ltmain.sh revision a3129944
1a3129944Smrg#! /bin/sh
2a3129944Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3a3129944Smrg##               by inline-source v2014-01-03.01
4698f425bSmrg
5a3129944Smrg# libtool (GNU libtool) 2.4.6
6a3129944Smrg# Provide generalized library-building support services.
7698f425bSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8698f425bSmrg
9a3129944Smrg# Copyright (C) 1996-2015 Free Software Foundation, Inc.
10698f425bSmrg# This is free software; see the source for copying conditions.  There is NO
11698f425bSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12698f425bSmrg
13698f425bSmrg# GNU Libtool is free software; you can redistribute it and/or modify
14266e564dSmrg# it under the terms of the GNU General Public License as published by
15266e564dSmrg# the Free Software Foundation; either version 2 of the License, or
16266e564dSmrg# (at your option) any later version.
17266e564dSmrg#
18698f425bSmrg# As a special exception to the GNU General Public License,
19698f425bSmrg# if you distribute this file as part of a program or library that
20698f425bSmrg# is built using GNU Libtool, you may include this file under the
21698f425bSmrg# same distribution terms that you use for the rest of that program.
22698f425bSmrg#
23698f425bSmrg# GNU Libtool is distributed in the hope that it will be useful, but
24266e564dSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25266e564dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26266e564dSmrg# General Public License for more details.
27266e564dSmrg#
28266e564dSmrg# You should have received a copy of the GNU General Public License
29a3129944Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30c5629e66Smrg
31266e564dSmrg
329ef0b394SmrgPROGRAM=libtool
33266e564dSmrgPACKAGE=libtool
34a3129944SmrgVERSION=2.4.6
35a3129944Smrgpackage_revision=2.4.6
36c5629e66Smrg
37a3129944Smrg
38a3129944Smrg## ------ ##
39a3129944Smrg## Usage. ##
40a3129944Smrg## ------ ##
41a3129944Smrg
42a3129944Smrg# Run './libtool --help' for help with using this script from the
43a3129944Smrg# command line.
44a3129944Smrg
45a3129944Smrg
46a3129944Smrg## ------------------------------- ##
47a3129944Smrg## User overridable command paths. ##
48a3129944Smrg## ------------------------------- ##
49a3129944Smrg
50a3129944Smrg# After configure completes, it has a better idea of some of the
51a3129944Smrg# shell tools we need than the defaults used by the functions shared
52a3129944Smrg# with bootstrap, so set those here where they can still be over-
53a3129944Smrg# ridden by the user, but otherwise take precedence.
54a3129944Smrg
55a3129944Smrg: ${AUTOCONF="autoconf"}
56a3129944Smrg: ${AUTOMAKE="automake"}
57a3129944Smrg
58a3129944Smrg
59a3129944Smrg## -------------------------- ##
60a3129944Smrg## Source external libraries. ##
61a3129944Smrg## -------------------------- ##
62a3129944Smrg
63a3129944Smrg# Much of our low-level functionality needs to be sourced from external
64a3129944Smrg# libraries, which are installed to $pkgauxdir.
65a3129944Smrg
66a3129944Smrg# Set a version string for this script.
67a3129944Smrgscriptversion=2015-01-20.17; # UTC
68a3129944Smrg
69a3129944Smrg# General shell script boiler plate, and helper functions.
70a3129944Smrg# Written by Gary V. Vaughan, 2004
71a3129944Smrg
72a3129944Smrg# Copyright (C) 2004-2015 Free Software Foundation, Inc.
73a3129944Smrg# This is free software; see the source for copying conditions.  There is NO
74a3129944Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75a3129944Smrg
76a3129944Smrg# This program is free software; you can redistribute it and/or modify
77a3129944Smrg# it under the terms of the GNU General Public License as published by
78a3129944Smrg# the Free Software Foundation; either version 3 of the License, or
79a3129944Smrg# (at your option) any later version.
80a3129944Smrg
81a3129944Smrg# As a special exception to the GNU General Public License, if you distribute
82a3129944Smrg# this file as part of a program or library that is built using GNU Libtool,
83a3129944Smrg# you may include this file under the same distribution terms that you use
84a3129944Smrg# for the rest of that program.
85a3129944Smrg
86a3129944Smrg# This program is distributed in the hope that it will be useful,
87a3129944Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
88a3129944Smrg# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
89a3129944Smrg# General Public License for more details.
90a3129944Smrg
91a3129944Smrg# You should have received a copy of the GNU General Public License
92a3129944Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>.
93a3129944Smrg
94a3129944Smrg# Please report bugs or propose patches to gary@gnu.org.
95a3129944Smrg
96a3129944Smrg
97a3129944Smrg## ------ ##
98a3129944Smrg## Usage. ##
99a3129944Smrg## ------ ##
100a3129944Smrg
101a3129944Smrg# Evaluate this file near the top of your script to gain access to
102a3129944Smrg# the functions and variables defined here:
103a3129944Smrg#
104a3129944Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
105a3129944Smrg#
106a3129944Smrg# If you need to override any of the default environment variable
107a3129944Smrg# settings, do that before evaluating this file.
108a3129944Smrg
109a3129944Smrg
110a3129944Smrg## -------------------- ##
111a3129944Smrg## Shell normalisation. ##
112a3129944Smrg## -------------------- ##
113a3129944Smrg
114a3129944Smrg# Some shells need a little help to be as Bourne compatible as possible.
115a3129944Smrg# Before doing anything else, make sure all that help has been provided!
116a3129944Smrg
117a3129944SmrgDUALCASE=1; export DUALCASE # for MKS sh
118a3129944Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
119c5629e66Smrg  emulate sh
120c5629e66Smrg  NULLCMD=:
121a3129944Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
122c5629e66Smrg  # is contrary to our usage.  Disable this feature.
123c5629e66Smrg  alias -g '${1+"$@"}'='"$@"'
124266e564dSmrg  setopt NO_GLOB_SUBST
125c5629e66Smrgelse
126a3129944Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
127266e564dSmrgfi
1289ef0b394Smrg
129a3129944Smrg# NLS nuisances: We save the old values in case they are required later.
130a3129944Smrg_G_user_locale=
131a3129944Smrg_G_safe_locale=
132a3129944Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
133c5629e66Smrgdo
134a3129944Smrg  eval "if test set = \"\${$_G_var+set}\"; then
135a3129944Smrg          save_$_G_var=\$$_G_var
136a3129944Smrg          $_G_var=C
137a3129944Smrg	  export $_G_var
138a3129944Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
139a3129944Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
140c5629e66Smrg	fi"
141c5629e66Smrgdone
142c5629e66Smrg
143a3129944Smrg# CDPATH.
144a3129944Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
145698f425bSmrg
146a3129944Smrg# Make sure IFS has a sensible default
147a3129944Smrgsp=' '
148a3129944Smrgnl='
149a3129944Smrg'
150a3129944SmrgIFS="$sp	$nl"
151a3129944Smrg
152a3129944Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
153a3129944Smrgif test "${PATH_SEPARATOR+set}" != set; then
154a3129944Smrg  PATH_SEPARATOR=:
155a3129944Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
156a3129944Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
157a3129944Smrg      PATH_SEPARATOR=';'
158a3129944Smrg  }
159a3129944Smrgfi
160698f425bSmrg
161698f425bSmrg
162698f425bSmrg
163a3129944Smrg## ------------------------- ##
164a3129944Smrg## Locate command utilities. ##
165a3129944Smrg## ------------------------- ##
166a3129944Smrg
167a3129944Smrg
168a3129944Smrg# func_executable_p FILE
169a3129944Smrg# ----------------------
170a3129944Smrg# Check that FILE is an executable regular file.
171a3129944Smrgfunc_executable_p ()
172a3129944Smrg{
173a3129944Smrg    test -f "$1" && test -x "$1"
174a3129944Smrg}
175a3129944Smrg
176a3129944Smrg
177a3129944Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
178a3129944Smrg# --------------------------------------------
179a3129944Smrg# Search for either a program that responds to --version with output
180a3129944Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
181a3129944Smrg# trying all the directories in PATH with each of the elements of
182a3129944Smrg# PROGS_LIST.
183a3129944Smrg#
184a3129944Smrg# CHECK_FUNC should accept the path to a candidate program, and
185a3129944Smrg# set $func_check_prog_result if it truncates its output less than
186a3129944Smrg# $_G_path_prog_max characters.
187a3129944Smrgfunc_path_progs ()
188a3129944Smrg{
189a3129944Smrg    _G_progs_list=$1
190a3129944Smrg    _G_check_func=$2
191a3129944Smrg    _G_PATH=${3-"$PATH"}
192a3129944Smrg
193a3129944Smrg    _G_path_prog_max=0
194a3129944Smrg    _G_path_prog_found=false
195a3129944Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
196a3129944Smrg    for _G_dir in $_G_PATH; do
197a3129944Smrg      IFS=$_G_save_IFS
198a3129944Smrg      test -z "$_G_dir" && _G_dir=.
199a3129944Smrg      for _G_prog_name in $_G_progs_list; do
200a3129944Smrg        for _exeext in '' .EXE; do
201a3129944Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
202a3129944Smrg          func_executable_p "$_G_path_prog" || continue
203a3129944Smrg          case `"$_G_path_prog" --version 2>&1` in
204a3129944Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
205a3129944Smrg            *)     $_G_check_func $_G_path_prog
206a3129944Smrg		   func_path_progs_result=$func_check_prog_result
207a3129944Smrg		   ;;
208a3129944Smrg          esac
209a3129944Smrg          $_G_path_prog_found && break 3
210a3129944Smrg        done
211a3129944Smrg      done
212a3129944Smrg    done
213a3129944Smrg    IFS=$_G_save_IFS
214a3129944Smrg    test -z "$func_path_progs_result" && {
215a3129944Smrg      echo "no acceptable sed could be found in \$PATH" >&2
216a3129944Smrg      exit 1
217a3129944Smrg    }
218a3129944Smrg}
219a3129944Smrg
220a3129944Smrg
221a3129944Smrg# We want to be able to use the functions in this file before configure
222a3129944Smrg# has figured out where the best binaries are kept, which means we have
223a3129944Smrg# to search for them ourselves - except when the results are already set
224a3129944Smrg# where we skip the searches.
225a3129944Smrg
226a3129944Smrg# Unless the user overrides by setting SED, search the path for either GNU
227a3129944Smrg# sed, or the sed that truncates its output the least.
228a3129944Smrgtest -z "$SED" && {
229a3129944Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
230a3129944Smrg  for _G_i in 1 2 3 4 5 6 7; do
231a3129944Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
232a3129944Smrg  done
233a3129944Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
234a3129944Smrg  _G_sed_script=
235a3129944Smrg
236a3129944Smrg  func_check_prog_sed ()
237a3129944Smrg  {
238a3129944Smrg    _G_path_prog=$1
239a3129944Smrg
240a3129944Smrg    _G_count=0
241a3129944Smrg    printf 0123456789 >conftest.in
242a3129944Smrg    while :
243a3129944Smrg    do
244a3129944Smrg      cat conftest.in conftest.in >conftest.tmp
245a3129944Smrg      mv conftest.tmp conftest.in
246a3129944Smrg      cp conftest.in conftest.nl
247a3129944Smrg      echo '' >> conftest.nl
248a3129944Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
249a3129944Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
250a3129944Smrg      _G_count=`expr $_G_count + 1`
251a3129944Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
252a3129944Smrg        # Best one so far, save it but keep looking for a better one
253a3129944Smrg        func_check_prog_result=$_G_path_prog
254a3129944Smrg        _G_path_prog_max=$_G_count
255a3129944Smrg      fi
256a3129944Smrg      # 10*(2^10) chars as input seems more than enough
257a3129944Smrg      test 10 -lt "$_G_count" && break
258a3129944Smrg    done
259a3129944Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
260a3129944Smrg  }
261a3129944Smrg
262a3129944Smrg  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
263a3129944Smrg  rm -f conftest.sed
264a3129944Smrg  SED=$func_path_progs_result
265a3129944Smrg}
266a3129944Smrg
267a3129944Smrg
268a3129944Smrg# Unless the user overrides by setting GREP, search the path for either GNU
269a3129944Smrg# grep, or the grep that truncates its output the least.
270a3129944Smrgtest -z "$GREP" && {
271a3129944Smrg  func_check_prog_grep ()
272a3129944Smrg  {
273a3129944Smrg    _G_path_prog=$1
274a3129944Smrg
275a3129944Smrg    _G_count=0
276a3129944Smrg    _G_path_prog_max=0
277a3129944Smrg    printf 0123456789 >conftest.in
278a3129944Smrg    while :
279a3129944Smrg    do
280a3129944Smrg      cat conftest.in conftest.in >conftest.tmp
281a3129944Smrg      mv conftest.tmp conftest.in
282a3129944Smrg      cp conftest.in conftest.nl
283a3129944Smrg      echo 'GREP' >> conftest.nl
284a3129944Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
285a3129944Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
286a3129944Smrg      _G_count=`expr $_G_count + 1`
287a3129944Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
288a3129944Smrg        # Best one so far, save it but keep looking for a better one
289a3129944Smrg        func_check_prog_result=$_G_path_prog
290a3129944Smrg        _G_path_prog_max=$_G_count
291a3129944Smrg      fi
292a3129944Smrg      # 10*(2^10) chars as input seems more than enough
293a3129944Smrg      test 10 -lt "$_G_count" && break
294a3129944Smrg    done
295a3129944Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
296a3129944Smrg  }
297a3129944Smrg
298a3129944Smrg  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
299a3129944Smrg  GREP=$func_path_progs_result
300a3129944Smrg}
301a3129944Smrg
302a3129944Smrg
303a3129944Smrg## ------------------------------- ##
304a3129944Smrg## User overridable command paths. ##
305a3129944Smrg## ------------------------------- ##
306a3129944Smrg
307a3129944Smrg# All uppercase variable names are used for environment variables.  These
308a3129944Smrg# variables can be overridden by the user before calling a script that
309a3129944Smrg# uses them if a suitable command of that name is not already available
310a3129944Smrg# in the command search PATH.
311698f425bSmrg
312698f425bSmrg: ${CP="cp -f"}
313a3129944Smrg: ${ECHO="printf %s\n"}
314a3129944Smrg: ${EGREP="$GREP -E"}
315a3129944Smrg: ${FGREP="$GREP -F"}
316a3129944Smrg: ${LN_S="ln -s"}
317698f425bSmrg: ${MAKE="make"}
318698f425bSmrg: ${MKDIR="mkdir"}
319698f425bSmrg: ${MV="mv -f"}
320698f425bSmrg: ${RM="rm -f"}
321698f425bSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
322266e564dSmrg
323698f425bSmrg
324a3129944Smrg## -------------------- ##
325a3129944Smrg## Useful sed snippets. ##
326a3129944Smrg## -------------------- ##
3279ef0b394Smrg
328a3129944Smrgsed_dirname='s|/[^/]*$||'
329a3129944Smrgsed_basename='s|^.*/||'
3309ef0b394Smrg
331a3129944Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
332a3129944Smrg# metacharacters that are still active within double-quoted strings.
333a3129944Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
3349ef0b394Smrg
335a3129944Smrg# Same as above, but do not quote variable references.
336a3129944Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
3379ef0b394Smrg
338a3129944Smrg# Sed substitution that turns a string into a regex matching for the
339a3129944Smrg# string literally.
340a3129944Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
3419ef0b394Smrg
342a3129944Smrg# Sed substitution that converts a w32 file name or path
343a3129944Smrg# that contains forward slashes, into one that contains
344a3129944Smrg# (escaped) backslashes.  A very naive implementation.
345a3129944Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
346a3129944Smrg
347a3129944Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
348a3129944Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
349a3129944Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
350a3129944Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
351a3129944Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
352a3129944Smrg_G_bs='\\'
353a3129944Smrg_G_bs2='\\\\'
354a3129944Smrg_G_bs4='\\\\\\\\'
355a3129944Smrg_G_dollar='\$'
356a3129944Smrgsed_double_backslash="\
357a3129944Smrg  s/$_G_bs4/&\\
358a3129944Smrg/g
359a3129944Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
360a3129944Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
361a3129944Smrg  s/\n//g"
3629ef0b394Smrg
3639ef0b394Smrg
364a3129944Smrg## ----------------- ##
365a3129944Smrg## Global variables. ##
366a3129944Smrg## ----------------- ##
3679ef0b394Smrg
368a3129944Smrg# Except for the global variables explicitly listed below, the following
369a3129944Smrg# functions in the '^func_' namespace, and the '^require_' namespace
370a3129944Smrg# variables initialised in the 'Resource management' section, sourcing
371a3129944Smrg# this file will not pollute your global namespace with anything
372a3129944Smrg# else. There's no portable way to scope variables in Bourne shell
373a3129944Smrg# though, so actually running these functions will sometimes place
374a3129944Smrg# results into a variable named after the function, and often use
375a3129944Smrg# temporary variables in the '^_G_' namespace. If you are careful to
376a3129944Smrg# avoid using those namespaces casually in your sourcing script, things
377a3129944Smrg# should continue to work as you expect. And, of course, you can freely
378a3129944Smrg# overwrite any of the functions or variables defined here before
379a3129944Smrg# calling anything to customize them.
3809ef0b394Smrg
381a3129944SmrgEXIT_SUCCESS=0
382a3129944SmrgEXIT_FAILURE=1
383a3129944SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
384a3129944SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
385266e564dSmrg
386a3129944Smrg# Allow overriding, eg assuming that you follow the convention of
387a3129944Smrg# putting '$debug_cmd' at the start of all your functions, you can get
388a3129944Smrg# bash to show function call trace with:
389a3129944Smrg#
390a3129944Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
391a3129944Smrgdebug_cmd=${debug_cmd-":"}
392a3129944Smrgexit_cmd=:
393698f425bSmrg
394a3129944Smrg# By convention, finish your script with:
395a3129944Smrg#
396a3129944Smrg#    exit $exit_status
397a3129944Smrg#
398a3129944Smrg# so that you can set exit_status to non-zero if you want to indicate
399a3129944Smrg# something went wrong during execution without actually bailing out at
400a3129944Smrg# the point of failure.
401a3129944Smrgexit_status=$EXIT_SUCCESS
4029ef0b394Smrg
403a3129944Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
404a3129944Smrg# is ksh but when the shell is invoked as "sh" and the current value of
405a3129944Smrg# the _XPG environment variable is not equal to 1 (one), the special
406a3129944Smrg# positional parameter $0, within a function call, is the name of the
407a3129944Smrg# function.
408a3129944Smrgprogpath=$0
409698f425bSmrg
410a3129944Smrg# The name of this program.
411a3129944Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
412698f425bSmrg
413a3129944Smrg# Make sure we have an absolute progpath for reexecution:
414698f425bSmrgcase $progpath in
415698f425bSmrg  [\\/]*|[A-Za-z]:\\*) ;;
416698f425bSmrg  *[\\/]*)
417a3129944Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
418698f425bSmrg     progdir=`cd "$progdir" && pwd`
419a3129944Smrg     progpath=$progdir/$progname
420698f425bSmrg     ;;
421698f425bSmrg  *)
422a3129944Smrg     _G_IFS=$IFS
423fb5e8d76Smrg     IFS=${PATH_SEPARATOR-:}
424698f425bSmrg     for progdir in $PATH; do
425a3129944Smrg       IFS=$_G_IFS
426698f425bSmrg       test -x "$progdir/$progname" && break
427698f425bSmrg     done
428a3129944Smrg     IFS=$_G_IFS
429698f425bSmrg     test -n "$progdir" || progdir=`pwd`
430a3129944Smrg     progpath=$progdir/$progname
431698f425bSmrg     ;;
432698f425bSmrgesac
433698f425bSmrg
434698f425bSmrg
435a3129944Smrg## ----------------- ##
436a3129944Smrg## Standard options. ##
437a3129944Smrg## ----------------- ##
4389ef0b394Smrg
439a3129944Smrg# The following options affect the operation of the functions defined
440a3129944Smrg# below, and should be set appropriately depending on run-time para-
441a3129944Smrg# meters passed on the command line.
442698f425bSmrg
443698f425bSmrgopt_dry_run=false
444698f425bSmrgopt_quiet=false
445698f425bSmrgopt_verbose=false
446698f425bSmrg
447a3129944Smrg# Categories 'all' and 'none' are always available.  Append any others
448a3129944Smrg# you will pass as the first argument to func_warning from your own
449a3129944Smrg# code.
450a3129944Smrgwarning_categories=
451698f425bSmrg
452a3129944Smrg# By default, display warnings according to 'opt_warning_types'.  Set
453a3129944Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
454a3129944Smrg# treat the next displayed warning as a fatal error.
455a3129944Smrgwarning_func=func_warn_and_continue
456698f425bSmrg
457a3129944Smrg# Set to 'all' to display all warnings, 'none' to suppress all
458a3129944Smrg# warnings, or a space delimited list of some subset of
459a3129944Smrg# 'warning_categories' to display only the listed warnings.
460a3129944Smrgopt_warning_types=all
461698f425bSmrg
4629ef0b394Smrg
463a3129944Smrg## -------------------- ##
464a3129944Smrg## Resource management. ##
465a3129944Smrg## -------------------- ##
466698f425bSmrg
467a3129944Smrg# This section contains definitions for functions that each ensure a
468a3129944Smrg# particular resource (a file, or a non-empty configuration variable for
469a3129944Smrg# example) is available, and if appropriate to extract default values
470a3129944Smrg# from pertinent package files. Call them using their associated
471a3129944Smrg# 'require_*' variable to ensure that they are executed, at most, once.
472a3129944Smrg#
473a3129944Smrg# It's entirely deliberate that calling these functions can set
474a3129944Smrg# variables that don't obey the namespace limitations obeyed by the rest
475a3129944Smrg# of this file, in order that that they be as useful as possible to
476a3129944Smrg# callers.
477698f425bSmrg
478698f425bSmrg
479a3129944Smrg# require_term_colors
480a3129944Smrg# -------------------
481a3129944Smrg# Allow display of bold text on terminals that support it.
482a3129944Smrgrequire_term_colors=func_require_term_colors
483a3129944Smrgfunc_require_term_colors ()
484698f425bSmrg{
485a3129944Smrg    $debug_cmd
486a3129944Smrg
487a3129944Smrg    test -t 1 && {
488a3129944Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
489a3129944Smrg      # precedence, because most terminfo databases neglect to describe
490a3129944Smrg      # whether color sequences are supported.
491a3129944Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
492a3129944Smrg
493a3129944Smrg      if test 1 = "$USE_ANSI_COLORS"; then
494a3129944Smrg        # Standard ANSI escape sequences
495a3129944Smrg        tc_reset='[0m'
496a3129944Smrg        tc_bold='[1m';   tc_standout='[7m'
497a3129944Smrg        tc_red='[31m';   tc_green='[32m'
498a3129944Smrg        tc_blue='[34m';  tc_cyan='[36m'
499a3129944Smrg      else
500a3129944Smrg        # Otherwise trust the terminfo database after all.
501a3129944Smrg        test -n "`tput sgr0 2>/dev/null`" && {
502a3129944Smrg          tc_reset=`tput sgr0`
503a3129944Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
504a3129944Smrg          tc_standout=$tc_bold
505a3129944Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
506a3129944Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
507a3129944Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
508a3129944Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
509a3129944Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
510a3129944Smrg        }
511a3129944Smrg      fi
512a3129944Smrg    }
513698f425bSmrg
514a3129944Smrg    require_term_colors=:
515698f425bSmrg}
516698f425bSmrg
517698f425bSmrg
518a3129944Smrg## ----------------- ##
519a3129944Smrg## Function library. ##
520a3129944Smrg## ----------------- ##
521a3129944Smrg
522a3129944Smrg# This section contains a variety of useful functions to call in your
523a3129944Smrg# scripts. Take note of the portable wrappers for features provided by
524a3129944Smrg# some modern shells, which will fall back to slower equivalents on
525a3129944Smrg# less featureful shells.
526a3129944Smrg
527a3129944Smrg
528a3129944Smrg# func_append VAR VALUE
529a3129944Smrg# ---------------------
530a3129944Smrg# Append VALUE onto the existing contents of VAR.
531a3129944Smrg
532a3129944Smrg  # We should try to minimise forks, especially on Windows where they are
533a3129944Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
534a3129944Smrg  # being used:
535a3129944Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
536a3129944Smrg    : ${_G_HAVE_ARITH_OP="yes"}
537a3129944Smrg    : ${_G_HAVE_XSI_OPS="yes"}
538a3129944Smrg    # The += operator was introduced in bash 3.1
539a3129944Smrg    case $BASH_VERSION in
540a3129944Smrg      [12].* | 3.0 | 3.0*) ;;
541a3129944Smrg      *)
542a3129944Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
543a3129944Smrg        ;;
544a3129944Smrg    esac
545a3129944Smrg  fi
546a3129944Smrg
547a3129944Smrg  # _G_HAVE_PLUSEQ_OP
548a3129944Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
549a3129944Smrg  # useable or anything else if it does not work.
550a3129944Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
551a3129944Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
552a3129944Smrg    && _G_HAVE_PLUSEQ_OP=yes
553a3129944Smrg
554a3129944Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
555a3129944Smrgthen
556a3129944Smrg  # This is an XSI compatible shell, allowing a faster implementation...
557a3129944Smrg  eval 'func_append ()
558a3129944Smrg  {
559a3129944Smrg    $debug_cmd
560a3129944Smrg
561a3129944Smrg    eval "$1+=\$2"
562a3129944Smrg  }'
563a3129944Smrgelse
564a3129944Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
565a3129944Smrg  func_append ()
566a3129944Smrg  {
567a3129944Smrg    $debug_cmd
568a3129944Smrg
569a3129944Smrg    eval "$1=\$$1\$2"
570a3129944Smrg  }
571a3129944Smrgfi
572a3129944Smrg
573a3129944Smrg
574a3129944Smrg# func_append_quoted VAR VALUE
575a3129944Smrg# ----------------------------
576a3129944Smrg# Quote VALUE and append to the end of shell variable VAR, separated
577a3129944Smrg# by a space.
578a3129944Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
579a3129944Smrg  eval 'func_append_quoted ()
580a3129944Smrg  {
581a3129944Smrg    $debug_cmd
582a3129944Smrg
583a3129944Smrg    func_quote_for_eval "$2"
584a3129944Smrg    eval "$1+=\\ \$func_quote_for_eval_result"
585a3129944Smrg  }'
586a3129944Smrgelse
587a3129944Smrg  func_append_quoted ()
588a3129944Smrg  {
589a3129944Smrg    $debug_cmd
590a3129944Smrg
591a3129944Smrg    func_quote_for_eval "$2"
592a3129944Smrg    eval "$1=\$$1\\ \$func_quote_for_eval_result"
593a3129944Smrg  }
594a3129944Smrgfi
595a3129944Smrg
596a3129944Smrg
597a3129944Smrg# func_append_uniq VAR VALUE
598a3129944Smrg# --------------------------
599a3129944Smrg# Append unique VALUE onto the existing contents of VAR, assuming
600a3129944Smrg# entries are delimited by the first character of VALUE.  For example:
601a3129944Smrg#
602a3129944Smrg#   func_append_uniq options " --another-option option-argument"
603a3129944Smrg#
604a3129944Smrg# will only append to $options if " --another-option option-argument "
605a3129944Smrg# is not already present somewhere in $options already (note spaces at
606a3129944Smrg# each end implied by leading space in second argument).
607a3129944Smrgfunc_append_uniq ()
608a3129944Smrg{
609a3129944Smrg    $debug_cmd
610a3129944Smrg
611a3129944Smrg    eval _G_current_value='`$ECHO $'$1'`'
612a3129944Smrg    _G_delim=`expr "$2" : '\(.\)'`
613a3129944Smrg
614a3129944Smrg    case $_G_delim$_G_current_value$_G_delim in
615a3129944Smrg      *"$2$_G_delim"*) ;;
616a3129944Smrg      *) func_append "$@" ;;
617a3129944Smrg    esac
618a3129944Smrg}
619a3129944Smrg
620a3129944Smrg
621a3129944Smrg# func_arith TERM...
622a3129944Smrg# ------------------
623a3129944Smrg# Set func_arith_result to the result of evaluating TERMs.
624a3129944Smrg  test -z "$_G_HAVE_ARITH_OP" \
625a3129944Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
626a3129944Smrg    && _G_HAVE_ARITH_OP=yes
627a3129944Smrg
628a3129944Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
629a3129944Smrg  eval 'func_arith ()
630a3129944Smrg  {
631a3129944Smrg    $debug_cmd
632a3129944Smrg
633a3129944Smrg    func_arith_result=$(( $* ))
634a3129944Smrg  }'
635a3129944Smrgelse
636a3129944Smrg  func_arith ()
637a3129944Smrg  {
638a3129944Smrg    $debug_cmd
639a3129944Smrg
640a3129944Smrg    func_arith_result=`expr "$@"`
641a3129944Smrg  }
642a3129944Smrgfi
643a3129944Smrg
644a3129944Smrg
645a3129944Smrg# func_basename FILE
646a3129944Smrg# ------------------
647a3129944Smrg# Set func_basename_result to FILE with everything up to and including
648a3129944Smrg# the last / stripped.
649a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
650a3129944Smrg  # If this shell supports suffix pattern removal, then use it to avoid
651a3129944Smrg  # forking. Hide the definitions single quotes in case the shell chokes
652a3129944Smrg  # on unsupported syntax...
653a3129944Smrg  _b='func_basename_result=${1##*/}'
654a3129944Smrg  _d='case $1 in
655a3129944Smrg        */*) func_dirname_result=${1%/*}$2 ;;
656a3129944Smrg        *  ) func_dirname_result=$3        ;;
657a3129944Smrg      esac'
658a3129944Smrg
659a3129944Smrgelse
660a3129944Smrg  # ...otherwise fall back to using sed.
661a3129944Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
662a3129944Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
663a3129944Smrg      if test "X$func_dirname_result" = "X$1"; then
664a3129944Smrg        func_dirname_result=$3
665a3129944Smrg      else
666a3129944Smrg        func_append func_dirname_result "$2"
667a3129944Smrg      fi'
668a3129944Smrgfi
669a3129944Smrg
670a3129944Smrgeval 'func_basename ()
671a3129944Smrg{
672a3129944Smrg    $debug_cmd
673a3129944Smrg
674a3129944Smrg    '"$_b"'
675a3129944Smrg}'
676a3129944Smrg
677a3129944Smrg
678a3129944Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
679a3129944Smrg# -------------------------------------------
680a3129944Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
681a3129944Smrg# otherwise set result to NONDIR_REPLACEMENT.
682a3129944Smrgeval 'func_dirname ()
683a3129944Smrg{
684a3129944Smrg    $debug_cmd
685a3129944Smrg
686a3129944Smrg    '"$_d"'
687a3129944Smrg}'
688a3129944Smrg
689a3129944Smrg
690a3129944Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
691a3129944Smrg# --------------------------------------------------------
692a3129944Smrg# Perform func_basename and func_dirname in a single function
693a3129944Smrg# call:
694a3129944Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
695a3129944Smrg#             add APPEND to the result, otherwise set result
696a3129944Smrg#             to NONDIR_REPLACEMENT.
697a3129944Smrg#             value returned in "$func_dirname_result"
698a3129944Smrg#   basename: Compute filename of FILE.
699a3129944Smrg#             value retuned in "$func_basename_result"
700a3129944Smrg# For efficiency, we do not delegate to the functions above but instead
701a3129944Smrg# duplicate the functionality here.
702a3129944Smrgeval 'func_dirname_and_basename ()
703a3129944Smrg{
704a3129944Smrg    $debug_cmd
705a3129944Smrg
706a3129944Smrg    '"$_b"'
707a3129944Smrg    '"$_d"'
708a3129944Smrg}'
709a3129944Smrg
710a3129944Smrg
711a3129944Smrg# func_echo ARG...
712a3129944Smrg# ----------------
713a3129944Smrg# Echo program name prefixed message.
714a3129944Smrgfunc_echo ()
715a3129944Smrg{
716a3129944Smrg    $debug_cmd
717a3129944Smrg
718a3129944Smrg    _G_message=$*
719a3129944Smrg
720a3129944Smrg    func_echo_IFS=$IFS
721a3129944Smrg    IFS=$nl
722a3129944Smrg    for _G_line in $_G_message; do
723a3129944Smrg      IFS=$func_echo_IFS
724a3129944Smrg      $ECHO "$progname: $_G_line"
725a3129944Smrg    done
726a3129944Smrg    IFS=$func_echo_IFS
727a3129944Smrg}
728a3129944Smrg
729a3129944Smrg
730a3129944Smrg# func_echo_all ARG...
731a3129944Smrg# --------------------
732a3129944Smrg# Invoke $ECHO with all args, space-separated.
733a3129944Smrgfunc_echo_all ()
734a3129944Smrg{
735a3129944Smrg    $ECHO "$*"
736a3129944Smrg}
737a3129944Smrg
738a3129944Smrg
739a3129944Smrg# func_echo_infix_1 INFIX ARG...
740a3129944Smrg# ------------------------------
741a3129944Smrg# Echo program name, followed by INFIX on the first line, with any
742a3129944Smrg# additional lines not showing INFIX.
743a3129944Smrgfunc_echo_infix_1 ()
744a3129944Smrg{
745a3129944Smrg    $debug_cmd
746a3129944Smrg
747a3129944Smrg    $require_term_colors
748a3129944Smrg
749a3129944Smrg    _G_infix=$1; shift
750a3129944Smrg    _G_indent=$_G_infix
751a3129944Smrg    _G_prefix="$progname: $_G_infix: "
752a3129944Smrg    _G_message=$*
753a3129944Smrg
754a3129944Smrg    # Strip color escape sequences before counting printable length
755a3129944Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
756a3129944Smrg    do
757a3129944Smrg      test -n "$_G_tc" && {
758a3129944Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
759a3129944Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
760a3129944Smrg      }
761a3129944Smrg    done
762a3129944Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
763a3129944Smrg
764a3129944Smrg    func_echo_infix_1_IFS=$IFS
765a3129944Smrg    IFS=$nl
766a3129944Smrg    for _G_line in $_G_message; do
767a3129944Smrg      IFS=$func_echo_infix_1_IFS
768a3129944Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
769a3129944Smrg      _G_prefix=$_G_indent
770a3129944Smrg    done
771a3129944Smrg    IFS=$func_echo_infix_1_IFS
772a3129944Smrg}
773a3129944Smrg
774a3129944Smrg
775a3129944Smrg# func_error ARG...
776a3129944Smrg# -----------------
777a3129944Smrg# Echo program name prefixed message to standard error.
778a3129944Smrgfunc_error ()
779a3129944Smrg{
780a3129944Smrg    $debug_cmd
781a3129944Smrg
782a3129944Smrg    $require_term_colors
783a3129944Smrg
784a3129944Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
785a3129944Smrg}
786a3129944Smrg
787a3129944Smrg
788a3129944Smrg# func_fatal_error ARG...
789a3129944Smrg# -----------------------
790a3129944Smrg# Echo program name prefixed message to standard error, and exit.
791a3129944Smrgfunc_fatal_error ()
792a3129944Smrg{
793a3129944Smrg    $debug_cmd
794a3129944Smrg
795a3129944Smrg    func_error "$*"
796a3129944Smrg    exit $EXIT_FAILURE
797a3129944Smrg}
798a3129944Smrg
799a3129944Smrg
800a3129944Smrg# func_grep EXPRESSION FILENAME
801a3129944Smrg# -----------------------------
802698f425bSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
803698f425bSmrgfunc_grep ()
804698f425bSmrg{
805a3129944Smrg    $debug_cmd
806a3129944Smrg
807698f425bSmrg    $GREP "$1" "$2" >/dev/null 2>&1
808698f425bSmrg}
809698f425bSmrg
810698f425bSmrg
811a3129944Smrg# func_len STRING
812a3129944Smrg# ---------------
813a3129944Smrg# Set func_len_result to the length of STRING. STRING may not
814a3129944Smrg# start with a hyphen.
815a3129944Smrg  test -z "$_G_HAVE_XSI_OPS" \
816a3129944Smrg    && (eval 'x=a/b/c;
817a3129944Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
818a3129944Smrg    && _G_HAVE_XSI_OPS=yes
819a3129944Smrg
820a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
821a3129944Smrg  eval 'func_len ()
822a3129944Smrg  {
823a3129944Smrg    $debug_cmd
824a3129944Smrg
825a3129944Smrg    func_len_result=${#1}
826a3129944Smrg  }'
827a3129944Smrgelse
828a3129944Smrg  func_len ()
829a3129944Smrg  {
830a3129944Smrg    $debug_cmd
831a3129944Smrg
832a3129944Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
833a3129944Smrg  }
834a3129944Smrgfi
835a3129944Smrg
836a3129944Smrg
837a3129944Smrg# func_mkdir_p DIRECTORY-PATH
838a3129944Smrg# ---------------------------
839698f425bSmrg# Make sure the entire path to DIRECTORY-PATH is available.
840698f425bSmrgfunc_mkdir_p ()
841698f425bSmrg{
842a3129944Smrg    $debug_cmd
843698f425bSmrg
844a3129944Smrg    _G_directory_path=$1
845a3129944Smrg    _G_dir_list=
846698f425bSmrg
847a3129944Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
848a3129944Smrg
849a3129944Smrg      # Protect directory names starting with '-'
850a3129944Smrg      case $_G_directory_path in
851a3129944Smrg        -*) _G_directory_path=./$_G_directory_path ;;
852698f425bSmrg      esac
853698f425bSmrg
854698f425bSmrg      # While some portion of DIR does not yet exist...
855a3129944Smrg      while test ! -d "$_G_directory_path"; do
856698f425bSmrg        # ...make a list in topmost first order.  Use a colon delimited
857698f425bSmrg	# list incase some portion of path contains whitespace.
858a3129944Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
859698f425bSmrg
860698f425bSmrg        # If the last portion added has no slash in it, the list is done
861a3129944Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
862698f425bSmrg
863698f425bSmrg        # ...otherwise throw away the child directory and loop
864a3129944Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
865698f425bSmrg      done
866a3129944Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
867698f425bSmrg
868a3129944Smrg      func_mkdir_p_IFS=$IFS; IFS=:
869a3129944Smrg      for _G_dir in $_G_dir_list; do
870a3129944Smrg	IFS=$func_mkdir_p_IFS
871a3129944Smrg        # mkdir can fail with a 'File exist' error if two processes
872698f425bSmrg        # try to create one of the directories concurrently.  Don't
873698f425bSmrg        # stop in that case!
874a3129944Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
875698f425bSmrg      done
876a3129944Smrg      IFS=$func_mkdir_p_IFS
877698f425bSmrg
878698f425bSmrg      # Bail out if we (or some other process) failed to create a directory.
879a3129944Smrg      test -d "$_G_directory_path" || \
880a3129944Smrg        func_fatal_error "Failed to create '$1'"
881698f425bSmrg    fi
882698f425bSmrg}
883266e564dSmrg
884266e564dSmrg
885a3129944Smrg# func_mktempdir [BASENAME]
886a3129944Smrg# -------------------------
887266e564dSmrg# Make a temporary directory that won't clash with other running
888266e564dSmrg# libtool processes, and avoids race conditions if possible.  If
889a3129944Smrg# given, BASENAME is the basename for that directory.
890266e564dSmrgfunc_mktempdir ()
891266e564dSmrg{
892a3129944Smrg    $debug_cmd
893a3129944Smrg
894a3129944Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
895266e564dSmrg
896a3129944Smrg    if test : = "$opt_dry_run"; then
897266e564dSmrg      # Return a directory name, but don't create it in dry-run mode
898a3129944Smrg      _G_tmpdir=$_G_template-$$
899266e564dSmrg    else
900266e564dSmrg
901266e564dSmrg      # If mktemp works, use that first and foremost
902a3129944Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
903266e564dSmrg
904a3129944Smrg      if test ! -d "$_G_tmpdir"; then
905698f425bSmrg        # Failing that, at least try and use $RANDOM to avoid a race
906a3129944Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
907266e564dSmrg
908a3129944Smrg        func_mktempdir_umask=`umask`
909698f425bSmrg        umask 0077
910a3129944Smrg        $MKDIR "$_G_tmpdir"
911a3129944Smrg        umask $func_mktempdir_umask
912266e564dSmrg      fi
913266e564dSmrg
914266e564dSmrg      # If we're not in dry-run mode, bomb out on failure
915a3129944Smrg      test -d "$_G_tmpdir" || \
916a3129944Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
917a3129944Smrg    fi
918a3129944Smrg
919a3129944Smrg    $ECHO "$_G_tmpdir"
920a3129944Smrg}
921a3129944Smrg
922a3129944Smrg
923a3129944Smrg# func_normal_abspath PATH
924a3129944Smrg# ------------------------
925a3129944Smrg# Remove doubled-up and trailing slashes, "." path components,
926a3129944Smrg# and cancel out any ".." path components in PATH after making
927a3129944Smrg# it an absolute path.
928a3129944Smrgfunc_normal_abspath ()
929a3129944Smrg{
930a3129944Smrg    $debug_cmd
931a3129944Smrg
932a3129944Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
933a3129944Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
934a3129944Smrg    _G_pathcdr='s|^/[^/]*||'
935a3129944Smrg    _G_removedotparts=':dotsl
936a3129944Smrg		s|/\./|/|g
937a3129944Smrg		t dotsl
938a3129944Smrg		s|/\.$|/|'
939a3129944Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
940a3129944Smrg    _G_finalslash='s|/*$|/|'
941a3129944Smrg
942a3129944Smrg    # Start from root dir and reassemble the path.
943a3129944Smrg    func_normal_abspath_result=
944a3129944Smrg    func_normal_abspath_tpath=$1
945a3129944Smrg    func_normal_abspath_altnamespace=
946a3129944Smrg    case $func_normal_abspath_tpath in
947a3129944Smrg      "")
948a3129944Smrg        # Empty path, that just means $cwd.
949a3129944Smrg        func_stripname '' '/' "`pwd`"
950a3129944Smrg        func_normal_abspath_result=$func_stripname_result
951a3129944Smrg        return
952a3129944Smrg        ;;
953a3129944Smrg      # The next three entries are used to spot a run of precisely
954a3129944Smrg      # two leading slashes without using negated character classes;
955a3129944Smrg      # we take advantage of case's first-match behaviour.
956a3129944Smrg      ///*)
957a3129944Smrg        # Unusual form of absolute path, do nothing.
958a3129944Smrg        ;;
959a3129944Smrg      //*)
960a3129944Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
961a3129944Smrg        # and for example Cygwin uses it to access remote file shares
962a3129944Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
963a3129944Smrg        func_normal_abspath_altnamespace=/
964a3129944Smrg        ;;
965a3129944Smrg      /*)
966a3129944Smrg        # Absolute path, do nothing.
967a3129944Smrg        ;;
968a3129944Smrg      *)
969a3129944Smrg        # Relative path, prepend $cwd.
970a3129944Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
971a3129944Smrg        ;;
972a3129944Smrg    esac
973a3129944Smrg
974a3129944Smrg    # Cancel out all the simple stuff to save iterations.  We also want
975a3129944Smrg    # the path to end with a slash for ease of parsing, so make sure
976a3129944Smrg    # there is one (and only one) here.
977a3129944Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
978a3129944Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
979a3129944Smrg    while :; do
980a3129944Smrg      # Processed it all yet?
981a3129944Smrg      if test / = "$func_normal_abspath_tpath"; then
982a3129944Smrg        # If we ascended to the root using ".." the result may be empty now.
983a3129944Smrg        if test -z "$func_normal_abspath_result"; then
984a3129944Smrg          func_normal_abspath_result=/
985a3129944Smrg        fi
986a3129944Smrg        break
987a3129944Smrg      fi
988a3129944Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
989a3129944Smrg          -e "$_G_pathcar"`
990a3129944Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
991a3129944Smrg          -e "$_G_pathcdr"`
992a3129944Smrg      # Figure out what to do with it
993a3129944Smrg      case $func_normal_abspath_tcomponent in
994a3129944Smrg        "")
995a3129944Smrg          # Trailing empty path component, ignore it.
996a3129944Smrg          ;;
997a3129944Smrg        ..)
998a3129944Smrg          # Parent dir; strip last assembled component from result.
999a3129944Smrg          func_dirname "$func_normal_abspath_result"
1000a3129944Smrg          func_normal_abspath_result=$func_dirname_result
1001a3129944Smrg          ;;
1002a3129944Smrg        *)
1003a3129944Smrg          # Actual path component, append it.
1004a3129944Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1005a3129944Smrg          ;;
1006a3129944Smrg      esac
1007a3129944Smrg    done
1008a3129944Smrg    # Restore leading double-slash if one was found on entry.
1009a3129944Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1010a3129944Smrg}
1011a3129944Smrg
1012a3129944Smrg
1013a3129944Smrg# func_notquiet ARG...
1014a3129944Smrg# --------------------
1015a3129944Smrg# Echo program name prefixed message only when not in quiet mode.
1016a3129944Smrgfunc_notquiet ()
1017a3129944Smrg{
1018a3129944Smrg    $debug_cmd
1019a3129944Smrg
1020a3129944Smrg    $opt_quiet || func_echo ${1+"$@"}
1021a3129944Smrg
1022a3129944Smrg    # A bug in bash halts the script if the last line of a function
1023a3129944Smrg    # fails when set -e is in force, so we need another command to
1024a3129944Smrg    # work around that:
1025a3129944Smrg    :
1026a3129944Smrg}
1027a3129944Smrg
1028a3129944Smrg
1029a3129944Smrg# func_relative_path SRCDIR DSTDIR
1030a3129944Smrg# --------------------------------
1031a3129944Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1032a3129944Smrgfunc_relative_path ()
1033a3129944Smrg{
1034a3129944Smrg    $debug_cmd
1035a3129944Smrg
1036a3129944Smrg    func_relative_path_result=
1037a3129944Smrg    func_normal_abspath "$1"
1038a3129944Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1039a3129944Smrg    func_normal_abspath "$2"
1040a3129944Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1041a3129944Smrg
1042a3129944Smrg    # Ascend the tree starting from libdir
1043a3129944Smrg    while :; do
1044a3129944Smrg      # check if we have found a prefix of bindir
1045a3129944Smrg      case $func_relative_path_tbindir in
1046a3129944Smrg        $func_relative_path_tlibdir)
1047a3129944Smrg          # found an exact match
1048a3129944Smrg          func_relative_path_tcancelled=
1049a3129944Smrg          break
1050a3129944Smrg          ;;
1051a3129944Smrg        $func_relative_path_tlibdir*)
1052a3129944Smrg          # found a matching prefix
1053a3129944Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1054a3129944Smrg          func_relative_path_tcancelled=$func_stripname_result
1055a3129944Smrg          if test -z "$func_relative_path_result"; then
1056a3129944Smrg            func_relative_path_result=.
1057a3129944Smrg          fi
1058a3129944Smrg          break
1059a3129944Smrg          ;;
1060a3129944Smrg        *)
1061a3129944Smrg          func_dirname $func_relative_path_tlibdir
1062a3129944Smrg          func_relative_path_tlibdir=$func_dirname_result
1063a3129944Smrg          if test -z "$func_relative_path_tlibdir"; then
1064a3129944Smrg            # Have to descend all the way to the root!
1065a3129944Smrg            func_relative_path_result=../$func_relative_path_result
1066a3129944Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1067a3129944Smrg            break
1068a3129944Smrg          fi
1069a3129944Smrg          func_relative_path_result=../$func_relative_path_result
1070a3129944Smrg          ;;
1071a3129944Smrg      esac
1072a3129944Smrg    done
1073a3129944Smrg
1074a3129944Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1075a3129944Smrg    func_stripname '' '/' "$func_relative_path_result"
1076a3129944Smrg    func_relative_path_result=$func_stripname_result
1077a3129944Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1078a3129944Smrg    if test -n "$func_stripname_result"; then
1079a3129944Smrg      func_append func_relative_path_result "/$func_stripname_result"
1080a3129944Smrg    fi
1081a3129944Smrg
1082a3129944Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1083a3129944Smrg    if test -n "$func_relative_path_result"; then
1084a3129944Smrg      func_stripname './' '' "$func_relative_path_result"
1085a3129944Smrg      func_relative_path_result=$func_stripname_result
1086266e564dSmrg    fi
1087266e564dSmrg
1088a3129944Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1089a3129944Smrg
1090a3129944Smrg    :
1091a3129944Smrg}
1092a3129944Smrg
1093a3129944Smrg
1094a3129944Smrg# func_quote_for_eval ARG...
1095a3129944Smrg# --------------------------
1096a3129944Smrg# Aesthetically quote ARGs to be evaled later.
1097a3129944Smrg# This function returns two values:
1098a3129944Smrg#   i) func_quote_for_eval_result
1099a3129944Smrg#      double-quoted, suitable for a subsequent eval
1100a3129944Smrg#  ii) func_quote_for_eval_unquoted_result
1101a3129944Smrg#      has all characters that are still active within double
1102a3129944Smrg#      quotes backslashified.
1103a3129944Smrgfunc_quote_for_eval ()
1104a3129944Smrg{
1105a3129944Smrg    $debug_cmd
1106a3129944Smrg
1107a3129944Smrg    func_quote_for_eval_unquoted_result=
1108a3129944Smrg    func_quote_for_eval_result=
1109a3129944Smrg    while test 0 -lt $#; do
1110a3129944Smrg      case $1 in
1111a3129944Smrg        *[\\\`\"\$]*)
1112a3129944Smrg	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
1113a3129944Smrg        *)
1114a3129944Smrg          _G_unquoted_arg=$1 ;;
1115a3129944Smrg      esac
1116a3129944Smrg      if test -n "$func_quote_for_eval_unquoted_result"; then
1117a3129944Smrg	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
1118a3129944Smrg      else
1119a3129944Smrg        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
1120a3129944Smrg      fi
1121a3129944Smrg
1122a3129944Smrg      case $_G_unquoted_arg in
1123a3129944Smrg        # Double-quote args containing shell metacharacters to delay
1124a3129944Smrg        # word splitting, command substitution and variable expansion
1125a3129944Smrg        # for a subsequent eval.
1126a3129944Smrg        # Many Bourne shells cannot handle close brackets correctly
1127a3129944Smrg        # in scan sets, so we specify it separately.
1128a3129944Smrg        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1129a3129944Smrg          _G_quoted_arg=\"$_G_unquoted_arg\"
1130a3129944Smrg          ;;
1131a3129944Smrg        *)
1132a3129944Smrg          _G_quoted_arg=$_G_unquoted_arg
1133a3129944Smrg	  ;;
1134a3129944Smrg      esac
1135a3129944Smrg
1136a3129944Smrg      if test -n "$func_quote_for_eval_result"; then
1137a3129944Smrg	func_append func_quote_for_eval_result " $_G_quoted_arg"
1138a3129944Smrg      else
1139a3129944Smrg        func_append func_quote_for_eval_result "$_G_quoted_arg"
1140a3129944Smrg      fi
1141a3129944Smrg      shift
1142a3129944Smrg    done
1143a3129944Smrg}
1144a3129944Smrg
1145a3129944Smrg
1146a3129944Smrg# func_quote_for_expand ARG
1147a3129944Smrg# -------------------------
1148a3129944Smrg# Aesthetically quote ARG to be evaled later; same as above,
1149a3129944Smrg# but do not quote variable references.
1150a3129944Smrgfunc_quote_for_expand ()
1151a3129944Smrg{
1152a3129944Smrg    $debug_cmd
1153a3129944Smrg
1154a3129944Smrg    case $1 in
1155a3129944Smrg      *[\\\`\"]*)
1156a3129944Smrg	_G_arg=`$ECHO "$1" | $SED \
1157a3129944Smrg	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
1158a3129944Smrg      *)
1159a3129944Smrg        _G_arg=$1 ;;
1160a3129944Smrg    esac
1161a3129944Smrg
1162a3129944Smrg    case $_G_arg in
1163a3129944Smrg      # Double-quote args containing shell metacharacters to delay
1164a3129944Smrg      # word splitting and command substitution for a subsequent eval.
1165a3129944Smrg      # Many Bourne shells cannot handle close brackets correctly
1166a3129944Smrg      # in scan sets, so we specify it separately.
1167a3129944Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1168a3129944Smrg        _G_arg=\"$_G_arg\"
1169a3129944Smrg        ;;
1170a3129944Smrg    esac
1171a3129944Smrg
1172a3129944Smrg    func_quote_for_expand_result=$_G_arg
1173a3129944Smrg}
1174a3129944Smrg
1175a3129944Smrg
1176a3129944Smrg# func_stripname PREFIX SUFFIX NAME
1177a3129944Smrg# ---------------------------------
1178a3129944Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1179a3129944Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1180a3129944Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1181a3129944Smrg# dot (in which case that matches only a dot).
1182a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1183a3129944Smrg  eval 'func_stripname ()
1184a3129944Smrg  {
1185a3129944Smrg    $debug_cmd
1186a3129944Smrg
1187a3129944Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1188a3129944Smrg    # positional parameters, so assign one to ordinary variable first.
1189a3129944Smrg    func_stripname_result=$3
1190a3129944Smrg    func_stripname_result=${func_stripname_result#"$1"}
1191a3129944Smrg    func_stripname_result=${func_stripname_result%"$2"}
1192a3129944Smrg  }'
1193a3129944Smrgelse
1194a3129944Smrg  func_stripname ()
1195a3129944Smrg  {
1196a3129944Smrg    $debug_cmd
1197a3129944Smrg
1198a3129944Smrg    case $2 in
1199a3129944Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1200a3129944Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1201a3129944Smrg    esac
1202a3129944Smrg  }
1203a3129944Smrgfi
1204a3129944Smrg
1205a3129944Smrg
1206a3129944Smrg# func_show_eval CMD [FAIL_EXP]
1207a3129944Smrg# -----------------------------
1208a3129944Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1209a3129944Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1210a3129944Smrg# is given, then evaluate it.
1211a3129944Smrgfunc_show_eval ()
1212a3129944Smrg{
1213a3129944Smrg    $debug_cmd
1214a3129944Smrg
1215a3129944Smrg    _G_cmd=$1
1216a3129944Smrg    _G_fail_exp=${2-':'}
1217a3129944Smrg
1218a3129944Smrg    func_quote_for_expand "$_G_cmd"
1219a3129944Smrg    eval "func_notquiet $func_quote_for_expand_result"
1220a3129944Smrg
1221a3129944Smrg    $opt_dry_run || {
1222a3129944Smrg      eval "$_G_cmd"
1223a3129944Smrg      _G_status=$?
1224a3129944Smrg      if test 0 -ne "$_G_status"; then
1225a3129944Smrg	eval "(exit $_G_status); $_G_fail_exp"
1226a3129944Smrg      fi
1227a3129944Smrg    }
1228a3129944Smrg}
1229a3129944Smrg
1230a3129944Smrg
1231a3129944Smrg# func_show_eval_locale CMD [FAIL_EXP]
1232a3129944Smrg# ------------------------------------
1233a3129944Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1234a3129944Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1235a3129944Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1236a3129944Smrgfunc_show_eval_locale ()
1237a3129944Smrg{
1238a3129944Smrg    $debug_cmd
1239a3129944Smrg
1240a3129944Smrg    _G_cmd=$1
1241a3129944Smrg    _G_fail_exp=${2-':'}
1242a3129944Smrg
1243a3129944Smrg    $opt_quiet || {
1244a3129944Smrg      func_quote_for_expand "$_G_cmd"
1245a3129944Smrg      eval "func_echo $func_quote_for_expand_result"
1246a3129944Smrg    }
1247a3129944Smrg
1248a3129944Smrg    $opt_dry_run || {
1249a3129944Smrg      eval "$_G_user_locale
1250a3129944Smrg	    $_G_cmd"
1251a3129944Smrg      _G_status=$?
1252a3129944Smrg      eval "$_G_safe_locale"
1253a3129944Smrg      if test 0 -ne "$_G_status"; then
1254a3129944Smrg	eval "(exit $_G_status); $_G_fail_exp"
1255a3129944Smrg      fi
1256a3129944Smrg    }
1257a3129944Smrg}
1258a3129944Smrg
1259a3129944Smrg
1260a3129944Smrg# func_tr_sh
1261a3129944Smrg# ----------
1262a3129944Smrg# Turn $1 into a string suitable for a shell variable name.
1263a3129944Smrg# Result is stored in $func_tr_sh_result.  All characters
1264a3129944Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1265a3129944Smrg# if $1 begins with a digit, a '_' is prepended as well.
1266a3129944Smrgfunc_tr_sh ()
1267a3129944Smrg{
1268a3129944Smrg    $debug_cmd
1269a3129944Smrg
1270a3129944Smrg    case $1 in
1271a3129944Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1272a3129944Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1273a3129944Smrg      ;;
1274a3129944Smrg    * )
1275a3129944Smrg      func_tr_sh_result=$1
1276a3129944Smrg      ;;
1277a3129944Smrg    esac
1278a3129944Smrg}
1279a3129944Smrg
1280a3129944Smrg
1281a3129944Smrg# func_verbose ARG...
1282a3129944Smrg# -------------------
1283a3129944Smrg# Echo program name prefixed message in verbose mode only.
1284a3129944Smrgfunc_verbose ()
1285a3129944Smrg{
1286a3129944Smrg    $debug_cmd
1287a3129944Smrg
1288a3129944Smrg    $opt_verbose && func_echo "$*"
1289a3129944Smrg
1290a3129944Smrg    :
1291a3129944Smrg}
1292a3129944Smrg
1293a3129944Smrg
1294a3129944Smrg# func_warn_and_continue ARG...
1295a3129944Smrg# -----------------------------
1296a3129944Smrg# Echo program name prefixed warning message to standard error.
1297a3129944Smrgfunc_warn_and_continue ()
1298a3129944Smrg{
1299a3129944Smrg    $debug_cmd
1300a3129944Smrg
1301a3129944Smrg    $require_term_colors
1302a3129944Smrg
1303a3129944Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1304a3129944Smrg}
1305a3129944Smrg
1306a3129944Smrg
1307a3129944Smrg# func_warning CATEGORY ARG...
1308a3129944Smrg# ----------------------------
1309a3129944Smrg# Echo program name prefixed warning message to standard error. Warning
1310a3129944Smrg# messages can be filtered according to CATEGORY, where this function
1311a3129944Smrg# elides messages where CATEGORY is not listed in the global variable
1312a3129944Smrg# 'opt_warning_types'.
1313a3129944Smrgfunc_warning ()
1314a3129944Smrg{
1315a3129944Smrg    $debug_cmd
1316a3129944Smrg
1317a3129944Smrg    # CATEGORY must be in the warning_categories list!
1318a3129944Smrg    case " $warning_categories " in
1319a3129944Smrg      *" $1 "*) ;;
1320a3129944Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1321a3129944Smrg    esac
1322a3129944Smrg
1323a3129944Smrg    _G_category=$1
1324a3129944Smrg    shift
1325a3129944Smrg
1326a3129944Smrg    case " $opt_warning_types " in
1327a3129944Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1328a3129944Smrg    esac
1329a3129944Smrg}
1330a3129944Smrg
1331a3129944Smrg
1332a3129944Smrg# func_sort_ver VER1 VER2
1333a3129944Smrg# -----------------------
1334a3129944Smrg# 'sort -V' is not generally available.
1335a3129944Smrg# Note this deviates from the version comparison in automake
1336a3129944Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1337a3129944Smrg# but this should suffice as we won't be specifying old
1338a3129944Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1339a3129944Smrg# If we did want full compatibility then we should probably
1340a3129944Smrg# use m4_version_compare from autoconf.
1341a3129944Smrgfunc_sort_ver ()
1342a3129944Smrg{
1343a3129944Smrg    $debug_cmd
1344a3129944Smrg
1345a3129944Smrg    printf '%s\n%s\n' "$1" "$2" \
1346a3129944Smrg      | 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
1347a3129944Smrg}
1348a3129944Smrg
1349a3129944Smrg# func_lt_ver PREV CURR
1350a3129944Smrg# ---------------------
1351a3129944Smrg# Return true if PREV and CURR are in the correct order according to
1352a3129944Smrg# func_sort_ver, otherwise false.  Use it like this:
1353a3129944Smrg#
1354a3129944Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1355a3129944Smrgfunc_lt_ver ()
1356a3129944Smrg{
1357a3129944Smrg    $debug_cmd
1358a3129944Smrg
1359a3129944Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1360a3129944Smrg}
1361a3129944Smrg
1362a3129944Smrg
1363a3129944Smrg# Local variables:
1364a3129944Smrg# mode: shell-script
1365a3129944Smrg# sh-indentation: 2
1366a3129944Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1367a3129944Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1368a3129944Smrg# time-stamp-time-zone: "UTC"
1369a3129944Smrg# End:
1370a3129944Smrg#! /bin/sh
1371a3129944Smrg
1372a3129944Smrg# Set a version string for this script.
1373a3129944Smrgscriptversion=2014-01-07.03; # UTC
1374a3129944Smrg
1375a3129944Smrg# A portable, pluggable option parser for Bourne shell.
1376a3129944Smrg# Written by Gary V. Vaughan, 2010
1377a3129944Smrg
1378a3129944Smrg# Copyright (C) 2010-2015 Free Software Foundation, Inc.
1379a3129944Smrg# This is free software; see the source for copying conditions.  There is NO
1380a3129944Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1381a3129944Smrg
1382a3129944Smrg# This program is free software: you can redistribute it and/or modify
1383a3129944Smrg# it under the terms of the GNU General Public License as published by
1384a3129944Smrg# the Free Software Foundation, either version 3 of the License, or
1385a3129944Smrg# (at your option) any later version.
1386a3129944Smrg
1387a3129944Smrg# This program is distributed in the hope that it will be useful,
1388a3129944Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1389a3129944Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1390a3129944Smrg# GNU General Public License for more details.
1391a3129944Smrg
1392a3129944Smrg# You should have received a copy of the GNU General Public License
1393a3129944Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1394a3129944Smrg
1395a3129944Smrg# Please report bugs or propose patches to gary@gnu.org.
1396a3129944Smrg
1397a3129944Smrg
1398a3129944Smrg## ------ ##
1399a3129944Smrg## Usage. ##
1400a3129944Smrg## ------ ##
1401a3129944Smrg
1402a3129944Smrg# This file is a library for parsing options in your shell scripts along
1403a3129944Smrg# with assorted other useful supporting features that you can make use
1404a3129944Smrg# of too.
1405a3129944Smrg#
1406a3129944Smrg# For the simplest scripts you might need only:
1407a3129944Smrg#
1408a3129944Smrg#   #!/bin/sh
1409a3129944Smrg#   . relative/path/to/funclib.sh
1410a3129944Smrg#   . relative/path/to/options-parser
1411a3129944Smrg#   scriptversion=1.0
1412a3129944Smrg#   func_options ${1+"$@"}
1413a3129944Smrg#   eval set dummy "$func_options_result"; shift
1414a3129944Smrg#   ...rest of your script...
1415a3129944Smrg#
1416a3129944Smrg# In order for the '--version' option to work, you will need to have a
1417a3129944Smrg# suitably formatted comment like the one at the top of this file
1418a3129944Smrg# starting with '# Written by ' and ending with '# warranty; '.
1419a3129944Smrg#
1420a3129944Smrg# For '-h' and '--help' to work, you will also need a one line
1421a3129944Smrg# description of your script's purpose in a comment directly above the
1422a3129944Smrg# '# Written by ' line, like the one at the top of this file.
1423a3129944Smrg#
1424a3129944Smrg# The default options also support '--debug', which will turn on shell
1425a3129944Smrg# execution tracing (see the comment above debug_cmd below for another
1426a3129944Smrg# use), and '--verbose' and the func_verbose function to allow your script
1427a3129944Smrg# to display verbose messages only when your user has specified
1428a3129944Smrg# '--verbose'.
1429a3129944Smrg#
1430a3129944Smrg# After sourcing this file, you can plug processing for additional
1431a3129944Smrg# options by amending the variables from the 'Configuration' section
1432a3129944Smrg# below, and following the instructions in the 'Option parsing'
1433a3129944Smrg# section further down.
1434a3129944Smrg
1435a3129944Smrg## -------------- ##
1436a3129944Smrg## Configuration. ##
1437a3129944Smrg## -------------- ##
1438a3129944Smrg
1439a3129944Smrg# You should override these variables in your script after sourcing this
1440a3129944Smrg# file so that they reflect the customisations you have added to the
1441a3129944Smrg# option parser.
1442a3129944Smrg
1443a3129944Smrg# The usage line for option parsing errors and the start of '-h' and
1444a3129944Smrg# '--help' output messages. You can embed shell variables for delayed
1445a3129944Smrg# expansion at the time the message is displayed, but you will need to
1446a3129944Smrg# quote other shell meta-characters carefully to prevent them being
1447a3129944Smrg# expanded when the contents are evaled.
1448a3129944Smrgusage='$progpath [OPTION]...'
1449a3129944Smrg
1450a3129944Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1451a3129944Smrg# override it after sourcing this library to reflect the full set of
1452a3129944Smrg# options your script accepts.
1453a3129944Smrgusage_message="\
1454a3129944Smrg       --debug        enable verbose shell tracing
1455a3129944Smrg   -W, --warnings=CATEGORY
1456a3129944Smrg                      report the warnings falling in CATEGORY [all]
1457a3129944Smrg   -v, --verbose      verbosely report processing
1458a3129944Smrg       --version      print version information and exit
1459a3129944Smrg   -h, --help         print short or long help message and exit
1460a3129944Smrg"
1461a3129944Smrg
1462a3129944Smrg# Additional text appended to 'usage_message' in response to '--help'.
1463a3129944Smrglong_help_message="
1464a3129944SmrgWarning categories include:
1465a3129944Smrg       'all'          show all warnings
1466a3129944Smrg       'none'         turn off all the warnings
1467a3129944Smrg       'error'        warnings are treated as fatal errors"
1468a3129944Smrg
1469a3129944Smrg# Help message printed before fatal option parsing errors.
1470a3129944Smrgfatal_help="Try '\$progname --help' for more information."
1471a3129944Smrg
1472a3129944Smrg
1473a3129944Smrg
1474a3129944Smrg## ------------------------- ##
1475a3129944Smrg## Hook function management. ##
1476a3129944Smrg## ------------------------- ##
1477a3129944Smrg
1478a3129944Smrg# This section contains functions for adding, removing, and running hooks
1479a3129944Smrg# to the main code.  A hook is just a named list of of function, that can
1480a3129944Smrg# be run in order later on.
1481a3129944Smrg
1482a3129944Smrg# func_hookable FUNC_NAME
1483a3129944Smrg# -----------------------
1484a3129944Smrg# Declare that FUNC_NAME will run hooks added with
1485a3129944Smrg# 'func_add_hook FUNC_NAME ...'.
1486a3129944Smrgfunc_hookable ()
1487a3129944Smrg{
1488a3129944Smrg    $debug_cmd
1489a3129944Smrg
1490a3129944Smrg    func_append hookable_fns " $1"
1491a3129944Smrg}
1492a3129944Smrg
1493a3129944Smrg
1494a3129944Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1495a3129944Smrg# ---------------------------------
1496a3129944Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1497a3129944Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1498a3129944Smrgfunc_add_hook ()
1499a3129944Smrg{
1500a3129944Smrg    $debug_cmd
1501a3129944Smrg
1502a3129944Smrg    case " $hookable_fns " in
1503a3129944Smrg      *" $1 "*) ;;
1504a3129944Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1505a3129944Smrg    esac
1506a3129944Smrg
1507a3129944Smrg    eval func_append ${1}_hooks '" $2"'
1508a3129944Smrg}
1509a3129944Smrg
1510a3129944Smrg
1511a3129944Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1512a3129944Smrg# ------------------------------------
1513a3129944Smrg# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1514a3129944Smrgfunc_remove_hook ()
1515a3129944Smrg{
1516a3129944Smrg    $debug_cmd
1517a3129944Smrg
1518a3129944Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1519a3129944Smrg}
1520a3129944Smrg
1521a3129944Smrg
1522a3129944Smrg# func_run_hooks FUNC_NAME [ARG]...
1523a3129944Smrg# ---------------------------------
1524a3129944Smrg# Run all hook functions registered to FUNC_NAME.
1525a3129944Smrg# It is assumed that the list of hook functions contains nothing more
1526a3129944Smrg# than a whitespace-delimited list of legal shell function names, and
1527a3129944Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1528a3129944Smrg# whitespace.
1529a3129944Smrgfunc_run_hooks ()
1530a3129944Smrg{
1531a3129944Smrg    $debug_cmd
1532a3129944Smrg
1533a3129944Smrg    case " $hookable_fns " in
1534a3129944Smrg      *" $1 "*) ;;
1535a3129944Smrg      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1536a3129944Smrg    esac
1537a3129944Smrg
1538a3129944Smrg    eval _G_hook_fns=\$$1_hooks; shift
1539a3129944Smrg
1540a3129944Smrg    for _G_hook in $_G_hook_fns; do
1541a3129944Smrg      eval $_G_hook '"$@"'
1542a3129944Smrg
1543a3129944Smrg      # store returned options list back into positional
1544a3129944Smrg      # parameters for next 'cmd' execution.
1545a3129944Smrg      eval _G_hook_result=\$${_G_hook}_result
1546a3129944Smrg      eval set dummy "$_G_hook_result"; shift
1547a3129944Smrg    done
1548a3129944Smrg
1549a3129944Smrg    func_quote_for_eval ${1+"$@"}
1550a3129944Smrg    func_run_hooks_result=$func_quote_for_eval_result
1551a3129944Smrg}
1552a3129944Smrg
1553a3129944Smrg
1554a3129944Smrg
1555a3129944Smrg## --------------- ##
1556a3129944Smrg## Option parsing. ##
1557a3129944Smrg## --------------- ##
1558a3129944Smrg
1559a3129944Smrg# In order to add your own option parsing hooks, you must accept the
1560a3129944Smrg# full positional parameter list in your hook function, remove any
1561a3129944Smrg# options that you action, and then pass back the remaining unprocessed
1562a3129944Smrg# options in '<hooked_function_name>_result', escaped suitably for
1563a3129944Smrg# 'eval'.  Like this:
1564a3129944Smrg#
1565a3129944Smrg#    my_options_prep ()
1566a3129944Smrg#    {
1567a3129944Smrg#        $debug_cmd
1568a3129944Smrg#
1569a3129944Smrg#        # Extend the existing usage message.
1570a3129944Smrg#        usage_message=$usage_message'
1571a3129944Smrg#      -s, --silent       don'\''t print informational messages
1572a3129944Smrg#    '
1573a3129944Smrg#
1574a3129944Smrg#        func_quote_for_eval ${1+"$@"}
1575a3129944Smrg#        my_options_prep_result=$func_quote_for_eval_result
1576a3129944Smrg#    }
1577a3129944Smrg#    func_add_hook func_options_prep my_options_prep
1578a3129944Smrg#
1579a3129944Smrg#
1580a3129944Smrg#    my_silent_option ()
1581a3129944Smrg#    {
1582a3129944Smrg#        $debug_cmd
1583a3129944Smrg#
1584a3129944Smrg#        # Note that for efficiency, we parse as many options as we can
1585a3129944Smrg#        # recognise in a loop before passing the remainder back to the
1586a3129944Smrg#        # caller on the first unrecognised argument we encounter.
1587a3129944Smrg#        while test $# -gt 0; do
1588a3129944Smrg#          opt=$1; shift
1589a3129944Smrg#          case $opt in
1590a3129944Smrg#            --silent|-s) opt_silent=: ;;
1591a3129944Smrg#            # Separate non-argument short options:
1592a3129944Smrg#            -s*)         func_split_short_opt "$_G_opt"
1593a3129944Smrg#                         set dummy "$func_split_short_opt_name" \
1594a3129944Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1595a3129944Smrg#                         shift
1596a3129944Smrg#                         ;;
1597a3129944Smrg#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
1598a3129944Smrg#          esac
1599a3129944Smrg#        done
1600a3129944Smrg#
1601a3129944Smrg#        func_quote_for_eval ${1+"$@"}
1602a3129944Smrg#        my_silent_option_result=$func_quote_for_eval_result
1603a3129944Smrg#    }
1604a3129944Smrg#    func_add_hook func_parse_options my_silent_option
1605a3129944Smrg#
1606a3129944Smrg#
1607a3129944Smrg#    my_option_validation ()
1608a3129944Smrg#    {
1609a3129944Smrg#        $debug_cmd
1610a3129944Smrg#
1611a3129944Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1612a3129944Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1613a3129944Smrg#
1614a3129944Smrg#        func_quote_for_eval ${1+"$@"}
1615a3129944Smrg#        my_option_validation_result=$func_quote_for_eval_result
1616a3129944Smrg#    }
1617a3129944Smrg#    func_add_hook func_validate_options my_option_validation
1618a3129944Smrg#
1619a3129944Smrg# You'll alse need to manually amend $usage_message to reflect the extra
1620a3129944Smrg# options you parse.  It's preferable to append if you can, so that
1621a3129944Smrg# multiple option parsing hooks can be added safely.
1622a3129944Smrg
1623a3129944Smrg
1624a3129944Smrg# func_options [ARG]...
1625a3129944Smrg# ---------------------
1626a3129944Smrg# All the functions called inside func_options are hookable. See the
1627a3129944Smrg# individual implementations for details.
1628a3129944Smrgfunc_hookable func_options
1629a3129944Smrgfunc_options ()
1630a3129944Smrg{
1631a3129944Smrg    $debug_cmd
1632a3129944Smrg
1633a3129944Smrg    func_options_prep ${1+"$@"}
1634a3129944Smrg    eval func_parse_options \
1635a3129944Smrg        ${func_options_prep_result+"$func_options_prep_result"}
1636a3129944Smrg    eval func_validate_options \
1637a3129944Smrg        ${func_parse_options_result+"$func_parse_options_result"}
1638a3129944Smrg
1639a3129944Smrg    eval func_run_hooks func_options \
1640a3129944Smrg        ${func_validate_options_result+"$func_validate_options_result"}
1641a3129944Smrg
1642a3129944Smrg    # save modified positional parameters for caller
1643a3129944Smrg    func_options_result=$func_run_hooks_result
1644266e564dSmrg}
1645266e564dSmrg
1646266e564dSmrg
1647a3129944Smrg# func_options_prep [ARG]...
1648a3129944Smrg# --------------------------
1649a3129944Smrg# All initialisations required before starting the option parse loop.
1650a3129944Smrg# Note that when calling hook functions, we pass through the list of
1651a3129944Smrg# positional parameters.  If a hook function modifies that list, and
1652a3129944Smrg# needs to propogate that back to rest of this script, then the complete
1653a3129944Smrg# modified list must be put in 'func_run_hooks_result' before
1654a3129944Smrg# returning.
1655a3129944Smrgfunc_hookable func_options_prep
1656a3129944Smrgfunc_options_prep ()
1657266e564dSmrg{
1658a3129944Smrg    $debug_cmd
1659698f425bSmrg
1660a3129944Smrg    # Option defaults:
1661a3129944Smrg    opt_verbose=false
1662a3129944Smrg    opt_warning_types=
1663a3129944Smrg
1664a3129944Smrg    func_run_hooks func_options_prep ${1+"$@"}
1665a3129944Smrg
1666a3129944Smrg    # save modified positional parameters for caller
1667a3129944Smrg    func_options_prep_result=$func_run_hooks_result
1668266e564dSmrg}
1669266e564dSmrg
1670266e564dSmrg
1671a3129944Smrg# func_parse_options [ARG]...
1672a3129944Smrg# ---------------------------
1673a3129944Smrg# The main option parsing loop.
1674a3129944Smrgfunc_hookable func_parse_options
1675a3129944Smrgfunc_parse_options ()
1676266e564dSmrg{
1677a3129944Smrg    $debug_cmd
1678698f425bSmrg
1679a3129944Smrg    func_parse_options_result=
1680698f425bSmrg
1681a3129944Smrg    # this just eases exit handling
1682a3129944Smrg    while test $# -gt 0; do
1683a3129944Smrg      # Defer to hook functions for initial option parsing, so they
1684a3129944Smrg      # get priority in the event of reusing an option name.
1685a3129944Smrg      func_run_hooks func_parse_options ${1+"$@"}
1686266e564dSmrg
1687a3129944Smrg      # Adjust func_parse_options positional parameters to match
1688a3129944Smrg      eval set dummy "$func_run_hooks_result"; shift
1689266e564dSmrg
1690a3129944Smrg      # Break out of the loop if we already parsed every option.
1691a3129944Smrg      test $# -gt 0 || break
1692266e564dSmrg
1693a3129944Smrg      _G_opt=$1
1694a3129944Smrg      shift
1695a3129944Smrg      case $_G_opt in
1696a3129944Smrg        --debug|-x)   debug_cmd='set -x'
1697a3129944Smrg                      func_echo "enabling shell trace mode"
1698a3129944Smrg                      $debug_cmd
1699a3129944Smrg                      ;;
1700a3129944Smrg
1701a3129944Smrg        --no-warnings|--no-warning|--no-warn)
1702a3129944Smrg                      set dummy --warnings none ${1+"$@"}
1703a3129944Smrg                      shift
1704a3129944Smrg		      ;;
1705698f425bSmrg
1706a3129944Smrg        --warnings|--warning|-W)
1707a3129944Smrg                      test $# = 0 && func_missing_arg $_G_opt && break
1708a3129944Smrg                      case " $warning_categories $1" in
1709a3129944Smrg                        *" $1 "*)
1710a3129944Smrg                          # trailing space prevents matching last $1 above
1711a3129944Smrg                          func_append_uniq opt_warning_types " $1"
1712a3129944Smrg                          ;;
1713a3129944Smrg                        *all)
1714a3129944Smrg                          opt_warning_types=$warning_categories
1715a3129944Smrg                          ;;
1716a3129944Smrg                        *none)
1717a3129944Smrg                          opt_warning_types=none
1718a3129944Smrg                          warning_func=:
1719a3129944Smrg                          ;;
1720a3129944Smrg                        *error)
1721a3129944Smrg                          opt_warning_types=$warning_categories
1722a3129944Smrg                          warning_func=func_fatal_error
1723a3129944Smrg                          ;;
1724a3129944Smrg                        *)
1725a3129944Smrg                          func_fatal_error \
1726a3129944Smrg                             "unsupported warning category: '$1'"
1727a3129944Smrg                          ;;
1728a3129944Smrg                      esac
1729a3129944Smrg                      shift
1730a3129944Smrg                      ;;
1731a3129944Smrg
1732a3129944Smrg        --verbose|-v) opt_verbose=: ;;
1733a3129944Smrg        --version)    func_version ;;
1734a3129944Smrg        -\?|-h)       func_usage ;;
1735a3129944Smrg        --help)       func_help ;;
1736a3129944Smrg
1737a3129944Smrg	# Separate optargs to long options (plugins may need this):
1738a3129944Smrg	--*=*)        func_split_equals "$_G_opt"
1739a3129944Smrg	              set dummy "$func_split_equals_lhs" \
1740a3129944Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1741a3129944Smrg                      shift
1742a3129944Smrg                      ;;
1743a3129944Smrg
1744a3129944Smrg       # Separate optargs to short options:
1745a3129944Smrg        -W*)
1746a3129944Smrg                      func_split_short_opt "$_G_opt"
1747a3129944Smrg                      set dummy "$func_split_short_opt_name" \
1748a3129944Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1749a3129944Smrg                      shift
1750a3129944Smrg                      ;;
1751a3129944Smrg
1752a3129944Smrg        # Separate non-argument short options:
1753a3129944Smrg        -\?*|-h*|-v*|-x*)
1754a3129944Smrg                      func_split_short_opt "$_G_opt"
1755a3129944Smrg                      set dummy "$func_split_short_opt_name" \
1756a3129944Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1757a3129944Smrg                      shift
1758a3129944Smrg                      ;;
1759a3129944Smrg
1760a3129944Smrg        --)           break ;;
1761a3129944Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1762a3129944Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1763a3129944Smrg      esac
1764a3129944Smrg    done
1765a3129944Smrg
1766a3129944Smrg    # save modified positional parameters for caller
1767a3129944Smrg    func_quote_for_eval ${1+"$@"}
1768a3129944Smrg    func_parse_options_result=$func_quote_for_eval_result
1769266e564dSmrg}
1770266e564dSmrg
1771698f425bSmrg
1772a3129944Smrg# func_validate_options [ARG]...
1773a3129944Smrg# ------------------------------
1774a3129944Smrg# Perform any sanity checks on option settings and/or unconsumed
1775a3129944Smrg# arguments.
1776a3129944Smrgfunc_hookable func_validate_options
1777a3129944Smrgfunc_validate_options ()
1778266e564dSmrg{
1779a3129944Smrg    $debug_cmd
1780698f425bSmrg
1781a3129944Smrg    # Display all warnings if -W was not given.
1782a3129944Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1783698f425bSmrg
1784a3129944Smrg    func_run_hooks func_validate_options ${1+"$@"}
1785266e564dSmrg
1786a3129944Smrg    # Bail if the options were screwed!
1787a3129944Smrg    $exit_cmd $EXIT_FAILURE
1788a3129944Smrg
1789a3129944Smrg    # save modified positional parameters for caller
1790a3129944Smrg    func_validate_options_result=$func_run_hooks_result
17919ef0b394Smrg}
1792698f425bSmrg
1793698f425bSmrg
17949ef0b394Smrg
1795a3129944Smrg## ----------------- ##
1796a3129944Smrg## Helper functions. ##
1797a3129944Smrg## ----------------- ##
1798266e564dSmrg
1799a3129944Smrg# This section contains the helper functions used by the rest of the
1800a3129944Smrg# hookable option parser framework in ascii-betical order.
1801a3129944Smrg
1802a3129944Smrg
1803a3129944Smrg# func_fatal_help ARG...
1804a3129944Smrg# ----------------------
1805a3129944Smrg# Echo program name prefixed message to standard error, followed by
1806a3129944Smrg# a help hint, and exit.
1807a3129944Smrgfunc_fatal_help ()
1808698f425bSmrg{
1809a3129944Smrg    $debug_cmd
18109ef0b394Smrg
1811a3129944Smrg    eval \$ECHO \""Usage: $usage"\"
1812a3129944Smrg    eval \$ECHO \""$fatal_help"\"
1813a3129944Smrg    func_error ${1+"$@"}
1814a3129944Smrg    exit $EXIT_FAILURE
1815698f425bSmrg}
1816266e564dSmrg
1817a3129944Smrg
1818a3129944Smrg# func_help
1819a3129944Smrg# ---------
1820a3129944Smrg# Echo long help message to standard output and exit.
1821698f425bSmrgfunc_help ()
1822698f425bSmrg{
1823a3129944Smrg    $debug_cmd
1824a3129944Smrg
1825a3129944Smrg    func_usage_message
1826a3129944Smrg    $ECHO "$long_help_message"
1827a3129944Smrg    exit 0
1828698f425bSmrg}
1829266e564dSmrg
1830a3129944Smrg
1831a3129944Smrg# func_missing_arg ARGNAME
1832a3129944Smrg# ------------------------
1833698f425bSmrg# Echo program name prefixed message to standard error and set global
1834698f425bSmrg# exit_cmd.
1835698f425bSmrgfunc_missing_arg ()
1836698f425bSmrg{
1837a3129944Smrg    $debug_cmd
18389ef0b394Smrg
1839a3129944Smrg    func_error "Missing argument for '$1'."
1840698f425bSmrg    exit_cmd=exit
1841698f425bSmrg}
1842698f425bSmrg
1843698f425bSmrg
1844a3129944Smrg# func_split_equals STRING
1845a3129944Smrg# ------------------------
1846a3129944Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
1847a3129944Smrg# splitting STRING at the '=' sign.
1848a3129944Smrgtest -z "$_G_HAVE_XSI_OPS" \
1849a3129944Smrg    && (eval 'x=a/b/c;
1850a3129944Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
1851a3129944Smrg    && _G_HAVE_XSI_OPS=yes
1852a3129944Smrg
1853a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"
1854a3129944Smrgthen
1855a3129944Smrg  # This is an XSI compatible shell, allowing a faster implementation...
1856a3129944Smrg  eval 'func_split_equals ()
1857a3129944Smrg  {
1858a3129944Smrg      $debug_cmd
1859a3129944Smrg
1860a3129944Smrg      func_split_equals_lhs=${1%%=*}
1861a3129944Smrg      func_split_equals_rhs=${1#*=}
1862a3129944Smrg      test "x$func_split_equals_lhs" = "x$1" \
1863a3129944Smrg        && func_split_equals_rhs=
1864a3129944Smrg  }'
1865a3129944Smrgelse
1866a3129944Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1867a3129944Smrg  func_split_equals ()
1868a3129944Smrg  {
1869a3129944Smrg      $debug_cmd
1870a3129944Smrg
1871a3129944Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
1872a3129944Smrg      func_split_equals_rhs=
1873a3129944Smrg      test "x$func_split_equals_lhs" = "x$1" \
1874a3129944Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
1875a3129944Smrg  }
1876a3129944Smrgfi #func_split_equals
1877a3129944Smrg
1878a3129944Smrg
1879a3129944Smrg# func_split_short_opt SHORTOPT
1880a3129944Smrg# -----------------------------
18819ef0b394Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
18829ef0b394Smrg# variables after splitting SHORTOPT after the 2nd character.
1883a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"
1884a3129944Smrgthen
1885a3129944Smrg  # This is an XSI compatible shell, allowing a faster implementation...
1886a3129944Smrg  eval 'func_split_short_opt ()
1887a3129944Smrg  {
1888a3129944Smrg      $debug_cmd
1889a3129944Smrg
1890a3129944Smrg      func_split_short_opt_arg=${1#??}
1891a3129944Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1892a3129944Smrg  }'
1893a3129944Smrgelse
1894a3129944Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1895a3129944Smrg  func_split_short_opt ()
1896a3129944Smrg  {
1897a3129944Smrg      $debug_cmd
1898a3129944Smrg
1899a3129944Smrg      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1900a3129944Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1901a3129944Smrg  }
1902a3129944Smrgfi #func_split_short_opt
1903a3129944Smrg
1904a3129944Smrg
1905a3129944Smrg# func_usage
1906a3129944Smrg# ----------
1907a3129944Smrg# Echo short help message to standard output and exit.
1908a3129944Smrgfunc_usage ()
19099ef0b394Smrg{
1910a3129944Smrg    $debug_cmd
1911698f425bSmrg
1912a3129944Smrg    func_usage_message
1913a3129944Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
1914a3129944Smrg    exit 0
1915a3129944Smrg}
19169ef0b394Smrg
19179ef0b394Smrg
1918a3129944Smrg# func_usage_message
1919a3129944Smrg# ------------------
1920a3129944Smrg# Echo short help message to standard output.
1921a3129944Smrgfunc_usage_message ()
19229ef0b394Smrg{
1923a3129944Smrg    $debug_cmd
19249ef0b394Smrg
1925a3129944Smrg    eval \$ECHO \""Usage: $usage"\"
1926a3129944Smrg    echo
1927a3129944Smrg    $SED -n 's|^# ||
1928a3129944Smrg        /^Written by/{
1929a3129944Smrg          x;p;x
1930a3129944Smrg        }
1931a3129944Smrg	h
1932a3129944Smrg	/^Written by/q' < "$progpath"
1933a3129944Smrg    echo
1934a3129944Smrg    eval \$ECHO \""$usage_message"\"
1935a3129944Smrg}
19369ef0b394Smrg
1937698f425bSmrg
1938a3129944Smrg# func_version
1939a3129944Smrg# ------------
1940a3129944Smrg# Echo version message to standard output and exit.
1941a3129944Smrgfunc_version ()
1942a3129944Smrg{
1943a3129944Smrg    $debug_cmd
1944698f425bSmrg
1945a3129944Smrg    printf '%s\n' "$progname $scriptversion"
1946a3129944Smrg    $SED -n '
1947a3129944Smrg        /(C)/!b go
1948a3129944Smrg        :more
1949a3129944Smrg        /\./!{
1950a3129944Smrg          N
1951a3129944Smrg          s|\n# | |
1952a3129944Smrg          b more
1953a3129944Smrg        }
1954a3129944Smrg        :go
1955a3129944Smrg        /^# Written by /,/# warranty; / {
1956a3129944Smrg          s|^# ||
1957a3129944Smrg          s|^# *$||
1958a3129944Smrg          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
1959a3129944Smrg          p
1960a3129944Smrg        }
1961a3129944Smrg        /^# Written by / {
1962a3129944Smrg          s|^# ||
1963a3129944Smrg          p
1964a3129944Smrg        }
1965a3129944Smrg        /^warranty; /q' < "$progpath"
1966698f425bSmrg
1967a3129944Smrg    exit $?
1968a3129944Smrg}
1969266e564dSmrg
1970266e564dSmrg
1971a3129944Smrg# Local variables:
1972a3129944Smrg# mode: shell-script
1973a3129944Smrg# sh-indentation: 2
1974a3129944Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1975a3129944Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1976a3129944Smrg# time-stamp-time-zone: "UTC"
1977a3129944Smrg# End:
1978266e564dSmrg
1979a3129944Smrg# Set a version string.
1980a3129944Smrgscriptversion='(GNU libtool) 2.4.6'
1981266e564dSmrg
1982698f425bSmrg
1983a3129944Smrg# func_echo ARG...
1984a3129944Smrg# ----------------
1985a3129944Smrg# Libtool also displays the current mode in messages, so override
1986a3129944Smrg# funclib.sh func_echo with this custom definition.
1987a3129944Smrgfunc_echo ()
19889ef0b394Smrg{
1989a3129944Smrg    $debug_cmd
19909ef0b394Smrg
1991a3129944Smrg    _G_message=$*
19929ef0b394Smrg
1993a3129944Smrg    func_echo_IFS=$IFS
1994a3129944Smrg    IFS=$nl
1995a3129944Smrg    for _G_line in $_G_message; do
1996a3129944Smrg      IFS=$func_echo_IFS
1997a3129944Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
1998a3129944Smrg    done
1999a3129944Smrg    IFS=$func_echo_IFS
2000a3129944Smrg}
20019ef0b394Smrg
2002a3129944Smrg
2003a3129944Smrg# func_warning ARG...
2004a3129944Smrg# -------------------
2005a3129944Smrg# Libtool warnings are not categorized, so override funclib.sh
2006a3129944Smrg# func_warning with this simpler definition.
2007a3129944Smrgfunc_warning ()
20089ef0b394Smrg{
2009a3129944Smrg    $debug_cmd
20109ef0b394Smrg
2011a3129944Smrg    $warning_func ${1+"$@"}
2012a3129944Smrg}
20139ef0b394Smrg
20149ef0b394Smrg
2015a3129944Smrg## ---------------- ##
2016a3129944Smrg## Options parsing. ##
2017a3129944Smrg## ---------------- ##
2018a3129944Smrg
2019a3129944Smrg# Hook in the functions to make sure our own options are parsed during
2020a3129944Smrg# the option parsing loop.
2021a3129944Smrg
2022a3129944Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2023a3129944Smrg
2024a3129944Smrg# Short help message in response to '-h'.
2025a3129944Smrgusage_message="Options:
2026a3129944Smrg       --config             show all configuration variables
2027a3129944Smrg       --debug              enable verbose shell tracing
2028a3129944Smrg   -n, --dry-run            display commands without modifying any files
2029a3129944Smrg       --features           display basic configuration information and exit
2030a3129944Smrg       --mode=MODE          use operation mode MODE
2031a3129944Smrg       --no-warnings        equivalent to '-Wnone'
2032a3129944Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2033a3129944Smrg       --quiet, --silent    don't print informational messages
2034a3129944Smrg       --tag=TAG            use configuration variables from tag TAG
2035a3129944Smrg   -v, --verbose            print more informational messages than default
2036a3129944Smrg       --version            print version information
2037a3129944Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2038a3129944Smrg   -h, --help, --help-all   print short, long, or detailed help message
2039a3129944Smrg"
20409ef0b394Smrg
2041a3129944Smrg# Additional text appended to 'usage_message' in response to '--help'.
2042a3129944Smrgfunc_help ()
20439ef0b394Smrg{
2044a3129944Smrg    $debug_cmd
2045a3129944Smrg
2046a3129944Smrg    func_usage_message
2047a3129944Smrg    $ECHO "$long_help_message
2048a3129944Smrg
2049a3129944SmrgMODE must be one of the following:
2050a3129944Smrg
2051a3129944Smrg       clean           remove files from the build directory
2052a3129944Smrg       compile         compile a source file into a libtool object
2053a3129944Smrg       execute         automatically set library path, then run a program
2054a3129944Smrg       finish          complete the installation of libtool libraries
2055a3129944Smrg       install         install libraries or executables
2056a3129944Smrg       link            create a library or an executable
2057a3129944Smrg       uninstall       remove libraries from an installed directory
2058a3129944Smrg
2059a3129944SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2060a3129944Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2061a3129944SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2062a3129944Smrg
2063a3129944SmrgWhen reporting a bug, please describe a test case to reproduce it and
2064a3129944Smrginclude the following information:
2065a3129944Smrg
2066a3129944Smrg       host-triplet:   $host
2067a3129944Smrg       shell:          $SHELL
2068a3129944Smrg       compiler:       $LTCC
2069a3129944Smrg       compiler flags: $LTCFLAGS
2070a3129944Smrg       linker:         $LD (gnu? $with_gnu_ld)
2071a3129944Smrg       version:        $progname (GNU libtool) 2.4.6
2072a3129944Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2073a3129944Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2074a3129944Smrg
2075a3129944SmrgReport bugs to <bug-libtool@gnu.org>.
2076a3129944SmrgGNU libtool home page: <http://www.gnu.org/s/libtool/>.
2077a3129944SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2078a3129944Smrg    exit 0
2079a3129944Smrg}
20809ef0b394Smrg
20819ef0b394Smrg
2082a3129944Smrg# func_lo2o OBJECT-NAME
2083a3129944Smrg# ---------------------
2084a3129944Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2085a3129944Smrg# object suffix.
2086a3129944Smrg
2087a3129944Smrglo2o=s/\\.lo\$/.$objext/
2088a3129944Smrgo2lo=s/\\.$objext\$/.lo/
2089a3129944Smrg
2090a3129944Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2091a3129944Smrg  eval 'func_lo2o ()
2092a3129944Smrg  {
2093a3129944Smrg    case $1 in
2094a3129944Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2095a3129944Smrg      *   ) func_lo2o_result=$1               ;;
2096a3129944Smrg    esac
2097a3129944Smrg  }'
2098a3129944Smrg
2099a3129944Smrg  # func_xform LIBOBJ-OR-SOURCE
2100a3129944Smrg  # ---------------------------
2101a3129944Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2102a3129944Smrg  # suffix to a '.lo' libtool-object suffix.
2103a3129944Smrg  eval 'func_xform ()
2104a3129944Smrg  {
2105a3129944Smrg    func_xform_result=${1%.*}.lo
2106a3129944Smrg  }'
2107a3129944Smrgelse
2108a3129944Smrg  # ...otherwise fall back to using sed.
2109a3129944Smrg  func_lo2o ()
2110a3129944Smrg  {
2111a3129944Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2112a3129944Smrg  }
2113a3129944Smrg
2114a3129944Smrg  func_xform ()
2115a3129944Smrg  {
2116a3129944Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2117a3129944Smrg  }
2118a3129944Smrgfi
21199ef0b394Smrg
21209ef0b394Smrg
2121a3129944Smrg# func_fatal_configuration ARG...
2122a3129944Smrg# -------------------------------
2123698f425bSmrg# Echo program name prefixed message to standard error, followed by
2124698f425bSmrg# a configuration failure hint, and exit.
2125698f425bSmrgfunc_fatal_configuration ()
2126698f425bSmrg{
2127a3129944Smrg    func__fatal_error ${1+"$@"} \
2128a3129944Smrg      "See the $PACKAGE documentation for more information." \
2129a3129944Smrg      "Fatal configuration error."
2130698f425bSmrg}
2131266e564dSmrg
2132c5629e66Smrg
2133698f425bSmrg# func_config
2134a3129944Smrg# -----------
2135698f425bSmrg# Display the configuration for all the tags in this script.
2136698f425bSmrgfunc_config ()
2137698f425bSmrg{
2138698f425bSmrg    re_begincf='^# ### BEGIN LIBTOOL'
2139698f425bSmrg    re_endcf='^# ### END LIBTOOL'
2140698f425bSmrg
2141698f425bSmrg    # Default configuration.
2142698f425bSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2143266e564dSmrg
2144266e564dSmrg    # Now print the configurations for the tags.
2145266e564dSmrg    for tagname in $taglist; do
2146698f425bSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2147266e564dSmrg    done
2148266e564dSmrg
2149698f425bSmrg    exit $?
2150698f425bSmrg}
2151266e564dSmrg
2152a3129944Smrg
2153698f425bSmrg# func_features
2154a3129944Smrg# -------------
2155698f425bSmrg# Display the features supported by this script.
2156698f425bSmrgfunc_features ()
2157698f425bSmrg{
21589ef0b394Smrg    echo "host: $host"
2159a3129944Smrg    if test yes = "$build_libtool_libs"; then
21609ef0b394Smrg      echo "enable shared libraries"
2161266e564dSmrg    else
21629ef0b394Smrg      echo "disable shared libraries"
2163266e564dSmrg    fi
2164a3129944Smrg    if test yes = "$build_old_libs"; then
21659ef0b394Smrg      echo "enable static libraries"
2166266e564dSmrg    else
21679ef0b394Smrg      echo "disable static libraries"
2168266e564dSmrg    fi
2169698f425bSmrg
2170266e564dSmrg    exit $?
2171698f425bSmrg}
2172266e564dSmrg
2173a3129944Smrg
2174a3129944Smrg# func_enable_tag TAGNAME
2175a3129944Smrg# -----------------------
2176698f425bSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2177698f425bSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2178698f425bSmrg# variable here.
2179698f425bSmrgfunc_enable_tag ()
2180698f425bSmrg{
2181a3129944Smrg    # Global variable:
2182a3129944Smrg    tagname=$1
2183266e564dSmrg
2184a3129944Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2185a3129944Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2186a3129944Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2187266e564dSmrg
2188a3129944Smrg    # Validate tagname.
2189a3129944Smrg    case $tagname in
2190a3129944Smrg      *[!-_A-Za-z0-9,/]*)
2191a3129944Smrg        func_fatal_error "invalid tag name: $tagname"
2192a3129944Smrg        ;;
2193a3129944Smrg    esac
2194266e564dSmrg
2195a3129944Smrg    # Don't test for the "default" C tag, as we know it's
2196a3129944Smrg    # there but not specially marked.
2197a3129944Smrg    case $tagname in
2198a3129944Smrg        CC) ;;
2199698f425bSmrg    *)
2200a3129944Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2201a3129944Smrg	  taglist="$taglist $tagname"
2202a3129944Smrg
2203a3129944Smrg	  # Evaluate the configuration.  Be careful to quote the path
2204a3129944Smrg	  # and the sed script, to avoid splitting on whitespace, but
2205a3129944Smrg	  # also don't use non-portable quotes within backquotes within
2206a3129944Smrg	  # quotes we have to do it in 2 steps:
2207a3129944Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2208a3129944Smrg	  eval "$extractedcf"
2209a3129944Smrg        else
2210a3129944Smrg	  func_error "ignoring unknown tag $tagname"
2211a3129944Smrg        fi
2212a3129944Smrg        ;;
2213a3129944Smrg    esac
2214698f425bSmrg}
2215698f425bSmrg
2216a3129944Smrg
22179ef0b394Smrg# func_check_version_match
2218a3129944Smrg# ------------------------
22199ef0b394Smrg# Ensure that we are using m4 macros, and libtool script from the same
22209ef0b394Smrg# release of libtool.
22219ef0b394Smrgfunc_check_version_match ()
2222698f425bSmrg{
2223a3129944Smrg    if test "$package_revision" != "$macro_revision"; then
2224a3129944Smrg      if test "$VERSION" != "$macro_version"; then
2225a3129944Smrg        if test -z "$macro_version"; then
2226a3129944Smrg          cat >&2 <<_LT_EOF
22279ef0b394Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
22289ef0b394Smrg$progname: definition of this LT_INIT comes from an older release.
22299ef0b394Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
22309ef0b394Smrg$progname: and run autoconf again.
22319ef0b394Smrg_LT_EOF
2232a3129944Smrg        else
2233a3129944Smrg          cat >&2 <<_LT_EOF
22349ef0b394Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
22359ef0b394Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
22369ef0b394Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
22379ef0b394Smrg$progname: and run autoconf again.
22389ef0b394Smrg_LT_EOF
2239a3129944Smrg        fi
2240a3129944Smrg      else
2241a3129944Smrg        cat >&2 <<_LT_EOF
22429ef0b394Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
22439ef0b394Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
22449ef0b394Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
22459ef0b394Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
22469ef0b394Smrg_LT_EOF
2247a3129944Smrg      fi
2248266e564dSmrg
2249a3129944Smrg      exit $EXIT_MISMATCH
2250a3129944Smrg    fi
22519ef0b394Smrg}
22529ef0b394Smrg
22539ef0b394Smrg
2254a3129944Smrg# libtool_options_prep [ARG]...
2255a3129944Smrg# -----------------------------
2256a3129944Smrg# Preparation for options parsed by libtool.
2257a3129944Smrglibtool_options_prep ()
2258a3129944Smrg{
2259a3129944Smrg    $debug_mode
22609ef0b394Smrg
2261a3129944Smrg    # Option defaults:
2262a3129944Smrg    opt_config=false
2263a3129944Smrg    opt_dlopen=
2264a3129944Smrg    opt_dry_run=false
2265a3129944Smrg    opt_help=false
2266a3129944Smrg    opt_mode=
2267a3129944Smrg    opt_preserve_dup_deps=false
2268a3129944Smrg    opt_quiet=false
22699ef0b394Smrg
2270a3129944Smrg    nonopt=
2271a3129944Smrg    preserve_args=
22729ef0b394Smrg
2273a3129944Smrg    # Shorthand for --mode=foo, only valid as the first argument
2274a3129944Smrg    case $1 in
2275a3129944Smrg    clean|clea|cle|cl)
2276a3129944Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2277a3129944Smrg      ;;
2278a3129944Smrg    compile|compil|compi|comp|com|co|c)
2279a3129944Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2280a3129944Smrg      ;;
2281a3129944Smrg    execute|execut|execu|exec|exe|ex|e)
2282a3129944Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2283a3129944Smrg      ;;
2284a3129944Smrg    finish|finis|fini|fin|fi|f)
2285a3129944Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2286a3129944Smrg      ;;
2287a3129944Smrg    install|instal|insta|inst|ins|in|i)
2288a3129944Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2289a3129944Smrg      ;;
2290a3129944Smrg    link|lin|li|l)
2291a3129944Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2292a3129944Smrg      ;;
2293a3129944Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2294a3129944Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2295a3129944Smrg      ;;
2296a3129944Smrg    esac
2297a3129944Smrg
2298a3129944Smrg    # Pass back the list of options.
2299a3129944Smrg    func_quote_for_eval ${1+"$@"}
2300a3129944Smrg    libtool_options_prep_result=$func_quote_for_eval_result
2301a3129944Smrg}
2302a3129944Smrgfunc_add_hook func_options_prep libtool_options_prep
2303266e564dSmrg
23049ef0b394Smrg
2305a3129944Smrg# libtool_parse_options [ARG]...
2306a3129944Smrg# ---------------------------------
2307a3129944Smrg# Provide handling for libtool specific options.
2308a3129944Smrglibtool_parse_options ()
23099ef0b394Smrg{
2310a3129944Smrg    $debug_cmd
2311698f425bSmrg
2312a3129944Smrg    # Perform our own loop to consume as many options as possible in
2313a3129944Smrg    # each iteration.
2314a3129944Smrg    while test $# -gt 0; do
2315a3129944Smrg      _G_opt=$1
2316a3129944Smrg      shift
2317a3129944Smrg      case $_G_opt in
2318a3129944Smrg        --dry-run|--dryrun|-n)
2319a3129944Smrg                        opt_dry_run=:
2320a3129944Smrg                        ;;
2321a3129944Smrg
2322a3129944Smrg        --config)       func_config ;;
2323a3129944Smrg
2324a3129944Smrg        --dlopen|-dlopen)
2325a3129944Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2326a3129944Smrg}$1"
2327a3129944Smrg                        shift
2328a3129944Smrg                        ;;
2329a3129944Smrg
2330a3129944Smrg        --preserve-dup-deps)
2331a3129944Smrg                        opt_preserve_dup_deps=: ;;
2332a3129944Smrg
2333a3129944Smrg        --features)     func_features ;;
2334a3129944Smrg
2335a3129944Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2336a3129944Smrg
2337a3129944Smrg        --help)         opt_help=: ;;
2338a3129944Smrg
2339a3129944Smrg        --help-all)     opt_help=': help-all' ;;
2340a3129944Smrg
2341a3129944Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2342a3129944Smrg                        opt_mode=$1
2343a3129944Smrg                        case $1 in
2344a3129944Smrg                          # Valid mode arguments:
2345a3129944Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2346a3129944Smrg
2347a3129944Smrg                          # Catch anything else as an error
2348a3129944Smrg                          *) func_error "invalid argument for $_G_opt"
2349a3129944Smrg                             exit_cmd=exit
2350a3129944Smrg                             break
2351a3129944Smrg                             ;;
2352a3129944Smrg                        esac
2353a3129944Smrg                        shift
2354a3129944Smrg                        ;;
2355a3129944Smrg
2356a3129944Smrg        --no-silent|--no-quiet)
2357a3129944Smrg                        opt_quiet=false
2358a3129944Smrg                        func_append preserve_args " $_G_opt"
2359a3129944Smrg                        ;;
2360a3129944Smrg
2361a3129944Smrg        --no-warnings|--no-warning|--no-warn)
2362a3129944Smrg                        opt_warning=false
2363a3129944Smrg                        func_append preserve_args " $_G_opt"
2364a3129944Smrg                        ;;
2365a3129944Smrg
2366a3129944Smrg        --no-verbose)
2367a3129944Smrg                        opt_verbose=false
2368a3129944Smrg                        func_append preserve_args " $_G_opt"
2369a3129944Smrg                        ;;
2370a3129944Smrg
2371a3129944Smrg        --silent|--quiet)
2372a3129944Smrg                        opt_quiet=:
2373a3129944Smrg                        opt_verbose=false
2374a3129944Smrg                        func_append preserve_args " $_G_opt"
2375a3129944Smrg                        ;;
2376a3129944Smrg
2377a3129944Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2378a3129944Smrg                        opt_tag=$1
2379a3129944Smrg                        func_append preserve_args " $_G_opt $1"
2380a3129944Smrg                        func_enable_tag "$1"
2381a3129944Smrg                        shift
2382a3129944Smrg                        ;;
2383a3129944Smrg
2384a3129944Smrg        --verbose|-v)   opt_quiet=false
2385a3129944Smrg                        opt_verbose=:
2386a3129944Smrg                        func_append preserve_args " $_G_opt"
2387a3129944Smrg                        ;;
2388a3129944Smrg
2389a3129944Smrg	# An option not handled by this hook function:
2390a3129944Smrg        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
2391a3129944Smrg      esac
2392a3129944Smrg    done
23939ef0b394Smrg
23949ef0b394Smrg
2395a3129944Smrg    # save modified positional parameters for caller
2396a3129944Smrg    func_quote_for_eval ${1+"$@"}
2397a3129944Smrg    libtool_parse_options_result=$func_quote_for_eval_result
2398a3129944Smrg}
2399a3129944Smrgfunc_add_hook func_parse_options libtool_parse_options
2400698f425bSmrg
2401266e564dSmrg
2402698f425bSmrg
2403a3129944Smrg# libtool_validate_options [ARG]...
2404a3129944Smrg# ---------------------------------
2405a3129944Smrg# Perform any sanity checks on option settings and/or unconsumed
2406a3129944Smrg# arguments.
2407a3129944Smrglibtool_validate_options ()
2408a3129944Smrg{
2409a3129944Smrg    # save first non-option argument
2410a3129944Smrg    if test 0 -lt $#; then
2411a3129944Smrg      nonopt=$1
2412a3129944Smrg      shift
2413698f425bSmrg    fi
2414698f425bSmrg
2415a3129944Smrg    # preserve --debug
2416a3129944Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2417698f425bSmrg
2418a3129944Smrg    case $host in
2419a3129944Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2420a3129944Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2421a3129944Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2422a3129944Smrg        # don't eliminate duplications in $postdeps and $predeps
2423a3129944Smrg        opt_duplicate_compiler_generated_deps=:
2424a3129944Smrg        ;;
2425a3129944Smrg      *)
2426a3129944Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2427a3129944Smrg        ;;
2428a3129944Smrg    esac
2429698f425bSmrg
2430a3129944Smrg    $opt_help || {
2431a3129944Smrg      # Sanity checks first:
2432a3129944Smrg      func_check_version_match
2433a3129944Smrg
2434a3129944Smrg      test yes != "$build_libtool_libs" \
2435a3129944Smrg        && test yes != "$build_old_libs" \
2436a3129944Smrg        && func_fatal_configuration "not configured to build any kind of library"
2437a3129944Smrg
2438a3129944Smrg      # Darwin sucks
2439a3129944Smrg      eval std_shrext=\"$shrext_cmds\"
2440a3129944Smrg
2441a3129944Smrg      # Only execute mode is allowed to have -dlopen flags.
2442a3129944Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2443a3129944Smrg        func_error "unrecognized option '-dlopen'"
2444a3129944Smrg        $ECHO "$help" 1>&2
2445a3129944Smrg        exit $EXIT_FAILURE
2446a3129944Smrg      fi
2447698f425bSmrg
2448a3129944Smrg      # Change the help message to a mode-specific one.
2449a3129944Smrg      generic_help=$help
2450a3129944Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2451a3129944Smrg    }
2452698f425bSmrg
2453a3129944Smrg    # Pass back the unparsed argument list
2454a3129944Smrg    func_quote_for_eval ${1+"$@"}
2455a3129944Smrg    libtool_validate_options_result=$func_quote_for_eval_result
24569ef0b394Smrg}
2457a3129944Smrgfunc_add_hook func_validate_options libtool_validate_options
2458698f425bSmrg
2459266e564dSmrg
2460a3129944Smrg# Process options as early as possible so that --help and --version
2461a3129944Smrg# can return quickly.
2462a3129944Smrgfunc_options ${1+"$@"}
2463a3129944Smrgeval set dummy "$func_options_result"; shift
2464a3129944Smrg
2465266e564dSmrg
2466266e564dSmrg
24679ef0b394Smrg## ----------- ##
24689ef0b394Smrg##    Main.    ##
24699ef0b394Smrg## ----------- ##
2470266e564dSmrg
2471a3129944Smrgmagic='%%%MAGIC variable%%%'
2472a3129944Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2473a3129944Smrg
2474a3129944Smrg# Global variables.
2475a3129944Smrgextracted_archives=
2476a3129944Smrgextracted_serial=0
2477a3129944Smrg
2478a3129944Smrg# If this variable is set in any of the actions, the command in it
2479a3129944Smrg# will be execed at the end.  This prevents here-documents from being
2480a3129944Smrg# left over by shells.
2481a3129944Smrgexec_cmd=
2482a3129944Smrg
2483a3129944Smrg
2484a3129944Smrg# A function that is used when there is no print builtin or printf.
2485a3129944Smrgfunc_fallback_echo ()
2486a3129944Smrg{
2487a3129944Smrg  eval 'cat <<_LTECHO_EOF
2488a3129944Smrg$1
2489a3129944Smrg_LTECHO_EOF'
2490a3129944Smrg}
2491a3129944Smrg
2492a3129944Smrg# func_generated_by_libtool
2493a3129944Smrg# True iff stdin has been generated by Libtool. This function is only
2494a3129944Smrg# a basic sanity check; it will hardly flush out determined imposters.
2495a3129944Smrgfunc_generated_by_libtool_p ()
2496a3129944Smrg{
2497a3129944Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2498a3129944Smrg}
2499a3129944Smrg
2500698f425bSmrg# func_lalib_p file
2501a3129944Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2502698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2503698f425bSmrg# determined imposters.
2504698f425bSmrgfunc_lalib_p ()
2505698f425bSmrg{
2506698f425bSmrg    test -f "$1" &&
2507a3129944Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2508698f425bSmrg}
2509266e564dSmrg
2510698f425bSmrg# func_lalib_unsafe_p file
2511a3129944Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2512698f425bSmrg# This function implements the same check as func_lalib_p without
2513698f425bSmrg# resorting to external programs.  To this end, it redirects stdin and
2514698f425bSmrg# closes it afterwards, without saving the original file descriptor.
2515698f425bSmrg# As a safety measure, use it only where a negative result would be
2516a3129944Smrg# fatal anyway.  Works if 'file' does not exist.
2517698f425bSmrgfunc_lalib_unsafe_p ()
2518698f425bSmrg{
2519698f425bSmrg    lalib_p=no
2520698f425bSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2521698f425bSmrg	for lalib_p_l in 1 2 3 4
2522698f425bSmrg	do
2523698f425bSmrg	    read lalib_p_line
2524a3129944Smrg	    case $lalib_p_line in
2525698f425bSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2526698f425bSmrg	    esac
2527698f425bSmrg	done
2528698f425bSmrg	exec 0<&5 5<&-
2529698f425bSmrg    fi
2530a3129944Smrg    test yes = "$lalib_p"
2531698f425bSmrg}
2532266e564dSmrg
2533698f425bSmrg# func_ltwrapper_script_p file
2534698f425bSmrg# True iff FILE is a libtool wrapper script
2535698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2536698f425bSmrg# determined imposters.
2537698f425bSmrgfunc_ltwrapper_script_p ()
2538698f425bSmrg{
2539a3129944Smrg    test -f "$1" &&
2540a3129944Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2541698f425bSmrg}
2542266e564dSmrg
2543698f425bSmrg# func_ltwrapper_executable_p file
2544698f425bSmrg# True iff FILE is a libtool wrapper executable
2545698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2546698f425bSmrg# determined imposters.
2547698f425bSmrgfunc_ltwrapper_executable_p ()
2548698f425bSmrg{
2549698f425bSmrg    func_ltwrapper_exec_suffix=
2550698f425bSmrg    case $1 in
2551698f425bSmrg    *.exe) ;;
2552698f425bSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
2553698f425bSmrg    esac
2554698f425bSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2555698f425bSmrg}
2556698f425bSmrg
2557698f425bSmrg# func_ltwrapper_scriptname file
2558698f425bSmrg# Assumes file is an ltwrapper_executable
2559698f425bSmrg# uses $file to determine the appropriate filename for a
2560698f425bSmrg# temporary ltwrapper_script.
2561698f425bSmrgfunc_ltwrapper_scriptname ()
2562698f425bSmrg{
25639ef0b394Smrg    func_dirname_and_basename "$1" "" "."
25649ef0b394Smrg    func_stripname '' '.exe' "$func_basename_result"
2565a3129944Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2566698f425bSmrg}
2567698f425bSmrg
2568698f425bSmrg# func_ltwrapper_p file
2569698f425bSmrg# True iff FILE is a libtool wrapper script or wrapper executable
2570698f425bSmrg# This function is only a basic sanity check; it will hardly flush out
2571698f425bSmrg# determined imposters.
2572698f425bSmrgfunc_ltwrapper_p ()
2573698f425bSmrg{
2574698f425bSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2575698f425bSmrg}
2576698f425bSmrg
2577698f425bSmrg
2578698f425bSmrg# func_execute_cmds commands fail_cmd
2579698f425bSmrg# Execute tilde-delimited COMMANDS.
2580698f425bSmrg# If FAIL_CMD is given, eval that upon failure.
2581698f425bSmrg# FAIL_CMD may read-access the current command in variable CMD!
2582698f425bSmrgfunc_execute_cmds ()
2583698f425bSmrg{
2584a3129944Smrg    $debug_cmd
2585a3129944Smrg
2586698f425bSmrg    save_ifs=$IFS; IFS='~'
2587698f425bSmrg    for cmd in $1; do
2588a3129944Smrg      IFS=$sp$nl
2589698f425bSmrg      eval cmd=\"$cmd\"
2590a3129944Smrg      IFS=$save_ifs
2591698f425bSmrg      func_show_eval "$cmd" "${2-:}"
2592698f425bSmrg    done
2593698f425bSmrg    IFS=$save_ifs
2594698f425bSmrg}
2595698f425bSmrg
2596698f425bSmrg
2597698f425bSmrg# func_source file
2598698f425bSmrg# Source FILE, adding directory component if necessary.
2599698f425bSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
2600698f425bSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2601698f425bSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2602a3129944Smrg# 'FILE.' does not work on cygwin managed mounts.
2603698f425bSmrgfunc_source ()
2604698f425bSmrg{
2605a3129944Smrg    $debug_cmd
2606a3129944Smrg
2607698f425bSmrg    case $1 in
2608698f425bSmrg    */* | *\\*)	. "$1" ;;
2609698f425bSmrg    *)		. "./$1" ;;
2610698f425bSmrg    esac
2611698f425bSmrg}
2612698f425bSmrg
2613698f425bSmrg
26149ef0b394Smrg# func_resolve_sysroot PATH
26159ef0b394Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
26169ef0b394Smrg# func_resolve_sysroot_result
26179ef0b394Smrgfunc_resolve_sysroot ()
26189ef0b394Smrg{
26199ef0b394Smrg  func_resolve_sysroot_result=$1
26209ef0b394Smrg  case $func_resolve_sysroot_result in
26219ef0b394Smrg  =*)
26229ef0b394Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
26239ef0b394Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
26249ef0b394Smrg    ;;
26259ef0b394Smrg  esac
26269ef0b394Smrg}
26279ef0b394Smrg
26289ef0b394Smrg# func_replace_sysroot PATH
26299ef0b394Smrg# If PATH begins with the sysroot, replace it with = and
26309ef0b394Smrg# store the result into func_replace_sysroot_result.
26319ef0b394Smrgfunc_replace_sysroot ()
26329ef0b394Smrg{
2633a3129944Smrg  case $lt_sysroot:$1 in
26349ef0b394Smrg  ?*:"$lt_sysroot"*)
26359ef0b394Smrg    func_stripname "$lt_sysroot" '' "$1"
2636a3129944Smrg    func_replace_sysroot_result='='$func_stripname_result
26379ef0b394Smrg    ;;
26389ef0b394Smrg  *)
26399ef0b394Smrg    # Including no sysroot.
26409ef0b394Smrg    func_replace_sysroot_result=$1
26419ef0b394Smrg    ;;
26429ef0b394Smrg  esac
26439ef0b394Smrg}
26449ef0b394Smrg
2645698f425bSmrg# func_infer_tag arg
2646698f425bSmrg# Infer tagged configuration to use if any are available and
2647698f425bSmrg# if one wasn't chosen via the "--tag" command line option.
2648698f425bSmrg# Only attempt this if the compiler in the base compile
2649698f425bSmrg# command doesn't match the default compiler.
2650698f425bSmrg# arg is usually of the form 'gcc ...'
2651698f425bSmrgfunc_infer_tag ()
2652698f425bSmrg{
2653a3129944Smrg    $debug_cmd
2654a3129944Smrg
2655698f425bSmrg    if test -n "$available_tags" && test -z "$tagname"; then
2656698f425bSmrg      CC_quoted=
2657698f425bSmrg      for arg in $CC; do
26589ef0b394Smrg	func_append_quoted CC_quoted "$arg"
2659698f425bSmrg      done
26609ef0b394Smrg      CC_expanded=`func_echo_all $CC`
26619ef0b394Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2662698f425bSmrg      case $@ in
2663698f425bSmrg      # Blanks in the command may have been stripped by the calling shell,
2664698f425bSmrg      # but not from the CC environment variable when configure was run.
26659ef0b394Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
26669ef0b394Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2667698f425bSmrg      # Blanks at the start of $base_compile will cause this to fail
2668698f425bSmrg      # if we don't check for them as well.
2669698f425bSmrg      *)
2670698f425bSmrg	for z in $available_tags; do
2671698f425bSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2672698f425bSmrg	    # Evaluate the configuration.
2673a3129944Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2674698f425bSmrg	    CC_quoted=
2675698f425bSmrg	    for arg in $CC; do
2676698f425bSmrg	      # Double-quote args containing other shell metacharacters.
26779ef0b394Smrg	      func_append_quoted CC_quoted "$arg"
2678698f425bSmrg	    done
26799ef0b394Smrg	    CC_expanded=`func_echo_all $CC`
26809ef0b394Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2681698f425bSmrg	    case "$@ " in
26829ef0b394Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
26839ef0b394Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2684698f425bSmrg	      # The compiler in the base compile command matches
2685698f425bSmrg	      # the one in the tagged configuration.
2686698f425bSmrg	      # Assume this is the tagged configuration we want.
2687698f425bSmrg	      tagname=$z
2688698f425bSmrg	      break
2689698f425bSmrg	      ;;
2690698f425bSmrg	    esac
2691698f425bSmrg	  fi
2692698f425bSmrg	done
2693698f425bSmrg	# If $tagname still isn't set, then no tagged configuration
2694698f425bSmrg	# was found and let the user know that the "--tag" command
2695698f425bSmrg	# line option must be used.
2696698f425bSmrg	if test -z "$tagname"; then
2697698f425bSmrg	  func_echo "unable to infer tagged configuration"
2698a3129944Smrg	  func_fatal_error "specify a tag with '--tag'"
2699698f425bSmrg#	else
2700698f425bSmrg#	  func_verbose "using $tagname tagged configuration"
2701698f425bSmrg	fi
2702698f425bSmrg	;;
2703698f425bSmrg      esac
2704698f425bSmrg    fi
2705698f425bSmrg}
2706698f425bSmrg
2707698f425bSmrg
2708698f425bSmrg
2709698f425bSmrg# func_write_libtool_object output_name pic_name nonpic_name
2710698f425bSmrg# Create a libtool object file (analogous to a ".la" file),
2711698f425bSmrg# but don't create it if we're doing a dry run.
2712698f425bSmrgfunc_write_libtool_object ()
2713698f425bSmrg{
2714a3129944Smrg    write_libobj=$1
2715a3129944Smrg    if test yes = "$build_libtool_libs"; then
2716a3129944Smrg      write_lobj=\'$2\'
2717698f425bSmrg    else
2718698f425bSmrg      write_lobj=none
2719698f425bSmrg    fi
2720698f425bSmrg
2721a3129944Smrg    if test yes = "$build_old_libs"; then
2722a3129944Smrg      write_oldobj=\'$3\'
2723698f425bSmrg    else
2724698f425bSmrg      write_oldobj=none
2725698f425bSmrg    fi
2726698f425bSmrg
2727698f425bSmrg    $opt_dry_run || {
2728698f425bSmrg      cat >${write_libobj}T <<EOF
2729698f425bSmrg# $write_libobj - a libtool object file
2730a3129944Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2731698f425bSmrg#
2732698f425bSmrg# Please DO NOT delete this file!
2733698f425bSmrg# It is necessary for linking the library.
2734698f425bSmrg
2735698f425bSmrg# Name of the PIC object.
2736698f425bSmrgpic_object=$write_lobj
2737698f425bSmrg
2738698f425bSmrg# Name of the non-PIC object
2739698f425bSmrgnon_pic_object=$write_oldobj
2740698f425bSmrg
2741698f425bSmrgEOF
2742a3129944Smrg      $MV "${write_libobj}T" "$write_libobj"
2743698f425bSmrg    }
2744698f425bSmrg}
2745698f425bSmrg
27469ef0b394Smrg
27479ef0b394Smrg##################################################
27489ef0b394Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
27499ef0b394Smrg##################################################
27509ef0b394Smrg
27519ef0b394Smrg# func_convert_core_file_wine_to_w32 ARG
27529ef0b394Smrg# Helper function used by file name conversion functions when $build is *nix,
27539ef0b394Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
27549ef0b394Smrg# correctly configured wine environment available, with the winepath program
27559ef0b394Smrg# in $build's $PATH.
27569ef0b394Smrg#
27579ef0b394Smrg# ARG is the $build file name to be converted to w32 format.
27589ef0b394Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
27599ef0b394Smrg# be empty on error (or when ARG is empty)
27609ef0b394Smrgfunc_convert_core_file_wine_to_w32 ()
27619ef0b394Smrg{
2762a3129944Smrg  $debug_cmd
2763a3129944Smrg
2764a3129944Smrg  func_convert_core_file_wine_to_w32_result=$1
27659ef0b394Smrg  if test -n "$1"; then
27669ef0b394Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
27679ef0b394Smrg    # are forced to check the contents of stdout. On the other hand, if the
27689ef0b394Smrg    # command is not found, the shell will set an exit code of 127 and print
27699ef0b394Smrg    # *an error message* to stdout. So we must check for both error code of
27709ef0b394Smrg    # zero AND non-empty stdout, which explains the odd construction:
27719ef0b394Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
2772a3129944Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
27739ef0b394Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
2774a3129944Smrg        $SED -e "$sed_naive_backslashify"`
27759ef0b394Smrg    else
27769ef0b394Smrg      func_convert_core_file_wine_to_w32_result=
27779ef0b394Smrg    fi
27789ef0b394Smrg  fi
27799ef0b394Smrg}
27809ef0b394Smrg# end: func_convert_core_file_wine_to_w32
27819ef0b394Smrg
27829ef0b394Smrg
27839ef0b394Smrg# func_convert_core_path_wine_to_w32 ARG
27849ef0b394Smrg# Helper function used by path conversion functions when $build is *nix, and
27859ef0b394Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
27869ef0b394Smrg# configured wine environment available, with the winepath program in $build's
27879ef0b394Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
27889ef0b394Smrg#
27899ef0b394Smrg# ARG is path to be converted from $build format to win32.
27909ef0b394Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
27919ef0b394Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
27929ef0b394Smrg# are convertible, then the result may be empty.
27939ef0b394Smrgfunc_convert_core_path_wine_to_w32 ()
27949ef0b394Smrg{
2795a3129944Smrg  $debug_cmd
2796a3129944Smrg
27979ef0b394Smrg  # unfortunately, winepath doesn't convert paths, only file names
2798a3129944Smrg  func_convert_core_path_wine_to_w32_result=
27999ef0b394Smrg  if test -n "$1"; then
28009ef0b394Smrg    oldIFS=$IFS
28019ef0b394Smrg    IFS=:
28029ef0b394Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
28039ef0b394Smrg      IFS=$oldIFS
28049ef0b394Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
2805a3129944Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
28069ef0b394Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
2807a3129944Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
28089ef0b394Smrg        else
28099ef0b394Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
28109ef0b394Smrg        fi
28119ef0b394Smrg      fi
28129ef0b394Smrg    done
28139ef0b394Smrg    IFS=$oldIFS
28149ef0b394Smrg  fi
28159ef0b394Smrg}
28169ef0b394Smrg# end: func_convert_core_path_wine_to_w32
28179ef0b394Smrg
28189ef0b394Smrg
28199ef0b394Smrg# func_cygpath ARGS...
28209ef0b394Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
28219ef0b394Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
28229ef0b394Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
28239ef0b394Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
28249ef0b394Smrg# file name or path is assumed to be in w32 format, as previously converted
28259ef0b394Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
28269ef0b394Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
28279ef0b394Smrg# Cygwin format). Returns an empty string on error.
28289ef0b394Smrg#
28299ef0b394Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
28309ef0b394Smrg# be converted.
28319ef0b394Smrg#
28329ef0b394Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
28339ef0b394Smrg# environment variable; do not put it in $PATH.
28349ef0b394Smrgfunc_cygpath ()
28359ef0b394Smrg{
2836a3129944Smrg  $debug_cmd
2837a3129944Smrg
28389ef0b394Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
28399ef0b394Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
28409ef0b394Smrg    if test "$?" -ne 0; then
28419ef0b394Smrg      # on failure, ensure result is empty
28429ef0b394Smrg      func_cygpath_result=
28439ef0b394Smrg    fi
28449ef0b394Smrg  else
28459ef0b394Smrg    func_cygpath_result=
2846a3129944Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
28479ef0b394Smrg  fi
28489ef0b394Smrg}
28499ef0b394Smrg#end: func_cygpath
28509ef0b394Smrg
28519ef0b394Smrg
28529ef0b394Smrg# func_convert_core_msys_to_w32 ARG
28539ef0b394Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
28549ef0b394Smrg# result in func_convert_core_msys_to_w32_result.
28559ef0b394Smrgfunc_convert_core_msys_to_w32 ()
28569ef0b394Smrg{
2857a3129944Smrg  $debug_cmd
2858a3129944Smrg
28599ef0b394Smrg  # awkward: cmd appends spaces to result
28609ef0b394Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
2861a3129944Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
28629ef0b394Smrg}
28639ef0b394Smrg#end: func_convert_core_msys_to_w32
28649ef0b394Smrg
28659ef0b394Smrg
28669ef0b394Smrg# func_convert_file_check ARG1 ARG2
28679ef0b394Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
28689ef0b394Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
28699ef0b394Smrg# func_to_host_file_result to ARG1).
28709ef0b394Smrgfunc_convert_file_check ()
28719ef0b394Smrg{
2872a3129944Smrg  $debug_cmd
2873a3129944Smrg
2874a3129944Smrg  if test -z "$2" && test -n "$1"; then
28759ef0b394Smrg    func_error "Could not determine host file name corresponding to"
2876a3129944Smrg    func_error "  '$1'"
28779ef0b394Smrg    func_error "Continuing, but uninstalled executables may not work."
28789ef0b394Smrg    # Fallback:
2879a3129944Smrg    func_to_host_file_result=$1
28809ef0b394Smrg  fi
28819ef0b394Smrg}
28829ef0b394Smrg# end func_convert_file_check
28839ef0b394Smrg
28849ef0b394Smrg
28859ef0b394Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
28869ef0b394Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
28879ef0b394Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
28889ef0b394Smrg# func_to_host_file_result to a simplistic fallback value (see below).
28899ef0b394Smrgfunc_convert_path_check ()
28909ef0b394Smrg{
2891a3129944Smrg  $debug_cmd
2892a3129944Smrg
28939ef0b394Smrg  if test -z "$4" && test -n "$3"; then
28949ef0b394Smrg    func_error "Could not determine the host path corresponding to"
2895a3129944Smrg    func_error "  '$3'"
28969ef0b394Smrg    func_error "Continuing, but uninstalled executables may not work."
28979ef0b394Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
28989ef0b394Smrg    # should not be "improved".  See libtool.info.
28999ef0b394Smrg    if test "x$1" != "x$2"; then
29009ef0b394Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
29019ef0b394Smrg      func_to_host_path_result=`echo "$3" |
29029ef0b394Smrg        $SED -e "$lt_replace_pathsep_chars"`
29039ef0b394Smrg    else
2904a3129944Smrg      func_to_host_path_result=$3
29059ef0b394Smrg    fi
29069ef0b394Smrg  fi
29079ef0b394Smrg}
29089ef0b394Smrg# end func_convert_path_check
29099ef0b394Smrg
29109ef0b394Smrg
29119ef0b394Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
29129ef0b394Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
29139ef0b394Smrg# and appending REPL if ORIG matches BACKPAT.
29149ef0b394Smrgfunc_convert_path_front_back_pathsep ()
29159ef0b394Smrg{
2916a3129944Smrg  $debug_cmd
2917a3129944Smrg
29189ef0b394Smrg  case $4 in
2919a3129944Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
29209ef0b394Smrg    ;;
29219ef0b394Smrg  esac
29229ef0b394Smrg  case $4 in
29239ef0b394Smrg  $2 ) func_append func_to_host_path_result "$3"
29249ef0b394Smrg    ;;
29259ef0b394Smrg  esac
29269ef0b394Smrg}
29279ef0b394Smrg# end func_convert_path_front_back_pathsep
29289ef0b394Smrg
29299ef0b394Smrg
29309ef0b394Smrg##################################################
29319ef0b394Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
29329ef0b394Smrg##################################################
2933a3129944Smrg# invoked via '$to_host_file_cmd ARG'
29349ef0b394Smrg#
29359ef0b394Smrg# In each case, ARG is the path to be converted from $build to $host format.
29369ef0b394Smrg# Result will be available in $func_to_host_file_result.
29379ef0b394Smrg
29389ef0b394Smrg
29399ef0b394Smrg# func_to_host_file ARG
29409ef0b394Smrg# Converts the file name ARG from $build format to $host format. Return result
29419ef0b394Smrg# in func_to_host_file_result.
29429ef0b394Smrgfunc_to_host_file ()
29439ef0b394Smrg{
2944a3129944Smrg  $debug_cmd
2945a3129944Smrg
29469ef0b394Smrg  $to_host_file_cmd "$1"
29479ef0b394Smrg}
29489ef0b394Smrg# end func_to_host_file
29499ef0b394Smrg
29509ef0b394Smrg
29519ef0b394Smrg# func_to_tool_file ARG LAZY
29529ef0b394Smrg# converts the file name ARG from $build format to toolchain format. Return
29539ef0b394Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
29549ef0b394Smrg# in (the comma separated) LAZY, no conversion takes place.
29559ef0b394Smrgfunc_to_tool_file ()
29569ef0b394Smrg{
2957a3129944Smrg  $debug_cmd
2958a3129944Smrg
29599ef0b394Smrg  case ,$2, in
29609ef0b394Smrg    *,"$to_tool_file_cmd",*)
29619ef0b394Smrg      func_to_tool_file_result=$1
29629ef0b394Smrg      ;;
29639ef0b394Smrg    *)
29649ef0b394Smrg      $to_tool_file_cmd "$1"
29659ef0b394Smrg      func_to_tool_file_result=$func_to_host_file_result
29669ef0b394Smrg      ;;
29679ef0b394Smrg  esac
29689ef0b394Smrg}
29699ef0b394Smrg# end func_to_tool_file
29709ef0b394Smrg
29719ef0b394Smrg
29729ef0b394Smrg# func_convert_file_noop ARG
29739ef0b394Smrg# Copy ARG to func_to_host_file_result.
29749ef0b394Smrgfunc_convert_file_noop ()
29759ef0b394Smrg{
2976a3129944Smrg  func_to_host_file_result=$1
29779ef0b394Smrg}
29789ef0b394Smrg# end func_convert_file_noop
29799ef0b394Smrg
29809ef0b394Smrg
29819ef0b394Smrg# func_convert_file_msys_to_w32 ARG
29829ef0b394Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
29839ef0b394Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
29849ef0b394Smrg# func_to_host_file_result.
29859ef0b394Smrgfunc_convert_file_msys_to_w32 ()
29869ef0b394Smrg{
2987a3129944Smrg  $debug_cmd
2988a3129944Smrg
2989a3129944Smrg  func_to_host_file_result=$1
29909ef0b394Smrg  if test -n "$1"; then
29919ef0b394Smrg    func_convert_core_msys_to_w32 "$1"
2992a3129944Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
29939ef0b394Smrg  fi
29949ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
29959ef0b394Smrg}
29969ef0b394Smrg# end func_convert_file_msys_to_w32
29979ef0b394Smrg
29989ef0b394Smrg
29999ef0b394Smrg# func_convert_file_cygwin_to_w32 ARG
30009ef0b394Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
30019ef0b394Smrg# func_to_host_file_result.
30029ef0b394Smrgfunc_convert_file_cygwin_to_w32 ()
30039ef0b394Smrg{
3004a3129944Smrg  $debug_cmd
3005a3129944Smrg
3006a3129944Smrg  func_to_host_file_result=$1
30079ef0b394Smrg  if test -n "$1"; then
30089ef0b394Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
30099ef0b394Smrg    # LT_CYGPATH in this case.
30109ef0b394Smrg    func_to_host_file_result=`cygpath -m "$1"`
30119ef0b394Smrg  fi
30129ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
30139ef0b394Smrg}
30149ef0b394Smrg# end func_convert_file_cygwin_to_w32
30159ef0b394Smrg
30169ef0b394Smrg
30179ef0b394Smrg# func_convert_file_nix_to_w32 ARG
30189ef0b394Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
30199ef0b394Smrg# and a working winepath. Returns result in func_to_host_file_result.
30209ef0b394Smrgfunc_convert_file_nix_to_w32 ()
30219ef0b394Smrg{
3022a3129944Smrg  $debug_cmd
3023a3129944Smrg
3024a3129944Smrg  func_to_host_file_result=$1
30259ef0b394Smrg  if test -n "$1"; then
30269ef0b394Smrg    func_convert_core_file_wine_to_w32 "$1"
3027a3129944Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
30289ef0b394Smrg  fi
30299ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
30309ef0b394Smrg}
30319ef0b394Smrg# end func_convert_file_nix_to_w32
30329ef0b394Smrg
30339ef0b394Smrg
30349ef0b394Smrg# func_convert_file_msys_to_cygwin ARG
30359ef0b394Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
30369ef0b394Smrg# Returns result in func_to_host_file_result.
30379ef0b394Smrgfunc_convert_file_msys_to_cygwin ()
30389ef0b394Smrg{
3039a3129944Smrg  $debug_cmd
3040a3129944Smrg
3041a3129944Smrg  func_to_host_file_result=$1
30429ef0b394Smrg  if test -n "$1"; then
30439ef0b394Smrg    func_convert_core_msys_to_w32 "$1"
30449ef0b394Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3045a3129944Smrg    func_to_host_file_result=$func_cygpath_result
30469ef0b394Smrg  fi
30479ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
30489ef0b394Smrg}
30499ef0b394Smrg# end func_convert_file_msys_to_cygwin
30509ef0b394Smrg
30519ef0b394Smrg
30529ef0b394Smrg# func_convert_file_nix_to_cygwin ARG
30539ef0b394Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
30549ef0b394Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
30559ef0b394Smrg# in func_to_host_file_result.
30569ef0b394Smrgfunc_convert_file_nix_to_cygwin ()
30579ef0b394Smrg{
3058a3129944Smrg  $debug_cmd
3059a3129944Smrg
3060a3129944Smrg  func_to_host_file_result=$1
30619ef0b394Smrg  if test -n "$1"; then
30629ef0b394Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
30639ef0b394Smrg    func_convert_core_file_wine_to_w32 "$1"
30649ef0b394Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3065a3129944Smrg    func_to_host_file_result=$func_cygpath_result
30669ef0b394Smrg  fi
30679ef0b394Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
30689ef0b394Smrg}
30699ef0b394Smrg# end func_convert_file_nix_to_cygwin
30709ef0b394Smrg
30719ef0b394Smrg
30729ef0b394Smrg#############################################
30739ef0b394Smrg# $build to $host PATH CONVERSION FUNCTIONS #
30749ef0b394Smrg#############################################
3075a3129944Smrg# invoked via '$to_host_path_cmd ARG'
30769ef0b394Smrg#
30779ef0b394Smrg# In each case, ARG is the path to be converted from $build to $host format.
30789ef0b394Smrg# The result will be available in $func_to_host_path_result.
30799ef0b394Smrg#
30809ef0b394Smrg# Path separators are also converted from $build format to $host format.  If
30819ef0b394Smrg# ARG begins or ends with a path separator character, it is preserved (but
30829ef0b394Smrg# converted to $host format) on output.
30839ef0b394Smrg#
30849ef0b394Smrg# All path conversion functions are named using the following convention:
30859ef0b394Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
30869ef0b394Smrg#   path conversion function         : func_convert_path_X_to_Y ()
30879ef0b394Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
30889ef0b394Smrg# same.  If conversion functions are added for new $build/$host combinations,
30899ef0b394Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
30909ef0b394Smrg# will break.
30919ef0b394Smrg
30929ef0b394Smrg
30939ef0b394Smrg# func_init_to_host_path_cmd
30949ef0b394Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
30959ef0b394Smrg# appropriate value, based on the value of $to_host_file_cmd.
30969ef0b394Smrgto_host_path_cmd=
30979ef0b394Smrgfunc_init_to_host_path_cmd ()
30989ef0b394Smrg{
3099a3129944Smrg  $debug_cmd
3100a3129944Smrg
31019ef0b394Smrg  if test -z "$to_host_path_cmd"; then
31029ef0b394Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3103a3129944Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
31049ef0b394Smrg  fi
31059ef0b394Smrg}
31069ef0b394Smrg
31079ef0b394Smrg
31089ef0b394Smrg# func_to_host_path ARG
31099ef0b394Smrg# Converts the path ARG from $build format to $host format. Return result
31109ef0b394Smrg# in func_to_host_path_result.
31119ef0b394Smrgfunc_to_host_path ()
31129ef0b394Smrg{
3113a3129944Smrg  $debug_cmd
3114a3129944Smrg
31159ef0b394Smrg  func_init_to_host_path_cmd
31169ef0b394Smrg  $to_host_path_cmd "$1"
31179ef0b394Smrg}
31189ef0b394Smrg# end func_to_host_path
31199ef0b394Smrg
31209ef0b394Smrg
31219ef0b394Smrg# func_convert_path_noop ARG
31229ef0b394Smrg# Copy ARG to func_to_host_path_result.
31239ef0b394Smrgfunc_convert_path_noop ()
31249ef0b394Smrg{
3125a3129944Smrg  func_to_host_path_result=$1
31269ef0b394Smrg}
31279ef0b394Smrg# end func_convert_path_noop
31289ef0b394Smrg
31299ef0b394Smrg
31309ef0b394Smrg# func_convert_path_msys_to_w32 ARG
31319ef0b394Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
31329ef0b394Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
31339ef0b394Smrg# func_to_host_path_result.
31349ef0b394Smrgfunc_convert_path_msys_to_w32 ()
31359ef0b394Smrg{
3136a3129944Smrg  $debug_cmd
3137a3129944Smrg
3138a3129944Smrg  func_to_host_path_result=$1
31399ef0b394Smrg  if test -n "$1"; then
31409ef0b394Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
31419ef0b394Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
31429ef0b394Smrg    # and winepath ignores them completely.
31439ef0b394Smrg    func_stripname : : "$1"
31449ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
31459ef0b394Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3146a3129944Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
31479ef0b394Smrg    func_convert_path_check : ";" \
31489ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31499ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31509ef0b394Smrg  fi
31519ef0b394Smrg}
31529ef0b394Smrg# end func_convert_path_msys_to_w32
31539ef0b394Smrg
31549ef0b394Smrg
31559ef0b394Smrg# func_convert_path_cygwin_to_w32 ARG
31569ef0b394Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
31579ef0b394Smrg# func_to_host_file_result.
31589ef0b394Smrgfunc_convert_path_cygwin_to_w32 ()
31599ef0b394Smrg{
3160a3129944Smrg  $debug_cmd
3161a3129944Smrg
3162a3129944Smrg  func_to_host_path_result=$1
31639ef0b394Smrg  if test -n "$1"; then
31649ef0b394Smrg    # See func_convert_path_msys_to_w32:
31659ef0b394Smrg    func_stripname : : "$1"
31669ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
31679ef0b394Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
31689ef0b394Smrg    func_convert_path_check : ";" \
31699ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31709ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31719ef0b394Smrg  fi
31729ef0b394Smrg}
31739ef0b394Smrg# end func_convert_path_cygwin_to_w32
31749ef0b394Smrg
31759ef0b394Smrg
31769ef0b394Smrg# func_convert_path_nix_to_w32 ARG
31779ef0b394Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
31789ef0b394Smrg# a working winepath.  Returns result in func_to_host_file_result.
31799ef0b394Smrgfunc_convert_path_nix_to_w32 ()
31809ef0b394Smrg{
3181a3129944Smrg  $debug_cmd
3182a3129944Smrg
3183a3129944Smrg  func_to_host_path_result=$1
31849ef0b394Smrg  if test -n "$1"; then
31859ef0b394Smrg    # See func_convert_path_msys_to_w32:
31869ef0b394Smrg    func_stripname : : "$1"
31879ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
31889ef0b394Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3189a3129944Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
31909ef0b394Smrg    func_convert_path_check : ";" \
31919ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31929ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31939ef0b394Smrg  fi
31949ef0b394Smrg}
31959ef0b394Smrg# end func_convert_path_nix_to_w32
31969ef0b394Smrg
31979ef0b394Smrg
31989ef0b394Smrg# func_convert_path_msys_to_cygwin ARG
31999ef0b394Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
32009ef0b394Smrg# Returns result in func_to_host_file_result.
32019ef0b394Smrgfunc_convert_path_msys_to_cygwin ()
32029ef0b394Smrg{
3203a3129944Smrg  $debug_cmd
3204a3129944Smrg
3205a3129944Smrg  func_to_host_path_result=$1
32069ef0b394Smrg  if test -n "$1"; then
32079ef0b394Smrg    # See func_convert_path_msys_to_w32:
32089ef0b394Smrg    func_stripname : : "$1"
32099ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
32109ef0b394Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
32119ef0b394Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3212a3129944Smrg    func_to_host_path_result=$func_cygpath_result
32139ef0b394Smrg    func_convert_path_check : : \
32149ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32159ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
32169ef0b394Smrg  fi
32179ef0b394Smrg}
32189ef0b394Smrg# end func_convert_path_msys_to_cygwin
32199ef0b394Smrg
32209ef0b394Smrg
32219ef0b394Smrg# func_convert_path_nix_to_cygwin ARG
32229ef0b394Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
32239ef0b394Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
32249ef0b394Smrg# func_to_host_file_result.
32259ef0b394Smrgfunc_convert_path_nix_to_cygwin ()
32269ef0b394Smrg{
3227a3129944Smrg  $debug_cmd
3228a3129944Smrg
3229a3129944Smrg  func_to_host_path_result=$1
32309ef0b394Smrg  if test -n "$1"; then
32319ef0b394Smrg    # Remove leading and trailing path separator characters from
32329ef0b394Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
32339ef0b394Smrg    # into '.;' and ';.', and winepath ignores them completely.
32349ef0b394Smrg    func_stripname : : "$1"
32359ef0b394Smrg    func_to_host_path_tmp1=$func_stripname_result
32369ef0b394Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
32379ef0b394Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3238a3129944Smrg    func_to_host_path_result=$func_cygpath_result
32399ef0b394Smrg    func_convert_path_check : : \
32409ef0b394Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32419ef0b394Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
32429ef0b394Smrg  fi
32439ef0b394Smrg}
32449ef0b394Smrg# end func_convert_path_nix_to_cygwin
32459ef0b394Smrg
32469ef0b394Smrg
3247a3129944Smrg# func_dll_def_p FILE
3248a3129944Smrg# True iff FILE is a Windows DLL '.def' file.
3249a3129944Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3250a3129944Smrgfunc_dll_def_p ()
3251a3129944Smrg{
3252a3129944Smrg  $debug_cmd
3253a3129944Smrg
3254a3129944Smrg  func_dll_def_p_tmp=`$SED -n \
3255a3129944Smrg    -e 's/^[	 ]*//' \
3256a3129944Smrg    -e '/^\(;.*\)*$/d' \
3257a3129944Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3258a3129944Smrg    -e q \
3259a3129944Smrg    "$1"`
3260a3129944Smrg  test DEF = "$func_dll_def_p_tmp"
3261a3129944Smrg}
3262a3129944Smrg
3263a3129944Smrg
3264698f425bSmrg# func_mode_compile arg...
3265698f425bSmrgfunc_mode_compile ()
3266698f425bSmrg{
3267a3129944Smrg    $debug_cmd
3268a3129944Smrg
3269698f425bSmrg    # Get the compilation command and the source file.
3270698f425bSmrg    base_compile=
3271a3129944Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3272698f425bSmrg    suppress_opt=yes
3273698f425bSmrg    suppress_output=
3274698f425bSmrg    arg_mode=normal
3275698f425bSmrg    libobj=
3276698f425bSmrg    later=
3277698f425bSmrg    pie_flag=
3278698f425bSmrg
3279698f425bSmrg    for arg
3280698f425bSmrg    do
3281698f425bSmrg      case $arg_mode in
3282698f425bSmrg      arg  )
3283698f425bSmrg	# do not "continue".  Instead, add this to base_compile
3284a3129944Smrg	lastarg=$arg
3285698f425bSmrg	arg_mode=normal
3286698f425bSmrg	;;
3287698f425bSmrg
3288698f425bSmrg      target )
3289a3129944Smrg	libobj=$arg
3290698f425bSmrg	arg_mode=normal
3291698f425bSmrg	continue
3292698f425bSmrg	;;
3293698f425bSmrg
3294698f425bSmrg      normal )
3295698f425bSmrg	# Accept any command-line options.
3296698f425bSmrg	case $arg in
3297698f425bSmrg	-o)
3298698f425bSmrg	  test -n "$libobj" && \
3299a3129944Smrg	    func_fatal_error "you cannot specify '-o' more than once"
3300698f425bSmrg	  arg_mode=target
3301698f425bSmrg	  continue
3302698f425bSmrg	  ;;
3303698f425bSmrg
3304698f425bSmrg	-pie | -fpie | -fPIE)
33059ef0b394Smrg          func_append pie_flag " $arg"
3306698f425bSmrg	  continue
3307698f425bSmrg	  ;;
3308698f425bSmrg
3309698f425bSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
33109ef0b394Smrg	  func_append later " $arg"
3311698f425bSmrg	  continue
3312698f425bSmrg	  ;;
3313266e564dSmrg
3314266e564dSmrg	-no-suppress)
3315266e564dSmrg	  suppress_opt=no
3316266e564dSmrg	  continue
3317266e564dSmrg	  ;;
3318266e564dSmrg
3319266e564dSmrg	-Xcompiler)
3320266e564dSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3321266e564dSmrg	  continue      #  The current "srcfile" will either be retained or
3322266e564dSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3323266e564dSmrg
3324266e564dSmrg	-Wc,*)
3325698f425bSmrg	  func_stripname '-Wc,' '' "$arg"
3326698f425bSmrg	  args=$func_stripname_result
3327266e564dSmrg	  lastarg=
3328a3129944Smrg	  save_ifs=$IFS; IFS=,
3329698f425bSmrg	  for arg in $args; do
3330a3129944Smrg	    IFS=$save_ifs
33319ef0b394Smrg	    func_append_quoted lastarg "$arg"
3332266e564dSmrg	  done
3333a3129944Smrg	  IFS=$save_ifs
3334698f425bSmrg	  func_stripname ' ' '' "$lastarg"
3335698f425bSmrg	  lastarg=$func_stripname_result
3336266e564dSmrg
3337266e564dSmrg	  # Add the arguments to base_compile.
33389ef0b394Smrg	  func_append base_compile " $lastarg"
3339266e564dSmrg	  continue
3340266e564dSmrg	  ;;
3341266e564dSmrg
3342698f425bSmrg	*)
3343266e564dSmrg	  # Accept the current argument as the source file.
3344266e564dSmrg	  # The previous "srcfile" becomes the current argument.
3345266e564dSmrg	  #
3346a3129944Smrg	  lastarg=$srcfile
3347a3129944Smrg	  srcfile=$arg
3348266e564dSmrg	  ;;
3349266e564dSmrg	esac  #  case $arg
3350266e564dSmrg	;;
3351266e564dSmrg      esac    #  case $arg_mode
3352266e564dSmrg
3353266e564dSmrg      # Aesthetically quote the previous argument.
33549ef0b394Smrg      func_append_quoted base_compile "$lastarg"
3355266e564dSmrg    done # for arg
3356266e564dSmrg
3357266e564dSmrg    case $arg_mode in
3358266e564dSmrg    arg)
3359698f425bSmrg      func_fatal_error "you must specify an argument for -Xcompile"
3360266e564dSmrg      ;;
3361266e564dSmrg    target)
3362a3129944Smrg      func_fatal_error "you must specify a target with '-o'"
3363266e564dSmrg      ;;
3364266e564dSmrg    *)
3365266e564dSmrg      # Get the name of the library object.
3366698f425bSmrg      test -z "$libobj" && {
3367698f425bSmrg	func_basename "$srcfile"
3368a3129944Smrg	libobj=$func_basename_result
3369698f425bSmrg      }
3370266e564dSmrg      ;;
3371266e564dSmrg    esac
3372266e564dSmrg
3373266e564dSmrg    # Recognize several different file suffixes.
3374266e564dSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3375266e564dSmrg    case $libobj in
3376698f425bSmrg    *.[cCFSifmso] | \
3377698f425bSmrg    *.ada | *.adb | *.ads | *.asm | \
3378698f425bSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3379fb5e8d76Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3380698f425bSmrg      func_xform "$libobj"
3381698f425bSmrg      libobj=$func_xform_result
3382698f425bSmrg      ;;
3383266e564dSmrg    esac
3384266e564dSmrg
3385266e564dSmrg    case $libobj in
3386698f425bSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3387266e564dSmrg    *)
3388a3129944Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3389266e564dSmrg      ;;
3390266e564dSmrg    esac
3391266e564dSmrg
3392266e564dSmrg    func_infer_tag $base_compile
3393266e564dSmrg
3394266e564dSmrg    for arg in $later; do
3395266e564dSmrg      case $arg in
3396698f425bSmrg      -shared)
3397a3129944Smrg	test yes = "$build_libtool_libs" \
3398a3129944Smrg	  || func_fatal_configuration "cannot build a shared library"
3399698f425bSmrg	build_old_libs=no
3400698f425bSmrg	continue
3401698f425bSmrg	;;
3402698f425bSmrg
3403266e564dSmrg      -static)
3404698f425bSmrg	build_libtool_libs=no
3405266e564dSmrg	build_old_libs=yes
3406266e564dSmrg	continue
3407266e564dSmrg	;;
3408266e564dSmrg
3409266e564dSmrg      -prefer-pic)
3410266e564dSmrg	pic_mode=yes
3411266e564dSmrg	continue
3412266e564dSmrg	;;
3413266e564dSmrg
3414266e564dSmrg      -prefer-non-pic)
3415266e564dSmrg	pic_mode=no
3416266e564dSmrg	continue
3417266e564dSmrg	;;
3418266e564dSmrg      esac
3419266e564dSmrg    done
3420266e564dSmrg
3421698f425bSmrg    func_quote_for_eval "$libobj"
3422698f425bSmrg    test "X$libobj" != "X$func_quote_for_eval_result" \
3423698f425bSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3424a3129944Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3425698f425bSmrg    func_dirname_and_basename "$obj" "/" ""
3426a3129944Smrg    objname=$func_basename_result
3427a3129944Smrg    xdir=$func_dirname_result
3428a3129944Smrg    lobj=$xdir$objdir/$objname
3429266e564dSmrg
3430698f425bSmrg    test -z "$base_compile" && \
3431698f425bSmrg      func_fatal_help "you must specify a compilation command"
3432266e564dSmrg
3433266e564dSmrg    # Delete any leftover library objects.
3434a3129944Smrg    if test yes = "$build_old_libs"; then
3435266e564dSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3436266e564dSmrg    else
3437266e564dSmrg      removelist="$lobj $libobj ${libobj}T"
3438266e564dSmrg    fi
3439266e564dSmrg
3440266e564dSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3441266e564dSmrg    case $host_os in
3442698f425bSmrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3443266e564dSmrg      pic_mode=default
3444266e564dSmrg      ;;
3445266e564dSmrg    esac
3446a3129944Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3447266e564dSmrg      # non-PIC code in shared libraries is not supported
3448266e564dSmrg      pic_mode=default
3449266e564dSmrg    fi
3450266e564dSmrg
3451266e564dSmrg    # Calculate the filename of the output object if compiler does
3452266e564dSmrg    # not support -o with -c
3453a3129944Smrg    if test no = "$compiler_c_o"; then
3454a3129944Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3455a3129944Smrg      lockfile=$output_obj.lock
3456266e564dSmrg    else
3457266e564dSmrg      output_obj=
3458266e564dSmrg      need_locks=no
3459266e564dSmrg      lockfile=
3460266e564dSmrg    fi
3461266e564dSmrg
3462266e564dSmrg    # Lock this critical section if it is needed
3463266e564dSmrg    # We use this script file to make the link, it avoids creating a new file
3464a3129944Smrg    if test yes = "$need_locks"; then
3465698f425bSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3466698f425bSmrg	func_echo "Waiting for $lockfile to be removed"
3467266e564dSmrg	sleep 2
3468266e564dSmrg      done
3469a3129944Smrg    elif test warn = "$need_locks"; then
3470266e564dSmrg      if test -f "$lockfile"; then
3471698f425bSmrg	$ECHO "\
3472266e564dSmrg*** ERROR, $lockfile exists and contains:
3473266e564dSmrg`cat $lockfile 2>/dev/null`
3474266e564dSmrg
3475266e564dSmrgThis indicates that another process is trying to use the same
3476266e564dSmrgtemporary object file, and libtool could not work around it because
3477a3129944Smrgyour compiler does not support '-c' and '-o' together.  If you
3478266e564dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3479266e564dSmrgavoid parallel builds (make -j) in this platform, or get a better
3480266e564dSmrgcompiler."
3481266e564dSmrg
3482698f425bSmrg	$opt_dry_run || $RM $removelist
3483266e564dSmrg	exit $EXIT_FAILURE
3484266e564dSmrg      fi
34859ef0b394Smrg      func_append removelist " $output_obj"
3486698f425bSmrg      $ECHO "$srcfile" > "$lockfile"
3487266e564dSmrg    fi
3488266e564dSmrg
3489698f425bSmrg    $opt_dry_run || $RM $removelist
34909ef0b394Smrg    func_append removelist " $lockfile"
3491698f425bSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3492698f425bSmrg
34939ef0b394Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
34949ef0b394Smrg    srcfile=$func_to_tool_file_result
3495698f425bSmrg    func_quote_for_eval "$srcfile"
3496698f425bSmrg    qsrcfile=$func_quote_for_eval_result
3497266e564dSmrg
3498266e564dSmrg    # Only build a PIC object if we are building libtool libraries.
3499a3129944Smrg    if test yes = "$build_libtool_libs"; then
3500266e564dSmrg      # Without this assignment, base_compile gets emptied.
3501266e564dSmrg      fbsd_hideous_sh_bug=$base_compile
3502266e564dSmrg
3503a3129944Smrg      if test no != "$pic_mode"; then
3504266e564dSmrg	command="$base_compile $qsrcfile $pic_flag"
3505266e564dSmrg      else
3506266e564dSmrg	# Don't build PIC code
3507266e564dSmrg	command="$base_compile $qsrcfile"
3508266e564dSmrg      fi
3509266e564dSmrg
3510698f425bSmrg      func_mkdir_p "$xdir$objdir"
3511266e564dSmrg
3512266e564dSmrg      if test -z "$output_obj"; then
3513266e564dSmrg	# Place PIC objects in $objdir
35149ef0b394Smrg	func_append command " -o $lobj"
3515266e564dSmrg      fi
3516266e564dSmrg
3517698f425bSmrg      func_show_eval_locale "$command"	\
3518698f425bSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3519266e564dSmrg
3520a3129944Smrg      if test warn = "$need_locks" &&
3521266e564dSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3522698f425bSmrg	$ECHO "\
3523266e564dSmrg*** ERROR, $lockfile contains:
3524266e564dSmrg`cat $lockfile 2>/dev/null`
3525266e564dSmrg
3526266e564dSmrgbut it should contain:
3527266e564dSmrg$srcfile
3528266e564dSmrg
3529266e564dSmrgThis indicates that another process is trying to use the same
3530266e564dSmrgtemporary object file, and libtool could not work around it because
3531a3129944Smrgyour compiler does not support '-c' and '-o' together.  If you
3532266e564dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3533266e564dSmrgavoid parallel builds (make -j) in this platform, or get a better
3534266e564dSmrgcompiler."
3535266e564dSmrg
3536698f425bSmrg	$opt_dry_run || $RM $removelist
3537266e564dSmrg	exit $EXIT_FAILURE
3538266e564dSmrg      fi
3539266e564dSmrg
3540266e564dSmrg      # Just move the object if needed, then go on to compile the next one
3541266e564dSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3542698f425bSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3543698f425bSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3544266e564dSmrg      fi
3545266e564dSmrg
3546266e564dSmrg      # Allow error messages only from the first compilation.
3547a3129944Smrg      if test yes = "$suppress_opt"; then
3548698f425bSmrg	suppress_output=' >/dev/null 2>&1'
3549266e564dSmrg      fi
3550266e564dSmrg    fi
3551266e564dSmrg
3552266e564dSmrg    # Only build a position-dependent object if we build old libraries.
3553a3129944Smrg    if test yes = "$build_old_libs"; then
3554a3129944Smrg      if test yes != "$pic_mode"; then
3555266e564dSmrg	# Don't build PIC code
3556698f425bSmrg	command="$base_compile $qsrcfile$pie_flag"
3557266e564dSmrg      else
3558266e564dSmrg	command="$base_compile $qsrcfile $pic_flag"
3559266e564dSmrg      fi
3560a3129944Smrg      if test yes = "$compiler_c_o"; then
35619ef0b394Smrg	func_append command " -o $obj"
3562266e564dSmrg      fi
3563266e564dSmrg
3564266e564dSmrg      # Suppress compiler output if we already did a PIC compilation.
35659ef0b394Smrg      func_append command "$suppress_output"
3566698f425bSmrg      func_show_eval_locale "$command" \
3567698f425bSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3568266e564dSmrg
3569a3129944Smrg      if test warn = "$need_locks" &&
3570266e564dSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3571698f425bSmrg	$ECHO "\
3572266e564dSmrg*** ERROR, $lockfile contains:
3573266e564dSmrg`cat $lockfile 2>/dev/null`
3574266e564dSmrg
3575266e564dSmrgbut it should contain:
3576266e564dSmrg$srcfile
3577266e564dSmrg
3578266e564dSmrgThis indicates that another process is trying to use the same
3579266e564dSmrgtemporary object file, and libtool could not work around it because
3580a3129944Smrgyour compiler does not support '-c' and '-o' together.  If you
3581266e564dSmrgrepeat this compilation, it may succeed, by chance, but you had better
3582266e564dSmrgavoid parallel builds (make -j) in this platform, or get a better
3583266e564dSmrgcompiler."
3584266e564dSmrg
3585698f425bSmrg	$opt_dry_run || $RM $removelist
3586266e564dSmrg	exit $EXIT_FAILURE
3587266e564dSmrg      fi
3588266e564dSmrg
3589266e564dSmrg      # Just move the object if needed
3590266e564dSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3591698f425bSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
3592698f425bSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3593266e564dSmrg      fi
3594266e564dSmrg    fi
3595266e564dSmrg
3596698f425bSmrg    $opt_dry_run || {
3597698f425bSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3598266e564dSmrg
3599698f425bSmrg      # Unlock the critical section if it was locked
3600a3129944Smrg      if test no != "$need_locks"; then
3601698f425bSmrg	removelist=$lockfile
3602698f425bSmrg        $RM "$lockfile"
3603698f425bSmrg      fi
3604698f425bSmrg    }
3605266e564dSmrg
3606266e564dSmrg    exit $EXIT_SUCCESS
3607698f425bSmrg}
3608266e564dSmrg
3609698f425bSmrg$opt_help || {
3610a3129944Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3611698f425bSmrg}
3612266e564dSmrg
3613698f425bSmrgfunc_mode_help ()
3614698f425bSmrg{
3615698f425bSmrg    # We need to display help for each of the modes.
36169ef0b394Smrg    case $opt_mode in
3617698f425bSmrg      "")
3618698f425bSmrg        # Generic help is extracted from the usage comments
3619698f425bSmrg        # at the start of this file.
3620698f425bSmrg        func_help
3621698f425bSmrg        ;;
3622266e564dSmrg
3623698f425bSmrg      clean)
3624698f425bSmrg        $ECHO \
3625698f425bSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3626266e564dSmrg
3627698f425bSmrgRemove files from the build directory.
3628266e564dSmrg
3629698f425bSmrgRM is the name of the program to use to delete files associated with each FILE
3630a3129944Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3631698f425bSmrgto RM.
3632266e564dSmrg
3633698f425bSmrgIf FILE is a libtool library, object or program, all the files associated
3634698f425bSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3635698f425bSmrg        ;;
3636266e564dSmrg
3637698f425bSmrg      compile)
3638698f425bSmrg      $ECHO \
3639698f425bSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3640266e564dSmrg
3641698f425bSmrgCompile a source file into a libtool library object.
3642266e564dSmrg
3643698f425bSmrgThis mode accepts the following additional options:
3644266e564dSmrg
3645698f425bSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3646698f425bSmrg  -no-suppress      do not suppress compiler output for multiple passes
36479ef0b394Smrg  -prefer-pic       try to build PIC objects only
36489ef0b394Smrg  -prefer-non-pic   try to build non-PIC objects only
3649a3129944Smrg  -shared           do not build a '.o' file suitable for static linking
3650a3129944Smrg  -static           only build a '.o' file suitable for static linking
36519ef0b394Smrg  -Wc,FLAG          pass FLAG directly to the compiler
3652266e564dSmrg
3653a3129944SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3654698f425bSmrgfrom the given SOURCEFILE.
3655266e564dSmrg
3656698f425bSmrgThe output file name is determined by removing the directory component from
3657a3129944SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3658a3129944Smrglibrary object suffix, '.lo'."
3659698f425bSmrg        ;;
3660266e564dSmrg
3661698f425bSmrg      execute)
3662698f425bSmrg        $ECHO \
3663698f425bSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3664266e564dSmrg
3665698f425bSmrgAutomatically set library path, then run a program.
3666266e564dSmrg
3667698f425bSmrgThis mode accepts the following additional options:
3668266e564dSmrg
3669698f425bSmrg  -dlopen FILE      add the directory containing FILE to the library path
3670266e564dSmrg
3671a3129944SmrgThis mode sets the library path environment variable according to '-dlopen'
3672698f425bSmrgflags.
3673266e564dSmrg
3674698f425bSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3675698f425bSmrginto their corresponding uninstalled binary, and any of their required library
3676698f425bSmrgdirectories are added to the library path.
3677266e564dSmrg
3678698f425bSmrgThen, COMMAND is executed, with ARGS as arguments."
3679698f425bSmrg        ;;
3680266e564dSmrg
3681698f425bSmrg      finish)
3682698f425bSmrg        $ECHO \
3683698f425bSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3684266e564dSmrg
3685698f425bSmrgComplete the installation of libtool libraries.
3686266e564dSmrg
3687698f425bSmrgEach LIBDIR is a directory that contains libtool libraries.
3688266e564dSmrg
3689698f425bSmrgThe commands that this mode executes may require superuser privileges.  Use
3690a3129944Smrgthe '--dry-run' option if you just want to see what would be executed."
3691698f425bSmrg        ;;
3692266e564dSmrg
3693698f425bSmrg      install)
3694698f425bSmrg        $ECHO \
3695698f425bSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3696266e564dSmrg
3697698f425bSmrgInstall executables or libraries.
3698266e564dSmrg
3699698f425bSmrgINSTALL-COMMAND is the installation command.  The first component should be
3700a3129944Smrgeither the 'install' or 'cp' program.
3701266e564dSmrg
3702698f425bSmrgThe following components of INSTALL-COMMAND are treated specially:
3703266e564dSmrg
37049ef0b394Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3705266e564dSmrg
3706698f425bSmrgThe rest of the components are interpreted as arguments to that command (only
3707698f425bSmrgBSD-compatible install options are recognized)."
3708698f425bSmrg        ;;
3709266e564dSmrg
3710698f425bSmrg      link)
3711698f425bSmrg        $ECHO \
3712698f425bSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3713266e564dSmrg
3714698f425bSmrgLink object files or libraries together to form another library, or to
3715698f425bSmrgcreate an executable program.
3716266e564dSmrg
3717698f425bSmrgLINK-COMMAND is a command using the C compiler that you would use to create
3718698f425bSmrga program from several object files.
3719266e564dSmrg
3720698f425bSmrgThe following components of LINK-COMMAND are treated specially:
3721266e564dSmrg
3722698f425bSmrg  -all-static       do not do any dynamic linking at all
3723698f425bSmrg  -avoid-version    do not add a version suffix if possible
37249ef0b394Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
37259ef0b394Smrg                    libraries must be found in the PATH setting at runtime)
3726a3129944Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3727698f425bSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3728698f425bSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3729698f425bSmrg  -export-symbols SYMFILE
3730698f425bSmrg                    try to export only the symbols listed in SYMFILE
3731698f425bSmrg  -export-symbols-regex REGEX
3732698f425bSmrg                    try to export only the symbols matching REGEX
3733698f425bSmrg  -LLIBDIR          search LIBDIR for required installed libraries
3734698f425bSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3735698f425bSmrg  -module           build a library that can dlopened
3736698f425bSmrg  -no-fast-install  disable the fast-install mode
3737698f425bSmrg  -no-install       link a not-installable executable
3738698f425bSmrg  -no-undefined     declare that a library does not refer to external symbols
3739698f425bSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3740a3129944Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3741a3129944Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3742698f425bSmrg  -precious-files-regex REGEX
3743698f425bSmrg                    don't remove output files matching REGEX
3744698f425bSmrg  -release RELEASE  specify package release information
3745698f425bSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
3746698f425bSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
3747698f425bSmrg  -shared           only do dynamic linking of libtool libraries
3748698f425bSmrg  -shrext SUFFIX    override the standard shared library file extension
3749698f425bSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
3750698f425bSmrg  -static-libtool-libs
3751698f425bSmrg                    do not do any dynamic linking of libtool libraries
3752698f425bSmrg  -version-info CURRENT[:REVISION[:AGE]]
3753698f425bSmrg                    specify library version info [each variable defaults to 0]
3754698f425bSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
37559ef0b394Smrg  -Wc,FLAG
37569ef0b394Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
37579ef0b394Smrg  -Wl,FLAG
37589ef0b394Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
37599ef0b394Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
3760266e564dSmrg
3761a3129944SmrgAll other options (arguments beginning with '-') are ignored.
3762266e564dSmrg
3763a3129944SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
3764698f425bSmrgtreated as uninstalled libtool libraries, other files are standard or library
3765698f425bSmrgobject files.
3766c5629e66Smrg
3767a3129944SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
3768a3129944Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
3769698f425bSmrgrequired, except when creating a convenience library.
3770266e564dSmrg
3771a3129944SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
3772a3129944Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
3773266e564dSmrg
3774a3129944SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
3775698f425bSmrgis created, otherwise an executable program is created."
3776266e564dSmrg        ;;
3777266e564dSmrg
3778698f425bSmrg      uninstall)
3779698f425bSmrg        $ECHO \
3780698f425bSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
3781266e564dSmrg
3782698f425bSmrgRemove libraries from an installation directory.
3783266e564dSmrg
3784698f425bSmrgRM is the name of the program to use to delete files associated with each FILE
3785a3129944Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3786698f425bSmrgto RM.
3787266e564dSmrg
3788698f425bSmrgIf FILE is a libtool library, all the files associated with it are deleted.
3789698f425bSmrgOtherwise, only FILE itself is deleted using RM."
3790698f425bSmrg        ;;
3791266e564dSmrg
3792698f425bSmrg      *)
3793a3129944Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
3794698f425bSmrg        ;;
3795698f425bSmrg    esac
3796266e564dSmrg
37979ef0b394Smrg    echo
3798a3129944Smrg    $ECHO "Try '$progname --help' for more information about other modes."
3799698f425bSmrg}
3800266e564dSmrg
38019ef0b394Smrg# Now that we've collected a possible --mode arg, show help if necessary
38029ef0b394Smrgif $opt_help; then
3803a3129944Smrg  if test : = "$opt_help"; then
38049ef0b394Smrg    func_mode_help
38059ef0b394Smrg  else
38069ef0b394Smrg    {
38079ef0b394Smrg      func_help noexit
38089ef0b394Smrg      for opt_mode in compile link execute install finish uninstall clean; do
38099ef0b394Smrg	func_mode_help
38109ef0b394Smrg      done
3811a3129944Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
38129ef0b394Smrg    {
38139ef0b394Smrg      func_help noexit
38149ef0b394Smrg      for opt_mode in compile link execute install finish uninstall clean; do
38159ef0b394Smrg	echo
38169ef0b394Smrg	func_mode_help
38179ef0b394Smrg      done
38189ef0b394Smrg    } |
3819a3129944Smrg    $SED '1d
38209ef0b394Smrg      /^When reporting/,/^Report/{
38219ef0b394Smrg	H
38229ef0b394Smrg	d
38239ef0b394Smrg      }
38249ef0b394Smrg      $x
38259ef0b394Smrg      /information about other modes/d
38269ef0b394Smrg      /more detailed .*MODE/d
38279ef0b394Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
38289ef0b394Smrg  fi
38299ef0b394Smrg  exit $?
38309ef0b394Smrgfi
3831266e564dSmrg
3832266e564dSmrg
3833698f425bSmrg# func_mode_execute arg...
3834698f425bSmrgfunc_mode_execute ()
3835698f425bSmrg{
3836a3129944Smrg    $debug_cmd
3837a3129944Smrg
3838698f425bSmrg    # The first argument is the command name.
3839a3129944Smrg    cmd=$nonopt
3840698f425bSmrg    test -z "$cmd" && \
3841698f425bSmrg      func_fatal_help "you must specify a COMMAND"
3842266e564dSmrg
3843698f425bSmrg    # Handle -dlopen flags immediately.
38449ef0b394Smrg    for file in $opt_dlopen; do
3845698f425bSmrg      test -f "$file" \
3846a3129944Smrg	|| func_fatal_help "'$file' is not a file"
3847266e564dSmrg
3848698f425bSmrg      dir=
3849698f425bSmrg      case $file in
3850698f425bSmrg      *.la)
38519ef0b394Smrg	func_resolve_sysroot "$file"
38529ef0b394Smrg	file=$func_resolve_sysroot_result
38539ef0b394Smrg
3854698f425bSmrg	# Check to see that this really is a libtool archive.
3855698f425bSmrg	func_lalib_unsafe_p "$file" \
3856a3129944Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
3857266e564dSmrg
3858698f425bSmrg	# Read the libtool library.
3859698f425bSmrg	dlname=
3860698f425bSmrg	library_names=
3861698f425bSmrg	func_source "$file"
3862266e564dSmrg
3863698f425bSmrg	# Skip this library if it cannot be dlopened.
3864698f425bSmrg	if test -z "$dlname"; then
3865698f425bSmrg	  # Warn if it was a shared library.
3866698f425bSmrg	  test -n "$library_names" && \
3867a3129944Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
3868698f425bSmrg	  continue
3869698f425bSmrg	fi
3870266e564dSmrg
3871698f425bSmrg	func_dirname "$file" "" "."
3872a3129944Smrg	dir=$func_dirname_result
3873266e564dSmrg
3874698f425bSmrg	if test -f "$dir/$objdir/$dlname"; then
38759ef0b394Smrg	  func_append dir "/$objdir"
3876698f425bSmrg	else
3877698f425bSmrg	  if test ! -f "$dir/$dlname"; then
3878a3129944Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
3879698f425bSmrg	  fi
3880698f425bSmrg	fi
3881266e564dSmrg	;;
3882266e564dSmrg
3883698f425bSmrg      *.lo)
3884698f425bSmrg	# Just add the directory containing the .lo file.
3885698f425bSmrg	func_dirname "$file" "" "."
3886a3129944Smrg	dir=$func_dirname_result
3887266e564dSmrg	;;
3888266e564dSmrg
3889698f425bSmrg      *)
3890a3129944Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
3891266e564dSmrg	continue
3892266e564dSmrg	;;
3893698f425bSmrg      esac
3894266e564dSmrg
3895698f425bSmrg      # Get the absolute pathname.
3896698f425bSmrg      absdir=`cd "$dir" && pwd`
3897a3129944Smrg      test -n "$absdir" && dir=$absdir
3898266e564dSmrg
3899698f425bSmrg      # Now add the directory to shlibpath_var.
3900698f425bSmrg      if eval "test -z \"\$$shlibpath_var\""; then
3901698f425bSmrg	eval "$shlibpath_var=\"\$dir\""
3902698f425bSmrg      else
3903698f425bSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
3904698f425bSmrg      fi
3905698f425bSmrg    done
3906266e564dSmrg
3907698f425bSmrg    # This variable tells wrapper scripts just to set shlibpath_var
3908698f425bSmrg    # rather than running their programs.
3909a3129944Smrg    libtool_execute_magic=$magic
3910266e564dSmrg
3911698f425bSmrg    # Check if any of the arguments is a wrapper script.
3912698f425bSmrg    args=
3913698f425bSmrg    for file
3914698f425bSmrg    do
3915698f425bSmrg      case $file in
39169ef0b394Smrg      -* | *.la | *.lo ) ;;
3917698f425bSmrg      *)
3918698f425bSmrg	# Do a test to see if this is really a libtool program.
3919698f425bSmrg	if func_ltwrapper_script_p "$file"; then
3920698f425bSmrg	  func_source "$file"
3921698f425bSmrg	  # Transform arg to wrapped name.
3922a3129944Smrg	  file=$progdir/$program
3923698f425bSmrg	elif func_ltwrapper_executable_p "$file"; then
3924698f425bSmrg	  func_ltwrapper_scriptname "$file"
3925698f425bSmrg	  func_source "$func_ltwrapper_scriptname_result"
3926698f425bSmrg	  # Transform arg to wrapped name.
3927a3129944Smrg	  file=$progdir/$program
3928698f425bSmrg	fi
3929698f425bSmrg	;;
3930698f425bSmrg      esac
3931698f425bSmrg      # Quote arguments (to preserve shell metacharacters).
39329ef0b394Smrg      func_append_quoted args "$file"
3933698f425bSmrg    done
3934266e564dSmrg
3935a3129944Smrg    if $opt_dry_run; then
3936a3129944Smrg      # Display what would be done.
3937a3129944Smrg      if test -n "$shlibpath_var"; then
3938a3129944Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
3939a3129944Smrg	echo "export $shlibpath_var"
3940a3129944Smrg      fi
3941a3129944Smrg      $ECHO "$cmd$args"
3942a3129944Smrg      exit $EXIT_SUCCESS
3943a3129944Smrg    else
3944698f425bSmrg      if test -n "$shlibpath_var"; then
3945698f425bSmrg	# Export the shlibpath_var.
3946698f425bSmrg	eval "export $shlibpath_var"
3947698f425bSmrg      fi
3948266e564dSmrg
3949698f425bSmrg      # Restore saved environment variables
3950698f425bSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
3951698f425bSmrg      do
3952698f425bSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
3953698f425bSmrg                $lt_var=\$save_$lt_var; export $lt_var
3954266e564dSmrg	      else
3955698f425bSmrg		$lt_unset $lt_var
3956698f425bSmrg	      fi"
3957698f425bSmrg      done
3958266e564dSmrg
3959698f425bSmrg      # Now prepare to actually exec the command.
3960a3129944Smrg      exec_cmd=\$cmd$args
3961698f425bSmrg    fi
3962698f425bSmrg}
3963266e564dSmrg
3964a3129944Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
39659ef0b394Smrg
39669ef0b394Smrg
39679ef0b394Smrg# func_mode_finish arg...
39689ef0b394Smrgfunc_mode_finish ()
39699ef0b394Smrg{
3970a3129944Smrg    $debug_cmd
3971a3129944Smrg
39729ef0b394Smrg    libs=
39739ef0b394Smrg    libdirs=
39749ef0b394Smrg    admincmds=
39759ef0b394Smrg
39769ef0b394Smrg    for opt in "$nonopt" ${1+"$@"}
39779ef0b394Smrg    do
39789ef0b394Smrg      if test -d "$opt"; then
39799ef0b394Smrg	func_append libdirs " $opt"
39809ef0b394Smrg
39819ef0b394Smrg      elif test -f "$opt"; then
39829ef0b394Smrg	if func_lalib_unsafe_p "$opt"; then
39839ef0b394Smrg	  func_append libs " $opt"
39849ef0b394Smrg	else
3985a3129944Smrg	  func_warning "'$opt' is not a valid libtool archive"
39869ef0b394Smrg	fi
39879ef0b394Smrg
39889ef0b394Smrg      else
3989a3129944Smrg	func_fatal_error "invalid argument '$opt'"
39909ef0b394Smrg      fi
39919ef0b394Smrg    done
3992266e564dSmrg
39939ef0b394Smrg    if test -n "$libs"; then
39949ef0b394Smrg      if test -n "$lt_sysroot"; then
39959ef0b394Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
39969ef0b394Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
39979ef0b394Smrg      else
39989ef0b394Smrg        sysroot_cmd=
39999ef0b394Smrg      fi
4000266e564dSmrg
40019ef0b394Smrg      # Remove sysroot references
40029ef0b394Smrg      if $opt_dry_run; then
40039ef0b394Smrg        for lib in $libs; do
4004a3129944Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
40059ef0b394Smrg        done
40069ef0b394Smrg      else
40079ef0b394Smrg        tmpdir=`func_mktempdir`
40089ef0b394Smrg        for lib in $libs; do
4009a3129944Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
40109ef0b394Smrg	    > $tmpdir/tmp-la
40119ef0b394Smrg	  mv -f $tmpdir/tmp-la $lib
40129ef0b394Smrg	done
40139ef0b394Smrg        ${RM}r "$tmpdir"
40149ef0b394Smrg      fi
40159ef0b394Smrg    fi
4016266e564dSmrg
4017698f425bSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4018698f425bSmrg      for libdir in $libdirs; do
4019698f425bSmrg	if test -n "$finish_cmds"; then
4020698f425bSmrg	  # Do each command in the finish commands.
4021698f425bSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4022698f425bSmrg'"$cmd"'"'
4023266e564dSmrg	fi
4024698f425bSmrg	if test -n "$finish_eval"; then
4025698f425bSmrg	  # Do the single finish_eval.
4026698f425bSmrg	  eval cmds=\"$finish_eval\"
40279ef0b394Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4028698f425bSmrg       $cmds"
4029698f425bSmrg	fi
4030698f425bSmrg      done
4031698f425bSmrg    fi
4032266e564dSmrg
4033698f425bSmrg    # Exit here if they wanted silent mode.
4034a3129944Smrg    $opt_quiet && exit $EXIT_SUCCESS
4035266e564dSmrg
40369ef0b394Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
40379ef0b394Smrg      echo "----------------------------------------------------------------------"
40389ef0b394Smrg      echo "Libraries have been installed in:"
40399ef0b394Smrg      for libdir in $libdirs; do
40409ef0b394Smrg	$ECHO "   $libdir"
40419ef0b394Smrg      done
40429ef0b394Smrg      echo
40439ef0b394Smrg      echo "If you ever happen to want to link against installed libraries"
40449ef0b394Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4045a3129944Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
40469ef0b394Smrg      echo "flag during linking and do at least one of the following:"
40479ef0b394Smrg      if test -n "$shlibpath_var"; then
4048a3129944Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
40499ef0b394Smrg	echo "     during execution"
40509ef0b394Smrg      fi
40519ef0b394Smrg      if test -n "$runpath_var"; then
4052a3129944Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
40539ef0b394Smrg	echo "     during linking"
40549ef0b394Smrg      fi
40559ef0b394Smrg      if test -n "$hardcode_libdir_flag_spec"; then
40569ef0b394Smrg	libdir=LIBDIR
40579ef0b394Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4058266e564dSmrg
4059a3129944Smrg	$ECHO "   - use the '$flag' linker flag"
40609ef0b394Smrg      fi
40619ef0b394Smrg      if test -n "$admincmds"; then
40629ef0b394Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
40639ef0b394Smrg      fi
40649ef0b394Smrg      if test -f /etc/ld.so.conf; then
4065a3129944Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
40669ef0b394Smrg      fi
40679ef0b394Smrg      echo
4068698f425bSmrg
40699ef0b394Smrg      echo "See any operating system documentation about shared libraries for"
40709ef0b394Smrg      case $host in
40719ef0b394Smrg	solaris2.[6789]|solaris2.1[0-9])
40729ef0b394Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
40739ef0b394Smrg	  echo "pages."
40749ef0b394Smrg	  ;;
40759ef0b394Smrg	*)
40769ef0b394Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
40779ef0b394Smrg	  ;;
40789ef0b394Smrg      esac
40799ef0b394Smrg      echo "----------------------------------------------------------------------"
40809ef0b394Smrg    fi
4081698f425bSmrg    exit $EXIT_SUCCESS
4082698f425bSmrg}
4083266e564dSmrg
4084a3129944Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4085266e564dSmrg
4086c5629e66Smrg
4087698f425bSmrg# func_mode_install arg...
4088698f425bSmrgfunc_mode_install ()
4089698f425bSmrg{
4090a3129944Smrg    $debug_cmd
4091a3129944Smrg
4092698f425bSmrg    # There may be an optional sh(1) argument at the beginning of
4093698f425bSmrg    # install_prog (especially on Windows NT).
4094a3129944Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4095698f425bSmrg       # Allow the use of GNU shtool's install command.
4096a3129944Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4097a3129944Smrg    then
4098698f425bSmrg      # Aesthetically quote it.
4099698f425bSmrg      func_quote_for_eval "$nonopt"
4100698f425bSmrg      install_prog="$func_quote_for_eval_result "
4101698f425bSmrg      arg=$1
4102698f425bSmrg      shift
4103698f425bSmrg    else
4104698f425bSmrg      install_prog=
4105698f425bSmrg      arg=$nonopt
4106266e564dSmrg    fi
4107266e564dSmrg
4108698f425bSmrg    # The real first argument should be the name of the installation program.
4109698f425bSmrg    # Aesthetically quote it.
4110698f425bSmrg    func_quote_for_eval "$arg"
41119ef0b394Smrg    func_append install_prog "$func_quote_for_eval_result"
41129ef0b394Smrg    install_shared_prog=$install_prog
41139ef0b394Smrg    case " $install_prog " in
41149ef0b394Smrg      *[\\\ /]cp\ *) install_cp=: ;;
41159ef0b394Smrg      *) install_cp=false ;;
41169ef0b394Smrg    esac
4117266e564dSmrg
4118698f425bSmrg    # We need to accept at least all the BSD install flags.
4119698f425bSmrg    dest=
4120698f425bSmrg    files=
4121698f425bSmrg    opts=
4122698f425bSmrg    prev=
4123698f425bSmrg    install_type=
4124a3129944Smrg    isdir=false
4125698f425bSmrg    stripme=
41269ef0b394Smrg    no_mode=:
4127698f425bSmrg    for arg
4128698f425bSmrg    do
41299ef0b394Smrg      arg2=
4130698f425bSmrg      if test -n "$dest"; then
41319ef0b394Smrg	func_append files " $dest"
4132698f425bSmrg	dest=$arg
4133698f425bSmrg	continue
4134698f425bSmrg      fi
4135266e564dSmrg
4136698f425bSmrg      case $arg in
4137a3129944Smrg      -d) isdir=: ;;
4138698f425bSmrg      -f)
41399ef0b394Smrg	if $install_cp; then :; else
41409ef0b394Smrg	  prev=$arg
41419ef0b394Smrg	fi
4142698f425bSmrg	;;
4143698f425bSmrg      -g | -m | -o)
4144698f425bSmrg	prev=$arg
4145698f425bSmrg	;;
4146698f425bSmrg      -s)
4147698f425bSmrg	stripme=" -s"
4148698f425bSmrg	continue
4149698f425bSmrg	;;
4150698f425bSmrg      -*)
4151698f425bSmrg	;;
4152698f425bSmrg      *)
4153698f425bSmrg	# If the previous option needed an argument, then skip it.
4154698f425bSmrg	if test -n "$prev"; then
4155a3129944Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
41569ef0b394Smrg	    arg2=$install_override_mode
41579ef0b394Smrg	    no_mode=false
41589ef0b394Smrg	  fi
4159698f425bSmrg	  prev=
4160698f425bSmrg	else
4161698f425bSmrg	  dest=$arg
4162698f425bSmrg	  continue
4163698f425bSmrg	fi
4164698f425bSmrg	;;
4165698f425bSmrg      esac
4166266e564dSmrg
4167698f425bSmrg      # Aesthetically quote the argument.
4168698f425bSmrg      func_quote_for_eval "$arg"
41699ef0b394Smrg      func_append install_prog " $func_quote_for_eval_result"
41709ef0b394Smrg      if test -n "$arg2"; then
41719ef0b394Smrg	func_quote_for_eval "$arg2"
41729ef0b394Smrg      fi
41739ef0b394Smrg      func_append install_shared_prog " $func_quote_for_eval_result"
4174698f425bSmrg    done
4175698f425bSmrg
4176698f425bSmrg    test -z "$install_prog" && \
4177698f425bSmrg      func_fatal_help "you must specify an install program"
4178698f425bSmrg
4179698f425bSmrg    test -n "$prev" && \
4180a3129944Smrg      func_fatal_help "the '$prev' option requires an argument"
4181698f425bSmrg
41829ef0b394Smrg    if test -n "$install_override_mode" && $no_mode; then
41839ef0b394Smrg      if $install_cp; then :; else
41849ef0b394Smrg	func_quote_for_eval "$install_override_mode"
41859ef0b394Smrg	func_append install_shared_prog " -m $func_quote_for_eval_result"
41869ef0b394Smrg      fi
41879ef0b394Smrg    fi
41889ef0b394Smrg
4189698f425bSmrg    if test -z "$files"; then
4190698f425bSmrg      if test -z "$dest"; then
4191698f425bSmrg	func_fatal_help "no file or destination specified"
4192698f425bSmrg      else
4193698f425bSmrg	func_fatal_help "you must specify a destination"
4194266e564dSmrg      fi
4195266e564dSmrg    fi
4196266e564dSmrg
4197698f425bSmrg    # Strip any trailing slash from the destination.
4198698f425bSmrg    func_stripname '' '/' "$dest"
4199698f425bSmrg    dest=$func_stripname_result
4200266e564dSmrg
4201698f425bSmrg    # Check to see that the destination is a directory.
4202a3129944Smrg    test -d "$dest" && isdir=:
4203a3129944Smrg    if $isdir; then
4204a3129944Smrg      destdir=$dest
4205698f425bSmrg      destname=
4206698f425bSmrg    else
4207698f425bSmrg      func_dirname_and_basename "$dest" "" "."
4208a3129944Smrg      destdir=$func_dirname_result
4209a3129944Smrg      destname=$func_basename_result
4210698f425bSmrg
4211698f425bSmrg      # Not a directory, so check to see that there is only one file specified.
4212698f425bSmrg      set dummy $files; shift
4213698f425bSmrg      test "$#" -gt 1 && \
4214a3129944Smrg	func_fatal_help "'$dest' is not a directory"
4215698f425bSmrg    fi
4216698f425bSmrg    case $destdir in
4217698f425bSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4218266e564dSmrg    *)
4219698f425bSmrg      for file in $files; do
4220698f425bSmrg	case $file in
4221698f425bSmrg	*.lo) ;;
4222698f425bSmrg	*)
4223a3129944Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4224698f425bSmrg	  ;;
4225698f425bSmrg	esac
4226698f425bSmrg      done
4227266e564dSmrg      ;;
4228266e564dSmrg    esac
4229266e564dSmrg
4230698f425bSmrg    # This variable tells wrapper scripts just to set variables rather
4231698f425bSmrg    # than running their programs.
4232a3129944Smrg    libtool_install_magic=$magic
4233266e564dSmrg
4234698f425bSmrg    staticlibs=
4235698f425bSmrg    future_libdirs=
4236698f425bSmrg    current_libdirs=
4237698f425bSmrg    for file in $files; do
4238266e564dSmrg
4239698f425bSmrg      # Do each installation.
4240698f425bSmrg      case $file in
4241698f425bSmrg      *.$libext)
4242698f425bSmrg	# Do the static libraries later.
42439ef0b394Smrg	func_append staticlibs " $file"
4244698f425bSmrg	;;
4245698f425bSmrg
4246698f425bSmrg      *.la)
42479ef0b394Smrg	func_resolve_sysroot "$file"
42489ef0b394Smrg	file=$func_resolve_sysroot_result
42499ef0b394Smrg
4250698f425bSmrg	# Check to see that this really is a libtool archive.
4251698f425bSmrg	func_lalib_unsafe_p "$file" \
4252a3129944Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4253698f425bSmrg
4254698f425bSmrg	library_names=
4255698f425bSmrg	old_library=
4256698f425bSmrg	relink_command=
4257698f425bSmrg	func_source "$file"
4258698f425bSmrg
4259698f425bSmrg	# Add the libdir to current_libdirs if it is the destination.
4260698f425bSmrg	if test "X$destdir" = "X$libdir"; then
4261698f425bSmrg	  case "$current_libdirs " in
4262698f425bSmrg	  *" $libdir "*) ;;
42639ef0b394Smrg	  *) func_append current_libdirs " $libdir" ;;
4264266e564dSmrg	  esac
4265698f425bSmrg	else
4266698f425bSmrg	  # Note the libdir as a future libdir.
4267698f425bSmrg	  case "$future_libdirs " in
4268698f425bSmrg	  *" $libdir "*) ;;
42699ef0b394Smrg	  *) func_append future_libdirs " $libdir" ;;
4270698f425bSmrg	  esac
4271698f425bSmrg	fi
4272266e564dSmrg
4273698f425bSmrg	func_dirname "$file" "/" ""
4274a3129944Smrg	dir=$func_dirname_result
42759ef0b394Smrg	func_append dir "$objdir"
4276698f425bSmrg
4277698f425bSmrg	if test -n "$relink_command"; then
4278698f425bSmrg	  # Determine the prefix the user has applied to our future dir.
42799ef0b394Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4280698f425bSmrg
4281698f425bSmrg	  # Don't allow the user to place us outside of our expected
4282698f425bSmrg	  # location b/c this prevents finding dependent libraries that
4283698f425bSmrg	  # are installed to the same prefix.
4284698f425bSmrg	  # At present, this check doesn't affect windows .dll's that
4285698f425bSmrg	  # are installed into $libdir/../bin (currently, that works fine)
4286698f425bSmrg	  # but it's something to keep an eye on.
4287698f425bSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4288a3129944Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4289698f425bSmrg
4290698f425bSmrg	  if test -n "$inst_prefix_dir"; then
4291698f425bSmrg	    # Stick the inst_prefix_dir data into the link command.
42929ef0b394Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4293698f425bSmrg	  else
42949ef0b394Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4295698f425bSmrg	  fi
4296698f425bSmrg
4297a3129944Smrg	  func_warning "relinking '$file'"
4298698f425bSmrg	  func_show_eval "$relink_command" \
4299a3129944Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4300698f425bSmrg	fi
4301698f425bSmrg
4302698f425bSmrg	# See the names of the shared library.
4303698f425bSmrg	set dummy $library_names; shift
4304698f425bSmrg	if test -n "$1"; then
4305a3129944Smrg	  realname=$1
4306698f425bSmrg	  shift
4307698f425bSmrg
4308a3129944Smrg	  srcname=$realname
4309a3129944Smrg	  test -n "$relink_command" && srcname=${realname}T
4310698f425bSmrg
4311698f425bSmrg	  # Install the shared library and build the symlinks.
43129ef0b394Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4313698f425bSmrg	      'exit $?'
4314a3129944Smrg	  tstripme=$stripme
4315698f425bSmrg	  case $host_os in
4316698f425bSmrg	  cygwin* | mingw* | pw32* | cegcc*)
4317698f425bSmrg	    case $realname in
4318698f425bSmrg	    *.dll.a)
4319a3129944Smrg	      tstripme=
4320a3129944Smrg	      ;;
4321a3129944Smrg	    esac
4322a3129944Smrg	    ;;
4323a3129944Smrg	  os2*)
4324a3129944Smrg	    case $realname in
4325a3129944Smrg	    *_dll.a)
4326a3129944Smrg	      tstripme=
4327698f425bSmrg	      ;;
4328698f425bSmrg	    esac
4329266e564dSmrg	    ;;
4330266e564dSmrg	  esac
4331698f425bSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
4332698f425bSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4333c5629e66Smrg	  fi
4334698f425bSmrg
4335698f425bSmrg	  if test "$#" -gt 0; then
4336698f425bSmrg	    # Delete the old symlinks, and create new ones.
4337a3129944Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4338698f425bSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4339698f425bSmrg	    # so we also need to try rm && ln -s.
4340698f425bSmrg	    for linkname
4341698f425bSmrg	    do
4342698f425bSmrg	      test "$linkname" != "$realname" \
4343698f425bSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4344266e564dSmrg	    done
4345266e564dSmrg	  fi
4346266e564dSmrg
4347698f425bSmrg	  # Do each command in the postinstall commands.
4348a3129944Smrg	  lib=$destdir/$realname
4349698f425bSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4350266e564dSmrg	fi
4351266e564dSmrg
4352698f425bSmrg	# Install the pseudo-library for information purposes.
4353698f425bSmrg	func_basename "$file"
4354a3129944Smrg	name=$func_basename_result
4355a3129944Smrg	instname=$dir/${name}i
4356698f425bSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4357266e564dSmrg
4358698f425bSmrg	# Maybe install the static library, too.
43599ef0b394Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4360698f425bSmrg	;;
4361266e564dSmrg
4362698f425bSmrg      *.lo)
4363698f425bSmrg	# Install (i.e. copy) a libtool object.
4364266e564dSmrg
4365698f425bSmrg	# Figure out destination file name, if it wasn't already specified.
4366698f425bSmrg	if test -n "$destname"; then
4367a3129944Smrg	  destfile=$destdir/$destname
4368698f425bSmrg	else
4369698f425bSmrg	  func_basename "$file"
4370a3129944Smrg	  destfile=$func_basename_result
4371a3129944Smrg	  destfile=$destdir/$destfile
4372698f425bSmrg	fi
4373698f425bSmrg
4374698f425bSmrg	# Deduce the name of the destination old-style object file.
4375698f425bSmrg	case $destfile in
4376698f425bSmrg	*.lo)
4377698f425bSmrg	  func_lo2o "$destfile"
4378698f425bSmrg	  staticdest=$func_lo2o_result
4379698f425bSmrg	  ;;
4380698f425bSmrg	*.$objext)
4381a3129944Smrg	  staticdest=$destfile
4382698f425bSmrg	  destfile=
4383698f425bSmrg	  ;;
4384698f425bSmrg	*)
4385a3129944Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4386698f425bSmrg	  ;;
4387266e564dSmrg	esac
4388266e564dSmrg
4389698f425bSmrg	# Install the libtool object if requested.
4390698f425bSmrg	test -n "$destfile" && \
4391698f425bSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4392698f425bSmrg
4393698f425bSmrg	# Install the old object if enabled.
4394a3129944Smrg	if test yes = "$build_old_libs"; then
4395698f425bSmrg	  # Deduce the name of the old-style object file.
4396698f425bSmrg	  func_lo2o "$file"
4397698f425bSmrg	  staticobj=$func_lo2o_result
4398698f425bSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4399266e564dSmrg	fi
4400698f425bSmrg	exit $EXIT_SUCCESS
4401698f425bSmrg	;;
4402266e564dSmrg
4403698f425bSmrg      *)
4404698f425bSmrg	# Figure out destination file name, if it wasn't already specified.
4405698f425bSmrg	if test -n "$destname"; then
4406a3129944Smrg	  destfile=$destdir/$destname
4407698f425bSmrg	else
4408698f425bSmrg	  func_basename "$file"
4409a3129944Smrg	  destfile=$func_basename_result
4410a3129944Smrg	  destfile=$destdir/$destfile
4411698f425bSmrg	fi
4412266e564dSmrg
4413698f425bSmrg	# If the file is missing, and there is a .exe on the end, strip it
4414698f425bSmrg	# because it is most likely a libtool script we actually want to
4415698f425bSmrg	# install
4416a3129944Smrg	stripped_ext=
4417698f425bSmrg	case $file in
4418698f425bSmrg	  *.exe)
4419698f425bSmrg	    if test ! -f "$file"; then
4420698f425bSmrg	      func_stripname '' '.exe' "$file"
4421698f425bSmrg	      file=$func_stripname_result
4422a3129944Smrg	      stripped_ext=.exe
4423698f425bSmrg	    fi
4424698f425bSmrg	    ;;
4425698f425bSmrg	esac
4426266e564dSmrg
4427698f425bSmrg	# Do a test to see if this is really a libtool program.
4428698f425bSmrg	case $host in
4429698f425bSmrg	*cygwin* | *mingw*)
4430698f425bSmrg	    if func_ltwrapper_executable_p "$file"; then
4431698f425bSmrg	      func_ltwrapper_scriptname "$file"
4432698f425bSmrg	      wrapper=$func_ltwrapper_scriptname_result
4433698f425bSmrg	    else
4434698f425bSmrg	      func_stripname '' '.exe' "$file"
4435698f425bSmrg	      wrapper=$func_stripname_result
4436698f425bSmrg	    fi
4437698f425bSmrg	    ;;
4438698f425bSmrg	*)
4439698f425bSmrg	    wrapper=$file
4440698f425bSmrg	    ;;
4441698f425bSmrg	esac
4442698f425bSmrg	if func_ltwrapper_script_p "$wrapper"; then
4443698f425bSmrg	  notinst_deplibs=
4444698f425bSmrg	  relink_command=
4445266e564dSmrg
4446698f425bSmrg	  func_source "$wrapper"
4447698f425bSmrg
4448698f425bSmrg	  # Check the variables that should have been set.
4449698f425bSmrg	  test -z "$generated_by_libtool_version" && \
4450a3129944Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4451698f425bSmrg
4452a3129944Smrg	  finalize=:
4453698f425bSmrg	  for lib in $notinst_deplibs; do
4454698f425bSmrg	    # Check to see that each library is installed.
4455698f425bSmrg	    libdir=
4456698f425bSmrg	    if test -f "$lib"; then
4457698f425bSmrg	      func_source "$lib"
4458698f425bSmrg	    fi
4459a3129944Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4460698f425bSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4461a3129944Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4462a3129944Smrg	      finalize=false
4463698f425bSmrg	    fi
4464698f425bSmrg	  done
4465698f425bSmrg
4466698f425bSmrg	  relink_command=
4467698f425bSmrg	  func_source "$wrapper"
4468698f425bSmrg
4469698f425bSmrg	  outputname=
4470a3129944Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4471698f425bSmrg	    $opt_dry_run || {
4472a3129944Smrg	      if $finalize; then
4473698f425bSmrg	        tmpdir=`func_mktempdir`
4474698f425bSmrg		func_basename "$file$stripped_ext"
4475a3129944Smrg		file=$func_basename_result
4476a3129944Smrg	        outputname=$tmpdir/$file
4477698f425bSmrg	        # Replace the output file specification.
44789ef0b394Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4479698f425bSmrg
4480a3129944Smrg	        $opt_quiet || {
4481698f425bSmrg	          func_quote_for_expand "$relink_command"
4482698f425bSmrg		  eval "func_echo $func_quote_for_expand_result"
4483698f425bSmrg	        }
4484698f425bSmrg	        if eval "$relink_command"; then :
4485698f425bSmrg	          else
4486a3129944Smrg		  func_error "error: relink '$file' with the above command before installing it"
4487698f425bSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
4488698f425bSmrg		  continue
4489698f425bSmrg	        fi
4490a3129944Smrg	        file=$outputname
4491698f425bSmrg	      else
4492a3129944Smrg	        func_warning "cannot relink '$file'"
4493698f425bSmrg	      fi
4494698f425bSmrg	    }
4495266e564dSmrg	  else
4496698f425bSmrg	    # Install the binary that we compiled earlier.
44979ef0b394Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4498266e564dSmrg	  fi
4499698f425bSmrg	fi
4500266e564dSmrg
4501698f425bSmrg	# remove .exe since cygwin /usr/bin/install will append another
4502698f425bSmrg	# one anyway
4503698f425bSmrg	case $install_prog,$host in
4504698f425bSmrg	*/usr/bin/install*,*cygwin*)
4505698f425bSmrg	  case $file:$destfile in
4506698f425bSmrg	  *.exe:*.exe)
4507698f425bSmrg	    # this is ok
4508698f425bSmrg	    ;;
4509698f425bSmrg	  *.exe:*)
4510698f425bSmrg	    destfile=$destfile.exe
4511698f425bSmrg	    ;;
4512698f425bSmrg	  *:*.exe)
4513698f425bSmrg	    func_stripname '' '.exe' "$destfile"
4514698f425bSmrg	    destfile=$func_stripname_result
4515698f425bSmrg	    ;;
4516698f425bSmrg	  esac
4517266e564dSmrg	  ;;
4518266e564dSmrg	esac
4519698f425bSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4520698f425bSmrg	$opt_dry_run || if test -n "$outputname"; then
4521698f425bSmrg	  ${RM}r "$tmpdir"
4522698f425bSmrg	fi
4523698f425bSmrg	;;
4524698f425bSmrg      esac
4525698f425bSmrg    done
4526266e564dSmrg
4527698f425bSmrg    for file in $staticlibs; do
4528698f425bSmrg      func_basename "$file"
4529a3129944Smrg      name=$func_basename_result
4530698f425bSmrg
4531698f425bSmrg      # Set up the ranlib parameters.
4532a3129944Smrg      oldlib=$destdir/$name
4533fb5e8d76Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4534fb5e8d76Smrg      tool_oldlib=$func_to_tool_file_result
4535698f425bSmrg
4536698f425bSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4537698f425bSmrg
4538698f425bSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
4539fb5e8d76Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4540698f425bSmrg      fi
4541698f425bSmrg
4542698f425bSmrg      # Do each command in the postinstall commands.
4543698f425bSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4544698f425bSmrg    done
4545698f425bSmrg
4546698f425bSmrg    test -n "$future_libdirs" && \
4547a3129944Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4548698f425bSmrg
4549698f425bSmrg    if test -n "$current_libdirs"; then
4550698f425bSmrg      # Maybe just do a dry run.
4551698f425bSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4552a3129944Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4553698f425bSmrg    else
4554698f425bSmrg      exit $EXIT_SUCCESS
4555698f425bSmrg    fi
4556698f425bSmrg}
4557698f425bSmrg
4558a3129944Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4559698f425bSmrg
4560698f425bSmrg
4561698f425bSmrg# func_generate_dlsyms outputname originator pic_p
4562698f425bSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4563698f425bSmrg# a dlpreopen symbol table.
4564698f425bSmrgfunc_generate_dlsyms ()
4565698f425bSmrg{
4566a3129944Smrg    $debug_cmd
4567a3129944Smrg
4568a3129944Smrg    my_outputname=$1
4569a3129944Smrg    my_originator=$2
4570a3129944Smrg    my_pic_p=${3-false}
4571a3129944Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4572698f425bSmrg    my_dlsyms=
4573698f425bSmrg
4574a3129944Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4575698f425bSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4576a3129944Smrg	my_dlsyms=${my_outputname}S.c
4577698f425bSmrg      else
4578698f425bSmrg	func_error "not configured to extract global symbols from dlpreopened files"
4579698f425bSmrg      fi
4580698f425bSmrg    fi
4581698f425bSmrg
4582698f425bSmrg    if test -n "$my_dlsyms"; then
4583698f425bSmrg      case $my_dlsyms in
4584698f425bSmrg      "") ;;
4585698f425bSmrg      *.c)
4586698f425bSmrg	# Discover the nlist of each of the dlfiles.
4587a3129944Smrg	nlist=$output_objdir/$my_outputname.nm
4588698f425bSmrg
4589698f425bSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4590698f425bSmrg
4591698f425bSmrg	# Parse the name list into a source file.
4592698f425bSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
4593698f425bSmrg
4594698f425bSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4595a3129944Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4596a3129944Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4597698f425bSmrg
4598698f425bSmrg#ifdef __cplusplus
4599698f425bSmrgextern \"C\" {
4600698f425bSmrg#endif
4601698f425bSmrg
4602a3129944Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
46039ef0b394Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
46049ef0b394Smrg#endif
46059ef0b394Smrg
46069ef0b394Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4607a3129944Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4608a3129944Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
46099ef0b394Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
46109ef0b394Smrg# define LT_DLSYM_CONST
4611a3129944Smrg#elif defined __osf__
46129ef0b394Smrg/* This system does not cope well with relocations in const data.  */
46139ef0b394Smrg# define LT_DLSYM_CONST
46149ef0b394Smrg#else
46159ef0b394Smrg# define LT_DLSYM_CONST const
46169ef0b394Smrg#endif
46179ef0b394Smrg
4618a3129944Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4619a3129944Smrg
4620698f425bSmrg/* External symbol declarations for the compiler. */\
4621698f425bSmrg"
4622698f425bSmrg
4623a3129944Smrg	if test yes = "$dlself"; then
4624a3129944Smrg	  func_verbose "generating symbol list for '$output'"
4625698f425bSmrg
4626698f425bSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4627698f425bSmrg
4628698f425bSmrg	  # Add our own program objects to the symbol list.
46299ef0b394Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4630698f425bSmrg	  for progfile in $progfiles; do
46319ef0b394Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4632a3129944Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
46339ef0b394Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4634698f425bSmrg	  done
4635698f425bSmrg
4636698f425bSmrg	  if test -n "$exclude_expsyms"; then
4637698f425bSmrg	    $opt_dry_run || {
4638698f425bSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4639698f425bSmrg	      eval '$MV "$nlist"T "$nlist"'
4640698f425bSmrg	    }
4641266e564dSmrg	  fi
4642698f425bSmrg
4643698f425bSmrg	  if test -n "$export_symbols_regex"; then
4644698f425bSmrg	    $opt_dry_run || {
4645698f425bSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4646698f425bSmrg	      eval '$MV "$nlist"T "$nlist"'
4647698f425bSmrg	    }
4648698f425bSmrg	  fi
4649698f425bSmrg
4650698f425bSmrg	  # Prepare the list of exported symbols
4651698f425bSmrg	  if test -z "$export_symbols"; then
4652a3129944Smrg	    export_symbols=$output_objdir/$outputname.exp
4653698f425bSmrg	    $opt_dry_run || {
4654698f425bSmrg	      $RM $export_symbols
4655a3129944Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4656698f425bSmrg	      case $host in
4657698f425bSmrg	      *cygwin* | *mingw* | *cegcc* )
4658698f425bSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4659698f425bSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4660698f425bSmrg	        ;;
4661698f425bSmrg	      esac
4662698f425bSmrg	    }
4663266e564dSmrg	  else
4664698f425bSmrg	    $opt_dry_run || {
4665a3129944Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4666698f425bSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4667698f425bSmrg	      eval '$MV "$nlist"T "$nlist"'
4668698f425bSmrg	      case $host in
46699ef0b394Smrg	        *cygwin* | *mingw* | *cegcc* )
4670698f425bSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4671698f425bSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4672698f425bSmrg	          ;;
4673698f425bSmrg	      esac
4674698f425bSmrg	    }
4675266e564dSmrg	  fi
4676698f425bSmrg	fi
4677266e564dSmrg
4678698f425bSmrg	for dlprefile in $dlprefiles; do
4679a3129944Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4680698f425bSmrg	  func_basename "$dlprefile"
4681a3129944Smrg	  name=$func_basename_result
46829ef0b394Smrg          case $host in
46839ef0b394Smrg	    *cygwin* | *mingw* | *cegcc* )
46849ef0b394Smrg	      # if an import library, we need to obtain dlname
46859ef0b394Smrg	      if func_win32_import_lib_p "$dlprefile"; then
46869ef0b394Smrg	        func_tr_sh "$dlprefile"
46879ef0b394Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4688a3129944Smrg	        dlprefile_dlbasename=
46899ef0b394Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
46909ef0b394Smrg	          # Use subshell, to avoid clobbering current variable values
46919ef0b394Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4692a3129944Smrg	          if test -n "$dlprefile_dlname"; then
46939ef0b394Smrg	            func_basename "$dlprefile_dlname"
4694a3129944Smrg	            dlprefile_dlbasename=$func_basename_result
46959ef0b394Smrg	          else
46969ef0b394Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
46979ef0b394Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
46989ef0b394Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
46999ef0b394Smrg	          fi
47009ef0b394Smrg	        fi
47019ef0b394Smrg	        $opt_dry_run || {
4702a3129944Smrg	          if test -n "$dlprefile_dlbasename"; then
47039ef0b394Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
47049ef0b394Smrg	          else
47059ef0b394Smrg	            func_warning "Could not compute DLL name from $name"
47069ef0b394Smrg	            eval '$ECHO ": $name " >> "$nlist"'
47079ef0b394Smrg	          fi
47089ef0b394Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47099ef0b394Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
47109ef0b394Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
47119ef0b394Smrg	        }
47129ef0b394Smrg	      else # not an import lib
47139ef0b394Smrg	        $opt_dry_run || {
47149ef0b394Smrg	          eval '$ECHO ": $name " >> "$nlist"'
47159ef0b394Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47169ef0b394Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
47179ef0b394Smrg	        }
47189ef0b394Smrg	      fi
47199ef0b394Smrg	    ;;
47209ef0b394Smrg	    *)
47219ef0b394Smrg	      $opt_dry_run || {
47229ef0b394Smrg	        eval '$ECHO ": $name " >> "$nlist"'
47239ef0b394Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47249ef0b394Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
47259ef0b394Smrg	      }
47269ef0b394Smrg	    ;;
47279ef0b394Smrg          esac
4728698f425bSmrg	done
4729698f425bSmrg
4730698f425bSmrg	$opt_dry_run || {
4731698f425bSmrg	  # Make sure we have at least an empty file.
4732698f425bSmrg	  test -f "$nlist" || : > "$nlist"
4733698f425bSmrg
4734698f425bSmrg	  if test -n "$exclude_expsyms"; then
4735698f425bSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4736698f425bSmrg	    $MV "$nlist"T "$nlist"
4737266e564dSmrg	  fi
4738698f425bSmrg
4739698f425bSmrg	  # Try sorting and uniquifying the output.
4740698f425bSmrg	  if $GREP -v "^: " < "$nlist" |
4741698f425bSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4742698f425bSmrg		sort -k 3
4743698f425bSmrg	      else
4744698f425bSmrg		sort +2
4745698f425bSmrg	      fi |
4746698f425bSmrg	      uniq > "$nlist"S; then
4747698f425bSmrg	    :
4748266e564dSmrg	  else
4749698f425bSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
4750266e564dSmrg	  fi
4751266e564dSmrg
4752698f425bSmrg	  if test -f "$nlist"S; then
4753698f425bSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
4754266e564dSmrg	  else
47559ef0b394Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
4756266e564dSmrg	  fi
4757266e564dSmrg
4758a3129944Smrg	  func_show_eval '$RM "${nlist}I"'
4759a3129944Smrg	  if test -n "$global_symbol_to_import"; then
4760a3129944Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
4761a3129944Smrg	  fi
4762a3129944Smrg
47639ef0b394Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
4764266e564dSmrg
4765698f425bSmrg/* The mapping between symbol names and symbols.  */
4766698f425bSmrgtypedef struct {
4767698f425bSmrg  const char *name;
4768698f425bSmrg  void *address;
4769698f425bSmrg} lt_dlsymlist;
47709ef0b394Smrgextern LT_DLSYM_CONST lt_dlsymlist
4771a3129944Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
4772a3129944Smrg"
4773a3129944Smrg
4774a3129944Smrg	  if test -s "$nlist"I; then
4775a3129944Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4776a3129944Smrgstatic void lt_syminit(void)
4777a3129944Smrg{
4778a3129944Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
4779a3129944Smrg  for (; symbol->name; ++symbol)
4780a3129944Smrg    {"
4781a3129944Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
4782a3129944Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4783a3129944Smrg    }
4784a3129944Smrg}"
4785a3129944Smrg	  fi
4786a3129944Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
47879ef0b394SmrgLT_DLSYM_CONST lt_dlsymlist
4788698f425bSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
4789a3129944Smrg{ {\"$my_originator\", (void *) 0},"
4790a3129944Smrg
4791a3129944Smrg	  if test -s "$nlist"I; then
4792a3129944Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4793a3129944Smrg  {\"@INIT@\", (void *) &lt_syminit},"
4794a3129944Smrg	  fi
4795266e564dSmrg
4796698f425bSmrg	  case $need_lib_prefix in
4797698f425bSmrg	  no)
4798698f425bSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
4799698f425bSmrg	    ;;
4800698f425bSmrg	  *)
4801698f425bSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
4802698f425bSmrg	    ;;
4803698f425bSmrg	  esac
48049ef0b394Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
4805698f425bSmrg  {0, (void *) 0}
4806698f425bSmrg};
4807266e564dSmrg
4808698f425bSmrg/* This works around a problem in FreeBSD linker */
4809698f425bSmrg#ifdef FREEBSD_WORKAROUND
4810698f425bSmrgstatic const void *lt_preloaded_setup() {
4811698f425bSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
4812698f425bSmrg}
4813698f425bSmrg#endif
4814698f425bSmrg
4815698f425bSmrg#ifdef __cplusplus
4816698f425bSmrg}
4817698f425bSmrg#endif\
4818698f425bSmrg"
4819698f425bSmrg	} # !$opt_dry_run
4820698f425bSmrg
4821698f425bSmrg	pic_flag_for_symtable=
4822698f425bSmrg	case "$compile_command " in
4823698f425bSmrg	*" -static "*) ;;
4824698f425bSmrg	*)
4825698f425bSmrg	  case $host in
4826698f425bSmrg	  # compiling the symbol table file with pic_flag works around
4827698f425bSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
4828698f425bSmrg	  # linked before any other PIC object.  But we must not use
4829698f425bSmrg	  # pic_flag when linking with -static.  The problem exists in
4830698f425bSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
4831fb5e8d76Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
4832698f425bSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
4833698f425bSmrg	  *-*-hpux*)
4834698f425bSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
4835698f425bSmrg	  *)
4836a3129944Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
4837698f425bSmrg	    ;;
4838698f425bSmrg	  esac
4839698f425bSmrg	  ;;
4840698f425bSmrg	esac
4841698f425bSmrg	symtab_cflags=
4842698f425bSmrg	for arg in $LTCFLAGS; do
4843698f425bSmrg	  case $arg in
4844698f425bSmrg	  -pie | -fpie | -fPIE) ;;
48459ef0b394Smrg	  *) func_append symtab_cflags " $arg" ;;
4846698f425bSmrg	  esac
4847698f425bSmrg	done
4848266e564dSmrg
4849698f425bSmrg	# Now compile the dynamic symbol file.
4850698f425bSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
4851266e564dSmrg
4852698f425bSmrg	# Clean up the generated files.
4853a3129944Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
4854266e564dSmrg
4855698f425bSmrg	# Transform the symbol file into the correct name.
4856a3129944Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
4857698f425bSmrg	case $host in
4858698f425bSmrg	*cygwin* | *mingw* | *cegcc* )
4859698f425bSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
48609ef0b394Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
48619ef0b394Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
4862698f425bSmrg	  else
48639ef0b394Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
48649ef0b394Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4865266e564dSmrg	  fi
4866698f425bSmrg	  ;;
4867698f425bSmrg	*)
48689ef0b394Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
48699ef0b394Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4870698f425bSmrg	  ;;
4871698f425bSmrg	esac
4872698f425bSmrg	;;
4873698f425bSmrg      *)
4874a3129944Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
4875698f425bSmrg	;;
4876698f425bSmrg      esac
4877698f425bSmrg    else
4878698f425bSmrg      # We keep going just in case the user didn't refer to
4879698f425bSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
4880698f425bSmrg      # really was required.
4881266e564dSmrg
4882698f425bSmrg      # Nullify the symbol file.
48839ef0b394Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
48849ef0b394Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
4885698f425bSmrg    fi
4886698f425bSmrg}
4887266e564dSmrg
4888a3129944Smrg# func_cygming_gnu_implib_p ARG
4889a3129944Smrg# This predicate returns with zero status (TRUE) if
4890a3129944Smrg# ARG is a GNU/binutils-style import library. Returns
4891a3129944Smrg# with nonzero status (FALSE) otherwise.
4892a3129944Smrgfunc_cygming_gnu_implib_p ()
4893a3129944Smrg{
4894a3129944Smrg  $debug_cmd
4895a3129944Smrg
4896a3129944Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4897a3129944Smrg  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)$'`
4898a3129944Smrg  test -n "$func_cygming_gnu_implib_tmp"
4899a3129944Smrg}
4900a3129944Smrg
4901a3129944Smrg# func_cygming_ms_implib_p ARG
4902a3129944Smrg# This predicate returns with zero status (TRUE) if
4903a3129944Smrg# ARG is an MS-style import library. Returns
4904a3129944Smrg# with nonzero status (FALSE) otherwise.
4905a3129944Smrgfunc_cygming_ms_implib_p ()
4906a3129944Smrg{
4907a3129944Smrg  $debug_cmd
4908a3129944Smrg
4909a3129944Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4910a3129944Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
4911a3129944Smrg  test -n "$func_cygming_ms_implib_tmp"
4912a3129944Smrg}
4913a3129944Smrg
4914698f425bSmrg# func_win32_libid arg
4915698f425bSmrg# return the library type of file 'arg'
4916698f425bSmrg#
4917698f425bSmrg# Need a lot of goo to handle *both* DLLs and import libs
4918698f425bSmrg# Has to be a shell function in order to 'eat' the argument
4919698f425bSmrg# that is supplied when $file_magic_command is called.
49209ef0b394Smrg# Despite the name, also deal with 64 bit binaries.
4921698f425bSmrgfunc_win32_libid ()
4922698f425bSmrg{
4923a3129944Smrg  $debug_cmd
4924a3129944Smrg
4925a3129944Smrg  win32_libid_type=unknown
4926698f425bSmrg  win32_fileres=`file -L $1 2>/dev/null`
4927698f425bSmrg  case $win32_fileres in
4928698f425bSmrg  *ar\ archive\ import\ library*) # definitely import
4929698f425bSmrg    win32_libid_type="x86 archive import"
4930698f425bSmrg    ;;
4931698f425bSmrg  *ar\ archive*) # could be an import, or static
49329ef0b394Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
4933698f425bSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
49349ef0b394Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
4935a3129944Smrg      case $nm_interface in
4936a3129944Smrg      "MS dumpbin")
4937a3129944Smrg	if func_cygming_ms_implib_p "$1" ||
4938a3129944Smrg	   func_cygming_gnu_implib_p "$1"
4939a3129944Smrg	then
4940a3129944Smrg	  win32_nmres=import
4941a3129944Smrg	else
4942a3129944Smrg	  win32_nmres=
4943a3129944Smrg	fi
4944a3129944Smrg	;;
4945a3129944Smrg      *)
4946a3129944Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
4947a3129944Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
4948a3129944Smrg	  $SED -n -e '
4949698f425bSmrg	    1,100{
4950698f425bSmrg		/ I /{
4951a3129944Smrg		    s|.*|import|
4952698f425bSmrg		    p
4953698f425bSmrg		    q
4954698f425bSmrg		}
4955698f425bSmrg	    }'`
4956a3129944Smrg	;;
4957a3129944Smrg      esac
4958698f425bSmrg      case $win32_nmres in
4959698f425bSmrg      import*)  win32_libid_type="x86 archive import";;
4960698f425bSmrg      *)        win32_libid_type="x86 archive static";;
4961698f425bSmrg      esac
4962698f425bSmrg    fi
4963698f425bSmrg    ;;
4964698f425bSmrg  *DLL*)
4965698f425bSmrg    win32_libid_type="x86 DLL"
4966698f425bSmrg    ;;
4967698f425bSmrg  *executable*) # but shell scripts are "executable" too...
4968698f425bSmrg    case $win32_fileres in
4969698f425bSmrg    *MS\ Windows\ PE\ Intel*)
4970698f425bSmrg      win32_libid_type="x86 DLL"
4971698f425bSmrg      ;;
4972698f425bSmrg    esac
4973698f425bSmrg    ;;
4974698f425bSmrg  esac
4975698f425bSmrg  $ECHO "$win32_libid_type"
4976698f425bSmrg}
4977266e564dSmrg
49789ef0b394Smrg# func_cygming_dll_for_implib ARG
49799ef0b394Smrg#
49809ef0b394Smrg# Platform-specific function to extract the
49819ef0b394Smrg# name of the DLL associated with the specified
49829ef0b394Smrg# import library ARG.
49839ef0b394Smrg# Invoked by eval'ing the libtool variable
49849ef0b394Smrg#    $sharedlib_from_linklib_cmd
49859ef0b394Smrg# Result is available in the variable
49869ef0b394Smrg#    $sharedlib_from_linklib_result
49879ef0b394Smrgfunc_cygming_dll_for_implib ()
49889ef0b394Smrg{
4989a3129944Smrg  $debug_cmd
4990a3129944Smrg
49919ef0b394Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
49929ef0b394Smrg}
49939ef0b394Smrg
49949ef0b394Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
49959ef0b394Smrg#
49969ef0b394Smrg# The is the core of a fallback implementation of a
49979ef0b394Smrg# platform-specific function to extract the name of the
49989ef0b394Smrg# DLL associated with the specified import library LIBNAME.
49999ef0b394Smrg#
50009ef0b394Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
50019ef0b394Smrg# on the platform and compiler that created the implib.
50029ef0b394Smrg#
50039ef0b394Smrg# Echos the name of the DLL associated with the
50049ef0b394Smrg# specified import library.
50059ef0b394Smrgfunc_cygming_dll_for_implib_fallback_core ()
50069ef0b394Smrg{
5007a3129944Smrg  $debug_cmd
5008a3129944Smrg
50099ef0b394Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
50109ef0b394Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
50119ef0b394Smrg    $SED '/^Contents of section '"$match_literal"':/{
50129ef0b394Smrg      # Place marker at beginning of archive member dllname section
50139ef0b394Smrg      s/.*/====MARK====/
50149ef0b394Smrg      p
50159ef0b394Smrg      d
50169ef0b394Smrg    }
50179ef0b394Smrg    # These lines can sometimes be longer than 43 characters, but
50189ef0b394Smrg    # are always uninteresting
50199ef0b394Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
50209ef0b394Smrg    /^In archive [^:]*:/d
50219ef0b394Smrg    # Ensure marker is printed
50229ef0b394Smrg    /^====MARK====/p
50239ef0b394Smrg    # Remove all lines with less than 43 characters
50249ef0b394Smrg    /^.\{43\}/!d
50259ef0b394Smrg    # From remaining lines, remove first 43 characters
50269ef0b394Smrg    s/^.\{43\}//' |
50279ef0b394Smrg    $SED -n '
50289ef0b394Smrg      # Join marker and all lines until next marker into a single line
50299ef0b394Smrg      /^====MARK====/ b para
50309ef0b394Smrg      H
50319ef0b394Smrg      $ b para
50329ef0b394Smrg      b
50339ef0b394Smrg      :para
50349ef0b394Smrg      x
50359ef0b394Smrg      s/\n//g
50369ef0b394Smrg      # Remove the marker
50379ef0b394Smrg      s/^====MARK====//
50389ef0b394Smrg      # Remove trailing dots and whitespace
50399ef0b394Smrg      s/[\. \t]*$//
50409ef0b394Smrg      # Print
50419ef0b394Smrg      /./p' |
50429ef0b394Smrg    # we now have a list, one entry per line, of the stringified
50439ef0b394Smrg    # contents of the appropriate section of all members of the
5044a3129944Smrg    # archive that possess that section. Heuristic: eliminate
5045a3129944Smrg    # all those that have a first or second character that is
50469ef0b394Smrg    # a '.' (that is, objdump's representation of an unprintable
50479ef0b394Smrg    # character.) This should work for all archives with less than
50489ef0b394Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
50499ef0b394Smrg    # begins with a literal '.' or a single character followed by
50509ef0b394Smrg    # a '.'.
50519ef0b394Smrg    #
50529ef0b394Smrg    # Of those that remain, print the first one.
50539ef0b394Smrg    $SED -e '/^\./d;/^.\./d;q'
50549ef0b394Smrg}
50559ef0b394Smrg
50569ef0b394Smrg# func_cygming_dll_for_implib_fallback ARG
50579ef0b394Smrg# Platform-specific function to extract the
50589ef0b394Smrg# name of the DLL associated with the specified
50599ef0b394Smrg# import library ARG.
50609ef0b394Smrg#
50619ef0b394Smrg# This fallback implementation is for use when $DLLTOOL
50629ef0b394Smrg# does not support the --identify-strict option.
50639ef0b394Smrg# Invoked by eval'ing the libtool variable
50649ef0b394Smrg#    $sharedlib_from_linklib_cmd
50659ef0b394Smrg# Result is available in the variable
50669ef0b394Smrg#    $sharedlib_from_linklib_result
50679ef0b394Smrgfunc_cygming_dll_for_implib_fallback ()
50689ef0b394Smrg{
5069a3129944Smrg  $debug_cmd
5070a3129944Smrg
5071a3129944Smrg  if func_cygming_gnu_implib_p "$1"; then
50729ef0b394Smrg    # binutils import library
50739ef0b394Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5074a3129944Smrg  elif func_cygming_ms_implib_p "$1"; then
50759ef0b394Smrg    # ms-generated import library
50769ef0b394Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
50779ef0b394Smrg  else
50789ef0b394Smrg    # unknown
5079a3129944Smrg    sharedlib_from_linklib_result=
50809ef0b394Smrg  fi
50819ef0b394Smrg}
5082266e564dSmrg
5083266e564dSmrg
5084698f425bSmrg# func_extract_an_archive dir oldlib
5085698f425bSmrgfunc_extract_an_archive ()
5086698f425bSmrg{
5087a3129944Smrg    $debug_cmd
5088a3129944Smrg
5089a3129944Smrg    f_ex_an_ar_dir=$1; shift
5090a3129944Smrg    f_ex_an_ar_oldlib=$1
5091a3129944Smrg    if test yes = "$lock_old_archive_extraction"; then
50929ef0b394Smrg      lockfile=$f_ex_an_ar_oldlib.lock
50939ef0b394Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
50949ef0b394Smrg	func_echo "Waiting for $lockfile to be removed"
50959ef0b394Smrg	sleep 2
50969ef0b394Smrg      done
50979ef0b394Smrg    fi
50989ef0b394Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
50999ef0b394Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5100a3129944Smrg    if test yes = "$lock_old_archive_extraction"; then
51019ef0b394Smrg      $opt_dry_run || rm -f "$lockfile"
51029ef0b394Smrg    fi
5103698f425bSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5104698f425bSmrg     :
5105698f425bSmrg    else
5106698f425bSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5107698f425bSmrg    fi
5108698f425bSmrg}
5109266e564dSmrg
5110266e564dSmrg
5111698f425bSmrg# func_extract_archives gentop oldlib ...
5112698f425bSmrgfunc_extract_archives ()
5113698f425bSmrg{
5114a3129944Smrg    $debug_cmd
5115a3129944Smrg
5116a3129944Smrg    my_gentop=$1; shift
5117698f425bSmrg    my_oldlibs=${1+"$@"}
5118a3129944Smrg    my_oldobjs=
5119a3129944Smrg    my_xlib=
5120a3129944Smrg    my_xabs=
5121a3129944Smrg    my_xdir=
5122266e564dSmrg
5123698f425bSmrg    for my_xlib in $my_oldlibs; do
5124698f425bSmrg      # Extract the objects.
5125698f425bSmrg      case $my_xlib in
5126a3129944Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5127698f425bSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5128698f425bSmrg      esac
5129698f425bSmrg      func_basename "$my_xlib"
5130a3129944Smrg      my_xlib=$func_basename_result
5131698f425bSmrg      my_xlib_u=$my_xlib
5132698f425bSmrg      while :; do
5133698f425bSmrg        case " $extracted_archives " in
5134698f425bSmrg	*" $my_xlib_u "*)
5135698f425bSmrg	  func_arith $extracted_serial + 1
5136698f425bSmrg	  extracted_serial=$func_arith_result
5137698f425bSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5138698f425bSmrg	*) break ;;
5139698f425bSmrg	esac
5140698f425bSmrg      done
5141698f425bSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5142a3129944Smrg      my_xdir=$my_gentop/$my_xlib_u
5143266e564dSmrg
5144698f425bSmrg      func_mkdir_p "$my_xdir"
5145266e564dSmrg
5146698f425bSmrg      case $host in
5147698f425bSmrg      *-darwin*)
5148698f425bSmrg	func_verbose "Extracting $my_xabs"
5149698f425bSmrg	# Do not bother doing anything if just a dry run
5150698f425bSmrg	$opt_dry_run || {
5151698f425bSmrg	  darwin_orig_dir=`pwd`
5152698f425bSmrg	  cd $my_xdir || exit $?
5153698f425bSmrg	  darwin_archive=$my_xabs
5154698f425bSmrg	  darwin_curdir=`pwd`
5155a3129944Smrg	  func_basename "$darwin_archive"
5156a3129944Smrg	  darwin_base_archive=$func_basename_result
5157698f425bSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5158698f425bSmrg	  if test -n "$darwin_arches"; then
5159698f425bSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5160698f425bSmrg	    darwin_arch=
5161698f425bSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5162a3129944Smrg	    for darwin_arch in  $darwin_arches; do
5163a3129944Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5164a3129944Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5165a3129944Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5166a3129944Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5167698f425bSmrg	      cd "$darwin_curdir"
5168a3129944Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5169698f425bSmrg	    done # $darwin_arches
5170698f425bSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5171a3129944Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5172698f425bSmrg	    darwin_file=
5173698f425bSmrg	    darwin_files=
5174698f425bSmrg	    for darwin_file in $darwin_filelist; do
51759ef0b394Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5176698f425bSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
5177698f425bSmrg	    done # $darwin_filelist
5178698f425bSmrg	    $RM -rf unfat-$$
5179698f425bSmrg	    cd "$darwin_orig_dir"
5180266e564dSmrg	  else
5181698f425bSmrg	    cd $darwin_orig_dir
5182698f425bSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5183698f425bSmrg	  fi # $darwin_arches
5184698f425bSmrg	} # !$opt_dry_run
5185698f425bSmrg	;;
5186698f425bSmrg      *)
5187698f425bSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5188698f425bSmrg	;;
5189698f425bSmrg      esac
51909ef0b394Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5191698f425bSmrg    done
5192266e564dSmrg
5193a3129944Smrg    func_extract_archives_result=$my_oldobjs
5194698f425bSmrg}
5195266e564dSmrg
5196266e564dSmrg
51979ef0b394Smrg# func_emit_wrapper [arg=no]
51989ef0b394Smrg#
51999ef0b394Smrg# Emit a libtool wrapper script on stdout.
52009ef0b394Smrg# Don't directly open a file because we may want to
52019ef0b394Smrg# incorporate the script contents within a cygwin/mingw
52029ef0b394Smrg# wrapper executable.  Must ONLY be called from within
52039ef0b394Smrg# func_mode_link because it depends on a number of variables
52049ef0b394Smrg# set therein.
5205698f425bSmrg#
52069ef0b394Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
52079ef0b394Smrg# variable will take.  If 'yes', then the emitted script
5208a3129944Smrg# will assume that the directory where it is stored is
52099ef0b394Smrg# the $objdir directory.  This is a cygwin/mingw-specific
52109ef0b394Smrg# behavior.
52119ef0b394Smrgfunc_emit_wrapper ()
5212698f425bSmrg{
52139ef0b394Smrg	func_emit_wrapper_arg1=${1-no}
5214266e564dSmrg
5215698f425bSmrg	$ECHO "\
5216698f425bSmrg#! $SHELL
5217266e564dSmrg
5218698f425bSmrg# $output - temporary wrapper script for $objdir/$outputname
5219a3129944Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5220698f425bSmrg#
5221698f425bSmrg# The $output program cannot be directly executed until all the libtool
5222698f425bSmrg# libraries that it depends on are installed.
5223698f425bSmrg#
5224698f425bSmrg# This wrapper script should never be moved out of the build directory.
5225698f425bSmrg# If it is, it will not operate correctly.
5226266e564dSmrg
5227698f425bSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
5228698f425bSmrg# metacharacters that are still active within double-quoted strings.
5229698f425bSmrgsed_quote_subst='$sed_quote_subst'
5230266e564dSmrg
5231698f425bSmrg# Be Bourne compatible
5232698f425bSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5233698f425bSmrg  emulate sh
5234698f425bSmrg  NULLCMD=:
5235698f425bSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5236698f425bSmrg  # is contrary to our usage.  Disable this feature.
5237698f425bSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5238698f425bSmrg  setopt NO_GLOB_SUBST
5239698f425bSmrgelse
5240698f425bSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5241698f425bSmrgfi
5242698f425bSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5243698f425bSmrgDUALCASE=1; export DUALCASE # for MKS sh
5244266e564dSmrg
5245698f425bSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5246698f425bSmrg# if CDPATH is set.
5247698f425bSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5248266e564dSmrg
5249698f425bSmrgrelink_command=\"$relink_command\"
5250266e564dSmrg
5251698f425bSmrg# This environment variable determines our operation mode.
5252698f425bSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5253698f425bSmrg  # install mode needs the following variables:
5254698f425bSmrg  generated_by_libtool_version='$macro_version'
5255698f425bSmrg  notinst_deplibs='$notinst_deplibs'
5256698f425bSmrgelse
5257698f425bSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5258698f425bSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
52599ef0b394Smrg    file=\"\$0\""
52609ef0b394Smrg
52619ef0b394Smrg    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
52629ef0b394Smrg    $ECHO "\
52639ef0b394Smrg
52649ef0b394Smrg# A function that is used when there is no print builtin or printf.
52659ef0b394Smrgfunc_fallback_echo ()
52669ef0b394Smrg{
52679ef0b394Smrg  eval 'cat <<_LTECHO_EOF
52689ef0b394Smrg\$1
52699ef0b394Smrg_LTECHO_EOF'
52709ef0b394Smrg}
52719ef0b394Smrg    ECHO=\"$qECHO\"
52729ef0b394Smrg  fi
52739ef0b394Smrg
52749ef0b394Smrg# Very basic option parsing. These options are (a) specific to
52759ef0b394Smrg# the libtool wrapper, (b) are identical between the wrapper
5276a3129944Smrg# /script/ and the wrapper /executable/ that is used only on
52779ef0b394Smrg# windows platforms, and (c) all begin with the string "--lt-"
5278a3129944Smrg# (application programs are unlikely to have options that match
52799ef0b394Smrg# this pattern).
52809ef0b394Smrg#
52819ef0b394Smrg# There are only two supported options: --lt-debug and
52829ef0b394Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
52839ef0b394Smrg#
52849ef0b394Smrg# The first argument to this parsing function should be the
52859ef0b394Smrg# script's $0 value, followed by "$@".
52869ef0b394Smrglt_option_debug=
52879ef0b394Smrgfunc_parse_lt_options ()
52889ef0b394Smrg{
52899ef0b394Smrg  lt_script_arg0=\$0
52909ef0b394Smrg  shift
52919ef0b394Smrg  for lt_opt
52929ef0b394Smrg  do
52939ef0b394Smrg    case \"\$lt_opt\" in
52949ef0b394Smrg    --lt-debug) lt_option_debug=1 ;;
52959ef0b394Smrg    --lt-dump-script)
52969ef0b394Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
52979ef0b394Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
52989ef0b394Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
52999ef0b394Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
53009ef0b394Smrg        exit 0
53019ef0b394Smrg      ;;
53029ef0b394Smrg    --lt-*)
53039ef0b394Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
53049ef0b394Smrg        exit 1
53059ef0b394Smrg      ;;
53069ef0b394Smrg    esac
53079ef0b394Smrg  done
53089ef0b394Smrg
53099ef0b394Smrg  # Print the debug banner immediately:
53109ef0b394Smrg  if test -n \"\$lt_option_debug\"; then
5311a3129944Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
53129ef0b394Smrg  fi
53139ef0b394Smrg}
53149ef0b394Smrg
53159ef0b394Smrg# Used when --lt-debug. Prints its arguments to stdout
53169ef0b394Smrg# (redirection is the responsibility of the caller)
53179ef0b394Smrgfunc_lt_dump_args ()
53189ef0b394Smrg{
53199ef0b394Smrg  lt_dump_args_N=1;
53209ef0b394Smrg  for lt_arg
53219ef0b394Smrg  do
5322a3129944Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
53239ef0b394Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
53249ef0b394Smrg  done
53259ef0b394Smrg}
53269ef0b394Smrg
53279ef0b394Smrg# Core function for launching the target application
53289ef0b394Smrgfunc_exec_program_core ()
53299ef0b394Smrg{
5330698f425bSmrg"
53319ef0b394Smrg  case $host in
53329ef0b394Smrg  # Backslashes separate directories on plain windows
53339ef0b394Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
53349ef0b394Smrg    $ECHO "\
53359ef0b394Smrg      if test -n \"\$lt_option_debug\"; then
5336a3129944Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
53379ef0b394Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
53389ef0b394Smrg      fi
53399ef0b394Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
53409ef0b394Smrg"
53419ef0b394Smrg    ;;
53429ef0b394Smrg
53439ef0b394Smrg  *)
53449ef0b394Smrg    $ECHO "\
53459ef0b394Smrg      if test -n \"\$lt_option_debug\"; then
5346a3129944Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
53479ef0b394Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
53489ef0b394Smrg      fi
53499ef0b394Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
53509ef0b394Smrg"
53519ef0b394Smrg    ;;
53529ef0b394Smrg  esac
53539ef0b394Smrg  $ECHO "\
53549ef0b394Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
53559ef0b394Smrg      exit 1
53569ef0b394Smrg}
53579ef0b394Smrg
53589ef0b394Smrg# A function to encapsulate launching the target application
53599ef0b394Smrg# Strips options in the --lt-* namespace from \$@ and
53609ef0b394Smrg# launches target application with the remaining arguments.
53619ef0b394Smrgfunc_exec_program ()
53629ef0b394Smrg{
5363fb5e8d76Smrg  case \" \$* \" in
5364fb5e8d76Smrg  *\\ --lt-*)
5365fb5e8d76Smrg    for lt_wr_arg
5366fb5e8d76Smrg    do
5367fb5e8d76Smrg      case \$lt_wr_arg in
5368fb5e8d76Smrg      --lt-*) ;;
5369fb5e8d76Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5370fb5e8d76Smrg      esac
5371fb5e8d76Smrg      shift
5372fb5e8d76Smrg    done ;;
5373fb5e8d76Smrg  esac
53749ef0b394Smrg  func_exec_program_core \${1+\"\$@\"}
53759ef0b394Smrg}
53769ef0b394Smrg
53779ef0b394Smrg  # Parse options
53789ef0b394Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5379266e564dSmrg
5380698f425bSmrg  # Find the directory that this script lives in.
53819ef0b394Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5382698f425bSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5383266e564dSmrg
5384698f425bSmrg  # Follow symbolic links until we get to the real thisdir.
53859ef0b394Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5386698f425bSmrg  while test -n \"\$file\"; do
53879ef0b394Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5388266e564dSmrg
5389698f425bSmrg    # If there was a directory component, then change thisdir.
5390698f425bSmrg    if test \"x\$destdir\" != \"x\$file\"; then
5391698f425bSmrg      case \"\$destdir\" in
5392698f425bSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5393698f425bSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5394266e564dSmrg      esac
5395698f425bSmrg    fi
5396266e564dSmrg
53979ef0b394Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
53989ef0b394Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5399698f425bSmrg  done
5400266e564dSmrg
5401698f425bSmrg  # Usually 'no', except on cygwin/mingw when embedded into
5402698f425bSmrg  # the cwrapper.
54039ef0b394Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5404698f425bSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5405698f425bSmrg    # special case for '.'
5406698f425bSmrg    if test \"\$thisdir\" = \".\"; then
5407698f425bSmrg      thisdir=\`pwd\`
5408698f425bSmrg    fi
5409698f425bSmrg    # remove .libs from thisdir
5410698f425bSmrg    case \"\$thisdir\" in
54119ef0b394Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5412698f425bSmrg    $objdir )   thisdir=. ;;
5413698f425bSmrg    esac
5414698f425bSmrg  fi
5415698f425bSmrg
5416698f425bSmrg  # Try to get the absolute directory name.
5417698f425bSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
5418698f425bSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5419698f425bSmrg"
5420698f425bSmrg
5421a3129944Smrg	if test yes = "$fast_install"; then
5422698f425bSmrg	  $ECHO "\
5423698f425bSmrg  program=lt-'$outputname'$exeext
5424698f425bSmrg  progdir=\"\$thisdir/$objdir\"
5425698f425bSmrg
5426698f425bSmrg  if test ! -f \"\$progdir/\$program\" ||
5427a3129944Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5428698f425bSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5429698f425bSmrg
5430698f425bSmrg    file=\"\$\$-\$program\"
5431698f425bSmrg
5432698f425bSmrg    if test ! -d \"\$progdir\"; then
5433698f425bSmrg      $MKDIR \"\$progdir\"
5434698f425bSmrg    else
5435698f425bSmrg      $RM \"\$progdir/\$file\"
5436698f425bSmrg    fi"
5437698f425bSmrg
5438698f425bSmrg	  $ECHO "\
5439698f425bSmrg
5440698f425bSmrg    # relink executable if necessary
5441698f425bSmrg    if test -n \"\$relink_command\"; then
5442698f425bSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5443698f425bSmrg      else
5444a3129944Smrg	\$ECHO \"\$relink_command_output\" >&2
5445698f425bSmrg	$RM \"\$progdir/\$file\"
5446698f425bSmrg	exit 1
5447266e564dSmrg      fi
5448698f425bSmrg    fi
5449266e564dSmrg
5450698f425bSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5451698f425bSmrg    { $RM \"\$progdir/\$program\";
5452698f425bSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5453698f425bSmrg    $RM \"\$progdir/\$file\"
5454698f425bSmrg  fi"
5455698f425bSmrg	else
5456698f425bSmrg	  $ECHO "\
5457698f425bSmrg  program='$outputname'
5458698f425bSmrg  progdir=\"\$thisdir/$objdir\"
5459698f425bSmrg"
5460266e564dSmrg	fi
5461266e564dSmrg
5462698f425bSmrg	$ECHO "\
5463266e564dSmrg
5464698f425bSmrg  if test -f \"\$progdir/\$program\"; then"
5465266e564dSmrg
54669ef0b394Smrg	# fixup the dll searchpath if we need to.
54679ef0b394Smrg	#
54689ef0b394Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
54699ef0b394Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
54709ef0b394Smrg	# libraries must come first.
54719ef0b394Smrg	if test -n "$dllsearchpath"; then
54729ef0b394Smrg	  $ECHO "\
54739ef0b394Smrg    # Add the dll search path components to the executable PATH
54749ef0b394Smrg    PATH=$dllsearchpath:\$PATH
54759ef0b394Smrg"
54769ef0b394Smrg	fi
54779ef0b394Smrg
5478698f425bSmrg	# Export our shlibpath_var if we have one.
5479a3129944Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5480698f425bSmrg	  $ECHO "\
5481698f425bSmrg    # Add our own library path to $shlibpath_var
5482698f425bSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5483266e564dSmrg
5484698f425bSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5485698f425bSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
54869ef0b394Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5487698f425bSmrg
5488698f425bSmrg    export $shlibpath_var
5489698f425bSmrg"
5490266e564dSmrg	fi
5491266e564dSmrg
5492698f425bSmrg	$ECHO "\
5493698f425bSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5494698f425bSmrg      # Run the actual program with our arguments.
54959ef0b394Smrg      func_exec_program \${1+\"\$@\"}
5496698f425bSmrg    fi
5497698f425bSmrg  else
5498698f425bSmrg    # The program doesn't exist.
5499a3129944Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5500698f425bSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
55019ef0b394Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5502698f425bSmrg    exit 1
5503698f425bSmrg  fi
5504698f425bSmrgfi\
5505698f425bSmrg"
5506698f425bSmrg}
5507266e564dSmrg
5508266e564dSmrg
5509698f425bSmrg# func_emit_cwrapperexe_src
5510698f425bSmrg# emit the source code for a wrapper executable on stdout
5511698f425bSmrg# Must ONLY be called from within func_mode_link because
5512698f425bSmrg# it depends on a number of variable set therein.
5513698f425bSmrgfunc_emit_cwrapperexe_src ()
5514698f425bSmrg{
5515698f425bSmrg	cat <<EOF
5516266e564dSmrg
5517698f425bSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5518a3129944Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5519266e564dSmrg
5520698f425bSmrg   The $output program cannot be directly executed until all the libtool
5521698f425bSmrg   libraries that it depends on are installed.
5522266e564dSmrg
5523698f425bSmrg   This wrapper executable should never be moved out of the build directory.
5524698f425bSmrg   If it is, it will not operate correctly.
5525698f425bSmrg*/
5526698f425bSmrgEOF
5527698f425bSmrg	    cat <<"EOF"
55289ef0b394Smrg#ifdef _MSC_VER
55299ef0b394Smrg# define _CRT_SECURE_NO_DEPRECATE 1
55309ef0b394Smrg#endif
5531698f425bSmrg#include <stdio.h>
5532698f425bSmrg#include <stdlib.h>
5533698f425bSmrg#ifdef _MSC_VER
5534698f425bSmrg# include <direct.h>
5535698f425bSmrg# include <process.h>
5536698f425bSmrg# include <io.h>
5537698f425bSmrg#else
5538698f425bSmrg# include <unistd.h>
5539698f425bSmrg# include <stdint.h>
5540698f425bSmrg# ifdef __CYGWIN__
5541698f425bSmrg#  include <io.h>
5542698f425bSmrg# endif
5543698f425bSmrg#endif
5544698f425bSmrg#include <malloc.h>
5545698f425bSmrg#include <stdarg.h>
5546698f425bSmrg#include <assert.h>
5547698f425bSmrg#include <string.h>
5548698f425bSmrg#include <ctype.h>
5549698f425bSmrg#include <errno.h>
5550698f425bSmrg#include <fcntl.h>
5551698f425bSmrg#include <sys/stat.h>
5552266e564dSmrg
5553a3129944Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5554a3129944Smrg
55559ef0b394Smrg/* declarations of non-ANSI functions */
5556a3129944Smrg#if defined __MINGW32__
55579ef0b394Smrg# ifdef __STRICT_ANSI__
55589ef0b394Smrgint _putenv (const char *);
55599ef0b394Smrg# endif
5560a3129944Smrg#elif defined __CYGWIN__
55619ef0b394Smrg# ifdef __STRICT_ANSI__
55629ef0b394Smrgchar *realpath (const char *, char *);
55639ef0b394Smrgint putenv (char *);
55649ef0b394Smrgint setenv (const char *, const char *, int);
55659ef0b394Smrg# endif
5566a3129944Smrg/* #elif defined other_platform || defined ... */
55679ef0b394Smrg#endif
55689ef0b394Smrg
55699ef0b394Smrg/* portability defines, excluding path handling macros */
5570a3129944Smrg#if defined _MSC_VER
55719ef0b394Smrg# define setmode _setmode
55729ef0b394Smrg# define stat    _stat
55739ef0b394Smrg# define chmod   _chmod
55749ef0b394Smrg# define getcwd  _getcwd
55759ef0b394Smrg# define putenv  _putenv
55769ef0b394Smrg# define S_IXUSR _S_IEXEC
5577a3129944Smrg#elif defined __MINGW32__
55789ef0b394Smrg# define setmode _setmode
55799ef0b394Smrg# define stat    _stat
55809ef0b394Smrg# define chmod   _chmod
55819ef0b394Smrg# define getcwd  _getcwd
55829ef0b394Smrg# define putenv  _putenv
5583a3129944Smrg#elif defined __CYGWIN__
55849ef0b394Smrg# define HAVE_SETENV
55859ef0b394Smrg# define FOPEN_WB "wb"
5586a3129944Smrg/* #elif defined other platforms ... */
55879ef0b394Smrg#endif
55889ef0b394Smrg
5589a3129944Smrg#if defined PATH_MAX
5590698f425bSmrg# define LT_PATHMAX PATH_MAX
5591a3129944Smrg#elif defined MAXPATHLEN
5592698f425bSmrg# define LT_PATHMAX MAXPATHLEN
5593698f425bSmrg#else
5594698f425bSmrg# define LT_PATHMAX 1024
5595698f425bSmrg#endif
5596266e564dSmrg
5597698f425bSmrg#ifndef S_IXOTH
5598698f425bSmrg# define S_IXOTH 0
5599698f425bSmrg#endif
5600698f425bSmrg#ifndef S_IXGRP
5601698f425bSmrg# define S_IXGRP 0
5602698f425bSmrg#endif
5603266e564dSmrg
56049ef0b394Smrg/* path handling portability macros */
5605698f425bSmrg#ifndef DIR_SEPARATOR
5606698f425bSmrg# define DIR_SEPARATOR '/'
5607698f425bSmrg# define PATH_SEPARATOR ':'
5608698f425bSmrg#endif
5609266e564dSmrg
5610a3129944Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5611a3129944Smrg  defined __OS2__
5612698f425bSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
5613698f425bSmrg# define FOPEN_WB "wb"
5614698f425bSmrg# ifndef DIR_SEPARATOR_2
5615698f425bSmrg#  define DIR_SEPARATOR_2 '\\'
5616698f425bSmrg# endif
5617698f425bSmrg# ifndef PATH_SEPARATOR_2
5618698f425bSmrg#  define PATH_SEPARATOR_2 ';'
5619698f425bSmrg# endif
5620698f425bSmrg#endif
5621266e564dSmrg
5622698f425bSmrg#ifndef DIR_SEPARATOR_2
5623698f425bSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5624698f425bSmrg#else /* DIR_SEPARATOR_2 */
5625698f425bSmrg# define IS_DIR_SEPARATOR(ch) \
5626698f425bSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5627698f425bSmrg#endif /* DIR_SEPARATOR_2 */
5628266e564dSmrg
5629698f425bSmrg#ifndef PATH_SEPARATOR_2
5630698f425bSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5631698f425bSmrg#else /* PATH_SEPARATOR_2 */
5632698f425bSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5633698f425bSmrg#endif /* PATH_SEPARATOR_2 */
5634266e564dSmrg
5635698f425bSmrg#ifndef FOPEN_WB
5636698f425bSmrg# define FOPEN_WB "w"
5637698f425bSmrg#endif
5638698f425bSmrg#ifndef _O_BINARY
5639698f425bSmrg# define _O_BINARY 0
5640698f425bSmrg#endif
5641266e564dSmrg
5642698f425bSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5643698f425bSmrg#define XFREE(stale) do { \
5644a3129944Smrg  if (stale) { free (stale); stale = 0; } \
5645698f425bSmrg} while (0)
5646266e564dSmrg
5647a3129944Smrg#if defined LT_DEBUGWRAPPER
56489ef0b394Smrgstatic int lt_debug = 1;
5649698f425bSmrg#else
56509ef0b394Smrgstatic int lt_debug = 0;
5651698f425bSmrg#endif
5652266e564dSmrg
56539ef0b394Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5654266e564dSmrg
5655698f425bSmrgvoid *xmalloc (size_t num);
5656698f425bSmrgchar *xstrdup (const char *string);
5657698f425bSmrgconst char *base_name (const char *name);
5658698f425bSmrgchar *find_executable (const char *wrapper);
5659698f425bSmrgchar *chase_symlinks (const char *pathspec);
5660698f425bSmrgint make_executable (const char *path);
5661698f425bSmrgint check_executable (const char *path);
5662698f425bSmrgchar *strendzap (char *str, const char *pat);
56639ef0b394Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
56649ef0b394Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
56659ef0b394Smrgstatic const char *nonnull (const char *s);
56669ef0b394Smrgstatic const char *nonempty (const char *s);
5667698f425bSmrgvoid lt_setenv (const char *name, const char *value);
5668698f425bSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5669698f425bSmrgvoid lt_update_exe_path (const char *name, const char *value);
5670698f425bSmrgvoid lt_update_lib_path (const char *name, const char *value);
56719ef0b394Smrgchar **prepare_spawn (char **argv);
56729ef0b394Smrgvoid lt_dump_script (FILE *f);
5673698f425bSmrgEOF
5674698f425bSmrg
5675698f425bSmrg	    cat <<EOF
5676a3129944Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5677a3129944Smrg# define externally_visible volatile
5678a3129944Smrg#else
5679a3129944Smrg# define externally_visible __attribute__((externally_visible)) volatile
5680a3129944Smrg#endif
5681a3129944Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5682698f425bSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5683698f425bSmrgEOF
5684266e564dSmrg
5685a3129944Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
56869ef0b394Smrg              func_to_host_path "$temp_rpath"
5687698f425bSmrg	      cat <<EOF
56889ef0b394Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5689698f425bSmrgEOF
5690698f425bSmrg	    else
5691698f425bSmrg	      cat <<"EOF"
5692698f425bSmrgconst char * LIB_PATH_VALUE   = "";
5693698f425bSmrgEOF
5694266e564dSmrg	    fi
5695266e564dSmrg
5696698f425bSmrg	    if test -n "$dllsearchpath"; then
56979ef0b394Smrg              func_to_host_path "$dllsearchpath:"
5698698f425bSmrg	      cat <<EOF
5699698f425bSmrgconst char * EXE_PATH_VARNAME = "PATH";
57009ef0b394Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5701266e564dSmrgEOF
5702266e564dSmrg	    else
5703698f425bSmrg	      cat <<"EOF"
5704698f425bSmrgconst char * EXE_PATH_VARNAME = "";
5705698f425bSmrgconst char * EXE_PATH_VALUE   = "";
5706698f425bSmrgEOF
5707266e564dSmrg	    fi
5708698f425bSmrg
5709a3129944Smrg	    if test yes = "$fast_install"; then
5710698f425bSmrg	      cat <<EOF
5711698f425bSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5712698f425bSmrgEOF
5713266e564dSmrg	    else
5714698f425bSmrg	      cat <<EOF
5715698f425bSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5716698f425bSmrgEOF
5717266e564dSmrg	    fi
5718266e564dSmrg
5719266e564dSmrg
5720698f425bSmrg	    cat <<"EOF"
5721266e564dSmrg
5722698f425bSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5723266e564dSmrg
5724698f425bSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5725698f425bSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
57269ef0b394Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5727266e564dSmrg
5728698f425bSmrgint
5729698f425bSmrgmain (int argc, char *argv[])
5730698f425bSmrg{
5731698f425bSmrg  char **newargz;
5732698f425bSmrg  int  newargc;
5733698f425bSmrg  char *tmp_pathspec;
5734698f425bSmrg  char *actual_cwrapper_path;
5735698f425bSmrg  char *actual_cwrapper_name;
5736698f425bSmrg  char *target_name;
5737698f425bSmrg  char *lt_argv_zero;
5738a3129944Smrg  int rval = 127;
5739266e564dSmrg
5740698f425bSmrg  int i;
5741266e564dSmrg
5742698f425bSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
5743a3129944Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
5744266e564dSmrg
57459ef0b394Smrg  /* very simple arg parsing; don't want to rely on getopt
57469ef0b394Smrg   * also, copy all non cwrapper options to newargz, except
57479ef0b394Smrg   * argz[0], which is handled differently
57489ef0b394Smrg   */
57499ef0b394Smrg  newargc=0;
5750698f425bSmrg  for (i = 1; i < argc; i++)
5751698f425bSmrg    {
5752a3129944Smrg      if (STREQ (argv[i], dumpscript_opt))
5753698f425bSmrg	{
5754698f425bSmrgEOF
5755a3129944Smrg	    case $host in
5756698f425bSmrg	      *mingw* | *cygwin* )
5757698f425bSmrg		# make stdout use "unix" line endings
5758698f425bSmrg		echo "          setmode(1,_O_BINARY);"
5759698f425bSmrg		;;
5760698f425bSmrg	      esac
5761266e564dSmrg
5762698f425bSmrg	    cat <<"EOF"
57639ef0b394Smrg	  lt_dump_script (stdout);
5764698f425bSmrg	  return 0;
5765698f425bSmrg	}
5766a3129944Smrg      if (STREQ (argv[i], debug_opt))
57679ef0b394Smrg	{
57689ef0b394Smrg          lt_debug = 1;
57699ef0b394Smrg          continue;
57709ef0b394Smrg	}
5771a3129944Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
57729ef0b394Smrg        {
57739ef0b394Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
57749ef0b394Smrg             namespace, but it is not one of the ones we know about and
57759ef0b394Smrg             have already dealt with, above (inluding dump-script), then
57769ef0b394Smrg             report an error. Otherwise, targets might begin to believe
57779ef0b394Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
57789ef0b394Smrg             namespace. The first time any user complains about this, we'll
57799ef0b394Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
57809ef0b394Smrg             or a configure.ac-settable value.
57819ef0b394Smrg           */
57829ef0b394Smrg          lt_fatal (__FILE__, __LINE__,
57839ef0b394Smrg		    "unrecognized %s option: '%s'",
57849ef0b394Smrg                    ltwrapper_option_prefix, argv[i]);
57859ef0b394Smrg        }
57869ef0b394Smrg      /* otherwise ... */
57879ef0b394Smrg      newargz[++newargc] = xstrdup (argv[i]);
5788698f425bSmrg    }
57899ef0b394Smrg  newargz[++newargc] = NULL;
57909ef0b394Smrg
57919ef0b394SmrgEOF
57929ef0b394Smrg	    cat <<EOF
57939ef0b394Smrg  /* The GNU banner must be the first non-error debug message */
5794a3129944Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
57959ef0b394SmrgEOF
57969ef0b394Smrg	    cat <<"EOF"
57979ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
57989ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
5799266e564dSmrg
5800698f425bSmrg  tmp_pathspec = find_executable (argv[0]);
5801698f425bSmrg  if (tmp_pathspec == NULL)
58029ef0b394Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
58039ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
58049ef0b394Smrg                  "(main) found exe (before symlink chase) at: %s\n",
58059ef0b394Smrg		  tmp_pathspec);
5806698f425bSmrg
5807698f425bSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
58089ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
58099ef0b394Smrg                  "(main) found exe (after symlink chase) at: %s\n",
58109ef0b394Smrg		  actual_cwrapper_path);
5811698f425bSmrg  XFREE (tmp_pathspec);
5812698f425bSmrg
58139ef0b394Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
5814698f425bSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
5815698f425bSmrg
5816698f425bSmrg  /* wrapper name transforms */
5817698f425bSmrg  strendzap (actual_cwrapper_name, ".exe");
5818698f425bSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
5819698f425bSmrg  XFREE (actual_cwrapper_name);
5820698f425bSmrg  actual_cwrapper_name = tmp_pathspec;
5821698f425bSmrg  tmp_pathspec = 0;
5822698f425bSmrg
5823698f425bSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
5824698f425bSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
5825698f425bSmrg  strendzap (target_name, ".exe");
5826698f425bSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
5827698f425bSmrg  XFREE (target_name);
5828698f425bSmrg  target_name = tmp_pathspec;
5829698f425bSmrg  tmp_pathspec = 0;
5830698f425bSmrg
58319ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
58329ef0b394Smrg		  "(main) libtool target name: %s\n",
58339ef0b394Smrg		  target_name);
5834698f425bSmrgEOF
5835266e564dSmrg
5836698f425bSmrg	    cat <<EOF
5837698f425bSmrg  newargz[0] =
5838698f425bSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
5839698f425bSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
5840698f425bSmrg  strcpy (newargz[0], actual_cwrapper_path);
5841698f425bSmrg  strcat (newargz[0], "$objdir");
5842698f425bSmrg  strcat (newargz[0], "/");
5843698f425bSmrgEOF
5844266e564dSmrg
5845698f425bSmrg	    cat <<"EOF"
5846698f425bSmrg  /* stop here, and copy so we don't have to do this twice */
5847698f425bSmrg  tmp_pathspec = xstrdup (newargz[0]);
5848266e564dSmrg
5849698f425bSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
5850698f425bSmrg  strcat (newargz[0], actual_cwrapper_name);
5851266e564dSmrg
5852698f425bSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
5853698f425bSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
5854698f425bSmrg  XFREE (tmp_pathspec);
5855698f425bSmrg  tmp_pathspec = NULL;
5856698f425bSmrgEOF
5857266e564dSmrg
5858698f425bSmrg	    case $host_os in
5859698f425bSmrg	      mingw*)
5860698f425bSmrg	    cat <<"EOF"
5861698f425bSmrg  {
5862698f425bSmrg    char* p;
5863698f425bSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
5864698f425bSmrg      {
5865698f425bSmrg	*p = '/';
5866698f425bSmrg      }
5867698f425bSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
5868698f425bSmrg      {
5869698f425bSmrg	*p = '/';
5870698f425bSmrg      }
5871698f425bSmrg  }
5872698f425bSmrgEOF
5873698f425bSmrg	    ;;
5874698f425bSmrg	    esac
5875266e564dSmrg
5876698f425bSmrg	    cat <<"EOF"
5877698f425bSmrg  XFREE (target_name);
5878698f425bSmrg  XFREE (actual_cwrapper_path);
5879698f425bSmrg  XFREE (actual_cwrapper_name);
5880266e564dSmrg
5881698f425bSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
5882698f425bSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
58839ef0b394Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
58849ef0b394Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
58859ef0b394Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
58869ef0b394Smrg     libraries must come first. */
5887698f425bSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
58889ef0b394Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
5889266e564dSmrg
58909ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
58919ef0b394Smrg		  nonnull (lt_argv_zero));
5892698f425bSmrg  for (i = 0; i < newargc; i++)
5893698f425bSmrg    {
58949ef0b394Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
58959ef0b394Smrg		      i, nonnull (newargz[i]));
5896698f425bSmrg    }
5897266e564dSmrg
5898698f425bSmrgEOF
5899266e564dSmrg
5900698f425bSmrg	    case $host_os in
5901698f425bSmrg	      mingw*)
5902698f425bSmrg		cat <<"EOF"
5903698f425bSmrg  /* execv doesn't actually work on mingw as expected on unix */
59049ef0b394Smrg  newargz = prepare_spawn (newargz);
5905a3129944Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
5906698f425bSmrg  if (rval == -1)
5907698f425bSmrg    {
5908698f425bSmrg      /* failed to start process */
59099ef0b394Smrg      lt_debugprintf (__FILE__, __LINE__,
59109ef0b394Smrg		      "(main) failed to launch target \"%s\": %s\n",
59119ef0b394Smrg		      lt_argv_zero, nonnull (strerror (errno)));
5912698f425bSmrg      return 127;
5913698f425bSmrg    }
5914698f425bSmrg  return rval;
5915698f425bSmrgEOF
5916698f425bSmrg		;;
5917698f425bSmrg	      *)
5918698f425bSmrg		cat <<"EOF"
5919698f425bSmrg  execv (lt_argv_zero, newargz);
5920698f425bSmrg  return rval; /* =127, but avoids unused variable warning */
5921698f425bSmrgEOF
5922698f425bSmrg		;;
5923698f425bSmrg	    esac
5924266e564dSmrg
5925698f425bSmrg	    cat <<"EOF"
5926698f425bSmrg}
5927266e564dSmrg
5928698f425bSmrgvoid *
5929698f425bSmrgxmalloc (size_t num)
5930698f425bSmrg{
5931698f425bSmrg  void *p = (void *) malloc (num);
5932698f425bSmrg  if (!p)
59339ef0b394Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
5934266e564dSmrg
5935698f425bSmrg  return p;
5936698f425bSmrg}
5937266e564dSmrg
5938698f425bSmrgchar *
5939698f425bSmrgxstrdup (const char *string)
5940698f425bSmrg{
5941698f425bSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
5942698f425bSmrg			  string) : NULL;
5943698f425bSmrg}
5944266e564dSmrg
5945698f425bSmrgconst char *
5946698f425bSmrgbase_name (const char *name)
5947698f425bSmrg{
5948698f425bSmrg  const char *base;
5949266e564dSmrg
5950a3129944Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
5951698f425bSmrg  /* Skip over the disk name in MSDOS pathnames. */
5952698f425bSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
5953698f425bSmrg    name += 2;
5954698f425bSmrg#endif
5955266e564dSmrg
5956698f425bSmrg  for (base = name; *name; name++)
5957698f425bSmrg    if (IS_DIR_SEPARATOR (*name))
5958698f425bSmrg      base = name + 1;
5959698f425bSmrg  return base;
5960698f425bSmrg}
5961266e564dSmrg
5962698f425bSmrgint
5963698f425bSmrgcheck_executable (const char *path)
5964698f425bSmrg{
5965698f425bSmrg  struct stat st;
5966266e564dSmrg
59679ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
59689ef0b394Smrg                  nonempty (path));
5969698f425bSmrg  if ((!path) || (!*path))
5970698f425bSmrg    return 0;
5971266e564dSmrg
5972698f425bSmrg  if ((stat (path, &st) >= 0)
5973698f425bSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
5974698f425bSmrg    return 1;
5975698f425bSmrg  else
5976698f425bSmrg    return 0;
5977698f425bSmrg}
5978266e564dSmrg
5979698f425bSmrgint
5980698f425bSmrgmake_executable (const char *path)
5981698f425bSmrg{
5982698f425bSmrg  int rval = 0;
5983698f425bSmrg  struct stat st;
5984266e564dSmrg
59859ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
59869ef0b394Smrg                  nonempty (path));
5987698f425bSmrg  if ((!path) || (!*path))
5988698f425bSmrg    return 0;
5989266e564dSmrg
5990698f425bSmrg  if (stat (path, &st) >= 0)
5991698f425bSmrg    {
5992698f425bSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
5993698f425bSmrg    }
5994698f425bSmrg  return rval;
5995698f425bSmrg}
5996266e564dSmrg
5997698f425bSmrg/* Searches for the full path of the wrapper.  Returns
5998698f425bSmrg   newly allocated full path name if found, NULL otherwise
5999698f425bSmrg   Does not chase symlinks, even on platforms that support them.
6000698f425bSmrg*/
6001698f425bSmrgchar *
6002698f425bSmrgfind_executable (const char *wrapper)
6003698f425bSmrg{
6004698f425bSmrg  int has_slash = 0;
6005698f425bSmrg  const char *p;
6006698f425bSmrg  const char *p_next;
6007698f425bSmrg  /* static buffer for getcwd */
6008698f425bSmrg  char tmp[LT_PATHMAX + 1];
6009a3129944Smrg  size_t tmp_len;
6010698f425bSmrg  char *concat_name;
6011266e564dSmrg
60129ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
60139ef0b394Smrg                  nonempty (wrapper));
6014266e564dSmrg
6015698f425bSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6016698f425bSmrg    return NULL;
6017266e564dSmrg
6018698f425bSmrg  /* Absolute path? */
6019a3129944Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6020698f425bSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6021698f425bSmrg    {
6022698f425bSmrg      concat_name = xstrdup (wrapper);
6023698f425bSmrg      if (check_executable (concat_name))
6024698f425bSmrg	return concat_name;
6025698f425bSmrg      XFREE (concat_name);
6026698f425bSmrg    }
6027698f425bSmrg  else
6028698f425bSmrg    {
6029698f425bSmrg#endif
6030698f425bSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6031698f425bSmrg	{
6032698f425bSmrg	  concat_name = xstrdup (wrapper);
6033698f425bSmrg	  if (check_executable (concat_name))
6034698f425bSmrg	    return concat_name;
6035698f425bSmrg	  XFREE (concat_name);
6036698f425bSmrg	}
6037a3129944Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6038698f425bSmrg    }
6039698f425bSmrg#endif
6040266e564dSmrg
6041698f425bSmrg  for (p = wrapper; *p; p++)
6042698f425bSmrg    if (*p == '/')
6043698f425bSmrg      {
6044698f425bSmrg	has_slash = 1;
6045698f425bSmrg	break;
6046698f425bSmrg      }
6047698f425bSmrg  if (!has_slash)
6048698f425bSmrg    {
6049698f425bSmrg      /* no slashes; search PATH */
6050698f425bSmrg      const char *path = getenv ("PATH");
6051698f425bSmrg      if (path != NULL)
6052698f425bSmrg	{
6053698f425bSmrg	  for (p = path; *p; p = p_next)
6054698f425bSmrg	    {
6055698f425bSmrg	      const char *q;
6056698f425bSmrg	      size_t p_len;
6057698f425bSmrg	      for (q = p; *q; q++)
6058698f425bSmrg		if (IS_PATH_SEPARATOR (*q))
6059698f425bSmrg		  break;
6060a3129944Smrg	      p_len = (size_t) (q - p);
6061698f425bSmrg	      p_next = (*q == '\0' ? q : q + 1);
6062698f425bSmrg	      if (p_len == 0)
6063698f425bSmrg		{
6064698f425bSmrg		  /* empty path: current directory */
6065698f425bSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
60669ef0b394Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
60679ef0b394Smrg                              nonnull (strerror (errno)));
6068698f425bSmrg		  tmp_len = strlen (tmp);
6069698f425bSmrg		  concat_name =
6070698f425bSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6071698f425bSmrg		  memcpy (concat_name, tmp, tmp_len);
6072698f425bSmrg		  concat_name[tmp_len] = '/';
6073698f425bSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6074698f425bSmrg		}
6075698f425bSmrg	      else
6076698f425bSmrg		{
6077698f425bSmrg		  concat_name =
6078698f425bSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6079698f425bSmrg		  memcpy (concat_name, p, p_len);
6080698f425bSmrg		  concat_name[p_len] = '/';
6081698f425bSmrg		  strcpy (concat_name + p_len + 1, wrapper);
6082698f425bSmrg		}
6083698f425bSmrg	      if (check_executable (concat_name))
6084698f425bSmrg		return concat_name;
6085698f425bSmrg	      XFREE (concat_name);
6086698f425bSmrg	    }
6087698f425bSmrg	}
6088698f425bSmrg      /* not found in PATH; assume curdir */
6089698f425bSmrg    }
6090698f425bSmrg  /* Relative path | not found in path: prepend cwd */
6091698f425bSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
60929ef0b394Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
60939ef0b394Smrg              nonnull (strerror (errno)));
6094698f425bSmrg  tmp_len = strlen (tmp);
6095698f425bSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6096698f425bSmrg  memcpy (concat_name, tmp, tmp_len);
6097698f425bSmrg  concat_name[tmp_len] = '/';
6098698f425bSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
6099266e564dSmrg
6100698f425bSmrg  if (check_executable (concat_name))
6101698f425bSmrg    return concat_name;
6102698f425bSmrg  XFREE (concat_name);
6103698f425bSmrg  return NULL;
6104698f425bSmrg}
6105266e564dSmrg
6106698f425bSmrgchar *
6107698f425bSmrgchase_symlinks (const char *pathspec)
6108698f425bSmrg{
6109698f425bSmrg#ifndef S_ISLNK
6110698f425bSmrg  return xstrdup (pathspec);
6111698f425bSmrg#else
6112698f425bSmrg  char buf[LT_PATHMAX];
6113698f425bSmrg  struct stat s;
6114698f425bSmrg  char *tmp_pathspec = xstrdup (pathspec);
6115698f425bSmrg  char *p;
6116698f425bSmrg  int has_symlinks = 0;
6117698f425bSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
6118698f425bSmrg    {
61199ef0b394Smrg      lt_debugprintf (__FILE__, __LINE__,
61209ef0b394Smrg		      "checking path component for symlinks: %s\n",
61219ef0b394Smrg		      tmp_pathspec);
6122698f425bSmrg      if (lstat (tmp_pathspec, &s) == 0)
6123698f425bSmrg	{
6124698f425bSmrg	  if (S_ISLNK (s.st_mode) != 0)
6125698f425bSmrg	    {
6126698f425bSmrg	      has_symlinks = 1;
6127698f425bSmrg	      break;
6128698f425bSmrg	    }
6129266e564dSmrg
6130698f425bSmrg	  /* search backwards for last DIR_SEPARATOR */
6131698f425bSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6132698f425bSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6133698f425bSmrg	    p--;
6134698f425bSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6135698f425bSmrg	    {
6136698f425bSmrg	      /* no more DIR_SEPARATORS left */
6137698f425bSmrg	      break;
6138698f425bSmrg	    }
6139698f425bSmrg	  *p = '\0';
6140698f425bSmrg	}
6141698f425bSmrg      else
6142698f425bSmrg	{
61439ef0b394Smrg	  lt_fatal (__FILE__, __LINE__,
61449ef0b394Smrg		    "error accessing file \"%s\": %s",
61459ef0b394Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6146698f425bSmrg	}
6147698f425bSmrg    }
6148698f425bSmrg  XFREE (tmp_pathspec);
6149266e564dSmrg
6150698f425bSmrg  if (!has_symlinks)
6151698f425bSmrg    {
6152698f425bSmrg      return xstrdup (pathspec);
6153698f425bSmrg    }
6154266e564dSmrg
6155698f425bSmrg  tmp_pathspec = realpath (pathspec, buf);
6156698f425bSmrg  if (tmp_pathspec == 0)
6157698f425bSmrg    {
61589ef0b394Smrg      lt_fatal (__FILE__, __LINE__,
61599ef0b394Smrg		"could not follow symlinks for %s", pathspec);
6160698f425bSmrg    }
6161698f425bSmrg  return xstrdup (tmp_pathspec);
6162698f425bSmrg#endif
6163698f425bSmrg}
6164266e564dSmrg
6165698f425bSmrgchar *
6166698f425bSmrgstrendzap (char *str, const char *pat)
6167698f425bSmrg{
6168698f425bSmrg  size_t len, patlen;
6169266e564dSmrg
6170698f425bSmrg  assert (str != NULL);
6171698f425bSmrg  assert (pat != NULL);
6172266e564dSmrg
6173698f425bSmrg  len = strlen (str);
6174698f425bSmrg  patlen = strlen (pat);
6175266e564dSmrg
6176698f425bSmrg  if (patlen <= len)
6177698f425bSmrg    {
6178698f425bSmrg      str += len - patlen;
6179a3129944Smrg      if (STREQ (str, pat))
6180698f425bSmrg	*str = '\0';
6181698f425bSmrg    }
6182698f425bSmrg  return str;
6183698f425bSmrg}
6184266e564dSmrg
61859ef0b394Smrgvoid
61869ef0b394Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
61879ef0b394Smrg{
61889ef0b394Smrg  va_list args;
61899ef0b394Smrg  if (lt_debug)
61909ef0b394Smrg    {
61919ef0b394Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
61929ef0b394Smrg      va_start (args, fmt);
61939ef0b394Smrg      (void) vfprintf (stderr, fmt, args);
61949ef0b394Smrg      va_end (args);
61959ef0b394Smrg    }
61969ef0b394Smrg}
61979ef0b394Smrg
6198698f425bSmrgstatic void
61999ef0b394Smrglt_error_core (int exit_status, const char *file,
62009ef0b394Smrg	       int line, const char *mode,
6201698f425bSmrg	       const char *message, va_list ap)
6202698f425bSmrg{
62039ef0b394Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6204698f425bSmrg  vfprintf (stderr, message, ap);
6205698f425bSmrg  fprintf (stderr, ".\n");
6206266e564dSmrg
6207698f425bSmrg  if (exit_status >= 0)
6208698f425bSmrg    exit (exit_status);
6209698f425bSmrg}
6210266e564dSmrg
6211698f425bSmrgvoid
62129ef0b394Smrglt_fatal (const char *file, int line, const char *message, ...)
6213698f425bSmrg{
6214698f425bSmrg  va_list ap;
6215698f425bSmrg  va_start (ap, message);
62169ef0b394Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6217698f425bSmrg  va_end (ap);
6218698f425bSmrg}
6219266e564dSmrg
62209ef0b394Smrgstatic const char *
62219ef0b394Smrgnonnull (const char *s)
62229ef0b394Smrg{
62239ef0b394Smrg  return s ? s : "(null)";
62249ef0b394Smrg}
62259ef0b394Smrg
62269ef0b394Smrgstatic const char *
62279ef0b394Smrgnonempty (const char *s)
62289ef0b394Smrg{
62299ef0b394Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
62309ef0b394Smrg}
62319ef0b394Smrg
6232698f425bSmrgvoid
6233698f425bSmrglt_setenv (const char *name, const char *value)
6234698f425bSmrg{
62359ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
62369ef0b394Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
62379ef0b394Smrg                  nonnull (name), nonnull (value));
6238698f425bSmrg  {
6239698f425bSmrg#ifdef HAVE_SETENV
6240698f425bSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
6241698f425bSmrg    char *str = xstrdup (value);
6242698f425bSmrg    setenv (name, str, 1);
6243698f425bSmrg#else
6244a3129944Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6245698f425bSmrg    char *str = XMALLOC (char, len);
6246698f425bSmrg    sprintf (str, "%s=%s", name, value);
6247698f425bSmrg    if (putenv (str) != EXIT_SUCCESS)
6248698f425bSmrg      {
6249698f425bSmrg        XFREE (str);
6250698f425bSmrg      }
6251698f425bSmrg#endif
6252698f425bSmrg  }
6253698f425bSmrg}
6254266e564dSmrg
6255698f425bSmrgchar *
6256698f425bSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
6257698f425bSmrg{
6258698f425bSmrg  char *new_value;
6259698f425bSmrg  if (orig_value && *orig_value)
6260698f425bSmrg    {
6261a3129944Smrg      size_t orig_value_len = strlen (orig_value);
6262a3129944Smrg      size_t add_len = strlen (add);
6263698f425bSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6264698f425bSmrg      if (to_end)
6265698f425bSmrg        {
6266698f425bSmrg          strcpy (new_value, orig_value);
6267698f425bSmrg          strcpy (new_value + orig_value_len, add);
6268698f425bSmrg        }
6269698f425bSmrg      else
6270698f425bSmrg        {
6271698f425bSmrg          strcpy (new_value, add);
6272698f425bSmrg          strcpy (new_value + add_len, orig_value);
6273698f425bSmrg        }
6274698f425bSmrg    }
6275698f425bSmrg  else
6276698f425bSmrg    {
6277698f425bSmrg      new_value = xstrdup (add);
6278698f425bSmrg    }
6279698f425bSmrg  return new_value;
6280698f425bSmrg}
6281266e564dSmrg
6282698f425bSmrgvoid
6283698f425bSmrglt_update_exe_path (const char *name, const char *value)
6284698f425bSmrg{
62859ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
62869ef0b394Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
62879ef0b394Smrg                  nonnull (name), nonnull (value));
6288266e564dSmrg
6289698f425bSmrg  if (name && *name && value && *value)
6290698f425bSmrg    {
6291698f425bSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6292698f425bSmrg      /* some systems can't cope with a ':'-terminated path #' */
6293a3129944Smrg      size_t len = strlen (new_value);
6294a3129944Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6295698f425bSmrg        {
6296a3129944Smrg          new_value[--len] = '\0';
6297698f425bSmrg        }
6298698f425bSmrg      lt_setenv (name, new_value);
6299698f425bSmrg      XFREE (new_value);
6300698f425bSmrg    }
6301698f425bSmrg}
6302266e564dSmrg
6303698f425bSmrgvoid
6304698f425bSmrglt_update_lib_path (const char *name, const char *value)
6305698f425bSmrg{
63069ef0b394Smrg  lt_debugprintf (__FILE__, __LINE__,
63079ef0b394Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
63089ef0b394Smrg                  nonnull (name), nonnull (value));
6309266e564dSmrg
6310698f425bSmrg  if (name && *name && value && *value)
6311698f425bSmrg    {
6312698f425bSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6313698f425bSmrg      lt_setenv (name, new_value);
6314698f425bSmrg      XFREE (new_value);
6315698f425bSmrg    }
6316698f425bSmrg}
6317266e564dSmrg
63189ef0b394SmrgEOF
63199ef0b394Smrg	    case $host_os in
63209ef0b394Smrg	      mingw*)
63219ef0b394Smrg		cat <<"EOF"
63229ef0b394Smrg
63239ef0b394Smrg/* Prepares an argument vector before calling spawn().
63249ef0b394Smrg   Note that spawn() does not by itself call the command interpreter
63259ef0b394Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
63269ef0b394Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
63279ef0b394Smrg         GetVersionEx(&v);
63289ef0b394Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
63299ef0b394Smrg      }) ? "cmd.exe" : "command.com").
63309ef0b394Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
63319ef0b394Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
63329ef0b394Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
63339ef0b394Smrg   special way:
63349ef0b394Smrg   - Space and tab are interpreted as delimiters. They are not treated as
63359ef0b394Smrg     delimiters if they are surrounded by double quotes: "...".
63369ef0b394Smrg   - Unescaped double quotes are removed from the input. Their only effect is
63379ef0b394Smrg     that within double quotes, space and tab are treated like normal
63389ef0b394Smrg     characters.
63399ef0b394Smrg   - Backslashes not followed by double quotes are not special.
63409ef0b394Smrg   - But 2*n+1 backslashes followed by a double quote become
63419ef0b394Smrg     n backslashes followed by a double quote (n >= 0):
63429ef0b394Smrg       \" -> "
63439ef0b394Smrg       \\\" -> \"
63449ef0b394Smrg       \\\\\" -> \\"
63459ef0b394Smrg */
63469ef0b394Smrg#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"
63479ef0b394Smrg#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"
63489ef0b394Smrgchar **
63499ef0b394Smrgprepare_spawn (char **argv)
63509ef0b394Smrg{
63519ef0b394Smrg  size_t argc;
63529ef0b394Smrg  char **new_argv;
63539ef0b394Smrg  size_t i;
63549ef0b394Smrg
63559ef0b394Smrg  /* Count number of arguments.  */
63569ef0b394Smrg  for (argc = 0; argv[argc] != NULL; argc++)
63579ef0b394Smrg    ;
63589ef0b394Smrg
63599ef0b394Smrg  /* Allocate new argument vector.  */
63609ef0b394Smrg  new_argv = XMALLOC (char *, argc + 1);
63619ef0b394Smrg
63629ef0b394Smrg  /* Put quoted arguments into the new argument vector.  */
63639ef0b394Smrg  for (i = 0; i < argc; i++)
63649ef0b394Smrg    {
63659ef0b394Smrg      const char *string = argv[i];
63669ef0b394Smrg
63679ef0b394Smrg      if (string[0] == '\0')
63689ef0b394Smrg	new_argv[i] = xstrdup ("\"\"");
63699ef0b394Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
63709ef0b394Smrg	{
63719ef0b394Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
63729ef0b394Smrg	  size_t length;
63739ef0b394Smrg	  unsigned int backslashes;
63749ef0b394Smrg	  const char *s;
63759ef0b394Smrg	  char *quoted_string;
63769ef0b394Smrg	  char *p;
63779ef0b394Smrg
63789ef0b394Smrg	  length = 0;
63799ef0b394Smrg	  backslashes = 0;
63809ef0b394Smrg	  if (quote_around)
63819ef0b394Smrg	    length++;
63829ef0b394Smrg	  for (s = string; *s != '\0'; s++)
63839ef0b394Smrg	    {
63849ef0b394Smrg	      char c = *s;
63859ef0b394Smrg	      if (c == '"')
63869ef0b394Smrg		length += backslashes + 1;
63879ef0b394Smrg	      length++;
63889ef0b394Smrg	      if (c == '\\')
63899ef0b394Smrg		backslashes++;
63909ef0b394Smrg	      else
63919ef0b394Smrg		backslashes = 0;
63929ef0b394Smrg	    }
63939ef0b394Smrg	  if (quote_around)
63949ef0b394Smrg	    length += backslashes + 1;
63959ef0b394Smrg
63969ef0b394Smrg	  quoted_string = XMALLOC (char, length + 1);
63979ef0b394Smrg
63989ef0b394Smrg	  p = quoted_string;
63999ef0b394Smrg	  backslashes = 0;
64009ef0b394Smrg	  if (quote_around)
64019ef0b394Smrg	    *p++ = '"';
64029ef0b394Smrg	  for (s = string; *s != '\0'; s++)
64039ef0b394Smrg	    {
64049ef0b394Smrg	      char c = *s;
64059ef0b394Smrg	      if (c == '"')
64069ef0b394Smrg		{
64079ef0b394Smrg		  unsigned int j;
64089ef0b394Smrg		  for (j = backslashes + 1; j > 0; j--)
64099ef0b394Smrg		    *p++ = '\\';
64109ef0b394Smrg		}
64119ef0b394Smrg	      *p++ = c;
64129ef0b394Smrg	      if (c == '\\')
64139ef0b394Smrg		backslashes++;
64149ef0b394Smrg	      else
64159ef0b394Smrg		backslashes = 0;
64169ef0b394Smrg	    }
64179ef0b394Smrg	  if (quote_around)
64189ef0b394Smrg	    {
64199ef0b394Smrg	      unsigned int j;
64209ef0b394Smrg	      for (j = backslashes; j > 0; j--)
64219ef0b394Smrg		*p++ = '\\';
64229ef0b394Smrg	      *p++ = '"';
64239ef0b394Smrg	    }
64249ef0b394Smrg	  *p = '\0';
64259ef0b394Smrg
64269ef0b394Smrg	  new_argv[i] = quoted_string;
64279ef0b394Smrg	}
64289ef0b394Smrg      else
64299ef0b394Smrg	new_argv[i] = (char *) string;
64309ef0b394Smrg    }
64319ef0b394Smrg  new_argv[argc] = NULL;
64329ef0b394Smrg
64339ef0b394Smrg  return new_argv;
64349ef0b394Smrg}
64359ef0b394SmrgEOF
64369ef0b394Smrg		;;
64379ef0b394Smrg	    esac
64389ef0b394Smrg
64399ef0b394Smrg            cat <<"EOF"
64409ef0b394Smrgvoid lt_dump_script (FILE* f)
64419ef0b394Smrg{
64429ef0b394SmrgEOF
64439ef0b394Smrg	    func_emit_wrapper yes |
6444fb5e8d76Smrg	      $SED -n -e '
6445fb5e8d76Smrgs/^\(.\{79\}\)\(..*\)/\1\
6446fb5e8d76Smrg\2/
6447fb5e8d76Smrgh
6448fb5e8d76Smrgs/\([\\"]\)/\\\1/g
6449fb5e8d76Smrgs/$/\\n/
6450fb5e8d76Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6451fb5e8d76Smrgg
6452fb5e8d76SmrgD'
64539ef0b394Smrg            cat <<"EOF"
64549ef0b394Smrg}
6455698f425bSmrgEOF
6456698f425bSmrg}
6457698f425bSmrg# end: func_emit_cwrapperexe_src
6458266e564dSmrg
64599ef0b394Smrg# func_win32_import_lib_p ARG
64609ef0b394Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
64619ef0b394Smrgfunc_win32_import_lib_p ()
64629ef0b394Smrg{
6463a3129944Smrg    $debug_cmd
6464a3129944Smrg
64659ef0b394Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
64669ef0b394Smrg    *import*) : ;;
64679ef0b394Smrg    *) false ;;
64689ef0b394Smrg    esac
64699ef0b394Smrg}
64709ef0b394Smrg
6471a3129944Smrg# func_suncc_cstd_abi
6472a3129944Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6473a3129944Smrg# Several compiler flags select an ABI that is incompatible with the
6474a3129944Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6475a3129944Smrgfunc_suncc_cstd_abi ()
6476a3129944Smrg{
6477a3129944Smrg    $debug_cmd
6478a3129944Smrg
6479a3129944Smrg    case " $compile_command " in
6480a3129944Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6481a3129944Smrg      suncc_use_cstd_abi=no
6482a3129944Smrg      ;;
6483a3129944Smrg    *)
6484a3129944Smrg      suncc_use_cstd_abi=yes
6485a3129944Smrg      ;;
6486a3129944Smrg    esac
6487a3129944Smrg}
6488a3129944Smrg
6489698f425bSmrg# func_mode_link arg...
6490698f425bSmrgfunc_mode_link ()
6491698f425bSmrg{
6492a3129944Smrg    $debug_cmd
6493a3129944Smrg
6494698f425bSmrg    case $host in
6495698f425bSmrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6496698f425bSmrg      # It is impossible to link a dll without this setting, and
6497698f425bSmrg      # we shouldn't force the makefile maintainer to figure out
6498a3129944Smrg      # what system we are compiling for in order to pass an extra
6499698f425bSmrg      # flag for every libtool invocation.
6500698f425bSmrg      # allow_undefined=no
6501266e564dSmrg
6502698f425bSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6503a3129944Smrg      # to make a dll that has undefined symbols, in which case not
6504698f425bSmrg      # even a static library is built.  For now, we need to specify
6505698f425bSmrg      # -no-undefined on the libtool link line when we can be certain
6506698f425bSmrg      # that all symbols are satisfied, otherwise we get a static library.
6507698f425bSmrg      allow_undefined=yes
6508698f425bSmrg      ;;
6509698f425bSmrg    *)
6510698f425bSmrg      allow_undefined=yes
6511698f425bSmrg      ;;
6512698f425bSmrg    esac
6513698f425bSmrg    libtool_args=$nonopt
6514698f425bSmrg    base_compile="$nonopt $@"
6515698f425bSmrg    compile_command=$nonopt
6516698f425bSmrg    finalize_command=$nonopt
6517266e564dSmrg
6518698f425bSmrg    compile_rpath=
6519698f425bSmrg    finalize_rpath=
6520698f425bSmrg    compile_shlibpath=
6521698f425bSmrg    finalize_shlibpath=
6522698f425bSmrg    convenience=
6523698f425bSmrg    old_convenience=
6524698f425bSmrg    deplibs=
6525698f425bSmrg    old_deplibs=
6526698f425bSmrg    compiler_flags=
6527698f425bSmrg    linker_flags=
6528698f425bSmrg    dllsearchpath=
6529698f425bSmrg    lib_search_path=`pwd`
6530698f425bSmrg    inst_prefix_dir=
6531698f425bSmrg    new_inherited_linker_flags=
6532266e564dSmrg
6533698f425bSmrg    avoid_version=no
65349ef0b394Smrg    bindir=
6535698f425bSmrg    dlfiles=
6536698f425bSmrg    dlprefiles=
6537698f425bSmrg    dlself=no
6538698f425bSmrg    export_dynamic=no
6539698f425bSmrg    export_symbols=
6540698f425bSmrg    export_symbols_regex=
6541698f425bSmrg    generated=
6542698f425bSmrg    libobjs=
6543698f425bSmrg    ltlibs=
6544698f425bSmrg    module=no
6545698f425bSmrg    no_install=no
6546698f425bSmrg    objs=
6547a3129944Smrg    os2dllname=
6548698f425bSmrg    non_pic_objects=
6549698f425bSmrg    precious_files_regex=
6550698f425bSmrg    prefer_static_libs=no
6551a3129944Smrg    preload=false
6552698f425bSmrg    prev=
6553698f425bSmrg    prevarg=
6554698f425bSmrg    release=
6555698f425bSmrg    rpath=
6556698f425bSmrg    xrpath=
6557698f425bSmrg    perm_rpath=
6558698f425bSmrg    temp_rpath=
6559698f425bSmrg    thread_safe=no
6560698f425bSmrg    vinfo=
6561698f425bSmrg    vinfo_number=no
6562698f425bSmrg    weak_libs=
6563a3129944Smrg    single_module=$wl-single_module
6564698f425bSmrg    func_infer_tag $base_compile
6565266e564dSmrg
6566698f425bSmrg    # We need to know -static, to get the right output filenames.
6567698f425bSmrg    for arg
6568698f425bSmrg    do
6569698f425bSmrg      case $arg in
6570698f425bSmrg      -shared)
6571a3129944Smrg	test yes != "$build_libtool_libs" \
6572a3129944Smrg	  && func_fatal_configuration "cannot build a shared library"
6573698f425bSmrg	build_old_libs=no
6574698f425bSmrg	break
6575698f425bSmrg	;;
6576698f425bSmrg      -all-static | -static | -static-libtool-libs)
6577698f425bSmrg	case $arg in
6578698f425bSmrg	-all-static)
6579a3129944Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6580698f425bSmrg	    func_warning "complete static linking is impossible in this configuration"
6581698f425bSmrg	  fi
6582698f425bSmrg	  if test -n "$link_static_flag"; then
6583698f425bSmrg	    dlopen_self=$dlopen_self_static
6584698f425bSmrg	  fi
6585698f425bSmrg	  prefer_static_libs=yes
6586698f425bSmrg	  ;;
6587698f425bSmrg	-static)
6588698f425bSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6589698f425bSmrg	    dlopen_self=$dlopen_self_static
6590698f425bSmrg	  fi
6591698f425bSmrg	  prefer_static_libs=built
6592698f425bSmrg	  ;;
6593698f425bSmrg	-static-libtool-libs)
6594698f425bSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6595698f425bSmrg	    dlopen_self=$dlopen_self_static
6596698f425bSmrg	  fi
6597698f425bSmrg	  prefer_static_libs=yes
6598698f425bSmrg	  ;;
6599698f425bSmrg	esac
6600698f425bSmrg	build_libtool_libs=no
6601698f425bSmrg	build_old_libs=yes
6602698f425bSmrg	break
6603698f425bSmrg	;;
6604698f425bSmrg      esac
6605698f425bSmrg    done
6606266e564dSmrg
6607698f425bSmrg    # See if our shared archives depend on static archives.
6608698f425bSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6609266e564dSmrg
6610698f425bSmrg    # Go through the arguments, transforming them on the way.
6611698f425bSmrg    while test "$#" -gt 0; do
6612a3129944Smrg      arg=$1
6613698f425bSmrg      shift
6614698f425bSmrg      func_quote_for_eval "$arg"
6615698f425bSmrg      qarg=$func_quote_for_eval_unquoted_result
6616698f425bSmrg      func_append libtool_args " $func_quote_for_eval_result"
6617266e564dSmrg
6618698f425bSmrg      # If the previous option needs an argument, assign it.
6619698f425bSmrg      if test -n "$prev"; then
6620698f425bSmrg	case $prev in
6621698f425bSmrg	output)
6622698f425bSmrg	  func_append compile_command " @OUTPUT@"
6623698f425bSmrg	  func_append finalize_command " @OUTPUT@"
6624698f425bSmrg	  ;;
6625698f425bSmrg	esac
6626266e564dSmrg
6627698f425bSmrg	case $prev in
66289ef0b394Smrg	bindir)
6629a3129944Smrg	  bindir=$arg
66309ef0b394Smrg	  prev=
66319ef0b394Smrg	  continue
66329ef0b394Smrg	  ;;
6633698f425bSmrg	dlfiles|dlprefiles)
6634a3129944Smrg	  $preload || {
6635698f425bSmrg	    # Add the symbol object into the linking commands.
6636698f425bSmrg	    func_append compile_command " @SYMFILE@"
6637698f425bSmrg	    func_append finalize_command " @SYMFILE@"
6638a3129944Smrg	    preload=:
6639a3129944Smrg	  }
6640698f425bSmrg	  case $arg in
6641698f425bSmrg	  *.la | *.lo) ;;  # We handle these cases below.
6642698f425bSmrg	  force)
6643a3129944Smrg	    if test no = "$dlself"; then
6644698f425bSmrg	      dlself=needless
6645698f425bSmrg	      export_dynamic=yes
6646698f425bSmrg	    fi
6647698f425bSmrg	    prev=
6648698f425bSmrg	    continue
6649698f425bSmrg	    ;;
6650698f425bSmrg	  self)
6651a3129944Smrg	    if test dlprefiles = "$prev"; then
6652698f425bSmrg	      dlself=yes
6653a3129944Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6654698f425bSmrg	      dlself=yes
6655698f425bSmrg	    else
6656698f425bSmrg	      dlself=needless
6657698f425bSmrg	      export_dynamic=yes
6658698f425bSmrg	    fi
6659698f425bSmrg	    prev=
6660698f425bSmrg	    continue
6661698f425bSmrg	    ;;
6662698f425bSmrg	  *)
6663a3129944Smrg	    if test dlfiles = "$prev"; then
66649ef0b394Smrg	      func_append dlfiles " $arg"
6665698f425bSmrg	    else
66669ef0b394Smrg	      func_append dlprefiles " $arg"
6667698f425bSmrg	    fi
6668698f425bSmrg	    prev=
6669698f425bSmrg	    continue
6670698f425bSmrg	    ;;
6671698f425bSmrg	  esac
6672698f425bSmrg	  ;;
6673698f425bSmrg	expsyms)
6674a3129944Smrg	  export_symbols=$arg
6675698f425bSmrg	  test -f "$arg" \
6676a3129944Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
6677698f425bSmrg	  prev=
6678698f425bSmrg	  continue
6679698f425bSmrg	  ;;
6680698f425bSmrg	expsyms_regex)
6681a3129944Smrg	  export_symbols_regex=$arg
6682698f425bSmrg	  prev=
6683698f425bSmrg	  continue
6684698f425bSmrg	  ;;
6685698f425bSmrg	framework)
6686266e564dSmrg	  case $host in
6687698f425bSmrg	    *-*-darwin*)
6688698f425bSmrg	      case "$deplibs " in
6689698f425bSmrg		*" $qarg.ltframework "*) ;;
66909ef0b394Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6691698f425bSmrg		   ;;
6692698f425bSmrg	      esac
6693698f425bSmrg	      ;;
6694266e564dSmrg	  esac
6695698f425bSmrg	  prev=
6696698f425bSmrg	  continue
6697266e564dSmrg	  ;;
6698698f425bSmrg	inst_prefix)
6699a3129944Smrg	  inst_prefix_dir=$arg
6700a3129944Smrg	  prev=
6701a3129944Smrg	  continue
6702a3129944Smrg	  ;;
6703a3129944Smrg	mllvm)
6704a3129944Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6705a3129944Smrg	  # '-mllvm $arg' options when doing the link step.
6706698f425bSmrg	  prev=
6707698f425bSmrg	  continue
6708266e564dSmrg	  ;;
6709698f425bSmrg	objectlist)
6710698f425bSmrg	  if test -f "$arg"; then
6711698f425bSmrg	    save_arg=$arg
6712698f425bSmrg	    moreargs=
6713698f425bSmrg	    for fil in `cat "$save_arg"`
6714698f425bSmrg	    do
67159ef0b394Smrg#	      func_append moreargs " $fil"
6716698f425bSmrg	      arg=$fil
6717698f425bSmrg	      # A libtool-controlled object.
6718266e564dSmrg
6719698f425bSmrg	      # Check to see that this really is a libtool object.
6720698f425bSmrg	      if func_lalib_unsafe_p "$arg"; then
6721698f425bSmrg		pic_object=
6722698f425bSmrg		non_pic_object=
6723266e564dSmrg
6724698f425bSmrg		# Read the .lo file
6725698f425bSmrg		func_source "$arg"
6726266e564dSmrg
6727698f425bSmrg		if test -z "$pic_object" ||
6728698f425bSmrg		   test -z "$non_pic_object" ||
6729a3129944Smrg		   test none = "$pic_object" &&
6730a3129944Smrg		   test none = "$non_pic_object"; then
6731a3129944Smrg		  func_fatal_error "cannot find name of object for '$arg'"
6732698f425bSmrg		fi
6733266e564dSmrg
6734698f425bSmrg		# Extract subdirectory from the argument.
6735698f425bSmrg		func_dirname "$arg" "/" ""
6736a3129944Smrg		xdir=$func_dirname_result
6737266e564dSmrg
6738a3129944Smrg		if test none != "$pic_object"; then
6739698f425bSmrg		  # Prepend the subdirectory the object is found in.
6740a3129944Smrg		  pic_object=$xdir$pic_object
6741266e564dSmrg
6742a3129944Smrg		  if test dlfiles = "$prev"; then
6743a3129944Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
67449ef0b394Smrg		      func_append dlfiles " $pic_object"
6745698f425bSmrg		      prev=
6746698f425bSmrg		      continue
6747698f425bSmrg		    else
6748698f425bSmrg		      # If libtool objects are unsupported, then we need to preload.
6749698f425bSmrg		      prev=dlprefiles
6750698f425bSmrg		    fi
6751698f425bSmrg		  fi
6752266e564dSmrg
6753698f425bSmrg		  # CHECK ME:  I think I busted this.  -Ossama
6754a3129944Smrg		  if test dlprefiles = "$prev"; then
6755698f425bSmrg		    # Preload the old-style object.
67569ef0b394Smrg		    func_append dlprefiles " $pic_object"
6757698f425bSmrg		    prev=
6758698f425bSmrg		  fi
6759266e564dSmrg
6760698f425bSmrg		  # A PIC object.
6761698f425bSmrg		  func_append libobjs " $pic_object"
6762a3129944Smrg		  arg=$pic_object
6763698f425bSmrg		fi
6764266e564dSmrg
6765698f425bSmrg		# Non-PIC object.
6766a3129944Smrg		if test none != "$non_pic_object"; then
6767698f425bSmrg		  # Prepend the subdirectory the object is found in.
6768a3129944Smrg		  non_pic_object=$xdir$non_pic_object
6769698f425bSmrg
6770698f425bSmrg		  # A standard non-PIC object
6771698f425bSmrg		  func_append non_pic_objects " $non_pic_object"
6772a3129944Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
6773a3129944Smrg		    arg=$non_pic_object
6774698f425bSmrg		  fi
6775698f425bSmrg		else
6776698f425bSmrg		  # If the PIC object exists, use it instead.
6777698f425bSmrg		  # $xdir was prepended to $pic_object above.
6778a3129944Smrg		  non_pic_object=$pic_object
6779698f425bSmrg		  func_append non_pic_objects " $non_pic_object"
6780698f425bSmrg		fi
6781698f425bSmrg	      else
6782698f425bSmrg		# Only an error if not doing a dry-run.
6783698f425bSmrg		if $opt_dry_run; then
6784698f425bSmrg		  # Extract subdirectory from the argument.
6785698f425bSmrg		  func_dirname "$arg" "/" ""
6786a3129944Smrg		  xdir=$func_dirname_result
6787698f425bSmrg
6788698f425bSmrg		  func_lo2o "$arg"
6789698f425bSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
6790698f425bSmrg		  non_pic_object=$xdir$func_lo2o_result
6791698f425bSmrg		  func_append libobjs " $pic_object"
6792698f425bSmrg		  func_append non_pic_objects " $non_pic_object"
6793698f425bSmrg	        else
6794a3129944Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
6795698f425bSmrg		fi
6796698f425bSmrg	      fi
6797698f425bSmrg	    done
6798266e564dSmrg	  else
6799a3129944Smrg	    func_fatal_error "link input file '$arg' does not exist"
6800266e564dSmrg	  fi
6801698f425bSmrg	  arg=$save_arg
6802698f425bSmrg	  prev=
6803698f425bSmrg	  continue
6804698f425bSmrg	  ;;
6805a3129944Smrg	os2dllname)
6806a3129944Smrg	  os2dllname=$arg
6807a3129944Smrg	  prev=
6808a3129944Smrg	  continue
6809a3129944Smrg	  ;;
6810698f425bSmrg	precious_regex)
6811a3129944Smrg	  precious_files_regex=$arg
6812698f425bSmrg	  prev=
6813698f425bSmrg	  continue
6814698f425bSmrg	  ;;
6815698f425bSmrg	release)
6816a3129944Smrg	  release=-$arg
6817698f425bSmrg	  prev=
6818698f425bSmrg	  continue
6819698f425bSmrg	  ;;
6820698f425bSmrg	rpath | xrpath)
6821698f425bSmrg	  # We need an absolute path.
6822698f425bSmrg	  case $arg in
6823698f425bSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
6824698f425bSmrg	  *)
6825698f425bSmrg	    func_fatal_error "only absolute run-paths are allowed"
6826698f425bSmrg	    ;;
6827698f425bSmrg	  esac
6828a3129944Smrg	  if test rpath = "$prev"; then
6829698f425bSmrg	    case "$rpath " in
6830698f425bSmrg	    *" $arg "*) ;;
68319ef0b394Smrg	    *) func_append rpath " $arg" ;;
6832698f425bSmrg	    esac
6833266e564dSmrg	  else
6834698f425bSmrg	    case "$xrpath " in
6835698f425bSmrg	    *" $arg "*) ;;
68369ef0b394Smrg	    *) func_append xrpath " $arg" ;;
6837698f425bSmrg	    esac
6838266e564dSmrg	  fi
6839698f425bSmrg	  prev=
6840698f425bSmrg	  continue
6841698f425bSmrg	  ;;
6842698f425bSmrg	shrext)
6843a3129944Smrg	  shrext_cmds=$arg
6844698f425bSmrg	  prev=
6845698f425bSmrg	  continue
6846698f425bSmrg	  ;;
6847698f425bSmrg	weak)
68489ef0b394Smrg	  func_append weak_libs " $arg"
6849698f425bSmrg	  prev=
6850698f425bSmrg	  continue
6851698f425bSmrg	  ;;
6852698f425bSmrg	xcclinker)
68539ef0b394Smrg	  func_append linker_flags " $qarg"
68549ef0b394Smrg	  func_append compiler_flags " $qarg"
6855698f425bSmrg	  prev=
6856698f425bSmrg	  func_append compile_command " $qarg"
6857698f425bSmrg	  func_append finalize_command " $qarg"
6858698f425bSmrg	  continue
6859698f425bSmrg	  ;;
6860698f425bSmrg	xcompiler)
68619ef0b394Smrg	  func_append compiler_flags " $qarg"
6862698f425bSmrg	  prev=
6863698f425bSmrg	  func_append compile_command " $qarg"
6864698f425bSmrg	  func_append finalize_command " $qarg"
6865698f425bSmrg	  continue
6866698f425bSmrg	  ;;
6867698f425bSmrg	xlinker)
68689ef0b394Smrg	  func_append linker_flags " $qarg"
68699ef0b394Smrg	  func_append compiler_flags " $wl$qarg"
6870698f425bSmrg	  prev=
6871698f425bSmrg	  func_append compile_command " $wl$qarg"
6872698f425bSmrg	  func_append finalize_command " $wl$qarg"
6873698f425bSmrg	  continue
6874698f425bSmrg	  ;;
6875698f425bSmrg	*)
6876698f425bSmrg	  eval "$prev=\"\$arg\""
6877698f425bSmrg	  prev=
6878698f425bSmrg	  continue
6879698f425bSmrg	  ;;
6880266e564dSmrg	esac
6881698f425bSmrg      fi # test -n "$prev"
6882266e564dSmrg
6883a3129944Smrg      prevarg=$arg
6884266e564dSmrg
6885698f425bSmrg      case $arg in
6886698f425bSmrg      -all-static)
6887698f425bSmrg	if test -n "$link_static_flag"; then
6888698f425bSmrg	  # See comment for -static flag below, for more details.
6889698f425bSmrg	  func_append compile_command " $link_static_flag"
6890698f425bSmrg	  func_append finalize_command " $link_static_flag"
6891698f425bSmrg	fi
6892698f425bSmrg	continue
6893698f425bSmrg	;;
6894266e564dSmrg
6895698f425bSmrg      -allow-undefined)
6896698f425bSmrg	# FIXME: remove this flag sometime in the future.
6897a3129944Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
6898698f425bSmrg	;;
6899266e564dSmrg
6900698f425bSmrg      -avoid-version)
6901698f425bSmrg	avoid_version=yes
6902698f425bSmrg	continue
6903698f425bSmrg	;;
6904266e564dSmrg
69059ef0b394Smrg      -bindir)
69069ef0b394Smrg	prev=bindir
69079ef0b394Smrg	continue
69089ef0b394Smrg	;;
69099ef0b394Smrg
6910698f425bSmrg      -dlopen)
6911698f425bSmrg	prev=dlfiles
6912698f425bSmrg	continue
6913698f425bSmrg	;;
6914266e564dSmrg
6915698f425bSmrg      -dlpreopen)
6916698f425bSmrg	prev=dlprefiles
6917698f425bSmrg	continue
6918698f425bSmrg	;;
6919266e564dSmrg
6920698f425bSmrg      -export-dynamic)
6921698f425bSmrg	export_dynamic=yes
6922698f425bSmrg	continue
6923698f425bSmrg	;;
6924266e564dSmrg
6925698f425bSmrg      -export-symbols | -export-symbols-regex)
6926698f425bSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
6927698f425bSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
6928698f425bSmrg	fi
6929a3129944Smrg	if test X-export-symbols = "X$arg"; then
6930698f425bSmrg	  prev=expsyms
6931698f425bSmrg	else
6932698f425bSmrg	  prev=expsyms_regex
6933698f425bSmrg	fi
6934698f425bSmrg	continue
6935698f425bSmrg	;;
6936266e564dSmrg
6937698f425bSmrg      -framework)
6938698f425bSmrg	prev=framework
6939698f425bSmrg	continue
6940698f425bSmrg	;;
6941266e564dSmrg
6942698f425bSmrg      -inst-prefix-dir)
6943698f425bSmrg	prev=inst_prefix
6944698f425bSmrg	continue
6945698f425bSmrg	;;
6946266e564dSmrg
6947698f425bSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
6948698f425bSmrg      # so, if we see these flags be careful not to treat them like -L
6949698f425bSmrg      -L[A-Z][A-Z]*:*)
6950698f425bSmrg	case $with_gcc/$host in
6951698f425bSmrg	no/*-*-irix* | /*-*-irix*)
6952698f425bSmrg	  func_append compile_command " $arg"
6953698f425bSmrg	  func_append finalize_command " $arg"
6954698f425bSmrg	  ;;
6955698f425bSmrg	esac
6956698f425bSmrg	continue
6957698f425bSmrg	;;
6958266e564dSmrg
6959698f425bSmrg      -L*)
69609ef0b394Smrg	func_stripname "-L" '' "$arg"
69619ef0b394Smrg	if test -z "$func_stripname_result"; then
6962698f425bSmrg	  if test "$#" -gt 0; then
6963a3129944Smrg	    func_fatal_error "require no space between '-L' and '$1'"
6964698f425bSmrg	  else
6965a3129944Smrg	    func_fatal_error "need path for '-L' option"
6966698f425bSmrg	  fi
6967698f425bSmrg	fi
69689ef0b394Smrg	func_resolve_sysroot "$func_stripname_result"
69699ef0b394Smrg	dir=$func_resolve_sysroot_result
6970698f425bSmrg	# We need an absolute path.
6971698f425bSmrg	case $dir in
6972698f425bSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
6973698f425bSmrg	*)
6974698f425bSmrg	  absdir=`cd "$dir" && pwd`
6975698f425bSmrg	  test -z "$absdir" && \
6976a3129944Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
6977a3129944Smrg	  dir=$absdir
6978698f425bSmrg	  ;;
6979698f425bSmrg	esac
6980698f425bSmrg	case "$deplibs " in
69819ef0b394Smrg	*" -L$dir "* | *" $arg "*)
69829ef0b394Smrg	  # Will only happen for absolute or sysroot arguments
69839ef0b394Smrg	  ;;
6984698f425bSmrg	*)
69859ef0b394Smrg	  # Preserve sysroot, but never include relative directories
69869ef0b394Smrg	  case $dir in
69879ef0b394Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
69889ef0b394Smrg	    *) func_append deplibs " -L$dir" ;;
69899ef0b394Smrg	  esac
69909ef0b394Smrg	  func_append lib_search_path " $dir"
6991698f425bSmrg	  ;;
6992698f425bSmrg	esac
6993698f425bSmrg	case $host in
6994698f425bSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
69959ef0b394Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
6996698f425bSmrg	  case :$dllsearchpath: in
6997698f425bSmrg	  *":$dir:"*) ;;
6998698f425bSmrg	  ::) dllsearchpath=$dir;;
69999ef0b394Smrg	  *) func_append dllsearchpath ":$dir";;
7000698f425bSmrg	  esac
7001698f425bSmrg	  case :$dllsearchpath: in
7002698f425bSmrg	  *":$testbindir:"*) ;;
7003698f425bSmrg	  ::) dllsearchpath=$testbindir;;
70049ef0b394Smrg	  *) func_append dllsearchpath ":$testbindir";;
7005698f425bSmrg	  esac
7006698f425bSmrg	  ;;
7007698f425bSmrg	esac
7008698f425bSmrg	continue
7009698f425bSmrg	;;
7010266e564dSmrg
7011698f425bSmrg      -l*)
7012a3129944Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7013698f425bSmrg	  case $host in
70149ef0b394Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7015698f425bSmrg	    # These systems don't actually have a C or math library (as such)
7016698f425bSmrg	    continue
7017698f425bSmrg	    ;;
7018698f425bSmrg	  *-*-os2*)
7019698f425bSmrg	    # These systems don't actually have a C library (as such)
7020a3129944Smrg	    test X-lc = "X$arg" && continue
7021698f425bSmrg	    ;;
7022a3129944Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
7023698f425bSmrg	    # Do not include libc due to us having libc/libc_r.
7024a3129944Smrg	    test X-lc = "X$arg" && continue
7025698f425bSmrg	    ;;
7026698f425bSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
7027698f425bSmrg	    # Rhapsody C and math libraries are in the System framework
70289ef0b394Smrg	    func_append deplibs " System.ltframework"
7029698f425bSmrg	    continue
7030698f425bSmrg	    ;;
7031698f425bSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7032698f425bSmrg	    # Causes problems with __ctype
7033a3129944Smrg	    test X-lc = "X$arg" && continue
7034698f425bSmrg	    ;;
7035698f425bSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7036698f425bSmrg	    # Compiler inserts libc in the correct place for threads to work
7037a3129944Smrg	    test X-lc = "X$arg" && continue
7038698f425bSmrg	    ;;
7039698f425bSmrg	  esac
7040a3129944Smrg	elif test X-lc_r = "X$arg"; then
7041698f425bSmrg	 case $host in
7042a3129944Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
7043698f425bSmrg	   # Do not include libc_r directly, use -pthread flag.
7044698f425bSmrg	   continue
7045698f425bSmrg	   ;;
7046698f425bSmrg	 esac
7047698f425bSmrg	fi
70489ef0b394Smrg	func_append deplibs " $arg"
7049698f425bSmrg	continue
7050698f425bSmrg	;;
7051266e564dSmrg
7052a3129944Smrg      -mllvm)
7053a3129944Smrg	prev=mllvm
7054a3129944Smrg	continue
7055a3129944Smrg	;;
7056a3129944Smrg
7057698f425bSmrg      -module)
7058698f425bSmrg	module=yes
7059698f425bSmrg	continue
7060698f425bSmrg	;;
7061266e564dSmrg
7062698f425bSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7063698f425bSmrg      # classes, name mangling, and exception handling.
7064698f425bSmrg      # Darwin uses the -arch flag to determine output architecture.
70659ef0b394Smrg      -model|-arch|-isysroot|--sysroot)
70669ef0b394Smrg	func_append compiler_flags " $arg"
7067698f425bSmrg	func_append compile_command " $arg"
7068698f425bSmrg	func_append finalize_command " $arg"
7069698f425bSmrg	prev=xcompiler
7070698f425bSmrg	continue
7071698f425bSmrg	;;
7072266e564dSmrg
7073fb5e8d76Smrg      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7074fb5e8d76Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
70759ef0b394Smrg	func_append compiler_flags " $arg"
7076698f425bSmrg	func_append compile_command " $arg"
7077698f425bSmrg	func_append finalize_command " $arg"
7078698f425bSmrg	case "$new_inherited_linker_flags " in
7079698f425bSmrg	    *" $arg "*) ;;
70809ef0b394Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7081698f425bSmrg	esac
7082698f425bSmrg	continue
7083698f425bSmrg	;;
7084266e564dSmrg
7085698f425bSmrg      -multi_module)
7086a3129944Smrg	single_module=$wl-multi_module
7087698f425bSmrg	continue
7088698f425bSmrg	;;
7089266e564dSmrg
7090698f425bSmrg      -no-fast-install)
7091698f425bSmrg	fast_install=no
7092698f425bSmrg	continue
7093698f425bSmrg	;;
7094266e564dSmrg
7095698f425bSmrg      -no-install)
7096698f425bSmrg	case $host in
7097698f425bSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7098698f425bSmrg	  # The PATH hackery in wrapper scripts is required on Windows
7099698f425bSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7100a3129944Smrg	  func_warning "'-no-install' is ignored for $host"
7101a3129944Smrg	  func_warning "assuming '-no-fast-install' instead"
7102698f425bSmrg	  fast_install=no
7103698f425bSmrg	  ;;
7104698f425bSmrg	*) no_install=yes ;;
7105698f425bSmrg	esac
7106698f425bSmrg	continue
7107698f425bSmrg	;;
7108266e564dSmrg
7109698f425bSmrg      -no-undefined)
7110698f425bSmrg	allow_undefined=no
7111698f425bSmrg	continue
7112698f425bSmrg	;;
7113266e564dSmrg
7114698f425bSmrg      -objectlist)
7115698f425bSmrg	prev=objectlist
7116698f425bSmrg	continue
7117698f425bSmrg	;;
7118266e564dSmrg
7119a3129944Smrg      -os2dllname)
7120a3129944Smrg	prev=os2dllname
7121a3129944Smrg	continue
7122a3129944Smrg	;;
7123a3129944Smrg
7124698f425bSmrg      -o) prev=output ;;
7125266e564dSmrg
7126698f425bSmrg      -precious-files-regex)
7127698f425bSmrg	prev=precious_regex
7128698f425bSmrg	continue
7129698f425bSmrg	;;
7130266e564dSmrg
7131698f425bSmrg      -release)
7132698f425bSmrg	prev=release
7133698f425bSmrg	continue
7134698f425bSmrg	;;
7135266e564dSmrg
7136698f425bSmrg      -rpath)
7137698f425bSmrg	prev=rpath
7138698f425bSmrg	continue
7139698f425bSmrg	;;
7140266e564dSmrg
7141698f425bSmrg      -R)
7142698f425bSmrg	prev=xrpath
7143698f425bSmrg	continue
7144698f425bSmrg	;;
7145266e564dSmrg
7146698f425bSmrg      -R*)
7147698f425bSmrg	func_stripname '-R' '' "$arg"
7148698f425bSmrg	dir=$func_stripname_result
7149698f425bSmrg	# We need an absolute path.
7150698f425bSmrg	case $dir in
7151698f425bSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
71529ef0b394Smrg	=*)
71539ef0b394Smrg	  func_stripname '=' '' "$dir"
71549ef0b394Smrg	  dir=$lt_sysroot$func_stripname_result
71559ef0b394Smrg	  ;;
7156698f425bSmrg	*)
7157698f425bSmrg	  func_fatal_error "only absolute run-paths are allowed"
7158698f425bSmrg	  ;;
7159698f425bSmrg	esac
7160698f425bSmrg	case "$xrpath " in
7161698f425bSmrg	*" $dir "*) ;;
71629ef0b394Smrg	*) func_append xrpath " $dir" ;;
7163698f425bSmrg	esac
7164698f425bSmrg	continue
7165698f425bSmrg	;;
7166266e564dSmrg
7167698f425bSmrg      -shared)
7168698f425bSmrg	# The effects of -shared are defined in a previous loop.
7169698f425bSmrg	continue
7170698f425bSmrg	;;
7171266e564dSmrg
7172698f425bSmrg      -shrext)
7173698f425bSmrg	prev=shrext
7174698f425bSmrg	continue
7175698f425bSmrg	;;
7176266e564dSmrg
7177698f425bSmrg      -static | -static-libtool-libs)
7178698f425bSmrg	# The effects of -static are defined in a previous loop.
7179698f425bSmrg	# We used to do the same as -all-static on platforms that
7180698f425bSmrg	# didn't have a PIC flag, but the assumption that the effects
7181698f425bSmrg	# would be equivalent was wrong.  It would break on at least
7182698f425bSmrg	# Digital Unix and AIX.
7183698f425bSmrg	continue
7184698f425bSmrg	;;
7185266e564dSmrg
7186698f425bSmrg      -thread-safe)
7187698f425bSmrg	thread_safe=yes
7188698f425bSmrg	continue
7189698f425bSmrg	;;
7190266e564dSmrg
7191698f425bSmrg      -version-info)
7192698f425bSmrg	prev=vinfo
7193698f425bSmrg	continue
7194698f425bSmrg	;;
7195266e564dSmrg
7196698f425bSmrg      -version-number)
7197698f425bSmrg	prev=vinfo
7198698f425bSmrg	vinfo_number=yes
7199698f425bSmrg	continue
7200698f425bSmrg	;;
7201266e564dSmrg
7202698f425bSmrg      -weak)
7203698f425bSmrg        prev=weak
7204698f425bSmrg	continue
7205698f425bSmrg	;;
7206266e564dSmrg
7207698f425bSmrg      -Wc,*)
7208698f425bSmrg	func_stripname '-Wc,' '' "$arg"
7209698f425bSmrg	args=$func_stripname_result
7210698f425bSmrg	arg=
7211a3129944Smrg	save_ifs=$IFS; IFS=,
7212698f425bSmrg	for flag in $args; do
7213a3129944Smrg	  IFS=$save_ifs
7214698f425bSmrg          func_quote_for_eval "$flag"
72159ef0b394Smrg	  func_append arg " $func_quote_for_eval_result"
72169ef0b394Smrg	  func_append compiler_flags " $func_quote_for_eval_result"
7217698f425bSmrg	done
7218a3129944Smrg	IFS=$save_ifs
7219698f425bSmrg	func_stripname ' ' '' "$arg"
7220698f425bSmrg	arg=$func_stripname_result
7221698f425bSmrg	;;
7222266e564dSmrg
7223698f425bSmrg      -Wl,*)
7224698f425bSmrg	func_stripname '-Wl,' '' "$arg"
7225698f425bSmrg	args=$func_stripname_result
7226698f425bSmrg	arg=
7227a3129944Smrg	save_ifs=$IFS; IFS=,
7228698f425bSmrg	for flag in $args; do
7229a3129944Smrg	  IFS=$save_ifs
7230698f425bSmrg          func_quote_for_eval "$flag"
72319ef0b394Smrg	  func_append arg " $wl$func_quote_for_eval_result"
72329ef0b394Smrg	  func_append compiler_flags " $wl$func_quote_for_eval_result"
72339ef0b394Smrg	  func_append linker_flags " $func_quote_for_eval_result"
7234698f425bSmrg	done
7235a3129944Smrg	IFS=$save_ifs
7236698f425bSmrg	func_stripname ' ' '' "$arg"
7237698f425bSmrg	arg=$func_stripname_result
7238698f425bSmrg	;;
7239266e564dSmrg
7240698f425bSmrg      -Xcompiler)
7241698f425bSmrg	prev=xcompiler
7242698f425bSmrg	continue
7243698f425bSmrg	;;
7244266e564dSmrg
7245698f425bSmrg      -Xlinker)
7246698f425bSmrg	prev=xlinker
7247698f425bSmrg	continue
7248698f425bSmrg	;;
7249266e564dSmrg
7250698f425bSmrg      -XCClinker)
7251698f425bSmrg	prev=xcclinker
7252698f425bSmrg	continue
7253698f425bSmrg	;;
7254266e564dSmrg
7255698f425bSmrg      # -msg_* for osf cc
7256698f425bSmrg      -msg_*)
7257698f425bSmrg	func_quote_for_eval "$arg"
7258a3129944Smrg	arg=$func_quote_for_eval_result
7259698f425bSmrg	;;
7260266e564dSmrg
72619ef0b394Smrg      # Flags to be passed through unchanged, with rationale:
72629ef0b394Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
72639ef0b394Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
72649ef0b394Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
72659ef0b394Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
72669ef0b394Smrg      # -q*                  compiler args for the IBM compiler
72679ef0b394Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
72689ef0b394Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
72699ef0b394Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7270a3129944Smrg      # -fstack-protector*   stack protector flags for GCC
72719ef0b394Smrg      # @file                GCC response files
72729ef0b394Smrg      # -tp=*                Portland pgcc target processor selection
72739ef0b394Smrg      # --sysroot=*          for sysroot support
7274a3129944Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7275a3129944Smrg      # -stdlib=*            select c++ std lib with clang
7276698f425bSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
72779ef0b394Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7278a3129944Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*)
7279698f425bSmrg        func_quote_for_eval "$arg"
7280a3129944Smrg	arg=$func_quote_for_eval_result
7281698f425bSmrg        func_append compile_command " $arg"
7282698f425bSmrg        func_append finalize_command " $arg"
72839ef0b394Smrg        func_append compiler_flags " $arg"
7284698f425bSmrg        continue
7285698f425bSmrg        ;;
7286266e564dSmrg
7287a3129944Smrg      -Z*)
7288a3129944Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7289a3129944Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7290a3129944Smrg	  compiler_flags="$compiler_flags $arg"
7291a3129944Smrg	  func_append compile_command " $arg"
7292a3129944Smrg	  func_append finalize_command " $arg"
7293a3129944Smrg	  case $arg in
7294a3129944Smrg	  -Zlinker | -Zstack)
7295a3129944Smrg	    prev=xcompiler
7296a3129944Smrg	    ;;
7297a3129944Smrg	  esac
7298a3129944Smrg	  continue
7299a3129944Smrg        else
7300a3129944Smrg	  # Otherwise treat like 'Some other compiler flag' below
7301a3129944Smrg	  func_quote_for_eval "$arg"
7302a3129944Smrg	  arg=$func_quote_for_eval_result
7303a3129944Smrg        fi
7304a3129944Smrg	;;
7305a3129944Smrg
7306698f425bSmrg      # Some other compiler flag.
7307698f425bSmrg      -* | +*)
7308698f425bSmrg        func_quote_for_eval "$arg"
7309a3129944Smrg	arg=$func_quote_for_eval_result
7310698f425bSmrg	;;
7311266e564dSmrg
7312698f425bSmrg      *.$objext)
7313698f425bSmrg	# A standard object.
73149ef0b394Smrg	func_append objs " $arg"
7315698f425bSmrg	;;
7316266e564dSmrg
7317698f425bSmrg      *.lo)
7318698f425bSmrg	# A libtool-controlled object.
7319266e564dSmrg
7320698f425bSmrg	# Check to see that this really is a libtool object.
7321698f425bSmrg	if func_lalib_unsafe_p "$arg"; then
7322698f425bSmrg	  pic_object=
7323698f425bSmrg	  non_pic_object=
7324266e564dSmrg
7325698f425bSmrg	  # Read the .lo file
7326698f425bSmrg	  func_source "$arg"
7327266e564dSmrg
7328698f425bSmrg	  if test -z "$pic_object" ||
7329698f425bSmrg	     test -z "$non_pic_object" ||
7330a3129944Smrg	     test none = "$pic_object" &&
7331a3129944Smrg	     test none = "$non_pic_object"; then
7332a3129944Smrg	    func_fatal_error "cannot find name of object for '$arg'"
7333698f425bSmrg	  fi
7334c5629e66Smrg
7335698f425bSmrg	  # Extract subdirectory from the argument.
7336698f425bSmrg	  func_dirname "$arg" "/" ""
7337a3129944Smrg	  xdir=$func_dirname_result
7338266e564dSmrg
7339a3129944Smrg	  test none = "$pic_object" || {
7340698f425bSmrg	    # Prepend the subdirectory the object is found in.
7341a3129944Smrg	    pic_object=$xdir$pic_object
7342266e564dSmrg
7343a3129944Smrg	    if test dlfiles = "$prev"; then
7344a3129944Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
73459ef0b394Smrg		func_append dlfiles " $pic_object"
7346698f425bSmrg		prev=
7347698f425bSmrg		continue
7348698f425bSmrg	      else
7349698f425bSmrg		# If libtool objects are unsupported, then we need to preload.
7350698f425bSmrg		prev=dlprefiles
7351698f425bSmrg	      fi
7352698f425bSmrg	    fi
7353266e564dSmrg
7354698f425bSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7355a3129944Smrg	    if test dlprefiles = "$prev"; then
7356698f425bSmrg	      # Preload the old-style object.
73579ef0b394Smrg	      func_append dlprefiles " $pic_object"
7358698f425bSmrg	      prev=
7359698f425bSmrg	    fi
7360266e564dSmrg
7361698f425bSmrg	    # A PIC object.
7362698f425bSmrg	    func_append libobjs " $pic_object"
7363a3129944Smrg	    arg=$pic_object
7364a3129944Smrg	  }
7365266e564dSmrg
7366698f425bSmrg	  # Non-PIC object.
7367a3129944Smrg	  if test none != "$non_pic_object"; then
7368698f425bSmrg	    # Prepend the subdirectory the object is found in.
7369a3129944Smrg	    non_pic_object=$xdir$non_pic_object
7370266e564dSmrg
7371698f425bSmrg	    # A standard non-PIC object
7372698f425bSmrg	    func_append non_pic_objects " $non_pic_object"
7373a3129944Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7374a3129944Smrg	      arg=$non_pic_object
7375698f425bSmrg	    fi
7376698f425bSmrg	  else
7377698f425bSmrg	    # If the PIC object exists, use it instead.
7378698f425bSmrg	    # $xdir was prepended to $pic_object above.
7379a3129944Smrg	    non_pic_object=$pic_object
7380698f425bSmrg	    func_append non_pic_objects " $non_pic_object"
7381698f425bSmrg	  fi
7382698f425bSmrg	else
7383698f425bSmrg	  # Only an error if not doing a dry-run.
7384698f425bSmrg	  if $opt_dry_run; then
7385698f425bSmrg	    # Extract subdirectory from the argument.
7386698f425bSmrg	    func_dirname "$arg" "/" ""
7387a3129944Smrg	    xdir=$func_dirname_result
7388698f425bSmrg
7389698f425bSmrg	    func_lo2o "$arg"
7390698f425bSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
7391698f425bSmrg	    non_pic_object=$xdir$func_lo2o_result
7392698f425bSmrg	    func_append libobjs " $pic_object"
7393698f425bSmrg	    func_append non_pic_objects " $non_pic_object"
7394698f425bSmrg	  else
7395a3129944Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
7396698f425bSmrg	  fi
7397698f425bSmrg	fi
7398698f425bSmrg	;;
7399698f425bSmrg
7400698f425bSmrg      *.$libext)
7401698f425bSmrg	# An archive.
74029ef0b394Smrg	func_append deplibs " $arg"
74039ef0b394Smrg	func_append old_deplibs " $arg"
7404698f425bSmrg	continue
7405698f425bSmrg	;;
7406698f425bSmrg
7407698f425bSmrg      *.la)
7408698f425bSmrg	# A libtool-controlled library.
7409698f425bSmrg
74109ef0b394Smrg	func_resolve_sysroot "$arg"
7411a3129944Smrg	if test dlfiles = "$prev"; then
7412698f425bSmrg	  # This library was specified with -dlopen.
74139ef0b394Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
7414698f425bSmrg	  prev=
7415a3129944Smrg	elif test dlprefiles = "$prev"; then
7416698f425bSmrg	  # The library was specified with -dlpreopen.
74179ef0b394Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7418698f425bSmrg	  prev=
7419698f425bSmrg	else
74209ef0b394Smrg	  func_append deplibs " $func_resolve_sysroot_result"
7421698f425bSmrg	fi
7422698f425bSmrg	continue
7423698f425bSmrg	;;
7424698f425bSmrg
7425698f425bSmrg      # Some other compiler argument.
7426698f425bSmrg      *)
7427698f425bSmrg	# Unknown arguments in both finalize_command and compile_command need
7428698f425bSmrg	# to be aesthetically quoted because they are evaled later.
7429698f425bSmrg	func_quote_for_eval "$arg"
7430a3129944Smrg	arg=$func_quote_for_eval_result
7431698f425bSmrg	;;
7432698f425bSmrg      esac # arg
7433698f425bSmrg
7434698f425bSmrg      # Now actually substitute the argument into the commands.
7435698f425bSmrg      if test -n "$arg"; then
7436698f425bSmrg	func_append compile_command " $arg"
7437698f425bSmrg	func_append finalize_command " $arg"
7438698f425bSmrg      fi
7439698f425bSmrg    done # argument parsing loop
7440698f425bSmrg
7441698f425bSmrg    test -n "$prev" && \
7442a3129944Smrg      func_fatal_help "the '$prevarg' option requires an argument"
7443698f425bSmrg
7444a3129944Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7445698f425bSmrg      eval arg=\"$export_dynamic_flag_spec\"
7446698f425bSmrg      func_append compile_command " $arg"
7447698f425bSmrg      func_append finalize_command " $arg"
7448698f425bSmrg    fi
7449698f425bSmrg
7450698f425bSmrg    oldlibs=
7451698f425bSmrg    # calculate the name of the file, without its directory
7452698f425bSmrg    func_basename "$output"
7453a3129944Smrg    outputname=$func_basename_result
7454a3129944Smrg    libobjs_save=$libobjs
7455698f425bSmrg
7456698f425bSmrg    if test -n "$shlibpath_var"; then
7457698f425bSmrg      # get the directories listed in $shlibpath_var
7458a3129944Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7459698f425bSmrg    else
7460698f425bSmrg      shlib_search_path=
7461698f425bSmrg    fi
7462698f425bSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7463698f425bSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7464698f425bSmrg
7465a3129944Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7466a3129944Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7467a3129944Smrg
7468698f425bSmrg    func_dirname "$output" "/" ""
7469a3129944Smrg    output_objdir=$func_dirname_result$objdir
74709ef0b394Smrg    func_to_tool_file "$output_objdir/"
74719ef0b394Smrg    tool_output_objdir=$func_to_tool_file_result
7472698f425bSmrg    # Create the object directory.
7473698f425bSmrg    func_mkdir_p "$output_objdir"
7474698f425bSmrg
7475698f425bSmrg    # Determine the type of output
7476698f425bSmrg    case $output in
7477698f425bSmrg    "")
7478698f425bSmrg      func_fatal_help "you must specify an output file"
7479698f425bSmrg      ;;
7480698f425bSmrg    *.$libext) linkmode=oldlib ;;
7481698f425bSmrg    *.lo | *.$objext) linkmode=obj ;;
7482698f425bSmrg    *.la) linkmode=lib ;;
7483698f425bSmrg    *) linkmode=prog ;; # Anything else should be a program.
7484698f425bSmrg    esac
7485698f425bSmrg
7486698f425bSmrg    specialdeplibs=
7487698f425bSmrg
7488698f425bSmrg    libs=
7489698f425bSmrg    # Find all interdependent deplibs by searching for libraries
7490698f425bSmrg    # that are linked more than once (e.g. -la -lb -la)
7491698f425bSmrg    for deplib in $deplibs; do
7492a3129944Smrg      if $opt_preserve_dup_deps; then
7493698f425bSmrg	case "$libs " in
74949ef0b394Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7495698f425bSmrg	esac
7496698f425bSmrg      fi
74979ef0b394Smrg      func_append libs " $deplib"
7498698f425bSmrg    done
7499698f425bSmrg
7500a3129944Smrg    if test lib = "$linkmode"; then
7501698f425bSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7502698f425bSmrg
7503698f425bSmrg      # Compute libraries that are listed more than once in $predeps
7504698f425bSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
7505698f425bSmrg      # not to be eliminated).
7506698f425bSmrg      pre_post_deps=
7507698f425bSmrg      if $opt_duplicate_compiler_generated_deps; then
7508698f425bSmrg	for pre_post_dep in $predeps $postdeps; do
7509698f425bSmrg	  case "$pre_post_deps " in
75109ef0b394Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7511698f425bSmrg	  esac
75129ef0b394Smrg	  func_append pre_post_deps " $pre_post_dep"
7513698f425bSmrg	done
7514698f425bSmrg      fi
7515698f425bSmrg      pre_post_deps=
7516698f425bSmrg    fi
7517698f425bSmrg
7518698f425bSmrg    deplibs=
7519698f425bSmrg    newdependency_libs=
7520698f425bSmrg    newlib_search_path=
7521698f425bSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7522698f425bSmrg    notinst_deplibs= # not-installed libtool libraries
7523698f425bSmrg    notinst_path= # paths that contain not-installed libtool libraries
7524698f425bSmrg
7525698f425bSmrg    case $linkmode in
7526698f425bSmrg    lib)
7527698f425bSmrg	passes="conv dlpreopen link"
7528698f425bSmrg	for file in $dlfiles $dlprefiles; do
7529698f425bSmrg	  case $file in
7530698f425bSmrg	  *.la) ;;
7531698f425bSmrg	  *)
7532a3129944Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7533698f425bSmrg	    ;;
7534698f425bSmrg	  esac
7535698f425bSmrg	done
7536698f425bSmrg	;;
7537698f425bSmrg    prog)
7538698f425bSmrg	compile_deplibs=
7539698f425bSmrg	finalize_deplibs=
7540a3129944Smrg	alldeplibs=false
7541698f425bSmrg	newdlfiles=
7542698f425bSmrg	newdlprefiles=
7543698f425bSmrg	passes="conv scan dlopen dlpreopen link"
7544698f425bSmrg	;;
7545698f425bSmrg    *)  passes="conv"
7546698f425bSmrg	;;
7547698f425bSmrg    esac
7548698f425bSmrg
7549698f425bSmrg    for pass in $passes; do
7550698f425bSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7551698f425bSmrg      # so that -L comes before libs that need it for instance...
7552a3129944Smrg      if test lib,link = "$linkmode,$pass"; then
7553698f425bSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
7554698f425bSmrg	##        order, and fix it there properly
7555698f425bSmrg        tmp_deplibs=
7556698f425bSmrg	for deplib in $deplibs; do
7557698f425bSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
7558698f425bSmrg	done
7559a3129944Smrg	deplibs=$tmp_deplibs
7560698f425bSmrg      fi
7561698f425bSmrg
7562a3129944Smrg      if test lib,link = "$linkmode,$pass" ||
7563a3129944Smrg	 test prog,scan = "$linkmode,$pass"; then
7564a3129944Smrg	libs=$deplibs
7565698f425bSmrg	deplibs=
7566698f425bSmrg      fi
7567a3129944Smrg      if test prog = "$linkmode"; then
7568698f425bSmrg	case $pass in
7569a3129944Smrg	dlopen) libs=$dlfiles ;;
7570a3129944Smrg	dlpreopen) libs=$dlprefiles ;;
7571698f425bSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7572698f425bSmrg	esac
7573698f425bSmrg      fi
7574a3129944Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7575698f425bSmrg	# Collect and forward deplibs of preopened libtool libs
7576698f425bSmrg	for lib in $dlprefiles; do
7577698f425bSmrg	  # Ignore non-libtool-libs
7578698f425bSmrg	  dependency_libs=
75799ef0b394Smrg	  func_resolve_sysroot "$lib"
7580698f425bSmrg	  case $lib in
75819ef0b394Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7582698f425bSmrg	  esac
7583698f425bSmrg
7584698f425bSmrg	  # Collect preopened libtool deplibs, except any this library
7585698f425bSmrg	  # has declared as weak libs
7586698f425bSmrg	  for deplib in $dependency_libs; do
75879ef0b394Smrg	    func_basename "$deplib"
75889ef0b394Smrg            deplib_base=$func_basename_result
7589698f425bSmrg	    case " $weak_libs " in
7590698f425bSmrg	    *" $deplib_base "*) ;;
75919ef0b394Smrg	    *) func_append deplibs " $deplib" ;;
7592698f425bSmrg	    esac
7593698f425bSmrg	  done
7594698f425bSmrg	done
7595a3129944Smrg	libs=$dlprefiles
7596698f425bSmrg      fi
7597a3129944Smrg      if test dlopen = "$pass"; then
7598698f425bSmrg	# Collect dlpreopened libraries
7599a3129944Smrg	save_deplibs=$deplibs
7600698f425bSmrg	deplibs=
7601698f425bSmrg      fi
7602698f425bSmrg
7603698f425bSmrg      for deplib in $libs; do
7604698f425bSmrg	lib=
7605a3129944Smrg	found=false
7606698f425bSmrg	case $deplib in
7607fb5e8d76Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7608fb5e8d76Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7609a3129944Smrg	  if test prog,link = "$linkmode,$pass"; then
7610698f425bSmrg	    compile_deplibs="$deplib $compile_deplibs"
7611698f425bSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
7612698f425bSmrg	  else
76139ef0b394Smrg	    func_append compiler_flags " $deplib"
7614a3129944Smrg	    if test lib = "$linkmode"; then
7615698f425bSmrg		case "$new_inherited_linker_flags " in
7616698f425bSmrg		    *" $deplib "*) ;;
76179ef0b394Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7618698f425bSmrg		esac
7619698f425bSmrg	    fi
7620698f425bSmrg	  fi
7621698f425bSmrg	  continue
7622698f425bSmrg	  ;;
7623698f425bSmrg	-l*)
7624a3129944Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7625a3129944Smrg	    func_warning "'-l' is ignored for archives/objects"
7626698f425bSmrg	    continue
7627698f425bSmrg	  fi
7628698f425bSmrg	  func_stripname '-l' '' "$deplib"
7629698f425bSmrg	  name=$func_stripname_result
7630a3129944Smrg	  if test lib = "$linkmode"; then
7631698f425bSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7632698f425bSmrg	  else
7633698f425bSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7634698f425bSmrg	  fi
7635698f425bSmrg	  for searchdir in $searchdirs; do
7636698f425bSmrg	    for search_ext in .la $std_shrext .so .a; do
7637698f425bSmrg	      # Search the libtool library
7638a3129944Smrg	      lib=$searchdir/lib$name$search_ext
7639698f425bSmrg	      if test -f "$lib"; then
7640a3129944Smrg		if test .la = "$search_ext"; then
7641a3129944Smrg		  found=:
7642698f425bSmrg		else
7643a3129944Smrg		  found=false
7644698f425bSmrg		fi
7645698f425bSmrg		break 2
7646698f425bSmrg	      fi
7647698f425bSmrg	    done
7648698f425bSmrg	  done
7649a3129944Smrg	  if $found; then
7650a3129944Smrg	    # deplib is a libtool library
7651698f425bSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7652698f425bSmrg	    # We need to do some special things here, and not later.
7653a3129944Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7654698f425bSmrg	      case " $predeps $postdeps " in
7655698f425bSmrg	      *" $deplib "*)
7656698f425bSmrg		if func_lalib_p "$lib"; then
7657698f425bSmrg		  library_names=
7658698f425bSmrg		  old_library=
7659698f425bSmrg		  func_source "$lib"
7660698f425bSmrg		  for l in $old_library $library_names; do
7661a3129944Smrg		    ll=$l
7662698f425bSmrg		  done
7663a3129944Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7664a3129944Smrg		    found=false
7665698f425bSmrg		    func_dirname "$lib" "" "."
7666a3129944Smrg		    ladir=$func_dirname_result
7667698f425bSmrg		    lib=$ladir/$old_library
7668a3129944Smrg		    if test prog,link = "$linkmode,$pass"; then
7669698f425bSmrg		      compile_deplibs="$deplib $compile_deplibs"
7670698f425bSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
7671698f425bSmrg		    else
7672698f425bSmrg		      deplibs="$deplib $deplibs"
7673a3129944Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7674698f425bSmrg		    fi
7675698f425bSmrg		    continue
7676698f425bSmrg		  fi
7677698f425bSmrg		fi
7678698f425bSmrg		;;
7679698f425bSmrg	      *) ;;
7680698f425bSmrg	      esac
7681698f425bSmrg	    fi
7682a3129944Smrg	  else
7683a3129944Smrg	    # deplib doesn't seem to be a libtool library
7684a3129944Smrg	    if test prog,link = "$linkmode,$pass"; then
7685a3129944Smrg	      compile_deplibs="$deplib $compile_deplibs"
7686a3129944Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7687a3129944Smrg	    else
7688a3129944Smrg	      deplibs="$deplib $deplibs"
7689a3129944Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7690a3129944Smrg	    fi
7691a3129944Smrg	    continue
7692698f425bSmrg	  fi
7693698f425bSmrg	  ;; # -l
7694698f425bSmrg	*.ltframework)
7695a3129944Smrg	  if test prog,link = "$linkmode,$pass"; then
7696698f425bSmrg	    compile_deplibs="$deplib $compile_deplibs"
7697698f425bSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
7698698f425bSmrg	  else
7699698f425bSmrg	    deplibs="$deplib $deplibs"
7700a3129944Smrg	    if test lib = "$linkmode"; then
7701698f425bSmrg		case "$new_inherited_linker_flags " in
7702698f425bSmrg		    *" $deplib "*) ;;
77039ef0b394Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7704698f425bSmrg		esac
7705698f425bSmrg	    fi
7706698f425bSmrg	  fi
7707698f425bSmrg	  continue
7708698f425bSmrg	  ;;
7709698f425bSmrg	-L*)
7710698f425bSmrg	  case $linkmode in
7711698f425bSmrg	  lib)
7712698f425bSmrg	    deplibs="$deplib $deplibs"
7713a3129944Smrg	    test conv = "$pass" && continue
7714698f425bSmrg	    newdependency_libs="$deplib $newdependency_libs"
7715698f425bSmrg	    func_stripname '-L' '' "$deplib"
77169ef0b394Smrg	    func_resolve_sysroot "$func_stripname_result"
77179ef0b394Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
7718698f425bSmrg	    ;;
7719698f425bSmrg	  prog)
7720a3129944Smrg	    if test conv = "$pass"; then
7721698f425bSmrg	      deplibs="$deplib $deplibs"
7722698f425bSmrg	      continue
7723698f425bSmrg	    fi
7724a3129944Smrg	    if test scan = "$pass"; then
7725698f425bSmrg	      deplibs="$deplib $deplibs"
7726698f425bSmrg	    else
7727698f425bSmrg	      compile_deplibs="$deplib $compile_deplibs"
7728698f425bSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7729698f425bSmrg	    fi
7730698f425bSmrg	    func_stripname '-L' '' "$deplib"
77319ef0b394Smrg	    func_resolve_sysroot "$func_stripname_result"
77329ef0b394Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
7733698f425bSmrg	    ;;
7734698f425bSmrg	  *)
7735a3129944Smrg	    func_warning "'-L' is ignored for archives/objects"
7736698f425bSmrg	    ;;
7737698f425bSmrg	  esac # linkmode
7738698f425bSmrg	  continue
7739698f425bSmrg	  ;; # -L
7740698f425bSmrg	-R*)
7741a3129944Smrg	  if test link = "$pass"; then
7742698f425bSmrg	    func_stripname '-R' '' "$deplib"
77439ef0b394Smrg	    func_resolve_sysroot "$func_stripname_result"
77449ef0b394Smrg	    dir=$func_resolve_sysroot_result
7745698f425bSmrg	    # Make sure the xrpath contains only unique directories.
7746698f425bSmrg	    case "$xrpath " in
7747698f425bSmrg	    *" $dir "*) ;;
77489ef0b394Smrg	    *) func_append xrpath " $dir" ;;
7749698f425bSmrg	    esac
7750698f425bSmrg	  fi
7751698f425bSmrg	  deplibs="$deplib $deplibs"
7752698f425bSmrg	  continue
7753698f425bSmrg	  ;;
77549ef0b394Smrg	*.la)
77559ef0b394Smrg	  func_resolve_sysroot "$deplib"
77569ef0b394Smrg	  lib=$func_resolve_sysroot_result
77579ef0b394Smrg	  ;;
7758698f425bSmrg	*.$libext)
7759a3129944Smrg	  if test conv = "$pass"; then
7760698f425bSmrg	    deplibs="$deplib $deplibs"
7761698f425bSmrg	    continue
7762698f425bSmrg	  fi
7763698f425bSmrg	  case $linkmode in
7764698f425bSmrg	  lib)
7765698f425bSmrg	    # Linking convenience modules into shared libraries is allowed,
7766698f425bSmrg	    # but linking other static libraries is non-portable.
7767698f425bSmrg	    case " $dlpreconveniencelibs " in
7768698f425bSmrg	    *" $deplib "*) ;;
7769698f425bSmrg	    *)
7770a3129944Smrg	      valid_a_lib=false
7771698f425bSmrg	      case $deplibs_check_method in
7772698f425bSmrg		match_pattern*)
7773698f425bSmrg		  set dummy $deplibs_check_method; shift
7774698f425bSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
77759ef0b394Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
7776698f425bSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
7777a3129944Smrg		    valid_a_lib=:
7778698f425bSmrg		  fi
7779698f425bSmrg		;;
7780698f425bSmrg		pass_all)
7781a3129944Smrg		  valid_a_lib=:
7782698f425bSmrg		;;
7783698f425bSmrg	      esac
7784a3129944Smrg	      if $valid_a_lib; then
7785a3129944Smrg		echo
7786a3129944Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
7787a3129944Smrg		$ECHO "*** static library $deplib is not portable!"
7788a3129944Smrg		deplibs="$deplib $deplibs"
7789a3129944Smrg	      else
77909ef0b394Smrg		echo
7791698f425bSmrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
77929ef0b394Smrg		echo "*** I have the capability to make that library automatically link in when"
77939ef0b394Smrg		echo "*** you link to this library.  But I can only do this if you have a"
77949ef0b394Smrg		echo "*** shared version of the library, which you do not appear to have"
77959ef0b394Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
77969ef0b394Smrg		echo "*** that it is just a static archive that I should not use here."
7797698f425bSmrg	      fi
7798698f425bSmrg	      ;;
7799698f425bSmrg	    esac
7800698f425bSmrg	    continue
7801698f425bSmrg	    ;;
7802698f425bSmrg	  prog)
7803a3129944Smrg	    if test link != "$pass"; then
7804698f425bSmrg	      deplibs="$deplib $deplibs"
7805698f425bSmrg	    else
7806698f425bSmrg	      compile_deplibs="$deplib $compile_deplibs"
7807698f425bSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7808698f425bSmrg	    fi
7809698f425bSmrg	    continue
7810698f425bSmrg	    ;;
7811698f425bSmrg	  esac # linkmode
7812698f425bSmrg	  ;; # *.$libext
7813698f425bSmrg	*.lo | *.$objext)
7814a3129944Smrg	  if test conv = "$pass"; then
7815698f425bSmrg	    deplibs="$deplib $deplibs"
7816a3129944Smrg	  elif test prog = "$linkmode"; then
7817a3129944Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
7818698f425bSmrg	      # If there is no dlopen support or we're linking statically,
7819698f425bSmrg	      # we need to preload.
78209ef0b394Smrg	      func_append newdlprefiles " $deplib"
7821698f425bSmrg	      compile_deplibs="$deplib $compile_deplibs"
7822698f425bSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7823698f425bSmrg	    else
78249ef0b394Smrg	      func_append newdlfiles " $deplib"
7825698f425bSmrg	    fi
7826698f425bSmrg	  fi
7827698f425bSmrg	  continue
7828698f425bSmrg	  ;;
7829698f425bSmrg	%DEPLIBS%)
7830a3129944Smrg	  alldeplibs=:
7831698f425bSmrg	  continue
7832698f425bSmrg	  ;;
7833698f425bSmrg	esac # case $deplib
7834698f425bSmrg
7835a3129944Smrg	$found || test -f "$lib" \
7836a3129944Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
7837698f425bSmrg
7838698f425bSmrg	# Check to see that this really is a libtool archive.
7839698f425bSmrg	func_lalib_unsafe_p "$lib" \
7840a3129944Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
7841698f425bSmrg
7842698f425bSmrg	func_dirname "$lib" "" "."
7843a3129944Smrg	ladir=$func_dirname_result
7844698f425bSmrg
7845698f425bSmrg	dlname=
7846698f425bSmrg	dlopen=
7847698f425bSmrg	dlpreopen=
7848698f425bSmrg	libdir=
7849698f425bSmrg	library_names=
7850698f425bSmrg	old_library=
7851698f425bSmrg	inherited_linker_flags=
7852698f425bSmrg	# If the library was installed with an old release of libtool,
7853698f425bSmrg	# it will not redefine variables installed, or shouldnotlink
7854698f425bSmrg	installed=yes
7855698f425bSmrg	shouldnotlink=no
7856698f425bSmrg	avoidtemprpath=
7857698f425bSmrg
7858698f425bSmrg
7859698f425bSmrg	# Read the .la file
7860698f425bSmrg	func_source "$lib"
7861698f425bSmrg
7862698f425bSmrg	# Convert "-framework foo" to "foo.ltframework"
7863698f425bSmrg	if test -n "$inherited_linker_flags"; then
78649ef0b394Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
7865698f425bSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
7866698f425bSmrg	    case " $new_inherited_linker_flags " in
7867698f425bSmrg	      *" $tmp_inherited_linker_flag "*) ;;
78689ef0b394Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
7869698f425bSmrg	    esac
7870698f425bSmrg	  done
7871698f425bSmrg	fi
78729ef0b394Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
7873a3129944Smrg	if test lib,link = "$linkmode,$pass" ||
7874a3129944Smrg	   test prog,scan = "$linkmode,$pass" ||
7875a3129944Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
78769ef0b394Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
78779ef0b394Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
7878698f425bSmrg	fi
7879698f425bSmrg
7880a3129944Smrg	if test conv = "$pass"; then
7881698f425bSmrg	  # Only check for convenience libraries
7882698f425bSmrg	  deplibs="$lib $deplibs"
7883698f425bSmrg	  if test -z "$libdir"; then
7884698f425bSmrg	    if test -z "$old_library"; then
7885a3129944Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
7886698f425bSmrg	    fi
7887698f425bSmrg	    # It is a libtool convenience library, so add in its objects.
78889ef0b394Smrg	    func_append convenience " $ladir/$objdir/$old_library"
78899ef0b394Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
7890a3129944Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
7891a3129944Smrg	    func_fatal_error "'$lib' is not a convenience library"
7892698f425bSmrg	  fi
7893698f425bSmrg	  tmp_libs=
7894698f425bSmrg	  for deplib in $dependency_libs; do
7895698f425bSmrg	    deplibs="$deplib $deplibs"
7896a3129944Smrg	    if $opt_preserve_dup_deps; then
7897698f425bSmrg	      case "$tmp_libs " in
78989ef0b394Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
7899698f425bSmrg	      esac
7900698f425bSmrg	    fi
79019ef0b394Smrg	    func_append tmp_libs " $deplib"
7902698f425bSmrg	  done
7903698f425bSmrg	  continue
7904698f425bSmrg	fi # $pass = conv
7905698f425bSmrg
7906698f425bSmrg
7907698f425bSmrg	# Get the name of the library we link against.
7908698f425bSmrg	linklib=
79099ef0b394Smrg	if test -n "$old_library" &&
7910a3129944Smrg	   { test yes = "$prefer_static_libs" ||
7911a3129944Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
79129ef0b394Smrg	  linklib=$old_library
79139ef0b394Smrg	else
79149ef0b394Smrg	  for l in $old_library $library_names; do
7915a3129944Smrg	    linklib=$l
79169ef0b394Smrg	  done
79179ef0b394Smrg	fi
7918698f425bSmrg	if test -z "$linklib"; then
7919a3129944Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
7920698f425bSmrg	fi
7921698f425bSmrg
7922698f425bSmrg	# This library was specified with -dlopen.
7923a3129944Smrg	if test dlopen = "$pass"; then
7924a3129944Smrg	  test -z "$libdir" \
7925a3129944Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
7926698f425bSmrg	  if test -z "$dlname" ||
7927a3129944Smrg	     test yes != "$dlopen_support" ||
7928a3129944Smrg	     test no = "$build_libtool_libs"
7929a3129944Smrg	  then
7930698f425bSmrg	    # If there is no dlname, no dlopen support or we're linking
7931698f425bSmrg	    # statically, we need to preload.  We also need to preload any
7932698f425bSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
7933698f425bSmrg	    # bomb out in the load deplibs phase.
79349ef0b394Smrg	    func_append dlprefiles " $lib $dependency_libs"
7935698f425bSmrg	  else
79369ef0b394Smrg	    func_append newdlfiles " $lib"
7937698f425bSmrg	  fi
7938698f425bSmrg	  continue
7939698f425bSmrg	fi # $pass = dlopen
7940698f425bSmrg
7941698f425bSmrg	# We need an absolute path.
7942698f425bSmrg	case $ladir in
7943a3129944Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
7944698f425bSmrg	*)
7945698f425bSmrg	  abs_ladir=`cd "$ladir" && pwd`
7946698f425bSmrg	  if test -z "$abs_ladir"; then
7947a3129944Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
7948698f425bSmrg	    func_warning "passing it literally to the linker, although it might fail"
7949a3129944Smrg	    abs_ladir=$ladir
7950698f425bSmrg	  fi
7951698f425bSmrg	  ;;
7952698f425bSmrg	esac
7953698f425bSmrg	func_basename "$lib"
7954a3129944Smrg	laname=$func_basename_result
7955698f425bSmrg
7956698f425bSmrg	# Find the relevant object directory and library name.
7957a3129944Smrg	if test yes = "$installed"; then
79589ef0b394Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7959a3129944Smrg	    func_warning "library '$lib' was moved."
7960a3129944Smrg	    dir=$ladir
7961a3129944Smrg	    absdir=$abs_ladir
7962a3129944Smrg	    libdir=$abs_ladir
7963698f425bSmrg	  else
7964a3129944Smrg	    dir=$lt_sysroot$libdir
7965a3129944Smrg	    absdir=$lt_sysroot$libdir
7966698f425bSmrg	  fi
7967a3129944Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
7968698f425bSmrg	else
7969698f425bSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7970a3129944Smrg	    dir=$ladir
7971a3129944Smrg	    absdir=$abs_ladir
7972698f425bSmrg	    # Remove this search path later
79739ef0b394Smrg	    func_append notinst_path " $abs_ladir"
7974698f425bSmrg	  else
7975a3129944Smrg	    dir=$ladir/$objdir
7976a3129944Smrg	    absdir=$abs_ladir/$objdir
7977698f425bSmrg	    # Remove this search path later
79789ef0b394Smrg	    func_append notinst_path " $abs_ladir"
7979698f425bSmrg	  fi
7980698f425bSmrg	fi # $installed = yes
7981698f425bSmrg	func_stripname 'lib' '.la' "$laname"
7982698f425bSmrg	name=$func_stripname_result
7983698f425bSmrg
7984698f425bSmrg	# This library was specified with -dlpreopen.
7985a3129944Smrg	if test dlpreopen = "$pass"; then
7986a3129944Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
7987a3129944Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
7988698f425bSmrg	  fi
7989a3129944Smrg	  case $host in
79909ef0b394Smrg	    # special handling for platforms with PE-DLLs.
79919ef0b394Smrg	    *cygwin* | *mingw* | *cegcc* )
79929ef0b394Smrg	      # Linker will automatically link against shared library if both
79939ef0b394Smrg	      # static and shared are present.  Therefore, ensure we extract
79949ef0b394Smrg	      # symbols from the import library if a shared library is present
79959ef0b394Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
79969ef0b394Smrg	      # this by putting the import library name into $newdlprefiles.
79979ef0b394Smrg	      # We recover the dlopen module name by 'saving' the la file
79989ef0b394Smrg	      # name in a special purpose variable, and (later) extracting the
79999ef0b394Smrg	      # dlname from the la file.
80009ef0b394Smrg	      if test -n "$dlname"; then
80019ef0b394Smrg	        func_tr_sh "$dir/$linklib"
80029ef0b394Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
80039ef0b394Smrg	        func_append newdlprefiles " $dir/$linklib"
80049ef0b394Smrg	      else
80059ef0b394Smrg	        func_append newdlprefiles " $dir/$old_library"
80069ef0b394Smrg	        # Keep a list of preopened convenience libraries to check
80079ef0b394Smrg	        # that they are being used correctly in the link pass.
80089ef0b394Smrg	        test -z "$libdir" && \
80099ef0b394Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
80109ef0b394Smrg	      fi
80119ef0b394Smrg	    ;;
80129ef0b394Smrg	    * )
80139ef0b394Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
80149ef0b394Smrg	      # are required to link).
80159ef0b394Smrg	      if test -n "$old_library"; then
80169ef0b394Smrg	        func_append newdlprefiles " $dir/$old_library"
80179ef0b394Smrg	        # Keep a list of preopened convenience libraries to check
80189ef0b394Smrg	        # that they are being used correctly in the link pass.
80199ef0b394Smrg	        test -z "$libdir" && \
80209ef0b394Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
80219ef0b394Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
80229ef0b394Smrg	      elif test -n "$dlname"; then
80239ef0b394Smrg	        func_append newdlprefiles " $dir/$dlname"
80249ef0b394Smrg	      else
80259ef0b394Smrg	        func_append newdlprefiles " $dir/$linklib"
80269ef0b394Smrg	      fi
80279ef0b394Smrg	    ;;
80289ef0b394Smrg	  esac
8029698f425bSmrg	fi # $pass = dlpreopen
8030698f425bSmrg
8031698f425bSmrg	if test -z "$libdir"; then
8032698f425bSmrg	  # Link the convenience library
8033a3129944Smrg	  if test lib = "$linkmode"; then
8034698f425bSmrg	    deplibs="$dir/$old_library $deplibs"
8035a3129944Smrg	  elif test prog,link = "$linkmode,$pass"; then
8036698f425bSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8037698f425bSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8038698f425bSmrg	  else
8039698f425bSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8040698f425bSmrg	  fi
8041698f425bSmrg	  continue
8042698f425bSmrg	fi
8043698f425bSmrg
8044698f425bSmrg
8045a3129944Smrg	if test prog = "$linkmode" && test link != "$pass"; then
80469ef0b394Smrg	  func_append newlib_search_path " $ladir"
8047698f425bSmrg	  deplibs="$lib $deplibs"
8048698f425bSmrg
8049a3129944Smrg	  linkalldeplibs=false
8050a3129944Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8051a3129944Smrg	     test no = "$build_libtool_libs"; then
8052a3129944Smrg	    linkalldeplibs=:
8053698f425bSmrg	  fi
8054698f425bSmrg
8055698f425bSmrg	  tmp_libs=
8056698f425bSmrg	  for deplib in $dependency_libs; do
8057698f425bSmrg	    case $deplib in
8058698f425bSmrg	    -L*) func_stripname '-L' '' "$deplib"
80599ef0b394Smrg	         func_resolve_sysroot "$func_stripname_result"
80609ef0b394Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8061698f425bSmrg		 ;;
8062698f425bSmrg	    esac
8063698f425bSmrg	    # Need to link against all dependency_libs?
8064a3129944Smrg	    if $linkalldeplibs; then
8065698f425bSmrg	      deplibs="$deplib $deplibs"
8066698f425bSmrg	    else
8067698f425bSmrg	      # Need to hardcode shared library paths
8068698f425bSmrg	      # or/and link against static libraries
8069698f425bSmrg	      newdependency_libs="$deplib $newdependency_libs"
8070698f425bSmrg	    fi
8071a3129944Smrg	    if $opt_preserve_dup_deps; then
8072698f425bSmrg	      case "$tmp_libs " in
80739ef0b394Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8074698f425bSmrg	      esac
8075698f425bSmrg	    fi
80769ef0b394Smrg	    func_append tmp_libs " $deplib"
8077698f425bSmrg	  done # for deplib
8078698f425bSmrg	  continue
8079698f425bSmrg	fi # $linkmode = prog...
8080698f425bSmrg
8081a3129944Smrg	if test prog,link = "$linkmode,$pass"; then
8082698f425bSmrg	  if test -n "$library_names" &&
8083a3129944Smrg	     { { test no = "$prefer_static_libs" ||
8084a3129944Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8085698f425bSmrg	       test -z "$old_library"; }; then
8086698f425bSmrg	    # We need to hardcode the library path
8087a3129944Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8088698f425bSmrg	      # Make sure the rpath contains only unique directories.
8089a3129944Smrg	      case $temp_rpath: in
8090698f425bSmrg	      *"$absdir:"*) ;;
80919ef0b394Smrg	      *) func_append temp_rpath "$absdir:" ;;
8092698f425bSmrg	      esac
8093698f425bSmrg	    fi
8094698f425bSmrg
8095698f425bSmrg	    # Hardcode the library path.
8096698f425bSmrg	    # Skip directories that are in the system default run-time
8097698f425bSmrg	    # search path.
8098698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8099698f425bSmrg	    *" $absdir "*) ;;
8100698f425bSmrg	    *)
8101698f425bSmrg	      case "$compile_rpath " in
8102698f425bSmrg	      *" $absdir "*) ;;
81039ef0b394Smrg	      *) func_append compile_rpath " $absdir" ;;
8104698f425bSmrg	      esac
8105698f425bSmrg	      ;;
8106698f425bSmrg	    esac
8107698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8108698f425bSmrg	    *" $libdir "*) ;;
8109698f425bSmrg	    *)
8110698f425bSmrg	      case "$finalize_rpath " in
8111698f425bSmrg	      *" $libdir "*) ;;
81129ef0b394Smrg	      *) func_append finalize_rpath " $libdir" ;;
8113698f425bSmrg	      esac
8114698f425bSmrg	      ;;
8115698f425bSmrg	    esac
8116698f425bSmrg	  fi # $linkmode,$pass = prog,link...
8117698f425bSmrg
8118a3129944Smrg	  if $alldeplibs &&
8119a3129944Smrg	     { test pass_all = "$deplibs_check_method" ||
8120a3129944Smrg	       { test yes = "$build_libtool_libs" &&
8121698f425bSmrg		 test -n "$library_names"; }; }; then
8122698f425bSmrg	    # We only need to search for static libraries
8123698f425bSmrg	    continue
8124698f425bSmrg	  fi
8125698f425bSmrg	fi
8126698f425bSmrg
8127698f425bSmrg	link_static=no # Whether the deplib will be linked statically
8128698f425bSmrg	use_static_libs=$prefer_static_libs
8129a3129944Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8130698f425bSmrg	  use_static_libs=no
8131698f425bSmrg	fi
8132698f425bSmrg	if test -n "$library_names" &&
8133a3129944Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8134698f425bSmrg	  case $host in
8135a3129944Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8136698f425bSmrg	      # No point in relinking DLLs because paths are not encoded
81379ef0b394Smrg	      func_append notinst_deplibs " $lib"
8138698f425bSmrg	      need_relink=no
8139698f425bSmrg	    ;;
8140698f425bSmrg	  *)
8141a3129944Smrg	    if test no = "$installed"; then
81429ef0b394Smrg	      func_append notinst_deplibs " $lib"
8143698f425bSmrg	      need_relink=yes
8144698f425bSmrg	    fi
8145698f425bSmrg	    ;;
8146698f425bSmrg	  esac
8147698f425bSmrg	  # This is a shared library
8148698f425bSmrg
8149698f425bSmrg	  # Warn about portability, can't link against -module's on some
8150698f425bSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8151a3129944Smrg	  dlopenmodule=
8152698f425bSmrg	  for dlpremoduletest in $dlprefiles; do
8153698f425bSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8154a3129944Smrg	      dlopenmodule=$dlpremoduletest
8155698f425bSmrg	      break
8156698f425bSmrg	    fi
8157698f425bSmrg	  done
8158a3129944Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
81599ef0b394Smrg	    echo
8160a3129944Smrg	    if test prog = "$linkmode"; then
8161698f425bSmrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8162698f425bSmrg	    else
8163698f425bSmrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8164698f425bSmrg	    fi
8165698f425bSmrg	    $ECHO "*** $linklib is not portable!"
8166698f425bSmrg	  fi
8167a3129944Smrg	  if test lib = "$linkmode" &&
8168a3129944Smrg	     test yes = "$hardcode_into_libs"; then
8169698f425bSmrg	    # Hardcode the library path.
8170698f425bSmrg	    # Skip directories that are in the system default run-time
8171698f425bSmrg	    # search path.
8172698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8173698f425bSmrg	    *" $absdir "*) ;;
8174698f425bSmrg	    *)
8175698f425bSmrg	      case "$compile_rpath " in
8176698f425bSmrg	      *" $absdir "*) ;;
81779ef0b394Smrg	      *) func_append compile_rpath " $absdir" ;;
8178698f425bSmrg	      esac
8179698f425bSmrg	      ;;
8180698f425bSmrg	    esac
8181698f425bSmrg	    case " $sys_lib_dlsearch_path " in
8182698f425bSmrg	    *" $libdir "*) ;;
8183698f425bSmrg	    *)
8184698f425bSmrg	      case "$finalize_rpath " in
8185698f425bSmrg	      *" $libdir "*) ;;
81869ef0b394Smrg	      *) func_append finalize_rpath " $libdir" ;;
8187698f425bSmrg	      esac
8188698f425bSmrg	      ;;
8189698f425bSmrg	    esac
8190698f425bSmrg	  fi
8191698f425bSmrg
8192698f425bSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8193698f425bSmrg	    # figure out the soname
8194698f425bSmrg	    set dummy $library_names
8195698f425bSmrg	    shift
8196a3129944Smrg	    realname=$1
8197698f425bSmrg	    shift
8198698f425bSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8199698f425bSmrg	    # use dlname if we got it. it's perfectly good, no?
8200698f425bSmrg	    if test -n "$dlname"; then
8201a3129944Smrg	      soname=$dlname
8202698f425bSmrg	    elif test -n "$soname_spec"; then
8203698f425bSmrg	      # bleh windows
8204698f425bSmrg	      case $host in
8205a3129944Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8206698f425bSmrg	        func_arith $current - $age
8207698f425bSmrg		major=$func_arith_result
8208a3129944Smrg		versuffix=-$major
8209698f425bSmrg		;;
8210698f425bSmrg	      esac
8211698f425bSmrg	      eval soname=\"$soname_spec\"
8212698f425bSmrg	    else
8213a3129944Smrg	      soname=$realname
8214698f425bSmrg	    fi
8215698f425bSmrg
8216698f425bSmrg	    # Make a new name for the extract_expsyms_cmds to use
8217a3129944Smrg	    soroot=$soname
8218698f425bSmrg	    func_basename "$soroot"
8219a3129944Smrg	    soname=$func_basename_result
8220698f425bSmrg	    func_stripname 'lib' '.dll' "$soname"
8221698f425bSmrg	    newlib=libimp-$func_stripname_result.a
8222698f425bSmrg
8223698f425bSmrg	    # If the library has no export list, then create one now
8224698f425bSmrg	    if test -f "$output_objdir/$soname-def"; then :
8225698f425bSmrg	    else
8226a3129944Smrg	      func_verbose "extracting exported symbol list from '$soname'"
8227698f425bSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8228698f425bSmrg	    fi
8229698f425bSmrg
8230698f425bSmrg	    # Create $newlib
8231698f425bSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8232a3129944Smrg	      func_verbose "generating import library for '$soname'"
8233698f425bSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8234698f425bSmrg	    fi
8235698f425bSmrg	    # make sure the library variables are pointing to the new library
8236698f425bSmrg	    dir=$output_objdir
8237698f425bSmrg	    linklib=$newlib
8238698f425bSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8239698f425bSmrg
8240a3129944Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8241698f425bSmrg	    add_shlibpath=
8242698f425bSmrg	    add_dir=
8243698f425bSmrg	    add=
8244698f425bSmrg	    lib_linked=yes
8245698f425bSmrg	    case $hardcode_action in
8246698f425bSmrg	    immediate | unsupported)
8247a3129944Smrg	      if test no = "$hardcode_direct"; then
8248a3129944Smrg		add=$dir/$linklib
8249698f425bSmrg		case $host in
8250a3129944Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8251a3129944Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8252698f425bSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8253a3129944Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
8254698f425bSmrg		  *-*-darwin* )
8255a3129944Smrg		    # if the lib is a (non-dlopened) module then we cannot
8256698f425bSmrg		    # link against it, someone is ignoring the earlier warnings
8257698f425bSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8258a3129944Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
8259698f425bSmrg		      if test "X$dlopenmodule" != "X$lib"; then
8260698f425bSmrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8261a3129944Smrg			if test -z "$old_library"; then
82629ef0b394Smrg			  echo
82639ef0b394Smrg			  echo "*** And there doesn't seem to be a static archive available"
82649ef0b394Smrg			  echo "*** The link will probably fail, sorry"
8265698f425bSmrg			else
8266a3129944Smrg			  add=$dir/$old_library
8267698f425bSmrg			fi
8268698f425bSmrg		      elif test -n "$old_library"; then
8269a3129944Smrg			add=$dir/$old_library
8270698f425bSmrg		      fi
8271698f425bSmrg		    fi
8272698f425bSmrg		esac
8273a3129944Smrg	      elif test no = "$hardcode_minus_L"; then
8274698f425bSmrg		case $host in
8275a3129944Smrg		*-*-sunos*) add_shlibpath=$dir ;;
8276698f425bSmrg		esac
8277a3129944Smrg		add_dir=-L$dir
8278a3129944Smrg		add=-l$name
8279a3129944Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8280a3129944Smrg		add_shlibpath=$dir
8281a3129944Smrg		add=-l$name
8282698f425bSmrg	      else
8283698f425bSmrg		lib_linked=no
8284698f425bSmrg	      fi
8285698f425bSmrg	      ;;
8286698f425bSmrg	    relink)
8287a3129944Smrg	      if test yes = "$hardcode_direct" &&
8288a3129944Smrg	         test no = "$hardcode_direct_absolute"; then
8289a3129944Smrg		add=$dir/$linklib
8290a3129944Smrg	      elif test yes = "$hardcode_minus_L"; then
8291a3129944Smrg		add_dir=-L$absdir
8292698f425bSmrg		# Try looking first in the location we're being installed to.
8293698f425bSmrg		if test -n "$inst_prefix_dir"; then
8294698f425bSmrg		  case $libdir in
8295698f425bSmrg		    [\\/]*)
82969ef0b394Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8297698f425bSmrg		      ;;
8298698f425bSmrg		  esac
8299698f425bSmrg		fi
8300a3129944Smrg		add=-l$name
8301a3129944Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8302a3129944Smrg		add_shlibpath=$dir
8303a3129944Smrg		add=-l$name
8304698f425bSmrg	      else
8305698f425bSmrg		lib_linked=no
8306698f425bSmrg	      fi
8307698f425bSmrg	      ;;
8308698f425bSmrg	    *) lib_linked=no ;;
8309698f425bSmrg	    esac
8310698f425bSmrg
8311a3129944Smrg	    if test yes != "$lib_linked"; then
8312698f425bSmrg	      func_fatal_configuration "unsupported hardcode properties"
8313698f425bSmrg	    fi
8314698f425bSmrg
8315698f425bSmrg	    if test -n "$add_shlibpath"; then
8316698f425bSmrg	      case :$compile_shlibpath: in
8317698f425bSmrg	      *":$add_shlibpath:"*) ;;
83189ef0b394Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8319698f425bSmrg	      esac
8320698f425bSmrg	    fi
8321a3129944Smrg	    if test prog = "$linkmode"; then
8322698f425bSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8323698f425bSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8324698f425bSmrg	    else
8325698f425bSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8326698f425bSmrg	      test -n "$add" && deplibs="$add $deplibs"
8327a3129944Smrg	      if test yes != "$hardcode_direct" &&
8328a3129944Smrg		 test yes != "$hardcode_minus_L" &&
8329a3129944Smrg		 test yes = "$hardcode_shlibpath_var"; then
8330698f425bSmrg		case :$finalize_shlibpath: in
8331698f425bSmrg		*":$libdir:"*) ;;
83329ef0b394Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
8333698f425bSmrg		esac
8334698f425bSmrg	      fi
8335698f425bSmrg	    fi
8336698f425bSmrg	  fi
8337698f425bSmrg
8338a3129944Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8339698f425bSmrg	    add_shlibpath=
8340698f425bSmrg	    add_dir=
8341698f425bSmrg	    add=
8342698f425bSmrg	    # Finalize command for both is simple: just hardcode it.
8343a3129944Smrg	    if test yes = "$hardcode_direct" &&
8344a3129944Smrg	       test no = "$hardcode_direct_absolute"; then
8345a3129944Smrg	      add=$libdir/$linklib
8346a3129944Smrg	    elif test yes = "$hardcode_minus_L"; then
8347a3129944Smrg	      add_dir=-L$libdir
8348a3129944Smrg	      add=-l$name
8349a3129944Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
8350698f425bSmrg	      case :$finalize_shlibpath: in
8351698f425bSmrg	      *":$libdir:"*) ;;
83529ef0b394Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8353698f425bSmrg	      esac
8354a3129944Smrg	      add=-l$name
8355a3129944Smrg	    elif test yes = "$hardcode_automatic"; then
8356698f425bSmrg	      if test -n "$inst_prefix_dir" &&
8357a3129944Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8358a3129944Smrg		add=$inst_prefix_dir$libdir/$linklib
8359698f425bSmrg	      else
8360a3129944Smrg		add=$libdir/$linklib
8361698f425bSmrg	      fi
8362698f425bSmrg	    else
8363698f425bSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
8364a3129944Smrg	      add_dir=-L$libdir
8365698f425bSmrg	      # Try looking first in the location we're being installed to.
8366698f425bSmrg	      if test -n "$inst_prefix_dir"; then
8367698f425bSmrg		case $libdir in
8368698f425bSmrg		  [\\/]*)
83699ef0b394Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8370698f425bSmrg		    ;;
8371698f425bSmrg		esac
8372698f425bSmrg	      fi
8373a3129944Smrg	      add=-l$name
8374698f425bSmrg	    fi
8375698f425bSmrg
8376a3129944Smrg	    if test prog = "$linkmode"; then
8377698f425bSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8378698f425bSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8379698f425bSmrg	    else
8380698f425bSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8381698f425bSmrg	      test -n "$add" && deplibs="$add $deplibs"
8382698f425bSmrg	    fi
8383698f425bSmrg	  fi
8384a3129944Smrg	elif test prog = "$linkmode"; then
8385698f425bSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8386698f425bSmrg	  # is not unsupported.  This is valid on all known static and
8387698f425bSmrg	  # shared platforms.
8388a3129944Smrg	  if test unsupported != "$hardcode_direct"; then
8389a3129944Smrg	    test -n "$old_library" && linklib=$old_library
8390698f425bSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8391698f425bSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8392698f425bSmrg	  else
8393698f425bSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8394698f425bSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8395698f425bSmrg	  fi
8396a3129944Smrg	elif test yes = "$build_libtool_libs"; then
8397698f425bSmrg	  # Not a shared library
8398a3129944Smrg	  if test pass_all != "$deplibs_check_method"; then
8399698f425bSmrg	    # We're trying link a shared library against a static one
8400698f425bSmrg	    # but the system doesn't support it.
8401698f425bSmrg
8402698f425bSmrg	    # Just print a warning and add the library to dependency_libs so
8403698f425bSmrg	    # that the program can be linked against the static library.
84049ef0b394Smrg	    echo
8405a3129944Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
84069ef0b394Smrg	    echo "*** I have the capability to make that library automatically link in when"
84079ef0b394Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
84089ef0b394Smrg	    echo "*** shared version of the library, which you do not appear to have."
8409a3129944Smrg	    if test yes = "$module"; then
84109ef0b394Smrg	      echo "*** But as you try to build a module library, libtool will still create "
84119ef0b394Smrg	      echo "*** a static module, that should work as long as the dlopening application"
84129ef0b394Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8413698f425bSmrg	      if test -z "$global_symbol_pipe"; then
84149ef0b394Smrg		echo
84159ef0b394Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8416a3129944Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
84179ef0b394Smrg		echo "*** not find such a program.  So, this module is probably useless."
8418a3129944Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8419698f425bSmrg	      fi
8420a3129944Smrg	      if test no = "$build_old_libs"; then
8421698f425bSmrg		build_libtool_libs=module
8422698f425bSmrg		build_old_libs=yes
8423698f425bSmrg	      else
8424698f425bSmrg		build_libtool_libs=no
8425698f425bSmrg	      fi
8426698f425bSmrg	    fi
8427698f425bSmrg	  else
8428698f425bSmrg	    deplibs="$dir/$old_library $deplibs"
8429698f425bSmrg	    link_static=yes
8430698f425bSmrg	  fi
8431698f425bSmrg	fi # link shared/static library?
8432698f425bSmrg
8433a3129944Smrg	if test lib = "$linkmode"; then
8434698f425bSmrg	  if test -n "$dependency_libs" &&
8435a3129944Smrg	     { test yes != "$hardcode_into_libs" ||
8436a3129944Smrg	       test yes = "$build_old_libs" ||
8437a3129944Smrg	       test yes = "$link_static"; }; then
8438698f425bSmrg	    # Extract -R from dependency_libs
8439698f425bSmrg	    temp_deplibs=
8440698f425bSmrg	    for libdir in $dependency_libs; do
8441698f425bSmrg	      case $libdir in
8442698f425bSmrg	      -R*) func_stripname '-R' '' "$libdir"
8443698f425bSmrg	           temp_xrpath=$func_stripname_result
8444698f425bSmrg		   case " $xrpath " in
8445698f425bSmrg		   *" $temp_xrpath "*) ;;
84469ef0b394Smrg		   *) func_append xrpath " $temp_xrpath";;
8447698f425bSmrg		   esac;;
84489ef0b394Smrg	      *) func_append temp_deplibs " $libdir";;
8449698f425bSmrg	      esac
8450698f425bSmrg	    done
8451a3129944Smrg	    dependency_libs=$temp_deplibs
8452698f425bSmrg	  fi
8453698f425bSmrg
84549ef0b394Smrg	  func_append newlib_search_path " $absdir"
8455698f425bSmrg	  # Link against this library
8456a3129944Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8457698f425bSmrg	  # ... and its dependency_libs
8458698f425bSmrg	  tmp_libs=
8459698f425bSmrg	  for deplib in $dependency_libs; do
8460698f425bSmrg	    newdependency_libs="$deplib $newdependency_libs"
84619ef0b394Smrg	    case $deplib in
84629ef0b394Smrg              -L*) func_stripname '-L' '' "$deplib"
84639ef0b394Smrg                   func_resolve_sysroot "$func_stripname_result";;
84649ef0b394Smrg              *) func_resolve_sysroot "$deplib" ;;
84659ef0b394Smrg            esac
8466a3129944Smrg	    if $opt_preserve_dup_deps; then
8467698f425bSmrg	      case "$tmp_libs " in
84689ef0b394Smrg	      *" $func_resolve_sysroot_result "*)
84699ef0b394Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8470698f425bSmrg	      esac
8471698f425bSmrg	    fi
84729ef0b394Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8473698f425bSmrg	  done
8474698f425bSmrg
8475a3129944Smrg	  if test no != "$link_all_deplibs"; then
8476698f425bSmrg	    # Add the search paths of all dependency libraries
8477698f425bSmrg	    for deplib in $dependency_libs; do
84789ef0b394Smrg	      path=
8479698f425bSmrg	      case $deplib in
8480a3129944Smrg	      -L*) path=$deplib ;;
8481698f425bSmrg	      *.la)
84829ef0b394Smrg	        func_resolve_sysroot "$deplib"
84839ef0b394Smrg	        deplib=$func_resolve_sysroot_result
8484698f425bSmrg	        func_dirname "$deplib" "" "."
84859ef0b394Smrg		dir=$func_dirname_result
8486698f425bSmrg		# We need an absolute path.
8487698f425bSmrg		case $dir in
8488a3129944Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8489698f425bSmrg		*)
8490698f425bSmrg		  absdir=`cd "$dir" && pwd`
8491698f425bSmrg		  if test -z "$absdir"; then
8492a3129944Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8493a3129944Smrg		    absdir=$dir
8494698f425bSmrg		  fi
8495698f425bSmrg		  ;;
8496698f425bSmrg		esac
8497698f425bSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
8498698f425bSmrg		case $host in
8499698f425bSmrg		*-*-darwin*)
8500698f425bSmrg		  depdepl=
8501a3129944Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8502a3129944Smrg		  if test -n "$deplibrary_names"; then
8503a3129944Smrg		    for tmp in $deplibrary_names; do
8504698f425bSmrg		      depdepl=$tmp
8505698f425bSmrg		    done
8506a3129944Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8507a3129944Smrg		      depdepl=$absdir/$objdir/$depdepl
8508a3129944Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8509698f425bSmrg                      if test -z "$darwin_install_name"; then
8510a3129944Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8511698f425bSmrg                      fi
8512a3129944Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8513a3129944Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8514698f425bSmrg		      path=
8515698f425bSmrg		    fi
8516698f425bSmrg		  fi
8517698f425bSmrg		  ;;
8518698f425bSmrg		*)
8519a3129944Smrg		  path=-L$absdir/$objdir
8520698f425bSmrg		  ;;
8521698f425bSmrg		esac
8522698f425bSmrg		else
8523a3129944Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8524698f425bSmrg		  test -z "$libdir" && \
8525a3129944Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8526698f425bSmrg		  test "$absdir" != "$libdir" && \
8527a3129944Smrg		    func_warning "'$deplib' seems to be moved"
8528698f425bSmrg
8529a3129944Smrg		  path=-L$absdir
8530698f425bSmrg		fi
8531698f425bSmrg		;;
8532698f425bSmrg	      esac
8533698f425bSmrg	      case " $deplibs " in
8534698f425bSmrg	      *" $path "*) ;;
8535698f425bSmrg	      *) deplibs="$path $deplibs" ;;
8536698f425bSmrg	      esac
8537698f425bSmrg	    done
8538698f425bSmrg	  fi # link_all_deplibs != no
8539698f425bSmrg	fi # linkmode = lib
8540698f425bSmrg      done # for deplib in $libs
8541a3129944Smrg      if test link = "$pass"; then
8542a3129944Smrg	if test prog = "$linkmode"; then
8543698f425bSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8544698f425bSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8545698f425bSmrg	else
85469ef0b394Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8547698f425bSmrg	fi
8548698f425bSmrg      fi
8549a3129944Smrg      dependency_libs=$newdependency_libs
8550a3129944Smrg      if test dlpreopen = "$pass"; then
8551698f425bSmrg	# Link the dlpreopened libraries before other libraries
8552698f425bSmrg	for deplib in $save_deplibs; do
8553698f425bSmrg	  deplibs="$deplib $deplibs"
8554698f425bSmrg	done
8555698f425bSmrg      fi
8556a3129944Smrg      if test dlopen != "$pass"; then
8557a3129944Smrg	test conv = "$pass" || {
8558698f425bSmrg	  # Make sure lib_search_path contains only unique directories.
8559698f425bSmrg	  lib_search_path=
8560698f425bSmrg	  for dir in $newlib_search_path; do
8561698f425bSmrg	    case "$lib_search_path " in
8562698f425bSmrg	    *" $dir "*) ;;
85639ef0b394Smrg	    *) func_append lib_search_path " $dir" ;;
8564698f425bSmrg	    esac
8565698f425bSmrg	  done
8566698f425bSmrg	  newlib_search_path=
8567a3129944Smrg	}
8568698f425bSmrg
8569a3129944Smrg	if test prog,link = "$linkmode,$pass"; then
8570698f425bSmrg	  vars="compile_deplibs finalize_deplibs"
8571a3129944Smrg	else
8572a3129944Smrg	  vars=deplibs
8573698f425bSmrg	fi
8574698f425bSmrg	for var in $vars dependency_libs; do
8575698f425bSmrg	  # Add libraries to $var in reverse order
8576698f425bSmrg	  eval tmp_libs=\"\$$var\"
8577698f425bSmrg	  new_libs=
8578698f425bSmrg	  for deplib in $tmp_libs; do
8579698f425bSmrg	    # FIXME: Pedantically, this is the right thing to do, so
8580698f425bSmrg	    #        that some nasty dependency loop isn't accidentally
8581698f425bSmrg	    #        broken:
8582698f425bSmrg	    #new_libs="$deplib $new_libs"
8583698f425bSmrg	    # Pragmatically, this seems to cause very few problems in
8584698f425bSmrg	    # practice:
8585698f425bSmrg	    case $deplib in
8586698f425bSmrg	    -L*) new_libs="$deplib $new_libs" ;;
8587698f425bSmrg	    -R*) ;;
8588698f425bSmrg	    *)
8589698f425bSmrg	      # And here is the reason: when a library appears more
8590698f425bSmrg	      # than once as an explicit dependence of a library, or
8591698f425bSmrg	      # is implicitly linked in more than once by the
8592698f425bSmrg	      # compiler, it is considered special, and multiple
8593698f425bSmrg	      # occurrences thereof are not removed.  Compare this
8594698f425bSmrg	      # with having the same library being listed as a
8595698f425bSmrg	      # dependency of multiple other libraries: in this case,
8596698f425bSmrg	      # we know (pedantically, we assume) the library does not
8597698f425bSmrg	      # need to be listed more than once, so we keep only the
8598698f425bSmrg	      # last copy.  This is not always right, but it is rare
8599698f425bSmrg	      # enough that we require users that really mean to play
8600698f425bSmrg	      # such unportable linking tricks to link the library
8601698f425bSmrg	      # using -Wl,-lname, so that libtool does not consider it
8602698f425bSmrg	      # for duplicate removal.
8603698f425bSmrg	      case " $specialdeplibs " in
8604698f425bSmrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8605698f425bSmrg	      *)
8606698f425bSmrg		case " $new_libs " in
8607698f425bSmrg		*" $deplib "*) ;;
8608698f425bSmrg		*) new_libs="$deplib $new_libs" ;;
8609698f425bSmrg		esac
8610698f425bSmrg		;;
8611698f425bSmrg	      esac
8612698f425bSmrg	      ;;
8613698f425bSmrg	    esac
8614698f425bSmrg	  done
8615698f425bSmrg	  tmp_libs=
8616698f425bSmrg	  for deplib in $new_libs; do
8617698f425bSmrg	    case $deplib in
8618698f425bSmrg	    -L*)
8619698f425bSmrg	      case " $tmp_libs " in
8620698f425bSmrg	      *" $deplib "*) ;;
86219ef0b394Smrg	      *) func_append tmp_libs " $deplib" ;;
8622698f425bSmrg	      esac
8623698f425bSmrg	      ;;
86249ef0b394Smrg	    *) func_append tmp_libs " $deplib" ;;
8625698f425bSmrg	    esac
8626698f425bSmrg	  done
8627698f425bSmrg	  eval $var=\"$tmp_libs\"
8628698f425bSmrg	done # for var
8629698f425bSmrg      fi
8630a3129944Smrg
8631a3129944Smrg      # Add Sun CC postdeps if required:
8632a3129944Smrg      test CXX = "$tagname" && {
8633a3129944Smrg        case $host_os in
8634a3129944Smrg        linux*)
8635a3129944Smrg          case `$CC -V 2>&1 | sed 5q` in
8636a3129944Smrg          *Sun\ C*) # Sun C++ 5.9
8637a3129944Smrg            func_suncc_cstd_abi
8638a3129944Smrg
8639a3129944Smrg            if test no != "$suncc_use_cstd_abi"; then
8640a3129944Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8641a3129944Smrg            fi
8642a3129944Smrg            ;;
8643a3129944Smrg          esac
8644a3129944Smrg          ;;
8645a3129944Smrg
8646a3129944Smrg        solaris*)
8647a3129944Smrg          func_cc_basename "$CC"
8648a3129944Smrg          case $func_cc_basename_result in
8649a3129944Smrg          CC* | sunCC*)
8650a3129944Smrg            func_suncc_cstd_abi
8651a3129944Smrg
8652a3129944Smrg            if test no != "$suncc_use_cstd_abi"; then
8653a3129944Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8654a3129944Smrg            fi
8655a3129944Smrg            ;;
8656a3129944Smrg          esac
8657a3129944Smrg          ;;
8658a3129944Smrg        esac
8659a3129944Smrg      }
8660a3129944Smrg
8661698f425bSmrg      # Last step: remove runtime libs from dependency_libs
8662698f425bSmrg      # (they stay in deplibs)
8663698f425bSmrg      tmp_libs=
8664a3129944Smrg      for i in $dependency_libs; do
8665698f425bSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
8666698f425bSmrg	*" $i "*)
8667a3129944Smrg	  i=
8668698f425bSmrg	  ;;
8669698f425bSmrg	esac
8670a3129944Smrg	if test -n "$i"; then
86719ef0b394Smrg	  func_append tmp_libs " $i"
8672698f425bSmrg	fi
8673698f425bSmrg      done
8674698f425bSmrg      dependency_libs=$tmp_libs
8675698f425bSmrg    done # for pass
8676a3129944Smrg    if test prog = "$linkmode"; then
8677a3129944Smrg      dlfiles=$newdlfiles
8678698f425bSmrg    fi
8679a3129944Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8680a3129944Smrg      dlprefiles=$newdlprefiles
8681698f425bSmrg    fi
8682698f425bSmrg
8683698f425bSmrg    case $linkmode in
8684698f425bSmrg    oldlib)
8685a3129944Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8686a3129944Smrg	func_warning "'-dlopen' is ignored for archives"
8687698f425bSmrg      fi
8688698f425bSmrg
8689698f425bSmrg      case " $deplibs" in
8690698f425bSmrg      *\ -l* | *\ -L*)
8691a3129944Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8692698f425bSmrg      esac
8693698f425bSmrg
8694698f425bSmrg      test -n "$rpath" && \
8695a3129944Smrg	func_warning "'-rpath' is ignored for archives"
8696698f425bSmrg
8697698f425bSmrg      test -n "$xrpath" && \
8698a3129944Smrg	func_warning "'-R' is ignored for archives"
8699698f425bSmrg
8700698f425bSmrg      test -n "$vinfo" && \
8701a3129944Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
8702698f425bSmrg
8703698f425bSmrg      test -n "$release" && \
8704a3129944Smrg	func_warning "'-release' is ignored for archives"
8705698f425bSmrg
8706698f425bSmrg      test -n "$export_symbols$export_symbols_regex" && \
8707a3129944Smrg	func_warning "'-export-symbols' is ignored for archives"
8708698f425bSmrg
8709698f425bSmrg      # Now set the variables for building old libraries.
8710698f425bSmrg      build_libtool_libs=no
8711a3129944Smrg      oldlibs=$output
87129ef0b394Smrg      func_append objs "$old_deplibs"
8713698f425bSmrg      ;;
8714698f425bSmrg
8715698f425bSmrg    lib)
8716a3129944Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
8717698f425bSmrg      case $outputname in
8718698f425bSmrg      lib*)
8719698f425bSmrg	func_stripname 'lib' '.la' "$outputname"
8720698f425bSmrg	name=$func_stripname_result
8721698f425bSmrg	eval shared_ext=\"$shrext_cmds\"
8722698f425bSmrg	eval libname=\"$libname_spec\"
8723698f425bSmrg	;;
8724698f425bSmrg      *)
8725a3129944Smrg	test no = "$module" \
8726a3129944Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
8727698f425bSmrg
8728a3129944Smrg	if test no != "$need_lib_prefix"; then
8729698f425bSmrg	  # Add the "lib" prefix for modules if required
8730698f425bSmrg	  func_stripname '' '.la' "$outputname"
8731698f425bSmrg	  name=$func_stripname_result
8732698f425bSmrg	  eval shared_ext=\"$shrext_cmds\"
8733698f425bSmrg	  eval libname=\"$libname_spec\"
8734698f425bSmrg	else
8735698f425bSmrg	  func_stripname '' '.la' "$outputname"
8736698f425bSmrg	  libname=$func_stripname_result
8737698f425bSmrg	fi
8738698f425bSmrg	;;
8739698f425bSmrg      esac
8740698f425bSmrg
8741698f425bSmrg      if test -n "$objs"; then
8742a3129944Smrg	if test pass_all != "$deplibs_check_method"; then
8743a3129944Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
8744698f425bSmrg	else
87459ef0b394Smrg	  echo
8746698f425bSmrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
8747698f425bSmrg	  $ECHO "*** objects $objs is not portable!"
87489ef0b394Smrg	  func_append libobjs " $objs"
8749698f425bSmrg	fi
8750698f425bSmrg      fi
8751698f425bSmrg
8752a3129944Smrg      test no = "$dlself" \
8753a3129944Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
8754698f425bSmrg
8755698f425bSmrg      set dummy $rpath
8756698f425bSmrg      shift
8757a3129944Smrg      test 1 -lt "$#" \
8758a3129944Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
8759698f425bSmrg
8760a3129944Smrg      install_libdir=$1
8761698f425bSmrg
8762698f425bSmrg      oldlibs=
8763698f425bSmrg      if test -z "$rpath"; then
8764a3129944Smrg	if test yes = "$build_libtool_libs"; then
8765698f425bSmrg	  # Building a libtool convenience library.
8766a3129944Smrg	  # Some compilers have problems with a '.al' extension so
8767698f425bSmrg	  # convenience libraries should have the same extension an
8768698f425bSmrg	  # archive normally would.
8769698f425bSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
8770698f425bSmrg	  build_libtool_libs=convenience
8771698f425bSmrg	  build_old_libs=yes
8772698f425bSmrg	fi
8773698f425bSmrg
8774698f425bSmrg	test -n "$vinfo" && \
8775a3129944Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
8776698f425bSmrg
8777698f425bSmrg	test -n "$release" && \
8778a3129944Smrg	  func_warning "'-release' is ignored for convenience libraries"
8779698f425bSmrg      else
8780698f425bSmrg
8781698f425bSmrg	# Parse the version information argument.
8782a3129944Smrg	save_ifs=$IFS; IFS=:
8783698f425bSmrg	set dummy $vinfo 0 0 0
8784698f425bSmrg	shift
8785a3129944Smrg	IFS=$save_ifs
8786698f425bSmrg
8787698f425bSmrg	test -n "$7" && \
8788a3129944Smrg	  func_fatal_help "too many parameters to '-version-info'"
8789698f425bSmrg
8790698f425bSmrg	# convert absolute version numbers to libtool ages
8791698f425bSmrg	# this retains compatibility with .la files and attempts
8792698f425bSmrg	# to make the code below a bit more comprehensible
8793698f425bSmrg
8794698f425bSmrg	case $vinfo_number in
8795698f425bSmrg	yes)
8796a3129944Smrg	  number_major=$1
8797a3129944Smrg	  number_minor=$2
8798a3129944Smrg	  number_revision=$3
8799698f425bSmrg	  #
8800698f425bSmrg	  # There are really only two kinds -- those that
8801698f425bSmrg	  # use the current revision as the major version
8802698f425bSmrg	  # and those that subtract age and use age as
8803698f425bSmrg	  # a minor version.  But, then there is irix
8804a3129944Smrg	  # that has an extra 1 added just for fun
8805698f425bSmrg	  #
8806698f425bSmrg	  case $version_type in
8807fb5e8d76Smrg	  # correct linux to gnu/linux during the next big refactor
8808a3129944Smrg	  darwin|freebsd-elf|linux|osf|windows|none)
8809698f425bSmrg	    func_arith $number_major + $number_minor
8810698f425bSmrg	    current=$func_arith_result
8811a3129944Smrg	    age=$number_minor
8812a3129944Smrg	    revision=$number_revision
8813698f425bSmrg	    ;;
8814a3129944Smrg	  freebsd-aout|qnx|sunos)
8815a3129944Smrg	    current=$number_major
8816a3129944Smrg	    revision=$number_minor
8817a3129944Smrg	    age=0
8818698f425bSmrg	    ;;
8819698f425bSmrg	  irix|nonstopux)
8820698f425bSmrg	    func_arith $number_major + $number_minor
8821698f425bSmrg	    current=$func_arith_result
8822a3129944Smrg	    age=$number_minor
8823a3129944Smrg	    revision=$number_minor
8824698f425bSmrg	    lt_irix_increment=no
8825698f425bSmrg	    ;;
8826698f425bSmrg	  esac
8827698f425bSmrg	  ;;
8828698f425bSmrg	no)
8829a3129944Smrg	  current=$1
8830a3129944Smrg	  revision=$2
8831a3129944Smrg	  age=$3
8832698f425bSmrg	  ;;
8833698f425bSmrg	esac
8834698f425bSmrg
8835698f425bSmrg	# Check that each of the things are valid numbers.
8836698f425bSmrg	case $current in
8837698f425bSmrg	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]) ;;
8838698f425bSmrg	*)
8839a3129944Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
8840a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
8841698f425bSmrg	  ;;
8842698f425bSmrg	esac
8843698f425bSmrg
8844698f425bSmrg	case $revision in
8845698f425bSmrg	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]) ;;
8846698f425bSmrg	*)
8847a3129944Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
8848a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
8849698f425bSmrg	  ;;
8850698f425bSmrg	esac
8851698f425bSmrg
8852698f425bSmrg	case $age in
8853698f425bSmrg	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]) ;;
8854698f425bSmrg	*)
8855a3129944Smrg	  func_error "AGE '$age' must be a nonnegative integer"
8856a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
8857698f425bSmrg	  ;;
8858698f425bSmrg	esac
8859698f425bSmrg
8860698f425bSmrg	if test "$age" -gt "$current"; then
8861a3129944Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
8862a3129944Smrg	  func_fatal_error "'$vinfo' is not valid version information"
8863698f425bSmrg	fi
8864698f425bSmrg
8865698f425bSmrg	# Calculate the version variables.
8866698f425bSmrg	major=
8867698f425bSmrg	versuffix=
8868698f425bSmrg	verstring=
8869698f425bSmrg	case $version_type in
8870698f425bSmrg	none) ;;
8871698f425bSmrg
8872698f425bSmrg	darwin)
8873698f425bSmrg	  # Like Linux, but with the current version available in
8874698f425bSmrg	  # verstring for coding it into the library header
8875698f425bSmrg	  func_arith $current - $age
8876698f425bSmrg	  major=.$func_arith_result
8877a3129944Smrg	  versuffix=$major.$age.$revision
8878698f425bSmrg	  # Darwin ld doesn't like 0 for these options...
8879698f425bSmrg	  func_arith $current + 1
8880698f425bSmrg	  minor_current=$func_arith_result
8881a3129944Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8882698f425bSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8883a3129944Smrg          # On Darwin other compilers
8884a3129944Smrg          case $CC in
8885a3129944Smrg              nagfor*)
8886a3129944Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8887a3129944Smrg                  ;;
8888a3129944Smrg              *)
8889a3129944Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8890a3129944Smrg                  ;;
8891a3129944Smrg          esac
8892698f425bSmrg	  ;;
8893698f425bSmrg
8894698f425bSmrg	freebsd-aout)
8895a3129944Smrg	  major=.$current
8896a3129944Smrg	  versuffix=.$current.$revision
8897698f425bSmrg	  ;;
8898698f425bSmrg
8899698f425bSmrg	freebsd-elf)
8900a3129944Smrg	  func_arith $current - $age
8901a3129944Smrg	  major=.$func_arith_result
8902a3129944Smrg	  versuffix=$major.$age.$revision
8903698f425bSmrg	  ;;
8904698f425bSmrg
8905698f425bSmrg	irix | nonstopux)
8906a3129944Smrg	  if test no = "$lt_irix_increment"; then
8907698f425bSmrg	    func_arith $current - $age
8908698f425bSmrg	  else
8909698f425bSmrg	    func_arith $current - $age + 1
8910698f425bSmrg	  fi
8911698f425bSmrg	  major=$func_arith_result
8912698f425bSmrg
8913698f425bSmrg	  case $version_type in
8914698f425bSmrg	    nonstopux) verstring_prefix=nonstopux ;;
8915698f425bSmrg	    *)         verstring_prefix=sgi ;;
8916698f425bSmrg	  esac
8917a3129944Smrg	  verstring=$verstring_prefix$major.$revision
8918698f425bSmrg
8919698f425bSmrg	  # Add in all the interfaces that we are compatible with.
8920698f425bSmrg	  loop=$revision
8921a3129944Smrg	  while test 0 -ne "$loop"; do
8922698f425bSmrg	    func_arith $revision - $loop
8923698f425bSmrg	    iface=$func_arith_result
8924698f425bSmrg	    func_arith $loop - 1
8925698f425bSmrg	    loop=$func_arith_result
8926a3129944Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
8927698f425bSmrg	  done
8928698f425bSmrg
8929a3129944Smrg	  # Before this point, $major must not contain '.'.
8930698f425bSmrg	  major=.$major
8931a3129944Smrg	  versuffix=$major.$revision
8932698f425bSmrg	  ;;
8933698f425bSmrg
8934fb5e8d76Smrg	linux) # correct to gnu/linux during the next big refactor
8935698f425bSmrg	  func_arith $current - $age
8936698f425bSmrg	  major=.$func_arith_result
8937a3129944Smrg	  versuffix=$major.$age.$revision
8938698f425bSmrg	  ;;
8939698f425bSmrg
8940698f425bSmrg	osf)
8941698f425bSmrg	  func_arith $current - $age
8942698f425bSmrg	  major=.$func_arith_result
8943a3129944Smrg	  versuffix=.$current.$age.$revision
8944a3129944Smrg	  verstring=$current.$age.$revision
8945698f425bSmrg
8946698f425bSmrg	  # Add in all the interfaces that we are compatible with.
8947698f425bSmrg	  loop=$age
8948a3129944Smrg	  while test 0 -ne "$loop"; do
8949698f425bSmrg	    func_arith $current - $loop
8950698f425bSmrg	    iface=$func_arith_result
8951698f425bSmrg	    func_arith $loop - 1
8952698f425bSmrg	    loop=$func_arith_result
8953a3129944Smrg	    verstring=$verstring:$iface.0
8954698f425bSmrg	  done
8955698f425bSmrg
8956698f425bSmrg	  # Make executables depend on our current version.
8957a3129944Smrg	  func_append verstring ":$current.0"
8958698f425bSmrg	  ;;
8959698f425bSmrg
8960698f425bSmrg	qnx)
8961a3129944Smrg	  major=.$current
8962a3129944Smrg	  versuffix=.$current
8963a3129944Smrg	  ;;
8964a3129944Smrg
8965a3129944Smrg	sco)
8966a3129944Smrg	  major=.$current
8967a3129944Smrg	  versuffix=.$current
8968698f425bSmrg	  ;;
8969698f425bSmrg
8970698f425bSmrg	sunos)
8971a3129944Smrg	  major=.$current
8972a3129944Smrg	  versuffix=.$current.$revision
8973698f425bSmrg	  ;;
8974698f425bSmrg
8975698f425bSmrg	windows)
8976698f425bSmrg	  # Use '-' rather than '.', since we only want one
8977a3129944Smrg	  # extension on DOS 8.3 file systems.
8978698f425bSmrg	  func_arith $current - $age
8979698f425bSmrg	  major=$func_arith_result
8980a3129944Smrg	  versuffix=-$major
8981698f425bSmrg	  ;;
8982698f425bSmrg
8983698f425bSmrg	*)
8984a3129944Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
8985698f425bSmrg	  ;;
8986698f425bSmrg	esac
8987698f425bSmrg
8988698f425bSmrg	# Clear the version info if we defaulted, and they specified a release.
8989698f425bSmrg	if test -z "$vinfo" && test -n "$release"; then
8990698f425bSmrg	  major=
8991698f425bSmrg	  case $version_type in
8992698f425bSmrg	  darwin)
8993698f425bSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
8994698f425bSmrg	    # problems, so we reset it completely
8995698f425bSmrg	    verstring=
8996698f425bSmrg	    ;;
8997698f425bSmrg	  *)
8998a3129944Smrg	    verstring=0.0
8999698f425bSmrg	    ;;
9000698f425bSmrg	  esac
9001a3129944Smrg	  if test no = "$need_version"; then
9002698f425bSmrg	    versuffix=
9003698f425bSmrg	  else
9004a3129944Smrg	    versuffix=.0.0
9005698f425bSmrg	  fi
9006698f425bSmrg	fi
9007698f425bSmrg
9008698f425bSmrg	# Remove version info from name if versioning should be avoided
9009a3129944Smrg	if test yes,no = "$avoid_version,$need_version"; then
9010698f425bSmrg	  major=
9011698f425bSmrg	  versuffix=
9012a3129944Smrg	  verstring=
9013698f425bSmrg	fi
9014698f425bSmrg
9015698f425bSmrg	# Check to see if the archive will have undefined symbols.
9016a3129944Smrg	if test yes = "$allow_undefined"; then
9017a3129944Smrg	  if test unsupported = "$allow_undefined_flag"; then
9018a3129944Smrg	    if test yes = "$build_old_libs"; then
9019a3129944Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9020a3129944Smrg	      build_libtool_libs=no
9021a3129944Smrg	    else
9022a3129944Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9023a3129944Smrg	    fi
9024698f425bSmrg	  fi
9025698f425bSmrg	else
9026698f425bSmrg	  # Don't allow undefined symbols.
9027a3129944Smrg	  allow_undefined_flag=$no_undefined_flag
9028698f425bSmrg	fi
9029698f425bSmrg
9030698f425bSmrg      fi
9031698f425bSmrg
9032a3129944Smrg      func_generate_dlsyms "$libname" "$libname" :
90339ef0b394Smrg      func_append libobjs " $symfileobj"
9034a3129944Smrg      test " " = "$libobjs" && libobjs=
9035698f425bSmrg
9036a3129944Smrg      if test relink != "$opt_mode"; then
9037698f425bSmrg	# Remove our outputs, but don't remove object files since they
9038698f425bSmrg	# may have been created when compiling PIC objects.
9039698f425bSmrg	removelist=
9040698f425bSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
9041698f425bSmrg	for p in $tempremovelist; do
9042698f425bSmrg	  case $p in
9043698f425bSmrg	    *.$objext | *.gcno)
9044698f425bSmrg	       ;;
9045a3129944Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9046a3129944Smrg	       if test -n "$precious_files_regex"; then
9047698f425bSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9048698f425bSmrg		 then
9049698f425bSmrg		   continue
9050698f425bSmrg		 fi
9051698f425bSmrg	       fi
90529ef0b394Smrg	       func_append removelist " $p"
9053698f425bSmrg	       ;;
9054698f425bSmrg	    *) ;;
9055698f425bSmrg	  esac
9056698f425bSmrg	done
9057698f425bSmrg	test -n "$removelist" && \
9058698f425bSmrg	  func_show_eval "${RM}r \$removelist"
9059698f425bSmrg      fi
9060698f425bSmrg
9061698f425bSmrg      # Now set the variables for building old libraries.
9062a3129944Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
90639ef0b394Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
9064698f425bSmrg
9065698f425bSmrg	# Transform .lo files to .o files.
9066a3129944Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9067698f425bSmrg      fi
9068698f425bSmrg
9069698f425bSmrg      # Eliminate all temporary directories.
9070698f425bSmrg      #for path in $notinst_path; do
90719ef0b394Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
90729ef0b394Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
90739ef0b394Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9074698f425bSmrg      #done
9075698f425bSmrg
9076698f425bSmrg      if test -n "$xrpath"; then
9077698f425bSmrg	# If the user specified any rpath flags, then add them.
9078698f425bSmrg	temp_xrpath=
9079698f425bSmrg	for libdir in $xrpath; do
90809ef0b394Smrg	  func_replace_sysroot "$libdir"
90819ef0b394Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9082698f425bSmrg	  case "$finalize_rpath " in
9083698f425bSmrg	  *" $libdir "*) ;;
90849ef0b394Smrg	  *) func_append finalize_rpath " $libdir" ;;
9085698f425bSmrg	  esac
9086698f425bSmrg	done
9087a3129944Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9088698f425bSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
9089698f425bSmrg	fi
9090698f425bSmrg      fi
9091698f425bSmrg
9092698f425bSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9093a3129944Smrg      old_dlfiles=$dlfiles
9094698f425bSmrg      dlfiles=
9095698f425bSmrg      for lib in $old_dlfiles; do
9096698f425bSmrg	case " $dlprefiles $dlfiles " in
9097698f425bSmrg	*" $lib "*) ;;
90989ef0b394Smrg	*) func_append dlfiles " $lib" ;;
9099698f425bSmrg	esac
9100698f425bSmrg      done
9101698f425bSmrg
9102698f425bSmrg      # Make sure dlprefiles contains only unique files
9103a3129944Smrg      old_dlprefiles=$dlprefiles
9104698f425bSmrg      dlprefiles=
9105698f425bSmrg      for lib in $old_dlprefiles; do
9106698f425bSmrg	case "$dlprefiles " in
9107698f425bSmrg	*" $lib "*) ;;
91089ef0b394Smrg	*) func_append dlprefiles " $lib" ;;
9109698f425bSmrg	esac
9110698f425bSmrg      done
9111698f425bSmrg
9112a3129944Smrg      if test yes = "$build_libtool_libs"; then
9113698f425bSmrg	if test -n "$rpath"; then
9114698f425bSmrg	  case $host in
91159ef0b394Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9116698f425bSmrg	    # these systems don't actually have a c library (as such)!
9117698f425bSmrg	    ;;
9118698f425bSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
9119698f425bSmrg	    # Rhapsody C library is in the System framework
91209ef0b394Smrg	    func_append deplibs " System.ltframework"
9121698f425bSmrg	    ;;
9122698f425bSmrg	  *-*-netbsd*)
9123698f425bSmrg	    # Don't link with libc until the a.out ld.so is fixed.
9124698f425bSmrg	    ;;
9125698f425bSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
9126698f425bSmrg	    # Do not include libc due to us having libc/libc_r.
9127698f425bSmrg	    ;;
9128698f425bSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9129698f425bSmrg	    # Causes problems with __ctype
9130698f425bSmrg	    ;;
9131698f425bSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9132698f425bSmrg	    # Compiler inserts libc in the correct place for threads to work
9133698f425bSmrg	    ;;
9134698f425bSmrg	  *)
9135698f425bSmrg	    # Add libc to deplibs on all other systems if necessary.
9136a3129944Smrg	    if test yes = "$build_libtool_need_lc"; then
91379ef0b394Smrg	      func_append deplibs " -lc"
9138698f425bSmrg	    fi
9139698f425bSmrg	    ;;
9140698f425bSmrg	  esac
9141698f425bSmrg	fi
9142698f425bSmrg
9143698f425bSmrg	# Transform deplibs into only deplibs that can be linked in shared.
9144698f425bSmrg	name_save=$name
9145698f425bSmrg	libname_save=$libname
9146698f425bSmrg	release_save=$release
9147698f425bSmrg	versuffix_save=$versuffix
9148698f425bSmrg	major_save=$major
9149698f425bSmrg	# I'm not sure if I'm treating the release correctly.  I think
9150698f425bSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9151698f425bSmrg	# add it in twice.  Is that correct?
9152a3129944Smrg	release=
9153a3129944Smrg	versuffix=
9154a3129944Smrg	major=
9155698f425bSmrg	newdeplibs=
9156698f425bSmrg	droppeddeps=no
9157698f425bSmrg	case $deplibs_check_method in
9158698f425bSmrg	pass_all)
9159698f425bSmrg	  # Don't check for shared/static.  Everything works.
9160698f425bSmrg	  # This might be a little naive.  We might want to check
9161698f425bSmrg	  # whether the library exists or not.  But this is on
9162698f425bSmrg	  # osf3 & osf4 and I'm not really sure... Just
9163698f425bSmrg	  # implementing what was already the behavior.
9164698f425bSmrg	  newdeplibs=$deplibs
9165698f425bSmrg	  ;;
9166698f425bSmrg	test_compile)
9167698f425bSmrg	  # This code stresses the "libraries are programs" paradigm to its
9168698f425bSmrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9169698f425bSmrg	  # against the deplibs as a proxy for the library.  Then we can check
9170698f425bSmrg	  # whether they linked in statically or dynamically with ldd.
9171698f425bSmrg	  $opt_dry_run || $RM conftest.c
9172698f425bSmrg	  cat > conftest.c <<EOF
9173698f425bSmrg	  int main() { return 0; }
9174698f425bSmrgEOF
9175698f425bSmrg	  $opt_dry_run || $RM conftest
9176698f425bSmrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9177698f425bSmrg	    ldd_output=`ldd conftest`
9178698f425bSmrg	    for i in $deplibs; do
9179698f425bSmrg	      case $i in
9180698f425bSmrg	      -l*)
9181698f425bSmrg		func_stripname -l '' "$i"
9182698f425bSmrg		name=$func_stripname_result
9183a3129944Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9184698f425bSmrg		  case " $predeps $postdeps " in
9185698f425bSmrg		  *" $i "*)
91869ef0b394Smrg		    func_append newdeplibs " $i"
9187a3129944Smrg		    i=
9188698f425bSmrg		    ;;
9189698f425bSmrg		  esac
9190698f425bSmrg		fi
9191a3129944Smrg		if test -n "$i"; then
9192698f425bSmrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9193698f425bSmrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9194698f425bSmrg		  set dummy $deplib_matches; shift
9195698f425bSmrg		  deplib_match=$1
9196a3129944Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
91979ef0b394Smrg		    func_append newdeplibs " $i"
9198698f425bSmrg		  else
9199698f425bSmrg		    droppeddeps=yes
92009ef0b394Smrg		    echo
9201698f425bSmrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
92029ef0b394Smrg		    echo "*** I have the capability to make that library automatically link in when"
92039ef0b394Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
92049ef0b394Smrg		    echo "*** shared version of the library, which I believe you do not have"
92059ef0b394Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
92069ef0b394Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9207698f425bSmrg		  fi
9208698f425bSmrg		fi
9209698f425bSmrg		;;
9210698f425bSmrg	      *)
92119ef0b394Smrg		func_append newdeplibs " $i"
9212698f425bSmrg		;;
9213698f425bSmrg	      esac
9214698f425bSmrg	    done
9215698f425bSmrg	  else
9216698f425bSmrg	    # Error occurred in the first compile.  Let's try to salvage
9217698f425bSmrg	    # the situation: Compile a separate program for each library.
9218698f425bSmrg	    for i in $deplibs; do
9219698f425bSmrg	      case $i in
9220698f425bSmrg	      -l*)
9221698f425bSmrg		func_stripname -l '' "$i"
9222698f425bSmrg		name=$func_stripname_result
9223698f425bSmrg		$opt_dry_run || $RM conftest
9224698f425bSmrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9225698f425bSmrg		  ldd_output=`ldd conftest`
9226a3129944Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9227698f425bSmrg		    case " $predeps $postdeps " in
9228698f425bSmrg		    *" $i "*)
92299ef0b394Smrg		      func_append newdeplibs " $i"
9230a3129944Smrg		      i=
9231698f425bSmrg		      ;;
9232698f425bSmrg		    esac
9233698f425bSmrg		  fi
9234a3129944Smrg		  if test -n "$i"; then
9235698f425bSmrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9236698f425bSmrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9237698f425bSmrg		    set dummy $deplib_matches; shift
9238698f425bSmrg		    deplib_match=$1
9239a3129944Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
92409ef0b394Smrg		      func_append newdeplibs " $i"
9241698f425bSmrg		    else
9242698f425bSmrg		      droppeddeps=yes
92439ef0b394Smrg		      echo
9244698f425bSmrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
92459ef0b394Smrg		      echo "*** I have the capability to make that library automatically link in when"
92469ef0b394Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
92479ef0b394Smrg		      echo "*** shared version of the library, which you do not appear to have"
92489ef0b394Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
92499ef0b394Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9250698f425bSmrg		    fi
9251698f425bSmrg		  fi
9252698f425bSmrg		else
9253698f425bSmrg		  droppeddeps=yes
92549ef0b394Smrg		  echo
9255698f425bSmrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
92569ef0b394Smrg		  echo "*** make it link in!  You will probably need to install it or some"
92579ef0b394Smrg		  echo "*** library that it depends on before this library will be fully"
92589ef0b394Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9259698f425bSmrg		fi
9260698f425bSmrg		;;
9261698f425bSmrg	      *)
92629ef0b394Smrg		func_append newdeplibs " $i"
9263698f425bSmrg		;;
9264698f425bSmrg	      esac
9265698f425bSmrg	    done
9266698f425bSmrg	  fi
9267698f425bSmrg	  ;;
9268698f425bSmrg	file_magic*)
9269698f425bSmrg	  set dummy $deplibs_check_method; shift
9270698f425bSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9271698f425bSmrg	  for a_deplib in $deplibs; do
9272698f425bSmrg	    case $a_deplib in
9273698f425bSmrg	    -l*)
9274698f425bSmrg	      func_stripname -l '' "$a_deplib"
9275698f425bSmrg	      name=$func_stripname_result
9276a3129944Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9277698f425bSmrg		case " $predeps $postdeps " in
9278698f425bSmrg		*" $a_deplib "*)
92799ef0b394Smrg		  func_append newdeplibs " $a_deplib"
9280a3129944Smrg		  a_deplib=
9281698f425bSmrg		  ;;
9282698f425bSmrg		esac
9283698f425bSmrg	      fi
9284a3129944Smrg	      if test -n "$a_deplib"; then
9285698f425bSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
92869ef0b394Smrg		if test -n "$file_magic_glob"; then
92879ef0b394Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
92889ef0b394Smrg		else
92899ef0b394Smrg		  libnameglob=$libname
92909ef0b394Smrg		fi
9291a3129944Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9292698f425bSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9293a3129944Smrg		  if test yes = "$want_nocaseglob"; then
92949ef0b394Smrg		    shopt -s nocaseglob
92959ef0b394Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
92969ef0b394Smrg		    $nocaseglob
92979ef0b394Smrg		  else
92989ef0b394Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
92999ef0b394Smrg		  fi
9300698f425bSmrg		  for potent_lib in $potential_libs; do
9301698f425bSmrg		      # Follow soft links.
9302698f425bSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9303698f425bSmrg			 $GREP " -> " >/dev/null; then
9304698f425bSmrg			continue
9305698f425bSmrg		      fi
9306698f425bSmrg		      # The statement above tries to avoid entering an
9307698f425bSmrg		      # endless loop below, in case of cyclic links.
9308698f425bSmrg		      # We might still enter an endless loop, since a link
9309698f425bSmrg		      # loop can be closed while we follow links,
9310698f425bSmrg		      # but so what?
9311a3129944Smrg		      potlib=$potent_lib
9312698f425bSmrg		      while test -h "$potlib" 2>/dev/null; do
9313a3129944Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9314698f425bSmrg			case $potliblink in
9315a3129944Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9316a3129944Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9317698f425bSmrg			esac
9318698f425bSmrg		      done
9319698f425bSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9320698f425bSmrg			 $SED -e 10q |
9321698f425bSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
93229ef0b394Smrg			func_append newdeplibs " $a_deplib"
9323a3129944Smrg			a_deplib=
9324698f425bSmrg			break 2
9325698f425bSmrg		      fi
9326698f425bSmrg		  done
9327698f425bSmrg		done
9328698f425bSmrg	      fi
9329a3129944Smrg	      if test -n "$a_deplib"; then
9330698f425bSmrg		droppeddeps=yes
93319ef0b394Smrg		echo
9332698f425bSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
93339ef0b394Smrg		echo "*** I have the capability to make that library automatically link in when"
93349ef0b394Smrg		echo "*** you link to this library.  But I can only do this if you have a"
93359ef0b394Smrg		echo "*** shared version of the library, which you do not appear to have"
93369ef0b394Smrg		echo "*** because I did check the linker path looking for a file starting"
9337a3129944Smrg		if test -z "$potlib"; then
9338698f425bSmrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9339698f425bSmrg		else
9340698f425bSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9341698f425bSmrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9342698f425bSmrg		fi
9343698f425bSmrg	      fi
9344698f425bSmrg	      ;;
9345698f425bSmrg	    *)
9346698f425bSmrg	      # Add a -L argument.
93479ef0b394Smrg	      func_append newdeplibs " $a_deplib"
9348698f425bSmrg	      ;;
9349698f425bSmrg	    esac
9350698f425bSmrg	  done # Gone through all deplibs.
9351698f425bSmrg	  ;;
9352698f425bSmrg	match_pattern*)
9353698f425bSmrg	  set dummy $deplibs_check_method; shift
9354698f425bSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9355698f425bSmrg	  for a_deplib in $deplibs; do
9356698f425bSmrg	    case $a_deplib in
9357698f425bSmrg	    -l*)
9358698f425bSmrg	      func_stripname -l '' "$a_deplib"
9359698f425bSmrg	      name=$func_stripname_result
9360a3129944Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9361698f425bSmrg		case " $predeps $postdeps " in
9362698f425bSmrg		*" $a_deplib "*)
93639ef0b394Smrg		  func_append newdeplibs " $a_deplib"
9364a3129944Smrg		  a_deplib=
9365698f425bSmrg		  ;;
9366698f425bSmrg		esac
9367698f425bSmrg	      fi
9368a3129944Smrg	      if test -n "$a_deplib"; then
9369698f425bSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9370698f425bSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9371698f425bSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9372698f425bSmrg		  for potent_lib in $potential_libs; do
9373a3129944Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
93749ef0b394Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9375698f425bSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
93769ef0b394Smrg		      func_append newdeplibs " $a_deplib"
9377a3129944Smrg		      a_deplib=
9378698f425bSmrg		      break 2
9379698f425bSmrg		    fi
9380698f425bSmrg		  done
9381698f425bSmrg		done
9382698f425bSmrg	      fi
9383a3129944Smrg	      if test -n "$a_deplib"; then
9384698f425bSmrg		droppeddeps=yes
93859ef0b394Smrg		echo
9386698f425bSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
93879ef0b394Smrg		echo "*** I have the capability to make that library automatically link in when"
93889ef0b394Smrg		echo "*** you link to this library.  But I can only do this if you have a"
93899ef0b394Smrg		echo "*** shared version of the library, which you do not appear to have"
93909ef0b394Smrg		echo "*** because I did check the linker path looking for a file starting"
9391a3129944Smrg		if test -z "$potlib"; then
9392698f425bSmrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9393698f425bSmrg		else
9394698f425bSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9395698f425bSmrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9396698f425bSmrg		fi
9397698f425bSmrg	      fi
9398698f425bSmrg	      ;;
9399698f425bSmrg	    *)
9400698f425bSmrg	      # Add a -L argument.
94019ef0b394Smrg	      func_append newdeplibs " $a_deplib"
9402698f425bSmrg	      ;;
9403698f425bSmrg	    esac
9404698f425bSmrg	  done # Gone through all deplibs.
9405698f425bSmrg	  ;;
9406698f425bSmrg	none | unknown | *)
9407a3129944Smrg	  newdeplibs=
94089ef0b394Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9409a3129944Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9410a3129944Smrg	    for i in $predeps $postdeps; do
9411698f425bSmrg	      # can't use Xsed below, because $i might contain '/'
9412a3129944Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9413698f425bSmrg	    done
9414698f425bSmrg	  fi
94159ef0b394Smrg	  case $tmp_deplibs in
94169ef0b394Smrg	  *[!\	\ ]*)
94179ef0b394Smrg	    echo
9418a3129944Smrg	    if test none = "$deplibs_check_method"; then
94199ef0b394Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9420698f425bSmrg	    else
94219ef0b394Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9422698f425bSmrg	    fi
94239ef0b394Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9424698f425bSmrg	    droppeddeps=yes
94259ef0b394Smrg	    ;;
94269ef0b394Smrg	  esac
9427698f425bSmrg	  ;;
9428698f425bSmrg	esac
9429698f425bSmrg	versuffix=$versuffix_save
9430698f425bSmrg	major=$major_save
9431698f425bSmrg	release=$release_save
9432698f425bSmrg	libname=$libname_save
9433698f425bSmrg	name=$name_save
9434698f425bSmrg
9435698f425bSmrg	case $host in
9436698f425bSmrg	*-*-rhapsody* | *-*-darwin1.[012])
9437698f425bSmrg	  # On Rhapsody replace the C library with the System framework
94389ef0b394Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9439698f425bSmrg	  ;;
9440698f425bSmrg	esac
9441698f425bSmrg
9442a3129944Smrg	if test yes = "$droppeddeps"; then
9443a3129944Smrg	  if test yes = "$module"; then
94449ef0b394Smrg	    echo
94459ef0b394Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9446698f425bSmrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
94479ef0b394Smrg	    echo "*** a static module, that should work as long as the dlopening"
94489ef0b394Smrg	    echo "*** application is linked with the -dlopen flag."
9449698f425bSmrg	    if test -z "$global_symbol_pipe"; then
94509ef0b394Smrg	      echo
94519ef0b394Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9452a3129944Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
94539ef0b394Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9454a3129944Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9455698f425bSmrg	    fi
9456a3129944Smrg	    if test no = "$build_old_libs"; then
9457a3129944Smrg	      oldlibs=$output_objdir/$libname.$libext
9458698f425bSmrg	      build_libtool_libs=module
9459698f425bSmrg	      build_old_libs=yes
9460698f425bSmrg	    else
9461698f425bSmrg	      build_libtool_libs=no
9462698f425bSmrg	    fi
9463698f425bSmrg	  else
94649ef0b394Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
94659ef0b394Smrg	    echo "*** automatically added whenever a program is linked with this library"
94669ef0b394Smrg	    echo "*** or is declared to -dlopen it."
9467698f425bSmrg
9468a3129944Smrg	    if test no = "$allow_undefined"; then
94699ef0b394Smrg	      echo
94709ef0b394Smrg	      echo "*** Since this library must not contain undefined symbols,"
94719ef0b394Smrg	      echo "*** because either the platform does not support them or"
94729ef0b394Smrg	      echo "*** it was explicitly requested with -no-undefined,"
94739ef0b394Smrg	      echo "*** libtool will only create a static version of it."
9474a3129944Smrg	      if test no = "$build_old_libs"; then
9475a3129944Smrg		oldlibs=$output_objdir/$libname.$libext
9476698f425bSmrg		build_libtool_libs=module
9477698f425bSmrg		build_old_libs=yes
9478698f425bSmrg	      else
9479698f425bSmrg		build_libtool_libs=no
9480698f425bSmrg	      fi
9481698f425bSmrg	    fi
9482698f425bSmrg	  fi
9483698f425bSmrg	fi
9484698f425bSmrg	# Done checking deplibs!
9485698f425bSmrg	deplibs=$newdeplibs
9486698f425bSmrg      fi
9487698f425bSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9488698f425bSmrg      case $host in
9489698f425bSmrg	*-*-darwin*)
94909ef0b394Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
94919ef0b394Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
94929ef0b394Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9493698f425bSmrg	  ;;
9494698f425bSmrg      esac
9495698f425bSmrg
9496698f425bSmrg      # move library search paths that coincide with paths to not yet
9497698f425bSmrg      # installed libraries to the beginning of the library search list
9498698f425bSmrg      new_libs=
9499698f425bSmrg      for path in $notinst_path; do
9500698f425bSmrg	case " $new_libs " in
9501698f425bSmrg	*" -L$path/$objdir "*) ;;
9502698f425bSmrg	*)
9503698f425bSmrg	  case " $deplibs " in
9504698f425bSmrg	  *" -L$path/$objdir "*)
95059ef0b394Smrg	    func_append new_libs " -L$path/$objdir" ;;
9506698f425bSmrg	  esac
9507698f425bSmrg	  ;;
9508698f425bSmrg	esac
9509698f425bSmrg      done
9510698f425bSmrg      for deplib in $deplibs; do
9511698f425bSmrg	case $deplib in
9512698f425bSmrg	-L*)
9513698f425bSmrg	  case " $new_libs " in
9514698f425bSmrg	  *" $deplib "*) ;;
95159ef0b394Smrg	  *) func_append new_libs " $deplib" ;;
9516698f425bSmrg	  esac
9517698f425bSmrg	  ;;
95189ef0b394Smrg	*) func_append new_libs " $deplib" ;;
9519698f425bSmrg	esac
9520698f425bSmrg      done
9521a3129944Smrg      deplibs=$new_libs
9522698f425bSmrg
9523698f425bSmrg      # All the library-specific variables (install_libdir is set above).
9524698f425bSmrg      library_names=
9525698f425bSmrg      old_library=
9526698f425bSmrg      dlname=
9527698f425bSmrg
9528698f425bSmrg      # Test again, we may have decided not to build it any more
9529a3129944Smrg      if test yes = "$build_libtool_libs"; then
9530a3129944Smrg	# Remove $wl instances when linking with ld.
9531fb5e8d76Smrg	# FIXME: should test the right _cmds variable.
9532fb5e8d76Smrg	case $archive_cmds in
9533fb5e8d76Smrg	  *\$LD\ *) wl= ;;
9534fb5e8d76Smrg        esac
9535a3129944Smrg	if test yes = "$hardcode_into_libs"; then
9536698f425bSmrg	  # Hardcode the library paths
9537698f425bSmrg	  hardcode_libdirs=
9538698f425bSmrg	  dep_rpath=
9539a3129944Smrg	  rpath=$finalize_rpath
9540a3129944Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9541698f425bSmrg	  for libdir in $rpath; do
9542698f425bSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
9543698f425bSmrg	      if test -n "$hardcode_libdir_separator"; then
95449ef0b394Smrg		func_replace_sysroot "$libdir"
95459ef0b394Smrg		libdir=$func_replace_sysroot_result
9546698f425bSmrg		if test -z "$hardcode_libdirs"; then
9547a3129944Smrg		  hardcode_libdirs=$libdir
9548698f425bSmrg		else
9549698f425bSmrg		  # Just accumulate the unique libdirs.
9550698f425bSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9551698f425bSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9552698f425bSmrg		    ;;
9553698f425bSmrg		  *)
95549ef0b394Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9555698f425bSmrg		    ;;
9556698f425bSmrg		  esac
9557698f425bSmrg		fi
9558698f425bSmrg	      else
9559698f425bSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
95609ef0b394Smrg		func_append dep_rpath " $flag"
9561698f425bSmrg	      fi
9562698f425bSmrg	    elif test -n "$runpath_var"; then
9563698f425bSmrg	      case "$perm_rpath " in
9564698f425bSmrg	      *" $libdir "*) ;;
9565fb5e8d76Smrg	      *) func_append perm_rpath " $libdir" ;;
9566698f425bSmrg	      esac
9567698f425bSmrg	    fi
9568698f425bSmrg	  done
9569698f425bSmrg	  # Substitute the hardcoded libdirs into the rpath.
9570698f425bSmrg	  if test -n "$hardcode_libdir_separator" &&
9571698f425bSmrg	     test -n "$hardcode_libdirs"; then
9572a3129944Smrg	    libdir=$hardcode_libdirs
9573fb5e8d76Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9574698f425bSmrg	  fi
9575698f425bSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9576698f425bSmrg	    # We should set the runpath_var.
9577698f425bSmrg	    rpath=
9578698f425bSmrg	    for dir in $perm_rpath; do
95799ef0b394Smrg	      func_append rpath "$dir:"
9580698f425bSmrg	    done
9581698f425bSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9582698f425bSmrg	  fi
9583698f425bSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9584698f425bSmrg	fi
9585266e564dSmrg
9586a3129944Smrg	shlibpath=$finalize_shlibpath
9587a3129944Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9588698f425bSmrg	if test -n "$shlibpath"; then
9589698f425bSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9590698f425bSmrg	fi
9591266e564dSmrg
9592698f425bSmrg	# Get the real and link names of the library.
9593698f425bSmrg	eval shared_ext=\"$shrext_cmds\"
9594698f425bSmrg	eval library_names=\"$library_names_spec\"
9595698f425bSmrg	set dummy $library_names
9596698f425bSmrg	shift
9597a3129944Smrg	realname=$1
9598698f425bSmrg	shift
9599266e564dSmrg
9600698f425bSmrg	if test -n "$soname_spec"; then
9601698f425bSmrg	  eval soname=\"$soname_spec\"
9602698f425bSmrg	else
9603a3129944Smrg	  soname=$realname
9604698f425bSmrg	fi
9605698f425bSmrg	if test -z "$dlname"; then
9606698f425bSmrg	  dlname=$soname
9607698f425bSmrg	fi
9608266e564dSmrg
9609a3129944Smrg	lib=$output_objdir/$realname
9610698f425bSmrg	linknames=
9611698f425bSmrg	for link
9612698f425bSmrg	do
96139ef0b394Smrg	  func_append linknames " $link"
9614698f425bSmrg	done
9615266e564dSmrg
9616698f425bSmrg	# Use standard objects if they are pic
96179ef0b394Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9618698f425bSmrg	test "X$libobjs" = "X " && libobjs=
9619266e564dSmrg
9620698f425bSmrg	delfiles=
9621698f425bSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9622698f425bSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9623a3129944Smrg	  export_symbols=$output_objdir/$libname.uexp
96249ef0b394Smrg	  func_append delfiles " $export_symbols"
9625698f425bSmrg	fi
9626266e564dSmrg
9627698f425bSmrg	orig_export_symbols=
9628698f425bSmrg	case $host_os in
9629698f425bSmrg	cygwin* | mingw* | cegcc*)
9630698f425bSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9631698f425bSmrg	    # exporting using user supplied symfile
9632a3129944Smrg	    func_dll_def_p "$export_symbols" || {
9633698f425bSmrg	      # and it's NOT already a .def file. Must figure out
9634698f425bSmrg	      # which of the given symbols are data symbols and tag
9635698f425bSmrg	      # them as such. So, trigger use of export_symbols_cmds.
9636698f425bSmrg	      # export_symbols gets reassigned inside the "prepare
9637698f425bSmrg	      # the list of exported symbols" if statement, so the
9638698f425bSmrg	      # include_expsyms logic still works.
9639a3129944Smrg	      orig_export_symbols=$export_symbols
9640698f425bSmrg	      export_symbols=
9641698f425bSmrg	      always_export_symbols=yes
9642a3129944Smrg	    }
9643698f425bSmrg	  fi
9644698f425bSmrg	  ;;
9645698f425bSmrg	esac
9646266e564dSmrg
9647698f425bSmrg	# Prepare the list of exported symbols
9648698f425bSmrg	if test -z "$export_symbols"; then
9649a3129944Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9650a3129944Smrg	    func_verbose "generating symbol list for '$libname.la'"
9651a3129944Smrg	    export_symbols=$output_objdir/$libname.exp
9652698f425bSmrg	    $opt_dry_run || $RM $export_symbols
9653698f425bSmrg	    cmds=$export_symbols_cmds
9654a3129944Smrg	    save_ifs=$IFS; IFS='~'
96559ef0b394Smrg	    for cmd1 in $cmds; do
9656a3129944Smrg	      IFS=$save_ifs
96579ef0b394Smrg	      # Take the normal branch if the nm_file_list_spec branch
96589ef0b394Smrg	      # doesn't work or if tool conversion is not needed.
96599ef0b394Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
96609ef0b394Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
96619ef0b394Smrg		  try_normal_branch=yes
96629ef0b394Smrg		  eval cmd=\"$cmd1\"
96639ef0b394Smrg		  func_len " $cmd"
96649ef0b394Smrg		  len=$func_len_result
96659ef0b394Smrg		  ;;
96669ef0b394Smrg		*)
96679ef0b394Smrg		  try_normal_branch=no
96689ef0b394Smrg		  ;;
96699ef0b394Smrg	      esac
9670a3129944Smrg	      if test yes = "$try_normal_branch" \
96719ef0b394Smrg		 && { test "$len" -lt "$max_cmd_len" \
96729ef0b394Smrg		      || test "$max_cmd_len" -le -1; }
96739ef0b394Smrg	      then
96749ef0b394Smrg		func_show_eval "$cmd" 'exit $?'
96759ef0b394Smrg		skipped_export=false
96769ef0b394Smrg	      elif test -n "$nm_file_list_spec"; then
96779ef0b394Smrg		func_basename "$output"
96789ef0b394Smrg		output_la=$func_basename_result
96799ef0b394Smrg		save_libobjs=$libobjs
96809ef0b394Smrg		save_output=$output
9681a3129944Smrg		output=$output_objdir/$output_la.nm
96829ef0b394Smrg		func_to_tool_file "$output"
96839ef0b394Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
96849ef0b394Smrg		func_append delfiles " $output"
96859ef0b394Smrg		func_verbose "creating $NM input file list: $output"
96869ef0b394Smrg		for obj in $save_libobjs; do
96879ef0b394Smrg		  func_to_tool_file "$obj"
96889ef0b394Smrg		  $ECHO "$func_to_tool_file_result"
96899ef0b394Smrg		done > "$output"
96909ef0b394Smrg		eval cmd=\"$cmd1\"
9691698f425bSmrg		func_show_eval "$cmd" 'exit $?'
96929ef0b394Smrg		output=$save_output
96939ef0b394Smrg		libobjs=$save_libobjs
9694698f425bSmrg		skipped_export=false
9695698f425bSmrg	      else
9696698f425bSmrg		# The command line is too long to execute in one step.
9697698f425bSmrg		func_verbose "using reloadable object file for export list..."
9698698f425bSmrg		skipped_export=:
9699698f425bSmrg		# Break out early, otherwise skipped_export may be
9700698f425bSmrg		# set to false by a later but shorter cmd.
9701698f425bSmrg		break
9702698f425bSmrg	      fi
9703698f425bSmrg	    done
9704a3129944Smrg	    IFS=$save_ifs
9705a3129944Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9706698f425bSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9707698f425bSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9708698f425bSmrg	    fi
9709698f425bSmrg	  fi
9710266e564dSmrg	fi
9711266e564dSmrg
9712698f425bSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9713a3129944Smrg	  tmp_export_symbols=$export_symbols
9714a3129944Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
97159ef0b394Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
9716698f425bSmrg	fi
9717266e564dSmrg
9718a3129944Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
9719698f425bSmrg	  # The given exports_symbols file has to be filtered, so filter it.
9720a3129944Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
9721698f425bSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
9722a3129944Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
9723698f425bSmrg	  # though. Also, the filter scales superlinearly with the number of
9724698f425bSmrg	  # global variables. join(1) would be nice here, but unfortunately
9725698f425bSmrg	  # isn't a blessed tool.
9726698f425bSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
97279ef0b394Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
9728698f425bSmrg	  export_symbols=$output_objdir/$libname.def
9729698f425bSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
9730698f425bSmrg	fi
9731266e564dSmrg
9732698f425bSmrg	tmp_deplibs=
9733698f425bSmrg	for test_deplib in $deplibs; do
9734698f425bSmrg	  case " $convenience " in
9735698f425bSmrg	  *" $test_deplib "*) ;;
9736698f425bSmrg	  *)
97379ef0b394Smrg	    func_append tmp_deplibs " $test_deplib"
9738698f425bSmrg	    ;;
9739698f425bSmrg	  esac
9740698f425bSmrg	done
9741a3129944Smrg	deplibs=$tmp_deplibs
9742266e564dSmrg
9743698f425bSmrg	if test -n "$convenience"; then
9744698f425bSmrg	  if test -n "$whole_archive_flag_spec" &&
9745a3129944Smrg	    test yes = "$compiler_needs_object" &&
9746698f425bSmrg	    test -z "$libobjs"; then
9747698f425bSmrg	    # extract the archives, so we have objects to list.
9748698f425bSmrg	    # TODO: could optimize this to just extract one archive.
9749698f425bSmrg	    whole_archive_flag_spec=
9750698f425bSmrg	  fi
9751698f425bSmrg	  if test -n "$whole_archive_flag_spec"; then
9752698f425bSmrg	    save_libobjs=$libobjs
9753698f425bSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
9754698f425bSmrg	    test "X$libobjs" = "X " && libobjs=
9755698f425bSmrg	  else
9756a3129944Smrg	    gentop=$output_objdir/${outputname}x
97579ef0b394Smrg	    func_append generated " $gentop"
9758266e564dSmrg
9759698f425bSmrg	    func_extract_archives $gentop $convenience
97609ef0b394Smrg	    func_append libobjs " $func_extract_archives_result"
9761698f425bSmrg	    test "X$libobjs" = "X " && libobjs=
9762698f425bSmrg	  fi
9763266e564dSmrg	fi
9764266e564dSmrg
9765a3129944Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
9766698f425bSmrg	  eval flag=\"$thread_safe_flag_spec\"
97679ef0b394Smrg	  func_append linker_flags " $flag"
9768266e564dSmrg	fi
9769266e564dSmrg
9770698f425bSmrg	# Make a backup of the uninstalled library when relinking
9771a3129944Smrg	if test relink = "$opt_mode"; then
9772698f425bSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
9773698f425bSmrg	fi
9774266e564dSmrg
9775698f425bSmrg	# Do each of the archive commands.
9776a3129944Smrg	if test yes = "$module" && test -n "$module_cmds"; then
9777698f425bSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
9778698f425bSmrg	    eval test_cmds=\"$module_expsym_cmds\"
9779698f425bSmrg	    cmds=$module_expsym_cmds
9780698f425bSmrg	  else
9781698f425bSmrg	    eval test_cmds=\"$module_cmds\"
9782698f425bSmrg	    cmds=$module_cmds
9783698f425bSmrg	  fi
9784266e564dSmrg	else
9785698f425bSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
9786698f425bSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
9787698f425bSmrg	    cmds=$archive_expsym_cmds
9788698f425bSmrg	  else
9789698f425bSmrg	    eval test_cmds=\"$archive_cmds\"
9790698f425bSmrg	    cmds=$archive_cmds
9791698f425bSmrg	  fi
9792266e564dSmrg	fi
9793266e564dSmrg
9794a3129944Smrg	if test : != "$skipped_export" &&
9795698f425bSmrg	   func_len " $test_cmds" &&
9796698f425bSmrg	   len=$func_len_result &&
9797698f425bSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
9798698f425bSmrg	  :
9799698f425bSmrg	else
9800698f425bSmrg	  # The command line is too long to link in one step, link piecewise
9801698f425bSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
9802698f425bSmrg	  # script.
9803266e564dSmrg
9804698f425bSmrg	  # Save the value of $output and $libobjs because we want to
9805698f425bSmrg	  # use them later.  If we have whole_archive_flag_spec, we
9806698f425bSmrg	  # want to use save_libobjs as it was before
9807698f425bSmrg	  # whole_archive_flag_spec was expanded, because we can't
9808698f425bSmrg	  # assume the linker understands whole_archive_flag_spec.
9809698f425bSmrg	  # This may have to be revisited, in case too many
9810698f425bSmrg	  # convenience libraries get linked in and end up exceeding
9811698f425bSmrg	  # the spec.
9812698f425bSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
9813698f425bSmrg	    save_libobjs=$libobjs
9814698f425bSmrg	  fi
9815698f425bSmrg	  save_output=$output
98169ef0b394Smrg	  func_basename "$output"
98179ef0b394Smrg	  output_la=$func_basename_result
9818266e564dSmrg
9819698f425bSmrg	  # Clear the reloadable object creation command queue and
9820698f425bSmrg	  # initialize k to one.
9821698f425bSmrg	  test_cmds=
9822698f425bSmrg	  concat_cmds=
9823698f425bSmrg	  objlist=
9824698f425bSmrg	  last_robj=
9825698f425bSmrg	  k=1
9826698f425bSmrg
9827a3129944Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
9828a3129944Smrg	    output=$output_objdir/$output_la.lnkscript
9829698f425bSmrg	    func_verbose "creating GNU ld script: $output"
98309ef0b394Smrg	    echo 'INPUT (' > $output
9831698f425bSmrg	    for obj in $save_libobjs
9832266e564dSmrg	    do
98339ef0b394Smrg	      func_to_tool_file "$obj"
98349ef0b394Smrg	      $ECHO "$func_to_tool_file_result" >> $output
9835698f425bSmrg	    done
98369ef0b394Smrg	    echo ')' >> $output
98379ef0b394Smrg	    func_append delfiles " $output"
98389ef0b394Smrg	    func_to_tool_file "$output"
98399ef0b394Smrg	    output=$func_to_tool_file_result
9840a3129944Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
9841a3129944Smrg	    output=$output_objdir/$output_la.lnk
9842698f425bSmrg	    func_verbose "creating linker input file list: $output"
9843698f425bSmrg	    : > $output
9844698f425bSmrg	    set x $save_libobjs
9845698f425bSmrg	    shift
9846698f425bSmrg	    firstobj=
9847a3129944Smrg	    if test yes = "$compiler_needs_object"; then
9848698f425bSmrg	      firstobj="$1 "
9849698f425bSmrg	      shift
9850698f425bSmrg	    fi
9851698f425bSmrg	    for obj
9852698f425bSmrg	    do
98539ef0b394Smrg	      func_to_tool_file "$obj"
98549ef0b394Smrg	      $ECHO "$func_to_tool_file_result" >> $output
9855698f425bSmrg	    done
98569ef0b394Smrg	    func_append delfiles " $output"
98579ef0b394Smrg	    func_to_tool_file "$output"
98589ef0b394Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
9859698f425bSmrg	  else
9860698f425bSmrg	    if test -n "$save_libobjs"; then
9861698f425bSmrg	      func_verbose "creating reloadable object files..."
9862a3129944Smrg	      output=$output_objdir/$output_la-$k.$objext
9863698f425bSmrg	      eval test_cmds=\"$reload_cmds\"
9864698f425bSmrg	      func_len " $test_cmds"
9865698f425bSmrg	      len0=$func_len_result
9866698f425bSmrg	      len=$len0
9867698f425bSmrg
9868698f425bSmrg	      # Loop over the list of objects to be linked.
9869698f425bSmrg	      for obj in $save_libobjs
9870698f425bSmrg	      do
9871698f425bSmrg		func_len " $obj"
9872698f425bSmrg		func_arith $len + $func_len_result
9873698f425bSmrg		len=$func_arith_result
9874a3129944Smrg		if test -z "$objlist" ||
9875698f425bSmrg		   test "$len" -lt "$max_cmd_len"; then
9876698f425bSmrg		  func_append objlist " $obj"
9877698f425bSmrg		else
9878698f425bSmrg		  # The command $test_cmds is almost too long, add a
9879698f425bSmrg		  # command to the queue.
9880a3129944Smrg		  if test 1 -eq "$k"; then
9881698f425bSmrg		    # The first file doesn't have a previous command to add.
98829ef0b394Smrg		    reload_objs=$objlist
98839ef0b394Smrg		    eval concat_cmds=\"$reload_cmds\"
9884698f425bSmrg		  else
9885698f425bSmrg		    # All subsequent reloadable object files will link in
9886698f425bSmrg		    # the last one created.
98879ef0b394Smrg		    reload_objs="$objlist $last_robj"
98889ef0b394Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
9889698f425bSmrg		  fi
9890a3129944Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
9891698f425bSmrg		  func_arith $k + 1
9892698f425bSmrg		  k=$func_arith_result
9893a3129944Smrg		  output=$output_objdir/$output_la-$k.$objext
98949ef0b394Smrg		  objlist=" $obj"
9895698f425bSmrg		  func_len " $last_robj"
9896698f425bSmrg		  func_arith $len0 + $func_len_result
9897698f425bSmrg		  len=$func_arith_result
9898698f425bSmrg		fi
9899698f425bSmrg	      done
9900698f425bSmrg	      # Handle the remaining objects by creating one last
9901698f425bSmrg	      # reloadable object file.  All subsequent reloadable object
9902698f425bSmrg	      # files will link in the last one created.
9903698f425bSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
99049ef0b394Smrg	      reload_objs="$objlist $last_robj"
9905a3129944Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
9906698f425bSmrg	      if test -n "$last_robj"; then
9907a3129944Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
9908698f425bSmrg	      fi
99099ef0b394Smrg	      func_append delfiles " $output"
9910266e564dSmrg
9911698f425bSmrg	    else
9912698f425bSmrg	      output=
9913698f425bSmrg	    fi
9914266e564dSmrg
9915a3129944Smrg	    ${skipped_export-false} && {
9916a3129944Smrg	      func_verbose "generating symbol list for '$libname.la'"
9917a3129944Smrg	      export_symbols=$output_objdir/$libname.exp
9918698f425bSmrg	      $opt_dry_run || $RM $export_symbols
9919698f425bSmrg	      libobjs=$output
9920698f425bSmrg	      # Append the command to create the export file.
9921698f425bSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
9922698f425bSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
9923698f425bSmrg	      if test -n "$last_robj"; then
9924698f425bSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
9925698f425bSmrg	      fi
9926a3129944Smrg	    }
9927266e564dSmrg
9928698f425bSmrg	    test -n "$save_libobjs" &&
9929698f425bSmrg	      func_verbose "creating a temporary reloadable object file: $output"
9930266e564dSmrg
9931698f425bSmrg	    # Loop through the commands generated above and execute them.
9932a3129944Smrg	    save_ifs=$IFS; IFS='~'
9933698f425bSmrg	    for cmd in $concat_cmds; do
9934a3129944Smrg	      IFS=$save_ifs
9935a3129944Smrg	      $opt_quiet || {
9936698f425bSmrg		  func_quote_for_expand "$cmd"
9937698f425bSmrg		  eval "func_echo $func_quote_for_expand_result"
9938698f425bSmrg	      }
9939698f425bSmrg	      $opt_dry_run || eval "$cmd" || {
9940698f425bSmrg		lt_exit=$?
9941698f425bSmrg
9942698f425bSmrg		# Restore the uninstalled library and exit
9943a3129944Smrg		if test relink = "$opt_mode"; then
9944698f425bSmrg		  ( cd "$output_objdir" && \
9945698f425bSmrg		    $RM "${realname}T" && \
9946698f425bSmrg		    $MV "${realname}U" "$realname" )
9947698f425bSmrg		fi
9948266e564dSmrg
9949698f425bSmrg		exit $lt_exit
9950698f425bSmrg	      }
9951698f425bSmrg	    done
9952a3129944Smrg	    IFS=$save_ifs
9953266e564dSmrg
9954698f425bSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
9955698f425bSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9956698f425bSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9957266e564dSmrg	    fi
9958266e564dSmrg	  fi
9959266e564dSmrg
9960a3129944Smrg          ${skipped_export-false} && {
9961698f425bSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
9962a3129944Smrg	      tmp_export_symbols=$export_symbols
9963a3129944Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
99649ef0b394Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
9965698f425bSmrg	    fi
9966266e564dSmrg
9967698f425bSmrg	    if test -n "$orig_export_symbols"; then
9968698f425bSmrg	      # The given exports_symbols file has to be filtered, so filter it.
9969a3129944Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
9970698f425bSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
9971a3129944Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
9972698f425bSmrg	      # though. Also, the filter scales superlinearly with the number of
9973698f425bSmrg	      # global variables. join(1) would be nice here, but unfortunately
9974698f425bSmrg	      # isn't a blessed tool.
9975698f425bSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
99769ef0b394Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
9977698f425bSmrg	      export_symbols=$output_objdir/$libname.def
9978698f425bSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
9979698f425bSmrg	    fi
9980a3129944Smrg	  }
9981266e564dSmrg
9982698f425bSmrg	  libobjs=$output
9983698f425bSmrg	  # Restore the value of output.
9984698f425bSmrg	  output=$save_output
9985266e564dSmrg
9986698f425bSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
9987698f425bSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
9988698f425bSmrg	    test "X$libobjs" = "X " && libobjs=
9989698f425bSmrg	  fi
9990698f425bSmrg	  # Expand the library linking commands again to reset the
9991698f425bSmrg	  # value of $libobjs for piecewise linking.
9992266e564dSmrg
9993698f425bSmrg	  # Do each of the archive commands.
9994a3129944Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
9995698f425bSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
9996698f425bSmrg	      cmds=$module_expsym_cmds
9997698f425bSmrg	    else
9998698f425bSmrg	      cmds=$module_cmds
9999266e564dSmrg	    fi
10000266e564dSmrg	  else
10001698f425bSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10002698f425bSmrg	      cmds=$archive_expsym_cmds
10003698f425bSmrg	    else
10004698f425bSmrg	      cmds=$archive_cmds
10005698f425bSmrg	    fi
10006266e564dSmrg	  fi
10007698f425bSmrg	fi
10008266e564dSmrg
10009698f425bSmrg	if test -n "$delfiles"; then
10010698f425bSmrg	  # Append the command to remove temporary files to $cmds.
10011698f425bSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10012698f425bSmrg	fi
10013266e564dSmrg
10014698f425bSmrg	# Add any objects from preloaded convenience libraries
10015698f425bSmrg	if test -n "$dlprefiles"; then
10016a3129944Smrg	  gentop=$output_objdir/${outputname}x
100179ef0b394Smrg	  func_append generated " $gentop"
10018266e564dSmrg
10019698f425bSmrg	  func_extract_archives $gentop $dlprefiles
100209ef0b394Smrg	  func_append libobjs " $func_extract_archives_result"
10021698f425bSmrg	  test "X$libobjs" = "X " && libobjs=
10022698f425bSmrg	fi
10023266e564dSmrg
10024a3129944Smrg	save_ifs=$IFS; IFS='~'
10025698f425bSmrg	for cmd in $cmds; do
10026a3129944Smrg	  IFS=$sp$nl
10027698f425bSmrg	  eval cmd=\"$cmd\"
10028a3129944Smrg	  IFS=$save_ifs
10029a3129944Smrg	  $opt_quiet || {
10030698f425bSmrg	    func_quote_for_expand "$cmd"
10031698f425bSmrg	    eval "func_echo $func_quote_for_expand_result"
10032698f425bSmrg	  }
10033698f425bSmrg	  $opt_dry_run || eval "$cmd" || {
10034698f425bSmrg	    lt_exit=$?
10035266e564dSmrg
10036698f425bSmrg	    # Restore the uninstalled library and exit
10037a3129944Smrg	    if test relink = "$opt_mode"; then
10038698f425bSmrg	      ( cd "$output_objdir" && \
10039698f425bSmrg	        $RM "${realname}T" && \
10040698f425bSmrg		$MV "${realname}U" "$realname" )
10041698f425bSmrg	    fi
10042266e564dSmrg
10043698f425bSmrg	    exit $lt_exit
10044698f425bSmrg	  }
10045698f425bSmrg	done
10046a3129944Smrg	IFS=$save_ifs
10047266e564dSmrg
10048698f425bSmrg	# Restore the uninstalled library and exit
10049a3129944Smrg	if test relink = "$opt_mode"; then
10050698f425bSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10051266e564dSmrg
10052698f425bSmrg	  if test -n "$convenience"; then
10053698f425bSmrg	    if test -z "$whole_archive_flag_spec"; then
10054698f425bSmrg	      func_show_eval '${RM}r "$gentop"'
10055698f425bSmrg	    fi
10056698f425bSmrg	  fi
10057266e564dSmrg
10058698f425bSmrg	  exit $EXIT_SUCCESS
10059698f425bSmrg	fi
10060698f425bSmrg
10061698f425bSmrg	# Create links to the real library.
10062698f425bSmrg	for linkname in $linknames; do
10063698f425bSmrg	  if test "$realname" != "$linkname"; then
10064698f425bSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10065266e564dSmrg	  fi
10066266e564dSmrg	done
10067266e564dSmrg
10068698f425bSmrg	# If -module or -export-dynamic was specified, set the dlname.
10069a3129944Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10070698f425bSmrg	  # On all known operating systems, these are identical.
10071a3129944Smrg	  dlname=$soname
10072698f425bSmrg	fi
10073698f425bSmrg      fi
10074266e564dSmrg      ;;
10075266e564dSmrg
10076698f425bSmrg    obj)
10077a3129944Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10078a3129944Smrg	func_warning "'-dlopen' is ignored for objects"
10079698f425bSmrg      fi
10080266e564dSmrg
10081698f425bSmrg      case " $deplibs" in
10082698f425bSmrg      *\ -l* | *\ -L*)
10083a3129944Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10084266e564dSmrg      esac
10085266e564dSmrg
10086698f425bSmrg      test -n "$rpath" && \
10087a3129944Smrg	func_warning "'-rpath' is ignored for objects"
10088698f425bSmrg
10089698f425bSmrg      test -n "$xrpath" && \
10090a3129944Smrg	func_warning "'-R' is ignored for objects"
10091266e564dSmrg
10092698f425bSmrg      test -n "$vinfo" && \
10093a3129944Smrg	func_warning "'-version-info' is ignored for objects"
10094266e564dSmrg
10095698f425bSmrg      test -n "$release" && \
10096a3129944Smrg	func_warning "'-release' is ignored for objects"
10097698f425bSmrg
10098698f425bSmrg      case $output in
10099698f425bSmrg      *.lo)
10100698f425bSmrg	test -n "$objs$old_deplibs" && \
10101a3129944Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10102698f425bSmrg
10103698f425bSmrg	libobj=$output
10104698f425bSmrg	func_lo2o "$libobj"
10105698f425bSmrg	obj=$func_lo2o_result
10106266e564dSmrg	;;
10107266e564dSmrg      *)
10108698f425bSmrg	libobj=
10109a3129944Smrg	obj=$output
10110266e564dSmrg	;;
10111266e564dSmrg      esac
10112266e564dSmrg
10113698f425bSmrg      # Delete the old objects.
10114698f425bSmrg      $opt_dry_run || $RM $obj $libobj
10115266e564dSmrg
10116698f425bSmrg      # Objects from convenience libraries.  This assumes
10117698f425bSmrg      # single-version convenience libraries.  Whenever we create
10118698f425bSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10119698f425bSmrg      # the extraction.
10120698f425bSmrg      reload_conv_objs=
10121698f425bSmrg      gentop=
10122a3129944Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10123a3129944Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10124a3129944Smrg      # into space.
10125a3129944Smrg      case $reload_cmds in
10126a3129944Smrg        *\$LD[\ \$]*) wl= ;;
10127a3129944Smrg      esac
10128698f425bSmrg      if test -n "$convenience"; then
10129698f425bSmrg	if test -n "$whole_archive_flag_spec"; then
10130698f425bSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10131a3129944Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10132a3129944Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10133698f425bSmrg	else
10134a3129944Smrg	  gentop=$output_objdir/${obj}x
101359ef0b394Smrg	  func_append generated " $gentop"
10136266e564dSmrg
10137698f425bSmrg	  func_extract_archives $gentop $convenience
10138698f425bSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10139698f425bSmrg	fi
10140266e564dSmrg      fi
10141266e564dSmrg
101429ef0b394Smrg      # If we're not building shared, we need to use non_pic_objs
10143a3129944Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
101449ef0b394Smrg
10145698f425bSmrg      # Create the old-style object.
10146a3129944Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10147266e564dSmrg
10148a3129944Smrg      output=$obj
10149698f425bSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10150266e564dSmrg
10151698f425bSmrg      # Exit if we aren't doing a library object file.
10152698f425bSmrg      if test -z "$libobj"; then
10153698f425bSmrg	if test -n "$gentop"; then
10154698f425bSmrg	  func_show_eval '${RM}r "$gentop"'
10155698f425bSmrg	fi
10156698f425bSmrg
10157698f425bSmrg	exit $EXIT_SUCCESS
10158266e564dSmrg      fi
10159698f425bSmrg
10160a3129944Smrg      test yes = "$build_libtool_libs" || {
10161698f425bSmrg	if test -n "$gentop"; then
10162698f425bSmrg	  func_show_eval '${RM}r "$gentop"'
10163698f425bSmrg	fi
10164698f425bSmrg
10165698f425bSmrg	# Create an invalid libtool object if no PIC, so that we don't
10166698f425bSmrg	# accidentally link it into a program.
10167698f425bSmrg	# $show "echo timestamp > $libobj"
10168698f425bSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10169698f425bSmrg	exit $EXIT_SUCCESS
10170a3129944Smrg      }
10171698f425bSmrg
10172a3129944Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10173698f425bSmrg	# Only do commands if we really have different PIC objects.
10174698f425bSmrg	reload_objs="$libobjs $reload_conv_objs"
10175a3129944Smrg	output=$libobj
10176698f425bSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
10177698f425bSmrg      fi
10178698f425bSmrg
10179698f425bSmrg      if test -n "$gentop"; then
10180698f425bSmrg	func_show_eval '${RM}r "$gentop"'
10181698f425bSmrg      fi
10182698f425bSmrg
10183698f425bSmrg      exit $EXIT_SUCCESS
10184266e564dSmrg      ;;
10185266e564dSmrg
10186698f425bSmrg    prog)
10187698f425bSmrg      case $host in
10188698f425bSmrg	*cygwin*) func_stripname '' '.exe' "$output"
10189698f425bSmrg	          output=$func_stripname_result.exe;;
10190698f425bSmrg      esac
10191698f425bSmrg      test -n "$vinfo" && \
10192a3129944Smrg	func_warning "'-version-info' is ignored for programs"
10193266e564dSmrg
10194698f425bSmrg      test -n "$release" && \
10195a3129944Smrg	func_warning "'-release' is ignored for programs"
10196266e564dSmrg
10197a3129944Smrg      $preload \
10198a3129944Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10199a3129944Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10200698f425bSmrg
10201698f425bSmrg      case $host in
10202698f425bSmrg      *-*-rhapsody* | *-*-darwin1.[012])
10203698f425bSmrg	# On Rhapsody replace the C library is the System framework
102049ef0b394Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
102059ef0b394Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10206266e564dSmrg	;;
10207698f425bSmrg      esac
10208266e564dSmrg
10209698f425bSmrg      case $host in
10210698f425bSmrg      *-*-darwin*)
10211698f425bSmrg	# Don't allow lazy linking, it breaks C++ global constructors
10212698f425bSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10213a3129944Smrg	if test CXX = "$tagname"; then
10214698f425bSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10215698f425bSmrg	    10.[0123])
10216a3129944Smrg	      func_append compile_command " $wl-bind_at_load"
10217a3129944Smrg	      func_append finalize_command " $wl-bind_at_load"
10218698f425bSmrg	    ;;
10219698f425bSmrg	  esac
10220266e564dSmrg	fi
10221698f425bSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
102229ef0b394Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
102239ef0b394Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10224698f425bSmrg	;;
10225698f425bSmrg      esac
10226266e564dSmrg
10227266e564dSmrg
10228698f425bSmrg      # move library search paths that coincide with paths to not yet
10229698f425bSmrg      # installed libraries to the beginning of the library search list
10230698f425bSmrg      new_libs=
10231698f425bSmrg      for path in $notinst_path; do
10232698f425bSmrg	case " $new_libs " in
10233698f425bSmrg	*" -L$path/$objdir "*) ;;
10234698f425bSmrg	*)
10235698f425bSmrg	  case " $compile_deplibs " in
10236698f425bSmrg	  *" -L$path/$objdir "*)
102379ef0b394Smrg	    func_append new_libs " -L$path/$objdir" ;;
10238266e564dSmrg	  esac
10239698f425bSmrg	  ;;
10240698f425bSmrg	esac
10241698f425bSmrg      done
10242698f425bSmrg      for deplib in $compile_deplibs; do
10243698f425bSmrg	case $deplib in
10244698f425bSmrg	-L*)
10245698f425bSmrg	  case " $new_libs " in
10246698f425bSmrg	  *" $deplib "*) ;;
102479ef0b394Smrg	  *) func_append new_libs " $deplib" ;;
10248266e564dSmrg	  esac
10249698f425bSmrg	  ;;
102509ef0b394Smrg	*) func_append new_libs " $deplib" ;;
10251698f425bSmrg	esac
10252698f425bSmrg      done
10253a3129944Smrg      compile_deplibs=$new_libs
10254266e564dSmrg
10255266e564dSmrg
102569ef0b394Smrg      func_append compile_command " $compile_deplibs"
102579ef0b394Smrg      func_append finalize_command " $finalize_deplibs"
10258266e564dSmrg
10259698f425bSmrg      if test -n "$rpath$xrpath"; then
10260698f425bSmrg	# If the user specified any rpath flags, then add them.
10261698f425bSmrg	for libdir in $rpath $xrpath; do
10262698f425bSmrg	  # This is the magic to use -rpath.
10263698f425bSmrg	  case "$finalize_rpath " in
10264698f425bSmrg	  *" $libdir "*) ;;
102659ef0b394Smrg	  *) func_append finalize_rpath " $libdir" ;;
10266698f425bSmrg	  esac
10267698f425bSmrg	done
10268698f425bSmrg      fi
10269266e564dSmrg
10270698f425bSmrg      # Now hardcode the library paths
10271698f425bSmrg      rpath=
10272698f425bSmrg      hardcode_libdirs=
10273698f425bSmrg      for libdir in $compile_rpath $finalize_rpath; do
10274698f425bSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10275698f425bSmrg	  if test -n "$hardcode_libdir_separator"; then
10276698f425bSmrg	    if test -z "$hardcode_libdirs"; then
10277a3129944Smrg	      hardcode_libdirs=$libdir
10278698f425bSmrg	    else
10279698f425bSmrg	      # Just accumulate the unique libdirs.
10280698f425bSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10281698f425bSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10282698f425bSmrg		;;
10283698f425bSmrg	      *)
102849ef0b394Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10285698f425bSmrg		;;
10286698f425bSmrg	      esac
10287698f425bSmrg	    fi
10288266e564dSmrg	  else
10289698f425bSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
102909ef0b394Smrg	    func_append rpath " $flag"
10291266e564dSmrg	  fi
10292698f425bSmrg	elif test -n "$runpath_var"; then
10293698f425bSmrg	  case "$perm_rpath " in
10294698f425bSmrg	  *" $libdir "*) ;;
102959ef0b394Smrg	  *) func_append perm_rpath " $libdir" ;;
10296698f425bSmrg	  esac
10297698f425bSmrg	fi
10298698f425bSmrg	case $host in
10299698f425bSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10300a3129944Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10301698f425bSmrg	  case :$dllsearchpath: in
10302698f425bSmrg	  *":$libdir:"*) ;;
10303698f425bSmrg	  ::) dllsearchpath=$libdir;;
103049ef0b394Smrg	  *) func_append dllsearchpath ":$libdir";;
10305698f425bSmrg	  esac
10306698f425bSmrg	  case :$dllsearchpath: in
10307698f425bSmrg	  *":$testbindir:"*) ;;
10308698f425bSmrg	  ::) dllsearchpath=$testbindir;;
103099ef0b394Smrg	  *) func_append dllsearchpath ":$testbindir";;
10310698f425bSmrg	  esac
10311698f425bSmrg	  ;;
10312698f425bSmrg	esac
10313698f425bSmrg      done
10314698f425bSmrg      # Substitute the hardcoded libdirs into the rpath.
10315698f425bSmrg      if test -n "$hardcode_libdir_separator" &&
10316698f425bSmrg	 test -n "$hardcode_libdirs"; then
10317a3129944Smrg	libdir=$hardcode_libdirs
10318698f425bSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10319698f425bSmrg      fi
10320a3129944Smrg      compile_rpath=$rpath
10321266e564dSmrg
10322698f425bSmrg      rpath=
10323698f425bSmrg      hardcode_libdirs=
10324698f425bSmrg      for libdir in $finalize_rpath; do
10325698f425bSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10326698f425bSmrg	  if test -n "$hardcode_libdir_separator"; then
10327698f425bSmrg	    if test -z "$hardcode_libdirs"; then
10328a3129944Smrg	      hardcode_libdirs=$libdir
10329698f425bSmrg	    else
10330698f425bSmrg	      # Just accumulate the unique libdirs.
10331698f425bSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10332698f425bSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10333698f425bSmrg		;;
10334698f425bSmrg	      *)
103359ef0b394Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10336698f425bSmrg		;;
10337698f425bSmrg	      esac
10338698f425bSmrg	    fi
10339266e564dSmrg	  else
10340698f425bSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
103419ef0b394Smrg	    func_append rpath " $flag"
10342266e564dSmrg	  fi
10343698f425bSmrg	elif test -n "$runpath_var"; then
10344698f425bSmrg	  case "$finalize_perm_rpath " in
10345698f425bSmrg	  *" $libdir "*) ;;
103469ef0b394Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10347698f425bSmrg	  esac
10348266e564dSmrg	fi
10349698f425bSmrg      done
10350698f425bSmrg      # Substitute the hardcoded libdirs into the rpath.
10351698f425bSmrg      if test -n "$hardcode_libdir_separator" &&
10352698f425bSmrg	 test -n "$hardcode_libdirs"; then
10353a3129944Smrg	libdir=$hardcode_libdirs
10354698f425bSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10355698f425bSmrg      fi
10356a3129944Smrg      finalize_rpath=$rpath
10357266e564dSmrg
10358a3129944Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10359698f425bSmrg	# Transform all the library objects into standard objects.
103609ef0b394Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
103619ef0b394Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10362698f425bSmrg      fi
10363266e564dSmrg
10364a3129944Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10365266e564dSmrg
10366698f425bSmrg      # template prelinking step
10367698f425bSmrg      if test -n "$prelink_cmds"; then
10368698f425bSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10369698f425bSmrg      fi
10370266e564dSmrg
10371a3129944Smrg      wrappers_required=:
10372698f425bSmrg      case $host in
103739ef0b394Smrg      *cegcc* | *mingw32ce*)
103749ef0b394Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10375a3129944Smrg        wrappers_required=false
103769ef0b394Smrg        ;;
10377698f425bSmrg      *cygwin* | *mingw* )
10378a3129944Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
10379698f425bSmrg        ;;
10380698f425bSmrg      *)
10381a3129944Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10382a3129944Smrg          wrappers_required=false
10383698f425bSmrg        fi
10384698f425bSmrg        ;;
10385698f425bSmrg      esac
10386a3129944Smrg      $wrappers_required || {
10387698f425bSmrg	# Replace the output file specification.
103889ef0b394Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10389a3129944Smrg	link_command=$compile_command$compile_rpath
10390266e564dSmrg
10391698f425bSmrg	# We have no uninstalled library dependencies, so finalize right now.
10392698f425bSmrg	exit_status=0
10393698f425bSmrg	func_show_eval "$link_command" 'exit_status=$?'
10394266e564dSmrg
103959ef0b394Smrg	if test -n "$postlink_cmds"; then
103969ef0b394Smrg	  func_to_tool_file "$output"
103979ef0b394Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
103989ef0b394Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
103999ef0b394Smrg	fi
104009ef0b394Smrg
10401698f425bSmrg	# Delete the generated files.
10402a3129944Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10403a3129944Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10404266e564dSmrg	fi
10405266e564dSmrg
10406698f425bSmrg	exit $exit_status
10407a3129944Smrg      }
10408266e564dSmrg
10409698f425bSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10410698f425bSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10411698f425bSmrg      fi
10412698f425bSmrg      if test -n "$finalize_shlibpath"; then
10413698f425bSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10414698f425bSmrg      fi
10415266e564dSmrg
10416698f425bSmrg      compile_var=
10417698f425bSmrg      finalize_var=
10418698f425bSmrg      if test -n "$runpath_var"; then
10419698f425bSmrg	if test -n "$perm_rpath"; then
10420698f425bSmrg	  # We should set the runpath_var.
10421698f425bSmrg	  rpath=
10422698f425bSmrg	  for dir in $perm_rpath; do
104239ef0b394Smrg	    func_append rpath "$dir:"
10424698f425bSmrg	  done
10425698f425bSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10426266e564dSmrg	fi
10427698f425bSmrg	if test -n "$finalize_perm_rpath"; then
10428698f425bSmrg	  # We should set the runpath_var.
10429698f425bSmrg	  rpath=
10430698f425bSmrg	  for dir in $finalize_perm_rpath; do
104319ef0b394Smrg	    func_append rpath "$dir:"
10432698f425bSmrg	  done
10433698f425bSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10434266e564dSmrg	fi
10435698f425bSmrg      fi
10436266e564dSmrg
10437a3129944Smrg      if test yes = "$no_install"; then
10438698f425bSmrg	# We don't need to create a wrapper script.
10439a3129944Smrg	link_command=$compile_var$compile_command$compile_rpath
10440698f425bSmrg	# Replace the output file specification.
104419ef0b394Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10442698f425bSmrg	# Delete the old output file.
10443698f425bSmrg	$opt_dry_run || $RM $output
10444698f425bSmrg	# Link the executable and exit
10445698f425bSmrg	func_show_eval "$link_command" 'exit $?'
104469ef0b394Smrg
104479ef0b394Smrg	if test -n "$postlink_cmds"; then
104489ef0b394Smrg	  func_to_tool_file "$output"
104499ef0b394Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
104509ef0b394Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
104519ef0b394Smrg	fi
104529ef0b394Smrg
10453266e564dSmrg	exit $EXIT_SUCCESS
10454698f425bSmrg      fi
10455266e564dSmrg
10456a3129944Smrg      case $hardcode_action,$fast_install in
10457a3129944Smrg        relink,*)
10458a3129944Smrg	  # Fast installation is not supported
10459a3129944Smrg	  link_command=$compile_var$compile_command$compile_rpath
10460a3129944Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10461698f425bSmrg
10462a3129944Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10463a3129944Smrg	  func_warning "'$output' will be relinked during installation"
10464a3129944Smrg	  ;;
10465a3129944Smrg        *,yes)
10466a3129944Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10467a3129944Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10468a3129944Smrg          ;;
10469a3129944Smrg	*,no)
10470a3129944Smrg	  link_command=$compile_var$compile_command$compile_rpath
10471a3129944Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10472a3129944Smrg          ;;
10473a3129944Smrg	*,needless)
10474a3129944Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10475a3129944Smrg	  relink_command=
10476a3129944Smrg          ;;
10477a3129944Smrg      esac
10478266e564dSmrg
10479698f425bSmrg      # Replace the output file specification.
104809ef0b394Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10481266e564dSmrg
10482698f425bSmrg      # Delete the old output files.
10483698f425bSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10484266e564dSmrg
10485698f425bSmrg      func_show_eval "$link_command" 'exit $?'
10486266e564dSmrg
104879ef0b394Smrg      if test -n "$postlink_cmds"; then
104889ef0b394Smrg	func_to_tool_file "$output_objdir/$outputname"
104899ef0b394Smrg	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'`
104909ef0b394Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
104919ef0b394Smrg      fi
104929ef0b394Smrg
10493698f425bSmrg      # Now create the wrapper script.
10494698f425bSmrg      func_verbose "creating $output"
10495266e564dSmrg
10496698f425bSmrg      # Quote the relink command for shipping.
10497698f425bSmrg      if test -n "$relink_command"; then
10498698f425bSmrg	# Preserve any variables that may affect compiler behavior
10499698f425bSmrg	for var in $variables_saved_for_relink; do
10500698f425bSmrg	  if eval test -z \"\${$var+set}\"; then
10501698f425bSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10502698f425bSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10503698f425bSmrg	    relink_command="$var=; export $var; $relink_command"
10504266e564dSmrg	  else
10505698f425bSmrg	    func_quote_for_eval "$var_value"
10506698f425bSmrg	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10507266e564dSmrg	  fi
10508698f425bSmrg	done
10509698f425bSmrg	relink_command="(cd `pwd`; $relink_command)"
105109ef0b394Smrg	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
10511698f425bSmrg      fi
10512698f425bSmrg
10513698f425bSmrg      # Only actually do things if not in dry run mode.
10514698f425bSmrg      $opt_dry_run || {
10515698f425bSmrg	# win32 will think the script is a binary if it has
10516698f425bSmrg	# a .exe suffix, so we strip it off here.
10517698f425bSmrg	case $output in
10518698f425bSmrg	  *.exe) func_stripname '' '.exe' "$output"
10519698f425bSmrg	         output=$func_stripname_result ;;
10520698f425bSmrg	esac
10521698f425bSmrg	# test for cygwin because mv fails w/o .exe extensions
10522698f425bSmrg	case $host in
10523698f425bSmrg	  *cygwin*)
10524698f425bSmrg	    exeext=.exe
10525698f425bSmrg	    func_stripname '' '.exe' "$outputname"
10526698f425bSmrg	    outputname=$func_stripname_result ;;
10527698f425bSmrg	  *) exeext= ;;
10528266e564dSmrg	esac
10529698f425bSmrg	case $host in
10530698f425bSmrg	  *cygwin* | *mingw* )
10531698f425bSmrg	    func_dirname_and_basename "$output" "" "."
10532698f425bSmrg	    output_name=$func_basename_result
10533698f425bSmrg	    output_path=$func_dirname_result
10534a3129944Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10535a3129944Smrg	    cwrapper=$output_path/$output_name.exe
10536698f425bSmrg	    $RM $cwrappersource $cwrapper
10537698f425bSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10538698f425bSmrg
10539698f425bSmrg	    func_emit_cwrapperexe_src > $cwrappersource
10540698f425bSmrg
10541698f425bSmrg	    # The wrapper executable is built using the $host compiler,
10542698f425bSmrg	    # because it contains $host paths and files. If cross-
10543698f425bSmrg	    # compiling, it, like the target executable, must be
10544698f425bSmrg	    # executed on the $host or under an emulation environment.
10545698f425bSmrg	    $opt_dry_run || {
10546698f425bSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10547698f425bSmrg	      $STRIP $cwrapper
10548698f425bSmrg	    }
10549266e564dSmrg
10550698f425bSmrg	    # Now, create the wrapper script for func_source use:
10551698f425bSmrg	    func_ltwrapper_scriptname $cwrapper
10552698f425bSmrg	    $RM $func_ltwrapper_scriptname_result
10553698f425bSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10554698f425bSmrg	    $opt_dry_run || {
10555698f425bSmrg	      # note: this script will not be executed, so do not chmod.
10556a3129944Smrg	      if test "x$build" = "x$host"; then
10557698f425bSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10558698f425bSmrg	      else
10559698f425bSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10560698f425bSmrg	      fi
10561698f425bSmrg	    }
10562698f425bSmrg	  ;;
10563698f425bSmrg	  * )
10564698f425bSmrg	    $RM $output
10565698f425bSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10566266e564dSmrg
10567698f425bSmrg	    func_emit_wrapper no > $output
10568698f425bSmrg	    chmod +x $output
10569698f425bSmrg	  ;;
10570698f425bSmrg	esac
10571698f425bSmrg      }
10572698f425bSmrg      exit $EXIT_SUCCESS
10573698f425bSmrg      ;;
10574698f425bSmrg    esac
10575266e564dSmrg
10576698f425bSmrg    # See if we need to build an old-fashioned archive.
10577698f425bSmrg    for oldlib in $oldlibs; do
10578266e564dSmrg
10579a3129944Smrg      case $build_libtool_libs in
10580a3129944Smrg        convenience)
10581a3129944Smrg	  oldobjs="$libobjs_save $symfileobj"
10582a3129944Smrg	  addlibs=$convenience
10583698f425bSmrg	  build_libtool_libs=no
10584a3129944Smrg	  ;;
10585a3129944Smrg	module)
10586a3129944Smrg	  oldobjs=$libobjs_save
10587a3129944Smrg	  addlibs=$old_convenience
10588a3129944Smrg	  build_libtool_libs=no
10589a3129944Smrg          ;;
10590a3129944Smrg	*)
10591698f425bSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10592a3129944Smrg	  $preload && test -f "$symfileobj" \
10593a3129944Smrg	    && func_append oldobjs " $symfileobj"
10594a3129944Smrg	  addlibs=$old_convenience
10595a3129944Smrg	  ;;
10596a3129944Smrg      esac
10597266e564dSmrg
10598698f425bSmrg      if test -n "$addlibs"; then
10599a3129944Smrg	gentop=$output_objdir/${outputname}x
106009ef0b394Smrg	func_append generated " $gentop"
10601266e564dSmrg
10602698f425bSmrg	func_extract_archives $gentop $addlibs
106039ef0b394Smrg	func_append oldobjs " $func_extract_archives_result"
10604698f425bSmrg      fi
10605266e564dSmrg
10606698f425bSmrg      # Do each command in the archive commands.
10607a3129944Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10608698f425bSmrg	cmds=$old_archive_from_new_cmds
10609698f425bSmrg      else
10610266e564dSmrg
10611698f425bSmrg	# Add any objects from preloaded convenience libraries
10612698f425bSmrg	if test -n "$dlprefiles"; then
10613a3129944Smrg	  gentop=$output_objdir/${outputname}x
106149ef0b394Smrg	  func_append generated " $gentop"
10615266e564dSmrg
10616698f425bSmrg	  func_extract_archives $gentop $dlprefiles
106179ef0b394Smrg	  func_append oldobjs " $func_extract_archives_result"
10618698f425bSmrg	fi
10619266e564dSmrg
10620698f425bSmrg	# POSIX demands no paths to be encoded in archives.  We have
10621698f425bSmrg	# to avoid creating archives with duplicate basenames if we
10622698f425bSmrg	# might have to extract them afterwards, e.g., when creating a
10623698f425bSmrg	# static archive out of a convenience library, or when linking
10624698f425bSmrg	# the entirety of a libtool archive into another (currently
10625698f425bSmrg	# not supported by libtool).
10626698f425bSmrg	if (for obj in $oldobjs
10627698f425bSmrg	    do
10628698f425bSmrg	      func_basename "$obj"
10629698f425bSmrg	      $ECHO "$func_basename_result"
10630698f425bSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
10631698f425bSmrg	  :
10632698f425bSmrg	else
106339ef0b394Smrg	  echo "copying selected object files to avoid basename conflicts..."
10634a3129944Smrg	  gentop=$output_objdir/${outputname}x
106359ef0b394Smrg	  func_append generated " $gentop"
10636698f425bSmrg	  func_mkdir_p "$gentop"
10637698f425bSmrg	  save_oldobjs=$oldobjs
10638698f425bSmrg	  oldobjs=
10639698f425bSmrg	  counter=1
10640698f425bSmrg	  for obj in $save_oldobjs
10641698f425bSmrg	  do
10642698f425bSmrg	    func_basename "$obj"
10643a3129944Smrg	    objbase=$func_basename_result
10644698f425bSmrg	    case " $oldobjs " in
10645698f425bSmrg	    " ") oldobjs=$obj ;;
10646698f425bSmrg	    *[\ /]"$objbase "*)
10647698f425bSmrg	      while :; do
10648698f425bSmrg		# Make sure we don't pick an alternate name that also
10649698f425bSmrg		# overlaps.
10650698f425bSmrg		newobj=lt$counter-$objbase
10651698f425bSmrg		func_arith $counter + 1
10652698f425bSmrg		counter=$func_arith_result
10653698f425bSmrg		case " $oldobjs " in
10654698f425bSmrg		*[\ /]"$newobj "*) ;;
10655698f425bSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10656698f425bSmrg		esac
10657698f425bSmrg	      done
10658698f425bSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
106599ef0b394Smrg	      func_append oldobjs " $gentop/$newobj"
10660698f425bSmrg	      ;;
106619ef0b394Smrg	    *) func_append oldobjs " $obj" ;;
10662698f425bSmrg	    esac
10663266e564dSmrg	  done
10664266e564dSmrg	fi
10665fb5e8d76Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10666fb5e8d76Smrg	tool_oldlib=$func_to_tool_file_result
10667698f425bSmrg	eval cmds=\"$old_archive_cmds\"
10668266e564dSmrg
10669698f425bSmrg	func_len " $cmds"
10670698f425bSmrg	len=$func_len_result
10671698f425bSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10672698f425bSmrg	  cmds=$old_archive_cmds
106739ef0b394Smrg	elif test -n "$archiver_list_spec"; then
106749ef0b394Smrg	  func_verbose "using command file archive linking..."
106759ef0b394Smrg	  for obj in $oldobjs
106769ef0b394Smrg	  do
106779ef0b394Smrg	    func_to_tool_file "$obj"
106789ef0b394Smrg	    $ECHO "$func_to_tool_file_result"
106799ef0b394Smrg	  done > $output_objdir/$libname.libcmd
106809ef0b394Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
106819ef0b394Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
106829ef0b394Smrg	  cmds=$old_archive_cmds
10683698f425bSmrg	else
10684698f425bSmrg	  # the command line is too long to link in one step, link in parts
10685698f425bSmrg	  func_verbose "using piecewise archive linking..."
10686698f425bSmrg	  save_RANLIB=$RANLIB
10687698f425bSmrg	  RANLIB=:
10688698f425bSmrg	  objlist=
10689698f425bSmrg	  concat_cmds=
10690698f425bSmrg	  save_oldobjs=$oldobjs
10691698f425bSmrg	  oldobjs=
10692698f425bSmrg	  # Is there a better way of finding the last object in the list?
10693698f425bSmrg	  for obj in $save_oldobjs
10694698f425bSmrg	  do
10695698f425bSmrg	    last_oldobj=$obj
10696698f425bSmrg	  done
10697698f425bSmrg	  eval test_cmds=\"$old_archive_cmds\"
10698698f425bSmrg	  func_len " $test_cmds"
10699698f425bSmrg	  len0=$func_len_result
10700698f425bSmrg	  len=$len0
10701698f425bSmrg	  for obj in $save_oldobjs
10702698f425bSmrg	  do
10703698f425bSmrg	    func_len " $obj"
10704698f425bSmrg	    func_arith $len + $func_len_result
10705698f425bSmrg	    len=$func_arith_result
10706698f425bSmrg	    func_append objlist " $obj"
10707698f425bSmrg	    if test "$len" -lt "$max_cmd_len"; then
10708698f425bSmrg	      :
10709698f425bSmrg	    else
10710698f425bSmrg	      # the above command should be used before it gets too long
10711698f425bSmrg	      oldobjs=$objlist
10712a3129944Smrg	      if test "$obj" = "$last_oldobj"; then
10713698f425bSmrg		RANLIB=$save_RANLIB
10714698f425bSmrg	      fi
10715698f425bSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10716a3129944Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
10717698f425bSmrg	      objlist=
10718698f425bSmrg	      len=$len0
10719698f425bSmrg	    fi
10720698f425bSmrg	  done
10721698f425bSmrg	  RANLIB=$save_RANLIB
10722698f425bSmrg	  oldobjs=$objlist
10723a3129944Smrg	  if test -z "$oldobjs"; then
10724698f425bSmrg	    eval cmds=\"\$concat_cmds\"
10725698f425bSmrg	  else
10726698f425bSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
10727698f425bSmrg	  fi
10728698f425bSmrg	fi
10729698f425bSmrg      fi
10730698f425bSmrg      func_execute_cmds "$cmds" 'exit $?'
10731266e564dSmrg    done
10732266e564dSmrg
10733698f425bSmrg    test -n "$generated" && \
10734698f425bSmrg      func_show_eval "${RM}r$generated"
10735266e564dSmrg
10736698f425bSmrg    # Now create the libtool archive.
10737698f425bSmrg    case $output in
10738698f425bSmrg    *.la)
10739698f425bSmrg      old_library=
10740a3129944Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
10741698f425bSmrg      func_verbose "creating $output"
10742266e564dSmrg
10743698f425bSmrg      # Preserve any variables that may affect compiler behavior
10744698f425bSmrg      for var in $variables_saved_for_relink; do
10745698f425bSmrg	if eval test -z \"\${$var+set}\"; then
10746698f425bSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10747698f425bSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
10748698f425bSmrg	  relink_command="$var=; export $var; $relink_command"
10749266e564dSmrg	else
10750698f425bSmrg	  func_quote_for_eval "$var_value"
10751698f425bSmrg	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10752266e564dSmrg	fi
10753698f425bSmrg      done
10754698f425bSmrg      # Quote the link command for shipping.
10755a3129944Smrg      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
107569ef0b394Smrg      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
10757a3129944Smrg      if test yes = "$hardcode_automatic"; then
10758698f425bSmrg	relink_command=
10759698f425bSmrg      fi
10760266e564dSmrg
10761698f425bSmrg      # Only create the output if not a dry run.
10762698f425bSmrg      $opt_dry_run || {
10763698f425bSmrg	for installed in no yes; do
10764a3129944Smrg	  if test yes = "$installed"; then
10765698f425bSmrg	    if test -z "$install_libdir"; then
10766698f425bSmrg	      break
10767698f425bSmrg	    fi
10768a3129944Smrg	    output=$output_objdir/${outputname}i
10769698f425bSmrg	    # Replace all uninstalled libtool libraries with the installed ones
10770698f425bSmrg	    newdependency_libs=
10771698f425bSmrg	    for deplib in $dependency_libs; do
10772698f425bSmrg	      case $deplib in
10773698f425bSmrg	      *.la)
10774698f425bSmrg		func_basename "$deplib"
10775a3129944Smrg		name=$func_basename_result
10776fb5e8d76Smrg		func_resolve_sysroot "$deplib"
10777a3129944Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
10778698f425bSmrg		test -z "$libdir" && \
10779a3129944Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
107809ef0b394Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
107819ef0b394Smrg		;;
107829ef0b394Smrg	      -L*)
107839ef0b394Smrg		func_stripname -L '' "$deplib"
107849ef0b394Smrg		func_replace_sysroot "$func_stripname_result"
107859ef0b394Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
10786698f425bSmrg		;;
107879ef0b394Smrg	      -R*)
107889ef0b394Smrg		func_stripname -R '' "$deplib"
107899ef0b394Smrg		func_replace_sysroot "$func_stripname_result"
107909ef0b394Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
107919ef0b394Smrg		;;
107929ef0b394Smrg	      *) func_append newdependency_libs " $deplib" ;;
10793698f425bSmrg	      esac
10794698f425bSmrg	    done
10795a3129944Smrg	    dependency_libs=$newdependency_libs
10796698f425bSmrg	    newdlfiles=
10797698f425bSmrg
10798698f425bSmrg	    for lib in $dlfiles; do
10799698f425bSmrg	      case $lib in
10800698f425bSmrg	      *.la)
10801698f425bSmrg	        func_basename "$lib"
10802a3129944Smrg		name=$func_basename_result
10803a3129944Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
10804698f425bSmrg		test -z "$libdir" && \
10805a3129944Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
108069ef0b394Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
10807698f425bSmrg		;;
108089ef0b394Smrg	      *) func_append newdlfiles " $lib" ;;
10809698f425bSmrg	      esac
10810698f425bSmrg	    done
10811a3129944Smrg	    dlfiles=$newdlfiles
10812698f425bSmrg	    newdlprefiles=
10813698f425bSmrg	    for lib in $dlprefiles; do
10814698f425bSmrg	      case $lib in
10815698f425bSmrg	      *.la)
10816698f425bSmrg		# Only pass preopened files to the pseudo-archive (for
10817698f425bSmrg		# eventual linking with the app. that links it) if we
10818698f425bSmrg		# didn't already link the preopened objects directly into
10819698f425bSmrg		# the library:
10820698f425bSmrg		func_basename "$lib"
10821a3129944Smrg		name=$func_basename_result
10822a3129944Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
10823698f425bSmrg		test -z "$libdir" && \
10824a3129944Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
108259ef0b394Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
10826698f425bSmrg		;;
10827698f425bSmrg	      esac
10828698f425bSmrg	    done
10829a3129944Smrg	    dlprefiles=$newdlprefiles
10830698f425bSmrg	  else
10831698f425bSmrg	    newdlfiles=
10832698f425bSmrg	    for lib in $dlfiles; do
10833698f425bSmrg	      case $lib in
10834a3129944Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
10835698f425bSmrg		*) abs=`pwd`"/$lib" ;;
10836698f425bSmrg	      esac
108379ef0b394Smrg	      func_append newdlfiles " $abs"
10838698f425bSmrg	    done
10839a3129944Smrg	    dlfiles=$newdlfiles
10840698f425bSmrg	    newdlprefiles=
10841698f425bSmrg	    for lib in $dlprefiles; do
10842698f425bSmrg	      case $lib in
10843a3129944Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
10844698f425bSmrg		*) abs=`pwd`"/$lib" ;;
10845698f425bSmrg	      esac
108469ef0b394Smrg	      func_append newdlprefiles " $abs"
10847698f425bSmrg	    done
10848a3129944Smrg	    dlprefiles=$newdlprefiles
10849698f425bSmrg	  fi
10850698f425bSmrg	  $RM $output
10851698f425bSmrg	  # place dlname in correct position for cygwin
108529ef0b394Smrg	  # In fact, it would be nice if we could use this code for all target
108539ef0b394Smrg	  # systems that can't hard-code library paths into their executables
108549ef0b394Smrg	  # and that have no shared library path variable independent of PATH,
108559ef0b394Smrg	  # but it turns out we can't easily determine that from inspecting
108569ef0b394Smrg	  # libtool variables, so we have to hard-code the OSs to which it
108579ef0b394Smrg	  # applies here; at the moment, that means platforms that use the PE
108589ef0b394Smrg	  # object format with DLL files.  See the long comment at the top of
108599ef0b394Smrg	  # tests/bindir.at for full details.
10860698f425bSmrg	  tdlname=$dlname
10861698f425bSmrg	  case $host,$output,$installed,$module,$dlname in
108629ef0b394Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
108639ef0b394Smrg	      # If a -bindir argument was supplied, place the dll there.
10864a3129944Smrg	      if test -n "$bindir"; then
108659ef0b394Smrg		func_relative_path "$install_libdir" "$bindir"
10866a3129944Smrg		tdlname=$func_relative_path_result/$dlname
108679ef0b394Smrg	      else
108689ef0b394Smrg		# Otherwise fall back on heuristic.
108699ef0b394Smrg		tdlname=../bin/$dlname
108709ef0b394Smrg	      fi
108719ef0b394Smrg	      ;;
10872698f425bSmrg	  esac
10873698f425bSmrg	  $ECHO > $output "\
10874698f425bSmrg# $outputname - a libtool library file
10875a3129944Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
10876698f425bSmrg#
10877698f425bSmrg# Please DO NOT delete this file!
10878698f425bSmrg# It is necessary for linking the library.
10879266e564dSmrg
10880698f425bSmrg# The name that we can dlopen(3).
10881698f425bSmrgdlname='$tdlname'
10882266e564dSmrg
10883698f425bSmrg# Names of this library.
10884698f425bSmrglibrary_names='$library_names'
10885266e564dSmrg
10886698f425bSmrg# The name of the static archive.
10887698f425bSmrgold_library='$old_library'
10888266e564dSmrg
10889a3129944Smrg# Linker flags that cannot go in dependency_libs.
10890698f425bSmrginherited_linker_flags='$new_inherited_linker_flags'
10891266e564dSmrg
10892698f425bSmrg# Libraries that this one depends upon.
10893698f425bSmrgdependency_libs='$dependency_libs'
10894266e564dSmrg
10895698f425bSmrg# Names of additional weak libraries provided by this library
10896698f425bSmrgweak_library_names='$weak_libs'
10897266e564dSmrg
10898698f425bSmrg# Version information for $libname.
10899698f425bSmrgcurrent=$current
10900698f425bSmrgage=$age
10901698f425bSmrgrevision=$revision
10902266e564dSmrg
10903698f425bSmrg# Is this an already installed library?
10904698f425bSmrginstalled=$installed
10905266e564dSmrg
10906698f425bSmrg# Should we warn about portability when linking against -modules?
10907698f425bSmrgshouldnotlink=$module
10908266e564dSmrg
10909698f425bSmrg# Files to dlopen/dlpreopen
10910698f425bSmrgdlopen='$dlfiles'
10911698f425bSmrgdlpreopen='$dlprefiles'
10912266e564dSmrg
10913698f425bSmrg# Directory that this library needs to be installed in:
10914698f425bSmrglibdir='$install_libdir'"
10915a3129944Smrg	  if test no,yes = "$installed,$need_relink"; then
10916698f425bSmrg	    $ECHO >> $output "\
10917698f425bSmrgrelink_command=\"$relink_command\""
10918698f425bSmrg	  fi
10919698f425bSmrg	done
10920698f425bSmrg      }
10921266e564dSmrg
10922698f425bSmrg      # Do a symbolic link so that the libtool archive can be found in
10923698f425bSmrg      # LD_LIBRARY_PATH before the program is installed.
10924698f425bSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
10925698f425bSmrg      ;;
10926698f425bSmrg    esac
10927698f425bSmrg    exit $EXIT_SUCCESS
10928698f425bSmrg}
10929266e564dSmrg
10930a3129944Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
10931a3129944Smrg  func_mode_link ${1+"$@"}
10932a3129944Smrgfi
10933266e564dSmrg
10934266e564dSmrg
10935698f425bSmrg# func_mode_uninstall arg...
10936698f425bSmrgfunc_mode_uninstall ()
10937698f425bSmrg{
10938a3129944Smrg    $debug_cmd
10939a3129944Smrg
10940a3129944Smrg    RM=$nonopt
10941266e564dSmrg    files=
10942a3129944Smrg    rmforce=false
10943266e564dSmrg    exit_status=0
10944266e564dSmrg
10945266e564dSmrg    # This variable tells wrapper scripts just to set variables rather
10946266e564dSmrg    # than running their programs.
10947a3129944Smrg    libtool_install_magic=$magic
10948266e564dSmrg
10949266e564dSmrg    for arg
10950266e564dSmrg    do
10951266e564dSmrg      case $arg in
10952a3129944Smrg      -f) func_append RM " $arg"; rmforce=: ;;
109539ef0b394Smrg      -*) func_append RM " $arg" ;;
109549ef0b394Smrg      *) func_append files " $arg" ;;
10955266e564dSmrg      esac
10956266e564dSmrg    done
10957266e564dSmrg
10958698f425bSmrg    test -z "$RM" && \
10959698f425bSmrg      func_fatal_help "you must specify an RM program"
10960266e564dSmrg
10961266e564dSmrg    rmdirs=
10962266e564dSmrg
10963266e564dSmrg    for file in $files; do
10964698f425bSmrg      func_dirname "$file" "" "."
10965a3129944Smrg      dir=$func_dirname_result
10966a3129944Smrg      if test . = "$dir"; then
10967a3129944Smrg	odir=$objdir
10968266e564dSmrg      else
10969a3129944Smrg	odir=$dir/$objdir
10970266e564dSmrg      fi
10971698f425bSmrg      func_basename "$file"
10972a3129944Smrg      name=$func_basename_result
10973a3129944Smrg      test uninstall = "$opt_mode" && odir=$dir
10974266e564dSmrg
109759ef0b394Smrg      # Remember odir for removal later, being careful to avoid duplicates
10976a3129944Smrg      if test clean = "$opt_mode"; then
10977266e564dSmrg	case " $rmdirs " in
109789ef0b394Smrg	  *" $odir "*) ;;
109799ef0b394Smrg	  *) func_append rmdirs " $odir" ;;
10980266e564dSmrg	esac
10981266e564dSmrg      fi
10982266e564dSmrg
10983266e564dSmrg      # Don't error if the file doesn't exist and rm -f was used.
10984698f425bSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
10985698f425bSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
10986698f425bSmrg	 test -f "$file"; then
10987266e564dSmrg	:
10988266e564dSmrg      elif test -d "$file"; then
10989266e564dSmrg	exit_status=1
10990266e564dSmrg	continue
10991a3129944Smrg      elif $rmforce; then
10992266e564dSmrg	continue
10993266e564dSmrg      fi
10994266e564dSmrg
10995a3129944Smrg      rmfiles=$file
10996266e564dSmrg
10997266e564dSmrg      case $name in
10998266e564dSmrg      *.la)
10999266e564dSmrg	# Possibly a libtool archive, so verify it.
11000698f425bSmrg	if func_lalib_p "$file"; then
11001698f425bSmrg	  func_source $dir/$name
11002266e564dSmrg
11003266e564dSmrg	  # Delete the libtool libraries and symlinks.
11004266e564dSmrg	  for n in $library_names; do
110059ef0b394Smrg	    func_append rmfiles " $odir/$n"
11006266e564dSmrg	  done
110079ef0b394Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11008266e564dSmrg
11009a3129944Smrg	  case $opt_mode in
11010266e564dSmrg	  clean)
110119ef0b394Smrg	    case " $library_names " in
11012266e564dSmrg	    *" $dlname "*) ;;
110139ef0b394Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11014266e564dSmrg	    esac
110159ef0b394Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11016266e564dSmrg	    ;;
11017266e564dSmrg	  uninstall)
11018266e564dSmrg	    if test -n "$library_names"; then
11019266e564dSmrg	      # Do each command in the postuninstall commands.
11020a3129944Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11021266e564dSmrg	    fi
11022266e564dSmrg
11023266e564dSmrg	    if test -n "$old_library"; then
11024266e564dSmrg	      # Do each command in the old_postuninstall commands.
11025a3129944Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11026266e564dSmrg	    fi
11027266e564dSmrg	    # FIXME: should reinstall the best remaining shared library.
11028266e564dSmrg	    ;;
11029266e564dSmrg	  esac
11030266e564dSmrg	fi
11031266e564dSmrg	;;
11032266e564dSmrg
11033266e564dSmrg      *.lo)
11034266e564dSmrg	# Possibly a libtool object, so verify it.
11035698f425bSmrg	if func_lalib_p "$file"; then
11036266e564dSmrg
11037266e564dSmrg	  # Read the .lo file
11038698f425bSmrg	  func_source $dir/$name
11039266e564dSmrg
11040266e564dSmrg	  # Add PIC object to the list of files to remove.
11041a3129944Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
110429ef0b394Smrg	    func_append rmfiles " $dir/$pic_object"
11043266e564dSmrg	  fi
11044266e564dSmrg
11045266e564dSmrg	  # Add non-PIC object to the list of files to remove.
11046a3129944Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
110479ef0b394Smrg	    func_append rmfiles " $dir/$non_pic_object"
11048266e564dSmrg	  fi
11049266e564dSmrg	fi
11050266e564dSmrg	;;
11051266e564dSmrg
11052266e564dSmrg      *)
11053a3129944Smrg	if test clean = "$opt_mode"; then
11054266e564dSmrg	  noexename=$name
11055266e564dSmrg	  case $file in
11056266e564dSmrg	  *.exe)
11057698f425bSmrg	    func_stripname '' '.exe' "$file"
11058698f425bSmrg	    file=$func_stripname_result
11059698f425bSmrg	    func_stripname '' '.exe' "$name"
11060698f425bSmrg	    noexename=$func_stripname_result
11061266e564dSmrg	    # $file with .exe has already been added to rmfiles,
11062266e564dSmrg	    # add $file without .exe
110639ef0b394Smrg	    func_append rmfiles " $file"
11064266e564dSmrg	    ;;
11065266e564dSmrg	  esac
11066266e564dSmrg	  # Do a test to see if this is a libtool program.
11067698f425bSmrg	  if func_ltwrapper_p "$file"; then
11068698f425bSmrg	    if func_ltwrapper_executable_p "$file"; then
11069698f425bSmrg	      func_ltwrapper_scriptname "$file"
11070698f425bSmrg	      relink_command=
11071698f425bSmrg	      func_source $func_ltwrapper_scriptname_result
110729ef0b394Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11073698f425bSmrg	    else
11074698f425bSmrg	      relink_command=
11075698f425bSmrg	      func_source $dir/$noexename
11076698f425bSmrg	    fi
11077266e564dSmrg
11078266e564dSmrg	    # note $name still contains .exe if it was in $file originally
11079266e564dSmrg	    # as does the version of $file that was added into $rmfiles
11080a3129944Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11081a3129944Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
110829ef0b394Smrg	      func_append rmfiles " $odir/lt-$name"
11083266e564dSmrg	    fi
11084a3129944Smrg	    if test "X$noexename" != "X$name"; then
11085a3129944Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11086266e564dSmrg	    fi
11087266e564dSmrg	  fi
11088266e564dSmrg	fi
11089266e564dSmrg	;;
11090266e564dSmrg      esac
11091698f425bSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11092266e564dSmrg    done
11093266e564dSmrg
11094a3129944Smrg    # Try to remove the $objdir's in the directories where we deleted files
11095266e564dSmrg    for dir in $rmdirs; do
11096266e564dSmrg      if test -d "$dir"; then
11097698f425bSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11098266e564dSmrg      fi
11099266e564dSmrg    done
11100266e564dSmrg
11101266e564dSmrg    exit $exit_status
11102698f425bSmrg}
11103266e564dSmrg
11104a3129944Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11105a3129944Smrg  func_mode_uninstall ${1+"$@"}
11106a3129944Smrgfi
11107266e564dSmrg
111089ef0b394Smrgtest -z "$opt_mode" && {
11109a3129944Smrg  help=$generic_help
11110698f425bSmrg  func_fatal_help "you must specify a MODE"
11111698f425bSmrg}
11112698f425bSmrg
11113698f425bSmrgtest -z "$exec_cmd" && \
11114a3129944Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11115266e564dSmrg
11116266e564dSmrgif test -n "$exec_cmd"; then
11117698f425bSmrg  eval exec "$exec_cmd"
11118266e564dSmrg  exit $EXIT_FAILURE
11119266e564dSmrgfi
11120266e564dSmrg
11121698f425bSmrgexit $exit_status
11122266e564dSmrg
11123266e564dSmrg
11124266e564dSmrg# The TAGs below are defined such that we never get into a situation
11125a3129944Smrg# where we disable both kinds of libraries.  Given conflicting
11126266e564dSmrg# choices, we go for a static library, that is the most portable,
11127266e564dSmrg# since we can't tell whether shared libraries were disabled because
11128266e564dSmrg# the user asked for that or because the platform doesn't support
11129266e564dSmrg# them.  This is particularly important on AIX, because we don't
11130266e564dSmrg# support having both static and shared libraries enabled at the same
11131266e564dSmrg# time on that platform, so we default to a shared-only configuration.
11132266e564dSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11133266e564dSmrg# configuration.  But we'll never go from static-only to shared-only.
11134266e564dSmrg
11135266e564dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11136698f425bSmrgbuild_libtool_libs=no
11137698f425bSmrgbuild_old_libs=yes
11138266e564dSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11139266e564dSmrg
11140266e564dSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11141698f425bSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11142266e564dSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11143266e564dSmrg
11144266e564dSmrg# Local Variables:
11145266e564dSmrg# mode:shell-script
11146266e564dSmrg# sh-indentation:2
11147266e564dSmrg# End:
11148