ltmain.sh revision e9628295
1e9628295Smrg#! /usr/bin/env sh
2862bcd1aSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3e9628295Smrg##               by inline-source v2019-02-19.15
488de56ccSmrg
5e9628295Smrg# libtool (GNU libtool) 2.4.7
6862bcd1aSmrg# Provide generalized library-building support services.
788de56ccSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
888de56ccSmrg
9e9628295Smrg# Copyright (C) 1996-2019, 2021-2022 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
34e9628295SmrgVERSION=2.4.7
35e9628295Smrgpackage_revision=2.4.7
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.
67e9628295Smrgscriptversion=2019-02-19.15; # UTC
68862bcd1aSmrg
69862bcd1aSmrg# General shell script boiler plate, and helper functions.
70862bcd1aSmrg# Written by Gary V. Vaughan, 2004
71862bcd1aSmrg
72e9628295Smrg# This is free software.  There is NO warranty; not even for
73e9628295Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74e9628295Smrg#
75e9628295Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76e9628295Smrg#
77e9628295Smrg# This file is dual licensed under the terms of the MIT license
78e9628295Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79e9628295Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80e9628295Smrg# these licenses when using or redistributing this software or any of
81e9628295Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82e9628295Smrg# included in the Bootstrap distribution for the full license texts.
83862bcd1aSmrg
84e9628295Smrg# Please report bugs or propose patches to:
85e9628295Smrg# <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
133e9628295Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134e9628295Smrg# in case the environment reset is needed later and the $save_* variant is not
135e9628295Smrg# defined (see the code above).
136e9628295SmrgLC_ALL=C
137e9628295SmrgLANGUAGE=C
138e9628295Smrgexport LANGUAGE LC_ALL
13988de56ccSmrg
140862bcd1aSmrg# Make sure IFS has a sensible default
141862bcd1aSmrgsp=' '
142862bcd1aSmrgnl='
143862bcd1aSmrg'
144862bcd1aSmrgIFS="$sp	$nl"
145862bcd1aSmrg
146862bcd1aSmrg# There are apparently some retarded 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
156e9628295Smrg# func_unset VAR
157e9628295Smrg# --------------
158e9628295Smrg# Portably unset VAR.
159e9628295Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160e9628295Smrg# status if VAR is already unset, which might be problematic if the
161e9628295Smrg# statement is used at the end of a function (thus poisoning its return
162e9628295Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163e9628295Smrg# the script in this case).
164e9628295Smrgfunc_unset ()
165e9628295Smrg{
166e9628295Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167e9628295Smrg}
168e9628295Smrg
169e9628295Smrg
170e9628295Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171e9628295Smrgfunc_unset CDPATH
172e9628295Smrg
173e9628295Smrg# Make sure ${,E,F}GREP behave sanely.
174e9628295Smrgfunc_unset GREP_OPTIONS
175e9628295Smrg
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
276e9628295Smrg  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
312e9628295Smrg  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
377e9628295Smrg# require_check_ifs_backslash
378e9628295Smrg# ---------------------------
379e9628295Smrg# Check if we can use backslash as IFS='\' separator, and set
380e9628295Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381e9628295Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382e9628295Smrgfunc_require_check_ifs_backslash ()
383e9628295Smrg{
384e9628295Smrg  _G_save_IFS=$IFS
385e9628295Smrg  IFS='\'
386e9628295Smrg  _G_check_ifs_backshlash='a\\b'
387e9628295Smrg  for _G_i in $_G_check_ifs_backshlash
388e9628295Smrg  do
389e9628295Smrg  case $_G_i in
390e9628295Smrg  a)
391e9628295Smrg    check_ifs_backshlash_broken=false
392e9628295Smrg    ;;
393e9628295Smrg  '')
394e9628295Smrg    break
395e9628295Smrg    ;;
396e9628295Smrg  *)
397e9628295Smrg    check_ifs_backshlash_broken=:
398e9628295Smrg    break
399e9628295Smrg    ;;
400e9628295Smrg  esac
401e9628295Smrg  done
402e9628295Smrg  IFS=$_G_save_IFS
403e9628295Smrg  require_check_ifs_backslash=:
404e9628295Smrg}
405e9628295Smrg
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
592862bcd1aSmrg  # useable 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
626e9628295Smrg    func_quote_arg pretty "$2"
627e9628295Smrg    eval "$1+=\\ \$func_quote_arg_result"
628862bcd1aSmrg  }'
629862bcd1aSmrgelse
630862bcd1aSmrg  func_append_quoted ()
631862bcd1aSmrg  {
632862bcd1aSmrg    $debug_cmd
633862bcd1aSmrg
634e9628295Smrg    func_quote_arg pretty "$2"
635e9628295Smrg    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.
742862bcd1aSmrg#             value retuned 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
90088de56ccSmrg	# list incase 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
1137e9628295Smrg# func_quote_portable EVAL ARG
1138e9628295Smrg# ----------------------------
1139e9628295Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140e9628295Smrg# keep attention to performance here so we as much as possible try to avoid
1141e9628295Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142e9628295Smrgfunc_quote_portable ()
1143862bcd1aSmrg{
1144862bcd1aSmrg    $debug_cmd
1145862bcd1aSmrg
1146e9628295Smrg    $require_check_ifs_backslash
1147e9628295Smrg
1148e9628295Smrg    func_quote_portable_result=$2
1149e9628295Smrg
1150e9628295Smrg    # one-time-loop (easy break)
1151e9628295Smrg    while true
1152e9628295Smrg    do
1153e9628295Smrg      if $1; then
1154e9628295Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155e9628295Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156e9628295Smrg        break
1157862bcd1aSmrg      fi
1158862bcd1aSmrg
1159e9628295Smrg      # Quote for eval.
1160e9628295Smrg      case $func_quote_portable_result in
1161e9628295Smrg        *[\\\`\"\$]*)
1162e9628295Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163e9628295Smrg          # contains the shell wildcard characters.
1164e9628295Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165e9628295Smrg            :*|*[\[\*\?]*)
1166e9628295Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167e9628295Smrg                  | $SED "$sed_quote_subst"`
1168e9628295Smrg              break
1169e9628295Smrg              ;;
1170e9628295Smrg          esac
1171e9628295Smrg
1172e9628295Smrg          func_quote_portable_old_IFS=$IFS
1173e9628295Smrg          for _G_char in '\' '`' '"' '$'
1174e9628295Smrg          do
1175e9628295Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176e9628295Smrg            set start "" ""
1177e9628295Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178e9628295Smrg            IFS=$_G_char
1179e9628295Smrg            for _G_part in $func_quote_portable_result
1180e9628295Smrg            do
1181e9628295Smrg              case $1 in
1182e9628295Smrg              quote)
1183e9628295Smrg                func_append func_quote_portable_result "$3$2"
1184e9628295Smrg                set quote "$_G_part" "\\$_G_char"
1185e9628295Smrg                ;;
1186e9628295Smrg              start)
1187e9628295Smrg                set first "" ""
1188e9628295Smrg                func_quote_portable_result=
1189e9628295Smrg                ;;
1190e9628295Smrg              first)
1191e9628295Smrg                set quote "$_G_part" ""
1192e9628295Smrg                ;;
1193e9628295Smrg              esac
1194e9628295Smrg            done
1195e9628295Smrg          done
1196e9628295Smrg          IFS=$func_quote_portable_old_IFS
1197862bcd1aSmrg          ;;
1198e9628295Smrg        *) ;;
1199862bcd1aSmrg      esac
1200e9628295Smrg      break
1201862bcd1aSmrg    done
1202e9628295Smrg
1203e9628295Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204e9628295Smrg    case $func_quote_portable_result in
1205e9628295Smrg      # double-quote args containing shell metacharacters to delay
1206e9628295Smrg      # word splitting, command substitution and variable expansion
1207e9628295Smrg      # for a subsequent eval.
1208e9628295Smrg      # many bourne shells cannot handle close brackets correctly
1209e9628295Smrg      # in scan sets, so we specify it separately.
1210e9628295Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211e9628295Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212e9628295Smrg        ;;
1213e9628295Smrg    esac
1214862bcd1aSmrg}
1215862bcd1aSmrg
1216862bcd1aSmrg
1217e9628295Smrg# func_quotefast_eval ARG
1218e9628295Smrg# -----------------------
1219e9628295Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220e9628295Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221e9628295Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222e9628295Smrg  printf -v _GL_test_printf_tilde %q '~'
1223e9628295Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224e9628295Smrg    func_quotefast_eval ()
1225e9628295Smrg    {
1226e9628295Smrg      printf -v func_quotefast_eval_result %q "$1"
1227e9628295Smrg    }
1228e9628295Smrg  else
1229e9628295Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230e9628295Smrg    func_quotefast_eval ()
1231e9628295Smrg    {
1232e9628295Smrg      case $1 in
1233e9628295Smrg        '~'*)
1234e9628295Smrg          func_quote_portable false "$1"
1235e9628295Smrg          func_quotefast_eval_result=$func_quote_portable_result
1236e9628295Smrg          ;;
1237e9628295Smrg        *)
1238e9628295Smrg          printf -v func_quotefast_eval_result %q "$1"
1239e9628295Smrg          ;;
1240e9628295Smrg      esac
1241e9628295Smrg    }
1242e9628295Smrg  fi
1243e9628295Smrgelse
1244e9628295Smrg  func_quotefast_eval ()
1245e9628295Smrg  {
1246e9628295Smrg    func_quote_portable false "$1"
1247e9628295Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248e9628295Smrg  }
1249e9628295Smrgfi
1250862bcd1aSmrg
1251e9628295Smrg
1252e9628295Smrg# func_quote_arg MODEs ARG
1253e9628295Smrg# ------------------------
1254e9628295Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255e9628295Smrg# specifiers listed below separated by ',' character.  This function returns two
1256e9628295Smrg# values:
1257e9628295Smrg#   i) func_quote_arg_result
1258e9628295Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259e9628295Smrg#  ii) func_quote_arg_unquoted_result
1260e9628295Smrg#      has all characters that are still active within double
1261e9628295Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262e9628295Smrg#
1263e9628295Smrg# Available modes:
1264e9628295Smrg# ----------------
1265e9628295Smrg# 'eval' (default)
1266e9628295Smrg#       - escape shell special characters
1267e9628295Smrg# 'expand'
1268e9628295Smrg#       - the same as 'eval';  but do not quote variable references
1269e9628295Smrg# 'pretty'
1270e9628295Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271e9628295Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272e9628295Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273e9628295Smrg# 'unquoted'
1274e9628295Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275e9628295Smrg#         wrapping double-quotes.
1276e9628295Smrg#
1277e9628295Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278e9628295Smrg#
1279e9628295Smrg#   string      | *_result              | *_unquoted_result
1280e9628295Smrg#   ------------+-----------------------+-------------------
1281e9628295Smrg#   "           | \"                    | \"
1282e9628295Smrg#   a b         | "a b"                 | a b
1283e9628295Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284e9628295Smrg#   *           | "*"                   | *
1285e9628295Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286e9628295Smrg#
1287e9628295Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288e9628295Smrg#
1289e9628295Smrg#   string        |   *_result          |  *_unquoted_result
1290e9628295Smrg#   --------------+---------------------+--------------------
1291e9628295Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292e9628295Smrgfunc_quote_arg ()
1293e9628295Smrg{
1294e9628295Smrg    _G_quote_expand=false
1295e9628295Smrg    case ,$1, in
1296e9628295Smrg      *,expand,*)
1297e9628295Smrg        _G_quote_expand=:
1298e9628295Smrg        ;;
129988de56ccSmrg    esac
130088de56ccSmrg
1301e9628295Smrg    case ,$1, in
1302e9628295Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303e9628295Smrg        func_quote_portable $_G_quote_expand "$2"
1304e9628295Smrg        func_quote_arg_result=$func_quote_portable_result
1305e9628295Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306e9628295Smrg        ;;
1307e9628295Smrg      *)
1308e9628295Smrg        # Faster quote-for-eval for some shells.
1309e9628295Smrg        func_quotefast_eval "$2"
1310e9628295Smrg        func_quote_arg_result=$func_quotefast_eval_result
131188de56ccSmrg        ;;
131288de56ccSmrg    esac
1313e9628295Smrg}
1314e9628295Smrg
131588de56ccSmrg
1316e9628295Smrg# func_quote MODEs ARGs...
1317e9628295Smrg# ------------------------
1318e9628295Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319e9628295Smrg# func_quote_arg's description for more info.
1320e9628295Smrgfunc_quote ()
1321e9628295Smrg{
1322e9628295Smrg    $debug_cmd
1323e9628295Smrg    _G_func_quote_mode=$1 ; shift
1324e9628295Smrg    func_quote_result=
1325e9628295Smrg    while test 0 -lt $#; do
1326e9628295Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327e9628295Smrg      if test -n "$func_quote_result"; then
1328e9628295Smrg        func_append func_quote_result " $func_quote_arg_result"
1329e9628295Smrg      else
1330e9628295Smrg        func_append func_quote_result "$func_quote_arg_result"
1331e9628295Smrg      fi
1332e9628295Smrg      shift
1333e9628295Smrg    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
1379e9628295Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380e9628295Smrg    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 || {
1405e9628295Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406e9628295Smrg      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
1536e9628295Smrg# This is free software.  There is NO warranty; not even for
1537e9628295Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538e9628295Smrg#
1539e9628295Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540e9628295Smrg#
1541e9628295Smrg# This file is dual licensed under the terms of the MIT license
1542e9628295Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543e9628295Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544e9628295Smrg# these licenses when using or redistributing this software or any of
1545e9628295Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546e9628295Smrg# included in the Bootstrap distribution for the full license texts.
1547862bcd1aSmrg
1548e9628295Smrg# Please report bugs or propose patches to:
1549e9628295Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550862bcd1aSmrg
1551e9628295Smrg# Set a version string for this script.
1552e9628295Smrgscriptversion=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
1575e9628295Smrg# 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#
1587e9628295Smrg# 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
1636e9628295Smrg# in the main code.  A hook is just a list of function names that can be
1637e9628295Smrg# 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# ------------------------------------
1670e9628295Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671e9628295Smrg# FUNC_NAME.
1672862bcd1aSmrgfunc_remove_hook ()
1673862bcd1aSmrg{
1674862bcd1aSmrg    $debug_cmd
1675862bcd1aSmrg
1676862bcd1aSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677862bcd1aSmrg}
1678862bcd1aSmrg
1679862bcd1aSmrg
1680e9628295Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681e9628295Smrg# ---------------------------------------------
1682e9628295Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683e9628295Smrg# *_result variable of FUNC_NAME_B.
1684e9628295Smrgfunc_propagate_result ()
1685e9628295Smrg{
1686e9628295Smrg    $debug_cmd
1687e9628295Smrg
1688e9628295Smrg    func_propagate_result_result=:
1689e9628295Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690e9628295Smrg    then
1691e9628295Smrg      eval "${2}_result=\$${1}_result"
1692e9628295Smrg    else
1693e9628295Smrg      func_propagate_result_result=false
1694e9628295Smrg    fi
1695e9628295Smrg}
1696e9628295Smrg
1697e9628295Smrg
1698862bcd1aSmrg# func_run_hooks FUNC_NAME [ARG]...
1699862bcd1aSmrg# ---------------------------------
1700862bcd1aSmrg# Run all hook functions registered to FUNC_NAME.
1701e9628295Smrg# 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 "*) ;;
1711e9628295Smrg      *) 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
1717e9628295Smrg      func_unset "${_G_hook}_result"
1718e9628295Smrg      eval $_G_hook '${1+"$@"}'
1719e9628295Smrg      func_propagate_result $_G_hook func_run_hooks
1720e9628295Smrg      if $func_propagate_result_result; then
1721e9628295Smrg        eval set dummy "$func_run_hooks_result"; shift
1722e9628295Smrg      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
1733e9628295Smrg# full positional parameter list from your hook function.  You may remove
1734e9628295Smrg# or edit any options that you action, and then pass back the remaining
1735e9628295Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736e9628295Smrg# suitably for 'eval'.
1737e9628295Smrg#
1738e9628295Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739e9628295Smrg# before your hook gets called; for best performance, only set the
1740e9628295Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741e9628295Smrg# function unnecessarily because it can be an expensive operation on some
1742e9628295Smrg# machines).
1743e9628295Smrg#
1744e9628295Smrg# 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#    '
1754e9628295Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755e9628295Smrg#        # 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#
1764e9628295Smrg#        args_changed=false
1765e9628295Smrg#
1766e9628295Smrg#        # 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
1772e9628295Smrg#            --silent|-s) opt_silent=:
1773e9628295Smrg#                         args_changed=:
1774e9628295Smrg#                         ;;
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
1780e9628295Smrg#                         args_changed=:
1781862bcd1aSmrg#                         ;;
1782e9628295Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783e9628295Smrg#                         # is added back to "$@" in case we need it later,
1784e9628295Smrg#                         # if $args_changed was set to 'true'.
1785e9628295Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786862bcd1aSmrg#          esac
1787862bcd1aSmrg#        done
1788862bcd1aSmrg#
1789e9628295Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1790e9628295Smrg#        if $args_changed; then
1791e9628295Smrg#          func_quote eval ${1+"$@"}
1792e9628295Smrg#          my_silent_option_result=$func_quote_result
1793e9628295Smrg#        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#
1807e9628295Smrg# 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
1812e9628295Smrg# func_options_finish [ARG]...
1813e9628295Smrg# ----------------------------
1814e9628295Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815e9628295Smrgfunc_options_finish ()
1816e9628295Smrg{
1817e9628295Smrg    $debug_cmd
1818e9628295Smrg
1819e9628295Smrg    func_run_hooks func_options ${1+"$@"}
1820e9628295Smrg    func_propagate_result func_run_hooks func_options_finish
1821e9628295Smrg}
1822e9628295Smrg
1823e9628295Smrg
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
1833e9628295Smrg    _G_options_quoted=false
1834862bcd1aSmrg
1835e9628295Smrg    for my_func in options_prep parse_options validate_options options_finish
1836e9628295Smrg    do
1837e9628295Smrg      func_unset func_${my_func}_result
1838e9628295Smrg      func_unset func_run_hooks_result
1839e9628295Smrg      eval func_$my_func '${1+"$@"}'
1840e9628295Smrg      func_propagate_result func_$my_func func_options
1841e9628295Smrg      if $func_propagate_result_result; then
1842e9628295Smrg        eval set dummy "$func_options_result"; shift
1843e9628295Smrg        _G_options_quoted=:
1844e9628295Smrg      fi
1845e9628295Smrg    done
1846d4a3aaf4Smrg
1847e9628295Smrg    $_G_options_quoted || {
1848e9628295Smrg      # As we (func_options) are top-level options-parser function and
1849e9628295Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850e9628295Smrg      # caller.
1851e9628295Smrg      func_quote eval ${1+"$@"}
1852e9628295Smrg      func_options_result=$func_quote_result
1853e9628295Smrg    }
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
1862e9628295Smrg# needs to propagate that back to rest of this script, then the complete
1863e9628295Smrg# 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+"$@"}
1874e9628295Smrg    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
1886e9628295Smrg    _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+"$@"}
1892e9628295Smrg      func_propagate_result func_run_hooks func_parse_options
1893e9628295Smrg      if $func_propagate_result_result; then
1894e9628295Smrg        eval set dummy "$func_parse_options_result"; shift
1895e9628295Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896e9628295Smrg        # down into the hook and it quoted it for us (because we are in
1897e9628295Smrg        # this if-branch).  No need to quote it again.
1898e9628295Smrg        _G_parse_options_requote=false
1899e9628295Smrg      fi
1900862bcd1aSmrg
1901862bcd1aSmrg      # Break out of the loop if we already parsed every option.
1902862bcd1aSmrg      test $# -gt 0 || break
1903862bcd1aSmrg
1904e9628295Smrg      # We expect that one of the options parsed in this function matches
1905e9628295Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906e9628295Smrg      _G_match_parse_options=:
1907862bcd1aSmrg      _G_opt=$1
1908862bcd1aSmrg      shift
1909862bcd1aSmrg      case $_G_opt in
1910862bcd1aSmrg        --debug|-x)   debug_cmd='set -x'
1911e9628295Smrg                      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)
1921e9628295Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922e9628295Smrg                        _G_parse_options_requote=:
1923e9628295Smrg                        break
1924e9628295Smrg                      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
1977e9628295Smrg        --)           _G_parse_options_requote=: ; break ;;
1978862bcd1aSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979e9628295Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980e9628295Smrg                      _G_match_parse_options=false
1981e9628295Smrg                      break
1982e9628295Smrg                      ;;
1983862bcd1aSmrg      esac
1984e9628295Smrg
1985e9628295Smrg      if $_G_match_parse_options; then
1986e9628295Smrg        _G_parse_options_requote=:
1987e9628295Smrg      fi
1988862bcd1aSmrg    done
1989862bcd1aSmrg
1990e9628295Smrg    if $_G_parse_options_requote; then
1991e9628295Smrg      # save modified positional parameters for caller
1992e9628295Smrg      func_quote eval ${1+"$@"}
1993e9628295Smrg      func_parse_options_result=$func_quote_result
1994e9628295Smrg    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+"$@"}
2011e9628295Smrg    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# ------------------------
2070e9628295Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071e9628295Smrg# 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#*=}
2086e9628295Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087e9628295Smrg        func_split_equals_rhs=
2088e9628295Smrg      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=
2098e9628295Smrg      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
2124e9628295Smrg      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.
2166e9628295Smrg# The version message is extracted from the calling file's header
2167e9628295Smrg# comments, with leading '# ' stripped:
2168e9628295Smrg#   1. First display the progname and version
2169e9628295Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170e9628295Smrg#   3. Then a blank line followed by the first following line matching
2171e9628295Smrg#      /^# Copyright /
2172e9628295Smrg#   4. Immediately followed by any lines between the previous matches,
2173e9628295Smrg#      except lines preceding the intervening completely blank line.
2174e9628295Smrg# 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 '
2181e9628295Smrg        /^# Written by /!b
2182e9628295Smrg        s|^# ||; p; n
2183e9628295Smrg
2184e9628295Smrg        :fwd2blnk
2185e9628295Smrg        /./ {
2186e9628295Smrg          n
2187e9628295Smrg          b fwd2blnk
2188862bcd1aSmrg        }
2189e9628295Smrg        p; n
2190e9628295Smrg
2191e9628295Smrg        :holdwrnt
2192e9628295Smrg        s|^# ||
2193e9628295Smrg        s|^# *$||
2194e9628295Smrg        /^Copyright /!{
2195e9628295Smrg          /./H
2196e9628295Smrg          n
2197e9628295Smrg          b holdwrnt
2198862bcd1aSmrg        }
2199e9628295Smrg
2200e9628295Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201e9628295Smrg        G
2202e9628295Smrg        s|\(\n\)\n*|\1|g
2203e9628295Smrg        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)
2213e9628295Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214862bcd1aSmrg# time-stamp-time-zone: "UTC"
2215862bcd1aSmrg# End:
22161ab64890Smrg
2217862bcd1aSmrg# Set a version string.
2218e9628295Smrgscriptversion='(GNU libtool) 2.4.7'
22192e9c7c8cSmrg
222088de56ccSmrg
2221862bcd1aSmrg# func_echo ARG...
2222862bcd1aSmrg# ----------------
2223862bcd1aSmrg# Libtool also displays the current mode in messages, so override
2224862bcd1aSmrg# funclib.sh func_echo with this custom definition.
2225862bcd1aSmrgfunc_echo ()
2226e9fcaa8aSmrg{
2227862bcd1aSmrg    $debug_cmd
2228e9fcaa8aSmrg
2229862bcd1aSmrg    _G_message=$*
2230862bcd1aSmrg
2231862bcd1aSmrg    func_echo_IFS=$IFS
2232862bcd1aSmrg    IFS=$nl
2233862bcd1aSmrg    for _G_line in $_G_message; do
2234862bcd1aSmrg      IFS=$func_echo_IFS
2235862bcd1aSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236862bcd1aSmrg    done
2237862bcd1aSmrg    IFS=$func_echo_IFS
2238862bcd1aSmrg}
2239e9fcaa8aSmrg
2240e9fcaa8aSmrg
2241862bcd1aSmrg# func_warning ARG...
2242862bcd1aSmrg# -------------------
2243862bcd1aSmrg# Libtool warnings are not categorized, so override funclib.sh
2244862bcd1aSmrg# func_warning with this simpler definition.
2245862bcd1aSmrgfunc_warning ()
2246e9fcaa8aSmrg{
2247862bcd1aSmrg    $debug_cmd
2248862bcd1aSmrg
2249862bcd1aSmrg    $warning_func ${1+"$@"}
2250862bcd1aSmrg}
2251862bcd1aSmrg
2252e9fcaa8aSmrg
2253862bcd1aSmrg## ---------------- ##
2254862bcd1aSmrg## Options parsing. ##
2255862bcd1aSmrg## ---------------- ##
2256862bcd1aSmrg
2257862bcd1aSmrg# Hook in the functions to make sure our own options are parsed during
2258862bcd1aSmrg# the option parsing loop.
2259862bcd1aSmrg
2260862bcd1aSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261862bcd1aSmrg
2262862bcd1aSmrg# Short help message in response to '-h'.
2263862bcd1aSmrgusage_message="Options:
2264862bcd1aSmrg       --config             show all configuration variables
2265862bcd1aSmrg       --debug              enable verbose shell tracing
2266862bcd1aSmrg   -n, --dry-run            display commands without modifying any files
2267862bcd1aSmrg       --features           display basic configuration information and exit
2268862bcd1aSmrg       --mode=MODE          use operation mode MODE
2269862bcd1aSmrg       --no-warnings        equivalent to '-Wnone'
2270862bcd1aSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271862bcd1aSmrg       --quiet, --silent    don't print informational messages
2272862bcd1aSmrg       --tag=TAG            use configuration variables from tag TAG
2273862bcd1aSmrg   -v, --verbose            print more informational messages than default
2274862bcd1aSmrg       --version            print version information
2275862bcd1aSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276862bcd1aSmrg   -h, --help, --help-all   print short, long, or detailed help message
2277862bcd1aSmrg"
2278e9fcaa8aSmrg
2279862bcd1aSmrg# Additional text appended to 'usage_message' in response to '--help'.
2280862bcd1aSmrgfunc_help ()
2281e9fcaa8aSmrg{
2282862bcd1aSmrg    $debug_cmd
2283862bcd1aSmrg
2284862bcd1aSmrg    func_usage_message
2285862bcd1aSmrg    $ECHO "$long_help_message
2286862bcd1aSmrg
2287862bcd1aSmrgMODE must be one of the following:
2288862bcd1aSmrg
2289862bcd1aSmrg       clean           remove files from the build directory
2290862bcd1aSmrg       compile         compile a source file into a libtool object
2291862bcd1aSmrg       execute         automatically set library path, then run a program
2292862bcd1aSmrg       finish          complete the installation of libtool libraries
2293862bcd1aSmrg       install         install libraries or executables
2294862bcd1aSmrg       link            create a library or an executable
2295862bcd1aSmrg       uninstall       remove libraries from an installed directory
2296862bcd1aSmrg
2297862bcd1aSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298862bcd1aSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299862bcd1aSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300862bcd1aSmrg
2301862bcd1aSmrgWhen reporting a bug, please describe a test case to reproduce it and
2302862bcd1aSmrginclude the following information:
2303862bcd1aSmrg
2304862bcd1aSmrg       host-triplet:   $host
2305862bcd1aSmrg       shell:          $SHELL
2306862bcd1aSmrg       compiler:       $LTCC
2307862bcd1aSmrg       compiler flags: $LTCFLAGS
2308862bcd1aSmrg       linker:         $LD (gnu? $with_gnu_ld)
2309e9628295Smrg       version:        $progname (GNU libtool) 2.4.7
2310862bcd1aSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311862bcd1aSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312862bcd1aSmrg
2313862bcd1aSmrgReport bugs to <bug-libtool@gnu.org>.
231403ea5dc6SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315862bcd1aSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316862bcd1aSmrg    exit 0
2317862bcd1aSmrg}
2318e9fcaa8aSmrg
2319e9fcaa8aSmrg
2320862bcd1aSmrg# func_lo2o OBJECT-NAME
2321862bcd1aSmrg# ---------------------
2322862bcd1aSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323862bcd1aSmrg# object suffix.
2324e9fcaa8aSmrg
2325862bcd1aSmrglo2o=s/\\.lo\$/.$objext/
2326862bcd1aSmrgo2lo=s/\\.$objext\$/.lo/
2327e9fcaa8aSmrg
2328862bcd1aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329862bcd1aSmrg  eval 'func_lo2o ()
2330862bcd1aSmrg  {
2331862bcd1aSmrg    case $1 in
2332862bcd1aSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333862bcd1aSmrg      *   ) func_lo2o_result=$1               ;;
2334862bcd1aSmrg    esac
2335862bcd1aSmrg  }'
2336862bcd1aSmrg
2337862bcd1aSmrg  # func_xform LIBOBJ-OR-SOURCE
2338862bcd1aSmrg  # ---------------------------
2339862bcd1aSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340862bcd1aSmrg  # suffix to a '.lo' libtool-object suffix.
2341862bcd1aSmrg  eval 'func_xform ()
2342862bcd1aSmrg  {
2343862bcd1aSmrg    func_xform_result=${1%.*}.lo
2344862bcd1aSmrg  }'
2345862bcd1aSmrgelse
2346862bcd1aSmrg  # ...otherwise fall back to using sed.
2347862bcd1aSmrg  func_lo2o ()
2348862bcd1aSmrg  {
2349862bcd1aSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350862bcd1aSmrg  }
2351862bcd1aSmrg
2352862bcd1aSmrg  func_xform ()
2353862bcd1aSmrg  {
2354862bcd1aSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355862bcd1aSmrg  }
2356862bcd1aSmrgfi
2357e9fcaa8aSmrg
2358e9fcaa8aSmrg
2359862bcd1aSmrg# func_fatal_configuration ARG...
2360862bcd1aSmrg# -------------------------------
236188de56ccSmrg# Echo program name prefixed message to standard error, followed by
236288de56ccSmrg# a configuration failure hint, and exit.
236388de56ccSmrgfunc_fatal_configuration ()
236488de56ccSmrg{
2365e9628295Smrg    func_fatal_error ${1+"$@"} \
2366862bcd1aSmrg      "See the $PACKAGE documentation for more information." \
2367862bcd1aSmrg      "Fatal configuration error."
236888de56ccSmrg}
23691ab64890Smrg
23702e9c7c8cSmrg
237188de56ccSmrg# func_config
2372862bcd1aSmrg# -----------
237388de56ccSmrg# Display the configuration for all the tags in this script.
237488de56ccSmrgfunc_config ()
237588de56ccSmrg{
237688de56ccSmrg    re_begincf='^# ### BEGIN LIBTOOL'
237788de56ccSmrg    re_endcf='^# ### END LIBTOOL'
237888de56ccSmrg
237988de56ccSmrg    # Default configuration.
238088de56ccSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
23811ab64890Smrg
23821ab64890Smrg    # Now print the configurations for the tags.
23831ab64890Smrg    for tagname in $taglist; do
238488de56ccSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
23851ab64890Smrg    done
2386b4ee4795Smrg
238788de56ccSmrg    exit $?
238888de56ccSmrg}
2389b4ee4795Smrg
2390862bcd1aSmrg
239188de56ccSmrg# func_features
2392862bcd1aSmrg# -------------
239388de56ccSmrg# Display the features supported by this script.
239488de56ccSmrgfunc_features ()
239588de56ccSmrg{
2396e9fcaa8aSmrg    echo "host: $host"
2397862bcd1aSmrg    if test yes = "$build_libtool_libs"; then
2398e9fcaa8aSmrg      echo "enable shared libraries"
23991ab64890Smrg    else
2400e9fcaa8aSmrg      echo "disable shared libraries"
24011ab64890Smrg    fi
2402862bcd1aSmrg    if test yes = "$build_old_libs"; then
2403e9fcaa8aSmrg      echo "enable static libraries"
24041ab64890Smrg    else
2405e9fcaa8aSmrg      echo "disable static libraries"
24061ab64890Smrg    fi
240788de56ccSmrg
24081ab64890Smrg    exit $?
240988de56ccSmrg}
24101ab64890Smrg
2411862bcd1aSmrg
2412862bcd1aSmrg# func_enable_tag TAGNAME
2413862bcd1aSmrg# -----------------------
241488de56ccSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
241588de56ccSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
241688de56ccSmrg# variable here.
241788de56ccSmrgfunc_enable_tag ()
241888de56ccSmrg{
2419862bcd1aSmrg    # Global variable:
2420862bcd1aSmrg    tagname=$1
24211ab64890Smrg
2422862bcd1aSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423862bcd1aSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424862bcd1aSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
24252e9c7c8cSmrg
2426862bcd1aSmrg    # Validate tagname.
2427862bcd1aSmrg    case $tagname in
2428862bcd1aSmrg      *[!-_A-Za-z0-9,/]*)
2429862bcd1aSmrg        func_fatal_error "invalid tag name: $tagname"
2430862bcd1aSmrg        ;;
2431862bcd1aSmrg    esac
24321ab64890Smrg
2433862bcd1aSmrg    # Don't test for the "default" C tag, as we know it's
2434862bcd1aSmrg    # there but not specially marked.
2435862bcd1aSmrg    case $tagname in
2436862bcd1aSmrg        CC) ;;
243788de56ccSmrg    *)
2438862bcd1aSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439862bcd1aSmrg	  taglist="$taglist $tagname"
2440862bcd1aSmrg
2441862bcd1aSmrg	  # Evaluate the configuration.  Be careful to quote the path
2442862bcd1aSmrg	  # and the sed script, to avoid splitting on whitespace, but
2443862bcd1aSmrg	  # also don't use non-portable quotes within backquotes within
2444862bcd1aSmrg	  # quotes we have to do it in 2 steps:
2445862bcd1aSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446862bcd1aSmrg	  eval "$extractedcf"
2447862bcd1aSmrg        else
2448862bcd1aSmrg	  func_error "ignoring unknown tag $tagname"
2449862bcd1aSmrg        fi
2450862bcd1aSmrg        ;;
2451862bcd1aSmrg    esac
245288de56ccSmrg}
245388de56ccSmrg
2454862bcd1aSmrg
2455e9fcaa8aSmrg# func_check_version_match
2456862bcd1aSmrg# ------------------------
2457e9fcaa8aSmrg# Ensure that we are using m4 macros, and libtool script from the same
2458e9fcaa8aSmrg# release of libtool.
2459e9fcaa8aSmrgfunc_check_version_match ()
246088de56ccSmrg{
2461862bcd1aSmrg    if test "$package_revision" != "$macro_revision"; then
2462862bcd1aSmrg      if test "$VERSION" != "$macro_version"; then
2463862bcd1aSmrg        if test -z "$macro_version"; then
2464862bcd1aSmrg          cat >&2 <<_LT_EOF
2465e9fcaa8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466e9fcaa8aSmrg$progname: definition of this LT_INIT comes from an older release.
2467e9fcaa8aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468e9fcaa8aSmrg$progname: and run autoconf again.
2469e9fcaa8aSmrg_LT_EOF
2470862bcd1aSmrg        else
2471862bcd1aSmrg          cat >&2 <<_LT_EOF
2472e9fcaa8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473e9fcaa8aSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474e9fcaa8aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475e9fcaa8aSmrg$progname: and run autoconf again.
2476e9fcaa8aSmrg_LT_EOF
2477862bcd1aSmrg        fi
2478862bcd1aSmrg      else
2479862bcd1aSmrg        cat >&2 <<_LT_EOF
2480e9fcaa8aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481e9fcaa8aSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482e9fcaa8aSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483e9fcaa8aSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484e9fcaa8aSmrg_LT_EOF
2485862bcd1aSmrg      fi
2486e9fcaa8aSmrg
2487862bcd1aSmrg      exit $EXIT_MISMATCH
2488862bcd1aSmrg    fi
2489e9fcaa8aSmrg}
2490e9fcaa8aSmrg
2491e9fcaa8aSmrg
2492862bcd1aSmrg# libtool_options_prep [ARG]...
2493862bcd1aSmrg# -----------------------------
2494862bcd1aSmrg# Preparation for options parsed by libtool.
2495862bcd1aSmrglibtool_options_prep ()
2496862bcd1aSmrg{
2497862bcd1aSmrg    $debug_mode
2498b4ee4795Smrg
2499862bcd1aSmrg    # Option defaults:
2500862bcd1aSmrg    opt_config=false
2501862bcd1aSmrg    opt_dlopen=
2502862bcd1aSmrg    opt_dry_run=false
2503862bcd1aSmrg    opt_help=false
2504862bcd1aSmrg    opt_mode=
2505862bcd1aSmrg    opt_preserve_dup_deps=false
2506862bcd1aSmrg    opt_quiet=false
25071ab64890Smrg
2508862bcd1aSmrg    nonopt=
2509862bcd1aSmrg    preserve_args=
2510e9fcaa8aSmrg
2511e9628295Smrg    _G_rc_lt_options_prep=:
2512e9628295Smrg
2513862bcd1aSmrg    # Shorthand for --mode=foo, only valid as the first argument
2514862bcd1aSmrg    case $1 in
2515862bcd1aSmrg    clean|clea|cle|cl)
2516862bcd1aSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517862bcd1aSmrg      ;;
2518862bcd1aSmrg    compile|compil|compi|comp|com|co|c)
2519862bcd1aSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520862bcd1aSmrg      ;;
2521862bcd1aSmrg    execute|execut|execu|exec|exe|ex|e)
2522862bcd1aSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523862bcd1aSmrg      ;;
2524862bcd1aSmrg    finish|finis|fini|fin|fi|f)
2525862bcd1aSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526862bcd1aSmrg      ;;
2527862bcd1aSmrg    install|instal|insta|inst|ins|in|i)
2528862bcd1aSmrg      shift; set dummy --mode install ${1+"$@"}; shift
2529862bcd1aSmrg      ;;
2530862bcd1aSmrg    link|lin|li|l)
2531862bcd1aSmrg      shift; set dummy --mode link ${1+"$@"}; shift
2532862bcd1aSmrg      ;;
2533862bcd1aSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534862bcd1aSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535862bcd1aSmrg      ;;
2536e9628295Smrg    *)
2537e9628295Smrg      _G_rc_lt_options_prep=false
2538e9628295Smrg      ;;
2539862bcd1aSmrg    esac
2540862bcd1aSmrg
2541e9628295Smrg    if $_G_rc_lt_options_prep; then
2542e9628295Smrg      # Pass back the list of options.
2543e9628295Smrg      func_quote eval ${1+"$@"}
2544e9628295Smrg      libtool_options_prep_result=$func_quote_result
2545e9628295Smrg    fi
2546862bcd1aSmrg}
2547862bcd1aSmrgfunc_add_hook func_options_prep libtool_options_prep
2548e9fcaa8aSmrg
2549e9fcaa8aSmrg
2550862bcd1aSmrg# libtool_parse_options [ARG]...
2551862bcd1aSmrg# ---------------------------------
2552862bcd1aSmrg# Provide handling for libtool specific options.
2553862bcd1aSmrglibtool_parse_options ()
2554e9fcaa8aSmrg{
2555862bcd1aSmrg    $debug_cmd
255688de56ccSmrg
2557e9628295Smrg    _G_rc_lt_parse_options=false
2558e9628295Smrg
2559862bcd1aSmrg    # Perform our own loop to consume as many options as possible in
2560862bcd1aSmrg    # each iteration.
2561862bcd1aSmrg    while test $# -gt 0; do
2562e9628295Smrg      _G_match_lt_parse_options=:
2563862bcd1aSmrg      _G_opt=$1
2564862bcd1aSmrg      shift
2565862bcd1aSmrg      case $_G_opt in
2566862bcd1aSmrg        --dry-run|--dryrun|-n)
2567862bcd1aSmrg                        opt_dry_run=:
2568862bcd1aSmrg                        ;;
2569862bcd1aSmrg
2570862bcd1aSmrg        --config)       func_config ;;
2571862bcd1aSmrg
2572862bcd1aSmrg        --dlopen|-dlopen)
2573862bcd1aSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574862bcd1aSmrg}$1"
2575862bcd1aSmrg                        shift
2576862bcd1aSmrg                        ;;
2577862bcd1aSmrg
2578862bcd1aSmrg        --preserve-dup-deps)
2579862bcd1aSmrg                        opt_preserve_dup_deps=: ;;
2580862bcd1aSmrg
2581862bcd1aSmrg        --features)     func_features ;;
2582862bcd1aSmrg
2583862bcd1aSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584862bcd1aSmrg
2585862bcd1aSmrg        --help)         opt_help=: ;;
2586862bcd1aSmrg
2587862bcd1aSmrg        --help-all)     opt_help=': help-all' ;;
2588862bcd1aSmrg
2589862bcd1aSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590862bcd1aSmrg                        opt_mode=$1
2591862bcd1aSmrg                        case $1 in
2592862bcd1aSmrg                          # Valid mode arguments:
2593862bcd1aSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594862bcd1aSmrg
2595862bcd1aSmrg                          # Catch anything else as an error
2596862bcd1aSmrg                          *) func_error "invalid argument for $_G_opt"
2597862bcd1aSmrg                             exit_cmd=exit
2598862bcd1aSmrg                             break
2599862bcd1aSmrg                             ;;
2600862bcd1aSmrg                        esac
2601862bcd1aSmrg                        shift
2602862bcd1aSmrg                        ;;
2603862bcd1aSmrg
2604862bcd1aSmrg        --no-silent|--no-quiet)
2605862bcd1aSmrg                        opt_quiet=false
2606862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2607862bcd1aSmrg                        ;;
2608862bcd1aSmrg
2609862bcd1aSmrg        --no-warnings|--no-warning|--no-warn)
2610862bcd1aSmrg                        opt_warning=false
2611862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2612862bcd1aSmrg                        ;;
2613862bcd1aSmrg
2614862bcd1aSmrg        --no-verbose)
2615862bcd1aSmrg                        opt_verbose=false
2616862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2617862bcd1aSmrg                        ;;
2618862bcd1aSmrg
2619862bcd1aSmrg        --silent|--quiet)
2620862bcd1aSmrg                        opt_quiet=:
2621862bcd1aSmrg                        opt_verbose=false
2622862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2623862bcd1aSmrg                        ;;
2624862bcd1aSmrg
2625862bcd1aSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626862bcd1aSmrg                        opt_tag=$1
2627862bcd1aSmrg                        func_append preserve_args " $_G_opt $1"
2628862bcd1aSmrg                        func_enable_tag "$1"
2629862bcd1aSmrg                        shift
2630862bcd1aSmrg                        ;;
2631862bcd1aSmrg
2632862bcd1aSmrg        --verbose|-v)   opt_quiet=false
2633862bcd1aSmrg                        opt_verbose=:
2634862bcd1aSmrg                        func_append preserve_args " $_G_opt"
2635862bcd1aSmrg                        ;;
2636862bcd1aSmrg
2637e9628295Smrg        # An option not handled by this hook function:
2638e9628295Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2639e9628295Smrg                        _G_match_lt_parse_options=false
2640e9628295Smrg                        break
2641e9628295Smrg                        ;;
2642862bcd1aSmrg      esac
2643e9628295Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644862bcd1aSmrg    done
2645e9fcaa8aSmrg
2646e9628295Smrg    if $_G_rc_lt_parse_options; then
2647e9628295Smrg      # save modified positional parameters for caller
2648e9628295Smrg      func_quote eval ${1+"$@"}
2649e9628295Smrg      libtool_parse_options_result=$func_quote_result
2650e9628295Smrg    fi
2651862bcd1aSmrg}
2652862bcd1aSmrgfunc_add_hook func_parse_options libtool_parse_options
265388de56ccSmrg
26542e9c7c8cSmrg
265588de56ccSmrg
2656862bcd1aSmrg# libtool_validate_options [ARG]...
2657862bcd1aSmrg# ---------------------------------
2658862bcd1aSmrg# Perform any sanity checks on option settings and/or unconsumed
2659862bcd1aSmrg# arguments.
2660862bcd1aSmrglibtool_validate_options ()
2661862bcd1aSmrg{
2662862bcd1aSmrg    # save first non-option argument
2663862bcd1aSmrg    if test 0 -lt $#; then
2664862bcd1aSmrg      nonopt=$1
2665862bcd1aSmrg      shift
266688de56ccSmrg    fi
266788de56ccSmrg
2668862bcd1aSmrg    # preserve --debug
2669862bcd1aSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
267088de56ccSmrg
2671862bcd1aSmrg    case $host in
2672862bcd1aSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673862bcd1aSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674862bcd1aSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675862bcd1aSmrg        # don't eliminate duplications in $postdeps and $predeps
2676862bcd1aSmrg        opt_duplicate_compiler_generated_deps=:
2677862bcd1aSmrg        ;;
2678862bcd1aSmrg      *)
2679862bcd1aSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680862bcd1aSmrg        ;;
2681862bcd1aSmrg    esac
26821ab64890Smrg
2683862bcd1aSmrg    $opt_help || {
2684862bcd1aSmrg      # Sanity checks first:
2685862bcd1aSmrg      func_check_version_match
268688de56ccSmrg
2687862bcd1aSmrg      test yes != "$build_libtool_libs" \
2688862bcd1aSmrg        && test yes != "$build_old_libs" \
2689862bcd1aSmrg        && func_fatal_configuration "not configured to build any kind of library"
269088de56ccSmrg
2691862bcd1aSmrg      # Darwin sucks
2692862bcd1aSmrg      eval std_shrext=\"$shrext_cmds\"
2693862bcd1aSmrg
2694862bcd1aSmrg      # Only execute mode is allowed to have -dlopen flags.
2695862bcd1aSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696862bcd1aSmrg        func_error "unrecognized option '-dlopen'"
2697862bcd1aSmrg        $ECHO "$help" 1>&2
2698862bcd1aSmrg        exit $EXIT_FAILURE
2699862bcd1aSmrg      fi
2700862bcd1aSmrg
2701862bcd1aSmrg      # Change the help message to a mode-specific one.
2702862bcd1aSmrg      generic_help=$help
2703862bcd1aSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704862bcd1aSmrg    }
2705862bcd1aSmrg
2706862bcd1aSmrg    # Pass back the unparsed argument list
2707e9628295Smrg    func_quote eval ${1+"$@"}
2708e9628295Smrg    libtool_validate_options_result=$func_quote_result
2709e9fcaa8aSmrg}
2710862bcd1aSmrgfunc_add_hook func_validate_options libtool_validate_options
2711862bcd1aSmrg
271288de56ccSmrg
2713862bcd1aSmrg# Process options as early as possible so that --help and --version
2714862bcd1aSmrg# can return quickly.
2715862bcd1aSmrgfunc_options ${1+"$@"}
2716862bcd1aSmrgeval set dummy "$func_options_result"; shift
271788de56ccSmrg
27181ab64890Smrg
27191ab64890Smrg
2720e9fcaa8aSmrg## ----------- ##
2721e9fcaa8aSmrg##    Main.    ##
2722e9fcaa8aSmrg## ----------- ##
27231ab64890Smrg
2724862bcd1aSmrgmagic='%%%MAGIC variable%%%'
2725862bcd1aSmrgmagic_exe='%%%MAGIC EXE variable%%%'
2726862bcd1aSmrg
2727862bcd1aSmrg# Global variables.
2728862bcd1aSmrgextracted_archives=
2729862bcd1aSmrgextracted_serial=0
2730862bcd1aSmrg
2731862bcd1aSmrg# If this variable is set in any of the actions, the command in it
2732862bcd1aSmrg# will be execed at the end.  This prevents here-documents from being
2733862bcd1aSmrg# left over by shells.
2734862bcd1aSmrgexec_cmd=
2735862bcd1aSmrg
2736862bcd1aSmrg
2737862bcd1aSmrg# A function that is used when there is no print builtin or printf.
2738862bcd1aSmrgfunc_fallback_echo ()
2739862bcd1aSmrg{
2740862bcd1aSmrg  eval 'cat <<_LTECHO_EOF
2741862bcd1aSmrg$1
2742862bcd1aSmrg_LTECHO_EOF'
2743862bcd1aSmrg}
2744862bcd1aSmrg
2745862bcd1aSmrg# func_generated_by_libtool
2746862bcd1aSmrg# True iff stdin has been generated by Libtool. This function is only
2747862bcd1aSmrg# a basic sanity check; it will hardly flush out determined imposters.
2748862bcd1aSmrgfunc_generated_by_libtool_p ()
2749862bcd1aSmrg{
2750862bcd1aSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751862bcd1aSmrg}
2752862bcd1aSmrg
275388de56ccSmrg# func_lalib_p file
2754862bcd1aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
275588de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
275688de56ccSmrg# determined imposters.
275788de56ccSmrgfunc_lalib_p ()
275888de56ccSmrg{
275988de56ccSmrg    test -f "$1" &&
2760862bcd1aSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
276188de56ccSmrg}
27621ab64890Smrg
276388de56ccSmrg# func_lalib_unsafe_p file
2764862bcd1aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
276588de56ccSmrg# This function implements the same check as func_lalib_p without
276688de56ccSmrg# resorting to external programs.  To this end, it redirects stdin and
276788de56ccSmrg# closes it afterwards, without saving the original file descriptor.
276888de56ccSmrg# As a safety measure, use it only where a negative result would be
2769862bcd1aSmrg# fatal anyway.  Works if 'file' does not exist.
277088de56ccSmrgfunc_lalib_unsafe_p ()
277188de56ccSmrg{
277288de56ccSmrg    lalib_p=no
277388de56ccSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
277488de56ccSmrg	for lalib_p_l in 1 2 3 4
277588de56ccSmrg	do
277688de56ccSmrg	    read lalib_p_line
2777862bcd1aSmrg	    case $lalib_p_line in
277888de56ccSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
277988de56ccSmrg	    esac
278088de56ccSmrg	done
278188de56ccSmrg	exec 0<&5 5<&-
278288de56ccSmrg    fi
2783862bcd1aSmrg    test yes = "$lalib_p"
278488de56ccSmrg}
27851ab64890Smrg
278688de56ccSmrg# func_ltwrapper_script_p file
278788de56ccSmrg# True iff FILE is a libtool wrapper script
278888de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
278988de56ccSmrg# determined imposters.
279088de56ccSmrgfunc_ltwrapper_script_p ()
279188de56ccSmrg{
2792862bcd1aSmrg    test -f "$1" &&
2793862bcd1aSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
279488de56ccSmrg}
27951ab64890Smrg
279688de56ccSmrg# func_ltwrapper_executable_p file
279788de56ccSmrg# True iff FILE is a libtool wrapper executable
279888de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
279988de56ccSmrg# determined imposters.
280088de56ccSmrgfunc_ltwrapper_executable_p ()
280188de56ccSmrg{
280288de56ccSmrg    func_ltwrapper_exec_suffix=
280388de56ccSmrg    case $1 in
280488de56ccSmrg    *.exe) ;;
280588de56ccSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
280688de56ccSmrg    esac
280788de56ccSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
280888de56ccSmrg}
28092e9c7c8cSmrg
281088de56ccSmrg# func_ltwrapper_scriptname file
281188de56ccSmrg# Assumes file is an ltwrapper_executable
281288de56ccSmrg# uses $file to determine the appropriate filename for a
281388de56ccSmrg# temporary ltwrapper_script.
281488de56ccSmrgfunc_ltwrapper_scriptname ()
281588de56ccSmrg{
2816e9fcaa8aSmrg    func_dirname_and_basename "$1" "" "."
2817e9fcaa8aSmrg    func_stripname '' '.exe' "$func_basename_result"
2818862bcd1aSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
281988de56ccSmrg}
282088de56ccSmrg
282188de56ccSmrg# func_ltwrapper_p file
282288de56ccSmrg# True iff FILE is a libtool wrapper script or wrapper executable
282388de56ccSmrg# This function is only a basic sanity check; it will hardly flush out
282488de56ccSmrg# determined imposters.
282588de56ccSmrgfunc_ltwrapper_p ()
282688de56ccSmrg{
282788de56ccSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
282888de56ccSmrg}
282988de56ccSmrg
283088de56ccSmrg
283188de56ccSmrg# func_execute_cmds commands fail_cmd
283288de56ccSmrg# Execute tilde-delimited COMMANDS.
283388de56ccSmrg# If FAIL_CMD is given, eval that upon failure.
283488de56ccSmrg# FAIL_CMD may read-access the current command in variable CMD!
283588de56ccSmrgfunc_execute_cmds ()
283688de56ccSmrg{
2837862bcd1aSmrg    $debug_cmd
2838862bcd1aSmrg
283988de56ccSmrg    save_ifs=$IFS; IFS='~'
284088de56ccSmrg    for cmd in $1; do
2841862bcd1aSmrg      IFS=$sp$nl
284288de56ccSmrg      eval cmd=\"$cmd\"
2843862bcd1aSmrg      IFS=$save_ifs
284488de56ccSmrg      func_show_eval "$cmd" "${2-:}"
284588de56ccSmrg    done
284688de56ccSmrg    IFS=$save_ifs
284788de56ccSmrg}
284888de56ccSmrg
284988de56ccSmrg
285088de56ccSmrg# func_source file
285188de56ccSmrg# Source FILE, adding directory component if necessary.
285288de56ccSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
285388de56ccSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
285488de56ccSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855862bcd1aSmrg# 'FILE.' does not work on cygwin managed mounts.
285688de56ccSmrgfunc_source ()
285788de56ccSmrg{
2858862bcd1aSmrg    $debug_cmd
2859862bcd1aSmrg
286088de56ccSmrg    case $1 in
286188de56ccSmrg    */* | *\\*)	. "$1" ;;
286288de56ccSmrg    *)		. "./$1" ;;
286388de56ccSmrg    esac
286488de56ccSmrg}
286588de56ccSmrg
286688de56ccSmrg
2867e9fcaa8aSmrg# func_resolve_sysroot PATH
2868e9fcaa8aSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2869e9fcaa8aSmrg# func_resolve_sysroot_result
2870e9fcaa8aSmrgfunc_resolve_sysroot ()
2871e9fcaa8aSmrg{
2872e9fcaa8aSmrg  func_resolve_sysroot_result=$1
2873e9fcaa8aSmrg  case $func_resolve_sysroot_result in
2874e9fcaa8aSmrg  =*)
2875e9fcaa8aSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2876e9fcaa8aSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2877e9fcaa8aSmrg    ;;
2878e9fcaa8aSmrg  esac
2879e9fcaa8aSmrg}
2880e9fcaa8aSmrg
2881e9fcaa8aSmrg# func_replace_sysroot PATH
2882e9fcaa8aSmrg# If PATH begins with the sysroot, replace it with = and
2883e9fcaa8aSmrg# store the result into func_replace_sysroot_result.
2884e9fcaa8aSmrgfunc_replace_sysroot ()
2885e9fcaa8aSmrg{
2886862bcd1aSmrg  case $lt_sysroot:$1 in
2887e9fcaa8aSmrg  ?*:"$lt_sysroot"*)
2888e9fcaa8aSmrg    func_stripname "$lt_sysroot" '' "$1"
2889862bcd1aSmrg    func_replace_sysroot_result='='$func_stripname_result
2890e9fcaa8aSmrg    ;;
2891e9fcaa8aSmrg  *)
2892e9fcaa8aSmrg    # Including no sysroot.
2893e9fcaa8aSmrg    func_replace_sysroot_result=$1
2894e9fcaa8aSmrg    ;;
2895e9fcaa8aSmrg  esac
2896e9fcaa8aSmrg}
2897e9fcaa8aSmrg
289888de56ccSmrg# func_infer_tag arg
289988de56ccSmrg# Infer tagged configuration to use if any are available and
290088de56ccSmrg# if one wasn't chosen via the "--tag" command line option.
290188de56ccSmrg# Only attempt this if the compiler in the base compile
290288de56ccSmrg# command doesn't match the default compiler.
290388de56ccSmrg# arg is usually of the form 'gcc ...'
290488de56ccSmrgfunc_infer_tag ()
290588de56ccSmrg{
2906862bcd1aSmrg    $debug_cmd
2907862bcd1aSmrg
290888de56ccSmrg    if test -n "$available_tags" && test -z "$tagname"; then
290988de56ccSmrg      CC_quoted=
291088de56ccSmrg      for arg in $CC; do
2911e9fcaa8aSmrg	func_append_quoted CC_quoted "$arg"
291288de56ccSmrg      done
2913e9fcaa8aSmrg      CC_expanded=`func_echo_all $CC`
2914e9fcaa8aSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
291588de56ccSmrg      case $@ in
291688de56ccSmrg      # Blanks in the command may have been stripped by the calling shell,
291788de56ccSmrg      # but not from the CC environment variable when configure was run.
2918e9fcaa8aSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2919e9fcaa8aSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
292088de56ccSmrg      # Blanks at the start of $base_compile will cause this to fail
292188de56ccSmrg      # if we don't check for them as well.
292288de56ccSmrg      *)
292388de56ccSmrg	for z in $available_tags; do
292488de56ccSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
292588de56ccSmrg	    # Evaluate the configuration.
2926862bcd1aSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
292788de56ccSmrg	    CC_quoted=
292888de56ccSmrg	    for arg in $CC; do
292988de56ccSmrg	      # Double-quote args containing other shell metacharacters.
2930e9fcaa8aSmrg	      func_append_quoted CC_quoted "$arg"
293188de56ccSmrg	    done
2932e9fcaa8aSmrg	    CC_expanded=`func_echo_all $CC`
2933e9fcaa8aSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
293488de56ccSmrg	    case "$@ " in
2935e9fcaa8aSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2936e9fcaa8aSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
293788de56ccSmrg	      # The compiler in the base compile command matches
293888de56ccSmrg	      # the one in the tagged configuration.
293988de56ccSmrg	      # Assume this is the tagged configuration we want.
294088de56ccSmrg	      tagname=$z
294188de56ccSmrg	      break
294288de56ccSmrg	      ;;
294388de56ccSmrg	    esac
294488de56ccSmrg	  fi
294588de56ccSmrg	done
294688de56ccSmrg	# If $tagname still isn't set, then no tagged configuration
294788de56ccSmrg	# was found and let the user know that the "--tag" command
294888de56ccSmrg	# line option must be used.
294988de56ccSmrg	if test -z "$tagname"; then
295088de56ccSmrg	  func_echo "unable to infer tagged configuration"
2951862bcd1aSmrg	  func_fatal_error "specify a tag with '--tag'"
295288de56ccSmrg#	else
295388de56ccSmrg#	  func_verbose "using $tagname tagged configuration"
295488de56ccSmrg	fi
295588de56ccSmrg	;;
295688de56ccSmrg      esac
295788de56ccSmrg    fi
295888de56ccSmrg}
295988de56ccSmrg
296088de56ccSmrg
296188de56ccSmrg
296288de56ccSmrg# func_write_libtool_object output_name pic_name nonpic_name
296388de56ccSmrg# Create a libtool object file (analogous to a ".la" file),
296488de56ccSmrg# but don't create it if we're doing a dry run.
296588de56ccSmrgfunc_write_libtool_object ()
296688de56ccSmrg{
2967862bcd1aSmrg    write_libobj=$1
2968862bcd1aSmrg    if test yes = "$build_libtool_libs"; then
2969862bcd1aSmrg      write_lobj=\'$2\'
297088de56ccSmrg    else
297188de56ccSmrg      write_lobj=none
297288de56ccSmrg    fi
297388de56ccSmrg
2974862bcd1aSmrg    if test yes = "$build_old_libs"; then
2975862bcd1aSmrg      write_oldobj=\'$3\'
297688de56ccSmrg    else
297788de56ccSmrg      write_oldobj=none
297888de56ccSmrg    fi
297988de56ccSmrg
298088de56ccSmrg    $opt_dry_run || {
298188de56ccSmrg      cat >${write_libobj}T <<EOF
298288de56ccSmrg# $write_libobj - a libtool object file
2983862bcd1aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
298488de56ccSmrg#
298588de56ccSmrg# Please DO NOT delete this file!
298688de56ccSmrg# It is necessary for linking the library.
298788de56ccSmrg
298888de56ccSmrg# Name of the PIC object.
298988de56ccSmrgpic_object=$write_lobj
299088de56ccSmrg
299188de56ccSmrg# Name of the non-PIC object
299288de56ccSmrgnon_pic_object=$write_oldobj
299388de56ccSmrg
299488de56ccSmrgEOF
2995862bcd1aSmrg      $MV "${write_libobj}T" "$write_libobj"
299688de56ccSmrg    }
299788de56ccSmrg}
299888de56ccSmrg
2999e9fcaa8aSmrg
3000e9fcaa8aSmrg##################################################
3001e9fcaa8aSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3002e9fcaa8aSmrg##################################################
3003e9fcaa8aSmrg
3004e9fcaa8aSmrg# func_convert_core_file_wine_to_w32 ARG
3005e9fcaa8aSmrg# Helper function used by file name conversion functions when $build is *nix,
3006e9fcaa8aSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3007e9fcaa8aSmrg# correctly configured wine environment available, with the winepath program
3008e9fcaa8aSmrg# in $build's $PATH.
3009e9fcaa8aSmrg#
3010e9fcaa8aSmrg# ARG is the $build file name to be converted to w32 format.
3011e9fcaa8aSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3012e9fcaa8aSmrg# be empty on error (or when ARG is empty)
3013e9fcaa8aSmrgfunc_convert_core_file_wine_to_w32 ()
3014e9fcaa8aSmrg{
3015862bcd1aSmrg  $debug_cmd
3016862bcd1aSmrg
3017862bcd1aSmrg  func_convert_core_file_wine_to_w32_result=$1
3018e9fcaa8aSmrg  if test -n "$1"; then
3019e9fcaa8aSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3020e9fcaa8aSmrg    # are forced to check the contents of stdout. On the other hand, if the
3021e9fcaa8aSmrg    # command is not found, the shell will set an exit code of 127 and print
3022e9fcaa8aSmrg    # *an error message* to stdout. So we must check for both error code of
3023e9fcaa8aSmrg    # zero AND non-empty stdout, which explains the odd construction:
3024e9fcaa8aSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025862bcd1aSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3026e9fcaa8aSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027862bcd1aSmrg        $SED -e "$sed_naive_backslashify"`
3028e9fcaa8aSmrg    else
3029e9fcaa8aSmrg      func_convert_core_file_wine_to_w32_result=
3030e9fcaa8aSmrg    fi
3031e9fcaa8aSmrg  fi
3032e9fcaa8aSmrg}
3033e9fcaa8aSmrg# end: func_convert_core_file_wine_to_w32
3034e9fcaa8aSmrg
3035e9fcaa8aSmrg
3036e9fcaa8aSmrg# func_convert_core_path_wine_to_w32 ARG
3037e9fcaa8aSmrg# Helper function used by path conversion functions when $build is *nix, and
3038e9fcaa8aSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3039e9fcaa8aSmrg# configured wine environment available, with the winepath program in $build's
3040e9fcaa8aSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3041e9fcaa8aSmrg#
3042e9fcaa8aSmrg# ARG is path to be converted from $build format to win32.
3043e9fcaa8aSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3044e9fcaa8aSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3045e9fcaa8aSmrg# are convertible, then the result may be empty.
3046e9fcaa8aSmrgfunc_convert_core_path_wine_to_w32 ()
3047e9fcaa8aSmrg{
3048862bcd1aSmrg  $debug_cmd
3049862bcd1aSmrg
3050e9fcaa8aSmrg  # unfortunately, winepath doesn't convert paths, only file names
3051862bcd1aSmrg  func_convert_core_path_wine_to_w32_result=
3052e9fcaa8aSmrg  if test -n "$1"; then
3053e9fcaa8aSmrg    oldIFS=$IFS
3054e9fcaa8aSmrg    IFS=:
3055e9fcaa8aSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
3056e9fcaa8aSmrg      IFS=$oldIFS
3057e9fcaa8aSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058862bcd1aSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3059e9fcaa8aSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060862bcd1aSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3061e9fcaa8aSmrg        else
3062e9fcaa8aSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3063e9fcaa8aSmrg        fi
3064e9fcaa8aSmrg      fi
3065e9fcaa8aSmrg    done
3066e9fcaa8aSmrg    IFS=$oldIFS
3067e9fcaa8aSmrg  fi
3068e9fcaa8aSmrg}
3069e9fcaa8aSmrg# end: func_convert_core_path_wine_to_w32
3070e9fcaa8aSmrg
3071e9fcaa8aSmrg
3072e9fcaa8aSmrg# func_cygpath ARGS...
3073e9fcaa8aSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3074e9fcaa8aSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3075e9fcaa8aSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3076e9fcaa8aSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3077e9fcaa8aSmrg# file name or path is assumed to be in w32 format, as previously converted
3078e9fcaa8aSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3079e9fcaa8aSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
3080e9fcaa8aSmrg# Cygwin format). Returns an empty string on error.
3081e9fcaa8aSmrg#
3082e9fcaa8aSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
3083e9fcaa8aSmrg# be converted.
3084e9fcaa8aSmrg#
3085e9fcaa8aSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3086e9fcaa8aSmrg# environment variable; do not put it in $PATH.
3087e9fcaa8aSmrgfunc_cygpath ()
3088e9fcaa8aSmrg{
3089862bcd1aSmrg  $debug_cmd
3090862bcd1aSmrg
3091e9fcaa8aSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3092e9fcaa8aSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3093e9fcaa8aSmrg    if test "$?" -ne 0; then
3094e9fcaa8aSmrg      # on failure, ensure result is empty
3095e9fcaa8aSmrg      func_cygpath_result=
3096e9fcaa8aSmrg    fi
3097e9fcaa8aSmrg  else
3098e9fcaa8aSmrg    func_cygpath_result=
3099862bcd1aSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3100e9fcaa8aSmrg  fi
3101e9fcaa8aSmrg}
3102e9fcaa8aSmrg#end: func_cygpath
3103e9fcaa8aSmrg
3104e9fcaa8aSmrg
3105e9fcaa8aSmrg# func_convert_core_msys_to_w32 ARG
3106e9fcaa8aSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3107e9fcaa8aSmrg# result in func_convert_core_msys_to_w32_result.
3108e9fcaa8aSmrgfunc_convert_core_msys_to_w32 ()
3109e9fcaa8aSmrg{
3110862bcd1aSmrg  $debug_cmd
3111862bcd1aSmrg
3112e9fcaa8aSmrg  # awkward: cmd appends spaces to result
3113e9fcaa8aSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114862bcd1aSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3115e9fcaa8aSmrg}
3116e9fcaa8aSmrg#end: func_convert_core_msys_to_w32
3117e9fcaa8aSmrg
3118e9fcaa8aSmrg
3119e9fcaa8aSmrg# func_convert_file_check ARG1 ARG2
3120e9fcaa8aSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
3121e9fcaa8aSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3122e9fcaa8aSmrg# func_to_host_file_result to ARG1).
3123e9fcaa8aSmrgfunc_convert_file_check ()
3124e9fcaa8aSmrg{
3125862bcd1aSmrg  $debug_cmd
3126862bcd1aSmrg
3127862bcd1aSmrg  if test -z "$2" && test -n "$1"; then
3128e9fcaa8aSmrg    func_error "Could not determine host file name corresponding to"
3129862bcd1aSmrg    func_error "  '$1'"
3130e9fcaa8aSmrg    func_error "Continuing, but uninstalled executables may not work."
3131e9fcaa8aSmrg    # Fallback:
3132862bcd1aSmrg    func_to_host_file_result=$1
3133e9fcaa8aSmrg  fi
3134e9fcaa8aSmrg}
3135e9fcaa8aSmrg# end func_convert_file_check
3136e9fcaa8aSmrg
3137e9fcaa8aSmrg
3138e9fcaa8aSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3139e9fcaa8aSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3140e9fcaa8aSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3141e9fcaa8aSmrg# func_to_host_file_result to a simplistic fallback value (see below).
3142e9fcaa8aSmrgfunc_convert_path_check ()
3143e9fcaa8aSmrg{
3144862bcd1aSmrg  $debug_cmd
3145862bcd1aSmrg
3146e9fcaa8aSmrg  if test -z "$4" && test -n "$3"; then
3147e9fcaa8aSmrg    func_error "Could not determine the host path corresponding to"
3148862bcd1aSmrg    func_error "  '$3'"
3149e9fcaa8aSmrg    func_error "Continuing, but uninstalled executables may not work."
3150e9fcaa8aSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
3151e9fcaa8aSmrg    # should not be "improved".  See libtool.info.
3152e9fcaa8aSmrg    if test "x$1" != "x$2"; then
3153e9fcaa8aSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
3154e9fcaa8aSmrg      func_to_host_path_result=`echo "$3" |
3155e9fcaa8aSmrg        $SED -e "$lt_replace_pathsep_chars"`
3156e9fcaa8aSmrg    else
3157862bcd1aSmrg      func_to_host_path_result=$3
3158e9fcaa8aSmrg    fi
3159e9fcaa8aSmrg  fi
3160e9fcaa8aSmrg}
3161e9fcaa8aSmrg# end func_convert_path_check
3162e9fcaa8aSmrg
3163e9fcaa8aSmrg
3164e9fcaa8aSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3165e9fcaa8aSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3166e9fcaa8aSmrg# and appending REPL if ORIG matches BACKPAT.
3167e9fcaa8aSmrgfunc_convert_path_front_back_pathsep ()
3168e9fcaa8aSmrg{
3169862bcd1aSmrg  $debug_cmd
3170862bcd1aSmrg
3171e9fcaa8aSmrg  case $4 in
3172862bcd1aSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3173e9fcaa8aSmrg    ;;
3174e9fcaa8aSmrg  esac
3175e9fcaa8aSmrg  case $4 in
3176e9fcaa8aSmrg  $2 ) func_append func_to_host_path_result "$3"
3177e9fcaa8aSmrg    ;;
3178e9fcaa8aSmrg  esac
3179e9fcaa8aSmrg}
3180e9fcaa8aSmrg# end func_convert_path_front_back_pathsep
3181e9fcaa8aSmrg
3182e9fcaa8aSmrg
3183e9fcaa8aSmrg##################################################
3184e9fcaa8aSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3185e9fcaa8aSmrg##################################################
3186862bcd1aSmrg# invoked via '$to_host_file_cmd ARG'
3187e9fcaa8aSmrg#
3188e9fcaa8aSmrg# In each case, ARG is the path to be converted from $build to $host format.
3189e9fcaa8aSmrg# Result will be available in $func_to_host_file_result.
3190e9fcaa8aSmrg
3191e9fcaa8aSmrg
3192e9fcaa8aSmrg# func_to_host_file ARG
3193e9fcaa8aSmrg# Converts the file name ARG from $build format to $host format. Return result
3194e9fcaa8aSmrg# in func_to_host_file_result.
3195e9fcaa8aSmrgfunc_to_host_file ()
3196e9fcaa8aSmrg{
3197862bcd1aSmrg  $debug_cmd
3198862bcd1aSmrg
3199e9fcaa8aSmrg  $to_host_file_cmd "$1"
3200e9fcaa8aSmrg}
3201e9fcaa8aSmrg# end func_to_host_file
3202e9fcaa8aSmrg
3203e9fcaa8aSmrg
3204e9fcaa8aSmrg# func_to_tool_file ARG LAZY
3205e9fcaa8aSmrg# converts the file name ARG from $build format to toolchain format. Return
3206e9fcaa8aSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
3207e9fcaa8aSmrg# in (the comma separated) LAZY, no conversion takes place.
3208e9fcaa8aSmrgfunc_to_tool_file ()
3209e9fcaa8aSmrg{
3210862bcd1aSmrg  $debug_cmd
3211862bcd1aSmrg
3212e9fcaa8aSmrg  case ,$2, in
3213e9fcaa8aSmrg    *,"$to_tool_file_cmd",*)
3214e9fcaa8aSmrg      func_to_tool_file_result=$1
3215e9fcaa8aSmrg      ;;
3216e9fcaa8aSmrg    *)
3217e9fcaa8aSmrg      $to_tool_file_cmd "$1"
3218e9fcaa8aSmrg      func_to_tool_file_result=$func_to_host_file_result
3219e9fcaa8aSmrg      ;;
3220e9fcaa8aSmrg  esac
3221e9fcaa8aSmrg}
3222e9fcaa8aSmrg# end func_to_tool_file
3223e9fcaa8aSmrg
3224e9fcaa8aSmrg
3225e9fcaa8aSmrg# func_convert_file_noop ARG
3226e9fcaa8aSmrg# Copy ARG to func_to_host_file_result.
3227e9fcaa8aSmrgfunc_convert_file_noop ()
3228e9fcaa8aSmrg{
3229862bcd1aSmrg  func_to_host_file_result=$1
3230e9fcaa8aSmrg}
3231e9fcaa8aSmrg# end func_convert_file_noop
3232e9fcaa8aSmrg
3233e9fcaa8aSmrg
3234e9fcaa8aSmrg# func_convert_file_msys_to_w32 ARG
3235e9fcaa8aSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3236e9fcaa8aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3237e9fcaa8aSmrg# func_to_host_file_result.
3238e9fcaa8aSmrgfunc_convert_file_msys_to_w32 ()
3239e9fcaa8aSmrg{
3240862bcd1aSmrg  $debug_cmd
3241862bcd1aSmrg
3242862bcd1aSmrg  func_to_host_file_result=$1
3243e9fcaa8aSmrg  if test -n "$1"; then
3244e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$1"
3245862bcd1aSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3246e9fcaa8aSmrg  fi
3247e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3248e9fcaa8aSmrg}
3249e9fcaa8aSmrg# end func_convert_file_msys_to_w32
3250e9fcaa8aSmrg
3251e9fcaa8aSmrg
3252e9fcaa8aSmrg# func_convert_file_cygwin_to_w32 ARG
3253e9fcaa8aSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3254e9fcaa8aSmrg# func_to_host_file_result.
3255e9fcaa8aSmrgfunc_convert_file_cygwin_to_w32 ()
3256e9fcaa8aSmrg{
3257862bcd1aSmrg  $debug_cmd
3258862bcd1aSmrg
3259862bcd1aSmrg  func_to_host_file_result=$1
3260e9fcaa8aSmrg  if test -n "$1"; then
3261e9fcaa8aSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3262e9fcaa8aSmrg    # LT_CYGPATH in this case.
3263e9fcaa8aSmrg    func_to_host_file_result=`cygpath -m "$1"`
3264e9fcaa8aSmrg  fi
3265e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3266e9fcaa8aSmrg}
3267e9fcaa8aSmrg# end func_convert_file_cygwin_to_w32
3268e9fcaa8aSmrg
3269e9fcaa8aSmrg
3270e9fcaa8aSmrg# func_convert_file_nix_to_w32 ARG
3271e9fcaa8aSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3272e9fcaa8aSmrg# and a working winepath. Returns result in func_to_host_file_result.
3273e9fcaa8aSmrgfunc_convert_file_nix_to_w32 ()
3274e9fcaa8aSmrg{
3275862bcd1aSmrg  $debug_cmd
3276862bcd1aSmrg
3277862bcd1aSmrg  func_to_host_file_result=$1
3278e9fcaa8aSmrg  if test -n "$1"; then
3279e9fcaa8aSmrg    func_convert_core_file_wine_to_w32 "$1"
3280862bcd1aSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3281e9fcaa8aSmrg  fi
3282e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3283e9fcaa8aSmrg}
3284e9fcaa8aSmrg# end func_convert_file_nix_to_w32
3285e9fcaa8aSmrg
3286e9fcaa8aSmrg
3287e9fcaa8aSmrg# func_convert_file_msys_to_cygwin ARG
3288e9fcaa8aSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3289e9fcaa8aSmrg# Returns result in func_to_host_file_result.
3290e9fcaa8aSmrgfunc_convert_file_msys_to_cygwin ()
3291e9fcaa8aSmrg{
3292862bcd1aSmrg  $debug_cmd
3293862bcd1aSmrg
3294862bcd1aSmrg  func_to_host_file_result=$1
3295e9fcaa8aSmrg  if test -n "$1"; then
3296e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$1"
3297e9fcaa8aSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298862bcd1aSmrg    func_to_host_file_result=$func_cygpath_result
3299e9fcaa8aSmrg  fi
3300e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3301e9fcaa8aSmrg}
3302e9fcaa8aSmrg# end func_convert_file_msys_to_cygwin
3303e9fcaa8aSmrg
3304e9fcaa8aSmrg
3305e9fcaa8aSmrg# func_convert_file_nix_to_cygwin ARG
3306e9fcaa8aSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3307e9fcaa8aSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3308e9fcaa8aSmrg# in func_to_host_file_result.
3309e9fcaa8aSmrgfunc_convert_file_nix_to_cygwin ()
3310e9fcaa8aSmrg{
3311862bcd1aSmrg  $debug_cmd
3312862bcd1aSmrg
3313862bcd1aSmrg  func_to_host_file_result=$1
3314e9fcaa8aSmrg  if test -n "$1"; then
3315e9fcaa8aSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3316e9fcaa8aSmrg    func_convert_core_file_wine_to_w32 "$1"
3317e9fcaa8aSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318862bcd1aSmrg    func_to_host_file_result=$func_cygpath_result
3319e9fcaa8aSmrg  fi
3320e9fcaa8aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3321e9fcaa8aSmrg}
3322e9fcaa8aSmrg# end func_convert_file_nix_to_cygwin
3323e9fcaa8aSmrg
3324e9fcaa8aSmrg
3325e9fcaa8aSmrg#############################################
3326e9fcaa8aSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3327e9fcaa8aSmrg#############################################
3328862bcd1aSmrg# invoked via '$to_host_path_cmd ARG'
3329e9fcaa8aSmrg#
3330e9fcaa8aSmrg# In each case, ARG is the path to be converted from $build to $host format.
3331e9fcaa8aSmrg# The result will be available in $func_to_host_path_result.
3332e9fcaa8aSmrg#
3333e9fcaa8aSmrg# Path separators are also converted from $build format to $host format.  If
3334e9fcaa8aSmrg# ARG begins or ends with a path separator character, it is preserved (but
3335e9fcaa8aSmrg# converted to $host format) on output.
3336e9fcaa8aSmrg#
3337e9fcaa8aSmrg# All path conversion functions are named using the following convention:
3338e9fcaa8aSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3339e9fcaa8aSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3340e9fcaa8aSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3341e9fcaa8aSmrg# same.  If conversion functions are added for new $build/$host combinations,
3342e9fcaa8aSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3343e9fcaa8aSmrg# will break.
3344e9fcaa8aSmrg
3345e9fcaa8aSmrg
3346e9fcaa8aSmrg# func_init_to_host_path_cmd
3347e9fcaa8aSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3348e9fcaa8aSmrg# appropriate value, based on the value of $to_host_file_cmd.
3349e9fcaa8aSmrgto_host_path_cmd=
3350e9fcaa8aSmrgfunc_init_to_host_path_cmd ()
3351e9fcaa8aSmrg{
3352862bcd1aSmrg  $debug_cmd
3353862bcd1aSmrg
3354e9fcaa8aSmrg  if test -z "$to_host_path_cmd"; then
3355e9fcaa8aSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356862bcd1aSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3357e9fcaa8aSmrg  fi
3358e9fcaa8aSmrg}
3359e9fcaa8aSmrg
3360e9fcaa8aSmrg
3361e9fcaa8aSmrg# func_to_host_path ARG
3362e9fcaa8aSmrg# Converts the path ARG from $build format to $host format. Return result
3363e9fcaa8aSmrg# in func_to_host_path_result.
3364e9fcaa8aSmrgfunc_to_host_path ()
3365e9fcaa8aSmrg{
3366862bcd1aSmrg  $debug_cmd
3367862bcd1aSmrg
3368e9fcaa8aSmrg  func_init_to_host_path_cmd
3369e9fcaa8aSmrg  $to_host_path_cmd "$1"
3370e9fcaa8aSmrg}
3371e9fcaa8aSmrg# end func_to_host_path
3372e9fcaa8aSmrg
3373e9fcaa8aSmrg
3374e9fcaa8aSmrg# func_convert_path_noop ARG
3375e9fcaa8aSmrg# Copy ARG to func_to_host_path_result.
3376e9fcaa8aSmrgfunc_convert_path_noop ()
3377e9fcaa8aSmrg{
3378862bcd1aSmrg  func_to_host_path_result=$1
3379e9fcaa8aSmrg}
3380e9fcaa8aSmrg# end func_convert_path_noop
3381e9fcaa8aSmrg
3382e9fcaa8aSmrg
3383e9fcaa8aSmrg# func_convert_path_msys_to_w32 ARG
3384e9fcaa8aSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3385e9fcaa8aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3386e9fcaa8aSmrg# func_to_host_path_result.
3387e9fcaa8aSmrgfunc_convert_path_msys_to_w32 ()
3388e9fcaa8aSmrg{
3389862bcd1aSmrg  $debug_cmd
3390862bcd1aSmrg
3391862bcd1aSmrg  func_to_host_path_result=$1
3392e9fcaa8aSmrg  if test -n "$1"; then
3393e9fcaa8aSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3394e9fcaa8aSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3395e9fcaa8aSmrg    # and winepath ignores them completely.
3396e9fcaa8aSmrg    func_stripname : : "$1"
3397e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3398e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399862bcd1aSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3400e9fcaa8aSmrg    func_convert_path_check : ";" \
3401e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3402e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3403e9fcaa8aSmrg  fi
3404e9fcaa8aSmrg}
3405e9fcaa8aSmrg# end func_convert_path_msys_to_w32
3406e9fcaa8aSmrg
3407e9fcaa8aSmrg
3408e9fcaa8aSmrg# func_convert_path_cygwin_to_w32 ARG
3409e9fcaa8aSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3410e9fcaa8aSmrg# func_to_host_file_result.
3411e9fcaa8aSmrgfunc_convert_path_cygwin_to_w32 ()
3412e9fcaa8aSmrg{
3413862bcd1aSmrg  $debug_cmd
3414862bcd1aSmrg
3415862bcd1aSmrg  func_to_host_path_result=$1
3416e9fcaa8aSmrg  if test -n "$1"; then
3417e9fcaa8aSmrg    # See func_convert_path_msys_to_w32:
3418e9fcaa8aSmrg    func_stripname : : "$1"
3419e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3420e9fcaa8aSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3421e9fcaa8aSmrg    func_convert_path_check : ";" \
3422e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3423e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3424e9fcaa8aSmrg  fi
3425e9fcaa8aSmrg}
3426e9fcaa8aSmrg# end func_convert_path_cygwin_to_w32
3427e9fcaa8aSmrg
3428e9fcaa8aSmrg
3429e9fcaa8aSmrg# func_convert_path_nix_to_w32 ARG
3430e9fcaa8aSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3431e9fcaa8aSmrg# a working winepath.  Returns result in func_to_host_file_result.
3432e9fcaa8aSmrgfunc_convert_path_nix_to_w32 ()
3433e9fcaa8aSmrg{
3434862bcd1aSmrg  $debug_cmd
3435862bcd1aSmrg
3436862bcd1aSmrg  func_to_host_path_result=$1
3437e9fcaa8aSmrg  if test -n "$1"; then
3438e9fcaa8aSmrg    # See func_convert_path_msys_to_w32:
3439e9fcaa8aSmrg    func_stripname : : "$1"
3440e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3441e9fcaa8aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442862bcd1aSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3443e9fcaa8aSmrg    func_convert_path_check : ";" \
3444e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3445e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3446e9fcaa8aSmrg  fi
3447e9fcaa8aSmrg}
3448e9fcaa8aSmrg# end func_convert_path_nix_to_w32
3449e9fcaa8aSmrg
3450e9fcaa8aSmrg
3451e9fcaa8aSmrg# func_convert_path_msys_to_cygwin ARG
3452e9fcaa8aSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3453e9fcaa8aSmrg# Returns result in func_to_host_file_result.
3454e9fcaa8aSmrgfunc_convert_path_msys_to_cygwin ()
3455e9fcaa8aSmrg{
3456862bcd1aSmrg  $debug_cmd
3457862bcd1aSmrg
3458862bcd1aSmrg  func_to_host_path_result=$1
3459e9fcaa8aSmrg  if test -n "$1"; then
3460e9fcaa8aSmrg    # See func_convert_path_msys_to_w32:
3461e9fcaa8aSmrg    func_stripname : : "$1"
3462e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3463e9fcaa8aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3464e9fcaa8aSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465862bcd1aSmrg    func_to_host_path_result=$func_cygpath_result
3466e9fcaa8aSmrg    func_convert_path_check : : \
3467e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3468e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3469e9fcaa8aSmrg  fi
3470e9fcaa8aSmrg}
3471e9fcaa8aSmrg# end func_convert_path_msys_to_cygwin
3472e9fcaa8aSmrg
3473e9fcaa8aSmrg
3474e9fcaa8aSmrg# func_convert_path_nix_to_cygwin ARG
3475e9fcaa8aSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3476e9fcaa8aSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3477e9fcaa8aSmrg# func_to_host_file_result.
3478e9fcaa8aSmrgfunc_convert_path_nix_to_cygwin ()
3479e9fcaa8aSmrg{
3480862bcd1aSmrg  $debug_cmd
3481862bcd1aSmrg
3482862bcd1aSmrg  func_to_host_path_result=$1
3483e9fcaa8aSmrg  if test -n "$1"; then
3484e9fcaa8aSmrg    # Remove leading and trailing path separator characters from
3485e9fcaa8aSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3486e9fcaa8aSmrg    # into '.;' and ';.', and winepath ignores them completely.
3487e9fcaa8aSmrg    func_stripname : : "$1"
3488e9fcaa8aSmrg    func_to_host_path_tmp1=$func_stripname_result
3489e9fcaa8aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3490e9fcaa8aSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491862bcd1aSmrg    func_to_host_path_result=$func_cygpath_result
3492e9fcaa8aSmrg    func_convert_path_check : : \
3493e9fcaa8aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3494e9fcaa8aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3495e9fcaa8aSmrg  fi
3496e9fcaa8aSmrg}
3497e9fcaa8aSmrg# end func_convert_path_nix_to_cygwin
3498e9fcaa8aSmrg
3499e9fcaa8aSmrg
3500862bcd1aSmrg# func_dll_def_p FILE
3501862bcd1aSmrg# True iff FILE is a Windows DLL '.def' file.
3502862bcd1aSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503862bcd1aSmrgfunc_dll_def_p ()
3504862bcd1aSmrg{
3505862bcd1aSmrg  $debug_cmd
3506862bcd1aSmrg
3507862bcd1aSmrg  func_dll_def_p_tmp=`$SED -n \
3508862bcd1aSmrg    -e 's/^[	 ]*//' \
3509862bcd1aSmrg    -e '/^\(;.*\)*$/d' \
3510862bcd1aSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511862bcd1aSmrg    -e q \
3512862bcd1aSmrg    "$1"`
3513862bcd1aSmrg  test DEF = "$func_dll_def_p_tmp"
3514862bcd1aSmrg}
3515862bcd1aSmrg
3516862bcd1aSmrg
351788de56ccSmrg# func_mode_compile arg...
351888de56ccSmrgfunc_mode_compile ()
351988de56ccSmrg{
3520862bcd1aSmrg    $debug_cmd
3521862bcd1aSmrg
352288de56ccSmrg    # Get the compilation command and the source file.
352388de56ccSmrg    base_compile=
3524862bcd1aSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
352588de56ccSmrg    suppress_opt=yes
352688de56ccSmrg    suppress_output=
352788de56ccSmrg    arg_mode=normal
352888de56ccSmrg    libobj=
352988de56ccSmrg    later=
353088de56ccSmrg    pie_flag=
353188de56ccSmrg
353288de56ccSmrg    for arg
353388de56ccSmrg    do
353488de56ccSmrg      case $arg_mode in
353588de56ccSmrg      arg  )
353688de56ccSmrg	# do not "continue".  Instead, add this to base_compile
3537862bcd1aSmrg	lastarg=$arg
353888de56ccSmrg	arg_mode=normal
353988de56ccSmrg	;;
354088de56ccSmrg
354188de56ccSmrg      target )
3542862bcd1aSmrg	libobj=$arg
354388de56ccSmrg	arg_mode=normal
354488de56ccSmrg	continue
354588de56ccSmrg	;;
354688de56ccSmrg
354788de56ccSmrg      normal )
354888de56ccSmrg	# Accept any command-line options.
354988de56ccSmrg	case $arg in
355088de56ccSmrg	-o)
355188de56ccSmrg	  test -n "$libobj" && \
3552862bcd1aSmrg	    func_fatal_error "you cannot specify '-o' more than once"
355388de56ccSmrg	  arg_mode=target
355488de56ccSmrg	  continue
355588de56ccSmrg	  ;;
355688de56ccSmrg
355788de56ccSmrg	-pie | -fpie | -fPIE)
3558e9fcaa8aSmrg          func_append pie_flag " $arg"
355988de56ccSmrg	  continue
356088de56ccSmrg	  ;;
356188de56ccSmrg
356288de56ccSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3563e9fcaa8aSmrg	  func_append later " $arg"
356488de56ccSmrg	  continue
356588de56ccSmrg	  ;;
356688de56ccSmrg
356788de56ccSmrg	-no-suppress)
35681ab64890Smrg	  suppress_opt=no
35691ab64890Smrg	  continue
35701ab64890Smrg	  ;;
35711ab64890Smrg
35721ab64890Smrg	-Xcompiler)
35731ab64890Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
35741ab64890Smrg	  continue      #  The current "srcfile" will either be retained or
35751ab64890Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
35761ab64890Smrg
35771ab64890Smrg	-Wc,*)
357888de56ccSmrg	  func_stripname '-Wc,' '' "$arg"
357988de56ccSmrg	  args=$func_stripname_result
35801ab64890Smrg	  lastarg=
3581862bcd1aSmrg	  save_ifs=$IFS; IFS=,
358288de56ccSmrg	  for arg in $args; do
3583862bcd1aSmrg	    IFS=$save_ifs
3584e9fcaa8aSmrg	    func_append_quoted lastarg "$arg"
35851ab64890Smrg	  done
3586862bcd1aSmrg	  IFS=$save_ifs
358788de56ccSmrg	  func_stripname ' ' '' "$lastarg"
358888de56ccSmrg	  lastarg=$func_stripname_result
35891ab64890Smrg
35901ab64890Smrg	  # Add the arguments to base_compile.
3591e9fcaa8aSmrg	  func_append base_compile " $lastarg"
35921ab64890Smrg	  continue
35931ab64890Smrg	  ;;
35941ab64890Smrg
359588de56ccSmrg	*)
35961ab64890Smrg	  # Accept the current argument as the source file.
35971ab64890Smrg	  # The previous "srcfile" becomes the current argument.
35981ab64890Smrg	  #
3599862bcd1aSmrg	  lastarg=$srcfile
3600862bcd1aSmrg	  srcfile=$arg
36011ab64890Smrg	  ;;
36021ab64890Smrg	esac  #  case $arg
36031ab64890Smrg	;;
36041ab64890Smrg      esac    #  case $arg_mode
36051ab64890Smrg
36061ab64890Smrg      # Aesthetically quote the previous argument.
3607e9fcaa8aSmrg      func_append_quoted base_compile "$lastarg"
36081ab64890Smrg    done # for arg
36091ab64890Smrg
36101ab64890Smrg    case $arg_mode in
36111ab64890Smrg    arg)
361288de56ccSmrg      func_fatal_error "you must specify an argument for -Xcompile"
36131ab64890Smrg      ;;
36141ab64890Smrg    target)
3615862bcd1aSmrg      func_fatal_error "you must specify a target with '-o'"
36161ab64890Smrg      ;;
36171ab64890Smrg    *)
36181ab64890Smrg      # Get the name of the library object.
361988de56ccSmrg      test -z "$libobj" && {
362088de56ccSmrg	func_basename "$srcfile"
3621862bcd1aSmrg	libobj=$func_basename_result
362288de56ccSmrg      }
36231ab64890Smrg      ;;
36241ab64890Smrg    esac
36251ab64890Smrg
36261ab64890Smrg    # Recognize several different file suffixes.
36271ab64890Smrg    # If the user specifies -o file.o, it is replaced with file.lo
36281ab64890Smrg    case $libobj in
362988de56ccSmrg    *.[cCFSifmso] | \
363088de56ccSmrg    *.ada | *.adb | *.ads | *.asm | \
363188de56ccSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632eb411b4bSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
363388de56ccSmrg      func_xform "$libobj"
363488de56ccSmrg      libobj=$func_xform_result
363588de56ccSmrg      ;;
36361ab64890Smrg    esac
36371ab64890Smrg
36381ab64890Smrg    case $libobj in
363988de56ccSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
36401ab64890Smrg    *)
3641862bcd1aSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
36421ab64890Smrg      ;;
36431ab64890Smrg    esac
36441ab64890Smrg
36451ab64890Smrg    func_infer_tag $base_compile
36461ab64890Smrg
36471ab64890Smrg    for arg in $later; do
36481ab64890Smrg      case $arg in
364988de56ccSmrg      -shared)
3650862bcd1aSmrg	test yes = "$build_libtool_libs" \
3651862bcd1aSmrg	  || func_fatal_configuration "cannot build a shared library"
365288de56ccSmrg	build_old_libs=no
365388de56ccSmrg	continue
365488de56ccSmrg	;;
365588de56ccSmrg
36561ab64890Smrg      -static)
365788de56ccSmrg	build_libtool_libs=no
36581ab64890Smrg	build_old_libs=yes
36591ab64890Smrg	continue
36601ab64890Smrg	;;
36611ab64890Smrg
36621ab64890Smrg      -prefer-pic)
36631ab64890Smrg	pic_mode=yes
36641ab64890Smrg	continue
36651ab64890Smrg	;;
36661ab64890Smrg
36671ab64890Smrg      -prefer-non-pic)
36681ab64890Smrg	pic_mode=no
36691ab64890Smrg	continue
36701ab64890Smrg	;;
36711ab64890Smrg      esac
36721ab64890Smrg    done
36731ab64890Smrg
3674e9628295Smrg    func_quote_arg pretty "$libobj"
3675e9628295Smrg    test "X$libobj" != "X$func_quote_arg_result" \
367688de56ccSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677862bcd1aSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
367888de56ccSmrg    func_dirname_and_basename "$obj" "/" ""
3679862bcd1aSmrg    objname=$func_basename_result
3680862bcd1aSmrg    xdir=$func_dirname_result
3681862bcd1aSmrg    lobj=$xdir$objdir/$objname
36821ab64890Smrg
368388de56ccSmrg    test -z "$base_compile" && \
368488de56ccSmrg      func_fatal_help "you must specify a compilation command"
36851ab64890Smrg
36861ab64890Smrg    # Delete any leftover library objects.
3687862bcd1aSmrg    if test yes = "$build_old_libs"; then
36881ab64890Smrg      removelist="$obj $lobj $libobj ${libobj}T"
36891ab64890Smrg    else
36901ab64890Smrg      removelist="$lobj $libobj ${libobj}T"
36911ab64890Smrg    fi
36921ab64890Smrg
36931ab64890Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
36941ab64890Smrg    case $host_os in
369588de56ccSmrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
36961ab64890Smrg      pic_mode=default
36971ab64890Smrg      ;;
36981ab64890Smrg    esac
3699862bcd1aSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
37001ab64890Smrg      # non-PIC code in shared libraries is not supported
37011ab64890Smrg      pic_mode=default
37021ab64890Smrg    fi
37031ab64890Smrg
37041ab64890Smrg    # Calculate the filename of the output object if compiler does
37051ab64890Smrg    # not support -o with -c
3706862bcd1aSmrg    if test no = "$compiler_c_o"; then
3707862bcd1aSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708862bcd1aSmrg      lockfile=$output_obj.lock
37091ab64890Smrg    else
37101ab64890Smrg      output_obj=
37111ab64890Smrg      need_locks=no
37121ab64890Smrg      lockfile=
37131ab64890Smrg    fi
37141ab64890Smrg
37151ab64890Smrg    # Lock this critical section if it is needed
37161ab64890Smrg    # We use this script file to make the link, it avoids creating a new file
3717862bcd1aSmrg    if test yes = "$need_locks"; then
371888de56ccSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
371988de56ccSmrg	func_echo "Waiting for $lockfile to be removed"
37201ab64890Smrg	sleep 2
37211ab64890Smrg      done
3722862bcd1aSmrg    elif test warn = "$need_locks"; then
37231ab64890Smrg      if test -f "$lockfile"; then
372488de56ccSmrg	$ECHO "\
37251ab64890Smrg*** ERROR, $lockfile exists and contains:
37261ab64890Smrg`cat $lockfile 2>/dev/null`
37271ab64890Smrg
37281ab64890SmrgThis indicates that another process is trying to use the same
37291ab64890Smrgtemporary object file, and libtool could not work around it because
3730862bcd1aSmrgyour compiler does not support '-c' and '-o' together.  If you
37311ab64890Smrgrepeat this compilation, it may succeed, by chance, but you had better
37321ab64890Smrgavoid parallel builds (make -j) in this platform, or get a better
37331ab64890Smrgcompiler."
37341ab64890Smrg
373588de56ccSmrg	$opt_dry_run || $RM $removelist
37361ab64890Smrg	exit $EXIT_FAILURE
37371ab64890Smrg      fi
3738e9fcaa8aSmrg      func_append removelist " $output_obj"
373988de56ccSmrg      $ECHO "$srcfile" > "$lockfile"
37401ab64890Smrg    fi
37411ab64890Smrg
374288de56ccSmrg    $opt_dry_run || $RM $removelist
3743e9fcaa8aSmrg    func_append removelist " $lockfile"
374488de56ccSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
374588de56ccSmrg
3746e9fcaa8aSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3747e9fcaa8aSmrg    srcfile=$func_to_tool_file_result
3748e9628295Smrg    func_quote_arg pretty "$srcfile"
3749e9628295Smrg    qsrcfile=$func_quote_arg_result
37501ab64890Smrg
37511ab64890Smrg    # Only build a PIC object if we are building libtool libraries.
3752862bcd1aSmrg    if test yes = "$build_libtool_libs"; then
37531ab64890Smrg      # Without this assignment, base_compile gets emptied.
37541ab64890Smrg      fbsd_hideous_sh_bug=$base_compile
37551ab64890Smrg
3756862bcd1aSmrg      if test no != "$pic_mode"; then
37571ab64890Smrg	command="$base_compile $qsrcfile $pic_flag"
37581ab64890Smrg      else
37591ab64890Smrg	# Don't build PIC code
37601ab64890Smrg	command="$base_compile $qsrcfile"
37611ab64890Smrg      fi
37621ab64890Smrg
376388de56ccSmrg      func_mkdir_p "$xdir$objdir"
37641ab64890Smrg
37651ab64890Smrg      if test -z "$output_obj"; then
37661ab64890Smrg	# Place PIC objects in $objdir
3767e9fcaa8aSmrg	func_append command " -o $lobj"
37681ab64890Smrg      fi
37691ab64890Smrg
377088de56ccSmrg      func_show_eval_locale "$command"	\
377188de56ccSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
37721ab64890Smrg
3773862bcd1aSmrg      if test warn = "$need_locks" &&
37741ab64890Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
377588de56ccSmrg	$ECHO "\
37761ab64890Smrg*** ERROR, $lockfile contains:
37771ab64890Smrg`cat $lockfile 2>/dev/null`
37781ab64890Smrg
37791ab64890Smrgbut it should contain:
37801ab64890Smrg$srcfile
37811ab64890Smrg
37821ab64890SmrgThis indicates that another process is trying to use the same
37831ab64890Smrgtemporary object file, and libtool could not work around it because
3784862bcd1aSmrgyour compiler does not support '-c' and '-o' together.  If you
37851ab64890Smrgrepeat this compilation, it may succeed, by chance, but you had better
37861ab64890Smrgavoid parallel builds (make -j) in this platform, or get a better
37871ab64890Smrgcompiler."
37881ab64890Smrg
378988de56ccSmrg	$opt_dry_run || $RM $removelist
37901ab64890Smrg	exit $EXIT_FAILURE
37911ab64890Smrg      fi
37921ab64890Smrg
37931ab64890Smrg      # Just move the object if needed, then go on to compile the next one
37941ab64890Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
379588de56ccSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
379688de56ccSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
37971ab64890Smrg      fi
37981ab64890Smrg
37991ab64890Smrg      # Allow error messages only from the first compilation.
3800862bcd1aSmrg      if test yes = "$suppress_opt"; then
380188de56ccSmrg	suppress_output=' >/dev/null 2>&1'
38021ab64890Smrg      fi
38031ab64890Smrg    fi
38041ab64890Smrg
38051ab64890Smrg    # Only build a position-dependent object if we build old libraries.
3806862bcd1aSmrg    if test yes = "$build_old_libs"; then
3807862bcd1aSmrg      if test yes != "$pic_mode"; then
38081ab64890Smrg	# Don't build PIC code
380988de56ccSmrg	command="$base_compile $qsrcfile$pie_flag"
38101ab64890Smrg      else
38111ab64890Smrg	command="$base_compile $qsrcfile $pic_flag"
38121ab64890Smrg      fi
3813862bcd1aSmrg      if test yes = "$compiler_c_o"; then
3814e9fcaa8aSmrg	func_append command " -o $obj"
38151ab64890Smrg      fi
38161ab64890Smrg
38171ab64890Smrg      # Suppress compiler output if we already did a PIC compilation.
3818e9fcaa8aSmrg      func_append command "$suppress_output"
381988de56ccSmrg      func_show_eval_locale "$command" \
382088de56ccSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
38211ab64890Smrg
3822862bcd1aSmrg      if test warn = "$need_locks" &&
38231ab64890Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
382488de56ccSmrg	$ECHO "\
38251ab64890Smrg*** ERROR, $lockfile contains:
38261ab64890Smrg`cat $lockfile 2>/dev/null`
38271ab64890Smrg
38281ab64890Smrgbut it should contain:
38291ab64890Smrg$srcfile
38301ab64890Smrg
38311ab64890SmrgThis indicates that another process is trying to use the same
38321ab64890Smrgtemporary object file, and libtool could not work around it because
3833862bcd1aSmrgyour compiler does not support '-c' and '-o' together.  If you
38341ab64890Smrgrepeat this compilation, it may succeed, by chance, but you had better
38351ab64890Smrgavoid parallel builds (make -j) in this platform, or get a better
38361ab64890Smrgcompiler."
38371ab64890Smrg
383888de56ccSmrg	$opt_dry_run || $RM $removelist
38391ab64890Smrg	exit $EXIT_FAILURE
38401ab64890Smrg      fi
38411ab64890Smrg
38421ab64890Smrg      # Just move the object if needed
38431ab64890Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
384488de56ccSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
384588de56ccSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
38461ab64890Smrg      fi
38471ab64890Smrg    fi
38481ab64890Smrg
384988de56ccSmrg    $opt_dry_run || {
385088de56ccSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
38511ab64890Smrg
385288de56ccSmrg      # Unlock the critical section if it was locked
3853862bcd1aSmrg      if test no != "$need_locks"; then
385488de56ccSmrg	removelist=$lockfile
385588de56ccSmrg        $RM "$lockfile"
385688de56ccSmrg      fi
385788de56ccSmrg    }
38581ab64890Smrg
38591ab64890Smrg    exit $EXIT_SUCCESS
386088de56ccSmrg}
38611ab64890Smrg
386288de56ccSmrg$opt_help || {
3863862bcd1aSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
386488de56ccSmrg}
38651ab64890Smrg
386688de56ccSmrgfunc_mode_help ()
386788de56ccSmrg{
386888de56ccSmrg    # We need to display help for each of the modes.
3869e9fcaa8aSmrg    case $opt_mode in
387088de56ccSmrg      "")
387188de56ccSmrg        # Generic help is extracted from the usage comments
387288de56ccSmrg        # at the start of this file.
387388de56ccSmrg        func_help
387488de56ccSmrg        ;;
38751ab64890Smrg
387688de56ccSmrg      clean)
387788de56ccSmrg        $ECHO \
387888de56ccSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
38791ab64890Smrg
388088de56ccSmrgRemove files from the build directory.
38811ab64890Smrg
388288de56ccSmrgRM is the name of the program to use to delete files associated with each FILE
3883862bcd1aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
388488de56ccSmrgto RM.
38851ab64890Smrg
388688de56ccSmrgIf FILE is a libtool library, object or program, all the files associated
388788de56ccSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
388888de56ccSmrg        ;;
38891ab64890Smrg
389088de56ccSmrg      compile)
389188de56ccSmrg      $ECHO \
389288de56ccSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
38931ab64890Smrg
389488de56ccSmrgCompile a source file into a libtool library object.
38951ab64890Smrg
389688de56ccSmrgThis mode accepts the following additional options:
38971ab64890Smrg
389888de56ccSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
389988de56ccSmrg  -no-suppress      do not suppress compiler output for multiple passes
3900e9fcaa8aSmrg  -prefer-pic       try to build PIC objects only
3901e9fcaa8aSmrg  -prefer-non-pic   try to build non-PIC objects only
3902862bcd1aSmrg  -shared           do not build a '.o' file suitable for static linking
3903862bcd1aSmrg  -static           only build a '.o' file suitable for static linking
3904e9628295Smrg  -Wc,FLAG
3905e9628295Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
39061ab64890Smrg
3907862bcd1aSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
390888de56ccSmrgfrom the given SOURCEFILE.
39091ab64890Smrg
391088de56ccSmrgThe output file name is determined by removing the directory component from
3911862bcd1aSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912862bcd1aSmrglibrary object suffix, '.lo'."
391388de56ccSmrg        ;;
39141ab64890Smrg
391588de56ccSmrg      execute)
391688de56ccSmrg        $ECHO \
391788de56ccSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
39181ab64890Smrg
391988de56ccSmrgAutomatically set library path, then run a program.
39201ab64890Smrg
392188de56ccSmrgThis mode accepts the following additional options:
39221ab64890Smrg
392388de56ccSmrg  -dlopen FILE      add the directory containing FILE to the library path
39241ab64890Smrg
3925862bcd1aSmrgThis mode sets the library path environment variable according to '-dlopen'
392688de56ccSmrgflags.
39271ab64890Smrg
392888de56ccSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
392988de56ccSmrginto their corresponding uninstalled binary, and any of their required library
393088de56ccSmrgdirectories are added to the library path.
39311ab64890Smrg
393288de56ccSmrgThen, COMMAND is executed, with ARGS as arguments."
393388de56ccSmrg        ;;
39341ab64890Smrg
393588de56ccSmrg      finish)
393688de56ccSmrg        $ECHO \
393788de56ccSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
39381ab64890Smrg
393988de56ccSmrgComplete the installation of libtool libraries.
39401ab64890Smrg
394188de56ccSmrgEach LIBDIR is a directory that contains libtool libraries.
39421ab64890Smrg
394388de56ccSmrgThe commands that this mode executes may require superuser privileges.  Use
3944862bcd1aSmrgthe '--dry-run' option if you just want to see what would be executed."
394588de56ccSmrg        ;;
39461ab64890Smrg
394788de56ccSmrg      install)
394888de56ccSmrg        $ECHO \
394988de56ccSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
39501ab64890Smrg
395188de56ccSmrgInstall executables or libraries.
39521ab64890Smrg
395388de56ccSmrgINSTALL-COMMAND is the installation command.  The first component should be
3954862bcd1aSmrgeither the 'install' or 'cp' program.
39551ab64890Smrg
395688de56ccSmrgThe following components of INSTALL-COMMAND are treated specially:
39571ab64890Smrg
3958e9fcaa8aSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
39591ab64890Smrg
396088de56ccSmrgThe rest of the components are interpreted as arguments to that command (only
396188de56ccSmrgBSD-compatible install options are recognized)."
396288de56ccSmrg        ;;
39631ab64890Smrg
396488de56ccSmrg      link)
396588de56ccSmrg        $ECHO \
396688de56ccSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
39671ab64890Smrg
396888de56ccSmrgLink object files or libraries together to form another library, or to
396988de56ccSmrgcreate an executable program.
39701ab64890Smrg
397188de56ccSmrgLINK-COMMAND is a command using the C compiler that you would use to create
397288de56ccSmrga program from several object files.
39731ab64890Smrg
397488de56ccSmrgThe following components of LINK-COMMAND are treated specially:
39751ab64890Smrg
397688de56ccSmrg  -all-static       do not do any dynamic linking at all
397788de56ccSmrg  -avoid-version    do not add a version suffix if possible
3978e9fcaa8aSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
3979e9fcaa8aSmrg                    libraries must be found in the PATH setting at runtime)
3980862bcd1aSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
398188de56ccSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
398288de56ccSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
398388de56ccSmrg  -export-symbols SYMFILE
398488de56ccSmrg                    try to export only the symbols listed in SYMFILE
398588de56ccSmrg  -export-symbols-regex REGEX
398688de56ccSmrg                    try to export only the symbols matching REGEX
398788de56ccSmrg  -LLIBDIR          search LIBDIR for required installed libraries
398888de56ccSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
398988de56ccSmrg  -module           build a library that can dlopened
399088de56ccSmrg  -no-fast-install  disable the fast-install mode
399188de56ccSmrg  -no-install       link a not-installable executable
399288de56ccSmrg  -no-undefined     declare that a library does not refer to external symbols
399388de56ccSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994862bcd1aSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995862bcd1aSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
399688de56ccSmrg  -precious-files-regex REGEX
399788de56ccSmrg                    don't remove output files matching REGEX
399888de56ccSmrg  -release RELEASE  specify package release information
399988de56ccSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
400088de56ccSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
400188de56ccSmrg  -shared           only do dynamic linking of libtool libraries
400288de56ccSmrg  -shrext SUFFIX    override the standard shared library file extension
400388de56ccSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
400488de56ccSmrg  -static-libtool-libs
400588de56ccSmrg                    do not do any dynamic linking of libtool libraries
400688de56ccSmrg  -version-info CURRENT[:REVISION[:AGE]]
400788de56ccSmrg                    specify library version info [each variable defaults to 0]
400888de56ccSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4009e9fcaa8aSmrg  -Wc,FLAG
4010e9fcaa8aSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011e9628295Smrg  -Wa,FLAG
4012e9628295Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4013e9fcaa8aSmrg  -Wl,FLAG
4014e9fcaa8aSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4015e9fcaa8aSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
40161ab64890Smrg
4017862bcd1aSmrgAll other options (arguments beginning with '-') are ignored.
40181ab64890Smrg
4019862bcd1aSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
402088de56ccSmrgtreated as uninstalled libtool libraries, other files are standard or library
402188de56ccSmrgobject files.
40221ab64890Smrg
4023862bcd1aSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024862bcd1aSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
402588de56ccSmrgrequired, except when creating a convenience library.
40261ab64890Smrg
4027862bcd1aSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028862bcd1aSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40291ab64890Smrg
4030862bcd1aSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
403188de56ccSmrgis created, otherwise an executable program is created."
4032b4ee4795Smrg        ;;
40331ab64890Smrg
403488de56ccSmrg      uninstall)
403588de56ccSmrg        $ECHO \
403688de56ccSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
40371ab64890Smrg
403888de56ccSmrgRemove libraries from an installation directory.
40391ab64890Smrg
404088de56ccSmrgRM is the name of the program to use to delete files associated with each FILE
4041862bcd1aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
404288de56ccSmrgto RM.
40432e9c7c8cSmrg
404488de56ccSmrgIf FILE is a libtool library, all the files associated with it are deleted.
404588de56ccSmrgOtherwise, only FILE itself is deleted using RM."
404688de56ccSmrg        ;;
40472e9c7c8cSmrg
404888de56ccSmrg      *)
4049862bcd1aSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
405088de56ccSmrg        ;;
405188de56ccSmrg    esac
40522e9c7c8cSmrg
4053e9fcaa8aSmrg    echo
4054862bcd1aSmrg    $ECHO "Try '$progname --help' for more information about other modes."
405588de56ccSmrg}
40562e9c7c8cSmrg
4057e9fcaa8aSmrg# Now that we've collected a possible --mode arg, show help if necessary
4058e9fcaa8aSmrgif $opt_help; then
4059862bcd1aSmrg  if test : = "$opt_help"; then
4060e9fcaa8aSmrg    func_mode_help
4061e9fcaa8aSmrg  else
4062e9fcaa8aSmrg    {
4063e9fcaa8aSmrg      func_help noexit
4064e9fcaa8aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4065e9fcaa8aSmrg	func_mode_help
4066e9fcaa8aSmrg      done
4067862bcd1aSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4068e9fcaa8aSmrg    {
4069e9fcaa8aSmrg      func_help noexit
4070e9fcaa8aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4071e9fcaa8aSmrg	echo
4072e9fcaa8aSmrg	func_mode_help
4073e9fcaa8aSmrg      done
4074e9fcaa8aSmrg    } |
4075862bcd1aSmrg    $SED '1d
4076e9fcaa8aSmrg      /^When reporting/,/^Report/{
4077e9fcaa8aSmrg	H
4078e9fcaa8aSmrg	d
4079e9fcaa8aSmrg      }
4080e9fcaa8aSmrg      $x
4081e9fcaa8aSmrg      /information about other modes/d
4082e9fcaa8aSmrg      /more detailed .*MODE/d
4083e9fcaa8aSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4084e9fcaa8aSmrg  fi
4085e9fcaa8aSmrg  exit $?
4086e9fcaa8aSmrgfi
40872e9c7c8cSmrg
40882e9c7c8cSmrg
408988de56ccSmrg# func_mode_execute arg...
409088de56ccSmrgfunc_mode_execute ()
409188de56ccSmrg{
4092862bcd1aSmrg    $debug_cmd
4093862bcd1aSmrg
409488de56ccSmrg    # The first argument is the command name.
4095862bcd1aSmrg    cmd=$nonopt
409688de56ccSmrg    test -z "$cmd" && \
409788de56ccSmrg      func_fatal_help "you must specify a COMMAND"
4098b4ee4795Smrg
409988de56ccSmrg    # Handle -dlopen flags immediately.
4100e9fcaa8aSmrg    for file in $opt_dlopen; do
410188de56ccSmrg      test -f "$file" \
4102862bcd1aSmrg	|| func_fatal_help "'$file' is not a file"
4103b4ee4795Smrg
410488de56ccSmrg      dir=
410588de56ccSmrg      case $file in
410688de56ccSmrg      *.la)
4107e9fcaa8aSmrg	func_resolve_sysroot "$file"
4108e9fcaa8aSmrg	file=$func_resolve_sysroot_result
4109e9fcaa8aSmrg
411088de56ccSmrg	# Check to see that this really is a libtool archive.
411188de56ccSmrg	func_lalib_unsafe_p "$file" \
4112862bcd1aSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113b4ee4795Smrg
411488de56ccSmrg	# Read the libtool library.
411588de56ccSmrg	dlname=
411688de56ccSmrg	library_names=
411788de56ccSmrg	func_source "$file"
41181ab64890Smrg
411988de56ccSmrg	# Skip this library if it cannot be dlopened.
412088de56ccSmrg	if test -z "$dlname"; then
412188de56ccSmrg	  # Warn if it was a shared library.
412288de56ccSmrg	  test -n "$library_names" && \
4123862bcd1aSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
412488de56ccSmrg	  continue
412588de56ccSmrg	fi
41261ab64890Smrg
412788de56ccSmrg	func_dirname "$file" "" "."
4128862bcd1aSmrg	dir=$func_dirname_result
41291ab64890Smrg
413088de56ccSmrg	if test -f "$dir/$objdir/$dlname"; then
4131e9fcaa8aSmrg	  func_append dir "/$objdir"
413288de56ccSmrg	else
413388de56ccSmrg	  if test ! -f "$dir/$dlname"; then
4134862bcd1aSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
413588de56ccSmrg	  fi
413688de56ccSmrg	fi
4137b4ee4795Smrg	;;
41381ab64890Smrg
413988de56ccSmrg      *.lo)
414088de56ccSmrg	# Just add the directory containing the .lo file.
414188de56ccSmrg	func_dirname "$file" "" "."
4142862bcd1aSmrg	dir=$func_dirname_result
4143b4ee4795Smrg	;;
41441ab64890Smrg
414588de56ccSmrg      *)
4146862bcd1aSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147b4ee4795Smrg	continue
4148b4ee4795Smrg	;;
414988de56ccSmrg      esac
41501ab64890Smrg
415188de56ccSmrg      # Get the absolute pathname.
415288de56ccSmrg      absdir=`cd "$dir" && pwd`
4153862bcd1aSmrg      test -n "$absdir" && dir=$absdir
41542e9c7c8cSmrg
415588de56ccSmrg      # Now add the directory to shlibpath_var.
415688de56ccSmrg      if eval "test -z \"\$$shlibpath_var\""; then
415788de56ccSmrg	eval "$shlibpath_var=\"\$dir\""
415888de56ccSmrg      else
415988de56ccSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
416088de56ccSmrg      fi
416188de56ccSmrg    done
41622e9c7c8cSmrg
416388de56ccSmrg    # This variable tells wrapper scripts just to set shlibpath_var
416488de56ccSmrg    # rather than running their programs.
4165862bcd1aSmrg    libtool_execute_magic=$magic
41662e9c7c8cSmrg
416788de56ccSmrg    # Check if any of the arguments is a wrapper script.
416888de56ccSmrg    args=
416988de56ccSmrg    for file
417088de56ccSmrg    do
417188de56ccSmrg      case $file in
4172e9fcaa8aSmrg      -* | *.la | *.lo ) ;;
417388de56ccSmrg      *)
417488de56ccSmrg	# Do a test to see if this is really a libtool program.
417588de56ccSmrg	if func_ltwrapper_script_p "$file"; then
417688de56ccSmrg	  func_source "$file"
417788de56ccSmrg	  # Transform arg to wrapped name.
4178862bcd1aSmrg	  file=$progdir/$program
417988de56ccSmrg	elif func_ltwrapper_executable_p "$file"; then
418088de56ccSmrg	  func_ltwrapper_scriptname "$file"
418188de56ccSmrg	  func_source "$func_ltwrapper_scriptname_result"
418288de56ccSmrg	  # Transform arg to wrapped name.
4183862bcd1aSmrg	  file=$progdir/$program
418488de56ccSmrg	fi
418588de56ccSmrg	;;
418688de56ccSmrg      esac
418788de56ccSmrg      # Quote arguments (to preserve shell metacharacters).
4188e9fcaa8aSmrg      func_append_quoted args "$file"
418988de56ccSmrg    done
41902e9c7c8cSmrg
4191862bcd1aSmrg    if $opt_dry_run; then
4192862bcd1aSmrg      # Display what would be done.
4193862bcd1aSmrg      if test -n "$shlibpath_var"; then
4194862bcd1aSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195862bcd1aSmrg	echo "export $shlibpath_var"
4196862bcd1aSmrg      fi
4197862bcd1aSmrg      $ECHO "$cmd$args"
4198862bcd1aSmrg      exit $EXIT_SUCCESS
4199862bcd1aSmrg    else
420088de56ccSmrg      if test -n "$shlibpath_var"; then
420188de56ccSmrg	# Export the shlibpath_var.
420288de56ccSmrg	eval "export $shlibpath_var"
420388de56ccSmrg      fi
42042e9c7c8cSmrg
420588de56ccSmrg      # Restore saved environment variables
420688de56ccSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
420788de56ccSmrg      do
420888de56ccSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
420988de56ccSmrg                $lt_var=\$save_$lt_var; export $lt_var
4210b4ee4795Smrg	      else
421188de56ccSmrg		$lt_unset $lt_var
421288de56ccSmrg	      fi"
421388de56ccSmrg      done
42142e9c7c8cSmrg
421588de56ccSmrg      # Now prepare to actually exec the command.
4216862bcd1aSmrg      exec_cmd=\$cmd$args
421788de56ccSmrg    fi
421888de56ccSmrg}
42192e9c7c8cSmrg
4220862bcd1aSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
42212e9c7c8cSmrg
4222b4ee4795Smrg
422388de56ccSmrg# func_mode_finish arg...
422488de56ccSmrgfunc_mode_finish ()
422588de56ccSmrg{
4226862bcd1aSmrg    $debug_cmd
4227862bcd1aSmrg
4228e9fcaa8aSmrg    libs=
4229e9fcaa8aSmrg    libdirs=
423088de56ccSmrg    admincmds=
42311ab64890Smrg
4232e9fcaa8aSmrg    for opt in "$nonopt" ${1+"$@"}
4233e9fcaa8aSmrg    do
4234e9fcaa8aSmrg      if test -d "$opt"; then
4235e9fcaa8aSmrg	func_append libdirs " $opt"
4236e9fcaa8aSmrg
4237e9fcaa8aSmrg      elif test -f "$opt"; then
4238e9fcaa8aSmrg	if func_lalib_unsafe_p "$opt"; then
4239e9fcaa8aSmrg	  func_append libs " $opt"
4240e9fcaa8aSmrg	else
4241862bcd1aSmrg	  func_warning "'$opt' is not a valid libtool archive"
4242e9fcaa8aSmrg	fi
4243e9fcaa8aSmrg
4244e9fcaa8aSmrg      else
4245862bcd1aSmrg	func_fatal_error "invalid argument '$opt'"
4246e9fcaa8aSmrg      fi
4247e9fcaa8aSmrg    done
4248e9fcaa8aSmrg
4249e9fcaa8aSmrg    if test -n "$libs"; then
4250e9fcaa8aSmrg      if test -n "$lt_sysroot"; then
4251e9fcaa8aSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4252e9fcaa8aSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4253e9fcaa8aSmrg      else
4254e9fcaa8aSmrg        sysroot_cmd=
4255e9fcaa8aSmrg      fi
42561ab64890Smrg
4257e9fcaa8aSmrg      # Remove sysroot references
4258e9fcaa8aSmrg      if $opt_dry_run; then
4259e9fcaa8aSmrg        for lib in $libs; do
4260862bcd1aSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4261e9fcaa8aSmrg        done
4262e9fcaa8aSmrg      else
4263e9fcaa8aSmrg        tmpdir=`func_mktempdir`
4264e9fcaa8aSmrg        for lib in $libs; do
4265862bcd1aSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4266e9fcaa8aSmrg	    > $tmpdir/tmp-la
4267e9fcaa8aSmrg	  mv -f $tmpdir/tmp-la $lib
4268e9fcaa8aSmrg	done
4269e9fcaa8aSmrg        ${RM}r "$tmpdir"
4270e9fcaa8aSmrg      fi
4271e9fcaa8aSmrg    fi
4272e9fcaa8aSmrg
4273e9fcaa8aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
427488de56ccSmrg      for libdir in $libdirs; do
427588de56ccSmrg	if test -n "$finish_cmds"; then
427688de56ccSmrg	  # Do each command in the finish commands.
427788de56ccSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
427888de56ccSmrg'"$cmd"'"'
4279b4ee4795Smrg	fi
428088de56ccSmrg	if test -n "$finish_eval"; then
428188de56ccSmrg	  # Do the single finish_eval.
428288de56ccSmrg	  eval cmds=\"$finish_eval\"
4283e9fcaa8aSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
428488de56ccSmrg       $cmds"
428588de56ccSmrg	fi
428688de56ccSmrg      done
428788de56ccSmrg    fi
42881ab64890Smrg
428988de56ccSmrg    # Exit here if they wanted silent mode.
4290862bcd1aSmrg    $opt_quiet && exit $EXIT_SUCCESS
42911ab64890Smrg
4292e9fcaa8aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4293e9fcaa8aSmrg      echo "----------------------------------------------------------------------"
4294e9fcaa8aSmrg      echo "Libraries have been installed in:"
4295e9fcaa8aSmrg      for libdir in $libdirs; do
4296e9fcaa8aSmrg	$ECHO "   $libdir"
4297e9fcaa8aSmrg      done
4298e9fcaa8aSmrg      echo
4299e9fcaa8aSmrg      echo "If you ever happen to want to link against installed libraries"
4300e9fcaa8aSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301862bcd1aSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4302e9fcaa8aSmrg      echo "flag during linking and do at least one of the following:"
4303e9fcaa8aSmrg      if test -n "$shlibpath_var"; then
4304862bcd1aSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4305e9fcaa8aSmrg	echo "     during execution"
4306e9fcaa8aSmrg      fi
4307e9fcaa8aSmrg      if test -n "$runpath_var"; then
4308862bcd1aSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4309e9fcaa8aSmrg	echo "     during linking"
4310e9fcaa8aSmrg      fi
4311e9fcaa8aSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4312e9fcaa8aSmrg	libdir=LIBDIR
4313e9fcaa8aSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
431488de56ccSmrg
4315862bcd1aSmrg	$ECHO "   - use the '$flag' linker flag"
4316e9fcaa8aSmrg      fi
4317e9fcaa8aSmrg      if test -n "$admincmds"; then
4318e9fcaa8aSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4319e9fcaa8aSmrg      fi
4320e9fcaa8aSmrg      if test -f /etc/ld.so.conf; then
4321862bcd1aSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4322e9fcaa8aSmrg      fi
4323e9fcaa8aSmrg      echo
432488de56ccSmrg
4325e9fcaa8aSmrg      echo "See any operating system documentation about shared libraries for"
4326e9fcaa8aSmrg      case $host in
4327e9fcaa8aSmrg	solaris2.[6789]|solaris2.1[0-9])
4328e9fcaa8aSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4329e9fcaa8aSmrg	  echo "pages."
4330e9fcaa8aSmrg	  ;;
4331e9fcaa8aSmrg	*)
4332e9fcaa8aSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333e9fcaa8aSmrg	  ;;
4334e9fcaa8aSmrg      esac
4335e9fcaa8aSmrg      echo "----------------------------------------------------------------------"
4336e9fcaa8aSmrg    fi
433788de56ccSmrg    exit $EXIT_SUCCESS
433888de56ccSmrg}
433988de56ccSmrg
4340862bcd1aSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
434188de56ccSmrg
434288de56ccSmrg
434388de56ccSmrg# func_mode_install arg...
434488de56ccSmrgfunc_mode_install ()
434588de56ccSmrg{
4346862bcd1aSmrg    $debug_cmd
4347862bcd1aSmrg
434888de56ccSmrg    # There may be an optional sh(1) argument at the beginning of
434988de56ccSmrg    # install_prog (especially on Windows NT).
4350862bcd1aSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
435188de56ccSmrg       # Allow the use of GNU shtool's install command.
4352862bcd1aSmrg       case $nonopt in *shtool*) :;; *) false;; esac
4353862bcd1aSmrg    then
435488de56ccSmrg      # Aesthetically quote it.
4355e9628295Smrg      func_quote_arg pretty "$nonopt"
4356e9628295Smrg      install_prog="$func_quote_arg_result "
435788de56ccSmrg      arg=$1
435888de56ccSmrg      shift
435988de56ccSmrg    else
436088de56ccSmrg      install_prog=
436188de56ccSmrg      arg=$nonopt
436288de56ccSmrg    fi
436388de56ccSmrg
436488de56ccSmrg    # The real first argument should be the name of the installation program.
436588de56ccSmrg    # Aesthetically quote it.
4366e9628295Smrg    func_quote_arg pretty "$arg"
4367e9628295Smrg    func_append install_prog "$func_quote_arg_result"
4368e9fcaa8aSmrg    install_shared_prog=$install_prog
4369e9fcaa8aSmrg    case " $install_prog " in
4370e9fcaa8aSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4371e9fcaa8aSmrg      *) install_cp=false ;;
4372e9fcaa8aSmrg    esac
437388de56ccSmrg
437488de56ccSmrg    # We need to accept at least all the BSD install flags.
437588de56ccSmrg    dest=
437688de56ccSmrg    files=
437788de56ccSmrg    opts=
437888de56ccSmrg    prev=
437988de56ccSmrg    install_type=
4380862bcd1aSmrg    isdir=false
438188de56ccSmrg    stripme=
4382e9fcaa8aSmrg    no_mode=:
438388de56ccSmrg    for arg
438488de56ccSmrg    do
4385e9fcaa8aSmrg      arg2=
438688de56ccSmrg      if test -n "$dest"; then
4387e9fcaa8aSmrg	func_append files " $dest"
438888de56ccSmrg	dest=$arg
438988de56ccSmrg	continue
439088de56ccSmrg      fi
439188de56ccSmrg
439288de56ccSmrg      case $arg in
4393862bcd1aSmrg      -d) isdir=: ;;
439488de56ccSmrg      -f)
4395e9fcaa8aSmrg	if $install_cp; then :; else
4396e9fcaa8aSmrg	  prev=$arg
4397e9fcaa8aSmrg	fi
439888de56ccSmrg	;;
439988de56ccSmrg      -g | -m | -o)
440088de56ccSmrg	prev=$arg
440188de56ccSmrg	;;
440288de56ccSmrg      -s)
440388de56ccSmrg	stripme=" -s"
440488de56ccSmrg	continue
440588de56ccSmrg	;;
440688de56ccSmrg      -*)
440788de56ccSmrg	;;
440888de56ccSmrg      *)
440988de56ccSmrg	# If the previous option needed an argument, then skip it.
441088de56ccSmrg	if test -n "$prev"; then
4411862bcd1aSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4412e9fcaa8aSmrg	    arg2=$install_override_mode
4413e9fcaa8aSmrg	    no_mode=false
4414e9fcaa8aSmrg	  fi
4415b4ee4795Smrg	  prev=
44162e9c7c8cSmrg	else
441788de56ccSmrg	  dest=$arg
441888de56ccSmrg	  continue
44191ab64890Smrg	fi
4420b4ee4795Smrg	;;
442188de56ccSmrg      esac
44221ab64890Smrg
442388de56ccSmrg      # Aesthetically quote the argument.
4424e9628295Smrg      func_quote_arg pretty "$arg"
4425e9628295Smrg      func_append install_prog " $func_quote_arg_result"
4426e9fcaa8aSmrg      if test -n "$arg2"; then
4427e9628295Smrg	func_quote_arg pretty "$arg2"
4428e9fcaa8aSmrg      fi
4429e9628295Smrg      func_append install_shared_prog " $func_quote_arg_result"
443088de56ccSmrg    done
44311ab64890Smrg
443288de56ccSmrg    test -z "$install_prog" && \
443388de56ccSmrg      func_fatal_help "you must specify an install program"
44341ab64890Smrg
443588de56ccSmrg    test -n "$prev" && \
4436862bcd1aSmrg      func_fatal_help "the '$prev' option requires an argument"
44372e9c7c8cSmrg
4438e9fcaa8aSmrg    if test -n "$install_override_mode" && $no_mode; then
4439e9fcaa8aSmrg      if $install_cp; then :; else
4440e9628295Smrg	func_quote_arg pretty "$install_override_mode"
4441e9628295Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4442e9fcaa8aSmrg      fi
4443e9fcaa8aSmrg    fi
4444e9fcaa8aSmrg
444588de56ccSmrg    if test -z "$files"; then
444688de56ccSmrg      if test -z "$dest"; then
444788de56ccSmrg	func_fatal_help "no file or destination specified"
444888de56ccSmrg      else
444988de56ccSmrg	func_fatal_help "you must specify a destination"
445088de56ccSmrg      fi
4451b4ee4795Smrg    fi
44522e9c7c8cSmrg
445388de56ccSmrg    # Strip any trailing slash from the destination.
445488de56ccSmrg    func_stripname '' '/' "$dest"
445588de56ccSmrg    dest=$func_stripname_result
44562e9c7c8cSmrg
445788de56ccSmrg    # Check to see that the destination is a directory.
4458862bcd1aSmrg    test -d "$dest" && isdir=:
4459862bcd1aSmrg    if $isdir; then
4460862bcd1aSmrg      destdir=$dest
446188de56ccSmrg      destname=
4462b4ee4795Smrg    else
446388de56ccSmrg      func_dirname_and_basename "$dest" "" "."
4464862bcd1aSmrg      destdir=$func_dirname_result
4465862bcd1aSmrg      destname=$func_basename_result
44662e9c7c8cSmrg
446788de56ccSmrg      # Not a directory, so check to see that there is only one file specified.
446888de56ccSmrg      set dummy $files; shift
446988de56ccSmrg      test "$#" -gt 1 && \
4470862bcd1aSmrg	func_fatal_help "'$dest' is not a directory"
44712e9c7c8cSmrg    fi
447288de56ccSmrg    case $destdir in
447388de56ccSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474b4ee4795Smrg    *)
447588de56ccSmrg      for file in $files; do
447688de56ccSmrg	case $file in
447788de56ccSmrg	*.lo) ;;
447888de56ccSmrg	*)
4479862bcd1aSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
448088de56ccSmrg	  ;;
448188de56ccSmrg	esac
448288de56ccSmrg      done
4483b4ee4795Smrg      ;;
4484b4ee4795Smrg    esac
44851ab64890Smrg
448688de56ccSmrg    # This variable tells wrapper scripts just to set variables rather
448788de56ccSmrg    # than running their programs.
4488862bcd1aSmrg    libtool_install_magic=$magic
44891ab64890Smrg
449088de56ccSmrg    staticlibs=
449188de56ccSmrg    future_libdirs=
449288de56ccSmrg    current_libdirs=
449388de56ccSmrg    for file in $files; do
44941ab64890Smrg
449588de56ccSmrg      # Do each installation.
449688de56ccSmrg      case $file in
449788de56ccSmrg      *.$libext)
449888de56ccSmrg	# Do the static libraries later.
4499e9fcaa8aSmrg	func_append staticlibs " $file"
450088de56ccSmrg	;;
450188de56ccSmrg
450288de56ccSmrg      *.la)
4503e9fcaa8aSmrg	func_resolve_sysroot "$file"
4504e9fcaa8aSmrg	file=$func_resolve_sysroot_result
4505e9fcaa8aSmrg
450688de56ccSmrg	# Check to see that this really is a libtool archive.
450788de56ccSmrg	func_lalib_unsafe_p "$file" \
4508862bcd1aSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
450988de56ccSmrg
451088de56ccSmrg	library_names=
451188de56ccSmrg	old_library=
451288de56ccSmrg	relink_command=
451388de56ccSmrg	func_source "$file"
451488de56ccSmrg
451588de56ccSmrg	# Add the libdir to current_libdirs if it is the destination.
451688de56ccSmrg	if test "X$destdir" = "X$libdir"; then
451788de56ccSmrg	  case "$current_libdirs " in
451888de56ccSmrg	  *" $libdir "*) ;;
4519e9fcaa8aSmrg	  *) func_append current_libdirs " $libdir" ;;
45202e9c7c8cSmrg	  esac
452188de56ccSmrg	else
452288de56ccSmrg	  # Note the libdir as a future libdir.
452388de56ccSmrg	  case "$future_libdirs " in
452488de56ccSmrg	  *" $libdir "*) ;;
4525e9fcaa8aSmrg	  *) func_append future_libdirs " $libdir" ;;
452688de56ccSmrg	  esac
452788de56ccSmrg	fi
45282e9c7c8cSmrg
452988de56ccSmrg	func_dirname "$file" "/" ""
4530862bcd1aSmrg	dir=$func_dirname_result
4531e9fcaa8aSmrg	func_append dir "$objdir"
453288de56ccSmrg
453388de56ccSmrg	if test -n "$relink_command"; then
453488de56ccSmrg	  # Determine the prefix the user has applied to our future dir.
4535e9fcaa8aSmrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
453688de56ccSmrg
453788de56ccSmrg	  # Don't allow the user to place us outside of our expected
453888de56ccSmrg	  # location b/c this prevents finding dependent libraries that
453988de56ccSmrg	  # are installed to the same prefix.
454088de56ccSmrg	  # At present, this check doesn't affect windows .dll's that
454188de56ccSmrg	  # are installed into $libdir/../bin (currently, that works fine)
454288de56ccSmrg	  # but it's something to keep an eye on.
454388de56ccSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4544862bcd1aSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
454588de56ccSmrg
454688de56ccSmrg	  if test -n "$inst_prefix_dir"; then
454788de56ccSmrg	    # Stick the inst_prefix_dir data into the link command.
4548e9fcaa8aSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
454988de56ccSmrg	  else
4550e9fcaa8aSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
455188de56ccSmrg	  fi
455288de56ccSmrg
4553862bcd1aSmrg	  func_warning "relinking '$file'"
455488de56ccSmrg	  func_show_eval "$relink_command" \
4555862bcd1aSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
455688de56ccSmrg	fi
455788de56ccSmrg
455888de56ccSmrg	# See the names of the shared library.
455988de56ccSmrg	set dummy $library_names; shift
456088de56ccSmrg	if test -n "$1"; then
4561862bcd1aSmrg	  realname=$1
456288de56ccSmrg	  shift
456388de56ccSmrg
4564862bcd1aSmrg	  srcname=$realname
4565862bcd1aSmrg	  test -n "$relink_command" && srcname=${realname}T
456688de56ccSmrg
456788de56ccSmrg	  # Install the shared library and build the symlinks.
4568e9fcaa8aSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
456988de56ccSmrg	      'exit $?'
4570862bcd1aSmrg	  tstripme=$stripme
457188de56ccSmrg	  case $host_os in
457288de56ccSmrg	  cygwin* | mingw* | pw32* | cegcc*)
457388de56ccSmrg	    case $realname in
457488de56ccSmrg	    *.dll.a)
4575862bcd1aSmrg	      tstripme=
4576862bcd1aSmrg	      ;;
4577862bcd1aSmrg	    esac
4578862bcd1aSmrg	    ;;
4579862bcd1aSmrg	  os2*)
4580862bcd1aSmrg	    case $realname in
4581862bcd1aSmrg	    *_dll.a)
4582862bcd1aSmrg	      tstripme=
458388de56ccSmrg	      ;;
458488de56ccSmrg	    esac
45852e9c7c8cSmrg	    ;;
45862e9c7c8cSmrg	  esac
458788de56ccSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
458888de56ccSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589b4ee4795Smrg	  fi
459088de56ccSmrg
459188de56ccSmrg	  if test "$#" -gt 0; then
459288de56ccSmrg	    # Delete the old symlinks, and create new ones.
4593862bcd1aSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
459488de56ccSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
459588de56ccSmrg	    # so we also need to try rm && ln -s.
459688de56ccSmrg	    for linkname
459788de56ccSmrg	    do
459888de56ccSmrg	      test "$linkname" != "$realname" \
459988de56ccSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600b4ee4795Smrg	    done
4601b4ee4795Smrg	  fi
46021ab64890Smrg
460388de56ccSmrg	  # Do each command in the postinstall commands.
4604862bcd1aSmrg	  lib=$destdir/$realname
460588de56ccSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4606b4ee4795Smrg	fi
46071ab64890Smrg
460888de56ccSmrg	# Install the pseudo-library for information purposes.
460988de56ccSmrg	func_basename "$file"
4610862bcd1aSmrg	name=$func_basename_result
4611862bcd1aSmrg	instname=$dir/${name}i
461288de56ccSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
46131ab64890Smrg
461488de56ccSmrg	# Maybe install the static library, too.
4615e9fcaa8aSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
461688de56ccSmrg	;;
46171ab64890Smrg
461888de56ccSmrg      *.lo)
461988de56ccSmrg	# Install (i.e. copy) a libtool object.
46201ab64890Smrg
462188de56ccSmrg	# Figure out destination file name, if it wasn't already specified.
462288de56ccSmrg	if test -n "$destname"; then
4623862bcd1aSmrg	  destfile=$destdir/$destname
462488de56ccSmrg	else
462588de56ccSmrg	  func_basename "$file"
4626862bcd1aSmrg	  destfile=$func_basename_result
4627862bcd1aSmrg	  destfile=$destdir/$destfile
4628b4ee4795Smrg	fi
46291ab64890Smrg
463088de56ccSmrg	# Deduce the name of the destination old-style object file.
463188de56ccSmrg	case $destfile in
463288de56ccSmrg	*.lo)
463388de56ccSmrg	  func_lo2o "$destfile"
463488de56ccSmrg	  staticdest=$func_lo2o_result
463588de56ccSmrg	  ;;
463688de56ccSmrg	*.$objext)
4637862bcd1aSmrg	  staticdest=$destfile
463888de56ccSmrg	  destfile=
463988de56ccSmrg	  ;;
464088de56ccSmrg	*)
4641862bcd1aSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
464288de56ccSmrg	  ;;
464388de56ccSmrg	esac
46441ab64890Smrg
464588de56ccSmrg	# Install the libtool object if requested.
464688de56ccSmrg	test -n "$destfile" && \
464788de56ccSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
46481ab64890Smrg
464988de56ccSmrg	# Install the old object if enabled.
4650862bcd1aSmrg	if test yes = "$build_old_libs"; then
465188de56ccSmrg	  # Deduce the name of the old-style object file.
465288de56ccSmrg	  func_lo2o "$file"
465388de56ccSmrg	  staticobj=$func_lo2o_result
465488de56ccSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
46551ab64890Smrg	fi
465688de56ccSmrg	exit $EXIT_SUCCESS
465788de56ccSmrg	;;
46581ab64890Smrg
465988de56ccSmrg      *)
466088de56ccSmrg	# Figure out destination file name, if it wasn't already specified.
466188de56ccSmrg	if test -n "$destname"; then
4662862bcd1aSmrg	  destfile=$destdir/$destname
466388de56ccSmrg	else
466488de56ccSmrg	  func_basename "$file"
4665862bcd1aSmrg	  destfile=$func_basename_result
4666862bcd1aSmrg	  destfile=$destdir/$destfile
466788de56ccSmrg	fi
46681ab64890Smrg
466988de56ccSmrg	# If the file is missing, and there is a .exe on the end, strip it
467088de56ccSmrg	# because it is most likely a libtool script we actually want to
467188de56ccSmrg	# install
4672862bcd1aSmrg	stripped_ext=
467388de56ccSmrg	case $file in
467488de56ccSmrg	  *.exe)
467588de56ccSmrg	    if test ! -f "$file"; then
467688de56ccSmrg	      func_stripname '' '.exe' "$file"
467788de56ccSmrg	      file=$func_stripname_result
4678862bcd1aSmrg	      stripped_ext=.exe
467988de56ccSmrg	    fi
468088de56ccSmrg	    ;;
468188de56ccSmrg	esac
468288de56ccSmrg
468388de56ccSmrg	# Do a test to see if this is really a libtool program.
468488de56ccSmrg	case $host in
468588de56ccSmrg	*cygwin* | *mingw*)
468688de56ccSmrg	    if func_ltwrapper_executable_p "$file"; then
468788de56ccSmrg	      func_ltwrapper_scriptname "$file"
468888de56ccSmrg	      wrapper=$func_ltwrapper_scriptname_result
468988de56ccSmrg	    else
469088de56ccSmrg	      func_stripname '' '.exe' "$file"
469188de56ccSmrg	      wrapper=$func_stripname_result
469288de56ccSmrg	    fi
469388de56ccSmrg	    ;;
4694b4ee4795Smrg	*)
469588de56ccSmrg	    wrapper=$file
469688de56ccSmrg	    ;;
469788de56ccSmrg	esac
469888de56ccSmrg	if func_ltwrapper_script_p "$wrapper"; then
469988de56ccSmrg	  notinst_deplibs=
470088de56ccSmrg	  relink_command=
470188de56ccSmrg
470288de56ccSmrg	  func_source "$wrapper"
470388de56ccSmrg
470488de56ccSmrg	  # Check the variables that should have been set.
470588de56ccSmrg	  test -z "$generated_by_libtool_version" && \
4706862bcd1aSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
470788de56ccSmrg
4708862bcd1aSmrg	  finalize=:
470988de56ccSmrg	  for lib in $notinst_deplibs; do
471088de56ccSmrg	    # Check to see that each library is installed.
471188de56ccSmrg	    libdir=
471288de56ccSmrg	    if test -f "$lib"; then
471388de56ccSmrg	      func_source "$lib"
471488de56ccSmrg	    fi
4715862bcd1aSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
471688de56ccSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717862bcd1aSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718862bcd1aSmrg	      finalize=false
471988de56ccSmrg	    fi
472088de56ccSmrg	  done
472188de56ccSmrg
472288de56ccSmrg	  relink_command=
472388de56ccSmrg	  func_source "$wrapper"
472488de56ccSmrg
472588de56ccSmrg	  outputname=
4726862bcd1aSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
472788de56ccSmrg	    $opt_dry_run || {
4728862bcd1aSmrg	      if $finalize; then
472988de56ccSmrg	        tmpdir=`func_mktempdir`
473088de56ccSmrg		func_basename "$file$stripped_ext"
4731862bcd1aSmrg		file=$func_basename_result
4732862bcd1aSmrg	        outputname=$tmpdir/$file
473388de56ccSmrg	        # Replace the output file specification.
4734e9fcaa8aSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
473588de56ccSmrg
4736862bcd1aSmrg	        $opt_quiet || {
4737e9628295Smrg	          func_quote_arg expand,pretty "$relink_command"
4738e9628295Smrg		  eval "func_echo $func_quote_arg_result"
473988de56ccSmrg	        }
474088de56ccSmrg	        if eval "$relink_command"; then :
474188de56ccSmrg	          else
4742862bcd1aSmrg		  func_error "error: relink '$file' with the above command before installing it"
474388de56ccSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
474488de56ccSmrg		  continue
474588de56ccSmrg	        fi
4746862bcd1aSmrg	        file=$outputname
474788de56ccSmrg	      else
4748862bcd1aSmrg	        func_warning "cannot relink '$file'"
474988de56ccSmrg	      fi
475088de56ccSmrg	    }
475188de56ccSmrg	  else
475288de56ccSmrg	    # Install the binary that we compiled earlier.
4753e9fcaa8aSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754b4ee4795Smrg	  fi
475588de56ccSmrg	fi
475688de56ccSmrg
475788de56ccSmrg	# remove .exe since cygwin /usr/bin/install will append another
475888de56ccSmrg	# one anyway
475988de56ccSmrg	case $install_prog,$host in
476088de56ccSmrg	*/usr/bin/install*,*cygwin*)
476188de56ccSmrg	  case $file:$destfile in
476288de56ccSmrg	  *.exe:*.exe)
476388de56ccSmrg	    # this is ok
476488de56ccSmrg	    ;;
476588de56ccSmrg	  *.exe:*)
476688de56ccSmrg	    destfile=$destfile.exe
476788de56ccSmrg	    ;;
476888de56ccSmrg	  *:*.exe)
476988de56ccSmrg	    func_stripname '' '.exe' "$destfile"
477088de56ccSmrg	    destfile=$func_stripname_result
477188de56ccSmrg	    ;;
477288de56ccSmrg	  esac
4773b4ee4795Smrg	  ;;
4774b4ee4795Smrg	esac
477588de56ccSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
477688de56ccSmrg	$opt_dry_run || if test -n "$outputname"; then
477788de56ccSmrg	  ${RM}r "$tmpdir"
477888de56ccSmrg	fi
477988de56ccSmrg	;;
478088de56ccSmrg      esac
478188de56ccSmrg    done
47821ab64890Smrg
478388de56ccSmrg    for file in $staticlibs; do
478488de56ccSmrg      func_basename "$file"
4785862bcd1aSmrg      name=$func_basename_result
478688de56ccSmrg
478788de56ccSmrg      # Set up the ranlib parameters.
4788862bcd1aSmrg      oldlib=$destdir/$name
4789eb411b4bSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790eb411b4bSmrg      tool_oldlib=$func_to_tool_file_result
479188de56ccSmrg
479288de56ccSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
479388de56ccSmrg
479488de56ccSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795eb411b4bSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
479688de56ccSmrg      fi
479788de56ccSmrg
479888de56ccSmrg      # Do each command in the postinstall commands.
479988de56ccSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
480088de56ccSmrg    done
480188de56ccSmrg
480288de56ccSmrg    test -n "$future_libdirs" && \
4803862bcd1aSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
480488de56ccSmrg
480588de56ccSmrg    if test -n "$current_libdirs"; then
480688de56ccSmrg      # Maybe just do a dry run.
480788de56ccSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808862bcd1aSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
480988de56ccSmrg    else
481088de56ccSmrg      exit $EXIT_SUCCESS
481188de56ccSmrg    fi
481288de56ccSmrg}
481388de56ccSmrg
4814862bcd1aSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
481588de56ccSmrg
481688de56ccSmrg
481788de56ccSmrg# func_generate_dlsyms outputname originator pic_p
481888de56ccSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
481988de56ccSmrg# a dlpreopen symbol table.
482088de56ccSmrgfunc_generate_dlsyms ()
482188de56ccSmrg{
4822862bcd1aSmrg    $debug_cmd
4823862bcd1aSmrg
4824862bcd1aSmrg    my_outputname=$1
4825862bcd1aSmrg    my_originator=$2
4826862bcd1aSmrg    my_pic_p=${3-false}
4827862bcd1aSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
482888de56ccSmrg    my_dlsyms=
482988de56ccSmrg
4830862bcd1aSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
483188de56ccSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832862bcd1aSmrg	my_dlsyms=${my_outputname}S.c
483388de56ccSmrg      else
483488de56ccSmrg	func_error "not configured to extract global symbols from dlpreopened files"
483588de56ccSmrg      fi
483688de56ccSmrg    fi
483788de56ccSmrg
483888de56ccSmrg    if test -n "$my_dlsyms"; then
483988de56ccSmrg      case $my_dlsyms in
484088de56ccSmrg      "") ;;
484188de56ccSmrg      *.c)
484288de56ccSmrg	# Discover the nlist of each of the dlfiles.
4843862bcd1aSmrg	nlist=$output_objdir/$my_outputname.nm
484488de56ccSmrg
484588de56ccSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
484688de56ccSmrg
484788de56ccSmrg	# Parse the name list into a source file.
484888de56ccSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
484988de56ccSmrg
485088de56ccSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851862bcd1aSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852862bcd1aSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
485388de56ccSmrg
485488de56ccSmrg#ifdef __cplusplus
485588de56ccSmrgextern \"C\" {
485688de56ccSmrg#endif
485788de56ccSmrg
4858862bcd1aSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4859e9fcaa8aSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4860e9fcaa8aSmrg#endif
4861e9fcaa8aSmrg
4862e9fcaa8aSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863862bcd1aSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864862bcd1aSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4865e9fcaa8aSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4866e9fcaa8aSmrg# define LT_DLSYM_CONST
4867862bcd1aSmrg#elif defined __osf__
4868e9fcaa8aSmrg/* This system does not cope well with relocations in const data.  */
4869e9fcaa8aSmrg# define LT_DLSYM_CONST
4870e9fcaa8aSmrg#else
4871e9fcaa8aSmrg# define LT_DLSYM_CONST const
4872e9fcaa8aSmrg#endif
4873e9fcaa8aSmrg
4874862bcd1aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875862bcd1aSmrg
487688de56ccSmrg/* External symbol declarations for the compiler. */\
487788de56ccSmrg"
487888de56ccSmrg
4879862bcd1aSmrg	if test yes = "$dlself"; then
4880862bcd1aSmrg	  func_verbose "generating symbol list for '$output'"
488188de56ccSmrg
488288de56ccSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
488388de56ccSmrg
488488de56ccSmrg	  # Add our own program objects to the symbol list.
4885e9fcaa8aSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
488688de56ccSmrg	  for progfile in $progfiles; do
4887e9fcaa8aSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888862bcd1aSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4889e9fcaa8aSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
489088de56ccSmrg	  done
489188de56ccSmrg
489288de56ccSmrg	  if test -n "$exclude_expsyms"; then
489388de56ccSmrg	    $opt_dry_run || {
489488de56ccSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
489588de56ccSmrg	      eval '$MV "$nlist"T "$nlist"'
489688de56ccSmrg	    }
4897b4ee4795Smrg	  fi
489888de56ccSmrg
489988de56ccSmrg	  if test -n "$export_symbols_regex"; then
490088de56ccSmrg	    $opt_dry_run || {
490188de56ccSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
490288de56ccSmrg	      eval '$MV "$nlist"T "$nlist"'
490388de56ccSmrg	    }
490488de56ccSmrg	  fi
490588de56ccSmrg
490688de56ccSmrg	  # Prepare the list of exported symbols
490788de56ccSmrg	  if test -z "$export_symbols"; then
4908862bcd1aSmrg	    export_symbols=$output_objdir/$outputname.exp
490988de56ccSmrg	    $opt_dry_run || {
491088de56ccSmrg	      $RM $export_symbols
4911862bcd1aSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
491288de56ccSmrg	      case $host in
491388de56ccSmrg	      *cygwin* | *mingw* | *cegcc* )
491488de56ccSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
491588de56ccSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
491688de56ccSmrg	        ;;
491788de56ccSmrg	      esac
491888de56ccSmrg	    }
4919b4ee4795Smrg	  else
492088de56ccSmrg	    $opt_dry_run || {
4921862bcd1aSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
492288de56ccSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
492388de56ccSmrg	      eval '$MV "$nlist"T "$nlist"'
492488de56ccSmrg	      case $host in
4925e9fcaa8aSmrg	        *cygwin* | *mingw* | *cegcc* )
492688de56ccSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
492788de56ccSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
492888de56ccSmrg	          ;;
492988de56ccSmrg	      esac
493088de56ccSmrg	    }
4931b4ee4795Smrg	  fi
493288de56ccSmrg	fi
49331ab64890Smrg
493488de56ccSmrg	for dlprefile in $dlprefiles; do
4935862bcd1aSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
493688de56ccSmrg	  func_basename "$dlprefile"
4937862bcd1aSmrg	  name=$func_basename_result
4938e9fcaa8aSmrg          case $host in
4939e9fcaa8aSmrg	    *cygwin* | *mingw* | *cegcc* )
4940e9fcaa8aSmrg	      # if an import library, we need to obtain dlname
4941e9fcaa8aSmrg	      if func_win32_import_lib_p "$dlprefile"; then
4942e9fcaa8aSmrg	        func_tr_sh "$dlprefile"
4943e9fcaa8aSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944862bcd1aSmrg	        dlprefile_dlbasename=
4945e9fcaa8aSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4946e9fcaa8aSmrg	          # Use subshell, to avoid clobbering current variable values
4947e9fcaa8aSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948862bcd1aSmrg	          if test -n "$dlprefile_dlname"; then
4949e9fcaa8aSmrg	            func_basename "$dlprefile_dlname"
4950862bcd1aSmrg	            dlprefile_dlbasename=$func_basename_result
4951e9fcaa8aSmrg	          else
4952e9fcaa8aSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4953e9fcaa8aSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4954e9fcaa8aSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4955e9fcaa8aSmrg	          fi
4956e9fcaa8aSmrg	        fi
4957e9fcaa8aSmrg	        $opt_dry_run || {
4958862bcd1aSmrg	          if test -n "$dlprefile_dlbasename"; then
4959e9fcaa8aSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4960e9fcaa8aSmrg	          else
4961e9fcaa8aSmrg	            func_warning "Could not compute DLL name from $name"
4962e9fcaa8aSmrg	            eval '$ECHO ": $name " >> "$nlist"'
4963e9fcaa8aSmrg	          fi
4964e9fcaa8aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965e9fcaa8aSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4966e9fcaa8aSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4967e9fcaa8aSmrg	        }
4968e9fcaa8aSmrg	      else # not an import lib
4969e9fcaa8aSmrg	        $opt_dry_run || {
4970e9fcaa8aSmrg	          eval '$ECHO ": $name " >> "$nlist"'
4971e9fcaa8aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4972e9fcaa8aSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4973e9fcaa8aSmrg	        }
4974e9fcaa8aSmrg	      fi
4975e9fcaa8aSmrg	    ;;
4976e9fcaa8aSmrg	    *)
4977e9fcaa8aSmrg	      $opt_dry_run || {
4978e9fcaa8aSmrg	        eval '$ECHO ": $name " >> "$nlist"'
4979e9fcaa8aSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4980e9fcaa8aSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4981e9fcaa8aSmrg	      }
4982e9fcaa8aSmrg	    ;;
4983e9fcaa8aSmrg          esac
498488de56ccSmrg	done
498588de56ccSmrg
498688de56ccSmrg	$opt_dry_run || {
498788de56ccSmrg	  # Make sure we have at least an empty file.
498888de56ccSmrg	  test -f "$nlist" || : > "$nlist"
498988de56ccSmrg
499088de56ccSmrg	  if test -n "$exclude_expsyms"; then
499188de56ccSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
499288de56ccSmrg	    $MV "$nlist"T "$nlist"
4993b4ee4795Smrg	  fi
499488de56ccSmrg
499588de56ccSmrg	  # Try sorting and uniquifying the output.
499688de56ccSmrg	  if $GREP -v "^: " < "$nlist" |
499788de56ccSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
499888de56ccSmrg		sort -k 3
499988de56ccSmrg	      else
500088de56ccSmrg		sort +2
500188de56ccSmrg	      fi |
500288de56ccSmrg	      uniq > "$nlist"S; then
500388de56ccSmrg	    :
5004b4ee4795Smrg	  else
500588de56ccSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006b4ee4795Smrg	  fi
50071ab64890Smrg
500888de56ccSmrg	  if test -f "$nlist"S; then
500988de56ccSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010b4ee4795Smrg	  else
5011e9fcaa8aSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012b4ee4795Smrg	  fi
50131ab64890Smrg
5014862bcd1aSmrg	  func_show_eval '$RM "${nlist}I"'
5015862bcd1aSmrg	  if test -n "$global_symbol_to_import"; then
5016862bcd1aSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017862bcd1aSmrg	  fi
5018862bcd1aSmrg
5019e9fcaa8aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
50201ab64890Smrg
502188de56ccSmrg/* The mapping between symbol names and symbols.  */
502288de56ccSmrgtypedef struct {
502388de56ccSmrg  const char *name;
502488de56ccSmrg  void *address;
502588de56ccSmrg} lt_dlsymlist;
5026e9fcaa8aSmrgextern LT_DLSYM_CONST lt_dlsymlist
5027862bcd1aSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028862bcd1aSmrg"
5029862bcd1aSmrg
5030862bcd1aSmrg	  if test -s "$nlist"I; then
5031862bcd1aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032862bcd1aSmrgstatic void lt_syminit(void)
5033862bcd1aSmrg{
5034862bcd1aSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035862bcd1aSmrg  for (; symbol->name; ++symbol)
5036862bcd1aSmrg    {"
5037862bcd1aSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038862bcd1aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039862bcd1aSmrg    }
5040862bcd1aSmrg}"
5041862bcd1aSmrg	  fi
5042862bcd1aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5043e9fcaa8aSmrgLT_DLSYM_CONST lt_dlsymlist
504488de56ccSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045862bcd1aSmrg{ {\"$my_originator\", (void *) 0},"
5046862bcd1aSmrg
5047862bcd1aSmrg	  if test -s "$nlist"I; then
5048862bcd1aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049862bcd1aSmrg  {\"@INIT@\", (void *) &lt_syminit},"
5050862bcd1aSmrg	  fi
50511ab64890Smrg
505288de56ccSmrg	  case $need_lib_prefix in
505388de56ccSmrg	  no)
505488de56ccSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
505588de56ccSmrg	    ;;
505688de56ccSmrg	  *)
505788de56ccSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
505888de56ccSmrg	    ;;
505988de56ccSmrg	  esac
5060e9fcaa8aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
506188de56ccSmrg  {0, (void *) 0}
506288de56ccSmrg};
50631ab64890Smrg
506488de56ccSmrg/* This works around a problem in FreeBSD linker */
506588de56ccSmrg#ifdef FREEBSD_WORKAROUND
506688de56ccSmrgstatic const void *lt_preloaded_setup() {
506788de56ccSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
506888de56ccSmrg}
506988de56ccSmrg#endif
507088de56ccSmrg
507188de56ccSmrg#ifdef __cplusplus
507288de56ccSmrg}
507388de56ccSmrg#endif\
507488de56ccSmrg"
507588de56ccSmrg	} # !$opt_dry_run
507688de56ccSmrg
507788de56ccSmrg	pic_flag_for_symtable=
507888de56ccSmrg	case "$compile_command " in
507988de56ccSmrg	*" -static "*) ;;
508088de56ccSmrg	*)
508188de56ccSmrg	  case $host in
508288de56ccSmrg	  # compiling the symbol table file with pic_flag works around
508388de56ccSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
508488de56ccSmrg	  # linked before any other PIC object.  But we must not use
508588de56ccSmrg	  # pic_flag when linking with -static.  The problem exists in
508688de56ccSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087eb411b4bSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
508888de56ccSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
508988de56ccSmrg	  *-*-hpux*)
509088de56ccSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
509188de56ccSmrg	  *)
5092862bcd1aSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
509388de56ccSmrg	    ;;
509488de56ccSmrg	  esac
509588de56ccSmrg	  ;;
509688de56ccSmrg	esac
509788de56ccSmrg	symtab_cflags=
509888de56ccSmrg	for arg in $LTCFLAGS; do
509988de56ccSmrg	  case $arg in
510088de56ccSmrg	  -pie | -fpie | -fPIE) ;;
5101e9fcaa8aSmrg	  *) func_append symtab_cflags " $arg" ;;
510288de56ccSmrg	  esac
510388de56ccSmrg	done
51041ab64890Smrg
510588de56ccSmrg	# Now compile the dynamic symbol file.
510688de56ccSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
51072e9c7c8cSmrg
510888de56ccSmrg	# Clean up the generated files.
5109862bcd1aSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
51101ab64890Smrg
511188de56ccSmrg	# Transform the symbol file into the correct name.
5112862bcd1aSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
511388de56ccSmrg	case $host in
511488de56ccSmrg	*cygwin* | *mingw* | *cegcc* )
511588de56ccSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
5116e9fcaa8aSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5117e9fcaa8aSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511888de56ccSmrg	  else
5119e9fcaa8aSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5120e9fcaa8aSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5121b4ee4795Smrg	  fi
512288de56ccSmrg	  ;;
512388de56ccSmrg	*)
5124e9fcaa8aSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5125e9fcaa8aSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512688de56ccSmrg	  ;;
512788de56ccSmrg	esac
512888de56ccSmrg	;;
512988de56ccSmrg      *)
5130862bcd1aSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
513188de56ccSmrg	;;
513288de56ccSmrg      esac
513388de56ccSmrg    else
513488de56ccSmrg      # We keep going just in case the user didn't refer to
513588de56ccSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
513688de56ccSmrg      # really was required.
51371ab64890Smrg
513888de56ccSmrg      # Nullify the symbol file.
5139e9fcaa8aSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5140e9fcaa8aSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
514188de56ccSmrg    fi
514288de56ccSmrg}
51432e9c7c8cSmrg
5144862bcd1aSmrg# func_cygming_gnu_implib_p ARG
5145862bcd1aSmrg# This predicate returns with zero status (TRUE) if
5146862bcd1aSmrg# ARG is a GNU/binutils-style import library. Returns
5147862bcd1aSmrg# with nonzero status (FALSE) otherwise.
5148862bcd1aSmrgfunc_cygming_gnu_implib_p ()
5149862bcd1aSmrg{
5150862bcd1aSmrg  $debug_cmd
5151862bcd1aSmrg
5152862bcd1aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153862bcd1aSmrg  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)$'`
5154862bcd1aSmrg  test -n "$func_cygming_gnu_implib_tmp"
5155862bcd1aSmrg}
5156862bcd1aSmrg
5157862bcd1aSmrg# func_cygming_ms_implib_p ARG
5158862bcd1aSmrg# This predicate returns with zero status (TRUE) if
5159862bcd1aSmrg# ARG is an MS-style import library. Returns
5160862bcd1aSmrg# with nonzero status (FALSE) otherwise.
5161862bcd1aSmrgfunc_cygming_ms_implib_p ()
5162862bcd1aSmrg{
5163862bcd1aSmrg  $debug_cmd
5164862bcd1aSmrg
5165862bcd1aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166862bcd1aSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167862bcd1aSmrg  test -n "$func_cygming_ms_implib_tmp"
5168862bcd1aSmrg}
5169862bcd1aSmrg
517088de56ccSmrg# func_win32_libid arg
517188de56ccSmrg# return the library type of file 'arg'
517288de56ccSmrg#
517388de56ccSmrg# Need a lot of goo to handle *both* DLLs and import libs
517488de56ccSmrg# Has to be a shell function in order to 'eat' the argument
517588de56ccSmrg# that is supplied when $file_magic_command is called.
5176e9fcaa8aSmrg# Despite the name, also deal with 64 bit binaries.
517788de56ccSmrgfunc_win32_libid ()
517888de56ccSmrg{
5179862bcd1aSmrg  $debug_cmd
5180862bcd1aSmrg
5181862bcd1aSmrg  win32_libid_type=unknown
518288de56ccSmrg  win32_fileres=`file -L $1 2>/dev/null`
518388de56ccSmrg  case $win32_fileres in
518488de56ccSmrg  *ar\ archive\ import\ library*) # definitely import
518588de56ccSmrg    win32_libid_type="x86 archive import"
518688de56ccSmrg    ;;
518788de56ccSmrg  *ar\ archive*) # could be an import, or static
5188e9fcaa8aSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
518988de56ccSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5190e9fcaa8aSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191862bcd1aSmrg      case $nm_interface in
5192862bcd1aSmrg      "MS dumpbin")
5193862bcd1aSmrg	if func_cygming_ms_implib_p "$1" ||
5194862bcd1aSmrg	   func_cygming_gnu_implib_p "$1"
5195862bcd1aSmrg	then
5196862bcd1aSmrg	  win32_nmres=import
5197862bcd1aSmrg	else
5198862bcd1aSmrg	  win32_nmres=
5199862bcd1aSmrg	fi
5200862bcd1aSmrg	;;
5201862bcd1aSmrg      *)
5202862bcd1aSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203862bcd1aSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204862bcd1aSmrg	  $SED -n -e '
520588de56ccSmrg	    1,100{
520688de56ccSmrg		/ I /{
5207862bcd1aSmrg		    s|.*|import|
520888de56ccSmrg		    p
520988de56ccSmrg		    q
521088de56ccSmrg		}
521188de56ccSmrg	    }'`
5212862bcd1aSmrg	;;
5213862bcd1aSmrg      esac
521488de56ccSmrg      case $win32_nmres in
521588de56ccSmrg      import*)  win32_libid_type="x86 archive import";;
521688de56ccSmrg      *)        win32_libid_type="x86 archive static";;
521788de56ccSmrg      esac
521888de56ccSmrg    fi
521988de56ccSmrg    ;;
522088de56ccSmrg  *DLL*)
522188de56ccSmrg    win32_libid_type="x86 DLL"
522288de56ccSmrg    ;;
522388de56ccSmrg  *executable*) # but shell scripts are "executable" too...
522488de56ccSmrg    case $win32_fileres in
522588de56ccSmrg    *MS\ Windows\ PE\ Intel*)
522688de56ccSmrg      win32_libid_type="x86 DLL"
522788de56ccSmrg      ;;
522888de56ccSmrg    esac
522988de56ccSmrg    ;;
523088de56ccSmrg  esac
523188de56ccSmrg  $ECHO "$win32_libid_type"
523288de56ccSmrg}
52332e9c7c8cSmrg
5234e9fcaa8aSmrg# func_cygming_dll_for_implib ARG
5235e9fcaa8aSmrg#
5236e9fcaa8aSmrg# Platform-specific function to extract the
5237e9fcaa8aSmrg# name of the DLL associated with the specified
5238e9fcaa8aSmrg# import library ARG.
5239e9fcaa8aSmrg# Invoked by eval'ing the libtool variable
5240e9fcaa8aSmrg#    $sharedlib_from_linklib_cmd
5241e9fcaa8aSmrg# Result is available in the variable
5242e9fcaa8aSmrg#    $sharedlib_from_linklib_result
5243e9fcaa8aSmrgfunc_cygming_dll_for_implib ()
5244e9fcaa8aSmrg{
5245862bcd1aSmrg  $debug_cmd
5246862bcd1aSmrg
5247e9fcaa8aSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5248e9fcaa8aSmrg}
5249e9fcaa8aSmrg
5250e9fcaa8aSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5251e9fcaa8aSmrg#
5252e9fcaa8aSmrg# The is the core of a fallback implementation of a
5253e9fcaa8aSmrg# platform-specific function to extract the name of the
5254e9fcaa8aSmrg# DLL associated with the specified import library LIBNAME.
5255e9fcaa8aSmrg#
5256e9fcaa8aSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5257e9fcaa8aSmrg# on the platform and compiler that created the implib.
5258e9fcaa8aSmrg#
5259e9fcaa8aSmrg# Echos the name of the DLL associated with the
5260e9fcaa8aSmrg# specified import library.
5261e9fcaa8aSmrgfunc_cygming_dll_for_implib_fallback_core ()
5262e9fcaa8aSmrg{
5263862bcd1aSmrg  $debug_cmd
5264862bcd1aSmrg
5265e9fcaa8aSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5266e9fcaa8aSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5267e9fcaa8aSmrg    $SED '/^Contents of section '"$match_literal"':/{
5268e9fcaa8aSmrg      # Place marker at beginning of archive member dllname section
5269e9fcaa8aSmrg      s/.*/====MARK====/
5270e9fcaa8aSmrg      p
5271e9fcaa8aSmrg      d
5272e9fcaa8aSmrg    }
5273e9fcaa8aSmrg    # These lines can sometimes be longer than 43 characters, but
5274e9fcaa8aSmrg    # are always uninteresting
5275e9fcaa8aSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5276e9fcaa8aSmrg    /^In archive [^:]*:/d
5277e9fcaa8aSmrg    # Ensure marker is printed
5278e9fcaa8aSmrg    /^====MARK====/p
5279e9fcaa8aSmrg    # Remove all lines with less than 43 characters
5280e9fcaa8aSmrg    /^.\{43\}/!d
5281e9fcaa8aSmrg    # From remaining lines, remove first 43 characters
5282e9fcaa8aSmrg    s/^.\{43\}//' |
5283e9fcaa8aSmrg    $SED -n '
5284e9fcaa8aSmrg      # Join marker and all lines until next marker into a single line
5285e9fcaa8aSmrg      /^====MARK====/ b para
5286e9fcaa8aSmrg      H
5287e9fcaa8aSmrg      $ b para
5288e9fcaa8aSmrg      b
5289e9fcaa8aSmrg      :para
5290e9fcaa8aSmrg      x
5291e9fcaa8aSmrg      s/\n//g
5292e9fcaa8aSmrg      # Remove the marker
5293e9fcaa8aSmrg      s/^====MARK====//
5294e9fcaa8aSmrg      # Remove trailing dots and whitespace
5295e9fcaa8aSmrg      s/[\. \t]*$//
5296e9fcaa8aSmrg      # Print
5297e9fcaa8aSmrg      /./p' |
5298e9fcaa8aSmrg    # we now have a list, one entry per line, of the stringified
5299e9fcaa8aSmrg    # contents of the appropriate section of all members of the
5300862bcd1aSmrg    # archive that possess that section. Heuristic: eliminate
5301862bcd1aSmrg    # all those that have a first or second character that is
5302e9fcaa8aSmrg    # a '.' (that is, objdump's representation of an unprintable
5303e9fcaa8aSmrg    # character.) This should work for all archives with less than
5304e9fcaa8aSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5305e9fcaa8aSmrg    # begins with a literal '.' or a single character followed by
5306e9fcaa8aSmrg    # a '.'.
5307e9fcaa8aSmrg    #
5308e9fcaa8aSmrg    # Of those that remain, print the first one.
5309e9fcaa8aSmrg    $SED -e '/^\./d;/^.\./d;q'
5310e9fcaa8aSmrg}
5311e9fcaa8aSmrg
5312e9fcaa8aSmrg# func_cygming_dll_for_implib_fallback ARG
5313e9fcaa8aSmrg# Platform-specific function to extract the
5314e9fcaa8aSmrg# name of the DLL associated with the specified
5315e9fcaa8aSmrg# import library ARG.
5316e9fcaa8aSmrg#
5317e9fcaa8aSmrg# This fallback implementation is for use when $DLLTOOL
5318e9fcaa8aSmrg# does not support the --identify-strict option.
5319e9fcaa8aSmrg# Invoked by eval'ing the libtool variable
5320e9fcaa8aSmrg#    $sharedlib_from_linklib_cmd
5321e9fcaa8aSmrg# Result is available in the variable
5322e9fcaa8aSmrg#    $sharedlib_from_linklib_result
5323e9fcaa8aSmrgfunc_cygming_dll_for_implib_fallback ()
5324e9fcaa8aSmrg{
5325862bcd1aSmrg  $debug_cmd
5326862bcd1aSmrg
5327862bcd1aSmrg  if func_cygming_gnu_implib_p "$1"; then
5328e9fcaa8aSmrg    # binutils import library
5329e9fcaa8aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330862bcd1aSmrg  elif func_cygming_ms_implib_p "$1"; then
5331e9fcaa8aSmrg    # ms-generated import library
5332e9fcaa8aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5333e9fcaa8aSmrg  else
5334e9fcaa8aSmrg    # unknown
5335862bcd1aSmrg    sharedlib_from_linklib_result=
5336e9fcaa8aSmrg  fi
5337e9fcaa8aSmrg}
53382e9c7c8cSmrg
53392e9c7c8cSmrg
534088de56ccSmrg# func_extract_an_archive dir oldlib
534188de56ccSmrgfunc_extract_an_archive ()
534288de56ccSmrg{
5343862bcd1aSmrg    $debug_cmd
5344862bcd1aSmrg
5345862bcd1aSmrg    f_ex_an_ar_dir=$1; shift
5346862bcd1aSmrg    f_ex_an_ar_oldlib=$1
5347862bcd1aSmrg    if test yes = "$lock_old_archive_extraction"; then
5348e9fcaa8aSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5349e9fcaa8aSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5350e9fcaa8aSmrg	func_echo "Waiting for $lockfile to be removed"
5351e9fcaa8aSmrg	sleep 2
5352e9fcaa8aSmrg      done
5353e9fcaa8aSmrg    fi
5354e9fcaa8aSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5355e9fcaa8aSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356862bcd1aSmrg    if test yes = "$lock_old_archive_extraction"; then
5357e9fcaa8aSmrg      $opt_dry_run || rm -f "$lockfile"
5358e9fcaa8aSmrg    fi
535988de56ccSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
536088de56ccSmrg     :
536188de56ccSmrg    else
536288de56ccSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
536388de56ccSmrg    fi
536488de56ccSmrg}
53651ab64890Smrg
53661ab64890Smrg
536788de56ccSmrg# func_extract_archives gentop oldlib ...
536888de56ccSmrgfunc_extract_archives ()
536988de56ccSmrg{
5370862bcd1aSmrg    $debug_cmd
5371862bcd1aSmrg
5372862bcd1aSmrg    my_gentop=$1; shift
537388de56ccSmrg    my_oldlibs=${1+"$@"}
5374862bcd1aSmrg    my_oldobjs=
5375862bcd1aSmrg    my_xlib=
5376862bcd1aSmrg    my_xabs=
5377862bcd1aSmrg    my_xdir=
53781ab64890Smrg
537988de56ccSmrg    for my_xlib in $my_oldlibs; do
538088de56ccSmrg      # Extract the objects.
538188de56ccSmrg      case $my_xlib in
5382862bcd1aSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
538388de56ccSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
538488de56ccSmrg      esac
538588de56ccSmrg      func_basename "$my_xlib"
5386862bcd1aSmrg      my_xlib=$func_basename_result
538788de56ccSmrg      my_xlib_u=$my_xlib
538888de56ccSmrg      while :; do
538988de56ccSmrg        case " $extracted_archives " in
539088de56ccSmrg	*" $my_xlib_u "*)
539188de56ccSmrg	  func_arith $extracted_serial + 1
539288de56ccSmrg	  extracted_serial=$func_arith_result
539388de56ccSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
539488de56ccSmrg	*) break ;;
539588de56ccSmrg	esac
539688de56ccSmrg      done
539788de56ccSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5398862bcd1aSmrg      my_xdir=$my_gentop/$my_xlib_u
53991ab64890Smrg
540088de56ccSmrg      func_mkdir_p "$my_xdir"
54012e9c7c8cSmrg
540288de56ccSmrg      case $host in
540388de56ccSmrg      *-darwin*)
540488de56ccSmrg	func_verbose "Extracting $my_xabs"
540588de56ccSmrg	# Do not bother doing anything if just a dry run
540688de56ccSmrg	$opt_dry_run || {
540788de56ccSmrg	  darwin_orig_dir=`pwd`
540888de56ccSmrg	  cd $my_xdir || exit $?
540988de56ccSmrg	  darwin_archive=$my_xabs
541088de56ccSmrg	  darwin_curdir=`pwd`
5411862bcd1aSmrg	  func_basename "$darwin_archive"
5412862bcd1aSmrg	  darwin_base_archive=$func_basename_result
541388de56ccSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
541488de56ccSmrg	  if test -n "$darwin_arches"; then
541588de56ccSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
541688de56ccSmrg	    darwin_arch=
541788de56ccSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418862bcd1aSmrg	    for darwin_arch in  $darwin_arches; do
5419862bcd1aSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420862bcd1aSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421862bcd1aSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422862bcd1aSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
542388de56ccSmrg	      cd "$darwin_curdir"
5424862bcd1aSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
542588de56ccSmrg	    done # $darwin_arches
542688de56ccSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427862bcd1aSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
542888de56ccSmrg	    darwin_file=
542988de56ccSmrg	    darwin_files=
543088de56ccSmrg	    for darwin_file in $darwin_filelist; do
5431e9fcaa8aSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
543288de56ccSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
543388de56ccSmrg	    done # $darwin_filelist
543488de56ccSmrg	    $RM -rf unfat-$$
543588de56ccSmrg	    cd "$darwin_orig_dir"
5436b4ee4795Smrg	  else
543788de56ccSmrg	    cd $darwin_orig_dir
543888de56ccSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
543988de56ccSmrg	  fi # $darwin_arches
544088de56ccSmrg	} # !$opt_dry_run
544188de56ccSmrg	;;
544288de56ccSmrg      *)
544388de56ccSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
544488de56ccSmrg	;;
544588de56ccSmrg      esac
5446e9fcaa8aSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
544788de56ccSmrg    done
54481ab64890Smrg
5449862bcd1aSmrg    func_extract_archives_result=$my_oldobjs
545088de56ccSmrg}
54511ab64890Smrg
54521ab64890Smrg
5453e9fcaa8aSmrg# func_emit_wrapper [arg=no]
5454e9fcaa8aSmrg#
5455e9fcaa8aSmrg# Emit a libtool wrapper script on stdout.
5456e9fcaa8aSmrg# Don't directly open a file because we may want to
5457e9fcaa8aSmrg# incorporate the script contents within a cygwin/mingw
5458e9fcaa8aSmrg# wrapper executable.  Must ONLY be called from within
5459e9fcaa8aSmrg# func_mode_link because it depends on a number of variables
5460e9fcaa8aSmrg# set therein.
546188de56ccSmrg#
5462e9fcaa8aSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5463e9fcaa8aSmrg# variable will take.  If 'yes', then the emitted script
5464862bcd1aSmrg# will assume that the directory where it is stored is
5465e9fcaa8aSmrg# the $objdir directory.  This is a cygwin/mingw-specific
5466e9fcaa8aSmrg# behavior.
5467e9fcaa8aSmrgfunc_emit_wrapper ()
546888de56ccSmrg{
5469e9fcaa8aSmrg	func_emit_wrapper_arg1=${1-no}
5470b4ee4795Smrg
547188de56ccSmrg	$ECHO "\
547288de56ccSmrg#! $SHELL
54731ab64890Smrg
547488de56ccSmrg# $output - temporary wrapper script for $objdir/$outputname
5475862bcd1aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
547688de56ccSmrg#
547788de56ccSmrg# The $output program cannot be directly executed until all the libtool
547888de56ccSmrg# libraries that it depends on are installed.
547988de56ccSmrg#
548088de56ccSmrg# This wrapper script should never be moved out of the build directory.
548188de56ccSmrg# If it is, it will not operate correctly.
54821ab64890Smrg
548388de56ccSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
548488de56ccSmrg# metacharacters that are still active within double-quoted strings.
548588de56ccSmrgsed_quote_subst='$sed_quote_subst'
54861ab64890Smrg
548788de56ccSmrg# Be Bourne compatible
548888de56ccSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
548988de56ccSmrg  emulate sh
549088de56ccSmrg  NULLCMD=:
549188de56ccSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
549288de56ccSmrg  # is contrary to our usage.  Disable this feature.
549388de56ccSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
549488de56ccSmrg  setopt NO_GLOB_SUBST
549588de56ccSmrgelse
549688de56ccSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
549788de56ccSmrgfi
549888de56ccSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
549988de56ccSmrgDUALCASE=1; export DUALCASE # for MKS sh
55001ab64890Smrg
550188de56ccSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
550288de56ccSmrg# if CDPATH is set.
550388de56ccSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
55041ab64890Smrg
550588de56ccSmrgrelink_command=\"$relink_command\"
55061ab64890Smrg
550788de56ccSmrg# This environment variable determines our operation mode.
550888de56ccSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
550988de56ccSmrg  # install mode needs the following variables:
551088de56ccSmrg  generated_by_libtool_version='$macro_version'
551188de56ccSmrg  notinst_deplibs='$notinst_deplibs'
551288de56ccSmrgelse
551388de56ccSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
551488de56ccSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5515e9fcaa8aSmrg    file=\"\$0\""
5516e9fcaa8aSmrg
5517e9628295Smrg    func_quote_arg pretty "$ECHO"
5518e9628295Smrg    qECHO=$func_quote_arg_result
5519e9fcaa8aSmrg    $ECHO "\
5520e9fcaa8aSmrg
5521e9fcaa8aSmrg# A function that is used when there is no print builtin or printf.
5522e9fcaa8aSmrgfunc_fallback_echo ()
5523e9fcaa8aSmrg{
5524e9fcaa8aSmrg  eval 'cat <<_LTECHO_EOF
5525e9fcaa8aSmrg\$1
5526e9fcaa8aSmrg_LTECHO_EOF'
5527e9fcaa8aSmrg}
5528e9628295Smrg    ECHO=$qECHO
5529e9fcaa8aSmrg  fi
5530e9fcaa8aSmrg
5531e9fcaa8aSmrg# Very basic option parsing. These options are (a) specific to
5532e9fcaa8aSmrg# the libtool wrapper, (b) are identical between the wrapper
5533862bcd1aSmrg# /script/ and the wrapper /executable/ that is used only on
5534e9fcaa8aSmrg# windows platforms, and (c) all begin with the string "--lt-"
5535862bcd1aSmrg# (application programs are unlikely to have options that match
5536e9fcaa8aSmrg# this pattern).
5537e9fcaa8aSmrg#
5538e9fcaa8aSmrg# There are only two supported options: --lt-debug and
5539e9fcaa8aSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5540e9fcaa8aSmrg#
5541e9fcaa8aSmrg# The first argument to this parsing function should be the
5542e9fcaa8aSmrg# script's $0 value, followed by "$@".
5543e9fcaa8aSmrglt_option_debug=
5544e9fcaa8aSmrgfunc_parse_lt_options ()
5545e9fcaa8aSmrg{
5546e9fcaa8aSmrg  lt_script_arg0=\$0
5547e9fcaa8aSmrg  shift
5548e9fcaa8aSmrg  for lt_opt
5549e9fcaa8aSmrg  do
5550e9fcaa8aSmrg    case \"\$lt_opt\" in
5551e9fcaa8aSmrg    --lt-debug) lt_option_debug=1 ;;
5552e9fcaa8aSmrg    --lt-dump-script)
5553e9fcaa8aSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5554e9fcaa8aSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5555e9fcaa8aSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5556e9fcaa8aSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5557e9fcaa8aSmrg        exit 0
5558e9fcaa8aSmrg      ;;
5559e9fcaa8aSmrg    --lt-*)
5560e9fcaa8aSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5561e9fcaa8aSmrg        exit 1
5562e9fcaa8aSmrg      ;;
5563e9fcaa8aSmrg    esac
5564e9fcaa8aSmrg  done
5565e9fcaa8aSmrg
5566e9fcaa8aSmrg  # Print the debug banner immediately:
5567e9fcaa8aSmrg  if test -n \"\$lt_option_debug\"; then
5568862bcd1aSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5569e9fcaa8aSmrg  fi
5570e9fcaa8aSmrg}
5571e9fcaa8aSmrg
5572e9fcaa8aSmrg# Used when --lt-debug. Prints its arguments to stdout
5573e9fcaa8aSmrg# (redirection is the responsibility of the caller)
5574e9fcaa8aSmrgfunc_lt_dump_args ()
5575e9fcaa8aSmrg{
5576e9fcaa8aSmrg  lt_dump_args_N=1;
5577e9fcaa8aSmrg  for lt_arg
5578e9fcaa8aSmrg  do
5579862bcd1aSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5580e9fcaa8aSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5581e9fcaa8aSmrg  done
5582e9fcaa8aSmrg}
5583e9fcaa8aSmrg
5584e9fcaa8aSmrg# Core function for launching the target application
5585e9fcaa8aSmrgfunc_exec_program_core ()
5586e9fcaa8aSmrg{
558788de56ccSmrg"
5588e9fcaa8aSmrg  case $host in
5589e9fcaa8aSmrg  # Backslashes separate directories on plain windows
5590e9fcaa8aSmrg  *-*-mingw | *-*-os2* | *-cegcc*)
5591e9fcaa8aSmrg    $ECHO "\
5592e9fcaa8aSmrg      if test -n \"\$lt_option_debug\"; then
5593862bcd1aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5594e9fcaa8aSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5595e9fcaa8aSmrg      fi
5596e9fcaa8aSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5597e9fcaa8aSmrg"
5598e9fcaa8aSmrg    ;;
5599e9fcaa8aSmrg
5600e9fcaa8aSmrg  *)
5601e9fcaa8aSmrg    $ECHO "\
5602e9fcaa8aSmrg      if test -n \"\$lt_option_debug\"; then
5603862bcd1aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5604e9fcaa8aSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5605e9fcaa8aSmrg      fi
5606e9fcaa8aSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5607e9fcaa8aSmrg"
5608e9fcaa8aSmrg    ;;
5609e9fcaa8aSmrg  esac
5610e9fcaa8aSmrg  $ECHO "\
5611e9fcaa8aSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5612e9fcaa8aSmrg      exit 1
5613e9fcaa8aSmrg}
5614e9fcaa8aSmrg
5615e9fcaa8aSmrg# A function to encapsulate launching the target application
5616e9fcaa8aSmrg# Strips options in the --lt-* namespace from \$@ and
5617e9fcaa8aSmrg# launches target application with the remaining arguments.
5618e9fcaa8aSmrgfunc_exec_program ()
5619e9fcaa8aSmrg{
5620eb411b4bSmrg  case \" \$* \" in
5621eb411b4bSmrg  *\\ --lt-*)
5622eb411b4bSmrg    for lt_wr_arg
5623eb411b4bSmrg    do
5624eb411b4bSmrg      case \$lt_wr_arg in
5625eb411b4bSmrg      --lt-*) ;;
5626eb411b4bSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627eb411b4bSmrg      esac
5628eb411b4bSmrg      shift
5629eb411b4bSmrg    done ;;
5630eb411b4bSmrg  esac
5631e9fcaa8aSmrg  func_exec_program_core \${1+\"\$@\"}
5632e9fcaa8aSmrg}
5633e9fcaa8aSmrg
5634e9fcaa8aSmrg  # Parse options
5635e9fcaa8aSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
56361ab64890Smrg
563788de56ccSmrg  # Find the directory that this script lives in.
5638e9fcaa8aSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
563988de56ccSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
56401ab64890Smrg
564188de56ccSmrg  # Follow symbolic links until we get to the real thisdir.
5642e9fcaa8aSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
564388de56ccSmrg  while test -n \"\$file\"; do
5644e9fcaa8aSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
56451ab64890Smrg
564688de56ccSmrg    # If there was a directory component, then change thisdir.
564788de56ccSmrg    if test \"x\$destdir\" != \"x\$file\"; then
564888de56ccSmrg      case \"\$destdir\" in
564988de56ccSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
565088de56ccSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5651b4ee4795Smrg      esac
565288de56ccSmrg    fi
56531ab64890Smrg
5654e9fcaa8aSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5655e9fcaa8aSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
565688de56ccSmrg  done
56571ab64890Smrg
565888de56ccSmrg  # Usually 'no', except on cygwin/mingw when embedded into
565988de56ccSmrg  # the cwrapper.
5660e9fcaa8aSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
566188de56ccSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
566288de56ccSmrg    # special case for '.'
566388de56ccSmrg    if test \"\$thisdir\" = \".\"; then
566488de56ccSmrg      thisdir=\`pwd\`
566588de56ccSmrg    fi
566688de56ccSmrg    # remove .libs from thisdir
566788de56ccSmrg    case \"\$thisdir\" in
5668e9fcaa8aSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
566988de56ccSmrg    $objdir )   thisdir=. ;;
567088de56ccSmrg    esac
567188de56ccSmrg  fi
567288de56ccSmrg
567388de56ccSmrg  # Try to get the absolute directory name.
567488de56ccSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
567588de56ccSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
567688de56ccSmrg"
567788de56ccSmrg
5678862bcd1aSmrg	if test yes = "$fast_install"; then
567988de56ccSmrg	  $ECHO "\
568088de56ccSmrg  program=lt-'$outputname'$exeext
568188de56ccSmrg  progdir=\"\$thisdir/$objdir\"
568288de56ccSmrg
568388de56ccSmrg  if test ! -f \"\$progdir/\$program\" ||
5684862bcd1aSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
568588de56ccSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
568688de56ccSmrg
568788de56ccSmrg    file=\"\$\$-\$program\"
568888de56ccSmrg
568988de56ccSmrg    if test ! -d \"\$progdir\"; then
569088de56ccSmrg      $MKDIR \"\$progdir\"
569188de56ccSmrg    else
569288de56ccSmrg      $RM \"\$progdir/\$file\"
569388de56ccSmrg    fi"
569488de56ccSmrg
569588de56ccSmrg	  $ECHO "\
569688de56ccSmrg
569788de56ccSmrg    # relink executable if necessary
569888de56ccSmrg    if test -n \"\$relink_command\"; then
569988de56ccSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
570088de56ccSmrg      else
5701862bcd1aSmrg	\$ECHO \"\$relink_command_output\" >&2
570288de56ccSmrg	$RM \"\$progdir/\$file\"
570388de56ccSmrg	exit 1
5704b4ee4795Smrg      fi
570588de56ccSmrg    fi
57061ab64890Smrg
570788de56ccSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
570888de56ccSmrg    { $RM \"\$progdir/\$program\";
570988de56ccSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
571088de56ccSmrg    $RM \"\$progdir/\$file\"
571188de56ccSmrg  fi"
571288de56ccSmrg	else
571388de56ccSmrg	  $ECHO "\
571488de56ccSmrg  program='$outputname'
571588de56ccSmrg  progdir=\"\$thisdir/$objdir\"
571688de56ccSmrg"
5717b4ee4795Smrg	fi
57181ab64890Smrg
571988de56ccSmrg	$ECHO "\
57201ab64890Smrg
572188de56ccSmrg  if test -f \"\$progdir/\$program\"; then"
57221ab64890Smrg
5723e9fcaa8aSmrg	# fixup the dll searchpath if we need to.
5724e9fcaa8aSmrg	#
5725e9fcaa8aSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5726e9fcaa8aSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5727e9fcaa8aSmrg	# libraries must come first.
5728e9fcaa8aSmrg	if test -n "$dllsearchpath"; then
5729e9fcaa8aSmrg	  $ECHO "\
5730e9fcaa8aSmrg    # Add the dll search path components to the executable PATH
5731e9fcaa8aSmrg    PATH=$dllsearchpath:\$PATH
5732e9fcaa8aSmrg"
5733e9fcaa8aSmrg	fi
5734e9fcaa8aSmrg
573588de56ccSmrg	# Export our shlibpath_var if we have one.
5736862bcd1aSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
573788de56ccSmrg	  $ECHO "\
573888de56ccSmrg    # Add our own library path to $shlibpath_var
573988de56ccSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
574088de56ccSmrg
574188de56ccSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
574288de56ccSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
5743e9fcaa8aSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
57441ab64890Smrg
574588de56ccSmrg    export $shlibpath_var
574688de56ccSmrg"
5747b4ee4795Smrg	fi
57481ab64890Smrg
574988de56ccSmrg	$ECHO "\
575088de56ccSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
575188de56ccSmrg      # Run the actual program with our arguments.
5752e9fcaa8aSmrg      func_exec_program \${1+\"\$@\"}
575388de56ccSmrg    fi
575488de56ccSmrg  else
575588de56ccSmrg    # The program doesn't exist.
5756862bcd1aSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
575788de56ccSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5758e9fcaa8aSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
575988de56ccSmrg    exit 1
576088de56ccSmrg  fi
576188de56ccSmrgfi\
576288de56ccSmrg"
576388de56ccSmrg}
57641ab64890Smrg
57651ab64890Smrg
576688de56ccSmrg# func_emit_cwrapperexe_src
576788de56ccSmrg# emit the source code for a wrapper executable on stdout
576888de56ccSmrg# Must ONLY be called from within func_mode_link because
576988de56ccSmrg# it depends on a number of variable set therein.
577088de56ccSmrgfunc_emit_cwrapperexe_src ()
577188de56ccSmrg{
577288de56ccSmrg	cat <<EOF
57731ab64890Smrg
577488de56ccSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775862bcd1aSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
57761ab64890Smrg
577788de56ccSmrg   The $output program cannot be directly executed until all the libtool
577888de56ccSmrg   libraries that it depends on are installed.
57791ab64890Smrg
578088de56ccSmrg   This wrapper executable should never be moved out of the build directory.
578188de56ccSmrg   If it is, it will not operate correctly.
578288de56ccSmrg*/
578388de56ccSmrgEOF
578488de56ccSmrg	    cat <<"EOF"
5785e9fcaa8aSmrg#ifdef _MSC_VER
5786e9fcaa8aSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5787e9fcaa8aSmrg#endif
578888de56ccSmrg#include <stdio.h>
578988de56ccSmrg#include <stdlib.h>
579088de56ccSmrg#ifdef _MSC_VER
579188de56ccSmrg# include <direct.h>
579288de56ccSmrg# include <process.h>
579388de56ccSmrg# include <io.h>
579488de56ccSmrg#else
579588de56ccSmrg# include <unistd.h>
579688de56ccSmrg# include <stdint.h>
579788de56ccSmrg# ifdef __CYGWIN__
579888de56ccSmrg#  include <io.h>
5799e9fcaa8aSmrg# endif
5800e9fcaa8aSmrg#endif
5801e9fcaa8aSmrg#include <malloc.h>
5802e9fcaa8aSmrg#include <stdarg.h>
5803e9fcaa8aSmrg#include <assert.h>
5804e9fcaa8aSmrg#include <string.h>
5805e9fcaa8aSmrg#include <ctype.h>
5806e9fcaa8aSmrg#include <errno.h>
5807e9fcaa8aSmrg#include <fcntl.h>
5808e9fcaa8aSmrg#include <sys/stat.h>
5809e9fcaa8aSmrg
5810862bcd1aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811862bcd1aSmrg
5812e9fcaa8aSmrg/* declarations of non-ANSI functions */
5813862bcd1aSmrg#if defined __MINGW32__
5814e9fcaa8aSmrg# ifdef __STRICT_ANSI__
5815e9fcaa8aSmrgint _putenv (const char *);
5816e9fcaa8aSmrg# endif
5817862bcd1aSmrg#elif defined __CYGWIN__
5818e9fcaa8aSmrg# ifdef __STRICT_ANSI__
581988de56ccSmrgchar *realpath (const char *, char *);
582088de56ccSmrgint putenv (char *);
582188de56ccSmrgint setenv (const char *, const char *, int);
582288de56ccSmrg# endif
5823862bcd1aSmrg/* #elif defined other_platform || defined ... */
5824e9fcaa8aSmrg#endif
5825e9fcaa8aSmrg
5826e9fcaa8aSmrg/* portability defines, excluding path handling macros */
5827862bcd1aSmrg#if defined _MSC_VER
5828e9fcaa8aSmrg# define setmode _setmode
5829e9fcaa8aSmrg# define stat    _stat
5830e9fcaa8aSmrg# define chmod   _chmod
5831e9fcaa8aSmrg# define getcwd  _getcwd
5832e9fcaa8aSmrg# define putenv  _putenv
5833e9fcaa8aSmrg# define S_IXUSR _S_IEXEC
5834862bcd1aSmrg#elif defined __MINGW32__
5835e9fcaa8aSmrg# define setmode _setmode
5836e9fcaa8aSmrg# define stat    _stat
5837e9fcaa8aSmrg# define chmod   _chmod
5838e9fcaa8aSmrg# define getcwd  _getcwd
5839e9fcaa8aSmrg# define putenv  _putenv
5840862bcd1aSmrg#elif defined __CYGWIN__
5841e9fcaa8aSmrg# define HAVE_SETENV
5842e9fcaa8aSmrg# define FOPEN_WB "wb"
5843862bcd1aSmrg/* #elif defined other platforms ... */
584488de56ccSmrg#endif
58451ab64890Smrg
5846862bcd1aSmrg#if defined PATH_MAX
584788de56ccSmrg# define LT_PATHMAX PATH_MAX
5848862bcd1aSmrg#elif defined MAXPATHLEN
584988de56ccSmrg# define LT_PATHMAX MAXPATHLEN
585088de56ccSmrg#else
585188de56ccSmrg# define LT_PATHMAX 1024
585288de56ccSmrg#endif
58531ab64890Smrg
585488de56ccSmrg#ifndef S_IXOTH
585588de56ccSmrg# define S_IXOTH 0
585688de56ccSmrg#endif
585788de56ccSmrg#ifndef S_IXGRP
585888de56ccSmrg# define S_IXGRP 0
585988de56ccSmrg#endif
58601ab64890Smrg
5861e9fcaa8aSmrg/* path handling portability macros */
586288de56ccSmrg#ifndef DIR_SEPARATOR
586388de56ccSmrg# define DIR_SEPARATOR '/'
586488de56ccSmrg# define PATH_SEPARATOR ':'
586588de56ccSmrg#endif
58661ab64890Smrg
5867862bcd1aSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868862bcd1aSmrg  defined __OS2__
586988de56ccSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
587088de56ccSmrg# define FOPEN_WB "wb"
587188de56ccSmrg# ifndef DIR_SEPARATOR_2
587288de56ccSmrg#  define DIR_SEPARATOR_2 '\\'
587388de56ccSmrg# endif
587488de56ccSmrg# ifndef PATH_SEPARATOR_2
587588de56ccSmrg#  define PATH_SEPARATOR_2 ';'
587688de56ccSmrg# endif
587788de56ccSmrg#endif
58781ab64890Smrg
587988de56ccSmrg#ifndef DIR_SEPARATOR_2
588088de56ccSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
588188de56ccSmrg#else /* DIR_SEPARATOR_2 */
588288de56ccSmrg# define IS_DIR_SEPARATOR(ch) \
588388de56ccSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
588488de56ccSmrg#endif /* DIR_SEPARATOR_2 */
58851ab64890Smrg
588688de56ccSmrg#ifndef PATH_SEPARATOR_2
588788de56ccSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
588888de56ccSmrg#else /* PATH_SEPARATOR_2 */
588988de56ccSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
589088de56ccSmrg#endif /* PATH_SEPARATOR_2 */
58911ab64890Smrg
589288de56ccSmrg#ifndef FOPEN_WB
589388de56ccSmrg# define FOPEN_WB "w"
589488de56ccSmrg#endif
589588de56ccSmrg#ifndef _O_BINARY
589688de56ccSmrg# define _O_BINARY 0
589788de56ccSmrg#endif
58981ab64890Smrg
589988de56ccSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
590088de56ccSmrg#define XFREE(stale) do { \
5901862bcd1aSmrg  if (stale) { free (stale); stale = 0; } \
590288de56ccSmrg} while (0)
59031ab64890Smrg
5904862bcd1aSmrg#if defined LT_DEBUGWRAPPER
5905e9fcaa8aSmrgstatic int lt_debug = 1;
590688de56ccSmrg#else
5907e9fcaa8aSmrgstatic int lt_debug = 0;
590888de56ccSmrg#endif
59091ab64890Smrg
5910e9fcaa8aSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
59111ab64890Smrg
591288de56ccSmrgvoid *xmalloc (size_t num);
591388de56ccSmrgchar *xstrdup (const char *string);
591488de56ccSmrgconst char *base_name (const char *name);
591588de56ccSmrgchar *find_executable (const char *wrapper);
591688de56ccSmrgchar *chase_symlinks (const char *pathspec);
591788de56ccSmrgint make_executable (const char *path);
591888de56ccSmrgint check_executable (const char *path);
591988de56ccSmrgchar *strendzap (char *str, const char *pat);
5920e9fcaa8aSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5921e9fcaa8aSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5922e9fcaa8aSmrgstatic const char *nonnull (const char *s);
5923e9fcaa8aSmrgstatic const char *nonempty (const char *s);
592488de56ccSmrgvoid lt_setenv (const char *name, const char *value);
592588de56ccSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
592688de56ccSmrgvoid lt_update_exe_path (const char *name, const char *value);
592788de56ccSmrgvoid lt_update_lib_path (const char *name, const char *value);
5928e9fcaa8aSmrgchar **prepare_spawn (char **argv);
5929e9fcaa8aSmrgvoid lt_dump_script (FILE *f);
593088de56ccSmrgEOF
593188de56ccSmrg
593288de56ccSmrg	    cat <<EOF
5933862bcd1aSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934862bcd1aSmrg# define externally_visible volatile
5935862bcd1aSmrg#else
5936862bcd1aSmrg# define externally_visible __attribute__((externally_visible)) volatile
5937862bcd1aSmrg#endif
5938862bcd1aSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
593988de56ccSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
594088de56ccSmrgEOF
59411ab64890Smrg
5942862bcd1aSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5943e9fcaa8aSmrg              func_to_host_path "$temp_rpath"
594488de56ccSmrg	      cat <<EOF
5945e9fcaa8aSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
594688de56ccSmrgEOF
594788de56ccSmrg	    else
594888de56ccSmrg	      cat <<"EOF"
594988de56ccSmrgconst char * LIB_PATH_VALUE   = "";
595088de56ccSmrgEOF
5951b4ee4795Smrg	    fi
59521ab64890Smrg
595388de56ccSmrg	    if test -n "$dllsearchpath"; then
5954e9fcaa8aSmrg              func_to_host_path "$dllsearchpath:"
595588de56ccSmrg	      cat <<EOF
595688de56ccSmrgconst char * EXE_PATH_VARNAME = "PATH";
5957e9fcaa8aSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5958b4ee4795SmrgEOF
5959b4ee4795Smrg	    else
596088de56ccSmrg	      cat <<"EOF"
596188de56ccSmrgconst char * EXE_PATH_VARNAME = "";
596288de56ccSmrgconst char * EXE_PATH_VALUE   = "";
596388de56ccSmrgEOF
5964b4ee4795Smrg	    fi
596588de56ccSmrg
5966862bcd1aSmrg	    if test yes = "$fast_install"; then
596788de56ccSmrg	      cat <<EOF
596888de56ccSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
596988de56ccSmrgEOF
5970b4ee4795Smrg	    else
597188de56ccSmrg	      cat <<EOF
597288de56ccSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
597388de56ccSmrgEOF
5974b4ee4795Smrg	    fi
59751ab64890Smrg
59761ab64890Smrg
597788de56ccSmrg	    cat <<"EOF"
59781ab64890Smrg
597988de56ccSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
59801ab64890Smrg
598188de56ccSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
598288de56ccSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5983e9fcaa8aSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
59841ab64890Smrg
598588de56ccSmrgint
598688de56ccSmrgmain (int argc, char *argv[])
598788de56ccSmrg{
598888de56ccSmrg  char **newargz;
598988de56ccSmrg  int  newargc;
599088de56ccSmrg  char *tmp_pathspec;
599188de56ccSmrg  char *actual_cwrapper_path;
599288de56ccSmrg  char *actual_cwrapper_name;
599388de56ccSmrg  char *target_name;
599488de56ccSmrg  char *lt_argv_zero;
5995862bcd1aSmrg  int rval = 127;
59961ab64890Smrg
599788de56ccSmrg  int i;
59981ab64890Smrg
599988de56ccSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000862bcd1aSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
60011ab64890Smrg
6002e9fcaa8aSmrg  /* very simple arg parsing; don't want to rely on getopt
6003e9fcaa8aSmrg   * also, copy all non cwrapper options to newargz, except
6004e9fcaa8aSmrg   * argz[0], which is handled differently
6005e9fcaa8aSmrg   */
6006e9fcaa8aSmrg  newargc=0;
600788de56ccSmrg  for (i = 1; i < argc; i++)
600888de56ccSmrg    {
6009862bcd1aSmrg      if (STREQ (argv[i], dumpscript_opt))
601088de56ccSmrg	{
601188de56ccSmrgEOF
6012862bcd1aSmrg	    case $host in
601388de56ccSmrg	      *mingw* | *cygwin* )
601488de56ccSmrg		# make stdout use "unix" line endings
601588de56ccSmrg		echo "          setmode(1,_O_BINARY);"
601688de56ccSmrg		;;
601788de56ccSmrg	      esac
60181ab64890Smrg
601988de56ccSmrg	    cat <<"EOF"
6020e9fcaa8aSmrg	  lt_dump_script (stdout);
602188de56ccSmrg	  return 0;
602288de56ccSmrg	}
6023862bcd1aSmrg      if (STREQ (argv[i], debug_opt))
6024e9fcaa8aSmrg	{
6025e9fcaa8aSmrg          lt_debug = 1;
6026e9fcaa8aSmrg          continue;
6027e9fcaa8aSmrg	}
6028862bcd1aSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6029e9fcaa8aSmrg        {
6030e9fcaa8aSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6031e9fcaa8aSmrg             namespace, but it is not one of the ones we know about and
6032e9fcaa8aSmrg             have already dealt with, above (inluding dump-script), then
6033e9fcaa8aSmrg             report an error. Otherwise, targets might begin to believe
6034e9fcaa8aSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6035e9fcaa8aSmrg             namespace. The first time any user complains about this, we'll
6036e9fcaa8aSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6037e9fcaa8aSmrg             or a configure.ac-settable value.
6038e9fcaa8aSmrg           */
6039e9fcaa8aSmrg          lt_fatal (__FILE__, __LINE__,
6040e9fcaa8aSmrg		    "unrecognized %s option: '%s'",
6041e9fcaa8aSmrg                    ltwrapper_option_prefix, argv[i]);
6042e9fcaa8aSmrg        }
6043e9fcaa8aSmrg      /* otherwise ... */
6044e9fcaa8aSmrg      newargz[++newargc] = xstrdup (argv[i]);
604588de56ccSmrg    }
6046e9fcaa8aSmrg  newargz[++newargc] = NULL;
6047e9fcaa8aSmrg
6048e9fcaa8aSmrgEOF
6049e9fcaa8aSmrg	    cat <<EOF
6050e9fcaa8aSmrg  /* The GNU banner must be the first non-error debug message */
6051862bcd1aSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6052e9fcaa8aSmrgEOF
6053e9fcaa8aSmrg	    cat <<"EOF"
6054e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6055e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
60561ab64890Smrg
605788de56ccSmrg  tmp_pathspec = find_executable (argv[0]);
605888de56ccSmrg  if (tmp_pathspec == NULL)
6059e9fcaa8aSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6060e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6061e9fcaa8aSmrg                  "(main) found exe (before symlink chase) at: %s\n",
6062e9fcaa8aSmrg		  tmp_pathspec);
606388de56ccSmrg
606488de56ccSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6065e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6066e9fcaa8aSmrg                  "(main) found exe (after symlink chase) at: %s\n",
6067e9fcaa8aSmrg		  actual_cwrapper_path);
606888de56ccSmrg  XFREE (tmp_pathspec);
606988de56ccSmrg
6070e9fcaa8aSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
607188de56ccSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
607288de56ccSmrg
607388de56ccSmrg  /* wrapper name transforms */
607488de56ccSmrg  strendzap (actual_cwrapper_name, ".exe");
607588de56ccSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
607688de56ccSmrg  XFREE (actual_cwrapper_name);
607788de56ccSmrg  actual_cwrapper_name = tmp_pathspec;
607888de56ccSmrg  tmp_pathspec = 0;
607988de56ccSmrg
608088de56ccSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
608188de56ccSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
608288de56ccSmrg  strendzap (target_name, ".exe");
608388de56ccSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
608488de56ccSmrg  XFREE (target_name);
608588de56ccSmrg  target_name = tmp_pathspec;
608688de56ccSmrg  tmp_pathspec = 0;
608788de56ccSmrg
6088e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6089e9fcaa8aSmrg		  "(main) libtool target name: %s\n",
6090e9fcaa8aSmrg		  target_name);
609188de56ccSmrgEOF
60921ab64890Smrg
609388de56ccSmrg	    cat <<EOF
609488de56ccSmrg  newargz[0] =
609588de56ccSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
609688de56ccSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
609788de56ccSmrg  strcpy (newargz[0], actual_cwrapper_path);
609888de56ccSmrg  strcat (newargz[0], "$objdir");
609988de56ccSmrg  strcat (newargz[0], "/");
610088de56ccSmrgEOF
61011ab64890Smrg
610288de56ccSmrg	    cat <<"EOF"
610388de56ccSmrg  /* stop here, and copy so we don't have to do this twice */
610488de56ccSmrg  tmp_pathspec = xstrdup (newargz[0]);
61051ab64890Smrg
610688de56ccSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
610788de56ccSmrg  strcat (newargz[0], actual_cwrapper_name);
61081ab64890Smrg
610988de56ccSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
611088de56ccSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
611188de56ccSmrg  XFREE (tmp_pathspec);
611288de56ccSmrg  tmp_pathspec = NULL;
611388de56ccSmrgEOF
61141ab64890Smrg
611588de56ccSmrg	    case $host_os in
611688de56ccSmrg	      mingw*)
611788de56ccSmrg	    cat <<"EOF"
611888de56ccSmrg  {
611988de56ccSmrg    char* p;
612088de56ccSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
612188de56ccSmrg      {
612288de56ccSmrg	*p = '/';
612388de56ccSmrg      }
612488de56ccSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
612588de56ccSmrg      {
612688de56ccSmrg	*p = '/';
612788de56ccSmrg      }
612888de56ccSmrg  }
612988de56ccSmrgEOF
613088de56ccSmrg	    ;;
613188de56ccSmrg	    esac
61321ab64890Smrg
613388de56ccSmrg	    cat <<"EOF"
613488de56ccSmrg  XFREE (target_name);
613588de56ccSmrg  XFREE (actual_cwrapper_path);
613688de56ccSmrg  XFREE (actual_cwrapper_name);
61371ab64890Smrg
613888de56ccSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
613988de56ccSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6140e9fcaa8aSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6141e9fcaa8aSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6142e9fcaa8aSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6143e9fcaa8aSmrg     libraries must come first. */
614488de56ccSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6145e9fcaa8aSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
61461ab64890Smrg
6147e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6148e9fcaa8aSmrg		  nonnull (lt_argv_zero));
614988de56ccSmrg  for (i = 0; i < newargc; i++)
615088de56ccSmrg    {
6151e9fcaa8aSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6152e9fcaa8aSmrg		      i, nonnull (newargz[i]));
615388de56ccSmrg    }
61541ab64890Smrg
615588de56ccSmrgEOF
61561ab64890Smrg
615788de56ccSmrg	    case $host_os in
615888de56ccSmrg	      mingw*)
615988de56ccSmrg		cat <<"EOF"
616088de56ccSmrg  /* execv doesn't actually work on mingw as expected on unix */
6161e9fcaa8aSmrg  newargz = prepare_spawn (newargz);
6162862bcd1aSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
616388de56ccSmrg  if (rval == -1)
616488de56ccSmrg    {
616588de56ccSmrg      /* failed to start process */
6166e9fcaa8aSmrg      lt_debugprintf (__FILE__, __LINE__,
6167e9fcaa8aSmrg		      "(main) failed to launch target \"%s\": %s\n",
6168e9fcaa8aSmrg		      lt_argv_zero, nonnull (strerror (errno)));
616988de56ccSmrg      return 127;
617088de56ccSmrg    }
617188de56ccSmrg  return rval;
617288de56ccSmrgEOF
617388de56ccSmrg		;;
617488de56ccSmrg	      *)
617588de56ccSmrg		cat <<"EOF"
617688de56ccSmrg  execv (lt_argv_zero, newargz);
617788de56ccSmrg  return rval; /* =127, but avoids unused variable warning */
617888de56ccSmrgEOF
617988de56ccSmrg		;;
618088de56ccSmrg	    esac
61811ab64890Smrg
618288de56ccSmrg	    cat <<"EOF"
618388de56ccSmrg}
61841ab64890Smrg
618588de56ccSmrgvoid *
618688de56ccSmrgxmalloc (size_t num)
618788de56ccSmrg{
618888de56ccSmrg  void *p = (void *) malloc (num);
618988de56ccSmrg  if (!p)
6190e9fcaa8aSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
61911ab64890Smrg
619288de56ccSmrg  return p;
619388de56ccSmrg}
61941ab64890Smrg
619588de56ccSmrgchar *
619688de56ccSmrgxstrdup (const char *string)
619788de56ccSmrg{
619888de56ccSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
619988de56ccSmrg			  string) : NULL;
620088de56ccSmrg}
62011ab64890Smrg
620288de56ccSmrgconst char *
620388de56ccSmrgbase_name (const char *name)
620488de56ccSmrg{
620588de56ccSmrg  const char *base;
6206b4ee4795Smrg
6207862bcd1aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
620888de56ccSmrg  /* Skip over the disk name in MSDOS pathnames. */
620988de56ccSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
621088de56ccSmrg    name += 2;
621188de56ccSmrg#endif
6212b4ee4795Smrg
621388de56ccSmrg  for (base = name; *name; name++)
621488de56ccSmrg    if (IS_DIR_SEPARATOR (*name))
621588de56ccSmrg      base = name + 1;
621688de56ccSmrg  return base;
621788de56ccSmrg}
6218b4ee4795Smrg
621988de56ccSmrgint
622088de56ccSmrgcheck_executable (const char *path)
622188de56ccSmrg{
622288de56ccSmrg  struct stat st;
6223b4ee4795Smrg
6224e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6225e9fcaa8aSmrg                  nonempty (path));
622688de56ccSmrg  if ((!path) || (!*path))
622788de56ccSmrg    return 0;
6228b4ee4795Smrg
622988de56ccSmrg  if ((stat (path, &st) >= 0)
623088de56ccSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
623188de56ccSmrg    return 1;
623288de56ccSmrg  else
623388de56ccSmrg    return 0;
623488de56ccSmrg}
62351ab64890Smrg
623688de56ccSmrgint
623788de56ccSmrgmake_executable (const char *path)
623888de56ccSmrg{
623988de56ccSmrg  int rval = 0;
624088de56ccSmrg  struct stat st;
62411ab64890Smrg
6242e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6243e9fcaa8aSmrg                  nonempty (path));
624488de56ccSmrg  if ((!path) || (!*path))
624588de56ccSmrg    return 0;
62461ab64890Smrg
624788de56ccSmrg  if (stat (path, &st) >= 0)
624888de56ccSmrg    {
624988de56ccSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
625088de56ccSmrg    }
625188de56ccSmrg  return rval;
625288de56ccSmrg}
6253b4ee4795Smrg
625488de56ccSmrg/* Searches for the full path of the wrapper.  Returns
625588de56ccSmrg   newly allocated full path name if found, NULL otherwise
625688de56ccSmrg   Does not chase symlinks, even on platforms that support them.
625788de56ccSmrg*/
625888de56ccSmrgchar *
625988de56ccSmrgfind_executable (const char *wrapper)
626088de56ccSmrg{
626188de56ccSmrg  int has_slash = 0;
626288de56ccSmrg  const char *p;
626388de56ccSmrg  const char *p_next;
626488de56ccSmrg  /* static buffer for getcwd */
626588de56ccSmrg  char tmp[LT_PATHMAX + 1];
6266862bcd1aSmrg  size_t tmp_len;
626788de56ccSmrg  char *concat_name;
6268b4ee4795Smrg
6269e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6270e9fcaa8aSmrg                  nonempty (wrapper));
6271b4ee4795Smrg
627288de56ccSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
627388de56ccSmrg    return NULL;
6274b4ee4795Smrg
627588de56ccSmrg  /* Absolute path? */
6276862bcd1aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
627788de56ccSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
627888de56ccSmrg    {
627988de56ccSmrg      concat_name = xstrdup (wrapper);
628088de56ccSmrg      if (check_executable (concat_name))
628188de56ccSmrg	return concat_name;
628288de56ccSmrg      XFREE (concat_name);
628388de56ccSmrg    }
628488de56ccSmrg  else
628588de56ccSmrg    {
628688de56ccSmrg#endif
628788de56ccSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
628888de56ccSmrg	{
628988de56ccSmrg	  concat_name = xstrdup (wrapper);
629088de56ccSmrg	  if (check_executable (concat_name))
629188de56ccSmrg	    return concat_name;
629288de56ccSmrg	  XFREE (concat_name);
629388de56ccSmrg	}
6294862bcd1aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
629588de56ccSmrg    }
629688de56ccSmrg#endif
62971ab64890Smrg
629888de56ccSmrg  for (p = wrapper; *p; p++)
629988de56ccSmrg    if (*p == '/')
630088de56ccSmrg      {
630188de56ccSmrg	has_slash = 1;
630288de56ccSmrg	break;
630388de56ccSmrg      }
630488de56ccSmrg  if (!has_slash)
630588de56ccSmrg    {
630688de56ccSmrg      /* no slashes; search PATH */
630788de56ccSmrg      const char *path = getenv ("PATH");
630888de56ccSmrg      if (path != NULL)
630988de56ccSmrg	{
631088de56ccSmrg	  for (p = path; *p; p = p_next)
631188de56ccSmrg	    {
631288de56ccSmrg	      const char *q;
631388de56ccSmrg	      size_t p_len;
631488de56ccSmrg	      for (q = p; *q; q++)
631588de56ccSmrg		if (IS_PATH_SEPARATOR (*q))
631688de56ccSmrg		  break;
6317862bcd1aSmrg	      p_len = (size_t) (q - p);
631888de56ccSmrg	      p_next = (*q == '\0' ? q : q + 1);
631988de56ccSmrg	      if (p_len == 0)
632088de56ccSmrg		{
632188de56ccSmrg		  /* empty path: current directory */
632288de56ccSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6323e9fcaa8aSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6324e9fcaa8aSmrg                              nonnull (strerror (errno)));
632588de56ccSmrg		  tmp_len = strlen (tmp);
632688de56ccSmrg		  concat_name =
632788de56ccSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
632888de56ccSmrg		  memcpy (concat_name, tmp, tmp_len);
632988de56ccSmrg		  concat_name[tmp_len] = '/';
633088de56ccSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
633188de56ccSmrg		}
633288de56ccSmrg	      else
633388de56ccSmrg		{
633488de56ccSmrg		  concat_name =
633588de56ccSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
633688de56ccSmrg		  memcpy (concat_name, p, p_len);
633788de56ccSmrg		  concat_name[p_len] = '/';
633888de56ccSmrg		  strcpy (concat_name + p_len + 1, wrapper);
633988de56ccSmrg		}
634088de56ccSmrg	      if (check_executable (concat_name))
634188de56ccSmrg		return concat_name;
634288de56ccSmrg	      XFREE (concat_name);
634388de56ccSmrg	    }
634488de56ccSmrg	}
634588de56ccSmrg      /* not found in PATH; assume curdir */
634688de56ccSmrg    }
634788de56ccSmrg  /* Relative path | not found in path: prepend cwd */
634888de56ccSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6349e9fcaa8aSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6350e9fcaa8aSmrg              nonnull (strerror (errno)));
635188de56ccSmrg  tmp_len = strlen (tmp);
635288de56ccSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
635388de56ccSmrg  memcpy (concat_name, tmp, tmp_len);
635488de56ccSmrg  concat_name[tmp_len] = '/';
635588de56ccSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
63561ab64890Smrg
635788de56ccSmrg  if (check_executable (concat_name))
635888de56ccSmrg    return concat_name;
635988de56ccSmrg  XFREE (concat_name);
636088de56ccSmrg  return NULL;
636188de56ccSmrg}
63621ab64890Smrg
636388de56ccSmrgchar *
636488de56ccSmrgchase_symlinks (const char *pathspec)
636588de56ccSmrg{
636688de56ccSmrg#ifndef S_ISLNK
636788de56ccSmrg  return xstrdup (pathspec);
636888de56ccSmrg#else
636988de56ccSmrg  char buf[LT_PATHMAX];
637088de56ccSmrg  struct stat s;
637188de56ccSmrg  char *tmp_pathspec = xstrdup (pathspec);
637288de56ccSmrg  char *p;
637388de56ccSmrg  int has_symlinks = 0;
637488de56ccSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
637588de56ccSmrg    {
6376e9fcaa8aSmrg      lt_debugprintf (__FILE__, __LINE__,
6377e9fcaa8aSmrg		      "checking path component for symlinks: %s\n",
6378e9fcaa8aSmrg		      tmp_pathspec);
637988de56ccSmrg      if (lstat (tmp_pathspec, &s) == 0)
638088de56ccSmrg	{
638188de56ccSmrg	  if (S_ISLNK (s.st_mode) != 0)
638288de56ccSmrg	    {
638388de56ccSmrg	      has_symlinks = 1;
638488de56ccSmrg	      break;
638588de56ccSmrg	    }
63861ab64890Smrg
638788de56ccSmrg	  /* search backwards for last DIR_SEPARATOR */
638888de56ccSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
638988de56ccSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
639088de56ccSmrg	    p--;
639188de56ccSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
639288de56ccSmrg	    {
639388de56ccSmrg	      /* no more DIR_SEPARATORS left */
639488de56ccSmrg	      break;
639588de56ccSmrg	    }
639688de56ccSmrg	  *p = '\0';
639788de56ccSmrg	}
639888de56ccSmrg      else
639988de56ccSmrg	{
6400e9fcaa8aSmrg	  lt_fatal (__FILE__, __LINE__,
6401e9fcaa8aSmrg		    "error accessing file \"%s\": %s",
6402e9fcaa8aSmrg		    tmp_pathspec, nonnull (strerror (errno)));
640388de56ccSmrg	}
640488de56ccSmrg    }
640588de56ccSmrg  XFREE (tmp_pathspec);
64061ab64890Smrg
640788de56ccSmrg  if (!has_symlinks)
640888de56ccSmrg    {
640988de56ccSmrg      return xstrdup (pathspec);
641088de56ccSmrg    }
64111ab64890Smrg
641288de56ccSmrg  tmp_pathspec = realpath (pathspec, buf);
641388de56ccSmrg  if (tmp_pathspec == 0)
641488de56ccSmrg    {
6415e9fcaa8aSmrg      lt_fatal (__FILE__, __LINE__,
6416e9fcaa8aSmrg		"could not follow symlinks for %s", pathspec);
641788de56ccSmrg    }
641888de56ccSmrg  return xstrdup (tmp_pathspec);
641988de56ccSmrg#endif
642088de56ccSmrg}
64211ab64890Smrg
642288de56ccSmrgchar *
642388de56ccSmrgstrendzap (char *str, const char *pat)
642488de56ccSmrg{
642588de56ccSmrg  size_t len, patlen;
64261ab64890Smrg
642788de56ccSmrg  assert (str != NULL);
642888de56ccSmrg  assert (pat != NULL);
64291ab64890Smrg
643088de56ccSmrg  len = strlen (str);
643188de56ccSmrg  patlen = strlen (pat);
64321ab64890Smrg
643388de56ccSmrg  if (patlen <= len)
643488de56ccSmrg    {
643588de56ccSmrg      str += len - patlen;
6436862bcd1aSmrg      if (STREQ (str, pat))
643788de56ccSmrg	*str = '\0';
643888de56ccSmrg    }
643988de56ccSmrg  return str;
644088de56ccSmrg}
64411ab64890Smrg
6442e9fcaa8aSmrgvoid
6443e9fcaa8aSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6444e9fcaa8aSmrg{
6445e9fcaa8aSmrg  va_list args;
6446e9fcaa8aSmrg  if (lt_debug)
6447e9fcaa8aSmrg    {
6448e9fcaa8aSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6449e9fcaa8aSmrg      va_start (args, fmt);
6450e9fcaa8aSmrg      (void) vfprintf (stderr, fmt, args);
6451e9fcaa8aSmrg      va_end (args);
6452e9fcaa8aSmrg    }
6453e9fcaa8aSmrg}
6454e9fcaa8aSmrg
645588de56ccSmrgstatic void
6456e9fcaa8aSmrglt_error_core (int exit_status, const char *file,
6457e9fcaa8aSmrg	       int line, const char *mode,
645888de56ccSmrg	       const char *message, va_list ap)
645988de56ccSmrg{
6460e9fcaa8aSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
646188de56ccSmrg  vfprintf (stderr, message, ap);
646288de56ccSmrg  fprintf (stderr, ".\n");
64631ab64890Smrg
646488de56ccSmrg  if (exit_status >= 0)
646588de56ccSmrg    exit (exit_status);
646688de56ccSmrg}
64671ab64890Smrg
646888de56ccSmrgvoid
6469e9fcaa8aSmrglt_fatal (const char *file, int line, const char *message, ...)
647088de56ccSmrg{
647188de56ccSmrg  va_list ap;
647288de56ccSmrg  va_start (ap, message);
6473e9fcaa8aSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
647488de56ccSmrg  va_end (ap);
647588de56ccSmrg}
64762e9c7c8cSmrg
6477e9fcaa8aSmrgstatic const char *
6478e9fcaa8aSmrgnonnull (const char *s)
6479e9fcaa8aSmrg{
6480e9fcaa8aSmrg  return s ? s : "(null)";
6481e9fcaa8aSmrg}
6482e9fcaa8aSmrg
6483e9fcaa8aSmrgstatic const char *
6484e9fcaa8aSmrgnonempty (const char *s)
6485e9fcaa8aSmrg{
6486e9fcaa8aSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6487e9fcaa8aSmrg}
6488e9fcaa8aSmrg
648988de56ccSmrgvoid
649088de56ccSmrglt_setenv (const char *name, const char *value)
649188de56ccSmrg{
6492e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6493e9fcaa8aSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6494e9fcaa8aSmrg                  nonnull (name), nonnull (value));
649588de56ccSmrg  {
649688de56ccSmrg#ifdef HAVE_SETENV
649788de56ccSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
649888de56ccSmrg    char *str = xstrdup (value);
649988de56ccSmrg    setenv (name, str, 1);
650088de56ccSmrg#else
6501862bcd1aSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
650288de56ccSmrg    char *str = XMALLOC (char, len);
650388de56ccSmrg    sprintf (str, "%s=%s", name, value);
650488de56ccSmrg    if (putenv (str) != EXIT_SUCCESS)
650588de56ccSmrg      {
650688de56ccSmrg        XFREE (str);
650788de56ccSmrg      }
650888de56ccSmrg#endif
650988de56ccSmrg  }
651088de56ccSmrg}
65111ab64890Smrg
651288de56ccSmrgchar *
651388de56ccSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
651488de56ccSmrg{
651588de56ccSmrg  char *new_value;
651688de56ccSmrg  if (orig_value && *orig_value)
651788de56ccSmrg    {
6518862bcd1aSmrg      size_t orig_value_len = strlen (orig_value);
6519862bcd1aSmrg      size_t add_len = strlen (add);
652088de56ccSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
652188de56ccSmrg      if (to_end)
652288de56ccSmrg        {
652388de56ccSmrg          strcpy (new_value, orig_value);
652488de56ccSmrg          strcpy (new_value + orig_value_len, add);
652588de56ccSmrg        }
652688de56ccSmrg      else
652788de56ccSmrg        {
652888de56ccSmrg          strcpy (new_value, add);
652988de56ccSmrg          strcpy (new_value + add_len, orig_value);
653088de56ccSmrg        }
653188de56ccSmrg    }
653288de56ccSmrg  else
653388de56ccSmrg    {
653488de56ccSmrg      new_value = xstrdup (add);
653588de56ccSmrg    }
653688de56ccSmrg  return new_value;
653788de56ccSmrg}
65381ab64890Smrg
653988de56ccSmrgvoid
654088de56ccSmrglt_update_exe_path (const char *name, const char *value)
654188de56ccSmrg{
6542e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6543e9fcaa8aSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6544e9fcaa8aSmrg                  nonnull (name), nonnull (value));
65451ab64890Smrg
654688de56ccSmrg  if (name && *name && value && *value)
654788de56ccSmrg    {
654888de56ccSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
654988de56ccSmrg      /* some systems can't cope with a ':'-terminated path #' */
6550862bcd1aSmrg      size_t len = strlen (new_value);
6551862bcd1aSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
655288de56ccSmrg        {
6553862bcd1aSmrg          new_value[--len] = '\0';
655488de56ccSmrg        }
655588de56ccSmrg      lt_setenv (name, new_value);
655688de56ccSmrg      XFREE (new_value);
655788de56ccSmrg    }
655888de56ccSmrg}
65591ab64890Smrg
656088de56ccSmrgvoid
656188de56ccSmrglt_update_lib_path (const char *name, const char *value)
656288de56ccSmrg{
6563e9fcaa8aSmrg  lt_debugprintf (__FILE__, __LINE__,
6564e9fcaa8aSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6565e9fcaa8aSmrg                  nonnull (name), nonnull (value));
65661ab64890Smrg
656788de56ccSmrg  if (name && *name && value && *value)
656888de56ccSmrg    {
656988de56ccSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
657088de56ccSmrg      lt_setenv (name, new_value);
657188de56ccSmrg      XFREE (new_value);
657288de56ccSmrg    }
657388de56ccSmrg}
65741ab64890Smrg
6575e9fcaa8aSmrgEOF
6576e9fcaa8aSmrg	    case $host_os in
6577e9fcaa8aSmrg	      mingw*)
6578e9fcaa8aSmrg		cat <<"EOF"
6579e9fcaa8aSmrg
6580e9fcaa8aSmrg/* Prepares an argument vector before calling spawn().
6581e9fcaa8aSmrg   Note that spawn() does not by itself call the command interpreter
6582e9fcaa8aSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6583e9fcaa8aSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6584e9fcaa8aSmrg         GetVersionEx(&v);
6585e9fcaa8aSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6586e9fcaa8aSmrg      }) ? "cmd.exe" : "command.com").
6587e9fcaa8aSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6588e9fcaa8aSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6589e9fcaa8aSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6590e9fcaa8aSmrg   special way:
6591e9fcaa8aSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6592e9fcaa8aSmrg     delimiters if they are surrounded by double quotes: "...".
6593e9fcaa8aSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6594e9fcaa8aSmrg     that within double quotes, space and tab are treated like normal
6595e9fcaa8aSmrg     characters.
6596e9fcaa8aSmrg   - Backslashes not followed by double quotes are not special.
6597e9fcaa8aSmrg   - But 2*n+1 backslashes followed by a double quote become
6598e9fcaa8aSmrg     n backslashes followed by a double quote (n >= 0):
6599e9fcaa8aSmrg       \" -> "
6600e9fcaa8aSmrg       \\\" -> \"
6601e9fcaa8aSmrg       \\\\\" -> \\"
6602e9fcaa8aSmrg */
6603e9fcaa8aSmrg#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"
6604e9fcaa8aSmrg#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"
6605e9fcaa8aSmrgchar **
6606e9fcaa8aSmrgprepare_spawn (char **argv)
6607e9fcaa8aSmrg{
6608e9fcaa8aSmrg  size_t argc;
6609e9fcaa8aSmrg  char **new_argv;
6610e9fcaa8aSmrg  size_t i;
6611e9fcaa8aSmrg
6612e9fcaa8aSmrg  /* Count number of arguments.  */
6613e9fcaa8aSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6614e9fcaa8aSmrg    ;
6615e9fcaa8aSmrg
6616e9fcaa8aSmrg  /* Allocate new argument vector.  */
6617e9fcaa8aSmrg  new_argv = XMALLOC (char *, argc + 1);
6618e9fcaa8aSmrg
6619e9fcaa8aSmrg  /* Put quoted arguments into the new argument vector.  */
6620e9fcaa8aSmrg  for (i = 0; i < argc; i++)
6621e9fcaa8aSmrg    {
6622e9fcaa8aSmrg      const char *string = argv[i];
6623e9fcaa8aSmrg
6624e9fcaa8aSmrg      if (string[0] == '\0')
6625e9fcaa8aSmrg	new_argv[i] = xstrdup ("\"\"");
6626e9fcaa8aSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6627e9fcaa8aSmrg	{
6628e9fcaa8aSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6629e9fcaa8aSmrg	  size_t length;
6630e9fcaa8aSmrg	  unsigned int backslashes;
6631e9fcaa8aSmrg	  const char *s;
6632e9fcaa8aSmrg	  char *quoted_string;
6633e9fcaa8aSmrg	  char *p;
6634e9fcaa8aSmrg
6635e9fcaa8aSmrg	  length = 0;
6636e9fcaa8aSmrg	  backslashes = 0;
6637e9fcaa8aSmrg	  if (quote_around)
6638e9fcaa8aSmrg	    length++;
6639e9fcaa8aSmrg	  for (s = string; *s != '\0'; s++)
6640e9fcaa8aSmrg	    {
6641e9fcaa8aSmrg	      char c = *s;
6642e9fcaa8aSmrg	      if (c == '"')
6643e9fcaa8aSmrg		length += backslashes + 1;
6644e9fcaa8aSmrg	      length++;
6645e9fcaa8aSmrg	      if (c == '\\')
6646e9fcaa8aSmrg		backslashes++;
6647e9fcaa8aSmrg	      else
6648e9fcaa8aSmrg		backslashes = 0;
6649e9fcaa8aSmrg	    }
6650e9fcaa8aSmrg	  if (quote_around)
6651e9fcaa8aSmrg	    length += backslashes + 1;
6652e9fcaa8aSmrg
6653e9fcaa8aSmrg	  quoted_string = XMALLOC (char, length + 1);
6654e9fcaa8aSmrg
6655e9fcaa8aSmrg	  p = quoted_string;
6656e9fcaa8aSmrg	  backslashes = 0;
6657e9fcaa8aSmrg	  if (quote_around)
6658e9fcaa8aSmrg	    *p++ = '"';
6659e9fcaa8aSmrg	  for (s = string; *s != '\0'; s++)
6660e9fcaa8aSmrg	    {
6661e9fcaa8aSmrg	      char c = *s;
6662e9fcaa8aSmrg	      if (c == '"')
6663e9fcaa8aSmrg		{
6664e9fcaa8aSmrg		  unsigned int j;
6665e9fcaa8aSmrg		  for (j = backslashes + 1; j > 0; j--)
6666e9fcaa8aSmrg		    *p++ = '\\';
6667e9fcaa8aSmrg		}
6668e9fcaa8aSmrg	      *p++ = c;
6669e9fcaa8aSmrg	      if (c == '\\')
6670e9fcaa8aSmrg		backslashes++;
6671e9fcaa8aSmrg	      else
6672e9fcaa8aSmrg		backslashes = 0;
6673e9fcaa8aSmrg	    }
6674e9fcaa8aSmrg	  if (quote_around)
6675e9fcaa8aSmrg	    {
6676e9fcaa8aSmrg	      unsigned int j;
6677e9fcaa8aSmrg	      for (j = backslashes; j > 0; j--)
6678e9fcaa8aSmrg		*p++ = '\\';
6679e9fcaa8aSmrg	      *p++ = '"';
6680e9fcaa8aSmrg	    }
6681e9fcaa8aSmrg	  *p = '\0';
6682e9fcaa8aSmrg
6683e9fcaa8aSmrg	  new_argv[i] = quoted_string;
6684e9fcaa8aSmrg	}
6685e9fcaa8aSmrg      else
6686e9fcaa8aSmrg	new_argv[i] = (char *) string;
6687e9fcaa8aSmrg    }
6688e9fcaa8aSmrg  new_argv[argc] = NULL;
6689e9fcaa8aSmrg
6690e9fcaa8aSmrg  return new_argv;
6691e9fcaa8aSmrg}
6692e9fcaa8aSmrgEOF
6693e9fcaa8aSmrg		;;
6694e9fcaa8aSmrg	    esac
6695e9fcaa8aSmrg
6696e9fcaa8aSmrg            cat <<"EOF"
6697e9fcaa8aSmrgvoid lt_dump_script (FILE* f)
6698e9fcaa8aSmrg{
6699e9fcaa8aSmrgEOF
6700e9fcaa8aSmrg	    func_emit_wrapper yes |
6701eb411b4bSmrg	      $SED -n -e '
6702eb411b4bSmrgs/^\(.\{79\}\)\(..*\)/\1\
6703eb411b4bSmrg\2/
6704eb411b4bSmrgh
6705eb411b4bSmrgs/\([\\"]\)/\\\1/g
6706eb411b4bSmrgs/$/\\n/
6707eb411b4bSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708eb411b4bSmrgg
6709eb411b4bSmrgD'
6710e9fcaa8aSmrg            cat <<"EOF"
6711e9fcaa8aSmrg}
671288de56ccSmrgEOF
671388de56ccSmrg}
671488de56ccSmrg# end: func_emit_cwrapperexe_src
67151ab64890Smrg
6716e9fcaa8aSmrg# func_win32_import_lib_p ARG
6717e9fcaa8aSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6718e9fcaa8aSmrgfunc_win32_import_lib_p ()
6719e9fcaa8aSmrg{
6720862bcd1aSmrg    $debug_cmd
6721862bcd1aSmrg
6722e9fcaa8aSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6723e9fcaa8aSmrg    *import*) : ;;
6724e9fcaa8aSmrg    *) false ;;
6725e9fcaa8aSmrg    esac
6726e9fcaa8aSmrg}
6727e9fcaa8aSmrg
6728862bcd1aSmrg# func_suncc_cstd_abi
6729862bcd1aSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730862bcd1aSmrg# Several compiler flags select an ABI that is incompatible with the
6731862bcd1aSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732862bcd1aSmrgfunc_suncc_cstd_abi ()
6733862bcd1aSmrg{
6734862bcd1aSmrg    $debug_cmd
6735862bcd1aSmrg
6736862bcd1aSmrg    case " $compile_command " in
6737862bcd1aSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738862bcd1aSmrg      suncc_use_cstd_abi=no
6739862bcd1aSmrg      ;;
6740862bcd1aSmrg    *)
6741862bcd1aSmrg      suncc_use_cstd_abi=yes
6742862bcd1aSmrg      ;;
6743862bcd1aSmrg    esac
6744862bcd1aSmrg}
6745862bcd1aSmrg
674688de56ccSmrg# func_mode_link arg...
674788de56ccSmrgfunc_mode_link ()
674888de56ccSmrg{
6749862bcd1aSmrg    $debug_cmd
6750862bcd1aSmrg
675188de56ccSmrg    case $host in
675288de56ccSmrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
675388de56ccSmrg      # It is impossible to link a dll without this setting, and
675488de56ccSmrg      # we shouldn't force the makefile maintainer to figure out
6755862bcd1aSmrg      # what system we are compiling for in order to pass an extra
675688de56ccSmrg      # flag for every libtool invocation.
675788de56ccSmrg      # allow_undefined=no
67581ab64890Smrg
675988de56ccSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6760862bcd1aSmrg      # to make a dll that has undefined symbols, in which case not
676188de56ccSmrg      # even a static library is built.  For now, we need to specify
676288de56ccSmrg      # -no-undefined on the libtool link line when we can be certain
676388de56ccSmrg      # that all symbols are satisfied, otherwise we get a static library.
676488de56ccSmrg      allow_undefined=yes
676588de56ccSmrg      ;;
676688de56ccSmrg    *)
676788de56ccSmrg      allow_undefined=yes
676888de56ccSmrg      ;;
676988de56ccSmrg    esac
677088de56ccSmrg    libtool_args=$nonopt
677188de56ccSmrg    base_compile="$nonopt $@"
677288de56ccSmrg    compile_command=$nonopt
677388de56ccSmrg    finalize_command=$nonopt
67741ab64890Smrg
677588de56ccSmrg    compile_rpath=
677688de56ccSmrg    finalize_rpath=
677788de56ccSmrg    compile_shlibpath=
677888de56ccSmrg    finalize_shlibpath=
677988de56ccSmrg    convenience=
678088de56ccSmrg    old_convenience=
678188de56ccSmrg    deplibs=
678288de56ccSmrg    old_deplibs=
678388de56ccSmrg    compiler_flags=
678488de56ccSmrg    linker_flags=
678588de56ccSmrg    dllsearchpath=
678688de56ccSmrg    lib_search_path=`pwd`
678788de56ccSmrg    inst_prefix_dir=
678888de56ccSmrg    new_inherited_linker_flags=
67891ab64890Smrg
679088de56ccSmrg    avoid_version=no
6791e9fcaa8aSmrg    bindir=
679288de56ccSmrg    dlfiles=
679388de56ccSmrg    dlprefiles=
679488de56ccSmrg    dlself=no
679588de56ccSmrg    export_dynamic=no
679688de56ccSmrg    export_symbols=
679788de56ccSmrg    export_symbols_regex=
679888de56ccSmrg    generated=
679988de56ccSmrg    libobjs=
680088de56ccSmrg    ltlibs=
680188de56ccSmrg    module=no
680288de56ccSmrg    no_install=no
680388de56ccSmrg    objs=
6804862bcd1aSmrg    os2dllname=
680588de56ccSmrg    non_pic_objects=
680688de56ccSmrg    precious_files_regex=
680788de56ccSmrg    prefer_static_libs=no
6808862bcd1aSmrg    preload=false
680988de56ccSmrg    prev=
681088de56ccSmrg    prevarg=
681188de56ccSmrg    release=
681288de56ccSmrg    rpath=
681388de56ccSmrg    xrpath=
681488de56ccSmrg    perm_rpath=
681588de56ccSmrg    temp_rpath=
681688de56ccSmrg    thread_safe=no
681788de56ccSmrg    vinfo=
681888de56ccSmrg    vinfo_number=no
681988de56ccSmrg    weak_libs=
6820862bcd1aSmrg    single_module=$wl-single_module
682188de56ccSmrg    func_infer_tag $base_compile
682288de56ccSmrg
682388de56ccSmrg    # We need to know -static, to get the right output filenames.
682488de56ccSmrg    for arg
682588de56ccSmrg    do
682688de56ccSmrg      case $arg in
682788de56ccSmrg      -shared)
6828862bcd1aSmrg	test yes != "$build_libtool_libs" \
6829862bcd1aSmrg	  && func_fatal_configuration "cannot build a shared library"
683088de56ccSmrg	build_old_libs=no
683188de56ccSmrg	break
683288de56ccSmrg	;;
683388de56ccSmrg      -all-static | -static | -static-libtool-libs)
683488de56ccSmrg	case $arg in
683588de56ccSmrg	-all-static)
6836862bcd1aSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
683788de56ccSmrg	    func_warning "complete static linking is impossible in this configuration"
683888de56ccSmrg	  fi
683988de56ccSmrg	  if test -n "$link_static_flag"; then
684088de56ccSmrg	    dlopen_self=$dlopen_self_static
684188de56ccSmrg	  fi
684288de56ccSmrg	  prefer_static_libs=yes
684388de56ccSmrg	  ;;
684488de56ccSmrg	-static)
684588de56ccSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
684688de56ccSmrg	    dlopen_self=$dlopen_self_static
684788de56ccSmrg	  fi
684888de56ccSmrg	  prefer_static_libs=built
684988de56ccSmrg	  ;;
685088de56ccSmrg	-static-libtool-libs)
685188de56ccSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
685288de56ccSmrg	    dlopen_self=$dlopen_self_static
6853b4ee4795Smrg	  fi
685488de56ccSmrg	  prefer_static_libs=yes
685588de56ccSmrg	  ;;
685688de56ccSmrg	esac
685788de56ccSmrg	build_libtool_libs=no
685888de56ccSmrg	build_old_libs=yes
685988de56ccSmrg	break
686088de56ccSmrg	;;
686188de56ccSmrg      esac
686288de56ccSmrg    done
68631ab64890Smrg
686488de56ccSmrg    # See if our shared archives depend on static archives.
686588de56ccSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
68661ab64890Smrg
686788de56ccSmrg    # Go through the arguments, transforming them on the way.
686888de56ccSmrg    while test "$#" -gt 0; do
6869862bcd1aSmrg      arg=$1
687088de56ccSmrg      shift
6871e9628295Smrg      func_quote_arg pretty,unquoted "$arg"
6872e9628295Smrg      qarg=$func_quote_arg_unquoted_result
6873e9628295Smrg      func_append libtool_args " $func_quote_arg_result"
68741ab64890Smrg
687588de56ccSmrg      # If the previous option needs an argument, assign it.
687688de56ccSmrg      if test -n "$prev"; then
687788de56ccSmrg	case $prev in
687888de56ccSmrg	output)
687988de56ccSmrg	  func_append compile_command " @OUTPUT@"
688088de56ccSmrg	  func_append finalize_command " @OUTPUT@"
688188de56ccSmrg	  ;;
688288de56ccSmrg	esac
68831ab64890Smrg
688488de56ccSmrg	case $prev in
6885e9fcaa8aSmrg	bindir)
6886862bcd1aSmrg	  bindir=$arg
6887e9fcaa8aSmrg	  prev=
6888e9fcaa8aSmrg	  continue
6889e9fcaa8aSmrg	  ;;
689088de56ccSmrg	dlfiles|dlprefiles)
6891862bcd1aSmrg	  $preload || {
689288de56ccSmrg	    # Add the symbol object into the linking commands.
689388de56ccSmrg	    func_append compile_command " @SYMFILE@"
689488de56ccSmrg	    func_append finalize_command " @SYMFILE@"
6895862bcd1aSmrg	    preload=:
6896862bcd1aSmrg	  }
689788de56ccSmrg	  case $arg in
689888de56ccSmrg	  *.la | *.lo) ;;  # We handle these cases below.
689988de56ccSmrg	  force)
6900862bcd1aSmrg	    if test no = "$dlself"; then
690188de56ccSmrg	      dlself=needless
690288de56ccSmrg	      export_dynamic=yes
690388de56ccSmrg	    fi
690488de56ccSmrg	    prev=
690588de56ccSmrg	    continue
690688de56ccSmrg	    ;;
690788de56ccSmrg	  self)
6908862bcd1aSmrg	    if test dlprefiles = "$prev"; then
690988de56ccSmrg	      dlself=yes
6910862bcd1aSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
691188de56ccSmrg	      dlself=yes
6912b4ee4795Smrg	    else
691388de56ccSmrg	      dlself=needless
691488de56ccSmrg	      export_dynamic=yes
6915b4ee4795Smrg	    fi
691688de56ccSmrg	    prev=
691788de56ccSmrg	    continue
691888de56ccSmrg	    ;;
691988de56ccSmrg	  *)
6920862bcd1aSmrg	    if test dlfiles = "$prev"; then
6921e9fcaa8aSmrg	      func_append dlfiles " $arg"
6922b4ee4795Smrg	    else
6923e9fcaa8aSmrg	      func_append dlprefiles " $arg"
6924b4ee4795Smrg	    fi
692588de56ccSmrg	    prev=
692688de56ccSmrg	    continue
692788de56ccSmrg	    ;;
692888de56ccSmrg	  esac
692988de56ccSmrg	  ;;
693088de56ccSmrg	expsyms)
6931862bcd1aSmrg	  export_symbols=$arg
693288de56ccSmrg	  test -f "$arg" \
6933862bcd1aSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
693488de56ccSmrg	  prev=
693588de56ccSmrg	  continue
693688de56ccSmrg	  ;;
693788de56ccSmrg	expsyms_regex)
6938862bcd1aSmrg	  export_symbols_regex=$arg
693988de56ccSmrg	  prev=
694088de56ccSmrg	  continue
694188de56ccSmrg	  ;;
694288de56ccSmrg	framework)
6943b4ee4795Smrg	  case $host in
694488de56ccSmrg	    *-*-darwin*)
694588de56ccSmrg	      case "$deplibs " in
694688de56ccSmrg		*" $qarg.ltframework "*) ;;
6947e9fcaa8aSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
694888de56ccSmrg		   ;;
694988de56ccSmrg	      esac
695088de56ccSmrg	      ;;
6951b4ee4795Smrg	  esac
695288de56ccSmrg	  prev=
695388de56ccSmrg	  continue
6954b4ee4795Smrg	  ;;
695588de56ccSmrg	inst_prefix)
6956862bcd1aSmrg	  inst_prefix_dir=$arg
6957862bcd1aSmrg	  prev=
6958862bcd1aSmrg	  continue
6959862bcd1aSmrg	  ;;
6960862bcd1aSmrg	mllvm)
6961862bcd1aSmrg	  # Clang does not use LLVM to link, so we can simply discard any
6962862bcd1aSmrg	  # '-mllvm $arg' options when doing the link step.
696388de56ccSmrg	  prev=
696488de56ccSmrg	  continue
6965b4ee4795Smrg	  ;;
696688de56ccSmrg	objectlist)
696788de56ccSmrg	  if test -f "$arg"; then
696888de56ccSmrg	    save_arg=$arg
696988de56ccSmrg	    moreargs=
697088de56ccSmrg	    for fil in `cat "$save_arg"`
697188de56ccSmrg	    do
6972e9fcaa8aSmrg#	      func_append moreargs " $fil"
697388de56ccSmrg	      arg=$fil
697488de56ccSmrg	      # A libtool-controlled object.
69752e9c7c8cSmrg
697688de56ccSmrg	      # Check to see that this really is a libtool object.
697788de56ccSmrg	      if func_lalib_unsafe_p "$arg"; then
697888de56ccSmrg		pic_object=
697988de56ccSmrg		non_pic_object=
69802e9c7c8cSmrg
698188de56ccSmrg		# Read the .lo file
698288de56ccSmrg		func_source "$arg"
69832e9c7c8cSmrg
698488de56ccSmrg		if test -z "$pic_object" ||
698588de56ccSmrg		   test -z "$non_pic_object" ||
6986862bcd1aSmrg		   test none = "$pic_object" &&
6987862bcd1aSmrg		   test none = "$non_pic_object"; then
6988862bcd1aSmrg		  func_fatal_error "cannot find name of object for '$arg'"
698988de56ccSmrg		fi
69902e9c7c8cSmrg
699188de56ccSmrg		# Extract subdirectory from the argument.
699288de56ccSmrg		func_dirname "$arg" "/" ""
6993862bcd1aSmrg		xdir=$func_dirname_result
69942e9c7c8cSmrg
6995862bcd1aSmrg		if test none != "$pic_object"; then
699688de56ccSmrg		  # Prepend the subdirectory the object is found in.
6997862bcd1aSmrg		  pic_object=$xdir$pic_object
69982e9c7c8cSmrg
6999862bcd1aSmrg		  if test dlfiles = "$prev"; then
7000862bcd1aSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7001e9fcaa8aSmrg		      func_append dlfiles " $pic_object"
700288de56ccSmrg		      prev=
700388de56ccSmrg		      continue
700488de56ccSmrg		    else
700588de56ccSmrg		      # If libtool objects are unsupported, then we need to preload.
700688de56ccSmrg		      prev=dlprefiles
700788de56ccSmrg		    fi
700888de56ccSmrg		  fi
70092e9c7c8cSmrg
701088de56ccSmrg		  # CHECK ME:  I think I busted this.  -Ossama
7011862bcd1aSmrg		  if test dlprefiles = "$prev"; then
701288de56ccSmrg		    # Preload the old-style object.
7013e9fcaa8aSmrg		    func_append dlprefiles " $pic_object"
701488de56ccSmrg		    prev=
701588de56ccSmrg		  fi
70162e9c7c8cSmrg
701788de56ccSmrg		  # A PIC object.
701888de56ccSmrg		  func_append libobjs " $pic_object"
7019862bcd1aSmrg		  arg=$pic_object
702088de56ccSmrg		fi
70212e9c7c8cSmrg
702288de56ccSmrg		# Non-PIC object.
7023862bcd1aSmrg		if test none != "$non_pic_object"; then
702488de56ccSmrg		  # Prepend the subdirectory the object is found in.
7025862bcd1aSmrg		  non_pic_object=$xdir$non_pic_object
70262e9c7c8cSmrg
702788de56ccSmrg		  # A standard non-PIC object
702888de56ccSmrg		  func_append non_pic_objects " $non_pic_object"
7029862bcd1aSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030862bcd1aSmrg		    arg=$non_pic_object
703188de56ccSmrg		  fi
703288de56ccSmrg		else
703388de56ccSmrg		  # If the PIC object exists, use it instead.
703488de56ccSmrg		  # $xdir was prepended to $pic_object above.
7035862bcd1aSmrg		  non_pic_object=$pic_object
703688de56ccSmrg		  func_append non_pic_objects " $non_pic_object"
703788de56ccSmrg		fi
703888de56ccSmrg	      else
703988de56ccSmrg		# Only an error if not doing a dry-run.
704088de56ccSmrg		if $opt_dry_run; then
704188de56ccSmrg		  # Extract subdirectory from the argument.
704288de56ccSmrg		  func_dirname "$arg" "/" ""
7043862bcd1aSmrg		  xdir=$func_dirname_result
704488de56ccSmrg
704588de56ccSmrg		  func_lo2o "$arg"
704688de56ccSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
704788de56ccSmrg		  non_pic_object=$xdir$func_lo2o_result
704888de56ccSmrg		  func_append libobjs " $pic_object"
704988de56ccSmrg		  func_append non_pic_objects " $non_pic_object"
705088de56ccSmrg	        else
7051862bcd1aSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
705288de56ccSmrg		fi
705388de56ccSmrg	      fi
705488de56ccSmrg	    done
7055b4ee4795Smrg	  else
7056862bcd1aSmrg	    func_fatal_error "link input file '$arg' does not exist"
7057b4ee4795Smrg	  fi
705888de56ccSmrg	  arg=$save_arg
705988de56ccSmrg	  prev=
706088de56ccSmrg	  continue
706188de56ccSmrg	  ;;
7062862bcd1aSmrg	os2dllname)
7063862bcd1aSmrg	  os2dllname=$arg
7064862bcd1aSmrg	  prev=
7065862bcd1aSmrg	  continue
7066862bcd1aSmrg	  ;;
706788de56ccSmrg	precious_regex)
7068862bcd1aSmrg	  precious_files_regex=$arg
706988de56ccSmrg	  prev=
707088de56ccSmrg	  continue
707188de56ccSmrg	  ;;
707288de56ccSmrg	release)
7073862bcd1aSmrg	  release=-$arg
707488de56ccSmrg	  prev=
707588de56ccSmrg	  continue
707688de56ccSmrg	  ;;
707788de56ccSmrg	rpath | xrpath)
707888de56ccSmrg	  # We need an absolute path.
707988de56ccSmrg	  case $arg in
708088de56ccSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
708188de56ccSmrg	  *)
708288de56ccSmrg	    func_fatal_error "only absolute run-paths are allowed"
708388de56ccSmrg	    ;;
708488de56ccSmrg	  esac
7085862bcd1aSmrg	  if test rpath = "$prev"; then
708688de56ccSmrg	    case "$rpath " in
708788de56ccSmrg	    *" $arg "*) ;;
7088e9fcaa8aSmrg	    *) func_append rpath " $arg" ;;
708988de56ccSmrg	    esac
7090b4ee4795Smrg	  else
709188de56ccSmrg	    case "$xrpath " in
709288de56ccSmrg	    *" $arg "*) ;;
7093e9fcaa8aSmrg	    *) func_append xrpath " $arg" ;;
709488de56ccSmrg	    esac
7095b4ee4795Smrg	  fi
709688de56ccSmrg	  prev=
709788de56ccSmrg	  continue
709888de56ccSmrg	  ;;
709988de56ccSmrg	shrext)
7100862bcd1aSmrg	  shrext_cmds=$arg
710188de56ccSmrg	  prev=
710288de56ccSmrg	  continue
710388de56ccSmrg	  ;;
710488de56ccSmrg	weak)
7105e9fcaa8aSmrg	  func_append weak_libs " $arg"
710688de56ccSmrg	  prev=
710788de56ccSmrg	  continue
710888de56ccSmrg	  ;;
7109e9628295Smrg	xassembler)
7110e9628295Smrg	  func_append compiler_flags " -Xassembler $qarg"
7111e9628295Smrg	  prev=
7112e9628295Smrg	  func_append compile_command " -Xassembler $qarg"
7113e9628295Smrg	  func_append finalize_command " -Xassembler $qarg"
7114e9628295Smrg	  continue
7115e9628295Smrg	  ;;
711688de56ccSmrg	xcclinker)
7117e9fcaa8aSmrg	  func_append linker_flags " $qarg"
7118e9fcaa8aSmrg	  func_append compiler_flags " $qarg"
711988de56ccSmrg	  prev=
712088de56ccSmrg	  func_append compile_command " $qarg"
712188de56ccSmrg	  func_append finalize_command " $qarg"
712288de56ccSmrg	  continue
712388de56ccSmrg	  ;;
712488de56ccSmrg	xcompiler)
7125e9fcaa8aSmrg	  func_append compiler_flags " $qarg"
712688de56ccSmrg	  prev=
712788de56ccSmrg	  func_append compile_command " $qarg"
712888de56ccSmrg	  func_append finalize_command " $qarg"
712988de56ccSmrg	  continue
713088de56ccSmrg	  ;;
713188de56ccSmrg	xlinker)
7132e9fcaa8aSmrg	  func_append linker_flags " $qarg"
7133e9fcaa8aSmrg	  func_append compiler_flags " $wl$qarg"
713488de56ccSmrg	  prev=
713588de56ccSmrg	  func_append compile_command " $wl$qarg"
713688de56ccSmrg	  func_append finalize_command " $wl$qarg"
713788de56ccSmrg	  continue
713888de56ccSmrg	  ;;
713988de56ccSmrg	*)
714088de56ccSmrg	  eval "$prev=\"\$arg\""
714188de56ccSmrg	  prev=
714288de56ccSmrg	  continue
714388de56ccSmrg	  ;;
71442e9c7c8cSmrg	esac
714588de56ccSmrg      fi # test -n "$prev"
71462e9c7c8cSmrg
7147862bcd1aSmrg      prevarg=$arg
71482e9c7c8cSmrg
714988de56ccSmrg      case $arg in
715088de56ccSmrg      -all-static)
715188de56ccSmrg	if test -n "$link_static_flag"; then
715288de56ccSmrg	  # See comment for -static flag below, for more details.
715388de56ccSmrg	  func_append compile_command " $link_static_flag"
715488de56ccSmrg	  func_append finalize_command " $link_static_flag"
715588de56ccSmrg	fi
715688de56ccSmrg	continue
715788de56ccSmrg	;;
71582e9c7c8cSmrg
715988de56ccSmrg      -allow-undefined)
716088de56ccSmrg	# FIXME: remove this flag sometime in the future.
7161862bcd1aSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
716288de56ccSmrg	;;
71632e9c7c8cSmrg
716488de56ccSmrg      -avoid-version)
716588de56ccSmrg	avoid_version=yes
716688de56ccSmrg	continue
716788de56ccSmrg	;;
71682e9c7c8cSmrg
7169e9fcaa8aSmrg      -bindir)
7170e9fcaa8aSmrg	prev=bindir
7171e9fcaa8aSmrg	continue
7172e9fcaa8aSmrg	;;
7173e9fcaa8aSmrg
717488de56ccSmrg      -dlopen)
717588de56ccSmrg	prev=dlfiles
717688de56ccSmrg	continue
717788de56ccSmrg	;;
71782e9c7c8cSmrg
717988de56ccSmrg      -dlpreopen)
718088de56ccSmrg	prev=dlprefiles
718188de56ccSmrg	continue
718288de56ccSmrg	;;
71832e9c7c8cSmrg
718488de56ccSmrg      -export-dynamic)
718588de56ccSmrg	export_dynamic=yes
718688de56ccSmrg	continue
718788de56ccSmrg	;;
71882e9c7c8cSmrg
718988de56ccSmrg      -export-symbols | -export-symbols-regex)
719088de56ccSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
719188de56ccSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
719288de56ccSmrg	fi
7193862bcd1aSmrg	if test X-export-symbols = "X$arg"; then
719488de56ccSmrg	  prev=expsyms
719588de56ccSmrg	else
719688de56ccSmrg	  prev=expsyms_regex
719788de56ccSmrg	fi
719888de56ccSmrg	continue
719988de56ccSmrg	;;
72002e9c7c8cSmrg
720188de56ccSmrg      -framework)
720288de56ccSmrg	prev=framework
720388de56ccSmrg	continue
720488de56ccSmrg	;;
72052e9c7c8cSmrg
720688de56ccSmrg      -inst-prefix-dir)
720788de56ccSmrg	prev=inst_prefix
720888de56ccSmrg	continue
720988de56ccSmrg	;;
72102e9c7c8cSmrg
721188de56ccSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
721288de56ccSmrg      # so, if we see these flags be careful not to treat them like -L
721388de56ccSmrg      -L[A-Z][A-Z]*:*)
721488de56ccSmrg	case $with_gcc/$host in
721588de56ccSmrg	no/*-*-irix* | /*-*-irix*)
721688de56ccSmrg	  func_append compile_command " $arg"
721788de56ccSmrg	  func_append finalize_command " $arg"
721888de56ccSmrg	  ;;
721988de56ccSmrg	esac
722088de56ccSmrg	continue
722188de56ccSmrg	;;
72222e9c7c8cSmrg
722388de56ccSmrg      -L*)
7224e9fcaa8aSmrg	func_stripname "-L" '' "$arg"
7225e9fcaa8aSmrg	if test -z "$func_stripname_result"; then
722688de56ccSmrg	  if test "$#" -gt 0; then
7227862bcd1aSmrg	    func_fatal_error "require no space between '-L' and '$1'"
722888de56ccSmrg	  else
7229862bcd1aSmrg	    func_fatal_error "need path for '-L' option"
723088de56ccSmrg	  fi
723188de56ccSmrg	fi
7232e9fcaa8aSmrg	func_resolve_sysroot "$func_stripname_result"
7233e9fcaa8aSmrg	dir=$func_resolve_sysroot_result
723488de56ccSmrg	# We need an absolute path.
723588de56ccSmrg	case $dir in
723688de56ccSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
723788de56ccSmrg	*)
723888de56ccSmrg	  absdir=`cd "$dir" && pwd`
723988de56ccSmrg	  test -z "$absdir" && \
7240862bcd1aSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241862bcd1aSmrg	  dir=$absdir
724288de56ccSmrg	  ;;
724388de56ccSmrg	esac
724488de56ccSmrg	case "$deplibs " in
7245e9fcaa8aSmrg	*" -L$dir "* | *" $arg "*)
7246e9fcaa8aSmrg	  # Will only happen for absolute or sysroot arguments
7247e9fcaa8aSmrg	  ;;
724888de56ccSmrg	*)
7249e9fcaa8aSmrg	  # Preserve sysroot, but never include relative directories
7250e9fcaa8aSmrg	  case $dir in
7251e9fcaa8aSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7252e9fcaa8aSmrg	    *) func_append deplibs " -L$dir" ;;
7253e9fcaa8aSmrg	  esac
7254e9fcaa8aSmrg	  func_append lib_search_path " $dir"
725588de56ccSmrg	  ;;
725688de56ccSmrg	esac
725788de56ccSmrg	case $host in
725888de56ccSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7259e9fcaa8aSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
726088de56ccSmrg	  case :$dllsearchpath: in
726188de56ccSmrg	  *":$dir:"*) ;;
726288de56ccSmrg	  ::) dllsearchpath=$dir;;
7263e9fcaa8aSmrg	  *) func_append dllsearchpath ":$dir";;
726488de56ccSmrg	  esac
726588de56ccSmrg	  case :$dllsearchpath: in
726688de56ccSmrg	  *":$testbindir:"*) ;;
726788de56ccSmrg	  ::) dllsearchpath=$testbindir;;
7268e9fcaa8aSmrg	  *) func_append dllsearchpath ":$testbindir";;
726988de56ccSmrg	  esac
727088de56ccSmrg	  ;;
727188de56ccSmrg	esac
727288de56ccSmrg	continue
727388de56ccSmrg	;;
72742e9c7c8cSmrg
727588de56ccSmrg      -l*)
7276862bcd1aSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
727788de56ccSmrg	  case $host in
7278e9fcaa8aSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
727988de56ccSmrg	    # These systems don't actually have a C or math library (as such)
728088de56ccSmrg	    continue
728188de56ccSmrg	    ;;
728288de56ccSmrg	  *-*-os2*)
728388de56ccSmrg	    # These systems don't actually have a C library (as such)
7284862bcd1aSmrg	    test X-lc = "X$arg" && continue
728588de56ccSmrg	    ;;
7286e9628295Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
728788de56ccSmrg	    # Do not include libc due to us having libc/libc_r.
7288862bcd1aSmrg	    test X-lc = "X$arg" && continue
728988de56ccSmrg	    ;;
729088de56ccSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
729188de56ccSmrg	    # Rhapsody C and math libraries are in the System framework
7292e9fcaa8aSmrg	    func_append deplibs " System.ltframework"
729388de56ccSmrg	    continue
729488de56ccSmrg	    ;;
729588de56ccSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
729688de56ccSmrg	    # Causes problems with __ctype
7297862bcd1aSmrg	    test X-lc = "X$arg" && continue
729888de56ccSmrg	    ;;
729988de56ccSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
730088de56ccSmrg	    # Compiler inserts libc in the correct place for threads to work
7301862bcd1aSmrg	    test X-lc = "X$arg" && continue
730288de56ccSmrg	    ;;
730388de56ccSmrg	  esac
7304862bcd1aSmrg	elif test X-lc_r = "X$arg"; then
730588de56ccSmrg	 case $host in
7306e9628295Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
730788de56ccSmrg	   # Do not include libc_r directly, use -pthread flag.
730888de56ccSmrg	   continue
730988de56ccSmrg	   ;;
731088de56ccSmrg	 esac
731188de56ccSmrg	fi
7312e9fcaa8aSmrg	func_append deplibs " $arg"
731388de56ccSmrg	continue
731488de56ccSmrg	;;
73152e9c7c8cSmrg
7316862bcd1aSmrg      -mllvm)
7317862bcd1aSmrg	prev=mllvm
7318862bcd1aSmrg	continue
7319862bcd1aSmrg	;;
7320862bcd1aSmrg
732188de56ccSmrg      -module)
732288de56ccSmrg	module=yes
732388de56ccSmrg	continue
732488de56ccSmrg	;;
73252e9c7c8cSmrg
732688de56ccSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
732788de56ccSmrg      # classes, name mangling, and exception handling.
732888de56ccSmrg      # Darwin uses the -arch flag to determine output architecture.
7329e9fcaa8aSmrg      -model|-arch|-isysroot|--sysroot)
7330e9fcaa8aSmrg	func_append compiler_flags " $arg"
733188de56ccSmrg	func_append compile_command " $arg"
733288de56ccSmrg	func_append finalize_command " $arg"
733388de56ccSmrg	prev=xcompiler
733488de56ccSmrg	continue
733588de56ccSmrg	;;
7336e9628295Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337e9628295Smrg     -pthread)
7338e9628295Smrg	case $host in
7339e9628295Smrg	  *solaris2*) ;;
7340e9628295Smrg	  *)
7341e9628295Smrg	    case "$new_inherited_linker_flags " in
7342e9628295Smrg	        *" $arg "*) ;;
7343e9628295Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344e9628295Smrg	    esac
7345e9628295Smrg	  ;;
7346e9628295Smrg	esac
7347e9628295Smrg	continue
7348e9628295Smrg	;;
7349e9628295Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350eb411b4bSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7351e9fcaa8aSmrg	func_append compiler_flags " $arg"
735288de56ccSmrg	func_append compile_command " $arg"
735388de56ccSmrg	func_append finalize_command " $arg"
735488de56ccSmrg	case "$new_inherited_linker_flags " in
735588de56ccSmrg	    *" $arg "*) ;;
7356e9fcaa8aSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
735788de56ccSmrg	esac
735888de56ccSmrg	continue
735988de56ccSmrg	;;
73602e9c7c8cSmrg
736188de56ccSmrg      -multi_module)
7362862bcd1aSmrg	single_module=$wl-multi_module
736388de56ccSmrg	continue
736488de56ccSmrg	;;
73652e9c7c8cSmrg
736688de56ccSmrg      -no-fast-install)
736788de56ccSmrg	fast_install=no
736888de56ccSmrg	continue
736988de56ccSmrg	;;
73702e9c7c8cSmrg
737188de56ccSmrg      -no-install)
737288de56ccSmrg	case $host in
737388de56ccSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
737488de56ccSmrg	  # The PATH hackery in wrapper scripts is required on Windows
737588de56ccSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7376862bcd1aSmrg	  func_warning "'-no-install' is ignored for $host"
7377862bcd1aSmrg	  func_warning "assuming '-no-fast-install' instead"
737888de56ccSmrg	  fast_install=no
737988de56ccSmrg	  ;;
738088de56ccSmrg	*) no_install=yes ;;
738188de56ccSmrg	esac
738288de56ccSmrg	continue
738388de56ccSmrg	;;
73842e9c7c8cSmrg
738588de56ccSmrg      -no-undefined)
738688de56ccSmrg	allow_undefined=no
738788de56ccSmrg	continue
738888de56ccSmrg	;;
73892e9c7c8cSmrg
739088de56ccSmrg      -objectlist)
739188de56ccSmrg	prev=objectlist
739288de56ccSmrg	continue
739388de56ccSmrg	;;
73942e9c7c8cSmrg
7395862bcd1aSmrg      -os2dllname)
7396862bcd1aSmrg	prev=os2dllname
7397862bcd1aSmrg	continue
7398862bcd1aSmrg	;;
7399862bcd1aSmrg
740088de56ccSmrg      -o) prev=output ;;
74012e9c7c8cSmrg
740288de56ccSmrg      -precious-files-regex)
740388de56ccSmrg	prev=precious_regex
740488de56ccSmrg	continue
740588de56ccSmrg	;;
74062e9c7c8cSmrg
740788de56ccSmrg      -release)
740888de56ccSmrg	prev=release
740988de56ccSmrg	continue
741088de56ccSmrg	;;
74112e9c7c8cSmrg
741288de56ccSmrg      -rpath)
741388de56ccSmrg	prev=rpath
741488de56ccSmrg	continue
741588de56ccSmrg	;;
74162e9c7c8cSmrg
741788de56ccSmrg      -R)
741888de56ccSmrg	prev=xrpath
741988de56ccSmrg	continue
742088de56ccSmrg	;;
74212e9c7c8cSmrg
742288de56ccSmrg      -R*)
742388de56ccSmrg	func_stripname '-R' '' "$arg"
742488de56ccSmrg	dir=$func_stripname_result
742588de56ccSmrg	# We need an absolute path.
742688de56ccSmrg	case $dir in
742788de56ccSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7428e9fcaa8aSmrg	=*)
7429e9fcaa8aSmrg	  func_stripname '=' '' "$dir"
7430e9fcaa8aSmrg	  dir=$lt_sysroot$func_stripname_result
7431e9fcaa8aSmrg	  ;;
743288de56ccSmrg	*)
743388de56ccSmrg	  func_fatal_error "only absolute run-paths are allowed"
743488de56ccSmrg	  ;;
743588de56ccSmrg	esac
743688de56ccSmrg	case "$xrpath " in
743788de56ccSmrg	*" $dir "*) ;;
7438e9fcaa8aSmrg	*) func_append xrpath " $dir" ;;
743988de56ccSmrg	esac
744088de56ccSmrg	continue
744188de56ccSmrg	;;
74422e9c7c8cSmrg
744388de56ccSmrg      -shared)
744488de56ccSmrg	# The effects of -shared are defined in a previous loop.
744588de56ccSmrg	continue
744688de56ccSmrg	;;
74472e9c7c8cSmrg
744888de56ccSmrg      -shrext)
744988de56ccSmrg	prev=shrext
745088de56ccSmrg	continue
745188de56ccSmrg	;;
74522e9c7c8cSmrg
745388de56ccSmrg      -static | -static-libtool-libs)
745488de56ccSmrg	# The effects of -static are defined in a previous loop.
745588de56ccSmrg	# We used to do the same as -all-static on platforms that
745688de56ccSmrg	# didn't have a PIC flag, but the assumption that the effects
745788de56ccSmrg	# would be equivalent was wrong.  It would break on at least
745888de56ccSmrg	# Digital Unix and AIX.
745988de56ccSmrg	continue
746088de56ccSmrg	;;
74612e9c7c8cSmrg
746288de56ccSmrg      -thread-safe)
746388de56ccSmrg	thread_safe=yes
746488de56ccSmrg	continue
746588de56ccSmrg	;;
74662e9c7c8cSmrg
746788de56ccSmrg      -version-info)
746888de56ccSmrg	prev=vinfo
746988de56ccSmrg	continue
747088de56ccSmrg	;;
74712e9c7c8cSmrg
747288de56ccSmrg      -version-number)
747388de56ccSmrg	prev=vinfo
747488de56ccSmrg	vinfo_number=yes
747588de56ccSmrg	continue
747688de56ccSmrg	;;
74772e9c7c8cSmrg
747888de56ccSmrg      -weak)
747988de56ccSmrg        prev=weak
748088de56ccSmrg	continue
748188de56ccSmrg	;;
74821ab64890Smrg
748388de56ccSmrg      -Wc,*)
748488de56ccSmrg	func_stripname '-Wc,' '' "$arg"
748588de56ccSmrg	args=$func_stripname_result
748688de56ccSmrg	arg=
7487862bcd1aSmrg	save_ifs=$IFS; IFS=,
748888de56ccSmrg	for flag in $args; do
7489862bcd1aSmrg	  IFS=$save_ifs
7490e9628295Smrg          func_quote_arg pretty "$flag"
7491e9628295Smrg	  func_append arg " $func_quote_arg_result"
7492e9628295Smrg	  func_append compiler_flags " $func_quote_arg_result"
749388de56ccSmrg	done
7494862bcd1aSmrg	IFS=$save_ifs
749588de56ccSmrg	func_stripname ' ' '' "$arg"
749688de56ccSmrg	arg=$func_stripname_result
749788de56ccSmrg	;;
7498b4ee4795Smrg
749988de56ccSmrg      -Wl,*)
750088de56ccSmrg	func_stripname '-Wl,' '' "$arg"
750188de56ccSmrg	args=$func_stripname_result
750288de56ccSmrg	arg=
7503862bcd1aSmrg	save_ifs=$IFS; IFS=,
750488de56ccSmrg	for flag in $args; do
7505862bcd1aSmrg	  IFS=$save_ifs
7506e9628295Smrg          func_quote_arg pretty "$flag"
7507e9628295Smrg	  func_append arg " $wl$func_quote_arg_result"
7508e9628295Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509e9628295Smrg	  func_append linker_flags " $func_quote_arg_result"
751088de56ccSmrg	done
7511862bcd1aSmrg	IFS=$save_ifs
751288de56ccSmrg	func_stripname ' ' '' "$arg"
751388de56ccSmrg	arg=$func_stripname_result
751488de56ccSmrg	;;
7515b4ee4795Smrg
7516e9628295Smrg      -Xassembler)
7517e9628295Smrg        prev=xassembler
7518e9628295Smrg        continue
7519e9628295Smrg        ;;
7520e9628295Smrg
752188de56ccSmrg      -Xcompiler)
752288de56ccSmrg	prev=xcompiler
752388de56ccSmrg	continue
752488de56ccSmrg	;;
7525b4ee4795Smrg
752688de56ccSmrg      -Xlinker)
752788de56ccSmrg	prev=xlinker
752888de56ccSmrg	continue
752988de56ccSmrg	;;
7530b4ee4795Smrg
753188de56ccSmrg      -XCClinker)
753288de56ccSmrg	prev=xcclinker
753388de56ccSmrg	continue
753488de56ccSmrg	;;
7535b4ee4795Smrg
753688de56ccSmrg      # -msg_* for osf cc
753788de56ccSmrg      -msg_*)
7538e9628295Smrg	func_quote_arg pretty "$arg"
7539e9628295Smrg	arg=$func_quote_arg_result
754088de56ccSmrg	;;
7541b4ee4795Smrg
7542e9fcaa8aSmrg      # Flags to be passed through unchanged, with rationale:
7543e9fcaa8aSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7544e9fcaa8aSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7545e9fcaa8aSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7546e9fcaa8aSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7547e9fcaa8aSmrg      # -q*                  compiler args for the IBM compiler
7548e9fcaa8aSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7549e9fcaa8aSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7550e9fcaa8aSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551862bcd1aSmrg      # -fstack-protector*   stack protector flags for GCC
7552e9fcaa8aSmrg      # @file                GCC response files
7553e9fcaa8aSmrg      # -tp=*                Portland pgcc target processor selection
7554e9fcaa8aSmrg      # --sysroot=*          for sysroot support
7555862bcd1aSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7556e9628295Smrg      # -specs=*             GCC specs files
7557862bcd1aSmrg      # -stdlib=*            select c++ std lib with clang
7558e9628295Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
7559e9628295Smrg      # -fuse-ld=*           Linker select flags for GCC
7560e9628295Smrg      # -Wa,*                Pass flags directly to the assembler
756188de56ccSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7562e9fcaa8aSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7563e9628295Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564e9628295Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565e9628295Smrg        func_quote_arg pretty "$arg"
7566e9628295Smrg	arg=$func_quote_arg_result
756788de56ccSmrg        func_append compile_command " $arg"
756888de56ccSmrg        func_append finalize_command " $arg"
7569e9fcaa8aSmrg        func_append compiler_flags " $arg"
757088de56ccSmrg        continue
757188de56ccSmrg        ;;
7572b4ee4795Smrg
7573862bcd1aSmrg      -Z*)
7574862bcd1aSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575862bcd1aSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576862bcd1aSmrg	  compiler_flags="$compiler_flags $arg"
7577862bcd1aSmrg	  func_append compile_command " $arg"
7578862bcd1aSmrg	  func_append finalize_command " $arg"
7579862bcd1aSmrg	  case $arg in
7580862bcd1aSmrg	  -Zlinker | -Zstack)
7581862bcd1aSmrg	    prev=xcompiler
7582862bcd1aSmrg	    ;;
7583862bcd1aSmrg	  esac
7584862bcd1aSmrg	  continue
7585862bcd1aSmrg        else
7586862bcd1aSmrg	  # Otherwise treat like 'Some other compiler flag' below
7587e9628295Smrg	  func_quote_arg pretty "$arg"
7588e9628295Smrg	  arg=$func_quote_arg_result
7589862bcd1aSmrg        fi
7590862bcd1aSmrg	;;
7591862bcd1aSmrg
759288de56ccSmrg      # Some other compiler flag.
759388de56ccSmrg      -* | +*)
7594e9628295Smrg        func_quote_arg pretty "$arg"
7595e9628295Smrg	arg=$func_quote_arg_result
759688de56ccSmrg	;;
7597b4ee4795Smrg
759888de56ccSmrg      *.$objext)
759988de56ccSmrg	# A standard object.
7600e9fcaa8aSmrg	func_append objs " $arg"
760188de56ccSmrg	;;
7602b4ee4795Smrg
760388de56ccSmrg      *.lo)
760488de56ccSmrg	# A libtool-controlled object.
7605b4ee4795Smrg
760688de56ccSmrg	# Check to see that this really is a libtool object.
760788de56ccSmrg	if func_lalib_unsafe_p "$arg"; then
760888de56ccSmrg	  pic_object=
760988de56ccSmrg	  non_pic_object=
7610b4ee4795Smrg
761188de56ccSmrg	  # Read the .lo file
761288de56ccSmrg	  func_source "$arg"
7613b4ee4795Smrg
761488de56ccSmrg	  if test -z "$pic_object" ||
761588de56ccSmrg	     test -z "$non_pic_object" ||
7616862bcd1aSmrg	     test none = "$pic_object" &&
7617862bcd1aSmrg	     test none = "$non_pic_object"; then
7618862bcd1aSmrg	    func_fatal_error "cannot find name of object for '$arg'"
761988de56ccSmrg	  fi
7620b4ee4795Smrg
762188de56ccSmrg	  # Extract subdirectory from the argument.
762288de56ccSmrg	  func_dirname "$arg" "/" ""
7623862bcd1aSmrg	  xdir=$func_dirname_result
7624b4ee4795Smrg
7625862bcd1aSmrg	  test none = "$pic_object" || {
762688de56ccSmrg	    # Prepend the subdirectory the object is found in.
7627862bcd1aSmrg	    pic_object=$xdir$pic_object
7628b4ee4795Smrg
7629862bcd1aSmrg	    if test dlfiles = "$prev"; then
7630862bcd1aSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7631e9fcaa8aSmrg		func_append dlfiles " $pic_object"
763288de56ccSmrg		prev=
763388de56ccSmrg		continue
763488de56ccSmrg	      else
763588de56ccSmrg		# If libtool objects are unsupported, then we need to preload.
763688de56ccSmrg		prev=dlprefiles
763788de56ccSmrg	      fi
763888de56ccSmrg	    fi
7639b4ee4795Smrg
764088de56ccSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7641862bcd1aSmrg	    if test dlprefiles = "$prev"; then
764288de56ccSmrg	      # Preload the old-style object.
7643e9fcaa8aSmrg	      func_append dlprefiles " $pic_object"
764488de56ccSmrg	      prev=
764588de56ccSmrg	    fi
76461ab64890Smrg
764788de56ccSmrg	    # A PIC object.
764888de56ccSmrg	    func_append libobjs " $pic_object"
7649862bcd1aSmrg	    arg=$pic_object
7650862bcd1aSmrg	  }
76511ab64890Smrg
765288de56ccSmrg	  # Non-PIC object.
7653862bcd1aSmrg	  if test none != "$non_pic_object"; then
765488de56ccSmrg	    # Prepend the subdirectory the object is found in.
7655862bcd1aSmrg	    non_pic_object=$xdir$non_pic_object
76561ab64890Smrg
765788de56ccSmrg	    # A standard non-PIC object
765888de56ccSmrg	    func_append non_pic_objects " $non_pic_object"
7659862bcd1aSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660862bcd1aSmrg	      arg=$non_pic_object
766188de56ccSmrg	    fi
766288de56ccSmrg	  else
766388de56ccSmrg	    # If the PIC object exists, use it instead.
766488de56ccSmrg	    # $xdir was prepended to $pic_object above.
7665862bcd1aSmrg	    non_pic_object=$pic_object
766688de56ccSmrg	    func_append non_pic_objects " $non_pic_object"
766788de56ccSmrg	  fi
766888de56ccSmrg	else
766988de56ccSmrg	  # Only an error if not doing a dry-run.
767088de56ccSmrg	  if $opt_dry_run; then
767188de56ccSmrg	    # Extract subdirectory from the argument.
767288de56ccSmrg	    func_dirname "$arg" "/" ""
7673862bcd1aSmrg	    xdir=$func_dirname_result
767488de56ccSmrg
767588de56ccSmrg	    func_lo2o "$arg"
767688de56ccSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
767788de56ccSmrg	    non_pic_object=$xdir$func_lo2o_result
767888de56ccSmrg	    func_append libobjs " $pic_object"
767988de56ccSmrg	    func_append non_pic_objects " $non_pic_object"
768088de56ccSmrg	  else
7681862bcd1aSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
768288de56ccSmrg	  fi
768388de56ccSmrg	fi
768488de56ccSmrg	;;
76851ab64890Smrg
768688de56ccSmrg      *.$libext)
768788de56ccSmrg	# An archive.
7688e9fcaa8aSmrg	func_append deplibs " $arg"
7689e9fcaa8aSmrg	func_append old_deplibs " $arg"
769088de56ccSmrg	continue
769188de56ccSmrg	;;
769288de56ccSmrg
769388de56ccSmrg      *.la)
769488de56ccSmrg	# A libtool-controlled library.
769588de56ccSmrg
7696e9fcaa8aSmrg	func_resolve_sysroot "$arg"
7697862bcd1aSmrg	if test dlfiles = "$prev"; then
769888de56ccSmrg	  # This library was specified with -dlopen.
7699e9fcaa8aSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
770088de56ccSmrg	  prev=
7701862bcd1aSmrg	elif test dlprefiles = "$prev"; then
770288de56ccSmrg	  # The library was specified with -dlpreopen.
7703e9fcaa8aSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
770488de56ccSmrg	  prev=
770588de56ccSmrg	else
7706e9fcaa8aSmrg	  func_append deplibs " $func_resolve_sysroot_result"
770788de56ccSmrg	fi
770888de56ccSmrg	continue
770988de56ccSmrg	;;
771088de56ccSmrg
771188de56ccSmrg      # Some other compiler argument.
771288de56ccSmrg      *)
771388de56ccSmrg	# Unknown arguments in both finalize_command and compile_command need
771488de56ccSmrg	# to be aesthetically quoted because they are evaled later.
7715e9628295Smrg	func_quote_arg pretty "$arg"
7716e9628295Smrg	arg=$func_quote_arg_result
771788de56ccSmrg	;;
771888de56ccSmrg      esac # arg
771988de56ccSmrg
772088de56ccSmrg      # Now actually substitute the argument into the commands.
772188de56ccSmrg      if test -n "$arg"; then
772288de56ccSmrg	func_append compile_command " $arg"
772388de56ccSmrg	func_append finalize_command " $arg"
772488de56ccSmrg      fi
772588de56ccSmrg    done # argument parsing loop
772688de56ccSmrg
772788de56ccSmrg    test -n "$prev" && \
7728862bcd1aSmrg      func_fatal_help "the '$prevarg' option requires an argument"
772988de56ccSmrg
7730862bcd1aSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
773188de56ccSmrg      eval arg=\"$export_dynamic_flag_spec\"
773288de56ccSmrg      func_append compile_command " $arg"
773388de56ccSmrg      func_append finalize_command " $arg"
773488de56ccSmrg    fi
773588de56ccSmrg
773688de56ccSmrg    oldlibs=
773788de56ccSmrg    # calculate the name of the file, without its directory
773888de56ccSmrg    func_basename "$output"
7739862bcd1aSmrg    outputname=$func_basename_result
7740862bcd1aSmrg    libobjs_save=$libobjs
774188de56ccSmrg
774288de56ccSmrg    if test -n "$shlibpath_var"; then
774388de56ccSmrg      # get the directories listed in $shlibpath_var
7744862bcd1aSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
774588de56ccSmrg    else
774688de56ccSmrg      shlib_search_path=
774788de56ccSmrg    fi
774888de56ccSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
774988de56ccSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
775088de56ccSmrg
7751862bcd1aSmrg    # Definition is injected by LT_CONFIG during libtool generation.
7752862bcd1aSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753862bcd1aSmrg
775488de56ccSmrg    func_dirname "$output" "/" ""
7755862bcd1aSmrg    output_objdir=$func_dirname_result$objdir
7756e9fcaa8aSmrg    func_to_tool_file "$output_objdir/"
7757e9fcaa8aSmrg    tool_output_objdir=$func_to_tool_file_result
775888de56ccSmrg    # Create the object directory.
775988de56ccSmrg    func_mkdir_p "$output_objdir"
776088de56ccSmrg
776188de56ccSmrg    # Determine the type of output
776288de56ccSmrg    case $output in
776388de56ccSmrg    "")
776488de56ccSmrg      func_fatal_help "you must specify an output file"
776588de56ccSmrg      ;;
776688de56ccSmrg    *.$libext) linkmode=oldlib ;;
776788de56ccSmrg    *.lo | *.$objext) linkmode=obj ;;
776888de56ccSmrg    *.la) linkmode=lib ;;
776988de56ccSmrg    *) linkmode=prog ;; # Anything else should be a program.
777088de56ccSmrg    esac
777188de56ccSmrg
777288de56ccSmrg    specialdeplibs=
777388de56ccSmrg
777488de56ccSmrg    libs=
777588de56ccSmrg    # Find all interdependent deplibs by searching for libraries
777688de56ccSmrg    # that are linked more than once (e.g. -la -lb -la)
777788de56ccSmrg    for deplib in $deplibs; do
7778862bcd1aSmrg      if $opt_preserve_dup_deps; then
777988de56ccSmrg	case "$libs " in
7780e9fcaa8aSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
778188de56ccSmrg	esac
778288de56ccSmrg      fi
7783e9fcaa8aSmrg      func_append libs " $deplib"
778488de56ccSmrg    done
778588de56ccSmrg
7786862bcd1aSmrg    if test lib = "$linkmode"; then
778788de56ccSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
778888de56ccSmrg
778988de56ccSmrg      # Compute libraries that are listed more than once in $predeps
779088de56ccSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
779188de56ccSmrg      # not to be eliminated).
779288de56ccSmrg      pre_post_deps=
779388de56ccSmrg      if $opt_duplicate_compiler_generated_deps; then
779488de56ccSmrg	for pre_post_dep in $predeps $postdeps; do
779588de56ccSmrg	  case "$pre_post_deps " in
7796e9fcaa8aSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
779788de56ccSmrg	  esac
7798e9fcaa8aSmrg	  func_append pre_post_deps " $pre_post_dep"
779988de56ccSmrg	done
780088de56ccSmrg      fi
780188de56ccSmrg      pre_post_deps=
780288de56ccSmrg    fi
780388de56ccSmrg
780488de56ccSmrg    deplibs=
780588de56ccSmrg    newdependency_libs=
780688de56ccSmrg    newlib_search_path=
780788de56ccSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
780888de56ccSmrg    notinst_deplibs= # not-installed libtool libraries
780988de56ccSmrg    notinst_path= # paths that contain not-installed libtool libraries
781088de56ccSmrg
781188de56ccSmrg    case $linkmode in
781288de56ccSmrg    lib)
781388de56ccSmrg	passes="conv dlpreopen link"
781488de56ccSmrg	for file in $dlfiles $dlprefiles; do
781588de56ccSmrg	  case $file in
781688de56ccSmrg	  *.la) ;;
781788de56ccSmrg	  *)
7818862bcd1aSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
781988de56ccSmrg	    ;;
782088de56ccSmrg	  esac
782188de56ccSmrg	done
782288de56ccSmrg	;;
782388de56ccSmrg    prog)
782488de56ccSmrg	compile_deplibs=
782588de56ccSmrg	finalize_deplibs=
7826862bcd1aSmrg	alldeplibs=false
782788de56ccSmrg	newdlfiles=
782888de56ccSmrg	newdlprefiles=
782988de56ccSmrg	passes="conv scan dlopen dlpreopen link"
783088de56ccSmrg	;;
783188de56ccSmrg    *)  passes="conv"
783288de56ccSmrg	;;
783388de56ccSmrg    esac
783488de56ccSmrg
783588de56ccSmrg    for pass in $passes; do
783688de56ccSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
783788de56ccSmrg      # so that -L comes before libs that need it for instance...
7838862bcd1aSmrg      if test lib,link = "$linkmode,$pass"; then
783988de56ccSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
784088de56ccSmrg	##        order, and fix it there properly
784188de56ccSmrg        tmp_deplibs=
784288de56ccSmrg	for deplib in $deplibs; do
784388de56ccSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
784488de56ccSmrg	done
7845862bcd1aSmrg	deplibs=$tmp_deplibs
784688de56ccSmrg      fi
784788de56ccSmrg
7848862bcd1aSmrg      if test lib,link = "$linkmode,$pass" ||
7849862bcd1aSmrg	 test prog,scan = "$linkmode,$pass"; then
7850862bcd1aSmrg	libs=$deplibs
785188de56ccSmrg	deplibs=
785288de56ccSmrg      fi
7853862bcd1aSmrg      if test prog = "$linkmode"; then
785488de56ccSmrg	case $pass in
7855862bcd1aSmrg	dlopen) libs=$dlfiles ;;
7856862bcd1aSmrg	dlpreopen) libs=$dlprefiles ;;
785703ea5dc6Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
785888de56ccSmrg	esac
785988de56ccSmrg      fi
7860862bcd1aSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
786188de56ccSmrg	# Collect and forward deplibs of preopened libtool libs
786288de56ccSmrg	for lib in $dlprefiles; do
786388de56ccSmrg	  # Ignore non-libtool-libs
786488de56ccSmrg	  dependency_libs=
7865e9fcaa8aSmrg	  func_resolve_sysroot "$lib"
786688de56ccSmrg	  case $lib in
7867e9fcaa8aSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
786888de56ccSmrg	  esac
786988de56ccSmrg
787088de56ccSmrg	  # Collect preopened libtool deplibs, except any this library
787188de56ccSmrg	  # has declared as weak libs
787288de56ccSmrg	  for deplib in $dependency_libs; do
7873e9fcaa8aSmrg	    func_basename "$deplib"
7874e9fcaa8aSmrg            deplib_base=$func_basename_result
787588de56ccSmrg	    case " $weak_libs " in
787688de56ccSmrg	    *" $deplib_base "*) ;;
7877e9fcaa8aSmrg	    *) func_append deplibs " $deplib" ;;
787888de56ccSmrg	    esac
787988de56ccSmrg	  done
788088de56ccSmrg	done
7881862bcd1aSmrg	libs=$dlprefiles
788288de56ccSmrg      fi
7883862bcd1aSmrg      if test dlopen = "$pass"; then
788488de56ccSmrg	# Collect dlpreopened libraries
7885862bcd1aSmrg	save_deplibs=$deplibs
788688de56ccSmrg	deplibs=
788788de56ccSmrg      fi
788888de56ccSmrg
788988de56ccSmrg      for deplib in $libs; do
789088de56ccSmrg	lib=
7891862bcd1aSmrg	found=false
789288de56ccSmrg	case $deplib in
7893eb411b4bSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894eb411b4bSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895862bcd1aSmrg	  if test prog,link = "$linkmode,$pass"; then
789688de56ccSmrg	    compile_deplibs="$deplib $compile_deplibs"
789788de56ccSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
789888de56ccSmrg	  else
7899e9fcaa8aSmrg	    func_append compiler_flags " $deplib"
7900862bcd1aSmrg	    if test lib = "$linkmode"; then
790188de56ccSmrg		case "$new_inherited_linker_flags " in
790288de56ccSmrg		    *" $deplib "*) ;;
7903e9fcaa8aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
790488de56ccSmrg		esac
790588de56ccSmrg	    fi
790688de56ccSmrg	  fi
790788de56ccSmrg	  continue
790888de56ccSmrg	  ;;
790988de56ccSmrg	-l*)
7910862bcd1aSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911862bcd1aSmrg	    func_warning "'-l' is ignored for archives/objects"
791288de56ccSmrg	    continue
791388de56ccSmrg	  fi
791488de56ccSmrg	  func_stripname '-l' '' "$deplib"
791588de56ccSmrg	  name=$func_stripname_result
7916862bcd1aSmrg	  if test lib = "$linkmode"; then
791788de56ccSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
791888de56ccSmrg	  else
791988de56ccSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
792088de56ccSmrg	  fi
792188de56ccSmrg	  for searchdir in $searchdirs; do
792288de56ccSmrg	    for search_ext in .la $std_shrext .so .a; do
792388de56ccSmrg	      # Search the libtool library
7924862bcd1aSmrg	      lib=$searchdir/lib$name$search_ext
792588de56ccSmrg	      if test -f "$lib"; then
7926862bcd1aSmrg		if test .la = "$search_ext"; then
7927862bcd1aSmrg		  found=:
792888de56ccSmrg		else
7929862bcd1aSmrg		  found=false
793088de56ccSmrg		fi
793188de56ccSmrg		break 2
793288de56ccSmrg	      fi
793388de56ccSmrg	    done
793488de56ccSmrg	  done
7935862bcd1aSmrg	  if $found; then
7936862bcd1aSmrg	    # deplib is a libtool library
793788de56ccSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
793888de56ccSmrg	    # We need to do some special things here, and not later.
7939862bcd1aSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
794088de56ccSmrg	      case " $predeps $postdeps " in
794188de56ccSmrg	      *" $deplib "*)
794288de56ccSmrg		if func_lalib_p "$lib"; then
794388de56ccSmrg		  library_names=
794488de56ccSmrg		  old_library=
794588de56ccSmrg		  func_source "$lib"
794688de56ccSmrg		  for l in $old_library $library_names; do
7947862bcd1aSmrg		    ll=$l
794888de56ccSmrg		  done
7949862bcd1aSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950862bcd1aSmrg		    found=false
795188de56ccSmrg		    func_dirname "$lib" "" "."
7952862bcd1aSmrg		    ladir=$func_dirname_result
795388de56ccSmrg		    lib=$ladir/$old_library
7954862bcd1aSmrg		    if test prog,link = "$linkmode,$pass"; then
795588de56ccSmrg		      compile_deplibs="$deplib $compile_deplibs"
795688de56ccSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
795788de56ccSmrg		    else
795888de56ccSmrg		      deplibs="$deplib $deplibs"
7959862bcd1aSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
796088de56ccSmrg		    fi
796188de56ccSmrg		    continue
796288de56ccSmrg		  fi
796388de56ccSmrg		fi
796488de56ccSmrg		;;
796588de56ccSmrg	      *) ;;
796688de56ccSmrg	      esac
796788de56ccSmrg	    fi
7968862bcd1aSmrg	  else
7969862bcd1aSmrg	    # deplib doesn't seem to be a libtool library
7970862bcd1aSmrg	    if test prog,link = "$linkmode,$pass"; then
7971862bcd1aSmrg	      compile_deplibs="$deplib $compile_deplibs"
7972862bcd1aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973862bcd1aSmrg	    else
7974862bcd1aSmrg	      deplibs="$deplib $deplibs"
7975862bcd1aSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976862bcd1aSmrg	    fi
7977862bcd1aSmrg	    continue
797888de56ccSmrg	  fi
797988de56ccSmrg	  ;; # -l
798088de56ccSmrg	*.ltframework)
7981862bcd1aSmrg	  if test prog,link = "$linkmode,$pass"; then
798288de56ccSmrg	    compile_deplibs="$deplib $compile_deplibs"
798388de56ccSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
798488de56ccSmrg	  else
798588de56ccSmrg	    deplibs="$deplib $deplibs"
7986862bcd1aSmrg	    if test lib = "$linkmode"; then
798788de56ccSmrg		case "$new_inherited_linker_flags " in
798888de56ccSmrg		    *" $deplib "*) ;;
7989e9fcaa8aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
799088de56ccSmrg		esac
799188de56ccSmrg	    fi
799288de56ccSmrg	  fi
799388de56ccSmrg	  continue
799488de56ccSmrg	  ;;
799588de56ccSmrg	-L*)
799688de56ccSmrg	  case $linkmode in
799788de56ccSmrg	  lib)
799888de56ccSmrg	    deplibs="$deplib $deplibs"
7999862bcd1aSmrg	    test conv = "$pass" && continue
800088de56ccSmrg	    newdependency_libs="$deplib $newdependency_libs"
800188de56ccSmrg	    func_stripname '-L' '' "$deplib"
8002e9fcaa8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8003e9fcaa8aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
800488de56ccSmrg	    ;;
800588de56ccSmrg	  prog)
8006862bcd1aSmrg	    if test conv = "$pass"; then
800788de56ccSmrg	      deplibs="$deplib $deplibs"
800888de56ccSmrg	      continue
800988de56ccSmrg	    fi
8010862bcd1aSmrg	    if test scan = "$pass"; then
801188de56ccSmrg	      deplibs="$deplib $deplibs"
801288de56ccSmrg	    else
801388de56ccSmrg	      compile_deplibs="$deplib $compile_deplibs"
801488de56ccSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
801588de56ccSmrg	    fi
801688de56ccSmrg	    func_stripname '-L' '' "$deplib"
8017e9fcaa8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8018e9fcaa8aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
801988de56ccSmrg	    ;;
802088de56ccSmrg	  *)
8021862bcd1aSmrg	    func_warning "'-L' is ignored for archives/objects"
802288de56ccSmrg	    ;;
802388de56ccSmrg	  esac # linkmode
802488de56ccSmrg	  continue
802588de56ccSmrg	  ;; # -L
802688de56ccSmrg	-R*)
8027862bcd1aSmrg	  if test link = "$pass"; then
802888de56ccSmrg	    func_stripname '-R' '' "$deplib"
8029e9fcaa8aSmrg	    func_resolve_sysroot "$func_stripname_result"
8030e9fcaa8aSmrg	    dir=$func_resolve_sysroot_result
803188de56ccSmrg	    # Make sure the xrpath contains only unique directories.
803288de56ccSmrg	    case "$xrpath " in
803388de56ccSmrg	    *" $dir "*) ;;
8034e9fcaa8aSmrg	    *) func_append xrpath " $dir" ;;
803588de56ccSmrg	    esac
803688de56ccSmrg	  fi
803788de56ccSmrg	  deplibs="$deplib $deplibs"
803888de56ccSmrg	  continue
803988de56ccSmrg	  ;;
8040e9fcaa8aSmrg	*.la)
8041e9fcaa8aSmrg	  func_resolve_sysroot "$deplib"
8042e9fcaa8aSmrg	  lib=$func_resolve_sysroot_result
8043e9fcaa8aSmrg	  ;;
804488de56ccSmrg	*.$libext)
8045862bcd1aSmrg	  if test conv = "$pass"; then
804688de56ccSmrg	    deplibs="$deplib $deplibs"
804788de56ccSmrg	    continue
804888de56ccSmrg	  fi
804988de56ccSmrg	  case $linkmode in
805088de56ccSmrg	  lib)
805188de56ccSmrg	    # Linking convenience modules into shared libraries is allowed,
805288de56ccSmrg	    # but linking other static libraries is non-portable.
805388de56ccSmrg	    case " $dlpreconveniencelibs " in
805488de56ccSmrg	    *" $deplib "*) ;;
805588de56ccSmrg	    *)
8056862bcd1aSmrg	      valid_a_lib=false
805788de56ccSmrg	      case $deplibs_check_method in
805888de56ccSmrg		match_pattern*)
805988de56ccSmrg		  set dummy $deplibs_check_method; shift
806088de56ccSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8061e9fcaa8aSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
806288de56ccSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063862bcd1aSmrg		    valid_a_lib=:
806488de56ccSmrg		  fi
806588de56ccSmrg		;;
806688de56ccSmrg		pass_all)
8067862bcd1aSmrg		  valid_a_lib=:
806888de56ccSmrg		;;
806988de56ccSmrg	      esac
8070862bcd1aSmrg	      if $valid_a_lib; then
8071862bcd1aSmrg		echo
8072862bcd1aSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073862bcd1aSmrg		$ECHO "*** static library $deplib is not portable!"
8074862bcd1aSmrg		deplibs="$deplib $deplibs"
8075862bcd1aSmrg	      else
8076e9fcaa8aSmrg		echo
807788de56ccSmrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8078e9fcaa8aSmrg		echo "*** I have the capability to make that library automatically link in when"
8079e9fcaa8aSmrg		echo "*** you link to this library.  But I can only do this if you have a"
8080e9fcaa8aSmrg		echo "*** shared version of the library, which you do not appear to have"
8081e9fcaa8aSmrg		echo "*** because the file extensions .$libext of this argument makes me believe"
8082e9fcaa8aSmrg		echo "*** that it is just a static archive that I should not use here."
808388de56ccSmrg	      fi
808488de56ccSmrg	      ;;
808588de56ccSmrg	    esac
808688de56ccSmrg	    continue
808788de56ccSmrg	    ;;
808888de56ccSmrg	  prog)
8089862bcd1aSmrg	    if test link != "$pass"; then
809088de56ccSmrg	      deplibs="$deplib $deplibs"
809188de56ccSmrg	    else
809288de56ccSmrg	      compile_deplibs="$deplib $compile_deplibs"
809388de56ccSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
809488de56ccSmrg	    fi
809588de56ccSmrg	    continue
809688de56ccSmrg	    ;;
809788de56ccSmrg	  esac # linkmode
809888de56ccSmrg	  ;; # *.$libext
809988de56ccSmrg	*.lo | *.$objext)
8100862bcd1aSmrg	  if test conv = "$pass"; then
810188de56ccSmrg	    deplibs="$deplib $deplibs"
8102862bcd1aSmrg	  elif test prog = "$linkmode"; then
8103862bcd1aSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
810488de56ccSmrg	      # If there is no dlopen support or we're linking statically,
810588de56ccSmrg	      # we need to preload.
8106e9fcaa8aSmrg	      func_append newdlprefiles " $deplib"
810788de56ccSmrg	      compile_deplibs="$deplib $compile_deplibs"
810888de56ccSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
810988de56ccSmrg	    else
8110e9fcaa8aSmrg	      func_append newdlfiles " $deplib"
811188de56ccSmrg	    fi
811288de56ccSmrg	  fi
811388de56ccSmrg	  continue
811488de56ccSmrg	  ;;
811588de56ccSmrg	%DEPLIBS%)
8116862bcd1aSmrg	  alldeplibs=:
811788de56ccSmrg	  continue
811888de56ccSmrg	  ;;
811988de56ccSmrg	esac # case $deplib
812088de56ccSmrg
8121862bcd1aSmrg	$found || test -f "$lib" \
8122862bcd1aSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
812388de56ccSmrg
812488de56ccSmrg	# Check to see that this really is a libtool archive.
812588de56ccSmrg	func_lalib_unsafe_p "$lib" \
8126862bcd1aSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
812788de56ccSmrg
812888de56ccSmrg	func_dirname "$lib" "" "."
8129862bcd1aSmrg	ladir=$func_dirname_result
813088de56ccSmrg
813188de56ccSmrg	dlname=
813288de56ccSmrg	dlopen=
813388de56ccSmrg	dlpreopen=
813488de56ccSmrg	libdir=
813588de56ccSmrg	library_names=
813688de56ccSmrg	old_library=
813788de56ccSmrg	inherited_linker_flags=
813888de56ccSmrg	# If the library was installed with an old release of libtool,
813988de56ccSmrg	# it will not redefine variables installed, or shouldnotlink
814088de56ccSmrg	installed=yes
814188de56ccSmrg	shouldnotlink=no
814288de56ccSmrg	avoidtemprpath=
814388de56ccSmrg
814488de56ccSmrg
814588de56ccSmrg	# Read the .la file
814688de56ccSmrg	func_source "$lib"
814788de56ccSmrg
814888de56ccSmrg	# Convert "-framework foo" to "foo.ltframework"
814988de56ccSmrg	if test -n "$inherited_linker_flags"; then
8150e9fcaa8aSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
815188de56ccSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
815288de56ccSmrg	    case " $new_inherited_linker_flags " in
815388de56ccSmrg	      *" $tmp_inherited_linker_flag "*) ;;
8154e9fcaa8aSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
815588de56ccSmrg	    esac
815688de56ccSmrg	  done
815788de56ccSmrg	fi
8158e9fcaa8aSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159862bcd1aSmrg	if test lib,link = "$linkmode,$pass" ||
8160862bcd1aSmrg	   test prog,scan = "$linkmode,$pass" ||
8161862bcd1aSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8162e9fcaa8aSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8163e9fcaa8aSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
816488de56ccSmrg	fi
816588de56ccSmrg
8166862bcd1aSmrg	if test conv = "$pass"; then
816788de56ccSmrg	  # Only check for convenience libraries
816888de56ccSmrg	  deplibs="$lib $deplibs"
816988de56ccSmrg	  if test -z "$libdir"; then
817088de56ccSmrg	    if test -z "$old_library"; then
8171862bcd1aSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
817288de56ccSmrg	    fi
817388de56ccSmrg	    # It is a libtool convenience library, so add in its objects.
8174e9fcaa8aSmrg	    func_append convenience " $ladir/$objdir/$old_library"
8175e9fcaa8aSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176862bcd1aSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177862bcd1aSmrg	    func_fatal_error "'$lib' is not a convenience library"
817888de56ccSmrg	  fi
817903ea5dc6Smrg	  tmp_libs=
818003ea5dc6Smrg	  for deplib in $dependency_libs; do
818103ea5dc6Smrg	    deplibs="$deplib $deplibs"
818203ea5dc6Smrg	    if $opt_preserve_dup_deps; then
818303ea5dc6Smrg	      case "$tmp_libs " in
818403ea5dc6Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
818503ea5dc6Smrg	      esac
818603ea5dc6Smrg	    fi
818703ea5dc6Smrg	    func_append tmp_libs " $deplib"
818803ea5dc6Smrg	  done
818988de56ccSmrg	  continue
819088de56ccSmrg	fi # $pass = conv
819188de56ccSmrg
819288de56ccSmrg
819388de56ccSmrg	# Get the name of the library we link against.
819488de56ccSmrg	linklib=
8195e9fcaa8aSmrg	if test -n "$old_library" &&
8196862bcd1aSmrg	   { test yes = "$prefer_static_libs" ||
8197862bcd1aSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8198e9fcaa8aSmrg	  linklib=$old_library
8199e9fcaa8aSmrg	else
8200e9fcaa8aSmrg	  for l in $old_library $library_names; do
8201862bcd1aSmrg	    linklib=$l
8202e9fcaa8aSmrg	  done
8203e9fcaa8aSmrg	fi
820488de56ccSmrg	if test -z "$linklib"; then
8205862bcd1aSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
820688de56ccSmrg	fi
820788de56ccSmrg
820888de56ccSmrg	# This library was specified with -dlopen.
8209862bcd1aSmrg	if test dlopen = "$pass"; then
8210862bcd1aSmrg	  test -z "$libdir" \
8211862bcd1aSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
821288de56ccSmrg	  if test -z "$dlname" ||
8213862bcd1aSmrg	     test yes != "$dlopen_support" ||
8214862bcd1aSmrg	     test no = "$build_libtool_libs"
8215862bcd1aSmrg	  then
821688de56ccSmrg	    # If there is no dlname, no dlopen support or we're linking
821788de56ccSmrg	    # statically, we need to preload.  We also need to preload any
821888de56ccSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
821988de56ccSmrg	    # bomb out in the load deplibs phase.
8220e9fcaa8aSmrg	    func_append dlprefiles " $lib $dependency_libs"
822188de56ccSmrg	  else
8222e9fcaa8aSmrg	    func_append newdlfiles " $lib"
822388de56ccSmrg	  fi
822488de56ccSmrg	  continue
822588de56ccSmrg	fi # $pass = dlopen
822688de56ccSmrg
822788de56ccSmrg	# We need an absolute path.
822888de56ccSmrg	case $ladir in
8229862bcd1aSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
823088de56ccSmrg	*)
823188de56ccSmrg	  abs_ladir=`cd "$ladir" && pwd`
823288de56ccSmrg	  if test -z "$abs_ladir"; then
8233862bcd1aSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
823488de56ccSmrg	    func_warning "passing it literally to the linker, although it might fail"
8235862bcd1aSmrg	    abs_ladir=$ladir
823688de56ccSmrg	  fi
823788de56ccSmrg	  ;;
823888de56ccSmrg	esac
823988de56ccSmrg	func_basename "$lib"
8240862bcd1aSmrg	laname=$func_basename_result
824188de56ccSmrg
824288de56ccSmrg	# Find the relevant object directory and library name.
8243862bcd1aSmrg	if test yes = "$installed"; then
8244e9fcaa8aSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245862bcd1aSmrg	    func_warning "library '$lib' was moved."
8246862bcd1aSmrg	    dir=$ladir
8247862bcd1aSmrg	    absdir=$abs_ladir
8248862bcd1aSmrg	    libdir=$abs_ladir
824988de56ccSmrg	  else
8250862bcd1aSmrg	    dir=$lt_sysroot$libdir
8251862bcd1aSmrg	    absdir=$lt_sysroot$libdir
825288de56ccSmrg	  fi
8253862bcd1aSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
825488de56ccSmrg	else
825588de56ccSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256862bcd1aSmrg	    dir=$ladir
8257862bcd1aSmrg	    absdir=$abs_ladir
825888de56ccSmrg	    # Remove this search path later
8259e9fcaa8aSmrg	    func_append notinst_path " $abs_ladir"
826088de56ccSmrg	  else
8261862bcd1aSmrg	    dir=$ladir/$objdir
8262862bcd1aSmrg	    absdir=$abs_ladir/$objdir
826388de56ccSmrg	    # Remove this search path later
8264e9fcaa8aSmrg	    func_append notinst_path " $abs_ladir"
826588de56ccSmrg	  fi
826688de56ccSmrg	fi # $installed = yes
826788de56ccSmrg	func_stripname 'lib' '.la' "$laname"
826888de56ccSmrg	name=$func_stripname_result
826988de56ccSmrg
827088de56ccSmrg	# This library was specified with -dlpreopen.
8271862bcd1aSmrg	if test dlpreopen = "$pass"; then
8272862bcd1aSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273862bcd1aSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
827488de56ccSmrg	  fi
8275862bcd1aSmrg	  case $host in
8276e9fcaa8aSmrg	    # special handling for platforms with PE-DLLs.
8277e9fcaa8aSmrg	    *cygwin* | *mingw* | *cegcc* )
8278e9fcaa8aSmrg	      # Linker will automatically link against shared library if both
8279e9fcaa8aSmrg	      # static and shared are present.  Therefore, ensure we extract
8280e9fcaa8aSmrg	      # symbols from the import library if a shared library is present
8281e9fcaa8aSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8282e9fcaa8aSmrg	      # this by putting the import library name into $newdlprefiles.
8283e9fcaa8aSmrg	      # We recover the dlopen module name by 'saving' the la file
8284e9fcaa8aSmrg	      # name in a special purpose variable, and (later) extracting the
8285e9fcaa8aSmrg	      # dlname from the la file.
8286e9fcaa8aSmrg	      if test -n "$dlname"; then
8287e9fcaa8aSmrg	        func_tr_sh "$dir/$linklib"
8288e9fcaa8aSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8289e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$linklib"
8290e9fcaa8aSmrg	      else
8291e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$old_library"
8292e9fcaa8aSmrg	        # Keep a list of preopened convenience libraries to check
8293e9fcaa8aSmrg	        # that they are being used correctly in the link pass.
8294e9fcaa8aSmrg	        test -z "$libdir" && \
8295e9fcaa8aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8296e9fcaa8aSmrg	      fi
8297e9fcaa8aSmrg	    ;;
8298e9fcaa8aSmrg	    * )
8299e9fcaa8aSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8300e9fcaa8aSmrg	      # are required to link).
8301e9fcaa8aSmrg	      if test -n "$old_library"; then
8302e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$old_library"
8303e9fcaa8aSmrg	        # Keep a list of preopened convenience libraries to check
8304e9fcaa8aSmrg	        # that they are being used correctly in the link pass.
8305e9fcaa8aSmrg	        test -z "$libdir" && \
8306e9fcaa8aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8307e9fcaa8aSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8308e9fcaa8aSmrg	      elif test -n "$dlname"; then
8309e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$dlname"
8310e9fcaa8aSmrg	      else
8311e9fcaa8aSmrg	        func_append newdlprefiles " $dir/$linklib"
8312e9fcaa8aSmrg	      fi
8313e9fcaa8aSmrg	    ;;
8314e9fcaa8aSmrg	  esac
831588de56ccSmrg	fi # $pass = dlpreopen
831688de56ccSmrg
831788de56ccSmrg	if test -z "$libdir"; then
831888de56ccSmrg	  # Link the convenience library
8319862bcd1aSmrg	  if test lib = "$linkmode"; then
832088de56ccSmrg	    deplibs="$dir/$old_library $deplibs"
8321862bcd1aSmrg	  elif test prog,link = "$linkmode,$pass"; then
832288de56ccSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
832388de56ccSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
832488de56ccSmrg	  else
832588de56ccSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
832688de56ccSmrg	  fi
832788de56ccSmrg	  continue
832888de56ccSmrg	fi
832988de56ccSmrg
833088de56ccSmrg
8331862bcd1aSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8332e9fcaa8aSmrg	  func_append newlib_search_path " $ladir"
833388de56ccSmrg	  deplibs="$lib $deplibs"
833488de56ccSmrg
8335862bcd1aSmrg	  linkalldeplibs=false
8336862bcd1aSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337862bcd1aSmrg	     test no = "$build_libtool_libs"; then
8338862bcd1aSmrg	    linkalldeplibs=:
833988de56ccSmrg	  fi
834088de56ccSmrg
834188de56ccSmrg	  tmp_libs=
834288de56ccSmrg	  for deplib in $dependency_libs; do
834388de56ccSmrg	    case $deplib in
834488de56ccSmrg	    -L*) func_stripname '-L' '' "$deplib"
8345e9fcaa8aSmrg	         func_resolve_sysroot "$func_stripname_result"
8346e9fcaa8aSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
834788de56ccSmrg		 ;;
834888de56ccSmrg	    esac
834988de56ccSmrg	    # Need to link against all dependency_libs?
8350862bcd1aSmrg	    if $linkalldeplibs; then
835188de56ccSmrg	      deplibs="$deplib $deplibs"
835288de56ccSmrg	    else
835388de56ccSmrg	      # Need to hardcode shared library paths
835488de56ccSmrg	      # or/and link against static libraries
835588de56ccSmrg	      newdependency_libs="$deplib $newdependency_libs"
835688de56ccSmrg	    fi
8357862bcd1aSmrg	    if $opt_preserve_dup_deps; then
835888de56ccSmrg	      case "$tmp_libs " in
8359e9fcaa8aSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
836088de56ccSmrg	      esac
836188de56ccSmrg	    fi
8362e9fcaa8aSmrg	    func_append tmp_libs " $deplib"
836388de56ccSmrg	  done # for deplib
836488de56ccSmrg	  continue
836588de56ccSmrg	fi # $linkmode = prog...
836688de56ccSmrg
8367862bcd1aSmrg	if test prog,link = "$linkmode,$pass"; then
836888de56ccSmrg	  if test -n "$library_names" &&
8369862bcd1aSmrg	     { { test no = "$prefer_static_libs" ||
8370862bcd1aSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
837188de56ccSmrg	       test -z "$old_library"; }; then
837288de56ccSmrg	    # We need to hardcode the library path
8373862bcd1aSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
837488de56ccSmrg	      # Make sure the rpath contains only unique directories.
8375862bcd1aSmrg	      case $temp_rpath: in
837688de56ccSmrg	      *"$absdir:"*) ;;
8377e9fcaa8aSmrg	      *) func_append temp_rpath "$absdir:" ;;
837888de56ccSmrg	      esac
837988de56ccSmrg	    fi
838088de56ccSmrg
838188de56ccSmrg	    # Hardcode the library path.
838288de56ccSmrg	    # Skip directories that are in the system default run-time
838388de56ccSmrg	    # search path.
838488de56ccSmrg	    case " $sys_lib_dlsearch_path " in
838588de56ccSmrg	    *" $absdir "*) ;;
838688de56ccSmrg	    *)
838788de56ccSmrg	      case "$compile_rpath " in
838888de56ccSmrg	      *" $absdir "*) ;;
8389e9fcaa8aSmrg	      *) func_append compile_rpath " $absdir" ;;
839088de56ccSmrg	      esac
839188de56ccSmrg	      ;;
839288de56ccSmrg	    esac
839388de56ccSmrg	    case " $sys_lib_dlsearch_path " in
839488de56ccSmrg	    *" $libdir "*) ;;
839588de56ccSmrg	    *)
839688de56ccSmrg	      case "$finalize_rpath " in
839788de56ccSmrg	      *" $libdir "*) ;;
8398e9fcaa8aSmrg	      *) func_append finalize_rpath " $libdir" ;;
839988de56ccSmrg	      esac
840088de56ccSmrg	      ;;
840188de56ccSmrg	    esac
840288de56ccSmrg	  fi # $linkmode,$pass = prog,link...
840388de56ccSmrg
8404862bcd1aSmrg	  if $alldeplibs &&
8405862bcd1aSmrg	     { test pass_all = "$deplibs_check_method" ||
8406862bcd1aSmrg	       { test yes = "$build_libtool_libs" &&
840788de56ccSmrg		 test -n "$library_names"; }; }; then
840888de56ccSmrg	    # We only need to search for static libraries
840988de56ccSmrg	    continue
841088de56ccSmrg	  fi
841188de56ccSmrg	fi
841288de56ccSmrg
841388de56ccSmrg	link_static=no # Whether the deplib will be linked statically
841488de56ccSmrg	use_static_libs=$prefer_static_libs
8415862bcd1aSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
841688de56ccSmrg	  use_static_libs=no
841788de56ccSmrg	fi
841888de56ccSmrg	if test -n "$library_names" &&
8419862bcd1aSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
842088de56ccSmrg	  case $host in
8421862bcd1aSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
842288de56ccSmrg	      # No point in relinking DLLs because paths are not encoded
8423e9fcaa8aSmrg	      func_append notinst_deplibs " $lib"
842488de56ccSmrg	      need_relink=no
842588de56ccSmrg	    ;;
842688de56ccSmrg	  *)
8427862bcd1aSmrg	    if test no = "$installed"; then
8428e9fcaa8aSmrg	      func_append notinst_deplibs " $lib"
842988de56ccSmrg	      need_relink=yes
843088de56ccSmrg	    fi
843188de56ccSmrg	    ;;
843288de56ccSmrg	  esac
843388de56ccSmrg	  # This is a shared library
843488de56ccSmrg
843588de56ccSmrg	  # Warn about portability, can't link against -module's on some
843688de56ccSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437862bcd1aSmrg	  dlopenmodule=
843888de56ccSmrg	  for dlpremoduletest in $dlprefiles; do
843988de56ccSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440862bcd1aSmrg	      dlopenmodule=$dlpremoduletest
844188de56ccSmrg	      break
844288de56ccSmrg	    fi
844388de56ccSmrg	  done
8444862bcd1aSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8445e9fcaa8aSmrg	    echo
8446862bcd1aSmrg	    if test prog = "$linkmode"; then
844788de56ccSmrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
844888de56ccSmrg	    else
844988de56ccSmrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
845088de56ccSmrg	    fi
845188de56ccSmrg	    $ECHO "*** $linklib is not portable!"
845288de56ccSmrg	  fi
8453862bcd1aSmrg	  if test lib = "$linkmode" &&
8454862bcd1aSmrg	     test yes = "$hardcode_into_libs"; then
845588de56ccSmrg	    # Hardcode the library path.
845688de56ccSmrg	    # Skip directories that are in the system default run-time
845788de56ccSmrg	    # search path.
845888de56ccSmrg	    case " $sys_lib_dlsearch_path " in
845988de56ccSmrg	    *" $absdir "*) ;;
846088de56ccSmrg	    *)
846188de56ccSmrg	      case "$compile_rpath " in
846288de56ccSmrg	      *" $absdir "*) ;;
8463e9fcaa8aSmrg	      *) func_append compile_rpath " $absdir" ;;
846488de56ccSmrg	      esac
846588de56ccSmrg	      ;;
846688de56ccSmrg	    esac
846788de56ccSmrg	    case " $sys_lib_dlsearch_path " in
846888de56ccSmrg	    *" $libdir "*) ;;
846988de56ccSmrg	    *)
847088de56ccSmrg	      case "$finalize_rpath " in
847188de56ccSmrg	      *" $libdir "*) ;;
8472e9fcaa8aSmrg	      *) func_append finalize_rpath " $libdir" ;;
847388de56ccSmrg	      esac
847488de56ccSmrg	      ;;
847588de56ccSmrg	    esac
847688de56ccSmrg	  fi
847788de56ccSmrg
847888de56ccSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
847988de56ccSmrg	    # figure out the soname
848088de56ccSmrg	    set dummy $library_names
848188de56ccSmrg	    shift
8482862bcd1aSmrg	    realname=$1
848388de56ccSmrg	    shift
848488de56ccSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
848588de56ccSmrg	    # use dlname if we got it. it's perfectly good, no?
848688de56ccSmrg	    if test -n "$dlname"; then
8487862bcd1aSmrg	      soname=$dlname
848888de56ccSmrg	    elif test -n "$soname_spec"; then
848988de56ccSmrg	      # bleh windows
849088de56ccSmrg	      case $host in
8491862bcd1aSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
849288de56ccSmrg	        func_arith $current - $age
849388de56ccSmrg		major=$func_arith_result
8494862bcd1aSmrg		versuffix=-$major
849588de56ccSmrg		;;
849688de56ccSmrg	      esac
849788de56ccSmrg	      eval soname=\"$soname_spec\"
849888de56ccSmrg	    else
8499862bcd1aSmrg	      soname=$realname
850088de56ccSmrg	    fi
850188de56ccSmrg
850288de56ccSmrg	    # Make a new name for the extract_expsyms_cmds to use
8503862bcd1aSmrg	    soroot=$soname
850488de56ccSmrg	    func_basename "$soroot"
8505862bcd1aSmrg	    soname=$func_basename_result
850688de56ccSmrg	    func_stripname 'lib' '.dll' "$soname"
850788de56ccSmrg	    newlib=libimp-$func_stripname_result.a
850888de56ccSmrg
850988de56ccSmrg	    # If the library has no export list, then create one now
851088de56ccSmrg	    if test -f "$output_objdir/$soname-def"; then :
851188de56ccSmrg	    else
8512862bcd1aSmrg	      func_verbose "extracting exported symbol list from '$soname'"
851388de56ccSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
851488de56ccSmrg	    fi
851588de56ccSmrg
851688de56ccSmrg	    # Create $newlib
851788de56ccSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8518862bcd1aSmrg	      func_verbose "generating import library for '$soname'"
851988de56ccSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
852088de56ccSmrg	    fi
852188de56ccSmrg	    # make sure the library variables are pointing to the new library
852288de56ccSmrg	    dir=$output_objdir
852388de56ccSmrg	    linklib=$newlib
852488de56ccSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
852588de56ccSmrg
8526862bcd1aSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
852788de56ccSmrg	    add_shlibpath=
852888de56ccSmrg	    add_dir=
852988de56ccSmrg	    add=
853088de56ccSmrg	    lib_linked=yes
853188de56ccSmrg	    case $hardcode_action in
853288de56ccSmrg	    immediate | unsupported)
8533862bcd1aSmrg	      if test no = "$hardcode_direct"; then
8534862bcd1aSmrg		add=$dir/$linklib
853588de56ccSmrg		case $host in
8536862bcd1aSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537862bcd1aSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
853888de56ccSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539862bcd1aSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
854088de56ccSmrg		  *-*-darwin* )
8541862bcd1aSmrg		    # if the lib is a (non-dlopened) module then we cannot
854288de56ccSmrg		    # link against it, someone is ignoring the earlier warnings
854388de56ccSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8544862bcd1aSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
854588de56ccSmrg		      if test "X$dlopenmodule" != "X$lib"; then
854688de56ccSmrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547862bcd1aSmrg			if test -z "$old_library"; then
8548e9fcaa8aSmrg			  echo
8549e9fcaa8aSmrg			  echo "*** And there doesn't seem to be a static archive available"
8550e9fcaa8aSmrg			  echo "*** The link will probably fail, sorry"
855188de56ccSmrg			else
8552862bcd1aSmrg			  add=$dir/$old_library
855388de56ccSmrg			fi
855488de56ccSmrg		      elif test -n "$old_library"; then
8555862bcd1aSmrg			add=$dir/$old_library
855688de56ccSmrg		      fi
855788de56ccSmrg		    fi
855888de56ccSmrg		esac
8559862bcd1aSmrg	      elif test no = "$hardcode_minus_L"; then
856088de56ccSmrg		case $host in
8561862bcd1aSmrg		*-*-sunos*) add_shlibpath=$dir ;;
856288de56ccSmrg		esac
8563862bcd1aSmrg		add_dir=-L$dir
8564862bcd1aSmrg		add=-l$name
8565862bcd1aSmrg	      elif test no = "$hardcode_shlibpath_var"; then
8566862bcd1aSmrg		add_shlibpath=$dir
8567862bcd1aSmrg		add=-l$name
856888de56ccSmrg	      else
856988de56ccSmrg		lib_linked=no
857088de56ccSmrg	      fi
857188de56ccSmrg	      ;;
857288de56ccSmrg	    relink)
8573862bcd1aSmrg	      if test yes = "$hardcode_direct" &&
8574862bcd1aSmrg	         test no = "$hardcode_direct_absolute"; then
8575862bcd1aSmrg		add=$dir/$linklib
8576862bcd1aSmrg	      elif test yes = "$hardcode_minus_L"; then
8577862bcd1aSmrg		add_dir=-L$absdir
857888de56ccSmrg		# Try looking first in the location we're being installed to.
857988de56ccSmrg		if test -n "$inst_prefix_dir"; then
858088de56ccSmrg		  case $libdir in
858188de56ccSmrg		    [\\/]*)
8582e9fcaa8aSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
858388de56ccSmrg		      ;;
858488de56ccSmrg		  esac
858588de56ccSmrg		fi
8586862bcd1aSmrg		add=-l$name
8587862bcd1aSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588862bcd1aSmrg		add_shlibpath=$dir
8589862bcd1aSmrg		add=-l$name
859088de56ccSmrg	      else
859188de56ccSmrg		lib_linked=no
859288de56ccSmrg	      fi
859388de56ccSmrg	      ;;
859488de56ccSmrg	    *) lib_linked=no ;;
859588de56ccSmrg	    esac
859688de56ccSmrg
8597862bcd1aSmrg	    if test yes != "$lib_linked"; then
859888de56ccSmrg	      func_fatal_configuration "unsupported hardcode properties"
859988de56ccSmrg	    fi
860088de56ccSmrg
860188de56ccSmrg	    if test -n "$add_shlibpath"; then
860288de56ccSmrg	      case :$compile_shlibpath: in
860388de56ccSmrg	      *":$add_shlibpath:"*) ;;
8604e9fcaa8aSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
860588de56ccSmrg	      esac
860688de56ccSmrg	    fi
8607862bcd1aSmrg	    if test prog = "$linkmode"; then
860888de56ccSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
860988de56ccSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
861088de56ccSmrg	    else
861188de56ccSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
861288de56ccSmrg	      test -n "$add" && deplibs="$add $deplibs"
8613862bcd1aSmrg	      if test yes != "$hardcode_direct" &&
8614862bcd1aSmrg		 test yes != "$hardcode_minus_L" &&
8615862bcd1aSmrg		 test yes = "$hardcode_shlibpath_var"; then
861688de56ccSmrg		case :$finalize_shlibpath: in
861788de56ccSmrg		*":$libdir:"*) ;;
8618e9fcaa8aSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
861988de56ccSmrg		esac
862088de56ccSmrg	      fi
862188de56ccSmrg	    fi
862288de56ccSmrg	  fi
862388de56ccSmrg
8624862bcd1aSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
862588de56ccSmrg	    add_shlibpath=
862688de56ccSmrg	    add_dir=
862788de56ccSmrg	    add=
862888de56ccSmrg	    # Finalize command for both is simple: just hardcode it.
8629862bcd1aSmrg	    if test yes = "$hardcode_direct" &&
8630862bcd1aSmrg	       test no = "$hardcode_direct_absolute"; then
8631862bcd1aSmrg	      add=$libdir/$linklib
8632862bcd1aSmrg	    elif test yes = "$hardcode_minus_L"; then
8633862bcd1aSmrg	      add_dir=-L$libdir
8634862bcd1aSmrg	      add=-l$name
8635862bcd1aSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
863688de56ccSmrg	      case :$finalize_shlibpath: in
863788de56ccSmrg	      *":$libdir:"*) ;;
8638e9fcaa8aSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
863988de56ccSmrg	      esac
8640862bcd1aSmrg	      add=-l$name
8641862bcd1aSmrg	    elif test yes = "$hardcode_automatic"; then
864288de56ccSmrg	      if test -n "$inst_prefix_dir" &&
8643862bcd1aSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644862bcd1aSmrg		add=$inst_prefix_dir$libdir/$linklib
864588de56ccSmrg	      else
8646862bcd1aSmrg		add=$libdir/$linklib
864788de56ccSmrg	      fi
864888de56ccSmrg	    else
864988de56ccSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650862bcd1aSmrg	      add_dir=-L$libdir
865188de56ccSmrg	      # Try looking first in the location we're being installed to.
865288de56ccSmrg	      if test -n "$inst_prefix_dir"; then
865388de56ccSmrg		case $libdir in
865488de56ccSmrg		  [\\/]*)
8655e9fcaa8aSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
865688de56ccSmrg		    ;;
865788de56ccSmrg		esac
865888de56ccSmrg	      fi
8659862bcd1aSmrg	      add=-l$name
866088de56ccSmrg	    fi
866188de56ccSmrg
8662862bcd1aSmrg	    if test prog = "$linkmode"; then
866388de56ccSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
866488de56ccSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
866588de56ccSmrg	    else
866688de56ccSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
866788de56ccSmrg	      test -n "$add" && deplibs="$add $deplibs"
866888de56ccSmrg	    fi
866988de56ccSmrg	  fi
8670862bcd1aSmrg	elif test prog = "$linkmode"; then
867188de56ccSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
867288de56ccSmrg	  # is not unsupported.  This is valid on all known static and
867388de56ccSmrg	  # shared platforms.
8674862bcd1aSmrg	  if test unsupported != "$hardcode_direct"; then
8675862bcd1aSmrg	    test -n "$old_library" && linklib=$old_library
867688de56ccSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
867788de56ccSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
867888de56ccSmrg	  else
867988de56ccSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
868088de56ccSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
868188de56ccSmrg	  fi
8682862bcd1aSmrg	elif test yes = "$build_libtool_libs"; then
868388de56ccSmrg	  # Not a shared library
8684862bcd1aSmrg	  if test pass_all != "$deplibs_check_method"; then
868588de56ccSmrg	    # We're trying link a shared library against a static one
868688de56ccSmrg	    # but the system doesn't support it.
868788de56ccSmrg
868888de56ccSmrg	    # Just print a warning and add the library to dependency_libs so
868988de56ccSmrg	    # that the program can be linked against the static library.
8690e9fcaa8aSmrg	    echo
8691862bcd1aSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8692e9fcaa8aSmrg	    echo "*** I have the capability to make that library automatically link in when"
8693e9fcaa8aSmrg	    echo "*** you link to this library.  But I can only do this if you have a"
8694e9fcaa8aSmrg	    echo "*** shared version of the library, which you do not appear to have."
8695862bcd1aSmrg	    if test yes = "$module"; then
8696e9fcaa8aSmrg	      echo "*** But as you try to build a module library, libtool will still create "
8697e9fcaa8aSmrg	      echo "*** a static module, that should work as long as the dlopening application"
8698e9fcaa8aSmrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
869988de56ccSmrg	      if test -z "$global_symbol_pipe"; then
8700e9fcaa8aSmrg		echo
8701e9fcaa8aSmrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702862bcd1aSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8703e9fcaa8aSmrg		echo "*** not find such a program.  So, this module is probably useless."
8704862bcd1aSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
870588de56ccSmrg	      fi
8706862bcd1aSmrg	      if test no = "$build_old_libs"; then
870788de56ccSmrg		build_libtool_libs=module
870888de56ccSmrg		build_old_libs=yes
870988de56ccSmrg	      else
871088de56ccSmrg		build_libtool_libs=no
871188de56ccSmrg	      fi
871288de56ccSmrg	    fi
871388de56ccSmrg	  else
871488de56ccSmrg	    deplibs="$dir/$old_library $deplibs"
871588de56ccSmrg	    link_static=yes
871688de56ccSmrg	  fi
871788de56ccSmrg	fi # link shared/static library?
871888de56ccSmrg
8719862bcd1aSmrg	if test lib = "$linkmode"; then
872088de56ccSmrg	  if test -n "$dependency_libs" &&
8721862bcd1aSmrg	     { test yes != "$hardcode_into_libs" ||
8722862bcd1aSmrg	       test yes = "$build_old_libs" ||
8723862bcd1aSmrg	       test yes = "$link_static"; }; then
872488de56ccSmrg	    # Extract -R from dependency_libs
872588de56ccSmrg	    temp_deplibs=
872688de56ccSmrg	    for libdir in $dependency_libs; do
872788de56ccSmrg	      case $libdir in
872888de56ccSmrg	      -R*) func_stripname '-R' '' "$libdir"
872988de56ccSmrg	           temp_xrpath=$func_stripname_result
873088de56ccSmrg		   case " $xrpath " in
873188de56ccSmrg		   *" $temp_xrpath "*) ;;
8732e9fcaa8aSmrg		   *) func_append xrpath " $temp_xrpath";;
873388de56ccSmrg		   esac;;
8734e9fcaa8aSmrg	      *) func_append temp_deplibs " $libdir";;
873588de56ccSmrg	      esac
873688de56ccSmrg	    done
8737862bcd1aSmrg	    dependency_libs=$temp_deplibs
873888de56ccSmrg	  fi
873988de56ccSmrg
8740e9fcaa8aSmrg	  func_append newlib_search_path " $absdir"
874188de56ccSmrg	  # Link against this library
8742862bcd1aSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
874388de56ccSmrg	  # ... and its dependency_libs
874488de56ccSmrg	  tmp_libs=
874588de56ccSmrg	  for deplib in $dependency_libs; do
874688de56ccSmrg	    newdependency_libs="$deplib $newdependency_libs"
8747e9fcaa8aSmrg	    case $deplib in
8748e9fcaa8aSmrg              -L*) func_stripname '-L' '' "$deplib"
8749e9fcaa8aSmrg                   func_resolve_sysroot "$func_stripname_result";;
8750e9fcaa8aSmrg              *) func_resolve_sysroot "$deplib" ;;
8751e9fcaa8aSmrg            esac
8752862bcd1aSmrg	    if $opt_preserve_dup_deps; then
875388de56ccSmrg	      case "$tmp_libs " in
8754e9fcaa8aSmrg	      *" $func_resolve_sysroot_result "*)
8755e9fcaa8aSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
875688de56ccSmrg	      esac
875788de56ccSmrg	    fi
8758e9fcaa8aSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
875988de56ccSmrg	  done
876088de56ccSmrg
8761862bcd1aSmrg	  if test no != "$link_all_deplibs"; then
876288de56ccSmrg	    # Add the search paths of all dependency libraries
876388de56ccSmrg	    for deplib in $dependency_libs; do
876447f86ac1Smrg	      path=
876588de56ccSmrg	      case $deplib in
8766862bcd1aSmrg	      -L*) path=$deplib ;;
876788de56ccSmrg	      *.la)
8768e9fcaa8aSmrg	        func_resolve_sysroot "$deplib"
8769e9fcaa8aSmrg	        deplib=$func_resolve_sysroot_result
877088de56ccSmrg	        func_dirname "$deplib" "" "."
8771e9fcaa8aSmrg		dir=$func_dirname_result
877288de56ccSmrg		# We need an absolute path.
877388de56ccSmrg		case $dir in
8774862bcd1aSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
877588de56ccSmrg		*)
877688de56ccSmrg		  absdir=`cd "$dir" && pwd`
877788de56ccSmrg		  if test -z "$absdir"; then
8778862bcd1aSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779862bcd1aSmrg		    absdir=$dir
878088de56ccSmrg		  fi
878188de56ccSmrg		  ;;
878288de56ccSmrg		esac
878388de56ccSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
878488de56ccSmrg		case $host in
878588de56ccSmrg		*-*-darwin*)
878688de56ccSmrg		  depdepl=
8787862bcd1aSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788862bcd1aSmrg		  if test -n "$deplibrary_names"; then
8789862bcd1aSmrg		    for tmp in $deplibrary_names; do
879088de56ccSmrg		      depdepl=$tmp
879188de56ccSmrg		    done
8792862bcd1aSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793862bcd1aSmrg		      depdepl=$absdir/$objdir/$depdepl
8794862bcd1aSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
879588de56ccSmrg                      if test -z "$darwin_install_name"; then
8796862bcd1aSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
879788de56ccSmrg                      fi
8798862bcd1aSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799862bcd1aSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
880088de56ccSmrg		      path=
880188de56ccSmrg		    fi
880288de56ccSmrg		  fi
880388de56ccSmrg		  ;;
880488de56ccSmrg		*)
8805862bcd1aSmrg		  path=-L$absdir/$objdir
880688de56ccSmrg		  ;;
880788de56ccSmrg		esac
880888de56ccSmrg		else
8809862bcd1aSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
881088de56ccSmrg		  test -z "$libdir" && \
8811862bcd1aSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
881288de56ccSmrg		  test "$absdir" != "$libdir" && \
8813862bcd1aSmrg		    func_warning "'$deplib' seems to be moved"
881488de56ccSmrg
8815862bcd1aSmrg		  path=-L$absdir
881688de56ccSmrg		fi
881788de56ccSmrg		;;
881888de56ccSmrg	      esac
881988de56ccSmrg	      case " $deplibs " in
882088de56ccSmrg	      *" $path "*) ;;
882188de56ccSmrg	      *) deplibs="$path $deplibs" ;;
882288de56ccSmrg	      esac
882388de56ccSmrg	    done
882488de56ccSmrg	  fi # link_all_deplibs != no
882588de56ccSmrg	fi # linkmode = lib
882688de56ccSmrg      done # for deplib in $libs
8827862bcd1aSmrg      if test link = "$pass"; then
8828862bcd1aSmrg	if test prog = "$linkmode"; then
882988de56ccSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
883088de56ccSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
883188de56ccSmrg	else
8832e9fcaa8aSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
883388de56ccSmrg	fi
883488de56ccSmrg      fi
8835862bcd1aSmrg      dependency_libs=$newdependency_libs
8836862bcd1aSmrg      if test dlpreopen = "$pass"; then
883788de56ccSmrg	# Link the dlpreopened libraries before other libraries
883888de56ccSmrg	for deplib in $save_deplibs; do
883988de56ccSmrg	  deplibs="$deplib $deplibs"
884088de56ccSmrg	done
884188de56ccSmrg      fi
8842862bcd1aSmrg      if test dlopen != "$pass"; then
8843862bcd1aSmrg	test conv = "$pass" || {
884488de56ccSmrg	  # Make sure lib_search_path contains only unique directories.
884588de56ccSmrg	  lib_search_path=
884688de56ccSmrg	  for dir in $newlib_search_path; do
884788de56ccSmrg	    case "$lib_search_path " in
884888de56ccSmrg	    *" $dir "*) ;;
8849e9fcaa8aSmrg	    *) func_append lib_search_path " $dir" ;;
885088de56ccSmrg	    esac
885188de56ccSmrg	  done
885288de56ccSmrg	  newlib_search_path=
8853862bcd1aSmrg	}
885488de56ccSmrg
8855862bcd1aSmrg	if test prog,link = "$linkmode,$pass"; then
885688de56ccSmrg	  vars="compile_deplibs finalize_deplibs"
8857862bcd1aSmrg	else
8858862bcd1aSmrg	  vars=deplibs
885988de56ccSmrg	fi
886088de56ccSmrg	for var in $vars dependency_libs; do
886188de56ccSmrg	  # Add libraries to $var in reverse order
886288de56ccSmrg	  eval tmp_libs=\"\$$var\"
886388de56ccSmrg	  new_libs=
886488de56ccSmrg	  for deplib in $tmp_libs; do
886588de56ccSmrg	    # FIXME: Pedantically, this is the right thing to do, so
886688de56ccSmrg	    #        that some nasty dependency loop isn't accidentally
886788de56ccSmrg	    #        broken:
886888de56ccSmrg	    #new_libs="$deplib $new_libs"
886988de56ccSmrg	    # Pragmatically, this seems to cause very few problems in
887088de56ccSmrg	    # practice:
887188de56ccSmrg	    case $deplib in
887288de56ccSmrg	    -L*) new_libs="$deplib $new_libs" ;;
887388de56ccSmrg	    -R*) ;;
887488de56ccSmrg	    *)
887588de56ccSmrg	      # And here is the reason: when a library appears more
887688de56ccSmrg	      # than once as an explicit dependence of a library, or
887788de56ccSmrg	      # is implicitly linked in more than once by the
887888de56ccSmrg	      # compiler, it is considered special, and multiple
887988de56ccSmrg	      # occurrences thereof are not removed.  Compare this
888088de56ccSmrg	      # with having the same library being listed as a
888188de56ccSmrg	      # dependency of multiple other libraries: in this case,
888288de56ccSmrg	      # we know (pedantically, we assume) the library does not
888388de56ccSmrg	      # need to be listed more than once, so we keep only the
888488de56ccSmrg	      # last copy.  This is not always right, but it is rare
888588de56ccSmrg	      # enough that we require users that really mean to play
888688de56ccSmrg	      # such unportable linking tricks to link the library
888788de56ccSmrg	      # using -Wl,-lname, so that libtool does not consider it
888888de56ccSmrg	      # for duplicate removal.
888988de56ccSmrg	      case " $specialdeplibs " in
889088de56ccSmrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
889188de56ccSmrg	      *)
889288de56ccSmrg		case " $new_libs " in
889388de56ccSmrg		*" $deplib "*) ;;
889488de56ccSmrg		*) new_libs="$deplib $new_libs" ;;
889588de56ccSmrg		esac
889688de56ccSmrg		;;
889788de56ccSmrg	      esac
889888de56ccSmrg	      ;;
889988de56ccSmrg	    esac
890088de56ccSmrg	  done
890188de56ccSmrg	  tmp_libs=
890288de56ccSmrg	  for deplib in $new_libs; do
890388de56ccSmrg	    case $deplib in
890488de56ccSmrg	    -L*)
890588de56ccSmrg	      case " $tmp_libs " in
890688de56ccSmrg	      *" $deplib "*) ;;
8907e9fcaa8aSmrg	      *) func_append tmp_libs " $deplib" ;;
890888de56ccSmrg	      esac
890988de56ccSmrg	      ;;
8910e9fcaa8aSmrg	    *) func_append tmp_libs " $deplib" ;;
891188de56ccSmrg	    esac
891288de56ccSmrg	  done
891388de56ccSmrg	  eval $var=\"$tmp_libs\"
891488de56ccSmrg	done # for var
891588de56ccSmrg      fi
8916862bcd1aSmrg
8917862bcd1aSmrg      # Add Sun CC postdeps if required:
8918862bcd1aSmrg      test CXX = "$tagname" && {
8919862bcd1aSmrg        case $host_os in
8920862bcd1aSmrg        linux*)
8921e9628295Smrg          case `$CC -V 2>&1 | $SED 5q` in
8922862bcd1aSmrg          *Sun\ C*) # Sun C++ 5.9
8923862bcd1aSmrg            func_suncc_cstd_abi
8924862bcd1aSmrg
8925862bcd1aSmrg            if test no != "$suncc_use_cstd_abi"; then
8926862bcd1aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8927862bcd1aSmrg            fi
8928862bcd1aSmrg            ;;
8929862bcd1aSmrg          esac
8930862bcd1aSmrg          ;;
8931862bcd1aSmrg
8932862bcd1aSmrg        solaris*)
8933862bcd1aSmrg          func_cc_basename "$CC"
8934862bcd1aSmrg          case $func_cc_basename_result in
8935862bcd1aSmrg          CC* | sunCC*)
8936862bcd1aSmrg            func_suncc_cstd_abi
8937862bcd1aSmrg
8938862bcd1aSmrg            if test no != "$suncc_use_cstd_abi"; then
8939862bcd1aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8940862bcd1aSmrg            fi
8941862bcd1aSmrg            ;;
8942862bcd1aSmrg          esac
8943862bcd1aSmrg          ;;
8944862bcd1aSmrg        esac
8945862bcd1aSmrg      }
8946862bcd1aSmrg
894788de56ccSmrg      # Last step: remove runtime libs from dependency_libs
894888de56ccSmrg      # (they stay in deplibs)
894988de56ccSmrg      tmp_libs=
8950862bcd1aSmrg      for i in $dependency_libs; do
895188de56ccSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
895288de56ccSmrg	*" $i "*)
8953862bcd1aSmrg	  i=
895488de56ccSmrg	  ;;
895588de56ccSmrg	esac
8956862bcd1aSmrg	if test -n "$i"; then
8957e9fcaa8aSmrg	  func_append tmp_libs " $i"
895888de56ccSmrg	fi
895988de56ccSmrg      done
896088de56ccSmrg      dependency_libs=$tmp_libs
896188de56ccSmrg    done # for pass
8962862bcd1aSmrg    if test prog = "$linkmode"; then
8963862bcd1aSmrg      dlfiles=$newdlfiles
896488de56ccSmrg    fi
8965862bcd1aSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966862bcd1aSmrg      dlprefiles=$newdlprefiles
896788de56ccSmrg    fi
896888de56ccSmrg
896988de56ccSmrg    case $linkmode in
897088de56ccSmrg    oldlib)
8971862bcd1aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972862bcd1aSmrg	func_warning "'-dlopen' is ignored for archives"
897388de56ccSmrg      fi
897488de56ccSmrg
897588de56ccSmrg      case " $deplibs" in
897688de56ccSmrg      *\ -l* | *\ -L*)
8977862bcd1aSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
897888de56ccSmrg      esac
897988de56ccSmrg
898088de56ccSmrg      test -n "$rpath" && \
8981862bcd1aSmrg	func_warning "'-rpath' is ignored for archives"
898288de56ccSmrg
898388de56ccSmrg      test -n "$xrpath" && \
8984862bcd1aSmrg	func_warning "'-R' is ignored for archives"
898588de56ccSmrg
898688de56ccSmrg      test -n "$vinfo" && \
8987862bcd1aSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
898888de56ccSmrg
898988de56ccSmrg      test -n "$release" && \
8990862bcd1aSmrg	func_warning "'-release' is ignored for archives"
899188de56ccSmrg
899288de56ccSmrg      test -n "$export_symbols$export_symbols_regex" && \
8993862bcd1aSmrg	func_warning "'-export-symbols' is ignored for archives"
899488de56ccSmrg
899588de56ccSmrg      # Now set the variables for building old libraries.
899688de56ccSmrg      build_libtool_libs=no
8997862bcd1aSmrg      oldlibs=$output
8998e9fcaa8aSmrg      func_append objs "$old_deplibs"
899988de56ccSmrg      ;;
900088de56ccSmrg
900188de56ccSmrg    lib)
9002862bcd1aSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
900388de56ccSmrg      case $outputname in
900488de56ccSmrg      lib*)
900588de56ccSmrg	func_stripname 'lib' '.la' "$outputname"
900688de56ccSmrg	name=$func_stripname_result
900788de56ccSmrg	eval shared_ext=\"$shrext_cmds\"
900888de56ccSmrg	eval libname=\"$libname_spec\"
900988de56ccSmrg	;;
901088de56ccSmrg      *)
9011862bcd1aSmrg	test no = "$module" \
9012862bcd1aSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
901388de56ccSmrg
9014862bcd1aSmrg	if test no != "$need_lib_prefix"; then
901588de56ccSmrg	  # Add the "lib" prefix for modules if required
901688de56ccSmrg	  func_stripname '' '.la' "$outputname"
901788de56ccSmrg	  name=$func_stripname_result
901888de56ccSmrg	  eval shared_ext=\"$shrext_cmds\"
901988de56ccSmrg	  eval libname=\"$libname_spec\"
902088de56ccSmrg	else
902188de56ccSmrg	  func_stripname '' '.la' "$outputname"
902288de56ccSmrg	  libname=$func_stripname_result
902388de56ccSmrg	fi
902488de56ccSmrg	;;
902588de56ccSmrg      esac
902688de56ccSmrg
902788de56ccSmrg      if test -n "$objs"; then
9028862bcd1aSmrg	if test pass_all != "$deplibs_check_method"; then
9029862bcd1aSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
903088de56ccSmrg	else
9031e9fcaa8aSmrg	  echo
903288de56ccSmrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
903388de56ccSmrg	  $ECHO "*** objects $objs is not portable!"
9034e9fcaa8aSmrg	  func_append libobjs " $objs"
903588de56ccSmrg	fi
903688de56ccSmrg      fi
903788de56ccSmrg
9038862bcd1aSmrg      test no = "$dlself" \
9039862bcd1aSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
904088de56ccSmrg
904188de56ccSmrg      set dummy $rpath
904288de56ccSmrg      shift
9043862bcd1aSmrg      test 1 -lt "$#" \
9044862bcd1aSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
904588de56ccSmrg
9046862bcd1aSmrg      install_libdir=$1
904788de56ccSmrg
904888de56ccSmrg      oldlibs=
904988de56ccSmrg      if test -z "$rpath"; then
9050862bcd1aSmrg	if test yes = "$build_libtool_libs"; then
905188de56ccSmrg	  # Building a libtool convenience library.
9052862bcd1aSmrg	  # Some compilers have problems with a '.al' extension so
905388de56ccSmrg	  # convenience libraries should have the same extension an
905488de56ccSmrg	  # archive normally would.
905588de56ccSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
905688de56ccSmrg	  build_libtool_libs=convenience
905788de56ccSmrg	  build_old_libs=yes
905888de56ccSmrg	fi
905988de56ccSmrg
906088de56ccSmrg	test -n "$vinfo" && \
9061862bcd1aSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
906288de56ccSmrg
906388de56ccSmrg	test -n "$release" && \
9064862bcd1aSmrg	  func_warning "'-release' is ignored for convenience libraries"
906588de56ccSmrg      else
906688de56ccSmrg
906788de56ccSmrg	# Parse the version information argument.
9068862bcd1aSmrg	save_ifs=$IFS; IFS=:
906988de56ccSmrg	set dummy $vinfo 0 0 0
907088de56ccSmrg	shift
9071862bcd1aSmrg	IFS=$save_ifs
907288de56ccSmrg
907388de56ccSmrg	test -n "$7" && \
9074862bcd1aSmrg	  func_fatal_help "too many parameters to '-version-info'"
907588de56ccSmrg
907688de56ccSmrg	# convert absolute version numbers to libtool ages
907788de56ccSmrg	# this retains compatibility with .la files and attempts
907888de56ccSmrg	# to make the code below a bit more comprehensible
907988de56ccSmrg
908088de56ccSmrg	case $vinfo_number in
908188de56ccSmrg	yes)
9082862bcd1aSmrg	  number_major=$1
9083862bcd1aSmrg	  number_minor=$2
9084862bcd1aSmrg	  number_revision=$3
908588de56ccSmrg	  #
908688de56ccSmrg	  # There are really only two kinds -- those that
908788de56ccSmrg	  # use the current revision as the major version
908888de56ccSmrg	  # and those that subtract age and use age as
908988de56ccSmrg	  # a minor version.  But, then there is irix
9090862bcd1aSmrg	  # that has an extra 1 added just for fun
909188de56ccSmrg	  #
909288de56ccSmrg	  case $version_type in
9093eb411b4bSmrg	  # correct linux to gnu/linux during the next big refactor
9094e9628295Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
909588de56ccSmrg	    func_arith $number_major + $number_minor
909688de56ccSmrg	    current=$func_arith_result
9097862bcd1aSmrg	    age=$number_minor
9098862bcd1aSmrg	    revision=$number_revision
909988de56ccSmrg	    ;;
9100862bcd1aSmrg	  freebsd-aout|qnx|sunos)
9101862bcd1aSmrg	    current=$number_major
9102862bcd1aSmrg	    revision=$number_minor
9103862bcd1aSmrg	    age=0
910488de56ccSmrg	    ;;
910588de56ccSmrg	  irix|nonstopux)
910688de56ccSmrg	    func_arith $number_major + $number_minor
910788de56ccSmrg	    current=$func_arith_result
9108862bcd1aSmrg	    age=$number_minor
9109862bcd1aSmrg	    revision=$number_minor
911088de56ccSmrg	    lt_irix_increment=no
911188de56ccSmrg	    ;;
911288de56ccSmrg	  esac
911388de56ccSmrg	  ;;
911488de56ccSmrg	no)
9115862bcd1aSmrg	  current=$1
9116862bcd1aSmrg	  revision=$2
9117862bcd1aSmrg	  age=$3
911888de56ccSmrg	  ;;
911988de56ccSmrg	esac
912088de56ccSmrg
912188de56ccSmrg	# Check that each of the things are valid numbers.
912288de56ccSmrg	case $current in
912388de56ccSmrg	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]) ;;
912488de56ccSmrg	*)
9125862bcd1aSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
912788de56ccSmrg	  ;;
912888de56ccSmrg	esac
912988de56ccSmrg
913088de56ccSmrg	case $revision in
913188de56ccSmrg	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]) ;;
913288de56ccSmrg	*)
9133862bcd1aSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
913588de56ccSmrg	  ;;
913688de56ccSmrg	esac
913788de56ccSmrg
913888de56ccSmrg	case $age in
913988de56ccSmrg	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]) ;;
914088de56ccSmrg	*)
9141862bcd1aSmrg	  func_error "AGE '$age' must be a nonnegative integer"
9142862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
914388de56ccSmrg	  ;;
914488de56ccSmrg	esac
914588de56ccSmrg
914688de56ccSmrg	if test "$age" -gt "$current"; then
9147862bcd1aSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148862bcd1aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
914988de56ccSmrg	fi
915088de56ccSmrg
915188de56ccSmrg	# Calculate the version variables.
915288de56ccSmrg	major=
915388de56ccSmrg	versuffix=
915488de56ccSmrg	verstring=
915588de56ccSmrg	case $version_type in
915688de56ccSmrg	none) ;;
915788de56ccSmrg
915888de56ccSmrg	darwin)
915988de56ccSmrg	  # Like Linux, but with the current version available in
916088de56ccSmrg	  # verstring for coding it into the library header
916188de56ccSmrg	  func_arith $current - $age
916288de56ccSmrg	  major=.$func_arith_result
9163862bcd1aSmrg	  versuffix=$major.$age.$revision
916488de56ccSmrg	  # Darwin ld doesn't like 0 for these options...
916588de56ccSmrg	  func_arith $current + 1
916688de56ccSmrg	  minor_current=$func_arith_result
9167862bcd1aSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
916888de56ccSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169862bcd1aSmrg          # On Darwin other compilers
9170862bcd1aSmrg          case $CC in
9171862bcd1aSmrg              nagfor*)
9172862bcd1aSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173862bcd1aSmrg                  ;;
9174862bcd1aSmrg              *)
9175862bcd1aSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176862bcd1aSmrg                  ;;
9177862bcd1aSmrg          esac
917888de56ccSmrg	  ;;
917988de56ccSmrg
918088de56ccSmrg	freebsd-aout)
9181862bcd1aSmrg	  major=.$current
9182862bcd1aSmrg	  versuffix=.$current.$revision
918388de56ccSmrg	  ;;
918488de56ccSmrg
9185e9628295Smrg	freebsd-elf | midnightbsd-elf)
9186862bcd1aSmrg	  func_arith $current - $age
9187862bcd1aSmrg	  major=.$func_arith_result
9188862bcd1aSmrg	  versuffix=$major.$age.$revision
918988de56ccSmrg	  ;;
919088de56ccSmrg
919188de56ccSmrg	irix | nonstopux)
9192862bcd1aSmrg	  if test no = "$lt_irix_increment"; then
919388de56ccSmrg	    func_arith $current - $age
919488de56ccSmrg	  else
919588de56ccSmrg	    func_arith $current - $age + 1
919688de56ccSmrg	  fi
919788de56ccSmrg	  major=$func_arith_result
919888de56ccSmrg
919988de56ccSmrg	  case $version_type in
920088de56ccSmrg	    nonstopux) verstring_prefix=nonstopux ;;
920188de56ccSmrg	    *)         verstring_prefix=sgi ;;
920288de56ccSmrg	  esac
9203862bcd1aSmrg	  verstring=$verstring_prefix$major.$revision
920488de56ccSmrg
920588de56ccSmrg	  # Add in all the interfaces that we are compatible with.
920688de56ccSmrg	  loop=$revision
9207862bcd1aSmrg	  while test 0 -ne "$loop"; do
920888de56ccSmrg	    func_arith $revision - $loop
920988de56ccSmrg	    iface=$func_arith_result
921088de56ccSmrg	    func_arith $loop - 1
921188de56ccSmrg	    loop=$func_arith_result
9212862bcd1aSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
921388de56ccSmrg	  done
921488de56ccSmrg
9215862bcd1aSmrg	  # Before this point, $major must not contain '.'.
921688de56ccSmrg	  major=.$major
9217862bcd1aSmrg	  versuffix=$major.$revision
921888de56ccSmrg	  ;;
921988de56ccSmrg
9220eb411b4bSmrg	linux) # correct to gnu/linux during the next big refactor
922188de56ccSmrg	  func_arith $current - $age
922288de56ccSmrg	  major=.$func_arith_result
9223862bcd1aSmrg	  versuffix=$major.$age.$revision
922488de56ccSmrg	  ;;
922588de56ccSmrg
922688de56ccSmrg	osf)
922788de56ccSmrg	  func_arith $current - $age
922888de56ccSmrg	  major=.$func_arith_result
9229862bcd1aSmrg	  versuffix=.$current.$age.$revision
9230862bcd1aSmrg	  verstring=$current.$age.$revision
923188de56ccSmrg
923288de56ccSmrg	  # Add in all the interfaces that we are compatible with.
923388de56ccSmrg	  loop=$age
9234862bcd1aSmrg	  while test 0 -ne "$loop"; do
923588de56ccSmrg	    func_arith $current - $loop
923688de56ccSmrg	    iface=$func_arith_result
923788de56ccSmrg	    func_arith $loop - 1
923888de56ccSmrg	    loop=$func_arith_result
9239862bcd1aSmrg	    verstring=$verstring:$iface.0
924088de56ccSmrg	  done
924188de56ccSmrg
924288de56ccSmrg	  # Make executables depend on our current version.
9243862bcd1aSmrg	  func_append verstring ":$current.0"
924488de56ccSmrg	  ;;
924588de56ccSmrg
924688de56ccSmrg	qnx)
9247862bcd1aSmrg	  major=.$current
9248862bcd1aSmrg	  versuffix=.$current
9249862bcd1aSmrg	  ;;
9250862bcd1aSmrg
9251862bcd1aSmrg	sco)
9252862bcd1aSmrg	  major=.$current
9253862bcd1aSmrg	  versuffix=.$current
925488de56ccSmrg	  ;;
925588de56ccSmrg
925688de56ccSmrg	sunos)
9257862bcd1aSmrg	  major=.$current
9258862bcd1aSmrg	  versuffix=.$current.$revision
925988de56ccSmrg	  ;;
926088de56ccSmrg
926188de56ccSmrg	windows)
926288de56ccSmrg	  # Use '-' rather than '.', since we only want one
9263862bcd1aSmrg	  # extension on DOS 8.3 file systems.
926488de56ccSmrg	  func_arith $current - $age
926588de56ccSmrg	  major=$func_arith_result
9266862bcd1aSmrg	  versuffix=-$major
926788de56ccSmrg	  ;;
926888de56ccSmrg
926988de56ccSmrg	*)
9270862bcd1aSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
927188de56ccSmrg	  ;;
927288de56ccSmrg	esac
927388de56ccSmrg
927488de56ccSmrg	# Clear the version info if we defaulted, and they specified a release.
927588de56ccSmrg	if test -z "$vinfo" && test -n "$release"; then
927688de56ccSmrg	  major=
927788de56ccSmrg	  case $version_type in
927888de56ccSmrg	  darwin)
927988de56ccSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
928088de56ccSmrg	    # problems, so we reset it completely
928188de56ccSmrg	    verstring=
928288de56ccSmrg	    ;;
928388de56ccSmrg	  *)
9284862bcd1aSmrg	    verstring=0.0
928588de56ccSmrg	    ;;
928688de56ccSmrg	  esac
9287862bcd1aSmrg	  if test no = "$need_version"; then
928888de56ccSmrg	    versuffix=
928988de56ccSmrg	  else
9290862bcd1aSmrg	    versuffix=.0.0
929188de56ccSmrg	  fi
929288de56ccSmrg	fi
929388de56ccSmrg
929488de56ccSmrg	# Remove version info from name if versioning should be avoided
9295862bcd1aSmrg	if test yes,no = "$avoid_version,$need_version"; then
929688de56ccSmrg	  major=
929788de56ccSmrg	  versuffix=
9298862bcd1aSmrg	  verstring=
929988de56ccSmrg	fi
930088de56ccSmrg
930188de56ccSmrg	# Check to see if the archive will have undefined symbols.
9302862bcd1aSmrg	if test yes = "$allow_undefined"; then
9303862bcd1aSmrg	  if test unsupported = "$allow_undefined_flag"; then
9304862bcd1aSmrg	    if test yes = "$build_old_libs"; then
9305862bcd1aSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306862bcd1aSmrg	      build_libtool_libs=no
9307862bcd1aSmrg	    else
9308862bcd1aSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309862bcd1aSmrg	    fi
931088de56ccSmrg	  fi
931188de56ccSmrg	else
931288de56ccSmrg	  # Don't allow undefined symbols.
9313862bcd1aSmrg	  allow_undefined_flag=$no_undefined_flag
931488de56ccSmrg	fi
931588de56ccSmrg
931688de56ccSmrg      fi
931788de56ccSmrg
9318862bcd1aSmrg      func_generate_dlsyms "$libname" "$libname" :
9319e9fcaa8aSmrg      func_append libobjs " $symfileobj"
9320862bcd1aSmrg      test " " = "$libobjs" && libobjs=
932188de56ccSmrg
9322862bcd1aSmrg      if test relink != "$opt_mode"; then
932388de56ccSmrg	# Remove our outputs, but don't remove object files since they
932488de56ccSmrg	# may have been created when compiling PIC objects.
932588de56ccSmrg	removelist=
932688de56ccSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
932788de56ccSmrg	for p in $tempremovelist; do
932888de56ccSmrg	  case $p in
932988de56ccSmrg	    *.$objext | *.gcno)
933088de56ccSmrg	       ;;
9331862bcd1aSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332862bcd1aSmrg	       if test -n "$precious_files_regex"; then
933388de56ccSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
933488de56ccSmrg		 then
933588de56ccSmrg		   continue
933688de56ccSmrg		 fi
933788de56ccSmrg	       fi
9338e9fcaa8aSmrg	       func_append removelist " $p"
933988de56ccSmrg	       ;;
934088de56ccSmrg	    *) ;;
934188de56ccSmrg	  esac
934288de56ccSmrg	done
934388de56ccSmrg	test -n "$removelist" && \
934488de56ccSmrg	  func_show_eval "${RM}r \$removelist"
934588de56ccSmrg      fi
934688de56ccSmrg
934788de56ccSmrg      # Now set the variables for building old libraries.
9348862bcd1aSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9349e9fcaa8aSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
935088de56ccSmrg
935188de56ccSmrg	# Transform .lo files to .o files.
9352862bcd1aSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
935388de56ccSmrg      fi
935488de56ccSmrg
935588de56ccSmrg      # Eliminate all temporary directories.
935688de56ccSmrg      #for path in $notinst_path; do
9357e9fcaa8aSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9358e9fcaa8aSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9359e9fcaa8aSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
936088de56ccSmrg      #done
936188de56ccSmrg
936288de56ccSmrg      if test -n "$xrpath"; then
936388de56ccSmrg	# If the user specified any rpath flags, then add them.
936488de56ccSmrg	temp_xrpath=
936588de56ccSmrg	for libdir in $xrpath; do
9366e9fcaa8aSmrg	  func_replace_sysroot "$libdir"
9367e9fcaa8aSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
936888de56ccSmrg	  case "$finalize_rpath " in
936988de56ccSmrg	  *" $libdir "*) ;;
9370e9fcaa8aSmrg	  *) func_append finalize_rpath " $libdir" ;;
937188de56ccSmrg	  esac
937288de56ccSmrg	done
9373862bcd1aSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
937488de56ccSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
937588de56ccSmrg	fi
937688de56ccSmrg      fi
937788de56ccSmrg
937888de56ccSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379862bcd1aSmrg      old_dlfiles=$dlfiles
938088de56ccSmrg      dlfiles=
938188de56ccSmrg      for lib in $old_dlfiles; do
938288de56ccSmrg	case " $dlprefiles $dlfiles " in
938388de56ccSmrg	*" $lib "*) ;;
9384e9fcaa8aSmrg	*) func_append dlfiles " $lib" ;;
938588de56ccSmrg	esac
938688de56ccSmrg      done
938788de56ccSmrg
938888de56ccSmrg      # Make sure dlprefiles contains only unique files
9389862bcd1aSmrg      old_dlprefiles=$dlprefiles
939088de56ccSmrg      dlprefiles=
939188de56ccSmrg      for lib in $old_dlprefiles; do
939288de56ccSmrg	case "$dlprefiles " in
939388de56ccSmrg	*" $lib "*) ;;
9394e9fcaa8aSmrg	*) func_append dlprefiles " $lib" ;;
939588de56ccSmrg	esac
939688de56ccSmrg      done
939788de56ccSmrg
9398862bcd1aSmrg      if test yes = "$build_libtool_libs"; then
939988de56ccSmrg	if test -n "$rpath"; then
940088de56ccSmrg	  case $host in
9401e9fcaa8aSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
940288de56ccSmrg	    # these systems don't actually have a c library (as such)!
940388de56ccSmrg	    ;;
940488de56ccSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
940588de56ccSmrg	    # Rhapsody C library is in the System framework
9406e9fcaa8aSmrg	    func_append deplibs " System.ltframework"
940788de56ccSmrg	    ;;
940888de56ccSmrg	  *-*-netbsd*)
940988de56ccSmrg	    # Don't link with libc until the a.out ld.so is fixed.
941088de56ccSmrg	    ;;
9411e9628295Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
941288de56ccSmrg	    # Do not include libc due to us having libc/libc_r.
941388de56ccSmrg	    ;;
941488de56ccSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
941588de56ccSmrg	    # Causes problems with __ctype
941688de56ccSmrg	    ;;
941788de56ccSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
941888de56ccSmrg	    # Compiler inserts libc in the correct place for threads to work
941988de56ccSmrg	    ;;
942088de56ccSmrg	  *)
942188de56ccSmrg	    # Add libc to deplibs on all other systems if necessary.
9422862bcd1aSmrg	    if test yes = "$build_libtool_need_lc"; then
9423e9fcaa8aSmrg	      func_append deplibs " -lc"
942488de56ccSmrg	    fi
942588de56ccSmrg	    ;;
942688de56ccSmrg	  esac
942788de56ccSmrg	fi
942888de56ccSmrg
942988de56ccSmrg	# Transform deplibs into only deplibs that can be linked in shared.
943088de56ccSmrg	name_save=$name
943188de56ccSmrg	libname_save=$libname
943288de56ccSmrg	release_save=$release
943388de56ccSmrg	versuffix_save=$versuffix
943488de56ccSmrg	major_save=$major
943588de56ccSmrg	# I'm not sure if I'm treating the release correctly.  I think
943688de56ccSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
943788de56ccSmrg	# add it in twice.  Is that correct?
9438862bcd1aSmrg	release=
9439862bcd1aSmrg	versuffix=
9440862bcd1aSmrg	major=
944188de56ccSmrg	newdeplibs=
944288de56ccSmrg	droppeddeps=no
944388de56ccSmrg	case $deplibs_check_method in
944488de56ccSmrg	pass_all)
944588de56ccSmrg	  # Don't check for shared/static.  Everything works.
944688de56ccSmrg	  # This might be a little naive.  We might want to check
944788de56ccSmrg	  # whether the library exists or not.  But this is on
944888de56ccSmrg	  # osf3 & osf4 and I'm not really sure... Just
944988de56ccSmrg	  # implementing what was already the behavior.
945088de56ccSmrg	  newdeplibs=$deplibs
945188de56ccSmrg	  ;;
945288de56ccSmrg	test_compile)
945388de56ccSmrg	  # This code stresses the "libraries are programs" paradigm to its
945488de56ccSmrg	  # limits. Maybe even breaks it.  We compile a program, linking it
945588de56ccSmrg	  # against the deplibs as a proxy for the library.  Then we can check
945688de56ccSmrg	  # whether they linked in statically or dynamically with ldd.
945788de56ccSmrg	  $opt_dry_run || $RM conftest.c
945888de56ccSmrg	  cat > conftest.c <<EOF
945988de56ccSmrg	  int main() { return 0; }
946088de56ccSmrgEOF
946188de56ccSmrg	  $opt_dry_run || $RM conftest
946288de56ccSmrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
946388de56ccSmrg	    ldd_output=`ldd conftest`
946488de56ccSmrg	    for i in $deplibs; do
946588de56ccSmrg	      case $i in
946688de56ccSmrg	      -l*)
946788de56ccSmrg		func_stripname -l '' "$i"
946888de56ccSmrg		name=$func_stripname_result
9469862bcd1aSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
947088de56ccSmrg		  case " $predeps $postdeps " in
947188de56ccSmrg		  *" $i "*)
9472e9fcaa8aSmrg		    func_append newdeplibs " $i"
9473862bcd1aSmrg		    i=
947488de56ccSmrg		    ;;
947588de56ccSmrg		  esac
947688de56ccSmrg		fi
9477862bcd1aSmrg		if test -n "$i"; then
947888de56ccSmrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
947988de56ccSmrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
948088de56ccSmrg		  set dummy $deplib_matches; shift
948188de56ccSmrg		  deplib_match=$1
9482862bcd1aSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9483e9fcaa8aSmrg		    func_append newdeplibs " $i"
948488de56ccSmrg		  else
948588de56ccSmrg		    droppeddeps=yes
9486e9fcaa8aSmrg		    echo
948788de56ccSmrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9488e9fcaa8aSmrg		    echo "*** I have the capability to make that library automatically link in when"
9489e9fcaa8aSmrg		    echo "*** you link to this library.  But I can only do this if you have a"
9490e9fcaa8aSmrg		    echo "*** shared version of the library, which I believe you do not have"
9491e9fcaa8aSmrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9492e9fcaa8aSmrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
949388de56ccSmrg		  fi
949488de56ccSmrg		fi
949588de56ccSmrg		;;
949688de56ccSmrg	      *)
9497e9fcaa8aSmrg		func_append newdeplibs " $i"
949888de56ccSmrg		;;
949988de56ccSmrg	      esac
950088de56ccSmrg	    done
950188de56ccSmrg	  else
950288de56ccSmrg	    # Error occurred in the first compile.  Let's try to salvage
950388de56ccSmrg	    # the situation: Compile a separate program for each library.
950488de56ccSmrg	    for i in $deplibs; do
950588de56ccSmrg	      case $i in
950688de56ccSmrg	      -l*)
950788de56ccSmrg		func_stripname -l '' "$i"
950888de56ccSmrg		name=$func_stripname_result
950988de56ccSmrg		$opt_dry_run || $RM conftest
951088de56ccSmrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
951188de56ccSmrg		  ldd_output=`ldd conftest`
9512862bcd1aSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
951388de56ccSmrg		    case " $predeps $postdeps " in
951488de56ccSmrg		    *" $i "*)
9515e9fcaa8aSmrg		      func_append newdeplibs " $i"
9516862bcd1aSmrg		      i=
951788de56ccSmrg		      ;;
951888de56ccSmrg		    esac
951988de56ccSmrg		  fi
9520862bcd1aSmrg		  if test -n "$i"; then
952188de56ccSmrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
952288de56ccSmrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
952388de56ccSmrg		    set dummy $deplib_matches; shift
952488de56ccSmrg		    deplib_match=$1
9525862bcd1aSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9526e9fcaa8aSmrg		      func_append newdeplibs " $i"
952788de56ccSmrg		    else
952888de56ccSmrg		      droppeddeps=yes
9529e9fcaa8aSmrg		      echo
953088de56ccSmrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9531e9fcaa8aSmrg		      echo "*** I have the capability to make that library automatically link in when"
9532e9fcaa8aSmrg		      echo "*** you link to this library.  But I can only do this if you have a"
9533e9fcaa8aSmrg		      echo "*** shared version of the library, which you do not appear to have"
9534e9fcaa8aSmrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9535e9fcaa8aSmrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
953688de56ccSmrg		    fi
953788de56ccSmrg		  fi
953888de56ccSmrg		else
953988de56ccSmrg		  droppeddeps=yes
9540e9fcaa8aSmrg		  echo
954188de56ccSmrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9542e9fcaa8aSmrg		  echo "*** make it link in!  You will probably need to install it or some"
9543e9fcaa8aSmrg		  echo "*** library that it depends on before this library will be fully"
9544e9fcaa8aSmrg		  echo "*** functional.  Installing it before continuing would be even better."
954588de56ccSmrg		fi
954688de56ccSmrg		;;
954788de56ccSmrg	      *)
9548e9fcaa8aSmrg		func_append newdeplibs " $i"
954988de56ccSmrg		;;
955088de56ccSmrg	      esac
955188de56ccSmrg	    done
955288de56ccSmrg	  fi
955388de56ccSmrg	  ;;
955488de56ccSmrg	file_magic*)
955588de56ccSmrg	  set dummy $deplibs_check_method; shift
955688de56ccSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
955788de56ccSmrg	  for a_deplib in $deplibs; do
955888de56ccSmrg	    case $a_deplib in
955988de56ccSmrg	    -l*)
956088de56ccSmrg	      func_stripname -l '' "$a_deplib"
956188de56ccSmrg	      name=$func_stripname_result
9562862bcd1aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
956388de56ccSmrg		case " $predeps $postdeps " in
956488de56ccSmrg		*" $a_deplib "*)
9565e9fcaa8aSmrg		  func_append newdeplibs " $a_deplib"
9566862bcd1aSmrg		  a_deplib=
956788de56ccSmrg		  ;;
956888de56ccSmrg		esac
956988de56ccSmrg	      fi
9570862bcd1aSmrg	      if test -n "$a_deplib"; then
957188de56ccSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9572e9fcaa8aSmrg		if test -n "$file_magic_glob"; then
9573e9fcaa8aSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9574e9fcaa8aSmrg		else
9575e9fcaa8aSmrg		  libnameglob=$libname
9576e9fcaa8aSmrg		fi
9577862bcd1aSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
957888de56ccSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579862bcd1aSmrg		  if test yes = "$want_nocaseglob"; then
9580e9fcaa8aSmrg		    shopt -s nocaseglob
9581e9fcaa8aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9582e9fcaa8aSmrg		    $nocaseglob
9583e9fcaa8aSmrg		  else
9584e9fcaa8aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9585e9fcaa8aSmrg		  fi
958688de56ccSmrg		  for potent_lib in $potential_libs; do
958788de56ccSmrg		      # Follow soft links.
958888de56ccSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
958988de56ccSmrg			 $GREP " -> " >/dev/null; then
959088de56ccSmrg			continue
959188de56ccSmrg		      fi
959288de56ccSmrg		      # The statement above tries to avoid entering an
959388de56ccSmrg		      # endless loop below, in case of cyclic links.
959488de56ccSmrg		      # We might still enter an endless loop, since a link
959588de56ccSmrg		      # loop can be closed while we follow links,
959688de56ccSmrg		      # but so what?
9597862bcd1aSmrg		      potlib=$potent_lib
959888de56ccSmrg		      while test -h "$potlib" 2>/dev/null; do
9599862bcd1aSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
960088de56ccSmrg			case $potliblink in
9601862bcd1aSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602862bcd1aSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
960388de56ccSmrg			esac
960488de56ccSmrg		      done
960588de56ccSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
960688de56ccSmrg			 $SED -e 10q |
960788de56ccSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
9608e9fcaa8aSmrg			func_append newdeplibs " $a_deplib"
9609862bcd1aSmrg			a_deplib=
961088de56ccSmrg			break 2
961188de56ccSmrg		      fi
961288de56ccSmrg		  done
961388de56ccSmrg		done
961488de56ccSmrg	      fi
9615862bcd1aSmrg	      if test -n "$a_deplib"; then
961688de56ccSmrg		droppeddeps=yes
9617e9fcaa8aSmrg		echo
961888de56ccSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9619e9fcaa8aSmrg		echo "*** I have the capability to make that library automatically link in when"
9620e9fcaa8aSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9621e9fcaa8aSmrg		echo "*** shared version of the library, which you do not appear to have"
9622e9fcaa8aSmrg		echo "*** because I did check the linker path looking for a file starting"
9623862bcd1aSmrg		if test -z "$potlib"; then
962488de56ccSmrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
962588de56ccSmrg		else
962688de56ccSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
962788de56ccSmrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
962888de56ccSmrg		fi
962988de56ccSmrg	      fi
963088de56ccSmrg	      ;;
963188de56ccSmrg	    *)
963288de56ccSmrg	      # Add a -L argument.
9633e9fcaa8aSmrg	      func_append newdeplibs " $a_deplib"
963488de56ccSmrg	      ;;
963588de56ccSmrg	    esac
963688de56ccSmrg	  done # Gone through all deplibs.
963788de56ccSmrg	  ;;
963888de56ccSmrg	match_pattern*)
963988de56ccSmrg	  set dummy $deplibs_check_method; shift
964088de56ccSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
964188de56ccSmrg	  for a_deplib in $deplibs; do
964288de56ccSmrg	    case $a_deplib in
964388de56ccSmrg	    -l*)
964488de56ccSmrg	      func_stripname -l '' "$a_deplib"
964588de56ccSmrg	      name=$func_stripname_result
9646862bcd1aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
964788de56ccSmrg		case " $predeps $postdeps " in
964888de56ccSmrg		*" $a_deplib "*)
9649e9fcaa8aSmrg		  func_append newdeplibs " $a_deplib"
9650862bcd1aSmrg		  a_deplib=
965188de56ccSmrg		  ;;
965288de56ccSmrg		esac
965388de56ccSmrg	      fi
9654862bcd1aSmrg	      if test -n "$a_deplib"; then
965588de56ccSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
965688de56ccSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
965788de56ccSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
965888de56ccSmrg		  for potent_lib in $potential_libs; do
9659862bcd1aSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9660e9fcaa8aSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
966188de56ccSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9662e9fcaa8aSmrg		      func_append newdeplibs " $a_deplib"
9663862bcd1aSmrg		      a_deplib=
966488de56ccSmrg		      break 2
966588de56ccSmrg		    fi
966688de56ccSmrg		  done
966788de56ccSmrg		done
966888de56ccSmrg	      fi
9669862bcd1aSmrg	      if test -n "$a_deplib"; then
967088de56ccSmrg		droppeddeps=yes
9671e9fcaa8aSmrg		echo
967288de56ccSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9673e9fcaa8aSmrg		echo "*** I have the capability to make that library automatically link in when"
9674e9fcaa8aSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9675e9fcaa8aSmrg		echo "*** shared version of the library, which you do not appear to have"
9676e9fcaa8aSmrg		echo "*** because I did check the linker path looking for a file starting"
9677862bcd1aSmrg		if test -z "$potlib"; then
967888de56ccSmrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
967988de56ccSmrg		else
968088de56ccSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
968188de56ccSmrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
968288de56ccSmrg		fi
968388de56ccSmrg	      fi
968488de56ccSmrg	      ;;
968588de56ccSmrg	    *)
968688de56ccSmrg	      # Add a -L argument.
9687e9fcaa8aSmrg	      func_append newdeplibs " $a_deplib"
968888de56ccSmrg	      ;;
968988de56ccSmrg	    esac
969088de56ccSmrg	  done # Gone through all deplibs.
969188de56ccSmrg	  ;;
969288de56ccSmrg	none | unknown | *)
9693862bcd1aSmrg	  newdeplibs=
9694e9fcaa8aSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695862bcd1aSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696862bcd1aSmrg	    for i in $predeps $postdeps; do
969788de56ccSmrg	      # can't use Xsed below, because $i might contain '/'
9698862bcd1aSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
969988de56ccSmrg	    done
970088de56ccSmrg	  fi
9701e9fcaa8aSmrg	  case $tmp_deplibs in
9702e9fcaa8aSmrg	  *[!\	\ ]*)
9703e9fcaa8aSmrg	    echo
9704862bcd1aSmrg	    if test none = "$deplibs_check_method"; then
9705e9fcaa8aSmrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
970688de56ccSmrg	    else
9707e9fcaa8aSmrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
970888de56ccSmrg	    fi
9709e9fcaa8aSmrg	    echo "*** All declared inter-library dependencies are being dropped."
971088de56ccSmrg	    droppeddeps=yes
9711e9fcaa8aSmrg	    ;;
9712e9fcaa8aSmrg	  esac
971388de56ccSmrg	  ;;
971488de56ccSmrg	esac
971588de56ccSmrg	versuffix=$versuffix_save
971688de56ccSmrg	major=$major_save
971788de56ccSmrg	release=$release_save
971888de56ccSmrg	libname=$libname_save
971988de56ccSmrg	name=$name_save
972088de56ccSmrg
972188de56ccSmrg	case $host in
972288de56ccSmrg	*-*-rhapsody* | *-*-darwin1.[012])
972388de56ccSmrg	  # On Rhapsody replace the C library with the System framework
9724e9fcaa8aSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
972588de56ccSmrg	  ;;
972688de56ccSmrg	esac
972788de56ccSmrg
9728862bcd1aSmrg	if test yes = "$droppeddeps"; then
9729862bcd1aSmrg	  if test yes = "$module"; then
9730e9fcaa8aSmrg	    echo
9731e9fcaa8aSmrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
973288de56ccSmrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9733e9fcaa8aSmrg	    echo "*** a static module, that should work as long as the dlopening"
9734e9fcaa8aSmrg	    echo "*** application is linked with the -dlopen flag."
973588de56ccSmrg	    if test -z "$global_symbol_pipe"; then
9736e9fcaa8aSmrg	      echo
9737e9fcaa8aSmrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738862bcd1aSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9739e9fcaa8aSmrg	      echo "*** not find such a program.  So, this module is probably useless."
9740862bcd1aSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
974188de56ccSmrg	    fi
9742862bcd1aSmrg	    if test no = "$build_old_libs"; then
9743862bcd1aSmrg	      oldlibs=$output_objdir/$libname.$libext
974488de56ccSmrg	      build_libtool_libs=module
974588de56ccSmrg	      build_old_libs=yes
974688de56ccSmrg	    else
974788de56ccSmrg	      build_libtool_libs=no
974888de56ccSmrg	    fi
974988de56ccSmrg	  else
9750e9fcaa8aSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9751e9fcaa8aSmrg	    echo "*** automatically added whenever a program is linked with this library"
9752e9fcaa8aSmrg	    echo "*** or is declared to -dlopen it."
975388de56ccSmrg
9754862bcd1aSmrg	    if test no = "$allow_undefined"; then
9755e9fcaa8aSmrg	      echo
9756e9fcaa8aSmrg	      echo "*** Since this library must not contain undefined symbols,"
9757e9fcaa8aSmrg	      echo "*** because either the platform does not support them or"
9758e9fcaa8aSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9759e9fcaa8aSmrg	      echo "*** libtool will only create a static version of it."
9760862bcd1aSmrg	      if test no = "$build_old_libs"; then
9761862bcd1aSmrg		oldlibs=$output_objdir/$libname.$libext
976288de56ccSmrg		build_libtool_libs=module
976388de56ccSmrg		build_old_libs=yes
976488de56ccSmrg	      else
976588de56ccSmrg		build_libtool_libs=no
976688de56ccSmrg	      fi
976788de56ccSmrg	    fi
976888de56ccSmrg	  fi
976988de56ccSmrg	fi
977088de56ccSmrg	# Done checking deplibs!
977188de56ccSmrg	deplibs=$newdeplibs
977288de56ccSmrg      fi
977388de56ccSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
977488de56ccSmrg      case $host in
977588de56ccSmrg	*-*-darwin*)
9776e9fcaa8aSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9777e9fcaa8aSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9778e9fcaa8aSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977988de56ccSmrg	  ;;
978088de56ccSmrg      esac
978188de56ccSmrg
978288de56ccSmrg      # move library search paths that coincide with paths to not yet
978388de56ccSmrg      # installed libraries to the beginning of the library search list
978488de56ccSmrg      new_libs=
978588de56ccSmrg      for path in $notinst_path; do
978688de56ccSmrg	case " $new_libs " in
978788de56ccSmrg	*" -L$path/$objdir "*) ;;
978888de56ccSmrg	*)
978988de56ccSmrg	  case " $deplibs " in
979088de56ccSmrg	  *" -L$path/$objdir "*)
9791e9fcaa8aSmrg	    func_append new_libs " -L$path/$objdir" ;;
979288de56ccSmrg	  esac
979388de56ccSmrg	  ;;
979488de56ccSmrg	esac
979588de56ccSmrg      done
979688de56ccSmrg      for deplib in $deplibs; do
979788de56ccSmrg	case $deplib in
979888de56ccSmrg	-L*)
979988de56ccSmrg	  case " $new_libs " in
980088de56ccSmrg	  *" $deplib "*) ;;
9801e9fcaa8aSmrg	  *) func_append new_libs " $deplib" ;;
980288de56ccSmrg	  esac
980388de56ccSmrg	  ;;
9804e9fcaa8aSmrg	*) func_append new_libs " $deplib" ;;
980588de56ccSmrg	esac
980688de56ccSmrg      done
9807862bcd1aSmrg      deplibs=$new_libs
980888de56ccSmrg
980988de56ccSmrg      # All the library-specific variables (install_libdir is set above).
981088de56ccSmrg      library_names=
981188de56ccSmrg      old_library=
981288de56ccSmrg      dlname=
981388de56ccSmrg
981488de56ccSmrg      # Test again, we may have decided not to build it any more
9815862bcd1aSmrg      if test yes = "$build_libtool_libs"; then
9816862bcd1aSmrg	# Remove $wl instances when linking with ld.
9817eb411b4bSmrg	# FIXME: should test the right _cmds variable.
9818eb411b4bSmrg	case $archive_cmds in
9819eb411b4bSmrg	  *\$LD\ *) wl= ;;
9820eb411b4bSmrg        esac
9821862bcd1aSmrg	if test yes = "$hardcode_into_libs"; then
982288de56ccSmrg	  # Hardcode the library paths
982388de56ccSmrg	  hardcode_libdirs=
982488de56ccSmrg	  dep_rpath=
9825862bcd1aSmrg	  rpath=$finalize_rpath
9826862bcd1aSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
982788de56ccSmrg	  for libdir in $rpath; do
982888de56ccSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
982988de56ccSmrg	      if test -n "$hardcode_libdir_separator"; then
9830e9fcaa8aSmrg		func_replace_sysroot "$libdir"
9831e9fcaa8aSmrg		libdir=$func_replace_sysroot_result
983288de56ccSmrg		if test -z "$hardcode_libdirs"; then
9833862bcd1aSmrg		  hardcode_libdirs=$libdir
983488de56ccSmrg		else
983588de56ccSmrg		  # Just accumulate the unique libdirs.
983688de56ccSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
983788de56ccSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
983888de56ccSmrg		    ;;
983988de56ccSmrg		  *)
9840e9fcaa8aSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
984188de56ccSmrg		    ;;
984288de56ccSmrg		  esac
984388de56ccSmrg		fi
984488de56ccSmrg	      else
984588de56ccSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
9846e9fcaa8aSmrg		func_append dep_rpath " $flag"
984788de56ccSmrg	      fi
984888de56ccSmrg	    elif test -n "$runpath_var"; then
984988de56ccSmrg	      case "$perm_rpath " in
985088de56ccSmrg	      *" $libdir "*) ;;
9851eb411b4bSmrg	      *) func_append perm_rpath " $libdir" ;;
985288de56ccSmrg	      esac
985388de56ccSmrg	    fi
985488de56ccSmrg	  done
985588de56ccSmrg	  # Substitute the hardcoded libdirs into the rpath.
985688de56ccSmrg	  if test -n "$hardcode_libdir_separator" &&
985788de56ccSmrg	     test -n "$hardcode_libdirs"; then
9858862bcd1aSmrg	    libdir=$hardcode_libdirs
9859eb411b4bSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
986088de56ccSmrg	  fi
986188de56ccSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
986288de56ccSmrg	    # We should set the runpath_var.
986388de56ccSmrg	    rpath=
986488de56ccSmrg	    for dir in $perm_rpath; do
9865e9fcaa8aSmrg	      func_append rpath "$dir:"
986688de56ccSmrg	    done
986788de56ccSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
986888de56ccSmrg	  fi
986988de56ccSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
987088de56ccSmrg	fi
98711ab64890Smrg
9872862bcd1aSmrg	shlibpath=$finalize_shlibpath
9873862bcd1aSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
987488de56ccSmrg	if test -n "$shlibpath"; then
987588de56ccSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
987688de56ccSmrg	fi
98771ab64890Smrg
987888de56ccSmrg	# Get the real and link names of the library.
987988de56ccSmrg	eval shared_ext=\"$shrext_cmds\"
988088de56ccSmrg	eval library_names=\"$library_names_spec\"
988188de56ccSmrg	set dummy $library_names
988288de56ccSmrg	shift
9883862bcd1aSmrg	realname=$1
988488de56ccSmrg	shift
98851ab64890Smrg
988688de56ccSmrg	if test -n "$soname_spec"; then
988788de56ccSmrg	  eval soname=\"$soname_spec\"
988888de56ccSmrg	else
9889862bcd1aSmrg	  soname=$realname
989088de56ccSmrg	fi
989188de56ccSmrg	if test -z "$dlname"; then
989288de56ccSmrg	  dlname=$soname
989388de56ccSmrg	fi
98941ab64890Smrg
9895862bcd1aSmrg	lib=$output_objdir/$realname
989688de56ccSmrg	linknames=
989788de56ccSmrg	for link
989888de56ccSmrg	do
9899e9fcaa8aSmrg	  func_append linknames " $link"
990088de56ccSmrg	done
99011ab64890Smrg
990288de56ccSmrg	# Use standard objects if they are pic
9903e9fcaa8aSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
990488de56ccSmrg	test "X$libobjs" = "X " && libobjs=
99051ab64890Smrg
990688de56ccSmrg	delfiles=
990788de56ccSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
990888de56ccSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909862bcd1aSmrg	  export_symbols=$output_objdir/$libname.uexp
9910e9fcaa8aSmrg	  func_append delfiles " $export_symbols"
991188de56ccSmrg	fi
99121ab64890Smrg
991388de56ccSmrg	orig_export_symbols=
991488de56ccSmrg	case $host_os in
991588de56ccSmrg	cygwin* | mingw* | cegcc*)
991688de56ccSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
991788de56ccSmrg	    # exporting using user supplied symfile
9918862bcd1aSmrg	    func_dll_def_p "$export_symbols" || {
991988de56ccSmrg	      # and it's NOT already a .def file. Must figure out
992088de56ccSmrg	      # which of the given symbols are data symbols and tag
992188de56ccSmrg	      # them as such. So, trigger use of export_symbols_cmds.
992288de56ccSmrg	      # export_symbols gets reassigned inside the "prepare
992388de56ccSmrg	      # the list of exported symbols" if statement, so the
992488de56ccSmrg	      # include_expsyms logic still works.
9925862bcd1aSmrg	      orig_export_symbols=$export_symbols
992688de56ccSmrg	      export_symbols=
992788de56ccSmrg	      always_export_symbols=yes
9928862bcd1aSmrg	    }
992988de56ccSmrg	  fi
993088de56ccSmrg	  ;;
993188de56ccSmrg	esac
99321ab64890Smrg
993388de56ccSmrg	# Prepare the list of exported symbols
993488de56ccSmrg	if test -z "$export_symbols"; then
9935862bcd1aSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936862bcd1aSmrg	    func_verbose "generating symbol list for '$libname.la'"
9937862bcd1aSmrg	    export_symbols=$output_objdir/$libname.exp
993888de56ccSmrg	    $opt_dry_run || $RM $export_symbols
993988de56ccSmrg	    cmds=$export_symbols_cmds
9940862bcd1aSmrg	    save_ifs=$IFS; IFS='~'
9941e9fcaa8aSmrg	    for cmd1 in $cmds; do
9942862bcd1aSmrg	      IFS=$save_ifs
9943e9fcaa8aSmrg	      # Take the normal branch if the nm_file_list_spec branch
9944e9fcaa8aSmrg	      # doesn't work or if tool conversion is not needed.
9945e9fcaa8aSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9946e9fcaa8aSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9947e9fcaa8aSmrg		  try_normal_branch=yes
9948e9fcaa8aSmrg		  eval cmd=\"$cmd1\"
9949e9fcaa8aSmrg		  func_len " $cmd"
9950e9fcaa8aSmrg		  len=$func_len_result
9951e9fcaa8aSmrg		  ;;
9952e9fcaa8aSmrg		*)
9953e9fcaa8aSmrg		  try_normal_branch=no
9954e9fcaa8aSmrg		  ;;
9955e9fcaa8aSmrg	      esac
9956862bcd1aSmrg	      if test yes = "$try_normal_branch" \
9957e9fcaa8aSmrg		 && { test "$len" -lt "$max_cmd_len" \
9958e9fcaa8aSmrg		      || test "$max_cmd_len" -le -1; }
9959e9fcaa8aSmrg	      then
9960e9fcaa8aSmrg		func_show_eval "$cmd" 'exit $?'
9961e9fcaa8aSmrg		skipped_export=false
9962e9fcaa8aSmrg	      elif test -n "$nm_file_list_spec"; then
9963e9fcaa8aSmrg		func_basename "$output"
9964e9fcaa8aSmrg		output_la=$func_basename_result
9965e9fcaa8aSmrg		save_libobjs=$libobjs
9966e9fcaa8aSmrg		save_output=$output
9967862bcd1aSmrg		output=$output_objdir/$output_la.nm
9968e9fcaa8aSmrg		func_to_tool_file "$output"
9969e9fcaa8aSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9970e9fcaa8aSmrg		func_append delfiles " $output"
9971e9fcaa8aSmrg		func_verbose "creating $NM input file list: $output"
9972e9fcaa8aSmrg		for obj in $save_libobjs; do
9973e9fcaa8aSmrg		  func_to_tool_file "$obj"
9974e9fcaa8aSmrg		  $ECHO "$func_to_tool_file_result"
9975e9fcaa8aSmrg		done > "$output"
9976e9fcaa8aSmrg		eval cmd=\"$cmd1\"
997788de56ccSmrg		func_show_eval "$cmd" 'exit $?'
9978e9fcaa8aSmrg		output=$save_output
9979e9fcaa8aSmrg		libobjs=$save_libobjs
998088de56ccSmrg		skipped_export=false
998188de56ccSmrg	      else
998288de56ccSmrg		# The command line is too long to execute in one step.
998388de56ccSmrg		func_verbose "using reloadable object file for export list..."
998488de56ccSmrg		skipped_export=:
998588de56ccSmrg		# Break out early, otherwise skipped_export may be
998688de56ccSmrg		# set to false by a later but shorter cmd.
998788de56ccSmrg		break
998888de56ccSmrg	      fi
998988de56ccSmrg	    done
9990862bcd1aSmrg	    IFS=$save_ifs
9991862bcd1aSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
999288de56ccSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
999388de56ccSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
999488de56ccSmrg	    fi
999588de56ccSmrg	  fi
99961ab64890Smrg	fi
99971ab64890Smrg
999888de56ccSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999862bcd1aSmrg	  tmp_export_symbols=$export_symbols
10000862bcd1aSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10001e9fcaa8aSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
1000288de56ccSmrg	fi
100031ab64890Smrg
10004862bcd1aSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
1000588de56ccSmrg	  # The given exports_symbols file has to be filtered, so filter it.
10006862bcd1aSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1000788de56ccSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008862bcd1aSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
1000988de56ccSmrg	  # though. Also, the filter scales superlinearly with the number of
1001088de56ccSmrg	  # global variables. join(1) would be nice here, but unfortunately
1001188de56ccSmrg	  # isn't a blessed tool.
1001288de56ccSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10013e9fcaa8aSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1001488de56ccSmrg	  export_symbols=$output_objdir/$libname.def
1001588de56ccSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
1001688de56ccSmrg	fi
100171ab64890Smrg
1001888de56ccSmrg	tmp_deplibs=
1001988de56ccSmrg	for test_deplib in $deplibs; do
1002088de56ccSmrg	  case " $convenience " in
1002188de56ccSmrg	  *" $test_deplib "*) ;;
1002288de56ccSmrg	  *)
10023e9fcaa8aSmrg	    func_append tmp_deplibs " $test_deplib"
1002488de56ccSmrg	    ;;
1002588de56ccSmrg	  esac
1002688de56ccSmrg	done
10027862bcd1aSmrg	deplibs=$tmp_deplibs
100281ab64890Smrg
1002988de56ccSmrg	if test -n "$convenience"; then
1003088de56ccSmrg	  if test -n "$whole_archive_flag_spec" &&
10031862bcd1aSmrg	    test yes = "$compiler_needs_object" &&
1003288de56ccSmrg	    test -z "$libobjs"; then
1003388de56ccSmrg	    # extract the archives, so we have objects to list.
1003488de56ccSmrg	    # TODO: could optimize this to just extract one archive.
1003588de56ccSmrg	    whole_archive_flag_spec=
1003688de56ccSmrg	  fi
1003788de56ccSmrg	  if test -n "$whole_archive_flag_spec"; then
1003888de56ccSmrg	    save_libobjs=$libobjs
1003988de56ccSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1004088de56ccSmrg	    test "X$libobjs" = "X " && libobjs=
1004188de56ccSmrg	  else
10042862bcd1aSmrg	    gentop=$output_objdir/${outputname}x
10043e9fcaa8aSmrg	    func_append generated " $gentop"
100441ab64890Smrg
1004588de56ccSmrg	    func_extract_archives $gentop $convenience
10046e9fcaa8aSmrg	    func_append libobjs " $func_extract_archives_result"
1004788de56ccSmrg	    test "X$libobjs" = "X " && libobjs=
1004888de56ccSmrg	  fi
10049b4ee4795Smrg	fi
100501ab64890Smrg
10051862bcd1aSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
1005288de56ccSmrg	  eval flag=\"$thread_safe_flag_spec\"
10053e9fcaa8aSmrg	  func_append linker_flags " $flag"
10054b4ee4795Smrg	fi
100552e9c7c8cSmrg
1005688de56ccSmrg	# Make a backup of the uninstalled library when relinking
10057862bcd1aSmrg	if test relink = "$opt_mode"; then
1005888de56ccSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
1005988de56ccSmrg	fi
100601ab64890Smrg
1006188de56ccSmrg	# Do each of the archive commands.
10062862bcd1aSmrg	if test yes = "$module" && test -n "$module_cmds"; then
1006388de56ccSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1006488de56ccSmrg	    eval test_cmds=\"$module_expsym_cmds\"
1006588de56ccSmrg	    cmds=$module_expsym_cmds
1006688de56ccSmrg	  else
1006788de56ccSmrg	    eval test_cmds=\"$module_cmds\"
1006888de56ccSmrg	    cmds=$module_cmds
1006988de56ccSmrg	  fi
10070b4ee4795Smrg	else
1007188de56ccSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1007288de56ccSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
1007388de56ccSmrg	    cmds=$archive_expsym_cmds
1007488de56ccSmrg	  else
1007588de56ccSmrg	    eval test_cmds=\"$archive_cmds\"
1007688de56ccSmrg	    cmds=$archive_cmds
1007788de56ccSmrg	  fi
10078b4ee4795Smrg	fi
100791ab64890Smrg
10080862bcd1aSmrg	if test : != "$skipped_export" &&
1008188de56ccSmrg	   func_len " $test_cmds" &&
1008288de56ccSmrg	   len=$func_len_result &&
1008388de56ccSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1008488de56ccSmrg	  :
1008588de56ccSmrg	else
1008688de56ccSmrg	  # The command line is too long to link in one step, link piecewise
1008788de56ccSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
1008888de56ccSmrg	  # script.
100891ab64890Smrg
1009088de56ccSmrg	  # Save the value of $output and $libobjs because we want to
1009188de56ccSmrg	  # use them later.  If we have whole_archive_flag_spec, we
1009288de56ccSmrg	  # want to use save_libobjs as it was before
1009388de56ccSmrg	  # whole_archive_flag_spec was expanded, because we can't
1009488de56ccSmrg	  # assume the linker understands whole_archive_flag_spec.
1009588de56ccSmrg	  # This may have to be revisited, in case too many
1009688de56ccSmrg	  # convenience libraries get linked in and end up exceeding
1009788de56ccSmrg	  # the spec.
1009888de56ccSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
1009988de56ccSmrg	    save_libobjs=$libobjs
1010088de56ccSmrg	  fi
1010188de56ccSmrg	  save_output=$output
10102e9fcaa8aSmrg	  func_basename "$output"
10103e9fcaa8aSmrg	  output_la=$func_basename_result
101041ab64890Smrg
1010588de56ccSmrg	  # Clear the reloadable object creation command queue and
1010688de56ccSmrg	  # initialize k to one.
1010788de56ccSmrg	  test_cmds=
1010888de56ccSmrg	  concat_cmds=
1010988de56ccSmrg	  objlist=
1011088de56ccSmrg	  last_robj=
1011188de56ccSmrg	  k=1
1011288de56ccSmrg
10113862bcd1aSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114862bcd1aSmrg	    output=$output_objdir/$output_la.lnkscript
1011588de56ccSmrg	    func_verbose "creating GNU ld script: $output"
10116e9fcaa8aSmrg	    echo 'INPUT (' > $output
1011788de56ccSmrg	    for obj in $save_libobjs
10118b4ee4795Smrg	    do
10119e9fcaa8aSmrg	      func_to_tool_file "$obj"
10120e9fcaa8aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
1012188de56ccSmrg	    done
10122e9fcaa8aSmrg	    echo ')' >> $output
10123e9fcaa8aSmrg	    func_append delfiles " $output"
10124e9fcaa8aSmrg	    func_to_tool_file "$output"
10125e9fcaa8aSmrg	    output=$func_to_tool_file_result
10126862bcd1aSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127862bcd1aSmrg	    output=$output_objdir/$output_la.lnk
1012888de56ccSmrg	    func_verbose "creating linker input file list: $output"
1012988de56ccSmrg	    : > $output
1013088de56ccSmrg	    set x $save_libobjs
1013188de56ccSmrg	    shift
1013288de56ccSmrg	    firstobj=
10133862bcd1aSmrg	    if test yes = "$compiler_needs_object"; then
1013488de56ccSmrg	      firstobj="$1 "
1013588de56ccSmrg	      shift
1013688de56ccSmrg	    fi
1013788de56ccSmrg	    for obj
1013888de56ccSmrg	    do
10139e9fcaa8aSmrg	      func_to_tool_file "$obj"
10140e9fcaa8aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
1014188de56ccSmrg	    done
10142e9fcaa8aSmrg	    func_append delfiles " $output"
10143e9fcaa8aSmrg	    func_to_tool_file "$output"
10144e9fcaa8aSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
1014588de56ccSmrg	  else
1014688de56ccSmrg	    if test -n "$save_libobjs"; then
1014788de56ccSmrg	      func_verbose "creating reloadable object files..."
10148862bcd1aSmrg	      output=$output_objdir/$output_la-$k.$objext
1014988de56ccSmrg	      eval test_cmds=\"$reload_cmds\"
1015088de56ccSmrg	      func_len " $test_cmds"
1015188de56ccSmrg	      len0=$func_len_result
1015288de56ccSmrg	      len=$len0
1015388de56ccSmrg
1015488de56ccSmrg	      # Loop over the list of objects to be linked.
1015588de56ccSmrg	      for obj in $save_libobjs
1015688de56ccSmrg	      do
1015788de56ccSmrg		func_len " $obj"
1015888de56ccSmrg		func_arith $len + $func_len_result
1015988de56ccSmrg		len=$func_arith_result
10160862bcd1aSmrg		if test -z "$objlist" ||
1016188de56ccSmrg		   test "$len" -lt "$max_cmd_len"; then
1016288de56ccSmrg		  func_append objlist " $obj"
1016388de56ccSmrg		else
1016488de56ccSmrg		  # The command $test_cmds is almost too long, add a
1016588de56ccSmrg		  # command to the queue.
10166862bcd1aSmrg		  if test 1 -eq "$k"; then
1016788de56ccSmrg		    # The first file doesn't have a previous command to add.
10168e9fcaa8aSmrg		    reload_objs=$objlist
10169e9fcaa8aSmrg		    eval concat_cmds=\"$reload_cmds\"
1017088de56ccSmrg		  else
1017188de56ccSmrg		    # All subsequent reloadable object files will link in
1017288de56ccSmrg		    # the last one created.
10173e9fcaa8aSmrg		    reload_objs="$objlist $last_robj"
10174e9fcaa8aSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
1017588de56ccSmrg		  fi
10176862bcd1aSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
1017788de56ccSmrg		  func_arith $k + 1
1017888de56ccSmrg		  k=$func_arith_result
10179862bcd1aSmrg		  output=$output_objdir/$output_la-$k.$objext
10180e9fcaa8aSmrg		  objlist=" $obj"
1018188de56ccSmrg		  func_len " $last_robj"
1018288de56ccSmrg		  func_arith $len0 + $func_len_result
1018388de56ccSmrg		  len=$func_arith_result
1018488de56ccSmrg		fi
1018588de56ccSmrg	      done
1018688de56ccSmrg	      # Handle the remaining objects by creating one last
1018788de56ccSmrg	      # reloadable object file.  All subsequent reloadable object
1018888de56ccSmrg	      # files will link in the last one created.
1018988de56ccSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10190e9fcaa8aSmrg	      reload_objs="$objlist $last_robj"
10191862bcd1aSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
1019288de56ccSmrg	      if test -n "$last_robj"; then
10193862bcd1aSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
1019488de56ccSmrg	      fi
10195e9fcaa8aSmrg	      func_append delfiles " $output"
101961ab64890Smrg
1019788de56ccSmrg	    else
1019888de56ccSmrg	      output=
1019988de56ccSmrg	    fi
102001ab64890Smrg
10201862bcd1aSmrg	    ${skipped_export-false} && {
10202862bcd1aSmrg	      func_verbose "generating symbol list for '$libname.la'"
10203862bcd1aSmrg	      export_symbols=$output_objdir/$libname.exp
1020488de56ccSmrg	      $opt_dry_run || $RM $export_symbols
1020588de56ccSmrg	      libobjs=$output
1020688de56ccSmrg	      # Append the command to create the export file.
1020788de56ccSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1020888de56ccSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
1020988de56ccSmrg	      if test -n "$last_robj"; then
1021088de56ccSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
1021188de56ccSmrg	      fi
10212862bcd1aSmrg	    }
102131ab64890Smrg
1021488de56ccSmrg	    test -n "$save_libobjs" &&
1021588de56ccSmrg	      func_verbose "creating a temporary reloadable object file: $output"
102161ab64890Smrg
1021788de56ccSmrg	    # Loop through the commands generated above and execute them.
10218862bcd1aSmrg	    save_ifs=$IFS; IFS='~'
1021988de56ccSmrg	    for cmd in $concat_cmds; do
10220862bcd1aSmrg	      IFS=$save_ifs
10221862bcd1aSmrg	      $opt_quiet || {
10222e9628295Smrg		  func_quote_arg expand,pretty "$cmd"
10223e9628295Smrg		  eval "func_echo $func_quote_arg_result"
1022488de56ccSmrg	      }
1022588de56ccSmrg	      $opt_dry_run || eval "$cmd" || {
1022688de56ccSmrg		lt_exit=$?
1022788de56ccSmrg
1022888de56ccSmrg		# Restore the uninstalled library and exit
10229862bcd1aSmrg		if test relink = "$opt_mode"; then
1023088de56ccSmrg		  ( cd "$output_objdir" && \
1023188de56ccSmrg		    $RM "${realname}T" && \
1023288de56ccSmrg		    $MV "${realname}U" "$realname" )
1023388de56ccSmrg		fi
102341ab64890Smrg
1023588de56ccSmrg		exit $lt_exit
1023688de56ccSmrg	      }
1023788de56ccSmrg	    done
10238862bcd1aSmrg	    IFS=$save_ifs
10239b4ee4795Smrg
1024088de56ccSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
1024188de56ccSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
1024288de56ccSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
102431ab64890Smrg	    fi
102441ab64890Smrg	  fi
102451ab64890Smrg
10246862bcd1aSmrg          ${skipped_export-false} && {
1024788de56ccSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248862bcd1aSmrg	      tmp_export_symbols=$export_symbols
10249862bcd1aSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10250e9fcaa8aSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
1025188de56ccSmrg	    fi
102522e9c7c8cSmrg
1025388de56ccSmrg	    if test -n "$orig_export_symbols"; then
1025488de56ccSmrg	      # The given exports_symbols file has to be filtered, so filter it.
10255862bcd1aSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
1025688de56ccSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257862bcd1aSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
1025888de56ccSmrg	      # though. Also, the filter scales superlinearly with the number of
1025988de56ccSmrg	      # global variables. join(1) would be nice here, but unfortunately
1026088de56ccSmrg	      # isn't a blessed tool.
1026188de56ccSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10262e9fcaa8aSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
1026388de56ccSmrg	      export_symbols=$output_objdir/$libname.def
1026488de56ccSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
1026588de56ccSmrg	    fi
10266862bcd1aSmrg	  }
102671ab64890Smrg
1026888de56ccSmrg	  libobjs=$output
1026988de56ccSmrg	  # Restore the value of output.
1027088de56ccSmrg	  output=$save_output
102711ab64890Smrg
1027288de56ccSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
1027388de56ccSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
1027488de56ccSmrg	    test "X$libobjs" = "X " && libobjs=
1027588de56ccSmrg	  fi
1027688de56ccSmrg	  # Expand the library linking commands again to reset the
1027788de56ccSmrg	  # value of $libobjs for piecewise linking.
102781ab64890Smrg
1027988de56ccSmrg	  # Do each of the archive commands.
10280862bcd1aSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
1028188de56ccSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
1028288de56ccSmrg	      cmds=$module_expsym_cmds
1028388de56ccSmrg	    else
1028488de56ccSmrg	      cmds=$module_cmds
10285b4ee4795Smrg	    fi
10286b4ee4795Smrg	  else
1028788de56ccSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1028888de56ccSmrg	      cmds=$archive_expsym_cmds
1028988de56ccSmrg	    else
1029088de56ccSmrg	      cmds=$archive_cmds
1029188de56ccSmrg	    fi
10292b4ee4795Smrg	  fi
1029388de56ccSmrg	fi
102941ab64890Smrg
1029588de56ccSmrg	if test -n "$delfiles"; then
1029688de56ccSmrg	  # Append the command to remove temporary files to $cmds.
1029788de56ccSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
1029888de56ccSmrg	fi
102991ab64890Smrg
1030088de56ccSmrg	# Add any objects from preloaded convenience libraries
1030188de56ccSmrg	if test -n "$dlprefiles"; then
10302862bcd1aSmrg	  gentop=$output_objdir/${outputname}x
10303e9fcaa8aSmrg	  func_append generated " $gentop"
103041ab64890Smrg
1030588de56ccSmrg	  func_extract_archives $gentop $dlprefiles
10306e9fcaa8aSmrg	  func_append libobjs " $func_extract_archives_result"
1030788de56ccSmrg	  test "X$libobjs" = "X " && libobjs=
1030888de56ccSmrg	fi
103091ab64890Smrg
10310862bcd1aSmrg	save_ifs=$IFS; IFS='~'
1031188de56ccSmrg	for cmd in $cmds; do
10312862bcd1aSmrg	  IFS=$sp$nl
1031388de56ccSmrg	  eval cmd=\"$cmd\"
10314862bcd1aSmrg	  IFS=$save_ifs
10315862bcd1aSmrg	  $opt_quiet || {
10316e9628295Smrg	    func_quote_arg expand,pretty "$cmd"
10317e9628295Smrg	    eval "func_echo $func_quote_arg_result"
1031888de56ccSmrg	  }
1031988de56ccSmrg	  $opt_dry_run || eval "$cmd" || {
1032088de56ccSmrg	    lt_exit=$?
103212e9c7c8cSmrg
1032288de56ccSmrg	    # Restore the uninstalled library and exit
10323862bcd1aSmrg	    if test relink = "$opt_mode"; then
1032488de56ccSmrg	      ( cd "$output_objdir" && \
1032588de56ccSmrg	        $RM "${realname}T" && \
1032688de56ccSmrg		$MV "${realname}U" "$realname" )
1032788de56ccSmrg	    fi
103282e9c7c8cSmrg
1032988de56ccSmrg	    exit $lt_exit
1033088de56ccSmrg	  }
1033188de56ccSmrg	done
10332862bcd1aSmrg	IFS=$save_ifs
103332e9c7c8cSmrg
1033488de56ccSmrg	# Restore the uninstalled library and exit
10335862bcd1aSmrg	if test relink = "$opt_mode"; then
1033688de56ccSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
103372e9c7c8cSmrg
1033888de56ccSmrg	  if test -n "$convenience"; then
1033988de56ccSmrg	    if test -z "$whole_archive_flag_spec"; then
1034088de56ccSmrg	      func_show_eval '${RM}r "$gentop"'
1034188de56ccSmrg	    fi
1034288de56ccSmrg	  fi
103432e9c7c8cSmrg
1034488de56ccSmrg	  exit $EXIT_SUCCESS
1034588de56ccSmrg	fi
1034688de56ccSmrg
1034788de56ccSmrg	# Create links to the real library.
1034888de56ccSmrg	for linkname in $linknames; do
1034988de56ccSmrg	  if test "$realname" != "$linkname"; then
1035088de56ccSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351b4ee4795Smrg	  fi
10352b4ee4795Smrg	done
103532e9c7c8cSmrg
1035488de56ccSmrg	# If -module or -export-dynamic was specified, set the dlname.
10355862bcd1aSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
1035688de56ccSmrg	  # On all known operating systems, these are identical.
10357862bcd1aSmrg	  dlname=$soname
1035888de56ccSmrg	fi
1035988de56ccSmrg      fi
103601ab64890Smrg      ;;
103611ab64890Smrg
1036288de56ccSmrg    obj)
10363862bcd1aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364862bcd1aSmrg	func_warning "'-dlopen' is ignored for objects"
1036588de56ccSmrg      fi
10366b4ee4795Smrg
1036788de56ccSmrg      case " $deplibs" in
1036888de56ccSmrg      *\ -l* | *\ -L*)
10369862bcd1aSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
103702e9c7c8cSmrg      esac
103711ab64890Smrg
1037288de56ccSmrg      test -n "$rpath" && \
10373862bcd1aSmrg	func_warning "'-rpath' is ignored for objects"
1037488de56ccSmrg
1037588de56ccSmrg      test -n "$xrpath" && \
10376862bcd1aSmrg	func_warning "'-R' is ignored for objects"
103771ab64890Smrg
1037888de56ccSmrg      test -n "$vinfo" && \
10379862bcd1aSmrg	func_warning "'-version-info' is ignored for objects"
103802e9c7c8cSmrg
1038188de56ccSmrg      test -n "$release" && \
10382862bcd1aSmrg	func_warning "'-release' is ignored for objects"
1038388de56ccSmrg
1038488de56ccSmrg      case $output in
1038588de56ccSmrg      *.lo)
1038688de56ccSmrg	test -n "$objs$old_deplibs" && \
10387862bcd1aSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
1038888de56ccSmrg
1038988de56ccSmrg	libobj=$output
1039088de56ccSmrg	func_lo2o "$libobj"
1039188de56ccSmrg	obj=$func_lo2o_result
10392b4ee4795Smrg	;;
10393b4ee4795Smrg      *)
1039488de56ccSmrg	libobj=
10395862bcd1aSmrg	obj=$output
103961ab64890Smrg	;;
103972e9c7c8cSmrg      esac
103981ab64890Smrg
1039988de56ccSmrg      # Delete the old objects.
1040088de56ccSmrg      $opt_dry_run || $RM $obj $libobj
104011ab64890Smrg
1040288de56ccSmrg      # Objects from convenience libraries.  This assumes
1040388de56ccSmrg      # single-version convenience libraries.  Whenever we create
1040488de56ccSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
1040588de56ccSmrg      # the extraction.
1040688de56ccSmrg      reload_conv_objs=
1040788de56ccSmrg      gentop=
10408862bcd1aSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409862bcd1aSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410862bcd1aSmrg      # into space.
10411862bcd1aSmrg      case $reload_cmds in
10412862bcd1aSmrg        *\$LD[\ \$]*) wl= ;;
10413862bcd1aSmrg      esac
1041488de56ccSmrg      if test -n "$convenience"; then
1041588de56ccSmrg	if test -n "$whole_archive_flag_spec"; then
1041688de56ccSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417862bcd1aSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418862bcd1aSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
1041988de56ccSmrg	else
10420862bcd1aSmrg	  gentop=$output_objdir/${obj}x
10421e9fcaa8aSmrg	  func_append generated " $gentop"
10422b4ee4795Smrg
1042388de56ccSmrg	  func_extract_archives $gentop $convenience
1042488de56ccSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
1042588de56ccSmrg	fi
10426b4ee4795Smrg      fi
10427b4ee4795Smrg
10428e9fcaa8aSmrg      # If we're not building shared, we need to use non_pic_objs
10429862bcd1aSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430e9fcaa8aSmrg
1043188de56ccSmrg      # Create the old-style object.
10432862bcd1aSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433b4ee4795Smrg
10434862bcd1aSmrg      output=$obj
1043588de56ccSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436b4ee4795Smrg
1043788de56ccSmrg      # Exit if we aren't doing a library object file.
1043888de56ccSmrg      if test -z "$libobj"; then
1043988de56ccSmrg	if test -n "$gentop"; then
1044088de56ccSmrg	  func_show_eval '${RM}r "$gentop"'
1044188de56ccSmrg	fi
1044288de56ccSmrg
1044388de56ccSmrg	exit $EXIT_SUCCESS
10444b4ee4795Smrg      fi
1044588de56ccSmrg
10446862bcd1aSmrg      test yes = "$build_libtool_libs" || {
1044788de56ccSmrg	if test -n "$gentop"; then
1044888de56ccSmrg	  func_show_eval '${RM}r "$gentop"'
1044988de56ccSmrg	fi
1045088de56ccSmrg
1045188de56ccSmrg	# Create an invalid libtool object if no PIC, so that we don't
1045288de56ccSmrg	# accidentally link it into a program.
1045388de56ccSmrg	# $show "echo timestamp > $libobj"
1045488de56ccSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
1045588de56ccSmrg	exit $EXIT_SUCCESS
10456862bcd1aSmrg      }
1045788de56ccSmrg
10458862bcd1aSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
1045988de56ccSmrg	# Only do commands if we really have different PIC objects.
1046088de56ccSmrg	reload_objs="$libobjs $reload_conv_objs"
10461862bcd1aSmrg	output=$libobj
1046288de56ccSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
1046388de56ccSmrg      fi
1046488de56ccSmrg
1046588de56ccSmrg      if test -n "$gentop"; then
1046688de56ccSmrg	func_show_eval '${RM}r "$gentop"'
1046788de56ccSmrg      fi
1046888de56ccSmrg
1046988de56ccSmrg      exit $EXIT_SUCCESS
10470b4ee4795Smrg      ;;
104711ab64890Smrg
1047288de56ccSmrg    prog)
1047388de56ccSmrg      case $host in
1047488de56ccSmrg	*cygwin*) func_stripname '' '.exe' "$output"
1047588de56ccSmrg	          output=$func_stripname_result.exe;;
1047688de56ccSmrg      esac
1047788de56ccSmrg      test -n "$vinfo" && \
10478862bcd1aSmrg	func_warning "'-version-info' is ignored for programs"
104791ab64890Smrg
1048088de56ccSmrg      test -n "$release" && \
10481862bcd1aSmrg	func_warning "'-release' is ignored for programs"
104821ab64890Smrg
10483862bcd1aSmrg      $preload \
10484862bcd1aSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485862bcd1aSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
1048688de56ccSmrg
1048788de56ccSmrg      case $host in
1048888de56ccSmrg      *-*-rhapsody* | *-*-darwin1.[012])
1048988de56ccSmrg	# On Rhapsody replace the C library is the System framework
10490e9fcaa8aSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10491e9fcaa8aSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492b4ee4795Smrg	;;
1049388de56ccSmrg      esac
10494b4ee4795Smrg
1049588de56ccSmrg      case $host in
1049688de56ccSmrg      *-*-darwin*)
1049788de56ccSmrg	# Don't allow lazy linking, it breaks C++ global constructors
1049888de56ccSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10499862bcd1aSmrg	if test CXX = "$tagname"; then
1050088de56ccSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
1050188de56ccSmrg	    10.[0123])
10502862bcd1aSmrg	      func_append compile_command " $wl-bind_at_load"
10503862bcd1aSmrg	      func_append finalize_command " $wl-bind_at_load"
1050488de56ccSmrg	    ;;
1050588de56ccSmrg	  esac
10506b4ee4795Smrg	fi
1050788de56ccSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10508e9fcaa8aSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10509e9fcaa8aSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1051088de56ccSmrg	;;
1051188de56ccSmrg      esac
10512b4ee4795Smrg
10513b4ee4795Smrg
1051488de56ccSmrg      # move library search paths that coincide with paths to not yet
1051588de56ccSmrg      # installed libraries to the beginning of the library search list
1051688de56ccSmrg      new_libs=
1051788de56ccSmrg      for path in $notinst_path; do
1051888de56ccSmrg	case " $new_libs " in
1051988de56ccSmrg	*" -L$path/$objdir "*) ;;
1052088de56ccSmrg	*)
1052188de56ccSmrg	  case " $compile_deplibs " in
1052288de56ccSmrg	  *" -L$path/$objdir "*)
10523e9fcaa8aSmrg	    func_append new_libs " -L$path/$objdir" ;;
105242e9c7c8cSmrg	  esac
1052588de56ccSmrg	  ;;
1052688de56ccSmrg	esac
1052788de56ccSmrg      done
1052888de56ccSmrg      for deplib in $compile_deplibs; do
1052988de56ccSmrg	case $deplib in
1053088de56ccSmrg	-L*)
1053188de56ccSmrg	  case " $new_libs " in
1053288de56ccSmrg	  *" $deplib "*) ;;
10533e9fcaa8aSmrg	  *) func_append new_libs " $deplib" ;;
105342e9c7c8cSmrg	  esac
1053588de56ccSmrg	  ;;
10536e9fcaa8aSmrg	*) func_append new_libs " $deplib" ;;
1053788de56ccSmrg	esac
1053888de56ccSmrg      done
10539862bcd1aSmrg      compile_deplibs=$new_libs
105401ab64890Smrg
10541b4ee4795Smrg
10542e9fcaa8aSmrg      func_append compile_command " $compile_deplibs"
10543e9fcaa8aSmrg      func_append finalize_command " $finalize_deplibs"
10544b4ee4795Smrg
1054588de56ccSmrg      if test -n "$rpath$xrpath"; then
1054688de56ccSmrg	# If the user specified any rpath flags, then add them.
1054788de56ccSmrg	for libdir in $rpath $xrpath; do
1054888de56ccSmrg	  # This is the magic to use -rpath.
1054988de56ccSmrg	  case "$finalize_rpath " in
1055088de56ccSmrg	  *" $libdir "*) ;;
10551e9fcaa8aSmrg	  *) func_append finalize_rpath " $libdir" ;;
1055288de56ccSmrg	  esac
1055388de56ccSmrg	done
1055488de56ccSmrg      fi
10555b4ee4795Smrg
1055688de56ccSmrg      # Now hardcode the library paths
1055788de56ccSmrg      rpath=
1055888de56ccSmrg      hardcode_libdirs=
1055988de56ccSmrg      for libdir in $compile_rpath $finalize_rpath; do
1056088de56ccSmrg	if test -n "$hardcode_libdir_flag_spec"; then
1056188de56ccSmrg	  if test -n "$hardcode_libdir_separator"; then
1056288de56ccSmrg	    if test -z "$hardcode_libdirs"; then
10563862bcd1aSmrg	      hardcode_libdirs=$libdir
1056488de56ccSmrg	    else
1056588de56ccSmrg	      # Just accumulate the unique libdirs.
1056688de56ccSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1056788de56ccSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1056888de56ccSmrg		;;
1056988de56ccSmrg	      *)
10570e9fcaa8aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1057188de56ccSmrg		;;
1057288de56ccSmrg	      esac
1057388de56ccSmrg	    fi
10574b4ee4795Smrg	  else
1057588de56ccSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10576e9fcaa8aSmrg	    func_append rpath " $flag"
10577b4ee4795Smrg	  fi
1057888de56ccSmrg	elif test -n "$runpath_var"; then
1057988de56ccSmrg	  case "$perm_rpath " in
1058088de56ccSmrg	  *" $libdir "*) ;;
10581e9fcaa8aSmrg	  *) func_append perm_rpath " $libdir" ;;
1058288de56ccSmrg	  esac
1058388de56ccSmrg	fi
1058488de56ccSmrg	case $host in
1058588de56ccSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586862bcd1aSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
1058788de56ccSmrg	  case :$dllsearchpath: in
1058888de56ccSmrg	  *":$libdir:"*) ;;
1058988de56ccSmrg	  ::) dllsearchpath=$libdir;;
10590e9fcaa8aSmrg	  *) func_append dllsearchpath ":$libdir";;
1059188de56ccSmrg	  esac
1059288de56ccSmrg	  case :$dllsearchpath: in
1059388de56ccSmrg	  *":$testbindir:"*) ;;
1059488de56ccSmrg	  ::) dllsearchpath=$testbindir;;
10595e9fcaa8aSmrg	  *) func_append dllsearchpath ":$testbindir";;
1059688de56ccSmrg	  esac
1059788de56ccSmrg	  ;;
1059888de56ccSmrg	esac
1059988de56ccSmrg      done
1060088de56ccSmrg      # Substitute the hardcoded libdirs into the rpath.
1060188de56ccSmrg      if test -n "$hardcode_libdir_separator" &&
1060288de56ccSmrg	 test -n "$hardcode_libdirs"; then
10603862bcd1aSmrg	libdir=$hardcode_libdirs
1060488de56ccSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1060588de56ccSmrg      fi
10606862bcd1aSmrg      compile_rpath=$rpath
10607b4ee4795Smrg
1060888de56ccSmrg      rpath=
1060988de56ccSmrg      hardcode_libdirs=
1061088de56ccSmrg      for libdir in $finalize_rpath; do
1061188de56ccSmrg	if test -n "$hardcode_libdir_flag_spec"; then
1061288de56ccSmrg	  if test -n "$hardcode_libdir_separator"; then
1061388de56ccSmrg	    if test -z "$hardcode_libdirs"; then
10614862bcd1aSmrg	      hardcode_libdirs=$libdir
1061588de56ccSmrg	    else
1061688de56ccSmrg	      # Just accumulate the unique libdirs.
1061788de56ccSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1061888de56ccSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1061988de56ccSmrg		;;
1062088de56ccSmrg	      *)
10621e9fcaa8aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1062288de56ccSmrg		;;
1062388de56ccSmrg	      esac
1062488de56ccSmrg	    fi
106251ab64890Smrg	  else
1062688de56ccSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10627e9fcaa8aSmrg	    func_append rpath " $flag"
106281ab64890Smrg	  fi
1062988de56ccSmrg	elif test -n "$runpath_var"; then
1063088de56ccSmrg	  case "$finalize_perm_rpath " in
1063188de56ccSmrg	  *" $libdir "*) ;;
10632e9fcaa8aSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
1063388de56ccSmrg	  esac
106341ab64890Smrg	fi
1063588de56ccSmrg      done
1063688de56ccSmrg      # Substitute the hardcoded libdirs into the rpath.
1063788de56ccSmrg      if test -n "$hardcode_libdir_separator" &&
1063888de56ccSmrg	 test -n "$hardcode_libdirs"; then
10639862bcd1aSmrg	libdir=$hardcode_libdirs
1064088de56ccSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1064188de56ccSmrg      fi
10642862bcd1aSmrg      finalize_rpath=$rpath
106431ab64890Smrg
10644862bcd1aSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
1064588de56ccSmrg	# Transform all the library objects into standard objects.
10646e9fcaa8aSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10647e9fcaa8aSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064888de56ccSmrg      fi
106491ab64890Smrg
10650862bcd1aSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
106511ab64890Smrg
1065288de56ccSmrg      # template prelinking step
1065388de56ccSmrg      if test -n "$prelink_cmds"; then
1065488de56ccSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
1065588de56ccSmrg      fi
106561ab64890Smrg
10657862bcd1aSmrg      wrappers_required=:
1065888de56ccSmrg      case $host in
10659e9fcaa8aSmrg      *cegcc* | *mingw32ce*)
10660e9fcaa8aSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661862bcd1aSmrg        wrappers_required=false
10662e9fcaa8aSmrg        ;;
1066388de56ccSmrg      *cygwin* | *mingw* )
10664862bcd1aSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
1066588de56ccSmrg        ;;
1066688de56ccSmrg      *)
10667862bcd1aSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668862bcd1aSmrg          wrappers_required=false
1066988de56ccSmrg        fi
1067088de56ccSmrg        ;;
1067188de56ccSmrg      esac
10672862bcd1aSmrg      $wrappers_required || {
1067388de56ccSmrg	# Replace the output file specification.
10674e9fcaa8aSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675862bcd1aSmrg	link_command=$compile_command$compile_rpath
106761ab64890Smrg
1067788de56ccSmrg	# We have no uninstalled library dependencies, so finalize right now.
1067888de56ccSmrg	exit_status=0
1067988de56ccSmrg	func_show_eval "$link_command" 'exit_status=$?'
106801ab64890Smrg
10681e9fcaa8aSmrg	if test -n "$postlink_cmds"; then
10682e9fcaa8aSmrg	  func_to_tool_file "$output"
10683e9fcaa8aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10684e9fcaa8aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10685e9fcaa8aSmrg	fi
10686e9fcaa8aSmrg
1068788de56ccSmrg	# Delete the generated files.
10688862bcd1aSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689862bcd1aSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
106901ab64890Smrg	fi
106911ab64890Smrg
1069288de56ccSmrg	exit $exit_status
10693862bcd1aSmrg      }
106941ab64890Smrg
1069588de56ccSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
1069688de56ccSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
1069788de56ccSmrg      fi
1069888de56ccSmrg      if test -n "$finalize_shlibpath"; then
1069988de56ccSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
1070088de56ccSmrg      fi
10701b4ee4795Smrg
1070288de56ccSmrg      compile_var=
1070388de56ccSmrg      finalize_var=
1070488de56ccSmrg      if test -n "$runpath_var"; then
1070588de56ccSmrg	if test -n "$perm_rpath"; then
1070688de56ccSmrg	  # We should set the runpath_var.
1070788de56ccSmrg	  rpath=
1070888de56ccSmrg	  for dir in $perm_rpath; do
10709e9fcaa8aSmrg	    func_append rpath "$dir:"
1071088de56ccSmrg	  done
1071188de56ccSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
107121ab64890Smrg	fi
1071388de56ccSmrg	if test -n "$finalize_perm_rpath"; then
1071488de56ccSmrg	  # We should set the runpath_var.
1071588de56ccSmrg	  rpath=
1071688de56ccSmrg	  for dir in $finalize_perm_rpath; do
10717e9fcaa8aSmrg	    func_append rpath "$dir:"
1071888de56ccSmrg	  done
1071988de56ccSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
107201ab64890Smrg	fi
1072188de56ccSmrg      fi
107221ab64890Smrg
10723862bcd1aSmrg      if test yes = "$no_install"; then
1072488de56ccSmrg	# We don't need to create a wrapper script.
10725862bcd1aSmrg	link_command=$compile_var$compile_command$compile_rpath
1072688de56ccSmrg	# Replace the output file specification.
10727e9fcaa8aSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1072888de56ccSmrg	# Delete the old output file.
1072988de56ccSmrg	$opt_dry_run || $RM $output
1073088de56ccSmrg	# Link the executable and exit
1073188de56ccSmrg	func_show_eval "$link_command" 'exit $?'
10732e9fcaa8aSmrg
10733e9fcaa8aSmrg	if test -n "$postlink_cmds"; then
10734e9fcaa8aSmrg	  func_to_tool_file "$output"
10735e9fcaa8aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10736e9fcaa8aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737e9fcaa8aSmrg	fi
10738e9fcaa8aSmrg
10739b4ee4795Smrg	exit $EXIT_SUCCESS
1074088de56ccSmrg      fi
107412e9c7c8cSmrg
10742862bcd1aSmrg      case $hardcode_action,$fast_install in
10743862bcd1aSmrg        relink,*)
10744862bcd1aSmrg	  # Fast installation is not supported
10745862bcd1aSmrg	  link_command=$compile_var$compile_command$compile_rpath
10746862bcd1aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1074788de56ccSmrg
10748862bcd1aSmrg	  func_warning "this platform does not like uninstalled shared libraries"
10749862bcd1aSmrg	  func_warning "'$output' will be relinked during installation"
10750862bcd1aSmrg	  ;;
10751862bcd1aSmrg        *,yes)
10752862bcd1aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753862bcd1aSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754862bcd1aSmrg          ;;
10755862bcd1aSmrg	*,no)
10756862bcd1aSmrg	  link_command=$compile_var$compile_command$compile_rpath
10757862bcd1aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758862bcd1aSmrg          ;;
10759862bcd1aSmrg	*,needless)
10760862bcd1aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761862bcd1aSmrg	  relink_command=
10762862bcd1aSmrg          ;;
10763862bcd1aSmrg      esac
107641ab64890Smrg
1076588de56ccSmrg      # Replace the output file specification.
10766e9fcaa8aSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
107671ab64890Smrg
1076888de56ccSmrg      # Delete the old output files.
1076988de56ccSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
107701ab64890Smrg
1077188de56ccSmrg      func_show_eval "$link_command" 'exit $?'
10772b4ee4795Smrg
10773e9fcaa8aSmrg      if test -n "$postlink_cmds"; then
10774e9fcaa8aSmrg	func_to_tool_file "$output_objdir/$outputname"
10775e9fcaa8aSmrg	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'`
10776e9fcaa8aSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10777e9fcaa8aSmrg      fi
10778e9fcaa8aSmrg
1077988de56ccSmrg      # Now create the wrapper script.
1078088de56ccSmrg      func_verbose "creating $output"
10781b4ee4795Smrg
1078288de56ccSmrg      # Quote the relink command for shipping.
1078388de56ccSmrg      if test -n "$relink_command"; then
1078488de56ccSmrg	# Preserve any variables that may affect compiler behavior
1078588de56ccSmrg	for var in $variables_saved_for_relink; do
1078688de56ccSmrg	  if eval test -z \"\${$var+set}\"; then
1078788de56ccSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1078888de56ccSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
1078988de56ccSmrg	    relink_command="$var=; export $var; $relink_command"
107901ab64890Smrg	  else
10791e9628295Smrg	    func_quote_arg pretty "$var_value"
10792e9628295Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
107931ab64890Smrg	  fi
1079488de56ccSmrg	done
10795e9628295Smrg	func_quote eval cd "`pwd`"
10796e9628295Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797e9628295Smrg	relink_command=$func_quote_arg_unquoted_result
1079888de56ccSmrg      fi
1079988de56ccSmrg
1080088de56ccSmrg      # Only actually do things if not in dry run mode.
1080188de56ccSmrg      $opt_dry_run || {
1080288de56ccSmrg	# win32 will think the script is a binary if it has
1080388de56ccSmrg	# a .exe suffix, so we strip it off here.
1080488de56ccSmrg	case $output in
1080588de56ccSmrg	  *.exe) func_stripname '' '.exe' "$output"
1080688de56ccSmrg	         output=$func_stripname_result ;;
1080788de56ccSmrg	esac
1080888de56ccSmrg	# test for cygwin because mv fails w/o .exe extensions
1080988de56ccSmrg	case $host in
1081088de56ccSmrg	  *cygwin*)
1081188de56ccSmrg	    exeext=.exe
1081288de56ccSmrg	    func_stripname '' '.exe' "$outputname"
1081388de56ccSmrg	    outputname=$func_stripname_result ;;
1081488de56ccSmrg	  *) exeext= ;;
108151ab64890Smrg	esac
1081688de56ccSmrg	case $host in
1081788de56ccSmrg	  *cygwin* | *mingw* )
1081888de56ccSmrg	    func_dirname_and_basename "$output" "" "."
1081988de56ccSmrg	    output_name=$func_basename_result
1082088de56ccSmrg	    output_path=$func_dirname_result
10821862bcd1aSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822862bcd1aSmrg	    cwrapper=$output_path/$output_name.exe
1082388de56ccSmrg	    $RM $cwrappersource $cwrapper
1082488de56ccSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
1082588de56ccSmrg
1082688de56ccSmrg	    func_emit_cwrapperexe_src > $cwrappersource
1082788de56ccSmrg
1082888de56ccSmrg	    # The wrapper executable is built using the $host compiler,
1082988de56ccSmrg	    # because it contains $host paths and files. If cross-
1083088de56ccSmrg	    # compiling, it, like the target executable, must be
1083188de56ccSmrg	    # executed on the $host or under an emulation environment.
1083288de56ccSmrg	    $opt_dry_run || {
1083388de56ccSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
1083488de56ccSmrg	      $STRIP $cwrapper
1083588de56ccSmrg	    }
108361ab64890Smrg
1083788de56ccSmrg	    # Now, create the wrapper script for func_source use:
1083888de56ccSmrg	    func_ltwrapper_scriptname $cwrapper
1083988de56ccSmrg	    $RM $func_ltwrapper_scriptname_result
1084088de56ccSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
1084188de56ccSmrg	    $opt_dry_run || {
1084288de56ccSmrg	      # note: this script will not be executed, so do not chmod.
10843862bcd1aSmrg	      if test "x$build" = "x$host"; then
1084488de56ccSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
1084588de56ccSmrg	      else
1084688de56ccSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
1084788de56ccSmrg	      fi
1084888de56ccSmrg	    }
1084988de56ccSmrg	  ;;
1085088de56ccSmrg	  * )
1085188de56ccSmrg	    $RM $output
1085288de56ccSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
108531ab64890Smrg
1085488de56ccSmrg	    func_emit_wrapper no > $output
1085588de56ccSmrg	    chmod +x $output
1085688de56ccSmrg	  ;;
1085788de56ccSmrg	esac
1085888de56ccSmrg      }
1085988de56ccSmrg      exit $EXIT_SUCCESS
1086088de56ccSmrg      ;;
1086188de56ccSmrg    esac
108621ab64890Smrg
1086388de56ccSmrg    # See if we need to build an old-fashioned archive.
1086488de56ccSmrg    for oldlib in $oldlibs; do
108651ab64890Smrg
10866862bcd1aSmrg      case $build_libtool_libs in
10867862bcd1aSmrg        convenience)
10868862bcd1aSmrg	  oldobjs="$libobjs_save $symfileobj"
10869862bcd1aSmrg	  addlibs=$convenience
1087088de56ccSmrg	  build_libtool_libs=no
10871862bcd1aSmrg	  ;;
10872862bcd1aSmrg	module)
10873862bcd1aSmrg	  oldobjs=$libobjs_save
10874862bcd1aSmrg	  addlibs=$old_convenience
10875862bcd1aSmrg	  build_libtool_libs=no
10876862bcd1aSmrg          ;;
10877862bcd1aSmrg	*)
1087888de56ccSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10879862bcd1aSmrg	  $preload && test -f "$symfileobj" \
10880862bcd1aSmrg	    && func_append oldobjs " $symfileobj"
10881862bcd1aSmrg	  addlibs=$old_convenience
10882862bcd1aSmrg	  ;;
10883862bcd1aSmrg      esac
108841ab64890Smrg
1088588de56ccSmrg      if test -n "$addlibs"; then
10886862bcd1aSmrg	gentop=$output_objdir/${outputname}x
10887e9fcaa8aSmrg	func_append generated " $gentop"
108881ab64890Smrg
1088988de56ccSmrg	func_extract_archives $gentop $addlibs
10890e9fcaa8aSmrg	func_append oldobjs " $func_extract_archives_result"
1089188de56ccSmrg      fi
108921ab64890Smrg
1089388de56ccSmrg      # Do each command in the archive commands.
10894862bcd1aSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
1089588de56ccSmrg	cmds=$old_archive_from_new_cmds
1089688de56ccSmrg      else
108971ab64890Smrg
1089888de56ccSmrg	# Add any objects from preloaded convenience libraries
1089988de56ccSmrg	if test -n "$dlprefiles"; then
10900862bcd1aSmrg	  gentop=$output_objdir/${outputname}x
10901e9fcaa8aSmrg	  func_append generated " $gentop"
109021ab64890Smrg
1090388de56ccSmrg	  func_extract_archives $gentop $dlprefiles
10904e9fcaa8aSmrg	  func_append oldobjs " $func_extract_archives_result"
1090588de56ccSmrg	fi
109061ab64890Smrg
1090788de56ccSmrg	# POSIX demands no paths to be encoded in archives.  We have
1090888de56ccSmrg	# to avoid creating archives with duplicate basenames if we
1090988de56ccSmrg	# might have to extract them afterwards, e.g., when creating a
1091088de56ccSmrg	# static archive out of a convenience library, or when linking
1091188de56ccSmrg	# the entirety of a libtool archive into another (currently
1091288de56ccSmrg	# not supported by libtool).
1091388de56ccSmrg	if (for obj in $oldobjs
1091488de56ccSmrg	    do
1091588de56ccSmrg	      func_basename "$obj"
1091688de56ccSmrg	      $ECHO "$func_basename_result"
1091788de56ccSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
1091888de56ccSmrg	  :
1091988de56ccSmrg	else
10920e9fcaa8aSmrg	  echo "copying selected object files to avoid basename conflicts..."
10921862bcd1aSmrg	  gentop=$output_objdir/${outputname}x
10922e9fcaa8aSmrg	  func_append generated " $gentop"
1092388de56ccSmrg	  func_mkdir_p "$gentop"
1092488de56ccSmrg	  save_oldobjs=$oldobjs
1092588de56ccSmrg	  oldobjs=
1092688de56ccSmrg	  counter=1
1092788de56ccSmrg	  for obj in $save_oldobjs
1092888de56ccSmrg	  do
1092988de56ccSmrg	    func_basename "$obj"
10930862bcd1aSmrg	    objbase=$func_basename_result
1093188de56ccSmrg	    case " $oldobjs " in
1093288de56ccSmrg	    " ") oldobjs=$obj ;;
1093388de56ccSmrg	    *[\ /]"$objbase "*)
1093488de56ccSmrg	      while :; do
1093588de56ccSmrg		# Make sure we don't pick an alternate name that also
1093688de56ccSmrg		# overlaps.
1093788de56ccSmrg		newobj=lt$counter-$objbase
1093888de56ccSmrg		func_arith $counter + 1
1093988de56ccSmrg		counter=$func_arith_result
1094088de56ccSmrg		case " $oldobjs " in
1094188de56ccSmrg		*[\ /]"$newobj "*) ;;
1094288de56ccSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
1094388de56ccSmrg		esac
1094488de56ccSmrg	      done
1094588de56ccSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10946e9fcaa8aSmrg	      func_append oldobjs " $gentop/$newobj"
1094788de56ccSmrg	      ;;
10948e9fcaa8aSmrg	    *) func_append oldobjs " $obj" ;;
1094988de56ccSmrg	    esac
109501ab64890Smrg	  done
109512e9c7c8cSmrg	fi
10952eb411b4bSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953eb411b4bSmrg	tool_oldlib=$func_to_tool_file_result
1095488de56ccSmrg	eval cmds=\"$old_archive_cmds\"
10955b4ee4795Smrg
1095688de56ccSmrg	func_len " $cmds"
1095788de56ccSmrg	len=$func_len_result
1095888de56ccSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1095988de56ccSmrg	  cmds=$old_archive_cmds
10960e9fcaa8aSmrg	elif test -n "$archiver_list_spec"; then
10961e9fcaa8aSmrg	  func_verbose "using command file archive linking..."
10962e9fcaa8aSmrg	  for obj in $oldobjs
10963e9fcaa8aSmrg	  do
10964e9fcaa8aSmrg	    func_to_tool_file "$obj"
10965e9fcaa8aSmrg	    $ECHO "$func_to_tool_file_result"
10966e9fcaa8aSmrg	  done > $output_objdir/$libname.libcmd
10967e9fcaa8aSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10968e9fcaa8aSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10969e9fcaa8aSmrg	  cmds=$old_archive_cmds
1097088de56ccSmrg	else
1097188de56ccSmrg	  # the command line is too long to link in one step, link in parts
1097288de56ccSmrg	  func_verbose "using piecewise archive linking..."
1097388de56ccSmrg	  save_RANLIB=$RANLIB
1097488de56ccSmrg	  RANLIB=:
1097588de56ccSmrg	  objlist=
1097688de56ccSmrg	  concat_cmds=
1097788de56ccSmrg	  save_oldobjs=$oldobjs
1097888de56ccSmrg	  oldobjs=
1097988de56ccSmrg	  # Is there a better way of finding the last object in the list?
1098088de56ccSmrg	  for obj in $save_oldobjs
1098188de56ccSmrg	  do
1098288de56ccSmrg	    last_oldobj=$obj
1098388de56ccSmrg	  done
1098488de56ccSmrg	  eval test_cmds=\"$old_archive_cmds\"
1098588de56ccSmrg	  func_len " $test_cmds"
1098688de56ccSmrg	  len0=$func_len_result
1098788de56ccSmrg	  len=$len0
1098888de56ccSmrg	  for obj in $save_oldobjs
1098988de56ccSmrg	  do
1099088de56ccSmrg	    func_len " $obj"
1099188de56ccSmrg	    func_arith $len + $func_len_result
1099288de56ccSmrg	    len=$func_arith_result
1099388de56ccSmrg	    func_append objlist " $obj"
1099488de56ccSmrg	    if test "$len" -lt "$max_cmd_len"; then
1099588de56ccSmrg	      :
1099688de56ccSmrg	    else
1099788de56ccSmrg	      # the above command should be used before it gets too long
1099888de56ccSmrg	      oldobjs=$objlist
10999862bcd1aSmrg	      if test "$obj" = "$last_oldobj"; then
1100088de56ccSmrg		RANLIB=$save_RANLIB
1100188de56ccSmrg	      fi
1100288de56ccSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003862bcd1aSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
1100488de56ccSmrg	      objlist=
1100588de56ccSmrg	      len=$len0
1100688de56ccSmrg	    fi
1100788de56ccSmrg	  done
1100888de56ccSmrg	  RANLIB=$save_RANLIB
1100988de56ccSmrg	  oldobjs=$objlist
11010862bcd1aSmrg	  if test -z "$oldobjs"; then
1101188de56ccSmrg	    eval cmds=\"\$concat_cmds\"
1101288de56ccSmrg	  else
1101388de56ccSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
1101488de56ccSmrg	  fi
1101588de56ccSmrg	fi
1101688de56ccSmrg      fi
1101788de56ccSmrg      func_execute_cmds "$cmds" 'exit $?'
110181ab64890Smrg    done
110191ab64890Smrg
1102088de56ccSmrg    test -n "$generated" && \
1102188de56ccSmrg      func_show_eval "${RM}r$generated"
110221ab64890Smrg
1102388de56ccSmrg    # Now create the libtool archive.
1102488de56ccSmrg    case $output in
1102588de56ccSmrg    *.la)
1102688de56ccSmrg      old_library=
11027862bcd1aSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
1102888de56ccSmrg      func_verbose "creating $output"
110292e9c7c8cSmrg
1103088de56ccSmrg      # Preserve any variables that may affect compiler behavior
1103188de56ccSmrg      for var in $variables_saved_for_relink; do
1103288de56ccSmrg	if eval test -z \"\${$var+set}\"; then
1103388de56ccSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1103488de56ccSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
1103588de56ccSmrg	  relink_command="$var=; export $var; $relink_command"
11036b4ee4795Smrg	else
11037e9628295Smrg	  func_quote_arg pretty,unquoted "$var_value"
11038e9628295Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039b4ee4795Smrg	fi
1104088de56ccSmrg      done
1104188de56ccSmrg      # Quote the link command for shipping.
11042e9628295Smrg      func_quote eval cd "`pwd`"
11043e9628295Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044e9628295Smrg      func_quote_arg pretty,unquoted "$relink_command"
11045e9628295Smrg      relink_command=$func_quote_arg_unquoted_result
11046862bcd1aSmrg      if test yes = "$hardcode_automatic"; then
1104788de56ccSmrg	relink_command=
1104888de56ccSmrg      fi
110491ab64890Smrg
1105088de56ccSmrg      # Only create the output if not a dry run.
1105188de56ccSmrg      $opt_dry_run || {
1105288de56ccSmrg	for installed in no yes; do
11053862bcd1aSmrg	  if test yes = "$installed"; then
1105488de56ccSmrg	    if test -z "$install_libdir"; then
1105588de56ccSmrg	      break
1105688de56ccSmrg	    fi
11057862bcd1aSmrg	    output=$output_objdir/${outputname}i
1105888de56ccSmrg	    # Replace all uninstalled libtool libraries with the installed ones
1105988de56ccSmrg	    newdependency_libs=
1106088de56ccSmrg	    for deplib in $dependency_libs; do
1106188de56ccSmrg	      case $deplib in
1106288de56ccSmrg	      *.la)
1106388de56ccSmrg		func_basename "$deplib"
11064862bcd1aSmrg		name=$func_basename_result
11065eb411b4bSmrg		func_resolve_sysroot "$deplib"
11066862bcd1aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
1106788de56ccSmrg		test -z "$libdir" && \
11068862bcd1aSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11069e9fcaa8aSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11070e9fcaa8aSmrg		;;
11071e9fcaa8aSmrg	      -L*)
11072e9fcaa8aSmrg		func_stripname -L '' "$deplib"
11073e9fcaa8aSmrg		func_replace_sysroot "$func_stripname_result"
11074e9fcaa8aSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
1107588de56ccSmrg		;;
11076e9fcaa8aSmrg	      -R*)
11077e9fcaa8aSmrg		func_stripname -R '' "$deplib"
11078e9fcaa8aSmrg		func_replace_sysroot "$func_stripname_result"
11079e9fcaa8aSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080e9fcaa8aSmrg		;;
11081e9fcaa8aSmrg	      *) func_append newdependency_libs " $deplib" ;;
1108288de56ccSmrg	      esac
1108388de56ccSmrg	    done
11084862bcd1aSmrg	    dependency_libs=$newdependency_libs
1108588de56ccSmrg	    newdlfiles=
1108688de56ccSmrg
1108788de56ccSmrg	    for lib in $dlfiles; do
1108888de56ccSmrg	      case $lib in
1108988de56ccSmrg	      *.la)
1109088de56ccSmrg	        func_basename "$lib"
11091862bcd1aSmrg		name=$func_basename_result
11092862bcd1aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1109388de56ccSmrg		test -z "$libdir" && \
11094862bcd1aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11095e9fcaa8aSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
1109688de56ccSmrg		;;
11097e9fcaa8aSmrg	      *) func_append newdlfiles " $lib" ;;
1109888de56ccSmrg	      esac
1109988de56ccSmrg	    done
11100862bcd1aSmrg	    dlfiles=$newdlfiles
1110188de56ccSmrg	    newdlprefiles=
1110288de56ccSmrg	    for lib in $dlprefiles; do
1110388de56ccSmrg	      case $lib in
1110488de56ccSmrg	      *.la)
1110588de56ccSmrg		# Only pass preopened files to the pseudo-archive (for
1110688de56ccSmrg		# eventual linking with the app. that links it) if we
1110788de56ccSmrg		# didn't already link the preopened objects directly into
1110888de56ccSmrg		# the library:
1110988de56ccSmrg		func_basename "$lib"
11110862bcd1aSmrg		name=$func_basename_result
11111862bcd1aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1111288de56ccSmrg		test -z "$libdir" && \
11113862bcd1aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11114e9fcaa8aSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
1111588de56ccSmrg		;;
1111688de56ccSmrg	      esac
1111788de56ccSmrg	    done
11118862bcd1aSmrg	    dlprefiles=$newdlprefiles
1111988de56ccSmrg	  else
1112088de56ccSmrg	    newdlfiles=
1112188de56ccSmrg	    for lib in $dlfiles; do
1112288de56ccSmrg	      case $lib in
11123862bcd1aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1112488de56ccSmrg		*) abs=`pwd`"/$lib" ;;
1112588de56ccSmrg	      esac
11126e9fcaa8aSmrg	      func_append newdlfiles " $abs"
1112788de56ccSmrg	    done
11128862bcd1aSmrg	    dlfiles=$newdlfiles
1112988de56ccSmrg	    newdlprefiles=
1113088de56ccSmrg	    for lib in $dlprefiles; do
1113188de56ccSmrg	      case $lib in
11132862bcd1aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1113388de56ccSmrg		*) abs=`pwd`"/$lib" ;;
1113488de56ccSmrg	      esac
11135e9fcaa8aSmrg	      func_append newdlprefiles " $abs"
1113688de56ccSmrg	    done
11137862bcd1aSmrg	    dlprefiles=$newdlprefiles
1113888de56ccSmrg	  fi
1113988de56ccSmrg	  $RM $output
1114088de56ccSmrg	  # place dlname in correct position for cygwin
11141e9fcaa8aSmrg	  # In fact, it would be nice if we could use this code for all target
11142e9fcaa8aSmrg	  # systems that can't hard-code library paths into their executables
11143e9fcaa8aSmrg	  # and that have no shared library path variable independent of PATH,
11144e9fcaa8aSmrg	  # but it turns out we can't easily determine that from inspecting
11145e9fcaa8aSmrg	  # libtool variables, so we have to hard-code the OSs to which it
11146e9fcaa8aSmrg	  # applies here; at the moment, that means platforms that use the PE
11147e9fcaa8aSmrg	  # object format with DLL files.  See the long comment at the top of
11148e9fcaa8aSmrg	  # tests/bindir.at for full details.
1114988de56ccSmrg	  tdlname=$dlname
1115088de56ccSmrg	  case $host,$output,$installed,$module,$dlname in
11151e9fcaa8aSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11152e9fcaa8aSmrg	      # If a -bindir argument was supplied, place the dll there.
11153862bcd1aSmrg	      if test -n "$bindir"; then
11154e9fcaa8aSmrg		func_relative_path "$install_libdir" "$bindir"
11155862bcd1aSmrg		tdlname=$func_relative_path_result/$dlname
11156e9fcaa8aSmrg	      else
11157e9fcaa8aSmrg		# Otherwise fall back on heuristic.
11158e9fcaa8aSmrg		tdlname=../bin/$dlname
11159e9fcaa8aSmrg	      fi
11160e9fcaa8aSmrg	      ;;
1116188de56ccSmrg	  esac
1116288de56ccSmrg	  $ECHO > $output "\
1116388de56ccSmrg# $outputname - a libtool library file
11164862bcd1aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
1116588de56ccSmrg#
1116688de56ccSmrg# Please DO NOT delete this file!
1116788de56ccSmrg# It is necessary for linking the library.
111681ab64890Smrg
1116988de56ccSmrg# The name that we can dlopen(3).
1117088de56ccSmrgdlname='$tdlname'
111711ab64890Smrg
1117288de56ccSmrg# Names of this library.
1117388de56ccSmrglibrary_names='$library_names'
111741ab64890Smrg
1117588de56ccSmrg# The name of the static archive.
1117688de56ccSmrgold_library='$old_library'
111771ab64890Smrg
11178862bcd1aSmrg# Linker flags that cannot go in dependency_libs.
1117988de56ccSmrginherited_linker_flags='$new_inherited_linker_flags'
111801ab64890Smrg
1118188de56ccSmrg# Libraries that this one depends upon.
1118288de56ccSmrgdependency_libs='$dependency_libs'
111831ab64890Smrg
1118488de56ccSmrg# Names of additional weak libraries provided by this library
1118588de56ccSmrgweak_library_names='$weak_libs'
111861ab64890Smrg
1118788de56ccSmrg# Version information for $libname.
1118888de56ccSmrgcurrent=$current
1118988de56ccSmrgage=$age
1119088de56ccSmrgrevision=$revision
111911ab64890Smrg
1119288de56ccSmrg# Is this an already installed library?
1119388de56ccSmrginstalled=$installed
111941ab64890Smrg
1119588de56ccSmrg# Should we warn about portability when linking against -modules?
1119688de56ccSmrgshouldnotlink=$module
111971ab64890Smrg
1119888de56ccSmrg# Files to dlopen/dlpreopen
1119988de56ccSmrgdlopen='$dlfiles'
1120088de56ccSmrgdlpreopen='$dlprefiles'
112011ab64890Smrg
1120288de56ccSmrg# Directory that this library needs to be installed in:
1120388de56ccSmrglibdir='$install_libdir'"
11204862bcd1aSmrg	  if test no,yes = "$installed,$need_relink"; then
1120588de56ccSmrg	    $ECHO >> $output "\
1120688de56ccSmrgrelink_command=\"$relink_command\""
1120788de56ccSmrg	  fi
1120888de56ccSmrg	done
1120988de56ccSmrg      }
112101ab64890Smrg
1121188de56ccSmrg      # Do a symbolic link so that the libtool archive can be found in
1121288de56ccSmrg      # LD_LIBRARY_PATH before the program is installed.
1121388de56ccSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
1121488de56ccSmrg      ;;
1121588de56ccSmrg    esac
1121688de56ccSmrg    exit $EXIT_SUCCESS
1121788de56ccSmrg}
11218b4ee4795Smrg
11219862bcd1aSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220862bcd1aSmrg  func_mode_link ${1+"$@"}
11221862bcd1aSmrgfi
112221ab64890Smrg
112231ab64890Smrg
1122488de56ccSmrg# func_mode_uninstall arg...
1122588de56ccSmrgfunc_mode_uninstall ()
1122688de56ccSmrg{
11227862bcd1aSmrg    $debug_cmd
11228862bcd1aSmrg
11229862bcd1aSmrg    RM=$nonopt
112301ab64890Smrg    files=
11231862bcd1aSmrg    rmforce=false
112321ab64890Smrg    exit_status=0
112331ab64890Smrg
112341ab64890Smrg    # This variable tells wrapper scripts just to set variables rather
112351ab64890Smrg    # than running their programs.
11236862bcd1aSmrg    libtool_install_magic=$magic
112371ab64890Smrg
112381ab64890Smrg    for arg
112391ab64890Smrg    do
112401ab64890Smrg      case $arg in
11241862bcd1aSmrg      -f) func_append RM " $arg"; rmforce=: ;;
11242e9fcaa8aSmrg      -*) func_append RM " $arg" ;;
11243e9fcaa8aSmrg      *) func_append files " $arg" ;;
112441ab64890Smrg      esac
112451ab64890Smrg    done
112461ab64890Smrg
1124788de56ccSmrg    test -z "$RM" && \
1124888de56ccSmrg      func_fatal_help "you must specify an RM program"
112491ab64890Smrg
112501ab64890Smrg    rmdirs=
112511ab64890Smrg
112521ab64890Smrg    for file in $files; do
1125388de56ccSmrg      func_dirname "$file" "" "."
11254862bcd1aSmrg      dir=$func_dirname_result
11255862bcd1aSmrg      if test . = "$dir"; then
11256862bcd1aSmrg	odir=$objdir
112571ab64890Smrg      else
11258862bcd1aSmrg	odir=$dir/$objdir
112591ab64890Smrg      fi
1126088de56ccSmrg      func_basename "$file"
11261862bcd1aSmrg      name=$func_basename_result
11262862bcd1aSmrg      test uninstall = "$opt_mode" && odir=$dir
112631ab64890Smrg
11264e9fcaa8aSmrg      # Remember odir for removal later, being careful to avoid duplicates
11265862bcd1aSmrg      if test clean = "$opt_mode"; then
112661ab64890Smrg	case " $rmdirs " in
11267e9fcaa8aSmrg	  *" $odir "*) ;;
11268e9fcaa8aSmrg	  *) func_append rmdirs " $odir" ;;
112691ab64890Smrg	esac
112701ab64890Smrg      fi
112711ab64890Smrg
112721ab64890Smrg      # Don't error if the file doesn't exist and rm -f was used.
1127388de56ccSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
1127488de56ccSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
1127588de56ccSmrg	 test -f "$file"; then
112761ab64890Smrg	:
112771ab64890Smrg      elif test -d "$file"; then
112781ab64890Smrg	exit_status=1
112791ab64890Smrg	continue
11280862bcd1aSmrg      elif $rmforce; then
112811ab64890Smrg	continue
112821ab64890Smrg      fi
112831ab64890Smrg
11284862bcd1aSmrg      rmfiles=$file
112851ab64890Smrg
112861ab64890Smrg      case $name in
112871ab64890Smrg      *.la)
112881ab64890Smrg	# Possibly a libtool archive, so verify it.
1128988de56ccSmrg	if func_lalib_p "$file"; then
1129088de56ccSmrg	  func_source $dir/$name
112911ab64890Smrg
112921ab64890Smrg	  # Delete the libtool libraries and symlinks.
112931ab64890Smrg	  for n in $library_names; do
11294e9fcaa8aSmrg	    func_append rmfiles " $odir/$n"
112951ab64890Smrg	  done
11296e9fcaa8aSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
112971ab64890Smrg
11298862bcd1aSmrg	  case $opt_mode in
112991ab64890Smrg	  clean)
11300e9fcaa8aSmrg	    case " $library_names " in
113011ab64890Smrg	    *" $dlname "*) ;;
11302e9fcaa8aSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
113031ab64890Smrg	    esac
11304e9fcaa8aSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
113051ab64890Smrg	    ;;
113061ab64890Smrg	  uninstall)
113071ab64890Smrg	    if test -n "$library_names"; then
113081ab64890Smrg	      # Do each command in the postuninstall commands.
11309862bcd1aSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
113101ab64890Smrg	    fi
113111ab64890Smrg
113121ab64890Smrg	    if test -n "$old_library"; then
113131ab64890Smrg	      # Do each command in the old_postuninstall commands.
11314862bcd1aSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
113151ab64890Smrg	    fi
113161ab64890Smrg	    # FIXME: should reinstall the best remaining shared library.
113171ab64890Smrg	    ;;
113181ab64890Smrg	  esac
113191ab64890Smrg	fi
113201ab64890Smrg	;;
113211ab64890Smrg
113221ab64890Smrg      *.lo)
113231ab64890Smrg	# Possibly a libtool object, so verify it.
1132488de56ccSmrg	if func_lalib_p "$file"; then
113251ab64890Smrg
113261ab64890Smrg	  # Read the .lo file
1132788de56ccSmrg	  func_source $dir/$name
113281ab64890Smrg
113291ab64890Smrg	  # Add PIC object to the list of files to remove.
11330862bcd1aSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11331e9fcaa8aSmrg	    func_append rmfiles " $dir/$pic_object"
113321ab64890Smrg	  fi
113331ab64890Smrg
113341ab64890Smrg	  # Add non-PIC object to the list of files to remove.
11335862bcd1aSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11336e9fcaa8aSmrg	    func_append rmfiles " $dir/$non_pic_object"
113371ab64890Smrg	  fi
113381ab64890Smrg	fi
113391ab64890Smrg	;;
113401ab64890Smrg
113411ab64890Smrg      *)
11342862bcd1aSmrg	if test clean = "$opt_mode"; then
113431ab64890Smrg	  noexename=$name
113441ab64890Smrg	  case $file in
113451ab64890Smrg	  *.exe)
1134688de56ccSmrg	    func_stripname '' '.exe' "$file"
1134788de56ccSmrg	    file=$func_stripname_result
1134888de56ccSmrg	    func_stripname '' '.exe' "$name"
1134988de56ccSmrg	    noexename=$func_stripname_result
113501ab64890Smrg	    # $file with .exe has already been added to rmfiles,
113511ab64890Smrg	    # add $file without .exe
11352e9fcaa8aSmrg	    func_append rmfiles " $file"
113531ab64890Smrg	    ;;
113541ab64890Smrg	  esac
113551ab64890Smrg	  # Do a test to see if this is a libtool program.
1135688de56ccSmrg	  if func_ltwrapper_p "$file"; then
1135788de56ccSmrg	    if func_ltwrapper_executable_p "$file"; then
1135888de56ccSmrg	      func_ltwrapper_scriptname "$file"
1135988de56ccSmrg	      relink_command=
1136088de56ccSmrg	      func_source $func_ltwrapper_scriptname_result
11361e9fcaa8aSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
1136288de56ccSmrg	    else
1136388de56ccSmrg	      relink_command=
1136488de56ccSmrg	      func_source $dir/$noexename
1136588de56ccSmrg	    fi
113661ab64890Smrg
113671ab64890Smrg	    # note $name still contains .exe if it was in $file originally
113681ab64890Smrg	    # as does the version of $file that was added into $rmfiles
11369862bcd1aSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370862bcd1aSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11371e9fcaa8aSmrg	      func_append rmfiles " $odir/lt-$name"
113721ab64890Smrg	    fi
11373862bcd1aSmrg	    if test "X$noexename" != "X$name"; then
11374862bcd1aSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
113751ab64890Smrg	    fi
113761ab64890Smrg	  fi
113771ab64890Smrg	fi
113781ab64890Smrg	;;
113791ab64890Smrg      esac
1138088de56ccSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
113811ab64890Smrg    done
113821ab64890Smrg
11383862bcd1aSmrg    # Try to remove the $objdir's in the directories where we deleted files
113841ab64890Smrg    for dir in $rmdirs; do
113851ab64890Smrg      if test -d "$dir"; then
1138688de56ccSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
113871ab64890Smrg      fi
113881ab64890Smrg    done
113891ab64890Smrg
113901ab64890Smrg    exit $exit_status
1139188de56ccSmrg}
113921ab64890Smrg
11393862bcd1aSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394862bcd1aSmrg  func_mode_uninstall ${1+"$@"}
11395862bcd1aSmrgfi
113962e9c7c8cSmrg
11397e9fcaa8aSmrgtest -z "$opt_mode" && {
11398862bcd1aSmrg  help=$generic_help
1139988de56ccSmrg  func_fatal_help "you must specify a MODE"
1140088de56ccSmrg}
1140188de56ccSmrg
1140288de56ccSmrgtest -z "$exec_cmd" && \
11403862bcd1aSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
114041ab64890Smrg
114051ab64890Smrgif test -n "$exec_cmd"; then
1140688de56ccSmrg  eval exec "$exec_cmd"
114071ab64890Smrg  exit $EXIT_FAILURE
114081ab64890Smrgfi
114091ab64890Smrg
1141088de56ccSmrgexit $exit_status
114111ab64890Smrg
114121ab64890Smrg
114131ab64890Smrg# The TAGs below are defined such that we never get into a situation
11414862bcd1aSmrg# where we disable both kinds of libraries.  Given conflicting
114151ab64890Smrg# choices, we go for a static library, that is the most portable,
114161ab64890Smrg# since we can't tell whether shared libraries were disabled because
114171ab64890Smrg# the user asked for that or because the platform doesn't support
114181ab64890Smrg# them.  This is particularly important on AIX, because we don't
114191ab64890Smrg# support having both static and shared libraries enabled at the same
114201ab64890Smrg# time on that platform, so we default to a shared-only configuration.
114211ab64890Smrg# If a disable-shared tag is given, we'll fallback to a static-only
114221ab64890Smrg# configuration.  But we'll never go from static-only to shared-only.
114231ab64890Smrg
114241ab64890Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
1142588de56ccSmrgbuild_libtool_libs=no
1142688de56ccSmrgbuild_old_libs=yes
114271ab64890Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
114281ab64890Smrg
114291ab64890Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
1143088de56ccSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
114311ab64890Smrg# ### END LIBTOOL TAG CONFIG: disable-static
114321ab64890Smrg
114331ab64890Smrg# Local Variables:
114341ab64890Smrg# mode:shell-script
114351ab64890Smrg# sh-indentation:2
114361ab64890Smrg# End:
11437