1b41a30aaSmrg#! /usr/bin/env sh
2b41a30aaSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3b41a30aaSmrg##               by inline-source v2019-02-19.15
4ea133fd7Smrg
5b41a30aaSmrg# libtool (GNU libtool) 2.4.7
6b41a30aaSmrg# Provide generalized library-building support services.
7ea133fd7Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8ea133fd7Smrg
9b41a30aaSmrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10ea133fd7Smrg# This is free software; see the source for copying conditions.  There is NO
11ea133fd7Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12ea133fd7Smrg
13ea133fd7Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14a253d6aeSmrg# it under the terms of the GNU General Public License as published by
15a253d6aeSmrg# the Free Software Foundation; either version 2 of the License, or
16a253d6aeSmrg# (at your option) any later version.
17a253d6aeSmrg#
18ea133fd7Smrg# As a special exception to the GNU General Public License,
19ea133fd7Smrg# if you distribute this file as part of a program or library that
20ea133fd7Smrg# is built using GNU Libtool, you may include this file under the
21ea133fd7Smrg# same distribution terms that you use for the rest of that program.
22ea133fd7Smrg#
23ea133fd7Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24a253d6aeSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25a253d6aeSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26a253d6aeSmrg# General Public License for more details.
27a253d6aeSmrg#
28a253d6aeSmrg# You should have received a copy of the GNU General Public License
29b41a30aaSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30ea133fd7Smrg
31b41a30aaSmrg
32b41a30aaSmrgPROGRAM=libtool
33b41a30aaSmrgPACKAGE=libtool
34b41a30aaSmrgVERSION=2.4.7
35b41a30aaSmrgpackage_revision=2.4.7
36b41a30aaSmrg
37b41a30aaSmrg
38b41a30aaSmrg## ------ ##
39b41a30aaSmrg## Usage. ##
40b41a30aaSmrg## ------ ##
41b41a30aaSmrg
42b41a30aaSmrg# Run './libtool --help' for help with using this script from the
43b41a30aaSmrg# command line.
44b41a30aaSmrg
45b41a30aaSmrg
46b41a30aaSmrg## ------------------------------- ##
47b41a30aaSmrg## User overridable command paths. ##
48b41a30aaSmrg## ------------------------------- ##
49b41a30aaSmrg
50b41a30aaSmrg# After configure completes, it has a better idea of some of the
51b41a30aaSmrg# shell tools we need than the defaults used by the functions shared
52b41a30aaSmrg# with bootstrap, so set those here where they can still be over-
53b41a30aaSmrg# ridden by the user, but otherwise take precedence.
54b41a30aaSmrg
55b41a30aaSmrg: ${AUTOCONF="autoconf"}
56b41a30aaSmrg: ${AUTOMAKE="automake"}
57b41a30aaSmrg
58b41a30aaSmrg
59b41a30aaSmrg## -------------------------- ##
60b41a30aaSmrg## Source external libraries. ##
61b41a30aaSmrg## -------------------------- ##
62b41a30aaSmrg
63b41a30aaSmrg# Much of our low-level functionality needs to be sourced from external
64b41a30aaSmrg# libraries, which are installed to $pkgauxdir.
65b41a30aaSmrg
66b41a30aaSmrg# Set a version string for this script.
67b41a30aaSmrgscriptversion=2019-02-19.15; # UTC
68b41a30aaSmrg
69b41a30aaSmrg# General shell script boiler plate, and helper functions.
70b41a30aaSmrg# Written by Gary V. Vaughan, 2004
71b41a30aaSmrg
72b41a30aaSmrg# This is free software.  There is NO warranty; not even for
73b41a30aaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74ea133fd7Smrg#
75b41a30aaSmrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76ea133fd7Smrg#
77b41a30aaSmrg# This file is dual licensed under the terms of the MIT license
78b41a30aaSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79b41a30aaSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80b41a30aaSmrg# these licenses when using or redistributing this software or any of
81b41a30aaSmrg# the files within it.  See the URLs above, or the file `LICENSE`
82b41a30aaSmrg# included in the Bootstrap distribution for the full license texts.
83b41a30aaSmrg
84b41a30aaSmrg# Please report bugs or propose patches to:
85b41a30aaSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
86b41a30aaSmrg
87b41a30aaSmrg
88b41a30aaSmrg## ------ ##
89b41a30aaSmrg## Usage. ##
90b41a30aaSmrg## ------ ##
91b41a30aaSmrg
92b41a30aaSmrg# Evaluate this file near the top of your script to gain access to
93b41a30aaSmrg# the functions and variables defined here:
94ea133fd7Smrg#
95b41a30aaSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96ea133fd7Smrg#
97b41a30aaSmrg# If you need to override any of the default environment variable
98b41a30aaSmrg# settings, do that before evaluating this file.
99ea133fd7Smrg
100ea133fd7Smrg
101b41a30aaSmrg## -------------------- ##
102b41a30aaSmrg## Shell normalisation. ##
103b41a30aaSmrg## -------------------- ##
104b41a30aaSmrg
105b41a30aaSmrg# Some shells need a little help to be as Bourne compatible as possible.
106b41a30aaSmrg# Before doing anything else, make sure all that help has been provided!
107b41a30aaSmrg
108b41a30aaSmrgDUALCASE=1; export DUALCASE # for MKS sh
109b41a30aaSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110ea133fd7Smrg  emulate sh
111ea133fd7Smrg  NULLCMD=:
112b41a30aaSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113ea133fd7Smrg  # is contrary to our usage.  Disable this feature.
114ea133fd7Smrg  alias -g '${1+"$@"}'='"$@"'
115ea133fd7Smrg  setopt NO_GLOB_SUBST
116ea133fd7Smrgelse
117b41a30aaSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118ea133fd7Smrgfi
11925b89263Smrg
120b41a30aaSmrg# NLS nuisances: We save the old values in case they are required later.
121b41a30aaSmrg_G_user_locale=
122b41a30aaSmrg_G_safe_locale=
123b41a30aaSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124ea133fd7Smrgdo
125b41a30aaSmrg  eval "if test set = \"\${$_G_var+set}\"; then
126b41a30aaSmrg          save_$_G_var=\$$_G_var
127b41a30aaSmrg          $_G_var=C
128b41a30aaSmrg	  export $_G_var
129b41a30aaSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130b41a30aaSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131ea133fd7Smrg	fi"
132ea133fd7Smrgdone
133b41a30aaSmrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134b41a30aaSmrg# in case the environment reset is needed later and the $save_* variant is not
135b41a30aaSmrg# defined (see the code above).
13625b89263SmrgLC_ALL=C
13725b89263SmrgLANGUAGE=C
13825b89263Smrgexport LANGUAGE LC_ALL
139ea133fd7Smrg
140b41a30aaSmrg# Make sure IFS has a sensible default
141b41a30aaSmrgsp=' '
142b41a30aaSmrgnl='
143b41a30aaSmrg'
144b41a30aaSmrgIFS="$sp	$nl"
145b41a30aaSmrg
146b41a30aaSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
147b41a30aaSmrgif test "${PATH_SEPARATOR+set}" != set; then
148b41a30aaSmrg  PATH_SEPARATOR=:
149b41a30aaSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150b41a30aaSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151b41a30aaSmrg      PATH_SEPARATOR=';'
152b41a30aaSmrg  }
153b41a30aaSmrgfi
154ea133fd7Smrg
155ea133fd7Smrg
156b41a30aaSmrg# func_unset VAR
157b41a30aaSmrg# --------------
158b41a30aaSmrg# Portably unset VAR.
159b41a30aaSmrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160b41a30aaSmrg# status if VAR is already unset, which might be problematic if the
161b41a30aaSmrg# statement is used at the end of a function (thus poisoning its return
162b41a30aaSmrg# value) or when 'set -e' is active (causing even a spurious abort of
163b41a30aaSmrg# the script in this case).
164b41a30aaSmrgfunc_unset ()
165b41a30aaSmrg{
166b41a30aaSmrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167b41a30aaSmrg}
168ea133fd7Smrg
169ea133fd7Smrg
170b41a30aaSmrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171b41a30aaSmrgfunc_unset CDPATH
172a253d6aeSmrg
173b41a30aaSmrg# Make sure ${,E,F}GREP behave sanely.
174b41a30aaSmrgfunc_unset GREP_OPTIONS
175ea133fd7Smrg
176ea133fd7Smrg
177b41a30aaSmrg## ------------------------- ##
178b41a30aaSmrg## Locate command utilities. ##
179b41a30aaSmrg## ------------------------- ##
180ea133fd7Smrg
181ea133fd7Smrg
182b41a30aaSmrg# func_executable_p FILE
183b41a30aaSmrg# ----------------------
184b41a30aaSmrg# Check that FILE is an executable regular file.
185b41a30aaSmrgfunc_executable_p ()
18606f32fbeSmrg{
187b41a30aaSmrg    test -f "$1" && test -x "$1"
188b41a30aaSmrg}
18906f32fbeSmrg
19006f32fbeSmrg
191b41a30aaSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192b41a30aaSmrg# --------------------------------------------
193b41a30aaSmrg# Search for either a program that responds to --version with output
194b41a30aaSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195b41a30aaSmrg# trying all the directories in PATH with each of the elements of
196b41a30aaSmrg# PROGS_LIST.
197b41a30aaSmrg#
198b41a30aaSmrg# CHECK_FUNC should accept the path to a candidate program, and
199b41a30aaSmrg# set $func_check_prog_result if it truncates its output less than
200b41a30aaSmrg# $_G_path_prog_max characters.
201b41a30aaSmrgfunc_path_progs ()
20206f32fbeSmrg{
203b41a30aaSmrg    _G_progs_list=$1
204b41a30aaSmrg    _G_check_func=$2
205b41a30aaSmrg    _G_PATH=${3-"$PATH"}
206b41a30aaSmrg
207b41a30aaSmrg    _G_path_prog_max=0
208b41a30aaSmrg    _G_path_prog_found=false
209b41a30aaSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210b41a30aaSmrg    for _G_dir in $_G_PATH; do
211b41a30aaSmrg      IFS=$_G_save_IFS
212b41a30aaSmrg      test -z "$_G_dir" && _G_dir=.
213b41a30aaSmrg      for _G_prog_name in $_G_progs_list; do
214b41a30aaSmrg        for _exeext in '' .EXE; do
215b41a30aaSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216b41a30aaSmrg          func_executable_p "$_G_path_prog" || continue
217b41a30aaSmrg          case `"$_G_path_prog" --version 2>&1` in
218b41a30aaSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219b41a30aaSmrg            *)     $_G_check_func $_G_path_prog
220b41a30aaSmrg		   func_path_progs_result=$func_check_prog_result
221b41a30aaSmrg		   ;;
222b41a30aaSmrg          esac
223b41a30aaSmrg          $_G_path_prog_found && break 3
224b41a30aaSmrg        done
225b41a30aaSmrg      done
226b41a30aaSmrg    done
227b41a30aaSmrg    IFS=$_G_save_IFS
228b41a30aaSmrg    test -z "$func_path_progs_result" && {
229b41a30aaSmrg      echo "no acceptable sed could be found in \$PATH" >&2
230b41a30aaSmrg      exit 1
231b41a30aaSmrg    }
232b41a30aaSmrg}
23306f32fbeSmrg
23406f32fbeSmrg
235b41a30aaSmrg# We want to be able to use the functions in this file before configure
236b41a30aaSmrg# has figured out where the best binaries are kept, which means we have
237b41a30aaSmrg# to search for them ourselves - except when the results are already set
238b41a30aaSmrg# where we skip the searches.
23906f32fbeSmrg
240b41a30aaSmrg# Unless the user overrides by setting SED, search the path for either GNU
241b41a30aaSmrg# sed, or the sed that truncates its output the least.
242b41a30aaSmrgtest -z "$SED" && {
243b41a30aaSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244b41a30aaSmrg  for _G_i in 1 2 3 4 5 6 7; do
245b41a30aaSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246b41a30aaSmrg  done
247b41a30aaSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248b41a30aaSmrg  _G_sed_script=
24906f32fbeSmrg
250b41a30aaSmrg  func_check_prog_sed ()
251b41a30aaSmrg  {
252b41a30aaSmrg    _G_path_prog=$1
253ea133fd7Smrg
254b41a30aaSmrg    _G_count=0
255b41a30aaSmrg    printf 0123456789 >conftest.in
256b41a30aaSmrg    while :
257b41a30aaSmrg    do
258b41a30aaSmrg      cat conftest.in conftest.in >conftest.tmp
259b41a30aaSmrg      mv conftest.tmp conftest.in
260b41a30aaSmrg      cp conftest.in conftest.nl
261b41a30aaSmrg      echo '' >> conftest.nl
262b41a30aaSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263b41a30aaSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264b41a30aaSmrg      _G_count=`expr $_G_count + 1`
265b41a30aaSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266b41a30aaSmrg        # Best one so far, save it but keep looking for a better one
267b41a30aaSmrg        func_check_prog_result=$_G_path_prog
268b41a30aaSmrg        _G_path_prog_max=$_G_count
269b41a30aaSmrg      fi
270b41a30aaSmrg      # 10*(2^10) chars as input seems more than enough
271b41a30aaSmrg      test 10 -lt "$_G_count" && break
272b41a30aaSmrg    done
273b41a30aaSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274b41a30aaSmrg  }
275a253d6aeSmrg
276b41a30aaSmrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277b41a30aaSmrg  rm -f conftest.sed
278b41a30aaSmrg  SED=$func_path_progs_result
279b41a30aaSmrg}
28025b89263Smrg
281b41a30aaSmrg
282b41a30aaSmrg# Unless the user overrides by setting GREP, search the path for either GNU
283b41a30aaSmrg# grep, or the grep that truncates its output the least.
284b41a30aaSmrgtest -z "$GREP" && {
285b41a30aaSmrg  func_check_prog_grep ()
286b41a30aaSmrg  {
287b41a30aaSmrg    _G_path_prog=$1
288b41a30aaSmrg
289b41a30aaSmrg    _G_count=0
290b41a30aaSmrg    _G_path_prog_max=0
291b41a30aaSmrg    printf 0123456789 >conftest.in
292b41a30aaSmrg    while :
293b41a30aaSmrg    do
294b41a30aaSmrg      cat conftest.in conftest.in >conftest.tmp
295b41a30aaSmrg      mv conftest.tmp conftest.in
296b41a30aaSmrg      cp conftest.in conftest.nl
297b41a30aaSmrg      echo 'GREP' >> conftest.nl
298b41a30aaSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299b41a30aaSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300b41a30aaSmrg      _G_count=`expr $_G_count + 1`
301b41a30aaSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302b41a30aaSmrg        # Best one so far, save it but keep looking for a better one
303b41a30aaSmrg        func_check_prog_result=$_G_path_prog
304b41a30aaSmrg        _G_path_prog_max=$_G_count
305b41a30aaSmrg      fi
306b41a30aaSmrg      # 10*(2^10) chars as input seems more than enough
307b41a30aaSmrg      test 10 -lt "$_G_count" && break
308b41a30aaSmrg    done
309b41a30aaSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310b41a30aaSmrg  }
311b41a30aaSmrg
312b41a30aaSmrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313b41a30aaSmrg  GREP=$func_path_progs_result
314b41a30aaSmrg}
315b41a30aaSmrg
316b41a30aaSmrg
317b41a30aaSmrg## ------------------------------- ##
318b41a30aaSmrg## User overridable command paths. ##
319b41a30aaSmrg## ------------------------------- ##
320b41a30aaSmrg
321b41a30aaSmrg# All uppercase variable names are used for environment variables.  These
322b41a30aaSmrg# variables can be overridden by the user before calling a script that
323b41a30aaSmrg# uses them if a suitable command of that name is not already available
324b41a30aaSmrg# in the command search PATH.
325b41a30aaSmrg
326b41a30aaSmrg: ${CP="cp -f"}
327b41a30aaSmrg: ${ECHO="printf %s\n"}
328b41a30aaSmrg: ${EGREP="$GREP -E"}
329b41a30aaSmrg: ${FGREP="$GREP -F"}
330b41a30aaSmrg: ${LN_S="ln -s"}
331b41a30aaSmrg: ${MAKE="make"}
332b41a30aaSmrg: ${MKDIR="mkdir"}
333b41a30aaSmrg: ${MV="mv -f"}
334b41a30aaSmrg: ${RM="rm -f"}
335b41a30aaSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336b41a30aaSmrg
337b41a30aaSmrg
338b41a30aaSmrg## -------------------- ##
339b41a30aaSmrg## Useful sed snippets. ##
340b41a30aaSmrg## -------------------- ##
341b41a30aaSmrg
342b41a30aaSmrgsed_dirname='s|/[^/]*$||'
343b41a30aaSmrgsed_basename='s|^.*/||'
344b41a30aaSmrg
345b41a30aaSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
346b41a30aaSmrg# metacharacters that are still active within double-quoted strings.
347b41a30aaSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348b41a30aaSmrg
349b41a30aaSmrg# Same as above, but do not quote variable references.
350b41a30aaSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351b41a30aaSmrg
352b41a30aaSmrg# Sed substitution that turns a string into a regex matching for the
353b41a30aaSmrg# string literally.
354b41a30aaSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355b41a30aaSmrg
356b41a30aaSmrg# Sed substitution that converts a w32 file name or path
357b41a30aaSmrg# that contains forward slashes, into one that contains
358b41a30aaSmrg# (escaped) backslashes.  A very naive implementation.
359b41a30aaSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360b41a30aaSmrg
361b41a30aaSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362b41a30aaSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363b41a30aaSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364b41a30aaSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
365b41a30aaSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366b41a30aaSmrg_G_bs='\\'
367b41a30aaSmrg_G_bs2='\\\\'
368b41a30aaSmrg_G_bs4='\\\\\\\\'
369b41a30aaSmrg_G_dollar='\$'
370b41a30aaSmrgsed_double_backslash="\
371b41a30aaSmrg  s/$_G_bs4/&\\
372b41a30aaSmrg/g
373b41a30aaSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374b41a30aaSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375b41a30aaSmrg  s/\n//g"
376b41a30aaSmrg
377b41a30aaSmrg# require_check_ifs_backslash
378b41a30aaSmrg# ---------------------------
379b41a30aaSmrg# Check if we can use backslash as IFS='\' separator, and set
380b41a30aaSmrg# $check_ifs_backshlash_broken to ':' or 'false'.
381b41a30aaSmrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382b41a30aaSmrgfunc_require_check_ifs_backslash ()
38325b89263Smrg{
384b41a30aaSmrg  _G_save_IFS=$IFS
385b41a30aaSmrg  IFS='\'
386b41a30aaSmrg  _G_check_ifs_backshlash='a\\b'
387b41a30aaSmrg  for _G_i in $_G_check_ifs_backshlash
388b41a30aaSmrg  do
389b41a30aaSmrg  case $_G_i in
390b41a30aaSmrg  a)
391b41a30aaSmrg    check_ifs_backshlash_broken=false
39225b89263Smrg    ;;
393b41a30aaSmrg  '')
394b41a30aaSmrg    break
39525b89263Smrg    ;;
396b41a30aaSmrg  *)
397b41a30aaSmrg    check_ifs_backshlash_broken=:
398b41a30aaSmrg    break
39925b89263Smrg    ;;
40025b89263Smrg  esac
40125b89263Smrg  done
402b41a30aaSmrg  IFS=$_G_save_IFS
403b41a30aaSmrg  require_check_ifs_backslash=:
40425b89263Smrg}
40525b89263Smrg
40625b89263Smrg
407b41a30aaSmrg## ----------------- ##
408b41a30aaSmrg## Global variables. ##
409b41a30aaSmrg## ----------------- ##
41025b89263Smrg
411b41a30aaSmrg# Except for the global variables explicitly listed below, the following
412b41a30aaSmrg# functions in the '^func_' namespace, and the '^require_' namespace
413b41a30aaSmrg# variables initialised in the 'Resource management' section, sourcing
414b41a30aaSmrg# this file will not pollute your global namespace with anything
415b41a30aaSmrg# else. There's no portable way to scope variables in Bourne shell
416b41a30aaSmrg# though, so actually running these functions will sometimes place
417b41a30aaSmrg# results into a variable named after the function, and often use
418b41a30aaSmrg# temporary variables in the '^_G_' namespace. If you are careful to
419b41a30aaSmrg# avoid using those namespaces casually in your sourcing script, things
420b41a30aaSmrg# should continue to work as you expect. And, of course, you can freely
421b41a30aaSmrg# overwrite any of the functions or variables defined here before
422b41a30aaSmrg# calling anything to customize them.
423b41a30aaSmrg
424b41a30aaSmrgEXIT_SUCCESS=0
425b41a30aaSmrgEXIT_FAILURE=1
426b41a30aaSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427b41a30aaSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428b41a30aaSmrg
429b41a30aaSmrg# Allow overriding, eg assuming that you follow the convention of
430b41a30aaSmrg# putting '$debug_cmd' at the start of all your functions, you can get
431b41a30aaSmrg# bash to show function call trace with:
432b41a30aaSmrg#
433b41a30aaSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434b41a30aaSmrgdebug_cmd=${debug_cmd-":"}
435b41a30aaSmrgexit_cmd=:
436b41a30aaSmrg
437b41a30aaSmrg# By convention, finish your script with:
438b41a30aaSmrg#
439b41a30aaSmrg#    exit $exit_status
440b41a30aaSmrg#
441b41a30aaSmrg# so that you can set exit_status to non-zero if you want to indicate
442b41a30aaSmrg# something went wrong during execution without actually bailing out at
443b41a30aaSmrg# the point of failure.
444b41a30aaSmrgexit_status=$EXIT_SUCCESS
445a253d6aeSmrg
446b41a30aaSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447b41a30aaSmrg# is ksh but when the shell is invoked as "sh" and the current value of
448b41a30aaSmrg# the _XPG environment variable is not equal to 1 (one), the special
449b41a30aaSmrg# positional parameter $0, within a function call, is the name of the
450b41a30aaSmrg# function.
451b41a30aaSmrgprogpath=$0
452b41a30aaSmrg
453b41a30aaSmrg# The name of this program.
454b41a30aaSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455a253d6aeSmrg
456b41a30aaSmrg# Make sure we have an absolute progpath for reexecution:
457ea133fd7Smrgcase $progpath in
458ea133fd7Smrg  [\\/]*|[A-Za-z]:\\*) ;;
459ea133fd7Smrg  *[\\/]*)
460b41a30aaSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461ea133fd7Smrg     progdir=`cd "$progdir" && pwd`
462b41a30aaSmrg     progpath=$progdir/$progname
463ea133fd7Smrg     ;;
464ea133fd7Smrg  *)
465b41a30aaSmrg     _G_IFS=$IFS
46657ee1794Smrg     IFS=${PATH_SEPARATOR-:}
467ea133fd7Smrg     for progdir in $PATH; do
468b41a30aaSmrg       IFS=$_G_IFS
469ea133fd7Smrg       test -x "$progdir/$progname" && break
470ea133fd7Smrg     done
471b41a30aaSmrg     IFS=$_G_IFS
472ea133fd7Smrg     test -n "$progdir" || progdir=`pwd`
473b41a30aaSmrg     progpath=$progdir/$progname
474ea133fd7Smrg     ;;
475ea133fd7Smrgesac
476a253d6aeSmrg
477ea133fd7Smrg
478b41a30aaSmrg## ----------------- ##
479b41a30aaSmrg## Standard options. ##
480b41a30aaSmrg## ----------------- ##
48106f32fbeSmrg
482b41a30aaSmrg# The following options affect the operation of the functions defined
483b41a30aaSmrg# below, and should be set appropriately depending on run-time para-
484b41a30aaSmrg# meters passed on the command line.
485ea133fd7Smrg
486ea133fd7Smrgopt_dry_run=false
487ea133fd7Smrgopt_quiet=false
488ea133fd7Smrgopt_verbose=false
489ea133fd7Smrg
490b41a30aaSmrg# Categories 'all' and 'none' are always available.  Append any others
491b41a30aaSmrg# you will pass as the first argument to func_warning from your own
492b41a30aaSmrg# code.
493b41a30aaSmrgwarning_categories=
494a253d6aeSmrg
495b41a30aaSmrg# By default, display warnings according to 'opt_warning_types'.  Set
496b41a30aaSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497b41a30aaSmrg# treat the next displayed warning as a fatal error.
498b41a30aaSmrgwarning_func=func_warn_and_continue
499a253d6aeSmrg
500b41a30aaSmrg# Set to 'all' to display all warnings, 'none' to suppress all
501b41a30aaSmrg# warnings, or a space delimited list of some subset of
502b41a30aaSmrg# 'warning_categories' to display only the listed warnings.
503b41a30aaSmrgopt_warning_types=all
504a253d6aeSmrg
50525b89263Smrg
506b41a30aaSmrg## -------------------- ##
507b41a30aaSmrg## Resource management. ##
508b41a30aaSmrg## -------------------- ##
509a253d6aeSmrg
510b41a30aaSmrg# This section contains definitions for functions that each ensure a
511b41a30aaSmrg# particular resource (a file, or a non-empty configuration variable for
512b41a30aaSmrg# example) is available, and if appropriate to extract default values
513b41a30aaSmrg# from pertinent package files. Call them using their associated
514b41a30aaSmrg# 'require_*' variable to ensure that they are executed, at most, once.
515b41a30aaSmrg#
516b41a30aaSmrg# It's entirely deliberate that calling these functions can set
517b41a30aaSmrg# variables that don't obey the namespace limitations obeyed by the rest
518b41a30aaSmrg# of this file, in order that that they be as useful as possible to
519b41a30aaSmrg# callers.
520a253d6aeSmrg
521a253d6aeSmrg
522b41a30aaSmrg# require_term_colors
523b41a30aaSmrg# -------------------
524b41a30aaSmrg# Allow display of bold text on terminals that support it.
525b41a30aaSmrgrequire_term_colors=func_require_term_colors
526b41a30aaSmrgfunc_require_term_colors ()
527ea133fd7Smrg{
528b41a30aaSmrg    $debug_cmd
529b41a30aaSmrg
530b41a30aaSmrg    test -t 1 && {
531b41a30aaSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532b41a30aaSmrg      # precedence, because most terminfo databases neglect to describe
533b41a30aaSmrg      # whether color sequences are supported.
534b41a30aaSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535b41a30aaSmrg
536b41a30aaSmrg      if test 1 = "$USE_ANSI_COLORS"; then
537b41a30aaSmrg        # Standard ANSI escape sequences
538b41a30aaSmrg        tc_reset='[0m'
539b41a30aaSmrg        tc_bold='[1m';   tc_standout='[7m'
540b41a30aaSmrg        tc_red='[31m';   tc_green='[32m'
541b41a30aaSmrg        tc_blue='[34m';  tc_cyan='[36m'
542b41a30aaSmrg      else
543b41a30aaSmrg        # Otherwise trust the terminfo database after all.
544b41a30aaSmrg        test -n "`tput sgr0 2>/dev/null`" && {
545b41a30aaSmrg          tc_reset=`tput sgr0`
546b41a30aaSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547b41a30aaSmrg          tc_standout=$tc_bold
548b41a30aaSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549b41a30aaSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550b41a30aaSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551b41a30aaSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552b41a30aaSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553b41a30aaSmrg        }
554b41a30aaSmrg      fi
555b41a30aaSmrg    }
556a253d6aeSmrg
557b41a30aaSmrg    require_term_colors=:
558ea133fd7Smrg}
559a253d6aeSmrg
560a253d6aeSmrg
561b41a30aaSmrg## ----------------- ##
562b41a30aaSmrg## Function library. ##
563b41a30aaSmrg## ----------------- ##
564ea133fd7Smrg
565b41a30aaSmrg# This section contains a variety of useful functions to call in your
566b41a30aaSmrg# scripts. Take note of the portable wrappers for features provided by
567b41a30aaSmrg# some modern shells, which will fall back to slower equivalents on
568b41a30aaSmrg# less featureful shells.
569ea133fd7Smrg
570b41a30aaSmrg
571b41a30aaSmrg# func_append VAR VALUE
572b41a30aaSmrg# ---------------------
573b41a30aaSmrg# Append VALUE onto the existing contents of VAR.
574b41a30aaSmrg
575b41a30aaSmrg  # We should try to minimise forks, especially on Windows where they are
576b41a30aaSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577b41a30aaSmrg  # being used:
578b41a30aaSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579b41a30aaSmrg    : ${_G_HAVE_ARITH_OP="yes"}
580b41a30aaSmrg    : ${_G_HAVE_XSI_OPS="yes"}
581b41a30aaSmrg    # The += operator was introduced in bash 3.1
582b41a30aaSmrg    case $BASH_VERSION in
583b41a30aaSmrg      [12].* | 3.0 | 3.0*) ;;
584b41a30aaSmrg      *)
585b41a30aaSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586b41a30aaSmrg        ;;
587b41a30aaSmrg    esac
588b41a30aaSmrg  fi
589b41a30aaSmrg
590b41a30aaSmrg  # _G_HAVE_PLUSEQ_OP
591b41a30aaSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
592b41a30aaSmrg  # useable or anything else if it does not work.
593b41a30aaSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594b41a30aaSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595b41a30aaSmrg    && _G_HAVE_PLUSEQ_OP=yes
596b41a30aaSmrg
597b41a30aaSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598b41a30aaSmrgthen
599b41a30aaSmrg  # This is an XSI compatible shell, allowing a faster implementation...
600b41a30aaSmrg  eval 'func_append ()
601b41a30aaSmrg  {
602b41a30aaSmrg    $debug_cmd
603b41a30aaSmrg
604b41a30aaSmrg    eval "$1+=\$2"
605b41a30aaSmrg  }'
606b41a30aaSmrgelse
607b41a30aaSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608b41a30aaSmrg  func_append ()
609b41a30aaSmrg  {
610b41a30aaSmrg    $debug_cmd
611b41a30aaSmrg
612b41a30aaSmrg    eval "$1=\$$1\$2"
613b41a30aaSmrg  }
614b41a30aaSmrgfi
615b41a30aaSmrg
616b41a30aaSmrg
617b41a30aaSmrg# func_append_quoted VAR VALUE
618b41a30aaSmrg# ----------------------------
619b41a30aaSmrg# Quote VALUE and append to the end of shell variable VAR, separated
620b41a30aaSmrg# by a space.
621b41a30aaSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622b41a30aaSmrg  eval 'func_append_quoted ()
623b41a30aaSmrg  {
624b41a30aaSmrg    $debug_cmd
625b41a30aaSmrg
626b41a30aaSmrg    func_quote_arg pretty "$2"
627b41a30aaSmrg    eval "$1+=\\ \$func_quote_arg_result"
628b41a30aaSmrg  }'
629b41a30aaSmrgelse
630b41a30aaSmrg  func_append_quoted ()
631b41a30aaSmrg  {
632b41a30aaSmrg    $debug_cmd
633b41a30aaSmrg
634b41a30aaSmrg    func_quote_arg pretty "$2"
635b41a30aaSmrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636b41a30aaSmrg  }
637b41a30aaSmrgfi
638b41a30aaSmrg
639b41a30aaSmrg
640b41a30aaSmrg# func_append_uniq VAR VALUE
641b41a30aaSmrg# --------------------------
642b41a30aaSmrg# Append unique VALUE onto the existing contents of VAR, assuming
643b41a30aaSmrg# entries are delimited by the first character of VALUE.  For example:
644b41a30aaSmrg#
645b41a30aaSmrg#   func_append_uniq options " --another-option option-argument"
646b41a30aaSmrg#
647b41a30aaSmrg# will only append to $options if " --another-option option-argument "
648b41a30aaSmrg# is not already present somewhere in $options already (note spaces at
649b41a30aaSmrg# each end implied by leading space in second argument).
650b41a30aaSmrgfunc_append_uniq ()
651b41a30aaSmrg{
652b41a30aaSmrg    $debug_cmd
653b41a30aaSmrg
654b41a30aaSmrg    eval _G_current_value='`$ECHO $'$1'`'
655b41a30aaSmrg    _G_delim=`expr "$2" : '\(.\)'`
656b41a30aaSmrg
657b41a30aaSmrg    case $_G_delim$_G_current_value$_G_delim in
658b41a30aaSmrg      *"$2$_G_delim"*) ;;
659b41a30aaSmrg      *) func_append "$@" ;;
660b41a30aaSmrg    esac
661b41a30aaSmrg}
662b41a30aaSmrg
663b41a30aaSmrg
664b41a30aaSmrg# func_arith TERM...
665b41a30aaSmrg# ------------------
666b41a30aaSmrg# Set func_arith_result to the result of evaluating TERMs.
667b41a30aaSmrg  test -z "$_G_HAVE_ARITH_OP" \
668b41a30aaSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669b41a30aaSmrg    && _G_HAVE_ARITH_OP=yes
670b41a30aaSmrg
671b41a30aaSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
672b41a30aaSmrg  eval 'func_arith ()
673b41a30aaSmrg  {
674b41a30aaSmrg    $debug_cmd
675b41a30aaSmrg
676b41a30aaSmrg    func_arith_result=$(( $* ))
677b41a30aaSmrg  }'
678b41a30aaSmrgelse
679b41a30aaSmrg  func_arith ()
680b41a30aaSmrg  {
681b41a30aaSmrg    $debug_cmd
682b41a30aaSmrg
683b41a30aaSmrg    func_arith_result=`expr "$@"`
684b41a30aaSmrg  }
685b41a30aaSmrgfi
686b41a30aaSmrg
687b41a30aaSmrg
688b41a30aaSmrg# func_basename FILE
689b41a30aaSmrg# ------------------
690b41a30aaSmrg# Set func_basename_result to FILE with everything up to and including
691b41a30aaSmrg# the last / stripped.
692b41a30aaSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
693b41a30aaSmrg  # If this shell supports suffix pattern removal, then use it to avoid
694b41a30aaSmrg  # forking. Hide the definitions single quotes in case the shell chokes
695b41a30aaSmrg  # on unsupported syntax...
696b41a30aaSmrg  _b='func_basename_result=${1##*/}'
697b41a30aaSmrg  _d='case $1 in
698b41a30aaSmrg        */*) func_dirname_result=${1%/*}$2 ;;
699b41a30aaSmrg        *  ) func_dirname_result=$3        ;;
700b41a30aaSmrg      esac'
701b41a30aaSmrg
702b41a30aaSmrgelse
703b41a30aaSmrg  # ...otherwise fall back to using sed.
704b41a30aaSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705b41a30aaSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706b41a30aaSmrg      if test "X$func_dirname_result" = "X$1"; then
707b41a30aaSmrg        func_dirname_result=$3
708b41a30aaSmrg      else
709b41a30aaSmrg        func_append func_dirname_result "$2"
710b41a30aaSmrg      fi'
711b41a30aaSmrgfi
712b41a30aaSmrg
713b41a30aaSmrgeval 'func_basename ()
714b41a30aaSmrg{
715b41a30aaSmrg    $debug_cmd
716b41a30aaSmrg
717b41a30aaSmrg    '"$_b"'
718b41a30aaSmrg}'
719b41a30aaSmrg
720b41a30aaSmrg
721b41a30aaSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722b41a30aaSmrg# -------------------------------------------
723b41a30aaSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724b41a30aaSmrg# otherwise set result to NONDIR_REPLACEMENT.
725b41a30aaSmrgeval 'func_dirname ()
726b41a30aaSmrg{
727b41a30aaSmrg    $debug_cmd
728b41a30aaSmrg
729b41a30aaSmrg    '"$_d"'
730b41a30aaSmrg}'
731b41a30aaSmrg
732b41a30aaSmrg
733b41a30aaSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734b41a30aaSmrg# --------------------------------------------------------
735b41a30aaSmrg# Perform func_basename and func_dirname in a single function
736b41a30aaSmrg# call:
737b41a30aaSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738b41a30aaSmrg#             add APPEND to the result, otherwise set result
739b41a30aaSmrg#             to NONDIR_REPLACEMENT.
740b41a30aaSmrg#             value returned in "$func_dirname_result"
741b41a30aaSmrg#   basename: Compute filename of FILE.
742b41a30aaSmrg#             value retuned in "$func_basename_result"
743b41a30aaSmrg# For efficiency, we do not delegate to the functions above but instead
744b41a30aaSmrg# duplicate the functionality here.
745b41a30aaSmrgeval 'func_dirname_and_basename ()
746b41a30aaSmrg{
747b41a30aaSmrg    $debug_cmd
748b41a30aaSmrg
749b41a30aaSmrg    '"$_b"'
750b41a30aaSmrg    '"$_d"'
751b41a30aaSmrg}'
752b41a30aaSmrg
753b41a30aaSmrg
754b41a30aaSmrg# func_echo ARG...
755b41a30aaSmrg# ----------------
756b41a30aaSmrg# Echo program name prefixed message.
757b41a30aaSmrgfunc_echo ()
758b41a30aaSmrg{
759b41a30aaSmrg    $debug_cmd
760b41a30aaSmrg
761b41a30aaSmrg    _G_message=$*
762b41a30aaSmrg
763b41a30aaSmrg    func_echo_IFS=$IFS
764b41a30aaSmrg    IFS=$nl
765b41a30aaSmrg    for _G_line in $_G_message; do
766b41a30aaSmrg      IFS=$func_echo_IFS
767b41a30aaSmrg      $ECHO "$progname: $_G_line"
768b41a30aaSmrg    done
769b41a30aaSmrg    IFS=$func_echo_IFS
770b41a30aaSmrg}
771b41a30aaSmrg
772b41a30aaSmrg
773b41a30aaSmrg# func_echo_all ARG...
774b41a30aaSmrg# --------------------
775b41a30aaSmrg# Invoke $ECHO with all args, space-separated.
776b41a30aaSmrgfunc_echo_all ()
777b41a30aaSmrg{
778b41a30aaSmrg    $ECHO "$*"
779b41a30aaSmrg}
780b41a30aaSmrg
781b41a30aaSmrg
782b41a30aaSmrg# func_echo_infix_1 INFIX ARG...
783b41a30aaSmrg# ------------------------------
784b41a30aaSmrg# Echo program name, followed by INFIX on the first line, with any
785b41a30aaSmrg# additional lines not showing INFIX.
786b41a30aaSmrgfunc_echo_infix_1 ()
787b41a30aaSmrg{
788b41a30aaSmrg    $debug_cmd
789b41a30aaSmrg
790b41a30aaSmrg    $require_term_colors
791b41a30aaSmrg
792b41a30aaSmrg    _G_infix=$1; shift
793b41a30aaSmrg    _G_indent=$_G_infix
794b41a30aaSmrg    _G_prefix="$progname: $_G_infix: "
795b41a30aaSmrg    _G_message=$*
796b41a30aaSmrg
797b41a30aaSmrg    # Strip color escape sequences before counting printable length
798b41a30aaSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799b41a30aaSmrg    do
800b41a30aaSmrg      test -n "$_G_tc" && {
801b41a30aaSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802b41a30aaSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803b41a30aaSmrg      }
804b41a30aaSmrg    done
805b41a30aaSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806b41a30aaSmrg
807b41a30aaSmrg    func_echo_infix_1_IFS=$IFS
808b41a30aaSmrg    IFS=$nl
809b41a30aaSmrg    for _G_line in $_G_message; do
810b41a30aaSmrg      IFS=$func_echo_infix_1_IFS
811b41a30aaSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812b41a30aaSmrg      _G_prefix=$_G_indent
813b41a30aaSmrg    done
814b41a30aaSmrg    IFS=$func_echo_infix_1_IFS
815b41a30aaSmrg}
816b41a30aaSmrg
817b41a30aaSmrg
818b41a30aaSmrg# func_error ARG...
819b41a30aaSmrg# -----------------
820b41a30aaSmrg# Echo program name prefixed message to standard error.
821b41a30aaSmrgfunc_error ()
822b41a30aaSmrg{
823b41a30aaSmrg    $debug_cmd
824b41a30aaSmrg
825b41a30aaSmrg    $require_term_colors
826b41a30aaSmrg
827b41a30aaSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828b41a30aaSmrg}
829b41a30aaSmrg
830b41a30aaSmrg
831b41a30aaSmrg# func_fatal_error ARG...
832b41a30aaSmrg# -----------------------
833b41a30aaSmrg# Echo program name prefixed message to standard error, and exit.
834b41a30aaSmrgfunc_fatal_error ()
835b41a30aaSmrg{
836b41a30aaSmrg    $debug_cmd
837b41a30aaSmrg
838b41a30aaSmrg    func_error "$*"
839b41a30aaSmrg    exit $EXIT_FAILURE
840b41a30aaSmrg}
841b41a30aaSmrg
842b41a30aaSmrg
843b41a30aaSmrg# func_grep EXPRESSION FILENAME
844b41a30aaSmrg# -----------------------------
845b41a30aaSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846b41a30aaSmrgfunc_grep ()
847ea133fd7Smrg{
848b41a30aaSmrg    $debug_cmd
849b41a30aaSmrg
850b41a30aaSmrg    $GREP "$1" "$2" >/dev/null 2>&1
851b41a30aaSmrg}
852b41a30aaSmrg
853ea133fd7Smrg
854b41a30aaSmrg# func_len STRING
855b41a30aaSmrg# ---------------
856b41a30aaSmrg# Set func_len_result to the length of STRING. STRING may not
857b41a30aaSmrg# start with a hyphen.
858b41a30aaSmrg  test -z "$_G_HAVE_XSI_OPS" \
859b41a30aaSmrg    && (eval 'x=a/b/c;
860b41a30aaSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861b41a30aaSmrg    && _G_HAVE_XSI_OPS=yes
862b41a30aaSmrg
863b41a30aaSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
864b41a30aaSmrg  eval 'func_len ()
865b41a30aaSmrg  {
866b41a30aaSmrg    $debug_cmd
867b41a30aaSmrg
868b41a30aaSmrg    func_len_result=${#1}
869b41a30aaSmrg  }'
870b41a30aaSmrgelse
871b41a30aaSmrg  func_len ()
872b41a30aaSmrg  {
873b41a30aaSmrg    $debug_cmd
874b41a30aaSmrg
875b41a30aaSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876b41a30aaSmrg  }
877b41a30aaSmrgfi
878b41a30aaSmrg
879b41a30aaSmrg
880b41a30aaSmrg# func_mkdir_p DIRECTORY-PATH
881b41a30aaSmrg# ---------------------------
882b41a30aaSmrg# Make sure the entire path to DIRECTORY-PATH is available.
883b41a30aaSmrgfunc_mkdir_p ()
884b41a30aaSmrg{
885b41a30aaSmrg    $debug_cmd
886ea133fd7Smrg
887b41a30aaSmrg    _G_directory_path=$1
888b41a30aaSmrg    _G_dir_list=
889b41a30aaSmrg
890b41a30aaSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891b41a30aaSmrg
892b41a30aaSmrg      # Protect directory names starting with '-'
893b41a30aaSmrg      case $_G_directory_path in
894b41a30aaSmrg        -*) _G_directory_path=./$_G_directory_path ;;
895ea133fd7Smrg      esac
896ea133fd7Smrg
897ea133fd7Smrg      # While some portion of DIR does not yet exist...
898b41a30aaSmrg      while test ! -d "$_G_directory_path"; do
899ea133fd7Smrg        # ...make a list in topmost first order.  Use a colon delimited
900ea133fd7Smrg	# list incase some portion of path contains whitespace.
901b41a30aaSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902ea133fd7Smrg
903ea133fd7Smrg        # If the last portion added has no slash in it, the list is done
904b41a30aaSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
905ea133fd7Smrg
906ea133fd7Smrg        # ...otherwise throw away the child directory and loop
907b41a30aaSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908ea133fd7Smrg      done
909b41a30aaSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910ea133fd7Smrg
911b41a30aaSmrg      func_mkdir_p_IFS=$IFS; IFS=:
912b41a30aaSmrg      for _G_dir in $_G_dir_list; do
913b41a30aaSmrg	IFS=$func_mkdir_p_IFS
914b41a30aaSmrg        # mkdir can fail with a 'File exist' error if two processes
915ea133fd7Smrg        # try to create one of the directories concurrently.  Don't
916ea133fd7Smrg        # stop in that case!
917b41a30aaSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
918ea133fd7Smrg      done
919b41a30aaSmrg      IFS=$func_mkdir_p_IFS
920ea133fd7Smrg
921ea133fd7Smrg      # Bail out if we (or some other process) failed to create a directory.
922b41a30aaSmrg      test -d "$_G_directory_path" || \
923b41a30aaSmrg        func_fatal_error "Failed to create '$1'"
924ea133fd7Smrg    fi
925ea133fd7Smrg}
926a253d6aeSmrg
927a253d6aeSmrg
928b41a30aaSmrg# func_mktempdir [BASENAME]
929b41a30aaSmrg# -------------------------
930a253d6aeSmrg# Make a temporary directory that won't clash with other running
931a253d6aeSmrg# libtool processes, and avoids race conditions if possible.  If
932b41a30aaSmrg# given, BASENAME is the basename for that directory.
933a253d6aeSmrgfunc_mktempdir ()
934a253d6aeSmrg{
935b41a30aaSmrg    $debug_cmd
936a253d6aeSmrg
937b41a30aaSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938b41a30aaSmrg
939b41a30aaSmrg    if test : = "$opt_dry_run"; then
940a253d6aeSmrg      # Return a directory name, but don't create it in dry-run mode
941b41a30aaSmrg      _G_tmpdir=$_G_template-$$
942a253d6aeSmrg    else
943a253d6aeSmrg
944a253d6aeSmrg      # If mktemp works, use that first and foremost
945b41a30aaSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946a253d6aeSmrg
947b41a30aaSmrg      if test ! -d "$_G_tmpdir"; then
948ea133fd7Smrg        # Failing that, at least try and use $RANDOM to avoid a race
949b41a30aaSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950a253d6aeSmrg
951b41a30aaSmrg        func_mktempdir_umask=`umask`
952ea133fd7Smrg        umask 0077
953b41a30aaSmrg        $MKDIR "$_G_tmpdir"
954b41a30aaSmrg        umask $func_mktempdir_umask
955a253d6aeSmrg      fi
956a253d6aeSmrg
957a253d6aeSmrg      # If we're not in dry-run mode, bomb out on failure
958b41a30aaSmrg      test -d "$_G_tmpdir" || \
959b41a30aaSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960a253d6aeSmrg    fi
961a253d6aeSmrg
962b41a30aaSmrg    $ECHO "$_G_tmpdir"
963a253d6aeSmrg}
964a253d6aeSmrg
965a253d6aeSmrg
966b41a30aaSmrg# func_normal_abspath PATH
967b41a30aaSmrg# ------------------------
968b41a30aaSmrg# Remove doubled-up and trailing slashes, "." path components,
969b41a30aaSmrg# and cancel out any ".." path components in PATH after making
970b41a30aaSmrg# it an absolute path.
971b41a30aaSmrgfunc_normal_abspath ()
972a253d6aeSmrg{
973b41a30aaSmrg    $debug_cmd
974b41a30aaSmrg
975b41a30aaSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
976b41a30aaSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977b41a30aaSmrg    _G_pathcdr='s|^/[^/]*||'
978b41a30aaSmrg    _G_removedotparts=':dotsl
979b41a30aaSmrg		s|/\./|/|g
980b41a30aaSmrg		t dotsl
981b41a30aaSmrg		s|/\.$|/|'
982b41a30aaSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
983b41a30aaSmrg    _G_finalslash='s|/*$|/|'
984b41a30aaSmrg
985b41a30aaSmrg    # Start from root dir and reassemble the path.
986b41a30aaSmrg    func_normal_abspath_result=
987b41a30aaSmrg    func_normal_abspath_tpath=$1
988b41a30aaSmrg    func_normal_abspath_altnamespace=
989b41a30aaSmrg    case $func_normal_abspath_tpath in
990b41a30aaSmrg      "")
991b41a30aaSmrg        # Empty path, that just means $cwd.
992b41a30aaSmrg        func_stripname '' '/' "`pwd`"
993b41a30aaSmrg        func_normal_abspath_result=$func_stripname_result
994b41a30aaSmrg        return
995b41a30aaSmrg        ;;
996b41a30aaSmrg      # The next three entries are used to spot a run of precisely
997b41a30aaSmrg      # two leading slashes without using negated character classes;
998b41a30aaSmrg      # we take advantage of case's first-match behaviour.
999b41a30aaSmrg      ///*)
1000b41a30aaSmrg        # Unusual form of absolute path, do nothing.
1001b41a30aaSmrg        ;;
1002b41a30aaSmrg      //*)
1003b41a30aaSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004b41a30aaSmrg        # and for example Cygwin uses it to access remote file shares
1005b41a30aaSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006b41a30aaSmrg        func_normal_abspath_altnamespace=/
1007b41a30aaSmrg        ;;
1008b41a30aaSmrg      /*)
1009b41a30aaSmrg        # Absolute path, do nothing.
1010b41a30aaSmrg        ;;
1011ea133fd7Smrg      *)
1012b41a30aaSmrg        # Relative path, prepend $cwd.
1013b41a30aaSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014b41a30aaSmrg        ;;
1015ea133fd7Smrg    esac
1016ea133fd7Smrg
1017b41a30aaSmrg    # Cancel out all the simple stuff to save iterations.  We also want
1018b41a30aaSmrg    # the path to end with a slash for ease of parsing, so make sure
1019b41a30aaSmrg    # there is one (and only one) here.
1020b41a30aaSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021b41a30aaSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022b41a30aaSmrg    while :; do
1023b41a30aaSmrg      # Processed it all yet?
1024b41a30aaSmrg      if test / = "$func_normal_abspath_tpath"; then
1025b41a30aaSmrg        # If we ascended to the root using ".." the result may be empty now.
1026b41a30aaSmrg        if test -z "$func_normal_abspath_result"; then
1027b41a30aaSmrg          func_normal_abspath_result=/
1028b41a30aaSmrg        fi
1029b41a30aaSmrg        break
1030b41a30aaSmrg      fi
1031b41a30aaSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032b41a30aaSmrg          -e "$_G_pathcar"`
1033b41a30aaSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034b41a30aaSmrg          -e "$_G_pathcdr"`
1035b41a30aaSmrg      # Figure out what to do with it
1036b41a30aaSmrg      case $func_normal_abspath_tcomponent in
1037b41a30aaSmrg        "")
1038b41a30aaSmrg          # Trailing empty path component, ignore it.
1039b41a30aaSmrg          ;;
1040b41a30aaSmrg        ..)
1041b41a30aaSmrg          # Parent dir; strip last assembled component from result.
1042b41a30aaSmrg          func_dirname "$func_normal_abspath_result"
1043b41a30aaSmrg          func_normal_abspath_result=$func_dirname_result
1044b41a30aaSmrg          ;;
1045b41a30aaSmrg        *)
1046b41a30aaSmrg          # Actual path component, append it.
1047b41a30aaSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048b41a30aaSmrg          ;;
1049b41a30aaSmrg      esac
1050b41a30aaSmrg    done
1051b41a30aaSmrg    # Restore leading double-slash if one was found on entry.
1052b41a30aaSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053b41a30aaSmrg}
1054b41a30aaSmrg
1055b41a30aaSmrg
1056b41a30aaSmrg# func_notquiet ARG...
1057b41a30aaSmrg# --------------------
1058b41a30aaSmrg# Echo program name prefixed message only when not in quiet mode.
1059b41a30aaSmrgfunc_notquiet ()
1060b41a30aaSmrg{
1061b41a30aaSmrg    $debug_cmd
1062b41a30aaSmrg
1063b41a30aaSmrg    $opt_quiet || func_echo ${1+"$@"}
1064b41a30aaSmrg
1065b41a30aaSmrg    # A bug in bash halts the script if the last line of a function
1066b41a30aaSmrg    # fails when set -e is in force, so we need another command to
1067b41a30aaSmrg    # work around that:
1068b41a30aaSmrg    :
1069b41a30aaSmrg}
1070b41a30aaSmrg
1071b41a30aaSmrg
1072b41a30aaSmrg# func_relative_path SRCDIR DSTDIR
1073b41a30aaSmrg# --------------------------------
1074b41a30aaSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075b41a30aaSmrgfunc_relative_path ()
1076b41a30aaSmrg{
1077b41a30aaSmrg    $debug_cmd
1078b41a30aaSmrg
1079b41a30aaSmrg    func_relative_path_result=
1080b41a30aaSmrg    func_normal_abspath "$1"
1081b41a30aaSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082b41a30aaSmrg    func_normal_abspath "$2"
1083b41a30aaSmrg    func_relative_path_tbindir=$func_normal_abspath_result
1084b41a30aaSmrg
1085b41a30aaSmrg    # Ascend the tree starting from libdir
1086b41a30aaSmrg    while :; do
1087b41a30aaSmrg      # check if we have found a prefix of bindir
1088b41a30aaSmrg      case $func_relative_path_tbindir in
1089b41a30aaSmrg        $func_relative_path_tlibdir)
1090b41a30aaSmrg          # found an exact match
1091b41a30aaSmrg          func_relative_path_tcancelled=
1092b41a30aaSmrg          break
1093b41a30aaSmrg          ;;
1094b41a30aaSmrg        $func_relative_path_tlibdir*)
1095b41a30aaSmrg          # found a matching prefix
1096b41a30aaSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097b41a30aaSmrg          func_relative_path_tcancelled=$func_stripname_result
1098b41a30aaSmrg          if test -z "$func_relative_path_result"; then
1099b41a30aaSmrg            func_relative_path_result=.
1100b41a30aaSmrg          fi
1101b41a30aaSmrg          break
1102b41a30aaSmrg          ;;
1103b41a30aaSmrg        *)
1104b41a30aaSmrg          func_dirname $func_relative_path_tlibdir
1105b41a30aaSmrg          func_relative_path_tlibdir=$func_dirname_result
1106b41a30aaSmrg          if test -z "$func_relative_path_tlibdir"; then
1107b41a30aaSmrg            # Have to descend all the way to the root!
1108b41a30aaSmrg            func_relative_path_result=../$func_relative_path_result
1109b41a30aaSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110b41a30aaSmrg            break
1111b41a30aaSmrg          fi
1112b41a30aaSmrg          func_relative_path_result=../$func_relative_path_result
1113b41a30aaSmrg          ;;
1114b41a30aaSmrg      esac
1115b41a30aaSmrg    done
1116b41a30aaSmrg
1117b41a30aaSmrg    # Now calculate path; take care to avoid doubling-up slashes.
1118b41a30aaSmrg    func_stripname '' '/' "$func_relative_path_result"
1119b41a30aaSmrg    func_relative_path_result=$func_stripname_result
1120b41a30aaSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121b41a30aaSmrg    if test -n "$func_stripname_result"; then
1122b41a30aaSmrg      func_append func_relative_path_result "/$func_stripname_result"
1123b41a30aaSmrg    fi
1124b41a30aaSmrg
1125b41a30aaSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126b41a30aaSmrg    if test -n "$func_relative_path_result"; then
1127b41a30aaSmrg      func_stripname './' '' "$func_relative_path_result"
1128b41a30aaSmrg      func_relative_path_result=$func_stripname_result
1129b41a30aaSmrg    fi
1130b41a30aaSmrg
1131b41a30aaSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132b41a30aaSmrg
1133b41a30aaSmrg    :
1134b41a30aaSmrg}
1135b41a30aaSmrg
1136b41a30aaSmrg
1137b41a30aaSmrg# func_quote_portable EVAL ARG
1138b41a30aaSmrg# ----------------------------
1139b41a30aaSmrg# Internal function to portably implement func_quote_arg.  Note that we still
1140b41a30aaSmrg# keep attention to performance here so we as much as possible try to avoid
1141b41a30aaSmrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142b41a30aaSmrgfunc_quote_portable ()
1143b41a30aaSmrg{
1144b41a30aaSmrg    $debug_cmd
1145b41a30aaSmrg
1146b41a30aaSmrg    $require_check_ifs_backslash
1147b41a30aaSmrg
1148b41a30aaSmrg    func_quote_portable_result=$2
1149b41a30aaSmrg
1150b41a30aaSmrg    # one-time-loop (easy break)
1151b41a30aaSmrg    while true
1152b41a30aaSmrg    do
1153b41a30aaSmrg      if $1; then
1154b41a30aaSmrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155b41a30aaSmrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156b41a30aaSmrg        break
1157b41a30aaSmrg      fi
1158b41a30aaSmrg
1159b41a30aaSmrg      # Quote for eval.
1160b41a30aaSmrg      case $func_quote_portable_result in
1161b41a30aaSmrg        *[\\\`\"\$]*)
1162b41a30aaSmrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163b41a30aaSmrg          # contains the shell wildcard characters.
1164b41a30aaSmrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165b41a30aaSmrg            :*|*[\[\*\?]*)
1166b41a30aaSmrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167b41a30aaSmrg                  | $SED "$sed_quote_subst"`
1168b41a30aaSmrg              break
1169b41a30aaSmrg              ;;
1170b41a30aaSmrg          esac
1171b41a30aaSmrg
1172b41a30aaSmrg          func_quote_portable_old_IFS=$IFS
1173b41a30aaSmrg          for _G_char in '\' '`' '"' '$'
1174b41a30aaSmrg          do
1175b41a30aaSmrg            # STATE($1) PREV($2) SEPARATOR($3)
1176b41a30aaSmrg            set start "" ""
1177b41a30aaSmrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178b41a30aaSmrg            IFS=$_G_char
1179b41a30aaSmrg            for _G_part in $func_quote_portable_result
1180b41a30aaSmrg            do
1181b41a30aaSmrg              case $1 in
1182b41a30aaSmrg              quote)
1183b41a30aaSmrg                func_append func_quote_portable_result "$3$2"
1184b41a30aaSmrg                set quote "$_G_part" "\\$_G_char"
1185b41a30aaSmrg                ;;
1186b41a30aaSmrg              start)
1187b41a30aaSmrg                set first "" ""
1188b41a30aaSmrg                func_quote_portable_result=
1189b41a30aaSmrg                ;;
1190b41a30aaSmrg              first)
1191b41a30aaSmrg                set quote "$_G_part" ""
1192b41a30aaSmrg                ;;
1193b41a30aaSmrg              esac
1194b41a30aaSmrg            done
1195b41a30aaSmrg          done
1196b41a30aaSmrg          IFS=$func_quote_portable_old_IFS
1197b41a30aaSmrg          ;;
1198b41a30aaSmrg        *) ;;
1199b41a30aaSmrg      esac
1200b41a30aaSmrg      break
1201b41a30aaSmrg    done
1202b41a30aaSmrg
1203b41a30aaSmrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204b41a30aaSmrg    case $func_quote_portable_result in
1205b41a30aaSmrg      # double-quote args containing shell metacharacters to delay
1206b41a30aaSmrg      # word splitting, command substitution and variable expansion
1207b41a30aaSmrg      # for a subsequent eval.
1208b41a30aaSmrg      # many bourne shells cannot handle close brackets correctly
1209ea133fd7Smrg      # in scan sets, so we specify it separately.
1210ea133fd7Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211b41a30aaSmrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212ea133fd7Smrg        ;;
1213a253d6aeSmrg    esac
1214a253d6aeSmrg}
1215a253d6aeSmrg
1216a253d6aeSmrg
1217b41a30aaSmrg# func_quotefast_eval ARG
1218b41a30aaSmrg# -----------------------
1219b41a30aaSmrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220b41a30aaSmrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221b41a30aaSmrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222b41a30aaSmrg  printf -v _GL_test_printf_tilde %q '~'
1223b41a30aaSmrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224b41a30aaSmrg    func_quotefast_eval ()
1225b41a30aaSmrg    {
1226b41a30aaSmrg      printf -v func_quotefast_eval_result %q "$1"
1227b41a30aaSmrg    }
1228b41a30aaSmrg  else
1229b41a30aaSmrg    # Broken older Bash implementations.  Make those faster too if possible.
1230b41a30aaSmrg    func_quotefast_eval ()
1231b41a30aaSmrg    {
1232b41a30aaSmrg      case $1 in
1233b41a30aaSmrg        '~'*)
1234b41a30aaSmrg          func_quote_portable false "$1"
1235b41a30aaSmrg          func_quotefast_eval_result=$func_quote_portable_result
1236b41a30aaSmrg          ;;
1237b41a30aaSmrg        *)
1238b41a30aaSmrg          printf -v func_quotefast_eval_result %q "$1"
1239b41a30aaSmrg          ;;
1240b41a30aaSmrg      esac
1241b41a30aaSmrg    }
1242b41a30aaSmrg  fi
1243b41a30aaSmrgelse
1244b41a30aaSmrg  func_quotefast_eval ()
1245b41a30aaSmrg  {
1246b41a30aaSmrg    func_quote_portable false "$1"
1247b41a30aaSmrg    func_quotefast_eval_result=$func_quote_portable_result
1248b41a30aaSmrg  }
1249b41a30aaSmrgfi
1250b41a30aaSmrg
1251b41a30aaSmrg
1252b41a30aaSmrg# func_quote_arg MODEs ARG
1253b41a30aaSmrg# ------------------------
1254b41a30aaSmrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255b41a30aaSmrg# specifiers listed below separated by ',' character.  This function returns two
1256b41a30aaSmrg# values:
1257b41a30aaSmrg#   i) func_quote_arg_result
1258b41a30aaSmrg#      double-quoted (when needed), suitable for a subsequent eval
1259b41a30aaSmrg#  ii) func_quote_arg_unquoted_result
1260b41a30aaSmrg#      has all characters that are still active within double
1261b41a30aaSmrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262b41a30aaSmrg#
1263b41a30aaSmrg# Available modes:
1264b41a30aaSmrg# ----------------
1265b41a30aaSmrg# 'eval' (default)
1266b41a30aaSmrg#       - escape shell special characters
1267b41a30aaSmrg# 'expand'
1268b41a30aaSmrg#       - the same as 'eval';  but do not quote variable references
1269b41a30aaSmrg# 'pretty'
1270b41a30aaSmrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271b41a30aaSmrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272b41a30aaSmrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273b41a30aaSmrg# 'unquoted'
1274b41a30aaSmrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275b41a30aaSmrg#         wrapping double-quotes.
1276b41a30aaSmrg#
1277b41a30aaSmrg# Examples for 'func_quote_arg pretty,unquoted string':
1278b41a30aaSmrg#
1279b41a30aaSmrg#   string      | *_result              | *_unquoted_result
1280b41a30aaSmrg#   ------------+-----------------------+-------------------
1281b41a30aaSmrg#   "           | \"                    | \"
1282b41a30aaSmrg#   a b         | "a b"                 | a b
1283b41a30aaSmrg#   "a b"       | "\"a b\""             | \"a b\"
1284b41a30aaSmrg#   *           | "*"                   | *
1285b41a30aaSmrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286b41a30aaSmrg#
1287b41a30aaSmrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288b41a30aaSmrg#
1289b41a30aaSmrg#   string        |   *_result          |  *_unquoted_result
1290b41a30aaSmrg#   --------------+---------------------+--------------------
1291b41a30aaSmrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292b41a30aaSmrgfunc_quote_arg ()
1293a253d6aeSmrg{
1294b41a30aaSmrg    _G_quote_expand=false
1295b41a30aaSmrg    case ,$1, in
1296b41a30aaSmrg      *,expand,*)
1297b41a30aaSmrg        _G_quote_expand=:
1298b41a30aaSmrg        ;;
1299ea133fd7Smrg    esac
1300ea133fd7Smrg
1301b41a30aaSmrg    case ,$1, in
1302b41a30aaSmrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303b41a30aaSmrg        func_quote_portable $_G_quote_expand "$2"
1304b41a30aaSmrg        func_quote_arg_result=$func_quote_portable_result
1305b41a30aaSmrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306b41a30aaSmrg        ;;
1307b41a30aaSmrg      *)
1308b41a30aaSmrg        # Faster quote-for-eval for some shells.
1309b41a30aaSmrg        func_quotefast_eval "$2"
1310b41a30aaSmrg        func_quote_arg_result=$func_quotefast_eval_result
1311ea133fd7Smrg        ;;
1312ea133fd7Smrg    esac
1313b41a30aaSmrg}
1314b41a30aaSmrg
1315ea133fd7Smrg
1316b41a30aaSmrg# func_quote MODEs ARGs...
1317b41a30aaSmrg# ------------------------
1318b41a30aaSmrg# Quote all ARGs to be evaled later and join them into single command.  See
1319b41a30aaSmrg# func_quote_arg's description for more info.
1320b41a30aaSmrgfunc_quote ()
1321b41a30aaSmrg{
1322b41a30aaSmrg    $debug_cmd
1323b41a30aaSmrg    _G_func_quote_mode=$1 ; shift
1324b41a30aaSmrg    func_quote_result=
1325b41a30aaSmrg    while test 0 -lt $#; do
1326b41a30aaSmrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327b41a30aaSmrg      if test -n "$func_quote_result"; then
1328b41a30aaSmrg        func_append func_quote_result " $func_quote_arg_result"
1329b41a30aaSmrg      else
1330b41a30aaSmrg        func_append func_quote_result "$func_quote_arg_result"
1331b41a30aaSmrg      fi
1332b41a30aaSmrg      shift
1333b41a30aaSmrg    done
1334a253d6aeSmrg}
1335a253d6aeSmrg
1336a253d6aeSmrg
1337b41a30aaSmrg# func_stripname PREFIX SUFFIX NAME
1338b41a30aaSmrg# ---------------------------------
1339b41a30aaSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340b41a30aaSmrg# PREFIX and SUFFIX must not contain globbing or regex special
1341b41a30aaSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342b41a30aaSmrg# dot (in which case that matches only a dot).
1343b41a30aaSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344b41a30aaSmrg  eval 'func_stripname ()
1345b41a30aaSmrg  {
1346b41a30aaSmrg    $debug_cmd
1347b41a30aaSmrg
1348b41a30aaSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349b41a30aaSmrg    # positional parameters, so assign one to ordinary variable first.
1350b41a30aaSmrg    func_stripname_result=$3
1351b41a30aaSmrg    func_stripname_result=${func_stripname_result#"$1"}
1352b41a30aaSmrg    func_stripname_result=${func_stripname_result%"$2"}
1353b41a30aaSmrg  }'
1354b41a30aaSmrgelse
1355b41a30aaSmrg  func_stripname ()
1356b41a30aaSmrg  {
1357b41a30aaSmrg    $debug_cmd
1358b41a30aaSmrg
1359b41a30aaSmrg    case $2 in
1360b41a30aaSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361b41a30aaSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362b41a30aaSmrg    esac
1363b41a30aaSmrg  }
1364b41a30aaSmrgfi
1365b41a30aaSmrg
1366b41a30aaSmrg
1367b41a30aaSmrg# func_show_eval CMD [FAIL_EXP]
1368b41a30aaSmrg# -----------------------------
1369b41a30aaSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370ea133fd7Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371ea133fd7Smrg# is given, then evaluate it.
1372ea133fd7Smrgfunc_show_eval ()
1373a253d6aeSmrg{
1374b41a30aaSmrg    $debug_cmd
1375b41a30aaSmrg
1376b41a30aaSmrg    _G_cmd=$1
1377b41a30aaSmrg    _G_fail_exp=${2-':'}
1378b41a30aaSmrg
1379b41a30aaSmrg    func_quote_arg pretty,expand "$_G_cmd"
1380b41a30aaSmrg    eval "func_notquiet $func_quote_arg_result"
1381b41a30aaSmrg
1382b41a30aaSmrg    $opt_dry_run || {
1383b41a30aaSmrg      eval "$_G_cmd"
1384b41a30aaSmrg      _G_status=$?
1385b41a30aaSmrg      if test 0 -ne "$_G_status"; then
1386b41a30aaSmrg	eval "(exit $_G_status); $_G_fail_exp"
1387b41a30aaSmrg      fi
1388b41a30aaSmrg    }
1389b41a30aaSmrg}
1390b41a30aaSmrg
1391b41a30aaSmrg
1392b41a30aaSmrg# func_show_eval_locale CMD [FAIL_EXP]
1393b41a30aaSmrg# ------------------------------------
1394b41a30aaSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395b41a30aaSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396b41a30aaSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397b41a30aaSmrgfunc_show_eval_locale ()
1398b41a30aaSmrg{
1399b41a30aaSmrg    $debug_cmd
1400b41a30aaSmrg
1401b41a30aaSmrg    _G_cmd=$1
1402b41a30aaSmrg    _G_fail_exp=${2-':'}
1403b41a30aaSmrg
1404b41a30aaSmrg    $opt_quiet || {
1405b41a30aaSmrg      func_quote_arg expand,pretty "$_G_cmd"
1406b41a30aaSmrg      eval "func_echo $func_quote_arg_result"
1407b41a30aaSmrg    }
1408b41a30aaSmrg
1409b41a30aaSmrg    $opt_dry_run || {
1410b41a30aaSmrg      eval "$_G_user_locale
1411b41a30aaSmrg	    $_G_cmd"
1412b41a30aaSmrg      _G_status=$?
1413b41a30aaSmrg      eval "$_G_safe_locale"
1414b41a30aaSmrg      if test 0 -ne "$_G_status"; then
1415b41a30aaSmrg	eval "(exit $_G_status); $_G_fail_exp"
1416b41a30aaSmrg      fi
1417b41a30aaSmrg    }
1418b41a30aaSmrg}
1419b41a30aaSmrg
1420b41a30aaSmrg
1421b41a30aaSmrg# func_tr_sh
1422b41a30aaSmrg# ----------
1423b41a30aaSmrg# Turn $1 into a string suitable for a shell variable name.
1424b41a30aaSmrg# Result is stored in $func_tr_sh_result.  All characters
1425b41a30aaSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426b41a30aaSmrg# if $1 begins with a digit, a '_' is prepended as well.
1427b41a30aaSmrgfunc_tr_sh ()
1428b41a30aaSmrg{
1429b41a30aaSmrg    $debug_cmd
1430b41a30aaSmrg
1431b41a30aaSmrg    case $1 in
1432b41a30aaSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433b41a30aaSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434b41a30aaSmrg      ;;
1435b41a30aaSmrg    * )
1436b41a30aaSmrg      func_tr_sh_result=$1
1437b41a30aaSmrg      ;;
1438b41a30aaSmrg    esac
1439b41a30aaSmrg}
1440b41a30aaSmrg
1441b41a30aaSmrg
1442b41a30aaSmrg# func_verbose ARG...
1443b41a30aaSmrg# -------------------
1444b41a30aaSmrg# Echo program name prefixed message in verbose mode only.
1445b41a30aaSmrgfunc_verbose ()
1446b41a30aaSmrg{
1447b41a30aaSmrg    $debug_cmd
1448b41a30aaSmrg
1449b41a30aaSmrg    $opt_verbose && func_echo "$*"
1450b41a30aaSmrg
1451b41a30aaSmrg    :
1452b41a30aaSmrg}
1453b41a30aaSmrg
1454b41a30aaSmrg
1455b41a30aaSmrg# func_warn_and_continue ARG...
1456b41a30aaSmrg# -----------------------------
1457b41a30aaSmrg# Echo program name prefixed warning message to standard error.
1458b41a30aaSmrgfunc_warn_and_continue ()
1459b41a30aaSmrg{
1460b41a30aaSmrg    $debug_cmd
1461b41a30aaSmrg
1462b41a30aaSmrg    $require_term_colors
1463b41a30aaSmrg
1464b41a30aaSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465b41a30aaSmrg}
1466b41a30aaSmrg
1467b41a30aaSmrg
1468b41a30aaSmrg# func_warning CATEGORY ARG...
1469b41a30aaSmrg# ----------------------------
1470b41a30aaSmrg# Echo program name prefixed warning message to standard error. Warning
1471b41a30aaSmrg# messages can be filtered according to CATEGORY, where this function
1472b41a30aaSmrg# elides messages where CATEGORY is not listed in the global variable
1473b41a30aaSmrg# 'opt_warning_types'.
1474b41a30aaSmrgfunc_warning ()
1475b41a30aaSmrg{
1476b41a30aaSmrg    $debug_cmd
1477b41a30aaSmrg
1478b41a30aaSmrg    # CATEGORY must be in the warning_categories list!
1479b41a30aaSmrg    case " $warning_categories " in
1480b41a30aaSmrg      *" $1 "*) ;;
1481b41a30aaSmrg      *) func_internal_error "invalid warning category '$1'" ;;
1482b41a30aaSmrg    esac
1483b41a30aaSmrg
1484b41a30aaSmrg    _G_category=$1
1485b41a30aaSmrg    shift
1486b41a30aaSmrg
1487b41a30aaSmrg    case " $opt_warning_types " in
1488b41a30aaSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489b41a30aaSmrg    esac
1490b41a30aaSmrg}
1491b41a30aaSmrg
1492b41a30aaSmrg
1493b41a30aaSmrg# func_sort_ver VER1 VER2
1494b41a30aaSmrg# -----------------------
1495b41a30aaSmrg# 'sort -V' is not generally available.
1496b41a30aaSmrg# Note this deviates from the version comparison in automake
1497b41a30aaSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498b41a30aaSmrg# but this should suffice as we won't be specifying old
1499b41a30aaSmrg# version formats or redundant trailing .0 in bootstrap.conf.
1500b41a30aaSmrg# If we did want full compatibility then we should probably
1501b41a30aaSmrg# use m4_version_compare from autoconf.
1502b41a30aaSmrgfunc_sort_ver ()
1503b41a30aaSmrg{
1504b41a30aaSmrg    $debug_cmd
1505b41a30aaSmrg
1506b41a30aaSmrg    printf '%s\n%s\n' "$1" "$2" \
1507b41a30aaSmrg      | 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
1508b41a30aaSmrg}
1509b41a30aaSmrg
1510b41a30aaSmrg# func_lt_ver PREV CURR
1511b41a30aaSmrg# ---------------------
1512b41a30aaSmrg# Return true if PREV and CURR are in the correct order according to
1513b41a30aaSmrg# func_sort_ver, otherwise false.  Use it like this:
1514b41a30aaSmrg#
1515b41a30aaSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516b41a30aaSmrgfunc_lt_ver ()
1517b41a30aaSmrg{
1518b41a30aaSmrg    $debug_cmd
1519b41a30aaSmrg
1520b41a30aaSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521b41a30aaSmrg}
1522b41a30aaSmrg
1523b41a30aaSmrg
1524b41a30aaSmrg# Local variables:
1525b41a30aaSmrg# mode: shell-script
1526b41a30aaSmrg# sh-indentation: 2
1527b41a30aaSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528b41a30aaSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529b41a30aaSmrg# time-stamp-time-zone: "UTC"
1530b41a30aaSmrg# End:
1531b41a30aaSmrg#! /bin/sh
1532b41a30aaSmrg
1533b41a30aaSmrg# A portable, pluggable option parser for Bourne shell.
1534b41a30aaSmrg# Written by Gary V. Vaughan, 2010
1535b41a30aaSmrg
1536b41a30aaSmrg# This is free software.  There is NO warranty; not even for
1537b41a30aaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538b41a30aaSmrg#
1539b41a30aaSmrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540b41a30aaSmrg#
1541b41a30aaSmrg# This file is dual licensed under the terms of the MIT license
1542b41a30aaSmrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543b41a30aaSmrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544b41a30aaSmrg# these licenses when using or redistributing this software or any of
1545b41a30aaSmrg# the files within it.  See the URLs above, or the file `LICENSE`
1546b41a30aaSmrg# included in the Bootstrap distribution for the full license texts.
1547b41a30aaSmrg
1548b41a30aaSmrg# Please report bugs or propose patches to:
1549b41a30aaSmrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550b41a30aaSmrg
1551b41a30aaSmrg# Set a version string for this script.
1552b41a30aaSmrgscriptversion=2019-02-19.15; # UTC
1553b41a30aaSmrg
1554b41a30aaSmrg
1555b41a30aaSmrg## ------ ##
1556b41a30aaSmrg## Usage. ##
1557b41a30aaSmrg## ------ ##
1558b41a30aaSmrg
1559b41a30aaSmrg# This file is a library for parsing options in your shell scripts along
1560b41a30aaSmrg# with assorted other useful supporting features that you can make use
1561b41a30aaSmrg# of too.
1562b41a30aaSmrg#
1563b41a30aaSmrg# For the simplest scripts you might need only:
1564b41a30aaSmrg#
1565b41a30aaSmrg#   #!/bin/sh
1566b41a30aaSmrg#   . relative/path/to/funclib.sh
1567b41a30aaSmrg#   . relative/path/to/options-parser
1568b41a30aaSmrg#   scriptversion=1.0
1569b41a30aaSmrg#   func_options ${1+"$@"}
1570b41a30aaSmrg#   eval set dummy "$func_options_result"; shift
1571b41a30aaSmrg#   ...rest of your script...
1572b41a30aaSmrg#
1573b41a30aaSmrg# In order for the '--version' option to work, you will need to have a
1574b41a30aaSmrg# suitably formatted comment like the one at the top of this file
1575b41a30aaSmrg# starting with '# Written by ' and ending with '# Copyright'.
1576b41a30aaSmrg#
1577b41a30aaSmrg# For '-h' and '--help' to work, you will also need a one line
1578b41a30aaSmrg# description of your script's purpose in a comment directly above the
1579b41a30aaSmrg# '# Written by ' line, like the one at the top of this file.
1580b41a30aaSmrg#
1581b41a30aaSmrg# The default options also support '--debug', which will turn on shell
1582b41a30aaSmrg# execution tracing (see the comment above debug_cmd below for another
1583b41a30aaSmrg# use), and '--verbose' and the func_verbose function to allow your script
1584b41a30aaSmrg# to display verbose messages only when your user has specified
1585b41a30aaSmrg# '--verbose'.
1586b41a30aaSmrg#
1587b41a30aaSmrg# After sourcing this file, you can plug in processing for additional
1588b41a30aaSmrg# options by amending the variables from the 'Configuration' section
1589b41a30aaSmrg# below, and following the instructions in the 'Option parsing'
1590b41a30aaSmrg# section further down.
1591b41a30aaSmrg
1592b41a30aaSmrg## -------------- ##
1593b41a30aaSmrg## Configuration. ##
1594b41a30aaSmrg## -------------- ##
1595b41a30aaSmrg
1596b41a30aaSmrg# You should override these variables in your script after sourcing this
1597b41a30aaSmrg# file so that they reflect the customisations you have added to the
1598b41a30aaSmrg# option parser.
1599b41a30aaSmrg
1600b41a30aaSmrg# The usage line for option parsing errors and the start of '-h' and
1601b41a30aaSmrg# '--help' output messages. You can embed shell variables for delayed
1602b41a30aaSmrg# expansion at the time the message is displayed, but you will need to
1603b41a30aaSmrg# quote other shell meta-characters carefully to prevent them being
1604b41a30aaSmrg# expanded when the contents are evaled.
1605b41a30aaSmrgusage='$progpath [OPTION]...'
1606b41a30aaSmrg
1607b41a30aaSmrg# Short help message in response to '-h' and '--help'.  Add to this or
1608b41a30aaSmrg# override it after sourcing this library to reflect the full set of
1609b41a30aaSmrg# options your script accepts.
1610b41a30aaSmrgusage_message="\
1611b41a30aaSmrg       --debug        enable verbose shell tracing
1612b41a30aaSmrg   -W, --warnings=CATEGORY
1613b41a30aaSmrg                      report the warnings falling in CATEGORY [all]
1614b41a30aaSmrg   -v, --verbose      verbosely report processing
1615b41a30aaSmrg       --version      print version information and exit
1616b41a30aaSmrg   -h, --help         print short or long help message and exit
1617b41a30aaSmrg"
1618b41a30aaSmrg
1619b41a30aaSmrg# Additional text appended to 'usage_message' in response to '--help'.
1620b41a30aaSmrglong_help_message="
1621b41a30aaSmrgWarning categories include:
1622b41a30aaSmrg       'all'          show all warnings
1623b41a30aaSmrg       'none'         turn off all the warnings
1624b41a30aaSmrg       'error'        warnings are treated as fatal errors"
1625b41a30aaSmrg
1626b41a30aaSmrg# Help message printed before fatal option parsing errors.
1627b41a30aaSmrgfatal_help="Try '\$progname --help' for more information."
1628b41a30aaSmrg
1629b41a30aaSmrg
1630b41a30aaSmrg
1631b41a30aaSmrg## ------------------------- ##
1632b41a30aaSmrg## Hook function management. ##
1633b41a30aaSmrg## ------------------------- ##
1634b41a30aaSmrg
1635b41a30aaSmrg# This section contains functions for adding, removing, and running hooks
1636b41a30aaSmrg# in the main code.  A hook is just a list of function names that can be
1637b41a30aaSmrg# run in order later on.
1638b41a30aaSmrg
1639b41a30aaSmrg# func_hookable FUNC_NAME
1640b41a30aaSmrg# -----------------------
1641b41a30aaSmrg# Declare that FUNC_NAME will run hooks added with
1642b41a30aaSmrg# 'func_add_hook FUNC_NAME ...'.
1643b41a30aaSmrgfunc_hookable ()
1644b41a30aaSmrg{
1645b41a30aaSmrg    $debug_cmd
1646b41a30aaSmrg
1647b41a30aaSmrg    func_append hookable_fns " $1"
1648b41a30aaSmrg}
1649b41a30aaSmrg
1650b41a30aaSmrg
1651b41a30aaSmrg# func_add_hook FUNC_NAME HOOK_FUNC
1652b41a30aaSmrg# ---------------------------------
1653b41a30aaSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654b41a30aaSmrg# first have been declared "hookable" by a call to 'func_hookable'.
1655b41a30aaSmrgfunc_add_hook ()
1656b41a30aaSmrg{
1657b41a30aaSmrg    $debug_cmd
1658b41a30aaSmrg
1659b41a30aaSmrg    case " $hookable_fns " in
1660b41a30aaSmrg      *" $1 "*) ;;
1661b41a30aaSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662b41a30aaSmrg    esac
1663b41a30aaSmrg
1664b41a30aaSmrg    eval func_append ${1}_hooks '" $2"'
1665b41a30aaSmrg}
1666b41a30aaSmrg
1667b41a30aaSmrg
1668b41a30aaSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669b41a30aaSmrg# ------------------------------------
1670b41a30aaSmrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671b41a30aaSmrg# FUNC_NAME.
1672b41a30aaSmrgfunc_remove_hook ()
1673b41a30aaSmrg{
1674b41a30aaSmrg    $debug_cmd
1675b41a30aaSmrg
1676b41a30aaSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677b41a30aaSmrg}
1678b41a30aaSmrg
1679b41a30aaSmrg
1680b41a30aaSmrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681b41a30aaSmrg# ---------------------------------------------
1682b41a30aaSmrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683b41a30aaSmrg# *_result variable of FUNC_NAME_B.
1684b41a30aaSmrgfunc_propagate_result ()
1685b41a30aaSmrg{
1686b41a30aaSmrg    $debug_cmd
1687b41a30aaSmrg
1688b41a30aaSmrg    func_propagate_result_result=:
1689b41a30aaSmrg    if eval "test \"\${${1}_result+set}\" = set"
1690b41a30aaSmrg    then
1691b41a30aaSmrg      eval "${2}_result=\$${1}_result"
1692b41a30aaSmrg    else
1693b41a30aaSmrg      func_propagate_result_result=false
1694b41a30aaSmrg    fi
1695b41a30aaSmrg}
1696b41a30aaSmrg
1697b41a30aaSmrg
1698b41a30aaSmrg# func_run_hooks FUNC_NAME [ARG]...
1699b41a30aaSmrg# ---------------------------------
1700b41a30aaSmrg# Run all hook functions registered to FUNC_NAME.
1701b41a30aaSmrg# It's assumed that the list of hook functions contains nothing more
1702b41a30aaSmrg# than a whitespace-delimited list of legal shell function names, and
1703b41a30aaSmrg# no effort is wasted trying to catch shell meta-characters or preserve
1704b41a30aaSmrg# whitespace.
1705b41a30aaSmrgfunc_run_hooks ()
1706b41a30aaSmrg{
1707b41a30aaSmrg    $debug_cmd
1708b41a30aaSmrg
1709b41a30aaSmrg    case " $hookable_fns " in
1710b41a30aaSmrg      *" $1 "*) ;;
1711b41a30aaSmrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712b41a30aaSmrg    esac
1713b41a30aaSmrg
1714b41a30aaSmrg    eval _G_hook_fns=\$$1_hooks; shift
1715b41a30aaSmrg
1716b41a30aaSmrg    for _G_hook in $_G_hook_fns; do
1717b41a30aaSmrg      func_unset "${_G_hook}_result"
1718b41a30aaSmrg      eval $_G_hook '${1+"$@"}'
1719b41a30aaSmrg      func_propagate_result $_G_hook func_run_hooks
1720b41a30aaSmrg      if $func_propagate_result_result; then
1721b41a30aaSmrg        eval set dummy "$func_run_hooks_result"; shift
1722b41a30aaSmrg      fi
1723b41a30aaSmrg    done
1724b41a30aaSmrg}
1725b41a30aaSmrg
1726b41a30aaSmrg
1727b41a30aaSmrg
1728b41a30aaSmrg## --------------- ##
1729b41a30aaSmrg## Option parsing. ##
1730b41a30aaSmrg## --------------- ##
1731b41a30aaSmrg
1732b41a30aaSmrg# In order to add your own option parsing hooks, you must accept the
1733b41a30aaSmrg# full positional parameter list from your hook function.  You may remove
1734b41a30aaSmrg# or edit any options that you action, and then pass back the remaining
1735b41a30aaSmrg# unprocessed options in '<hooked_function_name>_result', escaped
1736b41a30aaSmrg# suitably for 'eval'.
1737b41a30aaSmrg#
1738b41a30aaSmrg# The '<hooked_function_name>_result' variable is automatically unset
1739b41a30aaSmrg# before your hook gets called; for best performance, only set the
1740b41a30aaSmrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741b41a30aaSmrg# function unnecessarily because it can be an expensive operation on some
1742b41a30aaSmrg# machines).
1743b41a30aaSmrg#
1744b41a30aaSmrg# Like this:
1745b41a30aaSmrg#
1746b41a30aaSmrg#    my_options_prep ()
1747b41a30aaSmrg#    {
1748b41a30aaSmrg#        $debug_cmd
1749b41a30aaSmrg#
1750b41a30aaSmrg#        # Extend the existing usage message.
1751b41a30aaSmrg#        usage_message=$usage_message'
1752b41a30aaSmrg#      -s, --silent       don'\''t print informational messages
1753b41a30aaSmrg#    '
1754b41a30aaSmrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755b41a30aaSmrg#        # my_options_prep_result variable intact.
1756b41a30aaSmrg#    }
1757b41a30aaSmrg#    func_add_hook func_options_prep my_options_prep
1758b41a30aaSmrg#
1759b41a30aaSmrg#
1760b41a30aaSmrg#    my_silent_option ()
1761b41a30aaSmrg#    {
1762b41a30aaSmrg#        $debug_cmd
1763b41a30aaSmrg#
1764b41a30aaSmrg#        args_changed=false
1765b41a30aaSmrg#
1766b41a30aaSmrg#        # Note that, for efficiency, we parse as many options as we can
1767b41a30aaSmrg#        # recognise in a loop before passing the remainder back to the
1768b41a30aaSmrg#        # caller on the first unrecognised argument we encounter.
1769b41a30aaSmrg#        while test $# -gt 0; do
1770b41a30aaSmrg#          opt=$1; shift
1771b41a30aaSmrg#          case $opt in
1772b41a30aaSmrg#            --silent|-s) opt_silent=:
1773b41a30aaSmrg#                         args_changed=:
1774b41a30aaSmrg#                         ;;
1775b41a30aaSmrg#            # Separate non-argument short options:
1776b41a30aaSmrg#            -s*)         func_split_short_opt "$_G_opt"
1777b41a30aaSmrg#                         set dummy "$func_split_short_opt_name" \
1778b41a30aaSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779b41a30aaSmrg#                         shift
1780b41a30aaSmrg#                         args_changed=:
1781b41a30aaSmrg#                         ;;
1782b41a30aaSmrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783b41a30aaSmrg#                         # is added back to "$@" in case we need it later,
1784b41a30aaSmrg#                         # if $args_changed was set to 'true'.
1785b41a30aaSmrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786b41a30aaSmrg#          esac
1787b41a30aaSmrg#        done
1788b41a30aaSmrg#
1789b41a30aaSmrg#        # Only call 'func_quote' here if we processed at least one argument.
1790b41a30aaSmrg#        if $args_changed; then
1791b41a30aaSmrg#          func_quote eval ${1+"$@"}
1792b41a30aaSmrg#          my_silent_option_result=$func_quote_result
1793b41a30aaSmrg#        fi
1794b41a30aaSmrg#    }
1795b41a30aaSmrg#    func_add_hook func_parse_options my_silent_option
1796b41a30aaSmrg#
1797b41a30aaSmrg#
1798b41a30aaSmrg#    my_option_validation ()
1799b41a30aaSmrg#    {
1800b41a30aaSmrg#        $debug_cmd
1801b41a30aaSmrg#
1802b41a30aaSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803b41a30aaSmrg#    '--silent' and '--verbose' options are mutually exclusive."
1804b41a30aaSmrg#    }
1805b41a30aaSmrg#    func_add_hook func_validate_options my_option_validation
1806b41a30aaSmrg#
1807b41a30aaSmrg# You'll also need to manually amend $usage_message to reflect the extra
1808b41a30aaSmrg# options you parse.  It's preferable to append if you can, so that
1809b41a30aaSmrg# multiple option parsing hooks can be added safely.
1810b41a30aaSmrg
1811b41a30aaSmrg
1812b41a30aaSmrg# func_options_finish [ARG]...
1813b41a30aaSmrg# ----------------------------
1814b41a30aaSmrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815b41a30aaSmrgfunc_options_finish ()
1816b41a30aaSmrg{
1817b41a30aaSmrg    $debug_cmd
1818b41a30aaSmrg
1819b41a30aaSmrg    func_run_hooks func_options ${1+"$@"}
1820b41a30aaSmrg    func_propagate_result func_run_hooks func_options_finish
1821b41a30aaSmrg}
1822b41a30aaSmrg
1823b41a30aaSmrg
1824b41a30aaSmrg# func_options [ARG]...
1825b41a30aaSmrg# ---------------------
1826b41a30aaSmrg# All the functions called inside func_options are hookable. See the
1827b41a30aaSmrg# individual implementations for details.
1828b41a30aaSmrgfunc_hookable func_options
1829b41a30aaSmrgfunc_options ()
1830b41a30aaSmrg{
1831b41a30aaSmrg    $debug_cmd
1832b41a30aaSmrg
1833b41a30aaSmrg    _G_options_quoted=false
1834b41a30aaSmrg
1835b41a30aaSmrg    for my_func in options_prep parse_options validate_options options_finish
1836b41a30aaSmrg    do
1837b41a30aaSmrg      func_unset func_${my_func}_result
1838b41a30aaSmrg      func_unset func_run_hooks_result
1839b41a30aaSmrg      eval func_$my_func '${1+"$@"}'
1840b41a30aaSmrg      func_propagate_result func_$my_func func_options
1841b41a30aaSmrg      if $func_propagate_result_result; then
1842b41a30aaSmrg        eval set dummy "$func_options_result"; shift
1843b41a30aaSmrg        _G_options_quoted=:
1844b41a30aaSmrg      fi
1845b41a30aaSmrg    done
1846b41a30aaSmrg
1847b41a30aaSmrg    $_G_options_quoted || {
1848b41a30aaSmrg      # As we (func_options) are top-level options-parser function and
1849b41a30aaSmrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850b41a30aaSmrg      # caller.
1851b41a30aaSmrg      func_quote eval ${1+"$@"}
1852b41a30aaSmrg      func_options_result=$func_quote_result
1853b41a30aaSmrg    }
1854b41a30aaSmrg}
1855b41a30aaSmrg
1856b41a30aaSmrg
1857b41a30aaSmrg# func_options_prep [ARG]...
1858b41a30aaSmrg# --------------------------
1859b41a30aaSmrg# All initialisations required before starting the option parse loop.
1860b41a30aaSmrg# Note that when calling hook functions, we pass through the list of
1861b41a30aaSmrg# positional parameters.  If a hook function modifies that list, and
1862b41a30aaSmrg# needs to propagate that back to rest of this script, then the complete
1863b41a30aaSmrg# modified list must be put in 'func_run_hooks_result' before returning.
1864b41a30aaSmrgfunc_hookable func_options_prep
1865b41a30aaSmrgfunc_options_prep ()
1866b41a30aaSmrg{
1867b41a30aaSmrg    $debug_cmd
1868b41a30aaSmrg
1869b41a30aaSmrg    # Option defaults:
1870b41a30aaSmrg    opt_verbose=false
1871b41a30aaSmrg    opt_warning_types=
1872b41a30aaSmrg
1873b41a30aaSmrg    func_run_hooks func_options_prep ${1+"$@"}
1874b41a30aaSmrg    func_propagate_result func_run_hooks func_options_prep
1875b41a30aaSmrg}
1876b41a30aaSmrg
1877b41a30aaSmrg
1878b41a30aaSmrg# func_parse_options [ARG]...
1879b41a30aaSmrg# ---------------------------
1880b41a30aaSmrg# The main option parsing loop.
1881b41a30aaSmrgfunc_hookable func_parse_options
1882b41a30aaSmrgfunc_parse_options ()
1883b41a30aaSmrg{
1884b41a30aaSmrg    $debug_cmd
1885b41a30aaSmrg
1886b41a30aaSmrg    _G_parse_options_requote=false
1887b41a30aaSmrg    # this just eases exit handling
1888b41a30aaSmrg    while test $# -gt 0; do
1889b41a30aaSmrg      # Defer to hook functions for initial option parsing, so they
1890b41a30aaSmrg      # get priority in the event of reusing an option name.
1891b41a30aaSmrg      func_run_hooks func_parse_options ${1+"$@"}
1892b41a30aaSmrg      func_propagate_result func_run_hooks func_parse_options
1893b41a30aaSmrg      if $func_propagate_result_result; then
1894b41a30aaSmrg        eval set dummy "$func_parse_options_result"; shift
1895b41a30aaSmrg        # Even though we may have changed "$@", we passed the "$@" array
1896b41a30aaSmrg        # down into the hook and it quoted it for us (because we are in
1897b41a30aaSmrg        # this if-branch).  No need to quote it again.
1898b41a30aaSmrg        _G_parse_options_requote=false
1899b41a30aaSmrg      fi
1900b41a30aaSmrg
1901b41a30aaSmrg      # Break out of the loop if we already parsed every option.
1902b41a30aaSmrg      test $# -gt 0 || break
1903b41a30aaSmrg
1904b41a30aaSmrg      # We expect that one of the options parsed in this function matches
1905b41a30aaSmrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906b41a30aaSmrg      _G_match_parse_options=:
1907b41a30aaSmrg      _G_opt=$1
1908b41a30aaSmrg      shift
1909b41a30aaSmrg      case $_G_opt in
1910b41a30aaSmrg        --debug|-x)   debug_cmd='set -x'
1911b41a30aaSmrg                      func_echo "enabling shell trace mode" >&2
1912b41a30aaSmrg                      $debug_cmd
1913b41a30aaSmrg                      ;;
1914b41a30aaSmrg
1915b41a30aaSmrg        --no-warnings|--no-warning|--no-warn)
1916b41a30aaSmrg                      set dummy --warnings none ${1+"$@"}
1917b41a30aaSmrg                      shift
1918b41a30aaSmrg		      ;;
1919a253d6aeSmrg
1920b41a30aaSmrg        --warnings|--warning|-W)
1921b41a30aaSmrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922b41a30aaSmrg                        _G_parse_options_requote=:
1923b41a30aaSmrg                        break
1924b41a30aaSmrg                      fi
1925b41a30aaSmrg                      case " $warning_categories $1" in
1926b41a30aaSmrg                        *" $1 "*)
1927b41a30aaSmrg                          # trailing space prevents matching last $1 above
1928b41a30aaSmrg                          func_append_uniq opt_warning_types " $1"
1929b41a30aaSmrg                          ;;
1930b41a30aaSmrg                        *all)
1931b41a30aaSmrg                          opt_warning_types=$warning_categories
1932b41a30aaSmrg                          ;;
1933b41a30aaSmrg                        *none)
1934b41a30aaSmrg                          opt_warning_types=none
1935b41a30aaSmrg                          warning_func=:
1936b41a30aaSmrg                          ;;
1937b41a30aaSmrg                        *error)
1938b41a30aaSmrg                          opt_warning_types=$warning_categories
1939b41a30aaSmrg                          warning_func=func_fatal_error
1940b41a30aaSmrg                          ;;
1941b41a30aaSmrg                        *)
1942b41a30aaSmrg                          func_fatal_error \
1943b41a30aaSmrg                             "unsupported warning category: '$1'"
1944b41a30aaSmrg                          ;;
1945b41a30aaSmrg                      esac
1946b41a30aaSmrg                      shift
1947b41a30aaSmrg                      ;;
1948b41a30aaSmrg
1949b41a30aaSmrg        --verbose|-v) opt_verbose=: ;;
1950b41a30aaSmrg        --version)    func_version ;;
1951b41a30aaSmrg        -\?|-h)       func_usage ;;
1952b41a30aaSmrg        --help)       func_help ;;
1953b41a30aaSmrg
1954b41a30aaSmrg	# Separate optargs to long options (plugins may need this):
1955b41a30aaSmrg	--*=*)        func_split_equals "$_G_opt"
1956b41a30aaSmrg	              set dummy "$func_split_equals_lhs" \
1957b41a30aaSmrg                          "$func_split_equals_rhs" ${1+"$@"}
1958b41a30aaSmrg                      shift
1959b41a30aaSmrg                      ;;
1960b41a30aaSmrg
1961b41a30aaSmrg       # Separate optargs to short options:
1962b41a30aaSmrg        -W*)
1963b41a30aaSmrg                      func_split_short_opt "$_G_opt"
1964b41a30aaSmrg                      set dummy "$func_split_short_opt_name" \
1965b41a30aaSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966b41a30aaSmrg                      shift
1967b41a30aaSmrg                      ;;
1968b41a30aaSmrg
1969b41a30aaSmrg        # Separate non-argument short options:
1970b41a30aaSmrg        -\?*|-h*|-v*|-x*)
1971b41a30aaSmrg                      func_split_short_opt "$_G_opt"
1972b41a30aaSmrg                      set dummy "$func_split_short_opt_name" \
1973b41a30aaSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974b41a30aaSmrg                      shift
1975b41a30aaSmrg                      ;;
1976b41a30aaSmrg
1977b41a30aaSmrg        --)           _G_parse_options_requote=: ; break ;;
1978b41a30aaSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979b41a30aaSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980b41a30aaSmrg                      _G_match_parse_options=false
1981b41a30aaSmrg                      break
1982b41a30aaSmrg                      ;;
1983b41a30aaSmrg      esac
1984ea133fd7Smrg
1985b41a30aaSmrg      if $_G_match_parse_options; then
1986b41a30aaSmrg        _G_parse_options_requote=:
1987ea133fd7Smrg      fi
1988b41a30aaSmrg    done
1989b41a30aaSmrg
1990b41a30aaSmrg    if $_G_parse_options_requote; then
1991b41a30aaSmrg      # save modified positional parameters for caller
1992b41a30aaSmrg      func_quote eval ${1+"$@"}
1993b41a30aaSmrg      func_parse_options_result=$func_quote_result
1994a253d6aeSmrg    fi
1995a253d6aeSmrg}
1996a253d6aeSmrg
1997ea133fd7Smrg
1998b41a30aaSmrg# func_validate_options [ARG]...
1999b41a30aaSmrg# ------------------------------
2000b41a30aaSmrg# Perform any sanity checks on option settings and/or unconsumed
2001b41a30aaSmrg# arguments.
2002b41a30aaSmrgfunc_hookable func_validate_options
2003b41a30aaSmrgfunc_validate_options ()
2004a253d6aeSmrg{
2005b41a30aaSmrg    $debug_cmd
2006a253d6aeSmrg
2007b41a30aaSmrg    # Display all warnings if -W was not given.
2008b41a30aaSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009ea133fd7Smrg
2010b41a30aaSmrg    func_run_hooks func_validate_options ${1+"$@"}
2011b41a30aaSmrg    func_propagate_result func_run_hooks func_validate_options
2012a253d6aeSmrg
2013b41a30aaSmrg    # Bail if the options were screwed!
2014b41a30aaSmrg    $exit_cmd $EXIT_FAILURE
201506f32fbeSmrg}
201606f32fbeSmrg
2017a253d6aeSmrg
201806f32fbeSmrg
2019b41a30aaSmrg## ----------------- ##
2020b41a30aaSmrg## Helper functions. ##
2021b41a30aaSmrg## ----------------- ##
2022ea133fd7Smrg
2023b41a30aaSmrg# This section contains the helper functions used by the rest of the
2024b41a30aaSmrg# hookable option parser framework in ascii-betical order.
2025b41a30aaSmrg
2026b41a30aaSmrg
2027b41a30aaSmrg# func_fatal_help ARG...
2028b41a30aaSmrg# ----------------------
2029b41a30aaSmrg# Echo program name prefixed message to standard error, followed by
2030b41a30aaSmrg# a help hint, and exit.
2031b41a30aaSmrgfunc_fatal_help ()
2032ea133fd7Smrg{
2033b41a30aaSmrg    $debug_cmd
203406f32fbeSmrg
2035b41a30aaSmrg    eval \$ECHO \""Usage: $usage"\"
2036b41a30aaSmrg    eval \$ECHO \""$fatal_help"\"
2037b41a30aaSmrg    func_error ${1+"$@"}
2038b41a30aaSmrg    exit $EXIT_FAILURE
2039ea133fd7Smrg}
2040ea133fd7Smrg
2041b41a30aaSmrg
2042b41a30aaSmrg# func_help
2043b41a30aaSmrg# ---------
2044b41a30aaSmrg# Echo long help message to standard output and exit.
2045ea133fd7Smrgfunc_help ()
2046ea133fd7Smrg{
2047b41a30aaSmrg    $debug_cmd
2048b41a30aaSmrg
2049b41a30aaSmrg    func_usage_message
2050b41a30aaSmrg    $ECHO "$long_help_message"
2051b41a30aaSmrg    exit 0
2052ea133fd7Smrg}
2053ea133fd7Smrg
2054b41a30aaSmrg
2055b41a30aaSmrg# func_missing_arg ARGNAME
2056b41a30aaSmrg# ------------------------
2057ea133fd7Smrg# Echo program name prefixed message to standard error and set global
2058ea133fd7Smrg# exit_cmd.
2059ea133fd7Smrgfunc_missing_arg ()
2060ea133fd7Smrg{
2061b41a30aaSmrg    $debug_cmd
206206f32fbeSmrg
2063b41a30aaSmrg    func_error "Missing argument for '$1'."
2064ea133fd7Smrg    exit_cmd=exit
2065ea133fd7Smrg}
2066ea133fd7Smrg
2067ea133fd7Smrg
2068b41a30aaSmrg# func_split_equals STRING
2069b41a30aaSmrg# ------------------------
2070b41a30aaSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071b41a30aaSmrg# after splitting STRING at the '=' sign.
2072b41a30aaSmrgtest -z "$_G_HAVE_XSI_OPS" \
2073b41a30aaSmrg    && (eval 'x=a/b/c;
2074b41a30aaSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075b41a30aaSmrg    && _G_HAVE_XSI_OPS=yes
2076b41a30aaSmrg
2077b41a30aaSmrgif test yes = "$_G_HAVE_XSI_OPS"
2078b41a30aaSmrgthen
2079b41a30aaSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2080b41a30aaSmrg  eval 'func_split_equals ()
2081b41a30aaSmrg  {
2082b41a30aaSmrg      $debug_cmd
2083b41a30aaSmrg
2084b41a30aaSmrg      func_split_equals_lhs=${1%%=*}
2085b41a30aaSmrg      func_split_equals_rhs=${1#*=}
2086b41a30aaSmrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087b41a30aaSmrg        func_split_equals_rhs=
2088b41a30aaSmrg      fi
2089b41a30aaSmrg  }'
2090b41a30aaSmrgelse
2091b41a30aaSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092b41a30aaSmrg  func_split_equals ()
2093b41a30aaSmrg  {
2094b41a30aaSmrg      $debug_cmd
2095b41a30aaSmrg
2096b41a30aaSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097b41a30aaSmrg      func_split_equals_rhs=
2098b41a30aaSmrg      test "x$func_split_equals_lhs=" = "x$1" \
2099b41a30aaSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100b41a30aaSmrg  }
2101b41a30aaSmrgfi #func_split_equals
2102b41a30aaSmrg
2103b41a30aaSmrg
2104b41a30aaSmrg# func_split_short_opt SHORTOPT
2105b41a30aaSmrg# -----------------------------
210606f32fbeSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
210706f32fbeSmrg# variables after splitting SHORTOPT after the 2nd character.
2108b41a30aaSmrgif test yes = "$_G_HAVE_XSI_OPS"
2109b41a30aaSmrgthen
2110b41a30aaSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2111b41a30aaSmrg  eval 'func_split_short_opt ()
2112b41a30aaSmrg  {
2113b41a30aaSmrg      $debug_cmd
2114b41a30aaSmrg
2115b41a30aaSmrg      func_split_short_opt_arg=${1#??}
2116b41a30aaSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117b41a30aaSmrg  }'
2118b41a30aaSmrgelse
2119b41a30aaSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120b41a30aaSmrg  func_split_short_opt ()
2121b41a30aaSmrg  {
2122b41a30aaSmrg      $debug_cmd
2123b41a30aaSmrg
2124b41a30aaSmrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125b41a30aaSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126b41a30aaSmrg  }
2127b41a30aaSmrgfi #func_split_short_opt
2128b41a30aaSmrg
2129b41a30aaSmrg
2130b41a30aaSmrg# func_usage
2131b41a30aaSmrg# ----------
2132b41a30aaSmrg# Echo short help message to standard output and exit.
2133b41a30aaSmrgfunc_usage ()
213406f32fbeSmrg{
2135b41a30aaSmrg    $debug_cmd
213606f32fbeSmrg
2137b41a30aaSmrg    func_usage_message
2138b41a30aaSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139b41a30aaSmrg    exit 0
2140b41a30aaSmrg}
214106f32fbeSmrg
214206f32fbeSmrg
2143b41a30aaSmrg# func_usage_message
2144b41a30aaSmrg# ------------------
2145b41a30aaSmrg# Echo short help message to standard output.
2146b41a30aaSmrgfunc_usage_message ()
214706f32fbeSmrg{
2148b41a30aaSmrg    $debug_cmd
2149b41a30aaSmrg
2150b41a30aaSmrg    eval \$ECHO \""Usage: $usage"\"
2151b41a30aaSmrg    echo
2152b41a30aaSmrg    $SED -n 's|^# ||
2153b41a30aaSmrg        /^Written by/{
2154b41a30aaSmrg          x;p;x
2155b41a30aaSmrg        }
2156b41a30aaSmrg	h
2157b41a30aaSmrg	/^Written by/q' < "$progpath"
2158b41a30aaSmrg    echo
2159b41a30aaSmrg    eval \$ECHO \""$usage_message"\"
2160b41a30aaSmrg}
216106f32fbeSmrg
216206f32fbeSmrg
2163b41a30aaSmrg# func_version
2164b41a30aaSmrg# ------------
2165b41a30aaSmrg# Echo version message to standard output and exit.
2166b41a30aaSmrg# The version message is extracted from the calling file's header
2167b41a30aaSmrg# comments, with leading '# ' stripped:
2168b41a30aaSmrg#   1. First display the progname and version
2169b41a30aaSmrg#   2. Followed by the header comment line matching  /^# Written by /
2170b41a30aaSmrg#   3. Then a blank line followed by the first following line matching
2171b41a30aaSmrg#      /^# Copyright /
2172b41a30aaSmrg#   4. Immediately followed by any lines between the previous matches,
2173b41a30aaSmrg#      except lines preceding the intervening completely blank line.
2174b41a30aaSmrg# For example, see the header comments of this file.
2175b41a30aaSmrgfunc_version ()
2176b41a30aaSmrg{
2177b41a30aaSmrg    $debug_cmd
2178ea133fd7Smrg
2179b41a30aaSmrg    printf '%s\n' "$progname $scriptversion"
2180b41a30aaSmrg    $SED -n '
2181b41a30aaSmrg        /^# Written by /!b
2182b41a30aaSmrg        s|^# ||; p; n
2183ea133fd7Smrg
2184b41a30aaSmrg        :fwd2blnk
2185b41a30aaSmrg        /./ {
2186b41a30aaSmrg          n
2187b41a30aaSmrg          b fwd2blnk
2188b41a30aaSmrg        }
2189b41a30aaSmrg        p; n
2190b41a30aaSmrg
2191b41a30aaSmrg        :holdwrnt
2192b41a30aaSmrg        s|^# ||
2193b41a30aaSmrg        s|^# *$||
2194b41a30aaSmrg        /^Copyright /!{
2195b41a30aaSmrg          /./H
2196b41a30aaSmrg          n
2197b41a30aaSmrg          b holdwrnt
2198b41a30aaSmrg        }
2199ea133fd7Smrg
2200b41a30aaSmrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201b41a30aaSmrg        G
2202b41a30aaSmrg        s|\(\n\)\n*|\1|g
2203b41a30aaSmrg        p; q' < "$progpath"
2204ea133fd7Smrg
2205b41a30aaSmrg    exit $?
2206b41a30aaSmrg}
2207a253d6aeSmrg
2208a253d6aeSmrg
2209b41a30aaSmrg# Local variables:
2210b41a30aaSmrg# mode: shell-script
2211b41a30aaSmrg# sh-indentation: 2
2212b41a30aaSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213b41a30aaSmrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214b41a30aaSmrg# time-stamp-time-zone: "UTC"
2215b41a30aaSmrg# End:
2216a253d6aeSmrg
2217b41a30aaSmrg# Set a version string.
2218b41a30aaSmrgscriptversion='(GNU libtool) 2.4.7'
2219a253d6aeSmrg
222006f32fbeSmrg
2221b41a30aaSmrg# func_echo ARG...
2222b41a30aaSmrg# ----------------
2223b41a30aaSmrg# Libtool also displays the current mode in messages, so override
2224b41a30aaSmrg# funclib.sh func_echo with this custom definition.
2225b41a30aaSmrgfunc_echo ()
222606f32fbeSmrg{
2227b41a30aaSmrg    $debug_cmd
222806f32fbeSmrg
2229b41a30aaSmrg    _G_message=$*
223006f32fbeSmrg
2231b41a30aaSmrg    func_echo_IFS=$IFS
2232b41a30aaSmrg    IFS=$nl
2233b41a30aaSmrg    for _G_line in $_G_message; do
2234b41a30aaSmrg      IFS=$func_echo_IFS
2235b41a30aaSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236b41a30aaSmrg    done
2237b41a30aaSmrg    IFS=$func_echo_IFS
2238b41a30aaSmrg}
223906f32fbeSmrg
224006f32fbeSmrg
2241b41a30aaSmrg# func_warning ARG...
2242b41a30aaSmrg# -------------------
2243b41a30aaSmrg# Libtool warnings are not categorized, so override funclib.sh
2244b41a30aaSmrg# func_warning with this simpler definition.
2245b41a30aaSmrgfunc_warning ()
224606f32fbeSmrg{
2247b41a30aaSmrg    $debug_cmd
224806f32fbeSmrg
2249b41a30aaSmrg    $warning_func ${1+"$@"}
2250b41a30aaSmrg}
225106f32fbeSmrg
225206f32fbeSmrg
2253b41a30aaSmrg## ---------------- ##
2254b41a30aaSmrg## Options parsing. ##
2255b41a30aaSmrg## ---------------- ##
2256b41a30aaSmrg
2257b41a30aaSmrg# Hook in the functions to make sure our own options are parsed during
2258b41a30aaSmrg# the option parsing loop.
2259b41a30aaSmrg
2260b41a30aaSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261b41a30aaSmrg
2262b41a30aaSmrg# Short help message in response to '-h'.
2263b41a30aaSmrgusage_message="Options:
2264b41a30aaSmrg       --config             show all configuration variables
2265b41a30aaSmrg       --debug              enable verbose shell tracing
2266b41a30aaSmrg   -n, --dry-run            display commands without modifying any files
2267b41a30aaSmrg       --features           display basic configuration information and exit
2268b41a30aaSmrg       --mode=MODE          use operation mode MODE
2269b41a30aaSmrg       --no-warnings        equivalent to '-Wnone'
2270b41a30aaSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271b41a30aaSmrg       --quiet, --silent    don't print informational messages
2272b41a30aaSmrg       --tag=TAG            use configuration variables from tag TAG
2273b41a30aaSmrg   -v, --verbose            print more informational messages than default
2274b41a30aaSmrg       --version            print version information
2275b41a30aaSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276b41a30aaSmrg   -h, --help, --help-all   print short, long, or detailed help message
2277b41a30aaSmrg"
227806f32fbeSmrg
2279b41a30aaSmrg# Additional text appended to 'usage_message' in response to '--help'.
2280b41a30aaSmrgfunc_help ()
228106f32fbeSmrg{
2282b41a30aaSmrg    $debug_cmd
2283b41a30aaSmrg
2284b41a30aaSmrg    func_usage_message
2285b41a30aaSmrg    $ECHO "$long_help_message
2286b41a30aaSmrg
2287b41a30aaSmrgMODE must be one of the following:
2288b41a30aaSmrg
2289b41a30aaSmrg       clean           remove files from the build directory
2290b41a30aaSmrg       compile         compile a source file into a libtool object
2291b41a30aaSmrg       execute         automatically set library path, then run a program
2292b41a30aaSmrg       finish          complete the installation of libtool libraries
2293b41a30aaSmrg       install         install libraries or executables
2294b41a30aaSmrg       link            create a library or an executable
2295b41a30aaSmrg       uninstall       remove libraries from an installed directory
2296b41a30aaSmrg
2297b41a30aaSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298b41a30aaSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299b41a30aaSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300b41a30aaSmrg
2301b41a30aaSmrgWhen reporting a bug, please describe a test case to reproduce it and
2302b41a30aaSmrginclude the following information:
2303b41a30aaSmrg
2304b41a30aaSmrg       host-triplet:   $host
2305b41a30aaSmrg       shell:          $SHELL
2306b41a30aaSmrg       compiler:       $LTCC
2307b41a30aaSmrg       compiler flags: $LTCFLAGS
2308b41a30aaSmrg       linker:         $LD (gnu? $with_gnu_ld)
2309b41a30aaSmrg       version:        $progname (GNU libtool) 2.4.7
2310b41a30aaSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311b41a30aaSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312b41a30aaSmrg
2313b41a30aaSmrgReport bugs to <bug-libtool@gnu.org>.
2314b41a30aaSmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315b41a30aaSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316b41a30aaSmrg    exit 0
2317b41a30aaSmrg}
2318b41a30aaSmrg
2319b41a30aaSmrg
2320b41a30aaSmrg# func_lo2o OBJECT-NAME
2321b41a30aaSmrg# ---------------------
2322b41a30aaSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323b41a30aaSmrg# object suffix.
2324b41a30aaSmrg
2325b41a30aaSmrglo2o=s/\\.lo\$/.$objext/
2326b41a30aaSmrgo2lo=s/\\.$objext\$/.lo/
2327b41a30aaSmrg
2328b41a30aaSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329b41a30aaSmrg  eval 'func_lo2o ()
2330b41a30aaSmrg  {
2331b41a30aaSmrg    case $1 in
2332b41a30aaSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333b41a30aaSmrg      *   ) func_lo2o_result=$1               ;;
2334b41a30aaSmrg    esac
2335b41a30aaSmrg  }'
2336b41a30aaSmrg
2337b41a30aaSmrg  # func_xform LIBOBJ-OR-SOURCE
2338b41a30aaSmrg  # ---------------------------
2339b41a30aaSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340b41a30aaSmrg  # suffix to a '.lo' libtool-object suffix.
2341b41a30aaSmrg  eval 'func_xform ()
2342b41a30aaSmrg  {
2343b41a30aaSmrg    func_xform_result=${1%.*}.lo
2344b41a30aaSmrg  }'
2345b41a30aaSmrgelse
2346b41a30aaSmrg  # ...otherwise fall back to using sed.
2347b41a30aaSmrg  func_lo2o ()
2348b41a30aaSmrg  {
2349b41a30aaSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350b41a30aaSmrg  }
2351b41a30aaSmrg
2352b41a30aaSmrg  func_xform ()
2353b41a30aaSmrg  {
2354b41a30aaSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355b41a30aaSmrg  }
2356b41a30aaSmrgfi
235706f32fbeSmrg
235806f32fbeSmrg
2359b41a30aaSmrg# func_fatal_configuration ARG...
2360b41a30aaSmrg# -------------------------------
2361ea133fd7Smrg# Echo program name prefixed message to standard error, followed by
2362ea133fd7Smrg# a configuration failure hint, and exit.
2363ea133fd7Smrgfunc_fatal_configuration ()
2364ea133fd7Smrg{
2365b41a30aaSmrg    func_fatal_error ${1+"$@"} \
2366b41a30aaSmrg      "See the $PACKAGE documentation for more information." \
2367b41a30aaSmrg      "Fatal configuration error."
2368ea133fd7Smrg}
2369ea133fd7Smrg
2370ea133fd7Smrg
2371ea133fd7Smrg# func_config
2372b41a30aaSmrg# -----------
2373ea133fd7Smrg# Display the configuration for all the tags in this script.
2374ea133fd7Smrgfunc_config ()
2375ea133fd7Smrg{
2376ea133fd7Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2377ea133fd7Smrg    re_endcf='^# ### END LIBTOOL'
2378ea133fd7Smrg
2379ea133fd7Smrg    # Default configuration.
2380ea133fd7Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2381a253d6aeSmrg
2382a253d6aeSmrg    # Now print the configurations for the tags.
2383a253d6aeSmrg    for tagname in $taglist; do
2384ea133fd7Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385a253d6aeSmrg    done
2386a253d6aeSmrg
2387ea133fd7Smrg    exit $?
2388ea133fd7Smrg}
2389a253d6aeSmrg
2390b41a30aaSmrg
2391ea133fd7Smrg# func_features
2392b41a30aaSmrg# -------------
2393ea133fd7Smrg# Display the features supported by this script.
2394ea133fd7Smrgfunc_features ()
2395ea133fd7Smrg{
239625b89263Smrg    echo "host: $host"
2397b41a30aaSmrg    if test yes = "$build_libtool_libs"; then
239825b89263Smrg      echo "enable shared libraries"
2399a253d6aeSmrg    else
240025b89263Smrg      echo "disable shared libraries"
2401a253d6aeSmrg    fi
2402b41a30aaSmrg    if test yes = "$build_old_libs"; then
240325b89263Smrg      echo "enable static libraries"
2404a253d6aeSmrg    else
240525b89263Smrg      echo "disable static libraries"
2406a253d6aeSmrg    fi
2407ea133fd7Smrg
2408a253d6aeSmrg    exit $?
2409ea133fd7Smrg}
2410ea133fd7Smrg
2411b41a30aaSmrg
2412b41a30aaSmrg# func_enable_tag TAGNAME
2413b41a30aaSmrg# -----------------------
2414ea133fd7Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2415ea133fd7Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2416ea133fd7Smrg# variable here.
2417ea133fd7Smrgfunc_enable_tag ()
2418ea133fd7Smrg{
2419b41a30aaSmrg    # Global variable:
2420b41a30aaSmrg    tagname=$1
2421a253d6aeSmrg
2422b41a30aaSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423b41a30aaSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424b41a30aaSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425a253d6aeSmrg
2426b41a30aaSmrg    # Validate tagname.
2427b41a30aaSmrg    case $tagname in
2428b41a30aaSmrg      *[!-_A-Za-z0-9,/]*)
2429b41a30aaSmrg        func_fatal_error "invalid tag name: $tagname"
2430b41a30aaSmrg        ;;
2431b41a30aaSmrg    esac
2432a253d6aeSmrg
2433b41a30aaSmrg    # Don't test for the "default" C tag, as we know it's
2434b41a30aaSmrg    # there but not specially marked.
2435b41a30aaSmrg    case $tagname in
2436b41a30aaSmrg        CC) ;;
2437ea133fd7Smrg    *)
2438b41a30aaSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439b41a30aaSmrg	  taglist="$taglist $tagname"
2440b41a30aaSmrg
2441b41a30aaSmrg	  # Evaluate the configuration.  Be careful to quote the path
2442b41a30aaSmrg	  # and the sed script, to avoid splitting on whitespace, but
2443b41a30aaSmrg	  # also don't use non-portable quotes within backquotes within
2444b41a30aaSmrg	  # quotes we have to do it in 2 steps:
2445b41a30aaSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446b41a30aaSmrg	  eval "$extractedcf"
2447b41a30aaSmrg        else
2448b41a30aaSmrg	  func_error "ignoring unknown tag $tagname"
2449b41a30aaSmrg        fi
2450b41a30aaSmrg        ;;
2451b41a30aaSmrg    esac
2452ea133fd7Smrg}
2453a253d6aeSmrg
2454b41a30aaSmrg
245506f32fbeSmrg# func_check_version_match
2456b41a30aaSmrg# ------------------------
245706f32fbeSmrg# Ensure that we are using m4 macros, and libtool script from the same
245806f32fbeSmrg# release of libtool.
245906f32fbeSmrgfunc_check_version_match ()
2460ea133fd7Smrg{
2461b41a30aaSmrg    if test "$package_revision" != "$macro_revision"; then
2462b41a30aaSmrg      if test "$VERSION" != "$macro_version"; then
2463b41a30aaSmrg        if test -z "$macro_version"; then
2464b41a30aaSmrg          cat >&2 <<_LT_EOF
246506f32fbeSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
246606f32fbeSmrg$progname: definition of this LT_INIT comes from an older release.
246706f32fbeSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
246806f32fbeSmrg$progname: and run autoconf again.
246906f32fbeSmrg_LT_EOF
2470b41a30aaSmrg        else
2471b41a30aaSmrg          cat >&2 <<_LT_EOF
247206f32fbeSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
247306f32fbeSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
247406f32fbeSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
247506f32fbeSmrg$progname: and run autoconf again.
247606f32fbeSmrg_LT_EOF
2477b41a30aaSmrg        fi
2478b41a30aaSmrg      else
2479b41a30aaSmrg        cat >&2 <<_LT_EOF
248006f32fbeSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
248106f32fbeSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
248206f32fbeSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
248306f32fbeSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
248406f32fbeSmrg_LT_EOF
2485b41a30aaSmrg      fi
2486a253d6aeSmrg
2487b41a30aaSmrg      exit $EXIT_MISMATCH
2488b41a30aaSmrg    fi
248906f32fbeSmrg}
249006f32fbeSmrg
249106f32fbeSmrg
2492b41a30aaSmrg# libtool_options_prep [ARG]...
2493b41a30aaSmrg# -----------------------------
2494b41a30aaSmrg# Preparation for options parsed by libtool.
2495b41a30aaSmrglibtool_options_prep ()
2496b41a30aaSmrg{
2497b41a30aaSmrg    $debug_mode
249806f32fbeSmrg
2499b41a30aaSmrg    # Option defaults:
2500b41a30aaSmrg    opt_config=false
2501b41a30aaSmrg    opt_dlopen=
2502b41a30aaSmrg    opt_dry_run=false
2503b41a30aaSmrg    opt_help=false
2504b41a30aaSmrg    opt_mode=
2505b41a30aaSmrg    opt_preserve_dup_deps=false
2506b41a30aaSmrg    opt_quiet=false
250706f32fbeSmrg
2508b41a30aaSmrg    nonopt=
2509b41a30aaSmrg    preserve_args=
251006f32fbeSmrg
2511b41a30aaSmrg    _G_rc_lt_options_prep=:
251206f32fbeSmrg
2513b41a30aaSmrg    # Shorthand for --mode=foo, only valid as the first argument
2514b41a30aaSmrg    case $1 in
2515b41a30aaSmrg    clean|clea|cle|cl)
2516b41a30aaSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517b41a30aaSmrg      ;;
2518b41a30aaSmrg    compile|compil|compi|comp|com|co|c)
2519b41a30aaSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520b41a30aaSmrg      ;;
2521b41a30aaSmrg    execute|execut|execu|exec|exe|ex|e)
2522b41a30aaSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523b41a30aaSmrg      ;;
2524b41a30aaSmrg    finish|finis|fini|fin|fi|f)
2525b41a30aaSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526b41a30aaSmrg      ;;
2527b41a30aaSmrg    install|instal|insta|inst|ins|in|i)
2528b41a30aaSmrg      shift; set dummy --mode install ${1+"$@"}; shift
2529b41a30aaSmrg      ;;
2530b41a30aaSmrg    link|lin|li|l)
2531b41a30aaSmrg      shift; set dummy --mode link ${1+"$@"}; shift
2532b41a30aaSmrg      ;;
2533b41a30aaSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534b41a30aaSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535b41a30aaSmrg      ;;
2536b41a30aaSmrg    *)
2537b41a30aaSmrg      _G_rc_lt_options_prep=false
2538b41a30aaSmrg      ;;
2539ea133fd7Smrg    esac
2540ea133fd7Smrg
2541b41a30aaSmrg    if $_G_rc_lt_options_prep; then
2542b41a30aaSmrg      # Pass back the list of options.
2543b41a30aaSmrg      func_quote eval ${1+"$@"}
2544b41a30aaSmrg      libtool_options_prep_result=$func_quote_result
2545b41a30aaSmrg    fi
2546b41a30aaSmrg}
2547b41a30aaSmrgfunc_add_hook func_options_prep libtool_options_prep
254806f32fbeSmrg
254906f32fbeSmrg
2550b41a30aaSmrg# libtool_parse_options [ARG]...
2551b41a30aaSmrg# ---------------------------------
2552b41a30aaSmrg# Provide handling for libtool specific options.
2553b41a30aaSmrglibtool_parse_options ()
2554b41a30aaSmrg{
2555b41a30aaSmrg    $debug_cmd
2556ea133fd7Smrg
2557b41a30aaSmrg    _G_rc_lt_parse_options=false
2558a253d6aeSmrg
2559b41a30aaSmrg    # Perform our own loop to consume as many options as possible in
2560b41a30aaSmrg    # each iteration.
2561b41a30aaSmrg    while test $# -gt 0; do
2562b41a30aaSmrg      _G_match_lt_parse_options=:
2563b41a30aaSmrg      _G_opt=$1
2564b41a30aaSmrg      shift
2565b41a30aaSmrg      case $_G_opt in
2566b41a30aaSmrg        --dry-run|--dryrun|-n)
2567b41a30aaSmrg                        opt_dry_run=:
2568b41a30aaSmrg                        ;;
2569b41a30aaSmrg
2570b41a30aaSmrg        --config)       func_config ;;
2571b41a30aaSmrg
2572b41a30aaSmrg        --dlopen|-dlopen)
2573b41a30aaSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574b41a30aaSmrg}$1"
2575b41a30aaSmrg                        shift
2576b41a30aaSmrg                        ;;
2577b41a30aaSmrg
2578b41a30aaSmrg        --preserve-dup-deps)
2579b41a30aaSmrg                        opt_preserve_dup_deps=: ;;
2580b41a30aaSmrg
2581b41a30aaSmrg        --features)     func_features ;;
2582b41a30aaSmrg
2583b41a30aaSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584b41a30aaSmrg
2585b41a30aaSmrg        --help)         opt_help=: ;;
2586b41a30aaSmrg
2587b41a30aaSmrg        --help-all)     opt_help=': help-all' ;;
2588b41a30aaSmrg
2589b41a30aaSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590b41a30aaSmrg                        opt_mode=$1
2591b41a30aaSmrg                        case $1 in
2592b41a30aaSmrg                          # Valid mode arguments:
2593b41a30aaSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594b41a30aaSmrg
2595b41a30aaSmrg                          # Catch anything else as an error
2596b41a30aaSmrg                          *) func_error "invalid argument for $_G_opt"
2597b41a30aaSmrg                             exit_cmd=exit
2598b41a30aaSmrg                             break
2599b41a30aaSmrg                             ;;
2600b41a30aaSmrg                        esac
2601b41a30aaSmrg                        shift
2602b41a30aaSmrg                        ;;
2603b41a30aaSmrg
2604b41a30aaSmrg        --no-silent|--no-quiet)
2605b41a30aaSmrg                        opt_quiet=false
2606b41a30aaSmrg                        func_append preserve_args " $_G_opt"
2607b41a30aaSmrg                        ;;
2608b41a30aaSmrg
2609b41a30aaSmrg        --no-warnings|--no-warning|--no-warn)
2610b41a30aaSmrg                        opt_warning=false
2611b41a30aaSmrg                        func_append preserve_args " $_G_opt"
2612b41a30aaSmrg                        ;;
2613b41a30aaSmrg
2614b41a30aaSmrg        --no-verbose)
2615b41a30aaSmrg                        opt_verbose=false
2616b41a30aaSmrg                        func_append preserve_args " $_G_opt"
2617b41a30aaSmrg                        ;;
2618b41a30aaSmrg
2619b41a30aaSmrg        --silent|--quiet)
2620b41a30aaSmrg                        opt_quiet=:
2621b41a30aaSmrg                        opt_verbose=false
2622b41a30aaSmrg                        func_append preserve_args " $_G_opt"
2623b41a30aaSmrg                        ;;
2624b41a30aaSmrg
2625b41a30aaSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626b41a30aaSmrg                        opt_tag=$1
2627b41a30aaSmrg                        func_append preserve_args " $_G_opt $1"
2628b41a30aaSmrg                        func_enable_tag "$1"
2629b41a30aaSmrg                        shift
2630b41a30aaSmrg                        ;;
2631b41a30aaSmrg
2632b41a30aaSmrg        --verbose|-v)   opt_quiet=false
2633b41a30aaSmrg                        opt_verbose=:
2634b41a30aaSmrg                        func_append preserve_args " $_G_opt"
2635b41a30aaSmrg                        ;;
2636b41a30aaSmrg
2637b41a30aaSmrg        # An option not handled by this hook function:
2638b41a30aaSmrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2639b41a30aaSmrg                        _G_match_lt_parse_options=false
2640b41a30aaSmrg                        break
2641b41a30aaSmrg                        ;;
2642b41a30aaSmrg      esac
2643b41a30aaSmrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644b41a30aaSmrg    done
2645ea133fd7Smrg
2646b41a30aaSmrg    if $_G_rc_lt_parse_options; then
2647b41a30aaSmrg      # save modified positional parameters for caller
2648b41a30aaSmrg      func_quote eval ${1+"$@"}
2649b41a30aaSmrg      libtool_parse_options_result=$func_quote_result
2650ea133fd7Smrg    fi
2651b41a30aaSmrg}
2652b41a30aaSmrgfunc_add_hook func_parse_options libtool_parse_options
2653b41a30aaSmrg
2654ea133fd7Smrg
2655ea133fd7Smrg
2656b41a30aaSmrg# libtool_validate_options [ARG]...
2657b41a30aaSmrg# ---------------------------------
2658b41a30aaSmrg# Perform any sanity checks on option settings and/or unconsumed
2659b41a30aaSmrg# arguments.
2660b41a30aaSmrglibtool_validate_options ()
2661b41a30aaSmrg{
2662b41a30aaSmrg    # save first non-option argument
2663b41a30aaSmrg    if test 0 -lt $#; then
2664b41a30aaSmrg      nonopt=$1
2665b41a30aaSmrg      shift
266606f32fbeSmrg    fi
2667ea133fd7Smrg
2668b41a30aaSmrg    # preserve --debug
2669b41a30aaSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2670b41a30aaSmrg
2671b41a30aaSmrg    case $host in
2672b41a30aaSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673b41a30aaSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674b41a30aaSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675b41a30aaSmrg        # don't eliminate duplications in $postdeps and $predeps
2676b41a30aaSmrg        opt_duplicate_compiler_generated_deps=:
2677b41a30aaSmrg        ;;
2678b41a30aaSmrg      *)
2679b41a30aaSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680b41a30aaSmrg        ;;
2681b41a30aaSmrg    esac
2682b41a30aaSmrg
2683b41a30aaSmrg    $opt_help || {
2684b41a30aaSmrg      # Sanity checks first:
2685b41a30aaSmrg      func_check_version_match
2686b41a30aaSmrg
2687b41a30aaSmrg      test yes != "$build_libtool_libs" \
2688b41a30aaSmrg        && test yes != "$build_old_libs" \
2689b41a30aaSmrg        && func_fatal_configuration "not configured to build any kind of library"
2690b41a30aaSmrg
2691b41a30aaSmrg      # Darwin sucks
2692b41a30aaSmrg      eval std_shrext=\"$shrext_cmds\"
2693ea133fd7Smrg
2694b41a30aaSmrg      # Only execute mode is allowed to have -dlopen flags.
2695b41a30aaSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696b41a30aaSmrg        func_error "unrecognized option '-dlopen'"
2697b41a30aaSmrg        $ECHO "$help" 1>&2
2698b41a30aaSmrg        exit $EXIT_FAILURE
2699b41a30aaSmrg      fi
2700b41a30aaSmrg
2701b41a30aaSmrg      # Change the help message to a mode-specific one.
2702b41a30aaSmrg      generic_help=$help
2703b41a30aaSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704b41a30aaSmrg    }
2705ea133fd7Smrg
2706b41a30aaSmrg    # Pass back the unparsed argument list
2707b41a30aaSmrg    func_quote eval ${1+"$@"}
2708b41a30aaSmrg    libtool_validate_options_result=$func_quote_result
270906f32fbeSmrg}
2710b41a30aaSmrgfunc_add_hook func_validate_options libtool_validate_options
2711b41a30aaSmrg
2712ea133fd7Smrg
2713b41a30aaSmrg# Process options as early as possible so that --help and --version
2714b41a30aaSmrg# can return quickly.
2715b41a30aaSmrgfunc_options ${1+"$@"}
2716b41a30aaSmrgeval set dummy "$func_options_result"; shift
2717ea133fd7Smrg
2718a253d6aeSmrg
2719a253d6aeSmrg
272006f32fbeSmrg## ----------- ##
272106f32fbeSmrg##    Main.    ##
272206f32fbeSmrg## ----------- ##
2723a253d6aeSmrg
2724b41a30aaSmrgmagic='%%%MAGIC variable%%%'
2725b41a30aaSmrgmagic_exe='%%%MAGIC EXE variable%%%'
2726b41a30aaSmrg
2727b41a30aaSmrg# Global variables.
2728b41a30aaSmrgextracted_archives=
2729b41a30aaSmrgextracted_serial=0
2730b41a30aaSmrg
2731b41a30aaSmrg# If this variable is set in any of the actions, the command in it
2732b41a30aaSmrg# will be execed at the end.  This prevents here-documents from being
2733b41a30aaSmrg# left over by shells.
2734b41a30aaSmrgexec_cmd=
2735b41a30aaSmrg
2736b41a30aaSmrg
2737b41a30aaSmrg# A function that is used when there is no print builtin or printf.
2738b41a30aaSmrgfunc_fallback_echo ()
2739b41a30aaSmrg{
2740b41a30aaSmrg  eval 'cat <<_LTECHO_EOF
2741b41a30aaSmrg$1
2742b41a30aaSmrg_LTECHO_EOF'
2743b41a30aaSmrg}
2744b41a30aaSmrg
2745b41a30aaSmrg# func_generated_by_libtool
2746b41a30aaSmrg# True iff stdin has been generated by Libtool. This function is only
2747b41a30aaSmrg# a basic sanity check; it will hardly flush out determined imposters.
2748b41a30aaSmrgfunc_generated_by_libtool_p ()
2749b41a30aaSmrg{
2750b41a30aaSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751b41a30aaSmrg}
2752b41a30aaSmrg
2753ea133fd7Smrg# func_lalib_p file
2754b41a30aaSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2755ea133fd7Smrg# This function is only a basic sanity check; it will hardly flush out
2756ea133fd7Smrg# determined imposters.
2757ea133fd7Smrgfunc_lalib_p ()
2758ea133fd7Smrg{
2759ea133fd7Smrg    test -f "$1" &&
2760b41a30aaSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2761ea133fd7Smrg}
2762a253d6aeSmrg
2763ea133fd7Smrg# func_lalib_unsafe_p file
2764b41a30aaSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2765ea133fd7Smrg# This function implements the same check as func_lalib_p without
2766ea133fd7Smrg# resorting to external programs.  To this end, it redirects stdin and
2767ea133fd7Smrg# closes it afterwards, without saving the original file descriptor.
2768ea133fd7Smrg# As a safety measure, use it only where a negative result would be
2769b41a30aaSmrg# fatal anyway.  Works if 'file' does not exist.
2770ea133fd7Smrgfunc_lalib_unsafe_p ()
2771ea133fd7Smrg{
2772ea133fd7Smrg    lalib_p=no
2773ea133fd7Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2774ea133fd7Smrg	for lalib_p_l in 1 2 3 4
2775ea133fd7Smrg	do
2776ea133fd7Smrg	    read lalib_p_line
2777b41a30aaSmrg	    case $lalib_p_line in
2778ea133fd7Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2779ea133fd7Smrg	    esac
2780ea133fd7Smrg	done
2781ea133fd7Smrg	exec 0<&5 5<&-
2782ea133fd7Smrg    fi
2783b41a30aaSmrg    test yes = "$lalib_p"
2784ea133fd7Smrg}
2785a253d6aeSmrg
2786ea133fd7Smrg# func_ltwrapper_script_p file
2787ea133fd7Smrg# True iff FILE is a libtool wrapper script
2788ea133fd7Smrg# This function is only a basic sanity check; it will hardly flush out
2789ea133fd7Smrg# determined imposters.
2790ea133fd7Smrgfunc_ltwrapper_script_p ()
2791ea133fd7Smrg{
2792b41a30aaSmrg    test -f "$1" &&
2793b41a30aaSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2794ea133fd7Smrg}
2795a253d6aeSmrg
2796ea133fd7Smrg# func_ltwrapper_executable_p file
2797ea133fd7Smrg# True iff FILE is a libtool wrapper executable
2798ea133fd7Smrg# This function is only a basic sanity check; it will hardly flush out
2799ea133fd7Smrg# determined imposters.
2800ea133fd7Smrgfunc_ltwrapper_executable_p ()
2801ea133fd7Smrg{
2802ea133fd7Smrg    func_ltwrapper_exec_suffix=
2803ea133fd7Smrg    case $1 in
2804ea133fd7Smrg    *.exe) ;;
2805ea133fd7Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2806ea133fd7Smrg    esac
2807ea133fd7Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2808ea133fd7Smrg}
2809a253d6aeSmrg
2810ea133fd7Smrg# func_ltwrapper_scriptname file
2811ea133fd7Smrg# Assumes file is an ltwrapper_executable
2812ea133fd7Smrg# uses $file to determine the appropriate filename for a
2813ea133fd7Smrg# temporary ltwrapper_script.
2814ea133fd7Smrgfunc_ltwrapper_scriptname ()
2815ea133fd7Smrg{
281606f32fbeSmrg    func_dirname_and_basename "$1" "" "."
281706f32fbeSmrg    func_stripname '' '.exe' "$func_basename_result"
2818b41a30aaSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2819ea133fd7Smrg}
2820a253d6aeSmrg
2821ea133fd7Smrg# func_ltwrapper_p file
2822ea133fd7Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2823ea133fd7Smrg# This function is only a basic sanity check; it will hardly flush out
2824ea133fd7Smrg# determined imposters.
2825ea133fd7Smrgfunc_ltwrapper_p ()
2826ea133fd7Smrg{
2827ea133fd7Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2828ea133fd7Smrg}
2829a253d6aeSmrg
2830a253d6aeSmrg
2831ea133fd7Smrg# func_execute_cmds commands fail_cmd
2832ea133fd7Smrg# Execute tilde-delimited COMMANDS.
2833ea133fd7Smrg# If FAIL_CMD is given, eval that upon failure.
2834ea133fd7Smrg# FAIL_CMD may read-access the current command in variable CMD!
2835ea133fd7Smrgfunc_execute_cmds ()
2836ea133fd7Smrg{
2837b41a30aaSmrg    $debug_cmd
2838b41a30aaSmrg
2839ea133fd7Smrg    save_ifs=$IFS; IFS='~'
2840ea133fd7Smrg    for cmd in $1; do
2841b41a30aaSmrg      IFS=$sp$nl
2842ea133fd7Smrg      eval cmd=\"$cmd\"
2843b41a30aaSmrg      IFS=$save_ifs
2844ea133fd7Smrg      func_show_eval "$cmd" "${2-:}"
2845ea133fd7Smrg    done
2846ea133fd7Smrg    IFS=$save_ifs
2847ea133fd7Smrg}
2848ea133fd7Smrg
2849ea133fd7Smrg
2850ea133fd7Smrg# func_source file
2851ea133fd7Smrg# Source FILE, adding directory component if necessary.
2852ea133fd7Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2853ea133fd7Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2854ea133fd7Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855b41a30aaSmrg# 'FILE.' does not work on cygwin managed mounts.
2856ea133fd7Smrgfunc_source ()
2857ea133fd7Smrg{
2858b41a30aaSmrg    $debug_cmd
2859b41a30aaSmrg
2860ea133fd7Smrg    case $1 in
2861ea133fd7Smrg    */* | *\\*)	. "$1" ;;
2862ea133fd7Smrg    *)		. "./$1" ;;
2863ea133fd7Smrg    esac
2864ea133fd7Smrg}
2865ea133fd7Smrg
2866ea133fd7Smrg
286706f32fbeSmrg# func_resolve_sysroot PATH
286806f32fbeSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
286906f32fbeSmrg# func_resolve_sysroot_result
287006f32fbeSmrgfunc_resolve_sysroot ()
287106f32fbeSmrg{
287206f32fbeSmrg  func_resolve_sysroot_result=$1
287306f32fbeSmrg  case $func_resolve_sysroot_result in
287406f32fbeSmrg  =*)
287506f32fbeSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
287606f32fbeSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
287706f32fbeSmrg    ;;
287806f32fbeSmrg  esac
287906f32fbeSmrg}
288006f32fbeSmrg
288106f32fbeSmrg# func_replace_sysroot PATH
288206f32fbeSmrg# If PATH begins with the sysroot, replace it with = and
288306f32fbeSmrg# store the result into func_replace_sysroot_result.
288406f32fbeSmrgfunc_replace_sysroot ()
288506f32fbeSmrg{
2886b41a30aaSmrg  case $lt_sysroot:$1 in
288706f32fbeSmrg  ?*:"$lt_sysroot"*)
288806f32fbeSmrg    func_stripname "$lt_sysroot" '' "$1"
2889b41a30aaSmrg    func_replace_sysroot_result='='$func_stripname_result
289006f32fbeSmrg    ;;
289106f32fbeSmrg  *)
289206f32fbeSmrg    # Including no sysroot.
289306f32fbeSmrg    func_replace_sysroot_result=$1
289406f32fbeSmrg    ;;
289506f32fbeSmrg  esac
289606f32fbeSmrg}
289706f32fbeSmrg
2898ea133fd7Smrg# func_infer_tag arg
2899ea133fd7Smrg# Infer tagged configuration to use if any are available and
2900ea133fd7Smrg# if one wasn't chosen via the "--tag" command line option.
2901ea133fd7Smrg# Only attempt this if the compiler in the base compile
2902ea133fd7Smrg# command doesn't match the default compiler.
2903ea133fd7Smrg# arg is usually of the form 'gcc ...'
2904ea133fd7Smrgfunc_infer_tag ()
2905ea133fd7Smrg{
2906b41a30aaSmrg    $debug_cmd
2907b41a30aaSmrg
2908ea133fd7Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2909ea133fd7Smrg      CC_quoted=
2910ea133fd7Smrg      for arg in $CC; do
291106f32fbeSmrg	func_append_quoted CC_quoted "$arg"
2912ea133fd7Smrg      done
291325b89263Smrg      CC_expanded=`func_echo_all $CC`
291425b89263Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2915ea133fd7Smrg      case $@ in
2916ea133fd7Smrg      # Blanks in the command may have been stripped by the calling shell,
2917ea133fd7Smrg      # but not from the CC environment variable when configure was run.
291825b89263Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
291925b89263Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2920ea133fd7Smrg      # Blanks at the start of $base_compile will cause this to fail
2921ea133fd7Smrg      # if we don't check for them as well.
2922ea133fd7Smrg      *)
2923ea133fd7Smrg	for z in $available_tags; do
2924ea133fd7Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2925ea133fd7Smrg	    # Evaluate the configuration.
2926b41a30aaSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2927ea133fd7Smrg	    CC_quoted=
2928ea133fd7Smrg	    for arg in $CC; do
2929ea133fd7Smrg	      # Double-quote args containing other shell metacharacters.
293006f32fbeSmrg	      func_append_quoted CC_quoted "$arg"
2931ea133fd7Smrg	    done
293225b89263Smrg	    CC_expanded=`func_echo_all $CC`
293325b89263Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2934ea133fd7Smrg	    case "$@ " in
293525b89263Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
293625b89263Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2937ea133fd7Smrg	      # The compiler in the base compile command matches
2938ea133fd7Smrg	      # the one in the tagged configuration.
2939ea133fd7Smrg	      # Assume this is the tagged configuration we want.
2940ea133fd7Smrg	      tagname=$z
2941ea133fd7Smrg	      break
2942ea133fd7Smrg	      ;;
2943a253d6aeSmrg	    esac
2944ea133fd7Smrg	  fi
2945ea133fd7Smrg	done
2946ea133fd7Smrg	# If $tagname still isn't set, then no tagged configuration
2947ea133fd7Smrg	# was found and let the user know that the "--tag" command
2948ea133fd7Smrg	# line option must be used.
2949ea133fd7Smrg	if test -z "$tagname"; then
2950ea133fd7Smrg	  func_echo "unable to infer tagged configuration"
2951b41a30aaSmrg	  func_fatal_error "specify a tag with '--tag'"
2952ea133fd7Smrg#	else
2953ea133fd7Smrg#	  func_verbose "using $tagname tagged configuration"
2954ea133fd7Smrg	fi
2955ea133fd7Smrg	;;
2956ea133fd7Smrg      esac
2957ea133fd7Smrg    fi
2958ea133fd7Smrg}
2959ea133fd7Smrg
2960ea133fd7Smrg
2961ea133fd7Smrg
296206f32fbeSmrg# func_write_libtool_object output_name pic_name nonpic_name
296306f32fbeSmrg# Create a libtool object file (analogous to a ".la" file),
296406f32fbeSmrg# but don't create it if we're doing a dry run.
296506f32fbeSmrgfunc_write_libtool_object ()
296606f32fbeSmrg{
2967b41a30aaSmrg    write_libobj=$1
2968b41a30aaSmrg    if test yes = "$build_libtool_libs"; then
2969b41a30aaSmrg      write_lobj=\'$2\'
297006f32fbeSmrg    else
297106f32fbeSmrg      write_lobj=none
297206f32fbeSmrg    fi
297306f32fbeSmrg
2974b41a30aaSmrg    if test yes = "$build_old_libs"; then
2975b41a30aaSmrg      write_oldobj=\'$3\'
297606f32fbeSmrg    else
297706f32fbeSmrg      write_oldobj=none
297806f32fbeSmrg    fi
297906f32fbeSmrg
298006f32fbeSmrg    $opt_dry_run || {
298106f32fbeSmrg      cat >${write_libobj}T <<EOF
298206f32fbeSmrg# $write_libobj - a libtool object file
2983b41a30aaSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
298406f32fbeSmrg#
298506f32fbeSmrg# Please DO NOT delete this file!
298606f32fbeSmrg# It is necessary for linking the library.
298706f32fbeSmrg
298806f32fbeSmrg# Name of the PIC object.
298906f32fbeSmrgpic_object=$write_lobj
299006f32fbeSmrg
299106f32fbeSmrg# Name of the non-PIC object
299206f32fbeSmrgnon_pic_object=$write_oldobj
299306f32fbeSmrg
299406f32fbeSmrgEOF
2995b41a30aaSmrg      $MV "${write_libobj}T" "$write_libobj"
299606f32fbeSmrg    }
299706f32fbeSmrg}
299806f32fbeSmrg
299906f32fbeSmrg
300006f32fbeSmrg##################################################
300106f32fbeSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
300206f32fbeSmrg##################################################
300306f32fbeSmrg
300406f32fbeSmrg# func_convert_core_file_wine_to_w32 ARG
300506f32fbeSmrg# Helper function used by file name conversion functions when $build is *nix,
300606f32fbeSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
300706f32fbeSmrg# correctly configured wine environment available, with the winepath program
300806f32fbeSmrg# in $build's $PATH.
300906f32fbeSmrg#
301006f32fbeSmrg# ARG is the $build file name to be converted to w32 format.
301106f32fbeSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
301206f32fbeSmrg# be empty on error (or when ARG is empty)
301306f32fbeSmrgfunc_convert_core_file_wine_to_w32 ()
301406f32fbeSmrg{
3015b41a30aaSmrg  $debug_cmd
3016b41a30aaSmrg
3017b41a30aaSmrg  func_convert_core_file_wine_to_w32_result=$1
301806f32fbeSmrg  if test -n "$1"; then
301906f32fbeSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
302006f32fbeSmrg    # are forced to check the contents of stdout. On the other hand, if the
302106f32fbeSmrg    # command is not found, the shell will set an exit code of 127 and print
302206f32fbeSmrg    # *an error message* to stdout. So we must check for both error code of
302306f32fbeSmrg    # zero AND non-empty stdout, which explains the odd construction:
302406f32fbeSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025b41a30aaSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
302606f32fbeSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027b41a30aaSmrg        $SED -e "$sed_naive_backslashify"`
302806f32fbeSmrg    else
302906f32fbeSmrg      func_convert_core_file_wine_to_w32_result=
303006f32fbeSmrg    fi
303106f32fbeSmrg  fi
303206f32fbeSmrg}
303306f32fbeSmrg# end: func_convert_core_file_wine_to_w32
303406f32fbeSmrg
303506f32fbeSmrg
303606f32fbeSmrg# func_convert_core_path_wine_to_w32 ARG
303706f32fbeSmrg# Helper function used by path conversion functions when $build is *nix, and
303806f32fbeSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
303906f32fbeSmrg# configured wine environment available, with the winepath program in $build's
304006f32fbeSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
304106f32fbeSmrg#
304206f32fbeSmrg# ARG is path to be converted from $build format to win32.
304306f32fbeSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
304406f32fbeSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
304506f32fbeSmrg# are convertible, then the result may be empty.
304606f32fbeSmrgfunc_convert_core_path_wine_to_w32 ()
304706f32fbeSmrg{
3048b41a30aaSmrg  $debug_cmd
3049b41a30aaSmrg
305006f32fbeSmrg  # unfortunately, winepath doesn't convert paths, only file names
3051b41a30aaSmrg  func_convert_core_path_wine_to_w32_result=
305206f32fbeSmrg  if test -n "$1"; then
305306f32fbeSmrg    oldIFS=$IFS
305406f32fbeSmrg    IFS=:
305506f32fbeSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
305606f32fbeSmrg      IFS=$oldIFS
305706f32fbeSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058b41a30aaSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
305906f32fbeSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060b41a30aaSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
306106f32fbeSmrg        else
306206f32fbeSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
306306f32fbeSmrg        fi
306406f32fbeSmrg      fi
306506f32fbeSmrg    done
306606f32fbeSmrg    IFS=$oldIFS
306706f32fbeSmrg  fi
306806f32fbeSmrg}
306906f32fbeSmrg# end: func_convert_core_path_wine_to_w32
307006f32fbeSmrg
307106f32fbeSmrg
307206f32fbeSmrg# func_cygpath ARGS...
307306f32fbeSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
307406f32fbeSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
307506f32fbeSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
307606f32fbeSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
307706f32fbeSmrg# file name or path is assumed to be in w32 format, as previously converted
307806f32fbeSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
307906f32fbeSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
308006f32fbeSmrg# Cygwin format). Returns an empty string on error.
308106f32fbeSmrg#
308206f32fbeSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
308306f32fbeSmrg# be converted.
308406f32fbeSmrg#
308506f32fbeSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
308606f32fbeSmrg# environment variable; do not put it in $PATH.
308706f32fbeSmrgfunc_cygpath ()
308806f32fbeSmrg{
3089b41a30aaSmrg  $debug_cmd
3090b41a30aaSmrg
309106f32fbeSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
309206f32fbeSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
309306f32fbeSmrg    if test "$?" -ne 0; then
309406f32fbeSmrg      # on failure, ensure result is empty
309506f32fbeSmrg      func_cygpath_result=
309606f32fbeSmrg    fi
309706f32fbeSmrg  else
309806f32fbeSmrg    func_cygpath_result=
3099b41a30aaSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
310006f32fbeSmrg  fi
310106f32fbeSmrg}
310206f32fbeSmrg#end: func_cygpath
310306f32fbeSmrg
310406f32fbeSmrg
310506f32fbeSmrg# func_convert_core_msys_to_w32 ARG
310606f32fbeSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
310706f32fbeSmrg# result in func_convert_core_msys_to_w32_result.
310806f32fbeSmrgfunc_convert_core_msys_to_w32 ()
310906f32fbeSmrg{
3110b41a30aaSmrg  $debug_cmd
3111b41a30aaSmrg
311206f32fbeSmrg  # awkward: cmd appends spaces to result
311306f32fbeSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114b41a30aaSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
311506f32fbeSmrg}
311606f32fbeSmrg#end: func_convert_core_msys_to_w32
311706f32fbeSmrg
311806f32fbeSmrg
311906f32fbeSmrg# func_convert_file_check ARG1 ARG2
312006f32fbeSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
312106f32fbeSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
312206f32fbeSmrg# func_to_host_file_result to ARG1).
312306f32fbeSmrgfunc_convert_file_check ()
312406f32fbeSmrg{
3125b41a30aaSmrg  $debug_cmd
3126b41a30aaSmrg
3127b41a30aaSmrg  if test -z "$2" && test -n "$1"; then
312806f32fbeSmrg    func_error "Could not determine host file name corresponding to"
3129b41a30aaSmrg    func_error "  '$1'"
313006f32fbeSmrg    func_error "Continuing, but uninstalled executables may not work."
313106f32fbeSmrg    # Fallback:
3132b41a30aaSmrg    func_to_host_file_result=$1
313306f32fbeSmrg  fi
313406f32fbeSmrg}
313506f32fbeSmrg# end func_convert_file_check
313606f32fbeSmrg
313706f32fbeSmrg
313806f32fbeSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
313906f32fbeSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
314006f32fbeSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
314106f32fbeSmrg# func_to_host_file_result to a simplistic fallback value (see below).
314206f32fbeSmrgfunc_convert_path_check ()
314306f32fbeSmrg{
3144b41a30aaSmrg  $debug_cmd
3145b41a30aaSmrg
314606f32fbeSmrg  if test -z "$4" && test -n "$3"; then
314706f32fbeSmrg    func_error "Could not determine the host path corresponding to"
3148b41a30aaSmrg    func_error "  '$3'"
314906f32fbeSmrg    func_error "Continuing, but uninstalled executables may not work."
315006f32fbeSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
315106f32fbeSmrg    # should not be "improved".  See libtool.info.
315206f32fbeSmrg    if test "x$1" != "x$2"; then
315306f32fbeSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
315406f32fbeSmrg      func_to_host_path_result=`echo "$3" |
315506f32fbeSmrg        $SED -e "$lt_replace_pathsep_chars"`
315606f32fbeSmrg    else
3157b41a30aaSmrg      func_to_host_path_result=$3
315806f32fbeSmrg    fi
315906f32fbeSmrg  fi
316006f32fbeSmrg}
316106f32fbeSmrg# end func_convert_path_check
316206f32fbeSmrg
316306f32fbeSmrg
316406f32fbeSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
316506f32fbeSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
316606f32fbeSmrg# and appending REPL if ORIG matches BACKPAT.
316706f32fbeSmrgfunc_convert_path_front_back_pathsep ()
316806f32fbeSmrg{
3169b41a30aaSmrg  $debug_cmd
3170b41a30aaSmrg
317106f32fbeSmrg  case $4 in
3172b41a30aaSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
317306f32fbeSmrg    ;;
317406f32fbeSmrg  esac
317506f32fbeSmrg  case $4 in
317606f32fbeSmrg  $2 ) func_append func_to_host_path_result "$3"
317706f32fbeSmrg    ;;
317806f32fbeSmrg  esac
317906f32fbeSmrg}
318006f32fbeSmrg# end func_convert_path_front_back_pathsep
318106f32fbeSmrg
318206f32fbeSmrg
318306f32fbeSmrg##################################################
318406f32fbeSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
318506f32fbeSmrg##################################################
3186b41a30aaSmrg# invoked via '$to_host_file_cmd ARG'
318706f32fbeSmrg#
318806f32fbeSmrg# In each case, ARG is the path to be converted from $build to $host format.
318906f32fbeSmrg# Result will be available in $func_to_host_file_result.
319006f32fbeSmrg
319106f32fbeSmrg
319206f32fbeSmrg# func_to_host_file ARG
319306f32fbeSmrg# Converts the file name ARG from $build format to $host format. Return result
319406f32fbeSmrg# in func_to_host_file_result.
319506f32fbeSmrgfunc_to_host_file ()
319606f32fbeSmrg{
3197b41a30aaSmrg  $debug_cmd
3198b41a30aaSmrg
319906f32fbeSmrg  $to_host_file_cmd "$1"
320006f32fbeSmrg}
320106f32fbeSmrg# end func_to_host_file
320206f32fbeSmrg
320306f32fbeSmrg
320406f32fbeSmrg# func_to_tool_file ARG LAZY
320506f32fbeSmrg# converts the file name ARG from $build format to toolchain format. Return
320606f32fbeSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
320706f32fbeSmrg# in (the comma separated) LAZY, no conversion takes place.
320806f32fbeSmrgfunc_to_tool_file ()
320906f32fbeSmrg{
3210b41a30aaSmrg  $debug_cmd
3211b41a30aaSmrg
321206f32fbeSmrg  case ,$2, in
321306f32fbeSmrg    *,"$to_tool_file_cmd",*)
321406f32fbeSmrg      func_to_tool_file_result=$1
321506f32fbeSmrg      ;;
321606f32fbeSmrg    *)
321706f32fbeSmrg      $to_tool_file_cmd "$1"
321806f32fbeSmrg      func_to_tool_file_result=$func_to_host_file_result
321906f32fbeSmrg      ;;
322006f32fbeSmrg  esac
322106f32fbeSmrg}
322206f32fbeSmrg# end func_to_tool_file
322306f32fbeSmrg
322406f32fbeSmrg
322506f32fbeSmrg# func_convert_file_noop ARG
322606f32fbeSmrg# Copy ARG to func_to_host_file_result.
322706f32fbeSmrgfunc_convert_file_noop ()
322806f32fbeSmrg{
3229b41a30aaSmrg  func_to_host_file_result=$1
323006f32fbeSmrg}
323106f32fbeSmrg# end func_convert_file_noop
323206f32fbeSmrg
323306f32fbeSmrg
323406f32fbeSmrg# func_convert_file_msys_to_w32 ARG
323506f32fbeSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
323606f32fbeSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
323706f32fbeSmrg# func_to_host_file_result.
323806f32fbeSmrgfunc_convert_file_msys_to_w32 ()
323906f32fbeSmrg{
3240b41a30aaSmrg  $debug_cmd
3241b41a30aaSmrg
3242b41a30aaSmrg  func_to_host_file_result=$1
324306f32fbeSmrg  if test -n "$1"; then
324406f32fbeSmrg    func_convert_core_msys_to_w32 "$1"
3245b41a30aaSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
324606f32fbeSmrg  fi
324706f32fbeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
324806f32fbeSmrg}
324906f32fbeSmrg# end func_convert_file_msys_to_w32
325006f32fbeSmrg
325106f32fbeSmrg
325206f32fbeSmrg# func_convert_file_cygwin_to_w32 ARG
325306f32fbeSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
325406f32fbeSmrg# func_to_host_file_result.
325506f32fbeSmrgfunc_convert_file_cygwin_to_w32 ()
325606f32fbeSmrg{
3257b41a30aaSmrg  $debug_cmd
3258b41a30aaSmrg
3259b41a30aaSmrg  func_to_host_file_result=$1
326006f32fbeSmrg  if test -n "$1"; then
326106f32fbeSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
326206f32fbeSmrg    # LT_CYGPATH in this case.
326306f32fbeSmrg    func_to_host_file_result=`cygpath -m "$1"`
326406f32fbeSmrg  fi
326506f32fbeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
326606f32fbeSmrg}
326706f32fbeSmrg# end func_convert_file_cygwin_to_w32
326806f32fbeSmrg
326906f32fbeSmrg
327006f32fbeSmrg# func_convert_file_nix_to_w32 ARG
327106f32fbeSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
327206f32fbeSmrg# and a working winepath. Returns result in func_to_host_file_result.
327306f32fbeSmrgfunc_convert_file_nix_to_w32 ()
327406f32fbeSmrg{
3275b41a30aaSmrg  $debug_cmd
3276b41a30aaSmrg
3277b41a30aaSmrg  func_to_host_file_result=$1
327806f32fbeSmrg  if test -n "$1"; then
327906f32fbeSmrg    func_convert_core_file_wine_to_w32 "$1"
3280b41a30aaSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
328106f32fbeSmrg  fi
328206f32fbeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
328306f32fbeSmrg}
328406f32fbeSmrg# end func_convert_file_nix_to_w32
328506f32fbeSmrg
328606f32fbeSmrg
328706f32fbeSmrg# func_convert_file_msys_to_cygwin ARG
328806f32fbeSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
328906f32fbeSmrg# Returns result in func_to_host_file_result.
329006f32fbeSmrgfunc_convert_file_msys_to_cygwin ()
329106f32fbeSmrg{
3292b41a30aaSmrg  $debug_cmd
3293b41a30aaSmrg
3294b41a30aaSmrg  func_to_host_file_result=$1
329506f32fbeSmrg  if test -n "$1"; then
329606f32fbeSmrg    func_convert_core_msys_to_w32 "$1"
329706f32fbeSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298b41a30aaSmrg    func_to_host_file_result=$func_cygpath_result
329906f32fbeSmrg  fi
330006f32fbeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
330106f32fbeSmrg}
330206f32fbeSmrg# end func_convert_file_msys_to_cygwin
330306f32fbeSmrg
330406f32fbeSmrg
330506f32fbeSmrg# func_convert_file_nix_to_cygwin ARG
330606f32fbeSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
330706f32fbeSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
330806f32fbeSmrg# in func_to_host_file_result.
330906f32fbeSmrgfunc_convert_file_nix_to_cygwin ()
331006f32fbeSmrg{
3311b41a30aaSmrg  $debug_cmd
3312b41a30aaSmrg
3313b41a30aaSmrg  func_to_host_file_result=$1
331406f32fbeSmrg  if test -n "$1"; then
331506f32fbeSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
331606f32fbeSmrg    func_convert_core_file_wine_to_w32 "$1"
331706f32fbeSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318b41a30aaSmrg    func_to_host_file_result=$func_cygpath_result
331906f32fbeSmrg  fi
332006f32fbeSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
332106f32fbeSmrg}
332206f32fbeSmrg# end func_convert_file_nix_to_cygwin
332306f32fbeSmrg
332406f32fbeSmrg
332506f32fbeSmrg#############################################
332606f32fbeSmrg# $build to $host PATH CONVERSION FUNCTIONS #
332706f32fbeSmrg#############################################
3328b41a30aaSmrg# invoked via '$to_host_path_cmd ARG'
332906f32fbeSmrg#
333006f32fbeSmrg# In each case, ARG is the path to be converted from $build to $host format.
333106f32fbeSmrg# The result will be available in $func_to_host_path_result.
333206f32fbeSmrg#
333306f32fbeSmrg# Path separators are also converted from $build format to $host format.  If
333406f32fbeSmrg# ARG begins or ends with a path separator character, it is preserved (but
333506f32fbeSmrg# converted to $host format) on output.
333606f32fbeSmrg#
333706f32fbeSmrg# All path conversion functions are named using the following convention:
333806f32fbeSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
333906f32fbeSmrg#   path conversion function         : func_convert_path_X_to_Y ()
334006f32fbeSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
334106f32fbeSmrg# same.  If conversion functions are added for new $build/$host combinations,
334206f32fbeSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
334306f32fbeSmrg# will break.
334406f32fbeSmrg
334506f32fbeSmrg
334606f32fbeSmrg# func_init_to_host_path_cmd
334706f32fbeSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
334806f32fbeSmrg# appropriate value, based on the value of $to_host_file_cmd.
334906f32fbeSmrgto_host_path_cmd=
335006f32fbeSmrgfunc_init_to_host_path_cmd ()
335106f32fbeSmrg{
3352b41a30aaSmrg  $debug_cmd
3353b41a30aaSmrg
335406f32fbeSmrg  if test -z "$to_host_path_cmd"; then
335506f32fbeSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356b41a30aaSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
335706f32fbeSmrg  fi
335806f32fbeSmrg}
335906f32fbeSmrg
336006f32fbeSmrg
336106f32fbeSmrg# func_to_host_path ARG
336206f32fbeSmrg# Converts the path ARG from $build format to $host format. Return result
336306f32fbeSmrg# in func_to_host_path_result.
336406f32fbeSmrgfunc_to_host_path ()
336506f32fbeSmrg{
3366b41a30aaSmrg  $debug_cmd
3367b41a30aaSmrg
336806f32fbeSmrg  func_init_to_host_path_cmd
336906f32fbeSmrg  $to_host_path_cmd "$1"
337006f32fbeSmrg}
337106f32fbeSmrg# end func_to_host_path
337206f32fbeSmrg
337306f32fbeSmrg
337406f32fbeSmrg# func_convert_path_noop ARG
337506f32fbeSmrg# Copy ARG to func_to_host_path_result.
337606f32fbeSmrgfunc_convert_path_noop ()
337706f32fbeSmrg{
3378b41a30aaSmrg  func_to_host_path_result=$1
337906f32fbeSmrg}
338006f32fbeSmrg# end func_convert_path_noop
338106f32fbeSmrg
338206f32fbeSmrg
338306f32fbeSmrg# func_convert_path_msys_to_w32 ARG
338406f32fbeSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
338506f32fbeSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
338606f32fbeSmrg# func_to_host_path_result.
338706f32fbeSmrgfunc_convert_path_msys_to_w32 ()
3388ea133fd7Smrg{
3389b41a30aaSmrg  $debug_cmd
3390b41a30aaSmrg
3391b41a30aaSmrg  func_to_host_path_result=$1
339206f32fbeSmrg  if test -n "$1"; then
339306f32fbeSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
339406f32fbeSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
339506f32fbeSmrg    # and winepath ignores them completely.
339606f32fbeSmrg    func_stripname : : "$1"
339706f32fbeSmrg    func_to_host_path_tmp1=$func_stripname_result
339806f32fbeSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399b41a30aaSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
340006f32fbeSmrg    func_convert_path_check : ";" \
340106f32fbeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
340206f32fbeSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
340306f32fbeSmrg  fi
340406f32fbeSmrg}
340506f32fbeSmrg# end func_convert_path_msys_to_w32
3406ea133fd7Smrg
3407ea133fd7Smrg
340806f32fbeSmrg# func_convert_path_cygwin_to_w32 ARG
340906f32fbeSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
341006f32fbeSmrg# func_to_host_file_result.
341106f32fbeSmrgfunc_convert_path_cygwin_to_w32 ()
341206f32fbeSmrg{
3413b41a30aaSmrg  $debug_cmd
3414b41a30aaSmrg
3415b41a30aaSmrg  func_to_host_path_result=$1
341606f32fbeSmrg  if test -n "$1"; then
341706f32fbeSmrg    # See func_convert_path_msys_to_w32:
341806f32fbeSmrg    func_stripname : : "$1"
341906f32fbeSmrg    func_to_host_path_tmp1=$func_stripname_result
342006f32fbeSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
342106f32fbeSmrg    func_convert_path_check : ";" \
342206f32fbeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
342306f32fbeSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
342406f32fbeSmrg  fi
342506f32fbeSmrg}
342606f32fbeSmrg# end func_convert_path_cygwin_to_w32
3427ea133fd7Smrg
3428ea133fd7Smrg
342906f32fbeSmrg# func_convert_path_nix_to_w32 ARG
343006f32fbeSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
343106f32fbeSmrg# a working winepath.  Returns result in func_to_host_file_result.
343206f32fbeSmrgfunc_convert_path_nix_to_w32 ()
343306f32fbeSmrg{
3434b41a30aaSmrg  $debug_cmd
3435b41a30aaSmrg
3436b41a30aaSmrg  func_to_host_path_result=$1
343706f32fbeSmrg  if test -n "$1"; then
343806f32fbeSmrg    # See func_convert_path_msys_to_w32:
343906f32fbeSmrg    func_stripname : : "$1"
344006f32fbeSmrg    func_to_host_path_tmp1=$func_stripname_result
344106f32fbeSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442b41a30aaSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
344306f32fbeSmrg    func_convert_path_check : ";" \
344406f32fbeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
344506f32fbeSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
344606f32fbeSmrg  fi
344706f32fbeSmrg}
344806f32fbeSmrg# end func_convert_path_nix_to_w32
3449ea133fd7Smrg
345006f32fbeSmrg
345106f32fbeSmrg# func_convert_path_msys_to_cygwin ARG
345206f32fbeSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
345306f32fbeSmrg# Returns result in func_to_host_file_result.
345406f32fbeSmrgfunc_convert_path_msys_to_cygwin ()
345506f32fbeSmrg{
3456b41a30aaSmrg  $debug_cmd
3457b41a30aaSmrg
3458b41a30aaSmrg  func_to_host_path_result=$1
345906f32fbeSmrg  if test -n "$1"; then
346006f32fbeSmrg    # See func_convert_path_msys_to_w32:
346106f32fbeSmrg    func_stripname : : "$1"
346206f32fbeSmrg    func_to_host_path_tmp1=$func_stripname_result
346306f32fbeSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
346406f32fbeSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465b41a30aaSmrg    func_to_host_path_result=$func_cygpath_result
346606f32fbeSmrg    func_convert_path_check : : \
346706f32fbeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
346806f32fbeSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
346906f32fbeSmrg  fi
347006f32fbeSmrg}
347106f32fbeSmrg# end func_convert_path_msys_to_cygwin
347206f32fbeSmrg
347306f32fbeSmrg
347406f32fbeSmrg# func_convert_path_nix_to_cygwin ARG
347506f32fbeSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
347606f32fbeSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
347706f32fbeSmrg# func_to_host_file_result.
347806f32fbeSmrgfunc_convert_path_nix_to_cygwin ()
347906f32fbeSmrg{
3480b41a30aaSmrg  $debug_cmd
3481b41a30aaSmrg
3482b41a30aaSmrg  func_to_host_path_result=$1
348306f32fbeSmrg  if test -n "$1"; then
348406f32fbeSmrg    # Remove leading and trailing path separator characters from
348506f32fbeSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
348606f32fbeSmrg    # into '.;' and ';.', and winepath ignores them completely.
348706f32fbeSmrg    func_stripname : : "$1"
348806f32fbeSmrg    func_to_host_path_tmp1=$func_stripname_result
348906f32fbeSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
349006f32fbeSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491b41a30aaSmrg    func_to_host_path_result=$func_cygpath_result
349206f32fbeSmrg    func_convert_path_check : : \
349306f32fbeSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
349406f32fbeSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
349506f32fbeSmrg  fi
3496ea133fd7Smrg}
349706f32fbeSmrg# end func_convert_path_nix_to_cygwin
349806f32fbeSmrg
3499ea133fd7Smrg
3500b41a30aaSmrg# func_dll_def_p FILE
3501b41a30aaSmrg# True iff FILE is a Windows DLL '.def' file.
3502b41a30aaSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503b41a30aaSmrgfunc_dll_def_p ()
3504b41a30aaSmrg{
3505b41a30aaSmrg  $debug_cmd
3506b41a30aaSmrg
3507b41a30aaSmrg  func_dll_def_p_tmp=`$SED -n \
3508b41a30aaSmrg    -e 's/^[	 ]*//' \
3509b41a30aaSmrg    -e '/^\(;.*\)*$/d' \
3510b41a30aaSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511b41a30aaSmrg    -e q \
3512b41a30aaSmrg    "$1"`
3513b41a30aaSmrg  test DEF = "$func_dll_def_p_tmp"
3514b41a30aaSmrg}
3515b41a30aaSmrg
3516b41a30aaSmrg
3517ea133fd7Smrg# func_mode_compile arg...
3518ea133fd7Smrgfunc_mode_compile ()
3519ea133fd7Smrg{
3520b41a30aaSmrg    $debug_cmd
3521b41a30aaSmrg
3522ea133fd7Smrg    # Get the compilation command and the source file.
3523ea133fd7Smrg    base_compile=
3524b41a30aaSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3525ea133fd7Smrg    suppress_opt=yes
3526ea133fd7Smrg    suppress_output=
3527ea133fd7Smrg    arg_mode=normal
3528ea133fd7Smrg    libobj=
3529ea133fd7Smrg    later=
3530ea133fd7Smrg    pie_flag=
3531ea133fd7Smrg
3532ea133fd7Smrg    for arg
3533ea133fd7Smrg    do
3534ea133fd7Smrg      case $arg_mode in
3535ea133fd7Smrg      arg  )
3536ea133fd7Smrg	# do not "continue".  Instead, add this to base_compile
3537b41a30aaSmrg	lastarg=$arg
3538ea133fd7Smrg	arg_mode=normal
3539ea133fd7Smrg	;;
3540ea133fd7Smrg
3541ea133fd7Smrg      target )
3542b41a30aaSmrg	libobj=$arg
3543ea133fd7Smrg	arg_mode=normal
3544ea133fd7Smrg	continue
3545ea133fd7Smrg	;;
3546ea133fd7Smrg
3547ea133fd7Smrg      normal )
3548ea133fd7Smrg	# Accept any command-line options.
3549ea133fd7Smrg	case $arg in
3550ea133fd7Smrg	-o)
3551ea133fd7Smrg	  test -n "$libobj" && \
3552b41a30aaSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3553ea133fd7Smrg	  arg_mode=target
3554ea133fd7Smrg	  continue
3555ea133fd7Smrg	  ;;
3556ea133fd7Smrg
3557ea133fd7Smrg	-pie | -fpie | -fPIE)
355806f32fbeSmrg          func_append pie_flag " $arg"
3559ea133fd7Smrg	  continue
3560ea133fd7Smrg	  ;;
3561ea133fd7Smrg
3562ea133fd7Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
356306f32fbeSmrg	  func_append later " $arg"
3564ea133fd7Smrg	  continue
3565ea133fd7Smrg	  ;;
3566ea133fd7Smrg
3567ea133fd7Smrg	-no-suppress)
3568ea133fd7Smrg	  suppress_opt=no
3569ea133fd7Smrg	  continue
3570ea133fd7Smrg	  ;;
3571ea133fd7Smrg
3572ea133fd7Smrg	-Xcompiler)
3573ea133fd7Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3574ea133fd7Smrg	  continue      #  The current "srcfile" will either be retained or
3575ea133fd7Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
3576ea133fd7Smrg
3577ea133fd7Smrg	-Wc,*)
3578ea133fd7Smrg	  func_stripname '-Wc,' '' "$arg"
3579ea133fd7Smrg	  args=$func_stripname_result
3580ea133fd7Smrg	  lastarg=
3581b41a30aaSmrg	  save_ifs=$IFS; IFS=,
3582ea133fd7Smrg	  for arg in $args; do
3583b41a30aaSmrg	    IFS=$save_ifs
358406f32fbeSmrg	    func_append_quoted lastarg "$arg"
3585a253d6aeSmrg	  done
3586b41a30aaSmrg	  IFS=$save_ifs
3587ea133fd7Smrg	  func_stripname ' ' '' "$lastarg"
3588ea133fd7Smrg	  lastarg=$func_stripname_result
3589a253d6aeSmrg
3590a253d6aeSmrg	  # Add the arguments to base_compile.
359106f32fbeSmrg	  func_append base_compile " $lastarg"
3592a253d6aeSmrg	  continue
3593a253d6aeSmrg	  ;;
3594a253d6aeSmrg
3595ea133fd7Smrg	*)
3596a253d6aeSmrg	  # Accept the current argument as the source file.
3597a253d6aeSmrg	  # The previous "srcfile" becomes the current argument.
3598a253d6aeSmrg	  #
3599b41a30aaSmrg	  lastarg=$srcfile
3600b41a30aaSmrg	  srcfile=$arg
3601a253d6aeSmrg	  ;;
3602a253d6aeSmrg	esac  #  case $arg
3603a253d6aeSmrg	;;
3604a253d6aeSmrg      esac    #  case $arg_mode
3605a253d6aeSmrg
3606a253d6aeSmrg      # Aesthetically quote the previous argument.
360706f32fbeSmrg      func_append_quoted base_compile "$lastarg"
3608a253d6aeSmrg    done # for arg
3609a253d6aeSmrg
3610a253d6aeSmrg    case $arg_mode in
3611a253d6aeSmrg    arg)
3612ea133fd7Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3613a253d6aeSmrg      ;;
3614a253d6aeSmrg    target)
3615b41a30aaSmrg      func_fatal_error "you must specify a target with '-o'"
3616a253d6aeSmrg      ;;
3617a253d6aeSmrg    *)
3618a253d6aeSmrg      # Get the name of the library object.
3619ea133fd7Smrg      test -z "$libobj" && {
3620ea133fd7Smrg	func_basename "$srcfile"
3621b41a30aaSmrg	libobj=$func_basename_result
3622ea133fd7Smrg      }
3623a253d6aeSmrg      ;;
3624a253d6aeSmrg    esac
3625a253d6aeSmrg
3626a253d6aeSmrg    # Recognize several different file suffixes.
3627a253d6aeSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3628a253d6aeSmrg    case $libobj in
3629ea133fd7Smrg    *.[cCFSifmso] | \
3630ea133fd7Smrg    *.ada | *.adb | *.ads | *.asm | \
3631ea133fd7Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
363257ee1794Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3633ea133fd7Smrg      func_xform "$libobj"
3634ea133fd7Smrg      libobj=$func_xform_result
3635ea133fd7Smrg      ;;
3636a253d6aeSmrg    esac
3637a253d6aeSmrg
3638a253d6aeSmrg    case $libobj in
3639ea133fd7Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3640a253d6aeSmrg    *)
3641b41a30aaSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3642a253d6aeSmrg      ;;
3643a253d6aeSmrg    esac
3644a253d6aeSmrg
3645a253d6aeSmrg    func_infer_tag $base_compile
3646a253d6aeSmrg
3647a253d6aeSmrg    for arg in $later; do
3648a253d6aeSmrg      case $arg in
3649ea133fd7Smrg      -shared)
3650b41a30aaSmrg	test yes = "$build_libtool_libs" \
3651b41a30aaSmrg	  || func_fatal_configuration "cannot build a shared library"
3652ea133fd7Smrg	build_old_libs=no
3653ea133fd7Smrg	continue
3654ea133fd7Smrg	;;
3655ea133fd7Smrg
3656a253d6aeSmrg      -static)
3657ea133fd7Smrg	build_libtool_libs=no
3658a253d6aeSmrg	build_old_libs=yes
3659a253d6aeSmrg	continue
3660a253d6aeSmrg	;;
3661a253d6aeSmrg
3662a253d6aeSmrg      -prefer-pic)
3663a253d6aeSmrg	pic_mode=yes
3664a253d6aeSmrg	continue
3665a253d6aeSmrg	;;
3666a253d6aeSmrg
3667a253d6aeSmrg      -prefer-non-pic)
3668a253d6aeSmrg	pic_mode=no
3669a253d6aeSmrg	continue
3670a253d6aeSmrg	;;
3671a253d6aeSmrg      esac
3672a253d6aeSmrg    done
3673a253d6aeSmrg
3674b41a30aaSmrg    func_quote_arg pretty "$libobj"
3675b41a30aaSmrg    test "X$libobj" != "X$func_quote_arg_result" \
3676ea133fd7Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677b41a30aaSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3678ea133fd7Smrg    func_dirname_and_basename "$obj" "/" ""
3679b41a30aaSmrg    objname=$func_basename_result
3680b41a30aaSmrg    xdir=$func_dirname_result
3681b41a30aaSmrg    lobj=$xdir$objdir/$objname
3682a253d6aeSmrg
3683ea133fd7Smrg    test -z "$base_compile" && \
3684ea133fd7Smrg      func_fatal_help "you must specify a compilation command"
3685a253d6aeSmrg
3686a253d6aeSmrg    # Delete any leftover library objects.
3687b41a30aaSmrg    if test yes = "$build_old_libs"; then
3688a253d6aeSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3689a253d6aeSmrg    else
3690a253d6aeSmrg      removelist="$lobj $libobj ${libobj}T"
3691a253d6aeSmrg    fi
3692a253d6aeSmrg
3693a253d6aeSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3694a253d6aeSmrg    case $host_os in
3695ea133fd7Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3696a253d6aeSmrg      pic_mode=default
3697a253d6aeSmrg      ;;
3698a253d6aeSmrg    esac
3699b41a30aaSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3700a253d6aeSmrg      # non-PIC code in shared libraries is not supported
3701a253d6aeSmrg      pic_mode=default
3702a253d6aeSmrg    fi
3703a253d6aeSmrg
3704a253d6aeSmrg    # Calculate the filename of the output object if compiler does
3705a253d6aeSmrg    # not support -o with -c
3706b41a30aaSmrg    if test no = "$compiler_c_o"; then
3707b41a30aaSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708b41a30aaSmrg      lockfile=$output_obj.lock
3709a253d6aeSmrg    else
3710a253d6aeSmrg      output_obj=
3711a253d6aeSmrg      need_locks=no
3712a253d6aeSmrg      lockfile=
3713a253d6aeSmrg    fi
3714a253d6aeSmrg
3715a253d6aeSmrg    # Lock this critical section if it is needed
3716a253d6aeSmrg    # We use this script file to make the link, it avoids creating a new file
3717b41a30aaSmrg    if test yes = "$need_locks"; then
3718ea133fd7Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3719ea133fd7Smrg	func_echo "Waiting for $lockfile to be removed"
3720a253d6aeSmrg	sleep 2
3721a253d6aeSmrg      done
3722b41a30aaSmrg    elif test warn = "$need_locks"; then
3723a253d6aeSmrg      if test -f "$lockfile"; then
3724ea133fd7Smrg	$ECHO "\
3725a253d6aeSmrg*** ERROR, $lockfile exists and contains:
3726a253d6aeSmrg`cat $lockfile 2>/dev/null`
3727a253d6aeSmrg
3728a253d6aeSmrgThis indicates that another process is trying to use the same
3729a253d6aeSmrgtemporary object file, and libtool could not work around it because
3730b41a30aaSmrgyour compiler does not support '-c' and '-o' together.  If you
3731a253d6aeSmrgrepeat this compilation, it may succeed, by chance, but you had better
3732a253d6aeSmrgavoid parallel builds (make -j) in this platform, or get a better
3733a253d6aeSmrgcompiler."
3734a253d6aeSmrg
3735ea133fd7Smrg	$opt_dry_run || $RM $removelist
3736a253d6aeSmrg	exit $EXIT_FAILURE
3737a253d6aeSmrg      fi
373806f32fbeSmrg      func_append removelist " $output_obj"
3739ea133fd7Smrg      $ECHO "$srcfile" > "$lockfile"
3740a253d6aeSmrg    fi
3741a253d6aeSmrg
3742ea133fd7Smrg    $opt_dry_run || $RM $removelist
374306f32fbeSmrg    func_append removelist " $lockfile"
3744ea133fd7Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3745ea133fd7Smrg
374606f32fbeSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
374706f32fbeSmrg    srcfile=$func_to_tool_file_result
3748b41a30aaSmrg    func_quote_arg pretty "$srcfile"
3749b41a30aaSmrg    qsrcfile=$func_quote_arg_result
3750a253d6aeSmrg
3751a253d6aeSmrg    # Only build a PIC object if we are building libtool libraries.
3752b41a30aaSmrg    if test yes = "$build_libtool_libs"; then
3753a253d6aeSmrg      # Without this assignment, base_compile gets emptied.
3754a253d6aeSmrg      fbsd_hideous_sh_bug=$base_compile
3755a253d6aeSmrg
3756b41a30aaSmrg      if test no != "$pic_mode"; then
3757a253d6aeSmrg	command="$base_compile $qsrcfile $pic_flag"
3758a253d6aeSmrg      else
3759a253d6aeSmrg	# Don't build PIC code
3760a253d6aeSmrg	command="$base_compile $qsrcfile"
3761a253d6aeSmrg      fi
3762a253d6aeSmrg
3763ea133fd7Smrg      func_mkdir_p "$xdir$objdir"
3764a253d6aeSmrg
3765a253d6aeSmrg      if test -z "$output_obj"; then
3766a253d6aeSmrg	# Place PIC objects in $objdir
376706f32fbeSmrg	func_append command " -o $lobj"
3768a253d6aeSmrg      fi
3769a253d6aeSmrg
3770ea133fd7Smrg      func_show_eval_locale "$command"	\
3771ea133fd7Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3772a253d6aeSmrg
3773b41a30aaSmrg      if test warn = "$need_locks" &&
3774a253d6aeSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3775ea133fd7Smrg	$ECHO "\
3776a253d6aeSmrg*** ERROR, $lockfile contains:
3777a253d6aeSmrg`cat $lockfile 2>/dev/null`
3778a253d6aeSmrg
3779a253d6aeSmrgbut it should contain:
3780a253d6aeSmrg$srcfile
3781a253d6aeSmrg
3782a253d6aeSmrgThis indicates that another process is trying to use the same
3783a253d6aeSmrgtemporary object file, and libtool could not work around it because
3784b41a30aaSmrgyour compiler does not support '-c' and '-o' together.  If you
3785a253d6aeSmrgrepeat this compilation, it may succeed, by chance, but you had better
3786a253d6aeSmrgavoid parallel builds (make -j) in this platform, or get a better
3787a253d6aeSmrgcompiler."
3788a253d6aeSmrg
3789ea133fd7Smrg	$opt_dry_run || $RM $removelist
3790a253d6aeSmrg	exit $EXIT_FAILURE
3791a253d6aeSmrg      fi
3792a253d6aeSmrg
3793a253d6aeSmrg      # Just move the object if needed, then go on to compile the next one
3794a253d6aeSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3795ea133fd7Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3796ea133fd7Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3797a253d6aeSmrg      fi
3798a253d6aeSmrg
3799a253d6aeSmrg      # Allow error messages only from the first compilation.
3800b41a30aaSmrg      if test yes = "$suppress_opt"; then
3801ea133fd7Smrg	suppress_output=' >/dev/null 2>&1'
3802a253d6aeSmrg      fi
3803a253d6aeSmrg    fi
3804a253d6aeSmrg
3805a253d6aeSmrg    # Only build a position-dependent object if we build old libraries.
3806b41a30aaSmrg    if test yes = "$build_old_libs"; then
3807b41a30aaSmrg      if test yes != "$pic_mode"; then
3808a253d6aeSmrg	# Don't build PIC code
3809ea133fd7Smrg	command="$base_compile $qsrcfile$pie_flag"
3810a253d6aeSmrg      else
3811a253d6aeSmrg	command="$base_compile $qsrcfile $pic_flag"
3812a253d6aeSmrg      fi
3813b41a30aaSmrg      if test yes = "$compiler_c_o"; then
381406f32fbeSmrg	func_append command " -o $obj"
3815a253d6aeSmrg      fi
3816a253d6aeSmrg
3817a253d6aeSmrg      # Suppress compiler output if we already did a PIC compilation.
381806f32fbeSmrg      func_append command "$suppress_output"
3819ea133fd7Smrg      func_show_eval_locale "$command" \
3820ea133fd7Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3821a253d6aeSmrg
3822b41a30aaSmrg      if test warn = "$need_locks" &&
3823a253d6aeSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3824ea133fd7Smrg	$ECHO "\
3825a253d6aeSmrg*** ERROR, $lockfile contains:
3826a253d6aeSmrg`cat $lockfile 2>/dev/null`
3827a253d6aeSmrg
3828a253d6aeSmrgbut it should contain:
3829a253d6aeSmrg$srcfile
3830a253d6aeSmrg
3831a253d6aeSmrgThis indicates that another process is trying to use the same
3832a253d6aeSmrgtemporary object file, and libtool could not work around it because
3833b41a30aaSmrgyour compiler does not support '-c' and '-o' together.  If you
3834a253d6aeSmrgrepeat this compilation, it may succeed, by chance, but you had better
3835a253d6aeSmrgavoid parallel builds (make -j) in this platform, or get a better
3836a253d6aeSmrgcompiler."
3837a253d6aeSmrg
3838ea133fd7Smrg	$opt_dry_run || $RM $removelist
3839a253d6aeSmrg	exit $EXIT_FAILURE
3840a253d6aeSmrg      fi
3841a253d6aeSmrg
3842a253d6aeSmrg      # Just move the object if needed
3843a253d6aeSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3844ea133fd7Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3845ea133fd7Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3846a253d6aeSmrg      fi
3847a253d6aeSmrg    fi
3848a253d6aeSmrg
3849ea133fd7Smrg    $opt_dry_run || {
3850ea133fd7Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851a253d6aeSmrg
3852ea133fd7Smrg      # Unlock the critical section if it was locked
3853b41a30aaSmrg      if test no != "$need_locks"; then
3854ea133fd7Smrg	removelist=$lockfile
3855ea133fd7Smrg        $RM "$lockfile"
3856ea133fd7Smrg      fi
3857ea133fd7Smrg    }
3858a253d6aeSmrg
3859a253d6aeSmrg    exit $EXIT_SUCCESS
3860ea133fd7Smrg}
3861a253d6aeSmrg
3862ea133fd7Smrg$opt_help || {
3863b41a30aaSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3864ea133fd7Smrg}
3865a253d6aeSmrg
3866ea133fd7Smrgfunc_mode_help ()
3867ea133fd7Smrg{
3868ea133fd7Smrg    # We need to display help for each of the modes.
386906f32fbeSmrg    case $opt_mode in
3870ea133fd7Smrg      "")
3871ea133fd7Smrg        # Generic help is extracted from the usage comments
3872ea133fd7Smrg        # at the start of this file.
3873ea133fd7Smrg        func_help
3874ea133fd7Smrg        ;;
3875a253d6aeSmrg
3876ea133fd7Smrg      clean)
3877ea133fd7Smrg        $ECHO \
3878ea133fd7Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879a253d6aeSmrg
3880ea133fd7SmrgRemove files from the build directory.
3881a253d6aeSmrg
3882ea133fd7SmrgRM is the name of the program to use to delete files associated with each FILE
3883b41a30aaSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3884ea133fd7Smrgto RM.
3885a253d6aeSmrg
3886ea133fd7SmrgIf FILE is a libtool library, object or program, all the files associated
3887ea133fd7Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3888ea133fd7Smrg        ;;
3889a253d6aeSmrg
3890ea133fd7Smrg      compile)
3891ea133fd7Smrg      $ECHO \
3892ea133fd7Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893a253d6aeSmrg
3894ea133fd7SmrgCompile a source file into a libtool library object.
3895a253d6aeSmrg
3896ea133fd7SmrgThis mode accepts the following additional options:
3897a253d6aeSmrg
3898ea133fd7Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3899ea133fd7Smrg  -no-suppress      do not suppress compiler output for multiple passes
390025b89263Smrg  -prefer-pic       try to build PIC objects only
390125b89263Smrg  -prefer-non-pic   try to build non-PIC objects only
3902b41a30aaSmrg  -shared           do not build a '.o' file suitable for static linking
3903b41a30aaSmrg  -static           only build a '.o' file suitable for static linking
3904b41a30aaSmrg  -Wc,FLAG
3905b41a30aaSmrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906a253d6aeSmrg
3907b41a30aaSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3908ea133fd7Smrgfrom the given SOURCEFILE.
3909a253d6aeSmrg
3910ea133fd7SmrgThe output file name is determined by removing the directory component from
3911b41a30aaSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912b41a30aaSmrglibrary object suffix, '.lo'."
3913ea133fd7Smrg        ;;
3914a253d6aeSmrg
3915ea133fd7Smrg      execute)
3916ea133fd7Smrg        $ECHO \
3917ea133fd7Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3918a253d6aeSmrg
3919ea133fd7SmrgAutomatically set library path, then run a program.
3920a253d6aeSmrg
3921ea133fd7SmrgThis mode accepts the following additional options:
3922a253d6aeSmrg
3923ea133fd7Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924a253d6aeSmrg
3925b41a30aaSmrgThis mode sets the library path environment variable according to '-dlopen'
3926ea133fd7Smrgflags.
3927a253d6aeSmrg
3928ea133fd7SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3929ea133fd7Smrginto their corresponding uninstalled binary, and any of their required library
3930ea133fd7Smrgdirectories are added to the library path.
3931a253d6aeSmrg
3932ea133fd7SmrgThen, COMMAND is executed, with ARGS as arguments."
3933ea133fd7Smrg        ;;
3934a253d6aeSmrg
3935ea133fd7Smrg      finish)
3936ea133fd7Smrg        $ECHO \
3937ea133fd7Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938a253d6aeSmrg
3939ea133fd7SmrgComplete the installation of libtool libraries.
3940a253d6aeSmrg
3941ea133fd7SmrgEach LIBDIR is a directory that contains libtool libraries.
3942a253d6aeSmrg
3943ea133fd7SmrgThe commands that this mode executes may require superuser privileges.  Use
3944b41a30aaSmrgthe '--dry-run' option if you just want to see what would be executed."
3945ea133fd7Smrg        ;;
3946a253d6aeSmrg
3947ea133fd7Smrg      install)
3948ea133fd7Smrg        $ECHO \
3949ea133fd7Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3950a253d6aeSmrg
3951ea133fd7SmrgInstall executables or libraries.
3952a253d6aeSmrg
3953ea133fd7SmrgINSTALL-COMMAND is the installation command.  The first component should be
3954b41a30aaSmrgeither the 'install' or 'cp' program.
3955a253d6aeSmrg
3956ea133fd7SmrgThe following components of INSTALL-COMMAND are treated specially:
3957a253d6aeSmrg
395825b89263Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3959a253d6aeSmrg
3960ea133fd7SmrgThe rest of the components are interpreted as arguments to that command (only
3961ea133fd7SmrgBSD-compatible install options are recognized)."
3962ea133fd7Smrg        ;;
3963a253d6aeSmrg
3964ea133fd7Smrg      link)
3965ea133fd7Smrg        $ECHO \
3966ea133fd7Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3967a253d6aeSmrg
3968ea133fd7SmrgLink object files or libraries together to form another library, or to
3969ea133fd7Smrgcreate an executable program.
3970a253d6aeSmrg
3971ea133fd7SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3972ea133fd7Smrga program from several object files.
3973a253d6aeSmrg
3974ea133fd7SmrgThe following components of LINK-COMMAND are treated specially:
3975a253d6aeSmrg
3976ea133fd7Smrg  -all-static       do not do any dynamic linking at all
3977ea133fd7Smrg  -avoid-version    do not add a version suffix if possible
397825b89263Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
397925b89263Smrg                    libraries must be found in the PATH setting at runtime)
3980b41a30aaSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3981ea133fd7Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3982ea133fd7Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3983ea133fd7Smrg  -export-symbols SYMFILE
3984ea133fd7Smrg                    try to export only the symbols listed in SYMFILE
3985ea133fd7Smrg  -export-symbols-regex REGEX
3986ea133fd7Smrg                    try to export only the symbols matching REGEX
3987ea133fd7Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3988ea133fd7Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3989ea133fd7Smrg  -module           build a library that can dlopened
3990ea133fd7Smrg  -no-fast-install  disable the fast-install mode
3991ea133fd7Smrg  -no-install       link a not-installable executable
3992ea133fd7Smrg  -no-undefined     declare that a library does not refer to external symbols
3993ea133fd7Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994b41a30aaSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995b41a30aaSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3996ea133fd7Smrg  -precious-files-regex REGEX
3997ea133fd7Smrg                    don't remove output files matching REGEX
3998ea133fd7Smrg  -release RELEASE  specify package release information
3999ea133fd7Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4000ea133fd7Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4001ea133fd7Smrg  -shared           only do dynamic linking of libtool libraries
4002ea133fd7Smrg  -shrext SUFFIX    override the standard shared library file extension
4003ea133fd7Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4004ea133fd7Smrg  -static-libtool-libs
4005ea133fd7Smrg                    do not do any dynamic linking of libtool libraries
4006ea133fd7Smrg  -version-info CURRENT[:REVISION[:AGE]]
4007ea133fd7Smrg                    specify library version info [each variable defaults to 0]
4008ea133fd7Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
400925b89263Smrg  -Wc,FLAG
401025b89263Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011b41a30aaSmrg  -Wa,FLAG
4012b41a30aaSmrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
401325b89263Smrg  -Wl,FLAG
401425b89263Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
401525b89263Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4016a253d6aeSmrg
4017b41a30aaSmrgAll other options (arguments beginning with '-') are ignored.
4018a253d6aeSmrg
4019b41a30aaSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4020ea133fd7Smrgtreated as uninstalled libtool libraries, other files are standard or library
4021ea133fd7Smrgobject files.
4022a253d6aeSmrg
4023b41a30aaSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024b41a30aaSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4025ea133fd7Smrgrequired, except when creating a convenience library.
4026a253d6aeSmrg
4027b41a30aaSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028b41a30aaSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4029a253d6aeSmrg
4030b41a30aaSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4031ea133fd7Smrgis created, otherwise an executable program is created."
4032a253d6aeSmrg        ;;
4033a253d6aeSmrg
4034ea133fd7Smrg      uninstall)
4035ea133fd7Smrg        $ECHO \
4036ea133fd7Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4037a253d6aeSmrg
4038ea133fd7SmrgRemove libraries from an installation directory.
4039a253d6aeSmrg
4040ea133fd7SmrgRM is the name of the program to use to delete files associated with each FILE
4041b41a30aaSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4042ea133fd7Smrgto RM.
4043a253d6aeSmrg
4044ea133fd7SmrgIf FILE is a libtool library, all the files associated with it are deleted.
4045ea133fd7SmrgOtherwise, only FILE itself is deleted using RM."
4046ea133fd7Smrg        ;;
4047a253d6aeSmrg
4048ea133fd7Smrg      *)
4049b41a30aaSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
4050ea133fd7Smrg        ;;
4051ea133fd7Smrg    esac
4052a253d6aeSmrg
405325b89263Smrg    echo
4054b41a30aaSmrg    $ECHO "Try '$progname --help' for more information about other modes."
4055ea133fd7Smrg}
4056a253d6aeSmrg
405725b89263Smrg# Now that we've collected a possible --mode arg, show help if necessary
405825b89263Smrgif $opt_help; then
4059b41a30aaSmrg  if test : = "$opt_help"; then
406025b89263Smrg    func_mode_help
406125b89263Smrg  else
406225b89263Smrg    {
406325b89263Smrg      func_help noexit
406406f32fbeSmrg      for opt_mode in compile link execute install finish uninstall clean; do
406525b89263Smrg	func_mode_help
406625b89263Smrg      done
4067b41a30aaSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
406825b89263Smrg    {
406925b89263Smrg      func_help noexit
407006f32fbeSmrg      for opt_mode in compile link execute install finish uninstall clean; do
407125b89263Smrg	echo
407225b89263Smrg	func_mode_help
407325b89263Smrg      done
407425b89263Smrg    } |
4075b41a30aaSmrg    $SED '1d
407625b89263Smrg      /^When reporting/,/^Report/{
407725b89263Smrg	H
407825b89263Smrg	d
407925b89263Smrg      }
408025b89263Smrg      $x
408125b89263Smrg      /information about other modes/d
408225b89263Smrg      /more detailed .*MODE/d
408325b89263Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
408425b89263Smrg  fi
408525b89263Smrg  exit $?
408625b89263Smrgfi
4087a253d6aeSmrg
4088a253d6aeSmrg
4089ea133fd7Smrg# func_mode_execute arg...
4090ea133fd7Smrgfunc_mode_execute ()
4091ea133fd7Smrg{
4092b41a30aaSmrg    $debug_cmd
4093b41a30aaSmrg
4094ea133fd7Smrg    # The first argument is the command name.
4095b41a30aaSmrg    cmd=$nonopt
4096ea133fd7Smrg    test -z "$cmd" && \
4097ea133fd7Smrg      func_fatal_help "you must specify a COMMAND"
4098a253d6aeSmrg
4099ea133fd7Smrg    # Handle -dlopen flags immediately.
410006f32fbeSmrg    for file in $opt_dlopen; do
4101ea133fd7Smrg      test -f "$file" \
4102b41a30aaSmrg	|| func_fatal_help "'$file' is not a file"
4103a253d6aeSmrg
4104ea133fd7Smrg      dir=
4105ea133fd7Smrg      case $file in
4106ea133fd7Smrg      *.la)
410706f32fbeSmrg	func_resolve_sysroot "$file"
410806f32fbeSmrg	file=$func_resolve_sysroot_result
410906f32fbeSmrg
4110ea133fd7Smrg	# Check to see that this really is a libtool archive.
4111ea133fd7Smrg	func_lalib_unsafe_p "$file" \
4112b41a30aaSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113a253d6aeSmrg
4114ea133fd7Smrg	# Read the libtool library.
4115ea133fd7Smrg	dlname=
4116ea133fd7Smrg	library_names=
4117ea133fd7Smrg	func_source "$file"
4118a253d6aeSmrg
4119ea133fd7Smrg	# Skip this library if it cannot be dlopened.
4120ea133fd7Smrg	if test -z "$dlname"; then
4121ea133fd7Smrg	  # Warn if it was a shared library.
4122ea133fd7Smrg	  test -n "$library_names" && \
4123b41a30aaSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4124ea133fd7Smrg	  continue
4125ea133fd7Smrg	fi
4126a253d6aeSmrg
4127ea133fd7Smrg	func_dirname "$file" "" "."
4128b41a30aaSmrg	dir=$func_dirname_result
4129a253d6aeSmrg
4130ea133fd7Smrg	if test -f "$dir/$objdir/$dlname"; then
413106f32fbeSmrg	  func_append dir "/$objdir"
4132ea133fd7Smrg	else
4133ea133fd7Smrg	  if test ! -f "$dir/$dlname"; then
4134b41a30aaSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4135ea133fd7Smrg	  fi
4136ea133fd7Smrg	fi
4137a253d6aeSmrg	;;
4138a253d6aeSmrg
4139ea133fd7Smrg      *.lo)
4140ea133fd7Smrg	# Just add the directory containing the .lo file.
4141ea133fd7Smrg	func_dirname "$file" "" "."
4142b41a30aaSmrg	dir=$func_dirname_result
4143a253d6aeSmrg	;;
4144a253d6aeSmrg
4145ea133fd7Smrg      *)
4146b41a30aaSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147a253d6aeSmrg	continue
4148a253d6aeSmrg	;;
4149ea133fd7Smrg      esac
4150a253d6aeSmrg
4151ea133fd7Smrg      # Get the absolute pathname.
4152ea133fd7Smrg      absdir=`cd "$dir" && pwd`
4153b41a30aaSmrg      test -n "$absdir" && dir=$absdir
4154a253d6aeSmrg
4155ea133fd7Smrg      # Now add the directory to shlibpath_var.
4156ea133fd7Smrg      if eval "test -z \"\$$shlibpath_var\""; then
4157ea133fd7Smrg	eval "$shlibpath_var=\"\$dir\""
4158ea133fd7Smrg      else
4159ea133fd7Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4160ea133fd7Smrg      fi
4161ea133fd7Smrg    done
4162a253d6aeSmrg
4163ea133fd7Smrg    # This variable tells wrapper scripts just to set shlibpath_var
4164ea133fd7Smrg    # rather than running their programs.
4165b41a30aaSmrg    libtool_execute_magic=$magic
4166a253d6aeSmrg
4167ea133fd7Smrg    # Check if any of the arguments is a wrapper script.
4168ea133fd7Smrg    args=
4169ea133fd7Smrg    for file
4170ea133fd7Smrg    do
4171ea133fd7Smrg      case $file in
417225b89263Smrg      -* | *.la | *.lo ) ;;
4173ea133fd7Smrg      *)
4174ea133fd7Smrg	# Do a test to see if this is really a libtool program.
4175ea133fd7Smrg	if func_ltwrapper_script_p "$file"; then
4176ea133fd7Smrg	  func_source "$file"
4177ea133fd7Smrg	  # Transform arg to wrapped name.
4178b41a30aaSmrg	  file=$progdir/$program
4179ea133fd7Smrg	elif func_ltwrapper_executable_p "$file"; then
4180ea133fd7Smrg	  func_ltwrapper_scriptname "$file"
4181ea133fd7Smrg	  func_source "$func_ltwrapper_scriptname_result"
4182ea133fd7Smrg	  # Transform arg to wrapped name.
4183b41a30aaSmrg	  file=$progdir/$program
4184ea133fd7Smrg	fi
4185ea133fd7Smrg	;;
4186ea133fd7Smrg      esac
4187ea133fd7Smrg      # Quote arguments (to preserve shell metacharacters).
418806f32fbeSmrg      func_append_quoted args "$file"
4189ea133fd7Smrg    done
4190a253d6aeSmrg
4191b41a30aaSmrg    if $opt_dry_run; then
4192b41a30aaSmrg      # Display what would be done.
4193b41a30aaSmrg      if test -n "$shlibpath_var"; then
4194b41a30aaSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195b41a30aaSmrg	echo "export $shlibpath_var"
4196b41a30aaSmrg      fi
4197b41a30aaSmrg      $ECHO "$cmd$args"
4198b41a30aaSmrg      exit $EXIT_SUCCESS
4199b41a30aaSmrg    else
4200ea133fd7Smrg      if test -n "$shlibpath_var"; then
4201ea133fd7Smrg	# Export the shlibpath_var.
4202ea133fd7Smrg	eval "export $shlibpath_var"
4203ea133fd7Smrg      fi
4204a253d6aeSmrg
4205ea133fd7Smrg      # Restore saved environment variables
4206ea133fd7Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4207ea133fd7Smrg      do
4208ea133fd7Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4209ea133fd7Smrg                $lt_var=\$save_$lt_var; export $lt_var
4210ea133fd7Smrg	      else
4211ea133fd7Smrg		$lt_unset $lt_var
4212ea133fd7Smrg	      fi"
4213ea133fd7Smrg      done
4214a253d6aeSmrg
4215ea133fd7Smrg      # Now prepare to actually exec the command.
4216b41a30aaSmrg      exec_cmd=\$cmd$args
4217ea133fd7Smrg    fi
4218ea133fd7Smrg}
4219a253d6aeSmrg
4220b41a30aaSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4221a253d6aeSmrg
4222a253d6aeSmrg
4223ea133fd7Smrg# func_mode_finish arg...
4224ea133fd7Smrgfunc_mode_finish ()
4225ea133fd7Smrg{
4226b41a30aaSmrg    $debug_cmd
4227b41a30aaSmrg
422806f32fbeSmrg    libs=
422906f32fbeSmrg    libdirs=
4230ea133fd7Smrg    admincmds=
4231a253d6aeSmrg
423206f32fbeSmrg    for opt in "$nonopt" ${1+"$@"}
423306f32fbeSmrg    do
423406f32fbeSmrg      if test -d "$opt"; then
423506f32fbeSmrg	func_append libdirs " $opt"
423606f32fbeSmrg
423706f32fbeSmrg      elif test -f "$opt"; then
423806f32fbeSmrg	if func_lalib_unsafe_p "$opt"; then
423906f32fbeSmrg	  func_append libs " $opt"
424006f32fbeSmrg	else
4241b41a30aaSmrg	  func_warning "'$opt' is not a valid libtool archive"
424206f32fbeSmrg	fi
424306f32fbeSmrg
424406f32fbeSmrg      else
4245b41a30aaSmrg	func_fatal_error "invalid argument '$opt'"
424606f32fbeSmrg      fi
424706f32fbeSmrg    done
424806f32fbeSmrg
424906f32fbeSmrg    if test -n "$libs"; then
425006f32fbeSmrg      if test -n "$lt_sysroot"; then
425106f32fbeSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
425206f32fbeSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
425306f32fbeSmrg      else
425406f32fbeSmrg        sysroot_cmd=
425506f32fbeSmrg      fi
425606f32fbeSmrg
425706f32fbeSmrg      # Remove sysroot references
425806f32fbeSmrg      if $opt_dry_run; then
425906f32fbeSmrg        for lib in $libs; do
4260b41a30aaSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
426106f32fbeSmrg        done
426206f32fbeSmrg      else
426306f32fbeSmrg        tmpdir=`func_mktempdir`
426406f32fbeSmrg        for lib in $libs; do
4265b41a30aaSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
426606f32fbeSmrg	    > $tmpdir/tmp-la
426706f32fbeSmrg	  mv -f $tmpdir/tmp-la $lib
426806f32fbeSmrg	done
426906f32fbeSmrg        ${RM}r "$tmpdir"
427006f32fbeSmrg      fi
427106f32fbeSmrg    fi
4272a253d6aeSmrg
427306f32fbeSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4274ea133fd7Smrg      for libdir in $libdirs; do
4275ea133fd7Smrg	if test -n "$finish_cmds"; then
4276ea133fd7Smrg	  # Do each command in the finish commands.
4277ea133fd7Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4278ea133fd7Smrg'"$cmd"'"'
4279ea133fd7Smrg	fi
4280ea133fd7Smrg	if test -n "$finish_eval"; then
4281ea133fd7Smrg	  # Do the single finish_eval.
4282ea133fd7Smrg	  eval cmds=\"$finish_eval\"
428306f32fbeSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4284ea133fd7Smrg       $cmds"
4285ea133fd7Smrg	fi
4286ea133fd7Smrg      done
4287ea133fd7Smrg    fi
4288a253d6aeSmrg
4289ea133fd7Smrg    # Exit here if they wanted silent mode.
4290b41a30aaSmrg    $opt_quiet && exit $EXIT_SUCCESS
4291a253d6aeSmrg
429206f32fbeSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
429306f32fbeSmrg      echo "----------------------------------------------------------------------"
429406f32fbeSmrg      echo "Libraries have been installed in:"
429506f32fbeSmrg      for libdir in $libdirs; do
429606f32fbeSmrg	$ECHO "   $libdir"
429706f32fbeSmrg      done
429806f32fbeSmrg      echo
429906f32fbeSmrg      echo "If you ever happen to want to link against installed libraries"
430006f32fbeSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301b41a30aaSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
430206f32fbeSmrg      echo "flag during linking and do at least one of the following:"
430306f32fbeSmrg      if test -n "$shlibpath_var"; then
4304b41a30aaSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
430506f32fbeSmrg	echo "     during execution"
430606f32fbeSmrg      fi
430706f32fbeSmrg      if test -n "$runpath_var"; then
4308b41a30aaSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
430906f32fbeSmrg	echo "     during linking"
431006f32fbeSmrg      fi
431106f32fbeSmrg      if test -n "$hardcode_libdir_flag_spec"; then
431206f32fbeSmrg	libdir=LIBDIR
431306f32fbeSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
4314a253d6aeSmrg
4315b41a30aaSmrg	$ECHO "   - use the '$flag' linker flag"
431606f32fbeSmrg      fi
431706f32fbeSmrg      if test -n "$admincmds"; then
431806f32fbeSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
431906f32fbeSmrg      fi
432006f32fbeSmrg      if test -f /etc/ld.so.conf; then
4321b41a30aaSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
432206f32fbeSmrg      fi
432306f32fbeSmrg      echo
4324a253d6aeSmrg
432506f32fbeSmrg      echo "See any operating system documentation about shared libraries for"
432606f32fbeSmrg      case $host in
432706f32fbeSmrg	solaris2.[6789]|solaris2.1[0-9])
432806f32fbeSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
432906f32fbeSmrg	  echo "pages."
433006f32fbeSmrg	  ;;
433106f32fbeSmrg	*)
433206f32fbeSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
433306f32fbeSmrg	  ;;
433406f32fbeSmrg      esac
433506f32fbeSmrg      echo "----------------------------------------------------------------------"
433606f32fbeSmrg    fi
4337ea133fd7Smrg    exit $EXIT_SUCCESS
4338ea133fd7Smrg}
4339a253d6aeSmrg
4340b41a30aaSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4341a253d6aeSmrg
4342a253d6aeSmrg
4343ea133fd7Smrg# func_mode_install arg...
4344ea133fd7Smrgfunc_mode_install ()
4345ea133fd7Smrg{
4346b41a30aaSmrg    $debug_cmd
4347b41a30aaSmrg
4348ea133fd7Smrg    # There may be an optional sh(1) argument at the beginning of
4349ea133fd7Smrg    # install_prog (especially on Windows NT).
4350b41a30aaSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4351ea133fd7Smrg       # Allow the use of GNU shtool's install command.
4352b41a30aaSmrg       case $nonopt in *shtool*) :;; *) false;; esac
4353b41a30aaSmrg    then
4354ea133fd7Smrg      # Aesthetically quote it.
4355b41a30aaSmrg      func_quote_arg pretty "$nonopt"
4356b41a30aaSmrg      install_prog="$func_quote_arg_result "
4357ea133fd7Smrg      arg=$1
4358ea133fd7Smrg      shift
4359ea133fd7Smrg    else
4360ea133fd7Smrg      install_prog=
4361ea133fd7Smrg      arg=$nonopt
4362ea133fd7Smrg    fi
4363a253d6aeSmrg
4364ea133fd7Smrg    # The real first argument should be the name of the installation program.
4365ea133fd7Smrg    # Aesthetically quote it.
4366b41a30aaSmrg    func_quote_arg pretty "$arg"
4367b41a30aaSmrg    func_append install_prog "$func_quote_arg_result"
436825b89263Smrg    install_shared_prog=$install_prog
436925b89263Smrg    case " $install_prog " in
437025b89263Smrg      *[\\\ /]cp\ *) install_cp=: ;;
437125b89263Smrg      *) install_cp=false ;;
437225b89263Smrg    esac
4373ea133fd7Smrg
4374ea133fd7Smrg    # We need to accept at least all the BSD install flags.
4375ea133fd7Smrg    dest=
4376ea133fd7Smrg    files=
4377ea133fd7Smrg    opts=
4378ea133fd7Smrg    prev=
4379ea133fd7Smrg    install_type=
4380b41a30aaSmrg    isdir=false
4381ea133fd7Smrg    stripme=
438225b89263Smrg    no_mode=:
4383ea133fd7Smrg    for arg
4384ea133fd7Smrg    do
438525b89263Smrg      arg2=
4386ea133fd7Smrg      if test -n "$dest"; then
438706f32fbeSmrg	func_append files " $dest"
4388ea133fd7Smrg	dest=$arg
4389ea133fd7Smrg	continue
4390a253d6aeSmrg      fi
4391a253d6aeSmrg
4392ea133fd7Smrg      case $arg in
4393b41a30aaSmrg      -d) isdir=: ;;
4394ea133fd7Smrg      -f)
439525b89263Smrg	if $install_cp; then :; else
439625b89263Smrg	  prev=$arg
439725b89263Smrg	fi
4398ea133fd7Smrg	;;
4399ea133fd7Smrg      -g | -m | -o)
4400ea133fd7Smrg	prev=$arg
4401ea133fd7Smrg	;;
4402ea133fd7Smrg      -s)
4403ea133fd7Smrg	stripme=" -s"
4404ea133fd7Smrg	continue
4405ea133fd7Smrg	;;
4406ea133fd7Smrg      -*)
4407ea133fd7Smrg	;;
4408ea133fd7Smrg      *)
4409ea133fd7Smrg	# If the previous option needed an argument, then skip it.
4410ea133fd7Smrg	if test -n "$prev"; then
4411b41a30aaSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
441225b89263Smrg	    arg2=$install_override_mode
441325b89263Smrg	    no_mode=false
441425b89263Smrg	  fi
4415ea133fd7Smrg	  prev=
4416ea133fd7Smrg	else
4417ea133fd7Smrg	  dest=$arg
4418ea133fd7Smrg	  continue
4419ea133fd7Smrg	fi
4420ea133fd7Smrg	;;
4421ea133fd7Smrg      esac
4422a253d6aeSmrg
4423ea133fd7Smrg      # Aesthetically quote the argument.
4424b41a30aaSmrg      func_quote_arg pretty "$arg"
4425b41a30aaSmrg      func_append install_prog " $func_quote_arg_result"
442625b89263Smrg      if test -n "$arg2"; then
4427b41a30aaSmrg	func_quote_arg pretty "$arg2"
442825b89263Smrg      fi
4429b41a30aaSmrg      func_append install_shared_prog " $func_quote_arg_result"
4430ea133fd7Smrg    done
4431a253d6aeSmrg
4432ea133fd7Smrg    test -z "$install_prog" && \
4433ea133fd7Smrg      func_fatal_help "you must specify an install program"
4434a253d6aeSmrg
4435ea133fd7Smrg    test -n "$prev" && \
4436b41a30aaSmrg      func_fatal_help "the '$prev' option requires an argument"
4437a253d6aeSmrg
443825b89263Smrg    if test -n "$install_override_mode" && $no_mode; then
443925b89263Smrg      if $install_cp; then :; else
4440b41a30aaSmrg	func_quote_arg pretty "$install_override_mode"
4441b41a30aaSmrg	func_append install_shared_prog " -m $func_quote_arg_result"
444225b89263Smrg      fi
444325b89263Smrg    fi
444425b89263Smrg
4445ea133fd7Smrg    if test -z "$files"; then
4446ea133fd7Smrg      if test -z "$dest"; then
4447ea133fd7Smrg	func_fatal_help "no file or destination specified"
4448ea133fd7Smrg      else
4449ea133fd7Smrg	func_fatal_help "you must specify a destination"
4450a253d6aeSmrg      fi
4451a253d6aeSmrg    fi
4452a253d6aeSmrg
4453ea133fd7Smrg    # Strip any trailing slash from the destination.
4454ea133fd7Smrg    func_stripname '' '/' "$dest"
4455ea133fd7Smrg    dest=$func_stripname_result
4456a253d6aeSmrg
4457ea133fd7Smrg    # Check to see that the destination is a directory.
4458b41a30aaSmrg    test -d "$dest" && isdir=:
4459b41a30aaSmrg    if $isdir; then
4460b41a30aaSmrg      destdir=$dest
4461ea133fd7Smrg      destname=
4462ea133fd7Smrg    else
4463ea133fd7Smrg      func_dirname_and_basename "$dest" "" "."
4464b41a30aaSmrg      destdir=$func_dirname_result
4465b41a30aaSmrg      destname=$func_basename_result
4466ea133fd7Smrg
4467ea133fd7Smrg      # Not a directory, so check to see that there is only one file specified.
4468ea133fd7Smrg      set dummy $files; shift
4469ea133fd7Smrg      test "$#" -gt 1 && \
4470b41a30aaSmrg	func_fatal_help "'$dest' is not a directory"
4471ea133fd7Smrg    fi
4472ea133fd7Smrg    case $destdir in
4473ea133fd7Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474a253d6aeSmrg    *)
4475ea133fd7Smrg      for file in $files; do
4476ea133fd7Smrg	case $file in
4477ea133fd7Smrg	*.lo) ;;
4478ea133fd7Smrg	*)
4479b41a30aaSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4480ea133fd7Smrg	  ;;
4481ea133fd7Smrg	esac
4482ea133fd7Smrg      done
4483a253d6aeSmrg      ;;
4484a253d6aeSmrg    esac
4485a253d6aeSmrg
4486ea133fd7Smrg    # This variable tells wrapper scripts just to set variables rather
4487ea133fd7Smrg    # than running their programs.
4488b41a30aaSmrg    libtool_install_magic=$magic
4489a253d6aeSmrg
4490ea133fd7Smrg    staticlibs=
4491ea133fd7Smrg    future_libdirs=
4492ea133fd7Smrg    current_libdirs=
4493ea133fd7Smrg    for file in $files; do
4494a253d6aeSmrg
4495ea133fd7Smrg      # Do each installation.
4496ea133fd7Smrg      case $file in
4497ea133fd7Smrg      *.$libext)
4498ea133fd7Smrg	# Do the static libraries later.
449906f32fbeSmrg	func_append staticlibs " $file"
4500ea133fd7Smrg	;;
4501ea133fd7Smrg
4502ea133fd7Smrg      *.la)
450306f32fbeSmrg	func_resolve_sysroot "$file"
450406f32fbeSmrg	file=$func_resolve_sysroot_result
450506f32fbeSmrg
4506ea133fd7Smrg	# Check to see that this really is a libtool archive.
4507ea133fd7Smrg	func_lalib_unsafe_p "$file" \
4508b41a30aaSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4509ea133fd7Smrg
4510ea133fd7Smrg	library_names=
4511ea133fd7Smrg	old_library=
4512ea133fd7Smrg	relink_command=
4513ea133fd7Smrg	func_source "$file"
4514ea133fd7Smrg
4515ea133fd7Smrg	# Add the libdir to current_libdirs if it is the destination.
4516ea133fd7Smrg	if test "X$destdir" = "X$libdir"; then
4517ea133fd7Smrg	  case "$current_libdirs " in
4518ea133fd7Smrg	  *" $libdir "*) ;;
451906f32fbeSmrg	  *) func_append current_libdirs " $libdir" ;;
4520a253d6aeSmrg	  esac
4521ea133fd7Smrg	else
4522ea133fd7Smrg	  # Note the libdir as a future libdir.
4523ea133fd7Smrg	  case "$future_libdirs " in
4524ea133fd7Smrg	  *" $libdir "*) ;;
452506f32fbeSmrg	  *) func_append future_libdirs " $libdir" ;;
4526ea133fd7Smrg	  esac
4527ea133fd7Smrg	fi
4528a253d6aeSmrg
4529ea133fd7Smrg	func_dirname "$file" "/" ""
4530b41a30aaSmrg	dir=$func_dirname_result
453106f32fbeSmrg	func_append dir "$objdir"
4532ea133fd7Smrg
4533ea133fd7Smrg	if test -n "$relink_command"; then
4534ea133fd7Smrg	  # Determine the prefix the user has applied to our future dir.
453525b89263Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4536ea133fd7Smrg
4537ea133fd7Smrg	  # Don't allow the user to place us outside of our expected
4538ea133fd7Smrg	  # location b/c this prevents finding dependent libraries that
4539ea133fd7Smrg	  # are installed to the same prefix.
4540ea133fd7Smrg	  # At present, this check doesn't affect windows .dll's that
4541ea133fd7Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4542ea133fd7Smrg	  # but it's something to keep an eye on.
4543ea133fd7Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4544b41a30aaSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4545ea133fd7Smrg
4546ea133fd7Smrg	  if test -n "$inst_prefix_dir"; then
4547ea133fd7Smrg	    # Stick the inst_prefix_dir data into the link command.
454825b89263Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4549ea133fd7Smrg	  else
455025b89263Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4551ea133fd7Smrg	  fi
4552ea133fd7Smrg
4553b41a30aaSmrg	  func_warning "relinking '$file'"
4554ea133fd7Smrg	  func_show_eval "$relink_command" \
4555b41a30aaSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4556ea133fd7Smrg	fi
4557ea133fd7Smrg
4558ea133fd7Smrg	# See the names of the shared library.
4559ea133fd7Smrg	set dummy $library_names; shift
4560ea133fd7Smrg	if test -n "$1"; then
4561b41a30aaSmrg	  realname=$1
4562ea133fd7Smrg	  shift
4563ea133fd7Smrg
4564b41a30aaSmrg	  srcname=$realname
4565b41a30aaSmrg	  test -n "$relink_command" && srcname=${realname}T
4566ea133fd7Smrg
4567ea133fd7Smrg	  # Install the shared library and build the symlinks.
456825b89263Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4569ea133fd7Smrg	      'exit $?'
4570b41a30aaSmrg	  tstripme=$stripme
4571ea133fd7Smrg	  case $host_os in
4572ea133fd7Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4573ea133fd7Smrg	    case $realname in
4574ea133fd7Smrg	    *.dll.a)
4575b41a30aaSmrg	      tstripme=
4576b41a30aaSmrg	      ;;
4577b41a30aaSmrg	    esac
4578b41a30aaSmrg	    ;;
4579b41a30aaSmrg	  os2*)
4580b41a30aaSmrg	    case $realname in
4581b41a30aaSmrg	    *_dll.a)
4582b41a30aaSmrg	      tstripme=
4583ea133fd7Smrg	      ;;
4584ea133fd7Smrg	    esac
4585a253d6aeSmrg	    ;;
4586a253d6aeSmrg	  esac
4587ea133fd7Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4588ea133fd7Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589a253d6aeSmrg	  fi
4590ea133fd7Smrg
4591ea133fd7Smrg	  if test "$#" -gt 0; then
4592ea133fd7Smrg	    # Delete the old symlinks, and create new ones.
4593b41a30aaSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4594ea133fd7Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4595ea133fd7Smrg	    # so we also need to try rm && ln -s.
4596ea133fd7Smrg	    for linkname
4597ea133fd7Smrg	    do
4598ea133fd7Smrg	      test "$linkname" != "$realname" \
4599ea133fd7Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600a253d6aeSmrg	    done
4601a253d6aeSmrg	  fi
4602a253d6aeSmrg
4603ea133fd7Smrg	  # Do each command in the postinstall commands.
4604b41a30aaSmrg	  lib=$destdir/$realname
4605ea133fd7Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4606a253d6aeSmrg	fi
4607a253d6aeSmrg
4608ea133fd7Smrg	# Install the pseudo-library for information purposes.
4609ea133fd7Smrg	func_basename "$file"
4610b41a30aaSmrg	name=$func_basename_result
4611b41a30aaSmrg	instname=$dir/${name}i
4612ea133fd7Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4613a253d6aeSmrg
4614ea133fd7Smrg	# Maybe install the static library, too.
461506f32fbeSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4616ea133fd7Smrg	;;
4617a253d6aeSmrg
4618ea133fd7Smrg      *.lo)
4619ea133fd7Smrg	# Install (i.e. copy) a libtool object.
4620a253d6aeSmrg
4621ea133fd7Smrg	# Figure out destination file name, if it wasn't already specified.
4622ea133fd7Smrg	if test -n "$destname"; then
4623b41a30aaSmrg	  destfile=$destdir/$destname
4624ea133fd7Smrg	else
4625ea133fd7Smrg	  func_basename "$file"
4626b41a30aaSmrg	  destfile=$func_basename_result
4627b41a30aaSmrg	  destfile=$destdir/$destfile
4628ea133fd7Smrg	fi
4629ea133fd7Smrg
4630ea133fd7Smrg	# Deduce the name of the destination old-style object file.
4631ea133fd7Smrg	case $destfile in
4632ea133fd7Smrg	*.lo)
4633ea133fd7Smrg	  func_lo2o "$destfile"
4634ea133fd7Smrg	  staticdest=$func_lo2o_result
4635ea133fd7Smrg	  ;;
4636ea133fd7Smrg	*.$objext)
4637b41a30aaSmrg	  staticdest=$destfile
4638ea133fd7Smrg	  destfile=
4639ea133fd7Smrg	  ;;
4640ea133fd7Smrg	*)
4641b41a30aaSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4642ea133fd7Smrg	  ;;
4643a253d6aeSmrg	esac
4644a253d6aeSmrg
4645ea133fd7Smrg	# Install the libtool object if requested.
4646ea133fd7Smrg	test -n "$destfile" && \
4647ea133fd7Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4648ea133fd7Smrg
4649ea133fd7Smrg	# Install the old object if enabled.
4650b41a30aaSmrg	if test yes = "$build_old_libs"; then
4651ea133fd7Smrg	  # Deduce the name of the old-style object file.
4652ea133fd7Smrg	  func_lo2o "$file"
4653ea133fd7Smrg	  staticobj=$func_lo2o_result
4654ea133fd7Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4655a253d6aeSmrg	fi
4656ea133fd7Smrg	exit $EXIT_SUCCESS
4657ea133fd7Smrg	;;
4658a253d6aeSmrg
4659ea133fd7Smrg      *)
4660ea133fd7Smrg	# Figure out destination file name, if it wasn't already specified.
4661ea133fd7Smrg	if test -n "$destname"; then
4662b41a30aaSmrg	  destfile=$destdir/$destname
4663ea133fd7Smrg	else
4664ea133fd7Smrg	  func_basename "$file"
4665b41a30aaSmrg	  destfile=$func_basename_result
4666b41a30aaSmrg	  destfile=$destdir/$destfile
4667ea133fd7Smrg	fi
4668ea133fd7Smrg
4669ea133fd7Smrg	# If the file is missing, and there is a .exe on the end, strip it
4670ea133fd7Smrg	# because it is most likely a libtool script we actually want to
4671ea133fd7Smrg	# install
4672b41a30aaSmrg	stripped_ext=
4673ea133fd7Smrg	case $file in
4674ea133fd7Smrg	  *.exe)
4675ea133fd7Smrg	    if test ! -f "$file"; then
4676ea133fd7Smrg	      func_stripname '' '.exe' "$file"
4677ea133fd7Smrg	      file=$func_stripname_result
4678b41a30aaSmrg	      stripped_ext=.exe
4679a253d6aeSmrg	    fi
4680ea133fd7Smrg	    ;;
4681ea133fd7Smrg	esac
4682a253d6aeSmrg
4683ea133fd7Smrg	# Do a test to see if this is really a libtool program.
4684ea133fd7Smrg	case $host in
4685ea133fd7Smrg	*cygwin* | *mingw*)
4686ea133fd7Smrg	    if func_ltwrapper_executable_p "$file"; then
4687ea133fd7Smrg	      func_ltwrapper_scriptname "$file"
4688ea133fd7Smrg	      wrapper=$func_ltwrapper_scriptname_result
4689ea133fd7Smrg	    else
4690ea133fd7Smrg	      func_stripname '' '.exe' "$file"
4691ea133fd7Smrg	      wrapper=$func_stripname_result
4692ea133fd7Smrg	    fi
4693ea133fd7Smrg	    ;;
4694ea133fd7Smrg	*)
4695ea133fd7Smrg	    wrapper=$file
4696ea133fd7Smrg	    ;;
4697ea133fd7Smrg	esac
4698ea133fd7Smrg	if func_ltwrapper_script_p "$wrapper"; then
4699ea133fd7Smrg	  notinst_deplibs=
4700ea133fd7Smrg	  relink_command=
4701a253d6aeSmrg
4702ea133fd7Smrg	  func_source "$wrapper"
4703a253d6aeSmrg
4704ea133fd7Smrg	  # Check the variables that should have been set.
4705ea133fd7Smrg	  test -z "$generated_by_libtool_version" && \
4706b41a30aaSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4707ea133fd7Smrg
4708b41a30aaSmrg	  finalize=:
4709ea133fd7Smrg	  for lib in $notinst_deplibs; do
4710ea133fd7Smrg	    # Check to see that each library is installed.
4711ea133fd7Smrg	    libdir=
4712ea133fd7Smrg	    if test -f "$lib"; then
4713ea133fd7Smrg	      func_source "$lib"
4714ea133fd7Smrg	    fi
4715b41a30aaSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4716ea133fd7Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717b41a30aaSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718b41a30aaSmrg	      finalize=false
4719ea133fd7Smrg	    fi
4720ea133fd7Smrg	  done
4721ea133fd7Smrg
4722ea133fd7Smrg	  relink_command=
4723ea133fd7Smrg	  func_source "$wrapper"
4724ea133fd7Smrg
4725ea133fd7Smrg	  outputname=
4726b41a30aaSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4727ea133fd7Smrg	    $opt_dry_run || {
4728b41a30aaSmrg	      if $finalize; then
4729ea133fd7Smrg	        tmpdir=`func_mktempdir`
4730ea133fd7Smrg		func_basename "$file$stripped_ext"
4731b41a30aaSmrg		file=$func_basename_result
4732b41a30aaSmrg	        outputname=$tmpdir/$file
4733ea133fd7Smrg	        # Replace the output file specification.
473425b89263Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4735ea133fd7Smrg
4736b41a30aaSmrg	        $opt_quiet || {
4737b41a30aaSmrg	          func_quote_arg expand,pretty "$relink_command"
4738b41a30aaSmrg		  eval "func_echo $func_quote_arg_result"
4739ea133fd7Smrg	        }
4740ea133fd7Smrg	        if eval "$relink_command"; then :
4741ea133fd7Smrg	          else
4742b41a30aaSmrg		  func_error "error: relink '$file' with the above command before installing it"
4743ea133fd7Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4744ea133fd7Smrg		  continue
4745ea133fd7Smrg	        fi
4746b41a30aaSmrg	        file=$outputname
4747ea133fd7Smrg	      else
4748b41a30aaSmrg	        func_warning "cannot relink '$file'"
4749ea133fd7Smrg	      fi
4750ea133fd7Smrg	    }
4751a253d6aeSmrg	  else
4752ea133fd7Smrg	    # Install the binary that we compiled earlier.
475325b89263Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754a253d6aeSmrg	  fi
4755ea133fd7Smrg	fi
4756a253d6aeSmrg
4757ea133fd7Smrg	# remove .exe since cygwin /usr/bin/install will append another
4758ea133fd7Smrg	# one anyway
4759ea133fd7Smrg	case $install_prog,$host in
4760ea133fd7Smrg	*/usr/bin/install*,*cygwin*)
4761ea133fd7Smrg	  case $file:$destfile in
4762ea133fd7Smrg	  *.exe:*.exe)
4763ea133fd7Smrg	    # this is ok
4764ea133fd7Smrg	    ;;
4765ea133fd7Smrg	  *.exe:*)
4766ea133fd7Smrg	    destfile=$destfile.exe
4767ea133fd7Smrg	    ;;
4768ea133fd7Smrg	  *:*.exe)
4769ea133fd7Smrg	    func_stripname '' '.exe' "$destfile"
4770ea133fd7Smrg	    destfile=$func_stripname_result
4771ea133fd7Smrg	    ;;
4772ea133fd7Smrg	  esac
4773a253d6aeSmrg	  ;;
4774a253d6aeSmrg	esac
4775ea133fd7Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4776ea133fd7Smrg	$opt_dry_run || if test -n "$outputname"; then
4777ea133fd7Smrg	  ${RM}r "$tmpdir"
4778ea133fd7Smrg	fi
4779ea133fd7Smrg	;;
4780ea133fd7Smrg      esac
4781ea133fd7Smrg    done
4782a253d6aeSmrg
4783ea133fd7Smrg    for file in $staticlibs; do
4784ea133fd7Smrg      func_basename "$file"
4785b41a30aaSmrg      name=$func_basename_result
4786a253d6aeSmrg
4787ea133fd7Smrg      # Set up the ranlib parameters.
4788b41a30aaSmrg      oldlib=$destdir/$name
478957ee1794Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
479057ee1794Smrg      tool_oldlib=$func_to_tool_file_result
4791a253d6aeSmrg
4792ea133fd7Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4793a253d6aeSmrg
4794ea133fd7Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
479557ee1794Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4796ea133fd7Smrg      fi
4797a253d6aeSmrg
4798ea133fd7Smrg      # Do each command in the postinstall commands.
4799ea133fd7Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4800ea133fd7Smrg    done
4801a253d6aeSmrg
4802ea133fd7Smrg    test -n "$future_libdirs" && \
4803b41a30aaSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4804a253d6aeSmrg
4805ea133fd7Smrg    if test -n "$current_libdirs"; then
4806ea133fd7Smrg      # Maybe just do a dry run.
4807ea133fd7Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808b41a30aaSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4809ea133fd7Smrg    else
4810ea133fd7Smrg      exit $EXIT_SUCCESS
4811ea133fd7Smrg    fi
4812ea133fd7Smrg}
4813a253d6aeSmrg
4814b41a30aaSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4815a253d6aeSmrg
4816a253d6aeSmrg
4817ea133fd7Smrg# func_generate_dlsyms outputname originator pic_p
4818ea133fd7Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4819ea133fd7Smrg# a dlpreopen symbol table.
4820ea133fd7Smrgfunc_generate_dlsyms ()
4821ea133fd7Smrg{
4822b41a30aaSmrg    $debug_cmd
4823b41a30aaSmrg
4824b41a30aaSmrg    my_outputname=$1
4825b41a30aaSmrg    my_originator=$2
4826b41a30aaSmrg    my_pic_p=${3-false}
4827b41a30aaSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4828ea133fd7Smrg    my_dlsyms=
4829ea133fd7Smrg
4830b41a30aaSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4831ea133fd7Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832b41a30aaSmrg	my_dlsyms=${my_outputname}S.c
4833ea133fd7Smrg      else
4834ea133fd7Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4835ea133fd7Smrg      fi
4836ea133fd7Smrg    fi
4837a253d6aeSmrg
4838ea133fd7Smrg    if test -n "$my_dlsyms"; then
4839ea133fd7Smrg      case $my_dlsyms in
4840ea133fd7Smrg      "") ;;
4841ea133fd7Smrg      *.c)
4842ea133fd7Smrg	# Discover the nlist of each of the dlfiles.
4843b41a30aaSmrg	nlist=$output_objdir/$my_outputname.nm
4844ea133fd7Smrg
4845ea133fd7Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4846ea133fd7Smrg
4847ea133fd7Smrg	# Parse the name list into a source file.
4848ea133fd7Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4849ea133fd7Smrg
4850ea133fd7Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851b41a30aaSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852b41a30aaSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4853ea133fd7Smrg
4854ea133fd7Smrg#ifdef __cplusplus
4855ea133fd7Smrgextern \"C\" {
4856ea133fd7Smrg#endif
4857ea133fd7Smrg
4858b41a30aaSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
485925b89263Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
486025b89263Smrg#endif
486125b89263Smrg
486206f32fbeSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863b41a30aaSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864b41a30aaSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
486506f32fbeSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
486606f32fbeSmrg# define LT_DLSYM_CONST
4867b41a30aaSmrg#elif defined __osf__
486806f32fbeSmrg/* This system does not cope well with relocations in const data.  */
486906f32fbeSmrg# define LT_DLSYM_CONST
487006f32fbeSmrg#else
487106f32fbeSmrg# define LT_DLSYM_CONST const
487206f32fbeSmrg#endif
487306f32fbeSmrg
4874b41a30aaSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875b41a30aaSmrg
4876ea133fd7Smrg/* External symbol declarations for the compiler. */\
4877ea133fd7Smrg"
4878ea133fd7Smrg
4879b41a30aaSmrg	if test yes = "$dlself"; then
4880b41a30aaSmrg	  func_verbose "generating symbol list for '$output'"
4881ea133fd7Smrg
4882ea133fd7Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4883ea133fd7Smrg
4884ea133fd7Smrg	  # Add our own program objects to the symbol list.
488525b89263Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4886ea133fd7Smrg	  for progfile in $progfiles; do
488706f32fbeSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888b41a30aaSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
488906f32fbeSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4890ea133fd7Smrg	  done
4891ea133fd7Smrg
4892ea133fd7Smrg	  if test -n "$exclude_expsyms"; then
4893ea133fd7Smrg	    $opt_dry_run || {
4894ea133fd7Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4895ea133fd7Smrg	      eval '$MV "$nlist"T "$nlist"'
4896ea133fd7Smrg	    }
4897a253d6aeSmrg	  fi
4898a253d6aeSmrg
4899ea133fd7Smrg	  if test -n "$export_symbols_regex"; then
4900ea133fd7Smrg	    $opt_dry_run || {
4901ea133fd7Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4902ea133fd7Smrg	      eval '$MV "$nlist"T "$nlist"'
4903ea133fd7Smrg	    }
4904a253d6aeSmrg	  fi
4905ea133fd7Smrg
4906ea133fd7Smrg	  # Prepare the list of exported symbols
4907ea133fd7Smrg	  if test -z "$export_symbols"; then
4908b41a30aaSmrg	    export_symbols=$output_objdir/$outputname.exp
4909ea133fd7Smrg	    $opt_dry_run || {
4910ea133fd7Smrg	      $RM $export_symbols
4911b41a30aaSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4912ea133fd7Smrg	      case $host in
4913ea133fd7Smrg	      *cygwin* | *mingw* | *cegcc* )
4914ea133fd7Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4915ea133fd7Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4916ea133fd7Smrg	        ;;
4917a253d6aeSmrg	      esac
4918ea133fd7Smrg	    }
4919ea133fd7Smrg	  else
4920ea133fd7Smrg	    $opt_dry_run || {
4921b41a30aaSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4922ea133fd7Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4923ea133fd7Smrg	      eval '$MV "$nlist"T "$nlist"'
4924ea133fd7Smrg	      case $host in
492525b89263Smrg	        *cygwin* | *mingw* | *cegcc* )
4926ea133fd7Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4927ea133fd7Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4928ea133fd7Smrg	          ;;
4929a253d6aeSmrg	      esac
4930ea133fd7Smrg	    }
4931a253d6aeSmrg	  fi
4932ea133fd7Smrg	fi
4933a253d6aeSmrg
4934ea133fd7Smrg	for dlprefile in $dlprefiles; do
4935b41a30aaSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4936ea133fd7Smrg	  func_basename "$dlprefile"
4937b41a30aaSmrg	  name=$func_basename_result
493806f32fbeSmrg          case $host in
493906f32fbeSmrg	    *cygwin* | *mingw* | *cegcc* )
494006f32fbeSmrg	      # if an import library, we need to obtain dlname
494106f32fbeSmrg	      if func_win32_import_lib_p "$dlprefile"; then
494206f32fbeSmrg	        func_tr_sh "$dlprefile"
494306f32fbeSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944b41a30aaSmrg	        dlprefile_dlbasename=
494506f32fbeSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
494606f32fbeSmrg	          # Use subshell, to avoid clobbering current variable values
494706f32fbeSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948b41a30aaSmrg	          if test -n "$dlprefile_dlname"; then
494906f32fbeSmrg	            func_basename "$dlprefile_dlname"
4950b41a30aaSmrg	            dlprefile_dlbasename=$func_basename_result
495106f32fbeSmrg	          else
495206f32fbeSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
495306f32fbeSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
495406f32fbeSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
495506f32fbeSmrg	          fi
495606f32fbeSmrg	        fi
495706f32fbeSmrg	        $opt_dry_run || {
4958b41a30aaSmrg	          if test -n "$dlprefile_dlbasename"; then
495906f32fbeSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
496006f32fbeSmrg	          else
496106f32fbeSmrg	            func_warning "Could not compute DLL name from $name"
496206f32fbeSmrg	            eval '$ECHO ": $name " >> "$nlist"'
496306f32fbeSmrg	          fi
496406f32fbeSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
496506f32fbeSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
496606f32fbeSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
496706f32fbeSmrg	        }
496806f32fbeSmrg	      else # not an import lib
496906f32fbeSmrg	        $opt_dry_run || {
497006f32fbeSmrg	          eval '$ECHO ": $name " >> "$nlist"'
497106f32fbeSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
497206f32fbeSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
497306f32fbeSmrg	        }
497406f32fbeSmrg	      fi
497506f32fbeSmrg	    ;;
497606f32fbeSmrg	    *)
497706f32fbeSmrg	      $opt_dry_run || {
497806f32fbeSmrg	        eval '$ECHO ": $name " >> "$nlist"'
497906f32fbeSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
498006f32fbeSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
498106f32fbeSmrg	      }
498206f32fbeSmrg	    ;;
498306f32fbeSmrg          esac
4984ea133fd7Smrg	done
4985a253d6aeSmrg
4986ea133fd7Smrg	$opt_dry_run || {
4987ea133fd7Smrg	  # Make sure we have at least an empty file.
4988ea133fd7Smrg	  test -f "$nlist" || : > "$nlist"
4989a253d6aeSmrg
4990ea133fd7Smrg	  if test -n "$exclude_expsyms"; then
4991ea133fd7Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4992ea133fd7Smrg	    $MV "$nlist"T "$nlist"
4993a253d6aeSmrg	  fi
4994a253d6aeSmrg
4995ea133fd7Smrg	  # Try sorting and uniquifying the output.
4996ea133fd7Smrg	  if $GREP -v "^: " < "$nlist" |
4997ea133fd7Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4998ea133fd7Smrg		sort -k 3
4999a253d6aeSmrg	      else
5000ea133fd7Smrg		sort +2
5001ea133fd7Smrg	      fi |
5002ea133fd7Smrg	      uniq > "$nlist"S; then
5003ea133fd7Smrg	    :
5004a253d6aeSmrg	  else
5005ea133fd7Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006a253d6aeSmrg	  fi
5007a253d6aeSmrg
5008ea133fd7Smrg	  if test -f "$nlist"S; then
5009ea133fd7Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010a253d6aeSmrg	  else
501125b89263Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012a253d6aeSmrg	  fi
5013a253d6aeSmrg
5014b41a30aaSmrg	  func_show_eval '$RM "${nlist}I"'
5015b41a30aaSmrg	  if test -n "$global_symbol_to_import"; then
5016b41a30aaSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017b41a30aaSmrg	  fi
5018b41a30aaSmrg
501925b89263Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5020a253d6aeSmrg
5021ea133fd7Smrg/* The mapping between symbol names and symbols.  */
5022ea133fd7Smrgtypedef struct {
5023ea133fd7Smrg  const char *name;
5024ea133fd7Smrg  void *address;
5025ea133fd7Smrg} lt_dlsymlist;
502606f32fbeSmrgextern LT_DLSYM_CONST lt_dlsymlist
5027b41a30aaSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028b41a30aaSmrg"
5029b41a30aaSmrg
5030b41a30aaSmrg	  if test -s "$nlist"I; then
5031b41a30aaSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032b41a30aaSmrgstatic void lt_syminit(void)
5033b41a30aaSmrg{
5034b41a30aaSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035b41a30aaSmrg  for (; symbol->name; ++symbol)
5036b41a30aaSmrg    {"
5037b41a30aaSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038b41a30aaSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039b41a30aaSmrg    }
5040b41a30aaSmrg}"
5041b41a30aaSmrg	  fi
5042b41a30aaSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
504306f32fbeSmrgLT_DLSYM_CONST lt_dlsymlist
5044ea133fd7Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045b41a30aaSmrg{ {\"$my_originator\", (void *) 0},"
5046b41a30aaSmrg
5047b41a30aaSmrg	  if test -s "$nlist"I; then
5048b41a30aaSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049b41a30aaSmrg  {\"@INIT@\", (void *) &lt_syminit},"
5050b41a30aaSmrg	  fi
5051ea133fd7Smrg
5052ea133fd7Smrg	  case $need_lib_prefix in
5053ea133fd7Smrg	  no)
5054ea133fd7Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5055ea133fd7Smrg	    ;;
5056ea133fd7Smrg	  *)
5057ea133fd7Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5058ea133fd7Smrg	    ;;
5059ea133fd7Smrg	  esac
506025b89263Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5061ea133fd7Smrg  {0, (void *) 0}
5062ea133fd7Smrg};
5063ea133fd7Smrg
5064ea133fd7Smrg/* This works around a problem in FreeBSD linker */
5065ea133fd7Smrg#ifdef FREEBSD_WORKAROUND
5066ea133fd7Smrgstatic const void *lt_preloaded_setup() {
5067ea133fd7Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5068ea133fd7Smrg}
5069ea133fd7Smrg#endif
5070ea133fd7Smrg
5071ea133fd7Smrg#ifdef __cplusplus
5072ea133fd7Smrg}
5073ea133fd7Smrg#endif\
5074ea133fd7Smrg"
5075ea133fd7Smrg	} # !$opt_dry_run
5076ea133fd7Smrg
5077ea133fd7Smrg	pic_flag_for_symtable=
5078ea133fd7Smrg	case "$compile_command " in
5079ea133fd7Smrg	*" -static "*) ;;
5080ea133fd7Smrg	*)
5081ea133fd7Smrg	  case $host in
5082ea133fd7Smrg	  # compiling the symbol table file with pic_flag works around
5083ea133fd7Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
5084ea133fd7Smrg	  # linked before any other PIC object.  But we must not use
5085ea133fd7Smrg	  # pic_flag when linking with -static.  The problem exists in
5086ea133fd7Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
508757ee1794Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5088ea133fd7Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5089ea133fd7Smrg	  *-*-hpux*)
5090ea133fd7Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5091ea133fd7Smrg	  *)
5092b41a30aaSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5093ea133fd7Smrg	    ;;
5094ea133fd7Smrg	  esac
5095ea133fd7Smrg	  ;;
5096ea133fd7Smrg	esac
5097ea133fd7Smrg	symtab_cflags=
5098ea133fd7Smrg	for arg in $LTCFLAGS; do
5099ea133fd7Smrg	  case $arg in
5100ea133fd7Smrg	  -pie | -fpie | -fPIE) ;;
510106f32fbeSmrg	  *) func_append symtab_cflags " $arg" ;;
5102ea133fd7Smrg	  esac
5103ea133fd7Smrg	done
5104a253d6aeSmrg
5105ea133fd7Smrg	# Now compile the dynamic symbol file.
5106ea133fd7Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5107a253d6aeSmrg
5108ea133fd7Smrg	# Clean up the generated files.
5109b41a30aaSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5110ea133fd7Smrg
5111ea133fd7Smrg	# Transform the symbol file into the correct name.
5112b41a30aaSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5113ea133fd7Smrg	case $host in
5114ea133fd7Smrg	*cygwin* | *mingw* | *cegcc* )
5115ea133fd7Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
511625b89263Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
511725b89263Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5118ea133fd7Smrg	  else
511925b89263Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512025b89263Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5121ea133fd7Smrg	  fi
5122ea133fd7Smrg	  ;;
5123ea133fd7Smrg	*)
512425b89263Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
512525b89263Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5126a253d6aeSmrg	  ;;
5127a253d6aeSmrg	esac
5128ea133fd7Smrg	;;
5129ea133fd7Smrg      *)
5130b41a30aaSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5131ea133fd7Smrg	;;
5132ea133fd7Smrg      esac
5133ea133fd7Smrg    else
5134ea133fd7Smrg      # We keep going just in case the user didn't refer to
5135ea133fd7Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5136ea133fd7Smrg      # really was required.
5137ea133fd7Smrg
5138ea133fd7Smrg      # Nullify the symbol file.
513925b89263Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
514025b89263Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5141a253d6aeSmrg    fi
5142ea133fd7Smrg}
5143a253d6aeSmrg
5144b41a30aaSmrg# func_cygming_gnu_implib_p ARG
5145b41a30aaSmrg# This predicate returns with zero status (TRUE) if
5146b41a30aaSmrg# ARG is a GNU/binutils-style import library. Returns
5147b41a30aaSmrg# with nonzero status (FALSE) otherwise.
5148b41a30aaSmrgfunc_cygming_gnu_implib_p ()
5149b41a30aaSmrg{
5150b41a30aaSmrg  $debug_cmd
5151b41a30aaSmrg
5152b41a30aaSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153b41a30aaSmrg  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)$'`
5154b41a30aaSmrg  test -n "$func_cygming_gnu_implib_tmp"
5155b41a30aaSmrg}
5156b41a30aaSmrg
5157b41a30aaSmrg# func_cygming_ms_implib_p ARG
5158b41a30aaSmrg# This predicate returns with zero status (TRUE) if
5159b41a30aaSmrg# ARG is an MS-style import library. Returns
5160b41a30aaSmrg# with nonzero status (FALSE) otherwise.
5161b41a30aaSmrgfunc_cygming_ms_implib_p ()
5162b41a30aaSmrg{
5163b41a30aaSmrg  $debug_cmd
5164b41a30aaSmrg
5165b41a30aaSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166b41a30aaSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167b41a30aaSmrg  test -n "$func_cygming_ms_implib_tmp"
5168b41a30aaSmrg}
5169b41a30aaSmrg
5170ea133fd7Smrg# func_win32_libid arg
5171ea133fd7Smrg# return the library type of file 'arg'
5172ea133fd7Smrg#
5173ea133fd7Smrg# Need a lot of goo to handle *both* DLLs and import libs
5174ea133fd7Smrg# Has to be a shell function in order to 'eat' the argument
5175ea133fd7Smrg# that is supplied when $file_magic_command is called.
517625b89263Smrg# Despite the name, also deal with 64 bit binaries.
5177ea133fd7Smrgfunc_win32_libid ()
5178ea133fd7Smrg{
5179b41a30aaSmrg  $debug_cmd
5180b41a30aaSmrg
5181b41a30aaSmrg  win32_libid_type=unknown
5182ea133fd7Smrg  win32_fileres=`file -L $1 2>/dev/null`
5183ea133fd7Smrg  case $win32_fileres in
5184ea133fd7Smrg  *ar\ archive\ import\ library*) # definitely import
5185ea133fd7Smrg    win32_libid_type="x86 archive import"
5186ea133fd7Smrg    ;;
5187ea133fd7Smrg  *ar\ archive*) # could be an import, or static
518825b89263Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5189ea133fd7Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
519025b89263Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191b41a30aaSmrg      case $nm_interface in
5192b41a30aaSmrg      "MS dumpbin")
5193b41a30aaSmrg	if func_cygming_ms_implib_p "$1" ||
5194b41a30aaSmrg	   func_cygming_gnu_implib_p "$1"
5195b41a30aaSmrg	then
5196b41a30aaSmrg	  win32_nmres=import
5197b41a30aaSmrg	else
5198b41a30aaSmrg	  win32_nmres=
5199b41a30aaSmrg	fi
5200b41a30aaSmrg	;;
5201b41a30aaSmrg      *)
5202b41a30aaSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203b41a30aaSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204b41a30aaSmrg	  $SED -n -e '
5205ea133fd7Smrg	    1,100{
5206ea133fd7Smrg		/ I /{
5207b41a30aaSmrg		    s|.*|import|
5208ea133fd7Smrg		    p
5209ea133fd7Smrg		    q
5210ea133fd7Smrg		}
5211ea133fd7Smrg	    }'`
5212b41a30aaSmrg	;;
5213b41a30aaSmrg      esac
5214ea133fd7Smrg      case $win32_nmres in
5215ea133fd7Smrg      import*)  win32_libid_type="x86 archive import";;
5216ea133fd7Smrg      *)        win32_libid_type="x86 archive static";;
5217ea133fd7Smrg      esac
5218ea133fd7Smrg    fi
5219ea133fd7Smrg    ;;
5220ea133fd7Smrg  *DLL*)
5221ea133fd7Smrg    win32_libid_type="x86 DLL"
5222ea133fd7Smrg    ;;
5223ea133fd7Smrg  *executable*) # but shell scripts are "executable" too...
5224ea133fd7Smrg    case $win32_fileres in
5225ea133fd7Smrg    *MS\ Windows\ PE\ Intel*)
5226ea133fd7Smrg      win32_libid_type="x86 DLL"
5227ea133fd7Smrg      ;;
5228ea133fd7Smrg    esac
5229ea133fd7Smrg    ;;
5230ea133fd7Smrg  esac
5231ea133fd7Smrg  $ECHO "$win32_libid_type"
5232ea133fd7Smrg}
5233a253d6aeSmrg
523406f32fbeSmrg# func_cygming_dll_for_implib ARG
523506f32fbeSmrg#
523606f32fbeSmrg# Platform-specific function to extract the
523706f32fbeSmrg# name of the DLL associated with the specified
523806f32fbeSmrg# import library ARG.
523906f32fbeSmrg# Invoked by eval'ing the libtool variable
524006f32fbeSmrg#    $sharedlib_from_linklib_cmd
524106f32fbeSmrg# Result is available in the variable
524206f32fbeSmrg#    $sharedlib_from_linklib_result
524306f32fbeSmrgfunc_cygming_dll_for_implib ()
524406f32fbeSmrg{
5245b41a30aaSmrg  $debug_cmd
5246b41a30aaSmrg
524706f32fbeSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
524806f32fbeSmrg}
524906f32fbeSmrg
525006f32fbeSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
525106f32fbeSmrg#
525206f32fbeSmrg# The is the core of a fallback implementation of a
525306f32fbeSmrg# platform-specific function to extract the name of the
525406f32fbeSmrg# DLL associated with the specified import library LIBNAME.
525506f32fbeSmrg#
525606f32fbeSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
525706f32fbeSmrg# on the platform and compiler that created the implib.
525806f32fbeSmrg#
525906f32fbeSmrg# Echos the name of the DLL associated with the
526006f32fbeSmrg# specified import library.
526106f32fbeSmrgfunc_cygming_dll_for_implib_fallback_core ()
526206f32fbeSmrg{
5263b41a30aaSmrg  $debug_cmd
5264b41a30aaSmrg
526506f32fbeSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
526606f32fbeSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
526706f32fbeSmrg    $SED '/^Contents of section '"$match_literal"':/{
526806f32fbeSmrg      # Place marker at beginning of archive member dllname section
526906f32fbeSmrg      s/.*/====MARK====/
527006f32fbeSmrg      p
527106f32fbeSmrg      d
527206f32fbeSmrg    }
527306f32fbeSmrg    # These lines can sometimes be longer than 43 characters, but
527406f32fbeSmrg    # are always uninteresting
527506f32fbeSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
527606f32fbeSmrg    /^In archive [^:]*:/d
527706f32fbeSmrg    # Ensure marker is printed
527806f32fbeSmrg    /^====MARK====/p
527906f32fbeSmrg    # Remove all lines with less than 43 characters
528006f32fbeSmrg    /^.\{43\}/!d
528106f32fbeSmrg    # From remaining lines, remove first 43 characters
528206f32fbeSmrg    s/^.\{43\}//' |
528306f32fbeSmrg    $SED -n '
528406f32fbeSmrg      # Join marker and all lines until next marker into a single line
528506f32fbeSmrg      /^====MARK====/ b para
528606f32fbeSmrg      H
528706f32fbeSmrg      $ b para
528806f32fbeSmrg      b
528906f32fbeSmrg      :para
529006f32fbeSmrg      x
529106f32fbeSmrg      s/\n//g
529206f32fbeSmrg      # Remove the marker
529306f32fbeSmrg      s/^====MARK====//
529406f32fbeSmrg      # Remove trailing dots and whitespace
529506f32fbeSmrg      s/[\. \t]*$//
529606f32fbeSmrg      # Print
529706f32fbeSmrg      /./p' |
529806f32fbeSmrg    # we now have a list, one entry per line, of the stringified
529906f32fbeSmrg    # contents of the appropriate section of all members of the
5300b41a30aaSmrg    # archive that possess that section. Heuristic: eliminate
5301b41a30aaSmrg    # all those that have a first or second character that is
530206f32fbeSmrg    # a '.' (that is, objdump's representation of an unprintable
530306f32fbeSmrg    # character.) This should work for all archives with less than
530406f32fbeSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
530506f32fbeSmrg    # begins with a literal '.' or a single character followed by
530606f32fbeSmrg    # a '.'.
530706f32fbeSmrg    #
530806f32fbeSmrg    # Of those that remain, print the first one.
530906f32fbeSmrg    $SED -e '/^\./d;/^.\./d;q'
531006f32fbeSmrg}
531106f32fbeSmrg
531206f32fbeSmrg# func_cygming_dll_for_implib_fallback ARG
531306f32fbeSmrg# Platform-specific function to extract the
531406f32fbeSmrg# name of the DLL associated with the specified
531506f32fbeSmrg# import library ARG.
531606f32fbeSmrg#
531706f32fbeSmrg# This fallback implementation is for use when $DLLTOOL
531806f32fbeSmrg# does not support the --identify-strict option.
531906f32fbeSmrg# Invoked by eval'ing the libtool variable
532006f32fbeSmrg#    $sharedlib_from_linklib_cmd
532106f32fbeSmrg# Result is available in the variable
532206f32fbeSmrg#    $sharedlib_from_linklib_result
532306f32fbeSmrgfunc_cygming_dll_for_implib_fallback ()
532406f32fbeSmrg{
5325b41a30aaSmrg  $debug_cmd
5326b41a30aaSmrg
5327b41a30aaSmrg  if func_cygming_gnu_implib_p "$1"; then
532806f32fbeSmrg    # binutils import library
532906f32fbeSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330b41a30aaSmrg  elif func_cygming_ms_implib_p "$1"; then
533106f32fbeSmrg    # ms-generated import library
533206f32fbeSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
533306f32fbeSmrg  else
533406f32fbeSmrg    # unknown
5335b41a30aaSmrg    sharedlib_from_linklib_result=
533606f32fbeSmrg  fi
533706f32fbeSmrg}
5338a253d6aeSmrg
5339a253d6aeSmrg
5340ea133fd7Smrg# func_extract_an_archive dir oldlib
5341ea133fd7Smrgfunc_extract_an_archive ()
5342ea133fd7Smrg{
5343b41a30aaSmrg    $debug_cmd
5344b41a30aaSmrg
5345b41a30aaSmrg    f_ex_an_ar_dir=$1; shift
5346b41a30aaSmrg    f_ex_an_ar_oldlib=$1
5347b41a30aaSmrg    if test yes = "$lock_old_archive_extraction"; then
534825b89263Smrg      lockfile=$f_ex_an_ar_oldlib.lock
534925b89263Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
535025b89263Smrg	func_echo "Waiting for $lockfile to be removed"
535125b89263Smrg	sleep 2
535225b89263Smrg      done
535325b89263Smrg    fi
535425b89263Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
535525b89263Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356b41a30aaSmrg    if test yes = "$lock_old_archive_extraction"; then
535725b89263Smrg      $opt_dry_run || rm -f "$lockfile"
535825b89263Smrg    fi
5359ea133fd7Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5360ea133fd7Smrg     :
5361ea133fd7Smrg    else
5362ea133fd7Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5363ea133fd7Smrg    fi
5364ea133fd7Smrg}
5365a253d6aeSmrg
5366a253d6aeSmrg
5367ea133fd7Smrg# func_extract_archives gentop oldlib ...
5368ea133fd7Smrgfunc_extract_archives ()
5369ea133fd7Smrg{
5370b41a30aaSmrg    $debug_cmd
5371b41a30aaSmrg
5372b41a30aaSmrg    my_gentop=$1; shift
5373ea133fd7Smrg    my_oldlibs=${1+"$@"}
5374b41a30aaSmrg    my_oldobjs=
5375b41a30aaSmrg    my_xlib=
5376b41a30aaSmrg    my_xabs=
5377b41a30aaSmrg    my_xdir=
5378a253d6aeSmrg
5379ea133fd7Smrg    for my_xlib in $my_oldlibs; do
5380ea133fd7Smrg      # Extract the objects.
5381ea133fd7Smrg      case $my_xlib in
5382b41a30aaSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5383ea133fd7Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5384ea133fd7Smrg      esac
5385ea133fd7Smrg      func_basename "$my_xlib"
5386b41a30aaSmrg      my_xlib=$func_basename_result
5387ea133fd7Smrg      my_xlib_u=$my_xlib
5388ea133fd7Smrg      while :; do
5389ea133fd7Smrg        case " $extracted_archives " in
5390ea133fd7Smrg	*" $my_xlib_u "*)
5391ea133fd7Smrg	  func_arith $extracted_serial + 1
5392ea133fd7Smrg	  extracted_serial=$func_arith_result
5393ea133fd7Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5394ea133fd7Smrg	*) break ;;
5395ea133fd7Smrg	esac
5396ea133fd7Smrg      done
5397ea133fd7Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5398b41a30aaSmrg      my_xdir=$my_gentop/$my_xlib_u
5399a253d6aeSmrg
5400ea133fd7Smrg      func_mkdir_p "$my_xdir"
5401a253d6aeSmrg
5402ea133fd7Smrg      case $host in
5403ea133fd7Smrg      *-darwin*)
5404ea133fd7Smrg	func_verbose "Extracting $my_xabs"
5405ea133fd7Smrg	# Do not bother doing anything if just a dry run
5406ea133fd7Smrg	$opt_dry_run || {
5407ea133fd7Smrg	  darwin_orig_dir=`pwd`
5408ea133fd7Smrg	  cd $my_xdir || exit $?
5409ea133fd7Smrg	  darwin_archive=$my_xabs
5410ea133fd7Smrg	  darwin_curdir=`pwd`
5411b41a30aaSmrg	  func_basename "$darwin_archive"
5412b41a30aaSmrg	  darwin_base_archive=$func_basename_result
5413ea133fd7Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5414ea133fd7Smrg	  if test -n "$darwin_arches"; then
5415ea133fd7Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5416ea133fd7Smrg	    darwin_arch=
5417ea133fd7Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418b41a30aaSmrg	    for darwin_arch in  $darwin_arches; do
5419b41a30aaSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420b41a30aaSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421b41a30aaSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422b41a30aaSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5423ea133fd7Smrg	      cd "$darwin_curdir"
5424b41a30aaSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5425ea133fd7Smrg	    done # $darwin_arches
5426ea133fd7Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427b41a30aaSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5428ea133fd7Smrg	    darwin_file=
5429ea133fd7Smrg	    darwin_files=
5430ea133fd7Smrg	    for darwin_file in $darwin_filelist; do
543125b89263Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5432ea133fd7Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5433ea133fd7Smrg	    done # $darwin_filelist
5434ea133fd7Smrg	    $RM -rf unfat-$$
5435ea133fd7Smrg	    cd "$darwin_orig_dir"
5436ea133fd7Smrg	  else
5437ea133fd7Smrg	    cd $darwin_orig_dir
5438ea133fd7Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5439ea133fd7Smrg	  fi # $darwin_arches
5440ea133fd7Smrg	} # !$opt_dry_run
5441ea133fd7Smrg	;;
5442ea133fd7Smrg      *)
5443ea133fd7Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5444ea133fd7Smrg	;;
5445a253d6aeSmrg      esac
544625b89263Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5447ea133fd7Smrg    done
5448a253d6aeSmrg
5449b41a30aaSmrg    func_extract_archives_result=$my_oldobjs
5450ea133fd7Smrg}
5451a253d6aeSmrg
5452a253d6aeSmrg
545325b89263Smrg# func_emit_wrapper [arg=no]
545425b89263Smrg#
545525b89263Smrg# Emit a libtool wrapper script on stdout.
545625b89263Smrg# Don't directly open a file because we may want to
545725b89263Smrg# incorporate the script contents within a cygwin/mingw
545825b89263Smrg# wrapper executable.  Must ONLY be called from within
545925b89263Smrg# func_mode_link because it depends on a number of variables
546025b89263Smrg# set therein.
5461ea133fd7Smrg#
546225b89263Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
546325b89263Smrg# variable will take.  If 'yes', then the emitted script
5464b41a30aaSmrg# will assume that the directory where it is stored is
546525b89263Smrg# the $objdir directory.  This is a cygwin/mingw-specific
546625b89263Smrg# behavior.
546725b89263Smrgfunc_emit_wrapper ()
5468ea133fd7Smrg{
546925b89263Smrg	func_emit_wrapper_arg1=${1-no}
5470a253d6aeSmrg
5471ea133fd7Smrg	$ECHO "\
5472ea133fd7Smrg#! $SHELL
5473a253d6aeSmrg
5474ea133fd7Smrg# $output - temporary wrapper script for $objdir/$outputname
5475b41a30aaSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5476ea133fd7Smrg#
5477ea133fd7Smrg# The $output program cannot be directly executed until all the libtool
5478ea133fd7Smrg# libraries that it depends on are installed.
5479ea133fd7Smrg#
5480ea133fd7Smrg# This wrapper script should never be moved out of the build directory.
5481ea133fd7Smrg# If it is, it will not operate correctly.
5482a253d6aeSmrg
5483ea133fd7Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5484ea133fd7Smrg# metacharacters that are still active within double-quoted strings.
5485ea133fd7Smrgsed_quote_subst='$sed_quote_subst'
5486a253d6aeSmrg
5487ea133fd7Smrg# Be Bourne compatible
5488ea133fd7Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5489ea133fd7Smrg  emulate sh
5490ea133fd7Smrg  NULLCMD=:
5491ea133fd7Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5492ea133fd7Smrg  # is contrary to our usage.  Disable this feature.
5493ea133fd7Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5494ea133fd7Smrg  setopt NO_GLOB_SUBST
5495ea133fd7Smrgelse
5496ea133fd7Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5497ea133fd7Smrgfi
5498ea133fd7SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5499ea133fd7SmrgDUALCASE=1; export DUALCASE # for MKS sh
5500a253d6aeSmrg
5501ea133fd7Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5502ea133fd7Smrg# if CDPATH is set.
5503ea133fd7Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5504a253d6aeSmrg
5505ea133fd7Smrgrelink_command=\"$relink_command\"
5506a253d6aeSmrg
5507ea133fd7Smrg# This environment variable determines our operation mode.
5508ea133fd7Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5509ea133fd7Smrg  # install mode needs the following variables:
5510ea133fd7Smrg  generated_by_libtool_version='$macro_version'
5511ea133fd7Smrg  notinst_deplibs='$notinst_deplibs'
5512ea133fd7Smrgelse
5513ea133fd7Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5514ea133fd7Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
551525b89263Smrg    file=\"\$0\""
551625b89263Smrg
5517b41a30aaSmrg    func_quote_arg pretty "$ECHO"
5518b41a30aaSmrg    qECHO=$func_quote_arg_result
551925b89263Smrg    $ECHO "\
552025b89263Smrg
552125b89263Smrg# A function that is used when there is no print builtin or printf.
552225b89263Smrgfunc_fallback_echo ()
552325b89263Smrg{
552425b89263Smrg  eval 'cat <<_LTECHO_EOF
552525b89263Smrg\$1
552625b89263Smrg_LTECHO_EOF'
552725b89263Smrg}
5528b41a30aaSmrg    ECHO=$qECHO
552925b89263Smrg  fi
553025b89263Smrg
553125b89263Smrg# Very basic option parsing. These options are (a) specific to
553225b89263Smrg# the libtool wrapper, (b) are identical between the wrapper
5533b41a30aaSmrg# /script/ and the wrapper /executable/ that is used only on
553425b89263Smrg# windows platforms, and (c) all begin with the string "--lt-"
5535b41a30aaSmrg# (application programs are unlikely to have options that match
553625b89263Smrg# this pattern).
553725b89263Smrg#
553825b89263Smrg# There are only two supported options: --lt-debug and
553925b89263Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
554025b89263Smrg#
554125b89263Smrg# The first argument to this parsing function should be the
554225b89263Smrg# script's $0 value, followed by "$@".
554325b89263Smrglt_option_debug=
554425b89263Smrgfunc_parse_lt_options ()
554525b89263Smrg{
554625b89263Smrg  lt_script_arg0=\$0
554725b89263Smrg  shift
554825b89263Smrg  for lt_opt
554925b89263Smrg  do
555025b89263Smrg    case \"\$lt_opt\" in
555125b89263Smrg    --lt-debug) lt_option_debug=1 ;;
555225b89263Smrg    --lt-dump-script)
555325b89263Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
555425b89263Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
555525b89263Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
555625b89263Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
555725b89263Smrg        exit 0
555825b89263Smrg      ;;
555925b89263Smrg    --lt-*)
556025b89263Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
556125b89263Smrg        exit 1
556225b89263Smrg      ;;
556325b89263Smrg    esac
556425b89263Smrg  done
556525b89263Smrg
556625b89263Smrg  # Print the debug banner immediately:
556725b89263Smrg  if test -n \"\$lt_option_debug\"; then
5568b41a30aaSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
556925b89263Smrg  fi
557025b89263Smrg}
557125b89263Smrg
557225b89263Smrg# Used when --lt-debug. Prints its arguments to stdout
557325b89263Smrg# (redirection is the responsibility of the caller)
557425b89263Smrgfunc_lt_dump_args ()
557525b89263Smrg{
557625b89263Smrg  lt_dump_args_N=1;
557725b89263Smrg  for lt_arg
557825b89263Smrg  do
5579b41a30aaSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
558025b89263Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
558125b89263Smrg  done
558225b89263Smrg}
558325b89263Smrg
558425b89263Smrg# Core function for launching the target application
558525b89263Smrgfunc_exec_program_core ()
558625b89263Smrg{
5587ea133fd7Smrg"
558825b89263Smrg  case $host in
558925b89263Smrg  # Backslashes separate directories on plain windows
559025b89263Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
559125b89263Smrg    $ECHO "\
559225b89263Smrg      if test -n \"\$lt_option_debug\"; then
5593b41a30aaSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
559425b89263Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
559525b89263Smrg      fi
559625b89263Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
559725b89263Smrg"
559825b89263Smrg    ;;
559925b89263Smrg
560025b89263Smrg  *)
560125b89263Smrg    $ECHO "\
560225b89263Smrg      if test -n \"\$lt_option_debug\"; then
5603b41a30aaSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
560425b89263Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
560525b89263Smrg      fi
560625b89263Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
560725b89263Smrg"
560825b89263Smrg    ;;
560925b89263Smrg  esac
561025b89263Smrg  $ECHO "\
561125b89263Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
561225b89263Smrg      exit 1
561325b89263Smrg}
561425b89263Smrg
561525b89263Smrg# A function to encapsulate launching the target application
561625b89263Smrg# Strips options in the --lt-* namespace from \$@ and
561725b89263Smrg# launches target application with the remaining arguments.
561825b89263Smrgfunc_exec_program ()
561925b89263Smrg{
562057ee1794Smrg  case \" \$* \" in
562157ee1794Smrg  *\\ --lt-*)
562257ee1794Smrg    for lt_wr_arg
562357ee1794Smrg    do
562457ee1794Smrg      case \$lt_wr_arg in
562557ee1794Smrg      --lt-*) ;;
562657ee1794Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
562757ee1794Smrg      esac
562857ee1794Smrg      shift
562957ee1794Smrg    done ;;
563057ee1794Smrg  esac
563125b89263Smrg  func_exec_program_core \${1+\"\$@\"}
563225b89263Smrg}
563325b89263Smrg
563425b89263Smrg  # Parse options
563525b89263Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5636a253d6aeSmrg
5637ea133fd7Smrg  # Find the directory that this script lives in.
563825b89263Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5639ea133fd7Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5640a253d6aeSmrg
5641ea133fd7Smrg  # Follow symbolic links until we get to the real thisdir.
564225b89263Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5643ea133fd7Smrg  while test -n \"\$file\"; do
564425b89263Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5645a253d6aeSmrg
5646ea133fd7Smrg    # If there was a directory component, then change thisdir.
5647ea133fd7Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5648ea133fd7Smrg      case \"\$destdir\" in
5649ea133fd7Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5650ea133fd7Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5651ea133fd7Smrg      esac
5652ea133fd7Smrg    fi
5653a253d6aeSmrg
565425b89263Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
565525b89263Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5656ea133fd7Smrg  done
5657a253d6aeSmrg
5658ea133fd7Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5659ea133fd7Smrg  # the cwrapper.
566025b89263Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5661ea133fd7Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5662ea133fd7Smrg    # special case for '.'
5663ea133fd7Smrg    if test \"\$thisdir\" = \".\"; then
5664ea133fd7Smrg      thisdir=\`pwd\`
5665ea133fd7Smrg    fi
5666ea133fd7Smrg    # remove .libs from thisdir
5667ea133fd7Smrg    case \"\$thisdir\" in
566825b89263Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5669ea133fd7Smrg    $objdir )   thisdir=. ;;
5670ea133fd7Smrg    esac
5671ea133fd7Smrg  fi
5672a253d6aeSmrg
5673ea133fd7Smrg  # Try to get the absolute directory name.
5674ea133fd7Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5675ea133fd7Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5676ea133fd7Smrg"
5677a253d6aeSmrg
5678b41a30aaSmrg	if test yes = "$fast_install"; then
5679ea133fd7Smrg	  $ECHO "\
5680ea133fd7Smrg  program=lt-'$outputname'$exeext
5681ea133fd7Smrg  progdir=\"\$thisdir/$objdir\"
5682a253d6aeSmrg
5683ea133fd7Smrg  if test ! -f \"\$progdir/\$program\" ||
5684b41a30aaSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5685ea133fd7Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686a253d6aeSmrg
5687ea133fd7Smrg    file=\"\$\$-\$program\"
5688a253d6aeSmrg
5689ea133fd7Smrg    if test ! -d \"\$progdir\"; then
5690ea133fd7Smrg      $MKDIR \"\$progdir\"
5691ea133fd7Smrg    else
5692ea133fd7Smrg      $RM \"\$progdir/\$file\"
5693ea133fd7Smrg    fi"
5694a253d6aeSmrg
5695ea133fd7Smrg	  $ECHO "\
5696a253d6aeSmrg
5697ea133fd7Smrg    # relink executable if necessary
5698ea133fd7Smrg    if test -n \"\$relink_command\"; then
5699ea133fd7Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5700ea133fd7Smrg      else
5701b41a30aaSmrg	\$ECHO \"\$relink_command_output\" >&2
5702ea133fd7Smrg	$RM \"\$progdir/\$file\"
5703ea133fd7Smrg	exit 1
5704ea133fd7Smrg      fi
5705ea133fd7Smrg    fi
5706a253d6aeSmrg
5707ea133fd7Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5708ea133fd7Smrg    { $RM \"\$progdir/\$program\";
5709ea133fd7Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5710ea133fd7Smrg    $RM \"\$progdir/\$file\"
5711ea133fd7Smrg  fi"
5712ea133fd7Smrg	else
5713ea133fd7Smrg	  $ECHO "\
5714ea133fd7Smrg  program='$outputname'
5715ea133fd7Smrg  progdir=\"\$thisdir/$objdir\"
5716ea133fd7Smrg"
5717ea133fd7Smrg	fi
5718a253d6aeSmrg
5719ea133fd7Smrg	$ECHO "\
5720a253d6aeSmrg
5721ea133fd7Smrg  if test -f \"\$progdir/\$program\"; then"
5722a253d6aeSmrg
572306f32fbeSmrg	# fixup the dll searchpath if we need to.
572406f32fbeSmrg	#
572506f32fbeSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
572606f32fbeSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
572706f32fbeSmrg	# libraries must come first.
572806f32fbeSmrg	if test -n "$dllsearchpath"; then
572906f32fbeSmrg	  $ECHO "\
573006f32fbeSmrg    # Add the dll search path components to the executable PATH
573106f32fbeSmrg    PATH=$dllsearchpath:\$PATH
573206f32fbeSmrg"
573306f32fbeSmrg	fi
573406f32fbeSmrg
5735ea133fd7Smrg	# Export our shlibpath_var if we have one.
5736b41a30aaSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5737ea133fd7Smrg	  $ECHO "\
5738ea133fd7Smrg    # Add our own library path to $shlibpath_var
5739ea133fd7Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740a253d6aeSmrg
5741ea133fd7Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5742ea133fd7Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
574325b89263Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5744a253d6aeSmrg
5745ea133fd7Smrg    export $shlibpath_var
5746ea133fd7Smrg"
5747a253d6aeSmrg	fi
5748a253d6aeSmrg
5749ea133fd7Smrg	$ECHO "\
5750ea133fd7Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5751ea133fd7Smrg      # Run the actual program with our arguments.
575225b89263Smrg      func_exec_program \${1+\"\$@\"}
5753ea133fd7Smrg    fi
5754ea133fd7Smrg  else
5755ea133fd7Smrg    # The program doesn't exist.
5756b41a30aaSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5757ea133fd7Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
575825b89263Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5759ea133fd7Smrg    exit 1
5760ea133fd7Smrg  fi
5761ea133fd7Smrgfi\
5762ea133fd7Smrg"
5763ea133fd7Smrg}
5764a253d6aeSmrg
5765a253d6aeSmrg
5766ea133fd7Smrg# func_emit_cwrapperexe_src
5767ea133fd7Smrg# emit the source code for a wrapper executable on stdout
5768ea133fd7Smrg# Must ONLY be called from within func_mode_link because
5769ea133fd7Smrg# it depends on a number of variable set therein.
5770ea133fd7Smrgfunc_emit_cwrapperexe_src ()
5771ea133fd7Smrg{
5772ea133fd7Smrg	cat <<EOF
5773a253d6aeSmrg
5774ea133fd7Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775b41a30aaSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776a253d6aeSmrg
5777ea133fd7Smrg   The $output program cannot be directly executed until all the libtool
5778ea133fd7Smrg   libraries that it depends on are installed.
5779a253d6aeSmrg
5780ea133fd7Smrg   This wrapper executable should never be moved out of the build directory.
5781ea133fd7Smrg   If it is, it will not operate correctly.
5782ea133fd7Smrg*/
5783ea133fd7SmrgEOF
5784ea133fd7Smrg	    cat <<"EOF"
578525b89263Smrg#ifdef _MSC_VER
578625b89263Smrg# define _CRT_SECURE_NO_DEPRECATE 1
578725b89263Smrg#endif
5788ea133fd7Smrg#include <stdio.h>
5789ea133fd7Smrg#include <stdlib.h>
5790ea133fd7Smrg#ifdef _MSC_VER
5791ea133fd7Smrg# include <direct.h>
5792ea133fd7Smrg# include <process.h>
5793ea133fd7Smrg# include <io.h>
5794ea133fd7Smrg#else
5795ea133fd7Smrg# include <unistd.h>
5796ea133fd7Smrg# include <stdint.h>
5797ea133fd7Smrg# ifdef __CYGWIN__
5798ea133fd7Smrg#  include <io.h>
5799ea133fd7Smrg# endif
5800ea133fd7Smrg#endif
5801ea133fd7Smrg#include <malloc.h>
5802ea133fd7Smrg#include <stdarg.h>
5803ea133fd7Smrg#include <assert.h>
5804ea133fd7Smrg#include <string.h>
5805ea133fd7Smrg#include <ctype.h>
5806ea133fd7Smrg#include <errno.h>
5807ea133fd7Smrg#include <fcntl.h>
5808ea133fd7Smrg#include <sys/stat.h>
5809ea133fd7Smrg
5810b41a30aaSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811b41a30aaSmrg
581225b89263Smrg/* declarations of non-ANSI functions */
5813b41a30aaSmrg#if defined __MINGW32__
581425b89263Smrg# ifdef __STRICT_ANSI__
581525b89263Smrgint _putenv (const char *);
581625b89263Smrg# endif
5817b41a30aaSmrg#elif defined __CYGWIN__
581825b89263Smrg# ifdef __STRICT_ANSI__
581925b89263Smrgchar *realpath (const char *, char *);
582025b89263Smrgint putenv (char *);
582125b89263Smrgint setenv (const char *, const char *, int);
582225b89263Smrg# endif
5823b41a30aaSmrg/* #elif defined other_platform || defined ... */
582425b89263Smrg#endif
582525b89263Smrg
582625b89263Smrg/* portability defines, excluding path handling macros */
5827b41a30aaSmrg#if defined _MSC_VER
582825b89263Smrg# define setmode _setmode
582925b89263Smrg# define stat    _stat
583025b89263Smrg# define chmod   _chmod
583125b89263Smrg# define getcwd  _getcwd
583225b89263Smrg# define putenv  _putenv
583325b89263Smrg# define S_IXUSR _S_IEXEC
5834b41a30aaSmrg#elif defined __MINGW32__
583525b89263Smrg# define setmode _setmode
583625b89263Smrg# define stat    _stat
583725b89263Smrg# define chmod   _chmod
583825b89263Smrg# define getcwd  _getcwd
583925b89263Smrg# define putenv  _putenv
5840b41a30aaSmrg#elif defined __CYGWIN__
584125b89263Smrg# define HAVE_SETENV
584225b89263Smrg# define FOPEN_WB "wb"
5843b41a30aaSmrg/* #elif defined other platforms ... */
584425b89263Smrg#endif
584525b89263Smrg
5846b41a30aaSmrg#if defined PATH_MAX
5847ea133fd7Smrg# define LT_PATHMAX PATH_MAX
5848b41a30aaSmrg#elif defined MAXPATHLEN
5849ea133fd7Smrg# define LT_PATHMAX MAXPATHLEN
5850ea133fd7Smrg#else
5851ea133fd7Smrg# define LT_PATHMAX 1024
5852ea133fd7Smrg#endif
5853ea133fd7Smrg
5854ea133fd7Smrg#ifndef S_IXOTH
5855ea133fd7Smrg# define S_IXOTH 0
5856ea133fd7Smrg#endif
5857ea133fd7Smrg#ifndef S_IXGRP
5858ea133fd7Smrg# define S_IXGRP 0
5859ea133fd7Smrg#endif
5860ea133fd7Smrg
586125b89263Smrg/* path handling portability macros */
5862ea133fd7Smrg#ifndef DIR_SEPARATOR
5863ea133fd7Smrg# define DIR_SEPARATOR '/'
5864ea133fd7Smrg# define PATH_SEPARATOR ':'
5865ea133fd7Smrg#endif
5866ea133fd7Smrg
5867b41a30aaSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868b41a30aaSmrg  defined __OS2__
5869ea133fd7Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5870ea133fd7Smrg# define FOPEN_WB "wb"
5871ea133fd7Smrg# ifndef DIR_SEPARATOR_2
5872ea133fd7Smrg#  define DIR_SEPARATOR_2 '\\'
5873ea133fd7Smrg# endif
5874ea133fd7Smrg# ifndef PATH_SEPARATOR_2
5875ea133fd7Smrg#  define PATH_SEPARATOR_2 ';'
5876ea133fd7Smrg# endif
5877ea133fd7Smrg#endif
5878ea133fd7Smrg
5879ea133fd7Smrg#ifndef DIR_SEPARATOR_2
5880ea133fd7Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5881ea133fd7Smrg#else /* DIR_SEPARATOR_2 */
5882ea133fd7Smrg# define IS_DIR_SEPARATOR(ch) \
5883ea133fd7Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5884ea133fd7Smrg#endif /* DIR_SEPARATOR_2 */
5885ea133fd7Smrg
5886ea133fd7Smrg#ifndef PATH_SEPARATOR_2
5887ea133fd7Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5888ea133fd7Smrg#else /* PATH_SEPARATOR_2 */
5889ea133fd7Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5890ea133fd7Smrg#endif /* PATH_SEPARATOR_2 */
5891ea133fd7Smrg
5892ea133fd7Smrg#ifndef FOPEN_WB
5893ea133fd7Smrg# define FOPEN_WB "w"
5894ea133fd7Smrg#endif
5895ea133fd7Smrg#ifndef _O_BINARY
5896ea133fd7Smrg# define _O_BINARY 0
5897ea133fd7Smrg#endif
5898ea133fd7Smrg
5899ea133fd7Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5900ea133fd7Smrg#define XFREE(stale) do { \
5901b41a30aaSmrg  if (stale) { free (stale); stale = 0; } \
5902ea133fd7Smrg} while (0)
5903ea133fd7Smrg
5904b41a30aaSmrg#if defined LT_DEBUGWRAPPER
590525b89263Smrgstatic int lt_debug = 1;
5906ea133fd7Smrg#else
590725b89263Smrgstatic int lt_debug = 0;
5908ea133fd7Smrg#endif
5909ea133fd7Smrg
591025b89263Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5911ea133fd7Smrg
5912ea133fd7Smrgvoid *xmalloc (size_t num);
5913ea133fd7Smrgchar *xstrdup (const char *string);
5914ea133fd7Smrgconst char *base_name (const char *name);
5915ea133fd7Smrgchar *find_executable (const char *wrapper);
5916ea133fd7Smrgchar *chase_symlinks (const char *pathspec);
5917ea133fd7Smrgint make_executable (const char *path);
5918ea133fd7Smrgint check_executable (const char *path);
5919ea133fd7Smrgchar *strendzap (char *str, const char *pat);
592025b89263Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
592125b89263Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
592225b89263Smrgstatic const char *nonnull (const char *s);
592325b89263Smrgstatic const char *nonempty (const char *s);
5924ea133fd7Smrgvoid lt_setenv (const char *name, const char *value);
5925ea133fd7Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5926ea133fd7Smrgvoid lt_update_exe_path (const char *name, const char *value);
5927ea133fd7Smrgvoid lt_update_lib_path (const char *name, const char *value);
592825b89263Smrgchar **prepare_spawn (char **argv);
592925b89263Smrgvoid lt_dump_script (FILE *f);
5930ea133fd7SmrgEOF
5931ea133fd7Smrg
5932ea133fd7Smrg	    cat <<EOF
5933b41a30aaSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934b41a30aaSmrg# define externally_visible volatile
5935b41a30aaSmrg#else
5936b41a30aaSmrg# define externally_visible __attribute__((externally_visible)) volatile
5937b41a30aaSmrg#endif
5938b41a30aaSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5939ea133fd7Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5940ea133fd7SmrgEOF
5941ea133fd7Smrg
5942b41a30aaSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
594306f32fbeSmrg              func_to_host_path "$temp_rpath"
5944ea133fd7Smrg	      cat <<EOF
594506f32fbeSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5946a253d6aeSmrgEOF
5947a253d6aeSmrg	    else
5948ea133fd7Smrg	      cat <<"EOF"
5949ea133fd7Smrgconst char * LIB_PATH_VALUE   = "";
5950ea133fd7SmrgEOF
5951a253d6aeSmrg	    fi
5952ea133fd7Smrg
5953ea133fd7Smrg	    if test -n "$dllsearchpath"; then
595406f32fbeSmrg              func_to_host_path "$dllsearchpath:"
5955ea133fd7Smrg	      cat <<EOF
5956ea133fd7Smrgconst char * EXE_PATH_VARNAME = "PATH";
595706f32fbeSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5958ea133fd7SmrgEOF
5959a253d6aeSmrg	    else
5960ea133fd7Smrg	      cat <<"EOF"
5961ea133fd7Smrgconst char * EXE_PATH_VARNAME = "";
5962ea133fd7Smrgconst char * EXE_PATH_VALUE   = "";
5963ea133fd7SmrgEOF
5964a253d6aeSmrg	    fi
5965ea133fd7Smrg
5966b41a30aaSmrg	    if test yes = "$fast_install"; then
5967ea133fd7Smrg	      cat <<EOF
5968ea133fd7Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5969ea133fd7SmrgEOF
5970a253d6aeSmrg	    else
5971ea133fd7Smrg	      cat <<EOF
5972ea133fd7Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5973ea133fd7SmrgEOF
5974a253d6aeSmrg	    fi
5975a253d6aeSmrg
5976a253d6aeSmrg
5977ea133fd7Smrg	    cat <<"EOF"
5978a253d6aeSmrg
5979ea133fd7Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5980a253d6aeSmrg
5981ea133fd7Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5982ea133fd7Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
598325b89263Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5984a253d6aeSmrg
5985ea133fd7Smrgint
5986ea133fd7Smrgmain (int argc, char *argv[])
5987ea133fd7Smrg{
5988ea133fd7Smrg  char **newargz;
5989ea133fd7Smrg  int  newargc;
5990ea133fd7Smrg  char *tmp_pathspec;
5991ea133fd7Smrg  char *actual_cwrapper_path;
5992ea133fd7Smrg  char *actual_cwrapper_name;
5993ea133fd7Smrg  char *target_name;
5994ea133fd7Smrg  char *lt_argv_zero;
5995b41a30aaSmrg  int rval = 127;
5996a253d6aeSmrg
5997ea133fd7Smrg  int i;
5998a253d6aeSmrg
5999ea133fd7Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000b41a30aaSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6001a253d6aeSmrg
600225b89263Smrg  /* very simple arg parsing; don't want to rely on getopt
600325b89263Smrg   * also, copy all non cwrapper options to newargz, except
600425b89263Smrg   * argz[0], which is handled differently
600525b89263Smrg   */
600625b89263Smrg  newargc=0;
6007ea133fd7Smrg  for (i = 1; i < argc; i++)
6008ea133fd7Smrg    {
6009b41a30aaSmrg      if (STREQ (argv[i], dumpscript_opt))
6010ea133fd7Smrg	{
6011ea133fd7SmrgEOF
6012b41a30aaSmrg	    case $host in
6013ea133fd7Smrg	      *mingw* | *cygwin* )
6014ea133fd7Smrg		# make stdout use "unix" line endings
6015ea133fd7Smrg		echo "          setmode(1,_O_BINARY);"
6016ea133fd7Smrg		;;
6017ea133fd7Smrg	      esac
6018a253d6aeSmrg
6019ea133fd7Smrg	    cat <<"EOF"
602025b89263Smrg	  lt_dump_script (stdout);
6021ea133fd7Smrg	  return 0;
6022ea133fd7Smrg	}
6023b41a30aaSmrg      if (STREQ (argv[i], debug_opt))
602425b89263Smrg	{
602525b89263Smrg          lt_debug = 1;
602625b89263Smrg          continue;
602725b89263Smrg	}
6028b41a30aaSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
602925b89263Smrg        {
603025b89263Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
603125b89263Smrg             namespace, but it is not one of the ones we know about and
603225b89263Smrg             have already dealt with, above (inluding dump-script), then
603325b89263Smrg             report an error. Otherwise, targets might begin to believe
603425b89263Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
603525b89263Smrg             namespace. The first time any user complains about this, we'll
603625b89263Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
603725b89263Smrg             or a configure.ac-settable value.
603825b89263Smrg           */
603925b89263Smrg          lt_fatal (__FILE__, __LINE__,
604025b89263Smrg		    "unrecognized %s option: '%s'",
604125b89263Smrg                    ltwrapper_option_prefix, argv[i]);
604225b89263Smrg        }
604325b89263Smrg      /* otherwise ... */
604425b89263Smrg      newargz[++newargc] = xstrdup (argv[i]);
6045ea133fd7Smrg    }
604625b89263Smrg  newargz[++newargc] = NULL;
604725b89263Smrg
604825b89263SmrgEOF
604925b89263Smrg	    cat <<EOF
605025b89263Smrg  /* The GNU banner must be the first non-error debug message */
6051b41a30aaSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
605225b89263SmrgEOF
605325b89263Smrg	    cat <<"EOF"
605425b89263Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
605525b89263Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6056a253d6aeSmrg
6057ea133fd7Smrg  tmp_pathspec = find_executable (argv[0]);
6058ea133fd7Smrg  if (tmp_pathspec == NULL)
605925b89263Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
606025b89263Smrg  lt_debugprintf (__FILE__, __LINE__,
606125b89263Smrg                  "(main) found exe (before symlink chase) at: %s\n",
606225b89263Smrg		  tmp_pathspec);
6063ea133fd7Smrg
6064ea133fd7Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
606525b89263Smrg  lt_debugprintf (__FILE__, __LINE__,
606625b89263Smrg                  "(main) found exe (after symlink chase) at: %s\n",
606725b89263Smrg		  actual_cwrapper_path);
6068ea133fd7Smrg  XFREE (tmp_pathspec);
6069ea133fd7Smrg
607025b89263Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6071ea133fd7Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6072ea133fd7Smrg
6073ea133fd7Smrg  /* wrapper name transforms */
6074ea133fd7Smrg  strendzap (actual_cwrapper_name, ".exe");
6075ea133fd7Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6076ea133fd7Smrg  XFREE (actual_cwrapper_name);
6077ea133fd7Smrg  actual_cwrapper_name = tmp_pathspec;
6078ea133fd7Smrg  tmp_pathspec = 0;
6079ea133fd7Smrg
6080ea133fd7Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6081ea133fd7Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6082ea133fd7Smrg  strendzap (target_name, ".exe");
6083ea133fd7Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6084ea133fd7Smrg  XFREE (target_name);
6085ea133fd7Smrg  target_name = tmp_pathspec;
6086ea133fd7Smrg  tmp_pathspec = 0;
6087ea133fd7Smrg
608825b89263Smrg  lt_debugprintf (__FILE__, __LINE__,
608925b89263Smrg		  "(main) libtool target name: %s\n",
609025b89263Smrg		  target_name);
6091ea133fd7SmrgEOF
6092a253d6aeSmrg
6093ea133fd7Smrg	    cat <<EOF
6094ea133fd7Smrg  newargz[0] =
6095ea133fd7Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6096ea133fd7Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6097ea133fd7Smrg  strcpy (newargz[0], actual_cwrapper_path);
6098ea133fd7Smrg  strcat (newargz[0], "$objdir");
6099ea133fd7Smrg  strcat (newargz[0], "/");
6100ea133fd7SmrgEOF
6101a253d6aeSmrg
6102ea133fd7Smrg	    cat <<"EOF"
6103ea133fd7Smrg  /* stop here, and copy so we don't have to do this twice */
6104ea133fd7Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105a253d6aeSmrg
6106ea133fd7Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6107ea133fd7Smrg  strcat (newargz[0], actual_cwrapper_name);
6108a253d6aeSmrg
6109ea133fd7Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
6110ea133fd7Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6111ea133fd7Smrg  XFREE (tmp_pathspec);
6112ea133fd7Smrg  tmp_pathspec = NULL;
6113ea133fd7SmrgEOF
6114a253d6aeSmrg
6115ea133fd7Smrg	    case $host_os in
6116ea133fd7Smrg	      mingw*)
6117ea133fd7Smrg	    cat <<"EOF"
6118ea133fd7Smrg  {
6119ea133fd7Smrg    char* p;
6120ea133fd7Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6121ea133fd7Smrg      {
6122ea133fd7Smrg	*p = '/';
6123ea133fd7Smrg      }
6124ea133fd7Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6125ea133fd7Smrg      {
6126ea133fd7Smrg	*p = '/';
6127ea133fd7Smrg      }
6128ea133fd7Smrg  }
6129ea133fd7SmrgEOF
6130ea133fd7Smrg	    ;;
6131ea133fd7Smrg	    esac
6132a253d6aeSmrg
6133ea133fd7Smrg	    cat <<"EOF"
6134ea133fd7Smrg  XFREE (target_name);
6135ea133fd7Smrg  XFREE (actual_cwrapper_path);
6136ea133fd7Smrg  XFREE (actual_cwrapper_name);
6137a253d6aeSmrg
6138ea133fd7Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6139ea133fd7Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
614006f32fbeSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
614106f32fbeSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
614206f32fbeSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
614306f32fbeSmrg     libraries must come first. */
6144ea133fd7Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
614506f32fbeSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6146a253d6aeSmrg
614725b89263Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
614825b89263Smrg		  nonnull (lt_argv_zero));
6149ea133fd7Smrg  for (i = 0; i < newargc; i++)
6150ea133fd7Smrg    {
615125b89263Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
615225b89263Smrg		      i, nonnull (newargz[i]));
6153ea133fd7Smrg    }
6154a253d6aeSmrg
6155ea133fd7SmrgEOF
6156a253d6aeSmrg
6157ea133fd7Smrg	    case $host_os in
6158ea133fd7Smrg	      mingw*)
6159ea133fd7Smrg		cat <<"EOF"
6160ea133fd7Smrg  /* execv doesn't actually work on mingw as expected on unix */
616125b89263Smrg  newargz = prepare_spawn (newargz);
6162b41a30aaSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6163ea133fd7Smrg  if (rval == -1)
6164ea133fd7Smrg    {
6165ea133fd7Smrg      /* failed to start process */
616625b89263Smrg      lt_debugprintf (__FILE__, __LINE__,
616725b89263Smrg		      "(main) failed to launch target \"%s\": %s\n",
616825b89263Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6169ea133fd7Smrg      return 127;
6170ea133fd7Smrg    }
6171ea133fd7Smrg  return rval;
6172ea133fd7SmrgEOF
6173ea133fd7Smrg		;;
6174ea133fd7Smrg	      *)
6175ea133fd7Smrg		cat <<"EOF"
6176ea133fd7Smrg  execv (lt_argv_zero, newargz);
6177ea133fd7Smrg  return rval; /* =127, but avoids unused variable warning */
6178ea133fd7SmrgEOF
6179ea133fd7Smrg		;;
6180ea133fd7Smrg	    esac
6181a253d6aeSmrg
6182ea133fd7Smrg	    cat <<"EOF"
6183ea133fd7Smrg}
6184a253d6aeSmrg
6185ea133fd7Smrgvoid *
6186ea133fd7Smrgxmalloc (size_t num)
6187ea133fd7Smrg{
6188ea133fd7Smrg  void *p = (void *) malloc (num);
6189ea133fd7Smrg  if (!p)
619025b89263Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6191a253d6aeSmrg
6192ea133fd7Smrg  return p;
6193ea133fd7Smrg}
6194a253d6aeSmrg
6195ea133fd7Smrgchar *
6196ea133fd7Smrgxstrdup (const char *string)
6197ea133fd7Smrg{
6198ea133fd7Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6199ea133fd7Smrg			  string) : NULL;
6200ea133fd7Smrg}
6201a253d6aeSmrg
6202ea133fd7Smrgconst char *
6203ea133fd7Smrgbase_name (const char *name)
6204ea133fd7Smrg{
6205ea133fd7Smrg  const char *base;
6206a253d6aeSmrg
6207b41a30aaSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6208ea133fd7Smrg  /* Skip over the disk name in MSDOS pathnames. */
6209ea133fd7Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6210ea133fd7Smrg    name += 2;
6211ea133fd7Smrg#endif
6212a253d6aeSmrg
6213ea133fd7Smrg  for (base = name; *name; name++)
6214ea133fd7Smrg    if (IS_DIR_SEPARATOR (*name))
6215ea133fd7Smrg      base = name + 1;
6216ea133fd7Smrg  return base;
6217ea133fd7Smrg}
6218a253d6aeSmrg
6219ea133fd7Smrgint
6220ea133fd7Smrgcheck_executable (const char *path)
6221ea133fd7Smrg{
6222ea133fd7Smrg  struct stat st;
6223a253d6aeSmrg
622425b89263Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
622525b89263Smrg                  nonempty (path));
6226ea133fd7Smrg  if ((!path) || (!*path))
6227ea133fd7Smrg    return 0;
6228a253d6aeSmrg
6229ea133fd7Smrg  if ((stat (path, &st) >= 0)
6230ea133fd7Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6231ea133fd7Smrg    return 1;
6232ea133fd7Smrg  else
6233ea133fd7Smrg    return 0;
6234ea133fd7Smrg}
6235a253d6aeSmrg
6236ea133fd7Smrgint
6237ea133fd7Smrgmake_executable (const char *path)
6238ea133fd7Smrg{
6239ea133fd7Smrg  int rval = 0;
6240ea133fd7Smrg  struct stat st;
6241a253d6aeSmrg
624225b89263Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
624325b89263Smrg                  nonempty (path));
6244ea133fd7Smrg  if ((!path) || (!*path))
6245ea133fd7Smrg    return 0;
6246a253d6aeSmrg
6247ea133fd7Smrg  if (stat (path, &st) >= 0)
6248ea133fd7Smrg    {
6249ea133fd7Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6250ea133fd7Smrg    }
6251ea133fd7Smrg  return rval;
6252ea133fd7Smrg}
6253a253d6aeSmrg
6254ea133fd7Smrg/* Searches for the full path of the wrapper.  Returns
6255ea133fd7Smrg   newly allocated full path name if found, NULL otherwise
6256ea133fd7Smrg   Does not chase symlinks, even on platforms that support them.
6257ea133fd7Smrg*/
6258ea133fd7Smrgchar *
6259ea133fd7Smrgfind_executable (const char *wrapper)
6260ea133fd7Smrg{
6261ea133fd7Smrg  int has_slash = 0;
6262ea133fd7Smrg  const char *p;
6263ea133fd7Smrg  const char *p_next;
6264ea133fd7Smrg  /* static buffer for getcwd */
6265ea133fd7Smrg  char tmp[LT_PATHMAX + 1];
6266b41a30aaSmrg  size_t tmp_len;
6267ea133fd7Smrg  char *concat_name;
6268a253d6aeSmrg
626925b89263Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
627025b89263Smrg                  nonempty (wrapper));
6271a253d6aeSmrg
6272ea133fd7Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6273ea133fd7Smrg    return NULL;
6274a253d6aeSmrg
6275ea133fd7Smrg  /* Absolute path? */
6276b41a30aaSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6277ea133fd7Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6278ea133fd7Smrg    {
6279ea133fd7Smrg      concat_name = xstrdup (wrapper);
6280ea133fd7Smrg      if (check_executable (concat_name))
6281ea133fd7Smrg	return concat_name;
6282ea133fd7Smrg      XFREE (concat_name);
6283ea133fd7Smrg    }
6284ea133fd7Smrg  else
6285ea133fd7Smrg    {
6286ea133fd7Smrg#endif
6287ea133fd7Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6288ea133fd7Smrg	{
6289ea133fd7Smrg	  concat_name = xstrdup (wrapper);
6290ea133fd7Smrg	  if (check_executable (concat_name))
6291ea133fd7Smrg	    return concat_name;
6292ea133fd7Smrg	  XFREE (concat_name);
6293ea133fd7Smrg	}
6294b41a30aaSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6295ea133fd7Smrg    }
6296ea133fd7Smrg#endif
6297a253d6aeSmrg
6298ea133fd7Smrg  for (p = wrapper; *p; p++)
6299ea133fd7Smrg    if (*p == '/')
6300ea133fd7Smrg      {
6301ea133fd7Smrg	has_slash = 1;
6302ea133fd7Smrg	break;
6303ea133fd7Smrg      }
6304ea133fd7Smrg  if (!has_slash)
6305ea133fd7Smrg    {
6306ea133fd7Smrg      /* no slashes; search PATH */
6307ea133fd7Smrg      const char *path = getenv ("PATH");
6308ea133fd7Smrg      if (path != NULL)
6309ea133fd7Smrg	{
6310ea133fd7Smrg	  for (p = path; *p; p = p_next)
6311ea133fd7Smrg	    {
6312ea133fd7Smrg	      const char *q;
6313ea133fd7Smrg	      size_t p_len;
6314ea133fd7Smrg	      for (q = p; *q; q++)
6315ea133fd7Smrg		if (IS_PATH_SEPARATOR (*q))
6316ea133fd7Smrg		  break;
6317b41a30aaSmrg	      p_len = (size_t) (q - p);
6318ea133fd7Smrg	      p_next = (*q == '\0' ? q : q + 1);
6319ea133fd7Smrg	      if (p_len == 0)
6320ea133fd7Smrg		{
6321ea133fd7Smrg		  /* empty path: current directory */
6322ea133fd7Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
632325b89263Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
632425b89263Smrg                              nonnull (strerror (errno)));
6325ea133fd7Smrg		  tmp_len = strlen (tmp);
6326ea133fd7Smrg		  concat_name =
6327ea133fd7Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6328ea133fd7Smrg		  memcpy (concat_name, tmp, tmp_len);
6329ea133fd7Smrg		  concat_name[tmp_len] = '/';
6330ea133fd7Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6331ea133fd7Smrg		}
6332ea133fd7Smrg	      else
6333ea133fd7Smrg		{
6334ea133fd7Smrg		  concat_name =
6335ea133fd7Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6336ea133fd7Smrg		  memcpy (concat_name, p, p_len);
6337ea133fd7Smrg		  concat_name[p_len] = '/';
6338ea133fd7Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6339ea133fd7Smrg		}
6340ea133fd7Smrg	      if (check_executable (concat_name))
6341ea133fd7Smrg		return concat_name;
6342ea133fd7Smrg	      XFREE (concat_name);
6343ea133fd7Smrg	    }
6344ea133fd7Smrg	}
6345ea133fd7Smrg      /* not found in PATH; assume curdir */
6346ea133fd7Smrg    }
6347ea133fd7Smrg  /* Relative path | not found in path: prepend cwd */
6348ea133fd7Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
634925b89263Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
635025b89263Smrg              nonnull (strerror (errno)));
6351ea133fd7Smrg  tmp_len = strlen (tmp);
6352ea133fd7Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6353ea133fd7Smrg  memcpy (concat_name, tmp, tmp_len);
6354ea133fd7Smrg  concat_name[tmp_len] = '/';
6355ea133fd7Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6356a253d6aeSmrg
6357ea133fd7Smrg  if (check_executable (concat_name))
6358ea133fd7Smrg    return concat_name;
6359ea133fd7Smrg  XFREE (concat_name);
6360ea133fd7Smrg  return NULL;
6361ea133fd7Smrg}
6362a253d6aeSmrg
6363ea133fd7Smrgchar *
6364ea133fd7Smrgchase_symlinks (const char *pathspec)
6365ea133fd7Smrg{
6366ea133fd7Smrg#ifndef S_ISLNK
6367ea133fd7Smrg  return xstrdup (pathspec);
6368ea133fd7Smrg#else
6369ea133fd7Smrg  char buf[LT_PATHMAX];
6370ea133fd7Smrg  struct stat s;
6371ea133fd7Smrg  char *tmp_pathspec = xstrdup (pathspec);
6372ea133fd7Smrg  char *p;
6373ea133fd7Smrg  int has_symlinks = 0;
6374ea133fd7Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6375ea133fd7Smrg    {
637625b89263Smrg      lt_debugprintf (__FILE__, __LINE__,
637725b89263Smrg		      "checking path component for symlinks: %s\n",
637825b89263Smrg		      tmp_pathspec);
6379ea133fd7Smrg      if (lstat (tmp_pathspec, &s) == 0)
6380ea133fd7Smrg	{
6381ea133fd7Smrg	  if (S_ISLNK (s.st_mode) != 0)
6382ea133fd7Smrg	    {
6383ea133fd7Smrg	      has_symlinks = 1;
6384ea133fd7Smrg	      break;
6385ea133fd7Smrg	    }
6386a253d6aeSmrg
6387ea133fd7Smrg	  /* search backwards for last DIR_SEPARATOR */
6388ea133fd7Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6389ea133fd7Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6390ea133fd7Smrg	    p--;
6391ea133fd7Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6392ea133fd7Smrg	    {
6393ea133fd7Smrg	      /* no more DIR_SEPARATORS left */
6394ea133fd7Smrg	      break;
6395ea133fd7Smrg	    }
6396ea133fd7Smrg	  *p = '\0';
6397ea133fd7Smrg	}
6398ea133fd7Smrg      else
6399ea133fd7Smrg	{
640025b89263Smrg	  lt_fatal (__FILE__, __LINE__,
640125b89263Smrg		    "error accessing file \"%s\": %s",
640225b89263Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6403ea133fd7Smrg	}
6404ea133fd7Smrg    }
6405ea133fd7Smrg  XFREE (tmp_pathspec);
6406a253d6aeSmrg
6407ea133fd7Smrg  if (!has_symlinks)
6408ea133fd7Smrg    {
6409ea133fd7Smrg      return xstrdup (pathspec);
6410ea133fd7Smrg    }
6411a253d6aeSmrg
6412ea133fd7Smrg  tmp_pathspec = realpath (pathspec, buf);
6413ea133fd7Smrg  if (tmp_pathspec == 0)
6414ea133fd7Smrg    {
641525b89263Smrg      lt_fatal (__FILE__, __LINE__,
641625b89263Smrg		"could not follow symlinks for %s", pathspec);
6417ea133fd7Smrg    }
6418ea133fd7Smrg  return xstrdup (tmp_pathspec);
6419ea133fd7Smrg#endif
6420ea133fd7Smrg}
6421a253d6aeSmrg
6422ea133fd7Smrgchar *
6423ea133fd7Smrgstrendzap (char *str, const char *pat)
6424ea133fd7Smrg{
6425ea133fd7Smrg  size_t len, patlen;
6426a253d6aeSmrg
6427ea133fd7Smrg  assert (str != NULL);
6428ea133fd7Smrg  assert (pat != NULL);
6429a253d6aeSmrg
6430ea133fd7Smrg  len = strlen (str);
6431ea133fd7Smrg  patlen = strlen (pat);
6432a253d6aeSmrg
6433ea133fd7Smrg  if (patlen <= len)
6434ea133fd7Smrg    {
6435ea133fd7Smrg      str += len - patlen;
6436b41a30aaSmrg      if (STREQ (str, pat))
6437ea133fd7Smrg	*str = '\0';
6438ea133fd7Smrg    }
6439ea133fd7Smrg  return str;
6440ea133fd7Smrg}
6441a253d6aeSmrg
644225b89263Smrgvoid
644325b89263Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
644425b89263Smrg{
644525b89263Smrg  va_list args;
644625b89263Smrg  if (lt_debug)
644725b89263Smrg    {
644825b89263Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
644925b89263Smrg      va_start (args, fmt);
645025b89263Smrg      (void) vfprintf (stderr, fmt, args);
645125b89263Smrg      va_end (args);
645225b89263Smrg    }
645325b89263Smrg}
645425b89263Smrg
6455ea133fd7Smrgstatic void
645625b89263Smrglt_error_core (int exit_status, const char *file,
645725b89263Smrg	       int line, const char *mode,
6458ea133fd7Smrg	       const char *message, va_list ap)
6459ea133fd7Smrg{
646025b89263Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6461ea133fd7Smrg  vfprintf (stderr, message, ap);
6462ea133fd7Smrg  fprintf (stderr, ".\n");
6463a253d6aeSmrg
6464ea133fd7Smrg  if (exit_status >= 0)
6465ea133fd7Smrg    exit (exit_status);
6466ea133fd7Smrg}
6467a253d6aeSmrg
6468ea133fd7Smrgvoid
646925b89263Smrglt_fatal (const char *file, int line, const char *message, ...)
6470ea133fd7Smrg{
6471ea133fd7Smrg  va_list ap;
6472ea133fd7Smrg  va_start (ap, message);
647325b89263Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6474ea133fd7Smrg  va_end (ap);
6475ea133fd7Smrg}
6476a253d6aeSmrg
647725b89263Smrgstatic const char *
647825b89263Smrgnonnull (const char *s)
647925b89263Smrg{
648025b89263Smrg  return s ? s : "(null)";
648125b89263Smrg}
648225b89263Smrg
648325b89263Smrgstatic const char *
648425b89263Smrgnonempty (const char *s)
648525b89263Smrg{
648625b89263Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
648725b89263Smrg}
648825b89263Smrg
6489ea133fd7Smrgvoid
6490ea133fd7Smrglt_setenv (const char *name, const char *value)
6491ea133fd7Smrg{
649225b89263Smrg  lt_debugprintf (__FILE__, __LINE__,
649325b89263Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
649425b89263Smrg                  nonnull (name), nonnull (value));
6495ea133fd7Smrg  {
6496ea133fd7Smrg#ifdef HAVE_SETENV
6497ea133fd7Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6498ea133fd7Smrg    char *str = xstrdup (value);
6499ea133fd7Smrg    setenv (name, str, 1);
6500ea133fd7Smrg#else
6501b41a30aaSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6502ea133fd7Smrg    char *str = XMALLOC (char, len);
6503ea133fd7Smrg    sprintf (str, "%s=%s", name, value);
6504ea133fd7Smrg    if (putenv (str) != EXIT_SUCCESS)
6505ea133fd7Smrg      {
6506ea133fd7Smrg        XFREE (str);
6507ea133fd7Smrg      }
6508ea133fd7Smrg#endif
6509ea133fd7Smrg  }
6510ea133fd7Smrg}
6511a253d6aeSmrg
6512ea133fd7Smrgchar *
6513ea133fd7Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6514ea133fd7Smrg{
6515ea133fd7Smrg  char *new_value;
6516ea133fd7Smrg  if (orig_value && *orig_value)
6517ea133fd7Smrg    {
6518b41a30aaSmrg      size_t orig_value_len = strlen (orig_value);
6519b41a30aaSmrg      size_t add_len = strlen (add);
6520ea133fd7Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6521ea133fd7Smrg      if (to_end)
6522ea133fd7Smrg        {
6523ea133fd7Smrg          strcpy (new_value, orig_value);
6524ea133fd7Smrg          strcpy (new_value + orig_value_len, add);
6525ea133fd7Smrg        }
6526ea133fd7Smrg      else
6527ea133fd7Smrg        {
6528ea133fd7Smrg          strcpy (new_value, add);
6529ea133fd7Smrg          strcpy (new_value + add_len, orig_value);
6530ea133fd7Smrg        }
6531ea133fd7Smrg    }
6532ea133fd7Smrg  else
6533ea133fd7Smrg    {
6534ea133fd7Smrg      new_value = xstrdup (add);
6535ea133fd7Smrg    }
6536ea133fd7Smrg  return new_value;
6537ea133fd7Smrg}
6538a253d6aeSmrg
6539ea133fd7Smrgvoid
6540ea133fd7Smrglt_update_exe_path (const char *name, const char *value)
6541ea133fd7Smrg{
654225b89263Smrg  lt_debugprintf (__FILE__, __LINE__,
654325b89263Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
654425b89263Smrg                  nonnull (name), nonnull (value));
6545a253d6aeSmrg
6546ea133fd7Smrg  if (name && *name && value && *value)
6547ea133fd7Smrg    {
6548ea133fd7Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6549ea133fd7Smrg      /* some systems can't cope with a ':'-terminated path #' */
6550b41a30aaSmrg      size_t len = strlen (new_value);
6551b41a30aaSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6552ea133fd7Smrg        {
6553b41a30aaSmrg          new_value[--len] = '\0';
6554ea133fd7Smrg        }
6555ea133fd7Smrg      lt_setenv (name, new_value);
6556ea133fd7Smrg      XFREE (new_value);
6557ea133fd7Smrg    }
6558ea133fd7Smrg}
6559a253d6aeSmrg
6560ea133fd7Smrgvoid
6561ea133fd7Smrglt_update_lib_path (const char *name, const char *value)
6562ea133fd7Smrg{
656325b89263Smrg  lt_debugprintf (__FILE__, __LINE__,
656425b89263Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
656525b89263Smrg                  nonnull (name), nonnull (value));
6566a253d6aeSmrg
6567ea133fd7Smrg  if (name && *name && value && *value)
6568ea133fd7Smrg    {
6569ea133fd7Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6570ea133fd7Smrg      lt_setenv (name, new_value);
6571ea133fd7Smrg      XFREE (new_value);
6572ea133fd7Smrg    }
6573ea133fd7Smrg}
6574a253d6aeSmrg
657525b89263SmrgEOF
657625b89263Smrg	    case $host_os in
657725b89263Smrg	      mingw*)
657825b89263Smrg		cat <<"EOF"
657925b89263Smrg
658025b89263Smrg/* Prepares an argument vector before calling spawn().
658125b89263Smrg   Note that spawn() does not by itself call the command interpreter
658225b89263Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
658325b89263Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
658425b89263Smrg         GetVersionEx(&v);
658525b89263Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
658625b89263Smrg      }) ? "cmd.exe" : "command.com").
658725b89263Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
658825b89263Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
658925b89263Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
659025b89263Smrg   special way:
659125b89263Smrg   - Space and tab are interpreted as delimiters. They are not treated as
659225b89263Smrg     delimiters if they are surrounded by double quotes: "...".
659325b89263Smrg   - Unescaped double quotes are removed from the input. Their only effect is
659425b89263Smrg     that within double quotes, space and tab are treated like normal
659525b89263Smrg     characters.
659625b89263Smrg   - Backslashes not followed by double quotes are not special.
659725b89263Smrg   - But 2*n+1 backslashes followed by a double quote become
659825b89263Smrg     n backslashes followed by a double quote (n >= 0):
659925b89263Smrg       \" -> "
660025b89263Smrg       \\\" -> \"
660125b89263Smrg       \\\\\" -> \\"
660225b89263Smrg */
660325b89263Smrg#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"
660425b89263Smrg#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"
660525b89263Smrgchar **
660625b89263Smrgprepare_spawn (char **argv)
660725b89263Smrg{
660825b89263Smrg  size_t argc;
660925b89263Smrg  char **new_argv;
661025b89263Smrg  size_t i;
661125b89263Smrg
661225b89263Smrg  /* Count number of arguments.  */
661325b89263Smrg  for (argc = 0; argv[argc] != NULL; argc++)
661425b89263Smrg    ;
661525b89263Smrg
661625b89263Smrg  /* Allocate new argument vector.  */
661725b89263Smrg  new_argv = XMALLOC (char *, argc + 1);
661825b89263Smrg
661925b89263Smrg  /* Put quoted arguments into the new argument vector.  */
662025b89263Smrg  for (i = 0; i < argc; i++)
662125b89263Smrg    {
662225b89263Smrg      const char *string = argv[i];
662325b89263Smrg
662425b89263Smrg      if (string[0] == '\0')
662525b89263Smrg	new_argv[i] = xstrdup ("\"\"");
662625b89263Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
662725b89263Smrg	{
662825b89263Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
662925b89263Smrg	  size_t length;
663025b89263Smrg	  unsigned int backslashes;
663125b89263Smrg	  const char *s;
663225b89263Smrg	  char *quoted_string;
663325b89263Smrg	  char *p;
663425b89263Smrg
663525b89263Smrg	  length = 0;
663625b89263Smrg	  backslashes = 0;
663725b89263Smrg	  if (quote_around)
663825b89263Smrg	    length++;
663925b89263Smrg	  for (s = string; *s != '\0'; s++)
664025b89263Smrg	    {
664125b89263Smrg	      char c = *s;
664225b89263Smrg	      if (c == '"')
664325b89263Smrg		length += backslashes + 1;
664425b89263Smrg	      length++;
664525b89263Smrg	      if (c == '\\')
664625b89263Smrg		backslashes++;
664725b89263Smrg	      else
664825b89263Smrg		backslashes = 0;
664925b89263Smrg	    }
665025b89263Smrg	  if (quote_around)
665125b89263Smrg	    length += backslashes + 1;
665225b89263Smrg
665325b89263Smrg	  quoted_string = XMALLOC (char, length + 1);
665425b89263Smrg
665525b89263Smrg	  p = quoted_string;
665625b89263Smrg	  backslashes = 0;
665725b89263Smrg	  if (quote_around)
665825b89263Smrg	    *p++ = '"';
665925b89263Smrg	  for (s = string; *s != '\0'; s++)
666025b89263Smrg	    {
666125b89263Smrg	      char c = *s;
666225b89263Smrg	      if (c == '"')
666325b89263Smrg		{
666425b89263Smrg		  unsigned int j;
666525b89263Smrg		  for (j = backslashes + 1; j > 0; j--)
666625b89263Smrg		    *p++ = '\\';
666725b89263Smrg		}
666825b89263Smrg	      *p++ = c;
666925b89263Smrg	      if (c == '\\')
667025b89263Smrg		backslashes++;
667125b89263Smrg	      else
667225b89263Smrg		backslashes = 0;
667325b89263Smrg	    }
667425b89263Smrg	  if (quote_around)
667525b89263Smrg	    {
667625b89263Smrg	      unsigned int j;
667725b89263Smrg	      for (j = backslashes; j > 0; j--)
667825b89263Smrg		*p++ = '\\';
667925b89263Smrg	      *p++ = '"';
668025b89263Smrg	    }
668125b89263Smrg	  *p = '\0';
668225b89263Smrg
668325b89263Smrg	  new_argv[i] = quoted_string;
668425b89263Smrg	}
668525b89263Smrg      else
668625b89263Smrg	new_argv[i] = (char *) string;
668725b89263Smrg    }
668825b89263Smrg  new_argv[argc] = NULL;
668925b89263Smrg
669025b89263Smrg  return new_argv;
669125b89263Smrg}
669225b89263SmrgEOF
669325b89263Smrg		;;
669425b89263Smrg	    esac
669525b89263Smrg
669625b89263Smrg            cat <<"EOF"
669725b89263Smrgvoid lt_dump_script (FILE* f)
669825b89263Smrg{
669925b89263SmrgEOF
670025b89263Smrg	    func_emit_wrapper yes |
670157ee1794Smrg	      $SED -n -e '
670257ee1794Smrgs/^\(.\{79\}\)\(..*\)/\1\
670357ee1794Smrg\2/
670457ee1794Smrgh
670557ee1794Smrgs/\([\\"]\)/\\\1/g
670657ee1794Smrgs/$/\\n/
670757ee1794Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
670857ee1794Smrgg
670957ee1794SmrgD'
671025b89263Smrg            cat <<"EOF"
671125b89263Smrg}
6712ea133fd7SmrgEOF
6713ea133fd7Smrg}
6714ea133fd7Smrg# end: func_emit_cwrapperexe_src
6715a253d6aeSmrg
671625b89263Smrg# func_win32_import_lib_p ARG
671725b89263Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
671825b89263Smrgfunc_win32_import_lib_p ()
671925b89263Smrg{
6720b41a30aaSmrg    $debug_cmd
6721b41a30aaSmrg
672225b89263Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
672325b89263Smrg    *import*) : ;;
672425b89263Smrg    *) false ;;
672525b89263Smrg    esac
672625b89263Smrg}
672725b89263Smrg
6728b41a30aaSmrg# func_suncc_cstd_abi
6729b41a30aaSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730b41a30aaSmrg# Several compiler flags select an ABI that is incompatible with the
6731b41a30aaSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732b41a30aaSmrgfunc_suncc_cstd_abi ()
6733b41a30aaSmrg{
6734b41a30aaSmrg    $debug_cmd
6735b41a30aaSmrg
6736b41a30aaSmrg    case " $compile_command " in
6737b41a30aaSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738b41a30aaSmrg      suncc_use_cstd_abi=no
6739b41a30aaSmrg      ;;
6740b41a30aaSmrg    *)
6741b41a30aaSmrg      suncc_use_cstd_abi=yes
6742b41a30aaSmrg      ;;
6743b41a30aaSmrg    esac
6744b41a30aaSmrg}
6745b41a30aaSmrg
6746ea133fd7Smrg# func_mode_link arg...
6747ea133fd7Smrgfunc_mode_link ()
6748ea133fd7Smrg{
6749b41a30aaSmrg    $debug_cmd
6750b41a30aaSmrg
6751ea133fd7Smrg    case $host in
6752ea133fd7Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6753ea133fd7Smrg      # It is impossible to link a dll without this setting, and
6754ea133fd7Smrg      # we shouldn't force the makefile maintainer to figure out
6755b41a30aaSmrg      # what system we are compiling for in order to pass an extra
6756ea133fd7Smrg      # flag for every libtool invocation.
6757ea133fd7Smrg      # allow_undefined=no
6758a253d6aeSmrg
6759ea133fd7Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6760b41a30aaSmrg      # to make a dll that has undefined symbols, in which case not
6761ea133fd7Smrg      # even a static library is built.  For now, we need to specify
6762ea133fd7Smrg      # -no-undefined on the libtool link line when we can be certain
6763ea133fd7Smrg      # that all symbols are satisfied, otherwise we get a static library.
6764ea133fd7Smrg      allow_undefined=yes
6765ea133fd7Smrg      ;;
6766ea133fd7Smrg    *)
6767ea133fd7Smrg      allow_undefined=yes
6768ea133fd7Smrg      ;;
6769ea133fd7Smrg    esac
6770ea133fd7Smrg    libtool_args=$nonopt
6771ea133fd7Smrg    base_compile="$nonopt $@"
6772ea133fd7Smrg    compile_command=$nonopt
6773ea133fd7Smrg    finalize_command=$nonopt
6774a253d6aeSmrg
6775ea133fd7Smrg    compile_rpath=
6776ea133fd7Smrg    finalize_rpath=
6777ea133fd7Smrg    compile_shlibpath=
6778ea133fd7Smrg    finalize_shlibpath=
6779ea133fd7Smrg    convenience=
6780ea133fd7Smrg    old_convenience=
6781ea133fd7Smrg    deplibs=
6782ea133fd7Smrg    old_deplibs=
6783ea133fd7Smrg    compiler_flags=
6784ea133fd7Smrg    linker_flags=
6785ea133fd7Smrg    dllsearchpath=
6786ea133fd7Smrg    lib_search_path=`pwd`
6787ea133fd7Smrg    inst_prefix_dir=
6788ea133fd7Smrg    new_inherited_linker_flags=
6789a253d6aeSmrg
6790ea133fd7Smrg    avoid_version=no
679125b89263Smrg    bindir=
6792ea133fd7Smrg    dlfiles=
6793ea133fd7Smrg    dlprefiles=
6794ea133fd7Smrg    dlself=no
6795ea133fd7Smrg    export_dynamic=no
6796ea133fd7Smrg    export_symbols=
6797ea133fd7Smrg    export_symbols_regex=
6798ea133fd7Smrg    generated=
6799ea133fd7Smrg    libobjs=
6800ea133fd7Smrg    ltlibs=
6801ea133fd7Smrg    module=no
6802ea133fd7Smrg    no_install=no
6803ea133fd7Smrg    objs=
6804b41a30aaSmrg    os2dllname=
6805ea133fd7Smrg    non_pic_objects=
6806ea133fd7Smrg    precious_files_regex=
6807ea133fd7Smrg    prefer_static_libs=no
6808b41a30aaSmrg    preload=false
6809ea133fd7Smrg    prev=
6810ea133fd7Smrg    prevarg=
6811ea133fd7Smrg    release=
6812ea133fd7Smrg    rpath=
6813ea133fd7Smrg    xrpath=
6814ea133fd7Smrg    perm_rpath=
6815ea133fd7Smrg    temp_rpath=
6816ea133fd7Smrg    thread_safe=no
6817ea133fd7Smrg    vinfo=
6818ea133fd7Smrg    vinfo_number=no
6819ea133fd7Smrg    weak_libs=
6820b41a30aaSmrg    single_module=$wl-single_module
6821ea133fd7Smrg    func_infer_tag $base_compile
6822a253d6aeSmrg
6823ea133fd7Smrg    # We need to know -static, to get the right output filenames.
6824ea133fd7Smrg    for arg
6825ea133fd7Smrg    do
6826ea133fd7Smrg      case $arg in
6827ea133fd7Smrg      -shared)
6828b41a30aaSmrg	test yes != "$build_libtool_libs" \
6829b41a30aaSmrg	  && func_fatal_configuration "cannot build a shared library"
6830ea133fd7Smrg	build_old_libs=no
6831ea133fd7Smrg	break
6832ea133fd7Smrg	;;
6833ea133fd7Smrg      -all-static | -static | -static-libtool-libs)
6834ea133fd7Smrg	case $arg in
6835ea133fd7Smrg	-all-static)
6836b41a30aaSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6837ea133fd7Smrg	    func_warning "complete static linking is impossible in this configuration"
6838a253d6aeSmrg	  fi
6839ea133fd7Smrg	  if test -n "$link_static_flag"; then
6840ea133fd7Smrg	    dlopen_self=$dlopen_self_static
6841a253d6aeSmrg	  fi
6842ea133fd7Smrg	  prefer_static_libs=yes
6843a253d6aeSmrg	  ;;
6844ea133fd7Smrg	-static)
6845ea133fd7Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6846ea133fd7Smrg	    dlopen_self=$dlopen_self_static
6847ea133fd7Smrg	  fi
6848ea133fd7Smrg	  prefer_static_libs=built
6849ea133fd7Smrg	  ;;
6850ea133fd7Smrg	-static-libtool-libs)
6851ea133fd7Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6852ea133fd7Smrg	    dlopen_self=$dlopen_self_static
6853ea133fd7Smrg	  fi
6854ea133fd7Smrg	  prefer_static_libs=yes
6855a253d6aeSmrg	  ;;
6856a253d6aeSmrg	esac
6857ea133fd7Smrg	build_libtool_libs=no
6858ea133fd7Smrg	build_old_libs=yes
6859ea133fd7Smrg	break
6860ea133fd7Smrg	;;
6861ea133fd7Smrg      esac
6862ea133fd7Smrg    done
6863a253d6aeSmrg
6864ea133fd7Smrg    # See if our shared archives depend on static archives.
6865ea133fd7Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6866a253d6aeSmrg
6867ea133fd7Smrg    # Go through the arguments, transforming them on the way.
6868ea133fd7Smrg    while test "$#" -gt 0; do
6869b41a30aaSmrg      arg=$1
6870ea133fd7Smrg      shift
6871b41a30aaSmrg      func_quote_arg pretty,unquoted "$arg"
6872b41a30aaSmrg      qarg=$func_quote_arg_unquoted_result
6873b41a30aaSmrg      func_append libtool_args " $func_quote_arg_result"
6874a253d6aeSmrg
6875ea133fd7Smrg      # If the previous option needs an argument, assign it.
6876ea133fd7Smrg      if test -n "$prev"; then
6877ea133fd7Smrg	case $prev in
6878ea133fd7Smrg	output)
6879ea133fd7Smrg	  func_append compile_command " @OUTPUT@"
6880ea133fd7Smrg	  func_append finalize_command " @OUTPUT@"
6881ea133fd7Smrg	  ;;
6882ea133fd7Smrg	esac
6883a253d6aeSmrg
6884ea133fd7Smrg	case $prev in
688525b89263Smrg	bindir)
6886b41a30aaSmrg	  bindir=$arg
688725b89263Smrg	  prev=
688825b89263Smrg	  continue
688925b89263Smrg	  ;;
6890ea133fd7Smrg	dlfiles|dlprefiles)
6891b41a30aaSmrg	  $preload || {
6892ea133fd7Smrg	    # Add the symbol object into the linking commands.
6893ea133fd7Smrg	    func_append compile_command " @SYMFILE@"
6894ea133fd7Smrg	    func_append finalize_command " @SYMFILE@"
6895b41a30aaSmrg	    preload=:
6896b41a30aaSmrg	  }
6897ea133fd7Smrg	  case $arg in
6898ea133fd7Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6899ea133fd7Smrg	  force)
6900b41a30aaSmrg	    if test no = "$dlself"; then
6901ea133fd7Smrg	      dlself=needless
6902ea133fd7Smrg	      export_dynamic=yes
6903ea133fd7Smrg	    fi
6904ea133fd7Smrg	    prev=
6905ea133fd7Smrg	    continue
6906ea133fd7Smrg	    ;;
6907ea133fd7Smrg	  self)
6908b41a30aaSmrg	    if test dlprefiles = "$prev"; then
6909ea133fd7Smrg	      dlself=yes
6910b41a30aaSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6911ea133fd7Smrg	      dlself=yes
6912ea133fd7Smrg	    else
6913ea133fd7Smrg	      dlself=needless
6914ea133fd7Smrg	      export_dynamic=yes
6915ea133fd7Smrg	    fi
6916ea133fd7Smrg	    prev=
6917ea133fd7Smrg	    continue
6918a253d6aeSmrg	    ;;
6919a253d6aeSmrg	  *)
6920b41a30aaSmrg	    if test dlfiles = "$prev"; then
692106f32fbeSmrg	      func_append dlfiles " $arg"
6922ea133fd7Smrg	    else
692306f32fbeSmrg	      func_append dlprefiles " $arg"
6924ea133fd7Smrg	    fi
6925ea133fd7Smrg	    prev=
6926ea133fd7Smrg	    continue
6927a253d6aeSmrg	    ;;
6928a253d6aeSmrg	  esac
6929ea133fd7Smrg	  ;;
6930ea133fd7Smrg	expsyms)
6931b41a30aaSmrg	  export_symbols=$arg
6932ea133fd7Smrg	  test -f "$arg" \
6933b41a30aaSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
6934ea133fd7Smrg	  prev=
6935ea133fd7Smrg	  continue
6936ea133fd7Smrg	  ;;
6937ea133fd7Smrg	expsyms_regex)
6938b41a30aaSmrg	  export_symbols_regex=$arg
6939ea133fd7Smrg	  prev=
6940ea133fd7Smrg	  continue
6941ea133fd7Smrg	  ;;
6942ea133fd7Smrg	framework)
6943ea133fd7Smrg	  case $host in
6944ea133fd7Smrg	    *-*-darwin*)
6945ea133fd7Smrg	      case "$deplibs " in
6946ea133fd7Smrg		*" $qarg.ltframework "*) ;;
694706f32fbeSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6948ea133fd7Smrg		   ;;
6949ea133fd7Smrg	      esac
6950ea133fd7Smrg	      ;;
6951ea133fd7Smrg	  esac
6952ea133fd7Smrg	  prev=
6953ea133fd7Smrg	  continue
6954ea133fd7Smrg	  ;;
6955ea133fd7Smrg	inst_prefix)
6956b41a30aaSmrg	  inst_prefix_dir=$arg
6957b41a30aaSmrg	  prev=
6958b41a30aaSmrg	  continue
6959b41a30aaSmrg	  ;;
6960b41a30aaSmrg	mllvm)
6961b41a30aaSmrg	  # Clang does not use LLVM to link, so we can simply discard any
6962b41a30aaSmrg	  # '-mllvm $arg' options when doing the link step.
6963ea133fd7Smrg	  prev=
6964ea133fd7Smrg	  continue
6965ea133fd7Smrg	  ;;
6966ea133fd7Smrg	objectlist)
6967ea133fd7Smrg	  if test -f "$arg"; then
6968ea133fd7Smrg	    save_arg=$arg
6969ea133fd7Smrg	    moreargs=
6970ea133fd7Smrg	    for fil in `cat "$save_arg"`
6971ea133fd7Smrg	    do
697206f32fbeSmrg#	      func_append moreargs " $fil"
6973ea133fd7Smrg	      arg=$fil
6974ea133fd7Smrg	      # A libtool-controlled object.
6975a253d6aeSmrg
6976ea133fd7Smrg	      # Check to see that this really is a libtool object.
6977ea133fd7Smrg	      if func_lalib_unsafe_p "$arg"; then
6978ea133fd7Smrg		pic_object=
6979ea133fd7Smrg		non_pic_object=
6980a253d6aeSmrg
6981ea133fd7Smrg		# Read the .lo file
6982ea133fd7Smrg		func_source "$arg"
6983a253d6aeSmrg
6984ea133fd7Smrg		if test -z "$pic_object" ||
6985ea133fd7Smrg		   test -z "$non_pic_object" ||
6986b41a30aaSmrg		   test none = "$pic_object" &&
6987b41a30aaSmrg		   test none = "$non_pic_object"; then
6988b41a30aaSmrg		  func_fatal_error "cannot find name of object for '$arg'"
6989ea133fd7Smrg		fi
6990a253d6aeSmrg
6991ea133fd7Smrg		# Extract subdirectory from the argument.
6992ea133fd7Smrg		func_dirname "$arg" "/" ""
6993b41a30aaSmrg		xdir=$func_dirname_result
6994a253d6aeSmrg
6995b41a30aaSmrg		if test none != "$pic_object"; then
6996ea133fd7Smrg		  # Prepend the subdirectory the object is found in.
6997b41a30aaSmrg		  pic_object=$xdir$pic_object
6998a253d6aeSmrg
6999b41a30aaSmrg		  if test dlfiles = "$prev"; then
7000b41a30aaSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
700106f32fbeSmrg		      func_append dlfiles " $pic_object"
7002ea133fd7Smrg		      prev=
7003ea133fd7Smrg		      continue
7004ea133fd7Smrg		    else
7005ea133fd7Smrg		      # If libtool objects are unsupported, then we need to preload.
7006ea133fd7Smrg		      prev=dlprefiles
7007ea133fd7Smrg		    fi
7008ea133fd7Smrg		  fi
7009a253d6aeSmrg
7010ea133fd7Smrg		  # CHECK ME:  I think I busted this.  -Ossama
7011b41a30aaSmrg		  if test dlprefiles = "$prev"; then
7012ea133fd7Smrg		    # Preload the old-style object.
701306f32fbeSmrg		    func_append dlprefiles " $pic_object"
7014ea133fd7Smrg		    prev=
7015ea133fd7Smrg		  fi
7016a253d6aeSmrg
7017ea133fd7Smrg		  # A PIC object.
7018ea133fd7Smrg		  func_append libobjs " $pic_object"
7019b41a30aaSmrg		  arg=$pic_object
7020ea133fd7Smrg		fi
7021a253d6aeSmrg
7022ea133fd7Smrg		# Non-PIC object.
7023b41a30aaSmrg		if test none != "$non_pic_object"; then
7024ea133fd7Smrg		  # Prepend the subdirectory the object is found in.
7025b41a30aaSmrg		  non_pic_object=$xdir$non_pic_object
7026a253d6aeSmrg
7027ea133fd7Smrg		  # A standard non-PIC object
7028ea133fd7Smrg		  func_append non_pic_objects " $non_pic_object"
7029b41a30aaSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030b41a30aaSmrg		    arg=$non_pic_object
7031ea133fd7Smrg		  fi
7032ea133fd7Smrg		else
7033ea133fd7Smrg		  # If the PIC object exists, use it instead.
7034ea133fd7Smrg		  # $xdir was prepended to $pic_object above.
7035b41a30aaSmrg		  non_pic_object=$pic_object
7036ea133fd7Smrg		  func_append non_pic_objects " $non_pic_object"
7037ea133fd7Smrg		fi
7038ea133fd7Smrg	      else
7039ea133fd7Smrg		# Only an error if not doing a dry-run.
7040ea133fd7Smrg		if $opt_dry_run; then
7041ea133fd7Smrg		  # Extract subdirectory from the argument.
7042ea133fd7Smrg		  func_dirname "$arg" "/" ""
7043b41a30aaSmrg		  xdir=$func_dirname_result
7044ea133fd7Smrg
7045ea133fd7Smrg		  func_lo2o "$arg"
7046ea133fd7Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
7047ea133fd7Smrg		  non_pic_object=$xdir$func_lo2o_result
7048ea133fd7Smrg		  func_append libobjs " $pic_object"
7049ea133fd7Smrg		  func_append non_pic_objects " $non_pic_object"
7050ea133fd7Smrg	        else
7051b41a30aaSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
7052ea133fd7Smrg		fi
7053ea133fd7Smrg	      fi
7054ea133fd7Smrg	    done
7055ea133fd7Smrg	  else
7056b41a30aaSmrg	    func_fatal_error "link input file '$arg' does not exist"
7057ea133fd7Smrg	  fi
7058ea133fd7Smrg	  arg=$save_arg
7059ea133fd7Smrg	  prev=
7060ea133fd7Smrg	  continue
7061ea133fd7Smrg	  ;;
7062b41a30aaSmrg	os2dllname)
7063b41a30aaSmrg	  os2dllname=$arg
7064b41a30aaSmrg	  prev=
7065b41a30aaSmrg	  continue
7066b41a30aaSmrg	  ;;
7067ea133fd7Smrg	precious_regex)
7068b41a30aaSmrg	  precious_files_regex=$arg
7069ea133fd7Smrg	  prev=
7070ea133fd7Smrg	  continue
7071ea133fd7Smrg	  ;;
7072ea133fd7Smrg	release)
7073b41a30aaSmrg	  release=-$arg
7074ea133fd7Smrg	  prev=
7075ea133fd7Smrg	  continue
7076ea133fd7Smrg	  ;;
7077ea133fd7Smrg	rpath | xrpath)
7078ea133fd7Smrg	  # We need an absolute path.
7079ea133fd7Smrg	  case $arg in
7080ea133fd7Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7081ea133fd7Smrg	  *)
7082ea133fd7Smrg	    func_fatal_error "only absolute run-paths are allowed"
7083ea133fd7Smrg	    ;;
7084ea133fd7Smrg	  esac
7085b41a30aaSmrg	  if test rpath = "$prev"; then
7086ea133fd7Smrg	    case "$rpath " in
7087ea133fd7Smrg	    *" $arg "*) ;;
708806f32fbeSmrg	    *) func_append rpath " $arg" ;;
7089ea133fd7Smrg	    esac
7090ea133fd7Smrg	  else
7091ea133fd7Smrg	    case "$xrpath " in
7092ea133fd7Smrg	    *" $arg "*) ;;
709306f32fbeSmrg	    *) func_append xrpath " $arg" ;;
7094ea133fd7Smrg	    esac
7095ea133fd7Smrg	  fi
7096ea133fd7Smrg	  prev=
7097ea133fd7Smrg	  continue
7098ea133fd7Smrg	  ;;
7099ea133fd7Smrg	shrext)
7100b41a30aaSmrg	  shrext_cmds=$arg
7101ea133fd7Smrg	  prev=
7102ea133fd7Smrg	  continue
7103ea133fd7Smrg	  ;;
7104ea133fd7Smrg	weak)
710506f32fbeSmrg	  func_append weak_libs " $arg"
7106ea133fd7Smrg	  prev=
7107ea133fd7Smrg	  continue
7108ea133fd7Smrg	  ;;
7109b41a30aaSmrg	xassembler)
7110b41a30aaSmrg	  func_append compiler_flags " -Xassembler $qarg"
7111b41a30aaSmrg	  prev=
7112b41a30aaSmrg	  func_append compile_command " -Xassembler $qarg"
7113b41a30aaSmrg	  func_append finalize_command " -Xassembler $qarg"
7114b41a30aaSmrg	  continue
7115b41a30aaSmrg	  ;;
7116ea133fd7Smrg	xcclinker)
711706f32fbeSmrg	  func_append linker_flags " $qarg"
711806f32fbeSmrg	  func_append compiler_flags " $qarg"
7119ea133fd7Smrg	  prev=
7120ea133fd7Smrg	  func_append compile_command " $qarg"
7121ea133fd7Smrg	  func_append finalize_command " $qarg"
7122ea133fd7Smrg	  continue
7123ea133fd7Smrg	  ;;
7124ea133fd7Smrg	xcompiler)
712506f32fbeSmrg	  func_append compiler_flags " $qarg"
7126ea133fd7Smrg	  prev=
7127ea133fd7Smrg	  func_append compile_command " $qarg"
7128ea133fd7Smrg	  func_append finalize_command " $qarg"
7129ea133fd7Smrg	  continue
7130ea133fd7Smrg	  ;;
7131ea133fd7Smrg	xlinker)
713206f32fbeSmrg	  func_append linker_flags " $qarg"
713306f32fbeSmrg	  func_append compiler_flags " $wl$qarg"
7134ea133fd7Smrg	  prev=
7135ea133fd7Smrg	  func_append compile_command " $wl$qarg"
7136ea133fd7Smrg	  func_append finalize_command " $wl$qarg"
7137ea133fd7Smrg	  continue
7138ea133fd7Smrg	  ;;
7139ea133fd7Smrg	*)
7140ea133fd7Smrg	  eval "$prev=\"\$arg\""
7141ea133fd7Smrg	  prev=
7142ea133fd7Smrg	  continue
7143ea133fd7Smrg	  ;;
7144a253d6aeSmrg	esac
7145ea133fd7Smrg      fi # test -n "$prev"
7146a253d6aeSmrg
7147b41a30aaSmrg      prevarg=$arg
7148a253d6aeSmrg
7149ea133fd7Smrg      case $arg in
7150ea133fd7Smrg      -all-static)
7151ea133fd7Smrg	if test -n "$link_static_flag"; then
7152ea133fd7Smrg	  # See comment for -static flag below, for more details.
7153ea133fd7Smrg	  func_append compile_command " $link_static_flag"
7154ea133fd7Smrg	  func_append finalize_command " $link_static_flag"
7155ea133fd7Smrg	fi
7156ea133fd7Smrg	continue
7157ea133fd7Smrg	;;
7158a253d6aeSmrg
7159ea133fd7Smrg      -allow-undefined)
7160ea133fd7Smrg	# FIXME: remove this flag sometime in the future.
7161b41a30aaSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7162ea133fd7Smrg	;;
7163a253d6aeSmrg
7164ea133fd7Smrg      -avoid-version)
7165ea133fd7Smrg	avoid_version=yes
7166ea133fd7Smrg	continue
7167ea133fd7Smrg	;;
7168a253d6aeSmrg
716925b89263Smrg      -bindir)
717025b89263Smrg	prev=bindir
717125b89263Smrg	continue
717225b89263Smrg	;;
717325b89263Smrg
7174ea133fd7Smrg      -dlopen)
7175ea133fd7Smrg	prev=dlfiles
7176ea133fd7Smrg	continue
7177ea133fd7Smrg	;;
7178a253d6aeSmrg
7179ea133fd7Smrg      -dlpreopen)
7180ea133fd7Smrg	prev=dlprefiles
7181ea133fd7Smrg	continue
7182ea133fd7Smrg	;;
7183a253d6aeSmrg
7184ea133fd7Smrg      -export-dynamic)
7185ea133fd7Smrg	export_dynamic=yes
7186ea133fd7Smrg	continue
7187ea133fd7Smrg	;;
7188a253d6aeSmrg
7189ea133fd7Smrg      -export-symbols | -export-symbols-regex)
7190ea133fd7Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7191ea133fd7Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7192ea133fd7Smrg	fi
7193b41a30aaSmrg	if test X-export-symbols = "X$arg"; then
7194ea133fd7Smrg	  prev=expsyms
7195ea133fd7Smrg	else
7196ea133fd7Smrg	  prev=expsyms_regex
7197ea133fd7Smrg	fi
7198ea133fd7Smrg	continue
7199ea133fd7Smrg	;;
7200a253d6aeSmrg
7201ea133fd7Smrg      -framework)
7202ea133fd7Smrg	prev=framework
7203ea133fd7Smrg	continue
7204ea133fd7Smrg	;;
7205a253d6aeSmrg
7206ea133fd7Smrg      -inst-prefix-dir)
7207ea133fd7Smrg	prev=inst_prefix
7208ea133fd7Smrg	continue
7209ea133fd7Smrg	;;
7210a253d6aeSmrg
7211ea133fd7Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7212ea133fd7Smrg      # so, if we see these flags be careful not to treat them like -L
7213ea133fd7Smrg      -L[A-Z][A-Z]*:*)
7214ea133fd7Smrg	case $with_gcc/$host in
7215ea133fd7Smrg	no/*-*-irix* | /*-*-irix*)
7216ea133fd7Smrg	  func_append compile_command " $arg"
7217ea133fd7Smrg	  func_append finalize_command " $arg"
7218ea133fd7Smrg	  ;;
7219ea133fd7Smrg	esac
7220ea133fd7Smrg	continue
7221ea133fd7Smrg	;;
7222a253d6aeSmrg
7223ea133fd7Smrg      -L*)
722406f32fbeSmrg	func_stripname "-L" '' "$arg"
722506f32fbeSmrg	if test -z "$func_stripname_result"; then
7226ea133fd7Smrg	  if test "$#" -gt 0; then
7227b41a30aaSmrg	    func_fatal_error "require no space between '-L' and '$1'"
7228ea133fd7Smrg	  else
7229b41a30aaSmrg	    func_fatal_error "need path for '-L' option"
7230ea133fd7Smrg	  fi
7231ea133fd7Smrg	fi
723206f32fbeSmrg	func_resolve_sysroot "$func_stripname_result"
723306f32fbeSmrg	dir=$func_resolve_sysroot_result
7234ea133fd7Smrg	# We need an absolute path.
7235ea133fd7Smrg	case $dir in
7236ea133fd7Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7237ea133fd7Smrg	*)
7238ea133fd7Smrg	  absdir=`cd "$dir" && pwd`
7239ea133fd7Smrg	  test -z "$absdir" && \
7240b41a30aaSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241b41a30aaSmrg	  dir=$absdir
7242ea133fd7Smrg	  ;;
7243ea133fd7Smrg	esac
7244ea133fd7Smrg	case "$deplibs " in
724506f32fbeSmrg	*" -L$dir "* | *" $arg "*)
724606f32fbeSmrg	  # Will only happen for absolute or sysroot arguments
724706f32fbeSmrg	  ;;
7248ea133fd7Smrg	*)
724906f32fbeSmrg	  # Preserve sysroot, but never include relative directories
725006f32fbeSmrg	  case $dir in
725106f32fbeSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
725206f32fbeSmrg	    *) func_append deplibs " -L$dir" ;;
725306f32fbeSmrg	  esac
725406f32fbeSmrg	  func_append lib_search_path " $dir"
7255ea133fd7Smrg	  ;;
7256ea133fd7Smrg	esac
7257ea133fd7Smrg	case $host in
7258ea133fd7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
725925b89263Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7260ea133fd7Smrg	  case :$dllsearchpath: in
7261ea133fd7Smrg	  *":$dir:"*) ;;
7262ea133fd7Smrg	  ::) dllsearchpath=$dir;;
726306f32fbeSmrg	  *) func_append dllsearchpath ":$dir";;
7264ea133fd7Smrg	  esac
7265ea133fd7Smrg	  case :$dllsearchpath: in
7266ea133fd7Smrg	  *":$testbindir:"*) ;;
7267ea133fd7Smrg	  ::) dllsearchpath=$testbindir;;
726806f32fbeSmrg	  *) func_append dllsearchpath ":$testbindir";;
7269ea133fd7Smrg	  esac
7270ea133fd7Smrg	  ;;
7271ea133fd7Smrg	esac
7272ea133fd7Smrg	continue
7273ea133fd7Smrg	;;
7274a253d6aeSmrg
7275ea133fd7Smrg      -l*)
7276b41a30aaSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7277ea133fd7Smrg	  case $host in
727825b89263Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7279ea133fd7Smrg	    # These systems don't actually have a C or math library (as such)
7280ea133fd7Smrg	    continue
7281ea133fd7Smrg	    ;;
7282ea133fd7Smrg	  *-*-os2*)
7283ea133fd7Smrg	    # These systems don't actually have a C library (as such)
7284b41a30aaSmrg	    test X-lc = "X$arg" && continue
7285ea133fd7Smrg	    ;;
7286b41a30aaSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7287ea133fd7Smrg	    # Do not include libc due to us having libc/libc_r.
7288b41a30aaSmrg	    test X-lc = "X$arg" && continue
7289ea133fd7Smrg	    ;;
7290ea133fd7Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7291ea133fd7Smrg	    # Rhapsody C and math libraries are in the System framework
729206f32fbeSmrg	    func_append deplibs " System.ltframework"
7293ea133fd7Smrg	    continue
7294ea133fd7Smrg	    ;;
7295ea133fd7Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7296ea133fd7Smrg	    # Causes problems with __ctype
7297b41a30aaSmrg	    test X-lc = "X$arg" && continue
7298ea133fd7Smrg	    ;;
7299ea133fd7Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7300ea133fd7Smrg	    # Compiler inserts libc in the correct place for threads to work
7301b41a30aaSmrg	    test X-lc = "X$arg" && continue
7302ea133fd7Smrg	    ;;
7303ea133fd7Smrg	  esac
7304b41a30aaSmrg	elif test X-lc_r = "X$arg"; then
7305ea133fd7Smrg	 case $host in
7306b41a30aaSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7307ea133fd7Smrg	   # Do not include libc_r directly, use -pthread flag.
7308ea133fd7Smrg	   continue
7309ea133fd7Smrg	   ;;
7310ea133fd7Smrg	 esac
7311ea133fd7Smrg	fi
731206f32fbeSmrg	func_append deplibs " $arg"
7313ea133fd7Smrg	continue
7314ea133fd7Smrg	;;
7315a253d6aeSmrg
7316b41a30aaSmrg      -mllvm)
7317b41a30aaSmrg	prev=mllvm
7318b41a30aaSmrg	continue
7319b41a30aaSmrg	;;
7320b41a30aaSmrg
7321ea133fd7Smrg      -module)
7322ea133fd7Smrg	module=yes
7323ea133fd7Smrg	continue
7324ea133fd7Smrg	;;
7325a253d6aeSmrg
7326ea133fd7Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7327ea133fd7Smrg      # classes, name mangling, and exception handling.
7328ea133fd7Smrg      # Darwin uses the -arch flag to determine output architecture.
732906f32fbeSmrg      -model|-arch|-isysroot|--sysroot)
733006f32fbeSmrg	func_append compiler_flags " $arg"
7331ea133fd7Smrg	func_append compile_command " $arg"
7332ea133fd7Smrg	func_append finalize_command " $arg"
7333ea133fd7Smrg	prev=xcompiler
7334ea133fd7Smrg	continue
7335ea133fd7Smrg	;;
7336b41a30aaSmrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337b41a30aaSmrg     -pthread)
7338b41a30aaSmrg	case $host in
7339b41a30aaSmrg	  *solaris2*) ;;
7340b41a30aaSmrg	  *)
7341b41a30aaSmrg	    case "$new_inherited_linker_flags " in
7342b41a30aaSmrg	        *" $arg "*) ;;
7343b41a30aaSmrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344b41a30aaSmrg	    esac
7345b41a30aaSmrg	  ;;
7346b41a30aaSmrg	esac
7347b41a30aaSmrg	continue
7348b41a30aaSmrg	;;
7349b41a30aaSmrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
735057ee1794Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
735106f32fbeSmrg	func_append compiler_flags " $arg"
7352ea133fd7Smrg	func_append compile_command " $arg"
7353ea133fd7Smrg	func_append finalize_command " $arg"
7354ea133fd7Smrg	case "$new_inherited_linker_flags " in
7355ea133fd7Smrg	    *" $arg "*) ;;
735606f32fbeSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7357ea133fd7Smrg	esac
7358ea133fd7Smrg	continue
7359ea133fd7Smrg	;;
7360a253d6aeSmrg
7361ea133fd7Smrg      -multi_module)
7362b41a30aaSmrg	single_module=$wl-multi_module
7363ea133fd7Smrg	continue
7364ea133fd7Smrg	;;
7365a253d6aeSmrg
7366ea133fd7Smrg      -no-fast-install)
7367ea133fd7Smrg	fast_install=no
7368ea133fd7Smrg	continue
7369ea133fd7Smrg	;;
7370a253d6aeSmrg
7371ea133fd7Smrg      -no-install)
7372ea133fd7Smrg	case $host in
7373ea133fd7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7374ea133fd7Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7375ea133fd7Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7376b41a30aaSmrg	  func_warning "'-no-install' is ignored for $host"
7377b41a30aaSmrg	  func_warning "assuming '-no-fast-install' instead"
7378ea133fd7Smrg	  fast_install=no
7379ea133fd7Smrg	  ;;
7380ea133fd7Smrg	*) no_install=yes ;;
7381ea133fd7Smrg	esac
7382ea133fd7Smrg	continue
7383ea133fd7Smrg	;;
7384a253d6aeSmrg
7385ea133fd7Smrg      -no-undefined)
7386ea133fd7Smrg	allow_undefined=no
7387ea133fd7Smrg	continue
7388ea133fd7Smrg	;;
7389a253d6aeSmrg
7390ea133fd7Smrg      -objectlist)
7391ea133fd7Smrg	prev=objectlist
7392ea133fd7Smrg	continue
7393ea133fd7Smrg	;;
7394a253d6aeSmrg
7395b41a30aaSmrg      -os2dllname)
7396b41a30aaSmrg	prev=os2dllname
7397b41a30aaSmrg	continue
7398b41a30aaSmrg	;;
7399b41a30aaSmrg
7400ea133fd7Smrg      -o) prev=output ;;
7401a253d6aeSmrg
7402ea133fd7Smrg      -precious-files-regex)
7403ea133fd7Smrg	prev=precious_regex
7404ea133fd7Smrg	continue
7405ea133fd7Smrg	;;
7406a253d6aeSmrg
7407ea133fd7Smrg      -release)
7408ea133fd7Smrg	prev=release
7409ea133fd7Smrg	continue
7410ea133fd7Smrg	;;
7411a253d6aeSmrg
7412ea133fd7Smrg      -rpath)
7413ea133fd7Smrg	prev=rpath
7414ea133fd7Smrg	continue
7415ea133fd7Smrg	;;
7416a253d6aeSmrg
7417ea133fd7Smrg      -R)
7418ea133fd7Smrg	prev=xrpath
7419ea133fd7Smrg	continue
7420ea133fd7Smrg	;;
7421a253d6aeSmrg
7422ea133fd7Smrg      -R*)
7423ea133fd7Smrg	func_stripname '-R' '' "$arg"
7424ea133fd7Smrg	dir=$func_stripname_result
7425ea133fd7Smrg	# We need an absolute path.
7426ea133fd7Smrg	case $dir in
7427ea133fd7Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
742806f32fbeSmrg	=*)
742906f32fbeSmrg	  func_stripname '=' '' "$dir"
743006f32fbeSmrg	  dir=$lt_sysroot$func_stripname_result
743106f32fbeSmrg	  ;;
7432ea133fd7Smrg	*)
7433ea133fd7Smrg	  func_fatal_error "only absolute run-paths are allowed"
7434ea133fd7Smrg	  ;;
7435ea133fd7Smrg	esac
7436ea133fd7Smrg	case "$xrpath " in
7437ea133fd7Smrg	*" $dir "*) ;;
743806f32fbeSmrg	*) func_append xrpath " $dir" ;;
7439ea133fd7Smrg	esac
7440ea133fd7Smrg	continue
7441ea133fd7Smrg	;;
7442a253d6aeSmrg
7443ea133fd7Smrg      -shared)
7444ea133fd7Smrg	# The effects of -shared are defined in a previous loop.
7445ea133fd7Smrg	continue
7446ea133fd7Smrg	;;
7447a253d6aeSmrg
7448ea133fd7Smrg      -shrext)
7449ea133fd7Smrg	prev=shrext
7450ea133fd7Smrg	continue
7451ea133fd7Smrg	;;
7452a253d6aeSmrg
7453ea133fd7Smrg      -static | -static-libtool-libs)
7454ea133fd7Smrg	# The effects of -static are defined in a previous loop.
7455ea133fd7Smrg	# We used to do the same as -all-static on platforms that
7456ea133fd7Smrg	# didn't have a PIC flag, but the assumption that the effects
7457ea133fd7Smrg	# would be equivalent was wrong.  It would break on at least
7458ea133fd7Smrg	# Digital Unix and AIX.
7459ea133fd7Smrg	continue
7460ea133fd7Smrg	;;
7461a253d6aeSmrg
7462ea133fd7Smrg      -thread-safe)
7463ea133fd7Smrg	thread_safe=yes
7464ea133fd7Smrg	continue
7465ea133fd7Smrg	;;
7466a253d6aeSmrg
7467ea133fd7Smrg      -version-info)
7468ea133fd7Smrg	prev=vinfo
7469ea133fd7Smrg	continue
7470ea133fd7Smrg	;;
7471a253d6aeSmrg
7472ea133fd7Smrg      -version-number)
7473ea133fd7Smrg	prev=vinfo
7474ea133fd7Smrg	vinfo_number=yes
7475ea133fd7Smrg	continue
7476ea133fd7Smrg	;;
7477a253d6aeSmrg
7478ea133fd7Smrg      -weak)
7479ea133fd7Smrg        prev=weak
7480ea133fd7Smrg	continue
7481ea133fd7Smrg	;;
7482a253d6aeSmrg
7483ea133fd7Smrg      -Wc,*)
7484ea133fd7Smrg	func_stripname '-Wc,' '' "$arg"
7485ea133fd7Smrg	args=$func_stripname_result
7486ea133fd7Smrg	arg=
7487b41a30aaSmrg	save_ifs=$IFS; IFS=,
7488ea133fd7Smrg	for flag in $args; do
7489b41a30aaSmrg	  IFS=$save_ifs
7490b41a30aaSmrg          func_quote_arg pretty "$flag"
7491b41a30aaSmrg	  func_append arg " $func_quote_arg_result"
7492b41a30aaSmrg	  func_append compiler_flags " $func_quote_arg_result"
7493ea133fd7Smrg	done
7494b41a30aaSmrg	IFS=$save_ifs
7495ea133fd7Smrg	func_stripname ' ' '' "$arg"
7496ea133fd7Smrg	arg=$func_stripname_result
7497ea133fd7Smrg	;;
7498a253d6aeSmrg
7499ea133fd7Smrg      -Wl,*)
7500ea133fd7Smrg	func_stripname '-Wl,' '' "$arg"
7501ea133fd7Smrg	args=$func_stripname_result
7502ea133fd7Smrg	arg=
7503b41a30aaSmrg	save_ifs=$IFS; IFS=,
7504ea133fd7Smrg	for flag in $args; do
7505b41a30aaSmrg	  IFS=$save_ifs
7506b41a30aaSmrg          func_quote_arg pretty "$flag"
7507b41a30aaSmrg	  func_append arg " $wl$func_quote_arg_result"
7508b41a30aaSmrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509b41a30aaSmrg	  func_append linker_flags " $func_quote_arg_result"
7510ea133fd7Smrg	done
7511b41a30aaSmrg	IFS=$save_ifs
7512ea133fd7Smrg	func_stripname ' ' '' "$arg"
7513ea133fd7Smrg	arg=$func_stripname_result
7514ea133fd7Smrg	;;
7515a253d6aeSmrg
7516b41a30aaSmrg      -Xassembler)
7517b41a30aaSmrg        prev=xassembler
7518b41a30aaSmrg        continue
7519b41a30aaSmrg        ;;
7520b41a30aaSmrg
7521ea133fd7Smrg      -Xcompiler)
7522ea133fd7Smrg	prev=xcompiler
7523ea133fd7Smrg	continue
7524ea133fd7Smrg	;;
7525a253d6aeSmrg
7526ea133fd7Smrg      -Xlinker)
7527ea133fd7Smrg	prev=xlinker
7528ea133fd7Smrg	continue
7529ea133fd7Smrg	;;
7530a253d6aeSmrg
7531ea133fd7Smrg      -XCClinker)
7532ea133fd7Smrg	prev=xcclinker
7533ea133fd7Smrg	continue
7534ea133fd7Smrg	;;
7535a253d6aeSmrg
7536ea133fd7Smrg      # -msg_* for osf cc
7537ea133fd7Smrg      -msg_*)
7538b41a30aaSmrg	func_quote_arg pretty "$arg"
7539b41a30aaSmrg	arg=$func_quote_arg_result
7540ea133fd7Smrg	;;
7541a253d6aeSmrg
754225b89263Smrg      # Flags to be passed through unchanged, with rationale:
754325b89263Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
754425b89263Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
754525b89263Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
754625b89263Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
754725b89263Smrg      # -q*                  compiler args for the IBM compiler
754825b89263Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
754925b89263Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
755025b89263Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551b41a30aaSmrg      # -fstack-protector*   stack protector flags for GCC
755225b89263Smrg      # @file                GCC response files
755325b89263Smrg      # -tp=*                Portland pgcc target processor selection
755406f32fbeSmrg      # --sysroot=*          for sysroot support
7555b41a30aaSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7556b41a30aaSmrg      # -specs=*             GCC specs files
7557b41a30aaSmrg      # -stdlib=*            select c++ std lib with clang
7558b41a30aaSmrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
7559b41a30aaSmrg      # -fuse-ld=*           Linker select flags for GCC
7560b41a30aaSmrg      # -Wa,*                Pass flags directly to the assembler
7561ea133fd7Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
756206f32fbeSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7563b41a30aaSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564b41a30aaSmrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565b41a30aaSmrg        func_quote_arg pretty "$arg"
7566b41a30aaSmrg	arg=$func_quote_arg_result
7567ea133fd7Smrg        func_append compile_command " $arg"
7568ea133fd7Smrg        func_append finalize_command " $arg"
756906f32fbeSmrg        func_append compiler_flags " $arg"
7570ea133fd7Smrg        continue
7571ea133fd7Smrg        ;;
7572a253d6aeSmrg
7573b41a30aaSmrg      -Z*)
7574b41a30aaSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575b41a30aaSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576b41a30aaSmrg	  compiler_flags="$compiler_flags $arg"
7577b41a30aaSmrg	  func_append compile_command " $arg"
7578b41a30aaSmrg	  func_append finalize_command " $arg"
7579b41a30aaSmrg	  case $arg in
7580b41a30aaSmrg	  -Zlinker | -Zstack)
7581b41a30aaSmrg	    prev=xcompiler
7582b41a30aaSmrg	    ;;
7583b41a30aaSmrg	  esac
7584b41a30aaSmrg	  continue
7585b41a30aaSmrg        else
7586b41a30aaSmrg	  # Otherwise treat like 'Some other compiler flag' below
7587b41a30aaSmrg	  func_quote_arg pretty "$arg"
7588b41a30aaSmrg	  arg=$func_quote_arg_result
7589b41a30aaSmrg        fi
7590b41a30aaSmrg	;;
7591b41a30aaSmrg
7592ea133fd7Smrg      # Some other compiler flag.
7593ea133fd7Smrg      -* | +*)
7594b41a30aaSmrg        func_quote_arg pretty "$arg"
7595b41a30aaSmrg	arg=$func_quote_arg_result
7596ea133fd7Smrg	;;
7597a253d6aeSmrg
7598ea133fd7Smrg      *.$objext)
7599ea133fd7Smrg	# A standard object.
760006f32fbeSmrg	func_append objs " $arg"
7601ea133fd7Smrg	;;
7602ea133fd7Smrg
7603ea133fd7Smrg      *.lo)
7604ea133fd7Smrg	# A libtool-controlled object.
7605ea133fd7Smrg
7606ea133fd7Smrg	# Check to see that this really is a libtool object.
7607ea133fd7Smrg	if func_lalib_unsafe_p "$arg"; then
7608ea133fd7Smrg	  pic_object=
7609ea133fd7Smrg	  non_pic_object=
7610ea133fd7Smrg
7611ea133fd7Smrg	  # Read the .lo file
7612ea133fd7Smrg	  func_source "$arg"
7613ea133fd7Smrg
7614ea133fd7Smrg	  if test -z "$pic_object" ||
7615ea133fd7Smrg	     test -z "$non_pic_object" ||
7616b41a30aaSmrg	     test none = "$pic_object" &&
7617b41a30aaSmrg	     test none = "$non_pic_object"; then
7618b41a30aaSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7619ea133fd7Smrg	  fi
7620ea133fd7Smrg
7621ea133fd7Smrg	  # Extract subdirectory from the argument.
7622ea133fd7Smrg	  func_dirname "$arg" "/" ""
7623b41a30aaSmrg	  xdir=$func_dirname_result
7624ea133fd7Smrg
7625b41a30aaSmrg	  test none = "$pic_object" || {
7626ea133fd7Smrg	    # Prepend the subdirectory the object is found in.
7627b41a30aaSmrg	    pic_object=$xdir$pic_object
7628ea133fd7Smrg
7629b41a30aaSmrg	    if test dlfiles = "$prev"; then
7630b41a30aaSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
763106f32fbeSmrg		func_append dlfiles " $pic_object"
7632ea133fd7Smrg		prev=
7633ea133fd7Smrg		continue
7634ea133fd7Smrg	      else
7635ea133fd7Smrg		# If libtool objects are unsupported, then we need to preload.
7636ea133fd7Smrg		prev=dlprefiles
7637ea133fd7Smrg	      fi
7638ea133fd7Smrg	    fi
7639ea133fd7Smrg
7640ea133fd7Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7641b41a30aaSmrg	    if test dlprefiles = "$prev"; then
7642ea133fd7Smrg	      # Preload the old-style object.
764306f32fbeSmrg	      func_append dlprefiles " $pic_object"
7644ea133fd7Smrg	      prev=
7645ea133fd7Smrg	    fi
7646ea133fd7Smrg
7647ea133fd7Smrg	    # A PIC object.
7648ea133fd7Smrg	    func_append libobjs " $pic_object"
7649b41a30aaSmrg	    arg=$pic_object
7650b41a30aaSmrg	  }
7651ea133fd7Smrg
7652ea133fd7Smrg	  # Non-PIC object.
7653b41a30aaSmrg	  if test none != "$non_pic_object"; then
7654ea133fd7Smrg	    # Prepend the subdirectory the object is found in.
7655b41a30aaSmrg	    non_pic_object=$xdir$non_pic_object
7656ea133fd7Smrg
7657ea133fd7Smrg	    # A standard non-PIC object
7658ea133fd7Smrg	    func_append non_pic_objects " $non_pic_object"
7659b41a30aaSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660b41a30aaSmrg	      arg=$non_pic_object
7661ea133fd7Smrg	    fi
7662ea133fd7Smrg	  else
7663ea133fd7Smrg	    # If the PIC object exists, use it instead.
7664ea133fd7Smrg	    # $xdir was prepended to $pic_object above.
7665b41a30aaSmrg	    non_pic_object=$pic_object
7666ea133fd7Smrg	    func_append non_pic_objects " $non_pic_object"
7667ea133fd7Smrg	  fi
7668ea133fd7Smrg	else
7669ea133fd7Smrg	  # Only an error if not doing a dry-run.
7670ea133fd7Smrg	  if $opt_dry_run; then
7671ea133fd7Smrg	    # Extract subdirectory from the argument.
7672ea133fd7Smrg	    func_dirname "$arg" "/" ""
7673b41a30aaSmrg	    xdir=$func_dirname_result
7674ea133fd7Smrg
7675ea133fd7Smrg	    func_lo2o "$arg"
7676ea133fd7Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7677ea133fd7Smrg	    non_pic_object=$xdir$func_lo2o_result
7678ea133fd7Smrg	    func_append libobjs " $pic_object"
7679ea133fd7Smrg	    func_append non_pic_objects " $non_pic_object"
7680ea133fd7Smrg	  else
7681b41a30aaSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7682ea133fd7Smrg	  fi
7683ea133fd7Smrg	fi
7684ea133fd7Smrg	;;
7685ea133fd7Smrg
7686ea133fd7Smrg      *.$libext)
7687ea133fd7Smrg	# An archive.
768806f32fbeSmrg	func_append deplibs " $arg"
768906f32fbeSmrg	func_append old_deplibs " $arg"
7690ea133fd7Smrg	continue
7691ea133fd7Smrg	;;
7692ea133fd7Smrg
7693ea133fd7Smrg      *.la)
7694ea133fd7Smrg	# A libtool-controlled library.
7695ea133fd7Smrg
769606f32fbeSmrg	func_resolve_sysroot "$arg"
7697b41a30aaSmrg	if test dlfiles = "$prev"; then
7698ea133fd7Smrg	  # This library was specified with -dlopen.
769906f32fbeSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
7700ea133fd7Smrg	  prev=
7701b41a30aaSmrg	elif test dlprefiles = "$prev"; then
7702ea133fd7Smrg	  # The library was specified with -dlpreopen.
770306f32fbeSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7704ea133fd7Smrg	  prev=
7705ea133fd7Smrg	else
770606f32fbeSmrg	  func_append deplibs " $func_resolve_sysroot_result"
7707ea133fd7Smrg	fi
7708ea133fd7Smrg	continue
7709ea133fd7Smrg	;;
7710ea133fd7Smrg
7711ea133fd7Smrg      # Some other compiler argument.
7712ea133fd7Smrg      *)
7713ea133fd7Smrg	# Unknown arguments in both finalize_command and compile_command need
7714ea133fd7Smrg	# to be aesthetically quoted because they are evaled later.
7715b41a30aaSmrg	func_quote_arg pretty "$arg"
7716b41a30aaSmrg	arg=$func_quote_arg_result
7717ea133fd7Smrg	;;
7718ea133fd7Smrg      esac # arg
7719ea133fd7Smrg
7720ea133fd7Smrg      # Now actually substitute the argument into the commands.
7721ea133fd7Smrg      if test -n "$arg"; then
7722ea133fd7Smrg	func_append compile_command " $arg"
7723ea133fd7Smrg	func_append finalize_command " $arg"
7724ea133fd7Smrg      fi
7725ea133fd7Smrg    done # argument parsing loop
7726ea133fd7Smrg
7727ea133fd7Smrg    test -n "$prev" && \
7728b41a30aaSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7729ea133fd7Smrg
7730b41a30aaSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7731ea133fd7Smrg      eval arg=\"$export_dynamic_flag_spec\"
7732ea133fd7Smrg      func_append compile_command " $arg"
7733ea133fd7Smrg      func_append finalize_command " $arg"
7734ea133fd7Smrg    fi
7735ea133fd7Smrg
7736ea133fd7Smrg    oldlibs=
7737ea133fd7Smrg    # calculate the name of the file, without its directory
7738ea133fd7Smrg    func_basename "$output"
7739b41a30aaSmrg    outputname=$func_basename_result
7740b41a30aaSmrg    libobjs_save=$libobjs
7741ea133fd7Smrg
7742ea133fd7Smrg    if test -n "$shlibpath_var"; then
7743ea133fd7Smrg      # get the directories listed in $shlibpath_var
7744b41a30aaSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7745a253d6aeSmrg    else
7746ea133fd7Smrg      shlib_search_path=
7747a253d6aeSmrg    fi
7748ea133fd7Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7749ea133fd7Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750a253d6aeSmrg
7751b41a30aaSmrg    # Definition is injected by LT_CONFIG during libtool generation.
7752b41a30aaSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753b41a30aaSmrg
7754ea133fd7Smrg    func_dirname "$output" "/" ""
7755b41a30aaSmrg    output_objdir=$func_dirname_result$objdir
775606f32fbeSmrg    func_to_tool_file "$output_objdir/"
775706f32fbeSmrg    tool_output_objdir=$func_to_tool_file_result
7758ea133fd7Smrg    # Create the object directory.
7759ea133fd7Smrg    func_mkdir_p "$output_objdir"
7760a253d6aeSmrg
7761ea133fd7Smrg    # Determine the type of output
7762ea133fd7Smrg    case $output in
7763ea133fd7Smrg    "")
7764ea133fd7Smrg      func_fatal_help "you must specify an output file"
7765ea133fd7Smrg      ;;
7766ea133fd7Smrg    *.$libext) linkmode=oldlib ;;
7767ea133fd7Smrg    *.lo | *.$objext) linkmode=obj ;;
7768ea133fd7Smrg    *.la) linkmode=lib ;;
7769ea133fd7Smrg    *) linkmode=prog ;; # Anything else should be a program.
7770ea133fd7Smrg    esac
7771ea133fd7Smrg
7772ea133fd7Smrg    specialdeplibs=
7773ea133fd7Smrg
7774ea133fd7Smrg    libs=
7775ea133fd7Smrg    # Find all interdependent deplibs by searching for libraries
7776ea133fd7Smrg    # that are linked more than once (e.g. -la -lb -la)
7777ea133fd7Smrg    for deplib in $deplibs; do
7778b41a30aaSmrg      if $opt_preserve_dup_deps; then
7779ea133fd7Smrg	case "$libs " in
778006f32fbeSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7781ea133fd7Smrg	esac
7782ea133fd7Smrg      fi
778306f32fbeSmrg      func_append libs " $deplib"
7784ea133fd7Smrg    done
7785ea133fd7Smrg
7786b41a30aaSmrg    if test lib = "$linkmode"; then
7787ea133fd7Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7788ea133fd7Smrg
7789ea133fd7Smrg      # Compute libraries that are listed more than once in $predeps
7790ea133fd7Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7791ea133fd7Smrg      # not to be eliminated).
7792ea133fd7Smrg      pre_post_deps=
7793ea133fd7Smrg      if $opt_duplicate_compiler_generated_deps; then
7794ea133fd7Smrg	for pre_post_dep in $predeps $postdeps; do
7795ea133fd7Smrg	  case "$pre_post_deps " in
779606f32fbeSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7797ea133fd7Smrg	  esac
779806f32fbeSmrg	  func_append pre_post_deps " $pre_post_dep"
7799ea133fd7Smrg	done
7800ea133fd7Smrg      fi
7801ea133fd7Smrg      pre_post_deps=
7802ea133fd7Smrg    fi
7803ea133fd7Smrg
7804ea133fd7Smrg    deplibs=
7805ea133fd7Smrg    newdependency_libs=
7806ea133fd7Smrg    newlib_search_path=
7807ea133fd7Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7808ea133fd7Smrg    notinst_deplibs= # not-installed libtool libraries
7809ea133fd7Smrg    notinst_path= # paths that contain not-installed libtool libraries
7810ea133fd7Smrg
7811ea133fd7Smrg    case $linkmode in
7812ea133fd7Smrg    lib)
7813ea133fd7Smrg	passes="conv dlpreopen link"
7814ea133fd7Smrg	for file in $dlfiles $dlprefiles; do
7815ea133fd7Smrg	  case $file in
7816ea133fd7Smrg	  *.la) ;;
7817ea133fd7Smrg	  *)
7818b41a30aaSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7819ea133fd7Smrg	    ;;
7820ea133fd7Smrg	  esac
7821ea133fd7Smrg	done
7822ea133fd7Smrg	;;
7823ea133fd7Smrg    prog)
7824ea133fd7Smrg	compile_deplibs=
7825ea133fd7Smrg	finalize_deplibs=
7826b41a30aaSmrg	alldeplibs=false
7827ea133fd7Smrg	newdlfiles=
7828ea133fd7Smrg	newdlprefiles=
7829ea133fd7Smrg	passes="conv scan dlopen dlpreopen link"
7830ea133fd7Smrg	;;
7831ea133fd7Smrg    *)  passes="conv"
7832ea133fd7Smrg	;;
7833ea133fd7Smrg    esac
7834ea133fd7Smrg
7835ea133fd7Smrg    for pass in $passes; do
7836ea133fd7Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7837ea133fd7Smrg      # so that -L comes before libs that need it for instance...
7838b41a30aaSmrg      if test lib,link = "$linkmode,$pass"; then
7839ea133fd7Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7840ea133fd7Smrg	##        order, and fix it there properly
7841ea133fd7Smrg        tmp_deplibs=
7842ea133fd7Smrg	for deplib in $deplibs; do
7843ea133fd7Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7844ea133fd7Smrg	done
7845b41a30aaSmrg	deplibs=$tmp_deplibs
7846ea133fd7Smrg      fi
7847ea133fd7Smrg
7848b41a30aaSmrg      if test lib,link = "$linkmode,$pass" ||
7849b41a30aaSmrg	 test prog,scan = "$linkmode,$pass"; then
7850b41a30aaSmrg	libs=$deplibs
7851ea133fd7Smrg	deplibs=
7852ea133fd7Smrg      fi
7853b41a30aaSmrg      if test prog = "$linkmode"; then
7854ea133fd7Smrg	case $pass in
7855b41a30aaSmrg	dlopen) libs=$dlfiles ;;
7856b41a30aaSmrg	dlpreopen) libs=$dlprefiles ;;
7857b41a30aaSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7858ea133fd7Smrg	esac
7859ea133fd7Smrg      fi
7860b41a30aaSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7861ea133fd7Smrg	# Collect and forward deplibs of preopened libtool libs
7862ea133fd7Smrg	for lib in $dlprefiles; do
7863ea133fd7Smrg	  # Ignore non-libtool-libs
7864ea133fd7Smrg	  dependency_libs=
786506f32fbeSmrg	  func_resolve_sysroot "$lib"
7866ea133fd7Smrg	  case $lib in
786706f32fbeSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7868ea133fd7Smrg	  esac
7869ea133fd7Smrg
7870ea133fd7Smrg	  # Collect preopened libtool deplibs, except any this library
7871ea133fd7Smrg	  # has declared as weak libs
7872ea133fd7Smrg	  for deplib in $dependency_libs; do
787325b89263Smrg	    func_basename "$deplib"
787425b89263Smrg            deplib_base=$func_basename_result
7875ea133fd7Smrg	    case " $weak_libs " in
7876ea133fd7Smrg	    *" $deplib_base "*) ;;
787706f32fbeSmrg	    *) func_append deplibs " $deplib" ;;
7878ea133fd7Smrg	    esac
7879ea133fd7Smrg	  done
7880ea133fd7Smrg	done
7881b41a30aaSmrg	libs=$dlprefiles
7882ea133fd7Smrg      fi
7883b41a30aaSmrg      if test dlopen = "$pass"; then
7884ea133fd7Smrg	# Collect dlpreopened libraries
7885b41a30aaSmrg	save_deplibs=$deplibs
7886ea133fd7Smrg	deplibs=
7887ea133fd7Smrg      fi
7888ea133fd7Smrg
7889ea133fd7Smrg      for deplib in $libs; do
7890ea133fd7Smrg	lib=
7891b41a30aaSmrg	found=false
7892ea133fd7Smrg	case $deplib in
789357ee1794Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
789457ee1794Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895b41a30aaSmrg	  if test prog,link = "$linkmode,$pass"; then
7896ea133fd7Smrg	    compile_deplibs="$deplib $compile_deplibs"
7897ea133fd7Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7898ea133fd7Smrg	  else
789906f32fbeSmrg	    func_append compiler_flags " $deplib"
7900b41a30aaSmrg	    if test lib = "$linkmode"; then
7901ea133fd7Smrg		case "$new_inherited_linker_flags " in
7902ea133fd7Smrg		    *" $deplib "*) ;;
790306f32fbeSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7904ea133fd7Smrg		esac
7905ea133fd7Smrg	    fi
7906ea133fd7Smrg	  fi
7907ea133fd7Smrg	  continue
7908ea133fd7Smrg	  ;;
7909ea133fd7Smrg	-l*)
7910b41a30aaSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911b41a30aaSmrg	    func_warning "'-l' is ignored for archives/objects"
7912ea133fd7Smrg	    continue
7913ea133fd7Smrg	  fi
7914ea133fd7Smrg	  func_stripname '-l' '' "$deplib"
7915ea133fd7Smrg	  name=$func_stripname_result
7916b41a30aaSmrg	  if test lib = "$linkmode"; then
7917ea133fd7Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7918ea133fd7Smrg	  else
7919ea133fd7Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7920ea133fd7Smrg	  fi
7921ea133fd7Smrg	  for searchdir in $searchdirs; do
7922ea133fd7Smrg	    for search_ext in .la $std_shrext .so .a; do
7923ea133fd7Smrg	      # Search the libtool library
7924b41a30aaSmrg	      lib=$searchdir/lib$name$search_ext
7925ea133fd7Smrg	      if test -f "$lib"; then
7926b41a30aaSmrg		if test .la = "$search_ext"; then
7927b41a30aaSmrg		  found=:
7928ea133fd7Smrg		else
7929b41a30aaSmrg		  found=false
7930ea133fd7Smrg		fi
7931ea133fd7Smrg		break 2
7932ea133fd7Smrg	      fi
7933ea133fd7Smrg	    done
7934ea133fd7Smrg	  done
7935b41a30aaSmrg	  if $found; then
7936b41a30aaSmrg	    # deplib is a libtool library
7937ea133fd7Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7938ea133fd7Smrg	    # We need to do some special things here, and not later.
7939b41a30aaSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7940ea133fd7Smrg	      case " $predeps $postdeps " in
7941ea133fd7Smrg	      *" $deplib "*)
7942ea133fd7Smrg		if func_lalib_p "$lib"; then
7943ea133fd7Smrg		  library_names=
7944ea133fd7Smrg		  old_library=
7945ea133fd7Smrg		  func_source "$lib"
7946ea133fd7Smrg		  for l in $old_library $library_names; do
7947b41a30aaSmrg		    ll=$l
7948ea133fd7Smrg		  done
7949b41a30aaSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950b41a30aaSmrg		    found=false
7951ea133fd7Smrg		    func_dirname "$lib" "" "."
7952b41a30aaSmrg		    ladir=$func_dirname_result
7953ea133fd7Smrg		    lib=$ladir/$old_library
7954b41a30aaSmrg		    if test prog,link = "$linkmode,$pass"; then
7955ea133fd7Smrg		      compile_deplibs="$deplib $compile_deplibs"
7956ea133fd7Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7957ea133fd7Smrg		    else
7958ea133fd7Smrg		      deplibs="$deplib $deplibs"
7959b41a30aaSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7960ea133fd7Smrg		    fi
7961ea133fd7Smrg		    continue
7962ea133fd7Smrg		  fi
7963ea133fd7Smrg		fi
7964ea133fd7Smrg		;;
7965ea133fd7Smrg	      *) ;;
7966ea133fd7Smrg	      esac
7967ea133fd7Smrg	    fi
7968b41a30aaSmrg	  else
7969b41a30aaSmrg	    # deplib doesn't seem to be a libtool library
7970b41a30aaSmrg	    if test prog,link = "$linkmode,$pass"; then
7971b41a30aaSmrg	      compile_deplibs="$deplib $compile_deplibs"
7972b41a30aaSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973b41a30aaSmrg	    else
7974b41a30aaSmrg	      deplibs="$deplib $deplibs"
7975b41a30aaSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976b41a30aaSmrg	    fi
7977b41a30aaSmrg	    continue
7978ea133fd7Smrg	  fi
7979ea133fd7Smrg	  ;; # -l
7980ea133fd7Smrg	*.ltframework)
7981b41a30aaSmrg	  if test prog,link = "$linkmode,$pass"; then
7982ea133fd7Smrg	    compile_deplibs="$deplib $compile_deplibs"
7983ea133fd7Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7984ea133fd7Smrg	  else
7985ea133fd7Smrg	    deplibs="$deplib $deplibs"
7986b41a30aaSmrg	    if test lib = "$linkmode"; then
7987ea133fd7Smrg		case "$new_inherited_linker_flags " in
7988ea133fd7Smrg		    *" $deplib "*) ;;
798906f32fbeSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7990ea133fd7Smrg		esac
7991ea133fd7Smrg	    fi
7992ea133fd7Smrg	  fi
7993ea133fd7Smrg	  continue
7994ea133fd7Smrg	  ;;
7995ea133fd7Smrg	-L*)
7996ea133fd7Smrg	  case $linkmode in
7997ea133fd7Smrg	  lib)
7998ea133fd7Smrg	    deplibs="$deplib $deplibs"
7999b41a30aaSmrg	    test conv = "$pass" && continue
8000ea133fd7Smrg	    newdependency_libs="$deplib $newdependency_libs"
8001ea133fd7Smrg	    func_stripname '-L' '' "$deplib"
800206f32fbeSmrg	    func_resolve_sysroot "$func_stripname_result"
800306f32fbeSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8004ea133fd7Smrg	    ;;
8005ea133fd7Smrg	  prog)
8006b41a30aaSmrg	    if test conv = "$pass"; then
8007ea133fd7Smrg	      deplibs="$deplib $deplibs"
8008ea133fd7Smrg	      continue
8009ea133fd7Smrg	    fi
8010b41a30aaSmrg	    if test scan = "$pass"; then
8011ea133fd7Smrg	      deplibs="$deplib $deplibs"
8012ea133fd7Smrg	    else
8013ea133fd7Smrg	      compile_deplibs="$deplib $compile_deplibs"
8014ea133fd7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8015ea133fd7Smrg	    fi
8016ea133fd7Smrg	    func_stripname '-L' '' "$deplib"
801706f32fbeSmrg	    func_resolve_sysroot "$func_stripname_result"
801806f32fbeSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8019ea133fd7Smrg	    ;;
8020ea133fd7Smrg	  *)
8021b41a30aaSmrg	    func_warning "'-L' is ignored for archives/objects"
8022ea133fd7Smrg	    ;;
8023ea133fd7Smrg	  esac # linkmode
8024ea133fd7Smrg	  continue
8025ea133fd7Smrg	  ;; # -L
8026ea133fd7Smrg	-R*)
8027b41a30aaSmrg	  if test link = "$pass"; then
8028ea133fd7Smrg	    func_stripname '-R' '' "$deplib"
802906f32fbeSmrg	    func_resolve_sysroot "$func_stripname_result"
803006f32fbeSmrg	    dir=$func_resolve_sysroot_result
8031ea133fd7Smrg	    # Make sure the xrpath contains only unique directories.
8032ea133fd7Smrg	    case "$xrpath " in
8033ea133fd7Smrg	    *" $dir "*) ;;
803406f32fbeSmrg	    *) func_append xrpath " $dir" ;;
8035ea133fd7Smrg	    esac
8036ea133fd7Smrg	  fi
8037ea133fd7Smrg	  deplibs="$deplib $deplibs"
8038ea133fd7Smrg	  continue
8039ea133fd7Smrg	  ;;
804006f32fbeSmrg	*.la)
804106f32fbeSmrg	  func_resolve_sysroot "$deplib"
804206f32fbeSmrg	  lib=$func_resolve_sysroot_result
804306f32fbeSmrg	  ;;
8044ea133fd7Smrg	*.$libext)
8045b41a30aaSmrg	  if test conv = "$pass"; then
8046ea133fd7Smrg	    deplibs="$deplib $deplibs"
8047ea133fd7Smrg	    continue
8048ea133fd7Smrg	  fi
8049ea133fd7Smrg	  case $linkmode in
8050ea133fd7Smrg	  lib)
8051ea133fd7Smrg	    # Linking convenience modules into shared libraries is allowed,
8052ea133fd7Smrg	    # but linking other static libraries is non-portable.
8053ea133fd7Smrg	    case " $dlpreconveniencelibs " in
8054ea133fd7Smrg	    *" $deplib "*) ;;
8055ea133fd7Smrg	    *)
8056b41a30aaSmrg	      valid_a_lib=false
8057ea133fd7Smrg	      case $deplibs_check_method in
8058ea133fd7Smrg		match_pattern*)
8059ea133fd7Smrg		  set dummy $deplibs_check_method; shift
8060ea133fd7Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
806125b89263Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8062ea133fd7Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063b41a30aaSmrg		    valid_a_lib=:
8064ea133fd7Smrg		  fi
8065ea133fd7Smrg		;;
8066ea133fd7Smrg		pass_all)
8067b41a30aaSmrg		  valid_a_lib=:
8068ea133fd7Smrg		;;
8069ea133fd7Smrg	      esac
8070b41a30aaSmrg	      if $valid_a_lib; then
8071b41a30aaSmrg		echo
8072b41a30aaSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073b41a30aaSmrg		$ECHO "*** static library $deplib is not portable!"
8074b41a30aaSmrg		deplibs="$deplib $deplibs"
8075b41a30aaSmrg	      else
807625b89263Smrg		echo
8077ea133fd7Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
807825b89263Smrg		echo "*** I have the capability to make that library automatically link in when"
807925b89263Smrg		echo "*** you link to this library.  But I can only do this if you have a"
808025b89263Smrg		echo "*** shared version of the library, which you do not appear to have"
808125b89263Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
808225b89263Smrg		echo "*** that it is just a static archive that I should not use here."
8083ea133fd7Smrg	      fi
8084ea133fd7Smrg	      ;;
8085ea133fd7Smrg	    esac
8086ea133fd7Smrg	    continue
8087ea133fd7Smrg	    ;;
8088ea133fd7Smrg	  prog)
8089b41a30aaSmrg	    if test link != "$pass"; then
8090ea133fd7Smrg	      deplibs="$deplib $deplibs"
8091ea133fd7Smrg	    else
8092ea133fd7Smrg	      compile_deplibs="$deplib $compile_deplibs"
8093ea133fd7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8094ea133fd7Smrg	    fi
8095ea133fd7Smrg	    continue
8096ea133fd7Smrg	    ;;
8097ea133fd7Smrg	  esac # linkmode
8098ea133fd7Smrg	  ;; # *.$libext
8099ea133fd7Smrg	*.lo | *.$objext)
8100b41a30aaSmrg	  if test conv = "$pass"; then
8101ea133fd7Smrg	    deplibs="$deplib $deplibs"
8102b41a30aaSmrg	  elif test prog = "$linkmode"; then
8103b41a30aaSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8104ea133fd7Smrg	      # If there is no dlopen support or we're linking statically,
8105ea133fd7Smrg	      # we need to preload.
810606f32fbeSmrg	      func_append newdlprefiles " $deplib"
8107ea133fd7Smrg	      compile_deplibs="$deplib $compile_deplibs"
8108ea133fd7Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
8109ea133fd7Smrg	    else
811006f32fbeSmrg	      func_append newdlfiles " $deplib"
8111ea133fd7Smrg	    fi
8112ea133fd7Smrg	  fi
8113ea133fd7Smrg	  continue
8114ea133fd7Smrg	  ;;
8115ea133fd7Smrg	%DEPLIBS%)
8116b41a30aaSmrg	  alldeplibs=:
8117ea133fd7Smrg	  continue
8118ea133fd7Smrg	  ;;
8119ea133fd7Smrg	esac # case $deplib
8120ea133fd7Smrg
8121b41a30aaSmrg	$found || test -f "$lib" \
8122b41a30aaSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8123ea133fd7Smrg
8124ea133fd7Smrg	# Check to see that this really is a libtool archive.
8125ea133fd7Smrg	func_lalib_unsafe_p "$lib" \
8126b41a30aaSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8127ea133fd7Smrg
8128ea133fd7Smrg	func_dirname "$lib" "" "."
8129b41a30aaSmrg	ladir=$func_dirname_result
8130ea133fd7Smrg
8131ea133fd7Smrg	dlname=
8132ea133fd7Smrg	dlopen=
8133ea133fd7Smrg	dlpreopen=
8134ea133fd7Smrg	libdir=
8135ea133fd7Smrg	library_names=
8136ea133fd7Smrg	old_library=
8137ea133fd7Smrg	inherited_linker_flags=
8138ea133fd7Smrg	# If the library was installed with an old release of libtool,
8139ea133fd7Smrg	# it will not redefine variables installed, or shouldnotlink
8140ea133fd7Smrg	installed=yes
8141ea133fd7Smrg	shouldnotlink=no
8142ea133fd7Smrg	avoidtemprpath=
8143ea133fd7Smrg
8144ea133fd7Smrg
8145ea133fd7Smrg	# Read the .la file
8146ea133fd7Smrg	func_source "$lib"
8147ea133fd7Smrg
8148ea133fd7Smrg	# Convert "-framework foo" to "foo.ltframework"
8149ea133fd7Smrg	if test -n "$inherited_linker_flags"; then
815025b89263Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8151ea133fd7Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8152ea133fd7Smrg	    case " $new_inherited_linker_flags " in
8153ea133fd7Smrg	      *" $tmp_inherited_linker_flag "*) ;;
815406f32fbeSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8155ea133fd7Smrg	    esac
8156ea133fd7Smrg	  done
8157ea133fd7Smrg	fi
815825b89263Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159b41a30aaSmrg	if test lib,link = "$linkmode,$pass" ||
8160b41a30aaSmrg	   test prog,scan = "$linkmode,$pass" ||
8161b41a30aaSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
816206f32fbeSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
816306f32fbeSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8164ea133fd7Smrg	fi
8165ea133fd7Smrg
8166b41a30aaSmrg	if test conv = "$pass"; then
8167ea133fd7Smrg	  # Only check for convenience libraries
8168ea133fd7Smrg	  deplibs="$lib $deplibs"
8169ea133fd7Smrg	  if test -z "$libdir"; then
8170ea133fd7Smrg	    if test -z "$old_library"; then
8171b41a30aaSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
8172ea133fd7Smrg	    fi
8173ea133fd7Smrg	    # It is a libtool convenience library, so add in its objects.
817406f32fbeSmrg	    func_append convenience " $ladir/$objdir/$old_library"
817506f32fbeSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176b41a30aaSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177b41a30aaSmrg	    func_fatal_error "'$lib' is not a convenience library"
8178ea133fd7Smrg	  fi
8179b41a30aaSmrg	  tmp_libs=
8180b41a30aaSmrg	  for deplib in $dependency_libs; do
8181b41a30aaSmrg	    deplibs="$deplib $deplibs"
8182b41a30aaSmrg	    if $opt_preserve_dup_deps; then
8183b41a30aaSmrg	      case "$tmp_libs " in
8184b41a30aaSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185b41a30aaSmrg	      esac
8186b41a30aaSmrg	    fi
8187b41a30aaSmrg	    func_append tmp_libs " $deplib"
8188b41a30aaSmrg	  done
8189ea133fd7Smrg	  continue
8190ea133fd7Smrg	fi # $pass = conv
8191ea133fd7Smrg
8192ea133fd7Smrg
8193ea133fd7Smrg	# Get the name of the library we link against.
8194ea133fd7Smrg	linklib=
819506f32fbeSmrg	if test -n "$old_library" &&
8196b41a30aaSmrg	   { test yes = "$prefer_static_libs" ||
8197b41a30aaSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
819806f32fbeSmrg	  linklib=$old_library
819906f32fbeSmrg	else
820006f32fbeSmrg	  for l in $old_library $library_names; do
8201b41a30aaSmrg	    linklib=$l
820206f32fbeSmrg	  done
820306f32fbeSmrg	fi
8204ea133fd7Smrg	if test -z "$linklib"; then
8205b41a30aaSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
8206ea133fd7Smrg	fi
8207ea133fd7Smrg
8208ea133fd7Smrg	# This library was specified with -dlopen.
8209b41a30aaSmrg	if test dlopen = "$pass"; then
8210b41a30aaSmrg	  test -z "$libdir" \
8211b41a30aaSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8212ea133fd7Smrg	  if test -z "$dlname" ||
8213b41a30aaSmrg	     test yes != "$dlopen_support" ||
8214b41a30aaSmrg	     test no = "$build_libtool_libs"
8215b41a30aaSmrg	  then
8216ea133fd7Smrg	    # If there is no dlname, no dlopen support or we're linking
8217ea133fd7Smrg	    # statically, we need to preload.  We also need to preload any
8218ea133fd7Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
8219ea133fd7Smrg	    # bomb out in the load deplibs phase.
822006f32fbeSmrg	    func_append dlprefiles " $lib $dependency_libs"
8221ea133fd7Smrg	  else
822206f32fbeSmrg	    func_append newdlfiles " $lib"
8223ea133fd7Smrg	  fi
8224ea133fd7Smrg	  continue
8225ea133fd7Smrg	fi # $pass = dlopen
8226ea133fd7Smrg
8227ea133fd7Smrg	# We need an absolute path.
8228ea133fd7Smrg	case $ladir in
8229b41a30aaSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8230ea133fd7Smrg	*)
8231ea133fd7Smrg	  abs_ladir=`cd "$ladir" && pwd`
8232ea133fd7Smrg	  if test -z "$abs_ladir"; then
8233b41a30aaSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8234ea133fd7Smrg	    func_warning "passing it literally to the linker, although it might fail"
8235b41a30aaSmrg	    abs_ladir=$ladir
8236ea133fd7Smrg	  fi
8237ea133fd7Smrg	  ;;
8238ea133fd7Smrg	esac
8239ea133fd7Smrg	func_basename "$lib"
8240b41a30aaSmrg	laname=$func_basename_result
8241ea133fd7Smrg
8242ea133fd7Smrg	# Find the relevant object directory and library name.
8243b41a30aaSmrg	if test yes = "$installed"; then
824406f32fbeSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245b41a30aaSmrg	    func_warning "library '$lib' was moved."
8246b41a30aaSmrg	    dir=$ladir
8247b41a30aaSmrg	    absdir=$abs_ladir
8248b41a30aaSmrg	    libdir=$abs_ladir
8249ea133fd7Smrg	  else
8250b41a30aaSmrg	    dir=$lt_sysroot$libdir
8251b41a30aaSmrg	    absdir=$lt_sysroot$libdir
8252ea133fd7Smrg	  fi
8253b41a30aaSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8254ea133fd7Smrg	else
8255ea133fd7Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256b41a30aaSmrg	    dir=$ladir
8257b41a30aaSmrg	    absdir=$abs_ladir
8258ea133fd7Smrg	    # Remove this search path later
825906f32fbeSmrg	    func_append notinst_path " $abs_ladir"
8260ea133fd7Smrg	  else
8261b41a30aaSmrg	    dir=$ladir/$objdir
8262b41a30aaSmrg	    absdir=$abs_ladir/$objdir
8263ea133fd7Smrg	    # Remove this search path later
826406f32fbeSmrg	    func_append notinst_path " $abs_ladir"
8265ea133fd7Smrg	  fi
8266ea133fd7Smrg	fi # $installed = yes
8267ea133fd7Smrg	func_stripname 'lib' '.la' "$laname"
8268ea133fd7Smrg	name=$func_stripname_result
8269ea133fd7Smrg
8270ea133fd7Smrg	# This library was specified with -dlpreopen.
8271b41a30aaSmrg	if test dlpreopen = "$pass"; then
8272b41a30aaSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273b41a30aaSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8274ea133fd7Smrg	  fi
8275b41a30aaSmrg	  case $host in
827606f32fbeSmrg	    # special handling for platforms with PE-DLLs.
827706f32fbeSmrg	    *cygwin* | *mingw* | *cegcc* )
827806f32fbeSmrg	      # Linker will automatically link against shared library if both
827906f32fbeSmrg	      # static and shared are present.  Therefore, ensure we extract
828006f32fbeSmrg	      # symbols from the import library if a shared library is present
828106f32fbeSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
828206f32fbeSmrg	      # this by putting the import library name into $newdlprefiles.
828306f32fbeSmrg	      # We recover the dlopen module name by 'saving' the la file
828406f32fbeSmrg	      # name in a special purpose variable, and (later) extracting the
828506f32fbeSmrg	      # dlname from the la file.
828606f32fbeSmrg	      if test -n "$dlname"; then
828706f32fbeSmrg	        func_tr_sh "$dir/$linklib"
828806f32fbeSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
828906f32fbeSmrg	        func_append newdlprefiles " $dir/$linklib"
829006f32fbeSmrg	      else
829106f32fbeSmrg	        func_append newdlprefiles " $dir/$old_library"
829206f32fbeSmrg	        # Keep a list of preopened convenience libraries to check
829306f32fbeSmrg	        # that they are being used correctly in the link pass.
829406f32fbeSmrg	        test -z "$libdir" && \
829506f32fbeSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
829606f32fbeSmrg	      fi
829706f32fbeSmrg	    ;;
829806f32fbeSmrg	    * )
829906f32fbeSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
830006f32fbeSmrg	      # are required to link).
830106f32fbeSmrg	      if test -n "$old_library"; then
830206f32fbeSmrg	        func_append newdlprefiles " $dir/$old_library"
830306f32fbeSmrg	        # Keep a list of preopened convenience libraries to check
830406f32fbeSmrg	        # that they are being used correctly in the link pass.
830506f32fbeSmrg	        test -z "$libdir" && \
830606f32fbeSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
830706f32fbeSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
830806f32fbeSmrg	      elif test -n "$dlname"; then
830906f32fbeSmrg	        func_append newdlprefiles " $dir/$dlname"
831006f32fbeSmrg	      else
831106f32fbeSmrg	        func_append newdlprefiles " $dir/$linklib"
831206f32fbeSmrg	      fi
831306f32fbeSmrg	    ;;
831406f32fbeSmrg	  esac
8315ea133fd7Smrg	fi # $pass = dlpreopen
8316ea133fd7Smrg
8317ea133fd7Smrg	if test -z "$libdir"; then
8318ea133fd7Smrg	  # Link the convenience library
8319b41a30aaSmrg	  if test lib = "$linkmode"; then
8320ea133fd7Smrg	    deplibs="$dir/$old_library $deplibs"
8321b41a30aaSmrg	  elif test prog,link = "$linkmode,$pass"; then
8322ea133fd7Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8323ea133fd7Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8324ea133fd7Smrg	  else
8325ea133fd7Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8326ea133fd7Smrg	  fi
8327ea133fd7Smrg	  continue
8328ea133fd7Smrg	fi
8329ea133fd7Smrg
8330ea133fd7Smrg
8331b41a30aaSmrg	if test prog = "$linkmode" && test link != "$pass"; then
833206f32fbeSmrg	  func_append newlib_search_path " $ladir"
8333ea133fd7Smrg	  deplibs="$lib $deplibs"
8334ea133fd7Smrg
8335b41a30aaSmrg	  linkalldeplibs=false
8336b41a30aaSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337b41a30aaSmrg	     test no = "$build_libtool_libs"; then
8338b41a30aaSmrg	    linkalldeplibs=:
8339ea133fd7Smrg	  fi
8340ea133fd7Smrg
8341ea133fd7Smrg	  tmp_libs=
8342ea133fd7Smrg	  for deplib in $dependency_libs; do
8343ea133fd7Smrg	    case $deplib in
8344ea133fd7Smrg	    -L*) func_stripname '-L' '' "$deplib"
834506f32fbeSmrg	         func_resolve_sysroot "$func_stripname_result"
834606f32fbeSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8347ea133fd7Smrg		 ;;
8348ea133fd7Smrg	    esac
8349ea133fd7Smrg	    # Need to link against all dependency_libs?
8350b41a30aaSmrg	    if $linkalldeplibs; then
8351ea133fd7Smrg	      deplibs="$deplib $deplibs"
8352ea133fd7Smrg	    else
8353ea133fd7Smrg	      # Need to hardcode shared library paths
8354ea133fd7Smrg	      # or/and link against static libraries
8355ea133fd7Smrg	      newdependency_libs="$deplib $newdependency_libs"
8356ea133fd7Smrg	    fi
8357b41a30aaSmrg	    if $opt_preserve_dup_deps; then
8358ea133fd7Smrg	      case "$tmp_libs " in
835906f32fbeSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8360ea133fd7Smrg	      esac
8361ea133fd7Smrg	    fi
836206f32fbeSmrg	    func_append tmp_libs " $deplib"
8363ea133fd7Smrg	  done # for deplib
8364ea133fd7Smrg	  continue
8365ea133fd7Smrg	fi # $linkmode = prog...
8366ea133fd7Smrg
8367b41a30aaSmrg	if test prog,link = "$linkmode,$pass"; then
8368ea133fd7Smrg	  if test -n "$library_names" &&
8369b41a30aaSmrg	     { { test no = "$prefer_static_libs" ||
8370b41a30aaSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8371ea133fd7Smrg	       test -z "$old_library"; }; then
8372ea133fd7Smrg	    # We need to hardcode the library path
8373b41a30aaSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8374ea133fd7Smrg	      # Make sure the rpath contains only unique directories.
8375b41a30aaSmrg	      case $temp_rpath: in
8376ea133fd7Smrg	      *"$absdir:"*) ;;
837706f32fbeSmrg	      *) func_append temp_rpath "$absdir:" ;;
8378ea133fd7Smrg	      esac
8379ea133fd7Smrg	    fi
8380ea133fd7Smrg
8381ea133fd7Smrg	    # Hardcode the library path.
8382ea133fd7Smrg	    # Skip directories that are in the system default run-time
8383ea133fd7Smrg	    # search path.
8384ea133fd7Smrg	    case " $sys_lib_dlsearch_path " in
8385ea133fd7Smrg	    *" $absdir "*) ;;
8386ea133fd7Smrg	    *)
8387ea133fd7Smrg	      case "$compile_rpath " in
8388ea133fd7Smrg	      *" $absdir "*) ;;
838906f32fbeSmrg	      *) func_append compile_rpath " $absdir" ;;
8390ea133fd7Smrg	      esac
8391ea133fd7Smrg	      ;;
8392ea133fd7Smrg	    esac
8393ea133fd7Smrg	    case " $sys_lib_dlsearch_path " in
8394ea133fd7Smrg	    *" $libdir "*) ;;
8395ea133fd7Smrg	    *)
8396ea133fd7Smrg	      case "$finalize_rpath " in
8397ea133fd7Smrg	      *" $libdir "*) ;;
839806f32fbeSmrg	      *) func_append finalize_rpath " $libdir" ;;
8399ea133fd7Smrg	      esac
8400ea133fd7Smrg	      ;;
8401ea133fd7Smrg	    esac
8402ea133fd7Smrg	  fi # $linkmode,$pass = prog,link...
8403ea133fd7Smrg
8404b41a30aaSmrg	  if $alldeplibs &&
8405b41a30aaSmrg	     { test pass_all = "$deplibs_check_method" ||
8406b41a30aaSmrg	       { test yes = "$build_libtool_libs" &&
8407ea133fd7Smrg		 test -n "$library_names"; }; }; then
8408ea133fd7Smrg	    # We only need to search for static libraries
8409ea133fd7Smrg	    continue
8410ea133fd7Smrg	  fi
8411ea133fd7Smrg	fi
8412ea133fd7Smrg
8413ea133fd7Smrg	link_static=no # Whether the deplib will be linked statically
8414ea133fd7Smrg	use_static_libs=$prefer_static_libs
8415b41a30aaSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8416ea133fd7Smrg	  use_static_libs=no
8417ea133fd7Smrg	fi
8418ea133fd7Smrg	if test -n "$library_names" &&
8419b41a30aaSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8420ea133fd7Smrg	  case $host in
8421b41a30aaSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8422ea133fd7Smrg	      # No point in relinking DLLs because paths are not encoded
842306f32fbeSmrg	      func_append notinst_deplibs " $lib"
8424ea133fd7Smrg	      need_relink=no
8425ea133fd7Smrg	    ;;
8426ea133fd7Smrg	  *)
8427b41a30aaSmrg	    if test no = "$installed"; then
842806f32fbeSmrg	      func_append notinst_deplibs " $lib"
8429ea133fd7Smrg	      need_relink=yes
8430ea133fd7Smrg	    fi
8431ea133fd7Smrg	    ;;
8432ea133fd7Smrg	  esac
8433ea133fd7Smrg	  # This is a shared library
8434ea133fd7Smrg
8435ea133fd7Smrg	  # Warn about portability, can't link against -module's on some
8436ea133fd7Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437b41a30aaSmrg	  dlopenmodule=
8438ea133fd7Smrg	  for dlpremoduletest in $dlprefiles; do
8439ea133fd7Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440b41a30aaSmrg	      dlopenmodule=$dlpremoduletest
8441ea133fd7Smrg	      break
8442ea133fd7Smrg	    fi
8443ea133fd7Smrg	  done
8444b41a30aaSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
844525b89263Smrg	    echo
8446b41a30aaSmrg	    if test prog = "$linkmode"; then
8447ea133fd7Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8448ea133fd7Smrg	    else
8449ea133fd7Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8450ea133fd7Smrg	    fi
8451ea133fd7Smrg	    $ECHO "*** $linklib is not portable!"
8452ea133fd7Smrg	  fi
8453b41a30aaSmrg	  if test lib = "$linkmode" &&
8454b41a30aaSmrg	     test yes = "$hardcode_into_libs"; then
8455ea133fd7Smrg	    # Hardcode the library path.
8456ea133fd7Smrg	    # Skip directories that are in the system default run-time
8457ea133fd7Smrg	    # search path.
8458ea133fd7Smrg	    case " $sys_lib_dlsearch_path " in
8459ea133fd7Smrg	    *" $absdir "*) ;;
8460ea133fd7Smrg	    *)
8461ea133fd7Smrg	      case "$compile_rpath " in
8462ea133fd7Smrg	      *" $absdir "*) ;;
846306f32fbeSmrg	      *) func_append compile_rpath " $absdir" ;;
8464ea133fd7Smrg	      esac
8465ea133fd7Smrg	      ;;
8466ea133fd7Smrg	    esac
8467ea133fd7Smrg	    case " $sys_lib_dlsearch_path " in
8468ea133fd7Smrg	    *" $libdir "*) ;;
8469ea133fd7Smrg	    *)
8470ea133fd7Smrg	      case "$finalize_rpath " in
8471ea133fd7Smrg	      *" $libdir "*) ;;
847206f32fbeSmrg	      *) func_append finalize_rpath " $libdir" ;;
8473ea133fd7Smrg	      esac
8474ea133fd7Smrg	      ;;
8475ea133fd7Smrg	    esac
8476ea133fd7Smrg	  fi
8477ea133fd7Smrg
8478ea133fd7Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8479ea133fd7Smrg	    # figure out the soname
8480ea133fd7Smrg	    set dummy $library_names
8481ea133fd7Smrg	    shift
8482b41a30aaSmrg	    realname=$1
8483ea133fd7Smrg	    shift
8484ea133fd7Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8485ea133fd7Smrg	    # use dlname if we got it. it's perfectly good, no?
8486ea133fd7Smrg	    if test -n "$dlname"; then
8487b41a30aaSmrg	      soname=$dlname
8488ea133fd7Smrg	    elif test -n "$soname_spec"; then
8489ea133fd7Smrg	      # bleh windows
8490ea133fd7Smrg	      case $host in
8491b41a30aaSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8492ea133fd7Smrg	        func_arith $current - $age
8493ea133fd7Smrg		major=$func_arith_result
8494b41a30aaSmrg		versuffix=-$major
8495ea133fd7Smrg		;;
8496ea133fd7Smrg	      esac
8497ea133fd7Smrg	      eval soname=\"$soname_spec\"
8498ea133fd7Smrg	    else
8499b41a30aaSmrg	      soname=$realname
8500ea133fd7Smrg	    fi
8501ea133fd7Smrg
8502ea133fd7Smrg	    # Make a new name for the extract_expsyms_cmds to use
8503b41a30aaSmrg	    soroot=$soname
8504ea133fd7Smrg	    func_basename "$soroot"
8505b41a30aaSmrg	    soname=$func_basename_result
8506ea133fd7Smrg	    func_stripname 'lib' '.dll' "$soname"
8507ea133fd7Smrg	    newlib=libimp-$func_stripname_result.a
8508ea133fd7Smrg
8509ea133fd7Smrg	    # If the library has no export list, then create one now
8510ea133fd7Smrg	    if test -f "$output_objdir/$soname-def"; then :
8511ea133fd7Smrg	    else
8512b41a30aaSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8513ea133fd7Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8514ea133fd7Smrg	    fi
8515ea133fd7Smrg
8516ea133fd7Smrg	    # Create $newlib
8517ea133fd7Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8518b41a30aaSmrg	      func_verbose "generating import library for '$soname'"
8519ea133fd7Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8520ea133fd7Smrg	    fi
8521ea133fd7Smrg	    # make sure the library variables are pointing to the new library
8522ea133fd7Smrg	    dir=$output_objdir
8523ea133fd7Smrg	    linklib=$newlib
8524ea133fd7Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8525ea133fd7Smrg
8526b41a30aaSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8527ea133fd7Smrg	    add_shlibpath=
8528ea133fd7Smrg	    add_dir=
8529ea133fd7Smrg	    add=
8530ea133fd7Smrg	    lib_linked=yes
8531ea133fd7Smrg	    case $hardcode_action in
8532ea133fd7Smrg	    immediate | unsupported)
8533b41a30aaSmrg	      if test no = "$hardcode_direct"; then
8534b41a30aaSmrg		add=$dir/$linklib
8535ea133fd7Smrg		case $host in
8536b41a30aaSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537b41a30aaSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8538ea133fd7Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539b41a30aaSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8540ea133fd7Smrg		  *-*-darwin* )
8541b41a30aaSmrg		    # if the lib is a (non-dlopened) module then we cannot
8542ea133fd7Smrg		    # link against it, someone is ignoring the earlier warnings
8543ea133fd7Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8544b41a30aaSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8545ea133fd7Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8546ea133fd7Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547b41a30aaSmrg			if test -z "$old_library"; then
854825b89263Smrg			  echo
854925b89263Smrg			  echo "*** And there doesn't seem to be a static archive available"
855025b89263Smrg			  echo "*** The link will probably fail, sorry"
8551ea133fd7Smrg			else
8552b41a30aaSmrg			  add=$dir/$old_library
8553ea133fd7Smrg			fi
8554ea133fd7Smrg		      elif test -n "$old_library"; then
8555b41a30aaSmrg			add=$dir/$old_library
8556ea133fd7Smrg		      fi
8557ea133fd7Smrg		    fi
8558ea133fd7Smrg		esac
8559b41a30aaSmrg	      elif test no = "$hardcode_minus_L"; then
8560ea133fd7Smrg		case $host in
8561b41a30aaSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8562ea133fd7Smrg		esac
8563b41a30aaSmrg		add_dir=-L$dir
8564b41a30aaSmrg		add=-l$name
8565b41a30aaSmrg	      elif test no = "$hardcode_shlibpath_var"; then
8566b41a30aaSmrg		add_shlibpath=$dir
8567b41a30aaSmrg		add=-l$name
8568ea133fd7Smrg	      else
8569ea133fd7Smrg		lib_linked=no
8570ea133fd7Smrg	      fi
8571ea133fd7Smrg	      ;;
8572ea133fd7Smrg	    relink)
8573b41a30aaSmrg	      if test yes = "$hardcode_direct" &&
8574b41a30aaSmrg	         test no = "$hardcode_direct_absolute"; then
8575b41a30aaSmrg		add=$dir/$linklib
8576b41a30aaSmrg	      elif test yes = "$hardcode_minus_L"; then
8577b41a30aaSmrg		add_dir=-L$absdir
8578ea133fd7Smrg		# Try looking first in the location we're being installed to.
8579ea133fd7Smrg		if test -n "$inst_prefix_dir"; then
8580ea133fd7Smrg		  case $libdir in
8581ea133fd7Smrg		    [\\/]*)
858206f32fbeSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8583ea133fd7Smrg		      ;;
8584ea133fd7Smrg		  esac
8585ea133fd7Smrg		fi
8586b41a30aaSmrg		add=-l$name
8587b41a30aaSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588b41a30aaSmrg		add_shlibpath=$dir
8589b41a30aaSmrg		add=-l$name
8590ea133fd7Smrg	      else
8591ea133fd7Smrg		lib_linked=no
8592ea133fd7Smrg	      fi
8593ea133fd7Smrg	      ;;
8594ea133fd7Smrg	    *) lib_linked=no ;;
8595ea133fd7Smrg	    esac
8596ea133fd7Smrg
8597b41a30aaSmrg	    if test yes != "$lib_linked"; then
8598ea133fd7Smrg	      func_fatal_configuration "unsupported hardcode properties"
8599ea133fd7Smrg	    fi
8600ea133fd7Smrg
8601ea133fd7Smrg	    if test -n "$add_shlibpath"; then
8602ea133fd7Smrg	      case :$compile_shlibpath: in
8603ea133fd7Smrg	      *":$add_shlibpath:"*) ;;
860406f32fbeSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8605ea133fd7Smrg	      esac
8606ea133fd7Smrg	    fi
8607b41a30aaSmrg	    if test prog = "$linkmode"; then
8608ea133fd7Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8609ea133fd7Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8610ea133fd7Smrg	    else
8611ea133fd7Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8612ea133fd7Smrg	      test -n "$add" && deplibs="$add $deplibs"
8613b41a30aaSmrg	      if test yes != "$hardcode_direct" &&
8614b41a30aaSmrg		 test yes != "$hardcode_minus_L" &&
8615b41a30aaSmrg		 test yes = "$hardcode_shlibpath_var"; then
8616ea133fd7Smrg		case :$finalize_shlibpath: in
8617ea133fd7Smrg		*":$libdir:"*) ;;
861806f32fbeSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
8619ea133fd7Smrg		esac
8620ea133fd7Smrg	      fi
8621ea133fd7Smrg	    fi
8622ea133fd7Smrg	  fi
8623ea133fd7Smrg
8624b41a30aaSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8625ea133fd7Smrg	    add_shlibpath=
8626ea133fd7Smrg	    add_dir=
8627ea133fd7Smrg	    add=
8628ea133fd7Smrg	    # Finalize command for both is simple: just hardcode it.
8629b41a30aaSmrg	    if test yes = "$hardcode_direct" &&
8630b41a30aaSmrg	       test no = "$hardcode_direct_absolute"; then
8631b41a30aaSmrg	      add=$libdir/$linklib
8632b41a30aaSmrg	    elif test yes = "$hardcode_minus_L"; then
8633b41a30aaSmrg	      add_dir=-L$libdir
8634b41a30aaSmrg	      add=-l$name
8635b41a30aaSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8636ea133fd7Smrg	      case :$finalize_shlibpath: in
8637ea133fd7Smrg	      *":$libdir:"*) ;;
863806f32fbeSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8639ea133fd7Smrg	      esac
8640b41a30aaSmrg	      add=-l$name
8641b41a30aaSmrg	    elif test yes = "$hardcode_automatic"; then
8642ea133fd7Smrg	      if test -n "$inst_prefix_dir" &&
8643b41a30aaSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644b41a30aaSmrg		add=$inst_prefix_dir$libdir/$linklib
8645ea133fd7Smrg	      else
8646b41a30aaSmrg		add=$libdir/$linklib
8647ea133fd7Smrg	      fi
8648ea133fd7Smrg	    else
8649ea133fd7Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650b41a30aaSmrg	      add_dir=-L$libdir
8651ea133fd7Smrg	      # Try looking first in the location we're being installed to.
8652ea133fd7Smrg	      if test -n "$inst_prefix_dir"; then
8653ea133fd7Smrg		case $libdir in
8654ea133fd7Smrg		  [\\/]*)
865506f32fbeSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8656ea133fd7Smrg		    ;;
8657ea133fd7Smrg		esac
8658ea133fd7Smrg	      fi
8659b41a30aaSmrg	      add=-l$name
8660ea133fd7Smrg	    fi
8661ea133fd7Smrg
8662b41a30aaSmrg	    if test prog = "$linkmode"; then
8663ea133fd7Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8664ea133fd7Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8665ea133fd7Smrg	    else
8666ea133fd7Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8667ea133fd7Smrg	      test -n "$add" && deplibs="$add $deplibs"
8668ea133fd7Smrg	    fi
8669ea133fd7Smrg	  fi
8670b41a30aaSmrg	elif test prog = "$linkmode"; then
8671ea133fd7Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8672ea133fd7Smrg	  # is not unsupported.  This is valid on all known static and
8673ea133fd7Smrg	  # shared platforms.
8674b41a30aaSmrg	  if test unsupported != "$hardcode_direct"; then
8675b41a30aaSmrg	    test -n "$old_library" && linklib=$old_library
8676ea133fd7Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8677ea133fd7Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8678ea133fd7Smrg	  else
8679ea133fd7Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8680ea133fd7Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8681ea133fd7Smrg	  fi
8682b41a30aaSmrg	elif test yes = "$build_libtool_libs"; then
8683ea133fd7Smrg	  # Not a shared library
8684b41a30aaSmrg	  if test pass_all != "$deplibs_check_method"; then
8685ea133fd7Smrg	    # We're trying link a shared library against a static one
8686ea133fd7Smrg	    # but the system doesn't support it.
8687ea133fd7Smrg
8688ea133fd7Smrg	    # Just print a warning and add the library to dependency_libs so
8689ea133fd7Smrg	    # that the program can be linked against the static library.
869025b89263Smrg	    echo
8691b41a30aaSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
869225b89263Smrg	    echo "*** I have the capability to make that library automatically link in when"
869325b89263Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
869425b89263Smrg	    echo "*** shared version of the library, which you do not appear to have."
8695b41a30aaSmrg	    if test yes = "$module"; then
869625b89263Smrg	      echo "*** But as you try to build a module library, libtool will still create "
869725b89263Smrg	      echo "*** a static module, that should work as long as the dlopening application"
869825b89263Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8699ea133fd7Smrg	      if test -z "$global_symbol_pipe"; then
870025b89263Smrg		echo
870125b89263Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702b41a30aaSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
870325b89263Smrg		echo "*** not find such a program.  So, this module is probably useless."
8704b41a30aaSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8705ea133fd7Smrg	      fi
8706b41a30aaSmrg	      if test no = "$build_old_libs"; then
8707ea133fd7Smrg		build_libtool_libs=module
8708ea133fd7Smrg		build_old_libs=yes
8709ea133fd7Smrg	      else
8710ea133fd7Smrg		build_libtool_libs=no
8711ea133fd7Smrg	      fi
8712ea133fd7Smrg	    fi
8713ea133fd7Smrg	  else
8714ea133fd7Smrg	    deplibs="$dir/$old_library $deplibs"
8715ea133fd7Smrg	    link_static=yes
8716ea133fd7Smrg	  fi
8717ea133fd7Smrg	fi # link shared/static library?
8718ea133fd7Smrg
8719b41a30aaSmrg	if test lib = "$linkmode"; then
8720ea133fd7Smrg	  if test -n "$dependency_libs" &&
8721b41a30aaSmrg	     { test yes != "$hardcode_into_libs" ||
8722b41a30aaSmrg	       test yes = "$build_old_libs" ||
8723b41a30aaSmrg	       test yes = "$link_static"; }; then
8724ea133fd7Smrg	    # Extract -R from dependency_libs
8725ea133fd7Smrg	    temp_deplibs=
8726ea133fd7Smrg	    for libdir in $dependency_libs; do
8727ea133fd7Smrg	      case $libdir in
8728ea133fd7Smrg	      -R*) func_stripname '-R' '' "$libdir"
8729ea133fd7Smrg	           temp_xrpath=$func_stripname_result
8730ea133fd7Smrg		   case " $xrpath " in
8731ea133fd7Smrg		   *" $temp_xrpath "*) ;;
873206f32fbeSmrg		   *) func_append xrpath " $temp_xrpath";;
8733ea133fd7Smrg		   esac;;
873406f32fbeSmrg	      *) func_append temp_deplibs " $libdir";;
8735ea133fd7Smrg	      esac
8736ea133fd7Smrg	    done
8737b41a30aaSmrg	    dependency_libs=$temp_deplibs
8738ea133fd7Smrg	  fi
8739ea133fd7Smrg
874006f32fbeSmrg	  func_append newlib_search_path " $absdir"
8741ea133fd7Smrg	  # Link against this library
8742b41a30aaSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8743ea133fd7Smrg	  # ... and its dependency_libs
8744ea133fd7Smrg	  tmp_libs=
8745ea133fd7Smrg	  for deplib in $dependency_libs; do
8746ea133fd7Smrg	    newdependency_libs="$deplib $newdependency_libs"
874706f32fbeSmrg	    case $deplib in
874806f32fbeSmrg              -L*) func_stripname '-L' '' "$deplib"
874906f32fbeSmrg                   func_resolve_sysroot "$func_stripname_result";;
875006f32fbeSmrg              *) func_resolve_sysroot "$deplib" ;;
875106f32fbeSmrg            esac
8752b41a30aaSmrg	    if $opt_preserve_dup_deps; then
8753ea133fd7Smrg	      case "$tmp_libs " in
875406f32fbeSmrg	      *" $func_resolve_sysroot_result "*)
875506f32fbeSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8756ea133fd7Smrg	      esac
8757ea133fd7Smrg	    fi
875806f32fbeSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8759ea133fd7Smrg	  done
8760ea133fd7Smrg
8761b41a30aaSmrg	  if test no != "$link_all_deplibs"; then
8762ea133fd7Smrg	    # Add the search paths of all dependency libraries
8763ea133fd7Smrg	    for deplib in $dependency_libs; do
876425b89263Smrg	      path=
8765ea133fd7Smrg	      case $deplib in
8766b41a30aaSmrg	      -L*) path=$deplib ;;
8767ea133fd7Smrg	      *.la)
876806f32fbeSmrg	        func_resolve_sysroot "$deplib"
876906f32fbeSmrg	        deplib=$func_resolve_sysroot_result
8770ea133fd7Smrg	        func_dirname "$deplib" "" "."
877106f32fbeSmrg		dir=$func_dirname_result
8772ea133fd7Smrg		# We need an absolute path.
8773ea133fd7Smrg		case $dir in
8774b41a30aaSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8775ea133fd7Smrg		*)
8776ea133fd7Smrg		  absdir=`cd "$dir" && pwd`
8777ea133fd7Smrg		  if test -z "$absdir"; then
8778b41a30aaSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779b41a30aaSmrg		    absdir=$dir
8780ea133fd7Smrg		  fi
8781ea133fd7Smrg		  ;;
8782ea133fd7Smrg		esac
8783ea133fd7Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8784ea133fd7Smrg		case $host in
8785ea133fd7Smrg		*-*-darwin*)
8786ea133fd7Smrg		  depdepl=
8787b41a30aaSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788b41a30aaSmrg		  if test -n "$deplibrary_names"; then
8789b41a30aaSmrg		    for tmp in $deplibrary_names; do
8790ea133fd7Smrg		      depdepl=$tmp
8791ea133fd7Smrg		    done
8792b41a30aaSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793b41a30aaSmrg		      depdepl=$absdir/$objdir/$depdepl
8794b41a30aaSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8795ea133fd7Smrg                      if test -z "$darwin_install_name"; then
8796b41a30aaSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8797ea133fd7Smrg                      fi
8798b41a30aaSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799b41a30aaSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8800ea133fd7Smrg		      path=
8801ea133fd7Smrg		    fi
8802ea133fd7Smrg		  fi
8803ea133fd7Smrg		  ;;
8804ea133fd7Smrg		*)
8805b41a30aaSmrg		  path=-L$absdir/$objdir
8806ea133fd7Smrg		  ;;
8807ea133fd7Smrg		esac
8808ea133fd7Smrg		else
8809b41a30aaSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8810ea133fd7Smrg		  test -z "$libdir" && \
8811b41a30aaSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8812ea133fd7Smrg		  test "$absdir" != "$libdir" && \
8813b41a30aaSmrg		    func_warning "'$deplib' seems to be moved"
8814ea133fd7Smrg
8815b41a30aaSmrg		  path=-L$absdir
8816ea133fd7Smrg		fi
8817ea133fd7Smrg		;;
8818ea133fd7Smrg	      esac
8819ea133fd7Smrg	      case " $deplibs " in
8820ea133fd7Smrg	      *" $path "*) ;;
8821ea133fd7Smrg	      *) deplibs="$path $deplibs" ;;
8822ea133fd7Smrg	      esac
8823ea133fd7Smrg	    done
8824ea133fd7Smrg	  fi # link_all_deplibs != no
8825ea133fd7Smrg	fi # linkmode = lib
8826ea133fd7Smrg      done # for deplib in $libs
8827b41a30aaSmrg      if test link = "$pass"; then
8828b41a30aaSmrg	if test prog = "$linkmode"; then
8829ea133fd7Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8830ea133fd7Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8831ea133fd7Smrg	else
883225b89263Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8833ea133fd7Smrg	fi
8834ea133fd7Smrg      fi
8835b41a30aaSmrg      dependency_libs=$newdependency_libs
8836b41a30aaSmrg      if test dlpreopen = "$pass"; then
8837ea133fd7Smrg	# Link the dlpreopened libraries before other libraries
8838ea133fd7Smrg	for deplib in $save_deplibs; do
8839ea133fd7Smrg	  deplibs="$deplib $deplibs"
8840ea133fd7Smrg	done
8841ea133fd7Smrg      fi
8842b41a30aaSmrg      if test dlopen != "$pass"; then
8843b41a30aaSmrg	test conv = "$pass" || {
8844ea133fd7Smrg	  # Make sure lib_search_path contains only unique directories.
8845ea133fd7Smrg	  lib_search_path=
8846ea133fd7Smrg	  for dir in $newlib_search_path; do
8847ea133fd7Smrg	    case "$lib_search_path " in
8848ea133fd7Smrg	    *" $dir "*) ;;
884906f32fbeSmrg	    *) func_append lib_search_path " $dir" ;;
8850ea133fd7Smrg	    esac
8851ea133fd7Smrg	  done
8852ea133fd7Smrg	  newlib_search_path=
8853b41a30aaSmrg	}
8854ea133fd7Smrg
8855b41a30aaSmrg	if test prog,link = "$linkmode,$pass"; then
8856ea133fd7Smrg	  vars="compile_deplibs finalize_deplibs"
8857b41a30aaSmrg	else
8858b41a30aaSmrg	  vars=deplibs
8859ea133fd7Smrg	fi
8860ea133fd7Smrg	for var in $vars dependency_libs; do
8861ea133fd7Smrg	  # Add libraries to $var in reverse order
8862ea133fd7Smrg	  eval tmp_libs=\"\$$var\"
8863ea133fd7Smrg	  new_libs=
8864ea133fd7Smrg	  for deplib in $tmp_libs; do
8865ea133fd7Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8866ea133fd7Smrg	    #        that some nasty dependency loop isn't accidentally
8867ea133fd7Smrg	    #        broken:
8868ea133fd7Smrg	    #new_libs="$deplib $new_libs"
8869ea133fd7Smrg	    # Pragmatically, this seems to cause very few problems in
8870ea133fd7Smrg	    # practice:
8871ea133fd7Smrg	    case $deplib in
8872ea133fd7Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8873ea133fd7Smrg	    -R*) ;;
8874ea133fd7Smrg	    *)
8875ea133fd7Smrg	      # And here is the reason: when a library appears more
8876ea133fd7Smrg	      # than once as an explicit dependence of a library, or
8877ea133fd7Smrg	      # is implicitly linked in more than once by the
8878ea133fd7Smrg	      # compiler, it is considered special, and multiple
8879ea133fd7Smrg	      # occurrences thereof are not removed.  Compare this
8880ea133fd7Smrg	      # with having the same library being listed as a
8881ea133fd7Smrg	      # dependency of multiple other libraries: in this case,
8882ea133fd7Smrg	      # we know (pedantically, we assume) the library does not
8883ea133fd7Smrg	      # need to be listed more than once, so we keep only the
8884ea133fd7Smrg	      # last copy.  This is not always right, but it is rare
8885ea133fd7Smrg	      # enough that we require users that really mean to play
8886ea133fd7Smrg	      # such unportable linking tricks to link the library
8887ea133fd7Smrg	      # using -Wl,-lname, so that libtool does not consider it
8888ea133fd7Smrg	      # for duplicate removal.
8889ea133fd7Smrg	      case " $specialdeplibs " in
8890ea133fd7Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8891ea133fd7Smrg	      *)
8892ea133fd7Smrg		case " $new_libs " in
8893ea133fd7Smrg		*" $deplib "*) ;;
8894ea133fd7Smrg		*) new_libs="$deplib $new_libs" ;;
8895ea133fd7Smrg		esac
8896ea133fd7Smrg		;;
8897ea133fd7Smrg	      esac
8898ea133fd7Smrg	      ;;
8899ea133fd7Smrg	    esac
8900ea133fd7Smrg	  done
8901ea133fd7Smrg	  tmp_libs=
8902ea133fd7Smrg	  for deplib in $new_libs; do
8903ea133fd7Smrg	    case $deplib in
8904ea133fd7Smrg	    -L*)
8905ea133fd7Smrg	      case " $tmp_libs " in
8906ea133fd7Smrg	      *" $deplib "*) ;;
890706f32fbeSmrg	      *) func_append tmp_libs " $deplib" ;;
8908ea133fd7Smrg	      esac
8909ea133fd7Smrg	      ;;
891006f32fbeSmrg	    *) func_append tmp_libs " $deplib" ;;
8911ea133fd7Smrg	    esac
8912ea133fd7Smrg	  done
8913ea133fd7Smrg	  eval $var=\"$tmp_libs\"
8914ea133fd7Smrg	done # for var
8915ea133fd7Smrg      fi
8916b41a30aaSmrg
8917b41a30aaSmrg      # Add Sun CC postdeps if required:
8918b41a30aaSmrg      test CXX = "$tagname" && {
8919b41a30aaSmrg        case $host_os in
8920b41a30aaSmrg        linux*)
8921b41a30aaSmrg          case `$CC -V 2>&1 | $SED 5q` in
8922b41a30aaSmrg          *Sun\ C*) # Sun C++ 5.9
8923b41a30aaSmrg            func_suncc_cstd_abi
8924b41a30aaSmrg
8925b41a30aaSmrg            if test no != "$suncc_use_cstd_abi"; then
8926b41a30aaSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8927b41a30aaSmrg            fi
8928b41a30aaSmrg            ;;
8929b41a30aaSmrg          esac
8930b41a30aaSmrg          ;;
8931b41a30aaSmrg
8932b41a30aaSmrg        solaris*)
8933b41a30aaSmrg          func_cc_basename "$CC"
8934b41a30aaSmrg          case $func_cc_basename_result in
8935b41a30aaSmrg          CC* | sunCC*)
8936b41a30aaSmrg            func_suncc_cstd_abi
8937b41a30aaSmrg
8938b41a30aaSmrg            if test no != "$suncc_use_cstd_abi"; then
8939b41a30aaSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8940b41a30aaSmrg            fi
8941b41a30aaSmrg            ;;
8942b41a30aaSmrg          esac
8943b41a30aaSmrg          ;;
8944b41a30aaSmrg        esac
8945b41a30aaSmrg      }
8946b41a30aaSmrg
8947ea133fd7Smrg      # Last step: remove runtime libs from dependency_libs
8948ea133fd7Smrg      # (they stay in deplibs)
8949ea133fd7Smrg      tmp_libs=
8950b41a30aaSmrg      for i in $dependency_libs; do
8951ea133fd7Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8952ea133fd7Smrg	*" $i "*)
8953b41a30aaSmrg	  i=
8954ea133fd7Smrg	  ;;
8955ea133fd7Smrg	esac
8956b41a30aaSmrg	if test -n "$i"; then
895706f32fbeSmrg	  func_append tmp_libs " $i"
8958ea133fd7Smrg	fi
8959ea133fd7Smrg      done
8960ea133fd7Smrg      dependency_libs=$tmp_libs
8961ea133fd7Smrg    done # for pass
8962b41a30aaSmrg    if test prog = "$linkmode"; then
8963b41a30aaSmrg      dlfiles=$newdlfiles
8964ea133fd7Smrg    fi
8965b41a30aaSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966b41a30aaSmrg      dlprefiles=$newdlprefiles
8967ea133fd7Smrg    fi
8968ea133fd7Smrg
8969ea133fd7Smrg    case $linkmode in
8970ea133fd7Smrg    oldlib)
8971b41a30aaSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972b41a30aaSmrg	func_warning "'-dlopen' is ignored for archives"
8973ea133fd7Smrg      fi
8974ea133fd7Smrg
8975ea133fd7Smrg      case " $deplibs" in
8976ea133fd7Smrg      *\ -l* | *\ -L*)
8977b41a30aaSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8978ea133fd7Smrg      esac
8979ea133fd7Smrg
8980ea133fd7Smrg      test -n "$rpath" && \
8981b41a30aaSmrg	func_warning "'-rpath' is ignored for archives"
8982ea133fd7Smrg
8983ea133fd7Smrg      test -n "$xrpath" && \
8984b41a30aaSmrg	func_warning "'-R' is ignored for archives"
8985ea133fd7Smrg
8986ea133fd7Smrg      test -n "$vinfo" && \
8987b41a30aaSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
8988ea133fd7Smrg
8989ea133fd7Smrg      test -n "$release" && \
8990b41a30aaSmrg	func_warning "'-release' is ignored for archives"
8991ea133fd7Smrg
8992ea133fd7Smrg      test -n "$export_symbols$export_symbols_regex" && \
8993b41a30aaSmrg	func_warning "'-export-symbols' is ignored for archives"
8994ea133fd7Smrg
8995ea133fd7Smrg      # Now set the variables for building old libraries.
8996ea133fd7Smrg      build_libtool_libs=no
8997b41a30aaSmrg      oldlibs=$output
899806f32fbeSmrg      func_append objs "$old_deplibs"
8999ea133fd7Smrg      ;;
9000ea133fd7Smrg
9001ea133fd7Smrg    lib)
9002b41a30aaSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9003ea133fd7Smrg      case $outputname in
9004ea133fd7Smrg      lib*)
9005ea133fd7Smrg	func_stripname 'lib' '.la' "$outputname"
9006ea133fd7Smrg	name=$func_stripname_result
9007ea133fd7Smrg	eval shared_ext=\"$shrext_cmds\"
9008ea133fd7Smrg	eval libname=\"$libname_spec\"
9009ea133fd7Smrg	;;
9010ea133fd7Smrg      *)
9011b41a30aaSmrg	test no = "$module" \
9012b41a30aaSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9013ea133fd7Smrg
9014b41a30aaSmrg	if test no != "$need_lib_prefix"; then
9015ea133fd7Smrg	  # Add the "lib" prefix for modules if required
9016ea133fd7Smrg	  func_stripname '' '.la' "$outputname"
9017ea133fd7Smrg	  name=$func_stripname_result
9018ea133fd7Smrg	  eval shared_ext=\"$shrext_cmds\"
9019ea133fd7Smrg	  eval libname=\"$libname_spec\"
9020ea133fd7Smrg	else
9021ea133fd7Smrg	  func_stripname '' '.la' "$outputname"
9022ea133fd7Smrg	  libname=$func_stripname_result
9023ea133fd7Smrg	fi
9024ea133fd7Smrg	;;
9025ea133fd7Smrg      esac
9026ea133fd7Smrg
9027ea133fd7Smrg      if test -n "$objs"; then
9028b41a30aaSmrg	if test pass_all != "$deplibs_check_method"; then
9029b41a30aaSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9030ea133fd7Smrg	else
903125b89263Smrg	  echo
9032ea133fd7Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9033ea133fd7Smrg	  $ECHO "*** objects $objs is not portable!"
903406f32fbeSmrg	  func_append libobjs " $objs"
9035ea133fd7Smrg	fi
9036ea133fd7Smrg      fi
9037ea133fd7Smrg
9038b41a30aaSmrg      test no = "$dlself" \
9039b41a30aaSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9040ea133fd7Smrg
9041ea133fd7Smrg      set dummy $rpath
9042ea133fd7Smrg      shift
9043b41a30aaSmrg      test 1 -lt "$#" \
9044b41a30aaSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9045ea133fd7Smrg
9046b41a30aaSmrg      install_libdir=$1
9047ea133fd7Smrg
9048ea133fd7Smrg      oldlibs=
9049ea133fd7Smrg      if test -z "$rpath"; then
9050b41a30aaSmrg	if test yes = "$build_libtool_libs"; then
9051ea133fd7Smrg	  # Building a libtool convenience library.
9052b41a30aaSmrg	  # Some compilers have problems with a '.al' extension so
9053ea133fd7Smrg	  # convenience libraries should have the same extension an
9054ea133fd7Smrg	  # archive normally would.
9055ea133fd7Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9056ea133fd7Smrg	  build_libtool_libs=convenience
9057ea133fd7Smrg	  build_old_libs=yes
9058ea133fd7Smrg	fi
9059ea133fd7Smrg
9060ea133fd7Smrg	test -n "$vinfo" && \
9061b41a30aaSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9062ea133fd7Smrg
9063ea133fd7Smrg	test -n "$release" && \
9064b41a30aaSmrg	  func_warning "'-release' is ignored for convenience libraries"
9065ea133fd7Smrg      else
9066ea133fd7Smrg
9067ea133fd7Smrg	# Parse the version information argument.
9068b41a30aaSmrg	save_ifs=$IFS; IFS=:
9069ea133fd7Smrg	set dummy $vinfo 0 0 0
9070ea133fd7Smrg	shift
9071b41a30aaSmrg	IFS=$save_ifs
9072ea133fd7Smrg
9073ea133fd7Smrg	test -n "$7" && \
9074b41a30aaSmrg	  func_fatal_help "too many parameters to '-version-info'"
9075ea133fd7Smrg
9076ea133fd7Smrg	# convert absolute version numbers to libtool ages
9077ea133fd7Smrg	# this retains compatibility with .la files and attempts
9078ea133fd7Smrg	# to make the code below a bit more comprehensible
9079ea133fd7Smrg
9080ea133fd7Smrg	case $vinfo_number in
9081ea133fd7Smrg	yes)
9082b41a30aaSmrg	  number_major=$1
9083b41a30aaSmrg	  number_minor=$2
9084b41a30aaSmrg	  number_revision=$3
9085ea133fd7Smrg	  #
9086ea133fd7Smrg	  # There are really only two kinds -- those that
9087ea133fd7Smrg	  # use the current revision as the major version
9088ea133fd7Smrg	  # and those that subtract age and use age as
9089ea133fd7Smrg	  # a minor version.  But, then there is irix
9090b41a30aaSmrg	  # that has an extra 1 added just for fun
9091ea133fd7Smrg	  #
9092ea133fd7Smrg	  case $version_type in
909357ee1794Smrg	  # correct linux to gnu/linux during the next big refactor
9094b41a30aaSmrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9095ea133fd7Smrg	    func_arith $number_major + $number_minor
9096ea133fd7Smrg	    current=$func_arith_result
9097b41a30aaSmrg	    age=$number_minor
9098b41a30aaSmrg	    revision=$number_revision
9099ea133fd7Smrg	    ;;
9100b41a30aaSmrg	  freebsd-aout|qnx|sunos)
9101b41a30aaSmrg	    current=$number_major
9102b41a30aaSmrg	    revision=$number_minor
9103b41a30aaSmrg	    age=0
9104ea133fd7Smrg	    ;;
9105ea133fd7Smrg	  irix|nonstopux)
9106ea133fd7Smrg	    func_arith $number_major + $number_minor
9107ea133fd7Smrg	    current=$func_arith_result
9108b41a30aaSmrg	    age=$number_minor
9109b41a30aaSmrg	    revision=$number_minor
9110ea133fd7Smrg	    lt_irix_increment=no
9111ea133fd7Smrg	    ;;
9112ea133fd7Smrg	  esac
9113ea133fd7Smrg	  ;;
9114ea133fd7Smrg	no)
9115b41a30aaSmrg	  current=$1
9116b41a30aaSmrg	  revision=$2
9117b41a30aaSmrg	  age=$3
9118ea133fd7Smrg	  ;;
9119ea133fd7Smrg	esac
9120ea133fd7Smrg
9121ea133fd7Smrg	# Check that each of the things are valid numbers.
9122ea133fd7Smrg	case $current in
9123ea133fd7Smrg	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]) ;;
9124ea133fd7Smrg	*)
9125b41a30aaSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126b41a30aaSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9127ea133fd7Smrg	  ;;
9128ea133fd7Smrg	esac
9129ea133fd7Smrg
9130ea133fd7Smrg	case $revision in
9131ea133fd7Smrg	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]) ;;
9132ea133fd7Smrg	*)
9133b41a30aaSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134b41a30aaSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9135ea133fd7Smrg	  ;;
9136ea133fd7Smrg	esac
9137ea133fd7Smrg
9138ea133fd7Smrg	case $age in
9139ea133fd7Smrg	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]) ;;
9140ea133fd7Smrg	*)
9141b41a30aaSmrg	  func_error "AGE '$age' must be a nonnegative integer"
9142b41a30aaSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9143ea133fd7Smrg	  ;;
9144ea133fd7Smrg	esac
9145ea133fd7Smrg
9146ea133fd7Smrg	if test "$age" -gt "$current"; then
9147b41a30aaSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148b41a30aaSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9149ea133fd7Smrg	fi
9150ea133fd7Smrg
9151ea133fd7Smrg	# Calculate the version variables.
9152ea133fd7Smrg	major=
9153ea133fd7Smrg	versuffix=
9154ea133fd7Smrg	verstring=
9155ea133fd7Smrg	case $version_type in
9156ea133fd7Smrg	none) ;;
9157ea133fd7Smrg
9158ea133fd7Smrg	darwin)
9159ea133fd7Smrg	  # Like Linux, but with the current version available in
9160ea133fd7Smrg	  # verstring for coding it into the library header
9161ea133fd7Smrg	  func_arith $current - $age
9162ea133fd7Smrg	  major=.$func_arith_result
9163b41a30aaSmrg	  versuffix=$major.$age.$revision
9164ea133fd7Smrg	  # Darwin ld doesn't like 0 for these options...
9165ea133fd7Smrg	  func_arith $current + 1
9166ea133fd7Smrg	  minor_current=$func_arith_result
9167b41a30aaSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9168ea133fd7Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169b41a30aaSmrg          # On Darwin other compilers
9170b41a30aaSmrg          case $CC in
9171b41a30aaSmrg              nagfor*)
9172b41a30aaSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173b41a30aaSmrg                  ;;
9174b41a30aaSmrg              *)
9175b41a30aaSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176b41a30aaSmrg                  ;;
9177b41a30aaSmrg          esac
9178ea133fd7Smrg	  ;;
9179ea133fd7Smrg
9180ea133fd7Smrg	freebsd-aout)
9181b41a30aaSmrg	  major=.$current
9182b41a30aaSmrg	  versuffix=.$current.$revision
9183ea133fd7Smrg	  ;;
9184ea133fd7Smrg
9185b41a30aaSmrg	freebsd-elf | midnightbsd-elf)
9186b41a30aaSmrg	  func_arith $current - $age
9187b41a30aaSmrg	  major=.$func_arith_result
9188b41a30aaSmrg	  versuffix=$major.$age.$revision
9189ea133fd7Smrg	  ;;
9190ea133fd7Smrg
9191ea133fd7Smrg	irix | nonstopux)
9192b41a30aaSmrg	  if test no = "$lt_irix_increment"; then
9193ea133fd7Smrg	    func_arith $current - $age
9194ea133fd7Smrg	  else
9195ea133fd7Smrg	    func_arith $current - $age + 1
9196ea133fd7Smrg	  fi
9197ea133fd7Smrg	  major=$func_arith_result
9198ea133fd7Smrg
9199ea133fd7Smrg	  case $version_type in
9200ea133fd7Smrg	    nonstopux) verstring_prefix=nonstopux ;;
9201ea133fd7Smrg	    *)         verstring_prefix=sgi ;;
9202ea133fd7Smrg	  esac
9203b41a30aaSmrg	  verstring=$verstring_prefix$major.$revision
9204ea133fd7Smrg
9205ea133fd7Smrg	  # Add in all the interfaces that we are compatible with.
9206ea133fd7Smrg	  loop=$revision
9207b41a30aaSmrg	  while test 0 -ne "$loop"; do
9208ea133fd7Smrg	    func_arith $revision - $loop
9209ea133fd7Smrg	    iface=$func_arith_result
9210ea133fd7Smrg	    func_arith $loop - 1
9211ea133fd7Smrg	    loop=$func_arith_result
9212b41a30aaSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
9213ea133fd7Smrg	  done
9214ea133fd7Smrg
9215b41a30aaSmrg	  # Before this point, $major must not contain '.'.
9216ea133fd7Smrg	  major=.$major
9217b41a30aaSmrg	  versuffix=$major.$revision
9218ea133fd7Smrg	  ;;
9219ea133fd7Smrg
922057ee1794Smrg	linux) # correct to gnu/linux during the next big refactor
9221ea133fd7Smrg	  func_arith $current - $age
9222ea133fd7Smrg	  major=.$func_arith_result
9223b41a30aaSmrg	  versuffix=$major.$age.$revision
9224ea133fd7Smrg	  ;;
9225ea133fd7Smrg
9226ea133fd7Smrg	osf)
9227ea133fd7Smrg	  func_arith $current - $age
9228ea133fd7Smrg	  major=.$func_arith_result
9229b41a30aaSmrg	  versuffix=.$current.$age.$revision
9230b41a30aaSmrg	  verstring=$current.$age.$revision
9231ea133fd7Smrg
9232ea133fd7Smrg	  # Add in all the interfaces that we are compatible with.
9233ea133fd7Smrg	  loop=$age
9234b41a30aaSmrg	  while test 0 -ne "$loop"; do
9235ea133fd7Smrg	    func_arith $current - $loop
9236ea133fd7Smrg	    iface=$func_arith_result
9237ea133fd7Smrg	    func_arith $loop - 1
9238ea133fd7Smrg	    loop=$func_arith_result
9239b41a30aaSmrg	    verstring=$verstring:$iface.0
9240ea133fd7Smrg	  done
9241ea133fd7Smrg
9242ea133fd7Smrg	  # Make executables depend on our current version.
9243b41a30aaSmrg	  func_append verstring ":$current.0"
9244ea133fd7Smrg	  ;;
9245ea133fd7Smrg
9246ea133fd7Smrg	qnx)
9247b41a30aaSmrg	  major=.$current
9248b41a30aaSmrg	  versuffix=.$current
9249b41a30aaSmrg	  ;;
9250b41a30aaSmrg
9251b41a30aaSmrg	sco)
9252b41a30aaSmrg	  major=.$current
9253b41a30aaSmrg	  versuffix=.$current
9254ea133fd7Smrg	  ;;
9255ea133fd7Smrg
9256ea133fd7Smrg	sunos)
9257b41a30aaSmrg	  major=.$current
9258b41a30aaSmrg	  versuffix=.$current.$revision
9259ea133fd7Smrg	  ;;
9260ea133fd7Smrg
9261ea133fd7Smrg	windows)
9262ea133fd7Smrg	  # Use '-' rather than '.', since we only want one
9263b41a30aaSmrg	  # extension on DOS 8.3 file systems.
9264ea133fd7Smrg	  func_arith $current - $age
9265ea133fd7Smrg	  major=$func_arith_result
9266b41a30aaSmrg	  versuffix=-$major
9267ea133fd7Smrg	  ;;
9268ea133fd7Smrg
9269ea133fd7Smrg	*)
9270b41a30aaSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
9271ea133fd7Smrg	  ;;
9272ea133fd7Smrg	esac
9273ea133fd7Smrg
9274ea133fd7Smrg	# Clear the version info if we defaulted, and they specified a release.
9275ea133fd7Smrg	if test -z "$vinfo" && test -n "$release"; then
9276ea133fd7Smrg	  major=
9277ea133fd7Smrg	  case $version_type in
9278ea133fd7Smrg	  darwin)
9279ea133fd7Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
9280ea133fd7Smrg	    # problems, so we reset it completely
9281ea133fd7Smrg	    verstring=
9282ea133fd7Smrg	    ;;
9283ea133fd7Smrg	  *)
9284b41a30aaSmrg	    verstring=0.0
9285ea133fd7Smrg	    ;;
9286ea133fd7Smrg	  esac
9287b41a30aaSmrg	  if test no = "$need_version"; then
9288ea133fd7Smrg	    versuffix=
9289ea133fd7Smrg	  else
9290b41a30aaSmrg	    versuffix=.0.0
9291ea133fd7Smrg	  fi
9292ea133fd7Smrg	fi
9293ea133fd7Smrg
9294ea133fd7Smrg	# Remove version info from name if versioning should be avoided
9295b41a30aaSmrg	if test yes,no = "$avoid_version,$need_version"; then
9296ea133fd7Smrg	  major=
9297ea133fd7Smrg	  versuffix=
9298b41a30aaSmrg	  verstring=
9299ea133fd7Smrg	fi
9300ea133fd7Smrg
9301ea133fd7Smrg	# Check to see if the archive will have undefined symbols.
9302b41a30aaSmrg	if test yes = "$allow_undefined"; then
9303b41a30aaSmrg	  if test unsupported = "$allow_undefined_flag"; then
9304b41a30aaSmrg	    if test yes = "$build_old_libs"; then
9305b41a30aaSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306b41a30aaSmrg	      build_libtool_libs=no
9307b41a30aaSmrg	    else
9308b41a30aaSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309b41a30aaSmrg	    fi
9310ea133fd7Smrg	  fi
9311ea133fd7Smrg	else
9312ea133fd7Smrg	  # Don't allow undefined symbols.
9313b41a30aaSmrg	  allow_undefined_flag=$no_undefined_flag
9314ea133fd7Smrg	fi
9315ea133fd7Smrg
9316ea133fd7Smrg      fi
9317ea133fd7Smrg
9318b41a30aaSmrg      func_generate_dlsyms "$libname" "$libname" :
931906f32fbeSmrg      func_append libobjs " $symfileobj"
9320b41a30aaSmrg      test " " = "$libobjs" && libobjs=
9321ea133fd7Smrg
9322b41a30aaSmrg      if test relink != "$opt_mode"; then
9323ea133fd7Smrg	# Remove our outputs, but don't remove object files since they
9324ea133fd7Smrg	# may have been created when compiling PIC objects.
9325ea133fd7Smrg	removelist=
9326ea133fd7Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9327ea133fd7Smrg	for p in $tempremovelist; do
9328ea133fd7Smrg	  case $p in
9329ea133fd7Smrg	    *.$objext | *.gcno)
9330ea133fd7Smrg	       ;;
9331b41a30aaSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332b41a30aaSmrg	       if test -n "$precious_files_regex"; then
9333ea133fd7Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9334ea133fd7Smrg		 then
9335ea133fd7Smrg		   continue
9336ea133fd7Smrg		 fi
9337ea133fd7Smrg	       fi
933806f32fbeSmrg	       func_append removelist " $p"
9339ea133fd7Smrg	       ;;
9340ea133fd7Smrg	    *) ;;
9341ea133fd7Smrg	  esac
9342ea133fd7Smrg	done
9343ea133fd7Smrg	test -n "$removelist" && \
9344ea133fd7Smrg	  func_show_eval "${RM}r \$removelist"
9345ea133fd7Smrg      fi
9346ea133fd7Smrg
9347ea133fd7Smrg      # Now set the variables for building old libraries.
9348b41a30aaSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
934906f32fbeSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
9350ea133fd7Smrg
9351ea133fd7Smrg	# Transform .lo files to .o files.
9352b41a30aaSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9353ea133fd7Smrg      fi
9354ea133fd7Smrg
9355ea133fd7Smrg      # Eliminate all temporary directories.
9356ea133fd7Smrg      #for path in $notinst_path; do
935725b89263Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
935825b89263Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
935925b89263Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9360ea133fd7Smrg      #done
9361ea133fd7Smrg
9362ea133fd7Smrg      if test -n "$xrpath"; then
9363ea133fd7Smrg	# If the user specified any rpath flags, then add them.
9364ea133fd7Smrg	temp_xrpath=
9365ea133fd7Smrg	for libdir in $xrpath; do
936606f32fbeSmrg	  func_replace_sysroot "$libdir"
936706f32fbeSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9368ea133fd7Smrg	  case "$finalize_rpath " in
9369ea133fd7Smrg	  *" $libdir "*) ;;
937006f32fbeSmrg	  *) func_append finalize_rpath " $libdir" ;;
9371ea133fd7Smrg	  esac
9372ea133fd7Smrg	done
9373b41a30aaSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9374ea133fd7Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9375ea133fd7Smrg	fi
9376ea133fd7Smrg      fi
9377ea133fd7Smrg
9378ea133fd7Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379b41a30aaSmrg      old_dlfiles=$dlfiles
9380ea133fd7Smrg      dlfiles=
9381ea133fd7Smrg      for lib in $old_dlfiles; do
9382ea133fd7Smrg	case " $dlprefiles $dlfiles " in
9383ea133fd7Smrg	*" $lib "*) ;;
938406f32fbeSmrg	*) func_append dlfiles " $lib" ;;
9385ea133fd7Smrg	esac
9386ea133fd7Smrg      done
9387ea133fd7Smrg
9388ea133fd7Smrg      # Make sure dlprefiles contains only unique files
9389b41a30aaSmrg      old_dlprefiles=$dlprefiles
9390ea133fd7Smrg      dlprefiles=
9391ea133fd7Smrg      for lib in $old_dlprefiles; do
9392ea133fd7Smrg	case "$dlprefiles " in
9393ea133fd7Smrg	*" $lib "*) ;;
939406f32fbeSmrg	*) func_append dlprefiles " $lib" ;;
9395ea133fd7Smrg	esac
9396ea133fd7Smrg      done
9397ea133fd7Smrg
9398b41a30aaSmrg      if test yes = "$build_libtool_libs"; then
9399ea133fd7Smrg	if test -n "$rpath"; then
9400ea133fd7Smrg	  case $host in
940125b89263Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9402ea133fd7Smrg	    # these systems don't actually have a c library (as such)!
9403ea133fd7Smrg	    ;;
9404ea133fd7Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9405ea133fd7Smrg	    # Rhapsody C library is in the System framework
940606f32fbeSmrg	    func_append deplibs " System.ltframework"
9407ea133fd7Smrg	    ;;
9408ea133fd7Smrg	  *-*-netbsd*)
9409ea133fd7Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9410ea133fd7Smrg	    ;;
9411b41a30aaSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9412ea133fd7Smrg	    # Do not include libc due to us having libc/libc_r.
9413ea133fd7Smrg	    ;;
9414ea133fd7Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9415ea133fd7Smrg	    # Causes problems with __ctype
9416ea133fd7Smrg	    ;;
9417ea133fd7Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9418ea133fd7Smrg	    # Compiler inserts libc in the correct place for threads to work
9419ea133fd7Smrg	    ;;
9420ea133fd7Smrg	  *)
9421ea133fd7Smrg	    # Add libc to deplibs on all other systems if necessary.
9422b41a30aaSmrg	    if test yes = "$build_libtool_need_lc"; then
942306f32fbeSmrg	      func_append deplibs " -lc"
9424ea133fd7Smrg	    fi
9425ea133fd7Smrg	    ;;
9426ea133fd7Smrg	  esac
9427ea133fd7Smrg	fi
9428ea133fd7Smrg
9429ea133fd7Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9430ea133fd7Smrg	name_save=$name
9431ea133fd7Smrg	libname_save=$libname
9432ea133fd7Smrg	release_save=$release
9433ea133fd7Smrg	versuffix_save=$versuffix
9434ea133fd7Smrg	major_save=$major
9435ea133fd7Smrg	# I'm not sure if I'm treating the release correctly.  I think
9436ea133fd7Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9437ea133fd7Smrg	# add it in twice.  Is that correct?
9438b41a30aaSmrg	release=
9439b41a30aaSmrg	versuffix=
9440b41a30aaSmrg	major=
9441ea133fd7Smrg	newdeplibs=
9442ea133fd7Smrg	droppeddeps=no
9443ea133fd7Smrg	case $deplibs_check_method in
9444ea133fd7Smrg	pass_all)
9445ea133fd7Smrg	  # Don't check for shared/static.  Everything works.
9446ea133fd7Smrg	  # This might be a little naive.  We might want to check
9447ea133fd7Smrg	  # whether the library exists or not.  But this is on
9448ea133fd7Smrg	  # osf3 & osf4 and I'm not really sure... Just
9449ea133fd7Smrg	  # implementing what was already the behavior.
9450ea133fd7Smrg	  newdeplibs=$deplibs
9451ea133fd7Smrg	  ;;
9452ea133fd7Smrg	test_compile)
9453ea133fd7Smrg	  # This code stresses the "libraries are programs" paradigm to its
9454ea133fd7Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9455ea133fd7Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9456ea133fd7Smrg	  # whether they linked in statically or dynamically with ldd.
9457ea133fd7Smrg	  $opt_dry_run || $RM conftest.c
9458ea133fd7Smrg	  cat > conftest.c <<EOF
9459ea133fd7Smrg	  int main() { return 0; }
9460ea133fd7SmrgEOF
9461ea133fd7Smrg	  $opt_dry_run || $RM conftest
9462ea133fd7Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9463ea133fd7Smrg	    ldd_output=`ldd conftest`
9464ea133fd7Smrg	    for i in $deplibs; do
9465ea133fd7Smrg	      case $i in
9466ea133fd7Smrg	      -l*)
9467ea133fd7Smrg		func_stripname -l '' "$i"
9468ea133fd7Smrg		name=$func_stripname_result
9469b41a30aaSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9470ea133fd7Smrg		  case " $predeps $postdeps " in
9471ea133fd7Smrg		  *" $i "*)
947206f32fbeSmrg		    func_append newdeplibs " $i"
9473b41a30aaSmrg		    i=
9474ea133fd7Smrg		    ;;
9475ea133fd7Smrg		  esac
9476ea133fd7Smrg		fi
9477b41a30aaSmrg		if test -n "$i"; then
9478ea133fd7Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9479ea133fd7Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9480ea133fd7Smrg		  set dummy $deplib_matches; shift
9481ea133fd7Smrg		  deplib_match=$1
9482b41a30aaSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
948306f32fbeSmrg		    func_append newdeplibs " $i"
9484ea133fd7Smrg		  else
9485ea133fd7Smrg		    droppeddeps=yes
948625b89263Smrg		    echo
9487ea133fd7Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
948825b89263Smrg		    echo "*** I have the capability to make that library automatically link in when"
948925b89263Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
949025b89263Smrg		    echo "*** shared version of the library, which I believe you do not have"
949125b89263Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
949225b89263Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9493ea133fd7Smrg		  fi
9494ea133fd7Smrg		fi
9495ea133fd7Smrg		;;
9496ea133fd7Smrg	      *)
949706f32fbeSmrg		func_append newdeplibs " $i"
9498ea133fd7Smrg		;;
9499ea133fd7Smrg	      esac
9500ea133fd7Smrg	    done
9501ea133fd7Smrg	  else
9502ea133fd7Smrg	    # Error occurred in the first compile.  Let's try to salvage
9503ea133fd7Smrg	    # the situation: Compile a separate program for each library.
9504ea133fd7Smrg	    for i in $deplibs; do
9505ea133fd7Smrg	      case $i in
9506ea133fd7Smrg	      -l*)
9507ea133fd7Smrg		func_stripname -l '' "$i"
9508ea133fd7Smrg		name=$func_stripname_result
9509ea133fd7Smrg		$opt_dry_run || $RM conftest
9510ea133fd7Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9511ea133fd7Smrg		  ldd_output=`ldd conftest`
9512b41a30aaSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9513ea133fd7Smrg		    case " $predeps $postdeps " in
9514ea133fd7Smrg		    *" $i "*)
951506f32fbeSmrg		      func_append newdeplibs " $i"
9516b41a30aaSmrg		      i=
9517ea133fd7Smrg		      ;;
9518ea133fd7Smrg		    esac
9519ea133fd7Smrg		  fi
9520b41a30aaSmrg		  if test -n "$i"; then
9521ea133fd7Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9522ea133fd7Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9523ea133fd7Smrg		    set dummy $deplib_matches; shift
9524ea133fd7Smrg		    deplib_match=$1
9525b41a30aaSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
952606f32fbeSmrg		      func_append newdeplibs " $i"
9527ea133fd7Smrg		    else
9528ea133fd7Smrg		      droppeddeps=yes
952925b89263Smrg		      echo
9530ea133fd7Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
953125b89263Smrg		      echo "*** I have the capability to make that library automatically link in when"
953225b89263Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
953325b89263Smrg		      echo "*** shared version of the library, which you do not appear to have"
953425b89263Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
953525b89263Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9536ea133fd7Smrg		    fi
9537ea133fd7Smrg		  fi
9538ea133fd7Smrg		else
9539ea133fd7Smrg		  droppeddeps=yes
954025b89263Smrg		  echo
9541ea133fd7Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
954225b89263Smrg		  echo "*** make it link in!  You will probably need to install it or some"
954325b89263Smrg		  echo "*** library that it depends on before this library will be fully"
954425b89263Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9545ea133fd7Smrg		fi
9546ea133fd7Smrg		;;
9547ea133fd7Smrg	      *)
954806f32fbeSmrg		func_append newdeplibs " $i"
9549ea133fd7Smrg		;;
9550ea133fd7Smrg	      esac
9551ea133fd7Smrg	    done
9552ea133fd7Smrg	  fi
9553ea133fd7Smrg	  ;;
9554ea133fd7Smrg	file_magic*)
9555ea133fd7Smrg	  set dummy $deplibs_check_method; shift
9556ea133fd7Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9557ea133fd7Smrg	  for a_deplib in $deplibs; do
9558ea133fd7Smrg	    case $a_deplib in
9559ea133fd7Smrg	    -l*)
9560ea133fd7Smrg	      func_stripname -l '' "$a_deplib"
9561ea133fd7Smrg	      name=$func_stripname_result
9562b41a30aaSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9563ea133fd7Smrg		case " $predeps $postdeps " in
9564ea133fd7Smrg		*" $a_deplib "*)
956506f32fbeSmrg		  func_append newdeplibs " $a_deplib"
9566b41a30aaSmrg		  a_deplib=
9567ea133fd7Smrg		  ;;
9568ea133fd7Smrg		esac
9569ea133fd7Smrg	      fi
9570b41a30aaSmrg	      if test -n "$a_deplib"; then
9571ea133fd7Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
957206f32fbeSmrg		if test -n "$file_magic_glob"; then
957306f32fbeSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
957406f32fbeSmrg		else
957506f32fbeSmrg		  libnameglob=$libname
957606f32fbeSmrg		fi
9577b41a30aaSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9578ea133fd7Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579b41a30aaSmrg		  if test yes = "$want_nocaseglob"; then
958006f32fbeSmrg		    shopt -s nocaseglob
958106f32fbeSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958206f32fbeSmrg		    $nocaseglob
958306f32fbeSmrg		  else
958406f32fbeSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
958506f32fbeSmrg		  fi
9586ea133fd7Smrg		  for potent_lib in $potential_libs; do
9587ea133fd7Smrg		      # Follow soft links.
9588ea133fd7Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9589ea133fd7Smrg			 $GREP " -> " >/dev/null; then
9590ea133fd7Smrg			continue
9591ea133fd7Smrg		      fi
9592ea133fd7Smrg		      # The statement above tries to avoid entering an
9593ea133fd7Smrg		      # endless loop below, in case of cyclic links.
9594ea133fd7Smrg		      # We might still enter an endless loop, since a link
9595ea133fd7Smrg		      # loop can be closed while we follow links,
9596ea133fd7Smrg		      # but so what?
9597b41a30aaSmrg		      potlib=$potent_lib
9598ea133fd7Smrg		      while test -h "$potlib" 2>/dev/null; do
9599b41a30aaSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9600ea133fd7Smrg			case $potliblink in
9601b41a30aaSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602b41a30aaSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9603ea133fd7Smrg			esac
9604ea133fd7Smrg		      done
9605ea133fd7Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9606ea133fd7Smrg			 $SED -e 10q |
9607ea133fd7Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
960806f32fbeSmrg			func_append newdeplibs " $a_deplib"
9609b41a30aaSmrg			a_deplib=
9610ea133fd7Smrg			break 2
9611ea133fd7Smrg		      fi
9612ea133fd7Smrg		  done
9613ea133fd7Smrg		done
9614ea133fd7Smrg	      fi
9615b41a30aaSmrg	      if test -n "$a_deplib"; then
9616ea133fd7Smrg		droppeddeps=yes
961725b89263Smrg		echo
9618ea133fd7Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
961925b89263Smrg		echo "*** I have the capability to make that library automatically link in when"
962025b89263Smrg		echo "*** you link to this library.  But I can only do this if you have a"
962125b89263Smrg		echo "*** shared version of the library, which you do not appear to have"
962225b89263Smrg		echo "*** because I did check the linker path looking for a file starting"
9623b41a30aaSmrg		if test -z "$potlib"; then
9624ea133fd7Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9625ea133fd7Smrg		else
9626ea133fd7Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9627ea133fd7Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9628ea133fd7Smrg		fi
9629ea133fd7Smrg	      fi
9630ea133fd7Smrg	      ;;
9631ea133fd7Smrg	    *)
9632ea133fd7Smrg	      # Add a -L argument.
963306f32fbeSmrg	      func_append newdeplibs " $a_deplib"
9634ea133fd7Smrg	      ;;
9635ea133fd7Smrg	    esac
9636ea133fd7Smrg	  done # Gone through all deplibs.
9637ea133fd7Smrg	  ;;
9638ea133fd7Smrg	match_pattern*)
9639ea133fd7Smrg	  set dummy $deplibs_check_method; shift
9640ea133fd7Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9641ea133fd7Smrg	  for a_deplib in $deplibs; do
9642ea133fd7Smrg	    case $a_deplib in
9643ea133fd7Smrg	    -l*)
9644ea133fd7Smrg	      func_stripname -l '' "$a_deplib"
9645ea133fd7Smrg	      name=$func_stripname_result
9646b41a30aaSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9647ea133fd7Smrg		case " $predeps $postdeps " in
9648ea133fd7Smrg		*" $a_deplib "*)
964906f32fbeSmrg		  func_append newdeplibs " $a_deplib"
9650b41a30aaSmrg		  a_deplib=
9651ea133fd7Smrg		  ;;
9652ea133fd7Smrg		esac
9653ea133fd7Smrg	      fi
9654b41a30aaSmrg	      if test -n "$a_deplib"; then
9655ea133fd7Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9656ea133fd7Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9657ea133fd7Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9658ea133fd7Smrg		  for potent_lib in $potential_libs; do
9659b41a30aaSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
966025b89263Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9661ea133fd7Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
966206f32fbeSmrg		      func_append newdeplibs " $a_deplib"
9663b41a30aaSmrg		      a_deplib=
9664ea133fd7Smrg		      break 2
9665ea133fd7Smrg		    fi
9666ea133fd7Smrg		  done
9667ea133fd7Smrg		done
9668ea133fd7Smrg	      fi
9669b41a30aaSmrg	      if test -n "$a_deplib"; then
9670ea133fd7Smrg		droppeddeps=yes
967125b89263Smrg		echo
9672ea133fd7Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
967325b89263Smrg		echo "*** I have the capability to make that library automatically link in when"
967425b89263Smrg		echo "*** you link to this library.  But I can only do this if you have a"
967525b89263Smrg		echo "*** shared version of the library, which you do not appear to have"
967625b89263Smrg		echo "*** because I did check the linker path looking for a file starting"
9677b41a30aaSmrg		if test -z "$potlib"; then
9678ea133fd7Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9679ea133fd7Smrg		else
9680ea133fd7Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9681ea133fd7Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9682ea133fd7Smrg		fi
9683ea133fd7Smrg	      fi
9684ea133fd7Smrg	      ;;
9685ea133fd7Smrg	    *)
9686ea133fd7Smrg	      # Add a -L argument.
968706f32fbeSmrg	      func_append newdeplibs " $a_deplib"
9688ea133fd7Smrg	      ;;
9689ea133fd7Smrg	    esac
9690ea133fd7Smrg	  done # Gone through all deplibs.
9691ea133fd7Smrg	  ;;
9692ea133fd7Smrg	none | unknown | *)
9693b41a30aaSmrg	  newdeplibs=
969425b89263Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695b41a30aaSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696b41a30aaSmrg	    for i in $predeps $postdeps; do
9697ea133fd7Smrg	      # can't use Xsed below, because $i might contain '/'
9698b41a30aaSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9699ea133fd7Smrg	    done
9700ea133fd7Smrg	  fi
970125b89263Smrg	  case $tmp_deplibs in
970225b89263Smrg	  *[!\	\ ]*)
970325b89263Smrg	    echo
9704b41a30aaSmrg	    if test none = "$deplibs_check_method"; then
970525b89263Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9706ea133fd7Smrg	    else
970725b89263Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9708ea133fd7Smrg	    fi
970925b89263Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9710ea133fd7Smrg	    droppeddeps=yes
971125b89263Smrg	    ;;
971225b89263Smrg	  esac
9713ea133fd7Smrg	  ;;
9714ea133fd7Smrg	esac
9715ea133fd7Smrg	versuffix=$versuffix_save
9716ea133fd7Smrg	major=$major_save
9717ea133fd7Smrg	release=$release_save
9718ea133fd7Smrg	libname=$libname_save
9719ea133fd7Smrg	name=$name_save
9720ea133fd7Smrg
9721ea133fd7Smrg	case $host in
9722ea133fd7Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9723ea133fd7Smrg	  # On Rhapsody replace the C library with the System framework
972425b89263Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9725ea133fd7Smrg	  ;;
9726ea133fd7Smrg	esac
9727ea133fd7Smrg
9728b41a30aaSmrg	if test yes = "$droppeddeps"; then
9729b41a30aaSmrg	  if test yes = "$module"; then
973025b89263Smrg	    echo
973125b89263Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9732ea133fd7Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
973325b89263Smrg	    echo "*** a static module, that should work as long as the dlopening"
973425b89263Smrg	    echo "*** application is linked with the -dlopen flag."
9735ea133fd7Smrg	    if test -z "$global_symbol_pipe"; then
973625b89263Smrg	      echo
973725b89263Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738b41a30aaSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
973925b89263Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9740b41a30aaSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9741ea133fd7Smrg	    fi
9742b41a30aaSmrg	    if test no = "$build_old_libs"; then
9743b41a30aaSmrg	      oldlibs=$output_objdir/$libname.$libext
9744ea133fd7Smrg	      build_libtool_libs=module
9745ea133fd7Smrg	      build_old_libs=yes
9746ea133fd7Smrg	    else
9747ea133fd7Smrg	      build_libtool_libs=no
9748ea133fd7Smrg	    fi
9749ea133fd7Smrg	  else
975025b89263Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
975125b89263Smrg	    echo "*** automatically added whenever a program is linked with this library"
975225b89263Smrg	    echo "*** or is declared to -dlopen it."
9753ea133fd7Smrg
9754b41a30aaSmrg	    if test no = "$allow_undefined"; then
975525b89263Smrg	      echo
975625b89263Smrg	      echo "*** Since this library must not contain undefined symbols,"
975725b89263Smrg	      echo "*** because either the platform does not support them or"
975825b89263Smrg	      echo "*** it was explicitly requested with -no-undefined,"
975925b89263Smrg	      echo "*** libtool will only create a static version of it."
9760b41a30aaSmrg	      if test no = "$build_old_libs"; then
9761b41a30aaSmrg		oldlibs=$output_objdir/$libname.$libext
9762ea133fd7Smrg		build_libtool_libs=module
9763ea133fd7Smrg		build_old_libs=yes
9764ea133fd7Smrg	      else
9765ea133fd7Smrg		build_libtool_libs=no
9766ea133fd7Smrg	      fi
9767ea133fd7Smrg	    fi
9768ea133fd7Smrg	  fi
9769ea133fd7Smrg	fi
9770ea133fd7Smrg	# Done checking deplibs!
9771ea133fd7Smrg	deplibs=$newdeplibs
9772ea133fd7Smrg      fi
9773ea133fd7Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9774ea133fd7Smrg      case $host in
9775ea133fd7Smrg	*-*-darwin*)
977625b89263Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977725b89263Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
977825b89263Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9779ea133fd7Smrg	  ;;
9780ea133fd7Smrg      esac
9781ea133fd7Smrg
9782ea133fd7Smrg      # move library search paths that coincide with paths to not yet
9783ea133fd7Smrg      # installed libraries to the beginning of the library search list
9784ea133fd7Smrg      new_libs=
9785ea133fd7Smrg      for path in $notinst_path; do
9786ea133fd7Smrg	case " $new_libs " in
9787ea133fd7Smrg	*" -L$path/$objdir "*) ;;
9788ea133fd7Smrg	*)
9789ea133fd7Smrg	  case " $deplibs " in
9790ea133fd7Smrg	  *" -L$path/$objdir "*)
979106f32fbeSmrg	    func_append new_libs " -L$path/$objdir" ;;
9792ea133fd7Smrg	  esac
9793ea133fd7Smrg	  ;;
9794ea133fd7Smrg	esac
9795ea133fd7Smrg      done
9796ea133fd7Smrg      for deplib in $deplibs; do
9797ea133fd7Smrg	case $deplib in
9798ea133fd7Smrg	-L*)
9799ea133fd7Smrg	  case " $new_libs " in
9800ea133fd7Smrg	  *" $deplib "*) ;;
980106f32fbeSmrg	  *) func_append new_libs " $deplib" ;;
9802ea133fd7Smrg	  esac
9803ea133fd7Smrg	  ;;
980406f32fbeSmrg	*) func_append new_libs " $deplib" ;;
9805ea133fd7Smrg	esac
9806ea133fd7Smrg      done
9807b41a30aaSmrg      deplibs=$new_libs
9808ea133fd7Smrg
9809ea133fd7Smrg      # All the library-specific variables (install_libdir is set above).
9810ea133fd7Smrg      library_names=
9811ea133fd7Smrg      old_library=
9812ea133fd7Smrg      dlname=
9813ea133fd7Smrg
9814ea133fd7Smrg      # Test again, we may have decided not to build it any more
9815b41a30aaSmrg      if test yes = "$build_libtool_libs"; then
9816b41a30aaSmrg	# Remove $wl instances when linking with ld.
981757ee1794Smrg	# FIXME: should test the right _cmds variable.
981857ee1794Smrg	case $archive_cmds in
981957ee1794Smrg	  *\$LD\ *) wl= ;;
982057ee1794Smrg        esac
9821b41a30aaSmrg	if test yes = "$hardcode_into_libs"; then
9822ea133fd7Smrg	  # Hardcode the library paths
9823ea133fd7Smrg	  hardcode_libdirs=
9824ea133fd7Smrg	  dep_rpath=
9825b41a30aaSmrg	  rpath=$finalize_rpath
9826b41a30aaSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9827ea133fd7Smrg	  for libdir in $rpath; do
9828ea133fd7Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9829ea133fd7Smrg	      if test -n "$hardcode_libdir_separator"; then
983006f32fbeSmrg		func_replace_sysroot "$libdir"
983106f32fbeSmrg		libdir=$func_replace_sysroot_result
9832ea133fd7Smrg		if test -z "$hardcode_libdirs"; then
9833b41a30aaSmrg		  hardcode_libdirs=$libdir
9834ea133fd7Smrg		else
9835ea133fd7Smrg		  # Just accumulate the unique libdirs.
9836ea133fd7Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9837ea133fd7Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9838ea133fd7Smrg		    ;;
9839ea133fd7Smrg		  *)
984006f32fbeSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9841ea133fd7Smrg		    ;;
9842ea133fd7Smrg		  esac
9843ea133fd7Smrg		fi
9844ea133fd7Smrg	      else
9845ea133fd7Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
984606f32fbeSmrg		func_append dep_rpath " $flag"
9847ea133fd7Smrg	      fi
9848ea133fd7Smrg	    elif test -n "$runpath_var"; then
9849ea133fd7Smrg	      case "$perm_rpath " in
9850ea133fd7Smrg	      *" $libdir "*) ;;
985157ee1794Smrg	      *) func_append perm_rpath " $libdir" ;;
9852ea133fd7Smrg	      esac
9853ea133fd7Smrg	    fi
9854ea133fd7Smrg	  done
9855ea133fd7Smrg	  # Substitute the hardcoded libdirs into the rpath.
9856ea133fd7Smrg	  if test -n "$hardcode_libdir_separator" &&
9857ea133fd7Smrg	     test -n "$hardcode_libdirs"; then
9858b41a30aaSmrg	    libdir=$hardcode_libdirs
985957ee1794Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9860ea133fd7Smrg	  fi
9861ea133fd7Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9862ea133fd7Smrg	    # We should set the runpath_var.
9863ea133fd7Smrg	    rpath=
9864ea133fd7Smrg	    for dir in $perm_rpath; do
986506f32fbeSmrg	      func_append rpath "$dir:"
9866ea133fd7Smrg	    done
9867ea133fd7Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9868ea133fd7Smrg	  fi
9869ea133fd7Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9870ea133fd7Smrg	fi
9871a253d6aeSmrg
9872b41a30aaSmrg	shlibpath=$finalize_shlibpath
9873b41a30aaSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9874ea133fd7Smrg	if test -n "$shlibpath"; then
9875ea133fd7Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9876ea133fd7Smrg	fi
9877a253d6aeSmrg
9878ea133fd7Smrg	# Get the real and link names of the library.
9879ea133fd7Smrg	eval shared_ext=\"$shrext_cmds\"
9880ea133fd7Smrg	eval library_names=\"$library_names_spec\"
9881ea133fd7Smrg	set dummy $library_names
9882ea133fd7Smrg	shift
9883b41a30aaSmrg	realname=$1
9884ea133fd7Smrg	shift
9885a253d6aeSmrg
9886ea133fd7Smrg	if test -n "$soname_spec"; then
9887ea133fd7Smrg	  eval soname=\"$soname_spec\"
9888ea133fd7Smrg	else
9889b41a30aaSmrg	  soname=$realname
9890ea133fd7Smrg	fi
9891ea133fd7Smrg	if test -z "$dlname"; then
9892ea133fd7Smrg	  dlname=$soname
9893ea133fd7Smrg	fi
9894a253d6aeSmrg
9895b41a30aaSmrg	lib=$output_objdir/$realname
9896ea133fd7Smrg	linknames=
9897ea133fd7Smrg	for link
9898ea133fd7Smrg	do
989906f32fbeSmrg	  func_append linknames " $link"
9900ea133fd7Smrg	done
9901a253d6aeSmrg
9902ea133fd7Smrg	# Use standard objects if they are pic
990325b89263Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9904ea133fd7Smrg	test "X$libobjs" = "X " && libobjs=
9905a253d6aeSmrg
9906ea133fd7Smrg	delfiles=
9907ea133fd7Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9908ea133fd7Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909b41a30aaSmrg	  export_symbols=$output_objdir/$libname.uexp
991006f32fbeSmrg	  func_append delfiles " $export_symbols"
9911ea133fd7Smrg	fi
9912a253d6aeSmrg
9913ea133fd7Smrg	orig_export_symbols=
9914ea133fd7Smrg	case $host_os in
9915ea133fd7Smrg	cygwin* | mingw* | cegcc*)
9916ea133fd7Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9917ea133fd7Smrg	    # exporting using user supplied symfile
9918b41a30aaSmrg	    func_dll_def_p "$export_symbols" || {
9919ea133fd7Smrg	      # and it's NOT already a .def file. Must figure out
9920ea133fd7Smrg	      # which of the given symbols are data symbols and tag
9921ea133fd7Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9922ea133fd7Smrg	      # export_symbols gets reassigned inside the "prepare
9923ea133fd7Smrg	      # the list of exported symbols" if statement, so the
9924ea133fd7Smrg	      # include_expsyms logic still works.
9925b41a30aaSmrg	      orig_export_symbols=$export_symbols
9926ea133fd7Smrg	      export_symbols=
9927ea133fd7Smrg	      always_export_symbols=yes
9928b41a30aaSmrg	    }
9929ea133fd7Smrg	  fi
9930ea133fd7Smrg	  ;;
9931ea133fd7Smrg	esac
9932a253d6aeSmrg
9933ea133fd7Smrg	# Prepare the list of exported symbols
9934ea133fd7Smrg	if test -z "$export_symbols"; then
9935b41a30aaSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936b41a30aaSmrg	    func_verbose "generating symbol list for '$libname.la'"
9937b41a30aaSmrg	    export_symbols=$output_objdir/$libname.exp
9938ea133fd7Smrg	    $opt_dry_run || $RM $export_symbols
9939ea133fd7Smrg	    cmds=$export_symbols_cmds
9940b41a30aaSmrg	    save_ifs=$IFS; IFS='~'
994106f32fbeSmrg	    for cmd1 in $cmds; do
9942b41a30aaSmrg	      IFS=$save_ifs
994306f32fbeSmrg	      # Take the normal branch if the nm_file_list_spec branch
994406f32fbeSmrg	      # doesn't work or if tool conversion is not needed.
994506f32fbeSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
994606f32fbeSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
994706f32fbeSmrg		  try_normal_branch=yes
994806f32fbeSmrg		  eval cmd=\"$cmd1\"
994906f32fbeSmrg		  func_len " $cmd"
995006f32fbeSmrg		  len=$func_len_result
995106f32fbeSmrg		  ;;
995206f32fbeSmrg		*)
995306f32fbeSmrg		  try_normal_branch=no
995406f32fbeSmrg		  ;;
995506f32fbeSmrg	      esac
9956b41a30aaSmrg	      if test yes = "$try_normal_branch" \
995706f32fbeSmrg		 && { test "$len" -lt "$max_cmd_len" \
995806f32fbeSmrg		      || test "$max_cmd_len" -le -1; }
995906f32fbeSmrg	      then
996006f32fbeSmrg		func_show_eval "$cmd" 'exit $?'
996106f32fbeSmrg		skipped_export=false
996206f32fbeSmrg	      elif test -n "$nm_file_list_spec"; then
996306f32fbeSmrg		func_basename "$output"
996406f32fbeSmrg		output_la=$func_basename_result
996506f32fbeSmrg		save_libobjs=$libobjs
996606f32fbeSmrg		save_output=$output
9967b41a30aaSmrg		output=$output_objdir/$output_la.nm
996806f32fbeSmrg		func_to_tool_file "$output"
996906f32fbeSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
997006f32fbeSmrg		func_append delfiles " $output"
997106f32fbeSmrg		func_verbose "creating $NM input file list: $output"
997206f32fbeSmrg		for obj in $save_libobjs; do
997306f32fbeSmrg		  func_to_tool_file "$obj"
997406f32fbeSmrg		  $ECHO "$func_to_tool_file_result"
997506f32fbeSmrg		done > "$output"
997606f32fbeSmrg		eval cmd=\"$cmd1\"
9977ea133fd7Smrg		func_show_eval "$cmd" 'exit $?'
997806f32fbeSmrg		output=$save_output
997906f32fbeSmrg		libobjs=$save_libobjs
9980ea133fd7Smrg		skipped_export=false
9981ea133fd7Smrg	      else
9982ea133fd7Smrg		# The command line is too long to execute in one step.
9983ea133fd7Smrg		func_verbose "using reloadable object file for export list..."
9984ea133fd7Smrg		skipped_export=:
9985ea133fd7Smrg		# Break out early, otherwise skipped_export may be
9986ea133fd7Smrg		# set to false by a later but shorter cmd.
9987ea133fd7Smrg		break
9988ea133fd7Smrg	      fi
9989ea133fd7Smrg	    done
9990b41a30aaSmrg	    IFS=$save_ifs
9991b41a30aaSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9992ea133fd7Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9993ea133fd7Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9994ea133fd7Smrg	    fi
9995ea133fd7Smrg	  fi
9996ea133fd7Smrg	fi
9997a253d6aeSmrg
9998ea133fd7Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999b41a30aaSmrg	  tmp_export_symbols=$export_symbols
10000b41a30aaSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1000125b89263Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002ea133fd7Smrg	fi
10003a253d6aeSmrg
10004b41a30aaSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10005ea133fd7Smrg	  # The given exports_symbols file has to be filtered, so filter it.
10006b41a30aaSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10007ea133fd7Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008b41a30aaSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10009ea133fd7Smrg	  # though. Also, the filter scales superlinearly with the number of
10010ea133fd7Smrg	  # global variables. join(1) would be nice here, but unfortunately
10011ea133fd7Smrg	  # isn't a blessed tool.
10012ea133fd7Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1001306f32fbeSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10014ea133fd7Smrg	  export_symbols=$output_objdir/$libname.def
10015ea133fd7Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016a253d6aeSmrg	fi
10017a253d6aeSmrg
10018ea133fd7Smrg	tmp_deplibs=
10019ea133fd7Smrg	for test_deplib in $deplibs; do
10020ea133fd7Smrg	  case " $convenience " in
10021ea133fd7Smrg	  *" $test_deplib "*) ;;
10022ea133fd7Smrg	  *)
1002306f32fbeSmrg	    func_append tmp_deplibs " $test_deplib"
10024ea133fd7Smrg	    ;;
10025ea133fd7Smrg	  esac
10026ea133fd7Smrg	done
10027b41a30aaSmrg	deplibs=$tmp_deplibs
10028a253d6aeSmrg
10029ea133fd7Smrg	if test -n "$convenience"; then
10030ea133fd7Smrg	  if test -n "$whole_archive_flag_spec" &&
10031b41a30aaSmrg	    test yes = "$compiler_needs_object" &&
10032ea133fd7Smrg	    test -z "$libobjs"; then
10033ea133fd7Smrg	    # extract the archives, so we have objects to list.
10034ea133fd7Smrg	    # TODO: could optimize this to just extract one archive.
10035ea133fd7Smrg	    whole_archive_flag_spec=
10036ea133fd7Smrg	  fi
10037ea133fd7Smrg	  if test -n "$whole_archive_flag_spec"; then
10038ea133fd7Smrg	    save_libobjs=$libobjs
10039ea133fd7Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10040ea133fd7Smrg	    test "X$libobjs" = "X " && libobjs=
10041ea133fd7Smrg	  else
10042b41a30aaSmrg	    gentop=$output_objdir/${outputname}x
1004306f32fbeSmrg	    func_append generated " $gentop"
10044a253d6aeSmrg
10045ea133fd7Smrg	    func_extract_archives $gentop $convenience
1004606f32fbeSmrg	    func_append libobjs " $func_extract_archives_result"
10047ea133fd7Smrg	    test "X$libobjs" = "X " && libobjs=
10048ea133fd7Smrg	  fi
10049ea133fd7Smrg	fi
10050a253d6aeSmrg
10051b41a30aaSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10052ea133fd7Smrg	  eval flag=\"$thread_safe_flag_spec\"
1005306f32fbeSmrg	  func_append linker_flags " $flag"
10054ea133fd7Smrg	fi
10055a253d6aeSmrg
10056ea133fd7Smrg	# Make a backup of the uninstalled library when relinking
10057b41a30aaSmrg	if test relink = "$opt_mode"; then
10058ea133fd7Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059a253d6aeSmrg	fi
10060a253d6aeSmrg
10061ea133fd7Smrg	# Do each of the archive commands.
10062b41a30aaSmrg	if test yes = "$module" && test -n "$module_cmds"; then
10063ea133fd7Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10064ea133fd7Smrg	    eval test_cmds=\"$module_expsym_cmds\"
10065ea133fd7Smrg	    cmds=$module_expsym_cmds
10066ea133fd7Smrg	  else
10067ea133fd7Smrg	    eval test_cmds=\"$module_cmds\"
10068ea133fd7Smrg	    cmds=$module_cmds
10069ea133fd7Smrg	  fi
10070ea133fd7Smrg	else
10071ea133fd7Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10072ea133fd7Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
10073ea133fd7Smrg	    cmds=$archive_expsym_cmds
10074ea133fd7Smrg	  else
10075ea133fd7Smrg	    eval test_cmds=\"$archive_cmds\"
10076ea133fd7Smrg	    cmds=$archive_cmds
10077ea133fd7Smrg	  fi
10078a253d6aeSmrg	fi
10079a253d6aeSmrg
10080b41a30aaSmrg	if test : != "$skipped_export" &&
10081ea133fd7Smrg	   func_len " $test_cmds" &&
10082ea133fd7Smrg	   len=$func_len_result &&
10083ea133fd7Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10084ea133fd7Smrg	  :
10085ea133fd7Smrg	else
10086ea133fd7Smrg	  # The command line is too long to link in one step, link piecewise
10087ea133fd7Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10088ea133fd7Smrg	  # script.
10089a253d6aeSmrg
10090ea133fd7Smrg	  # Save the value of $output and $libobjs because we want to
10091ea133fd7Smrg	  # use them later.  If we have whole_archive_flag_spec, we
10092ea133fd7Smrg	  # want to use save_libobjs as it was before
10093ea133fd7Smrg	  # whole_archive_flag_spec was expanded, because we can't
10094ea133fd7Smrg	  # assume the linker understands whole_archive_flag_spec.
10095ea133fd7Smrg	  # This may have to be revisited, in case too many
10096ea133fd7Smrg	  # convenience libraries get linked in and end up exceeding
10097ea133fd7Smrg	  # the spec.
10098ea133fd7Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10099ea133fd7Smrg	    save_libobjs=$libobjs
10100ea133fd7Smrg	  fi
10101ea133fd7Smrg	  save_output=$output
1010225b89263Smrg	  func_basename "$output"
1010325b89263Smrg	  output_la=$func_basename_result
10104a253d6aeSmrg
10105ea133fd7Smrg	  # Clear the reloadable object creation command queue and
10106ea133fd7Smrg	  # initialize k to one.
10107ea133fd7Smrg	  test_cmds=
10108ea133fd7Smrg	  concat_cmds=
10109ea133fd7Smrg	  objlist=
10110ea133fd7Smrg	  last_robj=
10111ea133fd7Smrg	  k=1
10112a253d6aeSmrg
10113b41a30aaSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114b41a30aaSmrg	    output=$output_objdir/$output_la.lnkscript
10115ea133fd7Smrg	    func_verbose "creating GNU ld script: $output"
1011625b89263Smrg	    echo 'INPUT (' > $output
10117ea133fd7Smrg	    for obj in $save_libobjs
10118ea133fd7Smrg	    do
1011906f32fbeSmrg	      func_to_tool_file "$obj"
1012006f32fbeSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10121ea133fd7Smrg	    done
1012225b89263Smrg	    echo ')' >> $output
1012306f32fbeSmrg	    func_append delfiles " $output"
1012406f32fbeSmrg	    func_to_tool_file "$output"
1012506f32fbeSmrg	    output=$func_to_tool_file_result
10126b41a30aaSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127b41a30aaSmrg	    output=$output_objdir/$output_la.lnk
10128ea133fd7Smrg	    func_verbose "creating linker input file list: $output"
10129ea133fd7Smrg	    : > $output
10130ea133fd7Smrg	    set x $save_libobjs
10131ea133fd7Smrg	    shift
10132ea133fd7Smrg	    firstobj=
10133b41a30aaSmrg	    if test yes = "$compiler_needs_object"; then
10134ea133fd7Smrg	      firstobj="$1 "
10135ea133fd7Smrg	      shift
10136ea133fd7Smrg	    fi
10137ea133fd7Smrg	    for obj
10138ea133fd7Smrg	    do
1013906f32fbeSmrg	      func_to_tool_file "$obj"
1014006f32fbeSmrg	      $ECHO "$func_to_tool_file_result" >> $output
10141ea133fd7Smrg	    done
1014206f32fbeSmrg	    func_append delfiles " $output"
1014306f32fbeSmrg	    func_to_tool_file "$output"
1014406f32fbeSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10145ea133fd7Smrg	  else
10146ea133fd7Smrg	    if test -n "$save_libobjs"; then
10147ea133fd7Smrg	      func_verbose "creating reloadable object files..."
10148b41a30aaSmrg	      output=$output_objdir/$output_la-$k.$objext
10149ea133fd7Smrg	      eval test_cmds=\"$reload_cmds\"
10150ea133fd7Smrg	      func_len " $test_cmds"
10151ea133fd7Smrg	      len0=$func_len_result
10152ea133fd7Smrg	      len=$len0
10153ea133fd7Smrg
10154ea133fd7Smrg	      # Loop over the list of objects to be linked.
10155ea133fd7Smrg	      for obj in $save_libobjs
10156ea133fd7Smrg	      do
10157ea133fd7Smrg		func_len " $obj"
10158ea133fd7Smrg		func_arith $len + $func_len_result
10159ea133fd7Smrg		len=$func_arith_result
10160b41a30aaSmrg		if test -z "$objlist" ||
10161ea133fd7Smrg		   test "$len" -lt "$max_cmd_len"; then
10162ea133fd7Smrg		  func_append objlist " $obj"
10163ea133fd7Smrg		else
10164ea133fd7Smrg		  # The command $test_cmds is almost too long, add a
10165ea133fd7Smrg		  # command to the queue.
10166b41a30aaSmrg		  if test 1 -eq "$k"; then
10167ea133fd7Smrg		    # The first file doesn't have a previous command to add.
1016825b89263Smrg		    reload_objs=$objlist
1016925b89263Smrg		    eval concat_cmds=\"$reload_cmds\"
10170ea133fd7Smrg		  else
10171ea133fd7Smrg		    # All subsequent reloadable object files will link in
10172ea133fd7Smrg		    # the last one created.
1017325b89263Smrg		    reload_objs="$objlist $last_robj"
1017425b89263Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10175ea133fd7Smrg		  fi
10176b41a30aaSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
10177ea133fd7Smrg		  func_arith $k + 1
10178ea133fd7Smrg		  k=$func_arith_result
10179b41a30aaSmrg		  output=$output_objdir/$output_la-$k.$objext
1018025b89263Smrg		  objlist=" $obj"
10181ea133fd7Smrg		  func_len " $last_robj"
10182ea133fd7Smrg		  func_arith $len0 + $func_len_result
10183ea133fd7Smrg		  len=$func_arith_result
10184ea133fd7Smrg		fi
10185ea133fd7Smrg	      done
10186ea133fd7Smrg	      # Handle the remaining objects by creating one last
10187ea133fd7Smrg	      # reloadable object file.  All subsequent reloadable object
10188ea133fd7Smrg	      # files will link in the last one created.
10189ea133fd7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
1019025b89263Smrg	      reload_objs="$objlist $last_robj"
10191b41a30aaSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10192ea133fd7Smrg	      if test -n "$last_robj"; then
10193b41a30aaSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194ea133fd7Smrg	      fi
1019506f32fbeSmrg	      func_append delfiles " $output"
10196a253d6aeSmrg
10197ea133fd7Smrg	    else
10198ea133fd7Smrg	      output=
10199ea133fd7Smrg	    fi
10200a253d6aeSmrg
10201b41a30aaSmrg	    ${skipped_export-false} && {
10202b41a30aaSmrg	      func_verbose "generating symbol list for '$libname.la'"
10203b41a30aaSmrg	      export_symbols=$output_objdir/$libname.exp
10204ea133fd7Smrg	      $opt_dry_run || $RM $export_symbols
10205ea133fd7Smrg	      libobjs=$output
10206ea133fd7Smrg	      # Append the command to create the export file.
10207ea133fd7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10208ea133fd7Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10209ea133fd7Smrg	      if test -n "$last_robj"; then
10210ea133fd7Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10211ea133fd7Smrg	      fi
10212b41a30aaSmrg	    }
10213a253d6aeSmrg
10214ea133fd7Smrg	    test -n "$save_libobjs" &&
10215ea133fd7Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216a253d6aeSmrg
10217ea133fd7Smrg	    # Loop through the commands generated above and execute them.
10218b41a30aaSmrg	    save_ifs=$IFS; IFS='~'
10219ea133fd7Smrg	    for cmd in $concat_cmds; do
10220b41a30aaSmrg	      IFS=$save_ifs
10221b41a30aaSmrg	      $opt_quiet || {
10222b41a30aaSmrg		  func_quote_arg expand,pretty "$cmd"
10223b41a30aaSmrg		  eval "func_echo $func_quote_arg_result"
10224ea133fd7Smrg	      }
10225ea133fd7Smrg	      $opt_dry_run || eval "$cmd" || {
10226ea133fd7Smrg		lt_exit=$?
10227ea133fd7Smrg
10228ea133fd7Smrg		# Restore the uninstalled library and exit
10229b41a30aaSmrg		if test relink = "$opt_mode"; then
10230ea133fd7Smrg		  ( cd "$output_objdir" && \
10231ea133fd7Smrg		    $RM "${realname}T" && \
10232ea133fd7Smrg		    $MV "${realname}U" "$realname" )
10233ea133fd7Smrg		fi
10234a253d6aeSmrg
10235ea133fd7Smrg		exit $lt_exit
10236ea133fd7Smrg	      }
10237ea133fd7Smrg	    done
10238b41a30aaSmrg	    IFS=$save_ifs
10239ea133fd7Smrg
10240ea133fd7Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10241ea133fd7Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10242ea133fd7Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243a253d6aeSmrg	    fi
10244a253d6aeSmrg	  fi
10245a253d6aeSmrg
10246b41a30aaSmrg          ${skipped_export-false} && {
10247ea133fd7Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248b41a30aaSmrg	      tmp_export_symbols=$export_symbols
10249b41a30aaSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
1025025b89263Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10251ea133fd7Smrg	    fi
10252a253d6aeSmrg
10253ea133fd7Smrg	    if test -n "$orig_export_symbols"; then
10254ea133fd7Smrg	      # The given exports_symbols file has to be filtered, so filter it.
10255b41a30aaSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10256ea133fd7Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257b41a30aaSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10258ea133fd7Smrg	      # though. Also, the filter scales superlinearly with the number of
10259ea133fd7Smrg	      # global variables. join(1) would be nice here, but unfortunately
10260ea133fd7Smrg	      # isn't a blessed tool.
10261ea133fd7Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
1026206f32fbeSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10263ea133fd7Smrg	      export_symbols=$output_objdir/$libname.def
10264ea133fd7Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10265ea133fd7Smrg	    fi
10266b41a30aaSmrg	  }
10267a253d6aeSmrg
10268ea133fd7Smrg	  libobjs=$output
10269ea133fd7Smrg	  # Restore the value of output.
10270ea133fd7Smrg	  output=$save_output
10271a253d6aeSmrg
10272ea133fd7Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10273ea133fd7Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10274ea133fd7Smrg	    test "X$libobjs" = "X " && libobjs=
10275ea133fd7Smrg	  fi
10276ea133fd7Smrg	  # Expand the library linking commands again to reset the
10277ea133fd7Smrg	  # value of $libobjs for piecewise linking.
10278ea133fd7Smrg
10279ea133fd7Smrg	  # Do each of the archive commands.
10280b41a30aaSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
10281ea133fd7Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10282ea133fd7Smrg	      cmds=$module_expsym_cmds
10283a253d6aeSmrg	    else
10284ea133fd7Smrg	      cmds=$module_cmds
10285a253d6aeSmrg	    fi
10286a253d6aeSmrg	  else
10287ea133fd7Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10288ea133fd7Smrg	      cmds=$archive_expsym_cmds
10289ea133fd7Smrg	    else
10290ea133fd7Smrg	      cmds=$archive_cmds
10291ea133fd7Smrg	    fi
10292a253d6aeSmrg	  fi
10293a253d6aeSmrg	fi
10294a253d6aeSmrg
10295ea133fd7Smrg	if test -n "$delfiles"; then
10296ea133fd7Smrg	  # Append the command to remove temporary files to $cmds.
10297ea133fd7Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10298ea133fd7Smrg	fi
10299a253d6aeSmrg
10300ea133fd7Smrg	# Add any objects from preloaded convenience libraries
10301ea133fd7Smrg	if test -n "$dlprefiles"; then
10302b41a30aaSmrg	  gentop=$output_objdir/${outputname}x
1030306f32fbeSmrg	  func_append generated " $gentop"
10304a253d6aeSmrg
10305ea133fd7Smrg	  func_extract_archives $gentop $dlprefiles
1030606f32fbeSmrg	  func_append libobjs " $func_extract_archives_result"
10307ea133fd7Smrg	  test "X$libobjs" = "X " && libobjs=
10308a253d6aeSmrg	fi
10309a253d6aeSmrg
10310b41a30aaSmrg	save_ifs=$IFS; IFS='~'
10311ea133fd7Smrg	for cmd in $cmds; do
10312b41a30aaSmrg	  IFS=$sp$nl
10313ea133fd7Smrg	  eval cmd=\"$cmd\"
10314b41a30aaSmrg	  IFS=$save_ifs
10315b41a30aaSmrg	  $opt_quiet || {
10316b41a30aaSmrg	    func_quote_arg expand,pretty "$cmd"
10317b41a30aaSmrg	    eval "func_echo $func_quote_arg_result"
10318ea133fd7Smrg	  }
10319ea133fd7Smrg	  $opt_dry_run || eval "$cmd" || {
10320ea133fd7Smrg	    lt_exit=$?
10321a253d6aeSmrg
10322ea133fd7Smrg	    # Restore the uninstalled library and exit
10323b41a30aaSmrg	    if test relink = "$opt_mode"; then
10324ea133fd7Smrg	      ( cd "$output_objdir" && \
10325ea133fd7Smrg	        $RM "${realname}T" && \
10326ea133fd7Smrg		$MV "${realname}U" "$realname" )
10327ea133fd7Smrg	    fi
10328ea133fd7Smrg
10329ea133fd7Smrg	    exit $lt_exit
10330ea133fd7Smrg	  }
10331ea133fd7Smrg	done
10332b41a30aaSmrg	IFS=$save_ifs
10333ea133fd7Smrg
10334ea133fd7Smrg	# Restore the uninstalled library and exit
10335b41a30aaSmrg	if test relink = "$opt_mode"; then
10336ea133fd7Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337ea133fd7Smrg
10338ea133fd7Smrg	  if test -n "$convenience"; then
10339ea133fd7Smrg	    if test -z "$whole_archive_flag_spec"; then
10340ea133fd7Smrg	      func_show_eval '${RM}r "$gentop"'
10341a253d6aeSmrg	    fi
10342a253d6aeSmrg	  fi
10343a253d6aeSmrg
10344ea133fd7Smrg	  exit $EXIT_SUCCESS
10345ea133fd7Smrg	fi
10346a253d6aeSmrg
10347ea133fd7Smrg	# Create links to the real library.
10348ea133fd7Smrg	for linkname in $linknames; do
10349ea133fd7Smrg	  if test "$realname" != "$linkname"; then
10350ea133fd7Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351ea133fd7Smrg	  fi
10352ea133fd7Smrg	done
10353ea133fd7Smrg
10354ea133fd7Smrg	# If -module or -export-dynamic was specified, set the dlname.
10355b41a30aaSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10356ea133fd7Smrg	  # On all known operating systems, these are identical.
10357b41a30aaSmrg	  dlname=$soname
10358ea133fd7Smrg	fi
10359ea133fd7Smrg      fi
10360ea133fd7Smrg      ;;
10361ea133fd7Smrg
10362ea133fd7Smrg    obj)
10363b41a30aaSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364b41a30aaSmrg	func_warning "'-dlopen' is ignored for objects"
10365ea133fd7Smrg      fi
10366ea133fd7Smrg
10367ea133fd7Smrg      case " $deplibs" in
10368ea133fd7Smrg      *\ -l* | *\ -L*)
10369b41a30aaSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10370ea133fd7Smrg      esac
10371ea133fd7Smrg
10372ea133fd7Smrg      test -n "$rpath" && \
10373b41a30aaSmrg	func_warning "'-rpath' is ignored for objects"
10374ea133fd7Smrg
10375ea133fd7Smrg      test -n "$xrpath" && \
10376b41a30aaSmrg	func_warning "'-R' is ignored for objects"
10377ea133fd7Smrg
10378ea133fd7Smrg      test -n "$vinfo" && \
10379b41a30aaSmrg	func_warning "'-version-info' is ignored for objects"
10380ea133fd7Smrg
10381ea133fd7Smrg      test -n "$release" && \
10382b41a30aaSmrg	func_warning "'-release' is ignored for objects"
10383ea133fd7Smrg
10384ea133fd7Smrg      case $output in
10385ea133fd7Smrg      *.lo)
10386ea133fd7Smrg	test -n "$objs$old_deplibs" && \
10387b41a30aaSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10388ea133fd7Smrg
10389ea133fd7Smrg	libobj=$output
10390ea133fd7Smrg	func_lo2o "$libobj"
10391ea133fd7Smrg	obj=$func_lo2o_result
10392ea133fd7Smrg	;;
10393ea133fd7Smrg      *)
10394ea133fd7Smrg	libobj=
10395b41a30aaSmrg	obj=$output
10396ea133fd7Smrg	;;
10397ea133fd7Smrg      esac
10398ea133fd7Smrg
10399ea133fd7Smrg      # Delete the old objects.
10400ea133fd7Smrg      $opt_dry_run || $RM $obj $libobj
10401ea133fd7Smrg
10402ea133fd7Smrg      # Objects from convenience libraries.  This assumes
10403ea133fd7Smrg      # single-version convenience libraries.  Whenever we create
10404ea133fd7Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10405ea133fd7Smrg      # the extraction.
10406ea133fd7Smrg      reload_conv_objs=
10407ea133fd7Smrg      gentop=
10408b41a30aaSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409b41a30aaSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410b41a30aaSmrg      # into space.
10411b41a30aaSmrg      case $reload_cmds in
10412b41a30aaSmrg        *\$LD[\ \$]*) wl= ;;
10413b41a30aaSmrg      esac
10414ea133fd7Smrg      if test -n "$convenience"; then
10415ea133fd7Smrg	if test -n "$whole_archive_flag_spec"; then
10416ea133fd7Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417b41a30aaSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418b41a30aaSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419ea133fd7Smrg	else
10420b41a30aaSmrg	  gentop=$output_objdir/${obj}x
1042106f32fbeSmrg	  func_append generated " $gentop"
10422ea133fd7Smrg
10423ea133fd7Smrg	  func_extract_archives $gentop $convenience
10424ea133fd7Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425ea133fd7Smrg	fi
10426ea133fd7Smrg      fi
10427a253d6aeSmrg
1042806f32fbeSmrg      # If we're not building shared, we need to use non_pic_objs
10429b41a30aaSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
1043006f32fbeSmrg
10431ea133fd7Smrg      # Create the old-style object.
10432b41a30aaSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433a253d6aeSmrg
10434b41a30aaSmrg      output=$obj
10435ea133fd7Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436a253d6aeSmrg
10437ea133fd7Smrg      # Exit if we aren't doing a library object file.
10438ea133fd7Smrg      if test -z "$libobj"; then
10439ea133fd7Smrg	if test -n "$gentop"; then
10440ea133fd7Smrg	  func_show_eval '${RM}r "$gentop"'
10441ea133fd7Smrg	fi
10442a253d6aeSmrg
10443ea133fd7Smrg	exit $EXIT_SUCCESS
10444ea133fd7Smrg      fi
10445a253d6aeSmrg
10446b41a30aaSmrg      test yes = "$build_libtool_libs" || {
10447ea133fd7Smrg	if test -n "$gentop"; then
10448ea133fd7Smrg	  func_show_eval '${RM}r "$gentop"'
10449ea133fd7Smrg	fi
10450a253d6aeSmrg
10451ea133fd7Smrg	# Create an invalid libtool object if no PIC, so that we don't
10452ea133fd7Smrg	# accidentally link it into a program.
10453ea133fd7Smrg	# $show "echo timestamp > $libobj"
10454ea133fd7Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10455ea133fd7Smrg	exit $EXIT_SUCCESS
10456b41a30aaSmrg      }
10457a253d6aeSmrg
10458b41a30aaSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10459ea133fd7Smrg	# Only do commands if we really have different PIC objects.
10460ea133fd7Smrg	reload_objs="$libobjs $reload_conv_objs"
10461b41a30aaSmrg	output=$libobj
10462ea133fd7Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463a253d6aeSmrg      fi
10464a253d6aeSmrg
10465ea133fd7Smrg      if test -n "$gentop"; then
10466ea133fd7Smrg	func_show_eval '${RM}r "$gentop"'
10467ea133fd7Smrg      fi
10468a253d6aeSmrg
10469ea133fd7Smrg      exit $EXIT_SUCCESS
10470ea133fd7Smrg      ;;
10471a253d6aeSmrg
10472ea133fd7Smrg    prog)
10473ea133fd7Smrg      case $host in
10474ea133fd7Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10475ea133fd7Smrg	          output=$func_stripname_result.exe;;
10476a253d6aeSmrg      esac
10477ea133fd7Smrg      test -n "$vinfo" && \
10478b41a30aaSmrg	func_warning "'-version-info' is ignored for programs"
10479a253d6aeSmrg
10480ea133fd7Smrg      test -n "$release" && \
10481b41a30aaSmrg	func_warning "'-release' is ignored for programs"
10482a253d6aeSmrg
10483b41a30aaSmrg      $preload \
10484b41a30aaSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485b41a30aaSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10486a253d6aeSmrg
10487ea133fd7Smrg      case $host in
10488ea133fd7Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10489ea133fd7Smrg	# On Rhapsody replace the C library is the System framework
1049025b89263Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
1049125b89263Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492a253d6aeSmrg	;;
10493a253d6aeSmrg      esac
10494a253d6aeSmrg
10495ea133fd7Smrg      case $host in
10496ea133fd7Smrg      *-*-darwin*)
10497ea133fd7Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10498ea133fd7Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10499b41a30aaSmrg	if test CXX = "$tagname"; then
10500ea133fd7Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10501ea133fd7Smrg	    10.[0123])
10502b41a30aaSmrg	      func_append compile_command " $wl-bind_at_load"
10503b41a30aaSmrg	      func_append finalize_command " $wl-bind_at_load"
10504ea133fd7Smrg	    ;;
10505ea133fd7Smrg	  esac
10506ea133fd7Smrg	fi
10507ea133fd7Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
1050825b89263Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1050925b89263Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10510a253d6aeSmrg	;;
10511a253d6aeSmrg      esac
10512a253d6aeSmrg
10513a253d6aeSmrg
10514ea133fd7Smrg      # move library search paths that coincide with paths to not yet
10515ea133fd7Smrg      # installed libraries to the beginning of the library search list
10516ea133fd7Smrg      new_libs=
10517ea133fd7Smrg      for path in $notinst_path; do
10518ea133fd7Smrg	case " $new_libs " in
10519ea133fd7Smrg	*" -L$path/$objdir "*) ;;
10520a253d6aeSmrg	*)
10521ea133fd7Smrg	  case " $compile_deplibs " in
10522ea133fd7Smrg	  *" -L$path/$objdir "*)
1052306f32fbeSmrg	    func_append new_libs " -L$path/$objdir" ;;
10524ea133fd7Smrg	  esac
10525a253d6aeSmrg	  ;;
10526a253d6aeSmrg	esac
10527a253d6aeSmrg      done
10528ea133fd7Smrg      for deplib in $compile_deplibs; do
10529ea133fd7Smrg	case $deplib in
10530ea133fd7Smrg	-L*)
10531ea133fd7Smrg	  case " $new_libs " in
10532ea133fd7Smrg	  *" $deplib "*) ;;
1053306f32fbeSmrg	  *) func_append new_libs " $deplib" ;;
10534ea133fd7Smrg	  esac
10535ea133fd7Smrg	  ;;
1053606f32fbeSmrg	*) func_append new_libs " $deplib" ;;
10537ea133fd7Smrg	esac
10538ea133fd7Smrg      done
10539b41a30aaSmrg      compile_deplibs=$new_libs
10540a253d6aeSmrg
10541a253d6aeSmrg
1054206f32fbeSmrg      func_append compile_command " $compile_deplibs"
1054306f32fbeSmrg      func_append finalize_command " $finalize_deplibs"
10544a253d6aeSmrg
10545ea133fd7Smrg      if test -n "$rpath$xrpath"; then
10546ea133fd7Smrg	# If the user specified any rpath flags, then add them.
10547ea133fd7Smrg	for libdir in $rpath $xrpath; do
10548ea133fd7Smrg	  # This is the magic to use -rpath.
10549ea133fd7Smrg	  case "$finalize_rpath " in
10550ea133fd7Smrg	  *" $libdir "*) ;;
1055106f32fbeSmrg	  *) func_append finalize_rpath " $libdir" ;;
10552ea133fd7Smrg	  esac
10553ea133fd7Smrg	done
10554ea133fd7Smrg      fi
10555a253d6aeSmrg
10556ea133fd7Smrg      # Now hardcode the library paths
10557ea133fd7Smrg      rpath=
10558ea133fd7Smrg      hardcode_libdirs=
10559ea133fd7Smrg      for libdir in $compile_rpath $finalize_rpath; do
10560ea133fd7Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10561ea133fd7Smrg	  if test -n "$hardcode_libdir_separator"; then
10562ea133fd7Smrg	    if test -z "$hardcode_libdirs"; then
10563b41a30aaSmrg	      hardcode_libdirs=$libdir
10564ea133fd7Smrg	    else
10565ea133fd7Smrg	      # Just accumulate the unique libdirs.
10566ea133fd7Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10567ea133fd7Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10568ea133fd7Smrg		;;
10569ea133fd7Smrg	      *)
1057006f32fbeSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10571ea133fd7Smrg		;;
10572ea133fd7Smrg	      esac
10573ea133fd7Smrg	    fi
10574ea133fd7Smrg	  else
10575ea133fd7Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1057606f32fbeSmrg	    func_append rpath " $flag"
10577ea133fd7Smrg	  fi
10578ea133fd7Smrg	elif test -n "$runpath_var"; then
10579ea133fd7Smrg	  case "$perm_rpath " in
10580a253d6aeSmrg	  *" $libdir "*) ;;
1058106f32fbeSmrg	  *) func_append perm_rpath " $libdir" ;;
10582a253d6aeSmrg	  esac
10583ea133fd7Smrg	fi
10584ea133fd7Smrg	case $host in
10585ea133fd7Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586b41a30aaSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10587ea133fd7Smrg	  case :$dllsearchpath: in
10588ea133fd7Smrg	  *":$libdir:"*) ;;
10589ea133fd7Smrg	  ::) dllsearchpath=$libdir;;
1059006f32fbeSmrg	  *) func_append dllsearchpath ":$libdir";;
10591ea133fd7Smrg	  esac
10592ea133fd7Smrg	  case :$dllsearchpath: in
10593ea133fd7Smrg	  *":$testbindir:"*) ;;
10594ea133fd7Smrg	  ::) dllsearchpath=$testbindir;;
1059506f32fbeSmrg	  *) func_append dllsearchpath ":$testbindir";;
10596ea133fd7Smrg	  esac
10597ea133fd7Smrg	  ;;
10598ea133fd7Smrg	esac
10599ea133fd7Smrg      done
10600ea133fd7Smrg      # Substitute the hardcoded libdirs into the rpath.
10601ea133fd7Smrg      if test -n "$hardcode_libdir_separator" &&
10602ea133fd7Smrg	 test -n "$hardcode_libdirs"; then
10603b41a30aaSmrg	libdir=$hardcode_libdirs
10604ea133fd7Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10605ea133fd7Smrg      fi
10606b41a30aaSmrg      compile_rpath=$rpath
10607ea133fd7Smrg
10608ea133fd7Smrg      rpath=
10609ea133fd7Smrg      hardcode_libdirs=
10610ea133fd7Smrg      for libdir in $finalize_rpath; do
10611ea133fd7Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10612ea133fd7Smrg	  if test -n "$hardcode_libdir_separator"; then
10613ea133fd7Smrg	    if test -z "$hardcode_libdirs"; then
10614b41a30aaSmrg	      hardcode_libdirs=$libdir
10615ea133fd7Smrg	    else
10616ea133fd7Smrg	      # Just accumulate the unique libdirs.
10617ea133fd7Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10618ea133fd7Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10619ea133fd7Smrg		;;
10620ea133fd7Smrg	      *)
1062106f32fbeSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10622ea133fd7Smrg		;;
10623ea133fd7Smrg	      esac
10624ea133fd7Smrg	    fi
10625ea133fd7Smrg	  else
10626ea133fd7Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
1062706f32fbeSmrg	    func_append rpath " $flag"
10628ea133fd7Smrg	  fi
10629ea133fd7Smrg	elif test -n "$runpath_var"; then
10630ea133fd7Smrg	  case "$finalize_perm_rpath " in
10631a253d6aeSmrg	  *" $libdir "*) ;;
1063206f32fbeSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10633a253d6aeSmrg	  esac
10634a253d6aeSmrg	fi
10635ea133fd7Smrg      done
10636ea133fd7Smrg      # Substitute the hardcoded libdirs into the rpath.
10637ea133fd7Smrg      if test -n "$hardcode_libdir_separator" &&
10638ea133fd7Smrg	 test -n "$hardcode_libdirs"; then
10639b41a30aaSmrg	libdir=$hardcode_libdirs
10640ea133fd7Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10641ea133fd7Smrg      fi
10642b41a30aaSmrg      finalize_rpath=$rpath
10643a253d6aeSmrg
10644b41a30aaSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10645ea133fd7Smrg	# Transform all the library objects into standard objects.
1064625b89263Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1064725b89263Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10648ea133fd7Smrg      fi
10649a253d6aeSmrg
10650b41a30aaSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651a253d6aeSmrg
10652ea133fd7Smrg      # template prelinking step
10653ea133fd7Smrg      if test -n "$prelink_cmds"; then
10654ea133fd7Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10655ea133fd7Smrg      fi
10656a253d6aeSmrg
10657b41a30aaSmrg      wrappers_required=:
10658ea133fd7Smrg      case $host in
1065925b89263Smrg      *cegcc* | *mingw32ce*)
1066025b89263Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661b41a30aaSmrg        wrappers_required=false
1066225b89263Smrg        ;;
10663ea133fd7Smrg      *cygwin* | *mingw* )
10664b41a30aaSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10665ea133fd7Smrg        ;;
10666ea133fd7Smrg      *)
10667b41a30aaSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668b41a30aaSmrg          wrappers_required=false
10669ea133fd7Smrg        fi
10670ea133fd7Smrg        ;;
10671ea133fd7Smrg      esac
10672b41a30aaSmrg      $wrappers_required || {
10673ea133fd7Smrg	# Replace the output file specification.
1067425b89263Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675b41a30aaSmrg	link_command=$compile_command$compile_rpath
10676a253d6aeSmrg
10677ea133fd7Smrg	# We have no uninstalled library dependencies, so finalize right now.
10678ea133fd7Smrg	exit_status=0
10679ea133fd7Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680a253d6aeSmrg
1068106f32fbeSmrg	if test -n "$postlink_cmds"; then
1068206f32fbeSmrg	  func_to_tool_file "$output"
1068306f32fbeSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1068406f32fbeSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1068506f32fbeSmrg	fi
1068606f32fbeSmrg
10687ea133fd7Smrg	# Delete the generated files.
10688b41a30aaSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689b41a30aaSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690ea133fd7Smrg	fi
10691a253d6aeSmrg
10692ea133fd7Smrg	exit $exit_status
10693b41a30aaSmrg      }
10694a253d6aeSmrg
10695ea133fd7Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10696ea133fd7Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10697ea133fd7Smrg      fi
10698ea133fd7Smrg      if test -n "$finalize_shlibpath"; then
10699ea133fd7Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10700ea133fd7Smrg      fi
10701a253d6aeSmrg
10702ea133fd7Smrg      compile_var=
10703ea133fd7Smrg      finalize_var=
10704ea133fd7Smrg      if test -n "$runpath_var"; then
10705ea133fd7Smrg	if test -n "$perm_rpath"; then
10706ea133fd7Smrg	  # We should set the runpath_var.
10707ea133fd7Smrg	  rpath=
10708ea133fd7Smrg	  for dir in $perm_rpath; do
1070906f32fbeSmrg	    func_append rpath "$dir:"
10710a253d6aeSmrg	  done
10711ea133fd7Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712a253d6aeSmrg	fi
10713ea133fd7Smrg	if test -n "$finalize_perm_rpath"; then
10714ea133fd7Smrg	  # We should set the runpath_var.
10715ea133fd7Smrg	  rpath=
10716ea133fd7Smrg	  for dir in $finalize_perm_rpath; do
1071706f32fbeSmrg	    func_append rpath "$dir:"
10718ea133fd7Smrg	  done
10719ea133fd7Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720ea133fd7Smrg	fi
10721ea133fd7Smrg      fi
10722a253d6aeSmrg
10723b41a30aaSmrg      if test yes = "$no_install"; then
10724ea133fd7Smrg	# We don't need to create a wrapper script.
10725b41a30aaSmrg	link_command=$compile_var$compile_command$compile_rpath
10726ea133fd7Smrg	# Replace the output file specification.
1072725b89263Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10728ea133fd7Smrg	# Delete the old output file.
10729ea133fd7Smrg	$opt_dry_run || $RM $output
10730ea133fd7Smrg	# Link the executable and exit
10731ea133fd7Smrg	func_show_eval "$link_command" 'exit $?'
1073206f32fbeSmrg
1073306f32fbeSmrg	if test -n "$postlink_cmds"; then
1073406f32fbeSmrg	  func_to_tool_file "$output"
1073506f32fbeSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
1073606f32fbeSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
1073706f32fbeSmrg	fi
1073806f32fbeSmrg
10739ea133fd7Smrg	exit $EXIT_SUCCESS
10740ea133fd7Smrg      fi
10741a253d6aeSmrg
10742b41a30aaSmrg      case $hardcode_action,$fast_install in
10743b41a30aaSmrg        relink,*)
10744b41a30aaSmrg	  # Fast installation is not supported
10745b41a30aaSmrg	  link_command=$compile_var$compile_command$compile_rpath
10746b41a30aaSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10747a253d6aeSmrg
10748b41a30aaSmrg	  func_warning "this platform does not like uninstalled shared libraries"
10749b41a30aaSmrg	  func_warning "'$output' will be relinked during installation"
10750b41a30aaSmrg	  ;;
10751b41a30aaSmrg        *,yes)
10752b41a30aaSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753b41a30aaSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754b41a30aaSmrg          ;;
10755b41a30aaSmrg	*,no)
10756b41a30aaSmrg	  link_command=$compile_var$compile_command$compile_rpath
10757b41a30aaSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758b41a30aaSmrg          ;;
10759b41a30aaSmrg	*,needless)
10760b41a30aaSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761b41a30aaSmrg	  relink_command=
10762b41a30aaSmrg          ;;
10763b41a30aaSmrg      esac
10764a253d6aeSmrg
10765ea133fd7Smrg      # Replace the output file specification.
1076625b89263Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767a253d6aeSmrg
10768ea133fd7Smrg      # Delete the old output files.
10769ea133fd7Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770a253d6aeSmrg
10771ea133fd7Smrg      func_show_eval "$link_command" 'exit $?'
10772a253d6aeSmrg
1077306f32fbeSmrg      if test -n "$postlink_cmds"; then
1077406f32fbeSmrg	func_to_tool_file "$output_objdir/$outputname"
1077506f32fbeSmrg	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'`
1077606f32fbeSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
1077706f32fbeSmrg      fi
1077806f32fbeSmrg
10779ea133fd7Smrg      # Now create the wrapper script.
10780ea133fd7Smrg      func_verbose "creating $output"
10781a253d6aeSmrg
10782ea133fd7Smrg      # Quote the relink command for shipping.
10783ea133fd7Smrg      if test -n "$relink_command"; then
10784ea133fd7Smrg	# Preserve any variables that may affect compiler behavior
10785ea133fd7Smrg	for var in $variables_saved_for_relink; do
10786ea133fd7Smrg	  if eval test -z \"\${$var+set}\"; then
10787ea133fd7Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10788ea133fd7Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10789ea133fd7Smrg	    relink_command="$var=; export $var; $relink_command"
10790ea133fd7Smrg	  else
10791b41a30aaSmrg	    func_quote_arg pretty "$var_value"
10792b41a30aaSmrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793ea133fd7Smrg	  fi
10794ea133fd7Smrg	done
10795b41a30aaSmrg	func_quote eval cd "`pwd`"
10796b41a30aaSmrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797b41a30aaSmrg	relink_command=$func_quote_arg_unquoted_result
10798ea133fd7Smrg      fi
10799a253d6aeSmrg
10800ea133fd7Smrg      # Only actually do things if not in dry run mode.
10801ea133fd7Smrg      $opt_dry_run || {
10802ea133fd7Smrg	# win32 will think the script is a binary if it has
10803ea133fd7Smrg	# a .exe suffix, so we strip it off here.
10804ea133fd7Smrg	case $output in
10805ea133fd7Smrg	  *.exe) func_stripname '' '.exe' "$output"
10806ea133fd7Smrg	         output=$func_stripname_result ;;
10807ea133fd7Smrg	esac
10808ea133fd7Smrg	# test for cygwin because mv fails w/o .exe extensions
10809a253d6aeSmrg	case $host in
10810ea133fd7Smrg	  *cygwin*)
10811ea133fd7Smrg	    exeext=.exe
10812ea133fd7Smrg	    func_stripname '' '.exe' "$outputname"
10813ea133fd7Smrg	    outputname=$func_stripname_result ;;
10814ea133fd7Smrg	  *) exeext= ;;
10815a253d6aeSmrg	esac
10816ea133fd7Smrg	case $host in
10817ea133fd7Smrg	  *cygwin* | *mingw* )
10818ea133fd7Smrg	    func_dirname_and_basename "$output" "" "."
10819ea133fd7Smrg	    output_name=$func_basename_result
10820ea133fd7Smrg	    output_path=$func_dirname_result
10821b41a30aaSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822b41a30aaSmrg	    cwrapper=$output_path/$output_name.exe
10823ea133fd7Smrg	    $RM $cwrappersource $cwrapper
10824ea133fd7Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10825ea133fd7Smrg
10826ea133fd7Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10827ea133fd7Smrg
10828ea133fd7Smrg	    # The wrapper executable is built using the $host compiler,
10829ea133fd7Smrg	    # because it contains $host paths and files. If cross-
10830ea133fd7Smrg	    # compiling, it, like the target executable, must be
10831ea133fd7Smrg	    # executed on the $host or under an emulation environment.
10832ea133fd7Smrg	    $opt_dry_run || {
10833ea133fd7Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10834ea133fd7Smrg	      $STRIP $cwrapper
10835ea133fd7Smrg	    }
10836a253d6aeSmrg
10837ea133fd7Smrg	    # Now, create the wrapper script for func_source use:
10838ea133fd7Smrg	    func_ltwrapper_scriptname $cwrapper
10839ea133fd7Smrg	    $RM $func_ltwrapper_scriptname_result
10840ea133fd7Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10841ea133fd7Smrg	    $opt_dry_run || {
10842ea133fd7Smrg	      # note: this script will not be executed, so do not chmod.
10843b41a30aaSmrg	      if test "x$build" = "x$host"; then
10844ea133fd7Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10845a253d6aeSmrg	      else
10846ea133fd7Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10847a253d6aeSmrg	      fi
10848ea133fd7Smrg	    }
10849ea133fd7Smrg	  ;;
10850ea133fd7Smrg	  * )
10851ea133fd7Smrg	    $RM $output
10852ea133fd7Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853a253d6aeSmrg
10854ea133fd7Smrg	    func_emit_wrapper no > $output
10855ea133fd7Smrg	    chmod +x $output
10856a253d6aeSmrg	  ;;
10857a253d6aeSmrg	esac
10858ea133fd7Smrg      }
10859ea133fd7Smrg      exit $EXIT_SUCCESS
10860ea133fd7Smrg      ;;
10861ea133fd7Smrg    esac
10862a253d6aeSmrg
10863ea133fd7Smrg    # See if we need to build an old-fashioned archive.
10864ea133fd7Smrg    for oldlib in $oldlibs; do
10865a253d6aeSmrg
10866b41a30aaSmrg      case $build_libtool_libs in
10867b41a30aaSmrg        convenience)
10868b41a30aaSmrg	  oldobjs="$libobjs_save $symfileobj"
10869b41a30aaSmrg	  addlibs=$convenience
10870ea133fd7Smrg	  build_libtool_libs=no
10871b41a30aaSmrg	  ;;
10872b41a30aaSmrg	module)
10873b41a30aaSmrg	  oldobjs=$libobjs_save
10874b41a30aaSmrg	  addlibs=$old_convenience
10875b41a30aaSmrg	  build_libtool_libs=no
10876b41a30aaSmrg          ;;
10877b41a30aaSmrg	*)
10878ea133fd7Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10879b41a30aaSmrg	  $preload && test -f "$symfileobj" \
10880b41a30aaSmrg	    && func_append oldobjs " $symfileobj"
10881b41a30aaSmrg	  addlibs=$old_convenience
10882b41a30aaSmrg	  ;;
10883b41a30aaSmrg      esac
10884a253d6aeSmrg
10885ea133fd7Smrg      if test -n "$addlibs"; then
10886b41a30aaSmrg	gentop=$output_objdir/${outputname}x
1088706f32fbeSmrg	func_append generated " $gentop"
10888a253d6aeSmrg
10889ea133fd7Smrg	func_extract_archives $gentop $addlibs
1089006f32fbeSmrg	func_append oldobjs " $func_extract_archives_result"
10891ea133fd7Smrg      fi
10892a253d6aeSmrg
10893ea133fd7Smrg      # Do each command in the archive commands.
10894b41a30aaSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10895ea133fd7Smrg	cmds=$old_archive_from_new_cmds
10896ea133fd7Smrg      else
10897a253d6aeSmrg
10898ea133fd7Smrg	# Add any objects from preloaded convenience libraries
10899ea133fd7Smrg	if test -n "$dlprefiles"; then
10900b41a30aaSmrg	  gentop=$output_objdir/${outputname}x
1090106f32fbeSmrg	  func_append generated " $gentop"
10902a253d6aeSmrg
10903ea133fd7Smrg	  func_extract_archives $gentop $dlprefiles
1090406f32fbeSmrg	  func_append oldobjs " $func_extract_archives_result"
10905ea133fd7Smrg	fi
10906a253d6aeSmrg
10907ea133fd7Smrg	# POSIX demands no paths to be encoded in archives.  We have
10908ea133fd7Smrg	# to avoid creating archives with duplicate basenames if we
10909ea133fd7Smrg	# might have to extract them afterwards, e.g., when creating a
10910ea133fd7Smrg	# static archive out of a convenience library, or when linking
10911ea133fd7Smrg	# the entirety of a libtool archive into another (currently
10912ea133fd7Smrg	# not supported by libtool).
10913ea133fd7Smrg	if (for obj in $oldobjs
10914ea133fd7Smrg	    do
10915ea133fd7Smrg	      func_basename "$obj"
10916ea133fd7Smrg	      $ECHO "$func_basename_result"
10917ea133fd7Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10918ea133fd7Smrg	  :
10919ea133fd7Smrg	else
1092025b89263Smrg	  echo "copying selected object files to avoid basename conflicts..."
10921b41a30aaSmrg	  gentop=$output_objdir/${outputname}x
1092206f32fbeSmrg	  func_append generated " $gentop"
10923ea133fd7Smrg	  func_mkdir_p "$gentop"
10924ea133fd7Smrg	  save_oldobjs=$oldobjs
10925ea133fd7Smrg	  oldobjs=
10926ea133fd7Smrg	  counter=1
10927ea133fd7Smrg	  for obj in $save_oldobjs
10928ea133fd7Smrg	  do
10929ea133fd7Smrg	    func_basename "$obj"
10930b41a30aaSmrg	    objbase=$func_basename_result
10931ea133fd7Smrg	    case " $oldobjs " in
10932ea133fd7Smrg	    " ") oldobjs=$obj ;;
10933ea133fd7Smrg	    *[\ /]"$objbase "*)
10934ea133fd7Smrg	      while :; do
10935ea133fd7Smrg		# Make sure we don't pick an alternate name that also
10936ea133fd7Smrg		# overlaps.
10937ea133fd7Smrg		newobj=lt$counter-$objbase
10938ea133fd7Smrg		func_arith $counter + 1
10939ea133fd7Smrg		counter=$func_arith_result
10940ea133fd7Smrg		case " $oldobjs " in
10941ea133fd7Smrg		*[\ /]"$newobj "*) ;;
10942ea133fd7Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10943ea133fd7Smrg		esac
10944ea133fd7Smrg	      done
10945ea133fd7Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
1094606f32fbeSmrg	      func_append oldobjs " $gentop/$newobj"
10947ea133fd7Smrg	      ;;
1094806f32fbeSmrg	    *) func_append oldobjs " $obj" ;;
10949ea133fd7Smrg	    esac
10950a253d6aeSmrg	  done
10951a253d6aeSmrg	fi
1095257ee1794Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
1095357ee1794Smrg	tool_oldlib=$func_to_tool_file_result
10954ea133fd7Smrg	eval cmds=\"$old_archive_cmds\"
10955a253d6aeSmrg
10956ea133fd7Smrg	func_len " $cmds"
10957ea133fd7Smrg	len=$func_len_result
10958ea133fd7Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10959ea133fd7Smrg	  cmds=$old_archive_cmds
1096006f32fbeSmrg	elif test -n "$archiver_list_spec"; then
1096106f32fbeSmrg	  func_verbose "using command file archive linking..."
1096206f32fbeSmrg	  for obj in $oldobjs
1096306f32fbeSmrg	  do
1096406f32fbeSmrg	    func_to_tool_file "$obj"
1096506f32fbeSmrg	    $ECHO "$func_to_tool_file_result"
1096606f32fbeSmrg	  done > $output_objdir/$libname.libcmd
1096706f32fbeSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
1096806f32fbeSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
1096906f32fbeSmrg	  cmds=$old_archive_cmds
10970ea133fd7Smrg	else
10971ea133fd7Smrg	  # the command line is too long to link in one step, link in parts
10972ea133fd7Smrg	  func_verbose "using piecewise archive linking..."
10973ea133fd7Smrg	  save_RANLIB=$RANLIB
10974ea133fd7Smrg	  RANLIB=:
10975ea133fd7Smrg	  objlist=
10976ea133fd7Smrg	  concat_cmds=
10977ea133fd7Smrg	  save_oldobjs=$oldobjs
10978ea133fd7Smrg	  oldobjs=
10979ea133fd7Smrg	  # Is there a better way of finding the last object in the list?
10980ea133fd7Smrg	  for obj in $save_oldobjs
10981ea133fd7Smrg	  do
10982ea133fd7Smrg	    last_oldobj=$obj
10983ea133fd7Smrg	  done
10984ea133fd7Smrg	  eval test_cmds=\"$old_archive_cmds\"
10985ea133fd7Smrg	  func_len " $test_cmds"
10986ea133fd7Smrg	  len0=$func_len_result
10987ea133fd7Smrg	  len=$len0
10988ea133fd7Smrg	  for obj in $save_oldobjs
10989ea133fd7Smrg	  do
10990ea133fd7Smrg	    func_len " $obj"
10991ea133fd7Smrg	    func_arith $len + $func_len_result
10992ea133fd7Smrg	    len=$func_arith_result
10993ea133fd7Smrg	    func_append objlist " $obj"
10994ea133fd7Smrg	    if test "$len" -lt "$max_cmd_len"; then
10995ea133fd7Smrg	      :
10996ea133fd7Smrg	    else
10997ea133fd7Smrg	      # the above command should be used before it gets too long
10998ea133fd7Smrg	      oldobjs=$objlist
10999b41a30aaSmrg	      if test "$obj" = "$last_oldobj"; then
11000ea133fd7Smrg		RANLIB=$save_RANLIB
11001ea133fd7Smrg	      fi
11002ea133fd7Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003b41a30aaSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11004ea133fd7Smrg	      objlist=
11005ea133fd7Smrg	      len=$len0
11006ea133fd7Smrg	    fi
11007ea133fd7Smrg	  done
11008ea133fd7Smrg	  RANLIB=$save_RANLIB
11009ea133fd7Smrg	  oldobjs=$objlist
11010b41a30aaSmrg	  if test -z "$oldobjs"; then
11011ea133fd7Smrg	    eval cmds=\"\$concat_cmds\"
11012ea133fd7Smrg	  else
11013ea133fd7Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11014ea133fd7Smrg	  fi
11015ea133fd7Smrg	fi
11016ea133fd7Smrg      fi
11017ea133fd7Smrg      func_execute_cmds "$cmds" 'exit $?'
11018a253d6aeSmrg    done
11019a253d6aeSmrg
11020ea133fd7Smrg    test -n "$generated" && \
11021ea133fd7Smrg      func_show_eval "${RM}r$generated"
11022a253d6aeSmrg
11023ea133fd7Smrg    # Now create the libtool archive.
11024ea133fd7Smrg    case $output in
11025ea133fd7Smrg    *.la)
11026ea133fd7Smrg      old_library=
11027b41a30aaSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11028ea133fd7Smrg      func_verbose "creating $output"
11029a253d6aeSmrg
11030ea133fd7Smrg      # Preserve any variables that may affect compiler behavior
11031ea133fd7Smrg      for var in $variables_saved_for_relink; do
11032ea133fd7Smrg	if eval test -z \"\${$var+set}\"; then
11033ea133fd7Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11034ea133fd7Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
11035ea133fd7Smrg	  relink_command="$var=; export $var; $relink_command"
11036a253d6aeSmrg	else
11037b41a30aaSmrg	  func_quote_arg pretty,unquoted "$var_value"
11038b41a30aaSmrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039a253d6aeSmrg	fi
11040ea133fd7Smrg      done
11041ea133fd7Smrg      # Quote the link command for shipping.
11042b41a30aaSmrg      func_quote eval cd "`pwd`"
11043b41a30aaSmrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044b41a30aaSmrg      func_quote_arg pretty,unquoted "$relink_command"
11045b41a30aaSmrg      relink_command=$func_quote_arg_unquoted_result
11046b41a30aaSmrg      if test yes = "$hardcode_automatic"; then
11047ea133fd7Smrg	relink_command=
11048ea133fd7Smrg      fi
11049a253d6aeSmrg
11050ea133fd7Smrg      # Only create the output if not a dry run.
11051ea133fd7Smrg      $opt_dry_run || {
11052ea133fd7Smrg	for installed in no yes; do
11053b41a30aaSmrg	  if test yes = "$installed"; then
11054ea133fd7Smrg	    if test -z "$install_libdir"; then
11055ea133fd7Smrg	      break
11056ea133fd7Smrg	    fi
11057b41a30aaSmrg	    output=$output_objdir/${outputname}i
11058ea133fd7Smrg	    # Replace all uninstalled libtool libraries with the installed ones
11059ea133fd7Smrg	    newdependency_libs=
11060ea133fd7Smrg	    for deplib in $dependency_libs; do
11061ea133fd7Smrg	      case $deplib in
11062ea133fd7Smrg	      *.la)
11063ea133fd7Smrg		func_basename "$deplib"
11064b41a30aaSmrg		name=$func_basename_result
1106557ee1794Smrg		func_resolve_sysroot "$deplib"
11066b41a30aaSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11067ea133fd7Smrg		test -z "$libdir" && \
11068b41a30aaSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
1106906f32fbeSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
1107006f32fbeSmrg		;;
1107106f32fbeSmrg	      -L*)
1107206f32fbeSmrg		func_stripname -L '' "$deplib"
1107306f32fbeSmrg		func_replace_sysroot "$func_stripname_result"
1107406f32fbeSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
1107506f32fbeSmrg		;;
1107606f32fbeSmrg	      -R*)
1107706f32fbeSmrg		func_stripname -R '' "$deplib"
1107806f32fbeSmrg		func_replace_sysroot "$func_stripname_result"
1107906f32fbeSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080ea133fd7Smrg		;;
1108106f32fbeSmrg	      *) func_append newdependency_libs " $deplib" ;;
11082ea133fd7Smrg	      esac
11083ea133fd7Smrg	    done
11084b41a30aaSmrg	    dependency_libs=$newdependency_libs
11085ea133fd7Smrg	    newdlfiles=
11086ea133fd7Smrg
11087ea133fd7Smrg	    for lib in $dlfiles; do
11088ea133fd7Smrg	      case $lib in
11089ea133fd7Smrg	      *.la)
11090ea133fd7Smrg	        func_basename "$lib"
11091b41a30aaSmrg		name=$func_basename_result
11092b41a30aaSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11093ea133fd7Smrg		test -z "$libdir" && \
11094b41a30aaSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1109506f32fbeSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11096ea133fd7Smrg		;;
1109706f32fbeSmrg	      *) func_append newdlfiles " $lib" ;;
11098ea133fd7Smrg	      esac
11099ea133fd7Smrg	    done
11100b41a30aaSmrg	    dlfiles=$newdlfiles
11101ea133fd7Smrg	    newdlprefiles=
11102ea133fd7Smrg	    for lib in $dlprefiles; do
11103ea133fd7Smrg	      case $lib in
11104ea133fd7Smrg	      *.la)
11105ea133fd7Smrg		# Only pass preopened files to the pseudo-archive (for
11106ea133fd7Smrg		# eventual linking with the app. that links it) if we
11107ea133fd7Smrg		# didn't already link the preopened objects directly into
11108ea133fd7Smrg		# the library:
11109ea133fd7Smrg		func_basename "$lib"
11110b41a30aaSmrg		name=$func_basename_result
11111b41a30aaSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11112ea133fd7Smrg		test -z "$libdir" && \
11113b41a30aaSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
1111406f32fbeSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11115ea133fd7Smrg		;;
11116ea133fd7Smrg	      esac
11117ea133fd7Smrg	    done
11118b41a30aaSmrg	    dlprefiles=$newdlprefiles
11119ea133fd7Smrg	  else
11120ea133fd7Smrg	    newdlfiles=
11121ea133fd7Smrg	    for lib in $dlfiles; do
11122ea133fd7Smrg	      case $lib in
11123b41a30aaSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11124ea133fd7Smrg		*) abs=`pwd`"/$lib" ;;
11125ea133fd7Smrg	      esac
1112606f32fbeSmrg	      func_append newdlfiles " $abs"
11127ea133fd7Smrg	    done
11128b41a30aaSmrg	    dlfiles=$newdlfiles
11129ea133fd7Smrg	    newdlprefiles=
11130ea133fd7Smrg	    for lib in $dlprefiles; do
11131ea133fd7Smrg	      case $lib in
11132b41a30aaSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11133ea133fd7Smrg		*) abs=`pwd`"/$lib" ;;
11134ea133fd7Smrg	      esac
1113506f32fbeSmrg	      func_append newdlprefiles " $abs"
11136ea133fd7Smrg	    done
11137b41a30aaSmrg	    dlprefiles=$newdlprefiles
11138ea133fd7Smrg	  fi
11139ea133fd7Smrg	  $RM $output
11140ea133fd7Smrg	  # place dlname in correct position for cygwin
1114125b89263Smrg	  # In fact, it would be nice if we could use this code for all target
1114225b89263Smrg	  # systems that can't hard-code library paths into their executables
1114325b89263Smrg	  # and that have no shared library path variable independent of PATH,
1114425b89263Smrg	  # but it turns out we can't easily determine that from inspecting
1114525b89263Smrg	  # libtool variables, so we have to hard-code the OSs to which it
1114625b89263Smrg	  # applies here; at the moment, that means platforms that use the PE
1114725b89263Smrg	  # object format with DLL files.  See the long comment at the top of
1114825b89263Smrg	  # tests/bindir.at for full details.
11149ea133fd7Smrg	  tdlname=$dlname
11150ea133fd7Smrg	  case $host,$output,$installed,$module,$dlname in
1115125b89263Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
1115225b89263Smrg	      # If a -bindir argument was supplied, place the dll there.
11153b41a30aaSmrg	      if test -n "$bindir"; then
1115425b89263Smrg		func_relative_path "$install_libdir" "$bindir"
11155b41a30aaSmrg		tdlname=$func_relative_path_result/$dlname
1115625b89263Smrg	      else
1115725b89263Smrg		# Otherwise fall back on heuristic.
1115825b89263Smrg		tdlname=../bin/$dlname
1115925b89263Smrg	      fi
1116025b89263Smrg	      ;;
11161ea133fd7Smrg	  esac
11162ea133fd7Smrg	  $ECHO > $output "\
11163ea133fd7Smrg# $outputname - a libtool library file
11164b41a30aaSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11165ea133fd7Smrg#
11166ea133fd7Smrg# Please DO NOT delete this file!
11167ea133fd7Smrg# It is necessary for linking the library.
11168a253d6aeSmrg
11169ea133fd7Smrg# The name that we can dlopen(3).
11170ea133fd7Smrgdlname='$tdlname'
11171a253d6aeSmrg
11172ea133fd7Smrg# Names of this library.
11173ea133fd7Smrglibrary_names='$library_names'
11174a253d6aeSmrg
11175ea133fd7Smrg# The name of the static archive.
11176ea133fd7Smrgold_library='$old_library'
11177a253d6aeSmrg
11178b41a30aaSmrg# Linker flags that cannot go in dependency_libs.
11179ea133fd7Smrginherited_linker_flags='$new_inherited_linker_flags'
11180a253d6aeSmrg
11181ea133fd7Smrg# Libraries that this one depends upon.
11182ea133fd7Smrgdependency_libs='$dependency_libs'
11183a253d6aeSmrg
11184ea133fd7Smrg# Names of additional weak libraries provided by this library
11185ea133fd7Smrgweak_library_names='$weak_libs'
11186a253d6aeSmrg
11187ea133fd7Smrg# Version information for $libname.
11188ea133fd7Smrgcurrent=$current
11189ea133fd7Smrgage=$age
11190ea133fd7Smrgrevision=$revision
11191a253d6aeSmrg
11192ea133fd7Smrg# Is this an already installed library?
11193ea133fd7Smrginstalled=$installed
11194a253d6aeSmrg
11195ea133fd7Smrg# Should we warn about portability when linking against -modules?
11196ea133fd7Smrgshouldnotlink=$module
11197a253d6aeSmrg
11198ea133fd7Smrg# Files to dlopen/dlpreopen
11199ea133fd7Smrgdlopen='$dlfiles'
11200ea133fd7Smrgdlpreopen='$dlprefiles'
11201a253d6aeSmrg
11202ea133fd7Smrg# Directory that this library needs to be installed in:
11203ea133fd7Smrglibdir='$install_libdir'"
11204b41a30aaSmrg	  if test no,yes = "$installed,$need_relink"; then
11205ea133fd7Smrg	    $ECHO >> $output "\
11206ea133fd7Smrgrelink_command=\"$relink_command\""
11207ea133fd7Smrg	  fi
11208ea133fd7Smrg	done
11209ea133fd7Smrg      }
11210a253d6aeSmrg
11211ea133fd7Smrg      # Do a symbolic link so that the libtool archive can be found in
11212ea133fd7Smrg      # LD_LIBRARY_PATH before the program is installed.
11213ea133fd7Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11214ea133fd7Smrg      ;;
11215ea133fd7Smrg    esac
11216ea133fd7Smrg    exit $EXIT_SUCCESS
11217ea133fd7Smrg}
11218a253d6aeSmrg
11219b41a30aaSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220b41a30aaSmrg  func_mode_link ${1+"$@"}
11221b41a30aaSmrgfi
11222a253d6aeSmrg
11223a253d6aeSmrg
11224ea133fd7Smrg# func_mode_uninstall arg...
11225ea133fd7Smrgfunc_mode_uninstall ()
11226ea133fd7Smrg{
11227b41a30aaSmrg    $debug_cmd
11228b41a30aaSmrg
11229b41a30aaSmrg    RM=$nonopt
11230a253d6aeSmrg    files=
11231b41a30aaSmrg    rmforce=false
11232a253d6aeSmrg    exit_status=0
11233a253d6aeSmrg
11234a253d6aeSmrg    # This variable tells wrapper scripts just to set variables rather
11235a253d6aeSmrg    # than running their programs.
11236b41a30aaSmrg    libtool_install_magic=$magic
11237a253d6aeSmrg
11238a253d6aeSmrg    for arg
11239a253d6aeSmrg    do
11240a253d6aeSmrg      case $arg in
11241b41a30aaSmrg      -f) func_append RM " $arg"; rmforce=: ;;
1124206f32fbeSmrg      -*) func_append RM " $arg" ;;
1124306f32fbeSmrg      *) func_append files " $arg" ;;
11244a253d6aeSmrg      esac
11245a253d6aeSmrg    done
11246a253d6aeSmrg
11247ea133fd7Smrg    test -z "$RM" && \
11248ea133fd7Smrg      func_fatal_help "you must specify an RM program"
11249a253d6aeSmrg
11250a253d6aeSmrg    rmdirs=
11251a253d6aeSmrg
11252a253d6aeSmrg    for file in $files; do
11253ea133fd7Smrg      func_dirname "$file" "" "."
11254b41a30aaSmrg      dir=$func_dirname_result
11255b41a30aaSmrg      if test . = "$dir"; then
11256b41a30aaSmrg	odir=$objdir
11257a253d6aeSmrg      else
11258b41a30aaSmrg	odir=$dir/$objdir
11259a253d6aeSmrg      fi
11260ea133fd7Smrg      func_basename "$file"
11261b41a30aaSmrg      name=$func_basename_result
11262b41a30aaSmrg      test uninstall = "$opt_mode" && odir=$dir
11263a253d6aeSmrg
1126406f32fbeSmrg      # Remember odir for removal later, being careful to avoid duplicates
11265b41a30aaSmrg      if test clean = "$opt_mode"; then
11266a253d6aeSmrg	case " $rmdirs " in
1126706f32fbeSmrg	  *" $odir "*) ;;
1126806f32fbeSmrg	  *) func_append rmdirs " $odir" ;;
11269a253d6aeSmrg	esac
11270a253d6aeSmrg      fi
11271a253d6aeSmrg
11272a253d6aeSmrg      # Don't error if the file doesn't exist and rm -f was used.
11273ea133fd7Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11274ea133fd7Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11275ea133fd7Smrg	 test -f "$file"; then
11276a253d6aeSmrg	:
11277a253d6aeSmrg      elif test -d "$file"; then
11278a253d6aeSmrg	exit_status=1
11279a253d6aeSmrg	continue
11280b41a30aaSmrg      elif $rmforce; then
11281a253d6aeSmrg	continue
11282a253d6aeSmrg      fi
11283a253d6aeSmrg
11284b41a30aaSmrg      rmfiles=$file
11285a253d6aeSmrg
11286a253d6aeSmrg      case $name in
11287a253d6aeSmrg      *.la)
11288a253d6aeSmrg	# Possibly a libtool archive, so verify it.
11289ea133fd7Smrg	if func_lalib_p "$file"; then
11290ea133fd7Smrg	  func_source $dir/$name
11291a253d6aeSmrg
11292a253d6aeSmrg	  # Delete the libtool libraries and symlinks.
11293a253d6aeSmrg	  for n in $library_names; do
1129406f32fbeSmrg	    func_append rmfiles " $odir/$n"
11295a253d6aeSmrg	  done
1129606f32fbeSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297a253d6aeSmrg
11298b41a30aaSmrg	  case $opt_mode in
11299a253d6aeSmrg	  clean)
1130006f32fbeSmrg	    case " $library_names " in
11301a253d6aeSmrg	    *" $dlname "*) ;;
1130206f32fbeSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303a253d6aeSmrg	    esac
1130406f32fbeSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305a253d6aeSmrg	    ;;
11306a253d6aeSmrg	  uninstall)
11307a253d6aeSmrg	    if test -n "$library_names"; then
11308a253d6aeSmrg	      # Do each command in the postuninstall commands.
11309b41a30aaSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310a253d6aeSmrg	    fi
11311a253d6aeSmrg
11312a253d6aeSmrg	    if test -n "$old_library"; then
11313a253d6aeSmrg	      # Do each command in the old_postuninstall commands.
11314b41a30aaSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315a253d6aeSmrg	    fi
11316a253d6aeSmrg	    # FIXME: should reinstall the best remaining shared library.
11317a253d6aeSmrg	    ;;
11318a253d6aeSmrg	  esac
11319a253d6aeSmrg	fi
11320a253d6aeSmrg	;;
11321a253d6aeSmrg
11322a253d6aeSmrg      *.lo)
11323a253d6aeSmrg	# Possibly a libtool object, so verify it.
11324ea133fd7Smrg	if func_lalib_p "$file"; then
11325a253d6aeSmrg
11326a253d6aeSmrg	  # Read the .lo file
11327ea133fd7Smrg	  func_source $dir/$name
11328a253d6aeSmrg
11329a253d6aeSmrg	  # Add PIC object to the list of files to remove.
11330b41a30aaSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
1133106f32fbeSmrg	    func_append rmfiles " $dir/$pic_object"
11332a253d6aeSmrg	  fi
11333a253d6aeSmrg
11334a253d6aeSmrg	  # Add non-PIC object to the list of files to remove.
11335b41a30aaSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
1133606f32fbeSmrg	    func_append rmfiles " $dir/$non_pic_object"
11337a253d6aeSmrg	  fi
11338a253d6aeSmrg	fi
11339a253d6aeSmrg	;;
11340a253d6aeSmrg
11341a253d6aeSmrg      *)
11342b41a30aaSmrg	if test clean = "$opt_mode"; then
11343a253d6aeSmrg	  noexename=$name
11344a253d6aeSmrg	  case $file in
11345a253d6aeSmrg	  *.exe)
11346ea133fd7Smrg	    func_stripname '' '.exe' "$file"
11347ea133fd7Smrg	    file=$func_stripname_result
11348ea133fd7Smrg	    func_stripname '' '.exe' "$name"
11349ea133fd7Smrg	    noexename=$func_stripname_result
11350a253d6aeSmrg	    # $file with .exe has already been added to rmfiles,
11351a253d6aeSmrg	    # add $file without .exe
1135206f32fbeSmrg	    func_append rmfiles " $file"
11353a253d6aeSmrg	    ;;
11354a253d6aeSmrg	  esac
11355a253d6aeSmrg	  # Do a test to see if this is a libtool program.
11356ea133fd7Smrg	  if func_ltwrapper_p "$file"; then
11357ea133fd7Smrg	    if func_ltwrapper_executable_p "$file"; then
11358ea133fd7Smrg	      func_ltwrapper_scriptname "$file"
11359ea133fd7Smrg	      relink_command=
11360ea133fd7Smrg	      func_source $func_ltwrapper_scriptname_result
1136106f32fbeSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11362ea133fd7Smrg	    else
11363ea133fd7Smrg	      relink_command=
11364ea133fd7Smrg	      func_source $dir/$noexename
11365ea133fd7Smrg	    fi
11366a253d6aeSmrg
11367a253d6aeSmrg	    # note $name still contains .exe if it was in $file originally
11368a253d6aeSmrg	    # as does the version of $file that was added into $rmfiles
11369b41a30aaSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370b41a30aaSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
1137106f32fbeSmrg	      func_append rmfiles " $odir/lt-$name"
11372a253d6aeSmrg	    fi
11373b41a30aaSmrg	    if test "X$noexename" != "X$name"; then
11374b41a30aaSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375a253d6aeSmrg	    fi
11376a253d6aeSmrg	  fi
11377a253d6aeSmrg	fi
11378a253d6aeSmrg	;;
11379a253d6aeSmrg      esac
11380ea133fd7Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381a253d6aeSmrg    done
11382a253d6aeSmrg
11383b41a30aaSmrg    # Try to remove the $objdir's in the directories where we deleted files
11384a253d6aeSmrg    for dir in $rmdirs; do
11385a253d6aeSmrg      if test -d "$dir"; then
11386ea133fd7Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387a253d6aeSmrg      fi
11388a253d6aeSmrg    done
11389a253d6aeSmrg
11390a253d6aeSmrg    exit $exit_status
11391ea133fd7Smrg}
11392a253d6aeSmrg
11393b41a30aaSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394b41a30aaSmrg  func_mode_uninstall ${1+"$@"}
11395b41a30aaSmrgfi
11396a253d6aeSmrg
1139706f32fbeSmrgtest -z "$opt_mode" && {
11398b41a30aaSmrg  help=$generic_help
11399ea133fd7Smrg  func_fatal_help "you must specify a MODE"
11400ea133fd7Smrg}
11401ea133fd7Smrg
11402ea133fd7Smrgtest -z "$exec_cmd" && \
11403b41a30aaSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404a253d6aeSmrg
11405a253d6aeSmrgif test -n "$exec_cmd"; then
11406ea133fd7Smrg  eval exec "$exec_cmd"
11407a253d6aeSmrg  exit $EXIT_FAILURE
11408a253d6aeSmrgfi
11409a253d6aeSmrg
11410ea133fd7Smrgexit $exit_status
11411a253d6aeSmrg
11412a253d6aeSmrg
11413a253d6aeSmrg# The TAGs below are defined such that we never get into a situation
11414b41a30aaSmrg# where we disable both kinds of libraries.  Given conflicting
11415a253d6aeSmrg# choices, we go for a static library, that is the most portable,
11416a253d6aeSmrg# since we can't tell whether shared libraries were disabled because
11417a253d6aeSmrg# the user asked for that or because the platform doesn't support
11418a253d6aeSmrg# them.  This is particularly important on AIX, because we don't
11419a253d6aeSmrg# support having both static and shared libraries enabled at the same
11420a253d6aeSmrg# time on that platform, so we default to a shared-only configuration.
11421a253d6aeSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11422a253d6aeSmrg# configuration.  But we'll never go from static-only to shared-only.
11423a253d6aeSmrg
11424a253d6aeSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11425ea133fd7Smrgbuild_libtool_libs=no
11426ea133fd7Smrgbuild_old_libs=yes
11427a253d6aeSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11428a253d6aeSmrg
11429a253d6aeSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11430ea133fd7Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431a253d6aeSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11432a253d6aeSmrg
11433a253d6aeSmrg# Local Variables:
11434a253d6aeSmrg# mode:shell-script
11435a253d6aeSmrg# sh-indentation:2
11436a253d6aeSmrg# End:
11437