ltmain.sh revision da2e2ef6
1da2e2ef6Smrg#! /usr/bin/env sh
2b7d26471Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3da2e2ef6Smrg##               by inline-source v2019-02-19.15
45ffd6003Smrg
5da2e2ef6Smrg# libtool (GNU libtool) 2.4.7
6b7d26471Smrg# Provide generalized library-building support services.
75ffd6003Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
85ffd6003Smrg
9da2e2ef6Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
105ffd6003Smrg# This is free software; see the source for copying conditions.  There is NO
115ffd6003Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
125ffd6003Smrg
135ffd6003Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14145b7b3cSmrg# it under the terms of the GNU General Public License as published by
15145b7b3cSmrg# the Free Software Foundation; either version 2 of the License, or
16145b7b3cSmrg# (at your option) any later version.
17145b7b3cSmrg#
185ffd6003Smrg# As a special exception to the GNU General Public License,
195ffd6003Smrg# if you distribute this file as part of a program or library that
205ffd6003Smrg# is built using GNU Libtool, you may include this file under the
215ffd6003Smrg# same distribution terms that you use for the rest of that program.
225ffd6003Smrg#
235ffd6003Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24145b7b3cSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25145b7b3cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26145b7b3cSmrg# General Public License for more details.
27145b7b3cSmrg#
28145b7b3cSmrg# You should have received a copy of the GNU General Public License
29b7d26471Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30145b7b3cSmrg
31145b7b3cSmrg
32629baa8cSmrgPROGRAM=libtool
33145b7b3cSmrgPACKAGE=libtool
34da2e2ef6SmrgVERSION=2.4.7
35da2e2ef6Smrgpackage_revision=2.4.7
36578741aaSmrg
37b7d26471Smrg
38b7d26471Smrg## ------ ##
39b7d26471Smrg## Usage. ##
40b7d26471Smrg## ------ ##
41b7d26471Smrg
42b7d26471Smrg# Run './libtool --help' for help with using this script from the
43b7d26471Smrg# command line.
44b7d26471Smrg
45b7d26471Smrg
46b7d26471Smrg## ------------------------------- ##
47b7d26471Smrg## User overridable command paths. ##
48b7d26471Smrg## ------------------------------- ##
49b7d26471Smrg
50b7d26471Smrg# After configure completes, it has a better idea of some of the
51b7d26471Smrg# shell tools we need than the defaults used by the functions shared
52b7d26471Smrg# with bootstrap, so set those here where they can still be over-
53b7d26471Smrg# ridden by the user, but otherwise take precedence.
54b7d26471Smrg
55b7d26471Smrg: ${AUTOCONF="autoconf"}
56b7d26471Smrg: ${AUTOMAKE="automake"}
57b7d26471Smrg
58b7d26471Smrg
59b7d26471Smrg## -------------------------- ##
60b7d26471Smrg## Source external libraries. ##
61b7d26471Smrg## -------------------------- ##
62b7d26471Smrg
63b7d26471Smrg# Much of our low-level functionality needs to be sourced from external
64b7d26471Smrg# libraries, which are installed to $pkgauxdir.
65b7d26471Smrg
66b7d26471Smrg# Set a version string for this script.
67da2e2ef6Smrgscriptversion=2019-02-19.15; # UTC
68b7d26471Smrg
69b7d26471Smrg# General shell script boiler plate, and helper functions.
70b7d26471Smrg# Written by Gary V. Vaughan, 2004
71b7d26471Smrg
72da2e2ef6Smrg# This is free software.  There is NO warranty; not even for
73da2e2ef6Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74da2e2ef6Smrg#
75da2e2ef6Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76da2e2ef6Smrg#
77da2e2ef6Smrg# This file is dual licensed under the terms of the MIT license
78da2e2ef6Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79da2e2ef6Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80da2e2ef6Smrg# these licenses when using or redistributing this software or any of
81da2e2ef6Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82da2e2ef6Smrg# included in the Bootstrap distribution for the full license texts.
83b7d26471Smrg
84da2e2ef6Smrg# Please report bugs or propose patches to:
85da2e2ef6Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86b7d26471Smrg
87b7d26471Smrg
88b7d26471Smrg## ------ ##
89b7d26471Smrg## Usage. ##
90b7d26471Smrg## ------ ##
91b7d26471Smrg
92b7d26471Smrg# Evaluate this file near the top of your script to gain access to
93b7d26471Smrg# the functions and variables defined here:
94b7d26471Smrg#
95b7d26471Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96b7d26471Smrg#
97b7d26471Smrg# If you need to override any of the default environment variable
98b7d26471Smrg# settings, do that before evaluating this file.
99b7d26471Smrg
100b7d26471Smrg
101b7d26471Smrg## -------------------- ##
102b7d26471Smrg## Shell normalisation. ##
103b7d26471Smrg## -------------------- ##
104b7d26471Smrg
105b7d26471Smrg# Some shells need a little help to be as Bourne compatible as possible.
106b7d26471Smrg# Before doing anything else, make sure all that help has been provided!
107b7d26471Smrg
108b7d26471SmrgDUALCASE=1; export DUALCASE # for MKS sh
109b7d26471Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110578741aaSmrg  emulate sh
111578741aaSmrg  NULLCMD=:
112b7d26471Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113578741aaSmrg  # is contrary to our usage.  Disable this feature.
114578741aaSmrg  alias -g '${1+"$@"}'='"$@"'
115145b7b3cSmrg  setopt NO_GLOB_SUBST
116578741aaSmrgelse
117b7d26471Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118145b7b3cSmrgfi
119629baa8cSmrg
120b7d26471Smrg# NLS nuisances: We save the old values in case they are required later.
121b7d26471Smrg_G_user_locale=
122b7d26471Smrg_G_safe_locale=
123b7d26471Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124578741aaSmrgdo
125b7d26471Smrg  eval "if test set = \"\${$_G_var+set}\"; then
126b7d26471Smrg          save_$_G_var=\$$_G_var
127b7d26471Smrg          $_G_var=C
128b7d26471Smrg	  export $_G_var
129b7d26471Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130b7d26471Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131578741aaSmrg	fi"
132578741aaSmrgdone
133da2e2ef6Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134da2e2ef6Smrg# in case the environment reset is needed later and the $save_* variant is not
135da2e2ef6Smrg# defined (see the code above).
136da2e2ef6SmrgLC_ALL=C
137da2e2ef6SmrgLANGUAGE=C
138da2e2ef6Smrgexport LANGUAGE LC_ALL
1395ffd6003Smrg
140b7d26471Smrg# Make sure IFS has a sensible default
141b7d26471Smrgsp=' '
142b7d26471Smrgnl='
143b7d26471Smrg'
144b7d26471SmrgIFS="$sp	$nl"
145b7d26471Smrg
146b7d26471Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
147b7d26471Smrgif test "${PATH_SEPARATOR+set}" != set; then
148b7d26471Smrg  PATH_SEPARATOR=:
149b7d26471Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150b7d26471Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151b7d26471Smrg      PATH_SEPARATOR=';'
152b7d26471Smrg  }
153b7d26471Smrgfi
1545ffd6003Smrg
1555ffd6003Smrg
156da2e2ef6Smrg# func_unset VAR
157da2e2ef6Smrg# --------------
158da2e2ef6Smrg# Portably unset VAR.
159da2e2ef6Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160da2e2ef6Smrg# status if VAR is already unset, which might be problematic if the
161da2e2ef6Smrg# statement is used at the end of a function (thus poisoning its return
162da2e2ef6Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163da2e2ef6Smrg# the script in this case).
164da2e2ef6Smrgfunc_unset ()
165da2e2ef6Smrg{
166da2e2ef6Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167da2e2ef6Smrg}
168da2e2ef6Smrg
169da2e2ef6Smrg
170da2e2ef6Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171da2e2ef6Smrgfunc_unset CDPATH
172da2e2ef6Smrg
173da2e2ef6Smrg# Make sure ${,E,F}GREP behave sanely.
174da2e2ef6Smrgfunc_unset GREP_OPTIONS
175da2e2ef6Smrg
1765ffd6003Smrg
177b7d26471Smrg## ------------------------- ##
178b7d26471Smrg## Locate command utilities. ##
179b7d26471Smrg## ------------------------- ##
180b7d26471Smrg
181b7d26471Smrg
182b7d26471Smrg# func_executable_p FILE
183b7d26471Smrg# ----------------------
184b7d26471Smrg# Check that FILE is an executable regular file.
185b7d26471Smrgfunc_executable_p ()
186b7d26471Smrg{
187b7d26471Smrg    test -f "$1" && test -x "$1"
188b7d26471Smrg}
189b7d26471Smrg
190b7d26471Smrg
191b7d26471Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192b7d26471Smrg# --------------------------------------------
193b7d26471Smrg# Search for either a program that responds to --version with output
194b7d26471Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195b7d26471Smrg# trying all the directories in PATH with each of the elements of
196b7d26471Smrg# PROGS_LIST.
197b7d26471Smrg#
198b7d26471Smrg# CHECK_FUNC should accept the path to a candidate program, and
199b7d26471Smrg# set $func_check_prog_result if it truncates its output less than
200b7d26471Smrg# $_G_path_prog_max characters.
201b7d26471Smrgfunc_path_progs ()
202b7d26471Smrg{
203b7d26471Smrg    _G_progs_list=$1
204b7d26471Smrg    _G_check_func=$2
205b7d26471Smrg    _G_PATH=${3-"$PATH"}
206b7d26471Smrg
207b7d26471Smrg    _G_path_prog_max=0
208b7d26471Smrg    _G_path_prog_found=false
209b7d26471Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210b7d26471Smrg    for _G_dir in $_G_PATH; do
211b7d26471Smrg      IFS=$_G_save_IFS
212b7d26471Smrg      test -z "$_G_dir" && _G_dir=.
213b7d26471Smrg      for _G_prog_name in $_G_progs_list; do
214b7d26471Smrg        for _exeext in '' .EXE; do
215b7d26471Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216b7d26471Smrg          func_executable_p "$_G_path_prog" || continue
217b7d26471Smrg          case `"$_G_path_prog" --version 2>&1` in
218b7d26471Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219b7d26471Smrg            *)     $_G_check_func $_G_path_prog
220b7d26471Smrg		   func_path_progs_result=$func_check_prog_result
221b7d26471Smrg		   ;;
222b7d26471Smrg          esac
223b7d26471Smrg          $_G_path_prog_found && break 3
224b7d26471Smrg        done
225b7d26471Smrg      done
226b7d26471Smrg    done
227b7d26471Smrg    IFS=$_G_save_IFS
228b7d26471Smrg    test -z "$func_path_progs_result" && {
229b7d26471Smrg      echo "no acceptable sed could be found in \$PATH" >&2
230b7d26471Smrg      exit 1
231b7d26471Smrg    }
232b7d26471Smrg}
233b7d26471Smrg
234b7d26471Smrg
235b7d26471Smrg# We want to be able to use the functions in this file before configure
236b7d26471Smrg# has figured out where the best binaries are kept, which means we have
237b7d26471Smrg# to search for them ourselves - except when the results are already set
238b7d26471Smrg# where we skip the searches.
239b7d26471Smrg
240b7d26471Smrg# Unless the user overrides by setting SED, search the path for either GNU
241b7d26471Smrg# sed, or the sed that truncates its output the least.
242b7d26471Smrgtest -z "$SED" && {
243b7d26471Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244b7d26471Smrg  for _G_i in 1 2 3 4 5 6 7; do
245b7d26471Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246b7d26471Smrg  done
247b7d26471Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248b7d26471Smrg  _G_sed_script=
249b7d26471Smrg
250b7d26471Smrg  func_check_prog_sed ()
251b7d26471Smrg  {
252b7d26471Smrg    _G_path_prog=$1
253b7d26471Smrg
254b7d26471Smrg    _G_count=0
255b7d26471Smrg    printf 0123456789 >conftest.in
256b7d26471Smrg    while :
257b7d26471Smrg    do
258b7d26471Smrg      cat conftest.in conftest.in >conftest.tmp
259b7d26471Smrg      mv conftest.tmp conftest.in
260b7d26471Smrg      cp conftest.in conftest.nl
261b7d26471Smrg      echo '' >> conftest.nl
262b7d26471Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263b7d26471Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264b7d26471Smrg      _G_count=`expr $_G_count + 1`
265b7d26471Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266b7d26471Smrg        # Best one so far, save it but keep looking for a better one
267b7d26471Smrg        func_check_prog_result=$_G_path_prog
268b7d26471Smrg        _G_path_prog_max=$_G_count
269b7d26471Smrg      fi
270b7d26471Smrg      # 10*(2^10) chars as input seems more than enough
271b7d26471Smrg      test 10 -lt "$_G_count" && break
272b7d26471Smrg    done
273b7d26471Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274b7d26471Smrg  }
275b7d26471Smrg
276da2e2ef6Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277b7d26471Smrg  rm -f conftest.sed
278b7d26471Smrg  SED=$func_path_progs_result
279b7d26471Smrg}
280b7d26471Smrg
281b7d26471Smrg
282b7d26471Smrg# Unless the user overrides by setting GREP, search the path for either GNU
283b7d26471Smrg# grep, or the grep that truncates its output the least.
284b7d26471Smrgtest -z "$GREP" && {
285b7d26471Smrg  func_check_prog_grep ()
286b7d26471Smrg  {
287b7d26471Smrg    _G_path_prog=$1
288b7d26471Smrg
289b7d26471Smrg    _G_count=0
290b7d26471Smrg    _G_path_prog_max=0
291b7d26471Smrg    printf 0123456789 >conftest.in
292b7d26471Smrg    while :
293b7d26471Smrg    do
294b7d26471Smrg      cat conftest.in conftest.in >conftest.tmp
295b7d26471Smrg      mv conftest.tmp conftest.in
296b7d26471Smrg      cp conftest.in conftest.nl
297b7d26471Smrg      echo 'GREP' >> conftest.nl
298b7d26471Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299b7d26471Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300b7d26471Smrg      _G_count=`expr $_G_count + 1`
301b7d26471Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302b7d26471Smrg        # Best one so far, save it but keep looking for a better one
303b7d26471Smrg        func_check_prog_result=$_G_path_prog
304b7d26471Smrg        _G_path_prog_max=$_G_count
305b7d26471Smrg      fi
306b7d26471Smrg      # 10*(2^10) chars as input seems more than enough
307b7d26471Smrg      test 10 -lt "$_G_count" && break
308b7d26471Smrg    done
309b7d26471Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310b7d26471Smrg  }
311b7d26471Smrg
312da2e2ef6Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313b7d26471Smrg  GREP=$func_path_progs_result
314b7d26471Smrg}
315b7d26471Smrg
316b7d26471Smrg
317b7d26471Smrg## ------------------------------- ##
318b7d26471Smrg## User overridable command paths. ##
319b7d26471Smrg## ------------------------------- ##
320b7d26471Smrg
321b7d26471Smrg# All uppercase variable names are used for environment variables.  These
322b7d26471Smrg# variables can be overridden by the user before calling a script that
323b7d26471Smrg# uses them if a suitable command of that name is not already available
324b7d26471Smrg# in the command search PATH.
3255ffd6003Smrg
3265ffd6003Smrg: ${CP="cp -f"}
327b7d26471Smrg: ${ECHO="printf %s\n"}
328b7d26471Smrg: ${EGREP="$GREP -E"}
329b7d26471Smrg: ${FGREP="$GREP -F"}
3305ffd6003Smrg: ${LN_S="ln -s"}
3315ffd6003Smrg: ${MAKE="make"}
3325ffd6003Smrg: ${MKDIR="mkdir"}
3335ffd6003Smrg: ${MV="mv -f"}
3345ffd6003Smrg: ${RM="rm -f"}
3355ffd6003Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336145b7b3cSmrg
3375ffd6003Smrg
338b7d26471Smrg## -------------------- ##
339b7d26471Smrg## Useful sed snippets. ##
340b7d26471Smrg## -------------------- ##
341629baa8cSmrg
342b7d26471Smrgsed_dirname='s|/[^/]*$||'
343b7d26471Smrgsed_basename='s|^.*/||'
344629baa8cSmrg
345b7d26471Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
346b7d26471Smrg# metacharacters that are still active within double-quoted strings.
347b7d26471Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348629baa8cSmrg
349b7d26471Smrg# Same as above, but do not quote variable references.
350b7d26471Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351629baa8cSmrg
352b7d26471Smrg# Sed substitution that turns a string into a regex matching for the
353b7d26471Smrg# string literally.
354b7d26471Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355629baa8cSmrg
356b7d26471Smrg# Sed substitution that converts a w32 file name or path
357b7d26471Smrg# that contains forward slashes, into one that contains
358b7d26471Smrg# (escaped) backslashes.  A very naive implementation.
359b7d26471Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360b7d26471Smrg
361b7d26471Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362b7d26471Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363b7d26471Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364b7d26471Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
365b7d26471Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366b7d26471Smrg_G_bs='\\'
367b7d26471Smrg_G_bs2='\\\\'
368b7d26471Smrg_G_bs4='\\\\\\\\'
369b7d26471Smrg_G_dollar='\$'
370b7d26471Smrgsed_double_backslash="\
371b7d26471Smrg  s/$_G_bs4/&\\
372b7d26471Smrg/g
373b7d26471Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374b7d26471Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375b7d26471Smrg  s/\n//g"
376629baa8cSmrg
377da2e2ef6Smrg# require_check_ifs_backslash
378da2e2ef6Smrg# ---------------------------
379da2e2ef6Smrg# Check if we can use backslash as IFS='\' separator, and set
380da2e2ef6Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381da2e2ef6Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382da2e2ef6Smrgfunc_require_check_ifs_backslash ()
383da2e2ef6Smrg{
384da2e2ef6Smrg  _G_save_IFS=$IFS
385da2e2ef6Smrg  IFS='\'
386da2e2ef6Smrg  _G_check_ifs_backshlash='a\\b'
387da2e2ef6Smrg  for _G_i in $_G_check_ifs_backshlash
388da2e2ef6Smrg  do
389da2e2ef6Smrg  case $_G_i in
390da2e2ef6Smrg  a)
391da2e2ef6Smrg    check_ifs_backshlash_broken=false
392da2e2ef6Smrg    ;;
393da2e2ef6Smrg  '')
394da2e2ef6Smrg    break
395da2e2ef6Smrg    ;;
396da2e2ef6Smrg  *)
397da2e2ef6Smrg    check_ifs_backshlash_broken=:
398da2e2ef6Smrg    break
399da2e2ef6Smrg    ;;
400da2e2ef6Smrg  esac
401da2e2ef6Smrg  done
402da2e2ef6Smrg  IFS=$_G_save_IFS
403da2e2ef6Smrg  require_check_ifs_backslash=:
404da2e2ef6Smrg}
405da2e2ef6Smrg
406629baa8cSmrg
407b7d26471Smrg## ----------------- ##
408b7d26471Smrg## Global variables. ##
409b7d26471Smrg## ----------------- ##
410629baa8cSmrg
411b7d26471Smrg# Except for the global variables explicitly listed below, the following
412b7d26471Smrg# functions in the '^func_' namespace, and the '^require_' namespace
413b7d26471Smrg# variables initialised in the 'Resource management' section, sourcing
414b7d26471Smrg# this file will not pollute your global namespace with anything
415b7d26471Smrg# else. There's no portable way to scope variables in Bourne shell
416b7d26471Smrg# though, so actually running these functions will sometimes place
417b7d26471Smrg# results into a variable named after the function, and often use
418b7d26471Smrg# temporary variables in the '^_G_' namespace. If you are careful to
419b7d26471Smrg# avoid using those namespaces casually in your sourcing script, things
420b7d26471Smrg# should continue to work as you expect. And, of course, you can freely
421b7d26471Smrg# overwrite any of the functions or variables defined here before
422b7d26471Smrg# calling anything to customize them.
423629baa8cSmrg
424b7d26471SmrgEXIT_SUCCESS=0
425b7d26471SmrgEXIT_FAILURE=1
426b7d26471SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427b7d26471SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428145b7b3cSmrg
429b7d26471Smrg# Allow overriding, eg assuming that you follow the convention of
430b7d26471Smrg# putting '$debug_cmd' at the start of all your functions, you can get
431b7d26471Smrg# bash to show function call trace with:
432b7d26471Smrg#
433b7d26471Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434b7d26471Smrgdebug_cmd=${debug_cmd-":"}
435b7d26471Smrgexit_cmd=:
4365ffd6003Smrg
437b7d26471Smrg# By convention, finish your script with:
438b7d26471Smrg#
439b7d26471Smrg#    exit $exit_status
440b7d26471Smrg#
441b7d26471Smrg# so that you can set exit_status to non-zero if you want to indicate
442b7d26471Smrg# something went wrong during execution without actually bailing out at
443b7d26471Smrg# the point of failure.
444b7d26471Smrgexit_status=$EXIT_SUCCESS
445629baa8cSmrg
446b7d26471Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447b7d26471Smrg# is ksh but when the shell is invoked as "sh" and the current value of
448b7d26471Smrg# the _XPG environment variable is not equal to 1 (one), the special
449b7d26471Smrg# positional parameter $0, within a function call, is the name of the
450b7d26471Smrg# function.
451b7d26471Smrgprogpath=$0
4525ffd6003Smrg
453b7d26471Smrg# The name of this program.
454b7d26471Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
4555ffd6003Smrg
456b7d26471Smrg# Make sure we have an absolute progpath for reexecution:
4575ffd6003Smrgcase $progpath in
4585ffd6003Smrg  [\\/]*|[A-Za-z]:\\*) ;;
4595ffd6003Smrg  *[\\/]*)
460b7d26471Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
4615ffd6003Smrg     progdir=`cd "$progdir" && pwd`
462b7d26471Smrg     progpath=$progdir/$progname
4635ffd6003Smrg     ;;
4645ffd6003Smrg  *)
465b7d26471Smrg     _G_IFS=$IFS
466b7d26471Smrg     IFS=${PATH_SEPARATOR-:}
4675ffd6003Smrg     for progdir in $PATH; do
468b7d26471Smrg       IFS=$_G_IFS
4695ffd6003Smrg       test -x "$progdir/$progname" && break
4705ffd6003Smrg     done
471b7d26471Smrg     IFS=$_G_IFS
4725ffd6003Smrg     test -n "$progdir" || progdir=`pwd`
473b7d26471Smrg     progpath=$progdir/$progname
4745ffd6003Smrg     ;;
4755ffd6003Smrgesac
4765ffd6003Smrg
4775ffd6003Smrg
478b7d26471Smrg## ----------------- ##
479b7d26471Smrg## Standard options. ##
480b7d26471Smrg## ----------------- ##
481629baa8cSmrg
482b7d26471Smrg# The following options affect the operation of the functions defined
483b7d26471Smrg# below, and should be set appropriately depending on run-time para-
484b7d26471Smrg# meters passed on the command line.
4855ffd6003Smrg
4865ffd6003Smrgopt_dry_run=false
4875ffd6003Smrgopt_quiet=false
4885ffd6003Smrgopt_verbose=false
4895ffd6003Smrg
490b7d26471Smrg# Categories 'all' and 'none' are always available.  Append any others
491b7d26471Smrg# you will pass as the first argument to func_warning from your own
492b7d26471Smrg# code.
493b7d26471Smrgwarning_categories=
4945ffd6003Smrg
495b7d26471Smrg# By default, display warnings according to 'opt_warning_types'.  Set
496b7d26471Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497b7d26471Smrg# treat the next displayed warning as a fatal error.
498b7d26471Smrgwarning_func=func_warn_and_continue
4995ffd6003Smrg
500b7d26471Smrg# Set to 'all' to display all warnings, 'none' to suppress all
501b7d26471Smrg# warnings, or a space delimited list of some subset of
502b7d26471Smrg# 'warning_categories' to display only the listed warnings.
503b7d26471Smrgopt_warning_types=all
5045ffd6003Smrg
505629baa8cSmrg
506b7d26471Smrg## -------------------- ##
507b7d26471Smrg## Resource management. ##
508b7d26471Smrg## -------------------- ##
5095ffd6003Smrg
510b7d26471Smrg# This section contains definitions for functions that each ensure a
511b7d26471Smrg# particular resource (a file, or a non-empty configuration variable for
512b7d26471Smrg# example) is available, and if appropriate to extract default values
513b7d26471Smrg# from pertinent package files. Call them using their associated
514b7d26471Smrg# 'require_*' variable to ensure that they are executed, at most, once.
515b7d26471Smrg#
516b7d26471Smrg# It's entirely deliberate that calling these functions can set
517b7d26471Smrg# variables that don't obey the namespace limitations obeyed by the rest
518b7d26471Smrg# of this file, in order that that they be as useful as possible to
519b7d26471Smrg# callers.
5205ffd6003Smrg
5215ffd6003Smrg
522b7d26471Smrg# require_term_colors
523b7d26471Smrg# -------------------
524b7d26471Smrg# Allow display of bold text on terminals that support it.
525b7d26471Smrgrequire_term_colors=func_require_term_colors
526b7d26471Smrgfunc_require_term_colors ()
5275ffd6003Smrg{
528b7d26471Smrg    $debug_cmd
529b7d26471Smrg
530b7d26471Smrg    test -t 1 && {
531b7d26471Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532b7d26471Smrg      # precedence, because most terminfo databases neglect to describe
533b7d26471Smrg      # whether color sequences are supported.
534b7d26471Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535b7d26471Smrg
536b7d26471Smrg      if test 1 = "$USE_ANSI_COLORS"; then
537b7d26471Smrg        # Standard ANSI escape sequences
538b7d26471Smrg        tc_reset='[0m'
539b7d26471Smrg        tc_bold='[1m';   tc_standout='[7m'
540b7d26471Smrg        tc_red='[31m';   tc_green='[32m'
541b7d26471Smrg        tc_blue='[34m';  tc_cyan='[36m'
542b7d26471Smrg      else
543b7d26471Smrg        # Otherwise trust the terminfo database after all.
544b7d26471Smrg        test -n "`tput sgr0 2>/dev/null`" && {
545b7d26471Smrg          tc_reset=`tput sgr0`
546b7d26471Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547b7d26471Smrg          tc_standout=$tc_bold
548b7d26471Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549b7d26471Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550b7d26471Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551b7d26471Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552b7d26471Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553b7d26471Smrg        }
554b7d26471Smrg      fi
555b7d26471Smrg    }
5565ffd6003Smrg
557b7d26471Smrg    require_term_colors=:
5585ffd6003Smrg}
5595ffd6003Smrg
5605ffd6003Smrg
561b7d26471Smrg## ----------------- ##
562b7d26471Smrg## Function library. ##
563b7d26471Smrg## ----------------- ##
564b7d26471Smrg
565b7d26471Smrg# This section contains a variety of useful functions to call in your
566b7d26471Smrg# scripts. Take note of the portable wrappers for features provided by
567b7d26471Smrg# some modern shells, which will fall back to slower equivalents on
568b7d26471Smrg# less featureful shells.
569b7d26471Smrg
570b7d26471Smrg
571b7d26471Smrg# func_append VAR VALUE
572b7d26471Smrg# ---------------------
573b7d26471Smrg# Append VALUE onto the existing contents of VAR.
574b7d26471Smrg
575b7d26471Smrg  # We should try to minimise forks, especially on Windows where they are
576b7d26471Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577b7d26471Smrg  # being used:
578b7d26471Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579b7d26471Smrg    : ${_G_HAVE_ARITH_OP="yes"}
580b7d26471Smrg    : ${_G_HAVE_XSI_OPS="yes"}
581b7d26471Smrg    # The += operator was introduced in bash 3.1
582b7d26471Smrg    case $BASH_VERSION in
583b7d26471Smrg      [12].* | 3.0 | 3.0*) ;;
584b7d26471Smrg      *)
585b7d26471Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586b7d26471Smrg        ;;
587b7d26471Smrg    esac
588b7d26471Smrg  fi
589b7d26471Smrg
590b7d26471Smrg  # _G_HAVE_PLUSEQ_OP
591b7d26471Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
592b7d26471Smrg  # useable or anything else if it does not work.
593b7d26471Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594b7d26471Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595b7d26471Smrg    && _G_HAVE_PLUSEQ_OP=yes
596b7d26471Smrg
597b7d26471Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598b7d26471Smrgthen
599b7d26471Smrg  # This is an XSI compatible shell, allowing a faster implementation...
600b7d26471Smrg  eval 'func_append ()
601b7d26471Smrg  {
602b7d26471Smrg    $debug_cmd
603b7d26471Smrg
604b7d26471Smrg    eval "$1+=\$2"
605b7d26471Smrg  }'
606b7d26471Smrgelse
607b7d26471Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608b7d26471Smrg  func_append ()
609b7d26471Smrg  {
610b7d26471Smrg    $debug_cmd
611b7d26471Smrg
612b7d26471Smrg    eval "$1=\$$1\$2"
613b7d26471Smrg  }
614b7d26471Smrgfi
615b7d26471Smrg
616b7d26471Smrg
617b7d26471Smrg# func_append_quoted VAR VALUE
618b7d26471Smrg# ----------------------------
619b7d26471Smrg# Quote VALUE and append to the end of shell variable VAR, separated
620b7d26471Smrg# by a space.
621b7d26471Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622b7d26471Smrg  eval 'func_append_quoted ()
623b7d26471Smrg  {
624b7d26471Smrg    $debug_cmd
625b7d26471Smrg
626da2e2ef6Smrg    func_quote_arg pretty "$2"
627da2e2ef6Smrg    eval "$1+=\\ \$func_quote_arg_result"
628b7d26471Smrg  }'
629b7d26471Smrgelse
630b7d26471Smrg  func_append_quoted ()
631b7d26471Smrg  {
632b7d26471Smrg    $debug_cmd
633b7d26471Smrg
634da2e2ef6Smrg    func_quote_arg pretty "$2"
635da2e2ef6Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636b7d26471Smrg  }
637b7d26471Smrgfi
638b7d26471Smrg
639b7d26471Smrg
640b7d26471Smrg# func_append_uniq VAR VALUE
641b7d26471Smrg# --------------------------
642b7d26471Smrg# Append unique VALUE onto the existing contents of VAR, assuming
643b7d26471Smrg# entries are delimited by the first character of VALUE.  For example:
644b7d26471Smrg#
645b7d26471Smrg#   func_append_uniq options " --another-option option-argument"
646b7d26471Smrg#
647b7d26471Smrg# will only append to $options if " --another-option option-argument "
648b7d26471Smrg# is not already present somewhere in $options already (note spaces at
649b7d26471Smrg# each end implied by leading space in second argument).
650b7d26471Smrgfunc_append_uniq ()
651b7d26471Smrg{
652b7d26471Smrg    $debug_cmd
653b7d26471Smrg
654b7d26471Smrg    eval _G_current_value='`$ECHO $'$1'`'
655b7d26471Smrg    _G_delim=`expr "$2" : '\(.\)'`
656b7d26471Smrg
657b7d26471Smrg    case $_G_delim$_G_current_value$_G_delim in
658b7d26471Smrg      *"$2$_G_delim"*) ;;
659b7d26471Smrg      *) func_append "$@" ;;
660b7d26471Smrg    esac
661b7d26471Smrg}
662b7d26471Smrg
663b7d26471Smrg
664b7d26471Smrg# func_arith TERM...
665b7d26471Smrg# ------------------
666b7d26471Smrg# Set func_arith_result to the result of evaluating TERMs.
667b7d26471Smrg  test -z "$_G_HAVE_ARITH_OP" \
668b7d26471Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669b7d26471Smrg    && _G_HAVE_ARITH_OP=yes
670b7d26471Smrg
671b7d26471Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
672b7d26471Smrg  eval 'func_arith ()
673b7d26471Smrg  {
674b7d26471Smrg    $debug_cmd
675b7d26471Smrg
676b7d26471Smrg    func_arith_result=$(( $* ))
677b7d26471Smrg  }'
678b7d26471Smrgelse
679b7d26471Smrg  func_arith ()
680b7d26471Smrg  {
681b7d26471Smrg    $debug_cmd
682b7d26471Smrg
683b7d26471Smrg    func_arith_result=`expr "$@"`
684b7d26471Smrg  }
685b7d26471Smrgfi
686b7d26471Smrg
687b7d26471Smrg
688b7d26471Smrg# func_basename FILE
689b7d26471Smrg# ------------------
690b7d26471Smrg# Set func_basename_result to FILE with everything up to and including
691b7d26471Smrg# the last / stripped.
692b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
693b7d26471Smrg  # If this shell supports suffix pattern removal, then use it to avoid
694b7d26471Smrg  # forking. Hide the definitions single quotes in case the shell chokes
695b7d26471Smrg  # on unsupported syntax...
696b7d26471Smrg  _b='func_basename_result=${1##*/}'
697b7d26471Smrg  _d='case $1 in
698b7d26471Smrg        */*) func_dirname_result=${1%/*}$2 ;;
699b7d26471Smrg        *  ) func_dirname_result=$3        ;;
700b7d26471Smrg      esac'
701b7d26471Smrg
702b7d26471Smrgelse
703b7d26471Smrg  # ...otherwise fall back to using sed.
704b7d26471Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705b7d26471Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706b7d26471Smrg      if test "X$func_dirname_result" = "X$1"; then
707b7d26471Smrg        func_dirname_result=$3
708b7d26471Smrg      else
709b7d26471Smrg        func_append func_dirname_result "$2"
710b7d26471Smrg      fi'
711b7d26471Smrgfi
712b7d26471Smrg
713b7d26471Smrgeval 'func_basename ()
714b7d26471Smrg{
715b7d26471Smrg    $debug_cmd
716b7d26471Smrg
717b7d26471Smrg    '"$_b"'
718b7d26471Smrg}'
719b7d26471Smrg
720b7d26471Smrg
721b7d26471Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722b7d26471Smrg# -------------------------------------------
723b7d26471Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724b7d26471Smrg# otherwise set result to NONDIR_REPLACEMENT.
725b7d26471Smrgeval 'func_dirname ()
726b7d26471Smrg{
727b7d26471Smrg    $debug_cmd
728b7d26471Smrg
729b7d26471Smrg    '"$_d"'
730b7d26471Smrg}'
731b7d26471Smrg
732b7d26471Smrg
733b7d26471Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734b7d26471Smrg# --------------------------------------------------------
735b7d26471Smrg# Perform func_basename and func_dirname in a single function
736b7d26471Smrg# call:
737b7d26471Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738b7d26471Smrg#             add APPEND to the result, otherwise set result
739b7d26471Smrg#             to NONDIR_REPLACEMENT.
740b7d26471Smrg#             value returned in "$func_dirname_result"
741b7d26471Smrg#   basename: Compute filename of FILE.
742b7d26471Smrg#             value retuned in "$func_basename_result"
743b7d26471Smrg# For efficiency, we do not delegate to the functions above but instead
744b7d26471Smrg# duplicate the functionality here.
745b7d26471Smrgeval 'func_dirname_and_basename ()
746b7d26471Smrg{
747b7d26471Smrg    $debug_cmd
748b7d26471Smrg
749b7d26471Smrg    '"$_b"'
750b7d26471Smrg    '"$_d"'
751b7d26471Smrg}'
752b7d26471Smrg
753b7d26471Smrg
754b7d26471Smrg# func_echo ARG...
755b7d26471Smrg# ----------------
756b7d26471Smrg# Echo program name prefixed message.
757b7d26471Smrgfunc_echo ()
758b7d26471Smrg{
759b7d26471Smrg    $debug_cmd
760b7d26471Smrg
761b7d26471Smrg    _G_message=$*
762b7d26471Smrg
763b7d26471Smrg    func_echo_IFS=$IFS
764b7d26471Smrg    IFS=$nl
765b7d26471Smrg    for _G_line in $_G_message; do
766b7d26471Smrg      IFS=$func_echo_IFS
767b7d26471Smrg      $ECHO "$progname: $_G_line"
768b7d26471Smrg    done
769b7d26471Smrg    IFS=$func_echo_IFS
770b7d26471Smrg}
771b7d26471Smrg
772b7d26471Smrg
773b7d26471Smrg# func_echo_all ARG...
774b7d26471Smrg# --------------------
775b7d26471Smrg# Invoke $ECHO with all args, space-separated.
776b7d26471Smrgfunc_echo_all ()
777b7d26471Smrg{
778b7d26471Smrg    $ECHO "$*"
779b7d26471Smrg}
780b7d26471Smrg
781b7d26471Smrg
782b7d26471Smrg# func_echo_infix_1 INFIX ARG...
783b7d26471Smrg# ------------------------------
784b7d26471Smrg# Echo program name, followed by INFIX on the first line, with any
785b7d26471Smrg# additional lines not showing INFIX.
786b7d26471Smrgfunc_echo_infix_1 ()
787b7d26471Smrg{
788b7d26471Smrg    $debug_cmd
789b7d26471Smrg
790b7d26471Smrg    $require_term_colors
791b7d26471Smrg
792b7d26471Smrg    _G_infix=$1; shift
793b7d26471Smrg    _G_indent=$_G_infix
794b7d26471Smrg    _G_prefix="$progname: $_G_infix: "
795b7d26471Smrg    _G_message=$*
796b7d26471Smrg
797b7d26471Smrg    # Strip color escape sequences before counting printable length
798b7d26471Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799b7d26471Smrg    do
800b7d26471Smrg      test -n "$_G_tc" && {
801b7d26471Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802b7d26471Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803b7d26471Smrg      }
804b7d26471Smrg    done
805b7d26471Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806b7d26471Smrg
807b7d26471Smrg    func_echo_infix_1_IFS=$IFS
808b7d26471Smrg    IFS=$nl
809b7d26471Smrg    for _G_line in $_G_message; do
810b7d26471Smrg      IFS=$func_echo_infix_1_IFS
811b7d26471Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812b7d26471Smrg      _G_prefix=$_G_indent
813b7d26471Smrg    done
814b7d26471Smrg    IFS=$func_echo_infix_1_IFS
815b7d26471Smrg}
816b7d26471Smrg
817b7d26471Smrg
818b7d26471Smrg# func_error ARG...
819b7d26471Smrg# -----------------
820b7d26471Smrg# Echo program name prefixed message to standard error.
821b7d26471Smrgfunc_error ()
822b7d26471Smrg{
823b7d26471Smrg    $debug_cmd
824b7d26471Smrg
825b7d26471Smrg    $require_term_colors
826b7d26471Smrg
827b7d26471Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828b7d26471Smrg}
829b7d26471Smrg
830b7d26471Smrg
831b7d26471Smrg# func_fatal_error ARG...
832b7d26471Smrg# -----------------------
833b7d26471Smrg# Echo program name prefixed message to standard error, and exit.
834b7d26471Smrgfunc_fatal_error ()
835b7d26471Smrg{
836b7d26471Smrg    $debug_cmd
837b7d26471Smrg
838b7d26471Smrg    func_error "$*"
839b7d26471Smrg    exit $EXIT_FAILURE
840b7d26471Smrg}
841b7d26471Smrg
842b7d26471Smrg
843b7d26471Smrg# func_grep EXPRESSION FILENAME
844b7d26471Smrg# -----------------------------
8455ffd6003Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
8465ffd6003Smrgfunc_grep ()
8475ffd6003Smrg{
848b7d26471Smrg    $debug_cmd
849b7d26471Smrg
8505ffd6003Smrg    $GREP "$1" "$2" >/dev/null 2>&1
8515ffd6003Smrg}
8525ffd6003Smrg
8535ffd6003Smrg
854b7d26471Smrg# func_len STRING
855b7d26471Smrg# ---------------
856b7d26471Smrg# Set func_len_result to the length of STRING. STRING may not
857b7d26471Smrg# start with a hyphen.
858b7d26471Smrg  test -z "$_G_HAVE_XSI_OPS" \
859b7d26471Smrg    && (eval 'x=a/b/c;
860b7d26471Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861b7d26471Smrg    && _G_HAVE_XSI_OPS=yes
862b7d26471Smrg
863b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
864b7d26471Smrg  eval 'func_len ()
865b7d26471Smrg  {
866b7d26471Smrg    $debug_cmd
867b7d26471Smrg
868b7d26471Smrg    func_len_result=${#1}
869b7d26471Smrg  }'
870b7d26471Smrgelse
871b7d26471Smrg  func_len ()
872b7d26471Smrg  {
873b7d26471Smrg    $debug_cmd
874b7d26471Smrg
875b7d26471Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876b7d26471Smrg  }
877b7d26471Smrgfi
878b7d26471Smrg
879b7d26471Smrg
880b7d26471Smrg# func_mkdir_p DIRECTORY-PATH
881b7d26471Smrg# ---------------------------
8825ffd6003Smrg# Make sure the entire path to DIRECTORY-PATH is available.
8835ffd6003Smrgfunc_mkdir_p ()
8845ffd6003Smrg{
885b7d26471Smrg    $debug_cmd
886b7d26471Smrg
887b7d26471Smrg    _G_directory_path=$1
888b7d26471Smrg    _G_dir_list=
8895ffd6003Smrg
890b7d26471Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8915ffd6003Smrg
892b7d26471Smrg      # Protect directory names starting with '-'
893b7d26471Smrg      case $_G_directory_path in
894b7d26471Smrg        -*) _G_directory_path=./$_G_directory_path ;;
8955ffd6003Smrg      esac
8965ffd6003Smrg
8975ffd6003Smrg      # While some portion of DIR does not yet exist...
898b7d26471Smrg      while test ! -d "$_G_directory_path"; do
8995ffd6003Smrg        # ...make a list in topmost first order.  Use a colon delimited
9005ffd6003Smrg	# list incase some portion of path contains whitespace.
901b7d26471Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
9025ffd6003Smrg
9035ffd6003Smrg        # If the last portion added has no slash in it, the list is done
904b7d26471Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
9055ffd6003Smrg
9065ffd6003Smrg        # ...otherwise throw away the child directory and loop
907b7d26471Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
9085ffd6003Smrg      done
909b7d26471Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
9105ffd6003Smrg
911b7d26471Smrg      func_mkdir_p_IFS=$IFS; IFS=:
912b7d26471Smrg      for _G_dir in $_G_dir_list; do
913b7d26471Smrg	IFS=$func_mkdir_p_IFS
914b7d26471Smrg        # mkdir can fail with a 'File exist' error if two processes
9155ffd6003Smrg        # try to create one of the directories concurrently.  Don't
9165ffd6003Smrg        # stop in that case!
917b7d26471Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
9185ffd6003Smrg      done
919b7d26471Smrg      IFS=$func_mkdir_p_IFS
9205ffd6003Smrg
9215ffd6003Smrg      # Bail out if we (or some other process) failed to create a directory.
922b7d26471Smrg      test -d "$_G_directory_path" || \
923b7d26471Smrg        func_fatal_error "Failed to create '$1'"
9245ffd6003Smrg    fi
9255ffd6003Smrg}
926145b7b3cSmrg
927145b7b3cSmrg
928b7d26471Smrg# func_mktempdir [BASENAME]
929b7d26471Smrg# -------------------------
930145b7b3cSmrg# Make a temporary directory that won't clash with other running
931145b7b3cSmrg# libtool processes, and avoids race conditions if possible.  If
932b7d26471Smrg# given, BASENAME is the basename for that directory.
933145b7b3cSmrgfunc_mktempdir ()
934145b7b3cSmrg{
935b7d26471Smrg    $debug_cmd
936145b7b3cSmrg
937b7d26471Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
938b7d26471Smrg
939b7d26471Smrg    if test : = "$opt_dry_run"; then
940145b7b3cSmrg      # Return a directory name, but don't create it in dry-run mode
941b7d26471Smrg      _G_tmpdir=$_G_template-$$
942145b7b3cSmrg    else
943145b7b3cSmrg
944145b7b3cSmrg      # If mktemp works, use that first and foremost
945b7d26471Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946145b7b3cSmrg
947b7d26471Smrg      if test ! -d "$_G_tmpdir"; then
9485ffd6003Smrg        # Failing that, at least try and use $RANDOM to avoid a race
949b7d26471Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
950145b7b3cSmrg
951b7d26471Smrg        func_mktempdir_umask=`umask`
9525ffd6003Smrg        umask 0077
953b7d26471Smrg        $MKDIR "$_G_tmpdir"
954b7d26471Smrg        umask $func_mktempdir_umask
955145b7b3cSmrg      fi
956145b7b3cSmrg
957145b7b3cSmrg      # If we're not in dry-run mode, bomb out on failure
958b7d26471Smrg      test -d "$_G_tmpdir" || \
959b7d26471Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960145b7b3cSmrg    fi
961145b7b3cSmrg
962b7d26471Smrg    $ECHO "$_G_tmpdir"
963145b7b3cSmrg}
964145b7b3cSmrg
965145b7b3cSmrg
966b7d26471Smrg# func_normal_abspath PATH
967b7d26471Smrg# ------------------------
968b7d26471Smrg# Remove doubled-up and trailing slashes, "." path components,
969b7d26471Smrg# and cancel out any ".." path components in PATH after making
970b7d26471Smrg# it an absolute path.
971b7d26471Smrgfunc_normal_abspath ()
972b7d26471Smrg{
973b7d26471Smrg    $debug_cmd
974b7d26471Smrg
975b7d26471Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
976b7d26471Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977b7d26471Smrg    _G_pathcdr='s|^/[^/]*||'
978b7d26471Smrg    _G_removedotparts=':dotsl
979b7d26471Smrg		s|/\./|/|g
980b7d26471Smrg		t dotsl
981b7d26471Smrg		s|/\.$|/|'
982b7d26471Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
983b7d26471Smrg    _G_finalslash='s|/*$|/|'
984b7d26471Smrg
985b7d26471Smrg    # Start from root dir and reassemble the path.
986b7d26471Smrg    func_normal_abspath_result=
987b7d26471Smrg    func_normal_abspath_tpath=$1
988b7d26471Smrg    func_normal_abspath_altnamespace=
989b7d26471Smrg    case $func_normal_abspath_tpath in
990b7d26471Smrg      "")
991b7d26471Smrg        # Empty path, that just means $cwd.
992b7d26471Smrg        func_stripname '' '/' "`pwd`"
993b7d26471Smrg        func_normal_abspath_result=$func_stripname_result
994b7d26471Smrg        return
995b7d26471Smrg        ;;
996b7d26471Smrg      # The next three entries are used to spot a run of precisely
997b7d26471Smrg      # two leading slashes without using negated character classes;
998b7d26471Smrg      # we take advantage of case's first-match behaviour.
999b7d26471Smrg      ///*)
1000b7d26471Smrg        # Unusual form of absolute path, do nothing.
1001b7d26471Smrg        ;;
1002b7d26471Smrg      //*)
1003b7d26471Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004b7d26471Smrg        # and for example Cygwin uses it to access remote file shares
1005b7d26471Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006b7d26471Smrg        func_normal_abspath_altnamespace=/
1007b7d26471Smrg        ;;
1008b7d26471Smrg      /*)
1009b7d26471Smrg        # Absolute path, do nothing.
1010b7d26471Smrg        ;;
1011b7d26471Smrg      *)
1012b7d26471Smrg        # Relative path, prepend $cwd.
1013b7d26471Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014b7d26471Smrg        ;;
1015b7d26471Smrg    esac
1016b7d26471Smrg
1017b7d26471Smrg    # Cancel out all the simple stuff to save iterations.  We also want
1018b7d26471Smrg    # the path to end with a slash for ease of parsing, so make sure
1019b7d26471Smrg    # there is one (and only one) here.
1020b7d26471Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021b7d26471Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022b7d26471Smrg    while :; do
1023b7d26471Smrg      # Processed it all yet?
1024b7d26471Smrg      if test / = "$func_normal_abspath_tpath"; then
1025b7d26471Smrg        # If we ascended to the root using ".." the result may be empty now.
1026b7d26471Smrg        if test -z "$func_normal_abspath_result"; then
1027b7d26471Smrg          func_normal_abspath_result=/
1028b7d26471Smrg        fi
1029b7d26471Smrg        break
1030b7d26471Smrg      fi
1031b7d26471Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032b7d26471Smrg          -e "$_G_pathcar"`
1033b7d26471Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034b7d26471Smrg          -e "$_G_pathcdr"`
1035b7d26471Smrg      # Figure out what to do with it
1036b7d26471Smrg      case $func_normal_abspath_tcomponent in
1037b7d26471Smrg        "")
1038b7d26471Smrg          # Trailing empty path component, ignore it.
1039b7d26471Smrg          ;;
1040b7d26471Smrg        ..)
1041b7d26471Smrg          # Parent dir; strip last assembled component from result.
1042b7d26471Smrg          func_dirname "$func_normal_abspath_result"
1043b7d26471Smrg          func_normal_abspath_result=$func_dirname_result
1044b7d26471Smrg          ;;
1045b7d26471Smrg        *)
1046b7d26471Smrg          # Actual path component, append it.
1047b7d26471Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048b7d26471Smrg          ;;
1049b7d26471Smrg      esac
1050b7d26471Smrg    done
1051b7d26471Smrg    # Restore leading double-slash if one was found on entry.
1052b7d26471Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053b7d26471Smrg}
1054b7d26471Smrg
1055b7d26471Smrg
1056b7d26471Smrg# func_notquiet ARG...
1057b7d26471Smrg# --------------------
1058b7d26471Smrg# Echo program name prefixed message only when not in quiet mode.
1059b7d26471Smrgfunc_notquiet ()
1060b7d26471Smrg{
1061b7d26471Smrg    $debug_cmd
1062b7d26471Smrg
1063b7d26471Smrg    $opt_quiet || func_echo ${1+"$@"}
1064b7d26471Smrg
1065b7d26471Smrg    # A bug in bash halts the script if the last line of a function
1066b7d26471Smrg    # fails when set -e is in force, so we need another command to
1067b7d26471Smrg    # work around that:
1068b7d26471Smrg    :
1069b7d26471Smrg}
1070b7d26471Smrg
1071b7d26471Smrg
1072b7d26471Smrg# func_relative_path SRCDIR DSTDIR
1073b7d26471Smrg# --------------------------------
1074b7d26471Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075b7d26471Smrgfunc_relative_path ()
1076b7d26471Smrg{
1077b7d26471Smrg    $debug_cmd
1078b7d26471Smrg
1079b7d26471Smrg    func_relative_path_result=
1080b7d26471Smrg    func_normal_abspath "$1"
1081b7d26471Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082b7d26471Smrg    func_normal_abspath "$2"
1083b7d26471Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1084b7d26471Smrg
1085b7d26471Smrg    # Ascend the tree starting from libdir
1086b7d26471Smrg    while :; do
1087b7d26471Smrg      # check if we have found a prefix of bindir
1088b7d26471Smrg      case $func_relative_path_tbindir in
1089b7d26471Smrg        $func_relative_path_tlibdir)
1090b7d26471Smrg          # found an exact match
1091b7d26471Smrg          func_relative_path_tcancelled=
1092b7d26471Smrg          break
1093b7d26471Smrg          ;;
1094b7d26471Smrg        $func_relative_path_tlibdir*)
1095b7d26471Smrg          # found a matching prefix
1096b7d26471Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097b7d26471Smrg          func_relative_path_tcancelled=$func_stripname_result
1098b7d26471Smrg          if test -z "$func_relative_path_result"; then
1099b7d26471Smrg            func_relative_path_result=.
1100b7d26471Smrg          fi
1101b7d26471Smrg          break
1102b7d26471Smrg          ;;
1103b7d26471Smrg        *)
1104b7d26471Smrg          func_dirname $func_relative_path_tlibdir
1105b7d26471Smrg          func_relative_path_tlibdir=$func_dirname_result
1106b7d26471Smrg          if test -z "$func_relative_path_tlibdir"; then
1107b7d26471Smrg            # Have to descend all the way to the root!
1108b7d26471Smrg            func_relative_path_result=../$func_relative_path_result
1109b7d26471Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110b7d26471Smrg            break
1111b7d26471Smrg          fi
1112b7d26471Smrg          func_relative_path_result=../$func_relative_path_result
1113b7d26471Smrg          ;;
1114b7d26471Smrg      esac
1115b7d26471Smrg    done
1116b7d26471Smrg
1117b7d26471Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1118b7d26471Smrg    func_stripname '' '/' "$func_relative_path_result"
1119b7d26471Smrg    func_relative_path_result=$func_stripname_result
1120b7d26471Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121b7d26471Smrg    if test -n "$func_stripname_result"; then
1122b7d26471Smrg      func_append func_relative_path_result "/$func_stripname_result"
1123b7d26471Smrg    fi
1124b7d26471Smrg
1125b7d26471Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126b7d26471Smrg    if test -n "$func_relative_path_result"; then
1127b7d26471Smrg      func_stripname './' '' "$func_relative_path_result"
1128b7d26471Smrg      func_relative_path_result=$func_stripname_result
1129b7d26471Smrg    fi
1130b7d26471Smrg
1131b7d26471Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132b7d26471Smrg
1133b7d26471Smrg    :
1134b7d26471Smrg}
1135b7d26471Smrg
1136b7d26471Smrg
1137da2e2ef6Smrg# func_quote_portable EVAL ARG
1138da2e2ef6Smrg# ----------------------------
1139da2e2ef6Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140da2e2ef6Smrg# keep attention to performance here so we as much as possible try to avoid
1141da2e2ef6Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142da2e2ef6Smrgfunc_quote_portable ()
1143145b7b3cSmrg{
1144b7d26471Smrg    $debug_cmd
1145b7d26471Smrg
1146da2e2ef6Smrg    $require_check_ifs_backslash
1147da2e2ef6Smrg
1148da2e2ef6Smrg    func_quote_portable_result=$2
1149da2e2ef6Smrg
1150da2e2ef6Smrg    # one-time-loop (easy break)
1151da2e2ef6Smrg    while true
1152da2e2ef6Smrg    do
1153da2e2ef6Smrg      if $1; then
1154da2e2ef6Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155da2e2ef6Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156da2e2ef6Smrg        break
1157b7d26471Smrg      fi
1158b7d26471Smrg
1159da2e2ef6Smrg      # Quote for eval.
1160da2e2ef6Smrg      case $func_quote_portable_result in
1161da2e2ef6Smrg        *[\\\`\"\$]*)
1162da2e2ef6Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163da2e2ef6Smrg          # contains the shell wildcard characters.
1164da2e2ef6Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165da2e2ef6Smrg            :*|*[\[\*\?]*)
1166da2e2ef6Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167da2e2ef6Smrg                  | $SED "$sed_quote_subst"`
1168da2e2ef6Smrg              break
1169da2e2ef6Smrg              ;;
1170da2e2ef6Smrg          esac
1171da2e2ef6Smrg
1172da2e2ef6Smrg          func_quote_portable_old_IFS=$IFS
1173da2e2ef6Smrg          for _G_char in '\' '`' '"' '$'
1174da2e2ef6Smrg          do
1175da2e2ef6Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176da2e2ef6Smrg            set start "" ""
1177da2e2ef6Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178da2e2ef6Smrg            IFS=$_G_char
1179da2e2ef6Smrg            for _G_part in $func_quote_portable_result
1180da2e2ef6Smrg            do
1181da2e2ef6Smrg              case $1 in
1182da2e2ef6Smrg              quote)
1183da2e2ef6Smrg                func_append func_quote_portable_result "$3$2"
1184da2e2ef6Smrg                set quote "$_G_part" "\\$_G_char"
1185da2e2ef6Smrg                ;;
1186da2e2ef6Smrg              start)
1187da2e2ef6Smrg                set first "" ""
1188da2e2ef6Smrg                func_quote_portable_result=
1189da2e2ef6Smrg                ;;
1190da2e2ef6Smrg              first)
1191da2e2ef6Smrg                set quote "$_G_part" ""
1192da2e2ef6Smrg                ;;
1193da2e2ef6Smrg              esac
1194da2e2ef6Smrg            done
1195da2e2ef6Smrg          done
1196da2e2ef6Smrg          IFS=$func_quote_portable_old_IFS
1197b7d26471Smrg          ;;
1198da2e2ef6Smrg        *) ;;
1199b7d26471Smrg      esac
1200da2e2ef6Smrg      break
1201b7d26471Smrg    done
1202da2e2ef6Smrg
1203da2e2ef6Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204da2e2ef6Smrg    case $func_quote_portable_result in
1205da2e2ef6Smrg      # double-quote args containing shell metacharacters to delay
1206da2e2ef6Smrg      # word splitting, command substitution and variable expansion
1207da2e2ef6Smrg      # for a subsequent eval.
1208da2e2ef6Smrg      # many bourne shells cannot handle close brackets correctly
1209da2e2ef6Smrg      # in scan sets, so we specify it separately.
1210da2e2ef6Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211da2e2ef6Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212da2e2ef6Smrg        ;;
1213da2e2ef6Smrg    esac
1214b7d26471Smrg}
1215b7d26471Smrg
1216b7d26471Smrg
1217da2e2ef6Smrg# func_quotefast_eval ARG
1218da2e2ef6Smrg# -----------------------
1219da2e2ef6Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220da2e2ef6Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221da2e2ef6Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222da2e2ef6Smrg  printf -v _GL_test_printf_tilde %q '~'
1223da2e2ef6Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224da2e2ef6Smrg    func_quotefast_eval ()
1225da2e2ef6Smrg    {
1226da2e2ef6Smrg      printf -v func_quotefast_eval_result %q "$1"
1227da2e2ef6Smrg    }
1228da2e2ef6Smrg  else
1229da2e2ef6Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230da2e2ef6Smrg    func_quotefast_eval ()
1231da2e2ef6Smrg    {
1232da2e2ef6Smrg      case $1 in
1233da2e2ef6Smrg        '~'*)
1234da2e2ef6Smrg          func_quote_portable false "$1"
1235da2e2ef6Smrg          func_quotefast_eval_result=$func_quote_portable_result
1236da2e2ef6Smrg          ;;
1237da2e2ef6Smrg        *)
1238da2e2ef6Smrg          printf -v func_quotefast_eval_result %q "$1"
1239da2e2ef6Smrg          ;;
1240da2e2ef6Smrg      esac
1241da2e2ef6Smrg    }
1242da2e2ef6Smrg  fi
1243da2e2ef6Smrgelse
1244da2e2ef6Smrg  func_quotefast_eval ()
1245da2e2ef6Smrg  {
1246da2e2ef6Smrg    func_quote_portable false "$1"
1247da2e2ef6Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248da2e2ef6Smrg  }
1249da2e2ef6Smrgfi
1250b7d26471Smrg
1251da2e2ef6Smrg
1252da2e2ef6Smrg# func_quote_arg MODEs ARG
1253da2e2ef6Smrg# ------------------------
1254da2e2ef6Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255da2e2ef6Smrg# specifiers listed below separated by ',' character.  This function returns two
1256da2e2ef6Smrg# values:
1257da2e2ef6Smrg#   i) func_quote_arg_result
1258da2e2ef6Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259da2e2ef6Smrg#  ii) func_quote_arg_unquoted_result
1260da2e2ef6Smrg#      has all characters that are still active within double
1261da2e2ef6Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262da2e2ef6Smrg#
1263da2e2ef6Smrg# Available modes:
1264da2e2ef6Smrg# ----------------
1265da2e2ef6Smrg# 'eval' (default)
1266da2e2ef6Smrg#       - escape shell special characters
1267da2e2ef6Smrg# 'expand'
1268da2e2ef6Smrg#       - the same as 'eval';  but do not quote variable references
1269da2e2ef6Smrg# 'pretty'
1270da2e2ef6Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271da2e2ef6Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272da2e2ef6Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273da2e2ef6Smrg# 'unquoted'
1274da2e2ef6Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275da2e2ef6Smrg#         wrapping double-quotes.
1276da2e2ef6Smrg#
1277da2e2ef6Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278da2e2ef6Smrg#
1279da2e2ef6Smrg#   string      | *_result              | *_unquoted_result
1280da2e2ef6Smrg#   ------------+-----------------------+-------------------
1281da2e2ef6Smrg#   "           | \"                    | \"
1282da2e2ef6Smrg#   a b         | "a b"                 | a b
1283da2e2ef6Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284da2e2ef6Smrg#   *           | "*"                   | *
1285da2e2ef6Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286da2e2ef6Smrg#
1287da2e2ef6Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288da2e2ef6Smrg#
1289da2e2ef6Smrg#   string        |   *_result          |  *_unquoted_result
1290da2e2ef6Smrg#   --------------+---------------------+--------------------
1291da2e2ef6Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292da2e2ef6Smrgfunc_quote_arg ()
1293da2e2ef6Smrg{
1294da2e2ef6Smrg    _G_quote_expand=false
1295da2e2ef6Smrg    case ,$1, in
1296da2e2ef6Smrg      *,expand,*)
1297da2e2ef6Smrg        _G_quote_expand=:
1298da2e2ef6Smrg        ;;
12995ffd6003Smrg    esac
13005ffd6003Smrg
1301da2e2ef6Smrg    case ,$1, in
1302da2e2ef6Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303da2e2ef6Smrg        func_quote_portable $_G_quote_expand "$2"
1304da2e2ef6Smrg        func_quote_arg_result=$func_quote_portable_result
1305da2e2ef6Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306da2e2ef6Smrg        ;;
1307da2e2ef6Smrg      *)
1308da2e2ef6Smrg        # Faster quote-for-eval for some shells.
1309da2e2ef6Smrg        func_quotefast_eval "$2"
1310da2e2ef6Smrg        func_quote_arg_result=$func_quotefast_eval_result
13115ffd6003Smrg        ;;
1312145b7b3cSmrg    esac
1313da2e2ef6Smrg}
1314da2e2ef6Smrg
1315b7d26471Smrg
1316da2e2ef6Smrg# func_quote MODEs ARGs...
1317da2e2ef6Smrg# ------------------------
1318da2e2ef6Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319da2e2ef6Smrg# func_quote_arg's description for more info.
1320da2e2ef6Smrgfunc_quote ()
1321da2e2ef6Smrg{
1322da2e2ef6Smrg    $debug_cmd
1323da2e2ef6Smrg    _G_func_quote_mode=$1 ; shift
1324da2e2ef6Smrg    func_quote_result=
1325da2e2ef6Smrg    while test 0 -lt $#; do
1326da2e2ef6Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327da2e2ef6Smrg      if test -n "$func_quote_result"; then
1328da2e2ef6Smrg        func_append func_quote_result " $func_quote_arg_result"
1329da2e2ef6Smrg      else
1330da2e2ef6Smrg        func_append func_quote_result "$func_quote_arg_result"
1331da2e2ef6Smrg      fi
1332da2e2ef6Smrg      shift
1333da2e2ef6Smrg    done
1334b7d26471Smrg}
1335b7d26471Smrg
1336b7d26471Smrg
1337b7d26471Smrg# func_stripname PREFIX SUFFIX NAME
1338b7d26471Smrg# ---------------------------------
1339b7d26471Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340b7d26471Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1341b7d26471Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342b7d26471Smrg# dot (in which case that matches only a dot).
1343b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344b7d26471Smrg  eval 'func_stripname ()
1345b7d26471Smrg  {
1346b7d26471Smrg    $debug_cmd
1347b7d26471Smrg
1348b7d26471Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349b7d26471Smrg    # positional parameters, so assign one to ordinary variable first.
1350b7d26471Smrg    func_stripname_result=$3
1351b7d26471Smrg    func_stripname_result=${func_stripname_result#"$1"}
1352b7d26471Smrg    func_stripname_result=${func_stripname_result%"$2"}
1353b7d26471Smrg  }'
1354b7d26471Smrgelse
1355b7d26471Smrg  func_stripname ()
1356b7d26471Smrg  {
1357b7d26471Smrg    $debug_cmd
1358b7d26471Smrg
1359b7d26471Smrg    case $2 in
1360b7d26471Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361b7d26471Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362b7d26471Smrg    esac
1363b7d26471Smrg  }
1364b7d26471Smrgfi
1365b7d26471Smrg
1366b7d26471Smrg
1367b7d26471Smrg# func_show_eval CMD [FAIL_EXP]
1368b7d26471Smrg# -----------------------------
1369b7d26471Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370b7d26471Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371b7d26471Smrg# is given, then evaluate it.
1372b7d26471Smrgfunc_show_eval ()
1373b7d26471Smrg{
1374b7d26471Smrg    $debug_cmd
1375b7d26471Smrg
1376b7d26471Smrg    _G_cmd=$1
1377b7d26471Smrg    _G_fail_exp=${2-':'}
1378b7d26471Smrg
1379da2e2ef6Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380da2e2ef6Smrg    eval "func_notquiet $func_quote_arg_result"
1381b7d26471Smrg
1382b7d26471Smrg    $opt_dry_run || {
1383b7d26471Smrg      eval "$_G_cmd"
1384b7d26471Smrg      _G_status=$?
1385b7d26471Smrg      if test 0 -ne "$_G_status"; then
1386b7d26471Smrg	eval "(exit $_G_status); $_G_fail_exp"
1387b7d26471Smrg      fi
1388b7d26471Smrg    }
1389b7d26471Smrg}
1390b7d26471Smrg
1391b7d26471Smrg
1392b7d26471Smrg# func_show_eval_locale CMD [FAIL_EXP]
1393b7d26471Smrg# ------------------------------------
1394b7d26471Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395b7d26471Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396b7d26471Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397b7d26471Smrgfunc_show_eval_locale ()
1398b7d26471Smrg{
1399b7d26471Smrg    $debug_cmd
1400b7d26471Smrg
1401b7d26471Smrg    _G_cmd=$1
1402b7d26471Smrg    _G_fail_exp=${2-':'}
1403b7d26471Smrg
1404b7d26471Smrg    $opt_quiet || {
1405da2e2ef6Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406da2e2ef6Smrg      eval "func_echo $func_quote_arg_result"
1407b7d26471Smrg    }
1408b7d26471Smrg
1409b7d26471Smrg    $opt_dry_run || {
1410b7d26471Smrg      eval "$_G_user_locale
1411b7d26471Smrg	    $_G_cmd"
1412b7d26471Smrg      _G_status=$?
1413b7d26471Smrg      eval "$_G_safe_locale"
1414b7d26471Smrg      if test 0 -ne "$_G_status"; then
1415b7d26471Smrg	eval "(exit $_G_status); $_G_fail_exp"
1416b7d26471Smrg      fi
1417b7d26471Smrg    }
1418b7d26471Smrg}
1419b7d26471Smrg
1420b7d26471Smrg
1421b7d26471Smrg# func_tr_sh
1422b7d26471Smrg# ----------
1423b7d26471Smrg# Turn $1 into a string suitable for a shell variable name.
1424b7d26471Smrg# Result is stored in $func_tr_sh_result.  All characters
1425b7d26471Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426b7d26471Smrg# if $1 begins with a digit, a '_' is prepended as well.
1427b7d26471Smrgfunc_tr_sh ()
1428b7d26471Smrg{
1429b7d26471Smrg    $debug_cmd
1430b7d26471Smrg
1431b7d26471Smrg    case $1 in
1432b7d26471Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433b7d26471Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434b7d26471Smrg      ;;
1435b7d26471Smrg    * )
1436b7d26471Smrg      func_tr_sh_result=$1
1437b7d26471Smrg      ;;
1438b7d26471Smrg    esac
1439b7d26471Smrg}
1440b7d26471Smrg
1441b7d26471Smrg
1442b7d26471Smrg# func_verbose ARG...
1443b7d26471Smrg# -------------------
1444b7d26471Smrg# Echo program name prefixed message in verbose mode only.
1445b7d26471Smrgfunc_verbose ()
1446b7d26471Smrg{
1447b7d26471Smrg    $debug_cmd
1448b7d26471Smrg
1449b7d26471Smrg    $opt_verbose && func_echo "$*"
1450b7d26471Smrg
1451b7d26471Smrg    :
1452b7d26471Smrg}
1453b7d26471Smrg
1454b7d26471Smrg
1455b7d26471Smrg# func_warn_and_continue ARG...
1456b7d26471Smrg# -----------------------------
1457b7d26471Smrg# Echo program name prefixed warning message to standard error.
1458b7d26471Smrgfunc_warn_and_continue ()
1459b7d26471Smrg{
1460b7d26471Smrg    $debug_cmd
1461b7d26471Smrg
1462b7d26471Smrg    $require_term_colors
1463b7d26471Smrg
1464b7d26471Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465b7d26471Smrg}
1466b7d26471Smrg
1467b7d26471Smrg
1468b7d26471Smrg# func_warning CATEGORY ARG...
1469b7d26471Smrg# ----------------------------
1470b7d26471Smrg# Echo program name prefixed warning message to standard error. Warning
1471b7d26471Smrg# messages can be filtered according to CATEGORY, where this function
1472b7d26471Smrg# elides messages where CATEGORY is not listed in the global variable
1473b7d26471Smrg# 'opt_warning_types'.
1474b7d26471Smrgfunc_warning ()
1475b7d26471Smrg{
1476b7d26471Smrg    $debug_cmd
1477b7d26471Smrg
1478b7d26471Smrg    # CATEGORY must be in the warning_categories list!
1479b7d26471Smrg    case " $warning_categories " in
1480b7d26471Smrg      *" $1 "*) ;;
1481b7d26471Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1482b7d26471Smrg    esac
1483b7d26471Smrg
1484b7d26471Smrg    _G_category=$1
1485b7d26471Smrg    shift
1486b7d26471Smrg
1487b7d26471Smrg    case " $opt_warning_types " in
1488b7d26471Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489b7d26471Smrg    esac
1490b7d26471Smrg}
1491b7d26471Smrg
1492b7d26471Smrg
1493b7d26471Smrg# func_sort_ver VER1 VER2
1494b7d26471Smrg# -----------------------
1495b7d26471Smrg# 'sort -V' is not generally available.
1496b7d26471Smrg# Note this deviates from the version comparison in automake
1497b7d26471Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498b7d26471Smrg# but this should suffice as we won't be specifying old
1499b7d26471Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1500b7d26471Smrg# If we did want full compatibility then we should probably
1501b7d26471Smrg# use m4_version_compare from autoconf.
1502b7d26471Smrgfunc_sort_ver ()
1503b7d26471Smrg{
1504b7d26471Smrg    $debug_cmd
1505b7d26471Smrg
1506b7d26471Smrg    printf '%s\n%s\n' "$1" "$2" \
1507b7d26471Smrg      | 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
1508b7d26471Smrg}
1509b7d26471Smrg
1510b7d26471Smrg# func_lt_ver PREV CURR
1511b7d26471Smrg# ---------------------
1512b7d26471Smrg# Return true if PREV and CURR are in the correct order according to
1513b7d26471Smrg# func_sort_ver, otherwise false.  Use it like this:
1514b7d26471Smrg#
1515b7d26471Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516b7d26471Smrgfunc_lt_ver ()
1517b7d26471Smrg{
1518b7d26471Smrg    $debug_cmd
1519b7d26471Smrg
1520b7d26471Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521b7d26471Smrg}
1522b7d26471Smrg
1523b7d26471Smrg
1524b7d26471Smrg# Local variables:
1525b7d26471Smrg# mode: shell-script
1526b7d26471Smrg# sh-indentation: 2
1527b7d26471Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528b7d26471Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529b7d26471Smrg# time-stamp-time-zone: "UTC"
1530b7d26471Smrg# End:
1531b7d26471Smrg#! /bin/sh
1532b7d26471Smrg
1533b7d26471Smrg# A portable, pluggable option parser for Bourne shell.
1534b7d26471Smrg# Written by Gary V. Vaughan, 2010
1535b7d26471Smrg
1536da2e2ef6Smrg# This is free software.  There is NO warranty; not even for
1537da2e2ef6Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538da2e2ef6Smrg#
1539da2e2ef6Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540da2e2ef6Smrg#
1541da2e2ef6Smrg# This file is dual licensed under the terms of the MIT license
1542da2e2ef6Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543da2e2ef6Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544da2e2ef6Smrg# these licenses when using or redistributing this software or any of
1545da2e2ef6Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546da2e2ef6Smrg# included in the Bootstrap distribution for the full license texts.
1547b7d26471Smrg
1548da2e2ef6Smrg# Please report bugs or propose patches to:
1549da2e2ef6Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550b7d26471Smrg
1551da2e2ef6Smrg# Set a version string for this script.
1552da2e2ef6Smrgscriptversion=2019-02-19.15; # UTC
1553b7d26471Smrg
1554b7d26471Smrg
1555b7d26471Smrg## ------ ##
1556b7d26471Smrg## Usage. ##
1557b7d26471Smrg## ------ ##
1558b7d26471Smrg
1559b7d26471Smrg# This file is a library for parsing options in your shell scripts along
1560b7d26471Smrg# with assorted other useful supporting features that you can make use
1561b7d26471Smrg# of too.
1562b7d26471Smrg#
1563b7d26471Smrg# For the simplest scripts you might need only:
1564b7d26471Smrg#
1565b7d26471Smrg#   #!/bin/sh
1566b7d26471Smrg#   . relative/path/to/funclib.sh
1567b7d26471Smrg#   . relative/path/to/options-parser
1568b7d26471Smrg#   scriptversion=1.0
1569b7d26471Smrg#   func_options ${1+"$@"}
1570b7d26471Smrg#   eval set dummy "$func_options_result"; shift
1571b7d26471Smrg#   ...rest of your script...
1572b7d26471Smrg#
1573b7d26471Smrg# In order for the '--version' option to work, you will need to have a
1574b7d26471Smrg# suitably formatted comment like the one at the top of this file
1575da2e2ef6Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576b7d26471Smrg#
1577b7d26471Smrg# For '-h' and '--help' to work, you will also need a one line
1578b7d26471Smrg# description of your script's purpose in a comment directly above the
1579b7d26471Smrg# '# Written by ' line, like the one at the top of this file.
1580b7d26471Smrg#
1581b7d26471Smrg# The default options also support '--debug', which will turn on shell
1582b7d26471Smrg# execution tracing (see the comment above debug_cmd below for another
1583b7d26471Smrg# use), and '--verbose' and the func_verbose function to allow your script
1584b7d26471Smrg# to display verbose messages only when your user has specified
1585b7d26471Smrg# '--verbose'.
1586b7d26471Smrg#
1587da2e2ef6Smrg# After sourcing this file, you can plug in processing for additional
1588b7d26471Smrg# options by amending the variables from the 'Configuration' section
1589b7d26471Smrg# below, and following the instructions in the 'Option parsing'
1590b7d26471Smrg# section further down.
1591b7d26471Smrg
1592b7d26471Smrg## -------------- ##
1593b7d26471Smrg## Configuration. ##
1594b7d26471Smrg## -------------- ##
1595b7d26471Smrg
1596b7d26471Smrg# You should override these variables in your script after sourcing this
1597b7d26471Smrg# file so that they reflect the customisations you have added to the
1598b7d26471Smrg# option parser.
1599b7d26471Smrg
1600b7d26471Smrg# The usage line for option parsing errors and the start of '-h' and
1601b7d26471Smrg# '--help' output messages. You can embed shell variables for delayed
1602b7d26471Smrg# expansion at the time the message is displayed, but you will need to
1603b7d26471Smrg# quote other shell meta-characters carefully to prevent them being
1604b7d26471Smrg# expanded when the contents are evaled.
1605b7d26471Smrgusage='$progpath [OPTION]...'
1606b7d26471Smrg
1607b7d26471Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1608b7d26471Smrg# override it after sourcing this library to reflect the full set of
1609b7d26471Smrg# options your script accepts.
1610b7d26471Smrgusage_message="\
1611b7d26471Smrg       --debug        enable verbose shell tracing
1612b7d26471Smrg   -W, --warnings=CATEGORY
1613b7d26471Smrg                      report the warnings falling in CATEGORY [all]
1614b7d26471Smrg   -v, --verbose      verbosely report processing
1615b7d26471Smrg       --version      print version information and exit
1616b7d26471Smrg   -h, --help         print short or long help message and exit
1617b7d26471Smrg"
1618b7d26471Smrg
1619b7d26471Smrg# Additional text appended to 'usage_message' in response to '--help'.
1620b7d26471Smrglong_help_message="
1621b7d26471SmrgWarning categories include:
1622b7d26471Smrg       'all'          show all warnings
1623b7d26471Smrg       'none'         turn off all the warnings
1624b7d26471Smrg       'error'        warnings are treated as fatal errors"
1625b7d26471Smrg
1626b7d26471Smrg# Help message printed before fatal option parsing errors.
1627b7d26471Smrgfatal_help="Try '\$progname --help' for more information."
1628b7d26471Smrg
1629b7d26471Smrg
1630b7d26471Smrg
1631b7d26471Smrg## ------------------------- ##
1632b7d26471Smrg## Hook function management. ##
1633b7d26471Smrg## ------------------------- ##
1634b7d26471Smrg
1635b7d26471Smrg# This section contains functions for adding, removing, and running hooks
1636da2e2ef6Smrg# in the main code.  A hook is just a list of function names that can be
1637da2e2ef6Smrg# run in order later on.
1638b7d26471Smrg
1639b7d26471Smrg# func_hookable FUNC_NAME
1640b7d26471Smrg# -----------------------
1641b7d26471Smrg# Declare that FUNC_NAME will run hooks added with
1642b7d26471Smrg# 'func_add_hook FUNC_NAME ...'.
1643b7d26471Smrgfunc_hookable ()
1644b7d26471Smrg{
1645b7d26471Smrg    $debug_cmd
1646b7d26471Smrg
1647b7d26471Smrg    func_append hookable_fns " $1"
1648b7d26471Smrg}
1649b7d26471Smrg
1650b7d26471Smrg
1651b7d26471Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1652b7d26471Smrg# ---------------------------------
1653b7d26471Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654b7d26471Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1655b7d26471Smrgfunc_add_hook ()
1656b7d26471Smrg{
1657b7d26471Smrg    $debug_cmd
1658b7d26471Smrg
1659b7d26471Smrg    case " $hookable_fns " in
1660b7d26471Smrg      *" $1 "*) ;;
1661b7d26471Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662b7d26471Smrg    esac
1663b7d26471Smrg
1664b7d26471Smrg    eval func_append ${1}_hooks '" $2"'
1665b7d26471Smrg}
1666b7d26471Smrg
1667b7d26471Smrg
1668b7d26471Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669b7d26471Smrg# ------------------------------------
1670da2e2ef6Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671da2e2ef6Smrg# FUNC_NAME.
1672b7d26471Smrgfunc_remove_hook ()
1673b7d26471Smrg{
1674b7d26471Smrg    $debug_cmd
1675b7d26471Smrg
1676b7d26471Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677b7d26471Smrg}
1678b7d26471Smrg
1679b7d26471Smrg
1680da2e2ef6Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681da2e2ef6Smrg# ---------------------------------------------
1682da2e2ef6Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683da2e2ef6Smrg# *_result variable of FUNC_NAME_B.
1684da2e2ef6Smrgfunc_propagate_result ()
1685da2e2ef6Smrg{
1686da2e2ef6Smrg    $debug_cmd
1687da2e2ef6Smrg
1688da2e2ef6Smrg    func_propagate_result_result=:
1689da2e2ef6Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690da2e2ef6Smrg    then
1691da2e2ef6Smrg      eval "${2}_result=\$${1}_result"
1692da2e2ef6Smrg    else
1693da2e2ef6Smrg      func_propagate_result_result=false
1694da2e2ef6Smrg    fi
1695da2e2ef6Smrg}
1696da2e2ef6Smrg
1697da2e2ef6Smrg
1698b7d26471Smrg# func_run_hooks FUNC_NAME [ARG]...
1699b7d26471Smrg# ---------------------------------
1700b7d26471Smrg# Run all hook functions registered to FUNC_NAME.
1701da2e2ef6Smrg# It's assumed that the list of hook functions contains nothing more
1702b7d26471Smrg# than a whitespace-delimited list of legal shell function names, and
1703b7d26471Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1704b7d26471Smrg# whitespace.
1705b7d26471Smrgfunc_run_hooks ()
1706b7d26471Smrg{
1707b7d26471Smrg    $debug_cmd
1708b7d26471Smrg
1709b7d26471Smrg    case " $hookable_fns " in
1710b7d26471Smrg      *" $1 "*) ;;
1711da2e2ef6Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712b7d26471Smrg    esac
1713b7d26471Smrg
1714b7d26471Smrg    eval _G_hook_fns=\$$1_hooks; shift
1715b7d26471Smrg
1716b7d26471Smrg    for _G_hook in $_G_hook_fns; do
1717da2e2ef6Smrg      func_unset "${_G_hook}_result"
1718da2e2ef6Smrg      eval $_G_hook '${1+"$@"}'
1719da2e2ef6Smrg      func_propagate_result $_G_hook func_run_hooks
1720da2e2ef6Smrg      if $func_propagate_result_result; then
1721da2e2ef6Smrg        eval set dummy "$func_run_hooks_result"; shift
1722da2e2ef6Smrg      fi
1723b7d26471Smrg    done
1724b7d26471Smrg}
1725b7d26471Smrg
1726b7d26471Smrg
1727b7d26471Smrg
1728b7d26471Smrg## --------------- ##
1729b7d26471Smrg## Option parsing. ##
1730b7d26471Smrg## --------------- ##
1731b7d26471Smrg
1732b7d26471Smrg# In order to add your own option parsing hooks, you must accept the
1733da2e2ef6Smrg# full positional parameter list from your hook function.  You may remove
1734da2e2ef6Smrg# or edit any options that you action, and then pass back the remaining
1735da2e2ef6Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736da2e2ef6Smrg# suitably for 'eval'.
1737da2e2ef6Smrg#
1738da2e2ef6Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739da2e2ef6Smrg# before your hook gets called; for best performance, only set the
1740da2e2ef6Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741da2e2ef6Smrg# function unnecessarily because it can be an expensive operation on some
1742da2e2ef6Smrg# machines).
1743da2e2ef6Smrg#
1744da2e2ef6Smrg# Like this:
1745b7d26471Smrg#
1746b7d26471Smrg#    my_options_prep ()
1747b7d26471Smrg#    {
1748b7d26471Smrg#        $debug_cmd
1749b7d26471Smrg#
1750b7d26471Smrg#        # Extend the existing usage message.
1751b7d26471Smrg#        usage_message=$usage_message'
1752b7d26471Smrg#      -s, --silent       don'\''t print informational messages
1753b7d26471Smrg#    '
1754da2e2ef6Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755da2e2ef6Smrg#        # my_options_prep_result variable intact.
1756b7d26471Smrg#    }
1757b7d26471Smrg#    func_add_hook func_options_prep my_options_prep
1758b7d26471Smrg#
1759b7d26471Smrg#
1760b7d26471Smrg#    my_silent_option ()
1761b7d26471Smrg#    {
1762b7d26471Smrg#        $debug_cmd
1763b7d26471Smrg#
1764da2e2ef6Smrg#        args_changed=false
1765da2e2ef6Smrg#
1766da2e2ef6Smrg#        # Note that, for efficiency, we parse as many options as we can
1767b7d26471Smrg#        # recognise in a loop before passing the remainder back to the
1768b7d26471Smrg#        # caller on the first unrecognised argument we encounter.
1769b7d26471Smrg#        while test $# -gt 0; do
1770b7d26471Smrg#          opt=$1; shift
1771b7d26471Smrg#          case $opt in
1772da2e2ef6Smrg#            --silent|-s) opt_silent=:
1773da2e2ef6Smrg#                         args_changed=:
1774da2e2ef6Smrg#                         ;;
1775b7d26471Smrg#            # Separate non-argument short options:
1776b7d26471Smrg#            -s*)         func_split_short_opt "$_G_opt"
1777b7d26471Smrg#                         set dummy "$func_split_short_opt_name" \
1778b7d26471Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779b7d26471Smrg#                         shift
1780da2e2ef6Smrg#                         args_changed=:
1781b7d26471Smrg#                         ;;
1782da2e2ef6Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783da2e2ef6Smrg#                         # is added back to "$@" in case we need it later,
1784da2e2ef6Smrg#                         # if $args_changed was set to 'true'.
1785da2e2ef6Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786b7d26471Smrg#          esac
1787b7d26471Smrg#        done
1788b7d26471Smrg#
1789da2e2ef6Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1790da2e2ef6Smrg#        if $args_changed; then
1791da2e2ef6Smrg#          func_quote eval ${1+"$@"}
1792da2e2ef6Smrg#          my_silent_option_result=$func_quote_result
1793da2e2ef6Smrg#        fi
1794b7d26471Smrg#    }
1795b7d26471Smrg#    func_add_hook func_parse_options my_silent_option
1796b7d26471Smrg#
1797b7d26471Smrg#
1798b7d26471Smrg#    my_option_validation ()
1799b7d26471Smrg#    {
1800b7d26471Smrg#        $debug_cmd
1801b7d26471Smrg#
1802b7d26471Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803b7d26471Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1804b7d26471Smrg#    }
1805b7d26471Smrg#    func_add_hook func_validate_options my_option_validation
1806b7d26471Smrg#
1807da2e2ef6Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808b7d26471Smrg# options you parse.  It's preferable to append if you can, so that
1809b7d26471Smrg# multiple option parsing hooks can be added safely.
1810b7d26471Smrg
1811b7d26471Smrg
1812da2e2ef6Smrg# func_options_finish [ARG]...
1813da2e2ef6Smrg# ----------------------------
1814da2e2ef6Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815da2e2ef6Smrgfunc_options_finish ()
1816da2e2ef6Smrg{
1817da2e2ef6Smrg    $debug_cmd
1818da2e2ef6Smrg
1819da2e2ef6Smrg    func_run_hooks func_options ${1+"$@"}
1820da2e2ef6Smrg    func_propagate_result func_run_hooks func_options_finish
1821da2e2ef6Smrg}
1822da2e2ef6Smrg
1823da2e2ef6Smrg
1824b7d26471Smrg# func_options [ARG]...
1825b7d26471Smrg# ---------------------
1826b7d26471Smrg# All the functions called inside func_options are hookable. See the
1827b7d26471Smrg# individual implementations for details.
1828b7d26471Smrgfunc_hookable func_options
1829b7d26471Smrgfunc_options ()
1830b7d26471Smrg{
1831b7d26471Smrg    $debug_cmd
1832b7d26471Smrg
1833da2e2ef6Smrg    _G_options_quoted=false
1834b7d26471Smrg
1835da2e2ef6Smrg    for my_func in options_prep parse_options validate_options options_finish
1836da2e2ef6Smrg    do
1837da2e2ef6Smrg      func_unset func_${my_func}_result
1838da2e2ef6Smrg      func_unset func_run_hooks_result
1839da2e2ef6Smrg      eval func_$my_func '${1+"$@"}'
1840da2e2ef6Smrg      func_propagate_result func_$my_func func_options
1841da2e2ef6Smrg      if $func_propagate_result_result; then
1842da2e2ef6Smrg        eval set dummy "$func_options_result"; shift
1843da2e2ef6Smrg        _G_options_quoted=:
1844da2e2ef6Smrg      fi
1845da2e2ef6Smrg    done
1846b7d26471Smrg
1847da2e2ef6Smrg    $_G_options_quoted || {
1848da2e2ef6Smrg      # As we (func_options) are top-level options-parser function and
1849da2e2ef6Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850da2e2ef6Smrg      # caller.
1851da2e2ef6Smrg      func_quote eval ${1+"$@"}
1852da2e2ef6Smrg      func_options_result=$func_quote_result
1853da2e2ef6Smrg    }
1854145b7b3cSmrg}
1855145b7b3cSmrg
1856145b7b3cSmrg
1857b7d26471Smrg# func_options_prep [ARG]...
1858b7d26471Smrg# --------------------------
1859b7d26471Smrg# All initialisations required before starting the option parse loop.
1860b7d26471Smrg# Note that when calling hook functions, we pass through the list of
1861b7d26471Smrg# positional parameters.  If a hook function modifies that list, and
1862da2e2ef6Smrg# needs to propagate that back to rest of this script, then the complete
1863da2e2ef6Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864b7d26471Smrgfunc_hookable func_options_prep
1865b7d26471Smrgfunc_options_prep ()
1866145b7b3cSmrg{
1867b7d26471Smrg    $debug_cmd
18685ffd6003Smrg
1869b7d26471Smrg    # Option defaults:
1870b7d26471Smrg    opt_verbose=false
1871b7d26471Smrg    opt_warning_types=
1872b7d26471Smrg
1873b7d26471Smrg    func_run_hooks func_options_prep ${1+"$@"}
1874da2e2ef6Smrg    func_propagate_result func_run_hooks func_options_prep
1875145b7b3cSmrg}
1876145b7b3cSmrg
1877145b7b3cSmrg
1878b7d26471Smrg# func_parse_options [ARG]...
1879b7d26471Smrg# ---------------------------
1880b7d26471Smrg# The main option parsing loop.
1881b7d26471Smrgfunc_hookable func_parse_options
1882b7d26471Smrgfunc_parse_options ()
1883145b7b3cSmrg{
1884b7d26471Smrg    $debug_cmd
1885145b7b3cSmrg
1886da2e2ef6Smrg    _G_parse_options_requote=false
1887b7d26471Smrg    # this just eases exit handling
1888b7d26471Smrg    while test $# -gt 0; do
1889b7d26471Smrg      # Defer to hook functions for initial option parsing, so they
1890b7d26471Smrg      # get priority in the event of reusing an option name.
1891b7d26471Smrg      func_run_hooks func_parse_options ${1+"$@"}
1892da2e2ef6Smrg      func_propagate_result func_run_hooks func_parse_options
1893da2e2ef6Smrg      if $func_propagate_result_result; then
1894da2e2ef6Smrg        eval set dummy "$func_parse_options_result"; shift
1895da2e2ef6Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896da2e2ef6Smrg        # down into the hook and it quoted it for us (because we are in
1897da2e2ef6Smrg        # this if-branch).  No need to quote it again.
1898da2e2ef6Smrg        _G_parse_options_requote=false
1899da2e2ef6Smrg      fi
19005ffd6003Smrg
1901b7d26471Smrg      # Break out of the loop if we already parsed every option.
1902b7d26471Smrg      test $# -gt 0 || break
19035ffd6003Smrg
1904da2e2ef6Smrg      # We expect that one of the options parsed in this function matches
1905da2e2ef6Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906da2e2ef6Smrg      _G_match_parse_options=:
1907b7d26471Smrg      _G_opt=$1
1908b7d26471Smrg      shift
1909b7d26471Smrg      case $_G_opt in
1910b7d26471Smrg        --debug|-x)   debug_cmd='set -x'
1911da2e2ef6Smrg                      func_echo "enabling shell trace mode" >&2
1912b7d26471Smrg                      $debug_cmd
1913b7d26471Smrg                      ;;
1914b7d26471Smrg
1915b7d26471Smrg        --no-warnings|--no-warning|--no-warn)
1916b7d26471Smrg                      set dummy --warnings none ${1+"$@"}
1917b7d26471Smrg                      shift
1918b7d26471Smrg		      ;;
19195ffd6003Smrg
1920b7d26471Smrg        --warnings|--warning|-W)
1921da2e2ef6Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922da2e2ef6Smrg                        _G_parse_options_requote=:
1923da2e2ef6Smrg                        break
1924da2e2ef6Smrg                      fi
1925b7d26471Smrg                      case " $warning_categories $1" in
1926b7d26471Smrg                        *" $1 "*)
1927b7d26471Smrg                          # trailing space prevents matching last $1 above
1928b7d26471Smrg                          func_append_uniq opt_warning_types " $1"
1929b7d26471Smrg                          ;;
1930b7d26471Smrg                        *all)
1931b7d26471Smrg                          opt_warning_types=$warning_categories
1932b7d26471Smrg                          ;;
1933b7d26471Smrg                        *none)
1934b7d26471Smrg                          opt_warning_types=none
1935b7d26471Smrg                          warning_func=:
1936b7d26471Smrg                          ;;
1937b7d26471Smrg                        *error)
1938b7d26471Smrg                          opt_warning_types=$warning_categories
1939b7d26471Smrg                          warning_func=func_fatal_error
1940b7d26471Smrg                          ;;
1941b7d26471Smrg                        *)
1942b7d26471Smrg                          func_fatal_error \
1943b7d26471Smrg                             "unsupported warning category: '$1'"
1944b7d26471Smrg                          ;;
1945b7d26471Smrg                      esac
1946b7d26471Smrg                      shift
1947b7d26471Smrg                      ;;
1948b7d26471Smrg
1949b7d26471Smrg        --verbose|-v) opt_verbose=: ;;
1950b7d26471Smrg        --version)    func_version ;;
1951b7d26471Smrg        -\?|-h)       func_usage ;;
1952b7d26471Smrg        --help)       func_help ;;
1953b7d26471Smrg
1954b7d26471Smrg	# Separate optargs to long options (plugins may need this):
1955b7d26471Smrg	--*=*)        func_split_equals "$_G_opt"
1956b7d26471Smrg	              set dummy "$func_split_equals_lhs" \
1957b7d26471Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1958b7d26471Smrg                      shift
1959b7d26471Smrg                      ;;
1960b7d26471Smrg
1961b7d26471Smrg       # Separate optargs to short options:
1962b7d26471Smrg        -W*)
1963b7d26471Smrg                      func_split_short_opt "$_G_opt"
1964b7d26471Smrg                      set dummy "$func_split_short_opt_name" \
1965b7d26471Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966b7d26471Smrg                      shift
1967b7d26471Smrg                      ;;
1968b7d26471Smrg
1969b7d26471Smrg        # Separate non-argument short options:
1970b7d26471Smrg        -\?*|-h*|-v*|-x*)
1971b7d26471Smrg                      func_split_short_opt "$_G_opt"
1972b7d26471Smrg                      set dummy "$func_split_short_opt_name" \
1973b7d26471Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974b7d26471Smrg                      shift
1975b7d26471Smrg                      ;;
1976b7d26471Smrg
1977da2e2ef6Smrg        --)           _G_parse_options_requote=: ; break ;;
1978b7d26471Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979da2e2ef6Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980da2e2ef6Smrg                      _G_match_parse_options=false
1981da2e2ef6Smrg                      break
1982da2e2ef6Smrg                      ;;
1983b7d26471Smrg      esac
1984da2e2ef6Smrg
1985da2e2ef6Smrg      if $_G_match_parse_options; then
1986da2e2ef6Smrg        _G_parse_options_requote=:
1987da2e2ef6Smrg      fi
1988b7d26471Smrg    done
1989145b7b3cSmrg
1990da2e2ef6Smrg    if $_G_parse_options_requote; then
1991da2e2ef6Smrg      # save modified positional parameters for caller
1992da2e2ef6Smrg      func_quote eval ${1+"$@"}
1993da2e2ef6Smrg      func_parse_options_result=$func_quote_result
1994da2e2ef6Smrg    fi
1995629baa8cSmrg}
19965ffd6003Smrg
19975ffd6003Smrg
1998b7d26471Smrg# func_validate_options [ARG]...
1999b7d26471Smrg# ------------------------------
2000b7d26471Smrg# Perform any sanity checks on option settings and/or unconsumed
2001b7d26471Smrg# arguments.
2002b7d26471Smrgfunc_hookable func_validate_options
2003b7d26471Smrgfunc_validate_options ()
20045ffd6003Smrg{
2005b7d26471Smrg    $debug_cmd
2006629baa8cSmrg
2007b7d26471Smrg    # Display all warnings if -W was not given.
2008b7d26471Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009b7d26471Smrg
2010b7d26471Smrg    func_run_hooks func_validate_options ${1+"$@"}
2011da2e2ef6Smrg    func_propagate_result func_run_hooks func_validate_options
2012b7d26471Smrg
2013b7d26471Smrg    # Bail if the options were screwed!
2014b7d26471Smrg    $exit_cmd $EXIT_FAILURE
20155ffd6003Smrg}
20165ffd6003Smrg
2017b7d26471Smrg
2018b7d26471Smrg
2019b7d26471Smrg## ----------------- ##
2020b7d26471Smrg## Helper functions. ##
2021b7d26471Smrg## ----------------- ##
2022b7d26471Smrg
2023b7d26471Smrg# This section contains the helper functions used by the rest of the
2024b7d26471Smrg# hookable option parser framework in ascii-betical order.
2025b7d26471Smrg
2026b7d26471Smrg
2027b7d26471Smrg# func_fatal_help ARG...
2028b7d26471Smrg# ----------------------
2029b7d26471Smrg# Echo program name prefixed message to standard error, followed by
2030b7d26471Smrg# a help hint, and exit.
2031b7d26471Smrgfunc_fatal_help ()
20325ffd6003Smrg{
2033b7d26471Smrg    $debug_cmd
2034629baa8cSmrg
2035b7d26471Smrg    eval \$ECHO \""Usage: $usage"\"
2036b7d26471Smrg    eval \$ECHO \""$fatal_help"\"
2037b7d26471Smrg    func_error ${1+"$@"}
2038b7d26471Smrg    exit $EXIT_FAILURE
20395ffd6003Smrg}
20405ffd6003Smrg
2041b7d26471Smrg
2042b7d26471Smrg# func_help
2043b7d26471Smrg# ---------
2044b7d26471Smrg# Echo long help message to standard output and exit.
20455ffd6003Smrgfunc_help ()
20465ffd6003Smrg{
2047b7d26471Smrg    $debug_cmd
2048b7d26471Smrg
2049b7d26471Smrg    func_usage_message
2050b7d26471Smrg    $ECHO "$long_help_message"
2051b7d26471Smrg    exit 0
20525ffd6003Smrg}
20535ffd6003Smrg
2054b7d26471Smrg
2055b7d26471Smrg# func_missing_arg ARGNAME
2056b7d26471Smrg# ------------------------
20575ffd6003Smrg# Echo program name prefixed message to standard error and set global
20585ffd6003Smrg# exit_cmd.
20595ffd6003Smrgfunc_missing_arg ()
20605ffd6003Smrg{
2061b7d26471Smrg    $debug_cmd
2062629baa8cSmrg
2063b7d26471Smrg    func_error "Missing argument for '$1'."
20645ffd6003Smrg    exit_cmd=exit
2065145b7b3cSmrg}
2066145b7b3cSmrg
2067145b7b3cSmrg
2068b7d26471Smrg# func_split_equals STRING
2069b7d26471Smrg# ------------------------
2070da2e2ef6Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071da2e2ef6Smrg# after splitting STRING at the '=' sign.
2072b7d26471Smrgtest -z "$_G_HAVE_XSI_OPS" \
2073b7d26471Smrg    && (eval 'x=a/b/c;
2074b7d26471Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075b7d26471Smrg    && _G_HAVE_XSI_OPS=yes
2076b7d26471Smrg
2077b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"
2078b7d26471Smrgthen
2079b7d26471Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2080b7d26471Smrg  eval 'func_split_equals ()
2081b7d26471Smrg  {
2082b7d26471Smrg      $debug_cmd
2083b7d26471Smrg
2084b7d26471Smrg      func_split_equals_lhs=${1%%=*}
2085b7d26471Smrg      func_split_equals_rhs=${1#*=}
2086da2e2ef6Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087da2e2ef6Smrg        func_split_equals_rhs=
2088da2e2ef6Smrg      fi
2089b7d26471Smrg  }'
2090b7d26471Smrgelse
2091b7d26471Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092b7d26471Smrg  func_split_equals ()
2093b7d26471Smrg  {
2094b7d26471Smrg      $debug_cmd
2095b7d26471Smrg
2096b7d26471Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097b7d26471Smrg      func_split_equals_rhs=
2098da2e2ef6Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099b7d26471Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100b7d26471Smrg  }
2101b7d26471Smrgfi #func_split_equals
2102b7d26471Smrg
2103b7d26471Smrg
2104b7d26471Smrg# func_split_short_opt SHORTOPT
2105b7d26471Smrg# -----------------------------
2106629baa8cSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107629baa8cSmrg# variables after splitting SHORTOPT after the 2nd character.
2108b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"
2109b7d26471Smrgthen
2110b7d26471Smrg  # This is an XSI compatible shell, allowing a faster implementation...
2111b7d26471Smrg  eval 'func_split_short_opt ()
2112b7d26471Smrg  {
2113b7d26471Smrg      $debug_cmd
2114b7d26471Smrg
2115b7d26471Smrg      func_split_short_opt_arg=${1#??}
2116b7d26471Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117b7d26471Smrg  }'
2118b7d26471Smrgelse
2119b7d26471Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120b7d26471Smrg  func_split_short_opt ()
2121b7d26471Smrg  {
2122b7d26471Smrg      $debug_cmd
2123b7d26471Smrg
2124da2e2ef6Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125b7d26471Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126b7d26471Smrg  }
2127b7d26471Smrgfi #func_split_short_opt
2128b7d26471Smrg
2129b7d26471Smrg
2130b7d26471Smrg# func_usage
2131b7d26471Smrg# ----------
2132b7d26471Smrg# Echo short help message to standard output and exit.
2133b7d26471Smrgfunc_usage ()
2134629baa8cSmrg{
2135b7d26471Smrg    $debug_cmd
2136629baa8cSmrg
2137b7d26471Smrg    func_usage_message
2138b7d26471Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139b7d26471Smrg    exit 0
2140b7d26471Smrg}
2141145b7b3cSmrg
21425ffd6003Smrg
2143b7d26471Smrg# func_usage_message
2144b7d26471Smrg# ------------------
2145b7d26471Smrg# Echo short help message to standard output.
2146b7d26471Smrgfunc_usage_message ()
2147629baa8cSmrg{
2148b7d26471Smrg    $debug_cmd
2149629baa8cSmrg
2150b7d26471Smrg    eval \$ECHO \""Usage: $usage"\"
2151b7d26471Smrg    echo
2152b7d26471Smrg    $SED -n 's|^# ||
2153b7d26471Smrg        /^Written by/{
2154b7d26471Smrg          x;p;x
2155b7d26471Smrg        }
2156b7d26471Smrg	h
2157b7d26471Smrg	/^Written by/q' < "$progpath"
2158b7d26471Smrg    echo
2159b7d26471Smrg    eval \$ECHO \""$usage_message"\"
2160b7d26471Smrg}
2161629baa8cSmrg
2162629baa8cSmrg
2163b7d26471Smrg# func_version
2164b7d26471Smrg# ------------
2165b7d26471Smrg# Echo version message to standard output and exit.
2166da2e2ef6Smrg# The version message is extracted from the calling file's header
2167da2e2ef6Smrg# comments, with leading '# ' stripped:
2168da2e2ef6Smrg#   1. First display the progname and version
2169da2e2ef6Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170da2e2ef6Smrg#   3. Then a blank line followed by the first following line matching
2171da2e2ef6Smrg#      /^# Copyright /
2172da2e2ef6Smrg#   4. Immediately followed by any lines between the previous matches,
2173da2e2ef6Smrg#      except lines preceding the intervening completely blank line.
2174da2e2ef6Smrg# For example, see the header comments of this file.
2175b7d26471Smrgfunc_version ()
2176b7d26471Smrg{
2177b7d26471Smrg    $debug_cmd
21785ffd6003Smrg
2179b7d26471Smrg    printf '%s\n' "$progname $scriptversion"
2180b7d26471Smrg    $SED -n '
2181da2e2ef6Smrg        /^# Written by /!b
2182da2e2ef6Smrg        s|^# ||; p; n
2183da2e2ef6Smrg
2184da2e2ef6Smrg        :fwd2blnk
2185da2e2ef6Smrg        /./ {
2186da2e2ef6Smrg          n
2187da2e2ef6Smrg          b fwd2blnk
2188b7d26471Smrg        }
2189da2e2ef6Smrg        p; n
2190da2e2ef6Smrg
2191da2e2ef6Smrg        :holdwrnt
2192da2e2ef6Smrg        s|^# ||
2193da2e2ef6Smrg        s|^# *$||
2194da2e2ef6Smrg        /^Copyright /!{
2195da2e2ef6Smrg          /./H
2196da2e2ef6Smrg          n
2197da2e2ef6Smrg          b holdwrnt
2198b7d26471Smrg        }
2199da2e2ef6Smrg
2200da2e2ef6Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201da2e2ef6Smrg        G
2202da2e2ef6Smrg        s|\(\n\)\n*|\1|g
2203da2e2ef6Smrg        p; q' < "$progpath"
22045ffd6003Smrg
2205b7d26471Smrg    exit $?
2206b7d26471Smrg}
2207145b7b3cSmrg
2208145b7b3cSmrg
2209b7d26471Smrg# Local variables:
2210b7d26471Smrg# mode: shell-script
2211b7d26471Smrg# sh-indentation: 2
2212b7d26471Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213da2e2ef6Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214b7d26471Smrg# time-stamp-time-zone: "UTC"
2215b7d26471Smrg# End:
2216145b7b3cSmrg
2217b7d26471Smrg# Set a version string.
2218da2e2ef6Smrgscriptversion='(GNU libtool) 2.4.7'
2219145b7b3cSmrg
22205ffd6003Smrg
2221b7d26471Smrg# func_echo ARG...
2222b7d26471Smrg# ----------------
2223b7d26471Smrg# Libtool also displays the current mode in messages, so override
2224b7d26471Smrg# funclib.sh func_echo with this custom definition.
2225b7d26471Smrgfunc_echo ()
2226629baa8cSmrg{
2227b7d26471Smrg    $debug_cmd
2228629baa8cSmrg
2229b7d26471Smrg    _G_message=$*
2230b7d26471Smrg
2231b7d26471Smrg    func_echo_IFS=$IFS
2232b7d26471Smrg    IFS=$nl
2233b7d26471Smrg    for _G_line in $_G_message; do
2234b7d26471Smrg      IFS=$func_echo_IFS
2235b7d26471Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236b7d26471Smrg    done
2237b7d26471Smrg    IFS=$func_echo_IFS
2238b7d26471Smrg}
2239629baa8cSmrg
2240629baa8cSmrg
2241b7d26471Smrg# func_warning ARG...
2242b7d26471Smrg# -------------------
2243b7d26471Smrg# Libtool warnings are not categorized, so override funclib.sh
2244b7d26471Smrg# func_warning with this simpler definition.
2245b7d26471Smrgfunc_warning ()
2246629baa8cSmrg{
2247b7d26471Smrg    $debug_cmd
2248629baa8cSmrg
2249b7d26471Smrg    $warning_func ${1+"$@"}
2250b7d26471Smrg}
2251629baa8cSmrg
2252629baa8cSmrg
2253b7d26471Smrg## ---------------- ##
2254b7d26471Smrg## Options parsing. ##
2255b7d26471Smrg## ---------------- ##
2256b7d26471Smrg
2257b7d26471Smrg# Hook in the functions to make sure our own options are parsed during
2258b7d26471Smrg# the option parsing loop.
2259b7d26471Smrg
2260b7d26471Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261b7d26471Smrg
2262b7d26471Smrg# Short help message in response to '-h'.
2263b7d26471Smrgusage_message="Options:
2264b7d26471Smrg       --config             show all configuration variables
2265b7d26471Smrg       --debug              enable verbose shell tracing
2266b7d26471Smrg   -n, --dry-run            display commands without modifying any files
2267b7d26471Smrg       --features           display basic configuration information and exit
2268b7d26471Smrg       --mode=MODE          use operation mode MODE
2269b7d26471Smrg       --no-warnings        equivalent to '-Wnone'
2270b7d26471Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271b7d26471Smrg       --quiet, --silent    don't print informational messages
2272b7d26471Smrg       --tag=TAG            use configuration variables from tag TAG
2273b7d26471Smrg   -v, --verbose            print more informational messages than default
2274b7d26471Smrg       --version            print version information
2275b7d26471Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276b7d26471Smrg   -h, --help, --help-all   print short, long, or detailed help message
2277b7d26471Smrg"
2278629baa8cSmrg
2279b7d26471Smrg# Additional text appended to 'usage_message' in response to '--help'.
2280b7d26471Smrgfunc_help ()
2281629baa8cSmrg{
2282b7d26471Smrg    $debug_cmd
2283b7d26471Smrg
2284b7d26471Smrg    func_usage_message
2285b7d26471Smrg    $ECHO "$long_help_message
2286b7d26471Smrg
2287b7d26471SmrgMODE must be one of the following:
2288b7d26471Smrg
2289b7d26471Smrg       clean           remove files from the build directory
2290b7d26471Smrg       compile         compile a source file into a libtool object
2291b7d26471Smrg       execute         automatically set library path, then run a program
2292b7d26471Smrg       finish          complete the installation of libtool libraries
2293b7d26471Smrg       install         install libraries or executables
2294b7d26471Smrg       link            create a library or an executable
2295b7d26471Smrg       uninstall       remove libraries from an installed directory
2296b7d26471Smrg
2297b7d26471SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298b7d26471Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299b7d26471SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300b7d26471Smrg
2301b7d26471SmrgWhen reporting a bug, please describe a test case to reproduce it and
2302b7d26471Smrginclude the following information:
2303b7d26471Smrg
2304b7d26471Smrg       host-triplet:   $host
2305b7d26471Smrg       shell:          $SHELL
2306b7d26471Smrg       compiler:       $LTCC
2307b7d26471Smrg       compiler flags: $LTCFLAGS
2308b7d26471Smrg       linker:         $LD (gnu? $with_gnu_ld)
2309da2e2ef6Smrg       version:        $progname (GNU libtool) 2.4.7
2310b7d26471Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311b7d26471Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312b7d26471Smrg
2313b7d26471SmrgReport bugs to <bug-libtool@gnu.org>.
2314da2e2ef6SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315b7d26471SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316b7d26471Smrg    exit 0
2317b7d26471Smrg}
2318629baa8cSmrg
2319629baa8cSmrg
2320b7d26471Smrg# func_lo2o OBJECT-NAME
2321b7d26471Smrg# ---------------------
2322b7d26471Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323b7d26471Smrg# object suffix.
2324b7d26471Smrg
2325b7d26471Smrglo2o=s/\\.lo\$/.$objext/
2326b7d26471Smrgo2lo=s/\\.$objext\$/.lo/
2327b7d26471Smrg
2328b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329b7d26471Smrg  eval 'func_lo2o ()
2330b7d26471Smrg  {
2331b7d26471Smrg    case $1 in
2332b7d26471Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333b7d26471Smrg      *   ) func_lo2o_result=$1               ;;
2334b7d26471Smrg    esac
2335b7d26471Smrg  }'
2336b7d26471Smrg
2337b7d26471Smrg  # func_xform LIBOBJ-OR-SOURCE
2338b7d26471Smrg  # ---------------------------
2339b7d26471Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340b7d26471Smrg  # suffix to a '.lo' libtool-object suffix.
2341b7d26471Smrg  eval 'func_xform ()
2342b7d26471Smrg  {
2343b7d26471Smrg    func_xform_result=${1%.*}.lo
2344b7d26471Smrg  }'
2345b7d26471Smrgelse
2346b7d26471Smrg  # ...otherwise fall back to using sed.
2347b7d26471Smrg  func_lo2o ()
2348b7d26471Smrg  {
2349b7d26471Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350b7d26471Smrg  }
2351b7d26471Smrg
2352b7d26471Smrg  func_xform ()
2353b7d26471Smrg  {
2354b7d26471Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355b7d26471Smrg  }
2356b7d26471Smrgfi
2357629baa8cSmrg
2358629baa8cSmrg
2359b7d26471Smrg# func_fatal_configuration ARG...
2360b7d26471Smrg# -------------------------------
23615ffd6003Smrg# Echo program name prefixed message to standard error, followed by
23625ffd6003Smrg# a configuration failure hint, and exit.
23635ffd6003Smrgfunc_fatal_configuration ()
23645ffd6003Smrg{
2365da2e2ef6Smrg    func_fatal_error ${1+"$@"} \
2366b7d26471Smrg      "See the $PACKAGE documentation for more information." \
2367b7d26471Smrg      "Fatal configuration error."
23685ffd6003Smrg}
2369145b7b3cSmrg
2370578741aaSmrg
23715ffd6003Smrg# func_config
2372b7d26471Smrg# -----------
23735ffd6003Smrg# Display the configuration for all the tags in this script.
23745ffd6003Smrgfunc_config ()
23755ffd6003Smrg{
23765ffd6003Smrg    re_begincf='^# ### BEGIN LIBTOOL'
23775ffd6003Smrg    re_endcf='^# ### END LIBTOOL'
23785ffd6003Smrg
23795ffd6003Smrg    # Default configuration.
23805ffd6003Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2381145b7b3cSmrg
2382145b7b3cSmrg    # Now print the configurations for the tags.
2383145b7b3cSmrg    for tagname in $taglist; do
23845ffd6003Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2385145b7b3cSmrg    done
2386145b7b3cSmrg
23875ffd6003Smrg    exit $?
23885ffd6003Smrg}
2389145b7b3cSmrg
2390b7d26471Smrg
23915ffd6003Smrg# func_features
2392b7d26471Smrg# -------------
23935ffd6003Smrg# Display the features supported by this script.
23945ffd6003Smrgfunc_features ()
23955ffd6003Smrg{
2396629baa8cSmrg    echo "host: $host"
2397b7d26471Smrg    if test yes = "$build_libtool_libs"; then
2398629baa8cSmrg      echo "enable shared libraries"
2399145b7b3cSmrg    else
2400629baa8cSmrg      echo "disable shared libraries"
2401145b7b3cSmrg    fi
2402b7d26471Smrg    if test yes = "$build_old_libs"; then
2403629baa8cSmrg      echo "enable static libraries"
2404145b7b3cSmrg    else
2405629baa8cSmrg      echo "disable static libraries"
2406145b7b3cSmrg    fi
24075ffd6003Smrg
2408145b7b3cSmrg    exit $?
24095ffd6003Smrg}
2410145b7b3cSmrg
2411b7d26471Smrg
2412b7d26471Smrg# func_enable_tag TAGNAME
2413b7d26471Smrg# -----------------------
24145ffd6003Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
24155ffd6003Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
24165ffd6003Smrg# variable here.
24175ffd6003Smrgfunc_enable_tag ()
24185ffd6003Smrg{
2419b7d26471Smrg    # Global variable:
2420b7d26471Smrg    tagname=$1
2421145b7b3cSmrg
2422b7d26471Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423b7d26471Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424b7d26471Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2425145b7b3cSmrg
2426b7d26471Smrg    # Validate tagname.
2427b7d26471Smrg    case $tagname in
2428b7d26471Smrg      *[!-_A-Za-z0-9,/]*)
2429b7d26471Smrg        func_fatal_error "invalid tag name: $tagname"
2430b7d26471Smrg        ;;
2431b7d26471Smrg    esac
2432145b7b3cSmrg
2433b7d26471Smrg    # Don't test for the "default" C tag, as we know it's
2434b7d26471Smrg    # there but not specially marked.
2435b7d26471Smrg    case $tagname in
2436b7d26471Smrg        CC) ;;
24375ffd6003Smrg    *)
2438b7d26471Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439b7d26471Smrg	  taglist="$taglist $tagname"
2440b7d26471Smrg
2441b7d26471Smrg	  # Evaluate the configuration.  Be careful to quote the path
2442b7d26471Smrg	  # and the sed script, to avoid splitting on whitespace, but
2443b7d26471Smrg	  # also don't use non-portable quotes within backquotes within
2444b7d26471Smrg	  # quotes we have to do it in 2 steps:
2445b7d26471Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446b7d26471Smrg	  eval "$extractedcf"
2447b7d26471Smrg        else
2448b7d26471Smrg	  func_error "ignoring unknown tag $tagname"
2449b7d26471Smrg        fi
2450b7d26471Smrg        ;;
2451b7d26471Smrg    esac
24525ffd6003Smrg}
24535ffd6003Smrg
2454b7d26471Smrg
2455629baa8cSmrg# func_check_version_match
2456b7d26471Smrg# ------------------------
2457629baa8cSmrg# Ensure that we are using m4 macros, and libtool script from the same
2458629baa8cSmrg# release of libtool.
2459629baa8cSmrgfunc_check_version_match ()
24605ffd6003Smrg{
2461b7d26471Smrg    if test "$package_revision" != "$macro_revision"; then
2462b7d26471Smrg      if test "$VERSION" != "$macro_version"; then
2463b7d26471Smrg        if test -z "$macro_version"; then
2464b7d26471Smrg          cat >&2 <<_LT_EOF
2465629baa8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466629baa8cSmrg$progname: definition of this LT_INIT comes from an older release.
2467629baa8cSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468629baa8cSmrg$progname: and run autoconf again.
2469629baa8cSmrg_LT_EOF
2470b7d26471Smrg        else
2471b7d26471Smrg          cat >&2 <<_LT_EOF
2472629baa8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473629baa8cSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474629baa8cSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475629baa8cSmrg$progname: and run autoconf again.
2476629baa8cSmrg_LT_EOF
2477b7d26471Smrg        fi
2478b7d26471Smrg      else
2479b7d26471Smrg        cat >&2 <<_LT_EOF
2480629baa8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481629baa8cSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482629baa8cSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483629baa8cSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484629baa8cSmrg_LT_EOF
2485b7d26471Smrg      fi
2486629baa8cSmrg
2487b7d26471Smrg      exit $EXIT_MISMATCH
2488b7d26471Smrg    fi
2489629baa8cSmrg}
2490629baa8cSmrg
2491629baa8cSmrg
2492b7d26471Smrg# libtool_options_prep [ARG]...
2493b7d26471Smrg# -----------------------------
2494b7d26471Smrg# Preparation for options parsed by libtool.
2495b7d26471Smrglibtool_options_prep ()
2496b7d26471Smrg{
2497b7d26471Smrg    $debug_mode
2498145b7b3cSmrg
2499b7d26471Smrg    # Option defaults:
2500b7d26471Smrg    opt_config=false
2501b7d26471Smrg    opt_dlopen=
2502b7d26471Smrg    opt_dry_run=false
2503b7d26471Smrg    opt_help=false
2504b7d26471Smrg    opt_mode=
2505b7d26471Smrg    opt_preserve_dup_deps=false
2506b7d26471Smrg    opt_quiet=false
2507145b7b3cSmrg
2508b7d26471Smrg    nonopt=
2509b7d26471Smrg    preserve_args=
2510629baa8cSmrg
2511da2e2ef6Smrg    _G_rc_lt_options_prep=:
2512da2e2ef6Smrg
2513b7d26471Smrg    # Shorthand for --mode=foo, only valid as the first argument
2514b7d26471Smrg    case $1 in
2515b7d26471Smrg    clean|clea|cle|cl)
2516b7d26471Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517b7d26471Smrg      ;;
2518b7d26471Smrg    compile|compil|compi|comp|com|co|c)
2519b7d26471Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520b7d26471Smrg      ;;
2521b7d26471Smrg    execute|execut|execu|exec|exe|ex|e)
2522b7d26471Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523b7d26471Smrg      ;;
2524b7d26471Smrg    finish|finis|fini|fin|fi|f)
2525b7d26471Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526b7d26471Smrg      ;;
2527b7d26471Smrg    install|instal|insta|inst|ins|in|i)
2528b7d26471Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2529b7d26471Smrg      ;;
2530b7d26471Smrg    link|lin|li|l)
2531b7d26471Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2532b7d26471Smrg      ;;
2533b7d26471Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534b7d26471Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535b7d26471Smrg      ;;
2536da2e2ef6Smrg    *)
2537da2e2ef6Smrg      _G_rc_lt_options_prep=false
2538da2e2ef6Smrg      ;;
2539b7d26471Smrg    esac
2540b7d26471Smrg
2541da2e2ef6Smrg    if $_G_rc_lt_options_prep; then
2542da2e2ef6Smrg      # Pass back the list of options.
2543da2e2ef6Smrg      func_quote eval ${1+"$@"}
2544da2e2ef6Smrg      libtool_options_prep_result=$func_quote_result
2545da2e2ef6Smrg    fi
2546b7d26471Smrg}
2547b7d26471Smrgfunc_add_hook func_options_prep libtool_options_prep
2548629baa8cSmrg
2549629baa8cSmrg
2550b7d26471Smrg# libtool_parse_options [ARG]...
2551b7d26471Smrg# ---------------------------------
2552b7d26471Smrg# Provide handling for libtool specific options.
2553b7d26471Smrglibtool_parse_options ()
2554629baa8cSmrg{
2555b7d26471Smrg    $debug_cmd
25565ffd6003Smrg
2557da2e2ef6Smrg    _G_rc_lt_parse_options=false
2558da2e2ef6Smrg
2559b7d26471Smrg    # Perform our own loop to consume as many options as possible in
2560b7d26471Smrg    # each iteration.
2561b7d26471Smrg    while test $# -gt 0; do
2562da2e2ef6Smrg      _G_match_lt_parse_options=:
2563b7d26471Smrg      _G_opt=$1
2564b7d26471Smrg      shift
2565b7d26471Smrg      case $_G_opt in
2566b7d26471Smrg        --dry-run|--dryrun|-n)
2567b7d26471Smrg                        opt_dry_run=:
2568b7d26471Smrg                        ;;
2569b7d26471Smrg
2570b7d26471Smrg        --config)       func_config ;;
2571b7d26471Smrg
2572b7d26471Smrg        --dlopen|-dlopen)
2573b7d26471Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574b7d26471Smrg}$1"
2575b7d26471Smrg                        shift
2576b7d26471Smrg                        ;;
2577b7d26471Smrg
2578b7d26471Smrg        --preserve-dup-deps)
2579b7d26471Smrg                        opt_preserve_dup_deps=: ;;
2580b7d26471Smrg
2581b7d26471Smrg        --features)     func_features ;;
2582b7d26471Smrg
2583b7d26471Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584b7d26471Smrg
2585b7d26471Smrg        --help)         opt_help=: ;;
2586b7d26471Smrg
2587b7d26471Smrg        --help-all)     opt_help=': help-all' ;;
2588b7d26471Smrg
2589b7d26471Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590b7d26471Smrg                        opt_mode=$1
2591b7d26471Smrg                        case $1 in
2592b7d26471Smrg                          # Valid mode arguments:
2593b7d26471Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594b7d26471Smrg
2595b7d26471Smrg                          # Catch anything else as an error
2596b7d26471Smrg                          *) func_error "invalid argument for $_G_opt"
2597b7d26471Smrg                             exit_cmd=exit
2598b7d26471Smrg                             break
2599b7d26471Smrg                             ;;
2600b7d26471Smrg                        esac
2601b7d26471Smrg                        shift
2602b7d26471Smrg                        ;;
2603b7d26471Smrg
2604b7d26471Smrg        --no-silent|--no-quiet)
2605b7d26471Smrg                        opt_quiet=false
2606b7d26471Smrg                        func_append preserve_args " $_G_opt"
2607b7d26471Smrg                        ;;
2608b7d26471Smrg
2609b7d26471Smrg        --no-warnings|--no-warning|--no-warn)
2610b7d26471Smrg                        opt_warning=false
2611b7d26471Smrg                        func_append preserve_args " $_G_opt"
2612b7d26471Smrg                        ;;
2613b7d26471Smrg
2614b7d26471Smrg        --no-verbose)
2615b7d26471Smrg                        opt_verbose=false
2616b7d26471Smrg                        func_append preserve_args " $_G_opt"
2617b7d26471Smrg                        ;;
2618b7d26471Smrg
2619b7d26471Smrg        --silent|--quiet)
2620b7d26471Smrg                        opt_quiet=:
2621b7d26471Smrg                        opt_verbose=false
2622b7d26471Smrg                        func_append preserve_args " $_G_opt"
2623b7d26471Smrg                        ;;
2624b7d26471Smrg
2625b7d26471Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626b7d26471Smrg                        opt_tag=$1
2627b7d26471Smrg                        func_append preserve_args " $_G_opt $1"
2628b7d26471Smrg                        func_enable_tag "$1"
2629b7d26471Smrg                        shift
2630b7d26471Smrg                        ;;
2631b7d26471Smrg
2632b7d26471Smrg        --verbose|-v)   opt_quiet=false
2633b7d26471Smrg                        opt_verbose=:
2634b7d26471Smrg                        func_append preserve_args " $_G_opt"
2635b7d26471Smrg                        ;;
2636b7d26471Smrg
2637da2e2ef6Smrg        # An option not handled by this hook function:
2638da2e2ef6Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2639da2e2ef6Smrg                        _G_match_lt_parse_options=false
2640da2e2ef6Smrg                        break
2641da2e2ef6Smrg                        ;;
2642b7d26471Smrg      esac
2643da2e2ef6Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644b7d26471Smrg    done
2645629baa8cSmrg
2646da2e2ef6Smrg    if $_G_rc_lt_parse_options; then
2647da2e2ef6Smrg      # save modified positional parameters for caller
2648da2e2ef6Smrg      func_quote eval ${1+"$@"}
2649da2e2ef6Smrg      libtool_parse_options_result=$func_quote_result
2650da2e2ef6Smrg    fi
2651b7d26471Smrg}
2652b7d26471Smrgfunc_add_hook func_parse_options libtool_parse_options
26535ffd6003Smrg
2654145b7b3cSmrg
26555ffd6003Smrg
2656b7d26471Smrg# libtool_validate_options [ARG]...
2657b7d26471Smrg# ---------------------------------
2658b7d26471Smrg# Perform any sanity checks on option settings and/or unconsumed
2659b7d26471Smrg# arguments.
2660b7d26471Smrglibtool_validate_options ()
2661b7d26471Smrg{
2662b7d26471Smrg    # save first non-option argument
2663b7d26471Smrg    if test 0 -lt $#; then
2664b7d26471Smrg      nonopt=$1
2665b7d26471Smrg      shift
26665ffd6003Smrg    fi
26675ffd6003Smrg
2668b7d26471Smrg    # preserve --debug
2669b7d26471Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
26705ffd6003Smrg
2671b7d26471Smrg    case $host in
2672b7d26471Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673b7d26471Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674b7d26471Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675b7d26471Smrg        # don't eliminate duplications in $postdeps and $predeps
2676b7d26471Smrg        opt_duplicate_compiler_generated_deps=:
2677b7d26471Smrg        ;;
2678b7d26471Smrg      *)
2679b7d26471Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680b7d26471Smrg        ;;
2681b7d26471Smrg    esac
2682145b7b3cSmrg
2683b7d26471Smrg    $opt_help || {
2684b7d26471Smrg      # Sanity checks first:
2685b7d26471Smrg      func_check_version_match
2686b7d26471Smrg
2687b7d26471Smrg      test yes != "$build_libtool_libs" \
2688b7d26471Smrg        && test yes != "$build_old_libs" \
2689b7d26471Smrg        && func_fatal_configuration "not configured to build any kind of library"
26905ffd6003Smrg
2691b7d26471Smrg      # Darwin sucks
2692b7d26471Smrg      eval std_shrext=\"$shrext_cmds\"
26935ffd6003Smrg
2694b7d26471Smrg      # Only execute mode is allowed to have -dlopen flags.
2695b7d26471Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696b7d26471Smrg        func_error "unrecognized option '-dlopen'"
2697b7d26471Smrg        $ECHO "$help" 1>&2
2698b7d26471Smrg        exit $EXIT_FAILURE
2699b7d26471Smrg      fi
2700b7d26471Smrg
2701b7d26471Smrg      # Change the help message to a mode-specific one.
2702b7d26471Smrg      generic_help=$help
2703b7d26471Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704b7d26471Smrg    }
2705b7d26471Smrg
2706b7d26471Smrg    # Pass back the unparsed argument list
2707da2e2ef6Smrg    func_quote eval ${1+"$@"}
2708da2e2ef6Smrg    libtool_validate_options_result=$func_quote_result
2709629baa8cSmrg}
2710b7d26471Smrgfunc_add_hook func_validate_options libtool_validate_options
27115ffd6003Smrg
27125ffd6003Smrg
2713b7d26471Smrg# Process options as early as possible so that --help and --version
2714b7d26471Smrg# can return quickly.
2715b7d26471Smrgfunc_options ${1+"$@"}
2716b7d26471Smrgeval set dummy "$func_options_result"; shift
2717b7d26471Smrg
2718145b7b3cSmrg
2719145b7b3cSmrg
2720629baa8cSmrg## ----------- ##
2721629baa8cSmrg##    Main.    ##
2722629baa8cSmrg## ----------- ##
2723145b7b3cSmrg
2724b7d26471Smrgmagic='%%%MAGIC variable%%%'
2725b7d26471Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2726b7d26471Smrg
2727b7d26471Smrg# Global variables.
2728b7d26471Smrgextracted_archives=
2729b7d26471Smrgextracted_serial=0
2730b7d26471Smrg
2731b7d26471Smrg# If this variable is set in any of the actions, the command in it
2732b7d26471Smrg# will be execed at the end.  This prevents here-documents from being
2733b7d26471Smrg# left over by shells.
2734b7d26471Smrgexec_cmd=
2735b7d26471Smrg
2736b7d26471Smrg
2737b7d26471Smrg# A function that is used when there is no print builtin or printf.
2738b7d26471Smrgfunc_fallback_echo ()
2739b7d26471Smrg{
2740b7d26471Smrg  eval 'cat <<_LTECHO_EOF
2741b7d26471Smrg$1
2742b7d26471Smrg_LTECHO_EOF'
2743b7d26471Smrg}
2744b7d26471Smrg
2745b7d26471Smrg# func_generated_by_libtool
2746b7d26471Smrg# True iff stdin has been generated by Libtool. This function is only
2747b7d26471Smrg# a basic sanity check; it will hardly flush out determined imposters.
2748b7d26471Smrgfunc_generated_by_libtool_p ()
2749b7d26471Smrg{
2750b7d26471Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751b7d26471Smrg}
2752b7d26471Smrg
27535ffd6003Smrg# func_lalib_p file
2754b7d26471Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27555ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
27565ffd6003Smrg# determined imposters.
27575ffd6003Smrgfunc_lalib_p ()
27585ffd6003Smrg{
27595ffd6003Smrg    test -f "$1" &&
2760b7d26471Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
27615ffd6003Smrg}
2762145b7b3cSmrg
27635ffd6003Smrg# func_lalib_unsafe_p file
2764b7d26471Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
27655ffd6003Smrg# This function implements the same check as func_lalib_p without
27665ffd6003Smrg# resorting to external programs.  To this end, it redirects stdin and
27675ffd6003Smrg# closes it afterwards, without saving the original file descriptor.
27685ffd6003Smrg# As a safety measure, use it only where a negative result would be
2769b7d26471Smrg# fatal anyway.  Works if 'file' does not exist.
27705ffd6003Smrgfunc_lalib_unsafe_p ()
27715ffd6003Smrg{
27725ffd6003Smrg    lalib_p=no
27735ffd6003Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
27745ffd6003Smrg	for lalib_p_l in 1 2 3 4
27755ffd6003Smrg	do
27765ffd6003Smrg	    read lalib_p_line
2777b7d26471Smrg	    case $lalib_p_line in
27785ffd6003Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
27795ffd6003Smrg	    esac
27805ffd6003Smrg	done
27815ffd6003Smrg	exec 0<&5 5<&-
27825ffd6003Smrg    fi
2783b7d26471Smrg    test yes = "$lalib_p"
27845ffd6003Smrg}
2785145b7b3cSmrg
27865ffd6003Smrg# func_ltwrapper_script_p file
27875ffd6003Smrg# True iff FILE is a libtool wrapper script
27885ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
27895ffd6003Smrg# determined imposters.
27905ffd6003Smrgfunc_ltwrapper_script_p ()
27915ffd6003Smrg{
2792b7d26471Smrg    test -f "$1" &&
2793b7d26471Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
27945ffd6003Smrg}
2795145b7b3cSmrg
27965ffd6003Smrg# func_ltwrapper_executable_p file
27975ffd6003Smrg# True iff FILE is a libtool wrapper executable
27985ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
27995ffd6003Smrg# determined imposters.
28005ffd6003Smrgfunc_ltwrapper_executable_p ()
28015ffd6003Smrg{
28025ffd6003Smrg    func_ltwrapper_exec_suffix=
28035ffd6003Smrg    case $1 in
28045ffd6003Smrg    *.exe) ;;
28055ffd6003Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
28065ffd6003Smrg    esac
28075ffd6003Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
28085ffd6003Smrg}
2809145b7b3cSmrg
28105ffd6003Smrg# func_ltwrapper_scriptname file
28115ffd6003Smrg# Assumes file is an ltwrapper_executable
28125ffd6003Smrg# uses $file to determine the appropriate filename for a
28135ffd6003Smrg# temporary ltwrapper_script.
28145ffd6003Smrgfunc_ltwrapper_scriptname ()
28155ffd6003Smrg{
2816629baa8cSmrg    func_dirname_and_basename "$1" "" "."
2817629baa8cSmrg    func_stripname '' '.exe' "$func_basename_result"
2818b7d26471Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
28195ffd6003Smrg}
28205ffd6003Smrg
28215ffd6003Smrg# func_ltwrapper_p file
28225ffd6003Smrg# True iff FILE is a libtool wrapper script or wrapper executable
28235ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
28245ffd6003Smrg# determined imposters.
28255ffd6003Smrgfunc_ltwrapper_p ()
28265ffd6003Smrg{
28275ffd6003Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
28285ffd6003Smrg}
28295ffd6003Smrg
28305ffd6003Smrg
28315ffd6003Smrg# func_execute_cmds commands fail_cmd
28325ffd6003Smrg# Execute tilde-delimited COMMANDS.
28335ffd6003Smrg# If FAIL_CMD is given, eval that upon failure.
28345ffd6003Smrg# FAIL_CMD may read-access the current command in variable CMD!
28355ffd6003Smrgfunc_execute_cmds ()
28365ffd6003Smrg{
2837b7d26471Smrg    $debug_cmd
2838b7d26471Smrg
28395ffd6003Smrg    save_ifs=$IFS; IFS='~'
28405ffd6003Smrg    for cmd in $1; do
2841b7d26471Smrg      IFS=$sp$nl
28425ffd6003Smrg      eval cmd=\"$cmd\"
2843b7d26471Smrg      IFS=$save_ifs
28445ffd6003Smrg      func_show_eval "$cmd" "${2-:}"
28455ffd6003Smrg    done
28465ffd6003Smrg    IFS=$save_ifs
28475ffd6003Smrg}
28485ffd6003Smrg
28495ffd6003Smrg
28505ffd6003Smrg# func_source file
28515ffd6003Smrg# Source FILE, adding directory component if necessary.
28525ffd6003Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
28535ffd6003Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
28545ffd6003Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855b7d26471Smrg# 'FILE.' does not work on cygwin managed mounts.
28565ffd6003Smrgfunc_source ()
28575ffd6003Smrg{
2858b7d26471Smrg    $debug_cmd
2859b7d26471Smrg
28605ffd6003Smrg    case $1 in
28615ffd6003Smrg    */* | *\\*)	. "$1" ;;
28625ffd6003Smrg    *)		. "./$1" ;;
28635ffd6003Smrg    esac
28645ffd6003Smrg}
28655ffd6003Smrg
28665ffd6003Smrg
2867629baa8cSmrg# func_resolve_sysroot PATH
2868629baa8cSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2869629baa8cSmrg# func_resolve_sysroot_result
2870629baa8cSmrgfunc_resolve_sysroot ()
2871629baa8cSmrg{
2872629baa8cSmrg  func_resolve_sysroot_result=$1
2873629baa8cSmrg  case $func_resolve_sysroot_result in
2874629baa8cSmrg  =*)
2875629baa8cSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2876629baa8cSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2877629baa8cSmrg    ;;
2878629baa8cSmrg  esac
2879629baa8cSmrg}
2880629baa8cSmrg
2881629baa8cSmrg# func_replace_sysroot PATH
2882629baa8cSmrg# If PATH begins with the sysroot, replace it with = and
2883629baa8cSmrg# store the result into func_replace_sysroot_result.
2884629baa8cSmrgfunc_replace_sysroot ()
2885629baa8cSmrg{
2886b7d26471Smrg  case $lt_sysroot:$1 in
2887629baa8cSmrg  ?*:"$lt_sysroot"*)
2888629baa8cSmrg    func_stripname "$lt_sysroot" '' "$1"
2889b7d26471Smrg    func_replace_sysroot_result='='$func_stripname_result
2890629baa8cSmrg    ;;
2891629baa8cSmrg  *)
2892629baa8cSmrg    # Including no sysroot.
2893629baa8cSmrg    func_replace_sysroot_result=$1
2894629baa8cSmrg    ;;
2895629baa8cSmrg  esac
2896629baa8cSmrg}
2897629baa8cSmrg
28985ffd6003Smrg# func_infer_tag arg
28995ffd6003Smrg# Infer tagged configuration to use if any are available and
29005ffd6003Smrg# if one wasn't chosen via the "--tag" command line option.
29015ffd6003Smrg# Only attempt this if the compiler in the base compile
29025ffd6003Smrg# command doesn't match the default compiler.
29035ffd6003Smrg# arg is usually of the form 'gcc ...'
29045ffd6003Smrgfunc_infer_tag ()
29055ffd6003Smrg{
2906b7d26471Smrg    $debug_cmd
2907b7d26471Smrg
29085ffd6003Smrg    if test -n "$available_tags" && test -z "$tagname"; then
29095ffd6003Smrg      CC_quoted=
29105ffd6003Smrg      for arg in $CC; do
2911629baa8cSmrg	func_append_quoted CC_quoted "$arg"
29125ffd6003Smrg      done
2913629baa8cSmrg      CC_expanded=`func_echo_all $CC`
2914629baa8cSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
29155ffd6003Smrg      case $@ in
29165ffd6003Smrg      # Blanks in the command may have been stripped by the calling shell,
29175ffd6003Smrg      # but not from the CC environment variable when configure was run.
2918629baa8cSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2919629baa8cSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
29205ffd6003Smrg      # Blanks at the start of $base_compile will cause this to fail
29215ffd6003Smrg      # if we don't check for them as well.
29225ffd6003Smrg      *)
29235ffd6003Smrg	for z in $available_tags; do
29245ffd6003Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
29255ffd6003Smrg	    # Evaluate the configuration.
2926b7d26471Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
29275ffd6003Smrg	    CC_quoted=
29285ffd6003Smrg	    for arg in $CC; do
29295ffd6003Smrg	      # Double-quote args containing other shell metacharacters.
2930629baa8cSmrg	      func_append_quoted CC_quoted "$arg"
29315ffd6003Smrg	    done
2932629baa8cSmrg	    CC_expanded=`func_echo_all $CC`
2933629baa8cSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
29345ffd6003Smrg	    case "$@ " in
2935629baa8cSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2936629baa8cSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
29375ffd6003Smrg	      # The compiler in the base compile command matches
29385ffd6003Smrg	      # the one in the tagged configuration.
29395ffd6003Smrg	      # Assume this is the tagged configuration we want.
29405ffd6003Smrg	      tagname=$z
29415ffd6003Smrg	      break
29425ffd6003Smrg	      ;;
29435ffd6003Smrg	    esac
29445ffd6003Smrg	  fi
29455ffd6003Smrg	done
29465ffd6003Smrg	# If $tagname still isn't set, then no tagged configuration
29475ffd6003Smrg	# was found and let the user know that the "--tag" command
29485ffd6003Smrg	# line option must be used.
29495ffd6003Smrg	if test -z "$tagname"; then
29505ffd6003Smrg	  func_echo "unable to infer tagged configuration"
2951b7d26471Smrg	  func_fatal_error "specify a tag with '--tag'"
29525ffd6003Smrg#	else
29535ffd6003Smrg#	  func_verbose "using $tagname tagged configuration"
29545ffd6003Smrg	fi
29555ffd6003Smrg	;;
29565ffd6003Smrg      esac
29575ffd6003Smrg    fi
29585ffd6003Smrg}
29595ffd6003Smrg
29605ffd6003Smrg
29615ffd6003Smrg
29625ffd6003Smrg# func_write_libtool_object output_name pic_name nonpic_name
29635ffd6003Smrg# Create a libtool object file (analogous to a ".la" file),
29645ffd6003Smrg# but don't create it if we're doing a dry run.
29655ffd6003Smrgfunc_write_libtool_object ()
29665ffd6003Smrg{
2967b7d26471Smrg    write_libobj=$1
2968b7d26471Smrg    if test yes = "$build_libtool_libs"; then
2969b7d26471Smrg      write_lobj=\'$2\'
29705ffd6003Smrg    else
29715ffd6003Smrg      write_lobj=none
29725ffd6003Smrg    fi
29735ffd6003Smrg
2974b7d26471Smrg    if test yes = "$build_old_libs"; then
2975b7d26471Smrg      write_oldobj=\'$3\'
29765ffd6003Smrg    else
29775ffd6003Smrg      write_oldobj=none
29785ffd6003Smrg    fi
29795ffd6003Smrg
29805ffd6003Smrg    $opt_dry_run || {
29815ffd6003Smrg      cat >${write_libobj}T <<EOF
29825ffd6003Smrg# $write_libobj - a libtool object file
2983b7d26471Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
29845ffd6003Smrg#
29855ffd6003Smrg# Please DO NOT delete this file!
29865ffd6003Smrg# It is necessary for linking the library.
29875ffd6003Smrg
29885ffd6003Smrg# Name of the PIC object.
29895ffd6003Smrgpic_object=$write_lobj
29905ffd6003Smrg
29915ffd6003Smrg# Name of the non-PIC object
29925ffd6003Smrgnon_pic_object=$write_oldobj
29935ffd6003Smrg
29945ffd6003SmrgEOF
2995b7d26471Smrg      $MV "${write_libobj}T" "$write_libobj"
29965ffd6003Smrg    }
29975ffd6003Smrg}
29985ffd6003Smrg
2999629baa8cSmrg
3000629baa8cSmrg##################################################
3001629baa8cSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3002629baa8cSmrg##################################################
3003629baa8cSmrg
3004629baa8cSmrg# func_convert_core_file_wine_to_w32 ARG
3005629baa8cSmrg# Helper function used by file name conversion functions when $build is *nix,
3006629baa8cSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3007629baa8cSmrg# correctly configured wine environment available, with the winepath program
3008629baa8cSmrg# in $build's $PATH.
3009629baa8cSmrg#
3010629baa8cSmrg# ARG is the $build file name to be converted to w32 format.
3011629baa8cSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3012629baa8cSmrg# be empty on error (or when ARG is empty)
3013629baa8cSmrgfunc_convert_core_file_wine_to_w32 ()
3014629baa8cSmrg{
3015b7d26471Smrg  $debug_cmd
3016b7d26471Smrg
3017b7d26471Smrg  func_convert_core_file_wine_to_w32_result=$1
3018629baa8cSmrg  if test -n "$1"; then
3019629baa8cSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3020629baa8cSmrg    # are forced to check the contents of stdout. On the other hand, if the
3021629baa8cSmrg    # command is not found, the shell will set an exit code of 127 and print
3022629baa8cSmrg    # *an error message* to stdout. So we must check for both error code of
3023629baa8cSmrg    # zero AND non-empty stdout, which explains the odd construction:
3024629baa8cSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025b7d26471Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3026629baa8cSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027b7d26471Smrg        $SED -e "$sed_naive_backslashify"`
3028629baa8cSmrg    else
3029629baa8cSmrg      func_convert_core_file_wine_to_w32_result=
3030629baa8cSmrg    fi
3031629baa8cSmrg  fi
3032629baa8cSmrg}
3033629baa8cSmrg# end: func_convert_core_file_wine_to_w32
3034629baa8cSmrg
3035629baa8cSmrg
3036629baa8cSmrg# func_convert_core_path_wine_to_w32 ARG
3037629baa8cSmrg# Helper function used by path conversion functions when $build is *nix, and
3038629baa8cSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3039629baa8cSmrg# configured wine environment available, with the winepath program in $build's
3040629baa8cSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3041629baa8cSmrg#
3042629baa8cSmrg# ARG is path to be converted from $build format to win32.
3043629baa8cSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3044629baa8cSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3045629baa8cSmrg# are convertible, then the result may be empty.
3046629baa8cSmrgfunc_convert_core_path_wine_to_w32 ()
3047629baa8cSmrg{
3048b7d26471Smrg  $debug_cmd
3049b7d26471Smrg
3050629baa8cSmrg  # unfortunately, winepath doesn't convert paths, only file names
3051b7d26471Smrg  func_convert_core_path_wine_to_w32_result=
3052629baa8cSmrg  if test -n "$1"; then
3053629baa8cSmrg    oldIFS=$IFS
3054629baa8cSmrg    IFS=:
3055629baa8cSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
3056629baa8cSmrg      IFS=$oldIFS
3057629baa8cSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058b7d26471Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3059629baa8cSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060b7d26471Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3061629baa8cSmrg        else
3062629baa8cSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3063629baa8cSmrg        fi
3064629baa8cSmrg      fi
3065629baa8cSmrg    done
3066629baa8cSmrg    IFS=$oldIFS
3067629baa8cSmrg  fi
3068629baa8cSmrg}
3069629baa8cSmrg# end: func_convert_core_path_wine_to_w32
3070629baa8cSmrg
3071629baa8cSmrg
3072629baa8cSmrg# func_cygpath ARGS...
3073629baa8cSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3074629baa8cSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3075629baa8cSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3076629baa8cSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3077629baa8cSmrg# file name or path is assumed to be in w32 format, as previously converted
3078629baa8cSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3079629baa8cSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
3080629baa8cSmrg# Cygwin format). Returns an empty string on error.
3081629baa8cSmrg#
3082629baa8cSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
3083629baa8cSmrg# be converted.
3084629baa8cSmrg#
3085629baa8cSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3086629baa8cSmrg# environment variable; do not put it in $PATH.
3087629baa8cSmrgfunc_cygpath ()
3088629baa8cSmrg{
3089b7d26471Smrg  $debug_cmd
3090b7d26471Smrg
3091629baa8cSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3092629baa8cSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3093629baa8cSmrg    if test "$?" -ne 0; then
3094629baa8cSmrg      # on failure, ensure result is empty
3095629baa8cSmrg      func_cygpath_result=
3096629baa8cSmrg    fi
3097629baa8cSmrg  else
3098629baa8cSmrg    func_cygpath_result=
3099b7d26471Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3100629baa8cSmrg  fi
3101629baa8cSmrg}
3102629baa8cSmrg#end: func_cygpath
3103629baa8cSmrg
3104629baa8cSmrg
3105629baa8cSmrg# func_convert_core_msys_to_w32 ARG
3106629baa8cSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3107629baa8cSmrg# result in func_convert_core_msys_to_w32_result.
3108629baa8cSmrgfunc_convert_core_msys_to_w32 ()
3109629baa8cSmrg{
3110b7d26471Smrg  $debug_cmd
3111b7d26471Smrg
3112629baa8cSmrg  # awkward: cmd appends spaces to result
3113629baa8cSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114b7d26471Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3115629baa8cSmrg}
3116629baa8cSmrg#end: func_convert_core_msys_to_w32
3117629baa8cSmrg
3118629baa8cSmrg
3119629baa8cSmrg# func_convert_file_check ARG1 ARG2
3120629baa8cSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
3121629baa8cSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3122629baa8cSmrg# func_to_host_file_result to ARG1).
3123629baa8cSmrgfunc_convert_file_check ()
3124629baa8cSmrg{
3125b7d26471Smrg  $debug_cmd
3126b7d26471Smrg
3127b7d26471Smrg  if test -z "$2" && test -n "$1"; then
3128629baa8cSmrg    func_error "Could not determine host file name corresponding to"
3129b7d26471Smrg    func_error "  '$1'"
3130629baa8cSmrg    func_error "Continuing, but uninstalled executables may not work."
3131629baa8cSmrg    # Fallback:
3132b7d26471Smrg    func_to_host_file_result=$1
3133629baa8cSmrg  fi
3134629baa8cSmrg}
3135629baa8cSmrg# end func_convert_file_check
3136629baa8cSmrg
3137629baa8cSmrg
3138629baa8cSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3139629baa8cSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3140629baa8cSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3141629baa8cSmrg# func_to_host_file_result to a simplistic fallback value (see below).
3142629baa8cSmrgfunc_convert_path_check ()
3143629baa8cSmrg{
3144b7d26471Smrg  $debug_cmd
3145b7d26471Smrg
3146629baa8cSmrg  if test -z "$4" && test -n "$3"; then
3147629baa8cSmrg    func_error "Could not determine the host path corresponding to"
3148b7d26471Smrg    func_error "  '$3'"
3149629baa8cSmrg    func_error "Continuing, but uninstalled executables may not work."
3150629baa8cSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
3151629baa8cSmrg    # should not be "improved".  See libtool.info.
3152629baa8cSmrg    if test "x$1" != "x$2"; then
3153629baa8cSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
3154629baa8cSmrg      func_to_host_path_result=`echo "$3" |
3155629baa8cSmrg        $SED -e "$lt_replace_pathsep_chars"`
3156629baa8cSmrg    else
3157b7d26471Smrg      func_to_host_path_result=$3
3158629baa8cSmrg    fi
3159629baa8cSmrg  fi
3160629baa8cSmrg}
3161629baa8cSmrg# end func_convert_path_check
3162629baa8cSmrg
3163629baa8cSmrg
3164629baa8cSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3165629baa8cSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3166629baa8cSmrg# and appending REPL if ORIG matches BACKPAT.
3167629baa8cSmrgfunc_convert_path_front_back_pathsep ()
3168629baa8cSmrg{
3169b7d26471Smrg  $debug_cmd
3170b7d26471Smrg
3171629baa8cSmrg  case $4 in
3172b7d26471Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3173629baa8cSmrg    ;;
3174629baa8cSmrg  esac
3175629baa8cSmrg  case $4 in
3176629baa8cSmrg  $2 ) func_append func_to_host_path_result "$3"
3177629baa8cSmrg    ;;
3178629baa8cSmrg  esac
3179629baa8cSmrg}
3180629baa8cSmrg# end func_convert_path_front_back_pathsep
3181629baa8cSmrg
3182629baa8cSmrg
3183629baa8cSmrg##################################################
3184629baa8cSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3185629baa8cSmrg##################################################
3186b7d26471Smrg# invoked via '$to_host_file_cmd ARG'
3187629baa8cSmrg#
3188629baa8cSmrg# In each case, ARG is the path to be converted from $build to $host format.
3189629baa8cSmrg# Result will be available in $func_to_host_file_result.
3190629baa8cSmrg
3191629baa8cSmrg
3192629baa8cSmrg# func_to_host_file ARG
3193629baa8cSmrg# Converts the file name ARG from $build format to $host format. Return result
3194629baa8cSmrg# in func_to_host_file_result.
3195629baa8cSmrgfunc_to_host_file ()
3196629baa8cSmrg{
3197b7d26471Smrg  $debug_cmd
3198b7d26471Smrg
3199629baa8cSmrg  $to_host_file_cmd "$1"
3200629baa8cSmrg}
3201629baa8cSmrg# end func_to_host_file
3202629baa8cSmrg
3203629baa8cSmrg
3204629baa8cSmrg# func_to_tool_file ARG LAZY
3205629baa8cSmrg# converts the file name ARG from $build format to toolchain format. Return
3206629baa8cSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
3207629baa8cSmrg# in (the comma separated) LAZY, no conversion takes place.
3208629baa8cSmrgfunc_to_tool_file ()
3209629baa8cSmrg{
3210b7d26471Smrg  $debug_cmd
3211b7d26471Smrg
3212629baa8cSmrg  case ,$2, in
3213629baa8cSmrg    *,"$to_tool_file_cmd",*)
3214629baa8cSmrg      func_to_tool_file_result=$1
3215629baa8cSmrg      ;;
3216629baa8cSmrg    *)
3217629baa8cSmrg      $to_tool_file_cmd "$1"
3218629baa8cSmrg      func_to_tool_file_result=$func_to_host_file_result
3219629baa8cSmrg      ;;
3220629baa8cSmrg  esac
3221629baa8cSmrg}
3222629baa8cSmrg# end func_to_tool_file
3223629baa8cSmrg
3224629baa8cSmrg
3225629baa8cSmrg# func_convert_file_noop ARG
3226629baa8cSmrg# Copy ARG to func_to_host_file_result.
3227629baa8cSmrgfunc_convert_file_noop ()
3228629baa8cSmrg{
3229b7d26471Smrg  func_to_host_file_result=$1
3230629baa8cSmrg}
3231629baa8cSmrg# end func_convert_file_noop
3232629baa8cSmrg
3233629baa8cSmrg
3234629baa8cSmrg# func_convert_file_msys_to_w32 ARG
3235629baa8cSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3236629baa8cSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3237629baa8cSmrg# func_to_host_file_result.
3238629baa8cSmrgfunc_convert_file_msys_to_w32 ()
3239629baa8cSmrg{
3240b7d26471Smrg  $debug_cmd
3241b7d26471Smrg
3242b7d26471Smrg  func_to_host_file_result=$1
3243629baa8cSmrg  if test -n "$1"; then
3244629baa8cSmrg    func_convert_core_msys_to_w32 "$1"
3245b7d26471Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3246629baa8cSmrg  fi
3247629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3248629baa8cSmrg}
3249629baa8cSmrg# end func_convert_file_msys_to_w32
3250629baa8cSmrg
3251629baa8cSmrg
3252629baa8cSmrg# func_convert_file_cygwin_to_w32 ARG
3253629baa8cSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3254629baa8cSmrg# func_to_host_file_result.
3255629baa8cSmrgfunc_convert_file_cygwin_to_w32 ()
3256629baa8cSmrg{
3257b7d26471Smrg  $debug_cmd
3258b7d26471Smrg
3259b7d26471Smrg  func_to_host_file_result=$1
3260629baa8cSmrg  if test -n "$1"; then
3261629baa8cSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3262629baa8cSmrg    # LT_CYGPATH in this case.
3263629baa8cSmrg    func_to_host_file_result=`cygpath -m "$1"`
3264629baa8cSmrg  fi
3265629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3266629baa8cSmrg}
3267629baa8cSmrg# end func_convert_file_cygwin_to_w32
3268629baa8cSmrg
3269629baa8cSmrg
3270629baa8cSmrg# func_convert_file_nix_to_w32 ARG
3271629baa8cSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3272629baa8cSmrg# and a working winepath. Returns result in func_to_host_file_result.
3273629baa8cSmrgfunc_convert_file_nix_to_w32 ()
3274629baa8cSmrg{
3275b7d26471Smrg  $debug_cmd
3276b7d26471Smrg
3277b7d26471Smrg  func_to_host_file_result=$1
3278629baa8cSmrg  if test -n "$1"; then
3279629baa8cSmrg    func_convert_core_file_wine_to_w32 "$1"
3280b7d26471Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3281629baa8cSmrg  fi
3282629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3283629baa8cSmrg}
3284629baa8cSmrg# end func_convert_file_nix_to_w32
3285629baa8cSmrg
3286629baa8cSmrg
3287629baa8cSmrg# func_convert_file_msys_to_cygwin ARG
3288629baa8cSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3289629baa8cSmrg# Returns result in func_to_host_file_result.
3290629baa8cSmrgfunc_convert_file_msys_to_cygwin ()
3291629baa8cSmrg{
3292b7d26471Smrg  $debug_cmd
3293b7d26471Smrg
3294b7d26471Smrg  func_to_host_file_result=$1
3295629baa8cSmrg  if test -n "$1"; then
3296629baa8cSmrg    func_convert_core_msys_to_w32 "$1"
3297629baa8cSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298b7d26471Smrg    func_to_host_file_result=$func_cygpath_result
3299629baa8cSmrg  fi
3300629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3301629baa8cSmrg}
3302629baa8cSmrg# end func_convert_file_msys_to_cygwin
3303629baa8cSmrg
3304629baa8cSmrg
3305629baa8cSmrg# func_convert_file_nix_to_cygwin ARG
3306629baa8cSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3307629baa8cSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3308629baa8cSmrg# in func_to_host_file_result.
3309629baa8cSmrgfunc_convert_file_nix_to_cygwin ()
3310629baa8cSmrg{
3311b7d26471Smrg  $debug_cmd
3312b7d26471Smrg
3313b7d26471Smrg  func_to_host_file_result=$1
3314629baa8cSmrg  if test -n "$1"; then
3315629baa8cSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3316629baa8cSmrg    func_convert_core_file_wine_to_w32 "$1"
3317629baa8cSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318b7d26471Smrg    func_to_host_file_result=$func_cygpath_result
3319629baa8cSmrg  fi
3320629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3321629baa8cSmrg}
3322629baa8cSmrg# end func_convert_file_nix_to_cygwin
3323629baa8cSmrg
3324629baa8cSmrg
3325629baa8cSmrg#############################################
3326629baa8cSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3327629baa8cSmrg#############################################
3328b7d26471Smrg# invoked via '$to_host_path_cmd ARG'
3329629baa8cSmrg#
3330629baa8cSmrg# In each case, ARG is the path to be converted from $build to $host format.
3331629baa8cSmrg# The result will be available in $func_to_host_path_result.
3332629baa8cSmrg#
3333629baa8cSmrg# Path separators are also converted from $build format to $host format.  If
3334629baa8cSmrg# ARG begins or ends with a path separator character, it is preserved (but
3335629baa8cSmrg# converted to $host format) on output.
3336629baa8cSmrg#
3337629baa8cSmrg# All path conversion functions are named using the following convention:
3338629baa8cSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3339629baa8cSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3340629baa8cSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3341629baa8cSmrg# same.  If conversion functions are added for new $build/$host combinations,
3342629baa8cSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3343629baa8cSmrg# will break.
3344629baa8cSmrg
3345629baa8cSmrg
3346629baa8cSmrg# func_init_to_host_path_cmd
3347629baa8cSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3348629baa8cSmrg# appropriate value, based on the value of $to_host_file_cmd.
3349629baa8cSmrgto_host_path_cmd=
3350629baa8cSmrgfunc_init_to_host_path_cmd ()
3351629baa8cSmrg{
3352b7d26471Smrg  $debug_cmd
3353b7d26471Smrg
3354629baa8cSmrg  if test -z "$to_host_path_cmd"; then
3355629baa8cSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356b7d26471Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3357629baa8cSmrg  fi
3358629baa8cSmrg}
3359629baa8cSmrg
3360629baa8cSmrg
3361629baa8cSmrg# func_to_host_path ARG
3362629baa8cSmrg# Converts the path ARG from $build format to $host format. Return result
3363629baa8cSmrg# in func_to_host_path_result.
3364629baa8cSmrgfunc_to_host_path ()
3365629baa8cSmrg{
3366b7d26471Smrg  $debug_cmd
3367b7d26471Smrg
3368629baa8cSmrg  func_init_to_host_path_cmd
3369629baa8cSmrg  $to_host_path_cmd "$1"
3370629baa8cSmrg}
3371629baa8cSmrg# end func_to_host_path
3372629baa8cSmrg
3373629baa8cSmrg
3374629baa8cSmrg# func_convert_path_noop ARG
3375629baa8cSmrg# Copy ARG to func_to_host_path_result.
3376629baa8cSmrgfunc_convert_path_noop ()
3377629baa8cSmrg{
3378b7d26471Smrg  func_to_host_path_result=$1
3379629baa8cSmrg}
3380629baa8cSmrg# end func_convert_path_noop
3381629baa8cSmrg
3382629baa8cSmrg
3383629baa8cSmrg# func_convert_path_msys_to_w32 ARG
3384629baa8cSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3385629baa8cSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3386629baa8cSmrg# func_to_host_path_result.
3387629baa8cSmrgfunc_convert_path_msys_to_w32 ()
3388629baa8cSmrg{
3389b7d26471Smrg  $debug_cmd
3390b7d26471Smrg
3391b7d26471Smrg  func_to_host_path_result=$1
3392629baa8cSmrg  if test -n "$1"; then
3393629baa8cSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3394629baa8cSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3395629baa8cSmrg    # and winepath ignores them completely.
3396629baa8cSmrg    func_stripname : : "$1"
3397629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3398629baa8cSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399b7d26471Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3400629baa8cSmrg    func_convert_path_check : ";" \
3401629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3402629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3403629baa8cSmrg  fi
3404629baa8cSmrg}
3405629baa8cSmrg# end func_convert_path_msys_to_w32
3406629baa8cSmrg
3407629baa8cSmrg
3408629baa8cSmrg# func_convert_path_cygwin_to_w32 ARG
3409629baa8cSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3410629baa8cSmrg# func_to_host_file_result.
3411629baa8cSmrgfunc_convert_path_cygwin_to_w32 ()
3412629baa8cSmrg{
3413b7d26471Smrg  $debug_cmd
3414b7d26471Smrg
3415b7d26471Smrg  func_to_host_path_result=$1
3416629baa8cSmrg  if test -n "$1"; then
3417629baa8cSmrg    # See func_convert_path_msys_to_w32:
3418629baa8cSmrg    func_stripname : : "$1"
3419629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3420629baa8cSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3421629baa8cSmrg    func_convert_path_check : ";" \
3422629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3423629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3424629baa8cSmrg  fi
3425629baa8cSmrg}
3426629baa8cSmrg# end func_convert_path_cygwin_to_w32
3427629baa8cSmrg
3428629baa8cSmrg
3429629baa8cSmrg# func_convert_path_nix_to_w32 ARG
3430629baa8cSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3431629baa8cSmrg# a working winepath.  Returns result in func_to_host_file_result.
3432629baa8cSmrgfunc_convert_path_nix_to_w32 ()
3433629baa8cSmrg{
3434b7d26471Smrg  $debug_cmd
3435b7d26471Smrg
3436b7d26471Smrg  func_to_host_path_result=$1
3437629baa8cSmrg  if test -n "$1"; then
3438629baa8cSmrg    # See func_convert_path_msys_to_w32:
3439629baa8cSmrg    func_stripname : : "$1"
3440629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3441629baa8cSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442b7d26471Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3443629baa8cSmrg    func_convert_path_check : ";" \
3444629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3445629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3446629baa8cSmrg  fi
3447629baa8cSmrg}
3448629baa8cSmrg# end func_convert_path_nix_to_w32
3449629baa8cSmrg
3450629baa8cSmrg
3451629baa8cSmrg# func_convert_path_msys_to_cygwin ARG
3452629baa8cSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3453629baa8cSmrg# Returns result in func_to_host_file_result.
3454629baa8cSmrgfunc_convert_path_msys_to_cygwin ()
3455629baa8cSmrg{
3456b7d26471Smrg  $debug_cmd
3457b7d26471Smrg
3458b7d26471Smrg  func_to_host_path_result=$1
3459629baa8cSmrg  if test -n "$1"; then
3460629baa8cSmrg    # See func_convert_path_msys_to_w32:
3461629baa8cSmrg    func_stripname : : "$1"
3462629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3463629baa8cSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3464629baa8cSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465b7d26471Smrg    func_to_host_path_result=$func_cygpath_result
3466629baa8cSmrg    func_convert_path_check : : \
3467629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3468629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3469629baa8cSmrg  fi
3470629baa8cSmrg}
3471629baa8cSmrg# end func_convert_path_msys_to_cygwin
3472629baa8cSmrg
3473629baa8cSmrg
3474629baa8cSmrg# func_convert_path_nix_to_cygwin ARG
3475629baa8cSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3476629baa8cSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3477629baa8cSmrg# func_to_host_file_result.
3478629baa8cSmrgfunc_convert_path_nix_to_cygwin ()
3479629baa8cSmrg{
3480b7d26471Smrg  $debug_cmd
3481b7d26471Smrg
3482b7d26471Smrg  func_to_host_path_result=$1
3483629baa8cSmrg  if test -n "$1"; then
3484629baa8cSmrg    # Remove leading and trailing path separator characters from
3485629baa8cSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3486629baa8cSmrg    # into '.;' and ';.', and winepath ignores them completely.
3487629baa8cSmrg    func_stripname : : "$1"
3488629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3489629baa8cSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3490629baa8cSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491b7d26471Smrg    func_to_host_path_result=$func_cygpath_result
3492629baa8cSmrg    func_convert_path_check : : \
3493629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3494629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3495629baa8cSmrg  fi
3496629baa8cSmrg}
3497629baa8cSmrg# end func_convert_path_nix_to_cygwin
3498629baa8cSmrg
3499629baa8cSmrg
3500b7d26471Smrg# func_dll_def_p FILE
3501b7d26471Smrg# True iff FILE is a Windows DLL '.def' file.
3502b7d26471Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503b7d26471Smrgfunc_dll_def_p ()
3504b7d26471Smrg{
3505b7d26471Smrg  $debug_cmd
3506b7d26471Smrg
3507b7d26471Smrg  func_dll_def_p_tmp=`$SED -n \
3508b7d26471Smrg    -e 's/^[	 ]*//' \
3509b7d26471Smrg    -e '/^\(;.*\)*$/d' \
3510b7d26471Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511b7d26471Smrg    -e q \
3512b7d26471Smrg    "$1"`
3513b7d26471Smrg  test DEF = "$func_dll_def_p_tmp"
3514b7d26471Smrg}
3515b7d26471Smrg
3516b7d26471Smrg
35175ffd6003Smrg# func_mode_compile arg...
35185ffd6003Smrgfunc_mode_compile ()
35195ffd6003Smrg{
3520b7d26471Smrg    $debug_cmd
3521b7d26471Smrg
35225ffd6003Smrg    # Get the compilation command and the source file.
35235ffd6003Smrg    base_compile=
3524b7d26471Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
35255ffd6003Smrg    suppress_opt=yes
35265ffd6003Smrg    suppress_output=
35275ffd6003Smrg    arg_mode=normal
35285ffd6003Smrg    libobj=
35295ffd6003Smrg    later=
35305ffd6003Smrg    pie_flag=
35315ffd6003Smrg
35325ffd6003Smrg    for arg
35335ffd6003Smrg    do
35345ffd6003Smrg      case $arg_mode in
35355ffd6003Smrg      arg  )
35365ffd6003Smrg	# do not "continue".  Instead, add this to base_compile
3537b7d26471Smrg	lastarg=$arg
35385ffd6003Smrg	arg_mode=normal
35395ffd6003Smrg	;;
35405ffd6003Smrg
35415ffd6003Smrg      target )
3542b7d26471Smrg	libobj=$arg
35435ffd6003Smrg	arg_mode=normal
35445ffd6003Smrg	continue
35455ffd6003Smrg	;;
35465ffd6003Smrg
35475ffd6003Smrg      normal )
35485ffd6003Smrg	# Accept any command-line options.
35495ffd6003Smrg	case $arg in
35505ffd6003Smrg	-o)
35515ffd6003Smrg	  test -n "$libobj" && \
3552b7d26471Smrg	    func_fatal_error "you cannot specify '-o' more than once"
35535ffd6003Smrg	  arg_mode=target
35545ffd6003Smrg	  continue
35555ffd6003Smrg	  ;;
35565ffd6003Smrg
35575ffd6003Smrg	-pie | -fpie | -fPIE)
3558629baa8cSmrg          func_append pie_flag " $arg"
35595ffd6003Smrg	  continue
35605ffd6003Smrg	  ;;
35615ffd6003Smrg
35625ffd6003Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3563629baa8cSmrg	  func_append later " $arg"
35645ffd6003Smrg	  continue
35655ffd6003Smrg	  ;;
35665ffd6003Smrg
35675ffd6003Smrg	-no-suppress)
3568145b7b3cSmrg	  suppress_opt=no
3569145b7b3cSmrg	  continue
3570145b7b3cSmrg	  ;;
3571145b7b3cSmrg
3572145b7b3cSmrg	-Xcompiler)
3573145b7b3cSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3574145b7b3cSmrg	  continue      #  The current "srcfile" will either be retained or
3575145b7b3cSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3576145b7b3cSmrg
3577145b7b3cSmrg	-Wc,*)
35785ffd6003Smrg	  func_stripname '-Wc,' '' "$arg"
35795ffd6003Smrg	  args=$func_stripname_result
3580145b7b3cSmrg	  lastarg=
3581b7d26471Smrg	  save_ifs=$IFS; IFS=,
35825ffd6003Smrg	  for arg in $args; do
3583b7d26471Smrg	    IFS=$save_ifs
3584629baa8cSmrg	    func_append_quoted lastarg "$arg"
3585145b7b3cSmrg	  done
3586b7d26471Smrg	  IFS=$save_ifs
35875ffd6003Smrg	  func_stripname ' ' '' "$lastarg"
35885ffd6003Smrg	  lastarg=$func_stripname_result
3589145b7b3cSmrg
3590145b7b3cSmrg	  # Add the arguments to base_compile.
3591629baa8cSmrg	  func_append base_compile " $lastarg"
3592145b7b3cSmrg	  continue
3593145b7b3cSmrg	  ;;
3594145b7b3cSmrg
35955ffd6003Smrg	*)
3596145b7b3cSmrg	  # Accept the current argument as the source file.
3597145b7b3cSmrg	  # The previous "srcfile" becomes the current argument.
3598145b7b3cSmrg	  #
3599b7d26471Smrg	  lastarg=$srcfile
3600b7d26471Smrg	  srcfile=$arg
3601145b7b3cSmrg	  ;;
3602145b7b3cSmrg	esac  #  case $arg
3603145b7b3cSmrg	;;
3604145b7b3cSmrg      esac    #  case $arg_mode
3605145b7b3cSmrg
3606145b7b3cSmrg      # Aesthetically quote the previous argument.
3607629baa8cSmrg      func_append_quoted base_compile "$lastarg"
3608145b7b3cSmrg    done # for arg
3609145b7b3cSmrg
3610145b7b3cSmrg    case $arg_mode in
3611145b7b3cSmrg    arg)
36125ffd6003Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3613145b7b3cSmrg      ;;
3614145b7b3cSmrg    target)
3615b7d26471Smrg      func_fatal_error "you must specify a target with '-o'"
3616145b7b3cSmrg      ;;
3617145b7b3cSmrg    *)
3618145b7b3cSmrg      # Get the name of the library object.
36195ffd6003Smrg      test -z "$libobj" && {
36205ffd6003Smrg	func_basename "$srcfile"
3621b7d26471Smrg	libobj=$func_basename_result
36225ffd6003Smrg      }
3623145b7b3cSmrg      ;;
3624145b7b3cSmrg    esac
3625145b7b3cSmrg
3626145b7b3cSmrg    # Recognize several different file suffixes.
3627145b7b3cSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3628145b7b3cSmrg    case $libobj in
36295ffd6003Smrg    *.[cCFSifmso] | \
36305ffd6003Smrg    *.ada | *.adb | *.ads | *.asm | \
36315ffd6003Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632b7d26471Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
36335ffd6003Smrg      func_xform "$libobj"
36345ffd6003Smrg      libobj=$func_xform_result
36355ffd6003Smrg      ;;
3636145b7b3cSmrg    esac
3637145b7b3cSmrg
3638145b7b3cSmrg    case $libobj in
36395ffd6003Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3640145b7b3cSmrg    *)
3641b7d26471Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3642145b7b3cSmrg      ;;
3643145b7b3cSmrg    esac
3644145b7b3cSmrg
3645145b7b3cSmrg    func_infer_tag $base_compile
3646145b7b3cSmrg
3647145b7b3cSmrg    for arg in $later; do
3648145b7b3cSmrg      case $arg in
36495ffd6003Smrg      -shared)
3650b7d26471Smrg	test yes = "$build_libtool_libs" \
3651b7d26471Smrg	  || func_fatal_configuration "cannot build a shared library"
36525ffd6003Smrg	build_old_libs=no
36535ffd6003Smrg	continue
36545ffd6003Smrg	;;
36555ffd6003Smrg
3656145b7b3cSmrg      -static)
36575ffd6003Smrg	build_libtool_libs=no
3658145b7b3cSmrg	build_old_libs=yes
3659145b7b3cSmrg	continue
3660145b7b3cSmrg	;;
3661145b7b3cSmrg
3662145b7b3cSmrg      -prefer-pic)
3663145b7b3cSmrg	pic_mode=yes
3664145b7b3cSmrg	continue
3665145b7b3cSmrg	;;
3666145b7b3cSmrg
3667145b7b3cSmrg      -prefer-non-pic)
3668145b7b3cSmrg	pic_mode=no
3669145b7b3cSmrg	continue
3670145b7b3cSmrg	;;
3671145b7b3cSmrg      esac
3672145b7b3cSmrg    done
3673145b7b3cSmrg
3674da2e2ef6Smrg    func_quote_arg pretty "$libobj"
3675da2e2ef6Smrg    test "X$libobj" != "X$func_quote_arg_result" \
36765ffd6003Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677b7d26471Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
36785ffd6003Smrg    func_dirname_and_basename "$obj" "/" ""
3679b7d26471Smrg    objname=$func_basename_result
3680b7d26471Smrg    xdir=$func_dirname_result
3681b7d26471Smrg    lobj=$xdir$objdir/$objname
3682145b7b3cSmrg
36835ffd6003Smrg    test -z "$base_compile" && \
36845ffd6003Smrg      func_fatal_help "you must specify a compilation command"
3685145b7b3cSmrg
3686145b7b3cSmrg    # Delete any leftover library objects.
3687b7d26471Smrg    if test yes = "$build_old_libs"; then
3688145b7b3cSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3689145b7b3cSmrg    else
3690145b7b3cSmrg      removelist="$lobj $libobj ${libobj}T"
3691145b7b3cSmrg    fi
3692145b7b3cSmrg
3693145b7b3cSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3694145b7b3cSmrg    case $host_os in
36955ffd6003Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3696145b7b3cSmrg      pic_mode=default
3697145b7b3cSmrg      ;;
3698145b7b3cSmrg    esac
3699b7d26471Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3700145b7b3cSmrg      # non-PIC code in shared libraries is not supported
3701145b7b3cSmrg      pic_mode=default
3702145b7b3cSmrg    fi
3703145b7b3cSmrg
3704145b7b3cSmrg    # Calculate the filename of the output object if compiler does
3705145b7b3cSmrg    # not support -o with -c
3706b7d26471Smrg    if test no = "$compiler_c_o"; then
3707b7d26471Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708b7d26471Smrg      lockfile=$output_obj.lock
3709145b7b3cSmrg    else
3710145b7b3cSmrg      output_obj=
3711145b7b3cSmrg      need_locks=no
3712145b7b3cSmrg      lockfile=
3713145b7b3cSmrg    fi
3714145b7b3cSmrg
3715145b7b3cSmrg    # Lock this critical section if it is needed
3716145b7b3cSmrg    # We use this script file to make the link, it avoids creating a new file
3717b7d26471Smrg    if test yes = "$need_locks"; then
37185ffd6003Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
37195ffd6003Smrg	func_echo "Waiting for $lockfile to be removed"
3720145b7b3cSmrg	sleep 2
3721145b7b3cSmrg      done
3722b7d26471Smrg    elif test warn = "$need_locks"; then
3723145b7b3cSmrg      if test -f "$lockfile"; then
37245ffd6003Smrg	$ECHO "\
3725145b7b3cSmrg*** ERROR, $lockfile exists and contains:
3726145b7b3cSmrg`cat $lockfile 2>/dev/null`
3727145b7b3cSmrg
3728145b7b3cSmrgThis indicates that another process is trying to use the same
3729145b7b3cSmrgtemporary object file, and libtool could not work around it because
3730b7d26471Smrgyour compiler does not support '-c' and '-o' together.  If you
3731145b7b3cSmrgrepeat this compilation, it may succeed, by chance, but you had better
3732145b7b3cSmrgavoid parallel builds (make -j) in this platform, or get a better
3733145b7b3cSmrgcompiler."
3734145b7b3cSmrg
37355ffd6003Smrg	$opt_dry_run || $RM $removelist
3736145b7b3cSmrg	exit $EXIT_FAILURE
3737145b7b3cSmrg      fi
3738629baa8cSmrg      func_append removelist " $output_obj"
37395ffd6003Smrg      $ECHO "$srcfile" > "$lockfile"
3740145b7b3cSmrg    fi
3741145b7b3cSmrg
37425ffd6003Smrg    $opt_dry_run || $RM $removelist
3743629baa8cSmrg    func_append removelist " $lockfile"
37445ffd6003Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
37455ffd6003Smrg
3746629baa8cSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3747629baa8cSmrg    srcfile=$func_to_tool_file_result
3748da2e2ef6Smrg    func_quote_arg pretty "$srcfile"
3749da2e2ef6Smrg    qsrcfile=$func_quote_arg_result
3750145b7b3cSmrg
3751145b7b3cSmrg    # Only build a PIC object if we are building libtool libraries.
3752b7d26471Smrg    if test yes = "$build_libtool_libs"; then
3753145b7b3cSmrg      # Without this assignment, base_compile gets emptied.
3754145b7b3cSmrg      fbsd_hideous_sh_bug=$base_compile
3755145b7b3cSmrg
3756b7d26471Smrg      if test no != "$pic_mode"; then
3757145b7b3cSmrg	command="$base_compile $qsrcfile $pic_flag"
3758145b7b3cSmrg      else
3759145b7b3cSmrg	# Don't build PIC code
3760145b7b3cSmrg	command="$base_compile $qsrcfile"
3761145b7b3cSmrg      fi
3762145b7b3cSmrg
37635ffd6003Smrg      func_mkdir_p "$xdir$objdir"
3764145b7b3cSmrg
3765145b7b3cSmrg      if test -z "$output_obj"; then
3766145b7b3cSmrg	# Place PIC objects in $objdir
3767629baa8cSmrg	func_append command " -o $lobj"
3768145b7b3cSmrg      fi
3769145b7b3cSmrg
37705ffd6003Smrg      func_show_eval_locale "$command"	\
37715ffd6003Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3772145b7b3cSmrg
3773b7d26471Smrg      if test warn = "$need_locks" &&
3774145b7b3cSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
37755ffd6003Smrg	$ECHO "\
3776145b7b3cSmrg*** ERROR, $lockfile contains:
3777145b7b3cSmrg`cat $lockfile 2>/dev/null`
3778145b7b3cSmrg
3779145b7b3cSmrgbut it should contain:
3780145b7b3cSmrg$srcfile
3781145b7b3cSmrg
3782145b7b3cSmrgThis indicates that another process is trying to use the same
3783145b7b3cSmrgtemporary object file, and libtool could not work around it because
3784b7d26471Smrgyour compiler does not support '-c' and '-o' together.  If you
3785145b7b3cSmrgrepeat this compilation, it may succeed, by chance, but you had better
3786145b7b3cSmrgavoid parallel builds (make -j) in this platform, or get a better
3787145b7b3cSmrgcompiler."
3788145b7b3cSmrg
37895ffd6003Smrg	$opt_dry_run || $RM $removelist
3790145b7b3cSmrg	exit $EXIT_FAILURE
3791145b7b3cSmrg      fi
3792145b7b3cSmrg
3793145b7b3cSmrg      # Just move the object if needed, then go on to compile the next one
3794145b7b3cSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
37955ffd6003Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
37965ffd6003Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3797145b7b3cSmrg      fi
3798145b7b3cSmrg
3799145b7b3cSmrg      # Allow error messages only from the first compilation.
3800b7d26471Smrg      if test yes = "$suppress_opt"; then
38015ffd6003Smrg	suppress_output=' >/dev/null 2>&1'
3802145b7b3cSmrg      fi
3803145b7b3cSmrg    fi
3804145b7b3cSmrg
3805145b7b3cSmrg    # Only build a position-dependent object if we build old libraries.
3806b7d26471Smrg    if test yes = "$build_old_libs"; then
3807b7d26471Smrg      if test yes != "$pic_mode"; then
3808145b7b3cSmrg	# Don't build PIC code
38095ffd6003Smrg	command="$base_compile $qsrcfile$pie_flag"
3810145b7b3cSmrg      else
3811145b7b3cSmrg	command="$base_compile $qsrcfile $pic_flag"
3812145b7b3cSmrg      fi
3813b7d26471Smrg      if test yes = "$compiler_c_o"; then
3814629baa8cSmrg	func_append command " -o $obj"
3815145b7b3cSmrg      fi
3816145b7b3cSmrg
3817145b7b3cSmrg      # Suppress compiler output if we already did a PIC compilation.
3818629baa8cSmrg      func_append command "$suppress_output"
38195ffd6003Smrg      func_show_eval_locale "$command" \
38205ffd6003Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3821145b7b3cSmrg
3822b7d26471Smrg      if test warn = "$need_locks" &&
3823145b7b3cSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
38245ffd6003Smrg	$ECHO "\
3825145b7b3cSmrg*** ERROR, $lockfile contains:
3826145b7b3cSmrg`cat $lockfile 2>/dev/null`
3827145b7b3cSmrg
3828145b7b3cSmrgbut it should contain:
3829145b7b3cSmrg$srcfile
3830145b7b3cSmrg
3831145b7b3cSmrgThis indicates that another process is trying to use the same
3832145b7b3cSmrgtemporary object file, and libtool could not work around it because
3833b7d26471Smrgyour compiler does not support '-c' and '-o' together.  If you
3834145b7b3cSmrgrepeat this compilation, it may succeed, by chance, but you had better
3835145b7b3cSmrgavoid parallel builds (make -j) in this platform, or get a better
3836145b7b3cSmrgcompiler."
3837145b7b3cSmrg
38385ffd6003Smrg	$opt_dry_run || $RM $removelist
3839145b7b3cSmrg	exit $EXIT_FAILURE
3840145b7b3cSmrg      fi
3841145b7b3cSmrg
3842145b7b3cSmrg      # Just move the object if needed
3843145b7b3cSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
38445ffd6003Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
38455ffd6003Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3846145b7b3cSmrg      fi
3847145b7b3cSmrg    fi
3848145b7b3cSmrg
38495ffd6003Smrg    $opt_dry_run || {
38505ffd6003Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3851145b7b3cSmrg
38525ffd6003Smrg      # Unlock the critical section if it was locked
3853b7d26471Smrg      if test no != "$need_locks"; then
38545ffd6003Smrg	removelist=$lockfile
38555ffd6003Smrg        $RM "$lockfile"
38565ffd6003Smrg      fi
38575ffd6003Smrg    }
3858145b7b3cSmrg
3859145b7b3cSmrg    exit $EXIT_SUCCESS
38605ffd6003Smrg}
3861145b7b3cSmrg
38625ffd6003Smrg$opt_help || {
3863b7d26471Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
38645ffd6003Smrg}
3865145b7b3cSmrg
38665ffd6003Smrgfunc_mode_help ()
38675ffd6003Smrg{
38685ffd6003Smrg    # We need to display help for each of the modes.
3869629baa8cSmrg    case $opt_mode in
38705ffd6003Smrg      "")
38715ffd6003Smrg        # Generic help is extracted from the usage comments
38725ffd6003Smrg        # at the start of this file.
38735ffd6003Smrg        func_help
38745ffd6003Smrg        ;;
3875145b7b3cSmrg
38765ffd6003Smrg      clean)
38775ffd6003Smrg        $ECHO \
38785ffd6003Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3879145b7b3cSmrg
38805ffd6003SmrgRemove files from the build directory.
3881145b7b3cSmrg
38825ffd6003SmrgRM is the name of the program to use to delete files associated with each FILE
3883b7d26471Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
38845ffd6003Smrgto RM.
3885145b7b3cSmrg
38865ffd6003SmrgIf FILE is a libtool library, object or program, all the files associated
38875ffd6003Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
38885ffd6003Smrg        ;;
3889145b7b3cSmrg
38905ffd6003Smrg      compile)
38915ffd6003Smrg      $ECHO \
38925ffd6003Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3893145b7b3cSmrg
38945ffd6003SmrgCompile a source file into a libtool library object.
3895145b7b3cSmrg
38965ffd6003SmrgThis mode accepts the following additional options:
3897145b7b3cSmrg
38985ffd6003Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
38995ffd6003Smrg  -no-suppress      do not suppress compiler output for multiple passes
3900629baa8cSmrg  -prefer-pic       try to build PIC objects only
3901629baa8cSmrg  -prefer-non-pic   try to build non-PIC objects only
3902b7d26471Smrg  -shared           do not build a '.o' file suitable for static linking
3903b7d26471Smrg  -static           only build a '.o' file suitable for static linking
3904da2e2ef6Smrg  -Wc,FLAG
3905da2e2ef6Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
3906145b7b3cSmrg
3907b7d26471SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
39085ffd6003Smrgfrom the given SOURCEFILE.
3909145b7b3cSmrg
39105ffd6003SmrgThe output file name is determined by removing the directory component from
3911b7d26471SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912b7d26471Smrglibrary object suffix, '.lo'."
39135ffd6003Smrg        ;;
3914145b7b3cSmrg
39155ffd6003Smrg      execute)
39165ffd6003Smrg        $ECHO \
39175ffd6003Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3918145b7b3cSmrg
39195ffd6003SmrgAutomatically set library path, then run a program.
3920145b7b3cSmrg
39215ffd6003SmrgThis mode accepts the following additional options:
3922145b7b3cSmrg
39235ffd6003Smrg  -dlopen FILE      add the directory containing FILE to the library path
3924145b7b3cSmrg
3925b7d26471SmrgThis mode sets the library path environment variable according to '-dlopen'
39265ffd6003Smrgflags.
3927145b7b3cSmrg
39285ffd6003SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
39295ffd6003Smrginto their corresponding uninstalled binary, and any of their required library
39305ffd6003Smrgdirectories are added to the library path.
3931145b7b3cSmrg
39325ffd6003SmrgThen, COMMAND is executed, with ARGS as arguments."
39335ffd6003Smrg        ;;
3934145b7b3cSmrg
39355ffd6003Smrg      finish)
39365ffd6003Smrg        $ECHO \
39375ffd6003Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3938145b7b3cSmrg
39395ffd6003SmrgComplete the installation of libtool libraries.
3940145b7b3cSmrg
39415ffd6003SmrgEach LIBDIR is a directory that contains libtool libraries.
3942145b7b3cSmrg
39435ffd6003SmrgThe commands that this mode executes may require superuser privileges.  Use
3944b7d26471Smrgthe '--dry-run' option if you just want to see what would be executed."
39455ffd6003Smrg        ;;
3946145b7b3cSmrg
39475ffd6003Smrg      install)
39485ffd6003Smrg        $ECHO \
39495ffd6003Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3950145b7b3cSmrg
39515ffd6003SmrgInstall executables or libraries.
3952145b7b3cSmrg
39535ffd6003SmrgINSTALL-COMMAND is the installation command.  The first component should be
3954b7d26471Smrgeither the 'install' or 'cp' program.
3955145b7b3cSmrg
39565ffd6003SmrgThe following components of INSTALL-COMMAND are treated specially:
3957145b7b3cSmrg
3958629baa8cSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3959145b7b3cSmrg
39605ffd6003SmrgThe rest of the components are interpreted as arguments to that command (only
39615ffd6003SmrgBSD-compatible install options are recognized)."
39625ffd6003Smrg        ;;
3963145b7b3cSmrg
39645ffd6003Smrg      link)
39655ffd6003Smrg        $ECHO \
39665ffd6003Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3967145b7b3cSmrg
39685ffd6003SmrgLink object files or libraries together to form another library, or to
39695ffd6003Smrgcreate an executable program.
3970145b7b3cSmrg
39715ffd6003SmrgLINK-COMMAND is a command using the C compiler that you would use to create
39725ffd6003Smrga program from several object files.
3973145b7b3cSmrg
39745ffd6003SmrgThe following components of LINK-COMMAND are treated specially:
3975145b7b3cSmrg
39765ffd6003Smrg  -all-static       do not do any dynamic linking at all
39775ffd6003Smrg  -avoid-version    do not add a version suffix if possible
3978629baa8cSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
3979629baa8cSmrg                    libraries must be found in the PATH setting at runtime)
3980b7d26471Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
39815ffd6003Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
39825ffd6003Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
39835ffd6003Smrg  -export-symbols SYMFILE
39845ffd6003Smrg                    try to export only the symbols listed in SYMFILE
39855ffd6003Smrg  -export-symbols-regex REGEX
39865ffd6003Smrg                    try to export only the symbols matching REGEX
39875ffd6003Smrg  -LLIBDIR          search LIBDIR for required installed libraries
39885ffd6003Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
39895ffd6003Smrg  -module           build a library that can dlopened
39905ffd6003Smrg  -no-fast-install  disable the fast-install mode
39915ffd6003Smrg  -no-install       link a not-installable executable
39925ffd6003Smrg  -no-undefined     declare that a library does not refer to external symbols
39935ffd6003Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994b7d26471Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995b7d26471Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
39965ffd6003Smrg  -precious-files-regex REGEX
39975ffd6003Smrg                    don't remove output files matching REGEX
39985ffd6003Smrg  -release RELEASE  specify package release information
39995ffd6003Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
40005ffd6003Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
40015ffd6003Smrg  -shared           only do dynamic linking of libtool libraries
40025ffd6003Smrg  -shrext SUFFIX    override the standard shared library file extension
40035ffd6003Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
40045ffd6003Smrg  -static-libtool-libs
40055ffd6003Smrg                    do not do any dynamic linking of libtool libraries
40065ffd6003Smrg  -version-info CURRENT[:REVISION[:AGE]]
40075ffd6003Smrg                    specify library version info [each variable defaults to 0]
40085ffd6003Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4009629baa8cSmrg  -Wc,FLAG
4010629baa8cSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011da2e2ef6Smrg  -Wa,FLAG
4012da2e2ef6Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4013629baa8cSmrg  -Wl,FLAG
4014629baa8cSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4015629baa8cSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4016145b7b3cSmrg
4017b7d26471SmrgAll other options (arguments beginning with '-') are ignored.
4018145b7b3cSmrg
4019b7d26471SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
40205ffd6003Smrgtreated as uninstalled libtool libraries, other files are standard or library
40215ffd6003Smrgobject files.
4022578741aaSmrg
4023b7d26471SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024b7d26471Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
40255ffd6003Smrgrequired, except when creating a convenience library.
4026145b7b3cSmrg
4027b7d26471SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028b7d26471Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
4029145b7b3cSmrg
4030b7d26471SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
40315ffd6003Smrgis created, otherwise an executable program is created."
4032145b7b3cSmrg        ;;
4033145b7b3cSmrg
40345ffd6003Smrg      uninstall)
40355ffd6003Smrg        $ECHO \
40365ffd6003Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4037145b7b3cSmrg
40385ffd6003SmrgRemove libraries from an installation directory.
4039145b7b3cSmrg
40405ffd6003SmrgRM is the name of the program to use to delete files associated with each FILE
4041b7d26471Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
40425ffd6003Smrgto RM.
4043145b7b3cSmrg
40445ffd6003SmrgIf FILE is a libtool library, all the files associated with it are deleted.
40455ffd6003SmrgOtherwise, only FILE itself is deleted using RM."
40465ffd6003Smrg        ;;
4047145b7b3cSmrg
40485ffd6003Smrg      *)
4049b7d26471Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
40505ffd6003Smrg        ;;
40515ffd6003Smrg    esac
4052145b7b3cSmrg
4053629baa8cSmrg    echo
4054b7d26471Smrg    $ECHO "Try '$progname --help' for more information about other modes."
40555ffd6003Smrg}
4056145b7b3cSmrg
4057629baa8cSmrg# Now that we've collected a possible --mode arg, show help if necessary
4058629baa8cSmrgif $opt_help; then
4059b7d26471Smrg  if test : = "$opt_help"; then
4060629baa8cSmrg    func_mode_help
4061629baa8cSmrg  else
4062629baa8cSmrg    {
4063629baa8cSmrg      func_help noexit
4064629baa8cSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4065629baa8cSmrg	func_mode_help
4066629baa8cSmrg      done
4067b7d26471Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4068629baa8cSmrg    {
4069629baa8cSmrg      func_help noexit
4070629baa8cSmrg      for opt_mode in compile link execute install finish uninstall clean; do
4071629baa8cSmrg	echo
4072629baa8cSmrg	func_mode_help
4073629baa8cSmrg      done
4074629baa8cSmrg    } |
4075b7d26471Smrg    $SED '1d
4076629baa8cSmrg      /^When reporting/,/^Report/{
4077629baa8cSmrg	H
4078629baa8cSmrg	d
4079629baa8cSmrg      }
4080629baa8cSmrg      $x
4081629baa8cSmrg      /information about other modes/d
4082629baa8cSmrg      /more detailed .*MODE/d
4083629baa8cSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4084629baa8cSmrg  fi
4085629baa8cSmrg  exit $?
4086629baa8cSmrgfi
4087145b7b3cSmrg
4088145b7b3cSmrg
40895ffd6003Smrg# func_mode_execute arg...
40905ffd6003Smrgfunc_mode_execute ()
40915ffd6003Smrg{
4092b7d26471Smrg    $debug_cmd
4093b7d26471Smrg
40945ffd6003Smrg    # The first argument is the command name.
4095b7d26471Smrg    cmd=$nonopt
40965ffd6003Smrg    test -z "$cmd" && \
40975ffd6003Smrg      func_fatal_help "you must specify a COMMAND"
4098145b7b3cSmrg
40995ffd6003Smrg    # Handle -dlopen flags immediately.
4100629baa8cSmrg    for file in $opt_dlopen; do
41015ffd6003Smrg      test -f "$file" \
4102b7d26471Smrg	|| func_fatal_help "'$file' is not a file"
4103145b7b3cSmrg
41045ffd6003Smrg      dir=
41055ffd6003Smrg      case $file in
41065ffd6003Smrg      *.la)
4107629baa8cSmrg	func_resolve_sysroot "$file"
4108629baa8cSmrg	file=$func_resolve_sysroot_result
4109629baa8cSmrg
41105ffd6003Smrg	# Check to see that this really is a libtool archive.
41115ffd6003Smrg	func_lalib_unsafe_p "$file" \
4112b7d26471Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113145b7b3cSmrg
41145ffd6003Smrg	# Read the libtool library.
41155ffd6003Smrg	dlname=
41165ffd6003Smrg	library_names=
41175ffd6003Smrg	func_source "$file"
4118145b7b3cSmrg
41195ffd6003Smrg	# Skip this library if it cannot be dlopened.
41205ffd6003Smrg	if test -z "$dlname"; then
41215ffd6003Smrg	  # Warn if it was a shared library.
41225ffd6003Smrg	  test -n "$library_names" && \
4123b7d26471Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
41245ffd6003Smrg	  continue
41255ffd6003Smrg	fi
4126145b7b3cSmrg
41275ffd6003Smrg	func_dirname "$file" "" "."
4128b7d26471Smrg	dir=$func_dirname_result
4129145b7b3cSmrg
41305ffd6003Smrg	if test -f "$dir/$objdir/$dlname"; then
4131629baa8cSmrg	  func_append dir "/$objdir"
41325ffd6003Smrg	else
41335ffd6003Smrg	  if test ! -f "$dir/$dlname"; then
4134b7d26471Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
41355ffd6003Smrg	  fi
41365ffd6003Smrg	fi
4137145b7b3cSmrg	;;
4138145b7b3cSmrg
41395ffd6003Smrg      *.lo)
41405ffd6003Smrg	# Just add the directory containing the .lo file.
41415ffd6003Smrg	func_dirname "$file" "" "."
4142b7d26471Smrg	dir=$func_dirname_result
4143145b7b3cSmrg	;;
4144145b7b3cSmrg
41455ffd6003Smrg      *)
4146b7d26471Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147145b7b3cSmrg	continue
4148145b7b3cSmrg	;;
41495ffd6003Smrg      esac
4150145b7b3cSmrg
41515ffd6003Smrg      # Get the absolute pathname.
41525ffd6003Smrg      absdir=`cd "$dir" && pwd`
4153b7d26471Smrg      test -n "$absdir" && dir=$absdir
4154145b7b3cSmrg
41555ffd6003Smrg      # Now add the directory to shlibpath_var.
41565ffd6003Smrg      if eval "test -z \"\$$shlibpath_var\""; then
41575ffd6003Smrg	eval "$shlibpath_var=\"\$dir\""
41585ffd6003Smrg      else
41595ffd6003Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
41605ffd6003Smrg      fi
41615ffd6003Smrg    done
4162145b7b3cSmrg
41635ffd6003Smrg    # This variable tells wrapper scripts just to set shlibpath_var
41645ffd6003Smrg    # rather than running their programs.
4165b7d26471Smrg    libtool_execute_magic=$magic
4166145b7b3cSmrg
41675ffd6003Smrg    # Check if any of the arguments is a wrapper script.
41685ffd6003Smrg    args=
41695ffd6003Smrg    for file
41705ffd6003Smrg    do
41715ffd6003Smrg      case $file in
4172629baa8cSmrg      -* | *.la | *.lo ) ;;
41735ffd6003Smrg      *)
41745ffd6003Smrg	# Do a test to see if this is really a libtool program.
41755ffd6003Smrg	if func_ltwrapper_script_p "$file"; then
41765ffd6003Smrg	  func_source "$file"
41775ffd6003Smrg	  # Transform arg to wrapped name.
4178b7d26471Smrg	  file=$progdir/$program
41795ffd6003Smrg	elif func_ltwrapper_executable_p "$file"; then
41805ffd6003Smrg	  func_ltwrapper_scriptname "$file"
41815ffd6003Smrg	  func_source "$func_ltwrapper_scriptname_result"
41825ffd6003Smrg	  # Transform arg to wrapped name.
4183b7d26471Smrg	  file=$progdir/$program
41845ffd6003Smrg	fi
41855ffd6003Smrg	;;
41865ffd6003Smrg      esac
41875ffd6003Smrg      # Quote arguments (to preserve shell metacharacters).
4188629baa8cSmrg      func_append_quoted args "$file"
41895ffd6003Smrg    done
4190145b7b3cSmrg
4191b7d26471Smrg    if $opt_dry_run; then
4192b7d26471Smrg      # Display what would be done.
4193b7d26471Smrg      if test -n "$shlibpath_var"; then
4194b7d26471Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195b7d26471Smrg	echo "export $shlibpath_var"
4196b7d26471Smrg      fi
4197b7d26471Smrg      $ECHO "$cmd$args"
4198b7d26471Smrg      exit $EXIT_SUCCESS
4199b7d26471Smrg    else
42005ffd6003Smrg      if test -n "$shlibpath_var"; then
42015ffd6003Smrg	# Export the shlibpath_var.
42025ffd6003Smrg	eval "export $shlibpath_var"
42035ffd6003Smrg      fi
4204145b7b3cSmrg
42055ffd6003Smrg      # Restore saved environment variables
42065ffd6003Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
42075ffd6003Smrg      do
42085ffd6003Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
42095ffd6003Smrg                $lt_var=\$save_$lt_var; export $lt_var
4210145b7b3cSmrg	      else
42115ffd6003Smrg		$lt_unset $lt_var
42125ffd6003Smrg	      fi"
42135ffd6003Smrg      done
4214145b7b3cSmrg
42155ffd6003Smrg      # Now prepare to actually exec the command.
4216b7d26471Smrg      exec_cmd=\$cmd$args
42175ffd6003Smrg    fi
42185ffd6003Smrg}
4219145b7b3cSmrg
4220b7d26471Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4221145b7b3cSmrg
4222145b7b3cSmrg
42235ffd6003Smrg# func_mode_finish arg...
42245ffd6003Smrgfunc_mode_finish ()
42255ffd6003Smrg{
4226b7d26471Smrg    $debug_cmd
4227b7d26471Smrg
4228629baa8cSmrg    libs=
4229629baa8cSmrg    libdirs=
42305ffd6003Smrg    admincmds=
4231145b7b3cSmrg
4232629baa8cSmrg    for opt in "$nonopt" ${1+"$@"}
4233629baa8cSmrg    do
4234629baa8cSmrg      if test -d "$opt"; then
4235629baa8cSmrg	func_append libdirs " $opt"
4236629baa8cSmrg
4237629baa8cSmrg      elif test -f "$opt"; then
4238629baa8cSmrg	if func_lalib_unsafe_p "$opt"; then
4239629baa8cSmrg	  func_append libs " $opt"
4240629baa8cSmrg	else
4241b7d26471Smrg	  func_warning "'$opt' is not a valid libtool archive"
4242629baa8cSmrg	fi
4243629baa8cSmrg
4244629baa8cSmrg      else
4245b7d26471Smrg	func_fatal_error "invalid argument '$opt'"
4246629baa8cSmrg      fi
4247629baa8cSmrg    done
4248629baa8cSmrg
4249629baa8cSmrg    if test -n "$libs"; then
4250629baa8cSmrg      if test -n "$lt_sysroot"; then
4251629baa8cSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4252629baa8cSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4253629baa8cSmrg      else
4254629baa8cSmrg        sysroot_cmd=
4255629baa8cSmrg      fi
4256145b7b3cSmrg
4257629baa8cSmrg      # Remove sysroot references
4258629baa8cSmrg      if $opt_dry_run; then
4259629baa8cSmrg        for lib in $libs; do
4260b7d26471Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4261629baa8cSmrg        done
4262629baa8cSmrg      else
4263629baa8cSmrg        tmpdir=`func_mktempdir`
4264629baa8cSmrg        for lib in $libs; do
4265b7d26471Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4266629baa8cSmrg	    > $tmpdir/tmp-la
4267629baa8cSmrg	  mv -f $tmpdir/tmp-la $lib
4268629baa8cSmrg	done
4269629baa8cSmrg        ${RM}r "$tmpdir"
4270629baa8cSmrg      fi
4271629baa8cSmrg    fi
4272629baa8cSmrg
4273629baa8cSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
42745ffd6003Smrg      for libdir in $libdirs; do
42755ffd6003Smrg	if test -n "$finish_cmds"; then
42765ffd6003Smrg	  # Do each command in the finish commands.
42775ffd6003Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
42785ffd6003Smrg'"$cmd"'"'
4279145b7b3cSmrg	fi
42805ffd6003Smrg	if test -n "$finish_eval"; then
42815ffd6003Smrg	  # Do the single finish_eval.
42825ffd6003Smrg	  eval cmds=\"$finish_eval\"
4283629baa8cSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
42845ffd6003Smrg       $cmds"
42855ffd6003Smrg	fi
42865ffd6003Smrg      done
42875ffd6003Smrg    fi
4288145b7b3cSmrg
42895ffd6003Smrg    # Exit here if they wanted silent mode.
4290b7d26471Smrg    $opt_quiet && exit $EXIT_SUCCESS
4291145b7b3cSmrg
4292629baa8cSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4293629baa8cSmrg      echo "----------------------------------------------------------------------"
4294629baa8cSmrg      echo "Libraries have been installed in:"
4295629baa8cSmrg      for libdir in $libdirs; do
4296629baa8cSmrg	$ECHO "   $libdir"
4297629baa8cSmrg      done
4298629baa8cSmrg      echo
4299629baa8cSmrg      echo "If you ever happen to want to link against installed libraries"
4300629baa8cSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301b7d26471Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4302629baa8cSmrg      echo "flag during linking and do at least one of the following:"
4303629baa8cSmrg      if test -n "$shlibpath_var"; then
4304b7d26471Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4305629baa8cSmrg	echo "     during execution"
4306629baa8cSmrg      fi
4307629baa8cSmrg      if test -n "$runpath_var"; then
4308b7d26471Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4309629baa8cSmrg	echo "     during linking"
4310629baa8cSmrg      fi
4311629baa8cSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4312629baa8cSmrg	libdir=LIBDIR
4313629baa8cSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
43145ffd6003Smrg
4315b7d26471Smrg	$ECHO "   - use the '$flag' linker flag"
4316629baa8cSmrg      fi
4317629baa8cSmrg      if test -n "$admincmds"; then
4318629baa8cSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4319629baa8cSmrg      fi
4320629baa8cSmrg      if test -f /etc/ld.so.conf; then
4321b7d26471Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4322629baa8cSmrg      fi
4323629baa8cSmrg      echo
43245ffd6003Smrg
4325629baa8cSmrg      echo "See any operating system documentation about shared libraries for"
4326629baa8cSmrg      case $host in
4327629baa8cSmrg	solaris2.[6789]|solaris2.1[0-9])
4328629baa8cSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4329629baa8cSmrg	  echo "pages."
4330629baa8cSmrg	  ;;
4331629baa8cSmrg	*)
4332629baa8cSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333629baa8cSmrg	  ;;
4334629baa8cSmrg      esac
4335629baa8cSmrg      echo "----------------------------------------------------------------------"
4336629baa8cSmrg    fi
43375ffd6003Smrg    exit $EXIT_SUCCESS
43385ffd6003Smrg}
43395ffd6003Smrg
4340b7d26471Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
43415ffd6003Smrg
43425ffd6003Smrg
43435ffd6003Smrg# func_mode_install arg...
43445ffd6003Smrgfunc_mode_install ()
43455ffd6003Smrg{
4346b7d26471Smrg    $debug_cmd
4347b7d26471Smrg
43485ffd6003Smrg    # There may be an optional sh(1) argument at the beginning of
43495ffd6003Smrg    # install_prog (especially on Windows NT).
4350b7d26471Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
43515ffd6003Smrg       # Allow the use of GNU shtool's install command.
4352b7d26471Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4353b7d26471Smrg    then
43545ffd6003Smrg      # Aesthetically quote it.
4355da2e2ef6Smrg      func_quote_arg pretty "$nonopt"
4356da2e2ef6Smrg      install_prog="$func_quote_arg_result "
43575ffd6003Smrg      arg=$1
43585ffd6003Smrg      shift
43595ffd6003Smrg    else
43605ffd6003Smrg      install_prog=
43615ffd6003Smrg      arg=$nonopt
43625ffd6003Smrg    fi
43635ffd6003Smrg
43645ffd6003Smrg    # The real first argument should be the name of the installation program.
43655ffd6003Smrg    # Aesthetically quote it.
4366da2e2ef6Smrg    func_quote_arg pretty "$arg"
4367da2e2ef6Smrg    func_append install_prog "$func_quote_arg_result"
4368629baa8cSmrg    install_shared_prog=$install_prog
4369629baa8cSmrg    case " $install_prog " in
4370629baa8cSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4371629baa8cSmrg      *) install_cp=false ;;
4372629baa8cSmrg    esac
43735ffd6003Smrg
43745ffd6003Smrg    # We need to accept at least all the BSD install flags.
43755ffd6003Smrg    dest=
43765ffd6003Smrg    files=
43775ffd6003Smrg    opts=
43785ffd6003Smrg    prev=
43795ffd6003Smrg    install_type=
4380b7d26471Smrg    isdir=false
43815ffd6003Smrg    stripme=
4382629baa8cSmrg    no_mode=:
43835ffd6003Smrg    for arg
43845ffd6003Smrg    do
4385629baa8cSmrg      arg2=
43865ffd6003Smrg      if test -n "$dest"; then
4387629baa8cSmrg	func_append files " $dest"
43885ffd6003Smrg	dest=$arg
43895ffd6003Smrg	continue
43905ffd6003Smrg      fi
43915ffd6003Smrg
43925ffd6003Smrg      case $arg in
4393b7d26471Smrg      -d) isdir=: ;;
43945ffd6003Smrg      -f)
4395629baa8cSmrg	if $install_cp; then :; else
4396629baa8cSmrg	  prev=$arg
4397629baa8cSmrg	fi
43985ffd6003Smrg	;;
43995ffd6003Smrg      -g | -m | -o)
44005ffd6003Smrg	prev=$arg
44015ffd6003Smrg	;;
44025ffd6003Smrg      -s)
44035ffd6003Smrg	stripme=" -s"
44045ffd6003Smrg	continue
44055ffd6003Smrg	;;
44065ffd6003Smrg      -*)
44075ffd6003Smrg	;;
44085ffd6003Smrg      *)
44095ffd6003Smrg	# If the previous option needed an argument, then skip it.
44105ffd6003Smrg	if test -n "$prev"; then
4411b7d26471Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4412629baa8cSmrg	    arg2=$install_override_mode
4413629baa8cSmrg	    no_mode=false
4414629baa8cSmrg	  fi
4415145b7b3cSmrg	  prev=
4416145b7b3cSmrg	else
44175ffd6003Smrg	  dest=$arg
44185ffd6003Smrg	  continue
4419145b7b3cSmrg	fi
4420145b7b3cSmrg	;;
44215ffd6003Smrg      esac
4422145b7b3cSmrg
44235ffd6003Smrg      # Aesthetically quote the argument.
4424da2e2ef6Smrg      func_quote_arg pretty "$arg"
4425da2e2ef6Smrg      func_append install_prog " $func_quote_arg_result"
4426629baa8cSmrg      if test -n "$arg2"; then
4427da2e2ef6Smrg	func_quote_arg pretty "$arg2"
4428629baa8cSmrg      fi
4429da2e2ef6Smrg      func_append install_shared_prog " $func_quote_arg_result"
44305ffd6003Smrg    done
4431145b7b3cSmrg
44325ffd6003Smrg    test -z "$install_prog" && \
44335ffd6003Smrg      func_fatal_help "you must specify an install program"
4434145b7b3cSmrg
44355ffd6003Smrg    test -n "$prev" && \
4436b7d26471Smrg      func_fatal_help "the '$prev' option requires an argument"
4437145b7b3cSmrg
4438629baa8cSmrg    if test -n "$install_override_mode" && $no_mode; then
4439629baa8cSmrg      if $install_cp; then :; else
4440da2e2ef6Smrg	func_quote_arg pretty "$install_override_mode"
4441da2e2ef6Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4442629baa8cSmrg      fi
4443629baa8cSmrg    fi
4444629baa8cSmrg
44455ffd6003Smrg    if test -z "$files"; then
44465ffd6003Smrg      if test -z "$dest"; then
44475ffd6003Smrg	func_fatal_help "no file or destination specified"
44485ffd6003Smrg      else
44495ffd6003Smrg	func_fatal_help "you must specify a destination"
44505ffd6003Smrg      fi
4451145b7b3cSmrg    fi
4452145b7b3cSmrg
44535ffd6003Smrg    # Strip any trailing slash from the destination.
44545ffd6003Smrg    func_stripname '' '/' "$dest"
44555ffd6003Smrg    dest=$func_stripname_result
4456145b7b3cSmrg
44575ffd6003Smrg    # Check to see that the destination is a directory.
4458b7d26471Smrg    test -d "$dest" && isdir=:
4459b7d26471Smrg    if $isdir; then
4460b7d26471Smrg      destdir=$dest
44615ffd6003Smrg      destname=
4462145b7b3cSmrg    else
44635ffd6003Smrg      func_dirname_and_basename "$dest" "" "."
4464b7d26471Smrg      destdir=$func_dirname_result
4465b7d26471Smrg      destname=$func_basename_result
4466145b7b3cSmrg
44675ffd6003Smrg      # Not a directory, so check to see that there is only one file specified.
44685ffd6003Smrg      set dummy $files; shift
44695ffd6003Smrg      test "$#" -gt 1 && \
4470b7d26471Smrg	func_fatal_help "'$dest' is not a directory"
4471145b7b3cSmrg    fi
44725ffd6003Smrg    case $destdir in
44735ffd6003Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474145b7b3cSmrg    *)
44755ffd6003Smrg      for file in $files; do
44765ffd6003Smrg	case $file in
44775ffd6003Smrg	*.lo) ;;
44785ffd6003Smrg	*)
4479b7d26471Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
44805ffd6003Smrg	  ;;
44815ffd6003Smrg	esac
44825ffd6003Smrg      done
4483145b7b3cSmrg      ;;
4484145b7b3cSmrg    esac
4485145b7b3cSmrg
44865ffd6003Smrg    # This variable tells wrapper scripts just to set variables rather
44875ffd6003Smrg    # than running their programs.
4488b7d26471Smrg    libtool_install_magic=$magic
4489145b7b3cSmrg
44905ffd6003Smrg    staticlibs=
44915ffd6003Smrg    future_libdirs=
44925ffd6003Smrg    current_libdirs=
44935ffd6003Smrg    for file in $files; do
4494145b7b3cSmrg
44955ffd6003Smrg      # Do each installation.
44965ffd6003Smrg      case $file in
44975ffd6003Smrg      *.$libext)
44985ffd6003Smrg	# Do the static libraries later.
4499629baa8cSmrg	func_append staticlibs " $file"
45005ffd6003Smrg	;;
45015ffd6003Smrg
45025ffd6003Smrg      *.la)
4503629baa8cSmrg	func_resolve_sysroot "$file"
4504629baa8cSmrg	file=$func_resolve_sysroot_result
4505629baa8cSmrg
45065ffd6003Smrg	# Check to see that this really is a libtool archive.
45075ffd6003Smrg	func_lalib_unsafe_p "$file" \
4508b7d26471Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
45095ffd6003Smrg
45105ffd6003Smrg	library_names=
45115ffd6003Smrg	old_library=
45125ffd6003Smrg	relink_command=
45135ffd6003Smrg	func_source "$file"
45145ffd6003Smrg
45155ffd6003Smrg	# Add the libdir to current_libdirs if it is the destination.
45165ffd6003Smrg	if test "X$destdir" = "X$libdir"; then
45175ffd6003Smrg	  case "$current_libdirs " in
45185ffd6003Smrg	  *" $libdir "*) ;;
4519629baa8cSmrg	  *) func_append current_libdirs " $libdir" ;;
4520145b7b3cSmrg	  esac
45215ffd6003Smrg	else
45225ffd6003Smrg	  # Note the libdir as a future libdir.
45235ffd6003Smrg	  case "$future_libdirs " in
45245ffd6003Smrg	  *" $libdir "*) ;;
4525629baa8cSmrg	  *) func_append future_libdirs " $libdir" ;;
45265ffd6003Smrg	  esac
45275ffd6003Smrg	fi
4528145b7b3cSmrg
45295ffd6003Smrg	func_dirname "$file" "/" ""
4530b7d26471Smrg	dir=$func_dirname_result
4531629baa8cSmrg	func_append dir "$objdir"
45325ffd6003Smrg
45335ffd6003Smrg	if test -n "$relink_command"; then
45345ffd6003Smrg	  # Determine the prefix the user has applied to our future dir.
4535629baa8cSmrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
45365ffd6003Smrg
45375ffd6003Smrg	  # Don't allow the user to place us outside of our expected
45385ffd6003Smrg	  # location b/c this prevents finding dependent libraries that
45395ffd6003Smrg	  # are installed to the same prefix.
45405ffd6003Smrg	  # At present, this check doesn't affect windows .dll's that
45415ffd6003Smrg	  # are installed into $libdir/../bin (currently, that works fine)
45425ffd6003Smrg	  # but it's something to keep an eye on.
45435ffd6003Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4544b7d26471Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
45455ffd6003Smrg
45465ffd6003Smrg	  if test -n "$inst_prefix_dir"; then
45475ffd6003Smrg	    # Stick the inst_prefix_dir data into the link command.
4548629baa8cSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
45495ffd6003Smrg	  else
4550629baa8cSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
45515ffd6003Smrg	  fi
45525ffd6003Smrg
4553b7d26471Smrg	  func_warning "relinking '$file'"
45545ffd6003Smrg	  func_show_eval "$relink_command" \
4555b7d26471Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
45565ffd6003Smrg	fi
45575ffd6003Smrg
45585ffd6003Smrg	# See the names of the shared library.
45595ffd6003Smrg	set dummy $library_names; shift
45605ffd6003Smrg	if test -n "$1"; then
4561b7d26471Smrg	  realname=$1
45625ffd6003Smrg	  shift
45635ffd6003Smrg
4564b7d26471Smrg	  srcname=$realname
4565b7d26471Smrg	  test -n "$relink_command" && srcname=${realname}T
45665ffd6003Smrg
45675ffd6003Smrg	  # Install the shared library and build the symlinks.
4568629baa8cSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
45695ffd6003Smrg	      'exit $?'
4570b7d26471Smrg	  tstripme=$stripme
45715ffd6003Smrg	  case $host_os in
45725ffd6003Smrg	  cygwin* | mingw* | pw32* | cegcc*)
45735ffd6003Smrg	    case $realname in
45745ffd6003Smrg	    *.dll.a)
4575b7d26471Smrg	      tstripme=
4576b7d26471Smrg	      ;;
4577b7d26471Smrg	    esac
4578b7d26471Smrg	    ;;
4579b7d26471Smrg	  os2*)
4580b7d26471Smrg	    case $realname in
4581b7d26471Smrg	    *_dll.a)
4582b7d26471Smrg	      tstripme=
45835ffd6003Smrg	      ;;
45845ffd6003Smrg	    esac
4585145b7b3cSmrg	    ;;
4586145b7b3cSmrg	  esac
45875ffd6003Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
45885ffd6003Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589578741aaSmrg	  fi
45905ffd6003Smrg
45915ffd6003Smrg	  if test "$#" -gt 0; then
45925ffd6003Smrg	    # Delete the old symlinks, and create new ones.
4593b7d26471Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
45945ffd6003Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
45955ffd6003Smrg	    # so we also need to try rm && ln -s.
45965ffd6003Smrg	    for linkname
45975ffd6003Smrg	    do
45985ffd6003Smrg	      test "$linkname" != "$realname" \
45995ffd6003Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600145b7b3cSmrg	    done
4601145b7b3cSmrg	  fi
4602145b7b3cSmrg
46035ffd6003Smrg	  # Do each command in the postinstall commands.
4604b7d26471Smrg	  lib=$destdir/$realname
46055ffd6003Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4606145b7b3cSmrg	fi
4607145b7b3cSmrg
46085ffd6003Smrg	# Install the pseudo-library for information purposes.
46095ffd6003Smrg	func_basename "$file"
4610b7d26471Smrg	name=$func_basename_result
4611b7d26471Smrg	instname=$dir/${name}i
46125ffd6003Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4613145b7b3cSmrg
46145ffd6003Smrg	# Maybe install the static library, too.
4615629baa8cSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
46165ffd6003Smrg	;;
4617145b7b3cSmrg
46185ffd6003Smrg      *.lo)
46195ffd6003Smrg	# Install (i.e. copy) a libtool object.
4620145b7b3cSmrg
46215ffd6003Smrg	# Figure out destination file name, if it wasn't already specified.
46225ffd6003Smrg	if test -n "$destname"; then
4623b7d26471Smrg	  destfile=$destdir/$destname
46245ffd6003Smrg	else
46255ffd6003Smrg	  func_basename "$file"
4626b7d26471Smrg	  destfile=$func_basename_result
4627b7d26471Smrg	  destfile=$destdir/$destfile
46285ffd6003Smrg	fi
46295ffd6003Smrg
46305ffd6003Smrg	# Deduce the name of the destination old-style object file.
46315ffd6003Smrg	case $destfile in
46325ffd6003Smrg	*.lo)
46335ffd6003Smrg	  func_lo2o "$destfile"
46345ffd6003Smrg	  staticdest=$func_lo2o_result
46355ffd6003Smrg	  ;;
46365ffd6003Smrg	*.$objext)
4637b7d26471Smrg	  staticdest=$destfile
46385ffd6003Smrg	  destfile=
46395ffd6003Smrg	  ;;
46405ffd6003Smrg	*)
4641b7d26471Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
46425ffd6003Smrg	  ;;
4643145b7b3cSmrg	esac
4644145b7b3cSmrg
46455ffd6003Smrg	# Install the libtool object if requested.
46465ffd6003Smrg	test -n "$destfile" && \
46475ffd6003Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
46485ffd6003Smrg
46495ffd6003Smrg	# Install the old object if enabled.
4650b7d26471Smrg	if test yes = "$build_old_libs"; then
46515ffd6003Smrg	  # Deduce the name of the old-style object file.
46525ffd6003Smrg	  func_lo2o "$file"
46535ffd6003Smrg	  staticobj=$func_lo2o_result
46545ffd6003Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4655145b7b3cSmrg	fi
46565ffd6003Smrg	exit $EXIT_SUCCESS
46575ffd6003Smrg	;;
4658145b7b3cSmrg
46595ffd6003Smrg      *)
46605ffd6003Smrg	# Figure out destination file name, if it wasn't already specified.
46615ffd6003Smrg	if test -n "$destname"; then
4662b7d26471Smrg	  destfile=$destdir/$destname
46635ffd6003Smrg	else
46645ffd6003Smrg	  func_basename "$file"
4665b7d26471Smrg	  destfile=$func_basename_result
4666b7d26471Smrg	  destfile=$destdir/$destfile
46675ffd6003Smrg	fi
4668145b7b3cSmrg
46695ffd6003Smrg	# If the file is missing, and there is a .exe on the end, strip it
46705ffd6003Smrg	# because it is most likely a libtool script we actually want to
46715ffd6003Smrg	# install
4672b7d26471Smrg	stripped_ext=
46735ffd6003Smrg	case $file in
46745ffd6003Smrg	  *.exe)
46755ffd6003Smrg	    if test ! -f "$file"; then
46765ffd6003Smrg	      func_stripname '' '.exe' "$file"
46775ffd6003Smrg	      file=$func_stripname_result
4678b7d26471Smrg	      stripped_ext=.exe
46795ffd6003Smrg	    fi
46805ffd6003Smrg	    ;;
46815ffd6003Smrg	esac
4682145b7b3cSmrg
46835ffd6003Smrg	# Do a test to see if this is really a libtool program.
46845ffd6003Smrg	case $host in
46855ffd6003Smrg	*cygwin* | *mingw*)
46865ffd6003Smrg	    if func_ltwrapper_executable_p "$file"; then
46875ffd6003Smrg	      func_ltwrapper_scriptname "$file"
46885ffd6003Smrg	      wrapper=$func_ltwrapper_scriptname_result
46895ffd6003Smrg	    else
46905ffd6003Smrg	      func_stripname '' '.exe' "$file"
46915ffd6003Smrg	      wrapper=$func_stripname_result
46925ffd6003Smrg	    fi
46935ffd6003Smrg	    ;;
46945ffd6003Smrg	*)
46955ffd6003Smrg	    wrapper=$file
46965ffd6003Smrg	    ;;
46975ffd6003Smrg	esac
46985ffd6003Smrg	if func_ltwrapper_script_p "$wrapper"; then
46995ffd6003Smrg	  notinst_deplibs=
47005ffd6003Smrg	  relink_command=
4701145b7b3cSmrg
47025ffd6003Smrg	  func_source "$wrapper"
47035ffd6003Smrg
47045ffd6003Smrg	  # Check the variables that should have been set.
47055ffd6003Smrg	  test -z "$generated_by_libtool_version" && \
4706b7d26471Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
47075ffd6003Smrg
4708b7d26471Smrg	  finalize=:
47095ffd6003Smrg	  for lib in $notinst_deplibs; do
47105ffd6003Smrg	    # Check to see that each library is installed.
47115ffd6003Smrg	    libdir=
47125ffd6003Smrg	    if test -f "$lib"; then
47135ffd6003Smrg	      func_source "$lib"
47145ffd6003Smrg	    fi
4715b7d26471Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
47165ffd6003Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717b7d26471Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718b7d26471Smrg	      finalize=false
47195ffd6003Smrg	    fi
47205ffd6003Smrg	  done
47215ffd6003Smrg
47225ffd6003Smrg	  relink_command=
47235ffd6003Smrg	  func_source "$wrapper"
47245ffd6003Smrg
47255ffd6003Smrg	  outputname=
4726b7d26471Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
47275ffd6003Smrg	    $opt_dry_run || {
4728b7d26471Smrg	      if $finalize; then
47295ffd6003Smrg	        tmpdir=`func_mktempdir`
47305ffd6003Smrg		func_basename "$file$stripped_ext"
4731b7d26471Smrg		file=$func_basename_result
4732b7d26471Smrg	        outputname=$tmpdir/$file
47335ffd6003Smrg	        # Replace the output file specification.
4734629baa8cSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
47355ffd6003Smrg
4736b7d26471Smrg	        $opt_quiet || {
4737da2e2ef6Smrg	          func_quote_arg expand,pretty "$relink_command"
4738da2e2ef6Smrg		  eval "func_echo $func_quote_arg_result"
47395ffd6003Smrg	        }
47405ffd6003Smrg	        if eval "$relink_command"; then :
47415ffd6003Smrg	          else
4742b7d26471Smrg		  func_error "error: relink '$file' with the above command before installing it"
47435ffd6003Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
47445ffd6003Smrg		  continue
47455ffd6003Smrg	        fi
4746b7d26471Smrg	        file=$outputname
47475ffd6003Smrg	      else
4748b7d26471Smrg	        func_warning "cannot relink '$file'"
47495ffd6003Smrg	      fi
47505ffd6003Smrg	    }
4751145b7b3cSmrg	  else
47525ffd6003Smrg	    # Install the binary that we compiled earlier.
4753629baa8cSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754145b7b3cSmrg	  fi
47555ffd6003Smrg	fi
4756145b7b3cSmrg
47575ffd6003Smrg	# remove .exe since cygwin /usr/bin/install will append another
47585ffd6003Smrg	# one anyway
47595ffd6003Smrg	case $install_prog,$host in
47605ffd6003Smrg	*/usr/bin/install*,*cygwin*)
47615ffd6003Smrg	  case $file:$destfile in
47625ffd6003Smrg	  *.exe:*.exe)
47635ffd6003Smrg	    # this is ok
47645ffd6003Smrg	    ;;
47655ffd6003Smrg	  *.exe:*)
47665ffd6003Smrg	    destfile=$destfile.exe
47675ffd6003Smrg	    ;;
47685ffd6003Smrg	  *:*.exe)
47695ffd6003Smrg	    func_stripname '' '.exe' "$destfile"
47705ffd6003Smrg	    destfile=$func_stripname_result
47715ffd6003Smrg	    ;;
47725ffd6003Smrg	  esac
4773145b7b3cSmrg	  ;;
4774145b7b3cSmrg	esac
47755ffd6003Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
47765ffd6003Smrg	$opt_dry_run || if test -n "$outputname"; then
47775ffd6003Smrg	  ${RM}r "$tmpdir"
47785ffd6003Smrg	fi
47795ffd6003Smrg	;;
47805ffd6003Smrg      esac
47815ffd6003Smrg    done
4782145b7b3cSmrg
47835ffd6003Smrg    for file in $staticlibs; do
47845ffd6003Smrg      func_basename "$file"
4785b7d26471Smrg      name=$func_basename_result
47865ffd6003Smrg
47875ffd6003Smrg      # Set up the ranlib parameters.
4788b7d26471Smrg      oldlib=$destdir/$name
4789b7d26471Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790b7d26471Smrg      tool_oldlib=$func_to_tool_file_result
47915ffd6003Smrg
47925ffd6003Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
47935ffd6003Smrg
47945ffd6003Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795b7d26471Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
47965ffd6003Smrg      fi
47975ffd6003Smrg
47985ffd6003Smrg      # Do each command in the postinstall commands.
47995ffd6003Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
48005ffd6003Smrg    done
48015ffd6003Smrg
48025ffd6003Smrg    test -n "$future_libdirs" && \
4803b7d26471Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
48045ffd6003Smrg
48055ffd6003Smrg    if test -n "$current_libdirs"; then
48065ffd6003Smrg      # Maybe just do a dry run.
48075ffd6003Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808b7d26471Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
48095ffd6003Smrg    else
48105ffd6003Smrg      exit $EXIT_SUCCESS
48115ffd6003Smrg    fi
48125ffd6003Smrg}
48135ffd6003Smrg
4814b7d26471Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
48155ffd6003Smrg
48165ffd6003Smrg
48175ffd6003Smrg# func_generate_dlsyms outputname originator pic_p
48185ffd6003Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
48195ffd6003Smrg# a dlpreopen symbol table.
48205ffd6003Smrgfunc_generate_dlsyms ()
48215ffd6003Smrg{
4822b7d26471Smrg    $debug_cmd
4823b7d26471Smrg
4824b7d26471Smrg    my_outputname=$1
4825b7d26471Smrg    my_originator=$2
4826b7d26471Smrg    my_pic_p=${3-false}
4827b7d26471Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
48285ffd6003Smrg    my_dlsyms=
48295ffd6003Smrg
4830b7d26471Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
48315ffd6003Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832b7d26471Smrg	my_dlsyms=${my_outputname}S.c
48335ffd6003Smrg      else
48345ffd6003Smrg	func_error "not configured to extract global symbols from dlpreopened files"
48355ffd6003Smrg      fi
48365ffd6003Smrg    fi
48375ffd6003Smrg
48385ffd6003Smrg    if test -n "$my_dlsyms"; then
48395ffd6003Smrg      case $my_dlsyms in
48405ffd6003Smrg      "") ;;
48415ffd6003Smrg      *.c)
48425ffd6003Smrg	# Discover the nlist of each of the dlfiles.
4843b7d26471Smrg	nlist=$output_objdir/$my_outputname.nm
48445ffd6003Smrg
48455ffd6003Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
48465ffd6003Smrg
48475ffd6003Smrg	# Parse the name list into a source file.
48485ffd6003Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
48495ffd6003Smrg
48505ffd6003Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851b7d26471Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852b7d26471Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
48535ffd6003Smrg
48545ffd6003Smrg#ifdef __cplusplus
48555ffd6003Smrgextern \"C\" {
48565ffd6003Smrg#endif
48575ffd6003Smrg
4858b7d26471Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4859629baa8cSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4860629baa8cSmrg#endif
4861629baa8cSmrg
4862629baa8cSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863b7d26471Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864b7d26471Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4865629baa8cSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4866629baa8cSmrg# define LT_DLSYM_CONST
4867b7d26471Smrg#elif defined __osf__
4868629baa8cSmrg/* This system does not cope well with relocations in const data.  */
4869629baa8cSmrg# define LT_DLSYM_CONST
4870629baa8cSmrg#else
4871629baa8cSmrg# define LT_DLSYM_CONST const
4872629baa8cSmrg#endif
4873629baa8cSmrg
4874b7d26471Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875b7d26471Smrg
48765ffd6003Smrg/* External symbol declarations for the compiler. */\
48775ffd6003Smrg"
48785ffd6003Smrg
4879b7d26471Smrg	if test yes = "$dlself"; then
4880b7d26471Smrg	  func_verbose "generating symbol list for '$output'"
48815ffd6003Smrg
48825ffd6003Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
48835ffd6003Smrg
48845ffd6003Smrg	  # Add our own program objects to the symbol list.
4885629baa8cSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
48865ffd6003Smrg	  for progfile in $progfiles; do
4887629baa8cSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888b7d26471Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4889629baa8cSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
48905ffd6003Smrg	  done
48915ffd6003Smrg
48925ffd6003Smrg	  if test -n "$exclude_expsyms"; then
48935ffd6003Smrg	    $opt_dry_run || {
48945ffd6003Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
48955ffd6003Smrg	      eval '$MV "$nlist"T "$nlist"'
48965ffd6003Smrg	    }
4897145b7b3cSmrg	  fi
48985ffd6003Smrg
48995ffd6003Smrg	  if test -n "$export_symbols_regex"; then
49005ffd6003Smrg	    $opt_dry_run || {
49015ffd6003Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
49025ffd6003Smrg	      eval '$MV "$nlist"T "$nlist"'
49035ffd6003Smrg	    }
49045ffd6003Smrg	  fi
49055ffd6003Smrg
49065ffd6003Smrg	  # Prepare the list of exported symbols
49075ffd6003Smrg	  if test -z "$export_symbols"; then
4908b7d26471Smrg	    export_symbols=$output_objdir/$outputname.exp
49095ffd6003Smrg	    $opt_dry_run || {
49105ffd6003Smrg	      $RM $export_symbols
4911b7d26471Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
49125ffd6003Smrg	      case $host in
49135ffd6003Smrg	      *cygwin* | *mingw* | *cegcc* )
49145ffd6003Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49155ffd6003Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
49165ffd6003Smrg	        ;;
49175ffd6003Smrg	      esac
49185ffd6003Smrg	    }
4919145b7b3cSmrg	  else
49205ffd6003Smrg	    $opt_dry_run || {
4921b7d26471Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
49225ffd6003Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
49235ffd6003Smrg	      eval '$MV "$nlist"T "$nlist"'
49245ffd6003Smrg	      case $host in
4925629baa8cSmrg	        *cygwin* | *mingw* | *cegcc* )
49265ffd6003Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
49275ffd6003Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
49285ffd6003Smrg	          ;;
49295ffd6003Smrg	      esac
49305ffd6003Smrg	    }
4931145b7b3cSmrg	  fi
49325ffd6003Smrg	fi
4933145b7b3cSmrg
49345ffd6003Smrg	for dlprefile in $dlprefiles; do
4935b7d26471Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
49365ffd6003Smrg	  func_basename "$dlprefile"
4937b7d26471Smrg	  name=$func_basename_result
4938629baa8cSmrg          case $host in
4939629baa8cSmrg	    *cygwin* | *mingw* | *cegcc* )
4940629baa8cSmrg	      # if an import library, we need to obtain dlname
4941629baa8cSmrg	      if func_win32_import_lib_p "$dlprefile"; then
4942629baa8cSmrg	        func_tr_sh "$dlprefile"
4943629baa8cSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944b7d26471Smrg	        dlprefile_dlbasename=
4945629baa8cSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4946629baa8cSmrg	          # Use subshell, to avoid clobbering current variable values
4947629baa8cSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948b7d26471Smrg	          if test -n "$dlprefile_dlname"; then
4949629baa8cSmrg	            func_basename "$dlprefile_dlname"
4950b7d26471Smrg	            dlprefile_dlbasename=$func_basename_result
4951629baa8cSmrg	          else
4952629baa8cSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4953629baa8cSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4954629baa8cSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4955629baa8cSmrg	          fi
4956629baa8cSmrg	        fi
4957629baa8cSmrg	        $opt_dry_run || {
4958b7d26471Smrg	          if test -n "$dlprefile_dlbasename"; then
4959629baa8cSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4960629baa8cSmrg	          else
4961629baa8cSmrg	            func_warning "Could not compute DLL name from $name"
4962629baa8cSmrg	            eval '$ECHO ": $name " >> "$nlist"'
4963629baa8cSmrg	          fi
4964629baa8cSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965629baa8cSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4966629baa8cSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4967629baa8cSmrg	        }
4968629baa8cSmrg	      else # not an import lib
4969629baa8cSmrg	        $opt_dry_run || {
4970629baa8cSmrg	          eval '$ECHO ": $name " >> "$nlist"'
4971629baa8cSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4972629baa8cSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4973629baa8cSmrg	        }
4974629baa8cSmrg	      fi
4975629baa8cSmrg	    ;;
4976629baa8cSmrg	    *)
4977629baa8cSmrg	      $opt_dry_run || {
4978629baa8cSmrg	        eval '$ECHO ": $name " >> "$nlist"'
4979629baa8cSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4980629baa8cSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4981629baa8cSmrg	      }
4982629baa8cSmrg	    ;;
4983629baa8cSmrg          esac
49845ffd6003Smrg	done
49855ffd6003Smrg
49865ffd6003Smrg	$opt_dry_run || {
49875ffd6003Smrg	  # Make sure we have at least an empty file.
49885ffd6003Smrg	  test -f "$nlist" || : > "$nlist"
49895ffd6003Smrg
49905ffd6003Smrg	  if test -n "$exclude_expsyms"; then
49915ffd6003Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
49925ffd6003Smrg	    $MV "$nlist"T "$nlist"
4993145b7b3cSmrg	  fi
49945ffd6003Smrg
49955ffd6003Smrg	  # Try sorting and uniquifying the output.
49965ffd6003Smrg	  if $GREP -v "^: " < "$nlist" |
49975ffd6003Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
49985ffd6003Smrg		sort -k 3
49995ffd6003Smrg	      else
50005ffd6003Smrg		sort +2
50015ffd6003Smrg	      fi |
50025ffd6003Smrg	      uniq > "$nlist"S; then
50035ffd6003Smrg	    :
5004145b7b3cSmrg	  else
50055ffd6003Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006145b7b3cSmrg	  fi
5007145b7b3cSmrg
50085ffd6003Smrg	  if test -f "$nlist"S; then
50095ffd6003Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010145b7b3cSmrg	  else
5011629baa8cSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012145b7b3cSmrg	  fi
5013145b7b3cSmrg
5014b7d26471Smrg	  func_show_eval '$RM "${nlist}I"'
5015b7d26471Smrg	  if test -n "$global_symbol_to_import"; then
5016b7d26471Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017b7d26471Smrg	  fi
5018b7d26471Smrg
5019629baa8cSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5020145b7b3cSmrg
50215ffd6003Smrg/* The mapping between symbol names and symbols.  */
50225ffd6003Smrgtypedef struct {
50235ffd6003Smrg  const char *name;
50245ffd6003Smrg  void *address;
50255ffd6003Smrg} lt_dlsymlist;
5026629baa8cSmrgextern LT_DLSYM_CONST lt_dlsymlist
5027b7d26471Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028b7d26471Smrg"
5029b7d26471Smrg
5030b7d26471Smrg	  if test -s "$nlist"I; then
5031b7d26471Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032b7d26471Smrgstatic void lt_syminit(void)
5033b7d26471Smrg{
5034b7d26471Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035b7d26471Smrg  for (; symbol->name; ++symbol)
5036b7d26471Smrg    {"
5037b7d26471Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038b7d26471Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039b7d26471Smrg    }
5040b7d26471Smrg}"
5041b7d26471Smrg	  fi
5042b7d26471Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5043629baa8cSmrgLT_DLSYM_CONST lt_dlsymlist
50445ffd6003Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045b7d26471Smrg{ {\"$my_originator\", (void *) 0},"
5046b7d26471Smrg
5047b7d26471Smrg	  if test -s "$nlist"I; then
5048b7d26471Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049b7d26471Smrg  {\"@INIT@\", (void *) &lt_syminit},"
5050b7d26471Smrg	  fi
5051145b7b3cSmrg
50525ffd6003Smrg	  case $need_lib_prefix in
50535ffd6003Smrg	  no)
50545ffd6003Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
50555ffd6003Smrg	    ;;
50565ffd6003Smrg	  *)
50575ffd6003Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
50585ffd6003Smrg	    ;;
50595ffd6003Smrg	  esac
5060629baa8cSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
50615ffd6003Smrg  {0, (void *) 0}
50625ffd6003Smrg};
5063145b7b3cSmrg
50645ffd6003Smrg/* This works around a problem in FreeBSD linker */
50655ffd6003Smrg#ifdef FREEBSD_WORKAROUND
50665ffd6003Smrgstatic const void *lt_preloaded_setup() {
50675ffd6003Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
50685ffd6003Smrg}
50695ffd6003Smrg#endif
50705ffd6003Smrg
50715ffd6003Smrg#ifdef __cplusplus
50725ffd6003Smrg}
50735ffd6003Smrg#endif\
50745ffd6003Smrg"
50755ffd6003Smrg	} # !$opt_dry_run
50765ffd6003Smrg
50775ffd6003Smrg	pic_flag_for_symtable=
50785ffd6003Smrg	case "$compile_command " in
50795ffd6003Smrg	*" -static "*) ;;
50805ffd6003Smrg	*)
50815ffd6003Smrg	  case $host in
50825ffd6003Smrg	  # compiling the symbol table file with pic_flag works around
50835ffd6003Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
50845ffd6003Smrg	  # linked before any other PIC object.  But we must not use
50855ffd6003Smrg	  # pic_flag when linking with -static.  The problem exists in
50865ffd6003Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087b7d26471Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
50885ffd6003Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
50895ffd6003Smrg	  *-*-hpux*)
50905ffd6003Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
50915ffd6003Smrg	  *)
5092b7d26471Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
50935ffd6003Smrg	    ;;
50945ffd6003Smrg	  esac
50955ffd6003Smrg	  ;;
50965ffd6003Smrg	esac
50975ffd6003Smrg	symtab_cflags=
50985ffd6003Smrg	for arg in $LTCFLAGS; do
50995ffd6003Smrg	  case $arg in
51005ffd6003Smrg	  -pie | -fpie | -fPIE) ;;
5101629baa8cSmrg	  *) func_append symtab_cflags " $arg" ;;
51025ffd6003Smrg	  esac
51035ffd6003Smrg	done
5104145b7b3cSmrg
51055ffd6003Smrg	# Now compile the dynamic symbol file.
51065ffd6003Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5107145b7b3cSmrg
51085ffd6003Smrg	# Clean up the generated files.
5109b7d26471Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5110145b7b3cSmrg
51115ffd6003Smrg	# Transform the symbol file into the correct name.
5112b7d26471Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
51135ffd6003Smrg	case $host in
51145ffd6003Smrg	*cygwin* | *mingw* | *cegcc* )
51155ffd6003Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
5116629baa8cSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5117629baa8cSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
51185ffd6003Smrg	  else
5119629baa8cSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5120629baa8cSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5121145b7b3cSmrg	  fi
51225ffd6003Smrg	  ;;
51235ffd6003Smrg	*)
5124629baa8cSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5125629baa8cSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
51265ffd6003Smrg	  ;;
51275ffd6003Smrg	esac
51285ffd6003Smrg	;;
51295ffd6003Smrg      *)
5130b7d26471Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
51315ffd6003Smrg	;;
51325ffd6003Smrg      esac
51335ffd6003Smrg    else
51345ffd6003Smrg      # We keep going just in case the user didn't refer to
51355ffd6003Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
51365ffd6003Smrg      # really was required.
5137145b7b3cSmrg
51385ffd6003Smrg      # Nullify the symbol file.
5139629baa8cSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5140629baa8cSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
51415ffd6003Smrg    fi
51425ffd6003Smrg}
5143145b7b3cSmrg
5144b7d26471Smrg# func_cygming_gnu_implib_p ARG
5145b7d26471Smrg# This predicate returns with zero status (TRUE) if
5146b7d26471Smrg# ARG is a GNU/binutils-style import library. Returns
5147b7d26471Smrg# with nonzero status (FALSE) otherwise.
5148b7d26471Smrgfunc_cygming_gnu_implib_p ()
5149b7d26471Smrg{
5150b7d26471Smrg  $debug_cmd
5151b7d26471Smrg
5152b7d26471Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153b7d26471Smrg  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)$'`
5154b7d26471Smrg  test -n "$func_cygming_gnu_implib_tmp"
5155b7d26471Smrg}
5156b7d26471Smrg
5157b7d26471Smrg# func_cygming_ms_implib_p ARG
5158b7d26471Smrg# This predicate returns with zero status (TRUE) if
5159b7d26471Smrg# ARG is an MS-style import library. Returns
5160b7d26471Smrg# with nonzero status (FALSE) otherwise.
5161b7d26471Smrgfunc_cygming_ms_implib_p ()
5162b7d26471Smrg{
5163b7d26471Smrg  $debug_cmd
5164b7d26471Smrg
5165b7d26471Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166b7d26471Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167b7d26471Smrg  test -n "$func_cygming_ms_implib_tmp"
5168b7d26471Smrg}
5169b7d26471Smrg
51705ffd6003Smrg# func_win32_libid arg
51715ffd6003Smrg# return the library type of file 'arg'
51725ffd6003Smrg#
51735ffd6003Smrg# Need a lot of goo to handle *both* DLLs and import libs
51745ffd6003Smrg# Has to be a shell function in order to 'eat' the argument
51755ffd6003Smrg# that is supplied when $file_magic_command is called.
5176629baa8cSmrg# Despite the name, also deal with 64 bit binaries.
51775ffd6003Smrgfunc_win32_libid ()
51785ffd6003Smrg{
5179b7d26471Smrg  $debug_cmd
5180b7d26471Smrg
5181b7d26471Smrg  win32_libid_type=unknown
51825ffd6003Smrg  win32_fileres=`file -L $1 2>/dev/null`
51835ffd6003Smrg  case $win32_fileres in
51845ffd6003Smrg  *ar\ archive\ import\ library*) # definitely import
51855ffd6003Smrg    win32_libid_type="x86 archive import"
51865ffd6003Smrg    ;;
51875ffd6003Smrg  *ar\ archive*) # could be an import, or static
5188629baa8cSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
51895ffd6003Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5190629baa8cSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191b7d26471Smrg      case $nm_interface in
5192b7d26471Smrg      "MS dumpbin")
5193b7d26471Smrg	if func_cygming_ms_implib_p "$1" ||
5194b7d26471Smrg	   func_cygming_gnu_implib_p "$1"
5195b7d26471Smrg	then
5196b7d26471Smrg	  win32_nmres=import
5197b7d26471Smrg	else
5198b7d26471Smrg	  win32_nmres=
5199b7d26471Smrg	fi
5200b7d26471Smrg	;;
5201b7d26471Smrg      *)
5202b7d26471Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203b7d26471Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204b7d26471Smrg	  $SED -n -e '
52055ffd6003Smrg	    1,100{
52065ffd6003Smrg		/ I /{
5207b7d26471Smrg		    s|.*|import|
52085ffd6003Smrg		    p
52095ffd6003Smrg		    q
52105ffd6003Smrg		}
52115ffd6003Smrg	    }'`
5212b7d26471Smrg	;;
5213b7d26471Smrg      esac
52145ffd6003Smrg      case $win32_nmres in
52155ffd6003Smrg      import*)  win32_libid_type="x86 archive import";;
52165ffd6003Smrg      *)        win32_libid_type="x86 archive static";;
52175ffd6003Smrg      esac
52185ffd6003Smrg    fi
52195ffd6003Smrg    ;;
52205ffd6003Smrg  *DLL*)
52215ffd6003Smrg    win32_libid_type="x86 DLL"
52225ffd6003Smrg    ;;
52235ffd6003Smrg  *executable*) # but shell scripts are "executable" too...
52245ffd6003Smrg    case $win32_fileres in
52255ffd6003Smrg    *MS\ Windows\ PE\ Intel*)
52265ffd6003Smrg      win32_libid_type="x86 DLL"
52275ffd6003Smrg      ;;
52285ffd6003Smrg    esac
52295ffd6003Smrg    ;;
52305ffd6003Smrg  esac
52315ffd6003Smrg  $ECHO "$win32_libid_type"
52325ffd6003Smrg}
5233145b7b3cSmrg
5234629baa8cSmrg# func_cygming_dll_for_implib ARG
5235629baa8cSmrg#
5236629baa8cSmrg# Platform-specific function to extract the
5237629baa8cSmrg# name of the DLL associated with the specified
5238629baa8cSmrg# import library ARG.
5239629baa8cSmrg# Invoked by eval'ing the libtool variable
5240629baa8cSmrg#    $sharedlib_from_linklib_cmd
5241629baa8cSmrg# Result is available in the variable
5242629baa8cSmrg#    $sharedlib_from_linklib_result
5243629baa8cSmrgfunc_cygming_dll_for_implib ()
5244629baa8cSmrg{
5245b7d26471Smrg  $debug_cmd
5246b7d26471Smrg
5247629baa8cSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5248629baa8cSmrg}
5249629baa8cSmrg
5250629baa8cSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5251629baa8cSmrg#
5252629baa8cSmrg# The is the core of a fallback implementation of a
5253629baa8cSmrg# platform-specific function to extract the name of the
5254629baa8cSmrg# DLL associated with the specified import library LIBNAME.
5255629baa8cSmrg#
5256629baa8cSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5257629baa8cSmrg# on the platform and compiler that created the implib.
5258629baa8cSmrg#
5259629baa8cSmrg# Echos the name of the DLL associated with the
5260629baa8cSmrg# specified import library.
5261629baa8cSmrgfunc_cygming_dll_for_implib_fallback_core ()
5262629baa8cSmrg{
5263b7d26471Smrg  $debug_cmd
5264b7d26471Smrg
5265629baa8cSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5266629baa8cSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5267629baa8cSmrg    $SED '/^Contents of section '"$match_literal"':/{
5268629baa8cSmrg      # Place marker at beginning of archive member dllname section
5269629baa8cSmrg      s/.*/====MARK====/
5270629baa8cSmrg      p
5271629baa8cSmrg      d
5272629baa8cSmrg    }
5273629baa8cSmrg    # These lines can sometimes be longer than 43 characters, but
5274629baa8cSmrg    # are always uninteresting
5275629baa8cSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5276629baa8cSmrg    /^In archive [^:]*:/d
5277629baa8cSmrg    # Ensure marker is printed
5278629baa8cSmrg    /^====MARK====/p
5279629baa8cSmrg    # Remove all lines with less than 43 characters
5280629baa8cSmrg    /^.\{43\}/!d
5281629baa8cSmrg    # From remaining lines, remove first 43 characters
5282629baa8cSmrg    s/^.\{43\}//' |
5283629baa8cSmrg    $SED -n '
5284629baa8cSmrg      # Join marker and all lines until next marker into a single line
5285629baa8cSmrg      /^====MARK====/ b para
5286629baa8cSmrg      H
5287629baa8cSmrg      $ b para
5288629baa8cSmrg      b
5289629baa8cSmrg      :para
5290629baa8cSmrg      x
5291629baa8cSmrg      s/\n//g
5292629baa8cSmrg      # Remove the marker
5293629baa8cSmrg      s/^====MARK====//
5294629baa8cSmrg      # Remove trailing dots and whitespace
5295629baa8cSmrg      s/[\. \t]*$//
5296629baa8cSmrg      # Print
5297629baa8cSmrg      /./p' |
5298629baa8cSmrg    # we now have a list, one entry per line, of the stringified
5299629baa8cSmrg    # contents of the appropriate section of all members of the
5300b7d26471Smrg    # archive that possess that section. Heuristic: eliminate
5301b7d26471Smrg    # all those that have a first or second character that is
5302629baa8cSmrg    # a '.' (that is, objdump's representation of an unprintable
5303629baa8cSmrg    # character.) This should work for all archives with less than
5304629baa8cSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5305629baa8cSmrg    # begins with a literal '.' or a single character followed by
5306629baa8cSmrg    # a '.'.
5307629baa8cSmrg    #
5308629baa8cSmrg    # Of those that remain, print the first one.
5309629baa8cSmrg    $SED -e '/^\./d;/^.\./d;q'
5310629baa8cSmrg}
5311629baa8cSmrg
5312629baa8cSmrg# func_cygming_dll_for_implib_fallback ARG
5313629baa8cSmrg# Platform-specific function to extract the
5314629baa8cSmrg# name of the DLL associated with the specified
5315629baa8cSmrg# import library ARG.
5316629baa8cSmrg#
5317629baa8cSmrg# This fallback implementation is for use when $DLLTOOL
5318629baa8cSmrg# does not support the --identify-strict option.
5319629baa8cSmrg# Invoked by eval'ing the libtool variable
5320629baa8cSmrg#    $sharedlib_from_linklib_cmd
5321629baa8cSmrg# Result is available in the variable
5322629baa8cSmrg#    $sharedlib_from_linklib_result
5323629baa8cSmrgfunc_cygming_dll_for_implib_fallback ()
5324629baa8cSmrg{
5325b7d26471Smrg  $debug_cmd
5326b7d26471Smrg
5327b7d26471Smrg  if func_cygming_gnu_implib_p "$1"; then
5328629baa8cSmrg    # binutils import library
5329629baa8cSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330b7d26471Smrg  elif func_cygming_ms_implib_p "$1"; then
5331629baa8cSmrg    # ms-generated import library
5332629baa8cSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5333629baa8cSmrg  else
5334629baa8cSmrg    # unknown
5335b7d26471Smrg    sharedlib_from_linklib_result=
5336629baa8cSmrg  fi
5337629baa8cSmrg}
5338145b7b3cSmrg
5339145b7b3cSmrg
53405ffd6003Smrg# func_extract_an_archive dir oldlib
53415ffd6003Smrgfunc_extract_an_archive ()
53425ffd6003Smrg{
5343b7d26471Smrg    $debug_cmd
5344b7d26471Smrg
5345b7d26471Smrg    f_ex_an_ar_dir=$1; shift
5346b7d26471Smrg    f_ex_an_ar_oldlib=$1
5347b7d26471Smrg    if test yes = "$lock_old_archive_extraction"; then
5348629baa8cSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5349629baa8cSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5350629baa8cSmrg	func_echo "Waiting for $lockfile to be removed"
5351629baa8cSmrg	sleep 2
5352629baa8cSmrg      done
5353629baa8cSmrg    fi
5354629baa8cSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5355629baa8cSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356b7d26471Smrg    if test yes = "$lock_old_archive_extraction"; then
5357629baa8cSmrg      $opt_dry_run || rm -f "$lockfile"
5358629baa8cSmrg    fi
53595ffd6003Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
53605ffd6003Smrg     :
53615ffd6003Smrg    else
53625ffd6003Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
53635ffd6003Smrg    fi
53645ffd6003Smrg}
5365145b7b3cSmrg
5366145b7b3cSmrg
53675ffd6003Smrg# func_extract_archives gentop oldlib ...
53685ffd6003Smrgfunc_extract_archives ()
53695ffd6003Smrg{
5370b7d26471Smrg    $debug_cmd
5371b7d26471Smrg
5372b7d26471Smrg    my_gentop=$1; shift
53735ffd6003Smrg    my_oldlibs=${1+"$@"}
5374b7d26471Smrg    my_oldobjs=
5375b7d26471Smrg    my_xlib=
5376b7d26471Smrg    my_xabs=
5377b7d26471Smrg    my_xdir=
5378145b7b3cSmrg
53795ffd6003Smrg    for my_xlib in $my_oldlibs; do
53805ffd6003Smrg      # Extract the objects.
53815ffd6003Smrg      case $my_xlib in
5382b7d26471Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
53835ffd6003Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
53845ffd6003Smrg      esac
53855ffd6003Smrg      func_basename "$my_xlib"
5386b7d26471Smrg      my_xlib=$func_basename_result
53875ffd6003Smrg      my_xlib_u=$my_xlib
53885ffd6003Smrg      while :; do
53895ffd6003Smrg        case " $extracted_archives " in
53905ffd6003Smrg	*" $my_xlib_u "*)
53915ffd6003Smrg	  func_arith $extracted_serial + 1
53925ffd6003Smrg	  extracted_serial=$func_arith_result
53935ffd6003Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
53945ffd6003Smrg	*) break ;;
53955ffd6003Smrg	esac
53965ffd6003Smrg      done
53975ffd6003Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5398b7d26471Smrg      my_xdir=$my_gentop/$my_xlib_u
5399145b7b3cSmrg
54005ffd6003Smrg      func_mkdir_p "$my_xdir"
5401145b7b3cSmrg
54025ffd6003Smrg      case $host in
54035ffd6003Smrg      *-darwin*)
54045ffd6003Smrg	func_verbose "Extracting $my_xabs"
54055ffd6003Smrg	# Do not bother doing anything if just a dry run
54065ffd6003Smrg	$opt_dry_run || {
54075ffd6003Smrg	  darwin_orig_dir=`pwd`
54085ffd6003Smrg	  cd $my_xdir || exit $?
54095ffd6003Smrg	  darwin_archive=$my_xabs
54105ffd6003Smrg	  darwin_curdir=`pwd`
5411b7d26471Smrg	  func_basename "$darwin_archive"
5412b7d26471Smrg	  darwin_base_archive=$func_basename_result
54135ffd6003Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
54145ffd6003Smrg	  if test -n "$darwin_arches"; then
54155ffd6003Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
54165ffd6003Smrg	    darwin_arch=
54175ffd6003Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418b7d26471Smrg	    for darwin_arch in  $darwin_arches; do
5419b7d26471Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420b7d26471Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421b7d26471Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422b7d26471Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
54235ffd6003Smrg	      cd "$darwin_curdir"
5424b7d26471Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
54255ffd6003Smrg	    done # $darwin_arches
54265ffd6003Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427b7d26471Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
54285ffd6003Smrg	    darwin_file=
54295ffd6003Smrg	    darwin_files=
54305ffd6003Smrg	    for darwin_file in $darwin_filelist; do
5431629baa8cSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
54325ffd6003Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
54335ffd6003Smrg	    done # $darwin_filelist
54345ffd6003Smrg	    $RM -rf unfat-$$
54355ffd6003Smrg	    cd "$darwin_orig_dir"
5436145b7b3cSmrg	  else
54375ffd6003Smrg	    cd $darwin_orig_dir
54385ffd6003Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
54395ffd6003Smrg	  fi # $darwin_arches
54405ffd6003Smrg	} # !$opt_dry_run
54415ffd6003Smrg	;;
54425ffd6003Smrg      *)
54435ffd6003Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
54445ffd6003Smrg	;;
54455ffd6003Smrg      esac
5446629baa8cSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
54475ffd6003Smrg    done
5448145b7b3cSmrg
5449b7d26471Smrg    func_extract_archives_result=$my_oldobjs
54505ffd6003Smrg}
5451145b7b3cSmrg
5452145b7b3cSmrg
5453629baa8cSmrg# func_emit_wrapper [arg=no]
5454629baa8cSmrg#
5455629baa8cSmrg# Emit a libtool wrapper script on stdout.
5456629baa8cSmrg# Don't directly open a file because we may want to
5457629baa8cSmrg# incorporate the script contents within a cygwin/mingw
5458629baa8cSmrg# wrapper executable.  Must ONLY be called from within
5459629baa8cSmrg# func_mode_link because it depends on a number of variables
5460629baa8cSmrg# set therein.
54615ffd6003Smrg#
5462629baa8cSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5463629baa8cSmrg# variable will take.  If 'yes', then the emitted script
5464b7d26471Smrg# will assume that the directory where it is stored is
5465629baa8cSmrg# the $objdir directory.  This is a cygwin/mingw-specific
5466629baa8cSmrg# behavior.
5467629baa8cSmrgfunc_emit_wrapper ()
54685ffd6003Smrg{
5469629baa8cSmrg	func_emit_wrapper_arg1=${1-no}
5470145b7b3cSmrg
54715ffd6003Smrg	$ECHO "\
54725ffd6003Smrg#! $SHELL
5473145b7b3cSmrg
54745ffd6003Smrg# $output - temporary wrapper script for $objdir/$outputname
5475b7d26471Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
54765ffd6003Smrg#
54775ffd6003Smrg# The $output program cannot be directly executed until all the libtool
54785ffd6003Smrg# libraries that it depends on are installed.
54795ffd6003Smrg#
54805ffd6003Smrg# This wrapper script should never be moved out of the build directory.
54815ffd6003Smrg# If it is, it will not operate correctly.
5482145b7b3cSmrg
54835ffd6003Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
54845ffd6003Smrg# metacharacters that are still active within double-quoted strings.
54855ffd6003Smrgsed_quote_subst='$sed_quote_subst'
5486145b7b3cSmrg
54875ffd6003Smrg# Be Bourne compatible
54885ffd6003Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
54895ffd6003Smrg  emulate sh
54905ffd6003Smrg  NULLCMD=:
54915ffd6003Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
54925ffd6003Smrg  # is contrary to our usage.  Disable this feature.
54935ffd6003Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
54945ffd6003Smrg  setopt NO_GLOB_SUBST
54955ffd6003Smrgelse
54965ffd6003Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
54975ffd6003Smrgfi
54985ffd6003SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
54995ffd6003SmrgDUALCASE=1; export DUALCASE # for MKS sh
5500145b7b3cSmrg
55015ffd6003Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
55025ffd6003Smrg# if CDPATH is set.
55035ffd6003Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5504145b7b3cSmrg
55055ffd6003Smrgrelink_command=\"$relink_command\"
5506145b7b3cSmrg
55075ffd6003Smrg# This environment variable determines our operation mode.
55085ffd6003Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
55095ffd6003Smrg  # install mode needs the following variables:
55105ffd6003Smrg  generated_by_libtool_version='$macro_version'
55115ffd6003Smrg  notinst_deplibs='$notinst_deplibs'
55125ffd6003Smrgelse
55135ffd6003Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
55145ffd6003Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5515629baa8cSmrg    file=\"\$0\""
5516629baa8cSmrg
5517da2e2ef6Smrg    func_quote_arg pretty "$ECHO"
5518da2e2ef6Smrg    qECHO=$func_quote_arg_result
5519629baa8cSmrg    $ECHO "\
5520629baa8cSmrg
5521629baa8cSmrg# A function that is used when there is no print builtin or printf.
5522629baa8cSmrgfunc_fallback_echo ()
5523629baa8cSmrg{
5524629baa8cSmrg  eval 'cat <<_LTECHO_EOF
5525629baa8cSmrg\$1
5526629baa8cSmrg_LTECHO_EOF'
5527629baa8cSmrg}
5528da2e2ef6Smrg    ECHO=$qECHO
5529629baa8cSmrg  fi
5530629baa8cSmrg
5531629baa8cSmrg# Very basic option parsing. These options are (a) specific to
5532629baa8cSmrg# the libtool wrapper, (b) are identical between the wrapper
5533b7d26471Smrg# /script/ and the wrapper /executable/ that is used only on
5534629baa8cSmrg# windows platforms, and (c) all begin with the string "--lt-"
5535b7d26471Smrg# (application programs are unlikely to have options that match
5536629baa8cSmrg# this pattern).
5537629baa8cSmrg#
5538629baa8cSmrg# There are only two supported options: --lt-debug and
5539629baa8cSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5540629baa8cSmrg#
5541629baa8cSmrg# The first argument to this parsing function should be the
5542629baa8cSmrg# script's $0 value, followed by "$@".
5543629baa8cSmrglt_option_debug=
5544629baa8cSmrgfunc_parse_lt_options ()
5545629baa8cSmrg{
5546629baa8cSmrg  lt_script_arg0=\$0
5547629baa8cSmrg  shift
5548629baa8cSmrg  for lt_opt
5549629baa8cSmrg  do
5550629baa8cSmrg    case \"\$lt_opt\" in
5551629baa8cSmrg    --lt-debug) lt_option_debug=1 ;;
5552629baa8cSmrg    --lt-dump-script)
5553629baa8cSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5554629baa8cSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5555629baa8cSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5556629baa8cSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5557629baa8cSmrg        exit 0
5558629baa8cSmrg      ;;
5559629baa8cSmrg    --lt-*)
5560629baa8cSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5561629baa8cSmrg        exit 1
5562629baa8cSmrg      ;;
5563629baa8cSmrg    esac
5564629baa8cSmrg  done
5565629baa8cSmrg
5566629baa8cSmrg  # Print the debug banner immediately:
5567629baa8cSmrg  if test -n \"\$lt_option_debug\"; then
5568b7d26471Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5569629baa8cSmrg  fi
5570629baa8cSmrg}
5571629baa8cSmrg
5572629baa8cSmrg# Used when --lt-debug. Prints its arguments to stdout
5573629baa8cSmrg# (redirection is the responsibility of the caller)
5574629baa8cSmrgfunc_lt_dump_args ()
5575629baa8cSmrg{
5576629baa8cSmrg  lt_dump_args_N=1;
5577629baa8cSmrg  for lt_arg
5578629baa8cSmrg  do
5579b7d26471Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5580629baa8cSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5581629baa8cSmrg  done
5582629baa8cSmrg}
5583629baa8cSmrg
5584629baa8cSmrg# Core function for launching the target application
5585629baa8cSmrgfunc_exec_program_core ()
5586629baa8cSmrg{
55875ffd6003Smrg"
5588629baa8cSmrg  case $host in
5589629baa8cSmrg  # Backslashes separate directories on plain windows
5590629baa8cSmrg  *-*-mingw | *-*-os2* | *-cegcc*)
5591629baa8cSmrg    $ECHO "\
5592629baa8cSmrg      if test -n \"\$lt_option_debug\"; then
5593b7d26471Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5594629baa8cSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5595629baa8cSmrg      fi
5596629baa8cSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5597629baa8cSmrg"
5598629baa8cSmrg    ;;
5599629baa8cSmrg
5600629baa8cSmrg  *)
5601629baa8cSmrg    $ECHO "\
5602629baa8cSmrg      if test -n \"\$lt_option_debug\"; then
5603b7d26471Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5604629baa8cSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5605629baa8cSmrg      fi
5606629baa8cSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5607629baa8cSmrg"
5608629baa8cSmrg    ;;
5609629baa8cSmrg  esac
5610629baa8cSmrg  $ECHO "\
5611629baa8cSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5612629baa8cSmrg      exit 1
5613629baa8cSmrg}
5614629baa8cSmrg
5615629baa8cSmrg# A function to encapsulate launching the target application
5616629baa8cSmrg# Strips options in the --lt-* namespace from \$@ and
5617629baa8cSmrg# launches target application with the remaining arguments.
5618629baa8cSmrgfunc_exec_program ()
5619629baa8cSmrg{
5620b7d26471Smrg  case \" \$* \" in
5621b7d26471Smrg  *\\ --lt-*)
5622b7d26471Smrg    for lt_wr_arg
5623b7d26471Smrg    do
5624b7d26471Smrg      case \$lt_wr_arg in
5625b7d26471Smrg      --lt-*) ;;
5626b7d26471Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627b7d26471Smrg      esac
5628b7d26471Smrg      shift
5629b7d26471Smrg    done ;;
5630b7d26471Smrg  esac
5631629baa8cSmrg  func_exec_program_core \${1+\"\$@\"}
5632629baa8cSmrg}
5633629baa8cSmrg
5634629baa8cSmrg  # Parse options
5635629baa8cSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5636145b7b3cSmrg
56375ffd6003Smrg  # Find the directory that this script lives in.
5638629baa8cSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
56395ffd6003Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5640145b7b3cSmrg
56415ffd6003Smrg  # Follow symbolic links until we get to the real thisdir.
5642629baa8cSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
56435ffd6003Smrg  while test -n \"\$file\"; do
5644629baa8cSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5645145b7b3cSmrg
56465ffd6003Smrg    # If there was a directory component, then change thisdir.
56475ffd6003Smrg    if test \"x\$destdir\" != \"x\$file\"; then
56485ffd6003Smrg      case \"\$destdir\" in
56495ffd6003Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
56505ffd6003Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5651145b7b3cSmrg      esac
56525ffd6003Smrg    fi
5653145b7b3cSmrg
5654629baa8cSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5655629baa8cSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
56565ffd6003Smrg  done
5657145b7b3cSmrg
56585ffd6003Smrg  # Usually 'no', except on cygwin/mingw when embedded into
56595ffd6003Smrg  # the cwrapper.
5660629baa8cSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
56615ffd6003Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
56625ffd6003Smrg    # special case for '.'
56635ffd6003Smrg    if test \"\$thisdir\" = \".\"; then
56645ffd6003Smrg      thisdir=\`pwd\`
56655ffd6003Smrg    fi
56665ffd6003Smrg    # remove .libs from thisdir
56675ffd6003Smrg    case \"\$thisdir\" in
5668629baa8cSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
56695ffd6003Smrg    $objdir )   thisdir=. ;;
56705ffd6003Smrg    esac
56715ffd6003Smrg  fi
56725ffd6003Smrg
56735ffd6003Smrg  # Try to get the absolute directory name.
56745ffd6003Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
56755ffd6003Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
56765ffd6003Smrg"
56775ffd6003Smrg
5678b7d26471Smrg	if test yes = "$fast_install"; then
56795ffd6003Smrg	  $ECHO "\
56805ffd6003Smrg  program=lt-'$outputname'$exeext
56815ffd6003Smrg  progdir=\"\$thisdir/$objdir\"
56825ffd6003Smrg
56835ffd6003Smrg  if test ! -f \"\$progdir/\$program\" ||
5684b7d26471Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
56855ffd6003Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
56865ffd6003Smrg
56875ffd6003Smrg    file=\"\$\$-\$program\"
56885ffd6003Smrg
56895ffd6003Smrg    if test ! -d \"\$progdir\"; then
56905ffd6003Smrg      $MKDIR \"\$progdir\"
56915ffd6003Smrg    else
56925ffd6003Smrg      $RM \"\$progdir/\$file\"
56935ffd6003Smrg    fi"
56945ffd6003Smrg
56955ffd6003Smrg	  $ECHO "\
56965ffd6003Smrg
56975ffd6003Smrg    # relink executable if necessary
56985ffd6003Smrg    if test -n \"\$relink_command\"; then
56995ffd6003Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
57005ffd6003Smrg      else
5701b7d26471Smrg	\$ECHO \"\$relink_command_output\" >&2
57025ffd6003Smrg	$RM \"\$progdir/\$file\"
57035ffd6003Smrg	exit 1
5704145b7b3cSmrg      fi
57055ffd6003Smrg    fi
5706145b7b3cSmrg
57075ffd6003Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
57085ffd6003Smrg    { $RM \"\$progdir/\$program\";
57095ffd6003Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
57105ffd6003Smrg    $RM \"\$progdir/\$file\"
57115ffd6003Smrg  fi"
57125ffd6003Smrg	else
57135ffd6003Smrg	  $ECHO "\
57145ffd6003Smrg  program='$outputname'
57155ffd6003Smrg  progdir=\"\$thisdir/$objdir\"
57165ffd6003Smrg"
5717145b7b3cSmrg	fi
5718145b7b3cSmrg
57195ffd6003Smrg	$ECHO "\
5720145b7b3cSmrg
57215ffd6003Smrg  if test -f \"\$progdir/\$program\"; then"
5722145b7b3cSmrg
5723629baa8cSmrg	# fixup the dll searchpath if we need to.
5724629baa8cSmrg	#
5725629baa8cSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5726629baa8cSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5727629baa8cSmrg	# libraries must come first.
5728629baa8cSmrg	if test -n "$dllsearchpath"; then
5729629baa8cSmrg	  $ECHO "\
5730629baa8cSmrg    # Add the dll search path components to the executable PATH
5731629baa8cSmrg    PATH=$dllsearchpath:\$PATH
5732629baa8cSmrg"
5733629baa8cSmrg	fi
5734629baa8cSmrg
57355ffd6003Smrg	# Export our shlibpath_var if we have one.
5736b7d26471Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
57375ffd6003Smrg	  $ECHO "\
57385ffd6003Smrg    # Add our own library path to $shlibpath_var
57395ffd6003Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740145b7b3cSmrg
57415ffd6003Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
57425ffd6003Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5743629baa8cSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
57445ffd6003Smrg
57455ffd6003Smrg    export $shlibpath_var
57465ffd6003Smrg"
5747145b7b3cSmrg	fi
5748145b7b3cSmrg
57495ffd6003Smrg	$ECHO "\
57505ffd6003Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
57515ffd6003Smrg      # Run the actual program with our arguments.
5752629baa8cSmrg      func_exec_program \${1+\"\$@\"}
57535ffd6003Smrg    fi
57545ffd6003Smrg  else
57555ffd6003Smrg    # The program doesn't exist.
5756b7d26471Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
57575ffd6003Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5758629baa8cSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
57595ffd6003Smrg    exit 1
57605ffd6003Smrg  fi
57615ffd6003Smrgfi\
57625ffd6003Smrg"
57635ffd6003Smrg}
5764145b7b3cSmrg
5765145b7b3cSmrg
57665ffd6003Smrg# func_emit_cwrapperexe_src
57675ffd6003Smrg# emit the source code for a wrapper executable on stdout
57685ffd6003Smrg# Must ONLY be called from within func_mode_link because
57695ffd6003Smrg# it depends on a number of variable set therein.
57705ffd6003Smrgfunc_emit_cwrapperexe_src ()
57715ffd6003Smrg{
57725ffd6003Smrg	cat <<EOF
5773145b7b3cSmrg
57745ffd6003Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775b7d26471Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5776145b7b3cSmrg
57775ffd6003Smrg   The $output program cannot be directly executed until all the libtool
57785ffd6003Smrg   libraries that it depends on are installed.
5779145b7b3cSmrg
57805ffd6003Smrg   This wrapper executable should never be moved out of the build directory.
57815ffd6003Smrg   If it is, it will not operate correctly.
57825ffd6003Smrg*/
57835ffd6003SmrgEOF
57845ffd6003Smrg	    cat <<"EOF"
5785629baa8cSmrg#ifdef _MSC_VER
5786629baa8cSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5787629baa8cSmrg#endif
57885ffd6003Smrg#include <stdio.h>
57895ffd6003Smrg#include <stdlib.h>
57905ffd6003Smrg#ifdef _MSC_VER
57915ffd6003Smrg# include <direct.h>
57925ffd6003Smrg# include <process.h>
57935ffd6003Smrg# include <io.h>
57945ffd6003Smrg#else
57955ffd6003Smrg# include <unistd.h>
57965ffd6003Smrg# include <stdint.h>
57975ffd6003Smrg# ifdef __CYGWIN__
57985ffd6003Smrg#  include <io.h>
5799629baa8cSmrg# endif
5800629baa8cSmrg#endif
5801629baa8cSmrg#include <malloc.h>
5802629baa8cSmrg#include <stdarg.h>
5803629baa8cSmrg#include <assert.h>
5804629baa8cSmrg#include <string.h>
5805629baa8cSmrg#include <ctype.h>
5806629baa8cSmrg#include <errno.h>
5807629baa8cSmrg#include <fcntl.h>
5808629baa8cSmrg#include <sys/stat.h>
5809629baa8cSmrg
5810b7d26471Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811b7d26471Smrg
5812629baa8cSmrg/* declarations of non-ANSI functions */
5813b7d26471Smrg#if defined __MINGW32__
5814629baa8cSmrg# ifdef __STRICT_ANSI__
5815629baa8cSmrgint _putenv (const char *);
5816629baa8cSmrg# endif
5817b7d26471Smrg#elif defined __CYGWIN__
5818629baa8cSmrg# ifdef __STRICT_ANSI__
58195ffd6003Smrgchar *realpath (const char *, char *);
58205ffd6003Smrgint putenv (char *);
58215ffd6003Smrgint setenv (const char *, const char *, int);
58225ffd6003Smrg# endif
5823b7d26471Smrg/* #elif defined other_platform || defined ... */
5824629baa8cSmrg#endif
5825629baa8cSmrg
5826629baa8cSmrg/* portability defines, excluding path handling macros */
5827b7d26471Smrg#if defined _MSC_VER
5828629baa8cSmrg# define setmode _setmode
5829629baa8cSmrg# define stat    _stat
5830629baa8cSmrg# define chmod   _chmod
5831629baa8cSmrg# define getcwd  _getcwd
5832629baa8cSmrg# define putenv  _putenv
5833629baa8cSmrg# define S_IXUSR _S_IEXEC
5834b7d26471Smrg#elif defined __MINGW32__
5835629baa8cSmrg# define setmode _setmode
5836629baa8cSmrg# define stat    _stat
5837629baa8cSmrg# define chmod   _chmod
5838629baa8cSmrg# define getcwd  _getcwd
5839629baa8cSmrg# define putenv  _putenv
5840b7d26471Smrg#elif defined __CYGWIN__
5841629baa8cSmrg# define HAVE_SETENV
5842629baa8cSmrg# define FOPEN_WB "wb"
5843b7d26471Smrg/* #elif defined other platforms ... */
58445ffd6003Smrg#endif
5845145b7b3cSmrg
5846b7d26471Smrg#if defined PATH_MAX
58475ffd6003Smrg# define LT_PATHMAX PATH_MAX
5848b7d26471Smrg#elif defined MAXPATHLEN
58495ffd6003Smrg# define LT_PATHMAX MAXPATHLEN
58505ffd6003Smrg#else
58515ffd6003Smrg# define LT_PATHMAX 1024
58525ffd6003Smrg#endif
5853145b7b3cSmrg
58545ffd6003Smrg#ifndef S_IXOTH
58555ffd6003Smrg# define S_IXOTH 0
58565ffd6003Smrg#endif
58575ffd6003Smrg#ifndef S_IXGRP
58585ffd6003Smrg# define S_IXGRP 0
58595ffd6003Smrg#endif
5860145b7b3cSmrg
5861629baa8cSmrg/* path handling portability macros */
58625ffd6003Smrg#ifndef DIR_SEPARATOR
58635ffd6003Smrg# define DIR_SEPARATOR '/'
58645ffd6003Smrg# define PATH_SEPARATOR ':'
58655ffd6003Smrg#endif
5866145b7b3cSmrg
5867b7d26471Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868b7d26471Smrg  defined __OS2__
58695ffd6003Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
58705ffd6003Smrg# define FOPEN_WB "wb"
58715ffd6003Smrg# ifndef DIR_SEPARATOR_2
58725ffd6003Smrg#  define DIR_SEPARATOR_2 '\\'
58735ffd6003Smrg# endif
58745ffd6003Smrg# ifndef PATH_SEPARATOR_2
58755ffd6003Smrg#  define PATH_SEPARATOR_2 ';'
58765ffd6003Smrg# endif
58775ffd6003Smrg#endif
5878145b7b3cSmrg
58795ffd6003Smrg#ifndef DIR_SEPARATOR_2
58805ffd6003Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
58815ffd6003Smrg#else /* DIR_SEPARATOR_2 */
58825ffd6003Smrg# define IS_DIR_SEPARATOR(ch) \
58835ffd6003Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
58845ffd6003Smrg#endif /* DIR_SEPARATOR_2 */
5885145b7b3cSmrg
58865ffd6003Smrg#ifndef PATH_SEPARATOR_2
58875ffd6003Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
58885ffd6003Smrg#else /* PATH_SEPARATOR_2 */
58895ffd6003Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
58905ffd6003Smrg#endif /* PATH_SEPARATOR_2 */
5891145b7b3cSmrg
58925ffd6003Smrg#ifndef FOPEN_WB
58935ffd6003Smrg# define FOPEN_WB "w"
58945ffd6003Smrg#endif
58955ffd6003Smrg#ifndef _O_BINARY
58965ffd6003Smrg# define _O_BINARY 0
58975ffd6003Smrg#endif
5898145b7b3cSmrg
58995ffd6003Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
59005ffd6003Smrg#define XFREE(stale) do { \
5901b7d26471Smrg  if (stale) { free (stale); stale = 0; } \
59025ffd6003Smrg} while (0)
5903145b7b3cSmrg
5904b7d26471Smrg#if defined LT_DEBUGWRAPPER
5905629baa8cSmrgstatic int lt_debug = 1;
59065ffd6003Smrg#else
5907629baa8cSmrgstatic int lt_debug = 0;
59085ffd6003Smrg#endif
5909145b7b3cSmrg
5910629baa8cSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5911145b7b3cSmrg
59125ffd6003Smrgvoid *xmalloc (size_t num);
59135ffd6003Smrgchar *xstrdup (const char *string);
59145ffd6003Smrgconst char *base_name (const char *name);
59155ffd6003Smrgchar *find_executable (const char *wrapper);
59165ffd6003Smrgchar *chase_symlinks (const char *pathspec);
59175ffd6003Smrgint make_executable (const char *path);
59185ffd6003Smrgint check_executable (const char *path);
59195ffd6003Smrgchar *strendzap (char *str, const char *pat);
5920629baa8cSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5921629baa8cSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5922629baa8cSmrgstatic const char *nonnull (const char *s);
5923629baa8cSmrgstatic const char *nonempty (const char *s);
59245ffd6003Smrgvoid lt_setenv (const char *name, const char *value);
59255ffd6003Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
59265ffd6003Smrgvoid lt_update_exe_path (const char *name, const char *value);
59275ffd6003Smrgvoid lt_update_lib_path (const char *name, const char *value);
5928629baa8cSmrgchar **prepare_spawn (char **argv);
5929629baa8cSmrgvoid lt_dump_script (FILE *f);
59305ffd6003SmrgEOF
59315ffd6003Smrg
59325ffd6003Smrg	    cat <<EOF
5933b7d26471Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934b7d26471Smrg# define externally_visible volatile
5935b7d26471Smrg#else
5936b7d26471Smrg# define externally_visible __attribute__((externally_visible)) volatile
5937b7d26471Smrg#endif
5938b7d26471Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
59395ffd6003Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
59405ffd6003SmrgEOF
5941145b7b3cSmrg
5942b7d26471Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5943629baa8cSmrg              func_to_host_path "$temp_rpath"
59445ffd6003Smrg	      cat <<EOF
5945629baa8cSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
59465ffd6003SmrgEOF
59475ffd6003Smrg	    else
59485ffd6003Smrg	      cat <<"EOF"
59495ffd6003Smrgconst char * LIB_PATH_VALUE   = "";
59505ffd6003SmrgEOF
5951145b7b3cSmrg	    fi
5952145b7b3cSmrg
59535ffd6003Smrg	    if test -n "$dllsearchpath"; then
5954629baa8cSmrg              func_to_host_path "$dllsearchpath:"
59555ffd6003Smrg	      cat <<EOF
59565ffd6003Smrgconst char * EXE_PATH_VARNAME = "PATH";
5957629baa8cSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5958145b7b3cSmrgEOF
5959145b7b3cSmrg	    else
59605ffd6003Smrg	      cat <<"EOF"
59615ffd6003Smrgconst char * EXE_PATH_VARNAME = "";
59625ffd6003Smrgconst char * EXE_PATH_VALUE   = "";
59635ffd6003SmrgEOF
5964145b7b3cSmrg	    fi
59655ffd6003Smrg
5966b7d26471Smrg	    if test yes = "$fast_install"; then
59675ffd6003Smrg	      cat <<EOF
59685ffd6003Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
59695ffd6003SmrgEOF
5970145b7b3cSmrg	    else
59715ffd6003Smrg	      cat <<EOF
59725ffd6003Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
59735ffd6003SmrgEOF
5974145b7b3cSmrg	    fi
5975145b7b3cSmrg
5976145b7b3cSmrg
59775ffd6003Smrg	    cat <<"EOF"
5978145b7b3cSmrg
59795ffd6003Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5980145b7b3cSmrg
59815ffd6003Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
59825ffd6003Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5983629baa8cSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5984145b7b3cSmrg
59855ffd6003Smrgint
59865ffd6003Smrgmain (int argc, char *argv[])
59875ffd6003Smrg{
59885ffd6003Smrg  char **newargz;
59895ffd6003Smrg  int  newargc;
59905ffd6003Smrg  char *tmp_pathspec;
59915ffd6003Smrg  char *actual_cwrapper_path;
59925ffd6003Smrg  char *actual_cwrapper_name;
59935ffd6003Smrg  char *target_name;
59945ffd6003Smrg  char *lt_argv_zero;
5995b7d26471Smrg  int rval = 127;
5996145b7b3cSmrg
59975ffd6003Smrg  int i;
5998145b7b3cSmrg
59995ffd6003Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000b7d26471Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
6001145b7b3cSmrg
6002629baa8cSmrg  /* very simple arg parsing; don't want to rely on getopt
6003629baa8cSmrg   * also, copy all non cwrapper options to newargz, except
6004629baa8cSmrg   * argz[0], which is handled differently
6005629baa8cSmrg   */
6006629baa8cSmrg  newargc=0;
60075ffd6003Smrg  for (i = 1; i < argc; i++)
60085ffd6003Smrg    {
6009b7d26471Smrg      if (STREQ (argv[i], dumpscript_opt))
60105ffd6003Smrg	{
60115ffd6003SmrgEOF
6012b7d26471Smrg	    case $host in
60135ffd6003Smrg	      *mingw* | *cygwin* )
60145ffd6003Smrg		# make stdout use "unix" line endings
60155ffd6003Smrg		echo "          setmode(1,_O_BINARY);"
60165ffd6003Smrg		;;
60175ffd6003Smrg	      esac
6018145b7b3cSmrg
60195ffd6003Smrg	    cat <<"EOF"
6020629baa8cSmrg	  lt_dump_script (stdout);
60215ffd6003Smrg	  return 0;
60225ffd6003Smrg	}
6023b7d26471Smrg      if (STREQ (argv[i], debug_opt))
6024629baa8cSmrg	{
6025629baa8cSmrg          lt_debug = 1;
6026629baa8cSmrg          continue;
6027629baa8cSmrg	}
6028b7d26471Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6029629baa8cSmrg        {
6030629baa8cSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6031629baa8cSmrg             namespace, but it is not one of the ones we know about and
6032629baa8cSmrg             have already dealt with, above (inluding dump-script), then
6033629baa8cSmrg             report an error. Otherwise, targets might begin to believe
6034629baa8cSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6035629baa8cSmrg             namespace. The first time any user complains about this, we'll
6036629baa8cSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6037629baa8cSmrg             or a configure.ac-settable value.
6038629baa8cSmrg           */
6039629baa8cSmrg          lt_fatal (__FILE__, __LINE__,
6040629baa8cSmrg		    "unrecognized %s option: '%s'",
6041629baa8cSmrg                    ltwrapper_option_prefix, argv[i]);
6042629baa8cSmrg        }
6043629baa8cSmrg      /* otherwise ... */
6044629baa8cSmrg      newargz[++newargc] = xstrdup (argv[i]);
60455ffd6003Smrg    }
6046629baa8cSmrg  newargz[++newargc] = NULL;
6047629baa8cSmrg
6048629baa8cSmrgEOF
6049629baa8cSmrg	    cat <<EOF
6050629baa8cSmrg  /* The GNU banner must be the first non-error debug message */
6051b7d26471Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6052629baa8cSmrgEOF
6053629baa8cSmrg	    cat <<"EOF"
6054629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6055629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6056145b7b3cSmrg
60575ffd6003Smrg  tmp_pathspec = find_executable (argv[0]);
60585ffd6003Smrg  if (tmp_pathspec == NULL)
6059629baa8cSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6060629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6061629baa8cSmrg                  "(main) found exe (before symlink chase) at: %s\n",
6062629baa8cSmrg		  tmp_pathspec);
60635ffd6003Smrg
60645ffd6003Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6065629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6066629baa8cSmrg                  "(main) found exe (after symlink chase) at: %s\n",
6067629baa8cSmrg		  actual_cwrapper_path);
60685ffd6003Smrg  XFREE (tmp_pathspec);
60695ffd6003Smrg
6070629baa8cSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
60715ffd6003Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
60725ffd6003Smrg
60735ffd6003Smrg  /* wrapper name transforms */
60745ffd6003Smrg  strendzap (actual_cwrapper_name, ".exe");
60755ffd6003Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
60765ffd6003Smrg  XFREE (actual_cwrapper_name);
60775ffd6003Smrg  actual_cwrapper_name = tmp_pathspec;
60785ffd6003Smrg  tmp_pathspec = 0;
60795ffd6003Smrg
60805ffd6003Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
60815ffd6003Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
60825ffd6003Smrg  strendzap (target_name, ".exe");
60835ffd6003Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
60845ffd6003Smrg  XFREE (target_name);
60855ffd6003Smrg  target_name = tmp_pathspec;
60865ffd6003Smrg  tmp_pathspec = 0;
60875ffd6003Smrg
6088629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6089629baa8cSmrg		  "(main) libtool target name: %s\n",
6090629baa8cSmrg		  target_name);
60915ffd6003SmrgEOF
6092145b7b3cSmrg
60935ffd6003Smrg	    cat <<EOF
60945ffd6003Smrg  newargz[0] =
60955ffd6003Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
60965ffd6003Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
60975ffd6003Smrg  strcpy (newargz[0], actual_cwrapper_path);
60985ffd6003Smrg  strcat (newargz[0], "$objdir");
60995ffd6003Smrg  strcat (newargz[0], "/");
61005ffd6003SmrgEOF
6101145b7b3cSmrg
61025ffd6003Smrg	    cat <<"EOF"
61035ffd6003Smrg  /* stop here, and copy so we don't have to do this twice */
61045ffd6003Smrg  tmp_pathspec = xstrdup (newargz[0]);
6105145b7b3cSmrg
61065ffd6003Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
61075ffd6003Smrg  strcat (newargz[0], actual_cwrapper_name);
6108145b7b3cSmrg
61095ffd6003Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
61105ffd6003Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
61115ffd6003Smrg  XFREE (tmp_pathspec);
61125ffd6003Smrg  tmp_pathspec = NULL;
61135ffd6003SmrgEOF
6114145b7b3cSmrg
61155ffd6003Smrg	    case $host_os in
61165ffd6003Smrg	      mingw*)
61175ffd6003Smrg	    cat <<"EOF"
61185ffd6003Smrg  {
61195ffd6003Smrg    char* p;
61205ffd6003Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
61215ffd6003Smrg      {
61225ffd6003Smrg	*p = '/';
61235ffd6003Smrg      }
61245ffd6003Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
61255ffd6003Smrg      {
61265ffd6003Smrg	*p = '/';
61275ffd6003Smrg      }
61285ffd6003Smrg  }
61295ffd6003SmrgEOF
61305ffd6003Smrg	    ;;
61315ffd6003Smrg	    esac
6132145b7b3cSmrg
61335ffd6003Smrg	    cat <<"EOF"
61345ffd6003Smrg  XFREE (target_name);
61355ffd6003Smrg  XFREE (actual_cwrapper_path);
61365ffd6003Smrg  XFREE (actual_cwrapper_name);
6137145b7b3cSmrg
61385ffd6003Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
61395ffd6003Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6140629baa8cSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6141629baa8cSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6142629baa8cSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6143629baa8cSmrg     libraries must come first. */
61445ffd6003Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6145629baa8cSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6146145b7b3cSmrg
6147629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6148629baa8cSmrg		  nonnull (lt_argv_zero));
61495ffd6003Smrg  for (i = 0; i < newargc; i++)
61505ffd6003Smrg    {
6151629baa8cSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6152629baa8cSmrg		      i, nonnull (newargz[i]));
61535ffd6003Smrg    }
6154145b7b3cSmrg
61555ffd6003SmrgEOF
6156145b7b3cSmrg
61575ffd6003Smrg	    case $host_os in
61585ffd6003Smrg	      mingw*)
61595ffd6003Smrg		cat <<"EOF"
61605ffd6003Smrg  /* execv doesn't actually work on mingw as expected on unix */
6161629baa8cSmrg  newargz = prepare_spawn (newargz);
6162b7d26471Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
61635ffd6003Smrg  if (rval == -1)
61645ffd6003Smrg    {
61655ffd6003Smrg      /* failed to start process */
6166629baa8cSmrg      lt_debugprintf (__FILE__, __LINE__,
6167629baa8cSmrg		      "(main) failed to launch target \"%s\": %s\n",
6168629baa8cSmrg		      lt_argv_zero, nonnull (strerror (errno)));
61695ffd6003Smrg      return 127;
61705ffd6003Smrg    }
61715ffd6003Smrg  return rval;
61725ffd6003SmrgEOF
61735ffd6003Smrg		;;
61745ffd6003Smrg	      *)
61755ffd6003Smrg		cat <<"EOF"
61765ffd6003Smrg  execv (lt_argv_zero, newargz);
61775ffd6003Smrg  return rval; /* =127, but avoids unused variable warning */
61785ffd6003SmrgEOF
61795ffd6003Smrg		;;
61805ffd6003Smrg	    esac
6181145b7b3cSmrg
61825ffd6003Smrg	    cat <<"EOF"
61835ffd6003Smrg}
6184145b7b3cSmrg
61855ffd6003Smrgvoid *
61865ffd6003Smrgxmalloc (size_t num)
61875ffd6003Smrg{
61885ffd6003Smrg  void *p = (void *) malloc (num);
61895ffd6003Smrg  if (!p)
6190629baa8cSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6191145b7b3cSmrg
61925ffd6003Smrg  return p;
61935ffd6003Smrg}
6194145b7b3cSmrg
61955ffd6003Smrgchar *
61965ffd6003Smrgxstrdup (const char *string)
61975ffd6003Smrg{
61985ffd6003Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
61995ffd6003Smrg			  string) : NULL;
62005ffd6003Smrg}
6201145b7b3cSmrg
62025ffd6003Smrgconst char *
62035ffd6003Smrgbase_name (const char *name)
62045ffd6003Smrg{
62055ffd6003Smrg  const char *base;
6206145b7b3cSmrg
6207b7d26471Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62085ffd6003Smrg  /* Skip over the disk name in MSDOS pathnames. */
62095ffd6003Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
62105ffd6003Smrg    name += 2;
62115ffd6003Smrg#endif
6212145b7b3cSmrg
62135ffd6003Smrg  for (base = name; *name; name++)
62145ffd6003Smrg    if (IS_DIR_SEPARATOR (*name))
62155ffd6003Smrg      base = name + 1;
62165ffd6003Smrg  return base;
62175ffd6003Smrg}
6218145b7b3cSmrg
62195ffd6003Smrgint
62205ffd6003Smrgcheck_executable (const char *path)
62215ffd6003Smrg{
62225ffd6003Smrg  struct stat st;
6223145b7b3cSmrg
6224629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6225629baa8cSmrg                  nonempty (path));
62265ffd6003Smrg  if ((!path) || (!*path))
62275ffd6003Smrg    return 0;
6228145b7b3cSmrg
62295ffd6003Smrg  if ((stat (path, &st) >= 0)
62305ffd6003Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
62315ffd6003Smrg    return 1;
62325ffd6003Smrg  else
62335ffd6003Smrg    return 0;
62345ffd6003Smrg}
6235145b7b3cSmrg
62365ffd6003Smrgint
62375ffd6003Smrgmake_executable (const char *path)
62385ffd6003Smrg{
62395ffd6003Smrg  int rval = 0;
62405ffd6003Smrg  struct stat st;
6241145b7b3cSmrg
6242629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6243629baa8cSmrg                  nonempty (path));
62445ffd6003Smrg  if ((!path) || (!*path))
62455ffd6003Smrg    return 0;
6246145b7b3cSmrg
62475ffd6003Smrg  if (stat (path, &st) >= 0)
62485ffd6003Smrg    {
62495ffd6003Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
62505ffd6003Smrg    }
62515ffd6003Smrg  return rval;
62525ffd6003Smrg}
6253145b7b3cSmrg
62545ffd6003Smrg/* Searches for the full path of the wrapper.  Returns
62555ffd6003Smrg   newly allocated full path name if found, NULL otherwise
62565ffd6003Smrg   Does not chase symlinks, even on platforms that support them.
62575ffd6003Smrg*/
62585ffd6003Smrgchar *
62595ffd6003Smrgfind_executable (const char *wrapper)
62605ffd6003Smrg{
62615ffd6003Smrg  int has_slash = 0;
62625ffd6003Smrg  const char *p;
62635ffd6003Smrg  const char *p_next;
62645ffd6003Smrg  /* static buffer for getcwd */
62655ffd6003Smrg  char tmp[LT_PATHMAX + 1];
6266b7d26471Smrg  size_t tmp_len;
62675ffd6003Smrg  char *concat_name;
6268145b7b3cSmrg
6269629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6270629baa8cSmrg                  nonempty (wrapper));
6271145b7b3cSmrg
62725ffd6003Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
62735ffd6003Smrg    return NULL;
6274145b7b3cSmrg
62755ffd6003Smrg  /* Absolute path? */
6276b7d26471Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62775ffd6003Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
62785ffd6003Smrg    {
62795ffd6003Smrg      concat_name = xstrdup (wrapper);
62805ffd6003Smrg      if (check_executable (concat_name))
62815ffd6003Smrg	return concat_name;
62825ffd6003Smrg      XFREE (concat_name);
62835ffd6003Smrg    }
62845ffd6003Smrg  else
62855ffd6003Smrg    {
62865ffd6003Smrg#endif
62875ffd6003Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
62885ffd6003Smrg	{
62895ffd6003Smrg	  concat_name = xstrdup (wrapper);
62905ffd6003Smrg	  if (check_executable (concat_name))
62915ffd6003Smrg	    return concat_name;
62925ffd6003Smrg	  XFREE (concat_name);
62935ffd6003Smrg	}
6294b7d26471Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
62955ffd6003Smrg    }
62965ffd6003Smrg#endif
6297145b7b3cSmrg
62985ffd6003Smrg  for (p = wrapper; *p; p++)
62995ffd6003Smrg    if (*p == '/')
63005ffd6003Smrg      {
63015ffd6003Smrg	has_slash = 1;
63025ffd6003Smrg	break;
63035ffd6003Smrg      }
63045ffd6003Smrg  if (!has_slash)
63055ffd6003Smrg    {
63065ffd6003Smrg      /* no slashes; search PATH */
63075ffd6003Smrg      const char *path = getenv ("PATH");
63085ffd6003Smrg      if (path != NULL)
63095ffd6003Smrg	{
63105ffd6003Smrg	  for (p = path; *p; p = p_next)
63115ffd6003Smrg	    {
63125ffd6003Smrg	      const char *q;
63135ffd6003Smrg	      size_t p_len;
63145ffd6003Smrg	      for (q = p; *q; q++)
63155ffd6003Smrg		if (IS_PATH_SEPARATOR (*q))
63165ffd6003Smrg		  break;
6317b7d26471Smrg	      p_len = (size_t) (q - p);
63185ffd6003Smrg	      p_next = (*q == '\0' ? q : q + 1);
63195ffd6003Smrg	      if (p_len == 0)
63205ffd6003Smrg		{
63215ffd6003Smrg		  /* empty path: current directory */
63225ffd6003Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6323629baa8cSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6324629baa8cSmrg                              nonnull (strerror (errno)));
63255ffd6003Smrg		  tmp_len = strlen (tmp);
63265ffd6003Smrg		  concat_name =
63275ffd6003Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63285ffd6003Smrg		  memcpy (concat_name, tmp, tmp_len);
63295ffd6003Smrg		  concat_name[tmp_len] = '/';
63305ffd6003Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
63315ffd6003Smrg		}
63325ffd6003Smrg	      else
63335ffd6003Smrg		{
63345ffd6003Smrg		  concat_name =
63355ffd6003Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
63365ffd6003Smrg		  memcpy (concat_name, p, p_len);
63375ffd6003Smrg		  concat_name[p_len] = '/';
63385ffd6003Smrg		  strcpy (concat_name + p_len + 1, wrapper);
63395ffd6003Smrg		}
63405ffd6003Smrg	      if (check_executable (concat_name))
63415ffd6003Smrg		return concat_name;
63425ffd6003Smrg	      XFREE (concat_name);
63435ffd6003Smrg	    }
63445ffd6003Smrg	}
63455ffd6003Smrg      /* not found in PATH; assume curdir */
63465ffd6003Smrg    }
63475ffd6003Smrg  /* Relative path | not found in path: prepend cwd */
63485ffd6003Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6349629baa8cSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6350629baa8cSmrg              nonnull (strerror (errno)));
63515ffd6003Smrg  tmp_len = strlen (tmp);
63525ffd6003Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
63535ffd6003Smrg  memcpy (concat_name, tmp, tmp_len);
63545ffd6003Smrg  concat_name[tmp_len] = '/';
63555ffd6003Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6356145b7b3cSmrg
63575ffd6003Smrg  if (check_executable (concat_name))
63585ffd6003Smrg    return concat_name;
63595ffd6003Smrg  XFREE (concat_name);
63605ffd6003Smrg  return NULL;
63615ffd6003Smrg}
6362145b7b3cSmrg
63635ffd6003Smrgchar *
63645ffd6003Smrgchase_symlinks (const char *pathspec)
63655ffd6003Smrg{
63665ffd6003Smrg#ifndef S_ISLNK
63675ffd6003Smrg  return xstrdup (pathspec);
63685ffd6003Smrg#else
63695ffd6003Smrg  char buf[LT_PATHMAX];
63705ffd6003Smrg  struct stat s;
63715ffd6003Smrg  char *tmp_pathspec = xstrdup (pathspec);
63725ffd6003Smrg  char *p;
63735ffd6003Smrg  int has_symlinks = 0;
63745ffd6003Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
63755ffd6003Smrg    {
6376629baa8cSmrg      lt_debugprintf (__FILE__, __LINE__,
6377629baa8cSmrg		      "checking path component for symlinks: %s\n",
6378629baa8cSmrg		      tmp_pathspec);
63795ffd6003Smrg      if (lstat (tmp_pathspec, &s) == 0)
63805ffd6003Smrg	{
63815ffd6003Smrg	  if (S_ISLNK (s.st_mode) != 0)
63825ffd6003Smrg	    {
63835ffd6003Smrg	      has_symlinks = 1;
63845ffd6003Smrg	      break;
63855ffd6003Smrg	    }
6386145b7b3cSmrg
63875ffd6003Smrg	  /* search backwards for last DIR_SEPARATOR */
63885ffd6003Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
63895ffd6003Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63905ffd6003Smrg	    p--;
63915ffd6003Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
63925ffd6003Smrg	    {
63935ffd6003Smrg	      /* no more DIR_SEPARATORS left */
63945ffd6003Smrg	      break;
63955ffd6003Smrg	    }
63965ffd6003Smrg	  *p = '\0';
63975ffd6003Smrg	}
63985ffd6003Smrg      else
63995ffd6003Smrg	{
6400629baa8cSmrg	  lt_fatal (__FILE__, __LINE__,
6401629baa8cSmrg		    "error accessing file \"%s\": %s",
6402629baa8cSmrg		    tmp_pathspec, nonnull (strerror (errno)));
64035ffd6003Smrg	}
64045ffd6003Smrg    }
64055ffd6003Smrg  XFREE (tmp_pathspec);
6406145b7b3cSmrg
64075ffd6003Smrg  if (!has_symlinks)
64085ffd6003Smrg    {
64095ffd6003Smrg      return xstrdup (pathspec);
64105ffd6003Smrg    }
6411145b7b3cSmrg
64125ffd6003Smrg  tmp_pathspec = realpath (pathspec, buf);
64135ffd6003Smrg  if (tmp_pathspec == 0)
64145ffd6003Smrg    {
6415629baa8cSmrg      lt_fatal (__FILE__, __LINE__,
6416629baa8cSmrg		"could not follow symlinks for %s", pathspec);
64175ffd6003Smrg    }
64185ffd6003Smrg  return xstrdup (tmp_pathspec);
64195ffd6003Smrg#endif
64205ffd6003Smrg}
6421145b7b3cSmrg
64225ffd6003Smrgchar *
64235ffd6003Smrgstrendzap (char *str, const char *pat)
64245ffd6003Smrg{
64255ffd6003Smrg  size_t len, patlen;
6426145b7b3cSmrg
64275ffd6003Smrg  assert (str != NULL);
64285ffd6003Smrg  assert (pat != NULL);
6429145b7b3cSmrg
64305ffd6003Smrg  len = strlen (str);
64315ffd6003Smrg  patlen = strlen (pat);
6432145b7b3cSmrg
64335ffd6003Smrg  if (patlen <= len)
64345ffd6003Smrg    {
64355ffd6003Smrg      str += len - patlen;
6436b7d26471Smrg      if (STREQ (str, pat))
64375ffd6003Smrg	*str = '\0';
64385ffd6003Smrg    }
64395ffd6003Smrg  return str;
64405ffd6003Smrg}
6441145b7b3cSmrg
6442629baa8cSmrgvoid
6443629baa8cSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6444629baa8cSmrg{
6445629baa8cSmrg  va_list args;
6446629baa8cSmrg  if (lt_debug)
6447629baa8cSmrg    {
6448629baa8cSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6449629baa8cSmrg      va_start (args, fmt);
6450629baa8cSmrg      (void) vfprintf (stderr, fmt, args);
6451629baa8cSmrg      va_end (args);
6452629baa8cSmrg    }
6453629baa8cSmrg}
6454629baa8cSmrg
64555ffd6003Smrgstatic void
6456629baa8cSmrglt_error_core (int exit_status, const char *file,
6457629baa8cSmrg	       int line, const char *mode,
64585ffd6003Smrg	       const char *message, va_list ap)
64595ffd6003Smrg{
6460629baa8cSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
64615ffd6003Smrg  vfprintf (stderr, message, ap);
64625ffd6003Smrg  fprintf (stderr, ".\n");
6463145b7b3cSmrg
64645ffd6003Smrg  if (exit_status >= 0)
64655ffd6003Smrg    exit (exit_status);
64665ffd6003Smrg}
6467145b7b3cSmrg
64685ffd6003Smrgvoid
6469629baa8cSmrglt_fatal (const char *file, int line, const char *message, ...)
64705ffd6003Smrg{
64715ffd6003Smrg  va_list ap;
64725ffd6003Smrg  va_start (ap, message);
6473629baa8cSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
64745ffd6003Smrg  va_end (ap);
64755ffd6003Smrg}
6476145b7b3cSmrg
6477629baa8cSmrgstatic const char *
6478629baa8cSmrgnonnull (const char *s)
6479629baa8cSmrg{
6480629baa8cSmrg  return s ? s : "(null)";
6481629baa8cSmrg}
6482629baa8cSmrg
6483629baa8cSmrgstatic const char *
6484629baa8cSmrgnonempty (const char *s)
6485629baa8cSmrg{
6486629baa8cSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6487629baa8cSmrg}
6488629baa8cSmrg
64895ffd6003Smrgvoid
64905ffd6003Smrglt_setenv (const char *name, const char *value)
64915ffd6003Smrg{
6492629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6493629baa8cSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6494629baa8cSmrg                  nonnull (name), nonnull (value));
64955ffd6003Smrg  {
64965ffd6003Smrg#ifdef HAVE_SETENV
64975ffd6003Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
64985ffd6003Smrg    char *str = xstrdup (value);
64995ffd6003Smrg    setenv (name, str, 1);
65005ffd6003Smrg#else
6501b7d26471Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
65025ffd6003Smrg    char *str = XMALLOC (char, len);
65035ffd6003Smrg    sprintf (str, "%s=%s", name, value);
65045ffd6003Smrg    if (putenv (str) != EXIT_SUCCESS)
65055ffd6003Smrg      {
65065ffd6003Smrg        XFREE (str);
65075ffd6003Smrg      }
65085ffd6003Smrg#endif
65095ffd6003Smrg  }
65105ffd6003Smrg}
6511145b7b3cSmrg
65125ffd6003Smrgchar *
65135ffd6003Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
65145ffd6003Smrg{
65155ffd6003Smrg  char *new_value;
65165ffd6003Smrg  if (orig_value && *orig_value)
65175ffd6003Smrg    {
6518b7d26471Smrg      size_t orig_value_len = strlen (orig_value);
6519b7d26471Smrg      size_t add_len = strlen (add);
65205ffd6003Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
65215ffd6003Smrg      if (to_end)
65225ffd6003Smrg        {
65235ffd6003Smrg          strcpy (new_value, orig_value);
65245ffd6003Smrg          strcpy (new_value + orig_value_len, add);
65255ffd6003Smrg        }
65265ffd6003Smrg      else
65275ffd6003Smrg        {
65285ffd6003Smrg          strcpy (new_value, add);
65295ffd6003Smrg          strcpy (new_value + add_len, orig_value);
65305ffd6003Smrg        }
65315ffd6003Smrg    }
65325ffd6003Smrg  else
65335ffd6003Smrg    {
65345ffd6003Smrg      new_value = xstrdup (add);
65355ffd6003Smrg    }
65365ffd6003Smrg  return new_value;
65375ffd6003Smrg}
6538145b7b3cSmrg
65395ffd6003Smrgvoid
65405ffd6003Smrglt_update_exe_path (const char *name, const char *value)
65415ffd6003Smrg{
6542629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6543629baa8cSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6544629baa8cSmrg                  nonnull (name), nonnull (value));
6545145b7b3cSmrg
65465ffd6003Smrg  if (name && *name && value && *value)
65475ffd6003Smrg    {
65485ffd6003Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65495ffd6003Smrg      /* some systems can't cope with a ':'-terminated path #' */
6550b7d26471Smrg      size_t len = strlen (new_value);
6551b7d26471Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
65525ffd6003Smrg        {
6553b7d26471Smrg          new_value[--len] = '\0';
65545ffd6003Smrg        }
65555ffd6003Smrg      lt_setenv (name, new_value);
65565ffd6003Smrg      XFREE (new_value);
65575ffd6003Smrg    }
65585ffd6003Smrg}
6559145b7b3cSmrg
65605ffd6003Smrgvoid
65615ffd6003Smrglt_update_lib_path (const char *name, const char *value)
65625ffd6003Smrg{
6563629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6564629baa8cSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6565629baa8cSmrg                  nonnull (name), nonnull (value));
6566145b7b3cSmrg
65675ffd6003Smrg  if (name && *name && value && *value)
65685ffd6003Smrg    {
65695ffd6003Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
65705ffd6003Smrg      lt_setenv (name, new_value);
65715ffd6003Smrg      XFREE (new_value);
65725ffd6003Smrg    }
65735ffd6003Smrg}
6574145b7b3cSmrg
6575629baa8cSmrgEOF
6576629baa8cSmrg	    case $host_os in
6577629baa8cSmrg	      mingw*)
6578629baa8cSmrg		cat <<"EOF"
6579629baa8cSmrg
6580629baa8cSmrg/* Prepares an argument vector before calling spawn().
6581629baa8cSmrg   Note that spawn() does not by itself call the command interpreter
6582629baa8cSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6583629baa8cSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6584629baa8cSmrg         GetVersionEx(&v);
6585629baa8cSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6586629baa8cSmrg      }) ? "cmd.exe" : "command.com").
6587629baa8cSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6588629baa8cSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6589629baa8cSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6590629baa8cSmrg   special way:
6591629baa8cSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6592629baa8cSmrg     delimiters if they are surrounded by double quotes: "...".
6593629baa8cSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6594629baa8cSmrg     that within double quotes, space and tab are treated like normal
6595629baa8cSmrg     characters.
6596629baa8cSmrg   - Backslashes not followed by double quotes are not special.
6597629baa8cSmrg   - But 2*n+1 backslashes followed by a double quote become
6598629baa8cSmrg     n backslashes followed by a double quote (n >= 0):
6599629baa8cSmrg       \" -> "
6600629baa8cSmrg       \\\" -> \"
6601629baa8cSmrg       \\\\\" -> \\"
6602629baa8cSmrg */
6603629baa8cSmrg#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"
6604629baa8cSmrg#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"
6605629baa8cSmrgchar **
6606629baa8cSmrgprepare_spawn (char **argv)
6607629baa8cSmrg{
6608629baa8cSmrg  size_t argc;
6609629baa8cSmrg  char **new_argv;
6610629baa8cSmrg  size_t i;
6611629baa8cSmrg
6612629baa8cSmrg  /* Count number of arguments.  */
6613629baa8cSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6614629baa8cSmrg    ;
6615629baa8cSmrg
6616629baa8cSmrg  /* Allocate new argument vector.  */
6617629baa8cSmrg  new_argv = XMALLOC (char *, argc + 1);
6618629baa8cSmrg
6619629baa8cSmrg  /* Put quoted arguments into the new argument vector.  */
6620629baa8cSmrg  for (i = 0; i < argc; i++)
6621629baa8cSmrg    {
6622629baa8cSmrg      const char *string = argv[i];
6623629baa8cSmrg
6624629baa8cSmrg      if (string[0] == '\0')
6625629baa8cSmrg	new_argv[i] = xstrdup ("\"\"");
6626629baa8cSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6627629baa8cSmrg	{
6628629baa8cSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6629629baa8cSmrg	  size_t length;
6630629baa8cSmrg	  unsigned int backslashes;
6631629baa8cSmrg	  const char *s;
6632629baa8cSmrg	  char *quoted_string;
6633629baa8cSmrg	  char *p;
6634629baa8cSmrg
6635629baa8cSmrg	  length = 0;
6636629baa8cSmrg	  backslashes = 0;
6637629baa8cSmrg	  if (quote_around)
6638629baa8cSmrg	    length++;
6639629baa8cSmrg	  for (s = string; *s != '\0'; s++)
6640629baa8cSmrg	    {
6641629baa8cSmrg	      char c = *s;
6642629baa8cSmrg	      if (c == '"')
6643629baa8cSmrg		length += backslashes + 1;
6644629baa8cSmrg	      length++;
6645629baa8cSmrg	      if (c == '\\')
6646629baa8cSmrg		backslashes++;
6647629baa8cSmrg	      else
6648629baa8cSmrg		backslashes = 0;
6649629baa8cSmrg	    }
6650629baa8cSmrg	  if (quote_around)
6651629baa8cSmrg	    length += backslashes + 1;
6652629baa8cSmrg
6653629baa8cSmrg	  quoted_string = XMALLOC (char, length + 1);
6654629baa8cSmrg
6655629baa8cSmrg	  p = quoted_string;
6656629baa8cSmrg	  backslashes = 0;
6657629baa8cSmrg	  if (quote_around)
6658629baa8cSmrg	    *p++ = '"';
6659629baa8cSmrg	  for (s = string; *s != '\0'; s++)
6660629baa8cSmrg	    {
6661629baa8cSmrg	      char c = *s;
6662629baa8cSmrg	      if (c == '"')
6663629baa8cSmrg		{
6664629baa8cSmrg		  unsigned int j;
6665629baa8cSmrg		  for (j = backslashes + 1; j > 0; j--)
6666629baa8cSmrg		    *p++ = '\\';
6667629baa8cSmrg		}
6668629baa8cSmrg	      *p++ = c;
6669629baa8cSmrg	      if (c == '\\')
6670629baa8cSmrg		backslashes++;
6671629baa8cSmrg	      else
6672629baa8cSmrg		backslashes = 0;
6673629baa8cSmrg	    }
6674629baa8cSmrg	  if (quote_around)
6675629baa8cSmrg	    {
6676629baa8cSmrg	      unsigned int j;
6677629baa8cSmrg	      for (j = backslashes; j > 0; j--)
6678629baa8cSmrg		*p++ = '\\';
6679629baa8cSmrg	      *p++ = '"';
6680629baa8cSmrg	    }
6681629baa8cSmrg	  *p = '\0';
6682629baa8cSmrg
6683629baa8cSmrg	  new_argv[i] = quoted_string;
6684629baa8cSmrg	}
6685629baa8cSmrg      else
6686629baa8cSmrg	new_argv[i] = (char *) string;
6687629baa8cSmrg    }
6688629baa8cSmrg  new_argv[argc] = NULL;
6689629baa8cSmrg
6690629baa8cSmrg  return new_argv;
6691629baa8cSmrg}
6692629baa8cSmrgEOF
6693629baa8cSmrg		;;
6694629baa8cSmrg	    esac
6695629baa8cSmrg
6696629baa8cSmrg            cat <<"EOF"
6697629baa8cSmrgvoid lt_dump_script (FILE* f)
6698629baa8cSmrg{
6699629baa8cSmrgEOF
6700629baa8cSmrg	    func_emit_wrapper yes |
6701b7d26471Smrg	      $SED -n -e '
6702b7d26471Smrgs/^\(.\{79\}\)\(..*\)/\1\
6703b7d26471Smrg\2/
6704b7d26471Smrgh
6705b7d26471Smrgs/\([\\"]\)/\\\1/g
6706b7d26471Smrgs/$/\\n/
6707b7d26471Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708b7d26471Smrgg
6709b7d26471SmrgD'
6710629baa8cSmrg            cat <<"EOF"
6711629baa8cSmrg}
67125ffd6003SmrgEOF
67135ffd6003Smrg}
67145ffd6003Smrg# end: func_emit_cwrapperexe_src
6715145b7b3cSmrg
6716629baa8cSmrg# func_win32_import_lib_p ARG
6717629baa8cSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6718629baa8cSmrgfunc_win32_import_lib_p ()
6719629baa8cSmrg{
6720b7d26471Smrg    $debug_cmd
6721b7d26471Smrg
6722629baa8cSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6723629baa8cSmrg    *import*) : ;;
6724629baa8cSmrg    *) false ;;
6725629baa8cSmrg    esac
6726629baa8cSmrg}
6727629baa8cSmrg
6728b7d26471Smrg# func_suncc_cstd_abi
6729b7d26471Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730b7d26471Smrg# Several compiler flags select an ABI that is incompatible with the
6731b7d26471Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732b7d26471Smrgfunc_suncc_cstd_abi ()
6733b7d26471Smrg{
6734b7d26471Smrg    $debug_cmd
6735b7d26471Smrg
6736b7d26471Smrg    case " $compile_command " in
6737b7d26471Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738b7d26471Smrg      suncc_use_cstd_abi=no
6739b7d26471Smrg      ;;
6740b7d26471Smrg    *)
6741b7d26471Smrg      suncc_use_cstd_abi=yes
6742b7d26471Smrg      ;;
6743b7d26471Smrg    esac
6744b7d26471Smrg}
6745b7d26471Smrg
67465ffd6003Smrg# func_mode_link arg...
67475ffd6003Smrgfunc_mode_link ()
67485ffd6003Smrg{
6749b7d26471Smrg    $debug_cmd
6750b7d26471Smrg
67515ffd6003Smrg    case $host in
67525ffd6003Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
67535ffd6003Smrg      # It is impossible to link a dll without this setting, and
67545ffd6003Smrg      # we shouldn't force the makefile maintainer to figure out
6755b7d26471Smrg      # what system we are compiling for in order to pass an extra
67565ffd6003Smrg      # flag for every libtool invocation.
67575ffd6003Smrg      # allow_undefined=no
6758145b7b3cSmrg
67595ffd6003Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6760b7d26471Smrg      # to make a dll that has undefined symbols, in which case not
67615ffd6003Smrg      # even a static library is built.  For now, we need to specify
67625ffd6003Smrg      # -no-undefined on the libtool link line when we can be certain
67635ffd6003Smrg      # that all symbols are satisfied, otherwise we get a static library.
67645ffd6003Smrg      allow_undefined=yes
67655ffd6003Smrg      ;;
67665ffd6003Smrg    *)
67675ffd6003Smrg      allow_undefined=yes
67685ffd6003Smrg      ;;
67695ffd6003Smrg    esac
67705ffd6003Smrg    libtool_args=$nonopt
67715ffd6003Smrg    base_compile="$nonopt $@"
67725ffd6003Smrg    compile_command=$nonopt
67735ffd6003Smrg    finalize_command=$nonopt
6774145b7b3cSmrg
67755ffd6003Smrg    compile_rpath=
67765ffd6003Smrg    finalize_rpath=
67775ffd6003Smrg    compile_shlibpath=
67785ffd6003Smrg    finalize_shlibpath=
67795ffd6003Smrg    convenience=
67805ffd6003Smrg    old_convenience=
67815ffd6003Smrg    deplibs=
67825ffd6003Smrg    old_deplibs=
67835ffd6003Smrg    compiler_flags=
67845ffd6003Smrg    linker_flags=
67855ffd6003Smrg    dllsearchpath=
67865ffd6003Smrg    lib_search_path=`pwd`
67875ffd6003Smrg    inst_prefix_dir=
67885ffd6003Smrg    new_inherited_linker_flags=
6789145b7b3cSmrg
67905ffd6003Smrg    avoid_version=no
6791629baa8cSmrg    bindir=
67925ffd6003Smrg    dlfiles=
67935ffd6003Smrg    dlprefiles=
67945ffd6003Smrg    dlself=no
67955ffd6003Smrg    export_dynamic=no
67965ffd6003Smrg    export_symbols=
67975ffd6003Smrg    export_symbols_regex=
67985ffd6003Smrg    generated=
67995ffd6003Smrg    libobjs=
68005ffd6003Smrg    ltlibs=
68015ffd6003Smrg    module=no
68025ffd6003Smrg    no_install=no
68035ffd6003Smrg    objs=
6804b7d26471Smrg    os2dllname=
68055ffd6003Smrg    non_pic_objects=
68065ffd6003Smrg    precious_files_regex=
68075ffd6003Smrg    prefer_static_libs=no
6808b7d26471Smrg    preload=false
68095ffd6003Smrg    prev=
68105ffd6003Smrg    prevarg=
68115ffd6003Smrg    release=
68125ffd6003Smrg    rpath=
68135ffd6003Smrg    xrpath=
68145ffd6003Smrg    perm_rpath=
68155ffd6003Smrg    temp_rpath=
68165ffd6003Smrg    thread_safe=no
68175ffd6003Smrg    vinfo=
68185ffd6003Smrg    vinfo_number=no
68195ffd6003Smrg    weak_libs=
6820b7d26471Smrg    single_module=$wl-single_module
68215ffd6003Smrg    func_infer_tag $base_compile
68225ffd6003Smrg
68235ffd6003Smrg    # We need to know -static, to get the right output filenames.
68245ffd6003Smrg    for arg
68255ffd6003Smrg    do
68265ffd6003Smrg      case $arg in
68275ffd6003Smrg      -shared)
6828b7d26471Smrg	test yes != "$build_libtool_libs" \
6829b7d26471Smrg	  && func_fatal_configuration "cannot build a shared library"
68305ffd6003Smrg	build_old_libs=no
68315ffd6003Smrg	break
68325ffd6003Smrg	;;
68335ffd6003Smrg      -all-static | -static | -static-libtool-libs)
68345ffd6003Smrg	case $arg in
68355ffd6003Smrg	-all-static)
6836b7d26471Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
68375ffd6003Smrg	    func_warning "complete static linking is impossible in this configuration"
68385ffd6003Smrg	  fi
68395ffd6003Smrg	  if test -n "$link_static_flag"; then
68405ffd6003Smrg	    dlopen_self=$dlopen_self_static
68415ffd6003Smrg	  fi
68425ffd6003Smrg	  prefer_static_libs=yes
68435ffd6003Smrg	  ;;
68445ffd6003Smrg	-static)
68455ffd6003Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68465ffd6003Smrg	    dlopen_self=$dlopen_self_static
6847145b7b3cSmrg	  fi
68485ffd6003Smrg	  prefer_static_libs=built
68495ffd6003Smrg	  ;;
68505ffd6003Smrg	-static-libtool-libs)
68515ffd6003Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
68525ffd6003Smrg	    dlopen_self=$dlopen_self_static
68535ffd6003Smrg	  fi
68545ffd6003Smrg	  prefer_static_libs=yes
68555ffd6003Smrg	  ;;
68565ffd6003Smrg	esac
68575ffd6003Smrg	build_libtool_libs=no
68585ffd6003Smrg	build_old_libs=yes
68595ffd6003Smrg	break
68605ffd6003Smrg	;;
68615ffd6003Smrg      esac
68625ffd6003Smrg    done
6863145b7b3cSmrg
68645ffd6003Smrg    # See if our shared archives depend on static archives.
68655ffd6003Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6866145b7b3cSmrg
68675ffd6003Smrg    # Go through the arguments, transforming them on the way.
68685ffd6003Smrg    while test "$#" -gt 0; do
6869b7d26471Smrg      arg=$1
68705ffd6003Smrg      shift
6871da2e2ef6Smrg      func_quote_arg pretty,unquoted "$arg"
6872da2e2ef6Smrg      qarg=$func_quote_arg_unquoted_result
6873da2e2ef6Smrg      func_append libtool_args " $func_quote_arg_result"
6874145b7b3cSmrg
68755ffd6003Smrg      # If the previous option needs an argument, assign it.
68765ffd6003Smrg      if test -n "$prev"; then
68775ffd6003Smrg	case $prev in
68785ffd6003Smrg	output)
68795ffd6003Smrg	  func_append compile_command " @OUTPUT@"
68805ffd6003Smrg	  func_append finalize_command " @OUTPUT@"
68815ffd6003Smrg	  ;;
68825ffd6003Smrg	esac
6883145b7b3cSmrg
68845ffd6003Smrg	case $prev in
6885629baa8cSmrg	bindir)
6886b7d26471Smrg	  bindir=$arg
6887629baa8cSmrg	  prev=
6888629baa8cSmrg	  continue
6889629baa8cSmrg	  ;;
68905ffd6003Smrg	dlfiles|dlprefiles)
6891b7d26471Smrg	  $preload || {
68925ffd6003Smrg	    # Add the symbol object into the linking commands.
68935ffd6003Smrg	    func_append compile_command " @SYMFILE@"
68945ffd6003Smrg	    func_append finalize_command " @SYMFILE@"
6895b7d26471Smrg	    preload=:
6896b7d26471Smrg	  }
68975ffd6003Smrg	  case $arg in
68985ffd6003Smrg	  *.la | *.lo) ;;  # We handle these cases below.
68995ffd6003Smrg	  force)
6900b7d26471Smrg	    if test no = "$dlself"; then
69015ffd6003Smrg	      dlself=needless
69025ffd6003Smrg	      export_dynamic=yes
69035ffd6003Smrg	    fi
69045ffd6003Smrg	    prev=
69055ffd6003Smrg	    continue
69065ffd6003Smrg	    ;;
69075ffd6003Smrg	  self)
6908b7d26471Smrg	    if test dlprefiles = "$prev"; then
69095ffd6003Smrg	      dlself=yes
6910b7d26471Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
69115ffd6003Smrg	      dlself=yes
6912145b7b3cSmrg	    else
69135ffd6003Smrg	      dlself=needless
69145ffd6003Smrg	      export_dynamic=yes
6915145b7b3cSmrg	    fi
69165ffd6003Smrg	    prev=
69175ffd6003Smrg	    continue
69185ffd6003Smrg	    ;;
69195ffd6003Smrg	  *)
6920b7d26471Smrg	    if test dlfiles = "$prev"; then
6921629baa8cSmrg	      func_append dlfiles " $arg"
6922145b7b3cSmrg	    else
6923629baa8cSmrg	      func_append dlprefiles " $arg"
6924145b7b3cSmrg	    fi
69255ffd6003Smrg	    prev=
69265ffd6003Smrg	    continue
69275ffd6003Smrg	    ;;
69285ffd6003Smrg	  esac
69295ffd6003Smrg	  ;;
69305ffd6003Smrg	expsyms)
6931b7d26471Smrg	  export_symbols=$arg
69325ffd6003Smrg	  test -f "$arg" \
6933b7d26471Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
69345ffd6003Smrg	  prev=
69355ffd6003Smrg	  continue
69365ffd6003Smrg	  ;;
69375ffd6003Smrg	expsyms_regex)
6938b7d26471Smrg	  export_symbols_regex=$arg
69395ffd6003Smrg	  prev=
69405ffd6003Smrg	  continue
69415ffd6003Smrg	  ;;
69425ffd6003Smrg	framework)
69435ffd6003Smrg	  case $host in
69445ffd6003Smrg	    *-*-darwin*)
69455ffd6003Smrg	      case "$deplibs " in
69465ffd6003Smrg		*" $qarg.ltframework "*) ;;
6947629baa8cSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
69485ffd6003Smrg		   ;;
69495ffd6003Smrg	      esac
6950145b7b3cSmrg	      ;;
69515ffd6003Smrg	  esac
69525ffd6003Smrg	  prev=
69535ffd6003Smrg	  continue
69545ffd6003Smrg	  ;;
69555ffd6003Smrg	inst_prefix)
6956b7d26471Smrg	  inst_prefix_dir=$arg
6957b7d26471Smrg	  prev=
6958b7d26471Smrg	  continue
6959b7d26471Smrg	  ;;
6960b7d26471Smrg	mllvm)
6961b7d26471Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6962b7d26471Smrg	  # '-mllvm $arg' options when doing the link step.
69635ffd6003Smrg	  prev=
69645ffd6003Smrg	  continue
69655ffd6003Smrg	  ;;
69665ffd6003Smrg	objectlist)
69675ffd6003Smrg	  if test -f "$arg"; then
69685ffd6003Smrg	    save_arg=$arg
69695ffd6003Smrg	    moreargs=
69705ffd6003Smrg	    for fil in `cat "$save_arg"`
69715ffd6003Smrg	    do
6972629baa8cSmrg#	      func_append moreargs " $fil"
69735ffd6003Smrg	      arg=$fil
69745ffd6003Smrg	      # A libtool-controlled object.
6975145b7b3cSmrg
69765ffd6003Smrg	      # Check to see that this really is a libtool object.
69775ffd6003Smrg	      if func_lalib_unsafe_p "$arg"; then
69785ffd6003Smrg		pic_object=
69795ffd6003Smrg		non_pic_object=
6980145b7b3cSmrg
69815ffd6003Smrg		# Read the .lo file
69825ffd6003Smrg		func_source "$arg"
6983145b7b3cSmrg
69845ffd6003Smrg		if test -z "$pic_object" ||
69855ffd6003Smrg		   test -z "$non_pic_object" ||
6986b7d26471Smrg		   test none = "$pic_object" &&
6987b7d26471Smrg		   test none = "$non_pic_object"; then
6988b7d26471Smrg		  func_fatal_error "cannot find name of object for '$arg'"
69895ffd6003Smrg		fi
6990145b7b3cSmrg
69915ffd6003Smrg		# Extract subdirectory from the argument.
69925ffd6003Smrg		func_dirname "$arg" "/" ""
6993b7d26471Smrg		xdir=$func_dirname_result
6994145b7b3cSmrg
6995b7d26471Smrg		if test none != "$pic_object"; then
69965ffd6003Smrg		  # Prepend the subdirectory the object is found in.
6997b7d26471Smrg		  pic_object=$xdir$pic_object
6998145b7b3cSmrg
6999b7d26471Smrg		  if test dlfiles = "$prev"; then
7000b7d26471Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7001629baa8cSmrg		      func_append dlfiles " $pic_object"
70025ffd6003Smrg		      prev=
70035ffd6003Smrg		      continue
70045ffd6003Smrg		    else
70055ffd6003Smrg		      # If libtool objects are unsupported, then we need to preload.
70065ffd6003Smrg		      prev=dlprefiles
70075ffd6003Smrg		    fi
70085ffd6003Smrg		  fi
7009145b7b3cSmrg
70105ffd6003Smrg		  # CHECK ME:  I think I busted this.  -Ossama
7011b7d26471Smrg		  if test dlprefiles = "$prev"; then
70125ffd6003Smrg		    # Preload the old-style object.
7013629baa8cSmrg		    func_append dlprefiles " $pic_object"
70145ffd6003Smrg		    prev=
70155ffd6003Smrg		  fi
7016145b7b3cSmrg
70175ffd6003Smrg		  # A PIC object.
70185ffd6003Smrg		  func_append libobjs " $pic_object"
7019b7d26471Smrg		  arg=$pic_object
70205ffd6003Smrg		fi
7021145b7b3cSmrg
70225ffd6003Smrg		# Non-PIC object.
7023b7d26471Smrg		if test none != "$non_pic_object"; then
70245ffd6003Smrg		  # Prepend the subdirectory the object is found in.
7025b7d26471Smrg		  non_pic_object=$xdir$non_pic_object
7026145b7b3cSmrg
70275ffd6003Smrg		  # A standard non-PIC object
70285ffd6003Smrg		  func_append non_pic_objects " $non_pic_object"
7029b7d26471Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030b7d26471Smrg		    arg=$non_pic_object
70315ffd6003Smrg		  fi
70325ffd6003Smrg		else
70335ffd6003Smrg		  # If the PIC object exists, use it instead.
70345ffd6003Smrg		  # $xdir was prepended to $pic_object above.
7035b7d26471Smrg		  non_pic_object=$pic_object
70365ffd6003Smrg		  func_append non_pic_objects " $non_pic_object"
70375ffd6003Smrg		fi
70385ffd6003Smrg	      else
70395ffd6003Smrg		# Only an error if not doing a dry-run.
70405ffd6003Smrg		if $opt_dry_run; then
70415ffd6003Smrg		  # Extract subdirectory from the argument.
70425ffd6003Smrg		  func_dirname "$arg" "/" ""
7043b7d26471Smrg		  xdir=$func_dirname_result
70445ffd6003Smrg
70455ffd6003Smrg		  func_lo2o "$arg"
70465ffd6003Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
70475ffd6003Smrg		  non_pic_object=$xdir$func_lo2o_result
70485ffd6003Smrg		  func_append libobjs " $pic_object"
70495ffd6003Smrg		  func_append non_pic_objects " $non_pic_object"
70505ffd6003Smrg	        else
7051b7d26471Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
70525ffd6003Smrg		fi
70535ffd6003Smrg	      fi
70545ffd6003Smrg	    done
70555ffd6003Smrg	  else
7056b7d26471Smrg	    func_fatal_error "link input file '$arg' does not exist"
70575ffd6003Smrg	  fi
70585ffd6003Smrg	  arg=$save_arg
70595ffd6003Smrg	  prev=
70605ffd6003Smrg	  continue
70615ffd6003Smrg	  ;;
7062b7d26471Smrg	os2dllname)
7063b7d26471Smrg	  os2dllname=$arg
7064b7d26471Smrg	  prev=
7065b7d26471Smrg	  continue
7066b7d26471Smrg	  ;;
70675ffd6003Smrg	precious_regex)
7068b7d26471Smrg	  precious_files_regex=$arg
70695ffd6003Smrg	  prev=
70705ffd6003Smrg	  continue
70715ffd6003Smrg	  ;;
70725ffd6003Smrg	release)
7073b7d26471Smrg	  release=-$arg
70745ffd6003Smrg	  prev=
70755ffd6003Smrg	  continue
70765ffd6003Smrg	  ;;
70775ffd6003Smrg	rpath | xrpath)
70785ffd6003Smrg	  # We need an absolute path.
70795ffd6003Smrg	  case $arg in
70805ffd6003Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
70815ffd6003Smrg	  *)
70825ffd6003Smrg	    func_fatal_error "only absolute run-paths are allowed"
70835ffd6003Smrg	    ;;
70845ffd6003Smrg	  esac
7085b7d26471Smrg	  if test rpath = "$prev"; then
70865ffd6003Smrg	    case "$rpath " in
70875ffd6003Smrg	    *" $arg "*) ;;
7088629baa8cSmrg	    *) func_append rpath " $arg" ;;
70895ffd6003Smrg	    esac
70905ffd6003Smrg	  else
70915ffd6003Smrg	    case "$xrpath " in
70925ffd6003Smrg	    *" $arg "*) ;;
7093629baa8cSmrg	    *) func_append xrpath " $arg" ;;
70945ffd6003Smrg	    esac
70955ffd6003Smrg	  fi
70965ffd6003Smrg	  prev=
70975ffd6003Smrg	  continue
70985ffd6003Smrg	  ;;
70995ffd6003Smrg	shrext)
7100b7d26471Smrg	  shrext_cmds=$arg
71015ffd6003Smrg	  prev=
71025ffd6003Smrg	  continue
71035ffd6003Smrg	  ;;
71045ffd6003Smrg	weak)
7105629baa8cSmrg	  func_append weak_libs " $arg"
71065ffd6003Smrg	  prev=
71075ffd6003Smrg	  continue
71085ffd6003Smrg	  ;;
7109da2e2ef6Smrg	xassembler)
7110da2e2ef6Smrg	  func_append compiler_flags " -Xassembler $qarg"
7111da2e2ef6Smrg	  prev=
7112da2e2ef6Smrg	  func_append compile_command " -Xassembler $qarg"
7113da2e2ef6Smrg	  func_append finalize_command " -Xassembler $qarg"
7114da2e2ef6Smrg	  continue
7115da2e2ef6Smrg	  ;;
71165ffd6003Smrg	xcclinker)
7117629baa8cSmrg	  func_append linker_flags " $qarg"
7118629baa8cSmrg	  func_append compiler_flags " $qarg"
71195ffd6003Smrg	  prev=
71205ffd6003Smrg	  func_append compile_command " $qarg"
71215ffd6003Smrg	  func_append finalize_command " $qarg"
71225ffd6003Smrg	  continue
71235ffd6003Smrg	  ;;
71245ffd6003Smrg	xcompiler)
7125629baa8cSmrg	  func_append compiler_flags " $qarg"
71265ffd6003Smrg	  prev=
71275ffd6003Smrg	  func_append compile_command " $qarg"
71285ffd6003Smrg	  func_append finalize_command " $qarg"
71295ffd6003Smrg	  continue
71305ffd6003Smrg	  ;;
71315ffd6003Smrg	xlinker)
7132629baa8cSmrg	  func_append linker_flags " $qarg"
7133629baa8cSmrg	  func_append compiler_flags " $wl$qarg"
71345ffd6003Smrg	  prev=
71355ffd6003Smrg	  func_append compile_command " $wl$qarg"
71365ffd6003Smrg	  func_append finalize_command " $wl$qarg"
71375ffd6003Smrg	  continue
7138145b7b3cSmrg	  ;;
7139145b7b3cSmrg	*)
71405ffd6003Smrg	  eval "$prev=\"\$arg\""
71415ffd6003Smrg	  prev=
71425ffd6003Smrg	  continue
7143145b7b3cSmrg	  ;;
7144145b7b3cSmrg	esac
71455ffd6003Smrg      fi # test -n "$prev"
7146145b7b3cSmrg
7147b7d26471Smrg      prevarg=$arg
7148145b7b3cSmrg
71495ffd6003Smrg      case $arg in
71505ffd6003Smrg      -all-static)
71515ffd6003Smrg	if test -n "$link_static_flag"; then
71525ffd6003Smrg	  # See comment for -static flag below, for more details.
71535ffd6003Smrg	  func_append compile_command " $link_static_flag"
71545ffd6003Smrg	  func_append finalize_command " $link_static_flag"
7155145b7b3cSmrg	fi
71565ffd6003Smrg	continue
71575ffd6003Smrg	;;
7158145b7b3cSmrg
71595ffd6003Smrg      -allow-undefined)
71605ffd6003Smrg	# FIXME: remove this flag sometime in the future.
7161b7d26471Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
71625ffd6003Smrg	;;
7163145b7b3cSmrg
71645ffd6003Smrg      -avoid-version)
71655ffd6003Smrg	avoid_version=yes
71665ffd6003Smrg	continue
71675ffd6003Smrg	;;
7168145b7b3cSmrg
7169629baa8cSmrg      -bindir)
7170629baa8cSmrg	prev=bindir
7171629baa8cSmrg	continue
7172629baa8cSmrg	;;
7173629baa8cSmrg
71745ffd6003Smrg      -dlopen)
71755ffd6003Smrg	prev=dlfiles
71765ffd6003Smrg	continue
71775ffd6003Smrg	;;
7178145b7b3cSmrg
71795ffd6003Smrg      -dlpreopen)
71805ffd6003Smrg	prev=dlprefiles
71815ffd6003Smrg	continue
71825ffd6003Smrg	;;
7183145b7b3cSmrg
71845ffd6003Smrg      -export-dynamic)
71855ffd6003Smrg	export_dynamic=yes
71865ffd6003Smrg	continue
71875ffd6003Smrg	;;
7188145b7b3cSmrg
71895ffd6003Smrg      -export-symbols | -export-symbols-regex)
71905ffd6003Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
71915ffd6003Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
71925ffd6003Smrg	fi
7193b7d26471Smrg	if test X-export-symbols = "X$arg"; then
71945ffd6003Smrg	  prev=expsyms
7195145b7b3cSmrg	else
71965ffd6003Smrg	  prev=expsyms_regex
7197145b7b3cSmrg	fi
71985ffd6003Smrg	continue
71995ffd6003Smrg	;;
7200145b7b3cSmrg
72015ffd6003Smrg      -framework)
72025ffd6003Smrg	prev=framework
72035ffd6003Smrg	continue
72045ffd6003Smrg	;;
7205145b7b3cSmrg
72065ffd6003Smrg      -inst-prefix-dir)
72075ffd6003Smrg	prev=inst_prefix
72085ffd6003Smrg	continue
72095ffd6003Smrg	;;
7210145b7b3cSmrg
72115ffd6003Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
72125ffd6003Smrg      # so, if we see these flags be careful not to treat them like -L
72135ffd6003Smrg      -L[A-Z][A-Z]*:*)
72145ffd6003Smrg	case $with_gcc/$host in
72155ffd6003Smrg	no/*-*-irix* | /*-*-irix*)
72165ffd6003Smrg	  func_append compile_command " $arg"
72175ffd6003Smrg	  func_append finalize_command " $arg"
72185ffd6003Smrg	  ;;
72195ffd6003Smrg	esac
72205ffd6003Smrg	continue
72215ffd6003Smrg	;;
7222145b7b3cSmrg
72235ffd6003Smrg      -L*)
7224629baa8cSmrg	func_stripname "-L" '' "$arg"
7225629baa8cSmrg	if test -z "$func_stripname_result"; then
72265ffd6003Smrg	  if test "$#" -gt 0; then
7227b7d26471Smrg	    func_fatal_error "require no space between '-L' and '$1'"
7228145b7b3cSmrg	  else
7229b7d26471Smrg	    func_fatal_error "need path for '-L' option"
7230145b7b3cSmrg	  fi
72315ffd6003Smrg	fi
7232629baa8cSmrg	func_resolve_sysroot "$func_stripname_result"
7233629baa8cSmrg	dir=$func_resolve_sysroot_result
72345ffd6003Smrg	# We need an absolute path.
72355ffd6003Smrg	case $dir in
72365ffd6003Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
72375ffd6003Smrg	*)
72385ffd6003Smrg	  absdir=`cd "$dir" && pwd`
72395ffd6003Smrg	  test -z "$absdir" && \
7240b7d26471Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241b7d26471Smrg	  dir=$absdir
72425ffd6003Smrg	  ;;
7243145b7b3cSmrg	esac
72445ffd6003Smrg	case "$deplibs " in
7245629baa8cSmrg	*" -L$dir "* | *" $arg "*)
7246629baa8cSmrg	  # Will only happen for absolute or sysroot arguments
7247629baa8cSmrg	  ;;
72485ffd6003Smrg	*)
7249629baa8cSmrg	  # Preserve sysroot, but never include relative directories
7250629baa8cSmrg	  case $dir in
7251629baa8cSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7252629baa8cSmrg	    *) func_append deplibs " -L$dir" ;;
7253629baa8cSmrg	  esac
7254629baa8cSmrg	  func_append lib_search_path " $dir"
72555ffd6003Smrg	  ;;
7256145b7b3cSmrg	esac
7257145b7b3cSmrg	case $host in
72585ffd6003Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7259629baa8cSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
72605ffd6003Smrg	  case :$dllsearchpath: in
72615ffd6003Smrg	  *":$dir:"*) ;;
72625ffd6003Smrg	  ::) dllsearchpath=$dir;;
7263629baa8cSmrg	  *) func_append dllsearchpath ":$dir";;
72645ffd6003Smrg	  esac
72655ffd6003Smrg	  case :$dllsearchpath: in
72665ffd6003Smrg	  *":$testbindir:"*) ;;
72675ffd6003Smrg	  ::) dllsearchpath=$testbindir;;
7268629baa8cSmrg	  *) func_append dllsearchpath ":$testbindir";;
72695ffd6003Smrg	  esac
72705ffd6003Smrg	  ;;
7271145b7b3cSmrg	esac
72725ffd6003Smrg	continue
72735ffd6003Smrg	;;
7274145b7b3cSmrg
72755ffd6003Smrg      -l*)
7276b7d26471Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
72775ffd6003Smrg	  case $host in
7278629baa8cSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
72795ffd6003Smrg	    # These systems don't actually have a C or math library (as such)
72805ffd6003Smrg	    continue
72815ffd6003Smrg	    ;;
72825ffd6003Smrg	  *-*-os2*)
72835ffd6003Smrg	    # These systems don't actually have a C library (as such)
7284b7d26471Smrg	    test X-lc = "X$arg" && continue
72855ffd6003Smrg	    ;;
7286da2e2ef6Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
72875ffd6003Smrg	    # Do not include libc due to us having libc/libc_r.
7288b7d26471Smrg	    test X-lc = "X$arg" && continue
72895ffd6003Smrg	    ;;
72905ffd6003Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
72915ffd6003Smrg	    # Rhapsody C and math libraries are in the System framework
7292629baa8cSmrg	    func_append deplibs " System.ltframework"
72935ffd6003Smrg	    continue
72945ffd6003Smrg	    ;;
72955ffd6003Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
72965ffd6003Smrg	    # Causes problems with __ctype
7297b7d26471Smrg	    test X-lc = "X$arg" && continue
72985ffd6003Smrg	    ;;
72995ffd6003Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
73005ffd6003Smrg	    # Compiler inserts libc in the correct place for threads to work
7301b7d26471Smrg	    test X-lc = "X$arg" && continue
73025ffd6003Smrg	    ;;
73035ffd6003Smrg	  esac
7304b7d26471Smrg	elif test X-lc_r = "X$arg"; then
73055ffd6003Smrg	 case $host in
7306da2e2ef6Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
73075ffd6003Smrg	   # Do not include libc_r directly, use -pthread flag.
73085ffd6003Smrg	   continue
73095ffd6003Smrg	   ;;
73105ffd6003Smrg	 esac
73115ffd6003Smrg	fi
7312629baa8cSmrg	func_append deplibs " $arg"
73135ffd6003Smrg	continue
73145ffd6003Smrg	;;
7315145b7b3cSmrg
7316b7d26471Smrg      -mllvm)
7317b7d26471Smrg	prev=mllvm
7318b7d26471Smrg	continue
7319b7d26471Smrg	;;
7320b7d26471Smrg
73215ffd6003Smrg      -module)
73225ffd6003Smrg	module=yes
73235ffd6003Smrg	continue
73245ffd6003Smrg	;;
7325145b7b3cSmrg
73265ffd6003Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
73275ffd6003Smrg      # classes, name mangling, and exception handling.
73285ffd6003Smrg      # Darwin uses the -arch flag to determine output architecture.
7329629baa8cSmrg      -model|-arch|-isysroot|--sysroot)
7330629baa8cSmrg	func_append compiler_flags " $arg"
73315ffd6003Smrg	func_append compile_command " $arg"
73325ffd6003Smrg	func_append finalize_command " $arg"
73335ffd6003Smrg	prev=xcompiler
73345ffd6003Smrg	continue
73355ffd6003Smrg	;;
7336da2e2ef6Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337da2e2ef6Smrg     -pthread)
7338da2e2ef6Smrg	case $host in
7339da2e2ef6Smrg	  *solaris2*) ;;
7340da2e2ef6Smrg	  *)
7341da2e2ef6Smrg	    case "$new_inherited_linker_flags " in
7342da2e2ef6Smrg	        *" $arg "*) ;;
7343da2e2ef6Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344da2e2ef6Smrg	    esac
7345da2e2ef6Smrg	  ;;
7346da2e2ef6Smrg	esac
7347da2e2ef6Smrg	continue
7348da2e2ef6Smrg	;;
7349da2e2ef6Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350b7d26471Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7351629baa8cSmrg	func_append compiler_flags " $arg"
73525ffd6003Smrg	func_append compile_command " $arg"
73535ffd6003Smrg	func_append finalize_command " $arg"
73545ffd6003Smrg	case "$new_inherited_linker_flags " in
73555ffd6003Smrg	    *" $arg "*) ;;
7356629baa8cSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
73575ffd6003Smrg	esac
73585ffd6003Smrg	continue
73595ffd6003Smrg	;;
7360145b7b3cSmrg
73615ffd6003Smrg      -multi_module)
7362b7d26471Smrg	single_module=$wl-multi_module
73635ffd6003Smrg	continue
73645ffd6003Smrg	;;
7365145b7b3cSmrg
73665ffd6003Smrg      -no-fast-install)
73675ffd6003Smrg	fast_install=no
73685ffd6003Smrg	continue
73695ffd6003Smrg	;;
7370145b7b3cSmrg
73715ffd6003Smrg      -no-install)
73725ffd6003Smrg	case $host in
73735ffd6003Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
73745ffd6003Smrg	  # The PATH hackery in wrapper scripts is required on Windows
73755ffd6003Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7376b7d26471Smrg	  func_warning "'-no-install' is ignored for $host"
7377b7d26471Smrg	  func_warning "assuming '-no-fast-install' instead"
73785ffd6003Smrg	  fast_install=no
73795ffd6003Smrg	  ;;
73805ffd6003Smrg	*) no_install=yes ;;
73815ffd6003Smrg	esac
73825ffd6003Smrg	continue
73835ffd6003Smrg	;;
7384145b7b3cSmrg
73855ffd6003Smrg      -no-undefined)
73865ffd6003Smrg	allow_undefined=no
73875ffd6003Smrg	continue
73885ffd6003Smrg	;;
7389145b7b3cSmrg
73905ffd6003Smrg      -objectlist)
73915ffd6003Smrg	prev=objectlist
73925ffd6003Smrg	continue
73935ffd6003Smrg	;;
7394145b7b3cSmrg
7395b7d26471Smrg      -os2dllname)
7396b7d26471Smrg	prev=os2dllname
7397b7d26471Smrg	continue
7398b7d26471Smrg	;;
7399b7d26471Smrg
74005ffd6003Smrg      -o) prev=output ;;
7401145b7b3cSmrg
74025ffd6003Smrg      -precious-files-regex)
74035ffd6003Smrg	prev=precious_regex
74045ffd6003Smrg	continue
74055ffd6003Smrg	;;
7406145b7b3cSmrg
74075ffd6003Smrg      -release)
74085ffd6003Smrg	prev=release
74095ffd6003Smrg	continue
74105ffd6003Smrg	;;
7411145b7b3cSmrg
74125ffd6003Smrg      -rpath)
74135ffd6003Smrg	prev=rpath
74145ffd6003Smrg	continue
74155ffd6003Smrg	;;
7416145b7b3cSmrg
74175ffd6003Smrg      -R)
74185ffd6003Smrg	prev=xrpath
74195ffd6003Smrg	continue
74205ffd6003Smrg	;;
7421145b7b3cSmrg
74225ffd6003Smrg      -R*)
74235ffd6003Smrg	func_stripname '-R' '' "$arg"
74245ffd6003Smrg	dir=$func_stripname_result
74255ffd6003Smrg	# We need an absolute path.
74265ffd6003Smrg	case $dir in
74275ffd6003Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7428629baa8cSmrg	=*)
7429629baa8cSmrg	  func_stripname '=' '' "$dir"
7430629baa8cSmrg	  dir=$lt_sysroot$func_stripname_result
7431629baa8cSmrg	  ;;
74325ffd6003Smrg	*)
74335ffd6003Smrg	  func_fatal_error "only absolute run-paths are allowed"
74345ffd6003Smrg	  ;;
74355ffd6003Smrg	esac
74365ffd6003Smrg	case "$xrpath " in
74375ffd6003Smrg	*" $dir "*) ;;
7438629baa8cSmrg	*) func_append xrpath " $dir" ;;
74395ffd6003Smrg	esac
74405ffd6003Smrg	continue
74415ffd6003Smrg	;;
7442145b7b3cSmrg
74435ffd6003Smrg      -shared)
74445ffd6003Smrg	# The effects of -shared are defined in a previous loop.
74455ffd6003Smrg	continue
74465ffd6003Smrg	;;
7447145b7b3cSmrg
74485ffd6003Smrg      -shrext)
74495ffd6003Smrg	prev=shrext
74505ffd6003Smrg	continue
74515ffd6003Smrg	;;
7452145b7b3cSmrg
74535ffd6003Smrg      -static | -static-libtool-libs)
74545ffd6003Smrg	# The effects of -static are defined in a previous loop.
74555ffd6003Smrg	# We used to do the same as -all-static on platforms that
74565ffd6003Smrg	# didn't have a PIC flag, but the assumption that the effects
74575ffd6003Smrg	# would be equivalent was wrong.  It would break on at least
74585ffd6003Smrg	# Digital Unix and AIX.
74595ffd6003Smrg	continue
74605ffd6003Smrg	;;
7461145b7b3cSmrg
74625ffd6003Smrg      -thread-safe)
74635ffd6003Smrg	thread_safe=yes
74645ffd6003Smrg	continue
74655ffd6003Smrg	;;
7466145b7b3cSmrg
74675ffd6003Smrg      -version-info)
74685ffd6003Smrg	prev=vinfo
74695ffd6003Smrg	continue
74705ffd6003Smrg	;;
7471145b7b3cSmrg
74725ffd6003Smrg      -version-number)
74735ffd6003Smrg	prev=vinfo
74745ffd6003Smrg	vinfo_number=yes
74755ffd6003Smrg	continue
74765ffd6003Smrg	;;
7477145b7b3cSmrg
74785ffd6003Smrg      -weak)
74795ffd6003Smrg        prev=weak
74805ffd6003Smrg	continue
74815ffd6003Smrg	;;
7482145b7b3cSmrg
74835ffd6003Smrg      -Wc,*)
74845ffd6003Smrg	func_stripname '-Wc,' '' "$arg"
74855ffd6003Smrg	args=$func_stripname_result
74865ffd6003Smrg	arg=
7487b7d26471Smrg	save_ifs=$IFS; IFS=,
74885ffd6003Smrg	for flag in $args; do
7489b7d26471Smrg	  IFS=$save_ifs
7490da2e2ef6Smrg          func_quote_arg pretty "$flag"
7491da2e2ef6Smrg	  func_append arg " $func_quote_arg_result"
7492da2e2ef6Smrg	  func_append compiler_flags " $func_quote_arg_result"
74935ffd6003Smrg	done
7494b7d26471Smrg	IFS=$save_ifs
74955ffd6003Smrg	func_stripname ' ' '' "$arg"
74965ffd6003Smrg	arg=$func_stripname_result
74975ffd6003Smrg	;;
7498145b7b3cSmrg
74995ffd6003Smrg      -Wl,*)
75005ffd6003Smrg	func_stripname '-Wl,' '' "$arg"
75015ffd6003Smrg	args=$func_stripname_result
75025ffd6003Smrg	arg=
7503b7d26471Smrg	save_ifs=$IFS; IFS=,
75045ffd6003Smrg	for flag in $args; do
7505b7d26471Smrg	  IFS=$save_ifs
7506da2e2ef6Smrg          func_quote_arg pretty "$flag"
7507da2e2ef6Smrg	  func_append arg " $wl$func_quote_arg_result"
7508da2e2ef6Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509da2e2ef6Smrg	  func_append linker_flags " $func_quote_arg_result"
75105ffd6003Smrg	done
7511b7d26471Smrg	IFS=$save_ifs
75125ffd6003Smrg	func_stripname ' ' '' "$arg"
75135ffd6003Smrg	arg=$func_stripname_result
75145ffd6003Smrg	;;
7515145b7b3cSmrg
7516da2e2ef6Smrg      -Xassembler)
7517da2e2ef6Smrg        prev=xassembler
7518da2e2ef6Smrg        continue
7519da2e2ef6Smrg        ;;
7520da2e2ef6Smrg
75215ffd6003Smrg      -Xcompiler)
75225ffd6003Smrg	prev=xcompiler
75235ffd6003Smrg	continue
75245ffd6003Smrg	;;
7525145b7b3cSmrg
75265ffd6003Smrg      -Xlinker)
75275ffd6003Smrg	prev=xlinker
75285ffd6003Smrg	continue
75295ffd6003Smrg	;;
7530145b7b3cSmrg
75315ffd6003Smrg      -XCClinker)
75325ffd6003Smrg	prev=xcclinker
75335ffd6003Smrg	continue
75345ffd6003Smrg	;;
7535145b7b3cSmrg
75365ffd6003Smrg      # -msg_* for osf cc
75375ffd6003Smrg      -msg_*)
7538da2e2ef6Smrg	func_quote_arg pretty "$arg"
7539da2e2ef6Smrg	arg=$func_quote_arg_result
75405ffd6003Smrg	;;
7541145b7b3cSmrg
7542629baa8cSmrg      # Flags to be passed through unchanged, with rationale:
7543629baa8cSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7544629baa8cSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7545629baa8cSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7546629baa8cSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7547629baa8cSmrg      # -q*                  compiler args for the IBM compiler
7548629baa8cSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7549629baa8cSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7550629baa8cSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551b7d26471Smrg      # -fstack-protector*   stack protector flags for GCC
7552629baa8cSmrg      # @file                GCC response files
7553629baa8cSmrg      # -tp=*                Portland pgcc target processor selection
7554629baa8cSmrg      # --sysroot=*          for sysroot support
7555b7d26471Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7556da2e2ef6Smrg      # -specs=*             GCC specs files
7557b7d26471Smrg      # -stdlib=*            select c++ std lib with clang
7558da2e2ef6Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
7559da2e2ef6Smrg      # -fuse-ld=*           Linker select flags for GCC
7560da2e2ef6Smrg      # -Wa,*                Pass flags directly to the assembler
75615ffd6003Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7562629baa8cSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7563da2e2ef6Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564da2e2ef6Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565da2e2ef6Smrg        func_quote_arg pretty "$arg"
7566da2e2ef6Smrg	arg=$func_quote_arg_result
75675ffd6003Smrg        func_append compile_command " $arg"
75685ffd6003Smrg        func_append finalize_command " $arg"
7569629baa8cSmrg        func_append compiler_flags " $arg"
75705ffd6003Smrg        continue
75715ffd6003Smrg        ;;
7572145b7b3cSmrg
7573b7d26471Smrg      -Z*)
7574b7d26471Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575b7d26471Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576b7d26471Smrg	  compiler_flags="$compiler_flags $arg"
7577b7d26471Smrg	  func_append compile_command " $arg"
7578b7d26471Smrg	  func_append finalize_command " $arg"
7579b7d26471Smrg	  case $arg in
7580b7d26471Smrg	  -Zlinker | -Zstack)
7581b7d26471Smrg	    prev=xcompiler
7582b7d26471Smrg	    ;;
7583b7d26471Smrg	  esac
7584b7d26471Smrg	  continue
7585b7d26471Smrg        else
7586b7d26471Smrg	  # Otherwise treat like 'Some other compiler flag' below
7587da2e2ef6Smrg	  func_quote_arg pretty "$arg"
7588da2e2ef6Smrg	  arg=$func_quote_arg_result
7589b7d26471Smrg        fi
7590b7d26471Smrg	;;
7591b7d26471Smrg
75925ffd6003Smrg      # Some other compiler flag.
75935ffd6003Smrg      -* | +*)
7594da2e2ef6Smrg        func_quote_arg pretty "$arg"
7595da2e2ef6Smrg	arg=$func_quote_arg_result
75965ffd6003Smrg	;;
7597145b7b3cSmrg
75985ffd6003Smrg      *.$objext)
75995ffd6003Smrg	# A standard object.
7600629baa8cSmrg	func_append objs " $arg"
76015ffd6003Smrg	;;
7602145b7b3cSmrg
76035ffd6003Smrg      *.lo)
76045ffd6003Smrg	# A libtool-controlled object.
7605145b7b3cSmrg
76065ffd6003Smrg	# Check to see that this really is a libtool object.
76075ffd6003Smrg	if func_lalib_unsafe_p "$arg"; then
76085ffd6003Smrg	  pic_object=
76095ffd6003Smrg	  non_pic_object=
7610145b7b3cSmrg
76115ffd6003Smrg	  # Read the .lo file
76125ffd6003Smrg	  func_source "$arg"
7613145b7b3cSmrg
76145ffd6003Smrg	  if test -z "$pic_object" ||
76155ffd6003Smrg	     test -z "$non_pic_object" ||
7616b7d26471Smrg	     test none = "$pic_object" &&
7617b7d26471Smrg	     test none = "$non_pic_object"; then
7618b7d26471Smrg	    func_fatal_error "cannot find name of object for '$arg'"
76195ffd6003Smrg	  fi
7620145b7b3cSmrg
76215ffd6003Smrg	  # Extract subdirectory from the argument.
76225ffd6003Smrg	  func_dirname "$arg" "/" ""
7623b7d26471Smrg	  xdir=$func_dirname_result
7624145b7b3cSmrg
7625b7d26471Smrg	  test none = "$pic_object" || {
76265ffd6003Smrg	    # Prepend the subdirectory the object is found in.
7627b7d26471Smrg	    pic_object=$xdir$pic_object
7628145b7b3cSmrg
7629b7d26471Smrg	    if test dlfiles = "$prev"; then
7630b7d26471Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7631629baa8cSmrg		func_append dlfiles " $pic_object"
76325ffd6003Smrg		prev=
76335ffd6003Smrg		continue
76345ffd6003Smrg	      else
76355ffd6003Smrg		# If libtool objects are unsupported, then we need to preload.
76365ffd6003Smrg		prev=dlprefiles
76375ffd6003Smrg	      fi
76385ffd6003Smrg	    fi
7639145b7b3cSmrg
76405ffd6003Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7641b7d26471Smrg	    if test dlprefiles = "$prev"; then
76425ffd6003Smrg	      # Preload the old-style object.
7643629baa8cSmrg	      func_append dlprefiles " $pic_object"
76445ffd6003Smrg	      prev=
76455ffd6003Smrg	    fi
7646145b7b3cSmrg
76475ffd6003Smrg	    # A PIC object.
76485ffd6003Smrg	    func_append libobjs " $pic_object"
7649b7d26471Smrg	    arg=$pic_object
7650b7d26471Smrg	  }
7651145b7b3cSmrg
76525ffd6003Smrg	  # Non-PIC object.
7653b7d26471Smrg	  if test none != "$non_pic_object"; then
76545ffd6003Smrg	    # Prepend the subdirectory the object is found in.
7655b7d26471Smrg	    non_pic_object=$xdir$non_pic_object
7656145b7b3cSmrg
76575ffd6003Smrg	    # A standard non-PIC object
76585ffd6003Smrg	    func_append non_pic_objects " $non_pic_object"
7659b7d26471Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660b7d26471Smrg	      arg=$non_pic_object
76615ffd6003Smrg	    fi
76625ffd6003Smrg	  else
76635ffd6003Smrg	    # If the PIC object exists, use it instead.
76645ffd6003Smrg	    # $xdir was prepended to $pic_object above.
7665b7d26471Smrg	    non_pic_object=$pic_object
76665ffd6003Smrg	    func_append non_pic_objects " $non_pic_object"
76675ffd6003Smrg	  fi
76685ffd6003Smrg	else
76695ffd6003Smrg	  # Only an error if not doing a dry-run.
76705ffd6003Smrg	  if $opt_dry_run; then
76715ffd6003Smrg	    # Extract subdirectory from the argument.
76725ffd6003Smrg	    func_dirname "$arg" "/" ""
7673b7d26471Smrg	    xdir=$func_dirname_result
76745ffd6003Smrg
76755ffd6003Smrg	    func_lo2o "$arg"
76765ffd6003Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
76775ffd6003Smrg	    non_pic_object=$xdir$func_lo2o_result
76785ffd6003Smrg	    func_append libobjs " $pic_object"
76795ffd6003Smrg	    func_append non_pic_objects " $non_pic_object"
76805ffd6003Smrg	  else
7681b7d26471Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
76825ffd6003Smrg	  fi
76835ffd6003Smrg	fi
76845ffd6003Smrg	;;
7685145b7b3cSmrg
76865ffd6003Smrg      *.$libext)
76875ffd6003Smrg	# An archive.
7688629baa8cSmrg	func_append deplibs " $arg"
7689629baa8cSmrg	func_append old_deplibs " $arg"
76905ffd6003Smrg	continue
76915ffd6003Smrg	;;
7692578741aaSmrg
76935ffd6003Smrg      *.la)
76945ffd6003Smrg	# A libtool-controlled library.
7695145b7b3cSmrg
7696629baa8cSmrg	func_resolve_sysroot "$arg"
7697b7d26471Smrg	if test dlfiles = "$prev"; then
76985ffd6003Smrg	  # This library was specified with -dlopen.
7699629baa8cSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
77005ffd6003Smrg	  prev=
7701b7d26471Smrg	elif test dlprefiles = "$prev"; then
77025ffd6003Smrg	  # The library was specified with -dlpreopen.
7703629baa8cSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
77045ffd6003Smrg	  prev=
77055ffd6003Smrg	else
7706629baa8cSmrg	  func_append deplibs " $func_resolve_sysroot_result"
77075ffd6003Smrg	fi
77085ffd6003Smrg	continue
77095ffd6003Smrg	;;
7710145b7b3cSmrg
77115ffd6003Smrg      # Some other compiler argument.
77125ffd6003Smrg      *)
77135ffd6003Smrg	# Unknown arguments in both finalize_command and compile_command need
77145ffd6003Smrg	# to be aesthetically quoted because they are evaled later.
7715da2e2ef6Smrg	func_quote_arg pretty "$arg"
7716da2e2ef6Smrg	arg=$func_quote_arg_result
77175ffd6003Smrg	;;
77185ffd6003Smrg      esac # arg
7719145b7b3cSmrg
77205ffd6003Smrg      # Now actually substitute the argument into the commands.
77215ffd6003Smrg      if test -n "$arg"; then
77225ffd6003Smrg	func_append compile_command " $arg"
77235ffd6003Smrg	func_append finalize_command " $arg"
77245ffd6003Smrg      fi
77255ffd6003Smrg    done # argument parsing loop
7726145b7b3cSmrg
77275ffd6003Smrg    test -n "$prev" && \
7728b7d26471Smrg      func_fatal_help "the '$prevarg' option requires an argument"
7729145b7b3cSmrg
7730b7d26471Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
77315ffd6003Smrg      eval arg=\"$export_dynamic_flag_spec\"
77325ffd6003Smrg      func_append compile_command " $arg"
77335ffd6003Smrg      func_append finalize_command " $arg"
7734145b7b3cSmrg    fi
7735145b7b3cSmrg
77365ffd6003Smrg    oldlibs=
77375ffd6003Smrg    # calculate the name of the file, without its directory
77385ffd6003Smrg    func_basename "$output"
7739b7d26471Smrg    outputname=$func_basename_result
7740b7d26471Smrg    libobjs_save=$libobjs
77415ffd6003Smrg
77425ffd6003Smrg    if test -n "$shlibpath_var"; then
77435ffd6003Smrg      # get the directories listed in $shlibpath_var
7744b7d26471Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
77455ffd6003Smrg    else
77465ffd6003Smrg      shlib_search_path=
77475ffd6003Smrg    fi
77485ffd6003Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
77495ffd6003Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
77505ffd6003Smrg
7751b7d26471Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7752b7d26471Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753b7d26471Smrg
77545ffd6003Smrg    func_dirname "$output" "/" ""
7755b7d26471Smrg    output_objdir=$func_dirname_result$objdir
7756629baa8cSmrg    func_to_tool_file "$output_objdir/"
7757629baa8cSmrg    tool_output_objdir=$func_to_tool_file_result
77585ffd6003Smrg    # Create the object directory.
77595ffd6003Smrg    func_mkdir_p "$output_objdir"
77605ffd6003Smrg
77615ffd6003Smrg    # Determine the type of output
77625ffd6003Smrg    case $output in
77635ffd6003Smrg    "")
77645ffd6003Smrg      func_fatal_help "you must specify an output file"
77655ffd6003Smrg      ;;
77665ffd6003Smrg    *.$libext) linkmode=oldlib ;;
77675ffd6003Smrg    *.lo | *.$objext) linkmode=obj ;;
77685ffd6003Smrg    *.la) linkmode=lib ;;
77695ffd6003Smrg    *) linkmode=prog ;; # Anything else should be a program.
77705ffd6003Smrg    esac
77715ffd6003Smrg
77725ffd6003Smrg    specialdeplibs=
77735ffd6003Smrg
77745ffd6003Smrg    libs=
77755ffd6003Smrg    # Find all interdependent deplibs by searching for libraries
77765ffd6003Smrg    # that are linked more than once (e.g. -la -lb -la)
77775ffd6003Smrg    for deplib in $deplibs; do
7778b7d26471Smrg      if $opt_preserve_dup_deps; then
77795ffd6003Smrg	case "$libs " in
7780629baa8cSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
77815ffd6003Smrg	esac
77825ffd6003Smrg      fi
7783629baa8cSmrg      func_append libs " $deplib"
77845ffd6003Smrg    done
77855ffd6003Smrg
7786b7d26471Smrg    if test lib = "$linkmode"; then
77875ffd6003Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
77885ffd6003Smrg
77895ffd6003Smrg      # Compute libraries that are listed more than once in $predeps
77905ffd6003Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
77915ffd6003Smrg      # not to be eliminated).
77925ffd6003Smrg      pre_post_deps=
77935ffd6003Smrg      if $opt_duplicate_compiler_generated_deps; then
77945ffd6003Smrg	for pre_post_dep in $predeps $postdeps; do
77955ffd6003Smrg	  case "$pre_post_deps " in
7796629baa8cSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
77975ffd6003Smrg	  esac
7798629baa8cSmrg	  func_append pre_post_deps " $pre_post_dep"
77995ffd6003Smrg	done
78005ffd6003Smrg      fi
78015ffd6003Smrg      pre_post_deps=
78025ffd6003Smrg    fi
78035ffd6003Smrg
78045ffd6003Smrg    deplibs=
78055ffd6003Smrg    newdependency_libs=
78065ffd6003Smrg    newlib_search_path=
78075ffd6003Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
78085ffd6003Smrg    notinst_deplibs= # not-installed libtool libraries
78095ffd6003Smrg    notinst_path= # paths that contain not-installed libtool libraries
78105ffd6003Smrg
78115ffd6003Smrg    case $linkmode in
78125ffd6003Smrg    lib)
78135ffd6003Smrg	passes="conv dlpreopen link"
78145ffd6003Smrg	for file in $dlfiles $dlprefiles; do
78155ffd6003Smrg	  case $file in
78165ffd6003Smrg	  *.la) ;;
78175ffd6003Smrg	  *)
7818b7d26471Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
78195ffd6003Smrg	    ;;
78205ffd6003Smrg	  esac
78215ffd6003Smrg	done
78225ffd6003Smrg	;;
78235ffd6003Smrg    prog)
78245ffd6003Smrg	compile_deplibs=
78255ffd6003Smrg	finalize_deplibs=
7826b7d26471Smrg	alldeplibs=false
78275ffd6003Smrg	newdlfiles=
78285ffd6003Smrg	newdlprefiles=
78295ffd6003Smrg	passes="conv scan dlopen dlpreopen link"
78305ffd6003Smrg	;;
78315ffd6003Smrg    *)  passes="conv"
78325ffd6003Smrg	;;
78335ffd6003Smrg    esac
78345ffd6003Smrg
78355ffd6003Smrg    for pass in $passes; do
78365ffd6003Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
78375ffd6003Smrg      # so that -L comes before libs that need it for instance...
7838b7d26471Smrg      if test lib,link = "$linkmode,$pass"; then
78395ffd6003Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
78405ffd6003Smrg	##        order, and fix it there properly
78415ffd6003Smrg        tmp_deplibs=
78425ffd6003Smrg	for deplib in $deplibs; do
78435ffd6003Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
78445ffd6003Smrg	done
7845b7d26471Smrg	deplibs=$tmp_deplibs
78465ffd6003Smrg      fi
78475ffd6003Smrg
7848b7d26471Smrg      if test lib,link = "$linkmode,$pass" ||
7849b7d26471Smrg	 test prog,scan = "$linkmode,$pass"; then
7850b7d26471Smrg	libs=$deplibs
78515ffd6003Smrg	deplibs=
78525ffd6003Smrg      fi
7853b7d26471Smrg      if test prog = "$linkmode"; then
78545ffd6003Smrg	case $pass in
7855b7d26471Smrg	dlopen) libs=$dlfiles ;;
7856b7d26471Smrg	dlpreopen) libs=$dlprefiles ;;
7857629baa8cSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
78585ffd6003Smrg	esac
78595ffd6003Smrg      fi
7860b7d26471Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
78615ffd6003Smrg	# Collect and forward deplibs of preopened libtool libs
78625ffd6003Smrg	for lib in $dlprefiles; do
78635ffd6003Smrg	  # Ignore non-libtool-libs
78645ffd6003Smrg	  dependency_libs=
7865629baa8cSmrg	  func_resolve_sysroot "$lib"
78665ffd6003Smrg	  case $lib in
7867629baa8cSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
78685ffd6003Smrg	  esac
78695ffd6003Smrg
78705ffd6003Smrg	  # Collect preopened libtool deplibs, except any this library
78715ffd6003Smrg	  # has declared as weak libs
78725ffd6003Smrg	  for deplib in $dependency_libs; do
7873629baa8cSmrg	    func_basename "$deplib"
7874629baa8cSmrg            deplib_base=$func_basename_result
78755ffd6003Smrg	    case " $weak_libs " in
78765ffd6003Smrg	    *" $deplib_base "*) ;;
7877629baa8cSmrg	    *) func_append deplibs " $deplib" ;;
78785ffd6003Smrg	    esac
78795ffd6003Smrg	  done
78805ffd6003Smrg	done
7881b7d26471Smrg	libs=$dlprefiles
78825ffd6003Smrg      fi
7883b7d26471Smrg      if test dlopen = "$pass"; then
78845ffd6003Smrg	# Collect dlpreopened libraries
7885b7d26471Smrg	save_deplibs=$deplibs
78865ffd6003Smrg	deplibs=
78875ffd6003Smrg      fi
78885ffd6003Smrg
78895ffd6003Smrg      for deplib in $libs; do
78905ffd6003Smrg	lib=
7891b7d26471Smrg	found=false
78925ffd6003Smrg	case $deplib in
7893b7d26471Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894b7d26471Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895b7d26471Smrg	  if test prog,link = "$linkmode,$pass"; then
78965ffd6003Smrg	    compile_deplibs="$deplib $compile_deplibs"
78975ffd6003Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
78985ffd6003Smrg	  else
7899629baa8cSmrg	    func_append compiler_flags " $deplib"
7900b7d26471Smrg	    if test lib = "$linkmode"; then
79015ffd6003Smrg		case "$new_inherited_linker_flags " in
79025ffd6003Smrg		    *" $deplib "*) ;;
7903629baa8cSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79045ffd6003Smrg		esac
79055ffd6003Smrg	    fi
79065ffd6003Smrg	  fi
79075ffd6003Smrg	  continue
79085ffd6003Smrg	  ;;
79095ffd6003Smrg	-l*)
7910b7d26471Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911b7d26471Smrg	    func_warning "'-l' is ignored for archives/objects"
79125ffd6003Smrg	    continue
79135ffd6003Smrg	  fi
79145ffd6003Smrg	  func_stripname '-l' '' "$deplib"
79155ffd6003Smrg	  name=$func_stripname_result
7916b7d26471Smrg	  if test lib = "$linkmode"; then
79175ffd6003Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
79185ffd6003Smrg	  else
79195ffd6003Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
79205ffd6003Smrg	  fi
79215ffd6003Smrg	  for searchdir in $searchdirs; do
79225ffd6003Smrg	    for search_ext in .la $std_shrext .so .a; do
79235ffd6003Smrg	      # Search the libtool library
7924b7d26471Smrg	      lib=$searchdir/lib$name$search_ext
79255ffd6003Smrg	      if test -f "$lib"; then
7926b7d26471Smrg		if test .la = "$search_ext"; then
7927b7d26471Smrg		  found=:
79285ffd6003Smrg		else
7929b7d26471Smrg		  found=false
79305ffd6003Smrg		fi
79315ffd6003Smrg		break 2
79325ffd6003Smrg	      fi
79335ffd6003Smrg	    done
79345ffd6003Smrg	  done
7935b7d26471Smrg	  if $found; then
7936b7d26471Smrg	    # deplib is a libtool library
79375ffd6003Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
79385ffd6003Smrg	    # We need to do some special things here, and not later.
7939b7d26471Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
79405ffd6003Smrg	      case " $predeps $postdeps " in
79415ffd6003Smrg	      *" $deplib "*)
79425ffd6003Smrg		if func_lalib_p "$lib"; then
79435ffd6003Smrg		  library_names=
79445ffd6003Smrg		  old_library=
79455ffd6003Smrg		  func_source "$lib"
79465ffd6003Smrg		  for l in $old_library $library_names; do
7947b7d26471Smrg		    ll=$l
79485ffd6003Smrg		  done
7949b7d26471Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950b7d26471Smrg		    found=false
79515ffd6003Smrg		    func_dirname "$lib" "" "."
7952b7d26471Smrg		    ladir=$func_dirname_result
79535ffd6003Smrg		    lib=$ladir/$old_library
7954b7d26471Smrg		    if test prog,link = "$linkmode,$pass"; then
79555ffd6003Smrg		      compile_deplibs="$deplib $compile_deplibs"
79565ffd6003Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
79575ffd6003Smrg		    else
79585ffd6003Smrg		      deplibs="$deplib $deplibs"
7959b7d26471Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
79605ffd6003Smrg		    fi
79615ffd6003Smrg		    continue
79625ffd6003Smrg		  fi
79635ffd6003Smrg		fi
79645ffd6003Smrg		;;
79655ffd6003Smrg	      *) ;;
79665ffd6003Smrg	      esac
79675ffd6003Smrg	    fi
7968b7d26471Smrg	  else
7969b7d26471Smrg	    # deplib doesn't seem to be a libtool library
7970b7d26471Smrg	    if test prog,link = "$linkmode,$pass"; then
7971b7d26471Smrg	      compile_deplibs="$deplib $compile_deplibs"
7972b7d26471Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973b7d26471Smrg	    else
7974b7d26471Smrg	      deplibs="$deplib $deplibs"
7975b7d26471Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976b7d26471Smrg	    fi
7977b7d26471Smrg	    continue
79785ffd6003Smrg	  fi
79795ffd6003Smrg	  ;; # -l
79805ffd6003Smrg	*.ltframework)
7981b7d26471Smrg	  if test prog,link = "$linkmode,$pass"; then
79825ffd6003Smrg	    compile_deplibs="$deplib $compile_deplibs"
79835ffd6003Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
79845ffd6003Smrg	  else
79855ffd6003Smrg	    deplibs="$deplib $deplibs"
7986b7d26471Smrg	    if test lib = "$linkmode"; then
79875ffd6003Smrg		case "$new_inherited_linker_flags " in
79885ffd6003Smrg		    *" $deplib "*) ;;
7989629baa8cSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
79905ffd6003Smrg		esac
79915ffd6003Smrg	    fi
79925ffd6003Smrg	  fi
79935ffd6003Smrg	  continue
79945ffd6003Smrg	  ;;
79955ffd6003Smrg	-L*)
79965ffd6003Smrg	  case $linkmode in
79975ffd6003Smrg	  lib)
79985ffd6003Smrg	    deplibs="$deplib $deplibs"
7999b7d26471Smrg	    test conv = "$pass" && continue
80005ffd6003Smrg	    newdependency_libs="$deplib $newdependency_libs"
80015ffd6003Smrg	    func_stripname '-L' '' "$deplib"
8002629baa8cSmrg	    func_resolve_sysroot "$func_stripname_result"
8003629baa8cSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80045ffd6003Smrg	    ;;
80055ffd6003Smrg	  prog)
8006b7d26471Smrg	    if test conv = "$pass"; then
80075ffd6003Smrg	      deplibs="$deplib $deplibs"
80085ffd6003Smrg	      continue
80095ffd6003Smrg	    fi
8010b7d26471Smrg	    if test scan = "$pass"; then
80115ffd6003Smrg	      deplibs="$deplib $deplibs"
80125ffd6003Smrg	    else
80135ffd6003Smrg	      compile_deplibs="$deplib $compile_deplibs"
80145ffd6003Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80155ffd6003Smrg	    fi
80165ffd6003Smrg	    func_stripname '-L' '' "$deplib"
8017629baa8cSmrg	    func_resolve_sysroot "$func_stripname_result"
8018629baa8cSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
80195ffd6003Smrg	    ;;
80205ffd6003Smrg	  *)
8021b7d26471Smrg	    func_warning "'-L' is ignored for archives/objects"
80225ffd6003Smrg	    ;;
80235ffd6003Smrg	  esac # linkmode
80245ffd6003Smrg	  continue
80255ffd6003Smrg	  ;; # -L
80265ffd6003Smrg	-R*)
8027b7d26471Smrg	  if test link = "$pass"; then
80285ffd6003Smrg	    func_stripname '-R' '' "$deplib"
8029629baa8cSmrg	    func_resolve_sysroot "$func_stripname_result"
8030629baa8cSmrg	    dir=$func_resolve_sysroot_result
80315ffd6003Smrg	    # Make sure the xrpath contains only unique directories.
80325ffd6003Smrg	    case "$xrpath " in
80335ffd6003Smrg	    *" $dir "*) ;;
8034629baa8cSmrg	    *) func_append xrpath " $dir" ;;
80355ffd6003Smrg	    esac
80365ffd6003Smrg	  fi
80375ffd6003Smrg	  deplibs="$deplib $deplibs"
80385ffd6003Smrg	  continue
80395ffd6003Smrg	  ;;
8040629baa8cSmrg	*.la)
8041629baa8cSmrg	  func_resolve_sysroot "$deplib"
8042629baa8cSmrg	  lib=$func_resolve_sysroot_result
8043629baa8cSmrg	  ;;
80445ffd6003Smrg	*.$libext)
8045b7d26471Smrg	  if test conv = "$pass"; then
80465ffd6003Smrg	    deplibs="$deplib $deplibs"
80475ffd6003Smrg	    continue
80485ffd6003Smrg	  fi
80495ffd6003Smrg	  case $linkmode in
80505ffd6003Smrg	  lib)
80515ffd6003Smrg	    # Linking convenience modules into shared libraries is allowed,
80525ffd6003Smrg	    # but linking other static libraries is non-portable.
80535ffd6003Smrg	    case " $dlpreconveniencelibs " in
80545ffd6003Smrg	    *" $deplib "*) ;;
80555ffd6003Smrg	    *)
8056b7d26471Smrg	      valid_a_lib=false
80575ffd6003Smrg	      case $deplibs_check_method in
80585ffd6003Smrg		match_pattern*)
80595ffd6003Smrg		  set dummy $deplibs_check_method; shift
80605ffd6003Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8061629baa8cSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
80625ffd6003Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063b7d26471Smrg		    valid_a_lib=:
80645ffd6003Smrg		  fi
80655ffd6003Smrg		;;
80665ffd6003Smrg		pass_all)
8067b7d26471Smrg		  valid_a_lib=:
80685ffd6003Smrg		;;
80695ffd6003Smrg	      esac
8070b7d26471Smrg	      if $valid_a_lib; then
8071b7d26471Smrg		echo
8072b7d26471Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073b7d26471Smrg		$ECHO "*** static library $deplib is not portable!"
8074b7d26471Smrg		deplibs="$deplib $deplibs"
8075b7d26471Smrg	      else
8076629baa8cSmrg		echo
80775ffd6003Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8078629baa8cSmrg		echo "*** I have the capability to make that library automatically link in when"
8079629baa8cSmrg		echo "*** you link to this library.  But I can only do this if you have a"
8080629baa8cSmrg		echo "*** shared version of the library, which you do not appear to have"
8081629baa8cSmrg		echo "*** because the file extensions .$libext of this argument makes me believe"
8082629baa8cSmrg		echo "*** that it is just a static archive that I should not use here."
80835ffd6003Smrg	      fi
80845ffd6003Smrg	      ;;
80855ffd6003Smrg	    esac
80865ffd6003Smrg	    continue
80875ffd6003Smrg	    ;;
80885ffd6003Smrg	  prog)
8089b7d26471Smrg	    if test link != "$pass"; then
80905ffd6003Smrg	      deplibs="$deplib $deplibs"
80915ffd6003Smrg	    else
80925ffd6003Smrg	      compile_deplibs="$deplib $compile_deplibs"
80935ffd6003Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
80945ffd6003Smrg	    fi
80955ffd6003Smrg	    continue
80965ffd6003Smrg	    ;;
80975ffd6003Smrg	  esac # linkmode
80985ffd6003Smrg	  ;; # *.$libext
80995ffd6003Smrg	*.lo | *.$objext)
8100b7d26471Smrg	  if test conv = "$pass"; then
81015ffd6003Smrg	    deplibs="$deplib $deplibs"
8102b7d26471Smrg	  elif test prog = "$linkmode"; then
8103b7d26471Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
81045ffd6003Smrg	      # If there is no dlopen support or we're linking statically,
81055ffd6003Smrg	      # we need to preload.
8106629baa8cSmrg	      func_append newdlprefiles " $deplib"
81075ffd6003Smrg	      compile_deplibs="$deplib $compile_deplibs"
81085ffd6003Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
81095ffd6003Smrg	    else
8110629baa8cSmrg	      func_append newdlfiles " $deplib"
81115ffd6003Smrg	    fi
81125ffd6003Smrg	  fi
81135ffd6003Smrg	  continue
81145ffd6003Smrg	  ;;
81155ffd6003Smrg	%DEPLIBS%)
8116b7d26471Smrg	  alldeplibs=:
81175ffd6003Smrg	  continue
81185ffd6003Smrg	  ;;
81195ffd6003Smrg	esac # case $deplib
81205ffd6003Smrg
8121b7d26471Smrg	$found || test -f "$lib" \
8122b7d26471Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
81235ffd6003Smrg
81245ffd6003Smrg	# Check to see that this really is a libtool archive.
81255ffd6003Smrg	func_lalib_unsafe_p "$lib" \
8126b7d26471Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
81275ffd6003Smrg
81285ffd6003Smrg	func_dirname "$lib" "" "."
8129b7d26471Smrg	ladir=$func_dirname_result
81305ffd6003Smrg
81315ffd6003Smrg	dlname=
81325ffd6003Smrg	dlopen=
81335ffd6003Smrg	dlpreopen=
81345ffd6003Smrg	libdir=
81355ffd6003Smrg	library_names=
81365ffd6003Smrg	old_library=
81375ffd6003Smrg	inherited_linker_flags=
81385ffd6003Smrg	# If the library was installed with an old release of libtool,
81395ffd6003Smrg	# it will not redefine variables installed, or shouldnotlink
81405ffd6003Smrg	installed=yes
81415ffd6003Smrg	shouldnotlink=no
81425ffd6003Smrg	avoidtemprpath=
81435ffd6003Smrg
81445ffd6003Smrg
81455ffd6003Smrg	# Read the .la file
81465ffd6003Smrg	func_source "$lib"
81475ffd6003Smrg
81485ffd6003Smrg	# Convert "-framework foo" to "foo.ltframework"
81495ffd6003Smrg	if test -n "$inherited_linker_flags"; then
8150629baa8cSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
81515ffd6003Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
81525ffd6003Smrg	    case " $new_inherited_linker_flags " in
81535ffd6003Smrg	      *" $tmp_inherited_linker_flag "*) ;;
8154629baa8cSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
81555ffd6003Smrg	    esac
81565ffd6003Smrg	  done
81575ffd6003Smrg	fi
8158629baa8cSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159b7d26471Smrg	if test lib,link = "$linkmode,$pass" ||
8160b7d26471Smrg	   test prog,scan = "$linkmode,$pass" ||
8161b7d26471Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8162629baa8cSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8163629baa8cSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
81645ffd6003Smrg	fi
81655ffd6003Smrg
8166b7d26471Smrg	if test conv = "$pass"; then
81675ffd6003Smrg	  # Only check for convenience libraries
81685ffd6003Smrg	  deplibs="$lib $deplibs"
81695ffd6003Smrg	  if test -z "$libdir"; then
81705ffd6003Smrg	    if test -z "$old_library"; then
8171b7d26471Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
81725ffd6003Smrg	    fi
81735ffd6003Smrg	    # It is a libtool convenience library, so add in its objects.
8174629baa8cSmrg	    func_append convenience " $ladir/$objdir/$old_library"
8175629baa8cSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176b7d26471Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177b7d26471Smrg	    func_fatal_error "'$lib' is not a convenience library"
81785ffd6003Smrg	  fi
8179629baa8cSmrg	  tmp_libs=
8180629baa8cSmrg	  for deplib in $dependency_libs; do
8181629baa8cSmrg	    deplibs="$deplib $deplibs"
8182b7d26471Smrg	    if $opt_preserve_dup_deps; then
8183629baa8cSmrg	      case "$tmp_libs " in
8184629baa8cSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185629baa8cSmrg	      esac
8186629baa8cSmrg	    fi
8187629baa8cSmrg	    func_append tmp_libs " $deplib"
8188629baa8cSmrg	  done
81895ffd6003Smrg	  continue
81905ffd6003Smrg	fi # $pass = conv
81915ffd6003Smrg
81925ffd6003Smrg
81935ffd6003Smrg	# Get the name of the library we link against.
81945ffd6003Smrg	linklib=
8195629baa8cSmrg	if test -n "$old_library" &&
8196b7d26471Smrg	   { test yes = "$prefer_static_libs" ||
8197b7d26471Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8198629baa8cSmrg	  linklib=$old_library
8199629baa8cSmrg	else
8200629baa8cSmrg	  for l in $old_library $library_names; do
8201b7d26471Smrg	    linklib=$l
8202629baa8cSmrg	  done
8203629baa8cSmrg	fi
82045ffd6003Smrg	if test -z "$linklib"; then
8205b7d26471Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
82065ffd6003Smrg	fi
82075ffd6003Smrg
82085ffd6003Smrg	# This library was specified with -dlopen.
8209b7d26471Smrg	if test dlopen = "$pass"; then
8210b7d26471Smrg	  test -z "$libdir" \
8211b7d26471Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
82125ffd6003Smrg	  if test -z "$dlname" ||
8213b7d26471Smrg	     test yes != "$dlopen_support" ||
8214b7d26471Smrg	     test no = "$build_libtool_libs"
8215b7d26471Smrg	  then
82165ffd6003Smrg	    # If there is no dlname, no dlopen support or we're linking
82175ffd6003Smrg	    # statically, we need to preload.  We also need to preload any
82185ffd6003Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
82195ffd6003Smrg	    # bomb out in the load deplibs phase.
8220629baa8cSmrg	    func_append dlprefiles " $lib $dependency_libs"
82215ffd6003Smrg	  else
8222629baa8cSmrg	    func_append newdlfiles " $lib"
82235ffd6003Smrg	  fi
82245ffd6003Smrg	  continue
82255ffd6003Smrg	fi # $pass = dlopen
82265ffd6003Smrg
82275ffd6003Smrg	# We need an absolute path.
82285ffd6003Smrg	case $ladir in
8229b7d26471Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
82305ffd6003Smrg	*)
82315ffd6003Smrg	  abs_ladir=`cd "$ladir" && pwd`
82325ffd6003Smrg	  if test -z "$abs_ladir"; then
8233b7d26471Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
82345ffd6003Smrg	    func_warning "passing it literally to the linker, although it might fail"
8235b7d26471Smrg	    abs_ladir=$ladir
82365ffd6003Smrg	  fi
82375ffd6003Smrg	  ;;
82385ffd6003Smrg	esac
82395ffd6003Smrg	func_basename "$lib"
8240b7d26471Smrg	laname=$func_basename_result
82415ffd6003Smrg
82425ffd6003Smrg	# Find the relevant object directory and library name.
8243b7d26471Smrg	if test yes = "$installed"; then
8244629baa8cSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245b7d26471Smrg	    func_warning "library '$lib' was moved."
8246b7d26471Smrg	    dir=$ladir
8247b7d26471Smrg	    absdir=$abs_ladir
8248b7d26471Smrg	    libdir=$abs_ladir
82495ffd6003Smrg	  else
8250b7d26471Smrg	    dir=$lt_sysroot$libdir
8251b7d26471Smrg	    absdir=$lt_sysroot$libdir
82525ffd6003Smrg	  fi
8253b7d26471Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
82545ffd6003Smrg	else
82555ffd6003Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256b7d26471Smrg	    dir=$ladir
8257b7d26471Smrg	    absdir=$abs_ladir
82585ffd6003Smrg	    # Remove this search path later
8259629baa8cSmrg	    func_append notinst_path " $abs_ladir"
82605ffd6003Smrg	  else
8261b7d26471Smrg	    dir=$ladir/$objdir
8262b7d26471Smrg	    absdir=$abs_ladir/$objdir
82635ffd6003Smrg	    # Remove this search path later
8264629baa8cSmrg	    func_append notinst_path " $abs_ladir"
82655ffd6003Smrg	  fi
82665ffd6003Smrg	fi # $installed = yes
82675ffd6003Smrg	func_stripname 'lib' '.la' "$laname"
82685ffd6003Smrg	name=$func_stripname_result
82695ffd6003Smrg
82705ffd6003Smrg	# This library was specified with -dlpreopen.
8271b7d26471Smrg	if test dlpreopen = "$pass"; then
8272b7d26471Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273b7d26471Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
82745ffd6003Smrg	  fi
8275b7d26471Smrg	  case $host in
8276629baa8cSmrg	    # special handling for platforms with PE-DLLs.
8277629baa8cSmrg	    *cygwin* | *mingw* | *cegcc* )
8278629baa8cSmrg	      # Linker will automatically link against shared library if both
8279629baa8cSmrg	      # static and shared are present.  Therefore, ensure we extract
8280629baa8cSmrg	      # symbols from the import library if a shared library is present
8281629baa8cSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8282629baa8cSmrg	      # this by putting the import library name into $newdlprefiles.
8283629baa8cSmrg	      # We recover the dlopen module name by 'saving' the la file
8284629baa8cSmrg	      # name in a special purpose variable, and (later) extracting the
8285629baa8cSmrg	      # dlname from the la file.
8286629baa8cSmrg	      if test -n "$dlname"; then
8287629baa8cSmrg	        func_tr_sh "$dir/$linklib"
8288629baa8cSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8289629baa8cSmrg	        func_append newdlprefiles " $dir/$linklib"
8290629baa8cSmrg	      else
8291629baa8cSmrg	        func_append newdlprefiles " $dir/$old_library"
8292629baa8cSmrg	        # Keep a list of preopened convenience libraries to check
8293629baa8cSmrg	        # that they are being used correctly in the link pass.
8294629baa8cSmrg	        test -z "$libdir" && \
8295629baa8cSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8296629baa8cSmrg	      fi
8297629baa8cSmrg	    ;;
8298629baa8cSmrg	    * )
8299629baa8cSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8300629baa8cSmrg	      # are required to link).
8301629baa8cSmrg	      if test -n "$old_library"; then
8302629baa8cSmrg	        func_append newdlprefiles " $dir/$old_library"
8303629baa8cSmrg	        # Keep a list of preopened convenience libraries to check
8304629baa8cSmrg	        # that they are being used correctly in the link pass.
8305629baa8cSmrg	        test -z "$libdir" && \
8306629baa8cSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8307629baa8cSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8308629baa8cSmrg	      elif test -n "$dlname"; then
8309629baa8cSmrg	        func_append newdlprefiles " $dir/$dlname"
8310629baa8cSmrg	      else
8311629baa8cSmrg	        func_append newdlprefiles " $dir/$linklib"
8312629baa8cSmrg	      fi
8313629baa8cSmrg	    ;;
8314629baa8cSmrg	  esac
83155ffd6003Smrg	fi # $pass = dlpreopen
83165ffd6003Smrg
83175ffd6003Smrg	if test -z "$libdir"; then
83185ffd6003Smrg	  # Link the convenience library
8319b7d26471Smrg	  if test lib = "$linkmode"; then
83205ffd6003Smrg	    deplibs="$dir/$old_library $deplibs"
8321b7d26471Smrg	  elif test prog,link = "$linkmode,$pass"; then
83225ffd6003Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
83235ffd6003Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
83245ffd6003Smrg	  else
83255ffd6003Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
83265ffd6003Smrg	  fi
83275ffd6003Smrg	  continue
83285ffd6003Smrg	fi
83295ffd6003Smrg
83305ffd6003Smrg
8331b7d26471Smrg	if test prog = "$linkmode" && test link != "$pass"; then
8332629baa8cSmrg	  func_append newlib_search_path " $ladir"
83335ffd6003Smrg	  deplibs="$lib $deplibs"
83345ffd6003Smrg
8335b7d26471Smrg	  linkalldeplibs=false
8336b7d26471Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337b7d26471Smrg	     test no = "$build_libtool_libs"; then
8338b7d26471Smrg	    linkalldeplibs=:
83395ffd6003Smrg	  fi
83405ffd6003Smrg
83415ffd6003Smrg	  tmp_libs=
83425ffd6003Smrg	  for deplib in $dependency_libs; do
83435ffd6003Smrg	    case $deplib in
83445ffd6003Smrg	    -L*) func_stripname '-L' '' "$deplib"
8345629baa8cSmrg	         func_resolve_sysroot "$func_stripname_result"
8346629baa8cSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
83475ffd6003Smrg		 ;;
83485ffd6003Smrg	    esac
83495ffd6003Smrg	    # Need to link against all dependency_libs?
8350b7d26471Smrg	    if $linkalldeplibs; then
83515ffd6003Smrg	      deplibs="$deplib $deplibs"
83525ffd6003Smrg	    else
83535ffd6003Smrg	      # Need to hardcode shared library paths
83545ffd6003Smrg	      # or/and link against static libraries
83555ffd6003Smrg	      newdependency_libs="$deplib $newdependency_libs"
83565ffd6003Smrg	    fi
8357b7d26471Smrg	    if $opt_preserve_dup_deps; then
83585ffd6003Smrg	      case "$tmp_libs " in
8359629baa8cSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
83605ffd6003Smrg	      esac
83615ffd6003Smrg	    fi
8362629baa8cSmrg	    func_append tmp_libs " $deplib"
83635ffd6003Smrg	  done # for deplib
83645ffd6003Smrg	  continue
83655ffd6003Smrg	fi # $linkmode = prog...
83665ffd6003Smrg
8367b7d26471Smrg	if test prog,link = "$linkmode,$pass"; then
83685ffd6003Smrg	  if test -n "$library_names" &&
8369b7d26471Smrg	     { { test no = "$prefer_static_libs" ||
8370b7d26471Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
83715ffd6003Smrg	       test -z "$old_library"; }; then
83725ffd6003Smrg	    # We need to hardcode the library path
8373b7d26471Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
83745ffd6003Smrg	      # Make sure the rpath contains only unique directories.
8375b7d26471Smrg	      case $temp_rpath: in
83765ffd6003Smrg	      *"$absdir:"*) ;;
8377629baa8cSmrg	      *) func_append temp_rpath "$absdir:" ;;
83785ffd6003Smrg	      esac
83795ffd6003Smrg	    fi
83805ffd6003Smrg
83815ffd6003Smrg	    # Hardcode the library path.
83825ffd6003Smrg	    # Skip directories that are in the system default run-time
83835ffd6003Smrg	    # search path.
83845ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
83855ffd6003Smrg	    *" $absdir "*) ;;
83865ffd6003Smrg	    *)
83875ffd6003Smrg	      case "$compile_rpath " in
83885ffd6003Smrg	      *" $absdir "*) ;;
8389629baa8cSmrg	      *) func_append compile_rpath " $absdir" ;;
83905ffd6003Smrg	      esac
83915ffd6003Smrg	      ;;
83925ffd6003Smrg	    esac
83935ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
83945ffd6003Smrg	    *" $libdir "*) ;;
83955ffd6003Smrg	    *)
83965ffd6003Smrg	      case "$finalize_rpath " in
83975ffd6003Smrg	      *" $libdir "*) ;;
8398629baa8cSmrg	      *) func_append finalize_rpath " $libdir" ;;
83995ffd6003Smrg	      esac
84005ffd6003Smrg	      ;;
84015ffd6003Smrg	    esac
84025ffd6003Smrg	  fi # $linkmode,$pass = prog,link...
84035ffd6003Smrg
8404b7d26471Smrg	  if $alldeplibs &&
8405b7d26471Smrg	     { test pass_all = "$deplibs_check_method" ||
8406b7d26471Smrg	       { test yes = "$build_libtool_libs" &&
84075ffd6003Smrg		 test -n "$library_names"; }; }; then
84085ffd6003Smrg	    # We only need to search for static libraries
84095ffd6003Smrg	    continue
84105ffd6003Smrg	  fi
84115ffd6003Smrg	fi
84125ffd6003Smrg
84135ffd6003Smrg	link_static=no # Whether the deplib will be linked statically
84145ffd6003Smrg	use_static_libs=$prefer_static_libs
8415b7d26471Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
84165ffd6003Smrg	  use_static_libs=no
84175ffd6003Smrg	fi
84185ffd6003Smrg	if test -n "$library_names" &&
8419b7d26471Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
84205ffd6003Smrg	  case $host in
8421b7d26471Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
84225ffd6003Smrg	      # No point in relinking DLLs because paths are not encoded
8423629baa8cSmrg	      func_append notinst_deplibs " $lib"
84245ffd6003Smrg	      need_relink=no
84255ffd6003Smrg	    ;;
84265ffd6003Smrg	  *)
8427b7d26471Smrg	    if test no = "$installed"; then
8428629baa8cSmrg	      func_append notinst_deplibs " $lib"
84295ffd6003Smrg	      need_relink=yes
84305ffd6003Smrg	    fi
84315ffd6003Smrg	    ;;
84325ffd6003Smrg	  esac
84335ffd6003Smrg	  # This is a shared library
84345ffd6003Smrg
84355ffd6003Smrg	  # Warn about portability, can't link against -module's on some
84365ffd6003Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437b7d26471Smrg	  dlopenmodule=
84385ffd6003Smrg	  for dlpremoduletest in $dlprefiles; do
84395ffd6003Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440b7d26471Smrg	      dlopenmodule=$dlpremoduletest
84415ffd6003Smrg	      break
84425ffd6003Smrg	    fi
84435ffd6003Smrg	  done
8444b7d26471Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8445629baa8cSmrg	    echo
8446b7d26471Smrg	    if test prog = "$linkmode"; then
84475ffd6003Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
84485ffd6003Smrg	    else
84495ffd6003Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
84505ffd6003Smrg	    fi
84515ffd6003Smrg	    $ECHO "*** $linklib is not portable!"
84525ffd6003Smrg	  fi
8453b7d26471Smrg	  if test lib = "$linkmode" &&
8454b7d26471Smrg	     test yes = "$hardcode_into_libs"; then
84555ffd6003Smrg	    # Hardcode the library path.
84565ffd6003Smrg	    # Skip directories that are in the system default run-time
84575ffd6003Smrg	    # search path.
84585ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
84595ffd6003Smrg	    *" $absdir "*) ;;
84605ffd6003Smrg	    *)
84615ffd6003Smrg	      case "$compile_rpath " in
84625ffd6003Smrg	      *" $absdir "*) ;;
8463629baa8cSmrg	      *) func_append compile_rpath " $absdir" ;;
84645ffd6003Smrg	      esac
84655ffd6003Smrg	      ;;
84665ffd6003Smrg	    esac
84675ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
84685ffd6003Smrg	    *" $libdir "*) ;;
84695ffd6003Smrg	    *)
84705ffd6003Smrg	      case "$finalize_rpath " in
84715ffd6003Smrg	      *" $libdir "*) ;;
8472629baa8cSmrg	      *) func_append finalize_rpath " $libdir" ;;
84735ffd6003Smrg	      esac
84745ffd6003Smrg	      ;;
84755ffd6003Smrg	    esac
84765ffd6003Smrg	  fi
84775ffd6003Smrg
84785ffd6003Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
84795ffd6003Smrg	    # figure out the soname
84805ffd6003Smrg	    set dummy $library_names
84815ffd6003Smrg	    shift
8482b7d26471Smrg	    realname=$1
84835ffd6003Smrg	    shift
84845ffd6003Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
84855ffd6003Smrg	    # use dlname if we got it. it's perfectly good, no?
84865ffd6003Smrg	    if test -n "$dlname"; then
8487b7d26471Smrg	      soname=$dlname
84885ffd6003Smrg	    elif test -n "$soname_spec"; then
84895ffd6003Smrg	      # bleh windows
84905ffd6003Smrg	      case $host in
8491b7d26471Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
84925ffd6003Smrg	        func_arith $current - $age
84935ffd6003Smrg		major=$func_arith_result
8494b7d26471Smrg		versuffix=-$major
84955ffd6003Smrg		;;
84965ffd6003Smrg	      esac
84975ffd6003Smrg	      eval soname=\"$soname_spec\"
84985ffd6003Smrg	    else
8499b7d26471Smrg	      soname=$realname
85005ffd6003Smrg	    fi
85015ffd6003Smrg
85025ffd6003Smrg	    # Make a new name for the extract_expsyms_cmds to use
8503b7d26471Smrg	    soroot=$soname
85045ffd6003Smrg	    func_basename "$soroot"
8505b7d26471Smrg	    soname=$func_basename_result
85065ffd6003Smrg	    func_stripname 'lib' '.dll' "$soname"
85075ffd6003Smrg	    newlib=libimp-$func_stripname_result.a
85085ffd6003Smrg
85095ffd6003Smrg	    # If the library has no export list, then create one now
85105ffd6003Smrg	    if test -f "$output_objdir/$soname-def"; then :
85115ffd6003Smrg	    else
8512b7d26471Smrg	      func_verbose "extracting exported symbol list from '$soname'"
85135ffd6003Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
85145ffd6003Smrg	    fi
85155ffd6003Smrg
85165ffd6003Smrg	    # Create $newlib
85175ffd6003Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8518b7d26471Smrg	      func_verbose "generating import library for '$soname'"
85195ffd6003Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
85205ffd6003Smrg	    fi
85215ffd6003Smrg	    # make sure the library variables are pointing to the new library
85225ffd6003Smrg	    dir=$output_objdir
85235ffd6003Smrg	    linklib=$newlib
85245ffd6003Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
85255ffd6003Smrg
8526b7d26471Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
85275ffd6003Smrg	    add_shlibpath=
85285ffd6003Smrg	    add_dir=
85295ffd6003Smrg	    add=
85305ffd6003Smrg	    lib_linked=yes
85315ffd6003Smrg	    case $hardcode_action in
85325ffd6003Smrg	    immediate | unsupported)
8533b7d26471Smrg	      if test no = "$hardcode_direct"; then
8534b7d26471Smrg		add=$dir/$linklib
85355ffd6003Smrg		case $host in
8536b7d26471Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537b7d26471Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
85385ffd6003Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539b7d26471Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
85405ffd6003Smrg		  *-*-darwin* )
8541b7d26471Smrg		    # if the lib is a (non-dlopened) module then we cannot
85425ffd6003Smrg		    # link against it, someone is ignoring the earlier warnings
85435ffd6003Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8544b7d26471Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
85455ffd6003Smrg		      if test "X$dlopenmodule" != "X$lib"; then
85465ffd6003Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547b7d26471Smrg			if test -z "$old_library"; then
8548629baa8cSmrg			  echo
8549629baa8cSmrg			  echo "*** And there doesn't seem to be a static archive available"
8550629baa8cSmrg			  echo "*** The link will probably fail, sorry"
85515ffd6003Smrg			else
8552b7d26471Smrg			  add=$dir/$old_library
85535ffd6003Smrg			fi
85545ffd6003Smrg		      elif test -n "$old_library"; then
8555b7d26471Smrg			add=$dir/$old_library
85565ffd6003Smrg		      fi
85575ffd6003Smrg		    fi
85585ffd6003Smrg		esac
8559b7d26471Smrg	      elif test no = "$hardcode_minus_L"; then
85605ffd6003Smrg		case $host in
8561b7d26471Smrg		*-*-sunos*) add_shlibpath=$dir ;;
85625ffd6003Smrg		esac
8563b7d26471Smrg		add_dir=-L$dir
8564b7d26471Smrg		add=-l$name
8565b7d26471Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8566b7d26471Smrg		add_shlibpath=$dir
8567b7d26471Smrg		add=-l$name
85685ffd6003Smrg	      else
85695ffd6003Smrg		lib_linked=no
85705ffd6003Smrg	      fi
85715ffd6003Smrg	      ;;
85725ffd6003Smrg	    relink)
8573b7d26471Smrg	      if test yes = "$hardcode_direct" &&
8574b7d26471Smrg	         test no = "$hardcode_direct_absolute"; then
8575b7d26471Smrg		add=$dir/$linklib
8576b7d26471Smrg	      elif test yes = "$hardcode_minus_L"; then
8577b7d26471Smrg		add_dir=-L$absdir
85785ffd6003Smrg		# Try looking first in the location we're being installed to.
85795ffd6003Smrg		if test -n "$inst_prefix_dir"; then
85805ffd6003Smrg		  case $libdir in
85815ffd6003Smrg		    [\\/]*)
8582629baa8cSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
85835ffd6003Smrg		      ;;
85845ffd6003Smrg		  esac
85855ffd6003Smrg		fi
8586b7d26471Smrg		add=-l$name
8587b7d26471Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588b7d26471Smrg		add_shlibpath=$dir
8589b7d26471Smrg		add=-l$name
85905ffd6003Smrg	      else
85915ffd6003Smrg		lib_linked=no
85925ffd6003Smrg	      fi
85935ffd6003Smrg	      ;;
85945ffd6003Smrg	    *) lib_linked=no ;;
85955ffd6003Smrg	    esac
85965ffd6003Smrg
8597b7d26471Smrg	    if test yes != "$lib_linked"; then
85985ffd6003Smrg	      func_fatal_configuration "unsupported hardcode properties"
85995ffd6003Smrg	    fi
86005ffd6003Smrg
86015ffd6003Smrg	    if test -n "$add_shlibpath"; then
86025ffd6003Smrg	      case :$compile_shlibpath: in
86035ffd6003Smrg	      *":$add_shlibpath:"*) ;;
8604629baa8cSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
86055ffd6003Smrg	      esac
86065ffd6003Smrg	    fi
8607b7d26471Smrg	    if test prog = "$linkmode"; then
86085ffd6003Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
86095ffd6003Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
86105ffd6003Smrg	    else
86115ffd6003Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86125ffd6003Smrg	      test -n "$add" && deplibs="$add $deplibs"
8613b7d26471Smrg	      if test yes != "$hardcode_direct" &&
8614b7d26471Smrg		 test yes != "$hardcode_minus_L" &&
8615b7d26471Smrg		 test yes = "$hardcode_shlibpath_var"; then
86165ffd6003Smrg		case :$finalize_shlibpath: in
86175ffd6003Smrg		*":$libdir:"*) ;;
8618629baa8cSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
86195ffd6003Smrg		esac
86205ffd6003Smrg	      fi
86215ffd6003Smrg	    fi
86225ffd6003Smrg	  fi
86235ffd6003Smrg
8624b7d26471Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
86255ffd6003Smrg	    add_shlibpath=
86265ffd6003Smrg	    add_dir=
86275ffd6003Smrg	    add=
86285ffd6003Smrg	    # Finalize command for both is simple: just hardcode it.
8629b7d26471Smrg	    if test yes = "$hardcode_direct" &&
8630b7d26471Smrg	       test no = "$hardcode_direct_absolute"; then
8631b7d26471Smrg	      add=$libdir/$linklib
8632b7d26471Smrg	    elif test yes = "$hardcode_minus_L"; then
8633b7d26471Smrg	      add_dir=-L$libdir
8634b7d26471Smrg	      add=-l$name
8635b7d26471Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
86365ffd6003Smrg	      case :$finalize_shlibpath: in
86375ffd6003Smrg	      *":$libdir:"*) ;;
8638629baa8cSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
86395ffd6003Smrg	      esac
8640b7d26471Smrg	      add=-l$name
8641b7d26471Smrg	    elif test yes = "$hardcode_automatic"; then
86425ffd6003Smrg	      if test -n "$inst_prefix_dir" &&
8643b7d26471Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644b7d26471Smrg		add=$inst_prefix_dir$libdir/$linklib
86455ffd6003Smrg	      else
8646b7d26471Smrg		add=$libdir/$linklib
86475ffd6003Smrg	      fi
86485ffd6003Smrg	    else
86495ffd6003Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650b7d26471Smrg	      add_dir=-L$libdir
86515ffd6003Smrg	      # Try looking first in the location we're being installed to.
86525ffd6003Smrg	      if test -n "$inst_prefix_dir"; then
86535ffd6003Smrg		case $libdir in
86545ffd6003Smrg		  [\\/]*)
8655629baa8cSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
86565ffd6003Smrg		    ;;
86575ffd6003Smrg		esac
86585ffd6003Smrg	      fi
8659b7d26471Smrg	      add=-l$name
86605ffd6003Smrg	    fi
86615ffd6003Smrg
8662b7d26471Smrg	    if test prog = "$linkmode"; then
86635ffd6003Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
86645ffd6003Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
86655ffd6003Smrg	    else
86665ffd6003Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
86675ffd6003Smrg	      test -n "$add" && deplibs="$add $deplibs"
86685ffd6003Smrg	    fi
86695ffd6003Smrg	  fi
8670b7d26471Smrg	elif test prog = "$linkmode"; then
86715ffd6003Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
86725ffd6003Smrg	  # is not unsupported.  This is valid on all known static and
86735ffd6003Smrg	  # shared platforms.
8674b7d26471Smrg	  if test unsupported != "$hardcode_direct"; then
8675b7d26471Smrg	    test -n "$old_library" && linklib=$old_library
86765ffd6003Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
86775ffd6003Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
86785ffd6003Smrg	  else
86795ffd6003Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
86805ffd6003Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
86815ffd6003Smrg	  fi
8682b7d26471Smrg	elif test yes = "$build_libtool_libs"; then
86835ffd6003Smrg	  # Not a shared library
8684b7d26471Smrg	  if test pass_all != "$deplibs_check_method"; then
86855ffd6003Smrg	    # We're trying link a shared library against a static one
86865ffd6003Smrg	    # but the system doesn't support it.
86875ffd6003Smrg
86885ffd6003Smrg	    # Just print a warning and add the library to dependency_libs so
86895ffd6003Smrg	    # that the program can be linked against the static library.
8690629baa8cSmrg	    echo
8691b7d26471Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8692629baa8cSmrg	    echo "*** I have the capability to make that library automatically link in when"
8693629baa8cSmrg	    echo "*** you link to this library.  But I can only do this if you have a"
8694629baa8cSmrg	    echo "*** shared version of the library, which you do not appear to have."
8695b7d26471Smrg	    if test yes = "$module"; then
8696629baa8cSmrg	      echo "*** But as you try to build a module library, libtool will still create "
8697629baa8cSmrg	      echo "*** a static module, that should work as long as the dlopening application"
8698629baa8cSmrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
86995ffd6003Smrg	      if test -z "$global_symbol_pipe"; then
8700629baa8cSmrg		echo
8701629baa8cSmrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702b7d26471Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8703629baa8cSmrg		echo "*** not find such a program.  So, this module is probably useless."
8704b7d26471Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
87055ffd6003Smrg	      fi
8706b7d26471Smrg	      if test no = "$build_old_libs"; then
87075ffd6003Smrg		build_libtool_libs=module
87085ffd6003Smrg		build_old_libs=yes
87095ffd6003Smrg	      else
87105ffd6003Smrg		build_libtool_libs=no
87115ffd6003Smrg	      fi
87125ffd6003Smrg	    fi
87135ffd6003Smrg	  else
87145ffd6003Smrg	    deplibs="$dir/$old_library $deplibs"
87155ffd6003Smrg	    link_static=yes
87165ffd6003Smrg	  fi
87175ffd6003Smrg	fi # link shared/static library?
87185ffd6003Smrg
8719b7d26471Smrg	if test lib = "$linkmode"; then
87205ffd6003Smrg	  if test -n "$dependency_libs" &&
8721b7d26471Smrg	     { test yes != "$hardcode_into_libs" ||
8722b7d26471Smrg	       test yes = "$build_old_libs" ||
8723b7d26471Smrg	       test yes = "$link_static"; }; then
87245ffd6003Smrg	    # Extract -R from dependency_libs
87255ffd6003Smrg	    temp_deplibs=
87265ffd6003Smrg	    for libdir in $dependency_libs; do
87275ffd6003Smrg	      case $libdir in
87285ffd6003Smrg	      -R*) func_stripname '-R' '' "$libdir"
87295ffd6003Smrg	           temp_xrpath=$func_stripname_result
87305ffd6003Smrg		   case " $xrpath " in
87315ffd6003Smrg		   *" $temp_xrpath "*) ;;
8732629baa8cSmrg		   *) func_append xrpath " $temp_xrpath";;
87335ffd6003Smrg		   esac;;
8734629baa8cSmrg	      *) func_append temp_deplibs " $libdir";;
87355ffd6003Smrg	      esac
87365ffd6003Smrg	    done
8737b7d26471Smrg	    dependency_libs=$temp_deplibs
87385ffd6003Smrg	  fi
87395ffd6003Smrg
8740629baa8cSmrg	  func_append newlib_search_path " $absdir"
87415ffd6003Smrg	  # Link against this library
8742b7d26471Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
87435ffd6003Smrg	  # ... and its dependency_libs
87445ffd6003Smrg	  tmp_libs=
87455ffd6003Smrg	  for deplib in $dependency_libs; do
87465ffd6003Smrg	    newdependency_libs="$deplib $newdependency_libs"
8747629baa8cSmrg	    case $deplib in
8748629baa8cSmrg              -L*) func_stripname '-L' '' "$deplib"
8749629baa8cSmrg                   func_resolve_sysroot "$func_stripname_result";;
8750629baa8cSmrg              *) func_resolve_sysroot "$deplib" ;;
8751629baa8cSmrg            esac
8752b7d26471Smrg	    if $opt_preserve_dup_deps; then
87535ffd6003Smrg	      case "$tmp_libs " in
8754629baa8cSmrg	      *" $func_resolve_sysroot_result "*)
8755629baa8cSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
87565ffd6003Smrg	      esac
87575ffd6003Smrg	    fi
8758629baa8cSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
87595ffd6003Smrg	  done
87605ffd6003Smrg
8761b7d26471Smrg	  if test no != "$link_all_deplibs"; then
87625ffd6003Smrg	    # Add the search paths of all dependency libraries
87635ffd6003Smrg	    for deplib in $dependency_libs; do
87645ffd6003Smrg	      path=
87655ffd6003Smrg	      case $deplib in
8766b7d26471Smrg	      -L*) path=$deplib ;;
87675ffd6003Smrg	      *.la)
8768629baa8cSmrg	        func_resolve_sysroot "$deplib"
8769629baa8cSmrg	        deplib=$func_resolve_sysroot_result
87705ffd6003Smrg	        func_dirname "$deplib" "" "."
8771629baa8cSmrg		dir=$func_dirname_result
87725ffd6003Smrg		# We need an absolute path.
87735ffd6003Smrg		case $dir in
8774b7d26471Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
87755ffd6003Smrg		*)
87765ffd6003Smrg		  absdir=`cd "$dir" && pwd`
87775ffd6003Smrg		  if test -z "$absdir"; then
8778b7d26471Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779b7d26471Smrg		    absdir=$dir
87805ffd6003Smrg		  fi
87815ffd6003Smrg		  ;;
87825ffd6003Smrg		esac
87835ffd6003Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
87845ffd6003Smrg		case $host in
87855ffd6003Smrg		*-*-darwin*)
87865ffd6003Smrg		  depdepl=
8787b7d26471Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788b7d26471Smrg		  if test -n "$deplibrary_names"; then
8789b7d26471Smrg		    for tmp in $deplibrary_names; do
87905ffd6003Smrg		      depdepl=$tmp
87915ffd6003Smrg		    done
8792b7d26471Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793b7d26471Smrg		      depdepl=$absdir/$objdir/$depdepl
8794b7d26471Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
87955ffd6003Smrg                      if test -z "$darwin_install_name"; then
8796b7d26471Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
87975ffd6003Smrg                      fi
8798b7d26471Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799b7d26471Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
88005ffd6003Smrg		      path=
88015ffd6003Smrg		    fi
88025ffd6003Smrg		  fi
88035ffd6003Smrg		  ;;
88045ffd6003Smrg		*)
8805b7d26471Smrg		  path=-L$absdir/$objdir
88065ffd6003Smrg		  ;;
88075ffd6003Smrg		esac
88085ffd6003Smrg		else
8809b7d26471Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
88105ffd6003Smrg		  test -z "$libdir" && \
8811b7d26471Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
88125ffd6003Smrg		  test "$absdir" != "$libdir" && \
8813b7d26471Smrg		    func_warning "'$deplib' seems to be moved"
88145ffd6003Smrg
8815b7d26471Smrg		  path=-L$absdir
88165ffd6003Smrg		fi
88175ffd6003Smrg		;;
88185ffd6003Smrg	      esac
88195ffd6003Smrg	      case " $deplibs " in
88205ffd6003Smrg	      *" $path "*) ;;
88215ffd6003Smrg	      *) deplibs="$path $deplibs" ;;
88225ffd6003Smrg	      esac
88235ffd6003Smrg	    done
88245ffd6003Smrg	  fi # link_all_deplibs != no
88255ffd6003Smrg	fi # linkmode = lib
88265ffd6003Smrg      done # for deplib in $libs
8827b7d26471Smrg      if test link = "$pass"; then
8828b7d26471Smrg	if test prog = "$linkmode"; then
88295ffd6003Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
88305ffd6003Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
88315ffd6003Smrg	else
8832629baa8cSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
88335ffd6003Smrg	fi
88345ffd6003Smrg      fi
8835b7d26471Smrg      dependency_libs=$newdependency_libs
8836b7d26471Smrg      if test dlpreopen = "$pass"; then
88375ffd6003Smrg	# Link the dlpreopened libraries before other libraries
88385ffd6003Smrg	for deplib in $save_deplibs; do
88395ffd6003Smrg	  deplibs="$deplib $deplibs"
88405ffd6003Smrg	done
88415ffd6003Smrg      fi
8842b7d26471Smrg      if test dlopen != "$pass"; then
8843b7d26471Smrg	test conv = "$pass" || {
88445ffd6003Smrg	  # Make sure lib_search_path contains only unique directories.
88455ffd6003Smrg	  lib_search_path=
88465ffd6003Smrg	  for dir in $newlib_search_path; do
88475ffd6003Smrg	    case "$lib_search_path " in
88485ffd6003Smrg	    *" $dir "*) ;;
8849629baa8cSmrg	    *) func_append lib_search_path " $dir" ;;
88505ffd6003Smrg	    esac
88515ffd6003Smrg	  done
88525ffd6003Smrg	  newlib_search_path=
8853b7d26471Smrg	}
88545ffd6003Smrg
8855b7d26471Smrg	if test prog,link = "$linkmode,$pass"; then
88565ffd6003Smrg	  vars="compile_deplibs finalize_deplibs"
8857b7d26471Smrg	else
8858b7d26471Smrg	  vars=deplibs
88595ffd6003Smrg	fi
88605ffd6003Smrg	for var in $vars dependency_libs; do
88615ffd6003Smrg	  # Add libraries to $var in reverse order
88625ffd6003Smrg	  eval tmp_libs=\"\$$var\"
88635ffd6003Smrg	  new_libs=
88645ffd6003Smrg	  for deplib in $tmp_libs; do
88655ffd6003Smrg	    # FIXME: Pedantically, this is the right thing to do, so
88665ffd6003Smrg	    #        that some nasty dependency loop isn't accidentally
88675ffd6003Smrg	    #        broken:
88685ffd6003Smrg	    #new_libs="$deplib $new_libs"
88695ffd6003Smrg	    # Pragmatically, this seems to cause very few problems in
88705ffd6003Smrg	    # practice:
88715ffd6003Smrg	    case $deplib in
88725ffd6003Smrg	    -L*) new_libs="$deplib $new_libs" ;;
88735ffd6003Smrg	    -R*) ;;
88745ffd6003Smrg	    *)
88755ffd6003Smrg	      # And here is the reason: when a library appears more
88765ffd6003Smrg	      # than once as an explicit dependence of a library, or
88775ffd6003Smrg	      # is implicitly linked in more than once by the
88785ffd6003Smrg	      # compiler, it is considered special, and multiple
88795ffd6003Smrg	      # occurrences thereof are not removed.  Compare this
88805ffd6003Smrg	      # with having the same library being listed as a
88815ffd6003Smrg	      # dependency of multiple other libraries: in this case,
88825ffd6003Smrg	      # we know (pedantically, we assume) the library does not
88835ffd6003Smrg	      # need to be listed more than once, so we keep only the
88845ffd6003Smrg	      # last copy.  This is not always right, but it is rare
88855ffd6003Smrg	      # enough that we require users that really mean to play
88865ffd6003Smrg	      # such unportable linking tricks to link the library
88875ffd6003Smrg	      # using -Wl,-lname, so that libtool does not consider it
88885ffd6003Smrg	      # for duplicate removal.
88895ffd6003Smrg	      case " $specialdeplibs " in
88905ffd6003Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
88915ffd6003Smrg	      *)
88925ffd6003Smrg		case " $new_libs " in
88935ffd6003Smrg		*" $deplib "*) ;;
88945ffd6003Smrg		*) new_libs="$deplib $new_libs" ;;
88955ffd6003Smrg		esac
88965ffd6003Smrg		;;
88975ffd6003Smrg	      esac
88985ffd6003Smrg	      ;;
88995ffd6003Smrg	    esac
89005ffd6003Smrg	  done
89015ffd6003Smrg	  tmp_libs=
89025ffd6003Smrg	  for deplib in $new_libs; do
89035ffd6003Smrg	    case $deplib in
89045ffd6003Smrg	    -L*)
89055ffd6003Smrg	      case " $tmp_libs " in
89065ffd6003Smrg	      *" $deplib "*) ;;
8907629baa8cSmrg	      *) func_append tmp_libs " $deplib" ;;
89085ffd6003Smrg	      esac
89095ffd6003Smrg	      ;;
8910629baa8cSmrg	    *) func_append tmp_libs " $deplib" ;;
89115ffd6003Smrg	    esac
89125ffd6003Smrg	  done
89135ffd6003Smrg	  eval $var=\"$tmp_libs\"
89145ffd6003Smrg	done # for var
89155ffd6003Smrg      fi
8916b7d26471Smrg
8917b7d26471Smrg      # Add Sun CC postdeps if required:
8918b7d26471Smrg      test CXX = "$tagname" && {
8919b7d26471Smrg        case $host_os in
8920b7d26471Smrg        linux*)
8921da2e2ef6Smrg          case `$CC -V 2>&1 | $SED 5q` in
8922b7d26471Smrg          *Sun\ C*) # Sun C++ 5.9
8923b7d26471Smrg            func_suncc_cstd_abi
8924b7d26471Smrg
8925b7d26471Smrg            if test no != "$suncc_use_cstd_abi"; then
8926b7d26471Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8927b7d26471Smrg            fi
8928b7d26471Smrg            ;;
8929b7d26471Smrg          esac
8930b7d26471Smrg          ;;
8931b7d26471Smrg
8932b7d26471Smrg        solaris*)
8933b7d26471Smrg          func_cc_basename "$CC"
8934b7d26471Smrg          case $func_cc_basename_result in
8935b7d26471Smrg          CC* | sunCC*)
8936b7d26471Smrg            func_suncc_cstd_abi
8937b7d26471Smrg
8938b7d26471Smrg            if test no != "$suncc_use_cstd_abi"; then
8939b7d26471Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8940b7d26471Smrg            fi
8941b7d26471Smrg            ;;
8942b7d26471Smrg          esac
8943b7d26471Smrg          ;;
8944b7d26471Smrg        esac
8945b7d26471Smrg      }
8946b7d26471Smrg
89475ffd6003Smrg      # Last step: remove runtime libs from dependency_libs
89485ffd6003Smrg      # (they stay in deplibs)
89495ffd6003Smrg      tmp_libs=
8950b7d26471Smrg      for i in $dependency_libs; do
89515ffd6003Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
89525ffd6003Smrg	*" $i "*)
8953b7d26471Smrg	  i=
89545ffd6003Smrg	  ;;
89555ffd6003Smrg	esac
8956b7d26471Smrg	if test -n "$i"; then
8957629baa8cSmrg	  func_append tmp_libs " $i"
89585ffd6003Smrg	fi
89595ffd6003Smrg      done
89605ffd6003Smrg      dependency_libs=$tmp_libs
89615ffd6003Smrg    done # for pass
8962b7d26471Smrg    if test prog = "$linkmode"; then
8963b7d26471Smrg      dlfiles=$newdlfiles
89645ffd6003Smrg    fi
8965b7d26471Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966b7d26471Smrg      dlprefiles=$newdlprefiles
89675ffd6003Smrg    fi
89685ffd6003Smrg
89695ffd6003Smrg    case $linkmode in
89705ffd6003Smrg    oldlib)
8971b7d26471Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972b7d26471Smrg	func_warning "'-dlopen' is ignored for archives"
89735ffd6003Smrg      fi
89745ffd6003Smrg
89755ffd6003Smrg      case " $deplibs" in
89765ffd6003Smrg      *\ -l* | *\ -L*)
8977b7d26471Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
89785ffd6003Smrg      esac
89795ffd6003Smrg
89805ffd6003Smrg      test -n "$rpath" && \
8981b7d26471Smrg	func_warning "'-rpath' is ignored for archives"
89825ffd6003Smrg
89835ffd6003Smrg      test -n "$xrpath" && \
8984b7d26471Smrg	func_warning "'-R' is ignored for archives"
89855ffd6003Smrg
89865ffd6003Smrg      test -n "$vinfo" && \
8987b7d26471Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
89885ffd6003Smrg
89895ffd6003Smrg      test -n "$release" && \
8990b7d26471Smrg	func_warning "'-release' is ignored for archives"
89915ffd6003Smrg
89925ffd6003Smrg      test -n "$export_symbols$export_symbols_regex" && \
8993b7d26471Smrg	func_warning "'-export-symbols' is ignored for archives"
89945ffd6003Smrg
89955ffd6003Smrg      # Now set the variables for building old libraries.
89965ffd6003Smrg      build_libtool_libs=no
8997b7d26471Smrg      oldlibs=$output
8998629baa8cSmrg      func_append objs "$old_deplibs"
89995ffd6003Smrg      ;;
90005ffd6003Smrg
90015ffd6003Smrg    lib)
9002b7d26471Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
90035ffd6003Smrg      case $outputname in
90045ffd6003Smrg      lib*)
90055ffd6003Smrg	func_stripname 'lib' '.la' "$outputname"
90065ffd6003Smrg	name=$func_stripname_result
90075ffd6003Smrg	eval shared_ext=\"$shrext_cmds\"
90085ffd6003Smrg	eval libname=\"$libname_spec\"
90095ffd6003Smrg	;;
90105ffd6003Smrg      *)
9011b7d26471Smrg	test no = "$module" \
9012b7d26471Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
90135ffd6003Smrg
9014b7d26471Smrg	if test no != "$need_lib_prefix"; then
90155ffd6003Smrg	  # Add the "lib" prefix for modules if required
90165ffd6003Smrg	  func_stripname '' '.la' "$outputname"
90175ffd6003Smrg	  name=$func_stripname_result
90185ffd6003Smrg	  eval shared_ext=\"$shrext_cmds\"
90195ffd6003Smrg	  eval libname=\"$libname_spec\"
90205ffd6003Smrg	else
90215ffd6003Smrg	  func_stripname '' '.la' "$outputname"
90225ffd6003Smrg	  libname=$func_stripname_result
90235ffd6003Smrg	fi
90245ffd6003Smrg	;;
90255ffd6003Smrg      esac
90265ffd6003Smrg
90275ffd6003Smrg      if test -n "$objs"; then
9028b7d26471Smrg	if test pass_all != "$deplibs_check_method"; then
9029b7d26471Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
90305ffd6003Smrg	else
9031629baa8cSmrg	  echo
90325ffd6003Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
90335ffd6003Smrg	  $ECHO "*** objects $objs is not portable!"
9034629baa8cSmrg	  func_append libobjs " $objs"
90355ffd6003Smrg	fi
90365ffd6003Smrg      fi
90375ffd6003Smrg
9038b7d26471Smrg      test no = "$dlself" \
9039b7d26471Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
90405ffd6003Smrg
90415ffd6003Smrg      set dummy $rpath
90425ffd6003Smrg      shift
9043b7d26471Smrg      test 1 -lt "$#" \
9044b7d26471Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
90455ffd6003Smrg
9046b7d26471Smrg      install_libdir=$1
90475ffd6003Smrg
90485ffd6003Smrg      oldlibs=
90495ffd6003Smrg      if test -z "$rpath"; then
9050b7d26471Smrg	if test yes = "$build_libtool_libs"; then
90515ffd6003Smrg	  # Building a libtool convenience library.
9052b7d26471Smrg	  # Some compilers have problems with a '.al' extension so
90535ffd6003Smrg	  # convenience libraries should have the same extension an
90545ffd6003Smrg	  # archive normally would.
90555ffd6003Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
90565ffd6003Smrg	  build_libtool_libs=convenience
90575ffd6003Smrg	  build_old_libs=yes
90585ffd6003Smrg	fi
90595ffd6003Smrg
90605ffd6003Smrg	test -n "$vinfo" && \
9061b7d26471Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
90625ffd6003Smrg
90635ffd6003Smrg	test -n "$release" && \
9064b7d26471Smrg	  func_warning "'-release' is ignored for convenience libraries"
90655ffd6003Smrg      else
90665ffd6003Smrg
90675ffd6003Smrg	# Parse the version information argument.
9068b7d26471Smrg	save_ifs=$IFS; IFS=:
90695ffd6003Smrg	set dummy $vinfo 0 0 0
90705ffd6003Smrg	shift
9071b7d26471Smrg	IFS=$save_ifs
90725ffd6003Smrg
90735ffd6003Smrg	test -n "$7" && \
9074b7d26471Smrg	  func_fatal_help "too many parameters to '-version-info'"
90755ffd6003Smrg
90765ffd6003Smrg	# convert absolute version numbers to libtool ages
90775ffd6003Smrg	# this retains compatibility with .la files and attempts
90785ffd6003Smrg	# to make the code below a bit more comprehensible
90795ffd6003Smrg
90805ffd6003Smrg	case $vinfo_number in
90815ffd6003Smrg	yes)
9082b7d26471Smrg	  number_major=$1
9083b7d26471Smrg	  number_minor=$2
9084b7d26471Smrg	  number_revision=$3
90855ffd6003Smrg	  #
90865ffd6003Smrg	  # There are really only two kinds -- those that
90875ffd6003Smrg	  # use the current revision as the major version
90885ffd6003Smrg	  # and those that subtract age and use age as
90895ffd6003Smrg	  # a minor version.  But, then there is irix
9090b7d26471Smrg	  # that has an extra 1 added just for fun
90915ffd6003Smrg	  #
90925ffd6003Smrg	  case $version_type in
9093b7d26471Smrg	  # correct linux to gnu/linux during the next big refactor
9094da2e2ef6Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
90955ffd6003Smrg	    func_arith $number_major + $number_minor
90965ffd6003Smrg	    current=$func_arith_result
9097b7d26471Smrg	    age=$number_minor
9098b7d26471Smrg	    revision=$number_revision
90995ffd6003Smrg	    ;;
9100b7d26471Smrg	  freebsd-aout|qnx|sunos)
9101b7d26471Smrg	    current=$number_major
9102b7d26471Smrg	    revision=$number_minor
9103b7d26471Smrg	    age=0
91045ffd6003Smrg	    ;;
91055ffd6003Smrg	  irix|nonstopux)
91065ffd6003Smrg	    func_arith $number_major + $number_minor
91075ffd6003Smrg	    current=$func_arith_result
9108b7d26471Smrg	    age=$number_minor
9109b7d26471Smrg	    revision=$number_minor
91105ffd6003Smrg	    lt_irix_increment=no
91115ffd6003Smrg	    ;;
91125ffd6003Smrg	  esac
91135ffd6003Smrg	  ;;
91145ffd6003Smrg	no)
9115b7d26471Smrg	  current=$1
9116b7d26471Smrg	  revision=$2
9117b7d26471Smrg	  age=$3
91185ffd6003Smrg	  ;;
91195ffd6003Smrg	esac
91205ffd6003Smrg
91215ffd6003Smrg	# Check that each of the things are valid numbers.
91225ffd6003Smrg	case $current in
91235ffd6003Smrg	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]) ;;
91245ffd6003Smrg	*)
9125b7d26471Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91275ffd6003Smrg	  ;;
91285ffd6003Smrg	esac
91295ffd6003Smrg
91305ffd6003Smrg	case $revision in
91315ffd6003Smrg	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]) ;;
91325ffd6003Smrg	*)
9133b7d26471Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91355ffd6003Smrg	  ;;
91365ffd6003Smrg	esac
91375ffd6003Smrg
91385ffd6003Smrg	case $age in
91395ffd6003Smrg	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]) ;;
91405ffd6003Smrg	*)
9141b7d26471Smrg	  func_error "AGE '$age' must be a nonnegative integer"
9142b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91435ffd6003Smrg	  ;;
91445ffd6003Smrg	esac
91455ffd6003Smrg
91465ffd6003Smrg	if test "$age" -gt "$current"; then
9147b7d26471Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
91495ffd6003Smrg	fi
91505ffd6003Smrg
91515ffd6003Smrg	# Calculate the version variables.
91525ffd6003Smrg	major=
91535ffd6003Smrg	versuffix=
91545ffd6003Smrg	verstring=
91555ffd6003Smrg	case $version_type in
91565ffd6003Smrg	none) ;;
91575ffd6003Smrg
91585ffd6003Smrg	darwin)
91595ffd6003Smrg	  # Like Linux, but with the current version available in
91605ffd6003Smrg	  # verstring for coding it into the library header
91615ffd6003Smrg	  func_arith $current - $age
91625ffd6003Smrg	  major=.$func_arith_result
9163b7d26471Smrg	  versuffix=$major.$age.$revision
91645ffd6003Smrg	  # Darwin ld doesn't like 0 for these options...
91655ffd6003Smrg	  func_arith $current + 1
91665ffd6003Smrg	  minor_current=$func_arith_result
9167b7d26471Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
91685ffd6003Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169b7d26471Smrg          # On Darwin other compilers
9170b7d26471Smrg          case $CC in
9171b7d26471Smrg              nagfor*)
9172b7d26471Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173b7d26471Smrg                  ;;
9174b7d26471Smrg              *)
9175b7d26471Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176b7d26471Smrg                  ;;
9177b7d26471Smrg          esac
91785ffd6003Smrg	  ;;
91795ffd6003Smrg
91805ffd6003Smrg	freebsd-aout)
9181b7d26471Smrg	  major=.$current
9182b7d26471Smrg	  versuffix=.$current.$revision
91835ffd6003Smrg	  ;;
91845ffd6003Smrg
9185da2e2ef6Smrg	freebsd-elf | midnightbsd-elf)
9186b7d26471Smrg	  func_arith $current - $age
9187b7d26471Smrg	  major=.$func_arith_result
9188b7d26471Smrg	  versuffix=$major.$age.$revision
91895ffd6003Smrg	  ;;
91905ffd6003Smrg
91915ffd6003Smrg	irix | nonstopux)
9192b7d26471Smrg	  if test no = "$lt_irix_increment"; then
91935ffd6003Smrg	    func_arith $current - $age
91945ffd6003Smrg	  else
91955ffd6003Smrg	    func_arith $current - $age + 1
91965ffd6003Smrg	  fi
91975ffd6003Smrg	  major=$func_arith_result
91985ffd6003Smrg
91995ffd6003Smrg	  case $version_type in
92005ffd6003Smrg	    nonstopux) verstring_prefix=nonstopux ;;
92015ffd6003Smrg	    *)         verstring_prefix=sgi ;;
92025ffd6003Smrg	  esac
9203b7d26471Smrg	  verstring=$verstring_prefix$major.$revision
92045ffd6003Smrg
92055ffd6003Smrg	  # Add in all the interfaces that we are compatible with.
92065ffd6003Smrg	  loop=$revision
9207b7d26471Smrg	  while test 0 -ne "$loop"; do
92085ffd6003Smrg	    func_arith $revision - $loop
92095ffd6003Smrg	    iface=$func_arith_result
92105ffd6003Smrg	    func_arith $loop - 1
92115ffd6003Smrg	    loop=$func_arith_result
9212b7d26471Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
92135ffd6003Smrg	  done
92145ffd6003Smrg
9215b7d26471Smrg	  # Before this point, $major must not contain '.'.
92165ffd6003Smrg	  major=.$major
9217b7d26471Smrg	  versuffix=$major.$revision
92185ffd6003Smrg	  ;;
92195ffd6003Smrg
9220b7d26471Smrg	linux) # correct to gnu/linux during the next big refactor
92215ffd6003Smrg	  func_arith $current - $age
92225ffd6003Smrg	  major=.$func_arith_result
9223b7d26471Smrg	  versuffix=$major.$age.$revision
92245ffd6003Smrg	  ;;
92255ffd6003Smrg
92265ffd6003Smrg	osf)
92275ffd6003Smrg	  func_arith $current - $age
92285ffd6003Smrg	  major=.$func_arith_result
9229b7d26471Smrg	  versuffix=.$current.$age.$revision
9230b7d26471Smrg	  verstring=$current.$age.$revision
92315ffd6003Smrg
92325ffd6003Smrg	  # Add in all the interfaces that we are compatible with.
92335ffd6003Smrg	  loop=$age
9234b7d26471Smrg	  while test 0 -ne "$loop"; do
92355ffd6003Smrg	    func_arith $current - $loop
92365ffd6003Smrg	    iface=$func_arith_result
92375ffd6003Smrg	    func_arith $loop - 1
92385ffd6003Smrg	    loop=$func_arith_result
9239b7d26471Smrg	    verstring=$verstring:$iface.0
92405ffd6003Smrg	  done
92415ffd6003Smrg
92425ffd6003Smrg	  # Make executables depend on our current version.
9243b7d26471Smrg	  func_append verstring ":$current.0"
92445ffd6003Smrg	  ;;
92455ffd6003Smrg
92465ffd6003Smrg	qnx)
9247b7d26471Smrg	  major=.$current
9248b7d26471Smrg	  versuffix=.$current
9249b7d26471Smrg	  ;;
9250b7d26471Smrg
9251b7d26471Smrg	sco)
9252b7d26471Smrg	  major=.$current
9253b7d26471Smrg	  versuffix=.$current
92545ffd6003Smrg	  ;;
92555ffd6003Smrg
92565ffd6003Smrg	sunos)
9257b7d26471Smrg	  major=.$current
9258b7d26471Smrg	  versuffix=.$current.$revision
92595ffd6003Smrg	  ;;
92605ffd6003Smrg
92615ffd6003Smrg	windows)
92625ffd6003Smrg	  # Use '-' rather than '.', since we only want one
9263b7d26471Smrg	  # extension on DOS 8.3 file systems.
92645ffd6003Smrg	  func_arith $current - $age
92655ffd6003Smrg	  major=$func_arith_result
9266b7d26471Smrg	  versuffix=-$major
92675ffd6003Smrg	  ;;
92685ffd6003Smrg
92695ffd6003Smrg	*)
9270b7d26471Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
92715ffd6003Smrg	  ;;
92725ffd6003Smrg	esac
92735ffd6003Smrg
92745ffd6003Smrg	# Clear the version info if we defaulted, and they specified a release.
92755ffd6003Smrg	if test -z "$vinfo" && test -n "$release"; then
92765ffd6003Smrg	  major=
92775ffd6003Smrg	  case $version_type in
92785ffd6003Smrg	  darwin)
92795ffd6003Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
92805ffd6003Smrg	    # problems, so we reset it completely
92815ffd6003Smrg	    verstring=
92825ffd6003Smrg	    ;;
92835ffd6003Smrg	  *)
9284b7d26471Smrg	    verstring=0.0
92855ffd6003Smrg	    ;;
92865ffd6003Smrg	  esac
9287b7d26471Smrg	  if test no = "$need_version"; then
92885ffd6003Smrg	    versuffix=
92895ffd6003Smrg	  else
9290b7d26471Smrg	    versuffix=.0.0
92915ffd6003Smrg	  fi
92925ffd6003Smrg	fi
92935ffd6003Smrg
92945ffd6003Smrg	# Remove version info from name if versioning should be avoided
9295b7d26471Smrg	if test yes,no = "$avoid_version,$need_version"; then
92965ffd6003Smrg	  major=
92975ffd6003Smrg	  versuffix=
9298b7d26471Smrg	  verstring=
92995ffd6003Smrg	fi
93005ffd6003Smrg
93015ffd6003Smrg	# Check to see if the archive will have undefined symbols.
9302b7d26471Smrg	if test yes = "$allow_undefined"; then
9303b7d26471Smrg	  if test unsupported = "$allow_undefined_flag"; then
9304b7d26471Smrg	    if test yes = "$build_old_libs"; then
9305b7d26471Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306b7d26471Smrg	      build_libtool_libs=no
9307b7d26471Smrg	    else
9308b7d26471Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309b7d26471Smrg	    fi
93105ffd6003Smrg	  fi
93115ffd6003Smrg	else
93125ffd6003Smrg	  # Don't allow undefined symbols.
9313b7d26471Smrg	  allow_undefined_flag=$no_undefined_flag
93145ffd6003Smrg	fi
93155ffd6003Smrg
93165ffd6003Smrg      fi
93175ffd6003Smrg
9318b7d26471Smrg      func_generate_dlsyms "$libname" "$libname" :
9319629baa8cSmrg      func_append libobjs " $symfileobj"
9320b7d26471Smrg      test " " = "$libobjs" && libobjs=
93215ffd6003Smrg
9322b7d26471Smrg      if test relink != "$opt_mode"; then
93235ffd6003Smrg	# Remove our outputs, but don't remove object files since they
93245ffd6003Smrg	# may have been created when compiling PIC objects.
93255ffd6003Smrg	removelist=
93265ffd6003Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
93275ffd6003Smrg	for p in $tempremovelist; do
93285ffd6003Smrg	  case $p in
93295ffd6003Smrg	    *.$objext | *.gcno)
93305ffd6003Smrg	       ;;
9331b7d26471Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332b7d26471Smrg	       if test -n "$precious_files_regex"; then
93335ffd6003Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
93345ffd6003Smrg		 then
93355ffd6003Smrg		   continue
93365ffd6003Smrg		 fi
93375ffd6003Smrg	       fi
9338629baa8cSmrg	       func_append removelist " $p"
93395ffd6003Smrg	       ;;
93405ffd6003Smrg	    *) ;;
93415ffd6003Smrg	  esac
93425ffd6003Smrg	done
93435ffd6003Smrg	test -n "$removelist" && \
93445ffd6003Smrg	  func_show_eval "${RM}r \$removelist"
93455ffd6003Smrg      fi
93465ffd6003Smrg
93475ffd6003Smrg      # Now set the variables for building old libraries.
9348b7d26471Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9349629baa8cSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
93505ffd6003Smrg
93515ffd6003Smrg	# Transform .lo files to .o files.
9352b7d26471Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
93535ffd6003Smrg      fi
93545ffd6003Smrg
93555ffd6003Smrg      # Eliminate all temporary directories.
93565ffd6003Smrg      #for path in $notinst_path; do
9357629baa8cSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9358629baa8cSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9359629baa8cSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
93605ffd6003Smrg      #done
93615ffd6003Smrg
93625ffd6003Smrg      if test -n "$xrpath"; then
93635ffd6003Smrg	# If the user specified any rpath flags, then add them.
93645ffd6003Smrg	temp_xrpath=
93655ffd6003Smrg	for libdir in $xrpath; do
9366629baa8cSmrg	  func_replace_sysroot "$libdir"
9367629baa8cSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
93685ffd6003Smrg	  case "$finalize_rpath " in
93695ffd6003Smrg	  *" $libdir "*) ;;
9370629baa8cSmrg	  *) func_append finalize_rpath " $libdir" ;;
93715ffd6003Smrg	  esac
93725ffd6003Smrg	done
9373b7d26471Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
93745ffd6003Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
93755ffd6003Smrg	fi
93765ffd6003Smrg      fi
93775ffd6003Smrg
93785ffd6003Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379b7d26471Smrg      old_dlfiles=$dlfiles
93805ffd6003Smrg      dlfiles=
93815ffd6003Smrg      for lib in $old_dlfiles; do
93825ffd6003Smrg	case " $dlprefiles $dlfiles " in
93835ffd6003Smrg	*" $lib "*) ;;
9384629baa8cSmrg	*) func_append dlfiles " $lib" ;;
93855ffd6003Smrg	esac
93865ffd6003Smrg      done
93875ffd6003Smrg
93885ffd6003Smrg      # Make sure dlprefiles contains only unique files
9389b7d26471Smrg      old_dlprefiles=$dlprefiles
93905ffd6003Smrg      dlprefiles=
93915ffd6003Smrg      for lib in $old_dlprefiles; do
93925ffd6003Smrg	case "$dlprefiles " in
93935ffd6003Smrg	*" $lib "*) ;;
9394629baa8cSmrg	*) func_append dlprefiles " $lib" ;;
93955ffd6003Smrg	esac
93965ffd6003Smrg      done
93975ffd6003Smrg
9398b7d26471Smrg      if test yes = "$build_libtool_libs"; then
93995ffd6003Smrg	if test -n "$rpath"; then
94005ffd6003Smrg	  case $host in
9401629baa8cSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
94025ffd6003Smrg	    # these systems don't actually have a c library (as such)!
94035ffd6003Smrg	    ;;
94045ffd6003Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
94055ffd6003Smrg	    # Rhapsody C library is in the System framework
9406629baa8cSmrg	    func_append deplibs " System.ltframework"
94075ffd6003Smrg	    ;;
94085ffd6003Smrg	  *-*-netbsd*)
94095ffd6003Smrg	    # Don't link with libc until the a.out ld.so is fixed.
94105ffd6003Smrg	    ;;
9411da2e2ef6Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
94125ffd6003Smrg	    # Do not include libc due to us having libc/libc_r.
94135ffd6003Smrg	    ;;
94145ffd6003Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
94155ffd6003Smrg	    # Causes problems with __ctype
94165ffd6003Smrg	    ;;
94175ffd6003Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
94185ffd6003Smrg	    # Compiler inserts libc in the correct place for threads to work
94195ffd6003Smrg	    ;;
94205ffd6003Smrg	  *)
94215ffd6003Smrg	    # Add libc to deplibs on all other systems if necessary.
9422b7d26471Smrg	    if test yes = "$build_libtool_need_lc"; then
9423629baa8cSmrg	      func_append deplibs " -lc"
94245ffd6003Smrg	    fi
94255ffd6003Smrg	    ;;
94265ffd6003Smrg	  esac
94275ffd6003Smrg	fi
94285ffd6003Smrg
94295ffd6003Smrg	# Transform deplibs into only deplibs that can be linked in shared.
94305ffd6003Smrg	name_save=$name
94315ffd6003Smrg	libname_save=$libname
94325ffd6003Smrg	release_save=$release
94335ffd6003Smrg	versuffix_save=$versuffix
94345ffd6003Smrg	major_save=$major
94355ffd6003Smrg	# I'm not sure if I'm treating the release correctly.  I think
94365ffd6003Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
94375ffd6003Smrg	# add it in twice.  Is that correct?
9438b7d26471Smrg	release=
9439b7d26471Smrg	versuffix=
9440b7d26471Smrg	major=
94415ffd6003Smrg	newdeplibs=
94425ffd6003Smrg	droppeddeps=no
94435ffd6003Smrg	case $deplibs_check_method in
94445ffd6003Smrg	pass_all)
94455ffd6003Smrg	  # Don't check for shared/static.  Everything works.
94465ffd6003Smrg	  # This might be a little naive.  We might want to check
94475ffd6003Smrg	  # whether the library exists or not.  But this is on
94485ffd6003Smrg	  # osf3 & osf4 and I'm not really sure... Just
94495ffd6003Smrg	  # implementing what was already the behavior.
94505ffd6003Smrg	  newdeplibs=$deplibs
94515ffd6003Smrg	  ;;
94525ffd6003Smrg	test_compile)
94535ffd6003Smrg	  # This code stresses the "libraries are programs" paradigm to its
94545ffd6003Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
94555ffd6003Smrg	  # against the deplibs as a proxy for the library.  Then we can check
94565ffd6003Smrg	  # whether they linked in statically or dynamically with ldd.
94575ffd6003Smrg	  $opt_dry_run || $RM conftest.c
94585ffd6003Smrg	  cat > conftest.c <<EOF
94595ffd6003Smrg	  int main() { return 0; }
94605ffd6003SmrgEOF
94615ffd6003Smrg	  $opt_dry_run || $RM conftest
94625ffd6003Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
94635ffd6003Smrg	    ldd_output=`ldd conftest`
94645ffd6003Smrg	    for i in $deplibs; do
94655ffd6003Smrg	      case $i in
94665ffd6003Smrg	      -l*)
94675ffd6003Smrg		func_stripname -l '' "$i"
94685ffd6003Smrg		name=$func_stripname_result
9469b7d26471Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94705ffd6003Smrg		  case " $predeps $postdeps " in
94715ffd6003Smrg		  *" $i "*)
9472629baa8cSmrg		    func_append newdeplibs " $i"
9473b7d26471Smrg		    i=
94745ffd6003Smrg		    ;;
94755ffd6003Smrg		  esac
94765ffd6003Smrg		fi
9477b7d26471Smrg		if test -n "$i"; then
94785ffd6003Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
94795ffd6003Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
94805ffd6003Smrg		  set dummy $deplib_matches; shift
94815ffd6003Smrg		  deplib_match=$1
9482b7d26471Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9483629baa8cSmrg		    func_append newdeplibs " $i"
94845ffd6003Smrg		  else
94855ffd6003Smrg		    droppeddeps=yes
9486629baa8cSmrg		    echo
94875ffd6003Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9488629baa8cSmrg		    echo "*** I have the capability to make that library automatically link in when"
9489629baa8cSmrg		    echo "*** you link to this library.  But I can only do this if you have a"
9490629baa8cSmrg		    echo "*** shared version of the library, which I believe you do not have"
9491629baa8cSmrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9492629baa8cSmrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
94935ffd6003Smrg		  fi
94945ffd6003Smrg		fi
94955ffd6003Smrg		;;
94965ffd6003Smrg	      *)
9497629baa8cSmrg		func_append newdeplibs " $i"
94985ffd6003Smrg		;;
94995ffd6003Smrg	      esac
95005ffd6003Smrg	    done
95015ffd6003Smrg	  else
95025ffd6003Smrg	    # Error occurred in the first compile.  Let's try to salvage
95035ffd6003Smrg	    # the situation: Compile a separate program for each library.
95045ffd6003Smrg	    for i in $deplibs; do
95055ffd6003Smrg	      case $i in
95065ffd6003Smrg	      -l*)
95075ffd6003Smrg		func_stripname -l '' "$i"
95085ffd6003Smrg		name=$func_stripname_result
95095ffd6003Smrg		$opt_dry_run || $RM conftest
95105ffd6003Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
95115ffd6003Smrg		  ldd_output=`ldd conftest`
9512b7d26471Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95135ffd6003Smrg		    case " $predeps $postdeps " in
95145ffd6003Smrg		    *" $i "*)
9515629baa8cSmrg		      func_append newdeplibs " $i"
9516b7d26471Smrg		      i=
95175ffd6003Smrg		      ;;
95185ffd6003Smrg		    esac
95195ffd6003Smrg		  fi
9520b7d26471Smrg		  if test -n "$i"; then
95215ffd6003Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
95225ffd6003Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
95235ffd6003Smrg		    set dummy $deplib_matches; shift
95245ffd6003Smrg		    deplib_match=$1
9525b7d26471Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9526629baa8cSmrg		      func_append newdeplibs " $i"
95275ffd6003Smrg		    else
95285ffd6003Smrg		      droppeddeps=yes
9529629baa8cSmrg		      echo
95305ffd6003Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9531629baa8cSmrg		      echo "*** I have the capability to make that library automatically link in when"
9532629baa8cSmrg		      echo "*** you link to this library.  But I can only do this if you have a"
9533629baa8cSmrg		      echo "*** shared version of the library, which you do not appear to have"
9534629baa8cSmrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9535629baa8cSmrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
95365ffd6003Smrg		    fi
95375ffd6003Smrg		  fi
95385ffd6003Smrg		else
95395ffd6003Smrg		  droppeddeps=yes
9540629baa8cSmrg		  echo
95415ffd6003Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9542629baa8cSmrg		  echo "*** make it link in!  You will probably need to install it or some"
9543629baa8cSmrg		  echo "*** library that it depends on before this library will be fully"
9544629baa8cSmrg		  echo "*** functional.  Installing it before continuing would be even better."
95455ffd6003Smrg		fi
95465ffd6003Smrg		;;
95475ffd6003Smrg	      *)
9548629baa8cSmrg		func_append newdeplibs " $i"
95495ffd6003Smrg		;;
95505ffd6003Smrg	      esac
95515ffd6003Smrg	    done
95525ffd6003Smrg	  fi
95535ffd6003Smrg	  ;;
95545ffd6003Smrg	file_magic*)
95555ffd6003Smrg	  set dummy $deplibs_check_method; shift
95565ffd6003Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
95575ffd6003Smrg	  for a_deplib in $deplibs; do
95585ffd6003Smrg	    case $a_deplib in
95595ffd6003Smrg	    -l*)
95605ffd6003Smrg	      func_stripname -l '' "$a_deplib"
95615ffd6003Smrg	      name=$func_stripname_result
9562b7d26471Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95635ffd6003Smrg		case " $predeps $postdeps " in
95645ffd6003Smrg		*" $a_deplib "*)
9565629baa8cSmrg		  func_append newdeplibs " $a_deplib"
9566b7d26471Smrg		  a_deplib=
95675ffd6003Smrg		  ;;
95685ffd6003Smrg		esac
95695ffd6003Smrg	      fi
9570b7d26471Smrg	      if test -n "$a_deplib"; then
95715ffd6003Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9572629baa8cSmrg		if test -n "$file_magic_glob"; then
9573629baa8cSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9574629baa8cSmrg		else
9575629baa8cSmrg		  libnameglob=$libname
9576629baa8cSmrg		fi
9577b7d26471Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
95785ffd6003Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579b7d26471Smrg		  if test yes = "$want_nocaseglob"; then
9580629baa8cSmrg		    shopt -s nocaseglob
9581629baa8cSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9582629baa8cSmrg		    $nocaseglob
9583629baa8cSmrg		  else
9584629baa8cSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9585629baa8cSmrg		  fi
95865ffd6003Smrg		  for potent_lib in $potential_libs; do
95875ffd6003Smrg		      # Follow soft links.
95885ffd6003Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
95895ffd6003Smrg			 $GREP " -> " >/dev/null; then
95905ffd6003Smrg			continue
95915ffd6003Smrg		      fi
95925ffd6003Smrg		      # The statement above tries to avoid entering an
95935ffd6003Smrg		      # endless loop below, in case of cyclic links.
95945ffd6003Smrg		      # We might still enter an endless loop, since a link
95955ffd6003Smrg		      # loop can be closed while we follow links,
95965ffd6003Smrg		      # but so what?
9597b7d26471Smrg		      potlib=$potent_lib
95985ffd6003Smrg		      while test -h "$potlib" 2>/dev/null; do
9599b7d26471Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
96005ffd6003Smrg			case $potliblink in
9601b7d26471Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602b7d26471Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
96035ffd6003Smrg			esac
96045ffd6003Smrg		      done
96055ffd6003Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
96065ffd6003Smrg			 $SED -e 10q |
96075ffd6003Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9608629baa8cSmrg			func_append newdeplibs " $a_deplib"
9609b7d26471Smrg			a_deplib=
96105ffd6003Smrg			break 2
96115ffd6003Smrg		      fi
96125ffd6003Smrg		  done
96135ffd6003Smrg		done
96145ffd6003Smrg	      fi
9615b7d26471Smrg	      if test -n "$a_deplib"; then
96165ffd6003Smrg		droppeddeps=yes
9617629baa8cSmrg		echo
96185ffd6003Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9619629baa8cSmrg		echo "*** I have the capability to make that library automatically link in when"
9620629baa8cSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9621629baa8cSmrg		echo "*** shared version of the library, which you do not appear to have"
9622629baa8cSmrg		echo "*** because I did check the linker path looking for a file starting"
9623b7d26471Smrg		if test -z "$potlib"; then
96245ffd6003Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
96255ffd6003Smrg		else
96265ffd6003Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96275ffd6003Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
96285ffd6003Smrg		fi
96295ffd6003Smrg	      fi
96305ffd6003Smrg	      ;;
96315ffd6003Smrg	    *)
96325ffd6003Smrg	      # Add a -L argument.
9633629baa8cSmrg	      func_append newdeplibs " $a_deplib"
96345ffd6003Smrg	      ;;
96355ffd6003Smrg	    esac
96365ffd6003Smrg	  done # Gone through all deplibs.
96375ffd6003Smrg	  ;;
96385ffd6003Smrg	match_pattern*)
96395ffd6003Smrg	  set dummy $deplibs_check_method; shift
96405ffd6003Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
96415ffd6003Smrg	  for a_deplib in $deplibs; do
96425ffd6003Smrg	    case $a_deplib in
96435ffd6003Smrg	    -l*)
96445ffd6003Smrg	      func_stripname -l '' "$a_deplib"
96455ffd6003Smrg	      name=$func_stripname_result
9646b7d26471Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
96475ffd6003Smrg		case " $predeps $postdeps " in
96485ffd6003Smrg		*" $a_deplib "*)
9649629baa8cSmrg		  func_append newdeplibs " $a_deplib"
9650b7d26471Smrg		  a_deplib=
96515ffd6003Smrg		  ;;
96525ffd6003Smrg		esac
96535ffd6003Smrg	      fi
9654b7d26471Smrg	      if test -n "$a_deplib"; then
96555ffd6003Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
96565ffd6003Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
96575ffd6003Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
96585ffd6003Smrg		  for potent_lib in $potential_libs; do
9659b7d26471Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9660629baa8cSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
96615ffd6003Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9662629baa8cSmrg		      func_append newdeplibs " $a_deplib"
9663b7d26471Smrg		      a_deplib=
96645ffd6003Smrg		      break 2
96655ffd6003Smrg		    fi
96665ffd6003Smrg		  done
96675ffd6003Smrg		done
96685ffd6003Smrg	      fi
9669b7d26471Smrg	      if test -n "$a_deplib"; then
96705ffd6003Smrg		droppeddeps=yes
9671629baa8cSmrg		echo
96725ffd6003Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9673629baa8cSmrg		echo "*** I have the capability to make that library automatically link in when"
9674629baa8cSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9675629baa8cSmrg		echo "*** shared version of the library, which you do not appear to have"
9676629baa8cSmrg		echo "*** because I did check the linker path looking for a file starting"
9677b7d26471Smrg		if test -z "$potlib"; then
96785ffd6003Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
96795ffd6003Smrg		else
96805ffd6003Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
96815ffd6003Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
96825ffd6003Smrg		fi
96835ffd6003Smrg	      fi
96845ffd6003Smrg	      ;;
96855ffd6003Smrg	    *)
96865ffd6003Smrg	      # Add a -L argument.
9687629baa8cSmrg	      func_append newdeplibs " $a_deplib"
96885ffd6003Smrg	      ;;
96895ffd6003Smrg	    esac
96905ffd6003Smrg	  done # Gone through all deplibs.
96915ffd6003Smrg	  ;;
96925ffd6003Smrg	none | unknown | *)
9693b7d26471Smrg	  newdeplibs=
9694629baa8cSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695b7d26471Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696b7d26471Smrg	    for i in $predeps $postdeps; do
96975ffd6003Smrg	      # can't use Xsed below, because $i might contain '/'
9698b7d26471Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
96995ffd6003Smrg	    done
97005ffd6003Smrg	  fi
9701629baa8cSmrg	  case $tmp_deplibs in
9702629baa8cSmrg	  *[!\	\ ]*)
9703629baa8cSmrg	    echo
9704b7d26471Smrg	    if test none = "$deplibs_check_method"; then
9705629baa8cSmrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
97065ffd6003Smrg	    else
9707629baa8cSmrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
97085ffd6003Smrg	    fi
9709629baa8cSmrg	    echo "*** All declared inter-library dependencies are being dropped."
97105ffd6003Smrg	    droppeddeps=yes
9711629baa8cSmrg	    ;;
9712629baa8cSmrg	  esac
97135ffd6003Smrg	  ;;
97145ffd6003Smrg	esac
97155ffd6003Smrg	versuffix=$versuffix_save
97165ffd6003Smrg	major=$major_save
97175ffd6003Smrg	release=$release_save
97185ffd6003Smrg	libname=$libname_save
97195ffd6003Smrg	name=$name_save
97205ffd6003Smrg
97215ffd6003Smrg	case $host in
97225ffd6003Smrg	*-*-rhapsody* | *-*-darwin1.[012])
97235ffd6003Smrg	  # On Rhapsody replace the C library with the System framework
9724629baa8cSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
97255ffd6003Smrg	  ;;
97265ffd6003Smrg	esac
97275ffd6003Smrg
9728b7d26471Smrg	if test yes = "$droppeddeps"; then
9729b7d26471Smrg	  if test yes = "$module"; then
9730629baa8cSmrg	    echo
9731629baa8cSmrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
97325ffd6003Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9733629baa8cSmrg	    echo "*** a static module, that should work as long as the dlopening"
9734629baa8cSmrg	    echo "*** application is linked with the -dlopen flag."
97355ffd6003Smrg	    if test -z "$global_symbol_pipe"; then
9736629baa8cSmrg	      echo
9737629baa8cSmrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738b7d26471Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9739629baa8cSmrg	      echo "*** not find such a program.  So, this module is probably useless."
9740b7d26471Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
97415ffd6003Smrg	    fi
9742b7d26471Smrg	    if test no = "$build_old_libs"; then
9743b7d26471Smrg	      oldlibs=$output_objdir/$libname.$libext
97445ffd6003Smrg	      build_libtool_libs=module
97455ffd6003Smrg	      build_old_libs=yes
97465ffd6003Smrg	    else
97475ffd6003Smrg	      build_libtool_libs=no
97485ffd6003Smrg	    fi
97495ffd6003Smrg	  else
9750629baa8cSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9751629baa8cSmrg	    echo "*** automatically added whenever a program is linked with this library"
9752629baa8cSmrg	    echo "*** or is declared to -dlopen it."
97535ffd6003Smrg
9754b7d26471Smrg	    if test no = "$allow_undefined"; then
9755629baa8cSmrg	      echo
9756629baa8cSmrg	      echo "*** Since this library must not contain undefined symbols,"
9757629baa8cSmrg	      echo "*** because either the platform does not support them or"
9758629baa8cSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9759629baa8cSmrg	      echo "*** libtool will only create a static version of it."
9760b7d26471Smrg	      if test no = "$build_old_libs"; then
9761b7d26471Smrg		oldlibs=$output_objdir/$libname.$libext
97625ffd6003Smrg		build_libtool_libs=module
97635ffd6003Smrg		build_old_libs=yes
97645ffd6003Smrg	      else
97655ffd6003Smrg		build_libtool_libs=no
97665ffd6003Smrg	      fi
97675ffd6003Smrg	    fi
97685ffd6003Smrg	  fi
97695ffd6003Smrg	fi
97705ffd6003Smrg	# Done checking deplibs!
97715ffd6003Smrg	deplibs=$newdeplibs
97725ffd6003Smrg      fi
97735ffd6003Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
97745ffd6003Smrg      case $host in
97755ffd6003Smrg	*-*-darwin*)
9776629baa8cSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9777629baa8cSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9778629baa8cSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
97795ffd6003Smrg	  ;;
97805ffd6003Smrg      esac
97815ffd6003Smrg
97825ffd6003Smrg      # move library search paths that coincide with paths to not yet
97835ffd6003Smrg      # installed libraries to the beginning of the library search list
97845ffd6003Smrg      new_libs=
97855ffd6003Smrg      for path in $notinst_path; do
97865ffd6003Smrg	case " $new_libs " in
97875ffd6003Smrg	*" -L$path/$objdir "*) ;;
97885ffd6003Smrg	*)
97895ffd6003Smrg	  case " $deplibs " in
97905ffd6003Smrg	  *" -L$path/$objdir "*)
9791629baa8cSmrg	    func_append new_libs " -L$path/$objdir" ;;
97925ffd6003Smrg	  esac
97935ffd6003Smrg	  ;;
97945ffd6003Smrg	esac
97955ffd6003Smrg      done
97965ffd6003Smrg      for deplib in $deplibs; do
97975ffd6003Smrg	case $deplib in
97985ffd6003Smrg	-L*)
97995ffd6003Smrg	  case " $new_libs " in
98005ffd6003Smrg	  *" $deplib "*) ;;
9801629baa8cSmrg	  *) func_append new_libs " $deplib" ;;
98025ffd6003Smrg	  esac
98035ffd6003Smrg	  ;;
9804629baa8cSmrg	*) func_append new_libs " $deplib" ;;
98055ffd6003Smrg	esac
98065ffd6003Smrg      done
9807b7d26471Smrg      deplibs=$new_libs
98085ffd6003Smrg
98095ffd6003Smrg      # All the library-specific variables (install_libdir is set above).
98105ffd6003Smrg      library_names=
98115ffd6003Smrg      old_library=
98125ffd6003Smrg      dlname=
98135ffd6003Smrg
98145ffd6003Smrg      # Test again, we may have decided not to build it any more
9815b7d26471Smrg      if test yes = "$build_libtool_libs"; then
9816b7d26471Smrg	# Remove $wl instances when linking with ld.
9817b7d26471Smrg	# FIXME: should test the right _cmds variable.
9818b7d26471Smrg	case $archive_cmds in
9819b7d26471Smrg	  *\$LD\ *) wl= ;;
9820b7d26471Smrg        esac
9821b7d26471Smrg	if test yes = "$hardcode_into_libs"; then
98225ffd6003Smrg	  # Hardcode the library paths
98235ffd6003Smrg	  hardcode_libdirs=
98245ffd6003Smrg	  dep_rpath=
9825b7d26471Smrg	  rpath=$finalize_rpath
9826b7d26471Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
98275ffd6003Smrg	  for libdir in $rpath; do
98285ffd6003Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
98295ffd6003Smrg	      if test -n "$hardcode_libdir_separator"; then
9830629baa8cSmrg		func_replace_sysroot "$libdir"
9831629baa8cSmrg		libdir=$func_replace_sysroot_result
98325ffd6003Smrg		if test -z "$hardcode_libdirs"; then
9833b7d26471Smrg		  hardcode_libdirs=$libdir
98345ffd6003Smrg		else
98355ffd6003Smrg		  # Just accumulate the unique libdirs.
98365ffd6003Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
98375ffd6003Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
98385ffd6003Smrg		    ;;
98395ffd6003Smrg		  *)
9840629baa8cSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
98415ffd6003Smrg		    ;;
98425ffd6003Smrg		  esac
98435ffd6003Smrg		fi
98445ffd6003Smrg	      else
98455ffd6003Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9846629baa8cSmrg		func_append dep_rpath " $flag"
98475ffd6003Smrg	      fi
98485ffd6003Smrg	    elif test -n "$runpath_var"; then
98495ffd6003Smrg	      case "$perm_rpath " in
98505ffd6003Smrg	      *" $libdir "*) ;;
9851b7d26471Smrg	      *) func_append perm_rpath " $libdir" ;;
98525ffd6003Smrg	      esac
98535ffd6003Smrg	    fi
98545ffd6003Smrg	  done
98555ffd6003Smrg	  # Substitute the hardcoded libdirs into the rpath.
98565ffd6003Smrg	  if test -n "$hardcode_libdir_separator" &&
98575ffd6003Smrg	     test -n "$hardcode_libdirs"; then
9858b7d26471Smrg	    libdir=$hardcode_libdirs
9859b7d26471Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
98605ffd6003Smrg	  fi
98615ffd6003Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
98625ffd6003Smrg	    # We should set the runpath_var.
98635ffd6003Smrg	    rpath=
98645ffd6003Smrg	    for dir in $perm_rpath; do
9865629baa8cSmrg	      func_append rpath "$dir:"
98665ffd6003Smrg	    done
98675ffd6003Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
98685ffd6003Smrg	  fi
98695ffd6003Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
98705ffd6003Smrg	fi
9871145b7b3cSmrg
9872b7d26471Smrg	shlibpath=$finalize_shlibpath
9873b7d26471Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
98745ffd6003Smrg	if test -n "$shlibpath"; then
98755ffd6003Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
98765ffd6003Smrg	fi
9877145b7b3cSmrg
98785ffd6003Smrg	# Get the real and link names of the library.
98795ffd6003Smrg	eval shared_ext=\"$shrext_cmds\"
98805ffd6003Smrg	eval library_names=\"$library_names_spec\"
98815ffd6003Smrg	set dummy $library_names
98825ffd6003Smrg	shift
9883b7d26471Smrg	realname=$1
98845ffd6003Smrg	shift
9885145b7b3cSmrg
98865ffd6003Smrg	if test -n "$soname_spec"; then
98875ffd6003Smrg	  eval soname=\"$soname_spec\"
98885ffd6003Smrg	else
9889b7d26471Smrg	  soname=$realname
98905ffd6003Smrg	fi
98915ffd6003Smrg	if test -z "$dlname"; then
98925ffd6003Smrg	  dlname=$soname
98935ffd6003Smrg	fi
9894145b7b3cSmrg
9895b7d26471Smrg	lib=$output_objdir/$realname
98965ffd6003Smrg	linknames=
98975ffd6003Smrg	for link
98985ffd6003Smrg	do
9899629baa8cSmrg	  func_append linknames " $link"
99005ffd6003Smrg	done
9901145b7b3cSmrg
99025ffd6003Smrg	# Use standard objects if they are pic
9903629baa8cSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
99045ffd6003Smrg	test "X$libobjs" = "X " && libobjs=
9905145b7b3cSmrg
99065ffd6003Smrg	delfiles=
99075ffd6003Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
99085ffd6003Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909b7d26471Smrg	  export_symbols=$output_objdir/$libname.uexp
9910629baa8cSmrg	  func_append delfiles " $export_symbols"
99115ffd6003Smrg	fi
9912145b7b3cSmrg
99135ffd6003Smrg	orig_export_symbols=
99145ffd6003Smrg	case $host_os in
99155ffd6003Smrg	cygwin* | mingw* | cegcc*)
99165ffd6003Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
99175ffd6003Smrg	    # exporting using user supplied symfile
9918b7d26471Smrg	    func_dll_def_p "$export_symbols" || {
99195ffd6003Smrg	      # and it's NOT already a .def file. Must figure out
99205ffd6003Smrg	      # which of the given symbols are data symbols and tag
99215ffd6003Smrg	      # them as such. So, trigger use of export_symbols_cmds.
99225ffd6003Smrg	      # export_symbols gets reassigned inside the "prepare
99235ffd6003Smrg	      # the list of exported symbols" if statement, so the
99245ffd6003Smrg	      # include_expsyms logic still works.
9925b7d26471Smrg	      orig_export_symbols=$export_symbols
99265ffd6003Smrg	      export_symbols=
99275ffd6003Smrg	      always_export_symbols=yes
9928b7d26471Smrg	    }
99295ffd6003Smrg	  fi
99305ffd6003Smrg	  ;;
99315ffd6003Smrg	esac
9932145b7b3cSmrg
99335ffd6003Smrg	# Prepare the list of exported symbols
99345ffd6003Smrg	if test -z "$export_symbols"; then
9935b7d26471Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936b7d26471Smrg	    func_verbose "generating symbol list for '$libname.la'"
9937b7d26471Smrg	    export_symbols=$output_objdir/$libname.exp
99385ffd6003Smrg	    $opt_dry_run || $RM $export_symbols
99395ffd6003Smrg	    cmds=$export_symbols_cmds
9940b7d26471Smrg	    save_ifs=$IFS; IFS='~'
9941629baa8cSmrg	    for cmd1 in $cmds; do
9942b7d26471Smrg	      IFS=$save_ifs
9943629baa8cSmrg	      # Take the normal branch if the nm_file_list_spec branch
9944629baa8cSmrg	      # doesn't work or if tool conversion is not needed.
9945629baa8cSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9946629baa8cSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9947629baa8cSmrg		  try_normal_branch=yes
9948629baa8cSmrg		  eval cmd=\"$cmd1\"
9949629baa8cSmrg		  func_len " $cmd"
9950629baa8cSmrg		  len=$func_len_result
9951629baa8cSmrg		  ;;
9952629baa8cSmrg		*)
9953629baa8cSmrg		  try_normal_branch=no
9954629baa8cSmrg		  ;;
9955629baa8cSmrg	      esac
9956b7d26471Smrg	      if test yes = "$try_normal_branch" \
9957629baa8cSmrg		 && { test "$len" -lt "$max_cmd_len" \
9958629baa8cSmrg		      || test "$max_cmd_len" -le -1; }
9959629baa8cSmrg	      then
9960629baa8cSmrg		func_show_eval "$cmd" 'exit $?'
9961629baa8cSmrg		skipped_export=false
9962629baa8cSmrg	      elif test -n "$nm_file_list_spec"; then
9963629baa8cSmrg		func_basename "$output"
9964629baa8cSmrg		output_la=$func_basename_result
9965629baa8cSmrg		save_libobjs=$libobjs
9966629baa8cSmrg		save_output=$output
9967b7d26471Smrg		output=$output_objdir/$output_la.nm
9968629baa8cSmrg		func_to_tool_file "$output"
9969629baa8cSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9970629baa8cSmrg		func_append delfiles " $output"
9971629baa8cSmrg		func_verbose "creating $NM input file list: $output"
9972629baa8cSmrg		for obj in $save_libobjs; do
9973629baa8cSmrg		  func_to_tool_file "$obj"
9974629baa8cSmrg		  $ECHO "$func_to_tool_file_result"
9975629baa8cSmrg		done > "$output"
9976629baa8cSmrg		eval cmd=\"$cmd1\"
99775ffd6003Smrg		func_show_eval "$cmd" 'exit $?'
9978629baa8cSmrg		output=$save_output
9979629baa8cSmrg		libobjs=$save_libobjs
99805ffd6003Smrg		skipped_export=false
99815ffd6003Smrg	      else
99825ffd6003Smrg		# The command line is too long to execute in one step.
99835ffd6003Smrg		func_verbose "using reloadable object file for export list..."
99845ffd6003Smrg		skipped_export=:
99855ffd6003Smrg		# Break out early, otherwise skipped_export may be
99865ffd6003Smrg		# set to false by a later but shorter cmd.
99875ffd6003Smrg		break
99885ffd6003Smrg	      fi
99895ffd6003Smrg	    done
9990b7d26471Smrg	    IFS=$save_ifs
9991b7d26471Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
99925ffd6003Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
99935ffd6003Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
99945ffd6003Smrg	    fi
99955ffd6003Smrg	  fi
9996145b7b3cSmrg	fi
9997145b7b3cSmrg
99985ffd6003Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999b7d26471Smrg	  tmp_export_symbols=$export_symbols
10000b7d26471Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10001629baa8cSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
100025ffd6003Smrg	fi
10003145b7b3cSmrg
10004b7d26471Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
100055ffd6003Smrg	  # The given exports_symbols file has to be filtered, so filter it.
10006b7d26471Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
100075ffd6003Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008b7d26471Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
100095ffd6003Smrg	  # though. Also, the filter scales superlinearly with the number of
100105ffd6003Smrg	  # global variables. join(1) would be nice here, but unfortunately
100115ffd6003Smrg	  # isn't a blessed tool.
100125ffd6003Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10013629baa8cSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
100145ffd6003Smrg	  export_symbols=$output_objdir/$libname.def
100155ffd6003Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
100165ffd6003Smrg	fi
10017145b7b3cSmrg
100185ffd6003Smrg	tmp_deplibs=
100195ffd6003Smrg	for test_deplib in $deplibs; do
100205ffd6003Smrg	  case " $convenience " in
100215ffd6003Smrg	  *" $test_deplib "*) ;;
100225ffd6003Smrg	  *)
10023629baa8cSmrg	    func_append tmp_deplibs " $test_deplib"
100245ffd6003Smrg	    ;;
100255ffd6003Smrg	  esac
100265ffd6003Smrg	done
10027b7d26471Smrg	deplibs=$tmp_deplibs
10028145b7b3cSmrg
100295ffd6003Smrg	if test -n "$convenience"; then
100305ffd6003Smrg	  if test -n "$whole_archive_flag_spec" &&
10031b7d26471Smrg	    test yes = "$compiler_needs_object" &&
100325ffd6003Smrg	    test -z "$libobjs"; then
100335ffd6003Smrg	    # extract the archives, so we have objects to list.
100345ffd6003Smrg	    # TODO: could optimize this to just extract one archive.
100355ffd6003Smrg	    whole_archive_flag_spec=
100365ffd6003Smrg	  fi
100375ffd6003Smrg	  if test -n "$whole_archive_flag_spec"; then
100385ffd6003Smrg	    save_libobjs=$libobjs
100395ffd6003Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
100405ffd6003Smrg	    test "X$libobjs" = "X " && libobjs=
100415ffd6003Smrg	  else
10042b7d26471Smrg	    gentop=$output_objdir/${outputname}x
10043629baa8cSmrg	    func_append generated " $gentop"
10044145b7b3cSmrg
100455ffd6003Smrg	    func_extract_archives $gentop $convenience
10046629baa8cSmrg	    func_append libobjs " $func_extract_archives_result"
100475ffd6003Smrg	    test "X$libobjs" = "X " && libobjs=
100485ffd6003Smrg	  fi
10049145b7b3cSmrg	fi
10050145b7b3cSmrg
10051b7d26471Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
100525ffd6003Smrg	  eval flag=\"$thread_safe_flag_spec\"
10053629baa8cSmrg	  func_append linker_flags " $flag"
10054145b7b3cSmrg	fi
10055145b7b3cSmrg
100565ffd6003Smrg	# Make a backup of the uninstalled library when relinking
10057b7d26471Smrg	if test relink = "$opt_mode"; then
100585ffd6003Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
100595ffd6003Smrg	fi
10060145b7b3cSmrg
100615ffd6003Smrg	# Do each of the archive commands.
10062b7d26471Smrg	if test yes = "$module" && test -n "$module_cmds"; then
100635ffd6003Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
100645ffd6003Smrg	    eval test_cmds=\"$module_expsym_cmds\"
100655ffd6003Smrg	    cmds=$module_expsym_cmds
100665ffd6003Smrg	  else
100675ffd6003Smrg	    eval test_cmds=\"$module_cmds\"
100685ffd6003Smrg	    cmds=$module_cmds
100695ffd6003Smrg	  fi
10070145b7b3cSmrg	else
100715ffd6003Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
100725ffd6003Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
100735ffd6003Smrg	    cmds=$archive_expsym_cmds
100745ffd6003Smrg	  else
100755ffd6003Smrg	    eval test_cmds=\"$archive_cmds\"
100765ffd6003Smrg	    cmds=$archive_cmds
100775ffd6003Smrg	  fi
10078145b7b3cSmrg	fi
10079145b7b3cSmrg
10080b7d26471Smrg	if test : != "$skipped_export" &&
100815ffd6003Smrg	   func_len " $test_cmds" &&
100825ffd6003Smrg	   len=$func_len_result &&
100835ffd6003Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
100845ffd6003Smrg	  :
100855ffd6003Smrg	else
100865ffd6003Smrg	  # The command line is too long to link in one step, link piecewise
100875ffd6003Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
100885ffd6003Smrg	  # script.
10089145b7b3cSmrg
100905ffd6003Smrg	  # Save the value of $output and $libobjs because we want to
100915ffd6003Smrg	  # use them later.  If we have whole_archive_flag_spec, we
100925ffd6003Smrg	  # want to use save_libobjs as it was before
100935ffd6003Smrg	  # whole_archive_flag_spec was expanded, because we can't
100945ffd6003Smrg	  # assume the linker understands whole_archive_flag_spec.
100955ffd6003Smrg	  # This may have to be revisited, in case too many
100965ffd6003Smrg	  # convenience libraries get linked in and end up exceeding
100975ffd6003Smrg	  # the spec.
100985ffd6003Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
100995ffd6003Smrg	    save_libobjs=$libobjs
101005ffd6003Smrg	  fi
101015ffd6003Smrg	  save_output=$output
10102629baa8cSmrg	  func_basename "$output"
10103629baa8cSmrg	  output_la=$func_basename_result
10104145b7b3cSmrg
101055ffd6003Smrg	  # Clear the reloadable object creation command queue and
101065ffd6003Smrg	  # initialize k to one.
101075ffd6003Smrg	  test_cmds=
101085ffd6003Smrg	  concat_cmds=
101095ffd6003Smrg	  objlist=
101105ffd6003Smrg	  last_robj=
101115ffd6003Smrg	  k=1
101125ffd6003Smrg
10113b7d26471Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114b7d26471Smrg	    output=$output_objdir/$output_la.lnkscript
101155ffd6003Smrg	    func_verbose "creating GNU ld script: $output"
10116629baa8cSmrg	    echo 'INPUT (' > $output
101175ffd6003Smrg	    for obj in $save_libobjs
10118145b7b3cSmrg	    do
10119629baa8cSmrg	      func_to_tool_file "$obj"
10120629baa8cSmrg	      $ECHO "$func_to_tool_file_result" >> $output
101215ffd6003Smrg	    done
10122629baa8cSmrg	    echo ')' >> $output
10123629baa8cSmrg	    func_append delfiles " $output"
10124629baa8cSmrg	    func_to_tool_file "$output"
10125629baa8cSmrg	    output=$func_to_tool_file_result
10126b7d26471Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127b7d26471Smrg	    output=$output_objdir/$output_la.lnk
101285ffd6003Smrg	    func_verbose "creating linker input file list: $output"
101295ffd6003Smrg	    : > $output
101305ffd6003Smrg	    set x $save_libobjs
101315ffd6003Smrg	    shift
101325ffd6003Smrg	    firstobj=
10133b7d26471Smrg	    if test yes = "$compiler_needs_object"; then
101345ffd6003Smrg	      firstobj="$1 "
101355ffd6003Smrg	      shift
101365ffd6003Smrg	    fi
101375ffd6003Smrg	    for obj
101385ffd6003Smrg	    do
10139629baa8cSmrg	      func_to_tool_file "$obj"
10140629baa8cSmrg	      $ECHO "$func_to_tool_file_result" >> $output
101415ffd6003Smrg	    done
10142629baa8cSmrg	    func_append delfiles " $output"
10143629baa8cSmrg	    func_to_tool_file "$output"
10144629baa8cSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
101455ffd6003Smrg	  else
101465ffd6003Smrg	    if test -n "$save_libobjs"; then
101475ffd6003Smrg	      func_verbose "creating reloadable object files..."
10148b7d26471Smrg	      output=$output_objdir/$output_la-$k.$objext
101495ffd6003Smrg	      eval test_cmds=\"$reload_cmds\"
101505ffd6003Smrg	      func_len " $test_cmds"
101515ffd6003Smrg	      len0=$func_len_result
101525ffd6003Smrg	      len=$len0
101535ffd6003Smrg
101545ffd6003Smrg	      # Loop over the list of objects to be linked.
101555ffd6003Smrg	      for obj in $save_libobjs
101565ffd6003Smrg	      do
101575ffd6003Smrg		func_len " $obj"
101585ffd6003Smrg		func_arith $len + $func_len_result
101595ffd6003Smrg		len=$func_arith_result
10160b7d26471Smrg		if test -z "$objlist" ||
101615ffd6003Smrg		   test "$len" -lt "$max_cmd_len"; then
101625ffd6003Smrg		  func_append objlist " $obj"
101635ffd6003Smrg		else
101645ffd6003Smrg		  # The command $test_cmds is almost too long, add a
101655ffd6003Smrg		  # command to the queue.
10166b7d26471Smrg		  if test 1 -eq "$k"; then
101675ffd6003Smrg		    # The first file doesn't have a previous command to add.
10168629baa8cSmrg		    reload_objs=$objlist
10169629baa8cSmrg		    eval concat_cmds=\"$reload_cmds\"
101705ffd6003Smrg		  else
101715ffd6003Smrg		    # All subsequent reloadable object files will link in
101725ffd6003Smrg		    # the last one created.
10173629baa8cSmrg		    reload_objs="$objlist $last_robj"
10174629baa8cSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
101755ffd6003Smrg		  fi
10176b7d26471Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
101775ffd6003Smrg		  func_arith $k + 1
101785ffd6003Smrg		  k=$func_arith_result
10179b7d26471Smrg		  output=$output_objdir/$output_la-$k.$objext
10180629baa8cSmrg		  objlist=" $obj"
101815ffd6003Smrg		  func_len " $last_robj"
101825ffd6003Smrg		  func_arith $len0 + $func_len_result
101835ffd6003Smrg		  len=$func_arith_result
101845ffd6003Smrg		fi
101855ffd6003Smrg	      done
101865ffd6003Smrg	      # Handle the remaining objects by creating one last
101875ffd6003Smrg	      # reloadable object file.  All subsequent reloadable object
101885ffd6003Smrg	      # files will link in the last one created.
101895ffd6003Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10190629baa8cSmrg	      reload_objs="$objlist $last_robj"
10191b7d26471Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
101925ffd6003Smrg	      if test -n "$last_robj"; then
10193b7d26471Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
101945ffd6003Smrg	      fi
10195629baa8cSmrg	      func_append delfiles " $output"
10196145b7b3cSmrg
101975ffd6003Smrg	    else
101985ffd6003Smrg	      output=
101995ffd6003Smrg	    fi
10200145b7b3cSmrg
10201b7d26471Smrg	    ${skipped_export-false} && {
10202b7d26471Smrg	      func_verbose "generating symbol list for '$libname.la'"
10203b7d26471Smrg	      export_symbols=$output_objdir/$libname.exp
102045ffd6003Smrg	      $opt_dry_run || $RM $export_symbols
102055ffd6003Smrg	      libobjs=$output
102065ffd6003Smrg	      # Append the command to create the export file.
102075ffd6003Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
102085ffd6003Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
102095ffd6003Smrg	      if test -n "$last_robj"; then
102105ffd6003Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
102115ffd6003Smrg	      fi
10212b7d26471Smrg	    }
10213145b7b3cSmrg
102145ffd6003Smrg	    test -n "$save_libobjs" &&
102155ffd6003Smrg	      func_verbose "creating a temporary reloadable object file: $output"
10216145b7b3cSmrg
102175ffd6003Smrg	    # Loop through the commands generated above and execute them.
10218b7d26471Smrg	    save_ifs=$IFS; IFS='~'
102195ffd6003Smrg	    for cmd in $concat_cmds; do
10220b7d26471Smrg	      IFS=$save_ifs
10221b7d26471Smrg	      $opt_quiet || {
10222da2e2ef6Smrg		  func_quote_arg expand,pretty "$cmd"
10223da2e2ef6Smrg		  eval "func_echo $func_quote_arg_result"
102245ffd6003Smrg	      }
102255ffd6003Smrg	      $opt_dry_run || eval "$cmd" || {
102265ffd6003Smrg		lt_exit=$?
102275ffd6003Smrg
102285ffd6003Smrg		# Restore the uninstalled library and exit
10229b7d26471Smrg		if test relink = "$opt_mode"; then
102305ffd6003Smrg		  ( cd "$output_objdir" && \
102315ffd6003Smrg		    $RM "${realname}T" && \
102325ffd6003Smrg		    $MV "${realname}U" "$realname" )
102335ffd6003Smrg		fi
10234145b7b3cSmrg
102355ffd6003Smrg		exit $lt_exit
102365ffd6003Smrg	      }
102375ffd6003Smrg	    done
10238b7d26471Smrg	    IFS=$save_ifs
10239145b7b3cSmrg
102405ffd6003Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
102415ffd6003Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
102425ffd6003Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10243145b7b3cSmrg	    fi
10244145b7b3cSmrg	  fi
10245145b7b3cSmrg
10246b7d26471Smrg          ${skipped_export-false} && {
102475ffd6003Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248b7d26471Smrg	      tmp_export_symbols=$export_symbols
10249b7d26471Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10250629baa8cSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
102515ffd6003Smrg	    fi
10252145b7b3cSmrg
102535ffd6003Smrg	    if test -n "$orig_export_symbols"; then
102545ffd6003Smrg	      # The given exports_symbols file has to be filtered, so filter it.
10255b7d26471Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
102565ffd6003Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257b7d26471Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
102585ffd6003Smrg	      # though. Also, the filter scales superlinearly with the number of
102595ffd6003Smrg	      # global variables. join(1) would be nice here, but unfortunately
102605ffd6003Smrg	      # isn't a blessed tool.
102615ffd6003Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10262629baa8cSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
102635ffd6003Smrg	      export_symbols=$output_objdir/$libname.def
102645ffd6003Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
102655ffd6003Smrg	    fi
10266b7d26471Smrg	  }
10267145b7b3cSmrg
102685ffd6003Smrg	  libobjs=$output
102695ffd6003Smrg	  # Restore the value of output.
102705ffd6003Smrg	  output=$save_output
10271145b7b3cSmrg
102725ffd6003Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
102735ffd6003Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
102745ffd6003Smrg	    test "X$libobjs" = "X " && libobjs=
102755ffd6003Smrg	  fi
102765ffd6003Smrg	  # Expand the library linking commands again to reset the
102775ffd6003Smrg	  # value of $libobjs for piecewise linking.
10278145b7b3cSmrg
102795ffd6003Smrg	  # Do each of the archive commands.
10280b7d26471Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
102815ffd6003Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
102825ffd6003Smrg	      cmds=$module_expsym_cmds
102835ffd6003Smrg	    else
102845ffd6003Smrg	      cmds=$module_cmds
10285145b7b3cSmrg	    fi
10286145b7b3cSmrg	  else
102875ffd6003Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
102885ffd6003Smrg	      cmds=$archive_expsym_cmds
102895ffd6003Smrg	    else
102905ffd6003Smrg	      cmds=$archive_cmds
102915ffd6003Smrg	    fi
10292145b7b3cSmrg	  fi
102935ffd6003Smrg	fi
10294145b7b3cSmrg
102955ffd6003Smrg	if test -n "$delfiles"; then
102965ffd6003Smrg	  # Append the command to remove temporary files to $cmds.
102975ffd6003Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
102985ffd6003Smrg	fi
10299145b7b3cSmrg
103005ffd6003Smrg	# Add any objects from preloaded convenience libraries
103015ffd6003Smrg	if test -n "$dlprefiles"; then
10302b7d26471Smrg	  gentop=$output_objdir/${outputname}x
10303629baa8cSmrg	  func_append generated " $gentop"
10304145b7b3cSmrg
103055ffd6003Smrg	  func_extract_archives $gentop $dlprefiles
10306629baa8cSmrg	  func_append libobjs " $func_extract_archives_result"
103075ffd6003Smrg	  test "X$libobjs" = "X " && libobjs=
103085ffd6003Smrg	fi
10309145b7b3cSmrg
10310b7d26471Smrg	save_ifs=$IFS; IFS='~'
103115ffd6003Smrg	for cmd in $cmds; do
10312b7d26471Smrg	  IFS=$sp$nl
103135ffd6003Smrg	  eval cmd=\"$cmd\"
10314b7d26471Smrg	  IFS=$save_ifs
10315b7d26471Smrg	  $opt_quiet || {
10316da2e2ef6Smrg	    func_quote_arg expand,pretty "$cmd"
10317da2e2ef6Smrg	    eval "func_echo $func_quote_arg_result"
103185ffd6003Smrg	  }
103195ffd6003Smrg	  $opt_dry_run || eval "$cmd" || {
103205ffd6003Smrg	    lt_exit=$?
10321145b7b3cSmrg
103225ffd6003Smrg	    # Restore the uninstalled library and exit
10323b7d26471Smrg	    if test relink = "$opt_mode"; then
103245ffd6003Smrg	      ( cd "$output_objdir" && \
103255ffd6003Smrg	        $RM "${realname}T" && \
103265ffd6003Smrg		$MV "${realname}U" "$realname" )
103275ffd6003Smrg	    fi
10328145b7b3cSmrg
103295ffd6003Smrg	    exit $lt_exit
103305ffd6003Smrg	  }
103315ffd6003Smrg	done
10332b7d26471Smrg	IFS=$save_ifs
10333145b7b3cSmrg
103345ffd6003Smrg	# Restore the uninstalled library and exit
10335b7d26471Smrg	if test relink = "$opt_mode"; then
103365ffd6003Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10337145b7b3cSmrg
103385ffd6003Smrg	  if test -n "$convenience"; then
103395ffd6003Smrg	    if test -z "$whole_archive_flag_spec"; then
103405ffd6003Smrg	      func_show_eval '${RM}r "$gentop"'
103415ffd6003Smrg	    fi
103425ffd6003Smrg	  fi
10343145b7b3cSmrg
103445ffd6003Smrg	  exit $EXIT_SUCCESS
103455ffd6003Smrg	fi
103465ffd6003Smrg
103475ffd6003Smrg	# Create links to the real library.
103485ffd6003Smrg	for linkname in $linknames; do
103495ffd6003Smrg	  if test "$realname" != "$linkname"; then
103505ffd6003Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351145b7b3cSmrg	  fi
10352145b7b3cSmrg	done
10353145b7b3cSmrg
103545ffd6003Smrg	# If -module or -export-dynamic was specified, set the dlname.
10355b7d26471Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
103565ffd6003Smrg	  # On all known operating systems, these are identical.
10357b7d26471Smrg	  dlname=$soname
103585ffd6003Smrg	fi
103595ffd6003Smrg      fi
10360145b7b3cSmrg      ;;
10361145b7b3cSmrg
103625ffd6003Smrg    obj)
10363b7d26471Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364b7d26471Smrg	func_warning "'-dlopen' is ignored for objects"
103655ffd6003Smrg      fi
10366145b7b3cSmrg
103675ffd6003Smrg      case " $deplibs" in
103685ffd6003Smrg      *\ -l* | *\ -L*)
10369b7d26471Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10370145b7b3cSmrg      esac
10371145b7b3cSmrg
103725ffd6003Smrg      test -n "$rpath" && \
10373b7d26471Smrg	func_warning "'-rpath' is ignored for objects"
103745ffd6003Smrg
103755ffd6003Smrg      test -n "$xrpath" && \
10376b7d26471Smrg	func_warning "'-R' is ignored for objects"
10377145b7b3cSmrg
103785ffd6003Smrg      test -n "$vinfo" && \
10379b7d26471Smrg	func_warning "'-version-info' is ignored for objects"
10380145b7b3cSmrg
103815ffd6003Smrg      test -n "$release" && \
10382b7d26471Smrg	func_warning "'-release' is ignored for objects"
103835ffd6003Smrg
103845ffd6003Smrg      case $output in
103855ffd6003Smrg      *.lo)
103865ffd6003Smrg	test -n "$objs$old_deplibs" && \
10387b7d26471Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
103885ffd6003Smrg
103895ffd6003Smrg	libobj=$output
103905ffd6003Smrg	func_lo2o "$libobj"
103915ffd6003Smrg	obj=$func_lo2o_result
10392145b7b3cSmrg	;;
10393145b7b3cSmrg      *)
103945ffd6003Smrg	libobj=
10395b7d26471Smrg	obj=$output
10396145b7b3cSmrg	;;
10397145b7b3cSmrg      esac
10398145b7b3cSmrg
103995ffd6003Smrg      # Delete the old objects.
104005ffd6003Smrg      $opt_dry_run || $RM $obj $libobj
10401145b7b3cSmrg
104025ffd6003Smrg      # Objects from convenience libraries.  This assumes
104035ffd6003Smrg      # single-version convenience libraries.  Whenever we create
104045ffd6003Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
104055ffd6003Smrg      # the extraction.
104065ffd6003Smrg      reload_conv_objs=
104075ffd6003Smrg      gentop=
10408b7d26471Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409b7d26471Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410b7d26471Smrg      # into space.
10411b7d26471Smrg      case $reload_cmds in
10412b7d26471Smrg        *\$LD[\ \$]*) wl= ;;
10413b7d26471Smrg      esac
104145ffd6003Smrg      if test -n "$convenience"; then
104155ffd6003Smrg	if test -n "$whole_archive_flag_spec"; then
104165ffd6003Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417b7d26471Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418b7d26471Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
104195ffd6003Smrg	else
10420b7d26471Smrg	  gentop=$output_objdir/${obj}x
10421629baa8cSmrg	  func_append generated " $gentop"
10422145b7b3cSmrg
104235ffd6003Smrg	  func_extract_archives $gentop $convenience
104245ffd6003Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
104255ffd6003Smrg	fi
10426145b7b3cSmrg      fi
10427145b7b3cSmrg
10428629baa8cSmrg      # If we're not building shared, we need to use non_pic_objs
10429b7d26471Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430629baa8cSmrg
104315ffd6003Smrg      # Create the old-style object.
10432b7d26471Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433145b7b3cSmrg
10434b7d26471Smrg      output=$obj
104355ffd6003Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436145b7b3cSmrg
104375ffd6003Smrg      # Exit if we aren't doing a library object file.
104385ffd6003Smrg      if test -z "$libobj"; then
104395ffd6003Smrg	if test -n "$gentop"; then
104405ffd6003Smrg	  func_show_eval '${RM}r "$gentop"'
104415ffd6003Smrg	fi
104425ffd6003Smrg
104435ffd6003Smrg	exit $EXIT_SUCCESS
10444145b7b3cSmrg      fi
104455ffd6003Smrg
10446b7d26471Smrg      test yes = "$build_libtool_libs" || {
104475ffd6003Smrg	if test -n "$gentop"; then
104485ffd6003Smrg	  func_show_eval '${RM}r "$gentop"'
104495ffd6003Smrg	fi
104505ffd6003Smrg
104515ffd6003Smrg	# Create an invalid libtool object if no PIC, so that we don't
104525ffd6003Smrg	# accidentally link it into a program.
104535ffd6003Smrg	# $show "echo timestamp > $libobj"
104545ffd6003Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
104555ffd6003Smrg	exit $EXIT_SUCCESS
10456b7d26471Smrg      }
104575ffd6003Smrg
10458b7d26471Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
104595ffd6003Smrg	# Only do commands if we really have different PIC objects.
104605ffd6003Smrg	reload_objs="$libobjs $reload_conv_objs"
10461b7d26471Smrg	output=$libobj
104625ffd6003Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
104635ffd6003Smrg      fi
104645ffd6003Smrg
104655ffd6003Smrg      if test -n "$gentop"; then
104665ffd6003Smrg	func_show_eval '${RM}r "$gentop"'
104675ffd6003Smrg      fi
104685ffd6003Smrg
104695ffd6003Smrg      exit $EXIT_SUCCESS
10470145b7b3cSmrg      ;;
10471145b7b3cSmrg
104725ffd6003Smrg    prog)
104735ffd6003Smrg      case $host in
104745ffd6003Smrg	*cygwin*) func_stripname '' '.exe' "$output"
104755ffd6003Smrg	          output=$func_stripname_result.exe;;
104765ffd6003Smrg      esac
104775ffd6003Smrg      test -n "$vinfo" && \
10478b7d26471Smrg	func_warning "'-version-info' is ignored for programs"
10479145b7b3cSmrg
104805ffd6003Smrg      test -n "$release" && \
10481b7d26471Smrg	func_warning "'-release' is ignored for programs"
10482145b7b3cSmrg
10483b7d26471Smrg      $preload \
10484b7d26471Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485b7d26471Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
104865ffd6003Smrg
104875ffd6003Smrg      case $host in
104885ffd6003Smrg      *-*-rhapsody* | *-*-darwin1.[012])
104895ffd6003Smrg	# On Rhapsody replace the C library is the System framework
10490629baa8cSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10491629baa8cSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492145b7b3cSmrg	;;
104935ffd6003Smrg      esac
10494145b7b3cSmrg
104955ffd6003Smrg      case $host in
104965ffd6003Smrg      *-*-darwin*)
104975ffd6003Smrg	# Don't allow lazy linking, it breaks C++ global constructors
104985ffd6003Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10499b7d26471Smrg	if test CXX = "$tagname"; then
105005ffd6003Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
105015ffd6003Smrg	    10.[0123])
10502b7d26471Smrg	      func_append compile_command " $wl-bind_at_load"
10503b7d26471Smrg	      func_append finalize_command " $wl-bind_at_load"
105045ffd6003Smrg	    ;;
105055ffd6003Smrg	  esac
10506145b7b3cSmrg	fi
105075ffd6003Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10508629baa8cSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10509629baa8cSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
105105ffd6003Smrg	;;
105115ffd6003Smrg      esac
10512145b7b3cSmrg
10513145b7b3cSmrg
105145ffd6003Smrg      # move library search paths that coincide with paths to not yet
105155ffd6003Smrg      # installed libraries to the beginning of the library search list
105165ffd6003Smrg      new_libs=
105175ffd6003Smrg      for path in $notinst_path; do
105185ffd6003Smrg	case " $new_libs " in
105195ffd6003Smrg	*" -L$path/$objdir "*) ;;
105205ffd6003Smrg	*)
105215ffd6003Smrg	  case " $compile_deplibs " in
105225ffd6003Smrg	  *" -L$path/$objdir "*)
10523629baa8cSmrg	    func_append new_libs " -L$path/$objdir" ;;
10524145b7b3cSmrg	  esac
105255ffd6003Smrg	  ;;
105265ffd6003Smrg	esac
105275ffd6003Smrg      done
105285ffd6003Smrg      for deplib in $compile_deplibs; do
105295ffd6003Smrg	case $deplib in
105305ffd6003Smrg	-L*)
105315ffd6003Smrg	  case " $new_libs " in
105325ffd6003Smrg	  *" $deplib "*) ;;
10533629baa8cSmrg	  *) func_append new_libs " $deplib" ;;
10534145b7b3cSmrg	  esac
105355ffd6003Smrg	  ;;
10536629baa8cSmrg	*) func_append new_libs " $deplib" ;;
105375ffd6003Smrg	esac
105385ffd6003Smrg      done
10539b7d26471Smrg      compile_deplibs=$new_libs
10540145b7b3cSmrg
10541145b7b3cSmrg
10542629baa8cSmrg      func_append compile_command " $compile_deplibs"
10543629baa8cSmrg      func_append finalize_command " $finalize_deplibs"
10544145b7b3cSmrg
105455ffd6003Smrg      if test -n "$rpath$xrpath"; then
105465ffd6003Smrg	# If the user specified any rpath flags, then add them.
105475ffd6003Smrg	for libdir in $rpath $xrpath; do
105485ffd6003Smrg	  # This is the magic to use -rpath.
105495ffd6003Smrg	  case "$finalize_rpath " in
105505ffd6003Smrg	  *" $libdir "*) ;;
10551629baa8cSmrg	  *) func_append finalize_rpath " $libdir" ;;
105525ffd6003Smrg	  esac
105535ffd6003Smrg	done
105545ffd6003Smrg      fi
10555145b7b3cSmrg
105565ffd6003Smrg      # Now hardcode the library paths
105575ffd6003Smrg      rpath=
105585ffd6003Smrg      hardcode_libdirs=
105595ffd6003Smrg      for libdir in $compile_rpath $finalize_rpath; do
105605ffd6003Smrg	if test -n "$hardcode_libdir_flag_spec"; then
105615ffd6003Smrg	  if test -n "$hardcode_libdir_separator"; then
105625ffd6003Smrg	    if test -z "$hardcode_libdirs"; then
10563b7d26471Smrg	      hardcode_libdirs=$libdir
105645ffd6003Smrg	    else
105655ffd6003Smrg	      # Just accumulate the unique libdirs.
105665ffd6003Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
105675ffd6003Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
105685ffd6003Smrg		;;
105695ffd6003Smrg	      *)
10570629baa8cSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
105715ffd6003Smrg		;;
105725ffd6003Smrg	      esac
105735ffd6003Smrg	    fi
10574145b7b3cSmrg	  else
105755ffd6003Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10576629baa8cSmrg	    func_append rpath " $flag"
10577145b7b3cSmrg	  fi
105785ffd6003Smrg	elif test -n "$runpath_var"; then
105795ffd6003Smrg	  case "$perm_rpath " in
105805ffd6003Smrg	  *" $libdir "*) ;;
10581629baa8cSmrg	  *) func_append perm_rpath " $libdir" ;;
105825ffd6003Smrg	  esac
105835ffd6003Smrg	fi
105845ffd6003Smrg	case $host in
105855ffd6003Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586b7d26471Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
105875ffd6003Smrg	  case :$dllsearchpath: in
105885ffd6003Smrg	  *":$libdir:"*) ;;
105895ffd6003Smrg	  ::) dllsearchpath=$libdir;;
10590629baa8cSmrg	  *) func_append dllsearchpath ":$libdir";;
105915ffd6003Smrg	  esac
105925ffd6003Smrg	  case :$dllsearchpath: in
105935ffd6003Smrg	  *":$testbindir:"*) ;;
105945ffd6003Smrg	  ::) dllsearchpath=$testbindir;;
10595629baa8cSmrg	  *) func_append dllsearchpath ":$testbindir";;
105965ffd6003Smrg	  esac
105975ffd6003Smrg	  ;;
105985ffd6003Smrg	esac
105995ffd6003Smrg      done
106005ffd6003Smrg      # Substitute the hardcoded libdirs into the rpath.
106015ffd6003Smrg      if test -n "$hardcode_libdir_separator" &&
106025ffd6003Smrg	 test -n "$hardcode_libdirs"; then
10603b7d26471Smrg	libdir=$hardcode_libdirs
106045ffd6003Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106055ffd6003Smrg      fi
10606b7d26471Smrg      compile_rpath=$rpath
10607145b7b3cSmrg
106085ffd6003Smrg      rpath=
106095ffd6003Smrg      hardcode_libdirs=
106105ffd6003Smrg      for libdir in $finalize_rpath; do
106115ffd6003Smrg	if test -n "$hardcode_libdir_flag_spec"; then
106125ffd6003Smrg	  if test -n "$hardcode_libdir_separator"; then
106135ffd6003Smrg	    if test -z "$hardcode_libdirs"; then
10614b7d26471Smrg	      hardcode_libdirs=$libdir
106155ffd6003Smrg	    else
106165ffd6003Smrg	      # Just accumulate the unique libdirs.
106175ffd6003Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
106185ffd6003Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
106195ffd6003Smrg		;;
106205ffd6003Smrg	      *)
10621629baa8cSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
106225ffd6003Smrg		;;
106235ffd6003Smrg	      esac
106245ffd6003Smrg	    fi
10625145b7b3cSmrg	  else
106265ffd6003Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10627629baa8cSmrg	    func_append rpath " $flag"
10628145b7b3cSmrg	  fi
106295ffd6003Smrg	elif test -n "$runpath_var"; then
106305ffd6003Smrg	  case "$finalize_perm_rpath " in
106315ffd6003Smrg	  *" $libdir "*) ;;
10632629baa8cSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
106335ffd6003Smrg	  esac
10634145b7b3cSmrg	fi
106355ffd6003Smrg      done
106365ffd6003Smrg      # Substitute the hardcoded libdirs into the rpath.
106375ffd6003Smrg      if test -n "$hardcode_libdir_separator" &&
106385ffd6003Smrg	 test -n "$hardcode_libdirs"; then
10639b7d26471Smrg	libdir=$hardcode_libdirs
106405ffd6003Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
106415ffd6003Smrg      fi
10642b7d26471Smrg      finalize_rpath=$rpath
10643145b7b3cSmrg
10644b7d26471Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
106455ffd6003Smrg	# Transform all the library objects into standard objects.
10646629baa8cSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10647629baa8cSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
106485ffd6003Smrg      fi
10649145b7b3cSmrg
10650b7d26471Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10651145b7b3cSmrg
106525ffd6003Smrg      # template prelinking step
106535ffd6003Smrg      if test -n "$prelink_cmds"; then
106545ffd6003Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
106555ffd6003Smrg      fi
10656145b7b3cSmrg
10657b7d26471Smrg      wrappers_required=:
106585ffd6003Smrg      case $host in
10659629baa8cSmrg      *cegcc* | *mingw32ce*)
10660629baa8cSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661b7d26471Smrg        wrappers_required=false
10662629baa8cSmrg        ;;
106635ffd6003Smrg      *cygwin* | *mingw* )
10664b7d26471Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
106655ffd6003Smrg        ;;
106665ffd6003Smrg      *)
10667b7d26471Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668b7d26471Smrg          wrappers_required=false
106695ffd6003Smrg        fi
106705ffd6003Smrg        ;;
106715ffd6003Smrg      esac
10672b7d26471Smrg      $wrappers_required || {
106735ffd6003Smrg	# Replace the output file specification.
10674629baa8cSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675b7d26471Smrg	link_command=$compile_command$compile_rpath
10676145b7b3cSmrg
106775ffd6003Smrg	# We have no uninstalled library dependencies, so finalize right now.
106785ffd6003Smrg	exit_status=0
106795ffd6003Smrg	func_show_eval "$link_command" 'exit_status=$?'
10680145b7b3cSmrg
10681629baa8cSmrg	if test -n "$postlink_cmds"; then
10682629baa8cSmrg	  func_to_tool_file "$output"
10683629baa8cSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10684629baa8cSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10685629baa8cSmrg	fi
10686629baa8cSmrg
106875ffd6003Smrg	# Delete the generated files.
10688b7d26471Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689b7d26471Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10690145b7b3cSmrg	fi
10691145b7b3cSmrg
106925ffd6003Smrg	exit $exit_status
10693b7d26471Smrg      }
10694145b7b3cSmrg
106955ffd6003Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
106965ffd6003Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
106975ffd6003Smrg      fi
106985ffd6003Smrg      if test -n "$finalize_shlibpath"; then
106995ffd6003Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
107005ffd6003Smrg      fi
10701145b7b3cSmrg
107025ffd6003Smrg      compile_var=
107035ffd6003Smrg      finalize_var=
107045ffd6003Smrg      if test -n "$runpath_var"; then
107055ffd6003Smrg	if test -n "$perm_rpath"; then
107065ffd6003Smrg	  # We should set the runpath_var.
107075ffd6003Smrg	  rpath=
107085ffd6003Smrg	  for dir in $perm_rpath; do
10709629baa8cSmrg	    func_append rpath "$dir:"
107105ffd6003Smrg	  done
107115ffd6003Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10712145b7b3cSmrg	fi
107135ffd6003Smrg	if test -n "$finalize_perm_rpath"; then
107145ffd6003Smrg	  # We should set the runpath_var.
107155ffd6003Smrg	  rpath=
107165ffd6003Smrg	  for dir in $finalize_perm_rpath; do
10717629baa8cSmrg	    func_append rpath "$dir:"
107185ffd6003Smrg	  done
107195ffd6003Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10720145b7b3cSmrg	fi
107215ffd6003Smrg      fi
10722145b7b3cSmrg
10723b7d26471Smrg      if test yes = "$no_install"; then
107245ffd6003Smrg	# We don't need to create a wrapper script.
10725b7d26471Smrg	link_command=$compile_var$compile_command$compile_rpath
107265ffd6003Smrg	# Replace the output file specification.
10727629baa8cSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
107285ffd6003Smrg	# Delete the old output file.
107295ffd6003Smrg	$opt_dry_run || $RM $output
107305ffd6003Smrg	# Link the executable and exit
107315ffd6003Smrg	func_show_eval "$link_command" 'exit $?'
10732629baa8cSmrg
10733629baa8cSmrg	if test -n "$postlink_cmds"; then
10734629baa8cSmrg	  func_to_tool_file "$output"
10735629baa8cSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10736629baa8cSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737629baa8cSmrg	fi
10738629baa8cSmrg
10739145b7b3cSmrg	exit $EXIT_SUCCESS
107405ffd6003Smrg      fi
10741145b7b3cSmrg
10742b7d26471Smrg      case $hardcode_action,$fast_install in
10743b7d26471Smrg        relink,*)
10744b7d26471Smrg	  # Fast installation is not supported
10745b7d26471Smrg	  link_command=$compile_var$compile_command$compile_rpath
10746b7d26471Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
107475ffd6003Smrg
10748b7d26471Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10749b7d26471Smrg	  func_warning "'$output' will be relinked during installation"
10750b7d26471Smrg	  ;;
10751b7d26471Smrg        *,yes)
10752b7d26471Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753b7d26471Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754b7d26471Smrg          ;;
10755b7d26471Smrg	*,no)
10756b7d26471Smrg	  link_command=$compile_var$compile_command$compile_rpath
10757b7d26471Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758b7d26471Smrg          ;;
10759b7d26471Smrg	*,needless)
10760b7d26471Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761b7d26471Smrg	  relink_command=
10762b7d26471Smrg          ;;
10763b7d26471Smrg      esac
10764145b7b3cSmrg
107655ffd6003Smrg      # Replace the output file specification.
10766629baa8cSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10767145b7b3cSmrg
107685ffd6003Smrg      # Delete the old output files.
107695ffd6003Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10770145b7b3cSmrg
107715ffd6003Smrg      func_show_eval "$link_command" 'exit $?'
10772145b7b3cSmrg
10773629baa8cSmrg      if test -n "$postlink_cmds"; then
10774629baa8cSmrg	func_to_tool_file "$output_objdir/$outputname"
10775629baa8cSmrg	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'`
10776629baa8cSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10777629baa8cSmrg      fi
10778629baa8cSmrg
107795ffd6003Smrg      # Now create the wrapper script.
107805ffd6003Smrg      func_verbose "creating $output"
10781145b7b3cSmrg
107825ffd6003Smrg      # Quote the relink command for shipping.
107835ffd6003Smrg      if test -n "$relink_command"; then
107845ffd6003Smrg	# Preserve any variables that may affect compiler behavior
107855ffd6003Smrg	for var in $variables_saved_for_relink; do
107865ffd6003Smrg	  if eval test -z \"\${$var+set}\"; then
107875ffd6003Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
107885ffd6003Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
107895ffd6003Smrg	    relink_command="$var=; export $var; $relink_command"
10790145b7b3cSmrg	  else
10791da2e2ef6Smrg	    func_quote_arg pretty "$var_value"
10792da2e2ef6Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10793145b7b3cSmrg	  fi
107945ffd6003Smrg	done
10795da2e2ef6Smrg	func_quote eval cd "`pwd`"
10796da2e2ef6Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797da2e2ef6Smrg	relink_command=$func_quote_arg_unquoted_result
107985ffd6003Smrg      fi
107995ffd6003Smrg
108005ffd6003Smrg      # Only actually do things if not in dry run mode.
108015ffd6003Smrg      $opt_dry_run || {
108025ffd6003Smrg	# win32 will think the script is a binary if it has
108035ffd6003Smrg	# a .exe suffix, so we strip it off here.
108045ffd6003Smrg	case $output in
108055ffd6003Smrg	  *.exe) func_stripname '' '.exe' "$output"
108065ffd6003Smrg	         output=$func_stripname_result ;;
108075ffd6003Smrg	esac
108085ffd6003Smrg	# test for cygwin because mv fails w/o .exe extensions
108095ffd6003Smrg	case $host in
108105ffd6003Smrg	  *cygwin*)
108115ffd6003Smrg	    exeext=.exe
108125ffd6003Smrg	    func_stripname '' '.exe' "$outputname"
108135ffd6003Smrg	    outputname=$func_stripname_result ;;
108145ffd6003Smrg	  *) exeext= ;;
10815145b7b3cSmrg	esac
108165ffd6003Smrg	case $host in
108175ffd6003Smrg	  *cygwin* | *mingw* )
108185ffd6003Smrg	    func_dirname_and_basename "$output" "" "."
108195ffd6003Smrg	    output_name=$func_basename_result
108205ffd6003Smrg	    output_path=$func_dirname_result
10821b7d26471Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822b7d26471Smrg	    cwrapper=$output_path/$output_name.exe
108235ffd6003Smrg	    $RM $cwrappersource $cwrapper
108245ffd6003Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
108255ffd6003Smrg
108265ffd6003Smrg	    func_emit_cwrapperexe_src > $cwrappersource
108275ffd6003Smrg
108285ffd6003Smrg	    # The wrapper executable is built using the $host compiler,
108295ffd6003Smrg	    # because it contains $host paths and files. If cross-
108305ffd6003Smrg	    # compiling, it, like the target executable, must be
108315ffd6003Smrg	    # executed on the $host or under an emulation environment.
108325ffd6003Smrg	    $opt_dry_run || {
108335ffd6003Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
108345ffd6003Smrg	      $STRIP $cwrapper
108355ffd6003Smrg	    }
10836145b7b3cSmrg
108375ffd6003Smrg	    # Now, create the wrapper script for func_source use:
108385ffd6003Smrg	    func_ltwrapper_scriptname $cwrapper
108395ffd6003Smrg	    $RM $func_ltwrapper_scriptname_result
108405ffd6003Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
108415ffd6003Smrg	    $opt_dry_run || {
108425ffd6003Smrg	      # note: this script will not be executed, so do not chmod.
10843b7d26471Smrg	      if test "x$build" = "x$host"; then
108445ffd6003Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
108455ffd6003Smrg	      else
108465ffd6003Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
108475ffd6003Smrg	      fi
108485ffd6003Smrg	    }
108495ffd6003Smrg	  ;;
108505ffd6003Smrg	  * )
108515ffd6003Smrg	    $RM $output
108525ffd6003Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10853145b7b3cSmrg
108545ffd6003Smrg	    func_emit_wrapper no > $output
108555ffd6003Smrg	    chmod +x $output
108565ffd6003Smrg	  ;;
108575ffd6003Smrg	esac
108585ffd6003Smrg      }
108595ffd6003Smrg      exit $EXIT_SUCCESS
108605ffd6003Smrg      ;;
108615ffd6003Smrg    esac
10862145b7b3cSmrg
108635ffd6003Smrg    # See if we need to build an old-fashioned archive.
108645ffd6003Smrg    for oldlib in $oldlibs; do
10865145b7b3cSmrg
10866b7d26471Smrg      case $build_libtool_libs in
10867b7d26471Smrg        convenience)
10868b7d26471Smrg	  oldobjs="$libobjs_save $symfileobj"
10869b7d26471Smrg	  addlibs=$convenience
108705ffd6003Smrg	  build_libtool_libs=no
10871b7d26471Smrg	  ;;
10872b7d26471Smrg	module)
10873b7d26471Smrg	  oldobjs=$libobjs_save
10874b7d26471Smrg	  addlibs=$old_convenience
10875b7d26471Smrg	  build_libtool_libs=no
10876b7d26471Smrg          ;;
10877b7d26471Smrg	*)
108785ffd6003Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10879b7d26471Smrg	  $preload && test -f "$symfileobj" \
10880b7d26471Smrg	    && func_append oldobjs " $symfileobj"
10881b7d26471Smrg	  addlibs=$old_convenience
10882b7d26471Smrg	  ;;
10883b7d26471Smrg      esac
10884145b7b3cSmrg
108855ffd6003Smrg      if test -n "$addlibs"; then
10886b7d26471Smrg	gentop=$output_objdir/${outputname}x
10887629baa8cSmrg	func_append generated " $gentop"
10888145b7b3cSmrg
108895ffd6003Smrg	func_extract_archives $gentop $addlibs
10890629baa8cSmrg	func_append oldobjs " $func_extract_archives_result"
108915ffd6003Smrg      fi
10892145b7b3cSmrg
108935ffd6003Smrg      # Do each command in the archive commands.
10894b7d26471Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
108955ffd6003Smrg	cmds=$old_archive_from_new_cmds
108965ffd6003Smrg      else
10897145b7b3cSmrg
108985ffd6003Smrg	# Add any objects from preloaded convenience libraries
108995ffd6003Smrg	if test -n "$dlprefiles"; then
10900b7d26471Smrg	  gentop=$output_objdir/${outputname}x
10901629baa8cSmrg	  func_append generated " $gentop"
10902145b7b3cSmrg
109035ffd6003Smrg	  func_extract_archives $gentop $dlprefiles
10904629baa8cSmrg	  func_append oldobjs " $func_extract_archives_result"
109055ffd6003Smrg	fi
10906145b7b3cSmrg
109075ffd6003Smrg	# POSIX demands no paths to be encoded in archives.  We have
109085ffd6003Smrg	# to avoid creating archives with duplicate basenames if we
109095ffd6003Smrg	# might have to extract them afterwards, e.g., when creating a
109105ffd6003Smrg	# static archive out of a convenience library, or when linking
109115ffd6003Smrg	# the entirety of a libtool archive into another (currently
109125ffd6003Smrg	# not supported by libtool).
109135ffd6003Smrg	if (for obj in $oldobjs
109145ffd6003Smrg	    do
109155ffd6003Smrg	      func_basename "$obj"
109165ffd6003Smrg	      $ECHO "$func_basename_result"
109175ffd6003Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
109185ffd6003Smrg	  :
109195ffd6003Smrg	else
10920629baa8cSmrg	  echo "copying selected object files to avoid basename conflicts..."
10921b7d26471Smrg	  gentop=$output_objdir/${outputname}x
10922629baa8cSmrg	  func_append generated " $gentop"
109235ffd6003Smrg	  func_mkdir_p "$gentop"
109245ffd6003Smrg	  save_oldobjs=$oldobjs
109255ffd6003Smrg	  oldobjs=
109265ffd6003Smrg	  counter=1
109275ffd6003Smrg	  for obj in $save_oldobjs
109285ffd6003Smrg	  do
109295ffd6003Smrg	    func_basename "$obj"
10930b7d26471Smrg	    objbase=$func_basename_result
109315ffd6003Smrg	    case " $oldobjs " in
109325ffd6003Smrg	    " ") oldobjs=$obj ;;
109335ffd6003Smrg	    *[\ /]"$objbase "*)
109345ffd6003Smrg	      while :; do
109355ffd6003Smrg		# Make sure we don't pick an alternate name that also
109365ffd6003Smrg		# overlaps.
109375ffd6003Smrg		newobj=lt$counter-$objbase
109385ffd6003Smrg		func_arith $counter + 1
109395ffd6003Smrg		counter=$func_arith_result
109405ffd6003Smrg		case " $oldobjs " in
109415ffd6003Smrg		*[\ /]"$newobj "*) ;;
109425ffd6003Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
109435ffd6003Smrg		esac
109445ffd6003Smrg	      done
109455ffd6003Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10946629baa8cSmrg	      func_append oldobjs " $gentop/$newobj"
109475ffd6003Smrg	      ;;
10948629baa8cSmrg	    *) func_append oldobjs " $obj" ;;
109495ffd6003Smrg	    esac
10950145b7b3cSmrg	  done
10951145b7b3cSmrg	fi
10952b7d26471Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953b7d26471Smrg	tool_oldlib=$func_to_tool_file_result
109545ffd6003Smrg	eval cmds=\"$old_archive_cmds\"
10955145b7b3cSmrg
109565ffd6003Smrg	func_len " $cmds"
109575ffd6003Smrg	len=$func_len_result
109585ffd6003Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
109595ffd6003Smrg	  cmds=$old_archive_cmds
10960629baa8cSmrg	elif test -n "$archiver_list_spec"; then
10961629baa8cSmrg	  func_verbose "using command file archive linking..."
10962629baa8cSmrg	  for obj in $oldobjs
10963629baa8cSmrg	  do
10964629baa8cSmrg	    func_to_tool_file "$obj"
10965629baa8cSmrg	    $ECHO "$func_to_tool_file_result"
10966629baa8cSmrg	  done > $output_objdir/$libname.libcmd
10967629baa8cSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10968629baa8cSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10969629baa8cSmrg	  cmds=$old_archive_cmds
109705ffd6003Smrg	else
109715ffd6003Smrg	  # the command line is too long to link in one step, link in parts
109725ffd6003Smrg	  func_verbose "using piecewise archive linking..."
109735ffd6003Smrg	  save_RANLIB=$RANLIB
109745ffd6003Smrg	  RANLIB=:
109755ffd6003Smrg	  objlist=
109765ffd6003Smrg	  concat_cmds=
109775ffd6003Smrg	  save_oldobjs=$oldobjs
109785ffd6003Smrg	  oldobjs=
109795ffd6003Smrg	  # Is there a better way of finding the last object in the list?
109805ffd6003Smrg	  for obj in $save_oldobjs
109815ffd6003Smrg	  do
109825ffd6003Smrg	    last_oldobj=$obj
109835ffd6003Smrg	  done
109845ffd6003Smrg	  eval test_cmds=\"$old_archive_cmds\"
109855ffd6003Smrg	  func_len " $test_cmds"
109865ffd6003Smrg	  len0=$func_len_result
109875ffd6003Smrg	  len=$len0
109885ffd6003Smrg	  for obj in $save_oldobjs
109895ffd6003Smrg	  do
109905ffd6003Smrg	    func_len " $obj"
109915ffd6003Smrg	    func_arith $len + $func_len_result
109925ffd6003Smrg	    len=$func_arith_result
109935ffd6003Smrg	    func_append objlist " $obj"
109945ffd6003Smrg	    if test "$len" -lt "$max_cmd_len"; then
109955ffd6003Smrg	      :
109965ffd6003Smrg	    else
109975ffd6003Smrg	      # the above command should be used before it gets too long
109985ffd6003Smrg	      oldobjs=$objlist
10999b7d26471Smrg	      if test "$obj" = "$last_oldobj"; then
110005ffd6003Smrg		RANLIB=$save_RANLIB
110015ffd6003Smrg	      fi
110025ffd6003Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003b7d26471Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
110045ffd6003Smrg	      objlist=
110055ffd6003Smrg	      len=$len0
110065ffd6003Smrg	    fi
110075ffd6003Smrg	  done
110085ffd6003Smrg	  RANLIB=$save_RANLIB
110095ffd6003Smrg	  oldobjs=$objlist
11010b7d26471Smrg	  if test -z "$oldobjs"; then
110115ffd6003Smrg	    eval cmds=\"\$concat_cmds\"
110125ffd6003Smrg	  else
110135ffd6003Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
110145ffd6003Smrg	  fi
110155ffd6003Smrg	fi
110165ffd6003Smrg      fi
110175ffd6003Smrg      func_execute_cmds "$cmds" 'exit $?'
11018145b7b3cSmrg    done
11019145b7b3cSmrg
110205ffd6003Smrg    test -n "$generated" && \
110215ffd6003Smrg      func_show_eval "${RM}r$generated"
11022145b7b3cSmrg
110235ffd6003Smrg    # Now create the libtool archive.
110245ffd6003Smrg    case $output in
110255ffd6003Smrg    *.la)
110265ffd6003Smrg      old_library=
11027b7d26471Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
110285ffd6003Smrg      func_verbose "creating $output"
11029145b7b3cSmrg
110305ffd6003Smrg      # Preserve any variables that may affect compiler behavior
110315ffd6003Smrg      for var in $variables_saved_for_relink; do
110325ffd6003Smrg	if eval test -z \"\${$var+set}\"; then
110335ffd6003Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
110345ffd6003Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
110355ffd6003Smrg	  relink_command="$var=; export $var; $relink_command"
11036145b7b3cSmrg	else
11037da2e2ef6Smrg	  func_quote_arg pretty,unquoted "$var_value"
11038da2e2ef6Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039145b7b3cSmrg	fi
110405ffd6003Smrg      done
110415ffd6003Smrg      # Quote the link command for shipping.
11042da2e2ef6Smrg      func_quote eval cd "`pwd`"
11043da2e2ef6Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044da2e2ef6Smrg      func_quote_arg pretty,unquoted "$relink_command"
11045da2e2ef6Smrg      relink_command=$func_quote_arg_unquoted_result
11046b7d26471Smrg      if test yes = "$hardcode_automatic"; then
110475ffd6003Smrg	relink_command=
110485ffd6003Smrg      fi
11049145b7b3cSmrg
110505ffd6003Smrg      # Only create the output if not a dry run.
110515ffd6003Smrg      $opt_dry_run || {
110525ffd6003Smrg	for installed in no yes; do
11053b7d26471Smrg	  if test yes = "$installed"; then
110545ffd6003Smrg	    if test -z "$install_libdir"; then
110555ffd6003Smrg	      break
110565ffd6003Smrg	    fi
11057b7d26471Smrg	    output=$output_objdir/${outputname}i
110585ffd6003Smrg	    # Replace all uninstalled libtool libraries with the installed ones
110595ffd6003Smrg	    newdependency_libs=
110605ffd6003Smrg	    for deplib in $dependency_libs; do
110615ffd6003Smrg	      case $deplib in
110625ffd6003Smrg	      *.la)
110635ffd6003Smrg		func_basename "$deplib"
11064b7d26471Smrg		name=$func_basename_result
11065b7d26471Smrg		func_resolve_sysroot "$deplib"
11066b7d26471Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
110675ffd6003Smrg		test -z "$libdir" && \
11068b7d26471Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11069629baa8cSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11070629baa8cSmrg		;;
11071629baa8cSmrg	      -L*)
11072629baa8cSmrg		func_stripname -L '' "$deplib"
11073629baa8cSmrg		func_replace_sysroot "$func_stripname_result"
11074629baa8cSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
110755ffd6003Smrg		;;
11076629baa8cSmrg	      -R*)
11077629baa8cSmrg		func_stripname -R '' "$deplib"
11078629baa8cSmrg		func_replace_sysroot "$func_stripname_result"
11079629baa8cSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080629baa8cSmrg		;;
11081629baa8cSmrg	      *) func_append newdependency_libs " $deplib" ;;
110825ffd6003Smrg	      esac
110835ffd6003Smrg	    done
11084b7d26471Smrg	    dependency_libs=$newdependency_libs
110855ffd6003Smrg	    newdlfiles=
110865ffd6003Smrg
110875ffd6003Smrg	    for lib in $dlfiles; do
110885ffd6003Smrg	      case $lib in
110895ffd6003Smrg	      *.la)
110905ffd6003Smrg	        func_basename "$lib"
11091b7d26471Smrg		name=$func_basename_result
11092b7d26471Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
110935ffd6003Smrg		test -z "$libdir" && \
11094b7d26471Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11095629baa8cSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
110965ffd6003Smrg		;;
11097629baa8cSmrg	      *) func_append newdlfiles " $lib" ;;
110985ffd6003Smrg	      esac
110995ffd6003Smrg	    done
11100b7d26471Smrg	    dlfiles=$newdlfiles
111015ffd6003Smrg	    newdlprefiles=
111025ffd6003Smrg	    for lib in $dlprefiles; do
111035ffd6003Smrg	      case $lib in
111045ffd6003Smrg	      *.la)
111055ffd6003Smrg		# Only pass preopened files to the pseudo-archive (for
111065ffd6003Smrg		# eventual linking with the app. that links it) if we
111075ffd6003Smrg		# didn't already link the preopened objects directly into
111085ffd6003Smrg		# the library:
111095ffd6003Smrg		func_basename "$lib"
11110b7d26471Smrg		name=$func_basename_result
11111b7d26471Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
111125ffd6003Smrg		test -z "$libdir" && \
11113b7d26471Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11114629baa8cSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
111155ffd6003Smrg		;;
111165ffd6003Smrg	      esac
111175ffd6003Smrg	    done
11118b7d26471Smrg	    dlprefiles=$newdlprefiles
111195ffd6003Smrg	  else
111205ffd6003Smrg	    newdlfiles=
111215ffd6003Smrg	    for lib in $dlfiles; do
111225ffd6003Smrg	      case $lib in
11123b7d26471Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111245ffd6003Smrg		*) abs=`pwd`"/$lib" ;;
111255ffd6003Smrg	      esac
11126629baa8cSmrg	      func_append newdlfiles " $abs"
111275ffd6003Smrg	    done
11128b7d26471Smrg	    dlfiles=$newdlfiles
111295ffd6003Smrg	    newdlprefiles=
111305ffd6003Smrg	    for lib in $dlprefiles; do
111315ffd6003Smrg	      case $lib in
11132b7d26471Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
111335ffd6003Smrg		*) abs=`pwd`"/$lib" ;;
111345ffd6003Smrg	      esac
11135629baa8cSmrg	      func_append newdlprefiles " $abs"
111365ffd6003Smrg	    done
11137b7d26471Smrg	    dlprefiles=$newdlprefiles
111385ffd6003Smrg	  fi
111395ffd6003Smrg	  $RM $output
111405ffd6003Smrg	  # place dlname in correct position for cygwin
11141629baa8cSmrg	  # In fact, it would be nice if we could use this code for all target
11142629baa8cSmrg	  # systems that can't hard-code library paths into their executables
11143629baa8cSmrg	  # and that have no shared library path variable independent of PATH,
11144629baa8cSmrg	  # but it turns out we can't easily determine that from inspecting
11145629baa8cSmrg	  # libtool variables, so we have to hard-code the OSs to which it
11146629baa8cSmrg	  # applies here; at the moment, that means platforms that use the PE
11147629baa8cSmrg	  # object format with DLL files.  See the long comment at the top of
11148629baa8cSmrg	  # tests/bindir.at for full details.
111495ffd6003Smrg	  tdlname=$dlname
111505ffd6003Smrg	  case $host,$output,$installed,$module,$dlname in
11151629baa8cSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11152629baa8cSmrg	      # If a -bindir argument was supplied, place the dll there.
11153b7d26471Smrg	      if test -n "$bindir"; then
11154629baa8cSmrg		func_relative_path "$install_libdir" "$bindir"
11155b7d26471Smrg		tdlname=$func_relative_path_result/$dlname
11156629baa8cSmrg	      else
11157629baa8cSmrg		# Otherwise fall back on heuristic.
11158629baa8cSmrg		tdlname=../bin/$dlname
11159629baa8cSmrg	      fi
11160629baa8cSmrg	      ;;
111615ffd6003Smrg	  esac
111625ffd6003Smrg	  $ECHO > $output "\
111635ffd6003Smrg# $outputname - a libtool library file
11164b7d26471Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
111655ffd6003Smrg#
111665ffd6003Smrg# Please DO NOT delete this file!
111675ffd6003Smrg# It is necessary for linking the library.
11168145b7b3cSmrg
111695ffd6003Smrg# The name that we can dlopen(3).
111705ffd6003Smrgdlname='$tdlname'
11171145b7b3cSmrg
111725ffd6003Smrg# Names of this library.
111735ffd6003Smrglibrary_names='$library_names'
11174145b7b3cSmrg
111755ffd6003Smrg# The name of the static archive.
111765ffd6003Smrgold_library='$old_library'
11177145b7b3cSmrg
11178b7d26471Smrg# Linker flags that cannot go in dependency_libs.
111795ffd6003Smrginherited_linker_flags='$new_inherited_linker_flags'
11180145b7b3cSmrg
111815ffd6003Smrg# Libraries that this one depends upon.
111825ffd6003Smrgdependency_libs='$dependency_libs'
11183145b7b3cSmrg
111845ffd6003Smrg# Names of additional weak libraries provided by this library
111855ffd6003Smrgweak_library_names='$weak_libs'
11186145b7b3cSmrg
111875ffd6003Smrg# Version information for $libname.
111885ffd6003Smrgcurrent=$current
111895ffd6003Smrgage=$age
111905ffd6003Smrgrevision=$revision
11191145b7b3cSmrg
111925ffd6003Smrg# Is this an already installed library?
111935ffd6003Smrginstalled=$installed
11194145b7b3cSmrg
111955ffd6003Smrg# Should we warn about portability when linking against -modules?
111965ffd6003Smrgshouldnotlink=$module
11197145b7b3cSmrg
111985ffd6003Smrg# Files to dlopen/dlpreopen
111995ffd6003Smrgdlopen='$dlfiles'
112005ffd6003Smrgdlpreopen='$dlprefiles'
11201145b7b3cSmrg
112025ffd6003Smrg# Directory that this library needs to be installed in:
112035ffd6003Smrglibdir='$install_libdir'"
11204b7d26471Smrg	  if test no,yes = "$installed,$need_relink"; then
112055ffd6003Smrg	    $ECHO >> $output "\
112065ffd6003Smrgrelink_command=\"$relink_command\""
112075ffd6003Smrg	  fi
112085ffd6003Smrg	done
112095ffd6003Smrg      }
11210145b7b3cSmrg
112115ffd6003Smrg      # Do a symbolic link so that the libtool archive can be found in
112125ffd6003Smrg      # LD_LIBRARY_PATH before the program is installed.
112135ffd6003Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
112145ffd6003Smrg      ;;
112155ffd6003Smrg    esac
112165ffd6003Smrg    exit $EXIT_SUCCESS
112175ffd6003Smrg}
11218145b7b3cSmrg
11219b7d26471Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220b7d26471Smrg  func_mode_link ${1+"$@"}
11221b7d26471Smrgfi
11222145b7b3cSmrg
11223145b7b3cSmrg
112245ffd6003Smrg# func_mode_uninstall arg...
112255ffd6003Smrgfunc_mode_uninstall ()
112265ffd6003Smrg{
11227b7d26471Smrg    $debug_cmd
11228b7d26471Smrg
11229b7d26471Smrg    RM=$nonopt
11230145b7b3cSmrg    files=
11231b7d26471Smrg    rmforce=false
11232145b7b3cSmrg    exit_status=0
11233145b7b3cSmrg
11234145b7b3cSmrg    # This variable tells wrapper scripts just to set variables rather
11235145b7b3cSmrg    # than running their programs.
11236b7d26471Smrg    libtool_install_magic=$magic
11237145b7b3cSmrg
11238145b7b3cSmrg    for arg
11239145b7b3cSmrg    do
11240145b7b3cSmrg      case $arg in
11241b7d26471Smrg      -f) func_append RM " $arg"; rmforce=: ;;
11242629baa8cSmrg      -*) func_append RM " $arg" ;;
11243629baa8cSmrg      *) func_append files " $arg" ;;
11244145b7b3cSmrg      esac
11245145b7b3cSmrg    done
11246145b7b3cSmrg
112475ffd6003Smrg    test -z "$RM" && \
112485ffd6003Smrg      func_fatal_help "you must specify an RM program"
11249145b7b3cSmrg
11250145b7b3cSmrg    rmdirs=
11251145b7b3cSmrg
11252145b7b3cSmrg    for file in $files; do
112535ffd6003Smrg      func_dirname "$file" "" "."
11254b7d26471Smrg      dir=$func_dirname_result
11255b7d26471Smrg      if test . = "$dir"; then
11256b7d26471Smrg	odir=$objdir
11257145b7b3cSmrg      else
11258b7d26471Smrg	odir=$dir/$objdir
11259145b7b3cSmrg      fi
112605ffd6003Smrg      func_basename "$file"
11261b7d26471Smrg      name=$func_basename_result
11262b7d26471Smrg      test uninstall = "$opt_mode" && odir=$dir
11263145b7b3cSmrg
11264629baa8cSmrg      # Remember odir for removal later, being careful to avoid duplicates
11265b7d26471Smrg      if test clean = "$opt_mode"; then
11266145b7b3cSmrg	case " $rmdirs " in
11267629baa8cSmrg	  *" $odir "*) ;;
11268629baa8cSmrg	  *) func_append rmdirs " $odir" ;;
11269145b7b3cSmrg	esac
11270145b7b3cSmrg      fi
11271145b7b3cSmrg
11272145b7b3cSmrg      # Don't error if the file doesn't exist and rm -f was used.
112735ffd6003Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
112745ffd6003Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
112755ffd6003Smrg	 test -f "$file"; then
11276145b7b3cSmrg	:
11277145b7b3cSmrg      elif test -d "$file"; then
11278145b7b3cSmrg	exit_status=1
11279145b7b3cSmrg	continue
11280b7d26471Smrg      elif $rmforce; then
11281145b7b3cSmrg	continue
11282145b7b3cSmrg      fi
11283145b7b3cSmrg
11284b7d26471Smrg      rmfiles=$file
11285145b7b3cSmrg
11286145b7b3cSmrg      case $name in
11287145b7b3cSmrg      *.la)
11288145b7b3cSmrg	# Possibly a libtool archive, so verify it.
112895ffd6003Smrg	if func_lalib_p "$file"; then
112905ffd6003Smrg	  func_source $dir/$name
11291145b7b3cSmrg
11292145b7b3cSmrg	  # Delete the libtool libraries and symlinks.
11293145b7b3cSmrg	  for n in $library_names; do
11294629baa8cSmrg	    func_append rmfiles " $odir/$n"
11295145b7b3cSmrg	  done
11296629baa8cSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11297145b7b3cSmrg
11298b7d26471Smrg	  case $opt_mode in
11299145b7b3cSmrg	  clean)
11300629baa8cSmrg	    case " $library_names " in
11301145b7b3cSmrg	    *" $dlname "*) ;;
11302629baa8cSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11303145b7b3cSmrg	    esac
11304629baa8cSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11305145b7b3cSmrg	    ;;
11306145b7b3cSmrg	  uninstall)
11307145b7b3cSmrg	    if test -n "$library_names"; then
11308145b7b3cSmrg	      # Do each command in the postuninstall commands.
11309b7d26471Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11310145b7b3cSmrg	    fi
11311145b7b3cSmrg
11312145b7b3cSmrg	    if test -n "$old_library"; then
11313145b7b3cSmrg	      # Do each command in the old_postuninstall commands.
11314b7d26471Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11315145b7b3cSmrg	    fi
11316145b7b3cSmrg	    # FIXME: should reinstall the best remaining shared library.
11317145b7b3cSmrg	    ;;
11318145b7b3cSmrg	  esac
11319145b7b3cSmrg	fi
11320145b7b3cSmrg	;;
11321145b7b3cSmrg
11322145b7b3cSmrg      *.lo)
11323145b7b3cSmrg	# Possibly a libtool object, so verify it.
113245ffd6003Smrg	if func_lalib_p "$file"; then
11325145b7b3cSmrg
11326145b7b3cSmrg	  # Read the .lo file
113275ffd6003Smrg	  func_source $dir/$name
11328145b7b3cSmrg
11329145b7b3cSmrg	  # Add PIC object to the list of files to remove.
11330b7d26471Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11331629baa8cSmrg	    func_append rmfiles " $dir/$pic_object"
11332145b7b3cSmrg	  fi
11333145b7b3cSmrg
11334145b7b3cSmrg	  # Add non-PIC object to the list of files to remove.
11335b7d26471Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11336629baa8cSmrg	    func_append rmfiles " $dir/$non_pic_object"
11337145b7b3cSmrg	  fi
11338145b7b3cSmrg	fi
11339145b7b3cSmrg	;;
11340145b7b3cSmrg
11341145b7b3cSmrg      *)
11342b7d26471Smrg	if test clean = "$opt_mode"; then
11343145b7b3cSmrg	  noexename=$name
11344145b7b3cSmrg	  case $file in
11345145b7b3cSmrg	  *.exe)
113465ffd6003Smrg	    func_stripname '' '.exe' "$file"
113475ffd6003Smrg	    file=$func_stripname_result
113485ffd6003Smrg	    func_stripname '' '.exe' "$name"
113495ffd6003Smrg	    noexename=$func_stripname_result
11350145b7b3cSmrg	    # $file with .exe has already been added to rmfiles,
11351145b7b3cSmrg	    # add $file without .exe
11352629baa8cSmrg	    func_append rmfiles " $file"
11353145b7b3cSmrg	    ;;
11354145b7b3cSmrg	  esac
11355145b7b3cSmrg	  # Do a test to see if this is a libtool program.
113565ffd6003Smrg	  if func_ltwrapper_p "$file"; then
113575ffd6003Smrg	    if func_ltwrapper_executable_p "$file"; then
113585ffd6003Smrg	      func_ltwrapper_scriptname "$file"
113595ffd6003Smrg	      relink_command=
113605ffd6003Smrg	      func_source $func_ltwrapper_scriptname_result
11361629baa8cSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
113625ffd6003Smrg	    else
113635ffd6003Smrg	      relink_command=
113645ffd6003Smrg	      func_source $dir/$noexename
113655ffd6003Smrg	    fi
11366145b7b3cSmrg
11367145b7b3cSmrg	    # note $name still contains .exe if it was in $file originally
11368145b7b3cSmrg	    # as does the version of $file that was added into $rmfiles
11369b7d26471Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370b7d26471Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11371629baa8cSmrg	      func_append rmfiles " $odir/lt-$name"
11372145b7b3cSmrg	    fi
11373b7d26471Smrg	    if test "X$noexename" != "X$name"; then
11374b7d26471Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11375145b7b3cSmrg	    fi
11376145b7b3cSmrg	  fi
11377145b7b3cSmrg	fi
11378145b7b3cSmrg	;;
11379145b7b3cSmrg      esac
113805ffd6003Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11381145b7b3cSmrg    done
11382145b7b3cSmrg
11383b7d26471Smrg    # Try to remove the $objdir's in the directories where we deleted files
11384145b7b3cSmrg    for dir in $rmdirs; do
11385145b7b3cSmrg      if test -d "$dir"; then
113865ffd6003Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11387145b7b3cSmrg      fi
11388145b7b3cSmrg    done
11389145b7b3cSmrg
11390145b7b3cSmrg    exit $exit_status
113915ffd6003Smrg}
11392145b7b3cSmrg
11393b7d26471Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394b7d26471Smrg  func_mode_uninstall ${1+"$@"}
11395b7d26471Smrgfi
11396145b7b3cSmrg
11397629baa8cSmrgtest -z "$opt_mode" && {
11398b7d26471Smrg  help=$generic_help
113995ffd6003Smrg  func_fatal_help "you must specify a MODE"
114005ffd6003Smrg}
114015ffd6003Smrg
114025ffd6003Smrgtest -z "$exec_cmd" && \
11403b7d26471Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11404145b7b3cSmrg
11405145b7b3cSmrgif test -n "$exec_cmd"; then
114065ffd6003Smrg  eval exec "$exec_cmd"
11407145b7b3cSmrg  exit $EXIT_FAILURE
11408145b7b3cSmrgfi
11409145b7b3cSmrg
114105ffd6003Smrgexit $exit_status
11411145b7b3cSmrg
11412145b7b3cSmrg
11413145b7b3cSmrg# The TAGs below are defined such that we never get into a situation
11414b7d26471Smrg# where we disable both kinds of libraries.  Given conflicting
11415145b7b3cSmrg# choices, we go for a static library, that is the most portable,
11416145b7b3cSmrg# since we can't tell whether shared libraries were disabled because
11417145b7b3cSmrg# the user asked for that or because the platform doesn't support
11418145b7b3cSmrg# them.  This is particularly important on AIX, because we don't
11419145b7b3cSmrg# support having both static and shared libraries enabled at the same
11420145b7b3cSmrg# time on that platform, so we default to a shared-only configuration.
11421145b7b3cSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11422145b7b3cSmrg# configuration.  But we'll never go from static-only to shared-only.
11423145b7b3cSmrg
11424145b7b3cSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
114255ffd6003Smrgbuild_libtool_libs=no
114265ffd6003Smrgbuild_old_libs=yes
11427145b7b3cSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11428145b7b3cSmrg
11429145b7b3cSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
114305ffd6003Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11431145b7b3cSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11432145b7b3cSmrg
11433145b7b3cSmrg# Local Variables:
11434145b7b3cSmrg# mode:shell-script
11435145b7b3cSmrg# sh-indentation:2
11436145b7b3cSmrg# End:
11437