xref: /aosp_15_r20/external/sg3_utils/ltmain.sh (revision 44704f698541f6367e81f991ef8bb54ccbf3fc18)
1*44704f69SBart Van Assche#! /usr/bin/env sh
2*44704f69SBart Van Assche## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3*44704f69SBart Van Assche##               by inline-source v2019-02-19.15
4*44704f69SBart Van Assche
5*44704f69SBart Van Assche# libtool (GNU libtool) 2.4.7
6*44704f69SBart Van Assche# Provide generalized library-building support services.
7*44704f69SBart Van Assche# Written by Gordon Matzigkeit <[email protected]>, 1996
8*44704f69SBart Van Assche
9*44704f69SBart Van Assche# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10*44704f69SBart Van Assche# This is free software; see the source for copying conditions.  There is NO
11*44704f69SBart Van Assche# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12*44704f69SBart Van Assche
13*44704f69SBart Van Assche# GNU Libtool is free software; you can redistribute it and/or modify
14*44704f69SBart Van Assche# it under the terms of the GNU General Public License as published by
15*44704f69SBart Van Assche# the Free Software Foundation; either version 2 of the License, or
16*44704f69SBart Van Assche# (at your option) any later version.
17*44704f69SBart Van Assche#
18*44704f69SBart Van Assche# As a special exception to the GNU General Public License,
19*44704f69SBart Van Assche# if you distribute this file as part of a program or library that
20*44704f69SBart Van Assche# is built using GNU Libtool, you may include this file under the
21*44704f69SBart Van Assche# same distribution terms that you use for the rest of that program.
22*44704f69SBart Van Assche#
23*44704f69SBart Van Assche# GNU Libtool is distributed in the hope that it will be useful, but
24*44704f69SBart Van Assche# WITHOUT ANY WARRANTY; without even the implied warranty of
25*44704f69SBart Van Assche# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26*44704f69SBart Van Assche# General Public License for more details.
27*44704f69SBart Van Assche#
28*44704f69SBart Van Assche# You should have received a copy of the GNU General Public License
29*44704f69SBart Van Assche# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30*44704f69SBart Van Assche
31*44704f69SBart Van Assche
32*44704f69SBart Van AsschePROGRAM=libtool
33*44704f69SBart Van AsschePACKAGE=libtool
34*44704f69SBart Van AsscheVERSION="2.4.7 Debian-2.4.7-4"
35*44704f69SBart Van Asschepackage_revision=2.4.7
36*44704f69SBart Van Assche
37*44704f69SBart Van Assche
38*44704f69SBart Van Assche## ------ ##
39*44704f69SBart Van Assche## Usage. ##
40*44704f69SBart Van Assche## ------ ##
41*44704f69SBart Van Assche
42*44704f69SBart Van Assche# Run './libtool --help' for help with using this script from the
43*44704f69SBart Van Assche# command line.
44*44704f69SBart Van Assche
45*44704f69SBart Van Assche
46*44704f69SBart Van Assche## ------------------------------- ##
47*44704f69SBart Van Assche## User overridable command paths. ##
48*44704f69SBart Van Assche## ------------------------------- ##
49*44704f69SBart Van Assche
50*44704f69SBart Van Assche# After configure completes, it has a better idea of some of the
51*44704f69SBart Van Assche# shell tools we need than the defaults used by the functions shared
52*44704f69SBart Van Assche# with bootstrap, so set those here where they can still be over-
53*44704f69SBart Van Assche# ridden by the user, but otherwise take precedence.
54*44704f69SBart Van Assche
55*44704f69SBart Van Assche: ${AUTOCONF="autoconf"}
56*44704f69SBart Van Assche: ${AUTOMAKE="automake"}
57*44704f69SBart Van Assche
58*44704f69SBart Van Assche
59*44704f69SBart Van Assche## -------------------------- ##
60*44704f69SBart Van Assche## Source external libraries. ##
61*44704f69SBart Van Assche## -------------------------- ##
62*44704f69SBart Van Assche
63*44704f69SBart Van Assche# Much of our low-level functionality needs to be sourced from external
64*44704f69SBart Van Assche# libraries, which are installed to $pkgauxdir.
65*44704f69SBart Van Assche
66*44704f69SBart Van Assche# Set a version string for this script.
67*44704f69SBart Van Asschescriptversion=2019-02-19.15; # UTC
68*44704f69SBart Van Assche
69*44704f69SBart Van Assche# General shell script boiler plate, and helper functions.
70*44704f69SBart Van Assche# Written by Gary V. Vaughan, 2004
71*44704f69SBart Van Assche
72*44704f69SBart Van Assche# This is free software.  There is NO warranty; not even for
73*44704f69SBart Van Assche# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74*44704f69SBart Van Assche#
75*44704f69SBart Van Assche# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76*44704f69SBart Van Assche#
77*44704f69SBart Van Assche# This file is dual licensed under the terms of the MIT license
78*44704f69SBart Van Assche# <https://opensource.org/license/MIT>, and GPL version 2 or later
79*44704f69SBart Van Assche# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80*44704f69SBart Van Assche# these licenses when using or redistributing this software or any of
81*44704f69SBart Van Assche# the files within it.  See the URLs above, or the file `LICENSE`
82*44704f69SBart Van Assche# included in the Bootstrap distribution for the full license texts.
83*44704f69SBart Van Assche
84*44704f69SBart Van Assche# Please report bugs or propose patches to:
85*44704f69SBart Van Assche# <https://github.com/gnulib-modules/bootstrap/issues>
86*44704f69SBart Van Assche
87*44704f69SBart Van Assche
88*44704f69SBart Van Assche## ------ ##
89*44704f69SBart Van Assche## Usage. ##
90*44704f69SBart Van Assche## ------ ##
91*44704f69SBart Van Assche
92*44704f69SBart Van Assche# Evaluate this file near the top of your script to gain access to
93*44704f69SBart Van Assche# the functions and variables defined here:
94*44704f69SBart Van Assche#
95*44704f69SBart Van Assche#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96*44704f69SBart Van Assche#
97*44704f69SBart Van Assche# If you need to override any of the default environment variable
98*44704f69SBart Van Assche# settings, do that before evaluating this file.
99*44704f69SBart Van Assche
100*44704f69SBart Van Assche
101*44704f69SBart Van Assche## -------------------- ##
102*44704f69SBart Van Assche## Shell normalisation. ##
103*44704f69SBart Van Assche## -------------------- ##
104*44704f69SBart Van Assche
105*44704f69SBart Van Assche# Some shells need a little help to be as Bourne compatible as possible.
106*44704f69SBart Van Assche# Before doing anything else, make sure all that help has been provided!
107*44704f69SBart Van Assche
108*44704f69SBart Van AsscheDUALCASE=1; export DUALCASE # for MKS sh
109*44704f69SBart Van Asscheif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
110*44704f69SBart Van Assche  emulate sh
111*44704f69SBart Van Assche  NULLCMD=:
112*44704f69SBart Van Assche  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
113*44704f69SBart Van Assche  # is contrary to our usage.  Disable this feature.
114*44704f69SBart Van Assche  alias -g '${1+"$@"}'='"$@"'
115*44704f69SBart Van Assche  setopt NO_GLOB_SUBST
116*44704f69SBart Van Asscheelse
117*44704f69SBart Van Assche  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
118*44704f69SBart Van Asschefi
119*44704f69SBart Van Assche
120*44704f69SBart Van Assche# NLS nuisances: We save the old values in case they are required later.
121*44704f69SBart Van Assche_G_user_locale=
122*44704f69SBart Van Assche_G_safe_locale=
123*44704f69SBart Van Asschefor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
124*44704f69SBart Van Asschedo
125*44704f69SBart Van Assche  eval "if test set = \"\${$_G_var+set}\"; then
126*44704f69SBart Van Assche          save_$_G_var=\$$_G_var
127*44704f69SBart Van Assche          $_G_var=C
128*44704f69SBart Van Assche	  export $_G_var
129*44704f69SBart Van Assche	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130*44704f69SBart Van Assche	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
131*44704f69SBart Van Assche	fi"
132*44704f69SBart Van Asschedone
133*44704f69SBart Van Assche# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134*44704f69SBart Van Assche# in case the environment reset is needed later and the $save_* variant is not
135*44704f69SBart Van Assche# defined (see the code above).
136*44704f69SBart Van AsscheLC_ALL=C
137*44704f69SBart Van AsscheLANGUAGE=C
138*44704f69SBart Van Asscheexport LANGUAGE LC_ALL
139*44704f69SBart Van Assche
140*44704f69SBart Van Assche# Make sure IFS has a sensible default
141*44704f69SBart Van Asschesp=' '
142*44704f69SBart Van Asschenl='
143*44704f69SBart Van Assche'
144*44704f69SBart Van AsscheIFS="$sp	$nl"
145*44704f69SBart Van Assche
146*44704f69SBart Van Assche# There are apparently some retarded systems that use ';' as a PATH separator!
147*44704f69SBart Van Asscheif test "${PATH_SEPARATOR+set}" != set; then
148*44704f69SBart Van Assche  PATH_SEPARATOR=:
149*44704f69SBart Van Assche  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150*44704f69SBart Van Assche    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151*44704f69SBart Van Assche      PATH_SEPARATOR=';'
152*44704f69SBart Van Assche  }
153*44704f69SBart Van Asschefi
154*44704f69SBart Van Assche
155*44704f69SBart Van Assche
156*44704f69SBart Van Assche# func_unset VAR
157*44704f69SBart Van Assche# --------------
158*44704f69SBart Van Assche# Portably unset VAR.
159*44704f69SBart Van Assche# In some shells, an 'unset VAR' statement leaves a non-zero return
160*44704f69SBart Van Assche# status if VAR is already unset, which might be problematic if the
161*44704f69SBart Van Assche# statement is used at the end of a function (thus poisoning its return
162*44704f69SBart Van Assche# value) or when 'set -e' is active (causing even a spurious abort of
163*44704f69SBart Van Assche# the script in this case).
164*44704f69SBart Van Asschefunc_unset ()
165*44704f69SBart Van Assche{
166*44704f69SBart Van Assche    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167*44704f69SBart Van Assche}
168*44704f69SBart Van Assche
169*44704f69SBart Van Assche
170*44704f69SBart Van Assche# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171*44704f69SBart Van Asschefunc_unset CDPATH
172*44704f69SBart Van Assche
173*44704f69SBart Van Assche# Make sure ${,E,F}GREP behave sanely.
174*44704f69SBart Van Asschefunc_unset GREP_OPTIONS
175*44704f69SBart Van Assche
176*44704f69SBart Van Assche
177*44704f69SBart Van Assche## ------------------------- ##
178*44704f69SBart Van Assche## Locate command utilities. ##
179*44704f69SBart Van Assche## ------------------------- ##
180*44704f69SBart Van Assche
181*44704f69SBart Van Assche
182*44704f69SBart Van Assche# func_executable_p FILE
183*44704f69SBart Van Assche# ----------------------
184*44704f69SBart Van Assche# Check that FILE is an executable regular file.
185*44704f69SBart Van Asschefunc_executable_p ()
186*44704f69SBart Van Assche{
187*44704f69SBart Van Assche    test -f "$1" && test -x "$1"
188*44704f69SBart Van Assche}
189*44704f69SBart Van Assche
190*44704f69SBart Van Assche
191*44704f69SBart Van Assche# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192*44704f69SBart Van Assche# --------------------------------------------
193*44704f69SBart Van Assche# Search for either a program that responds to --version with output
194*44704f69SBart Van Assche# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195*44704f69SBart Van Assche# trying all the directories in PATH with each of the elements of
196*44704f69SBart Van Assche# PROGS_LIST.
197*44704f69SBart Van Assche#
198*44704f69SBart Van Assche# CHECK_FUNC should accept the path to a candidate program, and
199*44704f69SBart Van Assche# set $func_check_prog_result if it truncates its output less than
200*44704f69SBart Van Assche# $_G_path_prog_max characters.
201*44704f69SBart Van Asschefunc_path_progs ()
202*44704f69SBart Van Assche{
203*44704f69SBart Van Assche    _G_progs_list=$1
204*44704f69SBart Van Assche    _G_check_func=$2
205*44704f69SBart Van Assche    _G_PATH=${3-"$PATH"}
206*44704f69SBart Van Assche
207*44704f69SBart Van Assche    _G_path_prog_max=0
208*44704f69SBart Van Assche    _G_path_prog_found=false
209*44704f69SBart Van Assche    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210*44704f69SBart Van Assche    for _G_dir in $_G_PATH; do
211*44704f69SBart Van Assche      IFS=$_G_save_IFS
212*44704f69SBart Van Assche      test -z "$_G_dir" && _G_dir=.
213*44704f69SBart Van Assche      for _G_prog_name in $_G_progs_list; do
214*44704f69SBart Van Assche        for _exeext in '' .EXE; do
215*44704f69SBart Van Assche          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216*44704f69SBart Van Assche          func_executable_p "$_G_path_prog" || continue
217*44704f69SBart Van Assche          case `"$_G_path_prog" --version 2>&1` in
218*44704f69SBart Van Assche            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219*44704f69SBart Van Assche            *)     $_G_check_func $_G_path_prog
220*44704f69SBart Van Assche		   func_path_progs_result=$func_check_prog_result
221*44704f69SBart Van Assche		   ;;
222*44704f69SBart Van Assche          esac
223*44704f69SBart Van Assche          $_G_path_prog_found && break 3
224*44704f69SBart Van Assche        done
225*44704f69SBart Van Assche      done
226*44704f69SBart Van Assche    done
227*44704f69SBart Van Assche    IFS=$_G_save_IFS
228*44704f69SBart Van Assche    test -z "$func_path_progs_result" && {
229*44704f69SBart Van Assche      echo "no acceptable sed could be found in \$PATH" >&2
230*44704f69SBart Van Assche      exit 1
231*44704f69SBart Van Assche    }
232*44704f69SBart Van Assche}
233*44704f69SBart Van Assche
234*44704f69SBart Van Assche
235*44704f69SBart Van Assche# We want to be able to use the functions in this file before configure
236*44704f69SBart Van Assche# has figured out where the best binaries are kept, which means we have
237*44704f69SBart Van Assche# to search for them ourselves - except when the results are already set
238*44704f69SBart Van Assche# where we skip the searches.
239*44704f69SBart Van Assche
240*44704f69SBart Van Assche# Unless the user overrides by setting SED, search the path for either GNU
241*44704f69SBart Van Assche# sed, or the sed that truncates its output the least.
242*44704f69SBart Van Asschetest -z "$SED" && {
243*44704f69SBart Van Assche  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244*44704f69SBart Van Assche  for _G_i in 1 2 3 4 5 6 7; do
245*44704f69SBart Van Assche    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246*44704f69SBart Van Assche  done
247*44704f69SBart Van Assche  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248*44704f69SBart Van Assche  _G_sed_script=
249*44704f69SBart Van Assche
250*44704f69SBart Van Assche  func_check_prog_sed ()
251*44704f69SBart Van Assche  {
252*44704f69SBart Van Assche    _G_path_prog=$1
253*44704f69SBart Van Assche
254*44704f69SBart Van Assche    _G_count=0
255*44704f69SBart Van Assche    printf 0123456789 >conftest.in
256*44704f69SBart Van Assche    while :
257*44704f69SBart Van Assche    do
258*44704f69SBart Van Assche      cat conftest.in conftest.in >conftest.tmp
259*44704f69SBart Van Assche      mv conftest.tmp conftest.in
260*44704f69SBart Van Assche      cp conftest.in conftest.nl
261*44704f69SBart Van Assche      echo '' >> conftest.nl
262*44704f69SBart Van Assche      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263*44704f69SBart Van Assche      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264*44704f69SBart Van Assche      _G_count=`expr $_G_count + 1`
265*44704f69SBart Van Assche      if test "$_G_count" -gt "$_G_path_prog_max"; then
266*44704f69SBart Van Assche        # Best one so far, save it but keep looking for a better one
267*44704f69SBart Van Assche        func_check_prog_result=$_G_path_prog
268*44704f69SBart Van Assche        _G_path_prog_max=$_G_count
269*44704f69SBart Van Assche      fi
270*44704f69SBart Van Assche      # 10*(2^10) chars as input seems more than enough
271*44704f69SBart Van Assche      test 10 -lt "$_G_count" && break
272*44704f69SBart Van Assche    done
273*44704f69SBart Van Assche    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274*44704f69SBart Van Assche  }
275*44704f69SBart Van Assche
276*44704f69SBart Van Assche  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277*44704f69SBart Van Assche  rm -f conftest.sed
278*44704f69SBart Van Assche  SED=$func_path_progs_result
279*44704f69SBart Van Assche}
280*44704f69SBart Van Assche
281*44704f69SBart Van Assche
282*44704f69SBart Van Assche# Unless the user overrides by setting GREP, search the path for either GNU
283*44704f69SBart Van Assche# grep, or the grep that truncates its output the least.
284*44704f69SBart Van Asschetest -z "$GREP" && {
285*44704f69SBart Van Assche  func_check_prog_grep ()
286*44704f69SBart Van Assche  {
287*44704f69SBart Van Assche    _G_path_prog=$1
288*44704f69SBart Van Assche
289*44704f69SBart Van Assche    _G_count=0
290*44704f69SBart Van Assche    _G_path_prog_max=0
291*44704f69SBart Van Assche    printf 0123456789 >conftest.in
292*44704f69SBart Van Assche    while :
293*44704f69SBart Van Assche    do
294*44704f69SBart Van Assche      cat conftest.in conftest.in >conftest.tmp
295*44704f69SBart Van Assche      mv conftest.tmp conftest.in
296*44704f69SBart Van Assche      cp conftest.in conftest.nl
297*44704f69SBart Van Assche      echo 'GREP' >> conftest.nl
298*44704f69SBart Van Assche      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299*44704f69SBart Van Assche      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300*44704f69SBart Van Assche      _G_count=`expr $_G_count + 1`
301*44704f69SBart Van Assche      if test "$_G_count" -gt "$_G_path_prog_max"; then
302*44704f69SBart Van Assche        # Best one so far, save it but keep looking for a better one
303*44704f69SBart Van Assche        func_check_prog_result=$_G_path_prog
304*44704f69SBart Van Assche        _G_path_prog_max=$_G_count
305*44704f69SBart Van Assche      fi
306*44704f69SBart Van Assche      # 10*(2^10) chars as input seems more than enough
307*44704f69SBart Van Assche      test 10 -lt "$_G_count" && break
308*44704f69SBart Van Assche    done
309*44704f69SBart Van Assche    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310*44704f69SBart Van Assche  }
311*44704f69SBart Van Assche
312*44704f69SBart Van Assche  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313*44704f69SBart Van Assche  GREP=$func_path_progs_result
314*44704f69SBart Van Assche}
315*44704f69SBart Van Assche
316*44704f69SBart Van Assche
317*44704f69SBart Van Assche## ------------------------------- ##
318*44704f69SBart Van Assche## User overridable command paths. ##
319*44704f69SBart Van Assche## ------------------------------- ##
320*44704f69SBart Van Assche
321*44704f69SBart Van Assche# All uppercase variable names are used for environment variables.  These
322*44704f69SBart Van Assche# variables can be overridden by the user before calling a script that
323*44704f69SBart Van Assche# uses them if a suitable command of that name is not already available
324*44704f69SBart Van Assche# in the command search PATH.
325*44704f69SBart Van Assche
326*44704f69SBart Van Assche: ${CP="cp -f"}
327*44704f69SBart Van Assche: ${ECHO="printf %s\n"}
328*44704f69SBart Van Assche: ${EGREP="$GREP -E"}
329*44704f69SBart Van Assche: ${FGREP="$GREP -F"}
330*44704f69SBart Van Assche: ${LN_S="ln -s"}
331*44704f69SBart Van Assche: ${MAKE="make"}
332*44704f69SBart Van Assche: ${MKDIR="mkdir"}
333*44704f69SBart Van Assche: ${MV="mv -f"}
334*44704f69SBart Van Assche: ${RM="rm -f"}
335*44704f69SBart Van Assche: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
336*44704f69SBart Van Assche
337*44704f69SBart Van Assche
338*44704f69SBart Van Assche## -------------------- ##
339*44704f69SBart Van Assche## Useful sed snippets. ##
340*44704f69SBart Van Assche## -------------------- ##
341*44704f69SBart Van Assche
342*44704f69SBart Van Asschesed_dirname='s|/[^/]*$||'
343*44704f69SBart Van Asschesed_basename='s|^.*/||'
344*44704f69SBart Van Assche
345*44704f69SBart Van Assche# Sed substitution that helps us do robust quoting.  It backslashifies
346*44704f69SBart Van Assche# metacharacters that are still active within double-quoted strings.
347*44704f69SBart Van Asschesed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348*44704f69SBart Van Assche
349*44704f69SBart Van Assche# Same as above, but do not quote variable references.
350*44704f69SBart Van Asschesed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351*44704f69SBart Van Assche
352*44704f69SBart Van Assche# Sed substitution that turns a string into a regex matching for the
353*44704f69SBart Van Assche# string literally.
354*44704f69SBart Van Asschesed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355*44704f69SBart Van Assche
356*44704f69SBart Van Assche# Sed substitution that converts a w32 file name or path
357*44704f69SBart Van Assche# that contains forward slashes, into one that contains
358*44704f69SBart Van Assche# (escaped) backslashes.  A very naive implementation.
359*44704f69SBart Van Asschesed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360*44704f69SBart Van Assche
361*44704f69SBart Van Assche# Re-'\' parameter expansions in output of sed_double_quote_subst that
362*44704f69SBart Van Assche# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363*44704f69SBart Van Assche# '$' in input to sed_double_quote_subst, that '$' was protected from
364*44704f69SBart Van Assche# expansion.  Since each input '\' is now two '\'s, look for any number
365*44704f69SBart Van Assche# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366*44704f69SBart Van Assche_G_bs='\\'
367*44704f69SBart Van Assche_G_bs2='\\\\'
368*44704f69SBart Van Assche_G_bs4='\\\\\\\\'
369*44704f69SBart Van Assche_G_dollar='\$'
370*44704f69SBart Van Asschesed_double_backslash="\
371*44704f69SBart Van Assche  s/$_G_bs4/&\\
372*44704f69SBart Van Assche/g
373*44704f69SBart Van Assche  s/^$_G_bs2$_G_dollar/$_G_bs&/
374*44704f69SBart Van Assche  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375*44704f69SBart Van Assche  s/\n//g"
376*44704f69SBart Van Assche
377*44704f69SBart Van Assche# require_check_ifs_backslash
378*44704f69SBart Van Assche# ---------------------------
379*44704f69SBart Van Assche# Check if we can use backslash as IFS='\' separator, and set
380*44704f69SBart Van Assche# $check_ifs_backshlash_broken to ':' or 'false'.
381*44704f69SBart Van Asscherequire_check_ifs_backslash=func_require_check_ifs_backslash
382*44704f69SBart Van Asschefunc_require_check_ifs_backslash ()
383*44704f69SBart Van Assche{
384*44704f69SBart Van Assche  _G_save_IFS=$IFS
385*44704f69SBart Van Assche  IFS='\'
386*44704f69SBart Van Assche  _G_check_ifs_backshlash='a\\b'
387*44704f69SBart Van Assche  for _G_i in $_G_check_ifs_backshlash
388*44704f69SBart Van Assche  do
389*44704f69SBart Van Assche  case $_G_i in
390*44704f69SBart Van Assche  a)
391*44704f69SBart Van Assche    check_ifs_backshlash_broken=false
392*44704f69SBart Van Assche    ;;
393*44704f69SBart Van Assche  '')
394*44704f69SBart Van Assche    break
395*44704f69SBart Van Assche    ;;
396*44704f69SBart Van Assche  *)
397*44704f69SBart Van Assche    check_ifs_backshlash_broken=:
398*44704f69SBart Van Assche    break
399*44704f69SBart Van Assche    ;;
400*44704f69SBart Van Assche  esac
401*44704f69SBart Van Assche  done
402*44704f69SBart Van Assche  IFS=$_G_save_IFS
403*44704f69SBart Van Assche  require_check_ifs_backslash=:
404*44704f69SBart Van Assche}
405*44704f69SBart Van Assche
406*44704f69SBart Van Assche
407*44704f69SBart Van Assche## ----------------- ##
408*44704f69SBart Van Assche## Global variables. ##
409*44704f69SBart Van Assche## ----------------- ##
410*44704f69SBart Van Assche
411*44704f69SBart Van Assche# Except for the global variables explicitly listed below, the following
412*44704f69SBart Van Assche# functions in the '^func_' namespace, and the '^require_' namespace
413*44704f69SBart Van Assche# variables initialised in the 'Resource management' section, sourcing
414*44704f69SBart Van Assche# this file will not pollute your global namespace with anything
415*44704f69SBart Van Assche# else. There's no portable way to scope variables in Bourne shell
416*44704f69SBart Van Assche# though, so actually running these functions will sometimes place
417*44704f69SBart Van Assche# results into a variable named after the function, and often use
418*44704f69SBart Van Assche# temporary variables in the '^_G_' namespace. If you are careful to
419*44704f69SBart Van Assche# avoid using those namespaces casually in your sourcing script, things
420*44704f69SBart Van Assche# should continue to work as you expect. And, of course, you can freely
421*44704f69SBart Van Assche# overwrite any of the functions or variables defined here before
422*44704f69SBart Van Assche# calling anything to customize them.
423*44704f69SBart Van Assche
424*44704f69SBart Van AsscheEXIT_SUCCESS=0
425*44704f69SBart Van AsscheEXIT_FAILURE=1
426*44704f69SBart Van AsscheEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427*44704f69SBart Van AsscheEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
428*44704f69SBart Van Assche
429*44704f69SBart Van Assche# Allow overriding, eg assuming that you follow the convention of
430*44704f69SBart Van Assche# putting '$debug_cmd' at the start of all your functions, you can get
431*44704f69SBart Van Assche# bash to show function call trace with:
432*44704f69SBart Van Assche#
433*44704f69SBart Van Assche#    debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434*44704f69SBart Van Asschedebug_cmd=${debug_cmd-":"}
435*44704f69SBart Van Asscheexit_cmd=:
436*44704f69SBart Van Assche
437*44704f69SBart Van Assche# By convention, finish your script with:
438*44704f69SBart Van Assche#
439*44704f69SBart Van Assche#    exit $exit_status
440*44704f69SBart Van Assche#
441*44704f69SBart Van Assche# so that you can set exit_status to non-zero if you want to indicate
442*44704f69SBart Van Assche# something went wrong during execution without actually bailing out at
443*44704f69SBart Van Assche# the point of failure.
444*44704f69SBart Van Asscheexit_status=$EXIT_SUCCESS
445*44704f69SBart Van Assche
446*44704f69SBart Van Assche# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447*44704f69SBart Van Assche# is ksh but when the shell is invoked as "sh" and the current value of
448*44704f69SBart Van Assche# the _XPG environment variable is not equal to 1 (one), the special
449*44704f69SBart Van Assche# positional parameter $0, within a function call, is the name of the
450*44704f69SBart Van Assche# function.
451*44704f69SBart Van Asscheprogpath=$0
452*44704f69SBart Van Assche
453*44704f69SBart Van Assche# The name of this program.
454*44704f69SBart Van Asscheprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455*44704f69SBart Van Assche
456*44704f69SBart Van Assche# Make sure we have an absolute progpath for reexecution:
457*44704f69SBart Van Asschecase $progpath in
458*44704f69SBart Van Assche  [\\/]*|[A-Za-z]:\\*) ;;
459*44704f69SBart Van Assche  *[\\/]*)
460*44704f69SBart Van Assche     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461*44704f69SBart Van Assche     progdir=`cd "$progdir" && pwd`
462*44704f69SBart Van Assche     progpath=$progdir/$progname
463*44704f69SBart Van Assche     ;;
464*44704f69SBart Van Assche  *)
465*44704f69SBart Van Assche     _G_IFS=$IFS
466*44704f69SBart Van Assche     IFS=${PATH_SEPARATOR-:}
467*44704f69SBart Van Assche     for progdir in $PATH; do
468*44704f69SBart Van Assche       IFS=$_G_IFS
469*44704f69SBart Van Assche       test -x "$progdir/$progname" && break
470*44704f69SBart Van Assche     done
471*44704f69SBart Van Assche     IFS=$_G_IFS
472*44704f69SBart Van Assche     test -n "$progdir" || progdir=`pwd`
473*44704f69SBart Van Assche     progpath=$progdir/$progname
474*44704f69SBart Van Assche     ;;
475*44704f69SBart Van Asscheesac
476*44704f69SBart Van Assche
477*44704f69SBart Van Assche
478*44704f69SBart Van Assche## ----------------- ##
479*44704f69SBart Van Assche## Standard options. ##
480*44704f69SBart Van Assche## ----------------- ##
481*44704f69SBart Van Assche
482*44704f69SBart Van Assche# The following options affect the operation of the functions defined
483*44704f69SBart Van Assche# below, and should be set appropriately depending on run-time para-
484*44704f69SBart Van Assche# meters passed on the command line.
485*44704f69SBart Van Assche
486*44704f69SBart Van Asscheopt_dry_run=false
487*44704f69SBart Van Asscheopt_quiet=false
488*44704f69SBart Van Asscheopt_verbose=false
489*44704f69SBart Van Assche
490*44704f69SBart Van Assche# Categories 'all' and 'none' are always available.  Append any others
491*44704f69SBart Van Assche# you will pass as the first argument to func_warning from your own
492*44704f69SBart Van Assche# code.
493*44704f69SBart Van Asschewarning_categories=
494*44704f69SBart Van Assche
495*44704f69SBart Van Assche# By default, display warnings according to 'opt_warning_types'.  Set
496*44704f69SBart Van Assche# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497*44704f69SBart Van Assche# treat the next displayed warning as a fatal error.
498*44704f69SBart Van Asschewarning_func=func_warn_and_continue
499*44704f69SBart Van Assche
500*44704f69SBart Van Assche# Set to 'all' to display all warnings, 'none' to suppress all
501*44704f69SBart Van Assche# warnings, or a space delimited list of some subset of
502*44704f69SBart Van Assche# 'warning_categories' to display only the listed warnings.
503*44704f69SBart Van Asscheopt_warning_types=all
504*44704f69SBart Van Assche
505*44704f69SBart Van Assche
506*44704f69SBart Van Assche## -------------------- ##
507*44704f69SBart Van Assche## Resource management. ##
508*44704f69SBart Van Assche## -------------------- ##
509*44704f69SBart Van Assche
510*44704f69SBart Van Assche# This section contains definitions for functions that each ensure a
511*44704f69SBart Van Assche# particular resource (a file, or a non-empty configuration variable for
512*44704f69SBart Van Assche# example) is available, and if appropriate to extract default values
513*44704f69SBart Van Assche# from pertinent package files. Call them using their associated
514*44704f69SBart Van Assche# 'require_*' variable to ensure that they are executed, at most, once.
515*44704f69SBart Van Assche#
516*44704f69SBart Van Assche# It's entirely deliberate that calling these functions can set
517*44704f69SBart Van Assche# variables that don't obey the namespace limitations obeyed by the rest
518*44704f69SBart Van Assche# of this file, in order that that they be as useful as possible to
519*44704f69SBart Van Assche# callers.
520*44704f69SBart Van Assche
521*44704f69SBart Van Assche
522*44704f69SBart Van Assche# require_term_colors
523*44704f69SBart Van Assche# -------------------
524*44704f69SBart Van Assche# Allow display of bold text on terminals that support it.
525*44704f69SBart Van Asscherequire_term_colors=func_require_term_colors
526*44704f69SBart Van Asschefunc_require_term_colors ()
527*44704f69SBart Van Assche{
528*44704f69SBart Van Assche    $debug_cmd
529*44704f69SBart Van Assche
530*44704f69SBart Van Assche    test -t 1 && {
531*44704f69SBart Van Assche      # COLORTERM and USE_ANSI_COLORS environment variables take
532*44704f69SBart Van Assche      # precedence, because most terminfo databases neglect to describe
533*44704f69SBart Van Assche      # whether color sequences are supported.
534*44704f69SBart Van Assche      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535*44704f69SBart Van Assche
536*44704f69SBart Van Assche      if test 1 = "$USE_ANSI_COLORS"; then
537*44704f69SBart Van Assche        # Standard ANSI escape sequences
538*44704f69SBart Van Assche        tc_reset=''
539*44704f69SBart Van Assche        tc_bold='';   tc_standout=''
540*44704f69SBart Van Assche        tc_red='';   tc_green=''
541*44704f69SBart Van Assche        tc_blue='';  tc_cyan=''
542*44704f69SBart Van Assche      else
543*44704f69SBart Van Assche        # Otherwise trust the terminfo database after all.
544*44704f69SBart Van Assche        test -n "`tput sgr0 2>/dev/null`" && {
545*44704f69SBart Van Assche          tc_reset=`tput sgr0`
546*44704f69SBart Van Assche          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547*44704f69SBart Van Assche          tc_standout=$tc_bold
548*44704f69SBart Van Assche          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549*44704f69SBart Van Assche          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550*44704f69SBart Van Assche          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551*44704f69SBart Van Assche          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552*44704f69SBart Van Assche          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553*44704f69SBart Van Assche        }
554*44704f69SBart Van Assche      fi
555*44704f69SBart Van Assche    }
556*44704f69SBart Van Assche
557*44704f69SBart Van Assche    require_term_colors=:
558*44704f69SBart Van Assche}
559*44704f69SBart Van Assche
560*44704f69SBart Van Assche
561*44704f69SBart Van Assche## ----------------- ##
562*44704f69SBart Van Assche## Function library. ##
563*44704f69SBart Van Assche## ----------------- ##
564*44704f69SBart Van Assche
565*44704f69SBart Van Assche# This section contains a variety of useful functions to call in your
566*44704f69SBart Van Assche# scripts. Take note of the portable wrappers for features provided by
567*44704f69SBart Van Assche# some modern shells, which will fall back to slower equivalents on
568*44704f69SBart Van Assche# less featureful shells.
569*44704f69SBart Van Assche
570*44704f69SBart Van Assche
571*44704f69SBart Van Assche# func_append VAR VALUE
572*44704f69SBart Van Assche# ---------------------
573*44704f69SBart Van Assche# Append VALUE onto the existing contents of VAR.
574*44704f69SBart Van Assche
575*44704f69SBart Van Assche  # We should try to minimise forks, especially on Windows where they are
576*44704f69SBart Van Assche  # unreasonably slow, so skip the feature probes when bash or zsh are
577*44704f69SBart Van Assche  # being used:
578*44704f69SBart Van Assche  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579*44704f69SBart Van Assche    : ${_G_HAVE_ARITH_OP="yes"}
580*44704f69SBart Van Assche    : ${_G_HAVE_XSI_OPS="yes"}
581*44704f69SBart Van Assche    # The += operator was introduced in bash 3.1
582*44704f69SBart Van Assche    case $BASH_VERSION in
583*44704f69SBart Van Assche      [12].* | 3.0 | 3.0*) ;;
584*44704f69SBart Van Assche      *)
585*44704f69SBart Van Assche        : ${_G_HAVE_PLUSEQ_OP="yes"}
586*44704f69SBart Van Assche        ;;
587*44704f69SBart Van Assche    esac
588*44704f69SBart Van Assche  fi
589*44704f69SBart Van Assche
590*44704f69SBart Van Assche  # _G_HAVE_PLUSEQ_OP
591*44704f69SBart Van Assche  # Can be empty, in which case the shell is probed, "yes" if += is
592*44704f69SBart Van Assche  # useable or anything else if it does not work.
593*44704f69SBart Van Assche  test -z "$_G_HAVE_PLUSEQ_OP" \
594*44704f69SBart Van Assche    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595*44704f69SBart Van Assche    && _G_HAVE_PLUSEQ_OP=yes
596*44704f69SBart Van Assche
597*44704f69SBart Van Asscheif test yes = "$_G_HAVE_PLUSEQ_OP"
598*44704f69SBart Van Asschethen
599*44704f69SBart Van Assche  # This is an XSI compatible shell, allowing a faster implementation...
600*44704f69SBart Van Assche  eval 'func_append ()
601*44704f69SBart Van Assche  {
602*44704f69SBart Van Assche    $debug_cmd
603*44704f69SBart Van Assche
604*44704f69SBart Van Assche    eval "$1+=\$2"
605*44704f69SBart Van Assche  }'
606*44704f69SBart Van Asscheelse
607*44704f69SBart Van Assche  # ...otherwise fall back to using expr, which is often a shell builtin.
608*44704f69SBart Van Assche  func_append ()
609*44704f69SBart Van Assche  {
610*44704f69SBart Van Assche    $debug_cmd
611*44704f69SBart Van Assche
612*44704f69SBart Van Assche    eval "$1=\$$1\$2"
613*44704f69SBart Van Assche  }
614*44704f69SBart Van Asschefi
615*44704f69SBart Van Assche
616*44704f69SBart Van Assche
617*44704f69SBart Van Assche# func_append_quoted VAR VALUE
618*44704f69SBart Van Assche# ----------------------------
619*44704f69SBart Van Assche# Quote VALUE and append to the end of shell variable VAR, separated
620*44704f69SBart Van Assche# by a space.
621*44704f69SBart Van Asscheif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622*44704f69SBart Van Assche  eval 'func_append_quoted ()
623*44704f69SBart Van Assche  {
624*44704f69SBart Van Assche    $debug_cmd
625*44704f69SBart Van Assche
626*44704f69SBart Van Assche    func_quote_arg pretty "$2"
627*44704f69SBart Van Assche    eval "$1+=\\ \$func_quote_arg_result"
628*44704f69SBart Van Assche  }'
629*44704f69SBart Van Asscheelse
630*44704f69SBart Van Assche  func_append_quoted ()
631*44704f69SBart Van Assche  {
632*44704f69SBart Van Assche    $debug_cmd
633*44704f69SBart Van Assche
634*44704f69SBart Van Assche    func_quote_arg pretty "$2"
635*44704f69SBart Van Assche    eval "$1=\$$1\\ \$func_quote_arg_result"
636*44704f69SBart Van Assche  }
637*44704f69SBart Van Asschefi
638*44704f69SBart Van Assche
639*44704f69SBart Van Assche
640*44704f69SBart Van Assche# func_append_uniq VAR VALUE
641*44704f69SBart Van Assche# --------------------------
642*44704f69SBart Van Assche# Append unique VALUE onto the existing contents of VAR, assuming
643*44704f69SBart Van Assche# entries are delimited by the first character of VALUE.  For example:
644*44704f69SBart Van Assche#
645*44704f69SBart Van Assche#   func_append_uniq options " --another-option option-argument"
646*44704f69SBart Van Assche#
647*44704f69SBart Van Assche# will only append to $options if " --another-option option-argument "
648*44704f69SBart Van Assche# is not already present somewhere in $options already (note spaces at
649*44704f69SBart Van Assche# each end implied by leading space in second argument).
650*44704f69SBart Van Asschefunc_append_uniq ()
651*44704f69SBart Van Assche{
652*44704f69SBart Van Assche    $debug_cmd
653*44704f69SBart Van Assche
654*44704f69SBart Van Assche    eval _G_current_value='`$ECHO $'$1'`'
655*44704f69SBart Van Assche    _G_delim=`expr "$2" : '\(.\)'`
656*44704f69SBart Van Assche
657*44704f69SBart Van Assche    case $_G_delim$_G_current_value$_G_delim in
658*44704f69SBart Van Assche      *"$2$_G_delim"*) ;;
659*44704f69SBart Van Assche      *) func_append "$@" ;;
660*44704f69SBart Van Assche    esac
661*44704f69SBart Van Assche}
662*44704f69SBart Van Assche
663*44704f69SBart Van Assche
664*44704f69SBart Van Assche# func_arith TERM...
665*44704f69SBart Van Assche# ------------------
666*44704f69SBart Van Assche# Set func_arith_result to the result of evaluating TERMs.
667*44704f69SBart Van Assche  test -z "$_G_HAVE_ARITH_OP" \
668*44704f69SBart Van Assche    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669*44704f69SBart Van Assche    && _G_HAVE_ARITH_OP=yes
670*44704f69SBart Van Assche
671*44704f69SBart Van Asscheif test yes = "$_G_HAVE_ARITH_OP"; then
672*44704f69SBart Van Assche  eval 'func_arith ()
673*44704f69SBart Van Assche  {
674*44704f69SBart Van Assche    $debug_cmd
675*44704f69SBart Van Assche
676*44704f69SBart Van Assche    func_arith_result=$(( $* ))
677*44704f69SBart Van Assche  }'
678*44704f69SBart Van Asscheelse
679*44704f69SBart Van Assche  func_arith ()
680*44704f69SBart Van Assche  {
681*44704f69SBart Van Assche    $debug_cmd
682*44704f69SBart Van Assche
683*44704f69SBart Van Assche    func_arith_result=`expr "$@"`
684*44704f69SBart Van Assche  }
685*44704f69SBart Van Asschefi
686*44704f69SBart Van Assche
687*44704f69SBart Van Assche
688*44704f69SBart Van Assche# func_basename FILE
689*44704f69SBart Van Assche# ------------------
690*44704f69SBart Van Assche# Set func_basename_result to FILE with everything up to and including
691*44704f69SBart Van Assche# the last / stripped.
692*44704f69SBart Van Asscheif test yes = "$_G_HAVE_XSI_OPS"; then
693*44704f69SBart Van Assche  # If this shell supports suffix pattern removal, then use it to avoid
694*44704f69SBart Van Assche  # forking. Hide the definitions single quotes in case the shell chokes
695*44704f69SBart Van Assche  # on unsupported syntax...
696*44704f69SBart Van Assche  _b='func_basename_result=${1##*/}'
697*44704f69SBart Van Assche  _d='case $1 in
698*44704f69SBart Van Assche        */*) func_dirname_result=${1%/*}$2 ;;
699*44704f69SBart Van Assche        *  ) func_dirname_result=$3        ;;
700*44704f69SBart Van Assche      esac'
701*44704f69SBart Van Assche
702*44704f69SBart Van Asscheelse
703*44704f69SBart Van Assche  # ...otherwise fall back to using sed.
704*44704f69SBart Van Assche  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705*44704f69SBart Van Assche  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706*44704f69SBart Van Assche      if test "X$func_dirname_result" = "X$1"; then
707*44704f69SBart Van Assche        func_dirname_result=$3
708*44704f69SBart Van Assche      else
709*44704f69SBart Van Assche        func_append func_dirname_result "$2"
710*44704f69SBart Van Assche      fi'
711*44704f69SBart Van Asschefi
712*44704f69SBart Van Assche
713*44704f69SBart Van Asscheeval 'func_basename ()
714*44704f69SBart Van Assche{
715*44704f69SBart Van Assche    $debug_cmd
716*44704f69SBart Van Assche
717*44704f69SBart Van Assche    '"$_b"'
718*44704f69SBart Van Assche}'
719*44704f69SBart Van Assche
720*44704f69SBart Van Assche
721*44704f69SBart Van Assche# func_dirname FILE APPEND NONDIR_REPLACEMENT
722*44704f69SBart Van Assche# -------------------------------------------
723*44704f69SBart Van Assche# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724*44704f69SBart Van Assche# otherwise set result to NONDIR_REPLACEMENT.
725*44704f69SBart Van Asscheeval 'func_dirname ()
726*44704f69SBart Van Assche{
727*44704f69SBart Van Assche    $debug_cmd
728*44704f69SBart Van Assche
729*44704f69SBart Van Assche    '"$_d"'
730*44704f69SBart Van Assche}'
731*44704f69SBart Van Assche
732*44704f69SBart Van Assche
733*44704f69SBart Van Assche# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734*44704f69SBart Van Assche# --------------------------------------------------------
735*44704f69SBart Van Assche# Perform func_basename and func_dirname in a single function
736*44704f69SBart Van Assche# call:
737*44704f69SBart Van Assche#   dirname:  Compute the dirname of FILE.  If nonempty,
738*44704f69SBart Van Assche#             add APPEND to the result, otherwise set result
739*44704f69SBart Van Assche#             to NONDIR_REPLACEMENT.
740*44704f69SBart Van Assche#             value returned in "$func_dirname_result"
741*44704f69SBart Van Assche#   basename: Compute filename of FILE.
742*44704f69SBart Van Assche#             value retuned in "$func_basename_result"
743*44704f69SBart Van Assche# For efficiency, we do not delegate to the functions above but instead
744*44704f69SBart Van Assche# duplicate the functionality here.
745*44704f69SBart Van Asscheeval 'func_dirname_and_basename ()
746*44704f69SBart Van Assche{
747*44704f69SBart Van Assche    $debug_cmd
748*44704f69SBart Van Assche
749*44704f69SBart Van Assche    '"$_b"'
750*44704f69SBart Van Assche    '"$_d"'
751*44704f69SBart Van Assche}'
752*44704f69SBart Van Assche
753*44704f69SBart Van Assche
754*44704f69SBart Van Assche# func_echo ARG...
755*44704f69SBart Van Assche# ----------------
756*44704f69SBart Van Assche# Echo program name prefixed message.
757*44704f69SBart Van Asschefunc_echo ()
758*44704f69SBart Van Assche{
759*44704f69SBart Van Assche    $debug_cmd
760*44704f69SBart Van Assche
761*44704f69SBart Van Assche    _G_message=$*
762*44704f69SBart Van Assche
763*44704f69SBart Van Assche    func_echo_IFS=$IFS
764*44704f69SBart Van Assche    IFS=$nl
765*44704f69SBart Van Assche    for _G_line in $_G_message; do
766*44704f69SBart Van Assche      IFS=$func_echo_IFS
767*44704f69SBart Van Assche      $ECHO "$progname: $_G_line"
768*44704f69SBart Van Assche    done
769*44704f69SBart Van Assche    IFS=$func_echo_IFS
770*44704f69SBart Van Assche}
771*44704f69SBart Van Assche
772*44704f69SBart Van Assche
773*44704f69SBart Van Assche# func_echo_all ARG...
774*44704f69SBart Van Assche# --------------------
775*44704f69SBart Van Assche# Invoke $ECHO with all args, space-separated.
776*44704f69SBart Van Asschefunc_echo_all ()
777*44704f69SBart Van Assche{
778*44704f69SBart Van Assche    $ECHO "$*"
779*44704f69SBart Van Assche}
780*44704f69SBart Van Assche
781*44704f69SBart Van Assche
782*44704f69SBart Van Assche# func_echo_infix_1 INFIX ARG...
783*44704f69SBart Van Assche# ------------------------------
784*44704f69SBart Van Assche# Echo program name, followed by INFIX on the first line, with any
785*44704f69SBart Van Assche# additional lines not showing INFIX.
786*44704f69SBart Van Asschefunc_echo_infix_1 ()
787*44704f69SBart Van Assche{
788*44704f69SBart Van Assche    $debug_cmd
789*44704f69SBart Van Assche
790*44704f69SBart Van Assche    $require_term_colors
791*44704f69SBart Van Assche
792*44704f69SBart Van Assche    _G_infix=$1; shift
793*44704f69SBart Van Assche    _G_indent=$_G_infix
794*44704f69SBart Van Assche    _G_prefix="$progname: $_G_infix: "
795*44704f69SBart Van Assche    _G_message=$*
796*44704f69SBart Van Assche
797*44704f69SBart Van Assche    # Strip color escape sequences before counting printable length
798*44704f69SBart Van Assche    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799*44704f69SBart Van Assche    do
800*44704f69SBart Van Assche      test -n "$_G_tc" && {
801*44704f69SBart Van Assche        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802*44704f69SBart Van Assche        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803*44704f69SBart Van Assche      }
804*44704f69SBart Van Assche    done
805*44704f69SBart Van Assche    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806*44704f69SBart Van Assche
807*44704f69SBart Van Assche    func_echo_infix_1_IFS=$IFS
808*44704f69SBart Van Assche    IFS=$nl
809*44704f69SBart Van Assche    for _G_line in $_G_message; do
810*44704f69SBart Van Assche      IFS=$func_echo_infix_1_IFS
811*44704f69SBart Van Assche      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812*44704f69SBart Van Assche      _G_prefix=$_G_indent
813*44704f69SBart Van Assche    done
814*44704f69SBart Van Assche    IFS=$func_echo_infix_1_IFS
815*44704f69SBart Van Assche}
816*44704f69SBart Van Assche
817*44704f69SBart Van Assche
818*44704f69SBart Van Assche# func_error ARG...
819*44704f69SBart Van Assche# -----------------
820*44704f69SBart Van Assche# Echo program name prefixed message to standard error.
821*44704f69SBart Van Asschefunc_error ()
822*44704f69SBart Van Assche{
823*44704f69SBart Van Assche    $debug_cmd
824*44704f69SBart Van Assche
825*44704f69SBart Van Assche    $require_term_colors
826*44704f69SBart Van Assche
827*44704f69SBart Van Assche    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828*44704f69SBart Van Assche}
829*44704f69SBart Van Assche
830*44704f69SBart Van Assche
831*44704f69SBart Van Assche# func_fatal_error ARG...
832*44704f69SBart Van Assche# -----------------------
833*44704f69SBart Van Assche# Echo program name prefixed message to standard error, and exit.
834*44704f69SBart Van Asschefunc_fatal_error ()
835*44704f69SBart Van Assche{
836*44704f69SBart Van Assche    $debug_cmd
837*44704f69SBart Van Assche
838*44704f69SBart Van Assche    func_error "$*"
839*44704f69SBart Van Assche    exit $EXIT_FAILURE
840*44704f69SBart Van Assche}
841*44704f69SBart Van Assche
842*44704f69SBart Van Assche
843*44704f69SBart Van Assche# func_grep EXPRESSION FILENAME
844*44704f69SBart Van Assche# -----------------------------
845*44704f69SBart Van Assche# Check whether EXPRESSION matches any line of FILENAME, without output.
846*44704f69SBart Van Asschefunc_grep ()
847*44704f69SBart Van Assche{
848*44704f69SBart Van Assche    $debug_cmd
849*44704f69SBart Van Assche
850*44704f69SBart Van Assche    $GREP "$1" "$2" >/dev/null 2>&1
851*44704f69SBart Van Assche}
852*44704f69SBart Van Assche
853*44704f69SBart Van Assche
854*44704f69SBart Van Assche# func_len STRING
855*44704f69SBart Van Assche# ---------------
856*44704f69SBart Van Assche# Set func_len_result to the length of STRING. STRING may not
857*44704f69SBart Van Assche# start with a hyphen.
858*44704f69SBart Van Assche  test -z "$_G_HAVE_XSI_OPS" \
859*44704f69SBart Van Assche    && (eval 'x=a/b/c;
860*44704f69SBart Van Assche      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861*44704f69SBart Van Assche    && _G_HAVE_XSI_OPS=yes
862*44704f69SBart Van Assche
863*44704f69SBart Van Asscheif test yes = "$_G_HAVE_XSI_OPS"; then
864*44704f69SBart Van Assche  eval 'func_len ()
865*44704f69SBart Van Assche  {
866*44704f69SBart Van Assche    $debug_cmd
867*44704f69SBart Van Assche
868*44704f69SBart Van Assche    func_len_result=${#1}
869*44704f69SBart Van Assche  }'
870*44704f69SBart Van Asscheelse
871*44704f69SBart Van Assche  func_len ()
872*44704f69SBart Van Assche  {
873*44704f69SBart Van Assche    $debug_cmd
874*44704f69SBart Van Assche
875*44704f69SBart Van Assche    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876*44704f69SBart Van Assche  }
877*44704f69SBart Van Asschefi
878*44704f69SBart Van Assche
879*44704f69SBart Van Assche
880*44704f69SBart Van Assche# func_mkdir_p DIRECTORY-PATH
881*44704f69SBart Van Assche# ---------------------------
882*44704f69SBart Van Assche# Make sure the entire path to DIRECTORY-PATH is available.
883*44704f69SBart Van Asschefunc_mkdir_p ()
884*44704f69SBart Van Assche{
885*44704f69SBart Van Assche    $debug_cmd
886*44704f69SBart Van Assche
887*44704f69SBart Van Assche    _G_directory_path=$1
888*44704f69SBart Van Assche    _G_dir_list=
889*44704f69SBart Van Assche
890*44704f69SBart Van Assche    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891*44704f69SBart Van Assche
892*44704f69SBart Van Assche      # Protect directory names starting with '-'
893*44704f69SBart Van Assche      case $_G_directory_path in
894*44704f69SBart Van Assche        -*) _G_directory_path=./$_G_directory_path ;;
895*44704f69SBart Van Assche      esac
896*44704f69SBart Van Assche
897*44704f69SBart Van Assche      # While some portion of DIR does not yet exist...
898*44704f69SBart Van Assche      while test ! -d "$_G_directory_path"; do
899*44704f69SBart Van Assche        # ...make a list in topmost first order.  Use a colon delimited
900*44704f69SBart Van Assche	# list incase some portion of path contains whitespace.
901*44704f69SBart Van Assche        _G_dir_list=$_G_directory_path:$_G_dir_list
902*44704f69SBart Van Assche
903*44704f69SBart Van Assche        # If the last portion added has no slash in it, the list is done
904*44704f69SBart Van Assche        case $_G_directory_path in */*) ;; *) break ;; esac
905*44704f69SBart Van Assche
906*44704f69SBart Van Assche        # ...otherwise throw away the child directory and loop
907*44704f69SBart Van Assche        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908*44704f69SBart Van Assche      done
909*44704f69SBart Van Assche      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910*44704f69SBart Van Assche
911*44704f69SBart Van Assche      func_mkdir_p_IFS=$IFS; IFS=:
912*44704f69SBart Van Assche      for _G_dir in $_G_dir_list; do
913*44704f69SBart Van Assche	IFS=$func_mkdir_p_IFS
914*44704f69SBart Van Assche        # mkdir can fail with a 'File exist' error if two processes
915*44704f69SBart Van Assche        # try to create one of the directories concurrently.  Don't
916*44704f69SBart Van Assche        # stop in that case!
917*44704f69SBart Van Assche        $MKDIR "$_G_dir" 2>/dev/null || :
918*44704f69SBart Van Assche      done
919*44704f69SBart Van Assche      IFS=$func_mkdir_p_IFS
920*44704f69SBart Van Assche
921*44704f69SBart Van Assche      # Bail out if we (or some other process) failed to create a directory.
922*44704f69SBart Van Assche      test -d "$_G_directory_path" || \
923*44704f69SBart Van Assche        func_fatal_error "Failed to create '$1'"
924*44704f69SBart Van Assche    fi
925*44704f69SBart Van Assche}
926*44704f69SBart Van Assche
927*44704f69SBart Van Assche
928*44704f69SBart Van Assche# func_mktempdir [BASENAME]
929*44704f69SBart Van Assche# -------------------------
930*44704f69SBart Van Assche# Make a temporary directory that won't clash with other running
931*44704f69SBart Van Assche# libtool processes, and avoids race conditions if possible.  If
932*44704f69SBart Van Assche# given, BASENAME is the basename for that directory.
933*44704f69SBart Van Asschefunc_mktempdir ()
934*44704f69SBart Van Assche{
935*44704f69SBart Van Assche    $debug_cmd
936*44704f69SBart Van Assche
937*44704f69SBart Van Assche    _G_template=${TMPDIR-/tmp}/${1-$progname}
938*44704f69SBart Van Assche
939*44704f69SBart Van Assche    if test : = "$opt_dry_run"; then
940*44704f69SBart Van Assche      # Return a directory name, but don't create it in dry-run mode
941*44704f69SBart Van Assche      _G_tmpdir=$_G_template-$$
942*44704f69SBart Van Assche    else
943*44704f69SBart Van Assche
944*44704f69SBart Van Assche      # If mktemp works, use that first and foremost
945*44704f69SBart Van Assche      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
946*44704f69SBart Van Assche
947*44704f69SBart Van Assche      if test ! -d "$_G_tmpdir"; then
948*44704f69SBart Van Assche        # Failing that, at least try and use $RANDOM to avoid a race
949*44704f69SBart Van Assche        _G_tmpdir=$_G_template-${RANDOM-0}$$
950*44704f69SBart Van Assche
951*44704f69SBart Van Assche        func_mktempdir_umask=`umask`
952*44704f69SBart Van Assche        umask 0077
953*44704f69SBart Van Assche        $MKDIR "$_G_tmpdir"
954*44704f69SBart Van Assche        umask $func_mktempdir_umask
955*44704f69SBart Van Assche      fi
956*44704f69SBart Van Assche
957*44704f69SBart Van Assche      # If we're not in dry-run mode, bomb out on failure
958*44704f69SBart Van Assche      test -d "$_G_tmpdir" || \
959*44704f69SBart Van Assche        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
960*44704f69SBart Van Assche    fi
961*44704f69SBart Van Assche
962*44704f69SBart Van Assche    $ECHO "$_G_tmpdir"
963*44704f69SBart Van Assche}
964*44704f69SBart Van Assche
965*44704f69SBart Van Assche
966*44704f69SBart Van Assche# func_normal_abspath PATH
967*44704f69SBart Van Assche# ------------------------
968*44704f69SBart Van Assche# Remove doubled-up and trailing slashes, "." path components,
969*44704f69SBart Van Assche# and cancel out any ".." path components in PATH after making
970*44704f69SBart Van Assche# it an absolute path.
971*44704f69SBart Van Asschefunc_normal_abspath ()
972*44704f69SBart Van Assche{
973*44704f69SBart Van Assche    $debug_cmd
974*44704f69SBart Van Assche
975*44704f69SBart Van Assche    # These SED scripts presuppose an absolute path with a trailing slash.
976*44704f69SBart Van Assche    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977*44704f69SBart Van Assche    _G_pathcdr='s|^/[^/]*||'
978*44704f69SBart Van Assche    _G_removedotparts=':dotsl
979*44704f69SBart Van Assche		s|/\./|/|g
980*44704f69SBart Van Assche		t dotsl
981*44704f69SBart Van Assche		s|/\.$|/|'
982*44704f69SBart Van Assche    _G_collapseslashes='s|/\{1,\}|/|g'
983*44704f69SBart Van Assche    _G_finalslash='s|/*$|/|'
984*44704f69SBart Van Assche
985*44704f69SBart Van Assche    # Start from root dir and reassemble the path.
986*44704f69SBart Van Assche    func_normal_abspath_result=
987*44704f69SBart Van Assche    func_normal_abspath_tpath=$1
988*44704f69SBart Van Assche    func_normal_abspath_altnamespace=
989*44704f69SBart Van Assche    case $func_normal_abspath_tpath in
990*44704f69SBart Van Assche      "")
991*44704f69SBart Van Assche        # Empty path, that just means $cwd.
992*44704f69SBart Van Assche        func_stripname '' '/' "`pwd`"
993*44704f69SBart Van Assche        func_normal_abspath_result=$func_stripname_result
994*44704f69SBart Van Assche        return
995*44704f69SBart Van Assche        ;;
996*44704f69SBart Van Assche      # The next three entries are used to spot a run of precisely
997*44704f69SBart Van Assche      # two leading slashes without using negated character classes;
998*44704f69SBart Van Assche      # we take advantage of case's first-match behaviour.
999*44704f69SBart Van Assche      ///*)
1000*44704f69SBart Van Assche        # Unusual form of absolute path, do nothing.
1001*44704f69SBart Van Assche        ;;
1002*44704f69SBart Van Assche      //*)
1003*44704f69SBart Van Assche        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004*44704f69SBart Van Assche        # and for example Cygwin uses it to access remote file shares
1005*44704f69SBart Van Assche        # over CIFS/SMB, so we conserve a leading double slash if found.
1006*44704f69SBart Van Assche        func_normal_abspath_altnamespace=/
1007*44704f69SBart Van Assche        ;;
1008*44704f69SBart Van Assche      /*)
1009*44704f69SBart Van Assche        # Absolute path, do nothing.
1010*44704f69SBart Van Assche        ;;
1011*44704f69SBart Van Assche      *)
1012*44704f69SBart Van Assche        # Relative path, prepend $cwd.
1013*44704f69SBart Van Assche        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014*44704f69SBart Van Assche        ;;
1015*44704f69SBart Van Assche    esac
1016*44704f69SBart Van Assche
1017*44704f69SBart Van Assche    # Cancel out all the simple stuff to save iterations.  We also want
1018*44704f69SBart Van Assche    # the path to end with a slash for ease of parsing, so make sure
1019*44704f69SBart Van Assche    # there is one (and only one) here.
1020*44704f69SBart Van Assche    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021*44704f69SBart Van Assche          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022*44704f69SBart Van Assche    while :; do
1023*44704f69SBart Van Assche      # Processed it all yet?
1024*44704f69SBart Van Assche      if test / = "$func_normal_abspath_tpath"; then
1025*44704f69SBart Van Assche        # If we ascended to the root using ".." the result may be empty now.
1026*44704f69SBart Van Assche        if test -z "$func_normal_abspath_result"; then
1027*44704f69SBart Van Assche          func_normal_abspath_result=/
1028*44704f69SBart Van Assche        fi
1029*44704f69SBart Van Assche        break
1030*44704f69SBart Van Assche      fi
1031*44704f69SBart Van Assche      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032*44704f69SBart Van Assche          -e "$_G_pathcar"`
1033*44704f69SBart Van Assche      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034*44704f69SBart Van Assche          -e "$_G_pathcdr"`
1035*44704f69SBart Van Assche      # Figure out what to do with it
1036*44704f69SBart Van Assche      case $func_normal_abspath_tcomponent in
1037*44704f69SBart Van Assche        "")
1038*44704f69SBart Van Assche          # Trailing empty path component, ignore it.
1039*44704f69SBart Van Assche          ;;
1040*44704f69SBart Van Assche        ..)
1041*44704f69SBart Van Assche          # Parent dir; strip last assembled component from result.
1042*44704f69SBart Van Assche          func_dirname "$func_normal_abspath_result"
1043*44704f69SBart Van Assche          func_normal_abspath_result=$func_dirname_result
1044*44704f69SBart Van Assche          ;;
1045*44704f69SBart Van Assche        *)
1046*44704f69SBart Van Assche          # Actual path component, append it.
1047*44704f69SBart Van Assche          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048*44704f69SBart Van Assche          ;;
1049*44704f69SBart Van Assche      esac
1050*44704f69SBart Van Assche    done
1051*44704f69SBart Van Assche    # Restore leading double-slash if one was found on entry.
1052*44704f69SBart Van Assche    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053*44704f69SBart Van Assche}
1054*44704f69SBart Van Assche
1055*44704f69SBart Van Assche
1056*44704f69SBart Van Assche# func_notquiet ARG...
1057*44704f69SBart Van Assche# --------------------
1058*44704f69SBart Van Assche# Echo program name prefixed message only when not in quiet mode.
1059*44704f69SBart Van Asschefunc_notquiet ()
1060*44704f69SBart Van Assche{
1061*44704f69SBart Van Assche    $debug_cmd
1062*44704f69SBart Van Assche
1063*44704f69SBart Van Assche    $opt_quiet || func_echo ${1+"$@"}
1064*44704f69SBart Van Assche
1065*44704f69SBart Van Assche    # A bug in bash halts the script if the last line of a function
1066*44704f69SBart Van Assche    # fails when set -e is in force, so we need another command to
1067*44704f69SBart Van Assche    # work around that:
1068*44704f69SBart Van Assche    :
1069*44704f69SBart Van Assche}
1070*44704f69SBart Van Assche
1071*44704f69SBart Van Assche
1072*44704f69SBart Van Assche# func_relative_path SRCDIR DSTDIR
1073*44704f69SBart Van Assche# --------------------------------
1074*44704f69SBart Van Assche# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075*44704f69SBart Van Asschefunc_relative_path ()
1076*44704f69SBart Van Assche{
1077*44704f69SBart Van Assche    $debug_cmd
1078*44704f69SBart Van Assche
1079*44704f69SBart Van Assche    func_relative_path_result=
1080*44704f69SBart Van Assche    func_normal_abspath "$1"
1081*44704f69SBart Van Assche    func_relative_path_tlibdir=$func_normal_abspath_result
1082*44704f69SBart Van Assche    func_normal_abspath "$2"
1083*44704f69SBart Van Assche    func_relative_path_tbindir=$func_normal_abspath_result
1084*44704f69SBart Van Assche
1085*44704f69SBart Van Assche    # Ascend the tree starting from libdir
1086*44704f69SBart Van Assche    while :; do
1087*44704f69SBart Van Assche      # check if we have found a prefix of bindir
1088*44704f69SBart Van Assche      case $func_relative_path_tbindir in
1089*44704f69SBart Van Assche        $func_relative_path_tlibdir)
1090*44704f69SBart Van Assche          # found an exact match
1091*44704f69SBart Van Assche          func_relative_path_tcancelled=
1092*44704f69SBart Van Assche          break
1093*44704f69SBart Van Assche          ;;
1094*44704f69SBart Van Assche        $func_relative_path_tlibdir*)
1095*44704f69SBart Van Assche          # found a matching prefix
1096*44704f69SBart Van Assche          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097*44704f69SBart Van Assche          func_relative_path_tcancelled=$func_stripname_result
1098*44704f69SBart Van Assche          if test -z "$func_relative_path_result"; then
1099*44704f69SBart Van Assche            func_relative_path_result=.
1100*44704f69SBart Van Assche          fi
1101*44704f69SBart Van Assche          break
1102*44704f69SBart Van Assche          ;;
1103*44704f69SBart Van Assche        *)
1104*44704f69SBart Van Assche          func_dirname $func_relative_path_tlibdir
1105*44704f69SBart Van Assche          func_relative_path_tlibdir=$func_dirname_result
1106*44704f69SBart Van Assche          if test -z "$func_relative_path_tlibdir"; then
1107*44704f69SBart Van Assche            # Have to descend all the way to the root!
1108*44704f69SBart Van Assche            func_relative_path_result=../$func_relative_path_result
1109*44704f69SBart Van Assche            func_relative_path_tcancelled=$func_relative_path_tbindir
1110*44704f69SBart Van Assche            break
1111*44704f69SBart Van Assche          fi
1112*44704f69SBart Van Assche          func_relative_path_result=../$func_relative_path_result
1113*44704f69SBart Van Assche          ;;
1114*44704f69SBart Van Assche      esac
1115*44704f69SBart Van Assche    done
1116*44704f69SBart Van Assche
1117*44704f69SBart Van Assche    # Now calculate path; take care to avoid doubling-up slashes.
1118*44704f69SBart Van Assche    func_stripname '' '/' "$func_relative_path_result"
1119*44704f69SBart Van Assche    func_relative_path_result=$func_stripname_result
1120*44704f69SBart Van Assche    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121*44704f69SBart Van Assche    if test -n "$func_stripname_result"; then
1122*44704f69SBart Van Assche      func_append func_relative_path_result "/$func_stripname_result"
1123*44704f69SBart Van Assche    fi
1124*44704f69SBart Van Assche
1125*44704f69SBart Van Assche    # Normalisation. If bindir is libdir, return '.' else relative path.
1126*44704f69SBart Van Assche    if test -n "$func_relative_path_result"; then
1127*44704f69SBart Van Assche      func_stripname './' '' "$func_relative_path_result"
1128*44704f69SBart Van Assche      func_relative_path_result=$func_stripname_result
1129*44704f69SBart Van Assche    fi
1130*44704f69SBart Van Assche
1131*44704f69SBart Van Assche    test -n "$func_relative_path_result" || func_relative_path_result=.
1132*44704f69SBart Van Assche
1133*44704f69SBart Van Assche    :
1134*44704f69SBart Van Assche}
1135*44704f69SBart Van Assche
1136*44704f69SBart Van Assche
1137*44704f69SBart Van Assche# func_quote_portable EVAL ARG
1138*44704f69SBart Van Assche# ----------------------------
1139*44704f69SBart Van Assche# Internal function to portably implement func_quote_arg.  Note that we still
1140*44704f69SBart Van Assche# keep attention to performance here so we as much as possible try to avoid
1141*44704f69SBart Van Assche# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142*44704f69SBart Van Asschefunc_quote_portable ()
1143*44704f69SBart Van Assche{
1144*44704f69SBart Van Assche    $debug_cmd
1145*44704f69SBart Van Assche
1146*44704f69SBart Van Assche    $require_check_ifs_backslash
1147*44704f69SBart Van Assche
1148*44704f69SBart Van Assche    func_quote_portable_result=$2
1149*44704f69SBart Van Assche
1150*44704f69SBart Van Assche    # one-time-loop (easy break)
1151*44704f69SBart Van Assche    while true
1152*44704f69SBart Van Assche    do
1153*44704f69SBart Van Assche      if $1; then
1154*44704f69SBart Van Assche        func_quote_portable_result=`$ECHO "$2" | $SED \
1155*44704f69SBart Van Assche          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156*44704f69SBart Van Assche        break
1157*44704f69SBart Van Assche      fi
1158*44704f69SBart Van Assche
1159*44704f69SBart Van Assche      # Quote for eval.
1160*44704f69SBart Van Assche      case $func_quote_portable_result in
1161*44704f69SBart Van Assche        *[\\\`\"\$]*)
1162*44704f69SBart Van Assche          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163*44704f69SBart Van Assche          # contains the shell wildcard characters.
1164*44704f69SBart Van Assche          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165*44704f69SBart Van Assche            :*|*[\[\*\?]*)
1166*44704f69SBart Van Assche              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167*44704f69SBart Van Assche                  | $SED "$sed_quote_subst"`
1168*44704f69SBart Van Assche              break
1169*44704f69SBart Van Assche              ;;
1170*44704f69SBart Van Assche          esac
1171*44704f69SBart Van Assche
1172*44704f69SBart Van Assche          func_quote_portable_old_IFS=$IFS
1173*44704f69SBart Van Assche          for _G_char in '\' '`' '"' '$'
1174*44704f69SBart Van Assche          do
1175*44704f69SBart Van Assche            # STATE($1) PREV($2) SEPARATOR($3)
1176*44704f69SBart Van Assche            set start "" ""
1177*44704f69SBart Van Assche            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178*44704f69SBart Van Assche            IFS=$_G_char
1179*44704f69SBart Van Assche            for _G_part in $func_quote_portable_result
1180*44704f69SBart Van Assche            do
1181*44704f69SBart Van Assche              case $1 in
1182*44704f69SBart Van Assche              quote)
1183*44704f69SBart Van Assche                func_append func_quote_portable_result "$3$2"
1184*44704f69SBart Van Assche                set quote "$_G_part" "\\$_G_char"
1185*44704f69SBart Van Assche                ;;
1186*44704f69SBart Van Assche              start)
1187*44704f69SBart Van Assche                set first "" ""
1188*44704f69SBart Van Assche                func_quote_portable_result=
1189*44704f69SBart Van Assche                ;;
1190*44704f69SBart Van Assche              first)
1191*44704f69SBart Van Assche                set quote "$_G_part" ""
1192*44704f69SBart Van Assche                ;;
1193*44704f69SBart Van Assche              esac
1194*44704f69SBart Van Assche            done
1195*44704f69SBart Van Assche          done
1196*44704f69SBart Van Assche          IFS=$func_quote_portable_old_IFS
1197*44704f69SBart Van Assche          ;;
1198*44704f69SBart Van Assche        *) ;;
1199*44704f69SBart Van Assche      esac
1200*44704f69SBart Van Assche      break
1201*44704f69SBart Van Assche    done
1202*44704f69SBart Van Assche
1203*44704f69SBart Van Assche    func_quote_portable_unquoted_result=$func_quote_portable_result
1204*44704f69SBart Van Assche    case $func_quote_portable_result in
1205*44704f69SBart Van Assche      # double-quote args containing shell metacharacters to delay
1206*44704f69SBart Van Assche      # word splitting, command substitution and variable expansion
1207*44704f69SBart Van Assche      # for a subsequent eval.
1208*44704f69SBart Van Assche      # many bourne shells cannot handle close brackets correctly
1209*44704f69SBart Van Assche      # in scan sets, so we specify it separately.
1210*44704f69SBart Van Assche      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211*44704f69SBart Van Assche        func_quote_portable_result=\"$func_quote_portable_result\"
1212*44704f69SBart Van Assche        ;;
1213*44704f69SBart Van Assche    esac
1214*44704f69SBart Van Assche}
1215*44704f69SBart Van Assche
1216*44704f69SBart Van Assche
1217*44704f69SBart Van Assche# func_quotefast_eval ARG
1218*44704f69SBart Van Assche# -----------------------
1219*44704f69SBart Van Assche# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220*44704f69SBart Van Assche# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221*44704f69SBart Van Asscheif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222*44704f69SBart Van Assche  printf -v _GL_test_printf_tilde %q '~'
1223*44704f69SBart Van Assche  if test '\~' = "$_GL_test_printf_tilde"; then
1224*44704f69SBart Van Assche    func_quotefast_eval ()
1225*44704f69SBart Van Assche    {
1226*44704f69SBart Van Assche      printf -v func_quotefast_eval_result %q "$1"
1227*44704f69SBart Van Assche    }
1228*44704f69SBart Van Assche  else
1229*44704f69SBart Van Assche    # Broken older Bash implementations.  Make those faster too if possible.
1230*44704f69SBart Van Assche    func_quotefast_eval ()
1231*44704f69SBart Van Assche    {
1232*44704f69SBart Van Assche      case $1 in
1233*44704f69SBart Van Assche        '~'*)
1234*44704f69SBart Van Assche          func_quote_portable false "$1"
1235*44704f69SBart Van Assche          func_quotefast_eval_result=$func_quote_portable_result
1236*44704f69SBart Van Assche          ;;
1237*44704f69SBart Van Assche        *)
1238*44704f69SBart Van Assche          printf -v func_quotefast_eval_result %q "$1"
1239*44704f69SBart Van Assche          ;;
1240*44704f69SBart Van Assche      esac
1241*44704f69SBart Van Assche    }
1242*44704f69SBart Van Assche  fi
1243*44704f69SBart Van Asscheelse
1244*44704f69SBart Van Assche  func_quotefast_eval ()
1245*44704f69SBart Van Assche  {
1246*44704f69SBart Van Assche    func_quote_portable false "$1"
1247*44704f69SBart Van Assche    func_quotefast_eval_result=$func_quote_portable_result
1248*44704f69SBart Van Assche  }
1249*44704f69SBart Van Asschefi
1250*44704f69SBart Van Assche
1251*44704f69SBart Van Assche
1252*44704f69SBart Van Assche# func_quote_arg MODEs ARG
1253*44704f69SBart Van Assche# ------------------------
1254*44704f69SBart Van Assche# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255*44704f69SBart Van Assche# specifiers listed below separated by ',' character.  This function returns two
1256*44704f69SBart Van Assche# values:
1257*44704f69SBart Van Assche#   i) func_quote_arg_result
1258*44704f69SBart Van Assche#      double-quoted (when needed), suitable for a subsequent eval
1259*44704f69SBart Van Assche#  ii) func_quote_arg_unquoted_result
1260*44704f69SBart Van Assche#      has all characters that are still active within double
1261*44704f69SBart Van Assche#      quotes backslashified.  Available only if 'unquoted' is specified.
1262*44704f69SBart Van Assche#
1263*44704f69SBart Van Assche# Available modes:
1264*44704f69SBart Van Assche# ----------------
1265*44704f69SBart Van Assche# 'eval' (default)
1266*44704f69SBart Van Assche#       - escape shell special characters
1267*44704f69SBart Van Assche# 'expand'
1268*44704f69SBart Van Assche#       - the same as 'eval';  but do not quote variable references
1269*44704f69SBart Van Assche# 'pretty'
1270*44704f69SBart Van Assche#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271*44704f69SBart Van Assche#         be used later in func_quote to get output like: 'echo "a b"' instead
1272*44704f69SBart Van Assche#         of 'echo a\ b'.  This is slower than default on some shells.
1273*44704f69SBart Van Assche# 'unquoted'
1274*44704f69SBart Van Assche#       - produce also $func_quote_arg_unquoted_result which does not contain
1275*44704f69SBart Van Assche#         wrapping double-quotes.
1276*44704f69SBart Van Assche#
1277*44704f69SBart Van Assche# Examples for 'func_quote_arg pretty,unquoted string':
1278*44704f69SBart Van Assche#
1279*44704f69SBart Van Assche#   string      | *_result              | *_unquoted_result
1280*44704f69SBart Van Assche#   ------------+-----------------------+-------------------
1281*44704f69SBart Van Assche#   "           | \"                    | \"
1282*44704f69SBart Van Assche#   a b         | "a b"                 | a b
1283*44704f69SBart Van Assche#   "a b"       | "\"a b\""             | \"a b\"
1284*44704f69SBart Van Assche#   *           | "*"                   | *
1285*44704f69SBart Van Assche#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286*44704f69SBart Van Assche#
1287*44704f69SBart Van Assche# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288*44704f69SBart Van Assche#
1289*44704f69SBart Van Assche#   string        |   *_result          |  *_unquoted_result
1290*44704f69SBart Van Assche#   --------------+---------------------+--------------------
1291*44704f69SBart Van Assche#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292*44704f69SBart Van Asschefunc_quote_arg ()
1293*44704f69SBart Van Assche{
1294*44704f69SBart Van Assche    _G_quote_expand=false
1295*44704f69SBart Van Assche    case ,$1, in
1296*44704f69SBart Van Assche      *,expand,*)
1297*44704f69SBart Van Assche        _G_quote_expand=:
1298*44704f69SBart Van Assche        ;;
1299*44704f69SBart Van Assche    esac
1300*44704f69SBart Van Assche
1301*44704f69SBart Van Assche    case ,$1, in
1302*44704f69SBart Van Assche      *,pretty,*|*,expand,*|*,unquoted,*)
1303*44704f69SBart Van Assche        func_quote_portable $_G_quote_expand "$2"
1304*44704f69SBart Van Assche        func_quote_arg_result=$func_quote_portable_result
1305*44704f69SBart Van Assche        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306*44704f69SBart Van Assche        ;;
1307*44704f69SBart Van Assche      *)
1308*44704f69SBart Van Assche        # Faster quote-for-eval for some shells.
1309*44704f69SBart Van Assche        func_quotefast_eval "$2"
1310*44704f69SBart Van Assche        func_quote_arg_result=$func_quotefast_eval_result
1311*44704f69SBart Van Assche        ;;
1312*44704f69SBart Van Assche    esac
1313*44704f69SBart Van Assche}
1314*44704f69SBart Van Assche
1315*44704f69SBart Van Assche
1316*44704f69SBart Van Assche# func_quote MODEs ARGs...
1317*44704f69SBart Van Assche# ------------------------
1318*44704f69SBart Van Assche# Quote all ARGs to be evaled later and join them into single command.  See
1319*44704f69SBart Van Assche# func_quote_arg's description for more info.
1320*44704f69SBart Van Asschefunc_quote ()
1321*44704f69SBart Van Assche{
1322*44704f69SBart Van Assche    $debug_cmd
1323*44704f69SBart Van Assche    _G_func_quote_mode=$1 ; shift
1324*44704f69SBart Van Assche    func_quote_result=
1325*44704f69SBart Van Assche    while test 0 -lt $#; do
1326*44704f69SBart Van Assche      func_quote_arg "$_G_func_quote_mode" "$1"
1327*44704f69SBart Van Assche      if test -n "$func_quote_result"; then
1328*44704f69SBart Van Assche        func_append func_quote_result " $func_quote_arg_result"
1329*44704f69SBart Van Assche      else
1330*44704f69SBart Van Assche        func_append func_quote_result "$func_quote_arg_result"
1331*44704f69SBart Van Assche      fi
1332*44704f69SBart Van Assche      shift
1333*44704f69SBart Van Assche    done
1334*44704f69SBart Van Assche}
1335*44704f69SBart Van Assche
1336*44704f69SBart Van Assche
1337*44704f69SBart Van Assche# func_stripname PREFIX SUFFIX NAME
1338*44704f69SBart Van Assche# ---------------------------------
1339*44704f69SBart Van Assche# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340*44704f69SBart Van Assche# PREFIX and SUFFIX must not contain globbing or regex special
1341*44704f69SBart Van Assche# characters, hashes, percent signs, but SUFFIX may contain a leading
1342*44704f69SBart Van Assche# dot (in which case that matches only a dot).
1343*44704f69SBart Van Asscheif test yes = "$_G_HAVE_XSI_OPS"; then
1344*44704f69SBart Van Assche  eval 'func_stripname ()
1345*44704f69SBart Van Assche  {
1346*44704f69SBart Van Assche    $debug_cmd
1347*44704f69SBart Van Assche
1348*44704f69SBart Van Assche    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349*44704f69SBart Van Assche    # positional parameters, so assign one to ordinary variable first.
1350*44704f69SBart Van Assche    func_stripname_result=$3
1351*44704f69SBart Van Assche    func_stripname_result=${func_stripname_result#"$1"}
1352*44704f69SBart Van Assche    func_stripname_result=${func_stripname_result%"$2"}
1353*44704f69SBart Van Assche  }'
1354*44704f69SBart Van Asscheelse
1355*44704f69SBart Van Assche  func_stripname ()
1356*44704f69SBart Van Assche  {
1357*44704f69SBart Van Assche    $debug_cmd
1358*44704f69SBart Van Assche
1359*44704f69SBart Van Assche    case $2 in
1360*44704f69SBart Van Assche      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361*44704f69SBart Van Assche      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362*44704f69SBart Van Assche    esac
1363*44704f69SBart Van Assche  }
1364*44704f69SBart Van Asschefi
1365*44704f69SBart Van Assche
1366*44704f69SBart Van Assche
1367*44704f69SBart Van Assche# func_show_eval CMD [FAIL_EXP]
1368*44704f69SBart Van Assche# -----------------------------
1369*44704f69SBart Van Assche# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370*44704f69SBart Van Assche# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371*44704f69SBart Van Assche# is given, then evaluate it.
1372*44704f69SBart Van Asschefunc_show_eval ()
1373*44704f69SBart Van Assche{
1374*44704f69SBart Van Assche    $debug_cmd
1375*44704f69SBart Van Assche
1376*44704f69SBart Van Assche    _G_cmd=$1
1377*44704f69SBart Van Assche    _G_fail_exp=${2-':'}
1378*44704f69SBart Van Assche
1379*44704f69SBart Van Assche    func_quote_arg pretty,expand "$_G_cmd"
1380*44704f69SBart Van Assche    eval "func_notquiet $func_quote_arg_result"
1381*44704f69SBart Van Assche
1382*44704f69SBart Van Assche    $opt_dry_run || {
1383*44704f69SBart Van Assche      eval "$_G_cmd"
1384*44704f69SBart Van Assche      _G_status=$?
1385*44704f69SBart Van Assche      if test 0 -ne "$_G_status"; then
1386*44704f69SBart Van Assche	eval "(exit $_G_status); $_G_fail_exp"
1387*44704f69SBart Van Assche      fi
1388*44704f69SBart Van Assche    }
1389*44704f69SBart Van Assche}
1390*44704f69SBart Van Assche
1391*44704f69SBart Van Assche
1392*44704f69SBart Van Assche# func_show_eval_locale CMD [FAIL_EXP]
1393*44704f69SBart Van Assche# ------------------------------------
1394*44704f69SBart Van Assche# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395*44704f69SBart Van Assche# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396*44704f69SBart Van Assche# is given, then evaluate it.  Use the saved locale for evaluation.
1397*44704f69SBart Van Asschefunc_show_eval_locale ()
1398*44704f69SBart Van Assche{
1399*44704f69SBart Van Assche    $debug_cmd
1400*44704f69SBart Van Assche
1401*44704f69SBart Van Assche    _G_cmd=$1
1402*44704f69SBart Van Assche    _G_fail_exp=${2-':'}
1403*44704f69SBart Van Assche
1404*44704f69SBart Van Assche    $opt_quiet || {
1405*44704f69SBart Van Assche      func_quote_arg expand,pretty "$_G_cmd"
1406*44704f69SBart Van Assche      eval "func_echo $func_quote_arg_result"
1407*44704f69SBart Van Assche    }
1408*44704f69SBart Van Assche
1409*44704f69SBart Van Assche    $opt_dry_run || {
1410*44704f69SBart Van Assche      eval "$_G_user_locale
1411*44704f69SBart Van Assche	    $_G_cmd"
1412*44704f69SBart Van Assche      _G_status=$?
1413*44704f69SBart Van Assche      eval "$_G_safe_locale"
1414*44704f69SBart Van Assche      if test 0 -ne "$_G_status"; then
1415*44704f69SBart Van Assche	eval "(exit $_G_status); $_G_fail_exp"
1416*44704f69SBart Van Assche      fi
1417*44704f69SBart Van Assche    }
1418*44704f69SBart Van Assche}
1419*44704f69SBart Van Assche
1420*44704f69SBart Van Assche
1421*44704f69SBart Van Assche# func_tr_sh
1422*44704f69SBart Van Assche# ----------
1423*44704f69SBart Van Assche# Turn $1 into a string suitable for a shell variable name.
1424*44704f69SBart Van Assche# Result is stored in $func_tr_sh_result.  All characters
1425*44704f69SBart Van Assche# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426*44704f69SBart Van Assche# if $1 begins with a digit, a '_' is prepended as well.
1427*44704f69SBart Van Asschefunc_tr_sh ()
1428*44704f69SBart Van Assche{
1429*44704f69SBart Van Assche    $debug_cmd
1430*44704f69SBart Van Assche
1431*44704f69SBart Van Assche    case $1 in
1432*44704f69SBart Van Assche    [0-9]* | *[!a-zA-Z0-9_]*)
1433*44704f69SBart Van Assche      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434*44704f69SBart Van Assche      ;;
1435*44704f69SBart Van Assche    * )
1436*44704f69SBart Van Assche      func_tr_sh_result=$1
1437*44704f69SBart Van Assche      ;;
1438*44704f69SBart Van Assche    esac
1439*44704f69SBart Van Assche}
1440*44704f69SBart Van Assche
1441*44704f69SBart Van Assche
1442*44704f69SBart Van Assche# func_verbose ARG...
1443*44704f69SBart Van Assche# -------------------
1444*44704f69SBart Van Assche# Echo program name prefixed message in verbose mode only.
1445*44704f69SBart Van Asschefunc_verbose ()
1446*44704f69SBart Van Assche{
1447*44704f69SBart Van Assche    $debug_cmd
1448*44704f69SBart Van Assche
1449*44704f69SBart Van Assche    $opt_verbose && func_echo "$*"
1450*44704f69SBart Van Assche
1451*44704f69SBart Van Assche    :
1452*44704f69SBart Van Assche}
1453*44704f69SBart Van Assche
1454*44704f69SBart Van Assche
1455*44704f69SBart Van Assche# func_warn_and_continue ARG...
1456*44704f69SBart Van Assche# -----------------------------
1457*44704f69SBart Van Assche# Echo program name prefixed warning message to standard error.
1458*44704f69SBart Van Asschefunc_warn_and_continue ()
1459*44704f69SBart Van Assche{
1460*44704f69SBart Van Assche    $debug_cmd
1461*44704f69SBart Van Assche
1462*44704f69SBart Van Assche    $require_term_colors
1463*44704f69SBart Van Assche
1464*44704f69SBart Van Assche    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465*44704f69SBart Van Assche}
1466*44704f69SBart Van Assche
1467*44704f69SBart Van Assche
1468*44704f69SBart Van Assche# func_warning CATEGORY ARG...
1469*44704f69SBart Van Assche# ----------------------------
1470*44704f69SBart Van Assche# Echo program name prefixed warning message to standard error. Warning
1471*44704f69SBart Van Assche# messages can be filtered according to CATEGORY, where this function
1472*44704f69SBart Van Assche# elides messages where CATEGORY is not listed in the global variable
1473*44704f69SBart Van Assche# 'opt_warning_types'.
1474*44704f69SBart Van Asschefunc_warning ()
1475*44704f69SBart Van Assche{
1476*44704f69SBart Van Assche    $debug_cmd
1477*44704f69SBart Van Assche
1478*44704f69SBart Van Assche    # CATEGORY must be in the warning_categories list!
1479*44704f69SBart Van Assche    case " $warning_categories " in
1480*44704f69SBart Van Assche      *" $1 "*) ;;
1481*44704f69SBart Van Assche      *) func_internal_error "invalid warning category '$1'" ;;
1482*44704f69SBart Van Assche    esac
1483*44704f69SBart Van Assche
1484*44704f69SBart Van Assche    _G_category=$1
1485*44704f69SBart Van Assche    shift
1486*44704f69SBart Van Assche
1487*44704f69SBart Van Assche    case " $opt_warning_types " in
1488*44704f69SBart Van Assche      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489*44704f69SBart Van Assche    esac
1490*44704f69SBart Van Assche}
1491*44704f69SBart Van Assche
1492*44704f69SBart Van Assche
1493*44704f69SBart Van Assche# func_sort_ver VER1 VER2
1494*44704f69SBart Van Assche# -----------------------
1495*44704f69SBart Van Assche# 'sort -V' is not generally available.
1496*44704f69SBart Van Assche# Note this deviates from the version comparison in automake
1497*44704f69SBart Van Assche# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498*44704f69SBart Van Assche# but this should suffice as we won't be specifying old
1499*44704f69SBart Van Assche# version formats or redundant trailing .0 in bootstrap.conf.
1500*44704f69SBart Van Assche# If we did want full compatibility then we should probably
1501*44704f69SBart Van Assche# use m4_version_compare from autoconf.
1502*44704f69SBart Van Asschefunc_sort_ver ()
1503*44704f69SBart Van Assche{
1504*44704f69SBart Van Assche    $debug_cmd
1505*44704f69SBart Van Assche
1506*44704f69SBart Van Assche    printf '%s\n%s\n' "$1" "$2" \
1507*44704f69SBart Van Assche      | 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
1508*44704f69SBart Van Assche}
1509*44704f69SBart Van Assche
1510*44704f69SBart Van Assche# func_lt_ver PREV CURR
1511*44704f69SBart Van Assche# ---------------------
1512*44704f69SBart Van Assche# Return true if PREV and CURR are in the correct order according to
1513*44704f69SBart Van Assche# func_sort_ver, otherwise false.  Use it like this:
1514*44704f69SBart Van Assche#
1515*44704f69SBart Van Assche#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516*44704f69SBart Van Asschefunc_lt_ver ()
1517*44704f69SBart Van Assche{
1518*44704f69SBart Van Assche    $debug_cmd
1519*44704f69SBart Van Assche
1520*44704f69SBart Van Assche    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521*44704f69SBart Van Assche}
1522*44704f69SBart Van Assche
1523*44704f69SBart Van Assche
1524*44704f69SBart Van Assche# Local variables:
1525*44704f69SBart Van Assche# mode: shell-script
1526*44704f69SBart Van Assche# sh-indentation: 2
1527*44704f69SBart Van Assche# eval: (add-hook 'before-save-hook 'time-stamp)
1528*44704f69SBart Van Assche# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529*44704f69SBart Van Assche# time-stamp-time-zone: "UTC"
1530*44704f69SBart Van Assche# End:
1531*44704f69SBart Van Assche#! /bin/sh
1532*44704f69SBart Van Assche
1533*44704f69SBart Van Assche# A portable, pluggable option parser for Bourne shell.
1534*44704f69SBart Van Assche# Written by Gary V. Vaughan, 2010
1535*44704f69SBart Van Assche
1536*44704f69SBart Van Assche# This is free software.  There is NO warranty; not even for
1537*44704f69SBart Van Assche# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538*44704f69SBart Van Assche#
1539*44704f69SBart Van Assche# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540*44704f69SBart Van Assche#
1541*44704f69SBart Van Assche# This file is dual licensed under the terms of the MIT license
1542*44704f69SBart Van Assche# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543*44704f69SBart Van Assche# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544*44704f69SBart Van Assche# these licenses when using or redistributing this software or any of
1545*44704f69SBart Van Assche# the files within it.  See the URLs above, or the file `LICENSE`
1546*44704f69SBart Van Assche# included in the Bootstrap distribution for the full license texts.
1547*44704f69SBart Van Assche
1548*44704f69SBart Van Assche# Please report bugs or propose patches to:
1549*44704f69SBart Van Assche# <https://github.com/gnulib-modules/bootstrap/issues>
1550*44704f69SBart Van Assche
1551*44704f69SBart Van Assche# Set a version string for this script.
1552*44704f69SBart Van Asschescriptversion=2019-02-19.15; # UTC
1553*44704f69SBart Van Assche
1554*44704f69SBart Van Assche
1555*44704f69SBart Van Assche## ------ ##
1556*44704f69SBart Van Assche## Usage. ##
1557*44704f69SBart Van Assche## ------ ##
1558*44704f69SBart Van Assche
1559*44704f69SBart Van Assche# This file is a library for parsing options in your shell scripts along
1560*44704f69SBart Van Assche# with assorted other useful supporting features that you can make use
1561*44704f69SBart Van Assche# of too.
1562*44704f69SBart Van Assche#
1563*44704f69SBart Van Assche# For the simplest scripts you might need only:
1564*44704f69SBart Van Assche#
1565*44704f69SBart Van Assche#   #!/bin/sh
1566*44704f69SBart Van Assche#   . relative/path/to/funclib.sh
1567*44704f69SBart Van Assche#   . relative/path/to/options-parser
1568*44704f69SBart Van Assche#   scriptversion=1.0
1569*44704f69SBart Van Assche#   func_options ${1+"$@"}
1570*44704f69SBart Van Assche#   eval set dummy "$func_options_result"; shift
1571*44704f69SBart Van Assche#   ...rest of your script...
1572*44704f69SBart Van Assche#
1573*44704f69SBart Van Assche# In order for the '--version' option to work, you will need to have a
1574*44704f69SBart Van Assche# suitably formatted comment like the one at the top of this file
1575*44704f69SBart Van Assche# starting with '# Written by ' and ending with '# Copyright'.
1576*44704f69SBart Van Assche#
1577*44704f69SBart Van Assche# For '-h' and '--help' to work, you will also need a one line
1578*44704f69SBart Van Assche# description of your script's purpose in a comment directly above the
1579*44704f69SBart Van Assche# '# Written by ' line, like the one at the top of this file.
1580*44704f69SBart Van Assche#
1581*44704f69SBart Van Assche# The default options also support '--debug', which will turn on shell
1582*44704f69SBart Van Assche# execution tracing (see the comment above debug_cmd below for another
1583*44704f69SBart Van Assche# use), and '--verbose' and the func_verbose function to allow your script
1584*44704f69SBart Van Assche# to display verbose messages only when your user has specified
1585*44704f69SBart Van Assche# '--verbose'.
1586*44704f69SBart Van Assche#
1587*44704f69SBart Van Assche# After sourcing this file, you can plug in processing for additional
1588*44704f69SBart Van Assche# options by amending the variables from the 'Configuration' section
1589*44704f69SBart Van Assche# below, and following the instructions in the 'Option parsing'
1590*44704f69SBart Van Assche# section further down.
1591*44704f69SBart Van Assche
1592*44704f69SBart Van Assche## -------------- ##
1593*44704f69SBart Van Assche## Configuration. ##
1594*44704f69SBart Van Assche## -------------- ##
1595*44704f69SBart Van Assche
1596*44704f69SBart Van Assche# You should override these variables in your script after sourcing this
1597*44704f69SBart Van Assche# file so that they reflect the customisations you have added to the
1598*44704f69SBart Van Assche# option parser.
1599*44704f69SBart Van Assche
1600*44704f69SBart Van Assche# The usage line for option parsing errors and the start of '-h' and
1601*44704f69SBart Van Assche# '--help' output messages. You can embed shell variables for delayed
1602*44704f69SBart Van Assche# expansion at the time the message is displayed, but you will need to
1603*44704f69SBart Van Assche# quote other shell meta-characters carefully to prevent them being
1604*44704f69SBart Van Assche# expanded when the contents are evaled.
1605*44704f69SBart Van Asscheusage='$progpath [OPTION]...'
1606*44704f69SBart Van Assche
1607*44704f69SBart Van Assche# Short help message in response to '-h' and '--help'.  Add to this or
1608*44704f69SBart Van Assche# override it after sourcing this library to reflect the full set of
1609*44704f69SBart Van Assche# options your script accepts.
1610*44704f69SBart Van Asscheusage_message="\
1611*44704f69SBart Van Assche       --debug        enable verbose shell tracing
1612*44704f69SBart Van Assche   -W, --warnings=CATEGORY
1613*44704f69SBart Van Assche                      report the warnings falling in CATEGORY [all]
1614*44704f69SBart Van Assche   -v, --verbose      verbosely report processing
1615*44704f69SBart Van Assche       --version      print version information and exit
1616*44704f69SBart Van Assche   -h, --help         print short or long help message and exit
1617*44704f69SBart Van Assche"
1618*44704f69SBart Van Assche
1619*44704f69SBart Van Assche# Additional text appended to 'usage_message' in response to '--help'.
1620*44704f69SBart Van Asschelong_help_message="
1621*44704f69SBart Van AsscheWarning categories include:
1622*44704f69SBart Van Assche       'all'          show all warnings
1623*44704f69SBart Van Assche       'none'         turn off all the warnings
1624*44704f69SBart Van Assche       'error'        warnings are treated as fatal errors"
1625*44704f69SBart Van Assche
1626*44704f69SBart Van Assche# Help message printed before fatal option parsing errors.
1627*44704f69SBart Van Asschefatal_help="Try '\$progname --help' for more information."
1628*44704f69SBart Van Assche
1629*44704f69SBart Van Assche
1630*44704f69SBart Van Assche
1631*44704f69SBart Van Assche## ------------------------- ##
1632*44704f69SBart Van Assche## Hook function management. ##
1633*44704f69SBart Van Assche## ------------------------- ##
1634*44704f69SBart Van Assche
1635*44704f69SBart Van Assche# This section contains functions for adding, removing, and running hooks
1636*44704f69SBart Van Assche# in the main code.  A hook is just a list of function names that can be
1637*44704f69SBart Van Assche# run in order later on.
1638*44704f69SBart Van Assche
1639*44704f69SBart Van Assche# func_hookable FUNC_NAME
1640*44704f69SBart Van Assche# -----------------------
1641*44704f69SBart Van Assche# Declare that FUNC_NAME will run hooks added with
1642*44704f69SBart Van Assche# 'func_add_hook FUNC_NAME ...'.
1643*44704f69SBart Van Asschefunc_hookable ()
1644*44704f69SBart Van Assche{
1645*44704f69SBart Van Assche    $debug_cmd
1646*44704f69SBart Van Assche
1647*44704f69SBart Van Assche    func_append hookable_fns " $1"
1648*44704f69SBart Van Assche}
1649*44704f69SBart Van Assche
1650*44704f69SBart Van Assche
1651*44704f69SBart Van Assche# func_add_hook FUNC_NAME HOOK_FUNC
1652*44704f69SBart Van Assche# ---------------------------------
1653*44704f69SBart Van Assche# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654*44704f69SBart Van Assche# first have been declared "hookable" by a call to 'func_hookable'.
1655*44704f69SBart Van Asschefunc_add_hook ()
1656*44704f69SBart Van Assche{
1657*44704f69SBart Van Assche    $debug_cmd
1658*44704f69SBart Van Assche
1659*44704f69SBart Van Assche    case " $hookable_fns " in
1660*44704f69SBart Van Assche      *" $1 "*) ;;
1661*44704f69SBart Van Assche      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662*44704f69SBart Van Assche    esac
1663*44704f69SBart Van Assche
1664*44704f69SBart Van Assche    eval func_append ${1}_hooks '" $2"'
1665*44704f69SBart Van Assche}
1666*44704f69SBart Van Assche
1667*44704f69SBart Van Assche
1668*44704f69SBart Van Assche# func_remove_hook FUNC_NAME HOOK_FUNC
1669*44704f69SBart Van Assche# ------------------------------------
1670*44704f69SBart Van Assche# Remove HOOK_FUNC from the list of hook functions to be called by
1671*44704f69SBart Van Assche# FUNC_NAME.
1672*44704f69SBart Van Asschefunc_remove_hook ()
1673*44704f69SBart Van Assche{
1674*44704f69SBart Van Assche    $debug_cmd
1675*44704f69SBart Van Assche
1676*44704f69SBart Van Assche    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677*44704f69SBart Van Assche}
1678*44704f69SBart Van Assche
1679*44704f69SBart Van Assche
1680*44704f69SBart Van Assche# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681*44704f69SBart Van Assche# ---------------------------------------------
1682*44704f69SBart Van Assche# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683*44704f69SBart Van Assche# *_result variable of FUNC_NAME_B.
1684*44704f69SBart Van Asschefunc_propagate_result ()
1685*44704f69SBart Van Assche{
1686*44704f69SBart Van Assche    $debug_cmd
1687*44704f69SBart Van Assche
1688*44704f69SBart Van Assche    func_propagate_result_result=:
1689*44704f69SBart Van Assche    if eval "test \"\${${1}_result+set}\" = set"
1690*44704f69SBart Van Assche    then
1691*44704f69SBart Van Assche      eval "${2}_result=\$${1}_result"
1692*44704f69SBart Van Assche    else
1693*44704f69SBart Van Assche      func_propagate_result_result=false
1694*44704f69SBart Van Assche    fi
1695*44704f69SBart Van Assche}
1696*44704f69SBart Van Assche
1697*44704f69SBart Van Assche
1698*44704f69SBart Van Assche# func_run_hooks FUNC_NAME [ARG]...
1699*44704f69SBart Van Assche# ---------------------------------
1700*44704f69SBart Van Assche# Run all hook functions registered to FUNC_NAME.
1701*44704f69SBart Van Assche# It's assumed that the list of hook functions contains nothing more
1702*44704f69SBart Van Assche# than a whitespace-delimited list of legal shell function names, and
1703*44704f69SBart Van Assche# no effort is wasted trying to catch shell meta-characters or preserve
1704*44704f69SBart Van Assche# whitespace.
1705*44704f69SBart Van Asschefunc_run_hooks ()
1706*44704f69SBart Van Assche{
1707*44704f69SBart Van Assche    $debug_cmd
1708*44704f69SBart Van Assche
1709*44704f69SBart Van Assche    _G_rc_run_hooks=false
1710*44704f69SBart Van Assche
1711*44704f69SBart Van Assche    case " $hookable_fns " in
1712*44704f69SBart Van Assche      *" $1 "*) ;;
1713*44704f69SBart Van Assche      *) func_fatal_error "'$1' does not support hook functions." ;;
1714*44704f69SBart Van Assche    esac
1715*44704f69SBart Van Assche
1716*44704f69SBart Van Assche    eval _G_hook_fns=\$$1_hooks; shift
1717*44704f69SBart Van Assche
1718*44704f69SBart Van Assche    for _G_hook in $_G_hook_fns; do
1719*44704f69SBart Van Assche      func_unset "${_G_hook}_result"
1720*44704f69SBart Van Assche      eval $_G_hook '${1+"$@"}'
1721*44704f69SBart Van Assche      func_propagate_result $_G_hook func_run_hooks
1722*44704f69SBart Van Assche      if $func_propagate_result_result; then
1723*44704f69SBart Van Assche        eval set dummy "$func_run_hooks_result"; shift
1724*44704f69SBart Van Assche      fi
1725*44704f69SBart Van Assche    done
1726*44704f69SBart Van Assche}
1727*44704f69SBart Van Assche
1728*44704f69SBart Van Assche
1729*44704f69SBart Van Assche
1730*44704f69SBart Van Assche## --------------- ##
1731*44704f69SBart Van Assche## Option parsing. ##
1732*44704f69SBart Van Assche## --------------- ##
1733*44704f69SBart Van Assche
1734*44704f69SBart Van Assche# In order to add your own option parsing hooks, you must accept the
1735*44704f69SBart Van Assche# full positional parameter list from your hook function.  You may remove
1736*44704f69SBart Van Assche# or edit any options that you action, and then pass back the remaining
1737*44704f69SBart Van Assche# unprocessed options in '<hooked_function_name>_result', escaped
1738*44704f69SBart Van Assche# suitably for 'eval'.
1739*44704f69SBart Van Assche#
1740*44704f69SBart Van Assche# The '<hooked_function_name>_result' variable is automatically unset
1741*44704f69SBart Van Assche# before your hook gets called; for best performance, only set the
1742*44704f69SBart Van Assche# *_result variable when necessary (i.e. don't call the 'func_quote'
1743*44704f69SBart Van Assche# function unnecessarily because it can be an expensive operation on some
1744*44704f69SBart Van Assche# machines).
1745*44704f69SBart Van Assche#
1746*44704f69SBart Van Assche# Like this:
1747*44704f69SBart Van Assche#
1748*44704f69SBart Van Assche#    my_options_prep ()
1749*44704f69SBart Van Assche#    {
1750*44704f69SBart Van Assche#        $debug_cmd
1751*44704f69SBart Van Assche#
1752*44704f69SBart Van Assche#        # Extend the existing usage message.
1753*44704f69SBart Van Assche#        usage_message=$usage_message'
1754*44704f69SBart Van Assche#      -s, --silent       don'\''t print informational messages
1755*44704f69SBart Van Assche#    '
1756*44704f69SBart Van Assche#        # No change in '$@' (ignored completely by this hook).  Leave
1757*44704f69SBart Van Assche#        # my_options_prep_result variable intact.
1758*44704f69SBart Van Assche#    }
1759*44704f69SBart Van Assche#    func_add_hook func_options_prep my_options_prep
1760*44704f69SBart Van Assche#
1761*44704f69SBart Van Assche#
1762*44704f69SBart Van Assche#    my_silent_option ()
1763*44704f69SBart Van Assche#    {
1764*44704f69SBart Van Assche#        $debug_cmd
1765*44704f69SBart Van Assche#
1766*44704f69SBart Van Assche#        args_changed=false
1767*44704f69SBart Van Assche#
1768*44704f69SBart Van Assche#        # Note that, for efficiency, we parse as many options as we can
1769*44704f69SBart Van Assche#        # recognise in a loop before passing the remainder back to the
1770*44704f69SBart Van Assche#        # caller on the first unrecognised argument we encounter.
1771*44704f69SBart Van Assche#        while test $# -gt 0; do
1772*44704f69SBart Van Assche#          opt=$1; shift
1773*44704f69SBart Van Assche#          case $opt in
1774*44704f69SBart Van Assche#            --silent|-s) opt_silent=:
1775*44704f69SBart Van Assche#                         args_changed=:
1776*44704f69SBart Van Assche#                         ;;
1777*44704f69SBart Van Assche#            # Separate non-argument short options:
1778*44704f69SBart Van Assche#            -s*)         func_split_short_opt "$_G_opt"
1779*44704f69SBart Van Assche#                         set dummy "$func_split_short_opt_name" \
1780*44704f69SBart Van Assche#                             "-$func_split_short_opt_arg" ${1+"$@"}
1781*44704f69SBart Van Assche#                         shift
1782*44704f69SBart Van Assche#                         args_changed=:
1783*44704f69SBart Van Assche#                         ;;
1784*44704f69SBart Van Assche#            *)           # Make sure the first unrecognised option "$_G_opt"
1785*44704f69SBart Van Assche#                         # is added back to "$@" in case we need it later,
1786*44704f69SBart Van Assche#                         # if $args_changed was set to 'true'.
1787*44704f69SBart Van Assche#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1788*44704f69SBart Van Assche#          esac
1789*44704f69SBart Van Assche#        done
1790*44704f69SBart Van Assche#
1791*44704f69SBart Van Assche#        # Only call 'func_quote' here if we processed at least one argument.
1792*44704f69SBart Van Assche#        if $args_changed; then
1793*44704f69SBart Van Assche#          func_quote eval ${1+"$@"}
1794*44704f69SBart Van Assche#          my_silent_option_result=$func_quote_result
1795*44704f69SBart Van Assche#        fi
1796*44704f69SBart Van Assche#    }
1797*44704f69SBart Van Assche#    func_add_hook func_parse_options my_silent_option
1798*44704f69SBart Van Assche#
1799*44704f69SBart Van Assche#
1800*44704f69SBart Van Assche#    my_option_validation ()
1801*44704f69SBart Van Assche#    {
1802*44704f69SBart Van Assche#        $debug_cmd
1803*44704f69SBart Van Assche#
1804*44704f69SBart Van Assche#        $opt_silent && $opt_verbose && func_fatal_help "\
1805*44704f69SBart Van Assche#    '--silent' and '--verbose' options are mutually exclusive."
1806*44704f69SBart Van Assche#    }
1807*44704f69SBart Van Assche#    func_add_hook func_validate_options my_option_validation
1808*44704f69SBart Van Assche#
1809*44704f69SBart Van Assche# You'll also need to manually amend $usage_message to reflect the extra
1810*44704f69SBart Van Assche# options you parse.  It's preferable to append if you can, so that
1811*44704f69SBart Van Assche# multiple option parsing hooks can be added safely.
1812*44704f69SBart Van Assche
1813*44704f69SBart Van Assche
1814*44704f69SBart Van Assche# func_options_finish [ARG]...
1815*44704f69SBart Van Assche# ----------------------------
1816*44704f69SBart Van Assche# Finishing the option parse loop (call 'func_options' hooks ATM).
1817*44704f69SBart Van Asschefunc_options_finish ()
1818*44704f69SBart Van Assche{
1819*44704f69SBart Van Assche    $debug_cmd
1820*44704f69SBart Van Assche
1821*44704f69SBart Van Assche    func_run_hooks func_options ${1+"$@"}
1822*44704f69SBart Van Assche    func_propagate_result func_run_hooks func_options_finish
1823*44704f69SBart Van Assche}
1824*44704f69SBart Van Assche
1825*44704f69SBart Van Assche
1826*44704f69SBart Van Assche# func_options [ARG]...
1827*44704f69SBart Van Assche# ---------------------
1828*44704f69SBart Van Assche# All the functions called inside func_options are hookable. See the
1829*44704f69SBart Van Assche# individual implementations for details.
1830*44704f69SBart Van Asschefunc_hookable func_options
1831*44704f69SBart Van Asschefunc_options ()
1832*44704f69SBart Van Assche{
1833*44704f69SBart Van Assche    $debug_cmd
1834*44704f69SBart Van Assche
1835*44704f69SBart Van Assche    _G_options_quoted=false
1836*44704f69SBart Van Assche
1837*44704f69SBart Van Assche    for my_func in options_prep parse_options validate_options options_finish
1838*44704f69SBart Van Assche    do
1839*44704f69SBart Van Assche      func_unset func_${my_func}_result
1840*44704f69SBart Van Assche      func_unset func_run_hooks_result
1841*44704f69SBart Van Assche      eval func_$my_func '${1+"$@"}'
1842*44704f69SBart Van Assche      func_propagate_result func_$my_func func_options
1843*44704f69SBart Van Assche      if $func_propagate_result_result; then
1844*44704f69SBart Van Assche        eval set dummy "$func_options_result"; shift
1845*44704f69SBart Van Assche        _G_options_quoted=:
1846*44704f69SBart Van Assche      fi
1847*44704f69SBart Van Assche    done
1848*44704f69SBart Van Assche
1849*44704f69SBart Van Assche    $_G_options_quoted || {
1850*44704f69SBart Van Assche      # As we (func_options) are top-level options-parser function and
1851*44704f69SBart Van Assche      # nobody quoted "$@" for us yet, we need to do it explicitly for
1852*44704f69SBart Van Assche      # caller.
1853*44704f69SBart Van Assche      func_quote eval ${1+"$@"}
1854*44704f69SBart Van Assche      func_options_result=$func_quote_result
1855*44704f69SBart Van Assche    }
1856*44704f69SBart Van Assche}
1857*44704f69SBart Van Assche
1858*44704f69SBart Van Assche
1859*44704f69SBart Van Assche# func_options_prep [ARG]...
1860*44704f69SBart Van Assche# --------------------------
1861*44704f69SBart Van Assche# All initialisations required before starting the option parse loop.
1862*44704f69SBart Van Assche# Note that when calling hook functions, we pass through the list of
1863*44704f69SBart Van Assche# positional parameters.  If a hook function modifies that list, and
1864*44704f69SBart Van Assche# needs to propagate that back to rest of this script, then the complete
1865*44704f69SBart Van Assche# modified list must be put in 'func_run_hooks_result' before returning.
1866*44704f69SBart Van Asschefunc_hookable func_options_prep
1867*44704f69SBart Van Asschefunc_options_prep ()
1868*44704f69SBart Van Assche{
1869*44704f69SBart Van Assche    $debug_cmd
1870*44704f69SBart Van Assche
1871*44704f69SBart Van Assche    # Option defaults:
1872*44704f69SBart Van Assche    opt_verbose=false
1873*44704f69SBart Van Assche    opt_warning_types=
1874*44704f69SBart Van Assche
1875*44704f69SBart Van Assche    func_run_hooks func_options_prep ${1+"$@"}
1876*44704f69SBart Van Assche    func_propagate_result func_run_hooks func_options_prep
1877*44704f69SBart Van Assche}
1878*44704f69SBart Van Assche
1879*44704f69SBart Van Assche
1880*44704f69SBart Van Assche# func_parse_options [ARG]...
1881*44704f69SBart Van Assche# ---------------------------
1882*44704f69SBart Van Assche# The main option parsing loop.
1883*44704f69SBart Van Asschefunc_hookable func_parse_options
1884*44704f69SBart Van Asschefunc_parse_options ()
1885*44704f69SBart Van Assche{
1886*44704f69SBart Van Assche    $debug_cmd
1887*44704f69SBart Van Assche
1888*44704f69SBart Van Assche    _G_parse_options_requote=false
1889*44704f69SBart Van Assche    # this just eases exit handling
1890*44704f69SBart Van Assche    while test $# -gt 0; do
1891*44704f69SBart Van Assche      # Defer to hook functions for initial option parsing, so they
1892*44704f69SBart Van Assche      # get priority in the event of reusing an option name.
1893*44704f69SBart Van Assche      func_run_hooks func_parse_options ${1+"$@"}
1894*44704f69SBart Van Assche      func_propagate_result func_run_hooks func_parse_options
1895*44704f69SBart Van Assche      if $func_propagate_result_result; then
1896*44704f69SBart Van Assche        eval set dummy "$func_parse_options_result"; shift
1897*44704f69SBart Van Assche        # Even though we may have changed "$@", we passed the "$@" array
1898*44704f69SBart Van Assche        # down into the hook and it quoted it for us (because we are in
1899*44704f69SBart Van Assche        # this if-branch).  No need to quote it again.
1900*44704f69SBart Van Assche        _G_parse_options_requote=false
1901*44704f69SBart Van Assche      fi
1902*44704f69SBart Van Assche
1903*44704f69SBart Van Assche      # Break out of the loop if we already parsed every option.
1904*44704f69SBart Van Assche      test $# -gt 0 || break
1905*44704f69SBart Van Assche
1906*44704f69SBart Van Assche      # We expect that one of the options parsed in this function matches
1907*44704f69SBart Van Assche      # and thus we remove _G_opt from "$@" and need to re-quote.
1908*44704f69SBart Van Assche      _G_match_parse_options=:
1909*44704f69SBart Van Assche      _G_opt=$1
1910*44704f69SBart Van Assche      shift
1911*44704f69SBart Van Assche      case $_G_opt in
1912*44704f69SBart Van Assche        --debug|-x)   debug_cmd='set -x'
1913*44704f69SBart Van Assche                      func_echo "enabling shell trace mode" >&2
1914*44704f69SBart Van Assche                      $debug_cmd
1915*44704f69SBart Van Assche                      ;;
1916*44704f69SBart Van Assche
1917*44704f69SBart Van Assche        --no-warnings|--no-warning|--no-warn)
1918*44704f69SBart Van Assche                      set dummy --warnings none ${1+"$@"}
1919*44704f69SBart Van Assche                      shift
1920*44704f69SBart Van Assche		      ;;
1921*44704f69SBart Van Assche
1922*44704f69SBart Van Assche        --warnings|--warning|-W)
1923*44704f69SBart Van Assche                      if test $# = 0 && func_missing_arg $_G_opt; then
1924*44704f69SBart Van Assche                        _G_parse_options_requote=:
1925*44704f69SBart Van Assche                        break
1926*44704f69SBart Van Assche                      fi
1927*44704f69SBart Van Assche                      case " $warning_categories $1" in
1928*44704f69SBart Van Assche                        *" $1 "*)
1929*44704f69SBart Van Assche                          # trailing space prevents matching last $1 above
1930*44704f69SBart Van Assche                          func_append_uniq opt_warning_types " $1"
1931*44704f69SBart Van Assche                          ;;
1932*44704f69SBart Van Assche                        *all)
1933*44704f69SBart Van Assche                          opt_warning_types=$warning_categories
1934*44704f69SBart Van Assche                          ;;
1935*44704f69SBart Van Assche                        *none)
1936*44704f69SBart Van Assche                          opt_warning_types=none
1937*44704f69SBart Van Assche                          warning_func=:
1938*44704f69SBart Van Assche                          ;;
1939*44704f69SBart Van Assche                        *error)
1940*44704f69SBart Van Assche                          opt_warning_types=$warning_categories
1941*44704f69SBart Van Assche                          warning_func=func_fatal_error
1942*44704f69SBart Van Assche                          ;;
1943*44704f69SBart Van Assche                        *)
1944*44704f69SBart Van Assche                          func_fatal_error \
1945*44704f69SBart Van Assche                             "unsupported warning category: '$1'"
1946*44704f69SBart Van Assche                          ;;
1947*44704f69SBart Van Assche                      esac
1948*44704f69SBart Van Assche                      shift
1949*44704f69SBart Van Assche                      ;;
1950*44704f69SBart Van Assche
1951*44704f69SBart Van Assche        --verbose|-v) opt_verbose=: ;;
1952*44704f69SBart Van Assche        --version)    func_version ;;
1953*44704f69SBart Van Assche        -\?|-h)       func_usage ;;
1954*44704f69SBart Van Assche        --help)       func_help ;;
1955*44704f69SBart Van Assche
1956*44704f69SBart Van Assche	# Separate optargs to long options (plugins may need this):
1957*44704f69SBart Van Assche	--*=*)        func_split_equals "$_G_opt"
1958*44704f69SBart Van Assche	              set dummy "$func_split_equals_lhs" \
1959*44704f69SBart Van Assche                          "$func_split_equals_rhs" ${1+"$@"}
1960*44704f69SBart Van Assche                      shift
1961*44704f69SBart Van Assche                      ;;
1962*44704f69SBart Van Assche
1963*44704f69SBart Van Assche       # Separate optargs to short options:
1964*44704f69SBart Van Assche        -W*)
1965*44704f69SBart Van Assche                      func_split_short_opt "$_G_opt"
1966*44704f69SBart Van Assche                      set dummy "$func_split_short_opt_name" \
1967*44704f69SBart Van Assche                          "$func_split_short_opt_arg" ${1+"$@"}
1968*44704f69SBart Van Assche                      shift
1969*44704f69SBart Van Assche                      ;;
1970*44704f69SBart Van Assche
1971*44704f69SBart Van Assche        # Separate non-argument short options:
1972*44704f69SBart Van Assche        -\?*|-h*|-v*|-x*)
1973*44704f69SBart Van Assche                      func_split_short_opt "$_G_opt"
1974*44704f69SBart Van Assche                      set dummy "$func_split_short_opt_name" \
1975*44704f69SBart Van Assche                          "-$func_split_short_opt_arg" ${1+"$@"}
1976*44704f69SBart Van Assche                      shift
1977*44704f69SBart Van Assche                      ;;
1978*44704f69SBart Van Assche
1979*44704f69SBart Van Assche        --)           _G_parse_options_requote=: ; break ;;
1980*44704f69SBart Van Assche        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1981*44704f69SBart Van Assche        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1982*44704f69SBart Van Assche                      _G_match_parse_options=false
1983*44704f69SBart Van Assche                      break
1984*44704f69SBart Van Assche                      ;;
1985*44704f69SBart Van Assche      esac
1986*44704f69SBart Van Assche
1987*44704f69SBart Van Assche      if $_G_match_parse_options; then
1988*44704f69SBart Van Assche        _G_parse_options_requote=:
1989*44704f69SBart Van Assche      fi
1990*44704f69SBart Van Assche    done
1991*44704f69SBart Van Assche
1992*44704f69SBart Van Assche    if $_G_parse_options_requote; then
1993*44704f69SBart Van Assche      # save modified positional parameters for caller
1994*44704f69SBart Van Assche      func_quote eval ${1+"$@"}
1995*44704f69SBart Van Assche      func_parse_options_result=$func_quote_result
1996*44704f69SBart Van Assche    fi
1997*44704f69SBart Van Assche}
1998*44704f69SBart Van Assche
1999*44704f69SBart Van Assche
2000*44704f69SBart Van Assche# func_validate_options [ARG]...
2001*44704f69SBart Van Assche# ------------------------------
2002*44704f69SBart Van Assche# Perform any sanity checks on option settings and/or unconsumed
2003*44704f69SBart Van Assche# arguments.
2004*44704f69SBart Van Asschefunc_hookable func_validate_options
2005*44704f69SBart Van Asschefunc_validate_options ()
2006*44704f69SBart Van Assche{
2007*44704f69SBart Van Assche    $debug_cmd
2008*44704f69SBart Van Assche
2009*44704f69SBart Van Assche    # Display all warnings if -W was not given.
2010*44704f69SBart Van Assche    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2011*44704f69SBart Van Assche
2012*44704f69SBart Van Assche    func_run_hooks func_validate_options ${1+"$@"}
2013*44704f69SBart Van Assche    func_propagate_result func_run_hooks func_validate_options
2014*44704f69SBart Van Assche
2015*44704f69SBart Van Assche    # Bail if the options were screwed!
2016*44704f69SBart Van Assche    $exit_cmd $EXIT_FAILURE
2017*44704f69SBart Van Assche}
2018*44704f69SBart Van Assche
2019*44704f69SBart Van Assche
2020*44704f69SBart Van Assche
2021*44704f69SBart Van Assche## ----------------- ##
2022*44704f69SBart Van Assche## Helper functions. ##
2023*44704f69SBart Van Assche## ----------------- ##
2024*44704f69SBart Van Assche
2025*44704f69SBart Van Assche# This section contains the helper functions used by the rest of the
2026*44704f69SBart Van Assche# hookable option parser framework in ascii-betical order.
2027*44704f69SBart Van Assche
2028*44704f69SBart Van Assche
2029*44704f69SBart Van Assche# func_fatal_help ARG...
2030*44704f69SBart Van Assche# ----------------------
2031*44704f69SBart Van Assche# Echo program name prefixed message to standard error, followed by
2032*44704f69SBart Van Assche# a help hint, and exit.
2033*44704f69SBart Van Asschefunc_fatal_help ()
2034*44704f69SBart Van Assche{
2035*44704f69SBart Van Assche    $debug_cmd
2036*44704f69SBart Van Assche
2037*44704f69SBart Van Assche    eval \$ECHO \""Usage: $usage"\"
2038*44704f69SBart Van Assche    eval \$ECHO \""$fatal_help"\"
2039*44704f69SBart Van Assche    func_error ${1+"$@"}
2040*44704f69SBart Van Assche    exit $EXIT_FAILURE
2041*44704f69SBart Van Assche}
2042*44704f69SBart Van Assche
2043*44704f69SBart Van Assche
2044*44704f69SBart Van Assche# func_help
2045*44704f69SBart Van Assche# ---------
2046*44704f69SBart Van Assche# Echo long help message to standard output and exit.
2047*44704f69SBart Van Asschefunc_help ()
2048*44704f69SBart Van Assche{
2049*44704f69SBart Van Assche    $debug_cmd
2050*44704f69SBart Van Assche
2051*44704f69SBart Van Assche    func_usage_message
2052*44704f69SBart Van Assche    $ECHO "$long_help_message"
2053*44704f69SBart Van Assche    exit 0
2054*44704f69SBart Van Assche}
2055*44704f69SBart Van Assche
2056*44704f69SBart Van Assche
2057*44704f69SBart Van Assche# func_missing_arg ARGNAME
2058*44704f69SBart Van Assche# ------------------------
2059*44704f69SBart Van Assche# Echo program name prefixed message to standard error and set global
2060*44704f69SBart Van Assche# exit_cmd.
2061*44704f69SBart Van Asschefunc_missing_arg ()
2062*44704f69SBart Van Assche{
2063*44704f69SBart Van Assche    $debug_cmd
2064*44704f69SBart Van Assche
2065*44704f69SBart Van Assche    func_error "Missing argument for '$1'."
2066*44704f69SBart Van Assche    exit_cmd=exit
2067*44704f69SBart Van Assche}
2068*44704f69SBart Van Assche
2069*44704f69SBart Van Assche
2070*44704f69SBart Van Assche# func_split_equals STRING
2071*44704f69SBart Van Assche# ------------------------
2072*44704f69SBart Van Assche# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2073*44704f69SBart Van Assche# after splitting STRING at the '=' sign.
2074*44704f69SBart Van Asschetest -z "$_G_HAVE_XSI_OPS" \
2075*44704f69SBart Van Assche    && (eval 'x=a/b/c;
2076*44704f69SBart Van Assche      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2077*44704f69SBart Van Assche    && _G_HAVE_XSI_OPS=yes
2078*44704f69SBart Van Assche
2079*44704f69SBart Van Asscheif test yes = "$_G_HAVE_XSI_OPS"
2080*44704f69SBart Van Asschethen
2081*44704f69SBart Van Assche  # This is an XSI compatible shell, allowing a faster implementation...
2082*44704f69SBart Van Assche  eval 'func_split_equals ()
2083*44704f69SBart Van Assche  {
2084*44704f69SBart Van Assche      $debug_cmd
2085*44704f69SBart Van Assche
2086*44704f69SBart Van Assche      func_split_equals_lhs=${1%%=*}
2087*44704f69SBart Van Assche      func_split_equals_rhs=${1#*=}
2088*44704f69SBart Van Assche      if test "x$func_split_equals_lhs" = "x$1"; then
2089*44704f69SBart Van Assche        func_split_equals_rhs=
2090*44704f69SBart Van Assche      fi
2091*44704f69SBart Van Assche  }'
2092*44704f69SBart Van Asscheelse
2093*44704f69SBart Van Assche  # ...otherwise fall back to using expr, which is often a shell builtin.
2094*44704f69SBart Van Assche  func_split_equals ()
2095*44704f69SBart Van Assche  {
2096*44704f69SBart Van Assche      $debug_cmd
2097*44704f69SBart Van Assche
2098*44704f69SBart Van Assche      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2099*44704f69SBart Van Assche      func_split_equals_rhs=
2100*44704f69SBart Van Assche      test "x$func_split_equals_lhs=" = "x$1" \
2101*44704f69SBart Van Assche        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2102*44704f69SBart Van Assche  }
2103*44704f69SBart Van Asschefi #func_split_equals
2104*44704f69SBart Van Assche
2105*44704f69SBart Van Assche
2106*44704f69SBart Van Assche# func_split_short_opt SHORTOPT
2107*44704f69SBart Van Assche# -----------------------------
2108*44704f69SBart Van Assche# Set func_split_short_opt_name and func_split_short_opt_arg shell
2109*44704f69SBart Van Assche# variables after splitting SHORTOPT after the 2nd character.
2110*44704f69SBart Van Asscheif test yes = "$_G_HAVE_XSI_OPS"
2111*44704f69SBart Van Asschethen
2112*44704f69SBart Van Assche  # This is an XSI compatible shell, allowing a faster implementation...
2113*44704f69SBart Van Assche  eval 'func_split_short_opt ()
2114*44704f69SBart Van Assche  {
2115*44704f69SBart Van Assche      $debug_cmd
2116*44704f69SBart Van Assche
2117*44704f69SBart Van Assche      func_split_short_opt_arg=${1#??}
2118*44704f69SBart Van Assche      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2119*44704f69SBart Van Assche  }'
2120*44704f69SBart Van Asscheelse
2121*44704f69SBart Van Assche  # ...otherwise fall back to using expr, which is often a shell builtin.
2122*44704f69SBart Van Assche  func_split_short_opt ()
2123*44704f69SBart Van Assche  {
2124*44704f69SBart Van Assche      $debug_cmd
2125*44704f69SBart Van Assche
2126*44704f69SBart Van Assche      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2127*44704f69SBart Van Assche      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2128*44704f69SBart Van Assche  }
2129*44704f69SBart Van Asschefi #func_split_short_opt
2130*44704f69SBart Van Assche
2131*44704f69SBart Van Assche
2132*44704f69SBart Van Assche# func_usage
2133*44704f69SBart Van Assche# ----------
2134*44704f69SBart Van Assche# Echo short help message to standard output and exit.
2135*44704f69SBart Van Asschefunc_usage ()
2136*44704f69SBart Van Assche{
2137*44704f69SBart Van Assche    $debug_cmd
2138*44704f69SBart Van Assche
2139*44704f69SBart Van Assche    func_usage_message
2140*44704f69SBart Van Assche    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2141*44704f69SBart Van Assche    exit 0
2142*44704f69SBart Van Assche}
2143*44704f69SBart Van Assche
2144*44704f69SBart Van Assche
2145*44704f69SBart Van Assche# func_usage_message
2146*44704f69SBart Van Assche# ------------------
2147*44704f69SBart Van Assche# Echo short help message to standard output.
2148*44704f69SBart Van Asschefunc_usage_message ()
2149*44704f69SBart Van Assche{
2150*44704f69SBart Van Assche    $debug_cmd
2151*44704f69SBart Van Assche
2152*44704f69SBart Van Assche    eval \$ECHO \""Usage: $usage"\"
2153*44704f69SBart Van Assche    echo
2154*44704f69SBart Van Assche    $SED -n 's|^# ||
2155*44704f69SBart Van Assche        /^Written by/{
2156*44704f69SBart Van Assche          x;p;x
2157*44704f69SBart Van Assche        }
2158*44704f69SBart Van Assche	h
2159*44704f69SBart Van Assche	/^Written by/q' < "$progpath"
2160*44704f69SBart Van Assche    echo
2161*44704f69SBart Van Assche    eval \$ECHO \""$usage_message"\"
2162*44704f69SBart Van Assche}
2163*44704f69SBart Van Assche
2164*44704f69SBart Van Assche
2165*44704f69SBart Van Assche# func_version
2166*44704f69SBart Van Assche# ------------
2167*44704f69SBart Van Assche# Echo version message to standard output and exit.
2168*44704f69SBart Van Assche# The version message is extracted from the calling file's header
2169*44704f69SBart Van Assche# comments, with leading '# ' stripped:
2170*44704f69SBart Van Assche#   1. First display the progname and version
2171*44704f69SBart Van Assche#   2. Followed by the header comment line matching  /^# Written by /
2172*44704f69SBart Van Assche#   3. Then a blank line followed by the first following line matching
2173*44704f69SBart Van Assche#      /^# Copyright /
2174*44704f69SBart Van Assche#   4. Immediately followed by any lines between the previous matches,
2175*44704f69SBart Van Assche#      except lines preceding the intervening completely blank line.
2176*44704f69SBart Van Assche# For example, see the header comments of this file.
2177*44704f69SBart Van Asschefunc_version ()
2178*44704f69SBart Van Assche{
2179*44704f69SBart Van Assche    $debug_cmd
2180*44704f69SBart Van Assche
2181*44704f69SBart Van Assche    printf '%s\n' "$progname $scriptversion"
2182*44704f69SBart Van Assche    $SED -n '
2183*44704f69SBart Van Assche        /^# Written by /!b
2184*44704f69SBart Van Assche        s|^# ||; p; n
2185*44704f69SBart Van Assche
2186*44704f69SBart Van Assche        :fwd2blnk
2187*44704f69SBart Van Assche        /./ {
2188*44704f69SBart Van Assche          n
2189*44704f69SBart Van Assche          b fwd2blnk
2190*44704f69SBart Van Assche        }
2191*44704f69SBart Van Assche        p; n
2192*44704f69SBart Van Assche
2193*44704f69SBart Van Assche        :holdwrnt
2194*44704f69SBart Van Assche        s|^# ||
2195*44704f69SBart Van Assche        s|^# *$||
2196*44704f69SBart Van Assche        /^Copyright /!{
2197*44704f69SBart Van Assche          /./H
2198*44704f69SBart Van Assche          n
2199*44704f69SBart Van Assche          b holdwrnt
2200*44704f69SBart Van Assche        }
2201*44704f69SBart Van Assche
2202*44704f69SBart Van Assche        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2203*44704f69SBart Van Assche        G
2204*44704f69SBart Van Assche        s|\(\n\)\n*|\1|g
2205*44704f69SBart Van Assche        p; q' < "$progpath"
2206*44704f69SBart Van Assche
2207*44704f69SBart Van Assche    exit $?
2208*44704f69SBart Van Assche}
2209*44704f69SBart Van Assche
2210*44704f69SBart Van Assche
2211*44704f69SBart Van Assche# Local variables:
2212*44704f69SBart Van Assche# mode: shell-script
2213*44704f69SBart Van Assche# sh-indentation: 2
2214*44704f69SBart Van Assche# eval: (add-hook 'before-save-hook 'time-stamp)
2215*44704f69SBart Van Assche# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2216*44704f69SBart Van Assche# time-stamp-time-zone: "UTC"
2217*44704f69SBart Van Assche# End:
2218*44704f69SBart Van Assche
2219*44704f69SBart Van Assche# Set a version string.
2220*44704f69SBart Van Asschescriptversion='(GNU libtool) 2.4.7'
2221*44704f69SBart Van Assche
2222*44704f69SBart Van Assche
2223*44704f69SBart Van Assche# func_echo ARG...
2224*44704f69SBart Van Assche# ----------------
2225*44704f69SBart Van Assche# Libtool also displays the current mode in messages, so override
2226*44704f69SBart Van Assche# funclib.sh func_echo with this custom definition.
2227*44704f69SBart Van Asschefunc_echo ()
2228*44704f69SBart Van Assche{
2229*44704f69SBart Van Assche    $debug_cmd
2230*44704f69SBart Van Assche
2231*44704f69SBart Van Assche    _G_message=$*
2232*44704f69SBart Van Assche
2233*44704f69SBart Van Assche    func_echo_IFS=$IFS
2234*44704f69SBart Van Assche    IFS=$nl
2235*44704f69SBart Van Assche    for _G_line in $_G_message; do
2236*44704f69SBart Van Assche      IFS=$func_echo_IFS
2237*44704f69SBart Van Assche      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2238*44704f69SBart Van Assche    done
2239*44704f69SBart Van Assche    IFS=$func_echo_IFS
2240*44704f69SBart Van Assche}
2241*44704f69SBart Van Assche
2242*44704f69SBart Van Assche
2243*44704f69SBart Van Assche# func_warning ARG...
2244*44704f69SBart Van Assche# -------------------
2245*44704f69SBart Van Assche# Libtool warnings are not categorized, so override funclib.sh
2246*44704f69SBart Van Assche# func_warning with this simpler definition.
2247*44704f69SBart Van Asschefunc_warning ()
2248*44704f69SBart Van Assche{
2249*44704f69SBart Van Assche    $debug_cmd
2250*44704f69SBart Van Assche
2251*44704f69SBart Van Assche    $warning_func ${1+"$@"}
2252*44704f69SBart Van Assche}
2253*44704f69SBart Van Assche
2254*44704f69SBart Van Assche
2255*44704f69SBart Van Assche## ---------------- ##
2256*44704f69SBart Van Assche## Options parsing. ##
2257*44704f69SBart Van Assche## ---------------- ##
2258*44704f69SBart Van Assche
2259*44704f69SBart Van Assche# Hook in the functions to make sure our own options are parsed during
2260*44704f69SBart Van Assche# the option parsing loop.
2261*44704f69SBart Van Assche
2262*44704f69SBart Van Asscheusage='$progpath [OPTION]... [MODE-ARG]...'
2263*44704f69SBart Van Assche
2264*44704f69SBart Van Assche# Short help message in response to '-h'.
2265*44704f69SBart Van Asscheusage_message="Options:
2266*44704f69SBart Van Assche       --config             show all configuration variables
2267*44704f69SBart Van Assche       --debug              enable verbose shell tracing
2268*44704f69SBart Van Assche   -n, --dry-run            display commands without modifying any files
2269*44704f69SBart Van Assche       --features           display basic configuration information and exit
2270*44704f69SBart Van Assche       --mode=MODE          use operation mode MODE
2271*44704f69SBart Van Assche       --no-warnings        equivalent to '-Wnone'
2272*44704f69SBart Van Assche       --preserve-dup-deps  don't remove duplicate dependency libraries
2273*44704f69SBart Van Assche       --quiet, --silent    don't print informational messages
2274*44704f69SBart Van Assche       --tag=TAG            use configuration variables from tag TAG
2275*44704f69SBart Van Assche   -v, --verbose            print more informational messages than default
2276*44704f69SBart Van Assche       --version            print version information
2277*44704f69SBart Van Assche   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2278*44704f69SBart Van Assche   -h, --help, --help-all   print short, long, or detailed help message
2279*44704f69SBart Van Assche"
2280*44704f69SBart Van Assche
2281*44704f69SBart Van Assche# Additional text appended to 'usage_message' in response to '--help'.
2282*44704f69SBart Van Asschefunc_help ()
2283*44704f69SBart Van Assche{
2284*44704f69SBart Van Assche    $debug_cmd
2285*44704f69SBart Van Assche
2286*44704f69SBart Van Assche    func_usage_message
2287*44704f69SBart Van Assche    $ECHO "$long_help_message
2288*44704f69SBart Van Assche
2289*44704f69SBart Van AsscheMODE must be one of the following:
2290*44704f69SBart Van Assche
2291*44704f69SBart Van Assche       clean           remove files from the build directory
2292*44704f69SBart Van Assche       compile         compile a source file into a libtool object
2293*44704f69SBart Van Assche       execute         automatically set library path, then run a program
2294*44704f69SBart Van Assche       finish          complete the installation of libtool libraries
2295*44704f69SBart Van Assche       install         install libraries or executables
2296*44704f69SBart Van Assche       link            create a library or an executable
2297*44704f69SBart Van Assche       uninstall       remove libraries from an installed directory
2298*44704f69SBart Van Assche
2299*44704f69SBart Van AsscheMODE-ARGS vary depending on the MODE.  When passed as first option,
2300*44704f69SBart Van Assche'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2301*44704f69SBart Van AsscheTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2302*44704f69SBart Van Assche
2303*44704f69SBart Van AsscheWhen reporting a bug, please describe a test case to reproduce it and
2304*44704f69SBart Van Asscheinclude the following information:
2305*44704f69SBart Van Assche
2306*44704f69SBart Van Assche       host-triplet:   $host
2307*44704f69SBart Van Assche       shell:          $SHELL
2308*44704f69SBart Van Assche       compiler:       $LTCC
2309*44704f69SBart Van Assche       compiler flags: $LTCFLAGS
2310*44704f69SBart Van Assche       linker:         $LD (gnu? $with_gnu_ld)
2311*44704f69SBart Van Assche       version:        $progname $scriptversion Debian-2.4.7-4
2312*44704f69SBart Van Assche       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2313*44704f69SBart Van Assche       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2314*44704f69SBart Van Assche
2315*44704f69SBart Van AsscheReport bugs to <[email protected]>.
2316*44704f69SBart Van AsscheGNU libtool home page: <http://www.gnu.org/s/libtool/>.
2317*44704f69SBart Van AsscheGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2318*44704f69SBart Van Assche    exit 0
2319*44704f69SBart Van Assche}
2320*44704f69SBart Van Assche
2321*44704f69SBart Van Assche
2322*44704f69SBart Van Assche# func_lo2o OBJECT-NAME
2323*44704f69SBart Van Assche# ---------------------
2324*44704f69SBart Van Assche# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2325*44704f69SBart Van Assche# object suffix.
2326*44704f69SBart Van Assche
2327*44704f69SBart Van Asschelo2o=s/\\.lo\$/.$objext/
2328*44704f69SBart Van Asscheo2lo=s/\\.$objext\$/.lo/
2329*44704f69SBart Van Assche
2330*44704f69SBart Van Asscheif test yes = "$_G_HAVE_XSI_OPS"; then
2331*44704f69SBart Van Assche  eval 'func_lo2o ()
2332*44704f69SBart Van Assche  {
2333*44704f69SBart Van Assche    case $1 in
2334*44704f69SBart Van Assche      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2335*44704f69SBart Van Assche      *   ) func_lo2o_result=$1               ;;
2336*44704f69SBart Van Assche    esac
2337*44704f69SBart Van Assche  }'
2338*44704f69SBart Van Assche
2339*44704f69SBart Van Assche  # func_xform LIBOBJ-OR-SOURCE
2340*44704f69SBart Van Assche  # ---------------------------
2341*44704f69SBart Van Assche  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2342*44704f69SBart Van Assche  # suffix to a '.lo' libtool-object suffix.
2343*44704f69SBart Van Assche  eval 'func_xform ()
2344*44704f69SBart Van Assche  {
2345*44704f69SBart Van Assche    func_xform_result=${1%.*}.lo
2346*44704f69SBart Van Assche  }'
2347*44704f69SBart Van Asscheelse
2348*44704f69SBart Van Assche  # ...otherwise fall back to using sed.
2349*44704f69SBart Van Assche  func_lo2o ()
2350*44704f69SBart Van Assche  {
2351*44704f69SBart Van Assche    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2352*44704f69SBart Van Assche  }
2353*44704f69SBart Van Assche
2354*44704f69SBart Van Assche  func_xform ()
2355*44704f69SBart Van Assche  {
2356*44704f69SBart Van Assche    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2357*44704f69SBart Van Assche  }
2358*44704f69SBart Van Asschefi
2359*44704f69SBart Van Assche
2360*44704f69SBart Van Assche
2361*44704f69SBart Van Assche# func_fatal_configuration ARG...
2362*44704f69SBart Van Assche# -------------------------------
2363*44704f69SBart Van Assche# Echo program name prefixed message to standard error, followed by
2364*44704f69SBart Van Assche# a configuration failure hint, and exit.
2365*44704f69SBart Van Asschefunc_fatal_configuration ()
2366*44704f69SBart Van Assche{
2367*44704f69SBart Van Assche    func_fatal_error ${1+"$@"} \
2368*44704f69SBart Van Assche      "See the $PACKAGE documentation for more information." \
2369*44704f69SBart Van Assche      "Fatal configuration error."
2370*44704f69SBart Van Assche}
2371*44704f69SBart Van Assche
2372*44704f69SBart Van Assche
2373*44704f69SBart Van Assche# func_config
2374*44704f69SBart Van Assche# -----------
2375*44704f69SBart Van Assche# Display the configuration for all the tags in this script.
2376*44704f69SBart Van Asschefunc_config ()
2377*44704f69SBart Van Assche{
2378*44704f69SBart Van Assche    re_begincf='^# ### BEGIN LIBTOOL'
2379*44704f69SBart Van Assche    re_endcf='^# ### END LIBTOOL'
2380*44704f69SBart Van Assche
2381*44704f69SBart Van Assche    # Default configuration.
2382*44704f69SBart Van Assche    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2383*44704f69SBart Van Assche
2384*44704f69SBart Van Assche    # Now print the configurations for the tags.
2385*44704f69SBart Van Assche    for tagname in $taglist; do
2386*44704f69SBart Van Assche      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2387*44704f69SBart Van Assche    done
2388*44704f69SBart Van Assche
2389*44704f69SBart Van Assche    exit $?
2390*44704f69SBart Van Assche}
2391*44704f69SBart Van Assche
2392*44704f69SBart Van Assche
2393*44704f69SBart Van Assche# func_features
2394*44704f69SBart Van Assche# -------------
2395*44704f69SBart Van Assche# Display the features supported by this script.
2396*44704f69SBart Van Asschefunc_features ()
2397*44704f69SBart Van Assche{
2398*44704f69SBart Van Assche    echo "host: $host"
2399*44704f69SBart Van Assche    if test yes = "$build_libtool_libs"; then
2400*44704f69SBart Van Assche      echo "enable shared libraries"
2401*44704f69SBart Van Assche    else
2402*44704f69SBart Van Assche      echo "disable shared libraries"
2403*44704f69SBart Van Assche    fi
2404*44704f69SBart Van Assche    if test yes = "$build_old_libs"; then
2405*44704f69SBart Van Assche      echo "enable static libraries"
2406*44704f69SBart Van Assche    else
2407*44704f69SBart Van Assche      echo "disable static libraries"
2408*44704f69SBart Van Assche    fi
2409*44704f69SBart Van Assche
2410*44704f69SBart Van Assche    exit $?
2411*44704f69SBart Van Assche}
2412*44704f69SBart Van Assche
2413*44704f69SBart Van Assche
2414*44704f69SBart Van Assche# func_enable_tag TAGNAME
2415*44704f69SBart Van Assche# -----------------------
2416*44704f69SBart Van Assche# Verify that TAGNAME is valid, and either flag an error and exit, or
2417*44704f69SBart Van Assche# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2418*44704f69SBart Van Assche# variable here.
2419*44704f69SBart Van Asschefunc_enable_tag ()
2420*44704f69SBart Van Assche{
2421*44704f69SBart Van Assche    # Global variable:
2422*44704f69SBart Van Assche    tagname=$1
2423*44704f69SBart Van Assche
2424*44704f69SBart Van Assche    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2425*44704f69SBart Van Assche    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2426*44704f69SBart Van Assche    sed_extractcf=/$re_begincf/,/$re_endcf/p
2427*44704f69SBart Van Assche
2428*44704f69SBart Van Assche    # Validate tagname.
2429*44704f69SBart Van Assche    case $tagname in
2430*44704f69SBart Van Assche      *[!-_A-Za-z0-9,/]*)
2431*44704f69SBart Van Assche        func_fatal_error "invalid tag name: $tagname"
2432*44704f69SBart Van Assche        ;;
2433*44704f69SBart Van Assche    esac
2434*44704f69SBart Van Assche
2435*44704f69SBart Van Assche    # Don't test for the "default" C tag, as we know it's
2436*44704f69SBart Van Assche    # there but not specially marked.
2437*44704f69SBart Van Assche    case $tagname in
2438*44704f69SBart Van Assche        CC) ;;
2439*44704f69SBart Van Assche    *)
2440*44704f69SBart Van Assche        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2441*44704f69SBart Van Assche	  taglist="$taglist $tagname"
2442*44704f69SBart Van Assche
2443*44704f69SBart Van Assche	  # Evaluate the configuration.  Be careful to quote the path
2444*44704f69SBart Van Assche	  # and the sed script, to avoid splitting on whitespace, but
2445*44704f69SBart Van Assche	  # also don't use non-portable quotes within backquotes within
2446*44704f69SBart Van Assche	  # quotes we have to do it in 2 steps:
2447*44704f69SBart Van Assche	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2448*44704f69SBart Van Assche	  eval "$extractedcf"
2449*44704f69SBart Van Assche        else
2450*44704f69SBart Van Assche	  func_error "ignoring unknown tag $tagname"
2451*44704f69SBart Van Assche        fi
2452*44704f69SBart Van Assche        ;;
2453*44704f69SBart Van Assche    esac
2454*44704f69SBart Van Assche}
2455*44704f69SBart Van Assche
2456*44704f69SBart Van Assche
2457*44704f69SBart Van Assche# func_check_version_match
2458*44704f69SBart Van Assche# ------------------------
2459*44704f69SBart Van Assche# Ensure that we are using m4 macros, and libtool script from the same
2460*44704f69SBart Van Assche# release of libtool.
2461*44704f69SBart Van Asschefunc_check_version_match ()
2462*44704f69SBart Van Assche{
2463*44704f69SBart Van Assche    if test "$package_revision" != "$macro_revision"; then
2464*44704f69SBart Van Assche      if test "$VERSION" != "$macro_version"; then
2465*44704f69SBart Van Assche        if test -z "$macro_version"; then
2466*44704f69SBart Van Assche          cat >&2 <<_LT_EOF
2467*44704f69SBart Van Assche$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2468*44704f69SBart Van Assche$progname: definition of this LT_INIT comes from an older release.
2469*44704f69SBart Van Assche$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2470*44704f69SBart Van Assche$progname: and run autoconf again.
2471*44704f69SBart Van Assche_LT_EOF
2472*44704f69SBart Van Assche        else
2473*44704f69SBart Van Assche          cat >&2 <<_LT_EOF
2474*44704f69SBart Van Assche$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2475*44704f69SBart Van Assche$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2476*44704f69SBart Van Assche$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2477*44704f69SBart Van Assche$progname: and run autoconf again.
2478*44704f69SBart Van Assche_LT_EOF
2479*44704f69SBart Van Assche        fi
2480*44704f69SBart Van Assche      else
2481*44704f69SBart Van Assche        cat >&2 <<_LT_EOF
2482*44704f69SBart Van Assche$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2483*44704f69SBart Van Assche$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2484*44704f69SBart Van Assche$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2485*44704f69SBart Van Assche$progname: of $PACKAGE $VERSION and run autoconf again.
2486*44704f69SBart Van Assche_LT_EOF
2487*44704f69SBart Van Assche      fi
2488*44704f69SBart Van Assche
2489*44704f69SBart Van Assche      exit $EXIT_MISMATCH
2490*44704f69SBart Van Assche    fi
2491*44704f69SBart Van Assche}
2492*44704f69SBart Van Assche
2493*44704f69SBart Van Assche
2494*44704f69SBart Van Assche# libtool_options_prep [ARG]...
2495*44704f69SBart Van Assche# -----------------------------
2496*44704f69SBart Van Assche# Preparation for options parsed by libtool.
2497*44704f69SBart Van Asschelibtool_options_prep ()
2498*44704f69SBart Van Assche{
2499*44704f69SBart Van Assche    $debug_mode
2500*44704f69SBart Van Assche
2501*44704f69SBart Van Assche    # Option defaults:
2502*44704f69SBart Van Assche    opt_config=false
2503*44704f69SBart Van Assche    opt_dlopen=
2504*44704f69SBart Van Assche    opt_dry_run=false
2505*44704f69SBart Van Assche    opt_help=false
2506*44704f69SBart Van Assche    opt_mode=
2507*44704f69SBart Van Assche    opt_preserve_dup_deps=false
2508*44704f69SBart Van Assche    opt_quiet=false
2509*44704f69SBart Van Assche
2510*44704f69SBart Van Assche    nonopt=
2511*44704f69SBart Van Assche    preserve_args=
2512*44704f69SBart Van Assche
2513*44704f69SBart Van Assche    _G_rc_lt_options_prep=:
2514*44704f69SBart Van Assche
2515*44704f69SBart Van Assche    _G_rc_lt_options_prep=:
2516*44704f69SBart Van Assche
2517*44704f69SBart Van Assche    # Shorthand for --mode=foo, only valid as the first argument
2518*44704f69SBart Van Assche    case $1 in
2519*44704f69SBart Van Assche    clean|clea|cle|cl)
2520*44704f69SBart Van Assche      shift; set dummy --mode clean ${1+"$@"}; shift
2521*44704f69SBart Van Assche      ;;
2522*44704f69SBart Van Assche    compile|compil|compi|comp|com|co|c)
2523*44704f69SBart Van Assche      shift; set dummy --mode compile ${1+"$@"}; shift
2524*44704f69SBart Van Assche      ;;
2525*44704f69SBart Van Assche    execute|execut|execu|exec|exe|ex|e)
2526*44704f69SBart Van Assche      shift; set dummy --mode execute ${1+"$@"}; shift
2527*44704f69SBart Van Assche      ;;
2528*44704f69SBart Van Assche    finish|finis|fini|fin|fi|f)
2529*44704f69SBart Van Assche      shift; set dummy --mode finish ${1+"$@"}; shift
2530*44704f69SBart Van Assche      ;;
2531*44704f69SBart Van Assche    install|instal|insta|inst|ins|in|i)
2532*44704f69SBart Van Assche      shift; set dummy --mode install ${1+"$@"}; shift
2533*44704f69SBart Van Assche      ;;
2534*44704f69SBart Van Assche    link|lin|li|l)
2535*44704f69SBart Van Assche      shift; set dummy --mode link ${1+"$@"}; shift
2536*44704f69SBart Van Assche      ;;
2537*44704f69SBart Van Assche    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2538*44704f69SBart Van Assche      shift; set dummy --mode uninstall ${1+"$@"}; shift
2539*44704f69SBart Van Assche      ;;
2540*44704f69SBart Van Assche    *)
2541*44704f69SBart Van Assche      _G_rc_lt_options_prep=false
2542*44704f69SBart Van Assche      ;;
2543*44704f69SBart Van Assche    esac
2544*44704f69SBart Van Assche
2545*44704f69SBart Van Assche    if $_G_rc_lt_options_prep; then
2546*44704f69SBart Van Assche      # Pass back the list of options.
2547*44704f69SBart Van Assche      func_quote eval ${1+"$@"}
2548*44704f69SBart Van Assche      libtool_options_prep_result=$func_quote_result
2549*44704f69SBart Van Assche    fi
2550*44704f69SBart Van Assche}
2551*44704f69SBart Van Asschefunc_add_hook func_options_prep libtool_options_prep
2552*44704f69SBart Van Assche
2553*44704f69SBart Van Assche
2554*44704f69SBart Van Assche# libtool_parse_options [ARG]...
2555*44704f69SBart Van Assche# ---------------------------------
2556*44704f69SBart Van Assche# Provide handling for libtool specific options.
2557*44704f69SBart Van Asschelibtool_parse_options ()
2558*44704f69SBart Van Assche{
2559*44704f69SBart Van Assche    $debug_cmd
2560*44704f69SBart Van Assche
2561*44704f69SBart Van Assche    _G_rc_lt_parse_options=false
2562*44704f69SBart Van Assche
2563*44704f69SBart Van Assche    # Perform our own loop to consume as many options as possible in
2564*44704f69SBart Van Assche    # each iteration.
2565*44704f69SBart Van Assche    while test $# -gt 0; do
2566*44704f69SBart Van Assche      _G_match_lt_parse_options=:
2567*44704f69SBart Van Assche      _G_opt=$1
2568*44704f69SBart Van Assche      shift
2569*44704f69SBart Van Assche      case $_G_opt in
2570*44704f69SBart Van Assche        --dry-run|--dryrun|-n)
2571*44704f69SBart Van Assche                        opt_dry_run=:
2572*44704f69SBart Van Assche                        ;;
2573*44704f69SBart Van Assche
2574*44704f69SBart Van Assche        --config)       func_config ;;
2575*44704f69SBart Van Assche
2576*44704f69SBart Van Assche        --dlopen|-dlopen)
2577*44704f69SBart Van Assche                        opt_dlopen="${opt_dlopen+$opt_dlopen
2578*44704f69SBart Van Assche}$1"
2579*44704f69SBart Van Assche                        shift
2580*44704f69SBart Van Assche                        ;;
2581*44704f69SBart Van Assche
2582*44704f69SBart Van Assche        --preserve-dup-deps)
2583*44704f69SBart Van Assche                        opt_preserve_dup_deps=: ;;
2584*44704f69SBart Van Assche
2585*44704f69SBart Van Assche        --features)     func_features ;;
2586*44704f69SBart Van Assche
2587*44704f69SBart Van Assche        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2588*44704f69SBart Van Assche
2589*44704f69SBart Van Assche        --help)         opt_help=: ;;
2590*44704f69SBart Van Assche
2591*44704f69SBart Van Assche        --help-all)     opt_help=': help-all' ;;
2592*44704f69SBart Van Assche
2593*44704f69SBart Van Assche        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2594*44704f69SBart Van Assche                        opt_mode=$1
2595*44704f69SBart Van Assche                        case $1 in
2596*44704f69SBart Van Assche                          # Valid mode arguments:
2597*44704f69SBart Van Assche                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2598*44704f69SBart Van Assche
2599*44704f69SBart Van Assche                          # Catch anything else as an error
2600*44704f69SBart Van Assche                          *) func_error "invalid argument for $_G_opt"
2601*44704f69SBart Van Assche                             exit_cmd=exit
2602*44704f69SBart Van Assche                             break
2603*44704f69SBart Van Assche                             ;;
2604*44704f69SBart Van Assche                        esac
2605*44704f69SBart Van Assche                        shift
2606*44704f69SBart Van Assche                        ;;
2607*44704f69SBart Van Assche
2608*44704f69SBart Van Assche        --no-silent|--no-quiet)
2609*44704f69SBart Van Assche                        opt_quiet=false
2610*44704f69SBart Van Assche                        func_append preserve_args " $_G_opt"
2611*44704f69SBart Van Assche                        ;;
2612*44704f69SBart Van Assche
2613*44704f69SBart Van Assche        --no-warnings|--no-warning|--no-warn)
2614*44704f69SBart Van Assche                        opt_warning=false
2615*44704f69SBart Van Assche                        func_append preserve_args " $_G_opt"
2616*44704f69SBart Van Assche                        ;;
2617*44704f69SBart Van Assche
2618*44704f69SBart Van Assche        --no-verbose)
2619*44704f69SBart Van Assche                        opt_verbose=false
2620*44704f69SBart Van Assche                        func_append preserve_args " $_G_opt"
2621*44704f69SBart Van Assche                        ;;
2622*44704f69SBart Van Assche
2623*44704f69SBart Van Assche        --silent|--quiet)
2624*44704f69SBart Van Assche                        opt_quiet=:
2625*44704f69SBart Van Assche                        opt_verbose=false
2626*44704f69SBart Van Assche                        func_append preserve_args " $_G_opt"
2627*44704f69SBart Van Assche                        ;;
2628*44704f69SBart Van Assche
2629*44704f69SBart Van Assche        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2630*44704f69SBart Van Assche                        opt_tag=$1
2631*44704f69SBart Van Assche                        func_append preserve_args " $_G_opt $1"
2632*44704f69SBart Van Assche                        func_enable_tag "$1"
2633*44704f69SBart Van Assche                        shift
2634*44704f69SBart Van Assche                        ;;
2635*44704f69SBart Van Assche
2636*44704f69SBart Van Assche        --verbose|-v)   opt_quiet=false
2637*44704f69SBart Van Assche                        opt_verbose=:
2638*44704f69SBart Van Assche                        func_append preserve_args " $_G_opt"
2639*44704f69SBart Van Assche                        ;;
2640*44704f69SBart Van Assche
2641*44704f69SBart Van Assche        # An option not handled by this hook function:
2642*44704f69SBart Van Assche        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2643*44704f69SBart Van Assche                        _G_match_lt_parse_options=false
2644*44704f69SBart Van Assche                        break
2645*44704f69SBart Van Assche                        ;;
2646*44704f69SBart Van Assche      esac
2647*44704f69SBart Van Assche      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2648*44704f69SBart Van Assche    done
2649*44704f69SBart Van Assche
2650*44704f69SBart Van Assche    if $_G_rc_lt_parse_options; then
2651*44704f69SBart Van Assche      # save modified positional parameters for caller
2652*44704f69SBart Van Assche      func_quote eval ${1+"$@"}
2653*44704f69SBart Van Assche      libtool_parse_options_result=$func_quote_result
2654*44704f69SBart Van Assche    fi
2655*44704f69SBart Van Assche}
2656*44704f69SBart Van Asschefunc_add_hook func_parse_options libtool_parse_options
2657*44704f69SBart Van Assche
2658*44704f69SBart Van Assche
2659*44704f69SBart Van Assche
2660*44704f69SBart Van Assche# libtool_validate_options [ARG]...
2661*44704f69SBart Van Assche# ---------------------------------
2662*44704f69SBart Van Assche# Perform any sanity checks on option settings and/or unconsumed
2663*44704f69SBart Van Assche# arguments.
2664*44704f69SBart Van Asschelibtool_validate_options ()
2665*44704f69SBart Van Assche{
2666*44704f69SBart Van Assche    # save first non-option argument
2667*44704f69SBart Van Assche    if test 0 -lt $#; then
2668*44704f69SBart Van Assche      nonopt=$1
2669*44704f69SBart Van Assche      shift
2670*44704f69SBart Van Assche    fi
2671*44704f69SBart Van Assche
2672*44704f69SBart Van Assche    # preserve --debug
2673*44704f69SBart Van Assche    test : = "$debug_cmd" || func_append preserve_args " --debug"
2674*44704f69SBart Van Assche
2675*44704f69SBart Van Assche    case $host in
2676*44704f69SBart Van Assche      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2677*44704f69SBart Van Assche      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2678*44704f69SBart Van Assche      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2679*44704f69SBart Van Assche        # don't eliminate duplications in $postdeps and $predeps
2680*44704f69SBart Van Assche        opt_duplicate_compiler_generated_deps=:
2681*44704f69SBart Van Assche        ;;
2682*44704f69SBart Van Assche      *)
2683*44704f69SBart Van Assche        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2684*44704f69SBart Van Assche        ;;
2685*44704f69SBart Van Assche    esac
2686*44704f69SBart Van Assche
2687*44704f69SBart Van Assche    $opt_help || {
2688*44704f69SBart Van Assche      # Sanity checks first:
2689*44704f69SBart Van Assche      func_check_version_match
2690*44704f69SBart Van Assche
2691*44704f69SBart Van Assche      test yes != "$build_libtool_libs" \
2692*44704f69SBart Van Assche        && test yes != "$build_old_libs" \
2693*44704f69SBart Van Assche        && func_fatal_configuration "not configured to build any kind of library"
2694*44704f69SBart Van Assche
2695*44704f69SBart Van Assche      # Darwin sucks
2696*44704f69SBart Van Assche      eval std_shrext=\"$shrext_cmds\"
2697*44704f69SBart Van Assche
2698*44704f69SBart Van Assche      # Only execute mode is allowed to have -dlopen flags.
2699*44704f69SBart Van Assche      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2700*44704f69SBart Van Assche        func_error "unrecognized option '-dlopen'"
2701*44704f69SBart Van Assche        $ECHO "$help" 1>&2
2702*44704f69SBart Van Assche        exit $EXIT_FAILURE
2703*44704f69SBart Van Assche      fi
2704*44704f69SBart Van Assche
2705*44704f69SBart Van Assche      # Change the help message to a mode-specific one.
2706*44704f69SBart Van Assche      generic_help=$help
2707*44704f69SBart Van Assche      help="Try '$progname --help --mode=$opt_mode' for more information."
2708*44704f69SBart Van Assche    }
2709*44704f69SBart Van Assche
2710*44704f69SBart Van Assche    # Pass back the unparsed argument list
2711*44704f69SBart Van Assche    func_quote eval ${1+"$@"}
2712*44704f69SBart Van Assche    libtool_validate_options_result=$func_quote_result
2713*44704f69SBart Van Assche}
2714*44704f69SBart Van Asschefunc_add_hook func_validate_options libtool_validate_options
2715*44704f69SBart Van Assche
2716*44704f69SBart Van Assche
2717*44704f69SBart Van Assche# Process options as early as possible so that --help and --version
2718*44704f69SBart Van Assche# can return quickly.
2719*44704f69SBart Van Asschefunc_options ${1+"$@"}
2720*44704f69SBart Van Asscheeval set dummy "$func_options_result"; shift
2721*44704f69SBart Van Assche
2722*44704f69SBart Van Assche
2723*44704f69SBart Van Assche
2724*44704f69SBart Van Assche## ----------- ##
2725*44704f69SBart Van Assche##    Main.    ##
2726*44704f69SBart Van Assche## ----------- ##
2727*44704f69SBart Van Assche
2728*44704f69SBart Van Asschemagic='%%%MAGIC variable%%%'
2729*44704f69SBart Van Asschemagic_exe='%%%MAGIC EXE variable%%%'
2730*44704f69SBart Van Assche
2731*44704f69SBart Van Assche# Global variables.
2732*44704f69SBart Van Asscheextracted_archives=
2733*44704f69SBart Van Asscheextracted_serial=0
2734*44704f69SBart Van Assche
2735*44704f69SBart Van Assche# If this variable is set in any of the actions, the command in it
2736*44704f69SBart Van Assche# will be execed at the end.  This prevents here-documents from being
2737*44704f69SBart Van Assche# left over by shells.
2738*44704f69SBart Van Asscheexec_cmd=
2739*44704f69SBart Van Assche
2740*44704f69SBart Van Assche
2741*44704f69SBart Van Assche# A function that is used when there is no print builtin or printf.
2742*44704f69SBart Van Asschefunc_fallback_echo ()
2743*44704f69SBart Van Assche{
2744*44704f69SBart Van Assche  eval 'cat <<_LTECHO_EOF
2745*44704f69SBart Van Assche$1
2746*44704f69SBart Van Assche_LTECHO_EOF'
2747*44704f69SBart Van Assche}
2748*44704f69SBart Van Assche
2749*44704f69SBart Van Assche# func_generated_by_libtool
2750*44704f69SBart Van Assche# True iff stdin has been generated by Libtool. This function is only
2751*44704f69SBart Van Assche# a basic sanity check; it will hardly flush out determined imposters.
2752*44704f69SBart Van Asschefunc_generated_by_libtool_p ()
2753*44704f69SBart Van Assche{
2754*44704f69SBart Van Assche  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2755*44704f69SBart Van Assche}
2756*44704f69SBart Van Assche
2757*44704f69SBart Van Assche# func_lalib_p file
2758*44704f69SBart Van Assche# True iff FILE is a libtool '.la' library or '.lo' object file.
2759*44704f69SBart Van Assche# This function is only a basic sanity check; it will hardly flush out
2760*44704f69SBart Van Assche# determined imposters.
2761*44704f69SBart Van Asschefunc_lalib_p ()
2762*44704f69SBart Van Assche{
2763*44704f69SBart Van Assche    test -f "$1" &&
2764*44704f69SBart Van Assche      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2765*44704f69SBart Van Assche}
2766*44704f69SBart Van Assche
2767*44704f69SBart Van Assche# func_lalib_unsafe_p file
2768*44704f69SBart Van Assche# True iff FILE is a libtool '.la' library or '.lo' object file.
2769*44704f69SBart Van Assche# This function implements the same check as func_lalib_p without
2770*44704f69SBart Van Assche# resorting to external programs.  To this end, it redirects stdin and
2771*44704f69SBart Van Assche# closes it afterwards, without saving the original file descriptor.
2772*44704f69SBart Van Assche# As a safety measure, use it only where a negative result would be
2773*44704f69SBart Van Assche# fatal anyway.  Works if 'file' does not exist.
2774*44704f69SBart Van Asschefunc_lalib_unsafe_p ()
2775*44704f69SBart Van Assche{
2776*44704f69SBart Van Assche    lalib_p=no
2777*44704f69SBart Van Assche    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2778*44704f69SBart Van Assche	for lalib_p_l in 1 2 3 4
2779*44704f69SBart Van Assche	do
2780*44704f69SBart Van Assche	    read lalib_p_line
2781*44704f69SBart Van Assche	    case $lalib_p_line in
2782*44704f69SBart Van Assche		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2783*44704f69SBart Van Assche	    esac
2784*44704f69SBart Van Assche	done
2785*44704f69SBart Van Assche	exec 0<&5 5<&-
2786*44704f69SBart Van Assche    fi
2787*44704f69SBart Van Assche    test yes = "$lalib_p"
2788*44704f69SBart Van Assche}
2789*44704f69SBart Van Assche
2790*44704f69SBart Van Assche# func_ltwrapper_script_p file
2791*44704f69SBart Van Assche# True iff FILE is a libtool wrapper script
2792*44704f69SBart Van Assche# This function is only a basic sanity check; it will hardly flush out
2793*44704f69SBart Van Assche# determined imposters.
2794*44704f69SBart Van Asschefunc_ltwrapper_script_p ()
2795*44704f69SBart Van Assche{
2796*44704f69SBart Van Assche    test -f "$1" &&
2797*44704f69SBart Van Assche      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2798*44704f69SBart Van Assche}
2799*44704f69SBart Van Assche
2800*44704f69SBart Van Assche# func_ltwrapper_executable_p file
2801*44704f69SBart Van Assche# True iff FILE is a libtool wrapper executable
2802*44704f69SBart Van Assche# This function is only a basic sanity check; it will hardly flush out
2803*44704f69SBart Van Assche# determined imposters.
2804*44704f69SBart Van Asschefunc_ltwrapper_executable_p ()
2805*44704f69SBart Van Assche{
2806*44704f69SBart Van Assche    func_ltwrapper_exec_suffix=
2807*44704f69SBart Van Assche    case $1 in
2808*44704f69SBart Van Assche    *.exe) ;;
2809*44704f69SBart Van Assche    *) func_ltwrapper_exec_suffix=.exe ;;
2810*44704f69SBart Van Assche    esac
2811*44704f69SBart Van Assche    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2812*44704f69SBart Van Assche}
2813*44704f69SBart Van Assche
2814*44704f69SBart Van Assche# func_ltwrapper_scriptname file
2815*44704f69SBart Van Assche# Assumes file is an ltwrapper_executable
2816*44704f69SBart Van Assche# uses $file to determine the appropriate filename for a
2817*44704f69SBart Van Assche# temporary ltwrapper_script.
2818*44704f69SBart Van Asschefunc_ltwrapper_scriptname ()
2819*44704f69SBart Van Assche{
2820*44704f69SBart Van Assche    func_dirname_and_basename "$1" "" "."
2821*44704f69SBart Van Assche    func_stripname '' '.exe' "$func_basename_result"
2822*44704f69SBart Van Assche    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2823*44704f69SBart Van Assche}
2824*44704f69SBart Van Assche
2825*44704f69SBart Van Assche# func_ltwrapper_p file
2826*44704f69SBart Van Assche# True iff FILE is a libtool wrapper script or wrapper executable
2827*44704f69SBart Van Assche# This function is only a basic sanity check; it will hardly flush out
2828*44704f69SBart Van Assche# determined imposters.
2829*44704f69SBart Van Asschefunc_ltwrapper_p ()
2830*44704f69SBart Van Assche{
2831*44704f69SBart Van Assche    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2832*44704f69SBart Van Assche}
2833*44704f69SBart Van Assche
2834*44704f69SBart Van Assche
2835*44704f69SBart Van Assche# func_execute_cmds commands fail_cmd
2836*44704f69SBart Van Assche# Execute tilde-delimited COMMANDS.
2837*44704f69SBart Van Assche# If FAIL_CMD is given, eval that upon failure.
2838*44704f69SBart Van Assche# FAIL_CMD may read-access the current command in variable CMD!
2839*44704f69SBart Van Asschefunc_execute_cmds ()
2840*44704f69SBart Van Assche{
2841*44704f69SBart Van Assche    $debug_cmd
2842*44704f69SBart Van Assche
2843*44704f69SBart Van Assche    save_ifs=$IFS; IFS='~'
2844*44704f69SBart Van Assche    for cmd in $1; do
2845*44704f69SBart Van Assche      IFS=$sp$nl
2846*44704f69SBart Van Assche      eval cmd=\"$cmd\"
2847*44704f69SBart Van Assche      IFS=$save_ifs
2848*44704f69SBart Van Assche      func_show_eval "$cmd" "${2-:}"
2849*44704f69SBart Van Assche    done
2850*44704f69SBart Van Assche    IFS=$save_ifs
2851*44704f69SBart Van Assche}
2852*44704f69SBart Van Assche
2853*44704f69SBart Van Assche
2854*44704f69SBart Van Assche# func_source file
2855*44704f69SBart Van Assche# Source FILE, adding directory component if necessary.
2856*44704f69SBart Van Assche# Note that it is not necessary on cygwin/mingw to append a dot to
2857*44704f69SBart Van Assche# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2858*44704f69SBart Van Assche# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2859*44704f69SBart Van Assche# 'FILE.' does not work on cygwin managed mounts.
2860*44704f69SBart Van Asschefunc_source ()
2861*44704f69SBart Van Assche{
2862*44704f69SBart Van Assche    $debug_cmd
2863*44704f69SBart Van Assche
2864*44704f69SBart Van Assche    case $1 in
2865*44704f69SBart Van Assche    */* | *\\*)	. "$1" ;;
2866*44704f69SBart Van Assche    *)		. "./$1" ;;
2867*44704f69SBart Van Assche    esac
2868*44704f69SBart Van Assche}
2869*44704f69SBart Van Assche
2870*44704f69SBart Van Assche
2871*44704f69SBart Van Assche# func_resolve_sysroot PATH
2872*44704f69SBart Van Assche# Replace a leading = in PATH with a sysroot.  Store the result into
2873*44704f69SBart Van Assche# func_resolve_sysroot_result
2874*44704f69SBart Van Asschefunc_resolve_sysroot ()
2875*44704f69SBart Van Assche{
2876*44704f69SBart Van Assche  func_resolve_sysroot_result=$1
2877*44704f69SBart Van Assche  case $func_resolve_sysroot_result in
2878*44704f69SBart Van Assche  =*)
2879*44704f69SBart Van Assche    func_stripname '=' '' "$func_resolve_sysroot_result"
2880*44704f69SBart Van Assche    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2881*44704f69SBart Van Assche    ;;
2882*44704f69SBart Van Assche  esac
2883*44704f69SBart Van Assche}
2884*44704f69SBart Van Assche
2885*44704f69SBart Van Assche# func_replace_sysroot PATH
2886*44704f69SBart Van Assche# If PATH begins with the sysroot, replace it with = and
2887*44704f69SBart Van Assche# store the result into func_replace_sysroot_result.
2888*44704f69SBart Van Asschefunc_replace_sysroot ()
2889*44704f69SBart Van Assche{
2890*44704f69SBart Van Assche  case $lt_sysroot:$1 in
2891*44704f69SBart Van Assche  ?*:"$lt_sysroot"*)
2892*44704f69SBart Van Assche    func_stripname "$lt_sysroot" '' "$1"
2893*44704f69SBart Van Assche    func_replace_sysroot_result='='$func_stripname_result
2894*44704f69SBart Van Assche    ;;
2895*44704f69SBart Van Assche  *)
2896*44704f69SBart Van Assche    # Including no sysroot.
2897*44704f69SBart Van Assche    func_replace_sysroot_result=$1
2898*44704f69SBart Van Assche    ;;
2899*44704f69SBart Van Assche  esac
2900*44704f69SBart Van Assche}
2901*44704f69SBart Van Assche
2902*44704f69SBart Van Assche# func_infer_tag arg
2903*44704f69SBart Van Assche# Infer tagged configuration to use if any are available and
2904*44704f69SBart Van Assche# if one wasn't chosen via the "--tag" command line option.
2905*44704f69SBart Van Assche# Only attempt this if the compiler in the base compile
2906*44704f69SBart Van Assche# command doesn't match the default compiler.
2907*44704f69SBart Van Assche# arg is usually of the form 'gcc ...'
2908*44704f69SBart Van Asschefunc_infer_tag ()
2909*44704f69SBart Van Assche{
2910*44704f69SBart Van Assche    $debug_cmd
2911*44704f69SBart Van Assche
2912*44704f69SBart Van Assche    if test -n "$available_tags" && test -z "$tagname"; then
2913*44704f69SBart Van Assche      CC_quoted=
2914*44704f69SBart Van Assche      for arg in $CC; do
2915*44704f69SBart Van Assche	func_append_quoted CC_quoted "$arg"
2916*44704f69SBart Van Assche      done
2917*44704f69SBart Van Assche      CC_expanded=`func_echo_all $CC`
2918*44704f69SBart Van Assche      CC_quoted_expanded=`func_echo_all $CC_quoted`
2919*44704f69SBart Van Assche      case $@ in
2920*44704f69SBart Van Assche      # Blanks in the command may have been stripped by the calling shell,
2921*44704f69SBart Van Assche      # but not from the CC environment variable when configure was run.
2922*44704f69SBart Van Assche      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2923*44704f69SBart Van Assche      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2924*44704f69SBart Van Assche      # Blanks at the start of $base_compile will cause this to fail
2925*44704f69SBart Van Assche      # if we don't check for them as well.
2926*44704f69SBart Van Assche      *)
2927*44704f69SBart Van Assche	for z in $available_tags; do
2928*44704f69SBart Van Assche	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2929*44704f69SBart Van Assche	    # Evaluate the configuration.
2930*44704f69SBart Van Assche	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2931*44704f69SBart Van Assche	    CC_quoted=
2932*44704f69SBart Van Assche	    for arg in $CC; do
2933*44704f69SBart Van Assche	      # Double-quote args containing other shell metacharacters.
2934*44704f69SBart Van Assche	      func_append_quoted CC_quoted "$arg"
2935*44704f69SBart Van Assche	    done
2936*44704f69SBart Van Assche	    CC_expanded=`func_echo_all $CC`
2937*44704f69SBart Van Assche	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2938*44704f69SBart Van Assche	    case "$@ " in
2939*44704f69SBart Van Assche	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2940*44704f69SBart Van Assche	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2941*44704f69SBart Van Assche	      # The compiler in the base compile command matches
2942*44704f69SBart Van Assche	      # the one in the tagged configuration.
2943*44704f69SBart Van Assche	      # Assume this is the tagged configuration we want.
2944*44704f69SBart Van Assche	      tagname=$z
2945*44704f69SBart Van Assche	      break
2946*44704f69SBart Van Assche	      ;;
2947*44704f69SBart Van Assche	    esac
2948*44704f69SBart Van Assche	  fi
2949*44704f69SBart Van Assche	done
2950*44704f69SBart Van Assche	# If $tagname still isn't set, then no tagged configuration
2951*44704f69SBart Van Assche	# was found and let the user know that the "--tag" command
2952*44704f69SBart Van Assche	# line option must be used.
2953*44704f69SBart Van Assche	if test -z "$tagname"; then
2954*44704f69SBart Van Assche	  func_echo "unable to infer tagged configuration"
2955*44704f69SBart Van Assche	  func_fatal_error "specify a tag with '--tag'"
2956*44704f69SBart Van Assche#	else
2957*44704f69SBart Van Assche#	  func_verbose "using $tagname tagged configuration"
2958*44704f69SBart Van Assche	fi
2959*44704f69SBart Van Assche	;;
2960*44704f69SBart Van Assche      esac
2961*44704f69SBart Van Assche    fi
2962*44704f69SBart Van Assche}
2963*44704f69SBart Van Assche
2964*44704f69SBart Van Assche
2965*44704f69SBart Van Assche
2966*44704f69SBart Van Assche# func_write_libtool_object output_name pic_name nonpic_name
2967*44704f69SBart Van Assche# Create a libtool object file (analogous to a ".la" file),
2968*44704f69SBart Van Assche# but don't create it if we're doing a dry run.
2969*44704f69SBart Van Asschefunc_write_libtool_object ()
2970*44704f69SBart Van Assche{
2971*44704f69SBart Van Assche    write_libobj=$1
2972*44704f69SBart Van Assche    if test yes = "$build_libtool_libs"; then
2973*44704f69SBart Van Assche      write_lobj=\'$2\'
2974*44704f69SBart Van Assche    else
2975*44704f69SBart Van Assche      write_lobj=none
2976*44704f69SBart Van Assche    fi
2977*44704f69SBart Van Assche
2978*44704f69SBart Van Assche    if test yes = "$build_old_libs"; then
2979*44704f69SBart Van Assche      write_oldobj=\'$3\'
2980*44704f69SBart Van Assche    else
2981*44704f69SBart Van Assche      write_oldobj=none
2982*44704f69SBart Van Assche    fi
2983*44704f69SBart Van Assche
2984*44704f69SBart Van Assche    $opt_dry_run || {
2985*44704f69SBart Van Assche      cat >${write_libobj}T <<EOF
2986*44704f69SBart Van Assche# $write_libobj - a libtool object file
2987*44704f69SBart Van Assche# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2988*44704f69SBart Van Assche#
2989*44704f69SBart Van Assche# Please DO NOT delete this file!
2990*44704f69SBart Van Assche# It is necessary for linking the library.
2991*44704f69SBart Van Assche
2992*44704f69SBart Van Assche# Name of the PIC object.
2993*44704f69SBart Van Asschepic_object=$write_lobj
2994*44704f69SBart Van Assche
2995*44704f69SBart Van Assche# Name of the non-PIC object
2996*44704f69SBart Van Asschenon_pic_object=$write_oldobj
2997*44704f69SBart Van Assche
2998*44704f69SBart Van AsscheEOF
2999*44704f69SBart Van Assche      $MV "${write_libobj}T" "$write_libobj"
3000*44704f69SBart Van Assche    }
3001*44704f69SBart Van Assche}
3002*44704f69SBart Van Assche
3003*44704f69SBart Van Assche
3004*44704f69SBart Van Assche##################################################
3005*44704f69SBart Van Assche# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3006*44704f69SBart Van Assche##################################################
3007*44704f69SBart Van Assche
3008*44704f69SBart Van Assche# func_convert_core_file_wine_to_w32 ARG
3009*44704f69SBart Van Assche# Helper function used by file name conversion functions when $build is *nix,
3010*44704f69SBart Van Assche# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3011*44704f69SBart Van Assche# correctly configured wine environment available, with the winepath program
3012*44704f69SBart Van Assche# in $build's $PATH.
3013*44704f69SBart Van Assche#
3014*44704f69SBart Van Assche# ARG is the $build file name to be converted to w32 format.
3015*44704f69SBart Van Assche# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3016*44704f69SBart Van Assche# be empty on error (or when ARG is empty)
3017*44704f69SBart Van Asschefunc_convert_core_file_wine_to_w32 ()
3018*44704f69SBart Van Assche{
3019*44704f69SBart Van Assche  $debug_cmd
3020*44704f69SBart Van Assche
3021*44704f69SBart Van Assche  func_convert_core_file_wine_to_w32_result=$1
3022*44704f69SBart Van Assche  if test -n "$1"; then
3023*44704f69SBart Van Assche    # Unfortunately, winepath does not exit with a non-zero error code, so we
3024*44704f69SBart Van Assche    # are forced to check the contents of stdout. On the other hand, if the
3025*44704f69SBart Van Assche    # command is not found, the shell will set an exit code of 127 and print
3026*44704f69SBart Van Assche    # *an error message* to stdout. So we must check for both error code of
3027*44704f69SBart Van Assche    # zero AND non-empty stdout, which explains the odd construction:
3028*44704f69SBart Van Assche    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3029*44704f69SBart Van Assche    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3030*44704f69SBart Van Assche      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3031*44704f69SBart Van Assche        $SED -e "$sed_naive_backslashify"`
3032*44704f69SBart Van Assche    else
3033*44704f69SBart Van Assche      func_convert_core_file_wine_to_w32_result=
3034*44704f69SBart Van Assche    fi
3035*44704f69SBart Van Assche  fi
3036*44704f69SBart Van Assche}
3037*44704f69SBart Van Assche# end: func_convert_core_file_wine_to_w32
3038*44704f69SBart Van Assche
3039*44704f69SBart Van Assche
3040*44704f69SBart Van Assche# func_convert_core_path_wine_to_w32 ARG
3041*44704f69SBart Van Assche# Helper function used by path conversion functions when $build is *nix, and
3042*44704f69SBart Van Assche# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3043*44704f69SBart Van Assche# configured wine environment available, with the winepath program in $build's
3044*44704f69SBart Van Assche# $PATH. Assumes ARG has no leading or trailing path separator characters.
3045*44704f69SBart Van Assche#
3046*44704f69SBart Van Assche# ARG is path to be converted from $build format to win32.
3047*44704f69SBart Van Assche# Result is available in $func_convert_core_path_wine_to_w32_result.
3048*44704f69SBart Van Assche# Unconvertible file (directory) names in ARG are skipped; if no directory names
3049*44704f69SBart Van Assche# are convertible, then the result may be empty.
3050*44704f69SBart Van Asschefunc_convert_core_path_wine_to_w32 ()
3051*44704f69SBart Van Assche{
3052*44704f69SBart Van Assche  $debug_cmd
3053*44704f69SBart Van Assche
3054*44704f69SBart Van Assche  # unfortunately, winepath doesn't convert paths, only file names
3055*44704f69SBart Van Assche  func_convert_core_path_wine_to_w32_result=
3056*44704f69SBart Van Assche  if test -n "$1"; then
3057*44704f69SBart Van Assche    oldIFS=$IFS
3058*44704f69SBart Van Assche    IFS=:
3059*44704f69SBart Van Assche    for func_convert_core_path_wine_to_w32_f in $1; do
3060*44704f69SBart Van Assche      IFS=$oldIFS
3061*44704f69SBart Van Assche      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3062*44704f69SBart Van Assche      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3063*44704f69SBart Van Assche        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3064*44704f69SBart Van Assche          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3065*44704f69SBart Van Assche        else
3066*44704f69SBart Van Assche          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3067*44704f69SBart Van Assche        fi
3068*44704f69SBart Van Assche      fi
3069*44704f69SBart Van Assche    done
3070*44704f69SBart Van Assche    IFS=$oldIFS
3071*44704f69SBart Van Assche  fi
3072*44704f69SBart Van Assche}
3073*44704f69SBart Van Assche# end: func_convert_core_path_wine_to_w32
3074*44704f69SBart Van Assche
3075*44704f69SBart Van Assche
3076*44704f69SBart Van Assche# func_cygpath ARGS...
3077*44704f69SBart Van Assche# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3078*44704f69SBart Van Assche# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3079*44704f69SBart Van Assche# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3080*44704f69SBart Van Assche# (2), returns the Cygwin file name or path in func_cygpath_result (input
3081*44704f69SBart Van Assche# file name or path is assumed to be in w32 format, as previously converted
3082*44704f69SBart Van Assche# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3083*44704f69SBart Van Assche# or path in func_cygpath_result (input file name or path is assumed to be in
3084*44704f69SBart Van Assche# Cygwin format). Returns an empty string on error.
3085*44704f69SBart Van Assche#
3086*44704f69SBart Van Assche# ARGS are passed to cygpath, with the last one being the file name or path to
3087*44704f69SBart Van Assche# be converted.
3088*44704f69SBart Van Assche#
3089*44704f69SBart Van Assche# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3090*44704f69SBart Van Assche# environment variable; do not put it in $PATH.
3091*44704f69SBart Van Asschefunc_cygpath ()
3092*44704f69SBart Van Assche{
3093*44704f69SBart Van Assche  $debug_cmd
3094*44704f69SBart Van Assche
3095*44704f69SBart Van Assche  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3096*44704f69SBart Van Assche    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3097*44704f69SBart Van Assche    if test "$?" -ne 0; then
3098*44704f69SBart Van Assche      # on failure, ensure result is empty
3099*44704f69SBart Van Assche      func_cygpath_result=
3100*44704f69SBart Van Assche    fi
3101*44704f69SBart Van Assche  else
3102*44704f69SBart Van Assche    func_cygpath_result=
3103*44704f69SBart Van Assche    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3104*44704f69SBart Van Assche  fi
3105*44704f69SBart Van Assche}
3106*44704f69SBart Van Assche#end: func_cygpath
3107*44704f69SBart Van Assche
3108*44704f69SBart Van Assche
3109*44704f69SBart Van Assche# func_convert_core_msys_to_w32 ARG
3110*44704f69SBart Van Assche# Convert file name or path ARG from MSYS format to w32 format.  Return
3111*44704f69SBart Van Assche# result in func_convert_core_msys_to_w32_result.
3112*44704f69SBart Van Asschefunc_convert_core_msys_to_w32 ()
3113*44704f69SBart Van Assche{
3114*44704f69SBart Van Assche  $debug_cmd
3115*44704f69SBart Van Assche
3116*44704f69SBart Van Assche  # awkward: cmd appends spaces to result
3117*44704f69SBart Van Assche  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3118*44704f69SBart Van Assche    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3119*44704f69SBart Van Assche}
3120*44704f69SBart Van Assche#end: func_convert_core_msys_to_w32
3121*44704f69SBart Van Assche
3122*44704f69SBart Van Assche
3123*44704f69SBart Van Assche# func_convert_file_check ARG1 ARG2
3124*44704f69SBart Van Assche# Verify that ARG1 (a file name in $build format) was converted to $host
3125*44704f69SBart Van Assche# format in ARG2. Otherwise, emit an error message, but continue (resetting
3126*44704f69SBart Van Assche# func_to_host_file_result to ARG1).
3127*44704f69SBart Van Asschefunc_convert_file_check ()
3128*44704f69SBart Van Assche{
3129*44704f69SBart Van Assche  $debug_cmd
3130*44704f69SBart Van Assche
3131*44704f69SBart Van Assche  if test -z "$2" && test -n "$1"; then
3132*44704f69SBart Van Assche    func_error "Could not determine host file name corresponding to"
3133*44704f69SBart Van Assche    func_error "  '$1'"
3134*44704f69SBart Van Assche    func_error "Continuing, but uninstalled executables may not work."
3135*44704f69SBart Van Assche    # Fallback:
3136*44704f69SBart Van Assche    func_to_host_file_result=$1
3137*44704f69SBart Van Assche  fi
3138*44704f69SBart Van Assche}
3139*44704f69SBart Van Assche# end func_convert_file_check
3140*44704f69SBart Van Assche
3141*44704f69SBart Van Assche
3142*44704f69SBart Van Assche# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3143*44704f69SBart Van Assche# Verify that FROM_PATH (a path in $build format) was converted to $host
3144*44704f69SBart Van Assche# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3145*44704f69SBart Van Assche# func_to_host_file_result to a simplistic fallback value (see below).
3146*44704f69SBart Van Asschefunc_convert_path_check ()
3147*44704f69SBart Van Assche{
3148*44704f69SBart Van Assche  $debug_cmd
3149*44704f69SBart Van Assche
3150*44704f69SBart Van Assche  if test -z "$4" && test -n "$3"; then
3151*44704f69SBart Van Assche    func_error "Could not determine the host path corresponding to"
3152*44704f69SBart Van Assche    func_error "  '$3'"
3153*44704f69SBart Van Assche    func_error "Continuing, but uninstalled executables may not work."
3154*44704f69SBart Van Assche    # Fallback.  This is a deliberately simplistic "conversion" and
3155*44704f69SBart Van Assche    # should not be "improved".  See libtool.info.
3156*44704f69SBart Van Assche    if test "x$1" != "x$2"; then
3157*44704f69SBart Van Assche      lt_replace_pathsep_chars="s|$1|$2|g"
3158*44704f69SBart Van Assche      func_to_host_path_result=`echo "$3" |
3159*44704f69SBart Van Assche        $SED -e "$lt_replace_pathsep_chars"`
3160*44704f69SBart Van Assche    else
3161*44704f69SBart Van Assche      func_to_host_path_result=$3
3162*44704f69SBart Van Assche    fi
3163*44704f69SBart Van Assche  fi
3164*44704f69SBart Van Assche}
3165*44704f69SBart Van Assche# end func_convert_path_check
3166*44704f69SBart Van Assche
3167*44704f69SBart Van Assche
3168*44704f69SBart Van Assche# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3169*44704f69SBart Van Assche# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3170*44704f69SBart Van Assche# and appending REPL if ORIG matches BACKPAT.
3171*44704f69SBart Van Asschefunc_convert_path_front_back_pathsep ()
3172*44704f69SBart Van Assche{
3173*44704f69SBart Van Assche  $debug_cmd
3174*44704f69SBart Van Assche
3175*44704f69SBart Van Assche  case $4 in
3176*44704f69SBart Van Assche  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3177*44704f69SBart Van Assche    ;;
3178*44704f69SBart Van Assche  esac
3179*44704f69SBart Van Assche  case $4 in
3180*44704f69SBart Van Assche  $2 ) func_append func_to_host_path_result "$3"
3181*44704f69SBart Van Assche    ;;
3182*44704f69SBart Van Assche  esac
3183*44704f69SBart Van Assche}
3184*44704f69SBart Van Assche# end func_convert_path_front_back_pathsep
3185*44704f69SBart Van Assche
3186*44704f69SBart Van Assche
3187*44704f69SBart Van Assche##################################################
3188*44704f69SBart Van Assche# $build to $host FILE NAME CONVERSION FUNCTIONS #
3189*44704f69SBart Van Assche##################################################
3190*44704f69SBart Van Assche# invoked via '$to_host_file_cmd ARG'
3191*44704f69SBart Van Assche#
3192*44704f69SBart Van Assche# In each case, ARG is the path to be converted from $build to $host format.
3193*44704f69SBart Van Assche# Result will be available in $func_to_host_file_result.
3194*44704f69SBart Van Assche
3195*44704f69SBart Van Assche
3196*44704f69SBart Van Assche# func_to_host_file ARG
3197*44704f69SBart Van Assche# Converts the file name ARG from $build format to $host format. Return result
3198*44704f69SBart Van Assche# in func_to_host_file_result.
3199*44704f69SBart Van Asschefunc_to_host_file ()
3200*44704f69SBart Van Assche{
3201*44704f69SBart Van Assche  $debug_cmd
3202*44704f69SBart Van Assche
3203*44704f69SBart Van Assche  $to_host_file_cmd "$1"
3204*44704f69SBart Van Assche}
3205*44704f69SBart Van Assche# end func_to_host_file
3206*44704f69SBart Van Assche
3207*44704f69SBart Van Assche
3208*44704f69SBart Van Assche# func_to_tool_file ARG LAZY
3209*44704f69SBart Van Assche# converts the file name ARG from $build format to toolchain format. Return
3210*44704f69SBart Van Assche# result in func_to_tool_file_result.  If the conversion in use is listed
3211*44704f69SBart Van Assche# in (the comma separated) LAZY, no conversion takes place.
3212*44704f69SBart Van Asschefunc_to_tool_file ()
3213*44704f69SBart Van Assche{
3214*44704f69SBart Van Assche  $debug_cmd
3215*44704f69SBart Van Assche
3216*44704f69SBart Van Assche  case ,$2, in
3217*44704f69SBart Van Assche    *,"$to_tool_file_cmd",*)
3218*44704f69SBart Van Assche      func_to_tool_file_result=$1
3219*44704f69SBart Van Assche      ;;
3220*44704f69SBart Van Assche    *)
3221*44704f69SBart Van Assche      $to_tool_file_cmd "$1"
3222*44704f69SBart Van Assche      func_to_tool_file_result=$func_to_host_file_result
3223*44704f69SBart Van Assche      ;;
3224*44704f69SBart Van Assche  esac
3225*44704f69SBart Van Assche}
3226*44704f69SBart Van Assche# end func_to_tool_file
3227*44704f69SBart Van Assche
3228*44704f69SBart Van Assche
3229*44704f69SBart Van Assche# func_convert_file_noop ARG
3230*44704f69SBart Van Assche# Copy ARG to func_to_host_file_result.
3231*44704f69SBart Van Asschefunc_convert_file_noop ()
3232*44704f69SBart Van Assche{
3233*44704f69SBart Van Assche  func_to_host_file_result=$1
3234*44704f69SBart Van Assche}
3235*44704f69SBart Van Assche# end func_convert_file_noop
3236*44704f69SBart Van Assche
3237*44704f69SBart Van Assche
3238*44704f69SBart Van Assche# func_convert_file_msys_to_w32 ARG
3239*44704f69SBart Van Assche# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3240*44704f69SBart Van Assche# conversion to w32 is not available inside the cwrapper.  Returns result in
3241*44704f69SBart Van Assche# func_to_host_file_result.
3242*44704f69SBart Van Asschefunc_convert_file_msys_to_w32 ()
3243*44704f69SBart Van Assche{
3244*44704f69SBart Van Assche  $debug_cmd
3245*44704f69SBart Van Assche
3246*44704f69SBart Van Assche  func_to_host_file_result=$1
3247*44704f69SBart Van Assche  if test -n "$1"; then
3248*44704f69SBart Van Assche    func_convert_core_msys_to_w32 "$1"
3249*44704f69SBart Van Assche    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3250*44704f69SBart Van Assche  fi
3251*44704f69SBart Van Assche  func_convert_file_check "$1" "$func_to_host_file_result"
3252*44704f69SBart Van Assche}
3253*44704f69SBart Van Assche# end func_convert_file_msys_to_w32
3254*44704f69SBart Van Assche
3255*44704f69SBart Van Assche
3256*44704f69SBart Van Assche# func_convert_file_cygwin_to_w32 ARG
3257*44704f69SBart Van Assche# Convert file name ARG from Cygwin to w32 format.  Returns result in
3258*44704f69SBart Van Assche# func_to_host_file_result.
3259*44704f69SBart Van Asschefunc_convert_file_cygwin_to_w32 ()
3260*44704f69SBart Van Assche{
3261*44704f69SBart Van Assche  $debug_cmd
3262*44704f69SBart Van Assche
3263*44704f69SBart Van Assche  func_to_host_file_result=$1
3264*44704f69SBart Van Assche  if test -n "$1"; then
3265*44704f69SBart Van Assche    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3266*44704f69SBart Van Assche    # LT_CYGPATH in this case.
3267*44704f69SBart Van Assche    func_to_host_file_result=`cygpath -m "$1"`
3268*44704f69SBart Van Assche  fi
3269*44704f69SBart Van Assche  func_convert_file_check "$1" "$func_to_host_file_result"
3270*44704f69SBart Van Assche}
3271*44704f69SBart Van Assche# end func_convert_file_cygwin_to_w32
3272*44704f69SBart Van Assche
3273*44704f69SBart Van Assche
3274*44704f69SBart Van Assche# func_convert_file_nix_to_w32 ARG
3275*44704f69SBart Van Assche# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3276*44704f69SBart Van Assche# and a working winepath. Returns result in func_to_host_file_result.
3277*44704f69SBart Van Asschefunc_convert_file_nix_to_w32 ()
3278*44704f69SBart Van Assche{
3279*44704f69SBart Van Assche  $debug_cmd
3280*44704f69SBart Van Assche
3281*44704f69SBart Van Assche  func_to_host_file_result=$1
3282*44704f69SBart Van Assche  if test -n "$1"; then
3283*44704f69SBart Van Assche    func_convert_core_file_wine_to_w32 "$1"
3284*44704f69SBart Van Assche    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3285*44704f69SBart Van Assche  fi
3286*44704f69SBart Van Assche  func_convert_file_check "$1" "$func_to_host_file_result"
3287*44704f69SBart Van Assche}
3288*44704f69SBart Van Assche# end func_convert_file_nix_to_w32
3289*44704f69SBart Van Assche
3290*44704f69SBart Van Assche
3291*44704f69SBart Van Assche# func_convert_file_msys_to_cygwin ARG
3292*44704f69SBart Van Assche# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3293*44704f69SBart Van Assche# Returns result in func_to_host_file_result.
3294*44704f69SBart Van Asschefunc_convert_file_msys_to_cygwin ()
3295*44704f69SBart Van Assche{
3296*44704f69SBart Van Assche  $debug_cmd
3297*44704f69SBart Van Assche
3298*44704f69SBart Van Assche  func_to_host_file_result=$1
3299*44704f69SBart Van Assche  if test -n "$1"; then
3300*44704f69SBart Van Assche    func_convert_core_msys_to_w32 "$1"
3301*44704f69SBart Van Assche    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3302*44704f69SBart Van Assche    func_to_host_file_result=$func_cygpath_result
3303*44704f69SBart Van Assche  fi
3304*44704f69SBart Van Assche  func_convert_file_check "$1" "$func_to_host_file_result"
3305*44704f69SBart Van Assche}
3306*44704f69SBart Van Assche# end func_convert_file_msys_to_cygwin
3307*44704f69SBart Van Assche
3308*44704f69SBart Van Assche
3309*44704f69SBart Van Assche# func_convert_file_nix_to_cygwin ARG
3310*44704f69SBart Van Assche# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3311*44704f69SBart Van Assche# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3312*44704f69SBart Van Assche# in func_to_host_file_result.
3313*44704f69SBart Van Asschefunc_convert_file_nix_to_cygwin ()
3314*44704f69SBart Van Assche{
3315*44704f69SBart Van Assche  $debug_cmd
3316*44704f69SBart Van Assche
3317*44704f69SBart Van Assche  func_to_host_file_result=$1
3318*44704f69SBart Van Assche  if test -n "$1"; then
3319*44704f69SBart Van Assche    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3320*44704f69SBart Van Assche    func_convert_core_file_wine_to_w32 "$1"
3321*44704f69SBart Van Assche    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3322*44704f69SBart Van Assche    func_to_host_file_result=$func_cygpath_result
3323*44704f69SBart Van Assche  fi
3324*44704f69SBart Van Assche  func_convert_file_check "$1" "$func_to_host_file_result"
3325*44704f69SBart Van Assche}
3326*44704f69SBart Van Assche# end func_convert_file_nix_to_cygwin
3327*44704f69SBart Van Assche
3328*44704f69SBart Van Assche
3329*44704f69SBart Van Assche#############################################
3330*44704f69SBart Van Assche# $build to $host PATH CONVERSION FUNCTIONS #
3331*44704f69SBart Van Assche#############################################
3332*44704f69SBart Van Assche# invoked via '$to_host_path_cmd ARG'
3333*44704f69SBart Van Assche#
3334*44704f69SBart Van Assche# In each case, ARG is the path to be converted from $build to $host format.
3335*44704f69SBart Van Assche# The result will be available in $func_to_host_path_result.
3336*44704f69SBart Van Assche#
3337*44704f69SBart Van Assche# Path separators are also converted from $build format to $host format.  If
3338*44704f69SBart Van Assche# ARG begins or ends with a path separator character, it is preserved (but
3339*44704f69SBart Van Assche# converted to $host format) on output.
3340*44704f69SBart Van Assche#
3341*44704f69SBart Van Assche# All path conversion functions are named using the following convention:
3342*44704f69SBart Van Assche#   file name conversion function    : func_convert_file_X_to_Y ()
3343*44704f69SBart Van Assche#   path conversion function         : func_convert_path_X_to_Y ()
3344*44704f69SBart Van Assche# where, for any given $build/$host combination the 'X_to_Y' value is the
3345*44704f69SBart Van Assche# same.  If conversion functions are added for new $build/$host combinations,
3346*44704f69SBart Van Assche# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3347*44704f69SBart Van Assche# will break.
3348*44704f69SBart Van Assche
3349*44704f69SBart Van Assche
3350*44704f69SBart Van Assche# func_init_to_host_path_cmd
3351*44704f69SBart Van Assche# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3352*44704f69SBart Van Assche# appropriate value, based on the value of $to_host_file_cmd.
3353*44704f69SBart Van Asscheto_host_path_cmd=
3354*44704f69SBart Van Asschefunc_init_to_host_path_cmd ()
3355*44704f69SBart Van Assche{
3356*44704f69SBart Van Assche  $debug_cmd
3357*44704f69SBart Van Assche
3358*44704f69SBart Van Assche  if test -z "$to_host_path_cmd"; then
3359*44704f69SBart Van Assche    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3360*44704f69SBart Van Assche    to_host_path_cmd=func_convert_path_$func_stripname_result
3361*44704f69SBart Van Assche  fi
3362*44704f69SBart Van Assche}
3363*44704f69SBart Van Assche
3364*44704f69SBart Van Assche
3365*44704f69SBart Van Assche# func_to_host_path ARG
3366*44704f69SBart Van Assche# Converts the path ARG from $build format to $host format. Return result
3367*44704f69SBart Van Assche# in func_to_host_path_result.
3368*44704f69SBart Van Asschefunc_to_host_path ()
3369*44704f69SBart Van Assche{
3370*44704f69SBart Van Assche  $debug_cmd
3371*44704f69SBart Van Assche
3372*44704f69SBart Van Assche  func_init_to_host_path_cmd
3373*44704f69SBart Van Assche  $to_host_path_cmd "$1"
3374*44704f69SBart Van Assche}
3375*44704f69SBart Van Assche# end func_to_host_path
3376*44704f69SBart Van Assche
3377*44704f69SBart Van Assche
3378*44704f69SBart Van Assche# func_convert_path_noop ARG
3379*44704f69SBart Van Assche# Copy ARG to func_to_host_path_result.
3380*44704f69SBart Van Asschefunc_convert_path_noop ()
3381*44704f69SBart Van Assche{
3382*44704f69SBart Van Assche  func_to_host_path_result=$1
3383*44704f69SBart Van Assche}
3384*44704f69SBart Van Assche# end func_convert_path_noop
3385*44704f69SBart Van Assche
3386*44704f69SBart Van Assche
3387*44704f69SBart Van Assche# func_convert_path_msys_to_w32 ARG
3388*44704f69SBart Van Assche# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3389*44704f69SBart Van Assche# conversion to w32 is not available inside the cwrapper.  Returns result in
3390*44704f69SBart Van Assche# func_to_host_path_result.
3391*44704f69SBart Van Asschefunc_convert_path_msys_to_w32 ()
3392*44704f69SBart Van Assche{
3393*44704f69SBart Van Assche  $debug_cmd
3394*44704f69SBart Van Assche
3395*44704f69SBart Van Assche  func_to_host_path_result=$1
3396*44704f69SBart Van Assche  if test -n "$1"; then
3397*44704f69SBart Van Assche    # Remove leading and trailing path separator characters from ARG.  MSYS
3398*44704f69SBart Van Assche    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3399*44704f69SBart Van Assche    # and winepath ignores them completely.
3400*44704f69SBart Van Assche    func_stripname : : "$1"
3401*44704f69SBart Van Assche    func_to_host_path_tmp1=$func_stripname_result
3402*44704f69SBart Van Assche    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3403*44704f69SBart Van Assche    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3404*44704f69SBart Van Assche    func_convert_path_check : ";" \
3405*44704f69SBart Van Assche      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3406*44704f69SBart Van Assche    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3407*44704f69SBart Van Assche  fi
3408*44704f69SBart Van Assche}
3409*44704f69SBart Van Assche# end func_convert_path_msys_to_w32
3410*44704f69SBart Van Assche
3411*44704f69SBart Van Assche
3412*44704f69SBart Van Assche# func_convert_path_cygwin_to_w32 ARG
3413*44704f69SBart Van Assche# Convert path ARG from Cygwin to w32 format.  Returns result in
3414*44704f69SBart Van Assche# func_to_host_file_result.
3415*44704f69SBart Van Asschefunc_convert_path_cygwin_to_w32 ()
3416*44704f69SBart Van Assche{
3417*44704f69SBart Van Assche  $debug_cmd
3418*44704f69SBart Van Assche
3419*44704f69SBart Van Assche  func_to_host_path_result=$1
3420*44704f69SBart Van Assche  if test -n "$1"; then
3421*44704f69SBart Van Assche    # See func_convert_path_msys_to_w32:
3422*44704f69SBart Van Assche    func_stripname : : "$1"
3423*44704f69SBart Van Assche    func_to_host_path_tmp1=$func_stripname_result
3424*44704f69SBart Van Assche    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3425*44704f69SBart Van Assche    func_convert_path_check : ";" \
3426*44704f69SBart Van Assche      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3427*44704f69SBart Van Assche    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3428*44704f69SBart Van Assche  fi
3429*44704f69SBart Van Assche}
3430*44704f69SBart Van Assche# end func_convert_path_cygwin_to_w32
3431*44704f69SBart Van Assche
3432*44704f69SBart Van Assche
3433*44704f69SBart Van Assche# func_convert_path_nix_to_w32 ARG
3434*44704f69SBart Van Assche# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3435*44704f69SBart Van Assche# a working winepath.  Returns result in func_to_host_file_result.
3436*44704f69SBart Van Asschefunc_convert_path_nix_to_w32 ()
3437*44704f69SBart Van Assche{
3438*44704f69SBart Van Assche  $debug_cmd
3439*44704f69SBart Van Assche
3440*44704f69SBart Van Assche  func_to_host_path_result=$1
3441*44704f69SBart Van Assche  if test -n "$1"; then
3442*44704f69SBart Van Assche    # See func_convert_path_msys_to_w32:
3443*44704f69SBart Van Assche    func_stripname : : "$1"
3444*44704f69SBart Van Assche    func_to_host_path_tmp1=$func_stripname_result
3445*44704f69SBart Van Assche    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3446*44704f69SBart Van Assche    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3447*44704f69SBart Van Assche    func_convert_path_check : ";" \
3448*44704f69SBart Van Assche      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3449*44704f69SBart Van Assche    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3450*44704f69SBart Van Assche  fi
3451*44704f69SBart Van Assche}
3452*44704f69SBart Van Assche# end func_convert_path_nix_to_w32
3453*44704f69SBart Van Assche
3454*44704f69SBart Van Assche
3455*44704f69SBart Van Assche# func_convert_path_msys_to_cygwin ARG
3456*44704f69SBart Van Assche# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3457*44704f69SBart Van Assche# Returns result in func_to_host_file_result.
3458*44704f69SBart Van Asschefunc_convert_path_msys_to_cygwin ()
3459*44704f69SBart Van Assche{
3460*44704f69SBart Van Assche  $debug_cmd
3461*44704f69SBart Van Assche
3462*44704f69SBart Van Assche  func_to_host_path_result=$1
3463*44704f69SBart Van Assche  if test -n "$1"; then
3464*44704f69SBart Van Assche    # See func_convert_path_msys_to_w32:
3465*44704f69SBart Van Assche    func_stripname : : "$1"
3466*44704f69SBart Van Assche    func_to_host_path_tmp1=$func_stripname_result
3467*44704f69SBart Van Assche    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3468*44704f69SBart Van Assche    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3469*44704f69SBart Van Assche    func_to_host_path_result=$func_cygpath_result
3470*44704f69SBart Van Assche    func_convert_path_check : : \
3471*44704f69SBart Van Assche      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3472*44704f69SBart Van Assche    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3473*44704f69SBart Van Assche  fi
3474*44704f69SBart Van Assche}
3475*44704f69SBart Van Assche# end func_convert_path_msys_to_cygwin
3476*44704f69SBart Van Assche
3477*44704f69SBart Van Assche
3478*44704f69SBart Van Assche# func_convert_path_nix_to_cygwin ARG
3479*44704f69SBart Van Assche# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3480*44704f69SBart Van Assche# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3481*44704f69SBart Van Assche# func_to_host_file_result.
3482*44704f69SBart Van Asschefunc_convert_path_nix_to_cygwin ()
3483*44704f69SBart Van Assche{
3484*44704f69SBart Van Assche  $debug_cmd
3485*44704f69SBart Van Assche
3486*44704f69SBart Van Assche  func_to_host_path_result=$1
3487*44704f69SBart Van Assche  if test -n "$1"; then
3488*44704f69SBart Van Assche    # Remove leading and trailing path separator characters from
3489*44704f69SBart Van Assche    # ARG. msys behavior is inconsistent here, cygpath turns them
3490*44704f69SBart Van Assche    # into '.;' and ';.', and winepath ignores them completely.
3491*44704f69SBart Van Assche    func_stripname : : "$1"
3492*44704f69SBart Van Assche    func_to_host_path_tmp1=$func_stripname_result
3493*44704f69SBart Van Assche    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3494*44704f69SBart Van Assche    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3495*44704f69SBart Van Assche    func_to_host_path_result=$func_cygpath_result
3496*44704f69SBart Van Assche    func_convert_path_check : : \
3497*44704f69SBart Van Assche      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3498*44704f69SBart Van Assche    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3499*44704f69SBart Van Assche  fi
3500*44704f69SBart Van Assche}
3501*44704f69SBart Van Assche# end func_convert_path_nix_to_cygwin
3502*44704f69SBart Van Assche
3503*44704f69SBart Van Assche
3504*44704f69SBart Van Assche# func_dll_def_p FILE
3505*44704f69SBart Van Assche# True iff FILE is a Windows DLL '.def' file.
3506*44704f69SBart Van Assche# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3507*44704f69SBart Van Asschefunc_dll_def_p ()
3508*44704f69SBart Van Assche{
3509*44704f69SBart Van Assche  $debug_cmd
3510*44704f69SBart Van Assche
3511*44704f69SBart Van Assche  func_dll_def_p_tmp=`$SED -n \
3512*44704f69SBart Van Assche    -e 's/^[	 ]*//' \
3513*44704f69SBart Van Assche    -e '/^\(;.*\)*$/d' \
3514*44704f69SBart Van Assche    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3515*44704f69SBart Van Assche    -e q \
3516*44704f69SBart Van Assche    "$1"`
3517*44704f69SBart Van Assche  test DEF = "$func_dll_def_p_tmp"
3518*44704f69SBart Van Assche}
3519*44704f69SBart Van Assche
3520*44704f69SBart Van Assche
3521*44704f69SBart Van Assche# func_mode_compile arg...
3522*44704f69SBart Van Asschefunc_mode_compile ()
3523*44704f69SBart Van Assche{
3524*44704f69SBart Van Assche    $debug_cmd
3525*44704f69SBart Van Assche
3526*44704f69SBart Van Assche    # Get the compilation command and the source file.
3527*44704f69SBart Van Assche    base_compile=
3528*44704f69SBart Van Assche    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3529*44704f69SBart Van Assche    suppress_opt=yes
3530*44704f69SBart Van Assche    suppress_output=
3531*44704f69SBart Van Assche    arg_mode=normal
3532*44704f69SBart Van Assche    libobj=
3533*44704f69SBart Van Assche    later=
3534*44704f69SBart Van Assche    pie_flag=
3535*44704f69SBart Van Assche
3536*44704f69SBart Van Assche    for arg
3537*44704f69SBart Van Assche    do
3538*44704f69SBart Van Assche      case $arg_mode in
3539*44704f69SBart Van Assche      arg  )
3540*44704f69SBart Van Assche	# do not "continue".  Instead, add this to base_compile
3541*44704f69SBart Van Assche	lastarg=$arg
3542*44704f69SBart Van Assche	arg_mode=normal
3543*44704f69SBart Van Assche	;;
3544*44704f69SBart Van Assche
3545*44704f69SBart Van Assche      target )
3546*44704f69SBart Van Assche	libobj=$arg
3547*44704f69SBart Van Assche	arg_mode=normal
3548*44704f69SBart Van Assche	continue
3549*44704f69SBart Van Assche	;;
3550*44704f69SBart Van Assche
3551*44704f69SBart Van Assche      normal )
3552*44704f69SBart Van Assche	# Accept any command-line options.
3553*44704f69SBart Van Assche	case $arg in
3554*44704f69SBart Van Assche	-o)
3555*44704f69SBart Van Assche	  test -n "$libobj" && \
3556*44704f69SBart Van Assche	    func_fatal_error "you cannot specify '-o' more than once"
3557*44704f69SBart Van Assche	  arg_mode=target
3558*44704f69SBart Van Assche	  continue
3559*44704f69SBart Van Assche	  ;;
3560*44704f69SBart Van Assche
3561*44704f69SBart Van Assche	-pie | -fpie | -fPIE)
3562*44704f69SBart Van Assche          func_append pie_flag " $arg"
3563*44704f69SBart Van Assche	  continue
3564*44704f69SBart Van Assche	  ;;
3565*44704f69SBart Van Assche
3566*44704f69SBart Van Assche	-shared | -static | -prefer-pic | -prefer-non-pic)
3567*44704f69SBart Van Assche	  func_append later " $arg"
3568*44704f69SBart Van Assche	  continue
3569*44704f69SBart Van Assche	  ;;
3570*44704f69SBart Van Assche
3571*44704f69SBart Van Assche	-no-suppress)
3572*44704f69SBart Van Assche	  suppress_opt=no
3573*44704f69SBart Van Assche	  continue
3574*44704f69SBart Van Assche	  ;;
3575*44704f69SBart Van Assche
3576*44704f69SBart Van Assche	-Xcompiler)
3577*44704f69SBart Van Assche	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3578*44704f69SBart Van Assche	  continue      #  The current "srcfile" will either be retained or
3579*44704f69SBart Van Assche	  ;;            #  replaced later.  I would guess that would be a bug.
3580*44704f69SBart Van Assche
3581*44704f69SBart Van Assche	-Wc,*)
3582*44704f69SBart Van Assche	  func_stripname '-Wc,' '' "$arg"
3583*44704f69SBart Van Assche	  args=$func_stripname_result
3584*44704f69SBart Van Assche	  lastarg=
3585*44704f69SBart Van Assche	  save_ifs=$IFS; IFS=,
3586*44704f69SBart Van Assche	  for arg in $args; do
3587*44704f69SBart Van Assche	    IFS=$save_ifs
3588*44704f69SBart Van Assche	    func_append_quoted lastarg "$arg"
3589*44704f69SBart Van Assche	  done
3590*44704f69SBart Van Assche	  IFS=$save_ifs
3591*44704f69SBart Van Assche	  func_stripname ' ' '' "$lastarg"
3592*44704f69SBart Van Assche	  lastarg=$func_stripname_result
3593*44704f69SBart Van Assche
3594*44704f69SBart Van Assche	  # Add the arguments to base_compile.
3595*44704f69SBart Van Assche	  func_append base_compile " $lastarg"
3596*44704f69SBart Van Assche	  continue
3597*44704f69SBart Van Assche	  ;;
3598*44704f69SBart Van Assche
3599*44704f69SBart Van Assche	*)
3600*44704f69SBart Van Assche	  # Accept the current argument as the source file.
3601*44704f69SBart Van Assche	  # The previous "srcfile" becomes the current argument.
3602*44704f69SBart Van Assche	  #
3603*44704f69SBart Van Assche	  lastarg=$srcfile
3604*44704f69SBart Van Assche	  srcfile=$arg
3605*44704f69SBart Van Assche	  ;;
3606*44704f69SBart Van Assche	esac  #  case $arg
3607*44704f69SBart Van Assche	;;
3608*44704f69SBart Van Assche      esac    #  case $arg_mode
3609*44704f69SBart Van Assche
3610*44704f69SBart Van Assche      # Aesthetically quote the previous argument.
3611*44704f69SBart Van Assche      func_append_quoted base_compile "$lastarg"
3612*44704f69SBart Van Assche    done # for arg
3613*44704f69SBart Van Assche
3614*44704f69SBart Van Assche    case $arg_mode in
3615*44704f69SBart Van Assche    arg)
3616*44704f69SBart Van Assche      func_fatal_error "you must specify an argument for -Xcompile"
3617*44704f69SBart Van Assche      ;;
3618*44704f69SBart Van Assche    target)
3619*44704f69SBart Van Assche      func_fatal_error "you must specify a target with '-o'"
3620*44704f69SBart Van Assche      ;;
3621*44704f69SBart Van Assche    *)
3622*44704f69SBart Van Assche      # Get the name of the library object.
3623*44704f69SBart Van Assche      test -z "$libobj" && {
3624*44704f69SBart Van Assche	func_basename "$srcfile"
3625*44704f69SBart Van Assche	libobj=$func_basename_result
3626*44704f69SBart Van Assche      }
3627*44704f69SBart Van Assche      ;;
3628*44704f69SBart Van Assche    esac
3629*44704f69SBart Van Assche
3630*44704f69SBart Van Assche    # Recognize several different file suffixes.
3631*44704f69SBart Van Assche    # If the user specifies -o file.o, it is replaced with file.lo
3632*44704f69SBart Van Assche    case $libobj in
3633*44704f69SBart Van Assche    *.[cCFSifmso] | \
3634*44704f69SBart Van Assche    *.ada | *.adb | *.ads | *.asm | \
3635*44704f69SBart Van Assche    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3636*44704f69SBart Van Assche    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3637*44704f69SBart Van Assche      func_xform "$libobj"
3638*44704f69SBart Van Assche      libobj=$func_xform_result
3639*44704f69SBart Van Assche      ;;
3640*44704f69SBart Van Assche    esac
3641*44704f69SBart Van Assche
3642*44704f69SBart Van Assche    case $libobj in
3643*44704f69SBart Van Assche    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3644*44704f69SBart Van Assche    *)
3645*44704f69SBart Van Assche      func_fatal_error "cannot determine name of library object from '$libobj'"
3646*44704f69SBart Van Assche      ;;
3647*44704f69SBart Van Assche    esac
3648*44704f69SBart Van Assche
3649*44704f69SBart Van Assche    func_infer_tag $base_compile
3650*44704f69SBart Van Assche
3651*44704f69SBart Van Assche    for arg in $later; do
3652*44704f69SBart Van Assche      case $arg in
3653*44704f69SBart Van Assche      -shared)
3654*44704f69SBart Van Assche	test yes = "$build_libtool_libs" \
3655*44704f69SBart Van Assche	  || func_fatal_configuration "cannot build a shared library"
3656*44704f69SBart Van Assche	build_old_libs=no
3657*44704f69SBart Van Assche	continue
3658*44704f69SBart Van Assche	;;
3659*44704f69SBart Van Assche
3660*44704f69SBart Van Assche      -static)
3661*44704f69SBart Van Assche	build_libtool_libs=no
3662*44704f69SBart Van Assche	build_old_libs=yes
3663*44704f69SBart Van Assche	continue
3664*44704f69SBart Van Assche	;;
3665*44704f69SBart Van Assche
3666*44704f69SBart Van Assche      -prefer-pic)
3667*44704f69SBart Van Assche	pic_mode=yes
3668*44704f69SBart Van Assche	continue
3669*44704f69SBart Van Assche	;;
3670*44704f69SBart Van Assche
3671*44704f69SBart Van Assche      -prefer-non-pic)
3672*44704f69SBart Van Assche	pic_mode=no
3673*44704f69SBart Van Assche	continue
3674*44704f69SBart Van Assche	;;
3675*44704f69SBart Van Assche      esac
3676*44704f69SBart Van Assche    done
3677*44704f69SBart Van Assche
3678*44704f69SBart Van Assche    func_quote_arg pretty "$libobj"
3679*44704f69SBart Van Assche    test "X$libobj" != "X$func_quote_arg_result" \
3680*44704f69SBart Van Assche      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3681*44704f69SBart Van Assche      && func_warning "libobj name '$libobj' may not contain shell special characters."
3682*44704f69SBart Van Assche    func_dirname_and_basename "$obj" "/" ""
3683*44704f69SBart Van Assche    objname=$func_basename_result
3684*44704f69SBart Van Assche    xdir=$func_dirname_result
3685*44704f69SBart Van Assche    lobj=$xdir$objdir/$objname
3686*44704f69SBart Van Assche
3687*44704f69SBart Van Assche    test -z "$base_compile" && \
3688*44704f69SBart Van Assche      func_fatal_help "you must specify a compilation command"
3689*44704f69SBart Van Assche
3690*44704f69SBart Van Assche    # Delete any leftover library objects.
3691*44704f69SBart Van Assche    if test yes = "$build_old_libs"; then
3692*44704f69SBart Van Assche      removelist="$obj $lobj $libobj ${libobj}T"
3693*44704f69SBart Van Assche    else
3694*44704f69SBart Van Assche      removelist="$lobj $libobj ${libobj}T"
3695*44704f69SBart Van Assche    fi
3696*44704f69SBart Van Assche
3697*44704f69SBart Van Assche    # On Cygwin there's no "real" PIC flag so we must build both object types
3698*44704f69SBart Van Assche    case $host_os in
3699*44704f69SBart Van Assche    cygwin* | mingw* | pw32* | os2* | cegcc*)
3700*44704f69SBart Van Assche      pic_mode=default
3701*44704f69SBart Van Assche      ;;
3702*44704f69SBart Van Assche    esac
3703*44704f69SBart Van Assche    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3704*44704f69SBart Van Assche      # non-PIC code in shared libraries is not supported
3705*44704f69SBart Van Assche      pic_mode=default
3706*44704f69SBart Van Assche    fi
3707*44704f69SBart Van Assche
3708*44704f69SBart Van Assche    # Calculate the filename of the output object if compiler does
3709*44704f69SBart Van Assche    # not support -o with -c
3710*44704f69SBart Van Assche    if test no = "$compiler_c_o"; then
3711*44704f69SBart Van Assche      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3712*44704f69SBart Van Assche      lockfile=$output_obj.lock
3713*44704f69SBart Van Assche    else
3714*44704f69SBart Van Assche      output_obj=
3715*44704f69SBart Van Assche      need_locks=no
3716*44704f69SBart Van Assche      lockfile=
3717*44704f69SBart Van Assche    fi
3718*44704f69SBart Van Assche
3719*44704f69SBart Van Assche    # Lock this critical section if it is needed
3720*44704f69SBart Van Assche    # We use this script file to make the link, it avoids creating a new file
3721*44704f69SBart Van Assche    if test yes = "$need_locks"; then
3722*44704f69SBart Van Assche      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3723*44704f69SBart Van Assche	func_echo "Waiting for $lockfile to be removed"
3724*44704f69SBart Van Assche	sleep 2
3725*44704f69SBart Van Assche      done
3726*44704f69SBart Van Assche    elif test warn = "$need_locks"; then
3727*44704f69SBart Van Assche      if test -f "$lockfile"; then
3728*44704f69SBart Van Assche	$ECHO "\
3729*44704f69SBart Van Assche*** ERROR, $lockfile exists and contains:
3730*44704f69SBart Van Assche`cat $lockfile 2>/dev/null`
3731*44704f69SBart Van Assche
3732*44704f69SBart Van AsscheThis indicates that another process is trying to use the same
3733*44704f69SBart Van Asschetemporary object file, and libtool could not work around it because
3734*44704f69SBart Van Asscheyour compiler does not support '-c' and '-o' together.  If you
3735*44704f69SBart Van Asscherepeat this compilation, it may succeed, by chance, but you had better
3736*44704f69SBart Van Asscheavoid parallel builds (make -j) in this platform, or get a better
3737*44704f69SBart Van Asschecompiler."
3738*44704f69SBart Van Assche
3739*44704f69SBart Van Assche	$opt_dry_run || $RM $removelist
3740*44704f69SBart Van Assche	exit $EXIT_FAILURE
3741*44704f69SBart Van Assche      fi
3742*44704f69SBart Van Assche      func_append removelist " $output_obj"
3743*44704f69SBart Van Assche      $ECHO "$srcfile" > "$lockfile"
3744*44704f69SBart Van Assche    fi
3745*44704f69SBart Van Assche
3746*44704f69SBart Van Assche    $opt_dry_run || $RM $removelist
3747*44704f69SBart Van Assche    func_append removelist " $lockfile"
3748*44704f69SBart Van Assche    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3749*44704f69SBart Van Assche
3750*44704f69SBart Van Assche    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3751*44704f69SBart Van Assche    srcfile=$func_to_tool_file_result
3752*44704f69SBart Van Assche    func_quote_arg pretty "$srcfile"
3753*44704f69SBart Van Assche    qsrcfile=$func_quote_arg_result
3754*44704f69SBart Van Assche
3755*44704f69SBart Van Assche    # Only build a PIC object if we are building libtool libraries.
3756*44704f69SBart Van Assche    if test yes = "$build_libtool_libs"; then
3757*44704f69SBart Van Assche      # Without this assignment, base_compile gets emptied.
3758*44704f69SBart Van Assche      fbsd_hideous_sh_bug=$base_compile
3759*44704f69SBart Van Assche
3760*44704f69SBart Van Assche      if test no != "$pic_mode"; then
3761*44704f69SBart Van Assche	command="$base_compile $qsrcfile $pic_flag"
3762*44704f69SBart Van Assche      else
3763*44704f69SBart Van Assche	# Don't build PIC code
3764*44704f69SBart Van Assche	command="$base_compile $qsrcfile"
3765*44704f69SBart Van Assche      fi
3766*44704f69SBart Van Assche
3767*44704f69SBart Van Assche      func_mkdir_p "$xdir$objdir"
3768*44704f69SBart Van Assche
3769*44704f69SBart Van Assche      if test -z "$output_obj"; then
3770*44704f69SBart Van Assche	# Place PIC objects in $objdir
3771*44704f69SBart Van Assche	func_append command " -o $lobj"
3772*44704f69SBart Van Assche      fi
3773*44704f69SBart Van Assche
3774*44704f69SBart Van Assche      func_show_eval_locale "$command"	\
3775*44704f69SBart Van Assche          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3776*44704f69SBart Van Assche
3777*44704f69SBart Van Assche      if test warn = "$need_locks" &&
3778*44704f69SBart Van Assche	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3779*44704f69SBart Van Assche	$ECHO "\
3780*44704f69SBart Van Assche*** ERROR, $lockfile contains:
3781*44704f69SBart Van Assche`cat $lockfile 2>/dev/null`
3782*44704f69SBart Van Assche
3783*44704f69SBart Van Asschebut it should contain:
3784*44704f69SBart Van Assche$srcfile
3785*44704f69SBart Van Assche
3786*44704f69SBart Van AsscheThis indicates that another process is trying to use the same
3787*44704f69SBart Van Asschetemporary object file, and libtool could not work around it because
3788*44704f69SBart Van Asscheyour compiler does not support '-c' and '-o' together.  If you
3789*44704f69SBart Van Asscherepeat this compilation, it may succeed, by chance, but you had better
3790*44704f69SBart Van Asscheavoid parallel builds (make -j) in this platform, or get a better
3791*44704f69SBart Van Asschecompiler."
3792*44704f69SBart Van Assche
3793*44704f69SBart Van Assche	$opt_dry_run || $RM $removelist
3794*44704f69SBart Van Assche	exit $EXIT_FAILURE
3795*44704f69SBart Van Assche      fi
3796*44704f69SBart Van Assche
3797*44704f69SBart Van Assche      # Just move the object if needed, then go on to compile the next one
3798*44704f69SBart Van Assche      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3799*44704f69SBart Van Assche	func_show_eval '$MV "$output_obj" "$lobj"' \
3800*44704f69SBart Van Assche	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3801*44704f69SBart Van Assche      fi
3802*44704f69SBart Van Assche
3803*44704f69SBart Van Assche      # Allow error messages only from the first compilation.
3804*44704f69SBart Van Assche      if test yes = "$suppress_opt"; then
3805*44704f69SBart Van Assche	suppress_output=' >/dev/null 2>&1'
3806*44704f69SBart Van Assche      fi
3807*44704f69SBart Van Assche    fi
3808*44704f69SBart Van Assche
3809*44704f69SBart Van Assche    # Only build a position-dependent object if we build old libraries.
3810*44704f69SBart Van Assche    if test yes = "$build_old_libs"; then
3811*44704f69SBart Van Assche      if test yes != "$pic_mode"; then
3812*44704f69SBart Van Assche	# Don't build PIC code
3813*44704f69SBart Van Assche	command="$base_compile $qsrcfile$pie_flag"
3814*44704f69SBart Van Assche      else
3815*44704f69SBart Van Assche	command="$base_compile $qsrcfile $pic_flag"
3816*44704f69SBart Van Assche      fi
3817*44704f69SBart Van Assche      if test yes = "$compiler_c_o"; then
3818*44704f69SBart Van Assche	func_append command " -o $obj"
3819*44704f69SBart Van Assche      fi
3820*44704f69SBart Van Assche
3821*44704f69SBart Van Assche      # Suppress compiler output if we already did a PIC compilation.
3822*44704f69SBart Van Assche      func_append command "$suppress_output"
3823*44704f69SBart Van Assche      func_show_eval_locale "$command" \
3824*44704f69SBart Van Assche        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3825*44704f69SBart Van Assche
3826*44704f69SBart Van Assche      if test warn = "$need_locks" &&
3827*44704f69SBart Van Assche	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3828*44704f69SBart Van Assche	$ECHO "\
3829*44704f69SBart Van Assche*** ERROR, $lockfile contains:
3830*44704f69SBart Van Assche`cat $lockfile 2>/dev/null`
3831*44704f69SBart Van Assche
3832*44704f69SBart Van Asschebut it should contain:
3833*44704f69SBart Van Assche$srcfile
3834*44704f69SBart Van Assche
3835*44704f69SBart Van AsscheThis indicates that another process is trying to use the same
3836*44704f69SBart Van Asschetemporary object file, and libtool could not work around it because
3837*44704f69SBart Van Asscheyour compiler does not support '-c' and '-o' together.  If you
3838*44704f69SBart Van Asscherepeat this compilation, it may succeed, by chance, but you had better
3839*44704f69SBart Van Asscheavoid parallel builds (make -j) in this platform, or get a better
3840*44704f69SBart Van Asschecompiler."
3841*44704f69SBart Van Assche
3842*44704f69SBart Van Assche	$opt_dry_run || $RM $removelist
3843*44704f69SBart Van Assche	exit $EXIT_FAILURE
3844*44704f69SBart Van Assche      fi
3845*44704f69SBart Van Assche
3846*44704f69SBart Van Assche      # Just move the object if needed
3847*44704f69SBart Van Assche      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3848*44704f69SBart Van Assche	func_show_eval '$MV "$output_obj" "$obj"' \
3849*44704f69SBart Van Assche	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3850*44704f69SBart Van Assche      fi
3851*44704f69SBart Van Assche    fi
3852*44704f69SBart Van Assche
3853*44704f69SBart Van Assche    $opt_dry_run || {
3854*44704f69SBart Van Assche      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3855*44704f69SBart Van Assche
3856*44704f69SBart Van Assche      # Unlock the critical section if it was locked
3857*44704f69SBart Van Assche      if test no != "$need_locks"; then
3858*44704f69SBart Van Assche	removelist=$lockfile
3859*44704f69SBart Van Assche        $RM "$lockfile"
3860*44704f69SBart Van Assche      fi
3861*44704f69SBart Van Assche    }
3862*44704f69SBart Van Assche
3863*44704f69SBart Van Assche    exit $EXIT_SUCCESS
3864*44704f69SBart Van Assche}
3865*44704f69SBart Van Assche
3866*44704f69SBart Van Assche$opt_help || {
3867*44704f69SBart Van Assche  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3868*44704f69SBart Van Assche}
3869*44704f69SBart Van Assche
3870*44704f69SBart Van Asschefunc_mode_help ()
3871*44704f69SBart Van Assche{
3872*44704f69SBart Van Assche    # We need to display help for each of the modes.
3873*44704f69SBart Van Assche    case $opt_mode in
3874*44704f69SBart Van Assche      "")
3875*44704f69SBart Van Assche        # Generic help is extracted from the usage comments
3876*44704f69SBart Van Assche        # at the start of this file.
3877*44704f69SBart Van Assche        func_help
3878*44704f69SBart Van Assche        ;;
3879*44704f69SBart Van Assche
3880*44704f69SBart Van Assche      clean)
3881*44704f69SBart Van Assche        $ECHO \
3882*44704f69SBart Van Assche"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3883*44704f69SBart Van Assche
3884*44704f69SBart Van AsscheRemove files from the build directory.
3885*44704f69SBart Van Assche
3886*44704f69SBart Van AsscheRM is the name of the program to use to delete files associated with each FILE
3887*44704f69SBart Van Assche(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3888*44704f69SBart Van Asscheto RM.
3889*44704f69SBart Van Assche
3890*44704f69SBart Van AsscheIf FILE is a libtool library, object or program, all the files associated
3891*44704f69SBart Van Asschewith it are deleted. Otherwise, only FILE itself is deleted using RM."
3892*44704f69SBart Van Assche        ;;
3893*44704f69SBart Van Assche
3894*44704f69SBart Van Assche      compile)
3895*44704f69SBart Van Assche      $ECHO \
3896*44704f69SBart Van Assche"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3897*44704f69SBart Van Assche
3898*44704f69SBart Van AsscheCompile a source file into a libtool library object.
3899*44704f69SBart Van Assche
3900*44704f69SBart Van AsscheThis mode accepts the following additional options:
3901*44704f69SBart Van Assche
3902*44704f69SBart Van Assche  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3903*44704f69SBart Van Assche  -no-suppress      do not suppress compiler output for multiple passes
3904*44704f69SBart Van Assche  -prefer-pic       try to build PIC objects only
3905*44704f69SBart Van Assche  -prefer-non-pic   try to build non-PIC objects only
3906*44704f69SBart Van Assche  -shared           do not build a '.o' file suitable for static linking
3907*44704f69SBart Van Assche  -static           only build a '.o' file suitable for static linking
3908*44704f69SBart Van Assche  -Wc,FLAG
3909*44704f69SBart Van Assche  -Xcompiler FLAG   pass FLAG directly to the compiler
3910*44704f69SBart Van Assche
3911*44704f69SBart Van AsscheCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3912*44704f69SBart Van Asschefrom the given SOURCEFILE.
3913*44704f69SBart Van Assche
3914*44704f69SBart Van AsscheThe output file name is determined by removing the directory component from
3915*44704f69SBart Van AsscheSOURCEFILE, then substituting the C source code suffix '.c' with the
3916*44704f69SBart Van Asschelibrary object suffix, '.lo'."
3917*44704f69SBart Van Assche        ;;
3918*44704f69SBart Van Assche
3919*44704f69SBart Van Assche      execute)
3920*44704f69SBart Van Assche        $ECHO \
3921*44704f69SBart Van Assche"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3922*44704f69SBart Van Assche
3923*44704f69SBart Van AsscheAutomatically set library path, then run a program.
3924*44704f69SBart Van Assche
3925*44704f69SBart Van AsscheThis mode accepts the following additional options:
3926*44704f69SBart Van Assche
3927*44704f69SBart Van Assche  -dlopen FILE      add the directory containing FILE to the library path
3928*44704f69SBart Van Assche
3929*44704f69SBart Van AsscheThis mode sets the library path environment variable according to '-dlopen'
3930*44704f69SBart Van Asscheflags.
3931*44704f69SBart Van Assche
3932*44704f69SBart Van AsscheIf any of the ARGS are libtool executable wrappers, then they are translated
3933*44704f69SBart Van Asscheinto their corresponding uninstalled binary, and any of their required library
3934*44704f69SBart Van Asschedirectories are added to the library path.
3935*44704f69SBart Van Assche
3936*44704f69SBart Van AsscheThen, COMMAND is executed, with ARGS as arguments."
3937*44704f69SBart Van Assche        ;;
3938*44704f69SBart Van Assche
3939*44704f69SBart Van Assche      finish)
3940*44704f69SBart Van Assche        $ECHO \
3941*44704f69SBart Van Assche"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3942*44704f69SBart Van Assche
3943*44704f69SBart Van AsscheComplete the installation of libtool libraries.
3944*44704f69SBart Van Assche
3945*44704f69SBart Van AsscheEach LIBDIR is a directory that contains libtool libraries.
3946*44704f69SBart Van Assche
3947*44704f69SBart Van AsscheThe commands that this mode executes may require superuser privileges.  Use
3948*44704f69SBart Van Asschethe '--dry-run' option if you just want to see what would be executed."
3949*44704f69SBart Van Assche        ;;
3950*44704f69SBart Van Assche
3951*44704f69SBart Van Assche      install)
3952*44704f69SBart Van Assche        $ECHO \
3953*44704f69SBart Van Assche"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3954*44704f69SBart Van Assche
3955*44704f69SBart Van AsscheInstall executables or libraries.
3956*44704f69SBart Van Assche
3957*44704f69SBart Van AsscheINSTALL-COMMAND is the installation command.  The first component should be
3958*44704f69SBart Van Asscheeither the 'install' or 'cp' program.
3959*44704f69SBart Van Assche
3960*44704f69SBart Van AsscheThe following components of INSTALL-COMMAND are treated specially:
3961*44704f69SBart Van Assche
3962*44704f69SBart Van Assche  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3963*44704f69SBart Van Assche
3964*44704f69SBart Van AsscheThe rest of the components are interpreted as arguments to that command (only
3965*44704f69SBart Van AsscheBSD-compatible install options are recognized)."
3966*44704f69SBart Van Assche        ;;
3967*44704f69SBart Van Assche
3968*44704f69SBart Van Assche      link)
3969*44704f69SBart Van Assche        $ECHO \
3970*44704f69SBart Van Assche"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3971*44704f69SBart Van Assche
3972*44704f69SBart Van AsscheLink object files or libraries together to form another library, or to
3973*44704f69SBart Van Asschecreate an executable program.
3974*44704f69SBart Van Assche
3975*44704f69SBart Van AsscheLINK-COMMAND is a command using the C compiler that you would use to create
3976*44704f69SBart Van Asschea program from several object files.
3977*44704f69SBart Van Assche
3978*44704f69SBart Van AsscheThe following components of LINK-COMMAND are treated specially:
3979*44704f69SBart Van Assche
3980*44704f69SBart Van Assche  -all-static       do not do any dynamic linking at all
3981*44704f69SBart Van Assche  -avoid-version    do not add a version suffix if possible
3982*44704f69SBart Van Assche  -bindir BINDIR    specify path to binaries directory (for systems where
3983*44704f69SBart Van Assche                    libraries must be found in the PATH setting at runtime)
3984*44704f69SBart Van Assche  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3985*44704f69SBart Van Assche  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3986*44704f69SBart Van Assche  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3987*44704f69SBart Van Assche  -export-symbols SYMFILE
3988*44704f69SBart Van Assche                    try to export only the symbols listed in SYMFILE
3989*44704f69SBart Van Assche  -export-symbols-regex REGEX
3990*44704f69SBart Van Assche                    try to export only the symbols matching REGEX
3991*44704f69SBart Van Assche  -LLIBDIR          search LIBDIR for required installed libraries
3992*44704f69SBart Van Assche  -lNAME            OUTPUT-FILE requires the installed library libNAME
3993*44704f69SBart Van Assche  -module           build a library that can dlopened
3994*44704f69SBart Van Assche  -no-fast-install  disable the fast-install mode
3995*44704f69SBart Van Assche  -no-install       link a not-installable executable
3996*44704f69SBart Van Assche  -no-undefined     declare that a library does not refer to external symbols
3997*44704f69SBart Van Assche  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3998*44704f69SBart Van Assche  -objectlist FILE  use a list of object files found in FILE to specify objects
3999*44704f69SBart Van Assche  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
4000*44704f69SBart Van Assche  -precious-files-regex REGEX
4001*44704f69SBart Van Assche                    don't remove output files matching REGEX
4002*44704f69SBart Van Assche  -release RELEASE  specify package release information
4003*44704f69SBart Van Assche  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4004*44704f69SBart Van Assche  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4005*44704f69SBart Van Assche  -shared           only do dynamic linking of libtool libraries
4006*44704f69SBart Van Assche  -shrext SUFFIX    override the standard shared library file extension
4007*44704f69SBart Van Assche  -static           do not do any dynamic linking of uninstalled libtool libraries
4008*44704f69SBart Van Assche  -static-libtool-libs
4009*44704f69SBart Van Assche                    do not do any dynamic linking of libtool libraries
4010*44704f69SBart Van Assche  -version-info CURRENT[:REVISION[:AGE]]
4011*44704f69SBart Van Assche                    specify library version info [each variable defaults to 0]
4012*44704f69SBart Van Assche  -weak LIBNAME     declare that the target provides the LIBNAME interface
4013*44704f69SBart Van Assche  -Wc,FLAG
4014*44704f69SBart Van Assche  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4015*44704f69SBart Van Assche  -Wa,FLAG
4016*44704f69SBart Van Assche  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4017*44704f69SBart Van Assche  -Wl,FLAG
4018*44704f69SBart Van Assche  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4019*44704f69SBart Van Assche  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
4020*44704f69SBart Van Assche
4021*44704f69SBart Van AsscheAll other options (arguments beginning with '-') are ignored.
4022*44704f69SBart Van Assche
4023*44704f69SBart Van AsscheEvery other argument is treated as a filename.  Files ending in '.la' are
4024*44704f69SBart Van Asschetreated as uninstalled libtool libraries, other files are standard or library
4025*44704f69SBart Van Asscheobject files.
4026*44704f69SBart Van Assche
4027*44704f69SBart Van AsscheIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4028*44704f69SBart Van Asscheonly library objects ('.lo' files) may be specified, and '-rpath' is
4029*44704f69SBart Van Asscherequired, except when creating a convenience library.
4030*44704f69SBart Van Assche
4031*44704f69SBart Van AsscheIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4032*44704f69SBart Van Asscheusing 'ar' and 'ranlib', or on Windows using 'lib'.
4033*44704f69SBart Van Assche
4034*44704f69SBart Van AsscheIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4035*44704f69SBart Van Asscheis created, otherwise an executable program is created."
4036*44704f69SBart Van Assche        ;;
4037*44704f69SBart Van Assche
4038*44704f69SBart Van Assche      uninstall)
4039*44704f69SBart Van Assche        $ECHO \
4040*44704f69SBart Van Assche"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
4041*44704f69SBart Van Assche
4042*44704f69SBart Van AsscheRemove libraries from an installation directory.
4043*44704f69SBart Van Assche
4044*44704f69SBart Van AsscheRM is the name of the program to use to delete files associated with each FILE
4045*44704f69SBart Van Assche(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4046*44704f69SBart Van Asscheto RM.
4047*44704f69SBart Van Assche
4048*44704f69SBart Van AsscheIf FILE is a libtool library, all the files associated with it are deleted.
4049*44704f69SBart Van AsscheOtherwise, only FILE itself is deleted using RM."
4050*44704f69SBart Van Assche        ;;
4051*44704f69SBart Van Assche
4052*44704f69SBart Van Assche      *)
4053*44704f69SBart Van Assche        func_fatal_help "invalid operation mode '$opt_mode'"
4054*44704f69SBart Van Assche        ;;
4055*44704f69SBart Van Assche    esac
4056*44704f69SBart Van Assche
4057*44704f69SBart Van Assche    echo
4058*44704f69SBart Van Assche    $ECHO "Try '$progname --help' for more information about other modes."
4059*44704f69SBart Van Assche}
4060*44704f69SBart Van Assche
4061*44704f69SBart Van Assche# Now that we've collected a possible --mode arg, show help if necessary
4062*44704f69SBart Van Asscheif $opt_help; then
4063*44704f69SBart Van Assche  if test : = "$opt_help"; then
4064*44704f69SBart Van Assche    func_mode_help
4065*44704f69SBart Van Assche  else
4066*44704f69SBart Van Assche    {
4067*44704f69SBart Van Assche      func_help noexit
4068*44704f69SBart Van Assche      for opt_mode in compile link execute install finish uninstall clean; do
4069*44704f69SBart Van Assche	func_mode_help
4070*44704f69SBart Van Assche      done
4071*44704f69SBart Van Assche    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4072*44704f69SBart Van Assche    {
4073*44704f69SBart Van Assche      func_help noexit
4074*44704f69SBart Van Assche      for opt_mode in compile link execute install finish uninstall clean; do
4075*44704f69SBart Van Assche	echo
4076*44704f69SBart Van Assche	func_mode_help
4077*44704f69SBart Van Assche      done
4078*44704f69SBart Van Assche    } |
4079*44704f69SBart Van Assche    $SED '1d
4080*44704f69SBart Van Assche      /^When reporting/,/^Report/{
4081*44704f69SBart Van Assche	H
4082*44704f69SBart Van Assche	d
4083*44704f69SBart Van Assche      }
4084*44704f69SBart Van Assche      $x
4085*44704f69SBart Van Assche      /information about other modes/d
4086*44704f69SBart Van Assche      /more detailed .*MODE/d
4087*44704f69SBart Van Assche      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4088*44704f69SBart Van Assche  fi
4089*44704f69SBart Van Assche  exit $?
4090*44704f69SBart Van Asschefi
4091*44704f69SBart Van Assche
4092*44704f69SBart Van Assche
4093*44704f69SBart Van Assche# func_mode_execute arg...
4094*44704f69SBart Van Asschefunc_mode_execute ()
4095*44704f69SBart Van Assche{
4096*44704f69SBart Van Assche    $debug_cmd
4097*44704f69SBart Van Assche
4098*44704f69SBart Van Assche    # The first argument is the command name.
4099*44704f69SBart Van Assche    cmd=$nonopt
4100*44704f69SBart Van Assche    test -z "$cmd" && \
4101*44704f69SBart Van Assche      func_fatal_help "you must specify a COMMAND"
4102*44704f69SBart Van Assche
4103*44704f69SBart Van Assche    # Handle -dlopen flags immediately.
4104*44704f69SBart Van Assche    for file in $opt_dlopen; do
4105*44704f69SBart Van Assche      test -f "$file" \
4106*44704f69SBart Van Assche	|| func_fatal_help "'$file' is not a file"
4107*44704f69SBart Van Assche
4108*44704f69SBart Van Assche      dir=
4109*44704f69SBart Van Assche      case $file in
4110*44704f69SBart Van Assche      *.la)
4111*44704f69SBart Van Assche	func_resolve_sysroot "$file"
4112*44704f69SBart Van Assche	file=$func_resolve_sysroot_result
4113*44704f69SBart Van Assche
4114*44704f69SBart Van Assche	# Check to see that this really is a libtool archive.
4115*44704f69SBart Van Assche	func_lalib_unsafe_p "$file" \
4116*44704f69SBart Van Assche	  || func_fatal_help "'$lib' is not a valid libtool archive"
4117*44704f69SBart Van Assche
4118*44704f69SBart Van Assche	# Read the libtool library.
4119*44704f69SBart Van Assche	dlname=
4120*44704f69SBart Van Assche	library_names=
4121*44704f69SBart Van Assche	func_source "$file"
4122*44704f69SBart Van Assche
4123*44704f69SBart Van Assche	# Skip this library if it cannot be dlopened.
4124*44704f69SBart Van Assche	if test -z "$dlname"; then
4125*44704f69SBart Van Assche	  # Warn if it was a shared library.
4126*44704f69SBart Van Assche	  test -n "$library_names" && \
4127*44704f69SBart Van Assche	    func_warning "'$file' was not linked with '-export-dynamic'"
4128*44704f69SBart Van Assche	  continue
4129*44704f69SBart Van Assche	fi
4130*44704f69SBart Van Assche
4131*44704f69SBart Van Assche	func_dirname "$file" "" "."
4132*44704f69SBart Van Assche	dir=$func_dirname_result
4133*44704f69SBart Van Assche
4134*44704f69SBart Van Assche	if test -f "$dir/$objdir/$dlname"; then
4135*44704f69SBart Van Assche	  func_append dir "/$objdir"
4136*44704f69SBart Van Assche	else
4137*44704f69SBart Van Assche	  if test ! -f "$dir/$dlname"; then
4138*44704f69SBart Van Assche	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4139*44704f69SBart Van Assche	  fi
4140*44704f69SBart Van Assche	fi
4141*44704f69SBart Van Assche	;;
4142*44704f69SBart Van Assche
4143*44704f69SBart Van Assche      *.lo)
4144*44704f69SBart Van Assche	# Just add the directory containing the .lo file.
4145*44704f69SBart Van Assche	func_dirname "$file" "" "."
4146*44704f69SBart Van Assche	dir=$func_dirname_result
4147*44704f69SBart Van Assche	;;
4148*44704f69SBart Van Assche
4149*44704f69SBart Van Assche      *)
4150*44704f69SBart Van Assche	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4151*44704f69SBart Van Assche	continue
4152*44704f69SBart Van Assche	;;
4153*44704f69SBart Van Assche      esac
4154*44704f69SBart Van Assche
4155*44704f69SBart Van Assche      # Get the absolute pathname.
4156*44704f69SBart Van Assche      absdir=`cd "$dir" && pwd`
4157*44704f69SBart Van Assche      test -n "$absdir" && dir=$absdir
4158*44704f69SBart Van Assche
4159*44704f69SBart Van Assche      # Now add the directory to shlibpath_var.
4160*44704f69SBart Van Assche      if eval "test -z \"\$$shlibpath_var\""; then
4161*44704f69SBart Van Assche	eval "$shlibpath_var=\"\$dir\""
4162*44704f69SBart Van Assche      else
4163*44704f69SBart Van Assche	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4164*44704f69SBart Van Assche      fi
4165*44704f69SBart Van Assche    done
4166*44704f69SBart Van Assche
4167*44704f69SBart Van Assche    # This variable tells wrapper scripts just to set shlibpath_var
4168*44704f69SBart Van Assche    # rather than running their programs.
4169*44704f69SBart Van Assche    libtool_execute_magic=$magic
4170*44704f69SBart Van Assche
4171*44704f69SBart Van Assche    # Check if any of the arguments is a wrapper script.
4172*44704f69SBart Van Assche    args=
4173*44704f69SBart Van Assche    for file
4174*44704f69SBart Van Assche    do
4175*44704f69SBart Van Assche      case $file in
4176*44704f69SBart Van Assche      -* | *.la | *.lo ) ;;
4177*44704f69SBart Van Assche      *)
4178*44704f69SBart Van Assche	# Do a test to see if this is really a libtool program.
4179*44704f69SBart Van Assche	if func_ltwrapper_script_p "$file"; then
4180*44704f69SBart Van Assche	  func_source "$file"
4181*44704f69SBart Van Assche	  # Transform arg to wrapped name.
4182*44704f69SBart Van Assche	  file=$progdir/$program
4183*44704f69SBart Van Assche	elif func_ltwrapper_executable_p "$file"; then
4184*44704f69SBart Van Assche	  func_ltwrapper_scriptname "$file"
4185*44704f69SBart Van Assche	  func_source "$func_ltwrapper_scriptname_result"
4186*44704f69SBart Van Assche	  # Transform arg to wrapped name.
4187*44704f69SBart Van Assche	  file=$progdir/$program
4188*44704f69SBart Van Assche	fi
4189*44704f69SBart Van Assche	;;
4190*44704f69SBart Van Assche      esac
4191*44704f69SBart Van Assche      # Quote arguments (to preserve shell metacharacters).
4192*44704f69SBart Van Assche      func_append_quoted args "$file"
4193*44704f69SBart Van Assche    done
4194*44704f69SBart Van Assche
4195*44704f69SBart Van Assche    if $opt_dry_run; then
4196*44704f69SBart Van Assche      # Display what would be done.
4197*44704f69SBart Van Assche      if test -n "$shlibpath_var"; then
4198*44704f69SBart Van Assche	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4199*44704f69SBart Van Assche	echo "export $shlibpath_var"
4200*44704f69SBart Van Assche      fi
4201*44704f69SBart Van Assche      $ECHO "$cmd$args"
4202*44704f69SBart Van Assche      exit $EXIT_SUCCESS
4203*44704f69SBart Van Assche    else
4204*44704f69SBart Van Assche      if test -n "$shlibpath_var"; then
4205*44704f69SBart Van Assche	# Export the shlibpath_var.
4206*44704f69SBart Van Assche	eval "export $shlibpath_var"
4207*44704f69SBart Van Assche      fi
4208*44704f69SBart Van Assche
4209*44704f69SBart Van Assche      # Restore saved environment variables
4210*44704f69SBart Van Assche      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4211*44704f69SBart Van Assche      do
4212*44704f69SBart Van Assche	eval "if test \"\${save_$lt_var+set}\" = set; then
4213*44704f69SBart Van Assche                $lt_var=\$save_$lt_var; export $lt_var
4214*44704f69SBart Van Assche	      else
4215*44704f69SBart Van Assche		$lt_unset $lt_var
4216*44704f69SBart Van Assche	      fi"
4217*44704f69SBart Van Assche      done
4218*44704f69SBart Van Assche
4219*44704f69SBart Van Assche      # Now prepare to actually exec the command.
4220*44704f69SBart Van Assche      exec_cmd=\$cmd$args
4221*44704f69SBart Van Assche    fi
4222*44704f69SBart Van Assche}
4223*44704f69SBart Van Assche
4224*44704f69SBart Van Asschetest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4225*44704f69SBart Van Assche
4226*44704f69SBart Van Assche
4227*44704f69SBart Van Assche# func_mode_finish arg...
4228*44704f69SBart Van Asschefunc_mode_finish ()
4229*44704f69SBart Van Assche{
4230*44704f69SBart Van Assche    $debug_cmd
4231*44704f69SBart Van Assche
4232*44704f69SBart Van Assche    libs=
4233*44704f69SBart Van Assche    libdirs=
4234*44704f69SBart Van Assche    admincmds=
4235*44704f69SBart Van Assche
4236*44704f69SBart Van Assche    for opt in "$nonopt" ${1+"$@"}
4237*44704f69SBart Van Assche    do
4238*44704f69SBart Van Assche      if test -d "$opt"; then
4239*44704f69SBart Van Assche	func_append libdirs " $opt"
4240*44704f69SBart Van Assche
4241*44704f69SBart Van Assche      elif test -f "$opt"; then
4242*44704f69SBart Van Assche	if func_lalib_unsafe_p "$opt"; then
4243*44704f69SBart Van Assche	  func_append libs " $opt"
4244*44704f69SBart Van Assche	else
4245*44704f69SBart Van Assche	  func_warning "'$opt' is not a valid libtool archive"
4246*44704f69SBart Van Assche	fi
4247*44704f69SBart Van Assche
4248*44704f69SBart Van Assche      else
4249*44704f69SBart Van Assche	func_fatal_error "invalid argument '$opt'"
4250*44704f69SBart Van Assche      fi
4251*44704f69SBart Van Assche    done
4252*44704f69SBart Van Assche
4253*44704f69SBart Van Assche    if test -n "$libs"; then
4254*44704f69SBart Van Assche      if test -n "$lt_sysroot"; then
4255*44704f69SBart Van Assche        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4256*44704f69SBart Van Assche        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4257*44704f69SBart Van Assche      else
4258*44704f69SBart Van Assche        sysroot_cmd=
4259*44704f69SBart Van Assche      fi
4260*44704f69SBart Van Assche
4261*44704f69SBart Van Assche      # Remove sysroot references
4262*44704f69SBart Van Assche      if $opt_dry_run; then
4263*44704f69SBart Van Assche        for lib in $libs; do
4264*44704f69SBart Van Assche          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4265*44704f69SBart Van Assche        done
4266*44704f69SBart Van Assche      else
4267*44704f69SBart Van Assche        tmpdir=`func_mktempdir`
4268*44704f69SBart Van Assche        for lib in $libs; do
4269*44704f69SBart Van Assche	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4270*44704f69SBart Van Assche	    > $tmpdir/tmp-la
4271*44704f69SBart Van Assche	  mv -f $tmpdir/tmp-la $lib
4272*44704f69SBart Van Assche	done
4273*44704f69SBart Van Assche        ${RM}r "$tmpdir"
4274*44704f69SBart Van Assche      fi
4275*44704f69SBart Van Assche    fi
4276*44704f69SBart Van Assche
4277*44704f69SBart Van Assche    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4278*44704f69SBart Van Assche      for libdir in $libdirs; do
4279*44704f69SBart Van Assche	if test -n "$finish_cmds"; then
4280*44704f69SBart Van Assche	  # Do each command in the finish commands.
4281*44704f69SBart Van Assche	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4282*44704f69SBart Van Assche'"$cmd"'"'
4283*44704f69SBart Van Assche	fi
4284*44704f69SBart Van Assche	if test -n "$finish_eval"; then
4285*44704f69SBart Van Assche	  # Do the single finish_eval.
4286*44704f69SBart Van Assche	  eval cmds=\"$finish_eval\"
4287*44704f69SBart Van Assche	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4288*44704f69SBart Van Assche       $cmds"
4289*44704f69SBart Van Assche	fi
4290*44704f69SBart Van Assche      done
4291*44704f69SBart Van Assche    fi
4292*44704f69SBart Van Assche
4293*44704f69SBart Van Assche    # Exit here if they wanted silent mode.
4294*44704f69SBart Van Assche    $opt_quiet && exit $EXIT_SUCCESS
4295*44704f69SBart Van Assche
4296*44704f69SBart Van Assche    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4297*44704f69SBart Van Assche      echo "----------------------------------------------------------------------"
4298*44704f69SBart Van Assche      echo "Libraries have been installed in:"
4299*44704f69SBart Van Assche      for libdir in $libdirs; do
4300*44704f69SBart Van Assche	$ECHO "   $libdir"
4301*44704f69SBart Van Assche      done
4302*44704f69SBart Van Assche      echo
4303*44704f69SBart Van Assche      echo "If you ever happen to want to link against installed libraries"
4304*44704f69SBart Van Assche      echo "in a given directory, LIBDIR, you must either use libtool, and"
4305*44704f69SBart Van Assche      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4306*44704f69SBart Van Assche      echo "flag during linking and do at least one of the following:"
4307*44704f69SBart Van Assche      if test -n "$shlibpath_var"; then
4308*44704f69SBart Van Assche	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4309*44704f69SBart Van Assche	echo "     during execution"
4310*44704f69SBart Van Assche      fi
4311*44704f69SBart Van Assche      if test -n "$runpath_var"; then
4312*44704f69SBart Van Assche	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4313*44704f69SBart Van Assche	echo "     during linking"
4314*44704f69SBart Van Assche      fi
4315*44704f69SBart Van Assche      if test -n "$hardcode_libdir_flag_spec"; then
4316*44704f69SBart Van Assche	libdir=LIBDIR
4317*44704f69SBart Van Assche	eval flag=\"$hardcode_libdir_flag_spec\"
4318*44704f69SBart Van Assche
4319*44704f69SBart Van Assche	$ECHO "   - use the '$flag' linker flag"
4320*44704f69SBart Van Assche      fi
4321*44704f69SBart Van Assche      if test -n "$admincmds"; then
4322*44704f69SBart Van Assche	$ECHO "   - have your system administrator run these commands:$admincmds"
4323*44704f69SBart Van Assche      fi
4324*44704f69SBart Van Assche      if test -f /etc/ld.so.conf; then
4325*44704f69SBart Van Assche	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4326*44704f69SBart Van Assche      fi
4327*44704f69SBart Van Assche      echo
4328*44704f69SBart Van Assche
4329*44704f69SBart Van Assche      echo "See any operating system documentation about shared libraries for"
4330*44704f69SBart Van Assche      case $host in
4331*44704f69SBart Van Assche	solaris2.[6789]|solaris2.1[0-9])
4332*44704f69SBart Van Assche	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4333*44704f69SBart Van Assche	  echo "pages."
4334*44704f69SBart Van Assche	  ;;
4335*44704f69SBart Van Assche	*)
4336*44704f69SBart Van Assche	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4337*44704f69SBart Van Assche	  ;;
4338*44704f69SBart Van Assche      esac
4339*44704f69SBart Van Assche      echo "----------------------------------------------------------------------"
4340*44704f69SBart Van Assche    fi
4341*44704f69SBart Van Assche    exit $EXIT_SUCCESS
4342*44704f69SBart Van Assche}
4343*44704f69SBart Van Assche
4344*44704f69SBart Van Asschetest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4345*44704f69SBart Van Assche
4346*44704f69SBart Van Assche
4347*44704f69SBart Van Assche# func_mode_install arg...
4348*44704f69SBart Van Asschefunc_mode_install ()
4349*44704f69SBart Van Assche{
4350*44704f69SBart Van Assche    $debug_cmd
4351*44704f69SBart Van Assche
4352*44704f69SBart Van Assche    # There may be an optional sh(1) argument at the beginning of
4353*44704f69SBart Van Assche    # install_prog (especially on Windows NT).
4354*44704f69SBart Van Assche    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4355*44704f69SBart Van Assche       # Allow the use of GNU shtool's install command.
4356*44704f69SBart Van Assche       case $nonopt in *shtool*) :;; *) false;; esac
4357*44704f69SBart Van Assche    then
4358*44704f69SBart Van Assche      # Aesthetically quote it.
4359*44704f69SBart Van Assche      func_quote_arg pretty "$nonopt"
4360*44704f69SBart Van Assche      install_prog="$func_quote_arg_result "
4361*44704f69SBart Van Assche      arg=$1
4362*44704f69SBart Van Assche      shift
4363*44704f69SBart Van Assche    else
4364*44704f69SBart Van Assche      install_prog=
4365*44704f69SBart Van Assche      arg=$nonopt
4366*44704f69SBart Van Assche    fi
4367*44704f69SBart Van Assche
4368*44704f69SBart Van Assche    # The real first argument should be the name of the installation program.
4369*44704f69SBart Van Assche    # Aesthetically quote it.
4370*44704f69SBart Van Assche    func_quote_arg pretty "$arg"
4371*44704f69SBart Van Assche    func_append install_prog "$func_quote_arg_result"
4372*44704f69SBart Van Assche    install_shared_prog=$install_prog
4373*44704f69SBart Van Assche    case " $install_prog " in
4374*44704f69SBart Van Assche      *[\\\ /]cp\ *) install_cp=: ;;
4375*44704f69SBart Van Assche      *) install_cp=false ;;
4376*44704f69SBart Van Assche    esac
4377*44704f69SBart Van Assche
4378*44704f69SBart Van Assche    # We need to accept at least all the BSD install flags.
4379*44704f69SBart Van Assche    dest=
4380*44704f69SBart Van Assche    files=
4381*44704f69SBart Van Assche    opts=
4382*44704f69SBart Van Assche    prev=
4383*44704f69SBart Van Assche    install_type=
4384*44704f69SBart Van Assche    isdir=false
4385*44704f69SBart Van Assche    stripme=
4386*44704f69SBart Van Assche    no_mode=:
4387*44704f69SBart Van Assche    for arg
4388*44704f69SBart Van Assche    do
4389*44704f69SBart Van Assche      arg2=
4390*44704f69SBart Van Assche      if test -n "$dest"; then
4391*44704f69SBart Van Assche	func_append files " $dest"
4392*44704f69SBart Van Assche	dest=$arg
4393*44704f69SBart Van Assche	continue
4394*44704f69SBart Van Assche      fi
4395*44704f69SBart Van Assche
4396*44704f69SBart Van Assche      case $arg in
4397*44704f69SBart Van Assche      -d) isdir=: ;;
4398*44704f69SBart Van Assche      -f)
4399*44704f69SBart Van Assche	if $install_cp; then :; else
4400*44704f69SBart Van Assche	  prev=$arg
4401*44704f69SBart Van Assche	fi
4402*44704f69SBart Van Assche	;;
4403*44704f69SBart Van Assche      -g | -m | -o)
4404*44704f69SBart Van Assche	prev=$arg
4405*44704f69SBart Van Assche	;;
4406*44704f69SBart Van Assche      -s)
4407*44704f69SBart Van Assche	stripme=" -s"
4408*44704f69SBart Van Assche	continue
4409*44704f69SBart Van Assche	;;
4410*44704f69SBart Van Assche      -*)
4411*44704f69SBart Van Assche	;;
4412*44704f69SBart Van Assche      *)
4413*44704f69SBart Van Assche	# If the previous option needed an argument, then skip it.
4414*44704f69SBart Van Assche	if test -n "$prev"; then
4415*44704f69SBart Van Assche	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4416*44704f69SBart Van Assche	    arg2=$install_override_mode
4417*44704f69SBart Van Assche	    no_mode=false
4418*44704f69SBart Van Assche	  fi
4419*44704f69SBart Van Assche	  prev=
4420*44704f69SBart Van Assche	else
4421*44704f69SBart Van Assche	  dest=$arg
4422*44704f69SBart Van Assche	  continue
4423*44704f69SBart Van Assche	fi
4424*44704f69SBart Van Assche	;;
4425*44704f69SBart Van Assche      esac
4426*44704f69SBart Van Assche
4427*44704f69SBart Van Assche      # Aesthetically quote the argument.
4428*44704f69SBart Van Assche      func_quote_arg pretty "$arg"
4429*44704f69SBart Van Assche      func_append install_prog " $func_quote_arg_result"
4430*44704f69SBart Van Assche      if test -n "$arg2"; then
4431*44704f69SBart Van Assche	func_quote_arg pretty "$arg2"
4432*44704f69SBart Van Assche      fi
4433*44704f69SBart Van Assche      func_append install_shared_prog " $func_quote_arg_result"
4434*44704f69SBart Van Assche    done
4435*44704f69SBart Van Assche
4436*44704f69SBart Van Assche    test -z "$install_prog" && \
4437*44704f69SBart Van Assche      func_fatal_help "you must specify an install program"
4438*44704f69SBart Van Assche
4439*44704f69SBart Van Assche    test -n "$prev" && \
4440*44704f69SBart Van Assche      func_fatal_help "the '$prev' option requires an argument"
4441*44704f69SBart Van Assche
4442*44704f69SBart Van Assche    if test -n "$install_override_mode" && $no_mode; then
4443*44704f69SBart Van Assche      if $install_cp; then :; else
4444*44704f69SBart Van Assche	func_quote_arg pretty "$install_override_mode"
4445*44704f69SBart Van Assche	func_append install_shared_prog " -m $func_quote_arg_result"
4446*44704f69SBart Van Assche      fi
4447*44704f69SBart Van Assche    fi
4448*44704f69SBart Van Assche
4449*44704f69SBart Van Assche    if test -z "$files"; then
4450*44704f69SBart Van Assche      if test -z "$dest"; then
4451*44704f69SBart Van Assche	func_fatal_help "no file or destination specified"
4452*44704f69SBart Van Assche      else
4453*44704f69SBart Van Assche	func_fatal_help "you must specify a destination"
4454*44704f69SBart Van Assche      fi
4455*44704f69SBart Van Assche    fi
4456*44704f69SBart Van Assche
4457*44704f69SBart Van Assche    # Strip any trailing slash from the destination.
4458*44704f69SBart Van Assche    func_stripname '' '/' "$dest"
4459*44704f69SBart Van Assche    dest=$func_stripname_result
4460*44704f69SBart Van Assche
4461*44704f69SBart Van Assche    # Check to see that the destination is a directory.
4462*44704f69SBart Van Assche    test -d "$dest" && isdir=:
4463*44704f69SBart Van Assche    if $isdir; then
4464*44704f69SBart Van Assche      destdir=$dest
4465*44704f69SBart Van Assche      destname=
4466*44704f69SBart Van Assche    else
4467*44704f69SBart Van Assche      func_dirname_and_basename "$dest" "" "."
4468*44704f69SBart Van Assche      destdir=$func_dirname_result
4469*44704f69SBart Van Assche      destname=$func_basename_result
4470*44704f69SBart Van Assche
4471*44704f69SBart Van Assche      # Not a directory, so check to see that there is only one file specified.
4472*44704f69SBart Van Assche      set dummy $files; shift
4473*44704f69SBart Van Assche      test "$#" -gt 1 && \
4474*44704f69SBart Van Assche	func_fatal_help "'$dest' is not a directory"
4475*44704f69SBart Van Assche    fi
4476*44704f69SBart Van Assche    case $destdir in
4477*44704f69SBart Van Assche    [\\/]* | [A-Za-z]:[\\/]*) ;;
4478*44704f69SBart Van Assche    *)
4479*44704f69SBart Van Assche      for file in $files; do
4480*44704f69SBart Van Assche	case $file in
4481*44704f69SBart Van Assche	*.lo) ;;
4482*44704f69SBart Van Assche	*)
4483*44704f69SBart Van Assche	  func_fatal_help "'$destdir' must be an absolute directory name"
4484*44704f69SBart Van Assche	  ;;
4485*44704f69SBart Van Assche	esac
4486*44704f69SBart Van Assche      done
4487*44704f69SBart Van Assche      ;;
4488*44704f69SBart Van Assche    esac
4489*44704f69SBart Van Assche
4490*44704f69SBart Van Assche    # This variable tells wrapper scripts just to set variables rather
4491*44704f69SBart Van Assche    # than running their programs.
4492*44704f69SBart Van Assche    libtool_install_magic=$magic
4493*44704f69SBart Van Assche
4494*44704f69SBart Van Assche    staticlibs=
4495*44704f69SBart Van Assche    future_libdirs=
4496*44704f69SBart Van Assche    current_libdirs=
4497*44704f69SBart Van Assche    for file in $files; do
4498*44704f69SBart Van Assche
4499*44704f69SBart Van Assche      # Do each installation.
4500*44704f69SBart Van Assche      case $file in
4501*44704f69SBart Van Assche      *.$libext)
4502*44704f69SBart Van Assche	# Do the static libraries later.
4503*44704f69SBart Van Assche	func_append staticlibs " $file"
4504*44704f69SBart Van Assche	;;
4505*44704f69SBart Van Assche
4506*44704f69SBart Van Assche      *.la)
4507*44704f69SBart Van Assche	func_resolve_sysroot "$file"
4508*44704f69SBart Van Assche	file=$func_resolve_sysroot_result
4509*44704f69SBart Van Assche
4510*44704f69SBart Van Assche	# Check to see that this really is a libtool archive.
4511*44704f69SBart Van Assche	func_lalib_unsafe_p "$file" \
4512*44704f69SBart Van Assche	  || func_fatal_help "'$file' is not a valid libtool archive"
4513*44704f69SBart Van Assche
4514*44704f69SBart Van Assche	library_names=
4515*44704f69SBart Van Assche	old_library=
4516*44704f69SBart Van Assche	relink_command=
4517*44704f69SBart Van Assche	func_source "$file"
4518*44704f69SBart Van Assche
4519*44704f69SBart Van Assche	# Add the libdir to current_libdirs if it is the destination.
4520*44704f69SBart Van Assche	if test "X$destdir" = "X$libdir"; then
4521*44704f69SBart Van Assche	  case "$current_libdirs " in
4522*44704f69SBart Van Assche	  *" $libdir "*) ;;
4523*44704f69SBart Van Assche	  *) func_append current_libdirs " $libdir" ;;
4524*44704f69SBart Van Assche	  esac
4525*44704f69SBart Van Assche	else
4526*44704f69SBart Van Assche	  # Note the libdir as a future libdir.
4527*44704f69SBart Van Assche	  case "$future_libdirs " in
4528*44704f69SBart Van Assche	  *" $libdir "*) ;;
4529*44704f69SBart Van Assche	  *) func_append future_libdirs " $libdir" ;;
4530*44704f69SBart Van Assche	  esac
4531*44704f69SBart Van Assche	fi
4532*44704f69SBart Van Assche
4533*44704f69SBart Van Assche	func_dirname "$file" "/" ""
4534*44704f69SBart Van Assche	dir=$func_dirname_result
4535*44704f69SBart Van Assche	func_append dir "$objdir"
4536*44704f69SBart Van Assche
4537*44704f69SBart Van Assche	if test -n "$relink_command"; then
4538*44704f69SBart Van Assche	  # Determine the prefix the user has applied to our future dir.
4539*44704f69SBart Van Assche	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4540*44704f69SBart Van Assche
4541*44704f69SBart Van Assche	  # Don't allow the user to place us outside of our expected
4542*44704f69SBart Van Assche	  # location b/c this prevents finding dependent libraries that
4543*44704f69SBart Van Assche	  # are installed to the same prefix.
4544*44704f69SBart Van Assche	  # At present, this check doesn't affect windows .dll's that
4545*44704f69SBart Van Assche	  # are installed into $libdir/../bin (currently, that works fine)
4546*44704f69SBart Van Assche	  # but it's something to keep an eye on.
4547*44704f69SBart Van Assche	  test "$inst_prefix_dir" = "$destdir" && \
4548*44704f69SBart Van Assche	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4549*44704f69SBart Van Assche
4550*44704f69SBart Van Assche	  if test -n "$inst_prefix_dir"; then
4551*44704f69SBart Van Assche	    # Stick the inst_prefix_dir data into the link command.
4552*44704f69SBart Van Assche	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4553*44704f69SBart Van Assche	  else
4554*44704f69SBart Van Assche	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4555*44704f69SBart Van Assche	  fi
4556*44704f69SBart Van Assche
4557*44704f69SBart Van Assche	  func_warning "relinking '$file'"
4558*44704f69SBart Van Assche	  func_show_eval "$relink_command" \
4559*44704f69SBart Van Assche	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4560*44704f69SBart Van Assche	fi
4561*44704f69SBart Van Assche
4562*44704f69SBart Van Assche	# See the names of the shared library.
4563*44704f69SBart Van Assche	set dummy $library_names; shift
4564*44704f69SBart Van Assche	if test -n "$1"; then
4565*44704f69SBart Van Assche	  realname=$1
4566*44704f69SBart Van Assche	  shift
4567*44704f69SBart Van Assche
4568*44704f69SBart Van Assche	  srcname=$realname
4569*44704f69SBart Van Assche	  test -n "$relink_command" && srcname=${realname}T
4570*44704f69SBart Van Assche
4571*44704f69SBart Van Assche	  # Install the shared library and build the symlinks.
4572*44704f69SBart Van Assche	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4573*44704f69SBart Van Assche	      'exit $?'
4574*44704f69SBart Van Assche	  tstripme=$stripme
4575*44704f69SBart Van Assche	  case $host_os in
4576*44704f69SBart Van Assche	  cygwin* | mingw* | pw32* | cegcc*)
4577*44704f69SBart Van Assche	    case $realname in
4578*44704f69SBart Van Assche	    *.dll.a)
4579*44704f69SBart Van Assche	      tstripme=
4580*44704f69SBart Van Assche	      ;;
4581*44704f69SBart Van Assche	    esac
4582*44704f69SBart Van Assche	    ;;
4583*44704f69SBart Van Assche	  os2*)
4584*44704f69SBart Van Assche	    case $realname in
4585*44704f69SBart Van Assche	    *_dll.a)
4586*44704f69SBart Van Assche	      tstripme=
4587*44704f69SBart Van Assche	      ;;
4588*44704f69SBart Van Assche	    esac
4589*44704f69SBart Van Assche	    ;;
4590*44704f69SBart Van Assche	  esac
4591*44704f69SBart Van Assche	  if test -n "$tstripme" && test -n "$striplib"; then
4592*44704f69SBart Van Assche	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4593*44704f69SBart Van Assche	  fi
4594*44704f69SBart Van Assche
4595*44704f69SBart Van Assche	  if test "$#" -gt 0; then
4596*44704f69SBart Van Assche	    # Delete the old symlinks, and create new ones.
4597*44704f69SBart Van Assche	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4598*44704f69SBart Van Assche	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4599*44704f69SBart Van Assche	    # so we also need to try rm && ln -s.
4600*44704f69SBart Van Assche	    for linkname
4601*44704f69SBart Van Assche	    do
4602*44704f69SBart Van Assche	      test "$linkname" != "$realname" \
4603*44704f69SBart Van Assche		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4604*44704f69SBart Van Assche	    done
4605*44704f69SBart Van Assche	  fi
4606*44704f69SBart Van Assche
4607*44704f69SBart Van Assche	  # Do each command in the postinstall commands.
4608*44704f69SBart Van Assche	  lib=$destdir/$realname
4609*44704f69SBart Van Assche	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4610*44704f69SBart Van Assche	fi
4611*44704f69SBart Van Assche
4612*44704f69SBart Van Assche	# Install the pseudo-library for information purposes.
4613*44704f69SBart Van Assche	func_basename "$file"
4614*44704f69SBart Van Assche	name=$func_basename_result
4615*44704f69SBart Van Assche	instname=$dir/${name}i
4616*44704f69SBart Van Assche	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4617*44704f69SBart Van Assche
4618*44704f69SBart Van Assche	# Maybe install the static library, too.
4619*44704f69SBart Van Assche	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4620*44704f69SBart Van Assche	;;
4621*44704f69SBart Van Assche
4622*44704f69SBart Van Assche      *.lo)
4623*44704f69SBart Van Assche	# Install (i.e. copy) a libtool object.
4624*44704f69SBart Van Assche
4625*44704f69SBart Van Assche	# Figure out destination file name, if it wasn't already specified.
4626*44704f69SBart Van Assche	if test -n "$destname"; then
4627*44704f69SBart Van Assche	  destfile=$destdir/$destname
4628*44704f69SBart Van Assche	else
4629*44704f69SBart Van Assche	  func_basename "$file"
4630*44704f69SBart Van Assche	  destfile=$func_basename_result
4631*44704f69SBart Van Assche	  destfile=$destdir/$destfile
4632*44704f69SBart Van Assche	fi
4633*44704f69SBart Van Assche
4634*44704f69SBart Van Assche	# Deduce the name of the destination old-style object file.
4635*44704f69SBart Van Assche	case $destfile in
4636*44704f69SBart Van Assche	*.lo)
4637*44704f69SBart Van Assche	  func_lo2o "$destfile"
4638*44704f69SBart Van Assche	  staticdest=$func_lo2o_result
4639*44704f69SBart Van Assche	  ;;
4640*44704f69SBart Van Assche	*.$objext)
4641*44704f69SBart Van Assche	  staticdest=$destfile
4642*44704f69SBart Van Assche	  destfile=
4643*44704f69SBart Van Assche	  ;;
4644*44704f69SBart Van Assche	*)
4645*44704f69SBart Van Assche	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4646*44704f69SBart Van Assche	  ;;
4647*44704f69SBart Van Assche	esac
4648*44704f69SBart Van Assche
4649*44704f69SBart Van Assche	# Install the libtool object if requested.
4650*44704f69SBart Van Assche	test -n "$destfile" && \
4651*44704f69SBart Van Assche	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4652*44704f69SBart Van Assche
4653*44704f69SBart Van Assche	# Install the old object if enabled.
4654*44704f69SBart Van Assche	if test yes = "$build_old_libs"; then
4655*44704f69SBart Van Assche	  # Deduce the name of the old-style object file.
4656*44704f69SBart Van Assche	  func_lo2o "$file"
4657*44704f69SBart Van Assche	  staticobj=$func_lo2o_result
4658*44704f69SBart Van Assche	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4659*44704f69SBart Van Assche	fi
4660*44704f69SBart Van Assche	exit $EXIT_SUCCESS
4661*44704f69SBart Van Assche	;;
4662*44704f69SBart Van Assche
4663*44704f69SBart Van Assche      *)
4664*44704f69SBart Van Assche	# Figure out destination file name, if it wasn't already specified.
4665*44704f69SBart Van Assche	if test -n "$destname"; then
4666*44704f69SBart Van Assche	  destfile=$destdir/$destname
4667*44704f69SBart Van Assche	else
4668*44704f69SBart Van Assche	  func_basename "$file"
4669*44704f69SBart Van Assche	  destfile=$func_basename_result
4670*44704f69SBart Van Assche	  destfile=$destdir/$destfile
4671*44704f69SBart Van Assche	fi
4672*44704f69SBart Van Assche
4673*44704f69SBart Van Assche	# If the file is missing, and there is a .exe on the end, strip it
4674*44704f69SBart Van Assche	# because it is most likely a libtool script we actually want to
4675*44704f69SBart Van Assche	# install
4676*44704f69SBart Van Assche	stripped_ext=
4677*44704f69SBart Van Assche	case $file in
4678*44704f69SBart Van Assche	  *.exe)
4679*44704f69SBart Van Assche	    if test ! -f "$file"; then
4680*44704f69SBart Van Assche	      func_stripname '' '.exe' "$file"
4681*44704f69SBart Van Assche	      file=$func_stripname_result
4682*44704f69SBart Van Assche	      stripped_ext=.exe
4683*44704f69SBart Van Assche	    fi
4684*44704f69SBart Van Assche	    ;;
4685*44704f69SBart Van Assche	esac
4686*44704f69SBart Van Assche
4687*44704f69SBart Van Assche	# Do a test to see if this is really a libtool program.
4688*44704f69SBart Van Assche	case $host in
4689*44704f69SBart Van Assche	*cygwin* | *mingw*)
4690*44704f69SBart Van Assche	    if func_ltwrapper_executable_p "$file"; then
4691*44704f69SBart Van Assche	      func_ltwrapper_scriptname "$file"
4692*44704f69SBart Van Assche	      wrapper=$func_ltwrapper_scriptname_result
4693*44704f69SBart Van Assche	    else
4694*44704f69SBart Van Assche	      func_stripname '' '.exe' "$file"
4695*44704f69SBart Van Assche	      wrapper=$func_stripname_result
4696*44704f69SBart Van Assche	    fi
4697*44704f69SBart Van Assche	    ;;
4698*44704f69SBart Van Assche	*)
4699*44704f69SBart Van Assche	    wrapper=$file
4700*44704f69SBart Van Assche	    ;;
4701*44704f69SBart Van Assche	esac
4702*44704f69SBart Van Assche	if func_ltwrapper_script_p "$wrapper"; then
4703*44704f69SBart Van Assche	  notinst_deplibs=
4704*44704f69SBart Van Assche	  relink_command=
4705*44704f69SBart Van Assche
4706*44704f69SBart Van Assche	  func_source "$wrapper"
4707*44704f69SBart Van Assche
4708*44704f69SBart Van Assche	  # Check the variables that should have been set.
4709*44704f69SBart Van Assche	  test -z "$generated_by_libtool_version" && \
4710*44704f69SBart Van Assche	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4711*44704f69SBart Van Assche
4712*44704f69SBart Van Assche	  finalize=:
4713*44704f69SBart Van Assche	  for lib in $notinst_deplibs; do
4714*44704f69SBart Van Assche	    # Check to see that each library is installed.
4715*44704f69SBart Van Assche	    libdir=
4716*44704f69SBart Van Assche	    if test -f "$lib"; then
4717*44704f69SBart Van Assche	      func_source "$lib"
4718*44704f69SBart Van Assche	    fi
4719*44704f69SBart Van Assche	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4720*44704f69SBart Van Assche	    if test -n "$libdir" && test ! -f "$libfile"; then
4721*44704f69SBart Van Assche	      func_warning "'$lib' has not been installed in '$libdir'"
4722*44704f69SBart Van Assche	      finalize=false
4723*44704f69SBart Van Assche	    fi
4724*44704f69SBart Van Assche	  done
4725*44704f69SBart Van Assche
4726*44704f69SBart Van Assche	  relink_command=
4727*44704f69SBart Van Assche	  func_source "$wrapper"
4728*44704f69SBart Van Assche
4729*44704f69SBart Van Assche	  outputname=
4730*44704f69SBart Van Assche	  if test no = "$fast_install" && test -n "$relink_command"; then
4731*44704f69SBart Van Assche	    $opt_dry_run || {
4732*44704f69SBart Van Assche	      if $finalize; then
4733*44704f69SBart Van Assche	        tmpdir=`func_mktempdir`
4734*44704f69SBart Van Assche		func_basename "$file$stripped_ext"
4735*44704f69SBart Van Assche		file=$func_basename_result
4736*44704f69SBart Van Assche	        outputname=$tmpdir/$file
4737*44704f69SBart Van Assche	        # Replace the output file specification.
4738*44704f69SBart Van Assche	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4739*44704f69SBart Van Assche
4740*44704f69SBart Van Assche	        $opt_quiet || {
4741*44704f69SBart Van Assche	          func_quote_arg expand,pretty "$relink_command"
4742*44704f69SBart Van Assche		  eval "func_echo $func_quote_arg_result"
4743*44704f69SBart Van Assche	        }
4744*44704f69SBart Van Assche	        if eval "$relink_command"; then :
4745*44704f69SBart Van Assche	          else
4746*44704f69SBart Van Assche		  func_error "error: relink '$file' with the above command before installing it"
4747*44704f69SBart Van Assche		  $opt_dry_run || ${RM}r "$tmpdir"
4748*44704f69SBart Van Assche		  continue
4749*44704f69SBart Van Assche	        fi
4750*44704f69SBart Van Assche	        file=$outputname
4751*44704f69SBart Van Assche	      else
4752*44704f69SBart Van Assche	        func_warning "cannot relink '$file'"
4753*44704f69SBart Van Assche	      fi
4754*44704f69SBart Van Assche	    }
4755*44704f69SBart Van Assche	  else
4756*44704f69SBart Van Assche	    # Install the binary that we compiled earlier.
4757*44704f69SBart Van Assche	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4758*44704f69SBart Van Assche	  fi
4759*44704f69SBart Van Assche	fi
4760*44704f69SBart Van Assche
4761*44704f69SBart Van Assche	# remove .exe since cygwin /usr/bin/install will append another
4762*44704f69SBart Van Assche	# one anyway
4763*44704f69SBart Van Assche	case $install_prog,$host in
4764*44704f69SBart Van Assche	*/usr/bin/install*,*cygwin*)
4765*44704f69SBart Van Assche	  case $file:$destfile in
4766*44704f69SBart Van Assche	  *.exe:*.exe)
4767*44704f69SBart Van Assche	    # this is ok
4768*44704f69SBart Van Assche	    ;;
4769*44704f69SBart Van Assche	  *.exe:*)
4770*44704f69SBart Van Assche	    destfile=$destfile.exe
4771*44704f69SBart Van Assche	    ;;
4772*44704f69SBart Van Assche	  *:*.exe)
4773*44704f69SBart Van Assche	    func_stripname '' '.exe' "$destfile"
4774*44704f69SBart Van Assche	    destfile=$func_stripname_result
4775*44704f69SBart Van Assche	    ;;
4776*44704f69SBart Van Assche	  esac
4777*44704f69SBart Van Assche	  ;;
4778*44704f69SBart Van Assche	esac
4779*44704f69SBart Van Assche	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4780*44704f69SBart Van Assche	$opt_dry_run || if test -n "$outputname"; then
4781*44704f69SBart Van Assche	  ${RM}r "$tmpdir"
4782*44704f69SBart Van Assche	fi
4783*44704f69SBart Van Assche	;;
4784*44704f69SBart Van Assche      esac
4785*44704f69SBart Van Assche    done
4786*44704f69SBart Van Assche
4787*44704f69SBart Van Assche    for file in $staticlibs; do
4788*44704f69SBart Van Assche      func_basename "$file"
4789*44704f69SBart Van Assche      name=$func_basename_result
4790*44704f69SBart Van Assche
4791*44704f69SBart Van Assche      # Set up the ranlib parameters.
4792*44704f69SBart Van Assche      oldlib=$destdir/$name
4793*44704f69SBart Van Assche      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4794*44704f69SBart Van Assche      tool_oldlib=$func_to_tool_file_result
4795*44704f69SBart Van Assche
4796*44704f69SBart Van Assche      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4797*44704f69SBart Van Assche
4798*44704f69SBart Van Assche      if test -n "$stripme" && test -n "$old_striplib"; then
4799*44704f69SBart Van Assche	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4800*44704f69SBart Van Assche      fi
4801*44704f69SBart Van Assche
4802*44704f69SBart Van Assche      # Do each command in the postinstall commands.
4803*44704f69SBart Van Assche      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4804*44704f69SBart Van Assche    done
4805*44704f69SBart Van Assche
4806*44704f69SBart Van Assche    test -n "$future_libdirs" && \
4807*44704f69SBart Van Assche      func_warning "remember to run '$progname --finish$future_libdirs'"
4808*44704f69SBart Van Assche
4809*44704f69SBart Van Assche    if test -n "$current_libdirs"; then
4810*44704f69SBart Van Assche      # Maybe just do a dry run.
4811*44704f69SBart Van Assche      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4812*44704f69SBart Van Assche      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4813*44704f69SBart Van Assche    else
4814*44704f69SBart Van Assche      exit $EXIT_SUCCESS
4815*44704f69SBart Van Assche    fi
4816*44704f69SBart Van Assche}
4817*44704f69SBart Van Assche
4818*44704f69SBart Van Asschetest install = "$opt_mode" && func_mode_install ${1+"$@"}
4819*44704f69SBart Van Assche
4820*44704f69SBart Van Assche
4821*44704f69SBart Van Assche# func_generate_dlsyms outputname originator pic_p
4822*44704f69SBart Van Assche# Extract symbols from dlprefiles and create ${outputname}S.o with
4823*44704f69SBart Van Assche# a dlpreopen symbol table.
4824*44704f69SBart Van Asschefunc_generate_dlsyms ()
4825*44704f69SBart Van Assche{
4826*44704f69SBart Van Assche    $debug_cmd
4827*44704f69SBart Van Assche
4828*44704f69SBart Van Assche    my_outputname=$1
4829*44704f69SBart Van Assche    my_originator=$2
4830*44704f69SBart Van Assche    my_pic_p=${3-false}
4831*44704f69SBart Van Assche    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4832*44704f69SBart Van Assche    my_dlsyms=
4833*44704f69SBart Van Assche
4834*44704f69SBart Van Assche    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4835*44704f69SBart Van Assche      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4836*44704f69SBart Van Assche	my_dlsyms=${my_outputname}S.c
4837*44704f69SBart Van Assche      else
4838*44704f69SBart Van Assche	func_error "not configured to extract global symbols from dlpreopened files"
4839*44704f69SBart Van Assche      fi
4840*44704f69SBart Van Assche    fi
4841*44704f69SBart Van Assche
4842*44704f69SBart Van Assche    if test -n "$my_dlsyms"; then
4843*44704f69SBart Van Assche      case $my_dlsyms in
4844*44704f69SBart Van Assche      "") ;;
4845*44704f69SBart Van Assche      *.c)
4846*44704f69SBart Van Assche	# Discover the nlist of each of the dlfiles.
4847*44704f69SBart Van Assche	nlist=$output_objdir/$my_outputname.nm
4848*44704f69SBart Van Assche
4849*44704f69SBart Van Assche	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4850*44704f69SBart Van Assche
4851*44704f69SBart Van Assche	# Parse the name list into a source file.
4852*44704f69SBart Van Assche	func_verbose "creating $output_objdir/$my_dlsyms"
4853*44704f69SBart Van Assche
4854*44704f69SBart Van Assche	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4855*44704f69SBart Van Assche/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4856*44704f69SBart Van Assche/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4857*44704f69SBart Van Assche
4858*44704f69SBart Van Assche#ifdef __cplusplus
4859*44704f69SBart Van Asscheextern \"C\" {
4860*44704f69SBart Van Assche#endif
4861*44704f69SBart Van Assche
4862*44704f69SBart Van Assche#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4863*44704f69SBart Van Assche#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4864*44704f69SBart Van Assche#endif
4865*44704f69SBart Van Assche
4866*44704f69SBart Van Assche/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4867*44704f69SBart Van Assche#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4868*44704f69SBart Van Assche/* DATA imports from DLLs on WIN32 can't be const, because runtime
4869*44704f69SBart Van Assche   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4870*44704f69SBart Van Assche# define LT_DLSYM_CONST
4871*44704f69SBart Van Assche#elif defined __osf__
4872*44704f69SBart Van Assche/* This system does not cope well with relocations in const data.  */
4873*44704f69SBart Van Assche# define LT_DLSYM_CONST
4874*44704f69SBart Van Assche#else
4875*44704f69SBart Van Assche# define LT_DLSYM_CONST const
4876*44704f69SBart Van Assche#endif
4877*44704f69SBart Van Assche
4878*44704f69SBart Van Assche#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4879*44704f69SBart Van Assche
4880*44704f69SBart Van Assche/* External symbol declarations for the compiler. */\
4881*44704f69SBart Van Assche"
4882*44704f69SBart Van Assche
4883*44704f69SBart Van Assche	if test yes = "$dlself"; then
4884*44704f69SBart Van Assche	  func_verbose "generating symbol list for '$output'"
4885*44704f69SBart Van Assche
4886*44704f69SBart Van Assche	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4887*44704f69SBart Van Assche
4888*44704f69SBart Van Assche	  # Add our own program objects to the symbol list.
4889*44704f69SBart Van Assche	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4890*44704f69SBart Van Assche	  for progfile in $progfiles; do
4891*44704f69SBart Van Assche	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4892*44704f69SBart Van Assche	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4893*44704f69SBart Van Assche	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4894*44704f69SBart Van Assche	  done
4895*44704f69SBart Van Assche
4896*44704f69SBart Van Assche	  if test -n "$exclude_expsyms"; then
4897*44704f69SBart Van Assche	    $opt_dry_run || {
4898*44704f69SBart Van Assche	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4899*44704f69SBart Van Assche	      eval '$MV "$nlist"T "$nlist"'
4900*44704f69SBart Van Assche	    }
4901*44704f69SBart Van Assche	  fi
4902*44704f69SBart Van Assche
4903*44704f69SBart Van Assche	  if test -n "$export_symbols_regex"; then
4904*44704f69SBart Van Assche	    $opt_dry_run || {
4905*44704f69SBart Van Assche	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4906*44704f69SBart Van Assche	      eval '$MV "$nlist"T "$nlist"'
4907*44704f69SBart Van Assche	    }
4908*44704f69SBart Van Assche	  fi
4909*44704f69SBart Van Assche
4910*44704f69SBart Van Assche	  # Prepare the list of exported symbols
4911*44704f69SBart Van Assche	  if test -z "$export_symbols"; then
4912*44704f69SBart Van Assche	    export_symbols=$output_objdir/$outputname.exp
4913*44704f69SBart Van Assche	    $opt_dry_run || {
4914*44704f69SBart Van Assche	      $RM $export_symbols
4915*44704f69SBart Van Assche	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4916*44704f69SBart Van Assche	      case $host in
4917*44704f69SBart Van Assche	      *cygwin* | *mingw* | *cegcc* )
4918*44704f69SBart Van Assche                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4919*44704f69SBart Van Assche                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4920*44704f69SBart Van Assche	        ;;
4921*44704f69SBart Van Assche	      esac
4922*44704f69SBart Van Assche	    }
4923*44704f69SBart Van Assche	  else
4924*44704f69SBart Van Assche	    $opt_dry_run || {
4925*44704f69SBart Van Assche	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4926*44704f69SBart Van Assche	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4927*44704f69SBart Van Assche	      eval '$MV "$nlist"T "$nlist"'
4928*44704f69SBart Van Assche	      case $host in
4929*44704f69SBart Van Assche	        *cygwin* | *mingw* | *cegcc* )
4930*44704f69SBart Van Assche	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4931*44704f69SBart Van Assche	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4932*44704f69SBart Van Assche	          ;;
4933*44704f69SBart Van Assche	      esac
4934*44704f69SBart Van Assche	    }
4935*44704f69SBart Van Assche	  fi
4936*44704f69SBart Van Assche	fi
4937*44704f69SBart Van Assche
4938*44704f69SBart Van Assche	for dlprefile in $dlprefiles; do
4939*44704f69SBart Van Assche	  func_verbose "extracting global C symbols from '$dlprefile'"
4940*44704f69SBart Van Assche	  func_basename "$dlprefile"
4941*44704f69SBart Van Assche	  name=$func_basename_result
4942*44704f69SBart Van Assche          case $host in
4943*44704f69SBart Van Assche	    *cygwin* | *mingw* | *cegcc* )
4944*44704f69SBart Van Assche	      # if an import library, we need to obtain dlname
4945*44704f69SBart Van Assche	      if func_win32_import_lib_p "$dlprefile"; then
4946*44704f69SBart Van Assche	        func_tr_sh "$dlprefile"
4947*44704f69SBart Van Assche	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4948*44704f69SBart Van Assche	        dlprefile_dlbasename=
4949*44704f69SBart Van Assche	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4950*44704f69SBart Van Assche	          # Use subshell, to avoid clobbering current variable values
4951*44704f69SBart Van Assche	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4952*44704f69SBart Van Assche	          if test -n "$dlprefile_dlname"; then
4953*44704f69SBart Van Assche	            func_basename "$dlprefile_dlname"
4954*44704f69SBart Van Assche	            dlprefile_dlbasename=$func_basename_result
4955*44704f69SBart Van Assche	          else
4956*44704f69SBart Van Assche	            # no lafile. user explicitly requested -dlpreopen <import library>.
4957*44704f69SBart Van Assche	            $sharedlib_from_linklib_cmd "$dlprefile"
4958*44704f69SBart Van Assche	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4959*44704f69SBart Van Assche	          fi
4960*44704f69SBart Van Assche	        fi
4961*44704f69SBart Van Assche	        $opt_dry_run || {
4962*44704f69SBart Van Assche	          if test -n "$dlprefile_dlbasename"; then
4963*44704f69SBart Van Assche	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4964*44704f69SBart Van Assche	          else
4965*44704f69SBart Van Assche	            func_warning "Could not compute DLL name from $name"
4966*44704f69SBart Van Assche	            eval '$ECHO ": $name " >> "$nlist"'
4967*44704f69SBart Van Assche	          fi
4968*44704f69SBart Van Assche	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4969*44704f69SBart Van Assche	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4970*44704f69SBart Van Assche	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4971*44704f69SBart Van Assche	        }
4972*44704f69SBart Van Assche	      else # not an import lib
4973*44704f69SBart Van Assche	        $opt_dry_run || {
4974*44704f69SBart Van Assche	          eval '$ECHO ": $name " >> "$nlist"'
4975*44704f69SBart Van Assche	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4976*44704f69SBart Van Assche	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4977*44704f69SBart Van Assche	        }
4978*44704f69SBart Van Assche	      fi
4979*44704f69SBart Van Assche	    ;;
4980*44704f69SBart Van Assche	    *)
4981*44704f69SBart Van Assche	      $opt_dry_run || {
4982*44704f69SBart Van Assche	        eval '$ECHO ": $name " >> "$nlist"'
4983*44704f69SBart Van Assche	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4984*44704f69SBart Van Assche	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4985*44704f69SBart Van Assche	      }
4986*44704f69SBart Van Assche	    ;;
4987*44704f69SBart Van Assche          esac
4988*44704f69SBart Van Assche	done
4989*44704f69SBart Van Assche
4990*44704f69SBart Van Assche	$opt_dry_run || {
4991*44704f69SBart Van Assche	  # Make sure we have at least an empty file.
4992*44704f69SBart Van Assche	  test -f "$nlist" || : > "$nlist"
4993*44704f69SBart Van Assche
4994*44704f69SBart Van Assche	  if test -n "$exclude_expsyms"; then
4995*44704f69SBart Van Assche	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4996*44704f69SBart Van Assche	    $MV "$nlist"T "$nlist"
4997*44704f69SBart Van Assche	  fi
4998*44704f69SBart Van Assche
4999*44704f69SBart Van Assche	  # Try sorting and uniquifying the output.
5000*44704f69SBart Van Assche	  if $GREP -v "^: " < "$nlist" |
5001*44704f69SBart Van Assche	      if sort -k 3 </dev/null >/dev/null 2>&1; then
5002*44704f69SBart Van Assche		sort -k 3
5003*44704f69SBart Van Assche	      else
5004*44704f69SBart Van Assche		sort +2
5005*44704f69SBart Van Assche	      fi |
5006*44704f69SBart Van Assche	      uniq > "$nlist"S; then
5007*44704f69SBart Van Assche	    :
5008*44704f69SBart Van Assche	  else
5009*44704f69SBart Van Assche	    $GREP -v "^: " < "$nlist" > "$nlist"S
5010*44704f69SBart Van Assche	  fi
5011*44704f69SBart Van Assche
5012*44704f69SBart Van Assche	  if test -f "$nlist"S; then
5013*44704f69SBart Van Assche	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5014*44704f69SBart Van Assche	  else
5015*44704f69SBart Van Assche	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5016*44704f69SBart Van Assche	  fi
5017*44704f69SBart Van Assche
5018*44704f69SBart Van Assche	  func_show_eval '$RM "${nlist}I"'
5019*44704f69SBart Van Assche	  if test -n "$global_symbol_to_import"; then
5020*44704f69SBart Van Assche	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5021*44704f69SBart Van Assche	  fi
5022*44704f69SBart Van Assche
5023*44704f69SBart Van Assche	  echo >> "$output_objdir/$my_dlsyms" "\
5024*44704f69SBart Van Assche
5025*44704f69SBart Van Assche/* The mapping between symbol names and symbols.  */
5026*44704f69SBart Van Asschetypedef struct {
5027*44704f69SBart Van Assche  const char *name;
5028*44704f69SBart Van Assche  void *address;
5029*44704f69SBart Van Assche} lt_dlsymlist;
5030*44704f69SBart Van Asscheextern LT_DLSYM_CONST lt_dlsymlist
5031*44704f69SBart Van Asschelt_${my_prefix}_LTX_preloaded_symbols[];\
5032*44704f69SBart Van Assche"
5033*44704f69SBart Van Assche
5034*44704f69SBart Van Assche	  if test -s "$nlist"I; then
5035*44704f69SBart Van Assche	    echo >> "$output_objdir/$my_dlsyms" "\
5036*44704f69SBart Van Asschestatic void lt_syminit(void)
5037*44704f69SBart Van Assche{
5038*44704f69SBart Van Assche  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5039*44704f69SBart Van Assche  for (; symbol->name; ++symbol)
5040*44704f69SBart Van Assche    {"
5041*44704f69SBart Van Assche	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5042*44704f69SBart Van Assche	    echo >> "$output_objdir/$my_dlsyms" "\
5043*44704f69SBart Van Assche    }
5044*44704f69SBart Van Assche}"
5045*44704f69SBart Van Assche	  fi
5046*44704f69SBart Van Assche	  echo >> "$output_objdir/$my_dlsyms" "\
5047*44704f69SBart Van AsscheLT_DLSYM_CONST lt_dlsymlist
5048*44704f69SBart Van Asschelt_${my_prefix}_LTX_preloaded_symbols[] =
5049*44704f69SBart Van Assche{ {\"$my_originator\", (void *) 0},"
5050*44704f69SBart Van Assche
5051*44704f69SBart Van Assche	  if test -s "$nlist"I; then
5052*44704f69SBart Van Assche	    echo >> "$output_objdir/$my_dlsyms" "\
5053*44704f69SBart Van Assche  {\"@INIT@\", (void *) &lt_syminit},"
5054*44704f69SBart Van Assche	  fi
5055*44704f69SBart Van Assche
5056*44704f69SBart Van Assche	  case $need_lib_prefix in
5057*44704f69SBart Van Assche	  no)
5058*44704f69SBart Van Assche	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5059*44704f69SBart Van Assche	    ;;
5060*44704f69SBart Van Assche	  *)
5061*44704f69SBart Van Assche	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5062*44704f69SBart Van Assche	    ;;
5063*44704f69SBart Van Assche	  esac
5064*44704f69SBart Van Assche	  echo >> "$output_objdir/$my_dlsyms" "\
5065*44704f69SBart Van Assche  {0, (void *) 0}
5066*44704f69SBart Van Assche};
5067*44704f69SBart Van Assche
5068*44704f69SBart Van Assche/* This works around a problem in FreeBSD linker */
5069*44704f69SBart Van Assche#ifdef FREEBSD_WORKAROUND
5070*44704f69SBart Van Asschestatic const void *lt_preloaded_setup() {
5071*44704f69SBart Van Assche  return lt_${my_prefix}_LTX_preloaded_symbols;
5072*44704f69SBart Van Assche}
5073*44704f69SBart Van Assche#endif
5074*44704f69SBart Van Assche
5075*44704f69SBart Van Assche#ifdef __cplusplus
5076*44704f69SBart Van Assche}
5077*44704f69SBart Van Assche#endif\
5078*44704f69SBart Van Assche"
5079*44704f69SBart Van Assche	} # !$opt_dry_run
5080*44704f69SBart Van Assche
5081*44704f69SBart Van Assche	pic_flag_for_symtable=
5082*44704f69SBart Van Assche	case "$compile_command " in
5083*44704f69SBart Van Assche	*" -static "*) ;;
5084*44704f69SBart Van Assche	*)
5085*44704f69SBart Van Assche	  case $host in
5086*44704f69SBart Van Assche	  # compiling the symbol table file with pic_flag works around
5087*44704f69SBart Van Assche	  # a FreeBSD bug that causes programs to crash when -lm is
5088*44704f69SBart Van Assche	  # linked before any other PIC object.  But we must not use
5089*44704f69SBart Van Assche	  # pic_flag when linking with -static.  The problem exists in
5090*44704f69SBart Van Assche	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5091*44704f69SBart Van Assche	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5092*44704f69SBart Van Assche	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5093*44704f69SBart Van Assche	  *-*-hpux*)
5094*44704f69SBart Van Assche	    pic_flag_for_symtable=" $pic_flag"  ;;
5095*44704f69SBart Van Assche	  *)
5096*44704f69SBart Van Assche	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5097*44704f69SBart Van Assche	    ;;
5098*44704f69SBart Van Assche	  esac
5099*44704f69SBart Van Assche	  ;;
5100*44704f69SBart Van Assche	esac
5101*44704f69SBart Van Assche	symtab_cflags=
5102*44704f69SBart Van Assche	for arg in $LTCFLAGS; do
5103*44704f69SBart Van Assche	  case $arg in
5104*44704f69SBart Van Assche	  -pie | -fpie | -fPIE) ;;
5105*44704f69SBart Van Assche	  *) func_append symtab_cflags " $arg" ;;
5106*44704f69SBart Van Assche	  esac
5107*44704f69SBart Van Assche	done
5108*44704f69SBart Van Assche
5109*44704f69SBart Van Assche	# Now compile the dynamic symbol file.
5110*44704f69SBart Van Assche	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
5111*44704f69SBart Van Assche
5112*44704f69SBart Van Assche	# Clean up the generated files.
5113*44704f69SBart Van Assche	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
5114*44704f69SBart Van Assche
5115*44704f69SBart Van Assche	# Transform the symbol file into the correct name.
5116*44704f69SBart Van Assche	symfileobj=$output_objdir/${my_outputname}S.$objext
5117*44704f69SBart Van Assche	case $host in
5118*44704f69SBart Van Assche	*cygwin* | *mingw* | *cegcc* )
5119*44704f69SBart Van Assche	  if test -f "$output_objdir/$my_outputname.def"; then
5120*44704f69SBart Van Assche	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5121*44704f69SBart Van Assche	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5122*44704f69SBart Van Assche	  else
5123*44704f69SBart Van Assche	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5124*44704f69SBart Van Assche	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5125*44704f69SBart Van Assche	  fi
5126*44704f69SBart Van Assche	  ;;
5127*44704f69SBart Van Assche	*)
5128*44704f69SBart Van Assche	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5129*44704f69SBart Van Assche	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5130*44704f69SBart Van Assche	  ;;
5131*44704f69SBart Van Assche	esac
5132*44704f69SBart Van Assche	;;
5133*44704f69SBart Van Assche      *)
5134*44704f69SBart Van Assche	func_fatal_error "unknown suffix for '$my_dlsyms'"
5135*44704f69SBart Van Assche	;;
5136*44704f69SBart Van Assche      esac
5137*44704f69SBart Van Assche    else
5138*44704f69SBart Van Assche      # We keep going just in case the user didn't refer to
5139*44704f69SBart Van Assche      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5140*44704f69SBart Van Assche      # really was required.
5141*44704f69SBart Van Assche
5142*44704f69SBart Van Assche      # Nullify the symbol file.
5143*44704f69SBart Van Assche      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5144*44704f69SBart Van Assche      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5145*44704f69SBart Van Assche    fi
5146*44704f69SBart Van Assche}
5147*44704f69SBart Van Assche
5148*44704f69SBart Van Assche# func_cygming_gnu_implib_p ARG
5149*44704f69SBart Van Assche# This predicate returns with zero status (TRUE) if
5150*44704f69SBart Van Assche# ARG is a GNU/binutils-style import library. Returns
5151*44704f69SBart Van Assche# with nonzero status (FALSE) otherwise.
5152*44704f69SBart Van Asschefunc_cygming_gnu_implib_p ()
5153*44704f69SBart Van Assche{
5154*44704f69SBart Van Assche  $debug_cmd
5155*44704f69SBart Van Assche
5156*44704f69SBart Van Assche  func_to_tool_file "$1" func_convert_file_msys_to_w32
5157*44704f69SBart Van Assche  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)$'`
5158*44704f69SBart Van Assche  test -n "$func_cygming_gnu_implib_tmp"
5159*44704f69SBart Van Assche}
5160*44704f69SBart Van Assche
5161*44704f69SBart Van Assche# func_cygming_ms_implib_p ARG
5162*44704f69SBart Van Assche# This predicate returns with zero status (TRUE) if
5163*44704f69SBart Van Assche# ARG is an MS-style import library. Returns
5164*44704f69SBart Van Assche# with nonzero status (FALSE) otherwise.
5165*44704f69SBart Van Asschefunc_cygming_ms_implib_p ()
5166*44704f69SBart Van Assche{
5167*44704f69SBart Van Assche  $debug_cmd
5168*44704f69SBart Van Assche
5169*44704f69SBart Van Assche  func_to_tool_file "$1" func_convert_file_msys_to_w32
5170*44704f69SBart Van Assche  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5171*44704f69SBart Van Assche  test -n "$func_cygming_ms_implib_tmp"
5172*44704f69SBart Van Assche}
5173*44704f69SBart Van Assche
5174*44704f69SBart Van Assche# func_win32_libid arg
5175*44704f69SBart Van Assche# return the library type of file 'arg'
5176*44704f69SBart Van Assche#
5177*44704f69SBart Van Assche# Need a lot of goo to handle *both* DLLs and import libs
5178*44704f69SBart Van Assche# Has to be a shell function in order to 'eat' the argument
5179*44704f69SBart Van Assche# that is supplied when $file_magic_command is called.
5180*44704f69SBart Van Assche# Despite the name, also deal with 64 bit binaries.
5181*44704f69SBart Van Asschefunc_win32_libid ()
5182*44704f69SBart Van Assche{
5183*44704f69SBart Van Assche  $debug_cmd
5184*44704f69SBart Van Assche
5185*44704f69SBart Van Assche  win32_libid_type=unknown
5186*44704f69SBart Van Assche  win32_fileres=`file -L $1 2>/dev/null`
5187*44704f69SBart Van Assche  case $win32_fileres in
5188*44704f69SBart Van Assche  *ar\ archive\ import\ library*) # definitely import
5189*44704f69SBart Van Assche    win32_libid_type="x86 archive import"
5190*44704f69SBart Van Assche    ;;
5191*44704f69SBart Van Assche  *ar\ archive*) # could be an import, or static
5192*44704f69SBart Van Assche    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5193*44704f69SBart Van Assche    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5194*44704f69SBart Van Assche       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5195*44704f69SBart Van Assche      case $nm_interface in
5196*44704f69SBart Van Assche      "MS dumpbin")
5197*44704f69SBart Van Assche	if func_cygming_ms_implib_p "$1" ||
5198*44704f69SBart Van Assche	   func_cygming_gnu_implib_p "$1"
5199*44704f69SBart Van Assche	then
5200*44704f69SBart Van Assche	  win32_nmres=import
5201*44704f69SBart Van Assche	else
5202*44704f69SBart Van Assche	  win32_nmres=
5203*44704f69SBart Van Assche	fi
5204*44704f69SBart Van Assche	;;
5205*44704f69SBart Van Assche      *)
5206*44704f69SBart Van Assche	func_to_tool_file "$1" func_convert_file_msys_to_w32
5207*44704f69SBart Van Assche	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5208*44704f69SBart Van Assche	  $SED -n -e '
5209*44704f69SBart Van Assche	    1,100{
5210*44704f69SBart Van Assche		/ I /{
5211*44704f69SBart Van Assche		    s|.*|import|
5212*44704f69SBart Van Assche		    p
5213*44704f69SBart Van Assche		    q
5214*44704f69SBart Van Assche		}
5215*44704f69SBart Van Assche	    }'`
5216*44704f69SBart Van Assche	;;
5217*44704f69SBart Van Assche      esac
5218*44704f69SBart Van Assche      case $win32_nmres in
5219*44704f69SBart Van Assche      import*)  win32_libid_type="x86 archive import";;
5220*44704f69SBart Van Assche      *)        win32_libid_type="x86 archive static";;
5221*44704f69SBart Van Assche      esac
5222*44704f69SBart Van Assche    fi
5223*44704f69SBart Van Assche    ;;
5224*44704f69SBart Van Assche  *DLL*)
5225*44704f69SBart Van Assche    win32_libid_type="x86 DLL"
5226*44704f69SBart Van Assche    ;;
5227*44704f69SBart Van Assche  *executable*) # but shell scripts are "executable" too...
5228*44704f69SBart Van Assche    case $win32_fileres in
5229*44704f69SBart Van Assche    *MS\ Windows\ PE\ Intel*)
5230*44704f69SBart Van Assche      win32_libid_type="x86 DLL"
5231*44704f69SBart Van Assche      ;;
5232*44704f69SBart Van Assche    esac
5233*44704f69SBart Van Assche    ;;
5234*44704f69SBart Van Assche  esac
5235*44704f69SBart Van Assche  $ECHO "$win32_libid_type"
5236*44704f69SBart Van Assche}
5237*44704f69SBart Van Assche
5238*44704f69SBart Van Assche# func_cygming_dll_for_implib ARG
5239*44704f69SBart Van Assche#
5240*44704f69SBart Van Assche# Platform-specific function to extract the
5241*44704f69SBart Van Assche# name of the DLL associated with the specified
5242*44704f69SBart Van Assche# import library ARG.
5243*44704f69SBart Van Assche# Invoked by eval'ing the libtool variable
5244*44704f69SBart Van Assche#    $sharedlib_from_linklib_cmd
5245*44704f69SBart Van Assche# Result is available in the variable
5246*44704f69SBart Van Assche#    $sharedlib_from_linklib_result
5247*44704f69SBart Van Asschefunc_cygming_dll_for_implib ()
5248*44704f69SBart Van Assche{
5249*44704f69SBart Van Assche  $debug_cmd
5250*44704f69SBart Van Assche
5251*44704f69SBart Van Assche  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5252*44704f69SBart Van Assche}
5253*44704f69SBart Van Assche
5254*44704f69SBart Van Assche# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5255*44704f69SBart Van Assche#
5256*44704f69SBart Van Assche# The is the core of a fallback implementation of a
5257*44704f69SBart Van Assche# platform-specific function to extract the name of the
5258*44704f69SBart Van Assche# DLL associated with the specified import library LIBNAME.
5259*44704f69SBart Van Assche#
5260*44704f69SBart Van Assche# SECTION_NAME is either .idata$6 or .idata$7, depending
5261*44704f69SBart Van Assche# on the platform and compiler that created the implib.
5262*44704f69SBart Van Assche#
5263*44704f69SBart Van Assche# Echos the name of the DLL associated with the
5264*44704f69SBart Van Assche# specified import library.
5265*44704f69SBart Van Asschefunc_cygming_dll_for_implib_fallback_core ()
5266*44704f69SBart Van Assche{
5267*44704f69SBart Van Assche  $debug_cmd
5268*44704f69SBart Van Assche
5269*44704f69SBart Van Assche  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5270*44704f69SBart Van Assche  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5271*44704f69SBart Van Assche    $SED '/^Contents of section '"$match_literal"':/{
5272*44704f69SBart Van Assche      # Place marker at beginning of archive member dllname section
5273*44704f69SBart Van Assche      s/.*/====MARK====/
5274*44704f69SBart Van Assche      p
5275*44704f69SBart Van Assche      d
5276*44704f69SBart Van Assche    }
5277*44704f69SBart Van Assche    # These lines can sometimes be longer than 43 characters, but
5278*44704f69SBart Van Assche    # are always uninteresting
5279*44704f69SBart Van Assche    /:[	 ]*file format pe[i]\{,1\}-/d
5280*44704f69SBart Van Assche    /^In archive [^:]*:/d
5281*44704f69SBart Van Assche    # Ensure marker is printed
5282*44704f69SBart Van Assche    /^====MARK====/p
5283*44704f69SBart Van Assche    # Remove all lines with less than 43 characters
5284*44704f69SBart Van Assche    /^.\{43\}/!d
5285*44704f69SBart Van Assche    # From remaining lines, remove first 43 characters
5286*44704f69SBart Van Assche    s/^.\{43\}//' |
5287*44704f69SBart Van Assche    $SED -n '
5288*44704f69SBart Van Assche      # Join marker and all lines until next marker into a single line
5289*44704f69SBart Van Assche      /^====MARK====/ b para
5290*44704f69SBart Van Assche      H
5291*44704f69SBart Van Assche      $ b para
5292*44704f69SBart Van Assche      b
5293*44704f69SBart Van Assche      :para
5294*44704f69SBart Van Assche      x
5295*44704f69SBart Van Assche      s/\n//g
5296*44704f69SBart Van Assche      # Remove the marker
5297*44704f69SBart Van Assche      s/^====MARK====//
5298*44704f69SBart Van Assche      # Remove trailing dots and whitespace
5299*44704f69SBart Van Assche      s/[\. \t]*$//
5300*44704f69SBart Van Assche      # Print
5301*44704f69SBart Van Assche      /./p' |
5302*44704f69SBart Van Assche    # we now have a list, one entry per line, of the stringified
5303*44704f69SBart Van Assche    # contents of the appropriate section of all members of the
5304*44704f69SBart Van Assche    # archive that possess that section. Heuristic: eliminate
5305*44704f69SBart Van Assche    # all those that have a first or second character that is
5306*44704f69SBart Van Assche    # a '.' (that is, objdump's representation of an unprintable
5307*44704f69SBart Van Assche    # character.) This should work for all archives with less than
5308*44704f69SBart Van Assche    # 0x302f exports -- but will fail for DLLs whose name actually
5309*44704f69SBart Van Assche    # begins with a literal '.' or a single character followed by
5310*44704f69SBart Van Assche    # a '.'.
5311*44704f69SBart Van Assche    #
5312*44704f69SBart Van Assche    # Of those that remain, print the first one.
5313*44704f69SBart Van Assche    $SED -e '/^\./d;/^.\./d;q'
5314*44704f69SBart Van Assche}
5315*44704f69SBart Van Assche
5316*44704f69SBart Van Assche# func_cygming_dll_for_implib_fallback ARG
5317*44704f69SBart Van Assche# Platform-specific function to extract the
5318*44704f69SBart Van Assche# name of the DLL associated with the specified
5319*44704f69SBart Van Assche# import library ARG.
5320*44704f69SBart Van Assche#
5321*44704f69SBart Van Assche# This fallback implementation is for use when $DLLTOOL
5322*44704f69SBart Van Assche# does not support the --identify-strict option.
5323*44704f69SBart Van Assche# Invoked by eval'ing the libtool variable
5324*44704f69SBart Van Assche#    $sharedlib_from_linklib_cmd
5325*44704f69SBart Van Assche# Result is available in the variable
5326*44704f69SBart Van Assche#    $sharedlib_from_linklib_result
5327*44704f69SBart Van Asschefunc_cygming_dll_for_implib_fallback ()
5328*44704f69SBart Van Assche{
5329*44704f69SBart Van Assche  $debug_cmd
5330*44704f69SBart Van Assche
5331*44704f69SBart Van Assche  if func_cygming_gnu_implib_p "$1"; then
5332*44704f69SBart Van Assche    # binutils import library
5333*44704f69SBart Van Assche    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5334*44704f69SBart Van Assche  elif func_cygming_ms_implib_p "$1"; then
5335*44704f69SBart Van Assche    # ms-generated import library
5336*44704f69SBart Van Assche    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5337*44704f69SBart Van Assche  else
5338*44704f69SBart Van Assche    # unknown
5339*44704f69SBart Van Assche    sharedlib_from_linklib_result=
5340*44704f69SBart Van Assche  fi
5341*44704f69SBart Van Assche}
5342*44704f69SBart Van Assche
5343*44704f69SBart Van Assche
5344*44704f69SBart Van Assche# func_extract_an_archive dir oldlib
5345*44704f69SBart Van Asschefunc_extract_an_archive ()
5346*44704f69SBart Van Assche{
5347*44704f69SBart Van Assche    $debug_cmd
5348*44704f69SBart Van Assche
5349*44704f69SBart Van Assche    f_ex_an_ar_dir=$1; shift
5350*44704f69SBart Van Assche    f_ex_an_ar_oldlib=$1
5351*44704f69SBart Van Assche    if test yes = "$lock_old_archive_extraction"; then
5352*44704f69SBart Van Assche      lockfile=$f_ex_an_ar_oldlib.lock
5353*44704f69SBart Van Assche      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5354*44704f69SBart Van Assche	func_echo "Waiting for $lockfile to be removed"
5355*44704f69SBart Van Assche	sleep 2
5356*44704f69SBart Van Assche      done
5357*44704f69SBart Van Assche    fi
5358*44704f69SBart Van Assche    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5359*44704f69SBart Van Assche		   'stat=$?; rm -f "$lockfile"; exit $stat'
5360*44704f69SBart Van Assche    if test yes = "$lock_old_archive_extraction"; then
5361*44704f69SBart Van Assche      $opt_dry_run || rm -f "$lockfile"
5362*44704f69SBart Van Assche    fi
5363*44704f69SBart Van Assche    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5364*44704f69SBart Van Assche     :
5365*44704f69SBart Van Assche    else
5366*44704f69SBart Van Assche      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5367*44704f69SBart Van Assche    fi
5368*44704f69SBart Van Assche}
5369*44704f69SBart Van Assche
5370*44704f69SBart Van Assche
5371*44704f69SBart Van Assche# func_extract_archives gentop oldlib ...
5372*44704f69SBart Van Asschefunc_extract_archives ()
5373*44704f69SBart Van Assche{
5374*44704f69SBart Van Assche    $debug_cmd
5375*44704f69SBart Van Assche
5376*44704f69SBart Van Assche    my_gentop=$1; shift
5377*44704f69SBart Van Assche    my_oldlibs=${1+"$@"}
5378*44704f69SBart Van Assche    my_oldobjs=
5379*44704f69SBart Van Assche    my_xlib=
5380*44704f69SBart Van Assche    my_xabs=
5381*44704f69SBart Van Assche    my_xdir=
5382*44704f69SBart Van Assche
5383*44704f69SBart Van Assche    for my_xlib in $my_oldlibs; do
5384*44704f69SBart Van Assche      # Extract the objects.
5385*44704f69SBart Van Assche      case $my_xlib in
5386*44704f69SBart Van Assche	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5387*44704f69SBart Van Assche	*) my_xabs=`pwd`"/$my_xlib" ;;
5388*44704f69SBart Van Assche      esac
5389*44704f69SBart Van Assche      func_basename "$my_xlib"
5390*44704f69SBart Van Assche      my_xlib=$func_basename_result
5391*44704f69SBart Van Assche      my_xlib_u=$my_xlib
5392*44704f69SBart Van Assche      while :; do
5393*44704f69SBart Van Assche        case " $extracted_archives " in
5394*44704f69SBart Van Assche	*" $my_xlib_u "*)
5395*44704f69SBart Van Assche	  func_arith $extracted_serial + 1
5396*44704f69SBart Van Assche	  extracted_serial=$func_arith_result
5397*44704f69SBart Van Assche	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5398*44704f69SBart Van Assche	*) break ;;
5399*44704f69SBart Van Assche	esac
5400*44704f69SBart Van Assche      done
5401*44704f69SBart Van Assche      extracted_archives="$extracted_archives $my_xlib_u"
5402*44704f69SBart Van Assche      my_xdir=$my_gentop/$my_xlib_u
5403*44704f69SBart Van Assche
5404*44704f69SBart Van Assche      func_mkdir_p "$my_xdir"
5405*44704f69SBart Van Assche
5406*44704f69SBart Van Assche      case $host in
5407*44704f69SBart Van Assche      *-darwin*)
5408*44704f69SBart Van Assche	func_verbose "Extracting $my_xabs"
5409*44704f69SBart Van Assche	# Do not bother doing anything if just a dry run
5410*44704f69SBart Van Assche	$opt_dry_run || {
5411*44704f69SBart Van Assche	  darwin_orig_dir=`pwd`
5412*44704f69SBart Van Assche	  cd $my_xdir || exit $?
5413*44704f69SBart Van Assche	  darwin_archive=$my_xabs
5414*44704f69SBart Van Assche	  darwin_curdir=`pwd`
5415*44704f69SBart Van Assche	  func_basename "$darwin_archive"
5416*44704f69SBart Van Assche	  darwin_base_archive=$func_basename_result
5417*44704f69SBart Van Assche	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5418*44704f69SBart Van Assche	  if test -n "$darwin_arches"; then
5419*44704f69SBart Van Assche	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5420*44704f69SBart Van Assche	    darwin_arch=
5421*44704f69SBart Van Assche	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5422*44704f69SBart Van Assche	    for darwin_arch in  $darwin_arches; do
5423*44704f69SBart Van Assche	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5424*44704f69SBart Van Assche	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5425*44704f69SBart Van Assche	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5426*44704f69SBart Van Assche	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5427*44704f69SBart Van Assche	      cd "$darwin_curdir"
5428*44704f69SBart Van Assche	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5429*44704f69SBart Van Assche	    done # $darwin_arches
5430*44704f69SBart Van Assche            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5431*44704f69SBart Van Assche	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5432*44704f69SBart Van Assche	    darwin_file=
5433*44704f69SBart Van Assche	    darwin_files=
5434*44704f69SBart Van Assche	    for darwin_file in $darwin_filelist; do
5435*44704f69SBart Van Assche	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5436*44704f69SBart Van Assche	      $LIPO -create -output "$darwin_file" $darwin_files
5437*44704f69SBart Van Assche	    done # $darwin_filelist
5438*44704f69SBart Van Assche	    $RM -rf unfat-$$
5439*44704f69SBart Van Assche	    cd "$darwin_orig_dir"
5440*44704f69SBart Van Assche	  else
5441*44704f69SBart Van Assche	    cd $darwin_orig_dir
5442*44704f69SBart Van Assche	    func_extract_an_archive "$my_xdir" "$my_xabs"
5443*44704f69SBart Van Assche	  fi # $darwin_arches
5444*44704f69SBart Van Assche	} # !$opt_dry_run
5445*44704f69SBart Van Assche	;;
5446*44704f69SBart Van Assche      *)
5447*44704f69SBart Van Assche        func_extract_an_archive "$my_xdir" "$my_xabs"
5448*44704f69SBart Van Assche	;;
5449*44704f69SBart Van Assche      esac
5450*44704f69SBart Van Assche      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5451*44704f69SBart Van Assche    done
5452*44704f69SBart Van Assche
5453*44704f69SBart Van Assche    func_extract_archives_result=$my_oldobjs
5454*44704f69SBart Van Assche}
5455*44704f69SBart Van Assche
5456*44704f69SBart Van Assche
5457*44704f69SBart Van Assche# func_emit_wrapper [arg=no]
5458*44704f69SBart Van Assche#
5459*44704f69SBart Van Assche# Emit a libtool wrapper script on stdout.
5460*44704f69SBart Van Assche# Don't directly open a file because we may want to
5461*44704f69SBart Van Assche# incorporate the script contents within a cygwin/mingw
5462*44704f69SBart Van Assche# wrapper executable.  Must ONLY be called from within
5463*44704f69SBart Van Assche# func_mode_link because it depends on a number of variables
5464*44704f69SBart Van Assche# set therein.
5465*44704f69SBart Van Assche#
5466*44704f69SBart Van Assche# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5467*44704f69SBart Van Assche# variable will take.  If 'yes', then the emitted script
5468*44704f69SBart Van Assche# will assume that the directory where it is stored is
5469*44704f69SBart Van Assche# the $objdir directory.  This is a cygwin/mingw-specific
5470*44704f69SBart Van Assche# behavior.
5471*44704f69SBart Van Asschefunc_emit_wrapper ()
5472*44704f69SBart Van Assche{
5473*44704f69SBart Van Assche	func_emit_wrapper_arg1=${1-no}
5474*44704f69SBart Van Assche
5475*44704f69SBart Van Assche	$ECHO "\
5476*44704f69SBart Van Assche#! $SHELL
5477*44704f69SBart Van Assche
5478*44704f69SBart Van Assche# $output - temporary wrapper script for $objdir/$outputname
5479*44704f69SBart Van Assche# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5480*44704f69SBart Van Assche#
5481*44704f69SBart Van Assche# The $output program cannot be directly executed until all the libtool
5482*44704f69SBart Van Assche# libraries that it depends on are installed.
5483*44704f69SBart Van Assche#
5484*44704f69SBart Van Assche# This wrapper script should never be moved out of the build directory.
5485*44704f69SBart Van Assche# If it is, it will not operate correctly.
5486*44704f69SBart Van Assche
5487*44704f69SBart Van Assche# Sed substitution that helps us do robust quoting.  It backslashifies
5488*44704f69SBart Van Assche# metacharacters that are still active within double-quoted strings.
5489*44704f69SBart Van Asschesed_quote_subst='$sed_quote_subst'
5490*44704f69SBart Van Assche
5491*44704f69SBart Van Assche# Be Bourne compatible
5492*44704f69SBart Van Asscheif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5493*44704f69SBart Van Assche  emulate sh
5494*44704f69SBart Van Assche  NULLCMD=:
5495*44704f69SBart Van Assche  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5496*44704f69SBart Van Assche  # is contrary to our usage.  Disable this feature.
5497*44704f69SBart Van Assche  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5498*44704f69SBart Van Assche  setopt NO_GLOB_SUBST
5499*44704f69SBart Van Asscheelse
5500*44704f69SBart Van Assche  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5501*44704f69SBart Van Asschefi
5502*44704f69SBart Van AsscheBIN_SH=xpg4; export BIN_SH # for Tru64
5503*44704f69SBart Van AsscheDUALCASE=1; export DUALCASE # for MKS sh
5504*44704f69SBart Van Assche
5505*44704f69SBart Van Assche# The HP-UX ksh and POSIX shell print the target directory to stdout
5506*44704f69SBart Van Assche# if CDPATH is set.
5507*44704f69SBart Van Assche(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5508*44704f69SBart Van Assche
5509*44704f69SBart Van Asscherelink_command=\"$relink_command\"
5510*44704f69SBart Van Assche
5511*44704f69SBart Van Assche# This environment variable determines our operation mode.
5512*44704f69SBart Van Asscheif test \"\$libtool_install_magic\" = \"$magic\"; then
5513*44704f69SBart Van Assche  # install mode needs the following variables:
5514*44704f69SBart Van Assche  generated_by_libtool_version='$macro_version'
5515*44704f69SBart Van Assche  notinst_deplibs='$notinst_deplibs'
5516*44704f69SBart Van Asscheelse
5517*44704f69SBart Van Assche  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5518*44704f69SBart Van Assche  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5519*44704f69SBart Van Assche    file=\"\$0\""
5520*44704f69SBart Van Assche
5521*44704f69SBart Van Assche    func_quote_arg pretty "$ECHO"
5522*44704f69SBart Van Assche    qECHO=$func_quote_arg_result
5523*44704f69SBart Van Assche    $ECHO "\
5524*44704f69SBart Van Assche
5525*44704f69SBart Van Assche# A function that is used when there is no print builtin or printf.
5526*44704f69SBart Van Asschefunc_fallback_echo ()
5527*44704f69SBart Van Assche{
5528*44704f69SBart Van Assche  eval 'cat <<_LTECHO_EOF
5529*44704f69SBart Van Assche\$1
5530*44704f69SBart Van Assche_LTECHO_EOF'
5531*44704f69SBart Van Assche}
5532*44704f69SBart Van Assche    ECHO=$qECHO
5533*44704f69SBart Van Assche  fi
5534*44704f69SBart Van Assche
5535*44704f69SBart Van Assche# Very basic option parsing. These options are (a) specific to
5536*44704f69SBart Van Assche# the libtool wrapper, (b) are identical between the wrapper
5537*44704f69SBart Van Assche# /script/ and the wrapper /executable/ that is used only on
5538*44704f69SBart Van Assche# windows platforms, and (c) all begin with the string "--lt-"
5539*44704f69SBart Van Assche# (application programs are unlikely to have options that match
5540*44704f69SBart Van Assche# this pattern).
5541*44704f69SBart Van Assche#
5542*44704f69SBart Van Assche# There are only two supported options: --lt-debug and
5543*44704f69SBart Van Assche# --lt-dump-script. There is, deliberately, no --lt-help.
5544*44704f69SBart Van Assche#
5545*44704f69SBart Van Assche# The first argument to this parsing function should be the
5546*44704f69SBart Van Assche# script's $0 value, followed by "$@".
5547*44704f69SBart Van Asschelt_option_debug=
5548*44704f69SBart Van Asschefunc_parse_lt_options ()
5549*44704f69SBart Van Assche{
5550*44704f69SBart Van Assche  lt_script_arg0=\$0
5551*44704f69SBart Van Assche  shift
5552*44704f69SBart Van Assche  for lt_opt
5553*44704f69SBart Van Assche  do
5554*44704f69SBart Van Assche    case \"\$lt_opt\" in
5555*44704f69SBart Van Assche    --lt-debug) lt_option_debug=1 ;;
5556*44704f69SBart Van Assche    --lt-dump-script)
5557*44704f69SBart Van Assche        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5558*44704f69SBart Van Assche        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5559*44704f69SBart Van Assche        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5560*44704f69SBart Van Assche        cat \"\$lt_dump_D/\$lt_dump_F\"
5561*44704f69SBart Van Assche        exit 0
5562*44704f69SBart Van Assche      ;;
5563*44704f69SBart Van Assche    --lt-*)
5564*44704f69SBart Van Assche        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5565*44704f69SBart Van Assche        exit 1
5566*44704f69SBart Van Assche      ;;
5567*44704f69SBart Van Assche    esac
5568*44704f69SBart Van Assche  done
5569*44704f69SBart Van Assche
5570*44704f69SBart Van Assche  # Print the debug banner immediately:
5571*44704f69SBart Van Assche  if test -n \"\$lt_option_debug\"; then
5572*44704f69SBart Van Assche    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5573*44704f69SBart Van Assche  fi
5574*44704f69SBart Van Assche}
5575*44704f69SBart Van Assche
5576*44704f69SBart Van Assche# Used when --lt-debug. Prints its arguments to stdout
5577*44704f69SBart Van Assche# (redirection is the responsibility of the caller)
5578*44704f69SBart Van Asschefunc_lt_dump_args ()
5579*44704f69SBart Van Assche{
5580*44704f69SBart Van Assche  lt_dump_args_N=1;
5581*44704f69SBart Van Assche  for lt_arg
5582*44704f69SBart Van Assche  do
5583*44704f69SBart Van Assche    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5584*44704f69SBart Van Assche    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5585*44704f69SBart Van Assche  done
5586*44704f69SBart Van Assche}
5587*44704f69SBart Van Assche
5588*44704f69SBart Van Assche# Core function for launching the target application
5589*44704f69SBart Van Asschefunc_exec_program_core ()
5590*44704f69SBart Van Assche{
5591*44704f69SBart Van Assche"
5592*44704f69SBart Van Assche  case $host in
5593*44704f69SBart Van Assche  # Backslashes separate directories on plain windows
5594*44704f69SBart Van Assche  *-*-mingw | *-*-os2* | *-cegcc*)
5595*44704f69SBart Van Assche    $ECHO "\
5596*44704f69SBart Van Assche      if test -n \"\$lt_option_debug\"; then
5597*44704f69SBart Van Assche        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5598*44704f69SBart Van Assche        func_lt_dump_args \${1+\"\$@\"} 1>&2
5599*44704f69SBart Van Assche      fi
5600*44704f69SBart Van Assche      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5601*44704f69SBart Van Assche"
5602*44704f69SBart Van Assche    ;;
5603*44704f69SBart Van Assche
5604*44704f69SBart Van Assche  *)
5605*44704f69SBart Van Assche    $ECHO "\
5606*44704f69SBart Van Assche      if test -n \"\$lt_option_debug\"; then
5607*44704f69SBart Van Assche        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5608*44704f69SBart Van Assche        func_lt_dump_args \${1+\"\$@\"} 1>&2
5609*44704f69SBart Van Assche      fi
5610*44704f69SBart Van Assche      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5611*44704f69SBart Van Assche"
5612*44704f69SBart Van Assche    ;;
5613*44704f69SBart Van Assche  esac
5614*44704f69SBart Van Assche  $ECHO "\
5615*44704f69SBart Van Assche      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5616*44704f69SBart Van Assche      exit 1
5617*44704f69SBart Van Assche}
5618*44704f69SBart Van Assche
5619*44704f69SBart Van Assche# A function to encapsulate launching the target application
5620*44704f69SBart Van Assche# Strips options in the --lt-* namespace from \$@ and
5621*44704f69SBart Van Assche# launches target application with the remaining arguments.
5622*44704f69SBart Van Asschefunc_exec_program ()
5623*44704f69SBart Van Assche{
5624*44704f69SBart Van Assche  case \" \$* \" in
5625*44704f69SBart Van Assche  *\\ --lt-*)
5626*44704f69SBart Van Assche    for lt_wr_arg
5627*44704f69SBart Van Assche    do
5628*44704f69SBart Van Assche      case \$lt_wr_arg in
5629*44704f69SBart Van Assche      --lt-*) ;;
5630*44704f69SBart Van Assche      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5631*44704f69SBart Van Assche      esac
5632*44704f69SBart Van Assche      shift
5633*44704f69SBart Van Assche    done ;;
5634*44704f69SBart Van Assche  esac
5635*44704f69SBart Van Assche  func_exec_program_core \${1+\"\$@\"}
5636*44704f69SBart Van Assche}
5637*44704f69SBart Van Assche
5638*44704f69SBart Van Assche  # Parse options
5639*44704f69SBart Van Assche  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5640*44704f69SBart Van Assche
5641*44704f69SBart Van Assche  # Find the directory that this script lives in.
5642*44704f69SBart Van Assche  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5643*44704f69SBart Van Assche  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5644*44704f69SBart Van Assche
5645*44704f69SBart Van Assche  # Follow symbolic links until we get to the real thisdir.
5646*44704f69SBart Van Assche  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5647*44704f69SBart Van Assche  while test -n \"\$file\"; do
5648*44704f69SBart Van Assche    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5649*44704f69SBart Van Assche
5650*44704f69SBart Van Assche    # If there was a directory component, then change thisdir.
5651*44704f69SBart Van Assche    if test \"x\$destdir\" != \"x\$file\"; then
5652*44704f69SBart Van Assche      case \"\$destdir\" in
5653*44704f69SBart Van Assche      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5654*44704f69SBart Van Assche      *) thisdir=\"\$thisdir/\$destdir\" ;;
5655*44704f69SBart Van Assche      esac
5656*44704f69SBart Van Assche    fi
5657*44704f69SBart Van Assche
5658*44704f69SBart Van Assche    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5659*44704f69SBart Van Assche    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5660*44704f69SBart Van Assche  done
5661*44704f69SBart Van Assche
5662*44704f69SBart Van Assche  # Usually 'no', except on cygwin/mingw when embedded into
5663*44704f69SBart Van Assche  # the cwrapper.
5664*44704f69SBart Van Assche  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5665*44704f69SBart Van Assche  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5666*44704f69SBart Van Assche    # special case for '.'
5667*44704f69SBart Van Assche    if test \"\$thisdir\" = \".\"; then
5668*44704f69SBart Van Assche      thisdir=\`pwd\`
5669*44704f69SBart Van Assche    fi
5670*44704f69SBart Van Assche    # remove .libs from thisdir
5671*44704f69SBart Van Assche    case \"\$thisdir\" in
5672*44704f69SBart Van Assche    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5673*44704f69SBart Van Assche    $objdir )   thisdir=. ;;
5674*44704f69SBart Van Assche    esac
5675*44704f69SBart Van Assche  fi
5676*44704f69SBart Van Assche
5677*44704f69SBart Van Assche  # Try to get the absolute directory name.
5678*44704f69SBart Van Assche  absdir=\`cd \"\$thisdir\" && pwd\`
5679*44704f69SBart Van Assche  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5680*44704f69SBart Van Assche"
5681*44704f69SBart Van Assche
5682*44704f69SBart Van Assche	if test yes = "$fast_install"; then
5683*44704f69SBart Van Assche	  $ECHO "\
5684*44704f69SBart Van Assche  program=lt-'$outputname'$exeext
5685*44704f69SBart Van Assche  progdir=\"\$thisdir/$objdir\"
5686*44704f69SBart Van Assche
5687*44704f69SBart Van Assche  if test ! -f \"\$progdir/\$program\" ||
5688*44704f69SBart Van Assche     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5689*44704f69SBart Van Assche       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5690*44704f69SBart Van Assche
5691*44704f69SBart Van Assche    file=\"\$\$-\$program\"
5692*44704f69SBart Van Assche
5693*44704f69SBart Van Assche    if test ! -d \"\$progdir\"; then
5694*44704f69SBart Van Assche      $MKDIR \"\$progdir\"
5695*44704f69SBart Van Assche    else
5696*44704f69SBart Van Assche      $RM \"\$progdir/\$file\"
5697*44704f69SBart Van Assche    fi"
5698*44704f69SBart Van Assche
5699*44704f69SBart Van Assche	  $ECHO "\
5700*44704f69SBart Van Assche
5701*44704f69SBart Van Assche    # relink executable if necessary
5702*44704f69SBart Van Assche    if test -n \"\$relink_command\"; then
5703*44704f69SBart Van Assche      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5704*44704f69SBart Van Assche      else
5705*44704f69SBart Van Assche	\$ECHO \"\$relink_command_output\" >&2
5706*44704f69SBart Van Assche	$RM \"\$progdir/\$file\"
5707*44704f69SBart Van Assche	exit 1
5708*44704f69SBart Van Assche      fi
5709*44704f69SBart Van Assche    fi
5710*44704f69SBart Van Assche
5711*44704f69SBart Van Assche    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5712*44704f69SBart Van Assche    { $RM \"\$progdir/\$program\";
5713*44704f69SBart Van Assche      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5714*44704f69SBart Van Assche    $RM \"\$progdir/\$file\"
5715*44704f69SBart Van Assche  fi"
5716*44704f69SBart Van Assche	else
5717*44704f69SBart Van Assche	  $ECHO "\
5718*44704f69SBart Van Assche  program='$outputname'
5719*44704f69SBart Van Assche  progdir=\"\$thisdir/$objdir\"
5720*44704f69SBart Van Assche"
5721*44704f69SBart Van Assche	fi
5722*44704f69SBart Van Assche
5723*44704f69SBart Van Assche	$ECHO "\
5724*44704f69SBart Van Assche
5725*44704f69SBart Van Assche  if test -f \"\$progdir/\$program\"; then"
5726*44704f69SBart Van Assche
5727*44704f69SBart Van Assche	# fixup the dll searchpath if we need to.
5728*44704f69SBart Van Assche	#
5729*44704f69SBart Van Assche	# Fix the DLL searchpath if we need to.  Do this before prepending
5730*44704f69SBart Van Assche	# to shlibpath, because on Windows, both are PATH and uninstalled
5731*44704f69SBart Van Assche	# libraries must come first.
5732*44704f69SBart Van Assche	if test -n "$dllsearchpath"; then
5733*44704f69SBart Van Assche	  $ECHO "\
5734*44704f69SBart Van Assche    # Add the dll search path components to the executable PATH
5735*44704f69SBart Van Assche    PATH=$dllsearchpath:\$PATH
5736*44704f69SBart Van Assche"
5737*44704f69SBart Van Assche	fi
5738*44704f69SBart Van Assche
5739*44704f69SBart Van Assche	# Export our shlibpath_var if we have one.
5740*44704f69SBart Van Assche	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5741*44704f69SBart Van Assche	  $ECHO "\
5742*44704f69SBart Van Assche    # Add our own library path to $shlibpath_var
5743*44704f69SBart Van Assche    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5744*44704f69SBart Van Assche
5745*44704f69SBart Van Assche    # Some systems cannot cope with colon-terminated $shlibpath_var
5746*44704f69SBart Van Assche    # The second colon is a workaround for a bug in BeOS R4 sed
5747*44704f69SBart Van Assche    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5748*44704f69SBart Van Assche
5749*44704f69SBart Van Assche    export $shlibpath_var
5750*44704f69SBart Van Assche"
5751*44704f69SBart Van Assche	fi
5752*44704f69SBart Van Assche
5753*44704f69SBart Van Assche	$ECHO "\
5754*44704f69SBart Van Assche    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5755*44704f69SBart Van Assche      # Run the actual program with our arguments.
5756*44704f69SBart Van Assche      func_exec_program \${1+\"\$@\"}
5757*44704f69SBart Van Assche    fi
5758*44704f69SBart Van Assche  else
5759*44704f69SBart Van Assche    # The program doesn't exist.
5760*44704f69SBart Van Assche    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5761*44704f69SBart Van Assche    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5762*44704f69SBart Van Assche    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5763*44704f69SBart Van Assche    exit 1
5764*44704f69SBart Van Assche  fi
5765*44704f69SBart Van Asschefi\
5766*44704f69SBart Van Assche"
5767*44704f69SBart Van Assche}
5768*44704f69SBart Van Assche
5769*44704f69SBart Van Assche
5770*44704f69SBart Van Assche# func_emit_cwrapperexe_src
5771*44704f69SBart Van Assche# emit the source code for a wrapper executable on stdout
5772*44704f69SBart Van Assche# Must ONLY be called from within func_mode_link because
5773*44704f69SBart Van Assche# it depends on a number of variable set therein.
5774*44704f69SBart Van Asschefunc_emit_cwrapperexe_src ()
5775*44704f69SBart Van Assche{
5776*44704f69SBart Van Assche	cat <<EOF
5777*44704f69SBart Van Assche
5778*44704f69SBart Van Assche/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5779*44704f69SBart Van Assche   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5780*44704f69SBart Van Assche
5781*44704f69SBart Van Assche   The $output program cannot be directly executed until all the libtool
5782*44704f69SBart Van Assche   libraries that it depends on are installed.
5783*44704f69SBart Van Assche
5784*44704f69SBart Van Assche   This wrapper executable should never be moved out of the build directory.
5785*44704f69SBart Van Assche   If it is, it will not operate correctly.
5786*44704f69SBart Van Assche*/
5787*44704f69SBart Van AsscheEOF
5788*44704f69SBart Van Assche	    cat <<"EOF"
5789*44704f69SBart Van Assche#ifdef _MSC_VER
5790*44704f69SBart Van Assche# define _CRT_SECURE_NO_DEPRECATE 1
5791*44704f69SBart Van Assche#endif
5792*44704f69SBart Van Assche#include <stdio.h>
5793*44704f69SBart Van Assche#include <stdlib.h>
5794*44704f69SBart Van Assche#ifdef _MSC_VER
5795*44704f69SBart Van Assche# include <direct.h>
5796*44704f69SBart Van Assche# include <process.h>
5797*44704f69SBart Van Assche# include <io.h>
5798*44704f69SBart Van Assche#else
5799*44704f69SBart Van Assche# include <unistd.h>
5800*44704f69SBart Van Assche# include <stdint.h>
5801*44704f69SBart Van Assche# ifdef __CYGWIN__
5802*44704f69SBart Van Assche#  include <io.h>
5803*44704f69SBart Van Assche# endif
5804*44704f69SBart Van Assche#endif
5805*44704f69SBart Van Assche#include <malloc.h>
5806*44704f69SBart Van Assche#include <stdarg.h>
5807*44704f69SBart Van Assche#include <assert.h>
5808*44704f69SBart Van Assche#include <string.h>
5809*44704f69SBart Van Assche#include <ctype.h>
5810*44704f69SBart Van Assche#include <errno.h>
5811*44704f69SBart Van Assche#include <fcntl.h>
5812*44704f69SBart Van Assche#include <sys/stat.h>
5813*44704f69SBart Van Assche
5814*44704f69SBart Van Assche#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5815*44704f69SBart Van Assche
5816*44704f69SBart Van Assche/* declarations of non-ANSI functions */
5817*44704f69SBart Van Assche#if defined __MINGW32__
5818*44704f69SBart Van Assche# ifdef __STRICT_ANSI__
5819*44704f69SBart Van Asscheint _putenv (const char *);
5820*44704f69SBart Van Assche# endif
5821*44704f69SBart Van Assche#elif defined __CYGWIN__
5822*44704f69SBart Van Assche# ifdef __STRICT_ANSI__
5823*44704f69SBart Van Asschechar *realpath (const char *, char *);
5824*44704f69SBart Van Asscheint putenv (char *);
5825*44704f69SBart Van Asscheint setenv (const char *, const char *, int);
5826*44704f69SBart Van Assche# endif
5827*44704f69SBart Van Assche/* #elif defined other_platform || defined ... */
5828*44704f69SBart Van Assche#endif
5829*44704f69SBart Van Assche
5830*44704f69SBart Van Assche/* portability defines, excluding path handling macros */
5831*44704f69SBart Van Assche#if defined _MSC_VER
5832*44704f69SBart Van Assche# define setmode _setmode
5833*44704f69SBart Van Assche# define stat    _stat
5834*44704f69SBart Van Assche# define chmod   _chmod
5835*44704f69SBart Van Assche# define getcwd  _getcwd
5836*44704f69SBart Van Assche# define putenv  _putenv
5837*44704f69SBart Van Assche# define S_IXUSR _S_IEXEC
5838*44704f69SBart Van Assche#elif defined __MINGW32__
5839*44704f69SBart Van Assche# define setmode _setmode
5840*44704f69SBart Van Assche# define stat    _stat
5841*44704f69SBart Van Assche# define chmod   _chmod
5842*44704f69SBart Van Assche# define getcwd  _getcwd
5843*44704f69SBart Van Assche# define putenv  _putenv
5844*44704f69SBart Van Assche#elif defined __CYGWIN__
5845*44704f69SBart Van Assche# define HAVE_SETENV
5846*44704f69SBart Van Assche# define FOPEN_WB "wb"
5847*44704f69SBart Van Assche/* #elif defined other platforms ... */
5848*44704f69SBart Van Assche#endif
5849*44704f69SBart Van Assche
5850*44704f69SBart Van Assche#if defined PATH_MAX
5851*44704f69SBart Van Assche# define LT_PATHMAX PATH_MAX
5852*44704f69SBart Van Assche#elif defined MAXPATHLEN
5853*44704f69SBart Van Assche# define LT_PATHMAX MAXPATHLEN
5854*44704f69SBart Van Assche#else
5855*44704f69SBart Van Assche# define LT_PATHMAX 1024
5856*44704f69SBart Van Assche#endif
5857*44704f69SBart Van Assche
5858*44704f69SBart Van Assche#ifndef S_IXOTH
5859*44704f69SBart Van Assche# define S_IXOTH 0
5860*44704f69SBart Van Assche#endif
5861*44704f69SBart Van Assche#ifndef S_IXGRP
5862*44704f69SBart Van Assche# define S_IXGRP 0
5863*44704f69SBart Van Assche#endif
5864*44704f69SBart Van Assche
5865*44704f69SBart Van Assche/* path handling portability macros */
5866*44704f69SBart Van Assche#ifndef DIR_SEPARATOR
5867*44704f69SBart Van Assche# define DIR_SEPARATOR '/'
5868*44704f69SBart Van Assche# define PATH_SEPARATOR ':'
5869*44704f69SBart Van Assche#endif
5870*44704f69SBart Van Assche
5871*44704f69SBart Van Assche#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5872*44704f69SBart Van Assche  defined __OS2__
5873*44704f69SBart Van Assche# define HAVE_DOS_BASED_FILE_SYSTEM
5874*44704f69SBart Van Assche# define FOPEN_WB "wb"
5875*44704f69SBart Van Assche# ifndef DIR_SEPARATOR_2
5876*44704f69SBart Van Assche#  define DIR_SEPARATOR_2 '\\'
5877*44704f69SBart Van Assche# endif
5878*44704f69SBart Van Assche# ifndef PATH_SEPARATOR_2
5879*44704f69SBart Van Assche#  define PATH_SEPARATOR_2 ';'
5880*44704f69SBart Van Assche# endif
5881*44704f69SBart Van Assche#endif
5882*44704f69SBart Van Assche
5883*44704f69SBart Van Assche#ifndef DIR_SEPARATOR_2
5884*44704f69SBart Van Assche# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5885*44704f69SBart Van Assche#else /* DIR_SEPARATOR_2 */
5886*44704f69SBart Van Assche# define IS_DIR_SEPARATOR(ch) \
5887*44704f69SBart Van Assche	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5888*44704f69SBart Van Assche#endif /* DIR_SEPARATOR_2 */
5889*44704f69SBart Van Assche
5890*44704f69SBart Van Assche#ifndef PATH_SEPARATOR_2
5891*44704f69SBart Van Assche# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5892*44704f69SBart Van Assche#else /* PATH_SEPARATOR_2 */
5893*44704f69SBart Van Assche# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5894*44704f69SBart Van Assche#endif /* PATH_SEPARATOR_2 */
5895*44704f69SBart Van Assche
5896*44704f69SBart Van Assche#ifndef FOPEN_WB
5897*44704f69SBart Van Assche# define FOPEN_WB "w"
5898*44704f69SBart Van Assche#endif
5899*44704f69SBart Van Assche#ifndef _O_BINARY
5900*44704f69SBart Van Assche# define _O_BINARY 0
5901*44704f69SBart Van Assche#endif
5902*44704f69SBart Van Assche
5903*44704f69SBart Van Assche#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5904*44704f69SBart Van Assche#define XFREE(stale) do { \
5905*44704f69SBart Van Assche  if (stale) { free (stale); stale = 0; } \
5906*44704f69SBart Van Assche} while (0)
5907*44704f69SBart Van Assche
5908*44704f69SBart Van Assche#if defined LT_DEBUGWRAPPER
5909*44704f69SBart Van Asschestatic int lt_debug = 1;
5910*44704f69SBart Van Assche#else
5911*44704f69SBart Van Asschestatic int lt_debug = 0;
5912*44704f69SBart Van Assche#endif
5913*44704f69SBart Van Assche
5914*44704f69SBart Van Asscheconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5915*44704f69SBart Van Assche
5916*44704f69SBart Van Asschevoid *xmalloc (size_t num);
5917*44704f69SBart Van Asschechar *xstrdup (const char *string);
5918*44704f69SBart Van Asscheconst char *base_name (const char *name);
5919*44704f69SBart Van Asschechar *find_executable (const char *wrapper);
5920*44704f69SBart Van Asschechar *chase_symlinks (const char *pathspec);
5921*44704f69SBart Van Asscheint make_executable (const char *path);
5922*44704f69SBart Van Asscheint check_executable (const char *path);
5923*44704f69SBart Van Asschechar *strendzap (char *str, const char *pat);
5924*44704f69SBart Van Asschevoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5925*44704f69SBart Van Asschevoid lt_fatal (const char *file, int line, const char *message, ...);
5926*44704f69SBart Van Asschestatic const char *nonnull (const char *s);
5927*44704f69SBart Van Asschestatic const char *nonempty (const char *s);
5928*44704f69SBart Van Asschevoid lt_setenv (const char *name, const char *value);
5929*44704f69SBart Van Asschechar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5930*44704f69SBart Van Asschevoid lt_update_exe_path (const char *name, const char *value);
5931*44704f69SBart Van Asschevoid lt_update_lib_path (const char *name, const char *value);
5932*44704f69SBart Van Asschechar **prepare_spawn (char **argv);
5933*44704f69SBart Van Asschevoid lt_dump_script (FILE *f);
5934*44704f69SBart Van AsscheEOF
5935*44704f69SBart Van Assche
5936*44704f69SBart Van Assche	    cat <<EOF
5937*44704f69SBart Van Assche#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5938*44704f69SBart Van Assche# define externally_visible volatile
5939*44704f69SBart Van Assche#else
5940*44704f69SBart Van Assche# define externally_visible __attribute__((externally_visible)) volatile
5941*44704f69SBart Van Assche#endif
5942*44704f69SBart Van Asscheexternally_visible const char * MAGIC_EXE = "$magic_exe";
5943*44704f69SBart Van Asscheconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5944*44704f69SBart Van AsscheEOF
5945*44704f69SBart Van Assche
5946*44704f69SBart Van Assche	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5947*44704f69SBart Van Assche              func_to_host_path "$temp_rpath"
5948*44704f69SBart Van Assche	      cat <<EOF
5949*44704f69SBart Van Asscheconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5950*44704f69SBart Van AsscheEOF
5951*44704f69SBart Van Assche	    else
5952*44704f69SBart Van Assche	      cat <<"EOF"
5953*44704f69SBart Van Asscheconst char * LIB_PATH_VALUE   = "";
5954*44704f69SBart Van AsscheEOF
5955*44704f69SBart Van Assche	    fi
5956*44704f69SBart Van Assche
5957*44704f69SBart Van Assche	    if test -n "$dllsearchpath"; then
5958*44704f69SBart Van Assche              func_to_host_path "$dllsearchpath:"
5959*44704f69SBart Van Assche	      cat <<EOF
5960*44704f69SBart Van Asscheconst char * EXE_PATH_VARNAME = "PATH";
5961*44704f69SBart Van Asscheconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5962*44704f69SBart Van AsscheEOF
5963*44704f69SBart Van Assche	    else
5964*44704f69SBart Van Assche	      cat <<"EOF"
5965*44704f69SBart Van Asscheconst char * EXE_PATH_VARNAME = "";
5966*44704f69SBart Van Asscheconst char * EXE_PATH_VALUE   = "";
5967*44704f69SBart Van AsscheEOF
5968*44704f69SBart Van Assche	    fi
5969*44704f69SBart Van Assche
5970*44704f69SBart Van Assche	    if test yes = "$fast_install"; then
5971*44704f69SBart Van Assche	      cat <<EOF
5972*44704f69SBart Van Asscheconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5973*44704f69SBart Van AsscheEOF
5974*44704f69SBart Van Assche	    else
5975*44704f69SBart Van Assche	      cat <<EOF
5976*44704f69SBart Van Asscheconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5977*44704f69SBart Van AsscheEOF
5978*44704f69SBart Van Assche	    fi
5979*44704f69SBart Van Assche
5980*44704f69SBart Van Assche
5981*44704f69SBart Van Assche	    cat <<"EOF"
5982*44704f69SBart Van Assche
5983*44704f69SBart Van Assche#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5984*44704f69SBart Van Assche
5985*44704f69SBart Van Asschestatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5986*44704f69SBart Van Asschestatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5987*44704f69SBart Van Asschestatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5988*44704f69SBart Van Assche
5989*44704f69SBart Van Asscheint
5990*44704f69SBart Van Asschemain (int argc, char *argv[])
5991*44704f69SBart Van Assche{
5992*44704f69SBart Van Assche  char **newargz;
5993*44704f69SBart Van Assche  int  newargc;
5994*44704f69SBart Van Assche  char *tmp_pathspec;
5995*44704f69SBart Van Assche  char *actual_cwrapper_path;
5996*44704f69SBart Van Assche  char *actual_cwrapper_name;
5997*44704f69SBart Van Assche  char *target_name;
5998*44704f69SBart Van Assche  char *lt_argv_zero;
5999*44704f69SBart Van Assche  int rval = 127;
6000*44704f69SBart Van Assche
6001*44704f69SBart Van Assche  int i;
6002*44704f69SBart Van Assche
6003*44704f69SBart Van Assche  program_name = (char *) xstrdup (base_name (argv[0]));
6004*44704f69SBart Van Assche  newargz = XMALLOC (char *, (size_t) argc + 1);
6005*44704f69SBart Van Assche
6006*44704f69SBart Van Assche  /* very simple arg parsing; don't want to rely on getopt
6007*44704f69SBart Van Assche   * also, copy all non cwrapper options to newargz, except
6008*44704f69SBart Van Assche   * argz[0], which is handled differently
6009*44704f69SBart Van Assche   */
6010*44704f69SBart Van Assche  newargc=0;
6011*44704f69SBart Van Assche  for (i = 1; i < argc; i++)
6012*44704f69SBart Van Assche    {
6013*44704f69SBart Van Assche      if (STREQ (argv[i], dumpscript_opt))
6014*44704f69SBart Van Assche	{
6015*44704f69SBart Van AsscheEOF
6016*44704f69SBart Van Assche	    case $host in
6017*44704f69SBart Van Assche	      *mingw* | *cygwin* )
6018*44704f69SBart Van Assche		# make stdout use "unix" line endings
6019*44704f69SBart Van Assche		echo "          setmode(1,_O_BINARY);"
6020*44704f69SBart Van Assche		;;
6021*44704f69SBart Van Assche	      esac
6022*44704f69SBart Van Assche
6023*44704f69SBart Van Assche	    cat <<"EOF"
6024*44704f69SBart Van Assche	  lt_dump_script (stdout);
6025*44704f69SBart Van Assche	  return 0;
6026*44704f69SBart Van Assche	}
6027*44704f69SBart Van Assche      if (STREQ (argv[i], debug_opt))
6028*44704f69SBart Van Assche	{
6029*44704f69SBart Van Assche          lt_debug = 1;
6030*44704f69SBart Van Assche          continue;
6031*44704f69SBart Van Assche	}
6032*44704f69SBart Van Assche      if (STREQ (argv[i], ltwrapper_option_prefix))
6033*44704f69SBart Van Assche        {
6034*44704f69SBart Van Assche          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6035*44704f69SBart Van Assche             namespace, but it is not one of the ones we know about and
6036*44704f69SBart Van Assche             have already dealt with, above (inluding dump-script), then
6037*44704f69SBart Van Assche             report an error. Otherwise, targets might begin to believe
6038*44704f69SBart Van Assche             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6039*44704f69SBart Van Assche             namespace. The first time any user complains about this, we'll
6040*44704f69SBart Van Assche             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6041*44704f69SBart Van Assche             or a configure.ac-settable value.
6042*44704f69SBart Van Assche           */
6043*44704f69SBart Van Assche          lt_fatal (__FILE__, __LINE__,
6044*44704f69SBart Van Assche		    "unrecognized %s option: '%s'",
6045*44704f69SBart Van Assche                    ltwrapper_option_prefix, argv[i]);
6046*44704f69SBart Van Assche        }
6047*44704f69SBart Van Assche      /* otherwise ... */
6048*44704f69SBart Van Assche      newargz[++newargc] = xstrdup (argv[i]);
6049*44704f69SBart Van Assche    }
6050*44704f69SBart Van Assche  newargz[++newargc] = NULL;
6051*44704f69SBart Van Assche
6052*44704f69SBart Van AsscheEOF
6053*44704f69SBart Van Assche	    cat <<EOF
6054*44704f69SBart Van Assche  /* The GNU banner must be the first non-error debug message */
6055*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6056*44704f69SBart Van AsscheEOF
6057*44704f69SBart Van Assche	    cat <<"EOF"
6058*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6059*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
6060*44704f69SBart Van Assche
6061*44704f69SBart Van Assche  tmp_pathspec = find_executable (argv[0]);
6062*44704f69SBart Van Assche  if (tmp_pathspec == NULL)
6063*44704f69SBart Van Assche    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6064*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__,
6065*44704f69SBart Van Assche                  "(main) found exe (before symlink chase) at: %s\n",
6066*44704f69SBart Van Assche		  tmp_pathspec);
6067*44704f69SBart Van Assche
6068*44704f69SBart Van Assche  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6069*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__,
6070*44704f69SBart Van Assche                  "(main) found exe (after symlink chase) at: %s\n",
6071*44704f69SBart Van Assche		  actual_cwrapper_path);
6072*44704f69SBart Van Assche  XFREE (tmp_pathspec);
6073*44704f69SBart Van Assche
6074*44704f69SBart Van Assche  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6075*44704f69SBart Van Assche  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6076*44704f69SBart Van Assche
6077*44704f69SBart Van Assche  /* wrapper name transforms */
6078*44704f69SBart Van Assche  strendzap (actual_cwrapper_name, ".exe");
6079*44704f69SBart Van Assche  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6080*44704f69SBart Van Assche  XFREE (actual_cwrapper_name);
6081*44704f69SBart Van Assche  actual_cwrapper_name = tmp_pathspec;
6082*44704f69SBart Van Assche  tmp_pathspec = 0;
6083*44704f69SBart Van Assche
6084*44704f69SBart Van Assche  /* target_name transforms -- use actual target program name; might have lt- prefix */
6085*44704f69SBart Van Assche  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6086*44704f69SBart Van Assche  strendzap (target_name, ".exe");
6087*44704f69SBart Van Assche  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6088*44704f69SBart Van Assche  XFREE (target_name);
6089*44704f69SBart Van Assche  target_name = tmp_pathspec;
6090*44704f69SBart Van Assche  tmp_pathspec = 0;
6091*44704f69SBart Van Assche
6092*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__,
6093*44704f69SBart Van Assche		  "(main) libtool target name: %s\n",
6094*44704f69SBart Van Assche		  target_name);
6095*44704f69SBart Van AsscheEOF
6096*44704f69SBart Van Assche
6097*44704f69SBart Van Assche	    cat <<EOF
6098*44704f69SBart Van Assche  newargz[0] =
6099*44704f69SBart Van Assche    XMALLOC (char, (strlen (actual_cwrapper_path) +
6100*44704f69SBart Van Assche		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6101*44704f69SBart Van Assche  strcpy (newargz[0], actual_cwrapper_path);
6102*44704f69SBart Van Assche  strcat (newargz[0], "$objdir");
6103*44704f69SBart Van Assche  strcat (newargz[0], "/");
6104*44704f69SBart Van AsscheEOF
6105*44704f69SBart Van Assche
6106*44704f69SBart Van Assche	    cat <<"EOF"
6107*44704f69SBart Van Assche  /* stop here, and copy so we don't have to do this twice */
6108*44704f69SBart Van Assche  tmp_pathspec = xstrdup (newargz[0]);
6109*44704f69SBart Van Assche
6110*44704f69SBart Van Assche  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6111*44704f69SBart Van Assche  strcat (newargz[0], actual_cwrapper_name);
6112*44704f69SBart Van Assche
6113*44704f69SBart Van Assche  /* DO want the lt- prefix here if it exists, so use target_name */
6114*44704f69SBart Van Assche  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6115*44704f69SBart Van Assche  XFREE (tmp_pathspec);
6116*44704f69SBart Van Assche  tmp_pathspec = NULL;
6117*44704f69SBart Van AsscheEOF
6118*44704f69SBart Van Assche
6119*44704f69SBart Van Assche	    case $host_os in
6120*44704f69SBart Van Assche	      mingw*)
6121*44704f69SBart Van Assche	    cat <<"EOF"
6122*44704f69SBart Van Assche  {
6123*44704f69SBart Van Assche    char* p;
6124*44704f69SBart Van Assche    while ((p = strchr (newargz[0], '\\')) != NULL)
6125*44704f69SBart Van Assche      {
6126*44704f69SBart Van Assche	*p = '/';
6127*44704f69SBart Van Assche      }
6128*44704f69SBart Van Assche    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6129*44704f69SBart Van Assche      {
6130*44704f69SBart Van Assche	*p = '/';
6131*44704f69SBart Van Assche      }
6132*44704f69SBart Van Assche  }
6133*44704f69SBart Van AsscheEOF
6134*44704f69SBart Van Assche	    ;;
6135*44704f69SBart Van Assche	    esac
6136*44704f69SBart Van Assche
6137*44704f69SBart Van Assche	    cat <<"EOF"
6138*44704f69SBart Van Assche  XFREE (target_name);
6139*44704f69SBart Van Assche  XFREE (actual_cwrapper_path);
6140*44704f69SBart Van Assche  XFREE (actual_cwrapper_name);
6141*44704f69SBart Van Assche
6142*44704f69SBart Van Assche  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6143*44704f69SBart Van Assche  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6144*44704f69SBart Van Assche  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6145*44704f69SBart Van Assche     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6146*44704f69SBart Van Assche     because on Windows, both *_VARNAMEs are PATH but uninstalled
6147*44704f69SBart Van Assche     libraries must come first. */
6148*44704f69SBart Van Assche  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6149*44704f69SBart Van Assche  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
6150*44704f69SBart Van Assche
6151*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6152*44704f69SBart Van Assche		  nonnull (lt_argv_zero));
6153*44704f69SBart Van Assche  for (i = 0; i < newargc; i++)
6154*44704f69SBart Van Assche    {
6155*44704f69SBart Van Assche      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6156*44704f69SBart Van Assche		      i, nonnull (newargz[i]));
6157*44704f69SBart Van Assche    }
6158*44704f69SBart Van Assche
6159*44704f69SBart Van AsscheEOF
6160*44704f69SBart Van Assche
6161*44704f69SBart Van Assche	    case $host_os in
6162*44704f69SBart Van Assche	      mingw*)
6163*44704f69SBart Van Assche		cat <<"EOF"
6164*44704f69SBart Van Assche  /* execv doesn't actually work on mingw as expected on unix */
6165*44704f69SBart Van Assche  newargz = prepare_spawn (newargz);
6166*44704f69SBart Van Assche  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6167*44704f69SBart Van Assche  if (rval == -1)
6168*44704f69SBart Van Assche    {
6169*44704f69SBart Van Assche      /* failed to start process */
6170*44704f69SBart Van Assche      lt_debugprintf (__FILE__, __LINE__,
6171*44704f69SBart Van Assche		      "(main) failed to launch target \"%s\": %s\n",
6172*44704f69SBart Van Assche		      lt_argv_zero, nonnull (strerror (errno)));
6173*44704f69SBart Van Assche      return 127;
6174*44704f69SBart Van Assche    }
6175*44704f69SBart Van Assche  return rval;
6176*44704f69SBart Van AsscheEOF
6177*44704f69SBart Van Assche		;;
6178*44704f69SBart Van Assche	      *)
6179*44704f69SBart Van Assche		cat <<"EOF"
6180*44704f69SBart Van Assche  execv (lt_argv_zero, newargz);
6181*44704f69SBart Van Assche  return rval; /* =127, but avoids unused variable warning */
6182*44704f69SBart Van AsscheEOF
6183*44704f69SBart Van Assche		;;
6184*44704f69SBart Van Assche	    esac
6185*44704f69SBart Van Assche
6186*44704f69SBart Van Assche	    cat <<"EOF"
6187*44704f69SBart Van Assche}
6188*44704f69SBart Van Assche
6189*44704f69SBart Van Asschevoid *
6190*44704f69SBart Van Asschexmalloc (size_t num)
6191*44704f69SBart Van Assche{
6192*44704f69SBart Van Assche  void *p = (void *) malloc (num);
6193*44704f69SBart Van Assche  if (!p)
6194*44704f69SBart Van Assche    lt_fatal (__FILE__, __LINE__, "memory exhausted");
6195*44704f69SBart Van Assche
6196*44704f69SBart Van Assche  return p;
6197*44704f69SBart Van Assche}
6198*44704f69SBart Van Assche
6199*44704f69SBart Van Asschechar *
6200*44704f69SBart Van Asschexstrdup (const char *string)
6201*44704f69SBart Van Assche{
6202*44704f69SBart Van Assche  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6203*44704f69SBart Van Assche			  string) : NULL;
6204*44704f69SBart Van Assche}
6205*44704f69SBart Van Assche
6206*44704f69SBart Van Asscheconst char *
6207*44704f69SBart Van Asschebase_name (const char *name)
6208*44704f69SBart Van Assche{
6209*44704f69SBart Van Assche  const char *base;
6210*44704f69SBart Van Assche
6211*44704f69SBart Van Assche#if defined HAVE_DOS_BASED_FILE_SYSTEM
6212*44704f69SBart Van Assche  /* Skip over the disk name in MSDOS pathnames. */
6213*44704f69SBart Van Assche  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6214*44704f69SBart Van Assche    name += 2;
6215*44704f69SBart Van Assche#endif
6216*44704f69SBart Van Assche
6217*44704f69SBart Van Assche  for (base = name; *name; name++)
6218*44704f69SBart Van Assche    if (IS_DIR_SEPARATOR (*name))
6219*44704f69SBart Van Assche      base = name + 1;
6220*44704f69SBart Van Assche  return base;
6221*44704f69SBart Van Assche}
6222*44704f69SBart Van Assche
6223*44704f69SBart Van Asscheint
6224*44704f69SBart Van Asschecheck_executable (const char *path)
6225*44704f69SBart Van Assche{
6226*44704f69SBart Van Assche  struct stat st;
6227*44704f69SBart Van Assche
6228*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6229*44704f69SBart Van Assche                  nonempty (path));
6230*44704f69SBart Van Assche  if ((!path) || (!*path))
6231*44704f69SBart Van Assche    return 0;
6232*44704f69SBart Van Assche
6233*44704f69SBart Van Assche  if ((stat (path, &st) >= 0)
6234*44704f69SBart Van Assche      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6235*44704f69SBart Van Assche    return 1;
6236*44704f69SBart Van Assche  else
6237*44704f69SBart Van Assche    return 0;
6238*44704f69SBart Van Assche}
6239*44704f69SBart Van Assche
6240*44704f69SBart Van Asscheint
6241*44704f69SBart Van Asschemake_executable (const char *path)
6242*44704f69SBart Van Assche{
6243*44704f69SBart Van Assche  int rval = 0;
6244*44704f69SBart Van Assche  struct stat st;
6245*44704f69SBart Van Assche
6246*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6247*44704f69SBart Van Assche                  nonempty (path));
6248*44704f69SBart Van Assche  if ((!path) || (!*path))
6249*44704f69SBart Van Assche    return 0;
6250*44704f69SBart Van Assche
6251*44704f69SBart Van Assche  if (stat (path, &st) >= 0)
6252*44704f69SBart Van Assche    {
6253*44704f69SBart Van Assche      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6254*44704f69SBart Van Assche    }
6255*44704f69SBart Van Assche  return rval;
6256*44704f69SBart Van Assche}
6257*44704f69SBart Van Assche
6258*44704f69SBart Van Assche/* Searches for the full path of the wrapper.  Returns
6259*44704f69SBart Van Assche   newly allocated full path name if found, NULL otherwise
6260*44704f69SBart Van Assche   Does not chase symlinks, even on platforms that support them.
6261*44704f69SBart Van Assche*/
6262*44704f69SBart Van Asschechar *
6263*44704f69SBart Van Asschefind_executable (const char *wrapper)
6264*44704f69SBart Van Assche{
6265*44704f69SBart Van Assche  int has_slash = 0;
6266*44704f69SBart Van Assche  const char *p;
6267*44704f69SBart Van Assche  const char *p_next;
6268*44704f69SBart Van Assche  /* static buffer for getcwd */
6269*44704f69SBart Van Assche  char tmp[LT_PATHMAX + 1];
6270*44704f69SBart Van Assche  size_t tmp_len;
6271*44704f69SBart Van Assche  char *concat_name;
6272*44704f69SBart Van Assche
6273*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6274*44704f69SBart Van Assche                  nonempty (wrapper));
6275*44704f69SBart Van Assche
6276*44704f69SBart Van Assche  if ((wrapper == NULL) || (*wrapper == '\0'))
6277*44704f69SBart Van Assche    return NULL;
6278*44704f69SBart Van Assche
6279*44704f69SBart Van Assche  /* Absolute path? */
6280*44704f69SBart Van Assche#if defined HAVE_DOS_BASED_FILE_SYSTEM
6281*44704f69SBart Van Assche  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6282*44704f69SBart Van Assche    {
6283*44704f69SBart Van Assche      concat_name = xstrdup (wrapper);
6284*44704f69SBart Van Assche      if (check_executable (concat_name))
6285*44704f69SBart Van Assche	return concat_name;
6286*44704f69SBart Van Assche      XFREE (concat_name);
6287*44704f69SBart Van Assche    }
6288*44704f69SBart Van Assche  else
6289*44704f69SBart Van Assche    {
6290*44704f69SBart Van Assche#endif
6291*44704f69SBart Van Assche      if (IS_DIR_SEPARATOR (wrapper[0]))
6292*44704f69SBart Van Assche	{
6293*44704f69SBart Van Assche	  concat_name = xstrdup (wrapper);
6294*44704f69SBart Van Assche	  if (check_executable (concat_name))
6295*44704f69SBart Van Assche	    return concat_name;
6296*44704f69SBart Van Assche	  XFREE (concat_name);
6297*44704f69SBart Van Assche	}
6298*44704f69SBart Van Assche#if defined HAVE_DOS_BASED_FILE_SYSTEM
6299*44704f69SBart Van Assche    }
6300*44704f69SBart Van Assche#endif
6301*44704f69SBart Van Assche
6302*44704f69SBart Van Assche  for (p = wrapper; *p; p++)
6303*44704f69SBart Van Assche    if (*p == '/')
6304*44704f69SBart Van Assche      {
6305*44704f69SBart Van Assche	has_slash = 1;
6306*44704f69SBart Van Assche	break;
6307*44704f69SBart Van Assche      }
6308*44704f69SBart Van Assche  if (!has_slash)
6309*44704f69SBart Van Assche    {
6310*44704f69SBart Van Assche      /* no slashes; search PATH */
6311*44704f69SBart Van Assche      const char *path = getenv ("PATH");
6312*44704f69SBart Van Assche      if (path != NULL)
6313*44704f69SBart Van Assche	{
6314*44704f69SBart Van Assche	  for (p = path; *p; p = p_next)
6315*44704f69SBart Van Assche	    {
6316*44704f69SBart Van Assche	      const char *q;
6317*44704f69SBart Van Assche	      size_t p_len;
6318*44704f69SBart Van Assche	      for (q = p; *q; q++)
6319*44704f69SBart Van Assche		if (IS_PATH_SEPARATOR (*q))
6320*44704f69SBart Van Assche		  break;
6321*44704f69SBart Van Assche	      p_len = (size_t) (q - p);
6322*44704f69SBart Van Assche	      p_next = (*q == '\0' ? q : q + 1);
6323*44704f69SBart Van Assche	      if (p_len == 0)
6324*44704f69SBart Van Assche		{
6325*44704f69SBart Van Assche		  /* empty path: current directory */
6326*44704f69SBart Van Assche		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6327*44704f69SBart Van Assche		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6328*44704f69SBart Van Assche                              nonnull (strerror (errno)));
6329*44704f69SBart Van Assche		  tmp_len = strlen (tmp);
6330*44704f69SBart Van Assche		  concat_name =
6331*44704f69SBart Van Assche		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6332*44704f69SBart Van Assche		  memcpy (concat_name, tmp, tmp_len);
6333*44704f69SBart Van Assche		  concat_name[tmp_len] = '/';
6334*44704f69SBart Van Assche		  strcpy (concat_name + tmp_len + 1, wrapper);
6335*44704f69SBart Van Assche		}
6336*44704f69SBart Van Assche	      else
6337*44704f69SBart Van Assche		{
6338*44704f69SBart Van Assche		  concat_name =
6339*44704f69SBart Van Assche		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6340*44704f69SBart Van Assche		  memcpy (concat_name, p, p_len);
6341*44704f69SBart Van Assche		  concat_name[p_len] = '/';
6342*44704f69SBart Van Assche		  strcpy (concat_name + p_len + 1, wrapper);
6343*44704f69SBart Van Assche		}
6344*44704f69SBart Van Assche	      if (check_executable (concat_name))
6345*44704f69SBart Van Assche		return concat_name;
6346*44704f69SBart Van Assche	      XFREE (concat_name);
6347*44704f69SBart Van Assche	    }
6348*44704f69SBart Van Assche	}
6349*44704f69SBart Van Assche      /* not found in PATH; assume curdir */
6350*44704f69SBart Van Assche    }
6351*44704f69SBart Van Assche  /* Relative path | not found in path: prepend cwd */
6352*44704f69SBart Van Assche  if (getcwd (tmp, LT_PATHMAX) == NULL)
6353*44704f69SBart Van Assche    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6354*44704f69SBart Van Assche              nonnull (strerror (errno)));
6355*44704f69SBart Van Assche  tmp_len = strlen (tmp);
6356*44704f69SBart Van Assche  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6357*44704f69SBart Van Assche  memcpy (concat_name, tmp, tmp_len);
6358*44704f69SBart Van Assche  concat_name[tmp_len] = '/';
6359*44704f69SBart Van Assche  strcpy (concat_name + tmp_len + 1, wrapper);
6360*44704f69SBart Van Assche
6361*44704f69SBart Van Assche  if (check_executable (concat_name))
6362*44704f69SBart Van Assche    return concat_name;
6363*44704f69SBart Van Assche  XFREE (concat_name);
6364*44704f69SBart Van Assche  return NULL;
6365*44704f69SBart Van Assche}
6366*44704f69SBart Van Assche
6367*44704f69SBart Van Asschechar *
6368*44704f69SBart Van Asschechase_symlinks (const char *pathspec)
6369*44704f69SBart Van Assche{
6370*44704f69SBart Van Assche#ifndef S_ISLNK
6371*44704f69SBart Van Assche  return xstrdup (pathspec);
6372*44704f69SBart Van Assche#else
6373*44704f69SBart Van Assche  char buf[LT_PATHMAX];
6374*44704f69SBart Van Assche  struct stat s;
6375*44704f69SBart Van Assche  char *tmp_pathspec = xstrdup (pathspec);
6376*44704f69SBart Van Assche  char *p;
6377*44704f69SBart Van Assche  int has_symlinks = 0;
6378*44704f69SBart Van Assche  while (strlen (tmp_pathspec) && !has_symlinks)
6379*44704f69SBart Van Assche    {
6380*44704f69SBart Van Assche      lt_debugprintf (__FILE__, __LINE__,
6381*44704f69SBart Van Assche		      "checking path component for symlinks: %s\n",
6382*44704f69SBart Van Assche		      tmp_pathspec);
6383*44704f69SBart Van Assche      if (lstat (tmp_pathspec, &s) == 0)
6384*44704f69SBart Van Assche	{
6385*44704f69SBart Van Assche	  if (S_ISLNK (s.st_mode) != 0)
6386*44704f69SBart Van Assche	    {
6387*44704f69SBart Van Assche	      has_symlinks = 1;
6388*44704f69SBart Van Assche	      break;
6389*44704f69SBart Van Assche	    }
6390*44704f69SBart Van Assche
6391*44704f69SBart Van Assche	  /* search backwards for last DIR_SEPARATOR */
6392*44704f69SBart Van Assche	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6393*44704f69SBart Van Assche	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6394*44704f69SBart Van Assche	    p--;
6395*44704f69SBart Van Assche	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6396*44704f69SBart Van Assche	    {
6397*44704f69SBart Van Assche	      /* no more DIR_SEPARATORS left */
6398*44704f69SBart Van Assche	      break;
6399*44704f69SBart Van Assche	    }
6400*44704f69SBart Van Assche	  *p = '\0';
6401*44704f69SBart Van Assche	}
6402*44704f69SBart Van Assche      else
6403*44704f69SBart Van Assche	{
6404*44704f69SBart Van Assche	  lt_fatal (__FILE__, __LINE__,
6405*44704f69SBart Van Assche		    "error accessing file \"%s\": %s",
6406*44704f69SBart Van Assche		    tmp_pathspec, nonnull (strerror (errno)));
6407*44704f69SBart Van Assche	}
6408*44704f69SBart Van Assche    }
6409*44704f69SBart Van Assche  XFREE (tmp_pathspec);
6410*44704f69SBart Van Assche
6411*44704f69SBart Van Assche  if (!has_symlinks)
6412*44704f69SBart Van Assche    {
6413*44704f69SBart Van Assche      return xstrdup (pathspec);
6414*44704f69SBart Van Assche    }
6415*44704f69SBart Van Assche
6416*44704f69SBart Van Assche  tmp_pathspec = realpath (pathspec, buf);
6417*44704f69SBart Van Assche  if (tmp_pathspec == 0)
6418*44704f69SBart Van Assche    {
6419*44704f69SBart Van Assche      lt_fatal (__FILE__, __LINE__,
6420*44704f69SBart Van Assche		"could not follow symlinks for %s", pathspec);
6421*44704f69SBart Van Assche    }
6422*44704f69SBart Van Assche  return xstrdup (tmp_pathspec);
6423*44704f69SBart Van Assche#endif
6424*44704f69SBart Van Assche}
6425*44704f69SBart Van Assche
6426*44704f69SBart Van Asschechar *
6427*44704f69SBart Van Asschestrendzap (char *str, const char *pat)
6428*44704f69SBart Van Assche{
6429*44704f69SBart Van Assche  size_t len, patlen;
6430*44704f69SBart Van Assche
6431*44704f69SBart Van Assche  assert (str != NULL);
6432*44704f69SBart Van Assche  assert (pat != NULL);
6433*44704f69SBart Van Assche
6434*44704f69SBart Van Assche  len = strlen (str);
6435*44704f69SBart Van Assche  patlen = strlen (pat);
6436*44704f69SBart Van Assche
6437*44704f69SBart Van Assche  if (patlen <= len)
6438*44704f69SBart Van Assche    {
6439*44704f69SBart Van Assche      str += len - patlen;
6440*44704f69SBart Van Assche      if (STREQ (str, pat))
6441*44704f69SBart Van Assche	*str = '\0';
6442*44704f69SBart Van Assche    }
6443*44704f69SBart Van Assche  return str;
6444*44704f69SBart Van Assche}
6445*44704f69SBart Van Assche
6446*44704f69SBart Van Asschevoid
6447*44704f69SBart Van Asschelt_debugprintf (const char *file, int line, const char *fmt, ...)
6448*44704f69SBart Van Assche{
6449*44704f69SBart Van Assche  va_list args;
6450*44704f69SBart Van Assche  if (lt_debug)
6451*44704f69SBart Van Assche    {
6452*44704f69SBart Van Assche      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6453*44704f69SBart Van Assche      va_start (args, fmt);
6454*44704f69SBart Van Assche      (void) vfprintf (stderr, fmt, args);
6455*44704f69SBart Van Assche      va_end (args);
6456*44704f69SBart Van Assche    }
6457*44704f69SBart Van Assche}
6458*44704f69SBart Van Assche
6459*44704f69SBart Van Asschestatic void
6460*44704f69SBart Van Asschelt_error_core (int exit_status, const char *file,
6461*44704f69SBart Van Assche	       int line, const char *mode,
6462*44704f69SBart Van Assche	       const char *message, va_list ap)
6463*44704f69SBart Van Assche{
6464*44704f69SBart Van Assche  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6465*44704f69SBart Van Assche  vfprintf (stderr, message, ap);
6466*44704f69SBart Van Assche  fprintf (stderr, ".\n");
6467*44704f69SBart Van Assche
6468*44704f69SBart Van Assche  if (exit_status >= 0)
6469*44704f69SBart Van Assche    exit (exit_status);
6470*44704f69SBart Van Assche}
6471*44704f69SBart Van Assche
6472*44704f69SBart Van Asschevoid
6473*44704f69SBart Van Asschelt_fatal (const char *file, int line, const char *message, ...)
6474*44704f69SBart Van Assche{
6475*44704f69SBart Van Assche  va_list ap;
6476*44704f69SBart Van Assche  va_start (ap, message);
6477*44704f69SBart Van Assche  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6478*44704f69SBart Van Assche  va_end (ap);
6479*44704f69SBart Van Assche}
6480*44704f69SBart Van Assche
6481*44704f69SBart Van Asschestatic const char *
6482*44704f69SBart Van Asschenonnull (const char *s)
6483*44704f69SBart Van Assche{
6484*44704f69SBart Van Assche  return s ? s : "(null)";
6485*44704f69SBart Van Assche}
6486*44704f69SBart Van Assche
6487*44704f69SBart Van Asschestatic const char *
6488*44704f69SBart Van Asschenonempty (const char *s)
6489*44704f69SBart Van Assche{
6490*44704f69SBart Van Assche  return (s && !*s) ? "(empty)" : nonnull (s);
6491*44704f69SBart Van Assche}
6492*44704f69SBart Van Assche
6493*44704f69SBart Van Asschevoid
6494*44704f69SBart Van Asschelt_setenv (const char *name, const char *value)
6495*44704f69SBart Van Assche{
6496*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__,
6497*44704f69SBart Van Assche		  "(lt_setenv) setting '%s' to '%s'\n",
6498*44704f69SBart Van Assche                  nonnull (name), nonnull (value));
6499*44704f69SBart Van Assche  {
6500*44704f69SBart Van Assche#ifdef HAVE_SETENV
6501*44704f69SBart Van Assche    /* always make a copy, for consistency with !HAVE_SETENV */
6502*44704f69SBart Van Assche    char *str = xstrdup (value);
6503*44704f69SBart Van Assche    setenv (name, str, 1);
6504*44704f69SBart Van Assche#else
6505*44704f69SBart Van Assche    size_t len = strlen (name) + 1 + strlen (value) + 1;
6506*44704f69SBart Van Assche    char *str = XMALLOC (char, len);
6507*44704f69SBart Van Assche    sprintf (str, "%s=%s", name, value);
6508*44704f69SBart Van Assche    if (putenv (str) != EXIT_SUCCESS)
6509*44704f69SBart Van Assche      {
6510*44704f69SBart Van Assche        XFREE (str);
6511*44704f69SBart Van Assche      }
6512*44704f69SBart Van Assche#endif
6513*44704f69SBart Van Assche  }
6514*44704f69SBart Van Assche}
6515*44704f69SBart Van Assche
6516*44704f69SBart Van Asschechar *
6517*44704f69SBart Van Asschelt_extend_str (const char *orig_value, const char *add, int to_end)
6518*44704f69SBart Van Assche{
6519*44704f69SBart Van Assche  char *new_value;
6520*44704f69SBart Van Assche  if (orig_value && *orig_value)
6521*44704f69SBart Van Assche    {
6522*44704f69SBart Van Assche      size_t orig_value_len = strlen (orig_value);
6523*44704f69SBart Van Assche      size_t add_len = strlen (add);
6524*44704f69SBart Van Assche      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6525*44704f69SBart Van Assche      if (to_end)
6526*44704f69SBart Van Assche        {
6527*44704f69SBart Van Assche          strcpy (new_value, orig_value);
6528*44704f69SBart Van Assche          strcpy (new_value + orig_value_len, add);
6529*44704f69SBart Van Assche        }
6530*44704f69SBart Van Assche      else
6531*44704f69SBart Van Assche        {
6532*44704f69SBart Van Assche          strcpy (new_value, add);
6533*44704f69SBart Van Assche          strcpy (new_value + add_len, orig_value);
6534*44704f69SBart Van Assche        }
6535*44704f69SBart Van Assche    }
6536*44704f69SBart Van Assche  else
6537*44704f69SBart Van Assche    {
6538*44704f69SBart Van Assche      new_value = xstrdup (add);
6539*44704f69SBart Van Assche    }
6540*44704f69SBart Van Assche  return new_value;
6541*44704f69SBart Van Assche}
6542*44704f69SBart Van Assche
6543*44704f69SBart Van Asschevoid
6544*44704f69SBart Van Asschelt_update_exe_path (const char *name, const char *value)
6545*44704f69SBart Van Assche{
6546*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__,
6547*44704f69SBart Van Assche		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6548*44704f69SBart Van Assche                  nonnull (name), nonnull (value));
6549*44704f69SBart Van Assche
6550*44704f69SBart Van Assche  if (name && *name && value && *value)
6551*44704f69SBart Van Assche    {
6552*44704f69SBart Van Assche      char *new_value = lt_extend_str (getenv (name), value, 0);
6553*44704f69SBart Van Assche      /* some systems can't cope with a ':'-terminated path #' */
6554*44704f69SBart Van Assche      size_t len = strlen (new_value);
6555*44704f69SBart Van Assche      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6556*44704f69SBart Van Assche        {
6557*44704f69SBart Van Assche          new_value[--len] = '\0';
6558*44704f69SBart Van Assche        }
6559*44704f69SBart Van Assche      lt_setenv (name, new_value);
6560*44704f69SBart Van Assche      XFREE (new_value);
6561*44704f69SBart Van Assche    }
6562*44704f69SBart Van Assche}
6563*44704f69SBart Van Assche
6564*44704f69SBart Van Asschevoid
6565*44704f69SBart Van Asschelt_update_lib_path (const char *name, const char *value)
6566*44704f69SBart Van Assche{
6567*44704f69SBart Van Assche  lt_debugprintf (__FILE__, __LINE__,
6568*44704f69SBart Van Assche		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6569*44704f69SBart Van Assche                  nonnull (name), nonnull (value));
6570*44704f69SBart Van Assche
6571*44704f69SBart Van Assche  if (name && *name && value && *value)
6572*44704f69SBart Van Assche    {
6573*44704f69SBart Van Assche      char *new_value = lt_extend_str (getenv (name), value, 0);
6574*44704f69SBart Van Assche      lt_setenv (name, new_value);
6575*44704f69SBart Van Assche      XFREE (new_value);
6576*44704f69SBart Van Assche    }
6577*44704f69SBart Van Assche}
6578*44704f69SBart Van Assche
6579*44704f69SBart Van AsscheEOF
6580*44704f69SBart Van Assche	    case $host_os in
6581*44704f69SBart Van Assche	      mingw*)
6582*44704f69SBart Van Assche		cat <<"EOF"
6583*44704f69SBart Van Assche
6584*44704f69SBart Van Assche/* Prepares an argument vector before calling spawn().
6585*44704f69SBart Van Assche   Note that spawn() does not by itself call the command interpreter
6586*44704f69SBart Van Assche     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6587*44704f69SBart Van Assche      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6588*44704f69SBart Van Assche         GetVersionEx(&v);
6589*44704f69SBart Van Assche         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6590*44704f69SBart Van Assche      }) ? "cmd.exe" : "command.com").
6591*44704f69SBart Van Assche   Instead it simply concatenates the arguments, separated by ' ', and calls
6592*44704f69SBart Van Assche   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6593*44704f69SBart Van Assche   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6594*44704f69SBart Van Assche   special way:
6595*44704f69SBart Van Assche   - Space and tab are interpreted as delimiters. They are not treated as
6596*44704f69SBart Van Assche     delimiters if they are surrounded by double quotes: "...".
6597*44704f69SBart Van Assche   - Unescaped double quotes are removed from the input. Their only effect is
6598*44704f69SBart Van Assche     that within double quotes, space and tab are treated like normal
6599*44704f69SBart Van Assche     characters.
6600*44704f69SBart Van Assche   - Backslashes not followed by double quotes are not special.
6601*44704f69SBart Van Assche   - But 2*n+1 backslashes followed by a double quote become
6602*44704f69SBart Van Assche     n backslashes followed by a double quote (n >= 0):
6603*44704f69SBart Van Assche       \" -> "
6604*44704f69SBart Van Assche       \\\" -> \"
6605*44704f69SBart Van Assche       \\\\\" -> \\"
6606*44704f69SBart Van Assche */
6607*44704f69SBart Van Assche#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"
6608*44704f69SBart Van Assche#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"
6609*44704f69SBart Van Asschechar **
6610*44704f69SBart Van Asscheprepare_spawn (char **argv)
6611*44704f69SBart Van Assche{
6612*44704f69SBart Van Assche  size_t argc;
6613*44704f69SBart Van Assche  char **new_argv;
6614*44704f69SBart Van Assche  size_t i;
6615*44704f69SBart Van Assche
6616*44704f69SBart Van Assche  /* Count number of arguments.  */
6617*44704f69SBart Van Assche  for (argc = 0; argv[argc] != NULL; argc++)
6618*44704f69SBart Van Assche    ;
6619*44704f69SBart Van Assche
6620*44704f69SBart Van Assche  /* Allocate new argument vector.  */
6621*44704f69SBart Van Assche  new_argv = XMALLOC (char *, argc + 1);
6622*44704f69SBart Van Assche
6623*44704f69SBart Van Assche  /* Put quoted arguments into the new argument vector.  */
6624*44704f69SBart Van Assche  for (i = 0; i < argc; i++)
6625*44704f69SBart Van Assche    {
6626*44704f69SBart Van Assche      const char *string = argv[i];
6627*44704f69SBart Van Assche
6628*44704f69SBart Van Assche      if (string[0] == '\0')
6629*44704f69SBart Van Assche	new_argv[i] = xstrdup ("\"\"");
6630*44704f69SBart Van Assche      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6631*44704f69SBart Van Assche	{
6632*44704f69SBart Van Assche	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6633*44704f69SBart Van Assche	  size_t length;
6634*44704f69SBart Van Assche	  unsigned int backslashes;
6635*44704f69SBart Van Assche	  const char *s;
6636*44704f69SBart Van Assche	  char *quoted_string;
6637*44704f69SBart Van Assche	  char *p;
6638*44704f69SBart Van Assche
6639*44704f69SBart Van Assche	  length = 0;
6640*44704f69SBart Van Assche	  backslashes = 0;
6641*44704f69SBart Van Assche	  if (quote_around)
6642*44704f69SBart Van Assche	    length++;
6643*44704f69SBart Van Assche	  for (s = string; *s != '\0'; s++)
6644*44704f69SBart Van Assche	    {
6645*44704f69SBart Van Assche	      char c = *s;
6646*44704f69SBart Van Assche	      if (c == '"')
6647*44704f69SBart Van Assche		length += backslashes + 1;
6648*44704f69SBart Van Assche	      length++;
6649*44704f69SBart Van Assche	      if (c == '\\')
6650*44704f69SBart Van Assche		backslashes++;
6651*44704f69SBart Van Assche	      else
6652*44704f69SBart Van Assche		backslashes = 0;
6653*44704f69SBart Van Assche	    }
6654*44704f69SBart Van Assche	  if (quote_around)
6655*44704f69SBart Van Assche	    length += backslashes + 1;
6656*44704f69SBart Van Assche
6657*44704f69SBart Van Assche	  quoted_string = XMALLOC (char, length + 1);
6658*44704f69SBart Van Assche
6659*44704f69SBart Van Assche	  p = quoted_string;
6660*44704f69SBart Van Assche	  backslashes = 0;
6661*44704f69SBart Van Assche	  if (quote_around)
6662*44704f69SBart Van Assche	    *p++ = '"';
6663*44704f69SBart Van Assche	  for (s = string; *s != '\0'; s++)
6664*44704f69SBart Van Assche	    {
6665*44704f69SBart Van Assche	      char c = *s;
6666*44704f69SBart Van Assche	      if (c == '"')
6667*44704f69SBart Van Assche		{
6668*44704f69SBart Van Assche		  unsigned int j;
6669*44704f69SBart Van Assche		  for (j = backslashes + 1; j > 0; j--)
6670*44704f69SBart Van Assche		    *p++ = '\\';
6671*44704f69SBart Van Assche		}
6672*44704f69SBart Van Assche	      *p++ = c;
6673*44704f69SBart Van Assche	      if (c == '\\')
6674*44704f69SBart Van Assche		backslashes++;
6675*44704f69SBart Van Assche	      else
6676*44704f69SBart Van Assche		backslashes = 0;
6677*44704f69SBart Van Assche	    }
6678*44704f69SBart Van Assche	  if (quote_around)
6679*44704f69SBart Van Assche	    {
6680*44704f69SBart Van Assche	      unsigned int j;
6681*44704f69SBart Van Assche	      for (j = backslashes; j > 0; j--)
6682*44704f69SBart Van Assche		*p++ = '\\';
6683*44704f69SBart Van Assche	      *p++ = '"';
6684*44704f69SBart Van Assche	    }
6685*44704f69SBart Van Assche	  *p = '\0';
6686*44704f69SBart Van Assche
6687*44704f69SBart Van Assche	  new_argv[i] = quoted_string;
6688*44704f69SBart Van Assche	}
6689*44704f69SBart Van Assche      else
6690*44704f69SBart Van Assche	new_argv[i] = (char *) string;
6691*44704f69SBart Van Assche    }
6692*44704f69SBart Van Assche  new_argv[argc] = NULL;
6693*44704f69SBart Van Assche
6694*44704f69SBart Van Assche  return new_argv;
6695*44704f69SBart Van Assche}
6696*44704f69SBart Van AsscheEOF
6697*44704f69SBart Van Assche		;;
6698*44704f69SBart Van Assche	    esac
6699*44704f69SBart Van Assche
6700*44704f69SBart Van Assche            cat <<"EOF"
6701*44704f69SBart Van Asschevoid lt_dump_script (FILE* f)
6702*44704f69SBart Van Assche{
6703*44704f69SBart Van AsscheEOF
6704*44704f69SBart Van Assche	    func_emit_wrapper yes |
6705*44704f69SBart Van Assche	      $SED -n -e '
6706*44704f69SBart Van Assches/^\(.\{79\}\)\(..*\)/\1\
6707*44704f69SBart Van Assche\2/
6708*44704f69SBart Van Asscheh
6709*44704f69SBart Van Assches/\([\\"]\)/\\\1/g
6710*44704f69SBart Van Assches/$/\\n/
6711*44704f69SBart Van Assches/\([^\n]*\).*/  fputs ("\1", f);/p
6712*44704f69SBart Van Asscheg
6713*44704f69SBart Van AsscheD'
6714*44704f69SBart Van Assche            cat <<"EOF"
6715*44704f69SBart Van Assche}
6716*44704f69SBart Van AsscheEOF
6717*44704f69SBart Van Assche}
6718*44704f69SBart Van Assche# end: func_emit_cwrapperexe_src
6719*44704f69SBart Van Assche
6720*44704f69SBart Van Assche# func_win32_import_lib_p ARG
6721*44704f69SBart Van Assche# True if ARG is an import lib, as indicated by $file_magic_cmd
6722*44704f69SBart Van Asschefunc_win32_import_lib_p ()
6723*44704f69SBart Van Assche{
6724*44704f69SBart Van Assche    $debug_cmd
6725*44704f69SBart Van Assche
6726*44704f69SBart Van Assche    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6727*44704f69SBart Van Assche    *import*) : ;;
6728*44704f69SBart Van Assche    *) false ;;
6729*44704f69SBart Van Assche    esac
6730*44704f69SBart Van Assche}
6731*44704f69SBart Van Assche
6732*44704f69SBart Van Assche# func_suncc_cstd_abi
6733*44704f69SBart Van Assche# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6734*44704f69SBart Van Assche# Several compiler flags select an ABI that is incompatible with the
6735*44704f69SBart Van Assche# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6736*44704f69SBart Van Asschefunc_suncc_cstd_abi ()
6737*44704f69SBart Van Assche{
6738*44704f69SBart Van Assche    $debug_cmd
6739*44704f69SBart Van Assche
6740*44704f69SBart Van Assche    case " $compile_command " in
6741*44704f69SBart Van Assche    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6742*44704f69SBart Van Assche      suncc_use_cstd_abi=no
6743*44704f69SBart Van Assche      ;;
6744*44704f69SBart Van Assche    *)
6745*44704f69SBart Van Assche      suncc_use_cstd_abi=yes
6746*44704f69SBart Van Assche      ;;
6747*44704f69SBart Van Assche    esac
6748*44704f69SBart Van Assche}
6749*44704f69SBart Van Assche
6750*44704f69SBart Van Assche# func_mode_link arg...
6751*44704f69SBart Van Asschefunc_mode_link ()
6752*44704f69SBart Van Assche{
6753*44704f69SBart Van Assche    $debug_cmd
6754*44704f69SBart Van Assche
6755*44704f69SBart Van Assche    case $host in
6756*44704f69SBart Van Assche    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6757*44704f69SBart Van Assche      # It is impossible to link a dll without this setting, and
6758*44704f69SBart Van Assche      # we shouldn't force the makefile maintainer to figure out
6759*44704f69SBart Van Assche      # what system we are compiling for in order to pass an extra
6760*44704f69SBart Van Assche      # flag for every libtool invocation.
6761*44704f69SBart Van Assche      # allow_undefined=no
6762*44704f69SBart Van Assche
6763*44704f69SBart Van Assche      # FIXME: Unfortunately, there are problems with the above when trying
6764*44704f69SBart Van Assche      # to make a dll that has undefined symbols, in which case not
6765*44704f69SBart Van Assche      # even a static library is built.  For now, we need to specify
6766*44704f69SBart Van Assche      # -no-undefined on the libtool link line when we can be certain
6767*44704f69SBart Van Assche      # that all symbols are satisfied, otherwise we get a static library.
6768*44704f69SBart Van Assche      allow_undefined=yes
6769*44704f69SBart Van Assche      ;;
6770*44704f69SBart Van Assche    *)
6771*44704f69SBart Van Assche      allow_undefined=yes
6772*44704f69SBart Van Assche      ;;
6773*44704f69SBart Van Assche    esac
6774*44704f69SBart Van Assche    libtool_args=$nonopt
6775*44704f69SBart Van Assche    base_compile="$nonopt $@"
6776*44704f69SBart Van Assche    compile_command=$nonopt
6777*44704f69SBart Van Assche    finalize_command=$nonopt
6778*44704f69SBart Van Assche
6779*44704f69SBart Van Assche    compile_rpath=
6780*44704f69SBart Van Assche    finalize_rpath=
6781*44704f69SBart Van Assche    compile_shlibpath=
6782*44704f69SBart Van Assche    finalize_shlibpath=
6783*44704f69SBart Van Assche    convenience=
6784*44704f69SBart Van Assche    old_convenience=
6785*44704f69SBart Van Assche    deplibs=
6786*44704f69SBart Van Assche    old_deplibs=
6787*44704f69SBart Van Assche    compiler_flags=
6788*44704f69SBart Van Assche    linker_flags=
6789*44704f69SBart Van Assche    dllsearchpath=
6790*44704f69SBart Van Assche    lib_search_path=`pwd`
6791*44704f69SBart Van Assche    inst_prefix_dir=
6792*44704f69SBart Van Assche    new_inherited_linker_flags=
6793*44704f69SBart Van Assche
6794*44704f69SBart Van Assche    avoid_version=no
6795*44704f69SBart Van Assche    bindir=
6796*44704f69SBart Van Assche    dlfiles=
6797*44704f69SBart Van Assche    dlprefiles=
6798*44704f69SBart Van Assche    dlself=no
6799*44704f69SBart Van Assche    export_dynamic=no
6800*44704f69SBart Van Assche    export_symbols=
6801*44704f69SBart Van Assche    export_symbols_regex=
6802*44704f69SBart Van Assche    generated=
6803*44704f69SBart Van Assche    libobjs=
6804*44704f69SBart Van Assche    ltlibs=
6805*44704f69SBart Van Assche    module=no
6806*44704f69SBart Van Assche    no_install=no
6807*44704f69SBart Van Assche    objs=
6808*44704f69SBart Van Assche    os2dllname=
6809*44704f69SBart Van Assche    non_pic_objects=
6810*44704f69SBart Van Assche    precious_files_regex=
6811*44704f69SBart Van Assche    prefer_static_libs=no
6812*44704f69SBart Van Assche    preload=false
6813*44704f69SBart Van Assche    prev=
6814*44704f69SBart Van Assche    prevarg=
6815*44704f69SBart Van Assche    release=
6816*44704f69SBart Van Assche    rpath=
6817*44704f69SBart Van Assche    xrpath=
6818*44704f69SBart Van Assche    perm_rpath=
6819*44704f69SBart Van Assche    temp_rpath=
6820*44704f69SBart Van Assche    thread_safe=no
6821*44704f69SBart Van Assche    vinfo=
6822*44704f69SBart Van Assche    vinfo_number=no
6823*44704f69SBart Van Assche    weak_libs=
6824*44704f69SBart Van Assche    single_module=$wl-single_module
6825*44704f69SBart Van Assche    func_infer_tag $base_compile
6826*44704f69SBart Van Assche
6827*44704f69SBart Van Assche    # We need to know -static, to get the right output filenames.
6828*44704f69SBart Van Assche    for arg
6829*44704f69SBart Van Assche    do
6830*44704f69SBart Van Assche      case $arg in
6831*44704f69SBart Van Assche      -shared)
6832*44704f69SBart Van Assche	test yes != "$build_libtool_libs" \
6833*44704f69SBart Van Assche	  && func_fatal_configuration "cannot build a shared library"
6834*44704f69SBart Van Assche	build_old_libs=no
6835*44704f69SBart Van Assche	break
6836*44704f69SBart Van Assche	;;
6837*44704f69SBart Van Assche      -all-static | -static | -static-libtool-libs)
6838*44704f69SBart Van Assche	case $arg in
6839*44704f69SBart Van Assche	-all-static)
6840*44704f69SBart Van Assche	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6841*44704f69SBart Van Assche	    func_warning "complete static linking is impossible in this configuration"
6842*44704f69SBart Van Assche	  fi
6843*44704f69SBart Van Assche	  if test -n "$link_static_flag"; then
6844*44704f69SBart Van Assche	    dlopen_self=$dlopen_self_static
6845*44704f69SBart Van Assche	  fi
6846*44704f69SBart Van Assche	  prefer_static_libs=yes
6847*44704f69SBart Van Assche	  ;;
6848*44704f69SBart Van Assche	-static)
6849*44704f69SBart Van Assche	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6850*44704f69SBart Van Assche	    dlopen_self=$dlopen_self_static
6851*44704f69SBart Van Assche	  fi
6852*44704f69SBart Van Assche	  prefer_static_libs=built
6853*44704f69SBart Van Assche	  ;;
6854*44704f69SBart Van Assche	-static-libtool-libs)
6855*44704f69SBart Van Assche	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6856*44704f69SBart Van Assche	    dlopen_self=$dlopen_self_static
6857*44704f69SBart Van Assche	  fi
6858*44704f69SBart Van Assche	  prefer_static_libs=yes
6859*44704f69SBart Van Assche	  ;;
6860*44704f69SBart Van Assche	esac
6861*44704f69SBart Van Assche	build_libtool_libs=no
6862*44704f69SBart Van Assche	build_old_libs=yes
6863*44704f69SBart Van Assche	break
6864*44704f69SBart Van Assche	;;
6865*44704f69SBart Van Assche      esac
6866*44704f69SBart Van Assche    done
6867*44704f69SBart Van Assche
6868*44704f69SBart Van Assche    # See if our shared archives depend on static archives.
6869*44704f69SBart Van Assche    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6870*44704f69SBart Van Assche
6871*44704f69SBart Van Assche    # Go through the arguments, transforming them on the way.
6872*44704f69SBart Van Assche    while test "$#" -gt 0; do
6873*44704f69SBart Van Assche      arg=$1
6874*44704f69SBart Van Assche      shift
6875*44704f69SBart Van Assche      func_quote_arg pretty,unquoted "$arg"
6876*44704f69SBart Van Assche      qarg=$func_quote_arg_unquoted_result
6877*44704f69SBart Van Assche      func_append libtool_args " $func_quote_arg_result"
6878*44704f69SBart Van Assche
6879*44704f69SBart Van Assche      # If the previous option needs an argument, assign it.
6880*44704f69SBart Van Assche      if test -n "$prev"; then
6881*44704f69SBart Van Assche	case $prev in
6882*44704f69SBart Van Assche	output)
6883*44704f69SBart Van Assche	  func_append compile_command " @OUTPUT@"
6884*44704f69SBart Van Assche	  func_append finalize_command " @OUTPUT@"
6885*44704f69SBart Van Assche	  ;;
6886*44704f69SBart Van Assche	esac
6887*44704f69SBart Van Assche
6888*44704f69SBart Van Assche	case $prev in
6889*44704f69SBart Van Assche	bindir)
6890*44704f69SBart Van Assche	  bindir=$arg
6891*44704f69SBart Van Assche	  prev=
6892*44704f69SBart Van Assche	  continue
6893*44704f69SBart Van Assche	  ;;
6894*44704f69SBart Van Assche	dlfiles|dlprefiles)
6895*44704f69SBart Van Assche	  $preload || {
6896*44704f69SBart Van Assche	    # Add the symbol object into the linking commands.
6897*44704f69SBart Van Assche	    func_append compile_command " @SYMFILE@"
6898*44704f69SBart Van Assche	    func_append finalize_command " @SYMFILE@"
6899*44704f69SBart Van Assche	    preload=:
6900*44704f69SBart Van Assche	  }
6901*44704f69SBart Van Assche	  case $arg in
6902*44704f69SBart Van Assche	  *.la | *.lo) ;;  # We handle these cases below.
6903*44704f69SBart Van Assche	  force)
6904*44704f69SBart Van Assche	    if test no = "$dlself"; then
6905*44704f69SBart Van Assche	      dlself=needless
6906*44704f69SBart Van Assche	      export_dynamic=yes
6907*44704f69SBart Van Assche	    fi
6908*44704f69SBart Van Assche	    prev=
6909*44704f69SBart Van Assche	    continue
6910*44704f69SBart Van Assche	    ;;
6911*44704f69SBart Van Assche	  self)
6912*44704f69SBart Van Assche	    if test dlprefiles = "$prev"; then
6913*44704f69SBart Van Assche	      dlself=yes
6914*44704f69SBart Van Assche	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6915*44704f69SBart Van Assche	      dlself=yes
6916*44704f69SBart Van Assche	    else
6917*44704f69SBart Van Assche	      dlself=needless
6918*44704f69SBart Van Assche	      export_dynamic=yes
6919*44704f69SBart Van Assche	    fi
6920*44704f69SBart Van Assche	    prev=
6921*44704f69SBart Van Assche	    continue
6922*44704f69SBart Van Assche	    ;;
6923*44704f69SBart Van Assche	  *)
6924*44704f69SBart Van Assche	    if test dlfiles = "$prev"; then
6925*44704f69SBart Van Assche	      func_append dlfiles " $arg"
6926*44704f69SBart Van Assche	    else
6927*44704f69SBart Van Assche	      func_append dlprefiles " $arg"
6928*44704f69SBart Van Assche	    fi
6929*44704f69SBart Van Assche	    prev=
6930*44704f69SBart Van Assche	    continue
6931*44704f69SBart Van Assche	    ;;
6932*44704f69SBart Van Assche	  esac
6933*44704f69SBart Van Assche	  ;;
6934*44704f69SBart Van Assche	expsyms)
6935*44704f69SBart Van Assche	  export_symbols=$arg
6936*44704f69SBart Van Assche	  test -f "$arg" \
6937*44704f69SBart Van Assche	    || func_fatal_error "symbol file '$arg' does not exist"
6938*44704f69SBart Van Assche	  prev=
6939*44704f69SBart Van Assche	  continue
6940*44704f69SBart Van Assche	  ;;
6941*44704f69SBart Van Assche	expsyms_regex)
6942*44704f69SBart Van Assche	  export_symbols_regex=$arg
6943*44704f69SBart Van Assche	  prev=
6944*44704f69SBart Van Assche	  continue
6945*44704f69SBart Van Assche	  ;;
6946*44704f69SBart Van Assche	framework)
6947*44704f69SBart Van Assche	  case $host in
6948*44704f69SBart Van Assche	    *-*-darwin*)
6949*44704f69SBart Van Assche	      case "$deplibs " in
6950*44704f69SBart Van Assche		*" $qarg.ltframework "*) ;;
6951*44704f69SBart Van Assche		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6952*44704f69SBart Van Assche		   ;;
6953*44704f69SBart Van Assche	      esac
6954*44704f69SBart Van Assche	      ;;
6955*44704f69SBart Van Assche	  esac
6956*44704f69SBart Van Assche	  prev=
6957*44704f69SBart Van Assche	  continue
6958*44704f69SBart Van Assche	  ;;
6959*44704f69SBart Van Assche	inst_prefix)
6960*44704f69SBart Van Assche	  inst_prefix_dir=$arg
6961*44704f69SBart Van Assche	  prev=
6962*44704f69SBart Van Assche	  continue
6963*44704f69SBart Van Assche	  ;;
6964*44704f69SBart Van Assche	mllvm)
6965*44704f69SBart Van Assche	  # Clang does not use LLVM to link, so we can simply discard any
6966*44704f69SBart Van Assche	  # '-mllvm $arg' options when doing the link step.
6967*44704f69SBart Van Assche	  prev=
6968*44704f69SBart Van Assche	  continue
6969*44704f69SBart Van Assche	  ;;
6970*44704f69SBart Van Assche	objectlist)
6971*44704f69SBart Van Assche	  if test -f "$arg"; then
6972*44704f69SBart Van Assche	    save_arg=$arg
6973*44704f69SBart Van Assche	    moreargs=
6974*44704f69SBart Van Assche	    for fil in `cat "$save_arg"`
6975*44704f69SBart Van Assche	    do
6976*44704f69SBart Van Assche#	      func_append moreargs " $fil"
6977*44704f69SBart Van Assche	      arg=$fil
6978*44704f69SBart Van Assche	      # A libtool-controlled object.
6979*44704f69SBart Van Assche
6980*44704f69SBart Van Assche	      # Check to see that this really is a libtool object.
6981*44704f69SBart Van Assche	      if func_lalib_unsafe_p "$arg"; then
6982*44704f69SBart Van Assche		pic_object=
6983*44704f69SBart Van Assche		non_pic_object=
6984*44704f69SBart Van Assche
6985*44704f69SBart Van Assche		# Read the .lo file
6986*44704f69SBart Van Assche		func_source "$arg"
6987*44704f69SBart Van Assche
6988*44704f69SBart Van Assche		if test -z "$pic_object" ||
6989*44704f69SBart Van Assche		   test -z "$non_pic_object" ||
6990*44704f69SBart Van Assche		   test none = "$pic_object" &&
6991*44704f69SBart Van Assche		   test none = "$non_pic_object"; then
6992*44704f69SBart Van Assche		  func_fatal_error "cannot find name of object for '$arg'"
6993*44704f69SBart Van Assche		fi
6994*44704f69SBart Van Assche
6995*44704f69SBart Van Assche		# Extract subdirectory from the argument.
6996*44704f69SBart Van Assche		func_dirname "$arg" "/" ""
6997*44704f69SBart Van Assche		xdir=$func_dirname_result
6998*44704f69SBart Van Assche
6999*44704f69SBart Van Assche		if test none != "$pic_object"; then
7000*44704f69SBart Van Assche		  # Prepend the subdirectory the object is found in.
7001*44704f69SBart Van Assche		  pic_object=$xdir$pic_object
7002*44704f69SBart Van Assche
7003*44704f69SBart Van Assche		  if test dlfiles = "$prev"; then
7004*44704f69SBart Van Assche		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7005*44704f69SBart Van Assche		      func_append dlfiles " $pic_object"
7006*44704f69SBart Van Assche		      prev=
7007*44704f69SBart Van Assche		      continue
7008*44704f69SBart Van Assche		    else
7009*44704f69SBart Van Assche		      # If libtool objects are unsupported, then we need to preload.
7010*44704f69SBart Van Assche		      prev=dlprefiles
7011*44704f69SBart Van Assche		    fi
7012*44704f69SBart Van Assche		  fi
7013*44704f69SBart Van Assche
7014*44704f69SBart Van Assche		  # CHECK ME:  I think I busted this.  -Ossama
7015*44704f69SBart Van Assche		  if test dlprefiles = "$prev"; then
7016*44704f69SBart Van Assche		    # Preload the old-style object.
7017*44704f69SBart Van Assche		    func_append dlprefiles " $pic_object"
7018*44704f69SBart Van Assche		    prev=
7019*44704f69SBart Van Assche		  fi
7020*44704f69SBart Van Assche
7021*44704f69SBart Van Assche		  # A PIC object.
7022*44704f69SBart Van Assche		  func_append libobjs " $pic_object"
7023*44704f69SBart Van Assche		  arg=$pic_object
7024*44704f69SBart Van Assche		fi
7025*44704f69SBart Van Assche
7026*44704f69SBart Van Assche		# Non-PIC object.
7027*44704f69SBart Van Assche		if test none != "$non_pic_object"; then
7028*44704f69SBart Van Assche		  # Prepend the subdirectory the object is found in.
7029*44704f69SBart Van Assche		  non_pic_object=$xdir$non_pic_object
7030*44704f69SBart Van Assche
7031*44704f69SBart Van Assche		  # A standard non-PIC object
7032*44704f69SBart Van Assche		  func_append non_pic_objects " $non_pic_object"
7033*44704f69SBart Van Assche		  if test -z "$pic_object" || test none = "$pic_object"; then
7034*44704f69SBart Van Assche		    arg=$non_pic_object
7035*44704f69SBart Van Assche		  fi
7036*44704f69SBart Van Assche		else
7037*44704f69SBart Van Assche		  # If the PIC object exists, use it instead.
7038*44704f69SBart Van Assche		  # $xdir was prepended to $pic_object above.
7039*44704f69SBart Van Assche		  non_pic_object=$pic_object
7040*44704f69SBart Van Assche		  func_append non_pic_objects " $non_pic_object"
7041*44704f69SBart Van Assche		fi
7042*44704f69SBart Van Assche	      else
7043*44704f69SBart Van Assche		# Only an error if not doing a dry-run.
7044*44704f69SBart Van Assche		if $opt_dry_run; then
7045*44704f69SBart Van Assche		  # Extract subdirectory from the argument.
7046*44704f69SBart Van Assche		  func_dirname "$arg" "/" ""
7047*44704f69SBart Van Assche		  xdir=$func_dirname_result
7048*44704f69SBart Van Assche
7049*44704f69SBart Van Assche		  func_lo2o "$arg"
7050*44704f69SBart Van Assche		  pic_object=$xdir$objdir/$func_lo2o_result
7051*44704f69SBart Van Assche		  non_pic_object=$xdir$func_lo2o_result
7052*44704f69SBart Van Assche		  func_append libobjs " $pic_object"
7053*44704f69SBart Van Assche		  func_append non_pic_objects " $non_pic_object"
7054*44704f69SBart Van Assche	        else
7055*44704f69SBart Van Assche		  func_fatal_error "'$arg' is not a valid libtool object"
7056*44704f69SBart Van Assche		fi
7057*44704f69SBart Van Assche	      fi
7058*44704f69SBart Van Assche	    done
7059*44704f69SBart Van Assche	  else
7060*44704f69SBart Van Assche	    func_fatal_error "link input file '$arg' does not exist"
7061*44704f69SBart Van Assche	  fi
7062*44704f69SBart Van Assche	  arg=$save_arg
7063*44704f69SBart Van Assche	  prev=
7064*44704f69SBart Van Assche	  continue
7065*44704f69SBart Van Assche	  ;;
7066*44704f69SBart Van Assche	os2dllname)
7067*44704f69SBart Van Assche	  os2dllname=$arg
7068*44704f69SBart Van Assche	  prev=
7069*44704f69SBart Van Assche	  continue
7070*44704f69SBart Van Assche	  ;;
7071*44704f69SBart Van Assche	precious_regex)
7072*44704f69SBart Van Assche	  precious_files_regex=$arg
7073*44704f69SBart Van Assche	  prev=
7074*44704f69SBart Van Assche	  continue
7075*44704f69SBart Van Assche	  ;;
7076*44704f69SBart Van Assche	release)
7077*44704f69SBart Van Assche	  release=-$arg
7078*44704f69SBart Van Assche	  prev=
7079*44704f69SBart Van Assche	  continue
7080*44704f69SBart Van Assche	  ;;
7081*44704f69SBart Van Assche	rpath | xrpath)
7082*44704f69SBart Van Assche	  # We need an absolute path.
7083*44704f69SBart Van Assche	  case $arg in
7084*44704f69SBart Van Assche	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7085*44704f69SBart Van Assche	  *)
7086*44704f69SBart Van Assche	    func_fatal_error "only absolute run-paths are allowed"
7087*44704f69SBart Van Assche	    ;;
7088*44704f69SBart Van Assche	  esac
7089*44704f69SBart Van Assche	  if test rpath = "$prev"; then
7090*44704f69SBart Van Assche	    case "$rpath " in
7091*44704f69SBart Van Assche	    *" $arg "*) ;;
7092*44704f69SBart Van Assche	    *) func_append rpath " $arg" ;;
7093*44704f69SBart Van Assche	    esac
7094*44704f69SBart Van Assche	  else
7095*44704f69SBart Van Assche	    case "$xrpath " in
7096*44704f69SBart Van Assche	    *" $arg "*) ;;
7097*44704f69SBart Van Assche	    *) func_append xrpath " $arg" ;;
7098*44704f69SBart Van Assche	    esac
7099*44704f69SBart Van Assche	  fi
7100*44704f69SBart Van Assche	  prev=
7101*44704f69SBart Van Assche	  continue
7102*44704f69SBart Van Assche	  ;;
7103*44704f69SBart Van Assche	shrext)
7104*44704f69SBart Van Assche	  shrext_cmds=$arg
7105*44704f69SBart Van Assche	  prev=
7106*44704f69SBart Van Assche	  continue
7107*44704f69SBart Van Assche	  ;;
7108*44704f69SBart Van Assche	weak)
7109*44704f69SBart Van Assche	  func_append weak_libs " $arg"
7110*44704f69SBart Van Assche	  prev=
7111*44704f69SBart Van Assche	  continue
7112*44704f69SBart Van Assche	  ;;
7113*44704f69SBart Van Assche	xassembler)
7114*44704f69SBart Van Assche	  func_append compiler_flags " -Xassembler $qarg"
7115*44704f69SBart Van Assche	  prev=
7116*44704f69SBart Van Assche	  func_append compile_command " -Xassembler $qarg"
7117*44704f69SBart Van Assche	  func_append finalize_command " -Xassembler $qarg"
7118*44704f69SBart Van Assche	  continue
7119*44704f69SBart Van Assche	  ;;
7120*44704f69SBart Van Assche	xcclinker)
7121*44704f69SBart Van Assche	  func_append linker_flags " $qarg"
7122*44704f69SBart Van Assche	  func_append compiler_flags " $qarg"
7123*44704f69SBart Van Assche	  prev=
7124*44704f69SBart Van Assche	  func_append compile_command " $qarg"
7125*44704f69SBart Van Assche	  func_append finalize_command " $qarg"
7126*44704f69SBart Van Assche	  continue
7127*44704f69SBart Van Assche	  ;;
7128*44704f69SBart Van Assche	xcompiler)
7129*44704f69SBart Van Assche	  func_append compiler_flags " $qarg"
7130*44704f69SBart Van Assche	  prev=
7131*44704f69SBart Van Assche	  func_append compile_command " $qarg"
7132*44704f69SBart Van Assche	  func_append finalize_command " $qarg"
7133*44704f69SBart Van Assche	  continue
7134*44704f69SBart Van Assche	  ;;
7135*44704f69SBart Van Assche	xlinker)
7136*44704f69SBart Van Assche	  func_append linker_flags " $qarg"
7137*44704f69SBart Van Assche	  func_append compiler_flags " $wl$qarg"
7138*44704f69SBart Van Assche	  prev=
7139*44704f69SBart Van Assche	  func_append compile_command " $wl$qarg"
7140*44704f69SBart Van Assche	  func_append finalize_command " $wl$qarg"
7141*44704f69SBart Van Assche	  continue
7142*44704f69SBart Van Assche	  ;;
7143*44704f69SBart Van Assche	*)
7144*44704f69SBart Van Assche	  eval "$prev=\"\$arg\""
7145*44704f69SBart Van Assche	  prev=
7146*44704f69SBart Van Assche	  continue
7147*44704f69SBart Van Assche	  ;;
7148*44704f69SBart Van Assche	esac
7149*44704f69SBart Van Assche      fi # test -n "$prev"
7150*44704f69SBart Van Assche
7151*44704f69SBart Van Assche      prevarg=$arg
7152*44704f69SBart Van Assche
7153*44704f69SBart Van Assche      case $arg in
7154*44704f69SBart Van Assche      -all-static)
7155*44704f69SBart Van Assche	if test -n "$link_static_flag"; then
7156*44704f69SBart Van Assche	  # See comment for -static flag below, for more details.
7157*44704f69SBart Van Assche	  func_append compile_command " $link_static_flag"
7158*44704f69SBart Van Assche	  func_append finalize_command " $link_static_flag"
7159*44704f69SBart Van Assche	fi
7160*44704f69SBart Van Assche	continue
7161*44704f69SBart Van Assche	;;
7162*44704f69SBart Van Assche
7163*44704f69SBart Van Assche      -allow-undefined)
7164*44704f69SBart Van Assche	# FIXME: remove this flag sometime in the future.
7165*44704f69SBart Van Assche	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7166*44704f69SBart Van Assche	;;
7167*44704f69SBart Van Assche
7168*44704f69SBart Van Assche      -avoid-version)
7169*44704f69SBart Van Assche	avoid_version=yes
7170*44704f69SBart Van Assche	continue
7171*44704f69SBart Van Assche	;;
7172*44704f69SBart Van Assche
7173*44704f69SBart Van Assche      -bindir)
7174*44704f69SBart Van Assche	prev=bindir
7175*44704f69SBart Van Assche	continue
7176*44704f69SBart Van Assche	;;
7177*44704f69SBart Van Assche
7178*44704f69SBart Van Assche      -dlopen)
7179*44704f69SBart Van Assche	prev=dlfiles
7180*44704f69SBart Van Assche	continue
7181*44704f69SBart Van Assche	;;
7182*44704f69SBart Van Assche
7183*44704f69SBart Van Assche      -dlpreopen)
7184*44704f69SBart Van Assche	prev=dlprefiles
7185*44704f69SBart Van Assche	continue
7186*44704f69SBart Van Assche	;;
7187*44704f69SBart Van Assche
7188*44704f69SBart Van Assche      -export-dynamic)
7189*44704f69SBart Van Assche	export_dynamic=yes
7190*44704f69SBart Van Assche	continue
7191*44704f69SBart Van Assche	;;
7192*44704f69SBart Van Assche
7193*44704f69SBart Van Assche      -export-symbols | -export-symbols-regex)
7194*44704f69SBart Van Assche	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7195*44704f69SBart Van Assche	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7196*44704f69SBart Van Assche	fi
7197*44704f69SBart Van Assche	if test X-export-symbols = "X$arg"; then
7198*44704f69SBart Van Assche	  prev=expsyms
7199*44704f69SBart Van Assche	else
7200*44704f69SBart Van Assche	  prev=expsyms_regex
7201*44704f69SBart Van Assche	fi
7202*44704f69SBart Van Assche	continue
7203*44704f69SBart Van Assche	;;
7204*44704f69SBart Van Assche
7205*44704f69SBart Van Assche      -framework)
7206*44704f69SBart Van Assche	prev=framework
7207*44704f69SBart Van Assche	continue
7208*44704f69SBart Van Assche	;;
7209*44704f69SBart Van Assche
7210*44704f69SBart Van Assche      -inst-prefix-dir)
7211*44704f69SBart Van Assche	prev=inst_prefix
7212*44704f69SBart Van Assche	continue
7213*44704f69SBart Van Assche	;;
7214*44704f69SBart Van Assche
7215*44704f69SBart Van Assche      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7216*44704f69SBart Van Assche      # so, if we see these flags be careful not to treat them like -L
7217*44704f69SBart Van Assche      -L[A-Z][A-Z]*:*)
7218*44704f69SBart Van Assche	case $with_gcc/$host in
7219*44704f69SBart Van Assche	no/*-*-irix* | /*-*-irix*)
7220*44704f69SBart Van Assche	  func_append compile_command " $arg"
7221*44704f69SBart Van Assche	  func_append finalize_command " $arg"
7222*44704f69SBart Van Assche	  ;;
7223*44704f69SBart Van Assche	esac
7224*44704f69SBart Van Assche	continue
7225*44704f69SBart Van Assche	;;
7226*44704f69SBart Van Assche
7227*44704f69SBart Van Assche      -L*)
7228*44704f69SBart Van Assche	func_stripname "-L" '' "$arg"
7229*44704f69SBart Van Assche	if test -z "$func_stripname_result"; then
7230*44704f69SBart Van Assche	  if test "$#" -gt 0; then
7231*44704f69SBart Van Assche	    func_fatal_error "require no space between '-L' and '$1'"
7232*44704f69SBart Van Assche	  else
7233*44704f69SBart Van Assche	    func_fatal_error "need path for '-L' option"
7234*44704f69SBart Van Assche	  fi
7235*44704f69SBart Van Assche	fi
7236*44704f69SBart Van Assche	func_resolve_sysroot "$func_stripname_result"
7237*44704f69SBart Van Assche	dir=$func_resolve_sysroot_result
7238*44704f69SBart Van Assche	# We need an absolute path.
7239*44704f69SBart Van Assche	case $dir in
7240*44704f69SBart Van Assche	[\\/]* | [A-Za-z]:[\\/]*) ;;
7241*44704f69SBart Van Assche	*)
7242*44704f69SBart Van Assche	  absdir=`cd "$dir" && pwd`
7243*44704f69SBart Van Assche	  test -z "$absdir" && \
7244*44704f69SBart Van Assche	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7245*44704f69SBart Van Assche	  dir=$absdir
7246*44704f69SBart Van Assche	  ;;
7247*44704f69SBart Van Assche	esac
7248*44704f69SBart Van Assche	case "$deplibs " in
7249*44704f69SBart Van Assche	*" -L$dir "* | *" $arg "*)
7250*44704f69SBart Van Assche	  # Will only happen for absolute or sysroot arguments
7251*44704f69SBart Van Assche	  ;;
7252*44704f69SBart Van Assche	*)
7253*44704f69SBart Van Assche	  # Preserve sysroot, but never include relative directories
7254*44704f69SBart Van Assche	  case $dir in
7255*44704f69SBart Van Assche	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7256*44704f69SBart Van Assche	    *) func_append deplibs " -L$dir" ;;
7257*44704f69SBart Van Assche	  esac
7258*44704f69SBart Van Assche	  func_append lib_search_path " $dir"
7259*44704f69SBart Van Assche	  ;;
7260*44704f69SBart Van Assche	esac
7261*44704f69SBart Van Assche	case $host in
7262*44704f69SBart Van Assche	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7263*44704f69SBart Van Assche	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7264*44704f69SBart Van Assche	  case :$dllsearchpath: in
7265*44704f69SBart Van Assche	  *":$dir:"*) ;;
7266*44704f69SBart Van Assche	  ::) dllsearchpath=$dir;;
7267*44704f69SBart Van Assche	  *) func_append dllsearchpath ":$dir";;
7268*44704f69SBart Van Assche	  esac
7269*44704f69SBart Van Assche	  case :$dllsearchpath: in
7270*44704f69SBart Van Assche	  *":$testbindir:"*) ;;
7271*44704f69SBart Van Assche	  ::) dllsearchpath=$testbindir;;
7272*44704f69SBart Van Assche	  *) func_append dllsearchpath ":$testbindir";;
7273*44704f69SBart Van Assche	  esac
7274*44704f69SBart Van Assche	  ;;
7275*44704f69SBart Van Assche	esac
7276*44704f69SBart Van Assche	continue
7277*44704f69SBart Van Assche	;;
7278*44704f69SBart Van Assche
7279*44704f69SBart Van Assche      -l*)
7280*44704f69SBart Van Assche	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7281*44704f69SBart Van Assche	  case $host in
7282*44704f69SBart Van Assche	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7283*44704f69SBart Van Assche	    # These systems don't actually have a C or math library (as such)
7284*44704f69SBart Van Assche	    continue
7285*44704f69SBart Van Assche	    ;;
7286*44704f69SBart Van Assche	  *-*-os2*)
7287*44704f69SBart Van Assche	    # These systems don't actually have a C library (as such)
7288*44704f69SBart Van Assche	    test X-lc = "X$arg" && continue
7289*44704f69SBart Van Assche	    ;;
7290*44704f69SBart Van Assche	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7291*44704f69SBart Van Assche	    # Do not include libc due to us having libc/libc_r.
7292*44704f69SBart Van Assche	    test X-lc = "X$arg" && continue
7293*44704f69SBart Van Assche	    ;;
7294*44704f69SBart Van Assche	  *-*-rhapsody* | *-*-darwin1.[012])
7295*44704f69SBart Van Assche	    # Rhapsody C and math libraries are in the System framework
7296*44704f69SBart Van Assche	    func_append deplibs " System.ltframework"
7297*44704f69SBart Van Assche	    continue
7298*44704f69SBart Van Assche	    ;;
7299*44704f69SBart Van Assche	  *-*-sco3.2v5* | *-*-sco5v6*)
7300*44704f69SBart Van Assche	    # Causes problems with __ctype
7301*44704f69SBart Van Assche	    test X-lc = "X$arg" && continue
7302*44704f69SBart Van Assche	    ;;
7303*44704f69SBart Van Assche	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7304*44704f69SBart Van Assche	    # Compiler inserts libc in the correct place for threads to work
7305*44704f69SBart Van Assche	    test X-lc = "X$arg" && continue
7306*44704f69SBart Van Assche	    ;;
7307*44704f69SBart Van Assche	  esac
7308*44704f69SBart Van Assche	elif test X-lc_r = "X$arg"; then
7309*44704f69SBart Van Assche	 case $host in
7310*44704f69SBart Van Assche	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7311*44704f69SBart Van Assche	   # Do not include libc_r directly, use -pthread flag.
7312*44704f69SBart Van Assche	   continue
7313*44704f69SBart Van Assche	   ;;
7314*44704f69SBart Van Assche	 esac
7315*44704f69SBart Van Assche	fi
7316*44704f69SBart Van Assche	func_append deplibs " $arg"
7317*44704f69SBart Van Assche	continue
7318*44704f69SBart Van Assche	;;
7319*44704f69SBart Van Assche
7320*44704f69SBart Van Assche      -mllvm)
7321*44704f69SBart Van Assche	prev=mllvm
7322*44704f69SBart Van Assche	continue
7323*44704f69SBart Van Assche	;;
7324*44704f69SBart Van Assche
7325*44704f69SBart Van Assche      -module)
7326*44704f69SBart Van Assche	module=yes
7327*44704f69SBart Van Assche	continue
7328*44704f69SBart Van Assche	;;
7329*44704f69SBart Van Assche
7330*44704f69SBart Van Assche      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7331*44704f69SBart Van Assche      # classes, name mangling, and exception handling.
7332*44704f69SBart Van Assche      # Darwin uses the -arch flag to determine output architecture.
7333*44704f69SBart Van Assche      -model|-arch|-isysroot|--sysroot)
7334*44704f69SBart Van Assche	func_append compiler_flags " $arg"
7335*44704f69SBart Van Assche	func_append compile_command " $arg"
7336*44704f69SBart Van Assche	func_append finalize_command " $arg"
7337*44704f69SBart Van Assche	prev=xcompiler
7338*44704f69SBart Van Assche	continue
7339*44704f69SBart Van Assche	;;
7340*44704f69SBart Van Assche     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7341*44704f69SBart Van Assche     -pthread)
7342*44704f69SBart Van Assche	case $host in
7343*44704f69SBart Van Assche	  *solaris2*) ;;
7344*44704f69SBart Van Assche	  *)
7345*44704f69SBart Van Assche	    case "$new_inherited_linker_flags " in
7346*44704f69SBart Van Assche	        *" $arg "*) ;;
7347*44704f69SBart Van Assche	        * ) func_append new_inherited_linker_flags " $arg" ;;
7348*44704f69SBart Van Assche	    esac
7349*44704f69SBart Van Assche	  ;;
7350*44704f69SBart Van Assche	esac
7351*44704f69SBart Van Assche	continue
7352*44704f69SBart Van Assche	;;
7353*44704f69SBart Van Assche      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7354*44704f69SBart Van Assche      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7355*44704f69SBart Van Assche	func_append compiler_flags " $arg"
7356*44704f69SBart Van Assche	func_append compile_command " $arg"
7357*44704f69SBart Van Assche	func_append finalize_command " $arg"
7358*44704f69SBart Van Assche	case "$new_inherited_linker_flags " in
7359*44704f69SBart Van Assche	    *" $arg "*) ;;
7360*44704f69SBart Van Assche	    * ) func_append new_inherited_linker_flags " $arg" ;;
7361*44704f69SBart Van Assche	esac
7362*44704f69SBart Van Assche	continue
7363*44704f69SBart Van Assche	;;
7364*44704f69SBart Van Assche
7365*44704f69SBart Van Assche      -multi_module)
7366*44704f69SBart Van Assche	single_module=$wl-multi_module
7367*44704f69SBart Van Assche	continue
7368*44704f69SBart Van Assche	;;
7369*44704f69SBart Van Assche
7370*44704f69SBart Van Assche      -no-fast-install)
7371*44704f69SBart Van Assche	fast_install=no
7372*44704f69SBart Van Assche	continue
7373*44704f69SBart Van Assche	;;
7374*44704f69SBart Van Assche
7375*44704f69SBart Van Assche      -no-install)
7376*44704f69SBart Van Assche	case $host in
7377*44704f69SBart Van Assche	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7378*44704f69SBart Van Assche	  # The PATH hackery in wrapper scripts is required on Windows
7379*44704f69SBart Van Assche	  # and Darwin in order for the loader to find any dlls it needs.
7380*44704f69SBart Van Assche	  func_warning "'-no-install' is ignored for $host"
7381*44704f69SBart Van Assche	  func_warning "assuming '-no-fast-install' instead"
7382*44704f69SBart Van Assche	  fast_install=no
7383*44704f69SBart Van Assche	  ;;
7384*44704f69SBart Van Assche	*) no_install=yes ;;
7385*44704f69SBart Van Assche	esac
7386*44704f69SBart Van Assche	continue
7387*44704f69SBart Van Assche	;;
7388*44704f69SBart Van Assche
7389*44704f69SBart Van Assche      -no-undefined)
7390*44704f69SBart Van Assche	allow_undefined=no
7391*44704f69SBart Van Assche	continue
7392*44704f69SBart Van Assche	;;
7393*44704f69SBart Van Assche
7394*44704f69SBart Van Assche      -objectlist)
7395*44704f69SBart Van Assche	prev=objectlist
7396*44704f69SBart Van Assche	continue
7397*44704f69SBart Van Assche	;;
7398*44704f69SBart Van Assche
7399*44704f69SBart Van Assche      -os2dllname)
7400*44704f69SBart Van Assche	prev=os2dllname
7401*44704f69SBart Van Assche	continue
7402*44704f69SBart Van Assche	;;
7403*44704f69SBart Van Assche
7404*44704f69SBart Van Assche      -o) prev=output ;;
7405*44704f69SBart Van Assche
7406*44704f69SBart Van Assche      -precious-files-regex)
7407*44704f69SBart Van Assche	prev=precious_regex
7408*44704f69SBart Van Assche	continue
7409*44704f69SBart Van Assche	;;
7410*44704f69SBart Van Assche
7411*44704f69SBart Van Assche      -release)
7412*44704f69SBart Van Assche	prev=release
7413*44704f69SBart Van Assche	continue
7414*44704f69SBart Van Assche	;;
7415*44704f69SBart Van Assche
7416*44704f69SBart Van Assche      -rpath)
7417*44704f69SBart Van Assche	prev=rpath
7418*44704f69SBart Van Assche	continue
7419*44704f69SBart Van Assche	;;
7420*44704f69SBart Van Assche
7421*44704f69SBart Van Assche      -R)
7422*44704f69SBart Van Assche	prev=xrpath
7423*44704f69SBart Van Assche	continue
7424*44704f69SBart Van Assche	;;
7425*44704f69SBart Van Assche
7426*44704f69SBart Van Assche      -R*)
7427*44704f69SBart Van Assche	func_stripname '-R' '' "$arg"
7428*44704f69SBart Van Assche	dir=$func_stripname_result
7429*44704f69SBart Van Assche	# We need an absolute path.
7430*44704f69SBart Van Assche	case $dir in
7431*44704f69SBart Van Assche	[\\/]* | [A-Za-z]:[\\/]*) ;;
7432*44704f69SBart Van Assche	=*)
7433*44704f69SBart Van Assche	  func_stripname '=' '' "$dir"
7434*44704f69SBart Van Assche	  dir=$lt_sysroot$func_stripname_result
7435*44704f69SBart Van Assche	  ;;
7436*44704f69SBart Van Assche	*)
7437*44704f69SBart Van Assche	  func_fatal_error "only absolute run-paths are allowed"
7438*44704f69SBart Van Assche	  ;;
7439*44704f69SBart Van Assche	esac
7440*44704f69SBart Van Assche	case "$xrpath " in
7441*44704f69SBart Van Assche	*" $dir "*) ;;
7442*44704f69SBart Van Assche	*) func_append xrpath " $dir" ;;
7443*44704f69SBart Van Assche	esac
7444*44704f69SBart Van Assche	continue
7445*44704f69SBart Van Assche	;;
7446*44704f69SBart Van Assche
7447*44704f69SBart Van Assche      -shared)
7448*44704f69SBart Van Assche	# The effects of -shared are defined in a previous loop.
7449*44704f69SBart Van Assche	continue
7450*44704f69SBart Van Assche	;;
7451*44704f69SBart Van Assche
7452*44704f69SBart Van Assche      -shrext)
7453*44704f69SBart Van Assche	prev=shrext
7454*44704f69SBart Van Assche	continue
7455*44704f69SBart Van Assche	;;
7456*44704f69SBart Van Assche
7457*44704f69SBart Van Assche      -static | -static-libtool-libs)
7458*44704f69SBart Van Assche	# The effects of -static are defined in a previous loop.
7459*44704f69SBart Van Assche	# We used to do the same as -all-static on platforms that
7460*44704f69SBart Van Assche	# didn't have a PIC flag, but the assumption that the effects
7461*44704f69SBart Van Assche	# would be equivalent was wrong.  It would break on at least
7462*44704f69SBart Van Assche	# Digital Unix and AIX.
7463*44704f69SBart Van Assche	continue
7464*44704f69SBart Van Assche	;;
7465*44704f69SBart Van Assche
7466*44704f69SBart Van Assche      -thread-safe)
7467*44704f69SBart Van Assche	thread_safe=yes
7468*44704f69SBart Van Assche	continue
7469*44704f69SBart Van Assche	;;
7470*44704f69SBart Van Assche
7471*44704f69SBart Van Assche      -version-info)
7472*44704f69SBart Van Assche	prev=vinfo
7473*44704f69SBart Van Assche	continue
7474*44704f69SBart Van Assche	;;
7475*44704f69SBart Van Assche
7476*44704f69SBart Van Assche      -version-number)
7477*44704f69SBart Van Assche	prev=vinfo
7478*44704f69SBart Van Assche	vinfo_number=yes
7479*44704f69SBart Van Assche	continue
7480*44704f69SBart Van Assche	;;
7481*44704f69SBart Van Assche
7482*44704f69SBart Van Assche      -weak)
7483*44704f69SBart Van Assche        prev=weak
7484*44704f69SBart Van Assche	continue
7485*44704f69SBart Van Assche	;;
7486*44704f69SBart Van Assche
7487*44704f69SBart Van Assche      -Wc,*)
7488*44704f69SBart Van Assche	func_stripname '-Wc,' '' "$arg"
7489*44704f69SBart Van Assche	args=$func_stripname_result
7490*44704f69SBart Van Assche	arg=
7491*44704f69SBart Van Assche	save_ifs=$IFS; IFS=,
7492*44704f69SBart Van Assche	for flag in $args; do
7493*44704f69SBart Van Assche	  IFS=$save_ifs
7494*44704f69SBart Van Assche          func_quote_arg pretty "$flag"
7495*44704f69SBart Van Assche	  func_append arg " $func_quote_arg_result"
7496*44704f69SBart Van Assche	  func_append compiler_flags " $func_quote_arg_result"
7497*44704f69SBart Van Assche	done
7498*44704f69SBart Van Assche	IFS=$save_ifs
7499*44704f69SBart Van Assche	func_stripname ' ' '' "$arg"
7500*44704f69SBart Van Assche	arg=$func_stripname_result
7501*44704f69SBart Van Assche	;;
7502*44704f69SBart Van Assche
7503*44704f69SBart Van Assche      -Wl,*)
7504*44704f69SBart Van Assche	func_stripname '-Wl,' '' "$arg"
7505*44704f69SBart Van Assche	args=$func_stripname_result
7506*44704f69SBart Van Assche	arg=
7507*44704f69SBart Van Assche	save_ifs=$IFS; IFS=,
7508*44704f69SBart Van Assche	for flag in $args; do
7509*44704f69SBart Van Assche	  IFS=$save_ifs
7510*44704f69SBart Van Assche          func_quote_arg pretty "$flag"
7511*44704f69SBart Van Assche	  func_append arg " $wl$func_quote_arg_result"
7512*44704f69SBart Van Assche	  func_append compiler_flags " $wl$func_quote_arg_result"
7513*44704f69SBart Van Assche	  func_append linker_flags " $func_quote_arg_result"
7514*44704f69SBart Van Assche	done
7515*44704f69SBart Van Assche	IFS=$save_ifs
7516*44704f69SBart Van Assche	func_stripname ' ' '' "$arg"
7517*44704f69SBart Van Assche	arg=$func_stripname_result
7518*44704f69SBart Van Assche	;;
7519*44704f69SBart Van Assche
7520*44704f69SBart Van Assche      -Xassembler)
7521*44704f69SBart Van Assche        prev=xassembler
7522*44704f69SBart Van Assche        continue
7523*44704f69SBart Van Assche        ;;
7524*44704f69SBart Van Assche
7525*44704f69SBart Van Assche      -Xcompiler)
7526*44704f69SBart Van Assche	prev=xcompiler
7527*44704f69SBart Van Assche	continue
7528*44704f69SBart Van Assche	;;
7529*44704f69SBart Van Assche
7530*44704f69SBart Van Assche      -Xlinker)
7531*44704f69SBart Van Assche	prev=xlinker
7532*44704f69SBart Van Assche	continue
7533*44704f69SBart Van Assche	;;
7534*44704f69SBart Van Assche
7535*44704f69SBart Van Assche      -XCClinker)
7536*44704f69SBart Van Assche	prev=xcclinker
7537*44704f69SBart Van Assche	continue
7538*44704f69SBart Van Assche	;;
7539*44704f69SBart Van Assche
7540*44704f69SBart Van Assche      # -msg_* for osf cc
7541*44704f69SBart Van Assche      -msg_*)
7542*44704f69SBart Van Assche	func_quote_arg pretty "$arg"
7543*44704f69SBart Van Assche	arg=$func_quote_arg_result
7544*44704f69SBart Van Assche	;;
7545*44704f69SBart Van Assche
7546*44704f69SBart Van Assche      # Flags to be passed through unchanged, with rationale:
7547*44704f69SBart Van Assche      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7548*44704f69SBart Van Assche      # -r[0-9][0-9]*        specify processor for the SGI compiler
7549*44704f69SBart Van Assche      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7550*44704f69SBart Van Assche      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7551*44704f69SBart Van Assche      # -q*                  compiler args for the IBM compiler
7552*44704f69SBart Van Assche      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7553*44704f69SBart Van Assche      # -F/path              path to uninstalled frameworks, gcc on darwin
7554*44704f69SBart Van Assche      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7555*44704f69SBart Van Assche      # -fstack-protector*   stack protector flags for GCC
7556*44704f69SBart Van Assche      # @file                GCC response files
7557*44704f69SBart Van Assche      # -tp=*                Portland pgcc target processor selection
7558*44704f69SBart Van Assche      # --sysroot=*          for sysroot support
7559*44704f69SBart Van Assche      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7560*44704f69SBart Van Assche      # -specs=*             GCC specs files
7561*44704f69SBart Van Assche      # -stdlib=*            select c++ std lib with clang
7562*44704f69SBart Van Assche      # -fsanitize=*         Clang/GCC memory and address sanitizer
7563*44704f69SBart Van Assche      # -fuse-ld=*           Linker select flags for GCC
7564*44704f69SBart Van Assche      # -static-*            direct GCC to link specific libraries statically
7565*44704f69SBart Van Assche      # -fcilkplus           Cilk Plus language extension features for C/C++
7566*44704f69SBart Van Assche      # -Wa,*                Pass flags directly to the assembler
7567*44704f69SBart Van Assche      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7568*44704f69SBart Van Assche      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7569*44704f69SBart Van Assche      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7570*44704f69SBart Van Assche      -specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus|-Wa,*)
7571*44704f69SBart Van Assche        func_quote_arg pretty "$arg"
7572*44704f69SBart Van Assche	arg=$func_quote_arg_result
7573*44704f69SBart Van Assche        func_append compile_command " $arg"
7574*44704f69SBart Van Assche        func_append finalize_command " $arg"
7575*44704f69SBart Van Assche        func_append compiler_flags " $arg"
7576*44704f69SBart Van Assche        continue
7577*44704f69SBart Van Assche        ;;
7578*44704f69SBart Van Assche
7579*44704f69SBart Van Assche      -Z*)
7580*44704f69SBart Van Assche        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7581*44704f69SBart Van Assche          # OS/2 uses -Zxxx to specify OS/2-specific options
7582*44704f69SBart Van Assche	  compiler_flags="$compiler_flags $arg"
7583*44704f69SBart Van Assche	  func_append compile_command " $arg"
7584*44704f69SBart Van Assche	  func_append finalize_command " $arg"
7585*44704f69SBart Van Assche	  case $arg in
7586*44704f69SBart Van Assche	  -Zlinker | -Zstack)
7587*44704f69SBart Van Assche	    prev=xcompiler
7588*44704f69SBart Van Assche	    ;;
7589*44704f69SBart Van Assche	  esac
7590*44704f69SBart Van Assche	  continue
7591*44704f69SBart Van Assche        else
7592*44704f69SBart Van Assche	  # Otherwise treat like 'Some other compiler flag' below
7593*44704f69SBart Van Assche	  func_quote_arg pretty "$arg"
7594*44704f69SBart Van Assche	  arg=$func_quote_arg_result
7595*44704f69SBart Van Assche        fi
7596*44704f69SBart Van Assche	;;
7597*44704f69SBart Van Assche
7598*44704f69SBart Van Assche      # Some other compiler flag.
7599*44704f69SBart Van Assche      -* | +*)
7600*44704f69SBart Van Assche        func_quote_arg pretty "$arg"
7601*44704f69SBart Van Assche	arg=$func_quote_arg_result
7602*44704f69SBart Van Assche	;;
7603*44704f69SBart Van Assche
7604*44704f69SBart Van Assche      *.$objext)
7605*44704f69SBart Van Assche	# A standard object.
7606*44704f69SBart Van Assche	func_append objs " $arg"
7607*44704f69SBart Van Assche	;;
7608*44704f69SBart Van Assche
7609*44704f69SBart Van Assche      *.lo)
7610*44704f69SBart Van Assche	# A libtool-controlled object.
7611*44704f69SBart Van Assche
7612*44704f69SBart Van Assche	# Check to see that this really is a libtool object.
7613*44704f69SBart Van Assche	if func_lalib_unsafe_p "$arg"; then
7614*44704f69SBart Van Assche	  pic_object=
7615*44704f69SBart Van Assche	  non_pic_object=
7616*44704f69SBart Van Assche
7617*44704f69SBart Van Assche	  # Read the .lo file
7618*44704f69SBart Van Assche	  func_source "$arg"
7619*44704f69SBart Van Assche
7620*44704f69SBart Van Assche	  if test -z "$pic_object" ||
7621*44704f69SBart Van Assche	     test -z "$non_pic_object" ||
7622*44704f69SBart Van Assche	     test none = "$pic_object" &&
7623*44704f69SBart Van Assche	     test none = "$non_pic_object"; then
7624*44704f69SBart Van Assche	    func_fatal_error "cannot find name of object for '$arg'"
7625*44704f69SBart Van Assche	  fi
7626*44704f69SBart Van Assche
7627*44704f69SBart Van Assche	  # Extract subdirectory from the argument.
7628*44704f69SBart Van Assche	  func_dirname "$arg" "/" ""
7629*44704f69SBart Van Assche	  xdir=$func_dirname_result
7630*44704f69SBart Van Assche
7631*44704f69SBart Van Assche	  test none = "$pic_object" || {
7632*44704f69SBart Van Assche	    # Prepend the subdirectory the object is found in.
7633*44704f69SBart Van Assche	    pic_object=$xdir$pic_object
7634*44704f69SBart Van Assche
7635*44704f69SBart Van Assche	    if test dlfiles = "$prev"; then
7636*44704f69SBart Van Assche	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7637*44704f69SBart Van Assche		func_append dlfiles " $pic_object"
7638*44704f69SBart Van Assche		prev=
7639*44704f69SBart Van Assche		continue
7640*44704f69SBart Van Assche	      else
7641*44704f69SBart Van Assche		# If libtool objects are unsupported, then we need to preload.
7642*44704f69SBart Van Assche		prev=dlprefiles
7643*44704f69SBart Van Assche	      fi
7644*44704f69SBart Van Assche	    fi
7645*44704f69SBart Van Assche
7646*44704f69SBart Van Assche	    # CHECK ME:  I think I busted this.  -Ossama
7647*44704f69SBart Van Assche	    if test dlprefiles = "$prev"; then
7648*44704f69SBart Van Assche	      # Preload the old-style object.
7649*44704f69SBart Van Assche	      func_append dlprefiles " $pic_object"
7650*44704f69SBart Van Assche	      prev=
7651*44704f69SBart Van Assche	    fi
7652*44704f69SBart Van Assche
7653*44704f69SBart Van Assche	    # A PIC object.
7654*44704f69SBart Van Assche	    func_append libobjs " $pic_object"
7655*44704f69SBart Van Assche	    arg=$pic_object
7656*44704f69SBart Van Assche	  }
7657*44704f69SBart Van Assche
7658*44704f69SBart Van Assche	  # Non-PIC object.
7659*44704f69SBart Van Assche	  if test none != "$non_pic_object"; then
7660*44704f69SBart Van Assche	    # Prepend the subdirectory the object is found in.
7661*44704f69SBart Van Assche	    non_pic_object=$xdir$non_pic_object
7662*44704f69SBart Van Assche
7663*44704f69SBart Van Assche	    # A standard non-PIC object
7664*44704f69SBart Van Assche	    func_append non_pic_objects " $non_pic_object"
7665*44704f69SBart Van Assche	    if test -z "$pic_object" || test none = "$pic_object"; then
7666*44704f69SBart Van Assche	      arg=$non_pic_object
7667*44704f69SBart Van Assche	    fi
7668*44704f69SBart Van Assche	  else
7669*44704f69SBart Van Assche	    # If the PIC object exists, use it instead.
7670*44704f69SBart Van Assche	    # $xdir was prepended to $pic_object above.
7671*44704f69SBart Van Assche	    non_pic_object=$pic_object
7672*44704f69SBart Van Assche	    func_append non_pic_objects " $non_pic_object"
7673*44704f69SBart Van Assche	  fi
7674*44704f69SBart Van Assche	else
7675*44704f69SBart Van Assche	  # Only an error if not doing a dry-run.
7676*44704f69SBart Van Assche	  if $opt_dry_run; then
7677*44704f69SBart Van Assche	    # Extract subdirectory from the argument.
7678*44704f69SBart Van Assche	    func_dirname "$arg" "/" ""
7679*44704f69SBart Van Assche	    xdir=$func_dirname_result
7680*44704f69SBart Van Assche
7681*44704f69SBart Van Assche	    func_lo2o "$arg"
7682*44704f69SBart Van Assche	    pic_object=$xdir$objdir/$func_lo2o_result
7683*44704f69SBart Van Assche	    non_pic_object=$xdir$func_lo2o_result
7684*44704f69SBart Van Assche	    func_append libobjs " $pic_object"
7685*44704f69SBart Van Assche	    func_append non_pic_objects " $non_pic_object"
7686*44704f69SBart Van Assche	  else
7687*44704f69SBart Van Assche	    func_fatal_error "'$arg' is not a valid libtool object"
7688*44704f69SBart Van Assche	  fi
7689*44704f69SBart Van Assche	fi
7690*44704f69SBart Van Assche	;;
7691*44704f69SBart Van Assche
7692*44704f69SBart Van Assche      *.$libext)
7693*44704f69SBart Van Assche	# An archive.
7694*44704f69SBart Van Assche	func_append deplibs " $arg"
7695*44704f69SBart Van Assche	func_append old_deplibs " $arg"
7696*44704f69SBart Van Assche	continue
7697*44704f69SBart Van Assche	;;
7698*44704f69SBart Van Assche
7699*44704f69SBart Van Assche      *.la)
7700*44704f69SBart Van Assche	# A libtool-controlled library.
7701*44704f69SBart Van Assche
7702*44704f69SBart Van Assche	func_resolve_sysroot "$arg"
7703*44704f69SBart Van Assche	if test dlfiles = "$prev"; then
7704*44704f69SBart Van Assche	  # This library was specified with -dlopen.
7705*44704f69SBart Van Assche	  func_append dlfiles " $func_resolve_sysroot_result"
7706*44704f69SBart Van Assche	  prev=
7707*44704f69SBart Van Assche	elif test dlprefiles = "$prev"; then
7708*44704f69SBart Van Assche	  # The library was specified with -dlpreopen.
7709*44704f69SBart Van Assche	  func_append dlprefiles " $func_resolve_sysroot_result"
7710*44704f69SBart Van Assche	  prev=
7711*44704f69SBart Van Assche	else
7712*44704f69SBart Van Assche	  func_append deplibs " $func_resolve_sysroot_result"
7713*44704f69SBart Van Assche	fi
7714*44704f69SBart Van Assche	continue
7715*44704f69SBart Van Assche	;;
7716*44704f69SBart Van Assche
7717*44704f69SBart Van Assche      # Some other compiler argument.
7718*44704f69SBart Van Assche      *)
7719*44704f69SBart Van Assche	# Unknown arguments in both finalize_command and compile_command need
7720*44704f69SBart Van Assche	# to be aesthetically quoted because they are evaled later.
7721*44704f69SBart Van Assche	func_quote_arg pretty "$arg"
7722*44704f69SBart Van Assche	arg=$func_quote_arg_result
7723*44704f69SBart Van Assche	;;
7724*44704f69SBart Van Assche      esac # arg
7725*44704f69SBart Van Assche
7726*44704f69SBart Van Assche      # Now actually substitute the argument into the commands.
7727*44704f69SBart Van Assche      if test -n "$arg"; then
7728*44704f69SBart Van Assche	func_append compile_command " $arg"
7729*44704f69SBart Van Assche	func_append finalize_command " $arg"
7730*44704f69SBart Van Assche      fi
7731*44704f69SBart Van Assche    done # argument parsing loop
7732*44704f69SBart Van Assche
7733*44704f69SBart Van Assche    test -n "$prev" && \
7734*44704f69SBart Van Assche      func_fatal_help "the '$prevarg' option requires an argument"
7735*44704f69SBart Van Assche
7736*44704f69SBart Van Assche    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7737*44704f69SBart Van Assche      eval arg=\"$export_dynamic_flag_spec\"
7738*44704f69SBart Van Assche      func_append compile_command " $arg"
7739*44704f69SBart Van Assche      func_append finalize_command " $arg"
7740*44704f69SBart Van Assche    fi
7741*44704f69SBart Van Assche
7742*44704f69SBart Van Assche    oldlibs=
7743*44704f69SBart Van Assche    # calculate the name of the file, without its directory
7744*44704f69SBart Van Assche    func_basename "$output"
7745*44704f69SBart Van Assche    outputname=$func_basename_result
7746*44704f69SBart Van Assche    libobjs_save=$libobjs
7747*44704f69SBart Van Assche
7748*44704f69SBart Van Assche    if test -n "$shlibpath_var"; then
7749*44704f69SBart Van Assche      # get the directories listed in $shlibpath_var
7750*44704f69SBart Van Assche      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7751*44704f69SBart Van Assche    else
7752*44704f69SBart Van Assche      shlib_search_path=
7753*44704f69SBart Van Assche    fi
7754*44704f69SBart Van Assche    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7755*44704f69SBart Van Assche    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7756*44704f69SBart Van Assche
7757*44704f69SBart Van Assche    # Definition is injected by LT_CONFIG during libtool generation.
7758*44704f69SBart Van Assche    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7759*44704f69SBart Van Assche
7760*44704f69SBart Van Assche    func_dirname "$output" "/" ""
7761*44704f69SBart Van Assche    output_objdir=$func_dirname_result$objdir
7762*44704f69SBart Van Assche    func_to_tool_file "$output_objdir/"
7763*44704f69SBart Van Assche    tool_output_objdir=$func_to_tool_file_result
7764*44704f69SBart Van Assche    # Create the object directory.
7765*44704f69SBart Van Assche    func_mkdir_p "$output_objdir"
7766*44704f69SBart Van Assche
7767*44704f69SBart Van Assche    # Determine the type of output
7768*44704f69SBart Van Assche    case $output in
7769*44704f69SBart Van Assche    "")
7770*44704f69SBart Van Assche      func_fatal_help "you must specify an output file"
7771*44704f69SBart Van Assche      ;;
7772*44704f69SBart Van Assche    *.$libext) linkmode=oldlib ;;
7773*44704f69SBart Van Assche    *.lo | *.$objext) linkmode=obj ;;
7774*44704f69SBart Van Assche    *.la) linkmode=lib ;;
7775*44704f69SBart Van Assche    *) linkmode=prog ;; # Anything else should be a program.
7776*44704f69SBart Van Assche    esac
7777*44704f69SBart Van Assche
7778*44704f69SBart Van Assche    specialdeplibs=
7779*44704f69SBart Van Assche
7780*44704f69SBart Van Assche    libs=
7781*44704f69SBart Van Assche    # Find all interdependent deplibs by searching for libraries
7782*44704f69SBart Van Assche    # that are linked more than once (e.g. -la -lb -la)
7783*44704f69SBart Van Assche    for deplib in $deplibs; do
7784*44704f69SBart Van Assche      if $opt_preserve_dup_deps; then
7785*44704f69SBart Van Assche	case "$libs " in
7786*44704f69SBart Van Assche	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7787*44704f69SBart Van Assche	esac
7788*44704f69SBart Van Assche      fi
7789*44704f69SBart Van Assche      func_append libs " $deplib"
7790*44704f69SBart Van Assche    done
7791*44704f69SBart Van Assche
7792*44704f69SBart Van Assche    if test lib = "$linkmode"; then
7793*44704f69SBart Van Assche      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7794*44704f69SBart Van Assche
7795*44704f69SBart Van Assche      # Compute libraries that are listed more than once in $predeps
7796*44704f69SBart Van Assche      # $postdeps and mark them as special (i.e., whose duplicates are
7797*44704f69SBart Van Assche      # not to be eliminated).
7798*44704f69SBart Van Assche      pre_post_deps=
7799*44704f69SBart Van Assche      if $opt_duplicate_compiler_generated_deps; then
7800*44704f69SBart Van Assche	for pre_post_dep in $predeps $postdeps; do
7801*44704f69SBart Van Assche	  case "$pre_post_deps " in
7802*44704f69SBart Van Assche	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7803*44704f69SBart Van Assche	  esac
7804*44704f69SBart Van Assche	  func_append pre_post_deps " $pre_post_dep"
7805*44704f69SBart Van Assche	done
7806*44704f69SBart Van Assche      fi
7807*44704f69SBart Van Assche      pre_post_deps=
7808*44704f69SBart Van Assche    fi
7809*44704f69SBart Van Assche
7810*44704f69SBart Van Assche    deplibs=
7811*44704f69SBart Van Assche    newdependency_libs=
7812*44704f69SBart Van Assche    newlib_search_path=
7813*44704f69SBart Van Assche    need_relink=no # whether we're linking any uninstalled libtool libraries
7814*44704f69SBart Van Assche    notinst_deplibs= # not-installed libtool libraries
7815*44704f69SBart Van Assche    notinst_path= # paths that contain not-installed libtool libraries
7816*44704f69SBart Van Assche
7817*44704f69SBart Van Assche    case $linkmode in
7818*44704f69SBart Van Assche    lib)
7819*44704f69SBart Van Assche	passes="conv dlpreopen link"
7820*44704f69SBart Van Assche	for file in $dlfiles $dlprefiles; do
7821*44704f69SBart Van Assche	  case $file in
7822*44704f69SBart Van Assche	  *.la) ;;
7823*44704f69SBart Van Assche	  *)
7824*44704f69SBart Van Assche	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7825*44704f69SBart Van Assche	    ;;
7826*44704f69SBart Van Assche	  esac
7827*44704f69SBart Van Assche	done
7828*44704f69SBart Van Assche	;;
7829*44704f69SBart Van Assche    prog)
7830*44704f69SBart Van Assche	compile_deplibs=
7831*44704f69SBart Van Assche	finalize_deplibs=
7832*44704f69SBart Van Assche	alldeplibs=false
7833*44704f69SBart Van Assche	newdlfiles=
7834*44704f69SBart Van Assche	newdlprefiles=
7835*44704f69SBart Van Assche	passes="conv scan dlopen dlpreopen link"
7836*44704f69SBart Van Assche	;;
7837*44704f69SBart Van Assche    *)  passes="conv"
7838*44704f69SBart Van Assche	;;
7839*44704f69SBart Van Assche    esac
7840*44704f69SBart Van Assche
7841*44704f69SBart Van Assche    for pass in $passes; do
7842*44704f69SBart Van Assche      # The preopen pass in lib mode reverses $deplibs; put it back here
7843*44704f69SBart Van Assche      # so that -L comes before libs that need it for instance...
7844*44704f69SBart Van Assche      if test lib,link = "$linkmode,$pass"; then
7845*44704f69SBart Van Assche	## FIXME: Find the place where the list is rebuilt in the wrong
7846*44704f69SBart Van Assche	##        order, and fix it there properly
7847*44704f69SBart Van Assche        tmp_deplibs=
7848*44704f69SBart Van Assche	for deplib in $deplibs; do
7849*44704f69SBart Van Assche	  tmp_deplibs="$deplib $tmp_deplibs"
7850*44704f69SBart Van Assche	done
7851*44704f69SBart Van Assche	deplibs=$tmp_deplibs
7852*44704f69SBart Van Assche      fi
7853*44704f69SBart Van Assche
7854*44704f69SBart Van Assche      if test lib,link = "$linkmode,$pass" ||
7855*44704f69SBart Van Assche	 test prog,scan = "$linkmode,$pass"; then
7856*44704f69SBart Van Assche	libs=$deplibs
7857*44704f69SBart Van Assche	deplibs=
7858*44704f69SBart Van Assche      fi
7859*44704f69SBart Van Assche      if test prog = "$linkmode"; then
7860*44704f69SBart Van Assche	case $pass in
7861*44704f69SBart Van Assche	dlopen) libs=$dlfiles ;;
7862*44704f69SBart Van Assche	dlpreopen) libs=$dlprefiles ;;
7863*44704f69SBart Van Assche	link)
7864*44704f69SBart Van Assche	  libs="$deplibs %DEPLIBS%"
7865*44704f69SBart Van Assche	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
7866*44704f69SBart Van Assche	  ;;
7867*44704f69SBart Van Assche	esac
7868*44704f69SBart Van Assche      fi
7869*44704f69SBart Van Assche      if test lib,dlpreopen = "$linkmode,$pass"; then
7870*44704f69SBart Van Assche	# Collect and forward deplibs of preopened libtool libs
7871*44704f69SBart Van Assche	for lib in $dlprefiles; do
7872*44704f69SBart Van Assche	  # Ignore non-libtool-libs
7873*44704f69SBart Van Assche	  dependency_libs=
7874*44704f69SBart Van Assche	  func_resolve_sysroot "$lib"
7875*44704f69SBart Van Assche	  case $lib in
7876*44704f69SBart Van Assche	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7877*44704f69SBart Van Assche	  esac
7878*44704f69SBart Van Assche
7879*44704f69SBart Van Assche	  # Collect preopened libtool deplibs, except any this library
7880*44704f69SBart Van Assche	  # has declared as weak libs
7881*44704f69SBart Van Assche	  for deplib in $dependency_libs; do
7882*44704f69SBart Van Assche	    func_basename "$deplib"
7883*44704f69SBart Van Assche            deplib_base=$func_basename_result
7884*44704f69SBart Van Assche	    case " $weak_libs " in
7885*44704f69SBart Van Assche	    *" $deplib_base "*) ;;
7886*44704f69SBart Van Assche	    *) func_append deplibs " $deplib" ;;
7887*44704f69SBart Van Assche	    esac
7888*44704f69SBart Van Assche	  done
7889*44704f69SBart Van Assche	done
7890*44704f69SBart Van Assche	libs=$dlprefiles
7891*44704f69SBart Van Assche      fi
7892*44704f69SBart Van Assche      if test dlopen = "$pass"; then
7893*44704f69SBart Van Assche	# Collect dlpreopened libraries
7894*44704f69SBart Van Assche	save_deplibs=$deplibs
7895*44704f69SBart Van Assche	deplibs=
7896*44704f69SBart Van Assche      fi
7897*44704f69SBart Van Assche
7898*44704f69SBart Van Assche      for deplib in $libs; do
7899*44704f69SBart Van Assche	lib=
7900*44704f69SBart Van Assche	found=false
7901*44704f69SBart Van Assche	case $deplib in
7902*44704f69SBart Van Assche	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7903*44704f69SBart Van Assche        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7904*44704f69SBart Van Assche	  if test prog,link = "$linkmode,$pass"; then
7905*44704f69SBart Van Assche	    compile_deplibs="$deplib $compile_deplibs"
7906*44704f69SBart Van Assche	    finalize_deplibs="$deplib $finalize_deplibs"
7907*44704f69SBart Van Assche	  else
7908*44704f69SBart Van Assche	    func_append compiler_flags " $deplib"
7909*44704f69SBart Van Assche	    if test lib = "$linkmode"; then
7910*44704f69SBart Van Assche		case "$new_inherited_linker_flags " in
7911*44704f69SBart Van Assche		    *" $deplib "*) ;;
7912*44704f69SBart Van Assche		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7913*44704f69SBart Van Assche		esac
7914*44704f69SBart Van Assche	    fi
7915*44704f69SBart Van Assche	  fi
7916*44704f69SBart Van Assche	  continue
7917*44704f69SBart Van Assche	  ;;
7918*44704f69SBart Van Assche	-l*)
7919*44704f69SBart Van Assche	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7920*44704f69SBart Van Assche	    func_warning "'-l' is ignored for archives/objects"
7921*44704f69SBart Van Assche	    continue
7922*44704f69SBart Van Assche	  fi
7923*44704f69SBart Van Assche	  func_stripname '-l' '' "$deplib"
7924*44704f69SBart Van Assche	  name=$func_stripname_result
7925*44704f69SBart Van Assche	  if test lib = "$linkmode"; then
7926*44704f69SBart Van Assche	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7927*44704f69SBart Van Assche	  else
7928*44704f69SBart Van Assche	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7929*44704f69SBart Van Assche	  fi
7930*44704f69SBart Van Assche	  for searchdir in $searchdirs; do
7931*44704f69SBart Van Assche	    for search_ext in .la $std_shrext .so .a; do
7932*44704f69SBart Van Assche	      # Search the libtool library
7933*44704f69SBart Van Assche	      lib=$searchdir/lib$name$search_ext
7934*44704f69SBart Van Assche	      if test -f "$lib"; then
7935*44704f69SBart Van Assche		if test .la = "$search_ext"; then
7936*44704f69SBart Van Assche		  found=:
7937*44704f69SBart Van Assche		else
7938*44704f69SBart Van Assche		  found=false
7939*44704f69SBart Van Assche		fi
7940*44704f69SBart Van Assche		break 2
7941*44704f69SBart Van Assche	      fi
7942*44704f69SBart Van Assche	    done
7943*44704f69SBart Van Assche	  done
7944*44704f69SBart Van Assche	  if $found; then
7945*44704f69SBart Van Assche	    # deplib is a libtool library
7946*44704f69SBart Van Assche	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7947*44704f69SBart Van Assche	    # We need to do some special things here, and not later.
7948*44704f69SBart Van Assche	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7949*44704f69SBart Van Assche	      case " $predeps $postdeps " in
7950*44704f69SBart Van Assche	      *" $deplib "*)
7951*44704f69SBart Van Assche		if func_lalib_p "$lib"; then
7952*44704f69SBart Van Assche		  library_names=
7953*44704f69SBart Van Assche		  old_library=
7954*44704f69SBart Van Assche		  func_source "$lib"
7955*44704f69SBart Van Assche		  for l in $old_library $library_names; do
7956*44704f69SBart Van Assche		    ll=$l
7957*44704f69SBart Van Assche		  done
7958*44704f69SBart Van Assche		  if test "X$ll" = "X$old_library"; then # only static version available
7959*44704f69SBart Van Assche		    found=false
7960*44704f69SBart Van Assche		    func_dirname "$lib" "" "."
7961*44704f69SBart Van Assche		    ladir=$func_dirname_result
7962*44704f69SBart Van Assche		    lib=$ladir/$old_library
7963*44704f69SBart Van Assche		    if test prog,link = "$linkmode,$pass"; then
7964*44704f69SBart Van Assche		      compile_deplibs="$deplib $compile_deplibs"
7965*44704f69SBart Van Assche		      finalize_deplibs="$deplib $finalize_deplibs"
7966*44704f69SBart Van Assche		    else
7967*44704f69SBart Van Assche		      deplibs="$deplib $deplibs"
7968*44704f69SBart Van Assche		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7969*44704f69SBart Van Assche		    fi
7970*44704f69SBart Van Assche		    continue
7971*44704f69SBart Van Assche		  fi
7972*44704f69SBart Van Assche		fi
7973*44704f69SBart Van Assche		;;
7974*44704f69SBart Van Assche	      *) ;;
7975*44704f69SBart Van Assche	      esac
7976*44704f69SBart Van Assche	    fi
7977*44704f69SBart Van Assche	  else
7978*44704f69SBart Van Assche	    # deplib doesn't seem to be a libtool library
7979*44704f69SBart Van Assche	    if test prog,link = "$linkmode,$pass"; then
7980*44704f69SBart Van Assche	      compile_deplibs="$deplib $compile_deplibs"
7981*44704f69SBart Van Assche	      finalize_deplibs="$deplib $finalize_deplibs"
7982*44704f69SBart Van Assche	    else
7983*44704f69SBart Van Assche	      deplibs="$deplib $deplibs"
7984*44704f69SBart Van Assche	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7985*44704f69SBart Van Assche	    fi
7986*44704f69SBart Van Assche	    continue
7987*44704f69SBart Van Assche	  fi
7988*44704f69SBart Van Assche	  ;; # -l
7989*44704f69SBart Van Assche	*.ltframework)
7990*44704f69SBart Van Assche	  if test prog,link = "$linkmode,$pass"; then
7991*44704f69SBart Van Assche	    compile_deplibs="$deplib $compile_deplibs"
7992*44704f69SBart Van Assche	    finalize_deplibs="$deplib $finalize_deplibs"
7993*44704f69SBart Van Assche	  else
7994*44704f69SBart Van Assche	    deplibs="$deplib $deplibs"
7995*44704f69SBart Van Assche	    if test lib = "$linkmode"; then
7996*44704f69SBart Van Assche		case "$new_inherited_linker_flags " in
7997*44704f69SBart Van Assche		    *" $deplib "*) ;;
7998*44704f69SBart Van Assche		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7999*44704f69SBart Van Assche		esac
8000*44704f69SBart Van Assche	    fi
8001*44704f69SBart Van Assche	  fi
8002*44704f69SBart Van Assche	  continue
8003*44704f69SBart Van Assche	  ;;
8004*44704f69SBart Van Assche	-L*)
8005*44704f69SBart Van Assche	  case $linkmode in
8006*44704f69SBart Van Assche	  lib)
8007*44704f69SBart Van Assche	    deplibs="$deplib $deplibs"
8008*44704f69SBart Van Assche	    test conv = "$pass" && continue
8009*44704f69SBart Van Assche	    newdependency_libs="$deplib $newdependency_libs"
8010*44704f69SBart Van Assche	    func_stripname '-L' '' "$deplib"
8011*44704f69SBart Van Assche	    func_resolve_sysroot "$func_stripname_result"
8012*44704f69SBart Van Assche	    func_append newlib_search_path " $func_resolve_sysroot_result"
8013*44704f69SBart Van Assche	    ;;
8014*44704f69SBart Van Assche	  prog)
8015*44704f69SBart Van Assche	    if test conv = "$pass"; then
8016*44704f69SBart Van Assche	      deplibs="$deplib $deplibs"
8017*44704f69SBart Van Assche	      continue
8018*44704f69SBart Van Assche	    fi
8019*44704f69SBart Van Assche	    if test scan = "$pass"; then
8020*44704f69SBart Van Assche	      deplibs="$deplib $deplibs"
8021*44704f69SBart Van Assche	    else
8022*44704f69SBart Van Assche	      compile_deplibs="$deplib $compile_deplibs"
8023*44704f69SBart Van Assche	      finalize_deplibs="$deplib $finalize_deplibs"
8024*44704f69SBart Van Assche	    fi
8025*44704f69SBart Van Assche	    func_stripname '-L' '' "$deplib"
8026*44704f69SBart Van Assche	    func_resolve_sysroot "$func_stripname_result"
8027*44704f69SBart Van Assche	    func_append newlib_search_path " $func_resolve_sysroot_result"
8028*44704f69SBart Van Assche	    ;;
8029*44704f69SBart Van Assche	  *)
8030*44704f69SBart Van Assche	    func_warning "'-L' is ignored for archives/objects"
8031*44704f69SBart Van Assche	    ;;
8032*44704f69SBart Van Assche	  esac # linkmode
8033*44704f69SBart Van Assche	  continue
8034*44704f69SBart Van Assche	  ;; # -L
8035*44704f69SBart Van Assche	-R*)
8036*44704f69SBart Van Assche	  if test link = "$pass"; then
8037*44704f69SBart Van Assche	    func_stripname '-R' '' "$deplib"
8038*44704f69SBart Van Assche	    func_resolve_sysroot "$func_stripname_result"
8039*44704f69SBart Van Assche	    dir=$func_resolve_sysroot_result
8040*44704f69SBart Van Assche	    # Make sure the xrpath contains only unique directories.
8041*44704f69SBart Van Assche	    case "$xrpath " in
8042*44704f69SBart Van Assche	    *" $dir "*) ;;
8043*44704f69SBart Van Assche	    *) func_append xrpath " $dir" ;;
8044*44704f69SBart Van Assche	    esac
8045*44704f69SBart Van Assche	  fi
8046*44704f69SBart Van Assche	  deplibs="$deplib $deplibs"
8047*44704f69SBart Van Assche	  continue
8048*44704f69SBart Van Assche	  ;;
8049*44704f69SBart Van Assche	*.la)
8050*44704f69SBart Van Assche	  func_resolve_sysroot "$deplib"
8051*44704f69SBart Van Assche	  lib=$func_resolve_sysroot_result
8052*44704f69SBart Van Assche	  ;;
8053*44704f69SBart Van Assche	*.$libext)
8054*44704f69SBart Van Assche	  if test conv = "$pass"; then
8055*44704f69SBart Van Assche	    deplibs="$deplib $deplibs"
8056*44704f69SBart Van Assche	    continue
8057*44704f69SBart Van Assche	  fi
8058*44704f69SBart Van Assche	  case $linkmode in
8059*44704f69SBart Van Assche	  lib)
8060*44704f69SBart Van Assche	    # Linking convenience modules into shared libraries is allowed,
8061*44704f69SBart Van Assche	    # but linking other static libraries is non-portable.
8062*44704f69SBart Van Assche	    case " $dlpreconveniencelibs " in
8063*44704f69SBart Van Assche	    *" $deplib "*) ;;
8064*44704f69SBart Van Assche	    *)
8065*44704f69SBart Van Assche	      valid_a_lib=false
8066*44704f69SBart Van Assche	      case $deplibs_check_method in
8067*44704f69SBart Van Assche		match_pattern*)
8068*44704f69SBart Van Assche		  set dummy $deplibs_check_method; shift
8069*44704f69SBart Van Assche		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8070*44704f69SBart Van Assche		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8071*44704f69SBart Van Assche		    | $EGREP "$match_pattern_regex" > /dev/null; then
8072*44704f69SBart Van Assche		    valid_a_lib=:
8073*44704f69SBart Van Assche		  fi
8074*44704f69SBart Van Assche		;;
8075*44704f69SBart Van Assche		pass_all)
8076*44704f69SBart Van Assche		  valid_a_lib=:
8077*44704f69SBart Van Assche		;;
8078*44704f69SBart Van Assche	      esac
8079*44704f69SBart Van Assche	      if $valid_a_lib; then
8080*44704f69SBart Van Assche		echo
8081*44704f69SBart Van Assche		$ECHO "*** Warning: Linking the shared library $output against the"
8082*44704f69SBart Van Assche		$ECHO "*** static library $deplib is not portable!"
8083*44704f69SBart Van Assche		deplibs="$deplib $deplibs"
8084*44704f69SBart Van Assche	      else
8085*44704f69SBart Van Assche		echo
8086*44704f69SBart Van Assche		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8087*44704f69SBart Van Assche		echo "*** I have the capability to make that library automatically link in when"
8088*44704f69SBart Van Assche		echo "*** you link to this library.  But I can only do this if you have a"
8089*44704f69SBart Van Assche		echo "*** shared version of the library, which you do not appear to have"
8090*44704f69SBart Van Assche		echo "*** because the file extensions .$libext of this argument makes me believe"
8091*44704f69SBart Van Assche		echo "*** that it is just a static archive that I should not use here."
8092*44704f69SBart Van Assche	      fi
8093*44704f69SBart Van Assche	      ;;
8094*44704f69SBart Van Assche	    esac
8095*44704f69SBart Van Assche	    continue
8096*44704f69SBart Van Assche	    ;;
8097*44704f69SBart Van Assche	  prog)
8098*44704f69SBart Van Assche	    if test link != "$pass"; then
8099*44704f69SBart Van Assche	      deplibs="$deplib $deplibs"
8100*44704f69SBart Van Assche	    else
8101*44704f69SBart Van Assche	      compile_deplibs="$deplib $compile_deplibs"
8102*44704f69SBart Van Assche	      finalize_deplibs="$deplib $finalize_deplibs"
8103*44704f69SBart Van Assche	    fi
8104*44704f69SBart Van Assche	    continue
8105*44704f69SBart Van Assche	    ;;
8106*44704f69SBart Van Assche	  esac # linkmode
8107*44704f69SBart Van Assche	  ;; # *.$libext
8108*44704f69SBart Van Assche	*.lo | *.$objext)
8109*44704f69SBart Van Assche	  if test conv = "$pass"; then
8110*44704f69SBart Van Assche	    deplibs="$deplib $deplibs"
8111*44704f69SBart Van Assche	  elif test prog = "$linkmode"; then
8112*44704f69SBart Van Assche	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8113*44704f69SBart Van Assche	      # If there is no dlopen support or we're linking statically,
8114*44704f69SBart Van Assche	      # we need to preload.
8115*44704f69SBart Van Assche	      func_append newdlprefiles " $deplib"
8116*44704f69SBart Van Assche	      compile_deplibs="$deplib $compile_deplibs"
8117*44704f69SBart Van Assche	      finalize_deplibs="$deplib $finalize_deplibs"
8118*44704f69SBart Van Assche	    else
8119*44704f69SBart Van Assche	      func_append newdlfiles " $deplib"
8120*44704f69SBart Van Assche	    fi
8121*44704f69SBart Van Assche	  fi
8122*44704f69SBart Van Assche	  continue
8123*44704f69SBart Van Assche	  ;;
8124*44704f69SBart Van Assche	%DEPLIBS%)
8125*44704f69SBart Van Assche	  alldeplibs=:
8126*44704f69SBart Van Assche	  continue
8127*44704f69SBart Van Assche	  ;;
8128*44704f69SBart Van Assche	esac # case $deplib
8129*44704f69SBart Van Assche
8130*44704f69SBart Van Assche	$found || test -f "$lib" \
8131*44704f69SBart Van Assche	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8132*44704f69SBart Van Assche
8133*44704f69SBart Van Assche	# Check to see that this really is a libtool archive.
8134*44704f69SBart Van Assche	func_lalib_unsafe_p "$lib" \
8135*44704f69SBart Van Assche	  || func_fatal_error "'$lib' is not a valid libtool archive"
8136*44704f69SBart Van Assche
8137*44704f69SBart Van Assche	func_dirname "$lib" "" "."
8138*44704f69SBart Van Assche	ladir=$func_dirname_result
8139*44704f69SBart Van Assche
8140*44704f69SBart Van Assche	dlname=
8141*44704f69SBart Van Assche	dlopen=
8142*44704f69SBart Van Assche	dlpreopen=
8143*44704f69SBart Van Assche	libdir=
8144*44704f69SBart Van Assche	library_names=
8145*44704f69SBart Van Assche	old_library=
8146*44704f69SBart Van Assche	inherited_linker_flags=
8147*44704f69SBart Van Assche	# If the library was installed with an old release of libtool,
8148*44704f69SBart Van Assche	# it will not redefine variables installed, or shouldnotlink
8149*44704f69SBart Van Assche	installed=yes
8150*44704f69SBart Van Assche	shouldnotlink=no
8151*44704f69SBart Van Assche	avoidtemprpath=
8152*44704f69SBart Van Assche
8153*44704f69SBart Van Assche
8154*44704f69SBart Van Assche	# Read the .la file
8155*44704f69SBart Van Assche	func_source "$lib"
8156*44704f69SBart Van Assche
8157*44704f69SBart Van Assche	# Convert "-framework foo" to "foo.ltframework"
8158*44704f69SBart Van Assche	if test -n "$inherited_linker_flags"; then
8159*44704f69SBart Van Assche	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8160*44704f69SBart Van Assche	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8161*44704f69SBart Van Assche	    case " $new_inherited_linker_flags " in
8162*44704f69SBart Van Assche	      *" $tmp_inherited_linker_flag "*) ;;
8163*44704f69SBart Van Assche	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8164*44704f69SBart Van Assche	    esac
8165*44704f69SBart Van Assche	  done
8166*44704f69SBart Van Assche	fi
8167*44704f69SBart Van Assche	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8168*44704f69SBart Van Assche	if test lib,link = "$linkmode,$pass" ||
8169*44704f69SBart Van Assche	   test prog,scan = "$linkmode,$pass" ||
8170*44704f69SBart Van Assche	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8171*44704f69SBart Van Assche	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8172*44704f69SBart Van Assche	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8173*44704f69SBart Van Assche	fi
8174*44704f69SBart Van Assche
8175*44704f69SBart Van Assche	if test conv = "$pass"; then
8176*44704f69SBart Van Assche	  # Only check for convenience libraries
8177*44704f69SBart Van Assche	  deplibs="$lib $deplibs"
8178*44704f69SBart Van Assche	  if test -z "$libdir"; then
8179*44704f69SBart Van Assche	    if test -z "$old_library"; then
8180*44704f69SBart Van Assche	      func_fatal_error "cannot find name of link library for '$lib'"
8181*44704f69SBart Van Assche	    fi
8182*44704f69SBart Van Assche	    # It is a libtool convenience library, so add in its objects.
8183*44704f69SBart Van Assche	    func_append convenience " $ladir/$objdir/$old_library"
8184*44704f69SBart Van Assche	    func_append old_convenience " $ladir/$objdir/$old_library"
8185*44704f69SBart Van Assche	    tmp_libs=
8186*44704f69SBart Van Assche	    for deplib in $dependency_libs; do
8187*44704f69SBart Van Assche	      deplibs="$deplib $deplibs"
8188*44704f69SBart Van Assche	      if $opt_preserve_dup_deps; then
8189*44704f69SBart Van Assche		case "$tmp_libs " in
8190*44704f69SBart Van Assche		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
8191*44704f69SBart Van Assche		esac
8192*44704f69SBart Van Assche	      fi
8193*44704f69SBart Van Assche	      func_append tmp_libs " $deplib"
8194*44704f69SBart Van Assche	    done
8195*44704f69SBart Van Assche	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8196*44704f69SBart Van Assche	    func_fatal_error "'$lib' is not a convenience library"
8197*44704f69SBart Van Assche	  fi
8198*44704f69SBart Van Assche	  continue
8199*44704f69SBart Van Assche	fi # $pass = conv
8200*44704f69SBart Van Assche
8201*44704f69SBart Van Assche
8202*44704f69SBart Van Assche	# Get the name of the library we link against.
8203*44704f69SBart Van Assche	linklib=
8204*44704f69SBart Van Assche	if test -n "$old_library" &&
8205*44704f69SBart Van Assche	   { test yes = "$prefer_static_libs" ||
8206*44704f69SBart Van Assche	     test built,no = "$prefer_static_libs,$installed"; }; then
8207*44704f69SBart Van Assche	  linklib=$old_library
8208*44704f69SBart Van Assche	else
8209*44704f69SBart Van Assche	  for l in $old_library $library_names; do
8210*44704f69SBart Van Assche	    linklib=$l
8211*44704f69SBart Van Assche	  done
8212*44704f69SBart Van Assche	fi
8213*44704f69SBart Van Assche	if test -z "$linklib"; then
8214*44704f69SBart Van Assche	  func_fatal_error "cannot find name of link library for '$lib'"
8215*44704f69SBart Van Assche	fi
8216*44704f69SBart Van Assche
8217*44704f69SBart Van Assche	# This library was specified with -dlopen.
8218*44704f69SBart Van Assche	if test dlopen = "$pass"; then
8219*44704f69SBart Van Assche	  test -z "$libdir" \
8220*44704f69SBart Van Assche	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8221*44704f69SBart Van Assche	  if test -z "$dlname" ||
8222*44704f69SBart Van Assche	     test yes != "$dlopen_support" ||
8223*44704f69SBart Van Assche	     test no = "$build_libtool_libs"
8224*44704f69SBart Van Assche	  then
8225*44704f69SBart Van Assche	    # If there is no dlname, no dlopen support or we're linking
8226*44704f69SBart Van Assche	    # statically, we need to preload.  We also need to preload any
8227*44704f69SBart Van Assche	    # dependent libraries so libltdl's deplib preloader doesn't
8228*44704f69SBart Van Assche	    # bomb out in the load deplibs phase.
8229*44704f69SBart Van Assche	    func_append dlprefiles " $lib $dependency_libs"
8230*44704f69SBart Van Assche	  else
8231*44704f69SBart Van Assche	    func_append newdlfiles " $lib"
8232*44704f69SBart Van Assche	  fi
8233*44704f69SBart Van Assche	  continue
8234*44704f69SBart Van Assche	fi # $pass = dlopen
8235*44704f69SBart Van Assche
8236*44704f69SBart Van Assche	# We need an absolute path.
8237*44704f69SBart Van Assche	case $ladir in
8238*44704f69SBart Van Assche	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8239*44704f69SBart Van Assche	*)
8240*44704f69SBart Van Assche	  abs_ladir=`cd "$ladir" && pwd`
8241*44704f69SBart Van Assche	  if test -z "$abs_ladir"; then
8242*44704f69SBart Van Assche	    func_warning "cannot determine absolute directory name of '$ladir'"
8243*44704f69SBart Van Assche	    func_warning "passing it literally to the linker, although it might fail"
8244*44704f69SBart Van Assche	    abs_ladir=$ladir
8245*44704f69SBart Van Assche	  fi
8246*44704f69SBart Van Assche	  ;;
8247*44704f69SBart Van Assche	esac
8248*44704f69SBart Van Assche	func_basename "$lib"
8249*44704f69SBart Van Assche	laname=$func_basename_result
8250*44704f69SBart Van Assche
8251*44704f69SBart Van Assche	# Find the relevant object directory and library name.
8252*44704f69SBart Van Assche	if test yes = "$installed"; then
8253*44704f69SBart Van Assche	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8254*44704f69SBart Van Assche	    func_warning "library '$lib' was moved."
8255*44704f69SBart Van Assche	    dir=$ladir
8256*44704f69SBart Van Assche	    absdir=$abs_ladir
8257*44704f69SBart Van Assche	    libdir=$abs_ladir
8258*44704f69SBart Van Assche	  else
8259*44704f69SBart Van Assche	    dir=$lt_sysroot$libdir
8260*44704f69SBart Van Assche	    absdir=$lt_sysroot$libdir
8261*44704f69SBart Van Assche	  fi
8262*44704f69SBart Van Assche	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8263*44704f69SBart Van Assche	else
8264*44704f69SBart Van Assche	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8265*44704f69SBart Van Assche	    dir=$ladir
8266*44704f69SBart Van Assche	    absdir=$abs_ladir
8267*44704f69SBart Van Assche	    # Remove this search path later
8268*44704f69SBart Van Assche	    func_append notinst_path " $abs_ladir"
8269*44704f69SBart Van Assche	  else
8270*44704f69SBart Van Assche	    dir=$ladir/$objdir
8271*44704f69SBart Van Assche	    absdir=$abs_ladir/$objdir
8272*44704f69SBart Van Assche	    # Remove this search path later
8273*44704f69SBart Van Assche	    func_append notinst_path " $abs_ladir"
8274*44704f69SBart Van Assche	  fi
8275*44704f69SBart Van Assche	fi # $installed = yes
8276*44704f69SBart Van Assche	func_stripname 'lib' '.la' "$laname"
8277*44704f69SBart Van Assche	name=$func_stripname_result
8278*44704f69SBart Van Assche
8279*44704f69SBart Van Assche	# This library was specified with -dlpreopen.
8280*44704f69SBart Van Assche	if test dlpreopen = "$pass"; then
8281*44704f69SBart Van Assche	  if test -z "$libdir" && test prog = "$linkmode"; then
8282*44704f69SBart Van Assche	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8283*44704f69SBart Van Assche	  fi
8284*44704f69SBart Van Assche	  case $host in
8285*44704f69SBart Van Assche	    # special handling for platforms with PE-DLLs.
8286*44704f69SBart Van Assche	    *cygwin* | *mingw* | *cegcc* )
8287*44704f69SBart Van Assche	      # Linker will automatically link against shared library if both
8288*44704f69SBart Van Assche	      # static and shared are present.  Therefore, ensure we extract
8289*44704f69SBart Van Assche	      # symbols from the import library if a shared library is present
8290*44704f69SBart Van Assche	      # (otherwise, the dlopen module name will be incorrect).  We do
8291*44704f69SBart Van Assche	      # this by putting the import library name into $newdlprefiles.
8292*44704f69SBart Van Assche	      # We recover the dlopen module name by 'saving' the la file
8293*44704f69SBart Van Assche	      # name in a special purpose variable, and (later) extracting the
8294*44704f69SBart Van Assche	      # dlname from the la file.
8295*44704f69SBart Van Assche	      if test -n "$dlname"; then
8296*44704f69SBart Van Assche	        func_tr_sh "$dir/$linklib"
8297*44704f69SBart Van Assche	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8298*44704f69SBart Van Assche	        func_append newdlprefiles " $dir/$linklib"
8299*44704f69SBart Van Assche	      else
8300*44704f69SBart Van Assche	        func_append newdlprefiles " $dir/$old_library"
8301*44704f69SBart Van Assche	        # Keep a list of preopened convenience libraries to check
8302*44704f69SBart Van Assche	        # that they are being used correctly in the link pass.
8303*44704f69SBart Van Assche	        test -z "$libdir" && \
8304*44704f69SBart Van Assche	          func_append dlpreconveniencelibs " $dir/$old_library"
8305*44704f69SBart Van Assche	      fi
8306*44704f69SBart Van Assche	    ;;
8307*44704f69SBart Van Assche	    * )
8308*44704f69SBart Van Assche	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8309*44704f69SBart Van Assche	      # are required to link).
8310*44704f69SBart Van Assche	      if test -n "$old_library"; then
8311*44704f69SBart Van Assche	        func_append newdlprefiles " $dir/$old_library"
8312*44704f69SBart Van Assche	        # Keep a list of preopened convenience libraries to check
8313*44704f69SBart Van Assche	        # that they are being used correctly in the link pass.
8314*44704f69SBart Van Assche	        test -z "$libdir" && \
8315*44704f69SBart Van Assche	          func_append dlpreconveniencelibs " $dir/$old_library"
8316*44704f69SBart Van Assche	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8317*44704f69SBart Van Assche	      elif test -n "$dlname"; then
8318*44704f69SBart Van Assche	        func_append newdlprefiles " $dir/$dlname"
8319*44704f69SBart Van Assche	      else
8320*44704f69SBart Van Assche	        func_append newdlprefiles " $dir/$linklib"
8321*44704f69SBart Van Assche	      fi
8322*44704f69SBart Van Assche	    ;;
8323*44704f69SBart Van Assche	  esac
8324*44704f69SBart Van Assche	fi # $pass = dlpreopen
8325*44704f69SBart Van Assche
8326*44704f69SBart Van Assche	if test -z "$libdir"; then
8327*44704f69SBart Van Assche	  # Link the convenience library
8328*44704f69SBart Van Assche	  if test lib = "$linkmode"; then
8329*44704f69SBart Van Assche	    deplibs="$dir/$old_library $deplibs"
8330*44704f69SBart Van Assche	  elif test prog,link = "$linkmode,$pass"; then
8331*44704f69SBart Van Assche	    compile_deplibs="$dir/$old_library $compile_deplibs"
8332*44704f69SBart Van Assche	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8333*44704f69SBart Van Assche	  else
8334*44704f69SBart Van Assche	    deplibs="$lib $deplibs" # used for prog,scan pass
8335*44704f69SBart Van Assche	  fi
8336*44704f69SBart Van Assche	  continue
8337*44704f69SBart Van Assche	fi
8338*44704f69SBart Van Assche
8339*44704f69SBart Van Assche
8340*44704f69SBart Van Assche	if test prog = "$linkmode" && test link != "$pass"; then
8341*44704f69SBart Van Assche	  func_append newlib_search_path " $ladir"
8342*44704f69SBart Van Assche	  deplibs="$lib $deplibs"
8343*44704f69SBart Van Assche
8344*44704f69SBart Van Assche	  linkalldeplibs=false
8345*44704f69SBart Van Assche	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8346*44704f69SBart Van Assche	     test no = "$build_libtool_libs"; then
8347*44704f69SBart Van Assche	    linkalldeplibs=:
8348*44704f69SBart Van Assche	  fi
8349*44704f69SBart Van Assche
8350*44704f69SBart Van Assche	  tmp_libs=
8351*44704f69SBart Van Assche	  for deplib in $dependency_libs; do
8352*44704f69SBart Van Assche	    case $deplib in
8353*44704f69SBart Van Assche	    -L*) func_stripname '-L' '' "$deplib"
8354*44704f69SBart Van Assche	         func_resolve_sysroot "$func_stripname_result"
8355*44704f69SBart Van Assche	         func_append newlib_search_path " $func_resolve_sysroot_result"
8356*44704f69SBart Van Assche		 ;;
8357*44704f69SBart Van Assche	    esac
8358*44704f69SBart Van Assche	    # Need to link against all dependency_libs?
8359*44704f69SBart Van Assche	    if $linkalldeplibs; then
8360*44704f69SBart Van Assche	      deplibs="$deplib $deplibs"
8361*44704f69SBart Van Assche	    else
8362*44704f69SBart Van Assche	      # Need to hardcode shared library paths
8363*44704f69SBart Van Assche	      # or/and link against static libraries
8364*44704f69SBart Van Assche	      newdependency_libs="$deplib $newdependency_libs"
8365*44704f69SBart Van Assche	    fi
8366*44704f69SBart Van Assche	    if $opt_preserve_dup_deps; then
8367*44704f69SBart Van Assche	      case "$tmp_libs " in
8368*44704f69SBart Van Assche	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8369*44704f69SBart Van Assche	      esac
8370*44704f69SBart Van Assche	    fi
8371*44704f69SBart Van Assche	    func_append tmp_libs " $deplib"
8372*44704f69SBart Van Assche	  done # for deplib
8373*44704f69SBart Van Assche	  continue
8374*44704f69SBart Van Assche	fi # $linkmode = prog...
8375*44704f69SBart Van Assche
8376*44704f69SBart Van Assche	if test prog,link = "$linkmode,$pass"; then
8377*44704f69SBart Van Assche	  if test -n "$library_names" &&
8378*44704f69SBart Van Assche	     { { test no = "$prefer_static_libs" ||
8379*44704f69SBart Van Assche	         test built,yes = "$prefer_static_libs,$installed"; } ||
8380*44704f69SBart Van Assche	       test -z "$old_library"; }; then
8381*44704f69SBart Van Assche	    # We need to hardcode the library path
8382*44704f69SBart Van Assche	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8383*44704f69SBart Van Assche	      # Make sure the rpath contains only unique directories.
8384*44704f69SBart Van Assche	      case $temp_rpath: in
8385*44704f69SBart Van Assche	      *"$absdir:"*) ;;
8386*44704f69SBart Van Assche	      *) func_append temp_rpath "$absdir:" ;;
8387*44704f69SBart Van Assche	      esac
8388*44704f69SBart Van Assche	    fi
8389*44704f69SBart Van Assche
8390*44704f69SBart Van Assche	    # Hardcode the library path.
8391*44704f69SBart Van Assche	    # Skip directories that are in the system default run-time
8392*44704f69SBart Van Assche	    # search path.
8393*44704f69SBart Van Assche	    case " $sys_lib_dlsearch_path " in
8394*44704f69SBart Van Assche	    *" $absdir "*) ;;
8395*44704f69SBart Van Assche	    *)
8396*44704f69SBart Van Assche	      case "$compile_rpath " in
8397*44704f69SBart Van Assche	      *" $absdir "*) ;;
8398*44704f69SBart Van Assche	      *) func_append compile_rpath " $absdir" ;;
8399*44704f69SBart Van Assche	      esac
8400*44704f69SBart Van Assche	      ;;
8401*44704f69SBart Van Assche	    esac
8402*44704f69SBart Van Assche	    case " $sys_lib_dlsearch_path " in
8403*44704f69SBart Van Assche	    *" $libdir "*) ;;
8404*44704f69SBart Van Assche	    *)
8405*44704f69SBart Van Assche	      case "$finalize_rpath " in
8406*44704f69SBart Van Assche	      *" $libdir "*) ;;
8407*44704f69SBart Van Assche	      *) func_append finalize_rpath " $libdir" ;;
8408*44704f69SBart Van Assche	      esac
8409*44704f69SBart Van Assche	      ;;
8410*44704f69SBart Van Assche	    esac
8411*44704f69SBart Van Assche	  fi # $linkmode,$pass = prog,link...
8412*44704f69SBart Van Assche
8413*44704f69SBart Van Assche	  if $alldeplibs &&
8414*44704f69SBart Van Assche	     { test pass_all = "$deplibs_check_method" ||
8415*44704f69SBart Van Assche	       { test yes = "$build_libtool_libs" &&
8416*44704f69SBart Van Assche		 test -n "$library_names"; }; }; then
8417*44704f69SBart Van Assche	    # We only need to search for static libraries
8418*44704f69SBart Van Assche	    continue
8419*44704f69SBart Van Assche	  fi
8420*44704f69SBart Van Assche	fi
8421*44704f69SBart Van Assche
8422*44704f69SBart Van Assche	link_static=no # Whether the deplib will be linked statically
8423*44704f69SBart Van Assche	use_static_libs=$prefer_static_libs
8424*44704f69SBart Van Assche	if test built = "$use_static_libs" && test yes = "$installed"; then
8425*44704f69SBart Van Assche	  use_static_libs=no
8426*44704f69SBart Van Assche	fi
8427*44704f69SBart Van Assche	if test -n "$library_names" &&
8428*44704f69SBart Van Assche	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8429*44704f69SBart Van Assche	  case $host in
8430*44704f69SBart Van Assche	  *cygwin* | *mingw* | *cegcc* | *os2*)
8431*44704f69SBart Van Assche	      # No point in relinking DLLs because paths are not encoded
8432*44704f69SBart Van Assche	      func_append notinst_deplibs " $lib"
8433*44704f69SBart Van Assche	      need_relink=no
8434*44704f69SBart Van Assche	    ;;
8435*44704f69SBart Van Assche	  *)
8436*44704f69SBart Van Assche	    if test no = "$installed"; then
8437*44704f69SBart Van Assche	      func_append notinst_deplibs " $lib"
8438*44704f69SBart Van Assche	      need_relink=yes
8439*44704f69SBart Van Assche	    fi
8440*44704f69SBart Van Assche	    ;;
8441*44704f69SBart Van Assche	  esac
8442*44704f69SBart Van Assche	  # This is a shared library
8443*44704f69SBart Van Assche
8444*44704f69SBart Van Assche	  # Warn about portability, can't link against -module's on some
8445*44704f69SBart Van Assche	  # systems (darwin).  Don't bleat about dlopened modules though!
8446*44704f69SBart Van Assche	  dlopenmodule=
8447*44704f69SBart Van Assche	  for dlpremoduletest in $dlprefiles; do
8448*44704f69SBart Van Assche	    if test "X$dlpremoduletest" = "X$lib"; then
8449*44704f69SBart Van Assche	      dlopenmodule=$dlpremoduletest
8450*44704f69SBart Van Assche	      break
8451*44704f69SBart Van Assche	    fi
8452*44704f69SBart Van Assche	  done
8453*44704f69SBart Van Assche	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8454*44704f69SBart Van Assche	    echo
8455*44704f69SBart Van Assche	    if test prog = "$linkmode"; then
8456*44704f69SBart Van Assche	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8457*44704f69SBart Van Assche	    else
8458*44704f69SBart Van Assche	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8459*44704f69SBart Van Assche	    fi
8460*44704f69SBart Van Assche	    $ECHO "*** $linklib is not portable!"
8461*44704f69SBart Van Assche	  fi
8462*44704f69SBart Van Assche	  if test lib = "$linkmode" &&
8463*44704f69SBart Van Assche	     test yes = "$hardcode_into_libs"; then
8464*44704f69SBart Van Assche	    # Hardcode the library path.
8465*44704f69SBart Van Assche	    # Skip directories that are in the system default run-time
8466*44704f69SBart Van Assche	    # search path.
8467*44704f69SBart Van Assche	    case " $sys_lib_dlsearch_path " in
8468*44704f69SBart Van Assche	    *" $absdir "*) ;;
8469*44704f69SBart Van Assche	    *)
8470*44704f69SBart Van Assche	      case "$compile_rpath " in
8471*44704f69SBart Van Assche	      *" $absdir "*) ;;
8472*44704f69SBart Van Assche	      *) func_append compile_rpath " $absdir" ;;
8473*44704f69SBart Van Assche	      esac
8474*44704f69SBart Van Assche	      ;;
8475*44704f69SBart Van Assche	    esac
8476*44704f69SBart Van Assche	    case " $sys_lib_dlsearch_path " in
8477*44704f69SBart Van Assche	    *" $libdir "*) ;;
8478*44704f69SBart Van Assche	    *)
8479*44704f69SBart Van Assche	      case "$finalize_rpath " in
8480*44704f69SBart Van Assche	      *" $libdir "*) ;;
8481*44704f69SBart Van Assche	      *) func_append finalize_rpath " $libdir" ;;
8482*44704f69SBart Van Assche	      esac
8483*44704f69SBart Van Assche	      ;;
8484*44704f69SBart Van Assche	    esac
8485*44704f69SBart Van Assche	  fi
8486*44704f69SBart Van Assche
8487*44704f69SBart Van Assche	  if test -n "$old_archive_from_expsyms_cmds"; then
8488*44704f69SBart Van Assche	    # figure out the soname
8489*44704f69SBart Van Assche	    set dummy $library_names
8490*44704f69SBart Van Assche	    shift
8491*44704f69SBart Van Assche	    realname=$1
8492*44704f69SBart Van Assche	    shift
8493*44704f69SBart Van Assche	    libname=`eval "\\$ECHO \"$libname_spec\""`
8494*44704f69SBart Van Assche	    # use dlname if we got it. it's perfectly good, no?
8495*44704f69SBart Van Assche	    if test -n "$dlname"; then
8496*44704f69SBart Van Assche	      soname=$dlname
8497*44704f69SBart Van Assche	    elif test -n "$soname_spec"; then
8498*44704f69SBart Van Assche	      # bleh windows
8499*44704f69SBart Van Assche	      case $host in
8500*44704f69SBart Van Assche	      *cygwin* | mingw* | *cegcc* | *os2*)
8501*44704f69SBart Van Assche	        func_arith $current - $age
8502*44704f69SBart Van Assche		major=$func_arith_result
8503*44704f69SBart Van Assche		versuffix=-$major
8504*44704f69SBart Van Assche		;;
8505*44704f69SBart Van Assche	      esac
8506*44704f69SBart Van Assche	      eval soname=\"$soname_spec\"
8507*44704f69SBart Van Assche	    else
8508*44704f69SBart Van Assche	      soname=$realname
8509*44704f69SBart Van Assche	    fi
8510*44704f69SBart Van Assche
8511*44704f69SBart Van Assche	    # Make a new name for the extract_expsyms_cmds to use
8512*44704f69SBart Van Assche	    soroot=$soname
8513*44704f69SBart Van Assche	    func_basename "$soroot"
8514*44704f69SBart Van Assche	    soname=$func_basename_result
8515*44704f69SBart Van Assche	    func_stripname 'lib' '.dll' "$soname"
8516*44704f69SBart Van Assche	    newlib=libimp-$func_stripname_result.a
8517*44704f69SBart Van Assche
8518*44704f69SBart Van Assche	    # If the library has no export list, then create one now
8519*44704f69SBart Van Assche	    if test -f "$output_objdir/$soname-def"; then :
8520*44704f69SBart Van Assche	    else
8521*44704f69SBart Van Assche	      func_verbose "extracting exported symbol list from '$soname'"
8522*44704f69SBart Van Assche	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8523*44704f69SBart Van Assche	    fi
8524*44704f69SBart Van Assche
8525*44704f69SBart Van Assche	    # Create $newlib
8526*44704f69SBart Van Assche	    if test -f "$output_objdir/$newlib"; then :; else
8527*44704f69SBart Van Assche	      func_verbose "generating import library for '$soname'"
8528*44704f69SBart Van Assche	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8529*44704f69SBart Van Assche	    fi
8530*44704f69SBart Van Assche	    # make sure the library variables are pointing to the new library
8531*44704f69SBart Van Assche	    dir=$output_objdir
8532*44704f69SBart Van Assche	    linklib=$newlib
8533*44704f69SBart Van Assche	  fi # test -n "$old_archive_from_expsyms_cmds"
8534*44704f69SBart Van Assche
8535*44704f69SBart Van Assche	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8536*44704f69SBart Van Assche	    add_shlibpath=
8537*44704f69SBart Van Assche	    add_dir=
8538*44704f69SBart Van Assche	    add=
8539*44704f69SBart Van Assche	    lib_linked=yes
8540*44704f69SBart Van Assche	    case $hardcode_action in
8541*44704f69SBart Van Assche	    immediate | unsupported)
8542*44704f69SBart Van Assche	      if test no = "$hardcode_direct"; then
8543*44704f69SBart Van Assche		add=$dir/$linklib
8544*44704f69SBart Van Assche		case $host in
8545*44704f69SBart Van Assche		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8546*44704f69SBart Van Assche		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8547*44704f69SBart Van Assche		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8548*44704f69SBart Van Assche		    *-*-unixware7*) add_dir=-L$dir ;;
8549*44704f69SBart Van Assche		  *-*-darwin* )
8550*44704f69SBart Van Assche		    # if the lib is a (non-dlopened) module then we cannot
8551*44704f69SBart Van Assche		    # link against it, someone is ignoring the earlier warnings
8552*44704f69SBart Van Assche		    if /usr/bin/file -L $add 2> /dev/null |
8553*44704f69SBart Van Assche			 $GREP ": [^:]* bundle" >/dev/null; then
8554*44704f69SBart Van Assche		      if test "X$dlopenmodule" != "X$lib"; then
8555*44704f69SBart Van Assche			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8556*44704f69SBart Van Assche			if test -z "$old_library"; then
8557*44704f69SBart Van Assche			  echo
8558*44704f69SBart Van Assche			  echo "*** And there doesn't seem to be a static archive available"
8559*44704f69SBart Van Assche			  echo "*** The link will probably fail, sorry"
8560*44704f69SBart Van Assche			else
8561*44704f69SBart Van Assche			  add=$dir/$old_library
8562*44704f69SBart Van Assche			fi
8563*44704f69SBart Van Assche		      elif test -n "$old_library"; then
8564*44704f69SBart Van Assche			add=$dir/$old_library
8565*44704f69SBart Van Assche		      fi
8566*44704f69SBart Van Assche		    fi
8567*44704f69SBart Van Assche		esac
8568*44704f69SBart Van Assche	      elif test no = "$hardcode_minus_L"; then
8569*44704f69SBart Van Assche		case $host in
8570*44704f69SBart Van Assche		*-*-sunos*) add_shlibpath=$dir ;;
8571*44704f69SBart Van Assche		esac
8572*44704f69SBart Van Assche		add_dir=-L$dir
8573*44704f69SBart Van Assche		add=-l$name
8574*44704f69SBart Van Assche	      elif test no = "$hardcode_shlibpath_var"; then
8575*44704f69SBart Van Assche		add_shlibpath=$dir
8576*44704f69SBart Van Assche		add=-l$name
8577*44704f69SBart Van Assche	      else
8578*44704f69SBart Van Assche		lib_linked=no
8579*44704f69SBart Van Assche	      fi
8580*44704f69SBart Van Assche	      ;;
8581*44704f69SBart Van Assche	    relink)
8582*44704f69SBart Van Assche	      if test yes = "$hardcode_direct" &&
8583*44704f69SBart Van Assche	         test no = "$hardcode_direct_absolute"; then
8584*44704f69SBart Van Assche		add=$dir/$linklib
8585*44704f69SBart Van Assche	      elif test yes = "$hardcode_minus_L"; then
8586*44704f69SBart Van Assche		add_dir=-L$absdir
8587*44704f69SBart Van Assche		# Try looking first in the location we're being installed to.
8588*44704f69SBart Van Assche		if test -n "$inst_prefix_dir"; then
8589*44704f69SBart Van Assche		  case $libdir in
8590*44704f69SBart Van Assche		    [\\/]*)
8591*44704f69SBart Van Assche		      func_append add_dir " -L$inst_prefix_dir$libdir"
8592*44704f69SBart Van Assche		      ;;
8593*44704f69SBart Van Assche		  esac
8594*44704f69SBart Van Assche		fi
8595*44704f69SBart Van Assche		add=-l$name
8596*44704f69SBart Van Assche	      elif test yes = "$hardcode_shlibpath_var"; then
8597*44704f69SBart Van Assche		add_shlibpath=$dir
8598*44704f69SBart Van Assche		add=-l$name
8599*44704f69SBart Van Assche	      else
8600*44704f69SBart Van Assche		lib_linked=no
8601*44704f69SBart Van Assche	      fi
8602*44704f69SBart Van Assche	      ;;
8603*44704f69SBart Van Assche	    *) lib_linked=no ;;
8604*44704f69SBart Van Assche	    esac
8605*44704f69SBart Van Assche
8606*44704f69SBart Van Assche	    if test yes != "$lib_linked"; then
8607*44704f69SBart Van Assche	      func_fatal_configuration "unsupported hardcode properties"
8608*44704f69SBart Van Assche	    fi
8609*44704f69SBart Van Assche
8610*44704f69SBart Van Assche	    if test -n "$add_shlibpath"; then
8611*44704f69SBart Van Assche	      case :$compile_shlibpath: in
8612*44704f69SBart Van Assche	      *":$add_shlibpath:"*) ;;
8613*44704f69SBart Van Assche	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8614*44704f69SBart Van Assche	      esac
8615*44704f69SBart Van Assche	    fi
8616*44704f69SBart Van Assche	    if test prog = "$linkmode"; then
8617*44704f69SBart Van Assche	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8618*44704f69SBart Van Assche	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8619*44704f69SBart Van Assche	    else
8620*44704f69SBart Van Assche	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8621*44704f69SBart Van Assche	      test -n "$add" && deplibs="$add $deplibs"
8622*44704f69SBart Van Assche	      if test yes != "$hardcode_direct" &&
8623*44704f69SBart Van Assche		 test yes != "$hardcode_minus_L" &&
8624*44704f69SBart Van Assche		 test yes = "$hardcode_shlibpath_var"; then
8625*44704f69SBart Van Assche		case :$finalize_shlibpath: in
8626*44704f69SBart Van Assche		*":$libdir:"*) ;;
8627*44704f69SBart Van Assche		*) func_append finalize_shlibpath "$libdir:" ;;
8628*44704f69SBart Van Assche		esac
8629*44704f69SBart Van Assche	      fi
8630*44704f69SBart Van Assche	    fi
8631*44704f69SBart Van Assche	  fi
8632*44704f69SBart Van Assche
8633*44704f69SBart Van Assche	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8634*44704f69SBart Van Assche	    add_shlibpath=
8635*44704f69SBart Van Assche	    add_dir=
8636*44704f69SBart Van Assche	    add=
8637*44704f69SBart Van Assche	    # Finalize command for both is simple: just hardcode it.
8638*44704f69SBart Van Assche	    if test yes = "$hardcode_direct" &&
8639*44704f69SBart Van Assche	       test no = "$hardcode_direct_absolute"; then
8640*44704f69SBart Van Assche	      add=$libdir/$linklib
8641*44704f69SBart Van Assche	    elif test yes = "$hardcode_minus_L"; then
8642*44704f69SBart Van Assche	      add_dir=-L$libdir
8643*44704f69SBart Van Assche	      add=-l$name
8644*44704f69SBart Van Assche	    elif test yes = "$hardcode_shlibpath_var"; then
8645*44704f69SBart Van Assche	      case :$finalize_shlibpath: in
8646*44704f69SBart Van Assche	      *":$libdir:"*) ;;
8647*44704f69SBart Van Assche	      *) func_append finalize_shlibpath "$libdir:" ;;
8648*44704f69SBart Van Assche	      esac
8649*44704f69SBart Van Assche	      add=-l$name
8650*44704f69SBart Van Assche	    elif test yes = "$hardcode_automatic"; then
8651*44704f69SBart Van Assche	      if test -n "$inst_prefix_dir" &&
8652*44704f69SBart Van Assche		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8653*44704f69SBart Van Assche		add=$inst_prefix_dir$libdir/$linklib
8654*44704f69SBart Van Assche	      else
8655*44704f69SBart Van Assche		add=$libdir/$linklib
8656*44704f69SBart Van Assche	      fi
8657*44704f69SBart Van Assche	    else
8658*44704f69SBart Van Assche	      # We cannot seem to hardcode it, guess we'll fake it.
8659*44704f69SBart Van Assche	      add_dir=-L$libdir
8660*44704f69SBart Van Assche	      # Try looking first in the location we're being installed to.
8661*44704f69SBart Van Assche	      if test -n "$inst_prefix_dir"; then
8662*44704f69SBart Van Assche		case $libdir in
8663*44704f69SBart Van Assche		  [\\/]*)
8664*44704f69SBart Van Assche		    func_append add_dir " -L$inst_prefix_dir$libdir"
8665*44704f69SBart Van Assche		    ;;
8666*44704f69SBart Van Assche		esac
8667*44704f69SBart Van Assche	      fi
8668*44704f69SBart Van Assche	      add=-l$name
8669*44704f69SBart Van Assche	    fi
8670*44704f69SBart Van Assche
8671*44704f69SBart Van Assche	    if test prog = "$linkmode"; then
8672*44704f69SBart Van Assche	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8673*44704f69SBart Van Assche	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8674*44704f69SBart Van Assche	    else
8675*44704f69SBart Van Assche	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8676*44704f69SBart Van Assche	      test -n "$add" && deplibs="$add $deplibs"
8677*44704f69SBart Van Assche	    fi
8678*44704f69SBart Van Assche	  fi
8679*44704f69SBart Van Assche	elif test prog = "$linkmode"; then
8680*44704f69SBart Van Assche	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8681*44704f69SBart Van Assche	  # is not unsupported.  This is valid on all known static and
8682*44704f69SBart Van Assche	  # shared platforms.
8683*44704f69SBart Van Assche	  if test unsupported != "$hardcode_direct"; then
8684*44704f69SBart Van Assche	    test -n "$old_library" && linklib=$old_library
8685*44704f69SBart Van Assche	    compile_deplibs="$dir/$linklib $compile_deplibs"
8686*44704f69SBart Van Assche	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8687*44704f69SBart Van Assche	  else
8688*44704f69SBart Van Assche	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8689*44704f69SBart Van Assche	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8690*44704f69SBart Van Assche	  fi
8691*44704f69SBart Van Assche	elif test yes = "$build_libtool_libs"; then
8692*44704f69SBart Van Assche	  # Not a shared library
8693*44704f69SBart Van Assche	  if test pass_all != "$deplibs_check_method"; then
8694*44704f69SBart Van Assche	    # We're trying link a shared library against a static one
8695*44704f69SBart Van Assche	    # but the system doesn't support it.
8696*44704f69SBart Van Assche
8697*44704f69SBart Van Assche	    # Just print a warning and add the library to dependency_libs so
8698*44704f69SBart Van Assche	    # that the program can be linked against the static library.
8699*44704f69SBart Van Assche	    echo
8700*44704f69SBart Van Assche	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8701*44704f69SBart Van Assche	    echo "*** I have the capability to make that library automatically link in when"
8702*44704f69SBart Van Assche	    echo "*** you link to this library.  But I can only do this if you have a"
8703*44704f69SBart Van Assche	    echo "*** shared version of the library, which you do not appear to have."
8704*44704f69SBart Van Assche	    if test yes = "$module"; then
8705*44704f69SBart Van Assche	      echo "*** But as you try to build a module library, libtool will still create "
8706*44704f69SBart Van Assche	      echo "*** a static module, that should work as long as the dlopening application"
8707*44704f69SBart Van Assche	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8708*44704f69SBart Van Assche	      if test -z "$global_symbol_pipe"; then
8709*44704f69SBart Van Assche		echo
8710*44704f69SBart Van Assche		echo "*** However, this would only work if libtool was able to extract symbol"
8711*44704f69SBart Van Assche		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8712*44704f69SBart Van Assche		echo "*** not find such a program.  So, this module is probably useless."
8713*44704f69SBart Van Assche		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8714*44704f69SBart Van Assche	      fi
8715*44704f69SBart Van Assche	      if test no = "$build_old_libs"; then
8716*44704f69SBart Van Assche		build_libtool_libs=module
8717*44704f69SBart Van Assche		build_old_libs=yes
8718*44704f69SBart Van Assche	      else
8719*44704f69SBart Van Assche		build_libtool_libs=no
8720*44704f69SBart Van Assche	      fi
8721*44704f69SBart Van Assche	    fi
8722*44704f69SBart Van Assche	  else
8723*44704f69SBart Van Assche	    deplibs="$dir/$old_library $deplibs"
8724*44704f69SBart Van Assche	    link_static=yes
8725*44704f69SBart Van Assche	  fi
8726*44704f69SBart Van Assche	fi # link shared/static library?
8727*44704f69SBart Van Assche
8728*44704f69SBart Van Assche	if test lib = "$linkmode"; then
8729*44704f69SBart Van Assche	  if test -n "$dependency_libs" &&
8730*44704f69SBart Van Assche	     { test yes != "$hardcode_into_libs" ||
8731*44704f69SBart Van Assche	       test yes = "$build_old_libs" ||
8732*44704f69SBart Van Assche	       test yes = "$link_static"; }; then
8733*44704f69SBart Van Assche	    # Extract -R from dependency_libs
8734*44704f69SBart Van Assche	    temp_deplibs=
8735*44704f69SBart Van Assche	    for libdir in $dependency_libs; do
8736*44704f69SBart Van Assche	      case $libdir in
8737*44704f69SBart Van Assche	      -R*) func_stripname '-R' '' "$libdir"
8738*44704f69SBart Van Assche	           temp_xrpath=$func_stripname_result
8739*44704f69SBart Van Assche		   case " $xrpath " in
8740*44704f69SBart Van Assche		   *" $temp_xrpath "*) ;;
8741*44704f69SBart Van Assche		   *) func_append xrpath " $temp_xrpath";;
8742*44704f69SBart Van Assche		   esac;;
8743*44704f69SBart Van Assche	      *) func_append temp_deplibs " $libdir";;
8744*44704f69SBart Van Assche	      esac
8745*44704f69SBart Van Assche	    done
8746*44704f69SBart Van Assche	    dependency_libs=$temp_deplibs
8747*44704f69SBart Van Assche	  fi
8748*44704f69SBart Van Assche
8749*44704f69SBart Van Assche	  func_append newlib_search_path " $absdir"
8750*44704f69SBart Van Assche	  # Link against this library
8751*44704f69SBart Van Assche	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8752*44704f69SBart Van Assche	  # ... and its dependency_libs
8753*44704f69SBart Van Assche	  tmp_libs=
8754*44704f69SBart Van Assche	  for deplib in $dependency_libs; do
8755*44704f69SBart Van Assche	    newdependency_libs="$deplib $newdependency_libs"
8756*44704f69SBart Van Assche	    case $deplib in
8757*44704f69SBart Van Assche              -L*) func_stripname '-L' '' "$deplib"
8758*44704f69SBart Van Assche                   func_resolve_sysroot "$func_stripname_result";;
8759*44704f69SBart Van Assche              *) func_resolve_sysroot "$deplib" ;;
8760*44704f69SBart Van Assche            esac
8761*44704f69SBart Van Assche	    if $opt_preserve_dup_deps; then
8762*44704f69SBart Van Assche	      case "$tmp_libs " in
8763*44704f69SBart Van Assche	      *" $func_resolve_sysroot_result "*)
8764*44704f69SBart Van Assche                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8765*44704f69SBart Van Assche	      esac
8766*44704f69SBart Van Assche	    fi
8767*44704f69SBart Van Assche	    func_append tmp_libs " $func_resolve_sysroot_result"
8768*44704f69SBart Van Assche	  done
8769*44704f69SBart Van Assche
8770*44704f69SBart Van Assche	  if test no != "$link_all_deplibs"; then
8771*44704f69SBart Van Assche	    # Add the search paths of all dependency libraries
8772*44704f69SBart Van Assche	    for deplib in $dependency_libs; do
8773*44704f69SBart Van Assche	      path=
8774*44704f69SBart Van Assche	      case $deplib in
8775*44704f69SBart Van Assche	      -L*) path=$deplib ;;
8776*44704f69SBart Van Assche	      *.la)
8777*44704f69SBart Van Assche	        func_resolve_sysroot "$deplib"
8778*44704f69SBart Van Assche	        deplib=$func_resolve_sysroot_result
8779*44704f69SBart Van Assche	        func_dirname "$deplib" "" "."
8780*44704f69SBart Van Assche		dir=$func_dirname_result
8781*44704f69SBart Van Assche		# We need an absolute path.
8782*44704f69SBart Van Assche		case $dir in
8783*44704f69SBart Van Assche		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8784*44704f69SBart Van Assche		*)
8785*44704f69SBart Van Assche		  absdir=`cd "$dir" && pwd`
8786*44704f69SBart Van Assche		  if test -z "$absdir"; then
8787*44704f69SBart Van Assche		    func_warning "cannot determine absolute directory name of '$dir'"
8788*44704f69SBart Van Assche		    absdir=$dir
8789*44704f69SBart Van Assche		  fi
8790*44704f69SBart Van Assche		  ;;
8791*44704f69SBart Van Assche		esac
8792*44704f69SBart Van Assche		if $GREP "^installed=no" $deplib > /dev/null; then
8793*44704f69SBart Van Assche		case $host in
8794*44704f69SBart Van Assche		*-*-darwin*)
8795*44704f69SBart Van Assche		  depdepl=
8796*44704f69SBart Van Assche		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8797*44704f69SBart Van Assche		  if test -n "$deplibrary_names"; then
8798*44704f69SBart Van Assche		    for tmp in $deplibrary_names; do
8799*44704f69SBart Van Assche		      depdepl=$tmp
8800*44704f69SBart Van Assche		    done
8801*44704f69SBart Van Assche		    if test -f "$absdir/$objdir/$depdepl"; then
8802*44704f69SBart Van Assche		      depdepl=$absdir/$objdir/$depdepl
8803*44704f69SBart Van Assche		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8804*44704f69SBart Van Assche                      if test -z "$darwin_install_name"; then
8805*44704f69SBart Van Assche                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8806*44704f69SBart Van Assche                      fi
8807*44704f69SBart Van Assche		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8808*44704f69SBart Van Assche		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8809*44704f69SBart Van Assche		      path=
8810*44704f69SBart Van Assche		    fi
8811*44704f69SBart Van Assche		  fi
8812*44704f69SBart Van Assche		  ;;
8813*44704f69SBart Van Assche		*)
8814*44704f69SBart Van Assche		  path=-L$absdir/$objdir
8815*44704f69SBart Van Assche		  ;;
8816*44704f69SBart Van Assche		esac
8817*44704f69SBart Van Assche		else
8818*44704f69SBart Van Assche		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8819*44704f69SBart Van Assche		  test -z "$libdir" && \
8820*44704f69SBart Van Assche		    func_fatal_error "'$deplib' is not a valid libtool archive"
8821*44704f69SBart Van Assche		  test "$absdir" != "$libdir" && \
8822*44704f69SBart Van Assche		    func_warning "'$deplib' seems to be moved"
8823*44704f69SBart Van Assche
8824*44704f69SBart Van Assche		  path=-L$absdir
8825*44704f69SBart Van Assche		fi
8826*44704f69SBart Van Assche		;;
8827*44704f69SBart Van Assche	      esac
8828*44704f69SBart Van Assche	      case " $deplibs " in
8829*44704f69SBart Van Assche	      *" $path "*) ;;
8830*44704f69SBart Van Assche	      *) deplibs="$path $deplibs" ;;
8831*44704f69SBart Van Assche	      esac
8832*44704f69SBart Van Assche	    done
8833*44704f69SBart Van Assche	  fi # link_all_deplibs != no
8834*44704f69SBart Van Assche	fi # linkmode = lib
8835*44704f69SBart Van Assche      done # for deplib in $libs
8836*44704f69SBart Van Assche      if test link = "$pass"; then
8837*44704f69SBart Van Assche	if test prog = "$linkmode"; then
8838*44704f69SBart Van Assche	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8839*44704f69SBart Van Assche	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8840*44704f69SBart Van Assche	else
8841*44704f69SBart Van Assche	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8842*44704f69SBart Van Assche	fi
8843*44704f69SBart Van Assche      fi
8844*44704f69SBart Van Assche      dependency_libs=$newdependency_libs
8845*44704f69SBart Van Assche      if test dlpreopen = "$pass"; then
8846*44704f69SBart Van Assche	# Link the dlpreopened libraries before other libraries
8847*44704f69SBart Van Assche	for deplib in $save_deplibs; do
8848*44704f69SBart Van Assche	  deplibs="$deplib $deplibs"
8849*44704f69SBart Van Assche	done
8850*44704f69SBart Van Assche      fi
8851*44704f69SBart Van Assche      if test dlopen != "$pass"; then
8852*44704f69SBart Van Assche	test conv = "$pass" || {
8853*44704f69SBart Van Assche	  # Make sure lib_search_path contains only unique directories.
8854*44704f69SBart Van Assche	  lib_search_path=
8855*44704f69SBart Van Assche	  for dir in $newlib_search_path; do
8856*44704f69SBart Van Assche	    case "$lib_search_path " in
8857*44704f69SBart Van Assche	    *" $dir "*) ;;
8858*44704f69SBart Van Assche	    *) func_append lib_search_path " $dir" ;;
8859*44704f69SBart Van Assche	    esac
8860*44704f69SBart Van Assche	  done
8861*44704f69SBart Van Assche	  newlib_search_path=
8862*44704f69SBart Van Assche	}
8863*44704f69SBart Van Assche
8864*44704f69SBart Van Assche	if test prog,link = "$linkmode,$pass"; then
8865*44704f69SBart Van Assche	  vars="compile_deplibs finalize_deplibs"
8866*44704f69SBart Van Assche	else
8867*44704f69SBart Van Assche	  vars=deplibs
8868*44704f69SBart Van Assche	fi
8869*44704f69SBart Van Assche	for var in $vars dependency_libs; do
8870*44704f69SBart Van Assche	  # Add libraries to $var in reverse order
8871*44704f69SBart Van Assche	  eval tmp_libs=\"\$$var\"
8872*44704f69SBart Van Assche	  new_libs=
8873*44704f69SBart Van Assche	  for deplib in $tmp_libs; do
8874*44704f69SBart Van Assche	    # FIXME: Pedantically, this is the right thing to do, so
8875*44704f69SBart Van Assche	    #        that some nasty dependency loop isn't accidentally
8876*44704f69SBart Van Assche	    #        broken:
8877*44704f69SBart Van Assche	    #new_libs="$deplib $new_libs"
8878*44704f69SBart Van Assche	    # Pragmatically, this seems to cause very few problems in
8879*44704f69SBart Van Assche	    # practice:
8880*44704f69SBart Van Assche	    case $deplib in
8881*44704f69SBart Van Assche	    -L*) new_libs="$deplib $new_libs" ;;
8882*44704f69SBart Van Assche	    -R*) ;;
8883*44704f69SBart Van Assche	    *)
8884*44704f69SBart Van Assche	      # And here is the reason: when a library appears more
8885*44704f69SBart Van Assche	      # than once as an explicit dependence of a library, or
8886*44704f69SBart Van Assche	      # is implicitly linked in more than once by the
8887*44704f69SBart Van Assche	      # compiler, it is considered special, and multiple
8888*44704f69SBart Van Assche	      # occurrences thereof are not removed.  Compare this
8889*44704f69SBart Van Assche	      # with having the same library being listed as a
8890*44704f69SBart Van Assche	      # dependency of multiple other libraries: in this case,
8891*44704f69SBart Van Assche	      # we know (pedantically, we assume) the library does not
8892*44704f69SBart Van Assche	      # need to be listed more than once, so we keep only the
8893*44704f69SBart Van Assche	      # last copy.  This is not always right, but it is rare
8894*44704f69SBart Van Assche	      # enough that we require users that really mean to play
8895*44704f69SBart Van Assche	      # such unportable linking tricks to link the library
8896*44704f69SBart Van Assche	      # using -Wl,-lname, so that libtool does not consider it
8897*44704f69SBart Van Assche	      # for duplicate removal.
8898*44704f69SBart Van Assche	      case " $specialdeplibs " in
8899*44704f69SBart Van Assche	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8900*44704f69SBart Van Assche	      *)
8901*44704f69SBart Van Assche		case " $new_libs " in
8902*44704f69SBart Van Assche		*" $deplib "*) ;;
8903*44704f69SBart Van Assche		*) new_libs="$deplib $new_libs" ;;
8904*44704f69SBart Van Assche		esac
8905*44704f69SBart Van Assche		;;
8906*44704f69SBart Van Assche	      esac
8907*44704f69SBart Van Assche	      ;;
8908*44704f69SBart Van Assche	    esac
8909*44704f69SBart Van Assche	  done
8910*44704f69SBart Van Assche	  tmp_libs=
8911*44704f69SBart Van Assche	  for deplib in $new_libs; do
8912*44704f69SBart Van Assche	    case $deplib in
8913*44704f69SBart Van Assche	    -L*)
8914*44704f69SBart Van Assche	      case " $tmp_libs " in
8915*44704f69SBart Van Assche	      *" $deplib "*) ;;
8916*44704f69SBart Van Assche	      *) func_append tmp_libs " $deplib" ;;
8917*44704f69SBart Van Assche	      esac
8918*44704f69SBart Van Assche	      ;;
8919*44704f69SBart Van Assche	    *) func_append tmp_libs " $deplib" ;;
8920*44704f69SBart Van Assche	    esac
8921*44704f69SBart Van Assche	  done
8922*44704f69SBart Van Assche	  eval $var=\"$tmp_libs\"
8923*44704f69SBart Van Assche	done # for var
8924*44704f69SBart Van Assche      fi
8925*44704f69SBart Van Assche
8926*44704f69SBart Van Assche      # Add Sun CC postdeps if required:
8927*44704f69SBart Van Assche      test CXX = "$tagname" && {
8928*44704f69SBart Van Assche        case $host_os in
8929*44704f69SBart Van Assche        linux*)
8930*44704f69SBart Van Assche          case `$CC -V 2>&1 | $SED 5q` in
8931*44704f69SBart Van Assche          *Sun\ C*) # Sun C++ 5.9
8932*44704f69SBart Van Assche            func_suncc_cstd_abi
8933*44704f69SBart Van Assche
8934*44704f69SBart Van Assche            if test no != "$suncc_use_cstd_abi"; then
8935*44704f69SBart Van Assche              func_append postdeps ' -library=Cstd -library=Crun'
8936*44704f69SBart Van Assche            fi
8937*44704f69SBart Van Assche            ;;
8938*44704f69SBart Van Assche          esac
8939*44704f69SBart Van Assche          ;;
8940*44704f69SBart Van Assche
8941*44704f69SBart Van Assche        solaris*)
8942*44704f69SBart Van Assche          func_cc_basename "$CC"
8943*44704f69SBart Van Assche          case $func_cc_basename_result in
8944*44704f69SBart Van Assche          CC* | sunCC*)
8945*44704f69SBart Van Assche            func_suncc_cstd_abi
8946*44704f69SBart Van Assche
8947*44704f69SBart Van Assche            if test no != "$suncc_use_cstd_abi"; then
8948*44704f69SBart Van Assche              func_append postdeps ' -library=Cstd -library=Crun'
8949*44704f69SBart Van Assche            fi
8950*44704f69SBart Van Assche            ;;
8951*44704f69SBart Van Assche          esac
8952*44704f69SBart Van Assche          ;;
8953*44704f69SBart Van Assche        esac
8954*44704f69SBart Van Assche      }
8955*44704f69SBart Van Assche
8956*44704f69SBart Van Assche      # Last step: remove runtime libs from dependency_libs
8957*44704f69SBart Van Assche      # (they stay in deplibs)
8958*44704f69SBart Van Assche      tmp_libs=
8959*44704f69SBart Van Assche      for i in $dependency_libs; do
8960*44704f69SBart Van Assche	case " $predeps $postdeps $compiler_lib_search_path " in
8961*44704f69SBart Van Assche	*" $i "*)
8962*44704f69SBart Van Assche	  i=
8963*44704f69SBart Van Assche	  ;;
8964*44704f69SBart Van Assche	esac
8965*44704f69SBart Van Assche	if test -n "$i"; then
8966*44704f69SBart Van Assche	  func_append tmp_libs " $i"
8967*44704f69SBart Van Assche	fi
8968*44704f69SBart Van Assche      done
8969*44704f69SBart Van Assche      dependency_libs=$tmp_libs
8970*44704f69SBart Van Assche    done # for pass
8971*44704f69SBart Van Assche    if test prog = "$linkmode"; then
8972*44704f69SBart Van Assche      dlfiles=$newdlfiles
8973*44704f69SBart Van Assche    fi
8974*44704f69SBart Van Assche    if test prog = "$linkmode" || test lib = "$linkmode"; then
8975*44704f69SBart Van Assche      dlprefiles=$newdlprefiles
8976*44704f69SBart Van Assche    fi
8977*44704f69SBart Van Assche
8978*44704f69SBart Van Assche    case $linkmode in
8979*44704f69SBart Van Assche    oldlib)
8980*44704f69SBart Van Assche      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8981*44704f69SBart Van Assche	func_warning "'-dlopen' is ignored for archives"
8982*44704f69SBart Van Assche      fi
8983*44704f69SBart Van Assche
8984*44704f69SBart Van Assche      case " $deplibs" in
8985*44704f69SBart Van Assche      *\ -l* | *\ -L*)
8986*44704f69SBart Van Assche	func_warning "'-l' and '-L' are ignored for archives" ;;
8987*44704f69SBart Van Assche      esac
8988*44704f69SBart Van Assche
8989*44704f69SBart Van Assche      test -n "$rpath" && \
8990*44704f69SBart Van Assche	func_warning "'-rpath' is ignored for archives"
8991*44704f69SBart Van Assche
8992*44704f69SBart Van Assche      test -n "$xrpath" && \
8993*44704f69SBart Van Assche	func_warning "'-R' is ignored for archives"
8994*44704f69SBart Van Assche
8995*44704f69SBart Van Assche      test -n "$vinfo" && \
8996*44704f69SBart Van Assche	func_warning "'-version-info/-version-number' is ignored for archives"
8997*44704f69SBart Van Assche
8998*44704f69SBart Van Assche      test -n "$release" && \
8999*44704f69SBart Van Assche	func_warning "'-release' is ignored for archives"
9000*44704f69SBart Van Assche
9001*44704f69SBart Van Assche      test -n "$export_symbols$export_symbols_regex" && \
9002*44704f69SBart Van Assche	func_warning "'-export-symbols' is ignored for archives"
9003*44704f69SBart Van Assche
9004*44704f69SBart Van Assche      # Now set the variables for building old libraries.
9005*44704f69SBart Van Assche      build_libtool_libs=no
9006*44704f69SBart Van Assche      oldlibs=$output
9007*44704f69SBart Van Assche      func_append objs "$old_deplibs"
9008*44704f69SBart Van Assche      ;;
9009*44704f69SBart Van Assche
9010*44704f69SBart Van Assche    lib)
9011*44704f69SBart Van Assche      # Make sure we only generate libraries of the form 'libNAME.la'.
9012*44704f69SBart Van Assche      case $outputname in
9013*44704f69SBart Van Assche      lib*)
9014*44704f69SBart Van Assche	func_stripname 'lib' '.la' "$outputname"
9015*44704f69SBart Van Assche	name=$func_stripname_result
9016*44704f69SBart Van Assche	eval shared_ext=\"$shrext_cmds\"
9017*44704f69SBart Van Assche	eval libname=\"$libname_spec\"
9018*44704f69SBart Van Assche	;;
9019*44704f69SBart Van Assche      *)
9020*44704f69SBart Van Assche	test no = "$module" \
9021*44704f69SBart Van Assche	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9022*44704f69SBart Van Assche
9023*44704f69SBart Van Assche	if test no != "$need_lib_prefix"; then
9024*44704f69SBart Van Assche	  # Add the "lib" prefix for modules if required
9025*44704f69SBart Van Assche	  func_stripname '' '.la' "$outputname"
9026*44704f69SBart Van Assche	  name=$func_stripname_result
9027*44704f69SBart Van Assche	  eval shared_ext=\"$shrext_cmds\"
9028*44704f69SBart Van Assche	  eval libname=\"$libname_spec\"
9029*44704f69SBart Van Assche	else
9030*44704f69SBart Van Assche	  func_stripname '' '.la' "$outputname"
9031*44704f69SBart Van Assche	  libname=$func_stripname_result
9032*44704f69SBart Van Assche	fi
9033*44704f69SBart Van Assche	;;
9034*44704f69SBart Van Assche      esac
9035*44704f69SBart Van Assche
9036*44704f69SBart Van Assche      if test -n "$objs"; then
9037*44704f69SBart Van Assche	if test pass_all != "$deplibs_check_method"; then
9038*44704f69SBart Van Assche	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9039*44704f69SBart Van Assche	else
9040*44704f69SBart Van Assche	  echo
9041*44704f69SBart Van Assche	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9042*44704f69SBart Van Assche	  $ECHO "*** objects $objs is not portable!"
9043*44704f69SBart Van Assche	  func_append libobjs " $objs"
9044*44704f69SBart Van Assche	fi
9045*44704f69SBart Van Assche      fi
9046*44704f69SBart Van Assche
9047*44704f69SBart Van Assche      test no = "$dlself" \
9048*44704f69SBart Van Assche	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9049*44704f69SBart Van Assche
9050*44704f69SBart Van Assche      set dummy $rpath
9051*44704f69SBart Van Assche      shift
9052*44704f69SBart Van Assche      test 1 -lt "$#" \
9053*44704f69SBart Van Assche	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9054*44704f69SBart Van Assche
9055*44704f69SBart Van Assche      install_libdir=$1
9056*44704f69SBart Van Assche
9057*44704f69SBart Van Assche      oldlibs=
9058*44704f69SBart Van Assche      if test -z "$rpath"; then
9059*44704f69SBart Van Assche	if test yes = "$build_libtool_libs"; then
9060*44704f69SBart Van Assche	  # Building a libtool convenience library.
9061*44704f69SBart Van Assche	  # Some compilers have problems with a '.al' extension so
9062*44704f69SBart Van Assche	  # convenience libraries should have the same extension an
9063*44704f69SBart Van Assche	  # archive normally would.
9064*44704f69SBart Van Assche	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9065*44704f69SBart Van Assche	  build_libtool_libs=convenience
9066*44704f69SBart Van Assche	  build_old_libs=yes
9067*44704f69SBart Van Assche	fi
9068*44704f69SBart Van Assche
9069*44704f69SBart Van Assche	test -n "$vinfo" && \
9070*44704f69SBart Van Assche	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9071*44704f69SBart Van Assche
9072*44704f69SBart Van Assche	test -n "$release" && \
9073*44704f69SBart Van Assche	  func_warning "'-release' is ignored for convenience libraries"
9074*44704f69SBart Van Assche      else
9075*44704f69SBart Van Assche
9076*44704f69SBart Van Assche	# Parse the version information argument.
9077*44704f69SBart Van Assche	save_ifs=$IFS; IFS=:
9078*44704f69SBart Van Assche	set dummy $vinfo 0 0 0
9079*44704f69SBart Van Assche	shift
9080*44704f69SBart Van Assche	IFS=$save_ifs
9081*44704f69SBart Van Assche
9082*44704f69SBart Van Assche	test -n "$7" && \
9083*44704f69SBart Van Assche	  func_fatal_help "too many parameters to '-version-info'"
9084*44704f69SBart Van Assche
9085*44704f69SBart Van Assche	# convert absolute version numbers to libtool ages
9086*44704f69SBart Van Assche	# this retains compatibility with .la files and attempts
9087*44704f69SBart Van Assche	# to make the code below a bit more comprehensible
9088*44704f69SBart Van Assche
9089*44704f69SBart Van Assche	case $vinfo_number in
9090*44704f69SBart Van Assche	yes)
9091*44704f69SBart Van Assche	  number_major=$1
9092*44704f69SBart Van Assche	  number_minor=$2
9093*44704f69SBart Van Assche	  number_revision=$3
9094*44704f69SBart Van Assche	  #
9095*44704f69SBart Van Assche	  # There are really only two kinds -- those that
9096*44704f69SBart Van Assche	  # use the current revision as the major version
9097*44704f69SBart Van Assche	  # and those that subtract age and use age as
9098*44704f69SBart Van Assche	  # a minor version.  But, then there is irix
9099*44704f69SBart Van Assche	  # that has an extra 1 added just for fun
9100*44704f69SBart Van Assche	  #
9101*44704f69SBart Van Assche	  case $version_type in
9102*44704f69SBart Van Assche	  # correct linux to gnu/linux during the next big refactor
9103*44704f69SBart Van Assche	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9104*44704f69SBart Van Assche	    func_arith $number_major + $number_minor
9105*44704f69SBart Van Assche	    current=$func_arith_result
9106*44704f69SBart Van Assche	    age=$number_minor
9107*44704f69SBart Van Assche	    revision=$number_revision
9108*44704f69SBart Van Assche	    ;;
9109*44704f69SBart Van Assche	  freebsd-aout|qnx|sunos)
9110*44704f69SBart Van Assche	    current=$number_major
9111*44704f69SBart Van Assche	    revision=$number_minor
9112*44704f69SBart Van Assche	    age=0
9113*44704f69SBart Van Assche	    ;;
9114*44704f69SBart Van Assche	  irix|nonstopux)
9115*44704f69SBart Van Assche	    func_arith $number_major + $number_minor
9116*44704f69SBart Van Assche	    current=$func_arith_result
9117*44704f69SBart Van Assche	    age=$number_minor
9118*44704f69SBart Van Assche	    revision=$number_minor
9119*44704f69SBart Van Assche	    lt_irix_increment=no
9120*44704f69SBart Van Assche	    ;;
9121*44704f69SBart Van Assche	  *)
9122*44704f69SBart Van Assche	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
9123*44704f69SBart Van Assche	    ;;
9124*44704f69SBart Van Assche	  esac
9125*44704f69SBart Van Assche	  ;;
9126*44704f69SBart Van Assche	no)
9127*44704f69SBart Van Assche	  current=$1
9128*44704f69SBart Van Assche	  revision=$2
9129*44704f69SBart Van Assche	  age=$3
9130*44704f69SBart Van Assche	  ;;
9131*44704f69SBart Van Assche	esac
9132*44704f69SBart Van Assche
9133*44704f69SBart Van Assche	# Check that each of the things are valid numbers.
9134*44704f69SBart Van Assche	case $current in
9135*44704f69SBart Van Assche	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]) ;;
9136*44704f69SBart Van Assche	*)
9137*44704f69SBart Van Assche	  func_error "CURRENT '$current' must be a nonnegative integer"
9138*44704f69SBart Van Assche	  func_fatal_error "'$vinfo' is not valid version information"
9139*44704f69SBart Van Assche	  ;;
9140*44704f69SBart Van Assche	esac
9141*44704f69SBart Van Assche
9142*44704f69SBart Van Assche	case $revision in
9143*44704f69SBart Van Assche	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]) ;;
9144*44704f69SBart Van Assche	*)
9145*44704f69SBart Van Assche	  func_error "REVISION '$revision' must be a nonnegative integer"
9146*44704f69SBart Van Assche	  func_fatal_error "'$vinfo' is not valid version information"
9147*44704f69SBart Van Assche	  ;;
9148*44704f69SBart Van Assche	esac
9149*44704f69SBart Van Assche
9150*44704f69SBart Van Assche	case $age in
9151*44704f69SBart Van Assche	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]) ;;
9152*44704f69SBart Van Assche	*)
9153*44704f69SBart Van Assche	  func_error "AGE '$age' must be a nonnegative integer"
9154*44704f69SBart Van Assche	  func_fatal_error "'$vinfo' is not valid version information"
9155*44704f69SBart Van Assche	  ;;
9156*44704f69SBart Van Assche	esac
9157*44704f69SBart Van Assche
9158*44704f69SBart Van Assche	if test "$age" -gt "$current"; then
9159*44704f69SBart Van Assche	  func_error "AGE '$age' is greater than the current interface number '$current'"
9160*44704f69SBart Van Assche	  func_fatal_error "'$vinfo' is not valid version information"
9161*44704f69SBart Van Assche	fi
9162*44704f69SBart Van Assche
9163*44704f69SBart Van Assche	# Calculate the version variables.
9164*44704f69SBart Van Assche	major=
9165*44704f69SBart Van Assche	versuffix=
9166*44704f69SBart Van Assche	verstring=
9167*44704f69SBart Van Assche	case $version_type in
9168*44704f69SBart Van Assche	none) ;;
9169*44704f69SBart Van Assche
9170*44704f69SBart Van Assche	darwin)
9171*44704f69SBart Van Assche	  # Like Linux, but with the current version available in
9172*44704f69SBart Van Assche	  # verstring for coding it into the library header
9173*44704f69SBart Van Assche	  func_arith $current - $age
9174*44704f69SBart Van Assche	  major=.$func_arith_result
9175*44704f69SBart Van Assche	  versuffix=$major.$age.$revision
9176*44704f69SBart Van Assche	  # Darwin ld doesn't like 0 for these options...
9177*44704f69SBart Van Assche	  func_arith $current + 1
9178*44704f69SBart Van Assche	  minor_current=$func_arith_result
9179*44704f69SBart Van Assche	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9180*44704f69SBart Van Assche	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9181*44704f69SBart Van Assche          # On Darwin other compilers
9182*44704f69SBart Van Assche          case $CC in
9183*44704f69SBart Van Assche              nagfor*)
9184*44704f69SBart Van Assche                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9185*44704f69SBart Van Assche                  ;;
9186*44704f69SBart Van Assche              *)
9187*44704f69SBart Van Assche                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9188*44704f69SBart Van Assche                  ;;
9189*44704f69SBart Van Assche          esac
9190*44704f69SBart Van Assche	  ;;
9191*44704f69SBart Van Assche
9192*44704f69SBart Van Assche	freebsd-aout)
9193*44704f69SBart Van Assche	  major=.$current
9194*44704f69SBart Van Assche	  versuffix=.$current.$revision
9195*44704f69SBart Van Assche	  ;;
9196*44704f69SBart Van Assche
9197*44704f69SBart Van Assche	freebsd-elf | midnightbsd-elf)
9198*44704f69SBart Van Assche	  func_arith $current - $age
9199*44704f69SBart Van Assche	  major=.$func_arith_result
9200*44704f69SBart Van Assche	  versuffix=$major.$age.$revision
9201*44704f69SBart Van Assche	  ;;
9202*44704f69SBart Van Assche
9203*44704f69SBart Van Assche	irix | nonstopux)
9204*44704f69SBart Van Assche	  if test no = "$lt_irix_increment"; then
9205*44704f69SBart Van Assche	    func_arith $current - $age
9206*44704f69SBart Van Assche	  else
9207*44704f69SBart Van Assche	    func_arith $current - $age + 1
9208*44704f69SBart Van Assche	  fi
9209*44704f69SBart Van Assche	  major=$func_arith_result
9210*44704f69SBart Van Assche
9211*44704f69SBart Van Assche	  case $version_type in
9212*44704f69SBart Van Assche	    nonstopux) verstring_prefix=nonstopux ;;
9213*44704f69SBart Van Assche	    *)         verstring_prefix=sgi ;;
9214*44704f69SBart Van Assche	  esac
9215*44704f69SBart Van Assche	  verstring=$verstring_prefix$major.$revision
9216*44704f69SBart Van Assche
9217*44704f69SBart Van Assche	  # Add in all the interfaces that we are compatible with.
9218*44704f69SBart Van Assche	  loop=$revision
9219*44704f69SBart Van Assche	  while test 0 -ne "$loop"; do
9220*44704f69SBart Van Assche	    func_arith $revision - $loop
9221*44704f69SBart Van Assche	    iface=$func_arith_result
9222*44704f69SBart Van Assche	    func_arith $loop - 1
9223*44704f69SBart Van Assche	    loop=$func_arith_result
9224*44704f69SBart Van Assche	    verstring=$verstring_prefix$major.$iface:$verstring
9225*44704f69SBart Van Assche	  done
9226*44704f69SBart Van Assche
9227*44704f69SBart Van Assche	  # Before this point, $major must not contain '.'.
9228*44704f69SBart Van Assche	  major=.$major
9229*44704f69SBart Van Assche	  versuffix=$major.$revision
9230*44704f69SBart Van Assche	  ;;
9231*44704f69SBart Van Assche
9232*44704f69SBart Van Assche	linux) # correct to gnu/linux during the next big refactor
9233*44704f69SBart Van Assche	  func_arith $current - $age
9234*44704f69SBart Van Assche	  major=.$func_arith_result
9235*44704f69SBart Van Assche	  versuffix=$major.$age.$revision
9236*44704f69SBart Van Assche	  ;;
9237*44704f69SBart Van Assche
9238*44704f69SBart Van Assche	osf)
9239*44704f69SBart Van Assche	  func_arith $current - $age
9240*44704f69SBart Van Assche	  major=.$func_arith_result
9241*44704f69SBart Van Assche	  versuffix=.$current.$age.$revision
9242*44704f69SBart Van Assche	  verstring=$current.$age.$revision
9243*44704f69SBart Van Assche
9244*44704f69SBart Van Assche	  # Add in all the interfaces that we are compatible with.
9245*44704f69SBart Van Assche	  loop=$age
9246*44704f69SBart Van Assche	  while test 0 -ne "$loop"; do
9247*44704f69SBart Van Assche	    func_arith $current - $loop
9248*44704f69SBart Van Assche	    iface=$func_arith_result
9249*44704f69SBart Van Assche	    func_arith $loop - 1
9250*44704f69SBart Van Assche	    loop=$func_arith_result
9251*44704f69SBart Van Assche	    verstring=$verstring:$iface.0
9252*44704f69SBart Van Assche	  done
9253*44704f69SBart Van Assche
9254*44704f69SBart Van Assche	  # Make executables depend on our current version.
9255*44704f69SBart Van Assche	  func_append verstring ":$current.0"
9256*44704f69SBart Van Assche	  ;;
9257*44704f69SBart Van Assche
9258*44704f69SBart Van Assche	qnx)
9259*44704f69SBart Van Assche	  major=.$current
9260*44704f69SBart Van Assche	  versuffix=.$current
9261*44704f69SBart Van Assche	  ;;
9262*44704f69SBart Van Assche
9263*44704f69SBart Van Assche	sco)
9264*44704f69SBart Van Assche	  major=.$current
9265*44704f69SBart Van Assche	  versuffix=.$current
9266*44704f69SBart Van Assche	  ;;
9267*44704f69SBart Van Assche
9268*44704f69SBart Van Assche	sunos)
9269*44704f69SBart Van Assche	  major=.$current
9270*44704f69SBart Van Assche	  versuffix=.$current.$revision
9271*44704f69SBart Van Assche	  ;;
9272*44704f69SBart Van Assche
9273*44704f69SBart Van Assche	windows)
9274*44704f69SBart Van Assche	  # Use '-' rather than '.', since we only want one
9275*44704f69SBart Van Assche	  # extension on DOS 8.3 file systems.
9276*44704f69SBart Van Assche	  func_arith $current - $age
9277*44704f69SBart Van Assche	  major=$func_arith_result
9278*44704f69SBart Van Assche	  versuffix=-$major
9279*44704f69SBart Van Assche	  ;;
9280*44704f69SBart Van Assche
9281*44704f69SBart Van Assche	*)
9282*44704f69SBart Van Assche	  func_fatal_configuration "unknown library version type '$version_type'"
9283*44704f69SBart Van Assche	  ;;
9284*44704f69SBart Van Assche	esac
9285*44704f69SBart Van Assche
9286*44704f69SBart Van Assche	# Clear the version info if we defaulted, and they specified a release.
9287*44704f69SBart Van Assche	if test -z "$vinfo" && test -n "$release"; then
9288*44704f69SBart Van Assche	  major=
9289*44704f69SBart Van Assche	  case $version_type in
9290*44704f69SBart Van Assche	  darwin)
9291*44704f69SBart Van Assche	    # we can't check for "0.0" in archive_cmds due to quoting
9292*44704f69SBart Van Assche	    # problems, so we reset it completely
9293*44704f69SBart Van Assche	    verstring=
9294*44704f69SBart Van Assche	    ;;
9295*44704f69SBart Van Assche	  *)
9296*44704f69SBart Van Assche	    verstring=0.0
9297*44704f69SBart Van Assche	    ;;
9298*44704f69SBart Van Assche	  esac
9299*44704f69SBart Van Assche	  if test no = "$need_version"; then
9300*44704f69SBart Van Assche	    versuffix=
9301*44704f69SBart Van Assche	  else
9302*44704f69SBart Van Assche	    versuffix=.0.0
9303*44704f69SBart Van Assche	  fi
9304*44704f69SBart Van Assche	fi
9305*44704f69SBart Van Assche
9306*44704f69SBart Van Assche	# Remove version info from name if versioning should be avoided
9307*44704f69SBart Van Assche	if test yes,no = "$avoid_version,$need_version"; then
9308*44704f69SBart Van Assche	  major=
9309*44704f69SBart Van Assche	  versuffix=
9310*44704f69SBart Van Assche	  verstring=
9311*44704f69SBart Van Assche	fi
9312*44704f69SBart Van Assche
9313*44704f69SBart Van Assche	# Check to see if the archive will have undefined symbols.
9314*44704f69SBart Van Assche	if test yes = "$allow_undefined"; then
9315*44704f69SBart Van Assche	  if test unsupported = "$allow_undefined_flag"; then
9316*44704f69SBart Van Assche	    if test yes = "$build_old_libs"; then
9317*44704f69SBart Van Assche	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9318*44704f69SBart Van Assche	      build_libtool_libs=no
9319*44704f69SBart Van Assche	    else
9320*44704f69SBart Van Assche	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9321*44704f69SBart Van Assche	    fi
9322*44704f69SBart Van Assche	  fi
9323*44704f69SBart Van Assche	else
9324*44704f69SBart Van Assche	  # Don't allow undefined symbols.
9325*44704f69SBart Van Assche	  allow_undefined_flag=$no_undefined_flag
9326*44704f69SBart Van Assche	fi
9327*44704f69SBart Van Assche
9328*44704f69SBart Van Assche      fi
9329*44704f69SBart Van Assche
9330*44704f69SBart Van Assche      func_generate_dlsyms "$libname" "$libname" :
9331*44704f69SBart Van Assche      func_append libobjs " $symfileobj"
9332*44704f69SBart Van Assche      test " " = "$libobjs" && libobjs=
9333*44704f69SBart Van Assche
9334*44704f69SBart Van Assche      if test relink != "$opt_mode"; then
9335*44704f69SBart Van Assche	# Remove our outputs, but don't remove object files since they
9336*44704f69SBart Van Assche	# may have been created when compiling PIC objects.
9337*44704f69SBart Van Assche	removelist=
9338*44704f69SBart Van Assche	tempremovelist=`$ECHO "$output_objdir/*"`
9339*44704f69SBart Van Assche	for p in $tempremovelist; do
9340*44704f69SBart Van Assche	  case $p in
9341*44704f69SBart Van Assche	    *.$objext | *.gcno)
9342*44704f69SBart Van Assche	       ;;
9343*44704f69SBart Van Assche	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9344*44704f69SBart Van Assche	       if test -n "$precious_files_regex"; then
9345*44704f69SBart Van Assche		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9346*44704f69SBart Van Assche		 then
9347*44704f69SBart Van Assche		   continue
9348*44704f69SBart Van Assche		 fi
9349*44704f69SBart Van Assche	       fi
9350*44704f69SBart Van Assche	       func_append removelist " $p"
9351*44704f69SBart Van Assche	       ;;
9352*44704f69SBart Van Assche	    *) ;;
9353*44704f69SBart Van Assche	  esac
9354*44704f69SBart Van Assche	done
9355*44704f69SBart Van Assche	test -n "$removelist" && \
9356*44704f69SBart Van Assche	  func_show_eval "${RM}r \$removelist"
9357*44704f69SBart Van Assche      fi
9358*44704f69SBart Van Assche
9359*44704f69SBart Van Assche      # Now set the variables for building old libraries.
9360*44704f69SBart Van Assche      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9361*44704f69SBart Van Assche	func_append oldlibs " $output_objdir/$libname.$libext"
9362*44704f69SBart Van Assche
9363*44704f69SBart Van Assche	# Transform .lo files to .o files.
9364*44704f69SBart Van Assche	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9365*44704f69SBart Van Assche      fi
9366*44704f69SBart Van Assche
9367*44704f69SBart Van Assche      # Eliminate all temporary directories.
9368*44704f69SBart Van Assche      #for path in $notinst_path; do
9369*44704f69SBart Van Assche      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9370*44704f69SBart Van Assche      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9371*44704f69SBart Van Assche      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9372*44704f69SBart Van Assche      #done
9373*44704f69SBart Van Assche
9374*44704f69SBart Van Assche      if test -n "$xrpath"; then
9375*44704f69SBart Van Assche	# If the user specified any rpath flags, then add them.
9376*44704f69SBart Van Assche	temp_xrpath=
9377*44704f69SBart Van Assche	for libdir in $xrpath; do
9378*44704f69SBart Van Assche	  func_replace_sysroot "$libdir"
9379*44704f69SBart Van Assche	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9380*44704f69SBart Van Assche	  case "$finalize_rpath " in
9381*44704f69SBart Van Assche	  *" $libdir "*) ;;
9382*44704f69SBart Van Assche	  *) func_append finalize_rpath " $libdir" ;;
9383*44704f69SBart Van Assche	  esac
9384*44704f69SBart Van Assche	done
9385*44704f69SBart Van Assche	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9386*44704f69SBart Van Assche	  dependency_libs="$temp_xrpath $dependency_libs"
9387*44704f69SBart Van Assche	fi
9388*44704f69SBart Van Assche      fi
9389*44704f69SBart Van Assche
9390*44704f69SBart Van Assche      # Make sure dlfiles contains only unique files that won't be dlpreopened
9391*44704f69SBart Van Assche      old_dlfiles=$dlfiles
9392*44704f69SBart Van Assche      dlfiles=
9393*44704f69SBart Van Assche      for lib in $old_dlfiles; do
9394*44704f69SBart Van Assche	case " $dlprefiles $dlfiles " in
9395*44704f69SBart Van Assche	*" $lib "*) ;;
9396*44704f69SBart Van Assche	*) func_append dlfiles " $lib" ;;
9397*44704f69SBart Van Assche	esac
9398*44704f69SBart Van Assche      done
9399*44704f69SBart Van Assche
9400*44704f69SBart Van Assche      # Make sure dlprefiles contains only unique files
9401*44704f69SBart Van Assche      old_dlprefiles=$dlprefiles
9402*44704f69SBart Van Assche      dlprefiles=
9403*44704f69SBart Van Assche      for lib in $old_dlprefiles; do
9404*44704f69SBart Van Assche	case "$dlprefiles " in
9405*44704f69SBart Van Assche	*" $lib "*) ;;
9406*44704f69SBart Van Assche	*) func_append dlprefiles " $lib" ;;
9407*44704f69SBart Van Assche	esac
9408*44704f69SBart Van Assche      done
9409*44704f69SBart Van Assche
9410*44704f69SBart Van Assche      if test yes = "$build_libtool_libs"; then
9411*44704f69SBart Van Assche	if test -n "$rpath"; then
9412*44704f69SBart Van Assche	  case $host in
9413*44704f69SBart Van Assche	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9414*44704f69SBart Van Assche	    # these systems don't actually have a c library (as such)!
9415*44704f69SBart Van Assche	    ;;
9416*44704f69SBart Van Assche	  *-*-rhapsody* | *-*-darwin1.[012])
9417*44704f69SBart Van Assche	    # Rhapsody C library is in the System framework
9418*44704f69SBart Van Assche	    func_append deplibs " System.ltframework"
9419*44704f69SBart Van Assche	    ;;
9420*44704f69SBart Van Assche	  *-*-netbsd*)
9421*44704f69SBart Van Assche	    # Don't link with libc until the a.out ld.so is fixed.
9422*44704f69SBart Van Assche	    ;;
9423*44704f69SBart Van Assche	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9424*44704f69SBart Van Assche	    # Do not include libc due to us having libc/libc_r.
9425*44704f69SBart Van Assche	    ;;
9426*44704f69SBart Van Assche	  *-*-sco3.2v5* | *-*-sco5v6*)
9427*44704f69SBart Van Assche	    # Causes problems with __ctype
9428*44704f69SBart Van Assche	    ;;
9429*44704f69SBart Van Assche	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9430*44704f69SBart Van Assche	    # Compiler inserts libc in the correct place for threads to work
9431*44704f69SBart Van Assche	    ;;
9432*44704f69SBart Van Assche	  *)
9433*44704f69SBart Van Assche	    # Add libc to deplibs on all other systems if necessary.
9434*44704f69SBart Van Assche	    if test yes = "$build_libtool_need_lc"; then
9435*44704f69SBart Van Assche	      func_append deplibs " -lc"
9436*44704f69SBart Van Assche	    fi
9437*44704f69SBart Van Assche	    ;;
9438*44704f69SBart Van Assche	  esac
9439*44704f69SBart Van Assche	fi
9440*44704f69SBart Van Assche
9441*44704f69SBart Van Assche	# Transform deplibs into only deplibs that can be linked in shared.
9442*44704f69SBart Van Assche	name_save=$name
9443*44704f69SBart Van Assche	libname_save=$libname
9444*44704f69SBart Van Assche	release_save=$release
9445*44704f69SBart Van Assche	versuffix_save=$versuffix
9446*44704f69SBart Van Assche	major_save=$major
9447*44704f69SBart Van Assche	# I'm not sure if I'm treating the release correctly.  I think
9448*44704f69SBart Van Assche	# release should show up in the -l (ie -lgmp5) so we don't want to
9449*44704f69SBart Van Assche	# add it in twice.  Is that correct?
9450*44704f69SBart Van Assche	release=
9451*44704f69SBart Van Assche	versuffix=
9452*44704f69SBart Van Assche	major=
9453*44704f69SBart Van Assche	newdeplibs=
9454*44704f69SBart Van Assche	droppeddeps=no
9455*44704f69SBart Van Assche	case $deplibs_check_method in
9456*44704f69SBart Van Assche	pass_all)
9457*44704f69SBart Van Assche	  # Don't check for shared/static.  Everything works.
9458*44704f69SBart Van Assche	  # This might be a little naive.  We might want to check
9459*44704f69SBart Van Assche	  # whether the library exists or not.  But this is on
9460*44704f69SBart Van Assche	  # osf3 & osf4 and I'm not really sure... Just
9461*44704f69SBart Van Assche	  # implementing what was already the behavior.
9462*44704f69SBart Van Assche	  newdeplibs=$deplibs
9463*44704f69SBart Van Assche	  ;;
9464*44704f69SBart Van Assche	test_compile)
9465*44704f69SBart Van Assche	  # This code stresses the "libraries are programs" paradigm to its
9466*44704f69SBart Van Assche	  # limits. Maybe even breaks it.  We compile a program, linking it
9467*44704f69SBart Van Assche	  # against the deplibs as a proxy for the library.  Then we can check
9468*44704f69SBart Van Assche	  # whether they linked in statically or dynamically with ldd.
9469*44704f69SBart Van Assche	  $opt_dry_run || $RM conftest.c
9470*44704f69SBart Van Assche	  cat > conftest.c <<EOF
9471*44704f69SBart Van Assche	  int main() { return 0; }
9472*44704f69SBart Van AsscheEOF
9473*44704f69SBart Van Assche	  $opt_dry_run || $RM conftest
9474*44704f69SBart Van Assche	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9475*44704f69SBart Van Assche	    ldd_output=`ldd conftest`
9476*44704f69SBart Van Assche	    for i in $deplibs; do
9477*44704f69SBart Van Assche	      case $i in
9478*44704f69SBart Van Assche	      -l*)
9479*44704f69SBart Van Assche		func_stripname -l '' "$i"
9480*44704f69SBart Van Assche		name=$func_stripname_result
9481*44704f69SBart Van Assche		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9482*44704f69SBart Van Assche		  case " $predeps $postdeps " in
9483*44704f69SBart Van Assche		  *" $i "*)
9484*44704f69SBart Van Assche		    func_append newdeplibs " $i"
9485*44704f69SBart Van Assche		    i=
9486*44704f69SBart Van Assche		    ;;
9487*44704f69SBart Van Assche		  esac
9488*44704f69SBart Van Assche		fi
9489*44704f69SBart Van Assche		if test -n "$i"; then
9490*44704f69SBart Van Assche		  libname=`eval "\\$ECHO \"$libname_spec\""`
9491*44704f69SBart Van Assche		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9492*44704f69SBart Van Assche		  set dummy $deplib_matches; shift
9493*44704f69SBart Van Assche		  deplib_match=$1
9494*44704f69SBart Van Assche		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9495*44704f69SBart Van Assche		    func_append newdeplibs " $i"
9496*44704f69SBart Van Assche		  else
9497*44704f69SBart Van Assche		    droppeddeps=yes
9498*44704f69SBart Van Assche		    echo
9499*44704f69SBart Van Assche		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9500*44704f69SBart Van Assche		    echo "*** I have the capability to make that library automatically link in when"
9501*44704f69SBart Van Assche		    echo "*** you link to this library.  But I can only do this if you have a"
9502*44704f69SBart Van Assche		    echo "*** shared version of the library, which I believe you do not have"
9503*44704f69SBart Van Assche		    echo "*** because a test_compile did reveal that the linker did not use it for"
9504*44704f69SBart Van Assche		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9505*44704f69SBart Van Assche		  fi
9506*44704f69SBart Van Assche		fi
9507*44704f69SBart Van Assche		;;
9508*44704f69SBart Van Assche	      *)
9509*44704f69SBart Van Assche		func_append newdeplibs " $i"
9510*44704f69SBart Van Assche		;;
9511*44704f69SBart Van Assche	      esac
9512*44704f69SBart Van Assche	    done
9513*44704f69SBart Van Assche	  else
9514*44704f69SBart Van Assche	    # Error occurred in the first compile.  Let's try to salvage
9515*44704f69SBart Van Assche	    # the situation: Compile a separate program for each library.
9516*44704f69SBart Van Assche	    for i in $deplibs; do
9517*44704f69SBart Van Assche	      case $i in
9518*44704f69SBart Van Assche	      -l*)
9519*44704f69SBart Van Assche		func_stripname -l '' "$i"
9520*44704f69SBart Van Assche		name=$func_stripname_result
9521*44704f69SBart Van Assche		$opt_dry_run || $RM conftest
9522*44704f69SBart Van Assche		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9523*44704f69SBart Van Assche		  ldd_output=`ldd conftest`
9524*44704f69SBart Van Assche		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9525*44704f69SBart Van Assche		    case " $predeps $postdeps " in
9526*44704f69SBart Van Assche		    *" $i "*)
9527*44704f69SBart Van Assche		      func_append newdeplibs " $i"
9528*44704f69SBart Van Assche		      i=
9529*44704f69SBart Van Assche		      ;;
9530*44704f69SBart Van Assche		    esac
9531*44704f69SBart Van Assche		  fi
9532*44704f69SBart Van Assche		  if test -n "$i"; then
9533*44704f69SBart Van Assche		    libname=`eval "\\$ECHO \"$libname_spec\""`
9534*44704f69SBart Van Assche		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9535*44704f69SBart Van Assche		    set dummy $deplib_matches; shift
9536*44704f69SBart Van Assche		    deplib_match=$1
9537*44704f69SBart Van Assche		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9538*44704f69SBart Van Assche		      func_append newdeplibs " $i"
9539*44704f69SBart Van Assche		    else
9540*44704f69SBart Van Assche		      droppeddeps=yes
9541*44704f69SBart Van Assche		      echo
9542*44704f69SBart Van Assche		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9543*44704f69SBart Van Assche		      echo "*** I have the capability to make that library automatically link in when"
9544*44704f69SBart Van Assche		      echo "*** you link to this library.  But I can only do this if you have a"
9545*44704f69SBart Van Assche		      echo "*** shared version of the library, which you do not appear to have"
9546*44704f69SBart Van Assche		      echo "*** because a test_compile did reveal that the linker did not use this one"
9547*44704f69SBart Van Assche		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9548*44704f69SBart Van Assche		    fi
9549*44704f69SBart Van Assche		  fi
9550*44704f69SBart Van Assche		else
9551*44704f69SBart Van Assche		  droppeddeps=yes
9552*44704f69SBart Van Assche		  echo
9553*44704f69SBart Van Assche		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9554*44704f69SBart Van Assche		  echo "*** make it link in!  You will probably need to install it or some"
9555*44704f69SBart Van Assche		  echo "*** library that it depends on before this library will be fully"
9556*44704f69SBart Van Assche		  echo "*** functional.  Installing it before continuing would be even better."
9557*44704f69SBart Van Assche		fi
9558*44704f69SBart Van Assche		;;
9559*44704f69SBart Van Assche	      *)
9560*44704f69SBart Van Assche		func_append newdeplibs " $i"
9561*44704f69SBart Van Assche		;;
9562*44704f69SBart Van Assche	      esac
9563*44704f69SBart Van Assche	    done
9564*44704f69SBart Van Assche	  fi
9565*44704f69SBart Van Assche	  ;;
9566*44704f69SBart Van Assche	file_magic*)
9567*44704f69SBart Van Assche	  set dummy $deplibs_check_method; shift
9568*44704f69SBart Van Assche	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9569*44704f69SBart Van Assche	  for a_deplib in $deplibs; do
9570*44704f69SBart Van Assche	    case $a_deplib in
9571*44704f69SBart Van Assche	    -l*)
9572*44704f69SBart Van Assche	      func_stripname -l '' "$a_deplib"
9573*44704f69SBart Van Assche	      name=$func_stripname_result
9574*44704f69SBart Van Assche	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9575*44704f69SBart Van Assche		case " $predeps $postdeps " in
9576*44704f69SBart Van Assche		*" $a_deplib "*)
9577*44704f69SBart Van Assche		  func_append newdeplibs " $a_deplib"
9578*44704f69SBart Van Assche		  a_deplib=
9579*44704f69SBart Van Assche		  ;;
9580*44704f69SBart Van Assche		esac
9581*44704f69SBart Van Assche	      fi
9582*44704f69SBart Van Assche	      if test -n "$a_deplib"; then
9583*44704f69SBart Van Assche		libname=`eval "\\$ECHO \"$libname_spec\""`
9584*44704f69SBart Van Assche		if test -n "$file_magic_glob"; then
9585*44704f69SBart Van Assche		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9586*44704f69SBart Van Assche		else
9587*44704f69SBart Van Assche		  libnameglob=$libname
9588*44704f69SBart Van Assche		fi
9589*44704f69SBart Van Assche		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9590*44704f69SBart Van Assche		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9591*44704f69SBart Van Assche		  if test yes = "$want_nocaseglob"; then
9592*44704f69SBart Van Assche		    shopt -s nocaseglob
9593*44704f69SBart Van Assche		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9594*44704f69SBart Van Assche		    $nocaseglob
9595*44704f69SBart Van Assche		  else
9596*44704f69SBart Van Assche		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9597*44704f69SBart Van Assche		  fi
9598*44704f69SBart Van Assche		  for potent_lib in $potential_libs; do
9599*44704f69SBart Van Assche		      # Follow soft links.
9600*44704f69SBart Van Assche		      if ls -lLd "$potent_lib" 2>/dev/null |
9601*44704f69SBart Van Assche			 $GREP " -> " >/dev/null; then
9602*44704f69SBart Van Assche			continue
9603*44704f69SBart Van Assche		      fi
9604*44704f69SBart Van Assche		      # The statement above tries to avoid entering an
9605*44704f69SBart Van Assche		      # endless loop below, in case of cyclic links.
9606*44704f69SBart Van Assche		      # We might still enter an endless loop, since a link
9607*44704f69SBart Van Assche		      # loop can be closed while we follow links,
9608*44704f69SBart Van Assche		      # but so what?
9609*44704f69SBart Van Assche		      potlib=$potent_lib
9610*44704f69SBart Van Assche		      while test -h "$potlib" 2>/dev/null; do
9611*44704f69SBart Van Assche			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9612*44704f69SBart Van Assche			case $potliblink in
9613*44704f69SBart Van Assche			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9614*44704f69SBart Van Assche			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9615*44704f69SBart Van Assche			esac
9616*44704f69SBart Van Assche		      done
9617*44704f69SBart Van Assche		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9618*44704f69SBart Van Assche			 $SED -e 10q |
9619*44704f69SBart Van Assche			 $EGREP "$file_magic_regex" > /dev/null; then
9620*44704f69SBart Van Assche			func_append newdeplibs " $a_deplib"
9621*44704f69SBart Van Assche			a_deplib=
9622*44704f69SBart Van Assche			break 2
9623*44704f69SBart Van Assche		      fi
9624*44704f69SBart Van Assche		  done
9625*44704f69SBart Van Assche		done
9626*44704f69SBart Van Assche	      fi
9627*44704f69SBart Van Assche	      if test -n "$a_deplib"; then
9628*44704f69SBart Van Assche		droppeddeps=yes
9629*44704f69SBart Van Assche		echo
9630*44704f69SBart Van Assche		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9631*44704f69SBart Van Assche		echo "*** I have the capability to make that library automatically link in when"
9632*44704f69SBart Van Assche		echo "*** you link to this library.  But I can only do this if you have a"
9633*44704f69SBart Van Assche		echo "*** shared version of the library, which you do not appear to have"
9634*44704f69SBart Van Assche		echo "*** because I did check the linker path looking for a file starting"
9635*44704f69SBart Van Assche		if test -z "$potlib"; then
9636*44704f69SBart Van Assche		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9637*44704f69SBart Van Assche		else
9638*44704f69SBart Van Assche		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9639*44704f69SBart Van Assche		  $ECHO "*** using a file magic. Last file checked: $potlib"
9640*44704f69SBart Van Assche		fi
9641*44704f69SBart Van Assche	      fi
9642*44704f69SBart Van Assche	      ;;
9643*44704f69SBart Van Assche	    *)
9644*44704f69SBart Van Assche	      # Add a -L argument.
9645*44704f69SBart Van Assche	      func_append newdeplibs " $a_deplib"
9646*44704f69SBart Van Assche	      ;;
9647*44704f69SBart Van Assche	    esac
9648*44704f69SBart Van Assche	  done # Gone through all deplibs.
9649*44704f69SBart Van Assche	  ;;
9650*44704f69SBart Van Assche	match_pattern*)
9651*44704f69SBart Van Assche	  set dummy $deplibs_check_method; shift
9652*44704f69SBart Van Assche	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9653*44704f69SBart Van Assche	  for a_deplib in $deplibs; do
9654*44704f69SBart Van Assche	    case $a_deplib in
9655*44704f69SBart Van Assche	    -l*)
9656*44704f69SBart Van Assche	      func_stripname -l '' "$a_deplib"
9657*44704f69SBart Van Assche	      name=$func_stripname_result
9658*44704f69SBart Van Assche	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9659*44704f69SBart Van Assche		case " $predeps $postdeps " in
9660*44704f69SBart Van Assche		*" $a_deplib "*)
9661*44704f69SBart Van Assche		  func_append newdeplibs " $a_deplib"
9662*44704f69SBart Van Assche		  a_deplib=
9663*44704f69SBart Van Assche		  ;;
9664*44704f69SBart Van Assche		esac
9665*44704f69SBart Van Assche	      fi
9666*44704f69SBart Van Assche	      if test -n "$a_deplib"; then
9667*44704f69SBart Van Assche		libname=`eval "\\$ECHO \"$libname_spec\""`
9668*44704f69SBart Van Assche		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9669*44704f69SBart Van Assche		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9670*44704f69SBart Van Assche		  for potent_lib in $potential_libs; do
9671*44704f69SBart Van Assche		    potlib=$potent_lib # see symlink-check above in file_magic test
9672*44704f69SBart Van Assche		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9673*44704f69SBart Van Assche		       $EGREP "$match_pattern_regex" > /dev/null; then
9674*44704f69SBart Van Assche		      func_append newdeplibs " $a_deplib"
9675*44704f69SBart Van Assche		      a_deplib=
9676*44704f69SBart Van Assche		      break 2
9677*44704f69SBart Van Assche		    fi
9678*44704f69SBart Van Assche		  done
9679*44704f69SBart Van Assche		done
9680*44704f69SBart Van Assche	      fi
9681*44704f69SBart Van Assche	      if test -n "$a_deplib"; then
9682*44704f69SBart Van Assche		droppeddeps=yes
9683*44704f69SBart Van Assche		echo
9684*44704f69SBart Van Assche		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9685*44704f69SBart Van Assche		echo "*** I have the capability to make that library automatically link in when"
9686*44704f69SBart Van Assche		echo "*** you link to this library.  But I can only do this if you have a"
9687*44704f69SBart Van Assche		echo "*** shared version of the library, which you do not appear to have"
9688*44704f69SBart Van Assche		echo "*** because I did check the linker path looking for a file starting"
9689*44704f69SBart Van Assche		if test -z "$potlib"; then
9690*44704f69SBart Van Assche		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9691*44704f69SBart Van Assche		else
9692*44704f69SBart Van Assche		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9693*44704f69SBart Van Assche		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9694*44704f69SBart Van Assche		fi
9695*44704f69SBart Van Assche	      fi
9696*44704f69SBart Van Assche	      ;;
9697*44704f69SBart Van Assche	    *)
9698*44704f69SBart Van Assche	      # Add a -L argument.
9699*44704f69SBart Van Assche	      func_append newdeplibs " $a_deplib"
9700*44704f69SBart Van Assche	      ;;
9701*44704f69SBart Van Assche	    esac
9702*44704f69SBart Van Assche	  done # Gone through all deplibs.
9703*44704f69SBart Van Assche	  ;;
9704*44704f69SBart Van Assche	none | unknown | *)
9705*44704f69SBart Van Assche	  newdeplibs=
9706*44704f69SBart Van Assche	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9707*44704f69SBart Van Assche	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9708*44704f69SBart Van Assche	    for i in $predeps $postdeps; do
9709*44704f69SBart Van Assche	      # can't use Xsed below, because $i might contain '/'
9710*44704f69SBart Van Assche	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9711*44704f69SBart Van Assche	    done
9712*44704f69SBart Van Assche	  fi
9713*44704f69SBart Van Assche	  case $tmp_deplibs in
9714*44704f69SBart Van Assche	  *[!\	\ ]*)
9715*44704f69SBart Van Assche	    echo
9716*44704f69SBart Van Assche	    if test none = "$deplibs_check_method"; then
9717*44704f69SBart Van Assche	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9718*44704f69SBart Van Assche	    else
9719*44704f69SBart Van Assche	      echo "*** Warning: inter-library dependencies are not known to be supported."
9720*44704f69SBart Van Assche	    fi
9721*44704f69SBart Van Assche	    echo "*** All declared inter-library dependencies are being dropped."
9722*44704f69SBart Van Assche	    droppeddeps=yes
9723*44704f69SBart Van Assche	    ;;
9724*44704f69SBart Van Assche	  esac
9725*44704f69SBart Van Assche	  ;;
9726*44704f69SBart Van Assche	esac
9727*44704f69SBart Van Assche	versuffix=$versuffix_save
9728*44704f69SBart Van Assche	major=$major_save
9729*44704f69SBart Van Assche	release=$release_save
9730*44704f69SBart Van Assche	libname=$libname_save
9731*44704f69SBart Van Assche	name=$name_save
9732*44704f69SBart Van Assche
9733*44704f69SBart Van Assche	case $host in
9734*44704f69SBart Van Assche	*-*-rhapsody* | *-*-darwin1.[012])
9735*44704f69SBart Van Assche	  # On Rhapsody replace the C library with the System framework
9736*44704f69SBart Van Assche	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9737*44704f69SBart Van Assche	  ;;
9738*44704f69SBart Van Assche	esac
9739*44704f69SBart Van Assche
9740*44704f69SBart Van Assche	if test yes = "$droppeddeps"; then
9741*44704f69SBart Van Assche	  if test yes = "$module"; then
9742*44704f69SBart Van Assche	    echo
9743*44704f69SBart Van Assche	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9744*44704f69SBart Van Assche	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9745*44704f69SBart Van Assche	    echo "*** a static module, that should work as long as the dlopening"
9746*44704f69SBart Van Assche	    echo "*** application is linked with the -dlopen flag."
9747*44704f69SBart Van Assche	    if test -z "$global_symbol_pipe"; then
9748*44704f69SBart Van Assche	      echo
9749*44704f69SBart Van Assche	      echo "*** However, this would only work if libtool was able to extract symbol"
9750*44704f69SBart Van Assche	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9751*44704f69SBart Van Assche	      echo "*** not find such a program.  So, this module is probably useless."
9752*44704f69SBart Van Assche	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9753*44704f69SBart Van Assche	    fi
9754*44704f69SBart Van Assche	    if test no = "$build_old_libs"; then
9755*44704f69SBart Van Assche	      oldlibs=$output_objdir/$libname.$libext
9756*44704f69SBart Van Assche	      build_libtool_libs=module
9757*44704f69SBart Van Assche	      build_old_libs=yes
9758*44704f69SBart Van Assche	    else
9759*44704f69SBart Van Assche	      build_libtool_libs=no
9760*44704f69SBart Van Assche	    fi
9761*44704f69SBart Van Assche	  else
9762*44704f69SBart Van Assche	    echo "*** The inter-library dependencies that have been dropped here will be"
9763*44704f69SBart Van Assche	    echo "*** automatically added whenever a program is linked with this library"
9764*44704f69SBart Van Assche	    echo "*** or is declared to -dlopen it."
9765*44704f69SBart Van Assche
9766*44704f69SBart Van Assche	    if test no = "$allow_undefined"; then
9767*44704f69SBart Van Assche	      echo
9768*44704f69SBart Van Assche	      echo "*** Since this library must not contain undefined symbols,"
9769*44704f69SBart Van Assche	      echo "*** because either the platform does not support them or"
9770*44704f69SBart Van Assche	      echo "*** it was explicitly requested with -no-undefined,"
9771*44704f69SBart Van Assche	      echo "*** libtool will only create a static version of it."
9772*44704f69SBart Van Assche	      if test no = "$build_old_libs"; then
9773*44704f69SBart Van Assche		oldlibs=$output_objdir/$libname.$libext
9774*44704f69SBart Van Assche		build_libtool_libs=module
9775*44704f69SBart Van Assche		build_old_libs=yes
9776*44704f69SBart Van Assche	      else
9777*44704f69SBart Van Assche		build_libtool_libs=no
9778*44704f69SBart Van Assche	      fi
9779*44704f69SBart Van Assche	    fi
9780*44704f69SBart Van Assche	  fi
9781*44704f69SBart Van Assche	fi
9782*44704f69SBart Van Assche	# Done checking deplibs!
9783*44704f69SBart Van Assche	deplibs=$newdeplibs
9784*44704f69SBart Van Assche      fi
9785*44704f69SBart Van Assche      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9786*44704f69SBart Van Assche      case $host in
9787*44704f69SBart Van Assche	*-*-darwin*)
9788*44704f69SBart Van Assche	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9789*44704f69SBart Van Assche	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9790*44704f69SBart Van Assche	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9791*44704f69SBart Van Assche	  ;;
9792*44704f69SBart Van Assche      esac
9793*44704f69SBart Van Assche
9794*44704f69SBart Van Assche      # move library search paths that coincide with paths to not yet
9795*44704f69SBart Van Assche      # installed libraries to the beginning of the library search list
9796*44704f69SBart Van Assche      new_libs=
9797*44704f69SBart Van Assche      for path in $notinst_path; do
9798*44704f69SBart Van Assche	case " $new_libs " in
9799*44704f69SBart Van Assche	*" -L$path/$objdir "*) ;;
9800*44704f69SBart Van Assche	*)
9801*44704f69SBart Van Assche	  case " $deplibs " in
9802*44704f69SBart Van Assche	  *" -L$path/$objdir "*)
9803*44704f69SBart Van Assche	    func_append new_libs " -L$path/$objdir" ;;
9804*44704f69SBart Van Assche	  esac
9805*44704f69SBart Van Assche	  ;;
9806*44704f69SBart Van Assche	esac
9807*44704f69SBart Van Assche      done
9808*44704f69SBart Van Assche      for deplib in $deplibs; do
9809*44704f69SBart Van Assche	case $deplib in
9810*44704f69SBart Van Assche	-L*)
9811*44704f69SBart Van Assche	  case " $new_libs " in
9812*44704f69SBart Van Assche	  *" $deplib "*) ;;
9813*44704f69SBart Van Assche	  *) func_append new_libs " $deplib" ;;
9814*44704f69SBart Van Assche	  esac
9815*44704f69SBart Van Assche	  ;;
9816*44704f69SBart Van Assche	*) func_append new_libs " $deplib" ;;
9817*44704f69SBart Van Assche	esac
9818*44704f69SBart Van Assche      done
9819*44704f69SBart Van Assche      deplibs=$new_libs
9820*44704f69SBart Van Assche
9821*44704f69SBart Van Assche      # All the library-specific variables (install_libdir is set above).
9822*44704f69SBart Van Assche      library_names=
9823*44704f69SBart Van Assche      old_library=
9824*44704f69SBart Van Assche      dlname=
9825*44704f69SBart Van Assche
9826*44704f69SBart Van Assche      # Test again, we may have decided not to build it any more
9827*44704f69SBart Van Assche      if test yes = "$build_libtool_libs"; then
9828*44704f69SBart Van Assche	# Remove $wl instances when linking with ld.
9829*44704f69SBart Van Assche	# FIXME: should test the right _cmds variable.
9830*44704f69SBart Van Assche	case $archive_cmds in
9831*44704f69SBart Van Assche	  *\$LD\ *) wl= ;;
9832*44704f69SBart Van Assche        esac
9833*44704f69SBart Van Assche	if test yes = "$hardcode_into_libs"; then
9834*44704f69SBart Van Assche	  # Hardcode the library paths
9835*44704f69SBart Van Assche	  hardcode_libdirs=
9836*44704f69SBart Van Assche	  dep_rpath=
9837*44704f69SBart Van Assche	  rpath=$finalize_rpath
9838*44704f69SBart Van Assche	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9839*44704f69SBart Van Assche	  for libdir in $rpath; do
9840*44704f69SBart Van Assche	    if test -n "$hardcode_libdir_flag_spec"; then
9841*44704f69SBart Van Assche	      if test -n "$hardcode_libdir_separator"; then
9842*44704f69SBart Van Assche		func_replace_sysroot "$libdir"
9843*44704f69SBart Van Assche		libdir=$func_replace_sysroot_result
9844*44704f69SBart Van Assche		if test -z "$hardcode_libdirs"; then
9845*44704f69SBart Van Assche		  hardcode_libdirs=$libdir
9846*44704f69SBart Van Assche		else
9847*44704f69SBart Van Assche		  # Just accumulate the unique libdirs.
9848*44704f69SBart Van Assche		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9849*44704f69SBart Van Assche		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9850*44704f69SBart Van Assche		    ;;
9851*44704f69SBart Van Assche		  *)
9852*44704f69SBart Van Assche		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9853*44704f69SBart Van Assche		    ;;
9854*44704f69SBart Van Assche		  esac
9855*44704f69SBart Van Assche		fi
9856*44704f69SBart Van Assche	      else
9857*44704f69SBart Van Assche		eval flag=\"$hardcode_libdir_flag_spec\"
9858*44704f69SBart Van Assche		func_append dep_rpath " $flag"
9859*44704f69SBart Van Assche	      fi
9860*44704f69SBart Van Assche	    elif test -n "$runpath_var"; then
9861*44704f69SBart Van Assche	      case "$perm_rpath " in
9862*44704f69SBart Van Assche	      *" $libdir "*) ;;
9863*44704f69SBart Van Assche	      *) func_append perm_rpath " $libdir" ;;
9864*44704f69SBart Van Assche	      esac
9865*44704f69SBart Van Assche	    fi
9866*44704f69SBart Van Assche	  done
9867*44704f69SBart Van Assche	  # Substitute the hardcoded libdirs into the rpath.
9868*44704f69SBart Van Assche	  if test -n "$hardcode_libdir_separator" &&
9869*44704f69SBart Van Assche	     test -n "$hardcode_libdirs"; then
9870*44704f69SBart Van Assche	    libdir=$hardcode_libdirs
9871*44704f69SBart Van Assche	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9872*44704f69SBart Van Assche	  fi
9873*44704f69SBart Van Assche	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9874*44704f69SBart Van Assche	    # We should set the runpath_var.
9875*44704f69SBart Van Assche	    rpath=
9876*44704f69SBart Van Assche	    for dir in $perm_rpath; do
9877*44704f69SBart Van Assche	      func_append rpath "$dir:"
9878*44704f69SBart Van Assche	    done
9879*44704f69SBart Van Assche	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9880*44704f69SBart Van Assche	  fi
9881*44704f69SBart Van Assche	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9882*44704f69SBart Van Assche	fi
9883*44704f69SBart Van Assche
9884*44704f69SBart Van Assche	shlibpath=$finalize_shlibpath
9885*44704f69SBart Van Assche	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9886*44704f69SBart Van Assche	if test -n "$shlibpath"; then
9887*44704f69SBart Van Assche	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9888*44704f69SBart Van Assche	fi
9889*44704f69SBart Van Assche
9890*44704f69SBart Van Assche	# Get the real and link names of the library.
9891*44704f69SBart Van Assche	eval shared_ext=\"$shrext_cmds\"
9892*44704f69SBart Van Assche	eval library_names=\"$library_names_spec\"
9893*44704f69SBart Van Assche	set dummy $library_names
9894*44704f69SBart Van Assche	shift
9895*44704f69SBart Van Assche	realname=$1
9896*44704f69SBart Van Assche	shift
9897*44704f69SBart Van Assche
9898*44704f69SBart Van Assche	if test -n "$soname_spec"; then
9899*44704f69SBart Van Assche	  eval soname=\"$soname_spec\"
9900*44704f69SBart Van Assche	else
9901*44704f69SBart Van Assche	  soname=$realname
9902*44704f69SBart Van Assche	fi
9903*44704f69SBart Van Assche	if test -z "$dlname"; then
9904*44704f69SBart Van Assche	  dlname=$soname
9905*44704f69SBart Van Assche	fi
9906*44704f69SBart Van Assche
9907*44704f69SBart Van Assche	lib=$output_objdir/$realname
9908*44704f69SBart Van Assche	linknames=
9909*44704f69SBart Van Assche	for link
9910*44704f69SBart Van Assche	do
9911*44704f69SBart Van Assche	  func_append linknames " $link"
9912*44704f69SBart Van Assche	done
9913*44704f69SBart Van Assche
9914*44704f69SBart Van Assche	# Use standard objects if they are pic
9915*44704f69SBart Van Assche	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9916*44704f69SBart Van Assche	test "X$libobjs" = "X " && libobjs=
9917*44704f69SBart Van Assche
9918*44704f69SBart Van Assche	delfiles=
9919*44704f69SBart Van Assche	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9920*44704f69SBart Van Assche	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9921*44704f69SBart Van Assche	  export_symbols=$output_objdir/$libname.uexp
9922*44704f69SBart Van Assche	  func_append delfiles " $export_symbols"
9923*44704f69SBart Van Assche	fi
9924*44704f69SBart Van Assche
9925*44704f69SBart Van Assche	orig_export_symbols=
9926*44704f69SBart Van Assche	case $host_os in
9927*44704f69SBart Van Assche	cygwin* | mingw* | cegcc*)
9928*44704f69SBart Van Assche	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9929*44704f69SBart Van Assche	    # exporting using user supplied symfile
9930*44704f69SBart Van Assche	    func_dll_def_p "$export_symbols" || {
9931*44704f69SBart Van Assche	      # and it's NOT already a .def file. Must figure out
9932*44704f69SBart Van Assche	      # which of the given symbols are data symbols and tag
9933*44704f69SBart Van Assche	      # them as such. So, trigger use of export_symbols_cmds.
9934*44704f69SBart Van Assche	      # export_symbols gets reassigned inside the "prepare
9935*44704f69SBart Van Assche	      # the list of exported symbols" if statement, so the
9936*44704f69SBart Van Assche	      # include_expsyms logic still works.
9937*44704f69SBart Van Assche	      orig_export_symbols=$export_symbols
9938*44704f69SBart Van Assche	      export_symbols=
9939*44704f69SBart Van Assche	      always_export_symbols=yes
9940*44704f69SBart Van Assche	    }
9941*44704f69SBart Van Assche	  fi
9942*44704f69SBart Van Assche	  ;;
9943*44704f69SBart Van Assche	esac
9944*44704f69SBart Van Assche
9945*44704f69SBart Van Assche	# Prepare the list of exported symbols
9946*44704f69SBart Van Assche	if test -z "$export_symbols"; then
9947*44704f69SBart Van Assche	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9948*44704f69SBart Van Assche	    func_verbose "generating symbol list for '$libname.la'"
9949*44704f69SBart Van Assche	    export_symbols=$output_objdir/$libname.exp
9950*44704f69SBart Van Assche	    $opt_dry_run || $RM $export_symbols
9951*44704f69SBart Van Assche	    cmds=$export_symbols_cmds
9952*44704f69SBart Van Assche	    save_ifs=$IFS; IFS='~'
9953*44704f69SBart Van Assche	    for cmd1 in $cmds; do
9954*44704f69SBart Van Assche	      IFS=$save_ifs
9955*44704f69SBart Van Assche	      # Take the normal branch if the nm_file_list_spec branch
9956*44704f69SBart Van Assche	      # doesn't work or if tool conversion is not needed.
9957*44704f69SBart Van Assche	      case $nm_file_list_spec~$to_tool_file_cmd in
9958*44704f69SBart Van Assche		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9959*44704f69SBart Van Assche		  try_normal_branch=yes
9960*44704f69SBart Van Assche		  eval cmd=\"$cmd1\"
9961*44704f69SBart Van Assche		  func_len " $cmd"
9962*44704f69SBart Van Assche		  len=$func_len_result
9963*44704f69SBart Van Assche		  ;;
9964*44704f69SBart Van Assche		*)
9965*44704f69SBart Van Assche		  try_normal_branch=no
9966*44704f69SBart Van Assche		  ;;
9967*44704f69SBart Van Assche	      esac
9968*44704f69SBart Van Assche	      if test yes = "$try_normal_branch" \
9969*44704f69SBart Van Assche		 && { test "$len" -lt "$max_cmd_len" \
9970*44704f69SBart Van Assche		      || test "$max_cmd_len" -le -1; }
9971*44704f69SBart Van Assche	      then
9972*44704f69SBart Van Assche		func_show_eval "$cmd" 'exit $?'
9973*44704f69SBart Van Assche		skipped_export=false
9974*44704f69SBart Van Assche	      elif test -n "$nm_file_list_spec"; then
9975*44704f69SBart Van Assche		func_basename "$output"
9976*44704f69SBart Van Assche		output_la=$func_basename_result
9977*44704f69SBart Van Assche		save_libobjs=$libobjs
9978*44704f69SBart Van Assche		save_output=$output
9979*44704f69SBart Van Assche		output=$output_objdir/$output_la.nm
9980*44704f69SBart Van Assche		func_to_tool_file "$output"
9981*44704f69SBart Van Assche		libobjs=$nm_file_list_spec$func_to_tool_file_result
9982*44704f69SBart Van Assche		func_append delfiles " $output"
9983*44704f69SBart Van Assche		func_verbose "creating $NM input file list: $output"
9984*44704f69SBart Van Assche		for obj in $save_libobjs; do
9985*44704f69SBart Van Assche		  func_to_tool_file "$obj"
9986*44704f69SBart Van Assche		  $ECHO "$func_to_tool_file_result"
9987*44704f69SBart Van Assche		done > "$output"
9988*44704f69SBart Van Assche		eval cmd=\"$cmd1\"
9989*44704f69SBart Van Assche		func_show_eval "$cmd" 'exit $?'
9990*44704f69SBart Van Assche		output=$save_output
9991*44704f69SBart Van Assche		libobjs=$save_libobjs
9992*44704f69SBart Van Assche		skipped_export=false
9993*44704f69SBart Van Assche	      else
9994*44704f69SBart Van Assche		# The command line is too long to execute in one step.
9995*44704f69SBart Van Assche		func_verbose "using reloadable object file for export list..."
9996*44704f69SBart Van Assche		skipped_export=:
9997*44704f69SBart Van Assche		# Break out early, otherwise skipped_export may be
9998*44704f69SBart Van Assche		# set to false by a later but shorter cmd.
9999*44704f69SBart Van Assche		break
10000*44704f69SBart Van Assche	      fi
10001*44704f69SBart Van Assche	    done
10002*44704f69SBart Van Assche	    IFS=$save_ifs
10003*44704f69SBart Van Assche	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
10004*44704f69SBart Van Assche	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10005*44704f69SBart Van Assche	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10006*44704f69SBart Van Assche	    fi
10007*44704f69SBart Van Assche	  fi
10008*44704f69SBart Van Assche	fi
10009*44704f69SBart Van Assche
10010*44704f69SBart Van Assche	if test -n "$export_symbols" && test -n "$include_expsyms"; then
10011*44704f69SBart Van Assche	  tmp_export_symbols=$export_symbols
10012*44704f69SBart Van Assche	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10013*44704f69SBart Van Assche	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10014*44704f69SBart Van Assche	fi
10015*44704f69SBart Van Assche
10016*44704f69SBart Van Assche	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10017*44704f69SBart Van Assche	  # The given exports_symbols file has to be filtered, so filter it.
10018*44704f69SBart Van Assche	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10019*44704f69SBart Van Assche	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10020*44704f69SBart Van Assche	  # 's' commands, which not all seds can handle. GNU sed should be fine
10021*44704f69SBart Van Assche	  # though. Also, the filter scales superlinearly with the number of
10022*44704f69SBart Van Assche	  # global variables. join(1) would be nice here, but unfortunately
10023*44704f69SBart Van Assche	  # isn't a blessed tool.
10024*44704f69SBart Van Assche	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10025*44704f69SBart Van Assche	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10026*44704f69SBart Van Assche	  export_symbols=$output_objdir/$libname.def
10027*44704f69SBart Van Assche	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10028*44704f69SBart Van Assche	fi
10029*44704f69SBart Van Assche
10030*44704f69SBart Van Assche	tmp_deplibs=
10031*44704f69SBart Van Assche	for test_deplib in $deplibs; do
10032*44704f69SBart Van Assche	  case " $convenience " in
10033*44704f69SBart Van Assche	  *" $test_deplib "*) ;;
10034*44704f69SBart Van Assche	  *)
10035*44704f69SBart Van Assche	    func_append tmp_deplibs " $test_deplib"
10036*44704f69SBart Van Assche	    ;;
10037*44704f69SBart Van Assche	  esac
10038*44704f69SBart Van Assche	done
10039*44704f69SBart Van Assche	deplibs=$tmp_deplibs
10040*44704f69SBart Van Assche
10041*44704f69SBart Van Assche	if test -n "$convenience"; then
10042*44704f69SBart Van Assche	  if test -n "$whole_archive_flag_spec" &&
10043*44704f69SBart Van Assche	    test yes = "$compiler_needs_object" &&
10044*44704f69SBart Van Assche	    test -z "$libobjs"; then
10045*44704f69SBart Van Assche	    # extract the archives, so we have objects to list.
10046*44704f69SBart Van Assche	    # TODO: could optimize this to just extract one archive.
10047*44704f69SBart Van Assche	    whole_archive_flag_spec=
10048*44704f69SBart Van Assche	  fi
10049*44704f69SBart Van Assche	  if test -n "$whole_archive_flag_spec"; then
10050*44704f69SBart Van Assche	    save_libobjs=$libobjs
10051*44704f69SBart Van Assche	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10052*44704f69SBart Van Assche	    test "X$libobjs" = "X " && libobjs=
10053*44704f69SBart Van Assche	  else
10054*44704f69SBart Van Assche	    gentop=$output_objdir/${outputname}x
10055*44704f69SBart Van Assche	    func_append generated " $gentop"
10056*44704f69SBart Van Assche
10057*44704f69SBart Van Assche	    func_extract_archives $gentop $convenience
10058*44704f69SBart Van Assche	    func_append libobjs " $func_extract_archives_result"
10059*44704f69SBart Van Assche	    test "X$libobjs" = "X " && libobjs=
10060*44704f69SBart Van Assche	  fi
10061*44704f69SBart Van Assche	fi
10062*44704f69SBart Van Assche
10063*44704f69SBart Van Assche	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10064*44704f69SBart Van Assche	  eval flag=\"$thread_safe_flag_spec\"
10065*44704f69SBart Van Assche	  func_append linker_flags " $flag"
10066*44704f69SBart Van Assche	fi
10067*44704f69SBart Van Assche
10068*44704f69SBart Van Assche	# Make a backup of the uninstalled library when relinking
10069*44704f69SBart Van Assche	if test relink = "$opt_mode"; then
10070*44704f69SBart Van Assche	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10071*44704f69SBart Van Assche	fi
10072*44704f69SBart Van Assche
10073*44704f69SBart Van Assche	# Do each of the archive commands.
10074*44704f69SBart Van Assche	if test yes = "$module" && test -n "$module_cmds"; then
10075*44704f69SBart Van Assche	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10076*44704f69SBart Van Assche	    eval test_cmds=\"$module_expsym_cmds\"
10077*44704f69SBart Van Assche	    cmds=$module_expsym_cmds
10078*44704f69SBart Van Assche	  else
10079*44704f69SBart Van Assche	    eval test_cmds=\"$module_cmds\"
10080*44704f69SBart Van Assche	    cmds=$module_cmds
10081*44704f69SBart Van Assche	  fi
10082*44704f69SBart Van Assche	else
10083*44704f69SBart Van Assche	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10084*44704f69SBart Van Assche	    eval test_cmds=\"$archive_expsym_cmds\"
10085*44704f69SBart Van Assche	    cmds=$archive_expsym_cmds
10086*44704f69SBart Van Assche	  else
10087*44704f69SBart Van Assche	    eval test_cmds=\"$archive_cmds\"
10088*44704f69SBart Van Assche	    cmds=$archive_cmds
10089*44704f69SBart Van Assche	  fi
10090*44704f69SBart Van Assche	fi
10091*44704f69SBart Van Assche
10092*44704f69SBart Van Assche	if test : != "$skipped_export" &&
10093*44704f69SBart Van Assche	   func_len " $test_cmds" &&
10094*44704f69SBart Van Assche	   len=$func_len_result &&
10095*44704f69SBart Van Assche	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10096*44704f69SBart Van Assche	  :
10097*44704f69SBart Van Assche	else
10098*44704f69SBart Van Assche	  # The command line is too long to link in one step, link piecewise
10099*44704f69SBart Van Assche	  # or, if using GNU ld and skipped_export is not :, use a linker
10100*44704f69SBart Van Assche	  # script.
10101*44704f69SBart Van Assche
10102*44704f69SBart Van Assche	  # Save the value of $output and $libobjs because we want to
10103*44704f69SBart Van Assche	  # use them later.  If we have whole_archive_flag_spec, we
10104*44704f69SBart Van Assche	  # want to use save_libobjs as it was before
10105*44704f69SBart Van Assche	  # whole_archive_flag_spec was expanded, because we can't
10106*44704f69SBart Van Assche	  # assume the linker understands whole_archive_flag_spec.
10107*44704f69SBart Van Assche	  # This may have to be revisited, in case too many
10108*44704f69SBart Van Assche	  # convenience libraries get linked in and end up exceeding
10109*44704f69SBart Van Assche	  # the spec.
10110*44704f69SBart Van Assche	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10111*44704f69SBart Van Assche	    save_libobjs=$libobjs
10112*44704f69SBart Van Assche	  fi
10113*44704f69SBart Van Assche	  save_output=$output
10114*44704f69SBart Van Assche	  func_basename "$output"
10115*44704f69SBart Van Assche	  output_la=$func_basename_result
10116*44704f69SBart Van Assche
10117*44704f69SBart Van Assche	  # Clear the reloadable object creation command queue and
10118*44704f69SBart Van Assche	  # initialize k to one.
10119*44704f69SBart Van Assche	  test_cmds=
10120*44704f69SBart Van Assche	  concat_cmds=
10121*44704f69SBart Van Assche	  objlist=
10122*44704f69SBart Van Assche	  last_robj=
10123*44704f69SBart Van Assche	  k=1
10124*44704f69SBart Van Assche
10125*44704f69SBart Van Assche	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10126*44704f69SBart Van Assche	    output=$output_objdir/$output_la.lnkscript
10127*44704f69SBart Van Assche	    func_verbose "creating GNU ld script: $output"
10128*44704f69SBart Van Assche	    echo 'INPUT (' > $output
10129*44704f69SBart Van Assche	    for obj in $save_libobjs
10130*44704f69SBart Van Assche	    do
10131*44704f69SBart Van Assche	      func_to_tool_file "$obj"
10132*44704f69SBart Van Assche	      $ECHO "$func_to_tool_file_result" >> $output
10133*44704f69SBart Van Assche	    done
10134*44704f69SBart Van Assche	    echo ')' >> $output
10135*44704f69SBart Van Assche	    func_append delfiles " $output"
10136*44704f69SBart Van Assche	    func_to_tool_file "$output"
10137*44704f69SBart Van Assche	    output=$func_to_tool_file_result
10138*44704f69SBart Van Assche	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10139*44704f69SBart Van Assche	    output=$output_objdir/$output_la.lnk
10140*44704f69SBart Van Assche	    func_verbose "creating linker input file list: $output"
10141*44704f69SBart Van Assche	    : > $output
10142*44704f69SBart Van Assche	    set x $save_libobjs
10143*44704f69SBart Van Assche	    shift
10144*44704f69SBart Van Assche	    firstobj=
10145*44704f69SBart Van Assche	    if test yes = "$compiler_needs_object"; then
10146*44704f69SBart Van Assche	      firstobj="$1 "
10147*44704f69SBart Van Assche	      shift
10148*44704f69SBart Van Assche	    fi
10149*44704f69SBart Van Assche	    for obj
10150*44704f69SBart Van Assche	    do
10151*44704f69SBart Van Assche	      func_to_tool_file "$obj"
10152*44704f69SBart Van Assche	      $ECHO "$func_to_tool_file_result" >> $output
10153*44704f69SBart Van Assche	    done
10154*44704f69SBart Van Assche	    func_append delfiles " $output"
10155*44704f69SBart Van Assche	    func_to_tool_file "$output"
10156*44704f69SBart Van Assche	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10157*44704f69SBart Van Assche	  else
10158*44704f69SBart Van Assche	    if test -n "$save_libobjs"; then
10159*44704f69SBart Van Assche	      func_verbose "creating reloadable object files..."
10160*44704f69SBart Van Assche	      output=$output_objdir/$output_la-$k.$objext
10161*44704f69SBart Van Assche	      eval test_cmds=\"$reload_cmds\"
10162*44704f69SBart Van Assche	      func_len " $test_cmds"
10163*44704f69SBart Van Assche	      len0=$func_len_result
10164*44704f69SBart Van Assche	      len=$len0
10165*44704f69SBart Van Assche
10166*44704f69SBart Van Assche	      # Loop over the list of objects to be linked.
10167*44704f69SBart Van Assche	      for obj in $save_libobjs
10168*44704f69SBart Van Assche	      do
10169*44704f69SBart Van Assche		func_len " $obj"
10170*44704f69SBart Van Assche		func_arith $len + $func_len_result
10171*44704f69SBart Van Assche		len=$func_arith_result
10172*44704f69SBart Van Assche		if test -z "$objlist" ||
10173*44704f69SBart Van Assche		   test "$len" -lt "$max_cmd_len"; then
10174*44704f69SBart Van Assche		  func_append objlist " $obj"
10175*44704f69SBart Van Assche		else
10176*44704f69SBart Van Assche		  # The command $test_cmds is almost too long, add a
10177*44704f69SBart Van Assche		  # command to the queue.
10178*44704f69SBart Van Assche		  if test 1 -eq "$k"; then
10179*44704f69SBart Van Assche		    # The first file doesn't have a previous command to add.
10180*44704f69SBart Van Assche		    reload_objs=$objlist
10181*44704f69SBart Van Assche		    eval concat_cmds=\"$reload_cmds\"
10182*44704f69SBart Van Assche		  else
10183*44704f69SBart Van Assche		    # All subsequent reloadable object files will link in
10184*44704f69SBart Van Assche		    # the last one created.
10185*44704f69SBart Van Assche		    reload_objs="$objlist $last_robj"
10186*44704f69SBart Van Assche		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10187*44704f69SBart Van Assche		  fi
10188*44704f69SBart Van Assche		  last_robj=$output_objdir/$output_la-$k.$objext
10189*44704f69SBart Van Assche		  func_arith $k + 1
10190*44704f69SBart Van Assche		  k=$func_arith_result
10191*44704f69SBart Van Assche		  output=$output_objdir/$output_la-$k.$objext
10192*44704f69SBart Van Assche		  objlist=" $obj"
10193*44704f69SBart Van Assche		  func_len " $last_robj"
10194*44704f69SBart Van Assche		  func_arith $len0 + $func_len_result
10195*44704f69SBart Van Assche		  len=$func_arith_result
10196*44704f69SBart Van Assche		fi
10197*44704f69SBart Van Assche	      done
10198*44704f69SBart Van Assche	      # Handle the remaining objects by creating one last
10199*44704f69SBart Van Assche	      # reloadable object file.  All subsequent reloadable object
10200*44704f69SBart Van Assche	      # files will link in the last one created.
10201*44704f69SBart Van Assche	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10202*44704f69SBart Van Assche	      reload_objs="$objlist $last_robj"
10203*44704f69SBart Van Assche	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10204*44704f69SBart Van Assche	      if test -n "$last_robj"; then
10205*44704f69SBart Van Assche	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10206*44704f69SBart Van Assche	      fi
10207*44704f69SBart Van Assche	      func_append delfiles " $output"
10208*44704f69SBart Van Assche
10209*44704f69SBart Van Assche	    else
10210*44704f69SBart Van Assche	      output=
10211*44704f69SBart Van Assche	    fi
10212*44704f69SBart Van Assche
10213*44704f69SBart Van Assche	    ${skipped_export-false} && {
10214*44704f69SBart Van Assche	      func_verbose "generating symbol list for '$libname.la'"
10215*44704f69SBart Van Assche	      export_symbols=$output_objdir/$libname.exp
10216*44704f69SBart Van Assche	      $opt_dry_run || $RM $export_symbols
10217*44704f69SBart Van Assche	      libobjs=$output
10218*44704f69SBart Van Assche	      # Append the command to create the export file.
10219*44704f69SBart Van Assche	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10220*44704f69SBart Van Assche	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10221*44704f69SBart Van Assche	      if test -n "$last_robj"; then
10222*44704f69SBart Van Assche		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10223*44704f69SBart Van Assche	      fi
10224*44704f69SBart Van Assche	    }
10225*44704f69SBart Van Assche
10226*44704f69SBart Van Assche	    test -n "$save_libobjs" &&
10227*44704f69SBart Van Assche	      func_verbose "creating a temporary reloadable object file: $output"
10228*44704f69SBart Van Assche
10229*44704f69SBart Van Assche	    # Loop through the commands generated above and execute them.
10230*44704f69SBart Van Assche	    save_ifs=$IFS; IFS='~'
10231*44704f69SBart Van Assche	    for cmd in $concat_cmds; do
10232*44704f69SBart Van Assche	      IFS=$save_ifs
10233*44704f69SBart Van Assche	      $opt_quiet || {
10234*44704f69SBart Van Assche		  func_quote_arg expand,pretty "$cmd"
10235*44704f69SBart Van Assche		  eval "func_echo $func_quote_arg_result"
10236*44704f69SBart Van Assche	      }
10237*44704f69SBart Van Assche	      $opt_dry_run || eval "$cmd" || {
10238*44704f69SBart Van Assche		lt_exit=$?
10239*44704f69SBart Van Assche
10240*44704f69SBart Van Assche		# Restore the uninstalled library and exit
10241*44704f69SBart Van Assche		if test relink = "$opt_mode"; then
10242*44704f69SBart Van Assche		  ( cd "$output_objdir" && \
10243*44704f69SBart Van Assche		    $RM "${realname}T" && \
10244*44704f69SBart Van Assche		    $MV "${realname}U" "$realname" )
10245*44704f69SBart Van Assche		fi
10246*44704f69SBart Van Assche
10247*44704f69SBart Van Assche		exit $lt_exit
10248*44704f69SBart Van Assche	      }
10249*44704f69SBart Van Assche	    done
10250*44704f69SBart Van Assche	    IFS=$save_ifs
10251*44704f69SBart Van Assche
10252*44704f69SBart Van Assche	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10253*44704f69SBart Van Assche	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10254*44704f69SBart Van Assche	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10255*44704f69SBart Van Assche	    fi
10256*44704f69SBart Van Assche	  fi
10257*44704f69SBart Van Assche
10258*44704f69SBart Van Assche          ${skipped_export-false} && {
10259*44704f69SBart Van Assche	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10260*44704f69SBart Van Assche	      tmp_export_symbols=$export_symbols
10261*44704f69SBart Van Assche	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10262*44704f69SBart Van Assche	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10263*44704f69SBart Van Assche	    fi
10264*44704f69SBart Van Assche
10265*44704f69SBart Van Assche	    if test -n "$orig_export_symbols"; then
10266*44704f69SBart Van Assche	      # The given exports_symbols file has to be filtered, so filter it.
10267*44704f69SBart Van Assche	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10268*44704f69SBart Van Assche	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10269*44704f69SBart Van Assche	      # 's' commands, which not all seds can handle. GNU sed should be fine
10270*44704f69SBart Van Assche	      # though. Also, the filter scales superlinearly with the number of
10271*44704f69SBart Van Assche	      # global variables. join(1) would be nice here, but unfortunately
10272*44704f69SBart Van Assche	      # isn't a blessed tool.
10273*44704f69SBart Van Assche	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10274*44704f69SBart Van Assche	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10275*44704f69SBart Van Assche	      export_symbols=$output_objdir/$libname.def
10276*44704f69SBart Van Assche	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10277*44704f69SBart Van Assche	    fi
10278*44704f69SBart Van Assche	  }
10279*44704f69SBart Van Assche
10280*44704f69SBart Van Assche	  libobjs=$output
10281*44704f69SBart Van Assche	  # Restore the value of output.
10282*44704f69SBart Van Assche	  output=$save_output
10283*44704f69SBart Van Assche
10284*44704f69SBart Van Assche	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10285*44704f69SBart Van Assche	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10286*44704f69SBart Van Assche	    test "X$libobjs" = "X " && libobjs=
10287*44704f69SBart Van Assche	  fi
10288*44704f69SBart Van Assche	  # Expand the library linking commands again to reset the
10289*44704f69SBart Van Assche	  # value of $libobjs for piecewise linking.
10290*44704f69SBart Van Assche
10291*44704f69SBart Van Assche	  # Do each of the archive commands.
10292*44704f69SBart Van Assche	  if test yes = "$module" && test -n "$module_cmds"; then
10293*44704f69SBart Van Assche	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10294*44704f69SBart Van Assche	      cmds=$module_expsym_cmds
10295*44704f69SBart Van Assche	    else
10296*44704f69SBart Van Assche	      cmds=$module_cmds
10297*44704f69SBart Van Assche	    fi
10298*44704f69SBart Van Assche	  else
10299*44704f69SBart Van Assche	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10300*44704f69SBart Van Assche	      cmds=$archive_expsym_cmds
10301*44704f69SBart Van Assche	    else
10302*44704f69SBart Van Assche	      cmds=$archive_cmds
10303*44704f69SBart Van Assche	    fi
10304*44704f69SBart Van Assche	  fi
10305*44704f69SBart Van Assche	fi
10306*44704f69SBart Van Assche
10307*44704f69SBart Van Assche	if test -n "$delfiles"; then
10308*44704f69SBart Van Assche	  # Append the command to remove temporary files to $cmds.
10309*44704f69SBart Van Assche	  eval cmds=\"\$cmds~\$RM $delfiles\"
10310*44704f69SBart Van Assche	fi
10311*44704f69SBart Van Assche
10312*44704f69SBart Van Assche	# Add any objects from preloaded convenience libraries
10313*44704f69SBart Van Assche	if test -n "$dlprefiles"; then
10314*44704f69SBart Van Assche	  gentop=$output_objdir/${outputname}x
10315*44704f69SBart Van Assche	  func_append generated " $gentop"
10316*44704f69SBart Van Assche
10317*44704f69SBart Van Assche	  func_extract_archives $gentop $dlprefiles
10318*44704f69SBart Van Assche	  func_append libobjs " $func_extract_archives_result"
10319*44704f69SBart Van Assche	  test "X$libobjs" = "X " && libobjs=
10320*44704f69SBart Van Assche	fi
10321*44704f69SBart Van Assche
10322*44704f69SBart Van Assche	save_ifs=$IFS; IFS='~'
10323*44704f69SBart Van Assche	for cmd in $cmds; do
10324*44704f69SBart Van Assche	  IFS=$sp$nl
10325*44704f69SBart Van Assche	  eval cmd=\"$cmd\"
10326*44704f69SBart Van Assche	  IFS=$save_ifs
10327*44704f69SBart Van Assche	  $opt_quiet || {
10328*44704f69SBart Van Assche	    func_quote_arg expand,pretty "$cmd"
10329*44704f69SBart Van Assche	    eval "func_echo $func_quote_arg_result"
10330*44704f69SBart Van Assche	  }
10331*44704f69SBart Van Assche	  $opt_dry_run || eval "$cmd" || {
10332*44704f69SBart Van Assche	    lt_exit=$?
10333*44704f69SBart Van Assche
10334*44704f69SBart Van Assche	    # Restore the uninstalled library and exit
10335*44704f69SBart Van Assche	    if test relink = "$opt_mode"; then
10336*44704f69SBart Van Assche	      ( cd "$output_objdir" && \
10337*44704f69SBart Van Assche	        $RM "${realname}T" && \
10338*44704f69SBart Van Assche		$MV "${realname}U" "$realname" )
10339*44704f69SBart Van Assche	    fi
10340*44704f69SBart Van Assche
10341*44704f69SBart Van Assche	    exit $lt_exit
10342*44704f69SBart Van Assche	  }
10343*44704f69SBart Van Assche	done
10344*44704f69SBart Van Assche	IFS=$save_ifs
10345*44704f69SBart Van Assche
10346*44704f69SBart Van Assche	# Restore the uninstalled library and exit
10347*44704f69SBart Van Assche	if test relink = "$opt_mode"; then
10348*44704f69SBart Van Assche	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10349*44704f69SBart Van Assche
10350*44704f69SBart Van Assche	  if test -n "$convenience"; then
10351*44704f69SBart Van Assche	    if test -z "$whole_archive_flag_spec"; then
10352*44704f69SBart Van Assche	      func_show_eval '${RM}r "$gentop"'
10353*44704f69SBart Van Assche	    fi
10354*44704f69SBart Van Assche	  fi
10355*44704f69SBart Van Assche
10356*44704f69SBart Van Assche	  exit $EXIT_SUCCESS
10357*44704f69SBart Van Assche	fi
10358*44704f69SBart Van Assche
10359*44704f69SBart Van Assche	# Create links to the real library.
10360*44704f69SBart Van Assche	for linkname in $linknames; do
10361*44704f69SBart Van Assche	  if test "$realname" != "$linkname"; then
10362*44704f69SBart Van Assche	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10363*44704f69SBart Van Assche	  fi
10364*44704f69SBart Van Assche	done
10365*44704f69SBart Van Assche
10366*44704f69SBart Van Assche	# If -module or -export-dynamic was specified, set the dlname.
10367*44704f69SBart Van Assche	if test yes = "$module" || test yes = "$export_dynamic"; then
10368*44704f69SBart Van Assche	  # On all known operating systems, these are identical.
10369*44704f69SBart Van Assche	  dlname=$soname
10370*44704f69SBart Van Assche	fi
10371*44704f69SBart Van Assche      fi
10372*44704f69SBart Van Assche      ;;
10373*44704f69SBart Van Assche
10374*44704f69SBart Van Assche    obj)
10375*44704f69SBart Van Assche      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10376*44704f69SBart Van Assche	func_warning "'-dlopen' is ignored for objects"
10377*44704f69SBart Van Assche      fi
10378*44704f69SBart Van Assche
10379*44704f69SBart Van Assche      case " $deplibs" in
10380*44704f69SBart Van Assche      *\ -l* | *\ -L*)
10381*44704f69SBart Van Assche	func_warning "'-l' and '-L' are ignored for objects" ;;
10382*44704f69SBart Van Assche      esac
10383*44704f69SBart Van Assche
10384*44704f69SBart Van Assche      test -n "$rpath" && \
10385*44704f69SBart Van Assche	func_warning "'-rpath' is ignored for objects"
10386*44704f69SBart Van Assche
10387*44704f69SBart Van Assche      test -n "$xrpath" && \
10388*44704f69SBart Van Assche	func_warning "'-R' is ignored for objects"
10389*44704f69SBart Van Assche
10390*44704f69SBart Van Assche      test -n "$vinfo" && \
10391*44704f69SBart Van Assche	func_warning "'-version-info' is ignored for objects"
10392*44704f69SBart Van Assche
10393*44704f69SBart Van Assche      test -n "$release" && \
10394*44704f69SBart Van Assche	func_warning "'-release' is ignored for objects"
10395*44704f69SBart Van Assche
10396*44704f69SBart Van Assche      case $output in
10397*44704f69SBart Van Assche      *.lo)
10398*44704f69SBart Van Assche	test -n "$objs$old_deplibs" && \
10399*44704f69SBart Van Assche	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10400*44704f69SBart Van Assche
10401*44704f69SBart Van Assche	libobj=$output
10402*44704f69SBart Van Assche	func_lo2o "$libobj"
10403*44704f69SBart Van Assche	obj=$func_lo2o_result
10404*44704f69SBart Van Assche	;;
10405*44704f69SBart Van Assche      *)
10406*44704f69SBart Van Assche	libobj=
10407*44704f69SBart Van Assche	obj=$output
10408*44704f69SBart Van Assche	;;
10409*44704f69SBart Van Assche      esac
10410*44704f69SBart Van Assche
10411*44704f69SBart Van Assche      # Delete the old objects.
10412*44704f69SBart Van Assche      $opt_dry_run || $RM $obj $libobj
10413*44704f69SBart Van Assche
10414*44704f69SBart Van Assche      # Objects from convenience libraries.  This assumes
10415*44704f69SBart Van Assche      # single-version convenience libraries.  Whenever we create
10416*44704f69SBart Van Assche      # different ones for PIC/non-PIC, this we'll have to duplicate
10417*44704f69SBart Van Assche      # the extraction.
10418*44704f69SBart Van Assche      reload_conv_objs=
10419*44704f69SBart Van Assche      gentop=
10420*44704f69SBart Van Assche      # if reload_cmds runs $LD directly, get rid of -Wl from
10421*44704f69SBart Van Assche      # whole_archive_flag_spec and hope we can get by with turning comma
10422*44704f69SBart Van Assche      # into space.
10423*44704f69SBart Van Assche      case $reload_cmds in
10424*44704f69SBart Van Assche        *\$LD[\ \$]*) wl= ;;
10425*44704f69SBart Van Assche      esac
10426*44704f69SBart Van Assche      if test -n "$convenience"; then
10427*44704f69SBart Van Assche	if test -n "$whole_archive_flag_spec"; then
10428*44704f69SBart Van Assche	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10429*44704f69SBart Van Assche	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10430*44704f69SBart Van Assche	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10431*44704f69SBart Van Assche	else
10432*44704f69SBart Van Assche	  gentop=$output_objdir/${obj}x
10433*44704f69SBart Van Assche	  func_append generated " $gentop"
10434*44704f69SBart Van Assche
10435*44704f69SBart Van Assche	  func_extract_archives $gentop $convenience
10436*44704f69SBart Van Assche	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10437*44704f69SBart Van Assche	fi
10438*44704f69SBart Van Assche      fi
10439*44704f69SBart Van Assche
10440*44704f69SBart Van Assche      # If we're not building shared, we need to use non_pic_objs
10441*44704f69SBart Van Assche      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10442*44704f69SBart Van Assche
10443*44704f69SBart Van Assche      # Create the old-style object.
10444*44704f69SBart Van Assche      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10445*44704f69SBart Van Assche
10446*44704f69SBart Van Assche      output=$obj
10447*44704f69SBart Van Assche      func_execute_cmds "$reload_cmds" 'exit $?'
10448*44704f69SBart Van Assche
10449*44704f69SBart Van Assche      # Exit if we aren't doing a library object file.
10450*44704f69SBart Van Assche      if test -z "$libobj"; then
10451*44704f69SBart Van Assche	if test -n "$gentop"; then
10452*44704f69SBart Van Assche	  func_show_eval '${RM}r "$gentop"'
10453*44704f69SBart Van Assche	fi
10454*44704f69SBart Van Assche
10455*44704f69SBart Van Assche	exit $EXIT_SUCCESS
10456*44704f69SBart Van Assche      fi
10457*44704f69SBart Van Assche
10458*44704f69SBart Van Assche      test yes = "$build_libtool_libs" || {
10459*44704f69SBart Van Assche	if test -n "$gentop"; then
10460*44704f69SBart Van Assche	  func_show_eval '${RM}r "$gentop"'
10461*44704f69SBart Van Assche	fi
10462*44704f69SBart Van Assche
10463*44704f69SBart Van Assche	# Create an invalid libtool object if no PIC, so that we don't
10464*44704f69SBart Van Assche	# accidentally link it into a program.
10465*44704f69SBart Van Assche	# $show "echo timestamp > $libobj"
10466*44704f69SBart Van Assche	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10467*44704f69SBart Van Assche	exit $EXIT_SUCCESS
10468*44704f69SBart Van Assche      }
10469*44704f69SBart Van Assche
10470*44704f69SBart Van Assche      if test -n "$pic_flag" || test default != "$pic_mode"; then
10471*44704f69SBart Van Assche	# Only do commands if we really have different PIC objects.
10472*44704f69SBart Van Assche	reload_objs="$libobjs $reload_conv_objs"
10473*44704f69SBart Van Assche	output=$libobj
10474*44704f69SBart Van Assche	func_execute_cmds "$reload_cmds" 'exit $?'
10475*44704f69SBart Van Assche      fi
10476*44704f69SBart Van Assche
10477*44704f69SBart Van Assche      if test -n "$gentop"; then
10478*44704f69SBart Van Assche	func_show_eval '${RM}r "$gentop"'
10479*44704f69SBart Van Assche      fi
10480*44704f69SBart Van Assche
10481*44704f69SBart Van Assche      exit $EXIT_SUCCESS
10482*44704f69SBart Van Assche      ;;
10483*44704f69SBart Van Assche
10484*44704f69SBart Van Assche    prog)
10485*44704f69SBart Van Assche      case $host in
10486*44704f69SBart Van Assche	*cygwin*) func_stripname '' '.exe' "$output"
10487*44704f69SBart Van Assche	          output=$func_stripname_result.exe;;
10488*44704f69SBart Van Assche      esac
10489*44704f69SBart Van Assche      test -n "$vinfo" && \
10490*44704f69SBart Van Assche	func_warning "'-version-info' is ignored for programs"
10491*44704f69SBart Van Assche
10492*44704f69SBart Van Assche      test -n "$release" && \
10493*44704f69SBart Van Assche	func_warning "'-release' is ignored for programs"
10494*44704f69SBart Van Assche
10495*44704f69SBart Van Assche      $preload \
10496*44704f69SBart Van Assche	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10497*44704f69SBart Van Assche	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10498*44704f69SBart Van Assche
10499*44704f69SBart Van Assche      case $host in
10500*44704f69SBart Van Assche      *-*-rhapsody* | *-*-darwin1.[012])
10501*44704f69SBart Van Assche	# On Rhapsody replace the C library is the System framework
10502*44704f69SBart Van Assche	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10503*44704f69SBart Van Assche	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10504*44704f69SBart Van Assche	;;
10505*44704f69SBart Van Assche      esac
10506*44704f69SBart Van Assche
10507*44704f69SBart Van Assche      case $host in
10508*44704f69SBart Van Assche      *-*-darwin*)
10509*44704f69SBart Van Assche	# Don't allow lazy linking, it breaks C++ global constructors
10510*44704f69SBart Van Assche	# But is supposedly fixed on 10.4 or later (yay!).
10511*44704f69SBart Van Assche	if test CXX = "$tagname"; then
10512*44704f69SBart Van Assche	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10513*44704f69SBart Van Assche	    10.[0123])
10514*44704f69SBart Van Assche	      func_append compile_command " $wl-bind_at_load"
10515*44704f69SBart Van Assche	      func_append finalize_command " $wl-bind_at_load"
10516*44704f69SBart Van Assche	    ;;
10517*44704f69SBart Van Assche	  esac
10518*44704f69SBart Van Assche	fi
10519*44704f69SBart Van Assche	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10520*44704f69SBart Van Assche	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10521*44704f69SBart Van Assche	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10522*44704f69SBart Van Assche	;;
10523*44704f69SBart Van Assche      esac
10524*44704f69SBart Van Assche
10525*44704f69SBart Van Assche
10526*44704f69SBart Van Assche      # move library search paths that coincide with paths to not yet
10527*44704f69SBart Van Assche      # installed libraries to the beginning of the library search list
10528*44704f69SBart Van Assche      new_libs=
10529*44704f69SBart Van Assche      for path in $notinst_path; do
10530*44704f69SBart Van Assche	case " $new_libs " in
10531*44704f69SBart Van Assche	*" -L$path/$objdir "*) ;;
10532*44704f69SBart Van Assche	*)
10533*44704f69SBart Van Assche	  case " $compile_deplibs " in
10534*44704f69SBart Van Assche	  *" -L$path/$objdir "*)
10535*44704f69SBart Van Assche	    func_append new_libs " -L$path/$objdir" ;;
10536*44704f69SBart Van Assche	  esac
10537*44704f69SBart Van Assche	  ;;
10538*44704f69SBart Van Assche	esac
10539*44704f69SBart Van Assche      done
10540*44704f69SBart Van Assche      for deplib in $compile_deplibs; do
10541*44704f69SBart Van Assche	case $deplib in
10542*44704f69SBart Van Assche	-L*)
10543*44704f69SBart Van Assche	  case " $new_libs " in
10544*44704f69SBart Van Assche	  *" $deplib "*) ;;
10545*44704f69SBart Van Assche	  *) func_append new_libs " $deplib" ;;
10546*44704f69SBart Van Assche	  esac
10547*44704f69SBart Van Assche	  ;;
10548*44704f69SBart Van Assche	*) func_append new_libs " $deplib" ;;
10549*44704f69SBart Van Assche	esac
10550*44704f69SBart Van Assche      done
10551*44704f69SBart Van Assche      compile_deplibs=$new_libs
10552*44704f69SBart Van Assche
10553*44704f69SBart Van Assche
10554*44704f69SBart Van Assche      func_append compile_command " $compile_deplibs"
10555*44704f69SBart Van Assche      func_append finalize_command " $finalize_deplibs"
10556*44704f69SBart Van Assche
10557*44704f69SBart Van Assche      if test -n "$rpath$xrpath"; then
10558*44704f69SBart Van Assche	# If the user specified any rpath flags, then add them.
10559*44704f69SBart Van Assche	for libdir in $rpath $xrpath; do
10560*44704f69SBart Van Assche	  # This is the magic to use -rpath.
10561*44704f69SBart Van Assche	  case "$finalize_rpath " in
10562*44704f69SBart Van Assche	  *" $libdir "*) ;;
10563*44704f69SBart Van Assche	  *) func_append finalize_rpath " $libdir" ;;
10564*44704f69SBart Van Assche	  esac
10565*44704f69SBart Van Assche	done
10566*44704f69SBart Van Assche      fi
10567*44704f69SBart Van Assche
10568*44704f69SBart Van Assche      # Now hardcode the library paths
10569*44704f69SBart Van Assche      rpath=
10570*44704f69SBart Van Assche      hardcode_libdirs=
10571*44704f69SBart Van Assche      for libdir in $compile_rpath $finalize_rpath; do
10572*44704f69SBart Van Assche	if test -n "$hardcode_libdir_flag_spec"; then
10573*44704f69SBart Van Assche	  if test -n "$hardcode_libdir_separator"; then
10574*44704f69SBart Van Assche	    if test -z "$hardcode_libdirs"; then
10575*44704f69SBart Van Assche	      hardcode_libdirs=$libdir
10576*44704f69SBart Van Assche	    else
10577*44704f69SBart Van Assche	      # Just accumulate the unique libdirs.
10578*44704f69SBart Van Assche	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10579*44704f69SBart Van Assche	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10580*44704f69SBart Van Assche		;;
10581*44704f69SBart Van Assche	      *)
10582*44704f69SBart Van Assche		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10583*44704f69SBart Van Assche		;;
10584*44704f69SBart Van Assche	      esac
10585*44704f69SBart Van Assche	    fi
10586*44704f69SBart Van Assche	  else
10587*44704f69SBart Van Assche	    eval flag=\"$hardcode_libdir_flag_spec\"
10588*44704f69SBart Van Assche	    func_append rpath " $flag"
10589*44704f69SBart Van Assche	  fi
10590*44704f69SBart Van Assche	elif test -n "$runpath_var"; then
10591*44704f69SBart Van Assche	  case "$perm_rpath " in
10592*44704f69SBart Van Assche	  *" $libdir "*) ;;
10593*44704f69SBart Van Assche	  *) func_append perm_rpath " $libdir" ;;
10594*44704f69SBart Van Assche	  esac
10595*44704f69SBart Van Assche	fi
10596*44704f69SBart Van Assche	case $host in
10597*44704f69SBart Van Assche	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10598*44704f69SBart Van Assche	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10599*44704f69SBart Van Assche	  case :$dllsearchpath: in
10600*44704f69SBart Van Assche	  *":$libdir:"*) ;;
10601*44704f69SBart Van Assche	  ::) dllsearchpath=$libdir;;
10602*44704f69SBart Van Assche	  *) func_append dllsearchpath ":$libdir";;
10603*44704f69SBart Van Assche	  esac
10604*44704f69SBart Van Assche	  case :$dllsearchpath: in
10605*44704f69SBart Van Assche	  *":$testbindir:"*) ;;
10606*44704f69SBart Van Assche	  ::) dllsearchpath=$testbindir;;
10607*44704f69SBart Van Assche	  *) func_append dllsearchpath ":$testbindir";;
10608*44704f69SBart Van Assche	  esac
10609*44704f69SBart Van Assche	  ;;
10610*44704f69SBart Van Assche	esac
10611*44704f69SBart Van Assche      done
10612*44704f69SBart Van Assche      # Substitute the hardcoded libdirs into the rpath.
10613*44704f69SBart Van Assche      if test -n "$hardcode_libdir_separator" &&
10614*44704f69SBart Van Assche	 test -n "$hardcode_libdirs"; then
10615*44704f69SBart Van Assche	libdir=$hardcode_libdirs
10616*44704f69SBart Van Assche	eval rpath=\" $hardcode_libdir_flag_spec\"
10617*44704f69SBart Van Assche      fi
10618*44704f69SBart Van Assche      compile_rpath=$rpath
10619*44704f69SBart Van Assche
10620*44704f69SBart Van Assche      rpath=
10621*44704f69SBart Van Assche      hardcode_libdirs=
10622*44704f69SBart Van Assche      for libdir in $finalize_rpath; do
10623*44704f69SBart Van Assche	if test -n "$hardcode_libdir_flag_spec"; then
10624*44704f69SBart Van Assche	  if test -n "$hardcode_libdir_separator"; then
10625*44704f69SBart Van Assche	    if test -z "$hardcode_libdirs"; then
10626*44704f69SBart Van Assche	      hardcode_libdirs=$libdir
10627*44704f69SBart Van Assche	    else
10628*44704f69SBart Van Assche	      # Just accumulate the unique libdirs.
10629*44704f69SBart Van Assche	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10630*44704f69SBart Van Assche	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10631*44704f69SBart Van Assche		;;
10632*44704f69SBart Van Assche	      *)
10633*44704f69SBart Van Assche		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10634*44704f69SBart Van Assche		;;
10635*44704f69SBart Van Assche	      esac
10636*44704f69SBart Van Assche	    fi
10637*44704f69SBart Van Assche	  else
10638*44704f69SBart Van Assche	    eval flag=\"$hardcode_libdir_flag_spec\"
10639*44704f69SBart Van Assche	    func_append rpath " $flag"
10640*44704f69SBart Van Assche	  fi
10641*44704f69SBart Van Assche	elif test -n "$runpath_var"; then
10642*44704f69SBart Van Assche	  case "$finalize_perm_rpath " in
10643*44704f69SBart Van Assche	  *" $libdir "*) ;;
10644*44704f69SBart Van Assche	  *) func_append finalize_perm_rpath " $libdir" ;;
10645*44704f69SBart Van Assche	  esac
10646*44704f69SBart Van Assche	fi
10647*44704f69SBart Van Assche      done
10648*44704f69SBart Van Assche      # Substitute the hardcoded libdirs into the rpath.
10649*44704f69SBart Van Assche      if test -n "$hardcode_libdir_separator" &&
10650*44704f69SBart Van Assche	 test -n "$hardcode_libdirs"; then
10651*44704f69SBart Van Assche	libdir=$hardcode_libdirs
10652*44704f69SBart Van Assche	eval rpath=\" $hardcode_libdir_flag_spec\"
10653*44704f69SBart Van Assche      fi
10654*44704f69SBart Van Assche      finalize_rpath=$rpath
10655*44704f69SBart Van Assche
10656*44704f69SBart Van Assche      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10657*44704f69SBart Van Assche	# Transform all the library objects into standard objects.
10658*44704f69SBart Van Assche	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10659*44704f69SBart Van Assche	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10660*44704f69SBart Van Assche      fi
10661*44704f69SBart Van Assche
10662*44704f69SBart Van Assche      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10663*44704f69SBart Van Assche
10664*44704f69SBart Van Assche      # template prelinking step
10665*44704f69SBart Van Assche      if test -n "$prelink_cmds"; then
10666*44704f69SBart Van Assche	func_execute_cmds "$prelink_cmds" 'exit $?'
10667*44704f69SBart Van Assche      fi
10668*44704f69SBart Van Assche
10669*44704f69SBart Van Assche      wrappers_required=:
10670*44704f69SBart Van Assche      case $host in
10671*44704f69SBart Van Assche      *cegcc* | *mingw32ce*)
10672*44704f69SBart Van Assche        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10673*44704f69SBart Van Assche        wrappers_required=false
10674*44704f69SBart Van Assche        ;;
10675*44704f69SBart Van Assche      *cygwin* | *mingw* )
10676*44704f69SBart Van Assche        test yes = "$build_libtool_libs" || wrappers_required=false
10677*44704f69SBart Van Assche        ;;
10678*44704f69SBart Van Assche      *)
10679*44704f69SBart Van Assche        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10680*44704f69SBart Van Assche          wrappers_required=false
10681*44704f69SBart Van Assche        fi
10682*44704f69SBart Van Assche        ;;
10683*44704f69SBart Van Assche      esac
10684*44704f69SBart Van Assche      $wrappers_required || {
10685*44704f69SBart Van Assche	# Replace the output file specification.
10686*44704f69SBart Van Assche	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10687*44704f69SBart Van Assche	link_command=$compile_command$compile_rpath
10688*44704f69SBart Van Assche
10689*44704f69SBart Van Assche	# We have no uninstalled library dependencies, so finalize right now.
10690*44704f69SBart Van Assche	exit_status=0
10691*44704f69SBart Van Assche	func_show_eval "$link_command" 'exit_status=$?'
10692*44704f69SBart Van Assche
10693*44704f69SBart Van Assche	if test -n "$postlink_cmds"; then
10694*44704f69SBart Van Assche	  func_to_tool_file "$output"
10695*44704f69SBart Van Assche	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10696*44704f69SBart Van Assche	  func_execute_cmds "$postlink_cmds" 'exit $?'
10697*44704f69SBart Van Assche	fi
10698*44704f69SBart Van Assche
10699*44704f69SBart Van Assche	# Delete the generated files.
10700*44704f69SBart Van Assche	if test -f "$output_objdir/${outputname}S.$objext"; then
10701*44704f69SBart Van Assche	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10702*44704f69SBart Van Assche	fi
10703*44704f69SBart Van Assche
10704*44704f69SBart Van Assche	exit $exit_status
10705*44704f69SBart Van Assche      }
10706*44704f69SBart Van Assche
10707*44704f69SBart Van Assche      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10708*44704f69SBart Van Assche	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10709*44704f69SBart Van Assche      fi
10710*44704f69SBart Van Assche      if test -n "$finalize_shlibpath"; then
10711*44704f69SBart Van Assche	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10712*44704f69SBart Van Assche      fi
10713*44704f69SBart Van Assche
10714*44704f69SBart Van Assche      compile_var=
10715*44704f69SBart Van Assche      finalize_var=
10716*44704f69SBart Van Assche      if test -n "$runpath_var"; then
10717*44704f69SBart Van Assche	if test -n "$perm_rpath"; then
10718*44704f69SBart Van Assche	  # We should set the runpath_var.
10719*44704f69SBart Van Assche	  rpath=
10720*44704f69SBart Van Assche	  for dir in $perm_rpath; do
10721*44704f69SBart Van Assche	    func_append rpath "$dir:"
10722*44704f69SBart Van Assche	  done
10723*44704f69SBart Van Assche	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10724*44704f69SBart Van Assche	fi
10725*44704f69SBart Van Assche	if test -n "$finalize_perm_rpath"; then
10726*44704f69SBart Van Assche	  # We should set the runpath_var.
10727*44704f69SBart Van Assche	  rpath=
10728*44704f69SBart Van Assche	  for dir in $finalize_perm_rpath; do
10729*44704f69SBart Van Assche	    func_append rpath "$dir:"
10730*44704f69SBart Van Assche	  done
10731*44704f69SBart Van Assche	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10732*44704f69SBart Van Assche	fi
10733*44704f69SBart Van Assche      fi
10734*44704f69SBart Van Assche
10735*44704f69SBart Van Assche      if test yes = "$no_install"; then
10736*44704f69SBart Van Assche	# We don't need to create a wrapper script.
10737*44704f69SBart Van Assche	link_command=$compile_var$compile_command$compile_rpath
10738*44704f69SBart Van Assche	# Replace the output file specification.
10739*44704f69SBart Van Assche	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10740*44704f69SBart Van Assche	# Delete the old output file.
10741*44704f69SBart Van Assche	$opt_dry_run || $RM $output
10742*44704f69SBart Van Assche	# Link the executable and exit
10743*44704f69SBart Van Assche	func_show_eval "$link_command" 'exit $?'
10744*44704f69SBart Van Assche
10745*44704f69SBart Van Assche	if test -n "$postlink_cmds"; then
10746*44704f69SBart Van Assche	  func_to_tool_file "$output"
10747*44704f69SBart Van Assche	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10748*44704f69SBart Van Assche	  func_execute_cmds "$postlink_cmds" 'exit $?'
10749*44704f69SBart Van Assche	fi
10750*44704f69SBart Van Assche
10751*44704f69SBart Van Assche	exit $EXIT_SUCCESS
10752*44704f69SBart Van Assche      fi
10753*44704f69SBart Van Assche
10754*44704f69SBart Van Assche      case $hardcode_action,$fast_install in
10755*44704f69SBart Van Assche        relink,*)
10756*44704f69SBart Van Assche	  # Fast installation is not supported
10757*44704f69SBart Van Assche	  link_command=$compile_var$compile_command$compile_rpath
10758*44704f69SBart Van Assche	  relink_command=$finalize_var$finalize_command$finalize_rpath
10759*44704f69SBart Van Assche
10760*44704f69SBart Van Assche	  func_warning "this platform does not like uninstalled shared libraries"
10761*44704f69SBart Van Assche	  func_warning "'$output' will be relinked during installation"
10762*44704f69SBart Van Assche	  ;;
10763*44704f69SBart Van Assche        *,yes)
10764*44704f69SBart Van Assche	  link_command=$finalize_var$compile_command$finalize_rpath
10765*44704f69SBart Van Assche	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10766*44704f69SBart Van Assche          ;;
10767*44704f69SBart Van Assche	*,no)
10768*44704f69SBart Van Assche	  link_command=$compile_var$compile_command$compile_rpath
10769*44704f69SBart Van Assche	  relink_command=$finalize_var$finalize_command$finalize_rpath
10770*44704f69SBart Van Assche          ;;
10771*44704f69SBart Van Assche	*,needless)
10772*44704f69SBart Van Assche	  link_command=$finalize_var$compile_command$finalize_rpath
10773*44704f69SBart Van Assche	  relink_command=
10774*44704f69SBart Van Assche          ;;
10775*44704f69SBart Van Assche      esac
10776*44704f69SBart Van Assche
10777*44704f69SBart Van Assche      # Replace the output file specification.
10778*44704f69SBart Van Assche      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10779*44704f69SBart Van Assche
10780*44704f69SBart Van Assche      # Delete the old output files.
10781*44704f69SBart Van Assche      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10782*44704f69SBart Van Assche
10783*44704f69SBart Van Assche      func_show_eval "$link_command" 'exit $?'
10784*44704f69SBart Van Assche
10785*44704f69SBart Van Assche      if test -n "$postlink_cmds"; then
10786*44704f69SBart Van Assche	func_to_tool_file "$output_objdir/$outputname"
10787*44704f69SBart Van Assche	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'`
10788*44704f69SBart Van Assche	func_execute_cmds "$postlink_cmds" 'exit $?'
10789*44704f69SBart Van Assche      fi
10790*44704f69SBart Van Assche
10791*44704f69SBart Van Assche      # Now create the wrapper script.
10792*44704f69SBart Van Assche      func_verbose "creating $output"
10793*44704f69SBart Van Assche
10794*44704f69SBart Van Assche      # Quote the relink command for shipping.
10795*44704f69SBart Van Assche      if test -n "$relink_command"; then
10796*44704f69SBart Van Assche	# Preserve any variables that may affect compiler behavior
10797*44704f69SBart Van Assche	for var in $variables_saved_for_relink; do
10798*44704f69SBart Van Assche	  if eval test -z \"\${$var+set}\"; then
10799*44704f69SBart Van Assche	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10800*44704f69SBart Van Assche	  elif eval var_value=\$$var; test -z "$var_value"; then
10801*44704f69SBart Van Assche	    relink_command="$var=; export $var; $relink_command"
10802*44704f69SBart Van Assche	  else
10803*44704f69SBart Van Assche	    func_quote_arg pretty "$var_value"
10804*44704f69SBart Van Assche	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
10805*44704f69SBart Van Assche	  fi
10806*44704f69SBart Van Assche	done
10807*44704f69SBart Van Assche	func_quote eval cd "`pwd`"
10808*44704f69SBart Van Assche	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10809*44704f69SBart Van Assche	relink_command=$func_quote_arg_unquoted_result
10810*44704f69SBart Van Assche      fi
10811*44704f69SBart Van Assche
10812*44704f69SBart Van Assche      # Only actually do things if not in dry run mode.
10813*44704f69SBart Van Assche      $opt_dry_run || {
10814*44704f69SBart Van Assche	# win32 will think the script is a binary if it has
10815*44704f69SBart Van Assche	# a .exe suffix, so we strip it off here.
10816*44704f69SBart Van Assche	case $output in
10817*44704f69SBart Van Assche	  *.exe) func_stripname '' '.exe' "$output"
10818*44704f69SBart Van Assche	         output=$func_stripname_result ;;
10819*44704f69SBart Van Assche	esac
10820*44704f69SBart Van Assche	# test for cygwin because mv fails w/o .exe extensions
10821*44704f69SBart Van Assche	case $host in
10822*44704f69SBart Van Assche	  *cygwin*)
10823*44704f69SBart Van Assche	    exeext=.exe
10824*44704f69SBart Van Assche	    func_stripname '' '.exe' "$outputname"
10825*44704f69SBart Van Assche	    outputname=$func_stripname_result ;;
10826*44704f69SBart Van Assche	  *) exeext= ;;
10827*44704f69SBart Van Assche	esac
10828*44704f69SBart Van Assche	case $host in
10829*44704f69SBart Van Assche	  *cygwin* | *mingw* )
10830*44704f69SBart Van Assche	    func_dirname_and_basename "$output" "" "."
10831*44704f69SBart Van Assche	    output_name=$func_basename_result
10832*44704f69SBart Van Assche	    output_path=$func_dirname_result
10833*44704f69SBart Van Assche	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10834*44704f69SBart Van Assche	    cwrapper=$output_path/$output_name.exe
10835*44704f69SBart Van Assche	    $RM $cwrappersource $cwrapper
10836*44704f69SBart Van Assche	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10837*44704f69SBart Van Assche
10838*44704f69SBart Van Assche	    func_emit_cwrapperexe_src > $cwrappersource
10839*44704f69SBart Van Assche
10840*44704f69SBart Van Assche	    # The wrapper executable is built using the $host compiler,
10841*44704f69SBart Van Assche	    # because it contains $host paths and files. If cross-
10842*44704f69SBart Van Assche	    # compiling, it, like the target executable, must be
10843*44704f69SBart Van Assche	    # executed on the $host or under an emulation environment.
10844*44704f69SBart Van Assche	    $opt_dry_run || {
10845*44704f69SBart Van Assche	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10846*44704f69SBart Van Assche	      $STRIP $cwrapper
10847*44704f69SBart Van Assche	    }
10848*44704f69SBart Van Assche
10849*44704f69SBart Van Assche	    # Now, create the wrapper script for func_source use:
10850*44704f69SBart Van Assche	    func_ltwrapper_scriptname $cwrapper
10851*44704f69SBart Van Assche	    $RM $func_ltwrapper_scriptname_result
10852*44704f69SBart Van Assche	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10853*44704f69SBart Van Assche	    $opt_dry_run || {
10854*44704f69SBart Van Assche	      # note: this script will not be executed, so do not chmod.
10855*44704f69SBart Van Assche	      if test "x$build" = "x$host"; then
10856*44704f69SBart Van Assche		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10857*44704f69SBart Van Assche	      else
10858*44704f69SBart Van Assche		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10859*44704f69SBart Van Assche	      fi
10860*44704f69SBart Van Assche	    }
10861*44704f69SBart Van Assche	  ;;
10862*44704f69SBart Van Assche	  * )
10863*44704f69SBart Van Assche	    $RM $output
10864*44704f69SBart Van Assche	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10865*44704f69SBart Van Assche
10866*44704f69SBart Van Assche	    func_emit_wrapper no > $output
10867*44704f69SBart Van Assche	    chmod +x $output
10868*44704f69SBart Van Assche	  ;;
10869*44704f69SBart Van Assche	esac
10870*44704f69SBart Van Assche      }
10871*44704f69SBart Van Assche      exit $EXIT_SUCCESS
10872*44704f69SBart Van Assche      ;;
10873*44704f69SBart Van Assche    esac
10874*44704f69SBart Van Assche
10875*44704f69SBart Van Assche    # See if we need to build an old-fashioned archive.
10876*44704f69SBart Van Assche    for oldlib in $oldlibs; do
10877*44704f69SBart Van Assche
10878*44704f69SBart Van Assche      case $build_libtool_libs in
10879*44704f69SBart Van Assche        convenience)
10880*44704f69SBart Van Assche	  oldobjs="$libobjs_save $symfileobj"
10881*44704f69SBart Van Assche	  addlibs=$convenience
10882*44704f69SBart Van Assche	  build_libtool_libs=no
10883*44704f69SBart Van Assche	  ;;
10884*44704f69SBart Van Assche	module)
10885*44704f69SBart Van Assche	  oldobjs=$libobjs_save
10886*44704f69SBart Van Assche	  addlibs=$old_convenience
10887*44704f69SBart Van Assche	  build_libtool_libs=no
10888*44704f69SBart Van Assche          ;;
10889*44704f69SBart Van Assche	*)
10890*44704f69SBart Van Assche	  oldobjs="$old_deplibs $non_pic_objects"
10891*44704f69SBart Van Assche	  $preload && test -f "$symfileobj" \
10892*44704f69SBart Van Assche	    && func_append oldobjs " $symfileobj"
10893*44704f69SBart Van Assche	  addlibs=$old_convenience
10894*44704f69SBart Van Assche	  ;;
10895*44704f69SBart Van Assche      esac
10896*44704f69SBart Van Assche
10897*44704f69SBart Van Assche      if test -n "$addlibs"; then
10898*44704f69SBart Van Assche	gentop=$output_objdir/${outputname}x
10899*44704f69SBart Van Assche	func_append generated " $gentop"
10900*44704f69SBart Van Assche
10901*44704f69SBart Van Assche	func_extract_archives $gentop $addlibs
10902*44704f69SBart Van Assche	func_append oldobjs " $func_extract_archives_result"
10903*44704f69SBart Van Assche      fi
10904*44704f69SBart Van Assche
10905*44704f69SBart Van Assche      # Do each command in the archive commands.
10906*44704f69SBart Van Assche      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10907*44704f69SBart Van Assche	cmds=$old_archive_from_new_cmds
10908*44704f69SBart Van Assche      else
10909*44704f69SBart Van Assche
10910*44704f69SBart Van Assche	# Add any objects from preloaded convenience libraries
10911*44704f69SBart Van Assche	if test -n "$dlprefiles"; then
10912*44704f69SBart Van Assche	  gentop=$output_objdir/${outputname}x
10913*44704f69SBart Van Assche	  func_append generated " $gentop"
10914*44704f69SBart Van Assche
10915*44704f69SBart Van Assche	  func_extract_archives $gentop $dlprefiles
10916*44704f69SBart Van Assche	  func_append oldobjs " $func_extract_archives_result"
10917*44704f69SBart Van Assche	fi
10918*44704f69SBart Van Assche
10919*44704f69SBart Van Assche	# POSIX demands no paths to be encoded in archives.  We have
10920*44704f69SBart Van Assche	# to avoid creating archives with duplicate basenames if we
10921*44704f69SBart Van Assche	# might have to extract them afterwards, e.g., when creating a
10922*44704f69SBart Van Assche	# static archive out of a convenience library, or when linking
10923*44704f69SBart Van Assche	# the entirety of a libtool archive into another (currently
10924*44704f69SBart Van Assche	# not supported by libtool).
10925*44704f69SBart Van Assche	if (for obj in $oldobjs
10926*44704f69SBart Van Assche	    do
10927*44704f69SBart Van Assche	      func_basename "$obj"
10928*44704f69SBart Van Assche	      $ECHO "$func_basename_result"
10929*44704f69SBart Van Assche	    done | sort | sort -uc >/dev/null 2>&1); then
10930*44704f69SBart Van Assche	  :
10931*44704f69SBart Van Assche	else
10932*44704f69SBart Van Assche	  echo "copying selected object files to avoid basename conflicts..."
10933*44704f69SBart Van Assche	  gentop=$output_objdir/${outputname}x
10934*44704f69SBart Van Assche	  func_append generated " $gentop"
10935*44704f69SBart Van Assche	  func_mkdir_p "$gentop"
10936*44704f69SBart Van Assche	  save_oldobjs=$oldobjs
10937*44704f69SBart Van Assche	  oldobjs=
10938*44704f69SBart Van Assche	  counter=1
10939*44704f69SBart Van Assche	  for obj in $save_oldobjs
10940*44704f69SBart Van Assche	  do
10941*44704f69SBart Van Assche	    func_basename "$obj"
10942*44704f69SBart Van Assche	    objbase=$func_basename_result
10943*44704f69SBart Van Assche	    case " $oldobjs " in
10944*44704f69SBart Van Assche	    " ") oldobjs=$obj ;;
10945*44704f69SBart Van Assche	    *[\ /]"$objbase "*)
10946*44704f69SBart Van Assche	      while :; do
10947*44704f69SBart Van Assche		# Make sure we don't pick an alternate name that also
10948*44704f69SBart Van Assche		# overlaps.
10949*44704f69SBart Van Assche		newobj=lt$counter-$objbase
10950*44704f69SBart Van Assche		func_arith $counter + 1
10951*44704f69SBart Van Assche		counter=$func_arith_result
10952*44704f69SBart Van Assche		case " $oldobjs " in
10953*44704f69SBart Van Assche		*[\ /]"$newobj "*) ;;
10954*44704f69SBart Van Assche		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10955*44704f69SBart Van Assche		esac
10956*44704f69SBart Van Assche	      done
10957*44704f69SBart Van Assche	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10958*44704f69SBart Van Assche	      func_append oldobjs " $gentop/$newobj"
10959*44704f69SBart Van Assche	      ;;
10960*44704f69SBart Van Assche	    *) func_append oldobjs " $obj" ;;
10961*44704f69SBart Van Assche	    esac
10962*44704f69SBart Van Assche	  done
10963*44704f69SBart Van Assche	fi
10964*44704f69SBart Van Assche	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10965*44704f69SBart Van Assche	tool_oldlib=$func_to_tool_file_result
10966*44704f69SBart Van Assche	eval cmds=\"$old_archive_cmds\"
10967*44704f69SBart Van Assche
10968*44704f69SBart Van Assche	func_len " $cmds"
10969*44704f69SBart Van Assche	len=$func_len_result
10970*44704f69SBart Van Assche	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10971*44704f69SBart Van Assche	  cmds=$old_archive_cmds
10972*44704f69SBart Van Assche	elif test -n "$archiver_list_spec"; then
10973*44704f69SBart Van Assche	  func_verbose "using command file archive linking..."
10974*44704f69SBart Van Assche	  for obj in $oldobjs
10975*44704f69SBart Van Assche	  do
10976*44704f69SBart Van Assche	    func_to_tool_file "$obj"
10977*44704f69SBart Van Assche	    $ECHO "$func_to_tool_file_result"
10978*44704f69SBart Van Assche	  done > $output_objdir/$libname.libcmd
10979*44704f69SBart Van Assche	  func_to_tool_file "$output_objdir/$libname.libcmd"
10980*44704f69SBart Van Assche	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10981*44704f69SBart Van Assche	  cmds=$old_archive_cmds
10982*44704f69SBart Van Assche	else
10983*44704f69SBart Van Assche	  # the command line is too long to link in one step, link in parts
10984*44704f69SBart Van Assche	  func_verbose "using piecewise archive linking..."
10985*44704f69SBart Van Assche	  save_RANLIB=$RANLIB
10986*44704f69SBart Van Assche	  RANLIB=:
10987*44704f69SBart Van Assche	  objlist=
10988*44704f69SBart Van Assche	  concat_cmds=
10989*44704f69SBart Van Assche	  save_oldobjs=$oldobjs
10990*44704f69SBart Van Assche	  oldobjs=
10991*44704f69SBart Van Assche	  # Is there a better way of finding the last object in the list?
10992*44704f69SBart Van Assche	  for obj in $save_oldobjs
10993*44704f69SBart Van Assche	  do
10994*44704f69SBart Van Assche	    last_oldobj=$obj
10995*44704f69SBart Van Assche	  done
10996*44704f69SBart Van Assche	  eval test_cmds=\"$old_archive_cmds\"
10997*44704f69SBart Van Assche	  func_len " $test_cmds"
10998*44704f69SBart Van Assche	  len0=$func_len_result
10999*44704f69SBart Van Assche	  len=$len0
11000*44704f69SBart Van Assche	  for obj in $save_oldobjs
11001*44704f69SBart Van Assche	  do
11002*44704f69SBart Van Assche	    func_len " $obj"
11003*44704f69SBart Van Assche	    func_arith $len + $func_len_result
11004*44704f69SBart Van Assche	    len=$func_arith_result
11005*44704f69SBart Van Assche	    func_append objlist " $obj"
11006*44704f69SBart Van Assche	    if test "$len" -lt "$max_cmd_len"; then
11007*44704f69SBart Van Assche	      :
11008*44704f69SBart Van Assche	    else
11009*44704f69SBart Van Assche	      # the above command should be used before it gets too long
11010*44704f69SBart Van Assche	      oldobjs=$objlist
11011*44704f69SBart Van Assche	      if test "$obj" = "$last_oldobj"; then
11012*44704f69SBart Van Assche		RANLIB=$save_RANLIB
11013*44704f69SBart Van Assche	      fi
11014*44704f69SBart Van Assche	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11015*44704f69SBart Van Assche	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11016*44704f69SBart Van Assche	      objlist=
11017*44704f69SBart Van Assche	      len=$len0
11018*44704f69SBart Van Assche	    fi
11019*44704f69SBart Van Assche	  done
11020*44704f69SBart Van Assche	  RANLIB=$save_RANLIB
11021*44704f69SBart Van Assche	  oldobjs=$objlist
11022*44704f69SBart Van Assche	  if test -z "$oldobjs"; then
11023*44704f69SBart Van Assche	    eval cmds=\"\$concat_cmds\"
11024*44704f69SBart Van Assche	  else
11025*44704f69SBart Van Assche	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11026*44704f69SBart Van Assche	  fi
11027*44704f69SBart Van Assche	fi
11028*44704f69SBart Van Assche      fi
11029*44704f69SBart Van Assche      func_execute_cmds "$cmds" 'exit $?'
11030*44704f69SBart Van Assche    done
11031*44704f69SBart Van Assche
11032*44704f69SBart Van Assche    test -n "$generated" && \
11033*44704f69SBart Van Assche      func_show_eval "${RM}r$generated"
11034*44704f69SBart Van Assche
11035*44704f69SBart Van Assche    # Now create the libtool archive.
11036*44704f69SBart Van Assche    case $output in
11037*44704f69SBart Van Assche    *.la)
11038*44704f69SBart Van Assche      old_library=
11039*44704f69SBart Van Assche      test yes = "$build_old_libs" && old_library=$libname.$libext
11040*44704f69SBart Van Assche      func_verbose "creating $output"
11041*44704f69SBart Van Assche
11042*44704f69SBart Van Assche      # Preserve any variables that may affect compiler behavior
11043*44704f69SBart Van Assche      for var in $variables_saved_for_relink; do
11044*44704f69SBart Van Assche	if eval test -z \"\${$var+set}\"; then
11045*44704f69SBart Van Assche	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11046*44704f69SBart Van Assche	elif eval var_value=\$$var; test -z "$var_value"; then
11047*44704f69SBart Van Assche	  relink_command="$var=; export $var; $relink_command"
11048*44704f69SBart Van Assche	else
11049*44704f69SBart Van Assche	  func_quote_arg pretty,unquoted "$var_value"
11050*44704f69SBart Van Assche	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11051*44704f69SBart Van Assche	fi
11052*44704f69SBart Van Assche      done
11053*44704f69SBart Van Assche      # Quote the link command for shipping.
11054*44704f69SBart Van Assche      func_quote eval cd "`pwd`"
11055*44704f69SBart Van Assche      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11056*44704f69SBart Van Assche      func_quote_arg pretty,unquoted "$relink_command"
11057*44704f69SBart Van Assche      relink_command=$func_quote_arg_unquoted_result
11058*44704f69SBart Van Assche      if test yes = "$hardcode_automatic"; then
11059*44704f69SBart Van Assche	relink_command=
11060*44704f69SBart Van Assche      fi
11061*44704f69SBart Van Assche
11062*44704f69SBart Van Assche      # Only create the output if not a dry run.
11063*44704f69SBart Van Assche      $opt_dry_run || {
11064*44704f69SBart Van Assche	for installed in no yes; do
11065*44704f69SBart Van Assche	  if test yes = "$installed"; then
11066*44704f69SBart Van Assche	    if test -z "$install_libdir"; then
11067*44704f69SBart Van Assche	      break
11068*44704f69SBart Van Assche	    fi
11069*44704f69SBart Van Assche	    output=$output_objdir/${outputname}i
11070*44704f69SBart Van Assche	    # Replace all uninstalled libtool libraries with the installed ones
11071*44704f69SBart Van Assche	    newdependency_libs=
11072*44704f69SBart Van Assche	    for deplib in $dependency_libs; do
11073*44704f69SBart Van Assche	      case $deplib in
11074*44704f69SBart Van Assche	      *.la)
11075*44704f69SBart Van Assche		func_basename "$deplib"
11076*44704f69SBart Van Assche		name=$func_basename_result
11077*44704f69SBart Van Assche		func_resolve_sysroot "$deplib"
11078*44704f69SBart Van Assche		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11079*44704f69SBart Van Assche		test -z "$libdir" && \
11080*44704f69SBart Van Assche		  func_fatal_error "'$deplib' is not a valid libtool archive"
11081*44704f69SBart Van Assche		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11082*44704f69SBart Van Assche		;;
11083*44704f69SBart Van Assche	      -L*)
11084*44704f69SBart Van Assche		func_stripname -L '' "$deplib"
11085*44704f69SBart Van Assche		func_replace_sysroot "$func_stripname_result"
11086*44704f69SBart Van Assche		func_append newdependency_libs " -L$func_replace_sysroot_result"
11087*44704f69SBart Van Assche		;;
11088*44704f69SBart Van Assche	      -R*)
11089*44704f69SBart Van Assche		func_stripname -R '' "$deplib"
11090*44704f69SBart Van Assche		func_replace_sysroot "$func_stripname_result"
11091*44704f69SBart Van Assche		func_append newdependency_libs " -R$func_replace_sysroot_result"
11092*44704f69SBart Van Assche		;;
11093*44704f69SBart Van Assche	      *) func_append newdependency_libs " $deplib" ;;
11094*44704f69SBart Van Assche	      esac
11095*44704f69SBart Van Assche	    done
11096*44704f69SBart Van Assche	    dependency_libs=$newdependency_libs
11097*44704f69SBart Van Assche	    newdlfiles=
11098*44704f69SBart Van Assche
11099*44704f69SBart Van Assche	    for lib in $dlfiles; do
11100*44704f69SBart Van Assche	      case $lib in
11101*44704f69SBart Van Assche	      *.la)
11102*44704f69SBart Van Assche	        func_basename "$lib"
11103*44704f69SBart Van Assche		name=$func_basename_result
11104*44704f69SBart Van Assche		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11105*44704f69SBart Van Assche		test -z "$libdir" && \
11106*44704f69SBart Van Assche		  func_fatal_error "'$lib' is not a valid libtool archive"
11107*44704f69SBart Van Assche		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11108*44704f69SBart Van Assche		;;
11109*44704f69SBart Van Assche	      *) func_append newdlfiles " $lib" ;;
11110*44704f69SBart Van Assche	      esac
11111*44704f69SBart Van Assche	    done
11112*44704f69SBart Van Assche	    dlfiles=$newdlfiles
11113*44704f69SBart Van Assche	    newdlprefiles=
11114*44704f69SBart Van Assche	    for lib in $dlprefiles; do
11115*44704f69SBart Van Assche	      case $lib in
11116*44704f69SBart Van Assche	      *.la)
11117*44704f69SBart Van Assche		# Only pass preopened files to the pseudo-archive (for
11118*44704f69SBart Van Assche		# eventual linking with the app. that links it) if we
11119*44704f69SBart Van Assche		# didn't already link the preopened objects directly into
11120*44704f69SBart Van Assche		# the library:
11121*44704f69SBart Van Assche		func_basename "$lib"
11122*44704f69SBart Van Assche		name=$func_basename_result
11123*44704f69SBart Van Assche		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11124*44704f69SBart Van Assche		test -z "$libdir" && \
11125*44704f69SBart Van Assche		  func_fatal_error "'$lib' is not a valid libtool archive"
11126*44704f69SBart Van Assche		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11127*44704f69SBart Van Assche		;;
11128*44704f69SBart Van Assche	      esac
11129*44704f69SBart Van Assche	    done
11130*44704f69SBart Van Assche	    dlprefiles=$newdlprefiles
11131*44704f69SBart Van Assche	  else
11132*44704f69SBart Van Assche	    newdlfiles=
11133*44704f69SBart Van Assche	    for lib in $dlfiles; do
11134*44704f69SBart Van Assche	      case $lib in
11135*44704f69SBart Van Assche		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11136*44704f69SBart Van Assche		*) abs=`pwd`"/$lib" ;;
11137*44704f69SBart Van Assche	      esac
11138*44704f69SBart Van Assche	      func_append newdlfiles " $abs"
11139*44704f69SBart Van Assche	    done
11140*44704f69SBart Van Assche	    dlfiles=$newdlfiles
11141*44704f69SBart Van Assche	    newdlprefiles=
11142*44704f69SBart Van Assche	    for lib in $dlprefiles; do
11143*44704f69SBart Van Assche	      case $lib in
11144*44704f69SBart Van Assche		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11145*44704f69SBart Van Assche		*) abs=`pwd`"/$lib" ;;
11146*44704f69SBart Van Assche	      esac
11147*44704f69SBart Van Assche	      func_append newdlprefiles " $abs"
11148*44704f69SBart Van Assche	    done
11149*44704f69SBart Van Assche	    dlprefiles=$newdlprefiles
11150*44704f69SBart Van Assche	  fi
11151*44704f69SBart Van Assche	  $RM $output
11152*44704f69SBart Van Assche	  # place dlname in correct position for cygwin
11153*44704f69SBart Van Assche	  # In fact, it would be nice if we could use this code for all target
11154*44704f69SBart Van Assche	  # systems that can't hard-code library paths into their executables
11155*44704f69SBart Van Assche	  # and that have no shared library path variable independent of PATH,
11156*44704f69SBart Van Assche	  # but it turns out we can't easily determine that from inspecting
11157*44704f69SBart Van Assche	  # libtool variables, so we have to hard-code the OSs to which it
11158*44704f69SBart Van Assche	  # applies here; at the moment, that means platforms that use the PE
11159*44704f69SBart Van Assche	  # object format with DLL files.  See the long comment at the top of
11160*44704f69SBart Van Assche	  # tests/bindir.at for full details.
11161*44704f69SBart Van Assche	  tdlname=$dlname
11162*44704f69SBart Van Assche	  case $host,$output,$installed,$module,$dlname in
11163*44704f69SBart Van Assche	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11164*44704f69SBart Van Assche	      # If a -bindir argument was supplied, place the dll there.
11165*44704f69SBart Van Assche	      if test -n "$bindir"; then
11166*44704f69SBart Van Assche		func_relative_path "$install_libdir" "$bindir"
11167*44704f69SBart Van Assche		tdlname=$func_relative_path_result/$dlname
11168*44704f69SBart Van Assche	      else
11169*44704f69SBart Van Assche		# Otherwise fall back on heuristic.
11170*44704f69SBart Van Assche		tdlname=../bin/$dlname
11171*44704f69SBart Van Assche	      fi
11172*44704f69SBart Van Assche	      ;;
11173*44704f69SBart Van Assche	  esac
11174*44704f69SBart Van Assche	  $ECHO > $output "\
11175*44704f69SBart Van Assche# $outputname - a libtool library file
11176*44704f69SBart Van Assche# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11177*44704f69SBart Van Assche#
11178*44704f69SBart Van Assche# Please DO NOT delete this file!
11179*44704f69SBart Van Assche# It is necessary for linking the library.
11180*44704f69SBart Van Assche
11181*44704f69SBart Van Assche# The name that we can dlopen(3).
11182*44704f69SBart Van Asschedlname='$tdlname'
11183*44704f69SBart Van Assche
11184*44704f69SBart Van Assche# Names of this library.
11185*44704f69SBart Van Asschelibrary_names='$library_names'
11186*44704f69SBart Van Assche
11187*44704f69SBart Van Assche# The name of the static archive.
11188*44704f69SBart Van Asscheold_library='$old_library'
11189*44704f69SBart Van Assche
11190*44704f69SBart Van Assche# Linker flags that cannot go in dependency_libs.
11191*44704f69SBart Van Asscheinherited_linker_flags='$new_inherited_linker_flags'
11192*44704f69SBart Van Assche
11193*44704f69SBart Van Assche# Libraries that this one depends upon.
11194*44704f69SBart Van Asschedependency_libs='$dependency_libs'
11195*44704f69SBart Van Assche
11196*44704f69SBart Van Assche# Names of additional weak libraries provided by this library
11197*44704f69SBart Van Asscheweak_library_names='$weak_libs'
11198*44704f69SBart Van Assche
11199*44704f69SBart Van Assche# Version information for $libname.
11200*44704f69SBart Van Asschecurrent=$current
11201*44704f69SBart Van Asscheage=$age
11202*44704f69SBart Van Asscherevision=$revision
11203*44704f69SBart Van Assche
11204*44704f69SBart Van Assche# Is this an already installed library?
11205*44704f69SBart Van Asscheinstalled=$installed
11206*44704f69SBart Van Assche
11207*44704f69SBart Van Assche# Should we warn about portability when linking against -modules?
11208*44704f69SBart Van Asscheshouldnotlink=$module
11209*44704f69SBart Van Assche
11210*44704f69SBart Van Assche# Files to dlopen/dlpreopen
11211*44704f69SBart Van Asschedlopen='$dlfiles'
11212*44704f69SBart Van Asschedlpreopen='$dlprefiles'
11213*44704f69SBart Van Assche
11214*44704f69SBart Van Assche# Directory that this library needs to be installed in:
11215*44704f69SBart Van Asschelibdir='$install_libdir'"
11216*44704f69SBart Van Assche	  if test no,yes = "$installed,$need_relink"; then
11217*44704f69SBart Van Assche	    $ECHO >> $output "\
11218*44704f69SBart Van Asscherelink_command=\"$relink_command\""
11219*44704f69SBart Van Assche	  fi
11220*44704f69SBart Van Assche	done
11221*44704f69SBart Van Assche      }
11222*44704f69SBart Van Assche
11223*44704f69SBart Van Assche      # Do a symbolic link so that the libtool archive can be found in
11224*44704f69SBart Van Assche      # LD_LIBRARY_PATH before the program is installed.
11225*44704f69SBart Van Assche      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11226*44704f69SBart Van Assche      ;;
11227*44704f69SBart Van Assche    esac
11228*44704f69SBart Van Assche    exit $EXIT_SUCCESS
11229*44704f69SBart Van Assche}
11230*44704f69SBart Van Assche
11231*44704f69SBart Van Asscheif test link = "$opt_mode" || test relink = "$opt_mode"; then
11232*44704f69SBart Van Assche  func_mode_link ${1+"$@"}
11233*44704f69SBart Van Asschefi
11234*44704f69SBart Van Assche
11235*44704f69SBart Van Assche
11236*44704f69SBart Van Assche# func_mode_uninstall arg...
11237*44704f69SBart Van Asschefunc_mode_uninstall ()
11238*44704f69SBart Van Assche{
11239*44704f69SBart Van Assche    $debug_cmd
11240*44704f69SBart Van Assche
11241*44704f69SBart Van Assche    RM=$nonopt
11242*44704f69SBart Van Assche    files=
11243*44704f69SBart Van Assche    rmforce=false
11244*44704f69SBart Van Assche    exit_status=0
11245*44704f69SBart Van Assche
11246*44704f69SBart Van Assche    # This variable tells wrapper scripts just to set variables rather
11247*44704f69SBart Van Assche    # than running their programs.
11248*44704f69SBart Van Assche    libtool_install_magic=$magic
11249*44704f69SBart Van Assche
11250*44704f69SBart Van Assche    for arg
11251*44704f69SBart Van Assche    do
11252*44704f69SBart Van Assche      case $arg in
11253*44704f69SBart Van Assche      -f) func_append RM " $arg"; rmforce=: ;;
11254*44704f69SBart Van Assche      -*) func_append RM " $arg" ;;
11255*44704f69SBart Van Assche      *) func_append files " $arg" ;;
11256*44704f69SBart Van Assche      esac
11257*44704f69SBart Van Assche    done
11258*44704f69SBart Van Assche
11259*44704f69SBart Van Assche    test -z "$RM" && \
11260*44704f69SBart Van Assche      func_fatal_help "you must specify an RM program"
11261*44704f69SBart Van Assche
11262*44704f69SBart Van Assche    rmdirs=
11263*44704f69SBart Van Assche
11264*44704f69SBart Van Assche    for file in $files; do
11265*44704f69SBart Van Assche      func_dirname "$file" "" "."
11266*44704f69SBart Van Assche      dir=$func_dirname_result
11267*44704f69SBart Van Assche      if test . = "$dir"; then
11268*44704f69SBart Van Assche	odir=$objdir
11269*44704f69SBart Van Assche      else
11270*44704f69SBart Van Assche	odir=$dir/$objdir
11271*44704f69SBart Van Assche      fi
11272*44704f69SBart Van Assche      func_basename "$file"
11273*44704f69SBart Van Assche      name=$func_basename_result
11274*44704f69SBart Van Assche      test uninstall = "$opt_mode" && odir=$dir
11275*44704f69SBart Van Assche
11276*44704f69SBart Van Assche      # Remember odir for removal later, being careful to avoid duplicates
11277*44704f69SBart Van Assche      if test clean = "$opt_mode"; then
11278*44704f69SBart Van Assche	case " $rmdirs " in
11279*44704f69SBart Van Assche	  *" $odir "*) ;;
11280*44704f69SBart Van Assche	  *) func_append rmdirs " $odir" ;;
11281*44704f69SBart Van Assche	esac
11282*44704f69SBart Van Assche      fi
11283*44704f69SBart Van Assche
11284*44704f69SBart Van Assche      # Don't error if the file doesn't exist and rm -f was used.
11285*44704f69SBart Van Assche      if { test -L "$file"; } >/dev/null 2>&1 ||
11286*44704f69SBart Van Assche	 { test -h "$file"; } >/dev/null 2>&1 ||
11287*44704f69SBart Van Assche	 test -f "$file"; then
11288*44704f69SBart Van Assche	:
11289*44704f69SBart Van Assche      elif test -d "$file"; then
11290*44704f69SBart Van Assche	exit_status=1
11291*44704f69SBart Van Assche	continue
11292*44704f69SBart Van Assche      elif $rmforce; then
11293*44704f69SBart Van Assche	continue
11294*44704f69SBart Van Assche      fi
11295*44704f69SBart Van Assche
11296*44704f69SBart Van Assche      rmfiles=$file
11297*44704f69SBart Van Assche
11298*44704f69SBart Van Assche      case $name in
11299*44704f69SBart Van Assche      *.la)
11300*44704f69SBart Van Assche	# Possibly a libtool archive, so verify it.
11301*44704f69SBart Van Assche	if func_lalib_p "$file"; then
11302*44704f69SBart Van Assche	  func_source $dir/$name
11303*44704f69SBart Van Assche
11304*44704f69SBart Van Assche	  # Delete the libtool libraries and symlinks.
11305*44704f69SBart Van Assche	  for n in $library_names; do
11306*44704f69SBart Van Assche	    func_append rmfiles " $odir/$n"
11307*44704f69SBart Van Assche	  done
11308*44704f69SBart Van Assche	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11309*44704f69SBart Van Assche
11310*44704f69SBart Van Assche	  case $opt_mode in
11311*44704f69SBart Van Assche	  clean)
11312*44704f69SBart Van Assche	    case " $library_names " in
11313*44704f69SBart Van Assche	    *" $dlname "*) ;;
11314*44704f69SBart Van Assche	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11315*44704f69SBart Van Assche	    esac
11316*44704f69SBart Van Assche	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11317*44704f69SBart Van Assche	    ;;
11318*44704f69SBart Van Assche	  uninstall)
11319*44704f69SBart Van Assche	    if test -n "$library_names"; then
11320*44704f69SBart Van Assche	      # Do each command in the postuninstall commands.
11321*44704f69SBart Van Assche	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11322*44704f69SBart Van Assche	    fi
11323*44704f69SBart Van Assche
11324*44704f69SBart Van Assche	    if test -n "$old_library"; then
11325*44704f69SBart Van Assche	      # Do each command in the old_postuninstall commands.
11326*44704f69SBart Van Assche	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11327*44704f69SBart Van Assche	    fi
11328*44704f69SBart Van Assche	    # FIXME: should reinstall the best remaining shared library.
11329*44704f69SBart Van Assche	    ;;
11330*44704f69SBart Van Assche	  esac
11331*44704f69SBart Van Assche	fi
11332*44704f69SBart Van Assche	;;
11333*44704f69SBart Van Assche
11334*44704f69SBart Van Assche      *.lo)
11335*44704f69SBart Van Assche	# Possibly a libtool object, so verify it.
11336*44704f69SBart Van Assche	if func_lalib_p "$file"; then
11337*44704f69SBart Van Assche
11338*44704f69SBart Van Assche	  # Read the .lo file
11339*44704f69SBart Van Assche	  func_source $dir/$name
11340*44704f69SBart Van Assche
11341*44704f69SBart Van Assche	  # Add PIC object to the list of files to remove.
11342*44704f69SBart Van Assche	  if test -n "$pic_object" && test none != "$pic_object"; then
11343*44704f69SBart Van Assche	    func_append rmfiles " $dir/$pic_object"
11344*44704f69SBart Van Assche	  fi
11345*44704f69SBart Van Assche
11346*44704f69SBart Van Assche	  # Add non-PIC object to the list of files to remove.
11347*44704f69SBart Van Assche	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11348*44704f69SBart Van Assche	    func_append rmfiles " $dir/$non_pic_object"
11349*44704f69SBart Van Assche	  fi
11350*44704f69SBart Van Assche	fi
11351*44704f69SBart Van Assche	;;
11352*44704f69SBart Van Assche
11353*44704f69SBart Van Assche      *)
11354*44704f69SBart Van Assche	if test clean = "$opt_mode"; then
11355*44704f69SBart Van Assche	  noexename=$name
11356*44704f69SBart Van Assche	  case $file in
11357*44704f69SBart Van Assche	  *.exe)
11358*44704f69SBart Van Assche	    func_stripname '' '.exe' "$file"
11359*44704f69SBart Van Assche	    file=$func_stripname_result
11360*44704f69SBart Van Assche	    func_stripname '' '.exe' "$name"
11361*44704f69SBart Van Assche	    noexename=$func_stripname_result
11362*44704f69SBart Van Assche	    # $file with .exe has already been added to rmfiles,
11363*44704f69SBart Van Assche	    # add $file without .exe
11364*44704f69SBart Van Assche	    func_append rmfiles " $file"
11365*44704f69SBart Van Assche	    ;;
11366*44704f69SBart Van Assche	  esac
11367*44704f69SBart Van Assche	  # Do a test to see if this is a libtool program.
11368*44704f69SBart Van Assche	  if func_ltwrapper_p "$file"; then
11369*44704f69SBart Van Assche	    if func_ltwrapper_executable_p "$file"; then
11370*44704f69SBart Van Assche	      func_ltwrapper_scriptname "$file"
11371*44704f69SBart Van Assche	      relink_command=
11372*44704f69SBart Van Assche	      func_source $func_ltwrapper_scriptname_result
11373*44704f69SBart Van Assche	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11374*44704f69SBart Van Assche	    else
11375*44704f69SBart Van Assche	      relink_command=
11376*44704f69SBart Van Assche	      func_source $dir/$noexename
11377*44704f69SBart Van Assche	    fi
11378*44704f69SBart Van Assche
11379*44704f69SBart Van Assche	    # note $name still contains .exe if it was in $file originally
11380*44704f69SBart Van Assche	    # as does the version of $file that was added into $rmfiles
11381*44704f69SBart Van Assche	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11382*44704f69SBart Van Assche	    if test yes = "$fast_install" && test -n "$relink_command"; then
11383*44704f69SBart Van Assche	      func_append rmfiles " $odir/lt-$name"
11384*44704f69SBart Van Assche	    fi
11385*44704f69SBart Van Assche	    if test "X$noexename" != "X$name"; then
11386*44704f69SBart Van Assche	      func_append rmfiles " $odir/lt-$noexename.c"
11387*44704f69SBart Van Assche	    fi
11388*44704f69SBart Van Assche	  fi
11389*44704f69SBart Van Assche	fi
11390*44704f69SBart Van Assche	;;
11391*44704f69SBart Van Assche      esac
11392*44704f69SBart Van Assche      func_show_eval "$RM $rmfiles" 'exit_status=1'
11393*44704f69SBart Van Assche    done
11394*44704f69SBart Van Assche
11395*44704f69SBart Van Assche    # Try to remove the $objdir's in the directories where we deleted files
11396*44704f69SBart Van Assche    for dir in $rmdirs; do
11397*44704f69SBart Van Assche      if test -d "$dir"; then
11398*44704f69SBart Van Assche	func_show_eval "rmdir $dir >/dev/null 2>&1"
11399*44704f69SBart Van Assche      fi
11400*44704f69SBart Van Assche    done
11401*44704f69SBart Van Assche
11402*44704f69SBart Van Assche    exit $exit_status
11403*44704f69SBart Van Assche}
11404*44704f69SBart Van Assche
11405*44704f69SBart Van Asscheif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11406*44704f69SBart Van Assche  func_mode_uninstall ${1+"$@"}
11407*44704f69SBart Van Asschefi
11408*44704f69SBart Van Assche
11409*44704f69SBart Van Asschetest -z "$opt_mode" && {
11410*44704f69SBart Van Assche  help=$generic_help
11411*44704f69SBart Van Assche  func_fatal_help "you must specify a MODE"
11412*44704f69SBart Van Assche}
11413*44704f69SBart Van Assche
11414*44704f69SBart Van Asschetest -z "$exec_cmd" && \
11415*44704f69SBart Van Assche  func_fatal_help "invalid operation mode '$opt_mode'"
11416*44704f69SBart Van Assche
11417*44704f69SBart Van Asscheif test -n "$exec_cmd"; then
11418*44704f69SBart Van Assche  eval exec "$exec_cmd"
11419*44704f69SBart Van Assche  exit $EXIT_FAILURE
11420*44704f69SBart Van Asschefi
11421*44704f69SBart Van Assche
11422*44704f69SBart Van Asscheexit $exit_status
11423*44704f69SBart Van Assche
11424*44704f69SBart Van Assche
11425*44704f69SBart Van Assche# The TAGs below are defined such that we never get into a situation
11426*44704f69SBart Van Assche# where we disable both kinds of libraries.  Given conflicting
11427*44704f69SBart Van Assche# choices, we go for a static library, that is the most portable,
11428*44704f69SBart Van Assche# since we can't tell whether shared libraries were disabled because
11429*44704f69SBart Van Assche# the user asked for that or because the platform doesn't support
11430*44704f69SBart Van Assche# them.  This is particularly important on AIX, because we don't
11431*44704f69SBart Van Assche# support having both static and shared libraries enabled at the same
11432*44704f69SBart Van Assche# time on that platform, so we default to a shared-only configuration.
11433*44704f69SBart Van Assche# If a disable-shared tag is given, we'll fallback to a static-only
11434*44704f69SBart Van Assche# configuration.  But we'll never go from static-only to shared-only.
11435*44704f69SBart Van Assche
11436*44704f69SBart Van Assche# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11437*44704f69SBart Van Asschebuild_libtool_libs=no
11438*44704f69SBart Van Asschebuild_old_libs=yes
11439*44704f69SBart Van Assche# ### END LIBTOOL TAG CONFIG: disable-shared
11440*44704f69SBart Van Assche
11441*44704f69SBart Van Assche# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11442*44704f69SBart Van Asschebuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11443*44704f69SBart Van Assche# ### END LIBTOOL TAG CONFIG: disable-static
11444*44704f69SBart Van Assche
11445*44704f69SBart Van Assche# Local Variables:
11446*44704f69SBart Van Assche# mode:shell-script
11447*44704f69SBart Van Assche# sh-indentation:2
11448*44704f69SBart Van Assche# End:
11449