1d87a3195Smrg#! /usr/bin/env sh
2eca46af7Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3d87a3195Smrg##               by inline-source v2019-02-19.15
42378475aSmrg
5d87a3195Smrg# libtool (GNU libtool) 2.4.7
6eca46af7Smrg# Provide generalized library-building support services.
72378475aSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
82378475aSmrg
9d87a3195Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
102378475aSmrg# This is free software; see the source for copying conditions.  There is NO
112378475aSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
122378475aSmrg
132378475aSmrg# GNU Libtool is free software; you can redistribute it and/or modify
1495b296d0Smrg# it under the terms of the GNU General Public License as published by
1595b296d0Smrg# the Free Software Foundation; either version 2 of the License, or
1695b296d0Smrg# (at your option) any later version.
1795b296d0Smrg#
182378475aSmrg# As a special exception to the GNU General Public License,
192378475aSmrg# if you distribute this file as part of a program or library that
202378475aSmrg# is built using GNU Libtool, you may include this file under the
212378475aSmrg# same distribution terms that you use for the rest of that program.
222378475aSmrg#
232378475aSmrg# GNU Libtool is distributed in the hope that it will be useful, but
2495b296d0Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
2595b296d0Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2695b296d0Smrg# General Public License for more details.
2795b296d0Smrg#
2895b296d0Smrg# You should have received a copy of the GNU General Public License
29eca46af7Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30e6f085baSmrg
3195b296d0Smrg
3214330f12SmrgPROGRAM=libtool
3395b296d0SmrgPACKAGE=libtool
34d87a3195SmrgVERSION=2.4.7
35d87a3195Smrgpackage_revision=2.4.7
36ff89ac2bSmrg
37eca46af7Smrg
38eca46af7Smrg## ------ ##
39eca46af7Smrg## Usage. ##
40eca46af7Smrg## ------ ##
41eca46af7Smrg
42eca46af7Smrg# Run './libtool --help' for help with using this script from the
43eca46af7Smrg# command line.
44eca46af7Smrg
45eca46af7Smrg
46eca46af7Smrg## ------------------------------- ##
47eca46af7Smrg## User overridable command paths. ##
48eca46af7Smrg## ------------------------------- ##
49eca46af7Smrg
50eca46af7Smrg# After configure completes, it has a better idea of some of the
51eca46af7Smrg# shell tools we need than the defaults used by the functions shared
52eca46af7Smrg# with bootstrap, so set those here where they can still be over-
53eca46af7Smrg# ridden by the user, but otherwise take precedence.
54eca46af7Smrg
55eca46af7Smrg: ${AUTOCONF="autoconf"}
56eca46af7Smrg: ${AUTOMAKE="automake"}
57eca46af7Smrg
58eca46af7Smrg
59eca46af7Smrg## -------------------------- ##
60eca46af7Smrg## Source external libraries. ##
61eca46af7Smrg## -------------------------- ##
62eca46af7Smrg
63eca46af7Smrg# Much of our low-level functionality needs to be sourced from external
64eca46af7Smrg# libraries, which are installed to $pkgauxdir.
65eca46af7Smrg
66eca46af7Smrg# Set a version string for this script.
67d87a3195Smrgscriptversion=2019-02-19.15; # UTC
68eca46af7Smrg
69eca46af7Smrg# General shell script boiler plate, and helper functions.
70eca46af7Smrg# Written by Gary V. Vaughan, 2004
71eca46af7Smrg
72d87a3195Smrg# This is free software.  There is NO warranty; not even for
73d87a3195Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74d87a3195Smrg#
75d87a3195Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76d87a3195Smrg#
77d87a3195Smrg# This file is dual licensed under the terms of the MIT license
78d87a3195Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79d87a3195Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80d87a3195Smrg# these licenses when using or redistributing this software or any of
81d87a3195Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82d87a3195Smrg# included in the Bootstrap distribution for the full license texts.
83eca46af7Smrg
84d87a3195Smrg# Please report bugs or propose patches to:
85d87a3195Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86eca46af7Smrg
87eca46af7Smrg
88eca46af7Smrg## ------ ##
89eca46af7Smrg## Usage. ##
90eca46af7Smrg## ------ ##
91eca46af7Smrg
92eca46af7Smrg# Evaluate this file near the top of your script to gain access to
93eca46af7Smrg# the functions and variables defined here:
94eca46af7Smrg#
95eca46af7Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96eca46af7Smrg#
97eca46af7Smrg# If you need to override any of the default environment variable
98eca46af7Smrg# settings, do that before evaluating this file.
99eca46af7Smrg
100eca46af7Smrg
101eca46af7Smrg## -------------------- ##
102eca46af7Smrg## Shell normalisation. ##
103eca46af7Smrg## -------------------- ##
104eca46af7Smrg
105eca46af7Smrg# Some shells need a little help to be as Bourne compatible as possible.
106eca46af7Smrg# Before doing anything else, make sure all that help has been provided!
107eca46af7Smrg
108eca46af7SmrgDUALCASE=1; export DUALCASE # for MKS sh
109eca46af7Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110ff89ac2bSmrg  emulate sh
111ff89ac2bSmrg  NULLCMD=:
112eca46af7Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113ff89ac2bSmrg  # is contrary to our usage.  Disable this feature.
114ff89ac2bSmrg  alias -g '${1+"$@"}'='"$@"'
11595b296d0Smrg  setopt NO_GLOB_SUBST
116ff89ac2bSmrgelse
117eca46af7Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
11895b296d0Smrgfi
11914330f12Smrg
120eca46af7Smrg# NLS nuisances: We save the old values in case they are required later.
121eca46af7Smrg_G_user_locale=
122eca46af7Smrg_G_safe_locale=
123eca46af7Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124ff89ac2bSmrgdo
125eca46af7Smrg  eval "if test set = \"\${$_G_var+set}\"; then
126eca46af7Smrg          save_$_G_var=\$$_G_var
127eca46af7Smrg          $_G_var=C
128eca46af7Smrg	  export $_G_var
129eca46af7Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130eca46af7Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131ff89ac2bSmrg	fi"
132ff89ac2bSmrgdone
133d87a3195Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134d87a3195Smrg# in case the environment reset is needed later and the $save_* variant is not
135d87a3195Smrg# defined (see the code above).
136d87a3195SmrgLC_ALL=C
137d87a3195SmrgLANGUAGE=C
138d87a3195Smrgexport LANGUAGE LC_ALL
1392378475aSmrg
140eca46af7Smrg# Make sure IFS has a sensible default
141eca46af7Smrgsp=' '
142eca46af7Smrgnl='
143eca46af7Smrg'
144eca46af7SmrgIFS="$sp	$nl"
145eca46af7Smrg
146eca46af7Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
147eca46af7Smrgif test "${PATH_SEPARATOR+set}" != set; then
148eca46af7Smrg  PATH_SEPARATOR=:
149eca46af7Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150eca46af7Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151eca46af7Smrg      PATH_SEPARATOR=';'
152eca46af7Smrg  }
153eca46af7Smrgfi
1542378475aSmrg
1552378475aSmrg
156d87a3195Smrg# func_unset VAR
157d87a3195Smrg# --------------
158d87a3195Smrg# Portably unset VAR.
159d87a3195Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160d87a3195Smrg# status if VAR is already unset, which might be problematic if the
161d87a3195Smrg# statement is used at the end of a function (thus poisoning its return
162d87a3195Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163d87a3195Smrg# the script in this case).
164d87a3195Smrgfunc_unset ()
165d87a3195Smrg{
166d87a3195Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167d87a3195Smrg}
168d87a3195Smrg
169d87a3195Smrg
170d87a3195Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171d87a3195Smrgfunc_unset CDPATH
172d87a3195Smrg
173d87a3195Smrg# Make sure ${,E,F}GREP behave sanely.
174d87a3195Smrgfunc_unset GREP_OPTIONS
175d87a3195Smrg
1762378475aSmrg
177eca46af7Smrg## ------------------------- ##
178eca46af7Smrg## Locate command utilities. ##
179eca46af7Smrg## ------------------------- ##
180eca46af7Smrg
181eca46af7Smrg
182eca46af7Smrg# func_executable_p FILE
183eca46af7Smrg# ----------------------
184eca46af7Smrg# Check that FILE is an executable regular file.
185eca46af7Smrgfunc_executable_p ()
186eca46af7Smrg{
187eca46af7Smrg    test -f "$1" && test -x "$1"
188eca46af7Smrg}
189eca46af7Smrg
190eca46af7Smrg
191eca46af7Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192eca46af7Smrg# --------------------------------------------
193eca46af7Smrg# Search for either a program that responds to --version with output
194eca46af7Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195eca46af7Smrg# trying all the directories in PATH with each of the elements of
196eca46af7Smrg# PROGS_LIST.
197eca46af7Smrg#
198eca46af7Smrg# CHECK_FUNC should accept the path to a candidate program, and
199eca46af7Smrg# set $func_check_prog_result if it truncates its output less than
200eca46af7Smrg# $_G_path_prog_max characters.
201eca46af7Smrgfunc_path_progs ()
202eca46af7Smrg{
203eca46af7Smrg    _G_progs_list=$1
204eca46af7Smrg    _G_check_func=$2
205eca46af7Smrg    _G_PATH=${3-"$PATH"}
206eca46af7Smrg
207eca46af7Smrg    _G_path_prog_max=0
208eca46af7Smrg    _G_path_prog_found=false
20989b0dc75Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210eca46af7Smrg    for _G_dir in $_G_PATH; do
211eca46af7Smrg      IFS=$_G_save_IFS
212eca46af7Smrg      test -z "$_G_dir" && _G_dir=.
213eca46af7Smrg      for _G_prog_name in $_G_progs_list; do
214eca46af7Smrg        for _exeext in '' .EXE; do
215eca46af7Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216eca46af7Smrg          func_executable_p "$_G_path_prog" || continue
217eca46af7Smrg          case `"$_G_path_prog" --version 2>&1` in
218eca46af7Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219eca46af7Smrg            *)     $_G_check_func $_G_path_prog
220eca46af7Smrg		   func_path_progs_result=$func_check_prog_result
221eca46af7Smrg		   ;;
222eca46af7Smrg          esac
223eca46af7Smrg          $_G_path_prog_found && break 3
224eca46af7Smrg        done
225eca46af7Smrg      done
226eca46af7Smrg    done
227eca46af7Smrg    IFS=$_G_save_IFS
228eca46af7Smrg    test -z "$func_path_progs_result" && {
229eca46af7Smrg      echo "no acceptable sed could be found in \$PATH" >&2
230eca46af7Smrg      exit 1
231eca46af7Smrg    }
232eca46af7Smrg}
233eca46af7Smrg
234eca46af7Smrg
235eca46af7Smrg# We want to be able to use the functions in this file before configure
236eca46af7Smrg# has figured out where the best binaries are kept, which means we have
237eca46af7Smrg# to search for them ourselves - except when the results are already set
238eca46af7Smrg# where we skip the searches.
239eca46af7Smrg
240eca46af7Smrg# Unless the user overrides by setting SED, search the path for either GNU
241eca46af7Smrg# sed, or the sed that truncates its output the least.
242eca46af7Smrgtest -z "$SED" && {
243eca46af7Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244eca46af7Smrg  for _G_i in 1 2 3 4 5 6 7; do
245eca46af7Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246eca46af7Smrg  done
247eca46af7Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248eca46af7Smrg  _G_sed_script=
249eca46af7Smrg
250eca46af7Smrg  func_check_prog_sed ()
251eca46af7Smrg  {
252eca46af7Smrg    _G_path_prog=$1
253eca46af7Smrg
254eca46af7Smrg    _G_count=0
255eca46af7Smrg    printf 0123456789 >conftest.in
256eca46af7Smrg    while :
257eca46af7Smrg    do
258eca46af7Smrg      cat conftest.in conftest.in >conftest.tmp
259eca46af7Smrg      mv conftest.tmp conftest.in
260eca46af7Smrg      cp conftest.in conftest.nl
261eca46af7Smrg      echo '' >> conftest.nl
262eca46af7Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263eca46af7Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264eca46af7Smrg      _G_count=`expr $_G_count + 1`
265eca46af7Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266eca46af7Smrg        # Best one so far, save it but keep looking for a better one
267eca46af7Smrg        func_check_prog_result=$_G_path_prog
268eca46af7Smrg        _G_path_prog_max=$_G_count
269eca46af7Smrg      fi
270eca46af7Smrg      # 10*(2^10) chars as input seems more than enough
271eca46af7Smrg      test 10 -lt "$_G_count" && break
272eca46af7Smrg    done
273eca46af7Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274eca46af7Smrg  }
275eca46af7Smrg
276d87a3195Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277eca46af7Smrg  rm -f conftest.sed
278eca46af7Smrg  SED=$func_path_progs_result
279eca46af7Smrg}
280eca46af7Smrg
281eca46af7Smrg
282eca46af7Smrg# Unless the user overrides by setting GREP, search the path for either GNU
283eca46af7Smrg# grep, or the grep that truncates its output the least.
284eca46af7Smrgtest -z "$GREP" && {
285eca46af7Smrg  func_check_prog_grep ()
286eca46af7Smrg  {
287eca46af7Smrg    _G_path_prog=$1
288eca46af7Smrg
289eca46af7Smrg    _G_count=0
290eca46af7Smrg    _G_path_prog_max=0
291eca46af7Smrg    printf 0123456789 >conftest.in
292eca46af7Smrg    while :
293eca46af7Smrg    do
294eca46af7Smrg      cat conftest.in conftest.in >conftest.tmp
295eca46af7Smrg      mv conftest.tmp conftest.in
296eca46af7Smrg      cp conftest.in conftest.nl
297eca46af7Smrg      echo 'GREP' >> conftest.nl
298eca46af7Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299eca46af7Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300eca46af7Smrg      _G_count=`expr $_G_count + 1`
301eca46af7Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302eca46af7Smrg        # Best one so far, save it but keep looking for a better one
303eca46af7Smrg        func_check_prog_result=$_G_path_prog
304eca46af7Smrg        _G_path_prog_max=$_G_count
305eca46af7Smrg      fi
306eca46af7Smrg      # 10*(2^10) chars as input seems more than enough
307eca46af7Smrg      test 10 -lt "$_G_count" && break
308eca46af7Smrg    done
309eca46af7Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310eca46af7Smrg  }
311eca46af7Smrg
312d87a3195Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313eca46af7Smrg  GREP=$func_path_progs_result
314eca46af7Smrg}
315eca46af7Smrg
316eca46af7Smrg
317eca46af7Smrg## ------------------------------- ##
318eca46af7Smrg## User overridable command paths. ##
319eca46af7Smrg## ------------------------------- ##
320eca46af7Smrg
321eca46af7Smrg# All uppercase variable names are used for environment variables.  These
322eca46af7Smrg# variables can be overridden by the user before calling a script that
323eca46af7Smrg# uses them if a suitable command of that name is not already available
324eca46af7Smrg# in the command search PATH.
3252378475aSmrg
3262378475aSmrg: ${CP="cp -f"}
327eca46af7Smrg: ${ECHO="printf %s\n"}
328eca46af7Smrg: ${EGREP="$GREP -E"}
329eca46af7Smrg: ${FGREP="$GREP -F"}
3302378475aSmrg: ${LN_S="ln -s"}
3312378475aSmrg: ${MAKE="make"}
3322378475aSmrg: ${MKDIR="mkdir"}
3332378475aSmrg: ${MV="mv -f"}
3342378475aSmrg: ${RM="rm -f"}
3352378475aSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
33695b296d0Smrg
3372378475aSmrg
338eca46af7Smrg## -------------------- ##
339eca46af7Smrg## Useful sed snippets. ##
340eca46af7Smrg## -------------------- ##
34114330f12Smrg
342eca46af7Smrgsed_dirname='s|/[^/]*$||'
343eca46af7Smrgsed_basename='s|^.*/||'
34414330f12Smrg
345eca46af7Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
346eca46af7Smrg# metacharacters that are still active within double-quoted strings.
347eca46af7Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
34814330f12Smrg
349eca46af7Smrg# Same as above, but do not quote variable references.
350eca46af7Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
35114330f12Smrg
352eca46af7Smrg# Sed substitution that turns a string into a regex matching for the
353eca46af7Smrg# string literally.
354eca46af7Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
35514330f12Smrg
356eca46af7Smrg# Sed substitution that converts a w32 file name or path
357eca46af7Smrg# that contains forward slashes, into one that contains
358eca46af7Smrg# (escaped) backslashes.  A very naive implementation.
359eca46af7Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360eca46af7Smrg
361eca46af7Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362eca46af7Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363eca46af7Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364eca46af7Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
365eca46af7Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366eca46af7Smrg_G_bs='\\'
367eca46af7Smrg_G_bs2='\\\\'
368eca46af7Smrg_G_bs4='\\\\\\\\'
369eca46af7Smrg_G_dollar='\$'
370eca46af7Smrgsed_double_backslash="\
371eca46af7Smrg  s/$_G_bs4/&\\
372eca46af7Smrg/g
373eca46af7Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374eca46af7Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375eca46af7Smrg  s/\n//g"
37614330f12Smrg
377d87a3195Smrg# require_check_ifs_backslash
378d87a3195Smrg# ---------------------------
379d87a3195Smrg# Check if we can use backslash as IFS='\' separator, and set
380d87a3195Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381d87a3195Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382d87a3195Smrgfunc_require_check_ifs_backslash ()
383d87a3195Smrg{
384d87a3195Smrg  _G_save_IFS=$IFS
385d87a3195Smrg  IFS='\'
386d87a3195Smrg  _G_check_ifs_backshlash='a\\b'
387d87a3195Smrg  for _G_i in $_G_check_ifs_backshlash
388d87a3195Smrg  do
389d87a3195Smrg  case $_G_i in
390d87a3195Smrg  a)
391d87a3195Smrg    check_ifs_backshlash_broken=false
392d87a3195Smrg    ;;
393d87a3195Smrg  '')
394d87a3195Smrg    break
395d87a3195Smrg    ;;
396d87a3195Smrg  *)
397d87a3195Smrg    check_ifs_backshlash_broken=:
398d87a3195Smrg    break
399d87a3195Smrg    ;;
400d87a3195Smrg  esac
401d87a3195Smrg  done
402d87a3195Smrg  IFS=$_G_save_IFS
403d87a3195Smrg  require_check_ifs_backslash=:
404d87a3195Smrg}
405d87a3195Smrg
40614330f12Smrg
407eca46af7Smrg## ----------------- ##
408eca46af7Smrg## Global variables. ##
409eca46af7Smrg## ----------------- ##
41014330f12Smrg
411eca46af7Smrg# Except for the global variables explicitly listed below, the following
412eca46af7Smrg# functions in the '^func_' namespace, and the '^require_' namespace
413eca46af7Smrg# variables initialised in the 'Resource management' section, sourcing
414eca46af7Smrg# this file will not pollute your global namespace with anything
415eca46af7Smrg# else. There's no portable way to scope variables in Bourne shell
416eca46af7Smrg# though, so actually running these functions will sometimes place
417eca46af7Smrg# results into a variable named after the function, and often use
418eca46af7Smrg# temporary variables in the '^_G_' namespace. If you are careful to
419eca46af7Smrg# avoid using those namespaces casually in your sourcing script, things
420eca46af7Smrg# should continue to work as you expect. And, of course, you can freely
421eca46af7Smrg# overwrite any of the functions or variables defined here before
422eca46af7Smrg# calling anything to customize them.
42314330f12Smrg
424eca46af7SmrgEXIT_SUCCESS=0
425eca46af7SmrgEXIT_FAILURE=1
426eca46af7SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427eca46af7SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
42839713583Smrg
429eca46af7Smrg# Allow overriding, eg assuming that you follow the convention of
430eca46af7Smrg# putting '$debug_cmd' at the start of all your functions, you can get
431eca46af7Smrg# bash to show function call trace with:
432eca46af7Smrg#
433eca46af7Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434eca46af7Smrgdebug_cmd=${debug_cmd-":"}
435eca46af7Smrgexit_cmd=:
4362378475aSmrg
437eca46af7Smrg# By convention, finish your script with:
438eca46af7Smrg#
439eca46af7Smrg#    exit $exit_status
440eca46af7Smrg#
441eca46af7Smrg# so that you can set exit_status to non-zero if you want to indicate
442eca46af7Smrg# something went wrong during execution without actually bailing out at
443eca46af7Smrg# the point of failure.
444eca46af7Smrgexit_status=$EXIT_SUCCESS
44514330f12Smrg
446eca46af7Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447eca46af7Smrg# is ksh but when the shell is invoked as "sh" and the current value of
448eca46af7Smrg# the _XPG environment variable is not equal to 1 (one), the special
449eca46af7Smrg# positional parameter $0, within a function call, is the name of the
450eca46af7Smrg# function.
451eca46af7Smrgprogpath=$0
4522378475aSmrg
453eca46af7Smrg# The name of this program.
454eca46af7Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
4552378475aSmrg
456eca46af7Smrg# Make sure we have an absolute progpath for reexecution:
4572378475aSmrgcase $progpath in
4582378475aSmrg  [\\/]*|[A-Za-z]:\\*) ;;
4592378475aSmrg  *[\\/]*)
460eca46af7Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
4612378475aSmrg     progdir=`cd "$progdir" && pwd`
462eca46af7Smrg     progpath=$progdir/$progname
4632378475aSmrg     ;;
4642378475aSmrg  *)
465eca46af7Smrg     _G_IFS=$IFS
466eca46af7Smrg     IFS=${PATH_SEPARATOR-:}
4672378475aSmrg     for progdir in $PATH; do
468eca46af7Smrg       IFS=$_G_IFS
4692378475aSmrg       test -x "$progdir/$progname" && break
4702378475aSmrg     done
471eca46af7Smrg     IFS=$_G_IFS
4722378475aSmrg     test -n "$progdir" || progdir=`pwd`
473eca46af7Smrg     progpath=$progdir/$progname
4742378475aSmrg     ;;
4752378475aSmrgesac
4762378475aSmrg
4772378475aSmrg
478eca46af7Smrg## ----------------- ##
479eca46af7Smrg## Standard options. ##
480eca46af7Smrg## ----------------- ##
48114330f12Smrg
482eca46af7Smrg# The following options affect the operation of the functions defined
483eca46af7Smrg# below, and should be set appropriately depending on run-time para-
484eca46af7Smrg# meters passed on the command line.
4852378475aSmrg
4862378475aSmrgopt_dry_run=false
4872378475aSmrgopt_quiet=false
4882378475aSmrgopt_verbose=false
4892378475aSmrg
490eca46af7Smrg# Categories 'all' and 'none' are always available.  Append any others
491eca46af7Smrg# you will pass as the first argument to func_warning from your own
492eca46af7Smrg# code.
493eca46af7Smrgwarning_categories=
4942378475aSmrg
495eca46af7Smrg# By default, display warnings according to 'opt_warning_types'.  Set
496eca46af7Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497eca46af7Smrg# treat the next displayed warning as a fatal error.
498eca46af7Smrgwarning_func=func_warn_and_continue
4992378475aSmrg
500eca46af7Smrg# Set to 'all' to display all warnings, 'none' to suppress all
501eca46af7Smrg# warnings, or a space delimited list of some subset of
502eca46af7Smrg# 'warning_categories' to display only the listed warnings.
503eca46af7Smrgopt_warning_types=all
5042378475aSmrg
50514330f12Smrg
506eca46af7Smrg## -------------------- ##
507eca46af7Smrg## Resource management. ##
508eca46af7Smrg## -------------------- ##
5092378475aSmrg
510eca46af7Smrg# This section contains definitions for functions that each ensure a
511eca46af7Smrg# particular resource (a file, or a non-empty configuration variable for
512eca46af7Smrg# example) is available, and if appropriate to extract default values
513eca46af7Smrg# from pertinent package files. Call them using their associated
514eca46af7Smrg# 'require_*' variable to ensure that they are executed, at most, once.
515eca46af7Smrg#
516eca46af7Smrg# It's entirely deliberate that calling these functions can set
517eca46af7Smrg# variables that don't obey the namespace limitations obeyed by the rest
518eca46af7Smrg# of this file, in order that that they be as useful as possible to
519eca46af7Smrg# callers.
5202378475aSmrg
5212378475aSmrg
522eca46af7Smrg# require_term_colors
523eca46af7Smrg# -------------------
524eca46af7Smrg# Allow display of bold text on terminals that support it.
525eca46af7Smrgrequire_term_colors=func_require_term_colors
526eca46af7Smrgfunc_require_term_colors ()
5272378475aSmrg{
528eca46af7Smrg    $debug_cmd
529eca46af7Smrg
530eca46af7Smrg    test -t 1 && {
531eca46af7Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532eca46af7Smrg      # precedence, because most terminfo databases neglect to describe
533eca46af7Smrg      # whether color sequences are supported.
534eca46af7Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535eca46af7Smrg
536eca46af7Smrg      if test 1 = "$USE_ANSI_COLORS"; then
537eca46af7Smrg        # Standard ANSI escape sequences
538eca46af7Smrg        tc_reset='[0m'
539eca46af7Smrg        tc_bold='[1m';   tc_standout='[7m'
540eca46af7Smrg        tc_red='[31m';   tc_green='[32m'
541eca46af7Smrg        tc_blue='[34m';  tc_cyan='[36m'
542eca46af7Smrg      else
543eca46af7Smrg        # Otherwise trust the terminfo database after all.
544eca46af7Smrg        test -n "`tput sgr0 2>/dev/null`" && {
545eca46af7Smrg          tc_reset=`tput sgr0`
546eca46af7Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547eca46af7Smrg          tc_standout=$tc_bold
548eca46af7Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549eca46af7Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550eca46af7Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551eca46af7Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552eca46af7Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553eca46af7Smrg        }
554eca46af7Smrg      fi
555eca46af7Smrg    }
5562378475aSmrg
557eca46af7Smrg    require_term_colors=:
5582378475aSmrg}
5592378475aSmrg
5602378475aSmrg
561eca46af7Smrg## ----------------- ##
562eca46af7Smrg## Function library. ##
563eca46af7Smrg## ----------------- ##
564eca46af7Smrg
565eca46af7Smrg# This section contains a variety of useful functions to call in your
566eca46af7Smrg# scripts. Take note of the portable wrappers for features provided by
567eca46af7Smrg# some modern shells, which will fall back to slower equivalents on
568eca46af7Smrg# less featureful shells.
569eca46af7Smrg
570eca46af7Smrg
571eca46af7Smrg# func_append VAR VALUE
572eca46af7Smrg# ---------------------
573eca46af7Smrg# Append VALUE onto the existing contents of VAR.
574eca46af7Smrg
575eca46af7Smrg  # We should try to minimise forks, especially on Windows where they are
576eca46af7Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577eca46af7Smrg  # being used:
578eca46af7Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579eca46af7Smrg    : ${_G_HAVE_ARITH_OP="yes"}
580eca46af7Smrg    : ${_G_HAVE_XSI_OPS="yes"}
581eca46af7Smrg    # The += operator was introduced in bash 3.1
582eca46af7Smrg    case $BASH_VERSION in
583eca46af7Smrg      [12].* | 3.0 | 3.0*) ;;
584eca46af7Smrg      *)
585eca46af7Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586eca46af7Smrg        ;;
587eca46af7Smrg    esac
588eca46af7Smrg  fi
589eca46af7Smrg
590eca46af7Smrg  # _G_HAVE_PLUSEQ_OP
591eca46af7Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
592eca46af7Smrg  # useable or anything else if it does not work.
593eca46af7Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594eca46af7Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595eca46af7Smrg    && _G_HAVE_PLUSEQ_OP=yes
596eca46af7Smrg
597eca46af7Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598eca46af7Smrgthen
599eca46af7Smrg  # This is an XSI compatible shell, allowing a faster implementation...
600eca46af7Smrg  eval 'func_append ()
601eca46af7Smrg  {
602eca46af7Smrg    $debug_cmd
603eca46af7Smrg
604eca46af7Smrg    eval "$1+=\$2"
605eca46af7Smrg  }'
606eca46af7Smrgelse
607eca46af7Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608eca46af7Smrg  func_append ()
609eca46af7Smrg  {
610eca46af7Smrg    $debug_cmd
611eca46af7Smrg
612eca46af7Smrg    eval "$1=\$$1\$2"
613eca46af7Smrg  }
614eca46af7Smrgfi
615eca46af7Smrg
616eca46af7Smrg
617eca46af7Smrg# func_append_quoted VAR VALUE
618eca46af7Smrg# ----------------------------
619eca46af7Smrg# Quote VALUE and append to the end of shell variable VAR, separated
620eca46af7Smrg# by a space.
621eca46af7Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622eca46af7Smrg  eval 'func_append_quoted ()
623eca46af7Smrg  {
624eca46af7Smrg    $debug_cmd
625eca46af7Smrg
626d87a3195Smrg    func_quote_arg pretty "$2"
627d87a3195Smrg    eval "$1+=\\ \$func_quote_arg_result"
628eca46af7Smrg  }'
629eca46af7Smrgelse
630eca46af7Smrg  func_append_quoted ()
631eca46af7Smrg  {
632eca46af7Smrg    $debug_cmd
633eca46af7Smrg
634d87a3195Smrg    func_quote_arg pretty "$2"
635d87a3195Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636eca46af7Smrg  }
637eca46af7Smrgfi
638eca46af7Smrg
639eca46af7Smrg
640eca46af7Smrg# func_append_uniq VAR VALUE
641eca46af7Smrg# --------------------------
642eca46af7Smrg# Append unique VALUE onto the existing contents of VAR, assuming
643eca46af7Smrg# entries are delimited by the first character of VALUE.  For example:
644eca46af7Smrg#
645eca46af7Smrg#   func_append_uniq options " --another-option option-argument"
646eca46af7Smrg#
647eca46af7Smrg# will only append to $options if " --another-option option-argument "
648eca46af7Smrg# is not already present somewhere in $options already (note spaces at
649eca46af7Smrg# each end implied by leading space in second argument).
650eca46af7Smrgfunc_append_uniq ()
651eca46af7Smrg{
652eca46af7Smrg    $debug_cmd
653eca46af7Smrg
654eca46af7Smrg    eval _G_current_value='`$ECHO $'$1'`'
655eca46af7Smrg    _G_delim=`expr "$2" : '\(.\)'`
656eca46af7Smrg
657eca46af7Smrg    case $_G_delim$_G_current_value$_G_delim in
658eca46af7Smrg      *"$2$_G_delim"*) ;;
659eca46af7Smrg      *) func_append "$@" ;;
660eca46af7Smrg    esac
661eca46af7Smrg}
662eca46af7Smrg
663eca46af7Smrg
664eca46af7Smrg# func_arith TERM...
665eca46af7Smrg# ------------------
666eca46af7Smrg# Set func_arith_result to the result of evaluating TERMs.
667eca46af7Smrg  test -z "$_G_HAVE_ARITH_OP" \
668eca46af7Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669eca46af7Smrg    && _G_HAVE_ARITH_OP=yes
670eca46af7Smrg
671eca46af7Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
672eca46af7Smrg  eval 'func_arith ()
673eca46af7Smrg  {
674eca46af7Smrg    $debug_cmd
675eca46af7Smrg
676eca46af7Smrg    func_arith_result=$(( $* ))
677eca46af7Smrg  }'
678eca46af7Smrgelse
679eca46af7Smrg  func_arith ()
680eca46af7Smrg  {
681eca46af7Smrg    $debug_cmd
682eca46af7Smrg
683eca46af7Smrg    func_arith_result=`expr "$@"`
684eca46af7Smrg  }
685eca46af7Smrgfi
686eca46af7Smrg
687eca46af7Smrg
688eca46af7Smrg# func_basename FILE
689eca46af7Smrg# ------------------
690eca46af7Smrg# Set func_basename_result to FILE with everything up to and including
691eca46af7Smrg# the last / stripped.
692eca46af7Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
693eca46af7Smrg  # If this shell supports suffix pattern removal, then use it to avoid
694eca46af7Smrg  # forking. Hide the definitions single quotes in case the shell chokes
695eca46af7Smrg  # on unsupported syntax...
696eca46af7Smrg  _b='func_basename_result=${1##*/}'
697eca46af7Smrg  _d='case $1 in
698eca46af7Smrg        */*) func_dirname_result=${1%/*}$2 ;;
699eca46af7Smrg        *  ) func_dirname_result=$3        ;;
700eca46af7Smrg      esac'
701eca46af7Smrg
702eca46af7Smrgelse
703eca46af7Smrg  # ...otherwise fall back to using sed.
704eca46af7Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705eca46af7Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706eca46af7Smrg      if test "X$func_dirname_result" = "X$1"; then
707eca46af7Smrg        func_dirname_result=$3
708eca46af7Smrg      else
709eca46af7Smrg        func_append func_dirname_result "$2"
710eca46af7Smrg      fi'
711eca46af7Smrgfi
712eca46af7Smrg
713eca46af7Smrgeval 'func_basename ()
714eca46af7Smrg{
715eca46af7Smrg    $debug_cmd
716eca46af7Smrg
717eca46af7Smrg    '"$_b"'
718eca46af7Smrg}'
719eca46af7Smrg
720eca46af7Smrg
721eca46af7Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722eca46af7Smrg# -------------------------------------------
723eca46af7Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724eca46af7Smrg# otherwise set result to NONDIR_REPLACEMENT.
725eca46af7Smrgeval 'func_dirname ()
726eca46af7Smrg{
727eca46af7Smrg    $debug_cmd
728eca46af7Smrg
729eca46af7Smrg    '"$_d"'
730eca46af7Smrg}'
731eca46af7Smrg
732eca46af7Smrg
733eca46af7Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734eca46af7Smrg# --------------------------------------------------------
735eca46af7Smrg# Perform func_basename and func_dirname in a single function
736eca46af7Smrg# call:
737eca46af7Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738eca46af7Smrg#             add APPEND to the result, otherwise set result
739eca46af7Smrg#             to NONDIR_REPLACEMENT.
740eca46af7Smrg#             value returned in "$func_dirname_result"
741eca46af7Smrg#   basename: Compute filename of FILE.
742eca46af7Smrg#             value retuned in "$func_basename_result"
743eca46af7Smrg# For efficiency, we do not delegate to the functions above but instead
744eca46af7Smrg# duplicate the functionality here.
745eca46af7Smrgeval 'func_dirname_and_basename ()
746eca46af7Smrg{
747eca46af7Smrg    $debug_cmd
748eca46af7Smrg
749eca46af7Smrg    '"$_b"'
750eca46af7Smrg    '"$_d"'
751eca46af7Smrg}'
752eca46af7Smrg
753eca46af7Smrg
754eca46af7Smrg# func_echo ARG...
755eca46af7Smrg# ----------------
756eca46af7Smrg# Echo program name prefixed message.
757eca46af7Smrgfunc_echo ()
758eca46af7Smrg{
759eca46af7Smrg    $debug_cmd
760eca46af7Smrg
761eca46af7Smrg    _G_message=$*
762eca46af7Smrg
763eca46af7Smrg    func_echo_IFS=$IFS
764eca46af7Smrg    IFS=$nl
765eca46af7Smrg    for _G_line in $_G_message; do
766eca46af7Smrg      IFS=$func_echo_IFS
767eca46af7Smrg      $ECHO "$progname: $_G_line"
768eca46af7Smrg    done
769eca46af7Smrg    IFS=$func_echo_IFS
770eca46af7Smrg}
771eca46af7Smrg
772eca46af7Smrg
773eca46af7Smrg# func_echo_all ARG...
774eca46af7Smrg# --------------------
775eca46af7Smrg# Invoke $ECHO with all args, space-separated.
776eca46af7Smrgfunc_echo_all ()
777eca46af7Smrg{
778eca46af7Smrg    $ECHO "$*"
779eca46af7Smrg}
780eca46af7Smrg
781eca46af7Smrg
782eca46af7Smrg# func_echo_infix_1 INFIX ARG...
783eca46af7Smrg# ------------------------------
784eca46af7Smrg# Echo program name, followed by INFIX on the first line, with any
785eca46af7Smrg# additional lines not showing INFIX.
786eca46af7Smrgfunc_echo_infix_1 ()
787eca46af7Smrg{
788eca46af7Smrg    $debug_cmd
789eca46af7Smrg
790eca46af7Smrg    $require_term_colors
791eca46af7Smrg
792eca46af7Smrg    _G_infix=$1; shift
793eca46af7Smrg    _G_indent=$_G_infix
794eca46af7Smrg    _G_prefix="$progname: $_G_infix: "
795eca46af7Smrg    _G_message=$*
796eca46af7Smrg
797eca46af7Smrg    # Strip color escape sequences before counting printable length
798eca46af7Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799eca46af7Smrg    do
800eca46af7Smrg      test -n "$_G_tc" && {
801eca46af7Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802eca46af7Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803eca46af7Smrg      }
804eca46af7Smrg    done
805eca46af7Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806eca46af7Smrg
807eca46af7Smrg    func_echo_infix_1_IFS=$IFS
808eca46af7Smrg    IFS=$nl
809eca46af7Smrg    for _G_line in $_G_message; do
810eca46af7Smrg      IFS=$func_echo_infix_1_IFS
811eca46af7Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812eca46af7Smrg      _G_prefix=$_G_indent
813eca46af7Smrg    done
814eca46af7Smrg    IFS=$func_echo_infix_1_IFS
815eca46af7Smrg}
816eca46af7Smrg
817eca46af7Smrg
818eca46af7Smrg# func_error ARG...
819eca46af7Smrg# -----------------
820eca46af7Smrg# Echo program name prefixed message to standard error.
821eca46af7Smrgfunc_error ()
822eca46af7Smrg{
823eca46af7Smrg    $debug_cmd
824eca46af7Smrg
825eca46af7Smrg    $require_term_colors
826eca46af7Smrg
827eca46af7Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828eca46af7Smrg}
829eca46af7Smrg
830eca46af7Smrg
831eca46af7Smrg# func_fatal_error ARG...
832eca46af7Smrg# -----------------------
833eca46af7Smrg# Echo program name prefixed message to standard error, and exit.
834eca46af7Smrgfunc_fatal_error ()
835eca46af7Smrg{
836eca46af7Smrg    $debug_cmd
837eca46af7Smrg
838eca46af7Smrg    func_error "$*"
839eca46af7Smrg    exit $EXIT_FAILURE
840eca46af7Smrg}
841eca46af7Smrg
842eca46af7Smrg
843eca46af7Smrg# func_grep EXPRESSION FILENAME
844eca46af7Smrg# -----------------------------
8452378475aSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
8462378475aSmrgfunc_grep ()
8472378475aSmrg{
848eca46af7Smrg    $debug_cmd
849eca46af7Smrg
8502378475aSmrg    $GREP "$1" "$2" >/dev/null 2>&1
8512378475aSmrg}
8522378475aSmrg
8532378475aSmrg
854eca46af7Smrg# func_len STRING
855eca46af7Smrg# ---------------
856eca46af7Smrg# Set func_len_result to the length of STRING. STRING may not
857eca46af7Smrg# start with a hyphen.
858eca46af7Smrg  test -z "$_G_HAVE_XSI_OPS" \
859eca46af7Smrg    && (eval 'x=a/b/c;
860eca46af7Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861eca46af7Smrg    && _G_HAVE_XSI_OPS=yes
862eca46af7Smrg
863eca46af7Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
864eca46af7Smrg  eval 'func_len ()
865eca46af7Smrg  {
866eca46af7Smrg    $debug_cmd
867eca46af7Smrg
868eca46af7Smrg    func_len_result=${#1}
869eca46af7Smrg  }'
870eca46af7Smrgelse
871eca46af7Smrg  func_len ()
872eca46af7Smrg  {
873eca46af7Smrg    $debug_cmd
874eca46af7Smrg
875eca46af7Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876eca46af7Smrg  }
877eca46af7Smrgfi
878eca46af7Smrg
879eca46af7Smrg
880eca46af7Smrg# func_mkdir_p DIRECTORY-PATH
881eca46af7Smrg# ---------------------------
8822378475aSmrg# Make sure the entire path to DIRECTORY-PATH is available.
8832378475aSmrgfunc_mkdir_p ()
8842378475aSmrg{
885eca46af7Smrg    $debug_cmd
8862378475aSmrg
887eca46af7Smrg    _G_directory_path=$1
888eca46af7Smrg    _G_dir_list=
8892378475aSmrg
890eca46af7Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891eca46af7Smrg
892eca46af7Smrg      # Protect directory names starting with '-'
893eca46af7Smrg      case $_G_directory_path in
894eca46af7Smrg        -*) _G_directory_path=./$_G_directory_path ;;
8952378475aSmrg      esac
8962378475aSmrg
8972378475aSmrg      # While some portion of DIR does not yet exist...
898eca46af7Smrg      while test ! -d "$_G_directory_path"; do
8992378475aSmrg        # ...make a list in topmost first order.  Use a colon delimited
9002378475aSmrg	# list incase some portion of path contains whitespace.
901eca46af7Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
9022378475aSmrg
9032378475aSmrg        # If the last portion added has no slash in it, the list is done
904eca46af7Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
9052378475aSmrg
9062378475aSmrg        # ...otherwise throw away the child directory and loop
907eca46af7Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
9082378475aSmrg      done
909eca46af7Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
9102378475aSmrg
911eca46af7Smrg      func_mkdir_p_IFS=$IFS; IFS=:
912eca46af7Smrg      for _G_dir in $_G_dir_list; do
913eca46af7Smrg	IFS=$func_mkdir_p_IFS
914eca46af7Smrg        # mkdir can fail with a 'File exist' error if two processes
9152378475aSmrg        # try to create one of the directories concurrently.  Don't
9162378475aSmrg        # stop in that case!
917eca46af7Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
9182378475aSmrg      done
919eca46af7Smrg      IFS=$func_mkdir_p_IFS
9202378475aSmrg
9212378475aSmrg      # Bail out if we (or some other process) failed to create a directory.
922eca46af7Smrg      test -d "$_G_directory_path" || \
923eca46af7Smrg        func_fatal_error "Failed to create '$1'"
9242378475aSmrg    fi
9252378475aSmrg}
92695b296d0Smrg
92795b296d0Smrg
928eca46af7Smrg# func_mktempdir [BASENAME]
929eca46af7Smrg# -------------------------
93095b296d0Smrg# Make a temporary directory that won't clash with other running
93195b296d0Smrg# libtool processes, and avoids race conditions if possible.  If
932eca46af7Smrg# given, BASENAME is the basename for that directory.
93395b296d0Smrgfunc_mktempdir ()
93495b296d0Smrg{
935eca46af7Smrg    $debug_cmd
936eca46af7Smrg
937eca46af7Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
93895b296d0Smrg
939eca46af7Smrg    if test : = "$opt_dry_run"; then
94095b296d0Smrg      # Return a directory name, but don't create it in dry-run mode
941eca46af7Smrg      _G_tmpdir=$_G_template-$$
94295b296d0Smrg    else
94395b296d0Smrg
94495b296d0Smrg      # If mktemp works, use that first and foremost
945eca46af7Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
94695b296d0Smrg
947eca46af7Smrg      if test ! -d "$_G_tmpdir"; then
9482378475aSmrg        # Failing that, at least try and use $RANDOM to avoid a race
949eca46af7Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
95095b296d0Smrg
951eca46af7Smrg        func_mktempdir_umask=`umask`
9522378475aSmrg        umask 0077
953eca46af7Smrg        $MKDIR "$_G_tmpdir"
954eca46af7Smrg        umask $func_mktempdir_umask
95595b296d0Smrg      fi
95695b296d0Smrg
95795b296d0Smrg      # If we're not in dry-run mode, bomb out on failure
958eca46af7Smrg      test -d "$_G_tmpdir" || \
959eca46af7Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960eca46af7Smrg    fi
961eca46af7Smrg
962eca46af7Smrg    $ECHO "$_G_tmpdir"
963eca46af7Smrg}
964eca46af7Smrg
965eca46af7Smrg
966eca46af7Smrg# func_normal_abspath PATH
967eca46af7Smrg# ------------------------
968eca46af7Smrg# Remove doubled-up and trailing slashes, "." path components,
969eca46af7Smrg# and cancel out any ".." path components in PATH after making
970eca46af7Smrg# it an absolute path.
971eca46af7Smrgfunc_normal_abspath ()
972eca46af7Smrg{
973eca46af7Smrg    $debug_cmd
974eca46af7Smrg
975eca46af7Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
976eca46af7Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977eca46af7Smrg    _G_pathcdr='s|^/[^/]*||'
978eca46af7Smrg    _G_removedotparts=':dotsl
979eca46af7Smrg		s|/\./|/|g
980eca46af7Smrg		t dotsl
981eca46af7Smrg		s|/\.$|/|'
982eca46af7Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
983eca46af7Smrg    _G_finalslash='s|/*$|/|'
984eca46af7Smrg
985eca46af7Smrg    # Start from root dir and reassemble the path.
986eca46af7Smrg    func_normal_abspath_result=
987eca46af7Smrg    func_normal_abspath_tpath=$1
988eca46af7Smrg    func_normal_abspath_altnamespace=
989eca46af7Smrg    case $func_normal_abspath_tpath in
990eca46af7Smrg      "")
991eca46af7Smrg        # Empty path, that just means $cwd.
992eca46af7Smrg        func_stripname '' '/' "`pwd`"
993eca46af7Smrg        func_normal_abspath_result=$func_stripname_result
994eca46af7Smrg        return
995eca46af7Smrg        ;;
996eca46af7Smrg      # The next three entries are used to spot a run of precisely
997eca46af7Smrg      # two leading slashes without using negated character classes;
998eca46af7Smrg      # we take advantage of case's first-match behaviour.
999eca46af7Smrg      ///*)
1000eca46af7Smrg        # Unusual form of absolute path, do nothing.
1001eca46af7Smrg        ;;
1002eca46af7Smrg      //*)
1003eca46af7Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004eca46af7Smrg        # and for example Cygwin uses it to access remote file shares
1005eca46af7Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006eca46af7Smrg        func_normal_abspath_altnamespace=/
1007eca46af7Smrg        ;;
1008eca46af7Smrg      /*)
1009eca46af7Smrg        # Absolute path, do nothing.
1010eca46af7Smrg        ;;
1011eca46af7Smrg      *)
1012eca46af7Smrg        # Relative path, prepend $cwd.
1013eca46af7Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014eca46af7Smrg        ;;
1015eca46af7Smrg    esac
1016eca46af7Smrg
1017eca46af7Smrg    # Cancel out all the simple stuff to save iterations.  We also want
1018eca46af7Smrg    # the path to end with a slash for ease of parsing, so make sure
1019eca46af7Smrg    # there is one (and only one) here.
1020eca46af7Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021eca46af7Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022eca46af7Smrg    while :; do
1023eca46af7Smrg      # Processed it all yet?
1024eca46af7Smrg      if test / = "$func_normal_abspath_tpath"; then
1025eca46af7Smrg        # If we ascended to the root using ".." the result may be empty now.
1026eca46af7Smrg        if test -z "$func_normal_abspath_result"; then
1027eca46af7Smrg          func_normal_abspath_result=/
1028eca46af7Smrg        fi
1029eca46af7Smrg        break
1030eca46af7Smrg      fi
1031eca46af7Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032eca46af7Smrg          -e "$_G_pathcar"`
1033eca46af7Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034eca46af7Smrg          -e "$_G_pathcdr"`
1035eca46af7Smrg      # Figure out what to do with it
1036eca46af7Smrg      case $func_normal_abspath_tcomponent in
1037eca46af7Smrg        "")
1038eca46af7Smrg          # Trailing empty path component, ignore it.
1039eca46af7Smrg          ;;
1040eca46af7Smrg        ..)
1041eca46af7Smrg          # Parent dir; strip last assembled component from result.
1042eca46af7Smrg          func_dirname "$func_normal_abspath_result"
1043eca46af7Smrg          func_normal_abspath_result=$func_dirname_result
1044eca46af7Smrg          ;;
1045eca46af7Smrg        *)
1046eca46af7Smrg          # Actual path component, append it.
1047eca46af7Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048eca46af7Smrg          ;;
1049eca46af7Smrg      esac
1050eca46af7Smrg    done
1051eca46af7Smrg    # Restore leading double-slash if one was found on entry.
1052eca46af7Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053eca46af7Smrg}
1054eca46af7Smrg
1055eca46af7Smrg
1056eca46af7Smrg# func_notquiet ARG...
1057eca46af7Smrg# --------------------
1058eca46af7Smrg# Echo program name prefixed message only when not in quiet mode.
1059eca46af7Smrgfunc_notquiet ()
1060eca46af7Smrg{
1061eca46af7Smrg    $debug_cmd
1062eca46af7Smrg
1063eca46af7Smrg    $opt_quiet || func_echo ${1+"$@"}
1064eca46af7Smrg
1065eca46af7Smrg    # A bug in bash halts the script if the last line of a function
1066eca46af7Smrg    # fails when set -e is in force, so we need another command to
1067eca46af7Smrg    # work around that:
1068eca46af7Smrg    :
1069eca46af7Smrg}
1070eca46af7Smrg
1071eca46af7Smrg
1072eca46af7Smrg# func_relative_path SRCDIR DSTDIR
1073eca46af7Smrg# --------------------------------
1074eca46af7Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075eca46af7Smrgfunc_relative_path ()
1076eca46af7Smrg{
1077eca46af7Smrg    $debug_cmd
1078eca46af7Smrg
1079eca46af7Smrg    func_relative_path_result=
1080eca46af7Smrg    func_normal_abspath "$1"
1081eca46af7Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082eca46af7Smrg    func_normal_abspath "$2"
1083eca46af7Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1084eca46af7Smrg
1085eca46af7Smrg    # Ascend the tree starting from libdir
1086eca46af7Smrg    while :; do
1087eca46af7Smrg      # check if we have found a prefix of bindir
1088eca46af7Smrg      case $func_relative_path_tbindir in
1089eca46af7Smrg        $func_relative_path_tlibdir)
1090eca46af7Smrg          # found an exact match
1091eca46af7Smrg          func_relative_path_tcancelled=
1092eca46af7Smrg          break
1093eca46af7Smrg          ;;
1094eca46af7Smrg        $func_relative_path_tlibdir*)
1095eca46af7Smrg          # found a matching prefix
1096eca46af7Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097eca46af7Smrg          func_relative_path_tcancelled=$func_stripname_result
1098eca46af7Smrg          if test -z "$func_relative_path_result"; then
1099eca46af7Smrg            func_relative_path_result=.
1100eca46af7Smrg          fi
1101eca46af7Smrg          break
1102eca46af7Smrg          ;;
1103eca46af7Smrg        *)
1104eca46af7Smrg          func_dirname $func_relative_path_tlibdir
1105eca46af7Smrg          func_relative_path_tlibdir=$func_dirname_result
1106eca46af7Smrg          if test -z "$func_relative_path_tlibdir"; then
1107eca46af7Smrg            # Have to descend all the way to the root!
1108eca46af7Smrg            func_relative_path_result=../$func_relative_path_result
1109eca46af7Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110eca46af7Smrg            break
1111eca46af7Smrg          fi
1112eca46af7Smrg          func_relative_path_result=../$func_relative_path_result
1113eca46af7Smrg          ;;
1114eca46af7Smrg      esac
1115eca46af7Smrg    done
1116eca46af7Smrg
1117eca46af7Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1118eca46af7Smrg    func_stripname '' '/' "$func_relative_path_result"
1119eca46af7Smrg    func_relative_path_result=$func_stripname_result
1120eca46af7Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121eca46af7Smrg    if test -n "$func_stripname_result"; then
1122eca46af7Smrg      func_append func_relative_path_result "/$func_stripname_result"
1123eca46af7Smrg    fi
1124eca46af7Smrg
1125eca46af7Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126eca46af7Smrg    if test -n "$func_relative_path_result"; then
1127eca46af7Smrg      func_stripname './' '' "$func_relative_path_result"
1128eca46af7Smrg      func_relative_path_result=$func_stripname_result
112995b296d0Smrg    fi
113095b296d0Smrg
1131eca46af7Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132eca46af7Smrg
1133eca46af7Smrg    :
1134eca46af7Smrg}
1135eca46af7Smrg
1136eca46af7Smrg
1137d87a3195Smrg# func_quote_portable EVAL ARG
1138d87a3195Smrg# ----------------------------
1139d87a3195Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140d87a3195Smrg# keep attention to performance here so we as much as possible try to avoid
1141d87a3195Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142d87a3195Smrgfunc_quote_portable ()
1143eca46af7Smrg{
1144eca46af7Smrg    $debug_cmd
1145eca46af7Smrg
1146d87a3195Smrg    $require_check_ifs_backslash
1147d87a3195Smrg
1148d87a3195Smrg    func_quote_portable_result=$2
1149d87a3195Smrg
1150d87a3195Smrg    # one-time-loop (easy break)
1151d87a3195Smrg    while true
1152d87a3195Smrg    do
1153d87a3195Smrg      if $1; then
1154d87a3195Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155d87a3195Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156d87a3195Smrg        break
1157eca46af7Smrg      fi
1158eca46af7Smrg
1159d87a3195Smrg      # Quote for eval.
1160d87a3195Smrg      case $func_quote_portable_result in
1161d87a3195Smrg        *[\\\`\"\$]*)
1162d87a3195Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163d87a3195Smrg          # contains the shell wildcard characters.
1164d87a3195Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165d87a3195Smrg            :*|*[\[\*\?]*)
1166d87a3195Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167d87a3195Smrg                  | $SED "$sed_quote_subst"`
1168d87a3195Smrg              break
1169d87a3195Smrg              ;;
1170d87a3195Smrg          esac
1171d87a3195Smrg
1172d87a3195Smrg          func_quote_portable_old_IFS=$IFS
1173d87a3195Smrg          for _G_char in '\' '`' '"' '$'
1174d87a3195Smrg          do
1175d87a3195Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176d87a3195Smrg            set start "" ""
1177d87a3195Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178d87a3195Smrg            IFS=$_G_char
1179d87a3195Smrg            for _G_part in $func_quote_portable_result
1180d87a3195Smrg            do
1181d87a3195Smrg              case $1 in
1182d87a3195Smrg              quote)
1183d87a3195Smrg                func_append func_quote_portable_result "$3$2"
1184d87a3195Smrg                set quote "$_G_part" "\\$_G_char"
1185d87a3195Smrg                ;;
1186d87a3195Smrg              start)
1187d87a3195Smrg                set first "" ""
1188d87a3195Smrg                func_quote_portable_result=
1189d87a3195Smrg                ;;
1190d87a3195Smrg              first)
1191d87a3195Smrg                set quote "$_G_part" ""
1192d87a3195Smrg                ;;
1193d87a3195Smrg              esac
1194d87a3195Smrg            done
1195d87a3195Smrg          done
1196d87a3195Smrg          IFS=$func_quote_portable_old_IFS
1197eca46af7Smrg          ;;
1198d87a3195Smrg        *) ;;
1199eca46af7Smrg      esac
1200d87a3195Smrg      break
1201eca46af7Smrg    done
1202d87a3195Smrg
1203d87a3195Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204d87a3195Smrg    case $func_quote_portable_result in
1205d87a3195Smrg      # double-quote args containing shell metacharacters to delay
1206d87a3195Smrg      # word splitting, command substitution and variable expansion
1207d87a3195Smrg      # for a subsequent eval.
1208d87a3195Smrg      # many bourne shells cannot handle close brackets correctly
1209d87a3195Smrg      # in scan sets, so we specify it separately.
1210d87a3195Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211d87a3195Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212d87a3195Smrg        ;;
1213d87a3195Smrg    esac
1214eca46af7Smrg}
1215eca46af7Smrg
1216eca46af7Smrg
1217d87a3195Smrg# func_quotefast_eval ARG
1218d87a3195Smrg# -----------------------
1219d87a3195Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220d87a3195Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221d87a3195Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222d87a3195Smrg  printf -v _GL_test_printf_tilde %q '~'
1223d87a3195Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224d87a3195Smrg    func_quotefast_eval ()
1225d87a3195Smrg    {
1226d87a3195Smrg      printf -v func_quotefast_eval_result %q "$1"
1227d87a3195Smrg    }
1228d87a3195Smrg  else
1229d87a3195Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230d87a3195Smrg    func_quotefast_eval ()
1231d87a3195Smrg    {
1232d87a3195Smrg      case $1 in
1233d87a3195Smrg        '~'*)
1234d87a3195Smrg          func_quote_portable false "$1"
1235d87a3195Smrg          func_quotefast_eval_result=$func_quote_portable_result
1236d87a3195Smrg          ;;
1237d87a3195Smrg        *)
1238d87a3195Smrg          printf -v func_quotefast_eval_result %q "$1"
1239d87a3195Smrg          ;;
1240d87a3195Smrg      esac
1241d87a3195Smrg    }
1242d87a3195Smrg  fi
1243d87a3195Smrgelse
1244d87a3195Smrg  func_quotefast_eval ()
1245d87a3195Smrg  {
1246d87a3195Smrg    func_quote_portable false "$1"
1247d87a3195Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248d87a3195Smrg  }
1249d87a3195Smrgfi
1250eca46af7Smrg
1251d87a3195Smrg
1252d87a3195Smrg# func_quote_arg MODEs ARG
1253d87a3195Smrg# ------------------------
1254d87a3195Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255d87a3195Smrg# specifiers listed below separated by ',' character.  This function returns two
1256d87a3195Smrg# values:
1257d87a3195Smrg#   i) func_quote_arg_result
1258d87a3195Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259d87a3195Smrg#  ii) func_quote_arg_unquoted_result
1260d87a3195Smrg#      has all characters that are still active within double
1261d87a3195Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262d87a3195Smrg#
1263d87a3195Smrg# Available modes:
1264d87a3195Smrg# ----------------
1265d87a3195Smrg# 'eval' (default)
1266d87a3195Smrg#       - escape shell special characters
1267d87a3195Smrg# 'expand'
1268d87a3195Smrg#       - the same as 'eval';  but do not quote variable references
1269d87a3195Smrg# 'pretty'
1270d87a3195Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271d87a3195Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272d87a3195Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273d87a3195Smrg# 'unquoted'
1274d87a3195Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275d87a3195Smrg#         wrapping double-quotes.
1276d87a3195Smrg#
1277d87a3195Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278d87a3195Smrg#
1279d87a3195Smrg#   string      | *_result              | *_unquoted_result
1280d87a3195Smrg#   ------------+-----------------------+-------------------
1281d87a3195Smrg#   "           | \"                    | \"
1282d87a3195Smrg#   a b         | "a b"                 | a b
1283d87a3195Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284d87a3195Smrg#   *           | "*"                   | *
1285d87a3195Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286d87a3195Smrg#
1287d87a3195Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288d87a3195Smrg#
1289d87a3195Smrg#   string        |   *_result          |  *_unquoted_result
1290d87a3195Smrg#   --------------+---------------------+--------------------
1291d87a3195Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292d87a3195Smrgfunc_quote_arg ()
1293d87a3195Smrg{
1294d87a3195Smrg    _G_quote_expand=false
1295d87a3195Smrg    case ,$1, in
1296d87a3195Smrg      *,expand,*)
1297d87a3195Smrg        _G_quote_expand=:
1298d87a3195Smrg        ;;
1299eca46af7Smrg    esac
1300eca46af7Smrg
1301d87a3195Smrg    case ,$1, in
1302d87a3195Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303d87a3195Smrg        func_quote_portable $_G_quote_expand "$2"
1304d87a3195Smrg        func_quote_arg_result=$func_quote_portable_result
1305d87a3195Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306d87a3195Smrg        ;;
1307d87a3195Smrg      *)
1308d87a3195Smrg        # Faster quote-for-eval for some shells.
1309d87a3195Smrg        func_quotefast_eval "$2"
1310d87a3195Smrg        func_quote_arg_result=$func_quotefast_eval_result
1311eca46af7Smrg        ;;
1312eca46af7Smrg    esac
1313d87a3195Smrg}
1314d87a3195Smrg
1315eca46af7Smrg
1316d87a3195Smrg# func_quote MODEs ARGs...
1317d87a3195Smrg# ------------------------
1318d87a3195Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319d87a3195Smrg# func_quote_arg's description for more info.
1320d87a3195Smrgfunc_quote ()
1321d87a3195Smrg{
1322d87a3195Smrg    $debug_cmd
1323d87a3195Smrg    _G_func_quote_mode=$1 ; shift
1324d87a3195Smrg    func_quote_result=
1325d87a3195Smrg    while test 0 -lt $#; do
1326d87a3195Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327d87a3195Smrg      if test -n "$func_quote_result"; then
1328d87a3195Smrg        func_append func_quote_result " $func_quote_arg_result"
1329d87a3195Smrg      else
1330d87a3195Smrg        func_append func_quote_result "$func_quote_arg_result"
1331d87a3195Smrg      fi
1332d87a3195Smrg      shift
1333d87a3195Smrg    done
1334eca46af7Smrg}
1335eca46af7Smrg
1336eca46af7Smrg
1337eca46af7Smrg# func_stripname PREFIX SUFFIX NAME
1338eca46af7Smrg# ---------------------------------
1339eca46af7Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340eca46af7Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1341eca46af7Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342eca46af7Smrg# dot (in which case that matches only a dot).
1343eca46af7Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344eca46af7Smrg  eval 'func_stripname ()
1345eca46af7Smrg  {
1346eca46af7Smrg    $debug_cmd
1347eca46af7Smrg
1348eca46af7Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349eca46af7Smrg    # positional parameters, so assign one to ordinary variable first.
1350eca46af7Smrg    func_stripname_result=$3
1351eca46af7Smrg    func_stripname_result=${func_stripname_result#"$1"}
1352eca46af7Smrg    func_stripname_result=${func_stripname_result%"$2"}
1353eca46af7Smrg  }'
1354eca46af7Smrgelse
1355eca46af7Smrg  func_stripname ()
1356eca46af7Smrg  {
1357eca46af7Smrg    $debug_cmd
1358eca46af7Smrg
1359eca46af7Smrg    case $2 in
1360eca46af7Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361eca46af7Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362eca46af7Smrg    esac
1363eca46af7Smrg  }
1364eca46af7Smrgfi
1365eca46af7Smrg
1366eca46af7Smrg
1367eca46af7Smrg# func_show_eval CMD [FAIL_EXP]
1368eca46af7Smrg# -----------------------------
1369eca46af7Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370eca46af7Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371eca46af7Smrg# is given, then evaluate it.
1372eca46af7Smrgfunc_show_eval ()
1373eca46af7Smrg{
1374eca46af7Smrg    $debug_cmd
1375eca46af7Smrg
1376eca46af7Smrg    _G_cmd=$1
1377eca46af7Smrg    _G_fail_exp=${2-':'}
1378eca46af7Smrg
1379d87a3195Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380d87a3195Smrg    eval "func_notquiet $func_quote_arg_result"
1381eca46af7Smrg
1382eca46af7Smrg    $opt_dry_run || {
1383eca46af7Smrg      eval "$_G_cmd"
1384eca46af7Smrg      _G_status=$?
1385eca46af7Smrg      if test 0 -ne "$_G_status"; then
1386eca46af7Smrg	eval "(exit $_G_status); $_G_fail_exp"
1387eca46af7Smrg      fi
1388eca46af7Smrg    }
1389eca46af7Smrg}
1390eca46af7Smrg
1391eca46af7Smrg
1392eca46af7Smrg# func_show_eval_locale CMD [FAIL_EXP]
1393eca46af7Smrg# ------------------------------------
1394eca46af7Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395eca46af7Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396eca46af7Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397eca46af7Smrgfunc_show_eval_locale ()
1398eca46af7Smrg{
1399eca46af7Smrg    $debug_cmd
1400eca46af7Smrg
1401eca46af7Smrg    _G_cmd=$1
1402eca46af7Smrg    _G_fail_exp=${2-':'}
1403eca46af7Smrg
1404eca46af7Smrg    $opt_quiet || {
1405d87a3195Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406d87a3195Smrg      eval "func_echo $func_quote_arg_result"
1407eca46af7Smrg    }
1408eca46af7Smrg
1409eca46af7Smrg    $opt_dry_run || {
1410eca46af7Smrg      eval "$_G_user_locale
1411eca46af7Smrg	    $_G_cmd"
1412eca46af7Smrg      _G_status=$?
1413eca46af7Smrg      eval "$_G_safe_locale"
1414eca46af7Smrg      if test 0 -ne "$_G_status"; then
1415eca46af7Smrg	eval "(exit $_G_status); $_G_fail_exp"
1416eca46af7Smrg      fi
1417eca46af7Smrg    }
1418eca46af7Smrg}
1419eca46af7Smrg
1420eca46af7Smrg
1421eca46af7Smrg# func_tr_sh
1422eca46af7Smrg# ----------
1423eca46af7Smrg# Turn $1 into a string suitable for a shell variable name.
1424eca46af7Smrg# Result is stored in $func_tr_sh_result.  All characters
1425eca46af7Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426eca46af7Smrg# if $1 begins with a digit, a '_' is prepended as well.
1427eca46af7Smrgfunc_tr_sh ()
1428eca46af7Smrg{
1429eca46af7Smrg    $debug_cmd
1430eca46af7Smrg
1431eca46af7Smrg    case $1 in
1432eca46af7Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433eca46af7Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434eca46af7Smrg      ;;
1435eca46af7Smrg    * )
1436eca46af7Smrg      func_tr_sh_result=$1
1437eca46af7Smrg      ;;
1438eca46af7Smrg    esac
1439eca46af7Smrg}
1440eca46af7Smrg
1441eca46af7Smrg
1442eca46af7Smrg# func_verbose ARG...
1443eca46af7Smrg# -------------------
1444eca46af7Smrg# Echo program name prefixed message in verbose mode only.
1445eca46af7Smrgfunc_verbose ()
1446eca46af7Smrg{
1447eca46af7Smrg    $debug_cmd
1448eca46af7Smrg
1449eca46af7Smrg    $opt_verbose && func_echo "$*"
1450eca46af7Smrg
1451eca46af7Smrg    :
1452eca46af7Smrg}
1453eca46af7Smrg
1454eca46af7Smrg
1455eca46af7Smrg# func_warn_and_continue ARG...
1456eca46af7Smrg# -----------------------------
1457eca46af7Smrg# Echo program name prefixed warning message to standard error.
1458eca46af7Smrgfunc_warn_and_continue ()
1459eca46af7Smrg{
1460eca46af7Smrg    $debug_cmd
1461eca46af7Smrg
1462eca46af7Smrg    $require_term_colors
1463eca46af7Smrg
1464eca46af7Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465eca46af7Smrg}
1466eca46af7Smrg
1467eca46af7Smrg
1468eca46af7Smrg# func_warning CATEGORY ARG...
1469eca46af7Smrg# ----------------------------
1470eca46af7Smrg# Echo program name prefixed warning message to standard error. Warning
1471eca46af7Smrg# messages can be filtered according to CATEGORY, where this function
1472eca46af7Smrg# elides messages where CATEGORY is not listed in the global variable
1473eca46af7Smrg# 'opt_warning_types'.
1474eca46af7Smrgfunc_warning ()
1475eca46af7Smrg{
1476eca46af7Smrg    $debug_cmd
1477eca46af7Smrg
1478eca46af7Smrg    # CATEGORY must be in the warning_categories list!
1479eca46af7Smrg    case " $warning_categories " in
1480eca46af7Smrg      *" $1 "*) ;;
1481eca46af7Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1482eca46af7Smrg    esac
1483eca46af7Smrg
1484eca46af7Smrg    _G_category=$1
1485eca46af7Smrg    shift
1486eca46af7Smrg
1487eca46af7Smrg    case " $opt_warning_types " in
1488eca46af7Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489eca46af7Smrg    esac
1490eca46af7Smrg}
1491eca46af7Smrg
1492eca46af7Smrg
1493eca46af7Smrg# func_sort_ver VER1 VER2
1494eca46af7Smrg# -----------------------
1495eca46af7Smrg# 'sort -V' is not generally available.
1496eca46af7Smrg# Note this deviates from the version comparison in automake
1497eca46af7Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498eca46af7Smrg# but this should suffice as we won't be specifying old
1499eca46af7Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1500eca46af7Smrg# If we did want full compatibility then we should probably
1501eca46af7Smrg# use m4_version_compare from autoconf.
1502eca46af7Smrgfunc_sort_ver ()
1503eca46af7Smrg{
1504eca46af7Smrg    $debug_cmd
1505eca46af7Smrg
1506eca46af7Smrg    printf '%s\n%s\n' "$1" "$2" \
1507eca46af7Smrg      | 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
1508eca46af7Smrg}
1509eca46af7Smrg
1510eca46af7Smrg# func_lt_ver PREV CURR
1511eca46af7Smrg# ---------------------
1512eca46af7Smrg# Return true if PREV and CURR are in the correct order according to
1513eca46af7Smrg# func_sort_ver, otherwise false.  Use it like this:
1514eca46af7Smrg#
1515eca46af7Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516eca46af7Smrgfunc_lt_ver ()
1517eca46af7Smrg{
1518eca46af7Smrg    $debug_cmd
1519eca46af7Smrg
1520eca46af7Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521eca46af7Smrg}
1522eca46af7Smrg
1523eca46af7Smrg
1524eca46af7Smrg# Local variables:
1525eca46af7Smrg# mode: shell-script
1526eca46af7Smrg# sh-indentation: 2
1527eca46af7Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528eca46af7Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529eca46af7Smrg# time-stamp-time-zone: "UTC"
1530eca46af7Smrg# End:
1531eca46af7Smrg#! /bin/sh
1532eca46af7Smrg
1533eca46af7Smrg# A portable, pluggable option parser for Bourne shell.
1534eca46af7Smrg# Written by Gary V. Vaughan, 2010
1535eca46af7Smrg
1536d87a3195Smrg# This is free software.  There is NO warranty; not even for
1537d87a3195Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538d87a3195Smrg#
1539d87a3195Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540d87a3195Smrg#
1541d87a3195Smrg# This file is dual licensed under the terms of the MIT license
1542d87a3195Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543d87a3195Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544d87a3195Smrg# these licenses when using or redistributing this software or any of
1545d87a3195Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546d87a3195Smrg# included in the Bootstrap distribution for the full license texts.
1547eca46af7Smrg
1548d87a3195Smrg# Please report bugs or propose patches to:
1549d87a3195Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550eca46af7Smrg
1551d87a3195Smrg# Set a version string for this script.
1552d87a3195Smrgscriptversion=2019-02-19.15; # UTC
1553eca46af7Smrg
1554eca46af7Smrg
1555eca46af7Smrg## ------ ##
1556eca46af7Smrg## Usage. ##
1557eca46af7Smrg## ------ ##
1558eca46af7Smrg
1559eca46af7Smrg# This file is a library for parsing options in your shell scripts along
1560eca46af7Smrg# with assorted other useful supporting features that you can make use
1561eca46af7Smrg# of too.
1562eca46af7Smrg#
1563eca46af7Smrg# For the simplest scripts you might need only:
1564eca46af7Smrg#
1565eca46af7Smrg#   #!/bin/sh
1566eca46af7Smrg#   . relative/path/to/funclib.sh
1567eca46af7Smrg#   . relative/path/to/options-parser
1568eca46af7Smrg#   scriptversion=1.0
1569eca46af7Smrg#   func_options ${1+"$@"}
1570eca46af7Smrg#   eval set dummy "$func_options_result"; shift
1571eca46af7Smrg#   ...rest of your script...
1572eca46af7Smrg#
1573eca46af7Smrg# In order for the '--version' option to work, you will need to have a
1574eca46af7Smrg# suitably formatted comment like the one at the top of this file
1575d87a3195Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576eca46af7Smrg#
1577eca46af7Smrg# For '-h' and '--help' to work, you will also need a one line
1578eca46af7Smrg# description of your script's purpose in a comment directly above the
1579eca46af7Smrg# '# Written by ' line, like the one at the top of this file.
1580eca46af7Smrg#
1581eca46af7Smrg# The default options also support '--debug', which will turn on shell
1582eca46af7Smrg# execution tracing (see the comment above debug_cmd below for another
1583eca46af7Smrg# use), and '--verbose' and the func_verbose function to allow your script
1584eca46af7Smrg# to display verbose messages only when your user has specified
1585eca46af7Smrg# '--verbose'.
1586eca46af7Smrg#
1587d87a3195Smrg# After sourcing this file, you can plug in processing for additional
1588eca46af7Smrg# options by amending the variables from the 'Configuration' section
1589eca46af7Smrg# below, and following the instructions in the 'Option parsing'
1590eca46af7Smrg# section further down.
1591eca46af7Smrg
1592eca46af7Smrg## -------------- ##
1593eca46af7Smrg## Configuration. ##
1594eca46af7Smrg## -------------- ##
1595eca46af7Smrg
1596eca46af7Smrg# You should override these variables in your script after sourcing this
1597eca46af7Smrg# file so that they reflect the customisations you have added to the
1598eca46af7Smrg# option parser.
1599eca46af7Smrg
1600eca46af7Smrg# The usage line for option parsing errors and the start of '-h' and
1601eca46af7Smrg# '--help' output messages. You can embed shell variables for delayed
1602eca46af7Smrg# expansion at the time the message is displayed, but you will need to
1603eca46af7Smrg# quote other shell meta-characters carefully to prevent them being
1604eca46af7Smrg# expanded when the contents are evaled.
1605eca46af7Smrgusage='$progpath [OPTION]...'
1606eca46af7Smrg
1607eca46af7Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1608eca46af7Smrg# override it after sourcing this library to reflect the full set of
1609eca46af7Smrg# options your script accepts.
1610eca46af7Smrgusage_message="\
1611eca46af7Smrg       --debug        enable verbose shell tracing
1612eca46af7Smrg   -W, --warnings=CATEGORY
1613eca46af7Smrg                      report the warnings falling in CATEGORY [all]
1614eca46af7Smrg   -v, --verbose      verbosely report processing
1615eca46af7Smrg       --version      print version information and exit
1616eca46af7Smrg   -h, --help         print short or long help message and exit
1617eca46af7Smrg"
1618eca46af7Smrg
1619eca46af7Smrg# Additional text appended to 'usage_message' in response to '--help'.
1620eca46af7Smrglong_help_message="
1621eca46af7SmrgWarning categories include:
1622eca46af7Smrg       'all'          show all warnings
1623eca46af7Smrg       'none'         turn off all the warnings
1624eca46af7Smrg       'error'        warnings are treated as fatal errors"
1625eca46af7Smrg
1626eca46af7Smrg# Help message printed before fatal option parsing errors.
1627eca46af7Smrgfatal_help="Try '\$progname --help' for more information."
1628eca46af7Smrg
1629eca46af7Smrg
1630eca46af7Smrg
1631eca46af7Smrg## ------------------------- ##
1632eca46af7Smrg## Hook function management. ##
1633eca46af7Smrg## ------------------------- ##
1634eca46af7Smrg
1635eca46af7Smrg# This section contains functions for adding, removing, and running hooks
1636d87a3195Smrg# in the main code.  A hook is just a list of function names that can be
1637d87a3195Smrg# run in order later on.
1638eca46af7Smrg
1639eca46af7Smrg# func_hookable FUNC_NAME
1640eca46af7Smrg# -----------------------
1641eca46af7Smrg# Declare that FUNC_NAME will run hooks added with
1642eca46af7Smrg# 'func_add_hook FUNC_NAME ...'.
1643eca46af7Smrgfunc_hookable ()
1644eca46af7Smrg{
1645eca46af7Smrg    $debug_cmd
1646eca46af7Smrg
1647eca46af7Smrg    func_append hookable_fns " $1"
1648eca46af7Smrg}
1649eca46af7Smrg
1650eca46af7Smrg
1651eca46af7Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1652eca46af7Smrg# ---------------------------------
1653eca46af7Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654eca46af7Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1655eca46af7Smrgfunc_add_hook ()
1656eca46af7Smrg{
1657eca46af7Smrg    $debug_cmd
1658eca46af7Smrg
1659eca46af7Smrg    case " $hookable_fns " in
1660eca46af7Smrg      *" $1 "*) ;;
1661eca46af7Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662eca46af7Smrg    esac
1663eca46af7Smrg
1664eca46af7Smrg    eval func_append ${1}_hooks '" $2"'
1665eca46af7Smrg}
1666eca46af7Smrg
1667eca46af7Smrg
1668eca46af7Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669eca46af7Smrg# ------------------------------------
1670d87a3195Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671d87a3195Smrg# FUNC_NAME.
1672eca46af7Smrgfunc_remove_hook ()
1673eca46af7Smrg{
1674eca46af7Smrg    $debug_cmd
1675eca46af7Smrg
1676eca46af7Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677eca46af7Smrg}
1678eca46af7Smrg
1679eca46af7Smrg
1680d87a3195Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681d87a3195Smrg# ---------------------------------------------
1682d87a3195Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683d87a3195Smrg# *_result variable of FUNC_NAME_B.
1684d87a3195Smrgfunc_propagate_result ()
1685d87a3195Smrg{
1686d87a3195Smrg    $debug_cmd
1687d87a3195Smrg
1688d87a3195Smrg    func_propagate_result_result=:
1689d87a3195Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690d87a3195Smrg    then
1691d87a3195Smrg      eval "${2}_result=\$${1}_result"
1692d87a3195Smrg    else
1693d87a3195Smrg      func_propagate_result_result=false
1694d87a3195Smrg    fi
1695d87a3195Smrg}
1696d87a3195Smrg
1697d87a3195Smrg
1698eca46af7Smrg# func_run_hooks FUNC_NAME [ARG]...
1699eca46af7Smrg# ---------------------------------
1700eca46af7Smrg# Run all hook functions registered to FUNC_NAME.
1701d87a3195Smrg# It's assumed that the list of hook functions contains nothing more
1702eca46af7Smrg# than a whitespace-delimited list of legal shell function names, and
1703eca46af7Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1704eca46af7Smrg# whitespace.
1705eca46af7Smrgfunc_run_hooks ()
1706eca46af7Smrg{
1707eca46af7Smrg    $debug_cmd
1708eca46af7Smrg
1709eca46af7Smrg    case " $hookable_fns " in
1710eca46af7Smrg      *" $1 "*) ;;
1711d87a3195Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712eca46af7Smrg    esac
1713eca46af7Smrg
1714eca46af7Smrg    eval _G_hook_fns=\$$1_hooks; shift
1715eca46af7Smrg
1716eca46af7Smrg    for _G_hook in $_G_hook_fns; do
1717d87a3195Smrg      func_unset "${_G_hook}_result"
1718d87a3195Smrg      eval $_G_hook '${1+"$@"}'
1719d87a3195Smrg      func_propagate_result $_G_hook func_run_hooks
1720d87a3195Smrg      if $func_propagate_result_result; then
1721d87a3195Smrg        eval set dummy "$func_run_hooks_result"; shift
1722d87a3195Smrg      fi
1723eca46af7Smrg    done
1724eca46af7Smrg}
1725eca46af7Smrg
1726eca46af7Smrg
1727eca46af7Smrg
1728eca46af7Smrg## --------------- ##
1729eca46af7Smrg## Option parsing. ##
1730eca46af7Smrg## --------------- ##
1731eca46af7Smrg
1732eca46af7Smrg# In order to add your own option parsing hooks, you must accept the
1733d87a3195Smrg# full positional parameter list from your hook function.  You may remove
1734d87a3195Smrg# or edit any options that you action, and then pass back the remaining
1735d87a3195Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736d87a3195Smrg# suitably for 'eval'.
1737d87a3195Smrg#
1738d87a3195Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739d87a3195Smrg# before your hook gets called; for best performance, only set the
1740d87a3195Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741d87a3195Smrg# function unnecessarily because it can be an expensive operation on some
1742d87a3195Smrg# machines).
1743d87a3195Smrg#
1744d87a3195Smrg# Like this:
1745eca46af7Smrg#
1746eca46af7Smrg#    my_options_prep ()
1747eca46af7Smrg#    {
1748eca46af7Smrg#        $debug_cmd
1749eca46af7Smrg#
1750eca46af7Smrg#        # Extend the existing usage message.
1751eca46af7Smrg#        usage_message=$usage_message'
1752eca46af7Smrg#      -s, --silent       don'\''t print informational messages
1753eca46af7Smrg#    '
1754d87a3195Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755d87a3195Smrg#        # my_options_prep_result variable intact.
1756eca46af7Smrg#    }
1757eca46af7Smrg#    func_add_hook func_options_prep my_options_prep
1758eca46af7Smrg#
1759eca46af7Smrg#
1760eca46af7Smrg#    my_silent_option ()
1761eca46af7Smrg#    {
1762eca46af7Smrg#        $debug_cmd
1763eca46af7Smrg#
1764d87a3195Smrg#        args_changed=false
1765d87a3195Smrg#
1766d87a3195Smrg#        # Note that, for efficiency, we parse as many options as we can
1767eca46af7Smrg#        # recognise in a loop before passing the remainder back to the
1768eca46af7Smrg#        # caller on the first unrecognised argument we encounter.
1769eca46af7Smrg#        while test $# -gt 0; do
1770eca46af7Smrg#          opt=$1; shift
1771eca46af7Smrg#          case $opt in
1772d87a3195Smrg#            --silent|-s) opt_silent=:
1773d87a3195Smrg#                         args_changed=:
1774d87a3195Smrg#                         ;;
1775eca46af7Smrg#            # Separate non-argument short options:
1776eca46af7Smrg#            -s*)         func_split_short_opt "$_G_opt"
1777eca46af7Smrg#                         set dummy "$func_split_short_opt_name" \
1778eca46af7Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779eca46af7Smrg#                         shift
1780d87a3195Smrg#                         args_changed=:
1781eca46af7Smrg#                         ;;
1782d87a3195Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783d87a3195Smrg#                         # is added back to "$@" in case we need it later,
1784d87a3195Smrg#                         # if $args_changed was set to 'true'.
1785d87a3195Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786eca46af7Smrg#          esac
1787eca46af7Smrg#        done
1788eca46af7Smrg#
1789d87a3195Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1790d87a3195Smrg#        if $args_changed; then
1791d87a3195Smrg#          func_quote eval ${1+"$@"}
1792d87a3195Smrg#          my_silent_option_result=$func_quote_result
1793d87a3195Smrg#        fi
1794eca46af7Smrg#    }
1795eca46af7Smrg#    func_add_hook func_parse_options my_silent_option
1796eca46af7Smrg#
1797eca46af7Smrg#
1798eca46af7Smrg#    my_option_validation ()
1799eca46af7Smrg#    {
1800eca46af7Smrg#        $debug_cmd
1801eca46af7Smrg#
1802eca46af7Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803eca46af7Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1804eca46af7Smrg#    }
1805eca46af7Smrg#    func_add_hook func_validate_options my_option_validation
1806eca46af7Smrg#
1807d87a3195Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808eca46af7Smrg# options you parse.  It's preferable to append if you can, so that
1809eca46af7Smrg# multiple option parsing hooks can be added safely.
1810eca46af7Smrg
1811eca46af7Smrg
1812d87a3195Smrg# func_options_finish [ARG]...
1813d87a3195Smrg# ----------------------------
1814d87a3195Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815d87a3195Smrgfunc_options_finish ()
1816d87a3195Smrg{
1817d87a3195Smrg    $debug_cmd
1818d87a3195Smrg
1819d87a3195Smrg    func_run_hooks func_options ${1+"$@"}
1820d87a3195Smrg    func_propagate_result func_run_hooks func_options_finish
1821d87a3195Smrg}
1822d87a3195Smrg
1823d87a3195Smrg
1824eca46af7Smrg# func_options [ARG]...
1825eca46af7Smrg# ---------------------
1826eca46af7Smrg# All the functions called inside func_options are hookable. See the
1827eca46af7Smrg# individual implementations for details.
1828eca46af7Smrgfunc_hookable func_options
1829eca46af7Smrgfunc_options ()
1830eca46af7Smrg{
1831eca46af7Smrg    $debug_cmd
1832eca46af7Smrg
1833d87a3195Smrg    _G_options_quoted=false
1834eca46af7Smrg
1835d87a3195Smrg    for my_func in options_prep parse_options validate_options options_finish
1836d87a3195Smrg    do
1837d87a3195Smrg      func_unset func_${my_func}_result
1838d87a3195Smrg      func_unset func_run_hooks_result
1839d87a3195Smrg      eval func_$my_func '${1+"$@"}'
1840d87a3195Smrg      func_propagate_result func_$my_func func_options
1841d87a3195Smrg      if $func_propagate_result_result; then
1842d87a3195Smrg        eval set dummy "$func_options_result"; shift
1843d87a3195Smrg        _G_options_quoted=:
1844d87a3195Smrg      fi
1845d87a3195Smrg    done
1846eca46af7Smrg
1847d87a3195Smrg    $_G_options_quoted || {
1848d87a3195Smrg      # As we (func_options) are top-level options-parser function and
1849d87a3195Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850d87a3195Smrg      # caller.
1851d87a3195Smrg      func_quote eval ${1+"$@"}
1852d87a3195Smrg      func_options_result=$func_quote_result
1853d87a3195Smrg    }
185495b296d0Smrg}
185595b296d0Smrg
185695b296d0Smrg
1857eca46af7Smrg# func_options_prep [ARG]...
1858eca46af7Smrg# --------------------------
1859eca46af7Smrg# All initialisations required before starting the option parse loop.
1860eca46af7Smrg# Note that when calling hook functions, we pass through the list of
1861eca46af7Smrg# positional parameters.  If a hook function modifies that list, and
1862d87a3195Smrg# needs to propagate that back to rest of this script, then the complete
1863d87a3195Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864eca46af7Smrgfunc_hookable func_options_prep
1865eca46af7Smrgfunc_options_prep ()
186695b296d0Smrg{
1867eca46af7Smrg    $debug_cmd
18682378475aSmrg
1869eca46af7Smrg    # Option defaults:
1870eca46af7Smrg    opt_verbose=false
1871eca46af7Smrg    opt_warning_types=
1872eca46af7Smrg
1873eca46af7Smrg    func_run_hooks func_options_prep ${1+"$@"}
1874d87a3195Smrg    func_propagate_result func_run_hooks func_options_prep
187595b296d0Smrg}
187695b296d0Smrg
187795b296d0Smrg
1878eca46af7Smrg# func_parse_options [ARG]...
1879eca46af7Smrg# ---------------------------
1880eca46af7Smrg# The main option parsing loop.
1881eca46af7Smrgfunc_hookable func_parse_options
1882eca46af7Smrgfunc_parse_options ()
188395b296d0Smrg{
1884eca46af7Smrg    $debug_cmd
18852378475aSmrg
1886d87a3195Smrg    _G_parse_options_requote=false
1887eca46af7Smrg    # this just eases exit handling
1888eca46af7Smrg    while test $# -gt 0; do
1889eca46af7Smrg      # Defer to hook functions for initial option parsing, so they
1890eca46af7Smrg      # get priority in the event of reusing an option name.
1891eca46af7Smrg      func_run_hooks func_parse_options ${1+"$@"}
1892d87a3195Smrg      func_propagate_result func_run_hooks func_parse_options
1893d87a3195Smrg      if $func_propagate_result_result; then
1894d87a3195Smrg        eval set dummy "$func_parse_options_result"; shift
1895d87a3195Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896d87a3195Smrg        # down into the hook and it quoted it for us (because we are in
1897d87a3195Smrg        # this if-branch).  No need to quote it again.
1898d87a3195Smrg        _G_parse_options_requote=false
1899d87a3195Smrg      fi
190095b296d0Smrg
1901eca46af7Smrg      # Break out of the loop if we already parsed every option.
1902eca46af7Smrg      test $# -gt 0 || break
190339713583Smrg
1904d87a3195Smrg      # We expect that one of the options parsed in this function matches
1905d87a3195Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906d87a3195Smrg      _G_match_parse_options=:
1907eca46af7Smrg      _G_opt=$1
1908eca46af7Smrg      shift
1909eca46af7Smrg      case $_G_opt in
1910eca46af7Smrg        --debug|-x)   debug_cmd='set -x'
1911d87a3195Smrg                      func_echo "enabling shell trace mode" >&2
1912eca46af7Smrg                      $debug_cmd
1913eca46af7Smrg                      ;;
1914eca46af7Smrg
1915eca46af7Smrg        --no-warnings|--no-warning|--no-warn)
1916eca46af7Smrg                      set dummy --warnings none ${1+"$@"}
1917eca46af7Smrg                      shift
1918eca46af7Smrg		      ;;
19192378475aSmrg
1920eca46af7Smrg        --warnings|--warning|-W)
1921d87a3195Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922d87a3195Smrg                        _G_parse_options_requote=:
1923d87a3195Smrg                        break
1924d87a3195Smrg                      fi
1925eca46af7Smrg                      case " $warning_categories $1" in
1926eca46af7Smrg                        *" $1 "*)
1927eca46af7Smrg                          # trailing space prevents matching last $1 above
1928eca46af7Smrg                          func_append_uniq opt_warning_types " $1"
1929eca46af7Smrg                          ;;
1930eca46af7Smrg                        *all)
1931eca46af7Smrg                          opt_warning_types=$warning_categories
1932eca46af7Smrg                          ;;
1933eca46af7Smrg                        *none)
1934eca46af7Smrg                          opt_warning_types=none
1935eca46af7Smrg                          warning_func=:
1936eca46af7Smrg                          ;;
1937eca46af7Smrg                        *error)
1938eca46af7Smrg                          opt_warning_types=$warning_categories
1939eca46af7Smrg                          warning_func=func_fatal_error
1940eca46af7Smrg                          ;;
1941eca46af7Smrg                        *)
1942eca46af7Smrg                          func_fatal_error \
1943eca46af7Smrg                             "unsupported warning category: '$1'"
1944eca46af7Smrg                          ;;
1945eca46af7Smrg                      esac
1946eca46af7Smrg                      shift
1947eca46af7Smrg                      ;;
1948eca46af7Smrg
1949eca46af7Smrg        --verbose|-v) opt_verbose=: ;;
1950eca46af7Smrg        --version)    func_version ;;
1951eca46af7Smrg        -\?|-h)       func_usage ;;
1952eca46af7Smrg        --help)       func_help ;;
1953eca46af7Smrg
1954eca46af7Smrg	# Separate optargs to long options (plugins may need this):
1955eca46af7Smrg	--*=*)        func_split_equals "$_G_opt"
1956eca46af7Smrg	              set dummy "$func_split_equals_lhs" \
1957eca46af7Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1958eca46af7Smrg                      shift
1959eca46af7Smrg                      ;;
1960eca46af7Smrg
1961eca46af7Smrg       # Separate optargs to short options:
1962eca46af7Smrg        -W*)
1963eca46af7Smrg                      func_split_short_opt "$_G_opt"
1964eca46af7Smrg                      set dummy "$func_split_short_opt_name" \
1965eca46af7Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966eca46af7Smrg                      shift
1967eca46af7Smrg                      ;;
1968eca46af7Smrg
1969eca46af7Smrg        # Separate non-argument short options:
1970eca46af7Smrg        -\?*|-h*|-v*|-x*)
1971eca46af7Smrg                      func_split_short_opt "$_G_opt"
1972eca46af7Smrg                      set dummy "$func_split_short_opt_name" \
1973eca46af7Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974eca46af7Smrg                      shift
1975eca46af7Smrg                      ;;
1976eca46af7Smrg
1977d87a3195Smrg        --)           _G_parse_options_requote=: ; break ;;
1978eca46af7Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979d87a3195Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980d87a3195Smrg                      _G_match_parse_options=false
1981d87a3195Smrg                      break
1982d87a3195Smrg                      ;;
1983eca46af7Smrg      esac
1984d87a3195Smrg
1985d87a3195Smrg      if $_G_match_parse_options; then
1986d87a3195Smrg        _G_parse_options_requote=:
1987d87a3195Smrg      fi
1988eca46af7Smrg    done
1989eca46af7Smrg
1990d87a3195Smrg    if $_G_parse_options_requote; then
1991d87a3195Smrg      # save modified positional parameters for caller
1992d87a3195Smrg      func_quote eval ${1+"$@"}
1993d87a3195Smrg      func_parse_options_result=$func_quote_result
1994d87a3195Smrg    fi
199595b296d0Smrg}
199695b296d0Smrg
19972378475aSmrg
1998eca46af7Smrg# func_validate_options [ARG]...
1999eca46af7Smrg# ------------------------------
2000eca46af7Smrg# Perform any sanity checks on option settings and/or unconsumed
2001eca46af7Smrg# arguments.
2002eca46af7Smrgfunc_hookable func_validate_options
2003eca46af7Smrgfunc_validate_options ()
200495b296d0Smrg{
2005eca46af7Smrg    $debug_cmd
20062378475aSmrg
2007eca46af7Smrg    # Display all warnings if -W was not given.
2008eca46af7Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
20092378475aSmrg
2010eca46af7Smrg    func_run_hooks func_validate_options ${1+"$@"}
2011d87a3195Smrg    func_propagate_result func_run_hooks func_validate_options
201295b296d0Smrg
2013eca46af7Smrg    # Bail if the options were screwed!
2014eca46af7Smrg    $exit_cmd $EXIT_FAILURE
201514330f12Smrg}
20162378475aSmrg
20172378475aSmrg
201814330f12Smrg
2019eca46af7Smrg## ----------------- ##
2020eca46af7Smrg## Helper functions. ##
2021eca46af7Smrg## ----------------- ##
20222378475aSmrg
2023eca46af7Smrg# This section contains the helper functions used by the rest of the
2024eca46af7Smrg# hookable option parser framework in ascii-betical order.
2025eca46af7Smrg
2026eca46af7Smrg
2027eca46af7Smrg# func_fatal_help ARG...
2028eca46af7Smrg# ----------------------
2029eca46af7Smrg# Echo program name prefixed message to standard error, followed by
2030eca46af7Smrg# a help hint, and exit.
2031eca46af7Smrgfunc_fatal_help ()
20322378475aSmrg{
2033eca46af7Smrg    $debug_cmd
203414330f12Smrg
2035eca46af7Smrg    eval \$ECHO \""Usage: $usage"\"
2036eca46af7Smrg    eval \$ECHO \""$fatal_help"\"
2037eca46af7Smrg    func_error ${1+"$@"}
2038eca46af7Smrg    exit $EXIT_FAILURE
20392378475aSmrg}
20402378475aSmrg
2041eca46af7Smrg
2042eca46af7Smrg# func_help
2043eca46af7Smrg# ---------
2044eca46af7Smrg# Echo long help message to standard output and exit.
20452378475aSmrgfunc_help ()
20462378475aSmrg{
2047eca46af7Smrg    $debug_cmd
2048eca46af7Smrg
2049eca46af7Smrg    func_usage_message
2050eca46af7Smrg    $ECHO "$long_help_message"
2051eca46af7Smrg    exit 0
20522378475aSmrg}
20532378475aSmrg
2054eca46af7Smrg
2055eca46af7Smrg# func_missing_arg ARGNAME
2056eca46af7Smrg# ------------------------
20572378475aSmrg# Echo program name prefixed message to standard error and set global
20582378475aSmrg# exit_cmd.
20592378475aSmrgfunc_missing_arg ()
20602378475aSmrg{
2061eca46af7Smrg    $debug_cmd
206214330f12Smrg
2063eca46af7Smrg    func_error "Missing argument for '$1'."
20642378475aSmrg    exit_cmd=exit
206595b296d0Smrg}
206695b296d0Smrg
206739713583Smrg
2068eca46af7Smrg# func_split_equals STRING
2069eca46af7Smrg# ------------------------
2070d87a3195Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071d87a3195Smrg# after splitting STRING at the '=' sign.
2072eca46af7Smrgtest -z "$_G_HAVE_XSI_OPS" \
2073eca46af7Smrg    && (eval 'x=a/b/c;
2074eca46af7Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075eca46af7Smrg    && _G_HAVE_XSI_OPS=yes
2076eca46af7Smrg
2077eca46af7Smrgif test yes = "$_G_HAVE_XSI_OPS"
2078eca46af7Smrgthen
2079eca46af7Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2080eca46af7Smrg  eval 'func_split_equals ()
2081eca46af7Smrg  {
2082eca46af7Smrg      $debug_cmd
2083eca46af7Smrg
2084eca46af7Smrg      func_split_equals_lhs=${1%%=*}
2085eca46af7Smrg      func_split_equals_rhs=${1#*=}
2086d87a3195Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087d87a3195Smrg        func_split_equals_rhs=
2088d87a3195Smrg      fi
2089eca46af7Smrg  }'
2090eca46af7Smrgelse
2091eca46af7Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092eca46af7Smrg  func_split_equals ()
2093eca46af7Smrg  {
2094eca46af7Smrg      $debug_cmd
2095eca46af7Smrg
2096eca46af7Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097eca46af7Smrg      func_split_equals_rhs=
2098d87a3195Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099eca46af7Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100eca46af7Smrg  }
2101eca46af7Smrgfi #func_split_equals
2102eca46af7Smrg
2103eca46af7Smrg
2104eca46af7Smrg# func_split_short_opt SHORTOPT
2105eca46af7Smrg# -----------------------------
210614330f12Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
210714330f12Smrg# variables after splitting SHORTOPT after the 2nd character.
2108eca46af7Smrgif test yes = "$_G_HAVE_XSI_OPS"
2109eca46af7Smrgthen
2110eca46af7Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2111eca46af7Smrg  eval 'func_split_short_opt ()
2112eca46af7Smrg  {
2113eca46af7Smrg      $debug_cmd
2114eca46af7Smrg
2115eca46af7Smrg      func_split_short_opt_arg=${1#??}
2116eca46af7Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117eca46af7Smrg  }'
2118eca46af7Smrgelse
2119eca46af7Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120eca46af7Smrg  func_split_short_opt ()
2121eca46af7Smrg  {
2122eca46af7Smrg      $debug_cmd
2123eca46af7Smrg
2124d87a3195Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125eca46af7Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126eca46af7Smrg  }
2127eca46af7Smrgfi #func_split_short_opt
2128eca46af7Smrg
2129eca46af7Smrg
2130eca46af7Smrg# func_usage
2131eca46af7Smrg# ----------
2132eca46af7Smrg# Echo short help message to standard output and exit.
2133eca46af7Smrgfunc_usage ()
213414330f12Smrg{
2135eca46af7Smrg    $debug_cmd
213639713583Smrg
2137eca46af7Smrg    func_usage_message
2138eca46af7Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139eca46af7Smrg    exit 0
2140eca46af7Smrg}
214114330f12Smrg
214214330f12Smrg
2143eca46af7Smrg# func_usage_message
2144eca46af7Smrg# ------------------
2145eca46af7Smrg# Echo short help message to standard output.
2146eca46af7Smrgfunc_usage_message ()
214714330f12Smrg{
2148eca46af7Smrg    $debug_cmd
214914330f12Smrg
2150eca46af7Smrg    eval \$ECHO \""Usage: $usage"\"
2151eca46af7Smrg    echo
2152eca46af7Smrg    $SED -n 's|^# ||
2153eca46af7Smrg        /^Written by/{
2154eca46af7Smrg          x;p;x
2155eca46af7Smrg        }
2156eca46af7Smrg	h
2157eca46af7Smrg	/^Written by/q' < "$progpath"
2158eca46af7Smrg    echo
2159eca46af7Smrg    eval \$ECHO \""$usage_message"\"
2160eca46af7Smrg}
216114330f12Smrg
21622378475aSmrg
2163eca46af7Smrg# func_version
2164eca46af7Smrg# ------------
2165eca46af7Smrg# Echo version message to standard output and exit.
2166d87a3195Smrg# The version message is extracted from the calling file's header
2167d87a3195Smrg# comments, with leading '# ' stripped:
2168d87a3195Smrg#   1. First display the progname and version
2169d87a3195Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170d87a3195Smrg#   3. Then a blank line followed by the first following line matching
2171d87a3195Smrg#      /^# Copyright /
2172d87a3195Smrg#   4. Immediately followed by any lines between the previous matches,
2173d87a3195Smrg#      except lines preceding the intervening completely blank line.
2174d87a3195Smrg# For example, see the header comments of this file.
2175eca46af7Smrgfunc_version ()
2176eca46af7Smrg{
2177eca46af7Smrg    $debug_cmd
21782378475aSmrg
2179eca46af7Smrg    printf '%s\n' "$progname $scriptversion"
2180eca46af7Smrg    $SED -n '
2181d87a3195Smrg        /^# Written by /!b
2182d87a3195Smrg        s|^# ||; p; n
2183d87a3195Smrg
2184d87a3195Smrg        :fwd2blnk
2185d87a3195Smrg        /./ {
2186d87a3195Smrg          n
2187d87a3195Smrg          b fwd2blnk
2188eca46af7Smrg        }
2189d87a3195Smrg        p; n
2190d87a3195Smrg
2191d87a3195Smrg        :holdwrnt
2192d87a3195Smrg        s|^# ||
2193d87a3195Smrg        s|^# *$||
2194d87a3195Smrg        /^Copyright /!{
2195d87a3195Smrg          /./H
2196d87a3195Smrg          n
2197d87a3195Smrg          b holdwrnt
2198eca46af7Smrg        }
2199d87a3195Smrg
2200d87a3195Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201d87a3195Smrg        G
2202d87a3195Smrg        s|\(\n\)\n*|\1|g
2203d87a3195Smrg        p; q' < "$progpath"
22042378475aSmrg
2205eca46af7Smrg    exit $?
2206eca46af7Smrg}
220795b296d0Smrg
220895b296d0Smrg
2209eca46af7Smrg# Local variables:
2210eca46af7Smrg# mode: shell-script
2211eca46af7Smrg# sh-indentation: 2
2212eca46af7Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213d87a3195Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214eca46af7Smrg# time-stamp-time-zone: "UTC"
2215eca46af7Smrg# End:
221695b296d0Smrg
2217eca46af7Smrg# Set a version string.
2218d87a3195Smrgscriptversion='(GNU libtool) 2.4.7'
221939713583Smrg
22202378475aSmrg
2221eca46af7Smrg# func_echo ARG...
2222eca46af7Smrg# ----------------
2223eca46af7Smrg# Libtool also displays the current mode in messages, so override
2224eca46af7Smrg# funclib.sh func_echo with this custom definition.
2225eca46af7Smrgfunc_echo ()
222614330f12Smrg{
2227eca46af7Smrg    $debug_cmd
222814330f12Smrg
2229eca46af7Smrg    _G_message=$*
2230eca46af7Smrg
2231eca46af7Smrg    func_echo_IFS=$IFS
2232eca46af7Smrg    IFS=$nl
2233eca46af7Smrg    for _G_line in $_G_message; do
2234eca46af7Smrg      IFS=$func_echo_IFS
2235eca46af7Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236eca46af7Smrg    done
2237eca46af7Smrg    IFS=$func_echo_IFS
2238eca46af7Smrg}
223914330f12Smrg
224014330f12Smrg
2241eca46af7Smrg# func_warning ARG...
2242eca46af7Smrg# -------------------
2243eca46af7Smrg# Libtool warnings are not categorized, so override funclib.sh
2244eca46af7Smrg# func_warning with this simpler definition.
2245eca46af7Smrgfunc_warning ()
224614330f12Smrg{
2247eca46af7Smrg    $debug_cmd
2248eca46af7Smrg
2249eca46af7Smrg    $warning_func ${1+"$@"}
2250eca46af7Smrg}
225114330f12Smrg
225214330f12Smrg
2253eca46af7Smrg## ---------------- ##
2254eca46af7Smrg## Options parsing. ##
2255eca46af7Smrg## ---------------- ##
2256eca46af7Smrg
2257eca46af7Smrg# Hook in the functions to make sure our own options are parsed during
2258eca46af7Smrg# the option parsing loop.
2259eca46af7Smrg
2260eca46af7Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261eca46af7Smrg
2262eca46af7Smrg# Short help message in response to '-h'.
2263eca46af7Smrgusage_message="Options:
2264eca46af7Smrg       --config             show all configuration variables
2265eca46af7Smrg       --debug              enable verbose shell tracing
2266eca46af7Smrg   -n, --dry-run            display commands without modifying any files
2267eca46af7Smrg       --features           display basic configuration information and exit
2268eca46af7Smrg       --mode=MODE          use operation mode MODE
2269eca46af7Smrg       --no-warnings        equivalent to '-Wnone'
2270eca46af7Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271eca46af7Smrg       --quiet, --silent    don't print informational messages
2272eca46af7Smrg       --tag=TAG            use configuration variables from tag TAG
2273eca46af7Smrg   -v, --verbose            print more informational messages than default
2274eca46af7Smrg       --version            print version information
2275eca46af7Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276eca46af7Smrg   -h, --help, --help-all   print short, long, or detailed help message
2277eca46af7Smrg"
227814330f12Smrg
2279eca46af7Smrg# Additional text appended to 'usage_message' in response to '--help'.
228089b0dc75Smrgfunc_help ()
228189b0dc75Smrg{
228289b0dc75Smrg    $debug_cmd
228389b0dc75Smrg
228489b0dc75Smrg    func_usage_message
228589b0dc75Smrg    $ECHO "$long_help_message
228614330f12Smrg
2287eca46af7SmrgMODE must be one of the following:
228814330f12Smrg
2289eca46af7Smrg       clean           remove files from the build directory
2290eca46af7Smrg       compile         compile a source file into a libtool object
2291eca46af7Smrg       execute         automatically set library path, then run a program
2292eca46af7Smrg       finish          complete the installation of libtool libraries
2293eca46af7Smrg       install         install libraries or executables
2294eca46af7Smrg       link            create a library or an executable
2295eca46af7Smrg       uninstall       remove libraries from an installed directory
229614330f12Smrg
2297eca46af7SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298eca46af7Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299eca46af7SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300eca46af7Smrg
2301eca46af7SmrgWhen reporting a bug, please describe a test case to reproduce it and
2302eca46af7Smrginclude the following information:
2303eca46af7Smrg
2304eca46af7Smrg       host-triplet:   $host
2305eca46af7Smrg       shell:          $SHELL
2306eca46af7Smrg       compiler:       $LTCC
2307eca46af7Smrg       compiler flags: $LTCFLAGS
2308eca46af7Smrg       linker:         $LD (gnu? $with_gnu_ld)
2309d87a3195Smrg       version:        $progname (GNU libtool) 2.4.7
2310eca46af7Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311eca46af7Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312eca46af7Smrg
2313eca46af7SmrgReport bugs to <bug-libtool@gnu.org>.
2314eca46af7SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315eca46af7SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
231689b0dc75Smrg    exit 0
231789b0dc75Smrg}
2318eca46af7Smrg
2319eca46af7Smrg
2320eca46af7Smrg# func_lo2o OBJECT-NAME
2321eca46af7Smrg# ---------------------
2322eca46af7Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323eca46af7Smrg# object suffix.
2324eca46af7Smrg
2325eca46af7Smrglo2o=s/\\.lo\$/.$objext/
2326eca46af7Smrgo2lo=s/\\.$objext\$/.lo/
2327eca46af7Smrg
2328eca46af7Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329eca46af7Smrg  eval 'func_lo2o ()
2330eca46af7Smrg  {
2331eca46af7Smrg    case $1 in
2332eca46af7Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333eca46af7Smrg      *   ) func_lo2o_result=$1               ;;
2334eca46af7Smrg    esac
2335eca46af7Smrg  }'
2336eca46af7Smrg
2337eca46af7Smrg  # func_xform LIBOBJ-OR-SOURCE
2338eca46af7Smrg  # ---------------------------
2339eca46af7Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340eca46af7Smrg  # suffix to a '.lo' libtool-object suffix.
2341eca46af7Smrg  eval 'func_xform ()
2342eca46af7Smrg  {
2343eca46af7Smrg    func_xform_result=${1%.*}.lo
2344eca46af7Smrg  }'
2345eca46af7Smrgelse
2346eca46af7Smrg  # ...otherwise fall back to using sed.
2347eca46af7Smrg  func_lo2o ()
2348eca46af7Smrg  {
2349eca46af7Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350eca46af7Smrg  }
2351eca46af7Smrg
2352eca46af7Smrg  func_xform ()
2353eca46af7Smrg  {
2354eca46af7Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355eca46af7Smrg  }
2356eca46af7Smrgfi
235714330f12Smrg
235814330f12Smrg
2359eca46af7Smrg# func_fatal_configuration ARG...
2360eca46af7Smrg# -------------------------------
23612378475aSmrg# Echo program name prefixed message to standard error, followed by
23622378475aSmrg# a configuration failure hint, and exit.
23632378475aSmrgfunc_fatal_configuration ()
23642378475aSmrg{
2365d87a3195Smrg    func_fatal_error ${1+"$@"} \
2366eca46af7Smrg      "See the $PACKAGE documentation for more information." \
2367eca46af7Smrg      "Fatal configuration error."
23682378475aSmrg}
2369ff89ac2bSmrg
237039713583Smrg
23712378475aSmrg# func_config
2372eca46af7Smrg# -----------
23732378475aSmrg# Display the configuration for all the tags in this script.
23742378475aSmrgfunc_config ()
23752378475aSmrg{
23762378475aSmrg    re_begincf='^# ### BEGIN LIBTOOL'
23772378475aSmrg    re_endcf='^# ### END LIBTOOL'
23782378475aSmrg
23792378475aSmrg    # Default configuration.
23802378475aSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
238195b296d0Smrg
238295b296d0Smrg    # Now print the configurations for the tags.
238395b296d0Smrg    for tagname in $taglist; do
23842378475aSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
238595b296d0Smrg    done
2386e6f085baSmrg
23872378475aSmrg    exit $?
23882378475aSmrg}
2389e6f085baSmrg
2390eca46af7Smrg
23912378475aSmrg# func_features
2392eca46af7Smrg# -------------
23932378475aSmrg# Display the features supported by this script.
23942378475aSmrgfunc_features ()
23952378475aSmrg{
239614330f12Smrg    echo "host: $host"
2397eca46af7Smrg    if test yes = "$build_libtool_libs"; then
239814330f12Smrg      echo "enable shared libraries"
239995b296d0Smrg    else
240014330f12Smrg      echo "disable shared libraries"
240195b296d0Smrg    fi
2402eca46af7Smrg    if test yes = "$build_old_libs"; then
240314330f12Smrg      echo "enable static libraries"
240495b296d0Smrg    else
240514330f12Smrg      echo "disable static libraries"
240695b296d0Smrg    fi
24072378475aSmrg
240895b296d0Smrg    exit $?
24092378475aSmrg}
241095b296d0Smrg
2411eca46af7Smrg
2412eca46af7Smrg# func_enable_tag TAGNAME
2413eca46af7Smrg# -----------------------
24142378475aSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
24152378475aSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
24162378475aSmrg# variable here.
24172378475aSmrgfunc_enable_tag ()
24182378475aSmrg{
2419eca46af7Smrg    # Global variable:
2420eca46af7Smrg    tagname=$1
242195b296d0Smrg
2422eca46af7Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423eca46af7Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424eca46af7Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
242539713583Smrg
2426eca46af7Smrg    # Validate tagname.
2427eca46af7Smrg    case $tagname in
2428eca46af7Smrg      *[!-_A-Za-z0-9,/]*)
2429eca46af7Smrg        func_fatal_error "invalid tag name: $tagname"
2430eca46af7Smrg        ;;
2431eca46af7Smrg    esac
243295b296d0Smrg
2433eca46af7Smrg    # Don't test for the "default" C tag, as we know it's
2434eca46af7Smrg    # there but not specially marked.
2435eca46af7Smrg    case $tagname in
2436eca46af7Smrg        CC) ;;
24372378475aSmrg    *)
2438eca46af7Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439eca46af7Smrg	  taglist="$taglist $tagname"
2440eca46af7Smrg
2441eca46af7Smrg	  # Evaluate the configuration.  Be careful to quote the path
2442eca46af7Smrg	  # and the sed script, to avoid splitting on whitespace, but
2443eca46af7Smrg	  # also don't use non-portable quotes within backquotes within
2444eca46af7Smrg	  # quotes we have to do it in 2 steps:
2445eca46af7Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446eca46af7Smrg	  eval "$extractedcf"
2447eca46af7Smrg        else
2448eca46af7Smrg	  func_error "ignoring unknown tag $tagname"
2449eca46af7Smrg        fi
2450eca46af7Smrg        ;;
2451eca46af7Smrg    esac
24522378475aSmrg}
24532378475aSmrg
2454eca46af7Smrg
245514330f12Smrg# func_check_version_match
2456eca46af7Smrg# ------------------------
245714330f12Smrg# Ensure that we are using m4 macros, and libtool script from the same
245814330f12Smrg# release of libtool.
245914330f12Smrgfunc_check_version_match ()
24602378475aSmrg{
2461eca46af7Smrg    if test "$package_revision" != "$macro_revision"; then
2462eca46af7Smrg      if test "$VERSION" != "$macro_version"; then
2463eca46af7Smrg        if test -z "$macro_version"; then
2464eca46af7Smrg          cat >&2 <<_LT_EOF
246514330f12Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
246614330f12Smrg$progname: definition of this LT_INIT comes from an older release.
246714330f12Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
246814330f12Smrg$progname: and run autoconf again.
246914330f12Smrg_LT_EOF
2470eca46af7Smrg        else
2471eca46af7Smrg          cat >&2 <<_LT_EOF
247214330f12Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
247314330f12Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
247414330f12Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
247514330f12Smrg$progname: and run autoconf again.
247614330f12Smrg_LT_EOF
2477eca46af7Smrg        fi
2478eca46af7Smrg      else
2479eca46af7Smrg        cat >&2 <<_LT_EOF
248014330f12Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
248114330f12Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
248214330f12Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
248314330f12Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
248414330f12Smrg_LT_EOF
2485eca46af7Smrg      fi
2486e6f085baSmrg
2487eca46af7Smrg      exit $EXIT_MISMATCH
2488eca46af7Smrg    fi
248914330f12Smrg}
249014330f12Smrg
249114330f12Smrg
2492eca46af7Smrg# libtool_options_prep [ARG]...
2493eca46af7Smrg# -----------------------------
2494eca46af7Smrg# Preparation for options parsed by libtool.
2495eca46af7Smrglibtool_options_prep ()
2496eca46af7Smrg{
2497eca46af7Smrg    $debug_mode
249814330f12Smrg
2499eca46af7Smrg    # Option defaults:
2500eca46af7Smrg    opt_config=false
2501eca46af7Smrg    opt_dlopen=
2502eca46af7Smrg    opt_dry_run=false
2503eca46af7Smrg    opt_help=false
2504eca46af7Smrg    opt_mode=
2505eca46af7Smrg    opt_preserve_dup_deps=false
2506eca46af7Smrg    opt_quiet=false
250714330f12Smrg
2508eca46af7Smrg    nonopt=
2509eca46af7Smrg    preserve_args=
251014330f12Smrg
2511d87a3195Smrg    _G_rc_lt_options_prep=:
2512d87a3195Smrg
2513eca46af7Smrg    # Shorthand for --mode=foo, only valid as the first argument
2514eca46af7Smrg    case $1 in
2515eca46af7Smrg    clean|clea|cle|cl)
2516eca46af7Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517eca46af7Smrg      ;;
2518eca46af7Smrg    compile|compil|compi|comp|com|co|c)
2519eca46af7Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520eca46af7Smrg      ;;
2521eca46af7Smrg    execute|execut|execu|exec|exe|ex|e)
2522eca46af7Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523eca46af7Smrg      ;;
2524eca46af7Smrg    finish|finis|fini|fin|fi|f)
2525eca46af7Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526eca46af7Smrg      ;;
2527eca46af7Smrg    install|instal|insta|inst|ins|in|i)
2528eca46af7Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2529eca46af7Smrg      ;;
2530eca46af7Smrg    link|lin|li|l)
2531eca46af7Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2532eca46af7Smrg      ;;
2533eca46af7Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534eca46af7Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535eca46af7Smrg      ;;
2536d87a3195Smrg    *)
2537d87a3195Smrg      _G_rc_lt_options_prep=false
2538d87a3195Smrg      ;;
2539eca46af7Smrg    esac
2540eca46af7Smrg
2541d87a3195Smrg    if $_G_rc_lt_options_prep; then
2542d87a3195Smrg      # Pass back the list of options.
2543d87a3195Smrg      func_quote eval ${1+"$@"}
2544d87a3195Smrg      libtool_options_prep_result=$func_quote_result
2545d87a3195Smrg    fi
2546eca46af7Smrg}
2547eca46af7Smrgfunc_add_hook func_options_prep libtool_options_prep
254895b296d0Smrg
254914330f12Smrg
2550eca46af7Smrg# libtool_parse_options [ARG]...
2551eca46af7Smrg# ---------------------------------
2552eca46af7Smrg# Provide handling for libtool specific options.
2553eca46af7Smrglibtool_parse_options ()
255414330f12Smrg{
2555eca46af7Smrg    $debug_cmd
25562378475aSmrg
2557d87a3195Smrg    _G_rc_lt_parse_options=false
2558d87a3195Smrg
2559eca46af7Smrg    # Perform our own loop to consume as many options as possible in
2560eca46af7Smrg    # each iteration.
2561eca46af7Smrg    while test $# -gt 0; do
2562d87a3195Smrg      _G_match_lt_parse_options=:
2563eca46af7Smrg      _G_opt=$1
2564eca46af7Smrg      shift
2565eca46af7Smrg      case $_G_opt in
2566eca46af7Smrg        --dry-run|--dryrun|-n)
2567eca46af7Smrg                        opt_dry_run=:
2568eca46af7Smrg                        ;;
2569eca46af7Smrg
2570eca46af7Smrg        --config)       func_config ;;
2571eca46af7Smrg
2572eca46af7Smrg        --dlopen|-dlopen)
2573eca46af7Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574eca46af7Smrg}$1"
2575eca46af7Smrg                        shift
2576eca46af7Smrg                        ;;
2577eca46af7Smrg
2578eca46af7Smrg        --preserve-dup-deps)
2579eca46af7Smrg                        opt_preserve_dup_deps=: ;;
2580eca46af7Smrg
2581eca46af7Smrg        --features)     func_features ;;
2582eca46af7Smrg
2583eca46af7Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584eca46af7Smrg
2585eca46af7Smrg        --help)         opt_help=: ;;
2586eca46af7Smrg
2587eca46af7Smrg        --help-all)     opt_help=': help-all' ;;
2588eca46af7Smrg
2589eca46af7Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590eca46af7Smrg                        opt_mode=$1
2591eca46af7Smrg                        case $1 in
2592eca46af7Smrg                          # Valid mode arguments:
2593eca46af7Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594eca46af7Smrg
2595eca46af7Smrg                          # Catch anything else as an error
2596eca46af7Smrg                          *) func_error "invalid argument for $_G_opt"
2597eca46af7Smrg                             exit_cmd=exit
2598eca46af7Smrg                             break
2599eca46af7Smrg                             ;;
2600eca46af7Smrg                        esac
2601eca46af7Smrg                        shift
2602eca46af7Smrg                        ;;
2603eca46af7Smrg
2604eca46af7Smrg        --no-silent|--no-quiet)
2605eca46af7Smrg                        opt_quiet=false
2606eca46af7Smrg                        func_append preserve_args " $_G_opt"
2607eca46af7Smrg                        ;;
2608eca46af7Smrg
2609eca46af7Smrg        --no-warnings|--no-warning|--no-warn)
2610eca46af7Smrg                        opt_warning=false
2611eca46af7Smrg                        func_append preserve_args " $_G_opt"
2612eca46af7Smrg                        ;;
2613eca46af7Smrg
2614eca46af7Smrg        --no-verbose)
2615eca46af7Smrg                        opt_verbose=false
2616eca46af7Smrg                        func_append preserve_args " $_G_opt"
2617eca46af7Smrg                        ;;
2618eca46af7Smrg
2619eca46af7Smrg        --silent|--quiet)
2620eca46af7Smrg                        opt_quiet=:
2621eca46af7Smrg                        opt_verbose=false
2622eca46af7Smrg                        func_append preserve_args " $_G_opt"
2623eca46af7Smrg                        ;;
2624eca46af7Smrg
2625eca46af7Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626eca46af7Smrg                        opt_tag=$1
2627eca46af7Smrg                        func_append preserve_args " $_G_opt $1"
2628eca46af7Smrg                        func_enable_tag "$1"
2629eca46af7Smrg                        shift
2630eca46af7Smrg                        ;;
2631eca46af7Smrg
2632eca46af7Smrg        --verbose|-v)   opt_quiet=false
2633eca46af7Smrg                        opt_verbose=:
2634eca46af7Smrg                        func_append preserve_args " $_G_opt"
2635eca46af7Smrg                        ;;
2636eca46af7Smrg
2637d87a3195Smrg        # An option not handled by this hook function:
2638d87a3195Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2639d87a3195Smrg                        _G_match_lt_parse_options=false
2640d87a3195Smrg                        break
2641d87a3195Smrg                        ;;
2642eca46af7Smrg      esac
2643d87a3195Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644eca46af7Smrg    done
264514330f12Smrg
2646d87a3195Smrg    if $_G_rc_lt_parse_options; then
2647d87a3195Smrg      # save modified positional parameters for caller
2648d87a3195Smrg      func_quote eval ${1+"$@"}
2649d87a3195Smrg      libtool_parse_options_result=$func_quote_result
2650d87a3195Smrg    fi
2651eca46af7Smrg}
2652eca46af7Smrgfunc_add_hook func_parse_options libtool_parse_options
26532378475aSmrg
265439713583Smrg
26552378475aSmrg
2656eca46af7Smrg# libtool_validate_options [ARG]...
2657eca46af7Smrg# ---------------------------------
2658eca46af7Smrg# Perform any sanity checks on option settings and/or unconsumed
2659eca46af7Smrg# arguments.
2660eca46af7Smrglibtool_validate_options ()
2661eca46af7Smrg{
2662eca46af7Smrg    # save first non-option argument
2663eca46af7Smrg    if test 0 -lt $#; then
2664eca46af7Smrg      nonopt=$1
2665eca46af7Smrg      shift
26662378475aSmrg    fi
26672378475aSmrg
2668eca46af7Smrg    # preserve --debug
2669eca46af7Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
26702378475aSmrg
2671eca46af7Smrg    case $host in
2672eca46af7Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673eca46af7Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674eca46af7Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675eca46af7Smrg        # don't eliminate duplications in $postdeps and $predeps
2676eca46af7Smrg        opt_duplicate_compiler_generated_deps=:
2677eca46af7Smrg        ;;
2678eca46af7Smrg      *)
2679eca46af7Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680eca46af7Smrg        ;;
2681eca46af7Smrg    esac
268295b296d0Smrg
2683eca46af7Smrg    $opt_help || {
2684eca46af7Smrg      # Sanity checks first:
2685eca46af7Smrg      func_check_version_match
2686eca46af7Smrg
2687eca46af7Smrg      test yes != "$build_libtool_libs" \
2688eca46af7Smrg        && test yes != "$build_old_libs" \
2689eca46af7Smrg        && func_fatal_configuration "not configured to build any kind of library"
2690eca46af7Smrg
2691eca46af7Smrg      # Darwin sucks
2692eca46af7Smrg      eval std_shrext=\"$shrext_cmds\"
2693eca46af7Smrg
2694eca46af7Smrg      # Only execute mode is allowed to have -dlopen flags.
2695eca46af7Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696eca46af7Smrg        func_error "unrecognized option '-dlopen'"
2697eca46af7Smrg        $ECHO "$help" 1>&2
2698eca46af7Smrg        exit $EXIT_FAILURE
2699eca46af7Smrg      fi
27002378475aSmrg
2701eca46af7Smrg      # Change the help message to a mode-specific one.
2702eca46af7Smrg      generic_help=$help
2703eca46af7Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704eca46af7Smrg    }
27052378475aSmrg
2706eca46af7Smrg    # Pass back the unparsed argument list
2707d87a3195Smrg    func_quote eval ${1+"$@"}
2708d87a3195Smrg    libtool_validate_options_result=$func_quote_result
270914330f12Smrg}
2710eca46af7Smrgfunc_add_hook func_validate_options libtool_validate_options
27112378475aSmrg
27122378475aSmrg
2713eca46af7Smrg# Process options as early as possible so that --help and --version
2714eca46af7Smrg# can return quickly.
2715eca46af7Smrgfunc_options ${1+"$@"}
2716eca46af7Smrgeval set dummy "$func_options_result"; shift
2717eca46af7Smrg
271895b296d0Smrg
271995b296d0Smrg
272014330f12Smrg## ----------- ##
272114330f12Smrg##    Main.    ##
272214330f12Smrg## ----------- ##
272395b296d0Smrg
2724eca46af7Smrgmagic='%%%MAGIC variable%%%'
2725eca46af7Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2726eca46af7Smrg
2727eca46af7Smrg# Global variables.
2728eca46af7Smrgextracted_archives=
2729eca46af7Smrgextracted_serial=0
2730eca46af7Smrg
2731eca46af7Smrg# If this variable is set in any of the actions, the command in it
2732eca46af7Smrg# will be execed at the end.  This prevents here-documents from being
2733eca46af7Smrg# left over by shells.
2734eca46af7Smrgexec_cmd=
2735eca46af7Smrg
2736eca46af7Smrg
2737eca46af7Smrg# A function that is used when there is no print builtin or printf.
2738eca46af7Smrgfunc_fallback_echo ()
2739eca46af7Smrg{
2740eca46af7Smrg  eval 'cat <<_LTECHO_EOF
2741eca46af7Smrg$1
2742eca46af7Smrg_LTECHO_EOF'
2743eca46af7Smrg}
2744eca46af7Smrg
2745eca46af7Smrg# func_generated_by_libtool
2746eca46af7Smrg# True iff stdin has been generated by Libtool. This function is only
2747eca46af7Smrg# a basic sanity check; it will hardly flush out determined imposters.
2748eca46af7Smrgfunc_generated_by_libtool_p ()
2749eca46af7Smrg{
2750eca46af7Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751eca46af7Smrg}
2752eca46af7Smrg
27532378475aSmrg# func_lalib_p file
2754eca46af7Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27552378475aSmrg# This function is only a basic sanity check; it will hardly flush out
27562378475aSmrg# determined imposters.
27572378475aSmrgfunc_lalib_p ()
27582378475aSmrg{
27592378475aSmrg    test -f "$1" &&
2760eca46af7Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
27612378475aSmrg}
276295b296d0Smrg
27632378475aSmrg# func_lalib_unsafe_p file
2764eca46af7Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27652378475aSmrg# This function implements the same check as func_lalib_p without
27662378475aSmrg# resorting to external programs.  To this end, it redirects stdin and
27672378475aSmrg# closes it afterwards, without saving the original file descriptor.
27682378475aSmrg# As a safety measure, use it only where a negative result would be
2769eca46af7Smrg# fatal anyway.  Works if 'file' does not exist.
27702378475aSmrgfunc_lalib_unsafe_p ()
27712378475aSmrg{
27722378475aSmrg    lalib_p=no
27732378475aSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
27742378475aSmrg	for lalib_p_l in 1 2 3 4
27752378475aSmrg	do
27762378475aSmrg	    read lalib_p_line
2777eca46af7Smrg	    case $lalib_p_line in
27782378475aSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
27792378475aSmrg	    esac
27802378475aSmrg	done
27812378475aSmrg	exec 0<&5 5<&-
27822378475aSmrg    fi
2783eca46af7Smrg    test yes = "$lalib_p"
27842378475aSmrg}
278595b296d0Smrg
27862378475aSmrg# func_ltwrapper_script_p file
27872378475aSmrg# True iff FILE is a libtool wrapper script
27882378475aSmrg# This function is only a basic sanity check; it will hardly flush out
27892378475aSmrg# determined imposters.
27902378475aSmrgfunc_ltwrapper_script_p ()
27912378475aSmrg{
2792eca46af7Smrg    test -f "$1" &&
2793eca46af7Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
27942378475aSmrg}
279595b296d0Smrg
27962378475aSmrg# func_ltwrapper_executable_p file
27972378475aSmrg# True iff FILE is a libtool wrapper executable
27982378475aSmrg# This function is only a basic sanity check; it will hardly flush out
27992378475aSmrg# determined imposters.
28002378475aSmrgfunc_ltwrapper_executable_p ()
28012378475aSmrg{
28022378475aSmrg    func_ltwrapper_exec_suffix=
28032378475aSmrg    case $1 in
28042378475aSmrg    *.exe) ;;
28052378475aSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
28062378475aSmrg    esac
28072378475aSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
28082378475aSmrg}
280939713583Smrg
28102378475aSmrg# func_ltwrapper_scriptname file
28112378475aSmrg# Assumes file is an ltwrapper_executable
28122378475aSmrg# uses $file to determine the appropriate filename for a
28132378475aSmrg# temporary ltwrapper_script.
28142378475aSmrgfunc_ltwrapper_scriptname ()
28152378475aSmrg{
281614330f12Smrg    func_dirname_and_basename "$1" "" "."
281714330f12Smrg    func_stripname '' '.exe' "$func_basename_result"
2818eca46af7Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
28192378475aSmrg}
28202378475aSmrg
28212378475aSmrg# func_ltwrapper_p file
28222378475aSmrg# True iff FILE is a libtool wrapper script or wrapper executable
28232378475aSmrg# This function is only a basic sanity check; it will hardly flush out
28242378475aSmrg# determined imposters.
28252378475aSmrgfunc_ltwrapper_p ()
28262378475aSmrg{
28272378475aSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
28282378475aSmrg}
28292378475aSmrg
28302378475aSmrg
28312378475aSmrg# func_execute_cmds commands fail_cmd
28322378475aSmrg# Execute tilde-delimited COMMANDS.
28332378475aSmrg# If FAIL_CMD is given, eval that upon failure.
28342378475aSmrg# FAIL_CMD may read-access the current command in variable CMD!
28352378475aSmrgfunc_execute_cmds ()
28362378475aSmrg{
2837eca46af7Smrg    $debug_cmd
2838eca46af7Smrg
28392378475aSmrg    save_ifs=$IFS; IFS='~'
28402378475aSmrg    for cmd in $1; do
2841eca46af7Smrg      IFS=$sp$nl
28422378475aSmrg      eval cmd=\"$cmd\"
2843eca46af7Smrg      IFS=$save_ifs
28442378475aSmrg      func_show_eval "$cmd" "${2-:}"
28452378475aSmrg    done
28462378475aSmrg    IFS=$save_ifs
28472378475aSmrg}
28482378475aSmrg
28492378475aSmrg
28502378475aSmrg# func_source file
28512378475aSmrg# Source FILE, adding directory component if necessary.
28522378475aSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
28532378475aSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
28542378475aSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855eca46af7Smrg# 'FILE.' does not work on cygwin managed mounts.
28562378475aSmrgfunc_source ()
28572378475aSmrg{
2858eca46af7Smrg    $debug_cmd
2859eca46af7Smrg
28602378475aSmrg    case $1 in
28612378475aSmrg    */* | *\\*)	. "$1" ;;
28622378475aSmrg    *)		. "./$1" ;;
28632378475aSmrg    esac
28642378475aSmrg}
28652378475aSmrg
28662378475aSmrg
286714330f12Smrg# func_resolve_sysroot PATH
286814330f12Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
286914330f12Smrg# func_resolve_sysroot_result
287014330f12Smrgfunc_resolve_sysroot ()
287114330f12Smrg{
287214330f12Smrg  func_resolve_sysroot_result=$1
287314330f12Smrg  case $func_resolve_sysroot_result in
287414330f12Smrg  =*)
287514330f12Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
287614330f12Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
287714330f12Smrg    ;;
287814330f12Smrg  esac
287914330f12Smrg}
288014330f12Smrg
288114330f12Smrg# func_replace_sysroot PATH
288214330f12Smrg# If PATH begins with the sysroot, replace it with = and
288314330f12Smrg# store the result into func_replace_sysroot_result.
288414330f12Smrgfunc_replace_sysroot ()
288514330f12Smrg{
2886eca46af7Smrg  case $lt_sysroot:$1 in
288714330f12Smrg  ?*:"$lt_sysroot"*)
288814330f12Smrg    func_stripname "$lt_sysroot" '' "$1"
2889eca46af7Smrg    func_replace_sysroot_result='='$func_stripname_result
289014330f12Smrg    ;;
289114330f12Smrg  *)
289214330f12Smrg    # Including no sysroot.
289314330f12Smrg    func_replace_sysroot_result=$1
289414330f12Smrg    ;;
289514330f12Smrg  esac
289614330f12Smrg}
289714330f12Smrg
28982378475aSmrg# func_infer_tag arg
28992378475aSmrg# Infer tagged configuration to use if any are available and
29002378475aSmrg# if one wasn't chosen via the "--tag" command line option.
29012378475aSmrg# Only attempt this if the compiler in the base compile
29022378475aSmrg# command doesn't match the default compiler.
29032378475aSmrg# arg is usually of the form 'gcc ...'
29042378475aSmrgfunc_infer_tag ()
29052378475aSmrg{
2906eca46af7Smrg    $debug_cmd
2907eca46af7Smrg
29082378475aSmrg    if test -n "$available_tags" && test -z "$tagname"; then
29092378475aSmrg      CC_quoted=
29102378475aSmrg      for arg in $CC; do
291114330f12Smrg	func_append_quoted CC_quoted "$arg"
29122378475aSmrg      done
291314330f12Smrg      CC_expanded=`func_echo_all $CC`
291414330f12Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
29152378475aSmrg      case $@ in
29162378475aSmrg      # Blanks in the command may have been stripped by the calling shell,
29172378475aSmrg      # but not from the CC environment variable when configure was run.
291814330f12Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
291914330f12Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
29202378475aSmrg      # Blanks at the start of $base_compile will cause this to fail
29212378475aSmrg      # if we don't check for them as well.
29222378475aSmrg      *)
29232378475aSmrg	for z in $available_tags; do
29242378475aSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
29252378475aSmrg	    # Evaluate the configuration.
2926eca46af7Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
29272378475aSmrg	    CC_quoted=
29282378475aSmrg	    for arg in $CC; do
29292378475aSmrg	      # Double-quote args containing other shell metacharacters.
293014330f12Smrg	      func_append_quoted CC_quoted "$arg"
29312378475aSmrg	    done
293214330f12Smrg	    CC_expanded=`func_echo_all $CC`
293314330f12Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
29342378475aSmrg	    case "$@ " in
293514330f12Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
293614330f12Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
29372378475aSmrg	      # The compiler in the base compile command matches
29382378475aSmrg	      # the one in the tagged configuration.
29392378475aSmrg	      # Assume this is the tagged configuration we want.
29402378475aSmrg	      tagname=$z
29412378475aSmrg	      break
29422378475aSmrg	      ;;
29432378475aSmrg	    esac
29442378475aSmrg	  fi
29452378475aSmrg	done
29462378475aSmrg	# If $tagname still isn't set, then no tagged configuration
29472378475aSmrg	# was found and let the user know that the "--tag" command
29482378475aSmrg	# line option must be used.
29492378475aSmrg	if test -z "$tagname"; then
29502378475aSmrg	  func_echo "unable to infer tagged configuration"
2951eca46af7Smrg	  func_fatal_error "specify a tag with '--tag'"
29522378475aSmrg#	else
29532378475aSmrg#	  func_verbose "using $tagname tagged configuration"
29542378475aSmrg	fi
29552378475aSmrg	;;
29562378475aSmrg      esac
29572378475aSmrg    fi
29582378475aSmrg}
29592378475aSmrg
29602378475aSmrg
29612378475aSmrg
29622378475aSmrg# func_write_libtool_object output_name pic_name nonpic_name
29632378475aSmrg# Create a libtool object file (analogous to a ".la" file),
29642378475aSmrg# but don't create it if we're doing a dry run.
29652378475aSmrgfunc_write_libtool_object ()
29662378475aSmrg{
2967eca46af7Smrg    write_libobj=$1
2968eca46af7Smrg    if test yes = "$build_libtool_libs"; then
2969eca46af7Smrg      write_lobj=\'$2\'
29702378475aSmrg    else
29712378475aSmrg      write_lobj=none
29722378475aSmrg    fi
29732378475aSmrg
2974eca46af7Smrg    if test yes = "$build_old_libs"; then
2975eca46af7Smrg      write_oldobj=\'$3\'
29762378475aSmrg    else
29772378475aSmrg      write_oldobj=none
29782378475aSmrg    fi
29792378475aSmrg
29802378475aSmrg    $opt_dry_run || {
29812378475aSmrg      cat >${write_libobj}T <<EOF
29822378475aSmrg# $write_libobj - a libtool object file
2983eca46af7Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
29842378475aSmrg#
29852378475aSmrg# Please DO NOT delete this file!
29862378475aSmrg# It is necessary for linking the library.
29872378475aSmrg
29882378475aSmrg# Name of the PIC object.
29892378475aSmrgpic_object=$write_lobj
29902378475aSmrg
29912378475aSmrg# Name of the non-PIC object
29922378475aSmrgnon_pic_object=$write_oldobj
29932378475aSmrg
29942378475aSmrgEOF
2995eca46af7Smrg      $MV "${write_libobj}T" "$write_libobj"
29962378475aSmrg    }
29972378475aSmrg}
29982378475aSmrg
299914330f12Smrg
300014330f12Smrg##################################################
300114330f12Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
300214330f12Smrg##################################################
300314330f12Smrg
300414330f12Smrg# func_convert_core_file_wine_to_w32 ARG
300514330f12Smrg# Helper function used by file name conversion functions when $build is *nix,
300614330f12Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
300714330f12Smrg# correctly configured wine environment available, with the winepath program
300814330f12Smrg# in $build's $PATH.
300914330f12Smrg#
301014330f12Smrg# ARG is the $build file name to be converted to w32 format.
301114330f12Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
301214330f12Smrg# be empty on error (or when ARG is empty)
301314330f12Smrgfunc_convert_core_file_wine_to_w32 ()
301414330f12Smrg{
3015eca46af7Smrg  $debug_cmd
3016eca46af7Smrg
3017eca46af7Smrg  func_convert_core_file_wine_to_w32_result=$1
301814330f12Smrg  if test -n "$1"; then
301914330f12Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
302014330f12Smrg    # are forced to check the contents of stdout. On the other hand, if the
302114330f12Smrg    # command is not found, the shell will set an exit code of 127 and print
302214330f12Smrg    # *an error message* to stdout. So we must check for both error code of
302314330f12Smrg    # zero AND non-empty stdout, which explains the odd construction:
302414330f12Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025eca46af7Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
302614330f12Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027eca46af7Smrg        $SED -e "$sed_naive_backslashify"`
302814330f12Smrg    else
302914330f12Smrg      func_convert_core_file_wine_to_w32_result=
303014330f12Smrg    fi
303114330f12Smrg  fi
303214330f12Smrg}
303314330f12Smrg# end: func_convert_core_file_wine_to_w32
303414330f12Smrg
303514330f12Smrg
303614330f12Smrg# func_convert_core_path_wine_to_w32 ARG
303714330f12Smrg# Helper function used by path conversion functions when $build is *nix, and
303814330f12Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
303914330f12Smrg# configured wine environment available, with the winepath program in $build's
304014330f12Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
304114330f12Smrg#
304214330f12Smrg# ARG is path to be converted from $build format to win32.
304314330f12Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
304414330f12Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
304514330f12Smrg# are convertible, then the result may be empty.
304614330f12Smrgfunc_convert_core_path_wine_to_w32 ()
304714330f12Smrg{
3048eca46af7Smrg  $debug_cmd
3049eca46af7Smrg
305014330f12Smrg  # unfortunately, winepath doesn't convert paths, only file names
3051eca46af7Smrg  func_convert_core_path_wine_to_w32_result=
305214330f12Smrg  if test -n "$1"; then
305314330f12Smrg    oldIFS=$IFS
305414330f12Smrg    IFS=:
305514330f12Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
305614330f12Smrg      IFS=$oldIFS
305714330f12Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058eca46af7Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
305914330f12Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060eca46af7Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
306114330f12Smrg        else
306214330f12Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
306314330f12Smrg        fi
306414330f12Smrg      fi
306514330f12Smrg    done
306614330f12Smrg    IFS=$oldIFS
306714330f12Smrg  fi
306814330f12Smrg}
306914330f12Smrg# end: func_convert_core_path_wine_to_w32
307014330f12Smrg
307114330f12Smrg
307214330f12Smrg# func_cygpath ARGS...
307314330f12Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
307414330f12Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
307514330f12Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
307614330f12Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
307714330f12Smrg# file name or path is assumed to be in w32 format, as previously converted
307814330f12Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
307914330f12Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
308014330f12Smrg# Cygwin format). Returns an empty string on error.
308114330f12Smrg#
308214330f12Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
308314330f12Smrg# be converted.
308414330f12Smrg#
308514330f12Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
308614330f12Smrg# environment variable; do not put it in $PATH.
308714330f12Smrgfunc_cygpath ()
308814330f12Smrg{
3089eca46af7Smrg  $debug_cmd
3090eca46af7Smrg
309114330f12Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
309214330f12Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
309314330f12Smrg    if test "$?" -ne 0; then
309414330f12Smrg      # on failure, ensure result is empty
309514330f12Smrg      func_cygpath_result=
309614330f12Smrg    fi
309714330f12Smrg  else
309814330f12Smrg    func_cygpath_result=
3099eca46af7Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
310014330f12Smrg  fi
310114330f12Smrg}
310214330f12Smrg#end: func_cygpath
310314330f12Smrg
310414330f12Smrg
310514330f12Smrg# func_convert_core_msys_to_w32 ARG
310614330f12Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
310714330f12Smrg# result in func_convert_core_msys_to_w32_result.
310814330f12Smrgfunc_convert_core_msys_to_w32 ()
310914330f12Smrg{
3110eca46af7Smrg  $debug_cmd
3111eca46af7Smrg
311214330f12Smrg  # awkward: cmd appends spaces to result
311314330f12Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114eca46af7Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
311514330f12Smrg}
311614330f12Smrg#end: func_convert_core_msys_to_w32
311714330f12Smrg
311814330f12Smrg
311914330f12Smrg# func_convert_file_check ARG1 ARG2
312014330f12Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
312114330f12Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
312214330f12Smrg# func_to_host_file_result to ARG1).
312314330f12Smrgfunc_convert_file_check ()
312414330f12Smrg{
3125eca46af7Smrg  $debug_cmd
3126eca46af7Smrg
3127eca46af7Smrg  if test -z "$2" && test -n "$1"; then
312814330f12Smrg    func_error "Could not determine host file name corresponding to"
3129eca46af7Smrg    func_error "  '$1'"
313014330f12Smrg    func_error "Continuing, but uninstalled executables may not work."
313114330f12Smrg    # Fallback:
3132eca46af7Smrg    func_to_host_file_result=$1
313314330f12Smrg  fi
313414330f12Smrg}
313514330f12Smrg# end func_convert_file_check
313614330f12Smrg
313714330f12Smrg
313814330f12Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
313914330f12Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
314014330f12Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
314114330f12Smrg# func_to_host_file_result to a simplistic fallback value (see below).
314214330f12Smrgfunc_convert_path_check ()
314314330f12Smrg{
3144eca46af7Smrg  $debug_cmd
3145eca46af7Smrg
314614330f12Smrg  if test -z "$4" && test -n "$3"; then
314714330f12Smrg    func_error "Could not determine the host path corresponding to"
3148eca46af7Smrg    func_error "  '$3'"
314914330f12Smrg    func_error "Continuing, but uninstalled executables may not work."
315014330f12Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
315114330f12Smrg    # should not be "improved".  See libtool.info.
315214330f12Smrg    if test "x$1" != "x$2"; then
315314330f12Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
315414330f12Smrg      func_to_host_path_result=`echo "$3" |
315514330f12Smrg        $SED -e "$lt_replace_pathsep_chars"`
315614330f12Smrg    else
3157eca46af7Smrg      func_to_host_path_result=$3
315814330f12Smrg    fi
315914330f12Smrg  fi
316014330f12Smrg}
316114330f12Smrg# end func_convert_path_check
316214330f12Smrg
316314330f12Smrg
316414330f12Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
316514330f12Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
316614330f12Smrg# and appending REPL if ORIG matches BACKPAT.
316714330f12Smrgfunc_convert_path_front_back_pathsep ()
316814330f12Smrg{
3169eca46af7Smrg  $debug_cmd
3170eca46af7Smrg
317114330f12Smrg  case $4 in
3172eca46af7Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
317314330f12Smrg    ;;
317414330f12Smrg  esac
317514330f12Smrg  case $4 in
317614330f12Smrg  $2 ) func_append func_to_host_path_result "$3"
317714330f12Smrg    ;;
317814330f12Smrg  esac
317914330f12Smrg}
318014330f12Smrg# end func_convert_path_front_back_pathsep
318114330f12Smrg
318214330f12Smrg
318314330f12Smrg##################################################
318414330f12Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
318514330f12Smrg##################################################
3186eca46af7Smrg# invoked via '$to_host_file_cmd ARG'
318714330f12Smrg#
318814330f12Smrg# In each case, ARG is the path to be converted from $build to $host format.
318914330f12Smrg# Result will be available in $func_to_host_file_result.
319014330f12Smrg
319114330f12Smrg
319214330f12Smrg# func_to_host_file ARG
319314330f12Smrg# Converts the file name ARG from $build format to $host format. Return result
319414330f12Smrg# in func_to_host_file_result.
319514330f12Smrgfunc_to_host_file ()
319614330f12Smrg{
3197eca46af7Smrg  $debug_cmd
3198eca46af7Smrg
319914330f12Smrg  $to_host_file_cmd "$1"
320014330f12Smrg}
320114330f12Smrg# end func_to_host_file
320214330f12Smrg
320314330f12Smrg
320414330f12Smrg# func_to_tool_file ARG LAZY
320514330f12Smrg# converts the file name ARG from $build format to toolchain format. Return
320614330f12Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
320714330f12Smrg# in (the comma separated) LAZY, no conversion takes place.
320814330f12Smrgfunc_to_tool_file ()
320914330f12Smrg{
3210eca46af7Smrg  $debug_cmd
3211eca46af7Smrg
321214330f12Smrg  case ,$2, in
321314330f12Smrg    *,"$to_tool_file_cmd",*)
321414330f12Smrg      func_to_tool_file_result=$1
321514330f12Smrg      ;;
321614330f12Smrg    *)
321714330f12Smrg      $to_tool_file_cmd "$1"
321814330f12Smrg      func_to_tool_file_result=$func_to_host_file_result
321914330f12Smrg      ;;
322014330f12Smrg  esac
322114330f12Smrg}
322214330f12Smrg# end func_to_tool_file
322314330f12Smrg
322414330f12Smrg
322514330f12Smrg# func_convert_file_noop ARG
322614330f12Smrg# Copy ARG to func_to_host_file_result.
322714330f12Smrgfunc_convert_file_noop ()
322814330f12Smrg{
3229eca46af7Smrg  func_to_host_file_result=$1
323014330f12Smrg}
323114330f12Smrg# end func_convert_file_noop
323214330f12Smrg
323314330f12Smrg
323414330f12Smrg# func_convert_file_msys_to_w32 ARG
323514330f12Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
323614330f12Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
323714330f12Smrg# func_to_host_file_result.
323814330f12Smrgfunc_convert_file_msys_to_w32 ()
323914330f12Smrg{
3240eca46af7Smrg  $debug_cmd
3241eca46af7Smrg
3242eca46af7Smrg  func_to_host_file_result=$1
324314330f12Smrg  if test -n "$1"; then
324414330f12Smrg    func_convert_core_msys_to_w32 "$1"
3245eca46af7Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
324614330f12Smrg  fi
324714330f12Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
324814330f12Smrg}
324914330f12Smrg# end func_convert_file_msys_to_w32
325014330f12Smrg
325114330f12Smrg
325214330f12Smrg# func_convert_file_cygwin_to_w32 ARG
325314330f12Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
325414330f12Smrg# func_to_host_file_result.
325514330f12Smrgfunc_convert_file_cygwin_to_w32 ()
325614330f12Smrg{
3257eca46af7Smrg  $debug_cmd
3258eca46af7Smrg
3259eca46af7Smrg  func_to_host_file_result=$1
326014330f12Smrg  if test -n "$1"; then
326114330f12Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
326214330f12Smrg    # LT_CYGPATH in this case.
326314330f12Smrg    func_to_host_file_result=`cygpath -m "$1"`
326414330f12Smrg  fi
326514330f12Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
326614330f12Smrg}
326714330f12Smrg# end func_convert_file_cygwin_to_w32
326814330f12Smrg
326914330f12Smrg
327014330f12Smrg# func_convert_file_nix_to_w32 ARG
327114330f12Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
327214330f12Smrg# and a working winepath. Returns result in func_to_host_file_result.
327314330f12Smrgfunc_convert_file_nix_to_w32 ()
327414330f12Smrg{
3275eca46af7Smrg  $debug_cmd
3276eca46af7Smrg
3277eca46af7Smrg  func_to_host_file_result=$1
327814330f12Smrg  if test -n "$1"; then
327914330f12Smrg    func_convert_core_file_wine_to_w32 "$1"
3280eca46af7Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
328114330f12Smrg  fi
328214330f12Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
328314330f12Smrg}
328414330f12Smrg# end func_convert_file_nix_to_w32
328514330f12Smrg
328614330f12Smrg
328714330f12Smrg# func_convert_file_msys_to_cygwin ARG
328814330f12Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
328914330f12Smrg# Returns result in func_to_host_file_result.
329014330f12Smrgfunc_convert_file_msys_to_cygwin ()
329114330f12Smrg{
3292eca46af7Smrg  $debug_cmd
3293eca46af7Smrg
3294eca46af7Smrg  func_to_host_file_result=$1
329514330f12Smrg  if test -n "$1"; then
329614330f12Smrg    func_convert_core_msys_to_w32 "$1"
329714330f12Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298eca46af7Smrg    func_to_host_file_result=$func_cygpath_result
329914330f12Smrg  fi
330014330f12Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
330114330f12Smrg}
330214330f12Smrg# end func_convert_file_msys_to_cygwin
330314330f12Smrg
330414330f12Smrg
330514330f12Smrg# func_convert_file_nix_to_cygwin ARG
330614330f12Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
330714330f12Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
330814330f12Smrg# in func_to_host_file_result.
330914330f12Smrgfunc_convert_file_nix_to_cygwin ()
331014330f12Smrg{
3311eca46af7Smrg  $debug_cmd
3312eca46af7Smrg
3313eca46af7Smrg  func_to_host_file_result=$1
331414330f12Smrg  if test -n "$1"; then
331514330f12Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
331614330f12Smrg    func_convert_core_file_wine_to_w32 "$1"
331714330f12Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318eca46af7Smrg    func_to_host_file_result=$func_cygpath_result
331914330f12Smrg  fi
332014330f12Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
332114330f12Smrg}
332214330f12Smrg# end func_convert_file_nix_to_cygwin
332314330f12Smrg
332414330f12Smrg
332514330f12Smrg#############################################
332614330f12Smrg# $build to $host PATH CONVERSION FUNCTIONS #
332714330f12Smrg#############################################
3328eca46af7Smrg# invoked via '$to_host_path_cmd ARG'
332914330f12Smrg#
333014330f12Smrg# In each case, ARG is the path to be converted from $build to $host format.
333114330f12Smrg# The result will be available in $func_to_host_path_result.
333214330f12Smrg#
333314330f12Smrg# Path separators are also converted from $build format to $host format.  If
333414330f12Smrg# ARG begins or ends with a path separator character, it is preserved (but
333514330f12Smrg# converted to $host format) on output.
333614330f12Smrg#
333714330f12Smrg# All path conversion functions are named using the following convention:
333814330f12Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
333914330f12Smrg#   path conversion function         : func_convert_path_X_to_Y ()
334014330f12Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
334114330f12Smrg# same.  If conversion functions are added for new $build/$host combinations,
334214330f12Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
334314330f12Smrg# will break.
334414330f12Smrg
334514330f12Smrg
334614330f12Smrg# func_init_to_host_path_cmd
334714330f12Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
334814330f12Smrg# appropriate value, based on the value of $to_host_file_cmd.
334914330f12Smrgto_host_path_cmd=
335014330f12Smrgfunc_init_to_host_path_cmd ()
335114330f12Smrg{
3352eca46af7Smrg  $debug_cmd
3353eca46af7Smrg
335414330f12Smrg  if test -z "$to_host_path_cmd"; then
335514330f12Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356eca46af7Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
335714330f12Smrg  fi
335814330f12Smrg}
335914330f12Smrg
336014330f12Smrg
336114330f12Smrg# func_to_host_path ARG
336214330f12Smrg# Converts the path ARG from $build format to $host format. Return result
336314330f12Smrg# in func_to_host_path_result.
336414330f12Smrgfunc_to_host_path ()
336514330f12Smrg{
3366eca46af7Smrg  $debug_cmd
3367eca46af7Smrg
336814330f12Smrg  func_init_to_host_path_cmd
336914330f12Smrg  $to_host_path_cmd "$1"
337014330f12Smrg}
337114330f12Smrg# end func_to_host_path
337214330f12Smrg
337314330f12Smrg
337414330f12Smrg# func_convert_path_noop ARG
337514330f12Smrg# Copy ARG to func_to_host_path_result.
337614330f12Smrgfunc_convert_path_noop ()
337714330f12Smrg{
3378eca46af7Smrg  func_to_host_path_result=$1
337914330f12Smrg}
338014330f12Smrg# end func_convert_path_noop
338114330f12Smrg
338214330f12Smrg
338314330f12Smrg# func_convert_path_msys_to_w32 ARG
338414330f12Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
338514330f12Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
338614330f12Smrg# func_to_host_path_result.
338714330f12Smrgfunc_convert_path_msys_to_w32 ()
338814330f12Smrg{
3389eca46af7Smrg  $debug_cmd
3390eca46af7Smrg
3391eca46af7Smrg  func_to_host_path_result=$1
339214330f12Smrg  if test -n "$1"; then
339314330f12Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
339414330f12Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
339514330f12Smrg    # and winepath ignores them completely.
339614330f12Smrg    func_stripname : : "$1"
339714330f12Smrg    func_to_host_path_tmp1=$func_stripname_result
339814330f12Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399eca46af7Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
340014330f12Smrg    func_convert_path_check : ";" \
340114330f12Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
340214330f12Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
340314330f12Smrg  fi
340414330f12Smrg}
340514330f12Smrg# end func_convert_path_msys_to_w32
340614330f12Smrg
340714330f12Smrg
340814330f12Smrg# func_convert_path_cygwin_to_w32 ARG
340914330f12Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
341014330f12Smrg# func_to_host_file_result.
341114330f12Smrgfunc_convert_path_cygwin_to_w32 ()
341214330f12Smrg{
3413eca46af7Smrg  $debug_cmd
3414eca46af7Smrg
3415eca46af7Smrg  func_to_host_path_result=$1
341614330f12Smrg  if test -n "$1"; then
341714330f12Smrg    # See func_convert_path_msys_to_w32:
341814330f12Smrg    func_stripname : : "$1"
341914330f12Smrg    func_to_host_path_tmp1=$func_stripname_result
342014330f12Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
342114330f12Smrg    func_convert_path_check : ";" \
342214330f12Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
342314330f12Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
342414330f12Smrg  fi
342514330f12Smrg}
342614330f12Smrg# end func_convert_path_cygwin_to_w32
342714330f12Smrg
342814330f12Smrg
342914330f12Smrg# func_convert_path_nix_to_w32 ARG
343014330f12Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
343114330f12Smrg# a working winepath.  Returns result in func_to_host_file_result.
343214330f12Smrgfunc_convert_path_nix_to_w32 ()
343314330f12Smrg{
3434eca46af7Smrg  $debug_cmd
3435eca46af7Smrg
3436eca46af7Smrg  func_to_host_path_result=$1
343714330f12Smrg  if test -n "$1"; then
343814330f12Smrg    # See func_convert_path_msys_to_w32:
343914330f12Smrg    func_stripname : : "$1"
344014330f12Smrg    func_to_host_path_tmp1=$func_stripname_result
344114330f12Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442eca46af7Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
344314330f12Smrg    func_convert_path_check : ";" \
344414330f12Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
344514330f12Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
344614330f12Smrg  fi
344714330f12Smrg}
344814330f12Smrg# end func_convert_path_nix_to_w32
344914330f12Smrg
345014330f12Smrg
345114330f12Smrg# func_convert_path_msys_to_cygwin ARG
345214330f12Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
345314330f12Smrg# Returns result in func_to_host_file_result.
345414330f12Smrgfunc_convert_path_msys_to_cygwin ()
345514330f12Smrg{
3456eca46af7Smrg  $debug_cmd
3457eca46af7Smrg
3458eca46af7Smrg  func_to_host_path_result=$1
345914330f12Smrg  if test -n "$1"; then
346014330f12Smrg    # See func_convert_path_msys_to_w32:
346114330f12Smrg    func_stripname : : "$1"
346214330f12Smrg    func_to_host_path_tmp1=$func_stripname_result
346314330f12Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
346414330f12Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465eca46af7Smrg    func_to_host_path_result=$func_cygpath_result
346614330f12Smrg    func_convert_path_check : : \
346714330f12Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
346814330f12Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
346914330f12Smrg  fi
347014330f12Smrg}
347114330f12Smrg# end func_convert_path_msys_to_cygwin
347214330f12Smrg
347314330f12Smrg
347414330f12Smrg# func_convert_path_nix_to_cygwin ARG
347514330f12Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
347614330f12Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
347714330f12Smrg# func_to_host_file_result.
347814330f12Smrgfunc_convert_path_nix_to_cygwin ()
347914330f12Smrg{
3480eca46af7Smrg  $debug_cmd
3481eca46af7Smrg
3482eca46af7Smrg  func_to_host_path_result=$1
348314330f12Smrg  if test -n "$1"; then
348414330f12Smrg    # Remove leading and trailing path separator characters from
348514330f12Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
348614330f12Smrg    # into '.;' and ';.', and winepath ignores them completely.
348714330f12Smrg    func_stripname : : "$1"
348814330f12Smrg    func_to_host_path_tmp1=$func_stripname_result
348914330f12Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
349014330f12Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491eca46af7Smrg    func_to_host_path_result=$func_cygpath_result
349214330f12Smrg    func_convert_path_check : : \
349314330f12Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
349414330f12Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
349514330f12Smrg  fi
349614330f12Smrg}
349714330f12Smrg# end func_convert_path_nix_to_cygwin
349814330f12Smrg
349914330f12Smrg
3500eca46af7Smrg# func_dll_def_p FILE
3501eca46af7Smrg# True iff FILE is a Windows DLL '.def' file.
3502eca46af7Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503eca46af7Smrgfunc_dll_def_p ()
3504eca46af7Smrg{
3505eca46af7Smrg  $debug_cmd
3506eca46af7Smrg
3507eca46af7Smrg  func_dll_def_p_tmp=`$SED -n \
3508eca46af7Smrg    -e 's/^[	 ]*//' \
3509eca46af7Smrg    -e '/^\(;.*\)*$/d' \
3510eca46af7Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511eca46af7Smrg    -e q \
3512eca46af7Smrg    "$1"`
3513eca46af7Smrg  test DEF = "$func_dll_def_p_tmp"
3514eca46af7Smrg}
3515eca46af7Smrg
3516eca46af7Smrg
35172378475aSmrg# func_mode_compile arg...
35182378475aSmrgfunc_mode_compile ()
35192378475aSmrg{
3520eca46af7Smrg    $debug_cmd
3521eca46af7Smrg
35222378475aSmrg    # Get the compilation command and the source file.
35232378475aSmrg    base_compile=
3524eca46af7Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
35252378475aSmrg    suppress_opt=yes
35262378475aSmrg    suppress_output=
35272378475aSmrg    arg_mode=normal
35282378475aSmrg    libobj=
35292378475aSmrg    later=
35302378475aSmrg    pie_flag=
35312378475aSmrg
35322378475aSmrg    for arg
35332378475aSmrg    do
35342378475aSmrg      case $arg_mode in
35352378475aSmrg      arg  )
35362378475aSmrg	# do not "continue".  Instead, add this to base_compile
3537eca46af7Smrg	lastarg=$arg
35382378475aSmrg	arg_mode=normal
35392378475aSmrg	;;
35402378475aSmrg
35412378475aSmrg      target )
3542eca46af7Smrg	libobj=$arg
35432378475aSmrg	arg_mode=normal
35442378475aSmrg	continue
35452378475aSmrg	;;
35462378475aSmrg
35472378475aSmrg      normal )
35482378475aSmrg	# Accept any command-line options.
35492378475aSmrg	case $arg in
35502378475aSmrg	-o)
35512378475aSmrg	  test -n "$libobj" && \
3552eca46af7Smrg	    func_fatal_error "you cannot specify '-o' more than once"
35532378475aSmrg	  arg_mode=target
35542378475aSmrg	  continue
35552378475aSmrg	  ;;
35562378475aSmrg
35572378475aSmrg	-pie | -fpie | -fPIE)
355814330f12Smrg          func_append pie_flag " $arg"
35592378475aSmrg	  continue
35602378475aSmrg	  ;;
35612378475aSmrg
35622378475aSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
356314330f12Smrg	  func_append later " $arg"
35642378475aSmrg	  continue
35652378475aSmrg	  ;;
35662378475aSmrg
35672378475aSmrg	-no-suppress)
356895b296d0Smrg	  suppress_opt=no
356995b296d0Smrg	  continue
357095b296d0Smrg	  ;;
357195b296d0Smrg
357295b296d0Smrg	-Xcompiler)
357395b296d0Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
357495b296d0Smrg	  continue      #  The current "srcfile" will either be retained or
357595b296d0Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
357695b296d0Smrg
357795b296d0Smrg	-Wc,*)
35782378475aSmrg	  func_stripname '-Wc,' '' "$arg"
35792378475aSmrg	  args=$func_stripname_result
358095b296d0Smrg	  lastarg=
3581eca46af7Smrg	  save_ifs=$IFS; IFS=,
35822378475aSmrg	  for arg in $args; do
3583eca46af7Smrg	    IFS=$save_ifs
358414330f12Smrg	    func_append_quoted lastarg "$arg"
358595b296d0Smrg	  done
3586eca46af7Smrg	  IFS=$save_ifs
35872378475aSmrg	  func_stripname ' ' '' "$lastarg"
35882378475aSmrg	  lastarg=$func_stripname_result
358995b296d0Smrg
359095b296d0Smrg	  # Add the arguments to base_compile.
359114330f12Smrg	  func_append base_compile " $lastarg"
359295b296d0Smrg	  continue
359395b296d0Smrg	  ;;
359495b296d0Smrg
35952378475aSmrg	*)
359695b296d0Smrg	  # Accept the current argument as the source file.
359795b296d0Smrg	  # The previous "srcfile" becomes the current argument.
359895b296d0Smrg	  #
3599eca46af7Smrg	  lastarg=$srcfile
3600eca46af7Smrg	  srcfile=$arg
360195b296d0Smrg	  ;;
360295b296d0Smrg	esac  #  case $arg
360395b296d0Smrg	;;
360495b296d0Smrg      esac    #  case $arg_mode
360595b296d0Smrg
360695b296d0Smrg      # Aesthetically quote the previous argument.
360714330f12Smrg      func_append_quoted base_compile "$lastarg"
360895b296d0Smrg    done # for arg
360995b296d0Smrg
361095b296d0Smrg    case $arg_mode in
361195b296d0Smrg    arg)
36122378475aSmrg      func_fatal_error "you must specify an argument for -Xcompile"
361395b296d0Smrg      ;;
361495b296d0Smrg    target)
3615eca46af7Smrg      func_fatal_error "you must specify a target with '-o'"
361695b296d0Smrg      ;;
361795b296d0Smrg    *)
361895b296d0Smrg      # Get the name of the library object.
36192378475aSmrg      test -z "$libobj" && {
36202378475aSmrg	func_basename "$srcfile"
3621eca46af7Smrg	libobj=$func_basename_result
36222378475aSmrg      }
362395b296d0Smrg      ;;
362495b296d0Smrg    esac
362595b296d0Smrg
362695b296d0Smrg    # Recognize several different file suffixes.
362795b296d0Smrg    # If the user specifies -o file.o, it is replaced with file.lo
362895b296d0Smrg    case $libobj in
36292378475aSmrg    *.[cCFSifmso] | \
36302378475aSmrg    *.ada | *.adb | *.ads | *.asm | \
36312378475aSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632eca46af7Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
36332378475aSmrg      func_xform "$libobj"
36342378475aSmrg      libobj=$func_xform_result
36352378475aSmrg      ;;
363695b296d0Smrg    esac
363795b296d0Smrg
363895b296d0Smrg    case $libobj in
36392378475aSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
364095b296d0Smrg    *)
3641eca46af7Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
364295b296d0Smrg      ;;
364395b296d0Smrg    esac
364495b296d0Smrg
364595b296d0Smrg    func_infer_tag $base_compile
364695b296d0Smrg
364795b296d0Smrg    for arg in $later; do
364895b296d0Smrg      case $arg in
36492378475aSmrg      -shared)
3650eca46af7Smrg	test yes = "$build_libtool_libs" \
3651eca46af7Smrg	  || func_fatal_configuration "cannot build a shared library"
36522378475aSmrg	build_old_libs=no
36532378475aSmrg	continue
36542378475aSmrg	;;
36552378475aSmrg
365695b296d0Smrg      -static)
36572378475aSmrg	build_libtool_libs=no
365895b296d0Smrg	build_old_libs=yes
365995b296d0Smrg	continue
366095b296d0Smrg	;;
366195b296d0Smrg
366295b296d0Smrg      -prefer-pic)
366395b296d0Smrg	pic_mode=yes
366495b296d0Smrg	continue
366595b296d0Smrg	;;
366695b296d0Smrg
366795b296d0Smrg      -prefer-non-pic)
366895b296d0Smrg	pic_mode=no
366995b296d0Smrg	continue
367095b296d0Smrg	;;
367195b296d0Smrg      esac
367295b296d0Smrg    done
367395b296d0Smrg
3674d87a3195Smrg    func_quote_arg pretty "$libobj"
3675d87a3195Smrg    test "X$libobj" != "X$func_quote_arg_result" \
36762378475aSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677eca46af7Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
36782378475aSmrg    func_dirname_and_basename "$obj" "/" ""
3679eca46af7Smrg    objname=$func_basename_result
3680eca46af7Smrg    xdir=$func_dirname_result
3681eca46af7Smrg    lobj=$xdir$objdir/$objname
368295b296d0Smrg
36832378475aSmrg    test -z "$base_compile" && \
36842378475aSmrg      func_fatal_help "you must specify a compilation command"
368595b296d0Smrg
368695b296d0Smrg    # Delete any leftover library objects.
3687eca46af7Smrg    if test yes = "$build_old_libs"; then
368895b296d0Smrg      removelist="$obj $lobj $libobj ${libobj}T"
368995b296d0Smrg    else
369095b296d0Smrg      removelist="$lobj $libobj ${libobj}T"
369195b296d0Smrg    fi
369295b296d0Smrg
369395b296d0Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
369495b296d0Smrg    case $host_os in
36952378475aSmrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
369695b296d0Smrg      pic_mode=default
369795b296d0Smrg      ;;
369895b296d0Smrg    esac
3699eca46af7Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
370095b296d0Smrg      # non-PIC code in shared libraries is not supported
370195b296d0Smrg      pic_mode=default
370295b296d0Smrg    fi
370395b296d0Smrg
370495b296d0Smrg    # Calculate the filename of the output object if compiler does
370595b296d0Smrg    # not support -o with -c
3706eca46af7Smrg    if test no = "$compiler_c_o"; then
3707eca46af7Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708eca46af7Smrg      lockfile=$output_obj.lock
370995b296d0Smrg    else
371095b296d0Smrg      output_obj=
371195b296d0Smrg      need_locks=no
371295b296d0Smrg      lockfile=
371395b296d0Smrg    fi
371495b296d0Smrg
371595b296d0Smrg    # Lock this critical section if it is needed
371695b296d0Smrg    # We use this script file to make the link, it avoids creating a new file
3717eca46af7Smrg    if test yes = "$need_locks"; then
37182378475aSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
37192378475aSmrg	func_echo "Waiting for $lockfile to be removed"
372095b296d0Smrg	sleep 2
372195b296d0Smrg      done
3722eca46af7Smrg    elif test warn = "$need_locks"; then
372395b296d0Smrg      if test -f "$lockfile"; then
37242378475aSmrg	$ECHO "\
372595b296d0Smrg*** ERROR, $lockfile exists and contains:
372695b296d0Smrg`cat $lockfile 2>/dev/null`
372795b296d0Smrg
372895b296d0SmrgThis indicates that another process is trying to use the same
372995b296d0Smrgtemporary object file, and libtool could not work around it because
3730eca46af7Smrgyour compiler does not support '-c' and '-o' together.  If you
373195b296d0Smrgrepeat this compilation, it may succeed, by chance, but you had better
373295b296d0Smrgavoid parallel builds (make -j) in this platform, or get a better
373395b296d0Smrgcompiler."
373495b296d0Smrg
37352378475aSmrg	$opt_dry_run || $RM $removelist
373695b296d0Smrg	exit $EXIT_FAILURE
373795b296d0Smrg      fi
373814330f12Smrg      func_append removelist " $output_obj"
37392378475aSmrg      $ECHO "$srcfile" > "$lockfile"
374095b296d0Smrg    fi
374195b296d0Smrg
37422378475aSmrg    $opt_dry_run || $RM $removelist
374314330f12Smrg    func_append removelist " $lockfile"
37442378475aSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
37452378475aSmrg
374614330f12Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
374714330f12Smrg    srcfile=$func_to_tool_file_result
3748d87a3195Smrg    func_quote_arg pretty "$srcfile"
3749d87a3195Smrg    qsrcfile=$func_quote_arg_result
375095b296d0Smrg
375195b296d0Smrg    # Only build a PIC object if we are building libtool libraries.
3752eca46af7Smrg    if test yes = "$build_libtool_libs"; then
375395b296d0Smrg      # Without this assignment, base_compile gets emptied.
375495b296d0Smrg      fbsd_hideous_sh_bug=$base_compile
375595b296d0Smrg
3756eca46af7Smrg      if test no != "$pic_mode"; then
375795b296d0Smrg	command="$base_compile $qsrcfile $pic_flag"
375895b296d0Smrg      else
375995b296d0Smrg	# Don't build PIC code
376095b296d0Smrg	command="$base_compile $qsrcfile"
376195b296d0Smrg      fi
376295b296d0Smrg
37632378475aSmrg      func_mkdir_p "$xdir$objdir"
376495b296d0Smrg
376595b296d0Smrg      if test -z "$output_obj"; then
376695b296d0Smrg	# Place PIC objects in $objdir
376714330f12Smrg	func_append command " -o $lobj"
376895b296d0Smrg      fi
376995b296d0Smrg
37702378475aSmrg      func_show_eval_locale "$command"	\
37712378475aSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
377295b296d0Smrg
3773eca46af7Smrg      if test warn = "$need_locks" &&
377495b296d0Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
37752378475aSmrg	$ECHO "\
377695b296d0Smrg*** ERROR, $lockfile contains:
377795b296d0Smrg`cat $lockfile 2>/dev/null`
377895b296d0Smrg
377995b296d0Smrgbut it should contain:
378095b296d0Smrg$srcfile
378195b296d0Smrg
378295b296d0SmrgThis indicates that another process is trying to use the same
378395b296d0Smrgtemporary object file, and libtool could not work around it because
3784eca46af7Smrgyour compiler does not support '-c' and '-o' together.  If you
378595b296d0Smrgrepeat this compilation, it may succeed, by chance, but you had better
378695b296d0Smrgavoid parallel builds (make -j) in this platform, or get a better
378795b296d0Smrgcompiler."
378895b296d0Smrg
37892378475aSmrg	$opt_dry_run || $RM $removelist
379095b296d0Smrg	exit $EXIT_FAILURE
379195b296d0Smrg      fi
379295b296d0Smrg
379395b296d0Smrg      # Just move the object if needed, then go on to compile the next one
379495b296d0Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
37952378475aSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
37962378475aSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
379795b296d0Smrg      fi
379895b296d0Smrg
379995b296d0Smrg      # Allow error messages only from the first compilation.
3800eca46af7Smrg      if test yes = "$suppress_opt"; then
38012378475aSmrg	suppress_output=' >/dev/null 2>&1'
380295b296d0Smrg      fi
380395b296d0Smrg    fi
380495b296d0Smrg
380595b296d0Smrg    # Only build a position-dependent object if we build old libraries.
3806eca46af7Smrg    if test yes = "$build_old_libs"; then
3807eca46af7Smrg      if test yes != "$pic_mode"; then
380895b296d0Smrg	# Don't build PIC code
38092378475aSmrg	command="$base_compile $qsrcfile$pie_flag"
381095b296d0Smrg      else
381195b296d0Smrg	command="$base_compile $qsrcfile $pic_flag"
381295b296d0Smrg      fi
3813eca46af7Smrg      if test yes = "$compiler_c_o"; then
381414330f12Smrg	func_append command " -o $obj"
381595b296d0Smrg      fi
381695b296d0Smrg
381795b296d0Smrg      # Suppress compiler output if we already did a PIC compilation.
381814330f12Smrg      func_append command "$suppress_output"
38192378475aSmrg      func_show_eval_locale "$command" \
38202378475aSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
382195b296d0Smrg
3822eca46af7Smrg      if test warn = "$need_locks" &&
382395b296d0Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
38242378475aSmrg	$ECHO "\
382595b296d0Smrg*** ERROR, $lockfile contains:
382695b296d0Smrg`cat $lockfile 2>/dev/null`
382795b296d0Smrg
382895b296d0Smrgbut it should contain:
382995b296d0Smrg$srcfile
383095b296d0Smrg
383195b296d0SmrgThis indicates that another process is trying to use the same
383295b296d0Smrgtemporary object file, and libtool could not work around it because
3833eca46af7Smrgyour compiler does not support '-c' and '-o' together.  If you
383495b296d0Smrgrepeat this compilation, it may succeed, by chance, but you had better
383595b296d0Smrgavoid parallel builds (make -j) in this platform, or get a better
383695b296d0Smrgcompiler."
383795b296d0Smrg
38382378475aSmrg	$opt_dry_run || $RM $removelist
383995b296d0Smrg	exit $EXIT_FAILURE
384095b296d0Smrg      fi
384195b296d0Smrg
384295b296d0Smrg      # Just move the object if needed
384395b296d0Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
38442378475aSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
38452378475aSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
384695b296d0Smrg      fi
384795b296d0Smrg    fi
384895b296d0Smrg
38492378475aSmrg    $opt_dry_run || {
38502378475aSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
385195b296d0Smrg
38522378475aSmrg      # Unlock the critical section if it was locked
3853eca46af7Smrg      if test no != "$need_locks"; then
38542378475aSmrg	removelist=$lockfile
38552378475aSmrg        $RM "$lockfile"
38562378475aSmrg      fi
38572378475aSmrg    }
385895b296d0Smrg
385995b296d0Smrg    exit $EXIT_SUCCESS
38602378475aSmrg}
386195b296d0Smrg
38622378475aSmrg$opt_help || {
3863eca46af7Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
38642378475aSmrg}
386595b296d0Smrg
38662378475aSmrgfunc_mode_help ()
38672378475aSmrg{
38682378475aSmrg    # We need to display help for each of the modes.
386914330f12Smrg    case $opt_mode in
38702378475aSmrg      "")
38712378475aSmrg        # Generic help is extracted from the usage comments
38722378475aSmrg        # at the start of this file.
38732378475aSmrg        func_help
38742378475aSmrg        ;;
387595b296d0Smrg
38762378475aSmrg      clean)
38772378475aSmrg        $ECHO \
38782378475aSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
387995b296d0Smrg
38802378475aSmrgRemove files from the build directory.
388195b296d0Smrg
38822378475aSmrgRM is the name of the program to use to delete files associated with each FILE
3883eca46af7Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
38842378475aSmrgto RM.
388595b296d0Smrg
38862378475aSmrgIf FILE is a libtool library, object or program, all the files associated
38872378475aSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
38882378475aSmrg        ;;
388995b296d0Smrg
38902378475aSmrg      compile)
38912378475aSmrg      $ECHO \
38922378475aSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
389395b296d0Smrg
38942378475aSmrgCompile a source file into a libtool library object.
389595b296d0Smrg
38962378475aSmrgThis mode accepts the following additional options:
389795b296d0Smrg
38982378475aSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
38992378475aSmrg  -no-suppress      do not suppress compiler output for multiple passes
390014330f12Smrg  -prefer-pic       try to build PIC objects only
390114330f12Smrg  -prefer-non-pic   try to build non-PIC objects only
3902eca46af7Smrg  -shared           do not build a '.o' file suitable for static linking
3903eca46af7Smrg  -static           only build a '.o' file suitable for static linking
3904d87a3195Smrg  -Wc,FLAG
3905d87a3195Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
390695b296d0Smrg
3907eca46af7SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
39082378475aSmrgfrom the given SOURCEFILE.
390995b296d0Smrg
39102378475aSmrgThe output file name is determined by removing the directory component from
3911eca46af7SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912eca46af7Smrglibrary object suffix, '.lo'."
39132378475aSmrg        ;;
391495b296d0Smrg
39152378475aSmrg      execute)
39162378475aSmrg        $ECHO \
39172378475aSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
391895b296d0Smrg
39192378475aSmrgAutomatically set library path, then run a program.
392095b296d0Smrg
39212378475aSmrgThis mode accepts the following additional options:
392295b296d0Smrg
39232378475aSmrg  -dlopen FILE      add the directory containing FILE to the library path
392495b296d0Smrg
3925eca46af7SmrgThis mode sets the library path environment variable according to '-dlopen'
39262378475aSmrgflags.
392795b296d0Smrg
39282378475aSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
39292378475aSmrginto their corresponding uninstalled binary, and any of their required library
39302378475aSmrgdirectories are added to the library path.
393195b296d0Smrg
39322378475aSmrgThen, COMMAND is executed, with ARGS as arguments."
39332378475aSmrg        ;;
393495b296d0Smrg
39352378475aSmrg      finish)
39362378475aSmrg        $ECHO \
39372378475aSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
393895b296d0Smrg
39392378475aSmrgComplete the installation of libtool libraries.
394095b296d0Smrg
39412378475aSmrgEach LIBDIR is a directory that contains libtool libraries.
394295b296d0Smrg
39432378475aSmrgThe commands that this mode executes may require superuser privileges.  Use
3944eca46af7Smrgthe '--dry-run' option if you just want to see what would be executed."
39452378475aSmrg        ;;
394695b296d0Smrg
39472378475aSmrg      install)
39482378475aSmrg        $ECHO \
39492378475aSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
395095b296d0Smrg
39512378475aSmrgInstall executables or libraries.
395295b296d0Smrg
39532378475aSmrgINSTALL-COMMAND is the installation command.  The first component should be
3954eca46af7Smrgeither the 'install' or 'cp' program.
395595b296d0Smrg
39562378475aSmrgThe following components of INSTALL-COMMAND are treated specially:
395795b296d0Smrg
395814330f12Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
395995b296d0Smrg
39602378475aSmrgThe rest of the components are interpreted as arguments to that command (only
39612378475aSmrgBSD-compatible install options are recognized)."
39622378475aSmrg        ;;
396395b296d0Smrg
39642378475aSmrg      link)
39652378475aSmrg        $ECHO \
39662378475aSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
396795b296d0Smrg
39682378475aSmrgLink object files or libraries together to form another library, or to
39692378475aSmrgcreate an executable program.
397095b296d0Smrg
39712378475aSmrgLINK-COMMAND is a command using the C compiler that you would use to create
39722378475aSmrga program from several object files.
397395b296d0Smrg
39742378475aSmrgThe following components of LINK-COMMAND are treated specially:
397595b296d0Smrg
39762378475aSmrg  -all-static       do not do any dynamic linking at all
39772378475aSmrg  -avoid-version    do not add a version suffix if possible
397814330f12Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
397914330f12Smrg                    libraries must be found in the PATH setting at runtime)
3980eca46af7Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
39812378475aSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
39822378475aSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
39832378475aSmrg  -export-symbols SYMFILE
39842378475aSmrg                    try to export only the symbols listed in SYMFILE
39852378475aSmrg  -export-symbols-regex REGEX
39862378475aSmrg                    try to export only the symbols matching REGEX
39872378475aSmrg  -LLIBDIR          search LIBDIR for required installed libraries
39882378475aSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
39892378475aSmrg  -module           build a library that can dlopened
39902378475aSmrg  -no-fast-install  disable the fast-install mode
39912378475aSmrg  -no-install       link a not-installable executable
39922378475aSmrg  -no-undefined     declare that a library does not refer to external symbols
39932378475aSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994eca46af7Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995eca46af7Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
39962378475aSmrg  -precious-files-regex REGEX
39972378475aSmrg                    don't remove output files matching REGEX
39982378475aSmrg  -release RELEASE  specify package release information
39992378475aSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
40002378475aSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
40012378475aSmrg  -shared           only do dynamic linking of libtool libraries
40022378475aSmrg  -shrext SUFFIX    override the standard shared library file extension
40032378475aSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
40042378475aSmrg  -static-libtool-libs
40052378475aSmrg                    do not do any dynamic linking of libtool libraries
40062378475aSmrg  -version-info CURRENT[:REVISION[:AGE]]
40072378475aSmrg                    specify library version info [each variable defaults to 0]
40082378475aSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
400914330f12Smrg  -Wc,FLAG
401014330f12Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011d87a3195Smrg  -Wa,FLAG
4012d87a3195Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
401314330f12Smrg  -Wl,FLAG
401414330f12Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
401514330f12Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
401695b296d0Smrg
4017eca46af7SmrgAll other options (arguments beginning with '-') are ignored.
401895b296d0Smrg
4019eca46af7SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
40202378475aSmrgtreated as uninstalled libtool libraries, other files are standard or library
40212378475aSmrgobject files.
402295b296d0Smrg
4023eca46af7SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024eca46af7Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
40252378475aSmrgrequired, except when creating a convenience library.
402695b296d0Smrg
4027eca46af7SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028eca46af7Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
402995b296d0Smrg
4030eca46af7SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
40312378475aSmrgis created, otherwise an executable program is created."
4032e6f085baSmrg        ;;
403395b296d0Smrg
40342378475aSmrg      uninstall)
40352378475aSmrg        $ECHO \
40362378475aSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
403795b296d0Smrg
40382378475aSmrgRemove libraries from an installation directory.
403995b296d0Smrg
40402378475aSmrgRM is the name of the program to use to delete files associated with each FILE
4041eca46af7Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
40422378475aSmrgto RM.
404339713583Smrg
40442378475aSmrgIf FILE is a libtool library, all the files associated with it are deleted.
40452378475aSmrgOtherwise, only FILE itself is deleted using RM."
40462378475aSmrg        ;;
404739713583Smrg
40482378475aSmrg      *)
4049eca46af7Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
40502378475aSmrg        ;;
40512378475aSmrg    esac
405239713583Smrg
405314330f12Smrg    echo
4054eca46af7Smrg    $ECHO "Try '$progname --help' for more information about other modes."
40552378475aSmrg}
405639713583Smrg
405714330f12Smrg# Now that we've collected a possible --mode arg, show help if necessary
405814330f12Smrgif $opt_help; then
4059eca46af7Smrg  if test : = "$opt_help"; then
406014330f12Smrg    func_mode_help
406114330f12Smrg  else
406214330f12Smrg    {
406314330f12Smrg      func_help noexit
406414330f12Smrg      for opt_mode in compile link execute install finish uninstall clean; do
406514330f12Smrg	func_mode_help
406614330f12Smrg      done
4067eca46af7Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
406814330f12Smrg    {
406914330f12Smrg      func_help noexit
407014330f12Smrg      for opt_mode in compile link execute install finish uninstall clean; do
407114330f12Smrg	echo
407214330f12Smrg	func_mode_help
407314330f12Smrg      done
407414330f12Smrg    } |
4075eca46af7Smrg    $SED '1d
407614330f12Smrg      /^When reporting/,/^Report/{
407714330f12Smrg	H
407814330f12Smrg	d
407914330f12Smrg      }
408014330f12Smrg      $x
408114330f12Smrg      /information about other modes/d
408214330f12Smrg      /more detailed .*MODE/d
408314330f12Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
408414330f12Smrg  fi
408514330f12Smrg  exit $?
408614330f12Smrgfi
408739713583Smrg
408839713583Smrg
40892378475aSmrg# func_mode_execute arg...
40902378475aSmrgfunc_mode_execute ()
40912378475aSmrg{
4092eca46af7Smrg    $debug_cmd
4093eca46af7Smrg
40942378475aSmrg    # The first argument is the command name.
4095eca46af7Smrg    cmd=$nonopt
40962378475aSmrg    test -z "$cmd" && \
40972378475aSmrg      func_fatal_help "you must specify a COMMAND"
4098e6f085baSmrg
40992378475aSmrg    # Handle -dlopen flags immediately.
410014330f12Smrg    for file in $opt_dlopen; do
41012378475aSmrg      test -f "$file" \
4102eca46af7Smrg	|| func_fatal_help "'$file' is not a file"
4103e6f085baSmrg
41042378475aSmrg      dir=
41052378475aSmrg      case $file in
41062378475aSmrg      *.la)
410714330f12Smrg	func_resolve_sysroot "$file"
410814330f12Smrg	file=$func_resolve_sysroot_result
410914330f12Smrg
41102378475aSmrg	# Check to see that this really is a libtool archive.
41112378475aSmrg	func_lalib_unsafe_p "$file" \
4112eca46af7Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113e6f085baSmrg
41142378475aSmrg	# Read the libtool library.
41152378475aSmrg	dlname=
41162378475aSmrg	library_names=
41172378475aSmrg	func_source "$file"
411895b296d0Smrg
41192378475aSmrg	# Skip this library if it cannot be dlopened.
41202378475aSmrg	if test -z "$dlname"; then
41212378475aSmrg	  # Warn if it was a shared library.
41222378475aSmrg	  test -n "$library_names" && \
4123eca46af7Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
41242378475aSmrg	  continue
41252378475aSmrg	fi
412695b296d0Smrg
41272378475aSmrg	func_dirname "$file" "" "."
4128eca46af7Smrg	dir=$func_dirname_result
412995b296d0Smrg
41302378475aSmrg	if test -f "$dir/$objdir/$dlname"; then
413114330f12Smrg	  func_append dir "/$objdir"
41322378475aSmrg	else
41332378475aSmrg	  if test ! -f "$dir/$dlname"; then
4134eca46af7Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
41352378475aSmrg	  fi
41362378475aSmrg	fi
4137e6f085baSmrg	;;
413895b296d0Smrg
41392378475aSmrg      *.lo)
41402378475aSmrg	# Just add the directory containing the .lo file.
41412378475aSmrg	func_dirname "$file" "" "."
4142eca46af7Smrg	dir=$func_dirname_result
4143e6f085baSmrg	;;
414495b296d0Smrg
41452378475aSmrg      *)
4146eca46af7Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147e6f085baSmrg	continue
4148e6f085baSmrg	;;
41492378475aSmrg      esac
415095b296d0Smrg
41512378475aSmrg      # Get the absolute pathname.
41522378475aSmrg      absdir=`cd "$dir" && pwd`
4153eca46af7Smrg      test -n "$absdir" && dir=$absdir
415439713583Smrg
41552378475aSmrg      # Now add the directory to shlibpath_var.
41562378475aSmrg      if eval "test -z \"\$$shlibpath_var\""; then
41572378475aSmrg	eval "$shlibpath_var=\"\$dir\""
41582378475aSmrg      else
41592378475aSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
41602378475aSmrg      fi
41612378475aSmrg    done
416239713583Smrg
41632378475aSmrg    # This variable tells wrapper scripts just to set shlibpath_var
41642378475aSmrg    # rather than running their programs.
4165eca46af7Smrg    libtool_execute_magic=$magic
416639713583Smrg
41672378475aSmrg    # Check if any of the arguments is a wrapper script.
41682378475aSmrg    args=
41692378475aSmrg    for file
41702378475aSmrg    do
41712378475aSmrg      case $file in
417214330f12Smrg      -* | *.la | *.lo ) ;;
41732378475aSmrg      *)
41742378475aSmrg	# Do a test to see if this is really a libtool program.
41752378475aSmrg	if func_ltwrapper_script_p "$file"; then
41762378475aSmrg	  func_source "$file"
41772378475aSmrg	  # Transform arg to wrapped name.
4178eca46af7Smrg	  file=$progdir/$program
41792378475aSmrg	elif func_ltwrapper_executable_p "$file"; then
41802378475aSmrg	  func_ltwrapper_scriptname "$file"
41812378475aSmrg	  func_source "$func_ltwrapper_scriptname_result"
41822378475aSmrg	  # Transform arg to wrapped name.
4183eca46af7Smrg	  file=$progdir/$program
41842378475aSmrg	fi
41852378475aSmrg	;;
41862378475aSmrg      esac
41872378475aSmrg      # Quote arguments (to preserve shell metacharacters).
418814330f12Smrg      func_append_quoted args "$file"
41892378475aSmrg    done
419039713583Smrg
4191eca46af7Smrg    if $opt_dry_run; then
4192eca46af7Smrg      # Display what would be done.
4193eca46af7Smrg      if test -n "$shlibpath_var"; then
4194eca46af7Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195eca46af7Smrg	echo "export $shlibpath_var"
4196eca46af7Smrg      fi
4197eca46af7Smrg      $ECHO "$cmd$args"
4198eca46af7Smrg      exit $EXIT_SUCCESS
4199eca46af7Smrg    else
42002378475aSmrg      if test -n "$shlibpath_var"; then
42012378475aSmrg	# Export the shlibpath_var.
42022378475aSmrg	eval "export $shlibpath_var"
42032378475aSmrg      fi
420439713583Smrg
42052378475aSmrg      # Restore saved environment variables
42062378475aSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
42072378475aSmrg      do
42082378475aSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
42092378475aSmrg                $lt_var=\$save_$lt_var; export $lt_var
4210e6f085baSmrg	      else
42112378475aSmrg		$lt_unset $lt_var
42122378475aSmrg	      fi"
42132378475aSmrg      done
421439713583Smrg
42152378475aSmrg      # Now prepare to actually exec the command.
4216eca46af7Smrg      exec_cmd=\$cmd$args
42172378475aSmrg    fi
42182378475aSmrg}
421939713583Smrg
4220eca46af7Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
422114330f12Smrg
422214330f12Smrg
422314330f12Smrg# func_mode_finish arg...
422414330f12Smrgfunc_mode_finish ()
422514330f12Smrg{
4226eca46af7Smrg    $debug_cmd
4227eca46af7Smrg
422814330f12Smrg    libs=
422914330f12Smrg    libdirs=
423014330f12Smrg    admincmds=
423114330f12Smrg
423214330f12Smrg    for opt in "$nonopt" ${1+"$@"}
423314330f12Smrg    do
423414330f12Smrg      if test -d "$opt"; then
423514330f12Smrg	func_append libdirs " $opt"
423614330f12Smrg
423714330f12Smrg      elif test -f "$opt"; then
423814330f12Smrg	if func_lalib_unsafe_p "$opt"; then
423914330f12Smrg	  func_append libs " $opt"
424014330f12Smrg	else
4241eca46af7Smrg	  func_warning "'$opt' is not a valid libtool archive"
424214330f12Smrg	fi
424314330f12Smrg
424414330f12Smrg      else
4245eca46af7Smrg	func_fatal_error "invalid argument '$opt'"
424614330f12Smrg      fi
424714330f12Smrg    done
424839713583Smrg
424914330f12Smrg    if test -n "$libs"; then
425014330f12Smrg      if test -n "$lt_sysroot"; then
425114330f12Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
425214330f12Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
425314330f12Smrg      else
425414330f12Smrg        sysroot_cmd=
425514330f12Smrg      fi
4256e6f085baSmrg
425714330f12Smrg      # Remove sysroot references
425814330f12Smrg      if $opt_dry_run; then
425914330f12Smrg        for lib in $libs; do
4260eca46af7Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
426114330f12Smrg        done
426214330f12Smrg      else
426314330f12Smrg        tmpdir=`func_mktempdir`
426414330f12Smrg        for lib in $libs; do
4265eca46af7Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
426614330f12Smrg	    > $tmpdir/tmp-la
426714330f12Smrg	  mv -f $tmpdir/tmp-la $lib
426814330f12Smrg	done
426914330f12Smrg        ${RM}r "$tmpdir"
427014330f12Smrg      fi
427114330f12Smrg    fi
427295b296d0Smrg
42732378475aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42742378475aSmrg      for libdir in $libdirs; do
42752378475aSmrg	if test -n "$finish_cmds"; then
42762378475aSmrg	  # Do each command in the finish commands.
42772378475aSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
42782378475aSmrg'"$cmd"'"'
4279e6f085baSmrg	fi
42802378475aSmrg	if test -n "$finish_eval"; then
42812378475aSmrg	  # Do the single finish_eval.
42822378475aSmrg	  eval cmds=\"$finish_eval\"
428314330f12Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
42842378475aSmrg       $cmds"
42852378475aSmrg	fi
42862378475aSmrg      done
42872378475aSmrg    fi
428895b296d0Smrg
42892378475aSmrg    # Exit here if they wanted silent mode.
4290eca46af7Smrg    $opt_quiet && exit $EXIT_SUCCESS
429195b296d0Smrg
429214330f12Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
429314330f12Smrg      echo "----------------------------------------------------------------------"
429414330f12Smrg      echo "Libraries have been installed in:"
429514330f12Smrg      for libdir in $libdirs; do
429614330f12Smrg	$ECHO "   $libdir"
429714330f12Smrg      done
429814330f12Smrg      echo
429914330f12Smrg      echo "If you ever happen to want to link against installed libraries"
430014330f12Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301eca46af7Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
430214330f12Smrg      echo "flag during linking and do at least one of the following:"
430314330f12Smrg      if test -n "$shlibpath_var"; then
4304eca46af7Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
430514330f12Smrg	echo "     during execution"
430614330f12Smrg      fi
430714330f12Smrg      if test -n "$runpath_var"; then
4308eca46af7Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
430914330f12Smrg	echo "     during linking"
431014330f12Smrg      fi
431114330f12Smrg      if test -n "$hardcode_libdir_flag_spec"; then
431214330f12Smrg	libdir=LIBDIR
431314330f12Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
43142378475aSmrg
4315eca46af7Smrg	$ECHO "   - use the '$flag' linker flag"
431614330f12Smrg      fi
431714330f12Smrg      if test -n "$admincmds"; then
431814330f12Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
431914330f12Smrg      fi
432014330f12Smrg      if test -f /etc/ld.so.conf; then
4321eca46af7Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
432214330f12Smrg      fi
432314330f12Smrg      echo
43242378475aSmrg
432514330f12Smrg      echo "See any operating system documentation about shared libraries for"
432614330f12Smrg      case $host in
432714330f12Smrg	solaris2.[6789]|solaris2.1[0-9])
432814330f12Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
432914330f12Smrg	  echo "pages."
433014330f12Smrg	  ;;
433114330f12Smrg	*)
433214330f12Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
433314330f12Smrg	  ;;
433414330f12Smrg      esac
433514330f12Smrg      echo "----------------------------------------------------------------------"
433614330f12Smrg    fi
43372378475aSmrg    exit $EXIT_SUCCESS
43382378475aSmrg}
43392378475aSmrg
4340eca46af7Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
43412378475aSmrg
43422378475aSmrg
43432378475aSmrg# func_mode_install arg...
43442378475aSmrgfunc_mode_install ()
43452378475aSmrg{
4346eca46af7Smrg    $debug_cmd
4347eca46af7Smrg
43482378475aSmrg    # There may be an optional sh(1) argument at the beginning of
43492378475aSmrg    # install_prog (especially on Windows NT).
4350eca46af7Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
43512378475aSmrg       # Allow the use of GNU shtool's install command.
4352eca46af7Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4353eca46af7Smrg    then
43542378475aSmrg      # Aesthetically quote it.
4355d87a3195Smrg      func_quote_arg pretty "$nonopt"
4356d87a3195Smrg      install_prog="$func_quote_arg_result "
43572378475aSmrg      arg=$1
43582378475aSmrg      shift
43592378475aSmrg    else
43602378475aSmrg      install_prog=
43612378475aSmrg      arg=$nonopt
43622378475aSmrg    fi
43632378475aSmrg
43642378475aSmrg    # The real first argument should be the name of the installation program.
43652378475aSmrg    # Aesthetically quote it.
4366d87a3195Smrg    func_quote_arg pretty "$arg"
4367d87a3195Smrg    func_append install_prog "$func_quote_arg_result"
436814330f12Smrg    install_shared_prog=$install_prog
436914330f12Smrg    case " $install_prog " in
437014330f12Smrg      *[\\\ /]cp\ *) install_cp=: ;;
437114330f12Smrg      *) install_cp=false ;;
437214330f12Smrg    esac
43732378475aSmrg
43742378475aSmrg    # We need to accept at least all the BSD install flags.
43752378475aSmrg    dest=
43762378475aSmrg    files=
43772378475aSmrg    opts=
43782378475aSmrg    prev=
43792378475aSmrg    install_type=
4380eca46af7Smrg    isdir=false
43812378475aSmrg    stripme=
438214330f12Smrg    no_mode=:
43832378475aSmrg    for arg
43842378475aSmrg    do
438514330f12Smrg      arg2=
43862378475aSmrg      if test -n "$dest"; then
438714330f12Smrg	func_append files " $dest"
43882378475aSmrg	dest=$arg
43892378475aSmrg	continue
43902378475aSmrg      fi
43912378475aSmrg
43922378475aSmrg      case $arg in
4393eca46af7Smrg      -d) isdir=: ;;
43942378475aSmrg      -f)
439514330f12Smrg	if $install_cp; then :; else
439614330f12Smrg	  prev=$arg
439714330f12Smrg	fi
43982378475aSmrg	;;
43992378475aSmrg      -g | -m | -o)
44002378475aSmrg	prev=$arg
44012378475aSmrg	;;
44022378475aSmrg      -s)
44032378475aSmrg	stripme=" -s"
44042378475aSmrg	continue
44052378475aSmrg	;;
44062378475aSmrg      -*)
44072378475aSmrg	;;
44082378475aSmrg      *)
44092378475aSmrg	# If the previous option needed an argument, then skip it.
44102378475aSmrg	if test -n "$prev"; then
4411eca46af7Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
441214330f12Smrg	    arg2=$install_override_mode
441314330f12Smrg	    no_mode=false
441414330f12Smrg	  fi
4415e6f085baSmrg	  prev=
441639713583Smrg	else
44172378475aSmrg	  dest=$arg
44182378475aSmrg	  continue
441995b296d0Smrg	fi
4420e6f085baSmrg	;;
44212378475aSmrg      esac
442295b296d0Smrg
44232378475aSmrg      # Aesthetically quote the argument.
4424d87a3195Smrg      func_quote_arg pretty "$arg"
4425d87a3195Smrg      func_append install_prog " $func_quote_arg_result"
442614330f12Smrg      if test -n "$arg2"; then
4427d87a3195Smrg	func_quote_arg pretty "$arg2"
442814330f12Smrg      fi
4429d87a3195Smrg      func_append install_shared_prog " $func_quote_arg_result"
44302378475aSmrg    done
443195b296d0Smrg
44322378475aSmrg    test -z "$install_prog" && \
44332378475aSmrg      func_fatal_help "you must specify an install program"
443495b296d0Smrg
44352378475aSmrg    test -n "$prev" && \
4436eca46af7Smrg      func_fatal_help "the '$prev' option requires an argument"
443739713583Smrg
443814330f12Smrg    if test -n "$install_override_mode" && $no_mode; then
443914330f12Smrg      if $install_cp; then :; else
4440d87a3195Smrg	func_quote_arg pretty "$install_override_mode"
4441d87a3195Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
444214330f12Smrg      fi
444314330f12Smrg    fi
444414330f12Smrg
44452378475aSmrg    if test -z "$files"; then
44462378475aSmrg      if test -z "$dest"; then
44472378475aSmrg	func_fatal_help "no file or destination specified"
44482378475aSmrg      else
44492378475aSmrg	func_fatal_help "you must specify a destination"
44502378475aSmrg      fi
4451e6f085baSmrg    fi
445239713583Smrg
44532378475aSmrg    # Strip any trailing slash from the destination.
44542378475aSmrg    func_stripname '' '/' "$dest"
44552378475aSmrg    dest=$func_stripname_result
445639713583Smrg
44572378475aSmrg    # Check to see that the destination is a directory.
4458eca46af7Smrg    test -d "$dest" && isdir=:
4459eca46af7Smrg    if $isdir; then
4460eca46af7Smrg      destdir=$dest
44612378475aSmrg      destname=
4462e6f085baSmrg    else
44632378475aSmrg      func_dirname_and_basename "$dest" "" "."
4464eca46af7Smrg      destdir=$func_dirname_result
4465eca46af7Smrg      destname=$func_basename_result
446639713583Smrg
44672378475aSmrg      # Not a directory, so check to see that there is only one file specified.
44682378475aSmrg      set dummy $files; shift
44692378475aSmrg      test "$#" -gt 1 && \
4470eca46af7Smrg	func_fatal_help "'$dest' is not a directory"
447139713583Smrg    fi
44722378475aSmrg    case $destdir in
44732378475aSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474e6f085baSmrg    *)
44752378475aSmrg      for file in $files; do
44762378475aSmrg	case $file in
44772378475aSmrg	*.lo) ;;
44782378475aSmrg	*)
4479eca46af7Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
44802378475aSmrg	  ;;
44812378475aSmrg	esac
44822378475aSmrg      done
4483e6f085baSmrg      ;;
4484e6f085baSmrg    esac
448595b296d0Smrg
44862378475aSmrg    # This variable tells wrapper scripts just to set variables rather
44872378475aSmrg    # than running their programs.
4488eca46af7Smrg    libtool_install_magic=$magic
448995b296d0Smrg
44902378475aSmrg    staticlibs=
44912378475aSmrg    future_libdirs=
44922378475aSmrg    current_libdirs=
44932378475aSmrg    for file in $files; do
449495b296d0Smrg
44952378475aSmrg      # Do each installation.
44962378475aSmrg      case $file in
44972378475aSmrg      *.$libext)
44982378475aSmrg	# Do the static libraries later.
449914330f12Smrg	func_append staticlibs " $file"
45002378475aSmrg	;;
45012378475aSmrg
45022378475aSmrg      *.la)
450314330f12Smrg	func_resolve_sysroot "$file"
450414330f12Smrg	file=$func_resolve_sysroot_result
450514330f12Smrg
45062378475aSmrg	# Check to see that this really is a libtool archive.
45072378475aSmrg	func_lalib_unsafe_p "$file" \
4508eca46af7Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
45092378475aSmrg
45102378475aSmrg	library_names=
45112378475aSmrg	old_library=
45122378475aSmrg	relink_command=
45132378475aSmrg	func_source "$file"
45142378475aSmrg
45152378475aSmrg	# Add the libdir to current_libdirs if it is the destination.
45162378475aSmrg	if test "X$destdir" = "X$libdir"; then
45172378475aSmrg	  case "$current_libdirs " in
45182378475aSmrg	  *" $libdir "*) ;;
451914330f12Smrg	  *) func_append current_libdirs " $libdir" ;;
452039713583Smrg	  esac
45212378475aSmrg	else
45222378475aSmrg	  # Note the libdir as a future libdir.
45232378475aSmrg	  case "$future_libdirs " in
45242378475aSmrg	  *" $libdir "*) ;;
452514330f12Smrg	  *) func_append future_libdirs " $libdir" ;;
45262378475aSmrg	  esac
45272378475aSmrg	fi
452839713583Smrg
45292378475aSmrg	func_dirname "$file" "/" ""
4530eca46af7Smrg	dir=$func_dirname_result
453114330f12Smrg	func_append dir "$objdir"
45322378475aSmrg
45332378475aSmrg	if test -n "$relink_command"; then
45342378475aSmrg	  # Determine the prefix the user has applied to our future dir.
453514330f12Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
45362378475aSmrg
45372378475aSmrg	  # Don't allow the user to place us outside of our expected
45382378475aSmrg	  # location b/c this prevents finding dependent libraries that
45392378475aSmrg	  # are installed to the same prefix.
45402378475aSmrg	  # At present, this check doesn't affect windows .dll's that
45412378475aSmrg	  # are installed into $libdir/../bin (currently, that works fine)
45422378475aSmrg	  # but it's something to keep an eye on.
45432378475aSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4544eca46af7Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
45452378475aSmrg
45462378475aSmrg	  if test -n "$inst_prefix_dir"; then
45472378475aSmrg	    # Stick the inst_prefix_dir data into the link command.
454814330f12Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
45492378475aSmrg	  else
455014330f12Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
45512378475aSmrg	  fi
45522378475aSmrg
4553eca46af7Smrg	  func_warning "relinking '$file'"
45542378475aSmrg	  func_show_eval "$relink_command" \
4555eca46af7Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
45562378475aSmrg	fi
45572378475aSmrg
45582378475aSmrg	# See the names of the shared library.
45592378475aSmrg	set dummy $library_names; shift
45602378475aSmrg	if test -n "$1"; then
4561eca46af7Smrg	  realname=$1
45622378475aSmrg	  shift
45632378475aSmrg
4564eca46af7Smrg	  srcname=$realname
4565eca46af7Smrg	  test -n "$relink_command" && srcname=${realname}T
45662378475aSmrg
45672378475aSmrg	  # Install the shared library and build the symlinks.
456814330f12Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
45692378475aSmrg	      'exit $?'
4570eca46af7Smrg	  tstripme=$stripme
45712378475aSmrg	  case $host_os in
45722378475aSmrg	  cygwin* | mingw* | pw32* | cegcc*)
45732378475aSmrg	    case $realname in
45742378475aSmrg	    *.dll.a)
4575eca46af7Smrg	      tstripme=
4576eca46af7Smrg	      ;;
4577eca46af7Smrg	    esac
4578eca46af7Smrg	    ;;
4579eca46af7Smrg	  os2*)
4580eca46af7Smrg	    case $realname in
4581eca46af7Smrg	    *_dll.a)
4582eca46af7Smrg	      tstripme=
45832378475aSmrg	      ;;
45842378475aSmrg	    esac
458539713583Smrg	    ;;
458639713583Smrg	  esac
45872378475aSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
45882378475aSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589e6f085baSmrg	  fi
45902378475aSmrg
45912378475aSmrg	  if test "$#" -gt 0; then
45922378475aSmrg	    # Delete the old symlinks, and create new ones.
4593eca46af7Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
45942378475aSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
45952378475aSmrg	    # so we also need to try rm && ln -s.
45962378475aSmrg	    for linkname
45972378475aSmrg	    do
45982378475aSmrg	      test "$linkname" != "$realname" \
45992378475aSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600e6f085baSmrg	    done
4601e6f085baSmrg	  fi
460295b296d0Smrg
46032378475aSmrg	  # Do each command in the postinstall commands.
4604eca46af7Smrg	  lib=$destdir/$realname
46052378475aSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4606e6f085baSmrg	fi
460795b296d0Smrg
46082378475aSmrg	# Install the pseudo-library for information purposes.
46092378475aSmrg	func_basename "$file"
4610eca46af7Smrg	name=$func_basename_result
4611eca46af7Smrg	instname=$dir/${name}i
46122378475aSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
461395b296d0Smrg
46142378475aSmrg	# Maybe install the static library, too.
461514330f12Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
46162378475aSmrg	;;
461795b296d0Smrg
46182378475aSmrg      *.lo)
46192378475aSmrg	# Install (i.e. copy) a libtool object.
462095b296d0Smrg
46212378475aSmrg	# Figure out destination file name, if it wasn't already specified.
46222378475aSmrg	if test -n "$destname"; then
4623eca46af7Smrg	  destfile=$destdir/$destname
46242378475aSmrg	else
46252378475aSmrg	  func_basename "$file"
4626eca46af7Smrg	  destfile=$func_basename_result
4627eca46af7Smrg	  destfile=$destdir/$destfile
4628e6f085baSmrg	fi
462995b296d0Smrg
46302378475aSmrg	# Deduce the name of the destination old-style object file.
46312378475aSmrg	case $destfile in
46322378475aSmrg	*.lo)
46332378475aSmrg	  func_lo2o "$destfile"
46342378475aSmrg	  staticdest=$func_lo2o_result
46352378475aSmrg	  ;;
46362378475aSmrg	*.$objext)
4637eca46af7Smrg	  staticdest=$destfile
46382378475aSmrg	  destfile=
46392378475aSmrg	  ;;
46402378475aSmrg	*)
4641eca46af7Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
46422378475aSmrg	  ;;
46432378475aSmrg	esac
464495b296d0Smrg
46452378475aSmrg	# Install the libtool object if requested.
46462378475aSmrg	test -n "$destfile" && \
46472378475aSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
464895b296d0Smrg
46492378475aSmrg	# Install the old object if enabled.
4650eca46af7Smrg	if test yes = "$build_old_libs"; then
46512378475aSmrg	  # Deduce the name of the old-style object file.
46522378475aSmrg	  func_lo2o "$file"
46532378475aSmrg	  staticobj=$func_lo2o_result
46542378475aSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
465595b296d0Smrg	fi
46562378475aSmrg	exit $EXIT_SUCCESS
46572378475aSmrg	;;
465895b296d0Smrg
46592378475aSmrg      *)
46602378475aSmrg	# Figure out destination file name, if it wasn't already specified.
46612378475aSmrg	if test -n "$destname"; then
4662eca46af7Smrg	  destfile=$destdir/$destname
46632378475aSmrg	else
46642378475aSmrg	  func_basename "$file"
4665eca46af7Smrg	  destfile=$func_basename_result
4666eca46af7Smrg	  destfile=$destdir/$destfile
46672378475aSmrg	fi
466895b296d0Smrg
46692378475aSmrg	# If the file is missing, and there is a .exe on the end, strip it
46702378475aSmrg	# because it is most likely a libtool script we actually want to
46712378475aSmrg	# install
4672eca46af7Smrg	stripped_ext=
46732378475aSmrg	case $file in
46742378475aSmrg	  *.exe)
46752378475aSmrg	    if test ! -f "$file"; then
46762378475aSmrg	      func_stripname '' '.exe' "$file"
46772378475aSmrg	      file=$func_stripname_result
4678eca46af7Smrg	      stripped_ext=.exe
46792378475aSmrg	    fi
46802378475aSmrg	    ;;
46812378475aSmrg	esac
46822378475aSmrg
46832378475aSmrg	# Do a test to see if this is really a libtool program.
46842378475aSmrg	case $host in
46852378475aSmrg	*cygwin* | *mingw*)
46862378475aSmrg	    if func_ltwrapper_executable_p "$file"; then
46872378475aSmrg	      func_ltwrapper_scriptname "$file"
46882378475aSmrg	      wrapper=$func_ltwrapper_scriptname_result
46892378475aSmrg	    else
46902378475aSmrg	      func_stripname '' '.exe' "$file"
46912378475aSmrg	      wrapper=$func_stripname_result
46922378475aSmrg	    fi
46932378475aSmrg	    ;;
4694e6f085baSmrg	*)
46952378475aSmrg	    wrapper=$file
46962378475aSmrg	    ;;
46972378475aSmrg	esac
46982378475aSmrg	if func_ltwrapper_script_p "$wrapper"; then
46992378475aSmrg	  notinst_deplibs=
47002378475aSmrg	  relink_command=
47012378475aSmrg
47022378475aSmrg	  func_source "$wrapper"
47032378475aSmrg
47042378475aSmrg	  # Check the variables that should have been set.
47052378475aSmrg	  test -z "$generated_by_libtool_version" && \
4706eca46af7Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
47072378475aSmrg
4708eca46af7Smrg	  finalize=:
47092378475aSmrg	  for lib in $notinst_deplibs; do
47102378475aSmrg	    # Check to see that each library is installed.
47112378475aSmrg	    libdir=
47122378475aSmrg	    if test -f "$lib"; then
47132378475aSmrg	      func_source "$lib"
47142378475aSmrg	    fi
4715eca46af7Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
47162378475aSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717eca46af7Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718eca46af7Smrg	      finalize=false
47192378475aSmrg	    fi
47202378475aSmrg	  done
47212378475aSmrg
47222378475aSmrg	  relink_command=
47232378475aSmrg	  func_source "$wrapper"
47242378475aSmrg
47252378475aSmrg	  outputname=
4726eca46af7Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
47272378475aSmrg	    $opt_dry_run || {
4728eca46af7Smrg	      if $finalize; then
47292378475aSmrg	        tmpdir=`func_mktempdir`
47302378475aSmrg		func_basename "$file$stripped_ext"
4731eca46af7Smrg		file=$func_basename_result
4732eca46af7Smrg	        outputname=$tmpdir/$file
47332378475aSmrg	        # Replace the output file specification.
473414330f12Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
47352378475aSmrg
4736eca46af7Smrg	        $opt_quiet || {
4737d87a3195Smrg	          func_quote_arg expand,pretty "$relink_command"
4738d87a3195Smrg		  eval "func_echo $func_quote_arg_result"
47392378475aSmrg	        }
47402378475aSmrg	        if eval "$relink_command"; then :
47412378475aSmrg	          else
4742eca46af7Smrg		  func_error "error: relink '$file' with the above command before installing it"
47432378475aSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
47442378475aSmrg		  continue
47452378475aSmrg	        fi
4746eca46af7Smrg	        file=$outputname
47472378475aSmrg	      else
4748eca46af7Smrg	        func_warning "cannot relink '$file'"
47492378475aSmrg	      fi
47502378475aSmrg	    }
47512378475aSmrg	  else
47522378475aSmrg	    # Install the binary that we compiled earlier.
475314330f12Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754e6f085baSmrg	  fi
47552378475aSmrg	fi
47562378475aSmrg
47572378475aSmrg	# remove .exe since cygwin /usr/bin/install will append another
47582378475aSmrg	# one anyway
47592378475aSmrg	case $install_prog,$host in
47602378475aSmrg	*/usr/bin/install*,*cygwin*)
47612378475aSmrg	  case $file:$destfile in
47622378475aSmrg	  *.exe:*.exe)
47632378475aSmrg	    # this is ok
47642378475aSmrg	    ;;
47652378475aSmrg	  *.exe:*)
47662378475aSmrg	    destfile=$destfile.exe
47672378475aSmrg	    ;;
47682378475aSmrg	  *:*.exe)
47692378475aSmrg	    func_stripname '' '.exe' "$destfile"
47702378475aSmrg	    destfile=$func_stripname_result
47712378475aSmrg	    ;;
47722378475aSmrg	  esac
4773e6f085baSmrg	  ;;
4774e6f085baSmrg	esac
47752378475aSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
47762378475aSmrg	$opt_dry_run || if test -n "$outputname"; then
47772378475aSmrg	  ${RM}r "$tmpdir"
47782378475aSmrg	fi
47792378475aSmrg	;;
47802378475aSmrg      esac
47812378475aSmrg    done
478295b296d0Smrg
47832378475aSmrg    for file in $staticlibs; do
47842378475aSmrg      func_basename "$file"
4785eca46af7Smrg      name=$func_basename_result
47862378475aSmrg
47872378475aSmrg      # Set up the ranlib parameters.
4788eca46af7Smrg      oldlib=$destdir/$name
4789eca46af7Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790eca46af7Smrg      tool_oldlib=$func_to_tool_file_result
47912378475aSmrg
47922378475aSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
47932378475aSmrg
47942378475aSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795eca46af7Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
47962378475aSmrg      fi
47972378475aSmrg
47982378475aSmrg      # Do each command in the postinstall commands.
47992378475aSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
48002378475aSmrg    done
48012378475aSmrg
48022378475aSmrg    test -n "$future_libdirs" && \
4803eca46af7Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
48042378475aSmrg
48052378475aSmrg    if test -n "$current_libdirs"; then
48062378475aSmrg      # Maybe just do a dry run.
48072378475aSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808eca46af7Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
48092378475aSmrg    else
48102378475aSmrg      exit $EXIT_SUCCESS
48112378475aSmrg    fi
48122378475aSmrg}
48132378475aSmrg
4814eca46af7Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
48152378475aSmrg
48162378475aSmrg
48172378475aSmrg# func_generate_dlsyms outputname originator pic_p
48182378475aSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
48192378475aSmrg# a dlpreopen symbol table.
48202378475aSmrgfunc_generate_dlsyms ()
48212378475aSmrg{
4822eca46af7Smrg    $debug_cmd
4823eca46af7Smrg
4824eca46af7Smrg    my_outputname=$1
4825eca46af7Smrg    my_originator=$2
4826eca46af7Smrg    my_pic_p=${3-false}
4827eca46af7Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
48282378475aSmrg    my_dlsyms=
48292378475aSmrg
4830eca46af7Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
48312378475aSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832eca46af7Smrg	my_dlsyms=${my_outputname}S.c
48332378475aSmrg      else
48342378475aSmrg	func_error "not configured to extract global symbols from dlpreopened files"
48352378475aSmrg      fi
48362378475aSmrg    fi
48372378475aSmrg
48382378475aSmrg    if test -n "$my_dlsyms"; then
48392378475aSmrg      case $my_dlsyms in
48402378475aSmrg      "") ;;
48412378475aSmrg      *.c)
48422378475aSmrg	# Discover the nlist of each of the dlfiles.
4843eca46af7Smrg	nlist=$output_objdir/$my_outputname.nm
48442378475aSmrg
48452378475aSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
48462378475aSmrg
48472378475aSmrg	# Parse the name list into a source file.
48482378475aSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
48492378475aSmrg
48502378475aSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851eca46af7Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852eca46af7Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
48532378475aSmrg
48542378475aSmrg#ifdef __cplusplus
48552378475aSmrgextern \"C\" {
48562378475aSmrg#endif
48572378475aSmrg
4858eca46af7Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
485914330f12Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
486014330f12Smrg#endif
486114330f12Smrg
486214330f12Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863eca46af7Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864eca46af7Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
486514330f12Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
486614330f12Smrg# define LT_DLSYM_CONST
4867eca46af7Smrg#elif defined __osf__
486814330f12Smrg/* This system does not cope well with relocations in const data.  */
486914330f12Smrg# define LT_DLSYM_CONST
487014330f12Smrg#else
487114330f12Smrg# define LT_DLSYM_CONST const
487214330f12Smrg#endif
487314330f12Smrg
4874eca46af7Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875eca46af7Smrg
48762378475aSmrg/* External symbol declarations for the compiler. */\
48772378475aSmrg"
48782378475aSmrg
4879eca46af7Smrg	if test yes = "$dlself"; then
4880eca46af7Smrg	  func_verbose "generating symbol list for '$output'"
48812378475aSmrg
48822378475aSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
48832378475aSmrg
48842378475aSmrg	  # Add our own program objects to the symbol list.
488514330f12Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
48862378475aSmrg	  for progfile in $progfiles; do
488714330f12Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888eca46af7Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
488914330f12Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
48902378475aSmrg	  done
48912378475aSmrg
48922378475aSmrg	  if test -n "$exclude_expsyms"; then
48932378475aSmrg	    $opt_dry_run || {
48942378475aSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
48952378475aSmrg	      eval '$MV "$nlist"T "$nlist"'
48962378475aSmrg	    }
4897e6f085baSmrg	  fi
48982378475aSmrg
48992378475aSmrg	  if test -n "$export_symbols_regex"; then
49002378475aSmrg	    $opt_dry_run || {
49012378475aSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
49022378475aSmrg	      eval '$MV "$nlist"T "$nlist"'
49032378475aSmrg	    }
49042378475aSmrg	  fi
49052378475aSmrg
49062378475aSmrg	  # Prepare the list of exported symbols
49072378475aSmrg	  if test -z "$export_symbols"; then
4908eca46af7Smrg	    export_symbols=$output_objdir/$outputname.exp
49092378475aSmrg	    $opt_dry_run || {
49102378475aSmrg	      $RM $export_symbols
4911eca46af7Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
49122378475aSmrg	      case $host in
49132378475aSmrg	      *cygwin* | *mingw* | *cegcc* )
49142378475aSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49152378475aSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
49162378475aSmrg	        ;;
49172378475aSmrg	      esac
49182378475aSmrg	    }
4919e6f085baSmrg	  else
49202378475aSmrg	    $opt_dry_run || {
4921eca46af7Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
49222378475aSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
49232378475aSmrg	      eval '$MV "$nlist"T "$nlist"'
49242378475aSmrg	      case $host in
492514330f12Smrg	        *cygwin* | *mingw* | *cegcc* )
49262378475aSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49272378475aSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
49282378475aSmrg	          ;;
49292378475aSmrg	      esac
49302378475aSmrg	    }
4931e6f085baSmrg	  fi
49322378475aSmrg	fi
493395b296d0Smrg
49342378475aSmrg	for dlprefile in $dlprefiles; do
4935eca46af7Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
49362378475aSmrg	  func_basename "$dlprefile"
4937eca46af7Smrg	  name=$func_basename_result
493814330f12Smrg          case $host in
493914330f12Smrg	    *cygwin* | *mingw* | *cegcc* )
494014330f12Smrg	      # if an import library, we need to obtain dlname
494114330f12Smrg	      if func_win32_import_lib_p "$dlprefile"; then
494214330f12Smrg	        func_tr_sh "$dlprefile"
494314330f12Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944eca46af7Smrg	        dlprefile_dlbasename=
494514330f12Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
494614330f12Smrg	          # Use subshell, to avoid clobbering current variable values
494714330f12Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948eca46af7Smrg	          if test -n "$dlprefile_dlname"; then
494914330f12Smrg	            func_basename "$dlprefile_dlname"
4950eca46af7Smrg	            dlprefile_dlbasename=$func_basename_result
495114330f12Smrg	          else
495214330f12Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
495314330f12Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
495414330f12Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
495514330f12Smrg	          fi
495614330f12Smrg	        fi
495714330f12Smrg	        $opt_dry_run || {
4958eca46af7Smrg	          if test -n "$dlprefile_dlbasename"; then
495914330f12Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
496014330f12Smrg	          else
496114330f12Smrg	            func_warning "Could not compute DLL name from $name"
496214330f12Smrg	            eval '$ECHO ": $name " >> "$nlist"'
496314330f12Smrg	          fi
496414330f12Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
496514330f12Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
496614330f12Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
496714330f12Smrg	        }
496814330f12Smrg	      else # not an import lib
496914330f12Smrg	        $opt_dry_run || {
497014330f12Smrg	          eval '$ECHO ": $name " >> "$nlist"'
497114330f12Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
497214330f12Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
497314330f12Smrg	        }
497414330f12Smrg	      fi
497514330f12Smrg	    ;;
497614330f12Smrg	    *)
497714330f12Smrg	      $opt_dry_run || {
497814330f12Smrg	        eval '$ECHO ": $name " >> "$nlist"'
497914330f12Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
498014330f12Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
498114330f12Smrg	      }
498214330f12Smrg	    ;;
498314330f12Smrg          esac
49842378475aSmrg	done
49852378475aSmrg
49862378475aSmrg	$opt_dry_run || {
49872378475aSmrg	  # Make sure we have at least an empty file.
49882378475aSmrg	  test -f "$nlist" || : > "$nlist"
49892378475aSmrg
49902378475aSmrg	  if test -n "$exclude_expsyms"; then
49912378475aSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
49922378475aSmrg	    $MV "$nlist"T "$nlist"
4993e6f085baSmrg	  fi
49942378475aSmrg
49952378475aSmrg	  # Try sorting and uniquifying the output.
49962378475aSmrg	  if $GREP -v "^: " < "$nlist" |
49972378475aSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
49982378475aSmrg		sort -k 3
49992378475aSmrg	      else
50002378475aSmrg		sort +2
50012378475aSmrg	      fi |
50022378475aSmrg	      uniq > "$nlist"S; then
50032378475aSmrg	    :
5004e6f085baSmrg	  else
50052378475aSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006e6f085baSmrg	  fi
500795b296d0Smrg
50082378475aSmrg	  if test -f "$nlist"S; then
50092378475aSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010e6f085baSmrg	  else
501114330f12Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012e6f085baSmrg	  fi
501395b296d0Smrg
5014eca46af7Smrg	  func_show_eval '$RM "${nlist}I"'
5015eca46af7Smrg	  if test -n "$global_symbol_to_import"; then
5016eca46af7Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017eca46af7Smrg	  fi
5018eca46af7Smrg
501914330f12Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
502095b296d0Smrg
50212378475aSmrg/* The mapping between symbol names and symbols.  */
50222378475aSmrgtypedef struct {
50232378475aSmrg  const char *name;
50242378475aSmrg  void *address;
50252378475aSmrg} lt_dlsymlist;
502614330f12Smrgextern LT_DLSYM_CONST lt_dlsymlist
5027eca46af7Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028eca46af7Smrg"
5029eca46af7Smrg
5030eca46af7Smrg	  if test -s "$nlist"I; then
5031eca46af7Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032eca46af7Smrgstatic void lt_syminit(void)
5033eca46af7Smrg{
5034eca46af7Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035eca46af7Smrg  for (; symbol->name; ++symbol)
5036eca46af7Smrg    {"
5037eca46af7Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038eca46af7Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039eca46af7Smrg    }
5040eca46af7Smrg}"
5041eca46af7Smrg	  fi
5042eca46af7Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
504314330f12SmrgLT_DLSYM_CONST lt_dlsymlist
50442378475aSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045eca46af7Smrg{ {\"$my_originator\", (void *) 0},"
5046eca46af7Smrg
5047eca46af7Smrg	  if test -s "$nlist"I; then
5048eca46af7Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049eca46af7Smrg  {\"@INIT@\", (void *) &lt_syminit},"
5050eca46af7Smrg	  fi
505195b296d0Smrg
50522378475aSmrg	  case $need_lib_prefix in
50532378475aSmrg	  no)
50542378475aSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
50552378475aSmrg	    ;;
50562378475aSmrg	  *)
50572378475aSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
50582378475aSmrg	    ;;
50592378475aSmrg	  esac
506014330f12Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50612378475aSmrg  {0, (void *) 0}
50622378475aSmrg};
506395b296d0Smrg
50642378475aSmrg/* This works around a problem in FreeBSD linker */
50652378475aSmrg#ifdef FREEBSD_WORKAROUND
50662378475aSmrgstatic const void *lt_preloaded_setup() {
50672378475aSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
50682378475aSmrg}
50692378475aSmrg#endif
50702378475aSmrg
50712378475aSmrg#ifdef __cplusplus
50722378475aSmrg}
50732378475aSmrg#endif\
50742378475aSmrg"
50752378475aSmrg	} # !$opt_dry_run
50762378475aSmrg
50772378475aSmrg	pic_flag_for_symtable=
50782378475aSmrg	case "$compile_command " in
50792378475aSmrg	*" -static "*) ;;
50802378475aSmrg	*)
50812378475aSmrg	  case $host in
50822378475aSmrg	  # compiling the symbol table file with pic_flag works around
50832378475aSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
50842378475aSmrg	  # linked before any other PIC object.  But we must not use
50852378475aSmrg	  # pic_flag when linking with -static.  The problem exists in
50862378475aSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087eca46af7Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
50882378475aSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
50892378475aSmrg	  *-*-hpux*)
50902378475aSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
50912378475aSmrg	  *)
5092eca46af7Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
50932378475aSmrg	    ;;
50942378475aSmrg	  esac
50952378475aSmrg	  ;;
50962378475aSmrg	esac
50972378475aSmrg	symtab_cflags=
50982378475aSmrg	for arg in $LTCFLAGS; do
50992378475aSmrg	  case $arg in
51002378475aSmrg	  -pie | -fpie | -fPIE) ;;
510114330f12Smrg	  *) func_append symtab_cflags " $arg" ;;
51022378475aSmrg	  esac
51032378475aSmrg	done
510495b296d0Smrg
51052378475aSmrg	# Now compile the dynamic symbol file.
51062378475aSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
510739713583Smrg
51082378475aSmrg	# Clean up the generated files.
5109eca46af7Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
511095b296d0Smrg
51112378475aSmrg	# Transform the symbol file into the correct name.
5112eca46af7Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
51132378475aSmrg	case $host in
51142378475aSmrg	*cygwin* | *mingw* | *cegcc* )
51152378475aSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
511614330f12Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511714330f12Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51182378475aSmrg	  else
511914330f12Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512014330f12Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5121e6f085baSmrg	  fi
51222378475aSmrg	  ;;
51232378475aSmrg	*)
512414330f12Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512514330f12Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51262378475aSmrg	  ;;
51272378475aSmrg	esac
51282378475aSmrg	;;
51292378475aSmrg      *)
5130eca46af7Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
51312378475aSmrg	;;
51322378475aSmrg      esac
51332378475aSmrg    else
51342378475aSmrg      # We keep going just in case the user didn't refer to
51352378475aSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
51362378475aSmrg      # really was required.
513795b296d0Smrg
51382378475aSmrg      # Nullify the symbol file.
513914330f12Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
514014330f12Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
51412378475aSmrg    fi
51422378475aSmrg}
514339713583Smrg
5144eca46af7Smrg# func_cygming_gnu_implib_p ARG
5145eca46af7Smrg# This predicate returns with zero status (TRUE) if
5146eca46af7Smrg# ARG is a GNU/binutils-style import library. Returns
5147eca46af7Smrg# with nonzero status (FALSE) otherwise.
5148eca46af7Smrgfunc_cygming_gnu_implib_p ()
5149eca46af7Smrg{
5150eca46af7Smrg  $debug_cmd
5151eca46af7Smrg
5152eca46af7Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153eca46af7Smrg  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)$'`
5154eca46af7Smrg  test -n "$func_cygming_gnu_implib_tmp"
5155eca46af7Smrg}
5156eca46af7Smrg
5157eca46af7Smrg# func_cygming_ms_implib_p ARG
5158eca46af7Smrg# This predicate returns with zero status (TRUE) if
5159eca46af7Smrg# ARG is an MS-style import library. Returns
5160eca46af7Smrg# with nonzero status (FALSE) otherwise.
5161eca46af7Smrgfunc_cygming_ms_implib_p ()
5162eca46af7Smrg{
5163eca46af7Smrg  $debug_cmd
5164eca46af7Smrg
5165eca46af7Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166eca46af7Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167eca46af7Smrg  test -n "$func_cygming_ms_implib_tmp"
5168eca46af7Smrg}
5169eca46af7Smrg
51702378475aSmrg# func_win32_libid arg
51712378475aSmrg# return the library type of file 'arg'
51722378475aSmrg#
51732378475aSmrg# Need a lot of goo to handle *both* DLLs and import libs
51742378475aSmrg# Has to be a shell function in order to 'eat' the argument
51752378475aSmrg# that is supplied when $file_magic_command is called.
517614330f12Smrg# Despite the name, also deal with 64 bit binaries.
51772378475aSmrgfunc_win32_libid ()
51782378475aSmrg{
5179eca46af7Smrg  $debug_cmd
5180eca46af7Smrg
5181eca46af7Smrg  win32_libid_type=unknown
51822378475aSmrg  win32_fileres=`file -L $1 2>/dev/null`
51832378475aSmrg  case $win32_fileres in
51842378475aSmrg  *ar\ archive\ import\ library*) # definitely import
51852378475aSmrg    win32_libid_type="x86 archive import"
51862378475aSmrg    ;;
51872378475aSmrg  *ar\ archive*) # could be an import, or static
518814330f12Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
51892378475aSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
519014330f12Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191eca46af7Smrg      case $nm_interface in
5192eca46af7Smrg      "MS dumpbin")
5193eca46af7Smrg	if func_cygming_ms_implib_p "$1" ||
5194eca46af7Smrg	   func_cygming_gnu_implib_p "$1"
5195eca46af7Smrg	then
5196eca46af7Smrg	  win32_nmres=import
5197eca46af7Smrg	else
5198eca46af7Smrg	  win32_nmres=
5199eca46af7Smrg	fi
5200eca46af7Smrg	;;
5201eca46af7Smrg      *)
5202eca46af7Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203eca46af7Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204eca46af7Smrg	  $SED -n -e '
52052378475aSmrg	    1,100{
52062378475aSmrg		/ I /{
5207eca46af7Smrg		    s|.*|import|
52082378475aSmrg		    p
52092378475aSmrg		    q
52102378475aSmrg		}
52112378475aSmrg	    }'`
5212eca46af7Smrg	;;
5213eca46af7Smrg      esac
52142378475aSmrg      case $win32_nmres in
52152378475aSmrg      import*)  win32_libid_type="x86 archive import";;
52162378475aSmrg      *)        win32_libid_type="x86 archive static";;
52172378475aSmrg      esac
52182378475aSmrg    fi
52192378475aSmrg    ;;
52202378475aSmrg  *DLL*)
52212378475aSmrg    win32_libid_type="x86 DLL"
52222378475aSmrg    ;;
52232378475aSmrg  *executable*) # but shell scripts are "executable" too...
52242378475aSmrg    case $win32_fileres in
52252378475aSmrg    *MS\ Windows\ PE\ Intel*)
52262378475aSmrg      win32_libid_type="x86 DLL"
52272378475aSmrg      ;;
52282378475aSmrg    esac
52292378475aSmrg    ;;
52302378475aSmrg  esac
52312378475aSmrg  $ECHO "$win32_libid_type"
52322378475aSmrg}
523339713583Smrg
523414330f12Smrg# func_cygming_dll_for_implib ARG
523514330f12Smrg#
523614330f12Smrg# Platform-specific function to extract the
523714330f12Smrg# name of the DLL associated with the specified
523814330f12Smrg# import library ARG.
523914330f12Smrg# Invoked by eval'ing the libtool variable
524014330f12Smrg#    $sharedlib_from_linklib_cmd
524114330f12Smrg# Result is available in the variable
524214330f12Smrg#    $sharedlib_from_linklib_result
524314330f12Smrgfunc_cygming_dll_for_implib ()
524414330f12Smrg{
5245eca46af7Smrg  $debug_cmd
5246eca46af7Smrg
524714330f12Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
524814330f12Smrg}
524914330f12Smrg
525014330f12Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
525114330f12Smrg#
525214330f12Smrg# The is the core of a fallback implementation of a
525314330f12Smrg# platform-specific function to extract the name of the
525414330f12Smrg# DLL associated with the specified import library LIBNAME.
525514330f12Smrg#
525614330f12Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
525714330f12Smrg# on the platform and compiler that created the implib.
525814330f12Smrg#
525914330f12Smrg# Echos the name of the DLL associated with the
526014330f12Smrg# specified import library.
526114330f12Smrgfunc_cygming_dll_for_implib_fallback_core ()
526214330f12Smrg{
5263eca46af7Smrg  $debug_cmd
5264eca46af7Smrg
526514330f12Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
526614330f12Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
526714330f12Smrg    $SED '/^Contents of section '"$match_literal"':/{
526814330f12Smrg      # Place marker at beginning of archive member dllname section
526914330f12Smrg      s/.*/====MARK====/
527014330f12Smrg      p
527114330f12Smrg      d
527214330f12Smrg    }
527314330f12Smrg    # These lines can sometimes be longer than 43 characters, but
527414330f12Smrg    # are always uninteresting
527514330f12Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
527614330f12Smrg    /^In archive [^:]*:/d
527714330f12Smrg    # Ensure marker is printed
527814330f12Smrg    /^====MARK====/p
527914330f12Smrg    # Remove all lines with less than 43 characters
528014330f12Smrg    /^.\{43\}/!d
528114330f12Smrg    # From remaining lines, remove first 43 characters
528214330f12Smrg    s/^.\{43\}//' |
528314330f12Smrg    $SED -n '
528414330f12Smrg      # Join marker and all lines until next marker into a single line
528514330f12Smrg      /^====MARK====/ b para
528614330f12Smrg      H
528714330f12Smrg      $ b para
528814330f12Smrg      b
528914330f12Smrg      :para
529014330f12Smrg      x
529114330f12Smrg      s/\n//g
529214330f12Smrg      # Remove the marker
529314330f12Smrg      s/^====MARK====//
529414330f12Smrg      # Remove trailing dots and whitespace
529514330f12Smrg      s/[\. \t]*$//
529614330f12Smrg      # Print
529714330f12Smrg      /./p' |
529814330f12Smrg    # we now have a list, one entry per line, of the stringified
529914330f12Smrg    # contents of the appropriate section of all members of the
5300eca46af7Smrg    # archive that possess that section. Heuristic: eliminate
5301eca46af7Smrg    # all those that have a first or second character that is
530214330f12Smrg    # a '.' (that is, objdump's representation of an unprintable
530314330f12Smrg    # character.) This should work for all archives with less than
530414330f12Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
530514330f12Smrg    # begins with a literal '.' or a single character followed by
530614330f12Smrg    # a '.'.
530714330f12Smrg    #
530814330f12Smrg    # Of those that remain, print the first one.
530914330f12Smrg    $SED -e '/^\./d;/^.\./d;q'
531014330f12Smrg}
531114330f12Smrg
531214330f12Smrg# func_cygming_dll_for_implib_fallback ARG
531314330f12Smrg# Platform-specific function to extract the
531414330f12Smrg# name of the DLL associated with the specified
531514330f12Smrg# import library ARG.
531614330f12Smrg#
531714330f12Smrg# This fallback implementation is for use when $DLLTOOL
531814330f12Smrg# does not support the --identify-strict option.
531914330f12Smrg# Invoked by eval'ing the libtool variable
532014330f12Smrg#    $sharedlib_from_linklib_cmd
532114330f12Smrg# Result is available in the variable
532214330f12Smrg#    $sharedlib_from_linklib_result
532314330f12Smrgfunc_cygming_dll_for_implib_fallback ()
532414330f12Smrg{
5325eca46af7Smrg  $debug_cmd
5326eca46af7Smrg
5327eca46af7Smrg  if func_cygming_gnu_implib_p "$1"; then
532814330f12Smrg    # binutils import library
532914330f12Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330eca46af7Smrg  elif func_cygming_ms_implib_p "$1"; then
533114330f12Smrg    # ms-generated import library
533214330f12Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
533314330f12Smrg  else
533414330f12Smrg    # unknown
5335eca46af7Smrg    sharedlib_from_linklib_result=
533614330f12Smrg  fi
533714330f12Smrg}
533839713583Smrg
533939713583Smrg
53402378475aSmrg# func_extract_an_archive dir oldlib
53412378475aSmrgfunc_extract_an_archive ()
53422378475aSmrg{
5343eca46af7Smrg    $debug_cmd
5344eca46af7Smrg
5345eca46af7Smrg    f_ex_an_ar_dir=$1; shift
5346eca46af7Smrg    f_ex_an_ar_oldlib=$1
5347eca46af7Smrg    if test yes = "$lock_old_archive_extraction"; then
534814330f12Smrg      lockfile=$f_ex_an_ar_oldlib.lock
534914330f12Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
535014330f12Smrg	func_echo "Waiting for $lockfile to be removed"
535114330f12Smrg	sleep 2
535214330f12Smrg      done
535314330f12Smrg    fi
535414330f12Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
535514330f12Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356eca46af7Smrg    if test yes = "$lock_old_archive_extraction"; then
535714330f12Smrg      $opt_dry_run || rm -f "$lockfile"
535814330f12Smrg    fi
53592378475aSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
53602378475aSmrg     :
53612378475aSmrg    else
53622378475aSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
53632378475aSmrg    fi
53642378475aSmrg}
536595b296d0Smrg
536695b296d0Smrg
53672378475aSmrg# func_extract_archives gentop oldlib ...
53682378475aSmrgfunc_extract_archives ()
53692378475aSmrg{
5370eca46af7Smrg    $debug_cmd
5371eca46af7Smrg
5372eca46af7Smrg    my_gentop=$1; shift
53732378475aSmrg    my_oldlibs=${1+"$@"}
5374eca46af7Smrg    my_oldobjs=
5375eca46af7Smrg    my_xlib=
5376eca46af7Smrg    my_xabs=
5377eca46af7Smrg    my_xdir=
537895b296d0Smrg
53792378475aSmrg    for my_xlib in $my_oldlibs; do
53802378475aSmrg      # Extract the objects.
53812378475aSmrg      case $my_xlib in
5382eca46af7Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
53832378475aSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
53842378475aSmrg      esac
53852378475aSmrg      func_basename "$my_xlib"
5386eca46af7Smrg      my_xlib=$func_basename_result
53872378475aSmrg      my_xlib_u=$my_xlib
53882378475aSmrg      while :; do
53892378475aSmrg        case " $extracted_archives " in
53902378475aSmrg	*" $my_xlib_u "*)
53912378475aSmrg	  func_arith $extracted_serial + 1
53922378475aSmrg	  extracted_serial=$func_arith_result
53932378475aSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
53942378475aSmrg	*) break ;;
53952378475aSmrg	esac
53962378475aSmrg      done
53972378475aSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5398eca46af7Smrg      my_xdir=$my_gentop/$my_xlib_u
539995b296d0Smrg
54002378475aSmrg      func_mkdir_p "$my_xdir"
540139713583Smrg
54022378475aSmrg      case $host in
54032378475aSmrg      *-darwin*)
54042378475aSmrg	func_verbose "Extracting $my_xabs"
54052378475aSmrg	# Do not bother doing anything if just a dry run
54062378475aSmrg	$opt_dry_run || {
54072378475aSmrg	  darwin_orig_dir=`pwd`
54082378475aSmrg	  cd $my_xdir || exit $?
54092378475aSmrg	  darwin_archive=$my_xabs
54102378475aSmrg	  darwin_curdir=`pwd`
5411eca46af7Smrg	  func_basename "$darwin_archive"
5412eca46af7Smrg	  darwin_base_archive=$func_basename_result
54132378475aSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
54142378475aSmrg	  if test -n "$darwin_arches"; then
54152378475aSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
54162378475aSmrg	    darwin_arch=
54172378475aSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418eca46af7Smrg	    for darwin_arch in  $darwin_arches; do
5419eca46af7Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420eca46af7Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421eca46af7Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422eca46af7Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
54232378475aSmrg	      cd "$darwin_curdir"
5424eca46af7Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
54252378475aSmrg	    done # $darwin_arches
54262378475aSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427eca46af7Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
54282378475aSmrg	    darwin_file=
54292378475aSmrg	    darwin_files=
54302378475aSmrg	    for darwin_file in $darwin_filelist; do
543114330f12Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
54322378475aSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
54332378475aSmrg	    done # $darwin_filelist
54342378475aSmrg	    $RM -rf unfat-$$
54352378475aSmrg	    cd "$darwin_orig_dir"
5436e6f085baSmrg	  else
54372378475aSmrg	    cd $darwin_orig_dir
54382378475aSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
54392378475aSmrg	  fi # $darwin_arches
54402378475aSmrg	} # !$opt_dry_run
54412378475aSmrg	;;
54422378475aSmrg      *)
54432378475aSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
54442378475aSmrg	;;
54452378475aSmrg      esac
544614330f12Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
54472378475aSmrg    done
544895b296d0Smrg
5449eca46af7Smrg    func_extract_archives_result=$my_oldobjs
54502378475aSmrg}
545195b296d0Smrg
545295b296d0Smrg
545314330f12Smrg# func_emit_wrapper [arg=no]
545414330f12Smrg#
545514330f12Smrg# Emit a libtool wrapper script on stdout.
545614330f12Smrg# Don't directly open a file because we may want to
545714330f12Smrg# incorporate the script contents within a cygwin/mingw
545814330f12Smrg# wrapper executable.  Must ONLY be called from within
545914330f12Smrg# func_mode_link because it depends on a number of variables
546014330f12Smrg# set therein.
54612378475aSmrg#
546214330f12Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
546314330f12Smrg# variable will take.  If 'yes', then the emitted script
5464eca46af7Smrg# will assume that the directory where it is stored is
546514330f12Smrg# the $objdir directory.  This is a cygwin/mingw-specific
546614330f12Smrg# behavior.
546714330f12Smrgfunc_emit_wrapper ()
54682378475aSmrg{
546914330f12Smrg	func_emit_wrapper_arg1=${1-no}
5470e6f085baSmrg
54712378475aSmrg	$ECHO "\
54722378475aSmrg#! $SHELL
547395b296d0Smrg
54742378475aSmrg# $output - temporary wrapper script for $objdir/$outputname
5475eca46af7Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
54762378475aSmrg#
54772378475aSmrg# The $output program cannot be directly executed until all the libtool
54782378475aSmrg# libraries that it depends on are installed.
54792378475aSmrg#
54802378475aSmrg# This wrapper script should never be moved out of the build directory.
54812378475aSmrg# If it is, it will not operate correctly.
548295b296d0Smrg
54832378475aSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
54842378475aSmrg# metacharacters that are still active within double-quoted strings.
54852378475aSmrgsed_quote_subst='$sed_quote_subst'
548695b296d0Smrg
54872378475aSmrg# Be Bourne compatible
54882378475aSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
54892378475aSmrg  emulate sh
54902378475aSmrg  NULLCMD=:
54912378475aSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
54922378475aSmrg  # is contrary to our usage.  Disable this feature.
54932378475aSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
54942378475aSmrg  setopt NO_GLOB_SUBST
54952378475aSmrgelse
54962378475aSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
54972378475aSmrgfi
54982378475aSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
54992378475aSmrgDUALCASE=1; export DUALCASE # for MKS sh
550095b296d0Smrg
55012378475aSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
55022378475aSmrg# if CDPATH is set.
55032378475aSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
550495b296d0Smrg
55052378475aSmrgrelink_command=\"$relink_command\"
550695b296d0Smrg
55072378475aSmrg# This environment variable determines our operation mode.
55082378475aSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
55092378475aSmrg  # install mode needs the following variables:
55102378475aSmrg  generated_by_libtool_version='$macro_version'
55112378475aSmrg  notinst_deplibs='$notinst_deplibs'
55122378475aSmrgelse
55132378475aSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
55142378475aSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
551514330f12Smrg    file=\"\$0\""
551614330f12Smrg
5517d87a3195Smrg    func_quote_arg pretty "$ECHO"
5518d87a3195Smrg    qECHO=$func_quote_arg_result
551914330f12Smrg    $ECHO "\
552014330f12Smrg
552114330f12Smrg# A function that is used when there is no print builtin or printf.
552214330f12Smrgfunc_fallback_echo ()
552314330f12Smrg{
552414330f12Smrg  eval 'cat <<_LTECHO_EOF
552514330f12Smrg\$1
552614330f12Smrg_LTECHO_EOF'
552714330f12Smrg}
5528d87a3195Smrg    ECHO=$qECHO
552914330f12Smrg  fi
553014330f12Smrg
553114330f12Smrg# Very basic option parsing. These options are (a) specific to
553214330f12Smrg# the libtool wrapper, (b) are identical between the wrapper
5533eca46af7Smrg# /script/ and the wrapper /executable/ that is used only on
553414330f12Smrg# windows platforms, and (c) all begin with the string "--lt-"
5535eca46af7Smrg# (application programs are unlikely to have options that match
553614330f12Smrg# this pattern).
553714330f12Smrg#
553814330f12Smrg# There are only two supported options: --lt-debug and
553914330f12Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
554014330f12Smrg#
554114330f12Smrg# The first argument to this parsing function should be the
554214330f12Smrg# script's $0 value, followed by "$@".
554314330f12Smrglt_option_debug=
554414330f12Smrgfunc_parse_lt_options ()
554514330f12Smrg{
554614330f12Smrg  lt_script_arg0=\$0
554714330f12Smrg  shift
554814330f12Smrg  for lt_opt
554914330f12Smrg  do
555014330f12Smrg    case \"\$lt_opt\" in
555114330f12Smrg    --lt-debug) lt_option_debug=1 ;;
555214330f12Smrg    --lt-dump-script)
555314330f12Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
555414330f12Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
555514330f12Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
555614330f12Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
555714330f12Smrg        exit 0
555814330f12Smrg      ;;
555914330f12Smrg    --lt-*)
556014330f12Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
556114330f12Smrg        exit 1
556214330f12Smrg      ;;
556314330f12Smrg    esac
556414330f12Smrg  done
556514330f12Smrg
556614330f12Smrg  # Print the debug banner immediately:
556714330f12Smrg  if test -n \"\$lt_option_debug\"; then
5568eca46af7Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
556914330f12Smrg  fi
557014330f12Smrg}
557114330f12Smrg
557214330f12Smrg# Used when --lt-debug. Prints its arguments to stdout
557314330f12Smrg# (redirection is the responsibility of the caller)
557414330f12Smrgfunc_lt_dump_args ()
557514330f12Smrg{
557614330f12Smrg  lt_dump_args_N=1;
557714330f12Smrg  for lt_arg
557814330f12Smrg  do
5579eca46af7Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
558014330f12Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
558114330f12Smrg  done
558214330f12Smrg}
558314330f12Smrg
558414330f12Smrg# Core function for launching the target application
558514330f12Smrgfunc_exec_program_core ()
558614330f12Smrg{
55872378475aSmrg"
558814330f12Smrg  case $host in
558914330f12Smrg  # Backslashes separate directories on plain windows
559014330f12Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
559114330f12Smrg    $ECHO "\
559214330f12Smrg      if test -n \"\$lt_option_debug\"; then
5593eca46af7Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
559414330f12Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
559514330f12Smrg      fi
559614330f12Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
559714330f12Smrg"
559814330f12Smrg    ;;
559914330f12Smrg
560014330f12Smrg  *)
560114330f12Smrg    $ECHO "\
560214330f12Smrg      if test -n \"\$lt_option_debug\"; then
5603eca46af7Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
560414330f12Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
560514330f12Smrg      fi
560614330f12Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
560714330f12Smrg"
560814330f12Smrg    ;;
560914330f12Smrg  esac
561014330f12Smrg  $ECHO "\
561114330f12Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
561214330f12Smrg      exit 1
561314330f12Smrg}
561414330f12Smrg
561514330f12Smrg# A function to encapsulate launching the target application
561614330f12Smrg# Strips options in the --lt-* namespace from \$@ and
561714330f12Smrg# launches target application with the remaining arguments.
561814330f12Smrgfunc_exec_program ()
561914330f12Smrg{
5620eca46af7Smrg  case \" \$* \" in
5621eca46af7Smrg  *\\ --lt-*)
5622eca46af7Smrg    for lt_wr_arg
5623eca46af7Smrg    do
5624eca46af7Smrg      case \$lt_wr_arg in
5625eca46af7Smrg      --lt-*) ;;
5626eca46af7Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627eca46af7Smrg      esac
5628eca46af7Smrg      shift
5629eca46af7Smrg    done ;;
5630eca46af7Smrg  esac
563114330f12Smrg  func_exec_program_core \${1+\"\$@\"}
563214330f12Smrg}
563314330f12Smrg
563414330f12Smrg  # Parse options
563514330f12Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
563695b296d0Smrg
56372378475aSmrg  # Find the directory that this script lives in.
563814330f12Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
56392378475aSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
564095b296d0Smrg
56412378475aSmrg  # Follow symbolic links until we get to the real thisdir.
564214330f12Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
56432378475aSmrg  while test -n \"\$file\"; do
564414330f12Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
564595b296d0Smrg
56462378475aSmrg    # If there was a directory component, then change thisdir.
56472378475aSmrg    if test \"x\$destdir\" != \"x\$file\"; then
56482378475aSmrg      case \"\$destdir\" in
56492378475aSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
56502378475aSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5651e6f085baSmrg      esac
56522378475aSmrg    fi
565395b296d0Smrg
565414330f12Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
565514330f12Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
56562378475aSmrg  done
565795b296d0Smrg
56582378475aSmrg  # Usually 'no', except on cygwin/mingw when embedded into
56592378475aSmrg  # the cwrapper.
566014330f12Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
56612378475aSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
56622378475aSmrg    # special case for '.'
56632378475aSmrg    if test \"\$thisdir\" = \".\"; then
56642378475aSmrg      thisdir=\`pwd\`
56652378475aSmrg    fi
56662378475aSmrg    # remove .libs from thisdir
56672378475aSmrg    case \"\$thisdir\" in
566814330f12Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
56692378475aSmrg    $objdir )   thisdir=. ;;
56702378475aSmrg    esac
56712378475aSmrg  fi
56722378475aSmrg
56732378475aSmrg  # Try to get the absolute directory name.
56742378475aSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
56752378475aSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
56762378475aSmrg"
56772378475aSmrg
5678eca46af7Smrg	if test yes = "$fast_install"; then
56792378475aSmrg	  $ECHO "\
56802378475aSmrg  program=lt-'$outputname'$exeext
56812378475aSmrg  progdir=\"\$thisdir/$objdir\"
56822378475aSmrg
56832378475aSmrg  if test ! -f \"\$progdir/\$program\" ||
5684eca46af7Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
56852378475aSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
56862378475aSmrg
56872378475aSmrg    file=\"\$\$-\$program\"
56882378475aSmrg
56892378475aSmrg    if test ! -d \"\$progdir\"; then
56902378475aSmrg      $MKDIR \"\$progdir\"
56912378475aSmrg    else
56922378475aSmrg      $RM \"\$progdir/\$file\"
56932378475aSmrg    fi"
56942378475aSmrg
56952378475aSmrg	  $ECHO "\
56962378475aSmrg
56972378475aSmrg    # relink executable if necessary
56982378475aSmrg    if test -n \"\$relink_command\"; then
56992378475aSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
57002378475aSmrg      else
5701eca46af7Smrg	\$ECHO \"\$relink_command_output\" >&2
57022378475aSmrg	$RM \"\$progdir/\$file\"
57032378475aSmrg	exit 1
5704e6f085baSmrg      fi
57052378475aSmrg    fi
570695b296d0Smrg
57072378475aSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
57082378475aSmrg    { $RM \"\$progdir/\$program\";
57092378475aSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
57102378475aSmrg    $RM \"\$progdir/\$file\"
57112378475aSmrg  fi"
57122378475aSmrg	else
57132378475aSmrg	  $ECHO "\
57142378475aSmrg  program='$outputname'
57152378475aSmrg  progdir=\"\$thisdir/$objdir\"
57162378475aSmrg"
5717e6f085baSmrg	fi
571895b296d0Smrg
57192378475aSmrg	$ECHO "\
572095b296d0Smrg
57212378475aSmrg  if test -f \"\$progdir/\$program\"; then"
572295b296d0Smrg
572314330f12Smrg	# fixup the dll searchpath if we need to.
572414330f12Smrg	#
572514330f12Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
572614330f12Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
572714330f12Smrg	# libraries must come first.
572814330f12Smrg	if test -n "$dllsearchpath"; then
572914330f12Smrg	  $ECHO "\
573014330f12Smrg    # Add the dll search path components to the executable PATH
573114330f12Smrg    PATH=$dllsearchpath:\$PATH
573214330f12Smrg"
573314330f12Smrg	fi
573414330f12Smrg
57352378475aSmrg	# Export our shlibpath_var if we have one.
5736eca46af7Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
57372378475aSmrg	  $ECHO "\
57382378475aSmrg    # Add our own library path to $shlibpath_var
57392378475aSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
57402378475aSmrg
57412378475aSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
57422378475aSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
574314330f12Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
574495b296d0Smrg
57452378475aSmrg    export $shlibpath_var
57462378475aSmrg"
5747e6f085baSmrg	fi
574895b296d0Smrg
57492378475aSmrg	$ECHO "\
57502378475aSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
57512378475aSmrg      # Run the actual program with our arguments.
575214330f12Smrg      func_exec_program \${1+\"\$@\"}
57532378475aSmrg    fi
57542378475aSmrg  else
57552378475aSmrg    # The program doesn't exist.
5756eca46af7Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
57572378475aSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
575814330f12Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
57592378475aSmrg    exit 1
57602378475aSmrg  fi
57612378475aSmrgfi\
57622378475aSmrg"
57632378475aSmrg}
576495b296d0Smrg
576539713583Smrg
57662378475aSmrg# func_emit_cwrapperexe_src
57672378475aSmrg# emit the source code for a wrapper executable on stdout
57682378475aSmrg# Must ONLY be called from within func_mode_link because
57692378475aSmrg# it depends on a number of variable set therein.
57702378475aSmrgfunc_emit_cwrapperexe_src ()
57712378475aSmrg{
57722378475aSmrg	cat <<EOF
577395b296d0Smrg
57742378475aSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775eca46af7Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
577695b296d0Smrg
57772378475aSmrg   The $output program cannot be directly executed until all the libtool
57782378475aSmrg   libraries that it depends on are installed.
577995b296d0Smrg
57802378475aSmrg   This wrapper executable should never be moved out of the build directory.
57812378475aSmrg   If it is, it will not operate correctly.
57822378475aSmrg*/
57832378475aSmrgEOF
57842378475aSmrg	    cat <<"EOF"
578514330f12Smrg#ifdef _MSC_VER
578614330f12Smrg# define _CRT_SECURE_NO_DEPRECATE 1
578714330f12Smrg#endif
57882378475aSmrg#include <stdio.h>
57892378475aSmrg#include <stdlib.h>
57902378475aSmrg#ifdef _MSC_VER
57912378475aSmrg# include <direct.h>
57922378475aSmrg# include <process.h>
57932378475aSmrg# include <io.h>
57942378475aSmrg#else
57952378475aSmrg# include <unistd.h>
57962378475aSmrg# include <stdint.h>
57972378475aSmrg# ifdef __CYGWIN__
57982378475aSmrg#  include <io.h>
57992378475aSmrg# endif
58002378475aSmrg#endif
58012378475aSmrg#include <malloc.h>
58022378475aSmrg#include <stdarg.h>
58032378475aSmrg#include <assert.h>
58042378475aSmrg#include <string.h>
58052378475aSmrg#include <ctype.h>
58062378475aSmrg#include <errno.h>
58072378475aSmrg#include <fcntl.h>
58082378475aSmrg#include <sys/stat.h>
580995b296d0Smrg
5810eca46af7Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811eca46af7Smrg
581214330f12Smrg/* declarations of non-ANSI functions */
5813eca46af7Smrg#if defined __MINGW32__
581414330f12Smrg# ifdef __STRICT_ANSI__
581514330f12Smrgint _putenv (const char *);
581614330f12Smrg# endif
5817eca46af7Smrg#elif defined __CYGWIN__
581814330f12Smrg# ifdef __STRICT_ANSI__
581914330f12Smrgchar *realpath (const char *, char *);
582014330f12Smrgint putenv (char *);
582114330f12Smrgint setenv (const char *, const char *, int);
582214330f12Smrg# endif
5823eca46af7Smrg/* #elif defined other_platform || defined ... */
582414330f12Smrg#endif
582514330f12Smrg
582614330f12Smrg/* portability defines, excluding path handling macros */
5827eca46af7Smrg#if defined _MSC_VER
582814330f12Smrg# define setmode _setmode
582914330f12Smrg# define stat    _stat
583014330f12Smrg# define chmod   _chmod
583114330f12Smrg# define getcwd  _getcwd
583214330f12Smrg# define putenv  _putenv
583314330f12Smrg# define S_IXUSR _S_IEXEC
5834eca46af7Smrg#elif defined __MINGW32__
583514330f12Smrg# define setmode _setmode
583614330f12Smrg# define stat    _stat
583714330f12Smrg# define chmod   _chmod
583814330f12Smrg# define getcwd  _getcwd
583914330f12Smrg# define putenv  _putenv
5840eca46af7Smrg#elif defined __CYGWIN__
584114330f12Smrg# define HAVE_SETENV
584214330f12Smrg# define FOPEN_WB "wb"
5843eca46af7Smrg/* #elif defined other platforms ... */
584414330f12Smrg#endif
584514330f12Smrg
5846eca46af7Smrg#if defined PATH_MAX
58472378475aSmrg# define LT_PATHMAX PATH_MAX
5848eca46af7Smrg#elif defined MAXPATHLEN
58492378475aSmrg# define LT_PATHMAX MAXPATHLEN
58502378475aSmrg#else
58512378475aSmrg# define LT_PATHMAX 1024
58522378475aSmrg#endif
585395b296d0Smrg
58542378475aSmrg#ifndef S_IXOTH
58552378475aSmrg# define S_IXOTH 0
58562378475aSmrg#endif
58572378475aSmrg#ifndef S_IXGRP
58582378475aSmrg# define S_IXGRP 0
58592378475aSmrg#endif
586095b296d0Smrg
586114330f12Smrg/* path handling portability macros */
58622378475aSmrg#ifndef DIR_SEPARATOR
58632378475aSmrg# define DIR_SEPARATOR '/'
58642378475aSmrg# define PATH_SEPARATOR ':'
58652378475aSmrg#endif
586695b296d0Smrg
5867eca46af7Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868eca46af7Smrg  defined __OS2__
58692378475aSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
58702378475aSmrg# define FOPEN_WB "wb"
58712378475aSmrg# ifndef DIR_SEPARATOR_2
58722378475aSmrg#  define DIR_SEPARATOR_2 '\\'
58732378475aSmrg# endif
58742378475aSmrg# ifndef PATH_SEPARATOR_2
58752378475aSmrg#  define PATH_SEPARATOR_2 ';'
58762378475aSmrg# endif
58772378475aSmrg#endif
587895b296d0Smrg
58792378475aSmrg#ifndef DIR_SEPARATOR_2
58802378475aSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
58812378475aSmrg#else /* DIR_SEPARATOR_2 */
58822378475aSmrg# define IS_DIR_SEPARATOR(ch) \
58832378475aSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
58842378475aSmrg#endif /* DIR_SEPARATOR_2 */
588595b296d0Smrg
58862378475aSmrg#ifndef PATH_SEPARATOR_2
58872378475aSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
58882378475aSmrg#else /* PATH_SEPARATOR_2 */
58892378475aSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
58902378475aSmrg#endif /* PATH_SEPARATOR_2 */
589195b296d0Smrg
58922378475aSmrg#ifndef FOPEN_WB
58932378475aSmrg# define FOPEN_WB "w"
58942378475aSmrg#endif
58952378475aSmrg#ifndef _O_BINARY
58962378475aSmrg# define _O_BINARY 0
58972378475aSmrg#endif
589895b296d0Smrg
58992378475aSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
59002378475aSmrg#define XFREE(stale) do { \
5901eca46af7Smrg  if (stale) { free (stale); stale = 0; } \
59022378475aSmrg} while (0)
590395b296d0Smrg
5904eca46af7Smrg#if defined LT_DEBUGWRAPPER
590514330f12Smrgstatic int lt_debug = 1;
59062378475aSmrg#else
590714330f12Smrgstatic int lt_debug = 0;
59082378475aSmrg#endif
590995b296d0Smrg
591014330f12Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
591195b296d0Smrg
59122378475aSmrgvoid *xmalloc (size_t num);
59132378475aSmrgchar *xstrdup (const char *string);
59142378475aSmrgconst char *base_name (const char *name);
59152378475aSmrgchar *find_executable (const char *wrapper);
59162378475aSmrgchar *chase_symlinks (const char *pathspec);
59172378475aSmrgint make_executable (const char *path);
59182378475aSmrgint check_executable (const char *path);
59192378475aSmrgchar *strendzap (char *str, const char *pat);
592014330f12Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
592114330f12Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
592214330f12Smrgstatic const char *nonnull (const char *s);
592314330f12Smrgstatic const char *nonempty (const char *s);
59242378475aSmrgvoid lt_setenv (const char *name, const char *value);
59252378475aSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
59262378475aSmrgvoid lt_update_exe_path (const char *name, const char *value);
59272378475aSmrgvoid lt_update_lib_path (const char *name, const char *value);
592814330f12Smrgchar **prepare_spawn (char **argv);
592914330f12Smrgvoid lt_dump_script (FILE *f);
59302378475aSmrgEOF
59312378475aSmrg
59322378475aSmrg	    cat <<EOF
5933eca46af7Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934eca46af7Smrg# define externally_visible volatile
5935eca46af7Smrg#else
5936eca46af7Smrg# define externally_visible __attribute__((externally_visible)) volatile
5937eca46af7Smrg#endif
5938eca46af7Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
59392378475aSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
59402378475aSmrgEOF
594195b296d0Smrg
5942eca46af7Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
594314330f12Smrg              func_to_host_path "$temp_rpath"
59442378475aSmrg	      cat <<EOF
594514330f12Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
59462378475aSmrgEOF
59472378475aSmrg	    else
59482378475aSmrg	      cat <<"EOF"
59492378475aSmrgconst char * LIB_PATH_VALUE   = "";
59502378475aSmrgEOF
5951e6f085baSmrg	    fi
595295b296d0Smrg
59532378475aSmrg	    if test -n "$dllsearchpath"; then
595414330f12Smrg              func_to_host_path "$dllsearchpath:"
59552378475aSmrg	      cat <<EOF
59562378475aSmrgconst char * EXE_PATH_VARNAME = "PATH";
595714330f12Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5958e6f085baSmrgEOF
5959e6f085baSmrg	    else
59602378475aSmrg	      cat <<"EOF"
59612378475aSmrgconst char * EXE_PATH_VARNAME = "";
59622378475aSmrgconst char * EXE_PATH_VALUE   = "";
59632378475aSmrgEOF
5964e6f085baSmrg	    fi
59652378475aSmrg
5966eca46af7Smrg	    if test yes = "$fast_install"; then
59672378475aSmrg	      cat <<EOF
59682378475aSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
59692378475aSmrgEOF
5970e6f085baSmrg	    else
59712378475aSmrg	      cat <<EOF
59722378475aSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
59732378475aSmrgEOF
5974e6f085baSmrg	    fi
597595b296d0Smrg
597695b296d0Smrg
59772378475aSmrg	    cat <<"EOF"
597895b296d0Smrg
59792378475aSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
598095b296d0Smrg
59812378475aSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
59822378475aSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
598314330f12Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
598495b296d0Smrg
59852378475aSmrgint
59862378475aSmrgmain (int argc, char *argv[])
59872378475aSmrg{
59882378475aSmrg  char **newargz;
59892378475aSmrg  int  newargc;
59902378475aSmrg  char *tmp_pathspec;
59912378475aSmrg  char *actual_cwrapper_path;
59922378475aSmrg  char *actual_cwrapper_name;
59932378475aSmrg  char *target_name;
59942378475aSmrg  char *lt_argv_zero;
5995eca46af7Smrg  int rval = 127;
599695b296d0Smrg
59972378475aSmrg  int i;
599895b296d0Smrg
59992378475aSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000eca46af7Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
600195b296d0Smrg
600214330f12Smrg  /* very simple arg parsing; don't want to rely on getopt
600314330f12Smrg   * also, copy all non cwrapper options to newargz, except
600414330f12Smrg   * argz[0], which is handled differently
600514330f12Smrg   */
600614330f12Smrg  newargc=0;
60072378475aSmrg  for (i = 1; i < argc; i++)
60082378475aSmrg    {
6009eca46af7Smrg      if (STREQ (argv[i], dumpscript_opt))
60102378475aSmrg	{
60112378475aSmrgEOF
6012eca46af7Smrg	    case $host in
60132378475aSmrg	      *mingw* | *cygwin* )
60142378475aSmrg		# make stdout use "unix" line endings
60152378475aSmrg		echo "          setmode(1,_O_BINARY);"
60162378475aSmrg		;;
60172378475aSmrg	      esac
601895b296d0Smrg
60192378475aSmrg	    cat <<"EOF"
602014330f12Smrg	  lt_dump_script (stdout);
60212378475aSmrg	  return 0;
60222378475aSmrg	}
6023eca46af7Smrg      if (STREQ (argv[i], debug_opt))
602414330f12Smrg	{
602514330f12Smrg          lt_debug = 1;
602614330f12Smrg          continue;
602714330f12Smrg	}
6028eca46af7Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
602914330f12Smrg        {
603014330f12Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
603114330f12Smrg             namespace, but it is not one of the ones we know about and
603214330f12Smrg             have already dealt with, above (inluding dump-script), then
603314330f12Smrg             report an error. Otherwise, targets might begin to believe
603414330f12Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
603514330f12Smrg             namespace. The first time any user complains about this, we'll
603614330f12Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
603714330f12Smrg             or a configure.ac-settable value.
603814330f12Smrg           */
603914330f12Smrg          lt_fatal (__FILE__, __LINE__,
604014330f12Smrg		    "unrecognized %s option: '%s'",
604114330f12Smrg                    ltwrapper_option_prefix, argv[i]);
604214330f12Smrg        }
604314330f12Smrg      /* otherwise ... */
604414330f12Smrg      newargz[++newargc] = xstrdup (argv[i]);
60452378475aSmrg    }
604614330f12Smrg  newargz[++newargc] = NULL;
604714330f12Smrg
604814330f12SmrgEOF
604914330f12Smrg	    cat <<EOF
605014330f12Smrg  /* The GNU banner must be the first non-error debug message */
6051eca46af7Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
605214330f12SmrgEOF
605314330f12Smrg	    cat <<"EOF"
605414330f12Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
605514330f12Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
605695b296d0Smrg
60572378475aSmrg  tmp_pathspec = find_executable (argv[0]);
60582378475aSmrg  if (tmp_pathspec == NULL)
605914330f12Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
606014330f12Smrg  lt_debugprintf (__FILE__, __LINE__,
606114330f12Smrg                  "(main) found exe (before symlink chase) at: %s\n",
606214330f12Smrg		  tmp_pathspec);
60632378475aSmrg
60642378475aSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
606514330f12Smrg  lt_debugprintf (__FILE__, __LINE__,
606614330f12Smrg                  "(main) found exe (after symlink chase) at: %s\n",
606714330f12Smrg		  actual_cwrapper_path);
60682378475aSmrg  XFREE (tmp_pathspec);
60692378475aSmrg
607014330f12Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
60712378475aSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
60722378475aSmrg
60732378475aSmrg  /* wrapper name transforms */
60742378475aSmrg  strendzap (actual_cwrapper_name, ".exe");
60752378475aSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
60762378475aSmrg  XFREE (actual_cwrapper_name);
60772378475aSmrg  actual_cwrapper_name = tmp_pathspec;
60782378475aSmrg  tmp_pathspec = 0;
60792378475aSmrg
60802378475aSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
60812378475aSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
60822378475aSmrg  strendzap (target_name, ".exe");
60832378475aSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
60842378475aSmrg  XFREE (target_name);
60852378475aSmrg  target_name = tmp_pathspec;
60862378475aSmrg  tmp_pathspec = 0;
60872378475aSmrg
608814330f12Smrg  lt_debugprintf (__FILE__, __LINE__,
608914330f12Smrg		  "(main) libtool target name: %s\n",
609014330f12Smrg		  target_name);
60912378475aSmrgEOF
609295b296d0Smrg
60932378475aSmrg	    cat <<EOF
60942378475aSmrg  newargz[0] =
60952378475aSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
60962378475aSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
60972378475aSmrg  strcpy (newargz[0], actual_cwrapper_path);
60982378475aSmrg  strcat (newargz[0], "$objdir");
60992378475aSmrg  strcat (newargz[0], "/");
61002378475aSmrgEOF
610195b296d0Smrg
61022378475aSmrg	    cat <<"EOF"
61032378475aSmrg  /* stop here, and copy so we don't have to do this twice */
61042378475aSmrg  tmp_pathspec = xstrdup (newargz[0]);
610595b296d0Smrg
61062378475aSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
61072378475aSmrg  strcat (newargz[0], actual_cwrapper_name);
610895b296d0Smrg
61092378475aSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
61102378475aSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
61112378475aSmrg  XFREE (tmp_pathspec);
61122378475aSmrg  tmp_pathspec = NULL;
61132378475aSmrgEOF
611495b296d0Smrg
61152378475aSmrg	    case $host_os in
61162378475aSmrg	      mingw*)
61172378475aSmrg	    cat <<"EOF"
61182378475aSmrg  {
61192378475aSmrg    char* p;
61202378475aSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
61212378475aSmrg      {
61222378475aSmrg	*p = '/';
61232378475aSmrg      }
61242378475aSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
61252378475aSmrg      {
61262378475aSmrg	*p = '/';
61272378475aSmrg      }
61282378475aSmrg  }
61292378475aSmrgEOF
61302378475aSmrg	    ;;
61312378475aSmrg	    esac
613295b296d0Smrg
61332378475aSmrg	    cat <<"EOF"
61342378475aSmrg  XFREE (target_name);
61352378475aSmrg  XFREE (actual_cwrapper_path);
61362378475aSmrg  XFREE (actual_cwrapper_name);
613795b296d0Smrg
61382378475aSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
61392378475aSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
614014330f12Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
614114330f12Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
614214330f12Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
614314330f12Smrg     libraries must come first. */
61442378475aSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
614514330f12Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
614695b296d0Smrg
614714330f12Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
614814330f12Smrg		  nonnull (lt_argv_zero));
61492378475aSmrg  for (i = 0; i < newargc; i++)
61502378475aSmrg    {
615114330f12Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
615214330f12Smrg		      i, nonnull (newargz[i]));
61532378475aSmrg    }
615495b296d0Smrg
61552378475aSmrgEOF
615695b296d0Smrg
61572378475aSmrg	    case $host_os in
61582378475aSmrg	      mingw*)
61592378475aSmrg		cat <<"EOF"
61602378475aSmrg  /* execv doesn't actually work on mingw as expected on unix */
616114330f12Smrg  newargz = prepare_spawn (newargz);
6162eca46af7Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
61632378475aSmrg  if (rval == -1)
61642378475aSmrg    {
61652378475aSmrg      /* failed to start process */
616614330f12Smrg      lt_debugprintf (__FILE__, __LINE__,
616714330f12Smrg		      "(main) failed to launch target \"%s\": %s\n",
616814330f12Smrg		      lt_argv_zero, nonnull (strerror (errno)));
61692378475aSmrg      return 127;
61702378475aSmrg    }
61712378475aSmrg  return rval;
61722378475aSmrgEOF
61732378475aSmrg		;;
61742378475aSmrg	      *)
61752378475aSmrg		cat <<"EOF"
61762378475aSmrg  execv (lt_argv_zero, newargz);
61772378475aSmrg  return rval; /* =127, but avoids unused variable warning */
61782378475aSmrgEOF
61792378475aSmrg		;;
61802378475aSmrg	    esac
618195b296d0Smrg
61822378475aSmrg	    cat <<"EOF"
61832378475aSmrg}
618495b296d0Smrg
61852378475aSmrgvoid *
61862378475aSmrgxmalloc (size_t num)
61872378475aSmrg{
61882378475aSmrg  void *p = (void *) malloc (num);
61892378475aSmrg  if (!p)
619014330f12Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
619195b296d0Smrg
61922378475aSmrg  return p;
61932378475aSmrg}
619495b296d0Smrg
61952378475aSmrgchar *
61962378475aSmrgxstrdup (const char *string)
61972378475aSmrg{
61982378475aSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
61992378475aSmrg			  string) : NULL;
62002378475aSmrg}
620195b296d0Smrg
62022378475aSmrgconst char *
62032378475aSmrgbase_name (const char *name)
62042378475aSmrg{
62052378475aSmrg  const char *base;
6206e6f085baSmrg
6207eca46af7Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62082378475aSmrg  /* Skip over the disk name in MSDOS pathnames. */
62092378475aSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
62102378475aSmrg    name += 2;
62112378475aSmrg#endif
6212e6f085baSmrg
62132378475aSmrg  for (base = name; *name; name++)
62142378475aSmrg    if (IS_DIR_SEPARATOR (*name))
62152378475aSmrg      base = name + 1;
62162378475aSmrg  return base;
62172378475aSmrg}
6218e6f085baSmrg
62192378475aSmrgint
62202378475aSmrgcheck_executable (const char *path)
62212378475aSmrg{
62222378475aSmrg  struct stat st;
6223e6f085baSmrg
622414330f12Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
622514330f12Smrg                  nonempty (path));
62262378475aSmrg  if ((!path) || (!*path))
62272378475aSmrg    return 0;
6228e6f085baSmrg
62292378475aSmrg  if ((stat (path, &st) >= 0)
62302378475aSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
62312378475aSmrg    return 1;
62322378475aSmrg  else
62332378475aSmrg    return 0;
62342378475aSmrg}
623595b296d0Smrg
62362378475aSmrgint
62372378475aSmrgmake_executable (const char *path)
62382378475aSmrg{
62392378475aSmrg  int rval = 0;
62402378475aSmrg  struct stat st;
624195b296d0Smrg
624214330f12Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
624314330f12Smrg                  nonempty (path));
62442378475aSmrg  if ((!path) || (!*path))
62452378475aSmrg    return 0;
624639713583Smrg
62472378475aSmrg  if (stat (path, &st) >= 0)
62482378475aSmrg    {
62492378475aSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
62502378475aSmrg    }
62512378475aSmrg  return rval;
62522378475aSmrg}
6253e6f085baSmrg
62542378475aSmrg/* Searches for the full path of the wrapper.  Returns
62552378475aSmrg   newly allocated full path name if found, NULL otherwise
62562378475aSmrg   Does not chase symlinks, even on platforms that support them.
62572378475aSmrg*/
62582378475aSmrgchar *
62592378475aSmrgfind_executable (const char *wrapper)
62602378475aSmrg{
62612378475aSmrg  int has_slash = 0;
62622378475aSmrg  const char *p;
62632378475aSmrg  const char *p_next;
62642378475aSmrg  /* static buffer for getcwd */
62652378475aSmrg  char tmp[LT_PATHMAX + 1];
6266eca46af7Smrg  size_t tmp_len;
62672378475aSmrg  char *concat_name;
6268e6f085baSmrg
626914330f12Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
627014330f12Smrg                  nonempty (wrapper));
6271e6f085baSmrg
62722378475aSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
62732378475aSmrg    return NULL;
6274e6f085baSmrg
62752378475aSmrg  /* Absolute path? */
6276eca46af7Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62772378475aSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
62782378475aSmrg    {
62792378475aSmrg      concat_name = xstrdup (wrapper);
62802378475aSmrg      if (check_executable (concat_name))
62812378475aSmrg	return concat_name;
62822378475aSmrg      XFREE (concat_name);
62832378475aSmrg    }
62842378475aSmrg  else
62852378475aSmrg    {
62862378475aSmrg#endif
62872378475aSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
62882378475aSmrg	{
62892378475aSmrg	  concat_name = xstrdup (wrapper);
62902378475aSmrg	  if (check_executable (concat_name))
62912378475aSmrg	    return concat_name;
62922378475aSmrg	  XFREE (concat_name);
62932378475aSmrg	}
6294eca46af7Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62952378475aSmrg    }
62962378475aSmrg#endif
629795b296d0Smrg
62982378475aSmrg  for (p = wrapper; *p; p++)
62992378475aSmrg    if (*p == '/')
63002378475aSmrg      {
63012378475aSmrg	has_slash = 1;
63022378475aSmrg	break;
63032378475aSmrg      }
63042378475aSmrg  if (!has_slash)
63052378475aSmrg    {
63062378475aSmrg      /* no slashes; search PATH */
63072378475aSmrg      const char *path = getenv ("PATH");
63082378475aSmrg      if (path != NULL)
63092378475aSmrg	{
63102378475aSmrg	  for (p = path; *p; p = p_next)
63112378475aSmrg	    {
63122378475aSmrg	      const char *q;
63132378475aSmrg	      size_t p_len;
63142378475aSmrg	      for (q = p; *q; q++)
63152378475aSmrg		if (IS_PATH_SEPARATOR (*q))
63162378475aSmrg		  break;
6317eca46af7Smrg	      p_len = (size_t) (q - p);
63182378475aSmrg	      p_next = (*q == '\0' ? q : q + 1);
63192378475aSmrg	      if (p_len == 0)
63202378475aSmrg		{
63212378475aSmrg		  /* empty path: current directory */
63222378475aSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
632314330f12Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
632414330f12Smrg                              nonnull (strerror (errno)));
63252378475aSmrg		  tmp_len = strlen (tmp);
63262378475aSmrg		  concat_name =
63272378475aSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63282378475aSmrg		  memcpy (concat_name, tmp, tmp_len);
63292378475aSmrg		  concat_name[tmp_len] = '/';
63302378475aSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
63312378475aSmrg		}
63322378475aSmrg	      else
63332378475aSmrg		{
63342378475aSmrg		  concat_name =
63352378475aSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
63362378475aSmrg		  memcpy (concat_name, p, p_len);
63372378475aSmrg		  concat_name[p_len] = '/';
63382378475aSmrg		  strcpy (concat_name + p_len + 1, wrapper);
63392378475aSmrg		}
63402378475aSmrg	      if (check_executable (concat_name))
63412378475aSmrg		return concat_name;
63422378475aSmrg	      XFREE (concat_name);
63432378475aSmrg	    }
63442378475aSmrg	}
63452378475aSmrg      /* not found in PATH; assume curdir */
63462378475aSmrg    }
63472378475aSmrg  /* Relative path | not found in path: prepend cwd */
63482378475aSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
634914330f12Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
635014330f12Smrg              nonnull (strerror (errno)));
63512378475aSmrg  tmp_len = strlen (tmp);
63522378475aSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63532378475aSmrg  memcpy (concat_name, tmp, tmp_len);
63542378475aSmrg  concat_name[tmp_len] = '/';
63552378475aSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
635695b296d0Smrg
63572378475aSmrg  if (check_executable (concat_name))
63582378475aSmrg    return concat_name;
63592378475aSmrg  XFREE (concat_name);
63602378475aSmrg  return NULL;
63612378475aSmrg}
636295b296d0Smrg
63632378475aSmrgchar *
63642378475aSmrgchase_symlinks (const char *pathspec)
63652378475aSmrg{
63662378475aSmrg#ifndef S_ISLNK
63672378475aSmrg  return xstrdup (pathspec);
63682378475aSmrg#else
63692378475aSmrg  char buf[LT_PATHMAX];
63702378475aSmrg  struct stat s;
63712378475aSmrg  char *tmp_pathspec = xstrdup (pathspec);
63722378475aSmrg  char *p;
63732378475aSmrg  int has_symlinks = 0;
63742378475aSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
63752378475aSmrg    {
637614330f12Smrg      lt_debugprintf (__FILE__, __LINE__,
637714330f12Smrg		      "checking path component for symlinks: %s\n",
637814330f12Smrg		      tmp_pathspec);
63792378475aSmrg      if (lstat (tmp_pathspec, &s) == 0)
63802378475aSmrg	{
63812378475aSmrg	  if (S_ISLNK (s.st_mode) != 0)
63822378475aSmrg	    {
63832378475aSmrg	      has_symlinks = 1;
63842378475aSmrg	      break;
63852378475aSmrg	    }
638695b296d0Smrg
63872378475aSmrg	  /* search backwards for last DIR_SEPARATOR */
63882378475aSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
63892378475aSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63902378475aSmrg	    p--;
63912378475aSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63922378475aSmrg	    {
63932378475aSmrg	      /* no more DIR_SEPARATORS left */
63942378475aSmrg	      break;
63952378475aSmrg	    }
63962378475aSmrg	  *p = '\0';
63972378475aSmrg	}
63982378475aSmrg      else
63992378475aSmrg	{
640014330f12Smrg	  lt_fatal (__FILE__, __LINE__,
640114330f12Smrg		    "error accessing file \"%s\": %s",
640214330f12Smrg		    tmp_pathspec, nonnull (strerror (errno)));
64032378475aSmrg	}
64042378475aSmrg    }
64052378475aSmrg  XFREE (tmp_pathspec);
640695b296d0Smrg
64072378475aSmrg  if (!has_symlinks)
64082378475aSmrg    {
64092378475aSmrg      return xstrdup (pathspec);
64102378475aSmrg    }
641195b296d0Smrg
64122378475aSmrg  tmp_pathspec = realpath (pathspec, buf);
64132378475aSmrg  if (tmp_pathspec == 0)
64142378475aSmrg    {
641514330f12Smrg      lt_fatal (__FILE__, __LINE__,
641614330f12Smrg		"could not follow symlinks for %s", pathspec);
64172378475aSmrg    }
64182378475aSmrg  return xstrdup (tmp_pathspec);
64192378475aSmrg#endif
64202378475aSmrg}
642195b296d0Smrg
64222378475aSmrgchar *
64232378475aSmrgstrendzap (char *str, const char *pat)
64242378475aSmrg{
64252378475aSmrg  size_t len, patlen;
642695b296d0Smrg
64272378475aSmrg  assert (str != NULL);
64282378475aSmrg  assert (pat != NULL);
642995b296d0Smrg
64302378475aSmrg  len = strlen (str);
64312378475aSmrg  patlen = strlen (pat);
643295b296d0Smrg
64332378475aSmrg  if (patlen <= len)
64342378475aSmrg    {
64352378475aSmrg      str += len - patlen;
6436eca46af7Smrg      if (STREQ (str, pat))
64372378475aSmrg	*str = '\0';
64382378475aSmrg    }
64392378475aSmrg  return str;
64402378475aSmrg}
644195b296d0Smrg
644214330f12Smrgvoid
644314330f12Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
644414330f12Smrg{
644514330f12Smrg  va_list args;
644614330f12Smrg  if (lt_debug)
644714330f12Smrg    {
644814330f12Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
644914330f12Smrg      va_start (args, fmt);
645014330f12Smrg      (void) vfprintf (stderr, fmt, args);
645114330f12Smrg      va_end (args);
645214330f12Smrg    }
645314330f12Smrg}
645414330f12Smrg
64552378475aSmrgstatic void
645614330f12Smrglt_error_core (int exit_status, const char *file,
645714330f12Smrg	       int line, const char *mode,
64582378475aSmrg	       const char *message, va_list ap)
64592378475aSmrg{
646014330f12Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
64612378475aSmrg  vfprintf (stderr, message, ap);
64622378475aSmrg  fprintf (stderr, ".\n");
646395b296d0Smrg
64642378475aSmrg  if (exit_status >= 0)
64652378475aSmrg    exit (exit_status);
64662378475aSmrg}
646795b296d0Smrg
64682378475aSmrgvoid
646914330f12Smrglt_fatal (const char *file, int line, const char *message, ...)
64702378475aSmrg{
64712378475aSmrg  va_list ap;
64722378475aSmrg  va_start (ap, message);
647314330f12Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
64742378475aSmrg  va_end (ap);
64752378475aSmrg}
647695b296d0Smrg
647714330f12Smrgstatic const char *
647814330f12Smrgnonnull (const char *s)
647914330f12Smrg{
648014330f12Smrg  return s ? s : "(null)";
648114330f12Smrg}
648214330f12Smrg
648314330f12Smrgstatic const char *
648414330f12Smrgnonempty (const char *s)
648514330f12Smrg{
648614330f12Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
648714330f12Smrg}
648814330f12Smrg
64892378475aSmrgvoid
64902378475aSmrglt_setenv (const char *name, const char *value)
64912378475aSmrg{
649214330f12Smrg  lt_debugprintf (__FILE__, __LINE__,
649314330f12Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
649414330f12Smrg                  nonnull (name), nonnull (value));
64952378475aSmrg  {
64962378475aSmrg#ifdef HAVE_SETENV
64972378475aSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
64982378475aSmrg    char *str = xstrdup (value);
64992378475aSmrg    setenv (name, str, 1);
65002378475aSmrg#else
6501eca46af7Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
65022378475aSmrg    char *str = XMALLOC (char, len);
65032378475aSmrg    sprintf (str, "%s=%s", name, value);
65042378475aSmrg    if (putenv (str) != EXIT_SUCCESS)
65052378475aSmrg      {
65062378475aSmrg        XFREE (str);
65072378475aSmrg      }
65082378475aSmrg#endif
65092378475aSmrg  }
65102378475aSmrg}
651195b296d0Smrg
65122378475aSmrgchar *
65132378475aSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
65142378475aSmrg{
65152378475aSmrg  char *new_value;
65162378475aSmrg  if (orig_value && *orig_value)
65172378475aSmrg    {
6518eca46af7Smrg      size_t orig_value_len = strlen (orig_value);
6519eca46af7Smrg      size_t add_len = strlen (add);
65202378475aSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
65212378475aSmrg      if (to_end)
65222378475aSmrg        {
65232378475aSmrg          strcpy (new_value, orig_value);
65242378475aSmrg          strcpy (new_value + orig_value_len, add);
65252378475aSmrg        }
65262378475aSmrg      else
65272378475aSmrg        {
65282378475aSmrg          strcpy (new_value, add);
65292378475aSmrg          strcpy (new_value + add_len, orig_value);
65302378475aSmrg        }
65312378475aSmrg    }
65322378475aSmrg  else
65332378475aSmrg    {
65342378475aSmrg      new_value = xstrdup (add);
65352378475aSmrg    }
65362378475aSmrg  return new_value;
65372378475aSmrg}
653895b296d0Smrg
65392378475aSmrgvoid
65402378475aSmrglt_update_exe_path (const char *name, const char *value)
65412378475aSmrg{
654214330f12Smrg  lt_debugprintf (__FILE__, __LINE__,
654314330f12Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
654414330f12Smrg                  nonnull (name), nonnull (value));
654595b296d0Smrg
65462378475aSmrg  if (name && *name && value && *value)
65472378475aSmrg    {
65482378475aSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65492378475aSmrg      /* some systems can't cope with a ':'-terminated path #' */
6550eca46af7Smrg      size_t len = strlen (new_value);
6551eca46af7Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
65522378475aSmrg        {
6553eca46af7Smrg          new_value[--len] = '\0';
65542378475aSmrg        }
65552378475aSmrg      lt_setenv (name, new_value);
65562378475aSmrg      XFREE (new_value);
65572378475aSmrg    }
65582378475aSmrg}
655995b296d0Smrg
65602378475aSmrgvoid
65612378475aSmrglt_update_lib_path (const char *name, const char *value)
65622378475aSmrg{
656314330f12Smrg  lt_debugprintf (__FILE__, __LINE__,
656414330f12Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
656514330f12Smrg                  nonnull (name), nonnull (value));
656695b296d0Smrg
65672378475aSmrg  if (name && *name && value && *value)
65682378475aSmrg    {
65692378475aSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65702378475aSmrg      lt_setenv (name, new_value);
65712378475aSmrg      XFREE (new_value);
65722378475aSmrg    }
65732378475aSmrg}
657495b296d0Smrg
657514330f12SmrgEOF
657614330f12Smrg	    case $host_os in
657714330f12Smrg	      mingw*)
657814330f12Smrg		cat <<"EOF"
657914330f12Smrg
658014330f12Smrg/* Prepares an argument vector before calling spawn().
658114330f12Smrg   Note that spawn() does not by itself call the command interpreter
658214330f12Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
658314330f12Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
658414330f12Smrg         GetVersionEx(&v);
658514330f12Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
658614330f12Smrg      }) ? "cmd.exe" : "command.com").
658714330f12Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
658814330f12Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
658914330f12Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
659014330f12Smrg   special way:
659114330f12Smrg   - Space and tab are interpreted as delimiters. They are not treated as
659214330f12Smrg     delimiters if they are surrounded by double quotes: "...".
659314330f12Smrg   - Unescaped double quotes are removed from the input. Their only effect is
659414330f12Smrg     that within double quotes, space and tab are treated like normal
659514330f12Smrg     characters.
659614330f12Smrg   - Backslashes not followed by double quotes are not special.
659714330f12Smrg   - But 2*n+1 backslashes followed by a double quote become
659814330f12Smrg     n backslashes followed by a double quote (n >= 0):
659914330f12Smrg       \" -> "
660014330f12Smrg       \\\" -> \"
660114330f12Smrg       \\\\\" -> \\"
660214330f12Smrg */
660314330f12Smrg#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"
660414330f12Smrg#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"
660514330f12Smrgchar **
660614330f12Smrgprepare_spawn (char **argv)
660714330f12Smrg{
660814330f12Smrg  size_t argc;
660914330f12Smrg  char **new_argv;
661014330f12Smrg  size_t i;
661114330f12Smrg
661214330f12Smrg  /* Count number of arguments.  */
661314330f12Smrg  for (argc = 0; argv[argc] != NULL; argc++)
661414330f12Smrg    ;
661514330f12Smrg
661614330f12Smrg  /* Allocate new argument vector.  */
661714330f12Smrg  new_argv = XMALLOC (char *, argc + 1);
661814330f12Smrg
661914330f12Smrg  /* Put quoted arguments into the new argument vector.  */
662014330f12Smrg  for (i = 0; i < argc; i++)
662114330f12Smrg    {
662214330f12Smrg      const char *string = argv[i];
662314330f12Smrg
662414330f12Smrg      if (string[0] == '\0')
662514330f12Smrg	new_argv[i] = xstrdup ("\"\"");
662614330f12Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
662714330f12Smrg	{
662814330f12Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
662914330f12Smrg	  size_t length;
663014330f12Smrg	  unsigned int backslashes;
663114330f12Smrg	  const char *s;
663214330f12Smrg	  char *quoted_string;
663314330f12Smrg	  char *p;
663414330f12Smrg
663514330f12Smrg	  length = 0;
663614330f12Smrg	  backslashes = 0;
663714330f12Smrg	  if (quote_around)
663814330f12Smrg	    length++;
663914330f12Smrg	  for (s = string; *s != '\0'; s++)
664014330f12Smrg	    {
664114330f12Smrg	      char c = *s;
664214330f12Smrg	      if (c == '"')
664314330f12Smrg		length += backslashes + 1;
664414330f12Smrg	      length++;
664514330f12Smrg	      if (c == '\\')
664614330f12Smrg		backslashes++;
664714330f12Smrg	      else
664814330f12Smrg		backslashes = 0;
664914330f12Smrg	    }
665014330f12Smrg	  if (quote_around)
665114330f12Smrg	    length += backslashes + 1;
665214330f12Smrg
665314330f12Smrg	  quoted_string = XMALLOC (char, length + 1);
665414330f12Smrg
665514330f12Smrg	  p = quoted_string;
665614330f12Smrg	  backslashes = 0;
665714330f12Smrg	  if (quote_around)
665814330f12Smrg	    *p++ = '"';
665914330f12Smrg	  for (s = string; *s != '\0'; s++)
666014330f12Smrg	    {
666114330f12Smrg	      char c = *s;
666214330f12Smrg	      if (c == '"')
666314330f12Smrg		{
666414330f12Smrg		  unsigned int j;
666514330f12Smrg		  for (j = backslashes + 1; j > 0; j--)
666614330f12Smrg		    *p++ = '\\';
666714330f12Smrg		}
666814330f12Smrg	      *p++ = c;
666914330f12Smrg	      if (c == '\\')
667014330f12Smrg		backslashes++;
667114330f12Smrg	      else
667214330f12Smrg		backslashes = 0;
667314330f12Smrg	    }
667414330f12Smrg	  if (quote_around)
667514330f12Smrg	    {
667614330f12Smrg	      unsigned int j;
667714330f12Smrg	      for (j = backslashes; j > 0; j--)
667814330f12Smrg		*p++ = '\\';
667914330f12Smrg	      *p++ = '"';
668014330f12Smrg	    }
668114330f12Smrg	  *p = '\0';
668214330f12Smrg
668314330f12Smrg	  new_argv[i] = quoted_string;
668414330f12Smrg	}
668514330f12Smrg      else
668614330f12Smrg	new_argv[i] = (char *) string;
668714330f12Smrg    }
668814330f12Smrg  new_argv[argc] = NULL;
668914330f12Smrg
669014330f12Smrg  return new_argv;
669114330f12Smrg}
669214330f12SmrgEOF
669314330f12Smrg		;;
669414330f12Smrg	    esac
669514330f12Smrg
669614330f12Smrg            cat <<"EOF"
669714330f12Smrgvoid lt_dump_script (FILE* f)
669814330f12Smrg{
669914330f12SmrgEOF
670014330f12Smrg	    func_emit_wrapper yes |
6701eca46af7Smrg	      $SED -n -e '
6702eca46af7Smrgs/^\(.\{79\}\)\(..*\)/\1\
6703eca46af7Smrg\2/
6704eca46af7Smrgh
6705eca46af7Smrgs/\([\\"]\)/\\\1/g
6706eca46af7Smrgs/$/\\n/
6707eca46af7Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708eca46af7Smrgg
6709eca46af7SmrgD'
671014330f12Smrg            cat <<"EOF"
671114330f12Smrg}
67122378475aSmrgEOF
67132378475aSmrg}
67142378475aSmrg# end: func_emit_cwrapperexe_src
671595b296d0Smrg
671614330f12Smrg# func_win32_import_lib_p ARG
671714330f12Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
671814330f12Smrgfunc_win32_import_lib_p ()
671914330f12Smrg{
6720eca46af7Smrg    $debug_cmd
6721eca46af7Smrg
672214330f12Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
672314330f12Smrg    *import*) : ;;
672414330f12Smrg    *) false ;;
672514330f12Smrg    esac
672614330f12Smrg}
672714330f12Smrg
672889b0dc75Smrg# func_suncc_cstd_abi
672989b0dc75Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
673089b0dc75Smrg# Several compiler flags select an ABI that is incompatible with the
673189b0dc75Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
673289b0dc75Smrgfunc_suncc_cstd_abi ()
673389b0dc75Smrg{
673489b0dc75Smrg    $debug_cmd
673589b0dc75Smrg
673689b0dc75Smrg    case " $compile_command " in
673789b0dc75Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
673889b0dc75Smrg      suncc_use_cstd_abi=no
673989b0dc75Smrg      ;;
674089b0dc75Smrg    *)
674189b0dc75Smrg      suncc_use_cstd_abi=yes
674289b0dc75Smrg      ;;
674389b0dc75Smrg    esac
674489b0dc75Smrg}
674589b0dc75Smrg
67462378475aSmrg# func_mode_link arg...
67472378475aSmrgfunc_mode_link ()
67482378475aSmrg{
6749eca46af7Smrg    $debug_cmd
6750eca46af7Smrg
67512378475aSmrg    case $host in
67522378475aSmrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
67532378475aSmrg      # It is impossible to link a dll without this setting, and
67542378475aSmrg      # we shouldn't force the makefile maintainer to figure out
6755eca46af7Smrg      # what system we are compiling for in order to pass an extra
67562378475aSmrg      # flag for every libtool invocation.
67572378475aSmrg      # allow_undefined=no
675895b296d0Smrg
67592378475aSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6760eca46af7Smrg      # to make a dll that has undefined symbols, in which case not
67612378475aSmrg      # even a static library is built.  For now, we need to specify
67622378475aSmrg      # -no-undefined on the libtool link line when we can be certain
67632378475aSmrg      # that all symbols are satisfied, otherwise we get a static library.
67642378475aSmrg      allow_undefined=yes
67652378475aSmrg      ;;
67662378475aSmrg    *)
67672378475aSmrg      allow_undefined=yes
67682378475aSmrg      ;;
67692378475aSmrg    esac
67702378475aSmrg    libtool_args=$nonopt
67712378475aSmrg    base_compile="$nonopt $@"
67722378475aSmrg    compile_command=$nonopt
67732378475aSmrg    finalize_command=$nonopt
677495b296d0Smrg
67752378475aSmrg    compile_rpath=
67762378475aSmrg    finalize_rpath=
67772378475aSmrg    compile_shlibpath=
67782378475aSmrg    finalize_shlibpath=
67792378475aSmrg    convenience=
67802378475aSmrg    old_convenience=
67812378475aSmrg    deplibs=
67822378475aSmrg    old_deplibs=
67832378475aSmrg    compiler_flags=
67842378475aSmrg    linker_flags=
67852378475aSmrg    dllsearchpath=
67862378475aSmrg    lib_search_path=`pwd`
67872378475aSmrg    inst_prefix_dir=
67882378475aSmrg    new_inherited_linker_flags=
678995b296d0Smrg
67902378475aSmrg    avoid_version=no
679114330f12Smrg    bindir=
67922378475aSmrg    dlfiles=
67932378475aSmrg    dlprefiles=
67942378475aSmrg    dlself=no
67952378475aSmrg    export_dynamic=no
67962378475aSmrg    export_symbols=
67972378475aSmrg    export_symbols_regex=
67982378475aSmrg    generated=
67992378475aSmrg    libobjs=
68002378475aSmrg    ltlibs=
68012378475aSmrg    module=no
68022378475aSmrg    no_install=no
68032378475aSmrg    objs=
6804eca46af7Smrg    os2dllname=
68052378475aSmrg    non_pic_objects=
68062378475aSmrg    precious_files_regex=
68072378475aSmrg    prefer_static_libs=no
6808eca46af7Smrg    preload=false
68092378475aSmrg    prev=
68102378475aSmrg    prevarg=
68112378475aSmrg    release=
68122378475aSmrg    rpath=
68132378475aSmrg    xrpath=
68142378475aSmrg    perm_rpath=
68152378475aSmrg    temp_rpath=
68162378475aSmrg    thread_safe=no
68172378475aSmrg    vinfo=
68182378475aSmrg    vinfo_number=no
68192378475aSmrg    weak_libs=
6820eca46af7Smrg    single_module=$wl-single_module
68212378475aSmrg    func_infer_tag $base_compile
68222378475aSmrg
68232378475aSmrg    # We need to know -static, to get the right output filenames.
68242378475aSmrg    for arg
68252378475aSmrg    do
68262378475aSmrg      case $arg in
68272378475aSmrg      -shared)
6828eca46af7Smrg	test yes != "$build_libtool_libs" \
6829eca46af7Smrg	  && func_fatal_configuration "cannot build a shared library"
68302378475aSmrg	build_old_libs=no
68312378475aSmrg	break
68322378475aSmrg	;;
68332378475aSmrg      -all-static | -static | -static-libtool-libs)
68342378475aSmrg	case $arg in
68352378475aSmrg	-all-static)
6836eca46af7Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
68372378475aSmrg	    func_warning "complete static linking is impossible in this configuration"
68382378475aSmrg	  fi
68392378475aSmrg	  if test -n "$link_static_flag"; then
68402378475aSmrg	    dlopen_self=$dlopen_self_static
68412378475aSmrg	  fi
68422378475aSmrg	  prefer_static_libs=yes
68432378475aSmrg	  ;;
68442378475aSmrg	-static)
68452378475aSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68462378475aSmrg	    dlopen_self=$dlopen_self_static
68472378475aSmrg	  fi
68482378475aSmrg	  prefer_static_libs=built
68492378475aSmrg	  ;;
68502378475aSmrg	-static-libtool-libs)
68512378475aSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68522378475aSmrg	    dlopen_self=$dlopen_self_static
6853e6f085baSmrg	  fi
68542378475aSmrg	  prefer_static_libs=yes
68552378475aSmrg	  ;;
68562378475aSmrg	esac
68572378475aSmrg	build_libtool_libs=no
68582378475aSmrg	build_old_libs=yes
68592378475aSmrg	break
68602378475aSmrg	;;
68612378475aSmrg      esac
68622378475aSmrg    done
686395b296d0Smrg
68642378475aSmrg    # See if our shared archives depend on static archives.
68652378475aSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
686695b296d0Smrg
68672378475aSmrg    # Go through the arguments, transforming them on the way.
68682378475aSmrg    while test "$#" -gt 0; do
6869eca46af7Smrg      arg=$1
68702378475aSmrg      shift
6871d87a3195Smrg      func_quote_arg pretty,unquoted "$arg"
6872d87a3195Smrg      qarg=$func_quote_arg_unquoted_result
6873d87a3195Smrg      func_append libtool_args " $func_quote_arg_result"
687495b296d0Smrg
68752378475aSmrg      # If the previous option needs an argument, assign it.
68762378475aSmrg      if test -n "$prev"; then
68772378475aSmrg	case $prev in
68782378475aSmrg	output)
68792378475aSmrg	  func_append compile_command " @OUTPUT@"
68802378475aSmrg	  func_append finalize_command " @OUTPUT@"
68812378475aSmrg	  ;;
68822378475aSmrg	esac
688395b296d0Smrg
68842378475aSmrg	case $prev in
688514330f12Smrg	bindir)
6886eca46af7Smrg	  bindir=$arg
688714330f12Smrg	  prev=
688814330f12Smrg	  continue
688914330f12Smrg	  ;;
68902378475aSmrg	dlfiles|dlprefiles)
6891eca46af7Smrg	  $preload || {
68922378475aSmrg	    # Add the symbol object into the linking commands.
68932378475aSmrg	    func_append compile_command " @SYMFILE@"
68942378475aSmrg	    func_append finalize_command " @SYMFILE@"
6895eca46af7Smrg	    preload=:
6896eca46af7Smrg	  }
68972378475aSmrg	  case $arg in
68982378475aSmrg	  *.la | *.lo) ;;  # We handle these cases below.
68992378475aSmrg	  force)
6900eca46af7Smrg	    if test no = "$dlself"; then
69012378475aSmrg	      dlself=needless
69022378475aSmrg	      export_dynamic=yes
69032378475aSmrg	    fi
69042378475aSmrg	    prev=
69052378475aSmrg	    continue
69062378475aSmrg	    ;;
69072378475aSmrg	  self)
6908eca46af7Smrg	    if test dlprefiles = "$prev"; then
69092378475aSmrg	      dlself=yes
6910eca46af7Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
69112378475aSmrg	      dlself=yes
6912e6f085baSmrg	    else
69132378475aSmrg	      dlself=needless
69142378475aSmrg	      export_dynamic=yes
6915e6f085baSmrg	    fi
69162378475aSmrg	    prev=
69172378475aSmrg	    continue
69182378475aSmrg	    ;;
69192378475aSmrg	  *)
6920eca46af7Smrg	    if test dlfiles = "$prev"; then
692114330f12Smrg	      func_append dlfiles " $arg"
6922e6f085baSmrg	    else
692314330f12Smrg	      func_append dlprefiles " $arg"
6924e6f085baSmrg	    fi
69252378475aSmrg	    prev=
69262378475aSmrg	    continue
69272378475aSmrg	    ;;
69282378475aSmrg	  esac
69292378475aSmrg	  ;;
69302378475aSmrg	expsyms)
6931eca46af7Smrg	  export_symbols=$arg
69322378475aSmrg	  test -f "$arg" \
6933eca46af7Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
69342378475aSmrg	  prev=
69352378475aSmrg	  continue
69362378475aSmrg	  ;;
69372378475aSmrg	expsyms_regex)
6938eca46af7Smrg	  export_symbols_regex=$arg
69392378475aSmrg	  prev=
69402378475aSmrg	  continue
69412378475aSmrg	  ;;
69422378475aSmrg	framework)
6943e6f085baSmrg	  case $host in
69442378475aSmrg	    *-*-darwin*)
69452378475aSmrg	      case "$deplibs " in
69462378475aSmrg		*" $qarg.ltframework "*) ;;
694714330f12Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
69482378475aSmrg		   ;;
69492378475aSmrg	      esac
69502378475aSmrg	      ;;
6951e6f085baSmrg	  esac
69522378475aSmrg	  prev=
69532378475aSmrg	  continue
6954e6f085baSmrg	  ;;
69552378475aSmrg	inst_prefix)
6956eca46af7Smrg	  inst_prefix_dir=$arg
6957eca46af7Smrg	  prev=
6958eca46af7Smrg	  continue
6959eca46af7Smrg	  ;;
6960eca46af7Smrg	mllvm)
6961eca46af7Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6962eca46af7Smrg	  # '-mllvm $arg' options when doing the link step.
69632378475aSmrg	  prev=
69642378475aSmrg	  continue
6965e6f085baSmrg	  ;;
69662378475aSmrg	objectlist)
69672378475aSmrg	  if test -f "$arg"; then
69682378475aSmrg	    save_arg=$arg
69692378475aSmrg	    moreargs=
69702378475aSmrg	    for fil in `cat "$save_arg"`
69712378475aSmrg	    do
697214330f12Smrg#	      func_append moreargs " $fil"
69732378475aSmrg	      arg=$fil
69742378475aSmrg	      # A libtool-controlled object.
697595b296d0Smrg
69762378475aSmrg	      # Check to see that this really is a libtool object.
69772378475aSmrg	      if func_lalib_unsafe_p "$arg"; then
69782378475aSmrg		pic_object=
69792378475aSmrg		non_pic_object=
698039713583Smrg
69812378475aSmrg		# Read the .lo file
69822378475aSmrg		func_source "$arg"
698339713583Smrg
69842378475aSmrg		if test -z "$pic_object" ||
69852378475aSmrg		   test -z "$non_pic_object" ||
6986eca46af7Smrg		   test none = "$pic_object" &&
6987eca46af7Smrg		   test none = "$non_pic_object"; then
6988eca46af7Smrg		  func_fatal_error "cannot find name of object for '$arg'"
69892378475aSmrg		fi
699039713583Smrg
69912378475aSmrg		# Extract subdirectory from the argument.
69922378475aSmrg		func_dirname "$arg" "/" ""
6993eca46af7Smrg		xdir=$func_dirname_result
699439713583Smrg
6995eca46af7Smrg		if test none != "$pic_object"; then
69962378475aSmrg		  # Prepend the subdirectory the object is found in.
6997eca46af7Smrg		  pic_object=$xdir$pic_object
699839713583Smrg
6999eca46af7Smrg		  if test dlfiles = "$prev"; then
7000eca46af7Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
700114330f12Smrg		      func_append dlfiles " $pic_object"
70022378475aSmrg		      prev=
70032378475aSmrg		      continue
70042378475aSmrg		    else
70052378475aSmrg		      # If libtool objects are unsupported, then we need to preload.
70062378475aSmrg		      prev=dlprefiles
70072378475aSmrg		    fi
70082378475aSmrg		  fi
700939713583Smrg
70102378475aSmrg		  # CHECK ME:  I think I busted this.  -Ossama
7011eca46af7Smrg		  if test dlprefiles = "$prev"; then
70122378475aSmrg		    # Preload the old-style object.
701314330f12Smrg		    func_append dlprefiles " $pic_object"
70142378475aSmrg		    prev=
70152378475aSmrg		  fi
701639713583Smrg
70172378475aSmrg		  # A PIC object.
70182378475aSmrg		  func_append libobjs " $pic_object"
7019eca46af7Smrg		  arg=$pic_object
70202378475aSmrg		fi
702139713583Smrg
70222378475aSmrg		# Non-PIC object.
7023eca46af7Smrg		if test none != "$non_pic_object"; then
70242378475aSmrg		  # Prepend the subdirectory the object is found in.
7025eca46af7Smrg		  non_pic_object=$xdir$non_pic_object
702639713583Smrg
70272378475aSmrg		  # A standard non-PIC object
70282378475aSmrg		  func_append non_pic_objects " $non_pic_object"
7029eca46af7Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030eca46af7Smrg		    arg=$non_pic_object
70312378475aSmrg		  fi
70322378475aSmrg		else
70332378475aSmrg		  # If the PIC object exists, use it instead.
70342378475aSmrg		  # $xdir was prepended to $pic_object above.
7035eca46af7Smrg		  non_pic_object=$pic_object
70362378475aSmrg		  func_append non_pic_objects " $non_pic_object"
70372378475aSmrg		fi
70382378475aSmrg	      else
70392378475aSmrg		# Only an error if not doing a dry-run.
70402378475aSmrg		if $opt_dry_run; then
70412378475aSmrg		  # Extract subdirectory from the argument.
70422378475aSmrg		  func_dirname "$arg" "/" ""
7043eca46af7Smrg		  xdir=$func_dirname_result
70442378475aSmrg
70452378475aSmrg		  func_lo2o "$arg"
70462378475aSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
70472378475aSmrg		  non_pic_object=$xdir$func_lo2o_result
70482378475aSmrg		  func_append libobjs " $pic_object"
70492378475aSmrg		  func_append non_pic_objects " $non_pic_object"
70502378475aSmrg	        else
7051eca46af7Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
70522378475aSmrg		fi
70532378475aSmrg	      fi
70542378475aSmrg	    done
7055e6f085baSmrg	  else
7056eca46af7Smrg	    func_fatal_error "link input file '$arg' does not exist"
7057e6f085baSmrg	  fi
70582378475aSmrg	  arg=$save_arg
70592378475aSmrg	  prev=
70602378475aSmrg	  continue
70612378475aSmrg	  ;;
7062eca46af7Smrg	os2dllname)
7063eca46af7Smrg	  os2dllname=$arg
7064eca46af7Smrg	  prev=
7065eca46af7Smrg	  continue
7066eca46af7Smrg	  ;;
70672378475aSmrg	precious_regex)
7068eca46af7Smrg	  precious_files_regex=$arg
70692378475aSmrg	  prev=
70702378475aSmrg	  continue
70712378475aSmrg	  ;;
70722378475aSmrg	release)
7073eca46af7Smrg	  release=-$arg
70742378475aSmrg	  prev=
70752378475aSmrg	  continue
70762378475aSmrg	  ;;
70772378475aSmrg	rpath | xrpath)
70782378475aSmrg	  # We need an absolute path.
70792378475aSmrg	  case $arg in
70802378475aSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
70812378475aSmrg	  *)
70822378475aSmrg	    func_fatal_error "only absolute run-paths are allowed"
70832378475aSmrg	    ;;
70842378475aSmrg	  esac
7085eca46af7Smrg	  if test rpath = "$prev"; then
70862378475aSmrg	    case "$rpath " in
70872378475aSmrg	    *" $arg "*) ;;
708814330f12Smrg	    *) func_append rpath " $arg" ;;
70892378475aSmrg	    esac
7090e6f085baSmrg	  else
70912378475aSmrg	    case "$xrpath " in
70922378475aSmrg	    *" $arg "*) ;;
709314330f12Smrg	    *) func_append xrpath " $arg" ;;
70942378475aSmrg	    esac
7095e6f085baSmrg	  fi
70962378475aSmrg	  prev=
70972378475aSmrg	  continue
70982378475aSmrg	  ;;
70992378475aSmrg	shrext)
7100eca46af7Smrg	  shrext_cmds=$arg
71012378475aSmrg	  prev=
71022378475aSmrg	  continue
71032378475aSmrg	  ;;
71042378475aSmrg	weak)
710514330f12Smrg	  func_append weak_libs " $arg"
71062378475aSmrg	  prev=
71072378475aSmrg	  continue
71082378475aSmrg	  ;;
7109d87a3195Smrg	xassembler)
7110d87a3195Smrg	  func_append compiler_flags " -Xassembler $qarg"
7111d87a3195Smrg	  prev=
7112d87a3195Smrg	  func_append compile_command " -Xassembler $qarg"
7113d87a3195Smrg	  func_append finalize_command " -Xassembler $qarg"
7114d87a3195Smrg	  continue
7115d87a3195Smrg	  ;;
71162378475aSmrg	xcclinker)
711714330f12Smrg	  func_append linker_flags " $qarg"
711814330f12Smrg	  func_append compiler_flags " $qarg"
71192378475aSmrg	  prev=
71202378475aSmrg	  func_append compile_command " $qarg"
71212378475aSmrg	  func_append finalize_command " $qarg"
71222378475aSmrg	  continue
71232378475aSmrg	  ;;
71242378475aSmrg	xcompiler)
712514330f12Smrg	  func_append compiler_flags " $qarg"
71262378475aSmrg	  prev=
71272378475aSmrg	  func_append compile_command " $qarg"
71282378475aSmrg	  func_append finalize_command " $qarg"
71292378475aSmrg	  continue
71302378475aSmrg	  ;;
71312378475aSmrg	xlinker)
713214330f12Smrg	  func_append linker_flags " $qarg"
713314330f12Smrg	  func_append compiler_flags " $wl$qarg"
71342378475aSmrg	  prev=
71352378475aSmrg	  func_append compile_command " $wl$qarg"
71362378475aSmrg	  func_append finalize_command " $wl$qarg"
71372378475aSmrg	  continue
71382378475aSmrg	  ;;
71392378475aSmrg	*)
71402378475aSmrg	  eval "$prev=\"\$arg\""
71412378475aSmrg	  prev=
71422378475aSmrg	  continue
71432378475aSmrg	  ;;
714439713583Smrg	esac
71452378475aSmrg      fi # test -n "$prev"
714639713583Smrg
7147eca46af7Smrg      prevarg=$arg
714839713583Smrg
71492378475aSmrg      case $arg in
71502378475aSmrg      -all-static)
71512378475aSmrg	if test -n "$link_static_flag"; then
71522378475aSmrg	  # See comment for -static flag below, for more details.
71532378475aSmrg	  func_append compile_command " $link_static_flag"
71542378475aSmrg	  func_append finalize_command " $link_static_flag"
71552378475aSmrg	fi
71562378475aSmrg	continue
71572378475aSmrg	;;
715839713583Smrg
71592378475aSmrg      -allow-undefined)
71602378475aSmrg	# FIXME: remove this flag sometime in the future.
7161eca46af7Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
71622378475aSmrg	;;
716339713583Smrg
71642378475aSmrg      -avoid-version)
71652378475aSmrg	avoid_version=yes
71662378475aSmrg	continue
71672378475aSmrg	;;
716839713583Smrg
716914330f12Smrg      -bindir)
717014330f12Smrg	prev=bindir
717114330f12Smrg	continue
717214330f12Smrg	;;
717314330f12Smrg
71742378475aSmrg      -dlopen)
71752378475aSmrg	prev=dlfiles
71762378475aSmrg	continue
71772378475aSmrg	;;
717839713583Smrg
71792378475aSmrg      -dlpreopen)
71802378475aSmrg	prev=dlprefiles
71812378475aSmrg	continue
71822378475aSmrg	;;
718339713583Smrg
71842378475aSmrg      -export-dynamic)
71852378475aSmrg	export_dynamic=yes
71862378475aSmrg	continue
71872378475aSmrg	;;
718839713583Smrg
71892378475aSmrg      -export-symbols | -export-symbols-regex)
71902378475aSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
71912378475aSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
71922378475aSmrg	fi
7193eca46af7Smrg	if test X-export-symbols = "X$arg"; then
71942378475aSmrg	  prev=expsyms
71952378475aSmrg	else
71962378475aSmrg	  prev=expsyms_regex
71972378475aSmrg	fi
71982378475aSmrg	continue
71992378475aSmrg	;;
720039713583Smrg
72012378475aSmrg      -framework)
72022378475aSmrg	prev=framework
72032378475aSmrg	continue
72042378475aSmrg	;;
720539713583Smrg
72062378475aSmrg      -inst-prefix-dir)
72072378475aSmrg	prev=inst_prefix
72082378475aSmrg	continue
72092378475aSmrg	;;
721039713583Smrg
72112378475aSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
72122378475aSmrg      # so, if we see these flags be careful not to treat them like -L
72132378475aSmrg      -L[A-Z][A-Z]*:*)
72142378475aSmrg	case $with_gcc/$host in
72152378475aSmrg	no/*-*-irix* | /*-*-irix*)
72162378475aSmrg	  func_append compile_command " $arg"
72172378475aSmrg	  func_append finalize_command " $arg"
72182378475aSmrg	  ;;
72192378475aSmrg	esac
72202378475aSmrg	continue
72212378475aSmrg	;;
722239713583Smrg
72232378475aSmrg      -L*)
722414330f12Smrg	func_stripname "-L" '' "$arg"
722514330f12Smrg	if test -z "$func_stripname_result"; then
72262378475aSmrg	  if test "$#" -gt 0; then
7227eca46af7Smrg	    func_fatal_error "require no space between '-L' and '$1'"
72282378475aSmrg	  else
7229eca46af7Smrg	    func_fatal_error "need path for '-L' option"
72302378475aSmrg	  fi
72312378475aSmrg	fi
723214330f12Smrg	func_resolve_sysroot "$func_stripname_result"
723314330f12Smrg	dir=$func_resolve_sysroot_result
72342378475aSmrg	# We need an absolute path.
72352378475aSmrg	case $dir in
72362378475aSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
72372378475aSmrg	*)
72382378475aSmrg	  absdir=`cd "$dir" && pwd`
72392378475aSmrg	  test -z "$absdir" && \
7240eca46af7Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241eca46af7Smrg	  dir=$absdir
72422378475aSmrg	  ;;
72432378475aSmrg	esac
72442378475aSmrg	case "$deplibs " in
724514330f12Smrg	*" -L$dir "* | *" $arg "*)
724614330f12Smrg	  # Will only happen for absolute or sysroot arguments
724714330f12Smrg	  ;;
72482378475aSmrg	*)
724914330f12Smrg	  # Preserve sysroot, but never include relative directories
725014330f12Smrg	  case $dir in
725114330f12Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
725214330f12Smrg	    *) func_append deplibs " -L$dir" ;;
725314330f12Smrg	  esac
725414330f12Smrg	  func_append lib_search_path " $dir"
72552378475aSmrg	  ;;
72562378475aSmrg	esac
72572378475aSmrg	case $host in
72582378475aSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
725914330f12Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
72602378475aSmrg	  case :$dllsearchpath: in
72612378475aSmrg	  *":$dir:"*) ;;
72622378475aSmrg	  ::) dllsearchpath=$dir;;
726314330f12Smrg	  *) func_append dllsearchpath ":$dir";;
72642378475aSmrg	  esac
72652378475aSmrg	  case :$dllsearchpath: in
72662378475aSmrg	  *":$testbindir:"*) ;;
72672378475aSmrg	  ::) dllsearchpath=$testbindir;;
726814330f12Smrg	  *) func_append dllsearchpath ":$testbindir";;
72692378475aSmrg	  esac
72702378475aSmrg	  ;;
72712378475aSmrg	esac
72722378475aSmrg	continue
72732378475aSmrg	;;
727439713583Smrg
72752378475aSmrg      -l*)
7276eca46af7Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
72772378475aSmrg	  case $host in
727814330f12Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
72792378475aSmrg	    # These systems don't actually have a C or math library (as such)
72802378475aSmrg	    continue
72812378475aSmrg	    ;;
72822378475aSmrg	  *-*-os2*)
72832378475aSmrg	    # These systems don't actually have a C library (as such)
7284eca46af7Smrg	    test X-lc = "X$arg" && continue
72852378475aSmrg	    ;;
7286d87a3195Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
72872378475aSmrg	    # Do not include libc due to us having libc/libc_r.
7288eca46af7Smrg	    test X-lc = "X$arg" && continue
72892378475aSmrg	    ;;
72902378475aSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
72912378475aSmrg	    # Rhapsody C and math libraries are in the System framework
729214330f12Smrg	    func_append deplibs " System.ltframework"
72932378475aSmrg	    continue
72942378475aSmrg	    ;;
72952378475aSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
72962378475aSmrg	    # Causes problems with __ctype
7297eca46af7Smrg	    test X-lc = "X$arg" && continue
72982378475aSmrg	    ;;
72992378475aSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
73002378475aSmrg	    # Compiler inserts libc in the correct place for threads to work
7301eca46af7Smrg	    test X-lc = "X$arg" && continue
73022378475aSmrg	    ;;
73032378475aSmrg	  esac
7304eca46af7Smrg	elif test X-lc_r = "X$arg"; then
73052378475aSmrg	 case $host in
7306d87a3195Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
73072378475aSmrg	   # Do not include libc_r directly, use -pthread flag.
73082378475aSmrg	   continue
73092378475aSmrg	   ;;
73102378475aSmrg	 esac
73112378475aSmrg	fi
731214330f12Smrg	func_append deplibs " $arg"
73132378475aSmrg	continue
73142378475aSmrg	;;
731539713583Smrg
7316eca46af7Smrg      -mllvm)
7317eca46af7Smrg	prev=mllvm
7318eca46af7Smrg	continue
7319eca46af7Smrg	;;
7320eca46af7Smrg
73212378475aSmrg      -module)
73222378475aSmrg	module=yes
73232378475aSmrg	continue
73242378475aSmrg	;;
732539713583Smrg
73262378475aSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
73272378475aSmrg      # classes, name mangling, and exception handling.
73282378475aSmrg      # Darwin uses the -arch flag to determine output architecture.
732914330f12Smrg      -model|-arch|-isysroot|--sysroot)
733014330f12Smrg	func_append compiler_flags " $arg"
73312378475aSmrg	func_append compile_command " $arg"
73322378475aSmrg	func_append finalize_command " $arg"
73332378475aSmrg	prev=xcompiler
73342378475aSmrg	continue
73352378475aSmrg	;;
7336d87a3195Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337d87a3195Smrg     -pthread)
7338d87a3195Smrg	case $host in
7339d87a3195Smrg	  *solaris2*) ;;
7340d87a3195Smrg	  *)
7341d87a3195Smrg	    case "$new_inherited_linker_flags " in
7342d87a3195Smrg	        *" $arg "*) ;;
7343d87a3195Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344d87a3195Smrg	    esac
7345d87a3195Smrg	  ;;
7346d87a3195Smrg	esac
7347d87a3195Smrg	continue
7348d87a3195Smrg	;;
7349d87a3195Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350eca46af7Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
735114330f12Smrg	func_append compiler_flags " $arg"
73522378475aSmrg	func_append compile_command " $arg"
73532378475aSmrg	func_append finalize_command " $arg"
73542378475aSmrg	case "$new_inherited_linker_flags " in
73552378475aSmrg	    *" $arg "*) ;;
735614330f12Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
73572378475aSmrg	esac
73582378475aSmrg	continue
73592378475aSmrg	;;
736039713583Smrg
73612378475aSmrg      -multi_module)
7362eca46af7Smrg	single_module=$wl-multi_module
73632378475aSmrg	continue
73642378475aSmrg	;;
736539713583Smrg
73662378475aSmrg      -no-fast-install)
73672378475aSmrg	fast_install=no
73682378475aSmrg	continue
73692378475aSmrg	;;
737039713583Smrg
73712378475aSmrg      -no-install)
73722378475aSmrg	case $host in
73732378475aSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
73742378475aSmrg	  # The PATH hackery in wrapper scripts is required on Windows
73752378475aSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7376eca46af7Smrg	  func_warning "'-no-install' is ignored for $host"
7377eca46af7Smrg	  func_warning "assuming '-no-fast-install' instead"
73782378475aSmrg	  fast_install=no
73792378475aSmrg	  ;;
73802378475aSmrg	*) no_install=yes ;;
73812378475aSmrg	esac
73822378475aSmrg	continue
73832378475aSmrg	;;
738439713583Smrg
73852378475aSmrg      -no-undefined)
73862378475aSmrg	allow_undefined=no
73872378475aSmrg	continue
73882378475aSmrg	;;
738939713583Smrg
73902378475aSmrg      -objectlist)
73912378475aSmrg	prev=objectlist
73922378475aSmrg	continue
73932378475aSmrg	;;
739439713583Smrg
7395eca46af7Smrg      -os2dllname)
7396eca46af7Smrg	prev=os2dllname
7397eca46af7Smrg	continue
7398eca46af7Smrg	;;
7399eca46af7Smrg
74002378475aSmrg      -o) prev=output ;;
740139713583Smrg
74022378475aSmrg      -precious-files-regex)
74032378475aSmrg	prev=precious_regex
74042378475aSmrg	continue
74052378475aSmrg	;;
740639713583Smrg
74072378475aSmrg      -release)
74082378475aSmrg	prev=release
74092378475aSmrg	continue
74102378475aSmrg	;;
741139713583Smrg
74122378475aSmrg      -rpath)
74132378475aSmrg	prev=rpath
74142378475aSmrg	continue
74152378475aSmrg	;;
741639713583Smrg
74172378475aSmrg      -R)
74182378475aSmrg	prev=xrpath
74192378475aSmrg	continue
74202378475aSmrg	;;
742139713583Smrg
74222378475aSmrg      -R*)
74232378475aSmrg	func_stripname '-R' '' "$arg"
74242378475aSmrg	dir=$func_stripname_result
74252378475aSmrg	# We need an absolute path.
74262378475aSmrg	case $dir in
74272378475aSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
742814330f12Smrg	=*)
742914330f12Smrg	  func_stripname '=' '' "$dir"
743014330f12Smrg	  dir=$lt_sysroot$func_stripname_result
743114330f12Smrg	  ;;
74322378475aSmrg	*)
74332378475aSmrg	  func_fatal_error "only absolute run-paths are allowed"
74342378475aSmrg	  ;;
74352378475aSmrg	esac
74362378475aSmrg	case "$xrpath " in
74372378475aSmrg	*" $dir "*) ;;
743814330f12Smrg	*) func_append xrpath " $dir" ;;
74392378475aSmrg	esac
74402378475aSmrg	continue
74412378475aSmrg	;;
744239713583Smrg
74432378475aSmrg      -shared)
74442378475aSmrg	# The effects of -shared are defined in a previous loop.
74452378475aSmrg	continue
74462378475aSmrg	;;
744739713583Smrg
74482378475aSmrg      -shrext)
74492378475aSmrg	prev=shrext
74502378475aSmrg	continue
74512378475aSmrg	;;
745239713583Smrg
74532378475aSmrg      -static | -static-libtool-libs)
74542378475aSmrg	# The effects of -static are defined in a previous loop.
74552378475aSmrg	# We used to do the same as -all-static on platforms that
74562378475aSmrg	# didn't have a PIC flag, but the assumption that the effects
74572378475aSmrg	# would be equivalent was wrong.  It would break on at least
74582378475aSmrg	# Digital Unix and AIX.
74592378475aSmrg	continue
74602378475aSmrg	;;
746139713583Smrg
74622378475aSmrg      -thread-safe)
74632378475aSmrg	thread_safe=yes
74642378475aSmrg	continue
74652378475aSmrg	;;
746639713583Smrg
74672378475aSmrg      -version-info)
74682378475aSmrg	prev=vinfo
74692378475aSmrg	continue
74702378475aSmrg	;;
747139713583Smrg
74722378475aSmrg      -version-number)
74732378475aSmrg	prev=vinfo
74742378475aSmrg	vinfo_number=yes
74752378475aSmrg	continue
74762378475aSmrg	;;
747739713583Smrg
74782378475aSmrg      -weak)
74792378475aSmrg        prev=weak
74802378475aSmrg	continue
74812378475aSmrg	;;
748295b296d0Smrg
74832378475aSmrg      -Wc,*)
74842378475aSmrg	func_stripname '-Wc,' '' "$arg"
74852378475aSmrg	args=$func_stripname_result
74862378475aSmrg	arg=
7487eca46af7Smrg	save_ifs=$IFS; IFS=,
74882378475aSmrg	for flag in $args; do
7489eca46af7Smrg	  IFS=$save_ifs
7490d87a3195Smrg          func_quote_arg pretty "$flag"
7491d87a3195Smrg	  func_append arg " $func_quote_arg_result"
7492d87a3195Smrg	  func_append compiler_flags " $func_quote_arg_result"
74932378475aSmrg	done
7494eca46af7Smrg	IFS=$save_ifs
74952378475aSmrg	func_stripname ' ' '' "$arg"
74962378475aSmrg	arg=$func_stripname_result
74972378475aSmrg	;;
7498e6f085baSmrg
74992378475aSmrg      -Wl,*)
75002378475aSmrg	func_stripname '-Wl,' '' "$arg"
75012378475aSmrg	args=$func_stripname_result
75022378475aSmrg	arg=
7503eca46af7Smrg	save_ifs=$IFS; IFS=,
75042378475aSmrg	for flag in $args; do
7505eca46af7Smrg	  IFS=$save_ifs
7506d87a3195Smrg          func_quote_arg pretty "$flag"
7507d87a3195Smrg	  func_append arg " $wl$func_quote_arg_result"
7508d87a3195Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509d87a3195Smrg	  func_append linker_flags " $func_quote_arg_result"
75102378475aSmrg	done
7511eca46af7Smrg	IFS=$save_ifs
75122378475aSmrg	func_stripname ' ' '' "$arg"
75132378475aSmrg	arg=$func_stripname_result
75142378475aSmrg	;;
7515e6f085baSmrg
7516d87a3195Smrg      -Xassembler)
7517d87a3195Smrg        prev=xassembler
7518d87a3195Smrg        continue
7519d87a3195Smrg        ;;
7520d87a3195Smrg
75212378475aSmrg      -Xcompiler)
75222378475aSmrg	prev=xcompiler
75232378475aSmrg	continue
75242378475aSmrg	;;
7525e6f085baSmrg
75262378475aSmrg      -Xlinker)
75272378475aSmrg	prev=xlinker
75282378475aSmrg	continue
75292378475aSmrg	;;
7530e6f085baSmrg
75312378475aSmrg      -XCClinker)
75322378475aSmrg	prev=xcclinker
75332378475aSmrg	continue
75342378475aSmrg	;;
7535e6f085baSmrg
75362378475aSmrg      # -msg_* for osf cc
75372378475aSmrg      -msg_*)
7538d87a3195Smrg	func_quote_arg pretty "$arg"
7539d87a3195Smrg	arg=$func_quote_arg_result
75402378475aSmrg	;;
7541e6f085baSmrg
754214330f12Smrg      # Flags to be passed through unchanged, with rationale:
754314330f12Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
754414330f12Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
754514330f12Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
754614330f12Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
754714330f12Smrg      # -q*                  compiler args for the IBM compiler
754814330f12Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
754914330f12Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
755014330f12Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551eca46af7Smrg      # -fstack-protector*   stack protector flags for GCC
755214330f12Smrg      # @file                GCC response files
755314330f12Smrg      # -tp=*                Portland pgcc target processor selection
755414330f12Smrg      # --sysroot=*          for sysroot support
7555eca46af7Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7556d87a3195Smrg      # -specs=*             GCC specs files
7557eca46af7Smrg      # -stdlib=*            select c++ std lib with clang
7558d87a3195Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
7559d87a3195Smrg      # -fuse-ld=*           Linker select flags for GCC
7560d87a3195Smrg      # -Wa,*                Pass flags directly to the assembler
75612378475aSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
756214330f12Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7563d87a3195Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564d87a3195Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565d87a3195Smrg        func_quote_arg pretty "$arg"
7566d87a3195Smrg	arg=$func_quote_arg_result
75672378475aSmrg        func_append compile_command " $arg"
75682378475aSmrg        func_append finalize_command " $arg"
756914330f12Smrg        func_append compiler_flags " $arg"
75702378475aSmrg        continue
75712378475aSmrg        ;;
7572e6f085baSmrg
7573eca46af7Smrg      -Z*)
7574eca46af7Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575eca46af7Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576eca46af7Smrg	  compiler_flags="$compiler_flags $arg"
7577eca46af7Smrg	  func_append compile_command " $arg"
7578eca46af7Smrg	  func_append finalize_command " $arg"
7579eca46af7Smrg	  case $arg in
7580eca46af7Smrg	  -Zlinker | -Zstack)
7581eca46af7Smrg	    prev=xcompiler
7582eca46af7Smrg	    ;;
7583eca46af7Smrg	  esac
7584eca46af7Smrg	  continue
7585eca46af7Smrg        else
7586eca46af7Smrg	  # Otherwise treat like 'Some other compiler flag' below
7587d87a3195Smrg	  func_quote_arg pretty "$arg"
7588d87a3195Smrg	  arg=$func_quote_arg_result
7589eca46af7Smrg        fi
7590eca46af7Smrg	;;
7591eca46af7Smrg
75922378475aSmrg      # Some other compiler flag.
75932378475aSmrg      -* | +*)
7594d87a3195Smrg        func_quote_arg pretty "$arg"
7595d87a3195Smrg	arg=$func_quote_arg_result
75962378475aSmrg	;;
7597e6f085baSmrg
75982378475aSmrg      *.$objext)
75992378475aSmrg	# A standard object.
760014330f12Smrg	func_append objs " $arg"
76012378475aSmrg	;;
7602e6f085baSmrg
76032378475aSmrg      *.lo)
76042378475aSmrg	# A libtool-controlled object.
7605e6f085baSmrg
76062378475aSmrg	# Check to see that this really is a libtool object.
76072378475aSmrg	if func_lalib_unsafe_p "$arg"; then
76082378475aSmrg	  pic_object=
76092378475aSmrg	  non_pic_object=
7610e6f085baSmrg
76112378475aSmrg	  # Read the .lo file
76122378475aSmrg	  func_source "$arg"
7613e6f085baSmrg
76142378475aSmrg	  if test -z "$pic_object" ||
76152378475aSmrg	     test -z "$non_pic_object" ||
7616eca46af7Smrg	     test none = "$pic_object" &&
7617eca46af7Smrg	     test none = "$non_pic_object"; then
7618eca46af7Smrg	    func_fatal_error "cannot find name of object for '$arg'"
76192378475aSmrg	  fi
7620e6f085baSmrg
76212378475aSmrg	  # Extract subdirectory from the argument.
76222378475aSmrg	  func_dirname "$arg" "/" ""
7623eca46af7Smrg	  xdir=$func_dirname_result
7624e6f085baSmrg
7625eca46af7Smrg	  test none = "$pic_object" || {
76262378475aSmrg	    # Prepend the subdirectory the object is found in.
7627eca46af7Smrg	    pic_object=$xdir$pic_object
7628e6f085baSmrg
7629eca46af7Smrg	    if test dlfiles = "$prev"; then
7630eca46af7Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
763114330f12Smrg		func_append dlfiles " $pic_object"
76322378475aSmrg		prev=
76332378475aSmrg		continue
76342378475aSmrg	      else
76352378475aSmrg		# If libtool objects are unsupported, then we need to preload.
76362378475aSmrg		prev=dlprefiles
76372378475aSmrg	      fi
76382378475aSmrg	    fi
7639e6f085baSmrg
76402378475aSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7641eca46af7Smrg	    if test dlprefiles = "$prev"; then
76422378475aSmrg	      # Preload the old-style object.
764314330f12Smrg	      func_append dlprefiles " $pic_object"
76442378475aSmrg	      prev=
76452378475aSmrg	    fi
764695b296d0Smrg
76472378475aSmrg	    # A PIC object.
76482378475aSmrg	    func_append libobjs " $pic_object"
7649eca46af7Smrg	    arg=$pic_object
7650eca46af7Smrg	  }
765195b296d0Smrg
76522378475aSmrg	  # Non-PIC object.
7653eca46af7Smrg	  if test none != "$non_pic_object"; then
76542378475aSmrg	    # Prepend the subdirectory the object is found in.
7655eca46af7Smrg	    non_pic_object=$xdir$non_pic_object
765695b296d0Smrg
76572378475aSmrg	    # A standard non-PIC object
76582378475aSmrg	    func_append non_pic_objects " $non_pic_object"
7659eca46af7Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660eca46af7Smrg	      arg=$non_pic_object
76612378475aSmrg	    fi
76622378475aSmrg	  else
76632378475aSmrg	    # If the PIC object exists, use it instead.
76642378475aSmrg	    # $xdir was prepended to $pic_object above.
7665eca46af7Smrg	    non_pic_object=$pic_object
76662378475aSmrg	    func_append non_pic_objects " $non_pic_object"
76672378475aSmrg	  fi
76682378475aSmrg	else
76692378475aSmrg	  # Only an error if not doing a dry-run.
76702378475aSmrg	  if $opt_dry_run; then
76712378475aSmrg	    # Extract subdirectory from the argument.
76722378475aSmrg	    func_dirname "$arg" "/" ""
7673eca46af7Smrg	    xdir=$func_dirname_result
76742378475aSmrg
76752378475aSmrg	    func_lo2o "$arg"
76762378475aSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
76772378475aSmrg	    non_pic_object=$xdir$func_lo2o_result
76782378475aSmrg	    func_append libobjs " $pic_object"
76792378475aSmrg	    func_append non_pic_objects " $non_pic_object"
76802378475aSmrg	  else
7681eca46af7Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
76822378475aSmrg	  fi
76832378475aSmrg	fi
76842378475aSmrg	;;
768595b296d0Smrg
76862378475aSmrg      *.$libext)
76872378475aSmrg	# An archive.
768814330f12Smrg	func_append deplibs " $arg"
768914330f12Smrg	func_append old_deplibs " $arg"
76902378475aSmrg	continue
76912378475aSmrg	;;
76922378475aSmrg
76932378475aSmrg      *.la)
76942378475aSmrg	# A libtool-controlled library.
76952378475aSmrg
769614330f12Smrg	func_resolve_sysroot "$arg"
7697eca46af7Smrg	if test dlfiles = "$prev"; then
76982378475aSmrg	  # This library was specified with -dlopen.
769914330f12Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
77002378475aSmrg	  prev=
7701eca46af7Smrg	elif test dlprefiles = "$prev"; then
77022378475aSmrg	  # The library was specified with -dlpreopen.
770314330f12Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
77042378475aSmrg	  prev=
77052378475aSmrg	else
770614330f12Smrg	  func_append deplibs " $func_resolve_sysroot_result"
77072378475aSmrg	fi
77082378475aSmrg	continue
77092378475aSmrg	;;
77102378475aSmrg
77112378475aSmrg      # Some other compiler argument.
77122378475aSmrg      *)
77132378475aSmrg	# Unknown arguments in both finalize_command and compile_command need
77142378475aSmrg	# to be aesthetically quoted because they are evaled later.
7715d87a3195Smrg	func_quote_arg pretty "$arg"
7716d87a3195Smrg	arg=$func_quote_arg_result
77172378475aSmrg	;;
77182378475aSmrg      esac # arg
77192378475aSmrg
77202378475aSmrg      # Now actually substitute the argument into the commands.
77212378475aSmrg      if test -n "$arg"; then
77222378475aSmrg	func_append compile_command " $arg"
77232378475aSmrg	func_append finalize_command " $arg"
77242378475aSmrg      fi
77252378475aSmrg    done # argument parsing loop
77262378475aSmrg
77272378475aSmrg    test -n "$prev" && \
7728eca46af7Smrg      func_fatal_help "the '$prevarg' option requires an argument"
77292378475aSmrg
7730eca46af7Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
77312378475aSmrg      eval arg=\"$export_dynamic_flag_spec\"
77322378475aSmrg      func_append compile_command " $arg"
77332378475aSmrg      func_append finalize_command " $arg"
77342378475aSmrg    fi
77352378475aSmrg
77362378475aSmrg    oldlibs=
77372378475aSmrg    # calculate the name of the file, without its directory
77382378475aSmrg    func_basename "$output"
7739eca46af7Smrg    outputname=$func_basename_result
7740eca46af7Smrg    libobjs_save=$libobjs
77412378475aSmrg
77422378475aSmrg    if test -n "$shlibpath_var"; then
77432378475aSmrg      # get the directories listed in $shlibpath_var
7744eca46af7Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
77452378475aSmrg    else
77462378475aSmrg      shlib_search_path=
77472378475aSmrg    fi
77482378475aSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
77492378475aSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
77502378475aSmrg
775189b0dc75Smrg    # Definition is injected by LT_CONFIG during libtool generation.
775289b0dc75Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
775389b0dc75Smrg
77542378475aSmrg    func_dirname "$output" "/" ""
7755eca46af7Smrg    output_objdir=$func_dirname_result$objdir
775614330f12Smrg    func_to_tool_file "$output_objdir/"
775714330f12Smrg    tool_output_objdir=$func_to_tool_file_result
77582378475aSmrg    # Create the object directory.
77592378475aSmrg    func_mkdir_p "$output_objdir"
77602378475aSmrg
77612378475aSmrg    # Determine the type of output
77622378475aSmrg    case $output in
77632378475aSmrg    "")
77642378475aSmrg      func_fatal_help "you must specify an output file"
77652378475aSmrg      ;;
77662378475aSmrg    *.$libext) linkmode=oldlib ;;
77672378475aSmrg    *.lo | *.$objext) linkmode=obj ;;
77682378475aSmrg    *.la) linkmode=lib ;;
77692378475aSmrg    *) linkmode=prog ;; # Anything else should be a program.
77702378475aSmrg    esac
77712378475aSmrg
77722378475aSmrg    specialdeplibs=
77732378475aSmrg
77742378475aSmrg    libs=
77752378475aSmrg    # Find all interdependent deplibs by searching for libraries
77762378475aSmrg    # that are linked more than once (e.g. -la -lb -la)
77772378475aSmrg    for deplib in $deplibs; do
7778eca46af7Smrg      if $opt_preserve_dup_deps; then
77792378475aSmrg	case "$libs " in
778014330f12Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
77812378475aSmrg	esac
77822378475aSmrg      fi
778314330f12Smrg      func_append libs " $deplib"
77842378475aSmrg    done
77852378475aSmrg
7786eca46af7Smrg    if test lib = "$linkmode"; then
77872378475aSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
77882378475aSmrg
77892378475aSmrg      # Compute libraries that are listed more than once in $predeps
77902378475aSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
77912378475aSmrg      # not to be eliminated).
77922378475aSmrg      pre_post_deps=
77932378475aSmrg      if $opt_duplicate_compiler_generated_deps; then
77942378475aSmrg	for pre_post_dep in $predeps $postdeps; do
77952378475aSmrg	  case "$pre_post_deps " in
779614330f12Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
77972378475aSmrg	  esac
779814330f12Smrg	  func_append pre_post_deps " $pre_post_dep"
77992378475aSmrg	done
78002378475aSmrg      fi
78012378475aSmrg      pre_post_deps=
78022378475aSmrg    fi
78032378475aSmrg
78042378475aSmrg    deplibs=
78052378475aSmrg    newdependency_libs=
78062378475aSmrg    newlib_search_path=
78072378475aSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
78082378475aSmrg    notinst_deplibs= # not-installed libtool libraries
78092378475aSmrg    notinst_path= # paths that contain not-installed libtool libraries
78102378475aSmrg
78112378475aSmrg    case $linkmode in
78122378475aSmrg    lib)
78132378475aSmrg	passes="conv dlpreopen link"
78142378475aSmrg	for file in $dlfiles $dlprefiles; do
78152378475aSmrg	  case $file in
78162378475aSmrg	  *.la) ;;
78172378475aSmrg	  *)
7818eca46af7Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
78192378475aSmrg	    ;;
78202378475aSmrg	  esac
78212378475aSmrg	done
78222378475aSmrg	;;
78232378475aSmrg    prog)
78242378475aSmrg	compile_deplibs=
78252378475aSmrg	finalize_deplibs=
7826eca46af7Smrg	alldeplibs=false
78272378475aSmrg	newdlfiles=
78282378475aSmrg	newdlprefiles=
78292378475aSmrg	passes="conv scan dlopen dlpreopen link"
78302378475aSmrg	;;
78312378475aSmrg    *)  passes="conv"
78322378475aSmrg	;;
78332378475aSmrg    esac
78342378475aSmrg
78352378475aSmrg    for pass in $passes; do
78362378475aSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
78372378475aSmrg      # so that -L comes before libs that need it for instance...
7838eca46af7Smrg      if test lib,link = "$linkmode,$pass"; then
78392378475aSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
78402378475aSmrg	##        order, and fix it there properly
78412378475aSmrg        tmp_deplibs=
78422378475aSmrg	for deplib in $deplibs; do
78432378475aSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
78442378475aSmrg	done
7845eca46af7Smrg	deplibs=$tmp_deplibs
78462378475aSmrg      fi
78472378475aSmrg
7848eca46af7Smrg      if test lib,link = "$linkmode,$pass" ||
7849eca46af7Smrg	 test prog,scan = "$linkmode,$pass"; then
7850eca46af7Smrg	libs=$deplibs
78512378475aSmrg	deplibs=
78522378475aSmrg      fi
7853eca46af7Smrg      if test prog = "$linkmode"; then
78542378475aSmrg	case $pass in
7855eca46af7Smrg	dlopen) libs=$dlfiles ;;
7856eca46af7Smrg	dlpreopen) libs=$dlprefiles ;;
78572378475aSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
78582378475aSmrg	esac
78592378475aSmrg      fi
7860eca46af7Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
78612378475aSmrg	# Collect and forward deplibs of preopened libtool libs
78622378475aSmrg	for lib in $dlprefiles; do
78632378475aSmrg	  # Ignore non-libtool-libs
78642378475aSmrg	  dependency_libs=
786514330f12Smrg	  func_resolve_sysroot "$lib"
78662378475aSmrg	  case $lib in
786714330f12Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
78682378475aSmrg	  esac
78692378475aSmrg
78702378475aSmrg	  # Collect preopened libtool deplibs, except any this library
78712378475aSmrg	  # has declared as weak libs
78722378475aSmrg	  for deplib in $dependency_libs; do
787314330f12Smrg	    func_basename "$deplib"
787414330f12Smrg            deplib_base=$func_basename_result
78752378475aSmrg	    case " $weak_libs " in
78762378475aSmrg	    *" $deplib_base "*) ;;
787714330f12Smrg	    *) func_append deplibs " $deplib" ;;
78782378475aSmrg	    esac
78792378475aSmrg	  done
78802378475aSmrg	done
7881eca46af7Smrg	libs=$dlprefiles
78822378475aSmrg      fi
7883eca46af7Smrg      if test dlopen = "$pass"; then
78842378475aSmrg	# Collect dlpreopened libraries
7885eca46af7Smrg	save_deplibs=$deplibs
78862378475aSmrg	deplibs=
78872378475aSmrg      fi
78882378475aSmrg
78892378475aSmrg      for deplib in $libs; do
78902378475aSmrg	lib=
7891eca46af7Smrg	found=false
78922378475aSmrg	case $deplib in
7893eca46af7Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894eca46af7Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895eca46af7Smrg	  if test prog,link = "$linkmode,$pass"; then
78962378475aSmrg	    compile_deplibs="$deplib $compile_deplibs"
78972378475aSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
78982378475aSmrg	  else
789914330f12Smrg	    func_append compiler_flags " $deplib"
7900eca46af7Smrg	    if test lib = "$linkmode"; then
79012378475aSmrg		case "$new_inherited_linker_flags " in
79022378475aSmrg		    *" $deplib "*) ;;
790314330f12Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79042378475aSmrg		esac
79052378475aSmrg	    fi
79062378475aSmrg	  fi
79072378475aSmrg	  continue
79082378475aSmrg	  ;;
79092378475aSmrg	-l*)
7910eca46af7Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911eca46af7Smrg	    func_warning "'-l' is ignored for archives/objects"
79122378475aSmrg	    continue
79132378475aSmrg	  fi
79142378475aSmrg	  func_stripname '-l' '' "$deplib"
79152378475aSmrg	  name=$func_stripname_result
7916eca46af7Smrg	  if test lib = "$linkmode"; then
79172378475aSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
79182378475aSmrg	  else
79192378475aSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
79202378475aSmrg	  fi
79212378475aSmrg	  for searchdir in $searchdirs; do
79222378475aSmrg	    for search_ext in .la $std_shrext .so .a; do
79232378475aSmrg	      # Search the libtool library
7924eca46af7Smrg	      lib=$searchdir/lib$name$search_ext
79252378475aSmrg	      if test -f "$lib"; then
7926eca46af7Smrg		if test .la = "$search_ext"; then
7927eca46af7Smrg		  found=:
79282378475aSmrg		else
7929eca46af7Smrg		  found=false
79302378475aSmrg		fi
79312378475aSmrg		break 2
79322378475aSmrg	      fi
79332378475aSmrg	    done
79342378475aSmrg	  done
7935eca46af7Smrg	  if $found; then
7936eca46af7Smrg	    # deplib is a libtool library
79372378475aSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
79382378475aSmrg	    # We need to do some special things here, and not later.
7939eca46af7Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
79402378475aSmrg	      case " $predeps $postdeps " in
79412378475aSmrg	      *" $deplib "*)
79422378475aSmrg		if func_lalib_p "$lib"; then
79432378475aSmrg		  library_names=
79442378475aSmrg		  old_library=
79452378475aSmrg		  func_source "$lib"
79462378475aSmrg		  for l in $old_library $library_names; do
7947eca46af7Smrg		    ll=$l
79482378475aSmrg		  done
7949eca46af7Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950eca46af7Smrg		    found=false
79512378475aSmrg		    func_dirname "$lib" "" "."
7952eca46af7Smrg		    ladir=$func_dirname_result
79532378475aSmrg		    lib=$ladir/$old_library
7954eca46af7Smrg		    if test prog,link = "$linkmode,$pass"; then
79552378475aSmrg		      compile_deplibs="$deplib $compile_deplibs"
79562378475aSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
79572378475aSmrg		    else
79582378475aSmrg		      deplibs="$deplib $deplibs"
7959eca46af7Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79602378475aSmrg		    fi
79612378475aSmrg		    continue
79622378475aSmrg		  fi
79632378475aSmrg		fi
79642378475aSmrg		;;
79652378475aSmrg	      *) ;;
79662378475aSmrg	      esac
79672378475aSmrg	    fi
7968eca46af7Smrg	  else
7969eca46af7Smrg	    # deplib doesn't seem to be a libtool library
7970eca46af7Smrg	    if test prog,link = "$linkmode,$pass"; then
7971eca46af7Smrg	      compile_deplibs="$deplib $compile_deplibs"
7972eca46af7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973eca46af7Smrg	    else
7974eca46af7Smrg	      deplibs="$deplib $deplibs"
7975eca46af7Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976eca46af7Smrg	    fi
7977eca46af7Smrg	    continue
79782378475aSmrg	  fi
79792378475aSmrg	  ;; # -l
79802378475aSmrg	*.ltframework)
7981eca46af7Smrg	  if test prog,link = "$linkmode,$pass"; then
79822378475aSmrg	    compile_deplibs="$deplib $compile_deplibs"
79832378475aSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
79842378475aSmrg	  else
79852378475aSmrg	    deplibs="$deplib $deplibs"
7986eca46af7Smrg	    if test lib = "$linkmode"; then
79872378475aSmrg		case "$new_inherited_linker_flags " in
79882378475aSmrg		    *" $deplib "*) ;;
798914330f12Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79902378475aSmrg		esac
79912378475aSmrg	    fi
79922378475aSmrg	  fi
79932378475aSmrg	  continue
79942378475aSmrg	  ;;
79952378475aSmrg	-L*)
79962378475aSmrg	  case $linkmode in
79972378475aSmrg	  lib)
79982378475aSmrg	    deplibs="$deplib $deplibs"
7999eca46af7Smrg	    test conv = "$pass" && continue
80002378475aSmrg	    newdependency_libs="$deplib $newdependency_libs"
80012378475aSmrg	    func_stripname '-L' '' "$deplib"
800214330f12Smrg	    func_resolve_sysroot "$func_stripname_result"
800314330f12Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80042378475aSmrg	    ;;
80052378475aSmrg	  prog)
8006eca46af7Smrg	    if test conv = "$pass"; then
80072378475aSmrg	      deplibs="$deplib $deplibs"
80082378475aSmrg	      continue
80092378475aSmrg	    fi
8010eca46af7Smrg	    if test scan = "$pass"; then
80112378475aSmrg	      deplibs="$deplib $deplibs"
80122378475aSmrg	    else
80132378475aSmrg	      compile_deplibs="$deplib $compile_deplibs"
80142378475aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
80152378475aSmrg	    fi
80162378475aSmrg	    func_stripname '-L' '' "$deplib"
801714330f12Smrg	    func_resolve_sysroot "$func_stripname_result"
801814330f12Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80192378475aSmrg	    ;;
80202378475aSmrg	  *)
8021eca46af7Smrg	    func_warning "'-L' is ignored for archives/objects"
80222378475aSmrg	    ;;
80232378475aSmrg	  esac # linkmode
80242378475aSmrg	  continue
80252378475aSmrg	  ;; # -L
80262378475aSmrg	-R*)
8027eca46af7Smrg	  if test link = "$pass"; then
80282378475aSmrg	    func_stripname '-R' '' "$deplib"
802914330f12Smrg	    func_resolve_sysroot "$func_stripname_result"
803014330f12Smrg	    dir=$func_resolve_sysroot_result
80312378475aSmrg	    # Make sure the xrpath contains only unique directories.
80322378475aSmrg	    case "$xrpath " in
80332378475aSmrg	    *" $dir "*) ;;
803414330f12Smrg	    *) func_append xrpath " $dir" ;;
80352378475aSmrg	    esac
80362378475aSmrg	  fi
80372378475aSmrg	  deplibs="$deplib $deplibs"
80382378475aSmrg	  continue
80392378475aSmrg	  ;;
804014330f12Smrg	*.la)
804114330f12Smrg	  func_resolve_sysroot "$deplib"
804214330f12Smrg	  lib=$func_resolve_sysroot_result
804314330f12Smrg	  ;;
80442378475aSmrg	*.$libext)
8045eca46af7Smrg	  if test conv = "$pass"; then
80462378475aSmrg	    deplibs="$deplib $deplibs"
80472378475aSmrg	    continue
80482378475aSmrg	  fi
80492378475aSmrg	  case $linkmode in
80502378475aSmrg	  lib)
80512378475aSmrg	    # Linking convenience modules into shared libraries is allowed,
80522378475aSmrg	    # but linking other static libraries is non-portable.
80532378475aSmrg	    case " $dlpreconveniencelibs " in
80542378475aSmrg	    *" $deplib "*) ;;
80552378475aSmrg	    *)
8056eca46af7Smrg	      valid_a_lib=false
80572378475aSmrg	      case $deplibs_check_method in
80582378475aSmrg		match_pattern*)
80592378475aSmrg		  set dummy $deplibs_check_method; shift
80602378475aSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
806114330f12Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
80622378475aSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063eca46af7Smrg		    valid_a_lib=:
80642378475aSmrg		  fi
80652378475aSmrg		;;
80662378475aSmrg		pass_all)
8067eca46af7Smrg		  valid_a_lib=:
80682378475aSmrg		;;
80692378475aSmrg	      esac
8070eca46af7Smrg	      if $valid_a_lib; then
8071eca46af7Smrg		echo
8072eca46af7Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073eca46af7Smrg		$ECHO "*** static library $deplib is not portable!"
8074eca46af7Smrg		deplibs="$deplib $deplibs"
8075eca46af7Smrg	      else
807614330f12Smrg		echo
80772378475aSmrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
807814330f12Smrg		echo "*** I have the capability to make that library automatically link in when"
807914330f12Smrg		echo "*** you link to this library.  But I can only do this if you have a"
808014330f12Smrg		echo "*** shared version of the library, which you do not appear to have"
808114330f12Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
808214330f12Smrg		echo "*** that it is just a static archive that I should not use here."
80832378475aSmrg	      fi
80842378475aSmrg	      ;;
80852378475aSmrg	    esac
80862378475aSmrg	    continue
80872378475aSmrg	    ;;
80882378475aSmrg	  prog)
8089eca46af7Smrg	    if test link != "$pass"; then
80902378475aSmrg	      deplibs="$deplib $deplibs"
80912378475aSmrg	    else
80922378475aSmrg	      compile_deplibs="$deplib $compile_deplibs"
80932378475aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
80942378475aSmrg	    fi
80952378475aSmrg	    continue
80962378475aSmrg	    ;;
80972378475aSmrg	  esac # linkmode
80982378475aSmrg	  ;; # *.$libext
80992378475aSmrg	*.lo | *.$objext)
8100eca46af7Smrg	  if test conv = "$pass"; then
81012378475aSmrg	    deplibs="$deplib $deplibs"
8102eca46af7Smrg	  elif test prog = "$linkmode"; then
8103eca46af7Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
81042378475aSmrg	      # If there is no dlopen support or we're linking statically,
81052378475aSmrg	      # we need to preload.
810614330f12Smrg	      func_append newdlprefiles " $deplib"
81072378475aSmrg	      compile_deplibs="$deplib $compile_deplibs"
81082378475aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
81092378475aSmrg	    else
811014330f12Smrg	      func_append newdlfiles " $deplib"
81112378475aSmrg	    fi
81122378475aSmrg	  fi
81132378475aSmrg	  continue
81142378475aSmrg	  ;;
81152378475aSmrg	%DEPLIBS%)
8116eca46af7Smrg	  alldeplibs=:
81172378475aSmrg	  continue
81182378475aSmrg	  ;;
81192378475aSmrg	esac # case $deplib
81202378475aSmrg
8121eca46af7Smrg	$found || test -f "$lib" \
8122eca46af7Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
81232378475aSmrg
81242378475aSmrg	# Check to see that this really is a libtool archive.
81252378475aSmrg	func_lalib_unsafe_p "$lib" \
8126eca46af7Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
81272378475aSmrg
81282378475aSmrg	func_dirname "$lib" "" "."
8129eca46af7Smrg	ladir=$func_dirname_result
81302378475aSmrg
81312378475aSmrg	dlname=
81322378475aSmrg	dlopen=
81332378475aSmrg	dlpreopen=
81342378475aSmrg	libdir=
81352378475aSmrg	library_names=
81362378475aSmrg	old_library=
81372378475aSmrg	inherited_linker_flags=
81382378475aSmrg	# If the library was installed with an old release of libtool,
81392378475aSmrg	# it will not redefine variables installed, or shouldnotlink
81402378475aSmrg	installed=yes
81412378475aSmrg	shouldnotlink=no
81422378475aSmrg	avoidtemprpath=
81432378475aSmrg
81442378475aSmrg
81452378475aSmrg	# Read the .la file
81462378475aSmrg	func_source "$lib"
81472378475aSmrg
81482378475aSmrg	# Convert "-framework foo" to "foo.ltframework"
81492378475aSmrg	if test -n "$inherited_linker_flags"; then
815014330f12Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
81512378475aSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
81522378475aSmrg	    case " $new_inherited_linker_flags " in
81532378475aSmrg	      *" $tmp_inherited_linker_flag "*) ;;
815414330f12Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
81552378475aSmrg	    esac
81562378475aSmrg	  done
81572378475aSmrg	fi
815814330f12Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159eca46af7Smrg	if test lib,link = "$linkmode,$pass" ||
8160eca46af7Smrg	   test prog,scan = "$linkmode,$pass" ||
8161eca46af7Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
816214330f12Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
816314330f12Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
81642378475aSmrg	fi
81652378475aSmrg
8166eca46af7Smrg	if test conv = "$pass"; then
81672378475aSmrg	  # Only check for convenience libraries
81682378475aSmrg	  deplibs="$lib $deplibs"
81692378475aSmrg	  if test -z "$libdir"; then
81702378475aSmrg	    if test -z "$old_library"; then
8171eca46af7Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
81722378475aSmrg	    fi
81732378475aSmrg	    # It is a libtool convenience library, so add in its objects.
817414330f12Smrg	    func_append convenience " $ladir/$objdir/$old_library"
817514330f12Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176eca46af7Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177eca46af7Smrg	    func_fatal_error "'$lib' is not a convenience library"
81782378475aSmrg	  fi
81792378475aSmrg	  tmp_libs=
81802378475aSmrg	  for deplib in $dependency_libs; do
81812378475aSmrg	    deplibs="$deplib $deplibs"
8182eca46af7Smrg	    if $opt_preserve_dup_deps; then
81832378475aSmrg	      case "$tmp_libs " in
818414330f12Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
81852378475aSmrg	      esac
81862378475aSmrg	    fi
818714330f12Smrg	    func_append tmp_libs " $deplib"
81882378475aSmrg	  done
81892378475aSmrg	  continue
81902378475aSmrg	fi # $pass = conv
81912378475aSmrg
81922378475aSmrg
81932378475aSmrg	# Get the name of the library we link against.
81942378475aSmrg	linklib=
819514330f12Smrg	if test -n "$old_library" &&
8196eca46af7Smrg	   { test yes = "$prefer_static_libs" ||
8197eca46af7Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
819814330f12Smrg	  linklib=$old_library
819914330f12Smrg	else
820014330f12Smrg	  for l in $old_library $library_names; do
8201eca46af7Smrg	    linklib=$l
820214330f12Smrg	  done
820314330f12Smrg	fi
82042378475aSmrg	if test -z "$linklib"; then
8205eca46af7Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
82062378475aSmrg	fi
82072378475aSmrg
82082378475aSmrg	# This library was specified with -dlopen.
8209eca46af7Smrg	if test dlopen = "$pass"; then
8210eca46af7Smrg	  test -z "$libdir" \
8211eca46af7Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
82122378475aSmrg	  if test -z "$dlname" ||
8213eca46af7Smrg	     test yes != "$dlopen_support" ||
8214eca46af7Smrg	     test no = "$build_libtool_libs"
8215eca46af7Smrg	  then
82162378475aSmrg	    # If there is no dlname, no dlopen support or we're linking
82172378475aSmrg	    # statically, we need to preload.  We also need to preload any
82182378475aSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
82192378475aSmrg	    # bomb out in the load deplibs phase.
822014330f12Smrg	    func_append dlprefiles " $lib $dependency_libs"
82212378475aSmrg	  else
822214330f12Smrg	    func_append newdlfiles " $lib"
82232378475aSmrg	  fi
82242378475aSmrg	  continue
82252378475aSmrg	fi # $pass = dlopen
82262378475aSmrg
82272378475aSmrg	# We need an absolute path.
82282378475aSmrg	case $ladir in
8229eca46af7Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
82302378475aSmrg	*)
82312378475aSmrg	  abs_ladir=`cd "$ladir" && pwd`
82322378475aSmrg	  if test -z "$abs_ladir"; then
8233eca46af7Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
82342378475aSmrg	    func_warning "passing it literally to the linker, although it might fail"
8235eca46af7Smrg	    abs_ladir=$ladir
82362378475aSmrg	  fi
82372378475aSmrg	  ;;
82382378475aSmrg	esac
82392378475aSmrg	func_basename "$lib"
8240eca46af7Smrg	laname=$func_basename_result
82412378475aSmrg
82422378475aSmrg	# Find the relevant object directory and library name.
8243eca46af7Smrg	if test yes = "$installed"; then
824414330f12Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245eca46af7Smrg	    func_warning "library '$lib' was moved."
8246eca46af7Smrg	    dir=$ladir
8247eca46af7Smrg	    absdir=$abs_ladir
8248eca46af7Smrg	    libdir=$abs_ladir
82492378475aSmrg	  else
8250eca46af7Smrg	    dir=$lt_sysroot$libdir
8251eca46af7Smrg	    absdir=$lt_sysroot$libdir
82522378475aSmrg	  fi
8253eca46af7Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
82542378475aSmrg	else
82552378475aSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256eca46af7Smrg	    dir=$ladir
8257eca46af7Smrg	    absdir=$abs_ladir
82582378475aSmrg	    # Remove this search path later
825914330f12Smrg	    func_append notinst_path " $abs_ladir"
82602378475aSmrg	  else
8261eca46af7Smrg	    dir=$ladir/$objdir
8262eca46af7Smrg	    absdir=$abs_ladir/$objdir
82632378475aSmrg	    # Remove this search path later
826414330f12Smrg	    func_append notinst_path " $abs_ladir"
82652378475aSmrg	  fi
82662378475aSmrg	fi # $installed = yes
82672378475aSmrg	func_stripname 'lib' '.la' "$laname"
82682378475aSmrg	name=$func_stripname_result
82692378475aSmrg
82702378475aSmrg	# This library was specified with -dlpreopen.
8271eca46af7Smrg	if test dlpreopen = "$pass"; then
8272eca46af7Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273eca46af7Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
82742378475aSmrg	  fi
8275eca46af7Smrg	  case $host in
827614330f12Smrg	    # special handling for platforms with PE-DLLs.
827714330f12Smrg	    *cygwin* | *mingw* | *cegcc* )
827814330f12Smrg	      # Linker will automatically link against shared library if both
827914330f12Smrg	      # static and shared are present.  Therefore, ensure we extract
828014330f12Smrg	      # symbols from the import library if a shared library is present
828114330f12Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
828214330f12Smrg	      # this by putting the import library name into $newdlprefiles.
828314330f12Smrg	      # We recover the dlopen module name by 'saving' the la file
828414330f12Smrg	      # name in a special purpose variable, and (later) extracting the
828514330f12Smrg	      # dlname from the la file.
828614330f12Smrg	      if test -n "$dlname"; then
828714330f12Smrg	        func_tr_sh "$dir/$linklib"
828814330f12Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
828914330f12Smrg	        func_append newdlprefiles " $dir/$linklib"
829014330f12Smrg	      else
829114330f12Smrg	        func_append newdlprefiles " $dir/$old_library"
829214330f12Smrg	        # Keep a list of preopened convenience libraries to check
829314330f12Smrg	        # that they are being used correctly in the link pass.
829414330f12Smrg	        test -z "$libdir" && \
829514330f12Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
829614330f12Smrg	      fi
829714330f12Smrg	    ;;
829814330f12Smrg	    * )
829914330f12Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
830014330f12Smrg	      # are required to link).
830114330f12Smrg	      if test -n "$old_library"; then
830214330f12Smrg	        func_append newdlprefiles " $dir/$old_library"
830314330f12Smrg	        # Keep a list of preopened convenience libraries to check
830414330f12Smrg	        # that they are being used correctly in the link pass.
830514330f12Smrg	        test -z "$libdir" && \
830614330f12Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
830714330f12Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
830814330f12Smrg	      elif test -n "$dlname"; then
830914330f12Smrg	        func_append newdlprefiles " $dir/$dlname"
831014330f12Smrg	      else
831114330f12Smrg	        func_append newdlprefiles " $dir/$linklib"
831214330f12Smrg	      fi
831314330f12Smrg	    ;;
831414330f12Smrg	  esac
83152378475aSmrg	fi # $pass = dlpreopen
83162378475aSmrg
83172378475aSmrg	if test -z "$libdir"; then
83182378475aSmrg	  # Link the convenience library
8319eca46af7Smrg	  if test lib = "$linkmode"; then
83202378475aSmrg	    deplibs="$dir/$old_library $deplibs"
8321eca46af7Smrg	  elif test prog,link = "$linkmode,$pass"; then
83222378475aSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
83232378475aSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
83242378475aSmrg	  else
83252378475aSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
83262378475aSmrg	  fi
83272378475aSmrg	  continue
83282378475aSmrg	fi
83292378475aSmrg
83302378475aSmrg
8331eca46af7Smrg	if test prog = "$linkmode" && test link != "$pass"; then
833214330f12Smrg	  func_append newlib_search_path " $ladir"
83332378475aSmrg	  deplibs="$lib $deplibs"
83342378475aSmrg
8335eca46af7Smrg	  linkalldeplibs=false
8336eca46af7Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337eca46af7Smrg	     test no = "$build_libtool_libs"; then
8338eca46af7Smrg	    linkalldeplibs=:
83392378475aSmrg	  fi
83402378475aSmrg
83412378475aSmrg	  tmp_libs=
83422378475aSmrg	  for deplib in $dependency_libs; do
83432378475aSmrg	    case $deplib in
83442378475aSmrg	    -L*) func_stripname '-L' '' "$deplib"
834514330f12Smrg	         func_resolve_sysroot "$func_stripname_result"
834614330f12Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
83472378475aSmrg		 ;;
83482378475aSmrg	    esac
83492378475aSmrg	    # Need to link against all dependency_libs?
8350eca46af7Smrg	    if $linkalldeplibs; then
83512378475aSmrg	      deplibs="$deplib $deplibs"
83522378475aSmrg	    else
83532378475aSmrg	      # Need to hardcode shared library paths
83542378475aSmrg	      # or/and link against static libraries
83552378475aSmrg	      newdependency_libs="$deplib $newdependency_libs"
83562378475aSmrg	    fi
8357eca46af7Smrg	    if $opt_preserve_dup_deps; then
83582378475aSmrg	      case "$tmp_libs " in
835914330f12Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
83602378475aSmrg	      esac
83612378475aSmrg	    fi
836214330f12Smrg	    func_append tmp_libs " $deplib"
83632378475aSmrg	  done # for deplib
83642378475aSmrg	  continue
83652378475aSmrg	fi # $linkmode = prog...
83662378475aSmrg
8367eca46af7Smrg	if test prog,link = "$linkmode,$pass"; then
83682378475aSmrg	  if test -n "$library_names" &&
8369eca46af7Smrg	     { { test no = "$prefer_static_libs" ||
8370eca46af7Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
83712378475aSmrg	       test -z "$old_library"; }; then
83722378475aSmrg	    # We need to hardcode the library path
8373eca46af7Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
83742378475aSmrg	      # Make sure the rpath contains only unique directories.
8375eca46af7Smrg	      case $temp_rpath: in
83762378475aSmrg	      *"$absdir:"*) ;;
837714330f12Smrg	      *) func_append temp_rpath "$absdir:" ;;
83782378475aSmrg	      esac
83792378475aSmrg	    fi
83802378475aSmrg
83812378475aSmrg	    # Hardcode the library path.
83822378475aSmrg	    # Skip directories that are in the system default run-time
83832378475aSmrg	    # search path.
83842378475aSmrg	    case " $sys_lib_dlsearch_path " in
83852378475aSmrg	    *" $absdir "*) ;;
83862378475aSmrg	    *)
83872378475aSmrg	      case "$compile_rpath " in
83882378475aSmrg	      *" $absdir "*) ;;
838914330f12Smrg	      *) func_append compile_rpath " $absdir" ;;
83902378475aSmrg	      esac
83912378475aSmrg	      ;;
83922378475aSmrg	    esac
83932378475aSmrg	    case " $sys_lib_dlsearch_path " in
83942378475aSmrg	    *" $libdir "*) ;;
83952378475aSmrg	    *)
83962378475aSmrg	      case "$finalize_rpath " in
83972378475aSmrg	      *" $libdir "*) ;;
839814330f12Smrg	      *) func_append finalize_rpath " $libdir" ;;
83992378475aSmrg	      esac
84002378475aSmrg	      ;;
84012378475aSmrg	    esac
84022378475aSmrg	  fi # $linkmode,$pass = prog,link...
84032378475aSmrg
8404eca46af7Smrg	  if $alldeplibs &&
8405eca46af7Smrg	     { test pass_all = "$deplibs_check_method" ||
8406eca46af7Smrg	       { test yes = "$build_libtool_libs" &&
84072378475aSmrg		 test -n "$library_names"; }; }; then
84082378475aSmrg	    # We only need to search for static libraries
84092378475aSmrg	    continue
84102378475aSmrg	  fi
84112378475aSmrg	fi
84122378475aSmrg
84132378475aSmrg	link_static=no # Whether the deplib will be linked statically
84142378475aSmrg	use_static_libs=$prefer_static_libs
8415eca46af7Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
84162378475aSmrg	  use_static_libs=no
84172378475aSmrg	fi
84182378475aSmrg	if test -n "$library_names" &&
8419eca46af7Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
84202378475aSmrg	  case $host in
8421eca46af7Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
84222378475aSmrg	      # No point in relinking DLLs because paths are not encoded
842314330f12Smrg	      func_append notinst_deplibs " $lib"
84242378475aSmrg	      need_relink=no
84252378475aSmrg	    ;;
84262378475aSmrg	  *)
8427eca46af7Smrg	    if test no = "$installed"; then
842814330f12Smrg	      func_append notinst_deplibs " $lib"
84292378475aSmrg	      need_relink=yes
84302378475aSmrg	    fi
84312378475aSmrg	    ;;
84322378475aSmrg	  esac
84332378475aSmrg	  # This is a shared library
84342378475aSmrg
84352378475aSmrg	  # Warn about portability, can't link against -module's on some
84362378475aSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437eca46af7Smrg	  dlopenmodule=
84382378475aSmrg	  for dlpremoduletest in $dlprefiles; do
84392378475aSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440eca46af7Smrg	      dlopenmodule=$dlpremoduletest
84412378475aSmrg	      break
84422378475aSmrg	    fi
84432378475aSmrg	  done
8444eca46af7Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
844514330f12Smrg	    echo
8446eca46af7Smrg	    if test prog = "$linkmode"; then
84472378475aSmrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
84482378475aSmrg	    else
84492378475aSmrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
84502378475aSmrg	    fi
84512378475aSmrg	    $ECHO "*** $linklib is not portable!"
84522378475aSmrg	  fi
8453eca46af7Smrg	  if test lib = "$linkmode" &&
8454eca46af7Smrg	     test yes = "$hardcode_into_libs"; then
84552378475aSmrg	    # Hardcode the library path.
84562378475aSmrg	    # Skip directories that are in the system default run-time
84572378475aSmrg	    # search path.
84582378475aSmrg	    case " $sys_lib_dlsearch_path " in
84592378475aSmrg	    *" $absdir "*) ;;
84602378475aSmrg	    *)
84612378475aSmrg	      case "$compile_rpath " in
84622378475aSmrg	      *" $absdir "*) ;;
846314330f12Smrg	      *) func_append compile_rpath " $absdir" ;;
84642378475aSmrg	      esac
84652378475aSmrg	      ;;
84662378475aSmrg	    esac
84672378475aSmrg	    case " $sys_lib_dlsearch_path " in
84682378475aSmrg	    *" $libdir "*) ;;
84692378475aSmrg	    *)
84702378475aSmrg	      case "$finalize_rpath " in
84712378475aSmrg	      *" $libdir "*) ;;
847214330f12Smrg	      *) func_append finalize_rpath " $libdir" ;;
84732378475aSmrg	      esac
84742378475aSmrg	      ;;
84752378475aSmrg	    esac
84762378475aSmrg	  fi
84772378475aSmrg
84782378475aSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
84792378475aSmrg	    # figure out the soname
84802378475aSmrg	    set dummy $library_names
84812378475aSmrg	    shift
8482eca46af7Smrg	    realname=$1
84832378475aSmrg	    shift
84842378475aSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
84852378475aSmrg	    # use dlname if we got it. it's perfectly good, no?
84862378475aSmrg	    if test -n "$dlname"; then
8487eca46af7Smrg	      soname=$dlname
84882378475aSmrg	    elif test -n "$soname_spec"; then
84892378475aSmrg	      # bleh windows
84902378475aSmrg	      case $host in
8491eca46af7Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
84922378475aSmrg	        func_arith $current - $age
84932378475aSmrg		major=$func_arith_result
8494eca46af7Smrg		versuffix=-$major
84952378475aSmrg		;;
84962378475aSmrg	      esac
84972378475aSmrg	      eval soname=\"$soname_spec\"
84982378475aSmrg	    else
8499eca46af7Smrg	      soname=$realname
85002378475aSmrg	    fi
85012378475aSmrg
85022378475aSmrg	    # Make a new name for the extract_expsyms_cmds to use
8503eca46af7Smrg	    soroot=$soname
85042378475aSmrg	    func_basename "$soroot"
8505eca46af7Smrg	    soname=$func_basename_result
85062378475aSmrg	    func_stripname 'lib' '.dll' "$soname"
85072378475aSmrg	    newlib=libimp-$func_stripname_result.a
85082378475aSmrg
85092378475aSmrg	    # If the library has no export list, then create one now
85102378475aSmrg	    if test -f "$output_objdir/$soname-def"; then :
85112378475aSmrg	    else
8512eca46af7Smrg	      func_verbose "extracting exported symbol list from '$soname'"
85132378475aSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
85142378475aSmrg	    fi
85152378475aSmrg
85162378475aSmrg	    # Create $newlib
85172378475aSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8518eca46af7Smrg	      func_verbose "generating import library for '$soname'"
85192378475aSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
85202378475aSmrg	    fi
85212378475aSmrg	    # make sure the library variables are pointing to the new library
85222378475aSmrg	    dir=$output_objdir
85232378475aSmrg	    linklib=$newlib
85242378475aSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
85252378475aSmrg
8526eca46af7Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
85272378475aSmrg	    add_shlibpath=
85282378475aSmrg	    add_dir=
85292378475aSmrg	    add=
85302378475aSmrg	    lib_linked=yes
85312378475aSmrg	    case $hardcode_action in
85322378475aSmrg	    immediate | unsupported)
8533eca46af7Smrg	      if test no = "$hardcode_direct"; then
8534eca46af7Smrg		add=$dir/$linklib
85352378475aSmrg		case $host in
8536eca46af7Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537eca46af7Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
85382378475aSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539eca46af7Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
85402378475aSmrg		  *-*-darwin* )
8541eca46af7Smrg		    # if the lib is a (non-dlopened) module then we cannot
85422378475aSmrg		    # link against it, someone is ignoring the earlier warnings
85432378475aSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8544eca46af7Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
85452378475aSmrg		      if test "X$dlopenmodule" != "X$lib"; then
85462378475aSmrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547eca46af7Smrg			if test -z "$old_library"; then
854814330f12Smrg			  echo
854914330f12Smrg			  echo "*** And there doesn't seem to be a static archive available"
855014330f12Smrg			  echo "*** The link will probably fail, sorry"
85512378475aSmrg			else
8552eca46af7Smrg			  add=$dir/$old_library
85532378475aSmrg			fi
85542378475aSmrg		      elif test -n "$old_library"; then
8555eca46af7Smrg			add=$dir/$old_library
85562378475aSmrg		      fi
85572378475aSmrg		    fi
85582378475aSmrg		esac
8559eca46af7Smrg	      elif test no = "$hardcode_minus_L"; then
85602378475aSmrg		case $host in
8561eca46af7Smrg		*-*-sunos*) add_shlibpath=$dir ;;
85622378475aSmrg		esac
8563eca46af7Smrg		add_dir=-L$dir
8564eca46af7Smrg		add=-l$name
8565eca46af7Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8566eca46af7Smrg		add_shlibpath=$dir
8567eca46af7Smrg		add=-l$name
85682378475aSmrg	      else
85692378475aSmrg		lib_linked=no
85702378475aSmrg	      fi
85712378475aSmrg	      ;;
85722378475aSmrg	    relink)
8573eca46af7Smrg	      if test yes = "$hardcode_direct" &&
8574eca46af7Smrg	         test no = "$hardcode_direct_absolute"; then
8575eca46af7Smrg		add=$dir/$linklib
8576eca46af7Smrg	      elif test yes = "$hardcode_minus_L"; then
8577eca46af7Smrg		add_dir=-L$absdir
85782378475aSmrg		# Try looking first in the location we're being installed to.
85792378475aSmrg		if test -n "$inst_prefix_dir"; then
85802378475aSmrg		  case $libdir in
85812378475aSmrg		    [\\/]*)
858214330f12Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
85832378475aSmrg		      ;;
85842378475aSmrg		  esac
85852378475aSmrg		fi
8586eca46af7Smrg		add=-l$name
8587eca46af7Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588eca46af7Smrg		add_shlibpath=$dir
8589eca46af7Smrg		add=-l$name
85902378475aSmrg	      else
85912378475aSmrg		lib_linked=no
85922378475aSmrg	      fi
85932378475aSmrg	      ;;
85942378475aSmrg	    *) lib_linked=no ;;
85952378475aSmrg	    esac
85962378475aSmrg
8597eca46af7Smrg	    if test yes != "$lib_linked"; then
85982378475aSmrg	      func_fatal_configuration "unsupported hardcode properties"
85992378475aSmrg	    fi
86002378475aSmrg
86012378475aSmrg	    if test -n "$add_shlibpath"; then
86022378475aSmrg	      case :$compile_shlibpath: in
86032378475aSmrg	      *":$add_shlibpath:"*) ;;
860414330f12Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
86052378475aSmrg	      esac
86062378475aSmrg	    fi
8607eca46af7Smrg	    if test prog = "$linkmode"; then
86082378475aSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
86092378475aSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
86102378475aSmrg	    else
86112378475aSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86122378475aSmrg	      test -n "$add" && deplibs="$add $deplibs"
8613eca46af7Smrg	      if test yes != "$hardcode_direct" &&
8614eca46af7Smrg		 test yes != "$hardcode_minus_L" &&
8615eca46af7Smrg		 test yes = "$hardcode_shlibpath_var"; then
86162378475aSmrg		case :$finalize_shlibpath: in
86172378475aSmrg		*":$libdir:"*) ;;
861814330f12Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
86192378475aSmrg		esac
86202378475aSmrg	      fi
86212378475aSmrg	    fi
86222378475aSmrg	  fi
86232378475aSmrg
8624eca46af7Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
86252378475aSmrg	    add_shlibpath=
86262378475aSmrg	    add_dir=
86272378475aSmrg	    add=
86282378475aSmrg	    # Finalize command for both is simple: just hardcode it.
8629eca46af7Smrg	    if test yes = "$hardcode_direct" &&
8630eca46af7Smrg	       test no = "$hardcode_direct_absolute"; then
8631eca46af7Smrg	      add=$libdir/$linklib
8632eca46af7Smrg	    elif test yes = "$hardcode_minus_L"; then
8633eca46af7Smrg	      add_dir=-L$libdir
8634eca46af7Smrg	      add=-l$name
8635eca46af7Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
86362378475aSmrg	      case :$finalize_shlibpath: in
86372378475aSmrg	      *":$libdir:"*) ;;
863814330f12Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
86392378475aSmrg	      esac
8640eca46af7Smrg	      add=-l$name
8641eca46af7Smrg	    elif test yes = "$hardcode_automatic"; then
86422378475aSmrg	      if test -n "$inst_prefix_dir" &&
8643eca46af7Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644eca46af7Smrg		add=$inst_prefix_dir$libdir/$linklib
86452378475aSmrg	      else
8646eca46af7Smrg		add=$libdir/$linklib
86472378475aSmrg	      fi
86482378475aSmrg	    else
86492378475aSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650eca46af7Smrg	      add_dir=-L$libdir
86512378475aSmrg	      # Try looking first in the location we're being installed to.
86522378475aSmrg	      if test -n "$inst_prefix_dir"; then
86532378475aSmrg		case $libdir in
86542378475aSmrg		  [\\/]*)
865514330f12Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
86562378475aSmrg		    ;;
86572378475aSmrg		esac
86582378475aSmrg	      fi
8659eca46af7Smrg	      add=-l$name
86602378475aSmrg	    fi
86612378475aSmrg
8662eca46af7Smrg	    if test prog = "$linkmode"; then
86632378475aSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
86642378475aSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
86652378475aSmrg	    else
86662378475aSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86672378475aSmrg	      test -n "$add" && deplibs="$add $deplibs"
86682378475aSmrg	    fi
86692378475aSmrg	  fi
8670eca46af7Smrg	elif test prog = "$linkmode"; then
86712378475aSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
86722378475aSmrg	  # is not unsupported.  This is valid on all known static and
86732378475aSmrg	  # shared platforms.
8674eca46af7Smrg	  if test unsupported != "$hardcode_direct"; then
8675eca46af7Smrg	    test -n "$old_library" && linklib=$old_library
86762378475aSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
86772378475aSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
86782378475aSmrg	  else
86792378475aSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
86802378475aSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
86812378475aSmrg	  fi
8682eca46af7Smrg	elif test yes = "$build_libtool_libs"; then
86832378475aSmrg	  # Not a shared library
8684eca46af7Smrg	  if test pass_all != "$deplibs_check_method"; then
86852378475aSmrg	    # We're trying link a shared library against a static one
86862378475aSmrg	    # but the system doesn't support it.
86872378475aSmrg
86882378475aSmrg	    # Just print a warning and add the library to dependency_libs so
86892378475aSmrg	    # that the program can be linked against the static library.
869014330f12Smrg	    echo
8691eca46af7Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
869214330f12Smrg	    echo "*** I have the capability to make that library automatically link in when"
869314330f12Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
869414330f12Smrg	    echo "*** shared version of the library, which you do not appear to have."
8695eca46af7Smrg	    if test yes = "$module"; then
869614330f12Smrg	      echo "*** But as you try to build a module library, libtool will still create "
869714330f12Smrg	      echo "*** a static module, that should work as long as the dlopening application"
869814330f12Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
86992378475aSmrg	      if test -z "$global_symbol_pipe"; then
870014330f12Smrg		echo
870114330f12Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702eca46af7Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
870314330f12Smrg		echo "*** not find such a program.  So, this module is probably useless."
8704eca46af7Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
87052378475aSmrg	      fi
8706eca46af7Smrg	      if test no = "$build_old_libs"; then
87072378475aSmrg		build_libtool_libs=module
87082378475aSmrg		build_old_libs=yes
87092378475aSmrg	      else
87102378475aSmrg		build_libtool_libs=no
87112378475aSmrg	      fi
87122378475aSmrg	    fi
87132378475aSmrg	  else
87142378475aSmrg	    deplibs="$dir/$old_library $deplibs"
87152378475aSmrg	    link_static=yes
87162378475aSmrg	  fi
87172378475aSmrg	fi # link shared/static library?
87182378475aSmrg
8719eca46af7Smrg	if test lib = "$linkmode"; then
87202378475aSmrg	  if test -n "$dependency_libs" &&
8721eca46af7Smrg	     { test yes != "$hardcode_into_libs" ||
8722eca46af7Smrg	       test yes = "$build_old_libs" ||
8723eca46af7Smrg	       test yes = "$link_static"; }; then
87242378475aSmrg	    # Extract -R from dependency_libs
87252378475aSmrg	    temp_deplibs=
87262378475aSmrg	    for libdir in $dependency_libs; do
87272378475aSmrg	      case $libdir in
87282378475aSmrg	      -R*) func_stripname '-R' '' "$libdir"
87292378475aSmrg	           temp_xrpath=$func_stripname_result
87302378475aSmrg		   case " $xrpath " in
87312378475aSmrg		   *" $temp_xrpath "*) ;;
873214330f12Smrg		   *) func_append xrpath " $temp_xrpath";;
87332378475aSmrg		   esac;;
873414330f12Smrg	      *) func_append temp_deplibs " $libdir";;
87352378475aSmrg	      esac
87362378475aSmrg	    done
8737eca46af7Smrg	    dependency_libs=$temp_deplibs
87382378475aSmrg	  fi
87392378475aSmrg
874014330f12Smrg	  func_append newlib_search_path " $absdir"
87412378475aSmrg	  # Link against this library
8742eca46af7Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
87432378475aSmrg	  # ... and its dependency_libs
87442378475aSmrg	  tmp_libs=
87452378475aSmrg	  for deplib in $dependency_libs; do
87462378475aSmrg	    newdependency_libs="$deplib $newdependency_libs"
874714330f12Smrg	    case $deplib in
874814330f12Smrg              -L*) func_stripname '-L' '' "$deplib"
874914330f12Smrg                   func_resolve_sysroot "$func_stripname_result";;
875014330f12Smrg              *) func_resolve_sysroot "$deplib" ;;
875114330f12Smrg            esac
8752eca46af7Smrg	    if $opt_preserve_dup_deps; then
87532378475aSmrg	      case "$tmp_libs " in
875414330f12Smrg	      *" $func_resolve_sysroot_result "*)
875514330f12Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
87562378475aSmrg	      esac
87572378475aSmrg	    fi
875814330f12Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
87592378475aSmrg	  done
87602378475aSmrg
8761eca46af7Smrg	  if test no != "$link_all_deplibs"; then
87622378475aSmrg	    # Add the search paths of all dependency libraries
87632378475aSmrg	    for deplib in $dependency_libs; do
876414330f12Smrg	      path=
87652378475aSmrg	      case $deplib in
8766eca46af7Smrg	      -L*) path=$deplib ;;
87672378475aSmrg	      *.la)
876814330f12Smrg	        func_resolve_sysroot "$deplib"
876914330f12Smrg	        deplib=$func_resolve_sysroot_result
87702378475aSmrg	        func_dirname "$deplib" "" "."
877114330f12Smrg		dir=$func_dirname_result
87722378475aSmrg		# We need an absolute path.
87732378475aSmrg		case $dir in
8774eca46af7Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
87752378475aSmrg		*)
87762378475aSmrg		  absdir=`cd "$dir" && pwd`
87772378475aSmrg		  if test -z "$absdir"; then
8778eca46af7Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779eca46af7Smrg		    absdir=$dir
87802378475aSmrg		  fi
87812378475aSmrg		  ;;
87822378475aSmrg		esac
87832378475aSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
87842378475aSmrg		case $host in
87852378475aSmrg		*-*-darwin*)
87862378475aSmrg		  depdepl=
8787eca46af7Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788eca46af7Smrg		  if test -n "$deplibrary_names"; then
8789eca46af7Smrg		    for tmp in $deplibrary_names; do
87902378475aSmrg		      depdepl=$tmp
87912378475aSmrg		    done
8792eca46af7Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793eca46af7Smrg		      depdepl=$absdir/$objdir/$depdepl
8794eca46af7Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
87952378475aSmrg                      if test -z "$darwin_install_name"; then
8796eca46af7Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
87972378475aSmrg                      fi
8798eca46af7Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799eca46af7Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
88002378475aSmrg		      path=
88012378475aSmrg		    fi
88022378475aSmrg		  fi
88032378475aSmrg		  ;;
88042378475aSmrg		*)
8805eca46af7Smrg		  path=-L$absdir/$objdir
88062378475aSmrg		  ;;
88072378475aSmrg		esac
88082378475aSmrg		else
8809eca46af7Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
88102378475aSmrg		  test -z "$libdir" && \
8811eca46af7Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
88122378475aSmrg		  test "$absdir" != "$libdir" && \
8813eca46af7Smrg		    func_warning "'$deplib' seems to be moved"
88142378475aSmrg
8815eca46af7Smrg		  path=-L$absdir
88162378475aSmrg		fi
88172378475aSmrg		;;
88182378475aSmrg	      esac
88192378475aSmrg	      case " $deplibs " in
88202378475aSmrg	      *" $path "*) ;;
88212378475aSmrg	      *) deplibs="$path $deplibs" ;;
88222378475aSmrg	      esac
88232378475aSmrg	    done
88242378475aSmrg	  fi # link_all_deplibs != no
88252378475aSmrg	fi # linkmode = lib
88262378475aSmrg      done # for deplib in $libs
8827eca46af7Smrg      if test link = "$pass"; then
8828eca46af7Smrg	if test prog = "$linkmode"; then
88292378475aSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
88302378475aSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
88312378475aSmrg	else
883214330f12Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
88332378475aSmrg	fi
88342378475aSmrg      fi
8835eca46af7Smrg      dependency_libs=$newdependency_libs
8836eca46af7Smrg      if test dlpreopen = "$pass"; then
88372378475aSmrg	# Link the dlpreopened libraries before other libraries
88382378475aSmrg	for deplib in $save_deplibs; do
88392378475aSmrg	  deplibs="$deplib $deplibs"
88402378475aSmrg	done
88412378475aSmrg      fi
8842eca46af7Smrg      if test dlopen != "$pass"; then
8843eca46af7Smrg	test conv = "$pass" || {
88442378475aSmrg	  # Make sure lib_search_path contains only unique directories.
88452378475aSmrg	  lib_search_path=
88462378475aSmrg	  for dir in $newlib_search_path; do
88472378475aSmrg	    case "$lib_search_path " in
88482378475aSmrg	    *" $dir "*) ;;
884914330f12Smrg	    *) func_append lib_search_path " $dir" ;;
88502378475aSmrg	    esac
88512378475aSmrg	  done
88522378475aSmrg	  newlib_search_path=
8853eca46af7Smrg	}
88542378475aSmrg
8855eca46af7Smrg	if test prog,link = "$linkmode,$pass"; then
88562378475aSmrg	  vars="compile_deplibs finalize_deplibs"
8857eca46af7Smrg	else
8858eca46af7Smrg	  vars=deplibs
88592378475aSmrg	fi
88602378475aSmrg	for var in $vars dependency_libs; do
88612378475aSmrg	  # Add libraries to $var in reverse order
88622378475aSmrg	  eval tmp_libs=\"\$$var\"
88632378475aSmrg	  new_libs=
88642378475aSmrg	  for deplib in $tmp_libs; do
88652378475aSmrg	    # FIXME: Pedantically, this is the right thing to do, so
88662378475aSmrg	    #        that some nasty dependency loop isn't accidentally
88672378475aSmrg	    #        broken:
88682378475aSmrg	    #new_libs="$deplib $new_libs"
88692378475aSmrg	    # Pragmatically, this seems to cause very few problems in
88702378475aSmrg	    # practice:
88712378475aSmrg	    case $deplib in
88722378475aSmrg	    -L*) new_libs="$deplib $new_libs" ;;
88732378475aSmrg	    -R*) ;;
88742378475aSmrg	    *)
88752378475aSmrg	      # And here is the reason: when a library appears more
88762378475aSmrg	      # than once as an explicit dependence of a library, or
88772378475aSmrg	      # is implicitly linked in more than once by the
88782378475aSmrg	      # compiler, it is considered special, and multiple
88792378475aSmrg	      # occurrences thereof are not removed.  Compare this
88802378475aSmrg	      # with having the same library being listed as a
88812378475aSmrg	      # dependency of multiple other libraries: in this case,
88822378475aSmrg	      # we know (pedantically, we assume) the library does not
88832378475aSmrg	      # need to be listed more than once, so we keep only the
88842378475aSmrg	      # last copy.  This is not always right, but it is rare
88852378475aSmrg	      # enough that we require users that really mean to play
88862378475aSmrg	      # such unportable linking tricks to link the library
88872378475aSmrg	      # using -Wl,-lname, so that libtool does not consider it
88882378475aSmrg	      # for duplicate removal.
88892378475aSmrg	      case " $specialdeplibs " in
88902378475aSmrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
88912378475aSmrg	      *)
88922378475aSmrg		case " $new_libs " in
88932378475aSmrg		*" $deplib "*) ;;
88942378475aSmrg		*) new_libs="$deplib $new_libs" ;;
88952378475aSmrg		esac
88962378475aSmrg		;;
88972378475aSmrg	      esac
88982378475aSmrg	      ;;
88992378475aSmrg	    esac
89002378475aSmrg	  done
89012378475aSmrg	  tmp_libs=
89022378475aSmrg	  for deplib in $new_libs; do
89032378475aSmrg	    case $deplib in
89042378475aSmrg	    -L*)
89052378475aSmrg	      case " $tmp_libs " in
89062378475aSmrg	      *" $deplib "*) ;;
890714330f12Smrg	      *) func_append tmp_libs " $deplib" ;;
89082378475aSmrg	      esac
89092378475aSmrg	      ;;
891014330f12Smrg	    *) func_append tmp_libs " $deplib" ;;
89112378475aSmrg	    esac
89122378475aSmrg	  done
89132378475aSmrg	  eval $var=\"$tmp_libs\"
89142378475aSmrg	done # for var
89152378475aSmrg      fi
891689b0dc75Smrg
891789b0dc75Smrg      # Add Sun CC postdeps if required:
891889b0dc75Smrg      test CXX = "$tagname" && {
891989b0dc75Smrg        case $host_os in
892089b0dc75Smrg        linux*)
8921d87a3195Smrg          case `$CC -V 2>&1 | $SED 5q` in
892289b0dc75Smrg          *Sun\ C*) # Sun C++ 5.9
892389b0dc75Smrg            func_suncc_cstd_abi
892489b0dc75Smrg
892589b0dc75Smrg            if test no != "$suncc_use_cstd_abi"; then
892689b0dc75Smrg              func_append postdeps ' -library=Cstd -library=Crun'
892789b0dc75Smrg            fi
892889b0dc75Smrg            ;;
892989b0dc75Smrg          esac
893089b0dc75Smrg          ;;
893189b0dc75Smrg
893289b0dc75Smrg        solaris*)
893389b0dc75Smrg          func_cc_basename "$CC"
893489b0dc75Smrg          case $func_cc_basename_result in
893589b0dc75Smrg          CC* | sunCC*)
893689b0dc75Smrg            func_suncc_cstd_abi
893789b0dc75Smrg
893889b0dc75Smrg            if test no != "$suncc_use_cstd_abi"; then
893989b0dc75Smrg              func_append postdeps ' -library=Cstd -library=Crun'
894089b0dc75Smrg            fi
894189b0dc75Smrg            ;;
894289b0dc75Smrg          esac
894389b0dc75Smrg          ;;
894489b0dc75Smrg        esac
894589b0dc75Smrg      }
894689b0dc75Smrg
89472378475aSmrg      # Last step: remove runtime libs from dependency_libs
89482378475aSmrg      # (they stay in deplibs)
89492378475aSmrg      tmp_libs=
8950eca46af7Smrg      for i in $dependency_libs; do
89512378475aSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
89522378475aSmrg	*" $i "*)
8953eca46af7Smrg	  i=
89542378475aSmrg	  ;;
89552378475aSmrg	esac
8956eca46af7Smrg	if test -n "$i"; then
895714330f12Smrg	  func_append tmp_libs " $i"
89582378475aSmrg	fi
89592378475aSmrg      done
89602378475aSmrg      dependency_libs=$tmp_libs
89612378475aSmrg    done # for pass
8962eca46af7Smrg    if test prog = "$linkmode"; then
8963eca46af7Smrg      dlfiles=$newdlfiles
89642378475aSmrg    fi
8965eca46af7Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966eca46af7Smrg      dlprefiles=$newdlprefiles
89672378475aSmrg    fi
89682378475aSmrg
89692378475aSmrg    case $linkmode in
89702378475aSmrg    oldlib)
8971eca46af7Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972eca46af7Smrg	func_warning "'-dlopen' is ignored for archives"
89732378475aSmrg      fi
89742378475aSmrg
89752378475aSmrg      case " $deplibs" in
89762378475aSmrg      *\ -l* | *\ -L*)
8977eca46af7Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
89782378475aSmrg      esac
89792378475aSmrg
89802378475aSmrg      test -n "$rpath" && \
8981eca46af7Smrg	func_warning "'-rpath' is ignored for archives"
89822378475aSmrg
89832378475aSmrg      test -n "$xrpath" && \
8984eca46af7Smrg	func_warning "'-R' is ignored for archives"
89852378475aSmrg
89862378475aSmrg      test -n "$vinfo" && \
8987eca46af7Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
89882378475aSmrg
89892378475aSmrg      test -n "$release" && \
8990eca46af7Smrg	func_warning "'-release' is ignored for archives"
89912378475aSmrg
89922378475aSmrg      test -n "$export_symbols$export_symbols_regex" && \
8993eca46af7Smrg	func_warning "'-export-symbols' is ignored for archives"
89942378475aSmrg
89952378475aSmrg      # Now set the variables for building old libraries.
89962378475aSmrg      build_libtool_libs=no
8997eca46af7Smrg      oldlibs=$output
899814330f12Smrg      func_append objs "$old_deplibs"
89992378475aSmrg      ;;
90002378475aSmrg
90012378475aSmrg    lib)
9002eca46af7Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
90032378475aSmrg      case $outputname in
90042378475aSmrg      lib*)
90052378475aSmrg	func_stripname 'lib' '.la' "$outputname"
90062378475aSmrg	name=$func_stripname_result
90072378475aSmrg	eval shared_ext=\"$shrext_cmds\"
90082378475aSmrg	eval libname=\"$libname_spec\"
90092378475aSmrg	;;
90102378475aSmrg      *)
9011eca46af7Smrg	test no = "$module" \
9012eca46af7Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
90132378475aSmrg
9014eca46af7Smrg	if test no != "$need_lib_prefix"; then
90152378475aSmrg	  # Add the "lib" prefix for modules if required
90162378475aSmrg	  func_stripname '' '.la' "$outputname"
90172378475aSmrg	  name=$func_stripname_result
90182378475aSmrg	  eval shared_ext=\"$shrext_cmds\"
90192378475aSmrg	  eval libname=\"$libname_spec\"
90202378475aSmrg	else
90212378475aSmrg	  func_stripname '' '.la' "$outputname"
90222378475aSmrg	  libname=$func_stripname_result
90232378475aSmrg	fi
90242378475aSmrg	;;
90252378475aSmrg      esac
90262378475aSmrg
90272378475aSmrg      if test -n "$objs"; then
9028eca46af7Smrg	if test pass_all != "$deplibs_check_method"; then
9029eca46af7Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
90302378475aSmrg	else
903114330f12Smrg	  echo
90322378475aSmrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
90332378475aSmrg	  $ECHO "*** objects $objs is not portable!"
903414330f12Smrg	  func_append libobjs " $objs"
90352378475aSmrg	fi
90362378475aSmrg      fi
90372378475aSmrg
9038eca46af7Smrg      test no = "$dlself" \
9039eca46af7Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
90402378475aSmrg
90412378475aSmrg      set dummy $rpath
90422378475aSmrg      shift
9043eca46af7Smrg      test 1 -lt "$#" \
9044eca46af7Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
90452378475aSmrg
9046eca46af7Smrg      install_libdir=$1
90472378475aSmrg
90482378475aSmrg      oldlibs=
90492378475aSmrg      if test -z "$rpath"; then
9050eca46af7Smrg	if test yes = "$build_libtool_libs"; then
90512378475aSmrg	  # Building a libtool convenience library.
9052eca46af7Smrg	  # Some compilers have problems with a '.al' extension so
90532378475aSmrg	  # convenience libraries should have the same extension an
90542378475aSmrg	  # archive normally would.
90552378475aSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
90562378475aSmrg	  build_libtool_libs=convenience
90572378475aSmrg	  build_old_libs=yes
90582378475aSmrg	fi
90592378475aSmrg
90602378475aSmrg	test -n "$vinfo" && \
9061eca46af7Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
90622378475aSmrg
90632378475aSmrg	test -n "$release" && \
9064eca46af7Smrg	  func_warning "'-release' is ignored for convenience libraries"
90652378475aSmrg      else
90662378475aSmrg
90672378475aSmrg	# Parse the version information argument.
9068eca46af7Smrg	save_ifs=$IFS; IFS=:
90692378475aSmrg	set dummy $vinfo 0 0 0
90702378475aSmrg	shift
9071eca46af7Smrg	IFS=$save_ifs
90722378475aSmrg
90732378475aSmrg	test -n "$7" && \
9074eca46af7Smrg	  func_fatal_help "too many parameters to '-version-info'"
90752378475aSmrg
90762378475aSmrg	# convert absolute version numbers to libtool ages
90772378475aSmrg	# this retains compatibility with .la files and attempts
90782378475aSmrg	# to make the code below a bit more comprehensible
90792378475aSmrg
90802378475aSmrg	case $vinfo_number in
90812378475aSmrg	yes)
9082eca46af7Smrg	  number_major=$1
9083eca46af7Smrg	  number_minor=$2
9084eca46af7Smrg	  number_revision=$3
90852378475aSmrg	  #
90862378475aSmrg	  # There are really only two kinds -- those that
90872378475aSmrg	  # use the current revision as the major version
90882378475aSmrg	  # and those that subtract age and use age as
90892378475aSmrg	  # a minor version.  But, then there is irix
9090eca46af7Smrg	  # that has an extra 1 added just for fun
90912378475aSmrg	  #
90922378475aSmrg	  case $version_type in
9093eca46af7Smrg	  # correct linux to gnu/linux during the next big refactor
9094d87a3195Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
90952378475aSmrg	    func_arith $number_major + $number_minor
90962378475aSmrg	    current=$func_arith_result
9097eca46af7Smrg	    age=$number_minor
9098eca46af7Smrg	    revision=$number_revision
90992378475aSmrg	    ;;
9100eca46af7Smrg	  freebsd-aout|qnx|sunos)
9101eca46af7Smrg	    current=$number_major
9102eca46af7Smrg	    revision=$number_minor
9103eca46af7Smrg	    age=0
91042378475aSmrg	    ;;
91052378475aSmrg	  irix|nonstopux)
91062378475aSmrg	    func_arith $number_major + $number_minor
91072378475aSmrg	    current=$func_arith_result
9108eca46af7Smrg	    age=$number_minor
9109eca46af7Smrg	    revision=$number_minor
91102378475aSmrg	    lt_irix_increment=no
91112378475aSmrg	    ;;
91122378475aSmrg	  esac
91132378475aSmrg	  ;;
91142378475aSmrg	no)
9115eca46af7Smrg	  current=$1
9116eca46af7Smrg	  revision=$2
9117eca46af7Smrg	  age=$3
91182378475aSmrg	  ;;
91192378475aSmrg	esac
91202378475aSmrg
91212378475aSmrg	# Check that each of the things are valid numbers.
91222378475aSmrg	case $current in
91232378475aSmrg	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]) ;;
91242378475aSmrg	*)
9125eca46af7Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126eca46af7Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91272378475aSmrg	  ;;
91282378475aSmrg	esac
91292378475aSmrg
91302378475aSmrg	case $revision in
91312378475aSmrg	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]) ;;
91322378475aSmrg	*)
9133eca46af7Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134eca46af7Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91352378475aSmrg	  ;;
91362378475aSmrg	esac
91372378475aSmrg
91382378475aSmrg	case $age in
91392378475aSmrg	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]) ;;
91402378475aSmrg	*)
9141eca46af7Smrg	  func_error "AGE '$age' must be a nonnegative integer"
9142eca46af7Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91432378475aSmrg	  ;;
91442378475aSmrg	esac
91452378475aSmrg
91462378475aSmrg	if test "$age" -gt "$current"; then
9147eca46af7Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148eca46af7Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91492378475aSmrg	fi
91502378475aSmrg
91512378475aSmrg	# Calculate the version variables.
91522378475aSmrg	major=
91532378475aSmrg	versuffix=
91542378475aSmrg	verstring=
91552378475aSmrg	case $version_type in
91562378475aSmrg	none) ;;
91572378475aSmrg
91582378475aSmrg	darwin)
91592378475aSmrg	  # Like Linux, but with the current version available in
91602378475aSmrg	  # verstring for coding it into the library header
91612378475aSmrg	  func_arith $current - $age
91622378475aSmrg	  major=.$func_arith_result
9163eca46af7Smrg	  versuffix=$major.$age.$revision
91642378475aSmrg	  # Darwin ld doesn't like 0 for these options...
91652378475aSmrg	  func_arith $current + 1
91662378475aSmrg	  minor_current=$func_arith_result
9167eca46af7Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91682378475aSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169eca46af7Smrg          # On Darwin other compilers
9170eca46af7Smrg          case $CC in
9171eca46af7Smrg              nagfor*)
9172eca46af7Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173eca46af7Smrg                  ;;
9174eca46af7Smrg              *)
9175eca46af7Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176eca46af7Smrg                  ;;
9177eca46af7Smrg          esac
91782378475aSmrg	  ;;
91792378475aSmrg
91802378475aSmrg	freebsd-aout)
9181eca46af7Smrg	  major=.$current
9182eca46af7Smrg	  versuffix=.$current.$revision
91832378475aSmrg	  ;;
91842378475aSmrg
9185d87a3195Smrg	freebsd-elf | midnightbsd-elf)
9186eca46af7Smrg	  func_arith $current - $age
9187eca46af7Smrg	  major=.$func_arith_result
9188eca46af7Smrg	  versuffix=$major.$age.$revision
91892378475aSmrg	  ;;
91902378475aSmrg
91912378475aSmrg	irix | nonstopux)
9192eca46af7Smrg	  if test no = "$lt_irix_increment"; then
91932378475aSmrg	    func_arith $current - $age
91942378475aSmrg	  else
91952378475aSmrg	    func_arith $current - $age + 1
91962378475aSmrg	  fi
91972378475aSmrg	  major=$func_arith_result
91982378475aSmrg
91992378475aSmrg	  case $version_type in
92002378475aSmrg	    nonstopux) verstring_prefix=nonstopux ;;
92012378475aSmrg	    *)         verstring_prefix=sgi ;;
92022378475aSmrg	  esac
9203eca46af7Smrg	  verstring=$verstring_prefix$major.$revision
92042378475aSmrg
92052378475aSmrg	  # Add in all the interfaces that we are compatible with.
92062378475aSmrg	  loop=$revision
9207eca46af7Smrg	  while test 0 -ne "$loop"; do
92082378475aSmrg	    func_arith $revision - $loop
92092378475aSmrg	    iface=$func_arith_result
92102378475aSmrg	    func_arith $loop - 1
92112378475aSmrg	    loop=$func_arith_result
9212eca46af7Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
92132378475aSmrg	  done
92142378475aSmrg
9215eca46af7Smrg	  # Before this point, $major must not contain '.'.
92162378475aSmrg	  major=.$major
9217eca46af7Smrg	  versuffix=$major.$revision
92182378475aSmrg	  ;;
92192378475aSmrg
9220eca46af7Smrg	linux) # correct to gnu/linux during the next big refactor
92212378475aSmrg	  func_arith $current - $age
92222378475aSmrg	  major=.$func_arith_result
9223eca46af7Smrg	  versuffix=$major.$age.$revision
92242378475aSmrg	  ;;
92252378475aSmrg
92262378475aSmrg	osf)
92272378475aSmrg	  func_arith $current - $age
92282378475aSmrg	  major=.$func_arith_result
9229eca46af7Smrg	  versuffix=.$current.$age.$revision
9230eca46af7Smrg	  verstring=$current.$age.$revision
92312378475aSmrg
92322378475aSmrg	  # Add in all the interfaces that we are compatible with.
92332378475aSmrg	  loop=$age
9234eca46af7Smrg	  while test 0 -ne "$loop"; do
92352378475aSmrg	    func_arith $current - $loop
92362378475aSmrg	    iface=$func_arith_result
92372378475aSmrg	    func_arith $loop - 1
92382378475aSmrg	    loop=$func_arith_result
9239eca46af7Smrg	    verstring=$verstring:$iface.0
92402378475aSmrg	  done
92412378475aSmrg
92422378475aSmrg	  # Make executables depend on our current version.
9243eca46af7Smrg	  func_append verstring ":$current.0"
92442378475aSmrg	  ;;
92452378475aSmrg
92462378475aSmrg	qnx)
9247eca46af7Smrg	  major=.$current
9248eca46af7Smrg	  versuffix=.$current
9249eca46af7Smrg	  ;;
9250eca46af7Smrg
9251eca46af7Smrg	sco)
9252eca46af7Smrg	  major=.$current
9253eca46af7Smrg	  versuffix=.$current
92542378475aSmrg	  ;;
92552378475aSmrg
92562378475aSmrg	sunos)
9257eca46af7Smrg	  major=.$current
9258eca46af7Smrg	  versuffix=.$current.$revision
92592378475aSmrg	  ;;
92602378475aSmrg
92612378475aSmrg	windows)
92622378475aSmrg	  # Use '-' rather than '.', since we only want one
9263eca46af7Smrg	  # extension on DOS 8.3 file systems.
92642378475aSmrg	  func_arith $current - $age
92652378475aSmrg	  major=$func_arith_result
9266eca46af7Smrg	  versuffix=-$major
92672378475aSmrg	  ;;
92682378475aSmrg
92692378475aSmrg	*)
9270eca46af7Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
92712378475aSmrg	  ;;
92722378475aSmrg	esac
92732378475aSmrg
92742378475aSmrg	# Clear the version info if we defaulted, and they specified a release.
92752378475aSmrg	if test -z "$vinfo" && test -n "$release"; then
92762378475aSmrg	  major=
92772378475aSmrg	  case $version_type in
92782378475aSmrg	  darwin)
92792378475aSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
92802378475aSmrg	    # problems, so we reset it completely
92812378475aSmrg	    verstring=
92822378475aSmrg	    ;;
92832378475aSmrg	  *)
9284eca46af7Smrg	    verstring=0.0
92852378475aSmrg	    ;;
92862378475aSmrg	  esac
9287eca46af7Smrg	  if test no = "$need_version"; then
92882378475aSmrg	    versuffix=
92892378475aSmrg	  else
9290eca46af7Smrg	    versuffix=.0.0
92912378475aSmrg	  fi
92922378475aSmrg	fi
92932378475aSmrg
92942378475aSmrg	# Remove version info from name if versioning should be avoided
9295eca46af7Smrg	if test yes,no = "$avoid_version,$need_version"; then
92962378475aSmrg	  major=
92972378475aSmrg	  versuffix=
9298eca46af7Smrg	  verstring=
92992378475aSmrg	fi
93002378475aSmrg
93012378475aSmrg	# Check to see if the archive will have undefined symbols.
9302eca46af7Smrg	if test yes = "$allow_undefined"; then
9303eca46af7Smrg	  if test unsupported = "$allow_undefined_flag"; then
9304eca46af7Smrg	    if test yes = "$build_old_libs"; then
9305eca46af7Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306eca46af7Smrg	      build_libtool_libs=no
9307eca46af7Smrg	    else
9308eca46af7Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309eca46af7Smrg	    fi
93102378475aSmrg	  fi
93112378475aSmrg	else
93122378475aSmrg	  # Don't allow undefined symbols.
9313eca46af7Smrg	  allow_undefined_flag=$no_undefined_flag
93142378475aSmrg	fi
93152378475aSmrg
93162378475aSmrg      fi
93172378475aSmrg
9318eca46af7Smrg      func_generate_dlsyms "$libname" "$libname" :
931914330f12Smrg      func_append libobjs " $symfileobj"
9320eca46af7Smrg      test " " = "$libobjs" && libobjs=
93212378475aSmrg
9322eca46af7Smrg      if test relink != "$opt_mode"; then
93232378475aSmrg	# Remove our outputs, but don't remove object files since they
93242378475aSmrg	# may have been created when compiling PIC objects.
93252378475aSmrg	removelist=
93262378475aSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
93272378475aSmrg	for p in $tempremovelist; do
93282378475aSmrg	  case $p in
93292378475aSmrg	    *.$objext | *.gcno)
93302378475aSmrg	       ;;
9331eca46af7Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332eca46af7Smrg	       if test -n "$precious_files_regex"; then
93332378475aSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
93342378475aSmrg		 then
93352378475aSmrg		   continue
93362378475aSmrg		 fi
93372378475aSmrg	       fi
933814330f12Smrg	       func_append removelist " $p"
93392378475aSmrg	       ;;
93402378475aSmrg	    *) ;;
93412378475aSmrg	  esac
93422378475aSmrg	done
93432378475aSmrg	test -n "$removelist" && \
93442378475aSmrg	  func_show_eval "${RM}r \$removelist"
93452378475aSmrg      fi
93462378475aSmrg
93472378475aSmrg      # Now set the variables for building old libraries.
9348eca46af7Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
934914330f12Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
93502378475aSmrg
93512378475aSmrg	# Transform .lo files to .o files.
9352eca46af7Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
93532378475aSmrg      fi
93542378475aSmrg
93552378475aSmrg      # Eliminate all temporary directories.
93562378475aSmrg      #for path in $notinst_path; do
935714330f12Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
935814330f12Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
935914330f12Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
93602378475aSmrg      #done
93612378475aSmrg
93622378475aSmrg      if test -n "$xrpath"; then
93632378475aSmrg	# If the user specified any rpath flags, then add them.
93642378475aSmrg	temp_xrpath=
93652378475aSmrg	for libdir in $xrpath; do
936614330f12Smrg	  func_replace_sysroot "$libdir"
936714330f12Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
93682378475aSmrg	  case "$finalize_rpath " in
93692378475aSmrg	  *" $libdir "*) ;;
937014330f12Smrg	  *) func_append finalize_rpath " $libdir" ;;
93712378475aSmrg	  esac
93722378475aSmrg	done
9373eca46af7Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
93742378475aSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
93752378475aSmrg	fi
93762378475aSmrg      fi
93772378475aSmrg
93782378475aSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379eca46af7Smrg      old_dlfiles=$dlfiles
93802378475aSmrg      dlfiles=
93812378475aSmrg      for lib in $old_dlfiles; do
93822378475aSmrg	case " $dlprefiles $dlfiles " in
93832378475aSmrg	*" $lib "*) ;;
938414330f12Smrg	*) func_append dlfiles " $lib" ;;
93852378475aSmrg	esac
93862378475aSmrg      done
93872378475aSmrg
93882378475aSmrg      # Make sure dlprefiles contains only unique files
9389eca46af7Smrg      old_dlprefiles=$dlprefiles
93902378475aSmrg      dlprefiles=
93912378475aSmrg      for lib in $old_dlprefiles; do
93922378475aSmrg	case "$dlprefiles " in
93932378475aSmrg	*" $lib "*) ;;
939414330f12Smrg	*) func_append dlprefiles " $lib" ;;
93952378475aSmrg	esac
93962378475aSmrg      done
93972378475aSmrg
9398eca46af7Smrg      if test yes = "$build_libtool_libs"; then
93992378475aSmrg	if test -n "$rpath"; then
94002378475aSmrg	  case $host in
940114330f12Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
94022378475aSmrg	    # these systems don't actually have a c library (as such)!
94032378475aSmrg	    ;;
94042378475aSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
94052378475aSmrg	    # Rhapsody C library is in the System framework
940614330f12Smrg	    func_append deplibs " System.ltframework"
94072378475aSmrg	    ;;
94082378475aSmrg	  *-*-netbsd*)
94092378475aSmrg	    # Don't link with libc until the a.out ld.so is fixed.
94102378475aSmrg	    ;;
9411d87a3195Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
94122378475aSmrg	    # Do not include libc due to us having libc/libc_r.
94132378475aSmrg	    ;;
94142378475aSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
94152378475aSmrg	    # Causes problems with __ctype
94162378475aSmrg	    ;;
94172378475aSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
94182378475aSmrg	    # Compiler inserts libc in the correct place for threads to work
94192378475aSmrg	    ;;
94202378475aSmrg	  *)
94212378475aSmrg	    # Add libc to deplibs on all other systems if necessary.
9422eca46af7Smrg	    if test yes = "$build_libtool_need_lc"; then
942314330f12Smrg	      func_append deplibs " -lc"
94242378475aSmrg	    fi
94252378475aSmrg	    ;;
94262378475aSmrg	  esac
94272378475aSmrg	fi
94282378475aSmrg
94292378475aSmrg	# Transform deplibs into only deplibs that can be linked in shared.
94302378475aSmrg	name_save=$name
94312378475aSmrg	libname_save=$libname
94322378475aSmrg	release_save=$release
94332378475aSmrg	versuffix_save=$versuffix
94342378475aSmrg	major_save=$major
94352378475aSmrg	# I'm not sure if I'm treating the release correctly.  I think
94362378475aSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
94372378475aSmrg	# add it in twice.  Is that correct?
9438eca46af7Smrg	release=
9439eca46af7Smrg	versuffix=
9440eca46af7Smrg	major=
94412378475aSmrg	newdeplibs=
94422378475aSmrg	droppeddeps=no
94432378475aSmrg	case $deplibs_check_method in
94442378475aSmrg	pass_all)
94452378475aSmrg	  # Don't check for shared/static.  Everything works.
94462378475aSmrg	  # This might be a little naive.  We might want to check
94472378475aSmrg	  # whether the library exists or not.  But this is on
94482378475aSmrg	  # osf3 & osf4 and I'm not really sure... Just
94492378475aSmrg	  # implementing what was already the behavior.
94502378475aSmrg	  newdeplibs=$deplibs
94512378475aSmrg	  ;;
94522378475aSmrg	test_compile)
94532378475aSmrg	  # This code stresses the "libraries are programs" paradigm to its
94542378475aSmrg	  # limits. Maybe even breaks it.  We compile a program, linking it
94552378475aSmrg	  # against the deplibs as a proxy for the library.  Then we can check
94562378475aSmrg	  # whether they linked in statically or dynamically with ldd.
94572378475aSmrg	  $opt_dry_run || $RM conftest.c
94582378475aSmrg	  cat > conftest.c <<EOF
94592378475aSmrg	  int main() { return 0; }
94602378475aSmrgEOF
94612378475aSmrg	  $opt_dry_run || $RM conftest
94622378475aSmrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
94632378475aSmrg	    ldd_output=`ldd conftest`
94642378475aSmrg	    for i in $deplibs; do
94652378475aSmrg	      case $i in
94662378475aSmrg	      -l*)
94672378475aSmrg		func_stripname -l '' "$i"
94682378475aSmrg		name=$func_stripname_result
9469eca46af7Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94702378475aSmrg		  case " $predeps $postdeps " in
94712378475aSmrg		  *" $i "*)
947214330f12Smrg		    func_append newdeplibs " $i"
9473eca46af7Smrg		    i=
94742378475aSmrg		    ;;
94752378475aSmrg		  esac
94762378475aSmrg		fi
9477eca46af7Smrg		if test -n "$i"; then
94782378475aSmrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
94792378475aSmrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
94802378475aSmrg		  set dummy $deplib_matches; shift
94812378475aSmrg		  deplib_match=$1
9482eca46af7Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
948314330f12Smrg		    func_append newdeplibs " $i"
94842378475aSmrg		  else
94852378475aSmrg		    droppeddeps=yes
948614330f12Smrg		    echo
94872378475aSmrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
948814330f12Smrg		    echo "*** I have the capability to make that library automatically link in when"
948914330f12Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
949014330f12Smrg		    echo "*** shared version of the library, which I believe you do not have"
949114330f12Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
949214330f12Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
94932378475aSmrg		  fi
94942378475aSmrg		fi
94952378475aSmrg		;;
94962378475aSmrg	      *)
949714330f12Smrg		func_append newdeplibs " $i"
94982378475aSmrg		;;
94992378475aSmrg	      esac
95002378475aSmrg	    done
95012378475aSmrg	  else
95022378475aSmrg	    # Error occurred in the first compile.  Let's try to salvage
95032378475aSmrg	    # the situation: Compile a separate program for each library.
95042378475aSmrg	    for i in $deplibs; do
95052378475aSmrg	      case $i in
95062378475aSmrg	      -l*)
95072378475aSmrg		func_stripname -l '' "$i"
95082378475aSmrg		name=$func_stripname_result
95092378475aSmrg		$opt_dry_run || $RM conftest
95102378475aSmrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
95112378475aSmrg		  ldd_output=`ldd conftest`
9512eca46af7Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95132378475aSmrg		    case " $predeps $postdeps " in
95142378475aSmrg		    *" $i "*)
951514330f12Smrg		      func_append newdeplibs " $i"
9516eca46af7Smrg		      i=
95172378475aSmrg		      ;;
95182378475aSmrg		    esac
95192378475aSmrg		  fi
9520eca46af7Smrg		  if test -n "$i"; then
95212378475aSmrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
95222378475aSmrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
95232378475aSmrg		    set dummy $deplib_matches; shift
95242378475aSmrg		    deplib_match=$1
9525eca46af7Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
952614330f12Smrg		      func_append newdeplibs " $i"
95272378475aSmrg		    else
95282378475aSmrg		      droppeddeps=yes
952914330f12Smrg		      echo
95302378475aSmrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
953114330f12Smrg		      echo "*** I have the capability to make that library automatically link in when"
953214330f12Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
953314330f12Smrg		      echo "*** shared version of the library, which you do not appear to have"
953414330f12Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
953514330f12Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
95362378475aSmrg		    fi
95372378475aSmrg		  fi
95382378475aSmrg		else
95392378475aSmrg		  droppeddeps=yes
954014330f12Smrg		  echo
95412378475aSmrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
954214330f12Smrg		  echo "*** make it link in!  You will probably need to install it or some"
954314330f12Smrg		  echo "*** library that it depends on before this library will be fully"
954414330f12Smrg		  echo "*** functional.  Installing it before continuing would be even better."
95452378475aSmrg		fi
95462378475aSmrg		;;
95472378475aSmrg	      *)
954814330f12Smrg		func_append newdeplibs " $i"
95492378475aSmrg		;;
95502378475aSmrg	      esac
95512378475aSmrg	    done
95522378475aSmrg	  fi
95532378475aSmrg	  ;;
95542378475aSmrg	file_magic*)
95552378475aSmrg	  set dummy $deplibs_check_method; shift
95562378475aSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
95572378475aSmrg	  for a_deplib in $deplibs; do
95582378475aSmrg	    case $a_deplib in
95592378475aSmrg	    -l*)
95602378475aSmrg	      func_stripname -l '' "$a_deplib"
95612378475aSmrg	      name=$func_stripname_result
9562eca46af7Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95632378475aSmrg		case " $predeps $postdeps " in
95642378475aSmrg		*" $a_deplib "*)
956514330f12Smrg		  func_append newdeplibs " $a_deplib"
9566eca46af7Smrg		  a_deplib=
95672378475aSmrg		  ;;
95682378475aSmrg		esac
95692378475aSmrg	      fi
9570eca46af7Smrg	      if test -n "$a_deplib"; then
95712378475aSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
957214330f12Smrg		if test -n "$file_magic_glob"; then
957314330f12Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
957414330f12Smrg		else
957514330f12Smrg		  libnameglob=$libname
957614330f12Smrg		fi
9577eca46af7Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
95782378475aSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579eca46af7Smrg		  if test yes = "$want_nocaseglob"; then
958014330f12Smrg		    shopt -s nocaseglob
958114330f12Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958214330f12Smrg		    $nocaseglob
958314330f12Smrg		  else
958414330f12Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958514330f12Smrg		  fi
95862378475aSmrg		  for potent_lib in $potential_libs; do
95872378475aSmrg		      # Follow soft links.
95882378475aSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
95892378475aSmrg			 $GREP " -> " >/dev/null; then
95902378475aSmrg			continue
95912378475aSmrg		      fi
95922378475aSmrg		      # The statement above tries to avoid entering an
95932378475aSmrg		      # endless loop below, in case of cyclic links.
95942378475aSmrg		      # We might still enter an endless loop, since a link
95952378475aSmrg		      # loop can be closed while we follow links,
95962378475aSmrg		      # but so what?
9597eca46af7Smrg		      potlib=$potent_lib
95982378475aSmrg		      while test -h "$potlib" 2>/dev/null; do
9599eca46af7Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
96002378475aSmrg			case $potliblink in
9601eca46af7Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602eca46af7Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
96032378475aSmrg			esac
96042378475aSmrg		      done
96052378475aSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
96062378475aSmrg			 $SED -e 10q |
96072378475aSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
960814330f12Smrg			func_append newdeplibs " $a_deplib"
9609eca46af7Smrg			a_deplib=
96102378475aSmrg			break 2
96112378475aSmrg		      fi
96122378475aSmrg		  done
96132378475aSmrg		done
96142378475aSmrg	      fi
9615eca46af7Smrg	      if test -n "$a_deplib"; then
96162378475aSmrg		droppeddeps=yes
961714330f12Smrg		echo
96182378475aSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
961914330f12Smrg		echo "*** I have the capability to make that library automatically link in when"
962014330f12Smrg		echo "*** you link to this library.  But I can only do this if you have a"
962114330f12Smrg		echo "*** shared version of the library, which you do not appear to have"
962214330f12Smrg		echo "*** because I did check the linker path looking for a file starting"
9623eca46af7Smrg		if test -z "$potlib"; then
96242378475aSmrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
96252378475aSmrg		else
96262378475aSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96272378475aSmrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
96282378475aSmrg		fi
96292378475aSmrg	      fi
96302378475aSmrg	      ;;
96312378475aSmrg	    *)
96322378475aSmrg	      # Add a -L argument.
963314330f12Smrg	      func_append newdeplibs " $a_deplib"
96342378475aSmrg	      ;;
96352378475aSmrg	    esac
96362378475aSmrg	  done # Gone through all deplibs.
96372378475aSmrg	  ;;
96382378475aSmrg	match_pattern*)
96392378475aSmrg	  set dummy $deplibs_check_method; shift
96402378475aSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
96412378475aSmrg	  for a_deplib in $deplibs; do
96422378475aSmrg	    case $a_deplib in
96432378475aSmrg	    -l*)
96442378475aSmrg	      func_stripname -l '' "$a_deplib"
96452378475aSmrg	      name=$func_stripname_result
9646eca46af7Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96472378475aSmrg		case " $predeps $postdeps " in
96482378475aSmrg		*" $a_deplib "*)
964914330f12Smrg		  func_append newdeplibs " $a_deplib"
9650eca46af7Smrg		  a_deplib=
96512378475aSmrg		  ;;
96522378475aSmrg		esac
96532378475aSmrg	      fi
9654eca46af7Smrg	      if test -n "$a_deplib"; then
96552378475aSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
96562378475aSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
96572378475aSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
96582378475aSmrg		  for potent_lib in $potential_libs; do
9659eca46af7Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
966014330f12Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
96612378475aSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
966214330f12Smrg		      func_append newdeplibs " $a_deplib"
9663eca46af7Smrg		      a_deplib=
96642378475aSmrg		      break 2
96652378475aSmrg		    fi
96662378475aSmrg		  done
96672378475aSmrg		done
96682378475aSmrg	      fi
9669eca46af7Smrg	      if test -n "$a_deplib"; then
96702378475aSmrg		droppeddeps=yes
967114330f12Smrg		echo
96722378475aSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
967314330f12Smrg		echo "*** I have the capability to make that library automatically link in when"
967414330f12Smrg		echo "*** you link to this library.  But I can only do this if you have a"
967514330f12Smrg		echo "*** shared version of the library, which you do not appear to have"
967614330f12Smrg		echo "*** because I did check the linker path looking for a file starting"
9677eca46af7Smrg		if test -z "$potlib"; then
96782378475aSmrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
96792378475aSmrg		else
96802378475aSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96812378475aSmrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
96822378475aSmrg		fi
96832378475aSmrg	      fi
96842378475aSmrg	      ;;
96852378475aSmrg	    *)
96862378475aSmrg	      # Add a -L argument.
968714330f12Smrg	      func_append newdeplibs " $a_deplib"
96882378475aSmrg	      ;;
96892378475aSmrg	    esac
96902378475aSmrg	  done # Gone through all deplibs.
96912378475aSmrg	  ;;
96922378475aSmrg	none | unknown | *)
9693eca46af7Smrg	  newdeplibs=
969414330f12Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695eca46af7Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696eca46af7Smrg	    for i in $predeps $postdeps; do
96972378475aSmrg	      # can't use Xsed below, because $i might contain '/'
9698eca46af7Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
96992378475aSmrg	    done
97002378475aSmrg	  fi
970114330f12Smrg	  case $tmp_deplibs in
970214330f12Smrg	  *[!\	\ ]*)
970314330f12Smrg	    echo
9704eca46af7Smrg	    if test none = "$deplibs_check_method"; then
970514330f12Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
97062378475aSmrg	    else
970714330f12Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
97082378475aSmrg	    fi
970914330f12Smrg	    echo "*** All declared inter-library dependencies are being dropped."
97102378475aSmrg	    droppeddeps=yes
971114330f12Smrg	    ;;
971214330f12Smrg	  esac
97132378475aSmrg	  ;;
97142378475aSmrg	esac
97152378475aSmrg	versuffix=$versuffix_save
97162378475aSmrg	major=$major_save
97172378475aSmrg	release=$release_save
97182378475aSmrg	libname=$libname_save
97192378475aSmrg	name=$name_save
97202378475aSmrg
97212378475aSmrg	case $host in
97222378475aSmrg	*-*-rhapsody* | *-*-darwin1.[012])
97232378475aSmrg	  # On Rhapsody replace the C library with the System framework
972414330f12Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
97252378475aSmrg	  ;;
97262378475aSmrg	esac
97272378475aSmrg
9728eca46af7Smrg	if test yes = "$droppeddeps"; then
9729eca46af7Smrg	  if test yes = "$module"; then
973014330f12Smrg	    echo
973114330f12Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
97322378475aSmrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
973314330f12Smrg	    echo "*** a static module, that should work as long as the dlopening"
973414330f12Smrg	    echo "*** application is linked with the -dlopen flag."
97352378475aSmrg	    if test -z "$global_symbol_pipe"; then
973614330f12Smrg	      echo
973714330f12Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738eca46af7Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
973914330f12Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9740eca46af7Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
97412378475aSmrg	    fi
9742eca46af7Smrg	    if test no = "$build_old_libs"; then
9743eca46af7Smrg	      oldlibs=$output_objdir/$libname.$libext
97442378475aSmrg	      build_libtool_libs=module
97452378475aSmrg	      build_old_libs=yes
97462378475aSmrg	    else
97472378475aSmrg	      build_libtool_libs=no
97482378475aSmrg	    fi
97492378475aSmrg	  else
975014330f12Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
975114330f12Smrg	    echo "*** automatically added whenever a program is linked with this library"
975214330f12Smrg	    echo "*** or is declared to -dlopen it."
97532378475aSmrg
9754eca46af7Smrg	    if test no = "$allow_undefined"; then
975514330f12Smrg	      echo
975614330f12Smrg	      echo "*** Since this library must not contain undefined symbols,"
975714330f12Smrg	      echo "*** because either the platform does not support them or"
975814330f12Smrg	      echo "*** it was explicitly requested with -no-undefined,"
975914330f12Smrg	      echo "*** libtool will only create a static version of it."
9760eca46af7Smrg	      if test no = "$build_old_libs"; then
9761eca46af7Smrg		oldlibs=$output_objdir/$libname.$libext
97622378475aSmrg		build_libtool_libs=module
97632378475aSmrg		build_old_libs=yes
97642378475aSmrg	      else
97652378475aSmrg		build_libtool_libs=no
97662378475aSmrg	      fi
97672378475aSmrg	    fi
97682378475aSmrg	  fi
97692378475aSmrg	fi
97702378475aSmrg	# Done checking deplibs!
97712378475aSmrg	deplibs=$newdeplibs
97722378475aSmrg      fi
97732378475aSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
97742378475aSmrg      case $host in
97752378475aSmrg	*-*-darwin*)
977614330f12Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977714330f12Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977814330f12Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97792378475aSmrg	  ;;
97802378475aSmrg      esac
97812378475aSmrg
97822378475aSmrg      # move library search paths that coincide with paths to not yet
97832378475aSmrg      # installed libraries to the beginning of the library search list
97842378475aSmrg      new_libs=
97852378475aSmrg      for path in $notinst_path; do
97862378475aSmrg	case " $new_libs " in
97872378475aSmrg	*" -L$path/$objdir "*) ;;
97882378475aSmrg	*)
97892378475aSmrg	  case " $deplibs " in
97902378475aSmrg	  *" -L$path/$objdir "*)
979114330f12Smrg	    func_append new_libs " -L$path/$objdir" ;;
97922378475aSmrg	  esac
97932378475aSmrg	  ;;
97942378475aSmrg	esac
97952378475aSmrg      done
97962378475aSmrg      for deplib in $deplibs; do
97972378475aSmrg	case $deplib in
97982378475aSmrg	-L*)
97992378475aSmrg	  case " $new_libs " in
98002378475aSmrg	  *" $deplib "*) ;;
980114330f12Smrg	  *) func_append new_libs " $deplib" ;;
98022378475aSmrg	  esac
98032378475aSmrg	  ;;
980414330f12Smrg	*) func_append new_libs " $deplib" ;;
98052378475aSmrg	esac
98062378475aSmrg      done
9807eca46af7Smrg      deplibs=$new_libs
98082378475aSmrg
98092378475aSmrg      # All the library-specific variables (install_libdir is set above).
98102378475aSmrg      library_names=
98112378475aSmrg      old_library=
98122378475aSmrg      dlname=
98132378475aSmrg
98142378475aSmrg      # Test again, we may have decided not to build it any more
9815eca46af7Smrg      if test yes = "$build_libtool_libs"; then
9816eca46af7Smrg	# Remove $wl instances when linking with ld.
9817eca46af7Smrg	# FIXME: should test the right _cmds variable.
9818eca46af7Smrg	case $archive_cmds in
9819eca46af7Smrg	  *\$LD\ *) wl= ;;
9820eca46af7Smrg        esac
9821eca46af7Smrg	if test yes = "$hardcode_into_libs"; then
98222378475aSmrg	  # Hardcode the library paths
98232378475aSmrg	  hardcode_libdirs=
98242378475aSmrg	  dep_rpath=
9825eca46af7Smrg	  rpath=$finalize_rpath
9826eca46af7Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
98272378475aSmrg	  for libdir in $rpath; do
98282378475aSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
98292378475aSmrg	      if test -n "$hardcode_libdir_separator"; then
983014330f12Smrg		func_replace_sysroot "$libdir"
983114330f12Smrg		libdir=$func_replace_sysroot_result
98322378475aSmrg		if test -z "$hardcode_libdirs"; then
9833eca46af7Smrg		  hardcode_libdirs=$libdir
98342378475aSmrg		else
98352378475aSmrg		  # Just accumulate the unique libdirs.
98362378475aSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
98372378475aSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
98382378475aSmrg		    ;;
98392378475aSmrg		  *)
984014330f12Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
98412378475aSmrg		    ;;
98422378475aSmrg		  esac
98432378475aSmrg		fi
98442378475aSmrg	      else
98452378475aSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
984614330f12Smrg		func_append dep_rpath " $flag"
98472378475aSmrg	      fi
98482378475aSmrg	    elif test -n "$runpath_var"; then
98492378475aSmrg	      case "$perm_rpath " in
98502378475aSmrg	      *" $libdir "*) ;;
9851eca46af7Smrg	      *) func_append perm_rpath " $libdir" ;;
98522378475aSmrg	      esac
98532378475aSmrg	    fi
98542378475aSmrg	  done
98552378475aSmrg	  # Substitute the hardcoded libdirs into the rpath.
98562378475aSmrg	  if test -n "$hardcode_libdir_separator" &&
98572378475aSmrg	     test -n "$hardcode_libdirs"; then
9858eca46af7Smrg	    libdir=$hardcode_libdirs
9859eca46af7Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
98602378475aSmrg	  fi
98612378475aSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
98622378475aSmrg	    # We should set the runpath_var.
98632378475aSmrg	    rpath=
98642378475aSmrg	    for dir in $perm_rpath; do
986514330f12Smrg	      func_append rpath "$dir:"
98662378475aSmrg	    done
98672378475aSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
98682378475aSmrg	  fi
98692378475aSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
98702378475aSmrg	fi
987195b296d0Smrg
9872eca46af7Smrg	shlibpath=$finalize_shlibpath
9873eca46af7Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
98742378475aSmrg	if test -n "$shlibpath"; then
98752378475aSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
98762378475aSmrg	fi
987795b296d0Smrg
98782378475aSmrg	# Get the real and link names of the library.
98792378475aSmrg	eval shared_ext=\"$shrext_cmds\"
98802378475aSmrg	eval library_names=\"$library_names_spec\"
98812378475aSmrg	set dummy $library_names
98822378475aSmrg	shift
9883eca46af7Smrg	realname=$1
98842378475aSmrg	shift
988595b296d0Smrg
98862378475aSmrg	if test -n "$soname_spec"; then
98872378475aSmrg	  eval soname=\"$soname_spec\"
98882378475aSmrg	else
9889eca46af7Smrg	  soname=$realname
98902378475aSmrg	fi
98912378475aSmrg	if test -z "$dlname"; then
98922378475aSmrg	  dlname=$soname
98932378475aSmrg	fi
989495b296d0Smrg
9895eca46af7Smrg	lib=$output_objdir/$realname
98962378475aSmrg	linknames=
98972378475aSmrg	for link
98982378475aSmrg	do
989914330f12Smrg	  func_append linknames " $link"
99002378475aSmrg	done
990195b296d0Smrg
99022378475aSmrg	# Use standard objects if they are pic
990314330f12Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
99042378475aSmrg	test "X$libobjs" = "X " && libobjs=
990595b296d0Smrg
99062378475aSmrg	delfiles=
99072378475aSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99082378475aSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909eca46af7Smrg	  export_symbols=$output_objdir/$libname.uexp
991014330f12Smrg	  func_append delfiles " $export_symbols"
99112378475aSmrg	fi
991295b296d0Smrg
99132378475aSmrg	orig_export_symbols=
99142378475aSmrg	case $host_os in
99152378475aSmrg	cygwin* | mingw* | cegcc*)
99162378475aSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
99172378475aSmrg	    # exporting using user supplied symfile
9918eca46af7Smrg	    func_dll_def_p "$export_symbols" || {
99192378475aSmrg	      # and it's NOT already a .def file. Must figure out
99202378475aSmrg	      # which of the given symbols are data symbols and tag
99212378475aSmrg	      # them as such. So, trigger use of export_symbols_cmds.
99222378475aSmrg	      # export_symbols gets reassigned inside the "prepare
99232378475aSmrg	      # the list of exported symbols" if statement, so the
99242378475aSmrg	      # include_expsyms logic still works.
9925eca46af7Smrg	      orig_export_symbols=$export_symbols
99262378475aSmrg	      export_symbols=
99272378475aSmrg	      always_export_symbols=yes
9928eca46af7Smrg	    }
99292378475aSmrg	  fi
99302378475aSmrg	  ;;
99312378475aSmrg	esac
993295b296d0Smrg
99332378475aSmrg	# Prepare the list of exported symbols
99342378475aSmrg	if test -z "$export_symbols"; then
9935eca46af7Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936eca46af7Smrg	    func_verbose "generating symbol list for '$libname.la'"
9937eca46af7Smrg	    export_symbols=$output_objdir/$libname.exp
99382378475aSmrg	    $opt_dry_run || $RM $export_symbols
99392378475aSmrg	    cmds=$export_symbols_cmds
9940eca46af7Smrg	    save_ifs=$IFS; IFS='~'
994114330f12Smrg	    for cmd1 in $cmds; do
9942eca46af7Smrg	      IFS=$save_ifs
994314330f12Smrg	      # Take the normal branch if the nm_file_list_spec branch
994414330f12Smrg	      # doesn't work or if tool conversion is not needed.
994514330f12Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
994614330f12Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
994714330f12Smrg		  try_normal_branch=yes
994814330f12Smrg		  eval cmd=\"$cmd1\"
994914330f12Smrg		  func_len " $cmd"
995014330f12Smrg		  len=$func_len_result
995114330f12Smrg		  ;;
995214330f12Smrg		*)
995314330f12Smrg		  try_normal_branch=no
995414330f12Smrg		  ;;
995514330f12Smrg	      esac
9956eca46af7Smrg	      if test yes = "$try_normal_branch" \
995714330f12Smrg		 && { test "$len" -lt "$max_cmd_len" \
995814330f12Smrg		      || test "$max_cmd_len" -le -1; }
995914330f12Smrg	      then
996014330f12Smrg		func_show_eval "$cmd" 'exit $?'
996114330f12Smrg		skipped_export=false
996214330f12Smrg	      elif test -n "$nm_file_list_spec"; then
996314330f12Smrg		func_basename "$output"
996414330f12Smrg		output_la=$func_basename_result
996514330f12Smrg		save_libobjs=$libobjs
996614330f12Smrg		save_output=$output
9967eca46af7Smrg		output=$output_objdir/$output_la.nm
996814330f12Smrg		func_to_tool_file "$output"
996914330f12Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
997014330f12Smrg		func_append delfiles " $output"
997114330f12Smrg		func_verbose "creating $NM input file list: $output"
997214330f12Smrg		for obj in $save_libobjs; do
997314330f12Smrg		  func_to_tool_file "$obj"
997414330f12Smrg		  $ECHO "$func_to_tool_file_result"
997514330f12Smrg		done > "$output"
997614330f12Smrg		eval cmd=\"$cmd1\"
99772378475aSmrg		func_show_eval "$cmd" 'exit $?'
997814330f12Smrg		output=$save_output
997914330f12Smrg		libobjs=$save_libobjs
99802378475aSmrg		skipped_export=false
99812378475aSmrg	      else
99822378475aSmrg		# The command line is too long to execute in one step.
99832378475aSmrg		func_verbose "using reloadable object file for export list..."
99842378475aSmrg		skipped_export=:
99852378475aSmrg		# Break out early, otherwise skipped_export may be
99862378475aSmrg		# set to false by a later but shorter cmd.
99872378475aSmrg		break
99882378475aSmrg	      fi
99892378475aSmrg	    done
9990eca46af7Smrg	    IFS=$save_ifs
9991eca46af7Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
99922378475aSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
99932378475aSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
99942378475aSmrg	    fi
99952378475aSmrg	  fi
999695b296d0Smrg	fi
999795b296d0Smrg
99982378475aSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999eca46af7Smrg	  tmp_export_symbols=$export_symbols
10000eca46af7Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1000114330f12Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
100022378475aSmrg	fi
1000395b296d0Smrg
10004eca46af7Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
100052378475aSmrg	  # The given exports_symbols file has to be filtered, so filter it.
10006eca46af7Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
100072378475aSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008eca46af7Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
100092378475aSmrg	  # though. Also, the filter scales superlinearly with the number of
100102378475aSmrg	  # global variables. join(1) would be nice here, but unfortunately
100112378475aSmrg	  # isn't a blessed tool.
100122378475aSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1001314330f12Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
100142378475aSmrg	  export_symbols=$output_objdir/$libname.def
100152378475aSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
100162378475aSmrg	fi
1001795b296d0Smrg
100182378475aSmrg	tmp_deplibs=
100192378475aSmrg	for test_deplib in $deplibs; do
100202378475aSmrg	  case " $convenience " in
100212378475aSmrg	  *" $test_deplib "*) ;;
100222378475aSmrg	  *)
1002314330f12Smrg	    func_append tmp_deplibs " $test_deplib"
100242378475aSmrg	    ;;
100252378475aSmrg	  esac
100262378475aSmrg	done
10027eca46af7Smrg	deplibs=$tmp_deplibs
1002895b296d0Smrg
100292378475aSmrg	if test -n "$convenience"; then
100302378475aSmrg	  if test -n "$whole_archive_flag_spec" &&
10031eca46af7Smrg	    test yes = "$compiler_needs_object" &&
100322378475aSmrg	    test -z "$libobjs"; then
100332378475aSmrg	    # extract the archives, so we have objects to list.
100342378475aSmrg	    # TODO: could optimize this to just extract one archive.
100352378475aSmrg	    whole_archive_flag_spec=
100362378475aSmrg	  fi
100372378475aSmrg	  if test -n "$whole_archive_flag_spec"; then
100382378475aSmrg	    save_libobjs=$libobjs
100392378475aSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
100402378475aSmrg	    test "X$libobjs" = "X " && libobjs=
100412378475aSmrg	  else
10042eca46af7Smrg	    gentop=$output_objdir/${outputname}x
1004314330f12Smrg	    func_append generated " $gentop"
1004495b296d0Smrg
100452378475aSmrg	    func_extract_archives $gentop $convenience
1004614330f12Smrg	    func_append libobjs " $func_extract_archives_result"
100472378475aSmrg	    test "X$libobjs" = "X " && libobjs=
100482378475aSmrg	  fi
10049e6f085baSmrg	fi
1005095b296d0Smrg
10051eca46af7Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
100522378475aSmrg	  eval flag=\"$thread_safe_flag_spec\"
1005314330f12Smrg	  func_append linker_flags " $flag"
10054e6f085baSmrg	fi
1005539713583Smrg
100562378475aSmrg	# Make a backup of the uninstalled library when relinking
10057eca46af7Smrg	if test relink = "$opt_mode"; then
100582378475aSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
100592378475aSmrg	fi
1006095b296d0Smrg
100612378475aSmrg	# Do each of the archive commands.
10062eca46af7Smrg	if test yes = "$module" && test -n "$module_cmds"; then
100632378475aSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
100642378475aSmrg	    eval test_cmds=\"$module_expsym_cmds\"
100652378475aSmrg	    cmds=$module_expsym_cmds
100662378475aSmrg	  else
100672378475aSmrg	    eval test_cmds=\"$module_cmds\"
100682378475aSmrg	    cmds=$module_cmds
100692378475aSmrg	  fi
10070e6f085baSmrg	else
100712378475aSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
100722378475aSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
100732378475aSmrg	    cmds=$archive_expsym_cmds
100742378475aSmrg	  else
100752378475aSmrg	    eval test_cmds=\"$archive_cmds\"
100762378475aSmrg	    cmds=$archive_cmds
100772378475aSmrg	  fi
10078e6f085baSmrg	fi
1007995b296d0Smrg
10080eca46af7Smrg	if test : != "$skipped_export" &&
100812378475aSmrg	   func_len " $test_cmds" &&
100822378475aSmrg	   len=$func_len_result &&
100832378475aSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
100842378475aSmrg	  :
100852378475aSmrg	else
100862378475aSmrg	  # The command line is too long to link in one step, link piecewise
100872378475aSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
100882378475aSmrg	  # script.
1008995b296d0Smrg
100902378475aSmrg	  # Save the value of $output and $libobjs because we want to
100912378475aSmrg	  # use them later.  If we have whole_archive_flag_spec, we
100922378475aSmrg	  # want to use save_libobjs as it was before
100932378475aSmrg	  # whole_archive_flag_spec was expanded, because we can't
100942378475aSmrg	  # assume the linker understands whole_archive_flag_spec.
100952378475aSmrg	  # This may have to be revisited, in case too many
100962378475aSmrg	  # convenience libraries get linked in and end up exceeding
100972378475aSmrg	  # the spec.
100982378475aSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
100992378475aSmrg	    save_libobjs=$libobjs
101002378475aSmrg	  fi
101012378475aSmrg	  save_output=$output
1010214330f12Smrg	  func_basename "$output"
1010314330f12Smrg	  output_la=$func_basename_result
1010495b296d0Smrg
101052378475aSmrg	  # Clear the reloadable object creation command queue and
101062378475aSmrg	  # initialize k to one.
101072378475aSmrg	  test_cmds=
101082378475aSmrg	  concat_cmds=
101092378475aSmrg	  objlist=
101102378475aSmrg	  last_robj=
101112378475aSmrg	  k=1
101122378475aSmrg
10113eca46af7Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114eca46af7Smrg	    output=$output_objdir/$output_la.lnkscript
101152378475aSmrg	    func_verbose "creating GNU ld script: $output"
1011614330f12Smrg	    echo 'INPUT (' > $output
101172378475aSmrg	    for obj in $save_libobjs
10118e6f085baSmrg	    do
1011914330f12Smrg	      func_to_tool_file "$obj"
1012014330f12Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101212378475aSmrg	    done
1012214330f12Smrg	    echo ')' >> $output
1012314330f12Smrg	    func_append delfiles " $output"
1012414330f12Smrg	    func_to_tool_file "$output"
1012514330f12Smrg	    output=$func_to_tool_file_result
10126eca46af7Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127eca46af7Smrg	    output=$output_objdir/$output_la.lnk
101282378475aSmrg	    func_verbose "creating linker input file list: $output"
101292378475aSmrg	    : > $output
101302378475aSmrg	    set x $save_libobjs
101312378475aSmrg	    shift
101322378475aSmrg	    firstobj=
10133eca46af7Smrg	    if test yes = "$compiler_needs_object"; then
101342378475aSmrg	      firstobj="$1 "
101352378475aSmrg	      shift
101362378475aSmrg	    fi
101372378475aSmrg	    for obj
101382378475aSmrg	    do
1013914330f12Smrg	      func_to_tool_file "$obj"
1014014330f12Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101412378475aSmrg	    done
1014214330f12Smrg	    func_append delfiles " $output"
1014314330f12Smrg	    func_to_tool_file "$output"
1014414330f12Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
101452378475aSmrg	  else
101462378475aSmrg	    if test -n "$save_libobjs"; then
101472378475aSmrg	      func_verbose "creating reloadable object files..."
10148eca46af7Smrg	      output=$output_objdir/$output_la-$k.$objext
101492378475aSmrg	      eval test_cmds=\"$reload_cmds\"
101502378475aSmrg	      func_len " $test_cmds"
101512378475aSmrg	      len0=$func_len_result
101522378475aSmrg	      len=$len0
101532378475aSmrg
101542378475aSmrg	      # Loop over the list of objects to be linked.
101552378475aSmrg	      for obj in $save_libobjs
101562378475aSmrg	      do
101572378475aSmrg		func_len " $obj"
101582378475aSmrg		func_arith $len + $func_len_result
101592378475aSmrg		len=$func_arith_result
10160eca46af7Smrg		if test -z "$objlist" ||
101612378475aSmrg		   test "$len" -lt "$max_cmd_len"; then
101622378475aSmrg		  func_append objlist " $obj"
101632378475aSmrg		else
101642378475aSmrg		  # The command $test_cmds is almost too long, add a
101652378475aSmrg		  # command to the queue.
10166eca46af7Smrg		  if test 1 -eq "$k"; then
101672378475aSmrg		    # The first file doesn't have a previous command to add.
1016814330f12Smrg		    reload_objs=$objlist
1016914330f12Smrg		    eval concat_cmds=\"$reload_cmds\"
101702378475aSmrg		  else
101712378475aSmrg		    # All subsequent reloadable object files will link in
101722378475aSmrg		    # the last one created.
1017314330f12Smrg		    reload_objs="$objlist $last_robj"
1017414330f12Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
101752378475aSmrg		  fi
10176eca46af7Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
101772378475aSmrg		  func_arith $k + 1
101782378475aSmrg		  k=$func_arith_result
10179eca46af7Smrg		  output=$output_objdir/$output_la-$k.$objext
1018014330f12Smrg		  objlist=" $obj"
101812378475aSmrg		  func_len " $last_robj"
101822378475aSmrg		  func_arith $len0 + $func_len_result
101832378475aSmrg		  len=$func_arith_result
101842378475aSmrg		fi
101852378475aSmrg	      done
101862378475aSmrg	      # Handle the remaining objects by creating one last
101872378475aSmrg	      # reloadable object file.  All subsequent reloadable object
101882378475aSmrg	      # files will link in the last one created.
101892378475aSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1019014330f12Smrg	      reload_objs="$objlist $last_robj"
10191eca46af7Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
101922378475aSmrg	      if test -n "$last_robj"; then
10193eca46af7Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
101942378475aSmrg	      fi
1019514330f12Smrg	      func_append delfiles " $output"
1019695b296d0Smrg
101972378475aSmrg	    else
101982378475aSmrg	      output=
101992378475aSmrg	    fi
1020095b296d0Smrg
10201eca46af7Smrg	    ${skipped_export-false} && {
10202eca46af7Smrg	      func_verbose "generating symbol list for '$libname.la'"
10203eca46af7Smrg	      export_symbols=$output_objdir/$libname.exp
102042378475aSmrg	      $opt_dry_run || $RM $export_symbols
102052378475aSmrg	      libobjs=$output
102062378475aSmrg	      # Append the command to create the export file.
102072378475aSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
102082378475aSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
102092378475aSmrg	      if test -n "$last_robj"; then
102102378475aSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
102112378475aSmrg	      fi
10212eca46af7Smrg	    }
1021395b296d0Smrg
102142378475aSmrg	    test -n "$save_libobjs" &&
102152378475aSmrg	      func_verbose "creating a temporary reloadable object file: $output"
1021695b296d0Smrg
102172378475aSmrg	    # Loop through the commands generated above and execute them.
10218eca46af7Smrg	    save_ifs=$IFS; IFS='~'
102192378475aSmrg	    for cmd in $concat_cmds; do
10220eca46af7Smrg	      IFS=$save_ifs
10221eca46af7Smrg	      $opt_quiet || {
10222d87a3195Smrg		  func_quote_arg expand,pretty "$cmd"
10223d87a3195Smrg		  eval "func_echo $func_quote_arg_result"
102242378475aSmrg	      }
102252378475aSmrg	      $opt_dry_run || eval "$cmd" || {
102262378475aSmrg		lt_exit=$?
102272378475aSmrg
102282378475aSmrg		# Restore the uninstalled library and exit
10229eca46af7Smrg		if test relink = "$opt_mode"; then
102302378475aSmrg		  ( cd "$output_objdir" && \
102312378475aSmrg		    $RM "${realname}T" && \
102322378475aSmrg		    $MV "${realname}U" "$realname" )
102332378475aSmrg		fi
1023495b296d0Smrg
102352378475aSmrg		exit $lt_exit
102362378475aSmrg	      }
102372378475aSmrg	    done
10238eca46af7Smrg	    IFS=$save_ifs
10239e6f085baSmrg
102402378475aSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
102412378475aSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
102422378475aSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
1024395b296d0Smrg	    fi
1024495b296d0Smrg	  fi
1024595b296d0Smrg
10246eca46af7Smrg          ${skipped_export-false} && {
102472378475aSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248eca46af7Smrg	      tmp_export_symbols=$export_symbols
10249eca46af7Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1025014330f12Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
102512378475aSmrg	    fi
1025239713583Smrg
102532378475aSmrg	    if test -n "$orig_export_symbols"; then
102542378475aSmrg	      # The given exports_symbols file has to be filtered, so filter it.
10255eca46af7Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
102562378475aSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257eca46af7Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
102582378475aSmrg	      # though. Also, the filter scales superlinearly with the number of
102592378475aSmrg	      # global variables. join(1) would be nice here, but unfortunately
102602378475aSmrg	      # isn't a blessed tool.
102612378475aSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1026214330f12Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
102632378475aSmrg	      export_symbols=$output_objdir/$libname.def
102642378475aSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
102652378475aSmrg	    fi
10266eca46af7Smrg	  }
1026795b296d0Smrg
102682378475aSmrg	  libobjs=$output
102692378475aSmrg	  # Restore the value of output.
102702378475aSmrg	  output=$save_output
1027195b296d0Smrg
102722378475aSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
102732378475aSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
102742378475aSmrg	    test "X$libobjs" = "X " && libobjs=
102752378475aSmrg	  fi
102762378475aSmrg	  # Expand the library linking commands again to reset the
102772378475aSmrg	  # value of $libobjs for piecewise linking.
1027895b296d0Smrg
102792378475aSmrg	  # Do each of the archive commands.
10280eca46af7Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
102812378475aSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
102822378475aSmrg	      cmds=$module_expsym_cmds
102832378475aSmrg	    else
102842378475aSmrg	      cmds=$module_cmds
10285e6f085baSmrg	    fi
10286e6f085baSmrg	  else
102872378475aSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
102882378475aSmrg	      cmds=$archive_expsym_cmds
102892378475aSmrg	    else
102902378475aSmrg	      cmds=$archive_cmds
102912378475aSmrg	    fi
10292e6f085baSmrg	  fi
102932378475aSmrg	fi
1029495b296d0Smrg
102952378475aSmrg	if test -n "$delfiles"; then
102962378475aSmrg	  # Append the command to remove temporary files to $cmds.
102972378475aSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
102982378475aSmrg	fi
1029995b296d0Smrg
103002378475aSmrg	# Add any objects from preloaded convenience libraries
103012378475aSmrg	if test -n "$dlprefiles"; then
10302eca46af7Smrg	  gentop=$output_objdir/${outputname}x
1030314330f12Smrg	  func_append generated " $gentop"
1030495b296d0Smrg
103052378475aSmrg	  func_extract_archives $gentop $dlprefiles
1030614330f12Smrg	  func_append libobjs " $func_extract_archives_result"
103072378475aSmrg	  test "X$libobjs" = "X " && libobjs=
103082378475aSmrg	fi
1030995b296d0Smrg
10310eca46af7Smrg	save_ifs=$IFS; IFS='~'
103112378475aSmrg	for cmd in $cmds; do
10312eca46af7Smrg	  IFS=$sp$nl
103132378475aSmrg	  eval cmd=\"$cmd\"
10314eca46af7Smrg	  IFS=$save_ifs
10315eca46af7Smrg	  $opt_quiet || {
10316d87a3195Smrg	    func_quote_arg expand,pretty "$cmd"
10317d87a3195Smrg	    eval "func_echo $func_quote_arg_result"
103182378475aSmrg	  }
103192378475aSmrg	  $opt_dry_run || eval "$cmd" || {
103202378475aSmrg	    lt_exit=$?
1032139713583Smrg
103222378475aSmrg	    # Restore the uninstalled library and exit
10323eca46af7Smrg	    if test relink = "$opt_mode"; then
103242378475aSmrg	      ( cd "$output_objdir" && \
103252378475aSmrg	        $RM "${realname}T" && \
103262378475aSmrg		$MV "${realname}U" "$realname" )
103272378475aSmrg	    fi
1032839713583Smrg
103292378475aSmrg	    exit $lt_exit
103302378475aSmrg	  }
103312378475aSmrg	done
10332eca46af7Smrg	IFS=$save_ifs
1033339713583Smrg
103342378475aSmrg	# Restore the uninstalled library and exit
10335eca46af7Smrg	if test relink = "$opt_mode"; then
103362378475aSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
1033739713583Smrg
103382378475aSmrg	  if test -n "$convenience"; then
103392378475aSmrg	    if test -z "$whole_archive_flag_spec"; then
103402378475aSmrg	      func_show_eval '${RM}r "$gentop"'
103412378475aSmrg	    fi
103422378475aSmrg	  fi
1034339713583Smrg
103442378475aSmrg	  exit $EXIT_SUCCESS
103452378475aSmrg	fi
103462378475aSmrg
103472378475aSmrg	# Create links to the real library.
103482378475aSmrg	for linkname in $linknames; do
103492378475aSmrg	  if test "$realname" != "$linkname"; then
103502378475aSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351e6f085baSmrg	  fi
10352e6f085baSmrg	done
1035339713583Smrg
103542378475aSmrg	# If -module or -export-dynamic was specified, set the dlname.
10355eca46af7Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
103562378475aSmrg	  # On all known operating systems, these are identical.
10357eca46af7Smrg	  dlname=$soname
103582378475aSmrg	fi
103592378475aSmrg      fi
1036095b296d0Smrg      ;;
1036195b296d0Smrg
103622378475aSmrg    obj)
10363eca46af7Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364eca46af7Smrg	func_warning "'-dlopen' is ignored for objects"
103652378475aSmrg      fi
10366e6f085baSmrg
103672378475aSmrg      case " $deplibs" in
103682378475aSmrg      *\ -l* | *\ -L*)
10369eca46af7Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
1037039713583Smrg      esac
1037195b296d0Smrg
103722378475aSmrg      test -n "$rpath" && \
10373eca46af7Smrg	func_warning "'-rpath' is ignored for objects"
103742378475aSmrg
103752378475aSmrg      test -n "$xrpath" && \
10376eca46af7Smrg	func_warning "'-R' is ignored for objects"
1037795b296d0Smrg
103782378475aSmrg      test -n "$vinfo" && \
10379eca46af7Smrg	func_warning "'-version-info' is ignored for objects"
1038039713583Smrg
103812378475aSmrg      test -n "$release" && \
10382eca46af7Smrg	func_warning "'-release' is ignored for objects"
103832378475aSmrg
103842378475aSmrg      case $output in
103852378475aSmrg      *.lo)
103862378475aSmrg	test -n "$objs$old_deplibs" && \
10387eca46af7Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
103882378475aSmrg
103892378475aSmrg	libobj=$output
103902378475aSmrg	func_lo2o "$libobj"
103912378475aSmrg	obj=$func_lo2o_result
10392e6f085baSmrg	;;
10393e6f085baSmrg      *)
103942378475aSmrg	libobj=
10395eca46af7Smrg	obj=$output
1039695b296d0Smrg	;;
1039739713583Smrg      esac
1039895b296d0Smrg
103992378475aSmrg      # Delete the old objects.
104002378475aSmrg      $opt_dry_run || $RM $obj $libobj
1040195b296d0Smrg
104022378475aSmrg      # Objects from convenience libraries.  This assumes
104032378475aSmrg      # single-version convenience libraries.  Whenever we create
104042378475aSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
104052378475aSmrg      # the extraction.
104062378475aSmrg      reload_conv_objs=
104072378475aSmrg      gentop=
10408eca46af7Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409eca46af7Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410eca46af7Smrg      # into space.
10411eca46af7Smrg      case $reload_cmds in
10412eca46af7Smrg        *\$LD[\ \$]*) wl= ;;
10413eca46af7Smrg      esac
104142378475aSmrg      if test -n "$convenience"; then
104152378475aSmrg	if test -n "$whole_archive_flag_spec"; then
104162378475aSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417eca46af7Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418eca46af7Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
104192378475aSmrg	else
10420eca46af7Smrg	  gentop=$output_objdir/${obj}x
1042114330f12Smrg	  func_append generated " $gentop"
10422e6f085baSmrg
104232378475aSmrg	  func_extract_archives $gentop $convenience
104242378475aSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
104252378475aSmrg	fi
10426e6f085baSmrg      fi
10427e6f085baSmrg
1042814330f12Smrg      # If we're not building shared, we need to use non_pic_objs
10429eca46af7Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
1043014330f12Smrg
104312378475aSmrg      # Create the old-style object.
10432eca46af7Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433e6f085baSmrg
10434eca46af7Smrg      output=$obj
104352378475aSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436e6f085baSmrg
104372378475aSmrg      # Exit if we aren't doing a library object file.
104382378475aSmrg      if test -z "$libobj"; then
104392378475aSmrg	if test -n "$gentop"; then
104402378475aSmrg	  func_show_eval '${RM}r "$gentop"'
104412378475aSmrg	fi
104422378475aSmrg
104432378475aSmrg	exit $EXIT_SUCCESS
10444e6f085baSmrg      fi
104452378475aSmrg
10446eca46af7Smrg      test yes = "$build_libtool_libs" || {
104472378475aSmrg	if test -n "$gentop"; then
104482378475aSmrg	  func_show_eval '${RM}r "$gentop"'
104492378475aSmrg	fi
104502378475aSmrg
104512378475aSmrg	# Create an invalid libtool object if no PIC, so that we don't
104522378475aSmrg	# accidentally link it into a program.
104532378475aSmrg	# $show "echo timestamp > $libobj"
104542378475aSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
104552378475aSmrg	exit $EXIT_SUCCESS
10456eca46af7Smrg      }
104572378475aSmrg
10458eca46af7Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
104592378475aSmrg	# Only do commands if we really have different PIC objects.
104602378475aSmrg	reload_objs="$libobjs $reload_conv_objs"
10461eca46af7Smrg	output=$libobj
104622378475aSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
104632378475aSmrg      fi
104642378475aSmrg
104652378475aSmrg      if test -n "$gentop"; then
104662378475aSmrg	func_show_eval '${RM}r "$gentop"'
104672378475aSmrg      fi
104682378475aSmrg
104692378475aSmrg      exit $EXIT_SUCCESS
10470e6f085baSmrg      ;;
1047195b296d0Smrg
104722378475aSmrg    prog)
104732378475aSmrg      case $host in
104742378475aSmrg	*cygwin*) func_stripname '' '.exe' "$output"
104752378475aSmrg	          output=$func_stripname_result.exe;;
104762378475aSmrg      esac
104772378475aSmrg      test -n "$vinfo" && \
10478eca46af7Smrg	func_warning "'-version-info' is ignored for programs"
1047995b296d0Smrg
104802378475aSmrg      test -n "$release" && \
10481eca46af7Smrg	func_warning "'-release' is ignored for programs"
1048295b296d0Smrg
10483eca46af7Smrg      $preload \
10484eca46af7Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485eca46af7Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
104862378475aSmrg
104872378475aSmrg      case $host in
104882378475aSmrg      *-*-rhapsody* | *-*-darwin1.[012])
104892378475aSmrg	# On Rhapsody replace the C library is the System framework
1049014330f12Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1049114330f12Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492e6f085baSmrg	;;
104932378475aSmrg      esac
10494e6f085baSmrg
104952378475aSmrg      case $host in
104962378475aSmrg      *-*-darwin*)
104972378475aSmrg	# Don't allow lazy linking, it breaks C++ global constructors
104982378475aSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10499eca46af7Smrg	if test CXX = "$tagname"; then
105002378475aSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
105012378475aSmrg	    10.[0123])
10502eca46af7Smrg	      func_append compile_command " $wl-bind_at_load"
10503eca46af7Smrg	      func_append finalize_command " $wl-bind_at_load"
105042378475aSmrg	    ;;
105052378475aSmrg	  esac
10506e6f085baSmrg	fi
105072378475aSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1050814330f12Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1050914330f12Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105102378475aSmrg	;;
105112378475aSmrg      esac
10512e6f085baSmrg
10513e6f085baSmrg
105142378475aSmrg      # move library search paths that coincide with paths to not yet
105152378475aSmrg      # installed libraries to the beginning of the library search list
105162378475aSmrg      new_libs=
105172378475aSmrg      for path in $notinst_path; do
105182378475aSmrg	case " $new_libs " in
105192378475aSmrg	*" -L$path/$objdir "*) ;;
105202378475aSmrg	*)
105212378475aSmrg	  case " $compile_deplibs " in
105222378475aSmrg	  *" -L$path/$objdir "*)
1052314330f12Smrg	    func_append new_libs " -L$path/$objdir" ;;
1052439713583Smrg	  esac
105252378475aSmrg	  ;;
105262378475aSmrg	esac
105272378475aSmrg      done
105282378475aSmrg      for deplib in $compile_deplibs; do
105292378475aSmrg	case $deplib in
105302378475aSmrg	-L*)
105312378475aSmrg	  case " $new_libs " in
105322378475aSmrg	  *" $deplib "*) ;;
1053314330f12Smrg	  *) func_append new_libs " $deplib" ;;
1053439713583Smrg	  esac
105352378475aSmrg	  ;;
1053614330f12Smrg	*) func_append new_libs " $deplib" ;;
105372378475aSmrg	esac
105382378475aSmrg      done
10539eca46af7Smrg      compile_deplibs=$new_libs
1054095b296d0Smrg
10541e6f085baSmrg
1054214330f12Smrg      func_append compile_command " $compile_deplibs"
1054314330f12Smrg      func_append finalize_command " $finalize_deplibs"
10544e6f085baSmrg
105452378475aSmrg      if test -n "$rpath$xrpath"; then
105462378475aSmrg	# If the user specified any rpath flags, then add them.
105472378475aSmrg	for libdir in $rpath $xrpath; do
105482378475aSmrg	  # This is the magic to use -rpath.
105492378475aSmrg	  case "$finalize_rpath " in
105502378475aSmrg	  *" $libdir "*) ;;
1055114330f12Smrg	  *) func_append finalize_rpath " $libdir" ;;
105522378475aSmrg	  esac
105532378475aSmrg	done
105542378475aSmrg      fi
10555e6f085baSmrg
105562378475aSmrg      # Now hardcode the library paths
105572378475aSmrg      rpath=
105582378475aSmrg      hardcode_libdirs=
105592378475aSmrg      for libdir in $compile_rpath $finalize_rpath; do
105602378475aSmrg	if test -n "$hardcode_libdir_flag_spec"; then
105612378475aSmrg	  if test -n "$hardcode_libdir_separator"; then
105622378475aSmrg	    if test -z "$hardcode_libdirs"; then
10563eca46af7Smrg	      hardcode_libdirs=$libdir
105642378475aSmrg	    else
105652378475aSmrg	      # Just accumulate the unique libdirs.
105662378475aSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
105672378475aSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
105682378475aSmrg		;;
105692378475aSmrg	      *)
1057014330f12Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
105712378475aSmrg		;;
105722378475aSmrg	      esac
105732378475aSmrg	    fi
10574e6f085baSmrg	  else
105752378475aSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1057614330f12Smrg	    func_append rpath " $flag"
10577e6f085baSmrg	  fi
105782378475aSmrg	elif test -n "$runpath_var"; then
105792378475aSmrg	  case "$perm_rpath " in
105802378475aSmrg	  *" $libdir "*) ;;
1058114330f12Smrg	  *) func_append perm_rpath " $libdir" ;;
105822378475aSmrg	  esac
105832378475aSmrg	fi
105842378475aSmrg	case $host in
105852378475aSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586eca46af7Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
105872378475aSmrg	  case :$dllsearchpath: in
105882378475aSmrg	  *":$libdir:"*) ;;
105892378475aSmrg	  ::) dllsearchpath=$libdir;;
1059014330f12Smrg	  *) func_append dllsearchpath ":$libdir";;
105912378475aSmrg	  esac
105922378475aSmrg	  case :$dllsearchpath: in
105932378475aSmrg	  *":$testbindir:"*) ;;
105942378475aSmrg	  ::) dllsearchpath=$testbindir;;
1059514330f12Smrg	  *) func_append dllsearchpath ":$testbindir";;
105962378475aSmrg	  esac
105972378475aSmrg	  ;;
105982378475aSmrg	esac
105992378475aSmrg      done
106002378475aSmrg      # Substitute the hardcoded libdirs into the rpath.
106012378475aSmrg      if test -n "$hardcode_libdir_separator" &&
106022378475aSmrg	 test -n "$hardcode_libdirs"; then
10603eca46af7Smrg	libdir=$hardcode_libdirs
106042378475aSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106052378475aSmrg      fi
10606eca46af7Smrg      compile_rpath=$rpath
10607e6f085baSmrg
106082378475aSmrg      rpath=
106092378475aSmrg      hardcode_libdirs=
106102378475aSmrg      for libdir in $finalize_rpath; do
106112378475aSmrg	if test -n "$hardcode_libdir_flag_spec"; then
106122378475aSmrg	  if test -n "$hardcode_libdir_separator"; then
106132378475aSmrg	    if test -z "$hardcode_libdirs"; then
10614eca46af7Smrg	      hardcode_libdirs=$libdir
106152378475aSmrg	    else
106162378475aSmrg	      # Just accumulate the unique libdirs.
106172378475aSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
106182378475aSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
106192378475aSmrg		;;
106202378475aSmrg	      *)
1062114330f12Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
106222378475aSmrg		;;
106232378475aSmrg	      esac
106242378475aSmrg	    fi
1062595b296d0Smrg	  else
106262378475aSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1062714330f12Smrg	    func_append rpath " $flag"
1062895b296d0Smrg	  fi
106292378475aSmrg	elif test -n "$runpath_var"; then
106302378475aSmrg	  case "$finalize_perm_rpath " in
106312378475aSmrg	  *" $libdir "*) ;;
1063214330f12Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
106332378475aSmrg	  esac
1063495b296d0Smrg	fi
106352378475aSmrg      done
106362378475aSmrg      # Substitute the hardcoded libdirs into the rpath.
106372378475aSmrg      if test -n "$hardcode_libdir_separator" &&
106382378475aSmrg	 test -n "$hardcode_libdirs"; then
10639eca46af7Smrg	libdir=$hardcode_libdirs
106402378475aSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106412378475aSmrg      fi
10642eca46af7Smrg      finalize_rpath=$rpath
1064395b296d0Smrg
10644eca46af7Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
106452378475aSmrg	# Transform all the library objects into standard objects.
1064614330f12Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064714330f12Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106482378475aSmrg      fi
1064995b296d0Smrg
10650eca46af7Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
1065195b296d0Smrg
106522378475aSmrg      # template prelinking step
106532378475aSmrg      if test -n "$prelink_cmds"; then
106542378475aSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
106552378475aSmrg      fi
1065695b296d0Smrg
10657eca46af7Smrg      wrappers_required=:
106582378475aSmrg      case $host in
1065914330f12Smrg      *cegcc* | *mingw32ce*)
1066014330f12Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661eca46af7Smrg        wrappers_required=false
1066214330f12Smrg        ;;
106632378475aSmrg      *cygwin* | *mingw* )
10664eca46af7Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
106652378475aSmrg        ;;
106662378475aSmrg      *)
10667eca46af7Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668eca46af7Smrg          wrappers_required=false
106692378475aSmrg        fi
106702378475aSmrg        ;;
106712378475aSmrg      esac
10672eca46af7Smrg      $wrappers_required || {
106732378475aSmrg	# Replace the output file specification.
1067414330f12Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675eca46af7Smrg	link_command=$compile_command$compile_rpath
1067695b296d0Smrg
106772378475aSmrg	# We have no uninstalled library dependencies, so finalize right now.
106782378475aSmrg	exit_status=0
106792378475aSmrg	func_show_eval "$link_command" 'exit_status=$?'
1068095b296d0Smrg
1068114330f12Smrg	if test -n "$postlink_cmds"; then
1068214330f12Smrg	  func_to_tool_file "$output"
1068314330f12Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1068414330f12Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1068514330f12Smrg	fi
1068614330f12Smrg
106872378475aSmrg	# Delete the generated files.
10688eca46af7Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689eca46af7Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
1069095b296d0Smrg	fi
1069195b296d0Smrg
106922378475aSmrg	exit $exit_status
10693eca46af7Smrg      }
1069495b296d0Smrg
106952378475aSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
106962378475aSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
106972378475aSmrg      fi
106982378475aSmrg      if test -n "$finalize_shlibpath"; then
106992378475aSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
107002378475aSmrg      fi
10701e6f085baSmrg
107022378475aSmrg      compile_var=
107032378475aSmrg      finalize_var=
107042378475aSmrg      if test -n "$runpath_var"; then
107052378475aSmrg	if test -n "$perm_rpath"; then
107062378475aSmrg	  # We should set the runpath_var.
107072378475aSmrg	  rpath=
107082378475aSmrg	  for dir in $perm_rpath; do
1070914330f12Smrg	    func_append rpath "$dir:"
107102378475aSmrg	  done
107112378475aSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
1071295b296d0Smrg	fi
107132378475aSmrg	if test -n "$finalize_perm_rpath"; then
107142378475aSmrg	  # We should set the runpath_var.
107152378475aSmrg	  rpath=
107162378475aSmrg	  for dir in $finalize_perm_rpath; do
1071714330f12Smrg	    func_append rpath "$dir:"
107182378475aSmrg	  done
107192378475aSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
1072095b296d0Smrg	fi
107212378475aSmrg      fi
1072295b296d0Smrg
10723eca46af7Smrg      if test yes = "$no_install"; then
107242378475aSmrg	# We don't need to create a wrapper script.
10725eca46af7Smrg	link_command=$compile_var$compile_command$compile_rpath
107262378475aSmrg	# Replace the output file specification.
1072714330f12Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
107282378475aSmrg	# Delete the old output file.
107292378475aSmrg	$opt_dry_run || $RM $output
107302378475aSmrg	# Link the executable and exit
107312378475aSmrg	func_show_eval "$link_command" 'exit $?'
1073214330f12Smrg
1073314330f12Smrg	if test -n "$postlink_cmds"; then
1073414330f12Smrg	  func_to_tool_file "$output"
1073514330f12Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1073614330f12Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1073714330f12Smrg	fi
1073814330f12Smrg
10739e6f085baSmrg	exit $EXIT_SUCCESS
107402378475aSmrg      fi
1074139713583Smrg
10742eca46af7Smrg      case $hardcode_action,$fast_install in
10743eca46af7Smrg        relink,*)
10744eca46af7Smrg	  # Fast installation is not supported
10745eca46af7Smrg	  link_command=$compile_var$compile_command$compile_rpath
10746eca46af7Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107472378475aSmrg
10748eca46af7Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10749eca46af7Smrg	  func_warning "'$output' will be relinked during installation"
10750eca46af7Smrg	  ;;
10751eca46af7Smrg        *,yes)
10752eca46af7Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753eca46af7Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754eca46af7Smrg          ;;
10755eca46af7Smrg	*,no)
10756eca46af7Smrg	  link_command=$compile_var$compile_command$compile_rpath
10757eca46af7Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758eca46af7Smrg          ;;
10759eca46af7Smrg	*,needless)
10760eca46af7Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761eca46af7Smrg	  relink_command=
10762eca46af7Smrg          ;;
10763eca46af7Smrg      esac
1076495b296d0Smrg
107652378475aSmrg      # Replace the output file specification.
1076614330f12Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
1076795b296d0Smrg
107682378475aSmrg      # Delete the old output files.
107692378475aSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
1077095b296d0Smrg
107712378475aSmrg      func_show_eval "$link_command" 'exit $?'
10772e6f085baSmrg
1077314330f12Smrg      if test -n "$postlink_cmds"; then
1077414330f12Smrg	func_to_tool_file "$output_objdir/$outputname"
1077514330f12Smrg	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'`
1077614330f12Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
1077714330f12Smrg      fi
1077814330f12Smrg
107792378475aSmrg      # Now create the wrapper script.
107802378475aSmrg      func_verbose "creating $output"
10781e6f085baSmrg
107822378475aSmrg      # Quote the relink command for shipping.
107832378475aSmrg      if test -n "$relink_command"; then
107842378475aSmrg	# Preserve any variables that may affect compiler behavior
107852378475aSmrg	for var in $variables_saved_for_relink; do
107862378475aSmrg	  if eval test -z \"\${$var+set}\"; then
107872378475aSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
107882378475aSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
107892378475aSmrg	    relink_command="$var=; export $var; $relink_command"
1079095b296d0Smrg	  else
10791d87a3195Smrg	    func_quote_arg pretty "$var_value"
10792d87a3195Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
1079395b296d0Smrg	  fi
107942378475aSmrg	done
10795d87a3195Smrg	func_quote eval cd "`pwd`"
10796d87a3195Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797d87a3195Smrg	relink_command=$func_quote_arg_unquoted_result
107982378475aSmrg      fi
107992378475aSmrg
108002378475aSmrg      # Only actually do things if not in dry run mode.
108012378475aSmrg      $opt_dry_run || {
108022378475aSmrg	# win32 will think the script is a binary if it has
108032378475aSmrg	# a .exe suffix, so we strip it off here.
108042378475aSmrg	case $output in
108052378475aSmrg	  *.exe) func_stripname '' '.exe' "$output"
108062378475aSmrg	         output=$func_stripname_result ;;
108072378475aSmrg	esac
108082378475aSmrg	# test for cygwin because mv fails w/o .exe extensions
108092378475aSmrg	case $host in
108102378475aSmrg	  *cygwin*)
108112378475aSmrg	    exeext=.exe
108122378475aSmrg	    func_stripname '' '.exe' "$outputname"
108132378475aSmrg	    outputname=$func_stripname_result ;;
108142378475aSmrg	  *) exeext= ;;
1081595b296d0Smrg	esac
108162378475aSmrg	case $host in
108172378475aSmrg	  *cygwin* | *mingw* )
108182378475aSmrg	    func_dirname_and_basename "$output" "" "."
108192378475aSmrg	    output_name=$func_basename_result
108202378475aSmrg	    output_path=$func_dirname_result
10821eca46af7Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822eca46af7Smrg	    cwrapper=$output_path/$output_name.exe
108232378475aSmrg	    $RM $cwrappersource $cwrapper
108242378475aSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
108252378475aSmrg
108262378475aSmrg	    func_emit_cwrapperexe_src > $cwrappersource
108272378475aSmrg
108282378475aSmrg	    # The wrapper executable is built using the $host compiler,
108292378475aSmrg	    # because it contains $host paths and files. If cross-
108302378475aSmrg	    # compiling, it, like the target executable, must be
108312378475aSmrg	    # executed on the $host or under an emulation environment.
108322378475aSmrg	    $opt_dry_run || {
108332378475aSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
108342378475aSmrg	      $STRIP $cwrapper
108352378475aSmrg	    }
1083695b296d0Smrg
108372378475aSmrg	    # Now, create the wrapper script for func_source use:
108382378475aSmrg	    func_ltwrapper_scriptname $cwrapper
108392378475aSmrg	    $RM $func_ltwrapper_scriptname_result
108402378475aSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
108412378475aSmrg	    $opt_dry_run || {
108422378475aSmrg	      # note: this script will not be executed, so do not chmod.
10843eca46af7Smrg	      if test "x$build" = "x$host"; then
108442378475aSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
108452378475aSmrg	      else
108462378475aSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
108472378475aSmrg	      fi
108482378475aSmrg	    }
108492378475aSmrg	  ;;
108502378475aSmrg	  * )
108512378475aSmrg	    $RM $output
108522378475aSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
1085395b296d0Smrg
108542378475aSmrg	    func_emit_wrapper no > $output
108552378475aSmrg	    chmod +x $output
108562378475aSmrg	  ;;
108572378475aSmrg	esac
108582378475aSmrg      }
108592378475aSmrg      exit $EXIT_SUCCESS
108602378475aSmrg      ;;
108612378475aSmrg    esac
1086295b296d0Smrg
108632378475aSmrg    # See if we need to build an old-fashioned archive.
108642378475aSmrg    for oldlib in $oldlibs; do
1086595b296d0Smrg
10866eca46af7Smrg      case $build_libtool_libs in
10867eca46af7Smrg        convenience)
10868eca46af7Smrg	  oldobjs="$libobjs_save $symfileobj"
10869eca46af7Smrg	  addlibs=$convenience
108702378475aSmrg	  build_libtool_libs=no
10871eca46af7Smrg	  ;;
10872eca46af7Smrg	module)
10873eca46af7Smrg	  oldobjs=$libobjs_save
10874eca46af7Smrg	  addlibs=$old_convenience
10875eca46af7Smrg	  build_libtool_libs=no
10876eca46af7Smrg          ;;
10877eca46af7Smrg	*)
108782378475aSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10879eca46af7Smrg	  $preload && test -f "$symfileobj" \
10880eca46af7Smrg	    && func_append oldobjs " $symfileobj"
10881eca46af7Smrg	  addlibs=$old_convenience
10882eca46af7Smrg	  ;;
10883eca46af7Smrg      esac
1088495b296d0Smrg
108852378475aSmrg      if test -n "$addlibs"; then
10886eca46af7Smrg	gentop=$output_objdir/${outputname}x
1088714330f12Smrg	func_append generated " $gentop"
1088895b296d0Smrg
108892378475aSmrg	func_extract_archives $gentop $addlibs
1089014330f12Smrg	func_append oldobjs " $func_extract_archives_result"
108912378475aSmrg      fi
1089295b296d0Smrg
108932378475aSmrg      # Do each command in the archive commands.
10894eca46af7Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
108952378475aSmrg	cmds=$old_archive_from_new_cmds
108962378475aSmrg      else
1089795b296d0Smrg
108982378475aSmrg	# Add any objects from preloaded convenience libraries
108992378475aSmrg	if test -n "$dlprefiles"; then
10900eca46af7Smrg	  gentop=$output_objdir/${outputname}x
1090114330f12Smrg	  func_append generated " $gentop"
1090295b296d0Smrg
109032378475aSmrg	  func_extract_archives $gentop $dlprefiles
1090414330f12Smrg	  func_append oldobjs " $func_extract_archives_result"
109052378475aSmrg	fi
1090695b296d0Smrg
109072378475aSmrg	# POSIX demands no paths to be encoded in archives.  We have
109082378475aSmrg	# to avoid creating archives with duplicate basenames if we
109092378475aSmrg	# might have to extract them afterwards, e.g., when creating a
109102378475aSmrg	# static archive out of a convenience library, or when linking
109112378475aSmrg	# the entirety of a libtool archive into another (currently
109122378475aSmrg	# not supported by libtool).
109132378475aSmrg	if (for obj in $oldobjs
109142378475aSmrg	    do
109152378475aSmrg	      func_basename "$obj"
109162378475aSmrg	      $ECHO "$func_basename_result"
109172378475aSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
109182378475aSmrg	  :
109192378475aSmrg	else
1092014330f12Smrg	  echo "copying selected object files to avoid basename conflicts..."
10921eca46af7Smrg	  gentop=$output_objdir/${outputname}x
1092214330f12Smrg	  func_append generated " $gentop"
109232378475aSmrg	  func_mkdir_p "$gentop"
109242378475aSmrg	  save_oldobjs=$oldobjs
109252378475aSmrg	  oldobjs=
109262378475aSmrg	  counter=1
109272378475aSmrg	  for obj in $save_oldobjs
109282378475aSmrg	  do
109292378475aSmrg	    func_basename "$obj"
10930eca46af7Smrg	    objbase=$func_basename_result
109312378475aSmrg	    case " $oldobjs " in
109322378475aSmrg	    " ") oldobjs=$obj ;;
109332378475aSmrg	    *[\ /]"$objbase "*)
109342378475aSmrg	      while :; do
109352378475aSmrg		# Make sure we don't pick an alternate name that also
109362378475aSmrg		# overlaps.
109372378475aSmrg		newobj=lt$counter-$objbase
109382378475aSmrg		func_arith $counter + 1
109392378475aSmrg		counter=$func_arith_result
109402378475aSmrg		case " $oldobjs " in
109412378475aSmrg		*[\ /]"$newobj "*) ;;
109422378475aSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
109432378475aSmrg		esac
109442378475aSmrg	      done
109452378475aSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
1094614330f12Smrg	      func_append oldobjs " $gentop/$newobj"
109472378475aSmrg	      ;;
1094814330f12Smrg	    *) func_append oldobjs " $obj" ;;
109492378475aSmrg	    esac
1095095b296d0Smrg	  done
1095139713583Smrg	fi
10952eca46af7Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953eca46af7Smrg	tool_oldlib=$func_to_tool_file_result
109542378475aSmrg	eval cmds=\"$old_archive_cmds\"
10955e6f085baSmrg
109562378475aSmrg	func_len " $cmds"
109572378475aSmrg	len=$func_len_result
109582378475aSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
109592378475aSmrg	  cmds=$old_archive_cmds
1096014330f12Smrg	elif test -n "$archiver_list_spec"; then
1096114330f12Smrg	  func_verbose "using command file archive linking..."
1096214330f12Smrg	  for obj in $oldobjs
1096314330f12Smrg	  do
1096414330f12Smrg	    func_to_tool_file "$obj"
1096514330f12Smrg	    $ECHO "$func_to_tool_file_result"
1096614330f12Smrg	  done > $output_objdir/$libname.libcmd
1096714330f12Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
1096814330f12Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
1096914330f12Smrg	  cmds=$old_archive_cmds
109702378475aSmrg	else
109712378475aSmrg	  # the command line is too long to link in one step, link in parts
109722378475aSmrg	  func_verbose "using piecewise archive linking..."
109732378475aSmrg	  save_RANLIB=$RANLIB
109742378475aSmrg	  RANLIB=:
109752378475aSmrg	  objlist=
109762378475aSmrg	  concat_cmds=
109772378475aSmrg	  save_oldobjs=$oldobjs
109782378475aSmrg	  oldobjs=
109792378475aSmrg	  # Is there a better way of finding the last object in the list?
109802378475aSmrg	  for obj in $save_oldobjs
109812378475aSmrg	  do
109822378475aSmrg	    last_oldobj=$obj
109832378475aSmrg	  done
109842378475aSmrg	  eval test_cmds=\"$old_archive_cmds\"
109852378475aSmrg	  func_len " $test_cmds"
109862378475aSmrg	  len0=$func_len_result
109872378475aSmrg	  len=$len0
109882378475aSmrg	  for obj in $save_oldobjs
109892378475aSmrg	  do
109902378475aSmrg	    func_len " $obj"
109912378475aSmrg	    func_arith $len + $func_len_result
109922378475aSmrg	    len=$func_arith_result
109932378475aSmrg	    func_append objlist " $obj"
109942378475aSmrg	    if test "$len" -lt "$max_cmd_len"; then
109952378475aSmrg	      :
109962378475aSmrg	    else
109972378475aSmrg	      # the above command should be used before it gets too long
109982378475aSmrg	      oldobjs=$objlist
10999eca46af7Smrg	      if test "$obj" = "$last_oldobj"; then
110002378475aSmrg		RANLIB=$save_RANLIB
110012378475aSmrg	      fi
110022378475aSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003eca46af7Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
110042378475aSmrg	      objlist=
110052378475aSmrg	      len=$len0
110062378475aSmrg	    fi
110072378475aSmrg	  done
110082378475aSmrg	  RANLIB=$save_RANLIB
110092378475aSmrg	  oldobjs=$objlist
11010eca46af7Smrg	  if test -z "$oldobjs"; then
110112378475aSmrg	    eval cmds=\"\$concat_cmds\"
110122378475aSmrg	  else
110132378475aSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
110142378475aSmrg	  fi
110152378475aSmrg	fi
110162378475aSmrg      fi
110172378475aSmrg      func_execute_cmds "$cmds" 'exit $?'
1101895b296d0Smrg    done
1101995b296d0Smrg
110202378475aSmrg    test -n "$generated" && \
110212378475aSmrg      func_show_eval "${RM}r$generated"
1102295b296d0Smrg
110232378475aSmrg    # Now create the libtool archive.
110242378475aSmrg    case $output in
110252378475aSmrg    *.la)
110262378475aSmrg      old_library=
11027eca46af7Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
110282378475aSmrg      func_verbose "creating $output"
1102939713583Smrg
110302378475aSmrg      # Preserve any variables that may affect compiler behavior
110312378475aSmrg      for var in $variables_saved_for_relink; do
110322378475aSmrg	if eval test -z \"\${$var+set}\"; then
110332378475aSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
110342378475aSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
110352378475aSmrg	  relink_command="$var=; export $var; $relink_command"
11036e6f085baSmrg	else
11037d87a3195Smrg	  func_quote_arg pretty,unquoted "$var_value"
11038d87a3195Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039e6f085baSmrg	fi
110402378475aSmrg      done
110412378475aSmrg      # Quote the link command for shipping.
11042d87a3195Smrg      func_quote eval cd "`pwd`"
11043d87a3195Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044d87a3195Smrg      func_quote_arg pretty,unquoted "$relink_command"
11045d87a3195Smrg      relink_command=$func_quote_arg_unquoted_result
11046eca46af7Smrg      if test yes = "$hardcode_automatic"; then
110472378475aSmrg	relink_command=
110482378475aSmrg      fi
1104995b296d0Smrg
110502378475aSmrg      # Only create the output if not a dry run.
110512378475aSmrg      $opt_dry_run || {
110522378475aSmrg	for installed in no yes; do
11053eca46af7Smrg	  if test yes = "$installed"; then
110542378475aSmrg	    if test -z "$install_libdir"; then
110552378475aSmrg	      break
110562378475aSmrg	    fi
11057eca46af7Smrg	    output=$output_objdir/${outputname}i
110582378475aSmrg	    # Replace all uninstalled libtool libraries with the installed ones
110592378475aSmrg	    newdependency_libs=
110602378475aSmrg	    for deplib in $dependency_libs; do
110612378475aSmrg	      case $deplib in
110622378475aSmrg	      *.la)
110632378475aSmrg		func_basename "$deplib"
11064eca46af7Smrg		name=$func_basename_result
11065eca46af7Smrg		func_resolve_sysroot "$deplib"
11066eca46af7Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
110672378475aSmrg		test -z "$libdir" && \
11068eca46af7Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
1106914330f12Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
1107014330f12Smrg		;;
1107114330f12Smrg	      -L*)
1107214330f12Smrg		func_stripname -L '' "$deplib"
1107314330f12Smrg		func_replace_sysroot "$func_stripname_result"
1107414330f12Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
110752378475aSmrg		;;
1107614330f12Smrg	      -R*)
1107714330f12Smrg		func_stripname -R '' "$deplib"
1107814330f12Smrg		func_replace_sysroot "$func_stripname_result"
1107914330f12Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
1108014330f12Smrg		;;
1108114330f12Smrg	      *) func_append newdependency_libs " $deplib" ;;
110822378475aSmrg	      esac
110832378475aSmrg	    done
11084eca46af7Smrg	    dependency_libs=$newdependency_libs
110852378475aSmrg	    newdlfiles=
110862378475aSmrg
110872378475aSmrg	    for lib in $dlfiles; do
110882378475aSmrg	      case $lib in
110892378475aSmrg	      *.la)
110902378475aSmrg	        func_basename "$lib"
11091eca46af7Smrg		name=$func_basename_result
11092eca46af7Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
110932378475aSmrg		test -z "$libdir" && \
11094eca46af7Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1109514330f12Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
110962378475aSmrg		;;
1109714330f12Smrg	      *) func_append newdlfiles " $lib" ;;
110982378475aSmrg	      esac
110992378475aSmrg	    done
11100eca46af7Smrg	    dlfiles=$newdlfiles
111012378475aSmrg	    newdlprefiles=
111022378475aSmrg	    for lib in $dlprefiles; do
111032378475aSmrg	      case $lib in
111042378475aSmrg	      *.la)
111052378475aSmrg		# Only pass preopened files to the pseudo-archive (for
111062378475aSmrg		# eventual linking with the app. that links it) if we
111072378475aSmrg		# didn't already link the preopened objects directly into
111082378475aSmrg		# the library:
111092378475aSmrg		func_basename "$lib"
11110eca46af7Smrg		name=$func_basename_result
11111eca46af7Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
111122378475aSmrg		test -z "$libdir" && \
11113eca46af7Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1111414330f12Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
111152378475aSmrg		;;
111162378475aSmrg	      esac
111172378475aSmrg	    done
11118eca46af7Smrg	    dlprefiles=$newdlprefiles
111192378475aSmrg	  else
111202378475aSmrg	    newdlfiles=
111212378475aSmrg	    for lib in $dlfiles; do
111222378475aSmrg	      case $lib in
11123eca46af7Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111242378475aSmrg		*) abs=`pwd`"/$lib" ;;
111252378475aSmrg	      esac
1112614330f12Smrg	      func_append newdlfiles " $abs"
111272378475aSmrg	    done
11128eca46af7Smrg	    dlfiles=$newdlfiles
111292378475aSmrg	    newdlprefiles=
111302378475aSmrg	    for lib in $dlprefiles; do
111312378475aSmrg	      case $lib in
11132eca46af7Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111332378475aSmrg		*) abs=`pwd`"/$lib" ;;
111342378475aSmrg	      esac
1113514330f12Smrg	      func_append newdlprefiles " $abs"
111362378475aSmrg	    done
11137eca46af7Smrg	    dlprefiles=$newdlprefiles
111382378475aSmrg	  fi
111392378475aSmrg	  $RM $output
111402378475aSmrg	  # place dlname in correct position for cygwin
1114114330f12Smrg	  # In fact, it would be nice if we could use this code for all target
1114214330f12Smrg	  # systems that can't hard-code library paths into their executables
1114314330f12Smrg	  # and that have no shared library path variable independent of PATH,
1114414330f12Smrg	  # but it turns out we can't easily determine that from inspecting
1114514330f12Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1114614330f12Smrg	  # applies here; at the moment, that means platforms that use the PE
1114714330f12Smrg	  # object format with DLL files.  See the long comment at the top of
1114814330f12Smrg	  # tests/bindir.at for full details.
111492378475aSmrg	  tdlname=$dlname
111502378475aSmrg	  case $host,$output,$installed,$module,$dlname in
1115114330f12Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1115214330f12Smrg	      # If a -bindir argument was supplied, place the dll there.
11153eca46af7Smrg	      if test -n "$bindir"; then
1115414330f12Smrg		func_relative_path "$install_libdir" "$bindir"
11155eca46af7Smrg		tdlname=$func_relative_path_result/$dlname
1115614330f12Smrg	      else
1115714330f12Smrg		# Otherwise fall back on heuristic.
1115814330f12Smrg		tdlname=../bin/$dlname
1115914330f12Smrg	      fi
1116014330f12Smrg	      ;;
111612378475aSmrg	  esac
111622378475aSmrg	  $ECHO > $output "\
111632378475aSmrg# $outputname - a libtool library file
11164eca46af7Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
111652378475aSmrg#
111662378475aSmrg# Please DO NOT delete this file!
111672378475aSmrg# It is necessary for linking the library.
1116895b296d0Smrg
111692378475aSmrg# The name that we can dlopen(3).
111702378475aSmrgdlname='$tdlname'
1117195b296d0Smrg
111722378475aSmrg# Names of this library.
111732378475aSmrglibrary_names='$library_names'
1117495b296d0Smrg
111752378475aSmrg# The name of the static archive.
111762378475aSmrgold_library='$old_library'
1117795b296d0Smrg
11178eca46af7Smrg# Linker flags that cannot go in dependency_libs.
111792378475aSmrginherited_linker_flags='$new_inherited_linker_flags'
1118095b296d0Smrg
111812378475aSmrg# Libraries that this one depends upon.
111822378475aSmrgdependency_libs='$dependency_libs'
1118395b296d0Smrg
111842378475aSmrg# Names of additional weak libraries provided by this library
111852378475aSmrgweak_library_names='$weak_libs'
1118695b296d0Smrg
111872378475aSmrg# Version information for $libname.
111882378475aSmrgcurrent=$current
111892378475aSmrgage=$age
111902378475aSmrgrevision=$revision
1119195b296d0Smrg
111922378475aSmrg# Is this an already installed library?
111932378475aSmrginstalled=$installed
1119495b296d0Smrg
111952378475aSmrg# Should we warn about portability when linking against -modules?
111962378475aSmrgshouldnotlink=$module
1119795b296d0Smrg
111982378475aSmrg# Files to dlopen/dlpreopen
111992378475aSmrgdlopen='$dlfiles'
112002378475aSmrgdlpreopen='$dlprefiles'
1120195b296d0Smrg
112022378475aSmrg# Directory that this library needs to be installed in:
112032378475aSmrglibdir='$install_libdir'"
11204eca46af7Smrg	  if test no,yes = "$installed,$need_relink"; then
112052378475aSmrg	    $ECHO >> $output "\
112062378475aSmrgrelink_command=\"$relink_command\""
112072378475aSmrg	  fi
112082378475aSmrg	done
112092378475aSmrg      }
1121095b296d0Smrg
112112378475aSmrg      # Do a symbolic link so that the libtool archive can be found in
112122378475aSmrg      # LD_LIBRARY_PATH before the program is installed.
112132378475aSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
112142378475aSmrg      ;;
112152378475aSmrg    esac
112162378475aSmrg    exit $EXIT_SUCCESS
112172378475aSmrg}
11218e6f085baSmrg
11219eca46af7Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220eca46af7Smrg  func_mode_link ${1+"$@"}
11221eca46af7Smrgfi
1122295b296d0Smrg
1122395b296d0Smrg
112242378475aSmrg# func_mode_uninstall arg...
112252378475aSmrgfunc_mode_uninstall ()
112262378475aSmrg{
11227eca46af7Smrg    $debug_cmd
11228eca46af7Smrg
11229eca46af7Smrg    RM=$nonopt
1123095b296d0Smrg    files=
11231eca46af7Smrg    rmforce=false
1123295b296d0Smrg    exit_status=0
1123395b296d0Smrg
1123495b296d0Smrg    # This variable tells wrapper scripts just to set variables rather
1123595b296d0Smrg    # than running their programs.
11236eca46af7Smrg    libtool_install_magic=$magic
1123795b296d0Smrg
1123895b296d0Smrg    for arg
1123995b296d0Smrg    do
1124095b296d0Smrg      case $arg in
11241eca46af7Smrg      -f) func_append RM " $arg"; rmforce=: ;;
1124214330f12Smrg      -*) func_append RM " $arg" ;;
1124314330f12Smrg      *) func_append files " $arg" ;;
1124495b296d0Smrg      esac
1124595b296d0Smrg    done
1124695b296d0Smrg
112472378475aSmrg    test -z "$RM" && \
112482378475aSmrg      func_fatal_help "you must specify an RM program"
1124995b296d0Smrg
1125095b296d0Smrg    rmdirs=
1125195b296d0Smrg
1125295b296d0Smrg    for file in $files; do
112532378475aSmrg      func_dirname "$file" "" "."
11254eca46af7Smrg      dir=$func_dirname_result
11255eca46af7Smrg      if test . = "$dir"; then
11256eca46af7Smrg	odir=$objdir
1125795b296d0Smrg      else
11258eca46af7Smrg	odir=$dir/$objdir
1125995b296d0Smrg      fi
112602378475aSmrg      func_basename "$file"
11261eca46af7Smrg      name=$func_basename_result
11262eca46af7Smrg      test uninstall = "$opt_mode" && odir=$dir
1126395b296d0Smrg
1126414330f12Smrg      # Remember odir for removal later, being careful to avoid duplicates
11265eca46af7Smrg      if test clean = "$opt_mode"; then
1126695b296d0Smrg	case " $rmdirs " in
1126714330f12Smrg	  *" $odir "*) ;;
1126814330f12Smrg	  *) func_append rmdirs " $odir" ;;
1126995b296d0Smrg	esac
1127095b296d0Smrg      fi
1127195b296d0Smrg
1127295b296d0Smrg      # Don't error if the file doesn't exist and rm -f was used.
112732378475aSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
112742378475aSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
112752378475aSmrg	 test -f "$file"; then
1127695b296d0Smrg	:
1127795b296d0Smrg      elif test -d "$file"; then
1127895b296d0Smrg	exit_status=1
1127995b296d0Smrg	continue
11280eca46af7Smrg      elif $rmforce; then
1128195b296d0Smrg	continue
1128295b296d0Smrg      fi
1128395b296d0Smrg
11284eca46af7Smrg      rmfiles=$file
1128595b296d0Smrg
1128695b296d0Smrg      case $name in
1128795b296d0Smrg      *.la)
1128895b296d0Smrg	# Possibly a libtool archive, so verify it.
112892378475aSmrg	if func_lalib_p "$file"; then
112902378475aSmrg	  func_source $dir/$name
1129195b296d0Smrg
1129295b296d0Smrg	  # Delete the libtool libraries and symlinks.
1129395b296d0Smrg	  for n in $library_names; do
1129414330f12Smrg	    func_append rmfiles " $odir/$n"
1129595b296d0Smrg	  done
1129614330f12Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
1129795b296d0Smrg
11298eca46af7Smrg	  case $opt_mode in
1129995b296d0Smrg	  clean)
1130014330f12Smrg	    case " $library_names " in
1130195b296d0Smrg	    *" $dlname "*) ;;
1130214330f12Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
1130395b296d0Smrg	    esac
1130414330f12Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
1130595b296d0Smrg	    ;;
1130695b296d0Smrg	  uninstall)
1130795b296d0Smrg	    if test -n "$library_names"; then
1130895b296d0Smrg	      # Do each command in the postuninstall commands.
11309eca46af7Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
1131095b296d0Smrg	    fi
1131195b296d0Smrg
1131295b296d0Smrg	    if test -n "$old_library"; then
1131395b296d0Smrg	      # Do each command in the old_postuninstall commands.
11314eca46af7Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
1131595b296d0Smrg	    fi
1131695b296d0Smrg	    # FIXME: should reinstall the best remaining shared library.
1131795b296d0Smrg	    ;;
1131895b296d0Smrg	  esac
1131995b296d0Smrg	fi
1132095b296d0Smrg	;;
1132195b296d0Smrg
1132295b296d0Smrg      *.lo)
1132395b296d0Smrg	# Possibly a libtool object, so verify it.
113242378475aSmrg	if func_lalib_p "$file"; then
1132595b296d0Smrg
1132695b296d0Smrg	  # Read the .lo file
113272378475aSmrg	  func_source $dir/$name
1132895b296d0Smrg
1132995b296d0Smrg	  # Add PIC object to the list of files to remove.
11330eca46af7Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
1133114330f12Smrg	    func_append rmfiles " $dir/$pic_object"
1133295b296d0Smrg	  fi
1133395b296d0Smrg
1133495b296d0Smrg	  # Add non-PIC object to the list of files to remove.
11335eca46af7Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
1133614330f12Smrg	    func_append rmfiles " $dir/$non_pic_object"
1133795b296d0Smrg	  fi
1133895b296d0Smrg	fi
1133995b296d0Smrg	;;
1134095b296d0Smrg
1134195b296d0Smrg      *)
11342eca46af7Smrg	if test clean = "$opt_mode"; then
1134395b296d0Smrg	  noexename=$name
1134495b296d0Smrg	  case $file in
1134595b296d0Smrg	  *.exe)
113462378475aSmrg	    func_stripname '' '.exe' "$file"
113472378475aSmrg	    file=$func_stripname_result
113482378475aSmrg	    func_stripname '' '.exe' "$name"
113492378475aSmrg	    noexename=$func_stripname_result
1135095b296d0Smrg	    # $file with .exe has already been added to rmfiles,
1135195b296d0Smrg	    # add $file without .exe
1135214330f12Smrg	    func_append rmfiles " $file"
1135395b296d0Smrg	    ;;
1135495b296d0Smrg	  esac
1135595b296d0Smrg	  # Do a test to see if this is a libtool program.
113562378475aSmrg	  if func_ltwrapper_p "$file"; then
113572378475aSmrg	    if func_ltwrapper_executable_p "$file"; then
113582378475aSmrg	      func_ltwrapper_scriptname "$file"
113592378475aSmrg	      relink_command=
113602378475aSmrg	      func_source $func_ltwrapper_scriptname_result
1136114330f12Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
113622378475aSmrg	    else
113632378475aSmrg	      relink_command=
113642378475aSmrg	      func_source $dir/$noexename
113652378475aSmrg	    fi
1136695b296d0Smrg
1136795b296d0Smrg	    # note $name still contains .exe if it was in $file originally
1136895b296d0Smrg	    # as does the version of $file that was added into $rmfiles
11369eca46af7Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370eca46af7Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
1137114330f12Smrg	      func_append rmfiles " $odir/lt-$name"
1137295b296d0Smrg	    fi
11373eca46af7Smrg	    if test "X$noexename" != "X$name"; then
11374eca46af7Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
1137595b296d0Smrg	    fi
1137695b296d0Smrg	  fi
1137795b296d0Smrg	fi
1137895b296d0Smrg	;;
1137995b296d0Smrg      esac
113802378475aSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
1138195b296d0Smrg    done
1138295b296d0Smrg
11383eca46af7Smrg    # Try to remove the $objdir's in the directories where we deleted files
1138495b296d0Smrg    for dir in $rmdirs; do
1138595b296d0Smrg      if test -d "$dir"; then
113862378475aSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
1138795b296d0Smrg      fi
1138895b296d0Smrg    done
1138995b296d0Smrg
1139095b296d0Smrg    exit $exit_status
113912378475aSmrg}
1139295b296d0Smrg
11393eca46af7Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394eca46af7Smrg  func_mode_uninstall ${1+"$@"}
11395eca46af7Smrgfi
1139639713583Smrg
1139714330f12Smrgtest -z "$opt_mode" && {
11398eca46af7Smrg  help=$generic_help
113992378475aSmrg  func_fatal_help "you must specify a MODE"
114002378475aSmrg}
114012378475aSmrg
114022378475aSmrgtest -z "$exec_cmd" && \
11403eca46af7Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
1140495b296d0Smrg
1140595b296d0Smrgif test -n "$exec_cmd"; then
114062378475aSmrg  eval exec "$exec_cmd"
1140795b296d0Smrg  exit $EXIT_FAILURE
1140895b296d0Smrgfi
1140995b296d0Smrg
114102378475aSmrgexit $exit_status
1141195b296d0Smrg
1141295b296d0Smrg
1141395b296d0Smrg# The TAGs below are defined such that we never get into a situation
11414eca46af7Smrg# where we disable both kinds of libraries.  Given conflicting
1141595b296d0Smrg# choices, we go for a static library, that is the most portable,
1141695b296d0Smrg# since we can't tell whether shared libraries were disabled because
1141795b296d0Smrg# the user asked for that or because the platform doesn't support
1141895b296d0Smrg# them.  This is particularly important on AIX, because we don't
1141995b296d0Smrg# support having both static and shared libraries enabled at the same
1142095b296d0Smrg# time on that platform, so we default to a shared-only configuration.
1142195b296d0Smrg# If a disable-shared tag is given, we'll fallback to a static-only
1142295b296d0Smrg# configuration.  But we'll never go from static-only to shared-only.
1142395b296d0Smrg
1142495b296d0Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
114252378475aSmrgbuild_libtool_libs=no
114262378475aSmrgbuild_old_libs=yes
1142795b296d0Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
1142895b296d0Smrg
1142995b296d0Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
114302378475aSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
1143195b296d0Smrg# ### END LIBTOOL TAG CONFIG: disable-static
1143295b296d0Smrg
1143395b296d0Smrg# Local Variables:
1143495b296d0Smrg# mode:shell-script
1143595b296d0Smrg# sh-indentation:2
1143695b296d0Smrg# End:
11437