174835918Smrg#! /usr/bin/env sh
2edce3322Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
374835918Smrg##               by inline-source v2019-02-19.15
46e7d3316Smrg
574835918Smrg# libtool (GNU libtool) 2.4.7
6edce3322Smrg# Provide generalized library-building support services.
76e7d3316Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
86e7d3316Smrg
974835918Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
106e7d3316Smrg# This is free software; see the source for copying conditions.  There is NO
116e7d3316Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
126e7d3316Smrg
136e7d3316Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14a966c04fSmrg# it under the terms of the GNU General Public License as published by
15a966c04fSmrg# the Free Software Foundation; either version 2 of the License, or
16a966c04fSmrg# (at your option) any later version.
17a966c04fSmrg#
186e7d3316Smrg# As a special exception to the GNU General Public License,
196e7d3316Smrg# if you distribute this file as part of a program or library that
206e7d3316Smrg# is built using GNU Libtool, you may include this file under the
216e7d3316Smrg# same distribution terms that you use for the rest of that program.
226e7d3316Smrg#
236e7d3316Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24a966c04fSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25a966c04fSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26a966c04fSmrg# General Public License for more details.
27a966c04fSmrg#
28a966c04fSmrg# You should have received a copy of the GNU General Public License
29edce3322Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30a966c04fSmrg
31a966c04fSmrg
326e7d3316SmrgPROGRAM=libtool
33a966c04fSmrgPACKAGE=libtool
3474835918SmrgVERSION=2.4.7
3574835918Smrgpackage_revision=2.4.7
362e2dd055Smrg
37edce3322Smrg
38edce3322Smrg## ------ ##
39edce3322Smrg## Usage. ##
40edce3322Smrg## ------ ##
41edce3322Smrg
42edce3322Smrg# Run './libtool --help' for help with using this script from the
43edce3322Smrg# command line.
44edce3322Smrg
45edce3322Smrg
46edce3322Smrg## ------------------------------- ##
47edce3322Smrg## User overridable command paths. ##
48edce3322Smrg## ------------------------------- ##
49edce3322Smrg
50edce3322Smrg# After configure completes, it has a better idea of some of the
51edce3322Smrg# shell tools we need than the defaults used by the functions shared
52edce3322Smrg# with bootstrap, so set those here where they can still be over-
53edce3322Smrg# ridden by the user, but otherwise take precedence.
54edce3322Smrg
55edce3322Smrg: ${AUTOCONF="autoconf"}
56edce3322Smrg: ${AUTOMAKE="automake"}
57edce3322Smrg
58edce3322Smrg
59edce3322Smrg## -------------------------- ##
60edce3322Smrg## Source external libraries. ##
61edce3322Smrg## -------------------------- ##
62edce3322Smrg
63edce3322Smrg# Much of our low-level functionality needs to be sourced from external
64edce3322Smrg# libraries, which are installed to $pkgauxdir.
65edce3322Smrg
66edce3322Smrg# Set a version string for this script.
6774835918Smrgscriptversion=2019-02-19.15; # UTC
68edce3322Smrg
69edce3322Smrg# General shell script boiler plate, and helper functions.
70edce3322Smrg# Written by Gary V. Vaughan, 2004
71edce3322Smrg
7274835918Smrg# This is free software.  There is NO warranty; not even for
7374835918Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7474835918Smrg#
7574835918Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
7674835918Smrg#
7774835918Smrg# This file is dual licensed under the terms of the MIT license
7874835918Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
7974835918Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
8074835918Smrg# these licenses when using or redistributing this software or any of
8174835918Smrg# the files within it.  See the URLs above, or the file `LICENSE`
8274835918Smrg# included in the Bootstrap distribution for the full license texts.
831c235774Smrg
8474835918Smrg# Please report bugs or propose patches to:
8574835918Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86edce3322Smrg
87edce3322Smrg
88edce3322Smrg## ------ ##
89edce3322Smrg## Usage. ##
90edce3322Smrg## ------ ##
91edce3322Smrg
92edce3322Smrg# Evaluate this file near the top of your script to gain access to
93edce3322Smrg# the functions and variables defined here:
94edce3322Smrg#
95edce3322Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96edce3322Smrg#
97edce3322Smrg# If you need to override any of the default environment variable
98edce3322Smrg# settings, do that before evaluating this file.
99edce3322Smrg
100edce3322Smrg
101edce3322Smrg## -------------------- ##
102edce3322Smrg## Shell normalisation. ##
103edce3322Smrg## -------------------- ##
104edce3322Smrg
105edce3322Smrg# Some shells need a little help to be as Bourne compatible as possible.
106edce3322Smrg# Before doing anything else, make sure all that help has been provided!
107edce3322Smrg
108edce3322SmrgDUALCASE=1; export DUALCASE # for MKS sh
109edce3322Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1102e2dd055Smrg  emulate sh
1112e2dd055Smrg  NULLCMD=:
112edce3322Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1132e2dd055Smrg  # is contrary to our usage.  Disable this feature.
1142e2dd055Smrg  alias -g '${1+"$@"}'='"$@"'
115a966c04fSmrg  setopt NO_GLOB_SUBST
1162e2dd055Smrgelse
117edce3322Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118a966c04fSmrgfi
119a966c04fSmrg
120edce3322Smrg# NLS nuisances: We save the old values in case they are required later.
121edce3322Smrg_G_user_locale=
122edce3322Smrg_G_safe_locale=
123edce3322Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1242e2dd055Smrgdo
125edce3322Smrg  eval "if test set = \"\${$_G_var+set}\"; then
126edce3322Smrg          save_$_G_var=\$$_G_var
127edce3322Smrg          $_G_var=C
128edce3322Smrg	  export $_G_var
129edce3322Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130edce3322Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1312e2dd055Smrg	fi"
1322e2dd055Smrgdone
13374835918Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
13474835918Smrg# in case the environment reset is needed later and the $save_* variant is not
13574835918Smrg# defined (see the code above).
13674835918SmrgLC_ALL=C
13774835918SmrgLANGUAGE=C
13874835918Smrgexport LANGUAGE LC_ALL
1396e7d3316Smrg
140edce3322Smrg# Make sure IFS has a sensible default
141edce3322Smrgsp=' '
142edce3322Smrgnl='
143edce3322Smrg'
144edce3322SmrgIFS="$sp	$nl"
145edce3322Smrg
146edce3322Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
147edce3322Smrgif test "${PATH_SEPARATOR+set}" != set; then
148edce3322Smrg  PATH_SEPARATOR=:
149edce3322Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150edce3322Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151edce3322Smrg      PATH_SEPARATOR=';'
152edce3322Smrg  }
153edce3322Smrgfi
1546e7d3316Smrg
1556e7d3316Smrg
15674835918Smrg# func_unset VAR
15774835918Smrg# --------------
15874835918Smrg# Portably unset VAR.
15974835918Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
16074835918Smrg# status if VAR is already unset, which might be problematic if the
16174835918Smrg# statement is used at the end of a function (thus poisoning its return
16274835918Smrg# value) or when 'set -e' is active (causing even a spurious abort of
16374835918Smrg# the script in this case).
16474835918Smrgfunc_unset ()
16574835918Smrg{
16674835918Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
16774835918Smrg}
16874835918Smrg
16974835918Smrg
17074835918Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
17174835918Smrgfunc_unset CDPATH
17274835918Smrg
17374835918Smrg# Make sure ${,E,F}GREP behave sanely.
17474835918Smrgfunc_unset GREP_OPTIONS
17574835918Smrg
1766e7d3316Smrg
177edce3322Smrg## ------------------------- ##
178edce3322Smrg## Locate command utilities. ##
179edce3322Smrg## ------------------------- ##
180edce3322Smrg
181edce3322Smrg
182edce3322Smrg# func_executable_p FILE
183edce3322Smrg# ----------------------
184edce3322Smrg# Check that FILE is an executable regular file.
185edce3322Smrgfunc_executable_p ()
186edce3322Smrg{
187edce3322Smrg    test -f "$1" && test -x "$1"
188edce3322Smrg}
189edce3322Smrg
190edce3322Smrg
191edce3322Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192edce3322Smrg# --------------------------------------------
193edce3322Smrg# Search for either a program that responds to --version with output
194edce3322Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195edce3322Smrg# trying all the directories in PATH with each of the elements of
196edce3322Smrg# PROGS_LIST.
197edce3322Smrg#
198edce3322Smrg# CHECK_FUNC should accept the path to a candidate program, and
199edce3322Smrg# set $func_check_prog_result if it truncates its output less than
200edce3322Smrg# $_G_path_prog_max characters.
201edce3322Smrgfunc_path_progs ()
202edce3322Smrg{
203edce3322Smrg    _G_progs_list=$1
204edce3322Smrg    _G_check_func=$2
205edce3322Smrg    _G_PATH=${3-"$PATH"}
206edce3322Smrg
207edce3322Smrg    _G_path_prog_max=0
208edce3322Smrg    _G_path_prog_found=false
209edce3322Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210edce3322Smrg    for _G_dir in $_G_PATH; do
211edce3322Smrg      IFS=$_G_save_IFS
212edce3322Smrg      test -z "$_G_dir" && _G_dir=.
213edce3322Smrg      for _G_prog_name in $_G_progs_list; do
214edce3322Smrg        for _exeext in '' .EXE; do
215edce3322Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216edce3322Smrg          func_executable_p "$_G_path_prog" || continue
217edce3322Smrg          case `"$_G_path_prog" --version 2>&1` in
218edce3322Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219edce3322Smrg            *)     $_G_check_func $_G_path_prog
220edce3322Smrg		   func_path_progs_result=$func_check_prog_result
221edce3322Smrg		   ;;
222edce3322Smrg          esac
223edce3322Smrg          $_G_path_prog_found && break 3
224edce3322Smrg        done
225edce3322Smrg      done
226edce3322Smrg    done
227edce3322Smrg    IFS=$_G_save_IFS
228edce3322Smrg    test -z "$func_path_progs_result" && {
229edce3322Smrg      echo "no acceptable sed could be found in \$PATH" >&2
230edce3322Smrg      exit 1
231edce3322Smrg    }
232edce3322Smrg}
233edce3322Smrg
234edce3322Smrg
235edce3322Smrg# We want to be able to use the functions in this file before configure
236edce3322Smrg# has figured out where the best binaries are kept, which means we have
237edce3322Smrg# to search for them ourselves - except when the results are already set
238edce3322Smrg# where we skip the searches.
239edce3322Smrg
240edce3322Smrg# Unless the user overrides by setting SED, search the path for either GNU
241edce3322Smrg# sed, or the sed that truncates its output the least.
242edce3322Smrgtest -z "$SED" && {
243edce3322Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244edce3322Smrg  for _G_i in 1 2 3 4 5 6 7; do
245edce3322Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246edce3322Smrg  done
247edce3322Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248edce3322Smrg  _G_sed_script=
249edce3322Smrg
250edce3322Smrg  func_check_prog_sed ()
251edce3322Smrg  {
252edce3322Smrg    _G_path_prog=$1
253edce3322Smrg
254edce3322Smrg    _G_count=0
255edce3322Smrg    printf 0123456789 >conftest.in
256edce3322Smrg    while :
257edce3322Smrg    do
258edce3322Smrg      cat conftest.in conftest.in >conftest.tmp
259edce3322Smrg      mv conftest.tmp conftest.in
260edce3322Smrg      cp conftest.in conftest.nl
261edce3322Smrg      echo '' >> conftest.nl
262edce3322Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263edce3322Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264edce3322Smrg      _G_count=`expr $_G_count + 1`
265edce3322Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266edce3322Smrg        # Best one so far, save it but keep looking for a better one
267edce3322Smrg        func_check_prog_result=$_G_path_prog
268edce3322Smrg        _G_path_prog_max=$_G_count
269edce3322Smrg      fi
270edce3322Smrg      # 10*(2^10) chars as input seems more than enough
271edce3322Smrg      test 10 -lt "$_G_count" && break
272edce3322Smrg    done
273edce3322Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274edce3322Smrg  }
275edce3322Smrg
27674835918Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277edce3322Smrg  rm -f conftest.sed
278edce3322Smrg  SED=$func_path_progs_result
279edce3322Smrg}
280edce3322Smrg
281edce3322Smrg
282edce3322Smrg# Unless the user overrides by setting GREP, search the path for either GNU
283edce3322Smrg# grep, or the grep that truncates its output the least.
284edce3322Smrgtest -z "$GREP" && {
285edce3322Smrg  func_check_prog_grep ()
286edce3322Smrg  {
287edce3322Smrg    _G_path_prog=$1
288edce3322Smrg
289edce3322Smrg    _G_count=0
290edce3322Smrg    _G_path_prog_max=0
291edce3322Smrg    printf 0123456789 >conftest.in
292edce3322Smrg    while :
293edce3322Smrg    do
294edce3322Smrg      cat conftest.in conftest.in >conftest.tmp
295edce3322Smrg      mv conftest.tmp conftest.in
296edce3322Smrg      cp conftest.in conftest.nl
297edce3322Smrg      echo 'GREP' >> conftest.nl
298edce3322Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299edce3322Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300edce3322Smrg      _G_count=`expr $_G_count + 1`
301edce3322Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302edce3322Smrg        # Best one so far, save it but keep looking for a better one
303edce3322Smrg        func_check_prog_result=$_G_path_prog
304edce3322Smrg        _G_path_prog_max=$_G_count
305edce3322Smrg      fi
306edce3322Smrg      # 10*(2^10) chars as input seems more than enough
307edce3322Smrg      test 10 -lt "$_G_count" && break
308edce3322Smrg    done
309edce3322Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310edce3322Smrg  }
311edce3322Smrg
31274835918Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313edce3322Smrg  GREP=$func_path_progs_result
314edce3322Smrg}
315edce3322Smrg
316edce3322Smrg
317edce3322Smrg## ------------------------------- ##
318edce3322Smrg## User overridable command paths. ##
319edce3322Smrg## ------------------------------- ##
320edce3322Smrg
321edce3322Smrg# All uppercase variable names are used for environment variables.  These
322edce3322Smrg# variables can be overridden by the user before calling a script that
323edce3322Smrg# uses them if a suitable command of that name is not already available
324edce3322Smrg# in the command search PATH.
3256e7d3316Smrg
3266e7d3316Smrg: ${CP="cp -f"}
327edce3322Smrg: ${ECHO="printf %s\n"}
328edce3322Smrg: ${EGREP="$GREP -E"}
329edce3322Smrg: ${FGREP="$GREP -F"}
330edce3322Smrg: ${LN_S="ln -s"}
3316e7d3316Smrg: ${MAKE="make"}
3326e7d3316Smrg: ${MKDIR="mkdir"}
3336e7d3316Smrg: ${MV="mv -f"}
3346e7d3316Smrg: ${RM="rm -f"}
3356e7d3316Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336a966c04fSmrg
3376e7d3316Smrg
338edce3322Smrg## -------------------- ##
339edce3322Smrg## Useful sed snippets. ##
340edce3322Smrg## -------------------- ##
34197cf2ee2Smrg
342edce3322Smrgsed_dirname='s|/[^/]*$||'
343edce3322Smrgsed_basename='s|^.*/||'
34497cf2ee2Smrg
345edce3322Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
346edce3322Smrg# metacharacters that are still active within double-quoted strings.
347edce3322Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
34897cf2ee2Smrg
349edce3322Smrg# Same as above, but do not quote variable references.
350edce3322Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
35197cf2ee2Smrg
352edce3322Smrg# Sed substitution that turns a string into a regex matching for the
353edce3322Smrg# string literally.
354edce3322Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
35597cf2ee2Smrg
356edce3322Smrg# Sed substitution that converts a w32 file name or path
357edce3322Smrg# that contains forward slashes, into one that contains
358edce3322Smrg# (escaped) backslashes.  A very naive implementation.
359edce3322Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360edce3322Smrg
361edce3322Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362edce3322Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363edce3322Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364edce3322Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
365edce3322Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366edce3322Smrg_G_bs='\\'
367edce3322Smrg_G_bs2='\\\\'
368edce3322Smrg_G_bs4='\\\\\\\\'
369edce3322Smrg_G_dollar='\$'
370edce3322Smrgsed_double_backslash="\
371edce3322Smrg  s/$_G_bs4/&\\
372edce3322Smrg/g
373edce3322Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374edce3322Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375edce3322Smrg  s/\n//g"
37697cf2ee2Smrg
37774835918Smrg# require_check_ifs_backslash
37874835918Smrg# ---------------------------
37974835918Smrg# Check if we can use backslash as IFS='\' separator, and set
38074835918Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
38174835918Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
38274835918Smrgfunc_require_check_ifs_backslash ()
38374835918Smrg{
38474835918Smrg  _G_save_IFS=$IFS
38574835918Smrg  IFS='\'
38674835918Smrg  _G_check_ifs_backshlash='a\\b'
38774835918Smrg  for _G_i in $_G_check_ifs_backshlash
38874835918Smrg  do
38974835918Smrg  case $_G_i in
39074835918Smrg  a)
39174835918Smrg    check_ifs_backshlash_broken=false
39274835918Smrg    ;;
39374835918Smrg  '')
39474835918Smrg    break
39574835918Smrg    ;;
39674835918Smrg  *)
39774835918Smrg    check_ifs_backshlash_broken=:
39874835918Smrg    break
39974835918Smrg    ;;
40074835918Smrg  esac
40174835918Smrg  done
40274835918Smrg  IFS=$_G_save_IFS
40374835918Smrg  require_check_ifs_backslash=:
40474835918Smrg}
40574835918Smrg
406a966c04fSmrg
407edce3322Smrg## ----------------- ##
408edce3322Smrg## Global variables. ##
409edce3322Smrg## ----------------- ##
4106e7d3316Smrg
411edce3322Smrg# Except for the global variables explicitly listed below, the following
412edce3322Smrg# functions in the '^func_' namespace, and the '^require_' namespace
413edce3322Smrg# variables initialised in the 'Resource management' section, sourcing
414edce3322Smrg# this file will not pollute your global namespace with anything
415edce3322Smrg# else. There's no portable way to scope variables in Bourne shell
416edce3322Smrg# though, so actually running these functions will sometimes place
417edce3322Smrg# results into a variable named after the function, and often use
418edce3322Smrg# temporary variables in the '^_G_' namespace. If you are careful to
419edce3322Smrg# avoid using those namespaces casually in your sourcing script, things
420edce3322Smrg# should continue to work as you expect. And, of course, you can freely
421edce3322Smrg# overwrite any of the functions or variables defined here before
422edce3322Smrg# calling anything to customize them.
4236e7d3316Smrg
424edce3322SmrgEXIT_SUCCESS=0
425edce3322SmrgEXIT_FAILURE=1
426edce3322SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427edce3322SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
4286e7d3316Smrg
429edce3322Smrg# Allow overriding, eg assuming that you follow the convention of
430edce3322Smrg# putting '$debug_cmd' at the start of all your functions, you can get
431edce3322Smrg# bash to show function call trace with:
432edce3322Smrg#
433edce3322Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434edce3322Smrgdebug_cmd=${debug_cmd-":"}
435edce3322Smrgexit_cmd=:
4366e7d3316Smrg
437edce3322Smrg# By convention, finish your script with:
438edce3322Smrg#
439edce3322Smrg#    exit $exit_status
440edce3322Smrg#
441edce3322Smrg# so that you can set exit_status to non-zero if you want to indicate
442edce3322Smrg# something went wrong during execution without actually bailing out at
443edce3322Smrg# the point of failure.
444edce3322Smrgexit_status=$EXIT_SUCCESS
4456e7d3316Smrg
446edce3322Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447edce3322Smrg# is ksh but when the shell is invoked as "sh" and the current value of
448edce3322Smrg# the _XPG environment variable is not equal to 1 (one), the special
449edce3322Smrg# positional parameter $0, within a function call, is the name of the
450edce3322Smrg# function.
451edce3322Smrgprogpath=$0
4526e7d3316Smrg
453edce3322Smrg# The name of this program.
454edce3322Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
4556e7d3316Smrg
456edce3322Smrg# Make sure we have an absolute progpath for reexecution:
4576e7d3316Smrgcase $progpath in
4586e7d3316Smrg  [\\/]*|[A-Za-z]:\\*) ;;
4596e7d3316Smrg  *[\\/]*)
460edce3322Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
4616e7d3316Smrg     progdir=`cd "$progdir" && pwd`
462edce3322Smrg     progpath=$progdir/$progname
4636e7d3316Smrg     ;;
4646e7d3316Smrg  *)
465edce3322Smrg     _G_IFS=$IFS
466ac92798bSmrg     IFS=${PATH_SEPARATOR-:}
4676e7d3316Smrg     for progdir in $PATH; do
468edce3322Smrg       IFS=$_G_IFS
4696e7d3316Smrg       test -x "$progdir/$progname" && break
4706e7d3316Smrg     done
471edce3322Smrg     IFS=$_G_IFS
4726e7d3316Smrg     test -n "$progdir" || progdir=`pwd`
473edce3322Smrg     progpath=$progdir/$progname
4746e7d3316Smrg     ;;
4756e7d3316Smrgesac
4766e7d3316Smrg
4776e7d3316Smrg
478edce3322Smrg## ----------------- ##
479edce3322Smrg## Standard options. ##
480edce3322Smrg## ----------------- ##
48197cf2ee2Smrg
482edce3322Smrg# The following options affect the operation of the functions defined
483edce3322Smrg# below, and should be set appropriately depending on run-time para-
484edce3322Smrg# meters passed on the command line.
4856e7d3316Smrg
4866e7d3316Smrgopt_dry_run=false
4876e7d3316Smrgopt_quiet=false
4886e7d3316Smrgopt_verbose=false
4896e7d3316Smrg
490edce3322Smrg# Categories 'all' and 'none' are always available.  Append any others
491edce3322Smrg# you will pass as the first argument to func_warning from your own
492edce3322Smrg# code.
493edce3322Smrgwarning_categories=
4946e7d3316Smrg
495edce3322Smrg# By default, display warnings according to 'opt_warning_types'.  Set
496edce3322Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497edce3322Smrg# treat the next displayed warning as a fatal error.
498edce3322Smrgwarning_func=func_warn_and_continue
4996e7d3316Smrg
500edce3322Smrg# Set to 'all' to display all warnings, 'none' to suppress all
501edce3322Smrg# warnings, or a space delimited list of some subset of
502edce3322Smrg# 'warning_categories' to display only the listed warnings.
503edce3322Smrgopt_warning_types=all
5046e7d3316Smrg
5056e7d3316Smrg
506edce3322Smrg## -------------------- ##
507edce3322Smrg## Resource management. ##
508edce3322Smrg## -------------------- ##
5096e7d3316Smrg
510edce3322Smrg# This section contains definitions for functions that each ensure a
511edce3322Smrg# particular resource (a file, or a non-empty configuration variable for
512edce3322Smrg# example) is available, and if appropriate to extract default values
513edce3322Smrg# from pertinent package files. Call them using their associated
514edce3322Smrg# 'require_*' variable to ensure that they are executed, at most, once.
515edce3322Smrg#
516edce3322Smrg# It's entirely deliberate that calling these functions can set
517edce3322Smrg# variables that don't obey the namespace limitations obeyed by the rest
518edce3322Smrg# of this file, in order that that they be as useful as possible to
519edce3322Smrg# callers.
5206e7d3316Smrg
5216e7d3316Smrg
522edce3322Smrg# require_term_colors
523edce3322Smrg# -------------------
524edce3322Smrg# Allow display of bold text on terminals that support it.
525edce3322Smrgrequire_term_colors=func_require_term_colors
526edce3322Smrgfunc_require_term_colors ()
5276e7d3316Smrg{
528edce3322Smrg    $debug_cmd
529edce3322Smrg
530edce3322Smrg    test -t 1 && {
531edce3322Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532edce3322Smrg      # precedence, because most terminfo databases neglect to describe
533edce3322Smrg      # whether color sequences are supported.
534edce3322Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535edce3322Smrg
536edce3322Smrg      if test 1 = "$USE_ANSI_COLORS"; then
537edce3322Smrg        # Standard ANSI escape sequences
538edce3322Smrg        tc_reset='[0m'
539edce3322Smrg        tc_bold='[1m';   tc_standout='[7m'
540edce3322Smrg        tc_red='[31m';   tc_green='[32m'
541edce3322Smrg        tc_blue='[34m';  tc_cyan='[36m'
542edce3322Smrg      else
543edce3322Smrg        # Otherwise trust the terminfo database after all.
544edce3322Smrg        test -n "`tput sgr0 2>/dev/null`" && {
545edce3322Smrg          tc_reset=`tput sgr0`
546edce3322Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547edce3322Smrg          tc_standout=$tc_bold
548edce3322Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549edce3322Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550edce3322Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551edce3322Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552edce3322Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553edce3322Smrg        }
554edce3322Smrg      fi
555edce3322Smrg    }
5566e7d3316Smrg
557edce3322Smrg    require_term_colors=:
5586e7d3316Smrg}
5596e7d3316Smrg
5606e7d3316Smrg
561edce3322Smrg## ----------------- ##
562edce3322Smrg## Function library. ##
563edce3322Smrg## ----------------- ##
564edce3322Smrg
565edce3322Smrg# This section contains a variety of useful functions to call in your
566edce3322Smrg# scripts. Take note of the portable wrappers for features provided by
567edce3322Smrg# some modern shells, which will fall back to slower equivalents on
568edce3322Smrg# less featureful shells.
569edce3322Smrg
570edce3322Smrg
571edce3322Smrg# func_append VAR VALUE
572edce3322Smrg# ---------------------
573edce3322Smrg# Append VALUE onto the existing contents of VAR.
574edce3322Smrg
575edce3322Smrg  # We should try to minimise forks, especially on Windows where they are
576edce3322Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577edce3322Smrg  # being used:
578edce3322Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579edce3322Smrg    : ${_G_HAVE_ARITH_OP="yes"}
580edce3322Smrg    : ${_G_HAVE_XSI_OPS="yes"}
581edce3322Smrg    # The += operator was introduced in bash 3.1
582edce3322Smrg    case $BASH_VERSION in
583edce3322Smrg      [12].* | 3.0 | 3.0*) ;;
584edce3322Smrg      *)
585edce3322Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586edce3322Smrg        ;;
587edce3322Smrg    esac
588edce3322Smrg  fi
589edce3322Smrg
590edce3322Smrg  # _G_HAVE_PLUSEQ_OP
591edce3322Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
592edce3322Smrg  # useable or anything else if it does not work.
593edce3322Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594edce3322Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595edce3322Smrg    && _G_HAVE_PLUSEQ_OP=yes
596edce3322Smrg
597edce3322Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598edce3322Smrgthen
599edce3322Smrg  # This is an XSI compatible shell, allowing a faster implementation...
600edce3322Smrg  eval 'func_append ()
601edce3322Smrg  {
602edce3322Smrg    $debug_cmd
603edce3322Smrg
604edce3322Smrg    eval "$1+=\$2"
605edce3322Smrg  }'
606edce3322Smrgelse
607edce3322Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608edce3322Smrg  func_append ()
609edce3322Smrg  {
610edce3322Smrg    $debug_cmd
611edce3322Smrg
612edce3322Smrg    eval "$1=\$$1\$2"
613edce3322Smrg  }
614edce3322Smrgfi
615edce3322Smrg
616edce3322Smrg
617edce3322Smrg# func_append_quoted VAR VALUE
618edce3322Smrg# ----------------------------
619edce3322Smrg# Quote VALUE and append to the end of shell variable VAR, separated
620edce3322Smrg# by a space.
621edce3322Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622edce3322Smrg  eval 'func_append_quoted ()
623edce3322Smrg  {
624edce3322Smrg    $debug_cmd
625edce3322Smrg
62674835918Smrg    func_quote_arg pretty "$2"
62774835918Smrg    eval "$1+=\\ \$func_quote_arg_result"
628edce3322Smrg  }'
629edce3322Smrgelse
630edce3322Smrg  func_append_quoted ()
631edce3322Smrg  {
632edce3322Smrg    $debug_cmd
633edce3322Smrg
63474835918Smrg    func_quote_arg pretty "$2"
63574835918Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636edce3322Smrg  }
637edce3322Smrgfi
638edce3322Smrg
639edce3322Smrg
640edce3322Smrg# func_append_uniq VAR VALUE
641edce3322Smrg# --------------------------
642edce3322Smrg# Append unique VALUE onto the existing contents of VAR, assuming
643edce3322Smrg# entries are delimited by the first character of VALUE.  For example:
644edce3322Smrg#
645edce3322Smrg#   func_append_uniq options " --another-option option-argument"
646edce3322Smrg#
647edce3322Smrg# will only append to $options if " --another-option option-argument "
648edce3322Smrg# is not already present somewhere in $options already (note spaces at
649edce3322Smrg# each end implied by leading space in second argument).
650edce3322Smrgfunc_append_uniq ()
651edce3322Smrg{
652edce3322Smrg    $debug_cmd
653edce3322Smrg
654edce3322Smrg    eval _G_current_value='`$ECHO $'$1'`'
655edce3322Smrg    _G_delim=`expr "$2" : '\(.\)'`
656edce3322Smrg
657edce3322Smrg    case $_G_delim$_G_current_value$_G_delim in
658edce3322Smrg      *"$2$_G_delim"*) ;;
659edce3322Smrg      *) func_append "$@" ;;
660edce3322Smrg    esac
661edce3322Smrg}
662edce3322Smrg
663edce3322Smrg
664edce3322Smrg# func_arith TERM...
665edce3322Smrg# ------------------
666edce3322Smrg# Set func_arith_result to the result of evaluating TERMs.
667edce3322Smrg  test -z "$_G_HAVE_ARITH_OP" \
668edce3322Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669edce3322Smrg    && _G_HAVE_ARITH_OP=yes
670edce3322Smrg
671edce3322Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
672edce3322Smrg  eval 'func_arith ()
673edce3322Smrg  {
674edce3322Smrg    $debug_cmd
675edce3322Smrg
676edce3322Smrg    func_arith_result=$(( $* ))
677edce3322Smrg  }'
678edce3322Smrgelse
679edce3322Smrg  func_arith ()
680edce3322Smrg  {
681edce3322Smrg    $debug_cmd
682edce3322Smrg
683edce3322Smrg    func_arith_result=`expr "$@"`
684edce3322Smrg  }
685edce3322Smrgfi
686edce3322Smrg
687edce3322Smrg
688edce3322Smrg# func_basename FILE
689edce3322Smrg# ------------------
690edce3322Smrg# Set func_basename_result to FILE with everything up to and including
691edce3322Smrg# the last / stripped.
692edce3322Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
693edce3322Smrg  # If this shell supports suffix pattern removal, then use it to avoid
694edce3322Smrg  # forking. Hide the definitions single quotes in case the shell chokes
695edce3322Smrg  # on unsupported syntax...
696edce3322Smrg  _b='func_basename_result=${1##*/}'
697edce3322Smrg  _d='case $1 in
698edce3322Smrg        */*) func_dirname_result=${1%/*}$2 ;;
699edce3322Smrg        *  ) func_dirname_result=$3        ;;
700edce3322Smrg      esac'
701edce3322Smrg
702edce3322Smrgelse
703edce3322Smrg  # ...otherwise fall back to using sed.
704edce3322Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705edce3322Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706edce3322Smrg      if test "X$func_dirname_result" = "X$1"; then
707edce3322Smrg        func_dirname_result=$3
708edce3322Smrg      else
709edce3322Smrg        func_append func_dirname_result "$2"
710edce3322Smrg      fi'
711edce3322Smrgfi
712edce3322Smrg
713edce3322Smrgeval 'func_basename ()
714edce3322Smrg{
715edce3322Smrg    $debug_cmd
716edce3322Smrg
717edce3322Smrg    '"$_b"'
718edce3322Smrg}'
719edce3322Smrg
720edce3322Smrg
721edce3322Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722edce3322Smrg# -------------------------------------------
723edce3322Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724edce3322Smrg# otherwise set result to NONDIR_REPLACEMENT.
725edce3322Smrgeval 'func_dirname ()
726edce3322Smrg{
727edce3322Smrg    $debug_cmd
728edce3322Smrg
729edce3322Smrg    '"$_d"'
730edce3322Smrg}'
731edce3322Smrg
732edce3322Smrg
733edce3322Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734edce3322Smrg# --------------------------------------------------------
735edce3322Smrg# Perform func_basename and func_dirname in a single function
736edce3322Smrg# call:
737edce3322Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738edce3322Smrg#             add APPEND to the result, otherwise set result
739edce3322Smrg#             to NONDIR_REPLACEMENT.
740edce3322Smrg#             value returned in "$func_dirname_result"
741edce3322Smrg#   basename: Compute filename of FILE.
742edce3322Smrg#             value retuned in "$func_basename_result"
743edce3322Smrg# For efficiency, we do not delegate to the functions above but instead
744edce3322Smrg# duplicate the functionality here.
745edce3322Smrgeval 'func_dirname_and_basename ()
746edce3322Smrg{
747edce3322Smrg    $debug_cmd
748edce3322Smrg
749edce3322Smrg    '"$_b"'
750edce3322Smrg    '"$_d"'
751edce3322Smrg}'
752edce3322Smrg
753edce3322Smrg
754edce3322Smrg# func_echo ARG...
755edce3322Smrg# ----------------
756edce3322Smrg# Echo program name prefixed message.
757edce3322Smrgfunc_echo ()
758edce3322Smrg{
759edce3322Smrg    $debug_cmd
760edce3322Smrg
761edce3322Smrg    _G_message=$*
762edce3322Smrg
763edce3322Smrg    func_echo_IFS=$IFS
764edce3322Smrg    IFS=$nl
765edce3322Smrg    for _G_line in $_G_message; do
766edce3322Smrg      IFS=$func_echo_IFS
767edce3322Smrg      $ECHO "$progname: $_G_line"
768edce3322Smrg    done
769edce3322Smrg    IFS=$func_echo_IFS
770edce3322Smrg}
771edce3322Smrg
772edce3322Smrg
773edce3322Smrg# func_echo_all ARG...
774edce3322Smrg# --------------------
775edce3322Smrg# Invoke $ECHO with all args, space-separated.
776edce3322Smrgfunc_echo_all ()
777edce3322Smrg{
778edce3322Smrg    $ECHO "$*"
779edce3322Smrg}
780edce3322Smrg
781edce3322Smrg
782edce3322Smrg# func_echo_infix_1 INFIX ARG...
783edce3322Smrg# ------------------------------
784edce3322Smrg# Echo program name, followed by INFIX on the first line, with any
785edce3322Smrg# additional lines not showing INFIX.
786edce3322Smrgfunc_echo_infix_1 ()
787edce3322Smrg{
788edce3322Smrg    $debug_cmd
789edce3322Smrg
790edce3322Smrg    $require_term_colors
791edce3322Smrg
792edce3322Smrg    _G_infix=$1; shift
793edce3322Smrg    _G_indent=$_G_infix
794edce3322Smrg    _G_prefix="$progname: $_G_infix: "
795edce3322Smrg    _G_message=$*
796edce3322Smrg
797edce3322Smrg    # Strip color escape sequences before counting printable length
798edce3322Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799edce3322Smrg    do
800edce3322Smrg      test -n "$_G_tc" && {
801edce3322Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802edce3322Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803edce3322Smrg      }
804edce3322Smrg    done
805edce3322Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806edce3322Smrg
807edce3322Smrg    func_echo_infix_1_IFS=$IFS
808edce3322Smrg    IFS=$nl
809edce3322Smrg    for _G_line in $_G_message; do
810edce3322Smrg      IFS=$func_echo_infix_1_IFS
811edce3322Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812edce3322Smrg      _G_prefix=$_G_indent
813edce3322Smrg    done
814edce3322Smrg    IFS=$func_echo_infix_1_IFS
815edce3322Smrg}
816edce3322Smrg
817edce3322Smrg
818edce3322Smrg# func_error ARG...
819edce3322Smrg# -----------------
820edce3322Smrg# Echo program name prefixed message to standard error.
821edce3322Smrgfunc_error ()
822edce3322Smrg{
823edce3322Smrg    $debug_cmd
824edce3322Smrg
825edce3322Smrg    $require_term_colors
826edce3322Smrg
827edce3322Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828edce3322Smrg}
829edce3322Smrg
830edce3322Smrg
831edce3322Smrg# func_fatal_error ARG...
832edce3322Smrg# -----------------------
833edce3322Smrg# Echo program name prefixed message to standard error, and exit.
834edce3322Smrgfunc_fatal_error ()
835edce3322Smrg{
836edce3322Smrg    $debug_cmd
837edce3322Smrg
838edce3322Smrg    func_error "$*"
839edce3322Smrg    exit $EXIT_FAILURE
840edce3322Smrg}
841edce3322Smrg
842edce3322Smrg
843edce3322Smrg# func_grep EXPRESSION FILENAME
844edce3322Smrg# -----------------------------
8456e7d3316Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
8466e7d3316Smrgfunc_grep ()
8476e7d3316Smrg{
848edce3322Smrg    $debug_cmd
849edce3322Smrg
8506e7d3316Smrg    $GREP "$1" "$2" >/dev/null 2>&1
8516e7d3316Smrg}
8526e7d3316Smrg
8536e7d3316Smrg
854edce3322Smrg# func_len STRING
855edce3322Smrg# ---------------
856edce3322Smrg# Set func_len_result to the length of STRING. STRING may not
857edce3322Smrg# start with a hyphen.
858edce3322Smrg  test -z "$_G_HAVE_XSI_OPS" \
859edce3322Smrg    && (eval 'x=a/b/c;
860edce3322Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861edce3322Smrg    && _G_HAVE_XSI_OPS=yes
862edce3322Smrg
863edce3322Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
864edce3322Smrg  eval 'func_len ()
865edce3322Smrg  {
866edce3322Smrg    $debug_cmd
867edce3322Smrg
868edce3322Smrg    func_len_result=${#1}
869edce3322Smrg  }'
870edce3322Smrgelse
871edce3322Smrg  func_len ()
872edce3322Smrg  {
873edce3322Smrg    $debug_cmd
874edce3322Smrg
875edce3322Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876edce3322Smrg  }
877edce3322Smrgfi
878edce3322Smrg
879edce3322Smrg
880edce3322Smrg# func_mkdir_p DIRECTORY-PATH
881edce3322Smrg# ---------------------------
8826e7d3316Smrg# Make sure the entire path to DIRECTORY-PATH is available.
8836e7d3316Smrgfunc_mkdir_p ()
8846e7d3316Smrg{
885edce3322Smrg    $debug_cmd
886edce3322Smrg
887edce3322Smrg    _G_directory_path=$1
888edce3322Smrg    _G_dir_list=
8896e7d3316Smrg
890edce3322Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8916e7d3316Smrg
892edce3322Smrg      # Protect directory names starting with '-'
893edce3322Smrg      case $_G_directory_path in
894edce3322Smrg        -*) _G_directory_path=./$_G_directory_path ;;
8956e7d3316Smrg      esac
8966e7d3316Smrg
8976e7d3316Smrg      # While some portion of DIR does not yet exist...
898edce3322Smrg      while test ! -d "$_G_directory_path"; do
8996e7d3316Smrg        # ...make a list in topmost first order.  Use a colon delimited
9006e7d3316Smrg	# list incase some portion of path contains whitespace.
901edce3322Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
9026e7d3316Smrg
9036e7d3316Smrg        # If the last portion added has no slash in it, the list is done
904edce3322Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
9056e7d3316Smrg
9066e7d3316Smrg        # ...otherwise throw away the child directory and loop
907edce3322Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
9086e7d3316Smrg      done
909edce3322Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
9106e7d3316Smrg
911edce3322Smrg      func_mkdir_p_IFS=$IFS; IFS=:
912edce3322Smrg      for _G_dir in $_G_dir_list; do
913edce3322Smrg	IFS=$func_mkdir_p_IFS
914edce3322Smrg        # mkdir can fail with a 'File exist' error if two processes
9156e7d3316Smrg        # try to create one of the directories concurrently.  Don't
9166e7d3316Smrg        # stop in that case!
917edce3322Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
9186e7d3316Smrg      done
919edce3322Smrg      IFS=$func_mkdir_p_IFS
9206e7d3316Smrg
9216e7d3316Smrg      # Bail out if we (or some other process) failed to create a directory.
922edce3322Smrg      test -d "$_G_directory_path" || \
923edce3322Smrg        func_fatal_error "Failed to create '$1'"
9246e7d3316Smrg    fi
9256e7d3316Smrg}
926a966c04fSmrg
927a966c04fSmrg
928edce3322Smrg# func_mktempdir [BASENAME]
929edce3322Smrg# -------------------------
930a966c04fSmrg# Make a temporary directory that won't clash with other running
931a966c04fSmrg# libtool processes, and avoids race conditions if possible.  If
932edce3322Smrg# given, BASENAME is the basename for that directory.
933a966c04fSmrgfunc_mktempdir ()
934a966c04fSmrg{
935edce3322Smrg    $debug_cmd
936edce3322Smrg
937edce3322Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938a966c04fSmrg
939edce3322Smrg    if test : = "$opt_dry_run"; then
940a966c04fSmrg      # Return a directory name, but don't create it in dry-run mode
941edce3322Smrg      _G_tmpdir=$_G_template-$$
942a966c04fSmrg    else
943a966c04fSmrg
944a966c04fSmrg      # If mktemp works, use that first and foremost
945edce3322Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946a966c04fSmrg
947edce3322Smrg      if test ! -d "$_G_tmpdir"; then
9486e7d3316Smrg        # Failing that, at least try and use $RANDOM to avoid a race
949edce3322Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950a966c04fSmrg
951edce3322Smrg        func_mktempdir_umask=`umask`
9526e7d3316Smrg        umask 0077
953edce3322Smrg        $MKDIR "$_G_tmpdir"
954edce3322Smrg        umask $func_mktempdir_umask
955a966c04fSmrg      fi
956a966c04fSmrg
957a966c04fSmrg      # If we're not in dry-run mode, bomb out on failure
958edce3322Smrg      test -d "$_G_tmpdir" || \
959edce3322Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960a966c04fSmrg    fi
961a966c04fSmrg
962edce3322Smrg    $ECHO "$_G_tmpdir"
963a966c04fSmrg}
964a966c04fSmrg
965a966c04fSmrg
966edce3322Smrg# func_normal_abspath PATH
967edce3322Smrg# ------------------------
968edce3322Smrg# Remove doubled-up and trailing slashes, "." path components,
969edce3322Smrg# and cancel out any ".." path components in PATH after making
970edce3322Smrg# it an absolute path.
971edce3322Smrgfunc_normal_abspath ()
972a966c04fSmrg{
973edce3322Smrg    $debug_cmd
9746e7d3316Smrg
975edce3322Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
976edce3322Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977edce3322Smrg    _G_pathcdr='s|^/[^/]*||'
978edce3322Smrg    _G_removedotparts=':dotsl
979edce3322Smrg		s|/\./|/|g
980edce3322Smrg		t dotsl
981edce3322Smrg		s|/\.$|/|'
982edce3322Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
983edce3322Smrg    _G_finalslash='s|/*$|/|'
984edce3322Smrg
985edce3322Smrg    # Start from root dir and reassemble the path.
986edce3322Smrg    func_normal_abspath_result=
987edce3322Smrg    func_normal_abspath_tpath=$1
988edce3322Smrg    func_normal_abspath_altnamespace=
989edce3322Smrg    case $func_normal_abspath_tpath in
990edce3322Smrg      "")
991edce3322Smrg        # Empty path, that just means $cwd.
992edce3322Smrg        func_stripname '' '/' "`pwd`"
993edce3322Smrg        func_normal_abspath_result=$func_stripname_result
994edce3322Smrg        return
995edce3322Smrg        ;;
996edce3322Smrg      # The next three entries are used to spot a run of precisely
997edce3322Smrg      # two leading slashes without using negated character classes;
998edce3322Smrg      # we take advantage of case's first-match behaviour.
999edce3322Smrg      ///*)
1000edce3322Smrg        # Unusual form of absolute path, do nothing.
1001edce3322Smrg        ;;
1002edce3322Smrg      //*)
1003edce3322Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004edce3322Smrg        # and for example Cygwin uses it to access remote file shares
1005edce3322Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006edce3322Smrg        func_normal_abspath_altnamespace=/
1007edce3322Smrg        ;;
1008edce3322Smrg      /*)
1009edce3322Smrg        # Absolute path, do nothing.
10106e7d3316Smrg        ;;
10116e7d3316Smrg      *)
1012edce3322Smrg        # Relative path, prepend $cwd.
1013edce3322Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014edce3322Smrg        ;;
1015a966c04fSmrg    esac
1016edce3322Smrg
1017edce3322Smrg    # Cancel out all the simple stuff to save iterations.  We also want
1018edce3322Smrg    # the path to end with a slash for ease of parsing, so make sure
1019edce3322Smrg    # there is one (and only one) here.
1020edce3322Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021edce3322Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022edce3322Smrg    while :; do
1023edce3322Smrg      # Processed it all yet?
1024edce3322Smrg      if test / = "$func_normal_abspath_tpath"; then
1025edce3322Smrg        # If we ascended to the root using ".." the result may be empty now.
1026edce3322Smrg        if test -z "$func_normal_abspath_result"; then
1027edce3322Smrg          func_normal_abspath_result=/
1028edce3322Smrg        fi
1029edce3322Smrg        break
1030edce3322Smrg      fi
1031edce3322Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032edce3322Smrg          -e "$_G_pathcar"`
1033edce3322Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034edce3322Smrg          -e "$_G_pathcdr"`
1035edce3322Smrg      # Figure out what to do with it
1036edce3322Smrg      case $func_normal_abspath_tcomponent in
1037edce3322Smrg        "")
1038edce3322Smrg          # Trailing empty path component, ignore it.
1039edce3322Smrg          ;;
1040edce3322Smrg        ..)
1041edce3322Smrg          # Parent dir; strip last assembled component from result.
1042edce3322Smrg          func_dirname "$func_normal_abspath_result"
1043edce3322Smrg          func_normal_abspath_result=$func_dirname_result
1044edce3322Smrg          ;;
1045edce3322Smrg        *)
1046edce3322Smrg          # Actual path component, append it.
1047edce3322Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048edce3322Smrg          ;;
1049edce3322Smrg      esac
1050edce3322Smrg    done
1051edce3322Smrg    # Restore leading double-slash if one was found on entry.
1052edce3322Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053edce3322Smrg}
1054edce3322Smrg
1055edce3322Smrg
1056edce3322Smrg# func_notquiet ARG...
1057edce3322Smrg# --------------------
1058edce3322Smrg# Echo program name prefixed message only when not in quiet mode.
1059edce3322Smrgfunc_notquiet ()
1060edce3322Smrg{
1061edce3322Smrg    $debug_cmd
1062edce3322Smrg
1063edce3322Smrg    $opt_quiet || func_echo ${1+"$@"}
1064edce3322Smrg
1065edce3322Smrg    # A bug in bash halts the script if the last line of a function
1066edce3322Smrg    # fails when set -e is in force, so we need another command to
1067edce3322Smrg    # work around that:
1068edce3322Smrg    :
1069edce3322Smrg}
1070edce3322Smrg
1071edce3322Smrg
1072edce3322Smrg# func_relative_path SRCDIR DSTDIR
1073edce3322Smrg# --------------------------------
1074edce3322Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075edce3322Smrgfunc_relative_path ()
1076edce3322Smrg{
1077edce3322Smrg    $debug_cmd
1078edce3322Smrg
1079edce3322Smrg    func_relative_path_result=
1080edce3322Smrg    func_normal_abspath "$1"
1081edce3322Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082edce3322Smrg    func_normal_abspath "$2"
1083edce3322Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1084edce3322Smrg
1085edce3322Smrg    # Ascend the tree starting from libdir
1086edce3322Smrg    while :; do
1087edce3322Smrg      # check if we have found a prefix of bindir
1088edce3322Smrg      case $func_relative_path_tbindir in
1089edce3322Smrg        $func_relative_path_tlibdir)
1090edce3322Smrg          # found an exact match
1091edce3322Smrg          func_relative_path_tcancelled=
1092edce3322Smrg          break
1093edce3322Smrg          ;;
1094edce3322Smrg        $func_relative_path_tlibdir*)
1095edce3322Smrg          # found a matching prefix
1096edce3322Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097edce3322Smrg          func_relative_path_tcancelled=$func_stripname_result
1098edce3322Smrg          if test -z "$func_relative_path_result"; then
1099edce3322Smrg            func_relative_path_result=.
1100edce3322Smrg          fi
1101edce3322Smrg          break
1102edce3322Smrg          ;;
1103edce3322Smrg        *)
1104edce3322Smrg          func_dirname $func_relative_path_tlibdir
1105edce3322Smrg          func_relative_path_tlibdir=$func_dirname_result
1106edce3322Smrg          if test -z "$func_relative_path_tlibdir"; then
1107edce3322Smrg            # Have to descend all the way to the root!
1108edce3322Smrg            func_relative_path_result=../$func_relative_path_result
1109edce3322Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110edce3322Smrg            break
1111edce3322Smrg          fi
1112edce3322Smrg          func_relative_path_result=../$func_relative_path_result
1113edce3322Smrg          ;;
1114edce3322Smrg      esac
1115edce3322Smrg    done
1116edce3322Smrg
1117edce3322Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1118edce3322Smrg    func_stripname '' '/' "$func_relative_path_result"
1119edce3322Smrg    func_relative_path_result=$func_stripname_result
1120edce3322Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121edce3322Smrg    if test -n "$func_stripname_result"; then
1122edce3322Smrg      func_append func_relative_path_result "/$func_stripname_result"
1123edce3322Smrg    fi
1124edce3322Smrg
1125edce3322Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126edce3322Smrg    if test -n "$func_relative_path_result"; then
1127edce3322Smrg      func_stripname './' '' "$func_relative_path_result"
1128edce3322Smrg      func_relative_path_result=$func_stripname_result
1129edce3322Smrg    fi
1130edce3322Smrg
1131edce3322Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132edce3322Smrg
1133edce3322Smrg    :
1134a966c04fSmrg}
1135a966c04fSmrg
1136a966c04fSmrg
113774835918Smrg# func_quote_portable EVAL ARG
113874835918Smrg# ----------------------------
113974835918Smrg# Internal function to portably implement func_quote_arg.  Note that we still
114074835918Smrg# keep attention to performance here so we as much as possible try to avoid
114174835918Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
114274835918Smrgfunc_quote_portable ()
1143edce3322Smrg{
1144edce3322Smrg    $debug_cmd
1145edce3322Smrg
114674835918Smrg    $require_check_ifs_backslash
114774835918Smrg
114874835918Smrg    func_quote_portable_result=$2
114974835918Smrg
115074835918Smrg    # one-time-loop (easy break)
115174835918Smrg    while true
115274835918Smrg    do
115374835918Smrg      if $1; then
115474835918Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
115574835918Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
115674835918Smrg        break
11571c235774Smrg      fi
115819569120Smrg
115974835918Smrg      # Quote for eval.
116074835918Smrg      case $func_quote_portable_result in
116174835918Smrg        *[\\\`\"\$]*)
116274835918Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
116374835918Smrg          # contains the shell wildcard characters.
116474835918Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
116574835918Smrg            :*|*[\[\*\?]*)
116674835918Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
116774835918Smrg                  | $SED "$sed_quote_subst"`
116874835918Smrg              break
116974835918Smrg              ;;
117074835918Smrg          esac
117174835918Smrg
117274835918Smrg          func_quote_portable_old_IFS=$IFS
117374835918Smrg          for _G_char in '\' '`' '"' '$'
117474835918Smrg          do
117574835918Smrg            # STATE($1) PREV($2) SEPARATOR($3)
117674835918Smrg            set start "" ""
117774835918Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
117874835918Smrg            IFS=$_G_char
117974835918Smrg            for _G_part in $func_quote_portable_result
118074835918Smrg            do
118174835918Smrg              case $1 in
118274835918Smrg              quote)
118374835918Smrg                func_append func_quote_portable_result "$3$2"
118474835918Smrg                set quote "$_G_part" "\\$_G_char"
118574835918Smrg                ;;
118674835918Smrg              start)
118774835918Smrg                set first "" ""
118874835918Smrg                func_quote_portable_result=
118974835918Smrg                ;;
119074835918Smrg              first)
119174835918Smrg                set quote "$_G_part" ""
119274835918Smrg                ;;
119374835918Smrg              esac
119474835918Smrg            done
119574835918Smrg          done
119674835918Smrg          IFS=$func_quote_portable_old_IFS
1197edce3322Smrg          ;;
119874835918Smrg        *) ;;
1199edce3322Smrg      esac
120074835918Smrg      break
12011c235774Smrg    done
120274835918Smrg
120374835918Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
120474835918Smrg    case $func_quote_portable_result in
120574835918Smrg      # double-quote args containing shell metacharacters to delay
120674835918Smrg      # word splitting, command substitution and variable expansion
120774835918Smrg      # for a subsequent eval.
120874835918Smrg      # many bourne shells cannot handle close brackets correctly
120974835918Smrg      # in scan sets, so we specify it separately.
121074835918Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
121174835918Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
121274835918Smrg        ;;
121374835918Smrg    esac
1214edce3322Smrg}
1215edce3322Smrg
1216edce3322Smrg
121774835918Smrg# func_quotefast_eval ARG
121874835918Smrg# -----------------------
121974835918Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
122074835918Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
122174835918Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
122274835918Smrg  printf -v _GL_test_printf_tilde %q '~'
122374835918Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
122474835918Smrg    func_quotefast_eval ()
122574835918Smrg    {
122674835918Smrg      printf -v func_quotefast_eval_result %q "$1"
122774835918Smrg    }
122874835918Smrg  else
122974835918Smrg    # Broken older Bash implementations.  Make those faster too if possible.
123074835918Smrg    func_quotefast_eval ()
123174835918Smrg    {
123274835918Smrg      case $1 in
123374835918Smrg        '~'*)
123474835918Smrg          func_quote_portable false "$1"
123574835918Smrg          func_quotefast_eval_result=$func_quote_portable_result
123674835918Smrg          ;;
123774835918Smrg        *)
123874835918Smrg          printf -v func_quotefast_eval_result %q "$1"
123974835918Smrg          ;;
124074835918Smrg      esac
124174835918Smrg    }
124274835918Smrg  fi
124374835918Smrgelse
124474835918Smrg  func_quotefast_eval ()
124574835918Smrg  {
124674835918Smrg    func_quote_portable false "$1"
124774835918Smrg    func_quotefast_eval_result=$func_quote_portable_result
124874835918Smrg  }
124974835918Smrgfi
125019569120Smrg
125174835918Smrg
125274835918Smrg# func_quote_arg MODEs ARG
125374835918Smrg# ------------------------
125474835918Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
125574835918Smrg# specifiers listed below separated by ',' character.  This function returns two
125674835918Smrg# values:
125774835918Smrg#   i) func_quote_arg_result
125874835918Smrg#      double-quoted (when needed), suitable for a subsequent eval
125974835918Smrg#  ii) func_quote_arg_unquoted_result
126074835918Smrg#      has all characters that are still active within double
126174835918Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
126274835918Smrg#
126374835918Smrg# Available modes:
126474835918Smrg# ----------------
126574835918Smrg# 'eval' (default)
126674835918Smrg#       - escape shell special characters
126774835918Smrg# 'expand'
126874835918Smrg#       - the same as 'eval';  but do not quote variable references
126974835918Smrg# 'pretty'
127074835918Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
127174835918Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
127274835918Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
127374835918Smrg# 'unquoted'
127474835918Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
127574835918Smrg#         wrapping double-quotes.
127674835918Smrg#
127774835918Smrg# Examples for 'func_quote_arg pretty,unquoted string':
127874835918Smrg#
127974835918Smrg#   string      | *_result              | *_unquoted_result
128074835918Smrg#   ------------+-----------------------+-------------------
128174835918Smrg#   "           | \"                    | \"
128274835918Smrg#   a b         | "a b"                 | a b
128374835918Smrg#   "a b"       | "\"a b\""             | \"a b\"
128474835918Smrg#   *           | "*"                   | *
128574835918Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
128674835918Smrg#
128774835918Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
128874835918Smrg#
128974835918Smrg#   string        |   *_result          |  *_unquoted_result
129074835918Smrg#   --------------+---------------------+--------------------
129174835918Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
129274835918Smrgfunc_quote_arg ()
129374835918Smrg{
129474835918Smrg    _G_quote_expand=false
129574835918Smrg    case ,$1, in
129674835918Smrg      *,expand,*)
129774835918Smrg        _G_quote_expand=:
129874835918Smrg        ;;
12996e7d3316Smrg    esac
13006e7d3316Smrg
130174835918Smrg    case ,$1, in
130274835918Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
130374835918Smrg        func_quote_portable $_G_quote_expand "$2"
130474835918Smrg        func_quote_arg_result=$func_quote_portable_result
130574835918Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
130674835918Smrg        ;;
130774835918Smrg      *)
130874835918Smrg        # Faster quote-for-eval for some shells.
130974835918Smrg        func_quotefast_eval "$2"
131074835918Smrg        func_quote_arg_result=$func_quotefast_eval_result
13116e7d3316Smrg        ;;
13126e7d3316Smrg    esac
131374835918Smrg}
13146e7d3316Smrg
131574835918Smrg
131674835918Smrg# func_quote MODEs ARGs...
131774835918Smrg# ------------------------
131874835918Smrg# Quote all ARGs to be evaled later and join them into single command.  See
131974835918Smrg# func_quote_arg's description for more info.
132074835918Smrgfunc_quote ()
132174835918Smrg{
132274835918Smrg    $debug_cmd
132374835918Smrg    _G_func_quote_mode=$1 ; shift
132474835918Smrg    func_quote_result=
132574835918Smrg    while test 0 -lt $#; do
132674835918Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
132774835918Smrg      if test -n "$func_quote_result"; then
132874835918Smrg        func_append func_quote_result " $func_quote_arg_result"
132974835918Smrg      else
133074835918Smrg        func_append func_quote_result "$func_quote_arg_result"
133174835918Smrg      fi
133274835918Smrg      shift
133374835918Smrg    done
1334edce3322Smrg}
1335edce3322Smrg
1336edce3322Smrg
1337edce3322Smrg# func_stripname PREFIX SUFFIX NAME
1338edce3322Smrg# ---------------------------------
1339edce3322Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340edce3322Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1341edce3322Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342edce3322Smrg# dot (in which case that matches only a dot).
1343edce3322Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344edce3322Smrg  eval 'func_stripname ()
1345edce3322Smrg  {
1346edce3322Smrg    $debug_cmd
1347edce3322Smrg
1348edce3322Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349edce3322Smrg    # positional parameters, so assign one to ordinary variable first.
1350edce3322Smrg    func_stripname_result=$3
1351edce3322Smrg    func_stripname_result=${func_stripname_result#"$1"}
1352edce3322Smrg    func_stripname_result=${func_stripname_result%"$2"}
1353edce3322Smrg  }'
1354edce3322Smrgelse
1355edce3322Smrg  func_stripname ()
1356edce3322Smrg  {
1357edce3322Smrg    $debug_cmd
1358edce3322Smrg
1359edce3322Smrg    case $2 in
1360edce3322Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361edce3322Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362edce3322Smrg    esac
1363edce3322Smrg  }
1364edce3322Smrgfi
1365edce3322Smrg
1366edce3322Smrg
1367edce3322Smrg# func_show_eval CMD [FAIL_EXP]
1368edce3322Smrg# -----------------------------
1369edce3322Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370edce3322Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371edce3322Smrg# is given, then evaluate it.
1372edce3322Smrgfunc_show_eval ()
1373edce3322Smrg{
1374edce3322Smrg    $debug_cmd
1375edce3322Smrg
1376edce3322Smrg    _G_cmd=$1
1377edce3322Smrg    _G_fail_exp=${2-':'}
1378edce3322Smrg
137974835918Smrg    func_quote_arg pretty,expand "$_G_cmd"
138074835918Smrg    eval "func_notquiet $func_quote_arg_result"
1381edce3322Smrg
1382edce3322Smrg    $opt_dry_run || {
1383edce3322Smrg      eval "$_G_cmd"
1384edce3322Smrg      _G_status=$?
1385edce3322Smrg      if test 0 -ne "$_G_status"; then
1386edce3322Smrg	eval "(exit $_G_status); $_G_fail_exp"
1387edce3322Smrg      fi
1388edce3322Smrg    }
1389edce3322Smrg}
1390edce3322Smrg
1391edce3322Smrg
1392edce3322Smrg# func_show_eval_locale CMD [FAIL_EXP]
1393edce3322Smrg# ------------------------------------
1394edce3322Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395edce3322Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396edce3322Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397edce3322Smrgfunc_show_eval_locale ()
1398edce3322Smrg{
1399edce3322Smrg    $debug_cmd
1400edce3322Smrg
1401edce3322Smrg    _G_cmd=$1
1402edce3322Smrg    _G_fail_exp=${2-':'}
1403edce3322Smrg
1404edce3322Smrg    $opt_quiet || {
140574835918Smrg      func_quote_arg expand,pretty "$_G_cmd"
140674835918Smrg      eval "func_echo $func_quote_arg_result"
1407edce3322Smrg    }
1408edce3322Smrg
1409edce3322Smrg    $opt_dry_run || {
1410edce3322Smrg      eval "$_G_user_locale
1411edce3322Smrg	    $_G_cmd"
1412edce3322Smrg      _G_status=$?
1413edce3322Smrg      eval "$_G_safe_locale"
1414edce3322Smrg      if test 0 -ne "$_G_status"; then
1415edce3322Smrg	eval "(exit $_G_status); $_G_fail_exp"
1416edce3322Smrg      fi
1417edce3322Smrg    }
1418edce3322Smrg}
1419edce3322Smrg
1420edce3322Smrg
1421edce3322Smrg# func_tr_sh
1422edce3322Smrg# ----------
1423edce3322Smrg# Turn $1 into a string suitable for a shell variable name.
1424edce3322Smrg# Result is stored in $func_tr_sh_result.  All characters
1425edce3322Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426edce3322Smrg# if $1 begins with a digit, a '_' is prepended as well.
1427edce3322Smrgfunc_tr_sh ()
1428edce3322Smrg{
1429edce3322Smrg    $debug_cmd
1430edce3322Smrg
1431edce3322Smrg    case $1 in
1432edce3322Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433edce3322Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434edce3322Smrg      ;;
1435edce3322Smrg    * )
1436edce3322Smrg      func_tr_sh_result=$1
1437edce3322Smrg      ;;
1438edce3322Smrg    esac
1439edce3322Smrg}
1440edce3322Smrg
1441edce3322Smrg
1442edce3322Smrg# func_verbose ARG...
1443edce3322Smrg# -------------------
1444edce3322Smrg# Echo program name prefixed message in verbose mode only.
1445edce3322Smrgfunc_verbose ()
1446edce3322Smrg{
1447edce3322Smrg    $debug_cmd
1448edce3322Smrg
1449edce3322Smrg    $opt_verbose && func_echo "$*"
1450edce3322Smrg
1451edce3322Smrg    :
1452edce3322Smrg}
1453edce3322Smrg
1454edce3322Smrg
1455edce3322Smrg# func_warn_and_continue ARG...
1456edce3322Smrg# -----------------------------
1457edce3322Smrg# Echo program name prefixed warning message to standard error.
1458edce3322Smrgfunc_warn_and_continue ()
1459edce3322Smrg{
1460edce3322Smrg    $debug_cmd
1461edce3322Smrg
1462edce3322Smrg    $require_term_colors
1463edce3322Smrg
1464edce3322Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465edce3322Smrg}
1466edce3322Smrg
1467edce3322Smrg
1468edce3322Smrg# func_warning CATEGORY ARG...
1469edce3322Smrg# ----------------------------
1470edce3322Smrg# Echo program name prefixed warning message to standard error. Warning
1471edce3322Smrg# messages can be filtered according to CATEGORY, where this function
1472edce3322Smrg# elides messages where CATEGORY is not listed in the global variable
1473edce3322Smrg# 'opt_warning_types'.
1474edce3322Smrgfunc_warning ()
1475edce3322Smrg{
1476edce3322Smrg    $debug_cmd
1477edce3322Smrg
1478edce3322Smrg    # CATEGORY must be in the warning_categories list!
1479edce3322Smrg    case " $warning_categories " in
1480edce3322Smrg      *" $1 "*) ;;
1481edce3322Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1482edce3322Smrg    esac
1483edce3322Smrg
1484edce3322Smrg    _G_category=$1
1485edce3322Smrg    shift
1486edce3322Smrg
1487edce3322Smrg    case " $opt_warning_types " in
1488edce3322Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489edce3322Smrg    esac
1490a966c04fSmrg}
1491a966c04fSmrg
1492a966c04fSmrg
1493edce3322Smrg# func_sort_ver VER1 VER2
1494edce3322Smrg# -----------------------
1495edce3322Smrg# 'sort -V' is not generally available.
1496edce3322Smrg# Note this deviates from the version comparison in automake
1497edce3322Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498edce3322Smrg# but this should suffice as we won't be specifying old
1499edce3322Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1500edce3322Smrg# If we did want full compatibility then we should probably
1501edce3322Smrg# use m4_version_compare from autoconf.
1502edce3322Smrgfunc_sort_ver ()
1503edce3322Smrg{
1504edce3322Smrg    $debug_cmd
1505edce3322Smrg
1506edce3322Smrg    printf '%s\n%s\n' "$1" "$2" \
1507edce3322Smrg      | 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
1508edce3322Smrg}
1509edce3322Smrg
1510edce3322Smrg# func_lt_ver PREV CURR
1511edce3322Smrg# ---------------------
1512edce3322Smrg# Return true if PREV and CURR are in the correct order according to
1513edce3322Smrg# func_sort_ver, otherwise false.  Use it like this:
1514edce3322Smrg#
1515edce3322Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516edce3322Smrgfunc_lt_ver ()
1517edce3322Smrg{
1518edce3322Smrg    $debug_cmd
1519edce3322Smrg
1520edce3322Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521edce3322Smrg}
1522edce3322Smrg
1523edce3322Smrg
1524edce3322Smrg# Local variables:
1525edce3322Smrg# mode: shell-script
1526edce3322Smrg# sh-indentation: 2
1527edce3322Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528edce3322Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529edce3322Smrg# time-stamp-time-zone: "UTC"
1530edce3322Smrg# End:
1531edce3322Smrg#! /bin/sh
1532edce3322Smrg
1533edce3322Smrg# A portable, pluggable option parser for Bourne shell.
1534edce3322Smrg# Written by Gary V. Vaughan, 2010
1535edce3322Smrg
153674835918Smrg# This is free software.  There is NO warranty; not even for
153774835918Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
153874835918Smrg#
153974835918Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
154074835918Smrg#
154174835918Smrg# This file is dual licensed under the terms of the MIT license
154274835918Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
154374835918Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
154474835918Smrg# these licenses when using or redistributing this software or any of
154574835918Smrg# the files within it.  See the URLs above, or the file `LICENSE`
154674835918Smrg# included in the Bootstrap distribution for the full license texts.
15471c235774Smrg
154874835918Smrg# Please report bugs or propose patches to:
154974835918Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
15501c235774Smrg
155174835918Smrg# Set a version string for this script.
155274835918Smrgscriptversion=2019-02-19.15; # UTC
1553edce3322Smrg
1554edce3322Smrg
1555edce3322Smrg## ------ ##
1556edce3322Smrg## Usage. ##
1557edce3322Smrg## ------ ##
1558edce3322Smrg
1559edce3322Smrg# This file is a library for parsing options in your shell scripts along
1560edce3322Smrg# with assorted other useful supporting features that you can make use
1561edce3322Smrg# of too.
1562edce3322Smrg#
1563edce3322Smrg# For the simplest scripts you might need only:
1564edce3322Smrg#
1565edce3322Smrg#   #!/bin/sh
1566edce3322Smrg#   . relative/path/to/funclib.sh
1567edce3322Smrg#   . relative/path/to/options-parser
1568edce3322Smrg#   scriptversion=1.0
1569edce3322Smrg#   func_options ${1+"$@"}
1570edce3322Smrg#   eval set dummy "$func_options_result"; shift
1571edce3322Smrg#   ...rest of your script...
1572edce3322Smrg#
1573edce3322Smrg# In order for the '--version' option to work, you will need to have a
1574edce3322Smrg# suitably formatted comment like the one at the top of this file
157574835918Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576edce3322Smrg#
1577edce3322Smrg# For '-h' and '--help' to work, you will also need a one line
1578edce3322Smrg# description of your script's purpose in a comment directly above the
1579edce3322Smrg# '# Written by ' line, like the one at the top of this file.
1580edce3322Smrg#
1581edce3322Smrg# The default options also support '--debug', which will turn on shell
1582edce3322Smrg# execution tracing (see the comment above debug_cmd below for another
1583edce3322Smrg# use), and '--verbose' and the func_verbose function to allow your script
1584edce3322Smrg# to display verbose messages only when your user has specified
1585edce3322Smrg# '--verbose'.
1586edce3322Smrg#
158774835918Smrg# After sourcing this file, you can plug in processing for additional
1588edce3322Smrg# options by amending the variables from the 'Configuration' section
1589edce3322Smrg# below, and following the instructions in the 'Option parsing'
1590edce3322Smrg# section further down.
1591edce3322Smrg
1592edce3322Smrg## -------------- ##
1593edce3322Smrg## Configuration. ##
1594edce3322Smrg## -------------- ##
1595edce3322Smrg
1596edce3322Smrg# You should override these variables in your script after sourcing this
1597edce3322Smrg# file so that they reflect the customisations you have added to the
1598edce3322Smrg# option parser.
1599edce3322Smrg
1600edce3322Smrg# The usage line for option parsing errors and the start of '-h' and
1601edce3322Smrg# '--help' output messages. You can embed shell variables for delayed
1602edce3322Smrg# expansion at the time the message is displayed, but you will need to
1603edce3322Smrg# quote other shell meta-characters carefully to prevent them being
1604edce3322Smrg# expanded when the contents are evaled.
1605edce3322Smrgusage='$progpath [OPTION]...'
1606edce3322Smrg
1607edce3322Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1608edce3322Smrg# override it after sourcing this library to reflect the full set of
1609edce3322Smrg# options your script accepts.
1610edce3322Smrgusage_message="\
1611edce3322Smrg       --debug        enable verbose shell tracing
1612edce3322Smrg   -W, --warnings=CATEGORY
1613edce3322Smrg                      report the warnings falling in CATEGORY [all]
1614edce3322Smrg   -v, --verbose      verbosely report processing
1615edce3322Smrg       --version      print version information and exit
1616edce3322Smrg   -h, --help         print short or long help message and exit
1617edce3322Smrg"
1618edce3322Smrg
1619edce3322Smrg# Additional text appended to 'usage_message' in response to '--help'.
1620edce3322Smrglong_help_message="
1621edce3322SmrgWarning categories include:
1622edce3322Smrg       'all'          show all warnings
1623edce3322Smrg       'none'         turn off all the warnings
1624edce3322Smrg       'error'        warnings are treated as fatal errors"
1625edce3322Smrg
1626edce3322Smrg# Help message printed before fatal option parsing errors.
1627edce3322Smrgfatal_help="Try '\$progname --help' for more information."
1628edce3322Smrg
1629edce3322Smrg
1630edce3322Smrg
1631edce3322Smrg## ------------------------- ##
1632edce3322Smrg## Hook function management. ##
1633edce3322Smrg## ------------------------- ##
1634edce3322Smrg
1635edce3322Smrg# This section contains functions for adding, removing, and running hooks
163674835918Smrg# in the main code.  A hook is just a list of function names that can be
163774835918Smrg# run in order later on.
1638edce3322Smrg
1639edce3322Smrg# func_hookable FUNC_NAME
1640edce3322Smrg# -----------------------
1641edce3322Smrg# Declare that FUNC_NAME will run hooks added with
1642edce3322Smrg# 'func_add_hook FUNC_NAME ...'.
1643edce3322Smrgfunc_hookable ()
1644edce3322Smrg{
1645edce3322Smrg    $debug_cmd
1646edce3322Smrg
1647edce3322Smrg    func_append hookable_fns " $1"
1648edce3322Smrg}
1649edce3322Smrg
1650edce3322Smrg
1651edce3322Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1652edce3322Smrg# ---------------------------------
1653edce3322Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654edce3322Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1655edce3322Smrgfunc_add_hook ()
1656edce3322Smrg{
1657edce3322Smrg    $debug_cmd
1658edce3322Smrg
1659edce3322Smrg    case " $hookable_fns " in
1660edce3322Smrg      *" $1 "*) ;;
1661edce3322Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662edce3322Smrg    esac
1663edce3322Smrg
1664edce3322Smrg    eval func_append ${1}_hooks '" $2"'
1665edce3322Smrg}
1666edce3322Smrg
1667edce3322Smrg
1668edce3322Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669edce3322Smrg# ------------------------------------
167074835918Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
167174835918Smrg# FUNC_NAME.
1672edce3322Smrgfunc_remove_hook ()
1673edce3322Smrg{
1674edce3322Smrg    $debug_cmd
1675edce3322Smrg
1676edce3322Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677edce3322Smrg}
1678edce3322Smrg
1679edce3322Smrg
168074835918Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
168174835918Smrg# ---------------------------------------------
168274835918Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
168374835918Smrg# *_result variable of FUNC_NAME_B.
168474835918Smrgfunc_propagate_result ()
168574835918Smrg{
168674835918Smrg    $debug_cmd
168774835918Smrg
168874835918Smrg    func_propagate_result_result=:
168974835918Smrg    if eval "test \"\${${1}_result+set}\" = set"
169074835918Smrg    then
169174835918Smrg      eval "${2}_result=\$${1}_result"
169274835918Smrg    else
169374835918Smrg      func_propagate_result_result=false
169474835918Smrg    fi
169574835918Smrg}
169674835918Smrg
169774835918Smrg
1698edce3322Smrg# func_run_hooks FUNC_NAME [ARG]...
1699edce3322Smrg# ---------------------------------
1700edce3322Smrg# Run all hook functions registered to FUNC_NAME.
170174835918Smrg# It's assumed that the list of hook functions contains nothing more
1702edce3322Smrg# than a whitespace-delimited list of legal shell function names, and
1703edce3322Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1704edce3322Smrg# whitespace.
1705edce3322Smrgfunc_run_hooks ()
1706edce3322Smrg{
1707edce3322Smrg    $debug_cmd
1708edce3322Smrg
1709edce3322Smrg    case " $hookable_fns " in
1710edce3322Smrg      *" $1 "*) ;;
171174835918Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712edce3322Smrg    esac
1713edce3322Smrg
1714edce3322Smrg    eval _G_hook_fns=\$$1_hooks; shift
1715edce3322Smrg
1716edce3322Smrg    for _G_hook in $_G_hook_fns; do
171774835918Smrg      func_unset "${_G_hook}_result"
171874835918Smrg      eval $_G_hook '${1+"$@"}'
171974835918Smrg      func_propagate_result $_G_hook func_run_hooks
172074835918Smrg      if $func_propagate_result_result; then
172174835918Smrg        eval set dummy "$func_run_hooks_result"; shift
172274835918Smrg      fi
1723edce3322Smrg    done
1724edce3322Smrg}
1725edce3322Smrg
1726edce3322Smrg
1727edce3322Smrg
1728edce3322Smrg## --------------- ##
1729edce3322Smrg## Option parsing. ##
1730edce3322Smrg## --------------- ##
1731edce3322Smrg
1732edce3322Smrg# In order to add your own option parsing hooks, you must accept the
173374835918Smrg# full positional parameter list from your hook function.  You may remove
173474835918Smrg# or edit any options that you action, and then pass back the remaining
173574835918Smrg# unprocessed options in '<hooked_function_name>_result', escaped
173674835918Smrg# suitably for 'eval'.
173774835918Smrg#
173874835918Smrg# The '<hooked_function_name>_result' variable is automatically unset
173974835918Smrg# before your hook gets called; for best performance, only set the
174074835918Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
174174835918Smrg# function unnecessarily because it can be an expensive operation on some
174274835918Smrg# machines).
174374835918Smrg#
174474835918Smrg# Like this:
1745edce3322Smrg#
1746edce3322Smrg#    my_options_prep ()
1747edce3322Smrg#    {
1748edce3322Smrg#        $debug_cmd
1749edce3322Smrg#
1750edce3322Smrg#        # Extend the existing usage message.
1751edce3322Smrg#        usage_message=$usage_message'
1752edce3322Smrg#      -s, --silent       don'\''t print informational messages
1753edce3322Smrg#    '
175474835918Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
175574835918Smrg#        # my_options_prep_result variable intact.
1756edce3322Smrg#    }
1757edce3322Smrg#    func_add_hook func_options_prep my_options_prep
1758edce3322Smrg#
1759edce3322Smrg#
1760edce3322Smrg#    my_silent_option ()
1761edce3322Smrg#    {
1762edce3322Smrg#        $debug_cmd
1763edce3322Smrg#
176474835918Smrg#        args_changed=false
176574835918Smrg#
176674835918Smrg#        # Note that, for efficiency, we parse as many options as we can
1767edce3322Smrg#        # recognise in a loop before passing the remainder back to the
1768edce3322Smrg#        # caller on the first unrecognised argument we encounter.
1769edce3322Smrg#        while test $# -gt 0; do
1770edce3322Smrg#          opt=$1; shift
1771edce3322Smrg#          case $opt in
177274835918Smrg#            --silent|-s) opt_silent=:
177374835918Smrg#                         args_changed=:
177474835918Smrg#                         ;;
1775edce3322Smrg#            # Separate non-argument short options:
1776edce3322Smrg#            -s*)         func_split_short_opt "$_G_opt"
1777edce3322Smrg#                         set dummy "$func_split_short_opt_name" \
1778edce3322Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779edce3322Smrg#                         shift
178074835918Smrg#                         args_changed=:
1781edce3322Smrg#                         ;;
178274835918Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
178374835918Smrg#                         # is added back to "$@" in case we need it later,
178474835918Smrg#                         # if $args_changed was set to 'true'.
178574835918Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786edce3322Smrg#          esac
1787edce3322Smrg#        done
1788edce3322Smrg#
178974835918Smrg#        # Only call 'func_quote' here if we processed at least one argument.
179074835918Smrg#        if $args_changed; then
179174835918Smrg#          func_quote eval ${1+"$@"}
179274835918Smrg#          my_silent_option_result=$func_quote_result
179374835918Smrg#        fi
1794edce3322Smrg#    }
1795edce3322Smrg#    func_add_hook func_parse_options my_silent_option
1796edce3322Smrg#
1797edce3322Smrg#
1798edce3322Smrg#    my_option_validation ()
1799edce3322Smrg#    {
1800edce3322Smrg#        $debug_cmd
1801edce3322Smrg#
1802edce3322Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803edce3322Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1804edce3322Smrg#    }
1805edce3322Smrg#    func_add_hook func_validate_options my_option_validation
1806edce3322Smrg#
180774835918Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808edce3322Smrg# options you parse.  It's preferable to append if you can, so that
1809edce3322Smrg# multiple option parsing hooks can be added safely.
1810edce3322Smrg
1811edce3322Smrg
181274835918Smrg# func_options_finish [ARG]...
181374835918Smrg# ----------------------------
181474835918Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
181574835918Smrgfunc_options_finish ()
181674835918Smrg{
181774835918Smrg    $debug_cmd
181874835918Smrg
181974835918Smrg    func_run_hooks func_options ${1+"$@"}
182074835918Smrg    func_propagate_result func_run_hooks func_options_finish
182174835918Smrg}
182274835918Smrg
182374835918Smrg
1824edce3322Smrg# func_options [ARG]...
1825edce3322Smrg# ---------------------
1826edce3322Smrg# All the functions called inside func_options are hookable. See the
1827edce3322Smrg# individual implementations for details.
1828edce3322Smrgfunc_hookable func_options
1829edce3322Smrgfunc_options ()
1830a966c04fSmrg{
1831edce3322Smrg    $debug_cmd
1832a966c04fSmrg
183374835918Smrg    _G_options_quoted=false
18346e7d3316Smrg
183574835918Smrg    for my_func in options_prep parse_options validate_options options_finish
183674835918Smrg    do
183774835918Smrg      func_unset func_${my_func}_result
183874835918Smrg      func_unset func_run_hooks_result
183974835918Smrg      eval func_$my_func '${1+"$@"}'
184074835918Smrg      func_propagate_result func_$my_func func_options
184174835918Smrg      if $func_propagate_result_result; then
184274835918Smrg        eval set dummy "$func_options_result"; shift
184374835918Smrg        _G_options_quoted=:
184474835918Smrg      fi
184574835918Smrg    done
1846edce3322Smrg
184774835918Smrg    $_G_options_quoted || {
184874835918Smrg      # As we (func_options) are top-level options-parser function and
184974835918Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
185074835918Smrg      # caller.
185174835918Smrg      func_quote eval ${1+"$@"}
185274835918Smrg      func_options_result=$func_quote_result
185374835918Smrg    }
1854a966c04fSmrg}
1855a966c04fSmrg
18566e7d3316Smrg
1857edce3322Smrg# func_options_prep [ARG]...
1858edce3322Smrg# --------------------------
1859edce3322Smrg# All initialisations required before starting the option parse loop.
1860edce3322Smrg# Note that when calling hook functions, we pass through the list of
1861edce3322Smrg# positional parameters.  If a hook function modifies that list, and
186274835918Smrg# needs to propagate that back to rest of this script, then the complete
186374835918Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864edce3322Smrgfunc_hookable func_options_prep
1865edce3322Smrgfunc_options_prep ()
1866a966c04fSmrg{
1867edce3322Smrg    $debug_cmd
1868a966c04fSmrg
1869edce3322Smrg    # Option defaults:
1870edce3322Smrg    opt_verbose=false
1871edce3322Smrg    opt_warning_types=
1872a966c04fSmrg
1873edce3322Smrg    func_run_hooks func_options_prep ${1+"$@"}
187474835918Smrg    func_propagate_result func_run_hooks func_options_prep
1875a966c04fSmrg}
1876a966c04fSmrg
1877edce3322Smrg
1878edce3322Smrg# func_parse_options [ARG]...
1879edce3322Smrg# ---------------------------
1880edce3322Smrg# The main option parsing loop.
1881edce3322Smrgfunc_hookable func_parse_options
1882edce3322Smrgfunc_parse_options ()
188397cf2ee2Smrg{
1884edce3322Smrg    $debug_cmd
1885edce3322Smrg
188674835918Smrg    _G_parse_options_requote=false
1887edce3322Smrg    # this just eases exit handling
1888edce3322Smrg    while test $# -gt 0; do
1889edce3322Smrg      # Defer to hook functions for initial option parsing, so they
1890edce3322Smrg      # get priority in the event of reusing an option name.
1891edce3322Smrg      func_run_hooks func_parse_options ${1+"$@"}
189274835918Smrg      func_propagate_result func_run_hooks func_parse_options
189374835918Smrg      if $func_propagate_result_result; then
189474835918Smrg        eval set dummy "$func_parse_options_result"; shift
189574835918Smrg        # Even though we may have changed "$@", we passed the "$@" array
189674835918Smrg        # down into the hook and it quoted it for us (because we are in
189774835918Smrg        # this if-branch).  No need to quote it again.
189874835918Smrg        _G_parse_options_requote=false
189974835918Smrg      fi
1900edce3322Smrg
1901edce3322Smrg      # Break out of the loop if we already parsed every option.
1902edce3322Smrg      test $# -gt 0 || break
1903edce3322Smrg
190474835918Smrg      # We expect that one of the options parsed in this function matches
190574835918Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
190674835918Smrg      _G_match_parse_options=:
1907edce3322Smrg      _G_opt=$1
1908edce3322Smrg      shift
1909edce3322Smrg      case $_G_opt in
1910edce3322Smrg        --debug|-x)   debug_cmd='set -x'
191174835918Smrg                      func_echo "enabling shell trace mode" >&2
1912edce3322Smrg                      $debug_cmd
1913edce3322Smrg                      ;;
1914edce3322Smrg
1915edce3322Smrg        --no-warnings|--no-warning|--no-warn)
1916edce3322Smrg                      set dummy --warnings none ${1+"$@"}
1917edce3322Smrg                      shift
1918edce3322Smrg		      ;;
1919edce3322Smrg
1920edce3322Smrg        --warnings|--warning|-W)
192174835918Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
192274835918Smrg                        _G_parse_options_requote=:
192374835918Smrg                        break
192474835918Smrg                      fi
1925edce3322Smrg                      case " $warning_categories $1" in
1926edce3322Smrg                        *" $1 "*)
1927edce3322Smrg                          # trailing space prevents matching last $1 above
1928edce3322Smrg                          func_append_uniq opt_warning_types " $1"
1929edce3322Smrg                          ;;
1930edce3322Smrg                        *all)
1931edce3322Smrg                          opt_warning_types=$warning_categories
1932edce3322Smrg                          ;;
1933edce3322Smrg                        *none)
1934edce3322Smrg                          opt_warning_types=none
1935edce3322Smrg                          warning_func=:
1936edce3322Smrg                          ;;
1937edce3322Smrg                        *error)
1938edce3322Smrg                          opt_warning_types=$warning_categories
1939edce3322Smrg                          warning_func=func_fatal_error
1940edce3322Smrg                          ;;
1941edce3322Smrg                        *)
1942edce3322Smrg                          func_fatal_error \
1943edce3322Smrg                             "unsupported warning category: '$1'"
1944edce3322Smrg                          ;;
1945edce3322Smrg                      esac
1946edce3322Smrg                      shift
1947edce3322Smrg                      ;;
1948edce3322Smrg
1949edce3322Smrg        --verbose|-v) opt_verbose=: ;;
1950edce3322Smrg        --version)    func_version ;;
1951edce3322Smrg        -\?|-h)       func_usage ;;
1952edce3322Smrg        --help)       func_help ;;
1953edce3322Smrg
1954edce3322Smrg	# Separate optargs to long options (plugins may need this):
1955edce3322Smrg	--*=*)        func_split_equals "$_G_opt"
1956edce3322Smrg	              set dummy "$func_split_equals_lhs" \
1957edce3322Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1958edce3322Smrg                      shift
1959edce3322Smrg                      ;;
1960edce3322Smrg
1961edce3322Smrg       # Separate optargs to short options:
1962edce3322Smrg        -W*)
1963edce3322Smrg                      func_split_short_opt "$_G_opt"
1964edce3322Smrg                      set dummy "$func_split_short_opt_name" \
1965edce3322Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966edce3322Smrg                      shift
1967edce3322Smrg                      ;;
1968edce3322Smrg
1969edce3322Smrg        # Separate non-argument short options:
1970edce3322Smrg        -\?*|-h*|-v*|-x*)
1971edce3322Smrg                      func_split_short_opt "$_G_opt"
1972edce3322Smrg                      set dummy "$func_split_short_opt_name" \
1973edce3322Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974edce3322Smrg                      shift
1975edce3322Smrg                      ;;
1976edce3322Smrg
197774835918Smrg        --)           _G_parse_options_requote=: ; break ;;
1978edce3322Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
197974835918Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
198074835918Smrg                      _G_match_parse_options=false
198174835918Smrg                      break
198274835918Smrg                      ;;
1983edce3322Smrg      esac
198474835918Smrg
198574835918Smrg      if $_G_match_parse_options; then
198674835918Smrg        _G_parse_options_requote=:
198774835918Smrg      fi
1988edce3322Smrg    done
1989edce3322Smrg
199074835918Smrg    if $_G_parse_options_requote; then
199174835918Smrg      # save modified positional parameters for caller
199274835918Smrg      func_quote eval ${1+"$@"}
199374835918Smrg      func_parse_options_result=$func_quote_result
199474835918Smrg    fi
199597cf2ee2Smrg}
199697cf2ee2Smrg
1997a966c04fSmrg
1998edce3322Smrg# func_validate_options [ARG]...
1999edce3322Smrg# ------------------------------
2000edce3322Smrg# Perform any sanity checks on option settings and/or unconsumed
2001edce3322Smrg# arguments.
2002edce3322Smrgfunc_hookable func_validate_options
2003edce3322Smrgfunc_validate_options ()
20046e7d3316Smrg{
2005edce3322Smrg    $debug_cmd
200697cf2ee2Smrg
2007edce3322Smrg    # Display all warnings if -W was not given.
2008edce3322Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009edce3322Smrg
2010edce3322Smrg    func_run_hooks func_validate_options ${1+"$@"}
201174835918Smrg    func_propagate_result func_run_hooks func_validate_options
2012edce3322Smrg
2013edce3322Smrg    # Bail if the options were screwed!
2014edce3322Smrg    $exit_cmd $EXIT_FAILURE
20156e7d3316Smrg}
2016a966c04fSmrg
2017edce3322Smrg
2018edce3322Smrg
2019edce3322Smrg## ----------------- ##
2020edce3322Smrg## Helper functions. ##
2021edce3322Smrg## ----------------- ##
2022edce3322Smrg
2023edce3322Smrg# This section contains the helper functions used by the rest of the
2024edce3322Smrg# hookable option parser framework in ascii-betical order.
2025edce3322Smrg
2026edce3322Smrg
2027edce3322Smrg# func_fatal_help ARG...
2028edce3322Smrg# ----------------------
2029edce3322Smrg# Echo program name prefixed message to standard error, followed by
2030edce3322Smrg# a help hint, and exit.
2031edce3322Smrgfunc_fatal_help ()
20326e7d3316Smrg{
2033edce3322Smrg    $debug_cmd
203497cf2ee2Smrg
2035edce3322Smrg    eval \$ECHO \""Usage: $usage"\"
2036edce3322Smrg    eval \$ECHO \""$fatal_help"\"
2037edce3322Smrg    func_error ${1+"$@"}
2038edce3322Smrg    exit $EXIT_FAILURE
20396e7d3316Smrg}
2040a966c04fSmrg
2041edce3322Smrg
2042edce3322Smrg# func_help
2043edce3322Smrg# ---------
2044edce3322Smrg# Echo long help message to standard output and exit.
20456e7d3316Smrgfunc_help ()
20466e7d3316Smrg{
2047edce3322Smrg    $debug_cmd
2048edce3322Smrg
2049edce3322Smrg    func_usage_message
2050edce3322Smrg    $ECHO "$long_help_message"
2051edce3322Smrg    exit 0
20526e7d3316Smrg}
2053a966c04fSmrg
2054edce3322Smrg
2055edce3322Smrg# func_missing_arg ARGNAME
2056edce3322Smrg# ------------------------
20576e7d3316Smrg# Echo program name prefixed message to standard error and set global
20586e7d3316Smrg# exit_cmd.
20596e7d3316Smrgfunc_missing_arg ()
20606e7d3316Smrg{
2061edce3322Smrg    $debug_cmd
206297cf2ee2Smrg
2063edce3322Smrg    func_error "Missing argument for '$1'."
20646e7d3316Smrg    exit_cmd=exit
20656e7d3316Smrg}
2066a966c04fSmrg
2067a966c04fSmrg
2068edce3322Smrg# func_split_equals STRING
2069edce3322Smrg# ------------------------
207074835918Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
207174835918Smrg# after splitting STRING at the '=' sign.
2072edce3322Smrgtest -z "$_G_HAVE_XSI_OPS" \
2073edce3322Smrg    && (eval 'x=a/b/c;
2074edce3322Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075edce3322Smrg    && _G_HAVE_XSI_OPS=yes
2076edce3322Smrg
2077edce3322Smrgif test yes = "$_G_HAVE_XSI_OPS"
2078edce3322Smrgthen
2079edce3322Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2080edce3322Smrg  eval 'func_split_equals ()
2081edce3322Smrg  {
2082edce3322Smrg      $debug_cmd
2083edce3322Smrg
2084edce3322Smrg      func_split_equals_lhs=${1%%=*}
2085edce3322Smrg      func_split_equals_rhs=${1#*=}
208674835918Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
208774835918Smrg        func_split_equals_rhs=
208874835918Smrg      fi
2089edce3322Smrg  }'
2090edce3322Smrgelse
2091edce3322Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092edce3322Smrg  func_split_equals ()
2093edce3322Smrg  {
2094edce3322Smrg      $debug_cmd
2095edce3322Smrg
2096edce3322Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097edce3322Smrg      func_split_equals_rhs=
209874835918Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099edce3322Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100edce3322Smrg  }
2101edce3322Smrgfi #func_split_equals
2102edce3322Smrg
2103edce3322Smrg
2104edce3322Smrg# func_split_short_opt SHORTOPT
2105edce3322Smrg# -----------------------------
210697cf2ee2Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
210797cf2ee2Smrg# variables after splitting SHORTOPT after the 2nd character.
2108edce3322Smrgif test yes = "$_G_HAVE_XSI_OPS"
2109edce3322Smrgthen
2110edce3322Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2111edce3322Smrg  eval 'func_split_short_opt ()
2112edce3322Smrg  {
2113edce3322Smrg      $debug_cmd
2114edce3322Smrg
2115edce3322Smrg      func_split_short_opt_arg=${1#??}
2116edce3322Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117edce3322Smrg  }'
2118edce3322Smrgelse
2119edce3322Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120edce3322Smrg  func_split_short_opt ()
2121edce3322Smrg  {
2122edce3322Smrg      $debug_cmd
2123edce3322Smrg
212474835918Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125edce3322Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126edce3322Smrg  }
2127edce3322Smrgfi #func_split_short_opt
2128edce3322Smrg
2129edce3322Smrg
2130edce3322Smrg# func_usage
2131edce3322Smrg# ----------
2132edce3322Smrg# Echo short help message to standard output and exit.
2133edce3322Smrgfunc_usage ()
213497cf2ee2Smrg{
2135edce3322Smrg    $debug_cmd
213697cf2ee2Smrg
2137edce3322Smrg    func_usage_message
2138edce3322Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139edce3322Smrg    exit 0
2140edce3322Smrg}
214197cf2ee2Smrg
214297cf2ee2Smrg
2143edce3322Smrg# func_usage_message
2144edce3322Smrg# ------------------
2145edce3322Smrg# Echo short help message to standard output.
2146edce3322Smrgfunc_usage_message ()
214797cf2ee2Smrg{
2148edce3322Smrg    $debug_cmd
214997cf2ee2Smrg
2150edce3322Smrg    eval \$ECHO \""Usage: $usage"\"
2151edce3322Smrg    echo
2152edce3322Smrg    $SED -n 's|^# ||
2153edce3322Smrg        /^Written by/{
2154edce3322Smrg          x;p;x
2155edce3322Smrg        }
2156edce3322Smrg	h
2157edce3322Smrg	/^Written by/q' < "$progpath"
2158edce3322Smrg    echo
2159edce3322Smrg    eval \$ECHO \""$usage_message"\"
2160edce3322Smrg}
216197cf2ee2Smrg
2162a966c04fSmrg
2163edce3322Smrg# func_version
2164edce3322Smrg# ------------
2165edce3322Smrg# Echo version message to standard output and exit.
216674835918Smrg# The version message is extracted from the calling file's header
216774835918Smrg# comments, with leading '# ' stripped:
216874835918Smrg#   1. First display the progname and version
216974835918Smrg#   2. Followed by the header comment line matching  /^# Written by /
217074835918Smrg#   3. Then a blank line followed by the first following line matching
217174835918Smrg#      /^# Copyright /
217274835918Smrg#   4. Immediately followed by any lines between the previous matches,
217374835918Smrg#      except lines preceding the intervening completely blank line.
217474835918Smrg# For example, see the header comments of this file.
2175edce3322Smrgfunc_version ()
2176edce3322Smrg{
2177edce3322Smrg    $debug_cmd
2178a966c04fSmrg
2179edce3322Smrg    printf '%s\n' "$progname $scriptversion"
2180edce3322Smrg    $SED -n '
218174835918Smrg        /^# Written by /!b
218274835918Smrg        s|^# ||; p; n
218374835918Smrg
218474835918Smrg        :fwd2blnk
218574835918Smrg        /./ {
218674835918Smrg          n
218774835918Smrg          b fwd2blnk
2188edce3322Smrg        }
218974835918Smrg        p; n
219074835918Smrg
219174835918Smrg        :holdwrnt
219274835918Smrg        s|^# ||
219374835918Smrg        s|^# *$||
219474835918Smrg        /^Copyright /!{
219574835918Smrg          /./H
219674835918Smrg          n
219774835918Smrg          b holdwrnt
21981c235774Smrg        }
219974835918Smrg
220074835918Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
220174835918Smrg        G
220274835918Smrg        s|\(\n\)\n*|\1|g
220374835918Smrg        p; q' < "$progpath"
22042e2dd055Smrg
2205edce3322Smrg    exit $?
2206edce3322Smrg}
2207a966c04fSmrg
22086e7d3316Smrg
2209edce3322Smrg# Local variables:
2210edce3322Smrg# mode: shell-script
2211edce3322Smrg# sh-indentation: 2
2212edce3322Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
221374835918Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214edce3322Smrg# time-stamp-time-zone: "UTC"
2215edce3322Smrg# End:
22166e7d3316Smrg
2217edce3322Smrg# Set a version string.
221874835918Smrgscriptversion='(GNU libtool) 2.4.7'
22196e7d3316Smrg
22206e7d3316Smrg
2221edce3322Smrg# func_echo ARG...
2222edce3322Smrg# ----------------
2223edce3322Smrg# Libtool also displays the current mode in messages, so override
2224edce3322Smrg# funclib.sh func_echo with this custom definition.
2225edce3322Smrgfunc_echo ()
222697cf2ee2Smrg{
2227edce3322Smrg    $debug_cmd
222897cf2ee2Smrg
2229edce3322Smrg    _G_message=$*
2230edce3322Smrg
2231edce3322Smrg    func_echo_IFS=$IFS
2232edce3322Smrg    IFS=$nl
2233edce3322Smrg    for _G_line in $_G_message; do
2234edce3322Smrg      IFS=$func_echo_IFS
2235edce3322Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236edce3322Smrg    done
2237edce3322Smrg    IFS=$func_echo_IFS
2238edce3322Smrg}
223997cf2ee2Smrg
224097cf2ee2Smrg
2241edce3322Smrg# func_warning ARG...
2242edce3322Smrg# -------------------
2243edce3322Smrg# Libtool warnings are not categorized, so override funclib.sh
2244edce3322Smrg# func_warning with this simpler definition.
2245edce3322Smrgfunc_warning ()
224697cf2ee2Smrg{
2247edce3322Smrg    $debug_cmd
2248edce3322Smrg
2249edce3322Smrg    $warning_func ${1+"$@"}
2250edce3322Smrg}
2251edce3322Smrg
225297cf2ee2Smrg
2253edce3322Smrg## ---------------- ##
2254edce3322Smrg## Options parsing. ##
2255edce3322Smrg## ---------------- ##
2256edce3322Smrg
2257edce3322Smrg# Hook in the functions to make sure our own options are parsed during
2258edce3322Smrg# the option parsing loop.
2259edce3322Smrg
2260edce3322Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261edce3322Smrg
2262edce3322Smrg# Short help message in response to '-h'.
2263edce3322Smrgusage_message="Options:
2264edce3322Smrg       --config             show all configuration variables
2265edce3322Smrg       --debug              enable verbose shell tracing
2266edce3322Smrg   -n, --dry-run            display commands without modifying any files
2267edce3322Smrg       --features           display basic configuration information and exit
2268edce3322Smrg       --mode=MODE          use operation mode MODE
2269edce3322Smrg       --no-warnings        equivalent to '-Wnone'
2270edce3322Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271edce3322Smrg       --quiet, --silent    don't print informational messages
2272edce3322Smrg       --tag=TAG            use configuration variables from tag TAG
2273edce3322Smrg   -v, --verbose            print more informational messages than default
2274edce3322Smrg       --version            print version information
2275edce3322Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276edce3322Smrg   -h, --help, --help-all   print short, long, or detailed help message
2277edce3322Smrg"
227897cf2ee2Smrg
2279edce3322Smrg# Additional text appended to 'usage_message' in response to '--help'.
2280edce3322Smrgfunc_help ()
228197cf2ee2Smrg{
2282edce3322Smrg    $debug_cmd
2283edce3322Smrg
2284edce3322Smrg    func_usage_message
2285edce3322Smrg    $ECHO "$long_help_message
2286edce3322Smrg
2287edce3322SmrgMODE must be one of the following:
2288edce3322Smrg
2289edce3322Smrg       clean           remove files from the build directory
2290edce3322Smrg       compile         compile a source file into a libtool object
2291edce3322Smrg       execute         automatically set library path, then run a program
2292edce3322Smrg       finish          complete the installation of libtool libraries
2293edce3322Smrg       install         install libraries or executables
2294edce3322Smrg       link            create a library or an executable
2295edce3322Smrg       uninstall       remove libraries from an installed directory
2296edce3322Smrg
2297edce3322SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298edce3322Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299edce3322SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300edce3322Smrg
2301edce3322SmrgWhen reporting a bug, please describe a test case to reproduce it and
2302edce3322Smrginclude the following information:
2303edce3322Smrg
2304edce3322Smrg       host-triplet:   $host
2305edce3322Smrg       shell:          $SHELL
2306edce3322Smrg       compiler:       $LTCC
2307edce3322Smrg       compiler flags: $LTCFLAGS
2308edce3322Smrg       linker:         $LD (gnu? $with_gnu_ld)
230974835918Smrg       version:        $progname (GNU libtool) 2.4.7
2310edce3322Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311edce3322Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312edce3322Smrg
2313edce3322SmrgReport bugs to <bug-libtool@gnu.org>.
231474835918SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315edce3322SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316edce3322Smrg    exit 0
2317edce3322Smrg}
231897cf2ee2Smrg
231997cf2ee2Smrg
2320edce3322Smrg# func_lo2o OBJECT-NAME
2321edce3322Smrg# ---------------------
2322edce3322Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323edce3322Smrg# object suffix.
232497cf2ee2Smrg
2325edce3322Smrglo2o=s/\\.lo\$/.$objext/
2326edce3322Smrgo2lo=s/\\.$objext\$/.lo/
232797cf2ee2Smrg
2328edce3322Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329edce3322Smrg  eval 'func_lo2o ()
2330edce3322Smrg  {
2331edce3322Smrg    case $1 in
2332edce3322Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333edce3322Smrg      *   ) func_lo2o_result=$1               ;;
2334edce3322Smrg    esac
2335edce3322Smrg  }'
2336edce3322Smrg
2337edce3322Smrg  # func_xform LIBOBJ-OR-SOURCE
2338edce3322Smrg  # ---------------------------
2339edce3322Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340edce3322Smrg  # suffix to a '.lo' libtool-object suffix.
2341edce3322Smrg  eval 'func_xform ()
2342edce3322Smrg  {
2343edce3322Smrg    func_xform_result=${1%.*}.lo
2344edce3322Smrg  }'
2345edce3322Smrgelse
2346edce3322Smrg  # ...otherwise fall back to using sed.
2347edce3322Smrg  func_lo2o ()
2348edce3322Smrg  {
2349edce3322Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350edce3322Smrg  }
2351edce3322Smrg
2352edce3322Smrg  func_xform ()
2353edce3322Smrg  {
2354edce3322Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355edce3322Smrg  }
2356edce3322Smrgfi
235797cf2ee2Smrg
235897cf2ee2Smrg
2359edce3322Smrg# func_fatal_configuration ARG...
2360edce3322Smrg# -------------------------------
23616e7d3316Smrg# Echo program name prefixed message to standard error, followed by
23626e7d3316Smrg# a configuration failure hint, and exit.
23636e7d3316Smrgfunc_fatal_configuration ()
23646e7d3316Smrg{
236574835918Smrg    func_fatal_error ${1+"$@"} \
2366edce3322Smrg      "See the $PACKAGE documentation for more information." \
2367edce3322Smrg      "Fatal configuration error."
23686e7d3316Smrg}
23696e7d3316Smrg
23706e7d3316Smrg
23716e7d3316Smrg# func_config
2372edce3322Smrg# -----------
23736e7d3316Smrg# Display the configuration for all the tags in this script.
23746e7d3316Smrgfunc_config ()
23756e7d3316Smrg{
23766e7d3316Smrg    re_begincf='^# ### BEGIN LIBTOOL'
23776e7d3316Smrg    re_endcf='^# ### END LIBTOOL'
23786e7d3316Smrg
23796e7d3316Smrg    # Default configuration.
23806e7d3316Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
23816e7d3316Smrg
2382a966c04fSmrg    # Now print the configurations for the tags.
2383a966c04fSmrg    for tagname in $taglist; do
23846e7d3316Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385a966c04fSmrg    done
2386a966c04fSmrg
23876e7d3316Smrg    exit $?
23886e7d3316Smrg}
2389a966c04fSmrg
2390edce3322Smrg
23916e7d3316Smrg# func_features
2392edce3322Smrg# -------------
23936e7d3316Smrg# Display the features supported by this script.
23946e7d3316Smrgfunc_features ()
23956e7d3316Smrg{
23966e7d3316Smrg    echo "host: $host"
2397edce3322Smrg    if test yes = "$build_libtool_libs"; then
23986e7d3316Smrg      echo "enable shared libraries"
2399a966c04fSmrg    else
24006e7d3316Smrg      echo "disable shared libraries"
2401a966c04fSmrg    fi
2402edce3322Smrg    if test yes = "$build_old_libs"; then
24036e7d3316Smrg      echo "enable static libraries"
2404a966c04fSmrg    else
24056e7d3316Smrg      echo "disable static libraries"
2406a966c04fSmrg    fi
24076e7d3316Smrg
2408a966c04fSmrg    exit $?
24096e7d3316Smrg}
2410a966c04fSmrg
2411edce3322Smrg
2412edce3322Smrg# func_enable_tag TAGNAME
2413edce3322Smrg# -----------------------
24146e7d3316Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
24156e7d3316Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
24166e7d3316Smrg# variable here.
24176e7d3316Smrgfunc_enable_tag ()
24186e7d3316Smrg{
2419edce3322Smrg    # Global variable:
2420edce3322Smrg    tagname=$1
2421a966c04fSmrg
2422edce3322Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423edce3322Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424edce3322Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425a966c04fSmrg
2426edce3322Smrg    # Validate tagname.
2427edce3322Smrg    case $tagname in
2428edce3322Smrg      *[!-_A-Za-z0-9,/]*)
2429edce3322Smrg        func_fatal_error "invalid tag name: $tagname"
2430edce3322Smrg        ;;
2431edce3322Smrg    esac
2432a966c04fSmrg
2433edce3322Smrg    # Don't test for the "default" C tag, as we know it's
2434edce3322Smrg    # there but not specially marked.
2435edce3322Smrg    case $tagname in
2436edce3322Smrg        CC) ;;
24376e7d3316Smrg    *)
2438edce3322Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439edce3322Smrg	  taglist="$taglist $tagname"
2440edce3322Smrg
2441edce3322Smrg	  # Evaluate the configuration.  Be careful to quote the path
2442edce3322Smrg	  # and the sed script, to avoid splitting on whitespace, but
2443edce3322Smrg	  # also don't use non-portable quotes within backquotes within
2444edce3322Smrg	  # quotes we have to do it in 2 steps:
2445edce3322Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446edce3322Smrg	  eval "$extractedcf"
2447edce3322Smrg        else
2448edce3322Smrg	  func_error "ignoring unknown tag $tagname"
2449edce3322Smrg        fi
2450edce3322Smrg        ;;
2451edce3322Smrg    esac
24526e7d3316Smrg}
24536e7d3316Smrg
2454edce3322Smrg
245597cf2ee2Smrg# func_check_version_match
2456edce3322Smrg# ------------------------
245797cf2ee2Smrg# Ensure that we are using m4 macros, and libtool script from the same
245897cf2ee2Smrg# release of libtool.
245997cf2ee2Smrgfunc_check_version_match ()
24606e7d3316Smrg{
2461edce3322Smrg    if test "$package_revision" != "$macro_revision"; then
2462edce3322Smrg      if test "$VERSION" != "$macro_version"; then
2463edce3322Smrg        if test -z "$macro_version"; then
2464edce3322Smrg          cat >&2 <<_LT_EOF
246597cf2ee2Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
246697cf2ee2Smrg$progname: definition of this LT_INIT comes from an older release.
246797cf2ee2Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
246897cf2ee2Smrg$progname: and run autoconf again.
246997cf2ee2Smrg_LT_EOF
2470edce3322Smrg        else
2471edce3322Smrg          cat >&2 <<_LT_EOF
247297cf2ee2Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
247397cf2ee2Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
247497cf2ee2Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
247597cf2ee2Smrg$progname: and run autoconf again.
247697cf2ee2Smrg_LT_EOF
2477edce3322Smrg        fi
2478edce3322Smrg      else
2479edce3322Smrg        cat >&2 <<_LT_EOF
248097cf2ee2Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
248197cf2ee2Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
248297cf2ee2Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
248397cf2ee2Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
248497cf2ee2Smrg_LT_EOF
2485edce3322Smrg      fi
2486a966c04fSmrg
2487edce3322Smrg      exit $EXIT_MISMATCH
2488edce3322Smrg    fi
248997cf2ee2Smrg}
249097cf2ee2Smrg
249197cf2ee2Smrg
2492edce3322Smrg# libtool_options_prep [ARG]...
2493edce3322Smrg# -----------------------------
2494edce3322Smrg# Preparation for options parsed by libtool.
2495edce3322Smrglibtool_options_prep ()
2496edce3322Smrg{
2497edce3322Smrg    $debug_mode
2498a966c04fSmrg
2499edce3322Smrg    # Option defaults:
2500edce3322Smrg    opt_config=false
2501edce3322Smrg    opt_dlopen=
2502edce3322Smrg    opt_dry_run=false
2503edce3322Smrg    opt_help=false
2504edce3322Smrg    opt_mode=
2505edce3322Smrg    opt_preserve_dup_deps=false
2506edce3322Smrg    opt_quiet=false
250797cf2ee2Smrg
2508edce3322Smrg    nonopt=
2509edce3322Smrg    preserve_args=
251097cf2ee2Smrg
251174835918Smrg    _G_rc_lt_options_prep=:
251274835918Smrg
2513edce3322Smrg    # Shorthand for --mode=foo, only valid as the first argument
2514edce3322Smrg    case $1 in
2515edce3322Smrg    clean|clea|cle|cl)
2516edce3322Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517edce3322Smrg      ;;
2518edce3322Smrg    compile|compil|compi|comp|com|co|c)
2519edce3322Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520edce3322Smrg      ;;
2521edce3322Smrg    execute|execut|execu|exec|exe|ex|e)
2522edce3322Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523edce3322Smrg      ;;
2524edce3322Smrg    finish|finis|fini|fin|fi|f)
2525edce3322Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526edce3322Smrg      ;;
2527edce3322Smrg    install|instal|insta|inst|ins|in|i)
2528edce3322Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2529edce3322Smrg      ;;
2530edce3322Smrg    link|lin|li|l)
2531edce3322Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2532edce3322Smrg      ;;
2533edce3322Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534edce3322Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535edce3322Smrg      ;;
253674835918Smrg    *)
253774835918Smrg      _G_rc_lt_options_prep=false
253874835918Smrg      ;;
2539edce3322Smrg    esac
2540edce3322Smrg
254174835918Smrg    if $_G_rc_lt_options_prep; then
254274835918Smrg      # Pass back the list of options.
254374835918Smrg      func_quote eval ${1+"$@"}
254474835918Smrg      libtool_options_prep_result=$func_quote_result
254574835918Smrg    fi
2546edce3322Smrg}
2547edce3322Smrgfunc_add_hook func_options_prep libtool_options_prep
254897cf2ee2Smrg
254997cf2ee2Smrg
2550edce3322Smrg# libtool_parse_options [ARG]...
2551edce3322Smrg# ---------------------------------
2552edce3322Smrg# Provide handling for libtool specific options.
2553edce3322Smrglibtool_parse_options ()
255497cf2ee2Smrg{
2555edce3322Smrg    $debug_cmd
25566e7d3316Smrg
255774835918Smrg    _G_rc_lt_parse_options=false
255874835918Smrg
2559edce3322Smrg    # Perform our own loop to consume as many options as possible in
2560edce3322Smrg    # each iteration.
2561edce3322Smrg    while test $# -gt 0; do
256274835918Smrg      _G_match_lt_parse_options=:
2563edce3322Smrg      _G_opt=$1
2564edce3322Smrg      shift
2565edce3322Smrg      case $_G_opt in
2566edce3322Smrg        --dry-run|--dryrun|-n)
2567edce3322Smrg                        opt_dry_run=:
2568edce3322Smrg                        ;;
2569edce3322Smrg
2570edce3322Smrg        --config)       func_config ;;
2571edce3322Smrg
2572edce3322Smrg        --dlopen|-dlopen)
2573edce3322Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574edce3322Smrg}$1"
2575edce3322Smrg                        shift
2576edce3322Smrg                        ;;
2577edce3322Smrg
2578edce3322Smrg        --preserve-dup-deps)
2579edce3322Smrg                        opt_preserve_dup_deps=: ;;
2580edce3322Smrg
2581edce3322Smrg        --features)     func_features ;;
2582edce3322Smrg
2583edce3322Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584edce3322Smrg
2585edce3322Smrg        --help)         opt_help=: ;;
2586edce3322Smrg
2587edce3322Smrg        --help-all)     opt_help=': help-all' ;;
2588edce3322Smrg
2589edce3322Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590edce3322Smrg                        opt_mode=$1
2591edce3322Smrg                        case $1 in
2592edce3322Smrg                          # Valid mode arguments:
2593edce3322Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594edce3322Smrg
2595edce3322Smrg                          # Catch anything else as an error
2596edce3322Smrg                          *) func_error "invalid argument for $_G_opt"
2597edce3322Smrg                             exit_cmd=exit
2598edce3322Smrg                             break
2599edce3322Smrg                             ;;
2600edce3322Smrg                        esac
2601edce3322Smrg                        shift
2602edce3322Smrg                        ;;
2603edce3322Smrg
2604edce3322Smrg        --no-silent|--no-quiet)
2605edce3322Smrg                        opt_quiet=false
2606edce3322Smrg                        func_append preserve_args " $_G_opt"
2607edce3322Smrg                        ;;
2608edce3322Smrg
2609edce3322Smrg        --no-warnings|--no-warning|--no-warn)
2610edce3322Smrg                        opt_warning=false
2611edce3322Smrg                        func_append preserve_args " $_G_opt"
2612edce3322Smrg                        ;;
2613edce3322Smrg
2614edce3322Smrg        --no-verbose)
2615edce3322Smrg                        opt_verbose=false
2616edce3322Smrg                        func_append preserve_args " $_G_opt"
2617edce3322Smrg                        ;;
2618edce3322Smrg
2619edce3322Smrg        --silent|--quiet)
2620edce3322Smrg                        opt_quiet=:
2621edce3322Smrg                        opt_verbose=false
2622edce3322Smrg                        func_append preserve_args " $_G_opt"
2623edce3322Smrg                        ;;
2624edce3322Smrg
2625edce3322Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626edce3322Smrg                        opt_tag=$1
2627edce3322Smrg                        func_append preserve_args " $_G_opt $1"
2628edce3322Smrg                        func_enable_tag "$1"
2629edce3322Smrg                        shift
2630edce3322Smrg                        ;;
2631edce3322Smrg
2632edce3322Smrg        --verbose|-v)   opt_quiet=false
2633edce3322Smrg                        opt_verbose=:
2634edce3322Smrg                        func_append preserve_args " $_G_opt"
2635edce3322Smrg                        ;;
2636edce3322Smrg
263774835918Smrg        # An option not handled by this hook function:
263874835918Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
263974835918Smrg                        _G_match_lt_parse_options=false
264074835918Smrg                        break
264174835918Smrg                        ;;
2642edce3322Smrg      esac
264374835918Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644edce3322Smrg    done
264597cf2ee2Smrg
264674835918Smrg    if $_G_rc_lt_parse_options; then
264774835918Smrg      # save modified positional parameters for caller
264874835918Smrg      func_quote eval ${1+"$@"}
264974835918Smrg      libtool_parse_options_result=$func_quote_result
265074835918Smrg    fi
2651edce3322Smrg}
2652edce3322Smrgfunc_add_hook func_parse_options libtool_parse_options
26536e7d3316Smrg
2654a966c04fSmrg
26556e7d3316Smrg
2656edce3322Smrg# libtool_validate_options [ARG]...
2657edce3322Smrg# ---------------------------------
2658edce3322Smrg# Perform any sanity checks on option settings and/or unconsumed
2659edce3322Smrg# arguments.
2660edce3322Smrglibtool_validate_options ()
2661edce3322Smrg{
2662edce3322Smrg    # save first non-option argument
2663edce3322Smrg    if test 0 -lt $#; then
2664edce3322Smrg      nonopt=$1
2665edce3322Smrg      shift
26666e7d3316Smrg    fi
26676e7d3316Smrg
2668edce3322Smrg    # preserve --debug
2669edce3322Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
26706e7d3316Smrg
2671edce3322Smrg    case $host in
2672edce3322Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673edce3322Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674edce3322Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675edce3322Smrg        # don't eliminate duplications in $postdeps and $predeps
2676edce3322Smrg        opt_duplicate_compiler_generated_deps=:
2677edce3322Smrg        ;;
2678edce3322Smrg      *)
2679edce3322Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680edce3322Smrg        ;;
2681edce3322Smrg    esac
26826e7d3316Smrg
2683edce3322Smrg    $opt_help || {
2684edce3322Smrg      # Sanity checks first:
2685edce3322Smrg      func_check_version_match
26866e7d3316Smrg
2687edce3322Smrg      test yes != "$build_libtool_libs" \
2688edce3322Smrg        && test yes != "$build_old_libs" \
2689edce3322Smrg        && func_fatal_configuration "not configured to build any kind of library"
26906e7d3316Smrg
2691edce3322Smrg      # Darwin sucks
2692edce3322Smrg      eval std_shrext=\"$shrext_cmds\"
2693edce3322Smrg
2694edce3322Smrg      # Only execute mode is allowed to have -dlopen flags.
2695edce3322Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696edce3322Smrg        func_error "unrecognized option '-dlopen'"
2697edce3322Smrg        $ECHO "$help" 1>&2
2698edce3322Smrg        exit $EXIT_FAILURE
2699edce3322Smrg      fi
2700edce3322Smrg
2701edce3322Smrg      # Change the help message to a mode-specific one.
2702edce3322Smrg      generic_help=$help
2703edce3322Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704edce3322Smrg    }
2705edce3322Smrg
2706edce3322Smrg    # Pass back the unparsed argument list
270774835918Smrg    func_quote eval ${1+"$@"}
270874835918Smrg    libtool_validate_options_result=$func_quote_result
270997cf2ee2Smrg}
2710edce3322Smrgfunc_add_hook func_validate_options libtool_validate_options
2711edce3322Smrg
27126e7d3316Smrg
2713edce3322Smrg# Process options as early as possible so that --help and --version
2714edce3322Smrg# can return quickly.
2715edce3322Smrgfunc_options ${1+"$@"}
2716edce3322Smrgeval set dummy "$func_options_result"; shift
27176e7d3316Smrg
2718a966c04fSmrg
2719a966c04fSmrg
272097cf2ee2Smrg## ----------- ##
272197cf2ee2Smrg##    Main.    ##
272297cf2ee2Smrg## ----------- ##
2723a966c04fSmrg
2724edce3322Smrgmagic='%%%MAGIC variable%%%'
2725edce3322Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2726edce3322Smrg
2727edce3322Smrg# Global variables.
2728edce3322Smrgextracted_archives=
2729edce3322Smrgextracted_serial=0
2730edce3322Smrg
2731edce3322Smrg# If this variable is set in any of the actions, the command in it
2732edce3322Smrg# will be execed at the end.  This prevents here-documents from being
2733edce3322Smrg# left over by shells.
2734edce3322Smrgexec_cmd=
2735edce3322Smrg
2736edce3322Smrg
2737edce3322Smrg# A function that is used when there is no print builtin or printf.
2738edce3322Smrgfunc_fallback_echo ()
2739edce3322Smrg{
2740edce3322Smrg  eval 'cat <<_LTECHO_EOF
2741edce3322Smrg$1
2742edce3322Smrg_LTECHO_EOF'
2743edce3322Smrg}
2744edce3322Smrg
2745edce3322Smrg# func_generated_by_libtool
2746edce3322Smrg# True iff stdin has been generated by Libtool. This function is only
2747edce3322Smrg# a basic sanity check; it will hardly flush out determined imposters.
2748edce3322Smrgfunc_generated_by_libtool_p ()
2749edce3322Smrg{
2750edce3322Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751edce3322Smrg}
2752edce3322Smrg
27536e7d3316Smrg# func_lalib_p file
2754edce3322Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27556e7d3316Smrg# This function is only a basic sanity check; it will hardly flush out
27566e7d3316Smrg# determined imposters.
27576e7d3316Smrgfunc_lalib_p ()
27586e7d3316Smrg{
27596e7d3316Smrg    test -f "$1" &&
2760edce3322Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
27616e7d3316Smrg}
2762a966c04fSmrg
27636e7d3316Smrg# func_lalib_unsafe_p file
2764edce3322Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27656e7d3316Smrg# This function implements the same check as func_lalib_p without
27666e7d3316Smrg# resorting to external programs.  To this end, it redirects stdin and
27676e7d3316Smrg# closes it afterwards, without saving the original file descriptor.
27686e7d3316Smrg# As a safety measure, use it only where a negative result would be
2769edce3322Smrg# fatal anyway.  Works if 'file' does not exist.
27706e7d3316Smrgfunc_lalib_unsafe_p ()
27716e7d3316Smrg{
27726e7d3316Smrg    lalib_p=no
27736e7d3316Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
27746e7d3316Smrg	for lalib_p_l in 1 2 3 4
27756e7d3316Smrg	do
27766e7d3316Smrg	    read lalib_p_line
2777edce3322Smrg	    case $lalib_p_line in
27786e7d3316Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
27796e7d3316Smrg	    esac
27806e7d3316Smrg	done
27816e7d3316Smrg	exec 0<&5 5<&-
27826e7d3316Smrg    fi
2783edce3322Smrg    test yes = "$lalib_p"
27846e7d3316Smrg}
2785a966c04fSmrg
27866e7d3316Smrg# func_ltwrapper_script_p file
27876e7d3316Smrg# True iff FILE is a libtool wrapper script
27886e7d3316Smrg# This function is only a basic sanity check; it will hardly flush out
27896e7d3316Smrg# determined imposters.
27906e7d3316Smrgfunc_ltwrapper_script_p ()
27916e7d3316Smrg{
2792edce3322Smrg    test -f "$1" &&
2793edce3322Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
27946e7d3316Smrg}
2795a966c04fSmrg
27966e7d3316Smrg# func_ltwrapper_executable_p file
27976e7d3316Smrg# True iff FILE is a libtool wrapper executable
27986e7d3316Smrg# This function is only a basic sanity check; it will hardly flush out
27996e7d3316Smrg# determined imposters.
28006e7d3316Smrgfunc_ltwrapper_executable_p ()
28016e7d3316Smrg{
28026e7d3316Smrg    func_ltwrapper_exec_suffix=
28036e7d3316Smrg    case $1 in
28046e7d3316Smrg    *.exe) ;;
28056e7d3316Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
28066e7d3316Smrg    esac
28076e7d3316Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
28086e7d3316Smrg}
28096e7d3316Smrg
28106e7d3316Smrg# func_ltwrapper_scriptname file
28116e7d3316Smrg# Assumes file is an ltwrapper_executable
28126e7d3316Smrg# uses $file to determine the appropriate filename for a
28136e7d3316Smrg# temporary ltwrapper_script.
28146e7d3316Smrgfunc_ltwrapper_scriptname ()
28156e7d3316Smrg{
281697cf2ee2Smrg    func_dirname_and_basename "$1" "" "."
281797cf2ee2Smrg    func_stripname '' '.exe' "$func_basename_result"
2818edce3322Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
28196e7d3316Smrg}
28206e7d3316Smrg
28216e7d3316Smrg# func_ltwrapper_p file
28226e7d3316Smrg# True iff FILE is a libtool wrapper script or wrapper executable
28236e7d3316Smrg# This function is only a basic sanity check; it will hardly flush out
28246e7d3316Smrg# determined imposters.
28256e7d3316Smrgfunc_ltwrapper_p ()
28266e7d3316Smrg{
28276e7d3316Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
28286e7d3316Smrg}
28296e7d3316Smrg
28306e7d3316Smrg
28316e7d3316Smrg# func_execute_cmds commands fail_cmd
28326e7d3316Smrg# Execute tilde-delimited COMMANDS.
28336e7d3316Smrg# If FAIL_CMD is given, eval that upon failure.
28346e7d3316Smrg# FAIL_CMD may read-access the current command in variable CMD!
28356e7d3316Smrgfunc_execute_cmds ()
28366e7d3316Smrg{
2837edce3322Smrg    $debug_cmd
2838edce3322Smrg
28396e7d3316Smrg    save_ifs=$IFS; IFS='~'
28406e7d3316Smrg    for cmd in $1; do
2841edce3322Smrg      IFS=$sp$nl
28426e7d3316Smrg      eval cmd=\"$cmd\"
2843edce3322Smrg      IFS=$save_ifs
28446e7d3316Smrg      func_show_eval "$cmd" "${2-:}"
28456e7d3316Smrg    done
28466e7d3316Smrg    IFS=$save_ifs
28476e7d3316Smrg}
28486e7d3316Smrg
28496e7d3316Smrg
28506e7d3316Smrg# func_source file
28516e7d3316Smrg# Source FILE, adding directory component if necessary.
28526e7d3316Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
28536e7d3316Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
28546e7d3316Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855edce3322Smrg# 'FILE.' does not work on cygwin managed mounts.
28566e7d3316Smrgfunc_source ()
28576e7d3316Smrg{
2858edce3322Smrg    $debug_cmd
2859edce3322Smrg
28606e7d3316Smrg    case $1 in
28616e7d3316Smrg    */* | *\\*)	. "$1" ;;
28626e7d3316Smrg    *)		. "./$1" ;;
28636e7d3316Smrg    esac
28646e7d3316Smrg}
28656e7d3316Smrg
28666e7d3316Smrg
286797cf2ee2Smrg# func_resolve_sysroot PATH
286897cf2ee2Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
286997cf2ee2Smrg# func_resolve_sysroot_result
287097cf2ee2Smrgfunc_resolve_sysroot ()
287197cf2ee2Smrg{
287297cf2ee2Smrg  func_resolve_sysroot_result=$1
287397cf2ee2Smrg  case $func_resolve_sysroot_result in
287497cf2ee2Smrg  =*)
287597cf2ee2Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
287697cf2ee2Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
287797cf2ee2Smrg    ;;
287897cf2ee2Smrg  esac
287997cf2ee2Smrg}
288097cf2ee2Smrg
288197cf2ee2Smrg# func_replace_sysroot PATH
288297cf2ee2Smrg# If PATH begins with the sysroot, replace it with = and
288397cf2ee2Smrg# store the result into func_replace_sysroot_result.
288497cf2ee2Smrgfunc_replace_sysroot ()
288597cf2ee2Smrg{
2886edce3322Smrg  case $lt_sysroot:$1 in
288797cf2ee2Smrg  ?*:"$lt_sysroot"*)
288897cf2ee2Smrg    func_stripname "$lt_sysroot" '' "$1"
2889edce3322Smrg    func_replace_sysroot_result='='$func_stripname_result
289097cf2ee2Smrg    ;;
289197cf2ee2Smrg  *)
289297cf2ee2Smrg    # Including no sysroot.
289397cf2ee2Smrg    func_replace_sysroot_result=$1
289497cf2ee2Smrg    ;;
289597cf2ee2Smrg  esac
289697cf2ee2Smrg}
289797cf2ee2Smrg
28986e7d3316Smrg# func_infer_tag arg
28996e7d3316Smrg# Infer tagged configuration to use if any are available and
29006e7d3316Smrg# if one wasn't chosen via the "--tag" command line option.
29016e7d3316Smrg# Only attempt this if the compiler in the base compile
29026e7d3316Smrg# command doesn't match the default compiler.
29036e7d3316Smrg# arg is usually of the form 'gcc ...'
29046e7d3316Smrgfunc_infer_tag ()
29056e7d3316Smrg{
2906edce3322Smrg    $debug_cmd
2907edce3322Smrg
29086e7d3316Smrg    if test -n "$available_tags" && test -z "$tagname"; then
29096e7d3316Smrg      CC_quoted=
29106e7d3316Smrg      for arg in $CC; do
291197cf2ee2Smrg	func_append_quoted CC_quoted "$arg"
29126e7d3316Smrg      done
29136e7d3316Smrg      CC_expanded=`func_echo_all $CC`
29146e7d3316Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
29156e7d3316Smrg      case $@ in
29166e7d3316Smrg      # Blanks in the command may have been stripped by the calling shell,
29176e7d3316Smrg      # but not from the CC environment variable when configure was run.
29186e7d3316Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29196e7d3316Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
29206e7d3316Smrg      # Blanks at the start of $base_compile will cause this to fail
29216e7d3316Smrg      # if we don't check for them as well.
29226e7d3316Smrg      *)
29236e7d3316Smrg	for z in $available_tags; do
29246e7d3316Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
29256e7d3316Smrg	    # Evaluate the configuration.
2926edce3322Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
29276e7d3316Smrg	    CC_quoted=
29286e7d3316Smrg	    for arg in $CC; do
29296e7d3316Smrg	      # Double-quote args containing other shell metacharacters.
293097cf2ee2Smrg	      func_append_quoted CC_quoted "$arg"
29316e7d3316Smrg	    done
29326e7d3316Smrg	    CC_expanded=`func_echo_all $CC`
29336e7d3316Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
29346e7d3316Smrg	    case "$@ " in
29356e7d3316Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
29366e7d3316Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
29376e7d3316Smrg	      # The compiler in the base compile command matches
29386e7d3316Smrg	      # the one in the tagged configuration.
29396e7d3316Smrg	      # Assume this is the tagged configuration we want.
29406e7d3316Smrg	      tagname=$z
29416e7d3316Smrg	      break
29426e7d3316Smrg	      ;;
29436e7d3316Smrg	    esac
29446e7d3316Smrg	  fi
29456e7d3316Smrg	done
29466e7d3316Smrg	# If $tagname still isn't set, then no tagged configuration
29476e7d3316Smrg	# was found and let the user know that the "--tag" command
29486e7d3316Smrg	# line option must be used.
29496e7d3316Smrg	if test -z "$tagname"; then
29506e7d3316Smrg	  func_echo "unable to infer tagged configuration"
2951edce3322Smrg	  func_fatal_error "specify a tag with '--tag'"
29526e7d3316Smrg#	else
29536e7d3316Smrg#	  func_verbose "using $tagname tagged configuration"
29546e7d3316Smrg	fi
29556e7d3316Smrg	;;
29566e7d3316Smrg      esac
29576e7d3316Smrg    fi
29586e7d3316Smrg}
29596e7d3316Smrg
29606e7d3316Smrg
29616e7d3316Smrg
296297cf2ee2Smrg# func_write_libtool_object output_name pic_name nonpic_name
296397cf2ee2Smrg# Create a libtool object file (analogous to a ".la" file),
296497cf2ee2Smrg# but don't create it if we're doing a dry run.
296597cf2ee2Smrgfunc_write_libtool_object ()
296697cf2ee2Smrg{
2967edce3322Smrg    write_libobj=$1
2968edce3322Smrg    if test yes = "$build_libtool_libs"; then
2969edce3322Smrg      write_lobj=\'$2\'
297097cf2ee2Smrg    else
297197cf2ee2Smrg      write_lobj=none
297297cf2ee2Smrg    fi
297397cf2ee2Smrg
2974edce3322Smrg    if test yes = "$build_old_libs"; then
2975edce3322Smrg      write_oldobj=\'$3\'
297697cf2ee2Smrg    else
297797cf2ee2Smrg      write_oldobj=none
297897cf2ee2Smrg    fi
297997cf2ee2Smrg
298097cf2ee2Smrg    $opt_dry_run || {
298197cf2ee2Smrg      cat >${write_libobj}T <<EOF
298297cf2ee2Smrg# $write_libobj - a libtool object file
2983edce3322Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
298497cf2ee2Smrg#
298597cf2ee2Smrg# Please DO NOT delete this file!
298697cf2ee2Smrg# It is necessary for linking the library.
298797cf2ee2Smrg
298897cf2ee2Smrg# Name of the PIC object.
298997cf2ee2Smrgpic_object=$write_lobj
299097cf2ee2Smrg
299197cf2ee2Smrg# Name of the non-PIC object
299297cf2ee2Smrgnon_pic_object=$write_oldobj
299397cf2ee2Smrg
299497cf2ee2SmrgEOF
2995edce3322Smrg      $MV "${write_libobj}T" "$write_libobj"
299697cf2ee2Smrg    }
299797cf2ee2Smrg}
299897cf2ee2Smrg
299997cf2ee2Smrg
300097cf2ee2Smrg##################################################
300197cf2ee2Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
300297cf2ee2Smrg##################################################
300397cf2ee2Smrg
300497cf2ee2Smrg# func_convert_core_file_wine_to_w32 ARG
300597cf2ee2Smrg# Helper function used by file name conversion functions when $build is *nix,
300697cf2ee2Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
300797cf2ee2Smrg# correctly configured wine environment available, with the winepath program
300897cf2ee2Smrg# in $build's $PATH.
300997cf2ee2Smrg#
301097cf2ee2Smrg# ARG is the $build file name to be converted to w32 format.
301197cf2ee2Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
301297cf2ee2Smrg# be empty on error (or when ARG is empty)
301397cf2ee2Smrgfunc_convert_core_file_wine_to_w32 ()
301497cf2ee2Smrg{
3015edce3322Smrg  $debug_cmd
3016edce3322Smrg
3017edce3322Smrg  func_convert_core_file_wine_to_w32_result=$1
301897cf2ee2Smrg  if test -n "$1"; then
301997cf2ee2Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
302097cf2ee2Smrg    # are forced to check the contents of stdout. On the other hand, if the
302197cf2ee2Smrg    # command is not found, the shell will set an exit code of 127 and print
302297cf2ee2Smrg    # *an error message* to stdout. So we must check for both error code of
302397cf2ee2Smrg    # zero AND non-empty stdout, which explains the odd construction:
302497cf2ee2Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025edce3322Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
302697cf2ee2Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027edce3322Smrg        $SED -e "$sed_naive_backslashify"`
302897cf2ee2Smrg    else
302997cf2ee2Smrg      func_convert_core_file_wine_to_w32_result=
303097cf2ee2Smrg    fi
303197cf2ee2Smrg  fi
303297cf2ee2Smrg}
303397cf2ee2Smrg# end: func_convert_core_file_wine_to_w32
303497cf2ee2Smrg
303597cf2ee2Smrg
303697cf2ee2Smrg# func_convert_core_path_wine_to_w32 ARG
303797cf2ee2Smrg# Helper function used by path conversion functions when $build is *nix, and
303897cf2ee2Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
303997cf2ee2Smrg# configured wine environment available, with the winepath program in $build's
304097cf2ee2Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
304197cf2ee2Smrg#
304297cf2ee2Smrg# ARG is path to be converted from $build format to win32.
304397cf2ee2Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
304497cf2ee2Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
304597cf2ee2Smrg# are convertible, then the result may be empty.
304697cf2ee2Smrgfunc_convert_core_path_wine_to_w32 ()
304797cf2ee2Smrg{
3048edce3322Smrg  $debug_cmd
3049edce3322Smrg
305097cf2ee2Smrg  # unfortunately, winepath doesn't convert paths, only file names
3051edce3322Smrg  func_convert_core_path_wine_to_w32_result=
305297cf2ee2Smrg  if test -n "$1"; then
305397cf2ee2Smrg    oldIFS=$IFS
305497cf2ee2Smrg    IFS=:
305597cf2ee2Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
305697cf2ee2Smrg      IFS=$oldIFS
305797cf2ee2Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058edce3322Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
305997cf2ee2Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060edce3322Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
306197cf2ee2Smrg        else
306297cf2ee2Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
306397cf2ee2Smrg        fi
306497cf2ee2Smrg      fi
306597cf2ee2Smrg    done
306697cf2ee2Smrg    IFS=$oldIFS
306797cf2ee2Smrg  fi
306897cf2ee2Smrg}
306997cf2ee2Smrg# end: func_convert_core_path_wine_to_w32
307097cf2ee2Smrg
307197cf2ee2Smrg
307297cf2ee2Smrg# func_cygpath ARGS...
307397cf2ee2Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
307497cf2ee2Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
307597cf2ee2Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
307697cf2ee2Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
307797cf2ee2Smrg# file name or path is assumed to be in w32 format, as previously converted
307897cf2ee2Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
307997cf2ee2Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
308097cf2ee2Smrg# Cygwin format). Returns an empty string on error.
308197cf2ee2Smrg#
308297cf2ee2Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
308397cf2ee2Smrg# be converted.
308497cf2ee2Smrg#
308597cf2ee2Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
308697cf2ee2Smrg# environment variable; do not put it in $PATH.
308797cf2ee2Smrgfunc_cygpath ()
308897cf2ee2Smrg{
3089edce3322Smrg  $debug_cmd
3090edce3322Smrg
309197cf2ee2Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
309297cf2ee2Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
309397cf2ee2Smrg    if test "$?" -ne 0; then
309497cf2ee2Smrg      # on failure, ensure result is empty
309597cf2ee2Smrg      func_cygpath_result=
309697cf2ee2Smrg    fi
309797cf2ee2Smrg  else
309897cf2ee2Smrg    func_cygpath_result=
3099edce3322Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
310097cf2ee2Smrg  fi
310197cf2ee2Smrg}
310297cf2ee2Smrg#end: func_cygpath
310397cf2ee2Smrg
310497cf2ee2Smrg
310597cf2ee2Smrg# func_convert_core_msys_to_w32 ARG
310697cf2ee2Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
310797cf2ee2Smrg# result in func_convert_core_msys_to_w32_result.
310897cf2ee2Smrgfunc_convert_core_msys_to_w32 ()
310997cf2ee2Smrg{
3110edce3322Smrg  $debug_cmd
3111edce3322Smrg
311297cf2ee2Smrg  # awkward: cmd appends spaces to result
311397cf2ee2Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114edce3322Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
311597cf2ee2Smrg}
311697cf2ee2Smrg#end: func_convert_core_msys_to_w32
311797cf2ee2Smrg
311897cf2ee2Smrg
311997cf2ee2Smrg# func_convert_file_check ARG1 ARG2
312097cf2ee2Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
312197cf2ee2Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
312297cf2ee2Smrg# func_to_host_file_result to ARG1).
312397cf2ee2Smrgfunc_convert_file_check ()
312497cf2ee2Smrg{
3125edce3322Smrg  $debug_cmd
3126edce3322Smrg
3127edce3322Smrg  if test -z "$2" && test -n "$1"; then
312897cf2ee2Smrg    func_error "Could not determine host file name corresponding to"
3129edce3322Smrg    func_error "  '$1'"
313097cf2ee2Smrg    func_error "Continuing, but uninstalled executables may not work."
313197cf2ee2Smrg    # Fallback:
3132edce3322Smrg    func_to_host_file_result=$1
313397cf2ee2Smrg  fi
313497cf2ee2Smrg}
313597cf2ee2Smrg# end func_convert_file_check
313697cf2ee2Smrg
313797cf2ee2Smrg
313897cf2ee2Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
313997cf2ee2Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
314097cf2ee2Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
314197cf2ee2Smrg# func_to_host_file_result to a simplistic fallback value (see below).
314297cf2ee2Smrgfunc_convert_path_check ()
314397cf2ee2Smrg{
3144edce3322Smrg  $debug_cmd
3145edce3322Smrg
314697cf2ee2Smrg  if test -z "$4" && test -n "$3"; then
314797cf2ee2Smrg    func_error "Could not determine the host path corresponding to"
3148edce3322Smrg    func_error "  '$3'"
314997cf2ee2Smrg    func_error "Continuing, but uninstalled executables may not work."
315097cf2ee2Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
315197cf2ee2Smrg    # should not be "improved".  See libtool.info.
315297cf2ee2Smrg    if test "x$1" != "x$2"; then
315397cf2ee2Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
315497cf2ee2Smrg      func_to_host_path_result=`echo "$3" |
315597cf2ee2Smrg        $SED -e "$lt_replace_pathsep_chars"`
315697cf2ee2Smrg    else
3157edce3322Smrg      func_to_host_path_result=$3
315897cf2ee2Smrg    fi
315997cf2ee2Smrg  fi
316097cf2ee2Smrg}
316197cf2ee2Smrg# end func_convert_path_check
316297cf2ee2Smrg
316397cf2ee2Smrg
316497cf2ee2Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
316597cf2ee2Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
316697cf2ee2Smrg# and appending REPL if ORIG matches BACKPAT.
316797cf2ee2Smrgfunc_convert_path_front_back_pathsep ()
316897cf2ee2Smrg{
3169edce3322Smrg  $debug_cmd
3170edce3322Smrg
317197cf2ee2Smrg  case $4 in
3172edce3322Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
317397cf2ee2Smrg    ;;
317497cf2ee2Smrg  esac
317597cf2ee2Smrg  case $4 in
317697cf2ee2Smrg  $2 ) func_append func_to_host_path_result "$3"
317797cf2ee2Smrg    ;;
317897cf2ee2Smrg  esac
317997cf2ee2Smrg}
318097cf2ee2Smrg# end func_convert_path_front_back_pathsep
318197cf2ee2Smrg
318297cf2ee2Smrg
318397cf2ee2Smrg##################################################
318497cf2ee2Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
318597cf2ee2Smrg##################################################
3186edce3322Smrg# invoked via '$to_host_file_cmd ARG'
318797cf2ee2Smrg#
318897cf2ee2Smrg# In each case, ARG is the path to be converted from $build to $host format.
318997cf2ee2Smrg# Result will be available in $func_to_host_file_result.
319097cf2ee2Smrg
319197cf2ee2Smrg
319297cf2ee2Smrg# func_to_host_file ARG
319397cf2ee2Smrg# Converts the file name ARG from $build format to $host format. Return result
319497cf2ee2Smrg# in func_to_host_file_result.
319597cf2ee2Smrgfunc_to_host_file ()
319697cf2ee2Smrg{
3197edce3322Smrg  $debug_cmd
3198edce3322Smrg
319997cf2ee2Smrg  $to_host_file_cmd "$1"
320097cf2ee2Smrg}
320197cf2ee2Smrg# end func_to_host_file
320297cf2ee2Smrg
320397cf2ee2Smrg
320497cf2ee2Smrg# func_to_tool_file ARG LAZY
320597cf2ee2Smrg# converts the file name ARG from $build format to toolchain format. Return
320697cf2ee2Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
320797cf2ee2Smrg# in (the comma separated) LAZY, no conversion takes place.
320897cf2ee2Smrgfunc_to_tool_file ()
320997cf2ee2Smrg{
3210edce3322Smrg  $debug_cmd
3211edce3322Smrg
321297cf2ee2Smrg  case ,$2, in
321397cf2ee2Smrg    *,"$to_tool_file_cmd",*)
321497cf2ee2Smrg      func_to_tool_file_result=$1
321597cf2ee2Smrg      ;;
321697cf2ee2Smrg    *)
321797cf2ee2Smrg      $to_tool_file_cmd "$1"
321897cf2ee2Smrg      func_to_tool_file_result=$func_to_host_file_result
321997cf2ee2Smrg      ;;
322097cf2ee2Smrg  esac
322197cf2ee2Smrg}
322297cf2ee2Smrg# end func_to_tool_file
322397cf2ee2Smrg
322497cf2ee2Smrg
322597cf2ee2Smrg# func_convert_file_noop ARG
322697cf2ee2Smrg# Copy ARG to func_to_host_file_result.
322797cf2ee2Smrgfunc_convert_file_noop ()
322897cf2ee2Smrg{
3229edce3322Smrg  func_to_host_file_result=$1
323097cf2ee2Smrg}
323197cf2ee2Smrg# end func_convert_file_noop
323297cf2ee2Smrg
323397cf2ee2Smrg
323497cf2ee2Smrg# func_convert_file_msys_to_w32 ARG
323597cf2ee2Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
323697cf2ee2Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
323797cf2ee2Smrg# func_to_host_file_result.
323897cf2ee2Smrgfunc_convert_file_msys_to_w32 ()
323997cf2ee2Smrg{
3240edce3322Smrg  $debug_cmd
3241edce3322Smrg
3242edce3322Smrg  func_to_host_file_result=$1
324397cf2ee2Smrg  if test -n "$1"; then
324497cf2ee2Smrg    func_convert_core_msys_to_w32 "$1"
3245edce3322Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
324697cf2ee2Smrg  fi
324797cf2ee2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
324897cf2ee2Smrg}
324997cf2ee2Smrg# end func_convert_file_msys_to_w32
325097cf2ee2Smrg
325197cf2ee2Smrg
325297cf2ee2Smrg# func_convert_file_cygwin_to_w32 ARG
325397cf2ee2Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
325497cf2ee2Smrg# func_to_host_file_result.
325597cf2ee2Smrgfunc_convert_file_cygwin_to_w32 ()
325697cf2ee2Smrg{
3257edce3322Smrg  $debug_cmd
3258edce3322Smrg
3259edce3322Smrg  func_to_host_file_result=$1
326097cf2ee2Smrg  if test -n "$1"; then
326197cf2ee2Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
326297cf2ee2Smrg    # LT_CYGPATH in this case.
326397cf2ee2Smrg    func_to_host_file_result=`cygpath -m "$1"`
326497cf2ee2Smrg  fi
326597cf2ee2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
326697cf2ee2Smrg}
326797cf2ee2Smrg# end func_convert_file_cygwin_to_w32
326897cf2ee2Smrg
326997cf2ee2Smrg
327097cf2ee2Smrg# func_convert_file_nix_to_w32 ARG
327197cf2ee2Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
327297cf2ee2Smrg# and a working winepath. Returns result in func_to_host_file_result.
327397cf2ee2Smrgfunc_convert_file_nix_to_w32 ()
327497cf2ee2Smrg{
3275edce3322Smrg  $debug_cmd
3276edce3322Smrg
3277edce3322Smrg  func_to_host_file_result=$1
327897cf2ee2Smrg  if test -n "$1"; then
327997cf2ee2Smrg    func_convert_core_file_wine_to_w32 "$1"
3280edce3322Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
328197cf2ee2Smrg  fi
328297cf2ee2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
328397cf2ee2Smrg}
328497cf2ee2Smrg# end func_convert_file_nix_to_w32
328597cf2ee2Smrg
328697cf2ee2Smrg
328797cf2ee2Smrg# func_convert_file_msys_to_cygwin ARG
328897cf2ee2Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
328997cf2ee2Smrg# Returns result in func_to_host_file_result.
329097cf2ee2Smrgfunc_convert_file_msys_to_cygwin ()
329197cf2ee2Smrg{
3292edce3322Smrg  $debug_cmd
3293edce3322Smrg
3294edce3322Smrg  func_to_host_file_result=$1
329597cf2ee2Smrg  if test -n "$1"; then
329697cf2ee2Smrg    func_convert_core_msys_to_w32 "$1"
329797cf2ee2Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298edce3322Smrg    func_to_host_file_result=$func_cygpath_result
329997cf2ee2Smrg  fi
330097cf2ee2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
330197cf2ee2Smrg}
330297cf2ee2Smrg# end func_convert_file_msys_to_cygwin
330397cf2ee2Smrg
330497cf2ee2Smrg
330597cf2ee2Smrg# func_convert_file_nix_to_cygwin ARG
330697cf2ee2Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
330797cf2ee2Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
330897cf2ee2Smrg# in func_to_host_file_result.
330997cf2ee2Smrgfunc_convert_file_nix_to_cygwin ()
331097cf2ee2Smrg{
3311edce3322Smrg  $debug_cmd
3312edce3322Smrg
3313edce3322Smrg  func_to_host_file_result=$1
331497cf2ee2Smrg  if test -n "$1"; then
331597cf2ee2Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
331697cf2ee2Smrg    func_convert_core_file_wine_to_w32 "$1"
331797cf2ee2Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318edce3322Smrg    func_to_host_file_result=$func_cygpath_result
331997cf2ee2Smrg  fi
332097cf2ee2Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
332197cf2ee2Smrg}
332297cf2ee2Smrg# end func_convert_file_nix_to_cygwin
332397cf2ee2Smrg
332497cf2ee2Smrg
332597cf2ee2Smrg#############################################
332697cf2ee2Smrg# $build to $host PATH CONVERSION FUNCTIONS #
332797cf2ee2Smrg#############################################
3328edce3322Smrg# invoked via '$to_host_path_cmd ARG'
332997cf2ee2Smrg#
333097cf2ee2Smrg# In each case, ARG is the path to be converted from $build to $host format.
333197cf2ee2Smrg# The result will be available in $func_to_host_path_result.
333297cf2ee2Smrg#
333397cf2ee2Smrg# Path separators are also converted from $build format to $host format.  If
333497cf2ee2Smrg# ARG begins or ends with a path separator character, it is preserved (but
333597cf2ee2Smrg# converted to $host format) on output.
333697cf2ee2Smrg#
333797cf2ee2Smrg# All path conversion functions are named using the following convention:
333897cf2ee2Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
333997cf2ee2Smrg#   path conversion function         : func_convert_path_X_to_Y ()
334097cf2ee2Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
334197cf2ee2Smrg# same.  If conversion functions are added for new $build/$host combinations,
334297cf2ee2Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
334397cf2ee2Smrg# will break.
334497cf2ee2Smrg
334597cf2ee2Smrg
334697cf2ee2Smrg# func_init_to_host_path_cmd
334797cf2ee2Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
334897cf2ee2Smrg# appropriate value, based on the value of $to_host_file_cmd.
334997cf2ee2Smrgto_host_path_cmd=
335097cf2ee2Smrgfunc_init_to_host_path_cmd ()
335197cf2ee2Smrg{
3352edce3322Smrg  $debug_cmd
3353edce3322Smrg
335497cf2ee2Smrg  if test -z "$to_host_path_cmd"; then
335597cf2ee2Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356edce3322Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
335797cf2ee2Smrg  fi
335897cf2ee2Smrg}
335997cf2ee2Smrg
336097cf2ee2Smrg
336197cf2ee2Smrg# func_to_host_path ARG
336297cf2ee2Smrg# Converts the path ARG from $build format to $host format. Return result
336397cf2ee2Smrg# in func_to_host_path_result.
336497cf2ee2Smrgfunc_to_host_path ()
336597cf2ee2Smrg{
3366edce3322Smrg  $debug_cmd
3367edce3322Smrg
336897cf2ee2Smrg  func_init_to_host_path_cmd
336997cf2ee2Smrg  $to_host_path_cmd "$1"
337097cf2ee2Smrg}
337197cf2ee2Smrg# end func_to_host_path
337297cf2ee2Smrg
337397cf2ee2Smrg
337497cf2ee2Smrg# func_convert_path_noop ARG
337597cf2ee2Smrg# Copy ARG to func_to_host_path_result.
337697cf2ee2Smrgfunc_convert_path_noop ()
337797cf2ee2Smrg{
3378edce3322Smrg  func_to_host_path_result=$1
337997cf2ee2Smrg}
338097cf2ee2Smrg# end func_convert_path_noop
338197cf2ee2Smrg
338297cf2ee2Smrg
338397cf2ee2Smrg# func_convert_path_msys_to_w32 ARG
338497cf2ee2Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
338597cf2ee2Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
338697cf2ee2Smrg# func_to_host_path_result.
338797cf2ee2Smrgfunc_convert_path_msys_to_w32 ()
33886e7d3316Smrg{
3389edce3322Smrg  $debug_cmd
3390edce3322Smrg
3391edce3322Smrg  func_to_host_path_result=$1
339297cf2ee2Smrg  if test -n "$1"; then
339397cf2ee2Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
339497cf2ee2Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
339597cf2ee2Smrg    # and winepath ignores them completely.
339697cf2ee2Smrg    func_stripname : : "$1"
339797cf2ee2Smrg    func_to_host_path_tmp1=$func_stripname_result
339897cf2ee2Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399edce3322Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
340097cf2ee2Smrg    func_convert_path_check : ";" \
340197cf2ee2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
340297cf2ee2Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
340397cf2ee2Smrg  fi
340497cf2ee2Smrg}
340597cf2ee2Smrg# end func_convert_path_msys_to_w32
34066e7d3316Smrg
34076e7d3316Smrg
340897cf2ee2Smrg# func_convert_path_cygwin_to_w32 ARG
340997cf2ee2Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
341097cf2ee2Smrg# func_to_host_file_result.
341197cf2ee2Smrgfunc_convert_path_cygwin_to_w32 ()
341297cf2ee2Smrg{
3413edce3322Smrg  $debug_cmd
3414edce3322Smrg
3415edce3322Smrg  func_to_host_path_result=$1
341697cf2ee2Smrg  if test -n "$1"; then
341797cf2ee2Smrg    # See func_convert_path_msys_to_w32:
341897cf2ee2Smrg    func_stripname : : "$1"
341997cf2ee2Smrg    func_to_host_path_tmp1=$func_stripname_result
342097cf2ee2Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
342197cf2ee2Smrg    func_convert_path_check : ";" \
342297cf2ee2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
342397cf2ee2Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
342497cf2ee2Smrg  fi
342597cf2ee2Smrg}
342697cf2ee2Smrg# end func_convert_path_cygwin_to_w32
34276e7d3316Smrg
34286e7d3316Smrg
342997cf2ee2Smrg# func_convert_path_nix_to_w32 ARG
343097cf2ee2Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
343197cf2ee2Smrg# a working winepath.  Returns result in func_to_host_file_result.
343297cf2ee2Smrgfunc_convert_path_nix_to_w32 ()
343397cf2ee2Smrg{
3434edce3322Smrg  $debug_cmd
3435edce3322Smrg
3436edce3322Smrg  func_to_host_path_result=$1
343797cf2ee2Smrg  if test -n "$1"; then
343897cf2ee2Smrg    # See func_convert_path_msys_to_w32:
343997cf2ee2Smrg    func_stripname : : "$1"
344097cf2ee2Smrg    func_to_host_path_tmp1=$func_stripname_result
344197cf2ee2Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442edce3322Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
344397cf2ee2Smrg    func_convert_path_check : ";" \
344497cf2ee2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
344597cf2ee2Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
344697cf2ee2Smrg  fi
344797cf2ee2Smrg}
344897cf2ee2Smrg# end func_convert_path_nix_to_w32
34496e7d3316Smrg
345097cf2ee2Smrg
345197cf2ee2Smrg# func_convert_path_msys_to_cygwin ARG
345297cf2ee2Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
345397cf2ee2Smrg# Returns result in func_to_host_file_result.
345497cf2ee2Smrgfunc_convert_path_msys_to_cygwin ()
345597cf2ee2Smrg{
3456edce3322Smrg  $debug_cmd
3457edce3322Smrg
3458edce3322Smrg  func_to_host_path_result=$1
345997cf2ee2Smrg  if test -n "$1"; then
346097cf2ee2Smrg    # See func_convert_path_msys_to_w32:
346197cf2ee2Smrg    func_stripname : : "$1"
346297cf2ee2Smrg    func_to_host_path_tmp1=$func_stripname_result
346397cf2ee2Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
346497cf2ee2Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465edce3322Smrg    func_to_host_path_result=$func_cygpath_result
346697cf2ee2Smrg    func_convert_path_check : : \
346797cf2ee2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
346897cf2ee2Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
346997cf2ee2Smrg  fi
347097cf2ee2Smrg}
347197cf2ee2Smrg# end func_convert_path_msys_to_cygwin
347297cf2ee2Smrg
347397cf2ee2Smrg
347497cf2ee2Smrg# func_convert_path_nix_to_cygwin ARG
347597cf2ee2Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
347697cf2ee2Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
347797cf2ee2Smrg# func_to_host_file_result.
347897cf2ee2Smrgfunc_convert_path_nix_to_cygwin ()
347997cf2ee2Smrg{
3480edce3322Smrg  $debug_cmd
3481edce3322Smrg
3482edce3322Smrg  func_to_host_path_result=$1
348397cf2ee2Smrg  if test -n "$1"; then
348497cf2ee2Smrg    # Remove leading and trailing path separator characters from
348597cf2ee2Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
348697cf2ee2Smrg    # into '.;' and ';.', and winepath ignores them completely.
348797cf2ee2Smrg    func_stripname : : "$1"
348897cf2ee2Smrg    func_to_host_path_tmp1=$func_stripname_result
348997cf2ee2Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
349097cf2ee2Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491edce3322Smrg    func_to_host_path_result=$func_cygpath_result
349297cf2ee2Smrg    func_convert_path_check : : \
349397cf2ee2Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
349497cf2ee2Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
349597cf2ee2Smrg  fi
34966e7d3316Smrg}
349797cf2ee2Smrg# end func_convert_path_nix_to_cygwin
349897cf2ee2Smrg
34996e7d3316Smrg
3500edce3322Smrg# func_dll_def_p FILE
3501edce3322Smrg# True iff FILE is a Windows DLL '.def' file.
3502edce3322Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503edce3322Smrgfunc_dll_def_p ()
3504edce3322Smrg{
3505edce3322Smrg  $debug_cmd
3506edce3322Smrg
3507edce3322Smrg  func_dll_def_p_tmp=`$SED -n \
3508edce3322Smrg    -e 's/^[	 ]*//' \
3509edce3322Smrg    -e '/^\(;.*\)*$/d' \
3510edce3322Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511edce3322Smrg    -e q \
3512edce3322Smrg    "$1"`
3513edce3322Smrg  test DEF = "$func_dll_def_p_tmp"
3514edce3322Smrg}
3515edce3322Smrg
3516edce3322Smrg
35176e7d3316Smrg# func_mode_compile arg...
35186e7d3316Smrgfunc_mode_compile ()
35196e7d3316Smrg{
3520edce3322Smrg    $debug_cmd
3521edce3322Smrg
35226e7d3316Smrg    # Get the compilation command and the source file.
35236e7d3316Smrg    base_compile=
3524edce3322Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
35256e7d3316Smrg    suppress_opt=yes
35266e7d3316Smrg    suppress_output=
35276e7d3316Smrg    arg_mode=normal
35286e7d3316Smrg    libobj=
35296e7d3316Smrg    later=
35306e7d3316Smrg    pie_flag=
35316e7d3316Smrg
35326e7d3316Smrg    for arg
35336e7d3316Smrg    do
35346e7d3316Smrg      case $arg_mode in
35356e7d3316Smrg      arg  )
35366e7d3316Smrg	# do not "continue".  Instead, add this to base_compile
3537edce3322Smrg	lastarg=$arg
35386e7d3316Smrg	arg_mode=normal
35396e7d3316Smrg	;;
35406e7d3316Smrg
35416e7d3316Smrg      target )
3542edce3322Smrg	libobj=$arg
35436e7d3316Smrg	arg_mode=normal
35446e7d3316Smrg	continue
35456e7d3316Smrg	;;
35466e7d3316Smrg
35476e7d3316Smrg      normal )
35486e7d3316Smrg	# Accept any command-line options.
35496e7d3316Smrg	case $arg in
35506e7d3316Smrg	-o)
35516e7d3316Smrg	  test -n "$libobj" && \
3552edce3322Smrg	    func_fatal_error "you cannot specify '-o' more than once"
35536e7d3316Smrg	  arg_mode=target
35546e7d3316Smrg	  continue
35556e7d3316Smrg	  ;;
35566e7d3316Smrg
35576e7d3316Smrg	-pie | -fpie | -fPIE)
355897cf2ee2Smrg          func_append pie_flag " $arg"
35596e7d3316Smrg	  continue
35606e7d3316Smrg	  ;;
35616e7d3316Smrg
35626e7d3316Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
356397cf2ee2Smrg	  func_append later " $arg"
35646e7d3316Smrg	  continue
35656e7d3316Smrg	  ;;
3566a966c04fSmrg
3567a966c04fSmrg	-no-suppress)
3568a966c04fSmrg	  suppress_opt=no
3569a966c04fSmrg	  continue
3570a966c04fSmrg	  ;;
3571a966c04fSmrg
3572a966c04fSmrg	-Xcompiler)
3573a966c04fSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3574a966c04fSmrg	  continue      #  The current "srcfile" will either be retained or
3575a966c04fSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3576a966c04fSmrg
3577a966c04fSmrg	-Wc,*)
35786e7d3316Smrg	  func_stripname '-Wc,' '' "$arg"
35796e7d3316Smrg	  args=$func_stripname_result
3580a966c04fSmrg	  lastarg=
3581edce3322Smrg	  save_ifs=$IFS; IFS=,
35826e7d3316Smrg	  for arg in $args; do
3583edce3322Smrg	    IFS=$save_ifs
358497cf2ee2Smrg	    func_append_quoted lastarg "$arg"
3585a966c04fSmrg	  done
3586edce3322Smrg	  IFS=$save_ifs
35876e7d3316Smrg	  func_stripname ' ' '' "$lastarg"
35886e7d3316Smrg	  lastarg=$func_stripname_result
3589a966c04fSmrg
3590a966c04fSmrg	  # Add the arguments to base_compile.
359197cf2ee2Smrg	  func_append base_compile " $lastarg"
3592a966c04fSmrg	  continue
3593a966c04fSmrg	  ;;
3594a966c04fSmrg
35956e7d3316Smrg	*)
3596a966c04fSmrg	  # Accept the current argument as the source file.
3597a966c04fSmrg	  # The previous "srcfile" becomes the current argument.
3598a966c04fSmrg	  #
3599edce3322Smrg	  lastarg=$srcfile
3600edce3322Smrg	  srcfile=$arg
3601a966c04fSmrg	  ;;
3602a966c04fSmrg	esac  #  case $arg
3603a966c04fSmrg	;;
3604a966c04fSmrg      esac    #  case $arg_mode
3605a966c04fSmrg
3606a966c04fSmrg      # Aesthetically quote the previous argument.
360797cf2ee2Smrg      func_append_quoted base_compile "$lastarg"
3608a966c04fSmrg    done # for arg
3609a966c04fSmrg
3610a966c04fSmrg    case $arg_mode in
3611a966c04fSmrg    arg)
36126e7d3316Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3613a966c04fSmrg      ;;
3614a966c04fSmrg    target)
3615edce3322Smrg      func_fatal_error "you must specify a target with '-o'"
3616a966c04fSmrg      ;;
3617a966c04fSmrg    *)
3618a966c04fSmrg      # Get the name of the library object.
36196e7d3316Smrg      test -z "$libobj" && {
36206e7d3316Smrg	func_basename "$srcfile"
3621edce3322Smrg	libobj=$func_basename_result
36226e7d3316Smrg      }
3623a966c04fSmrg      ;;
3624a966c04fSmrg    esac
3625a966c04fSmrg
3626a966c04fSmrg    # Recognize several different file suffixes.
3627a966c04fSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3628a966c04fSmrg    case $libobj in
36296e7d3316Smrg    *.[cCFSifmso] | \
36306e7d3316Smrg    *.ada | *.adb | *.ads | *.asm | \
36316e7d3316Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632ac92798bSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
36336e7d3316Smrg      func_xform "$libobj"
36346e7d3316Smrg      libobj=$func_xform_result
36356e7d3316Smrg      ;;
3636a966c04fSmrg    esac
3637a966c04fSmrg
3638a966c04fSmrg    case $libobj in
36396e7d3316Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3640a966c04fSmrg    *)
3641edce3322Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3642a966c04fSmrg      ;;
3643a966c04fSmrg    esac
3644a966c04fSmrg
3645a966c04fSmrg    func_infer_tag $base_compile
3646a966c04fSmrg
3647a966c04fSmrg    for arg in $later; do
3648a966c04fSmrg      case $arg in
36496e7d3316Smrg      -shared)
3650edce3322Smrg	test yes = "$build_libtool_libs" \
3651edce3322Smrg	  || func_fatal_configuration "cannot build a shared library"
36526e7d3316Smrg	build_old_libs=no
36536e7d3316Smrg	continue
36546e7d3316Smrg	;;
36556e7d3316Smrg
3656a966c04fSmrg      -static)
36576e7d3316Smrg	build_libtool_libs=no
3658a966c04fSmrg	build_old_libs=yes
3659a966c04fSmrg	continue
3660a966c04fSmrg	;;
3661a966c04fSmrg
3662a966c04fSmrg      -prefer-pic)
3663a966c04fSmrg	pic_mode=yes
3664a966c04fSmrg	continue
3665a966c04fSmrg	;;
3666a966c04fSmrg
3667a966c04fSmrg      -prefer-non-pic)
3668a966c04fSmrg	pic_mode=no
3669a966c04fSmrg	continue
3670a966c04fSmrg	;;
3671a966c04fSmrg      esac
3672a966c04fSmrg    done
3673a966c04fSmrg
367474835918Smrg    func_quote_arg pretty "$libobj"
367574835918Smrg    test "X$libobj" != "X$func_quote_arg_result" \
36766e7d3316Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677edce3322Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
36786e7d3316Smrg    func_dirname_and_basename "$obj" "/" ""
3679edce3322Smrg    objname=$func_basename_result
3680edce3322Smrg    xdir=$func_dirname_result
3681edce3322Smrg    lobj=$xdir$objdir/$objname
3682a966c04fSmrg
36836e7d3316Smrg    test -z "$base_compile" && \
36846e7d3316Smrg      func_fatal_help "you must specify a compilation command"
3685a966c04fSmrg
3686a966c04fSmrg    # Delete any leftover library objects.
3687edce3322Smrg    if test yes = "$build_old_libs"; then
3688a966c04fSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3689a966c04fSmrg    else
3690a966c04fSmrg      removelist="$lobj $libobj ${libobj}T"
3691a966c04fSmrg    fi
3692a966c04fSmrg
3693a966c04fSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3694a966c04fSmrg    case $host_os in
36956e7d3316Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3696a966c04fSmrg      pic_mode=default
3697a966c04fSmrg      ;;
3698a966c04fSmrg    esac
3699edce3322Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3700a966c04fSmrg      # non-PIC code in shared libraries is not supported
3701a966c04fSmrg      pic_mode=default
3702a966c04fSmrg    fi
3703a966c04fSmrg
3704a966c04fSmrg    # Calculate the filename of the output object if compiler does
3705a966c04fSmrg    # not support -o with -c
3706edce3322Smrg    if test no = "$compiler_c_o"; then
3707edce3322Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708edce3322Smrg      lockfile=$output_obj.lock
3709a966c04fSmrg    else
3710a966c04fSmrg      output_obj=
3711a966c04fSmrg      need_locks=no
3712a966c04fSmrg      lockfile=
3713a966c04fSmrg    fi
3714a966c04fSmrg
3715a966c04fSmrg    # Lock this critical section if it is needed
3716a966c04fSmrg    # We use this script file to make the link, it avoids creating a new file
3717edce3322Smrg    if test yes = "$need_locks"; then
37186e7d3316Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
37196e7d3316Smrg	func_echo "Waiting for $lockfile to be removed"
3720a966c04fSmrg	sleep 2
3721a966c04fSmrg      done
3722edce3322Smrg    elif test warn = "$need_locks"; then
3723a966c04fSmrg      if test -f "$lockfile"; then
37246e7d3316Smrg	$ECHO "\
3725a966c04fSmrg*** ERROR, $lockfile exists and contains:
3726a966c04fSmrg`cat $lockfile 2>/dev/null`
3727a966c04fSmrg
3728a966c04fSmrgThis indicates that another process is trying to use the same
3729a966c04fSmrgtemporary object file, and libtool could not work around it because
3730edce3322Smrgyour compiler does not support '-c' and '-o' together.  If you
3731a966c04fSmrgrepeat this compilation, it may succeed, by chance, but you had better
3732a966c04fSmrgavoid parallel builds (make -j) in this platform, or get a better
3733a966c04fSmrgcompiler."
3734a966c04fSmrg
37356e7d3316Smrg	$opt_dry_run || $RM $removelist
3736a966c04fSmrg	exit $EXIT_FAILURE
3737a966c04fSmrg      fi
373897cf2ee2Smrg      func_append removelist " $output_obj"
37396e7d3316Smrg      $ECHO "$srcfile" > "$lockfile"
3740a966c04fSmrg    fi
3741a966c04fSmrg
37426e7d3316Smrg    $opt_dry_run || $RM $removelist
374397cf2ee2Smrg    func_append removelist " $lockfile"
37446e7d3316Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
37456e7d3316Smrg
374697cf2ee2Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
374797cf2ee2Smrg    srcfile=$func_to_tool_file_result
374874835918Smrg    func_quote_arg pretty "$srcfile"
374974835918Smrg    qsrcfile=$func_quote_arg_result
3750a966c04fSmrg
3751a966c04fSmrg    # Only build a PIC object if we are building libtool libraries.
3752edce3322Smrg    if test yes = "$build_libtool_libs"; then
3753a966c04fSmrg      # Without this assignment, base_compile gets emptied.
3754a966c04fSmrg      fbsd_hideous_sh_bug=$base_compile
3755a966c04fSmrg
3756edce3322Smrg      if test no != "$pic_mode"; then
3757a966c04fSmrg	command="$base_compile $qsrcfile $pic_flag"
3758a966c04fSmrg      else
3759a966c04fSmrg	# Don't build PIC code
3760a966c04fSmrg	command="$base_compile $qsrcfile"
3761a966c04fSmrg      fi
3762a966c04fSmrg
37636e7d3316Smrg      func_mkdir_p "$xdir$objdir"
3764a966c04fSmrg
3765a966c04fSmrg      if test -z "$output_obj"; then
3766a966c04fSmrg	# Place PIC objects in $objdir
376797cf2ee2Smrg	func_append command " -o $lobj"
3768a966c04fSmrg      fi
3769a966c04fSmrg
37706e7d3316Smrg      func_show_eval_locale "$command"	\
37716e7d3316Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3772a966c04fSmrg
3773edce3322Smrg      if test warn = "$need_locks" &&
3774a966c04fSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
37756e7d3316Smrg	$ECHO "\
3776a966c04fSmrg*** ERROR, $lockfile contains:
3777a966c04fSmrg`cat $lockfile 2>/dev/null`
3778a966c04fSmrg
3779a966c04fSmrgbut it should contain:
3780a966c04fSmrg$srcfile
3781a966c04fSmrg
3782a966c04fSmrgThis indicates that another process is trying to use the same
3783a966c04fSmrgtemporary object file, and libtool could not work around it because
3784edce3322Smrgyour compiler does not support '-c' and '-o' together.  If you
3785a966c04fSmrgrepeat this compilation, it may succeed, by chance, but you had better
3786a966c04fSmrgavoid parallel builds (make -j) in this platform, or get a better
3787a966c04fSmrgcompiler."
3788a966c04fSmrg
37896e7d3316Smrg	$opt_dry_run || $RM $removelist
3790a966c04fSmrg	exit $EXIT_FAILURE
3791a966c04fSmrg      fi
3792a966c04fSmrg
3793a966c04fSmrg      # Just move the object if needed, then go on to compile the next one
3794a966c04fSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
37956e7d3316Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
37966e7d3316Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3797a966c04fSmrg      fi
3798a966c04fSmrg
3799a966c04fSmrg      # Allow error messages only from the first compilation.
3800edce3322Smrg      if test yes = "$suppress_opt"; then
38016e7d3316Smrg	suppress_output=' >/dev/null 2>&1'
3802a966c04fSmrg      fi
3803a966c04fSmrg    fi
3804a966c04fSmrg
3805a966c04fSmrg    # Only build a position-dependent object if we build old libraries.
3806edce3322Smrg    if test yes = "$build_old_libs"; then
3807edce3322Smrg      if test yes != "$pic_mode"; then
3808a966c04fSmrg	# Don't build PIC code
38096e7d3316Smrg	command="$base_compile $qsrcfile$pie_flag"
3810a966c04fSmrg      else
3811a966c04fSmrg	command="$base_compile $qsrcfile $pic_flag"
3812a966c04fSmrg      fi
3813edce3322Smrg      if test yes = "$compiler_c_o"; then
381497cf2ee2Smrg	func_append command " -o $obj"
3815a966c04fSmrg      fi
3816a966c04fSmrg
3817a966c04fSmrg      # Suppress compiler output if we already did a PIC compilation.
381897cf2ee2Smrg      func_append command "$suppress_output"
38196e7d3316Smrg      func_show_eval_locale "$command" \
38206e7d3316Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3821a966c04fSmrg
3822edce3322Smrg      if test warn = "$need_locks" &&
3823a966c04fSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
38246e7d3316Smrg	$ECHO "\
3825a966c04fSmrg*** ERROR, $lockfile contains:
3826a966c04fSmrg`cat $lockfile 2>/dev/null`
3827a966c04fSmrg
3828a966c04fSmrgbut it should contain:
3829a966c04fSmrg$srcfile
3830a966c04fSmrg
3831a966c04fSmrgThis indicates that another process is trying to use the same
3832a966c04fSmrgtemporary object file, and libtool could not work around it because
3833edce3322Smrgyour compiler does not support '-c' and '-o' together.  If you
3834a966c04fSmrgrepeat this compilation, it may succeed, by chance, but you had better
3835a966c04fSmrgavoid parallel builds (make -j) in this platform, or get a better
3836a966c04fSmrgcompiler."
3837a966c04fSmrg
38386e7d3316Smrg	$opt_dry_run || $RM $removelist
3839a966c04fSmrg	exit $EXIT_FAILURE
3840a966c04fSmrg      fi
3841a966c04fSmrg
3842a966c04fSmrg      # Just move the object if needed
3843a966c04fSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
38446e7d3316Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
38456e7d3316Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3846a966c04fSmrg      fi
3847a966c04fSmrg    fi
3848a966c04fSmrg
38496e7d3316Smrg    $opt_dry_run || {
38506e7d3316Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851a966c04fSmrg
38526e7d3316Smrg      # Unlock the critical section if it was locked
3853edce3322Smrg      if test no != "$need_locks"; then
38546e7d3316Smrg	removelist=$lockfile
38556e7d3316Smrg        $RM "$lockfile"
38566e7d3316Smrg      fi
38576e7d3316Smrg    }
3858a966c04fSmrg
3859a966c04fSmrg    exit $EXIT_SUCCESS
38606e7d3316Smrg}
3861a966c04fSmrg
38626e7d3316Smrg$opt_help || {
3863edce3322Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
38646e7d3316Smrg}
3865a966c04fSmrg
38666e7d3316Smrgfunc_mode_help ()
38676e7d3316Smrg{
38686e7d3316Smrg    # We need to display help for each of the modes.
386997cf2ee2Smrg    case $opt_mode in
38706e7d3316Smrg      "")
38716e7d3316Smrg        # Generic help is extracted from the usage comments
38726e7d3316Smrg        # at the start of this file.
38736e7d3316Smrg        func_help
38746e7d3316Smrg        ;;
3875a966c04fSmrg
38766e7d3316Smrg      clean)
38776e7d3316Smrg        $ECHO \
38786e7d3316Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879a966c04fSmrg
38806e7d3316SmrgRemove files from the build directory.
3881a966c04fSmrg
38826e7d3316SmrgRM is the name of the program to use to delete files associated with each FILE
3883edce3322Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
38846e7d3316Smrgto RM.
3885a966c04fSmrg
38866e7d3316SmrgIf FILE is a libtool library, object or program, all the files associated
38876e7d3316Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
38886e7d3316Smrg        ;;
3889a966c04fSmrg
38906e7d3316Smrg      compile)
38916e7d3316Smrg      $ECHO \
38926e7d3316Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893a966c04fSmrg
38946e7d3316SmrgCompile a source file into a libtool library object.
3895a966c04fSmrg
38966e7d3316SmrgThis mode accepts the following additional options:
3897a966c04fSmrg
38986e7d3316Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
38996e7d3316Smrg  -no-suppress      do not suppress compiler output for multiple passes
39006e7d3316Smrg  -prefer-pic       try to build PIC objects only
39016e7d3316Smrg  -prefer-non-pic   try to build non-PIC objects only
3902edce3322Smrg  -shared           do not build a '.o' file suitable for static linking
3903edce3322Smrg  -static           only build a '.o' file suitable for static linking
390474835918Smrg  -Wc,FLAG
390574835918Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906a966c04fSmrg
3907edce3322SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
39086e7d3316Smrgfrom the given SOURCEFILE.
3909a966c04fSmrg
39106e7d3316SmrgThe output file name is determined by removing the directory component from
3911edce3322SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912edce3322Smrglibrary object suffix, '.lo'."
39136e7d3316Smrg        ;;
3914a966c04fSmrg
39156e7d3316Smrg      execute)
39166e7d3316Smrg        $ECHO \
39176e7d3316Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3918a966c04fSmrg
39196e7d3316SmrgAutomatically set library path, then run a program.
3920a966c04fSmrg
39216e7d3316SmrgThis mode accepts the following additional options:
3922a966c04fSmrg
39236e7d3316Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924a966c04fSmrg
3925edce3322SmrgThis mode sets the library path environment variable according to '-dlopen'
39266e7d3316Smrgflags.
3927a966c04fSmrg
39286e7d3316SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
39296e7d3316Smrginto their corresponding uninstalled binary, and any of their required library
39306e7d3316Smrgdirectories are added to the library path.
3931a966c04fSmrg
39326e7d3316SmrgThen, COMMAND is executed, with ARGS as arguments."
39336e7d3316Smrg        ;;
3934a966c04fSmrg
39356e7d3316Smrg      finish)
39366e7d3316Smrg        $ECHO \
39376e7d3316Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938a966c04fSmrg
39396e7d3316SmrgComplete the installation of libtool libraries.
3940a966c04fSmrg
39416e7d3316SmrgEach LIBDIR is a directory that contains libtool libraries.
3942a966c04fSmrg
39436e7d3316SmrgThe commands that this mode executes may require superuser privileges.  Use
3944edce3322Smrgthe '--dry-run' option if you just want to see what would be executed."
39456e7d3316Smrg        ;;
3946a966c04fSmrg
39476e7d3316Smrg      install)
39486e7d3316Smrg        $ECHO \
39496e7d3316Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3950a966c04fSmrg
39516e7d3316SmrgInstall executables or libraries.
3952a966c04fSmrg
39536e7d3316SmrgINSTALL-COMMAND is the installation command.  The first component should be
3954edce3322Smrgeither the 'install' or 'cp' program.
3955a966c04fSmrg
39566e7d3316SmrgThe following components of INSTALL-COMMAND are treated specially:
3957a966c04fSmrg
39586e7d3316Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3959a966c04fSmrg
39606e7d3316SmrgThe rest of the components are interpreted as arguments to that command (only
39616e7d3316SmrgBSD-compatible install options are recognized)."
39626e7d3316Smrg        ;;
3963a966c04fSmrg
39646e7d3316Smrg      link)
39656e7d3316Smrg        $ECHO \
39666e7d3316Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3967a966c04fSmrg
39686e7d3316SmrgLink object files or libraries together to form another library, or to
39696e7d3316Smrgcreate an executable program.
3970a966c04fSmrg
39716e7d3316SmrgLINK-COMMAND is a command using the C compiler that you would use to create
39726e7d3316Smrga program from several object files.
3973a966c04fSmrg
39746e7d3316SmrgThe following components of LINK-COMMAND are treated specially:
3975a966c04fSmrg
39766e7d3316Smrg  -all-static       do not do any dynamic linking at all
39776e7d3316Smrg  -avoid-version    do not add a version suffix if possible
39786e7d3316Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
39796e7d3316Smrg                    libraries must be found in the PATH setting at runtime)
3980edce3322Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
39816e7d3316Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
39826e7d3316Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
39836e7d3316Smrg  -export-symbols SYMFILE
39846e7d3316Smrg                    try to export only the symbols listed in SYMFILE
39856e7d3316Smrg  -export-symbols-regex REGEX
39866e7d3316Smrg                    try to export only the symbols matching REGEX
39876e7d3316Smrg  -LLIBDIR          search LIBDIR for required installed libraries
39886e7d3316Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
39896e7d3316Smrg  -module           build a library that can dlopened
39906e7d3316Smrg  -no-fast-install  disable the fast-install mode
39916e7d3316Smrg  -no-install       link a not-installable executable
39926e7d3316Smrg  -no-undefined     declare that a library does not refer to external symbols
39936e7d3316Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994edce3322Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995edce3322Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
39966e7d3316Smrg  -precious-files-regex REGEX
39976e7d3316Smrg                    don't remove output files matching REGEX
39986e7d3316Smrg  -release RELEASE  specify package release information
39996e7d3316Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
40006e7d3316Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
40016e7d3316Smrg  -shared           only do dynamic linking of libtool libraries
40026e7d3316Smrg  -shrext SUFFIX    override the standard shared library file extension
40036e7d3316Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
40046e7d3316Smrg  -static-libtool-libs
40056e7d3316Smrg                    do not do any dynamic linking of libtool libraries
40066e7d3316Smrg  -version-info CURRENT[:REVISION[:AGE]]
40076e7d3316Smrg                    specify library version info [each variable defaults to 0]
40086e7d3316Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
40096e7d3316Smrg  -Wc,FLAG
40106e7d3316Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
401174835918Smrg  -Wa,FLAG
401274835918Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
40136e7d3316Smrg  -Wl,FLAG
40146e7d3316Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
40156e7d3316Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4016a966c04fSmrg
4017edce3322SmrgAll other options (arguments beginning with '-') are ignored.
4018a966c04fSmrg
4019edce3322SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
40206e7d3316Smrgtreated as uninstalled libtool libraries, other files are standard or library
40216e7d3316Smrgobject files.
4022a966c04fSmrg
4023edce3322SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024edce3322Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
40256e7d3316Smrgrequired, except when creating a convenience library.
4026a966c04fSmrg
4027edce3322SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028edce3322Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
40292e2dd055Smrg
4030edce3322SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
40316e7d3316Smrgis created, otherwise an executable program is created."
40326e7d3316Smrg        ;;
4033a966c04fSmrg
40346e7d3316Smrg      uninstall)
40356e7d3316Smrg        $ECHO \
40366e7d3316Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4037a966c04fSmrg
40386e7d3316SmrgRemove libraries from an installation directory.
4039a966c04fSmrg
40406e7d3316SmrgRM is the name of the program to use to delete files associated with each FILE
4041edce3322Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
40426e7d3316Smrgto RM.
4043a966c04fSmrg
40446e7d3316SmrgIf FILE is a libtool library, all the files associated with it are deleted.
40456e7d3316SmrgOtherwise, only FILE itself is deleted using RM."
40466e7d3316Smrg        ;;
4047a966c04fSmrg
40486e7d3316Smrg      *)
4049edce3322Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
40506e7d3316Smrg        ;;
40516e7d3316Smrg    esac
4052a966c04fSmrg
40536e7d3316Smrg    echo
4054edce3322Smrg    $ECHO "Try '$progname --help' for more information about other modes."
40556e7d3316Smrg}
4056a966c04fSmrg
40576e7d3316Smrg# Now that we've collected a possible --mode arg, show help if necessary
40586e7d3316Smrgif $opt_help; then
4059edce3322Smrg  if test : = "$opt_help"; then
40606e7d3316Smrg    func_mode_help
40616e7d3316Smrg  else
40626e7d3316Smrg    {
40636e7d3316Smrg      func_help noexit
406497cf2ee2Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40656e7d3316Smrg	func_mode_help
40666e7d3316Smrg      done
4067edce3322Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
40686e7d3316Smrg    {
40696e7d3316Smrg      func_help noexit
407097cf2ee2Smrg      for opt_mode in compile link execute install finish uninstall clean; do
40716e7d3316Smrg	echo
40726e7d3316Smrg	func_mode_help
40736e7d3316Smrg      done
40746e7d3316Smrg    } |
4075edce3322Smrg    $SED '1d
40766e7d3316Smrg      /^When reporting/,/^Report/{
40776e7d3316Smrg	H
40786e7d3316Smrg	d
40796e7d3316Smrg      }
40806e7d3316Smrg      $x
40816e7d3316Smrg      /information about other modes/d
40826e7d3316Smrg      /more detailed .*MODE/d
40836e7d3316Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
40846e7d3316Smrg  fi
40856e7d3316Smrg  exit $?
40866e7d3316Smrgfi
4087a966c04fSmrg
4088a966c04fSmrg
40896e7d3316Smrg# func_mode_execute arg...
40906e7d3316Smrgfunc_mode_execute ()
40916e7d3316Smrg{
4092edce3322Smrg    $debug_cmd
4093edce3322Smrg
40946e7d3316Smrg    # The first argument is the command name.
4095edce3322Smrg    cmd=$nonopt
40966e7d3316Smrg    test -z "$cmd" && \
40976e7d3316Smrg      func_fatal_help "you must specify a COMMAND"
4098a966c04fSmrg
40996e7d3316Smrg    # Handle -dlopen flags immediately.
410097cf2ee2Smrg    for file in $opt_dlopen; do
41016e7d3316Smrg      test -f "$file" \
4102edce3322Smrg	|| func_fatal_help "'$file' is not a file"
4103a966c04fSmrg
41046e7d3316Smrg      dir=
41056e7d3316Smrg      case $file in
41066e7d3316Smrg      *.la)
410797cf2ee2Smrg	func_resolve_sysroot "$file"
410897cf2ee2Smrg	file=$func_resolve_sysroot_result
410997cf2ee2Smrg
41106e7d3316Smrg	# Check to see that this really is a libtool archive.
41116e7d3316Smrg	func_lalib_unsafe_p "$file" \
4112edce3322Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113a966c04fSmrg
41146e7d3316Smrg	# Read the libtool library.
41156e7d3316Smrg	dlname=
41166e7d3316Smrg	library_names=
41176e7d3316Smrg	func_source "$file"
4118a966c04fSmrg
41196e7d3316Smrg	# Skip this library if it cannot be dlopened.
41206e7d3316Smrg	if test -z "$dlname"; then
41216e7d3316Smrg	  # Warn if it was a shared library.
41226e7d3316Smrg	  test -n "$library_names" && \
4123edce3322Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
41246e7d3316Smrg	  continue
41256e7d3316Smrg	fi
4126a966c04fSmrg
41276e7d3316Smrg	func_dirname "$file" "" "."
4128edce3322Smrg	dir=$func_dirname_result
4129a966c04fSmrg
41306e7d3316Smrg	if test -f "$dir/$objdir/$dlname"; then
413197cf2ee2Smrg	  func_append dir "/$objdir"
41326e7d3316Smrg	else
41336e7d3316Smrg	  if test ! -f "$dir/$dlname"; then
4134edce3322Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
41356e7d3316Smrg	  fi
41366e7d3316Smrg	fi
4137a966c04fSmrg	;;
4138a966c04fSmrg
41396e7d3316Smrg      *.lo)
41406e7d3316Smrg	# Just add the directory containing the .lo file.
41416e7d3316Smrg	func_dirname "$file" "" "."
4142edce3322Smrg	dir=$func_dirname_result
4143a966c04fSmrg	;;
41446e7d3316Smrg
41456e7d3316Smrg      *)
4146edce3322Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147a966c04fSmrg	continue
4148a966c04fSmrg	;;
41496e7d3316Smrg      esac
4150a966c04fSmrg
41516e7d3316Smrg      # Get the absolute pathname.
41526e7d3316Smrg      absdir=`cd "$dir" && pwd`
4153edce3322Smrg      test -n "$absdir" && dir=$absdir
4154a966c04fSmrg
41556e7d3316Smrg      # Now add the directory to shlibpath_var.
41566e7d3316Smrg      if eval "test -z \"\$$shlibpath_var\""; then
41576e7d3316Smrg	eval "$shlibpath_var=\"\$dir\""
41586e7d3316Smrg      else
41596e7d3316Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
41606e7d3316Smrg      fi
41616e7d3316Smrg    done
4162a966c04fSmrg
41636e7d3316Smrg    # This variable tells wrapper scripts just to set shlibpath_var
41646e7d3316Smrg    # rather than running their programs.
4165edce3322Smrg    libtool_execute_magic=$magic
4166a966c04fSmrg
41676e7d3316Smrg    # Check if any of the arguments is a wrapper script.
41686e7d3316Smrg    args=
41696e7d3316Smrg    for file
41706e7d3316Smrg    do
41716e7d3316Smrg      case $file in
41726e7d3316Smrg      -* | *.la | *.lo ) ;;
41736e7d3316Smrg      *)
41746e7d3316Smrg	# Do a test to see if this is really a libtool program.
41756e7d3316Smrg	if func_ltwrapper_script_p "$file"; then
41766e7d3316Smrg	  func_source "$file"
41776e7d3316Smrg	  # Transform arg to wrapped name.
4178edce3322Smrg	  file=$progdir/$program
41796e7d3316Smrg	elif func_ltwrapper_executable_p "$file"; then
41806e7d3316Smrg	  func_ltwrapper_scriptname "$file"
41816e7d3316Smrg	  func_source "$func_ltwrapper_scriptname_result"
41826e7d3316Smrg	  # Transform arg to wrapped name.
4183edce3322Smrg	  file=$progdir/$program
41846e7d3316Smrg	fi
4185a966c04fSmrg	;;
41866e7d3316Smrg      esac
41876e7d3316Smrg      # Quote arguments (to preserve shell metacharacters).
418897cf2ee2Smrg      func_append_quoted args "$file"
41896e7d3316Smrg    done
4190a966c04fSmrg
4191edce3322Smrg    if $opt_dry_run; then
4192edce3322Smrg      # Display what would be done.
4193edce3322Smrg      if test -n "$shlibpath_var"; then
4194edce3322Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195edce3322Smrg	echo "export $shlibpath_var"
4196edce3322Smrg      fi
4197edce3322Smrg      $ECHO "$cmd$args"
4198edce3322Smrg      exit $EXIT_SUCCESS
4199edce3322Smrg    else
42006e7d3316Smrg      if test -n "$shlibpath_var"; then
42016e7d3316Smrg	# Export the shlibpath_var.
42026e7d3316Smrg	eval "export $shlibpath_var"
42036e7d3316Smrg      fi
4204a966c04fSmrg
42056e7d3316Smrg      # Restore saved environment variables
42066e7d3316Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
42076e7d3316Smrg      do
42086e7d3316Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
42096e7d3316Smrg                $lt_var=\$save_$lt_var; export $lt_var
42106e7d3316Smrg	      else
42116e7d3316Smrg		$lt_unset $lt_var
42126e7d3316Smrg	      fi"
42136e7d3316Smrg      done
4214a966c04fSmrg
42156e7d3316Smrg      # Now prepare to actually exec the command.
4216edce3322Smrg      exec_cmd=\$cmd$args
42176e7d3316Smrg    fi
42186e7d3316Smrg}
4219a966c04fSmrg
4220edce3322Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4221a966c04fSmrg
4222a966c04fSmrg
42236e7d3316Smrg# func_mode_finish arg...
42246e7d3316Smrgfunc_mode_finish ()
42256e7d3316Smrg{
4226edce3322Smrg    $debug_cmd
4227edce3322Smrg
422897cf2ee2Smrg    libs=
422997cf2ee2Smrg    libdirs=
42306e7d3316Smrg    admincmds=
4231a966c04fSmrg
423297cf2ee2Smrg    for opt in "$nonopt" ${1+"$@"}
423397cf2ee2Smrg    do
423497cf2ee2Smrg      if test -d "$opt"; then
423597cf2ee2Smrg	func_append libdirs " $opt"
423697cf2ee2Smrg
423797cf2ee2Smrg      elif test -f "$opt"; then
423897cf2ee2Smrg	if func_lalib_unsafe_p "$opt"; then
423997cf2ee2Smrg	  func_append libs " $opt"
424097cf2ee2Smrg	else
4241edce3322Smrg	  func_warning "'$opt' is not a valid libtool archive"
424297cf2ee2Smrg	fi
424397cf2ee2Smrg
424497cf2ee2Smrg      else
4245edce3322Smrg	func_fatal_error "invalid argument '$opt'"
424697cf2ee2Smrg      fi
424797cf2ee2Smrg    done
424897cf2ee2Smrg
424997cf2ee2Smrg    if test -n "$libs"; then
425097cf2ee2Smrg      if test -n "$lt_sysroot"; then
425197cf2ee2Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
425297cf2ee2Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
425397cf2ee2Smrg      else
425497cf2ee2Smrg        sysroot_cmd=
425597cf2ee2Smrg      fi
425697cf2ee2Smrg
425797cf2ee2Smrg      # Remove sysroot references
425897cf2ee2Smrg      if $opt_dry_run; then
425997cf2ee2Smrg        for lib in $libs; do
4260edce3322Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
426197cf2ee2Smrg        done
426297cf2ee2Smrg      else
426397cf2ee2Smrg        tmpdir=`func_mktempdir`
426497cf2ee2Smrg        for lib in $libs; do
4265edce3322Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
426697cf2ee2Smrg	    > $tmpdir/tmp-la
426797cf2ee2Smrg	  mv -f $tmpdir/tmp-la $lib
426897cf2ee2Smrg	done
426997cf2ee2Smrg        ${RM}r "$tmpdir"
427097cf2ee2Smrg      fi
427197cf2ee2Smrg    fi
4272a966c04fSmrg
427397cf2ee2Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42746e7d3316Smrg      for libdir in $libdirs; do
42756e7d3316Smrg	if test -n "$finish_cmds"; then
42766e7d3316Smrg	  # Do each command in the finish commands.
42776e7d3316Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
42786e7d3316Smrg'"$cmd"'"'
42796e7d3316Smrg	fi
42806e7d3316Smrg	if test -n "$finish_eval"; then
42816e7d3316Smrg	  # Do the single finish_eval.
42826e7d3316Smrg	  eval cmds=\"$finish_eval\"
428397cf2ee2Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
42846e7d3316Smrg       $cmds"
42856e7d3316Smrg	fi
42866e7d3316Smrg      done
42876e7d3316Smrg    fi
4288a966c04fSmrg
42896e7d3316Smrg    # Exit here if they wanted silent mode.
4290edce3322Smrg    $opt_quiet && exit $EXIT_SUCCESS
4291a966c04fSmrg
429297cf2ee2Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
429397cf2ee2Smrg      echo "----------------------------------------------------------------------"
429497cf2ee2Smrg      echo "Libraries have been installed in:"
429597cf2ee2Smrg      for libdir in $libdirs; do
429697cf2ee2Smrg	$ECHO "   $libdir"
429797cf2ee2Smrg      done
429897cf2ee2Smrg      echo
429997cf2ee2Smrg      echo "If you ever happen to want to link against installed libraries"
430097cf2ee2Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301edce3322Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
430297cf2ee2Smrg      echo "flag during linking and do at least one of the following:"
430397cf2ee2Smrg      if test -n "$shlibpath_var"; then
4304edce3322Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
430597cf2ee2Smrg	echo "     during execution"
430697cf2ee2Smrg      fi
430797cf2ee2Smrg      if test -n "$runpath_var"; then
4308edce3322Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
430997cf2ee2Smrg	echo "     during linking"
431097cf2ee2Smrg      fi
431197cf2ee2Smrg      if test -n "$hardcode_libdir_flag_spec"; then
431297cf2ee2Smrg	libdir=LIBDIR
431397cf2ee2Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4314a966c04fSmrg
4315edce3322Smrg	$ECHO "   - use the '$flag' linker flag"
431697cf2ee2Smrg      fi
431797cf2ee2Smrg      if test -n "$admincmds"; then
431897cf2ee2Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
431997cf2ee2Smrg      fi
432097cf2ee2Smrg      if test -f /etc/ld.so.conf; then
4321edce3322Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
432297cf2ee2Smrg      fi
432397cf2ee2Smrg      echo
4324a966c04fSmrg
432597cf2ee2Smrg      echo "See any operating system documentation about shared libraries for"
432697cf2ee2Smrg      case $host in
432797cf2ee2Smrg	solaris2.[6789]|solaris2.1[0-9])
432897cf2ee2Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
432997cf2ee2Smrg	  echo "pages."
433097cf2ee2Smrg	  ;;
433197cf2ee2Smrg	*)
433297cf2ee2Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
433397cf2ee2Smrg	  ;;
433497cf2ee2Smrg      esac
433597cf2ee2Smrg      echo "----------------------------------------------------------------------"
433697cf2ee2Smrg    fi
43376e7d3316Smrg    exit $EXIT_SUCCESS
43386e7d3316Smrg}
4339a966c04fSmrg
4340edce3322Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4341a966c04fSmrg
4342a966c04fSmrg
43436e7d3316Smrg# func_mode_install arg...
43446e7d3316Smrgfunc_mode_install ()
43456e7d3316Smrg{
4346edce3322Smrg    $debug_cmd
4347edce3322Smrg
43486e7d3316Smrg    # There may be an optional sh(1) argument at the beginning of
43496e7d3316Smrg    # install_prog (especially on Windows NT).
4350edce3322Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
43516e7d3316Smrg       # Allow the use of GNU shtool's install command.
4352edce3322Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4353edce3322Smrg    then
43546e7d3316Smrg      # Aesthetically quote it.
435574835918Smrg      func_quote_arg pretty "$nonopt"
435674835918Smrg      install_prog="$func_quote_arg_result "
43576e7d3316Smrg      arg=$1
43586e7d3316Smrg      shift
43596e7d3316Smrg    else
43606e7d3316Smrg      install_prog=
43616e7d3316Smrg      arg=$nonopt
43626e7d3316Smrg    fi
4363a966c04fSmrg
43646e7d3316Smrg    # The real first argument should be the name of the installation program.
43656e7d3316Smrg    # Aesthetically quote it.
436674835918Smrg    func_quote_arg pretty "$arg"
436774835918Smrg    func_append install_prog "$func_quote_arg_result"
43686e7d3316Smrg    install_shared_prog=$install_prog
43696e7d3316Smrg    case " $install_prog " in
43706e7d3316Smrg      *[\\\ /]cp\ *) install_cp=: ;;
43716e7d3316Smrg      *) install_cp=false ;;
43726e7d3316Smrg    esac
4373a966c04fSmrg
43746e7d3316Smrg    # We need to accept at least all the BSD install flags.
43756e7d3316Smrg    dest=
43766e7d3316Smrg    files=
43776e7d3316Smrg    opts=
43786e7d3316Smrg    prev=
43796e7d3316Smrg    install_type=
4380edce3322Smrg    isdir=false
43816e7d3316Smrg    stripme=
43826e7d3316Smrg    no_mode=:
43836e7d3316Smrg    for arg
43846e7d3316Smrg    do
43856e7d3316Smrg      arg2=
43866e7d3316Smrg      if test -n "$dest"; then
438797cf2ee2Smrg	func_append files " $dest"
43886e7d3316Smrg	dest=$arg
4389a966c04fSmrg	continue
43906e7d3316Smrg      fi
4391a966c04fSmrg
43926e7d3316Smrg      case $arg in
4393edce3322Smrg      -d) isdir=: ;;
43946e7d3316Smrg      -f)
43956e7d3316Smrg	if $install_cp; then :; else
43966e7d3316Smrg	  prev=$arg
4397a966c04fSmrg	fi
43986e7d3316Smrg	;;
43996e7d3316Smrg      -g | -m | -o)
44006e7d3316Smrg	prev=$arg
44016e7d3316Smrg	;;
44026e7d3316Smrg      -s)
44036e7d3316Smrg	stripme=" -s"
4404a966c04fSmrg	continue
4405a966c04fSmrg	;;
44066e7d3316Smrg      -*)
44076e7d3316Smrg	;;
4408a966c04fSmrg      *)
44096e7d3316Smrg	# If the previous option needed an argument, then skip it.
44106e7d3316Smrg	if test -n "$prev"; then
4411edce3322Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
44126e7d3316Smrg	    arg2=$install_override_mode
44136e7d3316Smrg	    no_mode=false
44146e7d3316Smrg	  fi
44156e7d3316Smrg	  prev=
44166e7d3316Smrg	else
44176e7d3316Smrg	  dest=$arg
44186e7d3316Smrg	  continue
44196e7d3316Smrg	fi
4420a966c04fSmrg	;;
44216e7d3316Smrg      esac
4422a966c04fSmrg
44236e7d3316Smrg      # Aesthetically quote the argument.
442474835918Smrg      func_quote_arg pretty "$arg"
442574835918Smrg      func_append install_prog " $func_quote_arg_result"
44266e7d3316Smrg      if test -n "$arg2"; then
442774835918Smrg	func_quote_arg pretty "$arg2"
4428a966c04fSmrg      fi
442974835918Smrg      func_append install_shared_prog " $func_quote_arg_result"
44306e7d3316Smrg    done
4431a966c04fSmrg
44326e7d3316Smrg    test -z "$install_prog" && \
44336e7d3316Smrg      func_fatal_help "you must specify an install program"
4434a966c04fSmrg
44356e7d3316Smrg    test -n "$prev" && \
4436edce3322Smrg      func_fatal_help "the '$prev' option requires an argument"
4437a966c04fSmrg
44386e7d3316Smrg    if test -n "$install_override_mode" && $no_mode; then
44396e7d3316Smrg      if $install_cp; then :; else
444074835918Smrg	func_quote_arg pretty "$install_override_mode"
444174835918Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
44426e7d3316Smrg      fi
4443a966c04fSmrg    fi
4444a966c04fSmrg
44456e7d3316Smrg    if test -z "$files"; then
44466e7d3316Smrg      if test -z "$dest"; then
44476e7d3316Smrg	func_fatal_help "no file or destination specified"
44486e7d3316Smrg      else
44496e7d3316Smrg	func_fatal_help "you must specify a destination"
4450a966c04fSmrg      fi
4451a966c04fSmrg    fi
4452a966c04fSmrg
44536e7d3316Smrg    # Strip any trailing slash from the destination.
44546e7d3316Smrg    func_stripname '' '/' "$dest"
44556e7d3316Smrg    dest=$func_stripname_result
4456a966c04fSmrg
44576e7d3316Smrg    # Check to see that the destination is a directory.
4458edce3322Smrg    test -d "$dest" && isdir=:
4459edce3322Smrg    if $isdir; then
4460edce3322Smrg      destdir=$dest
44616e7d3316Smrg      destname=
44626e7d3316Smrg    else
44636e7d3316Smrg      func_dirname_and_basename "$dest" "" "."
4464edce3322Smrg      destdir=$func_dirname_result
4465edce3322Smrg      destname=$func_basename_result
44666e7d3316Smrg
44676e7d3316Smrg      # Not a directory, so check to see that there is only one file specified.
44686e7d3316Smrg      set dummy $files; shift
44696e7d3316Smrg      test "$#" -gt 1 && \
4470edce3322Smrg	func_fatal_help "'$dest' is not a directory"
44716e7d3316Smrg    fi
44726e7d3316Smrg    case $destdir in
44736e7d3316Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474a966c04fSmrg    *)
44756e7d3316Smrg      for file in $files; do
44766e7d3316Smrg	case $file in
44776e7d3316Smrg	*.lo) ;;
44786e7d3316Smrg	*)
4479edce3322Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
44806e7d3316Smrg	  ;;
44816e7d3316Smrg	esac
44826e7d3316Smrg      done
4483a966c04fSmrg      ;;
4484a966c04fSmrg    esac
4485a966c04fSmrg
44866e7d3316Smrg    # This variable tells wrapper scripts just to set variables rather
44876e7d3316Smrg    # than running their programs.
4488edce3322Smrg    libtool_install_magic=$magic
4489a966c04fSmrg
44906e7d3316Smrg    staticlibs=
44916e7d3316Smrg    future_libdirs=
44926e7d3316Smrg    current_libdirs=
44936e7d3316Smrg    for file in $files; do
4494a966c04fSmrg
44956e7d3316Smrg      # Do each installation.
44966e7d3316Smrg      case $file in
44976e7d3316Smrg      *.$libext)
44986e7d3316Smrg	# Do the static libraries later.
449997cf2ee2Smrg	func_append staticlibs " $file"
45006e7d3316Smrg	;;
45016e7d3316Smrg
45026e7d3316Smrg      *.la)
450397cf2ee2Smrg	func_resolve_sysroot "$file"
450497cf2ee2Smrg	file=$func_resolve_sysroot_result
450597cf2ee2Smrg
45066e7d3316Smrg	# Check to see that this really is a libtool archive.
45076e7d3316Smrg	func_lalib_unsafe_p "$file" \
4508edce3322Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
45096e7d3316Smrg
45106e7d3316Smrg	library_names=
45116e7d3316Smrg	old_library=
45126e7d3316Smrg	relink_command=
45136e7d3316Smrg	func_source "$file"
45146e7d3316Smrg
45156e7d3316Smrg	# Add the libdir to current_libdirs if it is the destination.
45166e7d3316Smrg	if test "X$destdir" = "X$libdir"; then
45176e7d3316Smrg	  case "$current_libdirs " in
45186e7d3316Smrg	  *" $libdir "*) ;;
451997cf2ee2Smrg	  *) func_append current_libdirs " $libdir" ;;
4520a966c04fSmrg	  esac
45216e7d3316Smrg	else
45226e7d3316Smrg	  # Note the libdir as a future libdir.
45236e7d3316Smrg	  case "$future_libdirs " in
45246e7d3316Smrg	  *" $libdir "*) ;;
452597cf2ee2Smrg	  *) func_append future_libdirs " $libdir" ;;
45266e7d3316Smrg	  esac
45276e7d3316Smrg	fi
4528a966c04fSmrg
45296e7d3316Smrg	func_dirname "$file" "/" ""
4530edce3322Smrg	dir=$func_dirname_result
453197cf2ee2Smrg	func_append dir "$objdir"
45326e7d3316Smrg
45336e7d3316Smrg	if test -n "$relink_command"; then
45346e7d3316Smrg	  # Determine the prefix the user has applied to our future dir.
45356e7d3316Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
45366e7d3316Smrg
45376e7d3316Smrg	  # Don't allow the user to place us outside of our expected
45386e7d3316Smrg	  # location b/c this prevents finding dependent libraries that
45396e7d3316Smrg	  # are installed to the same prefix.
45406e7d3316Smrg	  # At present, this check doesn't affect windows .dll's that
45416e7d3316Smrg	  # are installed into $libdir/../bin (currently, that works fine)
45426e7d3316Smrg	  # but it's something to keep an eye on.
45436e7d3316Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4544edce3322Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
45456e7d3316Smrg
45466e7d3316Smrg	  if test -n "$inst_prefix_dir"; then
45476e7d3316Smrg	    # Stick the inst_prefix_dir data into the link command.
45486e7d3316Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
45496e7d3316Smrg	  else
45506e7d3316Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
45516e7d3316Smrg	  fi
45526e7d3316Smrg
4553edce3322Smrg	  func_warning "relinking '$file'"
45546e7d3316Smrg	  func_show_eval "$relink_command" \
4555edce3322Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
45566e7d3316Smrg	fi
45576e7d3316Smrg
45586e7d3316Smrg	# See the names of the shared library.
45596e7d3316Smrg	set dummy $library_names; shift
45606e7d3316Smrg	if test -n "$1"; then
4561edce3322Smrg	  realname=$1
45626e7d3316Smrg	  shift
45636e7d3316Smrg
4564edce3322Smrg	  srcname=$realname
4565edce3322Smrg	  test -n "$relink_command" && srcname=${realname}T
45666e7d3316Smrg
45676e7d3316Smrg	  # Install the shared library and build the symlinks.
45686e7d3316Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
45696e7d3316Smrg	      'exit $?'
4570edce3322Smrg	  tstripme=$stripme
45716e7d3316Smrg	  case $host_os in
45726e7d3316Smrg	  cygwin* | mingw* | pw32* | cegcc*)
45736e7d3316Smrg	    case $realname in
45746e7d3316Smrg	    *.dll.a)
4575edce3322Smrg	      tstripme=
4576edce3322Smrg	      ;;
4577edce3322Smrg	    esac
4578edce3322Smrg	    ;;
4579edce3322Smrg	  os2*)
4580edce3322Smrg	    case $realname in
4581edce3322Smrg	    *_dll.a)
4582edce3322Smrg	      tstripme=
45836e7d3316Smrg	      ;;
45846e7d3316Smrg	    esac
4585a966c04fSmrg	    ;;
4586a966c04fSmrg	  esac
45876e7d3316Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
45886e7d3316Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
45896e7d3316Smrg	  fi
45906e7d3316Smrg
45916e7d3316Smrg	  if test "$#" -gt 0; then
45926e7d3316Smrg	    # Delete the old symlinks, and create new ones.
4593edce3322Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
45946e7d3316Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
45956e7d3316Smrg	    # so we also need to try rm && ln -s.
45966e7d3316Smrg	    for linkname
45976e7d3316Smrg	    do
45986e7d3316Smrg	      test "$linkname" != "$realname" \
45996e7d3316Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
46006e7d3316Smrg	    done
46016e7d3316Smrg	  fi
46026e7d3316Smrg
46036e7d3316Smrg	  # Do each command in the postinstall commands.
4604edce3322Smrg	  lib=$destdir/$realname
46056e7d3316Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
46066e7d3316Smrg	fi
46076e7d3316Smrg
46086e7d3316Smrg	# Install the pseudo-library for information purposes.
46096e7d3316Smrg	func_basename "$file"
4610edce3322Smrg	name=$func_basename_result
4611edce3322Smrg	instname=$dir/${name}i
46126e7d3316Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
46136e7d3316Smrg
46146e7d3316Smrg	# Maybe install the static library, too.
461597cf2ee2Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4616a966c04fSmrg	;;
46176e7d3316Smrg
46186e7d3316Smrg      *.lo)
46196e7d3316Smrg	# Install (i.e. copy) a libtool object.
46206e7d3316Smrg
46216e7d3316Smrg	# Figure out destination file name, if it wasn't already specified.
46226e7d3316Smrg	if test -n "$destname"; then
4623edce3322Smrg	  destfile=$destdir/$destname
46246e7d3316Smrg	else
46256e7d3316Smrg	  func_basename "$file"
4626edce3322Smrg	  destfile=$func_basename_result
4627edce3322Smrg	  destfile=$destdir/$destfile
46286e7d3316Smrg	fi
46296e7d3316Smrg
46306e7d3316Smrg	# Deduce the name of the destination old-style object file.
46316e7d3316Smrg	case $destfile in
46326e7d3316Smrg	*.lo)
46336e7d3316Smrg	  func_lo2o "$destfile"
46346e7d3316Smrg	  staticdest=$func_lo2o_result
4635a966c04fSmrg	  ;;
46366e7d3316Smrg	*.$objext)
4637edce3322Smrg	  staticdest=$destfile
46386e7d3316Smrg	  destfile=
4639a966c04fSmrg	  ;;
46406e7d3316Smrg	*)
4641edce3322Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4642a966c04fSmrg	  ;;
46436e7d3316Smrg	esac
46446e7d3316Smrg
46456e7d3316Smrg	# Install the libtool object if requested.
46466e7d3316Smrg	test -n "$destfile" && \
46476e7d3316Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
46486e7d3316Smrg
46496e7d3316Smrg	# Install the old object if enabled.
4650edce3322Smrg	if test yes = "$build_old_libs"; then
46516e7d3316Smrg	  # Deduce the name of the old-style object file.
46526e7d3316Smrg	  func_lo2o "$file"
46536e7d3316Smrg	  staticobj=$func_lo2o_result
46546e7d3316Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4655a966c04fSmrg	fi
46566e7d3316Smrg	exit $EXIT_SUCCESS
46576e7d3316Smrg	;;
4658a966c04fSmrg
46596e7d3316Smrg      *)
46606e7d3316Smrg	# Figure out destination file name, if it wasn't already specified.
46616e7d3316Smrg	if test -n "$destname"; then
4662edce3322Smrg	  destfile=$destdir/$destname
4663a966c04fSmrg	else
46646e7d3316Smrg	  func_basename "$file"
4665edce3322Smrg	  destfile=$func_basename_result
4666edce3322Smrg	  destfile=$destdir/$destfile
4667a966c04fSmrg	fi
4668a966c04fSmrg
46696e7d3316Smrg	# If the file is missing, and there is a .exe on the end, strip it
46706e7d3316Smrg	# because it is most likely a libtool script we actually want to
46716e7d3316Smrg	# install
4672edce3322Smrg	stripped_ext=
46736e7d3316Smrg	case $file in
46746e7d3316Smrg	  *.exe)
46756e7d3316Smrg	    if test ! -f "$file"; then
46766e7d3316Smrg	      func_stripname '' '.exe' "$file"
46776e7d3316Smrg	      file=$func_stripname_result
4678edce3322Smrg	      stripped_ext=.exe
46796e7d3316Smrg	    fi
46806e7d3316Smrg	    ;;
46816e7d3316Smrg	esac
4682a966c04fSmrg
46836e7d3316Smrg	# Do a test to see if this is really a libtool program.
46846e7d3316Smrg	case $host in
46856e7d3316Smrg	*cygwin* | *mingw*)
46866e7d3316Smrg	    if func_ltwrapper_executable_p "$file"; then
46876e7d3316Smrg	      func_ltwrapper_scriptname "$file"
46886e7d3316Smrg	      wrapper=$func_ltwrapper_scriptname_result
46896e7d3316Smrg	    else
46906e7d3316Smrg	      func_stripname '' '.exe' "$file"
46916e7d3316Smrg	      wrapper=$func_stripname_result
46926e7d3316Smrg	    fi
46936e7d3316Smrg	    ;;
46946e7d3316Smrg	*)
46956e7d3316Smrg	    wrapper=$file
46966e7d3316Smrg	    ;;
46976e7d3316Smrg	esac
46986e7d3316Smrg	if func_ltwrapper_script_p "$wrapper"; then
46996e7d3316Smrg	  notinst_deplibs=
47006e7d3316Smrg	  relink_command=
4701a966c04fSmrg
47026e7d3316Smrg	  func_source "$wrapper"
4703a966c04fSmrg
47046e7d3316Smrg	  # Check the variables that should have been set.
47056e7d3316Smrg	  test -z "$generated_by_libtool_version" && \
4706edce3322Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4707a966c04fSmrg
4708edce3322Smrg	  finalize=:
47096e7d3316Smrg	  for lib in $notinst_deplibs; do
47106e7d3316Smrg	    # Check to see that each library is installed.
47116e7d3316Smrg	    libdir=
47126e7d3316Smrg	    if test -f "$lib"; then
47136e7d3316Smrg	      func_source "$lib"
4714a966c04fSmrg	    fi
4715edce3322Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
47166e7d3316Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717edce3322Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718edce3322Smrg	      finalize=false
47196e7d3316Smrg	    fi
47206e7d3316Smrg	  done
4721a966c04fSmrg
47226e7d3316Smrg	  relink_command=
47236e7d3316Smrg	  func_source "$wrapper"
4724a966c04fSmrg
47256e7d3316Smrg	  outputname=
4726edce3322Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
47276e7d3316Smrg	    $opt_dry_run || {
4728edce3322Smrg	      if $finalize; then
47296e7d3316Smrg	        tmpdir=`func_mktempdir`
47306e7d3316Smrg		func_basename "$file$stripped_ext"
4731edce3322Smrg		file=$func_basename_result
4732edce3322Smrg	        outputname=$tmpdir/$file
47336e7d3316Smrg	        # Replace the output file specification.
47346e7d3316Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
47356e7d3316Smrg
4736edce3322Smrg	        $opt_quiet || {
473774835918Smrg	          func_quote_arg expand,pretty "$relink_command"
473874835918Smrg		  eval "func_echo $func_quote_arg_result"
47396e7d3316Smrg	        }
47406e7d3316Smrg	        if eval "$relink_command"; then :
47416e7d3316Smrg	          else
4742edce3322Smrg		  func_error "error: relink '$file' with the above command before installing it"
47436e7d3316Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
47446e7d3316Smrg		  continue
47456e7d3316Smrg	        fi
4746edce3322Smrg	        file=$outputname
47476e7d3316Smrg	      else
4748edce3322Smrg	        func_warning "cannot relink '$file'"
47496e7d3316Smrg	      fi
47506e7d3316Smrg	    }
4751a966c04fSmrg	  else
47526e7d3316Smrg	    # Install the binary that we compiled earlier.
47536e7d3316Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754a966c04fSmrg	  fi
47556e7d3316Smrg	fi
4756a966c04fSmrg
47576e7d3316Smrg	# remove .exe since cygwin /usr/bin/install will append another
47586e7d3316Smrg	# one anyway
47596e7d3316Smrg	case $install_prog,$host in
47606e7d3316Smrg	*/usr/bin/install*,*cygwin*)
47616e7d3316Smrg	  case $file:$destfile in
47626e7d3316Smrg	  *.exe:*.exe)
47636e7d3316Smrg	    # this is ok
47646e7d3316Smrg	    ;;
47656e7d3316Smrg	  *.exe:*)
47666e7d3316Smrg	    destfile=$destfile.exe
47676e7d3316Smrg	    ;;
47686e7d3316Smrg	  *:*.exe)
47696e7d3316Smrg	    func_stripname '' '.exe' "$destfile"
47706e7d3316Smrg	    destfile=$func_stripname_result
47716e7d3316Smrg	    ;;
47726e7d3316Smrg	  esac
4773a966c04fSmrg	  ;;
4774a966c04fSmrg	esac
47756e7d3316Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
47766e7d3316Smrg	$opt_dry_run || if test -n "$outputname"; then
47776e7d3316Smrg	  ${RM}r "$tmpdir"
47786e7d3316Smrg	fi
47796e7d3316Smrg	;;
47806e7d3316Smrg      esac
47816e7d3316Smrg    done
4782a966c04fSmrg
47836e7d3316Smrg    for file in $staticlibs; do
47846e7d3316Smrg      func_basename "$file"
4785edce3322Smrg      name=$func_basename_result
47866e7d3316Smrg
47876e7d3316Smrg      # Set up the ranlib parameters.
4788edce3322Smrg      oldlib=$destdir/$name
4789ac92798bSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790ac92798bSmrg      tool_oldlib=$func_to_tool_file_result
47916e7d3316Smrg
47926e7d3316Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
47936e7d3316Smrg
47946e7d3316Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795ac92798bSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
47966e7d3316Smrg      fi
47976e7d3316Smrg
47986e7d3316Smrg      # Do each command in the postinstall commands.
47996e7d3316Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
48006e7d3316Smrg    done
48016e7d3316Smrg
48026e7d3316Smrg    test -n "$future_libdirs" && \
4803edce3322Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
48046e7d3316Smrg
48056e7d3316Smrg    if test -n "$current_libdirs"; then
48066e7d3316Smrg      # Maybe just do a dry run.
48076e7d3316Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808edce3322Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
48096e7d3316Smrg    else
48106e7d3316Smrg      exit $EXIT_SUCCESS
48116e7d3316Smrg    fi
48126e7d3316Smrg}
48136e7d3316Smrg
4814edce3322Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
48156e7d3316Smrg
48166e7d3316Smrg
48176e7d3316Smrg# func_generate_dlsyms outputname originator pic_p
48186e7d3316Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
48196e7d3316Smrg# a dlpreopen symbol table.
48206e7d3316Smrgfunc_generate_dlsyms ()
48216e7d3316Smrg{
4822edce3322Smrg    $debug_cmd
4823edce3322Smrg
4824edce3322Smrg    my_outputname=$1
4825edce3322Smrg    my_originator=$2
4826edce3322Smrg    my_pic_p=${3-false}
4827edce3322Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
48286e7d3316Smrg    my_dlsyms=
48296e7d3316Smrg
4830edce3322Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
48316e7d3316Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832edce3322Smrg	my_dlsyms=${my_outputname}S.c
48336e7d3316Smrg      else
48346e7d3316Smrg	func_error "not configured to extract global symbols from dlpreopened files"
48356e7d3316Smrg      fi
48366e7d3316Smrg    fi
48376e7d3316Smrg
48386e7d3316Smrg    if test -n "$my_dlsyms"; then
48396e7d3316Smrg      case $my_dlsyms in
48406e7d3316Smrg      "") ;;
48416e7d3316Smrg      *.c)
48426e7d3316Smrg	# Discover the nlist of each of the dlfiles.
4843edce3322Smrg	nlist=$output_objdir/$my_outputname.nm
48446e7d3316Smrg
48456e7d3316Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
48466e7d3316Smrg
48476e7d3316Smrg	# Parse the name list into a source file.
48486e7d3316Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
48496e7d3316Smrg
48506e7d3316Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851edce3322Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852edce3322Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
48536e7d3316Smrg
48546e7d3316Smrg#ifdef __cplusplus
48556e7d3316Smrgextern \"C\" {
48566e7d3316Smrg#endif
48576e7d3316Smrg
4858edce3322Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
48596e7d3316Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
48606e7d3316Smrg#endif
48616e7d3316Smrg
486297cf2ee2Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863edce3322Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864edce3322Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
486597cf2ee2Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
486697cf2ee2Smrg# define LT_DLSYM_CONST
4867edce3322Smrg#elif defined __osf__
486897cf2ee2Smrg/* This system does not cope well with relocations in const data.  */
486997cf2ee2Smrg# define LT_DLSYM_CONST
487097cf2ee2Smrg#else
487197cf2ee2Smrg# define LT_DLSYM_CONST const
487297cf2ee2Smrg#endif
487397cf2ee2Smrg
4874edce3322Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875edce3322Smrg
48766e7d3316Smrg/* External symbol declarations for the compiler. */\
48776e7d3316Smrg"
48786e7d3316Smrg
4879edce3322Smrg	if test yes = "$dlself"; then
4880edce3322Smrg	  func_verbose "generating symbol list for '$output'"
48816e7d3316Smrg
48826e7d3316Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
48836e7d3316Smrg
48846e7d3316Smrg	  # Add our own program objects to the symbol list.
48856e7d3316Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
48866e7d3316Smrg	  for progfile in $progfiles; do
488797cf2ee2Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888edce3322Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
488997cf2ee2Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
48906e7d3316Smrg	  done
48916e7d3316Smrg
48926e7d3316Smrg	  if test -n "$exclude_expsyms"; then
48936e7d3316Smrg	    $opt_dry_run || {
48946e7d3316Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
48956e7d3316Smrg	      eval '$MV "$nlist"T "$nlist"'
48966e7d3316Smrg	    }
4897a966c04fSmrg	  fi
48986e7d3316Smrg
48996e7d3316Smrg	  if test -n "$export_symbols_regex"; then
49006e7d3316Smrg	    $opt_dry_run || {
49016e7d3316Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
49026e7d3316Smrg	      eval '$MV "$nlist"T "$nlist"'
49036e7d3316Smrg	    }
49046e7d3316Smrg	  fi
49056e7d3316Smrg
49066e7d3316Smrg	  # Prepare the list of exported symbols
49076e7d3316Smrg	  if test -z "$export_symbols"; then
4908edce3322Smrg	    export_symbols=$output_objdir/$outputname.exp
49096e7d3316Smrg	    $opt_dry_run || {
49106e7d3316Smrg	      $RM $export_symbols
4911edce3322Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
49126e7d3316Smrg	      case $host in
49136e7d3316Smrg	      *cygwin* | *mingw* | *cegcc* )
49146e7d3316Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49156e7d3316Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
49166e7d3316Smrg	        ;;
49176e7d3316Smrg	      esac
49186e7d3316Smrg	    }
4919a966c04fSmrg	  else
49206e7d3316Smrg	    $opt_dry_run || {
4921edce3322Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
49226e7d3316Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
49236e7d3316Smrg	      eval '$MV "$nlist"T "$nlist"'
49246e7d3316Smrg	      case $host in
49256e7d3316Smrg	        *cygwin* | *mingw* | *cegcc* )
49266e7d3316Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49276e7d3316Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
49286e7d3316Smrg	          ;;
49296e7d3316Smrg	      esac
49306e7d3316Smrg	    }
4931a966c04fSmrg	  fi
49326e7d3316Smrg	fi
4933a966c04fSmrg
49346e7d3316Smrg	for dlprefile in $dlprefiles; do
4935edce3322Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
49366e7d3316Smrg	  func_basename "$dlprefile"
4937edce3322Smrg	  name=$func_basename_result
493897cf2ee2Smrg          case $host in
493997cf2ee2Smrg	    *cygwin* | *mingw* | *cegcc* )
494097cf2ee2Smrg	      # if an import library, we need to obtain dlname
494197cf2ee2Smrg	      if func_win32_import_lib_p "$dlprefile"; then
494297cf2ee2Smrg	        func_tr_sh "$dlprefile"
494397cf2ee2Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944edce3322Smrg	        dlprefile_dlbasename=
494597cf2ee2Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
494697cf2ee2Smrg	          # Use subshell, to avoid clobbering current variable values
494797cf2ee2Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948edce3322Smrg	          if test -n "$dlprefile_dlname"; then
494997cf2ee2Smrg	            func_basename "$dlprefile_dlname"
4950edce3322Smrg	            dlprefile_dlbasename=$func_basename_result
495197cf2ee2Smrg	          else
495297cf2ee2Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
495397cf2ee2Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
495497cf2ee2Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
495597cf2ee2Smrg	          fi
495697cf2ee2Smrg	        fi
495797cf2ee2Smrg	        $opt_dry_run || {
4958edce3322Smrg	          if test -n "$dlprefile_dlbasename"; then
495997cf2ee2Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
496097cf2ee2Smrg	          else
496197cf2ee2Smrg	            func_warning "Could not compute DLL name from $name"
496297cf2ee2Smrg	            eval '$ECHO ": $name " >> "$nlist"'
496397cf2ee2Smrg	          fi
496497cf2ee2Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
496597cf2ee2Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
496697cf2ee2Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
496797cf2ee2Smrg	        }
496897cf2ee2Smrg	      else # not an import lib
496997cf2ee2Smrg	        $opt_dry_run || {
497097cf2ee2Smrg	          eval '$ECHO ": $name " >> "$nlist"'
497197cf2ee2Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
497297cf2ee2Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
497397cf2ee2Smrg	        }
497497cf2ee2Smrg	      fi
497597cf2ee2Smrg	    ;;
497697cf2ee2Smrg	    *)
497797cf2ee2Smrg	      $opt_dry_run || {
497897cf2ee2Smrg	        eval '$ECHO ": $name " >> "$nlist"'
497997cf2ee2Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
498097cf2ee2Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
498197cf2ee2Smrg	      }
498297cf2ee2Smrg	    ;;
498397cf2ee2Smrg          esac
49846e7d3316Smrg	done
49856e7d3316Smrg
49866e7d3316Smrg	$opt_dry_run || {
49876e7d3316Smrg	  # Make sure we have at least an empty file.
49886e7d3316Smrg	  test -f "$nlist" || : > "$nlist"
49896e7d3316Smrg
49906e7d3316Smrg	  if test -n "$exclude_expsyms"; then
49916e7d3316Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
49926e7d3316Smrg	    $MV "$nlist"T "$nlist"
4993a966c04fSmrg	  fi
49946e7d3316Smrg
49956e7d3316Smrg	  # Try sorting and uniquifying the output.
49966e7d3316Smrg	  if $GREP -v "^: " < "$nlist" |
49976e7d3316Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
49986e7d3316Smrg		sort -k 3
49996e7d3316Smrg	      else
50006e7d3316Smrg		sort +2
50016e7d3316Smrg	      fi |
50026e7d3316Smrg	      uniq > "$nlist"S; then
50036e7d3316Smrg	    :
5004a966c04fSmrg	  else
50056e7d3316Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006a966c04fSmrg	  fi
5007a966c04fSmrg
50086e7d3316Smrg	  if test -f "$nlist"S; then
50096e7d3316Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010a966c04fSmrg	  else
50116e7d3316Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012a966c04fSmrg	  fi
5013a966c04fSmrg
5014edce3322Smrg	  func_show_eval '$RM "${nlist}I"'
5015edce3322Smrg	  if test -n "$global_symbol_to_import"; then
5016edce3322Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017edce3322Smrg	  fi
5018edce3322Smrg
50196e7d3316Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5020a966c04fSmrg
50216e7d3316Smrg/* The mapping between symbol names and symbols.  */
50226e7d3316Smrgtypedef struct {
50236e7d3316Smrg  const char *name;
50246e7d3316Smrg  void *address;
50256e7d3316Smrg} lt_dlsymlist;
502697cf2ee2Smrgextern LT_DLSYM_CONST lt_dlsymlist
5027edce3322Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028edce3322Smrg"
5029edce3322Smrg
5030edce3322Smrg	  if test -s "$nlist"I; then
5031edce3322Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032edce3322Smrgstatic void lt_syminit(void)
5033edce3322Smrg{
5034edce3322Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035edce3322Smrg  for (; symbol->name; ++symbol)
5036edce3322Smrg    {"
5037edce3322Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038edce3322Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039edce3322Smrg    }
5040edce3322Smrg}"
5041edce3322Smrg	  fi
5042edce3322Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
504397cf2ee2SmrgLT_DLSYM_CONST lt_dlsymlist
50446e7d3316Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045edce3322Smrg{ {\"$my_originator\", (void *) 0},"
5046edce3322Smrg
5047edce3322Smrg	  if test -s "$nlist"I; then
5048edce3322Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049edce3322Smrg  {\"@INIT@\", (void *) &lt_syminit},"
5050edce3322Smrg	  fi
5051a966c04fSmrg
50526e7d3316Smrg	  case $need_lib_prefix in
50536e7d3316Smrg	  no)
50546e7d3316Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
50556e7d3316Smrg	    ;;
50566e7d3316Smrg	  *)
50576e7d3316Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
50586e7d3316Smrg	    ;;
50596e7d3316Smrg	  esac
50606e7d3316Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
50616e7d3316Smrg  {0, (void *) 0}
50626e7d3316Smrg};
5063a966c04fSmrg
50646e7d3316Smrg/* This works around a problem in FreeBSD linker */
50656e7d3316Smrg#ifdef FREEBSD_WORKAROUND
50666e7d3316Smrgstatic const void *lt_preloaded_setup() {
50676e7d3316Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
50686e7d3316Smrg}
50696e7d3316Smrg#endif
5070a966c04fSmrg
50716e7d3316Smrg#ifdef __cplusplus
50726e7d3316Smrg}
50736e7d3316Smrg#endif\
50746e7d3316Smrg"
50756e7d3316Smrg	} # !$opt_dry_run
5076a966c04fSmrg
50776e7d3316Smrg	pic_flag_for_symtable=
50786e7d3316Smrg	case "$compile_command " in
50796e7d3316Smrg	*" -static "*) ;;
50806e7d3316Smrg	*)
50816e7d3316Smrg	  case $host in
50826e7d3316Smrg	  # compiling the symbol table file with pic_flag works around
50836e7d3316Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
50846e7d3316Smrg	  # linked before any other PIC object.  But we must not use
50856e7d3316Smrg	  # pic_flag when linking with -static.  The problem exists in
50866e7d3316Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087ac92798bSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
50886e7d3316Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
50896e7d3316Smrg	  *-*-hpux*)
50906e7d3316Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
50916e7d3316Smrg	  *)
5092edce3322Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
50936e7d3316Smrg	    ;;
50946e7d3316Smrg	  esac
50956e7d3316Smrg	  ;;
50966e7d3316Smrg	esac
50976e7d3316Smrg	symtab_cflags=
50986e7d3316Smrg	for arg in $LTCFLAGS; do
50996e7d3316Smrg	  case $arg in
51006e7d3316Smrg	  -pie | -fpie | -fPIE) ;;
510197cf2ee2Smrg	  *) func_append symtab_cflags " $arg" ;;
51026e7d3316Smrg	  esac
51036e7d3316Smrg	done
5104a966c04fSmrg
51056e7d3316Smrg	# Now compile the dynamic symbol file.
51066e7d3316Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5107a966c04fSmrg
51086e7d3316Smrg	# Clean up the generated files.
5109edce3322Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5110a966c04fSmrg
51116e7d3316Smrg	# Transform the symbol file into the correct name.
5112edce3322Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
51136e7d3316Smrg	case $host in
51146e7d3316Smrg	*cygwin* | *mingw* | *cegcc* )
51156e7d3316Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
51166e7d3316Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51176e7d3316Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51186e7d3316Smrg	  else
51196e7d3316Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51206e7d3316Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51216e7d3316Smrg	  fi
51226e7d3316Smrg	  ;;
51236e7d3316Smrg	*)
51246e7d3316Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51256e7d3316Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51266e7d3316Smrg	  ;;
51276e7d3316Smrg	esac
51286e7d3316Smrg	;;
51296e7d3316Smrg      *)
5130edce3322Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
51316e7d3316Smrg	;;
51326e7d3316Smrg      esac
51336e7d3316Smrg    else
51346e7d3316Smrg      # We keep going just in case the user didn't refer to
51356e7d3316Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
51366e7d3316Smrg      # really was required.
5137a966c04fSmrg
51386e7d3316Smrg      # Nullify the symbol file.
51396e7d3316Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
51406e7d3316Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
51416e7d3316Smrg    fi
51426e7d3316Smrg}
5143a966c04fSmrg
5144edce3322Smrg# func_cygming_gnu_implib_p ARG
5145edce3322Smrg# This predicate returns with zero status (TRUE) if
5146edce3322Smrg# ARG is a GNU/binutils-style import library. Returns
5147edce3322Smrg# with nonzero status (FALSE) otherwise.
5148edce3322Smrgfunc_cygming_gnu_implib_p ()
5149edce3322Smrg{
5150edce3322Smrg  $debug_cmd
5151edce3322Smrg
5152edce3322Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153edce3322Smrg  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)$'`
5154edce3322Smrg  test -n "$func_cygming_gnu_implib_tmp"
5155edce3322Smrg}
5156edce3322Smrg
5157edce3322Smrg# func_cygming_ms_implib_p ARG
5158edce3322Smrg# This predicate returns with zero status (TRUE) if
5159edce3322Smrg# ARG is an MS-style import library. Returns
5160edce3322Smrg# with nonzero status (FALSE) otherwise.
5161edce3322Smrgfunc_cygming_ms_implib_p ()
5162edce3322Smrg{
5163edce3322Smrg  $debug_cmd
5164edce3322Smrg
5165edce3322Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166edce3322Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167edce3322Smrg  test -n "$func_cygming_ms_implib_tmp"
5168edce3322Smrg}
5169edce3322Smrg
51706e7d3316Smrg# func_win32_libid arg
51716e7d3316Smrg# return the library type of file 'arg'
51726e7d3316Smrg#
51736e7d3316Smrg# Need a lot of goo to handle *both* DLLs and import libs
51746e7d3316Smrg# Has to be a shell function in order to 'eat' the argument
51756e7d3316Smrg# that is supplied when $file_magic_command is called.
51766e7d3316Smrg# Despite the name, also deal with 64 bit binaries.
51776e7d3316Smrgfunc_win32_libid ()
51786e7d3316Smrg{
5179edce3322Smrg  $debug_cmd
5180edce3322Smrg
5181edce3322Smrg  win32_libid_type=unknown
51826e7d3316Smrg  win32_fileres=`file -L $1 2>/dev/null`
51836e7d3316Smrg  case $win32_fileres in
51846e7d3316Smrg  *ar\ archive\ import\ library*) # definitely import
51856e7d3316Smrg    win32_libid_type="x86 archive import"
51866e7d3316Smrg    ;;
51876e7d3316Smrg  *ar\ archive*) # could be an import, or static
51886e7d3316Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
51896e7d3316Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
51906e7d3316Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191edce3322Smrg      case $nm_interface in
5192edce3322Smrg      "MS dumpbin")
5193edce3322Smrg	if func_cygming_ms_implib_p "$1" ||
5194edce3322Smrg	   func_cygming_gnu_implib_p "$1"
5195edce3322Smrg	then
5196edce3322Smrg	  win32_nmres=import
5197edce3322Smrg	else
5198edce3322Smrg	  win32_nmres=
5199edce3322Smrg	fi
5200edce3322Smrg	;;
5201edce3322Smrg      *)
5202edce3322Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203edce3322Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204edce3322Smrg	  $SED -n -e '
52056e7d3316Smrg	    1,100{
52066e7d3316Smrg		/ I /{
5207edce3322Smrg		    s|.*|import|
52086e7d3316Smrg		    p
52096e7d3316Smrg		    q
52106e7d3316Smrg		}
52116e7d3316Smrg	    }'`
5212edce3322Smrg	;;
5213edce3322Smrg      esac
52146e7d3316Smrg      case $win32_nmres in
52156e7d3316Smrg      import*)  win32_libid_type="x86 archive import";;
52166e7d3316Smrg      *)        win32_libid_type="x86 archive static";;
52176e7d3316Smrg      esac
52186e7d3316Smrg    fi
52196e7d3316Smrg    ;;
52206e7d3316Smrg  *DLL*)
52216e7d3316Smrg    win32_libid_type="x86 DLL"
52226e7d3316Smrg    ;;
52236e7d3316Smrg  *executable*) # but shell scripts are "executable" too...
52246e7d3316Smrg    case $win32_fileres in
52256e7d3316Smrg    *MS\ Windows\ PE\ Intel*)
52266e7d3316Smrg      win32_libid_type="x86 DLL"
52276e7d3316Smrg      ;;
52286e7d3316Smrg    esac
52296e7d3316Smrg    ;;
52306e7d3316Smrg  esac
52316e7d3316Smrg  $ECHO "$win32_libid_type"
52326e7d3316Smrg}
5233a966c04fSmrg
523497cf2ee2Smrg# func_cygming_dll_for_implib ARG
523597cf2ee2Smrg#
523697cf2ee2Smrg# Platform-specific function to extract the
523797cf2ee2Smrg# name of the DLL associated with the specified
523897cf2ee2Smrg# import library ARG.
523997cf2ee2Smrg# Invoked by eval'ing the libtool variable
524097cf2ee2Smrg#    $sharedlib_from_linklib_cmd
524197cf2ee2Smrg# Result is available in the variable
524297cf2ee2Smrg#    $sharedlib_from_linklib_result
524397cf2ee2Smrgfunc_cygming_dll_for_implib ()
524497cf2ee2Smrg{
5245edce3322Smrg  $debug_cmd
5246edce3322Smrg
524797cf2ee2Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
524897cf2ee2Smrg}
524997cf2ee2Smrg
525097cf2ee2Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
525197cf2ee2Smrg#
525297cf2ee2Smrg# The is the core of a fallback implementation of a
525397cf2ee2Smrg# platform-specific function to extract the name of the
525497cf2ee2Smrg# DLL associated with the specified import library LIBNAME.
525597cf2ee2Smrg#
525697cf2ee2Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
525797cf2ee2Smrg# on the platform and compiler that created the implib.
525897cf2ee2Smrg#
525997cf2ee2Smrg# Echos the name of the DLL associated with the
526097cf2ee2Smrg# specified import library.
526197cf2ee2Smrgfunc_cygming_dll_for_implib_fallback_core ()
526297cf2ee2Smrg{
5263edce3322Smrg  $debug_cmd
5264edce3322Smrg
526597cf2ee2Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
526697cf2ee2Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
526797cf2ee2Smrg    $SED '/^Contents of section '"$match_literal"':/{
526897cf2ee2Smrg      # Place marker at beginning of archive member dllname section
526997cf2ee2Smrg      s/.*/====MARK====/
527097cf2ee2Smrg      p
527197cf2ee2Smrg      d
527297cf2ee2Smrg    }
527397cf2ee2Smrg    # These lines can sometimes be longer than 43 characters, but
527497cf2ee2Smrg    # are always uninteresting
527597cf2ee2Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
527697cf2ee2Smrg    /^In archive [^:]*:/d
527797cf2ee2Smrg    # Ensure marker is printed
527897cf2ee2Smrg    /^====MARK====/p
527997cf2ee2Smrg    # Remove all lines with less than 43 characters
528097cf2ee2Smrg    /^.\{43\}/!d
528197cf2ee2Smrg    # From remaining lines, remove first 43 characters
528297cf2ee2Smrg    s/^.\{43\}//' |
528397cf2ee2Smrg    $SED -n '
528497cf2ee2Smrg      # Join marker and all lines until next marker into a single line
528597cf2ee2Smrg      /^====MARK====/ b para
528697cf2ee2Smrg      H
528797cf2ee2Smrg      $ b para
528897cf2ee2Smrg      b
528997cf2ee2Smrg      :para
529097cf2ee2Smrg      x
529197cf2ee2Smrg      s/\n//g
529297cf2ee2Smrg      # Remove the marker
529397cf2ee2Smrg      s/^====MARK====//
529497cf2ee2Smrg      # Remove trailing dots and whitespace
529597cf2ee2Smrg      s/[\. \t]*$//
529697cf2ee2Smrg      # Print
529797cf2ee2Smrg      /./p' |
529897cf2ee2Smrg    # we now have a list, one entry per line, of the stringified
529997cf2ee2Smrg    # contents of the appropriate section of all members of the
5300edce3322Smrg    # archive that possess that section. Heuristic: eliminate
5301edce3322Smrg    # all those that have a first or second character that is
530297cf2ee2Smrg    # a '.' (that is, objdump's representation of an unprintable
530397cf2ee2Smrg    # character.) This should work for all archives with less than
530497cf2ee2Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
530597cf2ee2Smrg    # begins with a literal '.' or a single character followed by
530697cf2ee2Smrg    # a '.'.
530797cf2ee2Smrg    #
530897cf2ee2Smrg    # Of those that remain, print the first one.
530997cf2ee2Smrg    $SED -e '/^\./d;/^.\./d;q'
531097cf2ee2Smrg}
531197cf2ee2Smrg
531297cf2ee2Smrg# func_cygming_dll_for_implib_fallback ARG
531397cf2ee2Smrg# Platform-specific function to extract the
531497cf2ee2Smrg# name of the DLL associated with the specified
531597cf2ee2Smrg# import library ARG.
531697cf2ee2Smrg#
531797cf2ee2Smrg# This fallback implementation is for use when $DLLTOOL
531897cf2ee2Smrg# does not support the --identify-strict option.
531997cf2ee2Smrg# Invoked by eval'ing the libtool variable
532097cf2ee2Smrg#    $sharedlib_from_linklib_cmd
532197cf2ee2Smrg# Result is available in the variable
532297cf2ee2Smrg#    $sharedlib_from_linklib_result
532397cf2ee2Smrgfunc_cygming_dll_for_implib_fallback ()
532497cf2ee2Smrg{
5325edce3322Smrg  $debug_cmd
5326edce3322Smrg
5327edce3322Smrg  if func_cygming_gnu_implib_p "$1"; then
532897cf2ee2Smrg    # binutils import library
532997cf2ee2Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330edce3322Smrg  elif func_cygming_ms_implib_p "$1"; then
533197cf2ee2Smrg    # ms-generated import library
533297cf2ee2Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
533397cf2ee2Smrg  else
533497cf2ee2Smrg    # unknown
5335edce3322Smrg    sharedlib_from_linklib_result=
533697cf2ee2Smrg  fi
533797cf2ee2Smrg}
5338a966c04fSmrg
5339a966c04fSmrg
53406e7d3316Smrg# func_extract_an_archive dir oldlib
53416e7d3316Smrgfunc_extract_an_archive ()
53426e7d3316Smrg{
5343edce3322Smrg    $debug_cmd
5344edce3322Smrg
5345edce3322Smrg    f_ex_an_ar_dir=$1; shift
5346edce3322Smrg    f_ex_an_ar_oldlib=$1
5347edce3322Smrg    if test yes = "$lock_old_archive_extraction"; then
53486e7d3316Smrg      lockfile=$f_ex_an_ar_oldlib.lock
53496e7d3316Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
53506e7d3316Smrg	func_echo "Waiting for $lockfile to be removed"
53516e7d3316Smrg	sleep 2
53526e7d3316Smrg      done
53536e7d3316Smrg    fi
53546e7d3316Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
53556e7d3316Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356edce3322Smrg    if test yes = "$lock_old_archive_extraction"; then
53576e7d3316Smrg      $opt_dry_run || rm -f "$lockfile"
53586e7d3316Smrg    fi
53596e7d3316Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
53606e7d3316Smrg     :
53616e7d3316Smrg    else
53626e7d3316Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
53636e7d3316Smrg    fi
53646e7d3316Smrg}
5365a966c04fSmrg
5366a966c04fSmrg
53676e7d3316Smrg# func_extract_archives gentop oldlib ...
53686e7d3316Smrgfunc_extract_archives ()
53696e7d3316Smrg{
5370edce3322Smrg    $debug_cmd
5371edce3322Smrg
5372edce3322Smrg    my_gentop=$1; shift
53736e7d3316Smrg    my_oldlibs=${1+"$@"}
5374edce3322Smrg    my_oldobjs=
5375edce3322Smrg    my_xlib=
5376edce3322Smrg    my_xabs=
5377edce3322Smrg    my_xdir=
5378a966c04fSmrg
53796e7d3316Smrg    for my_xlib in $my_oldlibs; do
53806e7d3316Smrg      # Extract the objects.
53816e7d3316Smrg      case $my_xlib in
5382edce3322Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
53836e7d3316Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
53846e7d3316Smrg      esac
53856e7d3316Smrg      func_basename "$my_xlib"
5386edce3322Smrg      my_xlib=$func_basename_result
53876e7d3316Smrg      my_xlib_u=$my_xlib
53886e7d3316Smrg      while :; do
53896e7d3316Smrg        case " $extracted_archives " in
53906e7d3316Smrg	*" $my_xlib_u "*)
53916e7d3316Smrg	  func_arith $extracted_serial + 1
53926e7d3316Smrg	  extracted_serial=$func_arith_result
53936e7d3316Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
53946e7d3316Smrg	*) break ;;
53956e7d3316Smrg	esac
53966e7d3316Smrg      done
53976e7d3316Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5398edce3322Smrg      my_xdir=$my_gentop/$my_xlib_u
5399a966c04fSmrg
54006e7d3316Smrg      func_mkdir_p "$my_xdir"
54016e7d3316Smrg
54026e7d3316Smrg      case $host in
54036e7d3316Smrg      *-darwin*)
54046e7d3316Smrg	func_verbose "Extracting $my_xabs"
54056e7d3316Smrg	# Do not bother doing anything if just a dry run
54066e7d3316Smrg	$opt_dry_run || {
54076e7d3316Smrg	  darwin_orig_dir=`pwd`
54086e7d3316Smrg	  cd $my_xdir || exit $?
54096e7d3316Smrg	  darwin_archive=$my_xabs
54106e7d3316Smrg	  darwin_curdir=`pwd`
5411edce3322Smrg	  func_basename "$darwin_archive"
5412edce3322Smrg	  darwin_base_archive=$func_basename_result
54136e7d3316Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
54146e7d3316Smrg	  if test -n "$darwin_arches"; then
54156e7d3316Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
54166e7d3316Smrg	    darwin_arch=
54176e7d3316Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418edce3322Smrg	    for darwin_arch in  $darwin_arches; do
5419edce3322Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420edce3322Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421edce3322Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422edce3322Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
54236e7d3316Smrg	      cd "$darwin_curdir"
5424edce3322Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
54256e7d3316Smrg	    done # $darwin_arches
54266e7d3316Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427edce3322Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
54286e7d3316Smrg	    darwin_file=
54296e7d3316Smrg	    darwin_files=
54306e7d3316Smrg	    for darwin_file in $darwin_filelist; do
54316e7d3316Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
54326e7d3316Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
54336e7d3316Smrg	    done # $darwin_filelist
54346e7d3316Smrg	    $RM -rf unfat-$$
54356e7d3316Smrg	    cd "$darwin_orig_dir"
5436a966c04fSmrg	  else
54376e7d3316Smrg	    cd $darwin_orig_dir
54386e7d3316Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
54396e7d3316Smrg	  fi # $darwin_arches
54406e7d3316Smrg	} # !$opt_dry_run
54416e7d3316Smrg	;;
54426e7d3316Smrg      *)
54436e7d3316Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
54446e7d3316Smrg	;;
54456e7d3316Smrg      esac
54466e7d3316Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
54476e7d3316Smrg    done
5448a966c04fSmrg
5449edce3322Smrg    func_extract_archives_result=$my_oldobjs
54506e7d3316Smrg}
5451a966c04fSmrg
5452a966c04fSmrg
54536e7d3316Smrg# func_emit_wrapper [arg=no]
54546e7d3316Smrg#
54556e7d3316Smrg# Emit a libtool wrapper script on stdout.
54566e7d3316Smrg# Don't directly open a file because we may want to
54576e7d3316Smrg# incorporate the script contents within a cygwin/mingw
54586e7d3316Smrg# wrapper executable.  Must ONLY be called from within
54596e7d3316Smrg# func_mode_link because it depends on a number of variables
54606e7d3316Smrg# set therein.
54616e7d3316Smrg#
54626e7d3316Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
54636e7d3316Smrg# variable will take.  If 'yes', then the emitted script
5464edce3322Smrg# will assume that the directory where it is stored is
54656e7d3316Smrg# the $objdir directory.  This is a cygwin/mingw-specific
54666e7d3316Smrg# behavior.
54676e7d3316Smrgfunc_emit_wrapper ()
54686e7d3316Smrg{
54696e7d3316Smrg	func_emit_wrapper_arg1=${1-no}
5470a966c04fSmrg
54716e7d3316Smrg	$ECHO "\
54726e7d3316Smrg#! $SHELL
5473a966c04fSmrg
54746e7d3316Smrg# $output - temporary wrapper script for $objdir/$outputname
5475edce3322Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
54766e7d3316Smrg#
54776e7d3316Smrg# The $output program cannot be directly executed until all the libtool
54786e7d3316Smrg# libraries that it depends on are installed.
54796e7d3316Smrg#
54806e7d3316Smrg# This wrapper script should never be moved out of the build directory.
54816e7d3316Smrg# If it is, it will not operate correctly.
5482a966c04fSmrg
54836e7d3316Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
54846e7d3316Smrg# metacharacters that are still active within double-quoted strings.
54856e7d3316Smrgsed_quote_subst='$sed_quote_subst'
5486a966c04fSmrg
54876e7d3316Smrg# Be Bourne compatible
54886e7d3316Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
54896e7d3316Smrg  emulate sh
54906e7d3316Smrg  NULLCMD=:
54916e7d3316Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
54926e7d3316Smrg  # is contrary to our usage.  Disable this feature.
54936e7d3316Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
54946e7d3316Smrg  setopt NO_GLOB_SUBST
54956e7d3316Smrgelse
54966e7d3316Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
54976e7d3316Smrgfi
54986e7d3316SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
54996e7d3316SmrgDUALCASE=1; export DUALCASE # for MKS sh
5500a966c04fSmrg
55016e7d3316Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
55026e7d3316Smrg# if CDPATH is set.
55036e7d3316Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5504a966c04fSmrg
55056e7d3316Smrgrelink_command=\"$relink_command\"
5506a966c04fSmrg
55076e7d3316Smrg# This environment variable determines our operation mode.
55086e7d3316Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
55096e7d3316Smrg  # install mode needs the following variables:
55106e7d3316Smrg  generated_by_libtool_version='$macro_version'
55116e7d3316Smrg  notinst_deplibs='$notinst_deplibs'
55126e7d3316Smrgelse
55136e7d3316Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
55146e7d3316Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
55156e7d3316Smrg    file=\"\$0\""
5516a966c04fSmrg
551774835918Smrg    func_quote_arg pretty "$ECHO"
551874835918Smrg    qECHO=$func_quote_arg_result
55196e7d3316Smrg    $ECHO "\
5520a966c04fSmrg
55216e7d3316Smrg# A function that is used when there is no print builtin or printf.
55226e7d3316Smrgfunc_fallback_echo ()
55236e7d3316Smrg{
55246e7d3316Smrg  eval 'cat <<_LTECHO_EOF
55256e7d3316Smrg\$1
55266e7d3316Smrg_LTECHO_EOF'
55276e7d3316Smrg}
552874835918Smrg    ECHO=$qECHO
55296e7d3316Smrg  fi
55306e7d3316Smrg
55316e7d3316Smrg# Very basic option parsing. These options are (a) specific to
55326e7d3316Smrg# the libtool wrapper, (b) are identical between the wrapper
5533edce3322Smrg# /script/ and the wrapper /executable/ that is used only on
55346e7d3316Smrg# windows platforms, and (c) all begin with the string "--lt-"
5535edce3322Smrg# (application programs are unlikely to have options that match
55366e7d3316Smrg# this pattern).
55376e7d3316Smrg#
55386e7d3316Smrg# There are only two supported options: --lt-debug and
55396e7d3316Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
55406e7d3316Smrg#
55416e7d3316Smrg# The first argument to this parsing function should be the
55426e7d3316Smrg# script's $0 value, followed by "$@".
55436e7d3316Smrglt_option_debug=
55446e7d3316Smrgfunc_parse_lt_options ()
55456e7d3316Smrg{
55466e7d3316Smrg  lt_script_arg0=\$0
55476e7d3316Smrg  shift
55486e7d3316Smrg  for lt_opt
55496e7d3316Smrg  do
55506e7d3316Smrg    case \"\$lt_opt\" in
55516e7d3316Smrg    --lt-debug) lt_option_debug=1 ;;
55526e7d3316Smrg    --lt-dump-script)
55536e7d3316Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
55546e7d3316Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
55556e7d3316Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
55566e7d3316Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
55576e7d3316Smrg        exit 0
55586e7d3316Smrg      ;;
55596e7d3316Smrg    --lt-*)
55606e7d3316Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
55616e7d3316Smrg        exit 1
5562a966c04fSmrg      ;;
55636e7d3316Smrg    esac
55646e7d3316Smrg  done
5565a966c04fSmrg
55666e7d3316Smrg  # Print the debug banner immediately:
55676e7d3316Smrg  if test -n \"\$lt_option_debug\"; then
5568edce3322Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
55696e7d3316Smrg  fi
55706e7d3316Smrg}
5571a966c04fSmrg
55726e7d3316Smrg# Used when --lt-debug. Prints its arguments to stdout
55736e7d3316Smrg# (redirection is the responsibility of the caller)
55746e7d3316Smrgfunc_lt_dump_args ()
55756e7d3316Smrg{
55766e7d3316Smrg  lt_dump_args_N=1;
55776e7d3316Smrg  for lt_arg
55786e7d3316Smrg  do
5579edce3322Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
55806e7d3316Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
55816e7d3316Smrg  done
55826e7d3316Smrg}
5583a966c04fSmrg
55846e7d3316Smrg# Core function for launching the target application
55856e7d3316Smrgfunc_exec_program_core ()
55866e7d3316Smrg{
55876e7d3316Smrg"
55886e7d3316Smrg  case $host in
55896e7d3316Smrg  # Backslashes separate directories on plain windows
55906e7d3316Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
55916e7d3316Smrg    $ECHO "\
55926e7d3316Smrg      if test -n \"\$lt_option_debug\"; then
5593edce3322Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
55946e7d3316Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5595a966c04fSmrg      fi
55966e7d3316Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
55976e7d3316Smrg"
55986e7d3316Smrg    ;;
5599a966c04fSmrg
56006e7d3316Smrg  *)
56016e7d3316Smrg    $ECHO "\
56026e7d3316Smrg      if test -n \"\$lt_option_debug\"; then
5603edce3322Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
56046e7d3316Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5605a966c04fSmrg      fi
56066e7d3316Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
56076e7d3316Smrg"
56086e7d3316Smrg    ;;
56096e7d3316Smrg  esac
56106e7d3316Smrg  $ECHO "\
56116e7d3316Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
56126e7d3316Smrg      exit 1
56136e7d3316Smrg}
5614a966c04fSmrg
56156e7d3316Smrg# A function to encapsulate launching the target application
56166e7d3316Smrg# Strips options in the --lt-* namespace from \$@ and
56176e7d3316Smrg# launches target application with the remaining arguments.
56186e7d3316Smrgfunc_exec_program ()
56196e7d3316Smrg{
5620ac92798bSmrg  case \" \$* \" in
5621ac92798bSmrg  *\\ --lt-*)
5622ac92798bSmrg    for lt_wr_arg
5623ac92798bSmrg    do
5624ac92798bSmrg      case \$lt_wr_arg in
5625ac92798bSmrg      --lt-*) ;;
5626ac92798bSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627ac92798bSmrg      esac
5628ac92798bSmrg      shift
5629ac92798bSmrg    done ;;
5630ac92798bSmrg  esac
56316e7d3316Smrg  func_exec_program_core \${1+\"\$@\"}
56326e7d3316Smrg}
5633a966c04fSmrg
56346e7d3316Smrg  # Parse options
56356e7d3316Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5636a966c04fSmrg
56376e7d3316Smrg  # Find the directory that this script lives in.
56386e7d3316Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
56396e7d3316Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5640a966c04fSmrg
56416e7d3316Smrg  # Follow symbolic links until we get to the real thisdir.
56426e7d3316Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
56436e7d3316Smrg  while test -n \"\$file\"; do
56446e7d3316Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5645a966c04fSmrg
56466e7d3316Smrg    # If there was a directory component, then change thisdir.
56476e7d3316Smrg    if test \"x\$destdir\" != \"x\$file\"; then
56486e7d3316Smrg      case \"\$destdir\" in
56496e7d3316Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
56506e7d3316Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
56516e7d3316Smrg      esac
56526e7d3316Smrg    fi
5653a966c04fSmrg
56546e7d3316Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
56556e7d3316Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
56566e7d3316Smrg  done
5657a966c04fSmrg
56586e7d3316Smrg  # Usually 'no', except on cygwin/mingw when embedded into
56596e7d3316Smrg  # the cwrapper.
56606e7d3316Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
56616e7d3316Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
56626e7d3316Smrg    # special case for '.'
56636e7d3316Smrg    if test \"\$thisdir\" = \".\"; then
56646e7d3316Smrg      thisdir=\`pwd\`
56656e7d3316Smrg    fi
56666e7d3316Smrg    # remove .libs from thisdir
56676e7d3316Smrg    case \"\$thisdir\" in
56686e7d3316Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
56696e7d3316Smrg    $objdir )   thisdir=. ;;
56706e7d3316Smrg    esac
56716e7d3316Smrg  fi
5672a966c04fSmrg
56736e7d3316Smrg  # Try to get the absolute directory name.
56746e7d3316Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
56756e7d3316Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
56766e7d3316Smrg"
5677a966c04fSmrg
5678edce3322Smrg	if test yes = "$fast_install"; then
56796e7d3316Smrg	  $ECHO "\
56806e7d3316Smrg  program=lt-'$outputname'$exeext
56816e7d3316Smrg  progdir=\"\$thisdir/$objdir\"
5682a966c04fSmrg
56836e7d3316Smrg  if test ! -f \"\$progdir/\$program\" ||
5684edce3322Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
56856e7d3316Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686a966c04fSmrg
56876e7d3316Smrg    file=\"\$\$-\$program\"
5688a966c04fSmrg
56896e7d3316Smrg    if test ! -d \"\$progdir\"; then
56906e7d3316Smrg      $MKDIR \"\$progdir\"
56916e7d3316Smrg    else
56926e7d3316Smrg      $RM \"\$progdir/\$file\"
56936e7d3316Smrg    fi"
5694a966c04fSmrg
56956e7d3316Smrg	  $ECHO "\
5696a966c04fSmrg
56976e7d3316Smrg    # relink executable if necessary
56986e7d3316Smrg    if test -n \"\$relink_command\"; then
56996e7d3316Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
57006e7d3316Smrg      else
5701edce3322Smrg	\$ECHO \"\$relink_command_output\" >&2
57026e7d3316Smrg	$RM \"\$progdir/\$file\"
57036e7d3316Smrg	exit 1
57046e7d3316Smrg      fi
57056e7d3316Smrg    fi
5706a966c04fSmrg
57076e7d3316Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
57086e7d3316Smrg    { $RM \"\$progdir/\$program\";
57096e7d3316Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
57106e7d3316Smrg    $RM \"\$progdir/\$file\"
57116e7d3316Smrg  fi"
57126e7d3316Smrg	else
57136e7d3316Smrg	  $ECHO "\
57146e7d3316Smrg  program='$outputname'
57156e7d3316Smrg  progdir=\"\$thisdir/$objdir\"
57166e7d3316Smrg"
57176e7d3316Smrg	fi
5718a966c04fSmrg
57196e7d3316Smrg	$ECHO "\
5720a966c04fSmrg
57216e7d3316Smrg  if test -f \"\$progdir/\$program\"; then"
5722a966c04fSmrg
572397cf2ee2Smrg	# fixup the dll searchpath if we need to.
572497cf2ee2Smrg	#
572597cf2ee2Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
572697cf2ee2Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
572797cf2ee2Smrg	# libraries must come first.
572897cf2ee2Smrg	if test -n "$dllsearchpath"; then
572997cf2ee2Smrg	  $ECHO "\
573097cf2ee2Smrg    # Add the dll search path components to the executable PATH
573197cf2ee2Smrg    PATH=$dllsearchpath:\$PATH
573297cf2ee2Smrg"
573397cf2ee2Smrg	fi
573497cf2ee2Smrg
57356e7d3316Smrg	# Export our shlibpath_var if we have one.
5736edce3322Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
57376e7d3316Smrg	  $ECHO "\
57386e7d3316Smrg    # Add our own library path to $shlibpath_var
57396e7d3316Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740a966c04fSmrg
57416e7d3316Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
57426e7d3316Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
57436e7d3316Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5744a966c04fSmrg
57456e7d3316Smrg    export $shlibpath_var
57466e7d3316Smrg"
57476e7d3316Smrg	fi
5748a966c04fSmrg
57496e7d3316Smrg	$ECHO "\
57506e7d3316Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
57516e7d3316Smrg      # Run the actual program with our arguments.
57526e7d3316Smrg      func_exec_program \${1+\"\$@\"}
57536e7d3316Smrg    fi
57546e7d3316Smrg  else
57556e7d3316Smrg    # The program doesn't exist.
5756edce3322Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
57576e7d3316Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
57586e7d3316Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
57596e7d3316Smrg    exit 1
57606e7d3316Smrg  fi
57616e7d3316Smrgfi\
57626e7d3316Smrg"
57636e7d3316Smrg}
5764a966c04fSmrg
5765a966c04fSmrg
57666e7d3316Smrg# func_emit_cwrapperexe_src
57676e7d3316Smrg# emit the source code for a wrapper executable on stdout
57686e7d3316Smrg# Must ONLY be called from within func_mode_link because
57696e7d3316Smrg# it depends on a number of variable set therein.
57706e7d3316Smrgfunc_emit_cwrapperexe_src ()
57716e7d3316Smrg{
57726e7d3316Smrg	cat <<EOF
5773a966c04fSmrg
57746e7d3316Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775edce3322Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776a966c04fSmrg
57776e7d3316Smrg   The $output program cannot be directly executed until all the libtool
57786e7d3316Smrg   libraries that it depends on are installed.
5779a966c04fSmrg
57806e7d3316Smrg   This wrapper executable should never be moved out of the build directory.
57816e7d3316Smrg   If it is, it will not operate correctly.
57826e7d3316Smrg*/
57836e7d3316SmrgEOF
57846e7d3316Smrg	    cat <<"EOF"
57856e7d3316Smrg#ifdef _MSC_VER
57866e7d3316Smrg# define _CRT_SECURE_NO_DEPRECATE 1
57876e7d3316Smrg#endif
57886e7d3316Smrg#include <stdio.h>
57896e7d3316Smrg#include <stdlib.h>
57906e7d3316Smrg#ifdef _MSC_VER
57916e7d3316Smrg# include <direct.h>
57926e7d3316Smrg# include <process.h>
57936e7d3316Smrg# include <io.h>
57946e7d3316Smrg#else
57956e7d3316Smrg# include <unistd.h>
57966e7d3316Smrg# include <stdint.h>
57976e7d3316Smrg# ifdef __CYGWIN__
57986e7d3316Smrg#  include <io.h>
57996e7d3316Smrg# endif
58006e7d3316Smrg#endif
58016e7d3316Smrg#include <malloc.h>
58026e7d3316Smrg#include <stdarg.h>
58036e7d3316Smrg#include <assert.h>
58046e7d3316Smrg#include <string.h>
58056e7d3316Smrg#include <ctype.h>
58066e7d3316Smrg#include <errno.h>
58076e7d3316Smrg#include <fcntl.h>
58086e7d3316Smrg#include <sys/stat.h>
5809a966c04fSmrg
5810edce3322Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811edce3322Smrg
58126e7d3316Smrg/* declarations of non-ANSI functions */
5813edce3322Smrg#if defined __MINGW32__
58146e7d3316Smrg# ifdef __STRICT_ANSI__
58156e7d3316Smrgint _putenv (const char *);
58166e7d3316Smrg# endif
5817edce3322Smrg#elif defined __CYGWIN__
58186e7d3316Smrg# ifdef __STRICT_ANSI__
58196e7d3316Smrgchar *realpath (const char *, char *);
58206e7d3316Smrgint putenv (char *);
58216e7d3316Smrgint setenv (const char *, const char *, int);
58226e7d3316Smrg# endif
5823edce3322Smrg/* #elif defined other_platform || defined ... */
58246e7d3316Smrg#endif
5825a966c04fSmrg
58266e7d3316Smrg/* portability defines, excluding path handling macros */
5827edce3322Smrg#if defined _MSC_VER
58286e7d3316Smrg# define setmode _setmode
58296e7d3316Smrg# define stat    _stat
58306e7d3316Smrg# define chmod   _chmod
58316e7d3316Smrg# define getcwd  _getcwd
58326e7d3316Smrg# define putenv  _putenv
58336e7d3316Smrg# define S_IXUSR _S_IEXEC
5834edce3322Smrg#elif defined __MINGW32__
58356e7d3316Smrg# define setmode _setmode
58366e7d3316Smrg# define stat    _stat
58376e7d3316Smrg# define chmod   _chmod
58386e7d3316Smrg# define getcwd  _getcwd
58396e7d3316Smrg# define putenv  _putenv
5840edce3322Smrg#elif defined __CYGWIN__
58416e7d3316Smrg# define HAVE_SETENV
58426e7d3316Smrg# define FOPEN_WB "wb"
5843edce3322Smrg/* #elif defined other platforms ... */
58446e7d3316Smrg#endif
5845a966c04fSmrg
5846edce3322Smrg#if defined PATH_MAX
58476e7d3316Smrg# define LT_PATHMAX PATH_MAX
5848edce3322Smrg#elif defined MAXPATHLEN
58496e7d3316Smrg# define LT_PATHMAX MAXPATHLEN
58506e7d3316Smrg#else
58516e7d3316Smrg# define LT_PATHMAX 1024
58526e7d3316Smrg#endif
5853a966c04fSmrg
58546e7d3316Smrg#ifndef S_IXOTH
58556e7d3316Smrg# define S_IXOTH 0
58566e7d3316Smrg#endif
58576e7d3316Smrg#ifndef S_IXGRP
58586e7d3316Smrg# define S_IXGRP 0
58596e7d3316Smrg#endif
5860a966c04fSmrg
58616e7d3316Smrg/* path handling portability macros */
58626e7d3316Smrg#ifndef DIR_SEPARATOR
58636e7d3316Smrg# define DIR_SEPARATOR '/'
58646e7d3316Smrg# define PATH_SEPARATOR ':'
58656e7d3316Smrg#endif
5866a966c04fSmrg
5867edce3322Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868edce3322Smrg  defined __OS2__
58696e7d3316Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
58706e7d3316Smrg# define FOPEN_WB "wb"
58716e7d3316Smrg# ifndef DIR_SEPARATOR_2
58726e7d3316Smrg#  define DIR_SEPARATOR_2 '\\'
58736e7d3316Smrg# endif
58746e7d3316Smrg# ifndef PATH_SEPARATOR_2
58756e7d3316Smrg#  define PATH_SEPARATOR_2 ';'
58766e7d3316Smrg# endif
58776e7d3316Smrg#endif
5878a966c04fSmrg
58796e7d3316Smrg#ifndef DIR_SEPARATOR_2
58806e7d3316Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
58816e7d3316Smrg#else /* DIR_SEPARATOR_2 */
58826e7d3316Smrg# define IS_DIR_SEPARATOR(ch) \
58836e7d3316Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
58846e7d3316Smrg#endif /* DIR_SEPARATOR_2 */
5885a966c04fSmrg
58866e7d3316Smrg#ifndef PATH_SEPARATOR_2
58876e7d3316Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
58886e7d3316Smrg#else /* PATH_SEPARATOR_2 */
58896e7d3316Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
58906e7d3316Smrg#endif /* PATH_SEPARATOR_2 */
58916e7d3316Smrg
58926e7d3316Smrg#ifndef FOPEN_WB
58936e7d3316Smrg# define FOPEN_WB "w"
58946e7d3316Smrg#endif
58956e7d3316Smrg#ifndef _O_BINARY
58966e7d3316Smrg# define _O_BINARY 0
58976e7d3316Smrg#endif
58986e7d3316Smrg
58996e7d3316Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
59006e7d3316Smrg#define XFREE(stale) do { \
5901edce3322Smrg  if (stale) { free (stale); stale = 0; } \
59026e7d3316Smrg} while (0)
59036e7d3316Smrg
5904edce3322Smrg#if defined LT_DEBUGWRAPPER
59056e7d3316Smrgstatic int lt_debug = 1;
59066e7d3316Smrg#else
59076e7d3316Smrgstatic int lt_debug = 0;
59086e7d3316Smrg#endif
59096e7d3316Smrg
59106e7d3316Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
59116e7d3316Smrg
59126e7d3316Smrgvoid *xmalloc (size_t num);
59136e7d3316Smrgchar *xstrdup (const char *string);
59146e7d3316Smrgconst char *base_name (const char *name);
59156e7d3316Smrgchar *find_executable (const char *wrapper);
59166e7d3316Smrgchar *chase_symlinks (const char *pathspec);
59176e7d3316Smrgint make_executable (const char *path);
59186e7d3316Smrgint check_executable (const char *path);
59196e7d3316Smrgchar *strendzap (char *str, const char *pat);
59206e7d3316Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
59216e7d3316Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
59226e7d3316Smrgstatic const char *nonnull (const char *s);
59236e7d3316Smrgstatic const char *nonempty (const char *s);
59246e7d3316Smrgvoid lt_setenv (const char *name, const char *value);
59256e7d3316Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
59266e7d3316Smrgvoid lt_update_exe_path (const char *name, const char *value);
59276e7d3316Smrgvoid lt_update_lib_path (const char *name, const char *value);
59286e7d3316Smrgchar **prepare_spawn (char **argv);
59296e7d3316Smrgvoid lt_dump_script (FILE *f);
59306e7d3316SmrgEOF
59316e7d3316Smrg
59326e7d3316Smrg	    cat <<EOF
5933edce3322Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934edce3322Smrg# define externally_visible volatile
5935edce3322Smrg#else
5936edce3322Smrg# define externally_visible __attribute__((externally_visible)) volatile
5937edce3322Smrg#endif
5938edce3322Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
59396e7d3316Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
59406e7d3316SmrgEOF
59416e7d3316Smrg
5942edce3322Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
594397cf2ee2Smrg              func_to_host_path "$temp_rpath"
59446e7d3316Smrg	      cat <<EOF
594597cf2ee2Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5946a966c04fSmrgEOF
5947a966c04fSmrg	    else
59486e7d3316Smrg	      cat <<"EOF"
59496e7d3316Smrgconst char * LIB_PATH_VALUE   = "";
59506e7d3316SmrgEOF
5951a966c04fSmrg	    fi
59526e7d3316Smrg
59536e7d3316Smrg	    if test -n "$dllsearchpath"; then
595497cf2ee2Smrg              func_to_host_path "$dllsearchpath:"
59556e7d3316Smrg	      cat <<EOF
59566e7d3316Smrgconst char * EXE_PATH_VARNAME = "PATH";
595797cf2ee2Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
59586e7d3316SmrgEOF
5959a966c04fSmrg	    else
59606e7d3316Smrg	      cat <<"EOF"
59616e7d3316Smrgconst char * EXE_PATH_VARNAME = "";
59626e7d3316Smrgconst char * EXE_PATH_VALUE   = "";
59636e7d3316SmrgEOF
5964a966c04fSmrg	    fi
59656e7d3316Smrg
5966edce3322Smrg	    if test yes = "$fast_install"; then
59676e7d3316Smrg	      cat <<EOF
59686e7d3316Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
59696e7d3316SmrgEOF
5970a966c04fSmrg	    else
59716e7d3316Smrg	      cat <<EOF
59726e7d3316Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
59736e7d3316SmrgEOF
5974a966c04fSmrg	    fi
5975a966c04fSmrg
5976a966c04fSmrg
59776e7d3316Smrg	    cat <<"EOF"
5978a966c04fSmrg
59796e7d3316Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5980a966c04fSmrg
59816e7d3316Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
59826e7d3316Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
59836e7d3316Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5984a966c04fSmrg
59856e7d3316Smrgint
59866e7d3316Smrgmain (int argc, char *argv[])
59876e7d3316Smrg{
59886e7d3316Smrg  char **newargz;
59896e7d3316Smrg  int  newargc;
59906e7d3316Smrg  char *tmp_pathspec;
59916e7d3316Smrg  char *actual_cwrapper_path;
59926e7d3316Smrg  char *actual_cwrapper_name;
59936e7d3316Smrg  char *target_name;
59946e7d3316Smrg  char *lt_argv_zero;
5995edce3322Smrg  int rval = 127;
5996a966c04fSmrg
59976e7d3316Smrg  int i;
5998a966c04fSmrg
59996e7d3316Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000edce3322Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6001a966c04fSmrg
60026e7d3316Smrg  /* very simple arg parsing; don't want to rely on getopt
60036e7d3316Smrg   * also, copy all non cwrapper options to newargz, except
60046e7d3316Smrg   * argz[0], which is handled differently
60056e7d3316Smrg   */
60066e7d3316Smrg  newargc=0;
60076e7d3316Smrg  for (i = 1; i < argc; i++)
60086e7d3316Smrg    {
6009edce3322Smrg      if (STREQ (argv[i], dumpscript_opt))
60106e7d3316Smrg	{
60116e7d3316SmrgEOF
6012edce3322Smrg	    case $host in
60136e7d3316Smrg	      *mingw* | *cygwin* )
60146e7d3316Smrg		# make stdout use "unix" line endings
60156e7d3316Smrg		echo "          setmode(1,_O_BINARY);"
60166e7d3316Smrg		;;
60172e2dd055Smrg	      esac
6018a966c04fSmrg
60196e7d3316Smrg	    cat <<"EOF"
60206e7d3316Smrg	  lt_dump_script (stdout);
60216e7d3316Smrg	  return 0;
60226e7d3316Smrg	}
6023edce3322Smrg      if (STREQ (argv[i], debug_opt))
60246e7d3316Smrg	{
60256e7d3316Smrg          lt_debug = 1;
60266e7d3316Smrg          continue;
60276e7d3316Smrg	}
6028edce3322Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
60296e7d3316Smrg        {
60306e7d3316Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
60316e7d3316Smrg             namespace, but it is not one of the ones we know about and
60326e7d3316Smrg             have already dealt with, above (inluding dump-script), then
60336e7d3316Smrg             report an error. Otherwise, targets might begin to believe
60346e7d3316Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
60356e7d3316Smrg             namespace. The first time any user complains about this, we'll
60366e7d3316Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
60376e7d3316Smrg             or a configure.ac-settable value.
60386e7d3316Smrg           */
60396e7d3316Smrg          lt_fatal (__FILE__, __LINE__,
60406e7d3316Smrg		    "unrecognized %s option: '%s'",
60416e7d3316Smrg                    ltwrapper_option_prefix, argv[i]);
60426e7d3316Smrg        }
60436e7d3316Smrg      /* otherwise ... */
60446e7d3316Smrg      newargz[++newargc] = xstrdup (argv[i]);
60456e7d3316Smrg    }
60466e7d3316Smrg  newargz[++newargc] = NULL;
6047a966c04fSmrg
60486e7d3316SmrgEOF
60496e7d3316Smrg	    cat <<EOF
60506e7d3316Smrg  /* The GNU banner must be the first non-error debug message */
6051edce3322Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
60526e7d3316SmrgEOF
60536e7d3316Smrg	    cat <<"EOF"
60546e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
60556e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
60566e7d3316Smrg
60576e7d3316Smrg  tmp_pathspec = find_executable (argv[0]);
60586e7d3316Smrg  if (tmp_pathspec == NULL)
60596e7d3316Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
60606e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__,
60616e7d3316Smrg                  "(main) found exe (before symlink chase) at: %s\n",
60626e7d3316Smrg		  tmp_pathspec);
60636e7d3316Smrg
60646e7d3316Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
60656e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__,
60666e7d3316Smrg                  "(main) found exe (after symlink chase) at: %s\n",
60676e7d3316Smrg		  actual_cwrapper_path);
60686e7d3316Smrg  XFREE (tmp_pathspec);
60696e7d3316Smrg
60706e7d3316Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
60716e7d3316Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
60726e7d3316Smrg
60736e7d3316Smrg  /* wrapper name transforms */
60746e7d3316Smrg  strendzap (actual_cwrapper_name, ".exe");
60756e7d3316Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
60766e7d3316Smrg  XFREE (actual_cwrapper_name);
60776e7d3316Smrg  actual_cwrapper_name = tmp_pathspec;
60786e7d3316Smrg  tmp_pathspec = 0;
60796e7d3316Smrg
60806e7d3316Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
60816e7d3316Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
60826e7d3316Smrg  strendzap (target_name, ".exe");
60836e7d3316Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
60846e7d3316Smrg  XFREE (target_name);
60856e7d3316Smrg  target_name = tmp_pathspec;
60866e7d3316Smrg  tmp_pathspec = 0;
60876e7d3316Smrg
60886e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__,
60896e7d3316Smrg		  "(main) libtool target name: %s\n",
60906e7d3316Smrg		  target_name);
60916e7d3316SmrgEOF
6092a966c04fSmrg
60936e7d3316Smrg	    cat <<EOF
60946e7d3316Smrg  newargz[0] =
60956e7d3316Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
60966e7d3316Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
60976e7d3316Smrg  strcpy (newargz[0], actual_cwrapper_path);
60986e7d3316Smrg  strcat (newargz[0], "$objdir");
60996e7d3316Smrg  strcat (newargz[0], "/");
61006e7d3316SmrgEOF
6101a966c04fSmrg
61026e7d3316Smrg	    cat <<"EOF"
61036e7d3316Smrg  /* stop here, and copy so we don't have to do this twice */
61046e7d3316Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105a966c04fSmrg
61066e7d3316Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
61076e7d3316Smrg  strcat (newargz[0], actual_cwrapper_name);
6108a966c04fSmrg
61096e7d3316Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
61106e7d3316Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
61116e7d3316Smrg  XFREE (tmp_pathspec);
61126e7d3316Smrg  tmp_pathspec = NULL;
61136e7d3316SmrgEOF
6114a966c04fSmrg
61156e7d3316Smrg	    case $host_os in
61166e7d3316Smrg	      mingw*)
61176e7d3316Smrg	    cat <<"EOF"
61186e7d3316Smrg  {
61196e7d3316Smrg    char* p;
61206e7d3316Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
61216e7d3316Smrg      {
61226e7d3316Smrg	*p = '/';
61236e7d3316Smrg      }
61246e7d3316Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
61256e7d3316Smrg      {
61266e7d3316Smrg	*p = '/';
61276e7d3316Smrg      }
61286e7d3316Smrg  }
61296e7d3316SmrgEOF
61306e7d3316Smrg	    ;;
61316e7d3316Smrg	    esac
6132a966c04fSmrg
61336e7d3316Smrg	    cat <<"EOF"
61346e7d3316Smrg  XFREE (target_name);
61356e7d3316Smrg  XFREE (actual_cwrapper_path);
61366e7d3316Smrg  XFREE (actual_cwrapper_name);
6137a966c04fSmrg
61386e7d3316Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
61396e7d3316Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
614097cf2ee2Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
614197cf2ee2Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
614297cf2ee2Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
614397cf2ee2Smrg     libraries must come first. */
61446e7d3316Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
614597cf2ee2Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6146a966c04fSmrg
61476e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
61486e7d3316Smrg		  nonnull (lt_argv_zero));
61496e7d3316Smrg  for (i = 0; i < newargc; i++)
61506e7d3316Smrg    {
61516e7d3316Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
61526e7d3316Smrg		      i, nonnull (newargz[i]));
61536e7d3316Smrg    }
6154a966c04fSmrg
61556e7d3316SmrgEOF
6156a966c04fSmrg
61576e7d3316Smrg	    case $host_os in
61586e7d3316Smrg	      mingw*)
61596e7d3316Smrg		cat <<"EOF"
61606e7d3316Smrg  /* execv doesn't actually work on mingw as expected on unix */
61616e7d3316Smrg  newargz = prepare_spawn (newargz);
6162edce3322Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
61636e7d3316Smrg  if (rval == -1)
61646e7d3316Smrg    {
61656e7d3316Smrg      /* failed to start process */
61666e7d3316Smrg      lt_debugprintf (__FILE__, __LINE__,
61676e7d3316Smrg		      "(main) failed to launch target \"%s\": %s\n",
61686e7d3316Smrg		      lt_argv_zero, nonnull (strerror (errno)));
61696e7d3316Smrg      return 127;
61706e7d3316Smrg    }
61716e7d3316Smrg  return rval;
61726e7d3316SmrgEOF
61736e7d3316Smrg		;;
61746e7d3316Smrg	      *)
61756e7d3316Smrg		cat <<"EOF"
61766e7d3316Smrg  execv (lt_argv_zero, newargz);
61776e7d3316Smrg  return rval; /* =127, but avoids unused variable warning */
61786e7d3316SmrgEOF
61796e7d3316Smrg		;;
61806e7d3316Smrg	    esac
6181a966c04fSmrg
61826e7d3316Smrg	    cat <<"EOF"
61836e7d3316Smrg}
6184a966c04fSmrg
61856e7d3316Smrgvoid *
61866e7d3316Smrgxmalloc (size_t num)
61876e7d3316Smrg{
61886e7d3316Smrg  void *p = (void *) malloc (num);
61896e7d3316Smrg  if (!p)
61906e7d3316Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6191a966c04fSmrg
61926e7d3316Smrg  return p;
61936e7d3316Smrg}
6194a966c04fSmrg
61956e7d3316Smrgchar *
61966e7d3316Smrgxstrdup (const char *string)
61976e7d3316Smrg{
61986e7d3316Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
61996e7d3316Smrg			  string) : NULL;
62006e7d3316Smrg}
6201a966c04fSmrg
62026e7d3316Smrgconst char *
62036e7d3316Smrgbase_name (const char *name)
62046e7d3316Smrg{
62056e7d3316Smrg  const char *base;
6206a966c04fSmrg
6207edce3322Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62086e7d3316Smrg  /* Skip over the disk name in MSDOS pathnames. */
62096e7d3316Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
62106e7d3316Smrg    name += 2;
62116e7d3316Smrg#endif
6212a966c04fSmrg
62136e7d3316Smrg  for (base = name; *name; name++)
62146e7d3316Smrg    if (IS_DIR_SEPARATOR (*name))
62156e7d3316Smrg      base = name + 1;
62166e7d3316Smrg  return base;
62176e7d3316Smrg}
6218a966c04fSmrg
62196e7d3316Smrgint
62206e7d3316Smrgcheck_executable (const char *path)
62216e7d3316Smrg{
62226e7d3316Smrg  struct stat st;
6223a966c04fSmrg
62246e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
62256e7d3316Smrg                  nonempty (path));
62266e7d3316Smrg  if ((!path) || (!*path))
62276e7d3316Smrg    return 0;
6228a966c04fSmrg
62296e7d3316Smrg  if ((stat (path, &st) >= 0)
62306e7d3316Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
62316e7d3316Smrg    return 1;
62326e7d3316Smrg  else
62336e7d3316Smrg    return 0;
62346e7d3316Smrg}
6235a966c04fSmrg
62366e7d3316Smrgint
62376e7d3316Smrgmake_executable (const char *path)
62386e7d3316Smrg{
62396e7d3316Smrg  int rval = 0;
62406e7d3316Smrg  struct stat st;
6241a966c04fSmrg
62426e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
62436e7d3316Smrg                  nonempty (path));
62446e7d3316Smrg  if ((!path) || (!*path))
62456e7d3316Smrg    return 0;
6246a966c04fSmrg
62476e7d3316Smrg  if (stat (path, &st) >= 0)
62486e7d3316Smrg    {
62496e7d3316Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
62506e7d3316Smrg    }
62516e7d3316Smrg  return rval;
62526e7d3316Smrg}
6253a966c04fSmrg
62546e7d3316Smrg/* Searches for the full path of the wrapper.  Returns
62556e7d3316Smrg   newly allocated full path name if found, NULL otherwise
62566e7d3316Smrg   Does not chase symlinks, even on platforms that support them.
62576e7d3316Smrg*/
62586e7d3316Smrgchar *
62596e7d3316Smrgfind_executable (const char *wrapper)
62606e7d3316Smrg{
62616e7d3316Smrg  int has_slash = 0;
62626e7d3316Smrg  const char *p;
62636e7d3316Smrg  const char *p_next;
62646e7d3316Smrg  /* static buffer for getcwd */
62656e7d3316Smrg  char tmp[LT_PATHMAX + 1];
6266edce3322Smrg  size_t tmp_len;
62676e7d3316Smrg  char *concat_name;
6268a966c04fSmrg
62696e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
62706e7d3316Smrg                  nonempty (wrapper));
6271a966c04fSmrg
62726e7d3316Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
62736e7d3316Smrg    return NULL;
6274a966c04fSmrg
62756e7d3316Smrg  /* Absolute path? */
6276edce3322Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62776e7d3316Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
62786e7d3316Smrg    {
62796e7d3316Smrg      concat_name = xstrdup (wrapper);
62806e7d3316Smrg      if (check_executable (concat_name))
62816e7d3316Smrg	return concat_name;
62826e7d3316Smrg      XFREE (concat_name);
62836e7d3316Smrg    }
62846e7d3316Smrg  else
62856e7d3316Smrg    {
62866e7d3316Smrg#endif
62876e7d3316Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
62886e7d3316Smrg	{
62896e7d3316Smrg	  concat_name = xstrdup (wrapper);
62906e7d3316Smrg	  if (check_executable (concat_name))
62916e7d3316Smrg	    return concat_name;
62926e7d3316Smrg	  XFREE (concat_name);
62936e7d3316Smrg	}
6294edce3322Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62956e7d3316Smrg    }
62966e7d3316Smrg#endif
6297a966c04fSmrg
62986e7d3316Smrg  for (p = wrapper; *p; p++)
62996e7d3316Smrg    if (*p == '/')
63006e7d3316Smrg      {
63016e7d3316Smrg	has_slash = 1;
63026e7d3316Smrg	break;
63036e7d3316Smrg      }
63046e7d3316Smrg  if (!has_slash)
63056e7d3316Smrg    {
63066e7d3316Smrg      /* no slashes; search PATH */
63076e7d3316Smrg      const char *path = getenv ("PATH");
63086e7d3316Smrg      if (path != NULL)
63096e7d3316Smrg	{
63106e7d3316Smrg	  for (p = path; *p; p = p_next)
63116e7d3316Smrg	    {
63126e7d3316Smrg	      const char *q;
63136e7d3316Smrg	      size_t p_len;
63146e7d3316Smrg	      for (q = p; *q; q++)
63156e7d3316Smrg		if (IS_PATH_SEPARATOR (*q))
63166e7d3316Smrg		  break;
6317edce3322Smrg	      p_len = (size_t) (q - p);
63186e7d3316Smrg	      p_next = (*q == '\0' ? q : q + 1);
63196e7d3316Smrg	      if (p_len == 0)
63206e7d3316Smrg		{
63216e7d3316Smrg		  /* empty path: current directory */
63226e7d3316Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
63236e7d3316Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63246e7d3316Smrg                              nonnull (strerror (errno)));
63256e7d3316Smrg		  tmp_len = strlen (tmp);
63266e7d3316Smrg		  concat_name =
63276e7d3316Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63286e7d3316Smrg		  memcpy (concat_name, tmp, tmp_len);
63296e7d3316Smrg		  concat_name[tmp_len] = '/';
63306e7d3316Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
63316e7d3316Smrg		}
63326e7d3316Smrg	      else
63336e7d3316Smrg		{
63346e7d3316Smrg		  concat_name =
63356e7d3316Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
63366e7d3316Smrg		  memcpy (concat_name, p, p_len);
63376e7d3316Smrg		  concat_name[p_len] = '/';
63386e7d3316Smrg		  strcpy (concat_name + p_len + 1, wrapper);
63396e7d3316Smrg		}
63406e7d3316Smrg	      if (check_executable (concat_name))
63416e7d3316Smrg		return concat_name;
63426e7d3316Smrg	      XFREE (concat_name);
63436e7d3316Smrg	    }
63446e7d3316Smrg	}
63456e7d3316Smrg      /* not found in PATH; assume curdir */
63466e7d3316Smrg    }
63476e7d3316Smrg  /* Relative path | not found in path: prepend cwd */
63486e7d3316Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
63496e7d3316Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
63506e7d3316Smrg              nonnull (strerror (errno)));
63516e7d3316Smrg  tmp_len = strlen (tmp);
63526e7d3316Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63536e7d3316Smrg  memcpy (concat_name, tmp, tmp_len);
63546e7d3316Smrg  concat_name[tmp_len] = '/';
63556e7d3316Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6356a966c04fSmrg
63576e7d3316Smrg  if (check_executable (concat_name))
63586e7d3316Smrg    return concat_name;
63596e7d3316Smrg  XFREE (concat_name);
63606e7d3316Smrg  return NULL;
63616e7d3316Smrg}
6362a966c04fSmrg
63636e7d3316Smrgchar *
63646e7d3316Smrgchase_symlinks (const char *pathspec)
63656e7d3316Smrg{
63666e7d3316Smrg#ifndef S_ISLNK
63676e7d3316Smrg  return xstrdup (pathspec);
63686e7d3316Smrg#else
63696e7d3316Smrg  char buf[LT_PATHMAX];
63706e7d3316Smrg  struct stat s;
63716e7d3316Smrg  char *tmp_pathspec = xstrdup (pathspec);
63726e7d3316Smrg  char *p;
63736e7d3316Smrg  int has_symlinks = 0;
63746e7d3316Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
63756e7d3316Smrg    {
63766e7d3316Smrg      lt_debugprintf (__FILE__, __LINE__,
63776e7d3316Smrg		      "checking path component for symlinks: %s\n",
63786e7d3316Smrg		      tmp_pathspec);
63796e7d3316Smrg      if (lstat (tmp_pathspec, &s) == 0)
63806e7d3316Smrg	{
63816e7d3316Smrg	  if (S_ISLNK (s.st_mode) != 0)
63826e7d3316Smrg	    {
63836e7d3316Smrg	      has_symlinks = 1;
63846e7d3316Smrg	      break;
63856e7d3316Smrg	    }
6386a966c04fSmrg
63876e7d3316Smrg	  /* search backwards for last DIR_SEPARATOR */
63886e7d3316Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
63896e7d3316Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63906e7d3316Smrg	    p--;
63916e7d3316Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63926e7d3316Smrg	    {
63936e7d3316Smrg	      /* no more DIR_SEPARATORS left */
63946e7d3316Smrg	      break;
63956e7d3316Smrg	    }
63966e7d3316Smrg	  *p = '\0';
63976e7d3316Smrg	}
63986e7d3316Smrg      else
63996e7d3316Smrg	{
64006e7d3316Smrg	  lt_fatal (__FILE__, __LINE__,
64016e7d3316Smrg		    "error accessing file \"%s\": %s",
64026e7d3316Smrg		    tmp_pathspec, nonnull (strerror (errno)));
64036e7d3316Smrg	}
64046e7d3316Smrg    }
64056e7d3316Smrg  XFREE (tmp_pathspec);
6406a966c04fSmrg
64076e7d3316Smrg  if (!has_symlinks)
64086e7d3316Smrg    {
64096e7d3316Smrg      return xstrdup (pathspec);
64106e7d3316Smrg    }
6411a966c04fSmrg
64126e7d3316Smrg  tmp_pathspec = realpath (pathspec, buf);
64136e7d3316Smrg  if (tmp_pathspec == 0)
64146e7d3316Smrg    {
64156e7d3316Smrg      lt_fatal (__FILE__, __LINE__,
64166e7d3316Smrg		"could not follow symlinks for %s", pathspec);
64176e7d3316Smrg    }
64186e7d3316Smrg  return xstrdup (tmp_pathspec);
64196e7d3316Smrg#endif
64206e7d3316Smrg}
6421a966c04fSmrg
64226e7d3316Smrgchar *
64236e7d3316Smrgstrendzap (char *str, const char *pat)
64246e7d3316Smrg{
64256e7d3316Smrg  size_t len, patlen;
6426a966c04fSmrg
64276e7d3316Smrg  assert (str != NULL);
64286e7d3316Smrg  assert (pat != NULL);
6429a966c04fSmrg
64306e7d3316Smrg  len = strlen (str);
64316e7d3316Smrg  patlen = strlen (pat);
6432a966c04fSmrg
64336e7d3316Smrg  if (patlen <= len)
64346e7d3316Smrg    {
64356e7d3316Smrg      str += len - patlen;
6436edce3322Smrg      if (STREQ (str, pat))
64376e7d3316Smrg	*str = '\0';
64386e7d3316Smrg    }
64396e7d3316Smrg  return str;
64406e7d3316Smrg}
6441a966c04fSmrg
64426e7d3316Smrgvoid
64436e7d3316Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
64446e7d3316Smrg{
64456e7d3316Smrg  va_list args;
64466e7d3316Smrg  if (lt_debug)
64476e7d3316Smrg    {
64486e7d3316Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
64496e7d3316Smrg      va_start (args, fmt);
64506e7d3316Smrg      (void) vfprintf (stderr, fmt, args);
64516e7d3316Smrg      va_end (args);
64526e7d3316Smrg    }
64536e7d3316Smrg}
6454a966c04fSmrg
64556e7d3316Smrgstatic void
64566e7d3316Smrglt_error_core (int exit_status, const char *file,
64576e7d3316Smrg	       int line, const char *mode,
64586e7d3316Smrg	       const char *message, va_list ap)
64596e7d3316Smrg{
64606e7d3316Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
64616e7d3316Smrg  vfprintf (stderr, message, ap);
64626e7d3316Smrg  fprintf (stderr, ".\n");
6463a966c04fSmrg
64646e7d3316Smrg  if (exit_status >= 0)
64656e7d3316Smrg    exit (exit_status);
64666e7d3316Smrg}
6467a966c04fSmrg
64686e7d3316Smrgvoid
64696e7d3316Smrglt_fatal (const char *file, int line, const char *message, ...)
64706e7d3316Smrg{
64716e7d3316Smrg  va_list ap;
64726e7d3316Smrg  va_start (ap, message);
64736e7d3316Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
64746e7d3316Smrg  va_end (ap);
64756e7d3316Smrg}
6476a966c04fSmrg
64776e7d3316Smrgstatic const char *
64786e7d3316Smrgnonnull (const char *s)
64796e7d3316Smrg{
64806e7d3316Smrg  return s ? s : "(null)";
64816e7d3316Smrg}
6482a966c04fSmrg
64836e7d3316Smrgstatic const char *
64846e7d3316Smrgnonempty (const char *s)
64856e7d3316Smrg{
64866e7d3316Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
64876e7d3316Smrg}
6488a966c04fSmrg
64896e7d3316Smrgvoid
64906e7d3316Smrglt_setenv (const char *name, const char *value)
64916e7d3316Smrg{
64926e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__,
64936e7d3316Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
64946e7d3316Smrg                  nonnull (name), nonnull (value));
64956e7d3316Smrg  {
64966e7d3316Smrg#ifdef HAVE_SETENV
64976e7d3316Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
64986e7d3316Smrg    char *str = xstrdup (value);
64996e7d3316Smrg    setenv (name, str, 1);
65006e7d3316Smrg#else
6501edce3322Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
65026e7d3316Smrg    char *str = XMALLOC (char, len);
65036e7d3316Smrg    sprintf (str, "%s=%s", name, value);
65046e7d3316Smrg    if (putenv (str) != EXIT_SUCCESS)
65056e7d3316Smrg      {
65066e7d3316Smrg        XFREE (str);
65076e7d3316Smrg      }
65086e7d3316Smrg#endif
65096e7d3316Smrg  }
65106e7d3316Smrg}
6511a966c04fSmrg
65126e7d3316Smrgchar *
65136e7d3316Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
65146e7d3316Smrg{
65156e7d3316Smrg  char *new_value;
65166e7d3316Smrg  if (orig_value && *orig_value)
65176e7d3316Smrg    {
6518edce3322Smrg      size_t orig_value_len = strlen (orig_value);
6519edce3322Smrg      size_t add_len = strlen (add);
65206e7d3316Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
65216e7d3316Smrg      if (to_end)
65226e7d3316Smrg        {
65236e7d3316Smrg          strcpy (new_value, orig_value);
65246e7d3316Smrg          strcpy (new_value + orig_value_len, add);
65256e7d3316Smrg        }
65266e7d3316Smrg      else
65276e7d3316Smrg        {
65286e7d3316Smrg          strcpy (new_value, add);
65296e7d3316Smrg          strcpy (new_value + add_len, orig_value);
65306e7d3316Smrg        }
65316e7d3316Smrg    }
65326e7d3316Smrg  else
65336e7d3316Smrg    {
65346e7d3316Smrg      new_value = xstrdup (add);
65356e7d3316Smrg    }
65366e7d3316Smrg  return new_value;
65376e7d3316Smrg}
6538a966c04fSmrg
65396e7d3316Smrgvoid
65406e7d3316Smrglt_update_exe_path (const char *name, const char *value)
65416e7d3316Smrg{
65426e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__,
65436e7d3316Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
65446e7d3316Smrg                  nonnull (name), nonnull (value));
6545a966c04fSmrg
65466e7d3316Smrg  if (name && *name && value && *value)
65476e7d3316Smrg    {
65486e7d3316Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65496e7d3316Smrg      /* some systems can't cope with a ':'-terminated path #' */
6550edce3322Smrg      size_t len = strlen (new_value);
6551edce3322Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
65526e7d3316Smrg        {
6553edce3322Smrg          new_value[--len] = '\0';
65546e7d3316Smrg        }
65556e7d3316Smrg      lt_setenv (name, new_value);
65566e7d3316Smrg      XFREE (new_value);
65576e7d3316Smrg    }
65586e7d3316Smrg}
6559a966c04fSmrg
65606e7d3316Smrgvoid
65616e7d3316Smrglt_update_lib_path (const char *name, const char *value)
65626e7d3316Smrg{
65636e7d3316Smrg  lt_debugprintf (__FILE__, __LINE__,
65646e7d3316Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
65656e7d3316Smrg                  nonnull (name), nonnull (value));
6566a966c04fSmrg
65676e7d3316Smrg  if (name && *name && value && *value)
65686e7d3316Smrg    {
65696e7d3316Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65706e7d3316Smrg      lt_setenv (name, new_value);
65716e7d3316Smrg      XFREE (new_value);
65726e7d3316Smrg    }
65736e7d3316Smrg}
6574a966c04fSmrg
65756e7d3316SmrgEOF
65766e7d3316Smrg	    case $host_os in
65776e7d3316Smrg	      mingw*)
65786e7d3316Smrg		cat <<"EOF"
65796e7d3316Smrg
65806e7d3316Smrg/* Prepares an argument vector before calling spawn().
65816e7d3316Smrg   Note that spawn() does not by itself call the command interpreter
65826e7d3316Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
65836e7d3316Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
65846e7d3316Smrg         GetVersionEx(&v);
65856e7d3316Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
65866e7d3316Smrg      }) ? "cmd.exe" : "command.com").
65876e7d3316Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
65886e7d3316Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
65896e7d3316Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
65906e7d3316Smrg   special way:
65916e7d3316Smrg   - Space and tab are interpreted as delimiters. They are not treated as
65926e7d3316Smrg     delimiters if they are surrounded by double quotes: "...".
65936e7d3316Smrg   - Unescaped double quotes are removed from the input. Their only effect is
65946e7d3316Smrg     that within double quotes, space and tab are treated like normal
65956e7d3316Smrg     characters.
65966e7d3316Smrg   - Backslashes not followed by double quotes are not special.
65976e7d3316Smrg   - But 2*n+1 backslashes followed by a double quote become
65986e7d3316Smrg     n backslashes followed by a double quote (n >= 0):
65996e7d3316Smrg       \" -> "
66006e7d3316Smrg       \\\" -> \"
66016e7d3316Smrg       \\\\\" -> \\"
66026e7d3316Smrg */
66036e7d3316Smrg#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"
66046e7d3316Smrg#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"
66056e7d3316Smrgchar **
66066e7d3316Smrgprepare_spawn (char **argv)
66076e7d3316Smrg{
66086e7d3316Smrg  size_t argc;
66096e7d3316Smrg  char **new_argv;
66106e7d3316Smrg  size_t i;
6611a966c04fSmrg
66126e7d3316Smrg  /* Count number of arguments.  */
66136e7d3316Smrg  for (argc = 0; argv[argc] != NULL; argc++)
66146e7d3316Smrg    ;
6615a966c04fSmrg
66166e7d3316Smrg  /* Allocate new argument vector.  */
66176e7d3316Smrg  new_argv = XMALLOC (char *, argc + 1);
6618a966c04fSmrg
66196e7d3316Smrg  /* Put quoted arguments into the new argument vector.  */
66206e7d3316Smrg  for (i = 0; i < argc; i++)
66216e7d3316Smrg    {
66226e7d3316Smrg      const char *string = argv[i];
66236e7d3316Smrg
66246e7d3316Smrg      if (string[0] == '\0')
66256e7d3316Smrg	new_argv[i] = xstrdup ("\"\"");
66266e7d3316Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
66276e7d3316Smrg	{
66286e7d3316Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
66296e7d3316Smrg	  size_t length;
66306e7d3316Smrg	  unsigned int backslashes;
66316e7d3316Smrg	  const char *s;
66326e7d3316Smrg	  char *quoted_string;
66336e7d3316Smrg	  char *p;
66346e7d3316Smrg
66356e7d3316Smrg	  length = 0;
66366e7d3316Smrg	  backslashes = 0;
66376e7d3316Smrg	  if (quote_around)
66386e7d3316Smrg	    length++;
66396e7d3316Smrg	  for (s = string; *s != '\0'; s++)
66406e7d3316Smrg	    {
66416e7d3316Smrg	      char c = *s;
66426e7d3316Smrg	      if (c == '"')
66436e7d3316Smrg		length += backslashes + 1;
66446e7d3316Smrg	      length++;
66456e7d3316Smrg	      if (c == '\\')
66466e7d3316Smrg		backslashes++;
66476e7d3316Smrg	      else
66486e7d3316Smrg		backslashes = 0;
66496e7d3316Smrg	    }
66506e7d3316Smrg	  if (quote_around)
66516e7d3316Smrg	    length += backslashes + 1;
66526e7d3316Smrg
66536e7d3316Smrg	  quoted_string = XMALLOC (char, length + 1);
66546e7d3316Smrg
66556e7d3316Smrg	  p = quoted_string;
66566e7d3316Smrg	  backslashes = 0;
66576e7d3316Smrg	  if (quote_around)
66586e7d3316Smrg	    *p++ = '"';
66596e7d3316Smrg	  for (s = string; *s != '\0'; s++)
66606e7d3316Smrg	    {
66616e7d3316Smrg	      char c = *s;
66626e7d3316Smrg	      if (c == '"')
66636e7d3316Smrg		{
66646e7d3316Smrg		  unsigned int j;
66656e7d3316Smrg		  for (j = backslashes + 1; j > 0; j--)
66666e7d3316Smrg		    *p++ = '\\';
66676e7d3316Smrg		}
66686e7d3316Smrg	      *p++ = c;
66696e7d3316Smrg	      if (c == '\\')
66706e7d3316Smrg		backslashes++;
66716e7d3316Smrg	      else
66726e7d3316Smrg		backslashes = 0;
66736e7d3316Smrg	    }
66746e7d3316Smrg	  if (quote_around)
66756e7d3316Smrg	    {
66766e7d3316Smrg	      unsigned int j;
66776e7d3316Smrg	      for (j = backslashes; j > 0; j--)
66786e7d3316Smrg		*p++ = '\\';
66796e7d3316Smrg	      *p++ = '"';
66806e7d3316Smrg	    }
66816e7d3316Smrg	  *p = '\0';
6682a966c04fSmrg
66836e7d3316Smrg	  new_argv[i] = quoted_string;
66846e7d3316Smrg	}
66856e7d3316Smrg      else
66866e7d3316Smrg	new_argv[i] = (char *) string;
66876e7d3316Smrg    }
66886e7d3316Smrg  new_argv[argc] = NULL;
6689a966c04fSmrg
66906e7d3316Smrg  return new_argv;
66916e7d3316Smrg}
66926e7d3316SmrgEOF
6693a966c04fSmrg		;;
66946e7d3316Smrg	    esac
6695a966c04fSmrg
66966e7d3316Smrg            cat <<"EOF"
66976e7d3316Smrgvoid lt_dump_script (FILE* f)
66986e7d3316Smrg{
66996e7d3316SmrgEOF
67006e7d3316Smrg	    func_emit_wrapper yes |
6701ac92798bSmrg	      $SED -n -e '
6702ac92798bSmrgs/^\(.\{79\}\)\(..*\)/\1\
6703ac92798bSmrg\2/
6704ac92798bSmrgh
6705ac92798bSmrgs/\([\\"]\)/\\\1/g
6706ac92798bSmrgs/$/\\n/
6707ac92798bSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708ac92798bSmrgg
6709ac92798bSmrgD'
67106e7d3316Smrg            cat <<"EOF"
67116e7d3316Smrg}
67126e7d3316SmrgEOF
67136e7d3316Smrg}
67146e7d3316Smrg# end: func_emit_cwrapperexe_src
6715a966c04fSmrg
67166e7d3316Smrg# func_win32_import_lib_p ARG
67176e7d3316Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
67186e7d3316Smrgfunc_win32_import_lib_p ()
67196e7d3316Smrg{
6720edce3322Smrg    $debug_cmd
6721edce3322Smrg
67226e7d3316Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
67236e7d3316Smrg    *import*) : ;;
67246e7d3316Smrg    *) false ;;
67256e7d3316Smrg    esac
67266e7d3316Smrg}
6727a966c04fSmrg
6728edce3322Smrg# func_suncc_cstd_abi
6729edce3322Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730edce3322Smrg# Several compiler flags select an ABI that is incompatible with the
6731edce3322Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732edce3322Smrgfunc_suncc_cstd_abi ()
6733edce3322Smrg{
6734edce3322Smrg    $debug_cmd
6735edce3322Smrg
6736edce3322Smrg    case " $compile_command " in
6737edce3322Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738edce3322Smrg      suncc_use_cstd_abi=no
6739edce3322Smrg      ;;
6740edce3322Smrg    *)
6741edce3322Smrg      suncc_use_cstd_abi=yes
6742edce3322Smrg      ;;
6743edce3322Smrg    esac
6744edce3322Smrg}
6745edce3322Smrg
67466e7d3316Smrg# func_mode_link arg...
67476e7d3316Smrgfunc_mode_link ()
67486e7d3316Smrg{
6749edce3322Smrg    $debug_cmd
6750edce3322Smrg
67516e7d3316Smrg    case $host in
67526e7d3316Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
67536e7d3316Smrg      # It is impossible to link a dll without this setting, and
67546e7d3316Smrg      # we shouldn't force the makefile maintainer to figure out
6755edce3322Smrg      # what system we are compiling for in order to pass an extra
67566e7d3316Smrg      # flag for every libtool invocation.
67576e7d3316Smrg      # allow_undefined=no
6758a966c04fSmrg
67596e7d3316Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6760edce3322Smrg      # to make a dll that has undefined symbols, in which case not
67616e7d3316Smrg      # even a static library is built.  For now, we need to specify
67626e7d3316Smrg      # -no-undefined on the libtool link line when we can be certain
67636e7d3316Smrg      # that all symbols are satisfied, otherwise we get a static library.
67646e7d3316Smrg      allow_undefined=yes
67656e7d3316Smrg      ;;
67666e7d3316Smrg    *)
67676e7d3316Smrg      allow_undefined=yes
67686e7d3316Smrg      ;;
67696e7d3316Smrg    esac
67706e7d3316Smrg    libtool_args=$nonopt
67716e7d3316Smrg    base_compile="$nonopt $@"
67726e7d3316Smrg    compile_command=$nonopt
67736e7d3316Smrg    finalize_command=$nonopt
6774a966c04fSmrg
67756e7d3316Smrg    compile_rpath=
67766e7d3316Smrg    finalize_rpath=
67776e7d3316Smrg    compile_shlibpath=
67786e7d3316Smrg    finalize_shlibpath=
67796e7d3316Smrg    convenience=
67806e7d3316Smrg    old_convenience=
67816e7d3316Smrg    deplibs=
67826e7d3316Smrg    old_deplibs=
67836e7d3316Smrg    compiler_flags=
67846e7d3316Smrg    linker_flags=
67856e7d3316Smrg    dllsearchpath=
67866e7d3316Smrg    lib_search_path=`pwd`
67876e7d3316Smrg    inst_prefix_dir=
67886e7d3316Smrg    new_inherited_linker_flags=
6789a966c04fSmrg
67906e7d3316Smrg    avoid_version=no
67916e7d3316Smrg    bindir=
67926e7d3316Smrg    dlfiles=
67936e7d3316Smrg    dlprefiles=
67946e7d3316Smrg    dlself=no
67956e7d3316Smrg    export_dynamic=no
67966e7d3316Smrg    export_symbols=
67976e7d3316Smrg    export_symbols_regex=
67986e7d3316Smrg    generated=
67996e7d3316Smrg    libobjs=
68006e7d3316Smrg    ltlibs=
68016e7d3316Smrg    module=no
68026e7d3316Smrg    no_install=no
68036e7d3316Smrg    objs=
6804edce3322Smrg    os2dllname=
68056e7d3316Smrg    non_pic_objects=
68066e7d3316Smrg    precious_files_regex=
68076e7d3316Smrg    prefer_static_libs=no
6808edce3322Smrg    preload=false
68096e7d3316Smrg    prev=
68106e7d3316Smrg    prevarg=
68116e7d3316Smrg    release=
68126e7d3316Smrg    rpath=
68136e7d3316Smrg    xrpath=
68146e7d3316Smrg    perm_rpath=
68156e7d3316Smrg    temp_rpath=
68166e7d3316Smrg    thread_safe=no
68176e7d3316Smrg    vinfo=
68186e7d3316Smrg    vinfo_number=no
68196e7d3316Smrg    weak_libs=
6820edce3322Smrg    single_module=$wl-single_module
68216e7d3316Smrg    func_infer_tag $base_compile
6822a966c04fSmrg
68236e7d3316Smrg    # We need to know -static, to get the right output filenames.
68246e7d3316Smrg    for arg
68256e7d3316Smrg    do
68266e7d3316Smrg      case $arg in
68276e7d3316Smrg      -shared)
6828edce3322Smrg	test yes != "$build_libtool_libs" \
6829edce3322Smrg	  && func_fatal_configuration "cannot build a shared library"
68306e7d3316Smrg	build_old_libs=no
68316e7d3316Smrg	break
68326e7d3316Smrg	;;
68336e7d3316Smrg      -all-static | -static | -static-libtool-libs)
68346e7d3316Smrg	case $arg in
68356e7d3316Smrg	-all-static)
6836edce3322Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
68376e7d3316Smrg	    func_warning "complete static linking is impossible in this configuration"
68386e7d3316Smrg	  fi
68396e7d3316Smrg	  if test -n "$link_static_flag"; then
68406e7d3316Smrg	    dlopen_self=$dlopen_self_static
68416e7d3316Smrg	  fi
68426e7d3316Smrg	  prefer_static_libs=yes
68436e7d3316Smrg	  ;;
68446e7d3316Smrg	-static)
68456e7d3316Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68466e7d3316Smrg	    dlopen_self=$dlopen_self_static
68476e7d3316Smrg	  fi
68486e7d3316Smrg	  prefer_static_libs=built
68496e7d3316Smrg	  ;;
68506e7d3316Smrg	-static-libtool-libs)
68516e7d3316Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68526e7d3316Smrg	    dlopen_self=$dlopen_self_static
68536e7d3316Smrg	  fi
68546e7d3316Smrg	  prefer_static_libs=yes
68556e7d3316Smrg	  ;;
68566e7d3316Smrg	esac
68576e7d3316Smrg	build_libtool_libs=no
68586e7d3316Smrg	build_old_libs=yes
68596e7d3316Smrg	break
68606e7d3316Smrg	;;
68616e7d3316Smrg      esac
68626e7d3316Smrg    done
6863a966c04fSmrg
68646e7d3316Smrg    # See if our shared archives depend on static archives.
68656e7d3316Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6866a966c04fSmrg
68676e7d3316Smrg    # Go through the arguments, transforming them on the way.
68686e7d3316Smrg    while test "$#" -gt 0; do
6869edce3322Smrg      arg=$1
68706e7d3316Smrg      shift
687174835918Smrg      func_quote_arg pretty,unquoted "$arg"
687274835918Smrg      qarg=$func_quote_arg_unquoted_result
687374835918Smrg      func_append libtool_args " $func_quote_arg_result"
6874a966c04fSmrg
68756e7d3316Smrg      # If the previous option needs an argument, assign it.
68766e7d3316Smrg      if test -n "$prev"; then
68776e7d3316Smrg	case $prev in
68786e7d3316Smrg	output)
68796e7d3316Smrg	  func_append compile_command " @OUTPUT@"
68806e7d3316Smrg	  func_append finalize_command " @OUTPUT@"
68816e7d3316Smrg	  ;;
68826e7d3316Smrg	esac
6883a966c04fSmrg
68846e7d3316Smrg	case $prev in
68856e7d3316Smrg	bindir)
6886edce3322Smrg	  bindir=$arg
68876e7d3316Smrg	  prev=
68886e7d3316Smrg	  continue
68896e7d3316Smrg	  ;;
68906e7d3316Smrg	dlfiles|dlprefiles)
6891edce3322Smrg	  $preload || {
68926e7d3316Smrg	    # Add the symbol object into the linking commands.
68936e7d3316Smrg	    func_append compile_command " @SYMFILE@"
68946e7d3316Smrg	    func_append finalize_command " @SYMFILE@"
6895edce3322Smrg	    preload=:
6896edce3322Smrg	  }
68976e7d3316Smrg	  case $arg in
68986e7d3316Smrg	  *.la | *.lo) ;;  # We handle these cases below.
68996e7d3316Smrg	  force)
6900edce3322Smrg	    if test no = "$dlself"; then
69016e7d3316Smrg	      dlself=needless
69026e7d3316Smrg	      export_dynamic=yes
6903a966c04fSmrg	    fi
69046e7d3316Smrg	    prev=
69056e7d3316Smrg	    continue
69066e7d3316Smrg	    ;;
69076e7d3316Smrg	  self)
6908edce3322Smrg	    if test dlprefiles = "$prev"; then
69096e7d3316Smrg	      dlself=yes
6910edce3322Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
69116e7d3316Smrg	      dlself=yes
6912a966c04fSmrg	    else
69136e7d3316Smrg	      dlself=needless
69146e7d3316Smrg	      export_dynamic=yes
6915a966c04fSmrg	    fi
69166e7d3316Smrg	    prev=
69176e7d3316Smrg	    continue
69186e7d3316Smrg	    ;;
69196e7d3316Smrg	  *)
6920edce3322Smrg	    if test dlfiles = "$prev"; then
692197cf2ee2Smrg	      func_append dlfiles " $arg"
6922a966c04fSmrg	    else
692397cf2ee2Smrg	      func_append dlprefiles " $arg"
6924a966c04fSmrg	    fi
69256e7d3316Smrg	    prev=
69266e7d3316Smrg	    continue
69276e7d3316Smrg	    ;;
69286e7d3316Smrg	  esac
69296e7d3316Smrg	  ;;
69306e7d3316Smrg	expsyms)
6931edce3322Smrg	  export_symbols=$arg
69326e7d3316Smrg	  test -f "$arg" \
6933edce3322Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
69346e7d3316Smrg	  prev=
69356e7d3316Smrg	  continue
69366e7d3316Smrg	  ;;
69376e7d3316Smrg	expsyms_regex)
6938edce3322Smrg	  export_symbols_regex=$arg
69396e7d3316Smrg	  prev=
69406e7d3316Smrg	  continue
69416e7d3316Smrg	  ;;
69426e7d3316Smrg	framework)
6943a966c04fSmrg	  case $host in
69446e7d3316Smrg	    *-*-darwin*)
69456e7d3316Smrg	      case "$deplibs " in
69466e7d3316Smrg		*" $qarg.ltframework "*) ;;
694797cf2ee2Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
69486e7d3316Smrg		   ;;
69496e7d3316Smrg	      esac
69506e7d3316Smrg	      ;;
6951a966c04fSmrg	  esac
69526e7d3316Smrg	  prev=
69536e7d3316Smrg	  continue
6954a966c04fSmrg	  ;;
69556e7d3316Smrg	inst_prefix)
6956edce3322Smrg	  inst_prefix_dir=$arg
6957edce3322Smrg	  prev=
6958edce3322Smrg	  continue
6959edce3322Smrg	  ;;
6960edce3322Smrg	mllvm)
6961edce3322Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6962edce3322Smrg	  # '-mllvm $arg' options when doing the link step.
69636e7d3316Smrg	  prev=
69646e7d3316Smrg	  continue
6965a966c04fSmrg	  ;;
69666e7d3316Smrg	objectlist)
69676e7d3316Smrg	  if test -f "$arg"; then
69686e7d3316Smrg	    save_arg=$arg
69696e7d3316Smrg	    moreargs=
69706e7d3316Smrg	    for fil in `cat "$save_arg"`
69716e7d3316Smrg	    do
697297cf2ee2Smrg#	      func_append moreargs " $fil"
69736e7d3316Smrg	      arg=$fil
69746e7d3316Smrg	      # A libtool-controlled object.
6975a966c04fSmrg
69766e7d3316Smrg	      # Check to see that this really is a libtool object.
69776e7d3316Smrg	      if func_lalib_unsafe_p "$arg"; then
69786e7d3316Smrg		pic_object=
69796e7d3316Smrg		non_pic_object=
6980a966c04fSmrg
69816e7d3316Smrg		# Read the .lo file
69826e7d3316Smrg		func_source "$arg"
6983a966c04fSmrg
69846e7d3316Smrg		if test -z "$pic_object" ||
69856e7d3316Smrg		   test -z "$non_pic_object" ||
6986edce3322Smrg		   test none = "$pic_object" &&
6987edce3322Smrg		   test none = "$non_pic_object"; then
6988edce3322Smrg		  func_fatal_error "cannot find name of object for '$arg'"
69896e7d3316Smrg		fi
6990a966c04fSmrg
69916e7d3316Smrg		# Extract subdirectory from the argument.
69926e7d3316Smrg		func_dirname "$arg" "/" ""
6993edce3322Smrg		xdir=$func_dirname_result
6994a966c04fSmrg
6995edce3322Smrg		if test none != "$pic_object"; then
69966e7d3316Smrg		  # Prepend the subdirectory the object is found in.
6997edce3322Smrg		  pic_object=$xdir$pic_object
6998a966c04fSmrg
6999edce3322Smrg		  if test dlfiles = "$prev"; then
7000edce3322Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
700197cf2ee2Smrg		      func_append dlfiles " $pic_object"
70026e7d3316Smrg		      prev=
70036e7d3316Smrg		      continue
70046e7d3316Smrg		    else
70056e7d3316Smrg		      # If libtool objects are unsupported, then we need to preload.
70066e7d3316Smrg		      prev=dlprefiles
70076e7d3316Smrg		    fi
70086e7d3316Smrg		  fi
7009a966c04fSmrg
70106e7d3316Smrg		  # CHECK ME:  I think I busted this.  -Ossama
7011edce3322Smrg		  if test dlprefiles = "$prev"; then
70126e7d3316Smrg		    # Preload the old-style object.
701397cf2ee2Smrg		    func_append dlprefiles " $pic_object"
70146e7d3316Smrg		    prev=
70156e7d3316Smrg		  fi
7016a966c04fSmrg
70176e7d3316Smrg		  # A PIC object.
70186e7d3316Smrg		  func_append libobjs " $pic_object"
7019edce3322Smrg		  arg=$pic_object
70206e7d3316Smrg		fi
7021a966c04fSmrg
70226e7d3316Smrg		# Non-PIC object.
7023edce3322Smrg		if test none != "$non_pic_object"; then
70246e7d3316Smrg		  # Prepend the subdirectory the object is found in.
7025edce3322Smrg		  non_pic_object=$xdir$non_pic_object
7026a966c04fSmrg
70276e7d3316Smrg		  # A standard non-PIC object
70286e7d3316Smrg		  func_append non_pic_objects " $non_pic_object"
7029edce3322Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030edce3322Smrg		    arg=$non_pic_object
70316e7d3316Smrg		  fi
70326e7d3316Smrg		else
70336e7d3316Smrg		  # If the PIC object exists, use it instead.
70346e7d3316Smrg		  # $xdir was prepended to $pic_object above.
7035edce3322Smrg		  non_pic_object=$pic_object
70366e7d3316Smrg		  func_append non_pic_objects " $non_pic_object"
70376e7d3316Smrg		fi
70386e7d3316Smrg	      else
70396e7d3316Smrg		# Only an error if not doing a dry-run.
70406e7d3316Smrg		if $opt_dry_run; then
70416e7d3316Smrg		  # Extract subdirectory from the argument.
70426e7d3316Smrg		  func_dirname "$arg" "/" ""
7043edce3322Smrg		  xdir=$func_dirname_result
70446e7d3316Smrg
70456e7d3316Smrg		  func_lo2o "$arg"
70466e7d3316Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
70476e7d3316Smrg		  non_pic_object=$xdir$func_lo2o_result
70486e7d3316Smrg		  func_append libobjs " $pic_object"
70496e7d3316Smrg		  func_append non_pic_objects " $non_pic_object"
70506e7d3316Smrg	        else
7051edce3322Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
70526e7d3316Smrg		fi
70536e7d3316Smrg	      fi
70546e7d3316Smrg	    done
7055a966c04fSmrg	  else
7056edce3322Smrg	    func_fatal_error "link input file '$arg' does not exist"
7057a966c04fSmrg	  fi
70586e7d3316Smrg	  arg=$save_arg
70596e7d3316Smrg	  prev=
70606e7d3316Smrg	  continue
70616e7d3316Smrg	  ;;
7062edce3322Smrg	os2dllname)
7063edce3322Smrg	  os2dllname=$arg
7064edce3322Smrg	  prev=
7065edce3322Smrg	  continue
7066edce3322Smrg	  ;;
70676e7d3316Smrg	precious_regex)
7068edce3322Smrg	  precious_files_regex=$arg
70696e7d3316Smrg	  prev=
70706e7d3316Smrg	  continue
70716e7d3316Smrg	  ;;
70726e7d3316Smrg	release)
7073edce3322Smrg	  release=-$arg
70746e7d3316Smrg	  prev=
70756e7d3316Smrg	  continue
70766e7d3316Smrg	  ;;
70776e7d3316Smrg	rpath | xrpath)
70786e7d3316Smrg	  # We need an absolute path.
70796e7d3316Smrg	  case $arg in
70806e7d3316Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
70816e7d3316Smrg	  *)
70826e7d3316Smrg	    func_fatal_error "only absolute run-paths are allowed"
70836e7d3316Smrg	    ;;
70846e7d3316Smrg	  esac
7085edce3322Smrg	  if test rpath = "$prev"; then
70866e7d3316Smrg	    case "$rpath " in
70876e7d3316Smrg	    *" $arg "*) ;;
708897cf2ee2Smrg	    *) func_append rpath " $arg" ;;
70896e7d3316Smrg	    esac
7090a966c04fSmrg	  else
70916e7d3316Smrg	    case "$xrpath " in
70926e7d3316Smrg	    *" $arg "*) ;;
709397cf2ee2Smrg	    *) func_append xrpath " $arg" ;;
70946e7d3316Smrg	    esac
7095a966c04fSmrg	  fi
70966e7d3316Smrg	  prev=
70976e7d3316Smrg	  continue
70986e7d3316Smrg	  ;;
70996e7d3316Smrg	shrext)
7100edce3322Smrg	  shrext_cmds=$arg
71016e7d3316Smrg	  prev=
71026e7d3316Smrg	  continue
71036e7d3316Smrg	  ;;
71046e7d3316Smrg	weak)
710597cf2ee2Smrg	  func_append weak_libs " $arg"
71066e7d3316Smrg	  prev=
71076e7d3316Smrg	  continue
71086e7d3316Smrg	  ;;
710974835918Smrg	xassembler)
711074835918Smrg	  func_append compiler_flags " -Xassembler $qarg"
711174835918Smrg	  prev=
711274835918Smrg	  func_append compile_command " -Xassembler $qarg"
711374835918Smrg	  func_append finalize_command " -Xassembler $qarg"
711474835918Smrg	  continue
711574835918Smrg	  ;;
71166e7d3316Smrg	xcclinker)
711797cf2ee2Smrg	  func_append linker_flags " $qarg"
711897cf2ee2Smrg	  func_append compiler_flags " $qarg"
71196e7d3316Smrg	  prev=
71206e7d3316Smrg	  func_append compile_command " $qarg"
71216e7d3316Smrg	  func_append finalize_command " $qarg"
71226e7d3316Smrg	  continue
71236e7d3316Smrg	  ;;
71246e7d3316Smrg	xcompiler)
712597cf2ee2Smrg	  func_append compiler_flags " $qarg"
71266e7d3316Smrg	  prev=
71276e7d3316Smrg	  func_append compile_command " $qarg"
71286e7d3316Smrg	  func_append finalize_command " $qarg"
71296e7d3316Smrg	  continue
71306e7d3316Smrg	  ;;
71316e7d3316Smrg	xlinker)
713297cf2ee2Smrg	  func_append linker_flags " $qarg"
713397cf2ee2Smrg	  func_append compiler_flags " $wl$qarg"
71346e7d3316Smrg	  prev=
71356e7d3316Smrg	  func_append compile_command " $wl$qarg"
71366e7d3316Smrg	  func_append finalize_command " $wl$qarg"
71376e7d3316Smrg	  continue
71386e7d3316Smrg	  ;;
71396e7d3316Smrg	*)
71406e7d3316Smrg	  eval "$prev=\"\$arg\""
71416e7d3316Smrg	  prev=
71426e7d3316Smrg	  continue
71436e7d3316Smrg	  ;;
7144a966c04fSmrg	esac
71456e7d3316Smrg      fi # test -n "$prev"
7146a966c04fSmrg
7147edce3322Smrg      prevarg=$arg
7148a966c04fSmrg
71496e7d3316Smrg      case $arg in
71506e7d3316Smrg      -all-static)
71516e7d3316Smrg	if test -n "$link_static_flag"; then
71526e7d3316Smrg	  # See comment for -static flag below, for more details.
71536e7d3316Smrg	  func_append compile_command " $link_static_flag"
71546e7d3316Smrg	  func_append finalize_command " $link_static_flag"
71556e7d3316Smrg	fi
71566e7d3316Smrg	continue
71576e7d3316Smrg	;;
7158a966c04fSmrg
71596e7d3316Smrg      -allow-undefined)
71606e7d3316Smrg	# FIXME: remove this flag sometime in the future.
7161edce3322Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
71626e7d3316Smrg	;;
7163a966c04fSmrg
71646e7d3316Smrg      -avoid-version)
71656e7d3316Smrg	avoid_version=yes
71666e7d3316Smrg	continue
71676e7d3316Smrg	;;
7168a966c04fSmrg
71696e7d3316Smrg      -bindir)
71706e7d3316Smrg	prev=bindir
71716e7d3316Smrg	continue
71726e7d3316Smrg	;;
7173a966c04fSmrg
71746e7d3316Smrg      -dlopen)
71756e7d3316Smrg	prev=dlfiles
71766e7d3316Smrg	continue
71776e7d3316Smrg	;;
7178a966c04fSmrg
71796e7d3316Smrg      -dlpreopen)
71806e7d3316Smrg	prev=dlprefiles
71816e7d3316Smrg	continue
71826e7d3316Smrg	;;
7183a966c04fSmrg
71846e7d3316Smrg      -export-dynamic)
71856e7d3316Smrg	export_dynamic=yes
71866e7d3316Smrg	continue
71876e7d3316Smrg	;;
7188a966c04fSmrg
71896e7d3316Smrg      -export-symbols | -export-symbols-regex)
71906e7d3316Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
71916e7d3316Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
71926e7d3316Smrg	fi
7193edce3322Smrg	if test X-export-symbols = "X$arg"; then
71946e7d3316Smrg	  prev=expsyms
71956e7d3316Smrg	else
71966e7d3316Smrg	  prev=expsyms_regex
71976e7d3316Smrg	fi
71986e7d3316Smrg	continue
71996e7d3316Smrg	;;
7200a966c04fSmrg
72016e7d3316Smrg      -framework)
72026e7d3316Smrg	prev=framework
72036e7d3316Smrg	continue
72046e7d3316Smrg	;;
7205a966c04fSmrg
72066e7d3316Smrg      -inst-prefix-dir)
72076e7d3316Smrg	prev=inst_prefix
72086e7d3316Smrg	continue
72096e7d3316Smrg	;;
7210a966c04fSmrg
72116e7d3316Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
72126e7d3316Smrg      # so, if we see these flags be careful not to treat them like -L
72136e7d3316Smrg      -L[A-Z][A-Z]*:*)
72146e7d3316Smrg	case $with_gcc/$host in
72156e7d3316Smrg	no/*-*-irix* | /*-*-irix*)
72166e7d3316Smrg	  func_append compile_command " $arg"
72176e7d3316Smrg	  func_append finalize_command " $arg"
72186e7d3316Smrg	  ;;
72196e7d3316Smrg	esac
72206e7d3316Smrg	continue
72216e7d3316Smrg	;;
7222a966c04fSmrg
72236e7d3316Smrg      -L*)
722497cf2ee2Smrg	func_stripname "-L" '' "$arg"
722597cf2ee2Smrg	if test -z "$func_stripname_result"; then
72266e7d3316Smrg	  if test "$#" -gt 0; then
7227edce3322Smrg	    func_fatal_error "require no space between '-L' and '$1'"
72286e7d3316Smrg	  else
7229edce3322Smrg	    func_fatal_error "need path for '-L' option"
72306e7d3316Smrg	  fi
72316e7d3316Smrg	fi
723297cf2ee2Smrg	func_resolve_sysroot "$func_stripname_result"
723397cf2ee2Smrg	dir=$func_resolve_sysroot_result
72346e7d3316Smrg	# We need an absolute path.
72356e7d3316Smrg	case $dir in
72366e7d3316Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
72376e7d3316Smrg	*)
72386e7d3316Smrg	  absdir=`cd "$dir" && pwd`
72396e7d3316Smrg	  test -z "$absdir" && \
7240edce3322Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241edce3322Smrg	  dir=$absdir
72426e7d3316Smrg	  ;;
72436e7d3316Smrg	esac
72446e7d3316Smrg	case "$deplibs " in
724597cf2ee2Smrg	*" -L$dir "* | *" $arg "*)
724697cf2ee2Smrg	  # Will only happen for absolute or sysroot arguments
724797cf2ee2Smrg	  ;;
72486e7d3316Smrg	*)
724997cf2ee2Smrg	  # Preserve sysroot, but never include relative directories
725097cf2ee2Smrg	  case $dir in
725197cf2ee2Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
725297cf2ee2Smrg	    *) func_append deplibs " -L$dir" ;;
725397cf2ee2Smrg	  esac
725497cf2ee2Smrg	  func_append lib_search_path " $dir"
72556e7d3316Smrg	  ;;
72566e7d3316Smrg	esac
72576e7d3316Smrg	case $host in
72586e7d3316Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
72596e7d3316Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
72606e7d3316Smrg	  case :$dllsearchpath: in
72616e7d3316Smrg	  *":$dir:"*) ;;
72626e7d3316Smrg	  ::) dllsearchpath=$dir;;
726397cf2ee2Smrg	  *) func_append dllsearchpath ":$dir";;
72646e7d3316Smrg	  esac
72656e7d3316Smrg	  case :$dllsearchpath: in
72666e7d3316Smrg	  *":$testbindir:"*) ;;
72676e7d3316Smrg	  ::) dllsearchpath=$testbindir;;
726897cf2ee2Smrg	  *) func_append dllsearchpath ":$testbindir";;
72696e7d3316Smrg	  esac
72706e7d3316Smrg	  ;;
72716e7d3316Smrg	esac
72726e7d3316Smrg	continue
72736e7d3316Smrg	;;
7274a966c04fSmrg
72756e7d3316Smrg      -l*)
7276edce3322Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
72776e7d3316Smrg	  case $host in
72786e7d3316Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
72796e7d3316Smrg	    # These systems don't actually have a C or math library (as such)
72806e7d3316Smrg	    continue
72816e7d3316Smrg	    ;;
72826e7d3316Smrg	  *-*-os2*)
72836e7d3316Smrg	    # These systems don't actually have a C library (as such)
7284edce3322Smrg	    test X-lc = "X$arg" && continue
72856e7d3316Smrg	    ;;
728674835918Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
72876e7d3316Smrg	    # Do not include libc due to us having libc/libc_r.
7288edce3322Smrg	    test X-lc = "X$arg" && continue
72896e7d3316Smrg	    ;;
72906e7d3316Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
72916e7d3316Smrg	    # Rhapsody C and math libraries are in the System framework
729297cf2ee2Smrg	    func_append deplibs " System.ltframework"
72936e7d3316Smrg	    continue
72946e7d3316Smrg	    ;;
72956e7d3316Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
72966e7d3316Smrg	    # Causes problems with __ctype
7297edce3322Smrg	    test X-lc = "X$arg" && continue
72986e7d3316Smrg	    ;;
72996e7d3316Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
73006e7d3316Smrg	    # Compiler inserts libc in the correct place for threads to work
7301edce3322Smrg	    test X-lc = "X$arg" && continue
73026e7d3316Smrg	    ;;
73036e7d3316Smrg	  esac
7304edce3322Smrg	elif test X-lc_r = "X$arg"; then
73056e7d3316Smrg	 case $host in
730674835918Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
73076e7d3316Smrg	   # Do not include libc_r directly, use -pthread flag.
73086e7d3316Smrg	   continue
73096e7d3316Smrg	   ;;
73106e7d3316Smrg	 esac
73116e7d3316Smrg	fi
731297cf2ee2Smrg	func_append deplibs " $arg"
73136e7d3316Smrg	continue
73146e7d3316Smrg	;;
7315a966c04fSmrg
7316edce3322Smrg      -mllvm)
7317edce3322Smrg	prev=mllvm
7318edce3322Smrg	continue
7319edce3322Smrg	;;
7320edce3322Smrg
73216e7d3316Smrg      -module)
73226e7d3316Smrg	module=yes
73236e7d3316Smrg	continue
73246e7d3316Smrg	;;
7325a966c04fSmrg
73266e7d3316Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
73276e7d3316Smrg      # classes, name mangling, and exception handling.
73286e7d3316Smrg      # Darwin uses the -arch flag to determine output architecture.
732997cf2ee2Smrg      -model|-arch|-isysroot|--sysroot)
733097cf2ee2Smrg	func_append compiler_flags " $arg"
73316e7d3316Smrg	func_append compile_command " $arg"
73326e7d3316Smrg	func_append finalize_command " $arg"
73336e7d3316Smrg	prev=xcompiler
73346e7d3316Smrg	continue
73356e7d3316Smrg	;;
733674835918Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
733774835918Smrg     -pthread)
733874835918Smrg	case $host in
733974835918Smrg	  *solaris2*) ;;
734074835918Smrg	  *)
734174835918Smrg	    case "$new_inherited_linker_flags " in
734274835918Smrg	        *" $arg "*) ;;
734374835918Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
734474835918Smrg	    esac
734574835918Smrg	  ;;
734674835918Smrg	esac
734774835918Smrg	continue
734874835918Smrg	;;
734974835918Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350ac92798bSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
735197cf2ee2Smrg	func_append compiler_flags " $arg"
73526e7d3316Smrg	func_append compile_command " $arg"
73536e7d3316Smrg	func_append finalize_command " $arg"
73546e7d3316Smrg	case "$new_inherited_linker_flags " in
73556e7d3316Smrg	    *" $arg "*) ;;
735697cf2ee2Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
73576e7d3316Smrg	esac
73586e7d3316Smrg	continue
73596e7d3316Smrg	;;
7360a966c04fSmrg
73616e7d3316Smrg      -multi_module)
7362edce3322Smrg	single_module=$wl-multi_module
73636e7d3316Smrg	continue
73646e7d3316Smrg	;;
7365a966c04fSmrg
73666e7d3316Smrg      -no-fast-install)
73676e7d3316Smrg	fast_install=no
73686e7d3316Smrg	continue
73696e7d3316Smrg	;;
7370a966c04fSmrg
73716e7d3316Smrg      -no-install)
73726e7d3316Smrg	case $host in
73736e7d3316Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
73746e7d3316Smrg	  # The PATH hackery in wrapper scripts is required on Windows
73756e7d3316Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7376edce3322Smrg	  func_warning "'-no-install' is ignored for $host"
7377edce3322Smrg	  func_warning "assuming '-no-fast-install' instead"
73786e7d3316Smrg	  fast_install=no
73796e7d3316Smrg	  ;;
73806e7d3316Smrg	*) no_install=yes ;;
73816e7d3316Smrg	esac
73826e7d3316Smrg	continue
73836e7d3316Smrg	;;
7384a966c04fSmrg
73856e7d3316Smrg      -no-undefined)
73866e7d3316Smrg	allow_undefined=no
73876e7d3316Smrg	continue
73886e7d3316Smrg	;;
7389a966c04fSmrg
73906e7d3316Smrg      -objectlist)
73916e7d3316Smrg	prev=objectlist
73926e7d3316Smrg	continue
73936e7d3316Smrg	;;
7394a966c04fSmrg
7395edce3322Smrg      -os2dllname)
7396edce3322Smrg	prev=os2dllname
7397edce3322Smrg	continue
7398edce3322Smrg	;;
7399edce3322Smrg
74006e7d3316Smrg      -o) prev=output ;;
7401a966c04fSmrg
74026e7d3316Smrg      -precious-files-regex)
74036e7d3316Smrg	prev=precious_regex
74046e7d3316Smrg	continue
74056e7d3316Smrg	;;
7406a966c04fSmrg
74076e7d3316Smrg      -release)
74086e7d3316Smrg	prev=release
74096e7d3316Smrg	continue
74106e7d3316Smrg	;;
7411a966c04fSmrg
74126e7d3316Smrg      -rpath)
74136e7d3316Smrg	prev=rpath
74146e7d3316Smrg	continue
74156e7d3316Smrg	;;
7416a966c04fSmrg
74176e7d3316Smrg      -R)
74186e7d3316Smrg	prev=xrpath
74196e7d3316Smrg	continue
74206e7d3316Smrg	;;
7421a966c04fSmrg
74226e7d3316Smrg      -R*)
74236e7d3316Smrg	func_stripname '-R' '' "$arg"
74246e7d3316Smrg	dir=$func_stripname_result
74256e7d3316Smrg	# We need an absolute path.
74266e7d3316Smrg	case $dir in
74276e7d3316Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
742897cf2ee2Smrg	=*)
742997cf2ee2Smrg	  func_stripname '=' '' "$dir"
743097cf2ee2Smrg	  dir=$lt_sysroot$func_stripname_result
743197cf2ee2Smrg	  ;;
74326e7d3316Smrg	*)
74336e7d3316Smrg	  func_fatal_error "only absolute run-paths are allowed"
74346e7d3316Smrg	  ;;
74356e7d3316Smrg	esac
74366e7d3316Smrg	case "$xrpath " in
74376e7d3316Smrg	*" $dir "*) ;;
743897cf2ee2Smrg	*) func_append xrpath " $dir" ;;
74396e7d3316Smrg	esac
74406e7d3316Smrg	continue
74416e7d3316Smrg	;;
7442a966c04fSmrg
74436e7d3316Smrg      -shared)
74446e7d3316Smrg	# The effects of -shared are defined in a previous loop.
74456e7d3316Smrg	continue
74466e7d3316Smrg	;;
7447a966c04fSmrg
74486e7d3316Smrg      -shrext)
74496e7d3316Smrg	prev=shrext
74506e7d3316Smrg	continue
74516e7d3316Smrg	;;
7452a966c04fSmrg
74536e7d3316Smrg      -static | -static-libtool-libs)
74546e7d3316Smrg	# The effects of -static are defined in a previous loop.
74556e7d3316Smrg	# We used to do the same as -all-static on platforms that
74566e7d3316Smrg	# didn't have a PIC flag, but the assumption that the effects
74576e7d3316Smrg	# would be equivalent was wrong.  It would break on at least
74586e7d3316Smrg	# Digital Unix and AIX.
74596e7d3316Smrg	continue
74606e7d3316Smrg	;;
7461a966c04fSmrg
74626e7d3316Smrg      -thread-safe)
74636e7d3316Smrg	thread_safe=yes
74646e7d3316Smrg	continue
74656e7d3316Smrg	;;
7466a966c04fSmrg
74676e7d3316Smrg      -version-info)
74686e7d3316Smrg	prev=vinfo
74696e7d3316Smrg	continue
74706e7d3316Smrg	;;
7471a966c04fSmrg
74726e7d3316Smrg      -version-number)
74736e7d3316Smrg	prev=vinfo
74746e7d3316Smrg	vinfo_number=yes
74756e7d3316Smrg	continue
74766e7d3316Smrg	;;
7477a966c04fSmrg
74786e7d3316Smrg      -weak)
74796e7d3316Smrg        prev=weak
74806e7d3316Smrg	continue
74816e7d3316Smrg	;;
7482a966c04fSmrg
74836e7d3316Smrg      -Wc,*)
74846e7d3316Smrg	func_stripname '-Wc,' '' "$arg"
74856e7d3316Smrg	args=$func_stripname_result
74866e7d3316Smrg	arg=
7487edce3322Smrg	save_ifs=$IFS; IFS=,
74886e7d3316Smrg	for flag in $args; do
7489edce3322Smrg	  IFS=$save_ifs
749074835918Smrg          func_quote_arg pretty "$flag"
749174835918Smrg	  func_append arg " $func_quote_arg_result"
749274835918Smrg	  func_append compiler_flags " $func_quote_arg_result"
74936e7d3316Smrg	done
7494edce3322Smrg	IFS=$save_ifs
74956e7d3316Smrg	func_stripname ' ' '' "$arg"
74966e7d3316Smrg	arg=$func_stripname_result
74976e7d3316Smrg	;;
7498a966c04fSmrg
74996e7d3316Smrg      -Wl,*)
75006e7d3316Smrg	func_stripname '-Wl,' '' "$arg"
75016e7d3316Smrg	args=$func_stripname_result
75026e7d3316Smrg	arg=
7503edce3322Smrg	save_ifs=$IFS; IFS=,
75046e7d3316Smrg	for flag in $args; do
7505edce3322Smrg	  IFS=$save_ifs
750674835918Smrg          func_quote_arg pretty "$flag"
750774835918Smrg	  func_append arg " $wl$func_quote_arg_result"
750874835918Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
750974835918Smrg	  func_append linker_flags " $func_quote_arg_result"
75106e7d3316Smrg	done
7511edce3322Smrg	IFS=$save_ifs
75126e7d3316Smrg	func_stripname ' ' '' "$arg"
75136e7d3316Smrg	arg=$func_stripname_result
75146e7d3316Smrg	;;
7515a966c04fSmrg
751674835918Smrg      -Xassembler)
751774835918Smrg        prev=xassembler
751874835918Smrg        continue
751974835918Smrg        ;;
752074835918Smrg
75216e7d3316Smrg      -Xcompiler)
75226e7d3316Smrg	prev=xcompiler
75236e7d3316Smrg	continue
75246e7d3316Smrg	;;
7525a966c04fSmrg
75266e7d3316Smrg      -Xlinker)
75276e7d3316Smrg	prev=xlinker
75286e7d3316Smrg	continue
75296e7d3316Smrg	;;
7530a966c04fSmrg
75316e7d3316Smrg      -XCClinker)
75326e7d3316Smrg	prev=xcclinker
75336e7d3316Smrg	continue
75346e7d3316Smrg	;;
7535a966c04fSmrg
75366e7d3316Smrg      # -msg_* for osf cc
75376e7d3316Smrg      -msg_*)
753874835918Smrg	func_quote_arg pretty "$arg"
753974835918Smrg	arg=$func_quote_arg_result
75406e7d3316Smrg	;;
7541a966c04fSmrg
75426e7d3316Smrg      # Flags to be passed through unchanged, with rationale:
75436e7d3316Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
75446e7d3316Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
75456e7d3316Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
75466e7d3316Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
75476e7d3316Smrg      # -q*                  compiler args for the IBM compiler
75486e7d3316Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
75496e7d3316Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
75506e7d3316Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551edce3322Smrg      # -fstack-protector*   stack protector flags for GCC
75526e7d3316Smrg      # @file                GCC response files
75536e7d3316Smrg      # -tp=*                Portland pgcc target processor selection
755497cf2ee2Smrg      # --sysroot=*          for sysroot support
7555edce3322Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
755674835918Smrg      # -specs=*             GCC specs files
7557edce3322Smrg      # -stdlib=*            select c++ std lib with clang
755874835918Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
755974835918Smrg      # -fuse-ld=*           Linker select flags for GCC
756074835918Smrg      # -Wa,*                Pass flags directly to the assembler
75616e7d3316Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
756297cf2ee2Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
756374835918Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
756452dc082bSmrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
756574835918Smrg        func_quote_arg pretty "$arg"
756674835918Smrg	arg=$func_quote_arg_result
75676e7d3316Smrg        func_append compile_command " $arg"
75686e7d3316Smrg        func_append finalize_command " $arg"
756997cf2ee2Smrg        func_append compiler_flags " $arg"
75706e7d3316Smrg        continue
75716e7d3316Smrg        ;;
7572a966c04fSmrg
7573edce3322Smrg      -Z*)
7574edce3322Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575edce3322Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576edce3322Smrg	  compiler_flags="$compiler_flags $arg"
7577edce3322Smrg	  func_append compile_command " $arg"
7578edce3322Smrg	  func_append finalize_command " $arg"
7579edce3322Smrg	  case $arg in
7580edce3322Smrg	  -Zlinker | -Zstack)
7581edce3322Smrg	    prev=xcompiler
7582edce3322Smrg	    ;;
7583edce3322Smrg	  esac
7584edce3322Smrg	  continue
7585edce3322Smrg        else
7586edce3322Smrg	  # Otherwise treat like 'Some other compiler flag' below
758774835918Smrg	  func_quote_arg pretty "$arg"
758874835918Smrg	  arg=$func_quote_arg_result
7589edce3322Smrg        fi
7590edce3322Smrg	;;
7591edce3322Smrg
75926e7d3316Smrg      # Some other compiler flag.
75936e7d3316Smrg      -* | +*)
759474835918Smrg        func_quote_arg pretty "$arg"
759574835918Smrg	arg=$func_quote_arg_result
75966e7d3316Smrg	;;
7597a966c04fSmrg
75986e7d3316Smrg      *.$objext)
75996e7d3316Smrg	# A standard object.
760097cf2ee2Smrg	func_append objs " $arg"
76016e7d3316Smrg	;;
7602a966c04fSmrg
76036e7d3316Smrg      *.lo)
76046e7d3316Smrg	# A libtool-controlled object.
7605a966c04fSmrg
76066e7d3316Smrg	# Check to see that this really is a libtool object.
76076e7d3316Smrg	if func_lalib_unsafe_p "$arg"; then
76086e7d3316Smrg	  pic_object=
76096e7d3316Smrg	  non_pic_object=
7610a966c04fSmrg
76116e7d3316Smrg	  # Read the .lo file
76126e7d3316Smrg	  func_source "$arg"
7613a966c04fSmrg
76146e7d3316Smrg	  if test -z "$pic_object" ||
76156e7d3316Smrg	     test -z "$non_pic_object" ||
7616edce3322Smrg	     test none = "$pic_object" &&
7617edce3322Smrg	     test none = "$non_pic_object"; then
7618edce3322Smrg	    func_fatal_error "cannot find name of object for '$arg'"
76196e7d3316Smrg	  fi
76202e2dd055Smrg
76216e7d3316Smrg	  # Extract subdirectory from the argument.
76226e7d3316Smrg	  func_dirname "$arg" "/" ""
7623edce3322Smrg	  xdir=$func_dirname_result
7624a966c04fSmrg
7625edce3322Smrg	  test none = "$pic_object" || {
76266e7d3316Smrg	    # Prepend the subdirectory the object is found in.
7627edce3322Smrg	    pic_object=$xdir$pic_object
7628a966c04fSmrg
7629edce3322Smrg	    if test dlfiles = "$prev"; then
7630edce3322Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
763197cf2ee2Smrg		func_append dlfiles " $pic_object"
76326e7d3316Smrg		prev=
76336e7d3316Smrg		continue
76346e7d3316Smrg	      else
76356e7d3316Smrg		# If libtool objects are unsupported, then we need to preload.
76366e7d3316Smrg		prev=dlprefiles
76376e7d3316Smrg	      fi
76386e7d3316Smrg	    fi
76396e7d3316Smrg
76406e7d3316Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7641edce3322Smrg	    if test dlprefiles = "$prev"; then
76426e7d3316Smrg	      # Preload the old-style object.
764397cf2ee2Smrg	      func_append dlprefiles " $pic_object"
76446e7d3316Smrg	      prev=
76456e7d3316Smrg	    fi
76466e7d3316Smrg
76476e7d3316Smrg	    # A PIC object.
76486e7d3316Smrg	    func_append libobjs " $pic_object"
7649edce3322Smrg	    arg=$pic_object
7650edce3322Smrg	  }
76516e7d3316Smrg
76526e7d3316Smrg	  # Non-PIC object.
7653edce3322Smrg	  if test none != "$non_pic_object"; then
76546e7d3316Smrg	    # Prepend the subdirectory the object is found in.
7655edce3322Smrg	    non_pic_object=$xdir$non_pic_object
76566e7d3316Smrg
76576e7d3316Smrg	    # A standard non-PIC object
76586e7d3316Smrg	    func_append non_pic_objects " $non_pic_object"
7659edce3322Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660edce3322Smrg	      arg=$non_pic_object
76616e7d3316Smrg	    fi
76626e7d3316Smrg	  else
76636e7d3316Smrg	    # If the PIC object exists, use it instead.
76646e7d3316Smrg	    # $xdir was prepended to $pic_object above.
7665edce3322Smrg	    non_pic_object=$pic_object
76666e7d3316Smrg	    func_append non_pic_objects " $non_pic_object"
76676e7d3316Smrg	  fi
76686e7d3316Smrg	else
76696e7d3316Smrg	  # Only an error if not doing a dry-run.
76706e7d3316Smrg	  if $opt_dry_run; then
76716e7d3316Smrg	    # Extract subdirectory from the argument.
76726e7d3316Smrg	    func_dirname "$arg" "/" ""
7673edce3322Smrg	    xdir=$func_dirname_result
76746e7d3316Smrg
76756e7d3316Smrg	    func_lo2o "$arg"
76766e7d3316Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
76776e7d3316Smrg	    non_pic_object=$xdir$func_lo2o_result
76786e7d3316Smrg	    func_append libobjs " $pic_object"
76796e7d3316Smrg	    func_append non_pic_objects " $non_pic_object"
76806e7d3316Smrg	  else
7681edce3322Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
76826e7d3316Smrg	  fi
76836e7d3316Smrg	fi
76846e7d3316Smrg	;;
76856e7d3316Smrg
76866e7d3316Smrg      *.$libext)
76876e7d3316Smrg	# An archive.
768897cf2ee2Smrg	func_append deplibs " $arg"
768997cf2ee2Smrg	func_append old_deplibs " $arg"
76906e7d3316Smrg	continue
76916e7d3316Smrg	;;
76926e7d3316Smrg
76936e7d3316Smrg      *.la)
76946e7d3316Smrg	# A libtool-controlled library.
76956e7d3316Smrg
769697cf2ee2Smrg	func_resolve_sysroot "$arg"
7697edce3322Smrg	if test dlfiles = "$prev"; then
76986e7d3316Smrg	  # This library was specified with -dlopen.
769997cf2ee2Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
77006e7d3316Smrg	  prev=
7701edce3322Smrg	elif test dlprefiles = "$prev"; then
77026e7d3316Smrg	  # The library was specified with -dlpreopen.
770397cf2ee2Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
77046e7d3316Smrg	  prev=
77056e7d3316Smrg	else
770697cf2ee2Smrg	  func_append deplibs " $func_resolve_sysroot_result"
77076e7d3316Smrg	fi
77086e7d3316Smrg	continue
77096e7d3316Smrg	;;
77106e7d3316Smrg
77116e7d3316Smrg      # Some other compiler argument.
77126e7d3316Smrg      *)
77136e7d3316Smrg	# Unknown arguments in both finalize_command and compile_command need
77146e7d3316Smrg	# to be aesthetically quoted because they are evaled later.
771574835918Smrg	func_quote_arg pretty "$arg"
771674835918Smrg	arg=$func_quote_arg_result
77176e7d3316Smrg	;;
77186e7d3316Smrg      esac # arg
77196e7d3316Smrg
77206e7d3316Smrg      # Now actually substitute the argument into the commands.
77216e7d3316Smrg      if test -n "$arg"; then
77226e7d3316Smrg	func_append compile_command " $arg"
77236e7d3316Smrg	func_append finalize_command " $arg"
77246e7d3316Smrg      fi
77256e7d3316Smrg    done # argument parsing loop
77266e7d3316Smrg
77276e7d3316Smrg    test -n "$prev" && \
7728edce3322Smrg      func_fatal_help "the '$prevarg' option requires an argument"
77296e7d3316Smrg
7730edce3322Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
77316e7d3316Smrg      eval arg=\"$export_dynamic_flag_spec\"
77326e7d3316Smrg      func_append compile_command " $arg"
77336e7d3316Smrg      func_append finalize_command " $arg"
77346e7d3316Smrg    fi
77356e7d3316Smrg
77366e7d3316Smrg    oldlibs=
77376e7d3316Smrg    # calculate the name of the file, without its directory
77386e7d3316Smrg    func_basename "$output"
7739edce3322Smrg    outputname=$func_basename_result
7740edce3322Smrg    libobjs_save=$libobjs
77416e7d3316Smrg
77426e7d3316Smrg    if test -n "$shlibpath_var"; then
77436e7d3316Smrg      # get the directories listed in $shlibpath_var
7744edce3322Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7745a966c04fSmrg    else
77466e7d3316Smrg      shlib_search_path=
7747a966c04fSmrg    fi
77486e7d3316Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
77496e7d3316Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750a966c04fSmrg
7751edce3322Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7752edce3322Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753edce3322Smrg
77546e7d3316Smrg    func_dirname "$output" "/" ""
7755edce3322Smrg    output_objdir=$func_dirname_result$objdir
775697cf2ee2Smrg    func_to_tool_file "$output_objdir/"
775797cf2ee2Smrg    tool_output_objdir=$func_to_tool_file_result
77586e7d3316Smrg    # Create the object directory.
77596e7d3316Smrg    func_mkdir_p "$output_objdir"
7760a966c04fSmrg
77616e7d3316Smrg    # Determine the type of output
77626e7d3316Smrg    case $output in
77636e7d3316Smrg    "")
77646e7d3316Smrg      func_fatal_help "you must specify an output file"
77656e7d3316Smrg      ;;
77666e7d3316Smrg    *.$libext) linkmode=oldlib ;;
77676e7d3316Smrg    *.lo | *.$objext) linkmode=obj ;;
77686e7d3316Smrg    *.la) linkmode=lib ;;
77696e7d3316Smrg    *) linkmode=prog ;; # Anything else should be a program.
77706e7d3316Smrg    esac
77716e7d3316Smrg
77726e7d3316Smrg    specialdeplibs=
77736e7d3316Smrg
77746e7d3316Smrg    libs=
77756e7d3316Smrg    # Find all interdependent deplibs by searching for libraries
77766e7d3316Smrg    # that are linked more than once (e.g. -la -lb -la)
77776e7d3316Smrg    for deplib in $deplibs; do
7778edce3322Smrg      if $opt_preserve_dup_deps; then
77796e7d3316Smrg	case "$libs " in
778097cf2ee2Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
77816e7d3316Smrg	esac
77826e7d3316Smrg      fi
778397cf2ee2Smrg      func_append libs " $deplib"
77846e7d3316Smrg    done
77856e7d3316Smrg
7786edce3322Smrg    if test lib = "$linkmode"; then
77876e7d3316Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
77886e7d3316Smrg
77896e7d3316Smrg      # Compute libraries that are listed more than once in $predeps
77906e7d3316Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
77916e7d3316Smrg      # not to be eliminated).
77926e7d3316Smrg      pre_post_deps=
77936e7d3316Smrg      if $opt_duplicate_compiler_generated_deps; then
77946e7d3316Smrg	for pre_post_dep in $predeps $postdeps; do
77956e7d3316Smrg	  case "$pre_post_deps " in
779697cf2ee2Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
77976e7d3316Smrg	  esac
779897cf2ee2Smrg	  func_append pre_post_deps " $pre_post_dep"
77996e7d3316Smrg	done
78006e7d3316Smrg      fi
78016e7d3316Smrg      pre_post_deps=
78026e7d3316Smrg    fi
78036e7d3316Smrg
78046e7d3316Smrg    deplibs=
78056e7d3316Smrg    newdependency_libs=
78066e7d3316Smrg    newlib_search_path=
78076e7d3316Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
78086e7d3316Smrg    notinst_deplibs= # not-installed libtool libraries
78096e7d3316Smrg    notinst_path= # paths that contain not-installed libtool libraries
78106e7d3316Smrg
78116e7d3316Smrg    case $linkmode in
78126e7d3316Smrg    lib)
78136e7d3316Smrg	passes="conv dlpreopen link"
78146e7d3316Smrg	for file in $dlfiles $dlprefiles; do
78156e7d3316Smrg	  case $file in
78166e7d3316Smrg	  *.la) ;;
78176e7d3316Smrg	  *)
7818edce3322Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
78196e7d3316Smrg	    ;;
78206e7d3316Smrg	  esac
78216e7d3316Smrg	done
78226e7d3316Smrg	;;
78236e7d3316Smrg    prog)
78246e7d3316Smrg	compile_deplibs=
78256e7d3316Smrg	finalize_deplibs=
7826edce3322Smrg	alldeplibs=false
78276e7d3316Smrg	newdlfiles=
78286e7d3316Smrg	newdlprefiles=
78296e7d3316Smrg	passes="conv scan dlopen dlpreopen link"
78306e7d3316Smrg	;;
78316e7d3316Smrg    *)  passes="conv"
78326e7d3316Smrg	;;
78336e7d3316Smrg    esac
78346e7d3316Smrg
78356e7d3316Smrg    for pass in $passes; do
78366e7d3316Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
78376e7d3316Smrg      # so that -L comes before libs that need it for instance...
7838edce3322Smrg      if test lib,link = "$linkmode,$pass"; then
78396e7d3316Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
78406e7d3316Smrg	##        order, and fix it there properly
78416e7d3316Smrg        tmp_deplibs=
78426e7d3316Smrg	for deplib in $deplibs; do
78436e7d3316Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
78446e7d3316Smrg	done
7845edce3322Smrg	deplibs=$tmp_deplibs
78466e7d3316Smrg      fi
78476e7d3316Smrg
7848edce3322Smrg      if test lib,link = "$linkmode,$pass" ||
7849edce3322Smrg	 test prog,scan = "$linkmode,$pass"; then
7850edce3322Smrg	libs=$deplibs
78516e7d3316Smrg	deplibs=
78526e7d3316Smrg      fi
7853edce3322Smrg      if test prog = "$linkmode"; then
78546e7d3316Smrg	case $pass in
7855edce3322Smrg	dlopen) libs=$dlfiles ;;
7856edce3322Smrg	dlpreopen) libs=$dlprefiles ;;
7857edce3322Smrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
78586e7d3316Smrg	esac
78596e7d3316Smrg      fi
7860edce3322Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
78616e7d3316Smrg	# Collect and forward deplibs of preopened libtool libs
78626e7d3316Smrg	for lib in $dlprefiles; do
78636e7d3316Smrg	  # Ignore non-libtool-libs
78646e7d3316Smrg	  dependency_libs=
786597cf2ee2Smrg	  func_resolve_sysroot "$lib"
78666e7d3316Smrg	  case $lib in
786797cf2ee2Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
78686e7d3316Smrg	  esac
78696e7d3316Smrg
78706e7d3316Smrg	  # Collect preopened libtool deplibs, except any this library
78716e7d3316Smrg	  # has declared as weak libs
78726e7d3316Smrg	  for deplib in $dependency_libs; do
78736e7d3316Smrg	    func_basename "$deplib"
78746e7d3316Smrg            deplib_base=$func_basename_result
78756e7d3316Smrg	    case " $weak_libs " in
78766e7d3316Smrg	    *" $deplib_base "*) ;;
787797cf2ee2Smrg	    *) func_append deplibs " $deplib" ;;
78786e7d3316Smrg	    esac
78796e7d3316Smrg	  done
78806e7d3316Smrg	done
7881edce3322Smrg	libs=$dlprefiles
78826e7d3316Smrg      fi
7883edce3322Smrg      if test dlopen = "$pass"; then
78846e7d3316Smrg	# Collect dlpreopened libraries
7885edce3322Smrg	save_deplibs=$deplibs
78866e7d3316Smrg	deplibs=
78876e7d3316Smrg      fi
78886e7d3316Smrg
78896e7d3316Smrg      for deplib in $libs; do
78906e7d3316Smrg	lib=
7891edce3322Smrg	found=false
78926e7d3316Smrg	case $deplib in
7893ac92798bSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894ac92798bSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895edce3322Smrg	  if test prog,link = "$linkmode,$pass"; then
78966e7d3316Smrg	    compile_deplibs="$deplib $compile_deplibs"
78976e7d3316Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
78986e7d3316Smrg	  else
789997cf2ee2Smrg	    func_append compiler_flags " $deplib"
7900edce3322Smrg	    if test lib = "$linkmode"; then
79016e7d3316Smrg		case "$new_inherited_linker_flags " in
79026e7d3316Smrg		    *" $deplib "*) ;;
790397cf2ee2Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79046e7d3316Smrg		esac
79056e7d3316Smrg	    fi
79066e7d3316Smrg	  fi
79076e7d3316Smrg	  continue
79086e7d3316Smrg	  ;;
79096e7d3316Smrg	-l*)
7910edce3322Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911edce3322Smrg	    func_warning "'-l' is ignored for archives/objects"
79126e7d3316Smrg	    continue
79136e7d3316Smrg	  fi
79146e7d3316Smrg	  func_stripname '-l' '' "$deplib"
79156e7d3316Smrg	  name=$func_stripname_result
7916edce3322Smrg	  if test lib = "$linkmode"; then
79176e7d3316Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
79186e7d3316Smrg	  else
79196e7d3316Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
79206e7d3316Smrg	  fi
79216e7d3316Smrg	  for searchdir in $searchdirs; do
79226e7d3316Smrg	    for search_ext in .la $std_shrext .so .a; do
79236e7d3316Smrg	      # Search the libtool library
7924edce3322Smrg	      lib=$searchdir/lib$name$search_ext
79256e7d3316Smrg	      if test -f "$lib"; then
7926edce3322Smrg		if test .la = "$search_ext"; then
7927edce3322Smrg		  found=:
79286e7d3316Smrg		else
7929edce3322Smrg		  found=false
79306e7d3316Smrg		fi
79316e7d3316Smrg		break 2
79326e7d3316Smrg	      fi
79336e7d3316Smrg	    done
79346e7d3316Smrg	  done
7935edce3322Smrg	  if $found; then
7936edce3322Smrg	    # deplib is a libtool library
79376e7d3316Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
79386e7d3316Smrg	    # We need to do some special things here, and not later.
7939edce3322Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
79406e7d3316Smrg	      case " $predeps $postdeps " in
79416e7d3316Smrg	      *" $deplib "*)
79426e7d3316Smrg		if func_lalib_p "$lib"; then
79436e7d3316Smrg		  library_names=
79446e7d3316Smrg		  old_library=
79456e7d3316Smrg		  func_source "$lib"
79466e7d3316Smrg		  for l in $old_library $library_names; do
7947edce3322Smrg		    ll=$l
79486e7d3316Smrg		  done
7949edce3322Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950edce3322Smrg		    found=false
79516e7d3316Smrg		    func_dirname "$lib" "" "."
7952edce3322Smrg		    ladir=$func_dirname_result
79536e7d3316Smrg		    lib=$ladir/$old_library
7954edce3322Smrg		    if test prog,link = "$linkmode,$pass"; then
79556e7d3316Smrg		      compile_deplibs="$deplib $compile_deplibs"
79566e7d3316Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
79576e7d3316Smrg		    else
79586e7d3316Smrg		      deplibs="$deplib $deplibs"
7959edce3322Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79606e7d3316Smrg		    fi
79616e7d3316Smrg		    continue
79626e7d3316Smrg		  fi
79636e7d3316Smrg		fi
79646e7d3316Smrg		;;
79656e7d3316Smrg	      *) ;;
79666e7d3316Smrg	      esac
79676e7d3316Smrg	    fi
7968edce3322Smrg	  else
7969edce3322Smrg	    # deplib doesn't seem to be a libtool library
7970edce3322Smrg	    if test prog,link = "$linkmode,$pass"; then
7971edce3322Smrg	      compile_deplibs="$deplib $compile_deplibs"
7972edce3322Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973edce3322Smrg	    else
7974edce3322Smrg	      deplibs="$deplib $deplibs"
7975edce3322Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976edce3322Smrg	    fi
7977edce3322Smrg	    continue
79786e7d3316Smrg	  fi
79796e7d3316Smrg	  ;; # -l
79806e7d3316Smrg	*.ltframework)
7981edce3322Smrg	  if test prog,link = "$linkmode,$pass"; then
79826e7d3316Smrg	    compile_deplibs="$deplib $compile_deplibs"
79836e7d3316Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
79846e7d3316Smrg	  else
79856e7d3316Smrg	    deplibs="$deplib $deplibs"
7986edce3322Smrg	    if test lib = "$linkmode"; then
79876e7d3316Smrg		case "$new_inherited_linker_flags " in
79886e7d3316Smrg		    *" $deplib "*) ;;
798997cf2ee2Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79906e7d3316Smrg		esac
79916e7d3316Smrg	    fi
79926e7d3316Smrg	  fi
79936e7d3316Smrg	  continue
79946e7d3316Smrg	  ;;
79956e7d3316Smrg	-L*)
79966e7d3316Smrg	  case $linkmode in
79976e7d3316Smrg	  lib)
79986e7d3316Smrg	    deplibs="$deplib $deplibs"
7999edce3322Smrg	    test conv = "$pass" && continue
80006e7d3316Smrg	    newdependency_libs="$deplib $newdependency_libs"
80016e7d3316Smrg	    func_stripname '-L' '' "$deplib"
800297cf2ee2Smrg	    func_resolve_sysroot "$func_stripname_result"
800397cf2ee2Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80046e7d3316Smrg	    ;;
80056e7d3316Smrg	  prog)
8006edce3322Smrg	    if test conv = "$pass"; then
80076e7d3316Smrg	      deplibs="$deplib $deplibs"
80086e7d3316Smrg	      continue
80096e7d3316Smrg	    fi
8010edce3322Smrg	    if test scan = "$pass"; then
80116e7d3316Smrg	      deplibs="$deplib $deplibs"
80126e7d3316Smrg	    else
80136e7d3316Smrg	      compile_deplibs="$deplib $compile_deplibs"
80146e7d3316Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80156e7d3316Smrg	    fi
80166e7d3316Smrg	    func_stripname '-L' '' "$deplib"
801797cf2ee2Smrg	    func_resolve_sysroot "$func_stripname_result"
801897cf2ee2Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80196e7d3316Smrg	    ;;
80206e7d3316Smrg	  *)
8021edce3322Smrg	    func_warning "'-L' is ignored for archives/objects"
80226e7d3316Smrg	    ;;
80236e7d3316Smrg	  esac # linkmode
80246e7d3316Smrg	  continue
80256e7d3316Smrg	  ;; # -L
80266e7d3316Smrg	-R*)
8027edce3322Smrg	  if test link = "$pass"; then
80286e7d3316Smrg	    func_stripname '-R' '' "$deplib"
802997cf2ee2Smrg	    func_resolve_sysroot "$func_stripname_result"
803097cf2ee2Smrg	    dir=$func_resolve_sysroot_result
80316e7d3316Smrg	    # Make sure the xrpath contains only unique directories.
80326e7d3316Smrg	    case "$xrpath " in
80336e7d3316Smrg	    *" $dir "*) ;;
803497cf2ee2Smrg	    *) func_append xrpath " $dir" ;;
80356e7d3316Smrg	    esac
80366e7d3316Smrg	  fi
80376e7d3316Smrg	  deplibs="$deplib $deplibs"
80386e7d3316Smrg	  continue
80396e7d3316Smrg	  ;;
804097cf2ee2Smrg	*.la)
804197cf2ee2Smrg	  func_resolve_sysroot "$deplib"
804297cf2ee2Smrg	  lib=$func_resolve_sysroot_result
804397cf2ee2Smrg	  ;;
80446e7d3316Smrg	*.$libext)
8045edce3322Smrg	  if test conv = "$pass"; then
80466e7d3316Smrg	    deplibs="$deplib $deplibs"
80476e7d3316Smrg	    continue
80486e7d3316Smrg	  fi
80496e7d3316Smrg	  case $linkmode in
80506e7d3316Smrg	  lib)
80516e7d3316Smrg	    # Linking convenience modules into shared libraries is allowed,
80526e7d3316Smrg	    # but linking other static libraries is non-portable.
80536e7d3316Smrg	    case " $dlpreconveniencelibs " in
80546e7d3316Smrg	    *" $deplib "*) ;;
80556e7d3316Smrg	    *)
8056edce3322Smrg	      valid_a_lib=false
80576e7d3316Smrg	      case $deplibs_check_method in
80586e7d3316Smrg		match_pattern*)
80596e7d3316Smrg		  set dummy $deplibs_check_method; shift
80606e7d3316Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
80616e7d3316Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
80626e7d3316Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063edce3322Smrg		    valid_a_lib=:
80646e7d3316Smrg		  fi
80656e7d3316Smrg		;;
80666e7d3316Smrg		pass_all)
8067edce3322Smrg		  valid_a_lib=:
80686e7d3316Smrg		;;
80696e7d3316Smrg	      esac
8070edce3322Smrg	      if $valid_a_lib; then
8071edce3322Smrg		echo
8072edce3322Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073edce3322Smrg		$ECHO "*** static library $deplib is not portable!"
8074edce3322Smrg		deplibs="$deplib $deplibs"
8075edce3322Smrg	      else
80766e7d3316Smrg		echo
80776e7d3316Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
80786e7d3316Smrg		echo "*** I have the capability to make that library automatically link in when"
80796e7d3316Smrg		echo "*** you link to this library.  But I can only do this if you have a"
80806e7d3316Smrg		echo "*** shared version of the library, which you do not appear to have"
80816e7d3316Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
80826e7d3316Smrg		echo "*** that it is just a static archive that I should not use here."
80836e7d3316Smrg	      fi
80846e7d3316Smrg	      ;;
80856e7d3316Smrg	    esac
80866e7d3316Smrg	    continue
80876e7d3316Smrg	    ;;
80886e7d3316Smrg	  prog)
8089edce3322Smrg	    if test link != "$pass"; then
80906e7d3316Smrg	      deplibs="$deplib $deplibs"
80916e7d3316Smrg	    else
80926e7d3316Smrg	      compile_deplibs="$deplib $compile_deplibs"
80936e7d3316Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80946e7d3316Smrg	    fi
80956e7d3316Smrg	    continue
80966e7d3316Smrg	    ;;
80976e7d3316Smrg	  esac # linkmode
80986e7d3316Smrg	  ;; # *.$libext
80996e7d3316Smrg	*.lo | *.$objext)
8100edce3322Smrg	  if test conv = "$pass"; then
81016e7d3316Smrg	    deplibs="$deplib $deplibs"
8102edce3322Smrg	  elif test prog = "$linkmode"; then
8103edce3322Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
81046e7d3316Smrg	      # If there is no dlopen support or we're linking statically,
81056e7d3316Smrg	      # we need to preload.
810697cf2ee2Smrg	      func_append newdlprefiles " $deplib"
81076e7d3316Smrg	      compile_deplibs="$deplib $compile_deplibs"
81086e7d3316Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
81096e7d3316Smrg	    else
811097cf2ee2Smrg	      func_append newdlfiles " $deplib"
81116e7d3316Smrg	    fi
81126e7d3316Smrg	  fi
81136e7d3316Smrg	  continue
81146e7d3316Smrg	  ;;
81156e7d3316Smrg	%DEPLIBS%)
8116edce3322Smrg	  alldeplibs=:
81176e7d3316Smrg	  continue
81186e7d3316Smrg	  ;;
81196e7d3316Smrg	esac # case $deplib
81206e7d3316Smrg
8121edce3322Smrg	$found || test -f "$lib" \
8122edce3322Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
81236e7d3316Smrg
81246e7d3316Smrg	# Check to see that this really is a libtool archive.
81256e7d3316Smrg	func_lalib_unsafe_p "$lib" \
8126edce3322Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
81276e7d3316Smrg
81286e7d3316Smrg	func_dirname "$lib" "" "."
8129edce3322Smrg	ladir=$func_dirname_result
81306e7d3316Smrg
81316e7d3316Smrg	dlname=
81326e7d3316Smrg	dlopen=
81336e7d3316Smrg	dlpreopen=
81346e7d3316Smrg	libdir=
81356e7d3316Smrg	library_names=
81366e7d3316Smrg	old_library=
81376e7d3316Smrg	inherited_linker_flags=
81386e7d3316Smrg	# If the library was installed with an old release of libtool,
81396e7d3316Smrg	# it will not redefine variables installed, or shouldnotlink
81406e7d3316Smrg	installed=yes
81416e7d3316Smrg	shouldnotlink=no
81426e7d3316Smrg	avoidtemprpath=
81436e7d3316Smrg
81446e7d3316Smrg
81456e7d3316Smrg	# Read the .la file
81466e7d3316Smrg	func_source "$lib"
81476e7d3316Smrg
81486e7d3316Smrg	# Convert "-framework foo" to "foo.ltframework"
81496e7d3316Smrg	if test -n "$inherited_linker_flags"; then
81506e7d3316Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
81516e7d3316Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
81526e7d3316Smrg	    case " $new_inherited_linker_flags " in
81536e7d3316Smrg	      *" $tmp_inherited_linker_flag "*) ;;
815497cf2ee2Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
81556e7d3316Smrg	    esac
81566e7d3316Smrg	  done
81576e7d3316Smrg	fi
81586e7d3316Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159edce3322Smrg	if test lib,link = "$linkmode,$pass" ||
8160edce3322Smrg	   test prog,scan = "$linkmode,$pass" ||
8161edce3322Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
816297cf2ee2Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
816397cf2ee2Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
81646e7d3316Smrg	fi
81656e7d3316Smrg
8166edce3322Smrg	if test conv = "$pass"; then
81676e7d3316Smrg	  # Only check for convenience libraries
81686e7d3316Smrg	  deplibs="$lib $deplibs"
81696e7d3316Smrg	  if test -z "$libdir"; then
81706e7d3316Smrg	    if test -z "$old_library"; then
8171edce3322Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
81726e7d3316Smrg	    fi
81736e7d3316Smrg	    # It is a libtool convenience library, so add in its objects.
817497cf2ee2Smrg	    func_append convenience " $ladir/$objdir/$old_library"
817597cf2ee2Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176edce3322Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177edce3322Smrg	    func_fatal_error "'$lib' is not a convenience library"
81786e7d3316Smrg	  fi
8179edce3322Smrg	  tmp_libs=
8180edce3322Smrg	  for deplib in $dependency_libs; do
8181edce3322Smrg	    deplibs="$deplib $deplibs"
8182edce3322Smrg	    if $opt_preserve_dup_deps; then
8183edce3322Smrg	      case "$tmp_libs " in
8184edce3322Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185edce3322Smrg	      esac
8186edce3322Smrg	    fi
8187edce3322Smrg	    func_append tmp_libs " $deplib"
8188edce3322Smrg	  done
81896e7d3316Smrg	  continue
81906e7d3316Smrg	fi # $pass = conv
81916e7d3316Smrg
81926e7d3316Smrg
81936e7d3316Smrg	# Get the name of the library we link against.
81946e7d3316Smrg	linklib=
819597cf2ee2Smrg	if test -n "$old_library" &&
8196edce3322Smrg	   { test yes = "$prefer_static_libs" ||
8197edce3322Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
819897cf2ee2Smrg	  linklib=$old_library
819997cf2ee2Smrg	else
820097cf2ee2Smrg	  for l in $old_library $library_names; do
8201edce3322Smrg	    linklib=$l
820297cf2ee2Smrg	  done
820397cf2ee2Smrg	fi
82046e7d3316Smrg	if test -z "$linklib"; then
8205edce3322Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
82066e7d3316Smrg	fi
82076e7d3316Smrg
82086e7d3316Smrg	# This library was specified with -dlopen.
8209edce3322Smrg	if test dlopen = "$pass"; then
8210edce3322Smrg	  test -z "$libdir" \
8211edce3322Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
82126e7d3316Smrg	  if test -z "$dlname" ||
8213edce3322Smrg	     test yes != "$dlopen_support" ||
8214edce3322Smrg	     test no = "$build_libtool_libs"
8215edce3322Smrg	  then
82166e7d3316Smrg	    # If there is no dlname, no dlopen support or we're linking
82176e7d3316Smrg	    # statically, we need to preload.  We also need to preload any
82186e7d3316Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
82196e7d3316Smrg	    # bomb out in the load deplibs phase.
822097cf2ee2Smrg	    func_append dlprefiles " $lib $dependency_libs"
82216e7d3316Smrg	  else
822297cf2ee2Smrg	    func_append newdlfiles " $lib"
82236e7d3316Smrg	  fi
82246e7d3316Smrg	  continue
82256e7d3316Smrg	fi # $pass = dlopen
82266e7d3316Smrg
82276e7d3316Smrg	# We need an absolute path.
82286e7d3316Smrg	case $ladir in
8229edce3322Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
82306e7d3316Smrg	*)
82316e7d3316Smrg	  abs_ladir=`cd "$ladir" && pwd`
82326e7d3316Smrg	  if test -z "$abs_ladir"; then
8233edce3322Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
82346e7d3316Smrg	    func_warning "passing it literally to the linker, although it might fail"
8235edce3322Smrg	    abs_ladir=$ladir
82366e7d3316Smrg	  fi
82376e7d3316Smrg	  ;;
82386e7d3316Smrg	esac
82396e7d3316Smrg	func_basename "$lib"
8240edce3322Smrg	laname=$func_basename_result
82416e7d3316Smrg
82426e7d3316Smrg	# Find the relevant object directory and library name.
8243edce3322Smrg	if test yes = "$installed"; then
824497cf2ee2Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245edce3322Smrg	    func_warning "library '$lib' was moved."
8246edce3322Smrg	    dir=$ladir
8247edce3322Smrg	    absdir=$abs_ladir
8248edce3322Smrg	    libdir=$abs_ladir
82496e7d3316Smrg	  else
8250edce3322Smrg	    dir=$lt_sysroot$libdir
8251edce3322Smrg	    absdir=$lt_sysroot$libdir
82526e7d3316Smrg	  fi
8253edce3322Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
82546e7d3316Smrg	else
82556e7d3316Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256edce3322Smrg	    dir=$ladir
8257edce3322Smrg	    absdir=$abs_ladir
82586e7d3316Smrg	    # Remove this search path later
825997cf2ee2Smrg	    func_append notinst_path " $abs_ladir"
82606e7d3316Smrg	  else
8261edce3322Smrg	    dir=$ladir/$objdir
8262edce3322Smrg	    absdir=$abs_ladir/$objdir
82636e7d3316Smrg	    # Remove this search path later
826497cf2ee2Smrg	    func_append notinst_path " $abs_ladir"
82656e7d3316Smrg	  fi
82666e7d3316Smrg	fi # $installed = yes
82676e7d3316Smrg	func_stripname 'lib' '.la' "$laname"
82686e7d3316Smrg	name=$func_stripname_result
82696e7d3316Smrg
82706e7d3316Smrg	# This library was specified with -dlpreopen.
8271edce3322Smrg	if test dlpreopen = "$pass"; then
8272edce3322Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273edce3322Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
82746e7d3316Smrg	  fi
8275edce3322Smrg	  case $host in
827697cf2ee2Smrg	    # special handling for platforms with PE-DLLs.
827797cf2ee2Smrg	    *cygwin* | *mingw* | *cegcc* )
827897cf2ee2Smrg	      # Linker will automatically link against shared library if both
827997cf2ee2Smrg	      # static and shared are present.  Therefore, ensure we extract
828097cf2ee2Smrg	      # symbols from the import library if a shared library is present
828197cf2ee2Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
828297cf2ee2Smrg	      # this by putting the import library name into $newdlprefiles.
828397cf2ee2Smrg	      # We recover the dlopen module name by 'saving' the la file
828497cf2ee2Smrg	      # name in a special purpose variable, and (later) extracting the
828597cf2ee2Smrg	      # dlname from the la file.
828697cf2ee2Smrg	      if test -n "$dlname"; then
828797cf2ee2Smrg	        func_tr_sh "$dir/$linklib"
828897cf2ee2Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
828997cf2ee2Smrg	        func_append newdlprefiles " $dir/$linklib"
829097cf2ee2Smrg	      else
829197cf2ee2Smrg	        func_append newdlprefiles " $dir/$old_library"
829297cf2ee2Smrg	        # Keep a list of preopened convenience libraries to check
829397cf2ee2Smrg	        # that they are being used correctly in the link pass.
829497cf2ee2Smrg	        test -z "$libdir" && \
829597cf2ee2Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
829697cf2ee2Smrg	      fi
829797cf2ee2Smrg	    ;;
829897cf2ee2Smrg	    * )
829997cf2ee2Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
830097cf2ee2Smrg	      # are required to link).
830197cf2ee2Smrg	      if test -n "$old_library"; then
830297cf2ee2Smrg	        func_append newdlprefiles " $dir/$old_library"
830397cf2ee2Smrg	        # Keep a list of preopened convenience libraries to check
830497cf2ee2Smrg	        # that they are being used correctly in the link pass.
830597cf2ee2Smrg	        test -z "$libdir" && \
830697cf2ee2Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
830797cf2ee2Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
830897cf2ee2Smrg	      elif test -n "$dlname"; then
830997cf2ee2Smrg	        func_append newdlprefiles " $dir/$dlname"
831097cf2ee2Smrg	      else
831197cf2ee2Smrg	        func_append newdlprefiles " $dir/$linklib"
831297cf2ee2Smrg	      fi
831397cf2ee2Smrg	    ;;
831497cf2ee2Smrg	  esac
83156e7d3316Smrg	fi # $pass = dlpreopen
83166e7d3316Smrg
83176e7d3316Smrg	if test -z "$libdir"; then
83186e7d3316Smrg	  # Link the convenience library
8319edce3322Smrg	  if test lib = "$linkmode"; then
83206e7d3316Smrg	    deplibs="$dir/$old_library $deplibs"
8321edce3322Smrg	  elif test prog,link = "$linkmode,$pass"; then
83226e7d3316Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
83236e7d3316Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
83246e7d3316Smrg	  else
83256e7d3316Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
83266e7d3316Smrg	  fi
83276e7d3316Smrg	  continue
83286e7d3316Smrg	fi
83296e7d3316Smrg
83306e7d3316Smrg
8331edce3322Smrg	if test prog = "$linkmode" && test link != "$pass"; then
833297cf2ee2Smrg	  func_append newlib_search_path " $ladir"
83336e7d3316Smrg	  deplibs="$lib $deplibs"
83346e7d3316Smrg
8335edce3322Smrg	  linkalldeplibs=false
8336edce3322Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337edce3322Smrg	     test no = "$build_libtool_libs"; then
8338edce3322Smrg	    linkalldeplibs=:
83396e7d3316Smrg	  fi
83406e7d3316Smrg
83416e7d3316Smrg	  tmp_libs=
83426e7d3316Smrg	  for deplib in $dependency_libs; do
83436e7d3316Smrg	    case $deplib in
83446e7d3316Smrg	    -L*) func_stripname '-L' '' "$deplib"
834597cf2ee2Smrg	         func_resolve_sysroot "$func_stripname_result"
834697cf2ee2Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
83476e7d3316Smrg		 ;;
83486e7d3316Smrg	    esac
83496e7d3316Smrg	    # Need to link against all dependency_libs?
8350edce3322Smrg	    if $linkalldeplibs; then
83516e7d3316Smrg	      deplibs="$deplib $deplibs"
83526e7d3316Smrg	    else
83536e7d3316Smrg	      # Need to hardcode shared library paths
83546e7d3316Smrg	      # or/and link against static libraries
83556e7d3316Smrg	      newdependency_libs="$deplib $newdependency_libs"
83566e7d3316Smrg	    fi
8357edce3322Smrg	    if $opt_preserve_dup_deps; then
83586e7d3316Smrg	      case "$tmp_libs " in
835997cf2ee2Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
83606e7d3316Smrg	      esac
83616e7d3316Smrg	    fi
836297cf2ee2Smrg	    func_append tmp_libs " $deplib"
83636e7d3316Smrg	  done # for deplib
83646e7d3316Smrg	  continue
83656e7d3316Smrg	fi # $linkmode = prog...
83666e7d3316Smrg
8367edce3322Smrg	if test prog,link = "$linkmode,$pass"; then
83686e7d3316Smrg	  if test -n "$library_names" &&
8369edce3322Smrg	     { { test no = "$prefer_static_libs" ||
8370edce3322Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
83716e7d3316Smrg	       test -z "$old_library"; }; then
83726e7d3316Smrg	    # We need to hardcode the library path
8373edce3322Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
83746e7d3316Smrg	      # Make sure the rpath contains only unique directories.
8375edce3322Smrg	      case $temp_rpath: in
83766e7d3316Smrg	      *"$absdir:"*) ;;
837797cf2ee2Smrg	      *) func_append temp_rpath "$absdir:" ;;
83786e7d3316Smrg	      esac
83796e7d3316Smrg	    fi
83806e7d3316Smrg
83816e7d3316Smrg	    # Hardcode the library path.
83826e7d3316Smrg	    # Skip directories that are in the system default run-time
83836e7d3316Smrg	    # search path.
83846e7d3316Smrg	    case " $sys_lib_dlsearch_path " in
83856e7d3316Smrg	    *" $absdir "*) ;;
83866e7d3316Smrg	    *)
83876e7d3316Smrg	      case "$compile_rpath " in
83886e7d3316Smrg	      *" $absdir "*) ;;
838997cf2ee2Smrg	      *) func_append compile_rpath " $absdir" ;;
83906e7d3316Smrg	      esac
83916e7d3316Smrg	      ;;
83926e7d3316Smrg	    esac
83936e7d3316Smrg	    case " $sys_lib_dlsearch_path " in
83946e7d3316Smrg	    *" $libdir "*) ;;
83956e7d3316Smrg	    *)
83966e7d3316Smrg	      case "$finalize_rpath " in
83976e7d3316Smrg	      *" $libdir "*) ;;
839897cf2ee2Smrg	      *) func_append finalize_rpath " $libdir" ;;
83996e7d3316Smrg	      esac
84006e7d3316Smrg	      ;;
84016e7d3316Smrg	    esac
84026e7d3316Smrg	  fi # $linkmode,$pass = prog,link...
84036e7d3316Smrg
8404edce3322Smrg	  if $alldeplibs &&
8405edce3322Smrg	     { test pass_all = "$deplibs_check_method" ||
8406edce3322Smrg	       { test yes = "$build_libtool_libs" &&
84076e7d3316Smrg		 test -n "$library_names"; }; }; then
84086e7d3316Smrg	    # We only need to search for static libraries
84096e7d3316Smrg	    continue
84106e7d3316Smrg	  fi
84116e7d3316Smrg	fi
84126e7d3316Smrg
84136e7d3316Smrg	link_static=no # Whether the deplib will be linked statically
84146e7d3316Smrg	use_static_libs=$prefer_static_libs
8415edce3322Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
84166e7d3316Smrg	  use_static_libs=no
84176e7d3316Smrg	fi
84186e7d3316Smrg	if test -n "$library_names" &&
8419edce3322Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
84206e7d3316Smrg	  case $host in
8421edce3322Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
84226e7d3316Smrg	      # No point in relinking DLLs because paths are not encoded
842397cf2ee2Smrg	      func_append notinst_deplibs " $lib"
84246e7d3316Smrg	      need_relink=no
84256e7d3316Smrg	    ;;
84266e7d3316Smrg	  *)
8427edce3322Smrg	    if test no = "$installed"; then
842897cf2ee2Smrg	      func_append notinst_deplibs " $lib"
84296e7d3316Smrg	      need_relink=yes
84306e7d3316Smrg	    fi
84316e7d3316Smrg	    ;;
84326e7d3316Smrg	  esac
84336e7d3316Smrg	  # This is a shared library
84346e7d3316Smrg
84356e7d3316Smrg	  # Warn about portability, can't link against -module's on some
84366e7d3316Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437edce3322Smrg	  dlopenmodule=
84386e7d3316Smrg	  for dlpremoduletest in $dlprefiles; do
84396e7d3316Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440edce3322Smrg	      dlopenmodule=$dlpremoduletest
84416e7d3316Smrg	      break
84426e7d3316Smrg	    fi
84436e7d3316Smrg	  done
8444edce3322Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
84456e7d3316Smrg	    echo
8446edce3322Smrg	    if test prog = "$linkmode"; then
84476e7d3316Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
84486e7d3316Smrg	    else
84496e7d3316Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
84506e7d3316Smrg	    fi
84516e7d3316Smrg	    $ECHO "*** $linklib is not portable!"
84526e7d3316Smrg	  fi
8453edce3322Smrg	  if test lib = "$linkmode" &&
8454edce3322Smrg	     test yes = "$hardcode_into_libs"; then
84556e7d3316Smrg	    # Hardcode the library path.
84566e7d3316Smrg	    # Skip directories that are in the system default run-time
84576e7d3316Smrg	    # search path.
84586e7d3316Smrg	    case " $sys_lib_dlsearch_path " in
84596e7d3316Smrg	    *" $absdir "*) ;;
84606e7d3316Smrg	    *)
84616e7d3316Smrg	      case "$compile_rpath " in
84626e7d3316Smrg	      *" $absdir "*) ;;
846397cf2ee2Smrg	      *) func_append compile_rpath " $absdir" ;;
84646e7d3316Smrg	      esac
84656e7d3316Smrg	      ;;
84666e7d3316Smrg	    esac
84676e7d3316Smrg	    case " $sys_lib_dlsearch_path " in
84686e7d3316Smrg	    *" $libdir "*) ;;
84696e7d3316Smrg	    *)
84706e7d3316Smrg	      case "$finalize_rpath " in
84716e7d3316Smrg	      *" $libdir "*) ;;
847297cf2ee2Smrg	      *) func_append finalize_rpath " $libdir" ;;
84736e7d3316Smrg	      esac
84746e7d3316Smrg	      ;;
84756e7d3316Smrg	    esac
84766e7d3316Smrg	  fi
84776e7d3316Smrg
84786e7d3316Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
84796e7d3316Smrg	    # figure out the soname
84806e7d3316Smrg	    set dummy $library_names
84816e7d3316Smrg	    shift
8482edce3322Smrg	    realname=$1
84836e7d3316Smrg	    shift
84846e7d3316Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
84856e7d3316Smrg	    # use dlname if we got it. it's perfectly good, no?
84866e7d3316Smrg	    if test -n "$dlname"; then
8487edce3322Smrg	      soname=$dlname
84886e7d3316Smrg	    elif test -n "$soname_spec"; then
84896e7d3316Smrg	      # bleh windows
84906e7d3316Smrg	      case $host in
8491edce3322Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
84926e7d3316Smrg	        func_arith $current - $age
84936e7d3316Smrg		major=$func_arith_result
8494edce3322Smrg		versuffix=-$major
84956e7d3316Smrg		;;
84966e7d3316Smrg	      esac
84976e7d3316Smrg	      eval soname=\"$soname_spec\"
84986e7d3316Smrg	    else
8499edce3322Smrg	      soname=$realname
85006e7d3316Smrg	    fi
85016e7d3316Smrg
85026e7d3316Smrg	    # Make a new name for the extract_expsyms_cmds to use
8503edce3322Smrg	    soroot=$soname
85046e7d3316Smrg	    func_basename "$soroot"
8505edce3322Smrg	    soname=$func_basename_result
85066e7d3316Smrg	    func_stripname 'lib' '.dll' "$soname"
85076e7d3316Smrg	    newlib=libimp-$func_stripname_result.a
85086e7d3316Smrg
85096e7d3316Smrg	    # If the library has no export list, then create one now
85106e7d3316Smrg	    if test -f "$output_objdir/$soname-def"; then :
85116e7d3316Smrg	    else
8512edce3322Smrg	      func_verbose "extracting exported symbol list from '$soname'"
85136e7d3316Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
85146e7d3316Smrg	    fi
85156e7d3316Smrg
85166e7d3316Smrg	    # Create $newlib
85176e7d3316Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8518edce3322Smrg	      func_verbose "generating import library for '$soname'"
85196e7d3316Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
85206e7d3316Smrg	    fi
85216e7d3316Smrg	    # make sure the library variables are pointing to the new library
85226e7d3316Smrg	    dir=$output_objdir
85236e7d3316Smrg	    linklib=$newlib
85246e7d3316Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
85256e7d3316Smrg
8526edce3322Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
85276e7d3316Smrg	    add_shlibpath=
85286e7d3316Smrg	    add_dir=
85296e7d3316Smrg	    add=
85306e7d3316Smrg	    lib_linked=yes
85316e7d3316Smrg	    case $hardcode_action in
85326e7d3316Smrg	    immediate | unsupported)
8533edce3322Smrg	      if test no = "$hardcode_direct"; then
8534edce3322Smrg		add=$dir/$linklib
85356e7d3316Smrg		case $host in
8536edce3322Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537edce3322Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
85386e7d3316Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539edce3322Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
85406e7d3316Smrg		  *-*-darwin* )
8541edce3322Smrg		    # if the lib is a (non-dlopened) module then we cannot
85426e7d3316Smrg		    # link against it, someone is ignoring the earlier warnings
85436e7d3316Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8544edce3322Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
85456e7d3316Smrg		      if test "X$dlopenmodule" != "X$lib"; then
85466e7d3316Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547edce3322Smrg			if test -z "$old_library"; then
85486e7d3316Smrg			  echo
85496e7d3316Smrg			  echo "*** And there doesn't seem to be a static archive available"
85506e7d3316Smrg			  echo "*** The link will probably fail, sorry"
85516e7d3316Smrg			else
8552edce3322Smrg			  add=$dir/$old_library
85536e7d3316Smrg			fi
85546e7d3316Smrg		      elif test -n "$old_library"; then
8555edce3322Smrg			add=$dir/$old_library
85566e7d3316Smrg		      fi
85576e7d3316Smrg		    fi
85586e7d3316Smrg		esac
8559edce3322Smrg	      elif test no = "$hardcode_minus_L"; then
85606e7d3316Smrg		case $host in
8561edce3322Smrg		*-*-sunos*) add_shlibpath=$dir ;;
85626e7d3316Smrg		esac
8563edce3322Smrg		add_dir=-L$dir
8564edce3322Smrg		add=-l$name
8565edce3322Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8566edce3322Smrg		add_shlibpath=$dir
8567edce3322Smrg		add=-l$name
85686e7d3316Smrg	      else
85696e7d3316Smrg		lib_linked=no
85706e7d3316Smrg	      fi
85716e7d3316Smrg	      ;;
85726e7d3316Smrg	    relink)
8573edce3322Smrg	      if test yes = "$hardcode_direct" &&
8574edce3322Smrg	         test no = "$hardcode_direct_absolute"; then
8575edce3322Smrg		add=$dir/$linklib
8576edce3322Smrg	      elif test yes = "$hardcode_minus_L"; then
8577edce3322Smrg		add_dir=-L$absdir
85786e7d3316Smrg		# Try looking first in the location we're being installed to.
85796e7d3316Smrg		if test -n "$inst_prefix_dir"; then
85806e7d3316Smrg		  case $libdir in
85816e7d3316Smrg		    [\\/]*)
858297cf2ee2Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
85836e7d3316Smrg		      ;;
85846e7d3316Smrg		  esac
85856e7d3316Smrg		fi
8586edce3322Smrg		add=-l$name
8587edce3322Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588edce3322Smrg		add_shlibpath=$dir
8589edce3322Smrg		add=-l$name
85906e7d3316Smrg	      else
85916e7d3316Smrg		lib_linked=no
85926e7d3316Smrg	      fi
85936e7d3316Smrg	      ;;
85946e7d3316Smrg	    *) lib_linked=no ;;
85956e7d3316Smrg	    esac
85966e7d3316Smrg
8597edce3322Smrg	    if test yes != "$lib_linked"; then
85986e7d3316Smrg	      func_fatal_configuration "unsupported hardcode properties"
85996e7d3316Smrg	    fi
86006e7d3316Smrg
86016e7d3316Smrg	    if test -n "$add_shlibpath"; then
86026e7d3316Smrg	      case :$compile_shlibpath: in
86036e7d3316Smrg	      *":$add_shlibpath:"*) ;;
860497cf2ee2Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
86056e7d3316Smrg	      esac
86066e7d3316Smrg	    fi
8607edce3322Smrg	    if test prog = "$linkmode"; then
86086e7d3316Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
86096e7d3316Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
86106e7d3316Smrg	    else
86116e7d3316Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86126e7d3316Smrg	      test -n "$add" && deplibs="$add $deplibs"
8613edce3322Smrg	      if test yes != "$hardcode_direct" &&
8614edce3322Smrg		 test yes != "$hardcode_minus_L" &&
8615edce3322Smrg		 test yes = "$hardcode_shlibpath_var"; then
86166e7d3316Smrg		case :$finalize_shlibpath: in
86176e7d3316Smrg		*":$libdir:"*) ;;
861897cf2ee2Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
86196e7d3316Smrg		esac
86206e7d3316Smrg	      fi
86216e7d3316Smrg	    fi
86226e7d3316Smrg	  fi
86236e7d3316Smrg
8624edce3322Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
86256e7d3316Smrg	    add_shlibpath=
86266e7d3316Smrg	    add_dir=
86276e7d3316Smrg	    add=
86286e7d3316Smrg	    # Finalize command for both is simple: just hardcode it.
8629edce3322Smrg	    if test yes = "$hardcode_direct" &&
8630edce3322Smrg	       test no = "$hardcode_direct_absolute"; then
8631edce3322Smrg	      add=$libdir/$linklib
8632edce3322Smrg	    elif test yes = "$hardcode_minus_L"; then
8633edce3322Smrg	      add_dir=-L$libdir
8634edce3322Smrg	      add=-l$name
8635edce3322Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
86366e7d3316Smrg	      case :$finalize_shlibpath: in
86376e7d3316Smrg	      *":$libdir:"*) ;;
863897cf2ee2Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
86396e7d3316Smrg	      esac
8640edce3322Smrg	      add=-l$name
8641edce3322Smrg	    elif test yes = "$hardcode_automatic"; then
86426e7d3316Smrg	      if test -n "$inst_prefix_dir" &&
8643edce3322Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644edce3322Smrg		add=$inst_prefix_dir$libdir/$linklib
86456e7d3316Smrg	      else
8646edce3322Smrg		add=$libdir/$linklib
86476e7d3316Smrg	      fi
86486e7d3316Smrg	    else
86496e7d3316Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650edce3322Smrg	      add_dir=-L$libdir
86516e7d3316Smrg	      # Try looking first in the location we're being installed to.
86526e7d3316Smrg	      if test -n "$inst_prefix_dir"; then
86536e7d3316Smrg		case $libdir in
86546e7d3316Smrg		  [\\/]*)
865597cf2ee2Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
86566e7d3316Smrg		    ;;
86576e7d3316Smrg		esac
86586e7d3316Smrg	      fi
8659edce3322Smrg	      add=-l$name
86606e7d3316Smrg	    fi
86616e7d3316Smrg
8662edce3322Smrg	    if test prog = "$linkmode"; then
86636e7d3316Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
86646e7d3316Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
86656e7d3316Smrg	    else
86666e7d3316Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86676e7d3316Smrg	      test -n "$add" && deplibs="$add $deplibs"
86686e7d3316Smrg	    fi
86696e7d3316Smrg	  fi
8670edce3322Smrg	elif test prog = "$linkmode"; then
86716e7d3316Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
86726e7d3316Smrg	  # is not unsupported.  This is valid on all known static and
86736e7d3316Smrg	  # shared platforms.
8674edce3322Smrg	  if test unsupported != "$hardcode_direct"; then
8675edce3322Smrg	    test -n "$old_library" && linklib=$old_library
86766e7d3316Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
86776e7d3316Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
86786e7d3316Smrg	  else
86796e7d3316Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
86806e7d3316Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
86816e7d3316Smrg	  fi
8682edce3322Smrg	elif test yes = "$build_libtool_libs"; then
86836e7d3316Smrg	  # Not a shared library
8684edce3322Smrg	  if test pass_all != "$deplibs_check_method"; then
86856e7d3316Smrg	    # We're trying link a shared library against a static one
86866e7d3316Smrg	    # but the system doesn't support it.
86876e7d3316Smrg
86886e7d3316Smrg	    # Just print a warning and add the library to dependency_libs so
86896e7d3316Smrg	    # that the program can be linked against the static library.
86906e7d3316Smrg	    echo
8691edce3322Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
86926e7d3316Smrg	    echo "*** I have the capability to make that library automatically link in when"
86936e7d3316Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
86946e7d3316Smrg	    echo "*** shared version of the library, which you do not appear to have."
8695edce3322Smrg	    if test yes = "$module"; then
86966e7d3316Smrg	      echo "*** But as you try to build a module library, libtool will still create "
86976e7d3316Smrg	      echo "*** a static module, that should work as long as the dlopening application"
86986e7d3316Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
86996e7d3316Smrg	      if test -z "$global_symbol_pipe"; then
87006e7d3316Smrg		echo
87016e7d3316Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702edce3322Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
87036e7d3316Smrg		echo "*** not find such a program.  So, this module is probably useless."
8704edce3322Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
87056e7d3316Smrg	      fi
8706edce3322Smrg	      if test no = "$build_old_libs"; then
87076e7d3316Smrg		build_libtool_libs=module
87086e7d3316Smrg		build_old_libs=yes
87096e7d3316Smrg	      else
87106e7d3316Smrg		build_libtool_libs=no
87116e7d3316Smrg	      fi
87126e7d3316Smrg	    fi
87136e7d3316Smrg	  else
87146e7d3316Smrg	    deplibs="$dir/$old_library $deplibs"
87156e7d3316Smrg	    link_static=yes
87166e7d3316Smrg	  fi
87176e7d3316Smrg	fi # link shared/static library?
87186e7d3316Smrg
8719edce3322Smrg	if test lib = "$linkmode"; then
87206e7d3316Smrg	  if test -n "$dependency_libs" &&
8721edce3322Smrg	     { test yes != "$hardcode_into_libs" ||
8722edce3322Smrg	       test yes = "$build_old_libs" ||
8723edce3322Smrg	       test yes = "$link_static"; }; then
87246e7d3316Smrg	    # Extract -R from dependency_libs
87256e7d3316Smrg	    temp_deplibs=
87266e7d3316Smrg	    for libdir in $dependency_libs; do
87276e7d3316Smrg	      case $libdir in
87286e7d3316Smrg	      -R*) func_stripname '-R' '' "$libdir"
87296e7d3316Smrg	           temp_xrpath=$func_stripname_result
87306e7d3316Smrg		   case " $xrpath " in
87316e7d3316Smrg		   *" $temp_xrpath "*) ;;
873297cf2ee2Smrg		   *) func_append xrpath " $temp_xrpath";;
87336e7d3316Smrg		   esac;;
873497cf2ee2Smrg	      *) func_append temp_deplibs " $libdir";;
87356e7d3316Smrg	      esac
87366e7d3316Smrg	    done
8737edce3322Smrg	    dependency_libs=$temp_deplibs
87386e7d3316Smrg	  fi
87396e7d3316Smrg
874097cf2ee2Smrg	  func_append newlib_search_path " $absdir"
87416e7d3316Smrg	  # Link against this library
8742edce3322Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
87436e7d3316Smrg	  # ... and its dependency_libs
87446e7d3316Smrg	  tmp_libs=
87456e7d3316Smrg	  for deplib in $dependency_libs; do
87466e7d3316Smrg	    newdependency_libs="$deplib $newdependency_libs"
874797cf2ee2Smrg	    case $deplib in
874897cf2ee2Smrg              -L*) func_stripname '-L' '' "$deplib"
874997cf2ee2Smrg                   func_resolve_sysroot "$func_stripname_result";;
875097cf2ee2Smrg              *) func_resolve_sysroot "$deplib" ;;
875197cf2ee2Smrg            esac
8752edce3322Smrg	    if $opt_preserve_dup_deps; then
87536e7d3316Smrg	      case "$tmp_libs " in
875497cf2ee2Smrg	      *" $func_resolve_sysroot_result "*)
875597cf2ee2Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
87566e7d3316Smrg	      esac
87576e7d3316Smrg	    fi
875897cf2ee2Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
87596e7d3316Smrg	  done
87606e7d3316Smrg
8761edce3322Smrg	  if test no != "$link_all_deplibs"; then
87626e7d3316Smrg	    # Add the search paths of all dependency libraries
87636e7d3316Smrg	    for deplib in $dependency_libs; do
87646e7d3316Smrg	      path=
87656e7d3316Smrg	      case $deplib in
8766edce3322Smrg	      -L*) path=$deplib ;;
87676e7d3316Smrg	      *.la)
876897cf2ee2Smrg	        func_resolve_sysroot "$deplib"
876997cf2ee2Smrg	        deplib=$func_resolve_sysroot_result
87706e7d3316Smrg	        func_dirname "$deplib" "" "."
877197cf2ee2Smrg		dir=$func_dirname_result
87726e7d3316Smrg		# We need an absolute path.
87736e7d3316Smrg		case $dir in
8774edce3322Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
87756e7d3316Smrg		*)
87766e7d3316Smrg		  absdir=`cd "$dir" && pwd`
87776e7d3316Smrg		  if test -z "$absdir"; then
8778edce3322Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779edce3322Smrg		    absdir=$dir
87806e7d3316Smrg		  fi
87816e7d3316Smrg		  ;;
87826e7d3316Smrg		esac
87836e7d3316Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
87846e7d3316Smrg		case $host in
87856e7d3316Smrg		*-*-darwin*)
87866e7d3316Smrg		  depdepl=
8787edce3322Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788edce3322Smrg		  if test -n "$deplibrary_names"; then
8789edce3322Smrg		    for tmp in $deplibrary_names; do
87906e7d3316Smrg		      depdepl=$tmp
87916e7d3316Smrg		    done
8792edce3322Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793edce3322Smrg		      depdepl=$absdir/$objdir/$depdepl
8794edce3322Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
87956e7d3316Smrg                      if test -z "$darwin_install_name"; then
8796edce3322Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
87976e7d3316Smrg                      fi
8798edce3322Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799edce3322Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
88006e7d3316Smrg		      path=
88016e7d3316Smrg		    fi
88026e7d3316Smrg		  fi
88036e7d3316Smrg		  ;;
88046e7d3316Smrg		*)
8805edce3322Smrg		  path=-L$absdir/$objdir
88066e7d3316Smrg		  ;;
88076e7d3316Smrg		esac
88086e7d3316Smrg		else
8809edce3322Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
88106e7d3316Smrg		  test -z "$libdir" && \
8811edce3322Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
88126e7d3316Smrg		  test "$absdir" != "$libdir" && \
8813edce3322Smrg		    func_warning "'$deplib' seems to be moved"
88146e7d3316Smrg
8815edce3322Smrg		  path=-L$absdir
88166e7d3316Smrg		fi
88176e7d3316Smrg		;;
88186e7d3316Smrg	      esac
88196e7d3316Smrg	      case " $deplibs " in
88206e7d3316Smrg	      *" $path "*) ;;
88216e7d3316Smrg	      *) deplibs="$path $deplibs" ;;
88226e7d3316Smrg	      esac
88236e7d3316Smrg	    done
88246e7d3316Smrg	  fi # link_all_deplibs != no
88256e7d3316Smrg	fi # linkmode = lib
88266e7d3316Smrg      done # for deplib in $libs
8827edce3322Smrg      if test link = "$pass"; then
8828edce3322Smrg	if test prog = "$linkmode"; then
88296e7d3316Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
88306e7d3316Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
88316e7d3316Smrg	else
88326e7d3316Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
88336e7d3316Smrg	fi
88346e7d3316Smrg      fi
8835edce3322Smrg      dependency_libs=$newdependency_libs
8836edce3322Smrg      if test dlpreopen = "$pass"; then
88376e7d3316Smrg	# Link the dlpreopened libraries before other libraries
88386e7d3316Smrg	for deplib in $save_deplibs; do
88396e7d3316Smrg	  deplibs="$deplib $deplibs"
88406e7d3316Smrg	done
88416e7d3316Smrg      fi
8842edce3322Smrg      if test dlopen != "$pass"; then
8843edce3322Smrg	test conv = "$pass" || {
88446e7d3316Smrg	  # Make sure lib_search_path contains only unique directories.
88456e7d3316Smrg	  lib_search_path=
88466e7d3316Smrg	  for dir in $newlib_search_path; do
88476e7d3316Smrg	    case "$lib_search_path " in
88486e7d3316Smrg	    *" $dir "*) ;;
884997cf2ee2Smrg	    *) func_append lib_search_path " $dir" ;;
88506e7d3316Smrg	    esac
88516e7d3316Smrg	  done
88526e7d3316Smrg	  newlib_search_path=
8853edce3322Smrg	}
88546e7d3316Smrg
8855edce3322Smrg	if test prog,link = "$linkmode,$pass"; then
88566e7d3316Smrg	  vars="compile_deplibs finalize_deplibs"
8857edce3322Smrg	else
8858edce3322Smrg	  vars=deplibs
88596e7d3316Smrg	fi
88606e7d3316Smrg	for var in $vars dependency_libs; do
88616e7d3316Smrg	  # Add libraries to $var in reverse order
88626e7d3316Smrg	  eval tmp_libs=\"\$$var\"
88636e7d3316Smrg	  new_libs=
88646e7d3316Smrg	  for deplib in $tmp_libs; do
88656e7d3316Smrg	    # FIXME: Pedantically, this is the right thing to do, so
88666e7d3316Smrg	    #        that some nasty dependency loop isn't accidentally
88676e7d3316Smrg	    #        broken:
88686e7d3316Smrg	    #new_libs="$deplib $new_libs"
88696e7d3316Smrg	    # Pragmatically, this seems to cause very few problems in
88706e7d3316Smrg	    # practice:
88716e7d3316Smrg	    case $deplib in
88726e7d3316Smrg	    -L*) new_libs="$deplib $new_libs" ;;
88736e7d3316Smrg	    -R*) ;;
88746e7d3316Smrg	    *)
88756e7d3316Smrg	      # And here is the reason: when a library appears more
88766e7d3316Smrg	      # than once as an explicit dependence of a library, or
88776e7d3316Smrg	      # is implicitly linked in more than once by the
88786e7d3316Smrg	      # compiler, it is considered special, and multiple
88796e7d3316Smrg	      # occurrences thereof are not removed.  Compare this
88806e7d3316Smrg	      # with having the same library being listed as a
88816e7d3316Smrg	      # dependency of multiple other libraries: in this case,
88826e7d3316Smrg	      # we know (pedantically, we assume) the library does not
88836e7d3316Smrg	      # need to be listed more than once, so we keep only the
88846e7d3316Smrg	      # last copy.  This is not always right, but it is rare
88856e7d3316Smrg	      # enough that we require users that really mean to play
88866e7d3316Smrg	      # such unportable linking tricks to link the library
88876e7d3316Smrg	      # using -Wl,-lname, so that libtool does not consider it
88886e7d3316Smrg	      # for duplicate removal.
88896e7d3316Smrg	      case " $specialdeplibs " in
88906e7d3316Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
88916e7d3316Smrg	      *)
88926e7d3316Smrg		case " $new_libs " in
88936e7d3316Smrg		*" $deplib "*) ;;
88946e7d3316Smrg		*) new_libs="$deplib $new_libs" ;;
88956e7d3316Smrg		esac
88966e7d3316Smrg		;;
88976e7d3316Smrg	      esac
88986e7d3316Smrg	      ;;
88996e7d3316Smrg	    esac
89006e7d3316Smrg	  done
89016e7d3316Smrg	  tmp_libs=
89026e7d3316Smrg	  for deplib in $new_libs; do
89036e7d3316Smrg	    case $deplib in
89046e7d3316Smrg	    -L*)
89056e7d3316Smrg	      case " $tmp_libs " in
89066e7d3316Smrg	      *" $deplib "*) ;;
890797cf2ee2Smrg	      *) func_append tmp_libs " $deplib" ;;
89086e7d3316Smrg	      esac
89096e7d3316Smrg	      ;;
891097cf2ee2Smrg	    *) func_append tmp_libs " $deplib" ;;
89116e7d3316Smrg	    esac
89126e7d3316Smrg	  done
89136e7d3316Smrg	  eval $var=\"$tmp_libs\"
89146e7d3316Smrg	done # for var
89156e7d3316Smrg      fi
8916edce3322Smrg
8917edce3322Smrg      # Add Sun CC postdeps if required:
8918edce3322Smrg      test CXX = "$tagname" && {
8919edce3322Smrg        case $host_os in
8920edce3322Smrg        linux*)
892174835918Smrg          case `$CC -V 2>&1 | $SED 5q` in
8922edce3322Smrg          *Sun\ C*) # Sun C++ 5.9
8923edce3322Smrg            func_suncc_cstd_abi
8924edce3322Smrg
8925edce3322Smrg            if test no != "$suncc_use_cstd_abi"; then
8926edce3322Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8927edce3322Smrg            fi
8928edce3322Smrg            ;;
8929edce3322Smrg          esac
8930edce3322Smrg          ;;
8931edce3322Smrg
8932edce3322Smrg        solaris*)
8933edce3322Smrg          func_cc_basename "$CC"
8934edce3322Smrg          case $func_cc_basename_result in
8935edce3322Smrg          CC* | sunCC*)
8936edce3322Smrg            func_suncc_cstd_abi
8937edce3322Smrg
8938edce3322Smrg            if test no != "$suncc_use_cstd_abi"; then
8939edce3322Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8940edce3322Smrg            fi
8941edce3322Smrg            ;;
8942edce3322Smrg          esac
8943edce3322Smrg          ;;
8944edce3322Smrg        esac
8945edce3322Smrg      }
8946edce3322Smrg
89476e7d3316Smrg      # Last step: remove runtime libs from dependency_libs
89486e7d3316Smrg      # (they stay in deplibs)
89496e7d3316Smrg      tmp_libs=
8950edce3322Smrg      for i in $dependency_libs; do
89516e7d3316Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
89526e7d3316Smrg	*" $i "*)
8953edce3322Smrg	  i=
89546e7d3316Smrg	  ;;
89556e7d3316Smrg	esac
8956edce3322Smrg	if test -n "$i"; then
895797cf2ee2Smrg	  func_append tmp_libs " $i"
89586e7d3316Smrg	fi
89596e7d3316Smrg      done
89606e7d3316Smrg      dependency_libs=$tmp_libs
89616e7d3316Smrg    done # for pass
8962edce3322Smrg    if test prog = "$linkmode"; then
8963edce3322Smrg      dlfiles=$newdlfiles
89646e7d3316Smrg    fi
8965edce3322Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966edce3322Smrg      dlprefiles=$newdlprefiles
89676e7d3316Smrg    fi
89686e7d3316Smrg
89696e7d3316Smrg    case $linkmode in
89706e7d3316Smrg    oldlib)
8971edce3322Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972edce3322Smrg	func_warning "'-dlopen' is ignored for archives"
89736e7d3316Smrg      fi
89746e7d3316Smrg
89756e7d3316Smrg      case " $deplibs" in
89766e7d3316Smrg      *\ -l* | *\ -L*)
8977edce3322Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
89786e7d3316Smrg      esac
89796e7d3316Smrg
89806e7d3316Smrg      test -n "$rpath" && \
8981edce3322Smrg	func_warning "'-rpath' is ignored for archives"
89826e7d3316Smrg
89836e7d3316Smrg      test -n "$xrpath" && \
8984edce3322Smrg	func_warning "'-R' is ignored for archives"
89856e7d3316Smrg
89866e7d3316Smrg      test -n "$vinfo" && \
8987edce3322Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
89886e7d3316Smrg
89896e7d3316Smrg      test -n "$release" && \
8990edce3322Smrg	func_warning "'-release' is ignored for archives"
89916e7d3316Smrg
89926e7d3316Smrg      test -n "$export_symbols$export_symbols_regex" && \
8993edce3322Smrg	func_warning "'-export-symbols' is ignored for archives"
89946e7d3316Smrg
89956e7d3316Smrg      # Now set the variables for building old libraries.
89966e7d3316Smrg      build_libtool_libs=no
8997edce3322Smrg      oldlibs=$output
899897cf2ee2Smrg      func_append objs "$old_deplibs"
89996e7d3316Smrg      ;;
90006e7d3316Smrg
90016e7d3316Smrg    lib)
9002edce3322Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
90036e7d3316Smrg      case $outputname in
90046e7d3316Smrg      lib*)
90056e7d3316Smrg	func_stripname 'lib' '.la' "$outputname"
90066e7d3316Smrg	name=$func_stripname_result
90076e7d3316Smrg	eval shared_ext=\"$shrext_cmds\"
90086e7d3316Smrg	eval libname=\"$libname_spec\"
90096e7d3316Smrg	;;
90106e7d3316Smrg      *)
9011edce3322Smrg	test no = "$module" \
9012edce3322Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
90136e7d3316Smrg
9014edce3322Smrg	if test no != "$need_lib_prefix"; then
90156e7d3316Smrg	  # Add the "lib" prefix for modules if required
90166e7d3316Smrg	  func_stripname '' '.la' "$outputname"
90176e7d3316Smrg	  name=$func_stripname_result
90186e7d3316Smrg	  eval shared_ext=\"$shrext_cmds\"
90196e7d3316Smrg	  eval libname=\"$libname_spec\"
90206e7d3316Smrg	else
90216e7d3316Smrg	  func_stripname '' '.la' "$outputname"
90226e7d3316Smrg	  libname=$func_stripname_result
90236e7d3316Smrg	fi
90246e7d3316Smrg	;;
90256e7d3316Smrg      esac
90266e7d3316Smrg
90276e7d3316Smrg      if test -n "$objs"; then
9028edce3322Smrg	if test pass_all != "$deplibs_check_method"; then
9029edce3322Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
90306e7d3316Smrg	else
90316e7d3316Smrg	  echo
90326e7d3316Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
90336e7d3316Smrg	  $ECHO "*** objects $objs is not portable!"
903497cf2ee2Smrg	  func_append libobjs " $objs"
90356e7d3316Smrg	fi
90366e7d3316Smrg      fi
90376e7d3316Smrg
9038edce3322Smrg      test no = "$dlself" \
9039edce3322Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
90406e7d3316Smrg
90416e7d3316Smrg      set dummy $rpath
90426e7d3316Smrg      shift
9043edce3322Smrg      test 1 -lt "$#" \
9044edce3322Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
90456e7d3316Smrg
9046edce3322Smrg      install_libdir=$1
90476e7d3316Smrg
90486e7d3316Smrg      oldlibs=
90496e7d3316Smrg      if test -z "$rpath"; then
9050edce3322Smrg	if test yes = "$build_libtool_libs"; then
90516e7d3316Smrg	  # Building a libtool convenience library.
9052edce3322Smrg	  # Some compilers have problems with a '.al' extension so
90536e7d3316Smrg	  # convenience libraries should have the same extension an
90546e7d3316Smrg	  # archive normally would.
90556e7d3316Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
90566e7d3316Smrg	  build_libtool_libs=convenience
90576e7d3316Smrg	  build_old_libs=yes
90586e7d3316Smrg	fi
90596e7d3316Smrg
90606e7d3316Smrg	test -n "$vinfo" && \
9061edce3322Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
90626e7d3316Smrg
90636e7d3316Smrg	test -n "$release" && \
9064edce3322Smrg	  func_warning "'-release' is ignored for convenience libraries"
90656e7d3316Smrg      else
90666e7d3316Smrg
90676e7d3316Smrg	# Parse the version information argument.
9068edce3322Smrg	save_ifs=$IFS; IFS=:
90696e7d3316Smrg	set dummy $vinfo 0 0 0
90706e7d3316Smrg	shift
9071edce3322Smrg	IFS=$save_ifs
90726e7d3316Smrg
90736e7d3316Smrg	test -n "$7" && \
9074edce3322Smrg	  func_fatal_help "too many parameters to '-version-info'"
90756e7d3316Smrg
90766e7d3316Smrg	# convert absolute version numbers to libtool ages
90776e7d3316Smrg	# this retains compatibility with .la files and attempts
90786e7d3316Smrg	# to make the code below a bit more comprehensible
90796e7d3316Smrg
90806e7d3316Smrg	case $vinfo_number in
90816e7d3316Smrg	yes)
9082edce3322Smrg	  number_major=$1
9083edce3322Smrg	  number_minor=$2
9084edce3322Smrg	  number_revision=$3
90856e7d3316Smrg	  #
90866e7d3316Smrg	  # There are really only two kinds -- those that
90876e7d3316Smrg	  # use the current revision as the major version
90886e7d3316Smrg	  # and those that subtract age and use age as
90896e7d3316Smrg	  # a minor version.  But, then there is irix
9090edce3322Smrg	  # that has an extra 1 added just for fun
90916e7d3316Smrg	  #
90926e7d3316Smrg	  case $version_type in
9093ac92798bSmrg	  # correct linux to gnu/linux during the next big refactor
909474835918Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
90956e7d3316Smrg	    func_arith $number_major + $number_minor
90966e7d3316Smrg	    current=$func_arith_result
9097edce3322Smrg	    age=$number_minor
9098edce3322Smrg	    revision=$number_revision
90996e7d3316Smrg	    ;;
9100edce3322Smrg	  freebsd-aout|qnx|sunos)
9101edce3322Smrg	    current=$number_major
9102edce3322Smrg	    revision=$number_minor
9103edce3322Smrg	    age=0
91046e7d3316Smrg	    ;;
91056e7d3316Smrg	  irix|nonstopux)
91066e7d3316Smrg	    func_arith $number_major + $number_minor
91076e7d3316Smrg	    current=$func_arith_result
9108edce3322Smrg	    age=$number_minor
9109edce3322Smrg	    revision=$number_minor
91106e7d3316Smrg	    lt_irix_increment=no
91116e7d3316Smrg	    ;;
91126e7d3316Smrg	  esac
91136e7d3316Smrg	  ;;
91146e7d3316Smrg	no)
9115edce3322Smrg	  current=$1
9116edce3322Smrg	  revision=$2
9117edce3322Smrg	  age=$3
91186e7d3316Smrg	  ;;
91196e7d3316Smrg	esac
91206e7d3316Smrg
91216e7d3316Smrg	# Check that each of the things are valid numbers.
91226e7d3316Smrg	case $current in
91236e7d3316Smrg	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]) ;;
91246e7d3316Smrg	*)
9125edce3322Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126edce3322Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91276e7d3316Smrg	  ;;
91286e7d3316Smrg	esac
91296e7d3316Smrg
91306e7d3316Smrg	case $revision in
91316e7d3316Smrg	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]) ;;
91326e7d3316Smrg	*)
9133edce3322Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134edce3322Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91356e7d3316Smrg	  ;;
91366e7d3316Smrg	esac
91376e7d3316Smrg
91386e7d3316Smrg	case $age in
91396e7d3316Smrg	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]) ;;
91406e7d3316Smrg	*)
9141edce3322Smrg	  func_error "AGE '$age' must be a nonnegative integer"
9142edce3322Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91436e7d3316Smrg	  ;;
91446e7d3316Smrg	esac
91456e7d3316Smrg
91466e7d3316Smrg	if test "$age" -gt "$current"; then
9147edce3322Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148edce3322Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91496e7d3316Smrg	fi
91506e7d3316Smrg
91516e7d3316Smrg	# Calculate the version variables.
91526e7d3316Smrg	major=
91536e7d3316Smrg	versuffix=
91546e7d3316Smrg	verstring=
91556e7d3316Smrg	case $version_type in
91566e7d3316Smrg	none) ;;
91576e7d3316Smrg
91586e7d3316Smrg	darwin)
91596e7d3316Smrg	  # Like Linux, but with the current version available in
91606e7d3316Smrg	  # verstring for coding it into the library header
91616e7d3316Smrg	  func_arith $current - $age
91626e7d3316Smrg	  major=.$func_arith_result
9163edce3322Smrg	  versuffix=$major.$age.$revision
91646e7d3316Smrg	  # Darwin ld doesn't like 0 for these options...
91656e7d3316Smrg	  func_arith $current + 1
91666e7d3316Smrg	  minor_current=$func_arith_result
9167edce3322Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91686e7d3316Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169edce3322Smrg          # On Darwin other compilers
9170edce3322Smrg          case $CC in
9171edce3322Smrg              nagfor*)
9172edce3322Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173edce3322Smrg                  ;;
9174edce3322Smrg              *)
9175edce3322Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176edce3322Smrg                  ;;
9177edce3322Smrg          esac
91786e7d3316Smrg	  ;;
91796e7d3316Smrg
91806e7d3316Smrg	freebsd-aout)
9181edce3322Smrg	  major=.$current
9182edce3322Smrg	  versuffix=.$current.$revision
91836e7d3316Smrg	  ;;
91846e7d3316Smrg
918574835918Smrg	freebsd-elf | midnightbsd-elf)
9186edce3322Smrg	  func_arith $current - $age
9187edce3322Smrg	  major=.$func_arith_result
9188edce3322Smrg	  versuffix=$major.$age.$revision
91896e7d3316Smrg	  ;;
91906e7d3316Smrg
91916e7d3316Smrg	irix | nonstopux)
9192edce3322Smrg	  if test no = "$lt_irix_increment"; then
91936e7d3316Smrg	    func_arith $current - $age
91946e7d3316Smrg	  else
91956e7d3316Smrg	    func_arith $current - $age + 1
91966e7d3316Smrg	  fi
91976e7d3316Smrg	  major=$func_arith_result
91986e7d3316Smrg
91996e7d3316Smrg	  case $version_type in
92006e7d3316Smrg	    nonstopux) verstring_prefix=nonstopux ;;
92016e7d3316Smrg	    *)         verstring_prefix=sgi ;;
92026e7d3316Smrg	  esac
9203edce3322Smrg	  verstring=$verstring_prefix$major.$revision
92046e7d3316Smrg
92056e7d3316Smrg	  # Add in all the interfaces that we are compatible with.
92066e7d3316Smrg	  loop=$revision
9207edce3322Smrg	  while test 0 -ne "$loop"; do
92086e7d3316Smrg	    func_arith $revision - $loop
92096e7d3316Smrg	    iface=$func_arith_result
92106e7d3316Smrg	    func_arith $loop - 1
92116e7d3316Smrg	    loop=$func_arith_result
9212edce3322Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
92136e7d3316Smrg	  done
92146e7d3316Smrg
9215edce3322Smrg	  # Before this point, $major must not contain '.'.
92166e7d3316Smrg	  major=.$major
9217edce3322Smrg	  versuffix=$major.$revision
92186e7d3316Smrg	  ;;
92196e7d3316Smrg
9220ac92798bSmrg	linux) # correct to gnu/linux during the next big refactor
92216e7d3316Smrg	  func_arith $current - $age
92226e7d3316Smrg	  major=.$func_arith_result
9223edce3322Smrg	  versuffix=$major.$age.$revision
92246e7d3316Smrg	  ;;
92256e7d3316Smrg
92266e7d3316Smrg	osf)
92276e7d3316Smrg	  func_arith $current - $age
92286e7d3316Smrg	  major=.$func_arith_result
9229edce3322Smrg	  versuffix=.$current.$age.$revision
9230edce3322Smrg	  verstring=$current.$age.$revision
92316e7d3316Smrg
92326e7d3316Smrg	  # Add in all the interfaces that we are compatible with.
92336e7d3316Smrg	  loop=$age
9234edce3322Smrg	  while test 0 -ne "$loop"; do
92356e7d3316Smrg	    func_arith $current - $loop
92366e7d3316Smrg	    iface=$func_arith_result
92376e7d3316Smrg	    func_arith $loop - 1
92386e7d3316Smrg	    loop=$func_arith_result
9239edce3322Smrg	    verstring=$verstring:$iface.0
92406e7d3316Smrg	  done
92416e7d3316Smrg
92426e7d3316Smrg	  # Make executables depend on our current version.
9243edce3322Smrg	  func_append verstring ":$current.0"
92446e7d3316Smrg	  ;;
92456e7d3316Smrg
92466e7d3316Smrg	qnx)
9247edce3322Smrg	  major=.$current
9248edce3322Smrg	  versuffix=.$current
9249edce3322Smrg	  ;;
9250edce3322Smrg
9251edce3322Smrg	sco)
9252edce3322Smrg	  major=.$current
9253edce3322Smrg	  versuffix=.$current
92546e7d3316Smrg	  ;;
92556e7d3316Smrg
92566e7d3316Smrg	sunos)
9257edce3322Smrg	  major=.$current
9258edce3322Smrg	  versuffix=.$current.$revision
92596e7d3316Smrg	  ;;
92606e7d3316Smrg
92616e7d3316Smrg	windows)
92626e7d3316Smrg	  # Use '-' rather than '.', since we only want one
9263edce3322Smrg	  # extension on DOS 8.3 file systems.
92646e7d3316Smrg	  func_arith $current - $age
92656e7d3316Smrg	  major=$func_arith_result
9266edce3322Smrg	  versuffix=-$major
92676e7d3316Smrg	  ;;
92686e7d3316Smrg
92696e7d3316Smrg	*)
9270edce3322Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
92716e7d3316Smrg	  ;;
92726e7d3316Smrg	esac
92736e7d3316Smrg
92746e7d3316Smrg	# Clear the version info if we defaulted, and they specified a release.
92756e7d3316Smrg	if test -z "$vinfo" && test -n "$release"; then
92766e7d3316Smrg	  major=
92776e7d3316Smrg	  case $version_type in
92786e7d3316Smrg	  darwin)
92796e7d3316Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
92806e7d3316Smrg	    # problems, so we reset it completely
92816e7d3316Smrg	    verstring=
92826e7d3316Smrg	    ;;
92836e7d3316Smrg	  *)
9284edce3322Smrg	    verstring=0.0
92856e7d3316Smrg	    ;;
92866e7d3316Smrg	  esac
9287edce3322Smrg	  if test no = "$need_version"; then
92886e7d3316Smrg	    versuffix=
92896e7d3316Smrg	  else
9290edce3322Smrg	    versuffix=.0.0
92916e7d3316Smrg	  fi
92926e7d3316Smrg	fi
92936e7d3316Smrg
92946e7d3316Smrg	# Remove version info from name if versioning should be avoided
9295edce3322Smrg	if test yes,no = "$avoid_version,$need_version"; then
92966e7d3316Smrg	  major=
92976e7d3316Smrg	  versuffix=
9298edce3322Smrg	  verstring=
92996e7d3316Smrg	fi
93006e7d3316Smrg
93016e7d3316Smrg	# Check to see if the archive will have undefined symbols.
9302edce3322Smrg	if test yes = "$allow_undefined"; then
9303edce3322Smrg	  if test unsupported = "$allow_undefined_flag"; then
9304edce3322Smrg	    if test yes = "$build_old_libs"; then
9305edce3322Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306edce3322Smrg	      build_libtool_libs=no
9307edce3322Smrg	    else
9308edce3322Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309edce3322Smrg	    fi
93106e7d3316Smrg	  fi
93116e7d3316Smrg	else
93126e7d3316Smrg	  # Don't allow undefined symbols.
9313edce3322Smrg	  allow_undefined_flag=$no_undefined_flag
93146e7d3316Smrg	fi
93156e7d3316Smrg
93166e7d3316Smrg      fi
93176e7d3316Smrg
9318edce3322Smrg      func_generate_dlsyms "$libname" "$libname" :
931997cf2ee2Smrg      func_append libobjs " $symfileobj"
9320edce3322Smrg      test " " = "$libobjs" && libobjs=
93216e7d3316Smrg
9322edce3322Smrg      if test relink != "$opt_mode"; then
93236e7d3316Smrg	# Remove our outputs, but don't remove object files since they
93246e7d3316Smrg	# may have been created when compiling PIC objects.
93256e7d3316Smrg	removelist=
93266e7d3316Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
93276e7d3316Smrg	for p in $tempremovelist; do
93286e7d3316Smrg	  case $p in
93296e7d3316Smrg	    *.$objext | *.gcno)
93306e7d3316Smrg	       ;;
9331edce3322Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332edce3322Smrg	       if test -n "$precious_files_regex"; then
93336e7d3316Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
93346e7d3316Smrg		 then
93356e7d3316Smrg		   continue
93366e7d3316Smrg		 fi
93376e7d3316Smrg	       fi
933897cf2ee2Smrg	       func_append removelist " $p"
93396e7d3316Smrg	       ;;
93406e7d3316Smrg	    *) ;;
93416e7d3316Smrg	  esac
93426e7d3316Smrg	done
93436e7d3316Smrg	test -n "$removelist" && \
93446e7d3316Smrg	  func_show_eval "${RM}r \$removelist"
93456e7d3316Smrg      fi
93466e7d3316Smrg
93476e7d3316Smrg      # Now set the variables for building old libraries.
9348edce3322Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
934997cf2ee2Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
93506e7d3316Smrg
93516e7d3316Smrg	# Transform .lo files to .o files.
9352edce3322Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
93536e7d3316Smrg      fi
93546e7d3316Smrg
93556e7d3316Smrg      # Eliminate all temporary directories.
93566e7d3316Smrg      #for path in $notinst_path; do
93576e7d3316Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
93586e7d3316Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
93596e7d3316Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
93606e7d3316Smrg      #done
93616e7d3316Smrg
93626e7d3316Smrg      if test -n "$xrpath"; then
93636e7d3316Smrg	# If the user specified any rpath flags, then add them.
93646e7d3316Smrg	temp_xrpath=
93656e7d3316Smrg	for libdir in $xrpath; do
936697cf2ee2Smrg	  func_replace_sysroot "$libdir"
936797cf2ee2Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
93686e7d3316Smrg	  case "$finalize_rpath " in
93696e7d3316Smrg	  *" $libdir "*) ;;
937097cf2ee2Smrg	  *) func_append finalize_rpath " $libdir" ;;
93716e7d3316Smrg	  esac
93726e7d3316Smrg	done
9373edce3322Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
93746e7d3316Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
93756e7d3316Smrg	fi
93766e7d3316Smrg      fi
93776e7d3316Smrg
93786e7d3316Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379edce3322Smrg      old_dlfiles=$dlfiles
93806e7d3316Smrg      dlfiles=
93816e7d3316Smrg      for lib in $old_dlfiles; do
93826e7d3316Smrg	case " $dlprefiles $dlfiles " in
93836e7d3316Smrg	*" $lib "*) ;;
938497cf2ee2Smrg	*) func_append dlfiles " $lib" ;;
93856e7d3316Smrg	esac
93866e7d3316Smrg      done
93876e7d3316Smrg
93886e7d3316Smrg      # Make sure dlprefiles contains only unique files
9389edce3322Smrg      old_dlprefiles=$dlprefiles
93906e7d3316Smrg      dlprefiles=
93916e7d3316Smrg      for lib in $old_dlprefiles; do
93926e7d3316Smrg	case "$dlprefiles " in
93936e7d3316Smrg	*" $lib "*) ;;
939497cf2ee2Smrg	*) func_append dlprefiles " $lib" ;;
93956e7d3316Smrg	esac
93966e7d3316Smrg      done
93976e7d3316Smrg
9398edce3322Smrg      if test yes = "$build_libtool_libs"; then
93996e7d3316Smrg	if test -n "$rpath"; then
94006e7d3316Smrg	  case $host in
94016e7d3316Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
94026e7d3316Smrg	    # these systems don't actually have a c library (as such)!
94036e7d3316Smrg	    ;;
94046e7d3316Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
94056e7d3316Smrg	    # Rhapsody C library is in the System framework
940697cf2ee2Smrg	    func_append deplibs " System.ltframework"
94076e7d3316Smrg	    ;;
94086e7d3316Smrg	  *-*-netbsd*)
94096e7d3316Smrg	    # Don't link with libc until the a.out ld.so is fixed.
94106e7d3316Smrg	    ;;
941174835918Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
94126e7d3316Smrg	    # Do not include libc due to us having libc/libc_r.
94136e7d3316Smrg	    ;;
94146e7d3316Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
94156e7d3316Smrg	    # Causes problems with __ctype
94166e7d3316Smrg	    ;;
94176e7d3316Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
94186e7d3316Smrg	    # Compiler inserts libc in the correct place for threads to work
94196e7d3316Smrg	    ;;
94206e7d3316Smrg	  *)
94216e7d3316Smrg	    # Add libc to deplibs on all other systems if necessary.
9422edce3322Smrg	    if test yes = "$build_libtool_need_lc"; then
942397cf2ee2Smrg	      func_append deplibs " -lc"
94246e7d3316Smrg	    fi
94256e7d3316Smrg	    ;;
94266e7d3316Smrg	  esac
94276e7d3316Smrg	fi
94286e7d3316Smrg
94296e7d3316Smrg	# Transform deplibs into only deplibs that can be linked in shared.
94306e7d3316Smrg	name_save=$name
94316e7d3316Smrg	libname_save=$libname
94326e7d3316Smrg	release_save=$release
94336e7d3316Smrg	versuffix_save=$versuffix
94346e7d3316Smrg	major_save=$major
94356e7d3316Smrg	# I'm not sure if I'm treating the release correctly.  I think
94366e7d3316Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
94376e7d3316Smrg	# add it in twice.  Is that correct?
9438edce3322Smrg	release=
9439edce3322Smrg	versuffix=
9440edce3322Smrg	major=
94416e7d3316Smrg	newdeplibs=
94426e7d3316Smrg	droppeddeps=no
94436e7d3316Smrg	case $deplibs_check_method in
94446e7d3316Smrg	pass_all)
94456e7d3316Smrg	  # Don't check for shared/static.  Everything works.
94466e7d3316Smrg	  # This might be a little naive.  We might want to check
94476e7d3316Smrg	  # whether the library exists or not.  But this is on
94486e7d3316Smrg	  # osf3 & osf4 and I'm not really sure... Just
94496e7d3316Smrg	  # implementing what was already the behavior.
94506e7d3316Smrg	  newdeplibs=$deplibs
94516e7d3316Smrg	  ;;
94526e7d3316Smrg	test_compile)
94536e7d3316Smrg	  # This code stresses the "libraries are programs" paradigm to its
94546e7d3316Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
94556e7d3316Smrg	  # against the deplibs as a proxy for the library.  Then we can check
94566e7d3316Smrg	  # whether they linked in statically or dynamically with ldd.
94576e7d3316Smrg	  $opt_dry_run || $RM conftest.c
94586e7d3316Smrg	  cat > conftest.c <<EOF
94596e7d3316Smrg	  int main() { return 0; }
94606e7d3316SmrgEOF
94616e7d3316Smrg	  $opt_dry_run || $RM conftest
94626e7d3316Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
94636e7d3316Smrg	    ldd_output=`ldd conftest`
94646e7d3316Smrg	    for i in $deplibs; do
94656e7d3316Smrg	      case $i in
94666e7d3316Smrg	      -l*)
94676e7d3316Smrg		func_stripname -l '' "$i"
94686e7d3316Smrg		name=$func_stripname_result
9469edce3322Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94706e7d3316Smrg		  case " $predeps $postdeps " in
94716e7d3316Smrg		  *" $i "*)
947297cf2ee2Smrg		    func_append newdeplibs " $i"
9473edce3322Smrg		    i=
94746e7d3316Smrg		    ;;
94756e7d3316Smrg		  esac
94766e7d3316Smrg		fi
9477edce3322Smrg		if test -n "$i"; then
94786e7d3316Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
94796e7d3316Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
94806e7d3316Smrg		  set dummy $deplib_matches; shift
94816e7d3316Smrg		  deplib_match=$1
9482edce3322Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
948397cf2ee2Smrg		    func_append newdeplibs " $i"
94846e7d3316Smrg		  else
94856e7d3316Smrg		    droppeddeps=yes
94866e7d3316Smrg		    echo
94876e7d3316Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
94886e7d3316Smrg		    echo "*** I have the capability to make that library automatically link in when"
94896e7d3316Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
94906e7d3316Smrg		    echo "*** shared version of the library, which I believe you do not have"
94916e7d3316Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
94926e7d3316Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
94936e7d3316Smrg		  fi
94946e7d3316Smrg		fi
94956e7d3316Smrg		;;
94966e7d3316Smrg	      *)
949797cf2ee2Smrg		func_append newdeplibs " $i"
94986e7d3316Smrg		;;
94996e7d3316Smrg	      esac
95006e7d3316Smrg	    done
95016e7d3316Smrg	  else
95026e7d3316Smrg	    # Error occurred in the first compile.  Let's try to salvage
95036e7d3316Smrg	    # the situation: Compile a separate program for each library.
95046e7d3316Smrg	    for i in $deplibs; do
95056e7d3316Smrg	      case $i in
95066e7d3316Smrg	      -l*)
95076e7d3316Smrg		func_stripname -l '' "$i"
95086e7d3316Smrg		name=$func_stripname_result
95096e7d3316Smrg		$opt_dry_run || $RM conftest
95106e7d3316Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
95116e7d3316Smrg		  ldd_output=`ldd conftest`
9512edce3322Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95136e7d3316Smrg		    case " $predeps $postdeps " in
95146e7d3316Smrg		    *" $i "*)
951597cf2ee2Smrg		      func_append newdeplibs " $i"
9516edce3322Smrg		      i=
95176e7d3316Smrg		      ;;
95186e7d3316Smrg		    esac
95196e7d3316Smrg		  fi
9520edce3322Smrg		  if test -n "$i"; then
95216e7d3316Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
95226e7d3316Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
95236e7d3316Smrg		    set dummy $deplib_matches; shift
95246e7d3316Smrg		    deplib_match=$1
9525edce3322Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
952697cf2ee2Smrg		      func_append newdeplibs " $i"
95276e7d3316Smrg		    else
95286e7d3316Smrg		      droppeddeps=yes
95296e7d3316Smrg		      echo
95306e7d3316Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
95316e7d3316Smrg		      echo "*** I have the capability to make that library automatically link in when"
95326e7d3316Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
95336e7d3316Smrg		      echo "*** shared version of the library, which you do not appear to have"
95346e7d3316Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
95356e7d3316Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
95366e7d3316Smrg		    fi
95376e7d3316Smrg		  fi
95386e7d3316Smrg		else
95396e7d3316Smrg		  droppeddeps=yes
95406e7d3316Smrg		  echo
95416e7d3316Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
95426e7d3316Smrg		  echo "*** make it link in!  You will probably need to install it or some"
95436e7d3316Smrg		  echo "*** library that it depends on before this library will be fully"
95446e7d3316Smrg		  echo "*** functional.  Installing it before continuing would be even better."
95456e7d3316Smrg		fi
95466e7d3316Smrg		;;
95476e7d3316Smrg	      *)
954897cf2ee2Smrg		func_append newdeplibs " $i"
95496e7d3316Smrg		;;
95506e7d3316Smrg	      esac
95516e7d3316Smrg	    done
95526e7d3316Smrg	  fi
95536e7d3316Smrg	  ;;
95546e7d3316Smrg	file_magic*)
95556e7d3316Smrg	  set dummy $deplibs_check_method; shift
95566e7d3316Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
95576e7d3316Smrg	  for a_deplib in $deplibs; do
95586e7d3316Smrg	    case $a_deplib in
95596e7d3316Smrg	    -l*)
95606e7d3316Smrg	      func_stripname -l '' "$a_deplib"
95616e7d3316Smrg	      name=$func_stripname_result
9562edce3322Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95636e7d3316Smrg		case " $predeps $postdeps " in
95646e7d3316Smrg		*" $a_deplib "*)
956597cf2ee2Smrg		  func_append newdeplibs " $a_deplib"
9566edce3322Smrg		  a_deplib=
95676e7d3316Smrg		  ;;
95686e7d3316Smrg		esac
95696e7d3316Smrg	      fi
9570edce3322Smrg	      if test -n "$a_deplib"; then
95716e7d3316Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
957297cf2ee2Smrg		if test -n "$file_magic_glob"; then
957397cf2ee2Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
957497cf2ee2Smrg		else
957597cf2ee2Smrg		  libnameglob=$libname
957697cf2ee2Smrg		fi
9577edce3322Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
95786e7d3316Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579edce3322Smrg		  if test yes = "$want_nocaseglob"; then
958097cf2ee2Smrg		    shopt -s nocaseglob
958197cf2ee2Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958297cf2ee2Smrg		    $nocaseglob
958397cf2ee2Smrg		  else
958497cf2ee2Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958597cf2ee2Smrg		  fi
95866e7d3316Smrg		  for potent_lib in $potential_libs; do
95876e7d3316Smrg		      # Follow soft links.
95886e7d3316Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
95896e7d3316Smrg			 $GREP " -> " >/dev/null; then
95906e7d3316Smrg			continue
95916e7d3316Smrg		      fi
95926e7d3316Smrg		      # The statement above tries to avoid entering an
95936e7d3316Smrg		      # endless loop below, in case of cyclic links.
95946e7d3316Smrg		      # We might still enter an endless loop, since a link
95956e7d3316Smrg		      # loop can be closed while we follow links,
95966e7d3316Smrg		      # but so what?
9597edce3322Smrg		      potlib=$potent_lib
95986e7d3316Smrg		      while test -h "$potlib" 2>/dev/null; do
9599edce3322Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
96006e7d3316Smrg			case $potliblink in
9601edce3322Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602edce3322Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
96036e7d3316Smrg			esac
96046e7d3316Smrg		      done
96056e7d3316Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
96066e7d3316Smrg			 $SED -e 10q |
96076e7d3316Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
960897cf2ee2Smrg			func_append newdeplibs " $a_deplib"
9609edce3322Smrg			a_deplib=
96106e7d3316Smrg			break 2
96116e7d3316Smrg		      fi
96126e7d3316Smrg		  done
96136e7d3316Smrg		done
96146e7d3316Smrg	      fi
9615edce3322Smrg	      if test -n "$a_deplib"; then
96166e7d3316Smrg		droppeddeps=yes
96176e7d3316Smrg		echo
96186e7d3316Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96196e7d3316Smrg		echo "*** I have the capability to make that library automatically link in when"
96206e7d3316Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96216e7d3316Smrg		echo "*** shared version of the library, which you do not appear to have"
96226e7d3316Smrg		echo "*** because I did check the linker path looking for a file starting"
9623edce3322Smrg		if test -z "$potlib"; then
96246e7d3316Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
96256e7d3316Smrg		else
96266e7d3316Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96276e7d3316Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
96286e7d3316Smrg		fi
96296e7d3316Smrg	      fi
96306e7d3316Smrg	      ;;
96316e7d3316Smrg	    *)
96326e7d3316Smrg	      # Add a -L argument.
963397cf2ee2Smrg	      func_append newdeplibs " $a_deplib"
96346e7d3316Smrg	      ;;
96356e7d3316Smrg	    esac
96366e7d3316Smrg	  done # Gone through all deplibs.
96376e7d3316Smrg	  ;;
96386e7d3316Smrg	match_pattern*)
96396e7d3316Smrg	  set dummy $deplibs_check_method; shift
96406e7d3316Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
96416e7d3316Smrg	  for a_deplib in $deplibs; do
96426e7d3316Smrg	    case $a_deplib in
96436e7d3316Smrg	    -l*)
96446e7d3316Smrg	      func_stripname -l '' "$a_deplib"
96456e7d3316Smrg	      name=$func_stripname_result
9646edce3322Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96476e7d3316Smrg		case " $predeps $postdeps " in
96486e7d3316Smrg		*" $a_deplib "*)
964997cf2ee2Smrg		  func_append newdeplibs " $a_deplib"
9650edce3322Smrg		  a_deplib=
96516e7d3316Smrg		  ;;
96526e7d3316Smrg		esac
96536e7d3316Smrg	      fi
9654edce3322Smrg	      if test -n "$a_deplib"; then
96556e7d3316Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
96566e7d3316Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
96576e7d3316Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
96586e7d3316Smrg		  for potent_lib in $potential_libs; do
9659edce3322Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
96606e7d3316Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
96616e7d3316Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
966297cf2ee2Smrg		      func_append newdeplibs " $a_deplib"
9663edce3322Smrg		      a_deplib=
96646e7d3316Smrg		      break 2
96656e7d3316Smrg		    fi
96666e7d3316Smrg		  done
96676e7d3316Smrg		done
96686e7d3316Smrg	      fi
9669edce3322Smrg	      if test -n "$a_deplib"; then
96706e7d3316Smrg		droppeddeps=yes
96716e7d3316Smrg		echo
96726e7d3316Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
96736e7d3316Smrg		echo "*** I have the capability to make that library automatically link in when"
96746e7d3316Smrg		echo "*** you link to this library.  But I can only do this if you have a"
96756e7d3316Smrg		echo "*** shared version of the library, which you do not appear to have"
96766e7d3316Smrg		echo "*** because I did check the linker path looking for a file starting"
9677edce3322Smrg		if test -z "$potlib"; then
96786e7d3316Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
96796e7d3316Smrg		else
96806e7d3316Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96816e7d3316Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
96826e7d3316Smrg		fi
96836e7d3316Smrg	      fi
96846e7d3316Smrg	      ;;
96856e7d3316Smrg	    *)
96866e7d3316Smrg	      # Add a -L argument.
968797cf2ee2Smrg	      func_append newdeplibs " $a_deplib"
96886e7d3316Smrg	      ;;
96896e7d3316Smrg	    esac
96906e7d3316Smrg	  done # Gone through all deplibs.
96916e7d3316Smrg	  ;;
96926e7d3316Smrg	none | unknown | *)
9693edce3322Smrg	  newdeplibs=
96946e7d3316Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695edce3322Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696edce3322Smrg	    for i in $predeps $postdeps; do
96976e7d3316Smrg	      # can't use Xsed below, because $i might contain '/'
9698edce3322Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
96996e7d3316Smrg	    done
97006e7d3316Smrg	  fi
97016e7d3316Smrg	  case $tmp_deplibs in
97026e7d3316Smrg	  *[!\	\ ]*)
97036e7d3316Smrg	    echo
9704edce3322Smrg	    if test none = "$deplibs_check_method"; then
97056e7d3316Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
97066e7d3316Smrg	    else
97076e7d3316Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
97086e7d3316Smrg	    fi
97096e7d3316Smrg	    echo "*** All declared inter-library dependencies are being dropped."
97106e7d3316Smrg	    droppeddeps=yes
97116e7d3316Smrg	    ;;
97126e7d3316Smrg	  esac
97136e7d3316Smrg	  ;;
97146e7d3316Smrg	esac
97156e7d3316Smrg	versuffix=$versuffix_save
97166e7d3316Smrg	major=$major_save
97176e7d3316Smrg	release=$release_save
97186e7d3316Smrg	libname=$libname_save
97196e7d3316Smrg	name=$name_save
97206e7d3316Smrg
97216e7d3316Smrg	case $host in
97226e7d3316Smrg	*-*-rhapsody* | *-*-darwin1.[012])
97236e7d3316Smrg	  # On Rhapsody replace the C library with the System framework
97246e7d3316Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
97256e7d3316Smrg	  ;;
97266e7d3316Smrg	esac
97276e7d3316Smrg
9728edce3322Smrg	if test yes = "$droppeddeps"; then
9729edce3322Smrg	  if test yes = "$module"; then
97306e7d3316Smrg	    echo
97316e7d3316Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
97326e7d3316Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
97336e7d3316Smrg	    echo "*** a static module, that should work as long as the dlopening"
97346e7d3316Smrg	    echo "*** application is linked with the -dlopen flag."
97356e7d3316Smrg	    if test -z "$global_symbol_pipe"; then
97366e7d3316Smrg	      echo
97376e7d3316Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738edce3322Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
97396e7d3316Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9740edce3322Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
97416e7d3316Smrg	    fi
9742edce3322Smrg	    if test no = "$build_old_libs"; then
9743edce3322Smrg	      oldlibs=$output_objdir/$libname.$libext
97446e7d3316Smrg	      build_libtool_libs=module
97456e7d3316Smrg	      build_old_libs=yes
97466e7d3316Smrg	    else
97476e7d3316Smrg	      build_libtool_libs=no
97486e7d3316Smrg	    fi
97496e7d3316Smrg	  else
97506e7d3316Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
97516e7d3316Smrg	    echo "*** automatically added whenever a program is linked with this library"
97526e7d3316Smrg	    echo "*** or is declared to -dlopen it."
97536e7d3316Smrg
9754edce3322Smrg	    if test no = "$allow_undefined"; then
97556e7d3316Smrg	      echo
97566e7d3316Smrg	      echo "*** Since this library must not contain undefined symbols,"
97576e7d3316Smrg	      echo "*** because either the platform does not support them or"
97586e7d3316Smrg	      echo "*** it was explicitly requested with -no-undefined,"
97596e7d3316Smrg	      echo "*** libtool will only create a static version of it."
9760edce3322Smrg	      if test no = "$build_old_libs"; then
9761edce3322Smrg		oldlibs=$output_objdir/$libname.$libext
97626e7d3316Smrg		build_libtool_libs=module
97636e7d3316Smrg		build_old_libs=yes
97646e7d3316Smrg	      else
97656e7d3316Smrg		build_libtool_libs=no
97666e7d3316Smrg	      fi
97676e7d3316Smrg	    fi
97686e7d3316Smrg	  fi
97696e7d3316Smrg	fi
97706e7d3316Smrg	# Done checking deplibs!
97716e7d3316Smrg	deplibs=$newdeplibs
97726e7d3316Smrg      fi
97736e7d3316Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
97746e7d3316Smrg      case $host in
97756e7d3316Smrg	*-*-darwin*)
97766e7d3316Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97776e7d3316Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97786e7d3316Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97796e7d3316Smrg	  ;;
97806e7d3316Smrg      esac
97816e7d3316Smrg
97826e7d3316Smrg      # move library search paths that coincide with paths to not yet
97836e7d3316Smrg      # installed libraries to the beginning of the library search list
97846e7d3316Smrg      new_libs=
97856e7d3316Smrg      for path in $notinst_path; do
97866e7d3316Smrg	case " $new_libs " in
97876e7d3316Smrg	*" -L$path/$objdir "*) ;;
97886e7d3316Smrg	*)
97896e7d3316Smrg	  case " $deplibs " in
97906e7d3316Smrg	  *" -L$path/$objdir "*)
979197cf2ee2Smrg	    func_append new_libs " -L$path/$objdir" ;;
97926e7d3316Smrg	  esac
97936e7d3316Smrg	  ;;
97946e7d3316Smrg	esac
97956e7d3316Smrg      done
97966e7d3316Smrg      for deplib in $deplibs; do
97976e7d3316Smrg	case $deplib in
97986e7d3316Smrg	-L*)
97996e7d3316Smrg	  case " $new_libs " in
98006e7d3316Smrg	  *" $deplib "*) ;;
980197cf2ee2Smrg	  *) func_append new_libs " $deplib" ;;
98026e7d3316Smrg	  esac
98036e7d3316Smrg	  ;;
980497cf2ee2Smrg	*) func_append new_libs " $deplib" ;;
98056e7d3316Smrg	esac
98066e7d3316Smrg      done
9807edce3322Smrg      deplibs=$new_libs
98086e7d3316Smrg
98096e7d3316Smrg      # All the library-specific variables (install_libdir is set above).
98106e7d3316Smrg      library_names=
98116e7d3316Smrg      old_library=
98126e7d3316Smrg      dlname=
98136e7d3316Smrg
98146e7d3316Smrg      # Test again, we may have decided not to build it any more
9815edce3322Smrg      if test yes = "$build_libtool_libs"; then
9816edce3322Smrg	# Remove $wl instances when linking with ld.
9817ac92798bSmrg	# FIXME: should test the right _cmds variable.
9818ac92798bSmrg	case $archive_cmds in
9819ac92798bSmrg	  *\$LD\ *) wl= ;;
9820ac92798bSmrg        esac
9821edce3322Smrg	if test yes = "$hardcode_into_libs"; then
98226e7d3316Smrg	  # Hardcode the library paths
98236e7d3316Smrg	  hardcode_libdirs=
98246e7d3316Smrg	  dep_rpath=
9825edce3322Smrg	  rpath=$finalize_rpath
9826edce3322Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
98276e7d3316Smrg	  for libdir in $rpath; do
98286e7d3316Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
98296e7d3316Smrg	      if test -n "$hardcode_libdir_separator"; then
983097cf2ee2Smrg		func_replace_sysroot "$libdir"
983197cf2ee2Smrg		libdir=$func_replace_sysroot_result
98326e7d3316Smrg		if test -z "$hardcode_libdirs"; then
9833edce3322Smrg		  hardcode_libdirs=$libdir
98346e7d3316Smrg		else
98356e7d3316Smrg		  # Just accumulate the unique libdirs.
98366e7d3316Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
98376e7d3316Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
98386e7d3316Smrg		    ;;
98396e7d3316Smrg		  *)
984097cf2ee2Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
98416e7d3316Smrg		    ;;
98426e7d3316Smrg		  esac
98436e7d3316Smrg		fi
98446e7d3316Smrg	      else
98456e7d3316Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
984697cf2ee2Smrg		func_append dep_rpath " $flag"
98476e7d3316Smrg	      fi
98486e7d3316Smrg	    elif test -n "$runpath_var"; then
98496e7d3316Smrg	      case "$perm_rpath " in
98506e7d3316Smrg	      *" $libdir "*) ;;
9851ac92798bSmrg	      *) func_append perm_rpath " $libdir" ;;
98526e7d3316Smrg	      esac
98536e7d3316Smrg	    fi
98546e7d3316Smrg	  done
98556e7d3316Smrg	  # Substitute the hardcoded libdirs into the rpath.
98566e7d3316Smrg	  if test -n "$hardcode_libdir_separator" &&
98576e7d3316Smrg	     test -n "$hardcode_libdirs"; then
9858edce3322Smrg	    libdir=$hardcode_libdirs
9859ac92798bSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
98606e7d3316Smrg	  fi
98616e7d3316Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
98626e7d3316Smrg	    # We should set the runpath_var.
98636e7d3316Smrg	    rpath=
98646e7d3316Smrg	    for dir in $perm_rpath; do
986597cf2ee2Smrg	      func_append rpath "$dir:"
98666e7d3316Smrg	    done
98676e7d3316Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
98686e7d3316Smrg	  fi
98696e7d3316Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
98706e7d3316Smrg	fi
9871a966c04fSmrg
9872edce3322Smrg	shlibpath=$finalize_shlibpath
9873edce3322Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
98746e7d3316Smrg	if test -n "$shlibpath"; then
98756e7d3316Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
98766e7d3316Smrg	fi
9877a966c04fSmrg
98786e7d3316Smrg	# Get the real and link names of the library.
98796e7d3316Smrg	eval shared_ext=\"$shrext_cmds\"
98806e7d3316Smrg	eval library_names=\"$library_names_spec\"
98816e7d3316Smrg	set dummy $library_names
98826e7d3316Smrg	shift
9883edce3322Smrg	realname=$1
98846e7d3316Smrg	shift
9885a966c04fSmrg
98866e7d3316Smrg	if test -n "$soname_spec"; then
98876e7d3316Smrg	  eval soname=\"$soname_spec\"
98886e7d3316Smrg	else
9889edce3322Smrg	  soname=$realname
98906e7d3316Smrg	fi
98916e7d3316Smrg	if test -z "$dlname"; then
98926e7d3316Smrg	  dlname=$soname
98936e7d3316Smrg	fi
9894a966c04fSmrg
9895edce3322Smrg	lib=$output_objdir/$realname
98966e7d3316Smrg	linknames=
98976e7d3316Smrg	for link
98986e7d3316Smrg	do
989997cf2ee2Smrg	  func_append linknames " $link"
99006e7d3316Smrg	done
9901a966c04fSmrg
99026e7d3316Smrg	# Use standard objects if they are pic
99036e7d3316Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
99046e7d3316Smrg	test "X$libobjs" = "X " && libobjs=
9905a966c04fSmrg
99066e7d3316Smrg	delfiles=
99076e7d3316Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99086e7d3316Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909edce3322Smrg	  export_symbols=$output_objdir/$libname.uexp
991097cf2ee2Smrg	  func_append delfiles " $export_symbols"
99116e7d3316Smrg	fi
9912a966c04fSmrg
99136e7d3316Smrg	orig_export_symbols=
99146e7d3316Smrg	case $host_os in
99156e7d3316Smrg	cygwin* | mingw* | cegcc*)
99166e7d3316Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
99176e7d3316Smrg	    # exporting using user supplied symfile
9918edce3322Smrg	    func_dll_def_p "$export_symbols" || {
99196e7d3316Smrg	      # and it's NOT already a .def file. Must figure out
99206e7d3316Smrg	      # which of the given symbols are data symbols and tag
99216e7d3316Smrg	      # them as such. So, trigger use of export_symbols_cmds.
99226e7d3316Smrg	      # export_symbols gets reassigned inside the "prepare
99236e7d3316Smrg	      # the list of exported symbols" if statement, so the
99246e7d3316Smrg	      # include_expsyms logic still works.
9925edce3322Smrg	      orig_export_symbols=$export_symbols
99266e7d3316Smrg	      export_symbols=
99276e7d3316Smrg	      always_export_symbols=yes
9928edce3322Smrg	    }
99296e7d3316Smrg	  fi
99306e7d3316Smrg	  ;;
99316e7d3316Smrg	esac
9932a966c04fSmrg
99336e7d3316Smrg	# Prepare the list of exported symbols
99346e7d3316Smrg	if test -z "$export_symbols"; then
9935edce3322Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936edce3322Smrg	    func_verbose "generating symbol list for '$libname.la'"
9937edce3322Smrg	    export_symbols=$output_objdir/$libname.exp
99386e7d3316Smrg	    $opt_dry_run || $RM $export_symbols
99396e7d3316Smrg	    cmds=$export_symbols_cmds
9940edce3322Smrg	    save_ifs=$IFS; IFS='~'
994197cf2ee2Smrg	    for cmd1 in $cmds; do
9942edce3322Smrg	      IFS=$save_ifs
994397cf2ee2Smrg	      # Take the normal branch if the nm_file_list_spec branch
994497cf2ee2Smrg	      # doesn't work or if tool conversion is not needed.
994597cf2ee2Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
994697cf2ee2Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
994797cf2ee2Smrg		  try_normal_branch=yes
994897cf2ee2Smrg		  eval cmd=\"$cmd1\"
994997cf2ee2Smrg		  func_len " $cmd"
995097cf2ee2Smrg		  len=$func_len_result
995197cf2ee2Smrg		  ;;
995297cf2ee2Smrg		*)
995397cf2ee2Smrg		  try_normal_branch=no
995497cf2ee2Smrg		  ;;
995597cf2ee2Smrg	      esac
9956edce3322Smrg	      if test yes = "$try_normal_branch" \
995797cf2ee2Smrg		 && { test "$len" -lt "$max_cmd_len" \
995897cf2ee2Smrg		      || test "$max_cmd_len" -le -1; }
995997cf2ee2Smrg	      then
996097cf2ee2Smrg		func_show_eval "$cmd" 'exit $?'
996197cf2ee2Smrg		skipped_export=false
996297cf2ee2Smrg	      elif test -n "$nm_file_list_spec"; then
996397cf2ee2Smrg		func_basename "$output"
996497cf2ee2Smrg		output_la=$func_basename_result
996597cf2ee2Smrg		save_libobjs=$libobjs
996697cf2ee2Smrg		save_output=$output
9967edce3322Smrg		output=$output_objdir/$output_la.nm
996897cf2ee2Smrg		func_to_tool_file "$output"
996997cf2ee2Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
997097cf2ee2Smrg		func_append delfiles " $output"
997197cf2ee2Smrg		func_verbose "creating $NM input file list: $output"
997297cf2ee2Smrg		for obj in $save_libobjs; do
997397cf2ee2Smrg		  func_to_tool_file "$obj"
997497cf2ee2Smrg		  $ECHO "$func_to_tool_file_result"
997597cf2ee2Smrg		done > "$output"
997697cf2ee2Smrg		eval cmd=\"$cmd1\"
99776e7d3316Smrg		func_show_eval "$cmd" 'exit $?'
997897cf2ee2Smrg		output=$save_output
997997cf2ee2Smrg		libobjs=$save_libobjs
99806e7d3316Smrg		skipped_export=false
99816e7d3316Smrg	      else
99826e7d3316Smrg		# The command line is too long to execute in one step.
99836e7d3316Smrg		func_verbose "using reloadable object file for export list..."
99846e7d3316Smrg		skipped_export=:
99856e7d3316Smrg		# Break out early, otherwise skipped_export may be
99866e7d3316Smrg		# set to false by a later but shorter cmd.
99876e7d3316Smrg		break
99886e7d3316Smrg	      fi
99896e7d3316Smrg	    done
9990edce3322Smrg	    IFS=$save_ifs
9991edce3322Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
99926e7d3316Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
99936e7d3316Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
99946e7d3316Smrg	    fi
99956e7d3316Smrg	  fi
99966e7d3316Smrg	fi
9997a966c04fSmrg
99986e7d3316Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999edce3322Smrg	  tmp_export_symbols=$export_symbols
10000edce3322Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
100016e7d3316Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
100026e7d3316Smrg	fi
10003a966c04fSmrg
10004edce3322Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
100056e7d3316Smrg	  # The given exports_symbols file has to be filtered, so filter it.
10006edce3322Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
100076e7d3316Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008edce3322Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
100096e7d3316Smrg	  # though. Also, the filter scales superlinearly with the number of
100106e7d3316Smrg	  # global variables. join(1) would be nice here, but unfortunately
100116e7d3316Smrg	  # isn't a blessed tool.
100126e7d3316Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1001397cf2ee2Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
100146e7d3316Smrg	  export_symbols=$output_objdir/$libname.def
100156e7d3316Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016a966c04fSmrg	fi
10017a966c04fSmrg
100186e7d3316Smrg	tmp_deplibs=
100196e7d3316Smrg	for test_deplib in $deplibs; do
100206e7d3316Smrg	  case " $convenience " in
100216e7d3316Smrg	  *" $test_deplib "*) ;;
100226e7d3316Smrg	  *)
1002397cf2ee2Smrg	    func_append tmp_deplibs " $test_deplib"
100246e7d3316Smrg	    ;;
100256e7d3316Smrg	  esac
100266e7d3316Smrg	done
10027edce3322Smrg	deplibs=$tmp_deplibs
10028a966c04fSmrg
100296e7d3316Smrg	if test -n "$convenience"; then
100306e7d3316Smrg	  if test -n "$whole_archive_flag_spec" &&
10031edce3322Smrg	    test yes = "$compiler_needs_object" &&
100326e7d3316Smrg	    test -z "$libobjs"; then
100336e7d3316Smrg	    # extract the archives, so we have objects to list.
100346e7d3316Smrg	    # TODO: could optimize this to just extract one archive.
100356e7d3316Smrg	    whole_archive_flag_spec=
100366e7d3316Smrg	  fi
100376e7d3316Smrg	  if test -n "$whole_archive_flag_spec"; then
100386e7d3316Smrg	    save_libobjs=$libobjs
100396e7d3316Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
100406e7d3316Smrg	    test "X$libobjs" = "X " && libobjs=
100416e7d3316Smrg	  else
10042edce3322Smrg	    gentop=$output_objdir/${outputname}x
1004397cf2ee2Smrg	    func_append generated " $gentop"
10044a966c04fSmrg
100456e7d3316Smrg	    func_extract_archives $gentop $convenience
1004697cf2ee2Smrg	    func_append libobjs " $func_extract_archives_result"
100476e7d3316Smrg	    test "X$libobjs" = "X " && libobjs=
100486e7d3316Smrg	  fi
100496e7d3316Smrg	fi
10050a966c04fSmrg
10051edce3322Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
100526e7d3316Smrg	  eval flag=\"$thread_safe_flag_spec\"
1005397cf2ee2Smrg	  func_append linker_flags " $flag"
100546e7d3316Smrg	fi
10055a966c04fSmrg
100566e7d3316Smrg	# Make a backup of the uninstalled library when relinking
10057edce3322Smrg	if test relink = "$opt_mode"; then
100586e7d3316Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059a966c04fSmrg	fi
10060a966c04fSmrg
100616e7d3316Smrg	# Do each of the archive commands.
10062edce3322Smrg	if test yes = "$module" && test -n "$module_cmds"; then
100636e7d3316Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
100646e7d3316Smrg	    eval test_cmds=\"$module_expsym_cmds\"
100656e7d3316Smrg	    cmds=$module_expsym_cmds
100666e7d3316Smrg	  else
100676e7d3316Smrg	    eval test_cmds=\"$module_cmds\"
100686e7d3316Smrg	    cmds=$module_cmds
100696e7d3316Smrg	  fi
100706e7d3316Smrg	else
100716e7d3316Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
100726e7d3316Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
100736e7d3316Smrg	    cmds=$archive_expsym_cmds
100746e7d3316Smrg	  else
100756e7d3316Smrg	    eval test_cmds=\"$archive_cmds\"
100766e7d3316Smrg	    cmds=$archive_cmds
100776e7d3316Smrg	  fi
10078a966c04fSmrg	fi
10079a966c04fSmrg
10080edce3322Smrg	if test : != "$skipped_export" &&
100816e7d3316Smrg	   func_len " $test_cmds" &&
100826e7d3316Smrg	   len=$func_len_result &&
100836e7d3316Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
100846e7d3316Smrg	  :
100856e7d3316Smrg	else
100866e7d3316Smrg	  # The command line is too long to link in one step, link piecewise
100876e7d3316Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
100886e7d3316Smrg	  # script.
10089a966c04fSmrg
100906e7d3316Smrg	  # Save the value of $output and $libobjs because we want to
100916e7d3316Smrg	  # use them later.  If we have whole_archive_flag_spec, we
100926e7d3316Smrg	  # want to use save_libobjs as it was before
100936e7d3316Smrg	  # whole_archive_flag_spec was expanded, because we can't
100946e7d3316Smrg	  # assume the linker understands whole_archive_flag_spec.
100956e7d3316Smrg	  # This may have to be revisited, in case too many
100966e7d3316Smrg	  # convenience libraries get linked in and end up exceeding
100976e7d3316Smrg	  # the spec.
100986e7d3316Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
100996e7d3316Smrg	    save_libobjs=$libobjs
101006e7d3316Smrg	  fi
101016e7d3316Smrg	  save_output=$output
101026e7d3316Smrg	  func_basename "$output"
101036e7d3316Smrg	  output_la=$func_basename_result
10104a966c04fSmrg
101056e7d3316Smrg	  # Clear the reloadable object creation command queue and
101066e7d3316Smrg	  # initialize k to one.
101076e7d3316Smrg	  test_cmds=
101086e7d3316Smrg	  concat_cmds=
101096e7d3316Smrg	  objlist=
101106e7d3316Smrg	  last_robj=
101116e7d3316Smrg	  k=1
10112a966c04fSmrg
10113edce3322Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114edce3322Smrg	    output=$output_objdir/$output_la.lnkscript
101156e7d3316Smrg	    func_verbose "creating GNU ld script: $output"
101166e7d3316Smrg	    echo 'INPUT (' > $output
101176e7d3316Smrg	    for obj in $save_libobjs
101186e7d3316Smrg	    do
1011997cf2ee2Smrg	      func_to_tool_file "$obj"
1012097cf2ee2Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101216e7d3316Smrg	    done
101226e7d3316Smrg	    echo ')' >> $output
1012397cf2ee2Smrg	    func_append delfiles " $output"
1012497cf2ee2Smrg	    func_to_tool_file "$output"
1012597cf2ee2Smrg	    output=$func_to_tool_file_result
10126edce3322Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127edce3322Smrg	    output=$output_objdir/$output_la.lnk
101286e7d3316Smrg	    func_verbose "creating linker input file list: $output"
101296e7d3316Smrg	    : > $output
101306e7d3316Smrg	    set x $save_libobjs
101316e7d3316Smrg	    shift
101326e7d3316Smrg	    firstobj=
10133edce3322Smrg	    if test yes = "$compiler_needs_object"; then
101346e7d3316Smrg	      firstobj="$1 "
101356e7d3316Smrg	      shift
101366e7d3316Smrg	    fi
101376e7d3316Smrg	    for obj
101386e7d3316Smrg	    do
1013997cf2ee2Smrg	      func_to_tool_file "$obj"
1014097cf2ee2Smrg	      $ECHO "$func_to_tool_file_result" >> $output
101416e7d3316Smrg	    done
1014297cf2ee2Smrg	    func_append delfiles " $output"
1014397cf2ee2Smrg	    func_to_tool_file "$output"
1014497cf2ee2Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
101456e7d3316Smrg	  else
101466e7d3316Smrg	    if test -n "$save_libobjs"; then
101476e7d3316Smrg	      func_verbose "creating reloadable object files..."
10148edce3322Smrg	      output=$output_objdir/$output_la-$k.$objext
101496e7d3316Smrg	      eval test_cmds=\"$reload_cmds\"
101506e7d3316Smrg	      func_len " $test_cmds"
101516e7d3316Smrg	      len0=$func_len_result
101526e7d3316Smrg	      len=$len0
101536e7d3316Smrg
101546e7d3316Smrg	      # Loop over the list of objects to be linked.
101556e7d3316Smrg	      for obj in $save_libobjs
101566e7d3316Smrg	      do
101576e7d3316Smrg		func_len " $obj"
101586e7d3316Smrg		func_arith $len + $func_len_result
101596e7d3316Smrg		len=$func_arith_result
10160edce3322Smrg		if test -z "$objlist" ||
101616e7d3316Smrg		   test "$len" -lt "$max_cmd_len"; then
101626e7d3316Smrg		  func_append objlist " $obj"
101636e7d3316Smrg		else
101646e7d3316Smrg		  # The command $test_cmds is almost too long, add a
101656e7d3316Smrg		  # command to the queue.
10166edce3322Smrg		  if test 1 -eq "$k"; then
101676e7d3316Smrg		    # The first file doesn't have a previous command to add.
101686e7d3316Smrg		    reload_objs=$objlist
101696e7d3316Smrg		    eval concat_cmds=\"$reload_cmds\"
101706e7d3316Smrg		  else
101716e7d3316Smrg		    # All subsequent reloadable object files will link in
101726e7d3316Smrg		    # the last one created.
101736e7d3316Smrg		    reload_objs="$objlist $last_robj"
101746e7d3316Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
101756e7d3316Smrg		  fi
10176edce3322Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
101776e7d3316Smrg		  func_arith $k + 1
101786e7d3316Smrg		  k=$func_arith_result
10179edce3322Smrg		  output=$output_objdir/$output_la-$k.$objext
101806e7d3316Smrg		  objlist=" $obj"
101816e7d3316Smrg		  func_len " $last_robj"
101826e7d3316Smrg		  func_arith $len0 + $func_len_result
101836e7d3316Smrg		  len=$func_arith_result
101846e7d3316Smrg		fi
101856e7d3316Smrg	      done
101866e7d3316Smrg	      # Handle the remaining objects by creating one last
101876e7d3316Smrg	      # reloadable object file.  All subsequent reloadable object
101886e7d3316Smrg	      # files will link in the last one created.
101896e7d3316Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
101906e7d3316Smrg	      reload_objs="$objlist $last_robj"
10191edce3322Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
101926e7d3316Smrg	      if test -n "$last_robj"; then
10193edce3322Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
101946e7d3316Smrg	      fi
1019597cf2ee2Smrg	      func_append delfiles " $output"
101966e7d3316Smrg
101976e7d3316Smrg	    else
101986e7d3316Smrg	      output=
101996e7d3316Smrg	    fi
10200a966c04fSmrg
10201edce3322Smrg	    ${skipped_export-false} && {
10202edce3322Smrg	      func_verbose "generating symbol list for '$libname.la'"
10203edce3322Smrg	      export_symbols=$output_objdir/$libname.exp
102046e7d3316Smrg	      $opt_dry_run || $RM $export_symbols
102056e7d3316Smrg	      libobjs=$output
102066e7d3316Smrg	      # Append the command to create the export file.
102076e7d3316Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
102086e7d3316Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
102096e7d3316Smrg	      if test -n "$last_robj"; then
102106e7d3316Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
102116e7d3316Smrg	      fi
10212edce3322Smrg	    }
10213a966c04fSmrg
102146e7d3316Smrg	    test -n "$save_libobjs" &&
102156e7d3316Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216a966c04fSmrg
102176e7d3316Smrg	    # Loop through the commands generated above and execute them.
10218edce3322Smrg	    save_ifs=$IFS; IFS='~'
102196e7d3316Smrg	    for cmd in $concat_cmds; do
10220edce3322Smrg	      IFS=$save_ifs
10221edce3322Smrg	      $opt_quiet || {
1022274835918Smrg		  func_quote_arg expand,pretty "$cmd"
1022374835918Smrg		  eval "func_echo $func_quote_arg_result"
102246e7d3316Smrg	      }
102256e7d3316Smrg	      $opt_dry_run || eval "$cmd" || {
102266e7d3316Smrg		lt_exit=$?
102276e7d3316Smrg
102286e7d3316Smrg		# Restore the uninstalled library and exit
10229edce3322Smrg		if test relink = "$opt_mode"; then
102306e7d3316Smrg		  ( cd "$output_objdir" && \
102316e7d3316Smrg		    $RM "${realname}T" && \
102326e7d3316Smrg		    $MV "${realname}U" "$realname" )
102336e7d3316Smrg		fi
10234a966c04fSmrg
102356e7d3316Smrg		exit $lt_exit
102366e7d3316Smrg	      }
102376e7d3316Smrg	    done
10238edce3322Smrg	    IFS=$save_ifs
10239a966c04fSmrg
102406e7d3316Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
102416e7d3316Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
102426e7d3316Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243a966c04fSmrg	    fi
10244a966c04fSmrg	  fi
10245a966c04fSmrg
10246edce3322Smrg          ${skipped_export-false} && {
102476e7d3316Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248edce3322Smrg	      tmp_export_symbols=$export_symbols
10249edce3322Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
102506e7d3316Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
102516e7d3316Smrg	    fi
10252a966c04fSmrg
102536e7d3316Smrg	    if test -n "$orig_export_symbols"; then
102546e7d3316Smrg	      # The given exports_symbols file has to be filtered, so filter it.
10255edce3322Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
102566e7d3316Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257edce3322Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
102586e7d3316Smrg	      # though. Also, the filter scales superlinearly with the number of
102596e7d3316Smrg	      # global variables. join(1) would be nice here, but unfortunately
102606e7d3316Smrg	      # isn't a blessed tool.
102616e7d3316Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1026297cf2ee2Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
102636e7d3316Smrg	      export_symbols=$output_objdir/$libname.def
102646e7d3316Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
102656e7d3316Smrg	    fi
10266edce3322Smrg	  }
10267a966c04fSmrg
102686e7d3316Smrg	  libobjs=$output
102696e7d3316Smrg	  # Restore the value of output.
102706e7d3316Smrg	  output=$save_output
10271a966c04fSmrg
102726e7d3316Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
102736e7d3316Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
102746e7d3316Smrg	    test "X$libobjs" = "X " && libobjs=
102756e7d3316Smrg	  fi
102766e7d3316Smrg	  # Expand the library linking commands again to reset the
102776e7d3316Smrg	  # value of $libobjs for piecewise linking.
102786e7d3316Smrg
102796e7d3316Smrg	  # Do each of the archive commands.
10280edce3322Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
102816e7d3316Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
102826e7d3316Smrg	      cmds=$module_expsym_cmds
10283a966c04fSmrg	    else
102846e7d3316Smrg	      cmds=$module_cmds
10285a966c04fSmrg	    fi
10286a966c04fSmrg	  else
102876e7d3316Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
102886e7d3316Smrg	      cmds=$archive_expsym_cmds
102896e7d3316Smrg	    else
102906e7d3316Smrg	      cmds=$archive_cmds
102916e7d3316Smrg	    fi
10292a966c04fSmrg	  fi
10293a966c04fSmrg	fi
10294a966c04fSmrg
102956e7d3316Smrg	if test -n "$delfiles"; then
102966e7d3316Smrg	  # Append the command to remove temporary files to $cmds.
102976e7d3316Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
102986e7d3316Smrg	fi
10299a966c04fSmrg
103006e7d3316Smrg	# Add any objects from preloaded convenience libraries
103016e7d3316Smrg	if test -n "$dlprefiles"; then
10302edce3322Smrg	  gentop=$output_objdir/${outputname}x
1030397cf2ee2Smrg	  func_append generated " $gentop"
10304a966c04fSmrg
103056e7d3316Smrg	  func_extract_archives $gentop $dlprefiles
1030697cf2ee2Smrg	  func_append libobjs " $func_extract_archives_result"
103076e7d3316Smrg	  test "X$libobjs" = "X " && libobjs=
10308a966c04fSmrg	fi
10309a966c04fSmrg
10310edce3322Smrg	save_ifs=$IFS; IFS='~'
103116e7d3316Smrg	for cmd in $cmds; do
10312edce3322Smrg	  IFS=$sp$nl
103136e7d3316Smrg	  eval cmd=\"$cmd\"
10314edce3322Smrg	  IFS=$save_ifs
10315edce3322Smrg	  $opt_quiet || {
1031674835918Smrg	    func_quote_arg expand,pretty "$cmd"
1031774835918Smrg	    eval "func_echo $func_quote_arg_result"
103186e7d3316Smrg	  }
103196e7d3316Smrg	  $opt_dry_run || eval "$cmd" || {
103206e7d3316Smrg	    lt_exit=$?
10321a966c04fSmrg
103226e7d3316Smrg	    # Restore the uninstalled library and exit
10323edce3322Smrg	    if test relink = "$opt_mode"; then
103246e7d3316Smrg	      ( cd "$output_objdir" && \
103256e7d3316Smrg	        $RM "${realname}T" && \
103266e7d3316Smrg		$MV "${realname}U" "$realname" )
10327a966c04fSmrg	    fi
10328a966c04fSmrg
103296e7d3316Smrg	    exit $lt_exit
103306e7d3316Smrg	  }
103316e7d3316Smrg	done
10332edce3322Smrg	IFS=$save_ifs
10333a966c04fSmrg
103346e7d3316Smrg	# Restore the uninstalled library and exit
10335edce3322Smrg	if test relink = "$opt_mode"; then
103366e7d3316Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337a966c04fSmrg
103386e7d3316Smrg	  if test -n "$convenience"; then
103396e7d3316Smrg	    if test -z "$whole_archive_flag_spec"; then
103406e7d3316Smrg	      func_show_eval '${RM}r "$gentop"'
103416e7d3316Smrg	    fi
103426e7d3316Smrg	  fi
10343a966c04fSmrg
103446e7d3316Smrg	  exit $EXIT_SUCCESS
103456e7d3316Smrg	fi
10346a966c04fSmrg
103476e7d3316Smrg	# Create links to the real library.
103486e7d3316Smrg	for linkname in $linknames; do
103496e7d3316Smrg	  if test "$realname" != "$linkname"; then
103506e7d3316Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
103516e7d3316Smrg	  fi
103526e7d3316Smrg	done
10353a966c04fSmrg
103546e7d3316Smrg	# If -module or -export-dynamic was specified, set the dlname.
10355edce3322Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
103566e7d3316Smrg	  # On all known operating systems, these are identical.
10357edce3322Smrg	  dlname=$soname
103586e7d3316Smrg	fi
103596e7d3316Smrg      fi
103606e7d3316Smrg      ;;
10361a966c04fSmrg
103626e7d3316Smrg    obj)
10363edce3322Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364edce3322Smrg	func_warning "'-dlopen' is ignored for objects"
103656e7d3316Smrg      fi
10366a966c04fSmrg
103676e7d3316Smrg      case " $deplibs" in
103686e7d3316Smrg      *\ -l* | *\ -L*)
10369edce3322Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
103706e7d3316Smrg      esac
10371a966c04fSmrg
103726e7d3316Smrg      test -n "$rpath" && \
10373edce3322Smrg	func_warning "'-rpath' is ignored for objects"
10374a966c04fSmrg
103756e7d3316Smrg      test -n "$xrpath" && \
10376edce3322Smrg	func_warning "'-R' is ignored for objects"
103776e7d3316Smrg
103786e7d3316Smrg      test -n "$vinfo" && \
10379edce3322Smrg	func_warning "'-version-info' is ignored for objects"
10380a966c04fSmrg
103816e7d3316Smrg      test -n "$release" && \
10382edce3322Smrg	func_warning "'-release' is ignored for objects"
10383a966c04fSmrg
103846e7d3316Smrg      case $output in
103856e7d3316Smrg      *.lo)
103866e7d3316Smrg	test -n "$objs$old_deplibs" && \
10387edce3322Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
103886e7d3316Smrg
103896e7d3316Smrg	libobj=$output
103906e7d3316Smrg	func_lo2o "$libobj"
103916e7d3316Smrg	obj=$func_lo2o_result
103926e7d3316Smrg	;;
103936e7d3316Smrg      *)
103946e7d3316Smrg	libobj=
10395edce3322Smrg	obj=$output
10396a966c04fSmrg	;;
10397a966c04fSmrg      esac
10398a966c04fSmrg
103996e7d3316Smrg      # Delete the old objects.
104006e7d3316Smrg      $opt_dry_run || $RM $obj $libobj
10401a966c04fSmrg
104026e7d3316Smrg      # Objects from convenience libraries.  This assumes
104036e7d3316Smrg      # single-version convenience libraries.  Whenever we create
104046e7d3316Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
104056e7d3316Smrg      # the extraction.
104066e7d3316Smrg      reload_conv_objs=
104076e7d3316Smrg      gentop=
10408edce3322Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409edce3322Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410edce3322Smrg      # into space.
10411edce3322Smrg      case $reload_cmds in
10412edce3322Smrg        *\$LD[\ \$]*) wl= ;;
10413edce3322Smrg      esac
104146e7d3316Smrg      if test -n "$convenience"; then
104156e7d3316Smrg	if test -n "$whole_archive_flag_spec"; then
104166e7d3316Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417edce3322Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418edce3322Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419a966c04fSmrg	else
10420edce3322Smrg	  gentop=$output_objdir/${obj}x
1042197cf2ee2Smrg	  func_append generated " $gentop"
104226e7d3316Smrg
104236e7d3316Smrg	  func_extract_archives $gentop $convenience
104246e7d3316Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425a966c04fSmrg	fi
104266e7d3316Smrg      fi
10427a966c04fSmrg
1042897cf2ee2Smrg      # If we're not building shared, we need to use non_pic_objs
10429edce3322Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
1043097cf2ee2Smrg
104316e7d3316Smrg      # Create the old-style object.
10432edce3322Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433a966c04fSmrg
10434edce3322Smrg      output=$obj
104356e7d3316Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436a966c04fSmrg
104376e7d3316Smrg      # Exit if we aren't doing a library object file.
104386e7d3316Smrg      if test -z "$libobj"; then
104396e7d3316Smrg	if test -n "$gentop"; then
104406e7d3316Smrg	  func_show_eval '${RM}r "$gentop"'
104416e7d3316Smrg	fi
10442a966c04fSmrg
104436e7d3316Smrg	exit $EXIT_SUCCESS
10444a966c04fSmrg      fi
10445a966c04fSmrg
10446edce3322Smrg      test yes = "$build_libtool_libs" || {
104476e7d3316Smrg	if test -n "$gentop"; then
104486e7d3316Smrg	  func_show_eval '${RM}r "$gentop"'
104496e7d3316Smrg	fi
10450a966c04fSmrg
104516e7d3316Smrg	# Create an invalid libtool object if no PIC, so that we don't
104526e7d3316Smrg	# accidentally link it into a program.
104536e7d3316Smrg	# $show "echo timestamp > $libobj"
104546e7d3316Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
104556e7d3316Smrg	exit $EXIT_SUCCESS
10456edce3322Smrg      }
10457a966c04fSmrg
10458edce3322Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
104596e7d3316Smrg	# Only do commands if we really have different PIC objects.
104606e7d3316Smrg	reload_objs="$libobjs $reload_conv_objs"
10461edce3322Smrg	output=$libobj
104626e7d3316Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463a966c04fSmrg      fi
104646e7d3316Smrg
104656e7d3316Smrg      if test -n "$gentop"; then
104666e7d3316Smrg	func_show_eval '${RM}r "$gentop"'
104676e7d3316Smrg      fi
104686e7d3316Smrg
104696e7d3316Smrg      exit $EXIT_SUCCESS
10470a966c04fSmrg      ;;
10471a966c04fSmrg
104726e7d3316Smrg    prog)
104736e7d3316Smrg      case $host in
104746e7d3316Smrg	*cygwin*) func_stripname '' '.exe' "$output"
104756e7d3316Smrg	          output=$func_stripname_result.exe;;
104766e7d3316Smrg      esac
104776e7d3316Smrg      test -n "$vinfo" && \
10478edce3322Smrg	func_warning "'-version-info' is ignored for programs"
10479a966c04fSmrg
104806e7d3316Smrg      test -n "$release" && \
10481edce3322Smrg	func_warning "'-release' is ignored for programs"
10482a966c04fSmrg
10483edce3322Smrg      $preload \
10484edce3322Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485edce3322Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
104866e7d3316Smrg
104876e7d3316Smrg      case $host in
104886e7d3316Smrg      *-*-rhapsody* | *-*-darwin1.[012])
104896e7d3316Smrg	# On Rhapsody replace the C library is the System framework
104906e7d3316Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
104916e7d3316Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492a966c04fSmrg	;;
104936e7d3316Smrg      esac
10494a966c04fSmrg
104956e7d3316Smrg      case $host in
104966e7d3316Smrg      *-*-darwin*)
104976e7d3316Smrg	# Don't allow lazy linking, it breaks C++ global constructors
104986e7d3316Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10499edce3322Smrg	if test CXX = "$tagname"; then
105006e7d3316Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
105016e7d3316Smrg	    10.[0123])
10502edce3322Smrg	      func_append compile_command " $wl-bind_at_load"
10503edce3322Smrg	      func_append finalize_command " $wl-bind_at_load"
105046e7d3316Smrg	    ;;
105056e7d3316Smrg	  esac
10506a966c04fSmrg	fi
105076e7d3316Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
105086e7d3316Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105096e7d3316Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105106e7d3316Smrg	;;
105116e7d3316Smrg      esac
10512a966c04fSmrg
10513a966c04fSmrg
105146e7d3316Smrg      # move library search paths that coincide with paths to not yet
105156e7d3316Smrg      # installed libraries to the beginning of the library search list
105166e7d3316Smrg      new_libs=
105176e7d3316Smrg      for path in $notinst_path; do
105186e7d3316Smrg	case " $new_libs " in
105196e7d3316Smrg	*" -L$path/$objdir "*) ;;
105206e7d3316Smrg	*)
105216e7d3316Smrg	  case " $compile_deplibs " in
105226e7d3316Smrg	  *" -L$path/$objdir "*)
1052397cf2ee2Smrg	    func_append new_libs " -L$path/$objdir" ;;
10524a966c04fSmrg	  esac
105256e7d3316Smrg	  ;;
105266e7d3316Smrg	esac
105276e7d3316Smrg      done
105286e7d3316Smrg      for deplib in $compile_deplibs; do
105296e7d3316Smrg	case $deplib in
105306e7d3316Smrg	-L*)
105316e7d3316Smrg	  case " $new_libs " in
105326e7d3316Smrg	  *" $deplib "*) ;;
1053397cf2ee2Smrg	  *) func_append new_libs " $deplib" ;;
10534a966c04fSmrg	  esac
105356e7d3316Smrg	  ;;
1053697cf2ee2Smrg	*) func_append new_libs " $deplib" ;;
105376e7d3316Smrg	esac
105386e7d3316Smrg      done
10539edce3322Smrg      compile_deplibs=$new_libs
10540a966c04fSmrg
10541a966c04fSmrg
1054297cf2ee2Smrg      func_append compile_command " $compile_deplibs"
1054397cf2ee2Smrg      func_append finalize_command " $finalize_deplibs"
10544a966c04fSmrg
105456e7d3316Smrg      if test -n "$rpath$xrpath"; then
105466e7d3316Smrg	# If the user specified any rpath flags, then add them.
105476e7d3316Smrg	for libdir in $rpath $xrpath; do
105486e7d3316Smrg	  # This is the magic to use -rpath.
105496e7d3316Smrg	  case "$finalize_rpath " in
105506e7d3316Smrg	  *" $libdir "*) ;;
1055197cf2ee2Smrg	  *) func_append finalize_rpath " $libdir" ;;
105526e7d3316Smrg	  esac
105536e7d3316Smrg	done
105546e7d3316Smrg      fi
10555a966c04fSmrg
105566e7d3316Smrg      # Now hardcode the library paths
105576e7d3316Smrg      rpath=
105586e7d3316Smrg      hardcode_libdirs=
105596e7d3316Smrg      for libdir in $compile_rpath $finalize_rpath; do
105606e7d3316Smrg	if test -n "$hardcode_libdir_flag_spec"; then
105616e7d3316Smrg	  if test -n "$hardcode_libdir_separator"; then
105626e7d3316Smrg	    if test -z "$hardcode_libdirs"; then
10563edce3322Smrg	      hardcode_libdirs=$libdir
105646e7d3316Smrg	    else
105656e7d3316Smrg	      # Just accumulate the unique libdirs.
105666e7d3316Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
105676e7d3316Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
105686e7d3316Smrg		;;
105696e7d3316Smrg	      *)
1057097cf2ee2Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
105716e7d3316Smrg		;;
105726e7d3316Smrg	      esac
105736e7d3316Smrg	    fi
10574a966c04fSmrg	  else
105756e7d3316Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1057697cf2ee2Smrg	    func_append rpath " $flag"
10577a966c04fSmrg	  fi
105786e7d3316Smrg	elif test -n "$runpath_var"; then
105796e7d3316Smrg	  case "$perm_rpath " in
105806e7d3316Smrg	  *" $libdir "*) ;;
1058197cf2ee2Smrg	  *) func_append perm_rpath " $libdir" ;;
105826e7d3316Smrg	  esac
105836e7d3316Smrg	fi
105846e7d3316Smrg	case $host in
105856e7d3316Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586edce3322Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
105876e7d3316Smrg	  case :$dllsearchpath: in
105886e7d3316Smrg	  *":$libdir:"*) ;;
105896e7d3316Smrg	  ::) dllsearchpath=$libdir;;
1059097cf2ee2Smrg	  *) func_append dllsearchpath ":$libdir";;
105916e7d3316Smrg	  esac
105926e7d3316Smrg	  case :$dllsearchpath: in
105936e7d3316Smrg	  *":$testbindir:"*) ;;
105946e7d3316Smrg	  ::) dllsearchpath=$testbindir;;
1059597cf2ee2Smrg	  *) func_append dllsearchpath ":$testbindir";;
105966e7d3316Smrg	  esac
105976e7d3316Smrg	  ;;
105986e7d3316Smrg	esac
105996e7d3316Smrg      done
106006e7d3316Smrg      # Substitute the hardcoded libdirs into the rpath.
106016e7d3316Smrg      if test -n "$hardcode_libdir_separator" &&
106026e7d3316Smrg	 test -n "$hardcode_libdirs"; then
10603edce3322Smrg	libdir=$hardcode_libdirs
106046e7d3316Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106056e7d3316Smrg      fi
10606edce3322Smrg      compile_rpath=$rpath
10607a966c04fSmrg
106086e7d3316Smrg      rpath=
106096e7d3316Smrg      hardcode_libdirs=
106106e7d3316Smrg      for libdir in $finalize_rpath; do
106116e7d3316Smrg	if test -n "$hardcode_libdir_flag_spec"; then
106126e7d3316Smrg	  if test -n "$hardcode_libdir_separator"; then
106136e7d3316Smrg	    if test -z "$hardcode_libdirs"; then
10614edce3322Smrg	      hardcode_libdirs=$libdir
106156e7d3316Smrg	    else
106166e7d3316Smrg	      # Just accumulate the unique libdirs.
106176e7d3316Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
106186e7d3316Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
106196e7d3316Smrg		;;
106206e7d3316Smrg	      *)
1062197cf2ee2Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
106226e7d3316Smrg		;;
106236e7d3316Smrg	      esac
106246e7d3316Smrg	    fi
10625a966c04fSmrg	  else
106266e7d3316Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1062797cf2ee2Smrg	    func_append rpath " $flag"
10628a966c04fSmrg	  fi
106296e7d3316Smrg	elif test -n "$runpath_var"; then
106306e7d3316Smrg	  case "$finalize_perm_rpath " in
106316e7d3316Smrg	  *" $libdir "*) ;;
1063297cf2ee2Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
106336e7d3316Smrg	  esac
10634a966c04fSmrg	fi
106356e7d3316Smrg      done
106366e7d3316Smrg      # Substitute the hardcoded libdirs into the rpath.
106376e7d3316Smrg      if test -n "$hardcode_libdir_separator" &&
106386e7d3316Smrg	 test -n "$hardcode_libdirs"; then
10639edce3322Smrg	libdir=$hardcode_libdirs
106406e7d3316Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106416e7d3316Smrg      fi
10642edce3322Smrg      finalize_rpath=$rpath
10643a966c04fSmrg
10644edce3322Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
106456e7d3316Smrg	# Transform all the library objects into standard objects.
106466e7d3316Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106476e7d3316Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106486e7d3316Smrg      fi
10649a966c04fSmrg
10650edce3322Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651a966c04fSmrg
106526e7d3316Smrg      # template prelinking step
106536e7d3316Smrg      if test -n "$prelink_cmds"; then
106546e7d3316Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
106556e7d3316Smrg      fi
10656a966c04fSmrg
10657edce3322Smrg      wrappers_required=:
106586e7d3316Smrg      case $host in
106596e7d3316Smrg      *cegcc* | *mingw32ce*)
106606e7d3316Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661edce3322Smrg        wrappers_required=false
106626e7d3316Smrg        ;;
106636e7d3316Smrg      *cygwin* | *mingw* )
10664edce3322Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
106656e7d3316Smrg        ;;
106666e7d3316Smrg      *)
10667edce3322Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668edce3322Smrg          wrappers_required=false
106696e7d3316Smrg        fi
106706e7d3316Smrg        ;;
106716e7d3316Smrg      esac
10672edce3322Smrg      $wrappers_required || {
106736e7d3316Smrg	# Replace the output file specification.
106746e7d3316Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675edce3322Smrg	link_command=$compile_command$compile_rpath
10676a966c04fSmrg
106776e7d3316Smrg	# We have no uninstalled library dependencies, so finalize right now.
106786e7d3316Smrg	exit_status=0
106796e7d3316Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680a966c04fSmrg
1068197cf2ee2Smrg	if test -n "$postlink_cmds"; then
1068297cf2ee2Smrg	  func_to_tool_file "$output"
1068397cf2ee2Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1068497cf2ee2Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1068597cf2ee2Smrg	fi
1068697cf2ee2Smrg
106876e7d3316Smrg	# Delete the generated files.
10688edce3322Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689edce3322Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690a966c04fSmrg	fi
10691a966c04fSmrg
106926e7d3316Smrg	exit $exit_status
10693edce3322Smrg      }
10694a966c04fSmrg
106956e7d3316Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
106966e7d3316Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
106976e7d3316Smrg      fi
106986e7d3316Smrg      if test -n "$finalize_shlibpath"; then
106996e7d3316Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
107006e7d3316Smrg      fi
10701a966c04fSmrg
107026e7d3316Smrg      compile_var=
107036e7d3316Smrg      finalize_var=
107046e7d3316Smrg      if test -n "$runpath_var"; then
107056e7d3316Smrg	if test -n "$perm_rpath"; then
107066e7d3316Smrg	  # We should set the runpath_var.
107076e7d3316Smrg	  rpath=
107086e7d3316Smrg	  for dir in $perm_rpath; do
1070997cf2ee2Smrg	    func_append rpath "$dir:"
107106e7d3316Smrg	  done
107116e7d3316Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712a966c04fSmrg	fi
107136e7d3316Smrg	if test -n "$finalize_perm_rpath"; then
107146e7d3316Smrg	  # We should set the runpath_var.
107156e7d3316Smrg	  rpath=
107166e7d3316Smrg	  for dir in $finalize_perm_rpath; do
1071797cf2ee2Smrg	    func_append rpath "$dir:"
107186e7d3316Smrg	  done
107196e7d3316Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720a966c04fSmrg	fi
107216e7d3316Smrg      fi
10722a966c04fSmrg
10723edce3322Smrg      if test yes = "$no_install"; then
107246e7d3316Smrg	# We don't need to create a wrapper script.
10725edce3322Smrg	link_command=$compile_var$compile_command$compile_rpath
107266e7d3316Smrg	# Replace the output file specification.
107276e7d3316Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
107286e7d3316Smrg	# Delete the old output file.
107296e7d3316Smrg	$opt_dry_run || $RM $output
107306e7d3316Smrg	# Link the executable and exit
107316e7d3316Smrg	func_show_eval "$link_command" 'exit $?'
1073297cf2ee2Smrg
1073397cf2ee2Smrg	if test -n "$postlink_cmds"; then
1073497cf2ee2Smrg	  func_to_tool_file "$output"
1073597cf2ee2Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1073697cf2ee2Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1073797cf2ee2Smrg	fi
1073897cf2ee2Smrg
10739a966c04fSmrg	exit $EXIT_SUCCESS
107406e7d3316Smrg      fi
10741a966c04fSmrg
10742edce3322Smrg      case $hardcode_action,$fast_install in
10743edce3322Smrg        relink,*)
10744edce3322Smrg	  # Fast installation is not supported
10745edce3322Smrg	  link_command=$compile_var$compile_command$compile_rpath
10746edce3322Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107476e7d3316Smrg
10748edce3322Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10749edce3322Smrg	  func_warning "'$output' will be relinked during installation"
10750edce3322Smrg	  ;;
10751edce3322Smrg        *,yes)
10752edce3322Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753edce3322Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754edce3322Smrg          ;;
10755edce3322Smrg	*,no)
10756edce3322Smrg	  link_command=$compile_var$compile_command$compile_rpath
10757edce3322Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758edce3322Smrg          ;;
10759edce3322Smrg	*,needless)
10760edce3322Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761edce3322Smrg	  relink_command=
10762edce3322Smrg          ;;
10763edce3322Smrg      esac
10764a966c04fSmrg
107656e7d3316Smrg      # Replace the output file specification.
107666e7d3316Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767a966c04fSmrg
107686e7d3316Smrg      # Delete the old output files.
107696e7d3316Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770a966c04fSmrg
107716e7d3316Smrg      func_show_eval "$link_command" 'exit $?'
10772a966c04fSmrg
1077397cf2ee2Smrg      if test -n "$postlink_cmds"; then
1077497cf2ee2Smrg	func_to_tool_file "$output_objdir/$outputname"
1077597cf2ee2Smrg	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'`
1077697cf2ee2Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
1077797cf2ee2Smrg      fi
1077897cf2ee2Smrg
107796e7d3316Smrg      # Now create the wrapper script.
107806e7d3316Smrg      func_verbose "creating $output"
10781a966c04fSmrg
107826e7d3316Smrg      # Quote the relink command for shipping.
107836e7d3316Smrg      if test -n "$relink_command"; then
107846e7d3316Smrg	# Preserve any variables that may affect compiler behavior
107856e7d3316Smrg	for var in $variables_saved_for_relink; do
107866e7d3316Smrg	  if eval test -z \"\${$var+set}\"; then
107876e7d3316Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
107886e7d3316Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
107896e7d3316Smrg	    relink_command="$var=; export $var; $relink_command"
10790a966c04fSmrg	  else
1079174835918Smrg	    func_quote_arg pretty "$var_value"
1079274835918Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793a966c04fSmrg	  fi
107946e7d3316Smrg	done
1079574835918Smrg	func_quote eval cd "`pwd`"
1079674835918Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
1079774835918Smrg	relink_command=$func_quote_arg_unquoted_result
107986e7d3316Smrg      fi
10799a966c04fSmrg
108006e7d3316Smrg      # Only actually do things if not in dry run mode.
108016e7d3316Smrg      $opt_dry_run || {
108026e7d3316Smrg	# win32 will think the script is a binary if it has
108036e7d3316Smrg	# a .exe suffix, so we strip it off here.
108046e7d3316Smrg	case $output in
108056e7d3316Smrg	  *.exe) func_stripname '' '.exe' "$output"
108066e7d3316Smrg	         output=$func_stripname_result ;;
108076e7d3316Smrg	esac
108086e7d3316Smrg	# test for cygwin because mv fails w/o .exe extensions
108096e7d3316Smrg	case $host in
108106e7d3316Smrg	  *cygwin*)
108116e7d3316Smrg	    exeext=.exe
108126e7d3316Smrg	    func_stripname '' '.exe' "$outputname"
108136e7d3316Smrg	    outputname=$func_stripname_result ;;
108146e7d3316Smrg	  *) exeext= ;;
10815a966c04fSmrg	esac
108166e7d3316Smrg	case $host in
108176e7d3316Smrg	  *cygwin* | *mingw* )
108186e7d3316Smrg	    func_dirname_and_basename "$output" "" "."
108196e7d3316Smrg	    output_name=$func_basename_result
108206e7d3316Smrg	    output_path=$func_dirname_result
10821edce3322Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822edce3322Smrg	    cwrapper=$output_path/$output_name.exe
108236e7d3316Smrg	    $RM $cwrappersource $cwrapper
108246e7d3316Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
108256e7d3316Smrg
108266e7d3316Smrg	    func_emit_cwrapperexe_src > $cwrappersource
108276e7d3316Smrg
108286e7d3316Smrg	    # The wrapper executable is built using the $host compiler,
108296e7d3316Smrg	    # because it contains $host paths and files. If cross-
108306e7d3316Smrg	    # compiling, it, like the target executable, must be
108316e7d3316Smrg	    # executed on the $host or under an emulation environment.
108326e7d3316Smrg	    $opt_dry_run || {
108336e7d3316Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
108346e7d3316Smrg	      $STRIP $cwrapper
108356e7d3316Smrg	    }
10836a966c04fSmrg
108376e7d3316Smrg	    # Now, create the wrapper script for func_source use:
108386e7d3316Smrg	    func_ltwrapper_scriptname $cwrapper
108396e7d3316Smrg	    $RM $func_ltwrapper_scriptname_result
108406e7d3316Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
108416e7d3316Smrg	    $opt_dry_run || {
108426e7d3316Smrg	      # note: this script will not be executed, so do not chmod.
10843edce3322Smrg	      if test "x$build" = "x$host"; then
108446e7d3316Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
108456e7d3316Smrg	      else
108466e7d3316Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
108476e7d3316Smrg	      fi
108486e7d3316Smrg	    }
108496e7d3316Smrg	  ;;
108506e7d3316Smrg	  * )
108516e7d3316Smrg	    $RM $output
108526e7d3316Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853a966c04fSmrg
108546e7d3316Smrg	    func_emit_wrapper no > $output
108556e7d3316Smrg	    chmod +x $output
108566e7d3316Smrg	  ;;
108576e7d3316Smrg	esac
108586e7d3316Smrg      }
108596e7d3316Smrg      exit $EXIT_SUCCESS
108606e7d3316Smrg      ;;
108616e7d3316Smrg    esac
10862a966c04fSmrg
108636e7d3316Smrg    # See if we need to build an old-fashioned archive.
108646e7d3316Smrg    for oldlib in $oldlibs; do
10865a966c04fSmrg
10866edce3322Smrg      case $build_libtool_libs in
10867edce3322Smrg        convenience)
10868edce3322Smrg	  oldobjs="$libobjs_save $symfileobj"
10869edce3322Smrg	  addlibs=$convenience
108706e7d3316Smrg	  build_libtool_libs=no
10871edce3322Smrg	  ;;
10872edce3322Smrg	module)
10873edce3322Smrg	  oldobjs=$libobjs_save
10874edce3322Smrg	  addlibs=$old_convenience
10875edce3322Smrg	  build_libtool_libs=no
10876edce3322Smrg          ;;
10877edce3322Smrg	*)
108786e7d3316Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10879edce3322Smrg	  $preload && test -f "$symfileobj" \
10880edce3322Smrg	    && func_append oldobjs " $symfileobj"
10881edce3322Smrg	  addlibs=$old_convenience
10882edce3322Smrg	  ;;
10883edce3322Smrg      esac
10884a966c04fSmrg
108856e7d3316Smrg      if test -n "$addlibs"; then
10886edce3322Smrg	gentop=$output_objdir/${outputname}x
1088797cf2ee2Smrg	func_append generated " $gentop"
10888a966c04fSmrg
108896e7d3316Smrg	func_extract_archives $gentop $addlibs
1089097cf2ee2Smrg	func_append oldobjs " $func_extract_archives_result"
108916e7d3316Smrg      fi
10892a966c04fSmrg
108936e7d3316Smrg      # Do each command in the archive commands.
10894edce3322Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
108956e7d3316Smrg	cmds=$old_archive_from_new_cmds
108966e7d3316Smrg      else
10897a966c04fSmrg
108986e7d3316Smrg	# Add any objects from preloaded convenience libraries
108996e7d3316Smrg	if test -n "$dlprefiles"; then
10900edce3322Smrg	  gentop=$output_objdir/${outputname}x
1090197cf2ee2Smrg	  func_append generated " $gentop"
10902a966c04fSmrg
109036e7d3316Smrg	  func_extract_archives $gentop $dlprefiles
1090497cf2ee2Smrg	  func_append oldobjs " $func_extract_archives_result"
109056e7d3316Smrg	fi
10906a966c04fSmrg
109076e7d3316Smrg	# POSIX demands no paths to be encoded in archives.  We have
109086e7d3316Smrg	# to avoid creating archives with duplicate basenames if we
109096e7d3316Smrg	# might have to extract them afterwards, e.g., when creating a
109106e7d3316Smrg	# static archive out of a convenience library, or when linking
109116e7d3316Smrg	# the entirety of a libtool archive into another (currently
109126e7d3316Smrg	# not supported by libtool).
109136e7d3316Smrg	if (for obj in $oldobjs
109146e7d3316Smrg	    do
109156e7d3316Smrg	      func_basename "$obj"
109166e7d3316Smrg	      $ECHO "$func_basename_result"
109176e7d3316Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
109186e7d3316Smrg	  :
109196e7d3316Smrg	else
109206e7d3316Smrg	  echo "copying selected object files to avoid basename conflicts..."
10921edce3322Smrg	  gentop=$output_objdir/${outputname}x
1092297cf2ee2Smrg	  func_append generated " $gentop"
109236e7d3316Smrg	  func_mkdir_p "$gentop"
109246e7d3316Smrg	  save_oldobjs=$oldobjs
109256e7d3316Smrg	  oldobjs=
109266e7d3316Smrg	  counter=1
109276e7d3316Smrg	  for obj in $save_oldobjs
109286e7d3316Smrg	  do
109296e7d3316Smrg	    func_basename "$obj"
10930edce3322Smrg	    objbase=$func_basename_result
109316e7d3316Smrg	    case " $oldobjs " in
109326e7d3316Smrg	    " ") oldobjs=$obj ;;
109336e7d3316Smrg	    *[\ /]"$objbase "*)
109346e7d3316Smrg	      while :; do
109356e7d3316Smrg		# Make sure we don't pick an alternate name that also
109366e7d3316Smrg		# overlaps.
109376e7d3316Smrg		newobj=lt$counter-$objbase
109386e7d3316Smrg		func_arith $counter + 1
109396e7d3316Smrg		counter=$func_arith_result
109406e7d3316Smrg		case " $oldobjs " in
109416e7d3316Smrg		*[\ /]"$newobj "*) ;;
109426e7d3316Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
109436e7d3316Smrg		esac
109446e7d3316Smrg	      done
109456e7d3316Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
1094697cf2ee2Smrg	      func_append oldobjs " $gentop/$newobj"
109476e7d3316Smrg	      ;;
1094897cf2ee2Smrg	    *) func_append oldobjs " $obj" ;;
109496e7d3316Smrg	    esac
10950a966c04fSmrg	  done
10951a966c04fSmrg	fi
10952ac92798bSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953ac92798bSmrg	tool_oldlib=$func_to_tool_file_result
109546e7d3316Smrg	eval cmds=\"$old_archive_cmds\"
10955a966c04fSmrg
109566e7d3316Smrg	func_len " $cmds"
109576e7d3316Smrg	len=$func_len_result
109586e7d3316Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
109596e7d3316Smrg	  cmds=$old_archive_cmds
1096097cf2ee2Smrg	elif test -n "$archiver_list_spec"; then
1096197cf2ee2Smrg	  func_verbose "using command file archive linking..."
1096297cf2ee2Smrg	  for obj in $oldobjs
1096397cf2ee2Smrg	  do
1096497cf2ee2Smrg	    func_to_tool_file "$obj"
1096597cf2ee2Smrg	    $ECHO "$func_to_tool_file_result"
1096697cf2ee2Smrg	  done > $output_objdir/$libname.libcmd
1096797cf2ee2Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
1096897cf2ee2Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
1096997cf2ee2Smrg	  cmds=$old_archive_cmds
109706e7d3316Smrg	else
109716e7d3316Smrg	  # the command line is too long to link in one step, link in parts
109726e7d3316Smrg	  func_verbose "using piecewise archive linking..."
109736e7d3316Smrg	  save_RANLIB=$RANLIB
109746e7d3316Smrg	  RANLIB=:
109756e7d3316Smrg	  objlist=
109766e7d3316Smrg	  concat_cmds=
109776e7d3316Smrg	  save_oldobjs=$oldobjs
109786e7d3316Smrg	  oldobjs=
109796e7d3316Smrg	  # Is there a better way of finding the last object in the list?
109806e7d3316Smrg	  for obj in $save_oldobjs
109816e7d3316Smrg	  do
109826e7d3316Smrg	    last_oldobj=$obj
109836e7d3316Smrg	  done
109846e7d3316Smrg	  eval test_cmds=\"$old_archive_cmds\"
109856e7d3316Smrg	  func_len " $test_cmds"
109866e7d3316Smrg	  len0=$func_len_result
109876e7d3316Smrg	  len=$len0
109886e7d3316Smrg	  for obj in $save_oldobjs
109896e7d3316Smrg	  do
109906e7d3316Smrg	    func_len " $obj"
109916e7d3316Smrg	    func_arith $len + $func_len_result
109926e7d3316Smrg	    len=$func_arith_result
109936e7d3316Smrg	    func_append objlist " $obj"
109946e7d3316Smrg	    if test "$len" -lt "$max_cmd_len"; then
109956e7d3316Smrg	      :
109966e7d3316Smrg	    else
109976e7d3316Smrg	      # the above command should be used before it gets too long
109986e7d3316Smrg	      oldobjs=$objlist
10999edce3322Smrg	      if test "$obj" = "$last_oldobj"; then
110006e7d3316Smrg		RANLIB=$save_RANLIB
110016e7d3316Smrg	      fi
110026e7d3316Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003edce3322Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
110046e7d3316Smrg	      objlist=
110056e7d3316Smrg	      len=$len0
110066e7d3316Smrg	    fi
110076e7d3316Smrg	  done
110086e7d3316Smrg	  RANLIB=$save_RANLIB
110096e7d3316Smrg	  oldobjs=$objlist
11010edce3322Smrg	  if test -z "$oldobjs"; then
110116e7d3316Smrg	    eval cmds=\"\$concat_cmds\"
110126e7d3316Smrg	  else
110136e7d3316Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
110146e7d3316Smrg	  fi
110156e7d3316Smrg	fi
110166e7d3316Smrg      fi
110176e7d3316Smrg      func_execute_cmds "$cmds" 'exit $?'
11018a966c04fSmrg    done
11019a966c04fSmrg
110206e7d3316Smrg    test -n "$generated" && \
110216e7d3316Smrg      func_show_eval "${RM}r$generated"
11022a966c04fSmrg
110236e7d3316Smrg    # Now create the libtool archive.
110246e7d3316Smrg    case $output in
110256e7d3316Smrg    *.la)
110266e7d3316Smrg      old_library=
11027edce3322Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
110286e7d3316Smrg      func_verbose "creating $output"
11029a966c04fSmrg
110306e7d3316Smrg      # Preserve any variables that may affect compiler behavior
110316e7d3316Smrg      for var in $variables_saved_for_relink; do
110326e7d3316Smrg	if eval test -z \"\${$var+set}\"; then
110336e7d3316Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
110346e7d3316Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
110356e7d3316Smrg	  relink_command="$var=; export $var; $relink_command"
11036a966c04fSmrg	else
1103774835918Smrg	  func_quote_arg pretty,unquoted "$var_value"
1103874835918Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039a966c04fSmrg	fi
110406e7d3316Smrg      done
110416e7d3316Smrg      # Quote the link command for shipping.
1104274835918Smrg      func_quote eval cd "`pwd`"
1104374835918Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
1104474835918Smrg      func_quote_arg pretty,unquoted "$relink_command"
1104574835918Smrg      relink_command=$func_quote_arg_unquoted_result
11046edce3322Smrg      if test yes = "$hardcode_automatic"; then
110476e7d3316Smrg	relink_command=
110486e7d3316Smrg      fi
11049a966c04fSmrg
110506e7d3316Smrg      # Only create the output if not a dry run.
110516e7d3316Smrg      $opt_dry_run || {
110526e7d3316Smrg	for installed in no yes; do
11053edce3322Smrg	  if test yes = "$installed"; then
110546e7d3316Smrg	    if test -z "$install_libdir"; then
110556e7d3316Smrg	      break
110566e7d3316Smrg	    fi
11057edce3322Smrg	    output=$output_objdir/${outputname}i
110586e7d3316Smrg	    # Replace all uninstalled libtool libraries with the installed ones
110596e7d3316Smrg	    newdependency_libs=
110606e7d3316Smrg	    for deplib in $dependency_libs; do
110616e7d3316Smrg	      case $deplib in
110626e7d3316Smrg	      *.la)
110636e7d3316Smrg		func_basename "$deplib"
11064edce3322Smrg		name=$func_basename_result
11065ac92798bSmrg		func_resolve_sysroot "$deplib"
11066edce3322Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
110676e7d3316Smrg		test -z "$libdir" && \
11068edce3322Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
1106997cf2ee2Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
1107097cf2ee2Smrg		;;
1107197cf2ee2Smrg	      -L*)
1107297cf2ee2Smrg		func_stripname -L '' "$deplib"
1107397cf2ee2Smrg		func_replace_sysroot "$func_stripname_result"
1107497cf2ee2Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
1107597cf2ee2Smrg		;;
1107697cf2ee2Smrg	      -R*)
1107797cf2ee2Smrg		func_stripname -R '' "$deplib"
1107897cf2ee2Smrg		func_replace_sysroot "$func_stripname_result"
1107997cf2ee2Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
110806e7d3316Smrg		;;
1108197cf2ee2Smrg	      *) func_append newdependency_libs " $deplib" ;;
110826e7d3316Smrg	      esac
110836e7d3316Smrg	    done
11084edce3322Smrg	    dependency_libs=$newdependency_libs
110856e7d3316Smrg	    newdlfiles=
110866e7d3316Smrg
110876e7d3316Smrg	    for lib in $dlfiles; do
110886e7d3316Smrg	      case $lib in
110896e7d3316Smrg	      *.la)
110906e7d3316Smrg	        func_basename "$lib"
11091edce3322Smrg		name=$func_basename_result
11092edce3322Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
110936e7d3316Smrg		test -z "$libdir" && \
11094edce3322Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1109597cf2ee2Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
110966e7d3316Smrg		;;
1109797cf2ee2Smrg	      *) func_append newdlfiles " $lib" ;;
110986e7d3316Smrg	      esac
110996e7d3316Smrg	    done
11100edce3322Smrg	    dlfiles=$newdlfiles
111016e7d3316Smrg	    newdlprefiles=
111026e7d3316Smrg	    for lib in $dlprefiles; do
111036e7d3316Smrg	      case $lib in
111046e7d3316Smrg	      *.la)
111056e7d3316Smrg		# Only pass preopened files to the pseudo-archive (for
111066e7d3316Smrg		# eventual linking with the app. that links it) if we
111076e7d3316Smrg		# didn't already link the preopened objects directly into
111086e7d3316Smrg		# the library:
111096e7d3316Smrg		func_basename "$lib"
11110edce3322Smrg		name=$func_basename_result
11111edce3322Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
111126e7d3316Smrg		test -z "$libdir" && \
11113edce3322Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1111497cf2ee2Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
111156e7d3316Smrg		;;
111166e7d3316Smrg	      esac
111176e7d3316Smrg	    done
11118edce3322Smrg	    dlprefiles=$newdlprefiles
111196e7d3316Smrg	  else
111206e7d3316Smrg	    newdlfiles=
111216e7d3316Smrg	    for lib in $dlfiles; do
111226e7d3316Smrg	      case $lib in
11123edce3322Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111246e7d3316Smrg		*) abs=`pwd`"/$lib" ;;
111256e7d3316Smrg	      esac
1112697cf2ee2Smrg	      func_append newdlfiles " $abs"
111276e7d3316Smrg	    done
11128edce3322Smrg	    dlfiles=$newdlfiles
111296e7d3316Smrg	    newdlprefiles=
111306e7d3316Smrg	    for lib in $dlprefiles; do
111316e7d3316Smrg	      case $lib in
11132edce3322Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111336e7d3316Smrg		*) abs=`pwd`"/$lib" ;;
111346e7d3316Smrg	      esac
1113597cf2ee2Smrg	      func_append newdlprefiles " $abs"
111366e7d3316Smrg	    done
11137edce3322Smrg	    dlprefiles=$newdlprefiles
111386e7d3316Smrg	  fi
111396e7d3316Smrg	  $RM $output
111406e7d3316Smrg	  # place dlname in correct position for cygwin
111416e7d3316Smrg	  # In fact, it would be nice if we could use this code for all target
111426e7d3316Smrg	  # systems that can't hard-code library paths into their executables
111436e7d3316Smrg	  # and that have no shared library path variable independent of PATH,
111446e7d3316Smrg	  # but it turns out we can't easily determine that from inspecting
111456e7d3316Smrg	  # libtool variables, so we have to hard-code the OSs to which it
111466e7d3316Smrg	  # applies here; at the moment, that means platforms that use the PE
111476e7d3316Smrg	  # object format with DLL files.  See the long comment at the top of
111486e7d3316Smrg	  # tests/bindir.at for full details.
111496e7d3316Smrg	  tdlname=$dlname
111506e7d3316Smrg	  case $host,$output,$installed,$module,$dlname in
111516e7d3316Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
111526e7d3316Smrg	      # If a -bindir argument was supplied, place the dll there.
11153edce3322Smrg	      if test -n "$bindir"; then
111546e7d3316Smrg		func_relative_path "$install_libdir" "$bindir"
11155edce3322Smrg		tdlname=$func_relative_path_result/$dlname
111566e7d3316Smrg	      else
111576e7d3316Smrg		# Otherwise fall back on heuristic.
111586e7d3316Smrg		tdlname=../bin/$dlname
111596e7d3316Smrg	      fi
111606e7d3316Smrg	      ;;
111616e7d3316Smrg	  esac
111626e7d3316Smrg	  $ECHO > $output "\
111636e7d3316Smrg# $outputname - a libtool library file
11164edce3322Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
111656e7d3316Smrg#
111666e7d3316Smrg# Please DO NOT delete this file!
111676e7d3316Smrg# It is necessary for linking the library.
11168a966c04fSmrg
111696e7d3316Smrg# The name that we can dlopen(3).
111706e7d3316Smrgdlname='$tdlname'
11171a966c04fSmrg
111726e7d3316Smrg# Names of this library.
111736e7d3316Smrglibrary_names='$library_names'
11174a966c04fSmrg
111756e7d3316Smrg# The name of the static archive.
111766e7d3316Smrgold_library='$old_library'
11177a966c04fSmrg
11178edce3322Smrg# Linker flags that cannot go in dependency_libs.
111796e7d3316Smrginherited_linker_flags='$new_inherited_linker_flags'
11180a966c04fSmrg
111816e7d3316Smrg# Libraries that this one depends upon.
111826e7d3316Smrgdependency_libs='$dependency_libs'
11183a966c04fSmrg
111846e7d3316Smrg# Names of additional weak libraries provided by this library
111856e7d3316Smrgweak_library_names='$weak_libs'
11186a966c04fSmrg
111876e7d3316Smrg# Version information for $libname.
111886e7d3316Smrgcurrent=$current
111896e7d3316Smrgage=$age
111906e7d3316Smrgrevision=$revision
11191a966c04fSmrg
111926e7d3316Smrg# Is this an already installed library?
111936e7d3316Smrginstalled=$installed
11194a966c04fSmrg
111956e7d3316Smrg# Should we warn about portability when linking against -modules?
111966e7d3316Smrgshouldnotlink=$module
11197a966c04fSmrg
111986e7d3316Smrg# Files to dlopen/dlpreopen
111996e7d3316Smrgdlopen='$dlfiles'
112006e7d3316Smrgdlpreopen='$dlprefiles'
11201a966c04fSmrg
112026e7d3316Smrg# Directory that this library needs to be installed in:
112036e7d3316Smrglibdir='$install_libdir'"
11204edce3322Smrg	  if test no,yes = "$installed,$need_relink"; then
112056e7d3316Smrg	    $ECHO >> $output "\
112066e7d3316Smrgrelink_command=\"$relink_command\""
112076e7d3316Smrg	  fi
112086e7d3316Smrg	done
112096e7d3316Smrg      }
11210a966c04fSmrg
112116e7d3316Smrg      # Do a symbolic link so that the libtool archive can be found in
112126e7d3316Smrg      # LD_LIBRARY_PATH before the program is installed.
112136e7d3316Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
112146e7d3316Smrg      ;;
112156e7d3316Smrg    esac
112166e7d3316Smrg    exit $EXIT_SUCCESS
112176e7d3316Smrg}
11218a966c04fSmrg
11219edce3322Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220edce3322Smrg  func_mode_link ${1+"$@"}
11221edce3322Smrgfi
11222a966c04fSmrg
11223a966c04fSmrg
112246e7d3316Smrg# func_mode_uninstall arg...
112256e7d3316Smrgfunc_mode_uninstall ()
112266e7d3316Smrg{
11227edce3322Smrg    $debug_cmd
11228edce3322Smrg
11229edce3322Smrg    RM=$nonopt
11230a966c04fSmrg    files=
11231edce3322Smrg    rmforce=false
11232a966c04fSmrg    exit_status=0
11233a966c04fSmrg
11234a966c04fSmrg    # This variable tells wrapper scripts just to set variables rather
11235a966c04fSmrg    # than running their programs.
11236edce3322Smrg    libtool_install_magic=$magic
11237a966c04fSmrg
11238a966c04fSmrg    for arg
11239a966c04fSmrg    do
11240a966c04fSmrg      case $arg in
11241edce3322Smrg      -f) func_append RM " $arg"; rmforce=: ;;
1124297cf2ee2Smrg      -*) func_append RM " $arg" ;;
1124397cf2ee2Smrg      *) func_append files " $arg" ;;
11244a966c04fSmrg      esac
11245a966c04fSmrg    done
11246a966c04fSmrg
112476e7d3316Smrg    test -z "$RM" && \
112486e7d3316Smrg      func_fatal_help "you must specify an RM program"
11249a966c04fSmrg
11250a966c04fSmrg    rmdirs=
11251a966c04fSmrg
11252a966c04fSmrg    for file in $files; do
112536e7d3316Smrg      func_dirname "$file" "" "."
11254edce3322Smrg      dir=$func_dirname_result
11255edce3322Smrg      if test . = "$dir"; then
11256edce3322Smrg	odir=$objdir
11257a966c04fSmrg      else
11258edce3322Smrg	odir=$dir/$objdir
11259a966c04fSmrg      fi
112606e7d3316Smrg      func_basename "$file"
11261edce3322Smrg      name=$func_basename_result
11262edce3322Smrg      test uninstall = "$opt_mode" && odir=$dir
11263a966c04fSmrg
1126497cf2ee2Smrg      # Remember odir for removal later, being careful to avoid duplicates
11265edce3322Smrg      if test clean = "$opt_mode"; then
11266a966c04fSmrg	case " $rmdirs " in
1126797cf2ee2Smrg	  *" $odir "*) ;;
1126897cf2ee2Smrg	  *) func_append rmdirs " $odir" ;;
11269a966c04fSmrg	esac
11270a966c04fSmrg      fi
11271a966c04fSmrg
11272a966c04fSmrg      # Don't error if the file doesn't exist and rm -f was used.
112736e7d3316Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
112746e7d3316Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
112756e7d3316Smrg	 test -f "$file"; then
11276a966c04fSmrg	:
11277a966c04fSmrg      elif test -d "$file"; then
11278a966c04fSmrg	exit_status=1
11279a966c04fSmrg	continue
11280edce3322Smrg      elif $rmforce; then
11281a966c04fSmrg	continue
11282a966c04fSmrg      fi
11283a966c04fSmrg
11284edce3322Smrg      rmfiles=$file
11285a966c04fSmrg
11286a966c04fSmrg      case $name in
11287a966c04fSmrg      *.la)
11288a966c04fSmrg	# Possibly a libtool archive, so verify it.
112896e7d3316Smrg	if func_lalib_p "$file"; then
112906e7d3316Smrg	  func_source $dir/$name
11291a966c04fSmrg
11292a966c04fSmrg	  # Delete the libtool libraries and symlinks.
11293a966c04fSmrg	  for n in $library_names; do
1129497cf2ee2Smrg	    func_append rmfiles " $odir/$n"
11295a966c04fSmrg	  done
1129697cf2ee2Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297a966c04fSmrg
11298edce3322Smrg	  case $opt_mode in
11299a966c04fSmrg	  clean)
1130097cf2ee2Smrg	    case " $library_names " in
11301a966c04fSmrg	    *" $dlname "*) ;;
1130297cf2ee2Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303a966c04fSmrg	    esac
1130497cf2ee2Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305a966c04fSmrg	    ;;
11306a966c04fSmrg	  uninstall)
11307a966c04fSmrg	    if test -n "$library_names"; then
11308a966c04fSmrg	      # Do each command in the postuninstall commands.
11309edce3322Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310a966c04fSmrg	    fi
11311a966c04fSmrg
11312a966c04fSmrg	    if test -n "$old_library"; then
11313a966c04fSmrg	      # Do each command in the old_postuninstall commands.
11314edce3322Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315a966c04fSmrg	    fi
11316a966c04fSmrg	    # FIXME: should reinstall the best remaining shared library.
11317a966c04fSmrg	    ;;
11318a966c04fSmrg	  esac
11319a966c04fSmrg	fi
11320a966c04fSmrg	;;
11321a966c04fSmrg
11322a966c04fSmrg      *.lo)
11323a966c04fSmrg	# Possibly a libtool object, so verify it.
113246e7d3316Smrg	if func_lalib_p "$file"; then
11325a966c04fSmrg
11326a966c04fSmrg	  # Read the .lo file
113276e7d3316Smrg	  func_source $dir/$name
11328a966c04fSmrg
11329a966c04fSmrg	  # Add PIC object to the list of files to remove.
11330edce3322Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
1133197cf2ee2Smrg	    func_append rmfiles " $dir/$pic_object"
11332a966c04fSmrg	  fi
11333a966c04fSmrg
11334a966c04fSmrg	  # Add non-PIC object to the list of files to remove.
11335edce3322Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
1133697cf2ee2Smrg	    func_append rmfiles " $dir/$non_pic_object"
11337a966c04fSmrg	  fi
11338a966c04fSmrg	fi
11339a966c04fSmrg	;;
11340a966c04fSmrg
11341a966c04fSmrg      *)
11342edce3322Smrg	if test clean = "$opt_mode"; then
11343a966c04fSmrg	  noexename=$name
11344a966c04fSmrg	  case $file in
11345a966c04fSmrg	  *.exe)
113466e7d3316Smrg	    func_stripname '' '.exe' "$file"
113476e7d3316Smrg	    file=$func_stripname_result
113486e7d3316Smrg	    func_stripname '' '.exe' "$name"
113496e7d3316Smrg	    noexename=$func_stripname_result
11350a966c04fSmrg	    # $file with .exe has already been added to rmfiles,
11351a966c04fSmrg	    # add $file without .exe
1135297cf2ee2Smrg	    func_append rmfiles " $file"
11353a966c04fSmrg	    ;;
11354a966c04fSmrg	  esac
11355a966c04fSmrg	  # Do a test to see if this is a libtool program.
113566e7d3316Smrg	  if func_ltwrapper_p "$file"; then
113576e7d3316Smrg	    if func_ltwrapper_executable_p "$file"; then
113586e7d3316Smrg	      func_ltwrapper_scriptname "$file"
113596e7d3316Smrg	      relink_command=
113606e7d3316Smrg	      func_source $func_ltwrapper_scriptname_result
1136197cf2ee2Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
113626e7d3316Smrg	    else
113636e7d3316Smrg	      relink_command=
113646e7d3316Smrg	      func_source $dir/$noexename
113656e7d3316Smrg	    fi
11366a966c04fSmrg
11367a966c04fSmrg	    # note $name still contains .exe if it was in $file originally
11368a966c04fSmrg	    # as does the version of $file that was added into $rmfiles
11369edce3322Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370edce3322Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
1137197cf2ee2Smrg	      func_append rmfiles " $odir/lt-$name"
11372a966c04fSmrg	    fi
11373edce3322Smrg	    if test "X$noexename" != "X$name"; then
11374edce3322Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375a966c04fSmrg	    fi
11376a966c04fSmrg	  fi
11377a966c04fSmrg	fi
11378a966c04fSmrg	;;
11379a966c04fSmrg      esac
113806e7d3316Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381a966c04fSmrg    done
11382a966c04fSmrg
11383edce3322Smrg    # Try to remove the $objdir's in the directories where we deleted files
11384a966c04fSmrg    for dir in $rmdirs; do
11385a966c04fSmrg      if test -d "$dir"; then
113866e7d3316Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387a966c04fSmrg      fi
11388a966c04fSmrg    done
11389a966c04fSmrg
11390a966c04fSmrg    exit $exit_status
113916e7d3316Smrg}
11392a966c04fSmrg
11393edce3322Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394edce3322Smrg  func_mode_uninstall ${1+"$@"}
11395edce3322Smrgfi
11396a966c04fSmrg
1139797cf2ee2Smrgtest -z "$opt_mode" && {
11398edce3322Smrg  help=$generic_help
113996e7d3316Smrg  func_fatal_help "you must specify a MODE"
114006e7d3316Smrg}
114016e7d3316Smrg
114026e7d3316Smrgtest -z "$exec_cmd" && \
11403edce3322Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404a966c04fSmrg
11405a966c04fSmrgif test -n "$exec_cmd"; then
114066e7d3316Smrg  eval exec "$exec_cmd"
11407a966c04fSmrg  exit $EXIT_FAILURE
11408a966c04fSmrgfi
11409a966c04fSmrg
114106e7d3316Smrgexit $exit_status
11411a966c04fSmrg
11412a966c04fSmrg
11413a966c04fSmrg# The TAGs below are defined such that we never get into a situation
11414edce3322Smrg# where we disable both kinds of libraries.  Given conflicting
11415a966c04fSmrg# choices, we go for a static library, that is the most portable,
11416a966c04fSmrg# since we can't tell whether shared libraries were disabled because
11417a966c04fSmrg# the user asked for that or because the platform doesn't support
11418a966c04fSmrg# them.  This is particularly important on AIX, because we don't
11419a966c04fSmrg# support having both static and shared libraries enabled at the same
11420a966c04fSmrg# time on that platform, so we default to a shared-only configuration.
11421a966c04fSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11422a966c04fSmrg# configuration.  But we'll never go from static-only to shared-only.
11423a966c04fSmrg
11424a966c04fSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
114256e7d3316Smrgbuild_libtool_libs=no
114266e7d3316Smrgbuild_old_libs=yes
11427a966c04fSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11428a966c04fSmrg
11429a966c04fSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
114306e7d3316Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431a966c04fSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11432a966c04fSmrg
11433a966c04fSmrg# Local Variables:
11434a966c04fSmrg# mode:shell-script
11435a966c04fSmrg# sh-indentation:2
11436a966c04fSmrg# End:
11437