ltmain.sh revision b7d26471
1b7d26471Smrg#! /bin/sh
2b7d26471Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3b7d26471Smrg##               by inline-source v2014-01-03.01
45ffd6003Smrg
5b7d26471Smrg# libtool (GNU libtool) 2.4.6
6b7d26471Smrg# Provide generalized library-building support services.
75ffd6003Smrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
85ffd6003Smrg
9b7d26471Smrg# Copyright (C) 1996-2015 Free Software Foundation, Inc.
105ffd6003Smrg# This is free software; see the source for copying conditions.  There is NO
115ffd6003Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
125ffd6003Smrg
135ffd6003Smrg# GNU Libtool is free software; you can redistribute it and/or modify
14145b7b3cSmrg# it under the terms of the GNU General Public License as published by
15145b7b3cSmrg# the Free Software Foundation; either version 2 of the License, or
16145b7b3cSmrg# (at your option) any later version.
17145b7b3cSmrg#
185ffd6003Smrg# As a special exception to the GNU General Public License,
195ffd6003Smrg# if you distribute this file as part of a program or library that
205ffd6003Smrg# is built using GNU Libtool, you may include this file under the
215ffd6003Smrg# same distribution terms that you use for the rest of that program.
225ffd6003Smrg#
235ffd6003Smrg# GNU Libtool is distributed in the hope that it will be useful, but
24145b7b3cSmrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25145b7b3cSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26145b7b3cSmrg# General Public License for more details.
27145b7b3cSmrg#
28145b7b3cSmrg# You should have received a copy of the GNU General Public License
29b7d26471Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30145b7b3cSmrg
31145b7b3cSmrg
32629baa8cSmrgPROGRAM=libtool
33145b7b3cSmrgPACKAGE=libtool
34b7d26471SmrgVERSION=2.4.6
35b7d26471Smrgpackage_revision=2.4.6
36578741aaSmrg
37b7d26471Smrg
38b7d26471Smrg## ------ ##
39b7d26471Smrg## Usage. ##
40b7d26471Smrg## ------ ##
41b7d26471Smrg
42b7d26471Smrg# Run './libtool --help' for help with using this script from the
43b7d26471Smrg# command line.
44b7d26471Smrg
45b7d26471Smrg
46b7d26471Smrg## ------------------------------- ##
47b7d26471Smrg## User overridable command paths. ##
48b7d26471Smrg## ------------------------------- ##
49b7d26471Smrg
50b7d26471Smrg# After configure completes, it has a better idea of some of the
51b7d26471Smrg# shell tools we need than the defaults used by the functions shared
52b7d26471Smrg# with bootstrap, so set those here where they can still be over-
53b7d26471Smrg# ridden by the user, but otherwise take precedence.
54b7d26471Smrg
55b7d26471Smrg: ${AUTOCONF="autoconf"}
56b7d26471Smrg: ${AUTOMAKE="automake"}
57b7d26471Smrg
58b7d26471Smrg
59b7d26471Smrg## -------------------------- ##
60b7d26471Smrg## Source external libraries. ##
61b7d26471Smrg## -------------------------- ##
62b7d26471Smrg
63b7d26471Smrg# Much of our low-level functionality needs to be sourced from external
64b7d26471Smrg# libraries, which are installed to $pkgauxdir.
65b7d26471Smrg
66b7d26471Smrg# Set a version string for this script.
67b7d26471Smrgscriptversion=2015-01-20.17; # UTC
68b7d26471Smrg
69b7d26471Smrg# General shell script boiler plate, and helper functions.
70b7d26471Smrg# Written by Gary V. Vaughan, 2004
71b7d26471Smrg
72b7d26471Smrg# Copyright (C) 2004-2015 Free Software Foundation, Inc.
73b7d26471Smrg# This is free software; see the source for copying conditions.  There is NO
74b7d26471Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75b7d26471Smrg
76b7d26471Smrg# This program is free software; you can redistribute it and/or modify
77b7d26471Smrg# it under the terms of the GNU General Public License as published by
78b7d26471Smrg# the Free Software Foundation; either version 3 of the License, or
79b7d26471Smrg# (at your option) any later version.
80b7d26471Smrg
81b7d26471Smrg# As a special exception to the GNU General Public License, if you distribute
82b7d26471Smrg# this file as part of a program or library that is built using GNU Libtool,
83b7d26471Smrg# you may include this file under the same distribution terms that you use
84b7d26471Smrg# for the rest of that program.
85b7d26471Smrg
86b7d26471Smrg# This program is distributed in the hope that it will be useful,
87b7d26471Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
88b7d26471Smrg# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
89b7d26471Smrg# General Public License for more details.
90b7d26471Smrg
91b7d26471Smrg# You should have received a copy of the GNU General Public License
92b7d26471Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>.
93b7d26471Smrg
94b7d26471Smrg# Please report bugs or propose patches to gary@gnu.org.
95b7d26471Smrg
96b7d26471Smrg
97b7d26471Smrg## ------ ##
98b7d26471Smrg## Usage. ##
99b7d26471Smrg## ------ ##
100b7d26471Smrg
101b7d26471Smrg# Evaluate this file near the top of your script to gain access to
102b7d26471Smrg# the functions and variables defined here:
103b7d26471Smrg#
104b7d26471Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
105b7d26471Smrg#
106b7d26471Smrg# If you need to override any of the default environment variable
107b7d26471Smrg# settings, do that before evaluating this file.
108b7d26471Smrg
109b7d26471Smrg
110b7d26471Smrg## -------------------- ##
111b7d26471Smrg## Shell normalisation. ##
112b7d26471Smrg## -------------------- ##
113b7d26471Smrg
114b7d26471Smrg# Some shells need a little help to be as Bourne compatible as possible.
115b7d26471Smrg# Before doing anything else, make sure all that help has been provided!
116b7d26471Smrg
117b7d26471SmrgDUALCASE=1; export DUALCASE # for MKS sh
118b7d26471Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
119578741aaSmrg  emulate sh
120578741aaSmrg  NULLCMD=:
121b7d26471Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
122578741aaSmrg  # is contrary to our usage.  Disable this feature.
123578741aaSmrg  alias -g '${1+"$@"}'='"$@"'
124145b7b3cSmrg  setopt NO_GLOB_SUBST
125578741aaSmrgelse
126b7d26471Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
127145b7b3cSmrgfi
128629baa8cSmrg
129b7d26471Smrg# NLS nuisances: We save the old values in case they are required later.
130b7d26471Smrg_G_user_locale=
131b7d26471Smrg_G_safe_locale=
132b7d26471Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
133578741aaSmrgdo
134b7d26471Smrg  eval "if test set = \"\${$_G_var+set}\"; then
135b7d26471Smrg          save_$_G_var=\$$_G_var
136b7d26471Smrg          $_G_var=C
137b7d26471Smrg	  export $_G_var
138b7d26471Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
139b7d26471Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
140578741aaSmrg	fi"
141578741aaSmrgdone
142578741aaSmrg
143b7d26471Smrg# CDPATH.
144b7d26471Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
1455ffd6003Smrg
146b7d26471Smrg# Make sure IFS has a sensible default
147b7d26471Smrgsp=' '
148b7d26471Smrgnl='
149b7d26471Smrg'
150b7d26471SmrgIFS="$sp	$nl"
151b7d26471Smrg
152b7d26471Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
153b7d26471Smrgif test "${PATH_SEPARATOR+set}" != set; then
154b7d26471Smrg  PATH_SEPARATOR=:
155b7d26471Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
156b7d26471Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
157b7d26471Smrg      PATH_SEPARATOR=';'
158b7d26471Smrg  }
159b7d26471Smrgfi
1605ffd6003Smrg
1615ffd6003Smrg
1625ffd6003Smrg
163b7d26471Smrg## ------------------------- ##
164b7d26471Smrg## Locate command utilities. ##
165b7d26471Smrg## ------------------------- ##
166b7d26471Smrg
167b7d26471Smrg
168b7d26471Smrg# func_executable_p FILE
169b7d26471Smrg# ----------------------
170b7d26471Smrg# Check that FILE is an executable regular file.
171b7d26471Smrgfunc_executable_p ()
172b7d26471Smrg{
173b7d26471Smrg    test -f "$1" && test -x "$1"
174b7d26471Smrg}
175b7d26471Smrg
176b7d26471Smrg
177b7d26471Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
178b7d26471Smrg# --------------------------------------------
179b7d26471Smrg# Search for either a program that responds to --version with output
180b7d26471Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
181b7d26471Smrg# trying all the directories in PATH with each of the elements of
182b7d26471Smrg# PROGS_LIST.
183b7d26471Smrg#
184b7d26471Smrg# CHECK_FUNC should accept the path to a candidate program, and
185b7d26471Smrg# set $func_check_prog_result if it truncates its output less than
186b7d26471Smrg# $_G_path_prog_max characters.
187b7d26471Smrgfunc_path_progs ()
188b7d26471Smrg{
189b7d26471Smrg    _G_progs_list=$1
190b7d26471Smrg    _G_check_func=$2
191b7d26471Smrg    _G_PATH=${3-"$PATH"}
192b7d26471Smrg
193b7d26471Smrg    _G_path_prog_max=0
194b7d26471Smrg    _G_path_prog_found=false
195b7d26471Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
196b7d26471Smrg    for _G_dir in $_G_PATH; do
197b7d26471Smrg      IFS=$_G_save_IFS
198b7d26471Smrg      test -z "$_G_dir" && _G_dir=.
199b7d26471Smrg      for _G_prog_name in $_G_progs_list; do
200b7d26471Smrg        for _exeext in '' .EXE; do
201b7d26471Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
202b7d26471Smrg          func_executable_p "$_G_path_prog" || continue
203b7d26471Smrg          case `"$_G_path_prog" --version 2>&1` in
204b7d26471Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
205b7d26471Smrg            *)     $_G_check_func $_G_path_prog
206b7d26471Smrg		   func_path_progs_result=$func_check_prog_result
207b7d26471Smrg		   ;;
208b7d26471Smrg          esac
209b7d26471Smrg          $_G_path_prog_found && break 3
210b7d26471Smrg        done
211b7d26471Smrg      done
212b7d26471Smrg    done
213b7d26471Smrg    IFS=$_G_save_IFS
214b7d26471Smrg    test -z "$func_path_progs_result" && {
215b7d26471Smrg      echo "no acceptable sed could be found in \$PATH" >&2
216b7d26471Smrg      exit 1
217b7d26471Smrg    }
218b7d26471Smrg}
219b7d26471Smrg
220b7d26471Smrg
221b7d26471Smrg# We want to be able to use the functions in this file before configure
222b7d26471Smrg# has figured out where the best binaries are kept, which means we have
223b7d26471Smrg# to search for them ourselves - except when the results are already set
224b7d26471Smrg# where we skip the searches.
225b7d26471Smrg
226b7d26471Smrg# Unless the user overrides by setting SED, search the path for either GNU
227b7d26471Smrg# sed, or the sed that truncates its output the least.
228b7d26471Smrgtest -z "$SED" && {
229b7d26471Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
230b7d26471Smrg  for _G_i in 1 2 3 4 5 6 7; do
231b7d26471Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
232b7d26471Smrg  done
233b7d26471Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
234b7d26471Smrg  _G_sed_script=
235b7d26471Smrg
236b7d26471Smrg  func_check_prog_sed ()
237b7d26471Smrg  {
238b7d26471Smrg    _G_path_prog=$1
239b7d26471Smrg
240b7d26471Smrg    _G_count=0
241b7d26471Smrg    printf 0123456789 >conftest.in
242b7d26471Smrg    while :
243b7d26471Smrg    do
244b7d26471Smrg      cat conftest.in conftest.in >conftest.tmp
245b7d26471Smrg      mv conftest.tmp conftest.in
246b7d26471Smrg      cp conftest.in conftest.nl
247b7d26471Smrg      echo '' >> conftest.nl
248b7d26471Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
249b7d26471Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
250b7d26471Smrg      _G_count=`expr $_G_count + 1`
251b7d26471Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
252b7d26471Smrg        # Best one so far, save it but keep looking for a better one
253b7d26471Smrg        func_check_prog_result=$_G_path_prog
254b7d26471Smrg        _G_path_prog_max=$_G_count
255b7d26471Smrg      fi
256b7d26471Smrg      # 10*(2^10) chars as input seems more than enough
257b7d26471Smrg      test 10 -lt "$_G_count" && break
258b7d26471Smrg    done
259b7d26471Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
260b7d26471Smrg  }
261b7d26471Smrg
262b7d26471Smrg  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
263b7d26471Smrg  rm -f conftest.sed
264b7d26471Smrg  SED=$func_path_progs_result
265b7d26471Smrg}
266b7d26471Smrg
267b7d26471Smrg
268b7d26471Smrg# Unless the user overrides by setting GREP, search the path for either GNU
269b7d26471Smrg# grep, or the grep that truncates its output the least.
270b7d26471Smrgtest -z "$GREP" && {
271b7d26471Smrg  func_check_prog_grep ()
272b7d26471Smrg  {
273b7d26471Smrg    _G_path_prog=$1
274b7d26471Smrg
275b7d26471Smrg    _G_count=0
276b7d26471Smrg    _G_path_prog_max=0
277b7d26471Smrg    printf 0123456789 >conftest.in
278b7d26471Smrg    while :
279b7d26471Smrg    do
280b7d26471Smrg      cat conftest.in conftest.in >conftest.tmp
281b7d26471Smrg      mv conftest.tmp conftest.in
282b7d26471Smrg      cp conftest.in conftest.nl
283b7d26471Smrg      echo 'GREP' >> conftest.nl
284b7d26471Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
285b7d26471Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
286b7d26471Smrg      _G_count=`expr $_G_count + 1`
287b7d26471Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
288b7d26471Smrg        # Best one so far, save it but keep looking for a better one
289b7d26471Smrg        func_check_prog_result=$_G_path_prog
290b7d26471Smrg        _G_path_prog_max=$_G_count
291b7d26471Smrg      fi
292b7d26471Smrg      # 10*(2^10) chars as input seems more than enough
293b7d26471Smrg      test 10 -lt "$_G_count" && break
294b7d26471Smrg    done
295b7d26471Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
296b7d26471Smrg  }
297b7d26471Smrg
298b7d26471Smrg  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
299b7d26471Smrg  GREP=$func_path_progs_result
300b7d26471Smrg}
301b7d26471Smrg
302b7d26471Smrg
303b7d26471Smrg## ------------------------------- ##
304b7d26471Smrg## User overridable command paths. ##
305b7d26471Smrg## ------------------------------- ##
306b7d26471Smrg
307b7d26471Smrg# All uppercase variable names are used for environment variables.  These
308b7d26471Smrg# variables can be overridden by the user before calling a script that
309b7d26471Smrg# uses them if a suitable command of that name is not already available
310b7d26471Smrg# in the command search PATH.
3115ffd6003Smrg
3125ffd6003Smrg: ${CP="cp -f"}
313b7d26471Smrg: ${ECHO="printf %s\n"}
314b7d26471Smrg: ${EGREP="$GREP -E"}
315b7d26471Smrg: ${FGREP="$GREP -F"}
3165ffd6003Smrg: ${LN_S="ln -s"}
3175ffd6003Smrg: ${MAKE="make"}
3185ffd6003Smrg: ${MKDIR="mkdir"}
3195ffd6003Smrg: ${MV="mv -f"}
3205ffd6003Smrg: ${RM="rm -f"}
3215ffd6003Smrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
322145b7b3cSmrg
3235ffd6003Smrg
324b7d26471Smrg## -------------------- ##
325b7d26471Smrg## Useful sed snippets. ##
326b7d26471Smrg## -------------------- ##
327629baa8cSmrg
328b7d26471Smrgsed_dirname='s|/[^/]*$||'
329b7d26471Smrgsed_basename='s|^.*/||'
330629baa8cSmrg
331b7d26471Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
332b7d26471Smrg# metacharacters that are still active within double-quoted strings.
333b7d26471Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
334629baa8cSmrg
335b7d26471Smrg# Same as above, but do not quote variable references.
336b7d26471Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
337629baa8cSmrg
338b7d26471Smrg# Sed substitution that turns a string into a regex matching for the
339b7d26471Smrg# string literally.
340b7d26471Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
341629baa8cSmrg
342b7d26471Smrg# Sed substitution that converts a w32 file name or path
343b7d26471Smrg# that contains forward slashes, into one that contains
344b7d26471Smrg# (escaped) backslashes.  A very naive implementation.
345b7d26471Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
346b7d26471Smrg
347b7d26471Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
348b7d26471Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
349b7d26471Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
350b7d26471Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
351b7d26471Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
352b7d26471Smrg_G_bs='\\'
353b7d26471Smrg_G_bs2='\\\\'
354b7d26471Smrg_G_bs4='\\\\\\\\'
355b7d26471Smrg_G_dollar='\$'
356b7d26471Smrgsed_double_backslash="\
357b7d26471Smrg  s/$_G_bs4/&\\
358b7d26471Smrg/g
359b7d26471Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
360b7d26471Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
361b7d26471Smrg  s/\n//g"
362629baa8cSmrg
363629baa8cSmrg
364b7d26471Smrg## ----------------- ##
365b7d26471Smrg## Global variables. ##
366b7d26471Smrg## ----------------- ##
367629baa8cSmrg
368b7d26471Smrg# Except for the global variables explicitly listed below, the following
369b7d26471Smrg# functions in the '^func_' namespace, and the '^require_' namespace
370b7d26471Smrg# variables initialised in the 'Resource management' section, sourcing
371b7d26471Smrg# this file will not pollute your global namespace with anything
372b7d26471Smrg# else. There's no portable way to scope variables in Bourne shell
373b7d26471Smrg# though, so actually running these functions will sometimes place
374b7d26471Smrg# results into a variable named after the function, and often use
375b7d26471Smrg# temporary variables in the '^_G_' namespace. If you are careful to
376b7d26471Smrg# avoid using those namespaces casually in your sourcing script, things
377b7d26471Smrg# should continue to work as you expect. And, of course, you can freely
378b7d26471Smrg# overwrite any of the functions or variables defined here before
379b7d26471Smrg# calling anything to customize them.
380629baa8cSmrg
381b7d26471SmrgEXIT_SUCCESS=0
382b7d26471SmrgEXIT_FAILURE=1
383b7d26471SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
384b7d26471SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
385145b7b3cSmrg
386b7d26471Smrg# Allow overriding, eg assuming that you follow the convention of
387b7d26471Smrg# putting '$debug_cmd' at the start of all your functions, you can get
388b7d26471Smrg# bash to show function call trace with:
389b7d26471Smrg#
390b7d26471Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
391b7d26471Smrgdebug_cmd=${debug_cmd-":"}
392b7d26471Smrgexit_cmd=:
3935ffd6003Smrg
394b7d26471Smrg# By convention, finish your script with:
395b7d26471Smrg#
396b7d26471Smrg#    exit $exit_status
397b7d26471Smrg#
398b7d26471Smrg# so that you can set exit_status to non-zero if you want to indicate
399b7d26471Smrg# something went wrong during execution without actually bailing out at
400b7d26471Smrg# the point of failure.
401b7d26471Smrgexit_status=$EXIT_SUCCESS
402629baa8cSmrg
403b7d26471Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
404b7d26471Smrg# is ksh but when the shell is invoked as "sh" and the current value of
405b7d26471Smrg# the _XPG environment variable is not equal to 1 (one), the special
406b7d26471Smrg# positional parameter $0, within a function call, is the name of the
407b7d26471Smrg# function.
408b7d26471Smrgprogpath=$0
4095ffd6003Smrg
410b7d26471Smrg# The name of this program.
411b7d26471Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
4125ffd6003Smrg
413b7d26471Smrg# Make sure we have an absolute progpath for reexecution:
4145ffd6003Smrgcase $progpath in
4155ffd6003Smrg  [\\/]*|[A-Za-z]:\\*) ;;
4165ffd6003Smrg  *[\\/]*)
417b7d26471Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
4185ffd6003Smrg     progdir=`cd "$progdir" && pwd`
419b7d26471Smrg     progpath=$progdir/$progname
4205ffd6003Smrg     ;;
4215ffd6003Smrg  *)
422b7d26471Smrg     _G_IFS=$IFS
423b7d26471Smrg     IFS=${PATH_SEPARATOR-:}
4245ffd6003Smrg     for progdir in $PATH; do
425b7d26471Smrg       IFS=$_G_IFS
4265ffd6003Smrg       test -x "$progdir/$progname" && break
4275ffd6003Smrg     done
428b7d26471Smrg     IFS=$_G_IFS
4295ffd6003Smrg     test -n "$progdir" || progdir=`pwd`
430b7d26471Smrg     progpath=$progdir/$progname
4315ffd6003Smrg     ;;
4325ffd6003Smrgesac
4335ffd6003Smrg
4345ffd6003Smrg
435b7d26471Smrg## ----------------- ##
436b7d26471Smrg## Standard options. ##
437b7d26471Smrg## ----------------- ##
438629baa8cSmrg
439b7d26471Smrg# The following options affect the operation of the functions defined
440b7d26471Smrg# below, and should be set appropriately depending on run-time para-
441b7d26471Smrg# meters passed on the command line.
4425ffd6003Smrg
4435ffd6003Smrgopt_dry_run=false
4445ffd6003Smrgopt_quiet=false
4455ffd6003Smrgopt_verbose=false
4465ffd6003Smrg
447b7d26471Smrg# Categories 'all' and 'none' are always available.  Append any others
448b7d26471Smrg# you will pass as the first argument to func_warning from your own
449b7d26471Smrg# code.
450b7d26471Smrgwarning_categories=
4515ffd6003Smrg
452b7d26471Smrg# By default, display warnings according to 'opt_warning_types'.  Set
453b7d26471Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
454b7d26471Smrg# treat the next displayed warning as a fatal error.
455b7d26471Smrgwarning_func=func_warn_and_continue
4565ffd6003Smrg
457b7d26471Smrg# Set to 'all' to display all warnings, 'none' to suppress all
458b7d26471Smrg# warnings, or a space delimited list of some subset of
459b7d26471Smrg# 'warning_categories' to display only the listed warnings.
460b7d26471Smrgopt_warning_types=all
4615ffd6003Smrg
462629baa8cSmrg
463b7d26471Smrg## -------------------- ##
464b7d26471Smrg## Resource management. ##
465b7d26471Smrg## -------------------- ##
4665ffd6003Smrg
467b7d26471Smrg# This section contains definitions for functions that each ensure a
468b7d26471Smrg# particular resource (a file, or a non-empty configuration variable for
469b7d26471Smrg# example) is available, and if appropriate to extract default values
470b7d26471Smrg# from pertinent package files. Call them using their associated
471b7d26471Smrg# 'require_*' variable to ensure that they are executed, at most, once.
472b7d26471Smrg#
473b7d26471Smrg# It's entirely deliberate that calling these functions can set
474b7d26471Smrg# variables that don't obey the namespace limitations obeyed by the rest
475b7d26471Smrg# of this file, in order that that they be as useful as possible to
476b7d26471Smrg# callers.
4775ffd6003Smrg
4785ffd6003Smrg
479b7d26471Smrg# require_term_colors
480b7d26471Smrg# -------------------
481b7d26471Smrg# Allow display of bold text on terminals that support it.
482b7d26471Smrgrequire_term_colors=func_require_term_colors
483b7d26471Smrgfunc_require_term_colors ()
4845ffd6003Smrg{
485b7d26471Smrg    $debug_cmd
486b7d26471Smrg
487b7d26471Smrg    test -t 1 && {
488b7d26471Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
489b7d26471Smrg      # precedence, because most terminfo databases neglect to describe
490b7d26471Smrg      # whether color sequences are supported.
491b7d26471Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
492b7d26471Smrg
493b7d26471Smrg      if test 1 = "$USE_ANSI_COLORS"; then
494b7d26471Smrg        # Standard ANSI escape sequences
495b7d26471Smrg        tc_reset='[0m'
496b7d26471Smrg        tc_bold='[1m';   tc_standout='[7m'
497b7d26471Smrg        tc_red='[31m';   tc_green='[32m'
498b7d26471Smrg        tc_blue='[34m';  tc_cyan='[36m'
499b7d26471Smrg      else
500b7d26471Smrg        # Otherwise trust the terminfo database after all.
501b7d26471Smrg        test -n "`tput sgr0 2>/dev/null`" && {
502b7d26471Smrg          tc_reset=`tput sgr0`
503b7d26471Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
504b7d26471Smrg          tc_standout=$tc_bold
505b7d26471Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
506b7d26471Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
507b7d26471Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
508b7d26471Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
509b7d26471Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
510b7d26471Smrg        }
511b7d26471Smrg      fi
512b7d26471Smrg    }
5135ffd6003Smrg
514b7d26471Smrg    require_term_colors=:
5155ffd6003Smrg}
5165ffd6003Smrg
5175ffd6003Smrg
518b7d26471Smrg## ----------------- ##
519b7d26471Smrg## Function library. ##
520b7d26471Smrg## ----------------- ##
521b7d26471Smrg
522b7d26471Smrg# This section contains a variety of useful functions to call in your
523b7d26471Smrg# scripts. Take note of the portable wrappers for features provided by
524b7d26471Smrg# some modern shells, which will fall back to slower equivalents on
525b7d26471Smrg# less featureful shells.
526b7d26471Smrg
527b7d26471Smrg
528b7d26471Smrg# func_append VAR VALUE
529b7d26471Smrg# ---------------------
530b7d26471Smrg# Append VALUE onto the existing contents of VAR.
531b7d26471Smrg
532b7d26471Smrg  # We should try to minimise forks, especially on Windows where they are
533b7d26471Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
534b7d26471Smrg  # being used:
535b7d26471Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
536b7d26471Smrg    : ${_G_HAVE_ARITH_OP="yes"}
537b7d26471Smrg    : ${_G_HAVE_XSI_OPS="yes"}
538b7d26471Smrg    # The += operator was introduced in bash 3.1
539b7d26471Smrg    case $BASH_VERSION in
540b7d26471Smrg      [12].* | 3.0 | 3.0*) ;;
541b7d26471Smrg      *)
542b7d26471Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
543b7d26471Smrg        ;;
544b7d26471Smrg    esac
545b7d26471Smrg  fi
546b7d26471Smrg
547b7d26471Smrg  # _G_HAVE_PLUSEQ_OP
548b7d26471Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
549b7d26471Smrg  # useable or anything else if it does not work.
550b7d26471Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
551b7d26471Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
552b7d26471Smrg    && _G_HAVE_PLUSEQ_OP=yes
553b7d26471Smrg
554b7d26471Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
555b7d26471Smrgthen
556b7d26471Smrg  # This is an XSI compatible shell, allowing a faster implementation...
557b7d26471Smrg  eval 'func_append ()
558b7d26471Smrg  {
559b7d26471Smrg    $debug_cmd
560b7d26471Smrg
561b7d26471Smrg    eval "$1+=\$2"
562b7d26471Smrg  }'
563b7d26471Smrgelse
564b7d26471Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
565b7d26471Smrg  func_append ()
566b7d26471Smrg  {
567b7d26471Smrg    $debug_cmd
568b7d26471Smrg
569b7d26471Smrg    eval "$1=\$$1\$2"
570b7d26471Smrg  }
571b7d26471Smrgfi
572b7d26471Smrg
573b7d26471Smrg
574b7d26471Smrg# func_append_quoted VAR VALUE
575b7d26471Smrg# ----------------------------
576b7d26471Smrg# Quote VALUE and append to the end of shell variable VAR, separated
577b7d26471Smrg# by a space.
578b7d26471Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
579b7d26471Smrg  eval 'func_append_quoted ()
580b7d26471Smrg  {
581b7d26471Smrg    $debug_cmd
582b7d26471Smrg
583b7d26471Smrg    func_quote_for_eval "$2"
584b7d26471Smrg    eval "$1+=\\ \$func_quote_for_eval_result"
585b7d26471Smrg  }'
586b7d26471Smrgelse
587b7d26471Smrg  func_append_quoted ()
588b7d26471Smrg  {
589b7d26471Smrg    $debug_cmd
590b7d26471Smrg
591b7d26471Smrg    func_quote_for_eval "$2"
592b7d26471Smrg    eval "$1=\$$1\\ \$func_quote_for_eval_result"
593b7d26471Smrg  }
594b7d26471Smrgfi
595b7d26471Smrg
596b7d26471Smrg
597b7d26471Smrg# func_append_uniq VAR VALUE
598b7d26471Smrg# --------------------------
599b7d26471Smrg# Append unique VALUE onto the existing contents of VAR, assuming
600b7d26471Smrg# entries are delimited by the first character of VALUE.  For example:
601b7d26471Smrg#
602b7d26471Smrg#   func_append_uniq options " --another-option option-argument"
603b7d26471Smrg#
604b7d26471Smrg# will only append to $options if " --another-option option-argument "
605b7d26471Smrg# is not already present somewhere in $options already (note spaces at
606b7d26471Smrg# each end implied by leading space in second argument).
607b7d26471Smrgfunc_append_uniq ()
608b7d26471Smrg{
609b7d26471Smrg    $debug_cmd
610b7d26471Smrg
611b7d26471Smrg    eval _G_current_value='`$ECHO $'$1'`'
612b7d26471Smrg    _G_delim=`expr "$2" : '\(.\)'`
613b7d26471Smrg
614b7d26471Smrg    case $_G_delim$_G_current_value$_G_delim in
615b7d26471Smrg      *"$2$_G_delim"*) ;;
616b7d26471Smrg      *) func_append "$@" ;;
617b7d26471Smrg    esac
618b7d26471Smrg}
619b7d26471Smrg
620b7d26471Smrg
621b7d26471Smrg# func_arith TERM...
622b7d26471Smrg# ------------------
623b7d26471Smrg# Set func_arith_result to the result of evaluating TERMs.
624b7d26471Smrg  test -z "$_G_HAVE_ARITH_OP" \
625b7d26471Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
626b7d26471Smrg    && _G_HAVE_ARITH_OP=yes
627b7d26471Smrg
628b7d26471Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
629b7d26471Smrg  eval 'func_arith ()
630b7d26471Smrg  {
631b7d26471Smrg    $debug_cmd
632b7d26471Smrg
633b7d26471Smrg    func_arith_result=$(( $* ))
634b7d26471Smrg  }'
635b7d26471Smrgelse
636b7d26471Smrg  func_arith ()
637b7d26471Smrg  {
638b7d26471Smrg    $debug_cmd
639b7d26471Smrg
640b7d26471Smrg    func_arith_result=`expr "$@"`
641b7d26471Smrg  }
642b7d26471Smrgfi
643b7d26471Smrg
644b7d26471Smrg
645b7d26471Smrg# func_basename FILE
646b7d26471Smrg# ------------------
647b7d26471Smrg# Set func_basename_result to FILE with everything up to and including
648b7d26471Smrg# the last / stripped.
649b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
650b7d26471Smrg  # If this shell supports suffix pattern removal, then use it to avoid
651b7d26471Smrg  # forking. Hide the definitions single quotes in case the shell chokes
652b7d26471Smrg  # on unsupported syntax...
653b7d26471Smrg  _b='func_basename_result=${1##*/}'
654b7d26471Smrg  _d='case $1 in
655b7d26471Smrg        */*) func_dirname_result=${1%/*}$2 ;;
656b7d26471Smrg        *  ) func_dirname_result=$3        ;;
657b7d26471Smrg      esac'
658b7d26471Smrg
659b7d26471Smrgelse
660b7d26471Smrg  # ...otherwise fall back to using sed.
661b7d26471Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
662b7d26471Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
663b7d26471Smrg      if test "X$func_dirname_result" = "X$1"; then
664b7d26471Smrg        func_dirname_result=$3
665b7d26471Smrg      else
666b7d26471Smrg        func_append func_dirname_result "$2"
667b7d26471Smrg      fi'
668b7d26471Smrgfi
669b7d26471Smrg
670b7d26471Smrgeval 'func_basename ()
671b7d26471Smrg{
672b7d26471Smrg    $debug_cmd
673b7d26471Smrg
674b7d26471Smrg    '"$_b"'
675b7d26471Smrg}'
676b7d26471Smrg
677b7d26471Smrg
678b7d26471Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
679b7d26471Smrg# -------------------------------------------
680b7d26471Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
681b7d26471Smrg# otherwise set result to NONDIR_REPLACEMENT.
682b7d26471Smrgeval 'func_dirname ()
683b7d26471Smrg{
684b7d26471Smrg    $debug_cmd
685b7d26471Smrg
686b7d26471Smrg    '"$_d"'
687b7d26471Smrg}'
688b7d26471Smrg
689b7d26471Smrg
690b7d26471Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
691b7d26471Smrg# --------------------------------------------------------
692b7d26471Smrg# Perform func_basename and func_dirname in a single function
693b7d26471Smrg# call:
694b7d26471Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
695b7d26471Smrg#             add APPEND to the result, otherwise set result
696b7d26471Smrg#             to NONDIR_REPLACEMENT.
697b7d26471Smrg#             value returned in "$func_dirname_result"
698b7d26471Smrg#   basename: Compute filename of FILE.
699b7d26471Smrg#             value retuned in "$func_basename_result"
700b7d26471Smrg# For efficiency, we do not delegate to the functions above but instead
701b7d26471Smrg# duplicate the functionality here.
702b7d26471Smrgeval 'func_dirname_and_basename ()
703b7d26471Smrg{
704b7d26471Smrg    $debug_cmd
705b7d26471Smrg
706b7d26471Smrg    '"$_b"'
707b7d26471Smrg    '"$_d"'
708b7d26471Smrg}'
709b7d26471Smrg
710b7d26471Smrg
711b7d26471Smrg# func_echo ARG...
712b7d26471Smrg# ----------------
713b7d26471Smrg# Echo program name prefixed message.
714b7d26471Smrgfunc_echo ()
715b7d26471Smrg{
716b7d26471Smrg    $debug_cmd
717b7d26471Smrg
718b7d26471Smrg    _G_message=$*
719b7d26471Smrg
720b7d26471Smrg    func_echo_IFS=$IFS
721b7d26471Smrg    IFS=$nl
722b7d26471Smrg    for _G_line in $_G_message; do
723b7d26471Smrg      IFS=$func_echo_IFS
724b7d26471Smrg      $ECHO "$progname: $_G_line"
725b7d26471Smrg    done
726b7d26471Smrg    IFS=$func_echo_IFS
727b7d26471Smrg}
728b7d26471Smrg
729b7d26471Smrg
730b7d26471Smrg# func_echo_all ARG...
731b7d26471Smrg# --------------------
732b7d26471Smrg# Invoke $ECHO with all args, space-separated.
733b7d26471Smrgfunc_echo_all ()
734b7d26471Smrg{
735b7d26471Smrg    $ECHO "$*"
736b7d26471Smrg}
737b7d26471Smrg
738b7d26471Smrg
739b7d26471Smrg# func_echo_infix_1 INFIX ARG...
740b7d26471Smrg# ------------------------------
741b7d26471Smrg# Echo program name, followed by INFIX on the first line, with any
742b7d26471Smrg# additional lines not showing INFIX.
743b7d26471Smrgfunc_echo_infix_1 ()
744b7d26471Smrg{
745b7d26471Smrg    $debug_cmd
746b7d26471Smrg
747b7d26471Smrg    $require_term_colors
748b7d26471Smrg
749b7d26471Smrg    _G_infix=$1; shift
750b7d26471Smrg    _G_indent=$_G_infix
751b7d26471Smrg    _G_prefix="$progname: $_G_infix: "
752b7d26471Smrg    _G_message=$*
753b7d26471Smrg
754b7d26471Smrg    # Strip color escape sequences before counting printable length
755b7d26471Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
756b7d26471Smrg    do
757b7d26471Smrg      test -n "$_G_tc" && {
758b7d26471Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
759b7d26471Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
760b7d26471Smrg      }
761b7d26471Smrg    done
762b7d26471Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
763b7d26471Smrg
764b7d26471Smrg    func_echo_infix_1_IFS=$IFS
765b7d26471Smrg    IFS=$nl
766b7d26471Smrg    for _G_line in $_G_message; do
767b7d26471Smrg      IFS=$func_echo_infix_1_IFS
768b7d26471Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
769b7d26471Smrg      _G_prefix=$_G_indent
770b7d26471Smrg    done
771b7d26471Smrg    IFS=$func_echo_infix_1_IFS
772b7d26471Smrg}
773b7d26471Smrg
774b7d26471Smrg
775b7d26471Smrg# func_error ARG...
776b7d26471Smrg# -----------------
777b7d26471Smrg# Echo program name prefixed message to standard error.
778b7d26471Smrgfunc_error ()
779b7d26471Smrg{
780b7d26471Smrg    $debug_cmd
781b7d26471Smrg
782b7d26471Smrg    $require_term_colors
783b7d26471Smrg
784b7d26471Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
785b7d26471Smrg}
786b7d26471Smrg
787b7d26471Smrg
788b7d26471Smrg# func_fatal_error ARG...
789b7d26471Smrg# -----------------------
790b7d26471Smrg# Echo program name prefixed message to standard error, and exit.
791b7d26471Smrgfunc_fatal_error ()
792b7d26471Smrg{
793b7d26471Smrg    $debug_cmd
794b7d26471Smrg
795b7d26471Smrg    func_error "$*"
796b7d26471Smrg    exit $EXIT_FAILURE
797b7d26471Smrg}
798b7d26471Smrg
799b7d26471Smrg
800b7d26471Smrg# func_grep EXPRESSION FILENAME
801b7d26471Smrg# -----------------------------
8025ffd6003Smrg# Check whether EXPRESSION matches any line of FILENAME, without output.
8035ffd6003Smrgfunc_grep ()
8045ffd6003Smrg{
805b7d26471Smrg    $debug_cmd
806b7d26471Smrg
8075ffd6003Smrg    $GREP "$1" "$2" >/dev/null 2>&1
8085ffd6003Smrg}
8095ffd6003Smrg
8105ffd6003Smrg
811b7d26471Smrg# func_len STRING
812b7d26471Smrg# ---------------
813b7d26471Smrg# Set func_len_result to the length of STRING. STRING may not
814b7d26471Smrg# start with a hyphen.
815b7d26471Smrg  test -z "$_G_HAVE_XSI_OPS" \
816b7d26471Smrg    && (eval 'x=a/b/c;
817b7d26471Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
818b7d26471Smrg    && _G_HAVE_XSI_OPS=yes
819b7d26471Smrg
820b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
821b7d26471Smrg  eval 'func_len ()
822b7d26471Smrg  {
823b7d26471Smrg    $debug_cmd
824b7d26471Smrg
825b7d26471Smrg    func_len_result=${#1}
826b7d26471Smrg  }'
827b7d26471Smrgelse
828b7d26471Smrg  func_len ()
829b7d26471Smrg  {
830b7d26471Smrg    $debug_cmd
831b7d26471Smrg
832b7d26471Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
833b7d26471Smrg  }
834b7d26471Smrgfi
835b7d26471Smrg
836b7d26471Smrg
837b7d26471Smrg# func_mkdir_p DIRECTORY-PATH
838b7d26471Smrg# ---------------------------
8395ffd6003Smrg# Make sure the entire path to DIRECTORY-PATH is available.
8405ffd6003Smrgfunc_mkdir_p ()
8415ffd6003Smrg{
842b7d26471Smrg    $debug_cmd
843b7d26471Smrg
844b7d26471Smrg    _G_directory_path=$1
845b7d26471Smrg    _G_dir_list=
8465ffd6003Smrg
847b7d26471Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
8485ffd6003Smrg
849b7d26471Smrg      # Protect directory names starting with '-'
850b7d26471Smrg      case $_G_directory_path in
851b7d26471Smrg        -*) _G_directory_path=./$_G_directory_path ;;
8525ffd6003Smrg      esac
8535ffd6003Smrg
8545ffd6003Smrg      # While some portion of DIR does not yet exist...
855b7d26471Smrg      while test ! -d "$_G_directory_path"; do
8565ffd6003Smrg        # ...make a list in topmost first order.  Use a colon delimited
8575ffd6003Smrg	# list incase some portion of path contains whitespace.
858b7d26471Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
8595ffd6003Smrg
8605ffd6003Smrg        # If the last portion added has no slash in it, the list is done
861b7d26471Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
8625ffd6003Smrg
8635ffd6003Smrg        # ...otherwise throw away the child directory and loop
864b7d26471Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
8655ffd6003Smrg      done
866b7d26471Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
8675ffd6003Smrg
868b7d26471Smrg      func_mkdir_p_IFS=$IFS; IFS=:
869b7d26471Smrg      for _G_dir in $_G_dir_list; do
870b7d26471Smrg	IFS=$func_mkdir_p_IFS
871b7d26471Smrg        # mkdir can fail with a 'File exist' error if two processes
8725ffd6003Smrg        # try to create one of the directories concurrently.  Don't
8735ffd6003Smrg        # stop in that case!
874b7d26471Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
8755ffd6003Smrg      done
876b7d26471Smrg      IFS=$func_mkdir_p_IFS
8775ffd6003Smrg
8785ffd6003Smrg      # Bail out if we (or some other process) failed to create a directory.
879b7d26471Smrg      test -d "$_G_directory_path" || \
880b7d26471Smrg        func_fatal_error "Failed to create '$1'"
8815ffd6003Smrg    fi
8825ffd6003Smrg}
883145b7b3cSmrg
884145b7b3cSmrg
885b7d26471Smrg# func_mktempdir [BASENAME]
886b7d26471Smrg# -------------------------
887145b7b3cSmrg# Make a temporary directory that won't clash with other running
888145b7b3cSmrg# libtool processes, and avoids race conditions if possible.  If
889b7d26471Smrg# given, BASENAME is the basename for that directory.
890145b7b3cSmrgfunc_mktempdir ()
891145b7b3cSmrg{
892b7d26471Smrg    $debug_cmd
893145b7b3cSmrg
894b7d26471Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
895b7d26471Smrg
896b7d26471Smrg    if test : = "$opt_dry_run"; then
897145b7b3cSmrg      # Return a directory name, but don't create it in dry-run mode
898b7d26471Smrg      _G_tmpdir=$_G_template-$$
899145b7b3cSmrg    else
900145b7b3cSmrg
901145b7b3cSmrg      # If mktemp works, use that first and foremost
902b7d26471Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
903145b7b3cSmrg
904b7d26471Smrg      if test ! -d "$_G_tmpdir"; then
9055ffd6003Smrg        # Failing that, at least try and use $RANDOM to avoid a race
906b7d26471Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
907145b7b3cSmrg
908b7d26471Smrg        func_mktempdir_umask=`umask`
9095ffd6003Smrg        umask 0077
910b7d26471Smrg        $MKDIR "$_G_tmpdir"
911b7d26471Smrg        umask $func_mktempdir_umask
912145b7b3cSmrg      fi
913145b7b3cSmrg
914145b7b3cSmrg      # If we're not in dry-run mode, bomb out on failure
915b7d26471Smrg      test -d "$_G_tmpdir" || \
916b7d26471Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
917145b7b3cSmrg    fi
918145b7b3cSmrg
919b7d26471Smrg    $ECHO "$_G_tmpdir"
920145b7b3cSmrg}
921145b7b3cSmrg
922145b7b3cSmrg
923b7d26471Smrg# func_normal_abspath PATH
924b7d26471Smrg# ------------------------
925b7d26471Smrg# Remove doubled-up and trailing slashes, "." path components,
926b7d26471Smrg# and cancel out any ".." path components in PATH after making
927b7d26471Smrg# it an absolute path.
928b7d26471Smrgfunc_normal_abspath ()
929b7d26471Smrg{
930b7d26471Smrg    $debug_cmd
931b7d26471Smrg
932b7d26471Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
933b7d26471Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
934b7d26471Smrg    _G_pathcdr='s|^/[^/]*||'
935b7d26471Smrg    _G_removedotparts=':dotsl
936b7d26471Smrg		s|/\./|/|g
937b7d26471Smrg		t dotsl
938b7d26471Smrg		s|/\.$|/|'
939b7d26471Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
940b7d26471Smrg    _G_finalslash='s|/*$|/|'
941b7d26471Smrg
942b7d26471Smrg    # Start from root dir and reassemble the path.
943b7d26471Smrg    func_normal_abspath_result=
944b7d26471Smrg    func_normal_abspath_tpath=$1
945b7d26471Smrg    func_normal_abspath_altnamespace=
946b7d26471Smrg    case $func_normal_abspath_tpath in
947b7d26471Smrg      "")
948b7d26471Smrg        # Empty path, that just means $cwd.
949b7d26471Smrg        func_stripname '' '/' "`pwd`"
950b7d26471Smrg        func_normal_abspath_result=$func_stripname_result
951b7d26471Smrg        return
952b7d26471Smrg        ;;
953b7d26471Smrg      # The next three entries are used to spot a run of precisely
954b7d26471Smrg      # two leading slashes without using negated character classes;
955b7d26471Smrg      # we take advantage of case's first-match behaviour.
956b7d26471Smrg      ///*)
957b7d26471Smrg        # Unusual form of absolute path, do nothing.
958b7d26471Smrg        ;;
959b7d26471Smrg      //*)
960b7d26471Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
961b7d26471Smrg        # and for example Cygwin uses it to access remote file shares
962b7d26471Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
963b7d26471Smrg        func_normal_abspath_altnamespace=/
964b7d26471Smrg        ;;
965b7d26471Smrg      /*)
966b7d26471Smrg        # Absolute path, do nothing.
967b7d26471Smrg        ;;
968b7d26471Smrg      *)
969b7d26471Smrg        # Relative path, prepend $cwd.
970b7d26471Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
971b7d26471Smrg        ;;
972b7d26471Smrg    esac
973b7d26471Smrg
974b7d26471Smrg    # Cancel out all the simple stuff to save iterations.  We also want
975b7d26471Smrg    # the path to end with a slash for ease of parsing, so make sure
976b7d26471Smrg    # there is one (and only one) here.
977b7d26471Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
978b7d26471Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
979b7d26471Smrg    while :; do
980b7d26471Smrg      # Processed it all yet?
981b7d26471Smrg      if test / = "$func_normal_abspath_tpath"; then
982b7d26471Smrg        # If we ascended to the root using ".." the result may be empty now.
983b7d26471Smrg        if test -z "$func_normal_abspath_result"; then
984b7d26471Smrg          func_normal_abspath_result=/
985b7d26471Smrg        fi
986b7d26471Smrg        break
987b7d26471Smrg      fi
988b7d26471Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
989b7d26471Smrg          -e "$_G_pathcar"`
990b7d26471Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
991b7d26471Smrg          -e "$_G_pathcdr"`
992b7d26471Smrg      # Figure out what to do with it
993b7d26471Smrg      case $func_normal_abspath_tcomponent in
994b7d26471Smrg        "")
995b7d26471Smrg          # Trailing empty path component, ignore it.
996b7d26471Smrg          ;;
997b7d26471Smrg        ..)
998b7d26471Smrg          # Parent dir; strip last assembled component from result.
999b7d26471Smrg          func_dirname "$func_normal_abspath_result"
1000b7d26471Smrg          func_normal_abspath_result=$func_dirname_result
1001b7d26471Smrg          ;;
1002b7d26471Smrg        *)
1003b7d26471Smrg          # Actual path component, append it.
1004b7d26471Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1005b7d26471Smrg          ;;
1006b7d26471Smrg      esac
1007b7d26471Smrg    done
1008b7d26471Smrg    # Restore leading double-slash if one was found on entry.
1009b7d26471Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1010b7d26471Smrg}
1011b7d26471Smrg
1012b7d26471Smrg
1013b7d26471Smrg# func_notquiet ARG...
1014b7d26471Smrg# --------------------
1015b7d26471Smrg# Echo program name prefixed message only when not in quiet mode.
1016b7d26471Smrgfunc_notquiet ()
1017b7d26471Smrg{
1018b7d26471Smrg    $debug_cmd
1019b7d26471Smrg
1020b7d26471Smrg    $opt_quiet || func_echo ${1+"$@"}
1021b7d26471Smrg
1022b7d26471Smrg    # A bug in bash halts the script if the last line of a function
1023b7d26471Smrg    # fails when set -e is in force, so we need another command to
1024b7d26471Smrg    # work around that:
1025b7d26471Smrg    :
1026b7d26471Smrg}
1027b7d26471Smrg
1028b7d26471Smrg
1029b7d26471Smrg# func_relative_path SRCDIR DSTDIR
1030b7d26471Smrg# --------------------------------
1031b7d26471Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1032b7d26471Smrgfunc_relative_path ()
1033b7d26471Smrg{
1034b7d26471Smrg    $debug_cmd
1035b7d26471Smrg
1036b7d26471Smrg    func_relative_path_result=
1037b7d26471Smrg    func_normal_abspath "$1"
1038b7d26471Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1039b7d26471Smrg    func_normal_abspath "$2"
1040b7d26471Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1041b7d26471Smrg
1042b7d26471Smrg    # Ascend the tree starting from libdir
1043b7d26471Smrg    while :; do
1044b7d26471Smrg      # check if we have found a prefix of bindir
1045b7d26471Smrg      case $func_relative_path_tbindir in
1046b7d26471Smrg        $func_relative_path_tlibdir)
1047b7d26471Smrg          # found an exact match
1048b7d26471Smrg          func_relative_path_tcancelled=
1049b7d26471Smrg          break
1050b7d26471Smrg          ;;
1051b7d26471Smrg        $func_relative_path_tlibdir*)
1052b7d26471Smrg          # found a matching prefix
1053b7d26471Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1054b7d26471Smrg          func_relative_path_tcancelled=$func_stripname_result
1055b7d26471Smrg          if test -z "$func_relative_path_result"; then
1056b7d26471Smrg            func_relative_path_result=.
1057b7d26471Smrg          fi
1058b7d26471Smrg          break
1059b7d26471Smrg          ;;
1060b7d26471Smrg        *)
1061b7d26471Smrg          func_dirname $func_relative_path_tlibdir
1062b7d26471Smrg          func_relative_path_tlibdir=$func_dirname_result
1063b7d26471Smrg          if test -z "$func_relative_path_tlibdir"; then
1064b7d26471Smrg            # Have to descend all the way to the root!
1065b7d26471Smrg            func_relative_path_result=../$func_relative_path_result
1066b7d26471Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1067b7d26471Smrg            break
1068b7d26471Smrg          fi
1069b7d26471Smrg          func_relative_path_result=../$func_relative_path_result
1070b7d26471Smrg          ;;
1071b7d26471Smrg      esac
1072b7d26471Smrg    done
1073b7d26471Smrg
1074b7d26471Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1075b7d26471Smrg    func_stripname '' '/' "$func_relative_path_result"
1076b7d26471Smrg    func_relative_path_result=$func_stripname_result
1077b7d26471Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1078b7d26471Smrg    if test -n "$func_stripname_result"; then
1079b7d26471Smrg      func_append func_relative_path_result "/$func_stripname_result"
1080b7d26471Smrg    fi
1081b7d26471Smrg
1082b7d26471Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1083b7d26471Smrg    if test -n "$func_relative_path_result"; then
1084b7d26471Smrg      func_stripname './' '' "$func_relative_path_result"
1085b7d26471Smrg      func_relative_path_result=$func_stripname_result
1086b7d26471Smrg    fi
1087b7d26471Smrg
1088b7d26471Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1089b7d26471Smrg
1090b7d26471Smrg    :
1091b7d26471Smrg}
1092b7d26471Smrg
1093b7d26471Smrg
1094b7d26471Smrg# func_quote_for_eval ARG...
1095b7d26471Smrg# --------------------------
1096b7d26471Smrg# Aesthetically quote ARGs to be evaled later.
1097b7d26471Smrg# This function returns two values:
1098b7d26471Smrg#   i) func_quote_for_eval_result
1099b7d26471Smrg#      double-quoted, suitable for a subsequent eval
1100b7d26471Smrg#  ii) func_quote_for_eval_unquoted_result
1101b7d26471Smrg#      has all characters that are still active within double
1102b7d26471Smrg#      quotes backslashified.
11035ffd6003Smrgfunc_quote_for_eval ()
1104145b7b3cSmrg{
1105b7d26471Smrg    $debug_cmd
1106b7d26471Smrg
1107b7d26471Smrg    func_quote_for_eval_unquoted_result=
1108b7d26471Smrg    func_quote_for_eval_result=
1109b7d26471Smrg    while test 0 -lt $#; do
1110b7d26471Smrg      case $1 in
1111b7d26471Smrg        *[\\\`\"\$]*)
1112b7d26471Smrg	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
1113b7d26471Smrg        *)
1114b7d26471Smrg          _G_unquoted_arg=$1 ;;
1115b7d26471Smrg      esac
1116b7d26471Smrg      if test -n "$func_quote_for_eval_unquoted_result"; then
1117b7d26471Smrg	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
1118b7d26471Smrg      else
1119b7d26471Smrg        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
1120b7d26471Smrg      fi
1121b7d26471Smrg
1122b7d26471Smrg      case $_G_unquoted_arg in
1123b7d26471Smrg        # Double-quote args containing shell metacharacters to delay
1124b7d26471Smrg        # word splitting, command substitution and variable expansion
1125b7d26471Smrg        # for a subsequent eval.
1126b7d26471Smrg        # Many Bourne shells cannot handle close brackets correctly
1127b7d26471Smrg        # in scan sets, so we specify it separately.
1128b7d26471Smrg        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1129b7d26471Smrg          _G_quoted_arg=\"$_G_unquoted_arg\"
1130b7d26471Smrg          ;;
1131b7d26471Smrg        *)
1132b7d26471Smrg          _G_quoted_arg=$_G_unquoted_arg
1133b7d26471Smrg	  ;;
1134b7d26471Smrg      esac
1135b7d26471Smrg
1136b7d26471Smrg      if test -n "$func_quote_for_eval_result"; then
1137b7d26471Smrg	func_append func_quote_for_eval_result " $_G_quoted_arg"
1138b7d26471Smrg      else
1139b7d26471Smrg        func_append func_quote_for_eval_result "$_G_quoted_arg"
1140b7d26471Smrg      fi
1141b7d26471Smrg      shift
1142b7d26471Smrg    done
1143b7d26471Smrg}
1144b7d26471Smrg
1145b7d26471Smrg
1146b7d26471Smrg# func_quote_for_expand ARG
1147b7d26471Smrg# -------------------------
1148b7d26471Smrg# Aesthetically quote ARG to be evaled later; same as above,
1149b7d26471Smrg# but do not quote variable references.
1150b7d26471Smrgfunc_quote_for_expand ()
1151b7d26471Smrg{
1152b7d26471Smrg    $debug_cmd
1153b7d26471Smrg
11545ffd6003Smrg    case $1 in
1155b7d26471Smrg      *[\\\`\"]*)
1156b7d26471Smrg	_G_arg=`$ECHO "$1" | $SED \
1157b7d26471Smrg	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
11585ffd6003Smrg      *)
1159b7d26471Smrg        _G_arg=$1 ;;
11605ffd6003Smrg    esac
11615ffd6003Smrg
1162b7d26471Smrg    case $_G_arg in
11635ffd6003Smrg      # Double-quote args containing shell metacharacters to delay
1164b7d26471Smrg      # word splitting and command substitution for a subsequent eval.
11655ffd6003Smrg      # Many Bourne shells cannot handle close brackets correctly
11665ffd6003Smrg      # in scan sets, so we specify it separately.
11675ffd6003Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1168b7d26471Smrg        _G_arg=\"$_G_arg\"
11695ffd6003Smrg        ;;
1170145b7b3cSmrg    esac
1171b7d26471Smrg
1172b7d26471Smrg    func_quote_for_expand_result=$_G_arg
1173b7d26471Smrg}
1174b7d26471Smrg
1175b7d26471Smrg
1176b7d26471Smrg# func_stripname PREFIX SUFFIX NAME
1177b7d26471Smrg# ---------------------------------
1178b7d26471Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1179b7d26471Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1180b7d26471Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1181b7d26471Smrg# dot (in which case that matches only a dot).
1182b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1183b7d26471Smrg  eval 'func_stripname ()
1184b7d26471Smrg  {
1185b7d26471Smrg    $debug_cmd
1186b7d26471Smrg
1187b7d26471Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1188b7d26471Smrg    # positional parameters, so assign one to ordinary variable first.
1189b7d26471Smrg    func_stripname_result=$3
1190b7d26471Smrg    func_stripname_result=${func_stripname_result#"$1"}
1191b7d26471Smrg    func_stripname_result=${func_stripname_result%"$2"}
1192b7d26471Smrg  }'
1193b7d26471Smrgelse
1194b7d26471Smrg  func_stripname ()
1195b7d26471Smrg  {
1196b7d26471Smrg    $debug_cmd
1197b7d26471Smrg
1198b7d26471Smrg    case $2 in
1199b7d26471Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1200b7d26471Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1201b7d26471Smrg    esac
1202b7d26471Smrg  }
1203b7d26471Smrgfi
1204b7d26471Smrg
1205b7d26471Smrg
1206b7d26471Smrg# func_show_eval CMD [FAIL_EXP]
1207b7d26471Smrg# -----------------------------
1208b7d26471Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1209b7d26471Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1210b7d26471Smrg# is given, then evaluate it.
1211b7d26471Smrgfunc_show_eval ()
1212b7d26471Smrg{
1213b7d26471Smrg    $debug_cmd
1214b7d26471Smrg
1215b7d26471Smrg    _G_cmd=$1
1216b7d26471Smrg    _G_fail_exp=${2-':'}
1217b7d26471Smrg
1218b7d26471Smrg    func_quote_for_expand "$_G_cmd"
1219b7d26471Smrg    eval "func_notquiet $func_quote_for_expand_result"
1220b7d26471Smrg
1221b7d26471Smrg    $opt_dry_run || {
1222b7d26471Smrg      eval "$_G_cmd"
1223b7d26471Smrg      _G_status=$?
1224b7d26471Smrg      if test 0 -ne "$_G_status"; then
1225b7d26471Smrg	eval "(exit $_G_status); $_G_fail_exp"
1226b7d26471Smrg      fi
1227b7d26471Smrg    }
1228b7d26471Smrg}
1229b7d26471Smrg
1230b7d26471Smrg
1231b7d26471Smrg# func_show_eval_locale CMD [FAIL_EXP]
1232b7d26471Smrg# ------------------------------------
1233b7d26471Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1234b7d26471Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1235b7d26471Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1236b7d26471Smrgfunc_show_eval_locale ()
1237b7d26471Smrg{
1238b7d26471Smrg    $debug_cmd
1239b7d26471Smrg
1240b7d26471Smrg    _G_cmd=$1
1241b7d26471Smrg    _G_fail_exp=${2-':'}
1242b7d26471Smrg
1243b7d26471Smrg    $opt_quiet || {
1244b7d26471Smrg      func_quote_for_expand "$_G_cmd"
1245b7d26471Smrg      eval "func_echo $func_quote_for_expand_result"
1246b7d26471Smrg    }
1247b7d26471Smrg
1248b7d26471Smrg    $opt_dry_run || {
1249b7d26471Smrg      eval "$_G_user_locale
1250b7d26471Smrg	    $_G_cmd"
1251b7d26471Smrg      _G_status=$?
1252b7d26471Smrg      eval "$_G_safe_locale"
1253b7d26471Smrg      if test 0 -ne "$_G_status"; then
1254b7d26471Smrg	eval "(exit $_G_status); $_G_fail_exp"
1255b7d26471Smrg      fi
1256b7d26471Smrg    }
1257b7d26471Smrg}
1258b7d26471Smrg
1259b7d26471Smrg
1260b7d26471Smrg# func_tr_sh
1261b7d26471Smrg# ----------
1262b7d26471Smrg# Turn $1 into a string suitable for a shell variable name.
1263b7d26471Smrg# Result is stored in $func_tr_sh_result.  All characters
1264b7d26471Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1265b7d26471Smrg# if $1 begins with a digit, a '_' is prepended as well.
1266b7d26471Smrgfunc_tr_sh ()
1267b7d26471Smrg{
1268b7d26471Smrg    $debug_cmd
1269b7d26471Smrg
1270b7d26471Smrg    case $1 in
1271b7d26471Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1272b7d26471Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1273b7d26471Smrg      ;;
1274b7d26471Smrg    * )
1275b7d26471Smrg      func_tr_sh_result=$1
1276b7d26471Smrg      ;;
1277b7d26471Smrg    esac
1278b7d26471Smrg}
1279b7d26471Smrg
1280b7d26471Smrg
1281b7d26471Smrg# func_verbose ARG...
1282b7d26471Smrg# -------------------
1283b7d26471Smrg# Echo program name prefixed message in verbose mode only.
1284b7d26471Smrgfunc_verbose ()
1285b7d26471Smrg{
1286b7d26471Smrg    $debug_cmd
1287b7d26471Smrg
1288b7d26471Smrg    $opt_verbose && func_echo "$*"
1289b7d26471Smrg
1290b7d26471Smrg    :
1291b7d26471Smrg}
1292b7d26471Smrg
1293b7d26471Smrg
1294b7d26471Smrg# func_warn_and_continue ARG...
1295b7d26471Smrg# -----------------------------
1296b7d26471Smrg# Echo program name prefixed warning message to standard error.
1297b7d26471Smrgfunc_warn_and_continue ()
1298b7d26471Smrg{
1299b7d26471Smrg    $debug_cmd
1300b7d26471Smrg
1301b7d26471Smrg    $require_term_colors
1302b7d26471Smrg
1303b7d26471Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1304b7d26471Smrg}
1305b7d26471Smrg
1306b7d26471Smrg
1307b7d26471Smrg# func_warning CATEGORY ARG...
1308b7d26471Smrg# ----------------------------
1309b7d26471Smrg# Echo program name prefixed warning message to standard error. Warning
1310b7d26471Smrg# messages can be filtered according to CATEGORY, where this function
1311b7d26471Smrg# elides messages where CATEGORY is not listed in the global variable
1312b7d26471Smrg# 'opt_warning_types'.
1313b7d26471Smrgfunc_warning ()
1314b7d26471Smrg{
1315b7d26471Smrg    $debug_cmd
1316b7d26471Smrg
1317b7d26471Smrg    # CATEGORY must be in the warning_categories list!
1318b7d26471Smrg    case " $warning_categories " in
1319b7d26471Smrg      *" $1 "*) ;;
1320b7d26471Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1321b7d26471Smrg    esac
1322b7d26471Smrg
1323b7d26471Smrg    _G_category=$1
1324b7d26471Smrg    shift
1325b7d26471Smrg
1326b7d26471Smrg    case " $opt_warning_types " in
1327b7d26471Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1328b7d26471Smrg    esac
1329b7d26471Smrg}
1330b7d26471Smrg
1331b7d26471Smrg
1332b7d26471Smrg# func_sort_ver VER1 VER2
1333b7d26471Smrg# -----------------------
1334b7d26471Smrg# 'sort -V' is not generally available.
1335b7d26471Smrg# Note this deviates from the version comparison in automake
1336b7d26471Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1337b7d26471Smrg# but this should suffice as we won't be specifying old
1338b7d26471Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1339b7d26471Smrg# If we did want full compatibility then we should probably
1340b7d26471Smrg# use m4_version_compare from autoconf.
1341b7d26471Smrgfunc_sort_ver ()
1342b7d26471Smrg{
1343b7d26471Smrg    $debug_cmd
1344b7d26471Smrg
1345b7d26471Smrg    printf '%s\n%s\n' "$1" "$2" \
1346b7d26471Smrg      | 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
1347b7d26471Smrg}
1348b7d26471Smrg
1349b7d26471Smrg# func_lt_ver PREV CURR
1350b7d26471Smrg# ---------------------
1351b7d26471Smrg# Return true if PREV and CURR are in the correct order according to
1352b7d26471Smrg# func_sort_ver, otherwise false.  Use it like this:
1353b7d26471Smrg#
1354b7d26471Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1355b7d26471Smrgfunc_lt_ver ()
1356b7d26471Smrg{
1357b7d26471Smrg    $debug_cmd
1358b7d26471Smrg
1359b7d26471Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1360b7d26471Smrg}
1361b7d26471Smrg
1362b7d26471Smrg
1363b7d26471Smrg# Local variables:
1364b7d26471Smrg# mode: shell-script
1365b7d26471Smrg# sh-indentation: 2
1366b7d26471Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1367b7d26471Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1368b7d26471Smrg# time-stamp-time-zone: "UTC"
1369b7d26471Smrg# End:
1370b7d26471Smrg#! /bin/sh
1371b7d26471Smrg
1372b7d26471Smrg# Set a version string for this script.
1373b7d26471Smrgscriptversion=2014-01-07.03; # UTC
1374b7d26471Smrg
1375b7d26471Smrg# A portable, pluggable option parser for Bourne shell.
1376b7d26471Smrg# Written by Gary V. Vaughan, 2010
1377b7d26471Smrg
1378b7d26471Smrg# Copyright (C) 2010-2015 Free Software Foundation, Inc.
1379b7d26471Smrg# This is free software; see the source for copying conditions.  There is NO
1380b7d26471Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1381b7d26471Smrg
1382b7d26471Smrg# This program is free software: you can redistribute it and/or modify
1383b7d26471Smrg# it under the terms of the GNU General Public License as published by
1384b7d26471Smrg# the Free Software Foundation, either version 3 of the License, or
1385b7d26471Smrg# (at your option) any later version.
1386b7d26471Smrg
1387b7d26471Smrg# This program is distributed in the hope that it will be useful,
1388b7d26471Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1389b7d26471Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1390b7d26471Smrg# GNU General Public License for more details.
1391b7d26471Smrg
1392b7d26471Smrg# You should have received a copy of the GNU General Public License
1393b7d26471Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1394b7d26471Smrg
1395b7d26471Smrg# Please report bugs or propose patches to gary@gnu.org.
1396b7d26471Smrg
1397b7d26471Smrg
1398b7d26471Smrg## ------ ##
1399b7d26471Smrg## Usage. ##
1400b7d26471Smrg## ------ ##
1401b7d26471Smrg
1402b7d26471Smrg# This file is a library for parsing options in your shell scripts along
1403b7d26471Smrg# with assorted other useful supporting features that you can make use
1404b7d26471Smrg# of too.
1405b7d26471Smrg#
1406b7d26471Smrg# For the simplest scripts you might need only:
1407b7d26471Smrg#
1408b7d26471Smrg#   #!/bin/sh
1409b7d26471Smrg#   . relative/path/to/funclib.sh
1410b7d26471Smrg#   . relative/path/to/options-parser
1411b7d26471Smrg#   scriptversion=1.0
1412b7d26471Smrg#   func_options ${1+"$@"}
1413b7d26471Smrg#   eval set dummy "$func_options_result"; shift
1414b7d26471Smrg#   ...rest of your script...
1415b7d26471Smrg#
1416b7d26471Smrg# In order for the '--version' option to work, you will need to have a
1417b7d26471Smrg# suitably formatted comment like the one at the top of this file
1418b7d26471Smrg# starting with '# Written by ' and ending with '# warranty; '.
1419b7d26471Smrg#
1420b7d26471Smrg# For '-h' and '--help' to work, you will also need a one line
1421b7d26471Smrg# description of your script's purpose in a comment directly above the
1422b7d26471Smrg# '# Written by ' line, like the one at the top of this file.
1423b7d26471Smrg#
1424b7d26471Smrg# The default options also support '--debug', which will turn on shell
1425b7d26471Smrg# execution tracing (see the comment above debug_cmd below for another
1426b7d26471Smrg# use), and '--verbose' and the func_verbose function to allow your script
1427b7d26471Smrg# to display verbose messages only when your user has specified
1428b7d26471Smrg# '--verbose'.
1429b7d26471Smrg#
1430b7d26471Smrg# After sourcing this file, you can plug processing for additional
1431b7d26471Smrg# options by amending the variables from the 'Configuration' section
1432b7d26471Smrg# below, and following the instructions in the 'Option parsing'
1433b7d26471Smrg# section further down.
1434b7d26471Smrg
1435b7d26471Smrg## -------------- ##
1436b7d26471Smrg## Configuration. ##
1437b7d26471Smrg## -------------- ##
1438b7d26471Smrg
1439b7d26471Smrg# You should override these variables in your script after sourcing this
1440b7d26471Smrg# file so that they reflect the customisations you have added to the
1441b7d26471Smrg# option parser.
1442b7d26471Smrg
1443b7d26471Smrg# The usage line for option parsing errors and the start of '-h' and
1444b7d26471Smrg# '--help' output messages. You can embed shell variables for delayed
1445b7d26471Smrg# expansion at the time the message is displayed, but you will need to
1446b7d26471Smrg# quote other shell meta-characters carefully to prevent them being
1447b7d26471Smrg# expanded when the contents are evaled.
1448b7d26471Smrgusage='$progpath [OPTION]...'
1449b7d26471Smrg
1450b7d26471Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1451b7d26471Smrg# override it after sourcing this library to reflect the full set of
1452b7d26471Smrg# options your script accepts.
1453b7d26471Smrgusage_message="\
1454b7d26471Smrg       --debug        enable verbose shell tracing
1455b7d26471Smrg   -W, --warnings=CATEGORY
1456b7d26471Smrg                      report the warnings falling in CATEGORY [all]
1457b7d26471Smrg   -v, --verbose      verbosely report processing
1458b7d26471Smrg       --version      print version information and exit
1459b7d26471Smrg   -h, --help         print short or long help message and exit
1460b7d26471Smrg"
1461b7d26471Smrg
1462b7d26471Smrg# Additional text appended to 'usage_message' in response to '--help'.
1463b7d26471Smrglong_help_message="
1464b7d26471SmrgWarning categories include:
1465b7d26471Smrg       'all'          show all warnings
1466b7d26471Smrg       'none'         turn off all the warnings
1467b7d26471Smrg       'error'        warnings are treated as fatal errors"
1468b7d26471Smrg
1469b7d26471Smrg# Help message printed before fatal option parsing errors.
1470b7d26471Smrgfatal_help="Try '\$progname --help' for more information."
1471b7d26471Smrg
1472b7d26471Smrg
1473b7d26471Smrg
1474b7d26471Smrg## ------------------------- ##
1475b7d26471Smrg## Hook function management. ##
1476b7d26471Smrg## ------------------------- ##
1477b7d26471Smrg
1478b7d26471Smrg# This section contains functions for adding, removing, and running hooks
1479b7d26471Smrg# to the main code.  A hook is just a named list of of function, that can
1480b7d26471Smrg# be run in order later on.
1481b7d26471Smrg
1482b7d26471Smrg# func_hookable FUNC_NAME
1483b7d26471Smrg# -----------------------
1484b7d26471Smrg# Declare that FUNC_NAME will run hooks added with
1485b7d26471Smrg# 'func_add_hook FUNC_NAME ...'.
1486b7d26471Smrgfunc_hookable ()
1487b7d26471Smrg{
1488b7d26471Smrg    $debug_cmd
1489b7d26471Smrg
1490b7d26471Smrg    func_append hookable_fns " $1"
1491b7d26471Smrg}
1492b7d26471Smrg
1493b7d26471Smrg
1494b7d26471Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1495b7d26471Smrg# ---------------------------------
1496b7d26471Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1497b7d26471Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1498b7d26471Smrgfunc_add_hook ()
1499b7d26471Smrg{
1500b7d26471Smrg    $debug_cmd
1501b7d26471Smrg
1502b7d26471Smrg    case " $hookable_fns " in
1503b7d26471Smrg      *" $1 "*) ;;
1504b7d26471Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1505b7d26471Smrg    esac
1506b7d26471Smrg
1507b7d26471Smrg    eval func_append ${1}_hooks '" $2"'
1508b7d26471Smrg}
1509b7d26471Smrg
1510b7d26471Smrg
1511b7d26471Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1512b7d26471Smrg# ------------------------------------
1513b7d26471Smrg# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1514b7d26471Smrgfunc_remove_hook ()
1515b7d26471Smrg{
1516b7d26471Smrg    $debug_cmd
1517b7d26471Smrg
1518b7d26471Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1519b7d26471Smrg}
1520b7d26471Smrg
1521b7d26471Smrg
1522b7d26471Smrg# func_run_hooks FUNC_NAME [ARG]...
1523b7d26471Smrg# ---------------------------------
1524b7d26471Smrg# Run all hook functions registered to FUNC_NAME.
1525b7d26471Smrg# It is assumed that the list of hook functions contains nothing more
1526b7d26471Smrg# than a whitespace-delimited list of legal shell function names, and
1527b7d26471Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1528b7d26471Smrg# whitespace.
1529b7d26471Smrgfunc_run_hooks ()
1530b7d26471Smrg{
1531b7d26471Smrg    $debug_cmd
1532b7d26471Smrg
1533b7d26471Smrg    case " $hookable_fns " in
1534b7d26471Smrg      *" $1 "*) ;;
1535b7d26471Smrg      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1536b7d26471Smrg    esac
1537b7d26471Smrg
1538b7d26471Smrg    eval _G_hook_fns=\$$1_hooks; shift
1539b7d26471Smrg
1540b7d26471Smrg    for _G_hook in $_G_hook_fns; do
1541b7d26471Smrg      eval $_G_hook '"$@"'
1542b7d26471Smrg
1543b7d26471Smrg      # store returned options list back into positional
1544b7d26471Smrg      # parameters for next 'cmd' execution.
1545b7d26471Smrg      eval _G_hook_result=\$${_G_hook}_result
1546b7d26471Smrg      eval set dummy "$_G_hook_result"; shift
1547b7d26471Smrg    done
1548b7d26471Smrg
1549b7d26471Smrg    func_quote_for_eval ${1+"$@"}
1550b7d26471Smrg    func_run_hooks_result=$func_quote_for_eval_result
1551b7d26471Smrg}
1552b7d26471Smrg
1553b7d26471Smrg
1554b7d26471Smrg
1555b7d26471Smrg## --------------- ##
1556b7d26471Smrg## Option parsing. ##
1557b7d26471Smrg## --------------- ##
1558b7d26471Smrg
1559b7d26471Smrg# In order to add your own option parsing hooks, you must accept the
1560b7d26471Smrg# full positional parameter list in your hook function, remove any
1561b7d26471Smrg# options that you action, and then pass back the remaining unprocessed
1562b7d26471Smrg# options in '<hooked_function_name>_result', escaped suitably for
1563b7d26471Smrg# 'eval'.  Like this:
1564b7d26471Smrg#
1565b7d26471Smrg#    my_options_prep ()
1566b7d26471Smrg#    {
1567b7d26471Smrg#        $debug_cmd
1568b7d26471Smrg#
1569b7d26471Smrg#        # Extend the existing usage message.
1570b7d26471Smrg#        usage_message=$usage_message'
1571b7d26471Smrg#      -s, --silent       don'\''t print informational messages
1572b7d26471Smrg#    '
1573b7d26471Smrg#
1574b7d26471Smrg#        func_quote_for_eval ${1+"$@"}
1575b7d26471Smrg#        my_options_prep_result=$func_quote_for_eval_result
1576b7d26471Smrg#    }
1577b7d26471Smrg#    func_add_hook func_options_prep my_options_prep
1578b7d26471Smrg#
1579b7d26471Smrg#
1580b7d26471Smrg#    my_silent_option ()
1581b7d26471Smrg#    {
1582b7d26471Smrg#        $debug_cmd
1583b7d26471Smrg#
1584b7d26471Smrg#        # Note that for efficiency, we parse as many options as we can
1585b7d26471Smrg#        # recognise in a loop before passing the remainder back to the
1586b7d26471Smrg#        # caller on the first unrecognised argument we encounter.
1587b7d26471Smrg#        while test $# -gt 0; do
1588b7d26471Smrg#          opt=$1; shift
1589b7d26471Smrg#          case $opt in
1590b7d26471Smrg#            --silent|-s) opt_silent=: ;;
1591b7d26471Smrg#            # Separate non-argument short options:
1592b7d26471Smrg#            -s*)         func_split_short_opt "$_G_opt"
1593b7d26471Smrg#                         set dummy "$func_split_short_opt_name" \
1594b7d26471Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1595b7d26471Smrg#                         shift
1596b7d26471Smrg#                         ;;
1597b7d26471Smrg#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
1598b7d26471Smrg#          esac
1599b7d26471Smrg#        done
1600b7d26471Smrg#
1601b7d26471Smrg#        func_quote_for_eval ${1+"$@"}
1602b7d26471Smrg#        my_silent_option_result=$func_quote_for_eval_result
1603b7d26471Smrg#    }
1604b7d26471Smrg#    func_add_hook func_parse_options my_silent_option
1605b7d26471Smrg#
1606b7d26471Smrg#
1607b7d26471Smrg#    my_option_validation ()
1608b7d26471Smrg#    {
1609b7d26471Smrg#        $debug_cmd
1610b7d26471Smrg#
1611b7d26471Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1612b7d26471Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1613b7d26471Smrg#
1614b7d26471Smrg#        func_quote_for_eval ${1+"$@"}
1615b7d26471Smrg#        my_option_validation_result=$func_quote_for_eval_result
1616b7d26471Smrg#    }
1617b7d26471Smrg#    func_add_hook func_validate_options my_option_validation
1618b7d26471Smrg#
1619b7d26471Smrg# You'll alse need to manually amend $usage_message to reflect the extra
1620b7d26471Smrg# options you parse.  It's preferable to append if you can, so that
1621b7d26471Smrg# multiple option parsing hooks can be added safely.
1622b7d26471Smrg
1623b7d26471Smrg
1624b7d26471Smrg# func_options [ARG]...
1625b7d26471Smrg# ---------------------
1626b7d26471Smrg# All the functions called inside func_options are hookable. See the
1627b7d26471Smrg# individual implementations for details.
1628b7d26471Smrgfunc_hookable func_options
1629b7d26471Smrgfunc_options ()
1630b7d26471Smrg{
1631b7d26471Smrg    $debug_cmd
1632b7d26471Smrg
1633b7d26471Smrg    func_options_prep ${1+"$@"}
1634b7d26471Smrg    eval func_parse_options \
1635b7d26471Smrg        ${func_options_prep_result+"$func_options_prep_result"}
1636b7d26471Smrg    eval func_validate_options \
1637b7d26471Smrg        ${func_parse_options_result+"$func_parse_options_result"}
1638b7d26471Smrg
1639b7d26471Smrg    eval func_run_hooks func_options \
1640b7d26471Smrg        ${func_validate_options_result+"$func_validate_options_result"}
1641b7d26471Smrg
1642b7d26471Smrg    # save modified positional parameters for caller
1643b7d26471Smrg    func_options_result=$func_run_hooks_result
1644145b7b3cSmrg}
1645145b7b3cSmrg
1646145b7b3cSmrg
1647b7d26471Smrg# func_options_prep [ARG]...
1648b7d26471Smrg# --------------------------
1649b7d26471Smrg# All initialisations required before starting the option parse loop.
1650b7d26471Smrg# Note that when calling hook functions, we pass through the list of
1651b7d26471Smrg# positional parameters.  If a hook function modifies that list, and
1652b7d26471Smrg# needs to propogate that back to rest of this script, then the complete
1653b7d26471Smrg# modified list must be put in 'func_run_hooks_result' before
1654b7d26471Smrg# returning.
1655b7d26471Smrgfunc_hookable func_options_prep
1656b7d26471Smrgfunc_options_prep ()
1657145b7b3cSmrg{
1658b7d26471Smrg    $debug_cmd
16595ffd6003Smrg
1660b7d26471Smrg    # Option defaults:
1661b7d26471Smrg    opt_verbose=false
1662b7d26471Smrg    opt_warning_types=
1663b7d26471Smrg
1664b7d26471Smrg    func_run_hooks func_options_prep ${1+"$@"}
16655ffd6003Smrg
1666b7d26471Smrg    # save modified positional parameters for caller
1667b7d26471Smrg    func_options_prep_result=$func_run_hooks_result
1668145b7b3cSmrg}
1669145b7b3cSmrg
1670145b7b3cSmrg
1671b7d26471Smrg# func_parse_options [ARG]...
1672b7d26471Smrg# ---------------------------
1673b7d26471Smrg# The main option parsing loop.
1674b7d26471Smrgfunc_hookable func_parse_options
1675b7d26471Smrgfunc_parse_options ()
1676145b7b3cSmrg{
1677b7d26471Smrg    $debug_cmd
1678145b7b3cSmrg
1679b7d26471Smrg    func_parse_options_result=
16805ffd6003Smrg
1681b7d26471Smrg    # this just eases exit handling
1682b7d26471Smrg    while test $# -gt 0; do
1683b7d26471Smrg      # Defer to hook functions for initial option parsing, so they
1684b7d26471Smrg      # get priority in the event of reusing an option name.
1685b7d26471Smrg      func_run_hooks func_parse_options ${1+"$@"}
1686145b7b3cSmrg
1687b7d26471Smrg      # Adjust func_parse_options positional parameters to match
1688b7d26471Smrg      eval set dummy "$func_run_hooks_result"; shift
16895ffd6003Smrg
1690b7d26471Smrg      # Break out of the loop if we already parsed every option.
1691b7d26471Smrg      test $# -gt 0 || break
16925ffd6003Smrg
1693b7d26471Smrg      _G_opt=$1
1694b7d26471Smrg      shift
1695b7d26471Smrg      case $_G_opt in
1696b7d26471Smrg        --debug|-x)   debug_cmd='set -x'
1697b7d26471Smrg                      func_echo "enabling shell trace mode"
1698b7d26471Smrg                      $debug_cmd
1699b7d26471Smrg                      ;;
1700b7d26471Smrg
1701b7d26471Smrg        --no-warnings|--no-warning|--no-warn)
1702b7d26471Smrg                      set dummy --warnings none ${1+"$@"}
1703b7d26471Smrg                      shift
1704b7d26471Smrg		      ;;
17055ffd6003Smrg
1706b7d26471Smrg        --warnings|--warning|-W)
1707b7d26471Smrg                      test $# = 0 && func_missing_arg $_G_opt && break
1708b7d26471Smrg                      case " $warning_categories $1" in
1709b7d26471Smrg                        *" $1 "*)
1710b7d26471Smrg                          # trailing space prevents matching last $1 above
1711b7d26471Smrg                          func_append_uniq opt_warning_types " $1"
1712b7d26471Smrg                          ;;
1713b7d26471Smrg                        *all)
1714b7d26471Smrg                          opt_warning_types=$warning_categories
1715b7d26471Smrg                          ;;
1716b7d26471Smrg                        *none)
1717b7d26471Smrg                          opt_warning_types=none
1718b7d26471Smrg                          warning_func=:
1719b7d26471Smrg                          ;;
1720b7d26471Smrg                        *error)
1721b7d26471Smrg                          opt_warning_types=$warning_categories
1722b7d26471Smrg                          warning_func=func_fatal_error
1723b7d26471Smrg                          ;;
1724b7d26471Smrg                        *)
1725b7d26471Smrg                          func_fatal_error \
1726b7d26471Smrg                             "unsupported warning category: '$1'"
1727b7d26471Smrg                          ;;
1728b7d26471Smrg                      esac
1729b7d26471Smrg                      shift
1730b7d26471Smrg                      ;;
1731b7d26471Smrg
1732b7d26471Smrg        --verbose|-v) opt_verbose=: ;;
1733b7d26471Smrg        --version)    func_version ;;
1734b7d26471Smrg        -\?|-h)       func_usage ;;
1735b7d26471Smrg        --help)       func_help ;;
1736b7d26471Smrg
1737b7d26471Smrg	# Separate optargs to long options (plugins may need this):
1738b7d26471Smrg	--*=*)        func_split_equals "$_G_opt"
1739b7d26471Smrg	              set dummy "$func_split_equals_lhs" \
1740b7d26471Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1741b7d26471Smrg                      shift
1742b7d26471Smrg                      ;;
1743b7d26471Smrg
1744b7d26471Smrg       # Separate optargs to short options:
1745b7d26471Smrg        -W*)
1746b7d26471Smrg                      func_split_short_opt "$_G_opt"
1747b7d26471Smrg                      set dummy "$func_split_short_opt_name" \
1748b7d26471Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1749b7d26471Smrg                      shift
1750b7d26471Smrg                      ;;
1751b7d26471Smrg
1752b7d26471Smrg        # Separate non-argument short options:
1753b7d26471Smrg        -\?*|-h*|-v*|-x*)
1754b7d26471Smrg                      func_split_short_opt "$_G_opt"
1755b7d26471Smrg                      set dummy "$func_split_short_opt_name" \
1756b7d26471Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1757b7d26471Smrg                      shift
1758b7d26471Smrg                      ;;
1759b7d26471Smrg
1760b7d26471Smrg        --)           break ;;
1761b7d26471Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1762b7d26471Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1763b7d26471Smrg      esac
1764b7d26471Smrg    done
1765145b7b3cSmrg
1766b7d26471Smrg    # save modified positional parameters for caller
1767b7d26471Smrg    func_quote_for_eval ${1+"$@"}
1768b7d26471Smrg    func_parse_options_result=$func_quote_for_eval_result
1769629baa8cSmrg}
17705ffd6003Smrg
17715ffd6003Smrg
1772b7d26471Smrg# func_validate_options [ARG]...
1773b7d26471Smrg# ------------------------------
1774b7d26471Smrg# Perform any sanity checks on option settings and/or unconsumed
1775b7d26471Smrg# arguments.
1776b7d26471Smrgfunc_hookable func_validate_options
1777b7d26471Smrgfunc_validate_options ()
17785ffd6003Smrg{
1779b7d26471Smrg    $debug_cmd
1780629baa8cSmrg
1781b7d26471Smrg    # Display all warnings if -W was not given.
1782b7d26471Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1783b7d26471Smrg
1784b7d26471Smrg    func_run_hooks func_validate_options ${1+"$@"}
1785b7d26471Smrg
1786b7d26471Smrg    # Bail if the options were screwed!
1787b7d26471Smrg    $exit_cmd $EXIT_FAILURE
1788b7d26471Smrg
1789b7d26471Smrg    # save modified positional parameters for caller
1790b7d26471Smrg    func_validate_options_result=$func_run_hooks_result
17915ffd6003Smrg}
17925ffd6003Smrg
1793b7d26471Smrg
1794b7d26471Smrg
1795b7d26471Smrg## ----------------- ##
1796b7d26471Smrg## Helper functions. ##
1797b7d26471Smrg## ----------------- ##
1798b7d26471Smrg
1799b7d26471Smrg# This section contains the helper functions used by the rest of the
1800b7d26471Smrg# hookable option parser framework in ascii-betical order.
1801b7d26471Smrg
1802b7d26471Smrg
1803b7d26471Smrg# func_fatal_help ARG...
1804b7d26471Smrg# ----------------------
1805b7d26471Smrg# Echo program name prefixed message to standard error, followed by
1806b7d26471Smrg# a help hint, and exit.
1807b7d26471Smrgfunc_fatal_help ()
18085ffd6003Smrg{
1809b7d26471Smrg    $debug_cmd
1810629baa8cSmrg
1811b7d26471Smrg    eval \$ECHO \""Usage: $usage"\"
1812b7d26471Smrg    eval \$ECHO \""$fatal_help"\"
1813b7d26471Smrg    func_error ${1+"$@"}
1814b7d26471Smrg    exit $EXIT_FAILURE
18155ffd6003Smrg}
18165ffd6003Smrg
1817b7d26471Smrg
1818b7d26471Smrg# func_help
1819b7d26471Smrg# ---------
1820b7d26471Smrg# Echo long help message to standard output and exit.
18215ffd6003Smrgfunc_help ()
18225ffd6003Smrg{
1823b7d26471Smrg    $debug_cmd
1824b7d26471Smrg
1825b7d26471Smrg    func_usage_message
1826b7d26471Smrg    $ECHO "$long_help_message"
1827b7d26471Smrg    exit 0
18285ffd6003Smrg}
18295ffd6003Smrg
1830b7d26471Smrg
1831b7d26471Smrg# func_missing_arg ARGNAME
1832b7d26471Smrg# ------------------------
18335ffd6003Smrg# Echo program name prefixed message to standard error and set global
18345ffd6003Smrg# exit_cmd.
18355ffd6003Smrgfunc_missing_arg ()
18365ffd6003Smrg{
1837b7d26471Smrg    $debug_cmd
1838629baa8cSmrg
1839b7d26471Smrg    func_error "Missing argument for '$1'."
18405ffd6003Smrg    exit_cmd=exit
1841145b7b3cSmrg}
1842145b7b3cSmrg
1843145b7b3cSmrg
1844b7d26471Smrg# func_split_equals STRING
1845b7d26471Smrg# ------------------------
1846b7d26471Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
1847b7d26471Smrg# splitting STRING at the '=' sign.
1848b7d26471Smrgtest -z "$_G_HAVE_XSI_OPS" \
1849b7d26471Smrg    && (eval 'x=a/b/c;
1850b7d26471Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
1851b7d26471Smrg    && _G_HAVE_XSI_OPS=yes
1852b7d26471Smrg
1853b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"
1854b7d26471Smrgthen
1855b7d26471Smrg  # This is an XSI compatible shell, allowing a faster implementation...
1856b7d26471Smrg  eval 'func_split_equals ()
1857b7d26471Smrg  {
1858b7d26471Smrg      $debug_cmd
1859b7d26471Smrg
1860b7d26471Smrg      func_split_equals_lhs=${1%%=*}
1861b7d26471Smrg      func_split_equals_rhs=${1#*=}
1862b7d26471Smrg      test "x$func_split_equals_lhs" = "x$1" \
1863b7d26471Smrg        && func_split_equals_rhs=
1864b7d26471Smrg  }'
1865b7d26471Smrgelse
1866b7d26471Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1867b7d26471Smrg  func_split_equals ()
1868b7d26471Smrg  {
1869b7d26471Smrg      $debug_cmd
1870b7d26471Smrg
1871b7d26471Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
1872b7d26471Smrg      func_split_equals_rhs=
1873b7d26471Smrg      test "x$func_split_equals_lhs" = "x$1" \
1874b7d26471Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
1875b7d26471Smrg  }
1876b7d26471Smrgfi #func_split_equals
1877b7d26471Smrg
1878b7d26471Smrg
1879b7d26471Smrg# func_split_short_opt SHORTOPT
1880b7d26471Smrg# -----------------------------
1881629baa8cSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
1882629baa8cSmrg# variables after splitting SHORTOPT after the 2nd character.
1883b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"
1884b7d26471Smrgthen
1885b7d26471Smrg  # This is an XSI compatible shell, allowing a faster implementation...
1886b7d26471Smrg  eval 'func_split_short_opt ()
1887b7d26471Smrg  {
1888b7d26471Smrg      $debug_cmd
1889b7d26471Smrg
1890b7d26471Smrg      func_split_short_opt_arg=${1#??}
1891b7d26471Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1892b7d26471Smrg  }'
1893b7d26471Smrgelse
1894b7d26471Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1895b7d26471Smrg  func_split_short_opt ()
1896b7d26471Smrg  {
1897b7d26471Smrg      $debug_cmd
1898b7d26471Smrg
1899b7d26471Smrg      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1900b7d26471Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1901b7d26471Smrg  }
1902b7d26471Smrgfi #func_split_short_opt
1903b7d26471Smrg
1904b7d26471Smrg
1905b7d26471Smrg# func_usage
1906b7d26471Smrg# ----------
1907b7d26471Smrg# Echo short help message to standard output and exit.
1908b7d26471Smrgfunc_usage ()
1909629baa8cSmrg{
1910b7d26471Smrg    $debug_cmd
1911629baa8cSmrg
1912b7d26471Smrg    func_usage_message
1913b7d26471Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
1914b7d26471Smrg    exit 0
1915b7d26471Smrg}
1916145b7b3cSmrg
19175ffd6003Smrg
1918b7d26471Smrg# func_usage_message
1919b7d26471Smrg# ------------------
1920b7d26471Smrg# Echo short help message to standard output.
1921b7d26471Smrgfunc_usage_message ()
1922629baa8cSmrg{
1923b7d26471Smrg    $debug_cmd
1924629baa8cSmrg
1925b7d26471Smrg    eval \$ECHO \""Usage: $usage"\"
1926b7d26471Smrg    echo
1927b7d26471Smrg    $SED -n 's|^# ||
1928b7d26471Smrg        /^Written by/{
1929b7d26471Smrg          x;p;x
1930b7d26471Smrg        }
1931b7d26471Smrg	h
1932b7d26471Smrg	/^Written by/q' < "$progpath"
1933b7d26471Smrg    echo
1934b7d26471Smrg    eval \$ECHO \""$usage_message"\"
1935b7d26471Smrg}
1936629baa8cSmrg
1937629baa8cSmrg
1938b7d26471Smrg# func_version
1939b7d26471Smrg# ------------
1940b7d26471Smrg# Echo version message to standard output and exit.
1941b7d26471Smrgfunc_version ()
1942b7d26471Smrg{
1943b7d26471Smrg    $debug_cmd
19445ffd6003Smrg
1945b7d26471Smrg    printf '%s\n' "$progname $scriptversion"
1946b7d26471Smrg    $SED -n '
1947b7d26471Smrg        /(C)/!b go
1948b7d26471Smrg        :more
1949b7d26471Smrg        /\./!{
1950b7d26471Smrg          N
1951b7d26471Smrg          s|\n# | |
1952b7d26471Smrg          b more
1953b7d26471Smrg        }
1954b7d26471Smrg        :go
1955b7d26471Smrg        /^# Written by /,/# warranty; / {
1956b7d26471Smrg          s|^# ||
1957b7d26471Smrg          s|^# *$||
1958b7d26471Smrg          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
1959b7d26471Smrg          p
1960b7d26471Smrg        }
1961b7d26471Smrg        /^# Written by / {
1962b7d26471Smrg          s|^# ||
1963b7d26471Smrg          p
1964b7d26471Smrg        }
1965b7d26471Smrg        /^warranty; /q' < "$progpath"
19665ffd6003Smrg
1967b7d26471Smrg    exit $?
1968b7d26471Smrg}
1969145b7b3cSmrg
1970145b7b3cSmrg
1971b7d26471Smrg# Local variables:
1972b7d26471Smrg# mode: shell-script
1973b7d26471Smrg# sh-indentation: 2
1974b7d26471Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1975b7d26471Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1976b7d26471Smrg# time-stamp-time-zone: "UTC"
1977b7d26471Smrg# End:
1978145b7b3cSmrg
1979b7d26471Smrg# Set a version string.
1980b7d26471Smrgscriptversion='(GNU libtool) 2.4.6'
1981145b7b3cSmrg
19825ffd6003Smrg
1983b7d26471Smrg# func_echo ARG...
1984b7d26471Smrg# ----------------
1985b7d26471Smrg# Libtool also displays the current mode in messages, so override
1986b7d26471Smrg# funclib.sh func_echo with this custom definition.
1987b7d26471Smrgfunc_echo ()
1988629baa8cSmrg{
1989b7d26471Smrg    $debug_cmd
1990629baa8cSmrg
1991b7d26471Smrg    _G_message=$*
1992b7d26471Smrg
1993b7d26471Smrg    func_echo_IFS=$IFS
1994b7d26471Smrg    IFS=$nl
1995b7d26471Smrg    for _G_line in $_G_message; do
1996b7d26471Smrg      IFS=$func_echo_IFS
1997b7d26471Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
1998b7d26471Smrg    done
1999b7d26471Smrg    IFS=$func_echo_IFS
2000b7d26471Smrg}
2001629baa8cSmrg
2002629baa8cSmrg
2003b7d26471Smrg# func_warning ARG...
2004b7d26471Smrg# -------------------
2005b7d26471Smrg# Libtool warnings are not categorized, so override funclib.sh
2006b7d26471Smrg# func_warning with this simpler definition.
2007b7d26471Smrgfunc_warning ()
2008629baa8cSmrg{
2009b7d26471Smrg    $debug_cmd
2010629baa8cSmrg
2011b7d26471Smrg    $warning_func ${1+"$@"}
2012b7d26471Smrg}
2013629baa8cSmrg
2014629baa8cSmrg
2015b7d26471Smrg## ---------------- ##
2016b7d26471Smrg## Options parsing. ##
2017b7d26471Smrg## ---------------- ##
2018b7d26471Smrg
2019b7d26471Smrg# Hook in the functions to make sure our own options are parsed during
2020b7d26471Smrg# the option parsing loop.
2021b7d26471Smrg
2022b7d26471Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2023b7d26471Smrg
2024b7d26471Smrg# Short help message in response to '-h'.
2025b7d26471Smrgusage_message="Options:
2026b7d26471Smrg       --config             show all configuration variables
2027b7d26471Smrg       --debug              enable verbose shell tracing
2028b7d26471Smrg   -n, --dry-run            display commands without modifying any files
2029b7d26471Smrg       --features           display basic configuration information and exit
2030b7d26471Smrg       --mode=MODE          use operation mode MODE
2031b7d26471Smrg       --no-warnings        equivalent to '-Wnone'
2032b7d26471Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2033b7d26471Smrg       --quiet, --silent    don't print informational messages
2034b7d26471Smrg       --tag=TAG            use configuration variables from tag TAG
2035b7d26471Smrg   -v, --verbose            print more informational messages than default
2036b7d26471Smrg       --version            print version information
2037b7d26471Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2038b7d26471Smrg   -h, --help, --help-all   print short, long, or detailed help message
2039b7d26471Smrg"
2040629baa8cSmrg
2041b7d26471Smrg# Additional text appended to 'usage_message' in response to '--help'.
2042b7d26471Smrgfunc_help ()
2043629baa8cSmrg{
2044b7d26471Smrg    $debug_cmd
2045b7d26471Smrg
2046b7d26471Smrg    func_usage_message
2047b7d26471Smrg    $ECHO "$long_help_message
2048b7d26471Smrg
2049b7d26471SmrgMODE must be one of the following:
2050b7d26471Smrg
2051b7d26471Smrg       clean           remove files from the build directory
2052b7d26471Smrg       compile         compile a source file into a libtool object
2053b7d26471Smrg       execute         automatically set library path, then run a program
2054b7d26471Smrg       finish          complete the installation of libtool libraries
2055b7d26471Smrg       install         install libraries or executables
2056b7d26471Smrg       link            create a library or an executable
2057b7d26471Smrg       uninstall       remove libraries from an installed directory
2058b7d26471Smrg
2059b7d26471SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2060b7d26471Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2061b7d26471SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2062b7d26471Smrg
2063b7d26471SmrgWhen reporting a bug, please describe a test case to reproduce it and
2064b7d26471Smrginclude the following information:
2065b7d26471Smrg
2066b7d26471Smrg       host-triplet:   $host
2067b7d26471Smrg       shell:          $SHELL
2068b7d26471Smrg       compiler:       $LTCC
2069b7d26471Smrg       compiler flags: $LTCFLAGS
2070b7d26471Smrg       linker:         $LD (gnu? $with_gnu_ld)
2071b7d26471Smrg       version:        $progname (GNU libtool) 2.4.6
2072b7d26471Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2073b7d26471Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2074b7d26471Smrg
2075b7d26471SmrgReport bugs to <bug-libtool@gnu.org>.
2076b7d26471SmrgGNU libtool home page: <http://www.gnu.org/s/libtool/>.
2077b7d26471SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2078b7d26471Smrg    exit 0
2079b7d26471Smrg}
2080629baa8cSmrg
2081629baa8cSmrg
2082b7d26471Smrg# func_lo2o OBJECT-NAME
2083b7d26471Smrg# ---------------------
2084b7d26471Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2085b7d26471Smrg# object suffix.
2086b7d26471Smrg
2087b7d26471Smrglo2o=s/\\.lo\$/.$objext/
2088b7d26471Smrgo2lo=s/\\.$objext\$/.lo/
2089b7d26471Smrg
2090b7d26471Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2091b7d26471Smrg  eval 'func_lo2o ()
2092b7d26471Smrg  {
2093b7d26471Smrg    case $1 in
2094b7d26471Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2095b7d26471Smrg      *   ) func_lo2o_result=$1               ;;
2096b7d26471Smrg    esac
2097b7d26471Smrg  }'
2098b7d26471Smrg
2099b7d26471Smrg  # func_xform LIBOBJ-OR-SOURCE
2100b7d26471Smrg  # ---------------------------
2101b7d26471Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2102b7d26471Smrg  # suffix to a '.lo' libtool-object suffix.
2103b7d26471Smrg  eval 'func_xform ()
2104b7d26471Smrg  {
2105b7d26471Smrg    func_xform_result=${1%.*}.lo
2106b7d26471Smrg  }'
2107b7d26471Smrgelse
2108b7d26471Smrg  # ...otherwise fall back to using sed.
2109b7d26471Smrg  func_lo2o ()
2110b7d26471Smrg  {
2111b7d26471Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2112b7d26471Smrg  }
2113b7d26471Smrg
2114b7d26471Smrg  func_xform ()
2115b7d26471Smrg  {
2116b7d26471Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2117b7d26471Smrg  }
2118b7d26471Smrgfi
2119629baa8cSmrg
2120629baa8cSmrg
2121b7d26471Smrg# func_fatal_configuration ARG...
2122b7d26471Smrg# -------------------------------
21235ffd6003Smrg# Echo program name prefixed message to standard error, followed by
21245ffd6003Smrg# a configuration failure hint, and exit.
21255ffd6003Smrgfunc_fatal_configuration ()
21265ffd6003Smrg{
2127b7d26471Smrg    func__fatal_error ${1+"$@"} \
2128b7d26471Smrg      "See the $PACKAGE documentation for more information." \
2129b7d26471Smrg      "Fatal configuration error."
21305ffd6003Smrg}
2131145b7b3cSmrg
2132578741aaSmrg
21335ffd6003Smrg# func_config
2134b7d26471Smrg# -----------
21355ffd6003Smrg# Display the configuration for all the tags in this script.
21365ffd6003Smrgfunc_config ()
21375ffd6003Smrg{
21385ffd6003Smrg    re_begincf='^# ### BEGIN LIBTOOL'
21395ffd6003Smrg    re_endcf='^# ### END LIBTOOL'
21405ffd6003Smrg
21415ffd6003Smrg    # Default configuration.
21425ffd6003Smrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2143145b7b3cSmrg
2144145b7b3cSmrg    # Now print the configurations for the tags.
2145145b7b3cSmrg    for tagname in $taglist; do
21465ffd6003Smrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2147145b7b3cSmrg    done
2148145b7b3cSmrg
21495ffd6003Smrg    exit $?
21505ffd6003Smrg}
2151145b7b3cSmrg
2152b7d26471Smrg
21535ffd6003Smrg# func_features
2154b7d26471Smrg# -------------
21555ffd6003Smrg# Display the features supported by this script.
21565ffd6003Smrgfunc_features ()
21575ffd6003Smrg{
2158629baa8cSmrg    echo "host: $host"
2159b7d26471Smrg    if test yes = "$build_libtool_libs"; then
2160629baa8cSmrg      echo "enable shared libraries"
2161145b7b3cSmrg    else
2162629baa8cSmrg      echo "disable shared libraries"
2163145b7b3cSmrg    fi
2164b7d26471Smrg    if test yes = "$build_old_libs"; then
2165629baa8cSmrg      echo "enable static libraries"
2166145b7b3cSmrg    else
2167629baa8cSmrg      echo "disable static libraries"
2168145b7b3cSmrg    fi
21695ffd6003Smrg
2170145b7b3cSmrg    exit $?
21715ffd6003Smrg}
2172145b7b3cSmrg
2173b7d26471Smrg
2174b7d26471Smrg# func_enable_tag TAGNAME
2175b7d26471Smrg# -----------------------
21765ffd6003Smrg# Verify that TAGNAME is valid, and either flag an error and exit, or
21775ffd6003Smrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
21785ffd6003Smrg# variable here.
21795ffd6003Smrgfunc_enable_tag ()
21805ffd6003Smrg{
2181b7d26471Smrg    # Global variable:
2182b7d26471Smrg    tagname=$1
2183145b7b3cSmrg
2184b7d26471Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2185b7d26471Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2186b7d26471Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2187145b7b3cSmrg
2188b7d26471Smrg    # Validate tagname.
2189b7d26471Smrg    case $tagname in
2190b7d26471Smrg      *[!-_A-Za-z0-9,/]*)
2191b7d26471Smrg        func_fatal_error "invalid tag name: $tagname"
2192b7d26471Smrg        ;;
2193b7d26471Smrg    esac
2194145b7b3cSmrg
2195b7d26471Smrg    # Don't test for the "default" C tag, as we know it's
2196b7d26471Smrg    # there but not specially marked.
2197b7d26471Smrg    case $tagname in
2198b7d26471Smrg        CC) ;;
21995ffd6003Smrg    *)
2200b7d26471Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2201b7d26471Smrg	  taglist="$taglist $tagname"
2202b7d26471Smrg
2203b7d26471Smrg	  # Evaluate the configuration.  Be careful to quote the path
2204b7d26471Smrg	  # and the sed script, to avoid splitting on whitespace, but
2205b7d26471Smrg	  # also don't use non-portable quotes within backquotes within
2206b7d26471Smrg	  # quotes we have to do it in 2 steps:
2207b7d26471Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2208b7d26471Smrg	  eval "$extractedcf"
2209b7d26471Smrg        else
2210b7d26471Smrg	  func_error "ignoring unknown tag $tagname"
2211b7d26471Smrg        fi
2212b7d26471Smrg        ;;
2213b7d26471Smrg    esac
22145ffd6003Smrg}
22155ffd6003Smrg
2216b7d26471Smrg
2217629baa8cSmrg# func_check_version_match
2218b7d26471Smrg# ------------------------
2219629baa8cSmrg# Ensure that we are using m4 macros, and libtool script from the same
2220629baa8cSmrg# release of libtool.
2221629baa8cSmrgfunc_check_version_match ()
22225ffd6003Smrg{
2223b7d26471Smrg    if test "$package_revision" != "$macro_revision"; then
2224b7d26471Smrg      if test "$VERSION" != "$macro_version"; then
2225b7d26471Smrg        if test -z "$macro_version"; then
2226b7d26471Smrg          cat >&2 <<_LT_EOF
2227629baa8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2228629baa8cSmrg$progname: definition of this LT_INIT comes from an older release.
2229629baa8cSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2230629baa8cSmrg$progname: and run autoconf again.
2231629baa8cSmrg_LT_EOF
2232b7d26471Smrg        else
2233b7d26471Smrg          cat >&2 <<_LT_EOF
2234629baa8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2235629baa8cSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2236629baa8cSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2237629baa8cSmrg$progname: and run autoconf again.
2238629baa8cSmrg_LT_EOF
2239b7d26471Smrg        fi
2240b7d26471Smrg      else
2241b7d26471Smrg        cat >&2 <<_LT_EOF
2242629baa8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2243629baa8cSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2244629baa8cSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2245629baa8cSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
2246629baa8cSmrg_LT_EOF
2247b7d26471Smrg      fi
2248629baa8cSmrg
2249b7d26471Smrg      exit $EXIT_MISMATCH
2250b7d26471Smrg    fi
2251629baa8cSmrg}
2252629baa8cSmrg
2253629baa8cSmrg
2254b7d26471Smrg# libtool_options_prep [ARG]...
2255b7d26471Smrg# -----------------------------
2256b7d26471Smrg# Preparation for options parsed by libtool.
2257b7d26471Smrglibtool_options_prep ()
2258b7d26471Smrg{
2259b7d26471Smrg    $debug_mode
2260145b7b3cSmrg
2261b7d26471Smrg    # Option defaults:
2262b7d26471Smrg    opt_config=false
2263b7d26471Smrg    opt_dlopen=
2264b7d26471Smrg    opt_dry_run=false
2265b7d26471Smrg    opt_help=false
2266b7d26471Smrg    opt_mode=
2267b7d26471Smrg    opt_preserve_dup_deps=false
2268b7d26471Smrg    opt_quiet=false
2269145b7b3cSmrg
2270b7d26471Smrg    nonopt=
2271b7d26471Smrg    preserve_args=
2272629baa8cSmrg
2273b7d26471Smrg    # Shorthand for --mode=foo, only valid as the first argument
2274b7d26471Smrg    case $1 in
2275b7d26471Smrg    clean|clea|cle|cl)
2276b7d26471Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2277b7d26471Smrg      ;;
2278b7d26471Smrg    compile|compil|compi|comp|com|co|c)
2279b7d26471Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2280b7d26471Smrg      ;;
2281b7d26471Smrg    execute|execut|execu|exec|exe|ex|e)
2282b7d26471Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2283b7d26471Smrg      ;;
2284b7d26471Smrg    finish|finis|fini|fin|fi|f)
2285b7d26471Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2286b7d26471Smrg      ;;
2287b7d26471Smrg    install|instal|insta|inst|ins|in|i)
2288b7d26471Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2289b7d26471Smrg      ;;
2290b7d26471Smrg    link|lin|li|l)
2291b7d26471Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2292b7d26471Smrg      ;;
2293b7d26471Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2294b7d26471Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2295b7d26471Smrg      ;;
2296b7d26471Smrg    esac
2297b7d26471Smrg
2298b7d26471Smrg    # Pass back the list of options.
2299b7d26471Smrg    func_quote_for_eval ${1+"$@"}
2300b7d26471Smrg    libtool_options_prep_result=$func_quote_for_eval_result
2301b7d26471Smrg}
2302b7d26471Smrgfunc_add_hook func_options_prep libtool_options_prep
2303629baa8cSmrg
2304629baa8cSmrg
2305b7d26471Smrg# libtool_parse_options [ARG]...
2306b7d26471Smrg# ---------------------------------
2307b7d26471Smrg# Provide handling for libtool specific options.
2308b7d26471Smrglibtool_parse_options ()
2309629baa8cSmrg{
2310b7d26471Smrg    $debug_cmd
23115ffd6003Smrg
2312b7d26471Smrg    # Perform our own loop to consume as many options as possible in
2313b7d26471Smrg    # each iteration.
2314b7d26471Smrg    while test $# -gt 0; do
2315b7d26471Smrg      _G_opt=$1
2316b7d26471Smrg      shift
2317b7d26471Smrg      case $_G_opt in
2318b7d26471Smrg        --dry-run|--dryrun|-n)
2319b7d26471Smrg                        opt_dry_run=:
2320b7d26471Smrg                        ;;
2321b7d26471Smrg
2322b7d26471Smrg        --config)       func_config ;;
2323b7d26471Smrg
2324b7d26471Smrg        --dlopen|-dlopen)
2325b7d26471Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2326b7d26471Smrg}$1"
2327b7d26471Smrg                        shift
2328b7d26471Smrg                        ;;
2329b7d26471Smrg
2330b7d26471Smrg        --preserve-dup-deps)
2331b7d26471Smrg                        opt_preserve_dup_deps=: ;;
2332b7d26471Smrg
2333b7d26471Smrg        --features)     func_features ;;
2334b7d26471Smrg
2335b7d26471Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2336b7d26471Smrg
2337b7d26471Smrg        --help)         opt_help=: ;;
2338b7d26471Smrg
2339b7d26471Smrg        --help-all)     opt_help=': help-all' ;;
2340b7d26471Smrg
2341b7d26471Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2342b7d26471Smrg                        opt_mode=$1
2343b7d26471Smrg                        case $1 in
2344b7d26471Smrg                          # Valid mode arguments:
2345b7d26471Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2346b7d26471Smrg
2347b7d26471Smrg                          # Catch anything else as an error
2348b7d26471Smrg                          *) func_error "invalid argument for $_G_opt"
2349b7d26471Smrg                             exit_cmd=exit
2350b7d26471Smrg                             break
2351b7d26471Smrg                             ;;
2352b7d26471Smrg                        esac
2353b7d26471Smrg                        shift
2354b7d26471Smrg                        ;;
2355b7d26471Smrg
2356b7d26471Smrg        --no-silent|--no-quiet)
2357b7d26471Smrg                        opt_quiet=false
2358b7d26471Smrg                        func_append preserve_args " $_G_opt"
2359b7d26471Smrg                        ;;
2360b7d26471Smrg
2361b7d26471Smrg        --no-warnings|--no-warning|--no-warn)
2362b7d26471Smrg                        opt_warning=false
2363b7d26471Smrg                        func_append preserve_args " $_G_opt"
2364b7d26471Smrg                        ;;
2365b7d26471Smrg
2366b7d26471Smrg        --no-verbose)
2367b7d26471Smrg                        opt_verbose=false
2368b7d26471Smrg                        func_append preserve_args " $_G_opt"
2369b7d26471Smrg                        ;;
2370b7d26471Smrg
2371b7d26471Smrg        --silent|--quiet)
2372b7d26471Smrg                        opt_quiet=:
2373b7d26471Smrg                        opt_verbose=false
2374b7d26471Smrg                        func_append preserve_args " $_G_opt"
2375b7d26471Smrg                        ;;
2376b7d26471Smrg
2377b7d26471Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2378b7d26471Smrg                        opt_tag=$1
2379b7d26471Smrg                        func_append preserve_args " $_G_opt $1"
2380b7d26471Smrg                        func_enable_tag "$1"
2381b7d26471Smrg                        shift
2382b7d26471Smrg                        ;;
2383b7d26471Smrg
2384b7d26471Smrg        --verbose|-v)   opt_quiet=false
2385b7d26471Smrg                        opt_verbose=:
2386b7d26471Smrg                        func_append preserve_args " $_G_opt"
2387b7d26471Smrg                        ;;
2388b7d26471Smrg
2389b7d26471Smrg	# An option not handled by this hook function:
2390b7d26471Smrg        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
2391b7d26471Smrg      esac
2392b7d26471Smrg    done
2393629baa8cSmrg
2394629baa8cSmrg
2395b7d26471Smrg    # save modified positional parameters for caller
2396b7d26471Smrg    func_quote_for_eval ${1+"$@"}
2397b7d26471Smrg    libtool_parse_options_result=$func_quote_for_eval_result
2398b7d26471Smrg}
2399b7d26471Smrgfunc_add_hook func_parse_options libtool_parse_options
24005ffd6003Smrg
2401145b7b3cSmrg
24025ffd6003Smrg
2403b7d26471Smrg# libtool_validate_options [ARG]...
2404b7d26471Smrg# ---------------------------------
2405b7d26471Smrg# Perform any sanity checks on option settings and/or unconsumed
2406b7d26471Smrg# arguments.
2407b7d26471Smrglibtool_validate_options ()
2408b7d26471Smrg{
2409b7d26471Smrg    # save first non-option argument
2410b7d26471Smrg    if test 0 -lt $#; then
2411b7d26471Smrg      nonopt=$1
2412b7d26471Smrg      shift
24135ffd6003Smrg    fi
24145ffd6003Smrg
2415b7d26471Smrg    # preserve --debug
2416b7d26471Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
24175ffd6003Smrg
2418b7d26471Smrg    case $host in
2419b7d26471Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2420b7d26471Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2421b7d26471Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2422b7d26471Smrg        # don't eliminate duplications in $postdeps and $predeps
2423b7d26471Smrg        opt_duplicate_compiler_generated_deps=:
2424b7d26471Smrg        ;;
2425b7d26471Smrg      *)
2426b7d26471Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2427b7d26471Smrg        ;;
2428b7d26471Smrg    esac
2429145b7b3cSmrg
2430b7d26471Smrg    $opt_help || {
2431b7d26471Smrg      # Sanity checks first:
2432b7d26471Smrg      func_check_version_match
2433b7d26471Smrg
2434b7d26471Smrg      test yes != "$build_libtool_libs" \
2435b7d26471Smrg        && test yes != "$build_old_libs" \
2436b7d26471Smrg        && func_fatal_configuration "not configured to build any kind of library"
24375ffd6003Smrg
2438b7d26471Smrg      # Darwin sucks
2439b7d26471Smrg      eval std_shrext=\"$shrext_cmds\"
24405ffd6003Smrg
2441b7d26471Smrg      # Only execute mode is allowed to have -dlopen flags.
2442b7d26471Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2443b7d26471Smrg        func_error "unrecognized option '-dlopen'"
2444b7d26471Smrg        $ECHO "$help" 1>&2
2445b7d26471Smrg        exit $EXIT_FAILURE
2446b7d26471Smrg      fi
2447b7d26471Smrg
2448b7d26471Smrg      # Change the help message to a mode-specific one.
2449b7d26471Smrg      generic_help=$help
2450b7d26471Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2451b7d26471Smrg    }
2452b7d26471Smrg
2453b7d26471Smrg    # Pass back the unparsed argument list
2454b7d26471Smrg    func_quote_for_eval ${1+"$@"}
2455b7d26471Smrg    libtool_validate_options_result=$func_quote_for_eval_result
2456629baa8cSmrg}
2457b7d26471Smrgfunc_add_hook func_validate_options libtool_validate_options
24585ffd6003Smrg
24595ffd6003Smrg
2460b7d26471Smrg# Process options as early as possible so that --help and --version
2461b7d26471Smrg# can return quickly.
2462b7d26471Smrgfunc_options ${1+"$@"}
2463b7d26471Smrgeval set dummy "$func_options_result"; shift
2464b7d26471Smrg
2465145b7b3cSmrg
2466145b7b3cSmrg
2467629baa8cSmrg## ----------- ##
2468629baa8cSmrg##    Main.    ##
2469629baa8cSmrg## ----------- ##
2470145b7b3cSmrg
2471b7d26471Smrgmagic='%%%MAGIC variable%%%'
2472b7d26471Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2473b7d26471Smrg
2474b7d26471Smrg# Global variables.
2475b7d26471Smrgextracted_archives=
2476b7d26471Smrgextracted_serial=0
2477b7d26471Smrg
2478b7d26471Smrg# If this variable is set in any of the actions, the command in it
2479b7d26471Smrg# will be execed at the end.  This prevents here-documents from being
2480b7d26471Smrg# left over by shells.
2481b7d26471Smrgexec_cmd=
2482b7d26471Smrg
2483b7d26471Smrg
2484b7d26471Smrg# A function that is used when there is no print builtin or printf.
2485b7d26471Smrgfunc_fallback_echo ()
2486b7d26471Smrg{
2487b7d26471Smrg  eval 'cat <<_LTECHO_EOF
2488b7d26471Smrg$1
2489b7d26471Smrg_LTECHO_EOF'
2490b7d26471Smrg}
2491b7d26471Smrg
2492b7d26471Smrg# func_generated_by_libtool
2493b7d26471Smrg# True iff stdin has been generated by Libtool. This function is only
2494b7d26471Smrg# a basic sanity check; it will hardly flush out determined imposters.
2495b7d26471Smrgfunc_generated_by_libtool_p ()
2496b7d26471Smrg{
2497b7d26471Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2498b7d26471Smrg}
2499b7d26471Smrg
25005ffd6003Smrg# func_lalib_p file
2501b7d26471Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
25025ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
25035ffd6003Smrg# determined imposters.
25045ffd6003Smrgfunc_lalib_p ()
25055ffd6003Smrg{
25065ffd6003Smrg    test -f "$1" &&
2507b7d26471Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
25085ffd6003Smrg}
2509145b7b3cSmrg
25105ffd6003Smrg# func_lalib_unsafe_p file
2511b7d26471Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
25125ffd6003Smrg# This function implements the same check as func_lalib_p without
25135ffd6003Smrg# resorting to external programs.  To this end, it redirects stdin and
25145ffd6003Smrg# closes it afterwards, without saving the original file descriptor.
25155ffd6003Smrg# As a safety measure, use it only where a negative result would be
2516b7d26471Smrg# fatal anyway.  Works if 'file' does not exist.
25175ffd6003Smrgfunc_lalib_unsafe_p ()
25185ffd6003Smrg{
25195ffd6003Smrg    lalib_p=no
25205ffd6003Smrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
25215ffd6003Smrg	for lalib_p_l in 1 2 3 4
25225ffd6003Smrg	do
25235ffd6003Smrg	    read lalib_p_line
2524b7d26471Smrg	    case $lalib_p_line in
25255ffd6003Smrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
25265ffd6003Smrg	    esac
25275ffd6003Smrg	done
25285ffd6003Smrg	exec 0<&5 5<&-
25295ffd6003Smrg    fi
2530b7d26471Smrg    test yes = "$lalib_p"
25315ffd6003Smrg}
2532145b7b3cSmrg
25335ffd6003Smrg# func_ltwrapper_script_p file
25345ffd6003Smrg# True iff FILE is a libtool wrapper script
25355ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
25365ffd6003Smrg# determined imposters.
25375ffd6003Smrgfunc_ltwrapper_script_p ()
25385ffd6003Smrg{
2539b7d26471Smrg    test -f "$1" &&
2540b7d26471Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
25415ffd6003Smrg}
2542145b7b3cSmrg
25435ffd6003Smrg# func_ltwrapper_executable_p file
25445ffd6003Smrg# True iff FILE is a libtool wrapper executable
25455ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
25465ffd6003Smrg# determined imposters.
25475ffd6003Smrgfunc_ltwrapper_executable_p ()
25485ffd6003Smrg{
25495ffd6003Smrg    func_ltwrapper_exec_suffix=
25505ffd6003Smrg    case $1 in
25515ffd6003Smrg    *.exe) ;;
25525ffd6003Smrg    *) func_ltwrapper_exec_suffix=.exe ;;
25535ffd6003Smrg    esac
25545ffd6003Smrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
25555ffd6003Smrg}
2556145b7b3cSmrg
25575ffd6003Smrg# func_ltwrapper_scriptname file
25585ffd6003Smrg# Assumes file is an ltwrapper_executable
25595ffd6003Smrg# uses $file to determine the appropriate filename for a
25605ffd6003Smrg# temporary ltwrapper_script.
25615ffd6003Smrgfunc_ltwrapper_scriptname ()
25625ffd6003Smrg{
2563629baa8cSmrg    func_dirname_and_basename "$1" "" "."
2564629baa8cSmrg    func_stripname '' '.exe' "$func_basename_result"
2565b7d26471Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
25665ffd6003Smrg}
25675ffd6003Smrg
25685ffd6003Smrg# func_ltwrapper_p file
25695ffd6003Smrg# True iff FILE is a libtool wrapper script or wrapper executable
25705ffd6003Smrg# This function is only a basic sanity check; it will hardly flush out
25715ffd6003Smrg# determined imposters.
25725ffd6003Smrgfunc_ltwrapper_p ()
25735ffd6003Smrg{
25745ffd6003Smrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
25755ffd6003Smrg}
25765ffd6003Smrg
25775ffd6003Smrg
25785ffd6003Smrg# func_execute_cmds commands fail_cmd
25795ffd6003Smrg# Execute tilde-delimited COMMANDS.
25805ffd6003Smrg# If FAIL_CMD is given, eval that upon failure.
25815ffd6003Smrg# FAIL_CMD may read-access the current command in variable CMD!
25825ffd6003Smrgfunc_execute_cmds ()
25835ffd6003Smrg{
2584b7d26471Smrg    $debug_cmd
2585b7d26471Smrg
25865ffd6003Smrg    save_ifs=$IFS; IFS='~'
25875ffd6003Smrg    for cmd in $1; do
2588b7d26471Smrg      IFS=$sp$nl
25895ffd6003Smrg      eval cmd=\"$cmd\"
2590b7d26471Smrg      IFS=$save_ifs
25915ffd6003Smrg      func_show_eval "$cmd" "${2-:}"
25925ffd6003Smrg    done
25935ffd6003Smrg    IFS=$save_ifs
25945ffd6003Smrg}
25955ffd6003Smrg
25965ffd6003Smrg
25975ffd6003Smrg# func_source file
25985ffd6003Smrg# Source FILE, adding directory component if necessary.
25995ffd6003Smrg# Note that it is not necessary on cygwin/mingw to append a dot to
26005ffd6003Smrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
26015ffd6003Smrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2602b7d26471Smrg# 'FILE.' does not work on cygwin managed mounts.
26035ffd6003Smrgfunc_source ()
26045ffd6003Smrg{
2605b7d26471Smrg    $debug_cmd
2606b7d26471Smrg
26075ffd6003Smrg    case $1 in
26085ffd6003Smrg    */* | *\\*)	. "$1" ;;
26095ffd6003Smrg    *)		. "./$1" ;;
26105ffd6003Smrg    esac
26115ffd6003Smrg}
26125ffd6003Smrg
26135ffd6003Smrg
2614629baa8cSmrg# func_resolve_sysroot PATH
2615629baa8cSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
2616629baa8cSmrg# func_resolve_sysroot_result
2617629baa8cSmrgfunc_resolve_sysroot ()
2618629baa8cSmrg{
2619629baa8cSmrg  func_resolve_sysroot_result=$1
2620629baa8cSmrg  case $func_resolve_sysroot_result in
2621629baa8cSmrg  =*)
2622629baa8cSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2623629baa8cSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2624629baa8cSmrg    ;;
2625629baa8cSmrg  esac
2626629baa8cSmrg}
2627629baa8cSmrg
2628629baa8cSmrg# func_replace_sysroot PATH
2629629baa8cSmrg# If PATH begins with the sysroot, replace it with = and
2630629baa8cSmrg# store the result into func_replace_sysroot_result.
2631629baa8cSmrgfunc_replace_sysroot ()
2632629baa8cSmrg{
2633b7d26471Smrg  case $lt_sysroot:$1 in
2634629baa8cSmrg  ?*:"$lt_sysroot"*)
2635629baa8cSmrg    func_stripname "$lt_sysroot" '' "$1"
2636b7d26471Smrg    func_replace_sysroot_result='='$func_stripname_result
2637629baa8cSmrg    ;;
2638629baa8cSmrg  *)
2639629baa8cSmrg    # Including no sysroot.
2640629baa8cSmrg    func_replace_sysroot_result=$1
2641629baa8cSmrg    ;;
2642629baa8cSmrg  esac
2643629baa8cSmrg}
2644629baa8cSmrg
26455ffd6003Smrg# func_infer_tag arg
26465ffd6003Smrg# Infer tagged configuration to use if any are available and
26475ffd6003Smrg# if one wasn't chosen via the "--tag" command line option.
26485ffd6003Smrg# Only attempt this if the compiler in the base compile
26495ffd6003Smrg# command doesn't match the default compiler.
26505ffd6003Smrg# arg is usually of the form 'gcc ...'
26515ffd6003Smrgfunc_infer_tag ()
26525ffd6003Smrg{
2653b7d26471Smrg    $debug_cmd
2654b7d26471Smrg
26555ffd6003Smrg    if test -n "$available_tags" && test -z "$tagname"; then
26565ffd6003Smrg      CC_quoted=
26575ffd6003Smrg      for arg in $CC; do
2658629baa8cSmrg	func_append_quoted CC_quoted "$arg"
26595ffd6003Smrg      done
2660629baa8cSmrg      CC_expanded=`func_echo_all $CC`
2661629baa8cSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
26625ffd6003Smrg      case $@ in
26635ffd6003Smrg      # Blanks in the command may have been stripped by the calling shell,
26645ffd6003Smrg      # but not from the CC environment variable when configure was run.
2665629baa8cSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2666629baa8cSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
26675ffd6003Smrg      # Blanks at the start of $base_compile will cause this to fail
26685ffd6003Smrg      # if we don't check for them as well.
26695ffd6003Smrg      *)
26705ffd6003Smrg	for z in $available_tags; do
26715ffd6003Smrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
26725ffd6003Smrg	    # Evaluate the configuration.
2673b7d26471Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
26745ffd6003Smrg	    CC_quoted=
26755ffd6003Smrg	    for arg in $CC; do
26765ffd6003Smrg	      # Double-quote args containing other shell metacharacters.
2677629baa8cSmrg	      func_append_quoted CC_quoted "$arg"
26785ffd6003Smrg	    done
2679629baa8cSmrg	    CC_expanded=`func_echo_all $CC`
2680629baa8cSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
26815ffd6003Smrg	    case "$@ " in
2682629baa8cSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2683629baa8cSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
26845ffd6003Smrg	      # The compiler in the base compile command matches
26855ffd6003Smrg	      # the one in the tagged configuration.
26865ffd6003Smrg	      # Assume this is the tagged configuration we want.
26875ffd6003Smrg	      tagname=$z
26885ffd6003Smrg	      break
26895ffd6003Smrg	      ;;
26905ffd6003Smrg	    esac
26915ffd6003Smrg	  fi
26925ffd6003Smrg	done
26935ffd6003Smrg	# If $tagname still isn't set, then no tagged configuration
26945ffd6003Smrg	# was found and let the user know that the "--tag" command
26955ffd6003Smrg	# line option must be used.
26965ffd6003Smrg	if test -z "$tagname"; then
26975ffd6003Smrg	  func_echo "unable to infer tagged configuration"
2698b7d26471Smrg	  func_fatal_error "specify a tag with '--tag'"
26995ffd6003Smrg#	else
27005ffd6003Smrg#	  func_verbose "using $tagname tagged configuration"
27015ffd6003Smrg	fi
27025ffd6003Smrg	;;
27035ffd6003Smrg      esac
27045ffd6003Smrg    fi
27055ffd6003Smrg}
27065ffd6003Smrg
27075ffd6003Smrg
27085ffd6003Smrg
27095ffd6003Smrg# func_write_libtool_object output_name pic_name nonpic_name
27105ffd6003Smrg# Create a libtool object file (analogous to a ".la" file),
27115ffd6003Smrg# but don't create it if we're doing a dry run.
27125ffd6003Smrgfunc_write_libtool_object ()
27135ffd6003Smrg{
2714b7d26471Smrg    write_libobj=$1
2715b7d26471Smrg    if test yes = "$build_libtool_libs"; then
2716b7d26471Smrg      write_lobj=\'$2\'
27175ffd6003Smrg    else
27185ffd6003Smrg      write_lobj=none
27195ffd6003Smrg    fi
27205ffd6003Smrg
2721b7d26471Smrg    if test yes = "$build_old_libs"; then
2722b7d26471Smrg      write_oldobj=\'$3\'
27235ffd6003Smrg    else
27245ffd6003Smrg      write_oldobj=none
27255ffd6003Smrg    fi
27265ffd6003Smrg
27275ffd6003Smrg    $opt_dry_run || {
27285ffd6003Smrg      cat >${write_libobj}T <<EOF
27295ffd6003Smrg# $write_libobj - a libtool object file
2730b7d26471Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
27315ffd6003Smrg#
27325ffd6003Smrg# Please DO NOT delete this file!
27335ffd6003Smrg# It is necessary for linking the library.
27345ffd6003Smrg
27355ffd6003Smrg# Name of the PIC object.
27365ffd6003Smrgpic_object=$write_lobj
27375ffd6003Smrg
27385ffd6003Smrg# Name of the non-PIC object
27395ffd6003Smrgnon_pic_object=$write_oldobj
27405ffd6003Smrg
27415ffd6003SmrgEOF
2742b7d26471Smrg      $MV "${write_libobj}T" "$write_libobj"
27435ffd6003Smrg    }
27445ffd6003Smrg}
27455ffd6003Smrg
2746629baa8cSmrg
2747629baa8cSmrg##################################################
2748629baa8cSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
2749629baa8cSmrg##################################################
2750629baa8cSmrg
2751629baa8cSmrg# func_convert_core_file_wine_to_w32 ARG
2752629baa8cSmrg# Helper function used by file name conversion functions when $build is *nix,
2753629baa8cSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
2754629baa8cSmrg# correctly configured wine environment available, with the winepath program
2755629baa8cSmrg# in $build's $PATH.
2756629baa8cSmrg#
2757629baa8cSmrg# ARG is the $build file name to be converted to w32 format.
2758629baa8cSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
2759629baa8cSmrg# be empty on error (or when ARG is empty)
2760629baa8cSmrgfunc_convert_core_file_wine_to_w32 ()
2761629baa8cSmrg{
2762b7d26471Smrg  $debug_cmd
2763b7d26471Smrg
2764b7d26471Smrg  func_convert_core_file_wine_to_w32_result=$1
2765629baa8cSmrg  if test -n "$1"; then
2766629baa8cSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
2767629baa8cSmrg    # are forced to check the contents of stdout. On the other hand, if the
2768629baa8cSmrg    # command is not found, the shell will set an exit code of 127 and print
2769629baa8cSmrg    # *an error message* to stdout. So we must check for both error code of
2770629baa8cSmrg    # zero AND non-empty stdout, which explains the odd construction:
2771629baa8cSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
2772b7d26471Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
2773629baa8cSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
2774b7d26471Smrg        $SED -e "$sed_naive_backslashify"`
2775629baa8cSmrg    else
2776629baa8cSmrg      func_convert_core_file_wine_to_w32_result=
2777629baa8cSmrg    fi
2778629baa8cSmrg  fi
2779629baa8cSmrg}
2780629baa8cSmrg# end: func_convert_core_file_wine_to_w32
2781629baa8cSmrg
2782629baa8cSmrg
2783629baa8cSmrg# func_convert_core_path_wine_to_w32 ARG
2784629baa8cSmrg# Helper function used by path conversion functions when $build is *nix, and
2785629baa8cSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
2786629baa8cSmrg# configured wine environment available, with the winepath program in $build's
2787629baa8cSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
2788629baa8cSmrg#
2789629baa8cSmrg# ARG is path to be converted from $build format to win32.
2790629baa8cSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
2791629baa8cSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
2792629baa8cSmrg# are convertible, then the result may be empty.
2793629baa8cSmrgfunc_convert_core_path_wine_to_w32 ()
2794629baa8cSmrg{
2795b7d26471Smrg  $debug_cmd
2796b7d26471Smrg
2797629baa8cSmrg  # unfortunately, winepath doesn't convert paths, only file names
2798b7d26471Smrg  func_convert_core_path_wine_to_w32_result=
2799629baa8cSmrg  if test -n "$1"; then
2800629baa8cSmrg    oldIFS=$IFS
2801629baa8cSmrg    IFS=:
2802629baa8cSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
2803629baa8cSmrg      IFS=$oldIFS
2804629baa8cSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
2805b7d26471Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
2806629baa8cSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
2807b7d26471Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
2808629baa8cSmrg        else
2809629baa8cSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
2810629baa8cSmrg        fi
2811629baa8cSmrg      fi
2812629baa8cSmrg    done
2813629baa8cSmrg    IFS=$oldIFS
2814629baa8cSmrg  fi
2815629baa8cSmrg}
2816629baa8cSmrg# end: func_convert_core_path_wine_to_w32
2817629baa8cSmrg
2818629baa8cSmrg
2819629baa8cSmrg# func_cygpath ARGS...
2820629baa8cSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
2821629baa8cSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
2822629baa8cSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
2823629baa8cSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
2824629baa8cSmrg# file name or path is assumed to be in w32 format, as previously converted
2825629baa8cSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
2826629baa8cSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
2827629baa8cSmrg# Cygwin format). Returns an empty string on error.
2828629baa8cSmrg#
2829629baa8cSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
2830629baa8cSmrg# be converted.
2831629baa8cSmrg#
2832629baa8cSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
2833629baa8cSmrg# environment variable; do not put it in $PATH.
2834629baa8cSmrgfunc_cygpath ()
2835629baa8cSmrg{
2836b7d26471Smrg  $debug_cmd
2837b7d26471Smrg
2838629baa8cSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
2839629baa8cSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
2840629baa8cSmrg    if test "$?" -ne 0; then
2841629baa8cSmrg      # on failure, ensure result is empty
2842629baa8cSmrg      func_cygpath_result=
2843629baa8cSmrg    fi
2844629baa8cSmrg  else
2845629baa8cSmrg    func_cygpath_result=
2846b7d26471Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
2847629baa8cSmrg  fi
2848629baa8cSmrg}
2849629baa8cSmrg#end: func_cygpath
2850629baa8cSmrg
2851629baa8cSmrg
2852629baa8cSmrg# func_convert_core_msys_to_w32 ARG
2853629baa8cSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
2854629baa8cSmrg# result in func_convert_core_msys_to_w32_result.
2855629baa8cSmrgfunc_convert_core_msys_to_w32 ()
2856629baa8cSmrg{
2857b7d26471Smrg  $debug_cmd
2858b7d26471Smrg
2859629baa8cSmrg  # awkward: cmd appends spaces to result
2860629baa8cSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
2861b7d26471Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
2862629baa8cSmrg}
2863629baa8cSmrg#end: func_convert_core_msys_to_w32
2864629baa8cSmrg
2865629baa8cSmrg
2866629baa8cSmrg# func_convert_file_check ARG1 ARG2
2867629baa8cSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
2868629baa8cSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
2869629baa8cSmrg# func_to_host_file_result to ARG1).
2870629baa8cSmrgfunc_convert_file_check ()
2871629baa8cSmrg{
2872b7d26471Smrg  $debug_cmd
2873b7d26471Smrg
2874b7d26471Smrg  if test -z "$2" && test -n "$1"; then
2875629baa8cSmrg    func_error "Could not determine host file name corresponding to"
2876b7d26471Smrg    func_error "  '$1'"
2877629baa8cSmrg    func_error "Continuing, but uninstalled executables may not work."
2878629baa8cSmrg    # Fallback:
2879b7d26471Smrg    func_to_host_file_result=$1
2880629baa8cSmrg  fi
2881629baa8cSmrg}
2882629baa8cSmrg# end func_convert_file_check
2883629baa8cSmrg
2884629baa8cSmrg
2885629baa8cSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
2886629baa8cSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
2887629baa8cSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
2888629baa8cSmrg# func_to_host_file_result to a simplistic fallback value (see below).
2889629baa8cSmrgfunc_convert_path_check ()
2890629baa8cSmrg{
2891b7d26471Smrg  $debug_cmd
2892b7d26471Smrg
2893629baa8cSmrg  if test -z "$4" && test -n "$3"; then
2894629baa8cSmrg    func_error "Could not determine the host path corresponding to"
2895b7d26471Smrg    func_error "  '$3'"
2896629baa8cSmrg    func_error "Continuing, but uninstalled executables may not work."
2897629baa8cSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
2898629baa8cSmrg    # should not be "improved".  See libtool.info.
2899629baa8cSmrg    if test "x$1" != "x$2"; then
2900629baa8cSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
2901629baa8cSmrg      func_to_host_path_result=`echo "$3" |
2902629baa8cSmrg        $SED -e "$lt_replace_pathsep_chars"`
2903629baa8cSmrg    else
2904b7d26471Smrg      func_to_host_path_result=$3
2905629baa8cSmrg    fi
2906629baa8cSmrg  fi
2907629baa8cSmrg}
2908629baa8cSmrg# end func_convert_path_check
2909629baa8cSmrg
2910629baa8cSmrg
2911629baa8cSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
2912629baa8cSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
2913629baa8cSmrg# and appending REPL if ORIG matches BACKPAT.
2914629baa8cSmrgfunc_convert_path_front_back_pathsep ()
2915629baa8cSmrg{
2916b7d26471Smrg  $debug_cmd
2917b7d26471Smrg
2918629baa8cSmrg  case $4 in
2919b7d26471Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
2920629baa8cSmrg    ;;
2921629baa8cSmrg  esac
2922629baa8cSmrg  case $4 in
2923629baa8cSmrg  $2 ) func_append func_to_host_path_result "$3"
2924629baa8cSmrg    ;;
2925629baa8cSmrg  esac
2926629baa8cSmrg}
2927629baa8cSmrg# end func_convert_path_front_back_pathsep
2928629baa8cSmrg
2929629baa8cSmrg
2930629baa8cSmrg##################################################
2931629baa8cSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
2932629baa8cSmrg##################################################
2933b7d26471Smrg# invoked via '$to_host_file_cmd ARG'
2934629baa8cSmrg#
2935629baa8cSmrg# In each case, ARG is the path to be converted from $build to $host format.
2936629baa8cSmrg# Result will be available in $func_to_host_file_result.
2937629baa8cSmrg
2938629baa8cSmrg
2939629baa8cSmrg# func_to_host_file ARG
2940629baa8cSmrg# Converts the file name ARG from $build format to $host format. Return result
2941629baa8cSmrg# in func_to_host_file_result.
2942629baa8cSmrgfunc_to_host_file ()
2943629baa8cSmrg{
2944b7d26471Smrg  $debug_cmd
2945b7d26471Smrg
2946629baa8cSmrg  $to_host_file_cmd "$1"
2947629baa8cSmrg}
2948629baa8cSmrg# end func_to_host_file
2949629baa8cSmrg
2950629baa8cSmrg
2951629baa8cSmrg# func_to_tool_file ARG LAZY
2952629baa8cSmrg# converts the file name ARG from $build format to toolchain format. Return
2953629baa8cSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
2954629baa8cSmrg# in (the comma separated) LAZY, no conversion takes place.
2955629baa8cSmrgfunc_to_tool_file ()
2956629baa8cSmrg{
2957b7d26471Smrg  $debug_cmd
2958b7d26471Smrg
2959629baa8cSmrg  case ,$2, in
2960629baa8cSmrg    *,"$to_tool_file_cmd",*)
2961629baa8cSmrg      func_to_tool_file_result=$1
2962629baa8cSmrg      ;;
2963629baa8cSmrg    *)
2964629baa8cSmrg      $to_tool_file_cmd "$1"
2965629baa8cSmrg      func_to_tool_file_result=$func_to_host_file_result
2966629baa8cSmrg      ;;
2967629baa8cSmrg  esac
2968629baa8cSmrg}
2969629baa8cSmrg# end func_to_tool_file
2970629baa8cSmrg
2971629baa8cSmrg
2972629baa8cSmrg# func_convert_file_noop ARG
2973629baa8cSmrg# Copy ARG to func_to_host_file_result.
2974629baa8cSmrgfunc_convert_file_noop ()
2975629baa8cSmrg{
2976b7d26471Smrg  func_to_host_file_result=$1
2977629baa8cSmrg}
2978629baa8cSmrg# end func_convert_file_noop
2979629baa8cSmrg
2980629baa8cSmrg
2981629baa8cSmrg# func_convert_file_msys_to_w32 ARG
2982629baa8cSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
2983629baa8cSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
2984629baa8cSmrg# func_to_host_file_result.
2985629baa8cSmrgfunc_convert_file_msys_to_w32 ()
2986629baa8cSmrg{
2987b7d26471Smrg  $debug_cmd
2988b7d26471Smrg
2989b7d26471Smrg  func_to_host_file_result=$1
2990629baa8cSmrg  if test -n "$1"; then
2991629baa8cSmrg    func_convert_core_msys_to_w32 "$1"
2992b7d26471Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
2993629baa8cSmrg  fi
2994629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
2995629baa8cSmrg}
2996629baa8cSmrg# end func_convert_file_msys_to_w32
2997629baa8cSmrg
2998629baa8cSmrg
2999629baa8cSmrg# func_convert_file_cygwin_to_w32 ARG
3000629baa8cSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3001629baa8cSmrg# func_to_host_file_result.
3002629baa8cSmrgfunc_convert_file_cygwin_to_w32 ()
3003629baa8cSmrg{
3004b7d26471Smrg  $debug_cmd
3005b7d26471Smrg
3006b7d26471Smrg  func_to_host_file_result=$1
3007629baa8cSmrg  if test -n "$1"; then
3008629baa8cSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3009629baa8cSmrg    # LT_CYGPATH in this case.
3010629baa8cSmrg    func_to_host_file_result=`cygpath -m "$1"`
3011629baa8cSmrg  fi
3012629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3013629baa8cSmrg}
3014629baa8cSmrg# end func_convert_file_cygwin_to_w32
3015629baa8cSmrg
3016629baa8cSmrg
3017629baa8cSmrg# func_convert_file_nix_to_w32 ARG
3018629baa8cSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3019629baa8cSmrg# and a working winepath. Returns result in func_to_host_file_result.
3020629baa8cSmrgfunc_convert_file_nix_to_w32 ()
3021629baa8cSmrg{
3022b7d26471Smrg  $debug_cmd
3023b7d26471Smrg
3024b7d26471Smrg  func_to_host_file_result=$1
3025629baa8cSmrg  if test -n "$1"; then
3026629baa8cSmrg    func_convert_core_file_wine_to_w32 "$1"
3027b7d26471Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3028629baa8cSmrg  fi
3029629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3030629baa8cSmrg}
3031629baa8cSmrg# end func_convert_file_nix_to_w32
3032629baa8cSmrg
3033629baa8cSmrg
3034629baa8cSmrg# func_convert_file_msys_to_cygwin ARG
3035629baa8cSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3036629baa8cSmrg# Returns result in func_to_host_file_result.
3037629baa8cSmrgfunc_convert_file_msys_to_cygwin ()
3038629baa8cSmrg{
3039b7d26471Smrg  $debug_cmd
3040b7d26471Smrg
3041b7d26471Smrg  func_to_host_file_result=$1
3042629baa8cSmrg  if test -n "$1"; then
3043629baa8cSmrg    func_convert_core_msys_to_w32 "$1"
3044629baa8cSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3045b7d26471Smrg    func_to_host_file_result=$func_cygpath_result
3046629baa8cSmrg  fi
3047629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3048629baa8cSmrg}
3049629baa8cSmrg# end func_convert_file_msys_to_cygwin
3050629baa8cSmrg
3051629baa8cSmrg
3052629baa8cSmrg# func_convert_file_nix_to_cygwin ARG
3053629baa8cSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3054629baa8cSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3055629baa8cSmrg# in func_to_host_file_result.
3056629baa8cSmrgfunc_convert_file_nix_to_cygwin ()
3057629baa8cSmrg{
3058b7d26471Smrg  $debug_cmd
3059b7d26471Smrg
3060b7d26471Smrg  func_to_host_file_result=$1
3061629baa8cSmrg  if test -n "$1"; then
3062629baa8cSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3063629baa8cSmrg    func_convert_core_file_wine_to_w32 "$1"
3064629baa8cSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3065b7d26471Smrg    func_to_host_file_result=$func_cygpath_result
3066629baa8cSmrg  fi
3067629baa8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
3068629baa8cSmrg}
3069629baa8cSmrg# end func_convert_file_nix_to_cygwin
3070629baa8cSmrg
3071629baa8cSmrg
3072629baa8cSmrg#############################################
3073629baa8cSmrg# $build to $host PATH CONVERSION FUNCTIONS #
3074629baa8cSmrg#############################################
3075b7d26471Smrg# invoked via '$to_host_path_cmd ARG'
3076629baa8cSmrg#
3077629baa8cSmrg# In each case, ARG is the path to be converted from $build to $host format.
3078629baa8cSmrg# The result will be available in $func_to_host_path_result.
3079629baa8cSmrg#
3080629baa8cSmrg# Path separators are also converted from $build format to $host format.  If
3081629baa8cSmrg# ARG begins or ends with a path separator character, it is preserved (but
3082629baa8cSmrg# converted to $host format) on output.
3083629baa8cSmrg#
3084629baa8cSmrg# All path conversion functions are named using the following convention:
3085629baa8cSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
3086629baa8cSmrg#   path conversion function         : func_convert_path_X_to_Y ()
3087629baa8cSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3088629baa8cSmrg# same.  If conversion functions are added for new $build/$host combinations,
3089629baa8cSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3090629baa8cSmrg# will break.
3091629baa8cSmrg
3092629baa8cSmrg
3093629baa8cSmrg# func_init_to_host_path_cmd
3094629baa8cSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3095629baa8cSmrg# appropriate value, based on the value of $to_host_file_cmd.
3096629baa8cSmrgto_host_path_cmd=
3097629baa8cSmrgfunc_init_to_host_path_cmd ()
3098629baa8cSmrg{
3099b7d26471Smrg  $debug_cmd
3100b7d26471Smrg
3101629baa8cSmrg  if test -z "$to_host_path_cmd"; then
3102629baa8cSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3103b7d26471Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3104629baa8cSmrg  fi
3105629baa8cSmrg}
3106629baa8cSmrg
3107629baa8cSmrg
3108629baa8cSmrg# func_to_host_path ARG
3109629baa8cSmrg# Converts the path ARG from $build format to $host format. Return result
3110629baa8cSmrg# in func_to_host_path_result.
3111629baa8cSmrgfunc_to_host_path ()
3112629baa8cSmrg{
3113b7d26471Smrg  $debug_cmd
3114b7d26471Smrg
3115629baa8cSmrg  func_init_to_host_path_cmd
3116629baa8cSmrg  $to_host_path_cmd "$1"
3117629baa8cSmrg}
3118629baa8cSmrg# end func_to_host_path
3119629baa8cSmrg
3120629baa8cSmrg
3121629baa8cSmrg# func_convert_path_noop ARG
3122629baa8cSmrg# Copy ARG to func_to_host_path_result.
3123629baa8cSmrgfunc_convert_path_noop ()
3124629baa8cSmrg{
3125b7d26471Smrg  func_to_host_path_result=$1
3126629baa8cSmrg}
3127629baa8cSmrg# end func_convert_path_noop
3128629baa8cSmrg
3129629baa8cSmrg
3130629baa8cSmrg# func_convert_path_msys_to_w32 ARG
3131629baa8cSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3132629baa8cSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3133629baa8cSmrg# func_to_host_path_result.
3134629baa8cSmrgfunc_convert_path_msys_to_w32 ()
3135629baa8cSmrg{
3136b7d26471Smrg  $debug_cmd
3137b7d26471Smrg
3138b7d26471Smrg  func_to_host_path_result=$1
3139629baa8cSmrg  if test -n "$1"; then
3140629baa8cSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3141629baa8cSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3142629baa8cSmrg    # and winepath ignores them completely.
3143629baa8cSmrg    func_stripname : : "$1"
3144629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3145629baa8cSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3146b7d26471Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3147629baa8cSmrg    func_convert_path_check : ";" \
3148629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3149629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3150629baa8cSmrg  fi
3151629baa8cSmrg}
3152629baa8cSmrg# end func_convert_path_msys_to_w32
3153629baa8cSmrg
3154629baa8cSmrg
3155629baa8cSmrg# func_convert_path_cygwin_to_w32 ARG
3156629baa8cSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3157629baa8cSmrg# func_to_host_file_result.
3158629baa8cSmrgfunc_convert_path_cygwin_to_w32 ()
3159629baa8cSmrg{
3160b7d26471Smrg  $debug_cmd
3161b7d26471Smrg
3162b7d26471Smrg  func_to_host_path_result=$1
3163629baa8cSmrg  if test -n "$1"; then
3164629baa8cSmrg    # See func_convert_path_msys_to_w32:
3165629baa8cSmrg    func_stripname : : "$1"
3166629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3167629baa8cSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3168629baa8cSmrg    func_convert_path_check : ";" \
3169629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3170629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3171629baa8cSmrg  fi
3172629baa8cSmrg}
3173629baa8cSmrg# end func_convert_path_cygwin_to_w32
3174629baa8cSmrg
3175629baa8cSmrg
3176629baa8cSmrg# func_convert_path_nix_to_w32 ARG
3177629baa8cSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3178629baa8cSmrg# a working winepath.  Returns result in func_to_host_file_result.
3179629baa8cSmrgfunc_convert_path_nix_to_w32 ()
3180629baa8cSmrg{
3181b7d26471Smrg  $debug_cmd
3182b7d26471Smrg
3183b7d26471Smrg  func_to_host_path_result=$1
3184629baa8cSmrg  if test -n "$1"; then
3185629baa8cSmrg    # See func_convert_path_msys_to_w32:
3186629baa8cSmrg    func_stripname : : "$1"
3187629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3188629baa8cSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3189b7d26471Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3190629baa8cSmrg    func_convert_path_check : ";" \
3191629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3192629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3193629baa8cSmrg  fi
3194629baa8cSmrg}
3195629baa8cSmrg# end func_convert_path_nix_to_w32
3196629baa8cSmrg
3197629baa8cSmrg
3198629baa8cSmrg# func_convert_path_msys_to_cygwin ARG
3199629baa8cSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3200629baa8cSmrg# Returns result in func_to_host_file_result.
3201629baa8cSmrgfunc_convert_path_msys_to_cygwin ()
3202629baa8cSmrg{
3203b7d26471Smrg  $debug_cmd
3204b7d26471Smrg
3205b7d26471Smrg  func_to_host_path_result=$1
3206629baa8cSmrg  if test -n "$1"; then
3207629baa8cSmrg    # See func_convert_path_msys_to_w32:
3208629baa8cSmrg    func_stripname : : "$1"
3209629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3210629baa8cSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3211629baa8cSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3212b7d26471Smrg    func_to_host_path_result=$func_cygpath_result
3213629baa8cSmrg    func_convert_path_check : : \
3214629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3215629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3216629baa8cSmrg  fi
3217629baa8cSmrg}
3218629baa8cSmrg# end func_convert_path_msys_to_cygwin
3219629baa8cSmrg
3220629baa8cSmrg
3221629baa8cSmrg# func_convert_path_nix_to_cygwin ARG
3222629baa8cSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3223629baa8cSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3224629baa8cSmrg# func_to_host_file_result.
3225629baa8cSmrgfunc_convert_path_nix_to_cygwin ()
3226629baa8cSmrg{
3227b7d26471Smrg  $debug_cmd
3228b7d26471Smrg
3229b7d26471Smrg  func_to_host_path_result=$1
3230629baa8cSmrg  if test -n "$1"; then
3231629baa8cSmrg    # Remove leading and trailing path separator characters from
3232629baa8cSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3233629baa8cSmrg    # into '.;' and ';.', and winepath ignores them completely.
3234629baa8cSmrg    func_stripname : : "$1"
3235629baa8cSmrg    func_to_host_path_tmp1=$func_stripname_result
3236629baa8cSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3237629baa8cSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3238b7d26471Smrg    func_to_host_path_result=$func_cygpath_result
3239629baa8cSmrg    func_convert_path_check : : \
3240629baa8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3241629baa8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3242629baa8cSmrg  fi
3243629baa8cSmrg}
3244629baa8cSmrg# end func_convert_path_nix_to_cygwin
3245629baa8cSmrg
3246629baa8cSmrg
3247b7d26471Smrg# func_dll_def_p FILE
3248b7d26471Smrg# True iff FILE is a Windows DLL '.def' file.
3249b7d26471Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3250b7d26471Smrgfunc_dll_def_p ()
3251b7d26471Smrg{
3252b7d26471Smrg  $debug_cmd
3253b7d26471Smrg
3254b7d26471Smrg  func_dll_def_p_tmp=`$SED -n \
3255b7d26471Smrg    -e 's/^[	 ]*//' \
3256b7d26471Smrg    -e '/^\(;.*\)*$/d' \
3257b7d26471Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3258b7d26471Smrg    -e q \
3259b7d26471Smrg    "$1"`
3260b7d26471Smrg  test DEF = "$func_dll_def_p_tmp"
3261b7d26471Smrg}
3262b7d26471Smrg
3263b7d26471Smrg
32645ffd6003Smrg# func_mode_compile arg...
32655ffd6003Smrgfunc_mode_compile ()
32665ffd6003Smrg{
3267b7d26471Smrg    $debug_cmd
3268b7d26471Smrg
32695ffd6003Smrg    # Get the compilation command and the source file.
32705ffd6003Smrg    base_compile=
3271b7d26471Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
32725ffd6003Smrg    suppress_opt=yes
32735ffd6003Smrg    suppress_output=
32745ffd6003Smrg    arg_mode=normal
32755ffd6003Smrg    libobj=
32765ffd6003Smrg    later=
32775ffd6003Smrg    pie_flag=
32785ffd6003Smrg
32795ffd6003Smrg    for arg
32805ffd6003Smrg    do
32815ffd6003Smrg      case $arg_mode in
32825ffd6003Smrg      arg  )
32835ffd6003Smrg	# do not "continue".  Instead, add this to base_compile
3284b7d26471Smrg	lastarg=$arg
32855ffd6003Smrg	arg_mode=normal
32865ffd6003Smrg	;;
32875ffd6003Smrg
32885ffd6003Smrg      target )
3289b7d26471Smrg	libobj=$arg
32905ffd6003Smrg	arg_mode=normal
32915ffd6003Smrg	continue
32925ffd6003Smrg	;;
32935ffd6003Smrg
32945ffd6003Smrg      normal )
32955ffd6003Smrg	# Accept any command-line options.
32965ffd6003Smrg	case $arg in
32975ffd6003Smrg	-o)
32985ffd6003Smrg	  test -n "$libobj" && \
3299b7d26471Smrg	    func_fatal_error "you cannot specify '-o' more than once"
33005ffd6003Smrg	  arg_mode=target
33015ffd6003Smrg	  continue
33025ffd6003Smrg	  ;;
33035ffd6003Smrg
33045ffd6003Smrg	-pie | -fpie | -fPIE)
3305629baa8cSmrg          func_append pie_flag " $arg"
33065ffd6003Smrg	  continue
33075ffd6003Smrg	  ;;
33085ffd6003Smrg
33095ffd6003Smrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3310629baa8cSmrg	  func_append later " $arg"
33115ffd6003Smrg	  continue
33125ffd6003Smrg	  ;;
33135ffd6003Smrg
33145ffd6003Smrg	-no-suppress)
3315145b7b3cSmrg	  suppress_opt=no
3316145b7b3cSmrg	  continue
3317145b7b3cSmrg	  ;;
3318145b7b3cSmrg
3319145b7b3cSmrg	-Xcompiler)
3320145b7b3cSmrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3321145b7b3cSmrg	  continue      #  The current "srcfile" will either be retained or
3322145b7b3cSmrg	  ;;            #  replaced later.  I would guess that would be a bug.
3323145b7b3cSmrg
3324145b7b3cSmrg	-Wc,*)
33255ffd6003Smrg	  func_stripname '-Wc,' '' "$arg"
33265ffd6003Smrg	  args=$func_stripname_result
3327145b7b3cSmrg	  lastarg=
3328b7d26471Smrg	  save_ifs=$IFS; IFS=,
33295ffd6003Smrg	  for arg in $args; do
3330b7d26471Smrg	    IFS=$save_ifs
3331629baa8cSmrg	    func_append_quoted lastarg "$arg"
3332145b7b3cSmrg	  done
3333b7d26471Smrg	  IFS=$save_ifs
33345ffd6003Smrg	  func_stripname ' ' '' "$lastarg"
33355ffd6003Smrg	  lastarg=$func_stripname_result
3336145b7b3cSmrg
3337145b7b3cSmrg	  # Add the arguments to base_compile.
3338629baa8cSmrg	  func_append base_compile " $lastarg"
3339145b7b3cSmrg	  continue
3340145b7b3cSmrg	  ;;
3341145b7b3cSmrg
33425ffd6003Smrg	*)
3343145b7b3cSmrg	  # Accept the current argument as the source file.
3344145b7b3cSmrg	  # The previous "srcfile" becomes the current argument.
3345145b7b3cSmrg	  #
3346b7d26471Smrg	  lastarg=$srcfile
3347b7d26471Smrg	  srcfile=$arg
3348145b7b3cSmrg	  ;;
3349145b7b3cSmrg	esac  #  case $arg
3350145b7b3cSmrg	;;
3351145b7b3cSmrg      esac    #  case $arg_mode
3352145b7b3cSmrg
3353145b7b3cSmrg      # Aesthetically quote the previous argument.
3354629baa8cSmrg      func_append_quoted base_compile "$lastarg"
3355145b7b3cSmrg    done # for arg
3356145b7b3cSmrg
3357145b7b3cSmrg    case $arg_mode in
3358145b7b3cSmrg    arg)
33595ffd6003Smrg      func_fatal_error "you must specify an argument for -Xcompile"
3360145b7b3cSmrg      ;;
3361145b7b3cSmrg    target)
3362b7d26471Smrg      func_fatal_error "you must specify a target with '-o'"
3363145b7b3cSmrg      ;;
3364145b7b3cSmrg    *)
3365145b7b3cSmrg      # Get the name of the library object.
33665ffd6003Smrg      test -z "$libobj" && {
33675ffd6003Smrg	func_basename "$srcfile"
3368b7d26471Smrg	libobj=$func_basename_result
33695ffd6003Smrg      }
3370145b7b3cSmrg      ;;
3371145b7b3cSmrg    esac
3372145b7b3cSmrg
3373145b7b3cSmrg    # Recognize several different file suffixes.
3374145b7b3cSmrg    # If the user specifies -o file.o, it is replaced with file.lo
3375145b7b3cSmrg    case $libobj in
33765ffd6003Smrg    *.[cCFSifmso] | \
33775ffd6003Smrg    *.ada | *.adb | *.ads | *.asm | \
33785ffd6003Smrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3379b7d26471Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
33805ffd6003Smrg      func_xform "$libobj"
33815ffd6003Smrg      libobj=$func_xform_result
33825ffd6003Smrg      ;;
3383145b7b3cSmrg    esac
3384145b7b3cSmrg
3385145b7b3cSmrg    case $libobj in
33865ffd6003Smrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3387145b7b3cSmrg    *)
3388b7d26471Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3389145b7b3cSmrg      ;;
3390145b7b3cSmrg    esac
3391145b7b3cSmrg
3392145b7b3cSmrg    func_infer_tag $base_compile
3393145b7b3cSmrg
3394145b7b3cSmrg    for arg in $later; do
3395145b7b3cSmrg      case $arg in
33965ffd6003Smrg      -shared)
3397b7d26471Smrg	test yes = "$build_libtool_libs" \
3398b7d26471Smrg	  || func_fatal_configuration "cannot build a shared library"
33995ffd6003Smrg	build_old_libs=no
34005ffd6003Smrg	continue
34015ffd6003Smrg	;;
34025ffd6003Smrg
3403145b7b3cSmrg      -static)
34045ffd6003Smrg	build_libtool_libs=no
3405145b7b3cSmrg	build_old_libs=yes
3406145b7b3cSmrg	continue
3407145b7b3cSmrg	;;
3408145b7b3cSmrg
3409145b7b3cSmrg      -prefer-pic)
3410145b7b3cSmrg	pic_mode=yes
3411145b7b3cSmrg	continue
3412145b7b3cSmrg	;;
3413145b7b3cSmrg
3414145b7b3cSmrg      -prefer-non-pic)
3415145b7b3cSmrg	pic_mode=no
3416145b7b3cSmrg	continue
3417145b7b3cSmrg	;;
3418145b7b3cSmrg      esac
3419145b7b3cSmrg    done
3420145b7b3cSmrg
34215ffd6003Smrg    func_quote_for_eval "$libobj"
34225ffd6003Smrg    test "X$libobj" != "X$func_quote_for_eval_result" \
34235ffd6003Smrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3424b7d26471Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
34255ffd6003Smrg    func_dirname_and_basename "$obj" "/" ""
3426b7d26471Smrg    objname=$func_basename_result
3427b7d26471Smrg    xdir=$func_dirname_result
3428b7d26471Smrg    lobj=$xdir$objdir/$objname
3429145b7b3cSmrg
34305ffd6003Smrg    test -z "$base_compile" && \
34315ffd6003Smrg      func_fatal_help "you must specify a compilation command"
3432145b7b3cSmrg
3433145b7b3cSmrg    # Delete any leftover library objects.
3434b7d26471Smrg    if test yes = "$build_old_libs"; then
3435145b7b3cSmrg      removelist="$obj $lobj $libobj ${libobj}T"
3436145b7b3cSmrg    else
3437145b7b3cSmrg      removelist="$lobj $libobj ${libobj}T"
3438145b7b3cSmrg    fi
3439145b7b3cSmrg
3440145b7b3cSmrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3441145b7b3cSmrg    case $host_os in
34425ffd6003Smrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3443145b7b3cSmrg      pic_mode=default
3444145b7b3cSmrg      ;;
3445145b7b3cSmrg    esac
3446b7d26471Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3447145b7b3cSmrg      # non-PIC code in shared libraries is not supported
3448145b7b3cSmrg      pic_mode=default
3449145b7b3cSmrg    fi
3450145b7b3cSmrg
3451145b7b3cSmrg    # Calculate the filename of the output object if compiler does
3452145b7b3cSmrg    # not support -o with -c
3453b7d26471Smrg    if test no = "$compiler_c_o"; then
3454b7d26471Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3455b7d26471Smrg      lockfile=$output_obj.lock
3456145b7b3cSmrg    else
3457145b7b3cSmrg      output_obj=
3458145b7b3cSmrg      need_locks=no
3459145b7b3cSmrg      lockfile=
3460145b7b3cSmrg    fi
3461145b7b3cSmrg
3462145b7b3cSmrg    # Lock this critical section if it is needed
3463145b7b3cSmrg    # We use this script file to make the link, it avoids creating a new file
3464b7d26471Smrg    if test yes = "$need_locks"; then
34655ffd6003Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
34665ffd6003Smrg	func_echo "Waiting for $lockfile to be removed"
3467145b7b3cSmrg	sleep 2
3468145b7b3cSmrg      done
3469b7d26471Smrg    elif test warn = "$need_locks"; then
3470145b7b3cSmrg      if test -f "$lockfile"; then
34715ffd6003Smrg	$ECHO "\
3472145b7b3cSmrg*** ERROR, $lockfile exists and contains:
3473145b7b3cSmrg`cat $lockfile 2>/dev/null`
3474145b7b3cSmrg
3475145b7b3cSmrgThis indicates that another process is trying to use the same
3476145b7b3cSmrgtemporary object file, and libtool could not work around it because
3477b7d26471Smrgyour compiler does not support '-c' and '-o' together.  If you
3478145b7b3cSmrgrepeat this compilation, it may succeed, by chance, but you had better
3479145b7b3cSmrgavoid parallel builds (make -j) in this platform, or get a better
3480145b7b3cSmrgcompiler."
3481145b7b3cSmrg
34825ffd6003Smrg	$opt_dry_run || $RM $removelist
3483145b7b3cSmrg	exit $EXIT_FAILURE
3484145b7b3cSmrg      fi
3485629baa8cSmrg      func_append removelist " $output_obj"
34865ffd6003Smrg      $ECHO "$srcfile" > "$lockfile"
3487145b7b3cSmrg    fi
3488145b7b3cSmrg
34895ffd6003Smrg    $opt_dry_run || $RM $removelist
3490629baa8cSmrg    func_append removelist " $lockfile"
34915ffd6003Smrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
34925ffd6003Smrg
3493629baa8cSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3494629baa8cSmrg    srcfile=$func_to_tool_file_result
34955ffd6003Smrg    func_quote_for_eval "$srcfile"
34965ffd6003Smrg    qsrcfile=$func_quote_for_eval_result
3497145b7b3cSmrg
3498145b7b3cSmrg    # Only build a PIC object if we are building libtool libraries.
3499b7d26471Smrg    if test yes = "$build_libtool_libs"; then
3500145b7b3cSmrg      # Without this assignment, base_compile gets emptied.
3501145b7b3cSmrg      fbsd_hideous_sh_bug=$base_compile
3502145b7b3cSmrg
3503b7d26471Smrg      if test no != "$pic_mode"; then
3504145b7b3cSmrg	command="$base_compile $qsrcfile $pic_flag"
3505145b7b3cSmrg      else
3506145b7b3cSmrg	# Don't build PIC code
3507145b7b3cSmrg	command="$base_compile $qsrcfile"
3508145b7b3cSmrg      fi
3509145b7b3cSmrg
35105ffd6003Smrg      func_mkdir_p "$xdir$objdir"
3511145b7b3cSmrg
3512145b7b3cSmrg      if test -z "$output_obj"; then
3513145b7b3cSmrg	# Place PIC objects in $objdir
3514629baa8cSmrg	func_append command " -o $lobj"
3515145b7b3cSmrg      fi
3516145b7b3cSmrg
35175ffd6003Smrg      func_show_eval_locale "$command"	\
35185ffd6003Smrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3519145b7b3cSmrg
3520b7d26471Smrg      if test warn = "$need_locks" &&
3521145b7b3cSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
35225ffd6003Smrg	$ECHO "\
3523145b7b3cSmrg*** ERROR, $lockfile contains:
3524145b7b3cSmrg`cat $lockfile 2>/dev/null`
3525145b7b3cSmrg
3526145b7b3cSmrgbut it should contain:
3527145b7b3cSmrg$srcfile
3528145b7b3cSmrg
3529145b7b3cSmrgThis indicates that another process is trying to use the same
3530145b7b3cSmrgtemporary object file, and libtool could not work around it because
3531b7d26471Smrgyour compiler does not support '-c' and '-o' together.  If you
3532145b7b3cSmrgrepeat this compilation, it may succeed, by chance, but you had better
3533145b7b3cSmrgavoid parallel builds (make -j) in this platform, or get a better
3534145b7b3cSmrgcompiler."
3535145b7b3cSmrg
35365ffd6003Smrg	$opt_dry_run || $RM $removelist
3537145b7b3cSmrg	exit $EXIT_FAILURE
3538145b7b3cSmrg      fi
3539145b7b3cSmrg
3540145b7b3cSmrg      # Just move the object if needed, then go on to compile the next one
3541145b7b3cSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
35425ffd6003Smrg	func_show_eval '$MV "$output_obj" "$lobj"' \
35435ffd6003Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3544145b7b3cSmrg      fi
3545145b7b3cSmrg
3546145b7b3cSmrg      # Allow error messages only from the first compilation.
3547b7d26471Smrg      if test yes = "$suppress_opt"; then
35485ffd6003Smrg	suppress_output=' >/dev/null 2>&1'
3549145b7b3cSmrg      fi
3550145b7b3cSmrg    fi
3551145b7b3cSmrg
3552145b7b3cSmrg    # Only build a position-dependent object if we build old libraries.
3553b7d26471Smrg    if test yes = "$build_old_libs"; then
3554b7d26471Smrg      if test yes != "$pic_mode"; then
3555145b7b3cSmrg	# Don't build PIC code
35565ffd6003Smrg	command="$base_compile $qsrcfile$pie_flag"
3557145b7b3cSmrg      else
3558145b7b3cSmrg	command="$base_compile $qsrcfile $pic_flag"
3559145b7b3cSmrg      fi
3560b7d26471Smrg      if test yes = "$compiler_c_o"; then
3561629baa8cSmrg	func_append command " -o $obj"
3562145b7b3cSmrg      fi
3563145b7b3cSmrg
3564145b7b3cSmrg      # Suppress compiler output if we already did a PIC compilation.
3565629baa8cSmrg      func_append command "$suppress_output"
35665ffd6003Smrg      func_show_eval_locale "$command" \
35675ffd6003Smrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3568145b7b3cSmrg
3569b7d26471Smrg      if test warn = "$need_locks" &&
3570145b7b3cSmrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
35715ffd6003Smrg	$ECHO "\
3572145b7b3cSmrg*** ERROR, $lockfile contains:
3573145b7b3cSmrg`cat $lockfile 2>/dev/null`
3574145b7b3cSmrg
3575145b7b3cSmrgbut it should contain:
3576145b7b3cSmrg$srcfile
3577145b7b3cSmrg
3578145b7b3cSmrgThis indicates that another process is trying to use the same
3579145b7b3cSmrgtemporary object file, and libtool could not work around it because
3580b7d26471Smrgyour compiler does not support '-c' and '-o' together.  If you
3581145b7b3cSmrgrepeat this compilation, it may succeed, by chance, but you had better
3582145b7b3cSmrgavoid parallel builds (make -j) in this platform, or get a better
3583145b7b3cSmrgcompiler."
3584145b7b3cSmrg
35855ffd6003Smrg	$opt_dry_run || $RM $removelist
3586145b7b3cSmrg	exit $EXIT_FAILURE
3587145b7b3cSmrg      fi
3588145b7b3cSmrg
3589145b7b3cSmrg      # Just move the object if needed
3590145b7b3cSmrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
35915ffd6003Smrg	func_show_eval '$MV "$output_obj" "$obj"' \
35925ffd6003Smrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3593145b7b3cSmrg      fi
3594145b7b3cSmrg    fi
3595145b7b3cSmrg
35965ffd6003Smrg    $opt_dry_run || {
35975ffd6003Smrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3598145b7b3cSmrg
35995ffd6003Smrg      # Unlock the critical section if it was locked
3600b7d26471Smrg      if test no != "$need_locks"; then
36015ffd6003Smrg	removelist=$lockfile
36025ffd6003Smrg        $RM "$lockfile"
36035ffd6003Smrg      fi
36045ffd6003Smrg    }
3605145b7b3cSmrg
3606145b7b3cSmrg    exit $EXIT_SUCCESS
36075ffd6003Smrg}
3608145b7b3cSmrg
36095ffd6003Smrg$opt_help || {
3610b7d26471Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
36115ffd6003Smrg}
3612145b7b3cSmrg
36135ffd6003Smrgfunc_mode_help ()
36145ffd6003Smrg{
36155ffd6003Smrg    # We need to display help for each of the modes.
3616629baa8cSmrg    case $opt_mode in
36175ffd6003Smrg      "")
36185ffd6003Smrg        # Generic help is extracted from the usage comments
36195ffd6003Smrg        # at the start of this file.
36205ffd6003Smrg        func_help
36215ffd6003Smrg        ;;
3622145b7b3cSmrg
36235ffd6003Smrg      clean)
36245ffd6003Smrg        $ECHO \
36255ffd6003Smrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3626145b7b3cSmrg
36275ffd6003SmrgRemove files from the build directory.
3628145b7b3cSmrg
36295ffd6003SmrgRM is the name of the program to use to delete files associated with each FILE
3630b7d26471Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
36315ffd6003Smrgto RM.
3632145b7b3cSmrg
36335ffd6003SmrgIf FILE is a libtool library, object or program, all the files associated
36345ffd6003Smrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
36355ffd6003Smrg        ;;
3636145b7b3cSmrg
36375ffd6003Smrg      compile)
36385ffd6003Smrg      $ECHO \
36395ffd6003Smrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3640145b7b3cSmrg
36415ffd6003SmrgCompile a source file into a libtool library object.
3642145b7b3cSmrg
36435ffd6003SmrgThis mode accepts the following additional options:
3644145b7b3cSmrg
36455ffd6003Smrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
36465ffd6003Smrg  -no-suppress      do not suppress compiler output for multiple passes
3647629baa8cSmrg  -prefer-pic       try to build PIC objects only
3648629baa8cSmrg  -prefer-non-pic   try to build non-PIC objects only
3649b7d26471Smrg  -shared           do not build a '.o' file suitable for static linking
3650b7d26471Smrg  -static           only build a '.o' file suitable for static linking
3651629baa8cSmrg  -Wc,FLAG          pass FLAG directly to the compiler
3652145b7b3cSmrg
3653b7d26471SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
36545ffd6003Smrgfrom the given SOURCEFILE.
3655145b7b3cSmrg
36565ffd6003SmrgThe output file name is determined by removing the directory component from
3657b7d26471SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3658b7d26471Smrglibrary object suffix, '.lo'."
36595ffd6003Smrg        ;;
3660145b7b3cSmrg
36615ffd6003Smrg      execute)
36625ffd6003Smrg        $ECHO \
36635ffd6003Smrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3664145b7b3cSmrg
36655ffd6003SmrgAutomatically set library path, then run a program.
3666145b7b3cSmrg
36675ffd6003SmrgThis mode accepts the following additional options:
3668145b7b3cSmrg
36695ffd6003Smrg  -dlopen FILE      add the directory containing FILE to the library path
3670145b7b3cSmrg
3671b7d26471SmrgThis mode sets the library path environment variable according to '-dlopen'
36725ffd6003Smrgflags.
3673145b7b3cSmrg
36745ffd6003SmrgIf any of the ARGS are libtool executable wrappers, then they are translated
36755ffd6003Smrginto their corresponding uninstalled binary, and any of their required library
36765ffd6003Smrgdirectories are added to the library path.
3677145b7b3cSmrg
36785ffd6003SmrgThen, COMMAND is executed, with ARGS as arguments."
36795ffd6003Smrg        ;;
3680145b7b3cSmrg
36815ffd6003Smrg      finish)
36825ffd6003Smrg        $ECHO \
36835ffd6003Smrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3684145b7b3cSmrg
36855ffd6003SmrgComplete the installation of libtool libraries.
3686145b7b3cSmrg
36875ffd6003SmrgEach LIBDIR is a directory that contains libtool libraries.
3688145b7b3cSmrg
36895ffd6003SmrgThe commands that this mode executes may require superuser privileges.  Use
3690b7d26471Smrgthe '--dry-run' option if you just want to see what would be executed."
36915ffd6003Smrg        ;;
3692145b7b3cSmrg
36935ffd6003Smrg      install)
36945ffd6003Smrg        $ECHO \
36955ffd6003Smrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3696145b7b3cSmrg
36975ffd6003SmrgInstall executables or libraries.
3698145b7b3cSmrg
36995ffd6003SmrgINSTALL-COMMAND is the installation command.  The first component should be
3700b7d26471Smrgeither the 'install' or 'cp' program.
3701145b7b3cSmrg
37025ffd6003SmrgThe following components of INSTALL-COMMAND are treated specially:
3703145b7b3cSmrg
3704629baa8cSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3705145b7b3cSmrg
37065ffd6003SmrgThe rest of the components are interpreted as arguments to that command (only
37075ffd6003SmrgBSD-compatible install options are recognized)."
37085ffd6003Smrg        ;;
3709145b7b3cSmrg
37105ffd6003Smrg      link)
37115ffd6003Smrg        $ECHO \
37125ffd6003Smrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3713145b7b3cSmrg
37145ffd6003SmrgLink object files or libraries together to form another library, or to
37155ffd6003Smrgcreate an executable program.
3716145b7b3cSmrg
37175ffd6003SmrgLINK-COMMAND is a command using the C compiler that you would use to create
37185ffd6003Smrga program from several object files.
3719145b7b3cSmrg
37205ffd6003SmrgThe following components of LINK-COMMAND are treated specially:
3721145b7b3cSmrg
37225ffd6003Smrg  -all-static       do not do any dynamic linking at all
37235ffd6003Smrg  -avoid-version    do not add a version suffix if possible
3724629baa8cSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
3725629baa8cSmrg                    libraries must be found in the PATH setting at runtime)
3726b7d26471Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
37275ffd6003Smrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
37285ffd6003Smrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
37295ffd6003Smrg  -export-symbols SYMFILE
37305ffd6003Smrg                    try to export only the symbols listed in SYMFILE
37315ffd6003Smrg  -export-symbols-regex REGEX
37325ffd6003Smrg                    try to export only the symbols matching REGEX
37335ffd6003Smrg  -LLIBDIR          search LIBDIR for required installed libraries
37345ffd6003Smrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
37355ffd6003Smrg  -module           build a library that can dlopened
37365ffd6003Smrg  -no-fast-install  disable the fast-install mode
37375ffd6003Smrg  -no-install       link a not-installable executable
37385ffd6003Smrg  -no-undefined     declare that a library does not refer to external symbols
37395ffd6003Smrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3740b7d26471Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3741b7d26471Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
37425ffd6003Smrg  -precious-files-regex REGEX
37435ffd6003Smrg                    don't remove output files matching REGEX
37445ffd6003Smrg  -release RELEASE  specify package release information
37455ffd6003Smrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
37465ffd6003Smrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
37475ffd6003Smrg  -shared           only do dynamic linking of libtool libraries
37485ffd6003Smrg  -shrext SUFFIX    override the standard shared library file extension
37495ffd6003Smrg  -static           do not do any dynamic linking of uninstalled libtool libraries
37505ffd6003Smrg  -static-libtool-libs
37515ffd6003Smrg                    do not do any dynamic linking of libtool libraries
37525ffd6003Smrg  -version-info CURRENT[:REVISION[:AGE]]
37535ffd6003Smrg                    specify library version info [each variable defaults to 0]
37545ffd6003Smrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
3755629baa8cSmrg  -Wc,FLAG
3756629baa8cSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
3757629baa8cSmrg  -Wl,FLAG
3758629baa8cSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
3759629baa8cSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
3760145b7b3cSmrg
3761b7d26471SmrgAll other options (arguments beginning with '-') are ignored.
3762145b7b3cSmrg
3763b7d26471SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
37645ffd6003Smrgtreated as uninstalled libtool libraries, other files are standard or library
37655ffd6003Smrgobject files.
3766578741aaSmrg
3767b7d26471SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
3768b7d26471Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
37695ffd6003Smrgrequired, except when creating a convenience library.
3770145b7b3cSmrg
3771b7d26471SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
3772b7d26471Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
3773145b7b3cSmrg
3774b7d26471SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
37755ffd6003Smrgis created, otherwise an executable program is created."
3776145b7b3cSmrg        ;;
3777145b7b3cSmrg
37785ffd6003Smrg      uninstall)
37795ffd6003Smrg        $ECHO \
37805ffd6003Smrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
3781145b7b3cSmrg
37825ffd6003SmrgRemove libraries from an installation directory.
3783145b7b3cSmrg
37845ffd6003SmrgRM is the name of the program to use to delete files associated with each FILE
3785b7d26471Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
37865ffd6003Smrgto RM.
3787145b7b3cSmrg
37885ffd6003SmrgIf FILE is a libtool library, all the files associated with it are deleted.
37895ffd6003SmrgOtherwise, only FILE itself is deleted using RM."
37905ffd6003Smrg        ;;
3791145b7b3cSmrg
37925ffd6003Smrg      *)
3793b7d26471Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
37945ffd6003Smrg        ;;
37955ffd6003Smrg    esac
3796145b7b3cSmrg
3797629baa8cSmrg    echo
3798b7d26471Smrg    $ECHO "Try '$progname --help' for more information about other modes."
37995ffd6003Smrg}
3800145b7b3cSmrg
3801629baa8cSmrg# Now that we've collected a possible --mode arg, show help if necessary
3802629baa8cSmrgif $opt_help; then
3803b7d26471Smrg  if test : = "$opt_help"; then
3804629baa8cSmrg    func_mode_help
3805629baa8cSmrg  else
3806629baa8cSmrg    {
3807629baa8cSmrg      func_help noexit
3808629baa8cSmrg      for opt_mode in compile link execute install finish uninstall clean; do
3809629baa8cSmrg	func_mode_help
3810629baa8cSmrg      done
3811b7d26471Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
3812629baa8cSmrg    {
3813629baa8cSmrg      func_help noexit
3814629baa8cSmrg      for opt_mode in compile link execute install finish uninstall clean; do
3815629baa8cSmrg	echo
3816629baa8cSmrg	func_mode_help
3817629baa8cSmrg      done
3818629baa8cSmrg    } |
3819b7d26471Smrg    $SED '1d
3820629baa8cSmrg      /^When reporting/,/^Report/{
3821629baa8cSmrg	H
3822629baa8cSmrg	d
3823629baa8cSmrg      }
3824629baa8cSmrg      $x
3825629baa8cSmrg      /information about other modes/d
3826629baa8cSmrg      /more detailed .*MODE/d
3827629baa8cSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
3828629baa8cSmrg  fi
3829629baa8cSmrg  exit $?
3830629baa8cSmrgfi
3831145b7b3cSmrg
3832145b7b3cSmrg
38335ffd6003Smrg# func_mode_execute arg...
38345ffd6003Smrgfunc_mode_execute ()
38355ffd6003Smrg{
3836b7d26471Smrg    $debug_cmd
3837b7d26471Smrg
38385ffd6003Smrg    # The first argument is the command name.
3839b7d26471Smrg    cmd=$nonopt
38405ffd6003Smrg    test -z "$cmd" && \
38415ffd6003Smrg      func_fatal_help "you must specify a COMMAND"
3842145b7b3cSmrg
38435ffd6003Smrg    # Handle -dlopen flags immediately.
3844629baa8cSmrg    for file in $opt_dlopen; do
38455ffd6003Smrg      test -f "$file" \
3846b7d26471Smrg	|| func_fatal_help "'$file' is not a file"
3847145b7b3cSmrg
38485ffd6003Smrg      dir=
38495ffd6003Smrg      case $file in
38505ffd6003Smrg      *.la)
3851629baa8cSmrg	func_resolve_sysroot "$file"
3852629baa8cSmrg	file=$func_resolve_sysroot_result
3853629baa8cSmrg
38545ffd6003Smrg	# Check to see that this really is a libtool archive.
38555ffd6003Smrg	func_lalib_unsafe_p "$file" \
3856b7d26471Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
3857145b7b3cSmrg
38585ffd6003Smrg	# Read the libtool library.
38595ffd6003Smrg	dlname=
38605ffd6003Smrg	library_names=
38615ffd6003Smrg	func_source "$file"
3862145b7b3cSmrg
38635ffd6003Smrg	# Skip this library if it cannot be dlopened.
38645ffd6003Smrg	if test -z "$dlname"; then
38655ffd6003Smrg	  # Warn if it was a shared library.
38665ffd6003Smrg	  test -n "$library_names" && \
3867b7d26471Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
38685ffd6003Smrg	  continue
38695ffd6003Smrg	fi
3870145b7b3cSmrg
38715ffd6003Smrg	func_dirname "$file" "" "."
3872b7d26471Smrg	dir=$func_dirname_result
3873145b7b3cSmrg
38745ffd6003Smrg	if test -f "$dir/$objdir/$dlname"; then
3875629baa8cSmrg	  func_append dir "/$objdir"
38765ffd6003Smrg	else
38775ffd6003Smrg	  if test ! -f "$dir/$dlname"; then
3878b7d26471Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
38795ffd6003Smrg	  fi
38805ffd6003Smrg	fi
3881145b7b3cSmrg	;;
3882145b7b3cSmrg
38835ffd6003Smrg      *.lo)
38845ffd6003Smrg	# Just add the directory containing the .lo file.
38855ffd6003Smrg	func_dirname "$file" "" "."
3886b7d26471Smrg	dir=$func_dirname_result
3887145b7b3cSmrg	;;
3888145b7b3cSmrg
38895ffd6003Smrg      *)
3890b7d26471Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
3891145b7b3cSmrg	continue
3892145b7b3cSmrg	;;
38935ffd6003Smrg      esac
3894145b7b3cSmrg
38955ffd6003Smrg      # Get the absolute pathname.
38965ffd6003Smrg      absdir=`cd "$dir" && pwd`
3897b7d26471Smrg      test -n "$absdir" && dir=$absdir
3898145b7b3cSmrg
38995ffd6003Smrg      # Now add the directory to shlibpath_var.
39005ffd6003Smrg      if eval "test -z \"\$$shlibpath_var\""; then
39015ffd6003Smrg	eval "$shlibpath_var=\"\$dir\""
39025ffd6003Smrg      else
39035ffd6003Smrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
39045ffd6003Smrg      fi
39055ffd6003Smrg    done
3906145b7b3cSmrg
39075ffd6003Smrg    # This variable tells wrapper scripts just to set shlibpath_var
39085ffd6003Smrg    # rather than running their programs.
3909b7d26471Smrg    libtool_execute_magic=$magic
3910145b7b3cSmrg
39115ffd6003Smrg    # Check if any of the arguments is a wrapper script.
39125ffd6003Smrg    args=
39135ffd6003Smrg    for file
39145ffd6003Smrg    do
39155ffd6003Smrg      case $file in
3916629baa8cSmrg      -* | *.la | *.lo ) ;;
39175ffd6003Smrg      *)
39185ffd6003Smrg	# Do a test to see if this is really a libtool program.
39195ffd6003Smrg	if func_ltwrapper_script_p "$file"; then
39205ffd6003Smrg	  func_source "$file"
39215ffd6003Smrg	  # Transform arg to wrapped name.
3922b7d26471Smrg	  file=$progdir/$program
39235ffd6003Smrg	elif func_ltwrapper_executable_p "$file"; then
39245ffd6003Smrg	  func_ltwrapper_scriptname "$file"
39255ffd6003Smrg	  func_source "$func_ltwrapper_scriptname_result"
39265ffd6003Smrg	  # Transform arg to wrapped name.
3927b7d26471Smrg	  file=$progdir/$program
39285ffd6003Smrg	fi
39295ffd6003Smrg	;;
39305ffd6003Smrg      esac
39315ffd6003Smrg      # Quote arguments (to preserve shell metacharacters).
3932629baa8cSmrg      func_append_quoted args "$file"
39335ffd6003Smrg    done
3934145b7b3cSmrg
3935b7d26471Smrg    if $opt_dry_run; then
3936b7d26471Smrg      # Display what would be done.
3937b7d26471Smrg      if test -n "$shlibpath_var"; then
3938b7d26471Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
3939b7d26471Smrg	echo "export $shlibpath_var"
3940b7d26471Smrg      fi
3941b7d26471Smrg      $ECHO "$cmd$args"
3942b7d26471Smrg      exit $EXIT_SUCCESS
3943b7d26471Smrg    else
39445ffd6003Smrg      if test -n "$shlibpath_var"; then
39455ffd6003Smrg	# Export the shlibpath_var.
39465ffd6003Smrg	eval "export $shlibpath_var"
39475ffd6003Smrg      fi
3948145b7b3cSmrg
39495ffd6003Smrg      # Restore saved environment variables
39505ffd6003Smrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
39515ffd6003Smrg      do
39525ffd6003Smrg	eval "if test \"\${save_$lt_var+set}\" = set; then
39535ffd6003Smrg                $lt_var=\$save_$lt_var; export $lt_var
3954145b7b3cSmrg	      else
39555ffd6003Smrg		$lt_unset $lt_var
39565ffd6003Smrg	      fi"
39575ffd6003Smrg      done
3958145b7b3cSmrg
39595ffd6003Smrg      # Now prepare to actually exec the command.
3960b7d26471Smrg      exec_cmd=\$cmd$args
39615ffd6003Smrg    fi
39625ffd6003Smrg}
3963145b7b3cSmrg
3964b7d26471Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
3965145b7b3cSmrg
3966145b7b3cSmrg
39675ffd6003Smrg# func_mode_finish arg...
39685ffd6003Smrgfunc_mode_finish ()
39695ffd6003Smrg{
3970b7d26471Smrg    $debug_cmd
3971b7d26471Smrg
3972629baa8cSmrg    libs=
3973629baa8cSmrg    libdirs=
39745ffd6003Smrg    admincmds=
3975145b7b3cSmrg
3976629baa8cSmrg    for opt in "$nonopt" ${1+"$@"}
3977629baa8cSmrg    do
3978629baa8cSmrg      if test -d "$opt"; then
3979629baa8cSmrg	func_append libdirs " $opt"
3980629baa8cSmrg
3981629baa8cSmrg      elif test -f "$opt"; then
3982629baa8cSmrg	if func_lalib_unsafe_p "$opt"; then
3983629baa8cSmrg	  func_append libs " $opt"
3984629baa8cSmrg	else
3985b7d26471Smrg	  func_warning "'$opt' is not a valid libtool archive"
3986629baa8cSmrg	fi
3987629baa8cSmrg
3988629baa8cSmrg      else
3989b7d26471Smrg	func_fatal_error "invalid argument '$opt'"
3990629baa8cSmrg      fi
3991629baa8cSmrg    done
3992629baa8cSmrg
3993629baa8cSmrg    if test -n "$libs"; then
3994629baa8cSmrg      if test -n "$lt_sysroot"; then
3995629baa8cSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
3996629baa8cSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
3997629baa8cSmrg      else
3998629baa8cSmrg        sysroot_cmd=
3999629baa8cSmrg      fi
4000145b7b3cSmrg
4001629baa8cSmrg      # Remove sysroot references
4002629baa8cSmrg      if $opt_dry_run; then
4003629baa8cSmrg        for lib in $libs; do
4004b7d26471Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4005629baa8cSmrg        done
4006629baa8cSmrg      else
4007629baa8cSmrg        tmpdir=`func_mktempdir`
4008629baa8cSmrg        for lib in $libs; do
4009b7d26471Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4010629baa8cSmrg	    > $tmpdir/tmp-la
4011629baa8cSmrg	  mv -f $tmpdir/tmp-la $lib
4012629baa8cSmrg	done
4013629baa8cSmrg        ${RM}r "$tmpdir"
4014629baa8cSmrg      fi
4015629baa8cSmrg    fi
4016629baa8cSmrg
4017629baa8cSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
40185ffd6003Smrg      for libdir in $libdirs; do
40195ffd6003Smrg	if test -n "$finish_cmds"; then
40205ffd6003Smrg	  # Do each command in the finish commands.
40215ffd6003Smrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
40225ffd6003Smrg'"$cmd"'"'
4023145b7b3cSmrg	fi
40245ffd6003Smrg	if test -n "$finish_eval"; then
40255ffd6003Smrg	  # Do the single finish_eval.
40265ffd6003Smrg	  eval cmds=\"$finish_eval\"
4027629baa8cSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
40285ffd6003Smrg       $cmds"
40295ffd6003Smrg	fi
40305ffd6003Smrg      done
40315ffd6003Smrg    fi
4032145b7b3cSmrg
40335ffd6003Smrg    # Exit here if they wanted silent mode.
4034b7d26471Smrg    $opt_quiet && exit $EXIT_SUCCESS
4035145b7b3cSmrg
4036629baa8cSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4037629baa8cSmrg      echo "----------------------------------------------------------------------"
4038629baa8cSmrg      echo "Libraries have been installed in:"
4039629baa8cSmrg      for libdir in $libdirs; do
4040629baa8cSmrg	$ECHO "   $libdir"
4041629baa8cSmrg      done
4042629baa8cSmrg      echo
4043629baa8cSmrg      echo "If you ever happen to want to link against installed libraries"
4044629baa8cSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4045b7d26471Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4046629baa8cSmrg      echo "flag during linking and do at least one of the following:"
4047629baa8cSmrg      if test -n "$shlibpath_var"; then
4048b7d26471Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4049629baa8cSmrg	echo "     during execution"
4050629baa8cSmrg      fi
4051629baa8cSmrg      if test -n "$runpath_var"; then
4052b7d26471Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4053629baa8cSmrg	echo "     during linking"
4054629baa8cSmrg      fi
4055629baa8cSmrg      if test -n "$hardcode_libdir_flag_spec"; then
4056629baa8cSmrg	libdir=LIBDIR
4057629baa8cSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
40585ffd6003Smrg
4059b7d26471Smrg	$ECHO "   - use the '$flag' linker flag"
4060629baa8cSmrg      fi
4061629baa8cSmrg      if test -n "$admincmds"; then
4062629baa8cSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4063629baa8cSmrg      fi
4064629baa8cSmrg      if test -f /etc/ld.so.conf; then
4065b7d26471Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4066629baa8cSmrg      fi
4067629baa8cSmrg      echo
40685ffd6003Smrg
4069629baa8cSmrg      echo "See any operating system documentation about shared libraries for"
4070629baa8cSmrg      case $host in
4071629baa8cSmrg	solaris2.[6789]|solaris2.1[0-9])
4072629baa8cSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4073629baa8cSmrg	  echo "pages."
4074629baa8cSmrg	  ;;
4075629baa8cSmrg	*)
4076629baa8cSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4077629baa8cSmrg	  ;;
4078629baa8cSmrg      esac
4079629baa8cSmrg      echo "----------------------------------------------------------------------"
4080629baa8cSmrg    fi
40815ffd6003Smrg    exit $EXIT_SUCCESS
40825ffd6003Smrg}
40835ffd6003Smrg
4084b7d26471Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
40855ffd6003Smrg
40865ffd6003Smrg
40875ffd6003Smrg# func_mode_install arg...
40885ffd6003Smrgfunc_mode_install ()
40895ffd6003Smrg{
4090b7d26471Smrg    $debug_cmd
4091b7d26471Smrg
40925ffd6003Smrg    # There may be an optional sh(1) argument at the beginning of
40935ffd6003Smrg    # install_prog (especially on Windows NT).
4094b7d26471Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
40955ffd6003Smrg       # Allow the use of GNU shtool's install command.
4096b7d26471Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4097b7d26471Smrg    then
40985ffd6003Smrg      # Aesthetically quote it.
40995ffd6003Smrg      func_quote_for_eval "$nonopt"
41005ffd6003Smrg      install_prog="$func_quote_for_eval_result "
41015ffd6003Smrg      arg=$1
41025ffd6003Smrg      shift
41035ffd6003Smrg    else
41045ffd6003Smrg      install_prog=
41055ffd6003Smrg      arg=$nonopt
41065ffd6003Smrg    fi
41075ffd6003Smrg
41085ffd6003Smrg    # The real first argument should be the name of the installation program.
41095ffd6003Smrg    # Aesthetically quote it.
41105ffd6003Smrg    func_quote_for_eval "$arg"
4111629baa8cSmrg    func_append install_prog "$func_quote_for_eval_result"
4112629baa8cSmrg    install_shared_prog=$install_prog
4113629baa8cSmrg    case " $install_prog " in
4114629baa8cSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4115629baa8cSmrg      *) install_cp=false ;;
4116629baa8cSmrg    esac
41175ffd6003Smrg
41185ffd6003Smrg    # We need to accept at least all the BSD install flags.
41195ffd6003Smrg    dest=
41205ffd6003Smrg    files=
41215ffd6003Smrg    opts=
41225ffd6003Smrg    prev=
41235ffd6003Smrg    install_type=
4124b7d26471Smrg    isdir=false
41255ffd6003Smrg    stripme=
4126629baa8cSmrg    no_mode=:
41275ffd6003Smrg    for arg
41285ffd6003Smrg    do
4129629baa8cSmrg      arg2=
41305ffd6003Smrg      if test -n "$dest"; then
4131629baa8cSmrg	func_append files " $dest"
41325ffd6003Smrg	dest=$arg
41335ffd6003Smrg	continue
41345ffd6003Smrg      fi
41355ffd6003Smrg
41365ffd6003Smrg      case $arg in
4137b7d26471Smrg      -d) isdir=: ;;
41385ffd6003Smrg      -f)
4139629baa8cSmrg	if $install_cp; then :; else
4140629baa8cSmrg	  prev=$arg
4141629baa8cSmrg	fi
41425ffd6003Smrg	;;
41435ffd6003Smrg      -g | -m | -o)
41445ffd6003Smrg	prev=$arg
41455ffd6003Smrg	;;
41465ffd6003Smrg      -s)
41475ffd6003Smrg	stripme=" -s"
41485ffd6003Smrg	continue
41495ffd6003Smrg	;;
41505ffd6003Smrg      -*)
41515ffd6003Smrg	;;
41525ffd6003Smrg      *)
41535ffd6003Smrg	# If the previous option needed an argument, then skip it.
41545ffd6003Smrg	if test -n "$prev"; then
4155b7d26471Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4156629baa8cSmrg	    arg2=$install_override_mode
4157629baa8cSmrg	    no_mode=false
4158629baa8cSmrg	  fi
4159145b7b3cSmrg	  prev=
4160145b7b3cSmrg	else
41615ffd6003Smrg	  dest=$arg
41625ffd6003Smrg	  continue
4163145b7b3cSmrg	fi
4164145b7b3cSmrg	;;
41655ffd6003Smrg      esac
4166145b7b3cSmrg
41675ffd6003Smrg      # Aesthetically quote the argument.
41685ffd6003Smrg      func_quote_for_eval "$arg"
4169629baa8cSmrg      func_append install_prog " $func_quote_for_eval_result"
4170629baa8cSmrg      if test -n "$arg2"; then
4171629baa8cSmrg	func_quote_for_eval "$arg2"
4172629baa8cSmrg      fi
4173629baa8cSmrg      func_append install_shared_prog " $func_quote_for_eval_result"
41745ffd6003Smrg    done
4175145b7b3cSmrg
41765ffd6003Smrg    test -z "$install_prog" && \
41775ffd6003Smrg      func_fatal_help "you must specify an install program"
4178145b7b3cSmrg
41795ffd6003Smrg    test -n "$prev" && \
4180b7d26471Smrg      func_fatal_help "the '$prev' option requires an argument"
4181145b7b3cSmrg
4182629baa8cSmrg    if test -n "$install_override_mode" && $no_mode; then
4183629baa8cSmrg      if $install_cp; then :; else
4184629baa8cSmrg	func_quote_for_eval "$install_override_mode"
4185629baa8cSmrg	func_append install_shared_prog " -m $func_quote_for_eval_result"
4186629baa8cSmrg      fi
4187629baa8cSmrg    fi
4188629baa8cSmrg
41895ffd6003Smrg    if test -z "$files"; then
41905ffd6003Smrg      if test -z "$dest"; then
41915ffd6003Smrg	func_fatal_help "no file or destination specified"
41925ffd6003Smrg      else
41935ffd6003Smrg	func_fatal_help "you must specify a destination"
41945ffd6003Smrg      fi
4195145b7b3cSmrg    fi
4196145b7b3cSmrg
41975ffd6003Smrg    # Strip any trailing slash from the destination.
41985ffd6003Smrg    func_stripname '' '/' "$dest"
41995ffd6003Smrg    dest=$func_stripname_result
4200145b7b3cSmrg
42015ffd6003Smrg    # Check to see that the destination is a directory.
4202b7d26471Smrg    test -d "$dest" && isdir=:
4203b7d26471Smrg    if $isdir; then
4204b7d26471Smrg      destdir=$dest
42055ffd6003Smrg      destname=
4206145b7b3cSmrg    else
42075ffd6003Smrg      func_dirname_and_basename "$dest" "" "."
4208b7d26471Smrg      destdir=$func_dirname_result
4209b7d26471Smrg      destname=$func_basename_result
4210145b7b3cSmrg
42115ffd6003Smrg      # Not a directory, so check to see that there is only one file specified.
42125ffd6003Smrg      set dummy $files; shift
42135ffd6003Smrg      test "$#" -gt 1 && \
4214b7d26471Smrg	func_fatal_help "'$dest' is not a directory"
4215145b7b3cSmrg    fi
42165ffd6003Smrg    case $destdir in
42175ffd6003Smrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4218145b7b3cSmrg    *)
42195ffd6003Smrg      for file in $files; do
42205ffd6003Smrg	case $file in
42215ffd6003Smrg	*.lo) ;;
42225ffd6003Smrg	*)
4223b7d26471Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
42245ffd6003Smrg	  ;;
42255ffd6003Smrg	esac
42265ffd6003Smrg      done
4227145b7b3cSmrg      ;;
4228145b7b3cSmrg    esac
4229145b7b3cSmrg
42305ffd6003Smrg    # This variable tells wrapper scripts just to set variables rather
42315ffd6003Smrg    # than running their programs.
4232b7d26471Smrg    libtool_install_magic=$magic
4233145b7b3cSmrg
42345ffd6003Smrg    staticlibs=
42355ffd6003Smrg    future_libdirs=
42365ffd6003Smrg    current_libdirs=
42375ffd6003Smrg    for file in $files; do
4238145b7b3cSmrg
42395ffd6003Smrg      # Do each installation.
42405ffd6003Smrg      case $file in
42415ffd6003Smrg      *.$libext)
42425ffd6003Smrg	# Do the static libraries later.
4243629baa8cSmrg	func_append staticlibs " $file"
42445ffd6003Smrg	;;
42455ffd6003Smrg
42465ffd6003Smrg      *.la)
4247629baa8cSmrg	func_resolve_sysroot "$file"
4248629baa8cSmrg	file=$func_resolve_sysroot_result
4249629baa8cSmrg
42505ffd6003Smrg	# Check to see that this really is a libtool archive.
42515ffd6003Smrg	func_lalib_unsafe_p "$file" \
4252b7d26471Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
42535ffd6003Smrg
42545ffd6003Smrg	library_names=
42555ffd6003Smrg	old_library=
42565ffd6003Smrg	relink_command=
42575ffd6003Smrg	func_source "$file"
42585ffd6003Smrg
42595ffd6003Smrg	# Add the libdir to current_libdirs if it is the destination.
42605ffd6003Smrg	if test "X$destdir" = "X$libdir"; then
42615ffd6003Smrg	  case "$current_libdirs " in
42625ffd6003Smrg	  *" $libdir "*) ;;
4263629baa8cSmrg	  *) func_append current_libdirs " $libdir" ;;
4264145b7b3cSmrg	  esac
42655ffd6003Smrg	else
42665ffd6003Smrg	  # Note the libdir as a future libdir.
42675ffd6003Smrg	  case "$future_libdirs " in
42685ffd6003Smrg	  *" $libdir "*) ;;
4269629baa8cSmrg	  *) func_append future_libdirs " $libdir" ;;
42705ffd6003Smrg	  esac
42715ffd6003Smrg	fi
4272145b7b3cSmrg
42735ffd6003Smrg	func_dirname "$file" "/" ""
4274b7d26471Smrg	dir=$func_dirname_result
4275629baa8cSmrg	func_append dir "$objdir"
42765ffd6003Smrg
42775ffd6003Smrg	if test -n "$relink_command"; then
42785ffd6003Smrg	  # Determine the prefix the user has applied to our future dir.
4279629baa8cSmrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
42805ffd6003Smrg
42815ffd6003Smrg	  # Don't allow the user to place us outside of our expected
42825ffd6003Smrg	  # location b/c this prevents finding dependent libraries that
42835ffd6003Smrg	  # are installed to the same prefix.
42845ffd6003Smrg	  # At present, this check doesn't affect windows .dll's that
42855ffd6003Smrg	  # are installed into $libdir/../bin (currently, that works fine)
42865ffd6003Smrg	  # but it's something to keep an eye on.
42875ffd6003Smrg	  test "$inst_prefix_dir" = "$destdir" && \
4288b7d26471Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
42895ffd6003Smrg
42905ffd6003Smrg	  if test -n "$inst_prefix_dir"; then
42915ffd6003Smrg	    # Stick the inst_prefix_dir data into the link command.
4292629baa8cSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
42935ffd6003Smrg	  else
4294629baa8cSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
42955ffd6003Smrg	  fi
42965ffd6003Smrg
4297b7d26471Smrg	  func_warning "relinking '$file'"
42985ffd6003Smrg	  func_show_eval "$relink_command" \
4299b7d26471Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
43005ffd6003Smrg	fi
43015ffd6003Smrg
43025ffd6003Smrg	# See the names of the shared library.
43035ffd6003Smrg	set dummy $library_names; shift
43045ffd6003Smrg	if test -n "$1"; then
4305b7d26471Smrg	  realname=$1
43065ffd6003Smrg	  shift
43075ffd6003Smrg
4308b7d26471Smrg	  srcname=$realname
4309b7d26471Smrg	  test -n "$relink_command" && srcname=${realname}T
43105ffd6003Smrg
43115ffd6003Smrg	  # Install the shared library and build the symlinks.
4312629baa8cSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
43135ffd6003Smrg	      'exit $?'
4314b7d26471Smrg	  tstripme=$stripme
43155ffd6003Smrg	  case $host_os in
43165ffd6003Smrg	  cygwin* | mingw* | pw32* | cegcc*)
43175ffd6003Smrg	    case $realname in
43185ffd6003Smrg	    *.dll.a)
4319b7d26471Smrg	      tstripme=
4320b7d26471Smrg	      ;;
4321b7d26471Smrg	    esac
4322b7d26471Smrg	    ;;
4323b7d26471Smrg	  os2*)
4324b7d26471Smrg	    case $realname in
4325b7d26471Smrg	    *_dll.a)
4326b7d26471Smrg	      tstripme=
43275ffd6003Smrg	      ;;
43285ffd6003Smrg	    esac
4329145b7b3cSmrg	    ;;
4330145b7b3cSmrg	  esac
43315ffd6003Smrg	  if test -n "$tstripme" && test -n "$striplib"; then
43325ffd6003Smrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4333578741aaSmrg	  fi
43345ffd6003Smrg
43355ffd6003Smrg	  if test "$#" -gt 0; then
43365ffd6003Smrg	    # Delete the old symlinks, and create new ones.
4337b7d26471Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
43385ffd6003Smrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
43395ffd6003Smrg	    # so we also need to try rm && ln -s.
43405ffd6003Smrg	    for linkname
43415ffd6003Smrg	    do
43425ffd6003Smrg	      test "$linkname" != "$realname" \
43435ffd6003Smrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4344145b7b3cSmrg	    done
4345145b7b3cSmrg	  fi
4346145b7b3cSmrg
43475ffd6003Smrg	  # Do each command in the postinstall commands.
4348b7d26471Smrg	  lib=$destdir/$realname
43495ffd6003Smrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4350145b7b3cSmrg	fi
4351145b7b3cSmrg
43525ffd6003Smrg	# Install the pseudo-library for information purposes.
43535ffd6003Smrg	func_basename "$file"
4354b7d26471Smrg	name=$func_basename_result
4355b7d26471Smrg	instname=$dir/${name}i
43565ffd6003Smrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4357145b7b3cSmrg
43585ffd6003Smrg	# Maybe install the static library, too.
4359629baa8cSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
43605ffd6003Smrg	;;
4361145b7b3cSmrg
43625ffd6003Smrg      *.lo)
43635ffd6003Smrg	# Install (i.e. copy) a libtool object.
4364145b7b3cSmrg
43655ffd6003Smrg	# Figure out destination file name, if it wasn't already specified.
43665ffd6003Smrg	if test -n "$destname"; then
4367b7d26471Smrg	  destfile=$destdir/$destname
43685ffd6003Smrg	else
43695ffd6003Smrg	  func_basename "$file"
4370b7d26471Smrg	  destfile=$func_basename_result
4371b7d26471Smrg	  destfile=$destdir/$destfile
43725ffd6003Smrg	fi
43735ffd6003Smrg
43745ffd6003Smrg	# Deduce the name of the destination old-style object file.
43755ffd6003Smrg	case $destfile in
43765ffd6003Smrg	*.lo)
43775ffd6003Smrg	  func_lo2o "$destfile"
43785ffd6003Smrg	  staticdest=$func_lo2o_result
43795ffd6003Smrg	  ;;
43805ffd6003Smrg	*.$objext)
4381b7d26471Smrg	  staticdest=$destfile
43825ffd6003Smrg	  destfile=
43835ffd6003Smrg	  ;;
43845ffd6003Smrg	*)
4385b7d26471Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
43865ffd6003Smrg	  ;;
4387145b7b3cSmrg	esac
4388145b7b3cSmrg
43895ffd6003Smrg	# Install the libtool object if requested.
43905ffd6003Smrg	test -n "$destfile" && \
43915ffd6003Smrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
43925ffd6003Smrg
43935ffd6003Smrg	# Install the old object if enabled.
4394b7d26471Smrg	if test yes = "$build_old_libs"; then
43955ffd6003Smrg	  # Deduce the name of the old-style object file.
43965ffd6003Smrg	  func_lo2o "$file"
43975ffd6003Smrg	  staticobj=$func_lo2o_result
43985ffd6003Smrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4399145b7b3cSmrg	fi
44005ffd6003Smrg	exit $EXIT_SUCCESS
44015ffd6003Smrg	;;
4402145b7b3cSmrg
44035ffd6003Smrg      *)
44045ffd6003Smrg	# Figure out destination file name, if it wasn't already specified.
44055ffd6003Smrg	if test -n "$destname"; then
4406b7d26471Smrg	  destfile=$destdir/$destname
44075ffd6003Smrg	else
44085ffd6003Smrg	  func_basename "$file"
4409b7d26471Smrg	  destfile=$func_basename_result
4410b7d26471Smrg	  destfile=$destdir/$destfile
44115ffd6003Smrg	fi
4412145b7b3cSmrg
44135ffd6003Smrg	# If the file is missing, and there is a .exe on the end, strip it
44145ffd6003Smrg	# because it is most likely a libtool script we actually want to
44155ffd6003Smrg	# install
4416b7d26471Smrg	stripped_ext=
44175ffd6003Smrg	case $file in
44185ffd6003Smrg	  *.exe)
44195ffd6003Smrg	    if test ! -f "$file"; then
44205ffd6003Smrg	      func_stripname '' '.exe' "$file"
44215ffd6003Smrg	      file=$func_stripname_result
4422b7d26471Smrg	      stripped_ext=.exe
44235ffd6003Smrg	    fi
44245ffd6003Smrg	    ;;
44255ffd6003Smrg	esac
4426145b7b3cSmrg
44275ffd6003Smrg	# Do a test to see if this is really a libtool program.
44285ffd6003Smrg	case $host in
44295ffd6003Smrg	*cygwin* | *mingw*)
44305ffd6003Smrg	    if func_ltwrapper_executable_p "$file"; then
44315ffd6003Smrg	      func_ltwrapper_scriptname "$file"
44325ffd6003Smrg	      wrapper=$func_ltwrapper_scriptname_result
44335ffd6003Smrg	    else
44345ffd6003Smrg	      func_stripname '' '.exe' "$file"
44355ffd6003Smrg	      wrapper=$func_stripname_result
44365ffd6003Smrg	    fi
44375ffd6003Smrg	    ;;
44385ffd6003Smrg	*)
44395ffd6003Smrg	    wrapper=$file
44405ffd6003Smrg	    ;;
44415ffd6003Smrg	esac
44425ffd6003Smrg	if func_ltwrapper_script_p "$wrapper"; then
44435ffd6003Smrg	  notinst_deplibs=
44445ffd6003Smrg	  relink_command=
4445145b7b3cSmrg
44465ffd6003Smrg	  func_source "$wrapper"
44475ffd6003Smrg
44485ffd6003Smrg	  # Check the variables that should have been set.
44495ffd6003Smrg	  test -z "$generated_by_libtool_version" && \
4450b7d26471Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
44515ffd6003Smrg
4452b7d26471Smrg	  finalize=:
44535ffd6003Smrg	  for lib in $notinst_deplibs; do
44545ffd6003Smrg	    # Check to see that each library is installed.
44555ffd6003Smrg	    libdir=
44565ffd6003Smrg	    if test -f "$lib"; then
44575ffd6003Smrg	      func_source "$lib"
44585ffd6003Smrg	    fi
4459b7d26471Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
44605ffd6003Smrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4461b7d26471Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4462b7d26471Smrg	      finalize=false
44635ffd6003Smrg	    fi
44645ffd6003Smrg	  done
44655ffd6003Smrg
44665ffd6003Smrg	  relink_command=
44675ffd6003Smrg	  func_source "$wrapper"
44685ffd6003Smrg
44695ffd6003Smrg	  outputname=
4470b7d26471Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
44715ffd6003Smrg	    $opt_dry_run || {
4472b7d26471Smrg	      if $finalize; then
44735ffd6003Smrg	        tmpdir=`func_mktempdir`
44745ffd6003Smrg		func_basename "$file$stripped_ext"
4475b7d26471Smrg		file=$func_basename_result
4476b7d26471Smrg	        outputname=$tmpdir/$file
44775ffd6003Smrg	        # Replace the output file specification.
4478629baa8cSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
44795ffd6003Smrg
4480b7d26471Smrg	        $opt_quiet || {
44815ffd6003Smrg	          func_quote_for_expand "$relink_command"
44825ffd6003Smrg		  eval "func_echo $func_quote_for_expand_result"
44835ffd6003Smrg	        }
44845ffd6003Smrg	        if eval "$relink_command"; then :
44855ffd6003Smrg	          else
4486b7d26471Smrg		  func_error "error: relink '$file' with the above command before installing it"
44875ffd6003Smrg		  $opt_dry_run || ${RM}r "$tmpdir"
44885ffd6003Smrg		  continue
44895ffd6003Smrg	        fi
4490b7d26471Smrg	        file=$outputname
44915ffd6003Smrg	      else
4492b7d26471Smrg	        func_warning "cannot relink '$file'"
44935ffd6003Smrg	      fi
44945ffd6003Smrg	    }
4495145b7b3cSmrg	  else
44965ffd6003Smrg	    # Install the binary that we compiled earlier.
4497629baa8cSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4498145b7b3cSmrg	  fi
44995ffd6003Smrg	fi
4500145b7b3cSmrg
45015ffd6003Smrg	# remove .exe since cygwin /usr/bin/install will append another
45025ffd6003Smrg	# one anyway
45035ffd6003Smrg	case $install_prog,$host in
45045ffd6003Smrg	*/usr/bin/install*,*cygwin*)
45055ffd6003Smrg	  case $file:$destfile in
45065ffd6003Smrg	  *.exe:*.exe)
45075ffd6003Smrg	    # this is ok
45085ffd6003Smrg	    ;;
45095ffd6003Smrg	  *.exe:*)
45105ffd6003Smrg	    destfile=$destfile.exe
45115ffd6003Smrg	    ;;
45125ffd6003Smrg	  *:*.exe)
45135ffd6003Smrg	    func_stripname '' '.exe' "$destfile"
45145ffd6003Smrg	    destfile=$func_stripname_result
45155ffd6003Smrg	    ;;
45165ffd6003Smrg	  esac
4517145b7b3cSmrg	  ;;
4518145b7b3cSmrg	esac
45195ffd6003Smrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
45205ffd6003Smrg	$opt_dry_run || if test -n "$outputname"; then
45215ffd6003Smrg	  ${RM}r "$tmpdir"
45225ffd6003Smrg	fi
45235ffd6003Smrg	;;
45245ffd6003Smrg      esac
45255ffd6003Smrg    done
4526145b7b3cSmrg
45275ffd6003Smrg    for file in $staticlibs; do
45285ffd6003Smrg      func_basename "$file"
4529b7d26471Smrg      name=$func_basename_result
45305ffd6003Smrg
45315ffd6003Smrg      # Set up the ranlib parameters.
4532b7d26471Smrg      oldlib=$destdir/$name
4533b7d26471Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4534b7d26471Smrg      tool_oldlib=$func_to_tool_file_result
45355ffd6003Smrg
45365ffd6003Smrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
45375ffd6003Smrg
45385ffd6003Smrg      if test -n "$stripme" && test -n "$old_striplib"; then
4539b7d26471Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
45405ffd6003Smrg      fi
45415ffd6003Smrg
45425ffd6003Smrg      # Do each command in the postinstall commands.
45435ffd6003Smrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
45445ffd6003Smrg    done
45455ffd6003Smrg
45465ffd6003Smrg    test -n "$future_libdirs" && \
4547b7d26471Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
45485ffd6003Smrg
45495ffd6003Smrg    if test -n "$current_libdirs"; then
45505ffd6003Smrg      # Maybe just do a dry run.
45515ffd6003Smrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4552b7d26471Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
45535ffd6003Smrg    else
45545ffd6003Smrg      exit $EXIT_SUCCESS
45555ffd6003Smrg    fi
45565ffd6003Smrg}
45575ffd6003Smrg
4558b7d26471Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
45595ffd6003Smrg
45605ffd6003Smrg
45615ffd6003Smrg# func_generate_dlsyms outputname originator pic_p
45625ffd6003Smrg# Extract symbols from dlprefiles and create ${outputname}S.o with
45635ffd6003Smrg# a dlpreopen symbol table.
45645ffd6003Smrgfunc_generate_dlsyms ()
45655ffd6003Smrg{
4566b7d26471Smrg    $debug_cmd
4567b7d26471Smrg
4568b7d26471Smrg    my_outputname=$1
4569b7d26471Smrg    my_originator=$2
4570b7d26471Smrg    my_pic_p=${3-false}
4571b7d26471Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
45725ffd6003Smrg    my_dlsyms=
45735ffd6003Smrg
4574b7d26471Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
45755ffd6003Smrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4576b7d26471Smrg	my_dlsyms=${my_outputname}S.c
45775ffd6003Smrg      else
45785ffd6003Smrg	func_error "not configured to extract global symbols from dlpreopened files"
45795ffd6003Smrg      fi
45805ffd6003Smrg    fi
45815ffd6003Smrg
45825ffd6003Smrg    if test -n "$my_dlsyms"; then
45835ffd6003Smrg      case $my_dlsyms in
45845ffd6003Smrg      "") ;;
45855ffd6003Smrg      *.c)
45865ffd6003Smrg	# Discover the nlist of each of the dlfiles.
4587b7d26471Smrg	nlist=$output_objdir/$my_outputname.nm
45885ffd6003Smrg
45895ffd6003Smrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
45905ffd6003Smrg
45915ffd6003Smrg	# Parse the name list into a source file.
45925ffd6003Smrg	func_verbose "creating $output_objdir/$my_dlsyms"
45935ffd6003Smrg
45945ffd6003Smrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4595b7d26471Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4596b7d26471Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
45975ffd6003Smrg
45985ffd6003Smrg#ifdef __cplusplus
45995ffd6003Smrgextern \"C\" {
46005ffd6003Smrg#endif
46015ffd6003Smrg
4602b7d26471Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4603629baa8cSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4604629baa8cSmrg#endif
4605629baa8cSmrg
4606629baa8cSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4607b7d26471Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4608b7d26471Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4609629baa8cSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4610629baa8cSmrg# define LT_DLSYM_CONST
4611b7d26471Smrg#elif defined __osf__
4612629baa8cSmrg/* This system does not cope well with relocations in const data.  */
4613629baa8cSmrg# define LT_DLSYM_CONST
4614629baa8cSmrg#else
4615629baa8cSmrg# define LT_DLSYM_CONST const
4616629baa8cSmrg#endif
4617629baa8cSmrg
4618b7d26471Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4619b7d26471Smrg
46205ffd6003Smrg/* External symbol declarations for the compiler. */\
46215ffd6003Smrg"
46225ffd6003Smrg
4623b7d26471Smrg	if test yes = "$dlself"; then
4624b7d26471Smrg	  func_verbose "generating symbol list for '$output'"
46255ffd6003Smrg
46265ffd6003Smrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
46275ffd6003Smrg
46285ffd6003Smrg	  # Add our own program objects to the symbol list.
4629629baa8cSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
46305ffd6003Smrg	  for progfile in $progfiles; do
4631629baa8cSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4632b7d26471Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4633629baa8cSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
46345ffd6003Smrg	  done
46355ffd6003Smrg
46365ffd6003Smrg	  if test -n "$exclude_expsyms"; then
46375ffd6003Smrg	    $opt_dry_run || {
46385ffd6003Smrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
46395ffd6003Smrg	      eval '$MV "$nlist"T "$nlist"'
46405ffd6003Smrg	    }
4641145b7b3cSmrg	  fi
46425ffd6003Smrg
46435ffd6003Smrg	  if test -n "$export_symbols_regex"; then
46445ffd6003Smrg	    $opt_dry_run || {
46455ffd6003Smrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
46465ffd6003Smrg	      eval '$MV "$nlist"T "$nlist"'
46475ffd6003Smrg	    }
46485ffd6003Smrg	  fi
46495ffd6003Smrg
46505ffd6003Smrg	  # Prepare the list of exported symbols
46515ffd6003Smrg	  if test -z "$export_symbols"; then
4652b7d26471Smrg	    export_symbols=$output_objdir/$outputname.exp
46535ffd6003Smrg	    $opt_dry_run || {
46545ffd6003Smrg	      $RM $export_symbols
4655b7d26471Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
46565ffd6003Smrg	      case $host in
46575ffd6003Smrg	      *cygwin* | *mingw* | *cegcc* )
46585ffd6003Smrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
46595ffd6003Smrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
46605ffd6003Smrg	        ;;
46615ffd6003Smrg	      esac
46625ffd6003Smrg	    }
4663145b7b3cSmrg	  else
46645ffd6003Smrg	    $opt_dry_run || {
4665b7d26471Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
46665ffd6003Smrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
46675ffd6003Smrg	      eval '$MV "$nlist"T "$nlist"'
46685ffd6003Smrg	      case $host in
4669629baa8cSmrg	        *cygwin* | *mingw* | *cegcc* )
46705ffd6003Smrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
46715ffd6003Smrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
46725ffd6003Smrg	          ;;
46735ffd6003Smrg	      esac
46745ffd6003Smrg	    }
4675145b7b3cSmrg	  fi
46765ffd6003Smrg	fi
4677145b7b3cSmrg
46785ffd6003Smrg	for dlprefile in $dlprefiles; do
4679b7d26471Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
46805ffd6003Smrg	  func_basename "$dlprefile"
4681b7d26471Smrg	  name=$func_basename_result
4682629baa8cSmrg          case $host in
4683629baa8cSmrg	    *cygwin* | *mingw* | *cegcc* )
4684629baa8cSmrg	      # if an import library, we need to obtain dlname
4685629baa8cSmrg	      if func_win32_import_lib_p "$dlprefile"; then
4686629baa8cSmrg	        func_tr_sh "$dlprefile"
4687629baa8cSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4688b7d26471Smrg	        dlprefile_dlbasename=
4689629baa8cSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4690629baa8cSmrg	          # Use subshell, to avoid clobbering current variable values
4691629baa8cSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4692b7d26471Smrg	          if test -n "$dlprefile_dlname"; then
4693629baa8cSmrg	            func_basename "$dlprefile_dlname"
4694b7d26471Smrg	            dlprefile_dlbasename=$func_basename_result
4695629baa8cSmrg	          else
4696629baa8cSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4697629baa8cSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4698629baa8cSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4699629baa8cSmrg	          fi
4700629baa8cSmrg	        fi
4701629baa8cSmrg	        $opt_dry_run || {
4702b7d26471Smrg	          if test -n "$dlprefile_dlbasename"; then
4703629baa8cSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4704629baa8cSmrg	          else
4705629baa8cSmrg	            func_warning "Could not compute DLL name from $name"
4706629baa8cSmrg	            eval '$ECHO ": $name " >> "$nlist"'
4707629baa8cSmrg	          fi
4708629baa8cSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4709629baa8cSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4710629baa8cSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4711629baa8cSmrg	        }
4712629baa8cSmrg	      else # not an import lib
4713629baa8cSmrg	        $opt_dry_run || {
4714629baa8cSmrg	          eval '$ECHO ": $name " >> "$nlist"'
4715629baa8cSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4716629baa8cSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4717629baa8cSmrg	        }
4718629baa8cSmrg	      fi
4719629baa8cSmrg	    ;;
4720629baa8cSmrg	    *)
4721629baa8cSmrg	      $opt_dry_run || {
4722629baa8cSmrg	        eval '$ECHO ": $name " >> "$nlist"'
4723629baa8cSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4724629baa8cSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4725629baa8cSmrg	      }
4726629baa8cSmrg	    ;;
4727629baa8cSmrg          esac
47285ffd6003Smrg	done
47295ffd6003Smrg
47305ffd6003Smrg	$opt_dry_run || {
47315ffd6003Smrg	  # Make sure we have at least an empty file.
47325ffd6003Smrg	  test -f "$nlist" || : > "$nlist"
47335ffd6003Smrg
47345ffd6003Smrg	  if test -n "$exclude_expsyms"; then
47355ffd6003Smrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
47365ffd6003Smrg	    $MV "$nlist"T "$nlist"
4737145b7b3cSmrg	  fi
47385ffd6003Smrg
47395ffd6003Smrg	  # Try sorting and uniquifying the output.
47405ffd6003Smrg	  if $GREP -v "^: " < "$nlist" |
47415ffd6003Smrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
47425ffd6003Smrg		sort -k 3
47435ffd6003Smrg	      else
47445ffd6003Smrg		sort +2
47455ffd6003Smrg	      fi |
47465ffd6003Smrg	      uniq > "$nlist"S; then
47475ffd6003Smrg	    :
4748145b7b3cSmrg	  else
47495ffd6003Smrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
4750145b7b3cSmrg	  fi
4751145b7b3cSmrg
47525ffd6003Smrg	  if test -f "$nlist"S; then
47535ffd6003Smrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
4754145b7b3cSmrg	  else
4755629baa8cSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
4756145b7b3cSmrg	  fi
4757145b7b3cSmrg
4758b7d26471Smrg	  func_show_eval '$RM "${nlist}I"'
4759b7d26471Smrg	  if test -n "$global_symbol_to_import"; then
4760b7d26471Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
4761b7d26471Smrg	  fi
4762b7d26471Smrg
4763629baa8cSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
4764145b7b3cSmrg
47655ffd6003Smrg/* The mapping between symbol names and symbols.  */
47665ffd6003Smrgtypedef struct {
47675ffd6003Smrg  const char *name;
47685ffd6003Smrg  void *address;
47695ffd6003Smrg} lt_dlsymlist;
4770629baa8cSmrgextern LT_DLSYM_CONST lt_dlsymlist
4771b7d26471Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
4772b7d26471Smrg"
4773b7d26471Smrg
4774b7d26471Smrg	  if test -s "$nlist"I; then
4775b7d26471Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4776b7d26471Smrgstatic void lt_syminit(void)
4777b7d26471Smrg{
4778b7d26471Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
4779b7d26471Smrg  for (; symbol->name; ++symbol)
4780b7d26471Smrg    {"
4781b7d26471Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
4782b7d26471Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4783b7d26471Smrg    }
4784b7d26471Smrg}"
4785b7d26471Smrg	  fi
4786b7d26471Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
4787629baa8cSmrgLT_DLSYM_CONST lt_dlsymlist
47885ffd6003Smrglt_${my_prefix}_LTX_preloaded_symbols[] =
4789b7d26471Smrg{ {\"$my_originator\", (void *) 0},"
4790b7d26471Smrg
4791b7d26471Smrg	  if test -s "$nlist"I; then
4792b7d26471Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4793b7d26471Smrg  {\"@INIT@\", (void *) &lt_syminit},"
4794b7d26471Smrg	  fi
4795145b7b3cSmrg
47965ffd6003Smrg	  case $need_lib_prefix in
47975ffd6003Smrg	  no)
47985ffd6003Smrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
47995ffd6003Smrg	    ;;
48005ffd6003Smrg	  *)
48015ffd6003Smrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
48025ffd6003Smrg	    ;;
48035ffd6003Smrg	  esac
4804629baa8cSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
48055ffd6003Smrg  {0, (void *) 0}
48065ffd6003Smrg};
4807145b7b3cSmrg
48085ffd6003Smrg/* This works around a problem in FreeBSD linker */
48095ffd6003Smrg#ifdef FREEBSD_WORKAROUND
48105ffd6003Smrgstatic const void *lt_preloaded_setup() {
48115ffd6003Smrg  return lt_${my_prefix}_LTX_preloaded_symbols;
48125ffd6003Smrg}
48135ffd6003Smrg#endif
48145ffd6003Smrg
48155ffd6003Smrg#ifdef __cplusplus
48165ffd6003Smrg}
48175ffd6003Smrg#endif\
48185ffd6003Smrg"
48195ffd6003Smrg	} # !$opt_dry_run
48205ffd6003Smrg
48215ffd6003Smrg	pic_flag_for_symtable=
48225ffd6003Smrg	case "$compile_command " in
48235ffd6003Smrg	*" -static "*) ;;
48245ffd6003Smrg	*)
48255ffd6003Smrg	  case $host in
48265ffd6003Smrg	  # compiling the symbol table file with pic_flag works around
48275ffd6003Smrg	  # a FreeBSD bug that causes programs to crash when -lm is
48285ffd6003Smrg	  # linked before any other PIC object.  But we must not use
48295ffd6003Smrg	  # pic_flag when linking with -static.  The problem exists in
48305ffd6003Smrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
4831b7d26471Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
48325ffd6003Smrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
48335ffd6003Smrg	  *-*-hpux*)
48345ffd6003Smrg	    pic_flag_for_symtable=" $pic_flag"  ;;
48355ffd6003Smrg	  *)
4836b7d26471Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
48375ffd6003Smrg	    ;;
48385ffd6003Smrg	  esac
48395ffd6003Smrg	  ;;
48405ffd6003Smrg	esac
48415ffd6003Smrg	symtab_cflags=
48425ffd6003Smrg	for arg in $LTCFLAGS; do
48435ffd6003Smrg	  case $arg in
48445ffd6003Smrg	  -pie | -fpie | -fPIE) ;;
4845629baa8cSmrg	  *) func_append symtab_cflags " $arg" ;;
48465ffd6003Smrg	  esac
48475ffd6003Smrg	done
4848145b7b3cSmrg
48495ffd6003Smrg	# Now compile the dynamic symbol file.
48505ffd6003Smrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
4851145b7b3cSmrg
48525ffd6003Smrg	# Clean up the generated files.
4853b7d26471Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
4854145b7b3cSmrg
48555ffd6003Smrg	# Transform the symbol file into the correct name.
4856b7d26471Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
48575ffd6003Smrg	case $host in
48585ffd6003Smrg	*cygwin* | *mingw* | *cegcc* )
48595ffd6003Smrg	  if test -f "$output_objdir/$my_outputname.def"; then
4860629baa8cSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
4861629baa8cSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
48625ffd6003Smrg	  else
4863629baa8cSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4864629baa8cSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4865145b7b3cSmrg	  fi
48665ffd6003Smrg	  ;;
48675ffd6003Smrg	*)
4868629baa8cSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4869629baa8cSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
48705ffd6003Smrg	  ;;
48715ffd6003Smrg	esac
48725ffd6003Smrg	;;
48735ffd6003Smrg      *)
4874b7d26471Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
48755ffd6003Smrg	;;
48765ffd6003Smrg      esac
48775ffd6003Smrg    else
48785ffd6003Smrg      # We keep going just in case the user didn't refer to
48795ffd6003Smrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
48805ffd6003Smrg      # really was required.
4881145b7b3cSmrg
48825ffd6003Smrg      # Nullify the symbol file.
4883629baa8cSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
4884629baa8cSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
48855ffd6003Smrg    fi
48865ffd6003Smrg}
4887145b7b3cSmrg
4888b7d26471Smrg# func_cygming_gnu_implib_p ARG
4889b7d26471Smrg# This predicate returns with zero status (TRUE) if
4890b7d26471Smrg# ARG is a GNU/binutils-style import library. Returns
4891b7d26471Smrg# with nonzero status (FALSE) otherwise.
4892b7d26471Smrgfunc_cygming_gnu_implib_p ()
4893b7d26471Smrg{
4894b7d26471Smrg  $debug_cmd
4895b7d26471Smrg
4896b7d26471Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4897b7d26471Smrg  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)$'`
4898b7d26471Smrg  test -n "$func_cygming_gnu_implib_tmp"
4899b7d26471Smrg}
4900b7d26471Smrg
4901b7d26471Smrg# func_cygming_ms_implib_p ARG
4902b7d26471Smrg# This predicate returns with zero status (TRUE) if
4903b7d26471Smrg# ARG is an MS-style import library. Returns
4904b7d26471Smrg# with nonzero status (FALSE) otherwise.
4905b7d26471Smrgfunc_cygming_ms_implib_p ()
4906b7d26471Smrg{
4907b7d26471Smrg  $debug_cmd
4908b7d26471Smrg
4909b7d26471Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4910b7d26471Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
4911b7d26471Smrg  test -n "$func_cygming_ms_implib_tmp"
4912b7d26471Smrg}
4913b7d26471Smrg
49145ffd6003Smrg# func_win32_libid arg
49155ffd6003Smrg# return the library type of file 'arg'
49165ffd6003Smrg#
49175ffd6003Smrg# Need a lot of goo to handle *both* DLLs and import libs
49185ffd6003Smrg# Has to be a shell function in order to 'eat' the argument
49195ffd6003Smrg# that is supplied when $file_magic_command is called.
4920629baa8cSmrg# Despite the name, also deal with 64 bit binaries.
49215ffd6003Smrgfunc_win32_libid ()
49225ffd6003Smrg{
4923b7d26471Smrg  $debug_cmd
4924b7d26471Smrg
4925b7d26471Smrg  win32_libid_type=unknown
49265ffd6003Smrg  win32_fileres=`file -L $1 2>/dev/null`
49275ffd6003Smrg  case $win32_fileres in
49285ffd6003Smrg  *ar\ archive\ import\ library*) # definitely import
49295ffd6003Smrg    win32_libid_type="x86 archive import"
49305ffd6003Smrg    ;;
49315ffd6003Smrg  *ar\ archive*) # could be an import, or static
4932629baa8cSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
49335ffd6003Smrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
4934629baa8cSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
4935b7d26471Smrg      case $nm_interface in
4936b7d26471Smrg      "MS dumpbin")
4937b7d26471Smrg	if func_cygming_ms_implib_p "$1" ||
4938b7d26471Smrg	   func_cygming_gnu_implib_p "$1"
4939b7d26471Smrg	then
4940b7d26471Smrg	  win32_nmres=import
4941b7d26471Smrg	else
4942b7d26471Smrg	  win32_nmres=
4943b7d26471Smrg	fi
4944b7d26471Smrg	;;
4945b7d26471Smrg      *)
4946b7d26471Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
4947b7d26471Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
4948b7d26471Smrg	  $SED -n -e '
49495ffd6003Smrg	    1,100{
49505ffd6003Smrg		/ I /{
4951b7d26471Smrg		    s|.*|import|
49525ffd6003Smrg		    p
49535ffd6003Smrg		    q
49545ffd6003Smrg		}
49555ffd6003Smrg	    }'`
4956b7d26471Smrg	;;
4957b7d26471Smrg      esac
49585ffd6003Smrg      case $win32_nmres in
49595ffd6003Smrg      import*)  win32_libid_type="x86 archive import";;
49605ffd6003Smrg      *)        win32_libid_type="x86 archive static";;
49615ffd6003Smrg      esac
49625ffd6003Smrg    fi
49635ffd6003Smrg    ;;
49645ffd6003Smrg  *DLL*)
49655ffd6003Smrg    win32_libid_type="x86 DLL"
49665ffd6003Smrg    ;;
49675ffd6003Smrg  *executable*) # but shell scripts are "executable" too...
49685ffd6003Smrg    case $win32_fileres in
49695ffd6003Smrg    *MS\ Windows\ PE\ Intel*)
49705ffd6003Smrg      win32_libid_type="x86 DLL"
49715ffd6003Smrg      ;;
49725ffd6003Smrg    esac
49735ffd6003Smrg    ;;
49745ffd6003Smrg  esac
49755ffd6003Smrg  $ECHO "$win32_libid_type"
49765ffd6003Smrg}
4977145b7b3cSmrg
4978629baa8cSmrg# func_cygming_dll_for_implib ARG
4979629baa8cSmrg#
4980629baa8cSmrg# Platform-specific function to extract the
4981629baa8cSmrg# name of the DLL associated with the specified
4982629baa8cSmrg# import library ARG.
4983629baa8cSmrg# Invoked by eval'ing the libtool variable
4984629baa8cSmrg#    $sharedlib_from_linklib_cmd
4985629baa8cSmrg# Result is available in the variable
4986629baa8cSmrg#    $sharedlib_from_linklib_result
4987629baa8cSmrgfunc_cygming_dll_for_implib ()
4988629baa8cSmrg{
4989b7d26471Smrg  $debug_cmd
4990b7d26471Smrg
4991629baa8cSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
4992629baa8cSmrg}
4993629baa8cSmrg
4994629baa8cSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
4995629baa8cSmrg#
4996629baa8cSmrg# The is the core of a fallback implementation of a
4997629baa8cSmrg# platform-specific function to extract the name of the
4998629baa8cSmrg# DLL associated with the specified import library LIBNAME.
4999629baa8cSmrg#
5000629baa8cSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5001629baa8cSmrg# on the platform and compiler that created the implib.
5002629baa8cSmrg#
5003629baa8cSmrg# Echos the name of the DLL associated with the
5004629baa8cSmrg# specified import library.
5005629baa8cSmrgfunc_cygming_dll_for_implib_fallback_core ()
5006629baa8cSmrg{
5007b7d26471Smrg  $debug_cmd
5008b7d26471Smrg
5009629baa8cSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5010629baa8cSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5011629baa8cSmrg    $SED '/^Contents of section '"$match_literal"':/{
5012629baa8cSmrg      # Place marker at beginning of archive member dllname section
5013629baa8cSmrg      s/.*/====MARK====/
5014629baa8cSmrg      p
5015629baa8cSmrg      d
5016629baa8cSmrg    }
5017629baa8cSmrg    # These lines can sometimes be longer than 43 characters, but
5018629baa8cSmrg    # are always uninteresting
5019629baa8cSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
5020629baa8cSmrg    /^In archive [^:]*:/d
5021629baa8cSmrg    # Ensure marker is printed
5022629baa8cSmrg    /^====MARK====/p
5023629baa8cSmrg    # Remove all lines with less than 43 characters
5024629baa8cSmrg    /^.\{43\}/!d
5025629baa8cSmrg    # From remaining lines, remove first 43 characters
5026629baa8cSmrg    s/^.\{43\}//' |
5027629baa8cSmrg    $SED -n '
5028629baa8cSmrg      # Join marker and all lines until next marker into a single line
5029629baa8cSmrg      /^====MARK====/ b para
5030629baa8cSmrg      H
5031629baa8cSmrg      $ b para
5032629baa8cSmrg      b
5033629baa8cSmrg      :para
5034629baa8cSmrg      x
5035629baa8cSmrg      s/\n//g
5036629baa8cSmrg      # Remove the marker
5037629baa8cSmrg      s/^====MARK====//
5038629baa8cSmrg      # Remove trailing dots and whitespace
5039629baa8cSmrg      s/[\. \t]*$//
5040629baa8cSmrg      # Print
5041629baa8cSmrg      /./p' |
5042629baa8cSmrg    # we now have a list, one entry per line, of the stringified
5043629baa8cSmrg    # contents of the appropriate section of all members of the
5044b7d26471Smrg    # archive that possess that section. Heuristic: eliminate
5045b7d26471Smrg    # all those that have a first or second character that is
5046629baa8cSmrg    # a '.' (that is, objdump's representation of an unprintable
5047629baa8cSmrg    # character.) This should work for all archives with less than
5048629baa8cSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
5049629baa8cSmrg    # begins with a literal '.' or a single character followed by
5050629baa8cSmrg    # a '.'.
5051629baa8cSmrg    #
5052629baa8cSmrg    # Of those that remain, print the first one.
5053629baa8cSmrg    $SED -e '/^\./d;/^.\./d;q'
5054629baa8cSmrg}
5055629baa8cSmrg
5056629baa8cSmrg# func_cygming_dll_for_implib_fallback ARG
5057629baa8cSmrg# Platform-specific function to extract the
5058629baa8cSmrg# name of the DLL associated with the specified
5059629baa8cSmrg# import library ARG.
5060629baa8cSmrg#
5061629baa8cSmrg# This fallback implementation is for use when $DLLTOOL
5062629baa8cSmrg# does not support the --identify-strict option.
5063629baa8cSmrg# Invoked by eval'ing the libtool variable
5064629baa8cSmrg#    $sharedlib_from_linklib_cmd
5065629baa8cSmrg# Result is available in the variable
5066629baa8cSmrg#    $sharedlib_from_linklib_result
5067629baa8cSmrgfunc_cygming_dll_for_implib_fallback ()
5068629baa8cSmrg{
5069b7d26471Smrg  $debug_cmd
5070b7d26471Smrg
5071b7d26471Smrg  if func_cygming_gnu_implib_p "$1"; then
5072629baa8cSmrg    # binutils import library
5073629baa8cSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5074b7d26471Smrg  elif func_cygming_ms_implib_p "$1"; then
5075629baa8cSmrg    # ms-generated import library
5076629baa8cSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5077629baa8cSmrg  else
5078629baa8cSmrg    # unknown
5079b7d26471Smrg    sharedlib_from_linklib_result=
5080629baa8cSmrg  fi
5081629baa8cSmrg}
5082145b7b3cSmrg
5083145b7b3cSmrg
50845ffd6003Smrg# func_extract_an_archive dir oldlib
50855ffd6003Smrgfunc_extract_an_archive ()
50865ffd6003Smrg{
5087b7d26471Smrg    $debug_cmd
5088b7d26471Smrg
5089b7d26471Smrg    f_ex_an_ar_dir=$1; shift
5090b7d26471Smrg    f_ex_an_ar_oldlib=$1
5091b7d26471Smrg    if test yes = "$lock_old_archive_extraction"; then
5092629baa8cSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5093629baa8cSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5094629baa8cSmrg	func_echo "Waiting for $lockfile to be removed"
5095629baa8cSmrg	sleep 2
5096629baa8cSmrg      done
5097629baa8cSmrg    fi
5098629baa8cSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5099629baa8cSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5100b7d26471Smrg    if test yes = "$lock_old_archive_extraction"; then
5101629baa8cSmrg      $opt_dry_run || rm -f "$lockfile"
5102629baa8cSmrg    fi
51035ffd6003Smrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
51045ffd6003Smrg     :
51055ffd6003Smrg    else
51065ffd6003Smrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
51075ffd6003Smrg    fi
51085ffd6003Smrg}
5109145b7b3cSmrg
5110145b7b3cSmrg
51115ffd6003Smrg# func_extract_archives gentop oldlib ...
51125ffd6003Smrgfunc_extract_archives ()
51135ffd6003Smrg{
5114b7d26471Smrg    $debug_cmd
5115b7d26471Smrg
5116b7d26471Smrg    my_gentop=$1; shift
51175ffd6003Smrg    my_oldlibs=${1+"$@"}
5118b7d26471Smrg    my_oldobjs=
5119b7d26471Smrg    my_xlib=
5120b7d26471Smrg    my_xabs=
5121b7d26471Smrg    my_xdir=
5122145b7b3cSmrg
51235ffd6003Smrg    for my_xlib in $my_oldlibs; do
51245ffd6003Smrg      # Extract the objects.
51255ffd6003Smrg      case $my_xlib in
5126b7d26471Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
51275ffd6003Smrg	*) my_xabs=`pwd`"/$my_xlib" ;;
51285ffd6003Smrg      esac
51295ffd6003Smrg      func_basename "$my_xlib"
5130b7d26471Smrg      my_xlib=$func_basename_result
51315ffd6003Smrg      my_xlib_u=$my_xlib
51325ffd6003Smrg      while :; do
51335ffd6003Smrg        case " $extracted_archives " in
51345ffd6003Smrg	*" $my_xlib_u "*)
51355ffd6003Smrg	  func_arith $extracted_serial + 1
51365ffd6003Smrg	  extracted_serial=$func_arith_result
51375ffd6003Smrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
51385ffd6003Smrg	*) break ;;
51395ffd6003Smrg	esac
51405ffd6003Smrg      done
51415ffd6003Smrg      extracted_archives="$extracted_archives $my_xlib_u"
5142b7d26471Smrg      my_xdir=$my_gentop/$my_xlib_u
5143145b7b3cSmrg
51445ffd6003Smrg      func_mkdir_p "$my_xdir"
5145145b7b3cSmrg
51465ffd6003Smrg      case $host in
51475ffd6003Smrg      *-darwin*)
51485ffd6003Smrg	func_verbose "Extracting $my_xabs"
51495ffd6003Smrg	# Do not bother doing anything if just a dry run
51505ffd6003Smrg	$opt_dry_run || {
51515ffd6003Smrg	  darwin_orig_dir=`pwd`
51525ffd6003Smrg	  cd $my_xdir || exit $?
51535ffd6003Smrg	  darwin_archive=$my_xabs
51545ffd6003Smrg	  darwin_curdir=`pwd`
5155b7d26471Smrg	  func_basename "$darwin_archive"
5156b7d26471Smrg	  darwin_base_archive=$func_basename_result
51575ffd6003Smrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
51585ffd6003Smrg	  if test -n "$darwin_arches"; then
51595ffd6003Smrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
51605ffd6003Smrg	    darwin_arch=
51615ffd6003Smrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5162b7d26471Smrg	    for darwin_arch in  $darwin_arches; do
5163b7d26471Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5164b7d26471Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5165b7d26471Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5166b7d26471Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
51675ffd6003Smrg	      cd "$darwin_curdir"
5168b7d26471Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
51695ffd6003Smrg	    done # $darwin_arches
51705ffd6003Smrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5171b7d26471Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
51725ffd6003Smrg	    darwin_file=
51735ffd6003Smrg	    darwin_files=
51745ffd6003Smrg	    for darwin_file in $darwin_filelist; do
5175629baa8cSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
51765ffd6003Smrg	      $LIPO -create -output "$darwin_file" $darwin_files
51775ffd6003Smrg	    done # $darwin_filelist
51785ffd6003Smrg	    $RM -rf unfat-$$
51795ffd6003Smrg	    cd "$darwin_orig_dir"
5180145b7b3cSmrg	  else
51815ffd6003Smrg	    cd $darwin_orig_dir
51825ffd6003Smrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
51835ffd6003Smrg	  fi # $darwin_arches
51845ffd6003Smrg	} # !$opt_dry_run
51855ffd6003Smrg	;;
51865ffd6003Smrg      *)
51875ffd6003Smrg        func_extract_an_archive "$my_xdir" "$my_xabs"
51885ffd6003Smrg	;;
51895ffd6003Smrg      esac
5190629baa8cSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
51915ffd6003Smrg    done
5192145b7b3cSmrg
5193b7d26471Smrg    func_extract_archives_result=$my_oldobjs
51945ffd6003Smrg}
5195145b7b3cSmrg
5196145b7b3cSmrg
5197629baa8cSmrg# func_emit_wrapper [arg=no]
5198629baa8cSmrg#
5199629baa8cSmrg# Emit a libtool wrapper script on stdout.
5200629baa8cSmrg# Don't directly open a file because we may want to
5201629baa8cSmrg# incorporate the script contents within a cygwin/mingw
5202629baa8cSmrg# wrapper executable.  Must ONLY be called from within
5203629baa8cSmrg# func_mode_link because it depends on a number of variables
5204629baa8cSmrg# set therein.
52055ffd6003Smrg#
5206629baa8cSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5207629baa8cSmrg# variable will take.  If 'yes', then the emitted script
5208b7d26471Smrg# will assume that the directory where it is stored is
5209629baa8cSmrg# the $objdir directory.  This is a cygwin/mingw-specific
5210629baa8cSmrg# behavior.
5211629baa8cSmrgfunc_emit_wrapper ()
52125ffd6003Smrg{
5213629baa8cSmrg	func_emit_wrapper_arg1=${1-no}
5214145b7b3cSmrg
52155ffd6003Smrg	$ECHO "\
52165ffd6003Smrg#! $SHELL
5217145b7b3cSmrg
52185ffd6003Smrg# $output - temporary wrapper script for $objdir/$outputname
5219b7d26471Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
52205ffd6003Smrg#
52215ffd6003Smrg# The $output program cannot be directly executed until all the libtool
52225ffd6003Smrg# libraries that it depends on are installed.
52235ffd6003Smrg#
52245ffd6003Smrg# This wrapper script should never be moved out of the build directory.
52255ffd6003Smrg# If it is, it will not operate correctly.
5226145b7b3cSmrg
52275ffd6003Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
52285ffd6003Smrg# metacharacters that are still active within double-quoted strings.
52295ffd6003Smrgsed_quote_subst='$sed_quote_subst'
5230145b7b3cSmrg
52315ffd6003Smrg# Be Bourne compatible
52325ffd6003Smrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
52335ffd6003Smrg  emulate sh
52345ffd6003Smrg  NULLCMD=:
52355ffd6003Smrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
52365ffd6003Smrg  # is contrary to our usage.  Disable this feature.
52375ffd6003Smrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
52385ffd6003Smrg  setopt NO_GLOB_SUBST
52395ffd6003Smrgelse
52405ffd6003Smrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
52415ffd6003Smrgfi
52425ffd6003SmrgBIN_SH=xpg4; export BIN_SH # for Tru64
52435ffd6003SmrgDUALCASE=1; export DUALCASE # for MKS sh
5244145b7b3cSmrg
52455ffd6003Smrg# The HP-UX ksh and POSIX shell print the target directory to stdout
52465ffd6003Smrg# if CDPATH is set.
52475ffd6003Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5248145b7b3cSmrg
52495ffd6003Smrgrelink_command=\"$relink_command\"
5250145b7b3cSmrg
52515ffd6003Smrg# This environment variable determines our operation mode.
52525ffd6003Smrgif test \"\$libtool_install_magic\" = \"$magic\"; then
52535ffd6003Smrg  # install mode needs the following variables:
52545ffd6003Smrg  generated_by_libtool_version='$macro_version'
52555ffd6003Smrg  notinst_deplibs='$notinst_deplibs'
52565ffd6003Smrgelse
52575ffd6003Smrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
52585ffd6003Smrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5259629baa8cSmrg    file=\"\$0\""
5260629baa8cSmrg
5261629baa8cSmrg    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
5262629baa8cSmrg    $ECHO "\
5263629baa8cSmrg
5264629baa8cSmrg# A function that is used when there is no print builtin or printf.
5265629baa8cSmrgfunc_fallback_echo ()
5266629baa8cSmrg{
5267629baa8cSmrg  eval 'cat <<_LTECHO_EOF
5268629baa8cSmrg\$1
5269629baa8cSmrg_LTECHO_EOF'
5270629baa8cSmrg}
5271629baa8cSmrg    ECHO=\"$qECHO\"
5272629baa8cSmrg  fi
5273629baa8cSmrg
5274629baa8cSmrg# Very basic option parsing. These options are (a) specific to
5275629baa8cSmrg# the libtool wrapper, (b) are identical between the wrapper
5276b7d26471Smrg# /script/ and the wrapper /executable/ that is used only on
5277629baa8cSmrg# windows platforms, and (c) all begin with the string "--lt-"
5278b7d26471Smrg# (application programs are unlikely to have options that match
5279629baa8cSmrg# this pattern).
5280629baa8cSmrg#
5281629baa8cSmrg# There are only two supported options: --lt-debug and
5282629baa8cSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5283629baa8cSmrg#
5284629baa8cSmrg# The first argument to this parsing function should be the
5285629baa8cSmrg# script's $0 value, followed by "$@".
5286629baa8cSmrglt_option_debug=
5287629baa8cSmrgfunc_parse_lt_options ()
5288629baa8cSmrg{
5289629baa8cSmrg  lt_script_arg0=\$0
5290629baa8cSmrg  shift
5291629baa8cSmrg  for lt_opt
5292629baa8cSmrg  do
5293629baa8cSmrg    case \"\$lt_opt\" in
5294629baa8cSmrg    --lt-debug) lt_option_debug=1 ;;
5295629baa8cSmrg    --lt-dump-script)
5296629baa8cSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5297629baa8cSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5298629baa8cSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5299629baa8cSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5300629baa8cSmrg        exit 0
5301629baa8cSmrg      ;;
5302629baa8cSmrg    --lt-*)
5303629baa8cSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5304629baa8cSmrg        exit 1
5305629baa8cSmrg      ;;
5306629baa8cSmrg    esac
5307629baa8cSmrg  done
5308629baa8cSmrg
5309629baa8cSmrg  # Print the debug banner immediately:
5310629baa8cSmrg  if test -n \"\$lt_option_debug\"; then
5311b7d26471Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5312629baa8cSmrg  fi
5313629baa8cSmrg}
5314629baa8cSmrg
5315629baa8cSmrg# Used when --lt-debug. Prints its arguments to stdout
5316629baa8cSmrg# (redirection is the responsibility of the caller)
5317629baa8cSmrgfunc_lt_dump_args ()
5318629baa8cSmrg{
5319629baa8cSmrg  lt_dump_args_N=1;
5320629baa8cSmrg  for lt_arg
5321629baa8cSmrg  do
5322b7d26471Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5323629baa8cSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5324629baa8cSmrg  done
5325629baa8cSmrg}
5326629baa8cSmrg
5327629baa8cSmrg# Core function for launching the target application
5328629baa8cSmrgfunc_exec_program_core ()
5329629baa8cSmrg{
53305ffd6003Smrg"
5331629baa8cSmrg  case $host in
5332629baa8cSmrg  # Backslashes separate directories on plain windows
5333629baa8cSmrg  *-*-mingw | *-*-os2* | *-cegcc*)
5334629baa8cSmrg    $ECHO "\
5335629baa8cSmrg      if test -n \"\$lt_option_debug\"; then
5336b7d26471Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5337629baa8cSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5338629baa8cSmrg      fi
5339629baa8cSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5340629baa8cSmrg"
5341629baa8cSmrg    ;;
5342629baa8cSmrg
5343629baa8cSmrg  *)
5344629baa8cSmrg    $ECHO "\
5345629baa8cSmrg      if test -n \"\$lt_option_debug\"; then
5346b7d26471Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5347629baa8cSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5348629baa8cSmrg      fi
5349629baa8cSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5350629baa8cSmrg"
5351629baa8cSmrg    ;;
5352629baa8cSmrg  esac
5353629baa8cSmrg  $ECHO "\
5354629baa8cSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5355629baa8cSmrg      exit 1
5356629baa8cSmrg}
5357629baa8cSmrg
5358629baa8cSmrg# A function to encapsulate launching the target application
5359629baa8cSmrg# Strips options in the --lt-* namespace from \$@ and
5360629baa8cSmrg# launches target application with the remaining arguments.
5361629baa8cSmrgfunc_exec_program ()
5362629baa8cSmrg{
5363b7d26471Smrg  case \" \$* \" in
5364b7d26471Smrg  *\\ --lt-*)
5365b7d26471Smrg    for lt_wr_arg
5366b7d26471Smrg    do
5367b7d26471Smrg      case \$lt_wr_arg in
5368b7d26471Smrg      --lt-*) ;;
5369b7d26471Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5370b7d26471Smrg      esac
5371b7d26471Smrg      shift
5372b7d26471Smrg    done ;;
5373b7d26471Smrg  esac
5374629baa8cSmrg  func_exec_program_core \${1+\"\$@\"}
5375629baa8cSmrg}
5376629baa8cSmrg
5377629baa8cSmrg  # Parse options
5378629baa8cSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5379145b7b3cSmrg
53805ffd6003Smrg  # Find the directory that this script lives in.
5381629baa8cSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
53825ffd6003Smrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5383145b7b3cSmrg
53845ffd6003Smrg  # Follow symbolic links until we get to the real thisdir.
5385629baa8cSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
53865ffd6003Smrg  while test -n \"\$file\"; do
5387629baa8cSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5388145b7b3cSmrg
53895ffd6003Smrg    # If there was a directory component, then change thisdir.
53905ffd6003Smrg    if test \"x\$destdir\" != \"x\$file\"; then
53915ffd6003Smrg      case \"\$destdir\" in
53925ffd6003Smrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
53935ffd6003Smrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5394145b7b3cSmrg      esac
53955ffd6003Smrg    fi
5396145b7b3cSmrg
5397629baa8cSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5398629baa8cSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
53995ffd6003Smrg  done
5400145b7b3cSmrg
54015ffd6003Smrg  # Usually 'no', except on cygwin/mingw when embedded into
54025ffd6003Smrg  # the cwrapper.
5403629baa8cSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
54045ffd6003Smrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
54055ffd6003Smrg    # special case for '.'
54065ffd6003Smrg    if test \"\$thisdir\" = \".\"; then
54075ffd6003Smrg      thisdir=\`pwd\`
54085ffd6003Smrg    fi
54095ffd6003Smrg    # remove .libs from thisdir
54105ffd6003Smrg    case \"\$thisdir\" in
5411629baa8cSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
54125ffd6003Smrg    $objdir )   thisdir=. ;;
54135ffd6003Smrg    esac
54145ffd6003Smrg  fi
54155ffd6003Smrg
54165ffd6003Smrg  # Try to get the absolute directory name.
54175ffd6003Smrg  absdir=\`cd \"\$thisdir\" && pwd\`
54185ffd6003Smrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
54195ffd6003Smrg"
54205ffd6003Smrg
5421b7d26471Smrg	if test yes = "$fast_install"; then
54225ffd6003Smrg	  $ECHO "\
54235ffd6003Smrg  program=lt-'$outputname'$exeext
54245ffd6003Smrg  progdir=\"\$thisdir/$objdir\"
54255ffd6003Smrg
54265ffd6003Smrg  if test ! -f \"\$progdir/\$program\" ||
5427b7d26471Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
54285ffd6003Smrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
54295ffd6003Smrg
54305ffd6003Smrg    file=\"\$\$-\$program\"
54315ffd6003Smrg
54325ffd6003Smrg    if test ! -d \"\$progdir\"; then
54335ffd6003Smrg      $MKDIR \"\$progdir\"
54345ffd6003Smrg    else
54355ffd6003Smrg      $RM \"\$progdir/\$file\"
54365ffd6003Smrg    fi"
54375ffd6003Smrg
54385ffd6003Smrg	  $ECHO "\
54395ffd6003Smrg
54405ffd6003Smrg    # relink executable if necessary
54415ffd6003Smrg    if test -n \"\$relink_command\"; then
54425ffd6003Smrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
54435ffd6003Smrg      else
5444b7d26471Smrg	\$ECHO \"\$relink_command_output\" >&2
54455ffd6003Smrg	$RM \"\$progdir/\$file\"
54465ffd6003Smrg	exit 1
5447145b7b3cSmrg      fi
54485ffd6003Smrg    fi
5449145b7b3cSmrg
54505ffd6003Smrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
54515ffd6003Smrg    { $RM \"\$progdir/\$program\";
54525ffd6003Smrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
54535ffd6003Smrg    $RM \"\$progdir/\$file\"
54545ffd6003Smrg  fi"
54555ffd6003Smrg	else
54565ffd6003Smrg	  $ECHO "\
54575ffd6003Smrg  program='$outputname'
54585ffd6003Smrg  progdir=\"\$thisdir/$objdir\"
54595ffd6003Smrg"
5460145b7b3cSmrg	fi
5461145b7b3cSmrg
54625ffd6003Smrg	$ECHO "\
5463145b7b3cSmrg
54645ffd6003Smrg  if test -f \"\$progdir/\$program\"; then"
5465145b7b3cSmrg
5466629baa8cSmrg	# fixup the dll searchpath if we need to.
5467629baa8cSmrg	#
5468629baa8cSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5469629baa8cSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5470629baa8cSmrg	# libraries must come first.
5471629baa8cSmrg	if test -n "$dllsearchpath"; then
5472629baa8cSmrg	  $ECHO "\
5473629baa8cSmrg    # Add the dll search path components to the executable PATH
5474629baa8cSmrg    PATH=$dllsearchpath:\$PATH
5475629baa8cSmrg"
5476629baa8cSmrg	fi
5477629baa8cSmrg
54785ffd6003Smrg	# Export our shlibpath_var if we have one.
5479b7d26471Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
54805ffd6003Smrg	  $ECHO "\
54815ffd6003Smrg    # Add our own library path to $shlibpath_var
54825ffd6003Smrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5483145b7b3cSmrg
54845ffd6003Smrg    # Some systems cannot cope with colon-terminated $shlibpath_var
54855ffd6003Smrg    # The second colon is a workaround for a bug in BeOS R4 sed
5486629baa8cSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
54875ffd6003Smrg
54885ffd6003Smrg    export $shlibpath_var
54895ffd6003Smrg"
5490145b7b3cSmrg	fi
5491145b7b3cSmrg
54925ffd6003Smrg	$ECHO "\
54935ffd6003Smrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
54945ffd6003Smrg      # Run the actual program with our arguments.
5495629baa8cSmrg      func_exec_program \${1+\"\$@\"}
54965ffd6003Smrg    fi
54975ffd6003Smrg  else
54985ffd6003Smrg    # The program doesn't exist.
5499b7d26471Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
55005ffd6003Smrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5501629baa8cSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
55025ffd6003Smrg    exit 1
55035ffd6003Smrg  fi
55045ffd6003Smrgfi\
55055ffd6003Smrg"
55065ffd6003Smrg}
5507145b7b3cSmrg
5508145b7b3cSmrg
55095ffd6003Smrg# func_emit_cwrapperexe_src
55105ffd6003Smrg# emit the source code for a wrapper executable on stdout
55115ffd6003Smrg# Must ONLY be called from within func_mode_link because
55125ffd6003Smrg# it depends on a number of variable set therein.
55135ffd6003Smrgfunc_emit_cwrapperexe_src ()
55145ffd6003Smrg{
55155ffd6003Smrg	cat <<EOF
5516145b7b3cSmrg
55175ffd6003Smrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5518b7d26471Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5519145b7b3cSmrg
55205ffd6003Smrg   The $output program cannot be directly executed until all the libtool
55215ffd6003Smrg   libraries that it depends on are installed.
5522145b7b3cSmrg
55235ffd6003Smrg   This wrapper executable should never be moved out of the build directory.
55245ffd6003Smrg   If it is, it will not operate correctly.
55255ffd6003Smrg*/
55265ffd6003SmrgEOF
55275ffd6003Smrg	    cat <<"EOF"
5528629baa8cSmrg#ifdef _MSC_VER
5529629baa8cSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5530629baa8cSmrg#endif
55315ffd6003Smrg#include <stdio.h>
55325ffd6003Smrg#include <stdlib.h>
55335ffd6003Smrg#ifdef _MSC_VER
55345ffd6003Smrg# include <direct.h>
55355ffd6003Smrg# include <process.h>
55365ffd6003Smrg# include <io.h>
55375ffd6003Smrg#else
55385ffd6003Smrg# include <unistd.h>
55395ffd6003Smrg# include <stdint.h>
55405ffd6003Smrg# ifdef __CYGWIN__
55415ffd6003Smrg#  include <io.h>
5542629baa8cSmrg# endif
5543629baa8cSmrg#endif
5544629baa8cSmrg#include <malloc.h>
5545629baa8cSmrg#include <stdarg.h>
5546629baa8cSmrg#include <assert.h>
5547629baa8cSmrg#include <string.h>
5548629baa8cSmrg#include <ctype.h>
5549629baa8cSmrg#include <errno.h>
5550629baa8cSmrg#include <fcntl.h>
5551629baa8cSmrg#include <sys/stat.h>
5552629baa8cSmrg
5553b7d26471Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5554b7d26471Smrg
5555629baa8cSmrg/* declarations of non-ANSI functions */
5556b7d26471Smrg#if defined __MINGW32__
5557629baa8cSmrg# ifdef __STRICT_ANSI__
5558629baa8cSmrgint _putenv (const char *);
5559629baa8cSmrg# endif
5560b7d26471Smrg#elif defined __CYGWIN__
5561629baa8cSmrg# ifdef __STRICT_ANSI__
55625ffd6003Smrgchar *realpath (const char *, char *);
55635ffd6003Smrgint putenv (char *);
55645ffd6003Smrgint setenv (const char *, const char *, int);
55655ffd6003Smrg# endif
5566b7d26471Smrg/* #elif defined other_platform || defined ... */
5567629baa8cSmrg#endif
5568629baa8cSmrg
5569629baa8cSmrg/* portability defines, excluding path handling macros */
5570b7d26471Smrg#if defined _MSC_VER
5571629baa8cSmrg# define setmode _setmode
5572629baa8cSmrg# define stat    _stat
5573629baa8cSmrg# define chmod   _chmod
5574629baa8cSmrg# define getcwd  _getcwd
5575629baa8cSmrg# define putenv  _putenv
5576629baa8cSmrg# define S_IXUSR _S_IEXEC
5577b7d26471Smrg#elif defined __MINGW32__
5578629baa8cSmrg# define setmode _setmode
5579629baa8cSmrg# define stat    _stat
5580629baa8cSmrg# define chmod   _chmod
5581629baa8cSmrg# define getcwd  _getcwd
5582629baa8cSmrg# define putenv  _putenv
5583b7d26471Smrg#elif defined __CYGWIN__
5584629baa8cSmrg# define HAVE_SETENV
5585629baa8cSmrg# define FOPEN_WB "wb"
5586b7d26471Smrg/* #elif defined other platforms ... */
55875ffd6003Smrg#endif
5588145b7b3cSmrg
5589b7d26471Smrg#if defined PATH_MAX
55905ffd6003Smrg# define LT_PATHMAX PATH_MAX
5591b7d26471Smrg#elif defined MAXPATHLEN
55925ffd6003Smrg# define LT_PATHMAX MAXPATHLEN
55935ffd6003Smrg#else
55945ffd6003Smrg# define LT_PATHMAX 1024
55955ffd6003Smrg#endif
5596145b7b3cSmrg
55975ffd6003Smrg#ifndef S_IXOTH
55985ffd6003Smrg# define S_IXOTH 0
55995ffd6003Smrg#endif
56005ffd6003Smrg#ifndef S_IXGRP
56015ffd6003Smrg# define S_IXGRP 0
56025ffd6003Smrg#endif
5603145b7b3cSmrg
5604629baa8cSmrg/* path handling portability macros */
56055ffd6003Smrg#ifndef DIR_SEPARATOR
56065ffd6003Smrg# define DIR_SEPARATOR '/'
56075ffd6003Smrg# define PATH_SEPARATOR ':'
56085ffd6003Smrg#endif
5609145b7b3cSmrg
5610b7d26471Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5611b7d26471Smrg  defined __OS2__
56125ffd6003Smrg# define HAVE_DOS_BASED_FILE_SYSTEM
56135ffd6003Smrg# define FOPEN_WB "wb"
56145ffd6003Smrg# ifndef DIR_SEPARATOR_2
56155ffd6003Smrg#  define DIR_SEPARATOR_2 '\\'
56165ffd6003Smrg# endif
56175ffd6003Smrg# ifndef PATH_SEPARATOR_2
56185ffd6003Smrg#  define PATH_SEPARATOR_2 ';'
56195ffd6003Smrg# endif
56205ffd6003Smrg#endif
5621145b7b3cSmrg
56225ffd6003Smrg#ifndef DIR_SEPARATOR_2
56235ffd6003Smrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
56245ffd6003Smrg#else /* DIR_SEPARATOR_2 */
56255ffd6003Smrg# define IS_DIR_SEPARATOR(ch) \
56265ffd6003Smrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
56275ffd6003Smrg#endif /* DIR_SEPARATOR_2 */
5628145b7b3cSmrg
56295ffd6003Smrg#ifndef PATH_SEPARATOR_2
56305ffd6003Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
56315ffd6003Smrg#else /* PATH_SEPARATOR_2 */
56325ffd6003Smrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
56335ffd6003Smrg#endif /* PATH_SEPARATOR_2 */
5634145b7b3cSmrg
56355ffd6003Smrg#ifndef FOPEN_WB
56365ffd6003Smrg# define FOPEN_WB "w"
56375ffd6003Smrg#endif
56385ffd6003Smrg#ifndef _O_BINARY
56395ffd6003Smrg# define _O_BINARY 0
56405ffd6003Smrg#endif
5641145b7b3cSmrg
56425ffd6003Smrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
56435ffd6003Smrg#define XFREE(stale) do { \
5644b7d26471Smrg  if (stale) { free (stale); stale = 0; } \
56455ffd6003Smrg} while (0)
5646145b7b3cSmrg
5647b7d26471Smrg#if defined LT_DEBUGWRAPPER
5648629baa8cSmrgstatic int lt_debug = 1;
56495ffd6003Smrg#else
5650629baa8cSmrgstatic int lt_debug = 0;
56515ffd6003Smrg#endif
5652145b7b3cSmrg
5653629baa8cSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5654145b7b3cSmrg
56555ffd6003Smrgvoid *xmalloc (size_t num);
56565ffd6003Smrgchar *xstrdup (const char *string);
56575ffd6003Smrgconst char *base_name (const char *name);
56585ffd6003Smrgchar *find_executable (const char *wrapper);
56595ffd6003Smrgchar *chase_symlinks (const char *pathspec);
56605ffd6003Smrgint make_executable (const char *path);
56615ffd6003Smrgint check_executable (const char *path);
56625ffd6003Smrgchar *strendzap (char *str, const char *pat);
5663629baa8cSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5664629baa8cSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5665629baa8cSmrgstatic const char *nonnull (const char *s);
5666629baa8cSmrgstatic const char *nonempty (const char *s);
56675ffd6003Smrgvoid lt_setenv (const char *name, const char *value);
56685ffd6003Smrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
56695ffd6003Smrgvoid lt_update_exe_path (const char *name, const char *value);
56705ffd6003Smrgvoid lt_update_lib_path (const char *name, const char *value);
5671629baa8cSmrgchar **prepare_spawn (char **argv);
5672629baa8cSmrgvoid lt_dump_script (FILE *f);
56735ffd6003SmrgEOF
56745ffd6003Smrg
56755ffd6003Smrg	    cat <<EOF
5676b7d26471Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5677b7d26471Smrg# define externally_visible volatile
5678b7d26471Smrg#else
5679b7d26471Smrg# define externally_visible __attribute__((externally_visible)) volatile
5680b7d26471Smrg#endif
5681b7d26471Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
56825ffd6003Smrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
56835ffd6003SmrgEOF
5684145b7b3cSmrg
5685b7d26471Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5686629baa8cSmrg              func_to_host_path "$temp_rpath"
56875ffd6003Smrg	      cat <<EOF
5688629baa8cSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
56895ffd6003SmrgEOF
56905ffd6003Smrg	    else
56915ffd6003Smrg	      cat <<"EOF"
56925ffd6003Smrgconst char * LIB_PATH_VALUE   = "";
56935ffd6003SmrgEOF
5694145b7b3cSmrg	    fi
5695145b7b3cSmrg
56965ffd6003Smrg	    if test -n "$dllsearchpath"; then
5697629baa8cSmrg              func_to_host_path "$dllsearchpath:"
56985ffd6003Smrg	      cat <<EOF
56995ffd6003Smrgconst char * EXE_PATH_VARNAME = "PATH";
5700629baa8cSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5701145b7b3cSmrgEOF
5702145b7b3cSmrg	    else
57035ffd6003Smrg	      cat <<"EOF"
57045ffd6003Smrgconst char * EXE_PATH_VARNAME = "";
57055ffd6003Smrgconst char * EXE_PATH_VALUE   = "";
57065ffd6003SmrgEOF
5707145b7b3cSmrg	    fi
57085ffd6003Smrg
5709b7d26471Smrg	    if test yes = "$fast_install"; then
57105ffd6003Smrg	      cat <<EOF
57115ffd6003Smrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
57125ffd6003SmrgEOF
5713145b7b3cSmrg	    else
57145ffd6003Smrg	      cat <<EOF
57155ffd6003Smrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
57165ffd6003SmrgEOF
5717145b7b3cSmrg	    fi
5718145b7b3cSmrg
5719145b7b3cSmrg
57205ffd6003Smrg	    cat <<"EOF"
5721145b7b3cSmrg
57225ffd6003Smrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5723145b7b3cSmrg
57245ffd6003Smrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
57255ffd6003Smrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5726629baa8cSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5727145b7b3cSmrg
57285ffd6003Smrgint
57295ffd6003Smrgmain (int argc, char *argv[])
57305ffd6003Smrg{
57315ffd6003Smrg  char **newargz;
57325ffd6003Smrg  int  newargc;
57335ffd6003Smrg  char *tmp_pathspec;
57345ffd6003Smrg  char *actual_cwrapper_path;
57355ffd6003Smrg  char *actual_cwrapper_name;
57365ffd6003Smrg  char *target_name;
57375ffd6003Smrg  char *lt_argv_zero;
5738b7d26471Smrg  int rval = 127;
5739145b7b3cSmrg
57405ffd6003Smrg  int i;
5741145b7b3cSmrg
57425ffd6003Smrg  program_name = (char *) xstrdup (base_name (argv[0]));
5743b7d26471Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
5744145b7b3cSmrg
5745629baa8cSmrg  /* very simple arg parsing; don't want to rely on getopt
5746629baa8cSmrg   * also, copy all non cwrapper options to newargz, except
5747629baa8cSmrg   * argz[0], which is handled differently
5748629baa8cSmrg   */
5749629baa8cSmrg  newargc=0;
57505ffd6003Smrg  for (i = 1; i < argc; i++)
57515ffd6003Smrg    {
5752b7d26471Smrg      if (STREQ (argv[i], dumpscript_opt))
57535ffd6003Smrg	{
57545ffd6003SmrgEOF
5755b7d26471Smrg	    case $host in
57565ffd6003Smrg	      *mingw* | *cygwin* )
57575ffd6003Smrg		# make stdout use "unix" line endings
57585ffd6003Smrg		echo "          setmode(1,_O_BINARY);"
57595ffd6003Smrg		;;
57605ffd6003Smrg	      esac
5761145b7b3cSmrg
57625ffd6003Smrg	    cat <<"EOF"
5763629baa8cSmrg	  lt_dump_script (stdout);
57645ffd6003Smrg	  return 0;
57655ffd6003Smrg	}
5766b7d26471Smrg      if (STREQ (argv[i], debug_opt))
5767629baa8cSmrg	{
5768629baa8cSmrg          lt_debug = 1;
5769629baa8cSmrg          continue;
5770629baa8cSmrg	}
5771b7d26471Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
5772629baa8cSmrg        {
5773629baa8cSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
5774629baa8cSmrg             namespace, but it is not one of the ones we know about and
5775629baa8cSmrg             have already dealt with, above (inluding dump-script), then
5776629baa8cSmrg             report an error. Otherwise, targets might begin to believe
5777629baa8cSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
5778629baa8cSmrg             namespace. The first time any user complains about this, we'll
5779629baa8cSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
5780629baa8cSmrg             or a configure.ac-settable value.
5781629baa8cSmrg           */
5782629baa8cSmrg          lt_fatal (__FILE__, __LINE__,
5783629baa8cSmrg		    "unrecognized %s option: '%s'",
5784629baa8cSmrg                    ltwrapper_option_prefix, argv[i]);
5785629baa8cSmrg        }
5786629baa8cSmrg      /* otherwise ... */
5787629baa8cSmrg      newargz[++newargc] = xstrdup (argv[i]);
57885ffd6003Smrg    }
5789629baa8cSmrg  newargz[++newargc] = NULL;
5790629baa8cSmrg
5791629baa8cSmrgEOF
5792629baa8cSmrg	    cat <<EOF
5793629baa8cSmrg  /* The GNU banner must be the first non-error debug message */
5794b7d26471Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
5795629baa8cSmrgEOF
5796629baa8cSmrg	    cat <<"EOF"
5797629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
5798629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
5799145b7b3cSmrg
58005ffd6003Smrg  tmp_pathspec = find_executable (argv[0]);
58015ffd6003Smrg  if (tmp_pathspec == NULL)
5802629baa8cSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
5803629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
5804629baa8cSmrg                  "(main) found exe (before symlink chase) at: %s\n",
5805629baa8cSmrg		  tmp_pathspec);
58065ffd6003Smrg
58075ffd6003Smrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
5808629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
5809629baa8cSmrg                  "(main) found exe (after symlink chase) at: %s\n",
5810629baa8cSmrg		  actual_cwrapper_path);
58115ffd6003Smrg  XFREE (tmp_pathspec);
58125ffd6003Smrg
5813629baa8cSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
58145ffd6003Smrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
58155ffd6003Smrg
58165ffd6003Smrg  /* wrapper name transforms */
58175ffd6003Smrg  strendzap (actual_cwrapper_name, ".exe");
58185ffd6003Smrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
58195ffd6003Smrg  XFREE (actual_cwrapper_name);
58205ffd6003Smrg  actual_cwrapper_name = tmp_pathspec;
58215ffd6003Smrg  tmp_pathspec = 0;
58225ffd6003Smrg
58235ffd6003Smrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
58245ffd6003Smrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
58255ffd6003Smrg  strendzap (target_name, ".exe");
58265ffd6003Smrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
58275ffd6003Smrg  XFREE (target_name);
58285ffd6003Smrg  target_name = tmp_pathspec;
58295ffd6003Smrg  tmp_pathspec = 0;
58305ffd6003Smrg
5831629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
5832629baa8cSmrg		  "(main) libtool target name: %s\n",
5833629baa8cSmrg		  target_name);
58345ffd6003SmrgEOF
5835145b7b3cSmrg
58365ffd6003Smrg	    cat <<EOF
58375ffd6003Smrg  newargz[0] =
58385ffd6003Smrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
58395ffd6003Smrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
58405ffd6003Smrg  strcpy (newargz[0], actual_cwrapper_path);
58415ffd6003Smrg  strcat (newargz[0], "$objdir");
58425ffd6003Smrg  strcat (newargz[0], "/");
58435ffd6003SmrgEOF
5844145b7b3cSmrg
58455ffd6003Smrg	    cat <<"EOF"
58465ffd6003Smrg  /* stop here, and copy so we don't have to do this twice */
58475ffd6003Smrg  tmp_pathspec = xstrdup (newargz[0]);
5848145b7b3cSmrg
58495ffd6003Smrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
58505ffd6003Smrg  strcat (newargz[0], actual_cwrapper_name);
5851145b7b3cSmrg
58525ffd6003Smrg  /* DO want the lt- prefix here if it exists, so use target_name */
58535ffd6003Smrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
58545ffd6003Smrg  XFREE (tmp_pathspec);
58555ffd6003Smrg  tmp_pathspec = NULL;
58565ffd6003SmrgEOF
5857145b7b3cSmrg
58585ffd6003Smrg	    case $host_os in
58595ffd6003Smrg	      mingw*)
58605ffd6003Smrg	    cat <<"EOF"
58615ffd6003Smrg  {
58625ffd6003Smrg    char* p;
58635ffd6003Smrg    while ((p = strchr (newargz[0], '\\')) != NULL)
58645ffd6003Smrg      {
58655ffd6003Smrg	*p = '/';
58665ffd6003Smrg      }
58675ffd6003Smrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
58685ffd6003Smrg      {
58695ffd6003Smrg	*p = '/';
58705ffd6003Smrg      }
58715ffd6003Smrg  }
58725ffd6003SmrgEOF
58735ffd6003Smrg	    ;;
58745ffd6003Smrg	    esac
5875145b7b3cSmrg
58765ffd6003Smrg	    cat <<"EOF"
58775ffd6003Smrg  XFREE (target_name);
58785ffd6003Smrg  XFREE (actual_cwrapper_path);
58795ffd6003Smrg  XFREE (actual_cwrapper_name);
5880145b7b3cSmrg
58815ffd6003Smrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
58825ffd6003Smrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
5883629baa8cSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
5884629baa8cSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
5885629baa8cSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
5886629baa8cSmrg     libraries must come first. */
58875ffd6003Smrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
5888629baa8cSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
5889145b7b3cSmrg
5890629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
5891629baa8cSmrg		  nonnull (lt_argv_zero));
58925ffd6003Smrg  for (i = 0; i < newargc; i++)
58935ffd6003Smrg    {
5894629baa8cSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
5895629baa8cSmrg		      i, nonnull (newargz[i]));
58965ffd6003Smrg    }
5897145b7b3cSmrg
58985ffd6003SmrgEOF
5899145b7b3cSmrg
59005ffd6003Smrg	    case $host_os in
59015ffd6003Smrg	      mingw*)
59025ffd6003Smrg		cat <<"EOF"
59035ffd6003Smrg  /* execv doesn't actually work on mingw as expected on unix */
5904629baa8cSmrg  newargz = prepare_spawn (newargz);
5905b7d26471Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
59065ffd6003Smrg  if (rval == -1)
59075ffd6003Smrg    {
59085ffd6003Smrg      /* failed to start process */
5909629baa8cSmrg      lt_debugprintf (__FILE__, __LINE__,
5910629baa8cSmrg		      "(main) failed to launch target \"%s\": %s\n",
5911629baa8cSmrg		      lt_argv_zero, nonnull (strerror (errno)));
59125ffd6003Smrg      return 127;
59135ffd6003Smrg    }
59145ffd6003Smrg  return rval;
59155ffd6003SmrgEOF
59165ffd6003Smrg		;;
59175ffd6003Smrg	      *)
59185ffd6003Smrg		cat <<"EOF"
59195ffd6003Smrg  execv (lt_argv_zero, newargz);
59205ffd6003Smrg  return rval; /* =127, but avoids unused variable warning */
59215ffd6003SmrgEOF
59225ffd6003Smrg		;;
59235ffd6003Smrg	    esac
5924145b7b3cSmrg
59255ffd6003Smrg	    cat <<"EOF"
59265ffd6003Smrg}
5927145b7b3cSmrg
59285ffd6003Smrgvoid *
59295ffd6003Smrgxmalloc (size_t num)
59305ffd6003Smrg{
59315ffd6003Smrg  void *p = (void *) malloc (num);
59325ffd6003Smrg  if (!p)
5933629baa8cSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
5934145b7b3cSmrg
59355ffd6003Smrg  return p;
59365ffd6003Smrg}
5937145b7b3cSmrg
59385ffd6003Smrgchar *
59395ffd6003Smrgxstrdup (const char *string)
59405ffd6003Smrg{
59415ffd6003Smrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
59425ffd6003Smrg			  string) : NULL;
59435ffd6003Smrg}
5944145b7b3cSmrg
59455ffd6003Smrgconst char *
59465ffd6003Smrgbase_name (const char *name)
59475ffd6003Smrg{
59485ffd6003Smrg  const char *base;
5949145b7b3cSmrg
5950b7d26471Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
59515ffd6003Smrg  /* Skip over the disk name in MSDOS pathnames. */
59525ffd6003Smrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
59535ffd6003Smrg    name += 2;
59545ffd6003Smrg#endif
5955145b7b3cSmrg
59565ffd6003Smrg  for (base = name; *name; name++)
59575ffd6003Smrg    if (IS_DIR_SEPARATOR (*name))
59585ffd6003Smrg      base = name + 1;
59595ffd6003Smrg  return base;
59605ffd6003Smrg}
5961145b7b3cSmrg
59625ffd6003Smrgint
59635ffd6003Smrgcheck_executable (const char *path)
59645ffd6003Smrg{
59655ffd6003Smrg  struct stat st;
5966145b7b3cSmrg
5967629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
5968629baa8cSmrg                  nonempty (path));
59695ffd6003Smrg  if ((!path) || (!*path))
59705ffd6003Smrg    return 0;
5971145b7b3cSmrg
59725ffd6003Smrg  if ((stat (path, &st) >= 0)
59735ffd6003Smrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
59745ffd6003Smrg    return 1;
59755ffd6003Smrg  else
59765ffd6003Smrg    return 0;
59775ffd6003Smrg}
5978145b7b3cSmrg
59795ffd6003Smrgint
59805ffd6003Smrgmake_executable (const char *path)
59815ffd6003Smrg{
59825ffd6003Smrg  int rval = 0;
59835ffd6003Smrg  struct stat st;
5984145b7b3cSmrg
5985629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
5986629baa8cSmrg                  nonempty (path));
59875ffd6003Smrg  if ((!path) || (!*path))
59885ffd6003Smrg    return 0;
5989145b7b3cSmrg
59905ffd6003Smrg  if (stat (path, &st) >= 0)
59915ffd6003Smrg    {
59925ffd6003Smrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
59935ffd6003Smrg    }
59945ffd6003Smrg  return rval;
59955ffd6003Smrg}
5996145b7b3cSmrg
59975ffd6003Smrg/* Searches for the full path of the wrapper.  Returns
59985ffd6003Smrg   newly allocated full path name if found, NULL otherwise
59995ffd6003Smrg   Does not chase symlinks, even on platforms that support them.
60005ffd6003Smrg*/
60015ffd6003Smrgchar *
60025ffd6003Smrgfind_executable (const char *wrapper)
60035ffd6003Smrg{
60045ffd6003Smrg  int has_slash = 0;
60055ffd6003Smrg  const char *p;
60065ffd6003Smrg  const char *p_next;
60075ffd6003Smrg  /* static buffer for getcwd */
60085ffd6003Smrg  char tmp[LT_PATHMAX + 1];
6009b7d26471Smrg  size_t tmp_len;
60105ffd6003Smrg  char *concat_name;
6011145b7b3cSmrg
6012629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6013629baa8cSmrg                  nonempty (wrapper));
6014145b7b3cSmrg
60155ffd6003Smrg  if ((wrapper == NULL) || (*wrapper == '\0'))
60165ffd6003Smrg    return NULL;
6017145b7b3cSmrg
60185ffd6003Smrg  /* Absolute path? */
6019b7d26471Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
60205ffd6003Smrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
60215ffd6003Smrg    {
60225ffd6003Smrg      concat_name = xstrdup (wrapper);
60235ffd6003Smrg      if (check_executable (concat_name))
60245ffd6003Smrg	return concat_name;
60255ffd6003Smrg      XFREE (concat_name);
60265ffd6003Smrg    }
60275ffd6003Smrg  else
60285ffd6003Smrg    {
60295ffd6003Smrg#endif
60305ffd6003Smrg      if (IS_DIR_SEPARATOR (wrapper[0]))
60315ffd6003Smrg	{
60325ffd6003Smrg	  concat_name = xstrdup (wrapper);
60335ffd6003Smrg	  if (check_executable (concat_name))
60345ffd6003Smrg	    return concat_name;
60355ffd6003Smrg	  XFREE (concat_name);
60365ffd6003Smrg	}
6037b7d26471Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
60385ffd6003Smrg    }
60395ffd6003Smrg#endif
6040145b7b3cSmrg
60415ffd6003Smrg  for (p = wrapper; *p; p++)
60425ffd6003Smrg    if (*p == '/')
60435ffd6003Smrg      {
60445ffd6003Smrg	has_slash = 1;
60455ffd6003Smrg	break;
60465ffd6003Smrg      }
60475ffd6003Smrg  if (!has_slash)
60485ffd6003Smrg    {
60495ffd6003Smrg      /* no slashes; search PATH */
60505ffd6003Smrg      const char *path = getenv ("PATH");
60515ffd6003Smrg      if (path != NULL)
60525ffd6003Smrg	{
60535ffd6003Smrg	  for (p = path; *p; p = p_next)
60545ffd6003Smrg	    {
60555ffd6003Smrg	      const char *q;
60565ffd6003Smrg	      size_t p_len;
60575ffd6003Smrg	      for (q = p; *q; q++)
60585ffd6003Smrg		if (IS_PATH_SEPARATOR (*q))
60595ffd6003Smrg		  break;
6060b7d26471Smrg	      p_len = (size_t) (q - p);
60615ffd6003Smrg	      p_next = (*q == '\0' ? q : q + 1);
60625ffd6003Smrg	      if (p_len == 0)
60635ffd6003Smrg		{
60645ffd6003Smrg		  /* empty path: current directory */
60655ffd6003Smrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6066629baa8cSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6067629baa8cSmrg                              nonnull (strerror (errno)));
60685ffd6003Smrg		  tmp_len = strlen (tmp);
60695ffd6003Smrg		  concat_name =
60705ffd6003Smrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
60715ffd6003Smrg		  memcpy (concat_name, tmp, tmp_len);
60725ffd6003Smrg		  concat_name[tmp_len] = '/';
60735ffd6003Smrg		  strcpy (concat_name + tmp_len + 1, wrapper);
60745ffd6003Smrg		}
60755ffd6003Smrg	      else
60765ffd6003Smrg		{
60775ffd6003Smrg		  concat_name =
60785ffd6003Smrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
60795ffd6003Smrg		  memcpy (concat_name, p, p_len);
60805ffd6003Smrg		  concat_name[p_len] = '/';
60815ffd6003Smrg		  strcpy (concat_name + p_len + 1, wrapper);
60825ffd6003Smrg		}
60835ffd6003Smrg	      if (check_executable (concat_name))
60845ffd6003Smrg		return concat_name;
60855ffd6003Smrg	      XFREE (concat_name);
60865ffd6003Smrg	    }
60875ffd6003Smrg	}
60885ffd6003Smrg      /* not found in PATH; assume curdir */
60895ffd6003Smrg    }
60905ffd6003Smrg  /* Relative path | not found in path: prepend cwd */
60915ffd6003Smrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6092629baa8cSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6093629baa8cSmrg              nonnull (strerror (errno)));
60945ffd6003Smrg  tmp_len = strlen (tmp);
60955ffd6003Smrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
60965ffd6003Smrg  memcpy (concat_name, tmp, tmp_len);
60975ffd6003Smrg  concat_name[tmp_len] = '/';
60985ffd6003Smrg  strcpy (concat_name + tmp_len + 1, wrapper);
6099145b7b3cSmrg
61005ffd6003Smrg  if (check_executable (concat_name))
61015ffd6003Smrg    return concat_name;
61025ffd6003Smrg  XFREE (concat_name);
61035ffd6003Smrg  return NULL;
61045ffd6003Smrg}
6105145b7b3cSmrg
61065ffd6003Smrgchar *
61075ffd6003Smrgchase_symlinks (const char *pathspec)
61085ffd6003Smrg{
61095ffd6003Smrg#ifndef S_ISLNK
61105ffd6003Smrg  return xstrdup (pathspec);
61115ffd6003Smrg#else
61125ffd6003Smrg  char buf[LT_PATHMAX];
61135ffd6003Smrg  struct stat s;
61145ffd6003Smrg  char *tmp_pathspec = xstrdup (pathspec);
61155ffd6003Smrg  char *p;
61165ffd6003Smrg  int has_symlinks = 0;
61175ffd6003Smrg  while (strlen (tmp_pathspec) && !has_symlinks)
61185ffd6003Smrg    {
6119629baa8cSmrg      lt_debugprintf (__FILE__, __LINE__,
6120629baa8cSmrg		      "checking path component for symlinks: %s\n",
6121629baa8cSmrg		      tmp_pathspec);
61225ffd6003Smrg      if (lstat (tmp_pathspec, &s) == 0)
61235ffd6003Smrg	{
61245ffd6003Smrg	  if (S_ISLNK (s.st_mode) != 0)
61255ffd6003Smrg	    {
61265ffd6003Smrg	      has_symlinks = 1;
61275ffd6003Smrg	      break;
61285ffd6003Smrg	    }
6129145b7b3cSmrg
61305ffd6003Smrg	  /* search backwards for last DIR_SEPARATOR */
61315ffd6003Smrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
61325ffd6003Smrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
61335ffd6003Smrg	    p--;
61345ffd6003Smrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
61355ffd6003Smrg	    {
61365ffd6003Smrg	      /* no more DIR_SEPARATORS left */
61375ffd6003Smrg	      break;
61385ffd6003Smrg	    }
61395ffd6003Smrg	  *p = '\0';
61405ffd6003Smrg	}
61415ffd6003Smrg      else
61425ffd6003Smrg	{
6143629baa8cSmrg	  lt_fatal (__FILE__, __LINE__,
6144629baa8cSmrg		    "error accessing file \"%s\": %s",
6145629baa8cSmrg		    tmp_pathspec, nonnull (strerror (errno)));
61465ffd6003Smrg	}
61475ffd6003Smrg    }
61485ffd6003Smrg  XFREE (tmp_pathspec);
6149145b7b3cSmrg
61505ffd6003Smrg  if (!has_symlinks)
61515ffd6003Smrg    {
61525ffd6003Smrg      return xstrdup (pathspec);
61535ffd6003Smrg    }
6154145b7b3cSmrg
61555ffd6003Smrg  tmp_pathspec = realpath (pathspec, buf);
61565ffd6003Smrg  if (tmp_pathspec == 0)
61575ffd6003Smrg    {
6158629baa8cSmrg      lt_fatal (__FILE__, __LINE__,
6159629baa8cSmrg		"could not follow symlinks for %s", pathspec);
61605ffd6003Smrg    }
61615ffd6003Smrg  return xstrdup (tmp_pathspec);
61625ffd6003Smrg#endif
61635ffd6003Smrg}
6164145b7b3cSmrg
61655ffd6003Smrgchar *
61665ffd6003Smrgstrendzap (char *str, const char *pat)
61675ffd6003Smrg{
61685ffd6003Smrg  size_t len, patlen;
6169145b7b3cSmrg
61705ffd6003Smrg  assert (str != NULL);
61715ffd6003Smrg  assert (pat != NULL);
6172145b7b3cSmrg
61735ffd6003Smrg  len = strlen (str);
61745ffd6003Smrg  patlen = strlen (pat);
6175145b7b3cSmrg
61765ffd6003Smrg  if (patlen <= len)
61775ffd6003Smrg    {
61785ffd6003Smrg      str += len - patlen;
6179b7d26471Smrg      if (STREQ (str, pat))
61805ffd6003Smrg	*str = '\0';
61815ffd6003Smrg    }
61825ffd6003Smrg  return str;
61835ffd6003Smrg}
6184145b7b3cSmrg
6185629baa8cSmrgvoid
6186629baa8cSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6187629baa8cSmrg{
6188629baa8cSmrg  va_list args;
6189629baa8cSmrg  if (lt_debug)
6190629baa8cSmrg    {
6191629baa8cSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6192629baa8cSmrg      va_start (args, fmt);
6193629baa8cSmrg      (void) vfprintf (stderr, fmt, args);
6194629baa8cSmrg      va_end (args);
6195629baa8cSmrg    }
6196629baa8cSmrg}
6197629baa8cSmrg
61985ffd6003Smrgstatic void
6199629baa8cSmrglt_error_core (int exit_status, const char *file,
6200629baa8cSmrg	       int line, const char *mode,
62015ffd6003Smrg	       const char *message, va_list ap)
62025ffd6003Smrg{
6203629baa8cSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
62045ffd6003Smrg  vfprintf (stderr, message, ap);
62055ffd6003Smrg  fprintf (stderr, ".\n");
6206145b7b3cSmrg
62075ffd6003Smrg  if (exit_status >= 0)
62085ffd6003Smrg    exit (exit_status);
62095ffd6003Smrg}
6210145b7b3cSmrg
62115ffd6003Smrgvoid
6212629baa8cSmrglt_fatal (const char *file, int line, const char *message, ...)
62135ffd6003Smrg{
62145ffd6003Smrg  va_list ap;
62155ffd6003Smrg  va_start (ap, message);
6216629baa8cSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
62175ffd6003Smrg  va_end (ap);
62185ffd6003Smrg}
6219145b7b3cSmrg
6220629baa8cSmrgstatic const char *
6221629baa8cSmrgnonnull (const char *s)
6222629baa8cSmrg{
6223629baa8cSmrg  return s ? s : "(null)";
6224629baa8cSmrg}
6225629baa8cSmrg
6226629baa8cSmrgstatic const char *
6227629baa8cSmrgnonempty (const char *s)
6228629baa8cSmrg{
6229629baa8cSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6230629baa8cSmrg}
6231629baa8cSmrg
62325ffd6003Smrgvoid
62335ffd6003Smrglt_setenv (const char *name, const char *value)
62345ffd6003Smrg{
6235629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6236629baa8cSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6237629baa8cSmrg                  nonnull (name), nonnull (value));
62385ffd6003Smrg  {
62395ffd6003Smrg#ifdef HAVE_SETENV
62405ffd6003Smrg    /* always make a copy, for consistency with !HAVE_SETENV */
62415ffd6003Smrg    char *str = xstrdup (value);
62425ffd6003Smrg    setenv (name, str, 1);
62435ffd6003Smrg#else
6244b7d26471Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
62455ffd6003Smrg    char *str = XMALLOC (char, len);
62465ffd6003Smrg    sprintf (str, "%s=%s", name, value);
62475ffd6003Smrg    if (putenv (str) != EXIT_SUCCESS)
62485ffd6003Smrg      {
62495ffd6003Smrg        XFREE (str);
62505ffd6003Smrg      }
62515ffd6003Smrg#endif
62525ffd6003Smrg  }
62535ffd6003Smrg}
6254145b7b3cSmrg
62555ffd6003Smrgchar *
62565ffd6003Smrglt_extend_str (const char *orig_value, const char *add, int to_end)
62575ffd6003Smrg{
62585ffd6003Smrg  char *new_value;
62595ffd6003Smrg  if (orig_value && *orig_value)
62605ffd6003Smrg    {
6261b7d26471Smrg      size_t orig_value_len = strlen (orig_value);
6262b7d26471Smrg      size_t add_len = strlen (add);
62635ffd6003Smrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
62645ffd6003Smrg      if (to_end)
62655ffd6003Smrg        {
62665ffd6003Smrg          strcpy (new_value, orig_value);
62675ffd6003Smrg          strcpy (new_value + orig_value_len, add);
62685ffd6003Smrg        }
62695ffd6003Smrg      else
62705ffd6003Smrg        {
62715ffd6003Smrg          strcpy (new_value, add);
62725ffd6003Smrg          strcpy (new_value + add_len, orig_value);
62735ffd6003Smrg        }
62745ffd6003Smrg    }
62755ffd6003Smrg  else
62765ffd6003Smrg    {
62775ffd6003Smrg      new_value = xstrdup (add);
62785ffd6003Smrg    }
62795ffd6003Smrg  return new_value;
62805ffd6003Smrg}
6281145b7b3cSmrg
62825ffd6003Smrgvoid
62835ffd6003Smrglt_update_exe_path (const char *name, const char *value)
62845ffd6003Smrg{
6285629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6286629baa8cSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6287629baa8cSmrg                  nonnull (name), nonnull (value));
6288145b7b3cSmrg
62895ffd6003Smrg  if (name && *name && value && *value)
62905ffd6003Smrg    {
62915ffd6003Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
62925ffd6003Smrg      /* some systems can't cope with a ':'-terminated path #' */
6293b7d26471Smrg      size_t len = strlen (new_value);
6294b7d26471Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
62955ffd6003Smrg        {
6296b7d26471Smrg          new_value[--len] = '\0';
62975ffd6003Smrg        }
62985ffd6003Smrg      lt_setenv (name, new_value);
62995ffd6003Smrg      XFREE (new_value);
63005ffd6003Smrg    }
63015ffd6003Smrg}
6302145b7b3cSmrg
63035ffd6003Smrgvoid
63045ffd6003Smrglt_update_lib_path (const char *name, const char *value)
63055ffd6003Smrg{
6306629baa8cSmrg  lt_debugprintf (__FILE__, __LINE__,
6307629baa8cSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6308629baa8cSmrg                  nonnull (name), nonnull (value));
6309145b7b3cSmrg
63105ffd6003Smrg  if (name && *name && value && *value)
63115ffd6003Smrg    {
63125ffd6003Smrg      char *new_value = lt_extend_str (getenv (name), value, 0);
63135ffd6003Smrg      lt_setenv (name, new_value);
63145ffd6003Smrg      XFREE (new_value);
63155ffd6003Smrg    }
63165ffd6003Smrg}
6317145b7b3cSmrg
6318629baa8cSmrgEOF
6319629baa8cSmrg	    case $host_os in
6320629baa8cSmrg	      mingw*)
6321629baa8cSmrg		cat <<"EOF"
6322629baa8cSmrg
6323629baa8cSmrg/* Prepares an argument vector before calling spawn().
6324629baa8cSmrg   Note that spawn() does not by itself call the command interpreter
6325629baa8cSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6326629baa8cSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6327629baa8cSmrg         GetVersionEx(&v);
6328629baa8cSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6329629baa8cSmrg      }) ? "cmd.exe" : "command.com").
6330629baa8cSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6331629baa8cSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6332629baa8cSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6333629baa8cSmrg   special way:
6334629baa8cSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6335629baa8cSmrg     delimiters if they are surrounded by double quotes: "...".
6336629baa8cSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6337629baa8cSmrg     that within double quotes, space and tab are treated like normal
6338629baa8cSmrg     characters.
6339629baa8cSmrg   - Backslashes not followed by double quotes are not special.
6340629baa8cSmrg   - But 2*n+1 backslashes followed by a double quote become
6341629baa8cSmrg     n backslashes followed by a double quote (n >= 0):
6342629baa8cSmrg       \" -> "
6343629baa8cSmrg       \\\" -> \"
6344629baa8cSmrg       \\\\\" -> \\"
6345629baa8cSmrg */
6346629baa8cSmrg#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"
6347629baa8cSmrg#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"
6348629baa8cSmrgchar **
6349629baa8cSmrgprepare_spawn (char **argv)
6350629baa8cSmrg{
6351629baa8cSmrg  size_t argc;
6352629baa8cSmrg  char **new_argv;
6353629baa8cSmrg  size_t i;
6354629baa8cSmrg
6355629baa8cSmrg  /* Count number of arguments.  */
6356629baa8cSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6357629baa8cSmrg    ;
6358629baa8cSmrg
6359629baa8cSmrg  /* Allocate new argument vector.  */
6360629baa8cSmrg  new_argv = XMALLOC (char *, argc + 1);
6361629baa8cSmrg
6362629baa8cSmrg  /* Put quoted arguments into the new argument vector.  */
6363629baa8cSmrg  for (i = 0; i < argc; i++)
6364629baa8cSmrg    {
6365629baa8cSmrg      const char *string = argv[i];
6366629baa8cSmrg
6367629baa8cSmrg      if (string[0] == '\0')
6368629baa8cSmrg	new_argv[i] = xstrdup ("\"\"");
6369629baa8cSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6370629baa8cSmrg	{
6371629baa8cSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6372629baa8cSmrg	  size_t length;
6373629baa8cSmrg	  unsigned int backslashes;
6374629baa8cSmrg	  const char *s;
6375629baa8cSmrg	  char *quoted_string;
6376629baa8cSmrg	  char *p;
6377629baa8cSmrg
6378629baa8cSmrg	  length = 0;
6379629baa8cSmrg	  backslashes = 0;
6380629baa8cSmrg	  if (quote_around)
6381629baa8cSmrg	    length++;
6382629baa8cSmrg	  for (s = string; *s != '\0'; s++)
6383629baa8cSmrg	    {
6384629baa8cSmrg	      char c = *s;
6385629baa8cSmrg	      if (c == '"')
6386629baa8cSmrg		length += backslashes + 1;
6387629baa8cSmrg	      length++;
6388629baa8cSmrg	      if (c == '\\')
6389629baa8cSmrg		backslashes++;
6390629baa8cSmrg	      else
6391629baa8cSmrg		backslashes = 0;
6392629baa8cSmrg	    }
6393629baa8cSmrg	  if (quote_around)
6394629baa8cSmrg	    length += backslashes + 1;
6395629baa8cSmrg
6396629baa8cSmrg	  quoted_string = XMALLOC (char, length + 1);
6397629baa8cSmrg
6398629baa8cSmrg	  p = quoted_string;
6399629baa8cSmrg	  backslashes = 0;
6400629baa8cSmrg	  if (quote_around)
6401629baa8cSmrg	    *p++ = '"';
6402629baa8cSmrg	  for (s = string; *s != '\0'; s++)
6403629baa8cSmrg	    {
6404629baa8cSmrg	      char c = *s;
6405629baa8cSmrg	      if (c == '"')
6406629baa8cSmrg		{
6407629baa8cSmrg		  unsigned int j;
6408629baa8cSmrg		  for (j = backslashes + 1; j > 0; j--)
6409629baa8cSmrg		    *p++ = '\\';
6410629baa8cSmrg		}
6411629baa8cSmrg	      *p++ = c;
6412629baa8cSmrg	      if (c == '\\')
6413629baa8cSmrg		backslashes++;
6414629baa8cSmrg	      else
6415629baa8cSmrg		backslashes = 0;
6416629baa8cSmrg	    }
6417629baa8cSmrg	  if (quote_around)
6418629baa8cSmrg	    {
6419629baa8cSmrg	      unsigned int j;
6420629baa8cSmrg	      for (j = backslashes; j > 0; j--)
6421629baa8cSmrg		*p++ = '\\';
6422629baa8cSmrg	      *p++ = '"';
6423629baa8cSmrg	    }
6424629baa8cSmrg	  *p = '\0';
6425629baa8cSmrg
6426629baa8cSmrg	  new_argv[i] = quoted_string;
6427629baa8cSmrg	}
6428629baa8cSmrg      else
6429629baa8cSmrg	new_argv[i] = (char *) string;
6430629baa8cSmrg    }
6431629baa8cSmrg  new_argv[argc] = NULL;
6432629baa8cSmrg
6433629baa8cSmrg  return new_argv;
6434629baa8cSmrg}
6435629baa8cSmrgEOF
6436629baa8cSmrg		;;
6437629baa8cSmrg	    esac
6438629baa8cSmrg
6439629baa8cSmrg            cat <<"EOF"
6440629baa8cSmrgvoid lt_dump_script (FILE* f)
6441629baa8cSmrg{
6442629baa8cSmrgEOF
6443629baa8cSmrg	    func_emit_wrapper yes |
6444b7d26471Smrg	      $SED -n -e '
6445b7d26471Smrgs/^\(.\{79\}\)\(..*\)/\1\
6446b7d26471Smrg\2/
6447b7d26471Smrgh
6448b7d26471Smrgs/\([\\"]\)/\\\1/g
6449b7d26471Smrgs/$/\\n/
6450b7d26471Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6451b7d26471Smrgg
6452b7d26471SmrgD'
6453629baa8cSmrg            cat <<"EOF"
6454629baa8cSmrg}
64555ffd6003SmrgEOF
64565ffd6003Smrg}
64575ffd6003Smrg# end: func_emit_cwrapperexe_src
6458145b7b3cSmrg
6459629baa8cSmrg# func_win32_import_lib_p ARG
6460629baa8cSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6461629baa8cSmrgfunc_win32_import_lib_p ()
6462629baa8cSmrg{
6463b7d26471Smrg    $debug_cmd
6464b7d26471Smrg
6465629baa8cSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6466629baa8cSmrg    *import*) : ;;
6467629baa8cSmrg    *) false ;;
6468629baa8cSmrg    esac
6469629baa8cSmrg}
6470629baa8cSmrg
6471b7d26471Smrg# func_suncc_cstd_abi
6472b7d26471Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6473b7d26471Smrg# Several compiler flags select an ABI that is incompatible with the
6474b7d26471Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6475b7d26471Smrgfunc_suncc_cstd_abi ()
6476b7d26471Smrg{
6477b7d26471Smrg    $debug_cmd
6478b7d26471Smrg
6479b7d26471Smrg    case " $compile_command " in
6480b7d26471Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6481b7d26471Smrg      suncc_use_cstd_abi=no
6482b7d26471Smrg      ;;
6483b7d26471Smrg    *)
6484b7d26471Smrg      suncc_use_cstd_abi=yes
6485b7d26471Smrg      ;;
6486b7d26471Smrg    esac
6487b7d26471Smrg}
6488b7d26471Smrg
64895ffd6003Smrg# func_mode_link arg...
64905ffd6003Smrgfunc_mode_link ()
64915ffd6003Smrg{
6492b7d26471Smrg    $debug_cmd
6493b7d26471Smrg
64945ffd6003Smrg    case $host in
64955ffd6003Smrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
64965ffd6003Smrg      # It is impossible to link a dll without this setting, and
64975ffd6003Smrg      # we shouldn't force the makefile maintainer to figure out
6498b7d26471Smrg      # what system we are compiling for in order to pass an extra
64995ffd6003Smrg      # flag for every libtool invocation.
65005ffd6003Smrg      # allow_undefined=no
6501145b7b3cSmrg
65025ffd6003Smrg      # FIXME: Unfortunately, there are problems with the above when trying
6503b7d26471Smrg      # to make a dll that has undefined symbols, in which case not
65045ffd6003Smrg      # even a static library is built.  For now, we need to specify
65055ffd6003Smrg      # -no-undefined on the libtool link line when we can be certain
65065ffd6003Smrg      # that all symbols are satisfied, otherwise we get a static library.
65075ffd6003Smrg      allow_undefined=yes
65085ffd6003Smrg      ;;
65095ffd6003Smrg    *)
65105ffd6003Smrg      allow_undefined=yes
65115ffd6003Smrg      ;;
65125ffd6003Smrg    esac
65135ffd6003Smrg    libtool_args=$nonopt
65145ffd6003Smrg    base_compile="$nonopt $@"
65155ffd6003Smrg    compile_command=$nonopt
65165ffd6003Smrg    finalize_command=$nonopt
6517145b7b3cSmrg
65185ffd6003Smrg    compile_rpath=
65195ffd6003Smrg    finalize_rpath=
65205ffd6003Smrg    compile_shlibpath=
65215ffd6003Smrg    finalize_shlibpath=
65225ffd6003Smrg    convenience=
65235ffd6003Smrg    old_convenience=
65245ffd6003Smrg    deplibs=
65255ffd6003Smrg    old_deplibs=
65265ffd6003Smrg    compiler_flags=
65275ffd6003Smrg    linker_flags=
65285ffd6003Smrg    dllsearchpath=
65295ffd6003Smrg    lib_search_path=`pwd`
65305ffd6003Smrg    inst_prefix_dir=
65315ffd6003Smrg    new_inherited_linker_flags=
6532145b7b3cSmrg
65335ffd6003Smrg    avoid_version=no
6534629baa8cSmrg    bindir=
65355ffd6003Smrg    dlfiles=
65365ffd6003Smrg    dlprefiles=
65375ffd6003Smrg    dlself=no
65385ffd6003Smrg    export_dynamic=no
65395ffd6003Smrg    export_symbols=
65405ffd6003Smrg    export_symbols_regex=
65415ffd6003Smrg    generated=
65425ffd6003Smrg    libobjs=
65435ffd6003Smrg    ltlibs=
65445ffd6003Smrg    module=no
65455ffd6003Smrg    no_install=no
65465ffd6003Smrg    objs=
6547b7d26471Smrg    os2dllname=
65485ffd6003Smrg    non_pic_objects=
65495ffd6003Smrg    precious_files_regex=
65505ffd6003Smrg    prefer_static_libs=no
6551b7d26471Smrg    preload=false
65525ffd6003Smrg    prev=
65535ffd6003Smrg    prevarg=
65545ffd6003Smrg    release=
65555ffd6003Smrg    rpath=
65565ffd6003Smrg    xrpath=
65575ffd6003Smrg    perm_rpath=
65585ffd6003Smrg    temp_rpath=
65595ffd6003Smrg    thread_safe=no
65605ffd6003Smrg    vinfo=
65615ffd6003Smrg    vinfo_number=no
65625ffd6003Smrg    weak_libs=
6563b7d26471Smrg    single_module=$wl-single_module
65645ffd6003Smrg    func_infer_tag $base_compile
65655ffd6003Smrg
65665ffd6003Smrg    # We need to know -static, to get the right output filenames.
65675ffd6003Smrg    for arg
65685ffd6003Smrg    do
65695ffd6003Smrg      case $arg in
65705ffd6003Smrg      -shared)
6571b7d26471Smrg	test yes != "$build_libtool_libs" \
6572b7d26471Smrg	  && func_fatal_configuration "cannot build a shared library"
65735ffd6003Smrg	build_old_libs=no
65745ffd6003Smrg	break
65755ffd6003Smrg	;;
65765ffd6003Smrg      -all-static | -static | -static-libtool-libs)
65775ffd6003Smrg	case $arg in
65785ffd6003Smrg	-all-static)
6579b7d26471Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
65805ffd6003Smrg	    func_warning "complete static linking is impossible in this configuration"
65815ffd6003Smrg	  fi
65825ffd6003Smrg	  if test -n "$link_static_flag"; then
65835ffd6003Smrg	    dlopen_self=$dlopen_self_static
65845ffd6003Smrg	  fi
65855ffd6003Smrg	  prefer_static_libs=yes
65865ffd6003Smrg	  ;;
65875ffd6003Smrg	-static)
65885ffd6003Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
65895ffd6003Smrg	    dlopen_self=$dlopen_self_static
6590145b7b3cSmrg	  fi
65915ffd6003Smrg	  prefer_static_libs=built
65925ffd6003Smrg	  ;;
65935ffd6003Smrg	-static-libtool-libs)
65945ffd6003Smrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
65955ffd6003Smrg	    dlopen_self=$dlopen_self_static
65965ffd6003Smrg	  fi
65975ffd6003Smrg	  prefer_static_libs=yes
65985ffd6003Smrg	  ;;
65995ffd6003Smrg	esac
66005ffd6003Smrg	build_libtool_libs=no
66015ffd6003Smrg	build_old_libs=yes
66025ffd6003Smrg	break
66035ffd6003Smrg	;;
66045ffd6003Smrg      esac
66055ffd6003Smrg    done
6606145b7b3cSmrg
66075ffd6003Smrg    # See if our shared archives depend on static archives.
66085ffd6003Smrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6609145b7b3cSmrg
66105ffd6003Smrg    # Go through the arguments, transforming them on the way.
66115ffd6003Smrg    while test "$#" -gt 0; do
6612b7d26471Smrg      arg=$1
66135ffd6003Smrg      shift
66145ffd6003Smrg      func_quote_for_eval "$arg"
66155ffd6003Smrg      qarg=$func_quote_for_eval_unquoted_result
66165ffd6003Smrg      func_append libtool_args " $func_quote_for_eval_result"
6617145b7b3cSmrg
66185ffd6003Smrg      # If the previous option needs an argument, assign it.
66195ffd6003Smrg      if test -n "$prev"; then
66205ffd6003Smrg	case $prev in
66215ffd6003Smrg	output)
66225ffd6003Smrg	  func_append compile_command " @OUTPUT@"
66235ffd6003Smrg	  func_append finalize_command " @OUTPUT@"
66245ffd6003Smrg	  ;;
66255ffd6003Smrg	esac
6626145b7b3cSmrg
66275ffd6003Smrg	case $prev in
6628629baa8cSmrg	bindir)
6629b7d26471Smrg	  bindir=$arg
6630629baa8cSmrg	  prev=
6631629baa8cSmrg	  continue
6632629baa8cSmrg	  ;;
66335ffd6003Smrg	dlfiles|dlprefiles)
6634b7d26471Smrg	  $preload || {
66355ffd6003Smrg	    # Add the symbol object into the linking commands.
66365ffd6003Smrg	    func_append compile_command " @SYMFILE@"
66375ffd6003Smrg	    func_append finalize_command " @SYMFILE@"
6638b7d26471Smrg	    preload=:
6639b7d26471Smrg	  }
66405ffd6003Smrg	  case $arg in
66415ffd6003Smrg	  *.la | *.lo) ;;  # We handle these cases below.
66425ffd6003Smrg	  force)
6643b7d26471Smrg	    if test no = "$dlself"; then
66445ffd6003Smrg	      dlself=needless
66455ffd6003Smrg	      export_dynamic=yes
66465ffd6003Smrg	    fi
66475ffd6003Smrg	    prev=
66485ffd6003Smrg	    continue
66495ffd6003Smrg	    ;;
66505ffd6003Smrg	  self)
6651b7d26471Smrg	    if test dlprefiles = "$prev"; then
66525ffd6003Smrg	      dlself=yes
6653b7d26471Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
66545ffd6003Smrg	      dlself=yes
6655145b7b3cSmrg	    else
66565ffd6003Smrg	      dlself=needless
66575ffd6003Smrg	      export_dynamic=yes
6658145b7b3cSmrg	    fi
66595ffd6003Smrg	    prev=
66605ffd6003Smrg	    continue
66615ffd6003Smrg	    ;;
66625ffd6003Smrg	  *)
6663b7d26471Smrg	    if test dlfiles = "$prev"; then
6664629baa8cSmrg	      func_append dlfiles " $arg"
6665145b7b3cSmrg	    else
6666629baa8cSmrg	      func_append dlprefiles " $arg"
6667145b7b3cSmrg	    fi
66685ffd6003Smrg	    prev=
66695ffd6003Smrg	    continue
66705ffd6003Smrg	    ;;
66715ffd6003Smrg	  esac
66725ffd6003Smrg	  ;;
66735ffd6003Smrg	expsyms)
6674b7d26471Smrg	  export_symbols=$arg
66755ffd6003Smrg	  test -f "$arg" \
6676b7d26471Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
66775ffd6003Smrg	  prev=
66785ffd6003Smrg	  continue
66795ffd6003Smrg	  ;;
66805ffd6003Smrg	expsyms_regex)
6681b7d26471Smrg	  export_symbols_regex=$arg
66825ffd6003Smrg	  prev=
66835ffd6003Smrg	  continue
66845ffd6003Smrg	  ;;
66855ffd6003Smrg	framework)
66865ffd6003Smrg	  case $host in
66875ffd6003Smrg	    *-*-darwin*)
66885ffd6003Smrg	      case "$deplibs " in
66895ffd6003Smrg		*" $qarg.ltframework "*) ;;
6690629baa8cSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
66915ffd6003Smrg		   ;;
66925ffd6003Smrg	      esac
6693145b7b3cSmrg	      ;;
66945ffd6003Smrg	  esac
66955ffd6003Smrg	  prev=
66965ffd6003Smrg	  continue
66975ffd6003Smrg	  ;;
66985ffd6003Smrg	inst_prefix)
6699b7d26471Smrg	  inst_prefix_dir=$arg
6700b7d26471Smrg	  prev=
6701b7d26471Smrg	  continue
6702b7d26471Smrg	  ;;
6703b7d26471Smrg	mllvm)
6704b7d26471Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6705b7d26471Smrg	  # '-mllvm $arg' options when doing the link step.
67065ffd6003Smrg	  prev=
67075ffd6003Smrg	  continue
67085ffd6003Smrg	  ;;
67095ffd6003Smrg	objectlist)
67105ffd6003Smrg	  if test -f "$arg"; then
67115ffd6003Smrg	    save_arg=$arg
67125ffd6003Smrg	    moreargs=
67135ffd6003Smrg	    for fil in `cat "$save_arg"`
67145ffd6003Smrg	    do
6715629baa8cSmrg#	      func_append moreargs " $fil"
67165ffd6003Smrg	      arg=$fil
67175ffd6003Smrg	      # A libtool-controlled object.
6718145b7b3cSmrg
67195ffd6003Smrg	      # Check to see that this really is a libtool object.
67205ffd6003Smrg	      if func_lalib_unsafe_p "$arg"; then
67215ffd6003Smrg		pic_object=
67225ffd6003Smrg		non_pic_object=
6723145b7b3cSmrg
67245ffd6003Smrg		# Read the .lo file
67255ffd6003Smrg		func_source "$arg"
6726145b7b3cSmrg
67275ffd6003Smrg		if test -z "$pic_object" ||
67285ffd6003Smrg		   test -z "$non_pic_object" ||
6729b7d26471Smrg		   test none = "$pic_object" &&
6730b7d26471Smrg		   test none = "$non_pic_object"; then
6731b7d26471Smrg		  func_fatal_error "cannot find name of object for '$arg'"
67325ffd6003Smrg		fi
6733145b7b3cSmrg
67345ffd6003Smrg		# Extract subdirectory from the argument.
67355ffd6003Smrg		func_dirname "$arg" "/" ""
6736b7d26471Smrg		xdir=$func_dirname_result
6737145b7b3cSmrg
6738b7d26471Smrg		if test none != "$pic_object"; then
67395ffd6003Smrg		  # Prepend the subdirectory the object is found in.
6740b7d26471Smrg		  pic_object=$xdir$pic_object
6741145b7b3cSmrg
6742b7d26471Smrg		  if test dlfiles = "$prev"; then
6743b7d26471Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
6744629baa8cSmrg		      func_append dlfiles " $pic_object"
67455ffd6003Smrg		      prev=
67465ffd6003Smrg		      continue
67475ffd6003Smrg		    else
67485ffd6003Smrg		      # If libtool objects are unsupported, then we need to preload.
67495ffd6003Smrg		      prev=dlprefiles
67505ffd6003Smrg		    fi
67515ffd6003Smrg		  fi
6752145b7b3cSmrg
67535ffd6003Smrg		  # CHECK ME:  I think I busted this.  -Ossama
6754b7d26471Smrg		  if test dlprefiles = "$prev"; then
67555ffd6003Smrg		    # Preload the old-style object.
6756629baa8cSmrg		    func_append dlprefiles " $pic_object"
67575ffd6003Smrg		    prev=
67585ffd6003Smrg		  fi
6759145b7b3cSmrg
67605ffd6003Smrg		  # A PIC object.
67615ffd6003Smrg		  func_append libobjs " $pic_object"
6762b7d26471Smrg		  arg=$pic_object
67635ffd6003Smrg		fi
6764145b7b3cSmrg
67655ffd6003Smrg		# Non-PIC object.
6766b7d26471Smrg		if test none != "$non_pic_object"; then
67675ffd6003Smrg		  # Prepend the subdirectory the object is found in.
6768b7d26471Smrg		  non_pic_object=$xdir$non_pic_object
6769145b7b3cSmrg
67705ffd6003Smrg		  # A standard non-PIC object
67715ffd6003Smrg		  func_append non_pic_objects " $non_pic_object"
6772b7d26471Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
6773b7d26471Smrg		    arg=$non_pic_object
67745ffd6003Smrg		  fi
67755ffd6003Smrg		else
67765ffd6003Smrg		  # If the PIC object exists, use it instead.
67775ffd6003Smrg		  # $xdir was prepended to $pic_object above.
6778b7d26471Smrg		  non_pic_object=$pic_object
67795ffd6003Smrg		  func_append non_pic_objects " $non_pic_object"
67805ffd6003Smrg		fi
67815ffd6003Smrg	      else
67825ffd6003Smrg		# Only an error if not doing a dry-run.
67835ffd6003Smrg		if $opt_dry_run; then
67845ffd6003Smrg		  # Extract subdirectory from the argument.
67855ffd6003Smrg		  func_dirname "$arg" "/" ""
6786b7d26471Smrg		  xdir=$func_dirname_result
67875ffd6003Smrg
67885ffd6003Smrg		  func_lo2o "$arg"
67895ffd6003Smrg		  pic_object=$xdir$objdir/$func_lo2o_result
67905ffd6003Smrg		  non_pic_object=$xdir$func_lo2o_result
67915ffd6003Smrg		  func_append libobjs " $pic_object"
67925ffd6003Smrg		  func_append non_pic_objects " $non_pic_object"
67935ffd6003Smrg	        else
6794b7d26471Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
67955ffd6003Smrg		fi
67965ffd6003Smrg	      fi
67975ffd6003Smrg	    done
67985ffd6003Smrg	  else
6799b7d26471Smrg	    func_fatal_error "link input file '$arg' does not exist"
68005ffd6003Smrg	  fi
68015ffd6003Smrg	  arg=$save_arg
68025ffd6003Smrg	  prev=
68035ffd6003Smrg	  continue
68045ffd6003Smrg	  ;;
6805b7d26471Smrg	os2dllname)
6806b7d26471Smrg	  os2dllname=$arg
6807b7d26471Smrg	  prev=
6808b7d26471Smrg	  continue
6809b7d26471Smrg	  ;;
68105ffd6003Smrg	precious_regex)
6811b7d26471Smrg	  precious_files_regex=$arg
68125ffd6003Smrg	  prev=
68135ffd6003Smrg	  continue
68145ffd6003Smrg	  ;;
68155ffd6003Smrg	release)
6816b7d26471Smrg	  release=-$arg
68175ffd6003Smrg	  prev=
68185ffd6003Smrg	  continue
68195ffd6003Smrg	  ;;
68205ffd6003Smrg	rpath | xrpath)
68215ffd6003Smrg	  # We need an absolute path.
68225ffd6003Smrg	  case $arg in
68235ffd6003Smrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
68245ffd6003Smrg	  *)
68255ffd6003Smrg	    func_fatal_error "only absolute run-paths are allowed"
68265ffd6003Smrg	    ;;
68275ffd6003Smrg	  esac
6828b7d26471Smrg	  if test rpath = "$prev"; then
68295ffd6003Smrg	    case "$rpath " in
68305ffd6003Smrg	    *" $arg "*) ;;
6831629baa8cSmrg	    *) func_append rpath " $arg" ;;
68325ffd6003Smrg	    esac
68335ffd6003Smrg	  else
68345ffd6003Smrg	    case "$xrpath " in
68355ffd6003Smrg	    *" $arg "*) ;;
6836629baa8cSmrg	    *) func_append xrpath " $arg" ;;
68375ffd6003Smrg	    esac
68385ffd6003Smrg	  fi
68395ffd6003Smrg	  prev=
68405ffd6003Smrg	  continue
68415ffd6003Smrg	  ;;
68425ffd6003Smrg	shrext)
6843b7d26471Smrg	  shrext_cmds=$arg
68445ffd6003Smrg	  prev=
68455ffd6003Smrg	  continue
68465ffd6003Smrg	  ;;
68475ffd6003Smrg	weak)
6848629baa8cSmrg	  func_append weak_libs " $arg"
68495ffd6003Smrg	  prev=
68505ffd6003Smrg	  continue
68515ffd6003Smrg	  ;;
68525ffd6003Smrg	xcclinker)
6853629baa8cSmrg	  func_append linker_flags " $qarg"
6854629baa8cSmrg	  func_append compiler_flags " $qarg"
68555ffd6003Smrg	  prev=
68565ffd6003Smrg	  func_append compile_command " $qarg"
68575ffd6003Smrg	  func_append finalize_command " $qarg"
68585ffd6003Smrg	  continue
68595ffd6003Smrg	  ;;
68605ffd6003Smrg	xcompiler)
6861629baa8cSmrg	  func_append compiler_flags " $qarg"
68625ffd6003Smrg	  prev=
68635ffd6003Smrg	  func_append compile_command " $qarg"
68645ffd6003Smrg	  func_append finalize_command " $qarg"
68655ffd6003Smrg	  continue
68665ffd6003Smrg	  ;;
68675ffd6003Smrg	xlinker)
6868629baa8cSmrg	  func_append linker_flags " $qarg"
6869629baa8cSmrg	  func_append compiler_flags " $wl$qarg"
68705ffd6003Smrg	  prev=
68715ffd6003Smrg	  func_append compile_command " $wl$qarg"
68725ffd6003Smrg	  func_append finalize_command " $wl$qarg"
68735ffd6003Smrg	  continue
6874145b7b3cSmrg	  ;;
6875145b7b3cSmrg	*)
68765ffd6003Smrg	  eval "$prev=\"\$arg\""
68775ffd6003Smrg	  prev=
68785ffd6003Smrg	  continue
6879145b7b3cSmrg	  ;;
6880145b7b3cSmrg	esac
68815ffd6003Smrg      fi # test -n "$prev"
6882145b7b3cSmrg
6883b7d26471Smrg      prevarg=$arg
6884145b7b3cSmrg
68855ffd6003Smrg      case $arg in
68865ffd6003Smrg      -all-static)
68875ffd6003Smrg	if test -n "$link_static_flag"; then
68885ffd6003Smrg	  # See comment for -static flag below, for more details.
68895ffd6003Smrg	  func_append compile_command " $link_static_flag"
68905ffd6003Smrg	  func_append finalize_command " $link_static_flag"
6891145b7b3cSmrg	fi
68925ffd6003Smrg	continue
68935ffd6003Smrg	;;
6894145b7b3cSmrg
68955ffd6003Smrg      -allow-undefined)
68965ffd6003Smrg	# FIXME: remove this flag sometime in the future.
6897b7d26471Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
68985ffd6003Smrg	;;
6899145b7b3cSmrg
69005ffd6003Smrg      -avoid-version)
69015ffd6003Smrg	avoid_version=yes
69025ffd6003Smrg	continue
69035ffd6003Smrg	;;
6904145b7b3cSmrg
6905629baa8cSmrg      -bindir)
6906629baa8cSmrg	prev=bindir
6907629baa8cSmrg	continue
6908629baa8cSmrg	;;
6909629baa8cSmrg
69105ffd6003Smrg      -dlopen)
69115ffd6003Smrg	prev=dlfiles
69125ffd6003Smrg	continue
69135ffd6003Smrg	;;
6914145b7b3cSmrg
69155ffd6003Smrg      -dlpreopen)
69165ffd6003Smrg	prev=dlprefiles
69175ffd6003Smrg	continue
69185ffd6003Smrg	;;
6919145b7b3cSmrg
69205ffd6003Smrg      -export-dynamic)
69215ffd6003Smrg	export_dynamic=yes
69225ffd6003Smrg	continue
69235ffd6003Smrg	;;
6924145b7b3cSmrg
69255ffd6003Smrg      -export-symbols | -export-symbols-regex)
69265ffd6003Smrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
69275ffd6003Smrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
69285ffd6003Smrg	fi
6929b7d26471Smrg	if test X-export-symbols = "X$arg"; then
69305ffd6003Smrg	  prev=expsyms
6931145b7b3cSmrg	else
69325ffd6003Smrg	  prev=expsyms_regex
6933145b7b3cSmrg	fi
69345ffd6003Smrg	continue
69355ffd6003Smrg	;;
6936145b7b3cSmrg
69375ffd6003Smrg      -framework)
69385ffd6003Smrg	prev=framework
69395ffd6003Smrg	continue
69405ffd6003Smrg	;;
6941145b7b3cSmrg
69425ffd6003Smrg      -inst-prefix-dir)
69435ffd6003Smrg	prev=inst_prefix
69445ffd6003Smrg	continue
69455ffd6003Smrg	;;
6946145b7b3cSmrg
69475ffd6003Smrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
69485ffd6003Smrg      # so, if we see these flags be careful not to treat them like -L
69495ffd6003Smrg      -L[A-Z][A-Z]*:*)
69505ffd6003Smrg	case $with_gcc/$host in
69515ffd6003Smrg	no/*-*-irix* | /*-*-irix*)
69525ffd6003Smrg	  func_append compile_command " $arg"
69535ffd6003Smrg	  func_append finalize_command " $arg"
69545ffd6003Smrg	  ;;
69555ffd6003Smrg	esac
69565ffd6003Smrg	continue
69575ffd6003Smrg	;;
6958145b7b3cSmrg
69595ffd6003Smrg      -L*)
6960629baa8cSmrg	func_stripname "-L" '' "$arg"
6961629baa8cSmrg	if test -z "$func_stripname_result"; then
69625ffd6003Smrg	  if test "$#" -gt 0; then
6963b7d26471Smrg	    func_fatal_error "require no space between '-L' and '$1'"
6964145b7b3cSmrg	  else
6965b7d26471Smrg	    func_fatal_error "need path for '-L' option"
6966145b7b3cSmrg	  fi
69675ffd6003Smrg	fi
6968629baa8cSmrg	func_resolve_sysroot "$func_stripname_result"
6969629baa8cSmrg	dir=$func_resolve_sysroot_result
69705ffd6003Smrg	# We need an absolute path.
69715ffd6003Smrg	case $dir in
69725ffd6003Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
69735ffd6003Smrg	*)
69745ffd6003Smrg	  absdir=`cd "$dir" && pwd`
69755ffd6003Smrg	  test -z "$absdir" && \
6976b7d26471Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
6977b7d26471Smrg	  dir=$absdir
69785ffd6003Smrg	  ;;
6979145b7b3cSmrg	esac
69805ffd6003Smrg	case "$deplibs " in
6981629baa8cSmrg	*" -L$dir "* | *" $arg "*)
6982629baa8cSmrg	  # Will only happen for absolute or sysroot arguments
6983629baa8cSmrg	  ;;
69845ffd6003Smrg	*)
6985629baa8cSmrg	  # Preserve sysroot, but never include relative directories
6986629baa8cSmrg	  case $dir in
6987629baa8cSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
6988629baa8cSmrg	    *) func_append deplibs " -L$dir" ;;
6989629baa8cSmrg	  esac
6990629baa8cSmrg	  func_append lib_search_path " $dir"
69915ffd6003Smrg	  ;;
6992145b7b3cSmrg	esac
6993145b7b3cSmrg	case $host in
69945ffd6003Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6995629baa8cSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
69965ffd6003Smrg	  case :$dllsearchpath: in
69975ffd6003Smrg	  *":$dir:"*) ;;
69985ffd6003Smrg	  ::) dllsearchpath=$dir;;
6999629baa8cSmrg	  *) func_append dllsearchpath ":$dir";;
70005ffd6003Smrg	  esac
70015ffd6003Smrg	  case :$dllsearchpath: in
70025ffd6003Smrg	  *":$testbindir:"*) ;;
70035ffd6003Smrg	  ::) dllsearchpath=$testbindir;;
7004629baa8cSmrg	  *) func_append dllsearchpath ":$testbindir";;
70055ffd6003Smrg	  esac
70065ffd6003Smrg	  ;;
7007145b7b3cSmrg	esac
70085ffd6003Smrg	continue
70095ffd6003Smrg	;;
7010145b7b3cSmrg
70115ffd6003Smrg      -l*)
7012b7d26471Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
70135ffd6003Smrg	  case $host in
7014629baa8cSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
70155ffd6003Smrg	    # These systems don't actually have a C or math library (as such)
70165ffd6003Smrg	    continue
70175ffd6003Smrg	    ;;
70185ffd6003Smrg	  *-*-os2*)
70195ffd6003Smrg	    # These systems don't actually have a C library (as such)
7020b7d26471Smrg	    test X-lc = "X$arg" && continue
70215ffd6003Smrg	    ;;
7022b7d26471Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
70235ffd6003Smrg	    # Do not include libc due to us having libc/libc_r.
7024b7d26471Smrg	    test X-lc = "X$arg" && continue
70255ffd6003Smrg	    ;;
70265ffd6003Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
70275ffd6003Smrg	    # Rhapsody C and math libraries are in the System framework
7028629baa8cSmrg	    func_append deplibs " System.ltframework"
70295ffd6003Smrg	    continue
70305ffd6003Smrg	    ;;
70315ffd6003Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
70325ffd6003Smrg	    # Causes problems with __ctype
7033b7d26471Smrg	    test X-lc = "X$arg" && continue
70345ffd6003Smrg	    ;;
70355ffd6003Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
70365ffd6003Smrg	    # Compiler inserts libc in the correct place for threads to work
7037b7d26471Smrg	    test X-lc = "X$arg" && continue
70385ffd6003Smrg	    ;;
70395ffd6003Smrg	  esac
7040b7d26471Smrg	elif test X-lc_r = "X$arg"; then
70415ffd6003Smrg	 case $host in
7042b7d26471Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
70435ffd6003Smrg	   # Do not include libc_r directly, use -pthread flag.
70445ffd6003Smrg	   continue
70455ffd6003Smrg	   ;;
70465ffd6003Smrg	 esac
70475ffd6003Smrg	fi
7048629baa8cSmrg	func_append deplibs " $arg"
70495ffd6003Smrg	continue
70505ffd6003Smrg	;;
7051145b7b3cSmrg
7052b7d26471Smrg      -mllvm)
7053b7d26471Smrg	prev=mllvm
7054b7d26471Smrg	continue
7055b7d26471Smrg	;;
7056b7d26471Smrg
70575ffd6003Smrg      -module)
70585ffd6003Smrg	module=yes
70595ffd6003Smrg	continue
70605ffd6003Smrg	;;
7061145b7b3cSmrg
70625ffd6003Smrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
70635ffd6003Smrg      # classes, name mangling, and exception handling.
70645ffd6003Smrg      # Darwin uses the -arch flag to determine output architecture.
7065629baa8cSmrg      -model|-arch|-isysroot|--sysroot)
7066629baa8cSmrg	func_append compiler_flags " $arg"
70675ffd6003Smrg	func_append compile_command " $arg"
70685ffd6003Smrg	func_append finalize_command " $arg"
70695ffd6003Smrg	prev=xcompiler
70705ffd6003Smrg	continue
70715ffd6003Smrg	;;
7072145b7b3cSmrg
7073b7d26471Smrg      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7074b7d26471Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7075629baa8cSmrg	func_append compiler_flags " $arg"
70765ffd6003Smrg	func_append compile_command " $arg"
70775ffd6003Smrg	func_append finalize_command " $arg"
70785ffd6003Smrg	case "$new_inherited_linker_flags " in
70795ffd6003Smrg	    *" $arg "*) ;;
7080629baa8cSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
70815ffd6003Smrg	esac
70825ffd6003Smrg	continue
70835ffd6003Smrg	;;
7084145b7b3cSmrg
70855ffd6003Smrg      -multi_module)
7086b7d26471Smrg	single_module=$wl-multi_module
70875ffd6003Smrg	continue
70885ffd6003Smrg	;;
7089145b7b3cSmrg
70905ffd6003Smrg      -no-fast-install)
70915ffd6003Smrg	fast_install=no
70925ffd6003Smrg	continue
70935ffd6003Smrg	;;
7094145b7b3cSmrg
70955ffd6003Smrg      -no-install)
70965ffd6003Smrg	case $host in
70975ffd6003Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
70985ffd6003Smrg	  # The PATH hackery in wrapper scripts is required on Windows
70995ffd6003Smrg	  # and Darwin in order for the loader to find any dlls it needs.
7100b7d26471Smrg	  func_warning "'-no-install' is ignored for $host"
7101b7d26471Smrg	  func_warning "assuming '-no-fast-install' instead"
71025ffd6003Smrg	  fast_install=no
71035ffd6003Smrg	  ;;
71045ffd6003Smrg	*) no_install=yes ;;
71055ffd6003Smrg	esac
71065ffd6003Smrg	continue
71075ffd6003Smrg	;;
7108145b7b3cSmrg
71095ffd6003Smrg      -no-undefined)
71105ffd6003Smrg	allow_undefined=no
71115ffd6003Smrg	continue
71125ffd6003Smrg	;;
7113145b7b3cSmrg
71145ffd6003Smrg      -objectlist)
71155ffd6003Smrg	prev=objectlist
71165ffd6003Smrg	continue
71175ffd6003Smrg	;;
7118145b7b3cSmrg
7119b7d26471Smrg      -os2dllname)
7120b7d26471Smrg	prev=os2dllname
7121b7d26471Smrg	continue
7122b7d26471Smrg	;;
7123b7d26471Smrg
71245ffd6003Smrg      -o) prev=output ;;
7125145b7b3cSmrg
71265ffd6003Smrg      -precious-files-regex)
71275ffd6003Smrg	prev=precious_regex
71285ffd6003Smrg	continue
71295ffd6003Smrg	;;
7130145b7b3cSmrg
71315ffd6003Smrg      -release)
71325ffd6003Smrg	prev=release
71335ffd6003Smrg	continue
71345ffd6003Smrg	;;
7135145b7b3cSmrg
71365ffd6003Smrg      -rpath)
71375ffd6003Smrg	prev=rpath
71385ffd6003Smrg	continue
71395ffd6003Smrg	;;
7140145b7b3cSmrg
71415ffd6003Smrg      -R)
71425ffd6003Smrg	prev=xrpath
71435ffd6003Smrg	continue
71445ffd6003Smrg	;;
7145145b7b3cSmrg
71465ffd6003Smrg      -R*)
71475ffd6003Smrg	func_stripname '-R' '' "$arg"
71485ffd6003Smrg	dir=$func_stripname_result
71495ffd6003Smrg	# We need an absolute path.
71505ffd6003Smrg	case $dir in
71515ffd6003Smrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7152629baa8cSmrg	=*)
7153629baa8cSmrg	  func_stripname '=' '' "$dir"
7154629baa8cSmrg	  dir=$lt_sysroot$func_stripname_result
7155629baa8cSmrg	  ;;
71565ffd6003Smrg	*)
71575ffd6003Smrg	  func_fatal_error "only absolute run-paths are allowed"
71585ffd6003Smrg	  ;;
71595ffd6003Smrg	esac
71605ffd6003Smrg	case "$xrpath " in
71615ffd6003Smrg	*" $dir "*) ;;
7162629baa8cSmrg	*) func_append xrpath " $dir" ;;
71635ffd6003Smrg	esac
71645ffd6003Smrg	continue
71655ffd6003Smrg	;;
7166145b7b3cSmrg
71675ffd6003Smrg      -shared)
71685ffd6003Smrg	# The effects of -shared are defined in a previous loop.
71695ffd6003Smrg	continue
71705ffd6003Smrg	;;
7171145b7b3cSmrg
71725ffd6003Smrg      -shrext)
71735ffd6003Smrg	prev=shrext
71745ffd6003Smrg	continue
71755ffd6003Smrg	;;
7176145b7b3cSmrg
71775ffd6003Smrg      -static | -static-libtool-libs)
71785ffd6003Smrg	# The effects of -static are defined in a previous loop.
71795ffd6003Smrg	# We used to do the same as -all-static on platforms that
71805ffd6003Smrg	# didn't have a PIC flag, but the assumption that the effects
71815ffd6003Smrg	# would be equivalent was wrong.  It would break on at least
71825ffd6003Smrg	# Digital Unix and AIX.
71835ffd6003Smrg	continue
71845ffd6003Smrg	;;
7185145b7b3cSmrg
71865ffd6003Smrg      -thread-safe)
71875ffd6003Smrg	thread_safe=yes
71885ffd6003Smrg	continue
71895ffd6003Smrg	;;
7190145b7b3cSmrg
71915ffd6003Smrg      -version-info)
71925ffd6003Smrg	prev=vinfo
71935ffd6003Smrg	continue
71945ffd6003Smrg	;;
7195145b7b3cSmrg
71965ffd6003Smrg      -version-number)
71975ffd6003Smrg	prev=vinfo
71985ffd6003Smrg	vinfo_number=yes
71995ffd6003Smrg	continue
72005ffd6003Smrg	;;
7201145b7b3cSmrg
72025ffd6003Smrg      -weak)
72035ffd6003Smrg        prev=weak
72045ffd6003Smrg	continue
72055ffd6003Smrg	;;
7206145b7b3cSmrg
72075ffd6003Smrg      -Wc,*)
72085ffd6003Smrg	func_stripname '-Wc,' '' "$arg"
72095ffd6003Smrg	args=$func_stripname_result
72105ffd6003Smrg	arg=
7211b7d26471Smrg	save_ifs=$IFS; IFS=,
72125ffd6003Smrg	for flag in $args; do
7213b7d26471Smrg	  IFS=$save_ifs
72145ffd6003Smrg          func_quote_for_eval "$flag"
7215629baa8cSmrg	  func_append arg " $func_quote_for_eval_result"
7216629baa8cSmrg	  func_append compiler_flags " $func_quote_for_eval_result"
72175ffd6003Smrg	done
7218b7d26471Smrg	IFS=$save_ifs
72195ffd6003Smrg	func_stripname ' ' '' "$arg"
72205ffd6003Smrg	arg=$func_stripname_result
72215ffd6003Smrg	;;
7222145b7b3cSmrg
72235ffd6003Smrg      -Wl,*)
72245ffd6003Smrg	func_stripname '-Wl,' '' "$arg"
72255ffd6003Smrg	args=$func_stripname_result
72265ffd6003Smrg	arg=
7227b7d26471Smrg	save_ifs=$IFS; IFS=,
72285ffd6003Smrg	for flag in $args; do
7229b7d26471Smrg	  IFS=$save_ifs
72305ffd6003Smrg          func_quote_for_eval "$flag"
7231629baa8cSmrg	  func_append arg " $wl$func_quote_for_eval_result"
7232629baa8cSmrg	  func_append compiler_flags " $wl$func_quote_for_eval_result"
7233629baa8cSmrg	  func_append linker_flags " $func_quote_for_eval_result"
72345ffd6003Smrg	done
7235b7d26471Smrg	IFS=$save_ifs
72365ffd6003Smrg	func_stripname ' ' '' "$arg"
72375ffd6003Smrg	arg=$func_stripname_result
72385ffd6003Smrg	;;
7239145b7b3cSmrg
72405ffd6003Smrg      -Xcompiler)
72415ffd6003Smrg	prev=xcompiler
72425ffd6003Smrg	continue
72435ffd6003Smrg	;;
7244145b7b3cSmrg
72455ffd6003Smrg      -Xlinker)
72465ffd6003Smrg	prev=xlinker
72475ffd6003Smrg	continue
72485ffd6003Smrg	;;
7249145b7b3cSmrg
72505ffd6003Smrg      -XCClinker)
72515ffd6003Smrg	prev=xcclinker
72525ffd6003Smrg	continue
72535ffd6003Smrg	;;
7254145b7b3cSmrg
72555ffd6003Smrg      # -msg_* for osf cc
72565ffd6003Smrg      -msg_*)
72575ffd6003Smrg	func_quote_for_eval "$arg"
7258b7d26471Smrg	arg=$func_quote_for_eval_result
72595ffd6003Smrg	;;
7260145b7b3cSmrg
7261629baa8cSmrg      # Flags to be passed through unchanged, with rationale:
7262629baa8cSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7263629baa8cSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7264629baa8cSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7265629baa8cSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7266629baa8cSmrg      # -q*                  compiler args for the IBM compiler
7267629baa8cSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7268629baa8cSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7269629baa8cSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7270b7d26471Smrg      # -fstack-protector*   stack protector flags for GCC
7271629baa8cSmrg      # @file                GCC response files
7272629baa8cSmrg      # -tp=*                Portland pgcc target processor selection
7273629baa8cSmrg      # --sysroot=*          for sysroot support
7274b7d26471Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7275b7d26471Smrg      # -stdlib=*            select c++ std lib with clang
72765ffd6003Smrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7277629baa8cSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7278b7d26471Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*)
72795ffd6003Smrg        func_quote_for_eval "$arg"
7280b7d26471Smrg	arg=$func_quote_for_eval_result
72815ffd6003Smrg        func_append compile_command " $arg"
72825ffd6003Smrg        func_append finalize_command " $arg"
7283629baa8cSmrg        func_append compiler_flags " $arg"
72845ffd6003Smrg        continue
72855ffd6003Smrg        ;;
7286145b7b3cSmrg
7287b7d26471Smrg      -Z*)
7288b7d26471Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7289b7d26471Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7290b7d26471Smrg	  compiler_flags="$compiler_flags $arg"
7291b7d26471Smrg	  func_append compile_command " $arg"
7292b7d26471Smrg	  func_append finalize_command " $arg"
7293b7d26471Smrg	  case $arg in
7294b7d26471Smrg	  -Zlinker | -Zstack)
7295b7d26471Smrg	    prev=xcompiler
7296b7d26471Smrg	    ;;
7297b7d26471Smrg	  esac
7298b7d26471Smrg	  continue
7299b7d26471Smrg        else
7300b7d26471Smrg	  # Otherwise treat like 'Some other compiler flag' below
7301b7d26471Smrg	  func_quote_for_eval "$arg"
7302b7d26471Smrg	  arg=$func_quote_for_eval_result
7303b7d26471Smrg        fi
7304b7d26471Smrg	;;
7305b7d26471Smrg
73065ffd6003Smrg      # Some other compiler flag.
73075ffd6003Smrg      -* | +*)
73085ffd6003Smrg        func_quote_for_eval "$arg"
7309b7d26471Smrg	arg=$func_quote_for_eval_result
73105ffd6003Smrg	;;
7311145b7b3cSmrg
73125ffd6003Smrg      *.$objext)
73135ffd6003Smrg	# A standard object.
7314629baa8cSmrg	func_append objs " $arg"
73155ffd6003Smrg	;;
7316145b7b3cSmrg
73175ffd6003Smrg      *.lo)
73185ffd6003Smrg	# A libtool-controlled object.
7319145b7b3cSmrg
73205ffd6003Smrg	# Check to see that this really is a libtool object.
73215ffd6003Smrg	if func_lalib_unsafe_p "$arg"; then
73225ffd6003Smrg	  pic_object=
73235ffd6003Smrg	  non_pic_object=
7324145b7b3cSmrg
73255ffd6003Smrg	  # Read the .lo file
73265ffd6003Smrg	  func_source "$arg"
7327145b7b3cSmrg
73285ffd6003Smrg	  if test -z "$pic_object" ||
73295ffd6003Smrg	     test -z "$non_pic_object" ||
7330b7d26471Smrg	     test none = "$pic_object" &&
7331b7d26471Smrg	     test none = "$non_pic_object"; then
7332b7d26471Smrg	    func_fatal_error "cannot find name of object for '$arg'"
73335ffd6003Smrg	  fi
7334145b7b3cSmrg
73355ffd6003Smrg	  # Extract subdirectory from the argument.
73365ffd6003Smrg	  func_dirname "$arg" "/" ""
7337b7d26471Smrg	  xdir=$func_dirname_result
7338145b7b3cSmrg
7339b7d26471Smrg	  test none = "$pic_object" || {
73405ffd6003Smrg	    # Prepend the subdirectory the object is found in.
7341b7d26471Smrg	    pic_object=$xdir$pic_object
7342145b7b3cSmrg
7343b7d26471Smrg	    if test dlfiles = "$prev"; then
7344b7d26471Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7345629baa8cSmrg		func_append dlfiles " $pic_object"
73465ffd6003Smrg		prev=
73475ffd6003Smrg		continue
73485ffd6003Smrg	      else
73495ffd6003Smrg		# If libtool objects are unsupported, then we need to preload.
73505ffd6003Smrg		prev=dlprefiles
73515ffd6003Smrg	      fi
73525ffd6003Smrg	    fi
7353145b7b3cSmrg
73545ffd6003Smrg	    # CHECK ME:  I think I busted this.  -Ossama
7355b7d26471Smrg	    if test dlprefiles = "$prev"; then
73565ffd6003Smrg	      # Preload the old-style object.
7357629baa8cSmrg	      func_append dlprefiles " $pic_object"
73585ffd6003Smrg	      prev=
73595ffd6003Smrg	    fi
7360145b7b3cSmrg
73615ffd6003Smrg	    # A PIC object.
73625ffd6003Smrg	    func_append libobjs " $pic_object"
7363b7d26471Smrg	    arg=$pic_object
7364b7d26471Smrg	  }
7365145b7b3cSmrg
73665ffd6003Smrg	  # Non-PIC object.
7367b7d26471Smrg	  if test none != "$non_pic_object"; then
73685ffd6003Smrg	    # Prepend the subdirectory the object is found in.
7369b7d26471Smrg	    non_pic_object=$xdir$non_pic_object
7370145b7b3cSmrg
73715ffd6003Smrg	    # A standard non-PIC object
73725ffd6003Smrg	    func_append non_pic_objects " $non_pic_object"
7373b7d26471Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7374b7d26471Smrg	      arg=$non_pic_object
73755ffd6003Smrg	    fi
73765ffd6003Smrg	  else
73775ffd6003Smrg	    # If the PIC object exists, use it instead.
73785ffd6003Smrg	    # $xdir was prepended to $pic_object above.
7379b7d26471Smrg	    non_pic_object=$pic_object
73805ffd6003Smrg	    func_append non_pic_objects " $non_pic_object"
73815ffd6003Smrg	  fi
73825ffd6003Smrg	else
73835ffd6003Smrg	  # Only an error if not doing a dry-run.
73845ffd6003Smrg	  if $opt_dry_run; then
73855ffd6003Smrg	    # Extract subdirectory from the argument.
73865ffd6003Smrg	    func_dirname "$arg" "/" ""
7387b7d26471Smrg	    xdir=$func_dirname_result
73885ffd6003Smrg
73895ffd6003Smrg	    func_lo2o "$arg"
73905ffd6003Smrg	    pic_object=$xdir$objdir/$func_lo2o_result
73915ffd6003Smrg	    non_pic_object=$xdir$func_lo2o_result
73925ffd6003Smrg	    func_append libobjs " $pic_object"
73935ffd6003Smrg	    func_append non_pic_objects " $non_pic_object"
73945ffd6003Smrg	  else
7395b7d26471Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
73965ffd6003Smrg	  fi
73975ffd6003Smrg	fi
73985ffd6003Smrg	;;
7399145b7b3cSmrg
74005ffd6003Smrg      *.$libext)
74015ffd6003Smrg	# An archive.
7402629baa8cSmrg	func_append deplibs " $arg"
7403629baa8cSmrg	func_append old_deplibs " $arg"
74045ffd6003Smrg	continue
74055ffd6003Smrg	;;
7406578741aaSmrg
74075ffd6003Smrg      *.la)
74085ffd6003Smrg	# A libtool-controlled library.
7409145b7b3cSmrg
7410629baa8cSmrg	func_resolve_sysroot "$arg"
7411b7d26471Smrg	if test dlfiles = "$prev"; then
74125ffd6003Smrg	  # This library was specified with -dlopen.
7413629baa8cSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
74145ffd6003Smrg	  prev=
7415b7d26471Smrg	elif test dlprefiles = "$prev"; then
74165ffd6003Smrg	  # The library was specified with -dlpreopen.
7417629baa8cSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
74185ffd6003Smrg	  prev=
74195ffd6003Smrg	else
7420629baa8cSmrg	  func_append deplibs " $func_resolve_sysroot_result"
74215ffd6003Smrg	fi
74225ffd6003Smrg	continue
74235ffd6003Smrg	;;
7424145b7b3cSmrg
74255ffd6003Smrg      # Some other compiler argument.
74265ffd6003Smrg      *)
74275ffd6003Smrg	# Unknown arguments in both finalize_command and compile_command need
74285ffd6003Smrg	# to be aesthetically quoted because they are evaled later.
74295ffd6003Smrg	func_quote_for_eval "$arg"
7430b7d26471Smrg	arg=$func_quote_for_eval_result
74315ffd6003Smrg	;;
74325ffd6003Smrg      esac # arg
7433145b7b3cSmrg
74345ffd6003Smrg      # Now actually substitute the argument into the commands.
74355ffd6003Smrg      if test -n "$arg"; then
74365ffd6003Smrg	func_append compile_command " $arg"
74375ffd6003Smrg	func_append finalize_command " $arg"
74385ffd6003Smrg      fi
74395ffd6003Smrg    done # argument parsing loop
7440145b7b3cSmrg
74415ffd6003Smrg    test -n "$prev" && \
7442b7d26471Smrg      func_fatal_help "the '$prevarg' option requires an argument"
7443145b7b3cSmrg
7444b7d26471Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
74455ffd6003Smrg      eval arg=\"$export_dynamic_flag_spec\"
74465ffd6003Smrg      func_append compile_command " $arg"
74475ffd6003Smrg      func_append finalize_command " $arg"
7448145b7b3cSmrg    fi
7449145b7b3cSmrg
74505ffd6003Smrg    oldlibs=
74515ffd6003Smrg    # calculate the name of the file, without its directory
74525ffd6003Smrg    func_basename "$output"
7453b7d26471Smrg    outputname=$func_basename_result
7454b7d26471Smrg    libobjs_save=$libobjs
74555ffd6003Smrg
74565ffd6003Smrg    if test -n "$shlibpath_var"; then
74575ffd6003Smrg      # get the directories listed in $shlibpath_var
7458b7d26471Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
74595ffd6003Smrg    else
74605ffd6003Smrg      shlib_search_path=
74615ffd6003Smrg    fi
74625ffd6003Smrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
74635ffd6003Smrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
74645ffd6003Smrg
7465b7d26471Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7466b7d26471Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7467b7d26471Smrg
74685ffd6003Smrg    func_dirname "$output" "/" ""
7469b7d26471Smrg    output_objdir=$func_dirname_result$objdir
7470629baa8cSmrg    func_to_tool_file "$output_objdir/"
7471629baa8cSmrg    tool_output_objdir=$func_to_tool_file_result
74725ffd6003Smrg    # Create the object directory.
74735ffd6003Smrg    func_mkdir_p "$output_objdir"
74745ffd6003Smrg
74755ffd6003Smrg    # Determine the type of output
74765ffd6003Smrg    case $output in
74775ffd6003Smrg    "")
74785ffd6003Smrg      func_fatal_help "you must specify an output file"
74795ffd6003Smrg      ;;
74805ffd6003Smrg    *.$libext) linkmode=oldlib ;;
74815ffd6003Smrg    *.lo | *.$objext) linkmode=obj ;;
74825ffd6003Smrg    *.la) linkmode=lib ;;
74835ffd6003Smrg    *) linkmode=prog ;; # Anything else should be a program.
74845ffd6003Smrg    esac
74855ffd6003Smrg
74865ffd6003Smrg    specialdeplibs=
74875ffd6003Smrg
74885ffd6003Smrg    libs=
74895ffd6003Smrg    # Find all interdependent deplibs by searching for libraries
74905ffd6003Smrg    # that are linked more than once (e.g. -la -lb -la)
74915ffd6003Smrg    for deplib in $deplibs; do
7492b7d26471Smrg      if $opt_preserve_dup_deps; then
74935ffd6003Smrg	case "$libs " in
7494629baa8cSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
74955ffd6003Smrg	esac
74965ffd6003Smrg      fi
7497629baa8cSmrg      func_append libs " $deplib"
74985ffd6003Smrg    done
74995ffd6003Smrg
7500b7d26471Smrg    if test lib = "$linkmode"; then
75015ffd6003Smrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
75025ffd6003Smrg
75035ffd6003Smrg      # Compute libraries that are listed more than once in $predeps
75045ffd6003Smrg      # $postdeps and mark them as special (i.e., whose duplicates are
75055ffd6003Smrg      # not to be eliminated).
75065ffd6003Smrg      pre_post_deps=
75075ffd6003Smrg      if $opt_duplicate_compiler_generated_deps; then
75085ffd6003Smrg	for pre_post_dep in $predeps $postdeps; do
75095ffd6003Smrg	  case "$pre_post_deps " in
7510629baa8cSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
75115ffd6003Smrg	  esac
7512629baa8cSmrg	  func_append pre_post_deps " $pre_post_dep"
75135ffd6003Smrg	done
75145ffd6003Smrg      fi
75155ffd6003Smrg      pre_post_deps=
75165ffd6003Smrg    fi
75175ffd6003Smrg
75185ffd6003Smrg    deplibs=
75195ffd6003Smrg    newdependency_libs=
75205ffd6003Smrg    newlib_search_path=
75215ffd6003Smrg    need_relink=no # whether we're linking any uninstalled libtool libraries
75225ffd6003Smrg    notinst_deplibs= # not-installed libtool libraries
75235ffd6003Smrg    notinst_path= # paths that contain not-installed libtool libraries
75245ffd6003Smrg
75255ffd6003Smrg    case $linkmode in
75265ffd6003Smrg    lib)
75275ffd6003Smrg	passes="conv dlpreopen link"
75285ffd6003Smrg	for file in $dlfiles $dlprefiles; do
75295ffd6003Smrg	  case $file in
75305ffd6003Smrg	  *.la) ;;
75315ffd6003Smrg	  *)
7532b7d26471Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
75335ffd6003Smrg	    ;;
75345ffd6003Smrg	  esac
75355ffd6003Smrg	done
75365ffd6003Smrg	;;
75375ffd6003Smrg    prog)
75385ffd6003Smrg	compile_deplibs=
75395ffd6003Smrg	finalize_deplibs=
7540b7d26471Smrg	alldeplibs=false
75415ffd6003Smrg	newdlfiles=
75425ffd6003Smrg	newdlprefiles=
75435ffd6003Smrg	passes="conv scan dlopen dlpreopen link"
75445ffd6003Smrg	;;
75455ffd6003Smrg    *)  passes="conv"
75465ffd6003Smrg	;;
75475ffd6003Smrg    esac
75485ffd6003Smrg
75495ffd6003Smrg    for pass in $passes; do
75505ffd6003Smrg      # The preopen pass in lib mode reverses $deplibs; put it back here
75515ffd6003Smrg      # so that -L comes before libs that need it for instance...
7552b7d26471Smrg      if test lib,link = "$linkmode,$pass"; then
75535ffd6003Smrg	## FIXME: Find the place where the list is rebuilt in the wrong
75545ffd6003Smrg	##        order, and fix it there properly
75555ffd6003Smrg        tmp_deplibs=
75565ffd6003Smrg	for deplib in $deplibs; do
75575ffd6003Smrg	  tmp_deplibs="$deplib $tmp_deplibs"
75585ffd6003Smrg	done
7559b7d26471Smrg	deplibs=$tmp_deplibs
75605ffd6003Smrg      fi
75615ffd6003Smrg
7562b7d26471Smrg      if test lib,link = "$linkmode,$pass" ||
7563b7d26471Smrg	 test prog,scan = "$linkmode,$pass"; then
7564b7d26471Smrg	libs=$deplibs
75655ffd6003Smrg	deplibs=
75665ffd6003Smrg      fi
7567b7d26471Smrg      if test prog = "$linkmode"; then
75685ffd6003Smrg	case $pass in
7569b7d26471Smrg	dlopen) libs=$dlfiles ;;
7570b7d26471Smrg	dlpreopen) libs=$dlprefiles ;;
7571629baa8cSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
75725ffd6003Smrg	esac
75735ffd6003Smrg      fi
7574b7d26471Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
75755ffd6003Smrg	# Collect and forward deplibs of preopened libtool libs
75765ffd6003Smrg	for lib in $dlprefiles; do
75775ffd6003Smrg	  # Ignore non-libtool-libs
75785ffd6003Smrg	  dependency_libs=
7579629baa8cSmrg	  func_resolve_sysroot "$lib"
75805ffd6003Smrg	  case $lib in
7581629baa8cSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
75825ffd6003Smrg	  esac
75835ffd6003Smrg
75845ffd6003Smrg	  # Collect preopened libtool deplibs, except any this library
75855ffd6003Smrg	  # has declared as weak libs
75865ffd6003Smrg	  for deplib in $dependency_libs; do
7587629baa8cSmrg	    func_basename "$deplib"
7588629baa8cSmrg            deplib_base=$func_basename_result
75895ffd6003Smrg	    case " $weak_libs " in
75905ffd6003Smrg	    *" $deplib_base "*) ;;
7591629baa8cSmrg	    *) func_append deplibs " $deplib" ;;
75925ffd6003Smrg	    esac
75935ffd6003Smrg	  done
75945ffd6003Smrg	done
7595b7d26471Smrg	libs=$dlprefiles
75965ffd6003Smrg      fi
7597b7d26471Smrg      if test dlopen = "$pass"; then
75985ffd6003Smrg	# Collect dlpreopened libraries
7599b7d26471Smrg	save_deplibs=$deplibs
76005ffd6003Smrg	deplibs=
76015ffd6003Smrg      fi
76025ffd6003Smrg
76035ffd6003Smrg      for deplib in $libs; do
76045ffd6003Smrg	lib=
7605b7d26471Smrg	found=false
76065ffd6003Smrg	case $deplib in
7607b7d26471Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7608b7d26471Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7609b7d26471Smrg	  if test prog,link = "$linkmode,$pass"; then
76105ffd6003Smrg	    compile_deplibs="$deplib $compile_deplibs"
76115ffd6003Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
76125ffd6003Smrg	  else
7613629baa8cSmrg	    func_append compiler_flags " $deplib"
7614b7d26471Smrg	    if test lib = "$linkmode"; then
76155ffd6003Smrg		case "$new_inherited_linker_flags " in
76165ffd6003Smrg		    *" $deplib "*) ;;
7617629baa8cSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
76185ffd6003Smrg		esac
76195ffd6003Smrg	    fi
76205ffd6003Smrg	  fi
76215ffd6003Smrg	  continue
76225ffd6003Smrg	  ;;
76235ffd6003Smrg	-l*)
7624b7d26471Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7625b7d26471Smrg	    func_warning "'-l' is ignored for archives/objects"
76265ffd6003Smrg	    continue
76275ffd6003Smrg	  fi
76285ffd6003Smrg	  func_stripname '-l' '' "$deplib"
76295ffd6003Smrg	  name=$func_stripname_result
7630b7d26471Smrg	  if test lib = "$linkmode"; then
76315ffd6003Smrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
76325ffd6003Smrg	  else
76335ffd6003Smrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
76345ffd6003Smrg	  fi
76355ffd6003Smrg	  for searchdir in $searchdirs; do
76365ffd6003Smrg	    for search_ext in .la $std_shrext .so .a; do
76375ffd6003Smrg	      # Search the libtool library
7638b7d26471Smrg	      lib=$searchdir/lib$name$search_ext
76395ffd6003Smrg	      if test -f "$lib"; then
7640b7d26471Smrg		if test .la = "$search_ext"; then
7641b7d26471Smrg		  found=:
76425ffd6003Smrg		else
7643b7d26471Smrg		  found=false
76445ffd6003Smrg		fi
76455ffd6003Smrg		break 2
76465ffd6003Smrg	      fi
76475ffd6003Smrg	    done
76485ffd6003Smrg	  done
7649b7d26471Smrg	  if $found; then
7650b7d26471Smrg	    # deplib is a libtool library
76515ffd6003Smrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
76525ffd6003Smrg	    # We need to do some special things here, and not later.
7653b7d26471Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
76545ffd6003Smrg	      case " $predeps $postdeps " in
76555ffd6003Smrg	      *" $deplib "*)
76565ffd6003Smrg		if func_lalib_p "$lib"; then
76575ffd6003Smrg		  library_names=
76585ffd6003Smrg		  old_library=
76595ffd6003Smrg		  func_source "$lib"
76605ffd6003Smrg		  for l in $old_library $library_names; do
7661b7d26471Smrg		    ll=$l
76625ffd6003Smrg		  done
7663b7d26471Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7664b7d26471Smrg		    found=false
76655ffd6003Smrg		    func_dirname "$lib" "" "."
7666b7d26471Smrg		    ladir=$func_dirname_result
76675ffd6003Smrg		    lib=$ladir/$old_library
7668b7d26471Smrg		    if test prog,link = "$linkmode,$pass"; then
76695ffd6003Smrg		      compile_deplibs="$deplib $compile_deplibs"
76705ffd6003Smrg		      finalize_deplibs="$deplib $finalize_deplibs"
76715ffd6003Smrg		    else
76725ffd6003Smrg		      deplibs="$deplib $deplibs"
7673b7d26471Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
76745ffd6003Smrg		    fi
76755ffd6003Smrg		    continue
76765ffd6003Smrg		  fi
76775ffd6003Smrg		fi
76785ffd6003Smrg		;;
76795ffd6003Smrg	      *) ;;
76805ffd6003Smrg	      esac
76815ffd6003Smrg	    fi
7682b7d26471Smrg	  else
7683b7d26471Smrg	    # deplib doesn't seem to be a libtool library
7684b7d26471Smrg	    if test prog,link = "$linkmode,$pass"; then
7685b7d26471Smrg	      compile_deplibs="$deplib $compile_deplibs"
7686b7d26471Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7687b7d26471Smrg	    else
7688b7d26471Smrg	      deplibs="$deplib $deplibs"
7689b7d26471Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7690b7d26471Smrg	    fi
7691b7d26471Smrg	    continue
76925ffd6003Smrg	  fi
76935ffd6003Smrg	  ;; # -l
76945ffd6003Smrg	*.ltframework)
7695b7d26471Smrg	  if test prog,link = "$linkmode,$pass"; then
76965ffd6003Smrg	    compile_deplibs="$deplib $compile_deplibs"
76975ffd6003Smrg	    finalize_deplibs="$deplib $finalize_deplibs"
76985ffd6003Smrg	  else
76995ffd6003Smrg	    deplibs="$deplib $deplibs"
7700b7d26471Smrg	    if test lib = "$linkmode"; then
77015ffd6003Smrg		case "$new_inherited_linker_flags " in
77025ffd6003Smrg		    *" $deplib "*) ;;
7703629baa8cSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
77045ffd6003Smrg		esac
77055ffd6003Smrg	    fi
77065ffd6003Smrg	  fi
77075ffd6003Smrg	  continue
77085ffd6003Smrg	  ;;
77095ffd6003Smrg	-L*)
77105ffd6003Smrg	  case $linkmode in
77115ffd6003Smrg	  lib)
77125ffd6003Smrg	    deplibs="$deplib $deplibs"
7713b7d26471Smrg	    test conv = "$pass" && continue
77145ffd6003Smrg	    newdependency_libs="$deplib $newdependency_libs"
77155ffd6003Smrg	    func_stripname '-L' '' "$deplib"
7716629baa8cSmrg	    func_resolve_sysroot "$func_stripname_result"
7717629baa8cSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
77185ffd6003Smrg	    ;;
77195ffd6003Smrg	  prog)
7720b7d26471Smrg	    if test conv = "$pass"; then
77215ffd6003Smrg	      deplibs="$deplib $deplibs"
77225ffd6003Smrg	      continue
77235ffd6003Smrg	    fi
7724b7d26471Smrg	    if test scan = "$pass"; then
77255ffd6003Smrg	      deplibs="$deplib $deplibs"
77265ffd6003Smrg	    else
77275ffd6003Smrg	      compile_deplibs="$deplib $compile_deplibs"
77285ffd6003Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
77295ffd6003Smrg	    fi
77305ffd6003Smrg	    func_stripname '-L' '' "$deplib"
7731629baa8cSmrg	    func_resolve_sysroot "$func_stripname_result"
7732629baa8cSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
77335ffd6003Smrg	    ;;
77345ffd6003Smrg	  *)
7735b7d26471Smrg	    func_warning "'-L' is ignored for archives/objects"
77365ffd6003Smrg	    ;;
77375ffd6003Smrg	  esac # linkmode
77385ffd6003Smrg	  continue
77395ffd6003Smrg	  ;; # -L
77405ffd6003Smrg	-R*)
7741b7d26471Smrg	  if test link = "$pass"; then
77425ffd6003Smrg	    func_stripname '-R' '' "$deplib"
7743629baa8cSmrg	    func_resolve_sysroot "$func_stripname_result"
7744629baa8cSmrg	    dir=$func_resolve_sysroot_result
77455ffd6003Smrg	    # Make sure the xrpath contains only unique directories.
77465ffd6003Smrg	    case "$xrpath " in
77475ffd6003Smrg	    *" $dir "*) ;;
7748629baa8cSmrg	    *) func_append xrpath " $dir" ;;
77495ffd6003Smrg	    esac
77505ffd6003Smrg	  fi
77515ffd6003Smrg	  deplibs="$deplib $deplibs"
77525ffd6003Smrg	  continue
77535ffd6003Smrg	  ;;
7754629baa8cSmrg	*.la)
7755629baa8cSmrg	  func_resolve_sysroot "$deplib"
7756629baa8cSmrg	  lib=$func_resolve_sysroot_result
7757629baa8cSmrg	  ;;
77585ffd6003Smrg	*.$libext)
7759b7d26471Smrg	  if test conv = "$pass"; then
77605ffd6003Smrg	    deplibs="$deplib $deplibs"
77615ffd6003Smrg	    continue
77625ffd6003Smrg	  fi
77635ffd6003Smrg	  case $linkmode in
77645ffd6003Smrg	  lib)
77655ffd6003Smrg	    # Linking convenience modules into shared libraries is allowed,
77665ffd6003Smrg	    # but linking other static libraries is non-portable.
77675ffd6003Smrg	    case " $dlpreconveniencelibs " in
77685ffd6003Smrg	    *" $deplib "*) ;;
77695ffd6003Smrg	    *)
7770b7d26471Smrg	      valid_a_lib=false
77715ffd6003Smrg	      case $deplibs_check_method in
77725ffd6003Smrg		match_pattern*)
77735ffd6003Smrg		  set dummy $deplibs_check_method; shift
77745ffd6003Smrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
7775629baa8cSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
77765ffd6003Smrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
7777b7d26471Smrg		    valid_a_lib=:
77785ffd6003Smrg		  fi
77795ffd6003Smrg		;;
77805ffd6003Smrg		pass_all)
7781b7d26471Smrg		  valid_a_lib=:
77825ffd6003Smrg		;;
77835ffd6003Smrg	      esac
7784b7d26471Smrg	      if $valid_a_lib; then
7785b7d26471Smrg		echo
7786b7d26471Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
7787b7d26471Smrg		$ECHO "*** static library $deplib is not portable!"
7788b7d26471Smrg		deplibs="$deplib $deplibs"
7789b7d26471Smrg	      else
7790629baa8cSmrg		echo
77915ffd6003Smrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
7792629baa8cSmrg		echo "*** I have the capability to make that library automatically link in when"
7793629baa8cSmrg		echo "*** you link to this library.  But I can only do this if you have a"
7794629baa8cSmrg		echo "*** shared version of the library, which you do not appear to have"
7795629baa8cSmrg		echo "*** because the file extensions .$libext of this argument makes me believe"
7796629baa8cSmrg		echo "*** that it is just a static archive that I should not use here."
77975ffd6003Smrg	      fi
77985ffd6003Smrg	      ;;
77995ffd6003Smrg	    esac
78005ffd6003Smrg	    continue
78015ffd6003Smrg	    ;;
78025ffd6003Smrg	  prog)
7803b7d26471Smrg	    if test link != "$pass"; then
78045ffd6003Smrg	      deplibs="$deplib $deplibs"
78055ffd6003Smrg	    else
78065ffd6003Smrg	      compile_deplibs="$deplib $compile_deplibs"
78075ffd6003Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
78085ffd6003Smrg	    fi
78095ffd6003Smrg	    continue
78105ffd6003Smrg	    ;;
78115ffd6003Smrg	  esac # linkmode
78125ffd6003Smrg	  ;; # *.$libext
78135ffd6003Smrg	*.lo | *.$objext)
7814b7d26471Smrg	  if test conv = "$pass"; then
78155ffd6003Smrg	    deplibs="$deplib $deplibs"
7816b7d26471Smrg	  elif test prog = "$linkmode"; then
7817b7d26471Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
78185ffd6003Smrg	      # If there is no dlopen support or we're linking statically,
78195ffd6003Smrg	      # we need to preload.
7820629baa8cSmrg	      func_append newdlprefiles " $deplib"
78215ffd6003Smrg	      compile_deplibs="$deplib $compile_deplibs"
78225ffd6003Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
78235ffd6003Smrg	    else
7824629baa8cSmrg	      func_append newdlfiles " $deplib"
78255ffd6003Smrg	    fi
78265ffd6003Smrg	  fi
78275ffd6003Smrg	  continue
78285ffd6003Smrg	  ;;
78295ffd6003Smrg	%DEPLIBS%)
7830b7d26471Smrg	  alldeplibs=:
78315ffd6003Smrg	  continue
78325ffd6003Smrg	  ;;
78335ffd6003Smrg	esac # case $deplib
78345ffd6003Smrg
7835b7d26471Smrg	$found || test -f "$lib" \
7836b7d26471Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
78375ffd6003Smrg
78385ffd6003Smrg	# Check to see that this really is a libtool archive.
78395ffd6003Smrg	func_lalib_unsafe_p "$lib" \
7840b7d26471Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
78415ffd6003Smrg
78425ffd6003Smrg	func_dirname "$lib" "" "."
7843b7d26471Smrg	ladir=$func_dirname_result
78445ffd6003Smrg
78455ffd6003Smrg	dlname=
78465ffd6003Smrg	dlopen=
78475ffd6003Smrg	dlpreopen=
78485ffd6003Smrg	libdir=
78495ffd6003Smrg	library_names=
78505ffd6003Smrg	old_library=
78515ffd6003Smrg	inherited_linker_flags=
78525ffd6003Smrg	# If the library was installed with an old release of libtool,
78535ffd6003Smrg	# it will not redefine variables installed, or shouldnotlink
78545ffd6003Smrg	installed=yes
78555ffd6003Smrg	shouldnotlink=no
78565ffd6003Smrg	avoidtemprpath=
78575ffd6003Smrg
78585ffd6003Smrg
78595ffd6003Smrg	# Read the .la file
78605ffd6003Smrg	func_source "$lib"
78615ffd6003Smrg
78625ffd6003Smrg	# Convert "-framework foo" to "foo.ltframework"
78635ffd6003Smrg	if test -n "$inherited_linker_flags"; then
7864629baa8cSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
78655ffd6003Smrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
78665ffd6003Smrg	    case " $new_inherited_linker_flags " in
78675ffd6003Smrg	      *" $tmp_inherited_linker_flag "*) ;;
7868629baa8cSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
78695ffd6003Smrg	    esac
78705ffd6003Smrg	  done
78715ffd6003Smrg	fi
7872629baa8cSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
7873b7d26471Smrg	if test lib,link = "$linkmode,$pass" ||
7874b7d26471Smrg	   test prog,scan = "$linkmode,$pass" ||
7875b7d26471Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
7876629baa8cSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
7877629baa8cSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
78785ffd6003Smrg	fi
78795ffd6003Smrg
7880b7d26471Smrg	if test conv = "$pass"; then
78815ffd6003Smrg	  # Only check for convenience libraries
78825ffd6003Smrg	  deplibs="$lib $deplibs"
78835ffd6003Smrg	  if test -z "$libdir"; then
78845ffd6003Smrg	    if test -z "$old_library"; then
7885b7d26471Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
78865ffd6003Smrg	    fi
78875ffd6003Smrg	    # It is a libtool convenience library, so add in its objects.
7888629baa8cSmrg	    func_append convenience " $ladir/$objdir/$old_library"
7889629baa8cSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
7890b7d26471Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
7891b7d26471Smrg	    func_fatal_error "'$lib' is not a convenience library"
78925ffd6003Smrg	  fi
7893629baa8cSmrg	  tmp_libs=
7894629baa8cSmrg	  for deplib in $dependency_libs; do
7895629baa8cSmrg	    deplibs="$deplib $deplibs"
7896b7d26471Smrg	    if $opt_preserve_dup_deps; then
7897629baa8cSmrg	      case "$tmp_libs " in
7898629baa8cSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
7899629baa8cSmrg	      esac
7900629baa8cSmrg	    fi
7901629baa8cSmrg	    func_append tmp_libs " $deplib"
7902629baa8cSmrg	  done
79035ffd6003Smrg	  continue
79045ffd6003Smrg	fi # $pass = conv
79055ffd6003Smrg
79065ffd6003Smrg
79075ffd6003Smrg	# Get the name of the library we link against.
79085ffd6003Smrg	linklib=
7909629baa8cSmrg	if test -n "$old_library" &&
7910b7d26471Smrg	   { test yes = "$prefer_static_libs" ||
7911b7d26471Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
7912629baa8cSmrg	  linklib=$old_library
7913629baa8cSmrg	else
7914629baa8cSmrg	  for l in $old_library $library_names; do
7915b7d26471Smrg	    linklib=$l
7916629baa8cSmrg	  done
7917629baa8cSmrg	fi
79185ffd6003Smrg	if test -z "$linklib"; then
7919b7d26471Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
79205ffd6003Smrg	fi
79215ffd6003Smrg
79225ffd6003Smrg	# This library was specified with -dlopen.
7923b7d26471Smrg	if test dlopen = "$pass"; then
7924b7d26471Smrg	  test -z "$libdir" \
7925b7d26471Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
79265ffd6003Smrg	  if test -z "$dlname" ||
7927b7d26471Smrg	     test yes != "$dlopen_support" ||
7928b7d26471Smrg	     test no = "$build_libtool_libs"
7929b7d26471Smrg	  then
79305ffd6003Smrg	    # If there is no dlname, no dlopen support or we're linking
79315ffd6003Smrg	    # statically, we need to preload.  We also need to preload any
79325ffd6003Smrg	    # dependent libraries so libltdl's deplib preloader doesn't
79335ffd6003Smrg	    # bomb out in the load deplibs phase.
7934629baa8cSmrg	    func_append dlprefiles " $lib $dependency_libs"
79355ffd6003Smrg	  else
7936629baa8cSmrg	    func_append newdlfiles " $lib"
79375ffd6003Smrg	  fi
79385ffd6003Smrg	  continue
79395ffd6003Smrg	fi # $pass = dlopen
79405ffd6003Smrg
79415ffd6003Smrg	# We need an absolute path.
79425ffd6003Smrg	case $ladir in
7943b7d26471Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
79445ffd6003Smrg	*)
79455ffd6003Smrg	  abs_ladir=`cd "$ladir" && pwd`
79465ffd6003Smrg	  if test -z "$abs_ladir"; then
7947b7d26471Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
79485ffd6003Smrg	    func_warning "passing it literally to the linker, although it might fail"
7949b7d26471Smrg	    abs_ladir=$ladir
79505ffd6003Smrg	  fi
79515ffd6003Smrg	  ;;
79525ffd6003Smrg	esac
79535ffd6003Smrg	func_basename "$lib"
7954b7d26471Smrg	laname=$func_basename_result
79555ffd6003Smrg
79565ffd6003Smrg	# Find the relevant object directory and library name.
7957b7d26471Smrg	if test yes = "$installed"; then
7958629baa8cSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7959b7d26471Smrg	    func_warning "library '$lib' was moved."
7960b7d26471Smrg	    dir=$ladir
7961b7d26471Smrg	    absdir=$abs_ladir
7962b7d26471Smrg	    libdir=$abs_ladir
79635ffd6003Smrg	  else
7964b7d26471Smrg	    dir=$lt_sysroot$libdir
7965b7d26471Smrg	    absdir=$lt_sysroot$libdir
79665ffd6003Smrg	  fi
7967b7d26471Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
79685ffd6003Smrg	else
79695ffd6003Smrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7970b7d26471Smrg	    dir=$ladir
7971b7d26471Smrg	    absdir=$abs_ladir
79725ffd6003Smrg	    # Remove this search path later
7973629baa8cSmrg	    func_append notinst_path " $abs_ladir"
79745ffd6003Smrg	  else
7975b7d26471Smrg	    dir=$ladir/$objdir
7976b7d26471Smrg	    absdir=$abs_ladir/$objdir
79775ffd6003Smrg	    # Remove this search path later
7978629baa8cSmrg	    func_append notinst_path " $abs_ladir"
79795ffd6003Smrg	  fi
79805ffd6003Smrg	fi # $installed = yes
79815ffd6003Smrg	func_stripname 'lib' '.la' "$laname"
79825ffd6003Smrg	name=$func_stripname_result
79835ffd6003Smrg
79845ffd6003Smrg	# This library was specified with -dlpreopen.
7985b7d26471Smrg	if test dlpreopen = "$pass"; then
7986b7d26471Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
7987b7d26471Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
79885ffd6003Smrg	  fi
7989b7d26471Smrg	  case $host in
7990629baa8cSmrg	    # special handling for platforms with PE-DLLs.
7991629baa8cSmrg	    *cygwin* | *mingw* | *cegcc* )
7992629baa8cSmrg	      # Linker will automatically link against shared library if both
7993629baa8cSmrg	      # static and shared are present.  Therefore, ensure we extract
7994629baa8cSmrg	      # symbols from the import library if a shared library is present
7995629baa8cSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
7996629baa8cSmrg	      # this by putting the import library name into $newdlprefiles.
7997629baa8cSmrg	      # We recover the dlopen module name by 'saving' the la file
7998629baa8cSmrg	      # name in a special purpose variable, and (later) extracting the
7999629baa8cSmrg	      # dlname from the la file.
8000629baa8cSmrg	      if test -n "$dlname"; then
8001629baa8cSmrg	        func_tr_sh "$dir/$linklib"
8002629baa8cSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8003629baa8cSmrg	        func_append newdlprefiles " $dir/$linklib"
8004629baa8cSmrg	      else
8005629baa8cSmrg	        func_append newdlprefiles " $dir/$old_library"
8006629baa8cSmrg	        # Keep a list of preopened convenience libraries to check
8007629baa8cSmrg	        # that they are being used correctly in the link pass.
8008629baa8cSmrg	        test -z "$libdir" && \
8009629baa8cSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8010629baa8cSmrg	      fi
8011629baa8cSmrg	    ;;
8012629baa8cSmrg	    * )
8013629baa8cSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8014629baa8cSmrg	      # are required to link).
8015629baa8cSmrg	      if test -n "$old_library"; then
8016629baa8cSmrg	        func_append newdlprefiles " $dir/$old_library"
8017629baa8cSmrg	        # Keep a list of preopened convenience libraries to check
8018629baa8cSmrg	        # that they are being used correctly in the link pass.
8019629baa8cSmrg	        test -z "$libdir" && \
8020629baa8cSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8021629baa8cSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8022629baa8cSmrg	      elif test -n "$dlname"; then
8023629baa8cSmrg	        func_append newdlprefiles " $dir/$dlname"
8024629baa8cSmrg	      else
8025629baa8cSmrg	        func_append newdlprefiles " $dir/$linklib"
8026629baa8cSmrg	      fi
8027629baa8cSmrg	    ;;
8028629baa8cSmrg	  esac
80295ffd6003Smrg	fi # $pass = dlpreopen
80305ffd6003Smrg
80315ffd6003Smrg	if test -z "$libdir"; then
80325ffd6003Smrg	  # Link the convenience library
8033b7d26471Smrg	  if test lib = "$linkmode"; then
80345ffd6003Smrg	    deplibs="$dir/$old_library $deplibs"
8035b7d26471Smrg	  elif test prog,link = "$linkmode,$pass"; then
80365ffd6003Smrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
80375ffd6003Smrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
80385ffd6003Smrg	  else
80395ffd6003Smrg	    deplibs="$lib $deplibs" # used for prog,scan pass
80405ffd6003Smrg	  fi
80415ffd6003Smrg	  continue
80425ffd6003Smrg	fi
80435ffd6003Smrg
80445ffd6003Smrg
8045b7d26471Smrg	if test prog = "$linkmode" && test link != "$pass"; then
8046629baa8cSmrg	  func_append newlib_search_path " $ladir"
80475ffd6003Smrg	  deplibs="$lib $deplibs"
80485ffd6003Smrg
8049b7d26471Smrg	  linkalldeplibs=false
8050b7d26471Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8051b7d26471Smrg	     test no = "$build_libtool_libs"; then
8052b7d26471Smrg	    linkalldeplibs=:
80535ffd6003Smrg	  fi
80545ffd6003Smrg
80555ffd6003Smrg	  tmp_libs=
80565ffd6003Smrg	  for deplib in $dependency_libs; do
80575ffd6003Smrg	    case $deplib in
80585ffd6003Smrg	    -L*) func_stripname '-L' '' "$deplib"
8059629baa8cSmrg	         func_resolve_sysroot "$func_stripname_result"
8060629baa8cSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
80615ffd6003Smrg		 ;;
80625ffd6003Smrg	    esac
80635ffd6003Smrg	    # Need to link against all dependency_libs?
8064b7d26471Smrg	    if $linkalldeplibs; then
80655ffd6003Smrg	      deplibs="$deplib $deplibs"
80665ffd6003Smrg	    else
80675ffd6003Smrg	      # Need to hardcode shared library paths
80685ffd6003Smrg	      # or/and link against static libraries
80695ffd6003Smrg	      newdependency_libs="$deplib $newdependency_libs"
80705ffd6003Smrg	    fi
8071b7d26471Smrg	    if $opt_preserve_dup_deps; then
80725ffd6003Smrg	      case "$tmp_libs " in
8073629baa8cSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
80745ffd6003Smrg	      esac
80755ffd6003Smrg	    fi
8076629baa8cSmrg	    func_append tmp_libs " $deplib"
80775ffd6003Smrg	  done # for deplib
80785ffd6003Smrg	  continue
80795ffd6003Smrg	fi # $linkmode = prog...
80805ffd6003Smrg
8081b7d26471Smrg	if test prog,link = "$linkmode,$pass"; then
80825ffd6003Smrg	  if test -n "$library_names" &&
8083b7d26471Smrg	     { { test no = "$prefer_static_libs" ||
8084b7d26471Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
80855ffd6003Smrg	       test -z "$old_library"; }; then
80865ffd6003Smrg	    # We need to hardcode the library path
8087b7d26471Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
80885ffd6003Smrg	      # Make sure the rpath contains only unique directories.
8089b7d26471Smrg	      case $temp_rpath: in
80905ffd6003Smrg	      *"$absdir:"*) ;;
8091629baa8cSmrg	      *) func_append temp_rpath "$absdir:" ;;
80925ffd6003Smrg	      esac
80935ffd6003Smrg	    fi
80945ffd6003Smrg
80955ffd6003Smrg	    # Hardcode the library path.
80965ffd6003Smrg	    # Skip directories that are in the system default run-time
80975ffd6003Smrg	    # search path.
80985ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
80995ffd6003Smrg	    *" $absdir "*) ;;
81005ffd6003Smrg	    *)
81015ffd6003Smrg	      case "$compile_rpath " in
81025ffd6003Smrg	      *" $absdir "*) ;;
8103629baa8cSmrg	      *) func_append compile_rpath " $absdir" ;;
81045ffd6003Smrg	      esac
81055ffd6003Smrg	      ;;
81065ffd6003Smrg	    esac
81075ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
81085ffd6003Smrg	    *" $libdir "*) ;;
81095ffd6003Smrg	    *)
81105ffd6003Smrg	      case "$finalize_rpath " in
81115ffd6003Smrg	      *" $libdir "*) ;;
8112629baa8cSmrg	      *) func_append finalize_rpath " $libdir" ;;
81135ffd6003Smrg	      esac
81145ffd6003Smrg	      ;;
81155ffd6003Smrg	    esac
81165ffd6003Smrg	  fi # $linkmode,$pass = prog,link...
81175ffd6003Smrg
8118b7d26471Smrg	  if $alldeplibs &&
8119b7d26471Smrg	     { test pass_all = "$deplibs_check_method" ||
8120b7d26471Smrg	       { test yes = "$build_libtool_libs" &&
81215ffd6003Smrg		 test -n "$library_names"; }; }; then
81225ffd6003Smrg	    # We only need to search for static libraries
81235ffd6003Smrg	    continue
81245ffd6003Smrg	  fi
81255ffd6003Smrg	fi
81265ffd6003Smrg
81275ffd6003Smrg	link_static=no # Whether the deplib will be linked statically
81285ffd6003Smrg	use_static_libs=$prefer_static_libs
8129b7d26471Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
81305ffd6003Smrg	  use_static_libs=no
81315ffd6003Smrg	fi
81325ffd6003Smrg	if test -n "$library_names" &&
8133b7d26471Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
81345ffd6003Smrg	  case $host in
8135b7d26471Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
81365ffd6003Smrg	      # No point in relinking DLLs because paths are not encoded
8137629baa8cSmrg	      func_append notinst_deplibs " $lib"
81385ffd6003Smrg	      need_relink=no
81395ffd6003Smrg	    ;;
81405ffd6003Smrg	  *)
8141b7d26471Smrg	    if test no = "$installed"; then
8142629baa8cSmrg	      func_append notinst_deplibs " $lib"
81435ffd6003Smrg	      need_relink=yes
81445ffd6003Smrg	    fi
81455ffd6003Smrg	    ;;
81465ffd6003Smrg	  esac
81475ffd6003Smrg	  # This is a shared library
81485ffd6003Smrg
81495ffd6003Smrg	  # Warn about portability, can't link against -module's on some
81505ffd6003Smrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8151b7d26471Smrg	  dlopenmodule=
81525ffd6003Smrg	  for dlpremoduletest in $dlprefiles; do
81535ffd6003Smrg	    if test "X$dlpremoduletest" = "X$lib"; then
8154b7d26471Smrg	      dlopenmodule=$dlpremoduletest
81555ffd6003Smrg	      break
81565ffd6003Smrg	    fi
81575ffd6003Smrg	  done
8158b7d26471Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8159629baa8cSmrg	    echo
8160b7d26471Smrg	    if test prog = "$linkmode"; then
81615ffd6003Smrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
81625ffd6003Smrg	    else
81635ffd6003Smrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
81645ffd6003Smrg	    fi
81655ffd6003Smrg	    $ECHO "*** $linklib is not portable!"
81665ffd6003Smrg	  fi
8167b7d26471Smrg	  if test lib = "$linkmode" &&
8168b7d26471Smrg	     test yes = "$hardcode_into_libs"; then
81695ffd6003Smrg	    # Hardcode the library path.
81705ffd6003Smrg	    # Skip directories that are in the system default run-time
81715ffd6003Smrg	    # search path.
81725ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
81735ffd6003Smrg	    *" $absdir "*) ;;
81745ffd6003Smrg	    *)
81755ffd6003Smrg	      case "$compile_rpath " in
81765ffd6003Smrg	      *" $absdir "*) ;;
8177629baa8cSmrg	      *) func_append compile_rpath " $absdir" ;;
81785ffd6003Smrg	      esac
81795ffd6003Smrg	      ;;
81805ffd6003Smrg	    esac
81815ffd6003Smrg	    case " $sys_lib_dlsearch_path " in
81825ffd6003Smrg	    *" $libdir "*) ;;
81835ffd6003Smrg	    *)
81845ffd6003Smrg	      case "$finalize_rpath " in
81855ffd6003Smrg	      *" $libdir "*) ;;
8186629baa8cSmrg	      *) func_append finalize_rpath " $libdir" ;;
81875ffd6003Smrg	      esac
81885ffd6003Smrg	      ;;
81895ffd6003Smrg	    esac
81905ffd6003Smrg	  fi
81915ffd6003Smrg
81925ffd6003Smrg	  if test -n "$old_archive_from_expsyms_cmds"; then
81935ffd6003Smrg	    # figure out the soname
81945ffd6003Smrg	    set dummy $library_names
81955ffd6003Smrg	    shift
8196b7d26471Smrg	    realname=$1
81975ffd6003Smrg	    shift
81985ffd6003Smrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
81995ffd6003Smrg	    # use dlname if we got it. it's perfectly good, no?
82005ffd6003Smrg	    if test -n "$dlname"; then
8201b7d26471Smrg	      soname=$dlname
82025ffd6003Smrg	    elif test -n "$soname_spec"; then
82035ffd6003Smrg	      # bleh windows
82045ffd6003Smrg	      case $host in
8205b7d26471Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
82065ffd6003Smrg	        func_arith $current - $age
82075ffd6003Smrg		major=$func_arith_result
8208b7d26471Smrg		versuffix=-$major
82095ffd6003Smrg		;;
82105ffd6003Smrg	      esac
82115ffd6003Smrg	      eval soname=\"$soname_spec\"
82125ffd6003Smrg	    else
8213b7d26471Smrg	      soname=$realname
82145ffd6003Smrg	    fi
82155ffd6003Smrg
82165ffd6003Smrg	    # Make a new name for the extract_expsyms_cmds to use
8217b7d26471Smrg	    soroot=$soname
82185ffd6003Smrg	    func_basename "$soroot"
8219b7d26471Smrg	    soname=$func_basename_result
82205ffd6003Smrg	    func_stripname 'lib' '.dll' "$soname"
82215ffd6003Smrg	    newlib=libimp-$func_stripname_result.a
82225ffd6003Smrg
82235ffd6003Smrg	    # If the library has no export list, then create one now
82245ffd6003Smrg	    if test -f "$output_objdir/$soname-def"; then :
82255ffd6003Smrg	    else
8226b7d26471Smrg	      func_verbose "extracting exported symbol list from '$soname'"
82275ffd6003Smrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
82285ffd6003Smrg	    fi
82295ffd6003Smrg
82305ffd6003Smrg	    # Create $newlib
82315ffd6003Smrg	    if test -f "$output_objdir/$newlib"; then :; else
8232b7d26471Smrg	      func_verbose "generating import library for '$soname'"
82335ffd6003Smrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
82345ffd6003Smrg	    fi
82355ffd6003Smrg	    # make sure the library variables are pointing to the new library
82365ffd6003Smrg	    dir=$output_objdir
82375ffd6003Smrg	    linklib=$newlib
82385ffd6003Smrg	  fi # test -n "$old_archive_from_expsyms_cmds"
82395ffd6003Smrg
8240b7d26471Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
82415ffd6003Smrg	    add_shlibpath=
82425ffd6003Smrg	    add_dir=
82435ffd6003Smrg	    add=
82445ffd6003Smrg	    lib_linked=yes
82455ffd6003Smrg	    case $hardcode_action in
82465ffd6003Smrg	    immediate | unsupported)
8247b7d26471Smrg	      if test no = "$hardcode_direct"; then
8248b7d26471Smrg		add=$dir/$linklib
82495ffd6003Smrg		case $host in
8250b7d26471Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8251b7d26471Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
82525ffd6003Smrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8253b7d26471Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
82545ffd6003Smrg		  *-*-darwin* )
8255b7d26471Smrg		    # if the lib is a (non-dlopened) module then we cannot
82565ffd6003Smrg		    # link against it, someone is ignoring the earlier warnings
82575ffd6003Smrg		    if /usr/bin/file -L $add 2> /dev/null |
8258b7d26471Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
82595ffd6003Smrg		      if test "X$dlopenmodule" != "X$lib"; then
82605ffd6003Smrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8261b7d26471Smrg			if test -z "$old_library"; then
8262629baa8cSmrg			  echo
8263629baa8cSmrg			  echo "*** And there doesn't seem to be a static archive available"
8264629baa8cSmrg			  echo "*** The link will probably fail, sorry"
82655ffd6003Smrg			else
8266b7d26471Smrg			  add=$dir/$old_library
82675ffd6003Smrg			fi
82685ffd6003Smrg		      elif test -n "$old_library"; then
8269b7d26471Smrg			add=$dir/$old_library
82705ffd6003Smrg		      fi
82715ffd6003Smrg		    fi
82725ffd6003Smrg		esac
8273b7d26471Smrg	      elif test no = "$hardcode_minus_L"; then
82745ffd6003Smrg		case $host in
8275b7d26471Smrg		*-*-sunos*) add_shlibpath=$dir ;;
82765ffd6003Smrg		esac
8277b7d26471Smrg		add_dir=-L$dir
8278b7d26471Smrg		add=-l$name
8279b7d26471Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8280b7d26471Smrg		add_shlibpath=$dir
8281b7d26471Smrg		add=-l$name
82825ffd6003Smrg	      else
82835ffd6003Smrg		lib_linked=no
82845ffd6003Smrg	      fi
82855ffd6003Smrg	      ;;
82865ffd6003Smrg	    relink)
8287b7d26471Smrg	      if test yes = "$hardcode_direct" &&
8288b7d26471Smrg	         test no = "$hardcode_direct_absolute"; then
8289b7d26471Smrg		add=$dir/$linklib
8290b7d26471Smrg	      elif test yes = "$hardcode_minus_L"; then
8291b7d26471Smrg		add_dir=-L$absdir
82925ffd6003Smrg		# Try looking first in the location we're being installed to.
82935ffd6003Smrg		if test -n "$inst_prefix_dir"; then
82945ffd6003Smrg		  case $libdir in
82955ffd6003Smrg		    [\\/]*)
8296629baa8cSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
82975ffd6003Smrg		      ;;
82985ffd6003Smrg		  esac
82995ffd6003Smrg		fi
8300b7d26471Smrg		add=-l$name
8301b7d26471Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8302b7d26471Smrg		add_shlibpath=$dir
8303b7d26471Smrg		add=-l$name
83045ffd6003Smrg	      else
83055ffd6003Smrg		lib_linked=no
83065ffd6003Smrg	      fi
83075ffd6003Smrg	      ;;
83085ffd6003Smrg	    *) lib_linked=no ;;
83095ffd6003Smrg	    esac
83105ffd6003Smrg
8311b7d26471Smrg	    if test yes != "$lib_linked"; then
83125ffd6003Smrg	      func_fatal_configuration "unsupported hardcode properties"
83135ffd6003Smrg	    fi
83145ffd6003Smrg
83155ffd6003Smrg	    if test -n "$add_shlibpath"; then
83165ffd6003Smrg	      case :$compile_shlibpath: in
83175ffd6003Smrg	      *":$add_shlibpath:"*) ;;
8318629baa8cSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
83195ffd6003Smrg	      esac
83205ffd6003Smrg	    fi
8321b7d26471Smrg	    if test prog = "$linkmode"; then
83225ffd6003Smrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
83235ffd6003Smrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
83245ffd6003Smrg	    else
83255ffd6003Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
83265ffd6003Smrg	      test -n "$add" && deplibs="$add $deplibs"
8327b7d26471Smrg	      if test yes != "$hardcode_direct" &&
8328b7d26471Smrg		 test yes != "$hardcode_minus_L" &&
8329b7d26471Smrg		 test yes = "$hardcode_shlibpath_var"; then
83305ffd6003Smrg		case :$finalize_shlibpath: in
83315ffd6003Smrg		*":$libdir:"*) ;;
8332629baa8cSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
83335ffd6003Smrg		esac
83345ffd6003Smrg	      fi
83355ffd6003Smrg	    fi
83365ffd6003Smrg	  fi
83375ffd6003Smrg
8338b7d26471Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
83395ffd6003Smrg	    add_shlibpath=
83405ffd6003Smrg	    add_dir=
83415ffd6003Smrg	    add=
83425ffd6003Smrg	    # Finalize command for both is simple: just hardcode it.
8343b7d26471Smrg	    if test yes = "$hardcode_direct" &&
8344b7d26471Smrg	       test no = "$hardcode_direct_absolute"; then
8345b7d26471Smrg	      add=$libdir/$linklib
8346b7d26471Smrg	    elif test yes = "$hardcode_minus_L"; then
8347b7d26471Smrg	      add_dir=-L$libdir
8348b7d26471Smrg	      add=-l$name
8349b7d26471Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
83505ffd6003Smrg	      case :$finalize_shlibpath: in
83515ffd6003Smrg	      *":$libdir:"*) ;;
8352629baa8cSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
83535ffd6003Smrg	      esac
8354b7d26471Smrg	      add=-l$name
8355b7d26471Smrg	    elif test yes = "$hardcode_automatic"; then
83565ffd6003Smrg	      if test -n "$inst_prefix_dir" &&
8357b7d26471Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8358b7d26471Smrg		add=$inst_prefix_dir$libdir/$linklib
83595ffd6003Smrg	      else
8360b7d26471Smrg		add=$libdir/$linklib
83615ffd6003Smrg	      fi
83625ffd6003Smrg	    else
83635ffd6003Smrg	      # We cannot seem to hardcode it, guess we'll fake it.
8364b7d26471Smrg	      add_dir=-L$libdir
83655ffd6003Smrg	      # Try looking first in the location we're being installed to.
83665ffd6003Smrg	      if test -n "$inst_prefix_dir"; then
83675ffd6003Smrg		case $libdir in
83685ffd6003Smrg		  [\\/]*)
8369629baa8cSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
83705ffd6003Smrg		    ;;
83715ffd6003Smrg		esac
83725ffd6003Smrg	      fi
8373b7d26471Smrg	      add=-l$name
83745ffd6003Smrg	    fi
83755ffd6003Smrg
8376b7d26471Smrg	    if test prog = "$linkmode"; then
83775ffd6003Smrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
83785ffd6003Smrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
83795ffd6003Smrg	    else
83805ffd6003Smrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
83815ffd6003Smrg	      test -n "$add" && deplibs="$add $deplibs"
83825ffd6003Smrg	    fi
83835ffd6003Smrg	  fi
8384b7d26471Smrg	elif test prog = "$linkmode"; then
83855ffd6003Smrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
83865ffd6003Smrg	  # is not unsupported.  This is valid on all known static and
83875ffd6003Smrg	  # shared platforms.
8388b7d26471Smrg	  if test unsupported != "$hardcode_direct"; then
8389b7d26471Smrg	    test -n "$old_library" && linklib=$old_library
83905ffd6003Smrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
83915ffd6003Smrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
83925ffd6003Smrg	  else
83935ffd6003Smrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
83945ffd6003Smrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
83955ffd6003Smrg	  fi
8396b7d26471Smrg	elif test yes = "$build_libtool_libs"; then
83975ffd6003Smrg	  # Not a shared library
8398b7d26471Smrg	  if test pass_all != "$deplibs_check_method"; then
83995ffd6003Smrg	    # We're trying link a shared library against a static one
84005ffd6003Smrg	    # but the system doesn't support it.
84015ffd6003Smrg
84025ffd6003Smrg	    # Just print a warning and add the library to dependency_libs so
84035ffd6003Smrg	    # that the program can be linked against the static library.
8404629baa8cSmrg	    echo
8405b7d26471Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8406629baa8cSmrg	    echo "*** I have the capability to make that library automatically link in when"
8407629baa8cSmrg	    echo "*** you link to this library.  But I can only do this if you have a"
8408629baa8cSmrg	    echo "*** shared version of the library, which you do not appear to have."
8409b7d26471Smrg	    if test yes = "$module"; then
8410629baa8cSmrg	      echo "*** But as you try to build a module library, libtool will still create "
8411629baa8cSmrg	      echo "*** a static module, that should work as long as the dlopening application"
8412629baa8cSmrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
84135ffd6003Smrg	      if test -z "$global_symbol_pipe"; then
8414629baa8cSmrg		echo
8415629baa8cSmrg		echo "*** However, this would only work if libtool was able to extract symbol"
8416b7d26471Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8417629baa8cSmrg		echo "*** not find such a program.  So, this module is probably useless."
8418b7d26471Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
84195ffd6003Smrg	      fi
8420b7d26471Smrg	      if test no = "$build_old_libs"; then
84215ffd6003Smrg		build_libtool_libs=module
84225ffd6003Smrg		build_old_libs=yes
84235ffd6003Smrg	      else
84245ffd6003Smrg		build_libtool_libs=no
84255ffd6003Smrg	      fi
84265ffd6003Smrg	    fi
84275ffd6003Smrg	  else
84285ffd6003Smrg	    deplibs="$dir/$old_library $deplibs"
84295ffd6003Smrg	    link_static=yes
84305ffd6003Smrg	  fi
84315ffd6003Smrg	fi # link shared/static library?
84325ffd6003Smrg
8433b7d26471Smrg	if test lib = "$linkmode"; then
84345ffd6003Smrg	  if test -n "$dependency_libs" &&
8435b7d26471Smrg	     { test yes != "$hardcode_into_libs" ||
8436b7d26471Smrg	       test yes = "$build_old_libs" ||
8437b7d26471Smrg	       test yes = "$link_static"; }; then
84385ffd6003Smrg	    # Extract -R from dependency_libs
84395ffd6003Smrg	    temp_deplibs=
84405ffd6003Smrg	    for libdir in $dependency_libs; do
84415ffd6003Smrg	      case $libdir in
84425ffd6003Smrg	      -R*) func_stripname '-R' '' "$libdir"
84435ffd6003Smrg	           temp_xrpath=$func_stripname_result
84445ffd6003Smrg		   case " $xrpath " in
84455ffd6003Smrg		   *" $temp_xrpath "*) ;;
8446629baa8cSmrg		   *) func_append xrpath " $temp_xrpath";;
84475ffd6003Smrg		   esac;;
8448629baa8cSmrg	      *) func_append temp_deplibs " $libdir";;
84495ffd6003Smrg	      esac
84505ffd6003Smrg	    done
8451b7d26471Smrg	    dependency_libs=$temp_deplibs
84525ffd6003Smrg	  fi
84535ffd6003Smrg
8454629baa8cSmrg	  func_append newlib_search_path " $absdir"
84555ffd6003Smrg	  # Link against this library
8456b7d26471Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
84575ffd6003Smrg	  # ... and its dependency_libs
84585ffd6003Smrg	  tmp_libs=
84595ffd6003Smrg	  for deplib in $dependency_libs; do
84605ffd6003Smrg	    newdependency_libs="$deplib $newdependency_libs"
8461629baa8cSmrg	    case $deplib in
8462629baa8cSmrg              -L*) func_stripname '-L' '' "$deplib"
8463629baa8cSmrg                   func_resolve_sysroot "$func_stripname_result";;
8464629baa8cSmrg              *) func_resolve_sysroot "$deplib" ;;
8465629baa8cSmrg            esac
8466b7d26471Smrg	    if $opt_preserve_dup_deps; then
84675ffd6003Smrg	      case "$tmp_libs " in
8468629baa8cSmrg	      *" $func_resolve_sysroot_result "*)
8469629baa8cSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
84705ffd6003Smrg	      esac
84715ffd6003Smrg	    fi
8472629baa8cSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
84735ffd6003Smrg	  done
84745ffd6003Smrg
8475b7d26471Smrg	  if test no != "$link_all_deplibs"; then
84765ffd6003Smrg	    # Add the search paths of all dependency libraries
84775ffd6003Smrg	    for deplib in $dependency_libs; do
84785ffd6003Smrg	      path=
84795ffd6003Smrg	      case $deplib in
8480b7d26471Smrg	      -L*) path=$deplib ;;
84815ffd6003Smrg	      *.la)
8482629baa8cSmrg	        func_resolve_sysroot "$deplib"
8483629baa8cSmrg	        deplib=$func_resolve_sysroot_result
84845ffd6003Smrg	        func_dirname "$deplib" "" "."
8485629baa8cSmrg		dir=$func_dirname_result
84865ffd6003Smrg		# We need an absolute path.
84875ffd6003Smrg		case $dir in
8488b7d26471Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
84895ffd6003Smrg		*)
84905ffd6003Smrg		  absdir=`cd "$dir" && pwd`
84915ffd6003Smrg		  if test -z "$absdir"; then
8492b7d26471Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8493b7d26471Smrg		    absdir=$dir
84945ffd6003Smrg		  fi
84955ffd6003Smrg		  ;;
84965ffd6003Smrg		esac
84975ffd6003Smrg		if $GREP "^installed=no" $deplib > /dev/null; then
84985ffd6003Smrg		case $host in
84995ffd6003Smrg		*-*-darwin*)
85005ffd6003Smrg		  depdepl=
8501b7d26471Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8502b7d26471Smrg		  if test -n "$deplibrary_names"; then
8503b7d26471Smrg		    for tmp in $deplibrary_names; do
85045ffd6003Smrg		      depdepl=$tmp
85055ffd6003Smrg		    done
8506b7d26471Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8507b7d26471Smrg		      depdepl=$absdir/$objdir/$depdepl
8508b7d26471Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
85095ffd6003Smrg                      if test -z "$darwin_install_name"; then
8510b7d26471Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
85115ffd6003Smrg                      fi
8512b7d26471Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8513b7d26471Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
85145ffd6003Smrg		      path=
85155ffd6003Smrg		    fi
85165ffd6003Smrg		  fi
85175ffd6003Smrg		  ;;
85185ffd6003Smrg		*)
8519b7d26471Smrg		  path=-L$absdir/$objdir
85205ffd6003Smrg		  ;;
85215ffd6003Smrg		esac
85225ffd6003Smrg		else
8523b7d26471Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
85245ffd6003Smrg		  test -z "$libdir" && \
8525b7d26471Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
85265ffd6003Smrg		  test "$absdir" != "$libdir" && \
8527b7d26471Smrg		    func_warning "'$deplib' seems to be moved"
85285ffd6003Smrg
8529b7d26471Smrg		  path=-L$absdir
85305ffd6003Smrg		fi
85315ffd6003Smrg		;;
85325ffd6003Smrg	      esac
85335ffd6003Smrg	      case " $deplibs " in
85345ffd6003Smrg	      *" $path "*) ;;
85355ffd6003Smrg	      *) deplibs="$path $deplibs" ;;
85365ffd6003Smrg	      esac
85375ffd6003Smrg	    done
85385ffd6003Smrg	  fi # link_all_deplibs != no
85395ffd6003Smrg	fi # linkmode = lib
85405ffd6003Smrg      done # for deplib in $libs
8541b7d26471Smrg      if test link = "$pass"; then
8542b7d26471Smrg	if test prog = "$linkmode"; then
85435ffd6003Smrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
85445ffd6003Smrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
85455ffd6003Smrg	else
8546629baa8cSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
85475ffd6003Smrg	fi
85485ffd6003Smrg      fi
8549b7d26471Smrg      dependency_libs=$newdependency_libs
8550b7d26471Smrg      if test dlpreopen = "$pass"; then
85515ffd6003Smrg	# Link the dlpreopened libraries before other libraries
85525ffd6003Smrg	for deplib in $save_deplibs; do
85535ffd6003Smrg	  deplibs="$deplib $deplibs"
85545ffd6003Smrg	done
85555ffd6003Smrg      fi
8556b7d26471Smrg      if test dlopen != "$pass"; then
8557b7d26471Smrg	test conv = "$pass" || {
85585ffd6003Smrg	  # Make sure lib_search_path contains only unique directories.
85595ffd6003Smrg	  lib_search_path=
85605ffd6003Smrg	  for dir in $newlib_search_path; do
85615ffd6003Smrg	    case "$lib_search_path " in
85625ffd6003Smrg	    *" $dir "*) ;;
8563629baa8cSmrg	    *) func_append lib_search_path " $dir" ;;
85645ffd6003Smrg	    esac
85655ffd6003Smrg	  done
85665ffd6003Smrg	  newlib_search_path=
8567b7d26471Smrg	}
85685ffd6003Smrg
8569b7d26471Smrg	if test prog,link = "$linkmode,$pass"; then
85705ffd6003Smrg	  vars="compile_deplibs finalize_deplibs"
8571b7d26471Smrg	else
8572b7d26471Smrg	  vars=deplibs
85735ffd6003Smrg	fi
85745ffd6003Smrg	for var in $vars dependency_libs; do
85755ffd6003Smrg	  # Add libraries to $var in reverse order
85765ffd6003Smrg	  eval tmp_libs=\"\$$var\"
85775ffd6003Smrg	  new_libs=
85785ffd6003Smrg	  for deplib in $tmp_libs; do
85795ffd6003Smrg	    # FIXME: Pedantically, this is the right thing to do, so
85805ffd6003Smrg	    #        that some nasty dependency loop isn't accidentally
85815ffd6003Smrg	    #        broken:
85825ffd6003Smrg	    #new_libs="$deplib $new_libs"
85835ffd6003Smrg	    # Pragmatically, this seems to cause very few problems in
85845ffd6003Smrg	    # practice:
85855ffd6003Smrg	    case $deplib in
85865ffd6003Smrg	    -L*) new_libs="$deplib $new_libs" ;;
85875ffd6003Smrg	    -R*) ;;
85885ffd6003Smrg	    *)
85895ffd6003Smrg	      # And here is the reason: when a library appears more
85905ffd6003Smrg	      # than once as an explicit dependence of a library, or
85915ffd6003Smrg	      # is implicitly linked in more than once by the
85925ffd6003Smrg	      # compiler, it is considered special, and multiple
85935ffd6003Smrg	      # occurrences thereof are not removed.  Compare this
85945ffd6003Smrg	      # with having the same library being listed as a
85955ffd6003Smrg	      # dependency of multiple other libraries: in this case,
85965ffd6003Smrg	      # we know (pedantically, we assume) the library does not
85975ffd6003Smrg	      # need to be listed more than once, so we keep only the
85985ffd6003Smrg	      # last copy.  This is not always right, but it is rare
85995ffd6003Smrg	      # enough that we require users that really mean to play
86005ffd6003Smrg	      # such unportable linking tricks to link the library
86015ffd6003Smrg	      # using -Wl,-lname, so that libtool does not consider it
86025ffd6003Smrg	      # for duplicate removal.
86035ffd6003Smrg	      case " $specialdeplibs " in
86045ffd6003Smrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
86055ffd6003Smrg	      *)
86065ffd6003Smrg		case " $new_libs " in
86075ffd6003Smrg		*" $deplib "*) ;;
86085ffd6003Smrg		*) new_libs="$deplib $new_libs" ;;
86095ffd6003Smrg		esac
86105ffd6003Smrg		;;
86115ffd6003Smrg	      esac
86125ffd6003Smrg	      ;;
86135ffd6003Smrg	    esac
86145ffd6003Smrg	  done
86155ffd6003Smrg	  tmp_libs=
86165ffd6003Smrg	  for deplib in $new_libs; do
86175ffd6003Smrg	    case $deplib in
86185ffd6003Smrg	    -L*)
86195ffd6003Smrg	      case " $tmp_libs " in
86205ffd6003Smrg	      *" $deplib "*) ;;
8621629baa8cSmrg	      *) func_append tmp_libs " $deplib" ;;
86225ffd6003Smrg	      esac
86235ffd6003Smrg	      ;;
8624629baa8cSmrg	    *) func_append tmp_libs " $deplib" ;;
86255ffd6003Smrg	    esac
86265ffd6003Smrg	  done
86275ffd6003Smrg	  eval $var=\"$tmp_libs\"
86285ffd6003Smrg	done # for var
86295ffd6003Smrg      fi
8630b7d26471Smrg
8631b7d26471Smrg      # Add Sun CC postdeps if required:
8632b7d26471Smrg      test CXX = "$tagname" && {
8633b7d26471Smrg        case $host_os in
8634b7d26471Smrg        linux*)
8635b7d26471Smrg          case `$CC -V 2>&1 | sed 5q` in
8636b7d26471Smrg          *Sun\ C*) # Sun C++ 5.9
8637b7d26471Smrg            func_suncc_cstd_abi
8638b7d26471Smrg
8639b7d26471Smrg            if test no != "$suncc_use_cstd_abi"; then
8640b7d26471Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8641b7d26471Smrg            fi
8642b7d26471Smrg            ;;
8643b7d26471Smrg          esac
8644b7d26471Smrg          ;;
8645b7d26471Smrg
8646b7d26471Smrg        solaris*)
8647b7d26471Smrg          func_cc_basename "$CC"
8648b7d26471Smrg          case $func_cc_basename_result in
8649b7d26471Smrg          CC* | sunCC*)
8650b7d26471Smrg            func_suncc_cstd_abi
8651b7d26471Smrg
8652b7d26471Smrg            if test no != "$suncc_use_cstd_abi"; then
8653b7d26471Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8654b7d26471Smrg            fi
8655b7d26471Smrg            ;;
8656b7d26471Smrg          esac
8657b7d26471Smrg          ;;
8658b7d26471Smrg        esac
8659b7d26471Smrg      }
8660b7d26471Smrg
86615ffd6003Smrg      # Last step: remove runtime libs from dependency_libs
86625ffd6003Smrg      # (they stay in deplibs)
86635ffd6003Smrg      tmp_libs=
8664b7d26471Smrg      for i in $dependency_libs; do
86655ffd6003Smrg	case " $predeps $postdeps $compiler_lib_search_path " in
86665ffd6003Smrg	*" $i "*)
8667b7d26471Smrg	  i=
86685ffd6003Smrg	  ;;
86695ffd6003Smrg	esac
8670b7d26471Smrg	if test -n "$i"; then
8671629baa8cSmrg	  func_append tmp_libs " $i"
86725ffd6003Smrg	fi
86735ffd6003Smrg      done
86745ffd6003Smrg      dependency_libs=$tmp_libs
86755ffd6003Smrg    done # for pass
8676b7d26471Smrg    if test prog = "$linkmode"; then
8677b7d26471Smrg      dlfiles=$newdlfiles
86785ffd6003Smrg    fi
8679b7d26471Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8680b7d26471Smrg      dlprefiles=$newdlprefiles
86815ffd6003Smrg    fi
86825ffd6003Smrg
86835ffd6003Smrg    case $linkmode in
86845ffd6003Smrg    oldlib)
8685b7d26471Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8686b7d26471Smrg	func_warning "'-dlopen' is ignored for archives"
86875ffd6003Smrg      fi
86885ffd6003Smrg
86895ffd6003Smrg      case " $deplibs" in
86905ffd6003Smrg      *\ -l* | *\ -L*)
8691b7d26471Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
86925ffd6003Smrg      esac
86935ffd6003Smrg
86945ffd6003Smrg      test -n "$rpath" && \
8695b7d26471Smrg	func_warning "'-rpath' is ignored for archives"
86965ffd6003Smrg
86975ffd6003Smrg      test -n "$xrpath" && \
8698b7d26471Smrg	func_warning "'-R' is ignored for archives"
86995ffd6003Smrg
87005ffd6003Smrg      test -n "$vinfo" && \
8701b7d26471Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
87025ffd6003Smrg
87035ffd6003Smrg      test -n "$release" && \
8704b7d26471Smrg	func_warning "'-release' is ignored for archives"
87055ffd6003Smrg
87065ffd6003Smrg      test -n "$export_symbols$export_symbols_regex" && \
8707b7d26471Smrg	func_warning "'-export-symbols' is ignored for archives"
87085ffd6003Smrg
87095ffd6003Smrg      # Now set the variables for building old libraries.
87105ffd6003Smrg      build_libtool_libs=no
8711b7d26471Smrg      oldlibs=$output
8712629baa8cSmrg      func_append objs "$old_deplibs"
87135ffd6003Smrg      ;;
87145ffd6003Smrg
87155ffd6003Smrg    lib)
8716b7d26471Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
87175ffd6003Smrg      case $outputname in
87185ffd6003Smrg      lib*)
87195ffd6003Smrg	func_stripname 'lib' '.la' "$outputname"
87205ffd6003Smrg	name=$func_stripname_result
87215ffd6003Smrg	eval shared_ext=\"$shrext_cmds\"
87225ffd6003Smrg	eval libname=\"$libname_spec\"
87235ffd6003Smrg	;;
87245ffd6003Smrg      *)
8725b7d26471Smrg	test no = "$module" \
8726b7d26471Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
87275ffd6003Smrg
8728b7d26471Smrg	if test no != "$need_lib_prefix"; then
87295ffd6003Smrg	  # Add the "lib" prefix for modules if required
87305ffd6003Smrg	  func_stripname '' '.la' "$outputname"
87315ffd6003Smrg	  name=$func_stripname_result
87325ffd6003Smrg	  eval shared_ext=\"$shrext_cmds\"
87335ffd6003Smrg	  eval libname=\"$libname_spec\"
87345ffd6003Smrg	else
87355ffd6003Smrg	  func_stripname '' '.la' "$outputname"
87365ffd6003Smrg	  libname=$func_stripname_result
87375ffd6003Smrg	fi
87385ffd6003Smrg	;;
87395ffd6003Smrg      esac
87405ffd6003Smrg
87415ffd6003Smrg      if test -n "$objs"; then
8742b7d26471Smrg	if test pass_all != "$deplibs_check_method"; then
8743b7d26471Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
87445ffd6003Smrg	else
8745629baa8cSmrg	  echo
87465ffd6003Smrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
87475ffd6003Smrg	  $ECHO "*** objects $objs is not portable!"
8748629baa8cSmrg	  func_append libobjs " $objs"
87495ffd6003Smrg	fi
87505ffd6003Smrg      fi
87515ffd6003Smrg
8752b7d26471Smrg      test no = "$dlself" \
8753b7d26471Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
87545ffd6003Smrg
87555ffd6003Smrg      set dummy $rpath
87565ffd6003Smrg      shift
8757b7d26471Smrg      test 1 -lt "$#" \
8758b7d26471Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
87595ffd6003Smrg
8760b7d26471Smrg      install_libdir=$1
87615ffd6003Smrg
87625ffd6003Smrg      oldlibs=
87635ffd6003Smrg      if test -z "$rpath"; then
8764b7d26471Smrg	if test yes = "$build_libtool_libs"; then
87655ffd6003Smrg	  # Building a libtool convenience library.
8766b7d26471Smrg	  # Some compilers have problems with a '.al' extension so
87675ffd6003Smrg	  # convenience libraries should have the same extension an
87685ffd6003Smrg	  # archive normally would.
87695ffd6003Smrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
87705ffd6003Smrg	  build_libtool_libs=convenience
87715ffd6003Smrg	  build_old_libs=yes
87725ffd6003Smrg	fi
87735ffd6003Smrg
87745ffd6003Smrg	test -n "$vinfo" && \
8775b7d26471Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
87765ffd6003Smrg
87775ffd6003Smrg	test -n "$release" && \
8778b7d26471Smrg	  func_warning "'-release' is ignored for convenience libraries"
87795ffd6003Smrg      else
87805ffd6003Smrg
87815ffd6003Smrg	# Parse the version information argument.
8782b7d26471Smrg	save_ifs=$IFS; IFS=:
87835ffd6003Smrg	set dummy $vinfo 0 0 0
87845ffd6003Smrg	shift
8785b7d26471Smrg	IFS=$save_ifs
87865ffd6003Smrg
87875ffd6003Smrg	test -n "$7" && \
8788b7d26471Smrg	  func_fatal_help "too many parameters to '-version-info'"
87895ffd6003Smrg
87905ffd6003Smrg	# convert absolute version numbers to libtool ages
87915ffd6003Smrg	# this retains compatibility with .la files and attempts
87925ffd6003Smrg	# to make the code below a bit more comprehensible
87935ffd6003Smrg
87945ffd6003Smrg	case $vinfo_number in
87955ffd6003Smrg	yes)
8796b7d26471Smrg	  number_major=$1
8797b7d26471Smrg	  number_minor=$2
8798b7d26471Smrg	  number_revision=$3
87995ffd6003Smrg	  #
88005ffd6003Smrg	  # There are really only two kinds -- those that
88015ffd6003Smrg	  # use the current revision as the major version
88025ffd6003Smrg	  # and those that subtract age and use age as
88035ffd6003Smrg	  # a minor version.  But, then there is irix
8804b7d26471Smrg	  # that has an extra 1 added just for fun
88055ffd6003Smrg	  #
88065ffd6003Smrg	  case $version_type in
8807b7d26471Smrg	  # correct linux to gnu/linux during the next big refactor
8808b7d26471Smrg	  darwin|freebsd-elf|linux|osf|windows|none)
88095ffd6003Smrg	    func_arith $number_major + $number_minor
88105ffd6003Smrg	    current=$func_arith_result
8811b7d26471Smrg	    age=$number_minor
8812b7d26471Smrg	    revision=$number_revision
88135ffd6003Smrg	    ;;
8814b7d26471Smrg	  freebsd-aout|qnx|sunos)
8815b7d26471Smrg	    current=$number_major
8816b7d26471Smrg	    revision=$number_minor
8817b7d26471Smrg	    age=0
88185ffd6003Smrg	    ;;
88195ffd6003Smrg	  irix|nonstopux)
88205ffd6003Smrg	    func_arith $number_major + $number_minor
88215ffd6003Smrg	    current=$func_arith_result
8822b7d26471Smrg	    age=$number_minor
8823b7d26471Smrg	    revision=$number_minor
88245ffd6003Smrg	    lt_irix_increment=no
88255ffd6003Smrg	    ;;
88265ffd6003Smrg	  esac
88275ffd6003Smrg	  ;;
88285ffd6003Smrg	no)
8829b7d26471Smrg	  current=$1
8830b7d26471Smrg	  revision=$2
8831b7d26471Smrg	  age=$3
88325ffd6003Smrg	  ;;
88335ffd6003Smrg	esac
88345ffd6003Smrg
88355ffd6003Smrg	# Check that each of the things are valid numbers.
88365ffd6003Smrg	case $current in
88375ffd6003Smrg	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]) ;;
88385ffd6003Smrg	*)
8839b7d26471Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
8840b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
88415ffd6003Smrg	  ;;
88425ffd6003Smrg	esac
88435ffd6003Smrg
88445ffd6003Smrg	case $revision in
88455ffd6003Smrg	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]) ;;
88465ffd6003Smrg	*)
8847b7d26471Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
8848b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
88495ffd6003Smrg	  ;;
88505ffd6003Smrg	esac
88515ffd6003Smrg
88525ffd6003Smrg	case $age in
88535ffd6003Smrg	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]) ;;
88545ffd6003Smrg	*)
8855b7d26471Smrg	  func_error "AGE '$age' must be a nonnegative integer"
8856b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
88575ffd6003Smrg	  ;;
88585ffd6003Smrg	esac
88595ffd6003Smrg
88605ffd6003Smrg	if test "$age" -gt "$current"; then
8861b7d26471Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
8862b7d26471Smrg	  func_fatal_error "'$vinfo' is not valid version information"
88635ffd6003Smrg	fi
88645ffd6003Smrg
88655ffd6003Smrg	# Calculate the version variables.
88665ffd6003Smrg	major=
88675ffd6003Smrg	versuffix=
88685ffd6003Smrg	verstring=
88695ffd6003Smrg	case $version_type in
88705ffd6003Smrg	none) ;;
88715ffd6003Smrg
88725ffd6003Smrg	darwin)
88735ffd6003Smrg	  # Like Linux, but with the current version available in
88745ffd6003Smrg	  # verstring for coding it into the library header
88755ffd6003Smrg	  func_arith $current - $age
88765ffd6003Smrg	  major=.$func_arith_result
8877b7d26471Smrg	  versuffix=$major.$age.$revision
88785ffd6003Smrg	  # Darwin ld doesn't like 0 for these options...
88795ffd6003Smrg	  func_arith $current + 1
88805ffd6003Smrg	  minor_current=$func_arith_result
8881b7d26471Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
88825ffd6003Smrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8883b7d26471Smrg          # On Darwin other compilers
8884b7d26471Smrg          case $CC in
8885b7d26471Smrg              nagfor*)
8886b7d26471Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8887b7d26471Smrg                  ;;
8888b7d26471Smrg              *)
8889b7d26471Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8890b7d26471Smrg                  ;;
8891b7d26471Smrg          esac
88925ffd6003Smrg	  ;;
88935ffd6003Smrg
88945ffd6003Smrg	freebsd-aout)
8895b7d26471Smrg	  major=.$current
8896b7d26471Smrg	  versuffix=.$current.$revision
88975ffd6003Smrg	  ;;
88985ffd6003Smrg
88995ffd6003Smrg	freebsd-elf)
8900b7d26471Smrg	  func_arith $current - $age
8901b7d26471Smrg	  major=.$func_arith_result
8902b7d26471Smrg	  versuffix=$major.$age.$revision
89035ffd6003Smrg	  ;;
89045ffd6003Smrg
89055ffd6003Smrg	irix | nonstopux)
8906b7d26471Smrg	  if test no = "$lt_irix_increment"; then
89075ffd6003Smrg	    func_arith $current - $age
89085ffd6003Smrg	  else
89095ffd6003Smrg	    func_arith $current - $age + 1
89105ffd6003Smrg	  fi
89115ffd6003Smrg	  major=$func_arith_result
89125ffd6003Smrg
89135ffd6003Smrg	  case $version_type in
89145ffd6003Smrg	    nonstopux) verstring_prefix=nonstopux ;;
89155ffd6003Smrg	    *)         verstring_prefix=sgi ;;
89165ffd6003Smrg	  esac
8917b7d26471Smrg	  verstring=$verstring_prefix$major.$revision
89185ffd6003Smrg
89195ffd6003Smrg	  # Add in all the interfaces that we are compatible with.
89205ffd6003Smrg	  loop=$revision
8921b7d26471Smrg	  while test 0 -ne "$loop"; do
89225ffd6003Smrg	    func_arith $revision - $loop
89235ffd6003Smrg	    iface=$func_arith_result
89245ffd6003Smrg	    func_arith $loop - 1
89255ffd6003Smrg	    loop=$func_arith_result
8926b7d26471Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
89275ffd6003Smrg	  done
89285ffd6003Smrg
8929b7d26471Smrg	  # Before this point, $major must not contain '.'.
89305ffd6003Smrg	  major=.$major
8931b7d26471Smrg	  versuffix=$major.$revision
89325ffd6003Smrg	  ;;
89335ffd6003Smrg
8934b7d26471Smrg	linux) # correct to gnu/linux during the next big refactor
89355ffd6003Smrg	  func_arith $current - $age
89365ffd6003Smrg	  major=.$func_arith_result
8937b7d26471Smrg	  versuffix=$major.$age.$revision
89385ffd6003Smrg	  ;;
89395ffd6003Smrg
89405ffd6003Smrg	osf)
89415ffd6003Smrg	  func_arith $current - $age
89425ffd6003Smrg	  major=.$func_arith_result
8943b7d26471Smrg	  versuffix=.$current.$age.$revision
8944b7d26471Smrg	  verstring=$current.$age.$revision
89455ffd6003Smrg
89465ffd6003Smrg	  # Add in all the interfaces that we are compatible with.
89475ffd6003Smrg	  loop=$age
8948b7d26471Smrg	  while test 0 -ne "$loop"; do
89495ffd6003Smrg	    func_arith $current - $loop
89505ffd6003Smrg	    iface=$func_arith_result
89515ffd6003Smrg	    func_arith $loop - 1
89525ffd6003Smrg	    loop=$func_arith_result
8953b7d26471Smrg	    verstring=$verstring:$iface.0
89545ffd6003Smrg	  done
89555ffd6003Smrg
89565ffd6003Smrg	  # Make executables depend on our current version.
8957b7d26471Smrg	  func_append verstring ":$current.0"
89585ffd6003Smrg	  ;;
89595ffd6003Smrg
89605ffd6003Smrg	qnx)
8961b7d26471Smrg	  major=.$current
8962b7d26471Smrg	  versuffix=.$current
8963b7d26471Smrg	  ;;
8964b7d26471Smrg
8965b7d26471Smrg	sco)
8966b7d26471Smrg	  major=.$current
8967b7d26471Smrg	  versuffix=.$current
89685ffd6003Smrg	  ;;
89695ffd6003Smrg
89705ffd6003Smrg	sunos)
8971b7d26471Smrg	  major=.$current
8972b7d26471Smrg	  versuffix=.$current.$revision
89735ffd6003Smrg	  ;;
89745ffd6003Smrg
89755ffd6003Smrg	windows)
89765ffd6003Smrg	  # Use '-' rather than '.', since we only want one
8977b7d26471Smrg	  # extension on DOS 8.3 file systems.
89785ffd6003Smrg	  func_arith $current - $age
89795ffd6003Smrg	  major=$func_arith_result
8980b7d26471Smrg	  versuffix=-$major
89815ffd6003Smrg	  ;;
89825ffd6003Smrg
89835ffd6003Smrg	*)
8984b7d26471Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
89855ffd6003Smrg	  ;;
89865ffd6003Smrg	esac
89875ffd6003Smrg
89885ffd6003Smrg	# Clear the version info if we defaulted, and they specified a release.
89895ffd6003Smrg	if test -z "$vinfo" && test -n "$release"; then
89905ffd6003Smrg	  major=
89915ffd6003Smrg	  case $version_type in
89925ffd6003Smrg	  darwin)
89935ffd6003Smrg	    # we can't check for "0.0" in archive_cmds due to quoting
89945ffd6003Smrg	    # problems, so we reset it completely
89955ffd6003Smrg	    verstring=
89965ffd6003Smrg	    ;;
89975ffd6003Smrg	  *)
8998b7d26471Smrg	    verstring=0.0
89995ffd6003Smrg	    ;;
90005ffd6003Smrg	  esac
9001b7d26471Smrg	  if test no = "$need_version"; then
90025ffd6003Smrg	    versuffix=
90035ffd6003Smrg	  else
9004b7d26471Smrg	    versuffix=.0.0
90055ffd6003Smrg	  fi
90065ffd6003Smrg	fi
90075ffd6003Smrg
90085ffd6003Smrg	# Remove version info from name if versioning should be avoided
9009b7d26471Smrg	if test yes,no = "$avoid_version,$need_version"; then
90105ffd6003Smrg	  major=
90115ffd6003Smrg	  versuffix=
9012b7d26471Smrg	  verstring=
90135ffd6003Smrg	fi
90145ffd6003Smrg
90155ffd6003Smrg	# Check to see if the archive will have undefined symbols.
9016b7d26471Smrg	if test yes = "$allow_undefined"; then
9017b7d26471Smrg	  if test unsupported = "$allow_undefined_flag"; then
9018b7d26471Smrg	    if test yes = "$build_old_libs"; then
9019b7d26471Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9020b7d26471Smrg	      build_libtool_libs=no
9021b7d26471Smrg	    else
9022b7d26471Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9023b7d26471Smrg	    fi
90245ffd6003Smrg	  fi
90255ffd6003Smrg	else
90265ffd6003Smrg	  # Don't allow undefined symbols.
9027b7d26471Smrg	  allow_undefined_flag=$no_undefined_flag
90285ffd6003Smrg	fi
90295ffd6003Smrg
90305ffd6003Smrg      fi
90315ffd6003Smrg
9032b7d26471Smrg      func_generate_dlsyms "$libname" "$libname" :
9033629baa8cSmrg      func_append libobjs " $symfileobj"
9034b7d26471Smrg      test " " = "$libobjs" && libobjs=
90355ffd6003Smrg
9036b7d26471Smrg      if test relink != "$opt_mode"; then
90375ffd6003Smrg	# Remove our outputs, but don't remove object files since they
90385ffd6003Smrg	# may have been created when compiling PIC objects.
90395ffd6003Smrg	removelist=
90405ffd6003Smrg	tempremovelist=`$ECHO "$output_objdir/*"`
90415ffd6003Smrg	for p in $tempremovelist; do
90425ffd6003Smrg	  case $p in
90435ffd6003Smrg	    *.$objext | *.gcno)
90445ffd6003Smrg	       ;;
9045b7d26471Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9046b7d26471Smrg	       if test -n "$precious_files_regex"; then
90475ffd6003Smrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
90485ffd6003Smrg		 then
90495ffd6003Smrg		   continue
90505ffd6003Smrg		 fi
90515ffd6003Smrg	       fi
9052629baa8cSmrg	       func_append removelist " $p"
90535ffd6003Smrg	       ;;
90545ffd6003Smrg	    *) ;;
90555ffd6003Smrg	  esac
90565ffd6003Smrg	done
90575ffd6003Smrg	test -n "$removelist" && \
90585ffd6003Smrg	  func_show_eval "${RM}r \$removelist"
90595ffd6003Smrg      fi
90605ffd6003Smrg
90615ffd6003Smrg      # Now set the variables for building old libraries.
9062b7d26471Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9063629baa8cSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
90645ffd6003Smrg
90655ffd6003Smrg	# Transform .lo files to .o files.
9066b7d26471Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
90675ffd6003Smrg      fi
90685ffd6003Smrg
90695ffd6003Smrg      # Eliminate all temporary directories.
90705ffd6003Smrg      #for path in $notinst_path; do
9071629baa8cSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9072629baa8cSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9073629baa8cSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
90745ffd6003Smrg      #done
90755ffd6003Smrg
90765ffd6003Smrg      if test -n "$xrpath"; then
90775ffd6003Smrg	# If the user specified any rpath flags, then add them.
90785ffd6003Smrg	temp_xrpath=
90795ffd6003Smrg	for libdir in $xrpath; do
9080629baa8cSmrg	  func_replace_sysroot "$libdir"
9081629baa8cSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
90825ffd6003Smrg	  case "$finalize_rpath " in
90835ffd6003Smrg	  *" $libdir "*) ;;
9084629baa8cSmrg	  *) func_append finalize_rpath " $libdir" ;;
90855ffd6003Smrg	  esac
90865ffd6003Smrg	done
9087b7d26471Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
90885ffd6003Smrg	  dependency_libs="$temp_xrpath $dependency_libs"
90895ffd6003Smrg	fi
90905ffd6003Smrg      fi
90915ffd6003Smrg
90925ffd6003Smrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9093b7d26471Smrg      old_dlfiles=$dlfiles
90945ffd6003Smrg      dlfiles=
90955ffd6003Smrg      for lib in $old_dlfiles; do
90965ffd6003Smrg	case " $dlprefiles $dlfiles " in
90975ffd6003Smrg	*" $lib "*) ;;
9098629baa8cSmrg	*) func_append dlfiles " $lib" ;;
90995ffd6003Smrg	esac
91005ffd6003Smrg      done
91015ffd6003Smrg
91025ffd6003Smrg      # Make sure dlprefiles contains only unique files
9103b7d26471Smrg      old_dlprefiles=$dlprefiles
91045ffd6003Smrg      dlprefiles=
91055ffd6003Smrg      for lib in $old_dlprefiles; do
91065ffd6003Smrg	case "$dlprefiles " in
91075ffd6003Smrg	*" $lib "*) ;;
9108629baa8cSmrg	*) func_append dlprefiles " $lib" ;;
91095ffd6003Smrg	esac
91105ffd6003Smrg      done
91115ffd6003Smrg
9112b7d26471Smrg      if test yes = "$build_libtool_libs"; then
91135ffd6003Smrg	if test -n "$rpath"; then
91145ffd6003Smrg	  case $host in
9115629baa8cSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
91165ffd6003Smrg	    # these systems don't actually have a c library (as such)!
91175ffd6003Smrg	    ;;
91185ffd6003Smrg	  *-*-rhapsody* | *-*-darwin1.[012])
91195ffd6003Smrg	    # Rhapsody C library is in the System framework
9120629baa8cSmrg	    func_append deplibs " System.ltframework"
91215ffd6003Smrg	    ;;
91225ffd6003Smrg	  *-*-netbsd*)
91235ffd6003Smrg	    # Don't link with libc until the a.out ld.so is fixed.
91245ffd6003Smrg	    ;;
91255ffd6003Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
91265ffd6003Smrg	    # Do not include libc due to us having libc/libc_r.
91275ffd6003Smrg	    ;;
91285ffd6003Smrg	  *-*-sco3.2v5* | *-*-sco5v6*)
91295ffd6003Smrg	    # Causes problems with __ctype
91305ffd6003Smrg	    ;;
91315ffd6003Smrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
91325ffd6003Smrg	    # Compiler inserts libc in the correct place for threads to work
91335ffd6003Smrg	    ;;
91345ffd6003Smrg	  *)
91355ffd6003Smrg	    # Add libc to deplibs on all other systems if necessary.
9136b7d26471Smrg	    if test yes = "$build_libtool_need_lc"; then
9137629baa8cSmrg	      func_append deplibs " -lc"
91385ffd6003Smrg	    fi
91395ffd6003Smrg	    ;;
91405ffd6003Smrg	  esac
91415ffd6003Smrg	fi
91425ffd6003Smrg
91435ffd6003Smrg	# Transform deplibs into only deplibs that can be linked in shared.
91445ffd6003Smrg	name_save=$name
91455ffd6003Smrg	libname_save=$libname
91465ffd6003Smrg	release_save=$release
91475ffd6003Smrg	versuffix_save=$versuffix
91485ffd6003Smrg	major_save=$major
91495ffd6003Smrg	# I'm not sure if I'm treating the release correctly.  I think
91505ffd6003Smrg	# release should show up in the -l (ie -lgmp5) so we don't want to
91515ffd6003Smrg	# add it in twice.  Is that correct?
9152b7d26471Smrg	release=
9153b7d26471Smrg	versuffix=
9154b7d26471Smrg	major=
91555ffd6003Smrg	newdeplibs=
91565ffd6003Smrg	droppeddeps=no
91575ffd6003Smrg	case $deplibs_check_method in
91585ffd6003Smrg	pass_all)
91595ffd6003Smrg	  # Don't check for shared/static.  Everything works.
91605ffd6003Smrg	  # This might be a little naive.  We might want to check
91615ffd6003Smrg	  # whether the library exists or not.  But this is on
91625ffd6003Smrg	  # osf3 & osf4 and I'm not really sure... Just
91635ffd6003Smrg	  # implementing what was already the behavior.
91645ffd6003Smrg	  newdeplibs=$deplibs
91655ffd6003Smrg	  ;;
91665ffd6003Smrg	test_compile)
91675ffd6003Smrg	  # This code stresses the "libraries are programs" paradigm to its
91685ffd6003Smrg	  # limits. Maybe even breaks it.  We compile a program, linking it
91695ffd6003Smrg	  # against the deplibs as a proxy for the library.  Then we can check
91705ffd6003Smrg	  # whether they linked in statically or dynamically with ldd.
91715ffd6003Smrg	  $opt_dry_run || $RM conftest.c
91725ffd6003Smrg	  cat > conftest.c <<EOF
91735ffd6003Smrg	  int main() { return 0; }
91745ffd6003SmrgEOF
91755ffd6003Smrg	  $opt_dry_run || $RM conftest
91765ffd6003Smrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
91775ffd6003Smrg	    ldd_output=`ldd conftest`
91785ffd6003Smrg	    for i in $deplibs; do
91795ffd6003Smrg	      case $i in
91805ffd6003Smrg	      -l*)
91815ffd6003Smrg		func_stripname -l '' "$i"
91825ffd6003Smrg		name=$func_stripname_result
9183b7d26471Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
91845ffd6003Smrg		  case " $predeps $postdeps " in
91855ffd6003Smrg		  *" $i "*)
9186629baa8cSmrg		    func_append newdeplibs " $i"
9187b7d26471Smrg		    i=
91885ffd6003Smrg		    ;;
91895ffd6003Smrg		  esac
91905ffd6003Smrg		fi
9191b7d26471Smrg		if test -n "$i"; then
91925ffd6003Smrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
91935ffd6003Smrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
91945ffd6003Smrg		  set dummy $deplib_matches; shift
91955ffd6003Smrg		  deplib_match=$1
9196b7d26471Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9197629baa8cSmrg		    func_append newdeplibs " $i"
91985ffd6003Smrg		  else
91995ffd6003Smrg		    droppeddeps=yes
9200629baa8cSmrg		    echo
92015ffd6003Smrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9202629baa8cSmrg		    echo "*** I have the capability to make that library automatically link in when"
9203629baa8cSmrg		    echo "*** you link to this library.  But I can only do this if you have a"
9204629baa8cSmrg		    echo "*** shared version of the library, which I believe you do not have"
9205629baa8cSmrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9206629baa8cSmrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
92075ffd6003Smrg		  fi
92085ffd6003Smrg		fi
92095ffd6003Smrg		;;
92105ffd6003Smrg	      *)
9211629baa8cSmrg		func_append newdeplibs " $i"
92125ffd6003Smrg		;;
92135ffd6003Smrg	      esac
92145ffd6003Smrg	    done
92155ffd6003Smrg	  else
92165ffd6003Smrg	    # Error occurred in the first compile.  Let's try to salvage
92175ffd6003Smrg	    # the situation: Compile a separate program for each library.
92185ffd6003Smrg	    for i in $deplibs; do
92195ffd6003Smrg	      case $i in
92205ffd6003Smrg	      -l*)
92215ffd6003Smrg		func_stripname -l '' "$i"
92225ffd6003Smrg		name=$func_stripname_result
92235ffd6003Smrg		$opt_dry_run || $RM conftest
92245ffd6003Smrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
92255ffd6003Smrg		  ldd_output=`ldd conftest`
9226b7d26471Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
92275ffd6003Smrg		    case " $predeps $postdeps " in
92285ffd6003Smrg		    *" $i "*)
9229629baa8cSmrg		      func_append newdeplibs " $i"
9230b7d26471Smrg		      i=
92315ffd6003Smrg		      ;;
92325ffd6003Smrg		    esac
92335ffd6003Smrg		  fi
9234b7d26471Smrg		  if test -n "$i"; then
92355ffd6003Smrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
92365ffd6003Smrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
92375ffd6003Smrg		    set dummy $deplib_matches; shift
92385ffd6003Smrg		    deplib_match=$1
9239b7d26471Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9240629baa8cSmrg		      func_append newdeplibs " $i"
92415ffd6003Smrg		    else
92425ffd6003Smrg		      droppeddeps=yes
9243629baa8cSmrg		      echo
92445ffd6003Smrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9245629baa8cSmrg		      echo "*** I have the capability to make that library automatically link in when"
9246629baa8cSmrg		      echo "*** you link to this library.  But I can only do this if you have a"
9247629baa8cSmrg		      echo "*** shared version of the library, which you do not appear to have"
9248629baa8cSmrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9249629baa8cSmrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
92505ffd6003Smrg		    fi
92515ffd6003Smrg		  fi
92525ffd6003Smrg		else
92535ffd6003Smrg		  droppeddeps=yes
9254629baa8cSmrg		  echo
92555ffd6003Smrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9256629baa8cSmrg		  echo "*** make it link in!  You will probably need to install it or some"
9257629baa8cSmrg		  echo "*** library that it depends on before this library will be fully"
9258629baa8cSmrg		  echo "*** functional.  Installing it before continuing would be even better."
92595ffd6003Smrg		fi
92605ffd6003Smrg		;;
92615ffd6003Smrg	      *)
9262629baa8cSmrg		func_append newdeplibs " $i"
92635ffd6003Smrg		;;
92645ffd6003Smrg	      esac
92655ffd6003Smrg	    done
92665ffd6003Smrg	  fi
92675ffd6003Smrg	  ;;
92685ffd6003Smrg	file_magic*)
92695ffd6003Smrg	  set dummy $deplibs_check_method; shift
92705ffd6003Smrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
92715ffd6003Smrg	  for a_deplib in $deplibs; do
92725ffd6003Smrg	    case $a_deplib in
92735ffd6003Smrg	    -l*)
92745ffd6003Smrg	      func_stripname -l '' "$a_deplib"
92755ffd6003Smrg	      name=$func_stripname_result
9276b7d26471Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
92775ffd6003Smrg		case " $predeps $postdeps " in
92785ffd6003Smrg		*" $a_deplib "*)
9279629baa8cSmrg		  func_append newdeplibs " $a_deplib"
9280b7d26471Smrg		  a_deplib=
92815ffd6003Smrg		  ;;
92825ffd6003Smrg		esac
92835ffd6003Smrg	      fi
9284b7d26471Smrg	      if test -n "$a_deplib"; then
92855ffd6003Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9286629baa8cSmrg		if test -n "$file_magic_glob"; then
9287629baa8cSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9288629baa8cSmrg		else
9289629baa8cSmrg		  libnameglob=$libname
9290629baa8cSmrg		fi
9291b7d26471Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
92925ffd6003Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9293b7d26471Smrg		  if test yes = "$want_nocaseglob"; then
9294629baa8cSmrg		    shopt -s nocaseglob
9295629baa8cSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9296629baa8cSmrg		    $nocaseglob
9297629baa8cSmrg		  else
9298629baa8cSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9299629baa8cSmrg		  fi
93005ffd6003Smrg		  for potent_lib in $potential_libs; do
93015ffd6003Smrg		      # Follow soft links.
93025ffd6003Smrg		      if ls -lLd "$potent_lib" 2>/dev/null |
93035ffd6003Smrg			 $GREP " -> " >/dev/null; then
93045ffd6003Smrg			continue
93055ffd6003Smrg		      fi
93065ffd6003Smrg		      # The statement above tries to avoid entering an
93075ffd6003Smrg		      # endless loop below, in case of cyclic links.
93085ffd6003Smrg		      # We might still enter an endless loop, since a link
93095ffd6003Smrg		      # loop can be closed while we follow links,
93105ffd6003Smrg		      # but so what?
9311b7d26471Smrg		      potlib=$potent_lib
93125ffd6003Smrg		      while test -h "$potlib" 2>/dev/null; do
9313b7d26471Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
93145ffd6003Smrg			case $potliblink in
9315b7d26471Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9316b7d26471Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
93175ffd6003Smrg			esac
93185ffd6003Smrg		      done
93195ffd6003Smrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
93205ffd6003Smrg			 $SED -e 10q |
93215ffd6003Smrg			 $EGREP "$file_magic_regex" > /dev/null; then
9322629baa8cSmrg			func_append newdeplibs " $a_deplib"
9323b7d26471Smrg			a_deplib=
93245ffd6003Smrg			break 2
93255ffd6003Smrg		      fi
93265ffd6003Smrg		  done
93275ffd6003Smrg		done
93285ffd6003Smrg	      fi
9329b7d26471Smrg	      if test -n "$a_deplib"; then
93305ffd6003Smrg		droppeddeps=yes
9331629baa8cSmrg		echo
93325ffd6003Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9333629baa8cSmrg		echo "*** I have the capability to make that library automatically link in when"
9334629baa8cSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9335629baa8cSmrg		echo "*** shared version of the library, which you do not appear to have"
9336629baa8cSmrg		echo "*** because I did check the linker path looking for a file starting"
9337b7d26471Smrg		if test -z "$potlib"; then
93385ffd6003Smrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
93395ffd6003Smrg		else
93405ffd6003Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
93415ffd6003Smrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
93425ffd6003Smrg		fi
93435ffd6003Smrg	      fi
93445ffd6003Smrg	      ;;
93455ffd6003Smrg	    *)
93465ffd6003Smrg	      # Add a -L argument.
9347629baa8cSmrg	      func_append newdeplibs " $a_deplib"
93485ffd6003Smrg	      ;;
93495ffd6003Smrg	    esac
93505ffd6003Smrg	  done # Gone through all deplibs.
93515ffd6003Smrg	  ;;
93525ffd6003Smrg	match_pattern*)
93535ffd6003Smrg	  set dummy $deplibs_check_method; shift
93545ffd6003Smrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
93555ffd6003Smrg	  for a_deplib in $deplibs; do
93565ffd6003Smrg	    case $a_deplib in
93575ffd6003Smrg	    -l*)
93585ffd6003Smrg	      func_stripname -l '' "$a_deplib"
93595ffd6003Smrg	      name=$func_stripname_result
9360b7d26471Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
93615ffd6003Smrg		case " $predeps $postdeps " in
93625ffd6003Smrg		*" $a_deplib "*)
9363629baa8cSmrg		  func_append newdeplibs " $a_deplib"
9364b7d26471Smrg		  a_deplib=
93655ffd6003Smrg		  ;;
93665ffd6003Smrg		esac
93675ffd6003Smrg	      fi
9368b7d26471Smrg	      if test -n "$a_deplib"; then
93695ffd6003Smrg		libname=`eval "\\$ECHO \"$libname_spec\""`
93705ffd6003Smrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
93715ffd6003Smrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
93725ffd6003Smrg		  for potent_lib in $potential_libs; do
9373b7d26471Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9374629baa8cSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
93755ffd6003Smrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9376629baa8cSmrg		      func_append newdeplibs " $a_deplib"
9377b7d26471Smrg		      a_deplib=
93785ffd6003Smrg		      break 2
93795ffd6003Smrg		    fi
93805ffd6003Smrg		  done
93815ffd6003Smrg		done
93825ffd6003Smrg	      fi
9383b7d26471Smrg	      if test -n "$a_deplib"; then
93845ffd6003Smrg		droppeddeps=yes
9385629baa8cSmrg		echo
93865ffd6003Smrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9387629baa8cSmrg		echo "*** I have the capability to make that library automatically link in when"
9388629baa8cSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9389629baa8cSmrg		echo "*** shared version of the library, which you do not appear to have"
9390629baa8cSmrg		echo "*** because I did check the linker path looking for a file starting"
9391b7d26471Smrg		if test -z "$potlib"; then
93925ffd6003Smrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
93935ffd6003Smrg		else
93945ffd6003Smrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
93955ffd6003Smrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
93965ffd6003Smrg		fi
93975ffd6003Smrg	      fi
93985ffd6003Smrg	      ;;
93995ffd6003Smrg	    *)
94005ffd6003Smrg	      # Add a -L argument.
9401629baa8cSmrg	      func_append newdeplibs " $a_deplib"
94025ffd6003Smrg	      ;;
94035ffd6003Smrg	    esac
94045ffd6003Smrg	  done # Gone through all deplibs.
94055ffd6003Smrg	  ;;
94065ffd6003Smrg	none | unknown | *)
9407b7d26471Smrg	  newdeplibs=
9408629baa8cSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9409b7d26471Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9410b7d26471Smrg	    for i in $predeps $postdeps; do
94115ffd6003Smrg	      # can't use Xsed below, because $i might contain '/'
9412b7d26471Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
94135ffd6003Smrg	    done
94145ffd6003Smrg	  fi
9415629baa8cSmrg	  case $tmp_deplibs in
9416629baa8cSmrg	  *[!\	\ ]*)
9417629baa8cSmrg	    echo
9418b7d26471Smrg	    if test none = "$deplibs_check_method"; then
9419629baa8cSmrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
94205ffd6003Smrg	    else
9421629baa8cSmrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
94225ffd6003Smrg	    fi
9423629baa8cSmrg	    echo "*** All declared inter-library dependencies are being dropped."
94245ffd6003Smrg	    droppeddeps=yes
9425629baa8cSmrg	    ;;
9426629baa8cSmrg	  esac
94275ffd6003Smrg	  ;;
94285ffd6003Smrg	esac
94295ffd6003Smrg	versuffix=$versuffix_save
94305ffd6003Smrg	major=$major_save
94315ffd6003Smrg	release=$release_save
94325ffd6003Smrg	libname=$libname_save
94335ffd6003Smrg	name=$name_save
94345ffd6003Smrg
94355ffd6003Smrg	case $host in
94365ffd6003Smrg	*-*-rhapsody* | *-*-darwin1.[012])
94375ffd6003Smrg	  # On Rhapsody replace the C library with the System framework
9438629baa8cSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
94395ffd6003Smrg	  ;;
94405ffd6003Smrg	esac
94415ffd6003Smrg
9442b7d26471Smrg	if test yes = "$droppeddeps"; then
9443b7d26471Smrg	  if test yes = "$module"; then
9444629baa8cSmrg	    echo
9445629baa8cSmrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
94465ffd6003Smrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9447629baa8cSmrg	    echo "*** a static module, that should work as long as the dlopening"
9448629baa8cSmrg	    echo "*** application is linked with the -dlopen flag."
94495ffd6003Smrg	    if test -z "$global_symbol_pipe"; then
9450629baa8cSmrg	      echo
9451629baa8cSmrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9452b7d26471Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9453629baa8cSmrg	      echo "*** not find such a program.  So, this module is probably useless."
9454b7d26471Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
94555ffd6003Smrg	    fi
9456b7d26471Smrg	    if test no = "$build_old_libs"; then
9457b7d26471Smrg	      oldlibs=$output_objdir/$libname.$libext
94585ffd6003Smrg	      build_libtool_libs=module
94595ffd6003Smrg	      build_old_libs=yes
94605ffd6003Smrg	    else
94615ffd6003Smrg	      build_libtool_libs=no
94625ffd6003Smrg	    fi
94635ffd6003Smrg	  else
9464629baa8cSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9465629baa8cSmrg	    echo "*** automatically added whenever a program is linked with this library"
9466629baa8cSmrg	    echo "*** or is declared to -dlopen it."
94675ffd6003Smrg
9468b7d26471Smrg	    if test no = "$allow_undefined"; then
9469629baa8cSmrg	      echo
9470629baa8cSmrg	      echo "*** Since this library must not contain undefined symbols,"
9471629baa8cSmrg	      echo "*** because either the platform does not support them or"
9472629baa8cSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9473629baa8cSmrg	      echo "*** libtool will only create a static version of it."
9474b7d26471Smrg	      if test no = "$build_old_libs"; then
9475b7d26471Smrg		oldlibs=$output_objdir/$libname.$libext
94765ffd6003Smrg		build_libtool_libs=module
94775ffd6003Smrg		build_old_libs=yes
94785ffd6003Smrg	      else
94795ffd6003Smrg		build_libtool_libs=no
94805ffd6003Smrg	      fi
94815ffd6003Smrg	    fi
94825ffd6003Smrg	  fi
94835ffd6003Smrg	fi
94845ffd6003Smrg	# Done checking deplibs!
94855ffd6003Smrg	deplibs=$newdeplibs
94865ffd6003Smrg      fi
94875ffd6003Smrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
94885ffd6003Smrg      case $host in
94895ffd6003Smrg	*-*-darwin*)
9490629baa8cSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9491629baa8cSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9492629baa8cSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
94935ffd6003Smrg	  ;;
94945ffd6003Smrg      esac
94955ffd6003Smrg
94965ffd6003Smrg      # move library search paths that coincide with paths to not yet
94975ffd6003Smrg      # installed libraries to the beginning of the library search list
94985ffd6003Smrg      new_libs=
94995ffd6003Smrg      for path in $notinst_path; do
95005ffd6003Smrg	case " $new_libs " in
95015ffd6003Smrg	*" -L$path/$objdir "*) ;;
95025ffd6003Smrg	*)
95035ffd6003Smrg	  case " $deplibs " in
95045ffd6003Smrg	  *" -L$path/$objdir "*)
9505629baa8cSmrg	    func_append new_libs " -L$path/$objdir" ;;
95065ffd6003Smrg	  esac
95075ffd6003Smrg	  ;;
95085ffd6003Smrg	esac
95095ffd6003Smrg      done
95105ffd6003Smrg      for deplib in $deplibs; do
95115ffd6003Smrg	case $deplib in
95125ffd6003Smrg	-L*)
95135ffd6003Smrg	  case " $new_libs " in
95145ffd6003Smrg	  *" $deplib "*) ;;
9515629baa8cSmrg	  *) func_append new_libs " $deplib" ;;
95165ffd6003Smrg	  esac
95175ffd6003Smrg	  ;;
9518629baa8cSmrg	*) func_append new_libs " $deplib" ;;
95195ffd6003Smrg	esac
95205ffd6003Smrg      done
9521b7d26471Smrg      deplibs=$new_libs
95225ffd6003Smrg
95235ffd6003Smrg      # All the library-specific variables (install_libdir is set above).
95245ffd6003Smrg      library_names=
95255ffd6003Smrg      old_library=
95265ffd6003Smrg      dlname=
95275ffd6003Smrg
95285ffd6003Smrg      # Test again, we may have decided not to build it any more
9529b7d26471Smrg      if test yes = "$build_libtool_libs"; then
9530b7d26471Smrg	# Remove $wl instances when linking with ld.
9531b7d26471Smrg	# FIXME: should test the right _cmds variable.
9532b7d26471Smrg	case $archive_cmds in
9533b7d26471Smrg	  *\$LD\ *) wl= ;;
9534b7d26471Smrg        esac
9535b7d26471Smrg	if test yes = "$hardcode_into_libs"; then
95365ffd6003Smrg	  # Hardcode the library paths
95375ffd6003Smrg	  hardcode_libdirs=
95385ffd6003Smrg	  dep_rpath=
9539b7d26471Smrg	  rpath=$finalize_rpath
9540b7d26471Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
95415ffd6003Smrg	  for libdir in $rpath; do
95425ffd6003Smrg	    if test -n "$hardcode_libdir_flag_spec"; then
95435ffd6003Smrg	      if test -n "$hardcode_libdir_separator"; then
9544629baa8cSmrg		func_replace_sysroot "$libdir"
9545629baa8cSmrg		libdir=$func_replace_sysroot_result
95465ffd6003Smrg		if test -z "$hardcode_libdirs"; then
9547b7d26471Smrg		  hardcode_libdirs=$libdir
95485ffd6003Smrg		else
95495ffd6003Smrg		  # Just accumulate the unique libdirs.
95505ffd6003Smrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
95515ffd6003Smrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
95525ffd6003Smrg		    ;;
95535ffd6003Smrg		  *)
9554629baa8cSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
95555ffd6003Smrg		    ;;
95565ffd6003Smrg		  esac
95575ffd6003Smrg		fi
95585ffd6003Smrg	      else
95595ffd6003Smrg		eval flag=\"$hardcode_libdir_flag_spec\"
9560629baa8cSmrg		func_append dep_rpath " $flag"
95615ffd6003Smrg	      fi
95625ffd6003Smrg	    elif test -n "$runpath_var"; then
95635ffd6003Smrg	      case "$perm_rpath " in
95645ffd6003Smrg	      *" $libdir "*) ;;
9565b7d26471Smrg	      *) func_append perm_rpath " $libdir" ;;
95665ffd6003Smrg	      esac
95675ffd6003Smrg	    fi
95685ffd6003Smrg	  done
95695ffd6003Smrg	  # Substitute the hardcoded libdirs into the rpath.
95705ffd6003Smrg	  if test -n "$hardcode_libdir_separator" &&
95715ffd6003Smrg	     test -n "$hardcode_libdirs"; then
9572b7d26471Smrg	    libdir=$hardcode_libdirs
9573b7d26471Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
95745ffd6003Smrg	  fi
95755ffd6003Smrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
95765ffd6003Smrg	    # We should set the runpath_var.
95775ffd6003Smrg	    rpath=
95785ffd6003Smrg	    for dir in $perm_rpath; do
9579629baa8cSmrg	      func_append rpath "$dir:"
95805ffd6003Smrg	    done
95815ffd6003Smrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
95825ffd6003Smrg	  fi
95835ffd6003Smrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
95845ffd6003Smrg	fi
9585145b7b3cSmrg
9586b7d26471Smrg	shlibpath=$finalize_shlibpath
9587b7d26471Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
95885ffd6003Smrg	if test -n "$shlibpath"; then
95895ffd6003Smrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
95905ffd6003Smrg	fi
9591145b7b3cSmrg
95925ffd6003Smrg	# Get the real and link names of the library.
95935ffd6003Smrg	eval shared_ext=\"$shrext_cmds\"
95945ffd6003Smrg	eval library_names=\"$library_names_spec\"
95955ffd6003Smrg	set dummy $library_names
95965ffd6003Smrg	shift
9597b7d26471Smrg	realname=$1
95985ffd6003Smrg	shift
9599145b7b3cSmrg
96005ffd6003Smrg	if test -n "$soname_spec"; then
96015ffd6003Smrg	  eval soname=\"$soname_spec\"
96025ffd6003Smrg	else
9603b7d26471Smrg	  soname=$realname
96045ffd6003Smrg	fi
96055ffd6003Smrg	if test -z "$dlname"; then
96065ffd6003Smrg	  dlname=$soname
96075ffd6003Smrg	fi
9608145b7b3cSmrg
9609b7d26471Smrg	lib=$output_objdir/$realname
96105ffd6003Smrg	linknames=
96115ffd6003Smrg	for link
96125ffd6003Smrg	do
9613629baa8cSmrg	  func_append linknames " $link"
96145ffd6003Smrg	done
9615145b7b3cSmrg
96165ffd6003Smrg	# Use standard objects if they are pic
9617629baa8cSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
96185ffd6003Smrg	test "X$libobjs" = "X " && libobjs=
9619145b7b3cSmrg
96205ffd6003Smrg	delfiles=
96215ffd6003Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
96225ffd6003Smrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9623b7d26471Smrg	  export_symbols=$output_objdir/$libname.uexp
9624629baa8cSmrg	  func_append delfiles " $export_symbols"
96255ffd6003Smrg	fi
9626145b7b3cSmrg
96275ffd6003Smrg	orig_export_symbols=
96285ffd6003Smrg	case $host_os in
96295ffd6003Smrg	cygwin* | mingw* | cegcc*)
96305ffd6003Smrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
96315ffd6003Smrg	    # exporting using user supplied symfile
9632b7d26471Smrg	    func_dll_def_p "$export_symbols" || {
96335ffd6003Smrg	      # and it's NOT already a .def file. Must figure out
96345ffd6003Smrg	      # which of the given symbols are data symbols and tag
96355ffd6003Smrg	      # them as such. So, trigger use of export_symbols_cmds.
96365ffd6003Smrg	      # export_symbols gets reassigned inside the "prepare
96375ffd6003Smrg	      # the list of exported symbols" if statement, so the
96385ffd6003Smrg	      # include_expsyms logic still works.
9639b7d26471Smrg	      orig_export_symbols=$export_symbols
96405ffd6003Smrg	      export_symbols=
96415ffd6003Smrg	      always_export_symbols=yes
9642b7d26471Smrg	    }
96435ffd6003Smrg	  fi
96445ffd6003Smrg	  ;;
96455ffd6003Smrg	esac
9646145b7b3cSmrg
96475ffd6003Smrg	# Prepare the list of exported symbols
96485ffd6003Smrg	if test -z "$export_symbols"; then
9649b7d26471Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9650b7d26471Smrg	    func_verbose "generating symbol list for '$libname.la'"
9651b7d26471Smrg	    export_symbols=$output_objdir/$libname.exp
96525ffd6003Smrg	    $opt_dry_run || $RM $export_symbols
96535ffd6003Smrg	    cmds=$export_symbols_cmds
9654b7d26471Smrg	    save_ifs=$IFS; IFS='~'
9655629baa8cSmrg	    for cmd1 in $cmds; do
9656b7d26471Smrg	      IFS=$save_ifs
9657629baa8cSmrg	      # Take the normal branch if the nm_file_list_spec branch
9658629baa8cSmrg	      # doesn't work or if tool conversion is not needed.
9659629baa8cSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9660629baa8cSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9661629baa8cSmrg		  try_normal_branch=yes
9662629baa8cSmrg		  eval cmd=\"$cmd1\"
9663629baa8cSmrg		  func_len " $cmd"
9664629baa8cSmrg		  len=$func_len_result
9665629baa8cSmrg		  ;;
9666629baa8cSmrg		*)
9667629baa8cSmrg		  try_normal_branch=no
9668629baa8cSmrg		  ;;
9669629baa8cSmrg	      esac
9670b7d26471Smrg	      if test yes = "$try_normal_branch" \
9671629baa8cSmrg		 && { test "$len" -lt "$max_cmd_len" \
9672629baa8cSmrg		      || test "$max_cmd_len" -le -1; }
9673629baa8cSmrg	      then
9674629baa8cSmrg		func_show_eval "$cmd" 'exit $?'
9675629baa8cSmrg		skipped_export=false
9676629baa8cSmrg	      elif test -n "$nm_file_list_spec"; then
9677629baa8cSmrg		func_basename "$output"
9678629baa8cSmrg		output_la=$func_basename_result
9679629baa8cSmrg		save_libobjs=$libobjs
9680629baa8cSmrg		save_output=$output
9681b7d26471Smrg		output=$output_objdir/$output_la.nm
9682629baa8cSmrg		func_to_tool_file "$output"
9683629baa8cSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9684629baa8cSmrg		func_append delfiles " $output"
9685629baa8cSmrg		func_verbose "creating $NM input file list: $output"
9686629baa8cSmrg		for obj in $save_libobjs; do
9687629baa8cSmrg		  func_to_tool_file "$obj"
9688629baa8cSmrg		  $ECHO "$func_to_tool_file_result"
9689629baa8cSmrg		done > "$output"
9690629baa8cSmrg		eval cmd=\"$cmd1\"
96915ffd6003Smrg		func_show_eval "$cmd" 'exit $?'
9692629baa8cSmrg		output=$save_output
9693629baa8cSmrg		libobjs=$save_libobjs
96945ffd6003Smrg		skipped_export=false
96955ffd6003Smrg	      else
96965ffd6003Smrg		# The command line is too long to execute in one step.
96975ffd6003Smrg		func_verbose "using reloadable object file for export list..."
96985ffd6003Smrg		skipped_export=:
96995ffd6003Smrg		# Break out early, otherwise skipped_export may be
97005ffd6003Smrg		# set to false by a later but shorter cmd.
97015ffd6003Smrg		break
97025ffd6003Smrg	      fi
97035ffd6003Smrg	    done
9704b7d26471Smrg	    IFS=$save_ifs
9705b7d26471Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
97065ffd6003Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
97075ffd6003Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
97085ffd6003Smrg	    fi
97095ffd6003Smrg	  fi
9710145b7b3cSmrg	fi
9711145b7b3cSmrg
97125ffd6003Smrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9713b7d26471Smrg	  tmp_export_symbols=$export_symbols
9714b7d26471Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
9715629baa8cSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
97165ffd6003Smrg	fi
9717145b7b3cSmrg
9718b7d26471Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
97195ffd6003Smrg	  # The given exports_symbols file has to be filtered, so filter it.
9720b7d26471Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
97215ffd6003Smrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
9722b7d26471Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
97235ffd6003Smrg	  # though. Also, the filter scales superlinearly with the number of
97245ffd6003Smrg	  # global variables. join(1) would be nice here, but unfortunately
97255ffd6003Smrg	  # isn't a blessed tool.
97265ffd6003Smrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
9727629baa8cSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
97285ffd6003Smrg	  export_symbols=$output_objdir/$libname.def
97295ffd6003Smrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
97305ffd6003Smrg	fi
9731145b7b3cSmrg
97325ffd6003Smrg	tmp_deplibs=
97335ffd6003Smrg	for test_deplib in $deplibs; do
97345ffd6003Smrg	  case " $convenience " in
97355ffd6003Smrg	  *" $test_deplib "*) ;;
97365ffd6003Smrg	  *)
9737629baa8cSmrg	    func_append tmp_deplibs " $test_deplib"
97385ffd6003Smrg	    ;;
97395ffd6003Smrg	  esac
97405ffd6003Smrg	done
9741b7d26471Smrg	deplibs=$tmp_deplibs
9742145b7b3cSmrg
97435ffd6003Smrg	if test -n "$convenience"; then
97445ffd6003Smrg	  if test -n "$whole_archive_flag_spec" &&
9745b7d26471Smrg	    test yes = "$compiler_needs_object" &&
97465ffd6003Smrg	    test -z "$libobjs"; then
97475ffd6003Smrg	    # extract the archives, so we have objects to list.
97485ffd6003Smrg	    # TODO: could optimize this to just extract one archive.
97495ffd6003Smrg	    whole_archive_flag_spec=
97505ffd6003Smrg	  fi
97515ffd6003Smrg	  if test -n "$whole_archive_flag_spec"; then
97525ffd6003Smrg	    save_libobjs=$libobjs
97535ffd6003Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
97545ffd6003Smrg	    test "X$libobjs" = "X " && libobjs=
97555ffd6003Smrg	  else
9756b7d26471Smrg	    gentop=$output_objdir/${outputname}x
9757629baa8cSmrg	    func_append generated " $gentop"
9758145b7b3cSmrg
97595ffd6003Smrg	    func_extract_archives $gentop $convenience
9760629baa8cSmrg	    func_append libobjs " $func_extract_archives_result"
97615ffd6003Smrg	    test "X$libobjs" = "X " && libobjs=
97625ffd6003Smrg	  fi
9763145b7b3cSmrg	fi
9764145b7b3cSmrg
9765b7d26471Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
97665ffd6003Smrg	  eval flag=\"$thread_safe_flag_spec\"
9767629baa8cSmrg	  func_append linker_flags " $flag"
9768145b7b3cSmrg	fi
9769145b7b3cSmrg
97705ffd6003Smrg	# Make a backup of the uninstalled library when relinking
9771b7d26471Smrg	if test relink = "$opt_mode"; then
97725ffd6003Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
97735ffd6003Smrg	fi
9774145b7b3cSmrg
97755ffd6003Smrg	# Do each of the archive commands.
9776b7d26471Smrg	if test yes = "$module" && test -n "$module_cmds"; then
97775ffd6003Smrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
97785ffd6003Smrg	    eval test_cmds=\"$module_expsym_cmds\"
97795ffd6003Smrg	    cmds=$module_expsym_cmds
97805ffd6003Smrg	  else
97815ffd6003Smrg	    eval test_cmds=\"$module_cmds\"
97825ffd6003Smrg	    cmds=$module_cmds
97835ffd6003Smrg	  fi
9784145b7b3cSmrg	else
97855ffd6003Smrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
97865ffd6003Smrg	    eval test_cmds=\"$archive_expsym_cmds\"
97875ffd6003Smrg	    cmds=$archive_expsym_cmds
97885ffd6003Smrg	  else
97895ffd6003Smrg	    eval test_cmds=\"$archive_cmds\"
97905ffd6003Smrg	    cmds=$archive_cmds
97915ffd6003Smrg	  fi
9792145b7b3cSmrg	fi
9793145b7b3cSmrg
9794b7d26471Smrg	if test : != "$skipped_export" &&
97955ffd6003Smrg	   func_len " $test_cmds" &&
97965ffd6003Smrg	   len=$func_len_result &&
97975ffd6003Smrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
97985ffd6003Smrg	  :
97995ffd6003Smrg	else
98005ffd6003Smrg	  # The command line is too long to link in one step, link piecewise
98015ffd6003Smrg	  # or, if using GNU ld and skipped_export is not :, use a linker
98025ffd6003Smrg	  # script.
9803145b7b3cSmrg
98045ffd6003Smrg	  # Save the value of $output and $libobjs because we want to
98055ffd6003Smrg	  # use them later.  If we have whole_archive_flag_spec, we
98065ffd6003Smrg	  # want to use save_libobjs as it was before
98075ffd6003Smrg	  # whole_archive_flag_spec was expanded, because we can't
98085ffd6003Smrg	  # assume the linker understands whole_archive_flag_spec.
98095ffd6003Smrg	  # This may have to be revisited, in case too many
98105ffd6003Smrg	  # convenience libraries get linked in and end up exceeding
98115ffd6003Smrg	  # the spec.
98125ffd6003Smrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
98135ffd6003Smrg	    save_libobjs=$libobjs
98145ffd6003Smrg	  fi
98155ffd6003Smrg	  save_output=$output
9816629baa8cSmrg	  func_basename "$output"
9817629baa8cSmrg	  output_la=$func_basename_result
9818145b7b3cSmrg
98195ffd6003Smrg	  # Clear the reloadable object creation command queue and
98205ffd6003Smrg	  # initialize k to one.
98215ffd6003Smrg	  test_cmds=
98225ffd6003Smrg	  concat_cmds=
98235ffd6003Smrg	  objlist=
98245ffd6003Smrg	  last_robj=
98255ffd6003Smrg	  k=1
98265ffd6003Smrg
9827b7d26471Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
9828b7d26471Smrg	    output=$output_objdir/$output_la.lnkscript
98295ffd6003Smrg	    func_verbose "creating GNU ld script: $output"
9830629baa8cSmrg	    echo 'INPUT (' > $output
98315ffd6003Smrg	    for obj in $save_libobjs
9832145b7b3cSmrg	    do
9833629baa8cSmrg	      func_to_tool_file "$obj"
9834629baa8cSmrg	      $ECHO "$func_to_tool_file_result" >> $output
98355ffd6003Smrg	    done
9836629baa8cSmrg	    echo ')' >> $output
9837629baa8cSmrg	    func_append delfiles " $output"
9838629baa8cSmrg	    func_to_tool_file "$output"
9839629baa8cSmrg	    output=$func_to_tool_file_result
9840b7d26471Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
9841b7d26471Smrg	    output=$output_objdir/$output_la.lnk
98425ffd6003Smrg	    func_verbose "creating linker input file list: $output"
98435ffd6003Smrg	    : > $output
98445ffd6003Smrg	    set x $save_libobjs
98455ffd6003Smrg	    shift
98465ffd6003Smrg	    firstobj=
9847b7d26471Smrg	    if test yes = "$compiler_needs_object"; then
98485ffd6003Smrg	      firstobj="$1 "
98495ffd6003Smrg	      shift
98505ffd6003Smrg	    fi
98515ffd6003Smrg	    for obj
98525ffd6003Smrg	    do
9853629baa8cSmrg	      func_to_tool_file "$obj"
9854629baa8cSmrg	      $ECHO "$func_to_tool_file_result" >> $output
98555ffd6003Smrg	    done
9856629baa8cSmrg	    func_append delfiles " $output"
9857629baa8cSmrg	    func_to_tool_file "$output"
9858629baa8cSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
98595ffd6003Smrg	  else
98605ffd6003Smrg	    if test -n "$save_libobjs"; then
98615ffd6003Smrg	      func_verbose "creating reloadable object files..."
9862b7d26471Smrg	      output=$output_objdir/$output_la-$k.$objext
98635ffd6003Smrg	      eval test_cmds=\"$reload_cmds\"
98645ffd6003Smrg	      func_len " $test_cmds"
98655ffd6003Smrg	      len0=$func_len_result
98665ffd6003Smrg	      len=$len0
98675ffd6003Smrg
98685ffd6003Smrg	      # Loop over the list of objects to be linked.
98695ffd6003Smrg	      for obj in $save_libobjs
98705ffd6003Smrg	      do
98715ffd6003Smrg		func_len " $obj"
98725ffd6003Smrg		func_arith $len + $func_len_result
98735ffd6003Smrg		len=$func_arith_result
9874b7d26471Smrg		if test -z "$objlist" ||
98755ffd6003Smrg		   test "$len" -lt "$max_cmd_len"; then
98765ffd6003Smrg		  func_append objlist " $obj"
98775ffd6003Smrg		else
98785ffd6003Smrg		  # The command $test_cmds is almost too long, add a
98795ffd6003Smrg		  # command to the queue.
9880b7d26471Smrg		  if test 1 -eq "$k"; then
98815ffd6003Smrg		    # The first file doesn't have a previous command to add.
9882629baa8cSmrg		    reload_objs=$objlist
9883629baa8cSmrg		    eval concat_cmds=\"$reload_cmds\"
98845ffd6003Smrg		  else
98855ffd6003Smrg		    # All subsequent reloadable object files will link in
98865ffd6003Smrg		    # the last one created.
9887629baa8cSmrg		    reload_objs="$objlist $last_robj"
9888629baa8cSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
98895ffd6003Smrg		  fi
9890b7d26471Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
98915ffd6003Smrg		  func_arith $k + 1
98925ffd6003Smrg		  k=$func_arith_result
9893b7d26471Smrg		  output=$output_objdir/$output_la-$k.$objext
9894629baa8cSmrg		  objlist=" $obj"
98955ffd6003Smrg		  func_len " $last_robj"
98965ffd6003Smrg		  func_arith $len0 + $func_len_result
98975ffd6003Smrg		  len=$func_arith_result
98985ffd6003Smrg		fi
98995ffd6003Smrg	      done
99005ffd6003Smrg	      # Handle the remaining objects by creating one last
99015ffd6003Smrg	      # reloadable object file.  All subsequent reloadable object
99025ffd6003Smrg	      # files will link in the last one created.
99035ffd6003Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
9904629baa8cSmrg	      reload_objs="$objlist $last_robj"
9905b7d26471Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
99065ffd6003Smrg	      if test -n "$last_robj"; then
9907b7d26471Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
99085ffd6003Smrg	      fi
9909629baa8cSmrg	      func_append delfiles " $output"
9910145b7b3cSmrg
99115ffd6003Smrg	    else
99125ffd6003Smrg	      output=
99135ffd6003Smrg	    fi
9914145b7b3cSmrg
9915b7d26471Smrg	    ${skipped_export-false} && {
9916b7d26471Smrg	      func_verbose "generating symbol list for '$libname.la'"
9917b7d26471Smrg	      export_symbols=$output_objdir/$libname.exp
99185ffd6003Smrg	      $opt_dry_run || $RM $export_symbols
99195ffd6003Smrg	      libobjs=$output
99205ffd6003Smrg	      # Append the command to create the export file.
99215ffd6003Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
99225ffd6003Smrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
99235ffd6003Smrg	      if test -n "$last_robj"; then
99245ffd6003Smrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
99255ffd6003Smrg	      fi
9926b7d26471Smrg	    }
9927145b7b3cSmrg
99285ffd6003Smrg	    test -n "$save_libobjs" &&
99295ffd6003Smrg	      func_verbose "creating a temporary reloadable object file: $output"
9930145b7b3cSmrg
99315ffd6003Smrg	    # Loop through the commands generated above and execute them.
9932b7d26471Smrg	    save_ifs=$IFS; IFS='~'
99335ffd6003Smrg	    for cmd in $concat_cmds; do
9934b7d26471Smrg	      IFS=$save_ifs
9935b7d26471Smrg	      $opt_quiet || {
99365ffd6003Smrg		  func_quote_for_expand "$cmd"
99375ffd6003Smrg		  eval "func_echo $func_quote_for_expand_result"
99385ffd6003Smrg	      }
99395ffd6003Smrg	      $opt_dry_run || eval "$cmd" || {
99405ffd6003Smrg		lt_exit=$?
99415ffd6003Smrg
99425ffd6003Smrg		# Restore the uninstalled library and exit
9943b7d26471Smrg		if test relink = "$opt_mode"; then
99445ffd6003Smrg		  ( cd "$output_objdir" && \
99455ffd6003Smrg		    $RM "${realname}T" && \
99465ffd6003Smrg		    $MV "${realname}U" "$realname" )
99475ffd6003Smrg		fi
9948145b7b3cSmrg
99495ffd6003Smrg		exit $lt_exit
99505ffd6003Smrg	      }
99515ffd6003Smrg	    done
9952b7d26471Smrg	    IFS=$save_ifs
9953145b7b3cSmrg
99545ffd6003Smrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
99555ffd6003Smrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
99565ffd6003Smrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9957145b7b3cSmrg	    fi
9958145b7b3cSmrg	  fi
9959145b7b3cSmrg
9960b7d26471Smrg          ${skipped_export-false} && {
99615ffd6003Smrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
9962b7d26471Smrg	      tmp_export_symbols=$export_symbols
9963b7d26471Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
9964629baa8cSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
99655ffd6003Smrg	    fi
9966145b7b3cSmrg
99675ffd6003Smrg	    if test -n "$orig_export_symbols"; then
99685ffd6003Smrg	      # The given exports_symbols file has to be filtered, so filter it.
9969b7d26471Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
99705ffd6003Smrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
9971b7d26471Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
99725ffd6003Smrg	      # though. Also, the filter scales superlinearly with the number of
99735ffd6003Smrg	      # global variables. join(1) would be nice here, but unfortunately
99745ffd6003Smrg	      # isn't a blessed tool.
99755ffd6003Smrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
9976629baa8cSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
99775ffd6003Smrg	      export_symbols=$output_objdir/$libname.def
99785ffd6003Smrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
99795ffd6003Smrg	    fi
9980b7d26471Smrg	  }
9981145b7b3cSmrg
99825ffd6003Smrg	  libobjs=$output
99835ffd6003Smrg	  # Restore the value of output.
99845ffd6003Smrg	  output=$save_output
9985145b7b3cSmrg
99865ffd6003Smrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
99875ffd6003Smrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
99885ffd6003Smrg	    test "X$libobjs" = "X " && libobjs=
99895ffd6003Smrg	  fi
99905ffd6003Smrg	  # Expand the library linking commands again to reset the
99915ffd6003Smrg	  # value of $libobjs for piecewise linking.
9992145b7b3cSmrg
99935ffd6003Smrg	  # Do each of the archive commands.
9994b7d26471Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
99955ffd6003Smrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
99965ffd6003Smrg	      cmds=$module_expsym_cmds
99975ffd6003Smrg	    else
99985ffd6003Smrg	      cmds=$module_cmds
9999145b7b3cSmrg	    fi
10000145b7b3cSmrg	  else
100015ffd6003Smrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
100025ffd6003Smrg	      cmds=$archive_expsym_cmds
100035ffd6003Smrg	    else
100045ffd6003Smrg	      cmds=$archive_cmds
100055ffd6003Smrg	    fi
10006145b7b3cSmrg	  fi
100075ffd6003Smrg	fi
10008145b7b3cSmrg
100095ffd6003Smrg	if test -n "$delfiles"; then
100105ffd6003Smrg	  # Append the command to remove temporary files to $cmds.
100115ffd6003Smrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
100125ffd6003Smrg	fi
10013145b7b3cSmrg
100145ffd6003Smrg	# Add any objects from preloaded convenience libraries
100155ffd6003Smrg	if test -n "$dlprefiles"; then
10016b7d26471Smrg	  gentop=$output_objdir/${outputname}x
10017629baa8cSmrg	  func_append generated " $gentop"
10018145b7b3cSmrg
100195ffd6003Smrg	  func_extract_archives $gentop $dlprefiles
10020629baa8cSmrg	  func_append libobjs " $func_extract_archives_result"
100215ffd6003Smrg	  test "X$libobjs" = "X " && libobjs=
100225ffd6003Smrg	fi
10023145b7b3cSmrg
10024b7d26471Smrg	save_ifs=$IFS; IFS='~'
100255ffd6003Smrg	for cmd in $cmds; do
10026b7d26471Smrg	  IFS=$sp$nl
100275ffd6003Smrg	  eval cmd=\"$cmd\"
10028b7d26471Smrg	  IFS=$save_ifs
10029b7d26471Smrg	  $opt_quiet || {
100305ffd6003Smrg	    func_quote_for_expand "$cmd"
100315ffd6003Smrg	    eval "func_echo $func_quote_for_expand_result"
100325ffd6003Smrg	  }
100335ffd6003Smrg	  $opt_dry_run || eval "$cmd" || {
100345ffd6003Smrg	    lt_exit=$?
10035145b7b3cSmrg
100365ffd6003Smrg	    # Restore the uninstalled library and exit
10037b7d26471Smrg	    if test relink = "$opt_mode"; then
100385ffd6003Smrg	      ( cd "$output_objdir" && \
100395ffd6003Smrg	        $RM "${realname}T" && \
100405ffd6003Smrg		$MV "${realname}U" "$realname" )
100415ffd6003Smrg	    fi
10042145b7b3cSmrg
100435ffd6003Smrg	    exit $lt_exit
100445ffd6003Smrg	  }
100455ffd6003Smrg	done
10046b7d26471Smrg	IFS=$save_ifs
10047145b7b3cSmrg
100485ffd6003Smrg	# Restore the uninstalled library and exit
10049b7d26471Smrg	if test relink = "$opt_mode"; then
100505ffd6003Smrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10051145b7b3cSmrg
100525ffd6003Smrg	  if test -n "$convenience"; then
100535ffd6003Smrg	    if test -z "$whole_archive_flag_spec"; then
100545ffd6003Smrg	      func_show_eval '${RM}r "$gentop"'
100555ffd6003Smrg	    fi
100565ffd6003Smrg	  fi
10057145b7b3cSmrg
100585ffd6003Smrg	  exit $EXIT_SUCCESS
100595ffd6003Smrg	fi
100605ffd6003Smrg
100615ffd6003Smrg	# Create links to the real library.
100625ffd6003Smrg	for linkname in $linknames; do
100635ffd6003Smrg	  if test "$realname" != "$linkname"; then
100645ffd6003Smrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10065145b7b3cSmrg	  fi
10066145b7b3cSmrg	done
10067145b7b3cSmrg
100685ffd6003Smrg	# If -module or -export-dynamic was specified, set the dlname.
10069b7d26471Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
100705ffd6003Smrg	  # On all known operating systems, these are identical.
10071b7d26471Smrg	  dlname=$soname
100725ffd6003Smrg	fi
100735ffd6003Smrg      fi
10074145b7b3cSmrg      ;;
10075145b7b3cSmrg
100765ffd6003Smrg    obj)
10077b7d26471Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10078b7d26471Smrg	func_warning "'-dlopen' is ignored for objects"
100795ffd6003Smrg      fi
10080145b7b3cSmrg
100815ffd6003Smrg      case " $deplibs" in
100825ffd6003Smrg      *\ -l* | *\ -L*)
10083b7d26471Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10084145b7b3cSmrg      esac
10085145b7b3cSmrg
100865ffd6003Smrg      test -n "$rpath" && \
10087b7d26471Smrg	func_warning "'-rpath' is ignored for objects"
100885ffd6003Smrg
100895ffd6003Smrg      test -n "$xrpath" && \
10090b7d26471Smrg	func_warning "'-R' is ignored for objects"
10091145b7b3cSmrg
100925ffd6003Smrg      test -n "$vinfo" && \
10093b7d26471Smrg	func_warning "'-version-info' is ignored for objects"
10094145b7b3cSmrg
100955ffd6003Smrg      test -n "$release" && \
10096b7d26471Smrg	func_warning "'-release' is ignored for objects"
100975ffd6003Smrg
100985ffd6003Smrg      case $output in
100995ffd6003Smrg      *.lo)
101005ffd6003Smrg	test -n "$objs$old_deplibs" && \
10101b7d26471Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
101025ffd6003Smrg
101035ffd6003Smrg	libobj=$output
101045ffd6003Smrg	func_lo2o "$libobj"
101055ffd6003Smrg	obj=$func_lo2o_result
10106145b7b3cSmrg	;;
10107145b7b3cSmrg      *)
101085ffd6003Smrg	libobj=
10109b7d26471Smrg	obj=$output
10110145b7b3cSmrg	;;
10111145b7b3cSmrg      esac
10112145b7b3cSmrg
101135ffd6003Smrg      # Delete the old objects.
101145ffd6003Smrg      $opt_dry_run || $RM $obj $libobj
10115145b7b3cSmrg
101165ffd6003Smrg      # Objects from convenience libraries.  This assumes
101175ffd6003Smrg      # single-version convenience libraries.  Whenever we create
101185ffd6003Smrg      # different ones for PIC/non-PIC, this we'll have to duplicate
101195ffd6003Smrg      # the extraction.
101205ffd6003Smrg      reload_conv_objs=
101215ffd6003Smrg      gentop=
10122b7d26471Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10123b7d26471Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10124b7d26471Smrg      # into space.
10125b7d26471Smrg      case $reload_cmds in
10126b7d26471Smrg        *\$LD[\ \$]*) wl= ;;
10127b7d26471Smrg      esac
101285ffd6003Smrg      if test -n "$convenience"; then
101295ffd6003Smrg	if test -n "$whole_archive_flag_spec"; then
101305ffd6003Smrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10131b7d26471Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10132b7d26471Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
101335ffd6003Smrg	else
10134b7d26471Smrg	  gentop=$output_objdir/${obj}x
10135629baa8cSmrg	  func_append generated " $gentop"
10136145b7b3cSmrg
101375ffd6003Smrg	  func_extract_archives $gentop $convenience
101385ffd6003Smrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
101395ffd6003Smrg	fi
10140145b7b3cSmrg      fi
10141145b7b3cSmrg
10142629baa8cSmrg      # If we're not building shared, we need to use non_pic_objs
10143b7d26471Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10144629baa8cSmrg
101455ffd6003Smrg      # Create the old-style object.
10146b7d26471Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10147145b7b3cSmrg
10148b7d26471Smrg      output=$obj
101495ffd6003Smrg      func_execute_cmds "$reload_cmds" 'exit $?'
10150145b7b3cSmrg
101515ffd6003Smrg      # Exit if we aren't doing a library object file.
101525ffd6003Smrg      if test -z "$libobj"; then
101535ffd6003Smrg	if test -n "$gentop"; then
101545ffd6003Smrg	  func_show_eval '${RM}r "$gentop"'
101555ffd6003Smrg	fi
101565ffd6003Smrg
101575ffd6003Smrg	exit $EXIT_SUCCESS
10158145b7b3cSmrg      fi
101595ffd6003Smrg
10160b7d26471Smrg      test yes = "$build_libtool_libs" || {
101615ffd6003Smrg	if test -n "$gentop"; then
101625ffd6003Smrg	  func_show_eval '${RM}r "$gentop"'
101635ffd6003Smrg	fi
101645ffd6003Smrg
101655ffd6003Smrg	# Create an invalid libtool object if no PIC, so that we don't
101665ffd6003Smrg	# accidentally link it into a program.
101675ffd6003Smrg	# $show "echo timestamp > $libobj"
101685ffd6003Smrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
101695ffd6003Smrg	exit $EXIT_SUCCESS
10170b7d26471Smrg      }
101715ffd6003Smrg
10172b7d26471Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
101735ffd6003Smrg	# Only do commands if we really have different PIC objects.
101745ffd6003Smrg	reload_objs="$libobjs $reload_conv_objs"
10175b7d26471Smrg	output=$libobj
101765ffd6003Smrg	func_execute_cmds "$reload_cmds" 'exit $?'
101775ffd6003Smrg      fi
101785ffd6003Smrg
101795ffd6003Smrg      if test -n "$gentop"; then
101805ffd6003Smrg	func_show_eval '${RM}r "$gentop"'
101815ffd6003Smrg      fi
101825ffd6003Smrg
101835ffd6003Smrg      exit $EXIT_SUCCESS
10184145b7b3cSmrg      ;;
10185145b7b3cSmrg
101865ffd6003Smrg    prog)
101875ffd6003Smrg      case $host in
101885ffd6003Smrg	*cygwin*) func_stripname '' '.exe' "$output"
101895ffd6003Smrg	          output=$func_stripname_result.exe;;
101905ffd6003Smrg      esac
101915ffd6003Smrg      test -n "$vinfo" && \
10192b7d26471Smrg	func_warning "'-version-info' is ignored for programs"
10193145b7b3cSmrg
101945ffd6003Smrg      test -n "$release" && \
10195b7d26471Smrg	func_warning "'-release' is ignored for programs"
10196145b7b3cSmrg
10197b7d26471Smrg      $preload \
10198b7d26471Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10199b7d26471Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
102005ffd6003Smrg
102015ffd6003Smrg      case $host in
102025ffd6003Smrg      *-*-rhapsody* | *-*-darwin1.[012])
102035ffd6003Smrg	# On Rhapsody replace the C library is the System framework
10204629baa8cSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10205629baa8cSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10206145b7b3cSmrg	;;
102075ffd6003Smrg      esac
10208145b7b3cSmrg
102095ffd6003Smrg      case $host in
102105ffd6003Smrg      *-*-darwin*)
102115ffd6003Smrg	# Don't allow lazy linking, it breaks C++ global constructors
102125ffd6003Smrg	# But is supposedly fixed on 10.4 or later (yay!).
10213b7d26471Smrg	if test CXX = "$tagname"; then
102145ffd6003Smrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
102155ffd6003Smrg	    10.[0123])
10216b7d26471Smrg	      func_append compile_command " $wl-bind_at_load"
10217b7d26471Smrg	      func_append finalize_command " $wl-bind_at_load"
102185ffd6003Smrg	    ;;
102195ffd6003Smrg	  esac
10220145b7b3cSmrg	fi
102215ffd6003Smrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10222629baa8cSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10223629baa8cSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
102245ffd6003Smrg	;;
102255ffd6003Smrg      esac
10226145b7b3cSmrg
10227145b7b3cSmrg
102285ffd6003Smrg      # move library search paths that coincide with paths to not yet
102295ffd6003Smrg      # installed libraries to the beginning of the library search list
102305ffd6003Smrg      new_libs=
102315ffd6003Smrg      for path in $notinst_path; do
102325ffd6003Smrg	case " $new_libs " in
102335ffd6003Smrg	*" -L$path/$objdir "*) ;;
102345ffd6003Smrg	*)
102355ffd6003Smrg	  case " $compile_deplibs " in
102365ffd6003Smrg	  *" -L$path/$objdir "*)
10237629baa8cSmrg	    func_append new_libs " -L$path/$objdir" ;;
10238145b7b3cSmrg	  esac
102395ffd6003Smrg	  ;;
102405ffd6003Smrg	esac
102415ffd6003Smrg      done
102425ffd6003Smrg      for deplib in $compile_deplibs; do
102435ffd6003Smrg	case $deplib in
102445ffd6003Smrg	-L*)
102455ffd6003Smrg	  case " $new_libs " in
102465ffd6003Smrg	  *" $deplib "*) ;;
10247629baa8cSmrg	  *) func_append new_libs " $deplib" ;;
10248145b7b3cSmrg	  esac
102495ffd6003Smrg	  ;;
10250629baa8cSmrg	*) func_append new_libs " $deplib" ;;
102515ffd6003Smrg	esac
102525ffd6003Smrg      done
10253b7d26471Smrg      compile_deplibs=$new_libs
10254145b7b3cSmrg
10255145b7b3cSmrg
10256629baa8cSmrg      func_append compile_command " $compile_deplibs"
10257629baa8cSmrg      func_append finalize_command " $finalize_deplibs"
10258145b7b3cSmrg
102595ffd6003Smrg      if test -n "$rpath$xrpath"; then
102605ffd6003Smrg	# If the user specified any rpath flags, then add them.
102615ffd6003Smrg	for libdir in $rpath $xrpath; do
102625ffd6003Smrg	  # This is the magic to use -rpath.
102635ffd6003Smrg	  case "$finalize_rpath " in
102645ffd6003Smrg	  *" $libdir "*) ;;
10265629baa8cSmrg	  *) func_append finalize_rpath " $libdir" ;;
102665ffd6003Smrg	  esac
102675ffd6003Smrg	done
102685ffd6003Smrg      fi
10269145b7b3cSmrg
102705ffd6003Smrg      # Now hardcode the library paths
102715ffd6003Smrg      rpath=
102725ffd6003Smrg      hardcode_libdirs=
102735ffd6003Smrg      for libdir in $compile_rpath $finalize_rpath; do
102745ffd6003Smrg	if test -n "$hardcode_libdir_flag_spec"; then
102755ffd6003Smrg	  if test -n "$hardcode_libdir_separator"; then
102765ffd6003Smrg	    if test -z "$hardcode_libdirs"; then
10277b7d26471Smrg	      hardcode_libdirs=$libdir
102785ffd6003Smrg	    else
102795ffd6003Smrg	      # Just accumulate the unique libdirs.
102805ffd6003Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
102815ffd6003Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
102825ffd6003Smrg		;;
102835ffd6003Smrg	      *)
10284629baa8cSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
102855ffd6003Smrg		;;
102865ffd6003Smrg	      esac
102875ffd6003Smrg	    fi
10288145b7b3cSmrg	  else
102895ffd6003Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10290629baa8cSmrg	    func_append rpath " $flag"
10291145b7b3cSmrg	  fi
102925ffd6003Smrg	elif test -n "$runpath_var"; then
102935ffd6003Smrg	  case "$perm_rpath " in
102945ffd6003Smrg	  *" $libdir "*) ;;
10295629baa8cSmrg	  *) func_append perm_rpath " $libdir" ;;
102965ffd6003Smrg	  esac
102975ffd6003Smrg	fi
102985ffd6003Smrg	case $host in
102995ffd6003Smrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10300b7d26471Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
103015ffd6003Smrg	  case :$dllsearchpath: in
103025ffd6003Smrg	  *":$libdir:"*) ;;
103035ffd6003Smrg	  ::) dllsearchpath=$libdir;;
10304629baa8cSmrg	  *) func_append dllsearchpath ":$libdir";;
103055ffd6003Smrg	  esac
103065ffd6003Smrg	  case :$dllsearchpath: in
103075ffd6003Smrg	  *":$testbindir:"*) ;;
103085ffd6003Smrg	  ::) dllsearchpath=$testbindir;;
10309629baa8cSmrg	  *) func_append dllsearchpath ":$testbindir";;
103105ffd6003Smrg	  esac
103115ffd6003Smrg	  ;;
103125ffd6003Smrg	esac
103135ffd6003Smrg      done
103145ffd6003Smrg      # Substitute the hardcoded libdirs into the rpath.
103155ffd6003Smrg      if test -n "$hardcode_libdir_separator" &&
103165ffd6003Smrg	 test -n "$hardcode_libdirs"; then
10317b7d26471Smrg	libdir=$hardcode_libdirs
103185ffd6003Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
103195ffd6003Smrg      fi
10320b7d26471Smrg      compile_rpath=$rpath
10321145b7b3cSmrg
103225ffd6003Smrg      rpath=
103235ffd6003Smrg      hardcode_libdirs=
103245ffd6003Smrg      for libdir in $finalize_rpath; do
103255ffd6003Smrg	if test -n "$hardcode_libdir_flag_spec"; then
103265ffd6003Smrg	  if test -n "$hardcode_libdir_separator"; then
103275ffd6003Smrg	    if test -z "$hardcode_libdirs"; then
10328b7d26471Smrg	      hardcode_libdirs=$libdir
103295ffd6003Smrg	    else
103305ffd6003Smrg	      # Just accumulate the unique libdirs.
103315ffd6003Smrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
103325ffd6003Smrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
103335ffd6003Smrg		;;
103345ffd6003Smrg	      *)
10335629baa8cSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
103365ffd6003Smrg		;;
103375ffd6003Smrg	      esac
103385ffd6003Smrg	    fi
10339145b7b3cSmrg	  else
103405ffd6003Smrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10341629baa8cSmrg	    func_append rpath " $flag"
10342145b7b3cSmrg	  fi
103435ffd6003Smrg	elif test -n "$runpath_var"; then
103445ffd6003Smrg	  case "$finalize_perm_rpath " in
103455ffd6003Smrg	  *" $libdir "*) ;;
10346629baa8cSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
103475ffd6003Smrg	  esac
10348145b7b3cSmrg	fi
103495ffd6003Smrg      done
103505ffd6003Smrg      # Substitute the hardcoded libdirs into the rpath.
103515ffd6003Smrg      if test -n "$hardcode_libdir_separator" &&
103525ffd6003Smrg	 test -n "$hardcode_libdirs"; then
10353b7d26471Smrg	libdir=$hardcode_libdirs
103545ffd6003Smrg	eval rpath=\" $hardcode_libdir_flag_spec\"
103555ffd6003Smrg      fi
10356b7d26471Smrg      finalize_rpath=$rpath
10357145b7b3cSmrg
10358b7d26471Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
103595ffd6003Smrg	# Transform all the library objects into standard objects.
10360629baa8cSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10361629baa8cSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
103625ffd6003Smrg      fi
10363145b7b3cSmrg
10364b7d26471Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10365145b7b3cSmrg
103665ffd6003Smrg      # template prelinking step
103675ffd6003Smrg      if test -n "$prelink_cmds"; then
103685ffd6003Smrg	func_execute_cmds "$prelink_cmds" 'exit $?'
103695ffd6003Smrg      fi
10370145b7b3cSmrg
10371b7d26471Smrg      wrappers_required=:
103725ffd6003Smrg      case $host in
10373629baa8cSmrg      *cegcc* | *mingw32ce*)
10374629baa8cSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10375b7d26471Smrg        wrappers_required=false
10376629baa8cSmrg        ;;
103775ffd6003Smrg      *cygwin* | *mingw* )
10378b7d26471Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
103795ffd6003Smrg        ;;
103805ffd6003Smrg      *)
10381b7d26471Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10382b7d26471Smrg          wrappers_required=false
103835ffd6003Smrg        fi
103845ffd6003Smrg        ;;
103855ffd6003Smrg      esac
10386b7d26471Smrg      $wrappers_required || {
103875ffd6003Smrg	# Replace the output file specification.
10388629baa8cSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10389b7d26471Smrg	link_command=$compile_command$compile_rpath
10390145b7b3cSmrg
103915ffd6003Smrg	# We have no uninstalled library dependencies, so finalize right now.
103925ffd6003Smrg	exit_status=0
103935ffd6003Smrg	func_show_eval "$link_command" 'exit_status=$?'
10394145b7b3cSmrg
10395629baa8cSmrg	if test -n "$postlink_cmds"; then
10396629baa8cSmrg	  func_to_tool_file "$output"
10397629baa8cSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10398629baa8cSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10399629baa8cSmrg	fi
10400629baa8cSmrg
104015ffd6003Smrg	# Delete the generated files.
10402b7d26471Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10403b7d26471Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10404145b7b3cSmrg	fi
10405145b7b3cSmrg
104065ffd6003Smrg	exit $exit_status
10407b7d26471Smrg      }
10408145b7b3cSmrg
104095ffd6003Smrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
104105ffd6003Smrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
104115ffd6003Smrg      fi
104125ffd6003Smrg      if test -n "$finalize_shlibpath"; then
104135ffd6003Smrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
104145ffd6003Smrg      fi
10415145b7b3cSmrg
104165ffd6003Smrg      compile_var=
104175ffd6003Smrg      finalize_var=
104185ffd6003Smrg      if test -n "$runpath_var"; then
104195ffd6003Smrg	if test -n "$perm_rpath"; then
104205ffd6003Smrg	  # We should set the runpath_var.
104215ffd6003Smrg	  rpath=
104225ffd6003Smrg	  for dir in $perm_rpath; do
10423629baa8cSmrg	    func_append rpath "$dir:"
104245ffd6003Smrg	  done
104255ffd6003Smrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10426145b7b3cSmrg	fi
104275ffd6003Smrg	if test -n "$finalize_perm_rpath"; then
104285ffd6003Smrg	  # We should set the runpath_var.
104295ffd6003Smrg	  rpath=
104305ffd6003Smrg	  for dir in $finalize_perm_rpath; do
10431629baa8cSmrg	    func_append rpath "$dir:"
104325ffd6003Smrg	  done
104335ffd6003Smrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10434145b7b3cSmrg	fi
104355ffd6003Smrg      fi
10436145b7b3cSmrg
10437b7d26471Smrg      if test yes = "$no_install"; then
104385ffd6003Smrg	# We don't need to create a wrapper script.
10439b7d26471Smrg	link_command=$compile_var$compile_command$compile_rpath
104405ffd6003Smrg	# Replace the output file specification.
10441629baa8cSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
104425ffd6003Smrg	# Delete the old output file.
104435ffd6003Smrg	$opt_dry_run || $RM $output
104445ffd6003Smrg	# Link the executable and exit
104455ffd6003Smrg	func_show_eval "$link_command" 'exit $?'
10446629baa8cSmrg
10447629baa8cSmrg	if test -n "$postlink_cmds"; then
10448629baa8cSmrg	  func_to_tool_file "$output"
10449629baa8cSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10450629baa8cSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10451629baa8cSmrg	fi
10452629baa8cSmrg
10453145b7b3cSmrg	exit $EXIT_SUCCESS
104545ffd6003Smrg      fi
10455145b7b3cSmrg
10456b7d26471Smrg      case $hardcode_action,$fast_install in
10457b7d26471Smrg        relink,*)
10458b7d26471Smrg	  # Fast installation is not supported
10459b7d26471Smrg	  link_command=$compile_var$compile_command$compile_rpath
10460b7d26471Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
104615ffd6003Smrg
10462b7d26471Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10463b7d26471Smrg	  func_warning "'$output' will be relinked during installation"
10464b7d26471Smrg	  ;;
10465b7d26471Smrg        *,yes)
10466b7d26471Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10467b7d26471Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10468b7d26471Smrg          ;;
10469b7d26471Smrg	*,no)
10470b7d26471Smrg	  link_command=$compile_var$compile_command$compile_rpath
10471b7d26471Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10472b7d26471Smrg          ;;
10473b7d26471Smrg	*,needless)
10474b7d26471Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10475b7d26471Smrg	  relink_command=
10476b7d26471Smrg          ;;
10477b7d26471Smrg      esac
10478145b7b3cSmrg
104795ffd6003Smrg      # Replace the output file specification.
10480629baa8cSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10481145b7b3cSmrg
104825ffd6003Smrg      # Delete the old output files.
104835ffd6003Smrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10484145b7b3cSmrg
104855ffd6003Smrg      func_show_eval "$link_command" 'exit $?'
10486145b7b3cSmrg
10487629baa8cSmrg      if test -n "$postlink_cmds"; then
10488629baa8cSmrg	func_to_tool_file "$output_objdir/$outputname"
10489629baa8cSmrg	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'`
10490629baa8cSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10491629baa8cSmrg      fi
10492629baa8cSmrg
104935ffd6003Smrg      # Now create the wrapper script.
104945ffd6003Smrg      func_verbose "creating $output"
10495145b7b3cSmrg
104965ffd6003Smrg      # Quote the relink command for shipping.
104975ffd6003Smrg      if test -n "$relink_command"; then
104985ffd6003Smrg	# Preserve any variables that may affect compiler behavior
104995ffd6003Smrg	for var in $variables_saved_for_relink; do
105005ffd6003Smrg	  if eval test -z \"\${$var+set}\"; then
105015ffd6003Smrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
105025ffd6003Smrg	  elif eval var_value=\$$var; test -z "$var_value"; then
105035ffd6003Smrg	    relink_command="$var=; export $var; $relink_command"
10504145b7b3cSmrg	  else
105055ffd6003Smrg	    func_quote_for_eval "$var_value"
105065ffd6003Smrg	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10507145b7b3cSmrg	  fi
105085ffd6003Smrg	done
105095ffd6003Smrg	relink_command="(cd `pwd`; $relink_command)"
10510629baa8cSmrg	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
105115ffd6003Smrg      fi
105125ffd6003Smrg
105135ffd6003Smrg      # Only actually do things if not in dry run mode.
105145ffd6003Smrg      $opt_dry_run || {
105155ffd6003Smrg	# win32 will think the script is a binary if it has
105165ffd6003Smrg	# a .exe suffix, so we strip it off here.
105175ffd6003Smrg	case $output in
105185ffd6003Smrg	  *.exe) func_stripname '' '.exe' "$output"
105195ffd6003Smrg	         output=$func_stripname_result ;;
105205ffd6003Smrg	esac
105215ffd6003Smrg	# test for cygwin because mv fails w/o .exe extensions
105225ffd6003Smrg	case $host in
105235ffd6003Smrg	  *cygwin*)
105245ffd6003Smrg	    exeext=.exe
105255ffd6003Smrg	    func_stripname '' '.exe' "$outputname"
105265ffd6003Smrg	    outputname=$func_stripname_result ;;
105275ffd6003Smrg	  *) exeext= ;;
10528145b7b3cSmrg	esac
105295ffd6003Smrg	case $host in
105305ffd6003Smrg	  *cygwin* | *mingw* )
105315ffd6003Smrg	    func_dirname_and_basename "$output" "" "."
105325ffd6003Smrg	    output_name=$func_basename_result
105335ffd6003Smrg	    output_path=$func_dirname_result
10534b7d26471Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10535b7d26471Smrg	    cwrapper=$output_path/$output_name.exe
105365ffd6003Smrg	    $RM $cwrappersource $cwrapper
105375ffd6003Smrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
105385ffd6003Smrg
105395ffd6003Smrg	    func_emit_cwrapperexe_src > $cwrappersource
105405ffd6003Smrg
105415ffd6003Smrg	    # The wrapper executable is built using the $host compiler,
105425ffd6003Smrg	    # because it contains $host paths and files. If cross-
105435ffd6003Smrg	    # compiling, it, like the target executable, must be
105445ffd6003Smrg	    # executed on the $host or under an emulation environment.
105455ffd6003Smrg	    $opt_dry_run || {
105465ffd6003Smrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
105475ffd6003Smrg	      $STRIP $cwrapper
105485ffd6003Smrg	    }
10549145b7b3cSmrg
105505ffd6003Smrg	    # Now, create the wrapper script for func_source use:
105515ffd6003Smrg	    func_ltwrapper_scriptname $cwrapper
105525ffd6003Smrg	    $RM $func_ltwrapper_scriptname_result
105535ffd6003Smrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
105545ffd6003Smrg	    $opt_dry_run || {
105555ffd6003Smrg	      # note: this script will not be executed, so do not chmod.
10556b7d26471Smrg	      if test "x$build" = "x$host"; then
105575ffd6003Smrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
105585ffd6003Smrg	      else
105595ffd6003Smrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
105605ffd6003Smrg	      fi
105615ffd6003Smrg	    }
105625ffd6003Smrg	  ;;
105635ffd6003Smrg	  * )
105645ffd6003Smrg	    $RM $output
105655ffd6003Smrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10566145b7b3cSmrg
105675ffd6003Smrg	    func_emit_wrapper no > $output
105685ffd6003Smrg	    chmod +x $output
105695ffd6003Smrg	  ;;
105705ffd6003Smrg	esac
105715ffd6003Smrg      }
105725ffd6003Smrg      exit $EXIT_SUCCESS
105735ffd6003Smrg      ;;
105745ffd6003Smrg    esac
10575145b7b3cSmrg
105765ffd6003Smrg    # See if we need to build an old-fashioned archive.
105775ffd6003Smrg    for oldlib in $oldlibs; do
10578145b7b3cSmrg
10579b7d26471Smrg      case $build_libtool_libs in
10580b7d26471Smrg        convenience)
10581b7d26471Smrg	  oldobjs="$libobjs_save $symfileobj"
10582b7d26471Smrg	  addlibs=$convenience
105835ffd6003Smrg	  build_libtool_libs=no
10584b7d26471Smrg	  ;;
10585b7d26471Smrg	module)
10586b7d26471Smrg	  oldobjs=$libobjs_save
10587b7d26471Smrg	  addlibs=$old_convenience
10588b7d26471Smrg	  build_libtool_libs=no
10589b7d26471Smrg          ;;
10590b7d26471Smrg	*)
105915ffd6003Smrg	  oldobjs="$old_deplibs $non_pic_objects"
10592b7d26471Smrg	  $preload && test -f "$symfileobj" \
10593b7d26471Smrg	    && func_append oldobjs " $symfileobj"
10594b7d26471Smrg	  addlibs=$old_convenience
10595b7d26471Smrg	  ;;
10596b7d26471Smrg      esac
10597145b7b3cSmrg
105985ffd6003Smrg      if test -n "$addlibs"; then
10599b7d26471Smrg	gentop=$output_objdir/${outputname}x
10600629baa8cSmrg	func_append generated " $gentop"
10601145b7b3cSmrg
106025ffd6003Smrg	func_extract_archives $gentop $addlibs
10603629baa8cSmrg	func_append oldobjs " $func_extract_archives_result"
106045ffd6003Smrg      fi
10605145b7b3cSmrg
106065ffd6003Smrg      # Do each command in the archive commands.
10607b7d26471Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
106085ffd6003Smrg	cmds=$old_archive_from_new_cmds
106095ffd6003Smrg      else
10610145b7b3cSmrg
106115ffd6003Smrg	# Add any objects from preloaded convenience libraries
106125ffd6003Smrg	if test -n "$dlprefiles"; then
10613b7d26471Smrg	  gentop=$output_objdir/${outputname}x
10614629baa8cSmrg	  func_append generated " $gentop"
10615145b7b3cSmrg
106165ffd6003Smrg	  func_extract_archives $gentop $dlprefiles
10617629baa8cSmrg	  func_append oldobjs " $func_extract_archives_result"
106185ffd6003Smrg	fi
10619145b7b3cSmrg
106205ffd6003Smrg	# POSIX demands no paths to be encoded in archives.  We have
106215ffd6003Smrg	# to avoid creating archives with duplicate basenames if we
106225ffd6003Smrg	# might have to extract them afterwards, e.g., when creating a
106235ffd6003Smrg	# static archive out of a convenience library, or when linking
106245ffd6003Smrg	# the entirety of a libtool archive into another (currently
106255ffd6003Smrg	# not supported by libtool).
106265ffd6003Smrg	if (for obj in $oldobjs
106275ffd6003Smrg	    do
106285ffd6003Smrg	      func_basename "$obj"
106295ffd6003Smrg	      $ECHO "$func_basename_result"
106305ffd6003Smrg	    done | sort | sort -uc >/dev/null 2>&1); then
106315ffd6003Smrg	  :
106325ffd6003Smrg	else
10633629baa8cSmrg	  echo "copying selected object files to avoid basename conflicts..."
10634b7d26471Smrg	  gentop=$output_objdir/${outputname}x
10635629baa8cSmrg	  func_append generated " $gentop"
106365ffd6003Smrg	  func_mkdir_p "$gentop"
106375ffd6003Smrg	  save_oldobjs=$oldobjs
106385ffd6003Smrg	  oldobjs=
106395ffd6003Smrg	  counter=1
106405ffd6003Smrg	  for obj in $save_oldobjs
106415ffd6003Smrg	  do
106425ffd6003Smrg	    func_basename "$obj"
10643b7d26471Smrg	    objbase=$func_basename_result
106445ffd6003Smrg	    case " $oldobjs " in
106455ffd6003Smrg	    " ") oldobjs=$obj ;;
106465ffd6003Smrg	    *[\ /]"$objbase "*)
106475ffd6003Smrg	      while :; do
106485ffd6003Smrg		# Make sure we don't pick an alternate name that also
106495ffd6003Smrg		# overlaps.
106505ffd6003Smrg		newobj=lt$counter-$objbase
106515ffd6003Smrg		func_arith $counter + 1
106525ffd6003Smrg		counter=$func_arith_result
106535ffd6003Smrg		case " $oldobjs " in
106545ffd6003Smrg		*[\ /]"$newobj "*) ;;
106555ffd6003Smrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
106565ffd6003Smrg		esac
106575ffd6003Smrg	      done
106585ffd6003Smrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10659629baa8cSmrg	      func_append oldobjs " $gentop/$newobj"
106605ffd6003Smrg	      ;;
10661629baa8cSmrg	    *) func_append oldobjs " $obj" ;;
106625ffd6003Smrg	    esac
10663145b7b3cSmrg	  done
10664145b7b3cSmrg	fi
10665b7d26471Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10666b7d26471Smrg	tool_oldlib=$func_to_tool_file_result
106675ffd6003Smrg	eval cmds=\"$old_archive_cmds\"
10668145b7b3cSmrg
106695ffd6003Smrg	func_len " $cmds"
106705ffd6003Smrg	len=$func_len_result
106715ffd6003Smrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
106725ffd6003Smrg	  cmds=$old_archive_cmds
10673629baa8cSmrg	elif test -n "$archiver_list_spec"; then
10674629baa8cSmrg	  func_verbose "using command file archive linking..."
10675629baa8cSmrg	  for obj in $oldobjs
10676629baa8cSmrg	  do
10677629baa8cSmrg	    func_to_tool_file "$obj"
10678629baa8cSmrg	    $ECHO "$func_to_tool_file_result"
10679629baa8cSmrg	  done > $output_objdir/$libname.libcmd
10680629baa8cSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10681629baa8cSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10682629baa8cSmrg	  cmds=$old_archive_cmds
106835ffd6003Smrg	else
106845ffd6003Smrg	  # the command line is too long to link in one step, link in parts
106855ffd6003Smrg	  func_verbose "using piecewise archive linking..."
106865ffd6003Smrg	  save_RANLIB=$RANLIB
106875ffd6003Smrg	  RANLIB=:
106885ffd6003Smrg	  objlist=
106895ffd6003Smrg	  concat_cmds=
106905ffd6003Smrg	  save_oldobjs=$oldobjs
106915ffd6003Smrg	  oldobjs=
106925ffd6003Smrg	  # Is there a better way of finding the last object in the list?
106935ffd6003Smrg	  for obj in $save_oldobjs
106945ffd6003Smrg	  do
106955ffd6003Smrg	    last_oldobj=$obj
106965ffd6003Smrg	  done
106975ffd6003Smrg	  eval test_cmds=\"$old_archive_cmds\"
106985ffd6003Smrg	  func_len " $test_cmds"
106995ffd6003Smrg	  len0=$func_len_result
107005ffd6003Smrg	  len=$len0
107015ffd6003Smrg	  for obj in $save_oldobjs
107025ffd6003Smrg	  do
107035ffd6003Smrg	    func_len " $obj"
107045ffd6003Smrg	    func_arith $len + $func_len_result
107055ffd6003Smrg	    len=$func_arith_result
107065ffd6003Smrg	    func_append objlist " $obj"
107075ffd6003Smrg	    if test "$len" -lt "$max_cmd_len"; then
107085ffd6003Smrg	      :
107095ffd6003Smrg	    else
107105ffd6003Smrg	      # the above command should be used before it gets too long
107115ffd6003Smrg	      oldobjs=$objlist
10712b7d26471Smrg	      if test "$obj" = "$last_oldobj"; then
107135ffd6003Smrg		RANLIB=$save_RANLIB
107145ffd6003Smrg	      fi
107155ffd6003Smrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10716b7d26471Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
107175ffd6003Smrg	      objlist=
107185ffd6003Smrg	      len=$len0
107195ffd6003Smrg	    fi
107205ffd6003Smrg	  done
107215ffd6003Smrg	  RANLIB=$save_RANLIB
107225ffd6003Smrg	  oldobjs=$objlist
10723b7d26471Smrg	  if test -z "$oldobjs"; then
107245ffd6003Smrg	    eval cmds=\"\$concat_cmds\"
107255ffd6003Smrg	  else
107265ffd6003Smrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
107275ffd6003Smrg	  fi
107285ffd6003Smrg	fi
107295ffd6003Smrg      fi
107305ffd6003Smrg      func_execute_cmds "$cmds" 'exit $?'
10731145b7b3cSmrg    done
10732145b7b3cSmrg
107335ffd6003Smrg    test -n "$generated" && \
107345ffd6003Smrg      func_show_eval "${RM}r$generated"
10735145b7b3cSmrg
107365ffd6003Smrg    # Now create the libtool archive.
107375ffd6003Smrg    case $output in
107385ffd6003Smrg    *.la)
107395ffd6003Smrg      old_library=
10740b7d26471Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
107415ffd6003Smrg      func_verbose "creating $output"
10742145b7b3cSmrg
107435ffd6003Smrg      # Preserve any variables that may affect compiler behavior
107445ffd6003Smrg      for var in $variables_saved_for_relink; do
107455ffd6003Smrg	if eval test -z \"\${$var+set}\"; then
107465ffd6003Smrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
107475ffd6003Smrg	elif eval var_value=\$$var; test -z "$var_value"; then
107485ffd6003Smrg	  relink_command="$var=; export $var; $relink_command"
10749145b7b3cSmrg	else
107505ffd6003Smrg	  func_quote_for_eval "$var_value"
107515ffd6003Smrg	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10752145b7b3cSmrg	fi
107535ffd6003Smrg      done
107545ffd6003Smrg      # Quote the link command for shipping.
10755b7d26471Smrg      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
10756629baa8cSmrg      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
10757b7d26471Smrg      if test yes = "$hardcode_automatic"; then
107585ffd6003Smrg	relink_command=
107595ffd6003Smrg      fi
10760145b7b3cSmrg
107615ffd6003Smrg      # Only create the output if not a dry run.
107625ffd6003Smrg      $opt_dry_run || {
107635ffd6003Smrg	for installed in no yes; do
10764b7d26471Smrg	  if test yes = "$installed"; then
107655ffd6003Smrg	    if test -z "$install_libdir"; then
107665ffd6003Smrg	      break
107675ffd6003Smrg	    fi
10768b7d26471Smrg	    output=$output_objdir/${outputname}i
107695ffd6003Smrg	    # Replace all uninstalled libtool libraries with the installed ones
107705ffd6003Smrg	    newdependency_libs=
107715ffd6003Smrg	    for deplib in $dependency_libs; do
107725ffd6003Smrg	      case $deplib in
107735ffd6003Smrg	      *.la)
107745ffd6003Smrg		func_basename "$deplib"
10775b7d26471Smrg		name=$func_basename_result
10776b7d26471Smrg		func_resolve_sysroot "$deplib"
10777b7d26471Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
107785ffd6003Smrg		test -z "$libdir" && \
10779b7d26471Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
10780629baa8cSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
10781629baa8cSmrg		;;
10782629baa8cSmrg	      -L*)
10783629baa8cSmrg		func_stripname -L '' "$deplib"
10784629baa8cSmrg		func_replace_sysroot "$func_stripname_result"
10785629baa8cSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
107865ffd6003Smrg		;;
10787629baa8cSmrg	      -R*)
10788629baa8cSmrg		func_stripname -R '' "$deplib"
10789629baa8cSmrg		func_replace_sysroot "$func_stripname_result"
10790629baa8cSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
10791629baa8cSmrg		;;
10792629baa8cSmrg	      *) func_append newdependency_libs " $deplib" ;;
107935ffd6003Smrg	      esac
107945ffd6003Smrg	    done
10795b7d26471Smrg	    dependency_libs=$newdependency_libs
107965ffd6003Smrg	    newdlfiles=
107975ffd6003Smrg
107985ffd6003Smrg	    for lib in $dlfiles; do
107995ffd6003Smrg	      case $lib in
108005ffd6003Smrg	      *.la)
108015ffd6003Smrg	        func_basename "$lib"
10802b7d26471Smrg		name=$func_basename_result
10803b7d26471Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
108045ffd6003Smrg		test -z "$libdir" && \
10805b7d26471Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
10806629baa8cSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
108075ffd6003Smrg		;;
10808629baa8cSmrg	      *) func_append newdlfiles " $lib" ;;
108095ffd6003Smrg	      esac
108105ffd6003Smrg	    done
10811b7d26471Smrg	    dlfiles=$newdlfiles
108125ffd6003Smrg	    newdlprefiles=
108135ffd6003Smrg	    for lib in $dlprefiles; do
108145ffd6003Smrg	      case $lib in
108155ffd6003Smrg	      *.la)
108165ffd6003Smrg		# Only pass preopened files to the pseudo-archive (for
108175ffd6003Smrg		# eventual linking with the app. that links it) if we
108185ffd6003Smrg		# didn't already link the preopened objects directly into
108195ffd6003Smrg		# the library:
108205ffd6003Smrg		func_basename "$lib"
10821b7d26471Smrg		name=$func_basename_result
10822b7d26471Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
108235ffd6003Smrg		test -z "$libdir" && \
10824b7d26471Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
10825629baa8cSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
108265ffd6003Smrg		;;
108275ffd6003Smrg	      esac
108285ffd6003Smrg	    done
10829b7d26471Smrg	    dlprefiles=$newdlprefiles
108305ffd6003Smrg	  else
108315ffd6003Smrg	    newdlfiles=
108325ffd6003Smrg	    for lib in $dlfiles; do
108335ffd6003Smrg	      case $lib in
10834b7d26471Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
108355ffd6003Smrg		*) abs=`pwd`"/$lib" ;;
108365ffd6003Smrg	      esac
10837629baa8cSmrg	      func_append newdlfiles " $abs"
108385ffd6003Smrg	    done
10839b7d26471Smrg	    dlfiles=$newdlfiles
108405ffd6003Smrg	    newdlprefiles=
108415ffd6003Smrg	    for lib in $dlprefiles; do
108425ffd6003Smrg	      case $lib in
10843b7d26471Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
108445ffd6003Smrg		*) abs=`pwd`"/$lib" ;;
108455ffd6003Smrg	      esac
10846629baa8cSmrg	      func_append newdlprefiles " $abs"
108475ffd6003Smrg	    done
10848b7d26471Smrg	    dlprefiles=$newdlprefiles
108495ffd6003Smrg	  fi
108505ffd6003Smrg	  $RM $output
108515ffd6003Smrg	  # place dlname in correct position for cygwin
10852629baa8cSmrg	  # In fact, it would be nice if we could use this code for all target
10853629baa8cSmrg	  # systems that can't hard-code library paths into their executables
10854629baa8cSmrg	  # and that have no shared library path variable independent of PATH,
10855629baa8cSmrg	  # but it turns out we can't easily determine that from inspecting
10856629baa8cSmrg	  # libtool variables, so we have to hard-code the OSs to which it
10857629baa8cSmrg	  # applies here; at the moment, that means platforms that use the PE
10858629baa8cSmrg	  # object format with DLL files.  See the long comment at the top of
10859629baa8cSmrg	  # tests/bindir.at for full details.
108605ffd6003Smrg	  tdlname=$dlname
108615ffd6003Smrg	  case $host,$output,$installed,$module,$dlname in
10862629baa8cSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
10863629baa8cSmrg	      # If a -bindir argument was supplied, place the dll there.
10864b7d26471Smrg	      if test -n "$bindir"; then
10865629baa8cSmrg		func_relative_path "$install_libdir" "$bindir"
10866b7d26471Smrg		tdlname=$func_relative_path_result/$dlname
10867629baa8cSmrg	      else
10868629baa8cSmrg		# Otherwise fall back on heuristic.
10869629baa8cSmrg		tdlname=../bin/$dlname
10870629baa8cSmrg	      fi
10871629baa8cSmrg	      ;;
108725ffd6003Smrg	  esac
108735ffd6003Smrg	  $ECHO > $output "\
108745ffd6003Smrg# $outputname - a libtool library file
10875b7d26471Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
108765ffd6003Smrg#
108775ffd6003Smrg# Please DO NOT delete this file!
108785ffd6003Smrg# It is necessary for linking the library.
10879145b7b3cSmrg
108805ffd6003Smrg# The name that we can dlopen(3).
108815ffd6003Smrgdlname='$tdlname'
10882145b7b3cSmrg
108835ffd6003Smrg# Names of this library.
108845ffd6003Smrglibrary_names='$library_names'
10885145b7b3cSmrg
108865ffd6003Smrg# The name of the static archive.
108875ffd6003Smrgold_library='$old_library'
10888145b7b3cSmrg
10889b7d26471Smrg# Linker flags that cannot go in dependency_libs.
108905ffd6003Smrginherited_linker_flags='$new_inherited_linker_flags'
10891145b7b3cSmrg
108925ffd6003Smrg# Libraries that this one depends upon.
108935ffd6003Smrgdependency_libs='$dependency_libs'
10894145b7b3cSmrg
108955ffd6003Smrg# Names of additional weak libraries provided by this library
108965ffd6003Smrgweak_library_names='$weak_libs'
10897145b7b3cSmrg
108985ffd6003Smrg# Version information for $libname.
108995ffd6003Smrgcurrent=$current
109005ffd6003Smrgage=$age
109015ffd6003Smrgrevision=$revision
10902145b7b3cSmrg
109035ffd6003Smrg# Is this an already installed library?
109045ffd6003Smrginstalled=$installed
10905145b7b3cSmrg
109065ffd6003Smrg# Should we warn about portability when linking against -modules?
109075ffd6003Smrgshouldnotlink=$module
10908145b7b3cSmrg
109095ffd6003Smrg# Files to dlopen/dlpreopen
109105ffd6003Smrgdlopen='$dlfiles'
109115ffd6003Smrgdlpreopen='$dlprefiles'
10912145b7b3cSmrg
109135ffd6003Smrg# Directory that this library needs to be installed in:
109145ffd6003Smrglibdir='$install_libdir'"
10915b7d26471Smrg	  if test no,yes = "$installed,$need_relink"; then
109165ffd6003Smrg	    $ECHO >> $output "\
109175ffd6003Smrgrelink_command=\"$relink_command\""
109185ffd6003Smrg	  fi
109195ffd6003Smrg	done
109205ffd6003Smrg      }
10921145b7b3cSmrg
109225ffd6003Smrg      # Do a symbolic link so that the libtool archive can be found in
109235ffd6003Smrg      # LD_LIBRARY_PATH before the program is installed.
109245ffd6003Smrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
109255ffd6003Smrg      ;;
109265ffd6003Smrg    esac
109275ffd6003Smrg    exit $EXIT_SUCCESS
109285ffd6003Smrg}
10929145b7b3cSmrg
10930b7d26471Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
10931b7d26471Smrg  func_mode_link ${1+"$@"}
10932b7d26471Smrgfi
10933145b7b3cSmrg
10934145b7b3cSmrg
109355ffd6003Smrg# func_mode_uninstall arg...
109365ffd6003Smrgfunc_mode_uninstall ()
109375ffd6003Smrg{
10938b7d26471Smrg    $debug_cmd
10939b7d26471Smrg
10940b7d26471Smrg    RM=$nonopt
10941145b7b3cSmrg    files=
10942b7d26471Smrg    rmforce=false
10943145b7b3cSmrg    exit_status=0
10944145b7b3cSmrg
10945145b7b3cSmrg    # This variable tells wrapper scripts just to set variables rather
10946145b7b3cSmrg    # than running their programs.
10947b7d26471Smrg    libtool_install_magic=$magic
10948145b7b3cSmrg
10949145b7b3cSmrg    for arg
10950145b7b3cSmrg    do
10951145b7b3cSmrg      case $arg in
10952b7d26471Smrg      -f) func_append RM " $arg"; rmforce=: ;;
10953629baa8cSmrg      -*) func_append RM " $arg" ;;
10954629baa8cSmrg      *) func_append files " $arg" ;;
10955145b7b3cSmrg      esac
10956145b7b3cSmrg    done
10957145b7b3cSmrg
109585ffd6003Smrg    test -z "$RM" && \
109595ffd6003Smrg      func_fatal_help "you must specify an RM program"
10960145b7b3cSmrg
10961145b7b3cSmrg    rmdirs=
10962145b7b3cSmrg
10963145b7b3cSmrg    for file in $files; do
109645ffd6003Smrg      func_dirname "$file" "" "."
10965b7d26471Smrg      dir=$func_dirname_result
10966b7d26471Smrg      if test . = "$dir"; then
10967b7d26471Smrg	odir=$objdir
10968145b7b3cSmrg      else
10969b7d26471Smrg	odir=$dir/$objdir
10970145b7b3cSmrg      fi
109715ffd6003Smrg      func_basename "$file"
10972b7d26471Smrg      name=$func_basename_result
10973b7d26471Smrg      test uninstall = "$opt_mode" && odir=$dir
10974145b7b3cSmrg
10975629baa8cSmrg      # Remember odir for removal later, being careful to avoid duplicates
10976b7d26471Smrg      if test clean = "$opt_mode"; then
10977145b7b3cSmrg	case " $rmdirs " in
10978629baa8cSmrg	  *" $odir "*) ;;
10979629baa8cSmrg	  *) func_append rmdirs " $odir" ;;
10980145b7b3cSmrg	esac
10981145b7b3cSmrg      fi
10982145b7b3cSmrg
10983145b7b3cSmrg      # Don't error if the file doesn't exist and rm -f was used.
109845ffd6003Smrg      if { test -L "$file"; } >/dev/null 2>&1 ||
109855ffd6003Smrg	 { test -h "$file"; } >/dev/null 2>&1 ||
109865ffd6003Smrg	 test -f "$file"; then
10987145b7b3cSmrg	:
10988145b7b3cSmrg      elif test -d "$file"; then
10989145b7b3cSmrg	exit_status=1
10990145b7b3cSmrg	continue
10991b7d26471Smrg      elif $rmforce; then
10992145b7b3cSmrg	continue
10993145b7b3cSmrg      fi
10994145b7b3cSmrg
10995b7d26471Smrg      rmfiles=$file
10996145b7b3cSmrg
10997145b7b3cSmrg      case $name in
10998145b7b3cSmrg      *.la)
10999145b7b3cSmrg	# Possibly a libtool archive, so verify it.
110005ffd6003Smrg	if func_lalib_p "$file"; then
110015ffd6003Smrg	  func_source $dir/$name
11002145b7b3cSmrg
11003145b7b3cSmrg	  # Delete the libtool libraries and symlinks.
11004145b7b3cSmrg	  for n in $library_names; do
11005629baa8cSmrg	    func_append rmfiles " $odir/$n"
11006145b7b3cSmrg	  done
11007629baa8cSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11008145b7b3cSmrg
11009b7d26471Smrg	  case $opt_mode in
11010145b7b3cSmrg	  clean)
11011629baa8cSmrg	    case " $library_names " in
11012145b7b3cSmrg	    *" $dlname "*) ;;
11013629baa8cSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11014145b7b3cSmrg	    esac
11015629baa8cSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11016145b7b3cSmrg	    ;;
11017145b7b3cSmrg	  uninstall)
11018145b7b3cSmrg	    if test -n "$library_names"; then
11019145b7b3cSmrg	      # Do each command in the postuninstall commands.
11020b7d26471Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11021145b7b3cSmrg	    fi
11022145b7b3cSmrg
11023145b7b3cSmrg	    if test -n "$old_library"; then
11024145b7b3cSmrg	      # Do each command in the old_postuninstall commands.
11025b7d26471Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11026145b7b3cSmrg	    fi
11027145b7b3cSmrg	    # FIXME: should reinstall the best remaining shared library.
11028145b7b3cSmrg	    ;;
11029145b7b3cSmrg	  esac
11030145b7b3cSmrg	fi
11031145b7b3cSmrg	;;
11032145b7b3cSmrg
11033145b7b3cSmrg      *.lo)
11034145b7b3cSmrg	# Possibly a libtool object, so verify it.
110355ffd6003Smrg	if func_lalib_p "$file"; then
11036145b7b3cSmrg
11037145b7b3cSmrg	  # Read the .lo file
110385ffd6003Smrg	  func_source $dir/$name
11039145b7b3cSmrg
11040145b7b3cSmrg	  # Add PIC object to the list of files to remove.
11041b7d26471Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11042629baa8cSmrg	    func_append rmfiles " $dir/$pic_object"
11043145b7b3cSmrg	  fi
11044145b7b3cSmrg
11045145b7b3cSmrg	  # Add non-PIC object to the list of files to remove.
11046b7d26471Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11047629baa8cSmrg	    func_append rmfiles " $dir/$non_pic_object"
11048145b7b3cSmrg	  fi
11049145b7b3cSmrg	fi
11050145b7b3cSmrg	;;
11051145b7b3cSmrg
11052145b7b3cSmrg      *)
11053b7d26471Smrg	if test clean = "$opt_mode"; then
11054145b7b3cSmrg	  noexename=$name
11055145b7b3cSmrg	  case $file in
11056145b7b3cSmrg	  *.exe)
110575ffd6003Smrg	    func_stripname '' '.exe' "$file"
110585ffd6003Smrg	    file=$func_stripname_result
110595ffd6003Smrg	    func_stripname '' '.exe' "$name"
110605ffd6003Smrg	    noexename=$func_stripname_result
11061145b7b3cSmrg	    # $file with .exe has already been added to rmfiles,
11062145b7b3cSmrg	    # add $file without .exe
11063629baa8cSmrg	    func_append rmfiles " $file"
11064145b7b3cSmrg	    ;;
11065145b7b3cSmrg	  esac
11066145b7b3cSmrg	  # Do a test to see if this is a libtool program.
110675ffd6003Smrg	  if func_ltwrapper_p "$file"; then
110685ffd6003Smrg	    if func_ltwrapper_executable_p "$file"; then
110695ffd6003Smrg	      func_ltwrapper_scriptname "$file"
110705ffd6003Smrg	      relink_command=
110715ffd6003Smrg	      func_source $func_ltwrapper_scriptname_result
11072629baa8cSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
110735ffd6003Smrg	    else
110745ffd6003Smrg	      relink_command=
110755ffd6003Smrg	      func_source $dir/$noexename
110765ffd6003Smrg	    fi
11077145b7b3cSmrg
11078145b7b3cSmrg	    # note $name still contains .exe if it was in $file originally
11079145b7b3cSmrg	    # as does the version of $file that was added into $rmfiles
11080b7d26471Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11081b7d26471Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11082629baa8cSmrg	      func_append rmfiles " $odir/lt-$name"
11083145b7b3cSmrg	    fi
11084b7d26471Smrg	    if test "X$noexename" != "X$name"; then
11085b7d26471Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11086145b7b3cSmrg	    fi
11087145b7b3cSmrg	  fi
11088145b7b3cSmrg	fi
11089145b7b3cSmrg	;;
11090145b7b3cSmrg      esac
110915ffd6003Smrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11092145b7b3cSmrg    done
11093145b7b3cSmrg
11094b7d26471Smrg    # Try to remove the $objdir's in the directories where we deleted files
11095145b7b3cSmrg    for dir in $rmdirs; do
11096145b7b3cSmrg      if test -d "$dir"; then
110975ffd6003Smrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11098145b7b3cSmrg      fi
11099145b7b3cSmrg    done
11100145b7b3cSmrg
11101145b7b3cSmrg    exit $exit_status
111025ffd6003Smrg}
11103145b7b3cSmrg
11104b7d26471Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11105b7d26471Smrg  func_mode_uninstall ${1+"$@"}
11106b7d26471Smrgfi
11107145b7b3cSmrg
11108629baa8cSmrgtest -z "$opt_mode" && {
11109b7d26471Smrg  help=$generic_help
111105ffd6003Smrg  func_fatal_help "you must specify a MODE"
111115ffd6003Smrg}
111125ffd6003Smrg
111135ffd6003Smrgtest -z "$exec_cmd" && \
11114b7d26471Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11115145b7b3cSmrg
11116145b7b3cSmrgif test -n "$exec_cmd"; then
111175ffd6003Smrg  eval exec "$exec_cmd"
11118145b7b3cSmrg  exit $EXIT_FAILURE
11119145b7b3cSmrgfi
11120145b7b3cSmrg
111215ffd6003Smrgexit $exit_status
11122145b7b3cSmrg
11123145b7b3cSmrg
11124145b7b3cSmrg# The TAGs below are defined such that we never get into a situation
11125b7d26471Smrg# where we disable both kinds of libraries.  Given conflicting
11126145b7b3cSmrg# choices, we go for a static library, that is the most portable,
11127145b7b3cSmrg# since we can't tell whether shared libraries were disabled because
11128145b7b3cSmrg# the user asked for that or because the platform doesn't support
11129145b7b3cSmrg# them.  This is particularly important on AIX, because we don't
11130145b7b3cSmrg# support having both static and shared libraries enabled at the same
11131145b7b3cSmrg# time on that platform, so we default to a shared-only configuration.
11132145b7b3cSmrg# If a disable-shared tag is given, we'll fallback to a static-only
11133145b7b3cSmrg# configuration.  But we'll never go from static-only to shared-only.
11134145b7b3cSmrg
11135145b7b3cSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
111365ffd6003Smrgbuild_libtool_libs=no
111375ffd6003Smrgbuild_old_libs=yes
11138145b7b3cSmrg# ### END LIBTOOL TAG CONFIG: disable-shared
11139145b7b3cSmrg
11140145b7b3cSmrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
111415ffd6003Smrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11142145b7b3cSmrg# ### END LIBTOOL TAG CONFIG: disable-static
11143145b7b3cSmrg
11144145b7b3cSmrg# Local Variables:
11145145b7b3cSmrg# mode:shell-script
11146145b7b3cSmrg# sh-indentation:2
11147145b7b3cSmrg# End:
11148