ltmain.sh revision b0a0317a
1b0a0317aSmrg#! /bin/sh
2b0a0317aSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3b0a0317aSmrg##               by inline-source v2014-01-03.01
4521070a0Smrg
5b0a0317aSmrg# libtool (GNU libtool) 2.4.6
6b0a0317aSmrg# Provide generalized library-building support services.
7521070a0Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8521070a0Smrg
9b0a0317aSmrg# Copyright (C) 1996-2015 Free Software Foundation, Inc.
10521070a0Smrg# This is free software; see the source for copying conditions.  There is NO
11521070a0Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12521070a0Smrg
13521070a0Smrg# GNU Libtool is free software; you can redistribute it and/or modify
144456fccdSmrg# it under the terms of the GNU General Public License as published by
154456fccdSmrg# the Free Software Foundation; either version 2 of the License, or
164456fccdSmrg# (at your option) any later version.
174456fccdSmrg#
18521070a0Smrg# As a special exception to the GNU General Public License,
19521070a0Smrg# if you distribute this file as part of a program or library that
20521070a0Smrg# is built using GNU Libtool, you may include this file under the
21521070a0Smrg# same distribution terms that you use for the rest of that program.
22521070a0Smrg#
23521070a0Smrg# GNU Libtool is distributed in the hope that it will be useful, but
244456fccdSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
254456fccdSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
264456fccdSmrg# General Public License for more details.
274456fccdSmrg#
284456fccdSmrg# You should have received a copy of the GNU General Public License
29b0a0317aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
304456fccdSmrg
314456fccdSmrg
32ff63a143SmrgPROGRAM=libtool
334456fccdSmrgPACKAGE=libtool
34b0a0317aSmrgVERSION=2.4.6
35b0a0317aSmrgpackage_revision=2.4.6
3642d69509Smrg
37b0a0317aSmrg
38b0a0317aSmrg## ------ ##
39b0a0317aSmrg## Usage. ##
40b0a0317aSmrg## ------ ##
41b0a0317aSmrg
42b0a0317aSmrg# Run './libtool --help' for help with using this script from the
43b0a0317aSmrg# command line.
44b0a0317aSmrg
45b0a0317aSmrg
46b0a0317aSmrg## ------------------------------- ##
47b0a0317aSmrg## User overridable command paths. ##
48b0a0317aSmrg## ------------------------------- ##
49b0a0317aSmrg
50b0a0317aSmrg# After configure completes, it has a better idea of some of the
51b0a0317aSmrg# shell tools we need than the defaults used by the functions shared
52b0a0317aSmrg# with bootstrap, so set those here where they can still be over-
53b0a0317aSmrg# ridden by the user, but otherwise take precedence.
54b0a0317aSmrg
55b0a0317aSmrg: ${AUTOCONF="autoconf"}
56b0a0317aSmrg: ${AUTOMAKE="automake"}
57b0a0317aSmrg
58b0a0317aSmrg
59b0a0317aSmrg## -------------------------- ##
60b0a0317aSmrg## Source external libraries. ##
61b0a0317aSmrg## -------------------------- ##
62b0a0317aSmrg
63b0a0317aSmrg# Much of our low-level functionality needs to be sourced from external
64b0a0317aSmrg# libraries, which are installed to $pkgauxdir.
65b0a0317aSmrg
66b0a0317aSmrg# Set a version string for this script.
67b0a0317aSmrgscriptversion=2015-01-20.17; # UTC
68b0a0317aSmrg
69b0a0317aSmrg# General shell script boiler plate, and helper functions.
70b0a0317aSmrg# Written by Gary V. Vaughan, 2004
71b0a0317aSmrg
72b0a0317aSmrg# Copyright (C) 2004-2015 Free Software Foundation, Inc.
73b0a0317aSmrg# This is free software; see the source for copying conditions.  There is NO
74b0a0317aSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75b0a0317aSmrg
76b0a0317aSmrg# This program is free software; you can redistribute it and/or modify
77b0a0317aSmrg# it under the terms of the GNU General Public License as published by
78b0a0317aSmrg# the Free Software Foundation; either version 3 of the License, or
79b0a0317aSmrg# (at your option) any later version.
80b0a0317aSmrg
81b0a0317aSmrg# As a special exception to the GNU General Public License, if you distribute
82b0a0317aSmrg# this file as part of a program or library that is built using GNU Libtool,
83b0a0317aSmrg# you may include this file under the same distribution terms that you use
84b0a0317aSmrg# for the rest of that program.
85b0a0317aSmrg
86b0a0317aSmrg# This program is distributed in the hope that it will be useful,
87b0a0317aSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
88b0a0317aSmrg# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
89b0a0317aSmrg# General Public License for more details.
90b0a0317aSmrg
91b0a0317aSmrg# You should have received a copy of the GNU General Public License
92b0a0317aSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>.
93b0a0317aSmrg
94b0a0317aSmrg# Please report bugs or propose patches to gary@gnu.org.
95b0a0317aSmrg
96b0a0317aSmrg
97b0a0317aSmrg## ------ ##
98b0a0317aSmrg## Usage. ##
99b0a0317aSmrg## ------ ##
100b0a0317aSmrg
101b0a0317aSmrg# Evaluate this file near the top of your script to gain access to
102b0a0317aSmrg# the functions and variables defined here:
103b0a0317aSmrg#
104b0a0317aSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
105b0a0317aSmrg#
106b0a0317aSmrg# If you need to override any of the default environment variable
107b0a0317aSmrg# settings, do that before evaluating this file.
108b0a0317aSmrg
109b0a0317aSmrg
110b0a0317aSmrg## -------------------- ##
111b0a0317aSmrg## Shell normalisation. ##
112b0a0317aSmrg## -------------------- ##
113b0a0317aSmrg
114b0a0317aSmrg# Some shells need a little help to be as Bourne compatible as possible.
115b0a0317aSmrg# Before doing anything else, make sure all that help has been provided!
116b0a0317aSmrg
117b0a0317aSmrgDUALCASE=1; export DUALCASE # for MKS sh
118b0a0317aSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
11942d69509Smrg  emulate sh
12042d69509Smrg  NULLCMD=:
121b0a0317aSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
12242d69509Smrg  # is contrary to our usage.  Disable this feature.
12342d69509Smrg  alias -g '${1+"$@"}'='"$@"'
1244456fccdSmrg  setopt NO_GLOB_SUBST
12542d69509Smrgelse
126b0a0317aSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1274456fccdSmrgfi
128ff63a143Smrg
129b0a0317aSmrg# NLS nuisances: We save the old values in case they are required later.
130b0a0317aSmrg_G_user_locale=
131b0a0317aSmrg_G_safe_locale=
132b0a0317aSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
13342d69509Smrgdo
134b0a0317aSmrg  eval "if test set = \"\${$_G_var+set}\"; then
135b0a0317aSmrg          save_$_G_var=\$$_G_var
136b0a0317aSmrg          $_G_var=C
137b0a0317aSmrg	  export $_G_var
138b0a0317aSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
139b0a0317aSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
14042d69509Smrg	fi"
14142d69509Smrgdone
14242d69509Smrg
143b0a0317aSmrg# CDPATH.
144b0a0317aSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
145521070a0Smrg
146b0a0317aSmrg# Make sure IFS has a sensible default
147b0a0317aSmrgsp=' '
148b0a0317aSmrgnl='
149b0a0317aSmrg'
150b0a0317aSmrgIFS="$sp	$nl"
151b0a0317aSmrg
152b0a0317aSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
153b0a0317aSmrgif test "${PATH_SEPARATOR+set}" != set; then
154b0a0317aSmrg  PATH_SEPARATOR=:
155b0a0317aSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
156b0a0317aSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
157b0a0317aSmrg      PATH_SEPARATOR=';'
158b0a0317aSmrg  }
159b0a0317aSmrgfi
160521070a0Smrg
161521070a0Smrg
162521070a0Smrg
163b0a0317aSmrg## ------------------------- ##
164b0a0317aSmrg## Locate command utilities. ##
165b0a0317aSmrg## ------------------------- ##
166b0a0317aSmrg
167b0a0317aSmrg
168b0a0317aSmrg# func_executable_p FILE
169b0a0317aSmrg# ----------------------
170b0a0317aSmrg# Check that FILE is an executable regular file.
171b0a0317aSmrgfunc_executable_p ()
172b0a0317aSmrg{
173b0a0317aSmrg    test -f "$1" && test -x "$1"
174b0a0317aSmrg}
175b0a0317aSmrg
176b0a0317aSmrg
177b0a0317aSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
178b0a0317aSmrg# --------------------------------------------
179b0a0317aSmrg# Search for either a program that responds to --version with output
180b0a0317aSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
181b0a0317aSmrg# trying all the directories in PATH with each of the elements of
182b0a0317aSmrg# PROGS_LIST.
183b0a0317aSmrg#
184b0a0317aSmrg# CHECK_FUNC should accept the path to a candidate program, and
185b0a0317aSmrg# set $func_check_prog_result if it truncates its output less than
186b0a0317aSmrg# $_G_path_prog_max characters.
187b0a0317aSmrgfunc_path_progs ()
188b0a0317aSmrg{
189b0a0317aSmrg    _G_progs_list=$1
190b0a0317aSmrg    _G_check_func=$2
191b0a0317aSmrg    _G_PATH=${3-"$PATH"}
192b0a0317aSmrg
193b0a0317aSmrg    _G_path_prog_max=0
194b0a0317aSmrg    _G_path_prog_found=false
195b0a0317aSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
196b0a0317aSmrg    for _G_dir in $_G_PATH; do
197b0a0317aSmrg      IFS=$_G_save_IFS
198b0a0317aSmrg      test -z "$_G_dir" && _G_dir=.
199b0a0317aSmrg      for _G_prog_name in $_G_progs_list; do
200b0a0317aSmrg        for _exeext in '' .EXE; do
201b0a0317aSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
202b0a0317aSmrg          func_executable_p "$_G_path_prog" || continue
203b0a0317aSmrg          case `"$_G_path_prog" --version 2>&1` in
204b0a0317aSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
205b0a0317aSmrg            *)     $_G_check_func $_G_path_prog
206b0a0317aSmrg		   func_path_progs_result=$func_check_prog_result
207b0a0317aSmrg		   ;;
208b0a0317aSmrg          esac
209b0a0317aSmrg          $_G_path_prog_found && break 3
210b0a0317aSmrg        done
211b0a0317aSmrg      done
212b0a0317aSmrg    done
213b0a0317aSmrg    IFS=$_G_save_IFS
214b0a0317aSmrg    test -z "$func_path_progs_result" && {
215b0a0317aSmrg      echo "no acceptable sed could be found in \$PATH" >&2
216b0a0317aSmrg      exit 1
217b0a0317aSmrg    }
218b0a0317aSmrg}
219b0a0317aSmrg
220b0a0317aSmrg
221b0a0317aSmrg# We want to be able to use the functions in this file before configure
222b0a0317aSmrg# has figured out where the best binaries are kept, which means we have
223b0a0317aSmrg# to search for them ourselves - except when the results are already set
224b0a0317aSmrg# where we skip the searches.
225b0a0317aSmrg
226b0a0317aSmrg# Unless the user overrides by setting SED, search the path for either GNU
227b0a0317aSmrg# sed, or the sed that truncates its output the least.
228b0a0317aSmrgtest -z "$SED" && {
229b0a0317aSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
230b0a0317aSmrg  for _G_i in 1 2 3 4 5 6 7; do
231b0a0317aSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
232b0a0317aSmrg  done
233b0a0317aSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
234b0a0317aSmrg  _G_sed_script=
235b0a0317aSmrg
236b0a0317aSmrg  func_check_prog_sed ()
237b0a0317aSmrg  {
238b0a0317aSmrg    _G_path_prog=$1
239b0a0317aSmrg
240b0a0317aSmrg    _G_count=0
241b0a0317aSmrg    printf 0123456789 >conftest.in
242b0a0317aSmrg    while :
243b0a0317aSmrg    do
244b0a0317aSmrg      cat conftest.in conftest.in >conftest.tmp
245b0a0317aSmrg      mv conftest.tmp conftest.in
246b0a0317aSmrg      cp conftest.in conftest.nl
247b0a0317aSmrg      echo '' >> conftest.nl
248b0a0317aSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
249b0a0317aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
250b0a0317aSmrg      _G_count=`expr $_G_count + 1`
251b0a0317aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
252b0a0317aSmrg        # Best one so far, save it but keep looking for a better one
253b0a0317aSmrg        func_check_prog_result=$_G_path_prog
254b0a0317aSmrg        _G_path_prog_max=$_G_count
255b0a0317aSmrg      fi
256b0a0317aSmrg      # 10*(2^10) chars as input seems more than enough
257b0a0317aSmrg      test 10 -lt "$_G_count" && break
258b0a0317aSmrg    done
259b0a0317aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
260b0a0317aSmrg  }
261b0a0317aSmrg
262b0a0317aSmrg  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
263b0a0317aSmrg  rm -f conftest.sed
264b0a0317aSmrg  SED=$func_path_progs_result
265b0a0317aSmrg}
266b0a0317aSmrg
267b0a0317aSmrg
268b0a0317aSmrg# Unless the user overrides by setting GREP, search the path for either GNU
269b0a0317aSmrg# grep, or the grep that truncates its output the least.
270b0a0317aSmrgtest -z "$GREP" && {
271b0a0317aSmrg  func_check_prog_grep ()
272b0a0317aSmrg  {
273b0a0317aSmrg    _G_path_prog=$1
274b0a0317aSmrg
275b0a0317aSmrg    _G_count=0
276b0a0317aSmrg    _G_path_prog_max=0
277b0a0317aSmrg    printf 0123456789 >conftest.in
278b0a0317aSmrg    while :
279b0a0317aSmrg    do
280b0a0317aSmrg      cat conftest.in conftest.in >conftest.tmp
281b0a0317aSmrg      mv conftest.tmp conftest.in
282b0a0317aSmrg      cp conftest.in conftest.nl
283b0a0317aSmrg      echo 'GREP' >> conftest.nl
284b0a0317aSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
285b0a0317aSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
286b0a0317aSmrg      _G_count=`expr $_G_count + 1`
287b0a0317aSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
288b0a0317aSmrg        # Best one so far, save it but keep looking for a better one
289b0a0317aSmrg        func_check_prog_result=$_G_path_prog
290b0a0317aSmrg        _G_path_prog_max=$_G_count
291b0a0317aSmrg      fi
292b0a0317aSmrg      # 10*(2^10) chars as input seems more than enough
293b0a0317aSmrg      test 10 -lt "$_G_count" && break
294b0a0317aSmrg    done
295b0a0317aSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
296b0a0317aSmrg  }
297b0a0317aSmrg
298b0a0317aSmrg  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
299b0a0317aSmrg  GREP=$func_path_progs_result
300b0a0317aSmrg}
301b0a0317aSmrg
302b0a0317aSmrg
303b0a0317aSmrg## ------------------------------- ##
304b0a0317aSmrg## User overridable command paths. ##
305b0a0317aSmrg## ------------------------------- ##
306b0a0317aSmrg
307b0a0317aSmrg# All uppercase variable names are used for environment variables.  These
308b0a0317aSmrg# variables can be overridden by the user before calling a script that
309b0a0317aSmrg# uses them if a suitable command of that name is not already available
310b0a0317aSmrg# in the command search PATH.
311521070a0Smrg
312521070a0Smrg: ${CP="cp -f"}
313b0a0317aSmrg: ${ECHO="printf %s\n"}
314b0a0317aSmrg: ${EGREP="$GREP -E"}
315b0a0317aSmrg: ${FGREP="$GREP -F"}
316b0a0317aSmrg: ${LN_S="ln -s"}
317521070a0Smrg: ${MAKE="make"}
318521070a0Smrg: ${MKDIR="mkdir"}
319521070a0Smrg: ${MV="mv -f"}
320521070a0Smrg: ${RM="rm -f"}
321521070a0Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
3224456fccdSmrg
323521070a0Smrg
324b0a0317aSmrg## -------------------- ##
325b0a0317aSmrg## Useful sed snippets. ##
326b0a0317aSmrg## -------------------- ##
3273e6c936aSmrg
328b0a0317aSmrgsed_dirname='s|/[^/]*$||'
329b0a0317aSmrgsed_basename='s|^.*/||'
3303e6c936aSmrg
331b0a0317aSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
332b0a0317aSmrg# metacharacters that are still active within double-quoted strings.
333b0a0317aSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
3343e6c936aSmrg
335b0a0317aSmrg# Same as above, but do not quote variable references.
336b0a0317aSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
3373e6c936aSmrg
338b0a0317aSmrg# Sed substitution that turns a string into a regex matching for the
339b0a0317aSmrg# string literally.
340b0a0317aSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
3413e6c936aSmrg
342b0a0317aSmrg# Sed substitution that converts a w32 file name or path
343b0a0317aSmrg# that contains forward slashes, into one that contains
344b0a0317aSmrg# (escaped) backslashes.  A very naive implementation.
345b0a0317aSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
346b0a0317aSmrg
347b0a0317aSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
348b0a0317aSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
349b0a0317aSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
350b0a0317aSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
351b0a0317aSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
352b0a0317aSmrg_G_bs='\\'
353b0a0317aSmrg_G_bs2='\\\\'
354b0a0317aSmrg_G_bs4='\\\\\\\\'
355b0a0317aSmrg_G_dollar='\$'
356b0a0317aSmrgsed_double_backslash="\
357b0a0317aSmrg  s/$_G_bs4/&\\
358b0a0317aSmrg/g
359b0a0317aSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
360b0a0317aSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
361b0a0317aSmrg  s/\n//g"
3623e6c936aSmrg
3634456fccdSmrg
364b0a0317aSmrg## ----------------- ##
365b0a0317aSmrg## Global variables. ##
366b0a0317aSmrg## ----------------- ##
367521070a0Smrg
368b0a0317aSmrg# Except for the global variables explicitly listed below, the following
369b0a0317aSmrg# functions in the '^func_' namespace, and the '^require_' namespace
370b0a0317aSmrg# variables initialised in the 'Resource management' section, sourcing
371b0a0317aSmrg# this file will not pollute your global namespace with anything
372b0a0317aSmrg# else. There's no portable way to scope variables in Bourne shell
373b0a0317aSmrg# though, so actually running these functions will sometimes place
374b0a0317aSmrg# results into a variable named after the function, and often use
375b0a0317aSmrg# temporary variables in the '^_G_' namespace. If you are careful to
376b0a0317aSmrg# avoid using those namespaces casually in your sourcing script, things
377b0a0317aSmrg# should continue to work as you expect. And, of course, you can freely
378b0a0317aSmrg# overwrite any of the functions or variables defined here before
379b0a0317aSmrg# calling anything to customize them.
380ff63a143Smrg
381b0a0317aSmrgEXIT_SUCCESS=0
382b0a0317aSmrgEXIT_FAILURE=1
383b0a0317aSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
384b0a0317aSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
385ff63a143Smrg
386b0a0317aSmrg# Allow overriding, eg assuming that you follow the convention of
387b0a0317aSmrg# putting '$debug_cmd' at the start of all your functions, you can get
388b0a0317aSmrg# bash to show function call trace with:
389b0a0317aSmrg#
390b0a0317aSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
391b0a0317aSmrgdebug_cmd=${debug_cmd-":"}
392b0a0317aSmrgexit_cmd=:
393ff63a143Smrg
394b0a0317aSmrg# By convention, finish your script with:
395b0a0317aSmrg#
396b0a0317aSmrg#    exit $exit_status
397b0a0317aSmrg#
398b0a0317aSmrg# so that you can set exit_status to non-zero if you want to indicate
399b0a0317aSmrg# something went wrong during execution without actually bailing out at
400b0a0317aSmrg# the point of failure.
401b0a0317aSmrgexit_status=$EXIT_SUCCESS
402ff63a143Smrg
403b0a0317aSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
404b0a0317aSmrg# is ksh but when the shell is invoked as "sh" and the current value of
405b0a0317aSmrg# the _XPG environment variable is not equal to 1 (one), the special
406b0a0317aSmrg# positional parameter $0, within a function call, is the name of the
407b0a0317aSmrg# function.
408b0a0317aSmrgprogpath=$0
409521070a0Smrg
410b0a0317aSmrg# The name of this program.
411b0a0317aSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
412521070a0Smrg
413b0a0317aSmrg# Make sure we have an absolute progpath for reexecution:
414521070a0Smrgcase $progpath in
415521070a0Smrg  [\\/]*|[A-Za-z]:\\*) ;;
416521070a0Smrg  *[\\/]*)
417b0a0317aSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
418521070a0Smrg     progdir=`cd "$progdir" && pwd`
419b0a0317aSmrg     progpath=$progdir/$progname
420521070a0Smrg     ;;
421521070a0Smrg  *)
422b0a0317aSmrg     _G_IFS=$IFS
4233e6c936aSmrg     IFS=${PATH_SEPARATOR-:}
424521070a0Smrg     for progdir in $PATH; do
425b0a0317aSmrg       IFS=$_G_IFS
426521070a0Smrg       test -x "$progdir/$progname" && break
427521070a0Smrg     done
428b0a0317aSmrg     IFS=$_G_IFS
429521070a0Smrg     test -n "$progdir" || progdir=`pwd`
430b0a0317aSmrg     progpath=$progdir/$progname
431521070a0Smrg     ;;
432521070a0Smrgesac
433521070a0Smrg
434521070a0Smrg
435b0a0317aSmrg## ----------------- ##
436b0a0317aSmrg## Standard options. ##
437b0a0317aSmrg## ----------------- ##
4383e6c936aSmrg
439b0a0317aSmrg# The following options affect the operation of the functions defined
440b0a0317aSmrg# below, and should be set appropriately depending on run-time para-
441b0a0317aSmrg# meters passed on the command line.
442521070a0Smrg
443521070a0Smrgopt_dry_run=false
444521070a0Smrgopt_quiet=false
445521070a0Smrgopt_verbose=false
446521070a0Smrg
447b0a0317aSmrg# Categories 'all' and 'none' are always available.  Append any others
448b0a0317aSmrg# you will pass as the first argument to func_warning from your own
449b0a0317aSmrg# code.
450b0a0317aSmrgwarning_categories=
451521070a0Smrg
452b0a0317aSmrg# By default, display warnings according to 'opt_warning_types'.  Set
453b0a0317aSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
454b0a0317aSmrg# treat the next displayed warning as a fatal error.
455b0a0317aSmrgwarning_func=func_warn_and_continue
456521070a0Smrg
457b0a0317aSmrg# Set to 'all' to display all warnings, 'none' to suppress all
458b0a0317aSmrg# warnings, or a space delimited list of some subset of
459b0a0317aSmrg# 'warning_categories' to display only the listed warnings.
460b0a0317aSmrgopt_warning_types=all
461521070a0Smrg
462ff63a143Smrg
463b0a0317aSmrg## -------------------- ##
464b0a0317aSmrg## Resource management. ##
465b0a0317aSmrg## -------------------- ##
466521070a0Smrg
467b0a0317aSmrg# This section contains definitions for functions that each ensure a
468b0a0317aSmrg# particular resource (a file, or a non-empty configuration variable for
469b0a0317aSmrg# example) is available, and if appropriate to extract default values
470b0a0317aSmrg# from pertinent package files. Call them using their associated
471b0a0317aSmrg# 'require_*' variable to ensure that they are executed, at most, once.
472b0a0317aSmrg#
473b0a0317aSmrg# It's entirely deliberate that calling these functions can set
474b0a0317aSmrg# variables that don't obey the namespace limitations obeyed by the rest
475b0a0317aSmrg# of this file, in order that that they be as useful as possible to
476b0a0317aSmrg# callers.
477521070a0Smrg
478521070a0Smrg
479b0a0317aSmrg# require_term_colors
480b0a0317aSmrg# -------------------
481b0a0317aSmrg# Allow display of bold text on terminals that support it.
482b0a0317aSmrgrequire_term_colors=func_require_term_colors
483b0a0317aSmrgfunc_require_term_colors ()
484521070a0Smrg{
485b0a0317aSmrg    $debug_cmd
486b0a0317aSmrg
487b0a0317aSmrg    test -t 1 && {
488b0a0317aSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
489b0a0317aSmrg      # precedence, because most terminfo databases neglect to describe
490b0a0317aSmrg      # whether color sequences are supported.
491b0a0317aSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
492b0a0317aSmrg
493b0a0317aSmrg      if test 1 = "$USE_ANSI_COLORS"; then
494b0a0317aSmrg        # Standard ANSI escape sequences
495b0a0317aSmrg        tc_reset='[0m'
496b0a0317aSmrg        tc_bold='[1m';   tc_standout='[7m'
497b0a0317aSmrg        tc_red='[31m';   tc_green='[32m'
498b0a0317aSmrg        tc_blue='[34m';  tc_cyan='[36m'
499b0a0317aSmrg      else
500b0a0317aSmrg        # Otherwise trust the terminfo database after all.
501b0a0317aSmrg        test -n "`tput sgr0 2>/dev/null`" && {
502b0a0317aSmrg          tc_reset=`tput sgr0`
503b0a0317aSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
504b0a0317aSmrg          tc_standout=$tc_bold
505b0a0317aSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
506b0a0317aSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
507b0a0317aSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
508b0a0317aSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
509b0a0317aSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
510b0a0317aSmrg        }
511b0a0317aSmrg      fi
512b0a0317aSmrg    }
513521070a0Smrg
514b0a0317aSmrg    require_term_colors=:
515521070a0Smrg}
516521070a0Smrg
517521070a0Smrg
518b0a0317aSmrg## ----------------- ##
519b0a0317aSmrg## Function library. ##
520b0a0317aSmrg## ----------------- ##
521b0a0317aSmrg
522b0a0317aSmrg# This section contains a variety of useful functions to call in your
523b0a0317aSmrg# scripts. Take note of the portable wrappers for features provided by
524b0a0317aSmrg# some modern shells, which will fall back to slower equivalents on
525b0a0317aSmrg# less featureful shells.
526b0a0317aSmrg
527b0a0317aSmrg
528b0a0317aSmrg# func_append VAR VALUE
529b0a0317aSmrg# ---------------------
530b0a0317aSmrg# Append VALUE onto the existing contents of VAR.
531b0a0317aSmrg
532b0a0317aSmrg  # We should try to minimise forks, especially on Windows where they are
533b0a0317aSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
534b0a0317aSmrg  # being used:
535b0a0317aSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
536b0a0317aSmrg    : ${_G_HAVE_ARITH_OP="yes"}
537b0a0317aSmrg    : ${_G_HAVE_XSI_OPS="yes"}
538b0a0317aSmrg    # The += operator was introduced in bash 3.1
539b0a0317aSmrg    case $BASH_VERSION in
540b0a0317aSmrg      [12].* | 3.0 | 3.0*) ;;
541b0a0317aSmrg      *)
542b0a0317aSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
543b0a0317aSmrg        ;;
544b0a0317aSmrg    esac
545b0a0317aSmrg  fi
546b0a0317aSmrg
547b0a0317aSmrg  # _G_HAVE_PLUSEQ_OP
548b0a0317aSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
549b0a0317aSmrg  # useable or anything else if it does not work.
550b0a0317aSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
551b0a0317aSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
552b0a0317aSmrg    && _G_HAVE_PLUSEQ_OP=yes
553b0a0317aSmrg
554b0a0317aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
555b0a0317aSmrgthen
556b0a0317aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
557b0a0317aSmrg  eval 'func_append ()
558b0a0317aSmrg  {
559b0a0317aSmrg    $debug_cmd
560b0a0317aSmrg
561b0a0317aSmrg    eval "$1+=\$2"
562b0a0317aSmrg  }'
563b0a0317aSmrgelse
564b0a0317aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
565b0a0317aSmrg  func_append ()
566b0a0317aSmrg  {
567b0a0317aSmrg    $debug_cmd
568b0a0317aSmrg
569b0a0317aSmrg    eval "$1=\$$1\$2"
570b0a0317aSmrg  }
571b0a0317aSmrgfi
572b0a0317aSmrg
573b0a0317aSmrg
574b0a0317aSmrg# func_append_quoted VAR VALUE
575b0a0317aSmrg# ----------------------------
576b0a0317aSmrg# Quote VALUE and append to the end of shell variable VAR, separated
577b0a0317aSmrg# by a space.
578b0a0317aSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
579b0a0317aSmrg  eval 'func_append_quoted ()
580b0a0317aSmrg  {
581b0a0317aSmrg    $debug_cmd
582b0a0317aSmrg
583b0a0317aSmrg    func_quote_for_eval "$2"
584b0a0317aSmrg    eval "$1+=\\ \$func_quote_for_eval_result"
585b0a0317aSmrg  }'
586b0a0317aSmrgelse
587b0a0317aSmrg  func_append_quoted ()
588b0a0317aSmrg  {
589b0a0317aSmrg    $debug_cmd
590b0a0317aSmrg
591b0a0317aSmrg    func_quote_for_eval "$2"
592b0a0317aSmrg    eval "$1=\$$1\\ \$func_quote_for_eval_result"
593b0a0317aSmrg  }
594b0a0317aSmrgfi
595b0a0317aSmrg
596b0a0317aSmrg
597b0a0317aSmrg# func_append_uniq VAR VALUE
598b0a0317aSmrg# --------------------------
599b0a0317aSmrg# Append unique VALUE onto the existing contents of VAR, assuming
600b0a0317aSmrg# entries are delimited by the first character of VALUE.  For example:
601b0a0317aSmrg#
602b0a0317aSmrg#   func_append_uniq options " --another-option option-argument"
603b0a0317aSmrg#
604b0a0317aSmrg# will only append to $options if " --another-option option-argument "
605b0a0317aSmrg# is not already present somewhere in $options already (note spaces at
606b0a0317aSmrg# each end implied by leading space in second argument).
607b0a0317aSmrgfunc_append_uniq ()
608b0a0317aSmrg{
609b0a0317aSmrg    $debug_cmd
610b0a0317aSmrg
611b0a0317aSmrg    eval _G_current_value='`$ECHO $'$1'`'
612b0a0317aSmrg    _G_delim=`expr "$2" : '\(.\)'`
613b0a0317aSmrg
614b0a0317aSmrg    case $_G_delim$_G_current_value$_G_delim in
615b0a0317aSmrg      *"$2$_G_delim"*) ;;
616b0a0317aSmrg      *) func_append "$@" ;;
617b0a0317aSmrg    esac
618b0a0317aSmrg}
619b0a0317aSmrg
620b0a0317aSmrg
621b0a0317aSmrg# func_arith TERM...
622b0a0317aSmrg# ------------------
623b0a0317aSmrg# Set func_arith_result to the result of evaluating TERMs.
624b0a0317aSmrg  test -z "$_G_HAVE_ARITH_OP" \
625b0a0317aSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
626b0a0317aSmrg    && _G_HAVE_ARITH_OP=yes
627b0a0317aSmrg
628b0a0317aSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
629b0a0317aSmrg  eval 'func_arith ()
630b0a0317aSmrg  {
631b0a0317aSmrg    $debug_cmd
632b0a0317aSmrg
633b0a0317aSmrg    func_arith_result=$(( $* ))
634b0a0317aSmrg  }'
635b0a0317aSmrgelse
636b0a0317aSmrg  func_arith ()
637b0a0317aSmrg  {
638b0a0317aSmrg    $debug_cmd
639b0a0317aSmrg
640b0a0317aSmrg    func_arith_result=`expr "$@"`
641b0a0317aSmrg  }
642b0a0317aSmrgfi
643b0a0317aSmrg
644b0a0317aSmrg
645b0a0317aSmrg# func_basename FILE
646b0a0317aSmrg# ------------------
647b0a0317aSmrg# Set func_basename_result to FILE with everything up to and including
648b0a0317aSmrg# the last / stripped.
649b0a0317aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
650b0a0317aSmrg  # If this shell supports suffix pattern removal, then use it to avoid
651b0a0317aSmrg  # forking. Hide the definitions single quotes in case the shell chokes
652b0a0317aSmrg  # on unsupported syntax...
653b0a0317aSmrg  _b='func_basename_result=${1##*/}'
654b0a0317aSmrg  _d='case $1 in
655b0a0317aSmrg        */*) func_dirname_result=${1%/*}$2 ;;
656b0a0317aSmrg        *  ) func_dirname_result=$3        ;;
657b0a0317aSmrg      esac'
658b0a0317aSmrg
659b0a0317aSmrgelse
660b0a0317aSmrg  # ...otherwise fall back to using sed.
661b0a0317aSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
662b0a0317aSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
663b0a0317aSmrg      if test "X$func_dirname_result" = "X$1"; then
664b0a0317aSmrg        func_dirname_result=$3
665b0a0317aSmrg      else
666b0a0317aSmrg        func_append func_dirname_result "$2"
667b0a0317aSmrg      fi'
668b0a0317aSmrgfi
669b0a0317aSmrg
670b0a0317aSmrgeval 'func_basename ()
671b0a0317aSmrg{
672b0a0317aSmrg    $debug_cmd
673b0a0317aSmrg
674b0a0317aSmrg    '"$_b"'
675b0a0317aSmrg}'
676b0a0317aSmrg
677b0a0317aSmrg
678b0a0317aSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
679b0a0317aSmrg# -------------------------------------------
680b0a0317aSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
681b0a0317aSmrg# otherwise set result to NONDIR_REPLACEMENT.
682b0a0317aSmrgeval 'func_dirname ()
683b0a0317aSmrg{
684b0a0317aSmrg    $debug_cmd
685b0a0317aSmrg
686b0a0317aSmrg    '"$_d"'
687b0a0317aSmrg}'
688b0a0317aSmrg
689b0a0317aSmrg
690b0a0317aSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
691b0a0317aSmrg# --------------------------------------------------------
692b0a0317aSmrg# Perform func_basename and func_dirname in a single function
693b0a0317aSmrg# call:
694b0a0317aSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
695b0a0317aSmrg#             add APPEND to the result, otherwise set result
696b0a0317aSmrg#             to NONDIR_REPLACEMENT.
697b0a0317aSmrg#             value returned in "$func_dirname_result"
698b0a0317aSmrg#   basename: Compute filename of FILE.
699b0a0317aSmrg#             value retuned in "$func_basename_result"
700b0a0317aSmrg# For efficiency, we do not delegate to the functions above but instead
701b0a0317aSmrg# duplicate the functionality here.
702b0a0317aSmrgeval 'func_dirname_and_basename ()
703b0a0317aSmrg{
704b0a0317aSmrg    $debug_cmd
705b0a0317aSmrg
706b0a0317aSmrg    '"$_b"'
707b0a0317aSmrg    '"$_d"'
708b0a0317aSmrg}'
709b0a0317aSmrg
710b0a0317aSmrg
711b0a0317aSmrg# func_echo ARG...
712b0a0317aSmrg# ----------------
713b0a0317aSmrg# Echo program name prefixed message.
714b0a0317aSmrgfunc_echo ()
715b0a0317aSmrg{
716b0a0317aSmrg    $debug_cmd
717b0a0317aSmrg
718b0a0317aSmrg    _G_message=$*
719b0a0317aSmrg
720b0a0317aSmrg    func_echo_IFS=$IFS
721b0a0317aSmrg    IFS=$nl
722b0a0317aSmrg    for _G_line in $_G_message; do
723b0a0317aSmrg      IFS=$func_echo_IFS
724b0a0317aSmrg      $ECHO "$progname: $_G_line"
725b0a0317aSmrg    done
726b0a0317aSmrg    IFS=$func_echo_IFS
727b0a0317aSmrg}
728b0a0317aSmrg
729b0a0317aSmrg
730b0a0317aSmrg# func_echo_all ARG...
731b0a0317aSmrg# --------------------
732b0a0317aSmrg# Invoke $ECHO with all args, space-separated.
733b0a0317aSmrgfunc_echo_all ()
734b0a0317aSmrg{
735b0a0317aSmrg    $ECHO "$*"
736b0a0317aSmrg}
737b0a0317aSmrg
738b0a0317aSmrg
739b0a0317aSmrg# func_echo_infix_1 INFIX ARG...
740b0a0317aSmrg# ------------------------------
741b0a0317aSmrg# Echo program name, followed by INFIX on the first line, with any
742b0a0317aSmrg# additional lines not showing INFIX.
743b0a0317aSmrgfunc_echo_infix_1 ()
744b0a0317aSmrg{
745b0a0317aSmrg    $debug_cmd
746b0a0317aSmrg
747b0a0317aSmrg    $require_term_colors
748b0a0317aSmrg
749b0a0317aSmrg    _G_infix=$1; shift
750b0a0317aSmrg    _G_indent=$_G_infix
751b0a0317aSmrg    _G_prefix="$progname: $_G_infix: "
752b0a0317aSmrg    _G_message=$*
753b0a0317aSmrg
754b0a0317aSmrg    # Strip color escape sequences before counting printable length
755b0a0317aSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
756b0a0317aSmrg    do
757b0a0317aSmrg      test -n "$_G_tc" && {
758b0a0317aSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
759b0a0317aSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
760b0a0317aSmrg      }
761b0a0317aSmrg    done
762b0a0317aSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
763b0a0317aSmrg
764b0a0317aSmrg    func_echo_infix_1_IFS=$IFS
765b0a0317aSmrg    IFS=$nl
766b0a0317aSmrg    for _G_line in $_G_message; do
767b0a0317aSmrg      IFS=$func_echo_infix_1_IFS
768b0a0317aSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
769b0a0317aSmrg      _G_prefix=$_G_indent
770b0a0317aSmrg    done
771b0a0317aSmrg    IFS=$func_echo_infix_1_IFS
772b0a0317aSmrg}
773b0a0317aSmrg
774b0a0317aSmrg
775b0a0317aSmrg# func_error ARG...
776b0a0317aSmrg# -----------------
777b0a0317aSmrg# Echo program name prefixed message to standard error.
778b0a0317aSmrgfunc_error ()
779b0a0317aSmrg{
780b0a0317aSmrg    $debug_cmd
781b0a0317aSmrg
782b0a0317aSmrg    $require_term_colors
783b0a0317aSmrg
784b0a0317aSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
785b0a0317aSmrg}
786b0a0317aSmrg
787b0a0317aSmrg
788b0a0317aSmrg# func_fatal_error ARG...
789b0a0317aSmrg# -----------------------
790b0a0317aSmrg# Echo program name prefixed message to standard error, and exit.
791b0a0317aSmrgfunc_fatal_error ()
792b0a0317aSmrg{
793b0a0317aSmrg    $debug_cmd
794b0a0317aSmrg
795b0a0317aSmrg    func_error "$*"
796b0a0317aSmrg    exit $EXIT_FAILURE
797b0a0317aSmrg}
798b0a0317aSmrg
799b0a0317aSmrg
800b0a0317aSmrg# func_grep EXPRESSION FILENAME
801b0a0317aSmrg# -----------------------------
802521070a0Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
803521070a0Smrgfunc_grep ()
804521070a0Smrg{
805b0a0317aSmrg    $debug_cmd
806b0a0317aSmrg
807521070a0Smrg    $GREP "$1" "$2" >/dev/null 2>&1
808521070a0Smrg}
809521070a0Smrg
810521070a0Smrg
811b0a0317aSmrg# func_len STRING
812b0a0317aSmrg# ---------------
813b0a0317aSmrg# Set func_len_result to the length of STRING. STRING may not
814b0a0317aSmrg# start with a hyphen.
815b0a0317aSmrg  test -z "$_G_HAVE_XSI_OPS" \
816b0a0317aSmrg    && (eval 'x=a/b/c;
817b0a0317aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
818b0a0317aSmrg    && _G_HAVE_XSI_OPS=yes
819b0a0317aSmrg
820b0a0317aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
821b0a0317aSmrg  eval 'func_len ()
822b0a0317aSmrg  {
823b0a0317aSmrg    $debug_cmd
824b0a0317aSmrg
825b0a0317aSmrg    func_len_result=${#1}
826b0a0317aSmrg  }'
827b0a0317aSmrgelse
828b0a0317aSmrg  func_len ()
829b0a0317aSmrg  {
830b0a0317aSmrg    $debug_cmd
831b0a0317aSmrg
832b0a0317aSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
833b0a0317aSmrg  }
834b0a0317aSmrgfi
835b0a0317aSmrg
836b0a0317aSmrg
837b0a0317aSmrg# func_mkdir_p DIRECTORY-PATH
838b0a0317aSmrg# ---------------------------
839521070a0Smrg# Make sure the entire path to DIRECTORY-PATH is available.
840521070a0Smrgfunc_mkdir_p ()
841521070a0Smrg{
842b0a0317aSmrg    $debug_cmd
843b0a0317aSmrg
844b0a0317aSmrg    _G_directory_path=$1
845b0a0317aSmrg    _G_dir_list=
846521070a0Smrg
847b0a0317aSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
848521070a0Smrg
849b0a0317aSmrg      # Protect directory names starting with '-'
850b0a0317aSmrg      case $_G_directory_path in
851b0a0317aSmrg        -*) _G_directory_path=./$_G_directory_path ;;
852521070a0Smrg      esac
853521070a0Smrg
854521070a0Smrg      # While some portion of DIR does not yet exist...
855b0a0317aSmrg      while test ! -d "$_G_directory_path"; do
856521070a0Smrg        # ...make a list in topmost first order.  Use a colon delimited
857521070a0Smrg	# list incase some portion of path contains whitespace.
858b0a0317aSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
859521070a0Smrg
860521070a0Smrg        # If the last portion added has no slash in it, the list is done
861b0a0317aSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
862521070a0Smrg
863521070a0Smrg        # ...otherwise throw away the child directory and loop
864b0a0317aSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
865521070a0Smrg      done
866b0a0317aSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
867521070a0Smrg
868b0a0317aSmrg      func_mkdir_p_IFS=$IFS; IFS=:
869b0a0317aSmrg      for _G_dir in $_G_dir_list; do
870b0a0317aSmrg	IFS=$func_mkdir_p_IFS
871b0a0317aSmrg        # mkdir can fail with a 'File exist' error if two processes
872521070a0Smrg        # try to create one of the directories concurrently.  Don't
873521070a0Smrg        # stop in that case!
874b0a0317aSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
875521070a0Smrg      done
876b0a0317aSmrg      IFS=$func_mkdir_p_IFS
877521070a0Smrg
878521070a0Smrg      # Bail out if we (or some other process) failed to create a directory.
879b0a0317aSmrg      test -d "$_G_directory_path" || \
880b0a0317aSmrg        func_fatal_error "Failed to create '$1'"
881521070a0Smrg    fi
882521070a0Smrg}
8834456fccdSmrg
8844456fccdSmrg
885b0a0317aSmrg# func_mktempdir [BASENAME]
886b0a0317aSmrg# -------------------------
8874456fccdSmrg# Make a temporary directory that won't clash with other running
8884456fccdSmrg# libtool processes, and avoids race conditions if possible.  If
889b0a0317aSmrg# given, BASENAME is the basename for that directory.
8904456fccdSmrgfunc_mktempdir ()
8914456fccdSmrg{
892b0a0317aSmrg    $debug_cmd
893b0a0317aSmrg
894b0a0317aSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
8954456fccdSmrg
896b0a0317aSmrg    if test : = "$opt_dry_run"; then
8974456fccdSmrg      # Return a directory name, but don't create it in dry-run mode
898b0a0317aSmrg      _G_tmpdir=$_G_template-$$
8994456fccdSmrg    else
9004456fccdSmrg
9014456fccdSmrg      # If mktemp works, use that first and foremost
902b0a0317aSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
9034456fccdSmrg
904b0a0317aSmrg      if test ! -d "$_G_tmpdir"; then
905521070a0Smrg        # Failing that, at least try and use $RANDOM to avoid a race
906b0a0317aSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
9074456fccdSmrg
908b0a0317aSmrg        func_mktempdir_umask=`umask`
909521070a0Smrg        umask 0077
910b0a0317aSmrg        $MKDIR "$_G_tmpdir"
911b0a0317aSmrg        umask $func_mktempdir_umask
9124456fccdSmrg      fi
9134456fccdSmrg
9144456fccdSmrg      # If we're not in dry-run mode, bomb out on failure
915b0a0317aSmrg      test -d "$_G_tmpdir" || \
916b0a0317aSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
9174456fccdSmrg    fi
9184456fccdSmrg
919b0a0317aSmrg    $ECHO "$_G_tmpdir"
9204456fccdSmrg}
9214456fccdSmrg
9224456fccdSmrg
923b0a0317aSmrg# func_normal_abspath PATH
924b0a0317aSmrg# ------------------------
925b0a0317aSmrg# Remove doubled-up and trailing slashes, "." path components,
926b0a0317aSmrg# and cancel out any ".." path components in PATH after making
927b0a0317aSmrg# it an absolute path.
928b0a0317aSmrgfunc_normal_abspath ()
9294456fccdSmrg{
930b0a0317aSmrg    $debug_cmd
931521070a0Smrg
932b0a0317aSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
933b0a0317aSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
934b0a0317aSmrg    _G_pathcdr='s|^/[^/]*||'
935b0a0317aSmrg    _G_removedotparts=':dotsl
936b0a0317aSmrg		s|/\./|/|g
937b0a0317aSmrg		t dotsl
938b0a0317aSmrg		s|/\.$|/|'
939b0a0317aSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
940b0a0317aSmrg    _G_finalslash='s|/*$|/|'
941b0a0317aSmrg
942b0a0317aSmrg    # Start from root dir and reassemble the path.
943b0a0317aSmrg    func_normal_abspath_result=
944b0a0317aSmrg    func_normal_abspath_tpath=$1
945b0a0317aSmrg    func_normal_abspath_altnamespace=
946b0a0317aSmrg    case $func_normal_abspath_tpath in
947b0a0317aSmrg      "")
948b0a0317aSmrg        # Empty path, that just means $cwd.
949b0a0317aSmrg        func_stripname '' '/' "`pwd`"
950b0a0317aSmrg        func_normal_abspath_result=$func_stripname_result
951b0a0317aSmrg        return
952b0a0317aSmrg        ;;
953b0a0317aSmrg      # The next three entries are used to spot a run of precisely
954b0a0317aSmrg      # two leading slashes without using negated character classes;
955b0a0317aSmrg      # we take advantage of case's first-match behaviour.
956b0a0317aSmrg      ///*)
957b0a0317aSmrg        # Unusual form of absolute path, do nothing.
958b0a0317aSmrg        ;;
959b0a0317aSmrg      //*)
960b0a0317aSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
961b0a0317aSmrg        # and for example Cygwin uses it to access remote file shares
962b0a0317aSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
963b0a0317aSmrg        func_normal_abspath_altnamespace=/
964b0a0317aSmrg        ;;
965b0a0317aSmrg      /*)
966b0a0317aSmrg        # Absolute path, do nothing.
967521070a0Smrg        ;;
968521070a0Smrg      *)
969b0a0317aSmrg        # Relative path, prepend $cwd.
970b0a0317aSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
971b0a0317aSmrg        ;;
9724456fccdSmrg    esac
973b0a0317aSmrg
974b0a0317aSmrg    # Cancel out all the simple stuff to save iterations.  We also want
975b0a0317aSmrg    # the path to end with a slash for ease of parsing, so make sure
976b0a0317aSmrg    # there is one (and only one) here.
977b0a0317aSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
978b0a0317aSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
979b0a0317aSmrg    while :; do
980b0a0317aSmrg      # Processed it all yet?
981b0a0317aSmrg      if test / = "$func_normal_abspath_tpath"; then
982b0a0317aSmrg        # If we ascended to the root using ".." the result may be empty now.
983b0a0317aSmrg        if test -z "$func_normal_abspath_result"; then
984b0a0317aSmrg          func_normal_abspath_result=/
985b0a0317aSmrg        fi
986b0a0317aSmrg        break
987b0a0317aSmrg      fi
988b0a0317aSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
989b0a0317aSmrg          -e "$_G_pathcar"`
990b0a0317aSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
991b0a0317aSmrg          -e "$_G_pathcdr"`
992b0a0317aSmrg      # Figure out what to do with it
993b0a0317aSmrg      case $func_normal_abspath_tcomponent in
994b0a0317aSmrg        "")
995b0a0317aSmrg          # Trailing empty path component, ignore it.
996b0a0317aSmrg          ;;
997b0a0317aSmrg        ..)
998b0a0317aSmrg          # Parent dir; strip last assembled component from result.
999b0a0317aSmrg          func_dirname "$func_normal_abspath_result"
1000b0a0317aSmrg          func_normal_abspath_result=$func_dirname_result
1001b0a0317aSmrg          ;;
1002b0a0317aSmrg        *)
1003b0a0317aSmrg          # Actual path component, append it.
1004b0a0317aSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1005b0a0317aSmrg          ;;
1006b0a0317aSmrg      esac
1007b0a0317aSmrg    done
1008b0a0317aSmrg    # Restore leading double-slash if one was found on entry.
1009b0a0317aSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1010b0a0317aSmrg}
1011b0a0317aSmrg
1012b0a0317aSmrg
1013b0a0317aSmrg# func_notquiet ARG...
1014b0a0317aSmrg# --------------------
1015b0a0317aSmrg# Echo program name prefixed message only when not in quiet mode.
1016b0a0317aSmrgfunc_notquiet ()
1017b0a0317aSmrg{
1018b0a0317aSmrg    $debug_cmd
1019b0a0317aSmrg
1020b0a0317aSmrg    $opt_quiet || func_echo ${1+"$@"}
1021b0a0317aSmrg
1022b0a0317aSmrg    # A bug in bash halts the script if the last line of a function
1023b0a0317aSmrg    # fails when set -e is in force, so we need another command to
1024b0a0317aSmrg    # work around that:
1025b0a0317aSmrg    :
1026b0a0317aSmrg}
1027b0a0317aSmrg
1028b0a0317aSmrg
1029b0a0317aSmrg# func_relative_path SRCDIR DSTDIR
1030b0a0317aSmrg# --------------------------------
1031b0a0317aSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1032b0a0317aSmrgfunc_relative_path ()
1033b0a0317aSmrg{
1034b0a0317aSmrg    $debug_cmd
1035b0a0317aSmrg
1036b0a0317aSmrg    func_relative_path_result=
1037b0a0317aSmrg    func_normal_abspath "$1"
1038b0a0317aSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
1039b0a0317aSmrg    func_normal_abspath "$2"
1040b0a0317aSmrg    func_relative_path_tbindir=$func_normal_abspath_result
1041b0a0317aSmrg
1042b0a0317aSmrg    # Ascend the tree starting from libdir
1043b0a0317aSmrg    while :; do
1044b0a0317aSmrg      # check if we have found a prefix of bindir
1045b0a0317aSmrg      case $func_relative_path_tbindir in
1046b0a0317aSmrg        $func_relative_path_tlibdir)
1047b0a0317aSmrg          # found an exact match
1048b0a0317aSmrg          func_relative_path_tcancelled=
1049b0a0317aSmrg          break
1050b0a0317aSmrg          ;;
1051b0a0317aSmrg        $func_relative_path_tlibdir*)
1052b0a0317aSmrg          # found a matching prefix
1053b0a0317aSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1054b0a0317aSmrg          func_relative_path_tcancelled=$func_stripname_result
1055b0a0317aSmrg          if test -z "$func_relative_path_result"; then
1056b0a0317aSmrg            func_relative_path_result=.
1057b0a0317aSmrg          fi
1058b0a0317aSmrg          break
1059b0a0317aSmrg          ;;
1060b0a0317aSmrg        *)
1061b0a0317aSmrg          func_dirname $func_relative_path_tlibdir
1062b0a0317aSmrg          func_relative_path_tlibdir=$func_dirname_result
1063b0a0317aSmrg          if test -z "$func_relative_path_tlibdir"; then
1064b0a0317aSmrg            # Have to descend all the way to the root!
1065b0a0317aSmrg            func_relative_path_result=../$func_relative_path_result
1066b0a0317aSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1067b0a0317aSmrg            break
1068b0a0317aSmrg          fi
1069b0a0317aSmrg          func_relative_path_result=../$func_relative_path_result
1070b0a0317aSmrg          ;;
1071b0a0317aSmrg      esac
1072b0a0317aSmrg    done
1073b0a0317aSmrg
1074b0a0317aSmrg    # Now calculate path; take care to avoid doubling-up slashes.
1075b0a0317aSmrg    func_stripname '' '/' "$func_relative_path_result"
1076b0a0317aSmrg    func_relative_path_result=$func_stripname_result
1077b0a0317aSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1078b0a0317aSmrg    if test -n "$func_stripname_result"; then
1079b0a0317aSmrg      func_append func_relative_path_result "/$func_stripname_result"
1080b0a0317aSmrg    fi
1081b0a0317aSmrg
1082b0a0317aSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1083b0a0317aSmrg    if test -n "$func_relative_path_result"; then
1084b0a0317aSmrg      func_stripname './' '' "$func_relative_path_result"
1085b0a0317aSmrg      func_relative_path_result=$func_stripname_result
1086b0a0317aSmrg    fi
1087b0a0317aSmrg
1088b0a0317aSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1089b0a0317aSmrg
1090b0a0317aSmrg    :
10914456fccdSmrg}
10924456fccdSmrg
10934456fccdSmrg
1094b0a0317aSmrg# func_quote_for_eval ARG...
1095b0a0317aSmrg# --------------------------
1096b0a0317aSmrg# Aesthetically quote ARGs to be evaled later.
1097b0a0317aSmrg# This function returns two values:
1098b0a0317aSmrg#   i) func_quote_for_eval_result
1099b0a0317aSmrg#      double-quoted, suitable for a subsequent eval
1100b0a0317aSmrg#  ii) func_quote_for_eval_unquoted_result
1101b0a0317aSmrg#      has all characters that are still active within double
1102b0a0317aSmrg#      quotes backslashified.
1103b0a0317aSmrgfunc_quote_for_eval ()
1104b0a0317aSmrg{
1105b0a0317aSmrg    $debug_cmd
1106b0a0317aSmrg
1107b0a0317aSmrg    func_quote_for_eval_unquoted_result=
1108b0a0317aSmrg    func_quote_for_eval_result=
1109b0a0317aSmrg    while test 0 -lt $#; do
1110b0a0317aSmrg      case $1 in
1111b0a0317aSmrg        *[\\\`\"\$]*)
1112b0a0317aSmrg	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
1113b0a0317aSmrg        *)
1114b0a0317aSmrg          _G_unquoted_arg=$1 ;;
1115b0a0317aSmrg      esac
1116b0a0317aSmrg      if test -n "$func_quote_for_eval_unquoted_result"; then
1117b0a0317aSmrg	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
1118b0a0317aSmrg      else
1119b0a0317aSmrg        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
1120b0a0317aSmrg      fi
1121b0a0317aSmrg
1122b0a0317aSmrg      case $_G_unquoted_arg in
1123b0a0317aSmrg        # Double-quote args containing shell metacharacters to delay
1124b0a0317aSmrg        # word splitting, command substitution and variable expansion
1125b0a0317aSmrg        # for a subsequent eval.
1126b0a0317aSmrg        # Many Bourne shells cannot handle close brackets correctly
1127b0a0317aSmrg        # in scan sets, so we specify it separately.
1128b0a0317aSmrg        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1129b0a0317aSmrg          _G_quoted_arg=\"$_G_unquoted_arg\"
1130b0a0317aSmrg          ;;
1131b0a0317aSmrg        *)
1132b0a0317aSmrg          _G_quoted_arg=$_G_unquoted_arg
1133b0a0317aSmrg	  ;;
1134b0a0317aSmrg      esac
1135b0a0317aSmrg
1136b0a0317aSmrg      if test -n "$func_quote_for_eval_result"; then
1137b0a0317aSmrg	func_append func_quote_for_eval_result " $_G_quoted_arg"
1138b0a0317aSmrg      else
1139b0a0317aSmrg        func_append func_quote_for_eval_result "$_G_quoted_arg"
1140b0a0317aSmrg      fi
1141b0a0317aSmrg      shift
1142b0a0317aSmrg    done
1143b0a0317aSmrg}
1144b0a0317aSmrg
1145b0a0317aSmrg
1146b0a0317aSmrg# func_quote_for_expand ARG
1147b0a0317aSmrg# -------------------------
1148521070a0Smrg# Aesthetically quote ARG to be evaled later; same as above,
1149521070a0Smrg# but do not quote variable references.
1150521070a0Smrgfunc_quote_for_expand ()
11514456fccdSmrg{
1152b0a0317aSmrg    $debug_cmd
1153b0a0317aSmrg
1154521070a0Smrg    case $1 in
1155521070a0Smrg      *[\\\`\"]*)
1156b0a0317aSmrg	_G_arg=`$ECHO "$1" | $SED \
1157b0a0317aSmrg	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
11584456fccdSmrg      *)
1159b0a0317aSmrg        _G_arg=$1 ;;
1160521070a0Smrg    esac
1161521070a0Smrg
1162b0a0317aSmrg    case $_G_arg in
1163521070a0Smrg      # Double-quote args containing shell metacharacters to delay
1164521070a0Smrg      # word splitting and command substitution for a subsequent eval.
1165521070a0Smrg      # Many Bourne shells cannot handle close brackets correctly
1166521070a0Smrg      # in scan sets, so we specify it separately.
1167521070a0Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1168b0a0317aSmrg        _G_arg=\"$_G_arg\"
1169521070a0Smrg        ;;
1170521070a0Smrg    esac
1171521070a0Smrg
1172b0a0317aSmrg    func_quote_for_expand_result=$_G_arg
1173b0a0317aSmrg}
1174b0a0317aSmrg
1175b0a0317aSmrg
1176b0a0317aSmrg# func_stripname PREFIX SUFFIX NAME
1177b0a0317aSmrg# ---------------------------------
1178b0a0317aSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1179b0a0317aSmrg# PREFIX and SUFFIX must not contain globbing or regex special
1180b0a0317aSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1181b0a0317aSmrg# dot (in which case that matches only a dot).
1182b0a0317aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
1183b0a0317aSmrg  eval 'func_stripname ()
1184b0a0317aSmrg  {
1185b0a0317aSmrg    $debug_cmd
1186b0a0317aSmrg
1187b0a0317aSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1188b0a0317aSmrg    # positional parameters, so assign one to ordinary variable first.
1189b0a0317aSmrg    func_stripname_result=$3
1190b0a0317aSmrg    func_stripname_result=${func_stripname_result#"$1"}
1191b0a0317aSmrg    func_stripname_result=${func_stripname_result%"$2"}
1192b0a0317aSmrg  }'
1193b0a0317aSmrgelse
1194b0a0317aSmrg  func_stripname ()
1195b0a0317aSmrg  {
1196b0a0317aSmrg    $debug_cmd
1197b0a0317aSmrg
1198b0a0317aSmrg    case $2 in
1199b0a0317aSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1200b0a0317aSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1201b0a0317aSmrg    esac
1202b0a0317aSmrg  }
1203b0a0317aSmrgfi
1204b0a0317aSmrg
1205b0a0317aSmrg
1206b0a0317aSmrg# func_show_eval CMD [FAIL_EXP]
1207b0a0317aSmrg# -----------------------------
1208b0a0317aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1209b0a0317aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1210b0a0317aSmrg# is given, then evaluate it.
1211b0a0317aSmrgfunc_show_eval ()
1212b0a0317aSmrg{
1213b0a0317aSmrg    $debug_cmd
1214b0a0317aSmrg
1215b0a0317aSmrg    _G_cmd=$1
1216b0a0317aSmrg    _G_fail_exp=${2-':'}
1217b0a0317aSmrg
1218b0a0317aSmrg    func_quote_for_expand "$_G_cmd"
1219b0a0317aSmrg    eval "func_notquiet $func_quote_for_expand_result"
1220b0a0317aSmrg
1221b0a0317aSmrg    $opt_dry_run || {
1222b0a0317aSmrg      eval "$_G_cmd"
1223b0a0317aSmrg      _G_status=$?
1224b0a0317aSmrg      if test 0 -ne "$_G_status"; then
1225b0a0317aSmrg	eval "(exit $_G_status); $_G_fail_exp"
1226b0a0317aSmrg      fi
1227b0a0317aSmrg    }
1228b0a0317aSmrg}
1229b0a0317aSmrg
1230b0a0317aSmrg
1231b0a0317aSmrg# func_show_eval_locale CMD [FAIL_EXP]
1232b0a0317aSmrg# ------------------------------------
1233b0a0317aSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1234b0a0317aSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1235b0a0317aSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
1236b0a0317aSmrgfunc_show_eval_locale ()
1237b0a0317aSmrg{
1238b0a0317aSmrg    $debug_cmd
1239b0a0317aSmrg
1240b0a0317aSmrg    _G_cmd=$1
1241b0a0317aSmrg    _G_fail_exp=${2-':'}
1242b0a0317aSmrg
1243b0a0317aSmrg    $opt_quiet || {
1244b0a0317aSmrg      func_quote_for_expand "$_G_cmd"
1245b0a0317aSmrg      eval "func_echo $func_quote_for_expand_result"
1246b0a0317aSmrg    }
1247b0a0317aSmrg
1248b0a0317aSmrg    $opt_dry_run || {
1249b0a0317aSmrg      eval "$_G_user_locale
1250b0a0317aSmrg	    $_G_cmd"
1251b0a0317aSmrg      _G_status=$?
1252b0a0317aSmrg      eval "$_G_safe_locale"
1253b0a0317aSmrg      if test 0 -ne "$_G_status"; then
1254b0a0317aSmrg	eval "(exit $_G_status); $_G_fail_exp"
1255b0a0317aSmrg      fi
1256b0a0317aSmrg    }
1257b0a0317aSmrg}
1258b0a0317aSmrg
1259b0a0317aSmrg
1260b0a0317aSmrg# func_tr_sh
1261b0a0317aSmrg# ----------
1262b0a0317aSmrg# Turn $1 into a string suitable for a shell variable name.
1263b0a0317aSmrg# Result is stored in $func_tr_sh_result.  All characters
1264b0a0317aSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1265b0a0317aSmrg# if $1 begins with a digit, a '_' is prepended as well.
1266b0a0317aSmrgfunc_tr_sh ()
1267b0a0317aSmrg{
1268b0a0317aSmrg    $debug_cmd
1269b0a0317aSmrg
1270b0a0317aSmrg    case $1 in
1271b0a0317aSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
1272b0a0317aSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1273b0a0317aSmrg      ;;
1274b0a0317aSmrg    * )
1275b0a0317aSmrg      func_tr_sh_result=$1
1276b0a0317aSmrg      ;;
1277b0a0317aSmrg    esac
1278b0a0317aSmrg}
1279b0a0317aSmrg
1280b0a0317aSmrg
1281b0a0317aSmrg# func_verbose ARG...
1282b0a0317aSmrg# -------------------
1283b0a0317aSmrg# Echo program name prefixed message in verbose mode only.
1284b0a0317aSmrgfunc_verbose ()
1285b0a0317aSmrg{
1286b0a0317aSmrg    $debug_cmd
1287b0a0317aSmrg
1288b0a0317aSmrg    $opt_verbose && func_echo "$*"
1289b0a0317aSmrg
1290b0a0317aSmrg    :
1291b0a0317aSmrg}
1292b0a0317aSmrg
1293b0a0317aSmrg
1294b0a0317aSmrg# func_warn_and_continue ARG...
1295b0a0317aSmrg# -----------------------------
1296b0a0317aSmrg# Echo program name prefixed warning message to standard error.
1297b0a0317aSmrgfunc_warn_and_continue ()
1298b0a0317aSmrg{
1299b0a0317aSmrg    $debug_cmd
1300b0a0317aSmrg
1301b0a0317aSmrg    $require_term_colors
1302b0a0317aSmrg
1303b0a0317aSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1304b0a0317aSmrg}
1305b0a0317aSmrg
1306b0a0317aSmrg
1307b0a0317aSmrg# func_warning CATEGORY ARG...
1308b0a0317aSmrg# ----------------------------
1309b0a0317aSmrg# Echo program name prefixed warning message to standard error. Warning
1310b0a0317aSmrg# messages can be filtered according to CATEGORY, where this function
1311b0a0317aSmrg# elides messages where CATEGORY is not listed in the global variable
1312b0a0317aSmrg# 'opt_warning_types'.
1313b0a0317aSmrgfunc_warning ()
1314b0a0317aSmrg{
1315b0a0317aSmrg    $debug_cmd
1316b0a0317aSmrg
1317b0a0317aSmrg    # CATEGORY must be in the warning_categories list!
1318b0a0317aSmrg    case " $warning_categories " in
1319b0a0317aSmrg      *" $1 "*) ;;
1320b0a0317aSmrg      *) func_internal_error "invalid warning category '$1'" ;;
1321b0a0317aSmrg    esac
1322b0a0317aSmrg
1323b0a0317aSmrg    _G_category=$1
1324b0a0317aSmrg    shift
1325b0a0317aSmrg
1326b0a0317aSmrg    case " $opt_warning_types " in
1327b0a0317aSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1328b0a0317aSmrg    esac
13294456fccdSmrg}
13304456fccdSmrg
13314456fccdSmrg
1332b0a0317aSmrg# func_sort_ver VER1 VER2
1333b0a0317aSmrg# -----------------------
1334b0a0317aSmrg# 'sort -V' is not generally available.
1335b0a0317aSmrg# Note this deviates from the version comparison in automake
1336b0a0317aSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1337b0a0317aSmrg# but this should suffice as we won't be specifying old
1338b0a0317aSmrg# version formats or redundant trailing .0 in bootstrap.conf.
1339b0a0317aSmrg# If we did want full compatibility then we should probably
1340b0a0317aSmrg# use m4_version_compare from autoconf.
1341b0a0317aSmrgfunc_sort_ver ()
1342b0a0317aSmrg{
1343b0a0317aSmrg    $debug_cmd
1344b0a0317aSmrg
1345b0a0317aSmrg    printf '%s\n%s\n' "$1" "$2" \
1346b0a0317aSmrg      | 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
1347b0a0317aSmrg}
1348b0a0317aSmrg
1349b0a0317aSmrg# func_lt_ver PREV CURR
1350b0a0317aSmrg# ---------------------
1351b0a0317aSmrg# Return true if PREV and CURR are in the correct order according to
1352b0a0317aSmrg# func_sort_ver, otherwise false.  Use it like this:
1353b0a0317aSmrg#
1354b0a0317aSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1355b0a0317aSmrgfunc_lt_ver ()
1356b0a0317aSmrg{
1357b0a0317aSmrg    $debug_cmd
1358b0a0317aSmrg
1359b0a0317aSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1360b0a0317aSmrg}
1361b0a0317aSmrg
1362b0a0317aSmrg
1363b0a0317aSmrg# Local variables:
1364b0a0317aSmrg# mode: shell-script
1365b0a0317aSmrg# sh-indentation: 2
1366b0a0317aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1367b0a0317aSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1368b0a0317aSmrg# time-stamp-time-zone: "UTC"
1369b0a0317aSmrg# End:
1370b0a0317aSmrg#! /bin/sh
1371b0a0317aSmrg
1372b0a0317aSmrg# Set a version string for this script.
1373b0a0317aSmrgscriptversion=2014-01-07.03; # UTC
1374b0a0317aSmrg
1375b0a0317aSmrg# A portable, pluggable option parser for Bourne shell.
1376b0a0317aSmrg# Written by Gary V. Vaughan, 2010
1377b0a0317aSmrg
1378b0a0317aSmrg# Copyright (C) 2010-2015 Free Software Foundation, Inc.
1379b0a0317aSmrg# This is free software; see the source for copying conditions.  There is NO
1380b0a0317aSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1381b0a0317aSmrg
1382b0a0317aSmrg# This program is free software: you can redistribute it and/or modify
1383b0a0317aSmrg# it under the terms of the GNU General Public License as published by
1384b0a0317aSmrg# the Free Software Foundation, either version 3 of the License, or
1385b0a0317aSmrg# (at your option) any later version.
1386b0a0317aSmrg
1387b0a0317aSmrg# This program is distributed in the hope that it will be useful,
1388b0a0317aSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1389b0a0317aSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1390b0a0317aSmrg# GNU General Public License for more details.
1391b0a0317aSmrg
1392b0a0317aSmrg# You should have received a copy of the GNU General Public License
1393b0a0317aSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1394b0a0317aSmrg
1395b0a0317aSmrg# Please report bugs or propose patches to gary@gnu.org.
1396b0a0317aSmrg
1397b0a0317aSmrg
1398b0a0317aSmrg## ------ ##
1399b0a0317aSmrg## Usage. ##
1400b0a0317aSmrg## ------ ##
1401b0a0317aSmrg
1402b0a0317aSmrg# This file is a library for parsing options in your shell scripts along
1403b0a0317aSmrg# with assorted other useful supporting features that you can make use
1404b0a0317aSmrg# of too.
1405b0a0317aSmrg#
1406b0a0317aSmrg# For the simplest scripts you might need only:
1407b0a0317aSmrg#
1408b0a0317aSmrg#   #!/bin/sh
1409b0a0317aSmrg#   . relative/path/to/funclib.sh
1410b0a0317aSmrg#   . relative/path/to/options-parser
1411b0a0317aSmrg#   scriptversion=1.0
1412b0a0317aSmrg#   func_options ${1+"$@"}
1413b0a0317aSmrg#   eval set dummy "$func_options_result"; shift
1414b0a0317aSmrg#   ...rest of your script...
1415b0a0317aSmrg#
1416b0a0317aSmrg# In order for the '--version' option to work, you will need to have a
1417b0a0317aSmrg# suitably formatted comment like the one at the top of this file
1418b0a0317aSmrg# starting with '# Written by ' and ending with '# warranty; '.
1419b0a0317aSmrg#
1420b0a0317aSmrg# For '-h' and '--help' to work, you will also need a one line
1421b0a0317aSmrg# description of your script's purpose in a comment directly above the
1422b0a0317aSmrg# '# Written by ' line, like the one at the top of this file.
1423b0a0317aSmrg#
1424b0a0317aSmrg# The default options also support '--debug', which will turn on shell
1425b0a0317aSmrg# execution tracing (see the comment above debug_cmd below for another
1426b0a0317aSmrg# use), and '--verbose' and the func_verbose function to allow your script
1427b0a0317aSmrg# to display verbose messages only when your user has specified
1428b0a0317aSmrg# '--verbose'.
1429b0a0317aSmrg#
1430b0a0317aSmrg# After sourcing this file, you can plug processing for additional
1431b0a0317aSmrg# options by amending the variables from the 'Configuration' section
1432b0a0317aSmrg# below, and following the instructions in the 'Option parsing'
1433b0a0317aSmrg# section further down.
1434b0a0317aSmrg
1435b0a0317aSmrg## -------------- ##
1436b0a0317aSmrg## Configuration. ##
1437b0a0317aSmrg## -------------- ##
1438b0a0317aSmrg
1439b0a0317aSmrg# You should override these variables in your script after sourcing this
1440b0a0317aSmrg# file so that they reflect the customisations you have added to the
1441b0a0317aSmrg# option parser.
1442b0a0317aSmrg
1443b0a0317aSmrg# The usage line for option parsing errors and the start of '-h' and
1444b0a0317aSmrg# '--help' output messages. You can embed shell variables for delayed
1445b0a0317aSmrg# expansion at the time the message is displayed, but you will need to
1446b0a0317aSmrg# quote other shell meta-characters carefully to prevent them being
1447b0a0317aSmrg# expanded when the contents are evaled.
1448b0a0317aSmrgusage='$progpath [OPTION]...'
1449b0a0317aSmrg
1450b0a0317aSmrg# Short help message in response to '-h' and '--help'.  Add to this or
1451b0a0317aSmrg# override it after sourcing this library to reflect the full set of
1452b0a0317aSmrg# options your script accepts.
1453b0a0317aSmrgusage_message="\
1454b0a0317aSmrg       --debug        enable verbose shell tracing
1455b0a0317aSmrg   -W, --warnings=CATEGORY
1456b0a0317aSmrg                      report the warnings falling in CATEGORY [all]
1457b0a0317aSmrg   -v, --verbose      verbosely report processing
1458b0a0317aSmrg       --version      print version information and exit
1459b0a0317aSmrg   -h, --help         print short or long help message and exit
1460b0a0317aSmrg"
1461b0a0317aSmrg
1462b0a0317aSmrg# Additional text appended to 'usage_message' in response to '--help'.
1463b0a0317aSmrglong_help_message="
1464b0a0317aSmrgWarning categories include:
1465b0a0317aSmrg       'all'          show all warnings
1466b0a0317aSmrg       'none'         turn off all the warnings
1467b0a0317aSmrg       'error'        warnings are treated as fatal errors"
1468b0a0317aSmrg
1469b0a0317aSmrg# Help message printed before fatal option parsing errors.
1470b0a0317aSmrgfatal_help="Try '\$progname --help' for more information."
1471b0a0317aSmrg
1472b0a0317aSmrg
1473b0a0317aSmrg
1474b0a0317aSmrg## ------------------------- ##
1475b0a0317aSmrg## Hook function management. ##
1476b0a0317aSmrg## ------------------------- ##
1477b0a0317aSmrg
1478b0a0317aSmrg# This section contains functions for adding, removing, and running hooks
1479b0a0317aSmrg# to the main code.  A hook is just a named list of of function, that can
1480b0a0317aSmrg# be run in order later on.
1481b0a0317aSmrg
1482b0a0317aSmrg# func_hookable FUNC_NAME
1483b0a0317aSmrg# -----------------------
1484b0a0317aSmrg# Declare that FUNC_NAME will run hooks added with
1485b0a0317aSmrg# 'func_add_hook FUNC_NAME ...'.
1486b0a0317aSmrgfunc_hookable ()
1487b0a0317aSmrg{
1488b0a0317aSmrg    $debug_cmd
1489b0a0317aSmrg
1490b0a0317aSmrg    func_append hookable_fns " $1"
1491b0a0317aSmrg}
1492b0a0317aSmrg
1493b0a0317aSmrg
1494b0a0317aSmrg# func_add_hook FUNC_NAME HOOK_FUNC
1495b0a0317aSmrg# ---------------------------------
1496b0a0317aSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1497b0a0317aSmrg# first have been declared "hookable" by a call to 'func_hookable'.
1498b0a0317aSmrgfunc_add_hook ()
1499b0a0317aSmrg{
1500b0a0317aSmrg    $debug_cmd
1501b0a0317aSmrg
1502b0a0317aSmrg    case " $hookable_fns " in
1503b0a0317aSmrg      *" $1 "*) ;;
1504b0a0317aSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1505b0a0317aSmrg    esac
1506b0a0317aSmrg
1507b0a0317aSmrg    eval func_append ${1}_hooks '" $2"'
1508b0a0317aSmrg}
1509b0a0317aSmrg
1510b0a0317aSmrg
1511b0a0317aSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
1512b0a0317aSmrg# ------------------------------------
1513b0a0317aSmrg# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1514b0a0317aSmrgfunc_remove_hook ()
1515b0a0317aSmrg{
1516b0a0317aSmrg    $debug_cmd
1517b0a0317aSmrg
1518b0a0317aSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1519b0a0317aSmrg}
1520b0a0317aSmrg
1521b0a0317aSmrg
1522b0a0317aSmrg# func_run_hooks FUNC_NAME [ARG]...
1523b0a0317aSmrg# ---------------------------------
1524b0a0317aSmrg# Run all hook functions registered to FUNC_NAME.
1525b0a0317aSmrg# It is assumed that the list of hook functions contains nothing more
1526b0a0317aSmrg# than a whitespace-delimited list of legal shell function names, and
1527b0a0317aSmrg# no effort is wasted trying to catch shell meta-characters or preserve
1528b0a0317aSmrg# whitespace.
1529b0a0317aSmrgfunc_run_hooks ()
1530b0a0317aSmrg{
1531b0a0317aSmrg    $debug_cmd
1532b0a0317aSmrg
1533b0a0317aSmrg    case " $hookable_fns " in
1534b0a0317aSmrg      *" $1 "*) ;;
1535b0a0317aSmrg      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1536b0a0317aSmrg    esac
1537b0a0317aSmrg
1538b0a0317aSmrg    eval _G_hook_fns=\$$1_hooks; shift
1539b0a0317aSmrg
1540b0a0317aSmrg    for _G_hook in $_G_hook_fns; do
1541b0a0317aSmrg      eval $_G_hook '"$@"'
1542b0a0317aSmrg
1543b0a0317aSmrg      # store returned options list back into positional
1544b0a0317aSmrg      # parameters for next 'cmd' execution.
1545b0a0317aSmrg      eval _G_hook_result=\$${_G_hook}_result
1546b0a0317aSmrg      eval set dummy "$_G_hook_result"; shift
1547b0a0317aSmrg    done
1548b0a0317aSmrg
1549b0a0317aSmrg    func_quote_for_eval ${1+"$@"}
1550b0a0317aSmrg    func_run_hooks_result=$func_quote_for_eval_result
1551b0a0317aSmrg}
1552b0a0317aSmrg
1553b0a0317aSmrg
1554b0a0317aSmrg
1555b0a0317aSmrg## --------------- ##
1556b0a0317aSmrg## Option parsing. ##
1557b0a0317aSmrg## --------------- ##
1558b0a0317aSmrg
1559b0a0317aSmrg# In order to add your own option parsing hooks, you must accept the
1560b0a0317aSmrg# full positional parameter list in your hook function, remove any
1561b0a0317aSmrg# options that you action, and then pass back the remaining unprocessed
1562b0a0317aSmrg# options in '<hooked_function_name>_result', escaped suitably for
1563b0a0317aSmrg# 'eval'.  Like this:
1564b0a0317aSmrg#
1565b0a0317aSmrg#    my_options_prep ()
1566b0a0317aSmrg#    {
1567b0a0317aSmrg#        $debug_cmd
1568b0a0317aSmrg#
1569b0a0317aSmrg#        # Extend the existing usage message.
1570b0a0317aSmrg#        usage_message=$usage_message'
1571b0a0317aSmrg#      -s, --silent       don'\''t print informational messages
1572b0a0317aSmrg#    '
1573b0a0317aSmrg#
1574b0a0317aSmrg#        func_quote_for_eval ${1+"$@"}
1575b0a0317aSmrg#        my_options_prep_result=$func_quote_for_eval_result
1576b0a0317aSmrg#    }
1577b0a0317aSmrg#    func_add_hook func_options_prep my_options_prep
1578b0a0317aSmrg#
1579b0a0317aSmrg#
1580b0a0317aSmrg#    my_silent_option ()
1581b0a0317aSmrg#    {
1582b0a0317aSmrg#        $debug_cmd
1583b0a0317aSmrg#
1584b0a0317aSmrg#        # Note that for efficiency, we parse as many options as we can
1585b0a0317aSmrg#        # recognise in a loop before passing the remainder back to the
1586b0a0317aSmrg#        # caller on the first unrecognised argument we encounter.
1587b0a0317aSmrg#        while test $# -gt 0; do
1588b0a0317aSmrg#          opt=$1; shift
1589b0a0317aSmrg#          case $opt in
1590b0a0317aSmrg#            --silent|-s) opt_silent=: ;;
1591b0a0317aSmrg#            # Separate non-argument short options:
1592b0a0317aSmrg#            -s*)         func_split_short_opt "$_G_opt"
1593b0a0317aSmrg#                         set dummy "$func_split_short_opt_name" \
1594b0a0317aSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1595b0a0317aSmrg#                         shift
1596b0a0317aSmrg#                         ;;
1597b0a0317aSmrg#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
1598b0a0317aSmrg#          esac
1599b0a0317aSmrg#        done
1600b0a0317aSmrg#
1601b0a0317aSmrg#        func_quote_for_eval ${1+"$@"}
1602b0a0317aSmrg#        my_silent_option_result=$func_quote_for_eval_result
1603b0a0317aSmrg#    }
1604b0a0317aSmrg#    func_add_hook func_parse_options my_silent_option
1605b0a0317aSmrg#
1606b0a0317aSmrg#
1607b0a0317aSmrg#    my_option_validation ()
1608b0a0317aSmrg#    {
1609b0a0317aSmrg#        $debug_cmd
1610b0a0317aSmrg#
1611b0a0317aSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1612b0a0317aSmrg#    '--silent' and '--verbose' options are mutually exclusive."
1613b0a0317aSmrg#
1614b0a0317aSmrg#        func_quote_for_eval ${1+"$@"}
1615b0a0317aSmrg#        my_option_validation_result=$func_quote_for_eval_result
1616b0a0317aSmrg#    }
1617b0a0317aSmrg#    func_add_hook func_validate_options my_option_validation
1618b0a0317aSmrg#
1619b0a0317aSmrg# You'll alse need to manually amend $usage_message to reflect the extra
1620b0a0317aSmrg# options you parse.  It's preferable to append if you can, so that
1621b0a0317aSmrg# multiple option parsing hooks can be added safely.
1622b0a0317aSmrg
1623b0a0317aSmrg
1624b0a0317aSmrg# func_options [ARG]...
1625b0a0317aSmrg# ---------------------
1626b0a0317aSmrg# All the functions called inside func_options are hookable. See the
1627b0a0317aSmrg# individual implementations for details.
1628b0a0317aSmrgfunc_hookable func_options
1629b0a0317aSmrgfunc_options ()
16304456fccdSmrg{
1631b0a0317aSmrg    $debug_cmd
16324456fccdSmrg
1633b0a0317aSmrg    func_options_prep ${1+"$@"}
1634b0a0317aSmrg    eval func_parse_options \
1635b0a0317aSmrg        ${func_options_prep_result+"$func_options_prep_result"}
1636b0a0317aSmrg    eval func_validate_options \
1637b0a0317aSmrg        ${func_parse_options_result+"$func_parse_options_result"}
1638521070a0Smrg
1639b0a0317aSmrg    eval func_run_hooks func_options \
1640b0a0317aSmrg        ${func_validate_options_result+"$func_validate_options_result"}
1641b0a0317aSmrg
1642b0a0317aSmrg    # save modified positional parameters for caller
1643b0a0317aSmrg    func_options_result=$func_run_hooks_result
16444456fccdSmrg}
16454456fccdSmrg
1646521070a0Smrg
1647b0a0317aSmrg# func_options_prep [ARG]...
1648b0a0317aSmrg# --------------------------
1649b0a0317aSmrg# All initialisations required before starting the option parse loop.
1650b0a0317aSmrg# Note that when calling hook functions, we pass through the list of
1651b0a0317aSmrg# positional parameters.  If a hook function modifies that list, and
1652b0a0317aSmrg# needs to propogate that back to rest of this script, then the complete
1653b0a0317aSmrg# modified list must be put in 'func_run_hooks_result' before
1654b0a0317aSmrg# returning.
1655b0a0317aSmrgfunc_hookable func_options_prep
1656b0a0317aSmrgfunc_options_prep ()
16574456fccdSmrg{
1658b0a0317aSmrg    $debug_cmd
1659521070a0Smrg
1660b0a0317aSmrg    # Option defaults:
1661b0a0317aSmrg    opt_verbose=false
1662b0a0317aSmrg    opt_warning_types=
1663521070a0Smrg
1664b0a0317aSmrg    func_run_hooks func_options_prep ${1+"$@"}
1665b0a0317aSmrg
1666b0a0317aSmrg    # save modified positional parameters for caller
1667b0a0317aSmrg    func_options_prep_result=$func_run_hooks_result
1668521070a0Smrg}
16694456fccdSmrg
1670b0a0317aSmrg
1671b0a0317aSmrg# func_parse_options [ARG]...
1672b0a0317aSmrg# ---------------------------
1673b0a0317aSmrg# The main option parsing loop.
1674b0a0317aSmrgfunc_hookable func_parse_options
1675b0a0317aSmrgfunc_parse_options ()
16763e6c936aSmrg{
1677b0a0317aSmrg    $debug_cmd
1678b0a0317aSmrg
1679b0a0317aSmrg    func_parse_options_result=
1680b0a0317aSmrg
1681b0a0317aSmrg    # this just eases exit handling
1682b0a0317aSmrg    while test $# -gt 0; do
1683b0a0317aSmrg      # Defer to hook functions for initial option parsing, so they
1684b0a0317aSmrg      # get priority in the event of reusing an option name.
1685b0a0317aSmrg      func_run_hooks func_parse_options ${1+"$@"}
1686b0a0317aSmrg
1687b0a0317aSmrg      # Adjust func_parse_options positional parameters to match
1688b0a0317aSmrg      eval set dummy "$func_run_hooks_result"; shift
1689b0a0317aSmrg
1690b0a0317aSmrg      # Break out of the loop if we already parsed every option.
1691b0a0317aSmrg      test $# -gt 0 || break
1692b0a0317aSmrg
1693b0a0317aSmrg      _G_opt=$1
1694b0a0317aSmrg      shift
1695b0a0317aSmrg      case $_G_opt in
1696b0a0317aSmrg        --debug|-x)   debug_cmd='set -x'
1697b0a0317aSmrg                      func_echo "enabling shell trace mode"
1698b0a0317aSmrg                      $debug_cmd
1699b0a0317aSmrg                      ;;
1700b0a0317aSmrg
1701b0a0317aSmrg        --no-warnings|--no-warning|--no-warn)
1702b0a0317aSmrg                      set dummy --warnings none ${1+"$@"}
1703b0a0317aSmrg                      shift
1704b0a0317aSmrg		      ;;
1705b0a0317aSmrg
1706b0a0317aSmrg        --warnings|--warning|-W)
1707b0a0317aSmrg                      test $# = 0 && func_missing_arg $_G_opt && break
1708b0a0317aSmrg                      case " $warning_categories $1" in
1709b0a0317aSmrg                        *" $1 "*)
1710b0a0317aSmrg                          # trailing space prevents matching last $1 above
1711b0a0317aSmrg                          func_append_uniq opt_warning_types " $1"
1712b0a0317aSmrg                          ;;
1713b0a0317aSmrg                        *all)
1714b0a0317aSmrg                          opt_warning_types=$warning_categories
1715b0a0317aSmrg                          ;;
1716b0a0317aSmrg                        *none)
1717b0a0317aSmrg                          opt_warning_types=none
1718b0a0317aSmrg                          warning_func=:
1719b0a0317aSmrg                          ;;
1720b0a0317aSmrg                        *error)
1721b0a0317aSmrg                          opt_warning_types=$warning_categories
1722b0a0317aSmrg                          warning_func=func_fatal_error
1723b0a0317aSmrg                          ;;
1724b0a0317aSmrg                        *)
1725b0a0317aSmrg                          func_fatal_error \
1726b0a0317aSmrg                             "unsupported warning category: '$1'"
1727b0a0317aSmrg                          ;;
1728b0a0317aSmrg                      esac
1729b0a0317aSmrg                      shift
1730b0a0317aSmrg                      ;;
1731b0a0317aSmrg
1732b0a0317aSmrg        --verbose|-v) opt_verbose=: ;;
1733b0a0317aSmrg        --version)    func_version ;;
1734b0a0317aSmrg        -\?|-h)       func_usage ;;
1735b0a0317aSmrg        --help)       func_help ;;
1736b0a0317aSmrg
1737b0a0317aSmrg	# Separate optargs to long options (plugins may need this):
1738b0a0317aSmrg	--*=*)        func_split_equals "$_G_opt"
1739b0a0317aSmrg	              set dummy "$func_split_equals_lhs" \
1740b0a0317aSmrg                          "$func_split_equals_rhs" ${1+"$@"}
1741b0a0317aSmrg                      shift
1742b0a0317aSmrg                      ;;
1743b0a0317aSmrg
1744b0a0317aSmrg       # Separate optargs to short options:
1745b0a0317aSmrg        -W*)
1746b0a0317aSmrg                      func_split_short_opt "$_G_opt"
1747b0a0317aSmrg                      set dummy "$func_split_short_opt_name" \
1748b0a0317aSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
1749b0a0317aSmrg                      shift
1750b0a0317aSmrg                      ;;
1751b0a0317aSmrg
1752b0a0317aSmrg        # Separate non-argument short options:
1753b0a0317aSmrg        -\?*|-h*|-v*|-x*)
1754b0a0317aSmrg                      func_split_short_opt "$_G_opt"
1755b0a0317aSmrg                      set dummy "$func_split_short_opt_name" \
1756b0a0317aSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1757b0a0317aSmrg                      shift
1758b0a0317aSmrg                      ;;
1759b0a0317aSmrg
1760b0a0317aSmrg        --)           break ;;
1761b0a0317aSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1762b0a0317aSmrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1763b0a0317aSmrg      esac
1764b0a0317aSmrg    done
1765b0a0317aSmrg
1766b0a0317aSmrg    # save modified positional parameters for caller
1767b0a0317aSmrg    func_quote_for_eval ${1+"$@"}
1768b0a0317aSmrg    func_parse_options_result=$func_quote_for_eval_result
17693e6c936aSmrg}
17703e6c936aSmrg
17714456fccdSmrg
1772b0a0317aSmrg# func_validate_options [ARG]...
1773b0a0317aSmrg# ------------------------------
1774b0a0317aSmrg# Perform any sanity checks on option settings and/or unconsumed
1775b0a0317aSmrg# arguments.
1776b0a0317aSmrgfunc_hookable func_validate_options
1777b0a0317aSmrgfunc_validate_options ()
1778521070a0Smrg{
1779b0a0317aSmrg    $debug_cmd
17803e6c936aSmrg
1781b0a0317aSmrg    # Display all warnings if -W was not given.
1782b0a0317aSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1783b0a0317aSmrg
1784b0a0317aSmrg    func_run_hooks func_validate_options ${1+"$@"}
1785b0a0317aSmrg
1786b0a0317aSmrg    # Bail if the options were screwed!
1787b0a0317aSmrg    $exit_cmd $EXIT_FAILURE
1788b0a0317aSmrg
1789b0a0317aSmrg    # save modified positional parameters for caller
1790b0a0317aSmrg    func_validate_options_result=$func_run_hooks_result
1791521070a0Smrg}
1792521070a0Smrg
1793b0a0317aSmrg
1794b0a0317aSmrg
1795b0a0317aSmrg## ----------------- ##
1796b0a0317aSmrg## Helper functions. ##
1797b0a0317aSmrg## ----------------- ##
1798b0a0317aSmrg
1799b0a0317aSmrg# This section contains the helper functions used by the rest of the
1800b0a0317aSmrg# hookable option parser framework in ascii-betical order.
1801b0a0317aSmrg
1802b0a0317aSmrg
1803b0a0317aSmrg# func_fatal_help ARG...
1804b0a0317aSmrg# ----------------------
1805b0a0317aSmrg# Echo program name prefixed message to standard error, followed by
1806b0a0317aSmrg# a help hint, and exit.
1807b0a0317aSmrgfunc_fatal_help ()
1808521070a0Smrg{
1809b0a0317aSmrg    $debug_cmd
18103e6c936aSmrg
1811b0a0317aSmrg    eval \$ECHO \""Usage: $usage"\"
1812b0a0317aSmrg    eval \$ECHO \""$fatal_help"\"
1813b0a0317aSmrg    func_error ${1+"$@"}
1814b0a0317aSmrg    exit $EXIT_FAILURE
1815521070a0Smrg}
1816521070a0Smrg
1817b0a0317aSmrg
1818b0a0317aSmrg# func_help
1819b0a0317aSmrg# ---------
1820b0a0317aSmrg# Echo long help message to standard output and exit.
1821521070a0Smrgfunc_help ()
1822521070a0Smrg{
1823b0a0317aSmrg    $debug_cmd
1824b0a0317aSmrg
1825b0a0317aSmrg    func_usage_message
1826b0a0317aSmrg    $ECHO "$long_help_message"
1827b0a0317aSmrg    exit 0
1828521070a0Smrg}
1829521070a0Smrg
1830b0a0317aSmrg
1831b0a0317aSmrg# func_missing_arg ARGNAME
1832b0a0317aSmrg# ------------------------
1833521070a0Smrg# Echo program name prefixed message to standard error and set global
1834521070a0Smrg# exit_cmd.
1835521070a0Smrgfunc_missing_arg ()
1836521070a0Smrg{
1837b0a0317aSmrg    $debug_cmd
18383e6c936aSmrg
1839b0a0317aSmrg    func_error "Missing argument for '$1'."
1840521070a0Smrg    exit_cmd=exit
18414456fccdSmrg}
18424456fccdSmrg
18434456fccdSmrg
1844b0a0317aSmrg# func_split_equals STRING
1845b0a0317aSmrg# ------------------------
1846b0a0317aSmrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
1847b0a0317aSmrg# splitting STRING at the '=' sign.
1848b0a0317aSmrgtest -z "$_G_HAVE_XSI_OPS" \
1849b0a0317aSmrg    && (eval 'x=a/b/c;
1850b0a0317aSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
1851b0a0317aSmrg    && _G_HAVE_XSI_OPS=yes
1852b0a0317aSmrg
1853b0a0317aSmrgif test yes = "$_G_HAVE_XSI_OPS"
1854b0a0317aSmrgthen
1855b0a0317aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
1856b0a0317aSmrg  eval 'func_split_equals ()
1857b0a0317aSmrg  {
1858b0a0317aSmrg      $debug_cmd
1859b0a0317aSmrg
1860b0a0317aSmrg      func_split_equals_lhs=${1%%=*}
1861b0a0317aSmrg      func_split_equals_rhs=${1#*=}
1862b0a0317aSmrg      test "x$func_split_equals_lhs" = "x$1" \
1863b0a0317aSmrg        && func_split_equals_rhs=
1864b0a0317aSmrg  }'
1865b0a0317aSmrgelse
1866b0a0317aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1867b0a0317aSmrg  func_split_equals ()
1868b0a0317aSmrg  {
1869b0a0317aSmrg      $debug_cmd
1870b0a0317aSmrg
1871b0a0317aSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
1872b0a0317aSmrg      func_split_equals_rhs=
1873b0a0317aSmrg      test "x$func_split_equals_lhs" = "x$1" \
1874b0a0317aSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
1875b0a0317aSmrg  }
1876b0a0317aSmrgfi #func_split_equals
1877b0a0317aSmrg
1878b0a0317aSmrg
1879b0a0317aSmrg# func_split_short_opt SHORTOPT
1880b0a0317aSmrg# -----------------------------
18813e6c936aSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
18823e6c936aSmrg# variables after splitting SHORTOPT after the 2nd character.
1883b0a0317aSmrgif test yes = "$_G_HAVE_XSI_OPS"
1884b0a0317aSmrgthen
1885b0a0317aSmrg  # This is an XSI compatible shell, allowing a faster implementation...
1886b0a0317aSmrg  eval 'func_split_short_opt ()
1887b0a0317aSmrg  {
1888b0a0317aSmrg      $debug_cmd
1889b0a0317aSmrg
1890b0a0317aSmrg      func_split_short_opt_arg=${1#??}
1891b0a0317aSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1892b0a0317aSmrg  }'
1893b0a0317aSmrgelse
1894b0a0317aSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1895b0a0317aSmrg  func_split_short_opt ()
1896b0a0317aSmrg  {
1897b0a0317aSmrg      $debug_cmd
1898b0a0317aSmrg
1899b0a0317aSmrg      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1900b0a0317aSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1901b0a0317aSmrg  }
1902b0a0317aSmrgfi #func_split_short_opt
1903b0a0317aSmrg
1904b0a0317aSmrg
1905b0a0317aSmrg# func_usage
1906b0a0317aSmrg# ----------
1907b0a0317aSmrg# Echo short help message to standard output and exit.
1908b0a0317aSmrgfunc_usage ()
19093e6c936aSmrg{
1910b0a0317aSmrg    $debug_cmd
19113e6c936aSmrg
1912b0a0317aSmrg    func_usage_message
1913b0a0317aSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
1914b0a0317aSmrg    exit 0
1915b0a0317aSmrg}
19163e6c936aSmrg
19173e6c936aSmrg
1918b0a0317aSmrg# func_usage_message
1919b0a0317aSmrg# ------------------
1920b0a0317aSmrg# Echo short help message to standard output.
1921b0a0317aSmrgfunc_usage_message ()
19223e6c936aSmrg{
1923b0a0317aSmrg    $debug_cmd
19243e6c936aSmrg
1925b0a0317aSmrg    eval \$ECHO \""Usage: $usage"\"
1926b0a0317aSmrg    echo
1927b0a0317aSmrg    $SED -n 's|^# ||
1928b0a0317aSmrg        /^Written by/{
1929b0a0317aSmrg          x;p;x
1930b0a0317aSmrg        }
1931b0a0317aSmrg	h
1932b0a0317aSmrg	/^Written by/q' < "$progpath"
1933b0a0317aSmrg    echo
1934b0a0317aSmrg    eval \$ECHO \""$usage_message"\"
1935b0a0317aSmrg}
19363e6c936aSmrg
19374456fccdSmrg
1938b0a0317aSmrg# func_version
1939b0a0317aSmrg# ------------
1940b0a0317aSmrg# Echo version message to standard output and exit.
1941b0a0317aSmrgfunc_version ()
1942b0a0317aSmrg{
1943b0a0317aSmrg    $debug_cmd
1944521070a0Smrg
1945b0a0317aSmrg    printf '%s\n' "$progname $scriptversion"
1946b0a0317aSmrg    $SED -n '
1947b0a0317aSmrg        /(C)/!b go
1948b0a0317aSmrg        :more
1949b0a0317aSmrg        /\./!{
1950b0a0317aSmrg          N
1951b0a0317aSmrg          s|\n# | |
1952b0a0317aSmrg          b more
1953b0a0317aSmrg        }
1954b0a0317aSmrg        :go
1955b0a0317aSmrg        /^# Written by /,/# warranty; / {
1956b0a0317aSmrg          s|^# ||
1957b0a0317aSmrg          s|^# *$||
1958b0a0317aSmrg          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
1959b0a0317aSmrg          p
1960b0a0317aSmrg        }
1961b0a0317aSmrg        /^# Written by / {
1962b0a0317aSmrg          s|^# ||
1963b0a0317aSmrg          p
1964b0a0317aSmrg        }
1965b0a0317aSmrg        /^warranty; /q' < "$progpath"
1966521070a0Smrg
1967b0a0317aSmrg    exit $?
1968b0a0317aSmrg}
1969521070a0Smrg
19704456fccdSmrg
1971b0a0317aSmrg# Local variables:
1972b0a0317aSmrg# mode: shell-script
1973b0a0317aSmrg# sh-indentation: 2
1974b0a0317aSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1975b0a0317aSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1976b0a0317aSmrg# time-stamp-time-zone: "UTC"
1977b0a0317aSmrg# End:
19784456fccdSmrg
1979b0a0317aSmrg# Set a version string.
1980b0a0317aSmrgscriptversion='(GNU libtool) 2.4.6'
19814456fccdSmrg
1982521070a0Smrg
1983b0a0317aSmrg# func_echo ARG...
1984b0a0317aSmrg# ----------------
1985b0a0317aSmrg# Libtool also displays the current mode in messages, so override
1986b0a0317aSmrg# funclib.sh func_echo with this custom definition.
1987b0a0317aSmrgfunc_echo ()
19883e6c936aSmrg{
1989b0a0317aSmrg    $debug_cmd
19903e6c936aSmrg
1991b0a0317aSmrg    _G_message=$*
1992b0a0317aSmrg
1993b0a0317aSmrg    func_echo_IFS=$IFS
1994b0a0317aSmrg    IFS=$nl
1995b0a0317aSmrg    for _G_line in $_G_message; do
1996b0a0317aSmrg      IFS=$func_echo_IFS
1997b0a0317aSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
1998b0a0317aSmrg    done
1999b0a0317aSmrg    IFS=$func_echo_IFS
2000b0a0317aSmrg}
20013e6c936aSmrg
20023e6c936aSmrg
2003b0a0317aSmrg# func_warning ARG...
2004b0a0317aSmrg# -------------------
2005b0a0317aSmrg# Libtool warnings are not categorized, so override funclib.sh
2006b0a0317aSmrg# func_warning with this simpler definition.
2007b0a0317aSmrgfunc_warning ()
20083e6c936aSmrg{
2009b0a0317aSmrg    $debug_cmd
2010b0a0317aSmrg
2011b0a0317aSmrg    $warning_func ${1+"$@"}
2012b0a0317aSmrg}
2013b0a0317aSmrg
20143e6c936aSmrg
2015b0a0317aSmrg## ---------------- ##
2016b0a0317aSmrg## Options parsing. ##
2017b0a0317aSmrg## ---------------- ##
2018b0a0317aSmrg
2019b0a0317aSmrg# Hook in the functions to make sure our own options are parsed during
2020b0a0317aSmrg# the option parsing loop.
2021b0a0317aSmrg
2022b0a0317aSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
2023b0a0317aSmrg
2024b0a0317aSmrg# Short help message in response to '-h'.
2025b0a0317aSmrgusage_message="Options:
2026b0a0317aSmrg       --config             show all configuration variables
2027b0a0317aSmrg       --debug              enable verbose shell tracing
2028b0a0317aSmrg   -n, --dry-run            display commands without modifying any files
2029b0a0317aSmrg       --features           display basic configuration information and exit
2030b0a0317aSmrg       --mode=MODE          use operation mode MODE
2031b0a0317aSmrg       --no-warnings        equivalent to '-Wnone'
2032b0a0317aSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2033b0a0317aSmrg       --quiet, --silent    don't print informational messages
2034b0a0317aSmrg       --tag=TAG            use configuration variables from tag TAG
2035b0a0317aSmrg   -v, --verbose            print more informational messages than default
2036b0a0317aSmrg       --version            print version information
2037b0a0317aSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2038b0a0317aSmrg   -h, --help, --help-all   print short, long, or detailed help message
2039b0a0317aSmrg"
20403e6c936aSmrg
2041b0a0317aSmrg# Additional text appended to 'usage_message' in response to '--help'.
2042b0a0317aSmrgfunc_help ()
20433e6c936aSmrg{
2044b0a0317aSmrg    $debug_cmd
2045b0a0317aSmrg
2046b0a0317aSmrg    func_usage_message
2047b0a0317aSmrg    $ECHO "$long_help_message
2048b0a0317aSmrg
2049b0a0317aSmrgMODE must be one of the following:
2050b0a0317aSmrg
2051b0a0317aSmrg       clean           remove files from the build directory
2052b0a0317aSmrg       compile         compile a source file into a libtool object
2053b0a0317aSmrg       execute         automatically set library path, then run a program
2054b0a0317aSmrg       finish          complete the installation of libtool libraries
2055b0a0317aSmrg       install         install libraries or executables
2056b0a0317aSmrg       link            create a library or an executable
2057b0a0317aSmrg       uninstall       remove libraries from an installed directory
2058b0a0317aSmrg
2059b0a0317aSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2060b0a0317aSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2061b0a0317aSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2062b0a0317aSmrg
2063b0a0317aSmrgWhen reporting a bug, please describe a test case to reproduce it and
2064b0a0317aSmrginclude the following information:
2065b0a0317aSmrg
2066b0a0317aSmrg       host-triplet:   $host
2067b0a0317aSmrg       shell:          $SHELL
2068b0a0317aSmrg       compiler:       $LTCC
2069b0a0317aSmrg       compiler flags: $LTCFLAGS
2070b0a0317aSmrg       linker:         $LD (gnu? $with_gnu_ld)
2071b0a0317aSmrg       version:        $progname (GNU libtool) 2.4.6
2072b0a0317aSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2073b0a0317aSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2074b0a0317aSmrg
2075b0a0317aSmrgReport bugs to <bug-libtool@gnu.org>.
2076b0a0317aSmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2077b0a0317aSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2078b0a0317aSmrg    exit 0
2079b0a0317aSmrg}
20803e6c936aSmrg
20813e6c936aSmrg
2082b0a0317aSmrg# func_lo2o OBJECT-NAME
2083b0a0317aSmrg# ---------------------
2084b0a0317aSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2085b0a0317aSmrg# object suffix.
20863e6c936aSmrg
2087b0a0317aSmrglo2o=s/\\.lo\$/.$objext/
2088b0a0317aSmrgo2lo=s/\\.$objext\$/.lo/
20893e6c936aSmrg
2090b0a0317aSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
2091b0a0317aSmrg  eval 'func_lo2o ()
2092b0a0317aSmrg  {
2093b0a0317aSmrg    case $1 in
2094b0a0317aSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2095b0a0317aSmrg      *   ) func_lo2o_result=$1               ;;
2096b0a0317aSmrg    esac
2097b0a0317aSmrg  }'
2098b0a0317aSmrg
2099b0a0317aSmrg  # func_xform LIBOBJ-OR-SOURCE
2100b0a0317aSmrg  # ---------------------------
2101b0a0317aSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2102b0a0317aSmrg  # suffix to a '.lo' libtool-object suffix.
2103b0a0317aSmrg  eval 'func_xform ()
2104b0a0317aSmrg  {
2105b0a0317aSmrg    func_xform_result=${1%.*}.lo
2106b0a0317aSmrg  }'
2107b0a0317aSmrgelse
2108b0a0317aSmrg  # ...otherwise fall back to using sed.
2109b0a0317aSmrg  func_lo2o ()
2110b0a0317aSmrg  {
2111b0a0317aSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2112b0a0317aSmrg  }
2113b0a0317aSmrg
2114b0a0317aSmrg  func_xform ()
2115b0a0317aSmrg  {
2116b0a0317aSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2117b0a0317aSmrg  }
2118b0a0317aSmrgfi
21193e6c936aSmrg
21203e6c936aSmrg
2121b0a0317aSmrg# func_fatal_configuration ARG...
2122b0a0317aSmrg# -------------------------------
2123521070a0Smrg# Echo program name prefixed message to standard error, followed by
2124521070a0Smrg# a configuration failure hint, and exit.
2125521070a0Smrgfunc_fatal_configuration ()
2126521070a0Smrg{
2127b0a0317aSmrg    func_fatal_error ${1+"$@"} \
2128b0a0317aSmrg      "See the $PACKAGE documentation for more information." \
2129b0a0317aSmrg      "Fatal configuration error."
2130521070a0Smrg}
21314456fccdSmrg
213242d69509Smrg
2133521070a0Smrg# func_config
2134b0a0317aSmrg# -----------
2135521070a0Smrg# Display the configuration for all the tags in this script.
2136521070a0Smrgfunc_config ()
2137521070a0Smrg{
2138521070a0Smrg    re_begincf='^# ### BEGIN LIBTOOL'
2139521070a0Smrg    re_endcf='^# ### END LIBTOOL'
2140521070a0Smrg
2141521070a0Smrg    # Default configuration.
2142521070a0Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
21434456fccdSmrg
21444456fccdSmrg    # Now print the configurations for the tags.
21454456fccdSmrg    for tagname in $taglist; do
2146521070a0Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
21474456fccdSmrg    done
21484456fccdSmrg
2149521070a0Smrg    exit $?
2150521070a0Smrg}
21514456fccdSmrg
2152b0a0317aSmrg
2153521070a0Smrg# func_features
2154b0a0317aSmrg# -------------
2155521070a0Smrg# Display the features supported by this script.
2156521070a0Smrgfunc_features ()
2157521070a0Smrg{
2158ff63a143Smrg    echo "host: $host"
2159b0a0317aSmrg    if test yes = "$build_libtool_libs"; then
2160ff63a143Smrg      echo "enable shared libraries"
21614456fccdSmrg    else
2162ff63a143Smrg      echo "disable shared libraries"
21634456fccdSmrg    fi
2164b0a0317aSmrg    if test yes = "$build_old_libs"; then
2165ff63a143Smrg      echo "enable static libraries"
21664456fccdSmrg    else
2167ff63a143Smrg      echo "disable static libraries"
21684456fccdSmrg    fi
2169521070a0Smrg
21704456fccdSmrg    exit $?
2171521070a0Smrg}
21724456fccdSmrg
2173b0a0317aSmrg
2174b0a0317aSmrg# func_enable_tag TAGNAME
2175b0a0317aSmrg# -----------------------
2176521070a0Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2177521070a0Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2178521070a0Smrg# variable here.
2179521070a0Smrgfunc_enable_tag ()
2180521070a0Smrg{
2181b0a0317aSmrg    # Global variable:
2182b0a0317aSmrg    tagname=$1
21834456fccdSmrg
2184b0a0317aSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2185b0a0317aSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2186b0a0317aSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
21874456fccdSmrg
2188b0a0317aSmrg    # Validate tagname.
2189b0a0317aSmrg    case $tagname in
2190b0a0317aSmrg      *[!-_A-Za-z0-9,/]*)
2191b0a0317aSmrg        func_fatal_error "invalid tag name: $tagname"
2192b0a0317aSmrg        ;;
2193b0a0317aSmrg    esac
21944456fccdSmrg
2195b0a0317aSmrg    # Don't test for the "default" C tag, as we know it's
2196b0a0317aSmrg    # there but not specially marked.
2197b0a0317aSmrg    case $tagname in
2198b0a0317aSmrg        CC) ;;
2199521070a0Smrg    *)
2200b0a0317aSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2201b0a0317aSmrg	  taglist="$taglist $tagname"
2202b0a0317aSmrg
2203b0a0317aSmrg	  # Evaluate the configuration.  Be careful to quote the path
2204b0a0317aSmrg	  # and the sed script, to avoid splitting on whitespace, but
2205b0a0317aSmrg	  # also don't use non-portable quotes within backquotes within
2206b0a0317aSmrg	  # quotes we have to do it in 2 steps:
2207b0a0317aSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2208b0a0317aSmrg	  eval "$extractedcf"
2209b0a0317aSmrg        else
2210b0a0317aSmrg	  func_error "ignoring unknown tag $tagname"
2211b0a0317aSmrg        fi
2212b0a0317aSmrg        ;;
2213b0a0317aSmrg    esac
2214521070a0Smrg}
2215521070a0Smrg
2216b0a0317aSmrg
22173e6c936aSmrg# func_check_version_match
2218b0a0317aSmrg# ------------------------
22193e6c936aSmrg# Ensure that we are using m4 macros, and libtool script from the same
22203e6c936aSmrg# release of libtool.
22213e6c936aSmrgfunc_check_version_match ()
2222521070a0Smrg{
2223b0a0317aSmrg    if test "$package_revision" != "$macro_revision"; then
2224b0a0317aSmrg      if test "$VERSION" != "$macro_version"; then
2225b0a0317aSmrg        if test -z "$macro_version"; then
2226b0a0317aSmrg          cat >&2 <<_LT_EOF
22273e6c936aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
22283e6c936aSmrg$progname: definition of this LT_INIT comes from an older release.
22293e6c936aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
22303e6c936aSmrg$progname: and run autoconf again.
22313e6c936aSmrg_LT_EOF
2232b0a0317aSmrg        else
2233b0a0317aSmrg          cat >&2 <<_LT_EOF
22343e6c936aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
22353e6c936aSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
22363e6c936aSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
22373e6c936aSmrg$progname: and run autoconf again.
22383e6c936aSmrg_LT_EOF
2239b0a0317aSmrg        fi
2240b0a0317aSmrg      else
2241b0a0317aSmrg        cat >&2 <<_LT_EOF
22423e6c936aSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
22433e6c936aSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
22443e6c936aSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
22453e6c936aSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
22463e6c936aSmrg_LT_EOF
2247b0a0317aSmrg      fi
22483e6c936aSmrg
2249b0a0317aSmrg      exit $EXIT_MISMATCH
2250b0a0317aSmrg    fi
22513e6c936aSmrg}
22523e6c936aSmrg
22533e6c936aSmrg
2254b0a0317aSmrg# libtool_options_prep [ARG]...
2255b0a0317aSmrg# -----------------------------
2256b0a0317aSmrg# Preparation for options parsed by libtool.
2257b0a0317aSmrglibtool_options_prep ()
2258b0a0317aSmrg{
2259b0a0317aSmrg    $debug_mode
22603e6c936aSmrg
2261b0a0317aSmrg    # Option defaults:
2262b0a0317aSmrg    opt_config=false
2263b0a0317aSmrg    opt_dlopen=
2264b0a0317aSmrg    opt_dry_run=false
2265b0a0317aSmrg    opt_help=false
2266b0a0317aSmrg    opt_mode=
2267b0a0317aSmrg    opt_preserve_dup_deps=false
2268b0a0317aSmrg    opt_quiet=false
22693e6c936aSmrg
2270b0a0317aSmrg    nonopt=
2271b0a0317aSmrg    preserve_args=
22723e6c936aSmrg
2273b0a0317aSmrg    # Shorthand for --mode=foo, only valid as the first argument
2274b0a0317aSmrg    case $1 in
2275b0a0317aSmrg    clean|clea|cle|cl)
2276b0a0317aSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
2277b0a0317aSmrg      ;;
2278b0a0317aSmrg    compile|compil|compi|comp|com|co|c)
2279b0a0317aSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
2280b0a0317aSmrg      ;;
2281b0a0317aSmrg    execute|execut|execu|exec|exe|ex|e)
2282b0a0317aSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
2283b0a0317aSmrg      ;;
2284b0a0317aSmrg    finish|finis|fini|fin|fi|f)
2285b0a0317aSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
2286b0a0317aSmrg      ;;
2287b0a0317aSmrg    install|instal|insta|inst|ins|in|i)
2288b0a0317aSmrg      shift; set dummy --mode install ${1+"$@"}; shift
2289b0a0317aSmrg      ;;
2290b0a0317aSmrg    link|lin|li|l)
2291b0a0317aSmrg      shift; set dummy --mode link ${1+"$@"}; shift
2292b0a0317aSmrg      ;;
2293b0a0317aSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2294b0a0317aSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2295b0a0317aSmrg      ;;
2296b0a0317aSmrg    esac
2297b0a0317aSmrg
2298b0a0317aSmrg    # Pass back the list of options.
2299b0a0317aSmrg    func_quote_for_eval ${1+"$@"}
2300b0a0317aSmrg    libtool_options_prep_result=$func_quote_for_eval_result
2301b0a0317aSmrg}
2302b0a0317aSmrgfunc_add_hook func_options_prep libtool_options_prep
23034456fccdSmrg
23044456fccdSmrg
2305b0a0317aSmrg# libtool_parse_options [ARG]...
2306b0a0317aSmrg# ---------------------------------
2307b0a0317aSmrg# Provide handling for libtool specific options.
2308b0a0317aSmrglibtool_parse_options ()
23093e6c936aSmrg{
2310b0a0317aSmrg    $debug_cmd
2311521070a0Smrg
2312b0a0317aSmrg    # Perform our own loop to consume as many options as possible in
2313b0a0317aSmrg    # each iteration.
2314b0a0317aSmrg    while test $# -gt 0; do
2315b0a0317aSmrg      _G_opt=$1
2316b0a0317aSmrg      shift
2317b0a0317aSmrg      case $_G_opt in
2318b0a0317aSmrg        --dry-run|--dryrun|-n)
2319b0a0317aSmrg                        opt_dry_run=:
2320b0a0317aSmrg                        ;;
2321b0a0317aSmrg
2322b0a0317aSmrg        --config)       func_config ;;
2323b0a0317aSmrg
2324b0a0317aSmrg        --dlopen|-dlopen)
2325b0a0317aSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2326b0a0317aSmrg}$1"
2327b0a0317aSmrg                        shift
2328b0a0317aSmrg                        ;;
2329b0a0317aSmrg
2330b0a0317aSmrg        --preserve-dup-deps)
2331b0a0317aSmrg                        opt_preserve_dup_deps=: ;;
2332b0a0317aSmrg
2333b0a0317aSmrg        --features)     func_features ;;
2334b0a0317aSmrg
2335b0a0317aSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2336b0a0317aSmrg
2337b0a0317aSmrg        --help)         opt_help=: ;;
2338b0a0317aSmrg
2339b0a0317aSmrg        --help-all)     opt_help=': help-all' ;;
2340b0a0317aSmrg
2341b0a0317aSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2342b0a0317aSmrg                        opt_mode=$1
2343b0a0317aSmrg                        case $1 in
2344b0a0317aSmrg                          # Valid mode arguments:
2345b0a0317aSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2346b0a0317aSmrg
2347b0a0317aSmrg                          # Catch anything else as an error
2348b0a0317aSmrg                          *) func_error "invalid argument for $_G_opt"
2349b0a0317aSmrg                             exit_cmd=exit
2350b0a0317aSmrg                             break
2351b0a0317aSmrg                             ;;
2352b0a0317aSmrg                        esac
2353b0a0317aSmrg                        shift
2354b0a0317aSmrg                        ;;
2355b0a0317aSmrg
2356b0a0317aSmrg        --no-silent|--no-quiet)
2357b0a0317aSmrg                        opt_quiet=false
2358b0a0317aSmrg                        func_append preserve_args " $_G_opt"
2359b0a0317aSmrg                        ;;
2360b0a0317aSmrg
2361b0a0317aSmrg        --no-warnings|--no-warning|--no-warn)
2362b0a0317aSmrg                        opt_warning=false
2363b0a0317aSmrg                        func_append preserve_args " $_G_opt"
2364b0a0317aSmrg                        ;;
2365b0a0317aSmrg
2366b0a0317aSmrg        --no-verbose)
2367b0a0317aSmrg                        opt_verbose=false
2368b0a0317aSmrg                        func_append preserve_args " $_G_opt"
2369b0a0317aSmrg                        ;;
2370b0a0317aSmrg
2371b0a0317aSmrg        --silent|--quiet)
2372b0a0317aSmrg                        opt_quiet=:
2373b0a0317aSmrg                        opt_verbose=false
2374b0a0317aSmrg                        func_append preserve_args " $_G_opt"
2375b0a0317aSmrg                        ;;
2376b0a0317aSmrg
2377b0a0317aSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2378b0a0317aSmrg                        opt_tag=$1
2379b0a0317aSmrg                        func_append preserve_args " $_G_opt $1"
2380b0a0317aSmrg                        func_enable_tag "$1"
2381b0a0317aSmrg                        shift
2382b0a0317aSmrg                        ;;
2383b0a0317aSmrg
2384b0a0317aSmrg        --verbose|-v)   opt_quiet=false
2385b0a0317aSmrg                        opt_verbose=:
2386b0a0317aSmrg                        func_append preserve_args " $_G_opt"
2387b0a0317aSmrg                        ;;
2388b0a0317aSmrg
2389b0a0317aSmrg	# An option not handled by this hook function:
2390b0a0317aSmrg        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
2391b0a0317aSmrg      esac
2392b0a0317aSmrg    done
23933e6c936aSmrg
23943e6c936aSmrg
2395b0a0317aSmrg    # save modified positional parameters for caller
2396b0a0317aSmrg    func_quote_for_eval ${1+"$@"}
2397b0a0317aSmrg    libtool_parse_options_result=$func_quote_for_eval_result
2398b0a0317aSmrg}
2399b0a0317aSmrgfunc_add_hook func_parse_options libtool_parse_options
2400521070a0Smrg
24014456fccdSmrg
2402521070a0Smrg
2403b0a0317aSmrg# libtool_validate_options [ARG]...
2404b0a0317aSmrg# ---------------------------------
2405b0a0317aSmrg# Perform any sanity checks on option settings and/or unconsumed
2406b0a0317aSmrg# arguments.
2407b0a0317aSmrglibtool_validate_options ()
2408b0a0317aSmrg{
2409b0a0317aSmrg    # save first non-option argument
2410b0a0317aSmrg    if test 0 -lt $#; then
2411b0a0317aSmrg      nonopt=$1
2412b0a0317aSmrg      shift
2413521070a0Smrg    fi
2414521070a0Smrg
2415b0a0317aSmrg    # preserve --debug
2416b0a0317aSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2417521070a0Smrg
2418b0a0317aSmrg    case $host in
2419b0a0317aSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2420b0a0317aSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2421b0a0317aSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2422b0a0317aSmrg        # don't eliminate duplications in $postdeps and $predeps
2423b0a0317aSmrg        opt_duplicate_compiler_generated_deps=:
2424b0a0317aSmrg        ;;
2425b0a0317aSmrg      *)
2426b0a0317aSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2427b0a0317aSmrg        ;;
2428b0a0317aSmrg    esac
2429521070a0Smrg
2430b0a0317aSmrg    $opt_help || {
2431b0a0317aSmrg      # Sanity checks first:
2432b0a0317aSmrg      func_check_version_match
2433521070a0Smrg
2434b0a0317aSmrg      test yes != "$build_libtool_libs" \
2435b0a0317aSmrg        && test yes != "$build_old_libs" \
2436b0a0317aSmrg        && func_fatal_configuration "not configured to build any kind of library"
2437521070a0Smrg
2438b0a0317aSmrg      # Darwin sucks
2439b0a0317aSmrg      eval std_shrext=\"$shrext_cmds\"
2440b0a0317aSmrg
2441b0a0317aSmrg      # Only execute mode is allowed to have -dlopen flags.
2442b0a0317aSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2443b0a0317aSmrg        func_error "unrecognized option '-dlopen'"
2444b0a0317aSmrg        $ECHO "$help" 1>&2
2445b0a0317aSmrg        exit $EXIT_FAILURE
2446b0a0317aSmrg      fi
2447b0a0317aSmrg
2448b0a0317aSmrg      # Change the help message to a mode-specific one.
2449b0a0317aSmrg      generic_help=$help
2450b0a0317aSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2451b0a0317aSmrg    }
2452b0a0317aSmrg
2453b0a0317aSmrg    # Pass back the unparsed argument list
2454b0a0317aSmrg    func_quote_for_eval ${1+"$@"}
2455b0a0317aSmrg    libtool_validate_options_result=$func_quote_for_eval_result
24563e6c936aSmrg}
2457b0a0317aSmrgfunc_add_hook func_validate_options libtool_validate_options
2458b0a0317aSmrg
2459521070a0Smrg
2460b0a0317aSmrg# Process options as early as possible so that --help and --version
2461b0a0317aSmrg# can return quickly.
2462b0a0317aSmrgfunc_options ${1+"$@"}
2463b0a0317aSmrgeval set dummy "$func_options_result"; shift
2464521070a0Smrg
24654456fccdSmrg
24664456fccdSmrg
24673e6c936aSmrg## ----------- ##
24683e6c936aSmrg##    Main.    ##
24693e6c936aSmrg## ----------- ##
24704456fccdSmrg
2471b0a0317aSmrgmagic='%%%MAGIC variable%%%'
2472b0a0317aSmrgmagic_exe='%%%MAGIC EXE variable%%%'
2473b0a0317aSmrg
2474b0a0317aSmrg# Global variables.
2475b0a0317aSmrgextracted_archives=
2476b0a0317aSmrgextracted_serial=0
2477b0a0317aSmrg
2478b0a0317aSmrg# If this variable is set in any of the actions, the command in it
2479b0a0317aSmrg# will be execed at the end.  This prevents here-documents from being
2480b0a0317aSmrg# left over by shells.
2481b0a0317aSmrgexec_cmd=
2482b0a0317aSmrg
2483b0a0317aSmrg
2484b0a0317aSmrg# A function that is used when there is no print builtin or printf.
2485b0a0317aSmrgfunc_fallback_echo ()
2486b0a0317aSmrg{
2487b0a0317aSmrg  eval 'cat <<_LTECHO_EOF
2488b0a0317aSmrg$1
2489b0a0317aSmrg_LTECHO_EOF'
2490b0a0317aSmrg}
2491b0a0317aSmrg
2492b0a0317aSmrg# func_generated_by_libtool
2493b0a0317aSmrg# True iff stdin has been generated by Libtool. This function is only
2494b0a0317aSmrg# a basic sanity check; it will hardly flush out determined imposters.
2495b0a0317aSmrgfunc_generated_by_libtool_p ()
2496b0a0317aSmrg{
2497b0a0317aSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2498b0a0317aSmrg}
2499b0a0317aSmrg
2500521070a0Smrg# func_lalib_p file
2501b0a0317aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2502521070a0Smrg# This function is only a basic sanity check; it will hardly flush out
2503521070a0Smrg# determined imposters.
2504521070a0Smrgfunc_lalib_p ()
2505521070a0Smrg{
2506521070a0Smrg    test -f "$1" &&
2507b0a0317aSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2508521070a0Smrg}
25094456fccdSmrg
2510521070a0Smrg# func_lalib_unsafe_p file
2511b0a0317aSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2512521070a0Smrg# This function implements the same check as func_lalib_p without
2513521070a0Smrg# resorting to external programs.  To this end, it redirects stdin and
2514521070a0Smrg# closes it afterwards, without saving the original file descriptor.
2515521070a0Smrg# As a safety measure, use it only where a negative result would be
2516b0a0317aSmrg# fatal anyway.  Works if 'file' does not exist.
2517521070a0Smrgfunc_lalib_unsafe_p ()
2518521070a0Smrg{
2519521070a0Smrg    lalib_p=no
2520521070a0Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2521521070a0Smrg	for lalib_p_l in 1 2 3 4
2522521070a0Smrg	do
2523521070a0Smrg	    read lalib_p_line
2524b0a0317aSmrg	    case $lalib_p_line in
2525521070a0Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2526521070a0Smrg	    esac
2527521070a0Smrg	done
2528521070a0Smrg	exec 0<&5 5<&-
2529521070a0Smrg    fi
2530b0a0317aSmrg    test yes = "$lalib_p"
2531521070a0Smrg}
25324456fccdSmrg
2533521070a0Smrg# func_ltwrapper_script_p file
2534521070a0Smrg# True iff FILE is a libtool wrapper script
2535521070a0Smrg# This function is only a basic sanity check; it will hardly flush out
2536521070a0Smrg# determined imposters.
2537521070a0Smrgfunc_ltwrapper_script_p ()
2538521070a0Smrg{
2539b0a0317aSmrg    test -f "$1" &&
2540b0a0317aSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2541521070a0Smrg}
25424456fccdSmrg
2543521070a0Smrg# func_ltwrapper_executable_p file
2544521070a0Smrg# True iff FILE is a libtool wrapper executable
2545521070a0Smrg# This function is only a basic sanity check; it will hardly flush out
2546521070a0Smrg# determined imposters.
2547521070a0Smrgfunc_ltwrapper_executable_p ()
2548521070a0Smrg{
2549521070a0Smrg    func_ltwrapper_exec_suffix=
2550521070a0Smrg    case $1 in
2551521070a0Smrg    *.exe) ;;
2552521070a0Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
2553521070a0Smrg    esac
2554521070a0Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2555521070a0Smrg}
25564456fccdSmrg
2557521070a0Smrg# func_ltwrapper_scriptname file
2558521070a0Smrg# Assumes file is an ltwrapper_executable
2559521070a0Smrg# uses $file to determine the appropriate filename for a
2560521070a0Smrg# temporary ltwrapper_script.
2561521070a0Smrgfunc_ltwrapper_scriptname ()
2562521070a0Smrg{
25633e6c936aSmrg    func_dirname_and_basename "$1" "" "."
25643e6c936aSmrg    func_stripname '' '.exe' "$func_basename_result"
2565b0a0317aSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2566521070a0Smrg}
2567521070a0Smrg
2568521070a0Smrg# func_ltwrapper_p file
2569521070a0Smrg# True iff FILE is a libtool wrapper script or wrapper executable
2570521070a0Smrg# This function is only a basic sanity check; it will hardly flush out
2571521070a0Smrg# determined imposters.
2572521070a0Smrgfunc_ltwrapper_p ()
2573521070a0Smrg{
2574521070a0Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2575521070a0Smrg}
2576521070a0Smrg
2577521070a0Smrg
2578521070a0Smrg# func_execute_cmds commands fail_cmd
2579521070a0Smrg# Execute tilde-delimited COMMANDS.
2580521070a0Smrg# If FAIL_CMD is given, eval that upon failure.
2581521070a0Smrg# FAIL_CMD may read-access the current command in variable CMD!
2582521070a0Smrgfunc_execute_cmds ()
2583521070a0Smrg{
2584b0a0317aSmrg    $debug_cmd
2585b0a0317aSmrg
2586521070a0Smrg    save_ifs=$IFS; IFS='~'
2587521070a0Smrg    for cmd in $1; do
2588b0a0317aSmrg      IFS=$sp$nl
2589521070a0Smrg      eval cmd=\"$cmd\"
2590b0a0317aSmrg      IFS=$save_ifs
2591521070a0Smrg      func_show_eval "$cmd" "${2-:}"
2592521070a0Smrg    done
2593521070a0Smrg    IFS=$save_ifs
2594521070a0Smrg}
2595521070a0Smrg
2596521070a0Smrg
2597521070a0Smrg# func_source file
2598521070a0Smrg# Source FILE, adding directory component if necessary.
2599521070a0Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
2600521070a0Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2601521070a0Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2602b0a0317aSmrg# 'FILE.' does not work on cygwin managed mounts.
2603521070a0Smrgfunc_source ()
2604521070a0Smrg{
2605b0a0317aSmrg    $debug_cmd
2606b0a0317aSmrg
2607521070a0Smrg    case $1 in
2608521070a0Smrg    */* | *\\*)	. "$1" ;;
2609521070a0Smrg    *)		. "./$1" ;;
2610521070a0Smrg    esac
2611521070a0Smrg}
2612521070a0Smrg
2613521070a0Smrg
26143e6c936aSmrg# func_resolve_sysroot PATH
26153e6c936aSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
26163e6c936aSmrg# func_resolve_sysroot_result
26173e6c936aSmrgfunc_resolve_sysroot ()
26183e6c936aSmrg{
26193e6c936aSmrg  func_resolve_sysroot_result=$1
26203e6c936aSmrg  case $func_resolve_sysroot_result in
26213e6c936aSmrg  =*)
26223e6c936aSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
26233e6c936aSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
26243e6c936aSmrg    ;;
26253e6c936aSmrg  esac
26263e6c936aSmrg}
26273e6c936aSmrg
26283e6c936aSmrg# func_replace_sysroot PATH
26293e6c936aSmrg# If PATH begins with the sysroot, replace it with = and
26303e6c936aSmrg# store the result into func_replace_sysroot_result.
26313e6c936aSmrgfunc_replace_sysroot ()
26323e6c936aSmrg{
2633b0a0317aSmrg  case $lt_sysroot:$1 in
26343e6c936aSmrg  ?*:"$lt_sysroot"*)
26353e6c936aSmrg    func_stripname "$lt_sysroot" '' "$1"
2636b0a0317aSmrg    func_replace_sysroot_result='='$func_stripname_result
26373e6c936aSmrg    ;;
26383e6c936aSmrg  *)
26393e6c936aSmrg    # Including no sysroot.
26403e6c936aSmrg    func_replace_sysroot_result=$1
26413e6c936aSmrg    ;;
26423e6c936aSmrg  esac
26433e6c936aSmrg}
26443e6c936aSmrg
2645521070a0Smrg# func_infer_tag arg
2646521070a0Smrg# Infer tagged configuration to use if any are available and
2647521070a0Smrg# if one wasn't chosen via the "--tag" command line option.
2648521070a0Smrg# Only attempt this if the compiler in the base compile
2649521070a0Smrg# command doesn't match the default compiler.
2650521070a0Smrg# arg is usually of the form 'gcc ...'
2651521070a0Smrgfunc_infer_tag ()
2652521070a0Smrg{
2653b0a0317aSmrg    $debug_cmd
2654b0a0317aSmrg
2655521070a0Smrg    if test -n "$available_tags" && test -z "$tagname"; then
2656521070a0Smrg      CC_quoted=
2657521070a0Smrg      for arg in $CC; do
26583e6c936aSmrg	func_append_quoted CC_quoted "$arg"
2659521070a0Smrg      done
2660ff63a143Smrg      CC_expanded=`func_echo_all $CC`
2661ff63a143Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2662521070a0Smrg      case $@ in
2663521070a0Smrg      # Blanks in the command may have been stripped by the calling shell,
2664521070a0Smrg      # but not from the CC environment variable when configure was run.
2665ff63a143Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2666ff63a143Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2667521070a0Smrg      # Blanks at the start of $base_compile will cause this to fail
2668521070a0Smrg      # if we don't check for them as well.
2669521070a0Smrg      *)
2670521070a0Smrg	for z in $available_tags; do
2671521070a0Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2672521070a0Smrg	    # Evaluate the configuration.
2673b0a0317aSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2674521070a0Smrg	    CC_quoted=
2675521070a0Smrg	    for arg in $CC; do
2676521070a0Smrg	      # Double-quote args containing other shell metacharacters.
26773e6c936aSmrg	      func_append_quoted CC_quoted "$arg"
2678521070a0Smrg	    done
2679ff63a143Smrg	    CC_expanded=`func_echo_all $CC`
2680ff63a143Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2681521070a0Smrg	    case "$@ " in
2682ff63a143Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2683ff63a143Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2684521070a0Smrg	      # The compiler in the base compile command matches
2685521070a0Smrg	      # the one in the tagged configuration.
2686521070a0Smrg	      # Assume this is the tagged configuration we want.
2687521070a0Smrg	      tagname=$z
2688521070a0Smrg	      break
2689521070a0Smrg	      ;;
2690521070a0Smrg	    esac
2691521070a0Smrg	  fi
2692521070a0Smrg	done
2693521070a0Smrg	# If $tagname still isn't set, then no tagged configuration
2694521070a0Smrg	# was found and let the user know that the "--tag" command
2695521070a0Smrg	# line option must be used.
2696521070a0Smrg	if test -z "$tagname"; then
2697521070a0Smrg	  func_echo "unable to infer tagged configuration"
2698b0a0317aSmrg	  func_fatal_error "specify a tag with '--tag'"
2699521070a0Smrg#	else
2700521070a0Smrg#	  func_verbose "using $tagname tagged configuration"
2701521070a0Smrg	fi
2702521070a0Smrg	;;
2703521070a0Smrg      esac
2704521070a0Smrg    fi
2705521070a0Smrg}
2706521070a0Smrg
2707521070a0Smrg
27083e6c936aSmrg
27093e6c936aSmrg# func_write_libtool_object output_name pic_name nonpic_name
27103e6c936aSmrg# Create a libtool object file (analogous to a ".la" file),
27113e6c936aSmrg# but don't create it if we're doing a dry run.
27123e6c936aSmrgfunc_write_libtool_object ()
27133e6c936aSmrg{
2714b0a0317aSmrg    write_libobj=$1
2715b0a0317aSmrg    if test yes = "$build_libtool_libs"; then
2716b0a0317aSmrg      write_lobj=\'$2\'
27173e6c936aSmrg    else
27183e6c936aSmrg      write_lobj=none
27193e6c936aSmrg    fi
27203e6c936aSmrg
2721b0a0317aSmrg    if test yes = "$build_old_libs"; then
2722b0a0317aSmrg      write_oldobj=\'$3\'
27233e6c936aSmrg    else
27243e6c936aSmrg      write_oldobj=none
27253e6c936aSmrg    fi
27263e6c936aSmrg
27273e6c936aSmrg    $opt_dry_run || {
27283e6c936aSmrg      cat >${write_libobj}T <<EOF
27293e6c936aSmrg# $write_libobj - a libtool object file
2730b0a0317aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
27313e6c936aSmrg#
27323e6c936aSmrg# Please DO NOT delete this file!
27333e6c936aSmrg# It is necessary for linking the library.
27343e6c936aSmrg
27353e6c936aSmrg# Name of the PIC object.
27363e6c936aSmrgpic_object=$write_lobj
27373e6c936aSmrg
27383e6c936aSmrg# Name of the non-PIC object
27393e6c936aSmrgnon_pic_object=$write_oldobj
27403e6c936aSmrg
27413e6c936aSmrgEOF
2742b0a0317aSmrg      $MV "${write_libobj}T" "$write_libobj"
27433e6c936aSmrg    }
27443e6c936aSmrg}
27453e6c936aSmrg
27463e6c936aSmrg
27473e6c936aSmrg##################################################
27483e6c936aSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
27493e6c936aSmrg##################################################
27503e6c936aSmrg
27513e6c936aSmrg# func_convert_core_file_wine_to_w32 ARG
27523e6c936aSmrg# Helper function used by file name conversion functions when $build is *nix,
27533e6c936aSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
27543e6c936aSmrg# correctly configured wine environment available, with the winepath program
27553e6c936aSmrg# in $build's $PATH.
27563e6c936aSmrg#
27573e6c936aSmrg# ARG is the $build file name to be converted to w32 format.
27583e6c936aSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
27593e6c936aSmrg# be empty on error (or when ARG is empty)
27603e6c936aSmrgfunc_convert_core_file_wine_to_w32 ()
27613e6c936aSmrg{
2762b0a0317aSmrg  $debug_cmd
2763b0a0317aSmrg
2764b0a0317aSmrg  func_convert_core_file_wine_to_w32_result=$1
27653e6c936aSmrg  if test -n "$1"; then
27663e6c936aSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
27673e6c936aSmrg    # are forced to check the contents of stdout. On the other hand, if the
27683e6c936aSmrg    # command is not found, the shell will set an exit code of 127 and print
27693e6c936aSmrg    # *an error message* to stdout. So we must check for both error code of
27703e6c936aSmrg    # zero AND non-empty stdout, which explains the odd construction:
27713e6c936aSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
2772b0a0317aSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
27733e6c936aSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
2774b0a0317aSmrg        $SED -e "$sed_naive_backslashify"`
27753e6c936aSmrg    else
27763e6c936aSmrg      func_convert_core_file_wine_to_w32_result=
27773e6c936aSmrg    fi
27783e6c936aSmrg  fi
27793e6c936aSmrg}
27803e6c936aSmrg# end: func_convert_core_file_wine_to_w32
27813e6c936aSmrg
27823e6c936aSmrg
27833e6c936aSmrg# func_convert_core_path_wine_to_w32 ARG
27843e6c936aSmrg# Helper function used by path conversion functions when $build is *nix, and
27853e6c936aSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
27863e6c936aSmrg# configured wine environment available, with the winepath program in $build's
27873e6c936aSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
27883e6c936aSmrg#
27893e6c936aSmrg# ARG is path to be converted from $build format to win32.
27903e6c936aSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
27913e6c936aSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
27923e6c936aSmrg# are convertible, then the result may be empty.
27933e6c936aSmrgfunc_convert_core_path_wine_to_w32 ()
27943e6c936aSmrg{
2795b0a0317aSmrg  $debug_cmd
2796b0a0317aSmrg
27973e6c936aSmrg  # unfortunately, winepath doesn't convert paths, only file names
2798b0a0317aSmrg  func_convert_core_path_wine_to_w32_result=
27993e6c936aSmrg  if test -n "$1"; then
28003e6c936aSmrg    oldIFS=$IFS
28013e6c936aSmrg    IFS=:
28023e6c936aSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
28033e6c936aSmrg      IFS=$oldIFS
28043e6c936aSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
2805b0a0317aSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
28063e6c936aSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
2807b0a0317aSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
28083e6c936aSmrg        else
28093e6c936aSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
28103e6c936aSmrg        fi
28113e6c936aSmrg      fi
28123e6c936aSmrg    done
28133e6c936aSmrg    IFS=$oldIFS
28143e6c936aSmrg  fi
28153e6c936aSmrg}
28163e6c936aSmrg# end: func_convert_core_path_wine_to_w32
28173e6c936aSmrg
28183e6c936aSmrg
28193e6c936aSmrg# func_cygpath ARGS...
28203e6c936aSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
28213e6c936aSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
28223e6c936aSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
28233e6c936aSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
28243e6c936aSmrg# file name or path is assumed to be in w32 format, as previously converted
28253e6c936aSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
28263e6c936aSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
28273e6c936aSmrg# Cygwin format). Returns an empty string on error.
28283e6c936aSmrg#
28293e6c936aSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
28303e6c936aSmrg# be converted.
28313e6c936aSmrg#
28323e6c936aSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
28333e6c936aSmrg# environment variable; do not put it in $PATH.
28343e6c936aSmrgfunc_cygpath ()
28353e6c936aSmrg{
2836b0a0317aSmrg  $debug_cmd
2837b0a0317aSmrg
28383e6c936aSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
28393e6c936aSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
28403e6c936aSmrg    if test "$?" -ne 0; then
28413e6c936aSmrg      # on failure, ensure result is empty
28423e6c936aSmrg      func_cygpath_result=
28433e6c936aSmrg    fi
28443e6c936aSmrg  else
28453e6c936aSmrg    func_cygpath_result=
2846b0a0317aSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
28473e6c936aSmrg  fi
28483e6c936aSmrg}
28493e6c936aSmrg#end: func_cygpath
28503e6c936aSmrg
28513e6c936aSmrg
28523e6c936aSmrg# func_convert_core_msys_to_w32 ARG
28533e6c936aSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
28543e6c936aSmrg# result in func_convert_core_msys_to_w32_result.
28553e6c936aSmrgfunc_convert_core_msys_to_w32 ()
28563e6c936aSmrg{
2857b0a0317aSmrg  $debug_cmd
2858b0a0317aSmrg
28593e6c936aSmrg  # awkward: cmd appends spaces to result
28603e6c936aSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
2861b0a0317aSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
28623e6c936aSmrg}
28633e6c936aSmrg#end: func_convert_core_msys_to_w32
28643e6c936aSmrg
28653e6c936aSmrg
28663e6c936aSmrg# func_convert_file_check ARG1 ARG2
28673e6c936aSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
28683e6c936aSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
28693e6c936aSmrg# func_to_host_file_result to ARG1).
28703e6c936aSmrgfunc_convert_file_check ()
28713e6c936aSmrg{
2872b0a0317aSmrg  $debug_cmd
2873b0a0317aSmrg
2874b0a0317aSmrg  if test -z "$2" && test -n "$1"; then
28753e6c936aSmrg    func_error "Could not determine host file name corresponding to"
2876b0a0317aSmrg    func_error "  '$1'"
28773e6c936aSmrg    func_error "Continuing, but uninstalled executables may not work."
28783e6c936aSmrg    # Fallback:
2879b0a0317aSmrg    func_to_host_file_result=$1
28803e6c936aSmrg  fi
28813e6c936aSmrg}
28823e6c936aSmrg# end func_convert_file_check
28833e6c936aSmrg
28843e6c936aSmrg
28853e6c936aSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
28863e6c936aSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
28873e6c936aSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
28883e6c936aSmrg# func_to_host_file_result to a simplistic fallback value (see below).
28893e6c936aSmrgfunc_convert_path_check ()
28903e6c936aSmrg{
2891b0a0317aSmrg  $debug_cmd
2892b0a0317aSmrg
28933e6c936aSmrg  if test -z "$4" && test -n "$3"; then
28943e6c936aSmrg    func_error "Could not determine the host path corresponding to"
2895b0a0317aSmrg    func_error "  '$3'"
28963e6c936aSmrg    func_error "Continuing, but uninstalled executables may not work."
28973e6c936aSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
28983e6c936aSmrg    # should not be "improved".  See libtool.info.
28993e6c936aSmrg    if test "x$1" != "x$2"; then
29003e6c936aSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
29013e6c936aSmrg      func_to_host_path_result=`echo "$3" |
29023e6c936aSmrg        $SED -e "$lt_replace_pathsep_chars"`
29033e6c936aSmrg    else
2904b0a0317aSmrg      func_to_host_path_result=$3
29053e6c936aSmrg    fi
29063e6c936aSmrg  fi
29073e6c936aSmrg}
29083e6c936aSmrg# end func_convert_path_check
29093e6c936aSmrg
29103e6c936aSmrg
29113e6c936aSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
29123e6c936aSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
29133e6c936aSmrg# and appending REPL if ORIG matches BACKPAT.
29143e6c936aSmrgfunc_convert_path_front_back_pathsep ()
29153e6c936aSmrg{
2916b0a0317aSmrg  $debug_cmd
2917b0a0317aSmrg
29183e6c936aSmrg  case $4 in
2919b0a0317aSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
29203e6c936aSmrg    ;;
29213e6c936aSmrg  esac
29223e6c936aSmrg  case $4 in
29233e6c936aSmrg  $2 ) func_append func_to_host_path_result "$3"
29243e6c936aSmrg    ;;
29253e6c936aSmrg  esac
29263e6c936aSmrg}
29273e6c936aSmrg# end func_convert_path_front_back_pathsep
29283e6c936aSmrg
29293e6c936aSmrg
29303e6c936aSmrg##################################################
29313e6c936aSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
29323e6c936aSmrg##################################################
2933b0a0317aSmrg# invoked via '$to_host_file_cmd ARG'
29343e6c936aSmrg#
29353e6c936aSmrg# In each case, ARG is the path to be converted from $build to $host format.
29363e6c936aSmrg# Result will be available in $func_to_host_file_result.
29373e6c936aSmrg
29383e6c936aSmrg
29393e6c936aSmrg# func_to_host_file ARG
29403e6c936aSmrg# Converts the file name ARG from $build format to $host format. Return result
29413e6c936aSmrg# in func_to_host_file_result.
29423e6c936aSmrgfunc_to_host_file ()
29433e6c936aSmrg{
2944b0a0317aSmrg  $debug_cmd
2945b0a0317aSmrg
29463e6c936aSmrg  $to_host_file_cmd "$1"
29473e6c936aSmrg}
29483e6c936aSmrg# end func_to_host_file
29493e6c936aSmrg
29503e6c936aSmrg
29513e6c936aSmrg# func_to_tool_file ARG LAZY
29523e6c936aSmrg# converts the file name ARG from $build format to toolchain format. Return
29533e6c936aSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
29543e6c936aSmrg# in (the comma separated) LAZY, no conversion takes place.
29553e6c936aSmrgfunc_to_tool_file ()
29563e6c936aSmrg{
2957b0a0317aSmrg  $debug_cmd
2958b0a0317aSmrg
29593e6c936aSmrg  case ,$2, in
29603e6c936aSmrg    *,"$to_tool_file_cmd",*)
29613e6c936aSmrg      func_to_tool_file_result=$1
29623e6c936aSmrg      ;;
29633e6c936aSmrg    *)
29643e6c936aSmrg      $to_tool_file_cmd "$1"
29653e6c936aSmrg      func_to_tool_file_result=$func_to_host_file_result
29663e6c936aSmrg      ;;
29673e6c936aSmrg  esac
29683e6c936aSmrg}
29693e6c936aSmrg# end func_to_tool_file
29703e6c936aSmrg
29713e6c936aSmrg
29723e6c936aSmrg# func_convert_file_noop ARG
29733e6c936aSmrg# Copy ARG to func_to_host_file_result.
29743e6c936aSmrgfunc_convert_file_noop ()
29753e6c936aSmrg{
2976b0a0317aSmrg  func_to_host_file_result=$1
29773e6c936aSmrg}
29783e6c936aSmrg# end func_convert_file_noop
29793e6c936aSmrg
29803e6c936aSmrg
29813e6c936aSmrg# func_convert_file_msys_to_w32 ARG
29823e6c936aSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
29833e6c936aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
29843e6c936aSmrg# func_to_host_file_result.
29853e6c936aSmrgfunc_convert_file_msys_to_w32 ()
29863e6c936aSmrg{
2987b0a0317aSmrg  $debug_cmd
2988b0a0317aSmrg
2989b0a0317aSmrg  func_to_host_file_result=$1
29903e6c936aSmrg  if test -n "$1"; then
29913e6c936aSmrg    func_convert_core_msys_to_w32 "$1"
2992b0a0317aSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
29933e6c936aSmrg  fi
29943e6c936aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
29953e6c936aSmrg}
29963e6c936aSmrg# end func_convert_file_msys_to_w32
29973e6c936aSmrg
29983e6c936aSmrg
29993e6c936aSmrg# func_convert_file_cygwin_to_w32 ARG
30003e6c936aSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
30013e6c936aSmrg# func_to_host_file_result.
30023e6c936aSmrgfunc_convert_file_cygwin_to_w32 ()
30033e6c936aSmrg{
3004b0a0317aSmrg  $debug_cmd
3005b0a0317aSmrg
3006b0a0317aSmrg  func_to_host_file_result=$1
30073e6c936aSmrg  if test -n "$1"; then
30083e6c936aSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
30093e6c936aSmrg    # LT_CYGPATH in this case.
30103e6c936aSmrg    func_to_host_file_result=`cygpath -m "$1"`
30113e6c936aSmrg  fi
30123e6c936aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30133e6c936aSmrg}
30143e6c936aSmrg# end func_convert_file_cygwin_to_w32
30153e6c936aSmrg
30163e6c936aSmrg
30173e6c936aSmrg# func_convert_file_nix_to_w32 ARG
30183e6c936aSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
30193e6c936aSmrg# and a working winepath. Returns result in func_to_host_file_result.
30203e6c936aSmrgfunc_convert_file_nix_to_w32 ()
30213e6c936aSmrg{
3022b0a0317aSmrg  $debug_cmd
3023b0a0317aSmrg
3024b0a0317aSmrg  func_to_host_file_result=$1
30253e6c936aSmrg  if test -n "$1"; then
30263e6c936aSmrg    func_convert_core_file_wine_to_w32 "$1"
3027b0a0317aSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
30283e6c936aSmrg  fi
30293e6c936aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30303e6c936aSmrg}
30313e6c936aSmrg# end func_convert_file_nix_to_w32
30323e6c936aSmrg
30333e6c936aSmrg
30343e6c936aSmrg# func_convert_file_msys_to_cygwin ARG
30353e6c936aSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
30363e6c936aSmrg# Returns result in func_to_host_file_result.
30373e6c936aSmrgfunc_convert_file_msys_to_cygwin ()
30383e6c936aSmrg{
3039b0a0317aSmrg  $debug_cmd
3040b0a0317aSmrg
3041b0a0317aSmrg  func_to_host_file_result=$1
30423e6c936aSmrg  if test -n "$1"; then
30433e6c936aSmrg    func_convert_core_msys_to_w32 "$1"
30443e6c936aSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3045b0a0317aSmrg    func_to_host_file_result=$func_cygpath_result
30463e6c936aSmrg  fi
30473e6c936aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30483e6c936aSmrg}
30493e6c936aSmrg# end func_convert_file_msys_to_cygwin
30503e6c936aSmrg
30513e6c936aSmrg
30523e6c936aSmrg# func_convert_file_nix_to_cygwin ARG
30533e6c936aSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
30543e6c936aSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
30553e6c936aSmrg# in func_to_host_file_result.
30563e6c936aSmrgfunc_convert_file_nix_to_cygwin ()
30573e6c936aSmrg{
3058b0a0317aSmrg  $debug_cmd
3059b0a0317aSmrg
3060b0a0317aSmrg  func_to_host_file_result=$1
30613e6c936aSmrg  if test -n "$1"; then
30623e6c936aSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
30633e6c936aSmrg    func_convert_core_file_wine_to_w32 "$1"
30643e6c936aSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3065b0a0317aSmrg    func_to_host_file_result=$func_cygpath_result
30663e6c936aSmrg  fi
30673e6c936aSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30683e6c936aSmrg}
30693e6c936aSmrg# end func_convert_file_nix_to_cygwin
30703e6c936aSmrg
30713e6c936aSmrg
30723e6c936aSmrg#############################################
30733e6c936aSmrg# $build to $host PATH CONVERSION FUNCTIONS #
30743e6c936aSmrg#############################################
3075b0a0317aSmrg# invoked via '$to_host_path_cmd ARG'
30763e6c936aSmrg#
30773e6c936aSmrg# In each case, ARG is the path to be converted from $build to $host format.
30783e6c936aSmrg# The result will be available in $func_to_host_path_result.
30793e6c936aSmrg#
30803e6c936aSmrg# Path separators are also converted from $build format to $host format.  If
30813e6c936aSmrg# ARG begins or ends with a path separator character, it is preserved (but
30823e6c936aSmrg# converted to $host format) on output.
30833e6c936aSmrg#
30843e6c936aSmrg# All path conversion functions are named using the following convention:
30853e6c936aSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
30863e6c936aSmrg#   path conversion function         : func_convert_path_X_to_Y ()
30873e6c936aSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
30883e6c936aSmrg# same.  If conversion functions are added for new $build/$host combinations,
30893e6c936aSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
30903e6c936aSmrg# will break.
30913e6c936aSmrg
30923e6c936aSmrg
30933e6c936aSmrg# func_init_to_host_path_cmd
30943e6c936aSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
30953e6c936aSmrg# appropriate value, based on the value of $to_host_file_cmd.
30963e6c936aSmrgto_host_path_cmd=
30973e6c936aSmrgfunc_init_to_host_path_cmd ()
30983e6c936aSmrg{
3099b0a0317aSmrg  $debug_cmd
3100b0a0317aSmrg
31013e6c936aSmrg  if test -z "$to_host_path_cmd"; then
31023e6c936aSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3103b0a0317aSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
31043e6c936aSmrg  fi
31053e6c936aSmrg}
31063e6c936aSmrg
31073e6c936aSmrg
31083e6c936aSmrg# func_to_host_path ARG
31093e6c936aSmrg# Converts the path ARG from $build format to $host format. Return result
31103e6c936aSmrg# in func_to_host_path_result.
31113e6c936aSmrgfunc_to_host_path ()
31123e6c936aSmrg{
3113b0a0317aSmrg  $debug_cmd
3114b0a0317aSmrg
31153e6c936aSmrg  func_init_to_host_path_cmd
31163e6c936aSmrg  $to_host_path_cmd "$1"
31173e6c936aSmrg}
31183e6c936aSmrg# end func_to_host_path
31193e6c936aSmrg
31203e6c936aSmrg
31213e6c936aSmrg# func_convert_path_noop ARG
31223e6c936aSmrg# Copy ARG to func_to_host_path_result.
31233e6c936aSmrgfunc_convert_path_noop ()
31243e6c936aSmrg{
3125b0a0317aSmrg  func_to_host_path_result=$1
31263e6c936aSmrg}
31273e6c936aSmrg# end func_convert_path_noop
31283e6c936aSmrg
31293e6c936aSmrg
31303e6c936aSmrg# func_convert_path_msys_to_w32 ARG
31313e6c936aSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
31323e6c936aSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
31333e6c936aSmrg# func_to_host_path_result.
31343e6c936aSmrgfunc_convert_path_msys_to_w32 ()
31353e6c936aSmrg{
3136b0a0317aSmrg  $debug_cmd
3137b0a0317aSmrg
3138b0a0317aSmrg  func_to_host_path_result=$1
31393e6c936aSmrg  if test -n "$1"; then
31403e6c936aSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
31413e6c936aSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
31423e6c936aSmrg    # and winepath ignores them completely.
31433e6c936aSmrg    func_stripname : : "$1"
31443e6c936aSmrg    func_to_host_path_tmp1=$func_stripname_result
31453e6c936aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3146b0a0317aSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
31473e6c936aSmrg    func_convert_path_check : ";" \
31483e6c936aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31493e6c936aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31503e6c936aSmrg  fi
31513e6c936aSmrg}
31523e6c936aSmrg# end func_convert_path_msys_to_w32
31533e6c936aSmrg
31543e6c936aSmrg
31553e6c936aSmrg# func_convert_path_cygwin_to_w32 ARG
31563e6c936aSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
31573e6c936aSmrg# func_to_host_file_result.
31583e6c936aSmrgfunc_convert_path_cygwin_to_w32 ()
31593e6c936aSmrg{
3160b0a0317aSmrg  $debug_cmd
3161b0a0317aSmrg
3162b0a0317aSmrg  func_to_host_path_result=$1
31633e6c936aSmrg  if test -n "$1"; then
31643e6c936aSmrg    # See func_convert_path_msys_to_w32:
31653e6c936aSmrg    func_stripname : : "$1"
31663e6c936aSmrg    func_to_host_path_tmp1=$func_stripname_result
31673e6c936aSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
31683e6c936aSmrg    func_convert_path_check : ";" \
31693e6c936aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31703e6c936aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31713e6c936aSmrg  fi
31723e6c936aSmrg}
31733e6c936aSmrg# end func_convert_path_cygwin_to_w32
31743e6c936aSmrg
31753e6c936aSmrg
31763e6c936aSmrg# func_convert_path_nix_to_w32 ARG
31773e6c936aSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
31783e6c936aSmrg# a working winepath.  Returns result in func_to_host_file_result.
31793e6c936aSmrgfunc_convert_path_nix_to_w32 ()
3180521070a0Smrg{
3181b0a0317aSmrg  $debug_cmd
3182b0a0317aSmrg
3183b0a0317aSmrg  func_to_host_path_result=$1
31843e6c936aSmrg  if test -n "$1"; then
31853e6c936aSmrg    # See func_convert_path_msys_to_w32:
31863e6c936aSmrg    func_stripname : : "$1"
31873e6c936aSmrg    func_to_host_path_tmp1=$func_stripname_result
31883e6c936aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3189b0a0317aSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
31903e6c936aSmrg    func_convert_path_check : ";" \
31913e6c936aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31923e6c936aSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31933e6c936aSmrg  fi
31943e6c936aSmrg}
31953e6c936aSmrg# end func_convert_path_nix_to_w32
3196521070a0Smrg
3197521070a0Smrg
31983e6c936aSmrg# func_convert_path_msys_to_cygwin ARG
31993e6c936aSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
32003e6c936aSmrg# Returns result in func_to_host_file_result.
32013e6c936aSmrgfunc_convert_path_msys_to_cygwin ()
32023e6c936aSmrg{
3203b0a0317aSmrg  $debug_cmd
3204b0a0317aSmrg
3205b0a0317aSmrg  func_to_host_path_result=$1
32063e6c936aSmrg  if test -n "$1"; then
32073e6c936aSmrg    # See func_convert_path_msys_to_w32:
32083e6c936aSmrg    func_stripname : : "$1"
32093e6c936aSmrg    func_to_host_path_tmp1=$func_stripname_result
32103e6c936aSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
32113e6c936aSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3212b0a0317aSmrg    func_to_host_path_result=$func_cygpath_result
32133e6c936aSmrg    func_convert_path_check : : \
32143e6c936aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32153e6c936aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
32163e6c936aSmrg  fi
32173e6c936aSmrg}
32183e6c936aSmrg# end func_convert_path_msys_to_cygwin
3219521070a0Smrg
3220521070a0Smrg
32213e6c936aSmrg# func_convert_path_nix_to_cygwin ARG
32223e6c936aSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
32233e6c936aSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
32243e6c936aSmrg# func_to_host_file_result.
32253e6c936aSmrgfunc_convert_path_nix_to_cygwin ()
32263e6c936aSmrg{
3227b0a0317aSmrg  $debug_cmd
3228b0a0317aSmrg
3229b0a0317aSmrg  func_to_host_path_result=$1
32303e6c936aSmrg  if test -n "$1"; then
32313e6c936aSmrg    # Remove leading and trailing path separator characters from
32323e6c936aSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
32333e6c936aSmrg    # into '.;' and ';.', and winepath ignores them completely.
32343e6c936aSmrg    func_stripname : : "$1"
32353e6c936aSmrg    func_to_host_path_tmp1=$func_stripname_result
32363e6c936aSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
32373e6c936aSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3238b0a0317aSmrg    func_to_host_path_result=$func_cygpath_result
32393e6c936aSmrg    func_convert_path_check : : \
32403e6c936aSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32413e6c936aSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
32423e6c936aSmrg  fi
3243521070a0Smrg}
32443e6c936aSmrg# end func_convert_path_nix_to_cygwin
32453e6c936aSmrg
3246521070a0Smrg
3247b0a0317aSmrg# func_dll_def_p FILE
3248b0a0317aSmrg# True iff FILE is a Windows DLL '.def' file.
3249b0a0317aSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3250b0a0317aSmrgfunc_dll_def_p ()
3251b0a0317aSmrg{
3252b0a0317aSmrg  $debug_cmd
3253b0a0317aSmrg
3254b0a0317aSmrg  func_dll_def_p_tmp=`$SED -n \
3255b0a0317aSmrg    -e 's/^[	 ]*//' \
3256b0a0317aSmrg    -e '/^\(;.*\)*$/d' \
3257b0a0317aSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3258b0a0317aSmrg    -e q \
3259b0a0317aSmrg    "$1"`
3260b0a0317aSmrg  test DEF = "$func_dll_def_p_tmp"
3261b0a0317aSmrg}
3262b0a0317aSmrg
3263b0a0317aSmrg
3264521070a0Smrg# func_mode_compile arg...
3265521070a0Smrgfunc_mode_compile ()
3266521070a0Smrg{
3267b0a0317aSmrg    $debug_cmd
3268b0a0317aSmrg
3269521070a0Smrg    # Get the compilation command and the source file.
3270521070a0Smrg    base_compile=
3271b0a0317aSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3272521070a0Smrg    suppress_opt=yes
3273521070a0Smrg    suppress_output=
3274521070a0Smrg    arg_mode=normal
3275521070a0Smrg    libobj=
3276521070a0Smrg    later=
3277521070a0Smrg    pie_flag=
3278521070a0Smrg
3279521070a0Smrg    for arg
3280521070a0Smrg    do
3281521070a0Smrg      case $arg_mode in
3282521070a0Smrg      arg  )
3283521070a0Smrg	# do not "continue".  Instead, add this to base_compile
3284b0a0317aSmrg	lastarg=$arg
3285521070a0Smrg	arg_mode=normal
3286521070a0Smrg	;;
3287521070a0Smrg
3288521070a0Smrg      target )
3289b0a0317aSmrg	libobj=$arg
3290521070a0Smrg	arg_mode=normal
3291521070a0Smrg	continue
3292521070a0Smrg	;;
3293521070a0Smrg
3294521070a0Smrg      normal )
3295521070a0Smrg	# Accept any command-line options.
3296521070a0Smrg	case $arg in
3297521070a0Smrg	-o)
3298521070a0Smrg	  test -n "$libobj" && \
3299b0a0317aSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3300521070a0Smrg	  arg_mode=target
3301521070a0Smrg	  continue
3302521070a0Smrg	  ;;
3303521070a0Smrg
3304521070a0Smrg	-pie | -fpie | -fPIE)
33053e6c936aSmrg          func_append pie_flag " $arg"
3306521070a0Smrg	  continue
3307521070a0Smrg	  ;;
3308521070a0Smrg
3309521070a0Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
33103e6c936aSmrg	  func_append later " $arg"
3311521070a0Smrg	  continue
3312521070a0Smrg	  ;;
3313521070a0Smrg
3314521070a0Smrg	-no-suppress)
33154456fccdSmrg	  suppress_opt=no
33164456fccdSmrg	  continue
33174456fccdSmrg	  ;;
33184456fccdSmrg
33194456fccdSmrg	-Xcompiler)
33204456fccdSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
33214456fccdSmrg	  continue      #  The current "srcfile" will either be retained or
33224456fccdSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
33234456fccdSmrg
33244456fccdSmrg	-Wc,*)
3325521070a0Smrg	  func_stripname '-Wc,' '' "$arg"
3326521070a0Smrg	  args=$func_stripname_result
33274456fccdSmrg	  lastarg=
3328b0a0317aSmrg	  save_ifs=$IFS; IFS=,
3329521070a0Smrg	  for arg in $args; do
3330b0a0317aSmrg	    IFS=$save_ifs
33313e6c936aSmrg	    func_append_quoted lastarg "$arg"
33324456fccdSmrg	  done
3333b0a0317aSmrg	  IFS=$save_ifs
3334521070a0Smrg	  func_stripname ' ' '' "$lastarg"
3335521070a0Smrg	  lastarg=$func_stripname_result
33364456fccdSmrg
33374456fccdSmrg	  # Add the arguments to base_compile.
33383e6c936aSmrg	  func_append base_compile " $lastarg"
33394456fccdSmrg	  continue
33404456fccdSmrg	  ;;
33414456fccdSmrg
3342521070a0Smrg	*)
33434456fccdSmrg	  # Accept the current argument as the source file.
33444456fccdSmrg	  # The previous "srcfile" becomes the current argument.
33454456fccdSmrg	  #
3346b0a0317aSmrg	  lastarg=$srcfile
3347b0a0317aSmrg	  srcfile=$arg
33484456fccdSmrg	  ;;
33494456fccdSmrg	esac  #  case $arg
33504456fccdSmrg	;;
33514456fccdSmrg      esac    #  case $arg_mode
33524456fccdSmrg
33534456fccdSmrg      # Aesthetically quote the previous argument.
33543e6c936aSmrg      func_append_quoted base_compile "$lastarg"
33554456fccdSmrg    done # for arg
33564456fccdSmrg
33574456fccdSmrg    case $arg_mode in
33584456fccdSmrg    arg)
3359521070a0Smrg      func_fatal_error "you must specify an argument for -Xcompile"
33604456fccdSmrg      ;;
33614456fccdSmrg    target)
3362b0a0317aSmrg      func_fatal_error "you must specify a target with '-o'"
33634456fccdSmrg      ;;
33644456fccdSmrg    *)
33654456fccdSmrg      # Get the name of the library object.
3366521070a0Smrg      test -z "$libobj" && {
3367521070a0Smrg	func_basename "$srcfile"
3368b0a0317aSmrg	libobj=$func_basename_result
3369521070a0Smrg      }
33704456fccdSmrg      ;;
33714456fccdSmrg    esac
33724456fccdSmrg
33734456fccdSmrg    # Recognize several different file suffixes.
33744456fccdSmrg    # If the user specifies -o file.o, it is replaced with file.lo
33754456fccdSmrg    case $libobj in
3376521070a0Smrg    *.[cCFSifmso] | \
3377521070a0Smrg    *.ada | *.adb | *.ads | *.asm | \
3378521070a0Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
33793e6c936aSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3380521070a0Smrg      func_xform "$libobj"
3381521070a0Smrg      libobj=$func_xform_result
3382521070a0Smrg      ;;
33834456fccdSmrg    esac
33844456fccdSmrg
33854456fccdSmrg    case $libobj in
3386521070a0Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
33874456fccdSmrg    *)
3388b0a0317aSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
33894456fccdSmrg      ;;
33904456fccdSmrg    esac
33914456fccdSmrg
33924456fccdSmrg    func_infer_tag $base_compile
33934456fccdSmrg
33944456fccdSmrg    for arg in $later; do
33954456fccdSmrg      case $arg in
3396521070a0Smrg      -shared)
3397b0a0317aSmrg	test yes = "$build_libtool_libs" \
3398b0a0317aSmrg	  || func_fatal_configuration "cannot build a shared library"
3399521070a0Smrg	build_old_libs=no
3400521070a0Smrg	continue
3401521070a0Smrg	;;
3402521070a0Smrg
34034456fccdSmrg      -static)
3404521070a0Smrg	build_libtool_libs=no
34054456fccdSmrg	build_old_libs=yes
34064456fccdSmrg	continue
34074456fccdSmrg	;;
34084456fccdSmrg
34094456fccdSmrg      -prefer-pic)
34104456fccdSmrg	pic_mode=yes
34114456fccdSmrg	continue
34124456fccdSmrg	;;
34134456fccdSmrg
34144456fccdSmrg      -prefer-non-pic)
34154456fccdSmrg	pic_mode=no
34164456fccdSmrg	continue
34174456fccdSmrg	;;
34184456fccdSmrg      esac
34194456fccdSmrg    done
34204456fccdSmrg
3421521070a0Smrg    func_quote_for_eval "$libobj"
3422521070a0Smrg    test "X$libobj" != "X$func_quote_for_eval_result" \
3423521070a0Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3424b0a0317aSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3425521070a0Smrg    func_dirname_and_basename "$obj" "/" ""
3426b0a0317aSmrg    objname=$func_basename_result
3427b0a0317aSmrg    xdir=$func_dirname_result
3428b0a0317aSmrg    lobj=$xdir$objdir/$objname
34294456fccdSmrg
3430521070a0Smrg    test -z "$base_compile" && \
3431521070a0Smrg      func_fatal_help "you must specify a compilation command"
34324456fccdSmrg
34334456fccdSmrg    # Delete any leftover library objects.
3434b0a0317aSmrg    if test yes = "$build_old_libs"; then
34354456fccdSmrg      removelist="$obj $lobj $libobj ${libobj}T"
34364456fccdSmrg    else
34374456fccdSmrg      removelist="$lobj $libobj ${libobj}T"
34384456fccdSmrg    fi
34394456fccdSmrg
34404456fccdSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
34414456fccdSmrg    case $host_os in
3442521070a0Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
34434456fccdSmrg      pic_mode=default
34444456fccdSmrg      ;;
34454456fccdSmrg    esac
3446b0a0317aSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
34474456fccdSmrg      # non-PIC code in shared libraries is not supported
34484456fccdSmrg      pic_mode=default
34494456fccdSmrg    fi
34504456fccdSmrg
34514456fccdSmrg    # Calculate the filename of the output object if compiler does
34524456fccdSmrg    # not support -o with -c
3453b0a0317aSmrg    if test no = "$compiler_c_o"; then
3454b0a0317aSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3455b0a0317aSmrg      lockfile=$output_obj.lock
34564456fccdSmrg    else
34574456fccdSmrg      output_obj=
34584456fccdSmrg      need_locks=no
34594456fccdSmrg      lockfile=
34604456fccdSmrg    fi
34614456fccdSmrg
34624456fccdSmrg    # Lock this critical section if it is needed
34634456fccdSmrg    # We use this script file to make the link, it avoids creating a new file
3464b0a0317aSmrg    if test yes = "$need_locks"; then
3465521070a0Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3466521070a0Smrg	func_echo "Waiting for $lockfile to be removed"
34674456fccdSmrg	sleep 2
34684456fccdSmrg      done
3469b0a0317aSmrg    elif test warn = "$need_locks"; then
34704456fccdSmrg      if test -f "$lockfile"; then
3471521070a0Smrg	$ECHO "\
34724456fccdSmrg*** ERROR, $lockfile exists and contains:
34734456fccdSmrg`cat $lockfile 2>/dev/null`
34744456fccdSmrg
34754456fccdSmrgThis indicates that another process is trying to use the same
34764456fccdSmrgtemporary object file, and libtool could not work around it because
3477b0a0317aSmrgyour compiler does not support '-c' and '-o' together.  If you
34784456fccdSmrgrepeat this compilation, it may succeed, by chance, but you had better
34794456fccdSmrgavoid parallel builds (make -j) in this platform, or get a better
34804456fccdSmrgcompiler."
34814456fccdSmrg
3482521070a0Smrg	$opt_dry_run || $RM $removelist
34834456fccdSmrg	exit $EXIT_FAILURE
34844456fccdSmrg      fi
34853e6c936aSmrg      func_append removelist " $output_obj"
3486521070a0Smrg      $ECHO "$srcfile" > "$lockfile"
34874456fccdSmrg    fi
34884456fccdSmrg
3489521070a0Smrg    $opt_dry_run || $RM $removelist
34903e6c936aSmrg    func_append removelist " $lockfile"
3491521070a0Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3492521070a0Smrg
34933e6c936aSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
34943e6c936aSmrg    srcfile=$func_to_tool_file_result
3495521070a0Smrg    func_quote_for_eval "$srcfile"
3496521070a0Smrg    qsrcfile=$func_quote_for_eval_result
34974456fccdSmrg
34984456fccdSmrg    # Only build a PIC object if we are building libtool libraries.
3499b0a0317aSmrg    if test yes = "$build_libtool_libs"; then
35004456fccdSmrg      # Without this assignment, base_compile gets emptied.
35014456fccdSmrg      fbsd_hideous_sh_bug=$base_compile
35024456fccdSmrg
3503b0a0317aSmrg      if test no != "$pic_mode"; then
35044456fccdSmrg	command="$base_compile $qsrcfile $pic_flag"
35054456fccdSmrg      else
35064456fccdSmrg	# Don't build PIC code
35074456fccdSmrg	command="$base_compile $qsrcfile"
35084456fccdSmrg      fi
35094456fccdSmrg
3510521070a0Smrg      func_mkdir_p "$xdir$objdir"
35114456fccdSmrg
35124456fccdSmrg      if test -z "$output_obj"; then
35134456fccdSmrg	# Place PIC objects in $objdir
35143e6c936aSmrg	func_append command " -o $lobj"
35154456fccdSmrg      fi
35164456fccdSmrg
3517521070a0Smrg      func_show_eval_locale "$command"	\
3518521070a0Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
35194456fccdSmrg
3520b0a0317aSmrg      if test warn = "$need_locks" &&
35214456fccdSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3522521070a0Smrg	$ECHO "\
35234456fccdSmrg*** ERROR, $lockfile contains:
35244456fccdSmrg`cat $lockfile 2>/dev/null`
35254456fccdSmrg
35264456fccdSmrgbut it should contain:
35274456fccdSmrg$srcfile
35284456fccdSmrg
35294456fccdSmrgThis indicates that another process is trying to use the same
35304456fccdSmrgtemporary object file, and libtool could not work around it because
3531b0a0317aSmrgyour compiler does not support '-c' and '-o' together.  If you
35324456fccdSmrgrepeat this compilation, it may succeed, by chance, but you had better
35334456fccdSmrgavoid parallel builds (make -j) in this platform, or get a better
35344456fccdSmrgcompiler."
35354456fccdSmrg
3536521070a0Smrg	$opt_dry_run || $RM $removelist
35374456fccdSmrg	exit $EXIT_FAILURE
35384456fccdSmrg      fi
35394456fccdSmrg
35404456fccdSmrg      # Just move the object if needed, then go on to compile the next one
35414456fccdSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3542521070a0Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3543521070a0Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
35444456fccdSmrg      fi
35454456fccdSmrg
35464456fccdSmrg      # Allow error messages only from the first compilation.
3547b0a0317aSmrg      if test yes = "$suppress_opt"; then
3548521070a0Smrg	suppress_output=' >/dev/null 2>&1'
35494456fccdSmrg      fi
35504456fccdSmrg    fi
35514456fccdSmrg
35524456fccdSmrg    # Only build a position-dependent object if we build old libraries.
3553b0a0317aSmrg    if test yes = "$build_old_libs"; then
3554b0a0317aSmrg      if test yes != "$pic_mode"; then
35554456fccdSmrg	# Don't build PIC code
3556521070a0Smrg	command="$base_compile $qsrcfile$pie_flag"
35574456fccdSmrg      else
35584456fccdSmrg	command="$base_compile $qsrcfile $pic_flag"
35594456fccdSmrg      fi
3560b0a0317aSmrg      if test yes = "$compiler_c_o"; then
35613e6c936aSmrg	func_append command " -o $obj"
35624456fccdSmrg      fi
35634456fccdSmrg
35644456fccdSmrg      # Suppress compiler output if we already did a PIC compilation.
35653e6c936aSmrg      func_append command "$suppress_output"
3566521070a0Smrg      func_show_eval_locale "$command" \
3567521070a0Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
35684456fccdSmrg
3569b0a0317aSmrg      if test warn = "$need_locks" &&
35704456fccdSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3571521070a0Smrg	$ECHO "\
35724456fccdSmrg*** ERROR, $lockfile contains:
35734456fccdSmrg`cat $lockfile 2>/dev/null`
35744456fccdSmrg
35754456fccdSmrgbut it should contain:
35764456fccdSmrg$srcfile
35774456fccdSmrg
35784456fccdSmrgThis indicates that another process is trying to use the same
35794456fccdSmrgtemporary object file, and libtool could not work around it because
3580b0a0317aSmrgyour compiler does not support '-c' and '-o' together.  If you
35814456fccdSmrgrepeat this compilation, it may succeed, by chance, but you had better
35824456fccdSmrgavoid parallel builds (make -j) in this platform, or get a better
35834456fccdSmrgcompiler."
35844456fccdSmrg
3585521070a0Smrg	$opt_dry_run || $RM $removelist
35864456fccdSmrg	exit $EXIT_FAILURE
35874456fccdSmrg      fi
35884456fccdSmrg
35894456fccdSmrg      # Just move the object if needed
35904456fccdSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3591521070a0Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
3592521070a0Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
35934456fccdSmrg      fi
35944456fccdSmrg    fi
35954456fccdSmrg
3596521070a0Smrg    $opt_dry_run || {
3597521070a0Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
35984456fccdSmrg
3599521070a0Smrg      # Unlock the critical section if it was locked
3600b0a0317aSmrg      if test no != "$need_locks"; then
3601521070a0Smrg	removelist=$lockfile
3602521070a0Smrg        $RM "$lockfile"
3603521070a0Smrg      fi
3604521070a0Smrg    }
36054456fccdSmrg
36064456fccdSmrg    exit $EXIT_SUCCESS
3607521070a0Smrg}
36084456fccdSmrg
3609521070a0Smrg$opt_help || {
3610b0a0317aSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3611521070a0Smrg}
36124456fccdSmrg
3613521070a0Smrgfunc_mode_help ()
3614521070a0Smrg{
3615521070a0Smrg    # We need to display help for each of the modes.
36163e6c936aSmrg    case $opt_mode in
3617521070a0Smrg      "")
3618521070a0Smrg        # Generic help is extracted from the usage comments
3619521070a0Smrg        # at the start of this file.
3620521070a0Smrg        func_help
3621521070a0Smrg        ;;
36224456fccdSmrg
3623521070a0Smrg      clean)
3624521070a0Smrg        $ECHO \
3625521070a0Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
36264456fccdSmrg
3627521070a0SmrgRemove files from the build directory.
36284456fccdSmrg
3629521070a0SmrgRM is the name of the program to use to delete files associated with each FILE
3630b0a0317aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3631521070a0Smrgto RM.
36324456fccdSmrg
3633521070a0SmrgIf FILE is a libtool library, object or program, all the files associated
3634521070a0Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3635521070a0Smrg        ;;
36364456fccdSmrg
3637521070a0Smrg      compile)
3638521070a0Smrg      $ECHO \
3639521070a0Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
36404456fccdSmrg
3641521070a0SmrgCompile a source file into a libtool library object.
36424456fccdSmrg
3643521070a0SmrgThis mode accepts the following additional options:
36444456fccdSmrg
3645521070a0Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3646521070a0Smrg  -no-suppress      do not suppress compiler output for multiple passes
3647ff63a143Smrg  -prefer-pic       try to build PIC objects only
3648ff63a143Smrg  -prefer-non-pic   try to build non-PIC objects only
3649b0a0317aSmrg  -shared           do not build a '.o' file suitable for static linking
3650b0a0317aSmrg  -static           only build a '.o' file suitable for static linking
3651ff63a143Smrg  -Wc,FLAG          pass FLAG directly to the compiler
36524456fccdSmrg
3653b0a0317aSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3654521070a0Smrgfrom the given SOURCEFILE.
36554456fccdSmrg
3656521070a0SmrgThe output file name is determined by removing the directory component from
3657b0a0317aSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3658b0a0317aSmrglibrary object suffix, '.lo'."
3659521070a0Smrg        ;;
36604456fccdSmrg
3661521070a0Smrg      execute)
3662521070a0Smrg        $ECHO \
3663521070a0Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
36644456fccdSmrg
3665521070a0SmrgAutomatically set library path, then run a program.
36664456fccdSmrg
3667521070a0SmrgThis mode accepts the following additional options:
36684456fccdSmrg
3669521070a0Smrg  -dlopen FILE      add the directory containing FILE to the library path
36704456fccdSmrg
3671b0a0317aSmrgThis mode sets the library path environment variable according to '-dlopen'
3672521070a0Smrgflags.
36734456fccdSmrg
3674521070a0SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3675521070a0Smrginto their corresponding uninstalled binary, and any of their required library
3676521070a0Smrgdirectories are added to the library path.
36774456fccdSmrg
3678521070a0SmrgThen, COMMAND is executed, with ARGS as arguments."
3679521070a0Smrg        ;;
36804456fccdSmrg
3681521070a0Smrg      finish)
3682521070a0Smrg        $ECHO \
3683521070a0Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
36844456fccdSmrg
3685521070a0SmrgComplete the installation of libtool libraries.
36864456fccdSmrg
3687521070a0SmrgEach LIBDIR is a directory that contains libtool libraries.
36884456fccdSmrg
3689521070a0SmrgThe commands that this mode executes may require superuser privileges.  Use
3690b0a0317aSmrgthe '--dry-run' option if you just want to see what would be executed."
3691521070a0Smrg        ;;
36924456fccdSmrg
3693521070a0Smrg      install)
3694521070a0Smrg        $ECHO \
3695521070a0Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
36964456fccdSmrg
3697521070a0SmrgInstall executables or libraries.
36984456fccdSmrg
3699521070a0SmrgINSTALL-COMMAND is the installation command.  The first component should be
3700b0a0317aSmrgeither the 'install' or 'cp' program.
37014456fccdSmrg
3702521070a0SmrgThe following components of INSTALL-COMMAND are treated specially:
37034456fccdSmrg
3704ff63a143Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
37054456fccdSmrg
3706521070a0SmrgThe rest of the components are interpreted as arguments to that command (only
3707521070a0SmrgBSD-compatible install options are recognized)."
3708521070a0Smrg        ;;
37094456fccdSmrg
3710521070a0Smrg      link)
3711521070a0Smrg        $ECHO \
3712521070a0Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
37134456fccdSmrg
3714521070a0SmrgLink object files or libraries together to form another library, or to
3715521070a0Smrgcreate an executable program.
37164456fccdSmrg
3717521070a0SmrgLINK-COMMAND is a command using the C compiler that you would use to create
3718521070a0Smrga program from several object files.
37194456fccdSmrg
3720521070a0SmrgThe following components of LINK-COMMAND are treated specially:
37214456fccdSmrg
3722521070a0Smrg  -all-static       do not do any dynamic linking at all
3723521070a0Smrg  -avoid-version    do not add a version suffix if possible
3724ff63a143Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
3725ff63a143Smrg                    libraries must be found in the PATH setting at runtime)
3726b0a0317aSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3727521070a0Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3728521070a0Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3729521070a0Smrg  -export-symbols SYMFILE
3730521070a0Smrg                    try to export only the symbols listed in SYMFILE
3731521070a0Smrg  -export-symbols-regex REGEX
3732521070a0Smrg                    try to export only the symbols matching REGEX
3733521070a0Smrg  -LLIBDIR          search LIBDIR for required installed libraries
3734521070a0Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3735521070a0Smrg  -module           build a library that can dlopened
3736521070a0Smrg  -no-fast-install  disable the fast-install mode
3737521070a0Smrg  -no-install       link a not-installable executable
3738521070a0Smrg  -no-undefined     declare that a library does not refer to external symbols
3739521070a0Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3740b0a0317aSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3741b0a0317aSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3742521070a0Smrg  -precious-files-regex REGEX
3743521070a0Smrg                    don't remove output files matching REGEX
3744521070a0Smrg  -release RELEASE  specify package release information
3745521070a0Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
3746521070a0Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
3747521070a0Smrg  -shared           only do dynamic linking of libtool libraries
3748521070a0Smrg  -shrext SUFFIX    override the standard shared library file extension
3749521070a0Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
3750521070a0Smrg  -static-libtool-libs
3751521070a0Smrg                    do not do any dynamic linking of libtool libraries
3752521070a0Smrg  -version-info CURRENT[:REVISION[:AGE]]
3753521070a0Smrg                    specify library version info [each variable defaults to 0]
3754521070a0Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
3755ff63a143Smrg  -Wc,FLAG
3756ff63a143Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
3757ff63a143Smrg  -Wl,FLAG
3758ff63a143Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
3759ff63a143Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
37604456fccdSmrg
3761b0a0317aSmrgAll other options (arguments beginning with '-') are ignored.
37624456fccdSmrg
3763b0a0317aSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
3764521070a0Smrgtreated as uninstalled libtool libraries, other files are standard or library
3765521070a0Smrgobject files.
376642d69509Smrg
3767b0a0317aSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
3768b0a0317aSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
3769521070a0Smrgrequired, except when creating a convenience library.
37704456fccdSmrg
3771b0a0317aSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
3772b0a0317aSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
37734456fccdSmrg
3774b0a0317aSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
3775521070a0Smrgis created, otherwise an executable program is created."
37764456fccdSmrg        ;;
37774456fccdSmrg
3778521070a0Smrg      uninstall)
3779521070a0Smrg        $ECHO \
3780521070a0Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
37814456fccdSmrg
3782521070a0SmrgRemove libraries from an installation directory.
37834456fccdSmrg
3784521070a0SmrgRM is the name of the program to use to delete files associated with each FILE
3785b0a0317aSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3786521070a0Smrgto RM.
37874456fccdSmrg
3788521070a0SmrgIf FILE is a libtool library, all the files associated with it are deleted.
3789521070a0SmrgOtherwise, only FILE itself is deleted using RM."
3790521070a0Smrg        ;;
37914456fccdSmrg
3792521070a0Smrg      *)
3793b0a0317aSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
3794521070a0Smrg        ;;
3795521070a0Smrg    esac
37964456fccdSmrg
3797ff63a143Smrg    echo
3798b0a0317aSmrg    $ECHO "Try '$progname --help' for more information about other modes."
3799521070a0Smrg}
38004456fccdSmrg
3801ff63a143Smrg# Now that we've collected a possible --mode arg, show help if necessary
3802ff63a143Smrgif $opt_help; then
3803b0a0317aSmrg  if test : = "$opt_help"; then
3804ff63a143Smrg    func_mode_help
3805ff63a143Smrg  else
3806ff63a143Smrg    {
3807ff63a143Smrg      func_help noexit
38083e6c936aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
3809ff63a143Smrg	func_mode_help
3810ff63a143Smrg      done
3811b0a0317aSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
3812ff63a143Smrg    {
3813ff63a143Smrg      func_help noexit
38143e6c936aSmrg      for opt_mode in compile link execute install finish uninstall clean; do
3815ff63a143Smrg	echo
3816ff63a143Smrg	func_mode_help
3817ff63a143Smrg      done
3818ff63a143Smrg    } |
3819b0a0317aSmrg    $SED '1d
3820ff63a143Smrg      /^When reporting/,/^Report/{
3821ff63a143Smrg	H
3822ff63a143Smrg	d
3823ff63a143Smrg      }
3824ff63a143Smrg      $x
3825ff63a143Smrg      /information about other modes/d
3826ff63a143Smrg      /more detailed .*MODE/d
3827ff63a143Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
3828ff63a143Smrg  fi
3829ff63a143Smrg  exit $?
3830ff63a143Smrgfi
38314456fccdSmrg
38324456fccdSmrg
3833521070a0Smrg# func_mode_execute arg...
3834521070a0Smrgfunc_mode_execute ()
3835521070a0Smrg{
3836b0a0317aSmrg    $debug_cmd
3837b0a0317aSmrg
3838521070a0Smrg    # The first argument is the command name.
3839b0a0317aSmrg    cmd=$nonopt
3840521070a0Smrg    test -z "$cmd" && \
3841521070a0Smrg      func_fatal_help "you must specify a COMMAND"
38424456fccdSmrg
3843521070a0Smrg    # Handle -dlopen flags immediately.
38443e6c936aSmrg    for file in $opt_dlopen; do
3845521070a0Smrg      test -f "$file" \
3846b0a0317aSmrg	|| func_fatal_help "'$file' is not a file"
38474456fccdSmrg
3848521070a0Smrg      dir=
3849521070a0Smrg      case $file in
3850521070a0Smrg      *.la)
38513e6c936aSmrg	func_resolve_sysroot "$file"
38523e6c936aSmrg	file=$func_resolve_sysroot_result
38533e6c936aSmrg
3854521070a0Smrg	# Check to see that this really is a libtool archive.
3855521070a0Smrg	func_lalib_unsafe_p "$file" \
3856b0a0317aSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
38574456fccdSmrg
3858521070a0Smrg	# Read the libtool library.
3859521070a0Smrg	dlname=
3860521070a0Smrg	library_names=
3861521070a0Smrg	func_source "$file"
38624456fccdSmrg
3863521070a0Smrg	# Skip this library if it cannot be dlopened.
3864521070a0Smrg	if test -z "$dlname"; then
3865521070a0Smrg	  # Warn if it was a shared library.
3866521070a0Smrg	  test -n "$library_names" && \
3867b0a0317aSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
3868521070a0Smrg	  continue
3869521070a0Smrg	fi
38704456fccdSmrg
3871521070a0Smrg	func_dirname "$file" "" "."
3872b0a0317aSmrg	dir=$func_dirname_result
38734456fccdSmrg
3874521070a0Smrg	if test -f "$dir/$objdir/$dlname"; then
38753e6c936aSmrg	  func_append dir "/$objdir"
3876521070a0Smrg	else
3877521070a0Smrg	  if test ! -f "$dir/$dlname"; then
3878b0a0317aSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
3879521070a0Smrg	  fi
3880521070a0Smrg	fi
38814456fccdSmrg	;;
38824456fccdSmrg
3883521070a0Smrg      *.lo)
3884521070a0Smrg	# Just add the directory containing the .lo file.
3885521070a0Smrg	func_dirname "$file" "" "."
3886b0a0317aSmrg	dir=$func_dirname_result
38874456fccdSmrg	;;
38884456fccdSmrg
3889521070a0Smrg      *)
3890b0a0317aSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
38914456fccdSmrg	continue
38924456fccdSmrg	;;
3893521070a0Smrg      esac
38944456fccdSmrg
3895521070a0Smrg      # Get the absolute pathname.
3896521070a0Smrg      absdir=`cd "$dir" && pwd`
3897b0a0317aSmrg      test -n "$absdir" && dir=$absdir
38984456fccdSmrg
3899521070a0Smrg      # Now add the directory to shlibpath_var.
3900521070a0Smrg      if eval "test -z \"\$$shlibpath_var\""; then
3901521070a0Smrg	eval "$shlibpath_var=\"\$dir\""
3902521070a0Smrg      else
3903521070a0Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
3904521070a0Smrg      fi
3905521070a0Smrg    done
39064456fccdSmrg
3907521070a0Smrg    # This variable tells wrapper scripts just to set shlibpath_var
3908521070a0Smrg    # rather than running their programs.
3909b0a0317aSmrg    libtool_execute_magic=$magic
39104456fccdSmrg
3911521070a0Smrg    # Check if any of the arguments is a wrapper script.
3912521070a0Smrg    args=
3913521070a0Smrg    for file
3914521070a0Smrg    do
3915521070a0Smrg      case $file in
3916ff63a143Smrg      -* | *.la | *.lo ) ;;
3917521070a0Smrg      *)
3918521070a0Smrg	# Do a test to see if this is really a libtool program.
3919521070a0Smrg	if func_ltwrapper_script_p "$file"; then
3920521070a0Smrg	  func_source "$file"
3921521070a0Smrg	  # Transform arg to wrapped name.
3922b0a0317aSmrg	  file=$progdir/$program
3923521070a0Smrg	elif func_ltwrapper_executable_p "$file"; then
3924521070a0Smrg	  func_ltwrapper_scriptname "$file"
3925521070a0Smrg	  func_source "$func_ltwrapper_scriptname_result"
3926521070a0Smrg	  # Transform arg to wrapped name.
3927b0a0317aSmrg	  file=$progdir/$program
3928521070a0Smrg	fi
3929521070a0Smrg	;;
3930521070a0Smrg      esac
3931521070a0Smrg      # Quote arguments (to preserve shell metacharacters).
39323e6c936aSmrg      func_append_quoted args "$file"
3933521070a0Smrg    done
39344456fccdSmrg
3935b0a0317aSmrg    if $opt_dry_run; then
3936b0a0317aSmrg      # Display what would be done.
3937b0a0317aSmrg      if test -n "$shlibpath_var"; then
3938b0a0317aSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
3939b0a0317aSmrg	echo "export $shlibpath_var"
3940b0a0317aSmrg      fi
3941b0a0317aSmrg      $ECHO "$cmd$args"
3942b0a0317aSmrg      exit $EXIT_SUCCESS
3943b0a0317aSmrg    else
3944521070a0Smrg      if test -n "$shlibpath_var"; then
3945521070a0Smrg	# Export the shlibpath_var.
3946521070a0Smrg	eval "export $shlibpath_var"
3947521070a0Smrg      fi
39484456fccdSmrg
3949521070a0Smrg      # Restore saved environment variables
3950521070a0Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
3951521070a0Smrg      do
3952521070a0Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
3953521070a0Smrg                $lt_var=\$save_$lt_var; export $lt_var
39544456fccdSmrg	      else
3955521070a0Smrg		$lt_unset $lt_var
3956521070a0Smrg	      fi"
3957521070a0Smrg      done
39584456fccdSmrg
3959521070a0Smrg      # Now prepare to actually exec the command.
3960b0a0317aSmrg      exec_cmd=\$cmd$args
3961521070a0Smrg    fi
3962521070a0Smrg}
39634456fccdSmrg
3964b0a0317aSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
39654456fccdSmrg
39664456fccdSmrg
3967521070a0Smrg# func_mode_finish arg...
3968521070a0Smrgfunc_mode_finish ()
3969521070a0Smrg{
3970b0a0317aSmrg    $debug_cmd
3971b0a0317aSmrg
39723e6c936aSmrg    libs=
39733e6c936aSmrg    libdirs=
3974521070a0Smrg    admincmds=
39754456fccdSmrg
39763e6c936aSmrg    for opt in "$nonopt" ${1+"$@"}
39773e6c936aSmrg    do
39783e6c936aSmrg      if test -d "$opt"; then
39793e6c936aSmrg	func_append libdirs " $opt"
39803e6c936aSmrg
39813e6c936aSmrg      elif test -f "$opt"; then
39823e6c936aSmrg	if func_lalib_unsafe_p "$opt"; then
39833e6c936aSmrg	  func_append libs " $opt"
39843e6c936aSmrg	else
3985b0a0317aSmrg	  func_warning "'$opt' is not a valid libtool archive"
39863e6c936aSmrg	fi
39873e6c936aSmrg
39883e6c936aSmrg      else
3989b0a0317aSmrg	func_fatal_error "invalid argument '$opt'"
39903e6c936aSmrg      fi
39913e6c936aSmrg    done
39923e6c936aSmrg
39933e6c936aSmrg    if test -n "$libs"; then
39943e6c936aSmrg      if test -n "$lt_sysroot"; then
39953e6c936aSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
39963e6c936aSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
39973e6c936aSmrg      else
39983e6c936aSmrg        sysroot_cmd=
39993e6c936aSmrg      fi
40003e6c936aSmrg
40013e6c936aSmrg      # Remove sysroot references
40023e6c936aSmrg      if $opt_dry_run; then
40033e6c936aSmrg        for lib in $libs; do
4004b0a0317aSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
40053e6c936aSmrg        done
40063e6c936aSmrg      else
40073e6c936aSmrg        tmpdir=`func_mktempdir`
40083e6c936aSmrg        for lib in $libs; do
4009b0a0317aSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
40103e6c936aSmrg	    > $tmpdir/tmp-la
40113e6c936aSmrg	  mv -f $tmpdir/tmp-la $lib
40123e6c936aSmrg	done
40133e6c936aSmrg        ${RM}r "$tmpdir"
40143e6c936aSmrg      fi
40153e6c936aSmrg    fi
40164456fccdSmrg
40173e6c936aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4018521070a0Smrg      for libdir in $libdirs; do
4019521070a0Smrg	if test -n "$finish_cmds"; then
4020521070a0Smrg	  # Do each command in the finish commands.
4021521070a0Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4022521070a0Smrg'"$cmd"'"'
40234456fccdSmrg	fi
4024521070a0Smrg	if test -n "$finish_eval"; then
4025521070a0Smrg	  # Do the single finish_eval.
4026521070a0Smrg	  eval cmds=\"$finish_eval\"
40273e6c936aSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4028521070a0Smrg       $cmds"
4029521070a0Smrg	fi
4030521070a0Smrg      done
4031521070a0Smrg    fi
40324456fccdSmrg
4033521070a0Smrg    # Exit here if they wanted silent mode.
4034b0a0317aSmrg    $opt_quiet && exit $EXIT_SUCCESS
40354456fccdSmrg
40363e6c936aSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
40373e6c936aSmrg      echo "----------------------------------------------------------------------"
40383e6c936aSmrg      echo "Libraries have been installed in:"
40393e6c936aSmrg      for libdir in $libdirs; do
40403e6c936aSmrg	$ECHO "   $libdir"
40413e6c936aSmrg      done
40423e6c936aSmrg      echo
40433e6c936aSmrg      echo "If you ever happen to want to link against installed libraries"
40443e6c936aSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4045b0a0317aSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
40463e6c936aSmrg      echo "flag during linking and do at least one of the following:"
40473e6c936aSmrg      if test -n "$shlibpath_var"; then
4048b0a0317aSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
40493e6c936aSmrg	echo "     during execution"
40503e6c936aSmrg      fi
40513e6c936aSmrg      if test -n "$runpath_var"; then
4052b0a0317aSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
40533e6c936aSmrg	echo "     during linking"
40543e6c936aSmrg      fi
40553e6c936aSmrg      if test -n "$hardcode_libdir_flag_spec"; then
40563e6c936aSmrg	libdir=LIBDIR
40573e6c936aSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
4058521070a0Smrg
4059b0a0317aSmrg	$ECHO "   - use the '$flag' linker flag"
40603e6c936aSmrg      fi
40613e6c936aSmrg      if test -n "$admincmds"; then
40623e6c936aSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
40633e6c936aSmrg      fi
40643e6c936aSmrg      if test -f /etc/ld.so.conf; then
4065b0a0317aSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
40663e6c936aSmrg      fi
40673e6c936aSmrg      echo
4068521070a0Smrg
40693e6c936aSmrg      echo "See any operating system documentation about shared libraries for"
40703e6c936aSmrg      case $host in
40713e6c936aSmrg	solaris2.[6789]|solaris2.1[0-9])
40723e6c936aSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
40733e6c936aSmrg	  echo "pages."
40743e6c936aSmrg	  ;;
40753e6c936aSmrg	*)
40763e6c936aSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
40773e6c936aSmrg	  ;;
40783e6c936aSmrg      esac
40793e6c936aSmrg      echo "----------------------------------------------------------------------"
40803e6c936aSmrg    fi
4081521070a0Smrg    exit $EXIT_SUCCESS
4082521070a0Smrg}
4083521070a0Smrg
4084b0a0317aSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4085521070a0Smrg
4086521070a0Smrg
4087521070a0Smrg# func_mode_install arg...
4088521070a0Smrgfunc_mode_install ()
4089521070a0Smrg{
4090b0a0317aSmrg    $debug_cmd
4091b0a0317aSmrg
4092521070a0Smrg    # There may be an optional sh(1) argument at the beginning of
4093521070a0Smrg    # install_prog (especially on Windows NT).
4094b0a0317aSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4095521070a0Smrg       # Allow the use of GNU shtool's install command.
4096b0a0317aSmrg       case $nonopt in *shtool*) :;; *) false;; esac
4097b0a0317aSmrg    then
4098521070a0Smrg      # Aesthetically quote it.
4099521070a0Smrg      func_quote_for_eval "$nonopt"
4100521070a0Smrg      install_prog="$func_quote_for_eval_result "
4101521070a0Smrg      arg=$1
4102521070a0Smrg      shift
4103521070a0Smrg    else
4104521070a0Smrg      install_prog=
4105521070a0Smrg      arg=$nonopt
4106521070a0Smrg    fi
4107521070a0Smrg
4108521070a0Smrg    # The real first argument should be the name of the installation program.
4109521070a0Smrg    # Aesthetically quote it.
4110521070a0Smrg    func_quote_for_eval "$arg"
41113e6c936aSmrg    func_append install_prog "$func_quote_for_eval_result"
4112ff63a143Smrg    install_shared_prog=$install_prog
4113ff63a143Smrg    case " $install_prog " in
4114ff63a143Smrg      *[\\\ /]cp\ *) install_cp=: ;;
4115ff63a143Smrg      *) install_cp=false ;;
4116ff63a143Smrg    esac
4117521070a0Smrg
4118521070a0Smrg    # We need to accept at least all the BSD install flags.
4119521070a0Smrg    dest=
4120521070a0Smrg    files=
4121521070a0Smrg    opts=
4122521070a0Smrg    prev=
4123521070a0Smrg    install_type=
4124b0a0317aSmrg    isdir=false
4125521070a0Smrg    stripme=
4126ff63a143Smrg    no_mode=:
4127521070a0Smrg    for arg
4128521070a0Smrg    do
4129ff63a143Smrg      arg2=
4130521070a0Smrg      if test -n "$dest"; then
41313e6c936aSmrg	func_append files " $dest"
4132521070a0Smrg	dest=$arg
4133521070a0Smrg	continue
4134521070a0Smrg      fi
4135521070a0Smrg
4136521070a0Smrg      case $arg in
4137b0a0317aSmrg      -d) isdir=: ;;
4138521070a0Smrg      -f)
4139ff63a143Smrg	if $install_cp; then :; else
4140ff63a143Smrg	  prev=$arg
4141ff63a143Smrg	fi
4142521070a0Smrg	;;
4143521070a0Smrg      -g | -m | -o)
4144521070a0Smrg	prev=$arg
4145521070a0Smrg	;;
4146521070a0Smrg      -s)
4147521070a0Smrg	stripme=" -s"
4148521070a0Smrg	continue
4149521070a0Smrg	;;
4150521070a0Smrg      -*)
4151521070a0Smrg	;;
4152521070a0Smrg      *)
4153521070a0Smrg	# If the previous option needed an argument, then skip it.
4154521070a0Smrg	if test -n "$prev"; then
4155b0a0317aSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4156ff63a143Smrg	    arg2=$install_override_mode
4157ff63a143Smrg	    no_mode=false
4158ff63a143Smrg	  fi
41594456fccdSmrg	  prev=
41604456fccdSmrg	else
4161521070a0Smrg	  dest=$arg
4162521070a0Smrg	  continue
41634456fccdSmrg	fi
41644456fccdSmrg	;;
4165521070a0Smrg      esac
41664456fccdSmrg
4167521070a0Smrg      # Aesthetically quote the argument.
4168521070a0Smrg      func_quote_for_eval "$arg"
41693e6c936aSmrg      func_append install_prog " $func_quote_for_eval_result"
4170ff63a143Smrg      if test -n "$arg2"; then
4171ff63a143Smrg	func_quote_for_eval "$arg2"
4172ff63a143Smrg      fi
41733e6c936aSmrg      func_append install_shared_prog " $func_quote_for_eval_result"
4174521070a0Smrg    done
41754456fccdSmrg
4176521070a0Smrg    test -z "$install_prog" && \
4177521070a0Smrg      func_fatal_help "you must specify an install program"
41784456fccdSmrg
4179521070a0Smrg    test -n "$prev" && \
4180b0a0317aSmrg      func_fatal_help "the '$prev' option requires an argument"
41814456fccdSmrg
4182ff63a143Smrg    if test -n "$install_override_mode" && $no_mode; then
4183ff63a143Smrg      if $install_cp; then :; else
4184ff63a143Smrg	func_quote_for_eval "$install_override_mode"
41853e6c936aSmrg	func_append install_shared_prog " -m $func_quote_for_eval_result"
4186ff63a143Smrg      fi
4187ff63a143Smrg    fi
4188ff63a143Smrg
4189521070a0Smrg    if test -z "$files"; then
4190521070a0Smrg      if test -z "$dest"; then
4191521070a0Smrg	func_fatal_help "no file or destination specified"
4192521070a0Smrg      else
4193521070a0Smrg	func_fatal_help "you must specify a destination"
4194521070a0Smrg      fi
41954456fccdSmrg    fi
41964456fccdSmrg
4197521070a0Smrg    # Strip any trailing slash from the destination.
4198521070a0Smrg    func_stripname '' '/' "$dest"
4199521070a0Smrg    dest=$func_stripname_result
42004456fccdSmrg
4201521070a0Smrg    # Check to see that the destination is a directory.
4202b0a0317aSmrg    test -d "$dest" && isdir=:
4203b0a0317aSmrg    if $isdir; then
4204b0a0317aSmrg      destdir=$dest
4205521070a0Smrg      destname=
42064456fccdSmrg    else
4207521070a0Smrg      func_dirname_and_basename "$dest" "" "."
4208b0a0317aSmrg      destdir=$func_dirname_result
4209b0a0317aSmrg      destname=$func_basename_result
42104456fccdSmrg
4211521070a0Smrg      # Not a directory, so check to see that there is only one file specified.
4212521070a0Smrg      set dummy $files; shift
4213521070a0Smrg      test "$#" -gt 1 && \
4214b0a0317aSmrg	func_fatal_help "'$dest' is not a directory"
42154456fccdSmrg    fi
4216521070a0Smrg    case $destdir in
4217521070a0Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
42184456fccdSmrg    *)
4219521070a0Smrg      for file in $files; do
4220521070a0Smrg	case $file in
4221521070a0Smrg	*.lo) ;;
4222521070a0Smrg	*)
4223b0a0317aSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4224521070a0Smrg	  ;;
4225521070a0Smrg	esac
4226521070a0Smrg      done
42274456fccdSmrg      ;;
42284456fccdSmrg    esac
42294456fccdSmrg
4230521070a0Smrg    # This variable tells wrapper scripts just to set variables rather
4231521070a0Smrg    # than running their programs.
4232b0a0317aSmrg    libtool_install_magic=$magic
42334456fccdSmrg
4234521070a0Smrg    staticlibs=
4235521070a0Smrg    future_libdirs=
4236521070a0Smrg    current_libdirs=
4237521070a0Smrg    for file in $files; do
42384456fccdSmrg
4239521070a0Smrg      # Do each installation.
4240521070a0Smrg      case $file in
4241521070a0Smrg      *.$libext)
4242521070a0Smrg	# Do the static libraries later.
42433e6c936aSmrg	func_append staticlibs " $file"
4244521070a0Smrg	;;
4245521070a0Smrg
4246521070a0Smrg      *.la)
42473e6c936aSmrg	func_resolve_sysroot "$file"
42483e6c936aSmrg	file=$func_resolve_sysroot_result
42493e6c936aSmrg
4250521070a0Smrg	# Check to see that this really is a libtool archive.
4251521070a0Smrg	func_lalib_unsafe_p "$file" \
4252b0a0317aSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4253521070a0Smrg
4254521070a0Smrg	library_names=
4255521070a0Smrg	old_library=
4256521070a0Smrg	relink_command=
4257521070a0Smrg	func_source "$file"
4258521070a0Smrg
4259521070a0Smrg	# Add the libdir to current_libdirs if it is the destination.
4260521070a0Smrg	if test "X$destdir" = "X$libdir"; then
4261521070a0Smrg	  case "$current_libdirs " in
4262521070a0Smrg	  *" $libdir "*) ;;
42633e6c936aSmrg	  *) func_append current_libdirs " $libdir" ;;
42644456fccdSmrg	  esac
4265521070a0Smrg	else
4266521070a0Smrg	  # Note the libdir as a future libdir.
4267521070a0Smrg	  case "$future_libdirs " in
4268521070a0Smrg	  *" $libdir "*) ;;
42693e6c936aSmrg	  *) func_append future_libdirs " $libdir" ;;
4270521070a0Smrg	  esac
4271521070a0Smrg	fi
42724456fccdSmrg
4273521070a0Smrg	func_dirname "$file" "/" ""
4274b0a0317aSmrg	dir=$func_dirname_result
42753e6c936aSmrg	func_append dir "$objdir"
4276521070a0Smrg
4277521070a0Smrg	if test -n "$relink_command"; then
4278521070a0Smrg	  # Determine the prefix the user has applied to our future dir.
4279ff63a143Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4280521070a0Smrg
4281521070a0Smrg	  # Don't allow the user to place us outside of our expected
4282521070a0Smrg	  # location b/c this prevents finding dependent libraries that
4283521070a0Smrg	  # are installed to the same prefix.
4284521070a0Smrg	  # At present, this check doesn't affect windows .dll's that
4285521070a0Smrg	  # are installed into $libdir/../bin (currently, that works fine)
4286521070a0Smrg	  # but it's something to keep an eye on.
4287521070a0Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4288b0a0317aSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4289521070a0Smrg
4290521070a0Smrg	  if test -n "$inst_prefix_dir"; then
4291521070a0Smrg	    # Stick the inst_prefix_dir data into the link command.
4292ff63a143Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4293521070a0Smrg	  else
4294ff63a143Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4295521070a0Smrg	  fi
4296521070a0Smrg
4297b0a0317aSmrg	  func_warning "relinking '$file'"
4298521070a0Smrg	  func_show_eval "$relink_command" \
4299b0a0317aSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4300521070a0Smrg	fi
4301521070a0Smrg
4302521070a0Smrg	# See the names of the shared library.
4303521070a0Smrg	set dummy $library_names; shift
4304521070a0Smrg	if test -n "$1"; then
4305b0a0317aSmrg	  realname=$1
4306521070a0Smrg	  shift
4307521070a0Smrg
4308b0a0317aSmrg	  srcname=$realname
4309b0a0317aSmrg	  test -n "$relink_command" && srcname=${realname}T
4310521070a0Smrg
4311521070a0Smrg	  # Install the shared library and build the symlinks.
4312ff63a143Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4313521070a0Smrg	      'exit $?'
4314b0a0317aSmrg	  tstripme=$stripme
4315521070a0Smrg	  case $host_os in
4316521070a0Smrg	  cygwin* | mingw* | pw32* | cegcc*)
4317521070a0Smrg	    case $realname in
4318521070a0Smrg	    *.dll.a)
4319b0a0317aSmrg	      tstripme=
4320b0a0317aSmrg	      ;;
4321b0a0317aSmrg	    esac
4322b0a0317aSmrg	    ;;
4323b0a0317aSmrg	  os2*)
4324b0a0317aSmrg	    case $realname in
4325b0a0317aSmrg	    *_dll.a)
4326b0a0317aSmrg	      tstripme=
4327521070a0Smrg	      ;;
4328521070a0Smrg	    esac
43294456fccdSmrg	    ;;
43304456fccdSmrg	  esac
4331521070a0Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
4332521070a0Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
43334456fccdSmrg	  fi
4334521070a0Smrg
4335521070a0Smrg	  if test "$#" -gt 0; then
4336521070a0Smrg	    # Delete the old symlinks, and create new ones.
4337b0a0317aSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4338521070a0Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4339521070a0Smrg	    # so we also need to try rm && ln -s.
4340521070a0Smrg	    for linkname
4341521070a0Smrg	    do
4342521070a0Smrg	      test "$linkname" != "$realname" \
4343521070a0Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
43444456fccdSmrg	    done
43454456fccdSmrg	  fi
43464456fccdSmrg
4347521070a0Smrg	  # Do each command in the postinstall commands.
4348b0a0317aSmrg	  lib=$destdir/$realname
4349521070a0Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
43504456fccdSmrg	fi
43514456fccdSmrg
4352521070a0Smrg	# Install the pseudo-library for information purposes.
4353521070a0Smrg	func_basename "$file"
4354b0a0317aSmrg	name=$func_basename_result
4355b0a0317aSmrg	instname=$dir/${name}i
4356521070a0Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
43574456fccdSmrg
4358521070a0Smrg	# Maybe install the static library, too.
43593e6c936aSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4360521070a0Smrg	;;
43614456fccdSmrg
4362521070a0Smrg      *.lo)
4363521070a0Smrg	# Install (i.e. copy) a libtool object.
43644456fccdSmrg
4365521070a0Smrg	# Figure out destination file name, if it wasn't already specified.
4366521070a0Smrg	if test -n "$destname"; then
4367b0a0317aSmrg	  destfile=$destdir/$destname
4368521070a0Smrg	else
4369521070a0Smrg	  func_basename "$file"
4370b0a0317aSmrg	  destfile=$func_basename_result
4371b0a0317aSmrg	  destfile=$destdir/$destfile
43724456fccdSmrg	fi
43734456fccdSmrg
4374521070a0Smrg	# Deduce the name of the destination old-style object file.
4375521070a0Smrg	case $destfile in
4376521070a0Smrg	*.lo)
4377521070a0Smrg	  func_lo2o "$destfile"
4378521070a0Smrg	  staticdest=$func_lo2o_result
4379521070a0Smrg	  ;;
4380521070a0Smrg	*.$objext)
4381b0a0317aSmrg	  staticdest=$destfile
4382521070a0Smrg	  destfile=
4383521070a0Smrg	  ;;
4384521070a0Smrg	*)
4385b0a0317aSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4386521070a0Smrg	  ;;
4387521070a0Smrg	esac
43884456fccdSmrg
4389521070a0Smrg	# Install the libtool object if requested.
4390521070a0Smrg	test -n "$destfile" && \
4391521070a0Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
43924456fccdSmrg
4393521070a0Smrg	# Install the old object if enabled.
4394b0a0317aSmrg	if test yes = "$build_old_libs"; then
4395521070a0Smrg	  # Deduce the name of the old-style object file.
4396521070a0Smrg	  func_lo2o "$file"
4397521070a0Smrg	  staticobj=$func_lo2o_result
4398521070a0Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
43994456fccdSmrg	fi
4400521070a0Smrg	exit $EXIT_SUCCESS
4401521070a0Smrg	;;
44024456fccdSmrg
4403521070a0Smrg      *)
4404521070a0Smrg	# Figure out destination file name, if it wasn't already specified.
4405521070a0Smrg	if test -n "$destname"; then
4406b0a0317aSmrg	  destfile=$destdir/$destname
4407521070a0Smrg	else
4408521070a0Smrg	  func_basename "$file"
4409b0a0317aSmrg	  destfile=$func_basename_result
4410b0a0317aSmrg	  destfile=$destdir/$destfile
4411521070a0Smrg	fi
44124456fccdSmrg
4413521070a0Smrg	# If the file is missing, and there is a .exe on the end, strip it
4414521070a0Smrg	# because it is most likely a libtool script we actually want to
4415521070a0Smrg	# install
4416b0a0317aSmrg	stripped_ext=
4417521070a0Smrg	case $file in
4418521070a0Smrg	  *.exe)
4419521070a0Smrg	    if test ! -f "$file"; then
4420521070a0Smrg	      func_stripname '' '.exe' "$file"
4421521070a0Smrg	      file=$func_stripname_result
4422b0a0317aSmrg	      stripped_ext=.exe
4423521070a0Smrg	    fi
4424521070a0Smrg	    ;;
4425521070a0Smrg	esac
4426521070a0Smrg
4427521070a0Smrg	# Do a test to see if this is really a libtool program.
4428521070a0Smrg	case $host in
4429521070a0Smrg	*cygwin* | *mingw*)
4430521070a0Smrg	    if func_ltwrapper_executable_p "$file"; then
4431521070a0Smrg	      func_ltwrapper_scriptname "$file"
4432521070a0Smrg	      wrapper=$func_ltwrapper_scriptname_result
4433521070a0Smrg	    else
4434521070a0Smrg	      func_stripname '' '.exe' "$file"
4435521070a0Smrg	      wrapper=$func_stripname_result
4436521070a0Smrg	    fi
4437521070a0Smrg	    ;;
44384456fccdSmrg	*)
4439521070a0Smrg	    wrapper=$file
4440521070a0Smrg	    ;;
4441521070a0Smrg	esac
4442521070a0Smrg	if func_ltwrapper_script_p "$wrapper"; then
4443521070a0Smrg	  notinst_deplibs=
4444521070a0Smrg	  relink_command=
4445521070a0Smrg
4446521070a0Smrg	  func_source "$wrapper"
4447521070a0Smrg
4448521070a0Smrg	  # Check the variables that should have been set.
4449521070a0Smrg	  test -z "$generated_by_libtool_version" && \
4450b0a0317aSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4451521070a0Smrg
4452b0a0317aSmrg	  finalize=:
4453521070a0Smrg	  for lib in $notinst_deplibs; do
4454521070a0Smrg	    # Check to see that each library is installed.
4455521070a0Smrg	    libdir=
4456521070a0Smrg	    if test -f "$lib"; then
4457521070a0Smrg	      func_source "$lib"
4458521070a0Smrg	    fi
4459b0a0317aSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4460521070a0Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4461b0a0317aSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
4462b0a0317aSmrg	      finalize=false
4463521070a0Smrg	    fi
4464521070a0Smrg	  done
4465521070a0Smrg
4466521070a0Smrg	  relink_command=
4467521070a0Smrg	  func_source "$wrapper"
4468521070a0Smrg
4469521070a0Smrg	  outputname=
4470b0a0317aSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4471521070a0Smrg	    $opt_dry_run || {
4472b0a0317aSmrg	      if $finalize; then
4473521070a0Smrg	        tmpdir=`func_mktempdir`
4474521070a0Smrg		func_basename "$file$stripped_ext"
4475b0a0317aSmrg		file=$func_basename_result
4476b0a0317aSmrg	        outputname=$tmpdir/$file
4477521070a0Smrg	        # Replace the output file specification.
4478ff63a143Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4479521070a0Smrg
4480b0a0317aSmrg	        $opt_quiet || {
4481521070a0Smrg	          func_quote_for_expand "$relink_command"
4482521070a0Smrg		  eval "func_echo $func_quote_for_expand_result"
4483521070a0Smrg	        }
4484521070a0Smrg	        if eval "$relink_command"; then :
4485521070a0Smrg	          else
4486b0a0317aSmrg		  func_error "error: relink '$file' with the above command before installing it"
4487521070a0Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
4488521070a0Smrg		  continue
4489521070a0Smrg	        fi
4490b0a0317aSmrg	        file=$outputname
4491521070a0Smrg	      else
4492b0a0317aSmrg	        func_warning "cannot relink '$file'"
4493521070a0Smrg	      fi
4494521070a0Smrg	    }
4495521070a0Smrg	  else
4496521070a0Smrg	    # Install the binary that we compiled earlier.
4497ff63a143Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
44984456fccdSmrg	  fi
4499521070a0Smrg	fi
4500521070a0Smrg
4501521070a0Smrg	# remove .exe since cygwin /usr/bin/install will append another
4502521070a0Smrg	# one anyway
4503521070a0Smrg	case $install_prog,$host in
4504521070a0Smrg	*/usr/bin/install*,*cygwin*)
4505521070a0Smrg	  case $file:$destfile in
4506521070a0Smrg	  *.exe:*.exe)
4507521070a0Smrg	    # this is ok
4508521070a0Smrg	    ;;
4509521070a0Smrg	  *.exe:*)
4510521070a0Smrg	    destfile=$destfile.exe
4511521070a0Smrg	    ;;
4512521070a0Smrg	  *:*.exe)
4513521070a0Smrg	    func_stripname '' '.exe' "$destfile"
4514521070a0Smrg	    destfile=$func_stripname_result
4515521070a0Smrg	    ;;
4516521070a0Smrg	  esac
45174456fccdSmrg	  ;;
45184456fccdSmrg	esac
4519521070a0Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4520521070a0Smrg	$opt_dry_run || if test -n "$outputname"; then
4521521070a0Smrg	  ${RM}r "$tmpdir"
4522521070a0Smrg	fi
4523521070a0Smrg	;;
4524521070a0Smrg      esac
4525521070a0Smrg    done
45264456fccdSmrg
4527521070a0Smrg    for file in $staticlibs; do
4528521070a0Smrg      func_basename "$file"
4529b0a0317aSmrg      name=$func_basename_result
4530521070a0Smrg
4531521070a0Smrg      # Set up the ranlib parameters.
4532b0a0317aSmrg      oldlib=$destdir/$name
45333e6c936aSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
45343e6c936aSmrg      tool_oldlib=$func_to_tool_file_result
4535521070a0Smrg
4536521070a0Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4537521070a0Smrg
4538521070a0Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
45393e6c936aSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4540521070a0Smrg      fi
4541521070a0Smrg
4542521070a0Smrg      # Do each command in the postinstall commands.
4543521070a0Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4544521070a0Smrg    done
4545521070a0Smrg
4546521070a0Smrg    test -n "$future_libdirs" && \
4547b0a0317aSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4548521070a0Smrg
4549521070a0Smrg    if test -n "$current_libdirs"; then
4550521070a0Smrg      # Maybe just do a dry run.
4551521070a0Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4552b0a0317aSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4553521070a0Smrg    else
4554521070a0Smrg      exit $EXIT_SUCCESS
4555521070a0Smrg    fi
4556521070a0Smrg}
4557521070a0Smrg
4558b0a0317aSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4559521070a0Smrg
4560521070a0Smrg
4561521070a0Smrg# func_generate_dlsyms outputname originator pic_p
4562521070a0Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4563521070a0Smrg# a dlpreopen symbol table.
4564521070a0Smrgfunc_generate_dlsyms ()
4565521070a0Smrg{
4566b0a0317aSmrg    $debug_cmd
4567b0a0317aSmrg
4568b0a0317aSmrg    my_outputname=$1
4569b0a0317aSmrg    my_originator=$2
4570b0a0317aSmrg    my_pic_p=${3-false}
4571b0a0317aSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4572521070a0Smrg    my_dlsyms=
4573521070a0Smrg
4574b0a0317aSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4575521070a0Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4576b0a0317aSmrg	my_dlsyms=${my_outputname}S.c
4577521070a0Smrg      else
4578521070a0Smrg	func_error "not configured to extract global symbols from dlpreopened files"
4579521070a0Smrg      fi
4580521070a0Smrg    fi
4581521070a0Smrg
4582521070a0Smrg    if test -n "$my_dlsyms"; then
4583521070a0Smrg      case $my_dlsyms in
4584521070a0Smrg      "") ;;
4585521070a0Smrg      *.c)
4586521070a0Smrg	# Discover the nlist of each of the dlfiles.
4587b0a0317aSmrg	nlist=$output_objdir/$my_outputname.nm
4588521070a0Smrg
4589521070a0Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4590521070a0Smrg
4591521070a0Smrg	# Parse the name list into a source file.
4592521070a0Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
4593521070a0Smrg
4594521070a0Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4595b0a0317aSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4596b0a0317aSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4597521070a0Smrg
4598521070a0Smrg#ifdef __cplusplus
4599521070a0Smrgextern \"C\" {
4600521070a0Smrg#endif
4601521070a0Smrg
4602b0a0317aSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4603ff63a143Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4604ff63a143Smrg#endif
4605ff63a143Smrg
46063e6c936aSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4607b0a0317aSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4608b0a0317aSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
46093e6c936aSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
46103e6c936aSmrg# define LT_DLSYM_CONST
4611b0a0317aSmrg#elif defined __osf__
46123e6c936aSmrg/* This system does not cope well with relocations in const data.  */
46133e6c936aSmrg# define LT_DLSYM_CONST
46143e6c936aSmrg#else
46153e6c936aSmrg# define LT_DLSYM_CONST const
46163e6c936aSmrg#endif
46173e6c936aSmrg
4618b0a0317aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4619b0a0317aSmrg
4620521070a0Smrg/* External symbol declarations for the compiler. */\
4621521070a0Smrg"
4622521070a0Smrg
4623b0a0317aSmrg	if test yes = "$dlself"; then
4624b0a0317aSmrg	  func_verbose "generating symbol list for '$output'"
4625521070a0Smrg
4626521070a0Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4627521070a0Smrg
4628521070a0Smrg	  # Add our own program objects to the symbol list.
4629ff63a143Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4630521070a0Smrg	  for progfile in $progfiles; do
46313e6c936aSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4632b0a0317aSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
46333e6c936aSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4634521070a0Smrg	  done
4635521070a0Smrg
4636521070a0Smrg	  if test -n "$exclude_expsyms"; then
4637521070a0Smrg	    $opt_dry_run || {
4638521070a0Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4639521070a0Smrg	      eval '$MV "$nlist"T "$nlist"'
4640521070a0Smrg	    }
46414456fccdSmrg	  fi
4642521070a0Smrg
4643521070a0Smrg	  if test -n "$export_symbols_regex"; then
4644521070a0Smrg	    $opt_dry_run || {
4645521070a0Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4646521070a0Smrg	      eval '$MV "$nlist"T "$nlist"'
4647521070a0Smrg	    }
4648521070a0Smrg	  fi
4649521070a0Smrg
4650521070a0Smrg	  # Prepare the list of exported symbols
4651521070a0Smrg	  if test -z "$export_symbols"; then
4652b0a0317aSmrg	    export_symbols=$output_objdir/$outputname.exp
4653521070a0Smrg	    $opt_dry_run || {
4654521070a0Smrg	      $RM $export_symbols
4655b0a0317aSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4656521070a0Smrg	      case $host in
4657521070a0Smrg	      *cygwin* | *mingw* | *cegcc* )
4658521070a0Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4659521070a0Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4660521070a0Smrg	        ;;
4661521070a0Smrg	      esac
4662521070a0Smrg	    }
46634456fccdSmrg	  else
4664521070a0Smrg	    $opt_dry_run || {
4665b0a0317aSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4666521070a0Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4667521070a0Smrg	      eval '$MV "$nlist"T "$nlist"'
4668521070a0Smrg	      case $host in
4669ff63a143Smrg	        *cygwin* | *mingw* | *cegcc* )
4670521070a0Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4671521070a0Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4672521070a0Smrg	          ;;
4673521070a0Smrg	      esac
4674521070a0Smrg	    }
46754456fccdSmrg	  fi
4676521070a0Smrg	fi
46774456fccdSmrg
4678521070a0Smrg	for dlprefile in $dlprefiles; do
4679b0a0317aSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4680521070a0Smrg	  func_basename "$dlprefile"
4681b0a0317aSmrg	  name=$func_basename_result
46823e6c936aSmrg          case $host in
46833e6c936aSmrg	    *cygwin* | *mingw* | *cegcc* )
46843e6c936aSmrg	      # if an import library, we need to obtain dlname
46853e6c936aSmrg	      if func_win32_import_lib_p "$dlprefile"; then
46863e6c936aSmrg	        func_tr_sh "$dlprefile"
46873e6c936aSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4688b0a0317aSmrg	        dlprefile_dlbasename=
46893e6c936aSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
46903e6c936aSmrg	          # Use subshell, to avoid clobbering current variable values
46913e6c936aSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4692b0a0317aSmrg	          if test -n "$dlprefile_dlname"; then
46933e6c936aSmrg	            func_basename "$dlprefile_dlname"
4694b0a0317aSmrg	            dlprefile_dlbasename=$func_basename_result
46953e6c936aSmrg	          else
46963e6c936aSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
46973e6c936aSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
46983e6c936aSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
46993e6c936aSmrg	          fi
47003e6c936aSmrg	        fi
47013e6c936aSmrg	        $opt_dry_run || {
4702b0a0317aSmrg	          if test -n "$dlprefile_dlbasename"; then
47033e6c936aSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
47043e6c936aSmrg	          else
47053e6c936aSmrg	            func_warning "Could not compute DLL name from $name"
47063e6c936aSmrg	            eval '$ECHO ": $name " >> "$nlist"'
47073e6c936aSmrg	          fi
47083e6c936aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47093e6c936aSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
47103e6c936aSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
47113e6c936aSmrg	        }
47123e6c936aSmrg	      else # not an import lib
47133e6c936aSmrg	        $opt_dry_run || {
47143e6c936aSmrg	          eval '$ECHO ": $name " >> "$nlist"'
47153e6c936aSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47163e6c936aSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
47173e6c936aSmrg	        }
47183e6c936aSmrg	      fi
47193e6c936aSmrg	    ;;
47203e6c936aSmrg	    *)
47213e6c936aSmrg	      $opt_dry_run || {
47223e6c936aSmrg	        eval '$ECHO ": $name " >> "$nlist"'
47233e6c936aSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47243e6c936aSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
47253e6c936aSmrg	      }
47263e6c936aSmrg	    ;;
47273e6c936aSmrg          esac
4728521070a0Smrg	done
4729521070a0Smrg
4730521070a0Smrg	$opt_dry_run || {
4731521070a0Smrg	  # Make sure we have at least an empty file.
4732521070a0Smrg	  test -f "$nlist" || : > "$nlist"
4733521070a0Smrg
4734521070a0Smrg	  if test -n "$exclude_expsyms"; then
4735521070a0Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4736521070a0Smrg	    $MV "$nlist"T "$nlist"
47374456fccdSmrg	  fi
4738521070a0Smrg
4739521070a0Smrg	  # Try sorting and uniquifying the output.
4740521070a0Smrg	  if $GREP -v "^: " < "$nlist" |
4741521070a0Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4742521070a0Smrg		sort -k 3
4743521070a0Smrg	      else
4744521070a0Smrg		sort +2
4745521070a0Smrg	      fi |
4746521070a0Smrg	      uniq > "$nlist"S; then
4747521070a0Smrg	    :
47484456fccdSmrg	  else
4749521070a0Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
47504456fccdSmrg	  fi
47514456fccdSmrg
4752521070a0Smrg	  if test -f "$nlist"S; then
4753521070a0Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
47544456fccdSmrg	  else
4755ff63a143Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
47564456fccdSmrg	  fi
47574456fccdSmrg
4758b0a0317aSmrg	  func_show_eval '$RM "${nlist}I"'
4759b0a0317aSmrg	  if test -n "$global_symbol_to_import"; then
4760b0a0317aSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
4761b0a0317aSmrg	  fi
4762b0a0317aSmrg
4763ff63a143Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
47644456fccdSmrg
4765521070a0Smrg/* The mapping between symbol names and symbols.  */
4766521070a0Smrgtypedef struct {
4767521070a0Smrg  const char *name;
4768521070a0Smrg  void *address;
4769521070a0Smrg} lt_dlsymlist;
47703e6c936aSmrgextern LT_DLSYM_CONST lt_dlsymlist
4771b0a0317aSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
4772b0a0317aSmrg"
4773b0a0317aSmrg
4774b0a0317aSmrg	  if test -s "$nlist"I; then
4775b0a0317aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
4776b0a0317aSmrgstatic void lt_syminit(void)
4777b0a0317aSmrg{
4778b0a0317aSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
4779b0a0317aSmrg  for (; symbol->name; ++symbol)
4780b0a0317aSmrg    {"
4781b0a0317aSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
4782b0a0317aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
4783b0a0317aSmrg    }
4784b0a0317aSmrg}"
4785b0a0317aSmrg	  fi
4786b0a0317aSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
47873e6c936aSmrgLT_DLSYM_CONST lt_dlsymlist
4788521070a0Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
4789b0a0317aSmrg{ {\"$my_originator\", (void *) 0},"
4790b0a0317aSmrg
4791b0a0317aSmrg	  if test -s "$nlist"I; then
4792b0a0317aSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
4793b0a0317aSmrg  {\"@INIT@\", (void *) &lt_syminit},"
4794b0a0317aSmrg	  fi
47954456fccdSmrg
4796521070a0Smrg	  case $need_lib_prefix in
4797521070a0Smrg	  no)
4798521070a0Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
4799521070a0Smrg	    ;;
4800521070a0Smrg	  *)
4801521070a0Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
4802521070a0Smrg	    ;;
4803521070a0Smrg	  esac
4804ff63a143Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
4805521070a0Smrg  {0, (void *) 0}
4806521070a0Smrg};
48074456fccdSmrg
4808521070a0Smrg/* This works around a problem in FreeBSD linker */
4809521070a0Smrg#ifdef FREEBSD_WORKAROUND
4810521070a0Smrgstatic const void *lt_preloaded_setup() {
4811521070a0Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
4812521070a0Smrg}
4813521070a0Smrg#endif
4814521070a0Smrg
4815521070a0Smrg#ifdef __cplusplus
4816521070a0Smrg}
4817521070a0Smrg#endif\
4818521070a0Smrg"
4819521070a0Smrg	} # !$opt_dry_run
4820521070a0Smrg
4821521070a0Smrg	pic_flag_for_symtable=
4822521070a0Smrg	case "$compile_command " in
4823521070a0Smrg	*" -static "*) ;;
4824521070a0Smrg	*)
4825521070a0Smrg	  case $host in
4826521070a0Smrg	  # compiling the symbol table file with pic_flag works around
4827521070a0Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
4828521070a0Smrg	  # linked before any other PIC object.  But we must not use
4829521070a0Smrg	  # pic_flag when linking with -static.  The problem exists in
4830521070a0Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
48313e6c936aSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
4832521070a0Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
4833521070a0Smrg	  *-*-hpux*)
4834521070a0Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
4835521070a0Smrg	  *)
4836b0a0317aSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
4837521070a0Smrg	    ;;
4838521070a0Smrg	  esac
4839521070a0Smrg	  ;;
4840521070a0Smrg	esac
4841521070a0Smrg	symtab_cflags=
4842521070a0Smrg	for arg in $LTCFLAGS; do
4843521070a0Smrg	  case $arg in
4844521070a0Smrg	  -pie | -fpie | -fPIE) ;;
48453e6c936aSmrg	  *) func_append symtab_cflags " $arg" ;;
4846521070a0Smrg	  esac
4847521070a0Smrg	done
48484456fccdSmrg
4849521070a0Smrg	# Now compile the dynamic symbol file.
4850521070a0Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
48514456fccdSmrg
4852521070a0Smrg	# Clean up the generated files.
4853b0a0317aSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
48544456fccdSmrg
4855521070a0Smrg	# Transform the symbol file into the correct name.
4856b0a0317aSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
4857521070a0Smrg	case $host in
4858521070a0Smrg	*cygwin* | *mingw* | *cegcc* )
4859521070a0Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
4860ff63a143Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
4861ff63a143Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
4862521070a0Smrg	  else
4863ff63a143Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4864ff63a143Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
48654456fccdSmrg	  fi
4866521070a0Smrg	  ;;
4867521070a0Smrg	*)
4868ff63a143Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4869ff63a143Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4870521070a0Smrg	  ;;
4871521070a0Smrg	esac
4872521070a0Smrg	;;
4873521070a0Smrg      *)
4874b0a0317aSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
4875521070a0Smrg	;;
4876521070a0Smrg      esac
4877521070a0Smrg    else
4878521070a0Smrg      # We keep going just in case the user didn't refer to
4879521070a0Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
4880521070a0Smrg      # really was required.
48814456fccdSmrg
4882521070a0Smrg      # Nullify the symbol file.
4883ff63a143Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
4884ff63a143Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
4885521070a0Smrg    fi
4886521070a0Smrg}
48874456fccdSmrg
4888b0a0317aSmrg# func_cygming_gnu_implib_p ARG
4889b0a0317aSmrg# This predicate returns with zero status (TRUE) if
4890b0a0317aSmrg# ARG is a GNU/binutils-style import library. Returns
4891b0a0317aSmrg# with nonzero status (FALSE) otherwise.
4892b0a0317aSmrgfunc_cygming_gnu_implib_p ()
4893b0a0317aSmrg{
4894b0a0317aSmrg  $debug_cmd
4895b0a0317aSmrg
4896b0a0317aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4897b0a0317aSmrg  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)$'`
4898b0a0317aSmrg  test -n "$func_cygming_gnu_implib_tmp"
4899b0a0317aSmrg}
4900b0a0317aSmrg
4901b0a0317aSmrg# func_cygming_ms_implib_p ARG
4902b0a0317aSmrg# This predicate returns with zero status (TRUE) if
4903b0a0317aSmrg# ARG is an MS-style import library. Returns
4904b0a0317aSmrg# with nonzero status (FALSE) otherwise.
4905b0a0317aSmrgfunc_cygming_ms_implib_p ()
4906b0a0317aSmrg{
4907b0a0317aSmrg  $debug_cmd
4908b0a0317aSmrg
4909b0a0317aSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4910b0a0317aSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
4911b0a0317aSmrg  test -n "$func_cygming_ms_implib_tmp"
4912b0a0317aSmrg}
4913b0a0317aSmrg
4914521070a0Smrg# func_win32_libid arg
4915521070a0Smrg# return the library type of file 'arg'
4916521070a0Smrg#
4917521070a0Smrg# Need a lot of goo to handle *both* DLLs and import libs
4918521070a0Smrg# Has to be a shell function in order to 'eat' the argument
4919521070a0Smrg# that is supplied when $file_magic_command is called.
4920ff63a143Smrg# Despite the name, also deal with 64 bit binaries.
4921521070a0Smrgfunc_win32_libid ()
4922521070a0Smrg{
4923b0a0317aSmrg  $debug_cmd
4924b0a0317aSmrg
4925b0a0317aSmrg  win32_libid_type=unknown
4926521070a0Smrg  win32_fileres=`file -L $1 2>/dev/null`
4927521070a0Smrg  case $win32_fileres in
4928521070a0Smrg  *ar\ archive\ import\ library*) # definitely import
4929521070a0Smrg    win32_libid_type="x86 archive import"
4930521070a0Smrg    ;;
4931521070a0Smrg  *ar\ archive*) # could be an import, or static
4932ff63a143Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
4933521070a0Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
4934ff63a143Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
4935b0a0317aSmrg      case $nm_interface in
4936b0a0317aSmrg      "MS dumpbin")
4937b0a0317aSmrg	if func_cygming_ms_implib_p "$1" ||
4938b0a0317aSmrg	   func_cygming_gnu_implib_p "$1"
4939b0a0317aSmrg	then
4940b0a0317aSmrg	  win32_nmres=import
4941b0a0317aSmrg	else
4942b0a0317aSmrg	  win32_nmres=
4943b0a0317aSmrg	fi
4944b0a0317aSmrg	;;
4945b0a0317aSmrg      *)
4946b0a0317aSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
4947b0a0317aSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
4948b0a0317aSmrg	  $SED -n -e '
4949521070a0Smrg	    1,100{
4950521070a0Smrg		/ I /{
4951b0a0317aSmrg		    s|.*|import|
4952521070a0Smrg		    p
4953521070a0Smrg		    q
4954521070a0Smrg		}
4955521070a0Smrg	    }'`
4956b0a0317aSmrg	;;
4957b0a0317aSmrg      esac
4958521070a0Smrg      case $win32_nmres in
4959521070a0Smrg      import*)  win32_libid_type="x86 archive import";;
4960521070a0Smrg      *)        win32_libid_type="x86 archive static";;
4961521070a0Smrg      esac
4962521070a0Smrg    fi
4963521070a0Smrg    ;;
4964521070a0Smrg  *DLL*)
4965521070a0Smrg    win32_libid_type="x86 DLL"
4966521070a0Smrg    ;;
4967521070a0Smrg  *executable*) # but shell scripts are "executable" too...
4968521070a0Smrg    case $win32_fileres in
4969521070a0Smrg    *MS\ Windows\ PE\ Intel*)
4970521070a0Smrg      win32_libid_type="x86 DLL"
4971521070a0Smrg      ;;
4972521070a0Smrg    esac
4973521070a0Smrg    ;;
4974521070a0Smrg  esac
4975521070a0Smrg  $ECHO "$win32_libid_type"
4976521070a0Smrg}
49774456fccdSmrg
49783e6c936aSmrg# func_cygming_dll_for_implib ARG
49793e6c936aSmrg#
49803e6c936aSmrg# Platform-specific function to extract the
49813e6c936aSmrg# name of the DLL associated with the specified
49823e6c936aSmrg# import library ARG.
49833e6c936aSmrg# Invoked by eval'ing the libtool variable
49843e6c936aSmrg#    $sharedlib_from_linklib_cmd
49853e6c936aSmrg# Result is available in the variable
49863e6c936aSmrg#    $sharedlib_from_linklib_result
49873e6c936aSmrgfunc_cygming_dll_for_implib ()
49883e6c936aSmrg{
4989b0a0317aSmrg  $debug_cmd
4990b0a0317aSmrg
49913e6c936aSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
49923e6c936aSmrg}
49933e6c936aSmrg
49943e6c936aSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
49953e6c936aSmrg#
49963e6c936aSmrg# The is the core of a fallback implementation of a
49973e6c936aSmrg# platform-specific function to extract the name of the
49983e6c936aSmrg# DLL associated with the specified import library LIBNAME.
49993e6c936aSmrg#
50003e6c936aSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
50013e6c936aSmrg# on the platform and compiler that created the implib.
50023e6c936aSmrg#
50033e6c936aSmrg# Echos the name of the DLL associated with the
50043e6c936aSmrg# specified import library.
50053e6c936aSmrgfunc_cygming_dll_for_implib_fallback_core ()
50063e6c936aSmrg{
5007b0a0317aSmrg  $debug_cmd
5008b0a0317aSmrg
50093e6c936aSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
50103e6c936aSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
50113e6c936aSmrg    $SED '/^Contents of section '"$match_literal"':/{
50123e6c936aSmrg      # Place marker at beginning of archive member dllname section
50133e6c936aSmrg      s/.*/====MARK====/
50143e6c936aSmrg      p
50153e6c936aSmrg      d
50163e6c936aSmrg    }
50173e6c936aSmrg    # These lines can sometimes be longer than 43 characters, but
50183e6c936aSmrg    # are always uninteresting
50193e6c936aSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
50203e6c936aSmrg    /^In archive [^:]*:/d
50213e6c936aSmrg    # Ensure marker is printed
50223e6c936aSmrg    /^====MARK====/p
50233e6c936aSmrg    # Remove all lines with less than 43 characters
50243e6c936aSmrg    /^.\{43\}/!d
50253e6c936aSmrg    # From remaining lines, remove first 43 characters
50263e6c936aSmrg    s/^.\{43\}//' |
50273e6c936aSmrg    $SED -n '
50283e6c936aSmrg      # Join marker and all lines until next marker into a single line
50293e6c936aSmrg      /^====MARK====/ b para
50303e6c936aSmrg      H
50313e6c936aSmrg      $ b para
50323e6c936aSmrg      b
50333e6c936aSmrg      :para
50343e6c936aSmrg      x
50353e6c936aSmrg      s/\n//g
50363e6c936aSmrg      # Remove the marker
50373e6c936aSmrg      s/^====MARK====//
50383e6c936aSmrg      # Remove trailing dots and whitespace
50393e6c936aSmrg      s/[\. \t]*$//
50403e6c936aSmrg      # Print
50413e6c936aSmrg      /./p' |
50423e6c936aSmrg    # we now have a list, one entry per line, of the stringified
50433e6c936aSmrg    # contents of the appropriate section of all members of the
5044b0a0317aSmrg    # archive that possess that section. Heuristic: eliminate
5045b0a0317aSmrg    # all those that have a first or second character that is
50463e6c936aSmrg    # a '.' (that is, objdump's representation of an unprintable
50473e6c936aSmrg    # character.) This should work for all archives with less than
50483e6c936aSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
50493e6c936aSmrg    # begins with a literal '.' or a single character followed by
50503e6c936aSmrg    # a '.'.
50513e6c936aSmrg    #
50523e6c936aSmrg    # Of those that remain, print the first one.
50533e6c936aSmrg    $SED -e '/^\./d;/^.\./d;q'
50543e6c936aSmrg}
50553e6c936aSmrg
50563e6c936aSmrg# func_cygming_dll_for_implib_fallback ARG
50573e6c936aSmrg# Platform-specific function to extract the
50583e6c936aSmrg# name of the DLL associated with the specified
50593e6c936aSmrg# import library ARG.
50603e6c936aSmrg#
50613e6c936aSmrg# This fallback implementation is for use when $DLLTOOL
50623e6c936aSmrg# does not support the --identify-strict option.
50633e6c936aSmrg# Invoked by eval'ing the libtool variable
50643e6c936aSmrg#    $sharedlib_from_linklib_cmd
50653e6c936aSmrg# Result is available in the variable
50663e6c936aSmrg#    $sharedlib_from_linklib_result
50673e6c936aSmrgfunc_cygming_dll_for_implib_fallback ()
50683e6c936aSmrg{
5069b0a0317aSmrg  $debug_cmd
5070b0a0317aSmrg
5071b0a0317aSmrg  if func_cygming_gnu_implib_p "$1"; then
50723e6c936aSmrg    # binutils import library
50733e6c936aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5074b0a0317aSmrg  elif func_cygming_ms_implib_p "$1"; then
50753e6c936aSmrg    # ms-generated import library
50763e6c936aSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
50773e6c936aSmrg  else
50783e6c936aSmrg    # unknown
5079b0a0317aSmrg    sharedlib_from_linklib_result=
50803e6c936aSmrg  fi
50813e6c936aSmrg}
50824456fccdSmrg
50834456fccdSmrg
5084521070a0Smrg# func_extract_an_archive dir oldlib
5085521070a0Smrgfunc_extract_an_archive ()
5086521070a0Smrg{
5087b0a0317aSmrg    $debug_cmd
5088b0a0317aSmrg
5089b0a0317aSmrg    f_ex_an_ar_dir=$1; shift
5090b0a0317aSmrg    f_ex_an_ar_oldlib=$1
5091b0a0317aSmrg    if test yes = "$lock_old_archive_extraction"; then
5092ff63a143Smrg      lockfile=$f_ex_an_ar_oldlib.lock
5093ff63a143Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5094ff63a143Smrg	func_echo "Waiting for $lockfile to be removed"
5095ff63a143Smrg	sleep 2
5096ff63a143Smrg      done
5097ff63a143Smrg    fi
5098ff63a143Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5099ff63a143Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5100b0a0317aSmrg    if test yes = "$lock_old_archive_extraction"; then
5101ff63a143Smrg      $opt_dry_run || rm -f "$lockfile"
5102ff63a143Smrg    fi
5103521070a0Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5104521070a0Smrg     :
5105521070a0Smrg    else
5106521070a0Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5107521070a0Smrg    fi
5108521070a0Smrg}
51094456fccdSmrg
51104456fccdSmrg
5111521070a0Smrg# func_extract_archives gentop oldlib ...
5112521070a0Smrgfunc_extract_archives ()
5113521070a0Smrg{
5114b0a0317aSmrg    $debug_cmd
5115b0a0317aSmrg
5116b0a0317aSmrg    my_gentop=$1; shift
5117521070a0Smrg    my_oldlibs=${1+"$@"}
5118b0a0317aSmrg    my_oldobjs=
5119b0a0317aSmrg    my_xlib=
5120b0a0317aSmrg    my_xabs=
5121b0a0317aSmrg    my_xdir=
51224456fccdSmrg
5123521070a0Smrg    for my_xlib in $my_oldlibs; do
5124521070a0Smrg      # Extract the objects.
5125521070a0Smrg      case $my_xlib in
5126b0a0317aSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5127521070a0Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5128521070a0Smrg      esac
5129521070a0Smrg      func_basename "$my_xlib"
5130b0a0317aSmrg      my_xlib=$func_basename_result
5131521070a0Smrg      my_xlib_u=$my_xlib
5132521070a0Smrg      while :; do
5133521070a0Smrg        case " $extracted_archives " in
5134521070a0Smrg	*" $my_xlib_u "*)
5135521070a0Smrg	  func_arith $extracted_serial + 1
5136521070a0Smrg	  extracted_serial=$func_arith_result
5137521070a0Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5138521070a0Smrg	*) break ;;
5139521070a0Smrg	esac
5140521070a0Smrg      done
5141521070a0Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5142b0a0317aSmrg      my_xdir=$my_gentop/$my_xlib_u
51434456fccdSmrg
5144521070a0Smrg      func_mkdir_p "$my_xdir"
51454456fccdSmrg
5146521070a0Smrg      case $host in
5147521070a0Smrg      *-darwin*)
5148521070a0Smrg	func_verbose "Extracting $my_xabs"
5149521070a0Smrg	# Do not bother doing anything if just a dry run
5150521070a0Smrg	$opt_dry_run || {
5151521070a0Smrg	  darwin_orig_dir=`pwd`
5152521070a0Smrg	  cd $my_xdir || exit $?
5153521070a0Smrg	  darwin_archive=$my_xabs
5154521070a0Smrg	  darwin_curdir=`pwd`
5155b0a0317aSmrg	  func_basename "$darwin_archive"
5156b0a0317aSmrg	  darwin_base_archive=$func_basename_result
5157521070a0Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5158521070a0Smrg	  if test -n "$darwin_arches"; then
5159521070a0Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5160521070a0Smrg	    darwin_arch=
5161521070a0Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5162b0a0317aSmrg	    for darwin_arch in  $darwin_arches; do
5163b0a0317aSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5164b0a0317aSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5165b0a0317aSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5166b0a0317aSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5167521070a0Smrg	      cd "$darwin_curdir"
5168b0a0317aSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5169521070a0Smrg	    done # $darwin_arches
5170521070a0Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5171b0a0317aSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5172521070a0Smrg	    darwin_file=
5173521070a0Smrg	    darwin_files=
5174521070a0Smrg	    for darwin_file in $darwin_filelist; do
5175ff63a143Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5176521070a0Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
5177521070a0Smrg	    done # $darwin_filelist
5178521070a0Smrg	    $RM -rf unfat-$$
5179521070a0Smrg	    cd "$darwin_orig_dir"
51804456fccdSmrg	  else
5181521070a0Smrg	    cd $darwin_orig_dir
5182521070a0Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5183521070a0Smrg	  fi # $darwin_arches
5184521070a0Smrg	} # !$opt_dry_run
5185521070a0Smrg	;;
5186521070a0Smrg      *)
5187521070a0Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5188521070a0Smrg	;;
5189521070a0Smrg      esac
5190ff63a143Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5191521070a0Smrg    done
51924456fccdSmrg
5193b0a0317aSmrg    func_extract_archives_result=$my_oldobjs
5194521070a0Smrg}
51954456fccdSmrg
51964456fccdSmrg
5197ff63a143Smrg# func_emit_wrapper [arg=no]
5198ff63a143Smrg#
5199ff63a143Smrg# Emit a libtool wrapper script on stdout.
5200ff63a143Smrg# Don't directly open a file because we may want to
5201ff63a143Smrg# incorporate the script contents within a cygwin/mingw
5202ff63a143Smrg# wrapper executable.  Must ONLY be called from within
5203ff63a143Smrg# func_mode_link because it depends on a number of variables
5204ff63a143Smrg# set therein.
5205521070a0Smrg#
5206ff63a143Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5207ff63a143Smrg# variable will take.  If 'yes', then the emitted script
5208b0a0317aSmrg# will assume that the directory where it is stored is
5209ff63a143Smrg# the $objdir directory.  This is a cygwin/mingw-specific
5210ff63a143Smrg# behavior.
5211ff63a143Smrgfunc_emit_wrapper ()
5212521070a0Smrg{
5213ff63a143Smrg	func_emit_wrapper_arg1=${1-no}
52144456fccdSmrg
5215521070a0Smrg	$ECHO "\
5216521070a0Smrg#! $SHELL
52174456fccdSmrg
5218521070a0Smrg# $output - temporary wrapper script for $objdir/$outputname
5219b0a0317aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5220521070a0Smrg#
5221521070a0Smrg# The $output program cannot be directly executed until all the libtool
5222521070a0Smrg# libraries that it depends on are installed.
5223521070a0Smrg#
5224521070a0Smrg# This wrapper script should never be moved out of the build directory.
5225521070a0Smrg# If it is, it will not operate correctly.
52264456fccdSmrg
5227521070a0Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
5228521070a0Smrg# metacharacters that are still active within double-quoted strings.
5229521070a0Smrgsed_quote_subst='$sed_quote_subst'
52304456fccdSmrg
5231521070a0Smrg# Be Bourne compatible
5232521070a0Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5233521070a0Smrg  emulate sh
5234521070a0Smrg  NULLCMD=:
5235521070a0Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5236521070a0Smrg  # is contrary to our usage.  Disable this feature.
5237521070a0Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5238521070a0Smrg  setopt NO_GLOB_SUBST
5239521070a0Smrgelse
5240521070a0Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5241521070a0Smrgfi
5242521070a0SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5243521070a0SmrgDUALCASE=1; export DUALCASE # for MKS sh
52444456fccdSmrg
5245521070a0Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5246521070a0Smrg# if CDPATH is set.
5247521070a0Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
52484456fccdSmrg
5249521070a0Smrgrelink_command=\"$relink_command\"
52504456fccdSmrg
5251521070a0Smrg# This environment variable determines our operation mode.
5252521070a0Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5253521070a0Smrg  # install mode needs the following variables:
5254521070a0Smrg  generated_by_libtool_version='$macro_version'
5255521070a0Smrg  notinst_deplibs='$notinst_deplibs'
5256521070a0Smrgelse
5257521070a0Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5258521070a0Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5259ff63a143Smrg    file=\"\$0\""
5260ff63a143Smrg
5261ff63a143Smrg    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
5262ff63a143Smrg    $ECHO "\
5263ff63a143Smrg
5264ff63a143Smrg# A function that is used when there is no print builtin or printf.
5265ff63a143Smrgfunc_fallback_echo ()
5266ff63a143Smrg{
5267ff63a143Smrg  eval 'cat <<_LTECHO_EOF
5268ff63a143Smrg\$1
5269ff63a143Smrg_LTECHO_EOF'
5270ff63a143Smrg}
5271ff63a143Smrg    ECHO=\"$qECHO\"
5272ff63a143Smrg  fi
5273ff63a143Smrg
5274ff63a143Smrg# Very basic option parsing. These options are (a) specific to
5275ff63a143Smrg# the libtool wrapper, (b) are identical between the wrapper
5276b0a0317aSmrg# /script/ and the wrapper /executable/ that is used only on
5277ff63a143Smrg# windows platforms, and (c) all begin with the string "--lt-"
5278b0a0317aSmrg# (application programs are unlikely to have options that match
5279ff63a143Smrg# this pattern).
5280ff63a143Smrg#
5281ff63a143Smrg# There are only two supported options: --lt-debug and
5282ff63a143Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
5283ff63a143Smrg#
5284ff63a143Smrg# The first argument to this parsing function should be the
5285ff63a143Smrg# script's $0 value, followed by "$@".
5286ff63a143Smrglt_option_debug=
5287ff63a143Smrgfunc_parse_lt_options ()
5288ff63a143Smrg{
5289ff63a143Smrg  lt_script_arg0=\$0
5290ff63a143Smrg  shift
5291ff63a143Smrg  for lt_opt
5292ff63a143Smrg  do
5293ff63a143Smrg    case \"\$lt_opt\" in
5294ff63a143Smrg    --lt-debug) lt_option_debug=1 ;;
5295ff63a143Smrg    --lt-dump-script)
5296ff63a143Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5297ff63a143Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5298ff63a143Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5299ff63a143Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5300ff63a143Smrg        exit 0
5301ff63a143Smrg      ;;
5302ff63a143Smrg    --lt-*)
5303ff63a143Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5304ff63a143Smrg        exit 1
5305ff63a143Smrg      ;;
5306ff63a143Smrg    esac
5307ff63a143Smrg  done
5308ff63a143Smrg
5309ff63a143Smrg  # Print the debug banner immediately:
5310ff63a143Smrg  if test -n \"\$lt_option_debug\"; then
5311b0a0317aSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5312ff63a143Smrg  fi
5313ff63a143Smrg}
5314ff63a143Smrg
5315ff63a143Smrg# Used when --lt-debug. Prints its arguments to stdout
5316ff63a143Smrg# (redirection is the responsibility of the caller)
5317ff63a143Smrgfunc_lt_dump_args ()
5318ff63a143Smrg{
5319ff63a143Smrg  lt_dump_args_N=1;
5320ff63a143Smrg  for lt_arg
5321ff63a143Smrg  do
5322b0a0317aSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5323ff63a143Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5324ff63a143Smrg  done
5325ff63a143Smrg}
5326ff63a143Smrg
5327ff63a143Smrg# Core function for launching the target application
5328ff63a143Smrgfunc_exec_program_core ()
5329ff63a143Smrg{
5330521070a0Smrg"
5331ff63a143Smrg  case $host in
5332ff63a143Smrg  # Backslashes separate directories on plain windows
5333ff63a143Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
5334ff63a143Smrg    $ECHO "\
5335ff63a143Smrg      if test -n \"\$lt_option_debug\"; then
5336b0a0317aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5337ff63a143Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5338ff63a143Smrg      fi
5339ff63a143Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5340ff63a143Smrg"
5341ff63a143Smrg    ;;
5342ff63a143Smrg
5343ff63a143Smrg  *)
5344ff63a143Smrg    $ECHO "\
5345ff63a143Smrg      if test -n \"\$lt_option_debug\"; then
5346b0a0317aSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5347ff63a143Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5348ff63a143Smrg      fi
5349ff63a143Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5350ff63a143Smrg"
5351ff63a143Smrg    ;;
5352ff63a143Smrg  esac
5353ff63a143Smrg  $ECHO "\
5354ff63a143Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5355ff63a143Smrg      exit 1
5356ff63a143Smrg}
5357ff63a143Smrg
5358ff63a143Smrg# A function to encapsulate launching the target application
5359ff63a143Smrg# Strips options in the --lt-* namespace from \$@ and
5360ff63a143Smrg# launches target application with the remaining arguments.
5361ff63a143Smrgfunc_exec_program ()
5362ff63a143Smrg{
53633e6c936aSmrg  case \" \$* \" in
53643e6c936aSmrg  *\\ --lt-*)
53653e6c936aSmrg    for lt_wr_arg
53663e6c936aSmrg    do
53673e6c936aSmrg      case \$lt_wr_arg in
53683e6c936aSmrg      --lt-*) ;;
53693e6c936aSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
53703e6c936aSmrg      esac
53713e6c936aSmrg      shift
53723e6c936aSmrg    done ;;
53733e6c936aSmrg  esac
5374ff63a143Smrg  func_exec_program_core \${1+\"\$@\"}
5375ff63a143Smrg}
5376ff63a143Smrg
5377ff63a143Smrg  # Parse options
5378ff63a143Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
53794456fccdSmrg
5380521070a0Smrg  # Find the directory that this script lives in.
5381ff63a143Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5382521070a0Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
53834456fccdSmrg
5384521070a0Smrg  # Follow symbolic links until we get to the real thisdir.
5385ff63a143Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5386521070a0Smrg  while test -n \"\$file\"; do
5387ff63a143Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
53884456fccdSmrg
5389521070a0Smrg    # If there was a directory component, then change thisdir.
5390521070a0Smrg    if test \"x\$destdir\" != \"x\$file\"; then
5391521070a0Smrg      case \"\$destdir\" in
5392521070a0Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5393521070a0Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
53944456fccdSmrg      esac
5395521070a0Smrg    fi
53964456fccdSmrg
5397ff63a143Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5398ff63a143Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5399521070a0Smrg  done
54004456fccdSmrg
5401521070a0Smrg  # Usually 'no', except on cygwin/mingw when embedded into
5402521070a0Smrg  # the cwrapper.
5403ff63a143Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5404521070a0Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5405521070a0Smrg    # special case for '.'
5406521070a0Smrg    if test \"\$thisdir\" = \".\"; then
5407521070a0Smrg      thisdir=\`pwd\`
5408521070a0Smrg    fi
5409521070a0Smrg    # remove .libs from thisdir
5410521070a0Smrg    case \"\$thisdir\" in
5411ff63a143Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5412521070a0Smrg    $objdir )   thisdir=. ;;
5413521070a0Smrg    esac
5414521070a0Smrg  fi
5415521070a0Smrg
5416521070a0Smrg  # Try to get the absolute directory name.
5417521070a0Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
5418521070a0Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5419521070a0Smrg"
5420521070a0Smrg
5421b0a0317aSmrg	if test yes = "$fast_install"; then
5422521070a0Smrg	  $ECHO "\
5423521070a0Smrg  program=lt-'$outputname'$exeext
5424521070a0Smrg  progdir=\"\$thisdir/$objdir\"
5425521070a0Smrg
5426521070a0Smrg  if test ! -f \"\$progdir/\$program\" ||
5427b0a0317aSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5428521070a0Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5429521070a0Smrg
5430521070a0Smrg    file=\"\$\$-\$program\"
5431521070a0Smrg
5432521070a0Smrg    if test ! -d \"\$progdir\"; then
5433521070a0Smrg      $MKDIR \"\$progdir\"
5434521070a0Smrg    else
5435521070a0Smrg      $RM \"\$progdir/\$file\"
5436521070a0Smrg    fi"
5437521070a0Smrg
5438521070a0Smrg	  $ECHO "\
5439521070a0Smrg
5440521070a0Smrg    # relink executable if necessary
5441521070a0Smrg    if test -n \"\$relink_command\"; then
5442521070a0Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5443521070a0Smrg      else
5444b0a0317aSmrg	\$ECHO \"\$relink_command_output\" >&2
5445521070a0Smrg	$RM \"\$progdir/\$file\"
5446521070a0Smrg	exit 1
54474456fccdSmrg      fi
5448521070a0Smrg    fi
54494456fccdSmrg
5450521070a0Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5451521070a0Smrg    { $RM \"\$progdir/\$program\";
5452521070a0Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5453521070a0Smrg    $RM \"\$progdir/\$file\"
5454521070a0Smrg  fi"
5455521070a0Smrg	else
5456521070a0Smrg	  $ECHO "\
5457521070a0Smrg  program='$outputname'
5458521070a0Smrg  progdir=\"\$thisdir/$objdir\"
5459521070a0Smrg"
54604456fccdSmrg	fi
54614456fccdSmrg
5462521070a0Smrg	$ECHO "\
54634456fccdSmrg
5464521070a0Smrg  if test -f \"\$progdir/\$program\"; then"
54654456fccdSmrg
54663e6c936aSmrg	# fixup the dll searchpath if we need to.
54673e6c936aSmrg	#
54683e6c936aSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
54693e6c936aSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
54703e6c936aSmrg	# libraries must come first.
54713e6c936aSmrg	if test -n "$dllsearchpath"; then
54723e6c936aSmrg	  $ECHO "\
54733e6c936aSmrg    # Add the dll search path components to the executable PATH
54743e6c936aSmrg    PATH=$dllsearchpath:\$PATH
54753e6c936aSmrg"
54763e6c936aSmrg	fi
54773e6c936aSmrg
5478521070a0Smrg	# Export our shlibpath_var if we have one.
5479b0a0317aSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5480521070a0Smrg	  $ECHO "\
5481521070a0Smrg    # Add our own library path to $shlibpath_var
5482521070a0Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5483521070a0Smrg
5484521070a0Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5485521070a0Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5486ff63a143Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
54874456fccdSmrg
5488521070a0Smrg    export $shlibpath_var
5489521070a0Smrg"
54904456fccdSmrg	fi
54914456fccdSmrg
5492521070a0Smrg	$ECHO "\
5493521070a0Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5494521070a0Smrg      # Run the actual program with our arguments.
5495ff63a143Smrg      func_exec_program \${1+\"\$@\"}
5496521070a0Smrg    fi
5497521070a0Smrg  else
5498521070a0Smrg    # The program doesn't exist.
5499b0a0317aSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5500521070a0Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5501ff63a143Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5502521070a0Smrg    exit 1
5503521070a0Smrg  fi
5504521070a0Smrgfi\
5505521070a0Smrg"
5506521070a0Smrg}
55074456fccdSmrg
55084456fccdSmrg
5509521070a0Smrg# func_emit_cwrapperexe_src
5510521070a0Smrg# emit the source code for a wrapper executable on stdout
5511521070a0Smrg# Must ONLY be called from within func_mode_link because
5512521070a0Smrg# it depends on a number of variable set therein.
5513521070a0Smrgfunc_emit_cwrapperexe_src ()
5514521070a0Smrg{
5515521070a0Smrg	cat <<EOF
55164456fccdSmrg
5517521070a0Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5518b0a0317aSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
55194456fccdSmrg
5520521070a0Smrg   The $output program cannot be directly executed until all the libtool
5521521070a0Smrg   libraries that it depends on are installed.
55224456fccdSmrg
5523521070a0Smrg   This wrapper executable should never be moved out of the build directory.
5524521070a0Smrg   If it is, it will not operate correctly.
5525521070a0Smrg*/
5526521070a0SmrgEOF
5527521070a0Smrg	    cat <<"EOF"
5528ff63a143Smrg#ifdef _MSC_VER
5529ff63a143Smrg# define _CRT_SECURE_NO_DEPRECATE 1
5530ff63a143Smrg#endif
5531521070a0Smrg#include <stdio.h>
5532521070a0Smrg#include <stdlib.h>
5533521070a0Smrg#ifdef _MSC_VER
5534521070a0Smrg# include <direct.h>
5535521070a0Smrg# include <process.h>
5536521070a0Smrg# include <io.h>
5537521070a0Smrg#else
5538521070a0Smrg# include <unistd.h>
5539521070a0Smrg# include <stdint.h>
5540521070a0Smrg# ifdef __CYGWIN__
5541521070a0Smrg#  include <io.h>
5542521070a0Smrg# endif
5543521070a0Smrg#endif
5544521070a0Smrg#include <malloc.h>
5545521070a0Smrg#include <stdarg.h>
5546521070a0Smrg#include <assert.h>
5547521070a0Smrg#include <string.h>
5548521070a0Smrg#include <ctype.h>
5549521070a0Smrg#include <errno.h>
5550521070a0Smrg#include <fcntl.h>
5551521070a0Smrg#include <sys/stat.h>
55524456fccdSmrg
5553b0a0317aSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5554b0a0317aSmrg
5555ff63a143Smrg/* declarations of non-ANSI functions */
5556b0a0317aSmrg#if defined __MINGW32__
5557ff63a143Smrg# ifdef __STRICT_ANSI__
5558ff63a143Smrgint _putenv (const char *);
5559ff63a143Smrg# endif
5560b0a0317aSmrg#elif defined __CYGWIN__
5561ff63a143Smrg# ifdef __STRICT_ANSI__
5562ff63a143Smrgchar *realpath (const char *, char *);
5563ff63a143Smrgint putenv (char *);
5564ff63a143Smrgint setenv (const char *, const char *, int);
5565ff63a143Smrg# endif
5566b0a0317aSmrg/* #elif defined other_platform || defined ... */
5567ff63a143Smrg#endif
5568ff63a143Smrg
5569ff63a143Smrg/* portability defines, excluding path handling macros */
5570b0a0317aSmrg#if defined _MSC_VER
5571ff63a143Smrg# define setmode _setmode
5572ff63a143Smrg# define stat    _stat
5573ff63a143Smrg# define chmod   _chmod
5574ff63a143Smrg# define getcwd  _getcwd
5575ff63a143Smrg# define putenv  _putenv
5576ff63a143Smrg# define S_IXUSR _S_IEXEC
5577b0a0317aSmrg#elif defined __MINGW32__
5578ff63a143Smrg# define setmode _setmode
5579ff63a143Smrg# define stat    _stat
5580ff63a143Smrg# define chmod   _chmod
5581ff63a143Smrg# define getcwd  _getcwd
5582ff63a143Smrg# define putenv  _putenv
5583b0a0317aSmrg#elif defined __CYGWIN__
5584ff63a143Smrg# define HAVE_SETENV
5585ff63a143Smrg# define FOPEN_WB "wb"
5586b0a0317aSmrg/* #elif defined other platforms ... */
5587ff63a143Smrg#endif
5588ff63a143Smrg
5589b0a0317aSmrg#if defined PATH_MAX
5590521070a0Smrg# define LT_PATHMAX PATH_MAX
5591b0a0317aSmrg#elif defined MAXPATHLEN
5592521070a0Smrg# define LT_PATHMAX MAXPATHLEN
5593521070a0Smrg#else
5594521070a0Smrg# define LT_PATHMAX 1024
5595521070a0Smrg#endif
55964456fccdSmrg
5597521070a0Smrg#ifndef S_IXOTH
5598521070a0Smrg# define S_IXOTH 0
5599521070a0Smrg#endif
5600521070a0Smrg#ifndef S_IXGRP
5601521070a0Smrg# define S_IXGRP 0
5602521070a0Smrg#endif
56034456fccdSmrg
5604ff63a143Smrg/* path handling portability macros */
5605521070a0Smrg#ifndef DIR_SEPARATOR
5606521070a0Smrg# define DIR_SEPARATOR '/'
5607521070a0Smrg# define PATH_SEPARATOR ':'
5608521070a0Smrg#endif
56094456fccdSmrg
5610b0a0317aSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5611b0a0317aSmrg  defined __OS2__
5612521070a0Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
5613521070a0Smrg# define FOPEN_WB "wb"
5614521070a0Smrg# ifndef DIR_SEPARATOR_2
5615521070a0Smrg#  define DIR_SEPARATOR_2 '\\'
5616521070a0Smrg# endif
5617521070a0Smrg# ifndef PATH_SEPARATOR_2
5618521070a0Smrg#  define PATH_SEPARATOR_2 ';'
5619521070a0Smrg# endif
5620521070a0Smrg#endif
56214456fccdSmrg
5622521070a0Smrg#ifndef DIR_SEPARATOR_2
5623521070a0Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5624521070a0Smrg#else /* DIR_SEPARATOR_2 */
5625521070a0Smrg# define IS_DIR_SEPARATOR(ch) \
5626521070a0Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5627521070a0Smrg#endif /* DIR_SEPARATOR_2 */
56284456fccdSmrg
5629521070a0Smrg#ifndef PATH_SEPARATOR_2
5630521070a0Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5631521070a0Smrg#else /* PATH_SEPARATOR_2 */
5632521070a0Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5633521070a0Smrg#endif /* PATH_SEPARATOR_2 */
56344456fccdSmrg
5635521070a0Smrg#ifndef FOPEN_WB
5636521070a0Smrg# define FOPEN_WB "w"
5637521070a0Smrg#endif
5638521070a0Smrg#ifndef _O_BINARY
5639521070a0Smrg# define _O_BINARY 0
5640521070a0Smrg#endif
56414456fccdSmrg
5642521070a0Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5643521070a0Smrg#define XFREE(stale) do { \
5644b0a0317aSmrg  if (stale) { free (stale); stale = 0; } \
5645521070a0Smrg} while (0)
56464456fccdSmrg
5647b0a0317aSmrg#if defined LT_DEBUGWRAPPER
5648ff63a143Smrgstatic int lt_debug = 1;
5649521070a0Smrg#else
5650ff63a143Smrgstatic int lt_debug = 0;
5651521070a0Smrg#endif
56524456fccdSmrg
5653ff63a143Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
56544456fccdSmrg
5655521070a0Smrgvoid *xmalloc (size_t num);
5656521070a0Smrgchar *xstrdup (const char *string);
5657521070a0Smrgconst char *base_name (const char *name);
5658521070a0Smrgchar *find_executable (const char *wrapper);
5659521070a0Smrgchar *chase_symlinks (const char *pathspec);
5660521070a0Smrgint make_executable (const char *path);
5661521070a0Smrgint check_executable (const char *path);
5662521070a0Smrgchar *strendzap (char *str, const char *pat);
5663ff63a143Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5664ff63a143Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5665ff63a143Smrgstatic const char *nonnull (const char *s);
5666ff63a143Smrgstatic const char *nonempty (const char *s);
5667521070a0Smrgvoid lt_setenv (const char *name, const char *value);
5668521070a0Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5669521070a0Smrgvoid lt_update_exe_path (const char *name, const char *value);
5670521070a0Smrgvoid lt_update_lib_path (const char *name, const char *value);
5671ff63a143Smrgchar **prepare_spawn (char **argv);
5672ff63a143Smrgvoid lt_dump_script (FILE *f);
5673521070a0SmrgEOF
5674521070a0Smrg
5675521070a0Smrg	    cat <<EOF
5676b0a0317aSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5677b0a0317aSmrg# define externally_visible volatile
5678b0a0317aSmrg#else
5679b0a0317aSmrg# define externally_visible __attribute__((externally_visible)) volatile
5680b0a0317aSmrg#endif
5681b0a0317aSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5682521070a0Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5683521070a0SmrgEOF
56844456fccdSmrg
5685b0a0317aSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
56863e6c936aSmrg              func_to_host_path "$temp_rpath"
5687521070a0Smrg	      cat <<EOF
56883e6c936aSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5689521070a0SmrgEOF
5690521070a0Smrg	    else
5691521070a0Smrg	      cat <<"EOF"
5692521070a0Smrgconst char * LIB_PATH_VALUE   = "";
5693521070a0SmrgEOF
56944456fccdSmrg	    fi
56954456fccdSmrg
5696521070a0Smrg	    if test -n "$dllsearchpath"; then
56973e6c936aSmrg              func_to_host_path "$dllsearchpath:"
5698521070a0Smrg	      cat <<EOF
5699521070a0Smrgconst char * EXE_PATH_VARNAME = "PATH";
57003e6c936aSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
57014456fccdSmrgEOF
57024456fccdSmrg	    else
5703521070a0Smrg	      cat <<"EOF"
5704521070a0Smrgconst char * EXE_PATH_VARNAME = "";
5705521070a0Smrgconst char * EXE_PATH_VALUE   = "";
5706521070a0SmrgEOF
57074456fccdSmrg	    fi
5708521070a0Smrg
5709b0a0317aSmrg	    if test yes = "$fast_install"; then
5710521070a0Smrg	      cat <<EOF
5711521070a0Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5712521070a0SmrgEOF
57134456fccdSmrg	    else
5714521070a0Smrg	      cat <<EOF
5715521070a0Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5716521070a0SmrgEOF
57174456fccdSmrg	    fi
57184456fccdSmrg
57194456fccdSmrg
5720521070a0Smrg	    cat <<"EOF"
57214456fccdSmrg
5722521070a0Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
57234456fccdSmrg
5724521070a0Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5725521070a0Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5726ff63a143Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
57274456fccdSmrg
5728521070a0Smrgint
5729521070a0Smrgmain (int argc, char *argv[])
5730521070a0Smrg{
5731521070a0Smrg  char **newargz;
5732521070a0Smrg  int  newargc;
5733521070a0Smrg  char *tmp_pathspec;
5734521070a0Smrg  char *actual_cwrapper_path;
5735521070a0Smrg  char *actual_cwrapper_name;
5736521070a0Smrg  char *target_name;
5737521070a0Smrg  char *lt_argv_zero;
5738b0a0317aSmrg  int rval = 127;
57394456fccdSmrg
5740521070a0Smrg  int i;
57414456fccdSmrg
5742521070a0Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
5743b0a0317aSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
57444456fccdSmrg
5745ff63a143Smrg  /* very simple arg parsing; don't want to rely on getopt
5746ff63a143Smrg   * also, copy all non cwrapper options to newargz, except
5747ff63a143Smrg   * argz[0], which is handled differently
5748ff63a143Smrg   */
5749ff63a143Smrg  newargc=0;
5750521070a0Smrg  for (i = 1; i < argc; i++)
5751521070a0Smrg    {
5752b0a0317aSmrg      if (STREQ (argv[i], dumpscript_opt))
5753521070a0Smrg	{
5754521070a0SmrgEOF
5755b0a0317aSmrg	    case $host in
5756521070a0Smrg	      *mingw* | *cygwin* )
5757521070a0Smrg		# make stdout use "unix" line endings
5758521070a0Smrg		echo "          setmode(1,_O_BINARY);"
5759521070a0Smrg		;;
5760521070a0Smrg	      esac
57614456fccdSmrg
5762521070a0Smrg	    cat <<"EOF"
5763ff63a143Smrg	  lt_dump_script (stdout);
5764521070a0Smrg	  return 0;
5765521070a0Smrg	}
5766b0a0317aSmrg      if (STREQ (argv[i], debug_opt))
5767ff63a143Smrg	{
5768ff63a143Smrg          lt_debug = 1;
5769ff63a143Smrg          continue;
5770ff63a143Smrg	}
5771b0a0317aSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
5772ff63a143Smrg        {
5773ff63a143Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
5774ff63a143Smrg             namespace, but it is not one of the ones we know about and
5775ff63a143Smrg             have already dealt with, above (inluding dump-script), then
5776ff63a143Smrg             report an error. Otherwise, targets might begin to believe
5777ff63a143Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
5778ff63a143Smrg             namespace. The first time any user complains about this, we'll
5779ff63a143Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
5780ff63a143Smrg             or a configure.ac-settable value.
5781ff63a143Smrg           */
5782ff63a143Smrg          lt_fatal (__FILE__, __LINE__,
5783ff63a143Smrg		    "unrecognized %s option: '%s'",
5784ff63a143Smrg                    ltwrapper_option_prefix, argv[i]);
5785ff63a143Smrg        }
5786ff63a143Smrg      /* otherwise ... */
5787ff63a143Smrg      newargz[++newargc] = xstrdup (argv[i]);
5788521070a0Smrg    }
5789ff63a143Smrg  newargz[++newargc] = NULL;
5790ff63a143Smrg
5791ff63a143SmrgEOF
5792ff63a143Smrg	    cat <<EOF
5793ff63a143Smrg  /* The GNU banner must be the first non-error debug message */
5794b0a0317aSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
5795ff63a143SmrgEOF
5796ff63a143Smrg	    cat <<"EOF"
5797ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
5798ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
57994456fccdSmrg
5800521070a0Smrg  tmp_pathspec = find_executable (argv[0]);
5801521070a0Smrg  if (tmp_pathspec == NULL)
5802ff63a143Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
5803ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__,
5804ff63a143Smrg                  "(main) found exe (before symlink chase) at: %s\n",
5805ff63a143Smrg		  tmp_pathspec);
5806521070a0Smrg
5807521070a0Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
5808ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__,
5809ff63a143Smrg                  "(main) found exe (after symlink chase) at: %s\n",
5810ff63a143Smrg		  actual_cwrapper_path);
5811521070a0Smrg  XFREE (tmp_pathspec);
5812521070a0Smrg
5813ff63a143Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
5814521070a0Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
5815521070a0Smrg
5816521070a0Smrg  /* wrapper name transforms */
5817521070a0Smrg  strendzap (actual_cwrapper_name, ".exe");
5818521070a0Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
5819521070a0Smrg  XFREE (actual_cwrapper_name);
5820521070a0Smrg  actual_cwrapper_name = tmp_pathspec;
5821521070a0Smrg  tmp_pathspec = 0;
5822521070a0Smrg
5823521070a0Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
5824521070a0Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
5825521070a0Smrg  strendzap (target_name, ".exe");
5826521070a0Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
5827521070a0Smrg  XFREE (target_name);
5828521070a0Smrg  target_name = tmp_pathspec;
5829521070a0Smrg  tmp_pathspec = 0;
5830521070a0Smrg
5831ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__,
5832ff63a143Smrg		  "(main) libtool target name: %s\n",
5833ff63a143Smrg		  target_name);
5834521070a0SmrgEOF
58354456fccdSmrg
5836521070a0Smrg	    cat <<EOF
5837521070a0Smrg  newargz[0] =
5838521070a0Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
5839521070a0Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
5840521070a0Smrg  strcpy (newargz[0], actual_cwrapper_path);
5841521070a0Smrg  strcat (newargz[0], "$objdir");
5842521070a0Smrg  strcat (newargz[0], "/");
5843521070a0SmrgEOF
58444456fccdSmrg
5845521070a0Smrg	    cat <<"EOF"
5846521070a0Smrg  /* stop here, and copy so we don't have to do this twice */
5847521070a0Smrg  tmp_pathspec = xstrdup (newargz[0]);
58484456fccdSmrg
5849521070a0Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
5850521070a0Smrg  strcat (newargz[0], actual_cwrapper_name);
58514456fccdSmrg
5852521070a0Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
5853521070a0Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
5854521070a0Smrg  XFREE (tmp_pathspec);
5855521070a0Smrg  tmp_pathspec = NULL;
5856521070a0SmrgEOF
58574456fccdSmrg
5858521070a0Smrg	    case $host_os in
5859521070a0Smrg	      mingw*)
5860521070a0Smrg	    cat <<"EOF"
5861521070a0Smrg  {
5862521070a0Smrg    char* p;
5863521070a0Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
5864521070a0Smrg      {
5865521070a0Smrg	*p = '/';
5866521070a0Smrg      }
5867521070a0Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
5868521070a0Smrg      {
5869521070a0Smrg	*p = '/';
5870521070a0Smrg      }
5871521070a0Smrg  }
5872521070a0SmrgEOF
5873521070a0Smrg	    ;;
5874521070a0Smrg	    esac
58754456fccdSmrg
5876521070a0Smrg	    cat <<"EOF"
5877521070a0Smrg  XFREE (target_name);
5878521070a0Smrg  XFREE (actual_cwrapper_path);
5879521070a0Smrg  XFREE (actual_cwrapper_name);
58804456fccdSmrg
5881521070a0Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
5882521070a0Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
58833e6c936aSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
58843e6c936aSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
58853e6c936aSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
58863e6c936aSmrg     libraries must come first. */
5887521070a0Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
58883e6c936aSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
58894456fccdSmrg
5890ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
5891ff63a143Smrg		  nonnull (lt_argv_zero));
5892521070a0Smrg  for (i = 0; i < newargc; i++)
5893521070a0Smrg    {
5894ff63a143Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
5895ff63a143Smrg		      i, nonnull (newargz[i]));
5896521070a0Smrg    }
58974456fccdSmrg
5898521070a0SmrgEOF
58994456fccdSmrg
5900521070a0Smrg	    case $host_os in
5901521070a0Smrg	      mingw*)
5902521070a0Smrg		cat <<"EOF"
5903521070a0Smrg  /* execv doesn't actually work on mingw as expected on unix */
5904ff63a143Smrg  newargz = prepare_spawn (newargz);
5905b0a0317aSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
5906521070a0Smrg  if (rval == -1)
5907521070a0Smrg    {
5908521070a0Smrg      /* failed to start process */
5909ff63a143Smrg      lt_debugprintf (__FILE__, __LINE__,
5910ff63a143Smrg		      "(main) failed to launch target \"%s\": %s\n",
5911ff63a143Smrg		      lt_argv_zero, nonnull (strerror (errno)));
5912521070a0Smrg      return 127;
5913521070a0Smrg    }
5914521070a0Smrg  return rval;
5915521070a0SmrgEOF
5916521070a0Smrg		;;
5917521070a0Smrg	      *)
5918521070a0Smrg		cat <<"EOF"
5919521070a0Smrg  execv (lt_argv_zero, newargz);
5920521070a0Smrg  return rval; /* =127, but avoids unused variable warning */
5921521070a0SmrgEOF
5922521070a0Smrg		;;
5923521070a0Smrg	    esac
59244456fccdSmrg
5925521070a0Smrg	    cat <<"EOF"
5926521070a0Smrg}
59274456fccdSmrg
5928521070a0Smrgvoid *
5929521070a0Smrgxmalloc (size_t num)
5930521070a0Smrg{
5931521070a0Smrg  void *p = (void *) malloc (num);
5932521070a0Smrg  if (!p)
5933ff63a143Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
59344456fccdSmrg
5935521070a0Smrg  return p;
5936521070a0Smrg}
59374456fccdSmrg
5938521070a0Smrgchar *
5939521070a0Smrgxstrdup (const char *string)
5940521070a0Smrg{
5941521070a0Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
5942521070a0Smrg			  string) : NULL;
5943521070a0Smrg}
59444456fccdSmrg
5945521070a0Smrgconst char *
5946521070a0Smrgbase_name (const char *name)
5947521070a0Smrg{
5948521070a0Smrg  const char *base;
59494456fccdSmrg
5950b0a0317aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
5951521070a0Smrg  /* Skip over the disk name in MSDOS pathnames. */
5952521070a0Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
5953521070a0Smrg    name += 2;
5954521070a0Smrg#endif
59554456fccdSmrg
5956521070a0Smrg  for (base = name; *name; name++)
5957521070a0Smrg    if (IS_DIR_SEPARATOR (*name))
5958521070a0Smrg      base = name + 1;
5959521070a0Smrg  return base;
5960521070a0Smrg}
59614456fccdSmrg
5962521070a0Smrgint
5963521070a0Smrgcheck_executable (const char *path)
5964521070a0Smrg{
5965521070a0Smrg  struct stat st;
59664456fccdSmrg
5967ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
5968ff63a143Smrg                  nonempty (path));
5969521070a0Smrg  if ((!path) || (!*path))
5970521070a0Smrg    return 0;
59714456fccdSmrg
5972521070a0Smrg  if ((stat (path, &st) >= 0)
5973521070a0Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
5974521070a0Smrg    return 1;
5975521070a0Smrg  else
5976521070a0Smrg    return 0;
5977521070a0Smrg}
59784456fccdSmrg
5979521070a0Smrgint
5980521070a0Smrgmake_executable (const char *path)
5981521070a0Smrg{
5982521070a0Smrg  int rval = 0;
5983521070a0Smrg  struct stat st;
59844456fccdSmrg
5985ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
5986ff63a143Smrg                  nonempty (path));
5987521070a0Smrg  if ((!path) || (!*path))
5988521070a0Smrg    return 0;
59894456fccdSmrg
5990521070a0Smrg  if (stat (path, &st) >= 0)
5991521070a0Smrg    {
5992521070a0Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
5993521070a0Smrg    }
5994521070a0Smrg  return rval;
5995521070a0Smrg}
59964456fccdSmrg
5997521070a0Smrg/* Searches for the full path of the wrapper.  Returns
5998521070a0Smrg   newly allocated full path name if found, NULL otherwise
5999521070a0Smrg   Does not chase symlinks, even on platforms that support them.
6000521070a0Smrg*/
6001521070a0Smrgchar *
6002521070a0Smrgfind_executable (const char *wrapper)
6003521070a0Smrg{
6004521070a0Smrg  int has_slash = 0;
6005521070a0Smrg  const char *p;
6006521070a0Smrg  const char *p_next;
6007521070a0Smrg  /* static buffer for getcwd */
6008521070a0Smrg  char tmp[LT_PATHMAX + 1];
6009b0a0317aSmrg  size_t tmp_len;
6010521070a0Smrg  char *concat_name;
60114456fccdSmrg
6012ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6013ff63a143Smrg                  nonempty (wrapper));
60144456fccdSmrg
6015521070a0Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6016521070a0Smrg    return NULL;
60174456fccdSmrg
6018521070a0Smrg  /* Absolute path? */
6019b0a0317aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6020521070a0Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6021521070a0Smrg    {
6022521070a0Smrg      concat_name = xstrdup (wrapper);
6023521070a0Smrg      if (check_executable (concat_name))
6024521070a0Smrg	return concat_name;
6025521070a0Smrg      XFREE (concat_name);
6026521070a0Smrg    }
6027521070a0Smrg  else
6028521070a0Smrg    {
6029521070a0Smrg#endif
6030521070a0Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6031521070a0Smrg	{
6032521070a0Smrg	  concat_name = xstrdup (wrapper);
6033521070a0Smrg	  if (check_executable (concat_name))
6034521070a0Smrg	    return concat_name;
6035521070a0Smrg	  XFREE (concat_name);
6036521070a0Smrg	}
6037b0a0317aSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6038521070a0Smrg    }
6039521070a0Smrg#endif
60404456fccdSmrg
6041521070a0Smrg  for (p = wrapper; *p; p++)
6042521070a0Smrg    if (*p == '/')
6043521070a0Smrg      {
6044521070a0Smrg	has_slash = 1;
6045521070a0Smrg	break;
6046521070a0Smrg      }
6047521070a0Smrg  if (!has_slash)
6048521070a0Smrg    {
6049521070a0Smrg      /* no slashes; search PATH */
6050521070a0Smrg      const char *path = getenv ("PATH");
6051521070a0Smrg      if (path != NULL)
6052521070a0Smrg	{
6053521070a0Smrg	  for (p = path; *p; p = p_next)
6054521070a0Smrg	    {
6055521070a0Smrg	      const char *q;
6056521070a0Smrg	      size_t p_len;
6057521070a0Smrg	      for (q = p; *q; q++)
6058521070a0Smrg		if (IS_PATH_SEPARATOR (*q))
6059521070a0Smrg		  break;
6060b0a0317aSmrg	      p_len = (size_t) (q - p);
6061521070a0Smrg	      p_next = (*q == '\0' ? q : q + 1);
6062521070a0Smrg	      if (p_len == 0)
6063521070a0Smrg		{
6064521070a0Smrg		  /* empty path: current directory */
6065521070a0Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6066ff63a143Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6067ff63a143Smrg                              nonnull (strerror (errno)));
6068521070a0Smrg		  tmp_len = strlen (tmp);
6069521070a0Smrg		  concat_name =
6070521070a0Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6071521070a0Smrg		  memcpy (concat_name, tmp, tmp_len);
6072521070a0Smrg		  concat_name[tmp_len] = '/';
6073521070a0Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6074521070a0Smrg		}
6075521070a0Smrg	      else
6076521070a0Smrg		{
6077521070a0Smrg		  concat_name =
6078521070a0Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6079521070a0Smrg		  memcpy (concat_name, p, p_len);
6080521070a0Smrg		  concat_name[p_len] = '/';
6081521070a0Smrg		  strcpy (concat_name + p_len + 1, wrapper);
6082521070a0Smrg		}
6083521070a0Smrg	      if (check_executable (concat_name))
6084521070a0Smrg		return concat_name;
6085521070a0Smrg	      XFREE (concat_name);
6086521070a0Smrg	    }
6087521070a0Smrg	}
6088521070a0Smrg      /* not found in PATH; assume curdir */
6089521070a0Smrg    }
6090521070a0Smrg  /* Relative path | not found in path: prepend cwd */
6091521070a0Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6092ff63a143Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6093ff63a143Smrg              nonnull (strerror (errno)));
6094521070a0Smrg  tmp_len = strlen (tmp);
6095521070a0Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6096521070a0Smrg  memcpy (concat_name, tmp, tmp_len);
6097521070a0Smrg  concat_name[tmp_len] = '/';
6098521070a0Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
60994456fccdSmrg
6100521070a0Smrg  if (check_executable (concat_name))
6101521070a0Smrg    return concat_name;
6102521070a0Smrg  XFREE (concat_name);
6103521070a0Smrg  return NULL;
6104521070a0Smrg}
61054456fccdSmrg
6106521070a0Smrgchar *
6107521070a0Smrgchase_symlinks (const char *pathspec)
6108521070a0Smrg{
6109521070a0Smrg#ifndef S_ISLNK
6110521070a0Smrg  return xstrdup (pathspec);
6111521070a0Smrg#else
6112521070a0Smrg  char buf[LT_PATHMAX];
6113521070a0Smrg  struct stat s;
6114521070a0Smrg  char *tmp_pathspec = xstrdup (pathspec);
6115521070a0Smrg  char *p;
6116521070a0Smrg  int has_symlinks = 0;
6117521070a0Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
6118521070a0Smrg    {
6119ff63a143Smrg      lt_debugprintf (__FILE__, __LINE__,
6120ff63a143Smrg		      "checking path component for symlinks: %s\n",
6121ff63a143Smrg		      tmp_pathspec);
6122521070a0Smrg      if (lstat (tmp_pathspec, &s) == 0)
6123521070a0Smrg	{
6124521070a0Smrg	  if (S_ISLNK (s.st_mode) != 0)
6125521070a0Smrg	    {
6126521070a0Smrg	      has_symlinks = 1;
6127521070a0Smrg	      break;
6128521070a0Smrg	    }
61294456fccdSmrg
6130521070a0Smrg	  /* search backwards for last DIR_SEPARATOR */
6131521070a0Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6132521070a0Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6133521070a0Smrg	    p--;
6134521070a0Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6135521070a0Smrg	    {
6136521070a0Smrg	      /* no more DIR_SEPARATORS left */
6137521070a0Smrg	      break;
6138521070a0Smrg	    }
6139521070a0Smrg	  *p = '\0';
6140521070a0Smrg	}
6141521070a0Smrg      else
6142521070a0Smrg	{
6143ff63a143Smrg	  lt_fatal (__FILE__, __LINE__,
6144ff63a143Smrg		    "error accessing file \"%s\": %s",
6145ff63a143Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6146521070a0Smrg	}
6147521070a0Smrg    }
6148521070a0Smrg  XFREE (tmp_pathspec);
61494456fccdSmrg
6150521070a0Smrg  if (!has_symlinks)
6151521070a0Smrg    {
6152521070a0Smrg      return xstrdup (pathspec);
6153521070a0Smrg    }
61544456fccdSmrg
6155521070a0Smrg  tmp_pathspec = realpath (pathspec, buf);
6156521070a0Smrg  if (tmp_pathspec == 0)
6157521070a0Smrg    {
6158ff63a143Smrg      lt_fatal (__FILE__, __LINE__,
6159ff63a143Smrg		"could not follow symlinks for %s", pathspec);
6160521070a0Smrg    }
6161521070a0Smrg  return xstrdup (tmp_pathspec);
6162521070a0Smrg#endif
6163521070a0Smrg}
61644456fccdSmrg
6165521070a0Smrgchar *
6166521070a0Smrgstrendzap (char *str, const char *pat)
6167521070a0Smrg{
6168521070a0Smrg  size_t len, patlen;
61694456fccdSmrg
6170521070a0Smrg  assert (str != NULL);
6171521070a0Smrg  assert (pat != NULL);
61724456fccdSmrg
6173521070a0Smrg  len = strlen (str);
6174521070a0Smrg  patlen = strlen (pat);
61754456fccdSmrg
6176521070a0Smrg  if (patlen <= len)
6177521070a0Smrg    {
6178521070a0Smrg      str += len - patlen;
6179b0a0317aSmrg      if (STREQ (str, pat))
6180521070a0Smrg	*str = '\0';
6181521070a0Smrg    }
6182521070a0Smrg  return str;
6183521070a0Smrg}
61844456fccdSmrg
6185ff63a143Smrgvoid
6186ff63a143Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6187ff63a143Smrg{
6188ff63a143Smrg  va_list args;
6189ff63a143Smrg  if (lt_debug)
6190ff63a143Smrg    {
6191ff63a143Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6192ff63a143Smrg      va_start (args, fmt);
6193ff63a143Smrg      (void) vfprintf (stderr, fmt, args);
6194ff63a143Smrg      va_end (args);
6195ff63a143Smrg    }
6196ff63a143Smrg}
6197ff63a143Smrg
6198521070a0Smrgstatic void
6199ff63a143Smrglt_error_core (int exit_status, const char *file,
6200ff63a143Smrg	       int line, const char *mode,
6201521070a0Smrg	       const char *message, va_list ap)
6202521070a0Smrg{
6203ff63a143Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6204521070a0Smrg  vfprintf (stderr, message, ap);
6205521070a0Smrg  fprintf (stderr, ".\n");
62064456fccdSmrg
6207521070a0Smrg  if (exit_status >= 0)
6208521070a0Smrg    exit (exit_status);
6209521070a0Smrg}
62104456fccdSmrg
6211521070a0Smrgvoid
6212ff63a143Smrglt_fatal (const char *file, int line, const char *message, ...)
6213521070a0Smrg{
6214521070a0Smrg  va_list ap;
6215521070a0Smrg  va_start (ap, message);
6216ff63a143Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6217521070a0Smrg  va_end (ap);
6218521070a0Smrg}
62194456fccdSmrg
6220ff63a143Smrgstatic const char *
6221ff63a143Smrgnonnull (const char *s)
6222ff63a143Smrg{
6223ff63a143Smrg  return s ? s : "(null)";
6224ff63a143Smrg}
6225ff63a143Smrg
6226ff63a143Smrgstatic const char *
6227ff63a143Smrgnonempty (const char *s)
6228ff63a143Smrg{
6229ff63a143Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
6230ff63a143Smrg}
6231ff63a143Smrg
6232521070a0Smrgvoid
6233521070a0Smrglt_setenv (const char *name, const char *value)
6234521070a0Smrg{
6235ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__,
6236ff63a143Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
6237ff63a143Smrg                  nonnull (name), nonnull (value));
6238521070a0Smrg  {
6239521070a0Smrg#ifdef HAVE_SETENV
6240521070a0Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
6241521070a0Smrg    char *str = xstrdup (value);
6242521070a0Smrg    setenv (name, str, 1);
6243521070a0Smrg#else
6244b0a0317aSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6245521070a0Smrg    char *str = XMALLOC (char, len);
6246521070a0Smrg    sprintf (str, "%s=%s", name, value);
6247521070a0Smrg    if (putenv (str) != EXIT_SUCCESS)
6248521070a0Smrg      {
6249521070a0Smrg        XFREE (str);
6250521070a0Smrg      }
6251521070a0Smrg#endif
6252521070a0Smrg  }
6253521070a0Smrg}
62544456fccdSmrg
6255521070a0Smrgchar *
6256521070a0Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
6257521070a0Smrg{
6258521070a0Smrg  char *new_value;
6259521070a0Smrg  if (orig_value && *orig_value)
6260521070a0Smrg    {
6261b0a0317aSmrg      size_t orig_value_len = strlen (orig_value);
6262b0a0317aSmrg      size_t add_len = strlen (add);
6263521070a0Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6264521070a0Smrg      if (to_end)
6265521070a0Smrg        {
6266521070a0Smrg          strcpy (new_value, orig_value);
6267521070a0Smrg          strcpy (new_value + orig_value_len, add);
6268521070a0Smrg        }
6269521070a0Smrg      else
6270521070a0Smrg        {
6271521070a0Smrg          strcpy (new_value, add);
6272521070a0Smrg          strcpy (new_value + add_len, orig_value);
6273521070a0Smrg        }
6274521070a0Smrg    }
6275521070a0Smrg  else
6276521070a0Smrg    {
6277521070a0Smrg      new_value = xstrdup (add);
6278521070a0Smrg    }
6279521070a0Smrg  return new_value;
6280521070a0Smrg}
62814456fccdSmrg
6282521070a0Smrgvoid
6283521070a0Smrglt_update_exe_path (const char *name, const char *value)
6284521070a0Smrg{
6285ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__,
6286ff63a143Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6287ff63a143Smrg                  nonnull (name), nonnull (value));
62884456fccdSmrg
6289521070a0Smrg  if (name && *name && value && *value)
6290521070a0Smrg    {
6291521070a0Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6292521070a0Smrg      /* some systems can't cope with a ':'-terminated path #' */
6293b0a0317aSmrg      size_t len = strlen (new_value);
6294b0a0317aSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6295521070a0Smrg        {
6296b0a0317aSmrg          new_value[--len] = '\0';
6297521070a0Smrg        }
6298521070a0Smrg      lt_setenv (name, new_value);
6299521070a0Smrg      XFREE (new_value);
6300521070a0Smrg    }
6301521070a0Smrg}
63024456fccdSmrg
6303521070a0Smrgvoid
6304521070a0Smrglt_update_lib_path (const char *name, const char *value)
6305521070a0Smrg{
6306ff63a143Smrg  lt_debugprintf (__FILE__, __LINE__,
6307ff63a143Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6308ff63a143Smrg                  nonnull (name), nonnull (value));
63094456fccdSmrg
6310521070a0Smrg  if (name && *name && value && *value)
6311521070a0Smrg    {
6312521070a0Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6313521070a0Smrg      lt_setenv (name, new_value);
6314521070a0Smrg      XFREE (new_value);
6315521070a0Smrg    }
6316521070a0Smrg}
63174456fccdSmrg
6318ff63a143SmrgEOF
6319ff63a143Smrg	    case $host_os in
6320ff63a143Smrg	      mingw*)
6321ff63a143Smrg		cat <<"EOF"
6322ff63a143Smrg
6323ff63a143Smrg/* Prepares an argument vector before calling spawn().
6324ff63a143Smrg   Note that spawn() does not by itself call the command interpreter
6325ff63a143Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6326ff63a143Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6327ff63a143Smrg         GetVersionEx(&v);
6328ff63a143Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6329ff63a143Smrg      }) ? "cmd.exe" : "command.com").
6330ff63a143Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6331ff63a143Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6332ff63a143Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6333ff63a143Smrg   special way:
6334ff63a143Smrg   - Space and tab are interpreted as delimiters. They are not treated as
6335ff63a143Smrg     delimiters if they are surrounded by double quotes: "...".
6336ff63a143Smrg   - Unescaped double quotes are removed from the input. Their only effect is
6337ff63a143Smrg     that within double quotes, space and tab are treated like normal
6338ff63a143Smrg     characters.
6339ff63a143Smrg   - Backslashes not followed by double quotes are not special.
6340ff63a143Smrg   - But 2*n+1 backslashes followed by a double quote become
6341ff63a143Smrg     n backslashes followed by a double quote (n >= 0):
6342ff63a143Smrg       \" -> "
6343ff63a143Smrg       \\\" -> \"
6344ff63a143Smrg       \\\\\" -> \\"
6345ff63a143Smrg */
6346ff63a143Smrg#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"
6347ff63a143Smrg#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"
6348ff63a143Smrgchar **
6349ff63a143Smrgprepare_spawn (char **argv)
6350ff63a143Smrg{
6351ff63a143Smrg  size_t argc;
6352ff63a143Smrg  char **new_argv;
6353ff63a143Smrg  size_t i;
6354ff63a143Smrg
6355ff63a143Smrg  /* Count number of arguments.  */
6356ff63a143Smrg  for (argc = 0; argv[argc] != NULL; argc++)
6357ff63a143Smrg    ;
6358ff63a143Smrg
6359ff63a143Smrg  /* Allocate new argument vector.  */
6360ff63a143Smrg  new_argv = XMALLOC (char *, argc + 1);
6361ff63a143Smrg
6362ff63a143Smrg  /* Put quoted arguments into the new argument vector.  */
6363ff63a143Smrg  for (i = 0; i < argc; i++)
6364ff63a143Smrg    {
6365ff63a143Smrg      const char *string = argv[i];
6366ff63a143Smrg
6367ff63a143Smrg      if (string[0] == '\0')
6368ff63a143Smrg	new_argv[i] = xstrdup ("\"\"");
6369ff63a143Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6370ff63a143Smrg	{
6371ff63a143Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6372ff63a143Smrg	  size_t length;
6373ff63a143Smrg	  unsigned int backslashes;
6374ff63a143Smrg	  const char *s;
6375ff63a143Smrg	  char *quoted_string;
6376ff63a143Smrg	  char *p;
6377ff63a143Smrg
6378ff63a143Smrg	  length = 0;
6379ff63a143Smrg	  backslashes = 0;
6380ff63a143Smrg	  if (quote_around)
6381ff63a143Smrg	    length++;
6382ff63a143Smrg	  for (s = string; *s != '\0'; s++)
6383ff63a143Smrg	    {
6384ff63a143Smrg	      char c = *s;
6385ff63a143Smrg	      if (c == '"')
6386ff63a143Smrg		length += backslashes + 1;
6387ff63a143Smrg	      length++;
6388ff63a143Smrg	      if (c == '\\')
6389ff63a143Smrg		backslashes++;
6390ff63a143Smrg	      else
6391ff63a143Smrg		backslashes = 0;
6392ff63a143Smrg	    }
6393ff63a143Smrg	  if (quote_around)
6394ff63a143Smrg	    length += backslashes + 1;
6395ff63a143Smrg
6396ff63a143Smrg	  quoted_string = XMALLOC (char, length + 1);
6397ff63a143Smrg
6398ff63a143Smrg	  p = quoted_string;
6399ff63a143Smrg	  backslashes = 0;
6400ff63a143Smrg	  if (quote_around)
6401ff63a143Smrg	    *p++ = '"';
6402ff63a143Smrg	  for (s = string; *s != '\0'; s++)
6403ff63a143Smrg	    {
6404ff63a143Smrg	      char c = *s;
6405ff63a143Smrg	      if (c == '"')
6406ff63a143Smrg		{
6407ff63a143Smrg		  unsigned int j;
6408ff63a143Smrg		  for (j = backslashes + 1; j > 0; j--)
6409ff63a143Smrg		    *p++ = '\\';
6410ff63a143Smrg		}
6411ff63a143Smrg	      *p++ = c;
6412ff63a143Smrg	      if (c == '\\')
6413ff63a143Smrg		backslashes++;
6414ff63a143Smrg	      else
6415ff63a143Smrg		backslashes = 0;
6416ff63a143Smrg	    }
6417ff63a143Smrg	  if (quote_around)
6418ff63a143Smrg	    {
6419ff63a143Smrg	      unsigned int j;
6420ff63a143Smrg	      for (j = backslashes; j > 0; j--)
6421ff63a143Smrg		*p++ = '\\';
6422ff63a143Smrg	      *p++ = '"';
6423ff63a143Smrg	    }
6424ff63a143Smrg	  *p = '\0';
6425ff63a143Smrg
6426ff63a143Smrg	  new_argv[i] = quoted_string;
6427ff63a143Smrg	}
6428ff63a143Smrg      else
6429ff63a143Smrg	new_argv[i] = (char *) string;
6430ff63a143Smrg    }
6431ff63a143Smrg  new_argv[argc] = NULL;
6432ff63a143Smrg
6433ff63a143Smrg  return new_argv;
6434ff63a143Smrg}
6435ff63a143SmrgEOF
6436ff63a143Smrg		;;
6437ff63a143Smrg	    esac
6438ff63a143Smrg
6439ff63a143Smrg            cat <<"EOF"
6440ff63a143Smrgvoid lt_dump_script (FILE* f)
6441ff63a143Smrg{
6442ff63a143SmrgEOF
6443ff63a143Smrg	    func_emit_wrapper yes |
64443e6c936aSmrg	      $SED -n -e '
64453e6c936aSmrgs/^\(.\{79\}\)\(..*\)/\1\
64463e6c936aSmrg\2/
64473e6c936aSmrgh
64483e6c936aSmrgs/\([\\"]\)/\\\1/g
64493e6c936aSmrgs/$/\\n/
64503e6c936aSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
64513e6c936aSmrgg
64523e6c936aSmrgD'
6453ff63a143Smrg            cat <<"EOF"
6454ff63a143Smrg}
6455521070a0SmrgEOF
6456521070a0Smrg}
6457521070a0Smrg# end: func_emit_cwrapperexe_src
64584456fccdSmrg
6459ff63a143Smrg# func_win32_import_lib_p ARG
6460ff63a143Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6461ff63a143Smrgfunc_win32_import_lib_p ()
6462ff63a143Smrg{
6463b0a0317aSmrg    $debug_cmd
6464b0a0317aSmrg
6465ff63a143Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6466ff63a143Smrg    *import*) : ;;
6467ff63a143Smrg    *) false ;;
6468ff63a143Smrg    esac
6469ff63a143Smrg}
6470ff63a143Smrg
6471b0a0317aSmrg# func_suncc_cstd_abi
6472b0a0317aSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6473b0a0317aSmrg# Several compiler flags select an ABI that is incompatible with the
6474b0a0317aSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6475b0a0317aSmrgfunc_suncc_cstd_abi ()
6476b0a0317aSmrg{
6477b0a0317aSmrg    $debug_cmd
6478b0a0317aSmrg
6479b0a0317aSmrg    case " $compile_command " in
6480b0a0317aSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6481b0a0317aSmrg      suncc_use_cstd_abi=no
6482b0a0317aSmrg      ;;
6483b0a0317aSmrg    *)
6484b0a0317aSmrg      suncc_use_cstd_abi=yes
6485b0a0317aSmrg      ;;
6486b0a0317aSmrg    esac
6487b0a0317aSmrg}
6488b0a0317aSmrg
6489521070a0Smrg# func_mode_link arg...
6490521070a0Smrgfunc_mode_link ()
6491521070a0Smrg{
6492b0a0317aSmrg    $debug_cmd
6493b0a0317aSmrg
6494521070a0Smrg    case $host in
6495521070a0Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6496521070a0Smrg      # It is impossible to link a dll without this setting, and
6497521070a0Smrg      # we shouldn't force the makefile maintainer to figure out
6498b0a0317aSmrg      # what system we are compiling for in order to pass an extra
6499521070a0Smrg      # flag for every libtool invocation.
6500521070a0Smrg      # allow_undefined=no
65014456fccdSmrg
6502521070a0Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6503b0a0317aSmrg      # to make a dll that has undefined symbols, in which case not
6504521070a0Smrg      # even a static library is built.  For now, we need to specify
6505521070a0Smrg      # -no-undefined on the libtool link line when we can be certain
6506521070a0Smrg      # that all symbols are satisfied, otherwise we get a static library.
6507521070a0Smrg      allow_undefined=yes
6508521070a0Smrg      ;;
6509521070a0Smrg    *)
6510521070a0Smrg      allow_undefined=yes
6511521070a0Smrg      ;;
6512521070a0Smrg    esac
6513521070a0Smrg    libtool_args=$nonopt
6514521070a0Smrg    base_compile="$nonopt $@"
6515521070a0Smrg    compile_command=$nonopt
6516521070a0Smrg    finalize_command=$nonopt
65174456fccdSmrg
6518521070a0Smrg    compile_rpath=
6519521070a0Smrg    finalize_rpath=
6520521070a0Smrg    compile_shlibpath=
6521521070a0Smrg    finalize_shlibpath=
6522521070a0Smrg    convenience=
6523521070a0Smrg    old_convenience=
6524521070a0Smrg    deplibs=
6525521070a0Smrg    old_deplibs=
6526521070a0Smrg    compiler_flags=
6527521070a0Smrg    linker_flags=
6528521070a0Smrg    dllsearchpath=
6529521070a0Smrg    lib_search_path=`pwd`
6530521070a0Smrg    inst_prefix_dir=
6531521070a0Smrg    new_inherited_linker_flags=
65324456fccdSmrg
6533521070a0Smrg    avoid_version=no
6534ff63a143Smrg    bindir=
6535521070a0Smrg    dlfiles=
6536521070a0Smrg    dlprefiles=
6537521070a0Smrg    dlself=no
6538521070a0Smrg    export_dynamic=no
6539521070a0Smrg    export_symbols=
6540521070a0Smrg    export_symbols_regex=
6541521070a0Smrg    generated=
6542521070a0Smrg    libobjs=
6543521070a0Smrg    ltlibs=
6544521070a0Smrg    module=no
6545521070a0Smrg    no_install=no
6546521070a0Smrg    objs=
6547b0a0317aSmrg    os2dllname=
6548521070a0Smrg    non_pic_objects=
6549521070a0Smrg    precious_files_regex=
6550521070a0Smrg    prefer_static_libs=no
6551b0a0317aSmrg    preload=false
6552521070a0Smrg    prev=
6553521070a0Smrg    prevarg=
6554521070a0Smrg    release=
6555521070a0Smrg    rpath=
6556521070a0Smrg    xrpath=
6557521070a0Smrg    perm_rpath=
6558521070a0Smrg    temp_rpath=
6559521070a0Smrg    thread_safe=no
6560521070a0Smrg    vinfo=
6561521070a0Smrg    vinfo_number=no
6562521070a0Smrg    weak_libs=
6563b0a0317aSmrg    single_module=$wl-single_module
6564521070a0Smrg    func_infer_tag $base_compile
6565521070a0Smrg
6566521070a0Smrg    # We need to know -static, to get the right output filenames.
6567521070a0Smrg    for arg
6568521070a0Smrg    do
6569521070a0Smrg      case $arg in
6570521070a0Smrg      -shared)
6571b0a0317aSmrg	test yes != "$build_libtool_libs" \
6572b0a0317aSmrg	  && func_fatal_configuration "cannot build a shared library"
6573521070a0Smrg	build_old_libs=no
6574521070a0Smrg	break
6575521070a0Smrg	;;
6576521070a0Smrg      -all-static | -static | -static-libtool-libs)
6577521070a0Smrg	case $arg in
6578521070a0Smrg	-all-static)
6579b0a0317aSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6580521070a0Smrg	    func_warning "complete static linking is impossible in this configuration"
6581521070a0Smrg	  fi
6582521070a0Smrg	  if test -n "$link_static_flag"; then
6583521070a0Smrg	    dlopen_self=$dlopen_self_static
6584521070a0Smrg	  fi
6585521070a0Smrg	  prefer_static_libs=yes
6586521070a0Smrg	  ;;
6587521070a0Smrg	-static)
6588521070a0Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6589521070a0Smrg	    dlopen_self=$dlopen_self_static
6590521070a0Smrg	  fi
6591521070a0Smrg	  prefer_static_libs=built
6592521070a0Smrg	  ;;
6593521070a0Smrg	-static-libtool-libs)
6594521070a0Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6595521070a0Smrg	    dlopen_self=$dlopen_self_static
65964456fccdSmrg	  fi
6597521070a0Smrg	  prefer_static_libs=yes
6598521070a0Smrg	  ;;
6599521070a0Smrg	esac
6600521070a0Smrg	build_libtool_libs=no
6601521070a0Smrg	build_old_libs=yes
6602521070a0Smrg	break
6603521070a0Smrg	;;
6604521070a0Smrg      esac
6605521070a0Smrg    done
66064456fccdSmrg
6607521070a0Smrg    # See if our shared archives depend on static archives.
6608521070a0Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
66094456fccdSmrg
6610521070a0Smrg    # Go through the arguments, transforming them on the way.
6611521070a0Smrg    while test "$#" -gt 0; do
6612b0a0317aSmrg      arg=$1
6613521070a0Smrg      shift
6614521070a0Smrg      func_quote_for_eval "$arg"
6615521070a0Smrg      qarg=$func_quote_for_eval_unquoted_result
6616521070a0Smrg      func_append libtool_args " $func_quote_for_eval_result"
66174456fccdSmrg
6618521070a0Smrg      # If the previous option needs an argument, assign it.
6619521070a0Smrg      if test -n "$prev"; then
6620521070a0Smrg	case $prev in
6621521070a0Smrg	output)
6622521070a0Smrg	  func_append compile_command " @OUTPUT@"
6623521070a0Smrg	  func_append finalize_command " @OUTPUT@"
6624521070a0Smrg	  ;;
6625521070a0Smrg	esac
66264456fccdSmrg
6627521070a0Smrg	case $prev in
6628ff63a143Smrg	bindir)
6629b0a0317aSmrg	  bindir=$arg
6630ff63a143Smrg	  prev=
6631ff63a143Smrg	  continue
6632ff63a143Smrg	  ;;
6633521070a0Smrg	dlfiles|dlprefiles)
6634b0a0317aSmrg	  $preload || {
6635521070a0Smrg	    # Add the symbol object into the linking commands.
6636521070a0Smrg	    func_append compile_command " @SYMFILE@"
6637521070a0Smrg	    func_append finalize_command " @SYMFILE@"
6638b0a0317aSmrg	    preload=:
6639b0a0317aSmrg	  }
6640521070a0Smrg	  case $arg in
6641521070a0Smrg	  *.la | *.lo) ;;  # We handle these cases below.
6642521070a0Smrg	  force)
6643b0a0317aSmrg	    if test no = "$dlself"; then
6644521070a0Smrg	      dlself=needless
6645521070a0Smrg	      export_dynamic=yes
6646521070a0Smrg	    fi
6647521070a0Smrg	    prev=
6648521070a0Smrg	    continue
6649521070a0Smrg	    ;;
6650521070a0Smrg	  self)
6651b0a0317aSmrg	    if test dlprefiles = "$prev"; then
6652521070a0Smrg	      dlself=yes
6653b0a0317aSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6654521070a0Smrg	      dlself=yes
66554456fccdSmrg	    else
6656521070a0Smrg	      dlself=needless
6657521070a0Smrg	      export_dynamic=yes
66584456fccdSmrg	    fi
6659521070a0Smrg	    prev=
6660521070a0Smrg	    continue
6661521070a0Smrg	    ;;
6662521070a0Smrg	  *)
6663b0a0317aSmrg	    if test dlfiles = "$prev"; then
66643e6c936aSmrg	      func_append dlfiles " $arg"
66654456fccdSmrg	    else
66663e6c936aSmrg	      func_append dlprefiles " $arg"
66674456fccdSmrg	    fi
6668521070a0Smrg	    prev=
6669521070a0Smrg	    continue
6670521070a0Smrg	    ;;
6671521070a0Smrg	  esac
6672521070a0Smrg	  ;;
6673521070a0Smrg	expsyms)
6674b0a0317aSmrg	  export_symbols=$arg
6675521070a0Smrg	  test -f "$arg" \
6676b0a0317aSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
6677521070a0Smrg	  prev=
6678521070a0Smrg	  continue
6679521070a0Smrg	  ;;
6680521070a0Smrg	expsyms_regex)
6681b0a0317aSmrg	  export_symbols_regex=$arg
6682521070a0Smrg	  prev=
6683521070a0Smrg	  continue
6684521070a0Smrg	  ;;
6685521070a0Smrg	framework)
66864456fccdSmrg	  case $host in
6687521070a0Smrg	    *-*-darwin*)
6688521070a0Smrg	      case "$deplibs " in
6689521070a0Smrg		*" $qarg.ltframework "*) ;;
66903e6c936aSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6691521070a0Smrg		   ;;
6692521070a0Smrg	      esac
6693521070a0Smrg	      ;;
66944456fccdSmrg	  esac
6695521070a0Smrg	  prev=
6696521070a0Smrg	  continue
66974456fccdSmrg	  ;;
6698521070a0Smrg	inst_prefix)
6699b0a0317aSmrg	  inst_prefix_dir=$arg
6700b0a0317aSmrg	  prev=
6701b0a0317aSmrg	  continue
6702b0a0317aSmrg	  ;;
6703b0a0317aSmrg	mllvm)
6704b0a0317aSmrg	  # Clang does not use LLVM to link, so we can simply discard any
6705b0a0317aSmrg	  # '-mllvm $arg' options when doing the link step.
6706521070a0Smrg	  prev=
6707521070a0Smrg	  continue
67084456fccdSmrg	  ;;
6709521070a0Smrg	objectlist)
6710521070a0Smrg	  if test -f "$arg"; then
6711521070a0Smrg	    save_arg=$arg
6712521070a0Smrg	    moreargs=
6713521070a0Smrg	    for fil in `cat "$save_arg"`
6714521070a0Smrg	    do
67153e6c936aSmrg#	      func_append moreargs " $fil"
6716521070a0Smrg	      arg=$fil
6717521070a0Smrg	      # A libtool-controlled object.
67184456fccdSmrg
6719521070a0Smrg	      # Check to see that this really is a libtool object.
6720521070a0Smrg	      if func_lalib_unsafe_p "$arg"; then
6721521070a0Smrg		pic_object=
6722521070a0Smrg		non_pic_object=
67234456fccdSmrg
6724521070a0Smrg		# Read the .lo file
6725521070a0Smrg		func_source "$arg"
67264456fccdSmrg
6727521070a0Smrg		if test -z "$pic_object" ||
6728521070a0Smrg		   test -z "$non_pic_object" ||
6729b0a0317aSmrg		   test none = "$pic_object" &&
6730b0a0317aSmrg		   test none = "$non_pic_object"; then
6731b0a0317aSmrg		  func_fatal_error "cannot find name of object for '$arg'"
6732521070a0Smrg		fi
67334456fccdSmrg
6734521070a0Smrg		# Extract subdirectory from the argument.
6735521070a0Smrg		func_dirname "$arg" "/" ""
6736b0a0317aSmrg		xdir=$func_dirname_result
67374456fccdSmrg
6738b0a0317aSmrg		if test none != "$pic_object"; then
6739521070a0Smrg		  # Prepend the subdirectory the object is found in.
6740b0a0317aSmrg		  pic_object=$xdir$pic_object
67414456fccdSmrg
6742b0a0317aSmrg		  if test dlfiles = "$prev"; then
6743b0a0317aSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
67443e6c936aSmrg		      func_append dlfiles " $pic_object"
6745521070a0Smrg		      prev=
6746521070a0Smrg		      continue
6747521070a0Smrg		    else
6748521070a0Smrg		      # If libtool objects are unsupported, then we need to preload.
6749521070a0Smrg		      prev=dlprefiles
6750521070a0Smrg		    fi
6751521070a0Smrg		  fi
67524456fccdSmrg
6753521070a0Smrg		  # CHECK ME:  I think I busted this.  -Ossama
6754b0a0317aSmrg		  if test dlprefiles = "$prev"; then
6755521070a0Smrg		    # Preload the old-style object.
67563e6c936aSmrg		    func_append dlprefiles " $pic_object"
6757521070a0Smrg		    prev=
6758521070a0Smrg		  fi
67594456fccdSmrg
6760521070a0Smrg		  # A PIC object.
6761521070a0Smrg		  func_append libobjs " $pic_object"
6762b0a0317aSmrg		  arg=$pic_object
6763521070a0Smrg		fi
67644456fccdSmrg
6765521070a0Smrg		# Non-PIC object.
6766b0a0317aSmrg		if test none != "$non_pic_object"; then
6767521070a0Smrg		  # Prepend the subdirectory the object is found in.
6768b0a0317aSmrg		  non_pic_object=$xdir$non_pic_object
67694456fccdSmrg
6770521070a0Smrg		  # A standard non-PIC object
6771521070a0Smrg		  func_append non_pic_objects " $non_pic_object"
6772b0a0317aSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
6773b0a0317aSmrg		    arg=$non_pic_object
6774521070a0Smrg		  fi
6775521070a0Smrg		else
6776521070a0Smrg		  # If the PIC object exists, use it instead.
6777521070a0Smrg		  # $xdir was prepended to $pic_object above.
6778b0a0317aSmrg		  non_pic_object=$pic_object
6779521070a0Smrg		  func_append non_pic_objects " $non_pic_object"
6780521070a0Smrg		fi
6781521070a0Smrg	      else
6782521070a0Smrg		# Only an error if not doing a dry-run.
6783521070a0Smrg		if $opt_dry_run; then
6784521070a0Smrg		  # Extract subdirectory from the argument.
6785521070a0Smrg		  func_dirname "$arg" "/" ""
6786b0a0317aSmrg		  xdir=$func_dirname_result
6787521070a0Smrg
6788521070a0Smrg		  func_lo2o "$arg"
6789521070a0Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
6790521070a0Smrg		  non_pic_object=$xdir$func_lo2o_result
6791521070a0Smrg		  func_append libobjs " $pic_object"
6792521070a0Smrg		  func_append non_pic_objects " $non_pic_object"
6793521070a0Smrg	        else
6794b0a0317aSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
6795521070a0Smrg		fi
6796521070a0Smrg	      fi
6797521070a0Smrg	    done
67984456fccdSmrg	  else
6799b0a0317aSmrg	    func_fatal_error "link input file '$arg' does not exist"
68004456fccdSmrg	  fi
6801521070a0Smrg	  arg=$save_arg
6802521070a0Smrg	  prev=
6803521070a0Smrg	  continue
6804521070a0Smrg	  ;;
6805b0a0317aSmrg	os2dllname)
6806b0a0317aSmrg	  os2dllname=$arg
6807b0a0317aSmrg	  prev=
6808b0a0317aSmrg	  continue
6809b0a0317aSmrg	  ;;
6810521070a0Smrg	precious_regex)
6811b0a0317aSmrg	  precious_files_regex=$arg
6812521070a0Smrg	  prev=
6813521070a0Smrg	  continue
6814521070a0Smrg	  ;;
6815521070a0Smrg	release)
6816b0a0317aSmrg	  release=-$arg
6817521070a0Smrg	  prev=
6818521070a0Smrg	  continue
6819521070a0Smrg	  ;;
6820521070a0Smrg	rpath | xrpath)
6821521070a0Smrg	  # We need an absolute path.
6822521070a0Smrg	  case $arg in
6823521070a0Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
6824521070a0Smrg	  *)
6825521070a0Smrg	    func_fatal_error "only absolute run-paths are allowed"
6826521070a0Smrg	    ;;
6827521070a0Smrg	  esac
6828b0a0317aSmrg	  if test rpath = "$prev"; then
6829521070a0Smrg	    case "$rpath " in
6830521070a0Smrg	    *" $arg "*) ;;
68313e6c936aSmrg	    *) func_append rpath " $arg" ;;
6832521070a0Smrg	    esac
68334456fccdSmrg	  else
6834521070a0Smrg	    case "$xrpath " in
6835521070a0Smrg	    *" $arg "*) ;;
68363e6c936aSmrg	    *) func_append xrpath " $arg" ;;
6837521070a0Smrg	    esac
68384456fccdSmrg	  fi
6839521070a0Smrg	  prev=
6840521070a0Smrg	  continue
6841521070a0Smrg	  ;;
6842521070a0Smrg	shrext)
6843b0a0317aSmrg	  shrext_cmds=$arg
6844521070a0Smrg	  prev=
6845521070a0Smrg	  continue
6846521070a0Smrg	  ;;
6847521070a0Smrg	weak)
68483e6c936aSmrg	  func_append weak_libs " $arg"
6849521070a0Smrg	  prev=
6850521070a0Smrg	  continue
6851521070a0Smrg	  ;;
6852521070a0Smrg	xcclinker)
68533e6c936aSmrg	  func_append linker_flags " $qarg"
68543e6c936aSmrg	  func_append compiler_flags " $qarg"
6855521070a0Smrg	  prev=
6856521070a0Smrg	  func_append compile_command " $qarg"
6857521070a0Smrg	  func_append finalize_command " $qarg"
6858521070a0Smrg	  continue
6859521070a0Smrg	  ;;
6860521070a0Smrg	xcompiler)
68613e6c936aSmrg	  func_append compiler_flags " $qarg"
6862521070a0Smrg	  prev=
6863521070a0Smrg	  func_append compile_command " $qarg"
6864521070a0Smrg	  func_append finalize_command " $qarg"
6865521070a0Smrg	  continue
6866521070a0Smrg	  ;;
6867521070a0Smrg	xlinker)
68683e6c936aSmrg	  func_append linker_flags " $qarg"
68693e6c936aSmrg	  func_append compiler_flags " $wl$qarg"
6870521070a0Smrg	  prev=
6871521070a0Smrg	  func_append compile_command " $wl$qarg"
6872521070a0Smrg	  func_append finalize_command " $wl$qarg"
6873521070a0Smrg	  continue
6874521070a0Smrg	  ;;
6875521070a0Smrg	*)
6876521070a0Smrg	  eval "$prev=\"\$arg\""
6877521070a0Smrg	  prev=
6878521070a0Smrg	  continue
6879521070a0Smrg	  ;;
68804456fccdSmrg	esac
6881521070a0Smrg      fi # test -n "$prev"
68824456fccdSmrg
6883b0a0317aSmrg      prevarg=$arg
68844456fccdSmrg
6885521070a0Smrg      case $arg in
6886521070a0Smrg      -all-static)
6887521070a0Smrg	if test -n "$link_static_flag"; then
6888521070a0Smrg	  # See comment for -static flag below, for more details.
6889521070a0Smrg	  func_append compile_command " $link_static_flag"
6890521070a0Smrg	  func_append finalize_command " $link_static_flag"
6891521070a0Smrg	fi
6892521070a0Smrg	continue
6893521070a0Smrg	;;
68944456fccdSmrg
6895521070a0Smrg      -allow-undefined)
6896521070a0Smrg	# FIXME: remove this flag sometime in the future.
6897b0a0317aSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
6898521070a0Smrg	;;
68994456fccdSmrg
6900521070a0Smrg      -avoid-version)
6901521070a0Smrg	avoid_version=yes
6902521070a0Smrg	continue
6903521070a0Smrg	;;
69044456fccdSmrg
6905ff63a143Smrg      -bindir)
6906ff63a143Smrg	prev=bindir
6907ff63a143Smrg	continue
6908ff63a143Smrg	;;
6909ff63a143Smrg
6910521070a0Smrg      -dlopen)
6911521070a0Smrg	prev=dlfiles
6912521070a0Smrg	continue
6913521070a0Smrg	;;
69144456fccdSmrg
6915521070a0Smrg      -dlpreopen)
6916521070a0Smrg	prev=dlprefiles
6917521070a0Smrg	continue
6918521070a0Smrg	;;
69194456fccdSmrg
6920521070a0Smrg      -export-dynamic)
6921521070a0Smrg	export_dynamic=yes
6922521070a0Smrg	continue
6923521070a0Smrg	;;
69244456fccdSmrg
6925521070a0Smrg      -export-symbols | -export-symbols-regex)
6926521070a0Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
6927521070a0Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
6928521070a0Smrg	fi
6929b0a0317aSmrg	if test X-export-symbols = "X$arg"; then
6930521070a0Smrg	  prev=expsyms
6931521070a0Smrg	else
6932521070a0Smrg	  prev=expsyms_regex
6933521070a0Smrg	fi
6934521070a0Smrg	continue
6935521070a0Smrg	;;
69364456fccdSmrg
6937521070a0Smrg      -framework)
6938521070a0Smrg	prev=framework
6939521070a0Smrg	continue
6940521070a0Smrg	;;
69414456fccdSmrg
6942521070a0Smrg      -inst-prefix-dir)
6943521070a0Smrg	prev=inst_prefix
6944521070a0Smrg	continue
6945521070a0Smrg	;;
69464456fccdSmrg
6947521070a0Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
6948521070a0Smrg      # so, if we see these flags be careful not to treat them like -L
6949521070a0Smrg      -L[A-Z][A-Z]*:*)
6950521070a0Smrg	case $with_gcc/$host in
6951521070a0Smrg	no/*-*-irix* | /*-*-irix*)
6952521070a0Smrg	  func_append compile_command " $arg"
6953521070a0Smrg	  func_append finalize_command " $arg"
6954521070a0Smrg	  ;;
6955521070a0Smrg	esac
6956521070a0Smrg	continue
6957521070a0Smrg	;;
69584456fccdSmrg
6959521070a0Smrg      -L*)
69603e6c936aSmrg	func_stripname "-L" '' "$arg"
69613e6c936aSmrg	if test -z "$func_stripname_result"; then
6962521070a0Smrg	  if test "$#" -gt 0; then
6963b0a0317aSmrg	    func_fatal_error "require no space between '-L' and '$1'"
6964521070a0Smrg	  else
6965b0a0317aSmrg	    func_fatal_error "need path for '-L' option"
6966521070a0Smrg	  fi
6967521070a0Smrg	fi
69683e6c936aSmrg	func_resolve_sysroot "$func_stripname_result"
69693e6c936aSmrg	dir=$func_resolve_sysroot_result
6970521070a0Smrg	# We need an absolute path.
6971521070a0Smrg	case $dir in
6972521070a0Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
6973521070a0Smrg	*)
6974521070a0Smrg	  absdir=`cd "$dir" && pwd`
6975521070a0Smrg	  test -z "$absdir" && \
6976b0a0317aSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
6977b0a0317aSmrg	  dir=$absdir
6978521070a0Smrg	  ;;
6979521070a0Smrg	esac
6980521070a0Smrg	case "$deplibs " in
69813e6c936aSmrg	*" -L$dir "* | *" $arg "*)
69823e6c936aSmrg	  # Will only happen for absolute or sysroot arguments
69833e6c936aSmrg	  ;;
6984521070a0Smrg	*)
69853e6c936aSmrg	  # Preserve sysroot, but never include relative directories
69863e6c936aSmrg	  case $dir in
69873e6c936aSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
69883e6c936aSmrg	    *) func_append deplibs " -L$dir" ;;
69893e6c936aSmrg	  esac
69903e6c936aSmrg	  func_append lib_search_path " $dir"
6991521070a0Smrg	  ;;
6992521070a0Smrg	esac
6993521070a0Smrg	case $host in
6994521070a0Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6995ff63a143Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
6996521070a0Smrg	  case :$dllsearchpath: in
6997521070a0Smrg	  *":$dir:"*) ;;
6998521070a0Smrg	  ::) dllsearchpath=$dir;;
69993e6c936aSmrg	  *) func_append dllsearchpath ":$dir";;
7000521070a0Smrg	  esac
7001521070a0Smrg	  case :$dllsearchpath: in
7002521070a0Smrg	  *":$testbindir:"*) ;;
7003521070a0Smrg	  ::) dllsearchpath=$testbindir;;
70043e6c936aSmrg	  *) func_append dllsearchpath ":$testbindir";;
7005521070a0Smrg	  esac
7006521070a0Smrg	  ;;
7007521070a0Smrg	esac
7008521070a0Smrg	continue
7009521070a0Smrg	;;
70104456fccdSmrg
7011521070a0Smrg      -l*)
7012b0a0317aSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7013521070a0Smrg	  case $host in
7014ff63a143Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7015521070a0Smrg	    # These systems don't actually have a C or math library (as such)
7016521070a0Smrg	    continue
7017521070a0Smrg	    ;;
7018521070a0Smrg	  *-*-os2*)
7019521070a0Smrg	    # These systems don't actually have a C library (as such)
7020b0a0317aSmrg	    test X-lc = "X$arg" && continue
7021521070a0Smrg	    ;;
7022b0a0317aSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
7023521070a0Smrg	    # Do not include libc due to us having libc/libc_r.
7024b0a0317aSmrg	    test X-lc = "X$arg" && continue
7025521070a0Smrg	    ;;
7026521070a0Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
7027521070a0Smrg	    # Rhapsody C and math libraries are in the System framework
70283e6c936aSmrg	    func_append deplibs " System.ltframework"
7029521070a0Smrg	    continue
7030521070a0Smrg	    ;;
7031521070a0Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7032521070a0Smrg	    # Causes problems with __ctype
7033b0a0317aSmrg	    test X-lc = "X$arg" && continue
7034521070a0Smrg	    ;;
7035521070a0Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7036521070a0Smrg	    # Compiler inserts libc in the correct place for threads to work
7037b0a0317aSmrg	    test X-lc = "X$arg" && continue
7038521070a0Smrg	    ;;
7039521070a0Smrg	  esac
7040b0a0317aSmrg	elif test X-lc_r = "X$arg"; then
7041521070a0Smrg	 case $host in
7042b0a0317aSmrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
7043521070a0Smrg	   # Do not include libc_r directly, use -pthread flag.
7044521070a0Smrg	   continue
7045521070a0Smrg	   ;;
7046521070a0Smrg	 esac
7047521070a0Smrg	fi
70483e6c936aSmrg	func_append deplibs " $arg"
7049521070a0Smrg	continue
7050521070a0Smrg	;;
70514456fccdSmrg
7052b0a0317aSmrg      -mllvm)
7053b0a0317aSmrg	prev=mllvm
7054b0a0317aSmrg	continue
7055b0a0317aSmrg	;;
7056b0a0317aSmrg
7057521070a0Smrg      -module)
7058521070a0Smrg	module=yes
7059521070a0Smrg	continue
7060521070a0Smrg	;;
70614456fccdSmrg
7062521070a0Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7063521070a0Smrg      # classes, name mangling, and exception handling.
7064521070a0Smrg      # Darwin uses the -arch flag to determine output architecture.
70653e6c936aSmrg      -model|-arch|-isysroot|--sysroot)
70663e6c936aSmrg	func_append compiler_flags " $arg"
7067521070a0Smrg	func_append compile_command " $arg"
7068521070a0Smrg	func_append finalize_command " $arg"
7069521070a0Smrg	prev=xcompiler
7070521070a0Smrg	continue
7071521070a0Smrg	;;
70724456fccdSmrg
70733e6c936aSmrg      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
70743e6c936aSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
70753e6c936aSmrg	func_append compiler_flags " $arg"
7076521070a0Smrg	func_append compile_command " $arg"
7077521070a0Smrg	func_append finalize_command " $arg"
7078521070a0Smrg	case "$new_inherited_linker_flags " in
7079521070a0Smrg	    *" $arg "*) ;;
70803e6c936aSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7081521070a0Smrg	esac
7082521070a0Smrg	continue
7083521070a0Smrg	;;
70844456fccdSmrg
7085521070a0Smrg      -multi_module)
7086b0a0317aSmrg	single_module=$wl-multi_module
7087521070a0Smrg	continue
7088521070a0Smrg	;;
70894456fccdSmrg
7090521070a0Smrg      -no-fast-install)
7091521070a0Smrg	fast_install=no
7092521070a0Smrg	continue
7093521070a0Smrg	;;
70944456fccdSmrg
7095521070a0Smrg      -no-install)
7096521070a0Smrg	case $host in
7097521070a0Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7098521070a0Smrg	  # The PATH hackery in wrapper scripts is required on Windows
7099521070a0Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7100b0a0317aSmrg	  func_warning "'-no-install' is ignored for $host"
7101b0a0317aSmrg	  func_warning "assuming '-no-fast-install' instead"
7102521070a0Smrg	  fast_install=no
7103521070a0Smrg	  ;;
7104521070a0Smrg	*) no_install=yes ;;
7105521070a0Smrg	esac
7106521070a0Smrg	continue
7107521070a0Smrg	;;
71084456fccdSmrg
7109521070a0Smrg      -no-undefined)
7110521070a0Smrg	allow_undefined=no
7111521070a0Smrg	continue
7112521070a0Smrg	;;
71134456fccdSmrg
7114521070a0Smrg      -objectlist)
7115521070a0Smrg	prev=objectlist
7116521070a0Smrg	continue
7117521070a0Smrg	;;
71184456fccdSmrg
7119b0a0317aSmrg      -os2dllname)
7120b0a0317aSmrg	prev=os2dllname
7121b0a0317aSmrg	continue
7122b0a0317aSmrg	;;
7123b0a0317aSmrg
7124521070a0Smrg      -o) prev=output ;;
71254456fccdSmrg
7126521070a0Smrg      -precious-files-regex)
7127521070a0Smrg	prev=precious_regex
7128521070a0Smrg	continue
7129521070a0Smrg	;;
71304456fccdSmrg
7131521070a0Smrg      -release)
7132521070a0Smrg	prev=release
7133521070a0Smrg	continue
7134521070a0Smrg	;;
71354456fccdSmrg
7136521070a0Smrg      -rpath)
7137521070a0Smrg	prev=rpath
7138521070a0Smrg	continue
7139521070a0Smrg	;;
71404456fccdSmrg
7141521070a0Smrg      -R)
7142521070a0Smrg	prev=xrpath
7143521070a0Smrg	continue
7144521070a0Smrg	;;
71454456fccdSmrg
7146521070a0Smrg      -R*)
7147521070a0Smrg	func_stripname '-R' '' "$arg"
7148521070a0Smrg	dir=$func_stripname_result
7149521070a0Smrg	# We need an absolute path.
7150521070a0Smrg	case $dir in
7151521070a0Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
71523e6c936aSmrg	=*)
71533e6c936aSmrg	  func_stripname '=' '' "$dir"
71543e6c936aSmrg	  dir=$lt_sysroot$func_stripname_result
71553e6c936aSmrg	  ;;
7156521070a0Smrg	*)
7157521070a0Smrg	  func_fatal_error "only absolute run-paths are allowed"
7158521070a0Smrg	  ;;
7159521070a0Smrg	esac
7160521070a0Smrg	case "$xrpath " in
7161521070a0Smrg	*" $dir "*) ;;
71623e6c936aSmrg	*) func_append xrpath " $dir" ;;
7163521070a0Smrg	esac
7164521070a0Smrg	continue
7165521070a0Smrg	;;
71664456fccdSmrg
7167521070a0Smrg      -shared)
7168521070a0Smrg	# The effects of -shared are defined in a previous loop.
7169521070a0Smrg	continue
7170521070a0Smrg	;;
71714456fccdSmrg
7172521070a0Smrg      -shrext)
7173521070a0Smrg	prev=shrext
7174521070a0Smrg	continue
7175521070a0Smrg	;;
71764456fccdSmrg
7177521070a0Smrg      -static | -static-libtool-libs)
7178521070a0Smrg	# The effects of -static are defined in a previous loop.
7179521070a0Smrg	# We used to do the same as -all-static on platforms that
7180521070a0Smrg	# didn't have a PIC flag, but the assumption that the effects
7181521070a0Smrg	# would be equivalent was wrong.  It would break on at least
7182521070a0Smrg	# Digital Unix and AIX.
7183521070a0Smrg	continue
7184521070a0Smrg	;;
71854456fccdSmrg
7186521070a0Smrg      -thread-safe)
7187521070a0Smrg	thread_safe=yes
7188521070a0Smrg	continue
7189521070a0Smrg	;;
71904456fccdSmrg
7191521070a0Smrg      -version-info)
7192521070a0Smrg	prev=vinfo
7193521070a0Smrg	continue
7194521070a0Smrg	;;
71954456fccdSmrg
7196521070a0Smrg      -version-number)
7197521070a0Smrg	prev=vinfo
7198521070a0Smrg	vinfo_number=yes
7199521070a0Smrg	continue
7200521070a0Smrg	;;
72014456fccdSmrg
7202521070a0Smrg      -weak)
7203521070a0Smrg        prev=weak
7204521070a0Smrg	continue
7205521070a0Smrg	;;
72064456fccdSmrg
7207521070a0Smrg      -Wc,*)
7208521070a0Smrg	func_stripname '-Wc,' '' "$arg"
7209521070a0Smrg	args=$func_stripname_result
7210521070a0Smrg	arg=
7211b0a0317aSmrg	save_ifs=$IFS; IFS=,
7212521070a0Smrg	for flag in $args; do
7213b0a0317aSmrg	  IFS=$save_ifs
7214521070a0Smrg          func_quote_for_eval "$flag"
72153e6c936aSmrg	  func_append arg " $func_quote_for_eval_result"
72163e6c936aSmrg	  func_append compiler_flags " $func_quote_for_eval_result"
7217521070a0Smrg	done
7218b0a0317aSmrg	IFS=$save_ifs
7219521070a0Smrg	func_stripname ' ' '' "$arg"
7220521070a0Smrg	arg=$func_stripname_result
7221521070a0Smrg	;;
72224456fccdSmrg
7223521070a0Smrg      -Wl,*)
7224521070a0Smrg	func_stripname '-Wl,' '' "$arg"
7225521070a0Smrg	args=$func_stripname_result
7226521070a0Smrg	arg=
7227b0a0317aSmrg	save_ifs=$IFS; IFS=,
7228521070a0Smrg	for flag in $args; do
7229b0a0317aSmrg	  IFS=$save_ifs
7230521070a0Smrg          func_quote_for_eval "$flag"
72313e6c936aSmrg	  func_append arg " $wl$func_quote_for_eval_result"
72323e6c936aSmrg	  func_append compiler_flags " $wl$func_quote_for_eval_result"
72333e6c936aSmrg	  func_append linker_flags " $func_quote_for_eval_result"
7234521070a0Smrg	done
7235b0a0317aSmrg	IFS=$save_ifs
7236521070a0Smrg	func_stripname ' ' '' "$arg"
7237521070a0Smrg	arg=$func_stripname_result
7238521070a0Smrg	;;
72394456fccdSmrg
7240521070a0Smrg      -Xcompiler)
7241521070a0Smrg	prev=xcompiler
7242521070a0Smrg	continue
7243521070a0Smrg	;;
72444456fccdSmrg
7245521070a0Smrg      -Xlinker)
7246521070a0Smrg	prev=xlinker
7247521070a0Smrg	continue
7248521070a0Smrg	;;
72494456fccdSmrg
7250521070a0Smrg      -XCClinker)
7251521070a0Smrg	prev=xcclinker
7252521070a0Smrg	continue
7253521070a0Smrg	;;
72544456fccdSmrg
7255521070a0Smrg      # -msg_* for osf cc
7256521070a0Smrg      -msg_*)
7257521070a0Smrg	func_quote_for_eval "$arg"
7258b0a0317aSmrg	arg=$func_quote_for_eval_result
7259521070a0Smrg	;;
72604456fccdSmrg
7261ff63a143Smrg      # Flags to be passed through unchanged, with rationale:
7262ff63a143Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7263ff63a143Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7264ff63a143Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7265ff63a143Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7266ff63a143Smrg      # -q*                  compiler args for the IBM compiler
7267ff63a143Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7268ff63a143Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7269ff63a143Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7270b0a0317aSmrg      # -fstack-protector*   stack protector flags for GCC
7271ff63a143Smrg      # @file                GCC response files
7272ff63a143Smrg      # -tp=*                Portland pgcc target processor selection
72733e6c936aSmrg      # --sysroot=*          for sysroot support
7274b0a0317aSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7275b0a0317aSmrg      # -specs=*             GCC specs files
7276b0a0317aSmrg      # -stdlib=*            select c++ std lib with clang
7277521070a0Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
72783e6c936aSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7279b0a0317aSmrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7280b0a0317aSmrg      -specs=*)
7281521070a0Smrg        func_quote_for_eval "$arg"
7282b0a0317aSmrg	arg=$func_quote_for_eval_result
7283521070a0Smrg        func_append compile_command " $arg"
7284521070a0Smrg        func_append finalize_command " $arg"
72853e6c936aSmrg        func_append compiler_flags " $arg"
7286521070a0Smrg        continue
7287521070a0Smrg        ;;
72884456fccdSmrg
7289b0a0317aSmrg      -Z*)
7290b0a0317aSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7291b0a0317aSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7292b0a0317aSmrg	  compiler_flags="$compiler_flags $arg"
7293b0a0317aSmrg	  func_append compile_command " $arg"
7294b0a0317aSmrg	  func_append finalize_command " $arg"
7295b0a0317aSmrg	  case $arg in
7296b0a0317aSmrg	  -Zlinker | -Zstack)
7297b0a0317aSmrg	    prev=xcompiler
7298b0a0317aSmrg	    ;;
7299b0a0317aSmrg	  esac
7300b0a0317aSmrg	  continue
7301b0a0317aSmrg        else
7302b0a0317aSmrg	  # Otherwise treat like 'Some other compiler flag' below
7303b0a0317aSmrg	  func_quote_for_eval "$arg"
7304b0a0317aSmrg	  arg=$func_quote_for_eval_result
7305b0a0317aSmrg        fi
7306b0a0317aSmrg	;;
7307b0a0317aSmrg
7308521070a0Smrg      # Some other compiler flag.
7309521070a0Smrg      -* | +*)
7310521070a0Smrg        func_quote_for_eval "$arg"
7311b0a0317aSmrg	arg=$func_quote_for_eval_result
7312521070a0Smrg	;;
73134456fccdSmrg
7314521070a0Smrg      *.$objext)
7315521070a0Smrg	# A standard object.
73163e6c936aSmrg	func_append objs " $arg"
7317521070a0Smrg	;;
73184456fccdSmrg
7319521070a0Smrg      *.lo)
7320521070a0Smrg	# A libtool-controlled object.
73214456fccdSmrg
7322521070a0Smrg	# Check to see that this really is a libtool object.
7323521070a0Smrg	if func_lalib_unsafe_p "$arg"; then
7324521070a0Smrg	  pic_object=
7325521070a0Smrg	  non_pic_object=
73264456fccdSmrg
7327521070a0Smrg	  # Read the .lo file
7328521070a0Smrg	  func_source "$arg"
73294456fccdSmrg
7330521070a0Smrg	  if test -z "$pic_object" ||
7331521070a0Smrg	     test -z "$non_pic_object" ||
7332b0a0317aSmrg	     test none = "$pic_object" &&
7333b0a0317aSmrg	     test none = "$non_pic_object"; then
7334b0a0317aSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7335521070a0Smrg	  fi
73364456fccdSmrg
7337521070a0Smrg	  # Extract subdirectory from the argument.
7338521070a0Smrg	  func_dirname "$arg" "/" ""
7339b0a0317aSmrg	  xdir=$func_dirname_result
734042d69509Smrg
7341b0a0317aSmrg	  test none = "$pic_object" || {
7342521070a0Smrg	    # Prepend the subdirectory the object is found in.
7343b0a0317aSmrg	    pic_object=$xdir$pic_object
73444456fccdSmrg
7345b0a0317aSmrg	    if test dlfiles = "$prev"; then
7346b0a0317aSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
73473e6c936aSmrg		func_append dlfiles " $pic_object"
7348521070a0Smrg		prev=
7349521070a0Smrg		continue
7350521070a0Smrg	      else
7351521070a0Smrg		# If libtool objects are unsupported, then we need to preload.
7352521070a0Smrg		prev=dlprefiles
7353521070a0Smrg	      fi
7354521070a0Smrg	    fi
73554456fccdSmrg
7356521070a0Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7357b0a0317aSmrg	    if test dlprefiles = "$prev"; then
7358521070a0Smrg	      # Preload the old-style object.
73593e6c936aSmrg	      func_append dlprefiles " $pic_object"
7360521070a0Smrg	      prev=
7361521070a0Smrg	    fi
73624456fccdSmrg
7363521070a0Smrg	    # A PIC object.
7364521070a0Smrg	    func_append libobjs " $pic_object"
7365b0a0317aSmrg	    arg=$pic_object
7366b0a0317aSmrg	  }
73674456fccdSmrg
7368521070a0Smrg	  # Non-PIC object.
7369b0a0317aSmrg	  if test none != "$non_pic_object"; then
7370521070a0Smrg	    # Prepend the subdirectory the object is found in.
7371b0a0317aSmrg	    non_pic_object=$xdir$non_pic_object
73724456fccdSmrg
7373521070a0Smrg	    # A standard non-PIC object
7374521070a0Smrg	    func_append non_pic_objects " $non_pic_object"
7375b0a0317aSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7376b0a0317aSmrg	      arg=$non_pic_object
7377521070a0Smrg	    fi
7378521070a0Smrg	  else
7379521070a0Smrg	    # If the PIC object exists, use it instead.
7380521070a0Smrg	    # $xdir was prepended to $pic_object above.
7381b0a0317aSmrg	    non_pic_object=$pic_object
7382521070a0Smrg	    func_append non_pic_objects " $non_pic_object"
7383521070a0Smrg	  fi
7384521070a0Smrg	else
7385521070a0Smrg	  # Only an error if not doing a dry-run.
7386521070a0Smrg	  if $opt_dry_run; then
7387521070a0Smrg	    # Extract subdirectory from the argument.
7388521070a0Smrg	    func_dirname "$arg" "/" ""
7389b0a0317aSmrg	    xdir=$func_dirname_result
7390521070a0Smrg
7391521070a0Smrg	    func_lo2o "$arg"
7392521070a0Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
7393521070a0Smrg	    non_pic_object=$xdir$func_lo2o_result
7394521070a0Smrg	    func_append libobjs " $pic_object"
7395521070a0Smrg	    func_append non_pic_objects " $non_pic_object"
7396521070a0Smrg	  else
7397b0a0317aSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7398521070a0Smrg	  fi
7399521070a0Smrg	fi
7400521070a0Smrg	;;
74014456fccdSmrg
7402521070a0Smrg      *.$libext)
7403521070a0Smrg	# An archive.
74043e6c936aSmrg	func_append deplibs " $arg"
74053e6c936aSmrg	func_append old_deplibs " $arg"
7406521070a0Smrg	continue
7407521070a0Smrg	;;
7408521070a0Smrg
7409521070a0Smrg      *.la)
7410521070a0Smrg	# A libtool-controlled library.
7411521070a0Smrg
74123e6c936aSmrg	func_resolve_sysroot "$arg"
7413b0a0317aSmrg	if test dlfiles = "$prev"; then
7414521070a0Smrg	  # This library was specified with -dlopen.
74153e6c936aSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
7416521070a0Smrg	  prev=
7417b0a0317aSmrg	elif test dlprefiles = "$prev"; then
7418521070a0Smrg	  # The library was specified with -dlpreopen.
74193e6c936aSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7420521070a0Smrg	  prev=
7421521070a0Smrg	else
74223e6c936aSmrg	  func_append deplibs " $func_resolve_sysroot_result"
7423521070a0Smrg	fi
7424521070a0Smrg	continue
7425521070a0Smrg	;;
7426521070a0Smrg
7427521070a0Smrg      # Some other compiler argument.
7428521070a0Smrg      *)
7429521070a0Smrg	# Unknown arguments in both finalize_command and compile_command need
7430521070a0Smrg	# to be aesthetically quoted because they are evaled later.
7431521070a0Smrg	func_quote_for_eval "$arg"
7432b0a0317aSmrg	arg=$func_quote_for_eval_result
7433521070a0Smrg	;;
7434521070a0Smrg      esac # arg
7435521070a0Smrg
7436521070a0Smrg      # Now actually substitute the argument into the commands.
7437521070a0Smrg      if test -n "$arg"; then
7438521070a0Smrg	func_append compile_command " $arg"
7439521070a0Smrg	func_append finalize_command " $arg"
7440521070a0Smrg      fi
7441521070a0Smrg    done # argument parsing loop
7442521070a0Smrg
7443521070a0Smrg    test -n "$prev" && \
7444b0a0317aSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7445521070a0Smrg
7446b0a0317aSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7447521070a0Smrg      eval arg=\"$export_dynamic_flag_spec\"
7448521070a0Smrg      func_append compile_command " $arg"
7449521070a0Smrg      func_append finalize_command " $arg"
7450521070a0Smrg    fi
7451521070a0Smrg
7452521070a0Smrg    oldlibs=
7453521070a0Smrg    # calculate the name of the file, without its directory
7454521070a0Smrg    func_basename "$output"
7455b0a0317aSmrg    outputname=$func_basename_result
7456b0a0317aSmrg    libobjs_save=$libobjs
7457521070a0Smrg
7458521070a0Smrg    if test -n "$shlibpath_var"; then
7459521070a0Smrg      # get the directories listed in $shlibpath_var
7460b0a0317aSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7461521070a0Smrg    else
7462521070a0Smrg      shlib_search_path=
7463521070a0Smrg    fi
7464521070a0Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7465521070a0Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7466521070a0Smrg
7467b0a0317aSmrg    # Definition is injected by LT_CONFIG during libtool generation.
7468b0a0317aSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7469b0a0317aSmrg
7470521070a0Smrg    func_dirname "$output" "/" ""
7471b0a0317aSmrg    output_objdir=$func_dirname_result$objdir
74723e6c936aSmrg    func_to_tool_file "$output_objdir/"
74733e6c936aSmrg    tool_output_objdir=$func_to_tool_file_result
7474521070a0Smrg    # Create the object directory.
7475521070a0Smrg    func_mkdir_p "$output_objdir"
7476521070a0Smrg
7477521070a0Smrg    # Determine the type of output
7478521070a0Smrg    case $output in
7479521070a0Smrg    "")
7480521070a0Smrg      func_fatal_help "you must specify an output file"
7481521070a0Smrg      ;;
7482521070a0Smrg    *.$libext) linkmode=oldlib ;;
7483521070a0Smrg    *.lo | *.$objext) linkmode=obj ;;
7484521070a0Smrg    *.la) linkmode=lib ;;
7485521070a0Smrg    *) linkmode=prog ;; # Anything else should be a program.
7486521070a0Smrg    esac
7487521070a0Smrg
7488521070a0Smrg    specialdeplibs=
7489521070a0Smrg
7490521070a0Smrg    libs=
7491521070a0Smrg    # Find all interdependent deplibs by searching for libraries
7492521070a0Smrg    # that are linked more than once (e.g. -la -lb -la)
7493521070a0Smrg    for deplib in $deplibs; do
7494b0a0317aSmrg      if $opt_preserve_dup_deps; then
7495521070a0Smrg	case "$libs " in
74963e6c936aSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7497521070a0Smrg	esac
7498521070a0Smrg      fi
74993e6c936aSmrg      func_append libs " $deplib"
7500521070a0Smrg    done
7501521070a0Smrg
7502b0a0317aSmrg    if test lib = "$linkmode"; then
7503521070a0Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7504521070a0Smrg
7505521070a0Smrg      # Compute libraries that are listed more than once in $predeps
7506521070a0Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
7507521070a0Smrg      # not to be eliminated).
7508521070a0Smrg      pre_post_deps=
7509521070a0Smrg      if $opt_duplicate_compiler_generated_deps; then
7510521070a0Smrg	for pre_post_dep in $predeps $postdeps; do
7511521070a0Smrg	  case "$pre_post_deps " in
75123e6c936aSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7513521070a0Smrg	  esac
75143e6c936aSmrg	  func_append pre_post_deps " $pre_post_dep"
7515521070a0Smrg	done
7516521070a0Smrg      fi
7517521070a0Smrg      pre_post_deps=
7518521070a0Smrg    fi
7519521070a0Smrg
7520521070a0Smrg    deplibs=
7521521070a0Smrg    newdependency_libs=
7522521070a0Smrg    newlib_search_path=
7523521070a0Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7524521070a0Smrg    notinst_deplibs= # not-installed libtool libraries
7525521070a0Smrg    notinst_path= # paths that contain not-installed libtool libraries
7526521070a0Smrg
7527521070a0Smrg    case $linkmode in
7528521070a0Smrg    lib)
7529521070a0Smrg	passes="conv dlpreopen link"
7530521070a0Smrg	for file in $dlfiles $dlprefiles; do
7531521070a0Smrg	  case $file in
7532521070a0Smrg	  *.la) ;;
7533521070a0Smrg	  *)
7534b0a0317aSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7535521070a0Smrg	    ;;
7536521070a0Smrg	  esac
7537521070a0Smrg	done
7538521070a0Smrg	;;
7539521070a0Smrg    prog)
7540521070a0Smrg	compile_deplibs=
7541521070a0Smrg	finalize_deplibs=
7542b0a0317aSmrg	alldeplibs=false
7543521070a0Smrg	newdlfiles=
7544521070a0Smrg	newdlprefiles=
7545521070a0Smrg	passes="conv scan dlopen dlpreopen link"
7546521070a0Smrg	;;
7547521070a0Smrg    *)  passes="conv"
7548521070a0Smrg	;;
7549521070a0Smrg    esac
7550521070a0Smrg
7551521070a0Smrg    for pass in $passes; do
7552521070a0Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7553521070a0Smrg      # so that -L comes before libs that need it for instance...
7554b0a0317aSmrg      if test lib,link = "$linkmode,$pass"; then
7555521070a0Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
7556521070a0Smrg	##        order, and fix it there properly
7557521070a0Smrg        tmp_deplibs=
7558521070a0Smrg	for deplib in $deplibs; do
7559521070a0Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
7560521070a0Smrg	done
7561b0a0317aSmrg	deplibs=$tmp_deplibs
7562521070a0Smrg      fi
7563521070a0Smrg
7564b0a0317aSmrg      if test lib,link = "$linkmode,$pass" ||
7565b0a0317aSmrg	 test prog,scan = "$linkmode,$pass"; then
7566b0a0317aSmrg	libs=$deplibs
7567521070a0Smrg	deplibs=
7568521070a0Smrg      fi
7569b0a0317aSmrg      if test prog = "$linkmode"; then
7570521070a0Smrg	case $pass in
7571b0a0317aSmrg	dlopen) libs=$dlfiles ;;
7572b0a0317aSmrg	dlpreopen) libs=$dlprefiles ;;
7573b0a0317aSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7574521070a0Smrg	esac
7575521070a0Smrg      fi
7576b0a0317aSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7577521070a0Smrg	# Collect and forward deplibs of preopened libtool libs
7578521070a0Smrg	for lib in $dlprefiles; do
7579521070a0Smrg	  # Ignore non-libtool-libs
7580521070a0Smrg	  dependency_libs=
75813e6c936aSmrg	  func_resolve_sysroot "$lib"
7582521070a0Smrg	  case $lib in
75833e6c936aSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7584521070a0Smrg	  esac
7585521070a0Smrg
7586521070a0Smrg	  # Collect preopened libtool deplibs, except any this library
7587521070a0Smrg	  # has declared as weak libs
7588521070a0Smrg	  for deplib in $dependency_libs; do
7589ff63a143Smrg	    func_basename "$deplib"
7590ff63a143Smrg            deplib_base=$func_basename_result
7591521070a0Smrg	    case " $weak_libs " in
7592521070a0Smrg	    *" $deplib_base "*) ;;
75933e6c936aSmrg	    *) func_append deplibs " $deplib" ;;
7594521070a0Smrg	    esac
7595521070a0Smrg	  done
7596521070a0Smrg	done
7597b0a0317aSmrg	libs=$dlprefiles
7598521070a0Smrg      fi
7599b0a0317aSmrg      if test dlopen = "$pass"; then
7600521070a0Smrg	# Collect dlpreopened libraries
7601b0a0317aSmrg	save_deplibs=$deplibs
7602521070a0Smrg	deplibs=
7603521070a0Smrg      fi
7604521070a0Smrg
7605521070a0Smrg      for deplib in $libs; do
7606521070a0Smrg	lib=
7607b0a0317aSmrg	found=false
7608521070a0Smrg	case $deplib in
76093e6c936aSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
76103e6c936aSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7611b0a0317aSmrg	  if test prog,link = "$linkmode,$pass"; then
7612521070a0Smrg	    compile_deplibs="$deplib $compile_deplibs"
7613521070a0Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7614521070a0Smrg	  else
76153e6c936aSmrg	    func_append compiler_flags " $deplib"
7616b0a0317aSmrg	    if test lib = "$linkmode"; then
7617521070a0Smrg		case "$new_inherited_linker_flags " in
7618521070a0Smrg		    *" $deplib "*) ;;
76193e6c936aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7620521070a0Smrg		esac
7621521070a0Smrg	    fi
7622521070a0Smrg	  fi
7623521070a0Smrg	  continue
7624521070a0Smrg	  ;;
7625521070a0Smrg	-l*)
7626b0a0317aSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7627b0a0317aSmrg	    func_warning "'-l' is ignored for archives/objects"
7628521070a0Smrg	    continue
7629521070a0Smrg	  fi
7630521070a0Smrg	  func_stripname '-l' '' "$deplib"
7631521070a0Smrg	  name=$func_stripname_result
7632b0a0317aSmrg	  if test lib = "$linkmode"; then
7633521070a0Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7634521070a0Smrg	  else
7635521070a0Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7636521070a0Smrg	  fi
7637521070a0Smrg	  for searchdir in $searchdirs; do
7638521070a0Smrg	    for search_ext in .la $std_shrext .so .a; do
7639521070a0Smrg	      # Search the libtool library
7640b0a0317aSmrg	      lib=$searchdir/lib$name$search_ext
7641521070a0Smrg	      if test -f "$lib"; then
7642b0a0317aSmrg		if test .la = "$search_ext"; then
7643b0a0317aSmrg		  found=:
7644521070a0Smrg		else
7645b0a0317aSmrg		  found=false
7646521070a0Smrg		fi
7647521070a0Smrg		break 2
7648521070a0Smrg	      fi
7649521070a0Smrg	    done
7650521070a0Smrg	  done
7651b0a0317aSmrg	  if $found; then
7652b0a0317aSmrg	    # deplib is a libtool library
7653521070a0Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7654521070a0Smrg	    # We need to do some special things here, and not later.
7655b0a0317aSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7656521070a0Smrg	      case " $predeps $postdeps " in
7657521070a0Smrg	      *" $deplib "*)
7658521070a0Smrg		if func_lalib_p "$lib"; then
7659521070a0Smrg		  library_names=
7660521070a0Smrg		  old_library=
7661521070a0Smrg		  func_source "$lib"
7662521070a0Smrg		  for l in $old_library $library_names; do
7663b0a0317aSmrg		    ll=$l
7664521070a0Smrg		  done
7665b0a0317aSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
7666b0a0317aSmrg		    found=false
7667521070a0Smrg		    func_dirname "$lib" "" "."
7668b0a0317aSmrg		    ladir=$func_dirname_result
7669521070a0Smrg		    lib=$ladir/$old_library
7670b0a0317aSmrg		    if test prog,link = "$linkmode,$pass"; then
7671521070a0Smrg		      compile_deplibs="$deplib $compile_deplibs"
7672521070a0Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
7673521070a0Smrg		    else
7674521070a0Smrg		      deplibs="$deplib $deplibs"
7675b0a0317aSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7676521070a0Smrg		    fi
7677521070a0Smrg		    continue
7678521070a0Smrg		  fi
7679521070a0Smrg		fi
7680521070a0Smrg		;;
7681521070a0Smrg	      *) ;;
7682521070a0Smrg	      esac
7683521070a0Smrg	    fi
7684b0a0317aSmrg	  else
7685b0a0317aSmrg	    # deplib doesn't seem to be a libtool library
7686b0a0317aSmrg	    if test prog,link = "$linkmode,$pass"; then
7687b0a0317aSmrg	      compile_deplibs="$deplib $compile_deplibs"
7688b0a0317aSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7689b0a0317aSmrg	    else
7690b0a0317aSmrg	      deplibs="$deplib $deplibs"
7691b0a0317aSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7692b0a0317aSmrg	    fi
7693b0a0317aSmrg	    continue
7694521070a0Smrg	  fi
7695521070a0Smrg	  ;; # -l
7696521070a0Smrg	*.ltframework)
7697b0a0317aSmrg	  if test prog,link = "$linkmode,$pass"; then
7698521070a0Smrg	    compile_deplibs="$deplib $compile_deplibs"
7699521070a0Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
7700521070a0Smrg	  else
7701521070a0Smrg	    deplibs="$deplib $deplibs"
7702b0a0317aSmrg	    if test lib = "$linkmode"; then
7703521070a0Smrg		case "$new_inherited_linker_flags " in
7704521070a0Smrg		    *" $deplib "*) ;;
77053e6c936aSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7706521070a0Smrg		esac
7707521070a0Smrg	    fi
7708521070a0Smrg	  fi
7709521070a0Smrg	  continue
7710521070a0Smrg	  ;;
7711521070a0Smrg	-L*)
7712521070a0Smrg	  case $linkmode in
7713521070a0Smrg	  lib)
7714521070a0Smrg	    deplibs="$deplib $deplibs"
7715b0a0317aSmrg	    test conv = "$pass" && continue
7716521070a0Smrg	    newdependency_libs="$deplib $newdependency_libs"
7717521070a0Smrg	    func_stripname '-L' '' "$deplib"
77183e6c936aSmrg	    func_resolve_sysroot "$func_stripname_result"
77193e6c936aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
7720521070a0Smrg	    ;;
7721521070a0Smrg	  prog)
7722b0a0317aSmrg	    if test conv = "$pass"; then
7723521070a0Smrg	      deplibs="$deplib $deplibs"
7724521070a0Smrg	      continue
7725521070a0Smrg	    fi
7726b0a0317aSmrg	    if test scan = "$pass"; then
7727521070a0Smrg	      deplibs="$deplib $deplibs"
7728521070a0Smrg	    else
7729521070a0Smrg	      compile_deplibs="$deplib $compile_deplibs"
7730521070a0Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7731521070a0Smrg	    fi
7732521070a0Smrg	    func_stripname '-L' '' "$deplib"
77333e6c936aSmrg	    func_resolve_sysroot "$func_stripname_result"
77343e6c936aSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
7735521070a0Smrg	    ;;
7736521070a0Smrg	  *)
7737b0a0317aSmrg	    func_warning "'-L' is ignored for archives/objects"
7738521070a0Smrg	    ;;
7739521070a0Smrg	  esac # linkmode
7740521070a0Smrg	  continue
7741521070a0Smrg	  ;; # -L
7742521070a0Smrg	-R*)
7743b0a0317aSmrg	  if test link = "$pass"; then
7744521070a0Smrg	    func_stripname '-R' '' "$deplib"
77453e6c936aSmrg	    func_resolve_sysroot "$func_stripname_result"
77463e6c936aSmrg	    dir=$func_resolve_sysroot_result
7747521070a0Smrg	    # Make sure the xrpath contains only unique directories.
7748521070a0Smrg	    case "$xrpath " in
7749521070a0Smrg	    *" $dir "*) ;;
77503e6c936aSmrg	    *) func_append xrpath " $dir" ;;
7751521070a0Smrg	    esac
7752521070a0Smrg	  fi
7753521070a0Smrg	  deplibs="$deplib $deplibs"
7754521070a0Smrg	  continue
7755521070a0Smrg	  ;;
77563e6c936aSmrg	*.la)
77573e6c936aSmrg	  func_resolve_sysroot "$deplib"
77583e6c936aSmrg	  lib=$func_resolve_sysroot_result
77593e6c936aSmrg	  ;;
7760521070a0Smrg	*.$libext)
7761b0a0317aSmrg	  if test conv = "$pass"; then
7762521070a0Smrg	    deplibs="$deplib $deplibs"
7763521070a0Smrg	    continue
7764521070a0Smrg	  fi
7765521070a0Smrg	  case $linkmode in
7766521070a0Smrg	  lib)
7767521070a0Smrg	    # Linking convenience modules into shared libraries is allowed,
7768521070a0Smrg	    # but linking other static libraries is non-portable.
7769521070a0Smrg	    case " $dlpreconveniencelibs " in
7770521070a0Smrg	    *" $deplib "*) ;;
7771521070a0Smrg	    *)
7772b0a0317aSmrg	      valid_a_lib=false
7773521070a0Smrg	      case $deplibs_check_method in
7774521070a0Smrg		match_pattern*)
7775521070a0Smrg		  set dummy $deplibs_check_method; shift
7776521070a0Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
7777ff63a143Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
7778521070a0Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
7779b0a0317aSmrg		    valid_a_lib=:
7780521070a0Smrg		  fi
7781521070a0Smrg		;;
7782521070a0Smrg		pass_all)
7783b0a0317aSmrg		  valid_a_lib=:
7784521070a0Smrg		;;
7785521070a0Smrg	      esac
7786b0a0317aSmrg	      if $valid_a_lib; then
7787b0a0317aSmrg		echo
7788b0a0317aSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
7789b0a0317aSmrg		$ECHO "*** static library $deplib is not portable!"
7790b0a0317aSmrg		deplibs="$deplib $deplibs"
7791b0a0317aSmrg	      else
7792ff63a143Smrg		echo
7793521070a0Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
7794ff63a143Smrg		echo "*** I have the capability to make that library automatically link in when"
7795ff63a143Smrg		echo "*** you link to this library.  But I can only do this if you have a"
7796ff63a143Smrg		echo "*** shared version of the library, which you do not appear to have"
7797ff63a143Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
7798ff63a143Smrg		echo "*** that it is just a static archive that I should not use here."
7799521070a0Smrg	      fi
7800521070a0Smrg	      ;;
7801521070a0Smrg	    esac
7802521070a0Smrg	    continue
7803521070a0Smrg	    ;;
7804521070a0Smrg	  prog)
7805b0a0317aSmrg	    if test link != "$pass"; then
7806521070a0Smrg	      deplibs="$deplib $deplibs"
7807521070a0Smrg	    else
7808521070a0Smrg	      compile_deplibs="$deplib $compile_deplibs"
7809521070a0Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7810521070a0Smrg	    fi
7811521070a0Smrg	    continue
7812521070a0Smrg	    ;;
7813521070a0Smrg	  esac # linkmode
7814521070a0Smrg	  ;; # *.$libext
7815521070a0Smrg	*.lo | *.$objext)
7816b0a0317aSmrg	  if test conv = "$pass"; then
7817521070a0Smrg	    deplibs="$deplib $deplibs"
7818b0a0317aSmrg	  elif test prog = "$linkmode"; then
7819b0a0317aSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
7820521070a0Smrg	      # If there is no dlopen support or we're linking statically,
7821521070a0Smrg	      # we need to preload.
78223e6c936aSmrg	      func_append newdlprefiles " $deplib"
7823521070a0Smrg	      compile_deplibs="$deplib $compile_deplibs"
7824521070a0Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7825521070a0Smrg	    else
78263e6c936aSmrg	      func_append newdlfiles " $deplib"
7827521070a0Smrg	    fi
7828521070a0Smrg	  fi
7829521070a0Smrg	  continue
7830521070a0Smrg	  ;;
7831521070a0Smrg	%DEPLIBS%)
7832b0a0317aSmrg	  alldeplibs=:
7833521070a0Smrg	  continue
7834521070a0Smrg	  ;;
7835521070a0Smrg	esac # case $deplib
7836521070a0Smrg
7837b0a0317aSmrg	$found || test -f "$lib" \
7838b0a0317aSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
7839521070a0Smrg
7840521070a0Smrg	# Check to see that this really is a libtool archive.
7841521070a0Smrg	func_lalib_unsafe_p "$lib" \
7842b0a0317aSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
7843521070a0Smrg
7844521070a0Smrg	func_dirname "$lib" "" "."
7845b0a0317aSmrg	ladir=$func_dirname_result
7846521070a0Smrg
7847521070a0Smrg	dlname=
7848521070a0Smrg	dlopen=
7849521070a0Smrg	dlpreopen=
7850521070a0Smrg	libdir=
7851521070a0Smrg	library_names=
7852521070a0Smrg	old_library=
7853521070a0Smrg	inherited_linker_flags=
7854521070a0Smrg	# If the library was installed with an old release of libtool,
7855521070a0Smrg	# it will not redefine variables installed, or shouldnotlink
7856521070a0Smrg	installed=yes
7857521070a0Smrg	shouldnotlink=no
7858521070a0Smrg	avoidtemprpath=
7859521070a0Smrg
7860521070a0Smrg
7861521070a0Smrg	# Read the .la file
7862521070a0Smrg	func_source "$lib"
7863521070a0Smrg
7864521070a0Smrg	# Convert "-framework foo" to "foo.ltframework"
7865521070a0Smrg	if test -n "$inherited_linker_flags"; then
7866ff63a143Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
7867521070a0Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
7868521070a0Smrg	    case " $new_inherited_linker_flags " in
7869521070a0Smrg	      *" $tmp_inherited_linker_flag "*) ;;
78703e6c936aSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
7871521070a0Smrg	    esac
7872521070a0Smrg	  done
7873521070a0Smrg	fi
7874ff63a143Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
7875b0a0317aSmrg	if test lib,link = "$linkmode,$pass" ||
7876b0a0317aSmrg	   test prog,scan = "$linkmode,$pass" ||
7877b0a0317aSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
78783e6c936aSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
78793e6c936aSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
7880521070a0Smrg	fi
7881521070a0Smrg
7882b0a0317aSmrg	if test conv = "$pass"; then
7883521070a0Smrg	  # Only check for convenience libraries
7884521070a0Smrg	  deplibs="$lib $deplibs"
7885521070a0Smrg	  if test -z "$libdir"; then
7886521070a0Smrg	    if test -z "$old_library"; then
7887b0a0317aSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
7888521070a0Smrg	    fi
7889521070a0Smrg	    # It is a libtool convenience library, so add in its objects.
78903e6c936aSmrg	    func_append convenience " $ladir/$objdir/$old_library"
78913e6c936aSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
7892b0a0317aSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
7893b0a0317aSmrg	    func_fatal_error "'$lib' is not a convenience library"
7894521070a0Smrg	  fi
7895b0a0317aSmrg	  tmp_libs=
7896b0a0317aSmrg	  for deplib in $dependency_libs; do
7897b0a0317aSmrg	    deplibs="$deplib $deplibs"
7898b0a0317aSmrg	    if $opt_preserve_dup_deps; then
7899b0a0317aSmrg	      case "$tmp_libs " in
7900b0a0317aSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
7901b0a0317aSmrg	      esac
7902b0a0317aSmrg	    fi
7903b0a0317aSmrg	    func_append tmp_libs " $deplib"
7904b0a0317aSmrg	  done
7905521070a0Smrg	  continue
7906521070a0Smrg	fi # $pass = conv
7907521070a0Smrg
7908521070a0Smrg
7909521070a0Smrg	# Get the name of the library we link against.
7910521070a0Smrg	linklib=
79113e6c936aSmrg	if test -n "$old_library" &&
7912b0a0317aSmrg	   { test yes = "$prefer_static_libs" ||
7913b0a0317aSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
79143e6c936aSmrg	  linklib=$old_library
79153e6c936aSmrg	else
79163e6c936aSmrg	  for l in $old_library $library_names; do
7917b0a0317aSmrg	    linklib=$l
79183e6c936aSmrg	  done
79193e6c936aSmrg	fi
7920521070a0Smrg	if test -z "$linklib"; then
7921b0a0317aSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
7922521070a0Smrg	fi
7923521070a0Smrg
7924521070a0Smrg	# This library was specified with -dlopen.
7925b0a0317aSmrg	if test dlopen = "$pass"; then
7926b0a0317aSmrg	  test -z "$libdir" \
7927b0a0317aSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
7928521070a0Smrg	  if test -z "$dlname" ||
7929b0a0317aSmrg	     test yes != "$dlopen_support" ||
7930b0a0317aSmrg	     test no = "$build_libtool_libs"
7931b0a0317aSmrg	  then
7932521070a0Smrg	    # If there is no dlname, no dlopen support or we're linking
7933521070a0Smrg	    # statically, we need to preload.  We also need to preload any
7934521070a0Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
7935521070a0Smrg	    # bomb out in the load deplibs phase.
79363e6c936aSmrg	    func_append dlprefiles " $lib $dependency_libs"
7937521070a0Smrg	  else
79383e6c936aSmrg	    func_append newdlfiles " $lib"
7939521070a0Smrg	  fi
7940521070a0Smrg	  continue
7941521070a0Smrg	fi # $pass = dlopen
7942521070a0Smrg
7943521070a0Smrg	# We need an absolute path.
7944521070a0Smrg	case $ladir in
7945b0a0317aSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
7946521070a0Smrg	*)
7947521070a0Smrg	  abs_ladir=`cd "$ladir" && pwd`
7948521070a0Smrg	  if test -z "$abs_ladir"; then
7949b0a0317aSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
7950521070a0Smrg	    func_warning "passing it literally to the linker, although it might fail"
7951b0a0317aSmrg	    abs_ladir=$ladir
7952521070a0Smrg	  fi
7953521070a0Smrg	  ;;
7954521070a0Smrg	esac
7955521070a0Smrg	func_basename "$lib"
7956b0a0317aSmrg	laname=$func_basename_result
7957521070a0Smrg
7958521070a0Smrg	# Find the relevant object directory and library name.
7959b0a0317aSmrg	if test yes = "$installed"; then
79603e6c936aSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7961b0a0317aSmrg	    func_warning "library '$lib' was moved."
7962b0a0317aSmrg	    dir=$ladir
7963b0a0317aSmrg	    absdir=$abs_ladir
7964b0a0317aSmrg	    libdir=$abs_ladir
7965521070a0Smrg	  else
7966b0a0317aSmrg	    dir=$lt_sysroot$libdir
7967b0a0317aSmrg	    absdir=$lt_sysroot$libdir
7968521070a0Smrg	  fi
7969b0a0317aSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
7970521070a0Smrg	else
7971521070a0Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7972b0a0317aSmrg	    dir=$ladir
7973b0a0317aSmrg	    absdir=$abs_ladir
7974521070a0Smrg	    # Remove this search path later
79753e6c936aSmrg	    func_append notinst_path " $abs_ladir"
7976521070a0Smrg	  else
7977b0a0317aSmrg	    dir=$ladir/$objdir
7978b0a0317aSmrg	    absdir=$abs_ladir/$objdir
7979521070a0Smrg	    # Remove this search path later
79803e6c936aSmrg	    func_append notinst_path " $abs_ladir"
7981521070a0Smrg	  fi
7982521070a0Smrg	fi # $installed = yes
7983521070a0Smrg	func_stripname 'lib' '.la' "$laname"
7984521070a0Smrg	name=$func_stripname_result
7985521070a0Smrg
7986521070a0Smrg	# This library was specified with -dlpreopen.
7987b0a0317aSmrg	if test dlpreopen = "$pass"; then
7988b0a0317aSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
7989b0a0317aSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
7990521070a0Smrg	  fi
7991b0a0317aSmrg	  case $host in
79923e6c936aSmrg	    # special handling for platforms with PE-DLLs.
79933e6c936aSmrg	    *cygwin* | *mingw* | *cegcc* )
79943e6c936aSmrg	      # Linker will automatically link against shared library if both
79953e6c936aSmrg	      # static and shared are present.  Therefore, ensure we extract
79963e6c936aSmrg	      # symbols from the import library if a shared library is present
79973e6c936aSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
79983e6c936aSmrg	      # this by putting the import library name into $newdlprefiles.
79993e6c936aSmrg	      # We recover the dlopen module name by 'saving' the la file
80003e6c936aSmrg	      # name in a special purpose variable, and (later) extracting the
80013e6c936aSmrg	      # dlname from the la file.
80023e6c936aSmrg	      if test -n "$dlname"; then
80033e6c936aSmrg	        func_tr_sh "$dir/$linklib"
80043e6c936aSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
80053e6c936aSmrg	        func_append newdlprefiles " $dir/$linklib"
80063e6c936aSmrg	      else
80073e6c936aSmrg	        func_append newdlprefiles " $dir/$old_library"
80083e6c936aSmrg	        # Keep a list of preopened convenience libraries to check
80093e6c936aSmrg	        # that they are being used correctly in the link pass.
80103e6c936aSmrg	        test -z "$libdir" && \
80113e6c936aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
80123e6c936aSmrg	      fi
80133e6c936aSmrg	    ;;
80143e6c936aSmrg	    * )
80153e6c936aSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
80163e6c936aSmrg	      # are required to link).
80173e6c936aSmrg	      if test -n "$old_library"; then
80183e6c936aSmrg	        func_append newdlprefiles " $dir/$old_library"
80193e6c936aSmrg	        # Keep a list of preopened convenience libraries to check
80203e6c936aSmrg	        # that they are being used correctly in the link pass.
80213e6c936aSmrg	        test -z "$libdir" && \
80223e6c936aSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
80233e6c936aSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
80243e6c936aSmrg	      elif test -n "$dlname"; then
80253e6c936aSmrg	        func_append newdlprefiles " $dir/$dlname"
80263e6c936aSmrg	      else
80273e6c936aSmrg	        func_append newdlprefiles " $dir/$linklib"
80283e6c936aSmrg	      fi
80293e6c936aSmrg	    ;;
80303e6c936aSmrg	  esac
8031521070a0Smrg	fi # $pass = dlpreopen
8032521070a0Smrg
8033521070a0Smrg	if test -z "$libdir"; then
8034521070a0Smrg	  # Link the convenience library
8035b0a0317aSmrg	  if test lib = "$linkmode"; then
8036521070a0Smrg	    deplibs="$dir/$old_library $deplibs"
8037b0a0317aSmrg	  elif test prog,link = "$linkmode,$pass"; then
8038521070a0Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8039521070a0Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8040521070a0Smrg	  else
8041521070a0Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8042521070a0Smrg	  fi
8043521070a0Smrg	  continue
8044521070a0Smrg	fi
8045521070a0Smrg
8046521070a0Smrg
8047b0a0317aSmrg	if test prog = "$linkmode" && test link != "$pass"; then
80483e6c936aSmrg	  func_append newlib_search_path " $ladir"
8049521070a0Smrg	  deplibs="$lib $deplibs"
8050521070a0Smrg
8051b0a0317aSmrg	  linkalldeplibs=false
8052b0a0317aSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8053b0a0317aSmrg	     test no = "$build_libtool_libs"; then
8054b0a0317aSmrg	    linkalldeplibs=:
8055521070a0Smrg	  fi
8056521070a0Smrg
8057521070a0Smrg	  tmp_libs=
8058521070a0Smrg	  for deplib in $dependency_libs; do
8059521070a0Smrg	    case $deplib in
8060521070a0Smrg	    -L*) func_stripname '-L' '' "$deplib"
80613e6c936aSmrg	         func_resolve_sysroot "$func_stripname_result"
80623e6c936aSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8063521070a0Smrg		 ;;
8064521070a0Smrg	    esac
8065521070a0Smrg	    # Need to link against all dependency_libs?
8066b0a0317aSmrg	    if $linkalldeplibs; then
8067521070a0Smrg	      deplibs="$deplib $deplibs"
8068521070a0Smrg	    else
8069521070a0Smrg	      # Need to hardcode shared library paths
8070521070a0Smrg	      # or/and link against static libraries
8071521070a0Smrg	      newdependency_libs="$deplib $newdependency_libs"
8072521070a0Smrg	    fi
8073b0a0317aSmrg	    if $opt_preserve_dup_deps; then
8074521070a0Smrg	      case "$tmp_libs " in
80753e6c936aSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8076521070a0Smrg	      esac
8077521070a0Smrg	    fi
80783e6c936aSmrg	    func_append tmp_libs " $deplib"
8079521070a0Smrg	  done # for deplib
8080521070a0Smrg	  continue
8081521070a0Smrg	fi # $linkmode = prog...
8082521070a0Smrg
8083b0a0317aSmrg	if test prog,link = "$linkmode,$pass"; then
8084521070a0Smrg	  if test -n "$library_names" &&
8085b0a0317aSmrg	     { { test no = "$prefer_static_libs" ||
8086b0a0317aSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8087521070a0Smrg	       test -z "$old_library"; }; then
8088521070a0Smrg	    # We need to hardcode the library path
8089b0a0317aSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8090521070a0Smrg	      # Make sure the rpath contains only unique directories.
8091b0a0317aSmrg	      case $temp_rpath: in
8092521070a0Smrg	      *"$absdir:"*) ;;
80933e6c936aSmrg	      *) func_append temp_rpath "$absdir:" ;;
8094521070a0Smrg	      esac
8095521070a0Smrg	    fi
8096521070a0Smrg
8097521070a0Smrg	    # Hardcode the library path.
8098521070a0Smrg	    # Skip directories that are in the system default run-time
8099521070a0Smrg	    # search path.
8100521070a0Smrg	    case " $sys_lib_dlsearch_path " in
8101521070a0Smrg	    *" $absdir "*) ;;
8102521070a0Smrg	    *)
8103521070a0Smrg	      case "$compile_rpath " in
8104521070a0Smrg	      *" $absdir "*) ;;
81053e6c936aSmrg	      *) func_append compile_rpath " $absdir" ;;
8106521070a0Smrg	      esac
8107521070a0Smrg	      ;;
8108521070a0Smrg	    esac
8109521070a0Smrg	    case " $sys_lib_dlsearch_path " in
8110521070a0Smrg	    *" $libdir "*) ;;
8111521070a0Smrg	    *)
8112521070a0Smrg	      case "$finalize_rpath " in
8113521070a0Smrg	      *" $libdir "*) ;;
81143e6c936aSmrg	      *) func_append finalize_rpath " $libdir" ;;
8115521070a0Smrg	      esac
8116521070a0Smrg	      ;;
8117521070a0Smrg	    esac
8118521070a0Smrg	  fi # $linkmode,$pass = prog,link...
8119521070a0Smrg
8120b0a0317aSmrg	  if $alldeplibs &&
8121b0a0317aSmrg	     { test pass_all = "$deplibs_check_method" ||
8122b0a0317aSmrg	       { test yes = "$build_libtool_libs" &&
8123521070a0Smrg		 test -n "$library_names"; }; }; then
8124521070a0Smrg	    # We only need to search for static libraries
8125521070a0Smrg	    continue
8126521070a0Smrg	  fi
8127521070a0Smrg	fi
8128521070a0Smrg
8129521070a0Smrg	link_static=no # Whether the deplib will be linked statically
8130521070a0Smrg	use_static_libs=$prefer_static_libs
8131b0a0317aSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8132521070a0Smrg	  use_static_libs=no
8133521070a0Smrg	fi
8134521070a0Smrg	if test -n "$library_names" &&
8135b0a0317aSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8136521070a0Smrg	  case $host in
8137b0a0317aSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8138521070a0Smrg	      # No point in relinking DLLs because paths are not encoded
81393e6c936aSmrg	      func_append notinst_deplibs " $lib"
8140521070a0Smrg	      need_relink=no
8141521070a0Smrg	    ;;
8142521070a0Smrg	  *)
8143b0a0317aSmrg	    if test no = "$installed"; then
81443e6c936aSmrg	      func_append notinst_deplibs " $lib"
8145521070a0Smrg	      need_relink=yes
8146521070a0Smrg	    fi
8147521070a0Smrg	    ;;
8148521070a0Smrg	  esac
8149521070a0Smrg	  # This is a shared library
8150521070a0Smrg
8151521070a0Smrg	  # Warn about portability, can't link against -module's on some
8152521070a0Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8153b0a0317aSmrg	  dlopenmodule=
8154521070a0Smrg	  for dlpremoduletest in $dlprefiles; do
8155521070a0Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8156b0a0317aSmrg	      dlopenmodule=$dlpremoduletest
8157521070a0Smrg	      break
8158521070a0Smrg	    fi
8159521070a0Smrg	  done
8160b0a0317aSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8161ff63a143Smrg	    echo
8162b0a0317aSmrg	    if test prog = "$linkmode"; then
8163521070a0Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8164521070a0Smrg	    else
8165521070a0Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8166521070a0Smrg	    fi
8167521070a0Smrg	    $ECHO "*** $linklib is not portable!"
8168521070a0Smrg	  fi
8169b0a0317aSmrg	  if test lib = "$linkmode" &&
8170b0a0317aSmrg	     test yes = "$hardcode_into_libs"; then
8171521070a0Smrg	    # Hardcode the library path.
8172521070a0Smrg	    # Skip directories that are in the system default run-time
8173521070a0Smrg	    # search path.
8174521070a0Smrg	    case " $sys_lib_dlsearch_path " in
8175521070a0Smrg	    *" $absdir "*) ;;
8176521070a0Smrg	    *)
8177521070a0Smrg	      case "$compile_rpath " in
8178521070a0Smrg	      *" $absdir "*) ;;
81793e6c936aSmrg	      *) func_append compile_rpath " $absdir" ;;
8180521070a0Smrg	      esac
8181521070a0Smrg	      ;;
8182521070a0Smrg	    esac
8183521070a0Smrg	    case " $sys_lib_dlsearch_path " in
8184521070a0Smrg	    *" $libdir "*) ;;
8185521070a0Smrg	    *)
8186521070a0Smrg	      case "$finalize_rpath " in
8187521070a0Smrg	      *" $libdir "*) ;;
81883e6c936aSmrg	      *) func_append finalize_rpath " $libdir" ;;
8189521070a0Smrg	      esac
8190521070a0Smrg	      ;;
8191521070a0Smrg	    esac
8192521070a0Smrg	  fi
8193521070a0Smrg
8194521070a0Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8195521070a0Smrg	    # figure out the soname
8196521070a0Smrg	    set dummy $library_names
8197521070a0Smrg	    shift
8198b0a0317aSmrg	    realname=$1
8199521070a0Smrg	    shift
8200521070a0Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8201521070a0Smrg	    # use dlname if we got it. it's perfectly good, no?
8202521070a0Smrg	    if test -n "$dlname"; then
8203b0a0317aSmrg	      soname=$dlname
8204521070a0Smrg	    elif test -n "$soname_spec"; then
8205521070a0Smrg	      # bleh windows
8206521070a0Smrg	      case $host in
8207b0a0317aSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8208521070a0Smrg	        func_arith $current - $age
8209521070a0Smrg		major=$func_arith_result
8210b0a0317aSmrg		versuffix=-$major
8211521070a0Smrg		;;
8212521070a0Smrg	      esac
8213521070a0Smrg	      eval soname=\"$soname_spec\"
8214521070a0Smrg	    else
8215b0a0317aSmrg	      soname=$realname
8216521070a0Smrg	    fi
8217521070a0Smrg
8218521070a0Smrg	    # Make a new name for the extract_expsyms_cmds to use
8219b0a0317aSmrg	    soroot=$soname
8220521070a0Smrg	    func_basename "$soroot"
8221b0a0317aSmrg	    soname=$func_basename_result
8222521070a0Smrg	    func_stripname 'lib' '.dll' "$soname"
8223521070a0Smrg	    newlib=libimp-$func_stripname_result.a
8224521070a0Smrg
8225521070a0Smrg	    # If the library has no export list, then create one now
8226521070a0Smrg	    if test -f "$output_objdir/$soname-def"; then :
8227521070a0Smrg	    else
8228b0a0317aSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8229521070a0Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8230521070a0Smrg	    fi
8231521070a0Smrg
8232521070a0Smrg	    # Create $newlib
8233521070a0Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8234b0a0317aSmrg	      func_verbose "generating import library for '$soname'"
8235521070a0Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8236521070a0Smrg	    fi
8237521070a0Smrg	    # make sure the library variables are pointing to the new library
8238521070a0Smrg	    dir=$output_objdir
8239521070a0Smrg	    linklib=$newlib
8240521070a0Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8241521070a0Smrg
8242b0a0317aSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8243521070a0Smrg	    add_shlibpath=
8244521070a0Smrg	    add_dir=
8245521070a0Smrg	    add=
8246521070a0Smrg	    lib_linked=yes
8247521070a0Smrg	    case $hardcode_action in
8248521070a0Smrg	    immediate | unsupported)
8249b0a0317aSmrg	      if test no = "$hardcode_direct"; then
8250b0a0317aSmrg		add=$dir/$linklib
8251521070a0Smrg		case $host in
8252b0a0317aSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8253b0a0317aSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8254521070a0Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8255b0a0317aSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8256521070a0Smrg		  *-*-darwin* )
8257b0a0317aSmrg		    # if the lib is a (non-dlopened) module then we cannot
8258521070a0Smrg		    # link against it, someone is ignoring the earlier warnings
8259521070a0Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8260b0a0317aSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8261521070a0Smrg		      if test "X$dlopenmodule" != "X$lib"; then
8262521070a0Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8263b0a0317aSmrg			if test -z "$old_library"; then
8264ff63a143Smrg			  echo
8265ff63a143Smrg			  echo "*** And there doesn't seem to be a static archive available"
8266ff63a143Smrg			  echo "*** The link will probably fail, sorry"
8267521070a0Smrg			else
8268b0a0317aSmrg			  add=$dir/$old_library
8269521070a0Smrg			fi
8270521070a0Smrg		      elif test -n "$old_library"; then
8271b0a0317aSmrg			add=$dir/$old_library
8272521070a0Smrg		      fi
8273521070a0Smrg		    fi
8274521070a0Smrg		esac
8275b0a0317aSmrg	      elif test no = "$hardcode_minus_L"; then
8276521070a0Smrg		case $host in
8277b0a0317aSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8278521070a0Smrg		esac
8279b0a0317aSmrg		add_dir=-L$dir
8280b0a0317aSmrg		add=-l$name
8281b0a0317aSmrg	      elif test no = "$hardcode_shlibpath_var"; then
8282b0a0317aSmrg		add_shlibpath=$dir
8283b0a0317aSmrg		add=-l$name
8284521070a0Smrg	      else
8285521070a0Smrg		lib_linked=no
8286521070a0Smrg	      fi
8287521070a0Smrg	      ;;
8288521070a0Smrg	    relink)
8289b0a0317aSmrg	      if test yes = "$hardcode_direct" &&
8290b0a0317aSmrg	         test no = "$hardcode_direct_absolute"; then
8291b0a0317aSmrg		add=$dir/$linklib
8292b0a0317aSmrg	      elif test yes = "$hardcode_minus_L"; then
8293b0a0317aSmrg		add_dir=-L$absdir
8294521070a0Smrg		# Try looking first in the location we're being installed to.
8295521070a0Smrg		if test -n "$inst_prefix_dir"; then
8296521070a0Smrg		  case $libdir in
8297521070a0Smrg		    [\\/]*)
82983e6c936aSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8299521070a0Smrg		      ;;
8300521070a0Smrg		  esac
8301521070a0Smrg		fi
8302b0a0317aSmrg		add=-l$name
8303b0a0317aSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
8304b0a0317aSmrg		add_shlibpath=$dir
8305b0a0317aSmrg		add=-l$name
8306521070a0Smrg	      else
8307521070a0Smrg		lib_linked=no
8308521070a0Smrg	      fi
8309521070a0Smrg	      ;;
8310521070a0Smrg	    *) lib_linked=no ;;
8311521070a0Smrg	    esac
8312521070a0Smrg
8313b0a0317aSmrg	    if test yes != "$lib_linked"; then
8314521070a0Smrg	      func_fatal_configuration "unsupported hardcode properties"
8315521070a0Smrg	    fi
8316521070a0Smrg
8317521070a0Smrg	    if test -n "$add_shlibpath"; then
8318521070a0Smrg	      case :$compile_shlibpath: in
8319521070a0Smrg	      *":$add_shlibpath:"*) ;;
83203e6c936aSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8321521070a0Smrg	      esac
8322521070a0Smrg	    fi
8323b0a0317aSmrg	    if test prog = "$linkmode"; then
8324521070a0Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8325521070a0Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8326521070a0Smrg	    else
8327521070a0Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8328521070a0Smrg	      test -n "$add" && deplibs="$add $deplibs"
8329b0a0317aSmrg	      if test yes != "$hardcode_direct" &&
8330b0a0317aSmrg		 test yes != "$hardcode_minus_L" &&
8331b0a0317aSmrg		 test yes = "$hardcode_shlibpath_var"; then
8332521070a0Smrg		case :$finalize_shlibpath: in
8333521070a0Smrg		*":$libdir:"*) ;;
83343e6c936aSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
8335521070a0Smrg		esac
8336521070a0Smrg	      fi
8337521070a0Smrg	    fi
8338521070a0Smrg	  fi
8339521070a0Smrg
8340b0a0317aSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8341521070a0Smrg	    add_shlibpath=
8342521070a0Smrg	    add_dir=
8343521070a0Smrg	    add=
8344521070a0Smrg	    # Finalize command for both is simple: just hardcode it.
8345b0a0317aSmrg	    if test yes = "$hardcode_direct" &&
8346b0a0317aSmrg	       test no = "$hardcode_direct_absolute"; then
8347b0a0317aSmrg	      add=$libdir/$linklib
8348b0a0317aSmrg	    elif test yes = "$hardcode_minus_L"; then
8349b0a0317aSmrg	      add_dir=-L$libdir
8350b0a0317aSmrg	      add=-l$name
8351b0a0317aSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8352521070a0Smrg	      case :$finalize_shlibpath: in
8353521070a0Smrg	      *":$libdir:"*) ;;
83543e6c936aSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8355521070a0Smrg	      esac
8356b0a0317aSmrg	      add=-l$name
8357b0a0317aSmrg	    elif test yes = "$hardcode_automatic"; then
8358521070a0Smrg	      if test -n "$inst_prefix_dir" &&
8359b0a0317aSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8360b0a0317aSmrg		add=$inst_prefix_dir$libdir/$linklib
8361521070a0Smrg	      else
8362b0a0317aSmrg		add=$libdir/$linklib
8363521070a0Smrg	      fi
8364521070a0Smrg	    else
8365521070a0Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8366b0a0317aSmrg	      add_dir=-L$libdir
8367521070a0Smrg	      # Try looking first in the location we're being installed to.
8368521070a0Smrg	      if test -n "$inst_prefix_dir"; then
8369521070a0Smrg		case $libdir in
8370521070a0Smrg		  [\\/]*)
83713e6c936aSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8372521070a0Smrg		    ;;
8373521070a0Smrg		esac
8374521070a0Smrg	      fi
8375b0a0317aSmrg	      add=-l$name
8376521070a0Smrg	    fi
8377521070a0Smrg
8378b0a0317aSmrg	    if test prog = "$linkmode"; then
8379521070a0Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8380521070a0Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8381521070a0Smrg	    else
8382521070a0Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8383521070a0Smrg	      test -n "$add" && deplibs="$add $deplibs"
8384521070a0Smrg	    fi
8385521070a0Smrg	  fi
8386b0a0317aSmrg	elif test prog = "$linkmode"; then
8387521070a0Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8388521070a0Smrg	  # is not unsupported.  This is valid on all known static and
8389521070a0Smrg	  # shared platforms.
8390b0a0317aSmrg	  if test unsupported != "$hardcode_direct"; then
8391b0a0317aSmrg	    test -n "$old_library" && linklib=$old_library
8392521070a0Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8393521070a0Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8394521070a0Smrg	  else
8395521070a0Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8396521070a0Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8397521070a0Smrg	  fi
8398b0a0317aSmrg	elif test yes = "$build_libtool_libs"; then
8399521070a0Smrg	  # Not a shared library
8400b0a0317aSmrg	  if test pass_all != "$deplibs_check_method"; then
8401521070a0Smrg	    # We're trying link a shared library against a static one
8402521070a0Smrg	    # but the system doesn't support it.
8403521070a0Smrg
8404521070a0Smrg	    # Just print a warning and add the library to dependency_libs so
8405521070a0Smrg	    # that the program can be linked against the static library.
8406ff63a143Smrg	    echo
8407b0a0317aSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8408ff63a143Smrg	    echo "*** I have the capability to make that library automatically link in when"
8409ff63a143Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
8410ff63a143Smrg	    echo "*** shared version of the library, which you do not appear to have."
8411b0a0317aSmrg	    if test yes = "$module"; then
8412ff63a143Smrg	      echo "*** But as you try to build a module library, libtool will still create "
8413ff63a143Smrg	      echo "*** a static module, that should work as long as the dlopening application"
8414ff63a143Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8415521070a0Smrg	      if test -z "$global_symbol_pipe"; then
8416ff63a143Smrg		echo
8417ff63a143Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8418b0a0317aSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8419ff63a143Smrg		echo "*** not find such a program.  So, this module is probably useless."
8420b0a0317aSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8421521070a0Smrg	      fi
8422b0a0317aSmrg	      if test no = "$build_old_libs"; then
8423521070a0Smrg		build_libtool_libs=module
8424521070a0Smrg		build_old_libs=yes
8425521070a0Smrg	      else
8426521070a0Smrg		build_libtool_libs=no
8427521070a0Smrg	      fi
8428521070a0Smrg	    fi
8429521070a0Smrg	  else
8430521070a0Smrg	    deplibs="$dir/$old_library $deplibs"
8431521070a0Smrg	    link_static=yes
8432521070a0Smrg	  fi
8433521070a0Smrg	fi # link shared/static library?
8434521070a0Smrg
8435b0a0317aSmrg	if test lib = "$linkmode"; then
8436521070a0Smrg	  if test -n "$dependency_libs" &&
8437b0a0317aSmrg	     { test yes != "$hardcode_into_libs" ||
8438b0a0317aSmrg	       test yes = "$build_old_libs" ||
8439b0a0317aSmrg	       test yes = "$link_static"; }; then
8440521070a0Smrg	    # Extract -R from dependency_libs
8441521070a0Smrg	    temp_deplibs=
8442521070a0Smrg	    for libdir in $dependency_libs; do
8443521070a0Smrg	      case $libdir in
8444521070a0Smrg	      -R*) func_stripname '-R' '' "$libdir"
8445521070a0Smrg	           temp_xrpath=$func_stripname_result
8446521070a0Smrg		   case " $xrpath " in
8447521070a0Smrg		   *" $temp_xrpath "*) ;;
84483e6c936aSmrg		   *) func_append xrpath " $temp_xrpath";;
8449521070a0Smrg		   esac;;
84503e6c936aSmrg	      *) func_append temp_deplibs " $libdir";;
8451521070a0Smrg	      esac
8452521070a0Smrg	    done
8453b0a0317aSmrg	    dependency_libs=$temp_deplibs
8454521070a0Smrg	  fi
8455521070a0Smrg
84563e6c936aSmrg	  func_append newlib_search_path " $absdir"
8457521070a0Smrg	  # Link against this library
8458b0a0317aSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8459521070a0Smrg	  # ... and its dependency_libs
8460521070a0Smrg	  tmp_libs=
8461521070a0Smrg	  for deplib in $dependency_libs; do
8462521070a0Smrg	    newdependency_libs="$deplib $newdependency_libs"
84633e6c936aSmrg	    case $deplib in
84643e6c936aSmrg              -L*) func_stripname '-L' '' "$deplib"
84653e6c936aSmrg                   func_resolve_sysroot "$func_stripname_result";;
84663e6c936aSmrg              *) func_resolve_sysroot "$deplib" ;;
84673e6c936aSmrg            esac
8468b0a0317aSmrg	    if $opt_preserve_dup_deps; then
8469521070a0Smrg	      case "$tmp_libs " in
84703e6c936aSmrg	      *" $func_resolve_sysroot_result "*)
84713e6c936aSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8472521070a0Smrg	      esac
8473521070a0Smrg	    fi
84743e6c936aSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8475521070a0Smrg	  done
8476521070a0Smrg
8477b0a0317aSmrg	  if test no != "$link_all_deplibs"; then
8478521070a0Smrg	    # Add the search paths of all dependency libraries
8479521070a0Smrg	    for deplib in $dependency_libs; do
8480ff63a143Smrg	      path=
8481521070a0Smrg	      case $deplib in
8482b0a0317aSmrg	      -L*) path=$deplib ;;
8483521070a0Smrg	      *.la)
84843e6c936aSmrg	        func_resolve_sysroot "$deplib"
84853e6c936aSmrg	        deplib=$func_resolve_sysroot_result
8486521070a0Smrg	        func_dirname "$deplib" "" "."
84873e6c936aSmrg		dir=$func_dirname_result
8488521070a0Smrg		# We need an absolute path.
8489521070a0Smrg		case $dir in
8490b0a0317aSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8491521070a0Smrg		*)
8492521070a0Smrg		  absdir=`cd "$dir" && pwd`
8493521070a0Smrg		  if test -z "$absdir"; then
8494b0a0317aSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
8495b0a0317aSmrg		    absdir=$dir
8496521070a0Smrg		  fi
8497521070a0Smrg		  ;;
8498521070a0Smrg		esac
8499521070a0Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
8500521070a0Smrg		case $host in
8501521070a0Smrg		*-*-darwin*)
8502521070a0Smrg		  depdepl=
8503b0a0317aSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8504b0a0317aSmrg		  if test -n "$deplibrary_names"; then
8505b0a0317aSmrg		    for tmp in $deplibrary_names; do
8506521070a0Smrg		      depdepl=$tmp
8507521070a0Smrg		    done
8508b0a0317aSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
8509b0a0317aSmrg		      depdepl=$absdir/$objdir/$depdepl
8510b0a0317aSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8511521070a0Smrg                      if test -z "$darwin_install_name"; then
8512b0a0317aSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8513521070a0Smrg                      fi
8514b0a0317aSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8515b0a0317aSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8516521070a0Smrg		      path=
8517521070a0Smrg		    fi
8518521070a0Smrg		  fi
8519521070a0Smrg		  ;;
8520521070a0Smrg		*)
8521b0a0317aSmrg		  path=-L$absdir/$objdir
8522521070a0Smrg		  ;;
8523521070a0Smrg		esac
8524521070a0Smrg		else
8525b0a0317aSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8526521070a0Smrg		  test -z "$libdir" && \
8527b0a0317aSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8528521070a0Smrg		  test "$absdir" != "$libdir" && \
8529b0a0317aSmrg		    func_warning "'$deplib' seems to be moved"
8530521070a0Smrg
8531b0a0317aSmrg		  path=-L$absdir
8532521070a0Smrg		fi
8533521070a0Smrg		;;
8534521070a0Smrg	      esac
8535521070a0Smrg	      case " $deplibs " in
8536521070a0Smrg	      *" $path "*) ;;
8537521070a0Smrg	      *) deplibs="$path $deplibs" ;;
8538521070a0Smrg	      esac
8539521070a0Smrg	    done
8540521070a0Smrg	  fi # link_all_deplibs != no
8541521070a0Smrg	fi # linkmode = lib
8542521070a0Smrg      done # for deplib in $libs
8543b0a0317aSmrg      if test link = "$pass"; then
8544b0a0317aSmrg	if test prog = "$linkmode"; then
8545521070a0Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8546521070a0Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8547521070a0Smrg	else
8548ff63a143Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8549521070a0Smrg	fi
8550521070a0Smrg      fi
8551b0a0317aSmrg      dependency_libs=$newdependency_libs
8552b0a0317aSmrg      if test dlpreopen = "$pass"; then
8553521070a0Smrg	# Link the dlpreopened libraries before other libraries
8554521070a0Smrg	for deplib in $save_deplibs; do
8555521070a0Smrg	  deplibs="$deplib $deplibs"
8556521070a0Smrg	done
8557521070a0Smrg      fi
8558b0a0317aSmrg      if test dlopen != "$pass"; then
8559b0a0317aSmrg	test conv = "$pass" || {
8560521070a0Smrg	  # Make sure lib_search_path contains only unique directories.
8561521070a0Smrg	  lib_search_path=
8562521070a0Smrg	  for dir in $newlib_search_path; do
8563521070a0Smrg	    case "$lib_search_path " in
8564521070a0Smrg	    *" $dir "*) ;;
85653e6c936aSmrg	    *) func_append lib_search_path " $dir" ;;
8566521070a0Smrg	    esac
8567521070a0Smrg	  done
8568521070a0Smrg	  newlib_search_path=
8569b0a0317aSmrg	}
8570521070a0Smrg
8571b0a0317aSmrg	if test prog,link = "$linkmode,$pass"; then
8572521070a0Smrg	  vars="compile_deplibs finalize_deplibs"
8573b0a0317aSmrg	else
8574b0a0317aSmrg	  vars=deplibs
8575521070a0Smrg	fi
8576521070a0Smrg	for var in $vars dependency_libs; do
8577521070a0Smrg	  # Add libraries to $var in reverse order
8578521070a0Smrg	  eval tmp_libs=\"\$$var\"
8579521070a0Smrg	  new_libs=
8580521070a0Smrg	  for deplib in $tmp_libs; do
8581521070a0Smrg	    # FIXME: Pedantically, this is the right thing to do, so
8582521070a0Smrg	    #        that some nasty dependency loop isn't accidentally
8583521070a0Smrg	    #        broken:
8584521070a0Smrg	    #new_libs="$deplib $new_libs"
8585521070a0Smrg	    # Pragmatically, this seems to cause very few problems in
8586521070a0Smrg	    # practice:
8587521070a0Smrg	    case $deplib in
8588521070a0Smrg	    -L*) new_libs="$deplib $new_libs" ;;
8589521070a0Smrg	    -R*) ;;
8590521070a0Smrg	    *)
8591521070a0Smrg	      # And here is the reason: when a library appears more
8592521070a0Smrg	      # than once as an explicit dependence of a library, or
8593521070a0Smrg	      # is implicitly linked in more than once by the
8594521070a0Smrg	      # compiler, it is considered special, and multiple
8595521070a0Smrg	      # occurrences thereof are not removed.  Compare this
8596521070a0Smrg	      # with having the same library being listed as a
8597521070a0Smrg	      # dependency of multiple other libraries: in this case,
8598521070a0Smrg	      # we know (pedantically, we assume) the library does not
8599521070a0Smrg	      # need to be listed more than once, so we keep only the
8600521070a0Smrg	      # last copy.  This is not always right, but it is rare
8601521070a0Smrg	      # enough that we require users that really mean to play
8602521070a0Smrg	      # such unportable linking tricks to link the library
8603521070a0Smrg	      # using -Wl,-lname, so that libtool does not consider it
8604521070a0Smrg	      # for duplicate removal.
8605521070a0Smrg	      case " $specialdeplibs " in
8606521070a0Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8607521070a0Smrg	      *)
8608521070a0Smrg		case " $new_libs " in
8609521070a0Smrg		*" $deplib "*) ;;
8610521070a0Smrg		*) new_libs="$deplib $new_libs" ;;
8611521070a0Smrg		esac
8612521070a0Smrg		;;
8613521070a0Smrg	      esac
8614521070a0Smrg	      ;;
8615521070a0Smrg	    esac
8616521070a0Smrg	  done
8617521070a0Smrg	  tmp_libs=
8618521070a0Smrg	  for deplib in $new_libs; do
8619521070a0Smrg	    case $deplib in
8620521070a0Smrg	    -L*)
8621521070a0Smrg	      case " $tmp_libs " in
8622521070a0Smrg	      *" $deplib "*) ;;
86233e6c936aSmrg	      *) func_append tmp_libs " $deplib" ;;
8624521070a0Smrg	      esac
8625521070a0Smrg	      ;;
86263e6c936aSmrg	    *) func_append tmp_libs " $deplib" ;;
8627521070a0Smrg	    esac
8628521070a0Smrg	  done
8629521070a0Smrg	  eval $var=\"$tmp_libs\"
8630521070a0Smrg	done # for var
8631521070a0Smrg      fi
8632b0a0317aSmrg
8633b0a0317aSmrg      # Add Sun CC postdeps if required:
8634b0a0317aSmrg      test CXX = "$tagname" && {
8635b0a0317aSmrg        case $host_os in
8636b0a0317aSmrg        linux*)
8637b0a0317aSmrg          case `$CC -V 2>&1 | sed 5q` in
8638b0a0317aSmrg          *Sun\ C*) # Sun C++ 5.9
8639b0a0317aSmrg            func_suncc_cstd_abi
8640b0a0317aSmrg
8641b0a0317aSmrg            if test no != "$suncc_use_cstd_abi"; then
8642b0a0317aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8643b0a0317aSmrg            fi
8644b0a0317aSmrg            ;;
8645b0a0317aSmrg          esac
8646b0a0317aSmrg          ;;
8647b0a0317aSmrg
8648b0a0317aSmrg        solaris*)
8649b0a0317aSmrg          func_cc_basename "$CC"
8650b0a0317aSmrg          case $func_cc_basename_result in
8651b0a0317aSmrg          CC* | sunCC*)
8652b0a0317aSmrg            func_suncc_cstd_abi
8653b0a0317aSmrg
8654b0a0317aSmrg            if test no != "$suncc_use_cstd_abi"; then
8655b0a0317aSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8656b0a0317aSmrg            fi
8657b0a0317aSmrg            ;;
8658b0a0317aSmrg          esac
8659b0a0317aSmrg          ;;
8660b0a0317aSmrg        esac
8661b0a0317aSmrg      }
8662b0a0317aSmrg
8663521070a0Smrg      # Last step: remove runtime libs from dependency_libs
8664521070a0Smrg      # (they stay in deplibs)
8665521070a0Smrg      tmp_libs=
8666b0a0317aSmrg      for i in $dependency_libs; do
8667521070a0Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
8668521070a0Smrg	*" $i "*)
8669b0a0317aSmrg	  i=
8670521070a0Smrg	  ;;
8671521070a0Smrg	esac
8672b0a0317aSmrg	if test -n "$i"; then
86733e6c936aSmrg	  func_append tmp_libs " $i"
8674521070a0Smrg	fi
8675521070a0Smrg      done
8676521070a0Smrg      dependency_libs=$tmp_libs
8677521070a0Smrg    done # for pass
8678b0a0317aSmrg    if test prog = "$linkmode"; then
8679b0a0317aSmrg      dlfiles=$newdlfiles
8680521070a0Smrg    fi
8681b0a0317aSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8682b0a0317aSmrg      dlprefiles=$newdlprefiles
8683521070a0Smrg    fi
8684521070a0Smrg
8685521070a0Smrg    case $linkmode in
8686521070a0Smrg    oldlib)
8687b0a0317aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8688b0a0317aSmrg	func_warning "'-dlopen' is ignored for archives"
8689521070a0Smrg      fi
8690521070a0Smrg
8691521070a0Smrg      case " $deplibs" in
8692521070a0Smrg      *\ -l* | *\ -L*)
8693b0a0317aSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8694521070a0Smrg      esac
8695521070a0Smrg
8696521070a0Smrg      test -n "$rpath" && \
8697b0a0317aSmrg	func_warning "'-rpath' is ignored for archives"
8698521070a0Smrg
8699521070a0Smrg      test -n "$xrpath" && \
8700b0a0317aSmrg	func_warning "'-R' is ignored for archives"
8701521070a0Smrg
8702521070a0Smrg      test -n "$vinfo" && \
8703b0a0317aSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
8704521070a0Smrg
8705521070a0Smrg      test -n "$release" && \
8706b0a0317aSmrg	func_warning "'-release' is ignored for archives"
8707521070a0Smrg
8708521070a0Smrg      test -n "$export_symbols$export_symbols_regex" && \
8709b0a0317aSmrg	func_warning "'-export-symbols' is ignored for archives"
8710521070a0Smrg
8711521070a0Smrg      # Now set the variables for building old libraries.
8712521070a0Smrg      build_libtool_libs=no
8713b0a0317aSmrg      oldlibs=$output
87143e6c936aSmrg      func_append objs "$old_deplibs"
8715521070a0Smrg      ;;
8716521070a0Smrg
8717521070a0Smrg    lib)
8718b0a0317aSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
8719521070a0Smrg      case $outputname in
8720521070a0Smrg      lib*)
8721521070a0Smrg	func_stripname 'lib' '.la' "$outputname"
8722521070a0Smrg	name=$func_stripname_result
8723521070a0Smrg	eval shared_ext=\"$shrext_cmds\"
8724521070a0Smrg	eval libname=\"$libname_spec\"
8725521070a0Smrg	;;
8726521070a0Smrg      *)
8727b0a0317aSmrg	test no = "$module" \
8728b0a0317aSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
8729521070a0Smrg
8730b0a0317aSmrg	if test no != "$need_lib_prefix"; then
8731521070a0Smrg	  # Add the "lib" prefix for modules if required
8732521070a0Smrg	  func_stripname '' '.la' "$outputname"
8733521070a0Smrg	  name=$func_stripname_result
8734521070a0Smrg	  eval shared_ext=\"$shrext_cmds\"
8735521070a0Smrg	  eval libname=\"$libname_spec\"
8736521070a0Smrg	else
8737521070a0Smrg	  func_stripname '' '.la' "$outputname"
8738521070a0Smrg	  libname=$func_stripname_result
8739521070a0Smrg	fi
8740521070a0Smrg	;;
8741521070a0Smrg      esac
8742521070a0Smrg
8743521070a0Smrg      if test -n "$objs"; then
8744b0a0317aSmrg	if test pass_all != "$deplibs_check_method"; then
8745b0a0317aSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
8746521070a0Smrg	else
8747ff63a143Smrg	  echo
8748521070a0Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
8749521070a0Smrg	  $ECHO "*** objects $objs is not portable!"
87503e6c936aSmrg	  func_append libobjs " $objs"
8751521070a0Smrg	fi
8752521070a0Smrg      fi
8753521070a0Smrg
8754b0a0317aSmrg      test no = "$dlself" \
8755b0a0317aSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
8756521070a0Smrg
8757521070a0Smrg      set dummy $rpath
8758521070a0Smrg      shift
8759b0a0317aSmrg      test 1 -lt "$#" \
8760b0a0317aSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
8761521070a0Smrg
8762b0a0317aSmrg      install_libdir=$1
8763521070a0Smrg
8764521070a0Smrg      oldlibs=
8765521070a0Smrg      if test -z "$rpath"; then
8766b0a0317aSmrg	if test yes = "$build_libtool_libs"; then
8767521070a0Smrg	  # Building a libtool convenience library.
8768b0a0317aSmrg	  # Some compilers have problems with a '.al' extension so
8769521070a0Smrg	  # convenience libraries should have the same extension an
8770521070a0Smrg	  # archive normally would.
8771521070a0Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
8772521070a0Smrg	  build_libtool_libs=convenience
8773521070a0Smrg	  build_old_libs=yes
8774521070a0Smrg	fi
8775521070a0Smrg
8776521070a0Smrg	test -n "$vinfo" && \
8777b0a0317aSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
8778521070a0Smrg
8779521070a0Smrg	test -n "$release" && \
8780b0a0317aSmrg	  func_warning "'-release' is ignored for convenience libraries"
8781521070a0Smrg      else
8782521070a0Smrg
8783521070a0Smrg	# Parse the version information argument.
8784b0a0317aSmrg	save_ifs=$IFS; IFS=:
8785521070a0Smrg	set dummy $vinfo 0 0 0
8786521070a0Smrg	shift
8787b0a0317aSmrg	IFS=$save_ifs
8788521070a0Smrg
8789521070a0Smrg	test -n "$7" && \
8790b0a0317aSmrg	  func_fatal_help "too many parameters to '-version-info'"
8791521070a0Smrg
8792521070a0Smrg	# convert absolute version numbers to libtool ages
8793521070a0Smrg	# this retains compatibility with .la files and attempts
8794521070a0Smrg	# to make the code below a bit more comprehensible
8795521070a0Smrg
8796521070a0Smrg	case $vinfo_number in
8797521070a0Smrg	yes)
8798b0a0317aSmrg	  number_major=$1
8799b0a0317aSmrg	  number_minor=$2
8800b0a0317aSmrg	  number_revision=$3
8801521070a0Smrg	  #
8802521070a0Smrg	  # There are really only two kinds -- those that
8803521070a0Smrg	  # use the current revision as the major version
8804521070a0Smrg	  # and those that subtract age and use age as
8805521070a0Smrg	  # a minor version.  But, then there is irix
8806b0a0317aSmrg	  # that has an extra 1 added just for fun
8807521070a0Smrg	  #
8808521070a0Smrg	  case $version_type in
88093e6c936aSmrg	  # correct linux to gnu/linux during the next big refactor
8810b0a0317aSmrg	  darwin|freebsd-elf|linux|osf|windows|none)
8811521070a0Smrg	    func_arith $number_major + $number_minor
8812521070a0Smrg	    current=$func_arith_result
8813b0a0317aSmrg	    age=$number_minor
8814b0a0317aSmrg	    revision=$number_revision
8815521070a0Smrg	    ;;
8816b0a0317aSmrg	  freebsd-aout|qnx|sunos)
8817b0a0317aSmrg	    current=$number_major
8818b0a0317aSmrg	    revision=$number_minor
8819b0a0317aSmrg	    age=0
8820521070a0Smrg	    ;;
8821521070a0Smrg	  irix|nonstopux)
8822521070a0Smrg	    func_arith $number_major + $number_minor
8823521070a0Smrg	    current=$func_arith_result
8824b0a0317aSmrg	    age=$number_minor
8825b0a0317aSmrg	    revision=$number_minor
8826521070a0Smrg	    lt_irix_increment=no
8827521070a0Smrg	    ;;
8828521070a0Smrg	  esac
8829521070a0Smrg	  ;;
8830521070a0Smrg	no)
8831b0a0317aSmrg	  current=$1
8832b0a0317aSmrg	  revision=$2
8833b0a0317aSmrg	  age=$3
8834521070a0Smrg	  ;;
8835521070a0Smrg	esac
8836521070a0Smrg
8837521070a0Smrg	# Check that each of the things are valid numbers.
8838521070a0Smrg	case $current in
8839521070a0Smrg	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]) ;;
8840521070a0Smrg	*)
8841b0a0317aSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
8842b0a0317aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
8843521070a0Smrg	  ;;
8844521070a0Smrg	esac
8845521070a0Smrg
8846521070a0Smrg	case $revision in
8847521070a0Smrg	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]) ;;
8848521070a0Smrg	*)
8849b0a0317aSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
8850b0a0317aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
8851521070a0Smrg	  ;;
8852521070a0Smrg	esac
8853521070a0Smrg
8854521070a0Smrg	case $age in
8855521070a0Smrg	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]) ;;
8856521070a0Smrg	*)
8857b0a0317aSmrg	  func_error "AGE '$age' must be a nonnegative integer"
8858b0a0317aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
8859521070a0Smrg	  ;;
8860521070a0Smrg	esac
8861521070a0Smrg
8862521070a0Smrg	if test "$age" -gt "$current"; then
8863b0a0317aSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
8864b0a0317aSmrg	  func_fatal_error "'$vinfo' is not valid version information"
8865521070a0Smrg	fi
8866521070a0Smrg
8867521070a0Smrg	# Calculate the version variables.
8868521070a0Smrg	major=
8869521070a0Smrg	versuffix=
8870521070a0Smrg	verstring=
8871521070a0Smrg	case $version_type in
8872521070a0Smrg	none) ;;
8873521070a0Smrg
8874521070a0Smrg	darwin)
8875521070a0Smrg	  # Like Linux, but with the current version available in
8876521070a0Smrg	  # verstring for coding it into the library header
8877521070a0Smrg	  func_arith $current - $age
8878521070a0Smrg	  major=.$func_arith_result
8879b0a0317aSmrg	  versuffix=$major.$age.$revision
8880521070a0Smrg	  # Darwin ld doesn't like 0 for these options...
8881521070a0Smrg	  func_arith $current + 1
8882521070a0Smrg	  minor_current=$func_arith_result
8883b0a0317aSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8884521070a0Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8885b0a0317aSmrg          # On Darwin other compilers
8886b0a0317aSmrg          case $CC in
8887b0a0317aSmrg              nagfor*)
8888b0a0317aSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8889b0a0317aSmrg                  ;;
8890b0a0317aSmrg              *)
8891b0a0317aSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8892b0a0317aSmrg                  ;;
8893b0a0317aSmrg          esac
8894521070a0Smrg	  ;;
8895521070a0Smrg
8896521070a0Smrg	freebsd-aout)
8897b0a0317aSmrg	  major=.$current
8898b0a0317aSmrg	  versuffix=.$current.$revision
8899521070a0Smrg	  ;;
8900521070a0Smrg
8901521070a0Smrg	freebsd-elf)
8902b0a0317aSmrg	  func_arith $current - $age
8903b0a0317aSmrg	  major=.$func_arith_result
8904b0a0317aSmrg	  versuffix=$major.$age.$revision
8905521070a0Smrg	  ;;
8906521070a0Smrg
8907521070a0Smrg	irix | nonstopux)
8908b0a0317aSmrg	  if test no = "$lt_irix_increment"; then
8909521070a0Smrg	    func_arith $current - $age
8910521070a0Smrg	  else
8911521070a0Smrg	    func_arith $current - $age + 1
8912521070a0Smrg	  fi
8913521070a0Smrg	  major=$func_arith_result
8914521070a0Smrg
8915521070a0Smrg	  case $version_type in
8916521070a0Smrg	    nonstopux) verstring_prefix=nonstopux ;;
8917521070a0Smrg	    *)         verstring_prefix=sgi ;;
8918521070a0Smrg	  esac
8919b0a0317aSmrg	  verstring=$verstring_prefix$major.$revision
8920521070a0Smrg
8921521070a0Smrg	  # Add in all the interfaces that we are compatible with.
8922521070a0Smrg	  loop=$revision
8923b0a0317aSmrg	  while test 0 -ne "$loop"; do
8924521070a0Smrg	    func_arith $revision - $loop
8925521070a0Smrg	    iface=$func_arith_result
8926521070a0Smrg	    func_arith $loop - 1
8927521070a0Smrg	    loop=$func_arith_result
8928b0a0317aSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
8929521070a0Smrg	  done
8930521070a0Smrg
8931b0a0317aSmrg	  # Before this point, $major must not contain '.'.
8932521070a0Smrg	  major=.$major
8933b0a0317aSmrg	  versuffix=$major.$revision
8934521070a0Smrg	  ;;
8935521070a0Smrg
89363e6c936aSmrg	linux) # correct to gnu/linux during the next big refactor
8937521070a0Smrg	  func_arith $current - $age
8938521070a0Smrg	  major=.$func_arith_result
8939b0a0317aSmrg	  versuffix=$major.$age.$revision
8940521070a0Smrg	  ;;
8941521070a0Smrg
8942521070a0Smrg	osf)
8943521070a0Smrg	  func_arith $current - $age
8944521070a0Smrg	  major=.$func_arith_result
8945b0a0317aSmrg	  versuffix=.$current.$age.$revision
8946b0a0317aSmrg	  verstring=$current.$age.$revision
8947521070a0Smrg
8948521070a0Smrg	  # Add in all the interfaces that we are compatible with.
8949521070a0Smrg	  loop=$age
8950b0a0317aSmrg	  while test 0 -ne "$loop"; do
8951521070a0Smrg	    func_arith $current - $loop
8952521070a0Smrg	    iface=$func_arith_result
8953521070a0Smrg	    func_arith $loop - 1
8954521070a0Smrg	    loop=$func_arith_result
8955b0a0317aSmrg	    verstring=$verstring:$iface.0
8956521070a0Smrg	  done
8957521070a0Smrg
8958521070a0Smrg	  # Make executables depend on our current version.
8959b0a0317aSmrg	  func_append verstring ":$current.0"
8960521070a0Smrg	  ;;
8961521070a0Smrg
8962521070a0Smrg	qnx)
8963b0a0317aSmrg	  major=.$current
8964b0a0317aSmrg	  versuffix=.$current
8965b0a0317aSmrg	  ;;
8966b0a0317aSmrg
8967b0a0317aSmrg	sco)
8968b0a0317aSmrg	  major=.$current
8969b0a0317aSmrg	  versuffix=.$current
8970521070a0Smrg	  ;;
8971521070a0Smrg
8972521070a0Smrg	sunos)
8973b0a0317aSmrg	  major=.$current
8974b0a0317aSmrg	  versuffix=.$current.$revision
8975521070a0Smrg	  ;;
8976521070a0Smrg
8977521070a0Smrg	windows)
8978521070a0Smrg	  # Use '-' rather than '.', since we only want one
8979b0a0317aSmrg	  # extension on DOS 8.3 file systems.
8980521070a0Smrg	  func_arith $current - $age
8981521070a0Smrg	  major=$func_arith_result
8982b0a0317aSmrg	  versuffix=-$major
8983521070a0Smrg	  ;;
8984521070a0Smrg
8985521070a0Smrg	*)
8986b0a0317aSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
8987521070a0Smrg	  ;;
8988521070a0Smrg	esac
8989521070a0Smrg
8990521070a0Smrg	# Clear the version info if we defaulted, and they specified a release.
8991521070a0Smrg	if test -z "$vinfo" && test -n "$release"; then
8992521070a0Smrg	  major=
8993521070a0Smrg	  case $version_type in
8994521070a0Smrg	  darwin)
8995521070a0Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
8996521070a0Smrg	    # problems, so we reset it completely
8997521070a0Smrg	    verstring=
8998521070a0Smrg	    ;;
8999521070a0Smrg	  *)
9000b0a0317aSmrg	    verstring=0.0
9001521070a0Smrg	    ;;
9002521070a0Smrg	  esac
9003b0a0317aSmrg	  if test no = "$need_version"; then
9004521070a0Smrg	    versuffix=
9005521070a0Smrg	  else
9006b0a0317aSmrg	    versuffix=.0.0
9007521070a0Smrg	  fi
9008521070a0Smrg	fi
9009521070a0Smrg
9010521070a0Smrg	# Remove version info from name if versioning should be avoided
9011b0a0317aSmrg	if test yes,no = "$avoid_version,$need_version"; then
9012521070a0Smrg	  major=
9013521070a0Smrg	  versuffix=
9014b0a0317aSmrg	  verstring=
9015521070a0Smrg	fi
9016521070a0Smrg
9017521070a0Smrg	# Check to see if the archive will have undefined symbols.
9018b0a0317aSmrg	if test yes = "$allow_undefined"; then
9019b0a0317aSmrg	  if test unsupported = "$allow_undefined_flag"; then
9020b0a0317aSmrg	    if test yes = "$build_old_libs"; then
9021b0a0317aSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9022b0a0317aSmrg	      build_libtool_libs=no
9023b0a0317aSmrg	    else
9024b0a0317aSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9025b0a0317aSmrg	    fi
9026521070a0Smrg	  fi
9027521070a0Smrg	else
9028521070a0Smrg	  # Don't allow undefined symbols.
9029b0a0317aSmrg	  allow_undefined_flag=$no_undefined_flag
9030521070a0Smrg	fi
9031521070a0Smrg
9032521070a0Smrg      fi
9033521070a0Smrg
9034b0a0317aSmrg      func_generate_dlsyms "$libname" "$libname" :
90353e6c936aSmrg      func_append libobjs " $symfileobj"
9036b0a0317aSmrg      test " " = "$libobjs" && libobjs=
9037521070a0Smrg
9038b0a0317aSmrg      if test relink != "$opt_mode"; then
9039521070a0Smrg	# Remove our outputs, but don't remove object files since they
9040521070a0Smrg	# may have been created when compiling PIC objects.
9041521070a0Smrg	removelist=
9042521070a0Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
9043521070a0Smrg	for p in $tempremovelist; do
9044521070a0Smrg	  case $p in
9045521070a0Smrg	    *.$objext | *.gcno)
9046521070a0Smrg	       ;;
9047b0a0317aSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9048b0a0317aSmrg	       if test -n "$precious_files_regex"; then
9049521070a0Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9050521070a0Smrg		 then
9051521070a0Smrg		   continue
9052521070a0Smrg		 fi
9053521070a0Smrg	       fi
90543e6c936aSmrg	       func_append removelist " $p"
9055521070a0Smrg	       ;;
9056521070a0Smrg	    *) ;;
9057521070a0Smrg	  esac
9058521070a0Smrg	done
9059521070a0Smrg	test -n "$removelist" && \
9060521070a0Smrg	  func_show_eval "${RM}r \$removelist"
9061521070a0Smrg      fi
9062521070a0Smrg
9063521070a0Smrg      # Now set the variables for building old libraries.
9064b0a0317aSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
90653e6c936aSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
9066521070a0Smrg
9067521070a0Smrg	# Transform .lo files to .o files.
9068b0a0317aSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9069521070a0Smrg      fi
9070521070a0Smrg
9071521070a0Smrg      # Eliminate all temporary directories.
9072521070a0Smrg      #for path in $notinst_path; do
9073ff63a143Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9074ff63a143Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9075ff63a143Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9076521070a0Smrg      #done
9077521070a0Smrg
9078521070a0Smrg      if test -n "$xrpath"; then
9079521070a0Smrg	# If the user specified any rpath flags, then add them.
9080521070a0Smrg	temp_xrpath=
9081521070a0Smrg	for libdir in $xrpath; do
90823e6c936aSmrg	  func_replace_sysroot "$libdir"
90833e6c936aSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9084521070a0Smrg	  case "$finalize_rpath " in
9085521070a0Smrg	  *" $libdir "*) ;;
90863e6c936aSmrg	  *) func_append finalize_rpath " $libdir" ;;
9087521070a0Smrg	  esac
9088521070a0Smrg	done
9089b0a0317aSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9090521070a0Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
9091521070a0Smrg	fi
9092521070a0Smrg      fi
9093521070a0Smrg
9094521070a0Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9095b0a0317aSmrg      old_dlfiles=$dlfiles
9096521070a0Smrg      dlfiles=
9097521070a0Smrg      for lib in $old_dlfiles; do
9098521070a0Smrg	case " $dlprefiles $dlfiles " in
9099521070a0Smrg	*" $lib "*) ;;
91003e6c936aSmrg	*) func_append dlfiles " $lib" ;;
9101521070a0Smrg	esac
9102521070a0Smrg      done
9103521070a0Smrg
9104521070a0Smrg      # Make sure dlprefiles contains only unique files
9105b0a0317aSmrg      old_dlprefiles=$dlprefiles
9106521070a0Smrg      dlprefiles=
9107521070a0Smrg      for lib in $old_dlprefiles; do
9108521070a0Smrg	case "$dlprefiles " in
9109521070a0Smrg	*" $lib "*) ;;
91103e6c936aSmrg	*) func_append dlprefiles " $lib" ;;
9111521070a0Smrg	esac
9112521070a0Smrg      done
9113521070a0Smrg
9114b0a0317aSmrg      if test yes = "$build_libtool_libs"; then
9115521070a0Smrg	if test -n "$rpath"; then
9116521070a0Smrg	  case $host in
9117ff63a143Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9118521070a0Smrg	    # these systems don't actually have a c library (as such)!
9119521070a0Smrg	    ;;
9120521070a0Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
9121521070a0Smrg	    # Rhapsody C library is in the System framework
91223e6c936aSmrg	    func_append deplibs " System.ltframework"
9123521070a0Smrg	    ;;
9124521070a0Smrg	  *-*-netbsd*)
9125521070a0Smrg	    # Don't link with libc until the a.out ld.so is fixed.
9126521070a0Smrg	    ;;
9127521070a0Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
9128521070a0Smrg	    # Do not include libc due to us having libc/libc_r.
9129521070a0Smrg	    ;;
9130521070a0Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9131521070a0Smrg	    # Causes problems with __ctype
9132521070a0Smrg	    ;;
9133521070a0Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9134521070a0Smrg	    # Compiler inserts libc in the correct place for threads to work
9135521070a0Smrg	    ;;
9136521070a0Smrg	  *)
9137521070a0Smrg	    # Add libc to deplibs on all other systems if necessary.
9138b0a0317aSmrg	    if test yes = "$build_libtool_need_lc"; then
91393e6c936aSmrg	      func_append deplibs " -lc"
9140521070a0Smrg	    fi
9141521070a0Smrg	    ;;
9142521070a0Smrg	  esac
9143521070a0Smrg	fi
9144521070a0Smrg
9145521070a0Smrg	# Transform deplibs into only deplibs that can be linked in shared.
9146521070a0Smrg	name_save=$name
9147521070a0Smrg	libname_save=$libname
9148521070a0Smrg	release_save=$release
9149521070a0Smrg	versuffix_save=$versuffix
9150521070a0Smrg	major_save=$major
9151521070a0Smrg	# I'm not sure if I'm treating the release correctly.  I think
9152521070a0Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9153521070a0Smrg	# add it in twice.  Is that correct?
9154b0a0317aSmrg	release=
9155b0a0317aSmrg	versuffix=
9156b0a0317aSmrg	major=
9157521070a0Smrg	newdeplibs=
9158521070a0Smrg	droppeddeps=no
9159521070a0Smrg	case $deplibs_check_method in
9160521070a0Smrg	pass_all)
9161521070a0Smrg	  # Don't check for shared/static.  Everything works.
9162521070a0Smrg	  # This might be a little naive.  We might want to check
9163521070a0Smrg	  # whether the library exists or not.  But this is on
9164521070a0Smrg	  # osf3 & osf4 and I'm not really sure... Just
9165521070a0Smrg	  # implementing what was already the behavior.
9166521070a0Smrg	  newdeplibs=$deplibs
9167521070a0Smrg	  ;;
9168521070a0Smrg	test_compile)
9169521070a0Smrg	  # This code stresses the "libraries are programs" paradigm to its
9170521070a0Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9171521070a0Smrg	  # against the deplibs as a proxy for the library.  Then we can check
9172521070a0Smrg	  # whether they linked in statically or dynamically with ldd.
9173521070a0Smrg	  $opt_dry_run || $RM conftest.c
9174521070a0Smrg	  cat > conftest.c <<EOF
9175521070a0Smrg	  int main() { return 0; }
9176521070a0SmrgEOF
9177521070a0Smrg	  $opt_dry_run || $RM conftest
9178521070a0Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9179521070a0Smrg	    ldd_output=`ldd conftest`
9180521070a0Smrg	    for i in $deplibs; do
9181521070a0Smrg	      case $i in
9182521070a0Smrg	      -l*)
9183521070a0Smrg		func_stripname -l '' "$i"
9184521070a0Smrg		name=$func_stripname_result
9185b0a0317aSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9186521070a0Smrg		  case " $predeps $postdeps " in
9187521070a0Smrg		  *" $i "*)
91883e6c936aSmrg		    func_append newdeplibs " $i"
9189b0a0317aSmrg		    i=
9190521070a0Smrg		    ;;
9191521070a0Smrg		  esac
9192521070a0Smrg		fi
9193b0a0317aSmrg		if test -n "$i"; then
9194521070a0Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9195521070a0Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9196521070a0Smrg		  set dummy $deplib_matches; shift
9197521070a0Smrg		  deplib_match=$1
9198b0a0317aSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
91993e6c936aSmrg		    func_append newdeplibs " $i"
9200521070a0Smrg		  else
9201521070a0Smrg		    droppeddeps=yes
9202ff63a143Smrg		    echo
9203521070a0Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9204ff63a143Smrg		    echo "*** I have the capability to make that library automatically link in when"
9205ff63a143Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
9206ff63a143Smrg		    echo "*** shared version of the library, which I believe you do not have"
9207ff63a143Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9208ff63a143Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9209521070a0Smrg		  fi
9210521070a0Smrg		fi
9211521070a0Smrg		;;
9212521070a0Smrg	      *)
92133e6c936aSmrg		func_append newdeplibs " $i"
9214521070a0Smrg		;;
9215521070a0Smrg	      esac
9216521070a0Smrg	    done
9217521070a0Smrg	  else
9218521070a0Smrg	    # Error occurred in the first compile.  Let's try to salvage
9219521070a0Smrg	    # the situation: Compile a separate program for each library.
9220521070a0Smrg	    for i in $deplibs; do
9221521070a0Smrg	      case $i in
9222521070a0Smrg	      -l*)
9223521070a0Smrg		func_stripname -l '' "$i"
9224521070a0Smrg		name=$func_stripname_result
9225521070a0Smrg		$opt_dry_run || $RM conftest
9226521070a0Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9227521070a0Smrg		  ldd_output=`ldd conftest`
9228b0a0317aSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9229521070a0Smrg		    case " $predeps $postdeps " in
9230521070a0Smrg		    *" $i "*)
92313e6c936aSmrg		      func_append newdeplibs " $i"
9232b0a0317aSmrg		      i=
9233521070a0Smrg		      ;;
9234521070a0Smrg		    esac
9235521070a0Smrg		  fi
9236b0a0317aSmrg		  if test -n "$i"; then
9237521070a0Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9238521070a0Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9239521070a0Smrg		    set dummy $deplib_matches; shift
9240521070a0Smrg		    deplib_match=$1
9241b0a0317aSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
92423e6c936aSmrg		      func_append newdeplibs " $i"
9243521070a0Smrg		    else
9244521070a0Smrg		      droppeddeps=yes
9245ff63a143Smrg		      echo
9246521070a0Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9247ff63a143Smrg		      echo "*** I have the capability to make that library automatically link in when"
9248ff63a143Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
9249ff63a143Smrg		      echo "*** shared version of the library, which you do not appear to have"
9250ff63a143Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9251ff63a143Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9252521070a0Smrg		    fi
9253521070a0Smrg		  fi
9254521070a0Smrg		else
9255521070a0Smrg		  droppeddeps=yes
9256ff63a143Smrg		  echo
9257521070a0Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9258ff63a143Smrg		  echo "*** make it link in!  You will probably need to install it or some"
9259ff63a143Smrg		  echo "*** library that it depends on before this library will be fully"
9260ff63a143Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9261521070a0Smrg		fi
9262521070a0Smrg		;;
9263521070a0Smrg	      *)
92643e6c936aSmrg		func_append newdeplibs " $i"
9265521070a0Smrg		;;
9266521070a0Smrg	      esac
9267521070a0Smrg	    done
9268521070a0Smrg	  fi
9269521070a0Smrg	  ;;
9270521070a0Smrg	file_magic*)
9271521070a0Smrg	  set dummy $deplibs_check_method; shift
9272521070a0Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9273521070a0Smrg	  for a_deplib in $deplibs; do
9274521070a0Smrg	    case $a_deplib in
9275521070a0Smrg	    -l*)
9276521070a0Smrg	      func_stripname -l '' "$a_deplib"
9277521070a0Smrg	      name=$func_stripname_result
9278b0a0317aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9279521070a0Smrg		case " $predeps $postdeps " in
9280521070a0Smrg		*" $a_deplib "*)
92813e6c936aSmrg		  func_append newdeplibs " $a_deplib"
9282b0a0317aSmrg		  a_deplib=
9283521070a0Smrg		  ;;
9284521070a0Smrg		esac
9285521070a0Smrg	      fi
9286b0a0317aSmrg	      if test -n "$a_deplib"; then
9287521070a0Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
92883e6c936aSmrg		if test -n "$file_magic_glob"; then
92893e6c936aSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
92903e6c936aSmrg		else
92913e6c936aSmrg		  libnameglob=$libname
92923e6c936aSmrg		fi
9293b0a0317aSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9294521070a0Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9295b0a0317aSmrg		  if test yes = "$want_nocaseglob"; then
92963e6c936aSmrg		    shopt -s nocaseglob
92973e6c936aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
92983e6c936aSmrg		    $nocaseglob
92993e6c936aSmrg		  else
93003e6c936aSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
93013e6c936aSmrg		  fi
9302521070a0Smrg		  for potent_lib in $potential_libs; do
9303521070a0Smrg		      # Follow soft links.
9304521070a0Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9305521070a0Smrg			 $GREP " -> " >/dev/null; then
9306521070a0Smrg			continue
9307521070a0Smrg		      fi
9308521070a0Smrg		      # The statement above tries to avoid entering an
9309521070a0Smrg		      # endless loop below, in case of cyclic links.
9310521070a0Smrg		      # We might still enter an endless loop, since a link
9311521070a0Smrg		      # loop can be closed while we follow links,
9312521070a0Smrg		      # but so what?
9313b0a0317aSmrg		      potlib=$potent_lib
9314521070a0Smrg		      while test -h "$potlib" 2>/dev/null; do
9315b0a0317aSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9316521070a0Smrg			case $potliblink in
9317b0a0317aSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9318b0a0317aSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9319521070a0Smrg			esac
9320521070a0Smrg		      done
9321521070a0Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9322521070a0Smrg			 $SED -e 10q |
9323521070a0Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
93243e6c936aSmrg			func_append newdeplibs " $a_deplib"
9325b0a0317aSmrg			a_deplib=
9326521070a0Smrg			break 2
9327521070a0Smrg		      fi
9328521070a0Smrg		  done
9329521070a0Smrg		done
9330521070a0Smrg	      fi
9331b0a0317aSmrg	      if test -n "$a_deplib"; then
9332521070a0Smrg		droppeddeps=yes
9333ff63a143Smrg		echo
9334521070a0Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9335ff63a143Smrg		echo "*** I have the capability to make that library automatically link in when"
9336ff63a143Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9337ff63a143Smrg		echo "*** shared version of the library, which you do not appear to have"
9338ff63a143Smrg		echo "*** because I did check the linker path looking for a file starting"
9339b0a0317aSmrg		if test -z "$potlib"; then
9340521070a0Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9341521070a0Smrg		else
9342521070a0Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9343521070a0Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9344521070a0Smrg		fi
9345521070a0Smrg	      fi
9346521070a0Smrg	      ;;
9347521070a0Smrg	    *)
9348521070a0Smrg	      # Add a -L argument.
93493e6c936aSmrg	      func_append newdeplibs " $a_deplib"
9350521070a0Smrg	      ;;
9351521070a0Smrg	    esac
9352521070a0Smrg	  done # Gone through all deplibs.
9353521070a0Smrg	  ;;
9354521070a0Smrg	match_pattern*)
9355521070a0Smrg	  set dummy $deplibs_check_method; shift
9356521070a0Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9357521070a0Smrg	  for a_deplib in $deplibs; do
9358521070a0Smrg	    case $a_deplib in
9359521070a0Smrg	    -l*)
9360521070a0Smrg	      func_stripname -l '' "$a_deplib"
9361521070a0Smrg	      name=$func_stripname_result
9362b0a0317aSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9363521070a0Smrg		case " $predeps $postdeps " in
9364521070a0Smrg		*" $a_deplib "*)
93653e6c936aSmrg		  func_append newdeplibs " $a_deplib"
9366b0a0317aSmrg		  a_deplib=
9367521070a0Smrg		  ;;
9368521070a0Smrg		esac
9369521070a0Smrg	      fi
9370b0a0317aSmrg	      if test -n "$a_deplib"; then
9371521070a0Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9372521070a0Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9373521070a0Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9374521070a0Smrg		  for potent_lib in $potential_libs; do
9375b0a0317aSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9376ff63a143Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9377521070a0Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
93783e6c936aSmrg		      func_append newdeplibs " $a_deplib"
9379b0a0317aSmrg		      a_deplib=
9380521070a0Smrg		      break 2
9381521070a0Smrg		    fi
9382521070a0Smrg		  done
9383521070a0Smrg		done
9384521070a0Smrg	      fi
9385b0a0317aSmrg	      if test -n "$a_deplib"; then
9386521070a0Smrg		droppeddeps=yes
9387ff63a143Smrg		echo
9388521070a0Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9389ff63a143Smrg		echo "*** I have the capability to make that library automatically link in when"
9390ff63a143Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9391ff63a143Smrg		echo "*** shared version of the library, which you do not appear to have"
9392ff63a143Smrg		echo "*** because I did check the linker path looking for a file starting"
9393b0a0317aSmrg		if test -z "$potlib"; then
9394521070a0Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9395521070a0Smrg		else
9396521070a0Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9397521070a0Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9398521070a0Smrg		fi
9399521070a0Smrg	      fi
9400521070a0Smrg	      ;;
9401521070a0Smrg	    *)
9402521070a0Smrg	      # Add a -L argument.
94033e6c936aSmrg	      func_append newdeplibs " $a_deplib"
9404521070a0Smrg	      ;;
9405521070a0Smrg	    esac
9406521070a0Smrg	  done # Gone through all deplibs.
9407521070a0Smrg	  ;;
9408521070a0Smrg	none | unknown | *)
9409b0a0317aSmrg	  newdeplibs=
9410ff63a143Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9411b0a0317aSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9412b0a0317aSmrg	    for i in $predeps $postdeps; do
9413521070a0Smrg	      # can't use Xsed below, because $i might contain '/'
9414b0a0317aSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9415521070a0Smrg	    done
9416521070a0Smrg	  fi
9417ff63a143Smrg	  case $tmp_deplibs in
9418ff63a143Smrg	  *[!\	\ ]*)
9419ff63a143Smrg	    echo
9420b0a0317aSmrg	    if test none = "$deplibs_check_method"; then
9421ff63a143Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9422521070a0Smrg	    else
9423ff63a143Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9424521070a0Smrg	    fi
9425ff63a143Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9426521070a0Smrg	    droppeddeps=yes
9427ff63a143Smrg	    ;;
9428ff63a143Smrg	  esac
9429521070a0Smrg	  ;;
9430521070a0Smrg	esac
9431521070a0Smrg	versuffix=$versuffix_save
9432521070a0Smrg	major=$major_save
9433521070a0Smrg	release=$release_save
9434521070a0Smrg	libname=$libname_save
9435521070a0Smrg	name=$name_save
9436521070a0Smrg
9437521070a0Smrg	case $host in
9438521070a0Smrg	*-*-rhapsody* | *-*-darwin1.[012])
9439521070a0Smrg	  # On Rhapsody replace the C library with the System framework
9440ff63a143Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9441521070a0Smrg	  ;;
9442521070a0Smrg	esac
9443521070a0Smrg
9444b0a0317aSmrg	if test yes = "$droppeddeps"; then
9445b0a0317aSmrg	  if test yes = "$module"; then
9446ff63a143Smrg	    echo
9447ff63a143Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9448521070a0Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9449ff63a143Smrg	    echo "*** a static module, that should work as long as the dlopening"
9450ff63a143Smrg	    echo "*** application is linked with the -dlopen flag."
9451521070a0Smrg	    if test -z "$global_symbol_pipe"; then
9452ff63a143Smrg	      echo
9453ff63a143Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9454b0a0317aSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9455ff63a143Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9456b0a0317aSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9457521070a0Smrg	    fi
9458b0a0317aSmrg	    if test no = "$build_old_libs"; then
9459b0a0317aSmrg	      oldlibs=$output_objdir/$libname.$libext
9460521070a0Smrg	      build_libtool_libs=module
9461521070a0Smrg	      build_old_libs=yes
9462521070a0Smrg	    else
9463521070a0Smrg	      build_libtool_libs=no
9464521070a0Smrg	    fi
9465521070a0Smrg	  else
9466ff63a143Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9467ff63a143Smrg	    echo "*** automatically added whenever a program is linked with this library"
9468ff63a143Smrg	    echo "*** or is declared to -dlopen it."
9469521070a0Smrg
9470b0a0317aSmrg	    if test no = "$allow_undefined"; then
9471ff63a143Smrg	      echo
9472ff63a143Smrg	      echo "*** Since this library must not contain undefined symbols,"
9473ff63a143Smrg	      echo "*** because either the platform does not support them or"
9474ff63a143Smrg	      echo "*** it was explicitly requested with -no-undefined,"
9475ff63a143Smrg	      echo "*** libtool will only create a static version of it."
9476b0a0317aSmrg	      if test no = "$build_old_libs"; then
9477b0a0317aSmrg		oldlibs=$output_objdir/$libname.$libext
9478521070a0Smrg		build_libtool_libs=module
9479521070a0Smrg		build_old_libs=yes
9480521070a0Smrg	      else
9481521070a0Smrg		build_libtool_libs=no
9482521070a0Smrg	      fi
9483521070a0Smrg	    fi
9484521070a0Smrg	  fi
9485521070a0Smrg	fi
9486521070a0Smrg	# Done checking deplibs!
9487521070a0Smrg	deplibs=$newdeplibs
9488521070a0Smrg      fi
9489521070a0Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9490521070a0Smrg      case $host in
9491521070a0Smrg	*-*-darwin*)
9492ff63a143Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9493ff63a143Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9494ff63a143Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9495521070a0Smrg	  ;;
9496521070a0Smrg      esac
9497521070a0Smrg
9498521070a0Smrg      # move library search paths that coincide with paths to not yet
9499521070a0Smrg      # installed libraries to the beginning of the library search list
9500521070a0Smrg      new_libs=
9501521070a0Smrg      for path in $notinst_path; do
9502521070a0Smrg	case " $new_libs " in
9503521070a0Smrg	*" -L$path/$objdir "*) ;;
9504521070a0Smrg	*)
9505521070a0Smrg	  case " $deplibs " in
9506521070a0Smrg	  *" -L$path/$objdir "*)
95073e6c936aSmrg	    func_append new_libs " -L$path/$objdir" ;;
9508521070a0Smrg	  esac
9509521070a0Smrg	  ;;
9510521070a0Smrg	esac
9511521070a0Smrg      done
9512521070a0Smrg      for deplib in $deplibs; do
9513521070a0Smrg	case $deplib in
9514521070a0Smrg	-L*)
9515521070a0Smrg	  case " $new_libs " in
9516521070a0Smrg	  *" $deplib "*) ;;
95173e6c936aSmrg	  *) func_append new_libs " $deplib" ;;
9518521070a0Smrg	  esac
9519521070a0Smrg	  ;;
95203e6c936aSmrg	*) func_append new_libs " $deplib" ;;
9521521070a0Smrg	esac
9522521070a0Smrg      done
9523b0a0317aSmrg      deplibs=$new_libs
9524521070a0Smrg
9525521070a0Smrg      # All the library-specific variables (install_libdir is set above).
9526521070a0Smrg      library_names=
9527521070a0Smrg      old_library=
9528521070a0Smrg      dlname=
9529521070a0Smrg
9530521070a0Smrg      # Test again, we may have decided not to build it any more
9531b0a0317aSmrg      if test yes = "$build_libtool_libs"; then
9532b0a0317aSmrg	# Remove $wl instances when linking with ld.
95333e6c936aSmrg	# FIXME: should test the right _cmds variable.
95343e6c936aSmrg	case $archive_cmds in
95353e6c936aSmrg	  *\$LD\ *) wl= ;;
95363e6c936aSmrg        esac
9537b0a0317aSmrg	if test yes = "$hardcode_into_libs"; then
9538521070a0Smrg	  # Hardcode the library paths
9539521070a0Smrg	  hardcode_libdirs=
9540521070a0Smrg	  dep_rpath=
9541b0a0317aSmrg	  rpath=$finalize_rpath
9542b0a0317aSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9543521070a0Smrg	  for libdir in $rpath; do
9544521070a0Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
9545521070a0Smrg	      if test -n "$hardcode_libdir_separator"; then
95463e6c936aSmrg		func_replace_sysroot "$libdir"
95473e6c936aSmrg		libdir=$func_replace_sysroot_result
9548521070a0Smrg		if test -z "$hardcode_libdirs"; then
9549b0a0317aSmrg		  hardcode_libdirs=$libdir
9550521070a0Smrg		else
9551521070a0Smrg		  # Just accumulate the unique libdirs.
9552521070a0Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9553521070a0Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9554521070a0Smrg		    ;;
9555521070a0Smrg		  *)
95563e6c936aSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9557521070a0Smrg		    ;;
9558521070a0Smrg		  esac
9559521070a0Smrg		fi
9560521070a0Smrg	      else
9561521070a0Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
95623e6c936aSmrg		func_append dep_rpath " $flag"
9563521070a0Smrg	      fi
9564521070a0Smrg	    elif test -n "$runpath_var"; then
9565521070a0Smrg	      case "$perm_rpath " in
9566521070a0Smrg	      *" $libdir "*) ;;
95673e6c936aSmrg	      *) func_append perm_rpath " $libdir" ;;
9568521070a0Smrg	      esac
9569521070a0Smrg	    fi
9570521070a0Smrg	  done
9571521070a0Smrg	  # Substitute the hardcoded libdirs into the rpath.
9572521070a0Smrg	  if test -n "$hardcode_libdir_separator" &&
9573521070a0Smrg	     test -n "$hardcode_libdirs"; then
9574b0a0317aSmrg	    libdir=$hardcode_libdirs
95753e6c936aSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9576521070a0Smrg	  fi
9577521070a0Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9578521070a0Smrg	    # We should set the runpath_var.
9579521070a0Smrg	    rpath=
9580521070a0Smrg	    for dir in $perm_rpath; do
95813e6c936aSmrg	      func_append rpath "$dir:"
9582521070a0Smrg	    done
9583521070a0Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9584521070a0Smrg	  fi
9585521070a0Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9586521070a0Smrg	fi
95874456fccdSmrg
9588b0a0317aSmrg	shlibpath=$finalize_shlibpath
9589b0a0317aSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9590521070a0Smrg	if test -n "$shlibpath"; then
9591521070a0Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9592521070a0Smrg	fi
95934456fccdSmrg
9594521070a0Smrg	# Get the real and link names of the library.
9595521070a0Smrg	eval shared_ext=\"$shrext_cmds\"
9596521070a0Smrg	eval library_names=\"$library_names_spec\"
9597521070a0Smrg	set dummy $library_names
9598521070a0Smrg	shift
9599b0a0317aSmrg	realname=$1
9600521070a0Smrg	shift
96014456fccdSmrg
9602521070a0Smrg	if test -n "$soname_spec"; then
9603521070a0Smrg	  eval soname=\"$soname_spec\"
9604521070a0Smrg	else
9605b0a0317aSmrg	  soname=$realname
9606521070a0Smrg	fi
9607521070a0Smrg	if test -z "$dlname"; then
9608521070a0Smrg	  dlname=$soname
9609521070a0Smrg	fi
96104456fccdSmrg
9611b0a0317aSmrg	lib=$output_objdir/$realname
9612521070a0Smrg	linknames=
9613521070a0Smrg	for link
9614521070a0Smrg	do
96153e6c936aSmrg	  func_append linknames " $link"
9616521070a0Smrg	done
96174456fccdSmrg
9618521070a0Smrg	# Use standard objects if they are pic
9619ff63a143Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9620521070a0Smrg	test "X$libobjs" = "X " && libobjs=
96214456fccdSmrg
9622521070a0Smrg	delfiles=
9623521070a0Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9624521070a0Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9625b0a0317aSmrg	  export_symbols=$output_objdir/$libname.uexp
96263e6c936aSmrg	  func_append delfiles " $export_symbols"
9627521070a0Smrg	fi
96284456fccdSmrg
9629521070a0Smrg	orig_export_symbols=
9630521070a0Smrg	case $host_os in
9631521070a0Smrg	cygwin* | mingw* | cegcc*)
9632521070a0Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9633521070a0Smrg	    # exporting using user supplied symfile
9634b0a0317aSmrg	    func_dll_def_p "$export_symbols" || {
9635521070a0Smrg	      # and it's NOT already a .def file. Must figure out
9636521070a0Smrg	      # which of the given symbols are data symbols and tag
9637521070a0Smrg	      # them as such. So, trigger use of export_symbols_cmds.
9638521070a0Smrg	      # export_symbols gets reassigned inside the "prepare
9639521070a0Smrg	      # the list of exported symbols" if statement, so the
9640521070a0Smrg	      # include_expsyms logic still works.
9641b0a0317aSmrg	      orig_export_symbols=$export_symbols
9642521070a0Smrg	      export_symbols=
9643521070a0Smrg	      always_export_symbols=yes
9644b0a0317aSmrg	    }
9645521070a0Smrg	  fi
9646521070a0Smrg	  ;;
9647521070a0Smrg	esac
96484456fccdSmrg
9649521070a0Smrg	# Prepare the list of exported symbols
9650521070a0Smrg	if test -z "$export_symbols"; then
9651b0a0317aSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9652b0a0317aSmrg	    func_verbose "generating symbol list for '$libname.la'"
9653b0a0317aSmrg	    export_symbols=$output_objdir/$libname.exp
9654521070a0Smrg	    $opt_dry_run || $RM $export_symbols
9655521070a0Smrg	    cmds=$export_symbols_cmds
9656b0a0317aSmrg	    save_ifs=$IFS; IFS='~'
96573e6c936aSmrg	    for cmd1 in $cmds; do
9658b0a0317aSmrg	      IFS=$save_ifs
96593e6c936aSmrg	      # Take the normal branch if the nm_file_list_spec branch
96603e6c936aSmrg	      # doesn't work or if tool conversion is not needed.
96613e6c936aSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
96623e6c936aSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
96633e6c936aSmrg		  try_normal_branch=yes
96643e6c936aSmrg		  eval cmd=\"$cmd1\"
96653e6c936aSmrg		  func_len " $cmd"
96663e6c936aSmrg		  len=$func_len_result
96673e6c936aSmrg		  ;;
96683e6c936aSmrg		*)
96693e6c936aSmrg		  try_normal_branch=no
96703e6c936aSmrg		  ;;
96713e6c936aSmrg	      esac
9672b0a0317aSmrg	      if test yes = "$try_normal_branch" \
96733e6c936aSmrg		 && { test "$len" -lt "$max_cmd_len" \
96743e6c936aSmrg		      || test "$max_cmd_len" -le -1; }
96753e6c936aSmrg	      then
96763e6c936aSmrg		func_show_eval "$cmd" 'exit $?'
96773e6c936aSmrg		skipped_export=false
96783e6c936aSmrg	      elif test -n "$nm_file_list_spec"; then
96793e6c936aSmrg		func_basename "$output"
96803e6c936aSmrg		output_la=$func_basename_result
96813e6c936aSmrg		save_libobjs=$libobjs
96823e6c936aSmrg		save_output=$output
9683b0a0317aSmrg		output=$output_objdir/$output_la.nm
96843e6c936aSmrg		func_to_tool_file "$output"
96853e6c936aSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
96863e6c936aSmrg		func_append delfiles " $output"
96873e6c936aSmrg		func_verbose "creating $NM input file list: $output"
96883e6c936aSmrg		for obj in $save_libobjs; do
96893e6c936aSmrg		  func_to_tool_file "$obj"
96903e6c936aSmrg		  $ECHO "$func_to_tool_file_result"
96913e6c936aSmrg		done > "$output"
96923e6c936aSmrg		eval cmd=\"$cmd1\"
9693521070a0Smrg		func_show_eval "$cmd" 'exit $?'
96943e6c936aSmrg		output=$save_output
96953e6c936aSmrg		libobjs=$save_libobjs
9696521070a0Smrg		skipped_export=false
9697521070a0Smrg	      else
9698521070a0Smrg		# The command line is too long to execute in one step.
9699521070a0Smrg		func_verbose "using reloadable object file for export list..."
9700521070a0Smrg		skipped_export=:
9701521070a0Smrg		# Break out early, otherwise skipped_export may be
9702521070a0Smrg		# set to false by a later but shorter cmd.
9703521070a0Smrg		break
9704521070a0Smrg	      fi
9705521070a0Smrg	    done
9706b0a0317aSmrg	    IFS=$save_ifs
9707b0a0317aSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9708521070a0Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9709521070a0Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9710521070a0Smrg	    fi
9711521070a0Smrg	  fi
97124456fccdSmrg	fi
97134456fccdSmrg
9714521070a0Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9715b0a0317aSmrg	  tmp_export_symbols=$export_symbols
9716b0a0317aSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
9717ff63a143Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
9718521070a0Smrg	fi
97194456fccdSmrg
9720b0a0317aSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
9721521070a0Smrg	  # The given exports_symbols file has to be filtered, so filter it.
9722b0a0317aSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
9723521070a0Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
9724b0a0317aSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
9725521070a0Smrg	  # though. Also, the filter scales superlinearly with the number of
9726521070a0Smrg	  # global variables. join(1) would be nice here, but unfortunately
9727521070a0Smrg	  # isn't a blessed tool.
9728521070a0Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
97293e6c936aSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
9730521070a0Smrg	  export_symbols=$output_objdir/$libname.def
9731521070a0Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
9732521070a0Smrg	fi
97334456fccdSmrg
9734521070a0Smrg	tmp_deplibs=
9735521070a0Smrg	for test_deplib in $deplibs; do
9736521070a0Smrg	  case " $convenience " in
9737521070a0Smrg	  *" $test_deplib "*) ;;
9738521070a0Smrg	  *)
97393e6c936aSmrg	    func_append tmp_deplibs " $test_deplib"
9740521070a0Smrg	    ;;
9741521070a0Smrg	  esac
9742521070a0Smrg	done
9743b0a0317aSmrg	deplibs=$tmp_deplibs
97444456fccdSmrg
9745521070a0Smrg	if test -n "$convenience"; then
9746521070a0Smrg	  if test -n "$whole_archive_flag_spec" &&
9747b0a0317aSmrg	    test yes = "$compiler_needs_object" &&
9748521070a0Smrg	    test -z "$libobjs"; then
9749521070a0Smrg	    # extract the archives, so we have objects to list.
9750521070a0Smrg	    # TODO: could optimize this to just extract one archive.
9751521070a0Smrg	    whole_archive_flag_spec=
9752521070a0Smrg	  fi
9753521070a0Smrg	  if test -n "$whole_archive_flag_spec"; then
9754521070a0Smrg	    save_libobjs=$libobjs
9755521070a0Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
9756521070a0Smrg	    test "X$libobjs" = "X " && libobjs=
9757521070a0Smrg	  else
9758b0a0317aSmrg	    gentop=$output_objdir/${outputname}x
97593e6c936aSmrg	    func_append generated " $gentop"
97604456fccdSmrg
9761521070a0Smrg	    func_extract_archives $gentop $convenience
97623e6c936aSmrg	    func_append libobjs " $func_extract_archives_result"
9763521070a0Smrg	    test "X$libobjs" = "X " && libobjs=
9764521070a0Smrg	  fi
97654456fccdSmrg	fi
97664456fccdSmrg
9767b0a0317aSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
9768521070a0Smrg	  eval flag=\"$thread_safe_flag_spec\"
97693e6c936aSmrg	  func_append linker_flags " $flag"
97704456fccdSmrg	fi
97714456fccdSmrg
9772521070a0Smrg	# Make a backup of the uninstalled library when relinking
9773b0a0317aSmrg	if test relink = "$opt_mode"; then
9774521070a0Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
9775521070a0Smrg	fi
97764456fccdSmrg
9777521070a0Smrg	# Do each of the archive commands.
9778b0a0317aSmrg	if test yes = "$module" && test -n "$module_cmds"; then
9779521070a0Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
9780521070a0Smrg	    eval test_cmds=\"$module_expsym_cmds\"
9781521070a0Smrg	    cmds=$module_expsym_cmds
9782521070a0Smrg	  else
9783521070a0Smrg	    eval test_cmds=\"$module_cmds\"
9784521070a0Smrg	    cmds=$module_cmds
9785521070a0Smrg	  fi
97864456fccdSmrg	else
9787521070a0Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
9788521070a0Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
9789521070a0Smrg	    cmds=$archive_expsym_cmds
9790521070a0Smrg	  else
9791521070a0Smrg	    eval test_cmds=\"$archive_cmds\"
9792521070a0Smrg	    cmds=$archive_cmds
9793521070a0Smrg	  fi
97944456fccdSmrg	fi
97954456fccdSmrg
9796b0a0317aSmrg	if test : != "$skipped_export" &&
9797521070a0Smrg	   func_len " $test_cmds" &&
9798521070a0Smrg	   len=$func_len_result &&
9799521070a0Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
9800521070a0Smrg	  :
9801521070a0Smrg	else
9802521070a0Smrg	  # The command line is too long to link in one step, link piecewise
9803521070a0Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
9804521070a0Smrg	  # script.
98054456fccdSmrg
9806521070a0Smrg	  # Save the value of $output and $libobjs because we want to
9807521070a0Smrg	  # use them later.  If we have whole_archive_flag_spec, we
9808521070a0Smrg	  # want to use save_libobjs as it was before
9809521070a0Smrg	  # whole_archive_flag_spec was expanded, because we can't
9810521070a0Smrg	  # assume the linker understands whole_archive_flag_spec.
9811521070a0Smrg	  # This may have to be revisited, in case too many
9812521070a0Smrg	  # convenience libraries get linked in and end up exceeding
9813521070a0Smrg	  # the spec.
9814521070a0Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
9815521070a0Smrg	    save_libobjs=$libobjs
9816521070a0Smrg	  fi
9817521070a0Smrg	  save_output=$output
9818ff63a143Smrg	  func_basename "$output"
9819ff63a143Smrg	  output_la=$func_basename_result
98204456fccdSmrg
9821521070a0Smrg	  # Clear the reloadable object creation command queue and
9822521070a0Smrg	  # initialize k to one.
9823521070a0Smrg	  test_cmds=
9824521070a0Smrg	  concat_cmds=
9825521070a0Smrg	  objlist=
9826521070a0Smrg	  last_robj=
9827521070a0Smrg	  k=1
9828521070a0Smrg
9829b0a0317aSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
9830b0a0317aSmrg	    output=$output_objdir/$output_la.lnkscript
9831521070a0Smrg	    func_verbose "creating GNU ld script: $output"
9832ff63a143Smrg	    echo 'INPUT (' > $output
9833521070a0Smrg	    for obj in $save_libobjs
98344456fccdSmrg	    do
98353e6c936aSmrg	      func_to_tool_file "$obj"
98363e6c936aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
9837521070a0Smrg	    done
9838ff63a143Smrg	    echo ')' >> $output
98393e6c936aSmrg	    func_append delfiles " $output"
98403e6c936aSmrg	    func_to_tool_file "$output"
98413e6c936aSmrg	    output=$func_to_tool_file_result
9842b0a0317aSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
9843b0a0317aSmrg	    output=$output_objdir/$output_la.lnk
9844521070a0Smrg	    func_verbose "creating linker input file list: $output"
9845521070a0Smrg	    : > $output
9846521070a0Smrg	    set x $save_libobjs
9847521070a0Smrg	    shift
9848521070a0Smrg	    firstobj=
9849b0a0317aSmrg	    if test yes = "$compiler_needs_object"; then
9850521070a0Smrg	      firstobj="$1 "
9851521070a0Smrg	      shift
9852521070a0Smrg	    fi
9853521070a0Smrg	    for obj
9854521070a0Smrg	    do
98553e6c936aSmrg	      func_to_tool_file "$obj"
98563e6c936aSmrg	      $ECHO "$func_to_tool_file_result" >> $output
9857521070a0Smrg	    done
98583e6c936aSmrg	    func_append delfiles " $output"
98593e6c936aSmrg	    func_to_tool_file "$output"
98603e6c936aSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
9861521070a0Smrg	  else
9862521070a0Smrg	    if test -n "$save_libobjs"; then
9863521070a0Smrg	      func_verbose "creating reloadable object files..."
9864b0a0317aSmrg	      output=$output_objdir/$output_la-$k.$objext
9865521070a0Smrg	      eval test_cmds=\"$reload_cmds\"
9866521070a0Smrg	      func_len " $test_cmds"
9867521070a0Smrg	      len0=$func_len_result
9868521070a0Smrg	      len=$len0
9869521070a0Smrg
9870521070a0Smrg	      # Loop over the list of objects to be linked.
9871521070a0Smrg	      for obj in $save_libobjs
9872521070a0Smrg	      do
9873521070a0Smrg		func_len " $obj"
9874521070a0Smrg		func_arith $len + $func_len_result
9875521070a0Smrg		len=$func_arith_result
9876b0a0317aSmrg		if test -z "$objlist" ||
9877521070a0Smrg		   test "$len" -lt "$max_cmd_len"; then
9878521070a0Smrg		  func_append objlist " $obj"
9879521070a0Smrg		else
9880521070a0Smrg		  # The command $test_cmds is almost too long, add a
9881521070a0Smrg		  # command to the queue.
9882b0a0317aSmrg		  if test 1 -eq "$k"; then
9883521070a0Smrg		    # The first file doesn't have a previous command to add.
9884ff63a143Smrg		    reload_objs=$objlist
9885ff63a143Smrg		    eval concat_cmds=\"$reload_cmds\"
9886521070a0Smrg		  else
9887521070a0Smrg		    # All subsequent reloadable object files will link in
9888521070a0Smrg		    # the last one created.
9889ff63a143Smrg		    reload_objs="$objlist $last_robj"
9890ff63a143Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
9891521070a0Smrg		  fi
9892b0a0317aSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
9893521070a0Smrg		  func_arith $k + 1
9894521070a0Smrg		  k=$func_arith_result
9895b0a0317aSmrg		  output=$output_objdir/$output_la-$k.$objext
9896ff63a143Smrg		  objlist=" $obj"
9897521070a0Smrg		  func_len " $last_robj"
9898521070a0Smrg		  func_arith $len0 + $func_len_result
9899521070a0Smrg		  len=$func_arith_result
9900521070a0Smrg		fi
9901521070a0Smrg	      done
9902521070a0Smrg	      # Handle the remaining objects by creating one last
9903521070a0Smrg	      # reloadable object file.  All subsequent reloadable object
9904521070a0Smrg	      # files will link in the last one created.
9905521070a0Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
9906ff63a143Smrg	      reload_objs="$objlist $last_robj"
9907b0a0317aSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
9908521070a0Smrg	      if test -n "$last_robj"; then
9909b0a0317aSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
9910521070a0Smrg	      fi
99113e6c936aSmrg	      func_append delfiles " $output"
99124456fccdSmrg
9913521070a0Smrg	    else
9914521070a0Smrg	      output=
9915521070a0Smrg	    fi
99164456fccdSmrg
9917b0a0317aSmrg	    ${skipped_export-false} && {
9918b0a0317aSmrg	      func_verbose "generating symbol list for '$libname.la'"
9919b0a0317aSmrg	      export_symbols=$output_objdir/$libname.exp
9920521070a0Smrg	      $opt_dry_run || $RM $export_symbols
9921521070a0Smrg	      libobjs=$output
9922521070a0Smrg	      # Append the command to create the export file.
9923521070a0Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
9924521070a0Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
9925521070a0Smrg	      if test -n "$last_robj"; then
9926521070a0Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
9927521070a0Smrg	      fi
9928b0a0317aSmrg	    }
99294456fccdSmrg
9930521070a0Smrg	    test -n "$save_libobjs" &&
9931521070a0Smrg	      func_verbose "creating a temporary reloadable object file: $output"
99324456fccdSmrg
9933521070a0Smrg	    # Loop through the commands generated above and execute them.
9934b0a0317aSmrg	    save_ifs=$IFS; IFS='~'
9935521070a0Smrg	    for cmd in $concat_cmds; do
9936b0a0317aSmrg	      IFS=$save_ifs
9937b0a0317aSmrg	      $opt_quiet || {
9938521070a0Smrg		  func_quote_for_expand "$cmd"
9939521070a0Smrg		  eval "func_echo $func_quote_for_expand_result"
9940521070a0Smrg	      }
9941521070a0Smrg	      $opt_dry_run || eval "$cmd" || {
9942521070a0Smrg		lt_exit=$?
9943521070a0Smrg
9944521070a0Smrg		# Restore the uninstalled library and exit
9945b0a0317aSmrg		if test relink = "$opt_mode"; then
9946521070a0Smrg		  ( cd "$output_objdir" && \
9947521070a0Smrg		    $RM "${realname}T" && \
9948521070a0Smrg		    $MV "${realname}U" "$realname" )
9949521070a0Smrg		fi
99504456fccdSmrg
9951521070a0Smrg		exit $lt_exit
9952521070a0Smrg	      }
9953521070a0Smrg	    done
9954b0a0317aSmrg	    IFS=$save_ifs
99554456fccdSmrg
9956521070a0Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
9957521070a0Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9958521070a0Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
99594456fccdSmrg	    fi
99604456fccdSmrg	  fi
99614456fccdSmrg
9962b0a0317aSmrg          ${skipped_export-false} && {
9963521070a0Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
9964b0a0317aSmrg	      tmp_export_symbols=$export_symbols
9965b0a0317aSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
9966ff63a143Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
9967521070a0Smrg	    fi
99684456fccdSmrg
9969521070a0Smrg	    if test -n "$orig_export_symbols"; then
9970521070a0Smrg	      # The given exports_symbols file has to be filtered, so filter it.
9971b0a0317aSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
9972521070a0Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
9973b0a0317aSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
9974521070a0Smrg	      # though. Also, the filter scales superlinearly with the number of
9975521070a0Smrg	      # global variables. join(1) would be nice here, but unfortunately
9976521070a0Smrg	      # isn't a blessed tool.
9977521070a0Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
99783e6c936aSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
9979521070a0Smrg	      export_symbols=$output_objdir/$libname.def
9980521070a0Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
9981521070a0Smrg	    fi
9982b0a0317aSmrg	  }
99834456fccdSmrg
9984521070a0Smrg	  libobjs=$output
9985521070a0Smrg	  # Restore the value of output.
9986521070a0Smrg	  output=$save_output
99874456fccdSmrg
9988521070a0Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
9989521070a0Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
9990521070a0Smrg	    test "X$libobjs" = "X " && libobjs=
9991521070a0Smrg	  fi
9992521070a0Smrg	  # Expand the library linking commands again to reset the
9993521070a0Smrg	  # value of $libobjs for piecewise linking.
99944456fccdSmrg
9995521070a0Smrg	  # Do each of the archive commands.
9996b0a0317aSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
9997521070a0Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
9998521070a0Smrg	      cmds=$module_expsym_cmds
9999521070a0Smrg	    else
10000521070a0Smrg	      cmds=$module_cmds
100014456fccdSmrg	    fi
100024456fccdSmrg	  else
10003521070a0Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10004521070a0Smrg	      cmds=$archive_expsym_cmds
10005521070a0Smrg	    else
10006521070a0Smrg	      cmds=$archive_cmds
10007521070a0Smrg	    fi
100084456fccdSmrg	  fi
10009521070a0Smrg	fi
100104456fccdSmrg
10011521070a0Smrg	if test -n "$delfiles"; then
10012521070a0Smrg	  # Append the command to remove temporary files to $cmds.
10013521070a0Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10014521070a0Smrg	fi
100154456fccdSmrg
10016521070a0Smrg	# Add any objects from preloaded convenience libraries
10017521070a0Smrg	if test -n "$dlprefiles"; then
10018b0a0317aSmrg	  gentop=$output_objdir/${outputname}x
100193e6c936aSmrg	  func_append generated " $gentop"
100204456fccdSmrg
10021521070a0Smrg	  func_extract_archives $gentop $dlprefiles
100223e6c936aSmrg	  func_append libobjs " $func_extract_archives_result"
10023521070a0Smrg	  test "X$libobjs" = "X " && libobjs=
10024521070a0Smrg	fi
100254456fccdSmrg
10026b0a0317aSmrg	save_ifs=$IFS; IFS='~'
10027521070a0Smrg	for cmd in $cmds; do
10028b0a0317aSmrg	  IFS=$sp$nl
10029521070a0Smrg	  eval cmd=\"$cmd\"
10030b0a0317aSmrg	  IFS=$save_ifs
10031b0a0317aSmrg	  $opt_quiet || {
10032521070a0Smrg	    func_quote_for_expand "$cmd"
10033521070a0Smrg	    eval "func_echo $func_quote_for_expand_result"
10034521070a0Smrg	  }
10035521070a0Smrg	  $opt_dry_run || eval "$cmd" || {
10036521070a0Smrg	    lt_exit=$?
100374456fccdSmrg
10038521070a0Smrg	    # Restore the uninstalled library and exit
10039b0a0317aSmrg	    if test relink = "$opt_mode"; then
10040521070a0Smrg	      ( cd "$output_objdir" && \
10041521070a0Smrg	        $RM "${realname}T" && \
10042521070a0Smrg		$MV "${realname}U" "$realname" )
10043521070a0Smrg	    fi
100444456fccdSmrg
10045521070a0Smrg	    exit $lt_exit
10046521070a0Smrg	  }
10047521070a0Smrg	done
10048b0a0317aSmrg	IFS=$save_ifs
100494456fccdSmrg
10050521070a0Smrg	# Restore the uninstalled library and exit
10051b0a0317aSmrg	if test relink = "$opt_mode"; then
10052521070a0Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
100534456fccdSmrg
10054521070a0Smrg	  if test -n "$convenience"; then
10055521070a0Smrg	    if test -z "$whole_archive_flag_spec"; then
10056521070a0Smrg	      func_show_eval '${RM}r "$gentop"'
10057521070a0Smrg	    fi
10058521070a0Smrg	  fi
100594456fccdSmrg
10060521070a0Smrg	  exit $EXIT_SUCCESS
10061521070a0Smrg	fi
10062521070a0Smrg
10063521070a0Smrg	# Create links to the real library.
10064521070a0Smrg	for linkname in $linknames; do
10065521070a0Smrg	  if test "$realname" != "$linkname"; then
10066521070a0Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
100674456fccdSmrg	  fi
100684456fccdSmrg	done
100694456fccdSmrg
10070521070a0Smrg	# If -module or -export-dynamic was specified, set the dlname.
10071b0a0317aSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10072521070a0Smrg	  # On all known operating systems, these are identical.
10073b0a0317aSmrg	  dlname=$soname
10074521070a0Smrg	fi
10075521070a0Smrg      fi
100764456fccdSmrg      ;;
100774456fccdSmrg
10078521070a0Smrg    obj)
10079b0a0317aSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10080b0a0317aSmrg	func_warning "'-dlopen' is ignored for objects"
10081521070a0Smrg      fi
100824456fccdSmrg
10083521070a0Smrg      case " $deplibs" in
10084521070a0Smrg      *\ -l* | *\ -L*)
10085b0a0317aSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
100864456fccdSmrg      esac
100874456fccdSmrg
10088521070a0Smrg      test -n "$rpath" && \
10089b0a0317aSmrg	func_warning "'-rpath' is ignored for objects"
10090521070a0Smrg
10091521070a0Smrg      test -n "$xrpath" && \
10092b0a0317aSmrg	func_warning "'-R' is ignored for objects"
100934456fccdSmrg
10094521070a0Smrg      test -n "$vinfo" && \
10095b0a0317aSmrg	func_warning "'-version-info' is ignored for objects"
100964456fccdSmrg
10097521070a0Smrg      test -n "$release" && \
10098b0a0317aSmrg	func_warning "'-release' is ignored for objects"
10099521070a0Smrg
10100521070a0Smrg      case $output in
10101521070a0Smrg      *.lo)
10102521070a0Smrg	test -n "$objs$old_deplibs" && \
10103b0a0317aSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10104521070a0Smrg
10105521070a0Smrg	libobj=$output
10106521070a0Smrg	func_lo2o "$libobj"
10107521070a0Smrg	obj=$func_lo2o_result
101084456fccdSmrg	;;
101094456fccdSmrg      *)
10110521070a0Smrg	libobj=
10111b0a0317aSmrg	obj=$output
101124456fccdSmrg	;;
101134456fccdSmrg      esac
101144456fccdSmrg
10115521070a0Smrg      # Delete the old objects.
10116521070a0Smrg      $opt_dry_run || $RM $obj $libobj
101174456fccdSmrg
10118521070a0Smrg      # Objects from convenience libraries.  This assumes
10119521070a0Smrg      # single-version convenience libraries.  Whenever we create
10120521070a0Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10121521070a0Smrg      # the extraction.
10122521070a0Smrg      reload_conv_objs=
10123521070a0Smrg      gentop=
10124b0a0317aSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10125b0a0317aSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
10126b0a0317aSmrg      # into space.
10127b0a0317aSmrg      case $reload_cmds in
10128b0a0317aSmrg        *\$LD[\ \$]*) wl= ;;
10129b0a0317aSmrg      esac
10130521070a0Smrg      if test -n "$convenience"; then
10131521070a0Smrg	if test -n "$whole_archive_flag_spec"; then
10132521070a0Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10133b0a0317aSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10134b0a0317aSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10135521070a0Smrg	else
10136b0a0317aSmrg	  gentop=$output_objdir/${obj}x
101373e6c936aSmrg	  func_append generated " $gentop"
101384456fccdSmrg
10139521070a0Smrg	  func_extract_archives $gentop $convenience
10140521070a0Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10141521070a0Smrg	fi
101424456fccdSmrg      fi
101434456fccdSmrg
101443e6c936aSmrg      # If we're not building shared, we need to use non_pic_objs
10145b0a0317aSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
101463e6c936aSmrg
10147521070a0Smrg      # Create the old-style object.
10148b0a0317aSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
101494456fccdSmrg
10150b0a0317aSmrg      output=$obj
10151521070a0Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
101524456fccdSmrg
10153521070a0Smrg      # Exit if we aren't doing a library object file.
10154521070a0Smrg      if test -z "$libobj"; then
10155521070a0Smrg	if test -n "$gentop"; then
10156521070a0Smrg	  func_show_eval '${RM}r "$gentop"'
10157521070a0Smrg	fi
10158521070a0Smrg
10159521070a0Smrg	exit $EXIT_SUCCESS
101604456fccdSmrg      fi
10161521070a0Smrg
10162b0a0317aSmrg      test yes = "$build_libtool_libs" || {
10163521070a0Smrg	if test -n "$gentop"; then
10164521070a0Smrg	  func_show_eval '${RM}r "$gentop"'
10165521070a0Smrg	fi
10166521070a0Smrg
10167521070a0Smrg	# Create an invalid libtool object if no PIC, so that we don't
10168521070a0Smrg	# accidentally link it into a program.
10169521070a0Smrg	# $show "echo timestamp > $libobj"
10170521070a0Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10171521070a0Smrg	exit $EXIT_SUCCESS
10172b0a0317aSmrg      }
10173521070a0Smrg
10174b0a0317aSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10175521070a0Smrg	# Only do commands if we really have different PIC objects.
10176521070a0Smrg	reload_objs="$libobjs $reload_conv_objs"
10177b0a0317aSmrg	output=$libobj
10178521070a0Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
10179521070a0Smrg      fi
10180521070a0Smrg
10181521070a0Smrg      if test -n "$gentop"; then
10182521070a0Smrg	func_show_eval '${RM}r "$gentop"'
10183521070a0Smrg      fi
10184521070a0Smrg
10185521070a0Smrg      exit $EXIT_SUCCESS
101864456fccdSmrg      ;;
101874456fccdSmrg
10188521070a0Smrg    prog)
10189521070a0Smrg      case $host in
10190521070a0Smrg	*cygwin*) func_stripname '' '.exe' "$output"
10191521070a0Smrg	          output=$func_stripname_result.exe;;
10192521070a0Smrg      esac
10193521070a0Smrg      test -n "$vinfo" && \
10194b0a0317aSmrg	func_warning "'-version-info' is ignored for programs"
101954456fccdSmrg
10196521070a0Smrg      test -n "$release" && \
10197b0a0317aSmrg	func_warning "'-release' is ignored for programs"
101984456fccdSmrg
10199b0a0317aSmrg      $preload \
10200b0a0317aSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10201b0a0317aSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10202521070a0Smrg
10203521070a0Smrg      case $host in
10204521070a0Smrg      *-*-rhapsody* | *-*-darwin1.[012])
10205521070a0Smrg	# On Rhapsody replace the C library is the System framework
10206ff63a143Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10207ff63a143Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
102084456fccdSmrg	;;
10209521070a0Smrg      esac
102104456fccdSmrg
10211521070a0Smrg      case $host in
10212521070a0Smrg      *-*-darwin*)
10213521070a0Smrg	# Don't allow lazy linking, it breaks C++ global constructors
10214521070a0Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10215b0a0317aSmrg	if test CXX = "$tagname"; then
10216521070a0Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10217521070a0Smrg	    10.[0123])
10218b0a0317aSmrg	      func_append compile_command " $wl-bind_at_load"
10219b0a0317aSmrg	      func_append finalize_command " $wl-bind_at_load"
10220521070a0Smrg	    ;;
10221521070a0Smrg	  esac
102224456fccdSmrg	fi
10223521070a0Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10224ff63a143Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10225ff63a143Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10226521070a0Smrg	;;
10227521070a0Smrg      esac
102284456fccdSmrg
102294456fccdSmrg
10230521070a0Smrg      # move library search paths that coincide with paths to not yet
10231521070a0Smrg      # installed libraries to the beginning of the library search list
10232521070a0Smrg      new_libs=
10233521070a0Smrg      for path in $notinst_path; do
10234521070a0Smrg	case " $new_libs " in
10235521070a0Smrg	*" -L$path/$objdir "*) ;;
10236521070a0Smrg	*)
10237521070a0Smrg	  case " $compile_deplibs " in
10238521070a0Smrg	  *" -L$path/$objdir "*)
102393e6c936aSmrg	    func_append new_libs " -L$path/$objdir" ;;
102404456fccdSmrg	  esac
10241521070a0Smrg	  ;;
10242521070a0Smrg	esac
10243521070a0Smrg      done
10244521070a0Smrg      for deplib in $compile_deplibs; do
10245521070a0Smrg	case $deplib in
10246521070a0Smrg	-L*)
10247521070a0Smrg	  case " $new_libs " in
10248521070a0Smrg	  *" $deplib "*) ;;
102493e6c936aSmrg	  *) func_append new_libs " $deplib" ;;
102504456fccdSmrg	  esac
10251521070a0Smrg	  ;;
102523e6c936aSmrg	*) func_append new_libs " $deplib" ;;
10253521070a0Smrg	esac
10254521070a0Smrg      done
10255b0a0317aSmrg      compile_deplibs=$new_libs
102564456fccdSmrg
102574456fccdSmrg
102583e6c936aSmrg      func_append compile_command " $compile_deplibs"
102593e6c936aSmrg      func_append finalize_command " $finalize_deplibs"
102604456fccdSmrg
10261521070a0Smrg      if test -n "$rpath$xrpath"; then
10262521070a0Smrg	# If the user specified any rpath flags, then add them.
10263521070a0Smrg	for libdir in $rpath $xrpath; do
10264521070a0Smrg	  # This is the magic to use -rpath.
10265521070a0Smrg	  case "$finalize_rpath " in
10266521070a0Smrg	  *" $libdir "*) ;;
102673e6c936aSmrg	  *) func_append finalize_rpath " $libdir" ;;
10268521070a0Smrg	  esac
10269521070a0Smrg	done
10270521070a0Smrg      fi
102714456fccdSmrg
10272521070a0Smrg      # Now hardcode the library paths
10273521070a0Smrg      rpath=
10274521070a0Smrg      hardcode_libdirs=
10275521070a0Smrg      for libdir in $compile_rpath $finalize_rpath; do
10276521070a0Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10277521070a0Smrg	  if test -n "$hardcode_libdir_separator"; then
10278521070a0Smrg	    if test -z "$hardcode_libdirs"; then
10279b0a0317aSmrg	      hardcode_libdirs=$libdir
10280521070a0Smrg	    else
10281521070a0Smrg	      # Just accumulate the unique libdirs.
10282521070a0Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10283521070a0Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10284521070a0Smrg		;;
10285521070a0Smrg	      *)
102863e6c936aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10287521070a0Smrg		;;
10288521070a0Smrg	      esac
10289521070a0Smrg	    fi
102904456fccdSmrg	  else
10291521070a0Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
102923e6c936aSmrg	    func_append rpath " $flag"
102934456fccdSmrg	  fi
10294521070a0Smrg	elif test -n "$runpath_var"; then
10295521070a0Smrg	  case "$perm_rpath " in
10296521070a0Smrg	  *" $libdir "*) ;;
102973e6c936aSmrg	  *) func_append perm_rpath " $libdir" ;;
10298521070a0Smrg	  esac
10299521070a0Smrg	fi
10300521070a0Smrg	case $host in
10301521070a0Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10302b0a0317aSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10303521070a0Smrg	  case :$dllsearchpath: in
10304521070a0Smrg	  *":$libdir:"*) ;;
10305521070a0Smrg	  ::) dllsearchpath=$libdir;;
103063e6c936aSmrg	  *) func_append dllsearchpath ":$libdir";;
10307521070a0Smrg	  esac
10308521070a0Smrg	  case :$dllsearchpath: in
10309521070a0Smrg	  *":$testbindir:"*) ;;
10310521070a0Smrg	  ::) dllsearchpath=$testbindir;;
103113e6c936aSmrg	  *) func_append dllsearchpath ":$testbindir";;
10312521070a0Smrg	  esac
10313521070a0Smrg	  ;;
10314521070a0Smrg	esac
10315521070a0Smrg      done
10316521070a0Smrg      # Substitute the hardcoded libdirs into the rpath.
10317521070a0Smrg      if test -n "$hardcode_libdir_separator" &&
10318521070a0Smrg	 test -n "$hardcode_libdirs"; then
10319b0a0317aSmrg	libdir=$hardcode_libdirs
10320521070a0Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10321521070a0Smrg      fi
10322b0a0317aSmrg      compile_rpath=$rpath
103234456fccdSmrg
10324521070a0Smrg      rpath=
10325521070a0Smrg      hardcode_libdirs=
10326521070a0Smrg      for libdir in $finalize_rpath; do
10327521070a0Smrg	if test -n "$hardcode_libdir_flag_spec"; then
10328521070a0Smrg	  if test -n "$hardcode_libdir_separator"; then
10329521070a0Smrg	    if test -z "$hardcode_libdirs"; then
10330b0a0317aSmrg	      hardcode_libdirs=$libdir
10331521070a0Smrg	    else
10332521070a0Smrg	      # Just accumulate the unique libdirs.
10333521070a0Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10334521070a0Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10335521070a0Smrg		;;
10336521070a0Smrg	      *)
103373e6c936aSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10338521070a0Smrg		;;
10339521070a0Smrg	      esac
10340521070a0Smrg	    fi
103414456fccdSmrg	  else
10342521070a0Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
103433e6c936aSmrg	    func_append rpath " $flag"
103444456fccdSmrg	  fi
10345521070a0Smrg	elif test -n "$runpath_var"; then
10346521070a0Smrg	  case "$finalize_perm_rpath " in
10347521070a0Smrg	  *" $libdir "*) ;;
103483e6c936aSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10349521070a0Smrg	  esac
103504456fccdSmrg	fi
10351521070a0Smrg      done
10352521070a0Smrg      # Substitute the hardcoded libdirs into the rpath.
10353521070a0Smrg      if test -n "$hardcode_libdir_separator" &&
10354521070a0Smrg	 test -n "$hardcode_libdirs"; then
10355b0a0317aSmrg	libdir=$hardcode_libdirs
10356521070a0Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10357521070a0Smrg      fi
10358b0a0317aSmrg      finalize_rpath=$rpath
103594456fccdSmrg
10360b0a0317aSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10361521070a0Smrg	# Transform all the library objects into standard objects.
10362ff63a143Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10363ff63a143Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10364521070a0Smrg      fi
103654456fccdSmrg
10366b0a0317aSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
103674456fccdSmrg
10368521070a0Smrg      # template prelinking step
10369521070a0Smrg      if test -n "$prelink_cmds"; then
10370521070a0Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10371521070a0Smrg      fi
103724456fccdSmrg
10373b0a0317aSmrg      wrappers_required=:
10374521070a0Smrg      case $host in
10375ff63a143Smrg      *cegcc* | *mingw32ce*)
10376ff63a143Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10377b0a0317aSmrg        wrappers_required=false
10378ff63a143Smrg        ;;
10379521070a0Smrg      *cygwin* | *mingw* )
10380b0a0317aSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10381521070a0Smrg        ;;
10382521070a0Smrg      *)
10383b0a0317aSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10384b0a0317aSmrg          wrappers_required=false
10385521070a0Smrg        fi
10386521070a0Smrg        ;;
10387521070a0Smrg      esac
10388b0a0317aSmrg      $wrappers_required || {
10389521070a0Smrg	# Replace the output file specification.
10390ff63a143Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10391b0a0317aSmrg	link_command=$compile_command$compile_rpath
103924456fccdSmrg
10393521070a0Smrg	# We have no uninstalled library dependencies, so finalize right now.
10394521070a0Smrg	exit_status=0
10395521070a0Smrg	func_show_eval "$link_command" 'exit_status=$?'
103964456fccdSmrg
103973e6c936aSmrg	if test -n "$postlink_cmds"; then
103983e6c936aSmrg	  func_to_tool_file "$output"
103993e6c936aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
104003e6c936aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
104013e6c936aSmrg	fi
104023e6c936aSmrg
10403521070a0Smrg	# Delete the generated files.
10404b0a0317aSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10405b0a0317aSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
104064456fccdSmrg	fi
104074456fccdSmrg
10408521070a0Smrg	exit $exit_status
10409b0a0317aSmrg      }
104104456fccdSmrg
10411521070a0Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10412521070a0Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10413521070a0Smrg      fi
10414521070a0Smrg      if test -n "$finalize_shlibpath"; then
10415521070a0Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10416521070a0Smrg      fi
104174456fccdSmrg
10418521070a0Smrg      compile_var=
10419521070a0Smrg      finalize_var=
10420521070a0Smrg      if test -n "$runpath_var"; then
10421521070a0Smrg	if test -n "$perm_rpath"; then
10422521070a0Smrg	  # We should set the runpath_var.
10423521070a0Smrg	  rpath=
10424521070a0Smrg	  for dir in $perm_rpath; do
104253e6c936aSmrg	    func_append rpath "$dir:"
10426521070a0Smrg	  done
10427521070a0Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
104284456fccdSmrg	fi
10429521070a0Smrg	if test -n "$finalize_perm_rpath"; then
10430521070a0Smrg	  # We should set the runpath_var.
10431521070a0Smrg	  rpath=
10432521070a0Smrg	  for dir in $finalize_perm_rpath; do
104333e6c936aSmrg	    func_append rpath "$dir:"
10434521070a0Smrg	  done
10435521070a0Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
104364456fccdSmrg	fi
10437521070a0Smrg      fi
104384456fccdSmrg
10439b0a0317aSmrg      if test yes = "$no_install"; then
10440521070a0Smrg	# We don't need to create a wrapper script.
10441b0a0317aSmrg	link_command=$compile_var$compile_command$compile_rpath
10442521070a0Smrg	# Replace the output file specification.
10443ff63a143Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10444521070a0Smrg	# Delete the old output file.
10445521070a0Smrg	$opt_dry_run || $RM $output
10446521070a0Smrg	# Link the executable and exit
10447521070a0Smrg	func_show_eval "$link_command" 'exit $?'
104483e6c936aSmrg
104493e6c936aSmrg	if test -n "$postlink_cmds"; then
104503e6c936aSmrg	  func_to_tool_file "$output"
104513e6c936aSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
104523e6c936aSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
104533e6c936aSmrg	fi
104543e6c936aSmrg
104554456fccdSmrg	exit $EXIT_SUCCESS
10456521070a0Smrg      fi
104574456fccdSmrg
10458b0a0317aSmrg      case $hardcode_action,$fast_install in
10459b0a0317aSmrg        relink,*)
10460b0a0317aSmrg	  # Fast installation is not supported
10461b0a0317aSmrg	  link_command=$compile_var$compile_command$compile_rpath
10462b0a0317aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10463521070a0Smrg
10464b0a0317aSmrg	  func_warning "this platform does not like uninstalled shared libraries"
10465b0a0317aSmrg	  func_warning "'$output' will be relinked during installation"
10466b0a0317aSmrg	  ;;
10467b0a0317aSmrg        *,yes)
10468b0a0317aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10469b0a0317aSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10470b0a0317aSmrg          ;;
10471b0a0317aSmrg	*,no)
10472b0a0317aSmrg	  link_command=$compile_var$compile_command$compile_rpath
10473b0a0317aSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10474b0a0317aSmrg          ;;
10475b0a0317aSmrg	*,needless)
10476b0a0317aSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10477b0a0317aSmrg	  relink_command=
10478b0a0317aSmrg          ;;
10479b0a0317aSmrg      esac
104804456fccdSmrg
10481521070a0Smrg      # Replace the output file specification.
10482ff63a143Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
104834456fccdSmrg
10484521070a0Smrg      # Delete the old output files.
10485521070a0Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
104864456fccdSmrg
10487521070a0Smrg      func_show_eval "$link_command" 'exit $?'
104884456fccdSmrg
104893e6c936aSmrg      if test -n "$postlink_cmds"; then
104903e6c936aSmrg	func_to_tool_file "$output_objdir/$outputname"
104913e6c936aSmrg	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'`
104923e6c936aSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
104933e6c936aSmrg      fi
104943e6c936aSmrg
10495521070a0Smrg      # Now create the wrapper script.
10496521070a0Smrg      func_verbose "creating $output"
104974456fccdSmrg
10498521070a0Smrg      # Quote the relink command for shipping.
10499521070a0Smrg      if test -n "$relink_command"; then
10500521070a0Smrg	# Preserve any variables that may affect compiler behavior
10501521070a0Smrg	for var in $variables_saved_for_relink; do
10502521070a0Smrg	  if eval test -z \"\${$var+set}\"; then
10503521070a0Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10504521070a0Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10505521070a0Smrg	    relink_command="$var=; export $var; $relink_command"
105064456fccdSmrg	  else
10507521070a0Smrg	    func_quote_for_eval "$var_value"
10508521070a0Smrg	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
105094456fccdSmrg	  fi
10510521070a0Smrg	done
10511521070a0Smrg	relink_command="(cd `pwd`; $relink_command)"
10512ff63a143Smrg	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
10513521070a0Smrg      fi
10514521070a0Smrg
10515521070a0Smrg      # Only actually do things if not in dry run mode.
10516521070a0Smrg      $opt_dry_run || {
10517521070a0Smrg	# win32 will think the script is a binary if it has
10518521070a0Smrg	# a .exe suffix, so we strip it off here.
10519521070a0Smrg	case $output in
10520521070a0Smrg	  *.exe) func_stripname '' '.exe' "$output"
10521521070a0Smrg	         output=$func_stripname_result ;;
10522521070a0Smrg	esac
10523521070a0Smrg	# test for cygwin because mv fails w/o .exe extensions
10524521070a0Smrg	case $host in
10525521070a0Smrg	  *cygwin*)
10526521070a0Smrg	    exeext=.exe
10527521070a0Smrg	    func_stripname '' '.exe' "$outputname"
10528521070a0Smrg	    outputname=$func_stripname_result ;;
10529521070a0Smrg	  *) exeext= ;;
105304456fccdSmrg	esac
10531521070a0Smrg	case $host in
10532521070a0Smrg	  *cygwin* | *mingw* )
10533521070a0Smrg	    func_dirname_and_basename "$output" "" "."
10534521070a0Smrg	    output_name=$func_basename_result
10535521070a0Smrg	    output_path=$func_dirname_result
10536b0a0317aSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10537b0a0317aSmrg	    cwrapper=$output_path/$output_name.exe
10538521070a0Smrg	    $RM $cwrappersource $cwrapper
10539521070a0Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10540521070a0Smrg
10541521070a0Smrg	    func_emit_cwrapperexe_src > $cwrappersource
10542521070a0Smrg
10543521070a0Smrg	    # The wrapper executable is built using the $host compiler,
10544521070a0Smrg	    # because it contains $host paths and files. If cross-
10545521070a0Smrg	    # compiling, it, like the target executable, must be
10546521070a0Smrg	    # executed on the $host or under an emulation environment.
10547521070a0Smrg	    $opt_dry_run || {
10548521070a0Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10549521070a0Smrg	      $STRIP $cwrapper
10550521070a0Smrg	    }
105514456fccdSmrg
10552521070a0Smrg	    # Now, create the wrapper script for func_source use:
10553521070a0Smrg	    func_ltwrapper_scriptname $cwrapper
10554521070a0Smrg	    $RM $func_ltwrapper_scriptname_result
10555521070a0Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10556521070a0Smrg	    $opt_dry_run || {
10557521070a0Smrg	      # note: this script will not be executed, so do not chmod.
10558b0a0317aSmrg	      if test "x$build" = "x$host"; then
10559521070a0Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10560521070a0Smrg	      else
10561521070a0Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10562521070a0Smrg	      fi
10563521070a0Smrg	    }
10564521070a0Smrg	  ;;
10565521070a0Smrg	  * )
10566521070a0Smrg	    $RM $output
10567521070a0Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
105684456fccdSmrg
10569521070a0Smrg	    func_emit_wrapper no > $output
10570521070a0Smrg	    chmod +x $output
10571521070a0Smrg	  ;;
10572521070a0Smrg	esac
10573521070a0Smrg      }
10574521070a0Smrg      exit $EXIT_SUCCESS
10575521070a0Smrg      ;;
10576521070a0Smrg    esac
105774456fccdSmrg
10578521070a0Smrg    # See if we need to build an old-fashioned archive.
10579521070a0Smrg    for oldlib in $oldlibs; do
105804456fccdSmrg
10581b0a0317aSmrg      case $build_libtool_libs in
10582b0a0317aSmrg        convenience)
10583b0a0317aSmrg	  oldobjs="$libobjs_save $symfileobj"
10584b0a0317aSmrg	  addlibs=$convenience
10585521070a0Smrg	  build_libtool_libs=no
10586b0a0317aSmrg	  ;;
10587b0a0317aSmrg	module)
10588b0a0317aSmrg	  oldobjs=$libobjs_save
10589b0a0317aSmrg	  addlibs=$old_convenience
10590b0a0317aSmrg	  build_libtool_libs=no
10591b0a0317aSmrg          ;;
10592b0a0317aSmrg	*)
10593521070a0Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10594b0a0317aSmrg	  $preload && test -f "$symfileobj" \
10595b0a0317aSmrg	    && func_append oldobjs " $symfileobj"
10596b0a0317aSmrg	  addlibs=$old_convenience
10597b0a0317aSmrg	  ;;
10598b0a0317aSmrg      esac
105994456fccdSmrg
10600521070a0Smrg      if test -n "$addlibs"; then
10601b0a0317aSmrg	gentop=$output_objdir/${outputname}x
106023e6c936aSmrg	func_append generated " $gentop"
106034456fccdSmrg
10604521070a0Smrg	func_extract_archives $gentop $addlibs
106053e6c936aSmrg	func_append oldobjs " $func_extract_archives_result"
10606521070a0Smrg      fi
106074456fccdSmrg
10608521070a0Smrg      # Do each command in the archive commands.
10609b0a0317aSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10610521070a0Smrg	cmds=$old_archive_from_new_cmds
10611521070a0Smrg      else
106124456fccdSmrg
10613521070a0Smrg	# Add any objects from preloaded convenience libraries
10614521070a0Smrg	if test -n "$dlprefiles"; then
10615b0a0317aSmrg	  gentop=$output_objdir/${outputname}x
106163e6c936aSmrg	  func_append generated " $gentop"
106174456fccdSmrg
10618521070a0Smrg	  func_extract_archives $gentop $dlprefiles
106193e6c936aSmrg	  func_append oldobjs " $func_extract_archives_result"
10620521070a0Smrg	fi
106214456fccdSmrg
10622521070a0Smrg	# POSIX demands no paths to be encoded in archives.  We have
10623521070a0Smrg	# to avoid creating archives with duplicate basenames if we
10624521070a0Smrg	# might have to extract them afterwards, e.g., when creating a
10625521070a0Smrg	# static archive out of a convenience library, or when linking
10626521070a0Smrg	# the entirety of a libtool archive into another (currently
10627521070a0Smrg	# not supported by libtool).
10628521070a0Smrg	if (for obj in $oldobjs
10629521070a0Smrg	    do
10630521070a0Smrg	      func_basename "$obj"
10631521070a0Smrg	      $ECHO "$func_basename_result"
10632521070a0Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
10633521070a0Smrg	  :
10634521070a0Smrg	else
10635ff63a143Smrg	  echo "copying selected object files to avoid basename conflicts..."
10636b0a0317aSmrg	  gentop=$output_objdir/${outputname}x
106373e6c936aSmrg	  func_append generated " $gentop"
10638521070a0Smrg	  func_mkdir_p "$gentop"
10639521070a0Smrg	  save_oldobjs=$oldobjs
10640521070a0Smrg	  oldobjs=
10641521070a0Smrg	  counter=1
10642521070a0Smrg	  for obj in $save_oldobjs
10643521070a0Smrg	  do
10644521070a0Smrg	    func_basename "$obj"
10645b0a0317aSmrg	    objbase=$func_basename_result
10646521070a0Smrg	    case " $oldobjs " in
10647521070a0Smrg	    " ") oldobjs=$obj ;;
10648521070a0Smrg	    *[\ /]"$objbase "*)
10649521070a0Smrg	      while :; do
10650521070a0Smrg		# Make sure we don't pick an alternate name that also
10651521070a0Smrg		# overlaps.
10652521070a0Smrg		newobj=lt$counter-$objbase
10653521070a0Smrg		func_arith $counter + 1
10654521070a0Smrg		counter=$func_arith_result
10655521070a0Smrg		case " $oldobjs " in
10656521070a0Smrg		*[\ /]"$newobj "*) ;;
10657521070a0Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10658521070a0Smrg		esac
10659521070a0Smrg	      done
10660521070a0Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
106613e6c936aSmrg	      func_append oldobjs " $gentop/$newobj"
10662521070a0Smrg	      ;;
106633e6c936aSmrg	    *) func_append oldobjs " $obj" ;;
10664521070a0Smrg	    esac
106654456fccdSmrg	  done
106664456fccdSmrg	fi
106673e6c936aSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
106683e6c936aSmrg	tool_oldlib=$func_to_tool_file_result
10669521070a0Smrg	eval cmds=\"$old_archive_cmds\"
106704456fccdSmrg
10671521070a0Smrg	func_len " $cmds"
10672521070a0Smrg	len=$func_len_result
10673521070a0Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10674521070a0Smrg	  cmds=$old_archive_cmds
106753e6c936aSmrg	elif test -n "$archiver_list_spec"; then
106763e6c936aSmrg	  func_verbose "using command file archive linking..."
106773e6c936aSmrg	  for obj in $oldobjs
106783e6c936aSmrg	  do
106793e6c936aSmrg	    func_to_tool_file "$obj"
106803e6c936aSmrg	    $ECHO "$func_to_tool_file_result"
106813e6c936aSmrg	  done > $output_objdir/$libname.libcmd
106823e6c936aSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
106833e6c936aSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
106843e6c936aSmrg	  cmds=$old_archive_cmds
10685521070a0Smrg	else
10686521070a0Smrg	  # the command line is too long to link in one step, link in parts
10687521070a0Smrg	  func_verbose "using piecewise archive linking..."
10688521070a0Smrg	  save_RANLIB=$RANLIB
10689521070a0Smrg	  RANLIB=:
10690521070a0Smrg	  objlist=
10691521070a0Smrg	  concat_cmds=
10692521070a0Smrg	  save_oldobjs=$oldobjs
10693521070a0Smrg	  oldobjs=
10694521070a0Smrg	  # Is there a better way of finding the last object in the list?
10695521070a0Smrg	  for obj in $save_oldobjs
10696521070a0Smrg	  do
10697521070a0Smrg	    last_oldobj=$obj
10698521070a0Smrg	  done
10699521070a0Smrg	  eval test_cmds=\"$old_archive_cmds\"
10700521070a0Smrg	  func_len " $test_cmds"
10701521070a0Smrg	  len0=$func_len_result
10702521070a0Smrg	  len=$len0
10703521070a0Smrg	  for obj in $save_oldobjs
10704521070a0Smrg	  do
10705521070a0Smrg	    func_len " $obj"
10706521070a0Smrg	    func_arith $len + $func_len_result
10707521070a0Smrg	    len=$func_arith_result
10708521070a0Smrg	    func_append objlist " $obj"
10709521070a0Smrg	    if test "$len" -lt "$max_cmd_len"; then
10710521070a0Smrg	      :
10711521070a0Smrg	    else
10712521070a0Smrg	      # the above command should be used before it gets too long
10713521070a0Smrg	      oldobjs=$objlist
10714b0a0317aSmrg	      if test "$obj" = "$last_oldobj"; then
10715521070a0Smrg		RANLIB=$save_RANLIB
10716521070a0Smrg	      fi
10717521070a0Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10718b0a0317aSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
10719521070a0Smrg	      objlist=
10720521070a0Smrg	      len=$len0
10721521070a0Smrg	    fi
10722521070a0Smrg	  done
10723521070a0Smrg	  RANLIB=$save_RANLIB
10724521070a0Smrg	  oldobjs=$objlist
10725b0a0317aSmrg	  if test -z "$oldobjs"; then
10726521070a0Smrg	    eval cmds=\"\$concat_cmds\"
10727521070a0Smrg	  else
10728521070a0Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
10729521070a0Smrg	  fi
10730521070a0Smrg	fi
10731521070a0Smrg      fi
10732521070a0Smrg      func_execute_cmds "$cmds" 'exit $?'
107334456fccdSmrg    done
107344456fccdSmrg
10735521070a0Smrg    test -n "$generated" && \
10736521070a0Smrg      func_show_eval "${RM}r$generated"
107374456fccdSmrg
10738521070a0Smrg    # Now create the libtool archive.
10739521070a0Smrg    case $output in
10740521070a0Smrg    *.la)
10741521070a0Smrg      old_library=
10742b0a0317aSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
10743521070a0Smrg      func_verbose "creating $output"
107444456fccdSmrg
10745521070a0Smrg      # Preserve any variables that may affect compiler behavior
10746521070a0Smrg      for var in $variables_saved_for_relink; do
10747521070a0Smrg	if eval test -z \"\${$var+set}\"; then
10748521070a0Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10749521070a0Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
10750521070a0Smrg	  relink_command="$var=; export $var; $relink_command"
107514456fccdSmrg	else
10752521070a0Smrg	  func_quote_for_eval "$var_value"
10753521070a0Smrg	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
107544456fccdSmrg	fi
10755521070a0Smrg      done
10756521070a0Smrg      # Quote the link command for shipping.
10757b0a0317aSmrg      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
10758ff63a143Smrg      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
10759b0a0317aSmrg      if test yes = "$hardcode_automatic"; then
10760521070a0Smrg	relink_command=
10761521070a0Smrg      fi
107624456fccdSmrg
10763521070a0Smrg      # Only create the output if not a dry run.
10764521070a0Smrg      $opt_dry_run || {
10765521070a0Smrg	for installed in no yes; do
10766b0a0317aSmrg	  if test yes = "$installed"; then
10767521070a0Smrg	    if test -z "$install_libdir"; then
10768521070a0Smrg	      break
10769521070a0Smrg	    fi
10770b0a0317aSmrg	    output=$output_objdir/${outputname}i
10771521070a0Smrg	    # Replace all uninstalled libtool libraries with the installed ones
10772521070a0Smrg	    newdependency_libs=
10773521070a0Smrg	    for deplib in $dependency_libs; do
10774521070a0Smrg	      case $deplib in
10775521070a0Smrg	      *.la)
10776521070a0Smrg		func_basename "$deplib"
10777b0a0317aSmrg		name=$func_basename_result
107783e6c936aSmrg		func_resolve_sysroot "$deplib"
10779b0a0317aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
10780521070a0Smrg		test -z "$libdir" && \
10781b0a0317aSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
107823e6c936aSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
107833e6c936aSmrg		;;
107843e6c936aSmrg	      -L*)
107853e6c936aSmrg		func_stripname -L '' "$deplib"
107863e6c936aSmrg		func_replace_sysroot "$func_stripname_result"
107873e6c936aSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
107883e6c936aSmrg		;;
107893e6c936aSmrg	      -R*)
107903e6c936aSmrg		func_stripname -R '' "$deplib"
107913e6c936aSmrg		func_replace_sysroot "$func_stripname_result"
107923e6c936aSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
10793521070a0Smrg		;;
107943e6c936aSmrg	      *) func_append newdependency_libs " $deplib" ;;
10795521070a0Smrg	      esac
10796521070a0Smrg	    done
10797b0a0317aSmrg	    dependency_libs=$newdependency_libs
10798521070a0Smrg	    newdlfiles=
10799521070a0Smrg
10800521070a0Smrg	    for lib in $dlfiles; do
10801521070a0Smrg	      case $lib in
10802521070a0Smrg	      *.la)
10803521070a0Smrg	        func_basename "$lib"
10804b0a0317aSmrg		name=$func_basename_result
10805b0a0317aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
10806521070a0Smrg		test -z "$libdir" && \
10807b0a0317aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
108083e6c936aSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
10809521070a0Smrg		;;
108103e6c936aSmrg	      *) func_append newdlfiles " $lib" ;;
10811521070a0Smrg	      esac
10812521070a0Smrg	    done
10813b0a0317aSmrg	    dlfiles=$newdlfiles
10814521070a0Smrg	    newdlprefiles=
10815521070a0Smrg	    for lib in $dlprefiles; do
10816521070a0Smrg	      case $lib in
10817521070a0Smrg	      *.la)
10818521070a0Smrg		# Only pass preopened files to the pseudo-archive (for
10819521070a0Smrg		# eventual linking with the app. that links it) if we
10820521070a0Smrg		# didn't already link the preopened objects directly into
10821521070a0Smrg		# the library:
10822521070a0Smrg		func_basename "$lib"
10823b0a0317aSmrg		name=$func_basename_result
10824b0a0317aSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
10825521070a0Smrg		test -z "$libdir" && \
10826b0a0317aSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
108273e6c936aSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
10828521070a0Smrg		;;
10829521070a0Smrg	      esac
10830521070a0Smrg	    done
10831b0a0317aSmrg	    dlprefiles=$newdlprefiles
10832521070a0Smrg	  else
10833521070a0Smrg	    newdlfiles=
10834521070a0Smrg	    for lib in $dlfiles; do
10835521070a0Smrg	      case $lib in
10836b0a0317aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
10837521070a0Smrg		*) abs=`pwd`"/$lib" ;;
10838521070a0Smrg	      esac
108393e6c936aSmrg	      func_append newdlfiles " $abs"
10840521070a0Smrg	    done
10841b0a0317aSmrg	    dlfiles=$newdlfiles
10842521070a0Smrg	    newdlprefiles=
10843521070a0Smrg	    for lib in $dlprefiles; do
10844521070a0Smrg	      case $lib in
10845b0a0317aSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
10846521070a0Smrg		*) abs=`pwd`"/$lib" ;;
10847521070a0Smrg	      esac
108483e6c936aSmrg	      func_append newdlprefiles " $abs"
10849521070a0Smrg	    done
10850b0a0317aSmrg	    dlprefiles=$newdlprefiles
10851521070a0Smrg	  fi
10852521070a0Smrg	  $RM $output
10853521070a0Smrg	  # place dlname in correct position for cygwin
10854ff63a143Smrg	  # In fact, it would be nice if we could use this code for all target
10855ff63a143Smrg	  # systems that can't hard-code library paths into their executables
10856ff63a143Smrg	  # and that have no shared library path variable independent of PATH,
10857ff63a143Smrg	  # but it turns out we can't easily determine that from inspecting
10858ff63a143Smrg	  # libtool variables, so we have to hard-code the OSs to which it
10859ff63a143Smrg	  # applies here; at the moment, that means platforms that use the PE
10860ff63a143Smrg	  # object format with DLL files.  See the long comment at the top of
10861ff63a143Smrg	  # tests/bindir.at for full details.
10862521070a0Smrg	  tdlname=$dlname
10863521070a0Smrg	  case $host,$output,$installed,$module,$dlname in
10864ff63a143Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
10865ff63a143Smrg	      # If a -bindir argument was supplied, place the dll there.
10866b0a0317aSmrg	      if test -n "$bindir"; then
10867ff63a143Smrg		func_relative_path "$install_libdir" "$bindir"
10868b0a0317aSmrg		tdlname=$func_relative_path_result/$dlname
10869ff63a143Smrg	      else
10870ff63a143Smrg		# Otherwise fall back on heuristic.
10871ff63a143Smrg		tdlname=../bin/$dlname
10872ff63a143Smrg	      fi
10873ff63a143Smrg	      ;;
10874521070a0Smrg	  esac
10875521070a0Smrg	  $ECHO > $output "\
10876521070a0Smrg# $outputname - a libtool library file
10877b0a0317aSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
10878521070a0Smrg#
10879521070a0Smrg# Please DO NOT delete this file!
10880521070a0Smrg# It is necessary for linking the library.
108814456fccdSmrg
10882521070a0Smrg# The name that we can dlopen(3).
10883521070a0Smrgdlname='$tdlname'
108844456fccdSmrg
10885521070a0Smrg# Names of this library.
10886521070a0Smrglibrary_names='$library_names'
108874456fccdSmrg
10888521070a0Smrg# The name of the static archive.
10889521070a0Smrgold_library='$old_library'
108904456fccdSmrg
10891b0a0317aSmrg# Linker flags that cannot go in dependency_libs.
10892521070a0Smrginherited_linker_flags='$new_inherited_linker_flags'
108934456fccdSmrg
10894521070a0Smrg# Libraries that this one depends upon.
10895521070a0Smrgdependency_libs='$dependency_libs'
108964456fccdSmrg
10897521070a0Smrg# Names of additional weak libraries provided by this library
10898521070a0Smrgweak_library_names='$weak_libs'
108994456fccdSmrg
10900521070a0Smrg# Version information for $libname.
10901521070a0Smrgcurrent=$current
10902521070a0Smrgage=$age
10903521070a0Smrgrevision=$revision
109044456fccdSmrg
10905521070a0Smrg# Is this an already installed library?
10906521070a0Smrginstalled=$installed
109074456fccdSmrg
10908521070a0Smrg# Should we warn about portability when linking against -modules?
10909521070a0Smrgshouldnotlink=$module
109104456fccdSmrg
10911521070a0Smrg# Files to dlopen/dlpreopen
10912521070a0Smrgdlopen='$dlfiles'
10913521070a0Smrgdlpreopen='$dlprefiles'
109144456fccdSmrg
10915521070a0Smrg# Directory that this library needs to be installed in:
10916521070a0Smrglibdir='$install_libdir'"
10917b0a0317aSmrg	  if test no,yes = "$installed,$need_relink"; then
10918521070a0Smrg	    $ECHO >> $output "\
10919521070a0Smrgrelink_command=\"$relink_command\""
10920521070a0Smrg	  fi
10921521070a0Smrg	done
10922521070a0Smrg      }
109234456fccdSmrg
10924521070a0Smrg      # Do a symbolic link so that the libtool archive can be found in
10925521070a0Smrg      # LD_LIBRARY_PATH before the program is installed.
10926521070a0Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
10927521070a0Smrg      ;;
10928521070a0Smrg    esac
10929521070a0Smrg    exit $EXIT_SUCCESS
10930521070a0Smrg}
109314456fccdSmrg
10932b0a0317aSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
10933b0a0317aSmrg  func_mode_link ${1+"$@"}
10934b0a0317aSmrgfi
109354456fccdSmrg
109364456fccdSmrg
10937521070a0Smrg# func_mode_uninstall arg...
10938521070a0Smrgfunc_mode_uninstall ()
10939521070a0Smrg{
10940b0a0317aSmrg    $debug_cmd
10941b0a0317aSmrg
10942b0a0317aSmrg    RM=$nonopt
109434456fccdSmrg    files=
10944b0a0317aSmrg    rmforce=false
109454456fccdSmrg    exit_status=0
109464456fccdSmrg
109474456fccdSmrg    # This variable tells wrapper scripts just to set variables rather
109484456fccdSmrg    # than running their programs.
10949b0a0317aSmrg    libtool_install_magic=$magic
109504456fccdSmrg
109514456fccdSmrg    for arg
109524456fccdSmrg    do
109534456fccdSmrg      case $arg in
10954b0a0317aSmrg      -f) func_append RM " $arg"; rmforce=: ;;
109553e6c936aSmrg      -*) func_append RM " $arg" ;;
109563e6c936aSmrg      *) func_append files " $arg" ;;
109574456fccdSmrg      esac
109584456fccdSmrg    done
109594456fccdSmrg
10960521070a0Smrg    test -z "$RM" && \
10961521070a0Smrg      func_fatal_help "you must specify an RM program"
109624456fccdSmrg
109634456fccdSmrg    rmdirs=
109644456fccdSmrg
109654456fccdSmrg    for file in $files; do
10966521070a0Smrg      func_dirname "$file" "" "."
10967b0a0317aSmrg      dir=$func_dirname_result
10968b0a0317aSmrg      if test . = "$dir"; then
10969b0a0317aSmrg	odir=$objdir
109704456fccdSmrg      else
10971b0a0317aSmrg	odir=$dir/$objdir
109724456fccdSmrg      fi
10973521070a0Smrg      func_basename "$file"
10974b0a0317aSmrg      name=$func_basename_result
10975b0a0317aSmrg      test uninstall = "$opt_mode" && odir=$dir
109764456fccdSmrg
109773e6c936aSmrg      # Remember odir for removal later, being careful to avoid duplicates
10978b0a0317aSmrg      if test clean = "$opt_mode"; then
109794456fccdSmrg	case " $rmdirs " in
109803e6c936aSmrg	  *" $odir "*) ;;
109813e6c936aSmrg	  *) func_append rmdirs " $odir" ;;
109824456fccdSmrg	esac
109834456fccdSmrg      fi
109844456fccdSmrg
109854456fccdSmrg      # Don't error if the file doesn't exist and rm -f was used.
10986521070a0Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
10987521070a0Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
10988521070a0Smrg	 test -f "$file"; then
109894456fccdSmrg	:
109904456fccdSmrg      elif test -d "$file"; then
109914456fccdSmrg	exit_status=1
109924456fccdSmrg	continue
10993b0a0317aSmrg      elif $rmforce; then
109944456fccdSmrg	continue
109954456fccdSmrg      fi
109964456fccdSmrg
10997b0a0317aSmrg      rmfiles=$file
109984456fccdSmrg
109994456fccdSmrg      case $name in
110004456fccdSmrg      *.la)
110014456fccdSmrg	# Possibly a libtool archive, so verify it.
11002521070a0Smrg	if func_lalib_p "$file"; then
11003521070a0Smrg	  func_source $dir/$name
110044456fccdSmrg
110054456fccdSmrg	  # Delete the libtool libraries and symlinks.
110064456fccdSmrg	  for n in $library_names; do
110073e6c936aSmrg	    func_append rmfiles " $odir/$n"
110084456fccdSmrg	  done
110093e6c936aSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
110104456fccdSmrg
11011b0a0317aSmrg	  case $opt_mode in
110124456fccdSmrg	  clean)
110133e6c936aSmrg	    case " $library_names " in
110144456fccdSmrg	    *" $dlname "*) ;;
110153e6c936aSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
110164456fccdSmrg	    esac
110173e6c936aSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
110184456fccdSmrg	    ;;
110194456fccdSmrg	  uninstall)
110204456fccdSmrg	    if test -n "$library_names"; then
110214456fccdSmrg	      # Do each command in the postuninstall commands.
11022b0a0317aSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
110234456fccdSmrg	    fi
110244456fccdSmrg
110254456fccdSmrg	    if test -n "$old_library"; then
110264456fccdSmrg	      # Do each command in the old_postuninstall commands.
11027b0a0317aSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
110284456fccdSmrg	    fi
110294456fccdSmrg	    # FIXME: should reinstall the best remaining shared library.
110304456fccdSmrg	    ;;
110314456fccdSmrg	  esac
110324456fccdSmrg	fi
110334456fccdSmrg	;;
110344456fccdSmrg
110354456fccdSmrg      *.lo)
110364456fccdSmrg	# Possibly a libtool object, so verify it.
11037521070a0Smrg	if func_lalib_p "$file"; then
110384456fccdSmrg
110394456fccdSmrg	  # Read the .lo file
11040521070a0Smrg	  func_source $dir/$name
110414456fccdSmrg
110424456fccdSmrg	  # Add PIC object to the list of files to remove.
11043b0a0317aSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
110443e6c936aSmrg	    func_append rmfiles " $dir/$pic_object"
110454456fccdSmrg	  fi
110464456fccdSmrg
110474456fccdSmrg	  # Add non-PIC object to the list of files to remove.
11048b0a0317aSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
110493e6c936aSmrg	    func_append rmfiles " $dir/$non_pic_object"
110504456fccdSmrg	  fi
110514456fccdSmrg	fi
110524456fccdSmrg	;;
110534456fccdSmrg
110544456fccdSmrg      *)
11055b0a0317aSmrg	if test clean = "$opt_mode"; then
110564456fccdSmrg	  noexename=$name
110574456fccdSmrg	  case $file in
110584456fccdSmrg	  *.exe)
11059521070a0Smrg	    func_stripname '' '.exe' "$file"
11060521070a0Smrg	    file=$func_stripname_result
11061521070a0Smrg	    func_stripname '' '.exe' "$name"
11062521070a0Smrg	    noexename=$func_stripname_result
110634456fccdSmrg	    # $file with .exe has already been added to rmfiles,
110644456fccdSmrg	    # add $file without .exe
110653e6c936aSmrg	    func_append rmfiles " $file"
110664456fccdSmrg	    ;;
110674456fccdSmrg	  esac
110684456fccdSmrg	  # Do a test to see if this is a libtool program.
11069521070a0Smrg	  if func_ltwrapper_p "$file"; then
11070521070a0Smrg	    if func_ltwrapper_executable_p "$file"; then
11071521070a0Smrg	      func_ltwrapper_scriptname "$file"
11072521070a0Smrg	      relink_command=
11073521070a0Smrg	      func_source $func_ltwrapper_scriptname_result
110743e6c936aSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11075521070a0Smrg	    else
11076521070a0Smrg	      relink_command=
11077521070a0Smrg	      func_source $dir/$noexename
11078521070a0Smrg	    fi
110794456fccdSmrg
110804456fccdSmrg	    # note $name still contains .exe if it was in $file originally
110814456fccdSmrg	    # as does the version of $file that was added into $rmfiles
11082b0a0317aSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11083b0a0317aSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
110843e6c936aSmrg	      func_append rmfiles " $odir/lt-$name"
110854456fccdSmrg	    fi
11086b0a0317aSmrg	    if test "X$noexename" != "X$name"; then
11087b0a0317aSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
110884456fccdSmrg	    fi
110894456fccdSmrg	  fi
110904456fccdSmrg	fi
110914456fccdSmrg	;;
110924456fccdSmrg      esac
11093521070a0Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
110944456fccdSmrg    done
110954456fccdSmrg
11096b0a0317aSmrg    # Try to remove the $objdir's in the directories where we deleted files
110974456fccdSmrg    for dir in $rmdirs; do
110984456fccdSmrg      if test -d "$dir"; then
11099521070a0Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
111004456fccdSmrg      fi
111014456fccdSmrg    done
111024456fccdSmrg
111034456fccdSmrg    exit $exit_status
11104521070a0Smrg}
111054456fccdSmrg
11106b0a0317aSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11107b0a0317aSmrg  func_mode_uninstall ${1+"$@"}
11108b0a0317aSmrgfi
111094456fccdSmrg
111103e6c936aSmrgtest -z "$opt_mode" && {
11111b0a0317aSmrg  help=$generic_help
11112521070a0Smrg  func_fatal_help "you must specify a MODE"
11113521070a0Smrg}
11114521070a0Smrg
11115521070a0Smrgtest -z "$exec_cmd" && \
11116b0a0317aSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
111174456fccdSmrg
111184456fccdSmrgif test -n "$exec_cmd"; then
11119521070a0Smrg  eval exec "$exec_cmd"
111204456fccdSmrg  exit $EXIT_FAILURE
111214456fccdSmrgfi
111224456fccdSmrg
11123521070a0Smrgexit $exit_status
111244456fccdSmrg
111254456fccdSmrg
111264456fccdSmrg# The TAGs below are defined such that we never get into a situation
11127b0a0317aSmrg# where we disable both kinds of libraries.  Given conflicting
111284456fccdSmrg# choices, we go for a static library, that is the most portable,
111294456fccdSmrg# since we can't tell whether shared libraries were disabled because
111304456fccdSmrg# the user asked for that or because the platform doesn't support
111314456fccdSmrg# them.  This is particularly important on AIX, because we don't
111324456fccdSmrg# support having both static and shared libraries enabled at the same
111334456fccdSmrg# time on that platform, so we default to a shared-only configuration.
111344456fccdSmrg# If a disable-shared tag is given, we'll fallback to a static-only
111354456fccdSmrg# configuration.  But we'll never go from static-only to shared-only.
111364456fccdSmrg
111374456fccdSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11138521070a0Smrgbuild_libtool_libs=no
11139521070a0Smrgbuild_old_libs=yes
111404456fccdSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
111414456fccdSmrg
111424456fccdSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11143521070a0Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
111444456fccdSmrg# ### END LIBTOOL TAG CONFIG: disable-static
111454456fccdSmrg
111464456fccdSmrg# Local Variables:
111474456fccdSmrg# mode:shell-script
111484456fccdSmrg# sh-indentation:2
111494456fccdSmrg# End:
11150