xref: /OK3568_Linux_fs/external/xserver/ltmain.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#! /bin/sh
2*4882a593Smuzhiyun## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3*4882a593Smuzhiyun##               by inline-source v2014-01-03.01
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun# libtool (GNU libtool) 2.4.6
6*4882a593Smuzhiyun# Provide generalized library-building support services.
7*4882a593Smuzhiyun# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun# Copyright (C) 1996-2015 Free Software Foundation, Inc.
10*4882a593Smuzhiyun# This is free software; see the source for copying conditions.  There is NO
11*4882a593Smuzhiyun# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun# GNU Libtool is free software; you can redistribute it and/or modify
14*4882a593Smuzhiyun# it under the terms of the GNU General Public License as published by
15*4882a593Smuzhiyun# the Free Software Foundation; either version 2 of the License, or
16*4882a593Smuzhiyun# (at your option) any later version.
17*4882a593Smuzhiyun#
18*4882a593Smuzhiyun# As a special exception to the GNU General Public License,
19*4882a593Smuzhiyun# if you distribute this file as part of a program or library that
20*4882a593Smuzhiyun# is built using GNU Libtool, you may include this file under the
21*4882a593Smuzhiyun# same distribution terms that you use for the rest of that program.
22*4882a593Smuzhiyun#
23*4882a593Smuzhiyun# GNU Libtool is distributed in the hope that it will be useful, but
24*4882a593Smuzhiyun# WITHOUT ANY WARRANTY; without even the implied warranty of
25*4882a593Smuzhiyun# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26*4882a593Smuzhiyun# General Public License for more details.
27*4882a593Smuzhiyun#
28*4882a593Smuzhiyun# You should have received a copy of the GNU General Public License
29*4882a593Smuzhiyun# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun
32*4882a593SmuzhiyunPROGRAM=libtool
33*4882a593SmuzhiyunPACKAGE=libtool
34*4882a593SmuzhiyunVERSION=2.4.6
35*4882a593Smuzhiyunpackage_revision=2.4.6
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun## ------ ##
39*4882a593Smuzhiyun## Usage. ##
40*4882a593Smuzhiyun## ------ ##
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun# Run './libtool --help' for help with using this script from the
43*4882a593Smuzhiyun# command line.
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun## ------------------------------- ##
47*4882a593Smuzhiyun## User overridable command paths. ##
48*4882a593Smuzhiyun## ------------------------------- ##
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun# After configure completes, it has a better idea of some of the
51*4882a593Smuzhiyun# shell tools we need than the defaults used by the functions shared
52*4882a593Smuzhiyun# with bootstrap, so set those here where they can still be over-
53*4882a593Smuzhiyun# ridden by the user, but otherwise take precedence.
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun: ${AUTOCONF="autoconf"}
56*4882a593Smuzhiyun: ${AUTOMAKE="automake"}
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun## -------------------------- ##
60*4882a593Smuzhiyun## Source external libraries. ##
61*4882a593Smuzhiyun## -------------------------- ##
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun# Much of our low-level functionality needs to be sourced from external
64*4882a593Smuzhiyun# libraries, which are installed to $pkgauxdir.
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun# Set a version string for this script.
67*4882a593Smuzhiyunscriptversion=2015-10-04.22; # UTC
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun# General shell script boiler plate, and helper functions.
70*4882a593Smuzhiyun# Written by Gary V. Vaughan, 2004
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun# Copyright (C) 2004-2015 Free Software Foundation, Inc.
73*4882a593Smuzhiyun# This is free software; see the source for copying conditions.  There is NO
74*4882a593Smuzhiyun# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun# This program is free software; you can redistribute it and/or modify
77*4882a593Smuzhiyun# it under the terms of the GNU General Public License as published by
78*4882a593Smuzhiyun# the Free Software Foundation; either version 3 of the License, or
79*4882a593Smuzhiyun# (at your option) any later version.
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun# As a special exception to the GNU General Public License, if you distribute
82*4882a593Smuzhiyun# this file as part of a program or library that is built using GNU Libtool,
83*4882a593Smuzhiyun# you may include this file under the same distribution terms that you use
84*4882a593Smuzhiyun# for the rest of that program.
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun# This program is distributed in the hope that it will be useful,
87*4882a593Smuzhiyun# but WITHOUT ANY WARRANTY; without even the implied warranty of
88*4882a593Smuzhiyun# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
89*4882a593Smuzhiyun# General Public License for more details.
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun# You should have received a copy of the GNU General Public License
92*4882a593Smuzhiyun# along with this program. If not, see <http://www.gnu.org/licenses/>.
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun# Please report bugs or propose patches to gary@gnu.org.
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun## ------ ##
98*4882a593Smuzhiyun## Usage. ##
99*4882a593Smuzhiyun## ------ ##
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun# Evaluate this file near the top of your script to gain access to
102*4882a593Smuzhiyun# the functions and variables defined here:
103*4882a593Smuzhiyun#
104*4882a593Smuzhiyun#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
105*4882a593Smuzhiyun#
106*4882a593Smuzhiyun# If you need to override any of the default environment variable
107*4882a593Smuzhiyun# settings, do that before evaluating this file.
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun## -------------------- ##
111*4882a593Smuzhiyun## Shell normalisation. ##
112*4882a593Smuzhiyun## -------------------- ##
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun# Some shells need a little help to be as Bourne compatible as possible.
115*4882a593Smuzhiyun# Before doing anything else, make sure all that help has been provided!
116*4882a593Smuzhiyun
117*4882a593SmuzhiyunDUALCASE=1; export DUALCASE # for MKS sh
118*4882a593Smuzhiyunif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
119*4882a593Smuzhiyun  emulate sh
120*4882a593Smuzhiyun  NULLCMD=:
121*4882a593Smuzhiyun  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
122*4882a593Smuzhiyun  # is contrary to our usage.  Disable this feature.
123*4882a593Smuzhiyun  alias -g '${1+"$@"}'='"$@"'
124*4882a593Smuzhiyun  setopt NO_GLOB_SUBST
125*4882a593Smuzhiyunelse
126*4882a593Smuzhiyun  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
127*4882a593Smuzhiyunfi
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun# NLS nuisances: We save the old values in case they are required later.
130*4882a593Smuzhiyun_G_user_locale=
131*4882a593Smuzhiyun_G_safe_locale=
132*4882a593Smuzhiyunfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
133*4882a593Smuzhiyundo
134*4882a593Smuzhiyun  eval "if test set = \"\${$_G_var+set}\"; then
135*4882a593Smuzhiyun          save_$_G_var=\$$_G_var
136*4882a593Smuzhiyun          $_G_var=C
137*4882a593Smuzhiyun	  export $_G_var
138*4882a593Smuzhiyun	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
139*4882a593Smuzhiyun	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
140*4882a593Smuzhiyun	fi"
141*4882a593Smuzhiyundone
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun# CDPATH.
144*4882a593Smuzhiyun(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun# Make sure IFS has a sensible default
147*4882a593Smuzhiyunsp=' '
148*4882a593Smuzhiyunnl='
149*4882a593Smuzhiyun'
150*4882a593SmuzhiyunIFS="$sp	$nl"
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun# There are apparently some retarded systems that use ';' as a PATH separator!
153*4882a593Smuzhiyunif test "${PATH_SEPARATOR+set}" != set; then
154*4882a593Smuzhiyun  PATH_SEPARATOR=:
155*4882a593Smuzhiyun  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
156*4882a593Smuzhiyun    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
157*4882a593Smuzhiyun      PATH_SEPARATOR=';'
158*4882a593Smuzhiyun  }
159*4882a593Smuzhiyunfi
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun## ------------------------- ##
164*4882a593Smuzhiyun## Locate command utilities. ##
165*4882a593Smuzhiyun## ------------------------- ##
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun# func_executable_p FILE
169*4882a593Smuzhiyun# ----------------------
170*4882a593Smuzhiyun# Check that FILE is an executable regular file.
171*4882a593Smuzhiyunfunc_executable_p ()
172*4882a593Smuzhiyun{
173*4882a593Smuzhiyun    test -f "$1" && test -x "$1"
174*4882a593Smuzhiyun}
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
178*4882a593Smuzhiyun# --------------------------------------------
179*4882a593Smuzhiyun# Search for either a program that responds to --version with output
180*4882a593Smuzhiyun# containing "GNU", or else returned by CHECK_FUNC otherwise, by
181*4882a593Smuzhiyun# trying all the directories in PATH with each of the elements of
182*4882a593Smuzhiyun# PROGS_LIST.
183*4882a593Smuzhiyun#
184*4882a593Smuzhiyun# CHECK_FUNC should accept the path to a candidate program, and
185*4882a593Smuzhiyun# set $func_check_prog_result if it truncates its output less than
186*4882a593Smuzhiyun# $_G_path_prog_max characters.
187*4882a593Smuzhiyunfunc_path_progs ()
188*4882a593Smuzhiyun{
189*4882a593Smuzhiyun    _G_progs_list=$1
190*4882a593Smuzhiyun    _G_check_func=$2
191*4882a593Smuzhiyun    _G_PATH=${3-"$PATH"}
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun    _G_path_prog_max=0
194*4882a593Smuzhiyun    _G_path_prog_found=false
195*4882a593Smuzhiyun    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
196*4882a593Smuzhiyun    for _G_dir in $_G_PATH; do
197*4882a593Smuzhiyun      IFS=$_G_save_IFS
198*4882a593Smuzhiyun      test -z "$_G_dir" && _G_dir=.
199*4882a593Smuzhiyun      for _G_prog_name in $_G_progs_list; do
200*4882a593Smuzhiyun        for _exeext in '' .EXE; do
201*4882a593Smuzhiyun          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
202*4882a593Smuzhiyun          func_executable_p "$_G_path_prog" || continue
203*4882a593Smuzhiyun          case `"$_G_path_prog" --version 2>&1` in
204*4882a593Smuzhiyun            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
205*4882a593Smuzhiyun            *)     $_G_check_func $_G_path_prog
206*4882a593Smuzhiyun		   func_path_progs_result=$func_check_prog_result
207*4882a593Smuzhiyun		   ;;
208*4882a593Smuzhiyun          esac
209*4882a593Smuzhiyun          $_G_path_prog_found && break 3
210*4882a593Smuzhiyun        done
211*4882a593Smuzhiyun      done
212*4882a593Smuzhiyun    done
213*4882a593Smuzhiyun    IFS=$_G_save_IFS
214*4882a593Smuzhiyun    test -z "$func_path_progs_result" && {
215*4882a593Smuzhiyun      echo "no acceptable sed could be found in \$PATH" >&2
216*4882a593Smuzhiyun      exit 1
217*4882a593Smuzhiyun    }
218*4882a593Smuzhiyun}
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun# We want to be able to use the functions in this file before configure
222*4882a593Smuzhiyun# has figured out where the best binaries are kept, which means we have
223*4882a593Smuzhiyun# to search for them ourselves - except when the results are already set
224*4882a593Smuzhiyun# where we skip the searches.
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun# Unless the user overrides by setting SED, search the path for either GNU
227*4882a593Smuzhiyun# sed, or the sed that truncates its output the least.
228*4882a593Smuzhiyuntest -z "$SED" && {
229*4882a593Smuzhiyun  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
230*4882a593Smuzhiyun  for _G_i in 1 2 3 4 5 6 7; do
231*4882a593Smuzhiyun    _G_sed_script=$_G_sed_script$nl$_G_sed_script
232*4882a593Smuzhiyun  done
233*4882a593Smuzhiyun  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
234*4882a593Smuzhiyun  _G_sed_script=
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun  func_check_prog_sed ()
237*4882a593Smuzhiyun  {
238*4882a593Smuzhiyun    _G_path_prog=$1
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun    _G_count=0
241*4882a593Smuzhiyun    printf 0123456789 >conftest.in
242*4882a593Smuzhiyun    while :
243*4882a593Smuzhiyun    do
244*4882a593Smuzhiyun      cat conftest.in conftest.in >conftest.tmp
245*4882a593Smuzhiyun      mv conftest.tmp conftest.in
246*4882a593Smuzhiyun      cp conftest.in conftest.nl
247*4882a593Smuzhiyun      echo '' >> conftest.nl
248*4882a593Smuzhiyun      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
249*4882a593Smuzhiyun      diff conftest.out conftest.nl >/dev/null 2>&1 || break
250*4882a593Smuzhiyun      _G_count=`expr $_G_count + 1`
251*4882a593Smuzhiyun      if test "$_G_count" -gt "$_G_path_prog_max"; then
252*4882a593Smuzhiyun        # Best one so far, save it but keep looking for a better one
253*4882a593Smuzhiyun        func_check_prog_result=$_G_path_prog
254*4882a593Smuzhiyun        _G_path_prog_max=$_G_count
255*4882a593Smuzhiyun      fi
256*4882a593Smuzhiyun      # 10*(2^10) chars as input seems more than enough
257*4882a593Smuzhiyun      test 10 -lt "$_G_count" && break
258*4882a593Smuzhiyun    done
259*4882a593Smuzhiyun    rm -f conftest.in conftest.tmp conftest.nl conftest.out
260*4882a593Smuzhiyun  }
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
263*4882a593Smuzhiyun  rm -f conftest.sed
264*4882a593Smuzhiyun  SED=$func_path_progs_result
265*4882a593Smuzhiyun}
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun# Unless the user overrides by setting GREP, search the path for either GNU
269*4882a593Smuzhiyun# grep, or the grep that truncates its output the least.
270*4882a593Smuzhiyuntest -z "$GREP" && {
271*4882a593Smuzhiyun  func_check_prog_grep ()
272*4882a593Smuzhiyun  {
273*4882a593Smuzhiyun    _G_path_prog=$1
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun    _G_count=0
276*4882a593Smuzhiyun    _G_path_prog_max=0
277*4882a593Smuzhiyun    printf 0123456789 >conftest.in
278*4882a593Smuzhiyun    while :
279*4882a593Smuzhiyun    do
280*4882a593Smuzhiyun      cat conftest.in conftest.in >conftest.tmp
281*4882a593Smuzhiyun      mv conftest.tmp conftest.in
282*4882a593Smuzhiyun      cp conftest.in conftest.nl
283*4882a593Smuzhiyun      echo 'GREP' >> conftest.nl
284*4882a593Smuzhiyun      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
285*4882a593Smuzhiyun      diff conftest.out conftest.nl >/dev/null 2>&1 || break
286*4882a593Smuzhiyun      _G_count=`expr $_G_count + 1`
287*4882a593Smuzhiyun      if test "$_G_count" -gt "$_G_path_prog_max"; then
288*4882a593Smuzhiyun        # Best one so far, save it but keep looking for a better one
289*4882a593Smuzhiyun        func_check_prog_result=$_G_path_prog
290*4882a593Smuzhiyun        _G_path_prog_max=$_G_count
291*4882a593Smuzhiyun      fi
292*4882a593Smuzhiyun      # 10*(2^10) chars as input seems more than enough
293*4882a593Smuzhiyun      test 10 -lt "$_G_count" && break
294*4882a593Smuzhiyun    done
295*4882a593Smuzhiyun    rm -f conftest.in conftest.tmp conftest.nl conftest.out
296*4882a593Smuzhiyun  }
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
299*4882a593Smuzhiyun  GREP=$func_path_progs_result
300*4882a593Smuzhiyun}
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun## ------------------------------- ##
304*4882a593Smuzhiyun## User overridable command paths. ##
305*4882a593Smuzhiyun## ------------------------------- ##
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun# All uppercase variable names are used for environment variables.  These
308*4882a593Smuzhiyun# variables can be overridden by the user before calling a script that
309*4882a593Smuzhiyun# uses them if a suitable command of that name is not already available
310*4882a593Smuzhiyun# in the command search PATH.
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun: ${CP="cp -f"}
313*4882a593Smuzhiyun: ${ECHO="printf %s\n"}
314*4882a593Smuzhiyun: ${EGREP="$GREP -E"}
315*4882a593Smuzhiyun: ${FGREP="$GREP -F"}
316*4882a593Smuzhiyun: ${LN_S="ln -s"}
317*4882a593Smuzhiyun: ${MAKE="make"}
318*4882a593Smuzhiyun: ${MKDIR="mkdir"}
319*4882a593Smuzhiyun: ${MV="mv -f"}
320*4882a593Smuzhiyun: ${RM="rm -f"}
321*4882a593Smuzhiyun: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun## -------------------- ##
325*4882a593Smuzhiyun## Useful sed snippets. ##
326*4882a593Smuzhiyun## -------------------- ##
327*4882a593Smuzhiyun
328*4882a593Smuzhiyunsed_dirname='s|/[^/]*$||'
329*4882a593Smuzhiyunsed_basename='s|^.*/||'
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun# Sed substitution that helps us do robust quoting.  It backslashifies
332*4882a593Smuzhiyun# metacharacters that are still active within double-quoted strings.
333*4882a593Smuzhiyunsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun# Same as above, but do not quote variable references.
336*4882a593Smuzhiyunsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun# Sed substitution that turns a string into a regex matching for the
339*4882a593Smuzhiyun# string literally.
340*4882a593Smuzhiyunsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun# Sed substitution that converts a w32 file name or path
343*4882a593Smuzhiyun# that contains forward slashes, into one that contains
344*4882a593Smuzhiyun# (escaped) backslashes.  A very naive implementation.
345*4882a593Smuzhiyunsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun# Re-'\' parameter expansions in output of sed_double_quote_subst that
348*4882a593Smuzhiyun# were '\'-ed in input to the same.  If an odd number of '\' preceded a
349*4882a593Smuzhiyun# '$' in input to sed_double_quote_subst, that '$' was protected from
350*4882a593Smuzhiyun# expansion.  Since each input '\' is now two '\'s, look for any number
351*4882a593Smuzhiyun# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
352*4882a593Smuzhiyun_G_bs='\\'
353*4882a593Smuzhiyun_G_bs2='\\\\'
354*4882a593Smuzhiyun_G_bs4='\\\\\\\\'
355*4882a593Smuzhiyun_G_dollar='\$'
356*4882a593Smuzhiyunsed_double_backslash="\
357*4882a593Smuzhiyun  s/$_G_bs4/&\\
358*4882a593Smuzhiyun/g
359*4882a593Smuzhiyun  s/^$_G_bs2$_G_dollar/$_G_bs&/
360*4882a593Smuzhiyun  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
361*4882a593Smuzhiyun  s/\n//g"
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun## ----------------- ##
365*4882a593Smuzhiyun## Global variables. ##
366*4882a593Smuzhiyun## ----------------- ##
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun# Except for the global variables explicitly listed below, the following
369*4882a593Smuzhiyun# functions in the '^func_' namespace, and the '^require_' namespace
370*4882a593Smuzhiyun# variables initialised in the 'Resource management' section, sourcing
371*4882a593Smuzhiyun# this file will not pollute your global namespace with anything
372*4882a593Smuzhiyun# else. There's no portable way to scope variables in Bourne shell
373*4882a593Smuzhiyun# though, so actually running these functions will sometimes place
374*4882a593Smuzhiyun# results into a variable named after the function, and often use
375*4882a593Smuzhiyun# temporary variables in the '^_G_' namespace. If you are careful to
376*4882a593Smuzhiyun# avoid using those namespaces casually in your sourcing script, things
377*4882a593Smuzhiyun# should continue to work as you expect. And, of course, you can freely
378*4882a593Smuzhiyun# overwrite any of the functions or variables defined here before
379*4882a593Smuzhiyun# calling anything to customize them.
380*4882a593Smuzhiyun
381*4882a593SmuzhiyunEXIT_SUCCESS=0
382*4882a593SmuzhiyunEXIT_FAILURE=1
383*4882a593SmuzhiyunEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
384*4882a593SmuzhiyunEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun# Allow overriding, eg assuming that you follow the convention of
387*4882a593Smuzhiyun# putting '$debug_cmd' at the start of all your functions, you can get
388*4882a593Smuzhiyun# bash to show function call trace with:
389*4882a593Smuzhiyun#
390*4882a593Smuzhiyun#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
391*4882a593Smuzhiyundebug_cmd=${debug_cmd-":"}
392*4882a593Smuzhiyunexit_cmd=:
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun# By convention, finish your script with:
395*4882a593Smuzhiyun#
396*4882a593Smuzhiyun#    exit $exit_status
397*4882a593Smuzhiyun#
398*4882a593Smuzhiyun# so that you can set exit_status to non-zero if you want to indicate
399*4882a593Smuzhiyun# something went wrong during execution without actually bailing out at
400*4882a593Smuzhiyun# the point of failure.
401*4882a593Smuzhiyunexit_status=$EXIT_SUCCESS
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
404*4882a593Smuzhiyun# is ksh but when the shell is invoked as "sh" and the current value of
405*4882a593Smuzhiyun# the _XPG environment variable is not equal to 1 (one), the special
406*4882a593Smuzhiyun# positional parameter $0, within a function call, is the name of the
407*4882a593Smuzhiyun# function.
408*4882a593Smuzhiyunprogpath=$0
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun# The name of this program.
411*4882a593Smuzhiyunprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun# Make sure we have an absolute progpath for reexecution:
414*4882a593Smuzhiyuncase $progpath in
415*4882a593Smuzhiyun  [\\/]*|[A-Za-z]:\\*) ;;
416*4882a593Smuzhiyun  *[\\/]*)
417*4882a593Smuzhiyun     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
418*4882a593Smuzhiyun     progdir=`cd "$progdir" && pwd`
419*4882a593Smuzhiyun     progpath=$progdir/$progname
420*4882a593Smuzhiyun     ;;
421*4882a593Smuzhiyun  *)
422*4882a593Smuzhiyun     _G_IFS=$IFS
423*4882a593Smuzhiyun     IFS=${PATH_SEPARATOR-:}
424*4882a593Smuzhiyun     for progdir in $PATH; do
425*4882a593Smuzhiyun       IFS=$_G_IFS
426*4882a593Smuzhiyun       test -x "$progdir/$progname" && break
427*4882a593Smuzhiyun     done
428*4882a593Smuzhiyun     IFS=$_G_IFS
429*4882a593Smuzhiyun     test -n "$progdir" || progdir=`pwd`
430*4882a593Smuzhiyun     progpath=$progdir/$progname
431*4882a593Smuzhiyun     ;;
432*4882a593Smuzhiyunesac
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun## ----------------- ##
436*4882a593Smuzhiyun## Standard options. ##
437*4882a593Smuzhiyun## ----------------- ##
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun# The following options affect the operation of the functions defined
440*4882a593Smuzhiyun# below, and should be set appropriately depending on run-time para-
441*4882a593Smuzhiyun# meters passed on the command line.
442*4882a593Smuzhiyun
443*4882a593Smuzhiyunopt_dry_run=false
444*4882a593Smuzhiyunopt_quiet=false
445*4882a593Smuzhiyunopt_verbose=false
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun# Categories 'all' and 'none' are always available.  Append any others
448*4882a593Smuzhiyun# you will pass as the first argument to func_warning from your own
449*4882a593Smuzhiyun# code.
450*4882a593Smuzhiyunwarning_categories=
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun# By default, display warnings according to 'opt_warning_types'.  Set
453*4882a593Smuzhiyun# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
454*4882a593Smuzhiyun# treat the next displayed warning as a fatal error.
455*4882a593Smuzhiyunwarning_func=func_warn_and_continue
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun# Set to 'all' to display all warnings, 'none' to suppress all
458*4882a593Smuzhiyun# warnings, or a space delimited list of some subset of
459*4882a593Smuzhiyun# 'warning_categories' to display only the listed warnings.
460*4882a593Smuzhiyunopt_warning_types=all
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun## -------------------- ##
464*4882a593Smuzhiyun## Resource management. ##
465*4882a593Smuzhiyun## -------------------- ##
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun# This section contains definitions for functions that each ensure a
468*4882a593Smuzhiyun# particular resource (a file, or a non-empty configuration variable for
469*4882a593Smuzhiyun# example) is available, and if appropriate to extract default values
470*4882a593Smuzhiyun# from pertinent package files. Call them using their associated
471*4882a593Smuzhiyun# 'require_*' variable to ensure that they are executed, at most, once.
472*4882a593Smuzhiyun#
473*4882a593Smuzhiyun# It's entirely deliberate that calling these functions can set
474*4882a593Smuzhiyun# variables that don't obey the namespace limitations obeyed by the rest
475*4882a593Smuzhiyun# of this file, in order that that they be as useful as possible to
476*4882a593Smuzhiyun# callers.
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun# require_term_colors
480*4882a593Smuzhiyun# -------------------
481*4882a593Smuzhiyun# Allow display of bold text on terminals that support it.
482*4882a593Smuzhiyunrequire_term_colors=func_require_term_colors
483*4882a593Smuzhiyunfunc_require_term_colors ()
484*4882a593Smuzhiyun{
485*4882a593Smuzhiyun    $debug_cmd
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun    test -t 1 && {
488*4882a593Smuzhiyun      # COLORTERM and USE_ANSI_COLORS environment variables take
489*4882a593Smuzhiyun      # precedence, because most terminfo databases neglect to describe
490*4882a593Smuzhiyun      # whether color sequences are supported.
491*4882a593Smuzhiyun      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun      if test 1 = "$USE_ANSI_COLORS"; then
494*4882a593Smuzhiyun        # Standard ANSI escape sequences
495*4882a593Smuzhiyun        tc_reset=''
496*4882a593Smuzhiyun        tc_bold='';   tc_standout=''
497*4882a593Smuzhiyun        tc_red='';   tc_green=''
498*4882a593Smuzhiyun        tc_blue='';  tc_cyan=''
499*4882a593Smuzhiyun      else
500*4882a593Smuzhiyun        # Otherwise trust the terminfo database after all.
501*4882a593Smuzhiyun        test -n "`tput sgr0 2>/dev/null`" && {
502*4882a593Smuzhiyun          tc_reset=`tput sgr0`
503*4882a593Smuzhiyun          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
504*4882a593Smuzhiyun          tc_standout=$tc_bold
505*4882a593Smuzhiyun          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
506*4882a593Smuzhiyun          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
507*4882a593Smuzhiyun          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
508*4882a593Smuzhiyun          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
509*4882a593Smuzhiyun          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
510*4882a593Smuzhiyun        }
511*4882a593Smuzhiyun      fi
512*4882a593Smuzhiyun    }
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun    require_term_colors=:
515*4882a593Smuzhiyun}
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun## ----------------- ##
519*4882a593Smuzhiyun## Function library. ##
520*4882a593Smuzhiyun## ----------------- ##
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun# This section contains a variety of useful functions to call in your
523*4882a593Smuzhiyun# scripts. Take note of the portable wrappers for features provided by
524*4882a593Smuzhiyun# some modern shells, which will fall back to slower equivalents on
525*4882a593Smuzhiyun# less featureful shells.
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun# func_append VAR VALUE
529*4882a593Smuzhiyun# ---------------------
530*4882a593Smuzhiyun# Append VALUE onto the existing contents of VAR.
531*4882a593Smuzhiyun
532*4882a593Smuzhiyun  # We should try to minimise forks, especially on Windows where they are
533*4882a593Smuzhiyun  # unreasonably slow, so skip the feature probes when bash or zsh are
534*4882a593Smuzhiyun  # being used:
535*4882a593Smuzhiyun  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
536*4882a593Smuzhiyun    : ${_G_HAVE_ARITH_OP="yes"}
537*4882a593Smuzhiyun    : ${_G_HAVE_XSI_OPS="yes"}
538*4882a593Smuzhiyun    # The += operator was introduced in bash 3.1
539*4882a593Smuzhiyun    case $BASH_VERSION in
540*4882a593Smuzhiyun      [12].* | 3.0 | 3.0*) ;;
541*4882a593Smuzhiyun      *)
542*4882a593Smuzhiyun        : ${_G_HAVE_PLUSEQ_OP="yes"}
543*4882a593Smuzhiyun        ;;
544*4882a593Smuzhiyun    esac
545*4882a593Smuzhiyun  fi
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun  # _G_HAVE_PLUSEQ_OP
548*4882a593Smuzhiyun  # Can be empty, in which case the shell is probed, "yes" if += is
549*4882a593Smuzhiyun  # useable or anything else if it does not work.
550*4882a593Smuzhiyun  test -z "$_G_HAVE_PLUSEQ_OP" \
551*4882a593Smuzhiyun    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
552*4882a593Smuzhiyun    && _G_HAVE_PLUSEQ_OP=yes
553*4882a593Smuzhiyun
554*4882a593Smuzhiyunif test yes = "$_G_HAVE_PLUSEQ_OP"
555*4882a593Smuzhiyunthen
556*4882a593Smuzhiyun  # This is an XSI compatible shell, allowing a faster implementation...
557*4882a593Smuzhiyun  eval 'func_append ()
558*4882a593Smuzhiyun  {
559*4882a593Smuzhiyun    $debug_cmd
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun    eval "$1+=\$2"
562*4882a593Smuzhiyun  }'
563*4882a593Smuzhiyunelse
564*4882a593Smuzhiyun  # ...otherwise fall back to using expr, which is often a shell builtin.
565*4882a593Smuzhiyun  func_append ()
566*4882a593Smuzhiyun  {
567*4882a593Smuzhiyun    $debug_cmd
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun    eval "$1=\$$1\$2"
570*4882a593Smuzhiyun  }
571*4882a593Smuzhiyunfi
572*4882a593Smuzhiyun
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun# func_append_quoted VAR VALUE
575*4882a593Smuzhiyun# ----------------------------
576*4882a593Smuzhiyun# Quote VALUE and append to the end of shell variable VAR, separated
577*4882a593Smuzhiyun# by a space.
578*4882a593Smuzhiyunif test yes = "$_G_HAVE_PLUSEQ_OP"; then
579*4882a593Smuzhiyun  eval 'func_append_quoted ()
580*4882a593Smuzhiyun  {
581*4882a593Smuzhiyun    $debug_cmd
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun    func_quote_for_eval "$2"
584*4882a593Smuzhiyun    eval "$1+=\\ \$func_quote_for_eval_result"
585*4882a593Smuzhiyun  }'
586*4882a593Smuzhiyunelse
587*4882a593Smuzhiyun  func_append_quoted ()
588*4882a593Smuzhiyun  {
589*4882a593Smuzhiyun    $debug_cmd
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun    func_quote_for_eval "$2"
592*4882a593Smuzhiyun    eval "$1=\$$1\\ \$func_quote_for_eval_result"
593*4882a593Smuzhiyun  }
594*4882a593Smuzhiyunfi
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun# func_append_uniq VAR VALUE
598*4882a593Smuzhiyun# --------------------------
599*4882a593Smuzhiyun# Append unique VALUE onto the existing contents of VAR, assuming
600*4882a593Smuzhiyun# entries are delimited by the first character of VALUE.  For example:
601*4882a593Smuzhiyun#
602*4882a593Smuzhiyun#   func_append_uniq options " --another-option option-argument"
603*4882a593Smuzhiyun#
604*4882a593Smuzhiyun# will only append to $options if " --another-option option-argument "
605*4882a593Smuzhiyun# is not already present somewhere in $options already (note spaces at
606*4882a593Smuzhiyun# each end implied by leading space in second argument).
607*4882a593Smuzhiyunfunc_append_uniq ()
608*4882a593Smuzhiyun{
609*4882a593Smuzhiyun    $debug_cmd
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun    eval _G_current_value='`$ECHO $'$1'`'
612*4882a593Smuzhiyun    _G_delim=`expr "$2" : '\(.\)'`
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun    case $_G_delim$_G_current_value$_G_delim in
615*4882a593Smuzhiyun      *"$2$_G_delim"*) ;;
616*4882a593Smuzhiyun      *) func_append "$@" ;;
617*4882a593Smuzhiyun    esac
618*4882a593Smuzhiyun}
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun# func_arith TERM...
622*4882a593Smuzhiyun# ------------------
623*4882a593Smuzhiyun# Set func_arith_result to the result of evaluating TERMs.
624*4882a593Smuzhiyun  test -z "$_G_HAVE_ARITH_OP" \
625*4882a593Smuzhiyun    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
626*4882a593Smuzhiyun    && _G_HAVE_ARITH_OP=yes
627*4882a593Smuzhiyun
628*4882a593Smuzhiyunif test yes = "$_G_HAVE_ARITH_OP"; then
629*4882a593Smuzhiyun  eval 'func_arith ()
630*4882a593Smuzhiyun  {
631*4882a593Smuzhiyun    $debug_cmd
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun    func_arith_result=$(( $* ))
634*4882a593Smuzhiyun  }'
635*4882a593Smuzhiyunelse
636*4882a593Smuzhiyun  func_arith ()
637*4882a593Smuzhiyun  {
638*4882a593Smuzhiyun    $debug_cmd
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun    func_arith_result=`expr "$@"`
641*4882a593Smuzhiyun  }
642*4882a593Smuzhiyunfi
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun# func_basename FILE
646*4882a593Smuzhiyun# ------------------
647*4882a593Smuzhiyun# Set func_basename_result to FILE with everything up to and including
648*4882a593Smuzhiyun# the last / stripped.
649*4882a593Smuzhiyunif test yes = "$_G_HAVE_XSI_OPS"; then
650*4882a593Smuzhiyun  # If this shell supports suffix pattern removal, then use it to avoid
651*4882a593Smuzhiyun  # forking. Hide the definitions single quotes in case the shell chokes
652*4882a593Smuzhiyun  # on unsupported syntax...
653*4882a593Smuzhiyun  _b='func_basename_result=${1##*/}'
654*4882a593Smuzhiyun  _d='case $1 in
655*4882a593Smuzhiyun        */*) func_dirname_result=${1%/*}$2 ;;
656*4882a593Smuzhiyun        *  ) func_dirname_result=$3        ;;
657*4882a593Smuzhiyun      esac'
658*4882a593Smuzhiyun
659*4882a593Smuzhiyunelse
660*4882a593Smuzhiyun  # ...otherwise fall back to using sed.
661*4882a593Smuzhiyun  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
662*4882a593Smuzhiyun  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
663*4882a593Smuzhiyun      if test "X$func_dirname_result" = "X$1"; then
664*4882a593Smuzhiyun        func_dirname_result=$3
665*4882a593Smuzhiyun      else
666*4882a593Smuzhiyun        func_append func_dirname_result "$2"
667*4882a593Smuzhiyun      fi'
668*4882a593Smuzhiyunfi
669*4882a593Smuzhiyun
670*4882a593Smuzhiyuneval 'func_basename ()
671*4882a593Smuzhiyun{
672*4882a593Smuzhiyun    $debug_cmd
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun    '"$_b"'
675*4882a593Smuzhiyun}'
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun# func_dirname FILE APPEND NONDIR_REPLACEMENT
679*4882a593Smuzhiyun# -------------------------------------------
680*4882a593Smuzhiyun# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
681*4882a593Smuzhiyun# otherwise set result to NONDIR_REPLACEMENT.
682*4882a593Smuzhiyuneval 'func_dirname ()
683*4882a593Smuzhiyun{
684*4882a593Smuzhiyun    $debug_cmd
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun    '"$_d"'
687*4882a593Smuzhiyun}'
688*4882a593Smuzhiyun
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
691*4882a593Smuzhiyun# --------------------------------------------------------
692*4882a593Smuzhiyun# Perform func_basename and func_dirname in a single function
693*4882a593Smuzhiyun# call:
694*4882a593Smuzhiyun#   dirname:  Compute the dirname of FILE.  If nonempty,
695*4882a593Smuzhiyun#             add APPEND to the result, otherwise set result
696*4882a593Smuzhiyun#             to NONDIR_REPLACEMENT.
697*4882a593Smuzhiyun#             value returned in "$func_dirname_result"
698*4882a593Smuzhiyun#   basename: Compute filename of FILE.
699*4882a593Smuzhiyun#             value retuned in "$func_basename_result"
700*4882a593Smuzhiyun# For efficiency, we do not delegate to the functions above but instead
701*4882a593Smuzhiyun# duplicate the functionality here.
702*4882a593Smuzhiyuneval 'func_dirname_and_basename ()
703*4882a593Smuzhiyun{
704*4882a593Smuzhiyun    $debug_cmd
705*4882a593Smuzhiyun
706*4882a593Smuzhiyun    '"$_b"'
707*4882a593Smuzhiyun    '"$_d"'
708*4882a593Smuzhiyun}'
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun
711*4882a593Smuzhiyun# func_echo ARG...
712*4882a593Smuzhiyun# ----------------
713*4882a593Smuzhiyun# Echo program name prefixed message.
714*4882a593Smuzhiyunfunc_echo ()
715*4882a593Smuzhiyun{
716*4882a593Smuzhiyun    $debug_cmd
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun    _G_message=$*
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun    func_echo_IFS=$IFS
721*4882a593Smuzhiyun    IFS=$nl
722*4882a593Smuzhiyun    for _G_line in $_G_message; do
723*4882a593Smuzhiyun      IFS=$func_echo_IFS
724*4882a593Smuzhiyun      $ECHO "$progname: $_G_line"
725*4882a593Smuzhiyun    done
726*4882a593Smuzhiyun    IFS=$func_echo_IFS
727*4882a593Smuzhiyun}
728*4882a593Smuzhiyun
729*4882a593Smuzhiyun
730*4882a593Smuzhiyun# func_echo_all ARG...
731*4882a593Smuzhiyun# --------------------
732*4882a593Smuzhiyun# Invoke $ECHO with all args, space-separated.
733*4882a593Smuzhiyunfunc_echo_all ()
734*4882a593Smuzhiyun{
735*4882a593Smuzhiyun    $ECHO "$*"
736*4882a593Smuzhiyun}
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun# func_echo_infix_1 INFIX ARG...
740*4882a593Smuzhiyun# ------------------------------
741*4882a593Smuzhiyun# Echo program name, followed by INFIX on the first line, with any
742*4882a593Smuzhiyun# additional lines not showing INFIX.
743*4882a593Smuzhiyunfunc_echo_infix_1 ()
744*4882a593Smuzhiyun{
745*4882a593Smuzhiyun    $debug_cmd
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun    $require_term_colors
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun    _G_infix=$1; shift
750*4882a593Smuzhiyun    _G_indent=$_G_infix
751*4882a593Smuzhiyun    _G_prefix="$progname: $_G_infix: "
752*4882a593Smuzhiyun    _G_message=$*
753*4882a593Smuzhiyun
754*4882a593Smuzhiyun    # Strip color escape sequences before counting printable length
755*4882a593Smuzhiyun    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
756*4882a593Smuzhiyun    do
757*4882a593Smuzhiyun      test -n "$_G_tc" && {
758*4882a593Smuzhiyun        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
759*4882a593Smuzhiyun        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
760*4882a593Smuzhiyun      }
761*4882a593Smuzhiyun    done
762*4882a593Smuzhiyun    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun    func_echo_infix_1_IFS=$IFS
765*4882a593Smuzhiyun    IFS=$nl
766*4882a593Smuzhiyun    for _G_line in $_G_message; do
767*4882a593Smuzhiyun      IFS=$func_echo_infix_1_IFS
768*4882a593Smuzhiyun      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
769*4882a593Smuzhiyun      _G_prefix=$_G_indent
770*4882a593Smuzhiyun    done
771*4882a593Smuzhiyun    IFS=$func_echo_infix_1_IFS
772*4882a593Smuzhiyun}
773*4882a593Smuzhiyun
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun# func_error ARG...
776*4882a593Smuzhiyun# -----------------
777*4882a593Smuzhiyun# Echo program name prefixed message to standard error.
778*4882a593Smuzhiyunfunc_error ()
779*4882a593Smuzhiyun{
780*4882a593Smuzhiyun    $debug_cmd
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun    $require_term_colors
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
785*4882a593Smuzhiyun}
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun# func_fatal_error ARG...
789*4882a593Smuzhiyun# -----------------------
790*4882a593Smuzhiyun# Echo program name prefixed message to standard error, and exit.
791*4882a593Smuzhiyunfunc_fatal_error ()
792*4882a593Smuzhiyun{
793*4882a593Smuzhiyun    $debug_cmd
794*4882a593Smuzhiyun
795*4882a593Smuzhiyun    func_error "$*"
796*4882a593Smuzhiyun    exit $EXIT_FAILURE
797*4882a593Smuzhiyun}
798*4882a593Smuzhiyun
799*4882a593Smuzhiyun
800*4882a593Smuzhiyun# func_grep EXPRESSION FILENAME
801*4882a593Smuzhiyun# -----------------------------
802*4882a593Smuzhiyun# Check whether EXPRESSION matches any line of FILENAME, without output.
803*4882a593Smuzhiyunfunc_grep ()
804*4882a593Smuzhiyun{
805*4882a593Smuzhiyun    $debug_cmd
806*4882a593Smuzhiyun
807*4882a593Smuzhiyun    $GREP "$1" "$2" >/dev/null 2>&1
808*4882a593Smuzhiyun}
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun# func_len STRING
812*4882a593Smuzhiyun# ---------------
813*4882a593Smuzhiyun# Set func_len_result to the length of STRING. STRING may not
814*4882a593Smuzhiyun# start with a hyphen.
815*4882a593Smuzhiyun  test -z "$_G_HAVE_XSI_OPS" \
816*4882a593Smuzhiyun    && (eval 'x=a/b/c;
817*4882a593Smuzhiyun      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
818*4882a593Smuzhiyun    && _G_HAVE_XSI_OPS=yes
819*4882a593Smuzhiyun
820*4882a593Smuzhiyunif test yes = "$_G_HAVE_XSI_OPS"; then
821*4882a593Smuzhiyun  eval 'func_len ()
822*4882a593Smuzhiyun  {
823*4882a593Smuzhiyun    $debug_cmd
824*4882a593Smuzhiyun
825*4882a593Smuzhiyun    func_len_result=${#1}
826*4882a593Smuzhiyun  }'
827*4882a593Smuzhiyunelse
828*4882a593Smuzhiyun  func_len ()
829*4882a593Smuzhiyun  {
830*4882a593Smuzhiyun    $debug_cmd
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
833*4882a593Smuzhiyun  }
834*4882a593Smuzhiyunfi
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun
837*4882a593Smuzhiyun# func_mkdir_p DIRECTORY-PATH
838*4882a593Smuzhiyun# ---------------------------
839*4882a593Smuzhiyun# Make sure the entire path to DIRECTORY-PATH is available.
840*4882a593Smuzhiyunfunc_mkdir_p ()
841*4882a593Smuzhiyun{
842*4882a593Smuzhiyun    $debug_cmd
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun    _G_directory_path=$1
845*4882a593Smuzhiyun    _G_dir_list=
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun      # Protect directory names starting with '-'
850*4882a593Smuzhiyun      case $_G_directory_path in
851*4882a593Smuzhiyun        -*) _G_directory_path=./$_G_directory_path ;;
852*4882a593Smuzhiyun      esac
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun      # While some portion of DIR does not yet exist...
855*4882a593Smuzhiyun      while test ! -d "$_G_directory_path"; do
856*4882a593Smuzhiyun        # ...make a list in topmost first order.  Use a colon delimited
857*4882a593Smuzhiyun	# list incase some portion of path contains whitespace.
858*4882a593Smuzhiyun        _G_dir_list=$_G_directory_path:$_G_dir_list
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun        # If the last portion added has no slash in it, the list is done
861*4882a593Smuzhiyun        case $_G_directory_path in */*) ;; *) break ;; esac
862*4882a593Smuzhiyun
863*4882a593Smuzhiyun        # ...otherwise throw away the child directory and loop
864*4882a593Smuzhiyun        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
865*4882a593Smuzhiyun      done
866*4882a593Smuzhiyun      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
867*4882a593Smuzhiyun
868*4882a593Smuzhiyun      func_mkdir_p_IFS=$IFS; IFS=:
869*4882a593Smuzhiyun      for _G_dir in $_G_dir_list; do
870*4882a593Smuzhiyun	IFS=$func_mkdir_p_IFS
871*4882a593Smuzhiyun        # mkdir can fail with a 'File exist' error if two processes
872*4882a593Smuzhiyun        # try to create one of the directories concurrently.  Don't
873*4882a593Smuzhiyun        # stop in that case!
874*4882a593Smuzhiyun        $MKDIR "$_G_dir" 2>/dev/null || :
875*4882a593Smuzhiyun      done
876*4882a593Smuzhiyun      IFS=$func_mkdir_p_IFS
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun      # Bail out if we (or some other process) failed to create a directory.
879*4882a593Smuzhiyun      test -d "$_G_directory_path" || \
880*4882a593Smuzhiyun        func_fatal_error "Failed to create '$1'"
881*4882a593Smuzhiyun    fi
882*4882a593Smuzhiyun}
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun
885*4882a593Smuzhiyun# func_mktempdir [BASENAME]
886*4882a593Smuzhiyun# -------------------------
887*4882a593Smuzhiyun# Make a temporary directory that won't clash with other running
888*4882a593Smuzhiyun# libtool processes, and avoids race conditions if possible.  If
889*4882a593Smuzhiyun# given, BASENAME is the basename for that directory.
890*4882a593Smuzhiyunfunc_mktempdir ()
891*4882a593Smuzhiyun{
892*4882a593Smuzhiyun    $debug_cmd
893*4882a593Smuzhiyun
894*4882a593Smuzhiyun    _G_template=${TMPDIR-/tmp}/${1-$progname}
895*4882a593Smuzhiyun
896*4882a593Smuzhiyun    if test : = "$opt_dry_run"; then
897*4882a593Smuzhiyun      # Return a directory name, but don't create it in dry-run mode
898*4882a593Smuzhiyun      _G_tmpdir=$_G_template-$$
899*4882a593Smuzhiyun    else
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun      # If mktemp works, use that first and foremost
902*4882a593Smuzhiyun      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun      if test ! -d "$_G_tmpdir"; then
905*4882a593Smuzhiyun        # Failing that, at least try and use $RANDOM to avoid a race
906*4882a593Smuzhiyun        _G_tmpdir=$_G_template-${RANDOM-0}$$
907*4882a593Smuzhiyun
908*4882a593Smuzhiyun        func_mktempdir_umask=`umask`
909*4882a593Smuzhiyun        umask 0077
910*4882a593Smuzhiyun        $MKDIR "$_G_tmpdir"
911*4882a593Smuzhiyun        umask $func_mktempdir_umask
912*4882a593Smuzhiyun      fi
913*4882a593Smuzhiyun
914*4882a593Smuzhiyun      # If we're not in dry-run mode, bomb out on failure
915*4882a593Smuzhiyun      test -d "$_G_tmpdir" || \
916*4882a593Smuzhiyun        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
917*4882a593Smuzhiyun    fi
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun    $ECHO "$_G_tmpdir"
920*4882a593Smuzhiyun}
921*4882a593Smuzhiyun
922*4882a593Smuzhiyun
923*4882a593Smuzhiyun# func_normal_abspath PATH
924*4882a593Smuzhiyun# ------------------------
925*4882a593Smuzhiyun# Remove doubled-up and trailing slashes, "." path components,
926*4882a593Smuzhiyun# and cancel out any ".." path components in PATH after making
927*4882a593Smuzhiyun# it an absolute path.
928*4882a593Smuzhiyunfunc_normal_abspath ()
929*4882a593Smuzhiyun{
930*4882a593Smuzhiyun    $debug_cmd
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun    # These SED scripts presuppose an absolute path with a trailing slash.
933*4882a593Smuzhiyun    _G_pathcar='s|^/\([^/]*\).*$|\1|'
934*4882a593Smuzhiyun    _G_pathcdr='s|^/[^/]*||'
935*4882a593Smuzhiyun    _G_removedotparts=':dotsl
936*4882a593Smuzhiyun		s|/\./|/|g
937*4882a593Smuzhiyun		t dotsl
938*4882a593Smuzhiyun		s|/\.$|/|'
939*4882a593Smuzhiyun    _G_collapseslashes='s|/\{1,\}|/|g'
940*4882a593Smuzhiyun    _G_finalslash='s|/*$|/|'
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun    # Start from root dir and reassemble the path.
943*4882a593Smuzhiyun    func_normal_abspath_result=
944*4882a593Smuzhiyun    func_normal_abspath_tpath=$1
945*4882a593Smuzhiyun    func_normal_abspath_altnamespace=
946*4882a593Smuzhiyun    case $func_normal_abspath_tpath in
947*4882a593Smuzhiyun      "")
948*4882a593Smuzhiyun        # Empty path, that just means $cwd.
949*4882a593Smuzhiyun        func_stripname '' '/' "`pwd`"
950*4882a593Smuzhiyun        func_normal_abspath_result=$func_stripname_result
951*4882a593Smuzhiyun        return
952*4882a593Smuzhiyun        ;;
953*4882a593Smuzhiyun      # The next three entries are used to spot a run of precisely
954*4882a593Smuzhiyun      # two leading slashes without using negated character classes;
955*4882a593Smuzhiyun      # we take advantage of case's first-match behaviour.
956*4882a593Smuzhiyun      ///*)
957*4882a593Smuzhiyun        # Unusual form of absolute path, do nothing.
958*4882a593Smuzhiyun        ;;
959*4882a593Smuzhiyun      //*)
960*4882a593Smuzhiyun        # Not necessarily an ordinary path; POSIX reserves leading '//'
961*4882a593Smuzhiyun        # and for example Cygwin uses it to access remote file shares
962*4882a593Smuzhiyun        # over CIFS/SMB, so we conserve a leading double slash if found.
963*4882a593Smuzhiyun        func_normal_abspath_altnamespace=/
964*4882a593Smuzhiyun        ;;
965*4882a593Smuzhiyun      /*)
966*4882a593Smuzhiyun        # Absolute path, do nothing.
967*4882a593Smuzhiyun        ;;
968*4882a593Smuzhiyun      *)
969*4882a593Smuzhiyun        # Relative path, prepend $cwd.
970*4882a593Smuzhiyun        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
971*4882a593Smuzhiyun        ;;
972*4882a593Smuzhiyun    esac
973*4882a593Smuzhiyun
974*4882a593Smuzhiyun    # Cancel out all the simple stuff to save iterations.  We also want
975*4882a593Smuzhiyun    # the path to end with a slash for ease of parsing, so make sure
976*4882a593Smuzhiyun    # there is one (and only one) here.
977*4882a593Smuzhiyun    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
978*4882a593Smuzhiyun          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
979*4882a593Smuzhiyun    while :; do
980*4882a593Smuzhiyun      # Processed it all yet?
981*4882a593Smuzhiyun      if test / = "$func_normal_abspath_tpath"; then
982*4882a593Smuzhiyun        # If we ascended to the root using ".." the result may be empty now.
983*4882a593Smuzhiyun        if test -z "$func_normal_abspath_result"; then
984*4882a593Smuzhiyun          func_normal_abspath_result=/
985*4882a593Smuzhiyun        fi
986*4882a593Smuzhiyun        break
987*4882a593Smuzhiyun      fi
988*4882a593Smuzhiyun      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
989*4882a593Smuzhiyun          -e "$_G_pathcar"`
990*4882a593Smuzhiyun      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
991*4882a593Smuzhiyun          -e "$_G_pathcdr"`
992*4882a593Smuzhiyun      # Figure out what to do with it
993*4882a593Smuzhiyun      case $func_normal_abspath_tcomponent in
994*4882a593Smuzhiyun        "")
995*4882a593Smuzhiyun          # Trailing empty path component, ignore it.
996*4882a593Smuzhiyun          ;;
997*4882a593Smuzhiyun        ..)
998*4882a593Smuzhiyun          # Parent dir; strip last assembled component from result.
999*4882a593Smuzhiyun          func_dirname "$func_normal_abspath_result"
1000*4882a593Smuzhiyun          func_normal_abspath_result=$func_dirname_result
1001*4882a593Smuzhiyun          ;;
1002*4882a593Smuzhiyun        *)
1003*4882a593Smuzhiyun          # Actual path component, append it.
1004*4882a593Smuzhiyun          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1005*4882a593Smuzhiyun          ;;
1006*4882a593Smuzhiyun      esac
1007*4882a593Smuzhiyun    done
1008*4882a593Smuzhiyun    # Restore leading double-slash if one was found on entry.
1009*4882a593Smuzhiyun    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1010*4882a593Smuzhiyun}
1011*4882a593Smuzhiyun
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun# func_notquiet ARG...
1014*4882a593Smuzhiyun# --------------------
1015*4882a593Smuzhiyun# Echo program name prefixed message only when not in quiet mode.
1016*4882a593Smuzhiyunfunc_notquiet ()
1017*4882a593Smuzhiyun{
1018*4882a593Smuzhiyun    $debug_cmd
1019*4882a593Smuzhiyun
1020*4882a593Smuzhiyun    $opt_quiet || func_echo ${1+"$@"}
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun    # A bug in bash halts the script if the last line of a function
1023*4882a593Smuzhiyun    # fails when set -e is in force, so we need another command to
1024*4882a593Smuzhiyun    # work around that:
1025*4882a593Smuzhiyun    :
1026*4882a593Smuzhiyun}
1027*4882a593Smuzhiyun
1028*4882a593Smuzhiyun
1029*4882a593Smuzhiyun# func_relative_path SRCDIR DSTDIR
1030*4882a593Smuzhiyun# --------------------------------
1031*4882a593Smuzhiyun# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1032*4882a593Smuzhiyunfunc_relative_path ()
1033*4882a593Smuzhiyun{
1034*4882a593Smuzhiyun    $debug_cmd
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun    func_relative_path_result=
1037*4882a593Smuzhiyun    func_normal_abspath "$1"
1038*4882a593Smuzhiyun    func_relative_path_tlibdir=$func_normal_abspath_result
1039*4882a593Smuzhiyun    func_normal_abspath "$2"
1040*4882a593Smuzhiyun    func_relative_path_tbindir=$func_normal_abspath_result
1041*4882a593Smuzhiyun
1042*4882a593Smuzhiyun    # Ascend the tree starting from libdir
1043*4882a593Smuzhiyun    while :; do
1044*4882a593Smuzhiyun      # check if we have found a prefix of bindir
1045*4882a593Smuzhiyun      case $func_relative_path_tbindir in
1046*4882a593Smuzhiyun        $func_relative_path_tlibdir)
1047*4882a593Smuzhiyun          # found an exact match
1048*4882a593Smuzhiyun          func_relative_path_tcancelled=
1049*4882a593Smuzhiyun          break
1050*4882a593Smuzhiyun          ;;
1051*4882a593Smuzhiyun        $func_relative_path_tlibdir*)
1052*4882a593Smuzhiyun          # found a matching prefix
1053*4882a593Smuzhiyun          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1054*4882a593Smuzhiyun          func_relative_path_tcancelled=$func_stripname_result
1055*4882a593Smuzhiyun          if test -z "$func_relative_path_result"; then
1056*4882a593Smuzhiyun            func_relative_path_result=.
1057*4882a593Smuzhiyun          fi
1058*4882a593Smuzhiyun          break
1059*4882a593Smuzhiyun          ;;
1060*4882a593Smuzhiyun        *)
1061*4882a593Smuzhiyun          func_dirname $func_relative_path_tlibdir
1062*4882a593Smuzhiyun          func_relative_path_tlibdir=$func_dirname_result
1063*4882a593Smuzhiyun          if test -z "$func_relative_path_tlibdir"; then
1064*4882a593Smuzhiyun            # Have to descend all the way to the root!
1065*4882a593Smuzhiyun            func_relative_path_result=../$func_relative_path_result
1066*4882a593Smuzhiyun            func_relative_path_tcancelled=$func_relative_path_tbindir
1067*4882a593Smuzhiyun            break
1068*4882a593Smuzhiyun          fi
1069*4882a593Smuzhiyun          func_relative_path_result=../$func_relative_path_result
1070*4882a593Smuzhiyun          ;;
1071*4882a593Smuzhiyun      esac
1072*4882a593Smuzhiyun    done
1073*4882a593Smuzhiyun
1074*4882a593Smuzhiyun    # Now calculate path; take care to avoid doubling-up slashes.
1075*4882a593Smuzhiyun    func_stripname '' '/' "$func_relative_path_result"
1076*4882a593Smuzhiyun    func_relative_path_result=$func_stripname_result
1077*4882a593Smuzhiyun    func_stripname '/' '/' "$func_relative_path_tcancelled"
1078*4882a593Smuzhiyun    if test -n "$func_stripname_result"; then
1079*4882a593Smuzhiyun      func_append func_relative_path_result "/$func_stripname_result"
1080*4882a593Smuzhiyun    fi
1081*4882a593Smuzhiyun
1082*4882a593Smuzhiyun    # Normalisation. If bindir is libdir, return '.' else relative path.
1083*4882a593Smuzhiyun    if test -n "$func_relative_path_result"; then
1084*4882a593Smuzhiyun      func_stripname './' '' "$func_relative_path_result"
1085*4882a593Smuzhiyun      func_relative_path_result=$func_stripname_result
1086*4882a593Smuzhiyun    fi
1087*4882a593Smuzhiyun
1088*4882a593Smuzhiyun    test -n "$func_relative_path_result" || func_relative_path_result=.
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun    :
1091*4882a593Smuzhiyun}
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun# func_quote ARG
1095*4882a593Smuzhiyun# --------------
1096*4882a593Smuzhiyun# Aesthetically quote one ARG, store the result into $func_quote_result.  Note
1097*4882a593Smuzhiyun# that we keep attention to performance here (so far O(N) complexity as long as
1098*4882a593Smuzhiyun# func_append is O(1)).
1099*4882a593Smuzhiyunfunc_quote ()
1100*4882a593Smuzhiyun{
1101*4882a593Smuzhiyun    $debug_cmd
1102*4882a593Smuzhiyun
1103*4882a593Smuzhiyun    func_quote_result=$1
1104*4882a593Smuzhiyun
1105*4882a593Smuzhiyun    case $func_quote_result in
1106*4882a593Smuzhiyun      *[\\\`\"\$]*)
1107*4882a593Smuzhiyun        case $func_quote_result in
1108*4882a593Smuzhiyun          *[\[\*\?]*)
1109*4882a593Smuzhiyun            func_quote_result=`$ECHO "$func_quote_result" | $SED "$sed_quote_subst"`
1110*4882a593Smuzhiyun            return 0
1111*4882a593Smuzhiyun            ;;
1112*4882a593Smuzhiyun        esac
1113*4882a593Smuzhiyun
1114*4882a593Smuzhiyun        func_quote_old_IFS=$IFS
1115*4882a593Smuzhiyun        for _G_char in '\' '`' '"' '$'
1116*4882a593Smuzhiyun        do
1117*4882a593Smuzhiyun          # STATE($1) PREV($2) SEPARATOR($3)
1118*4882a593Smuzhiyun          set start "" ""
1119*4882a593Smuzhiyun          func_quote_result=dummy"$_G_char$func_quote_result$_G_char"dummy
1120*4882a593Smuzhiyun          IFS=$_G_char
1121*4882a593Smuzhiyun          for _G_part in $func_quote_result
1122*4882a593Smuzhiyun          do
1123*4882a593Smuzhiyun            case $1 in
1124*4882a593Smuzhiyun            quote)
1125*4882a593Smuzhiyun              func_append func_quote_result "$3$2"
1126*4882a593Smuzhiyun              set quote "$_G_part" "\\$_G_char"
1127*4882a593Smuzhiyun              ;;
1128*4882a593Smuzhiyun            start)
1129*4882a593Smuzhiyun              set first "" ""
1130*4882a593Smuzhiyun              func_quote_result=
1131*4882a593Smuzhiyun              ;;
1132*4882a593Smuzhiyun            first)
1133*4882a593Smuzhiyun              set quote "$_G_part" ""
1134*4882a593Smuzhiyun              ;;
1135*4882a593Smuzhiyun            esac
1136*4882a593Smuzhiyun          done
1137*4882a593Smuzhiyun          IFS=$func_quote_old_IFS
1138*4882a593Smuzhiyun        done
1139*4882a593Smuzhiyun        ;;
1140*4882a593Smuzhiyun      *) ;;
1141*4882a593Smuzhiyun    esac
1142*4882a593Smuzhiyun}
1143*4882a593Smuzhiyun
1144*4882a593Smuzhiyun
1145*4882a593Smuzhiyun# func_quote_for_eval ARG...
1146*4882a593Smuzhiyun# --------------------------
1147*4882a593Smuzhiyun# Aesthetically quote ARGs to be evaled later.
1148*4882a593Smuzhiyun# This function returns two values:
1149*4882a593Smuzhiyun#   i) func_quote_for_eval_result
1150*4882a593Smuzhiyun#      double-quoted, suitable for a subsequent eval
1151*4882a593Smuzhiyun#  ii) func_quote_for_eval_unquoted_result
1152*4882a593Smuzhiyun#      has all characters that are still active within double
1153*4882a593Smuzhiyun#      quotes backslashified.
1154*4882a593Smuzhiyunfunc_quote_for_eval ()
1155*4882a593Smuzhiyun{
1156*4882a593Smuzhiyun    $debug_cmd
1157*4882a593Smuzhiyun
1158*4882a593Smuzhiyun    func_quote_for_eval_unquoted_result=
1159*4882a593Smuzhiyun    func_quote_for_eval_result=
1160*4882a593Smuzhiyun    while test 0 -lt $#; do
1161*4882a593Smuzhiyun      func_quote "$1"
1162*4882a593Smuzhiyun      _G_unquoted_arg=$func_quote_result
1163*4882a593Smuzhiyun      if test -n "$func_quote_for_eval_unquoted_result"; then
1164*4882a593Smuzhiyun	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
1165*4882a593Smuzhiyun      else
1166*4882a593Smuzhiyun        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
1167*4882a593Smuzhiyun      fi
1168*4882a593Smuzhiyun
1169*4882a593Smuzhiyun      case $_G_unquoted_arg in
1170*4882a593Smuzhiyun        # Double-quote args containing shell metacharacters to delay
1171*4882a593Smuzhiyun        # word splitting, command substitution and variable expansion
1172*4882a593Smuzhiyun        # for a subsequent eval.
1173*4882a593Smuzhiyun        # Many Bourne shells cannot handle close brackets correctly
1174*4882a593Smuzhiyun        # in scan sets, so we specify it separately.
1175*4882a593Smuzhiyun        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1176*4882a593Smuzhiyun          _G_quoted_arg=\"$_G_unquoted_arg\"
1177*4882a593Smuzhiyun          ;;
1178*4882a593Smuzhiyun        *)
1179*4882a593Smuzhiyun          _G_quoted_arg=$_G_unquoted_arg
1180*4882a593Smuzhiyun	  ;;
1181*4882a593Smuzhiyun      esac
1182*4882a593Smuzhiyun
1183*4882a593Smuzhiyun      if test -n "$func_quote_for_eval_result"; then
1184*4882a593Smuzhiyun	func_append func_quote_for_eval_result " $_G_quoted_arg"
1185*4882a593Smuzhiyun      else
1186*4882a593Smuzhiyun        func_append func_quote_for_eval_result "$_G_quoted_arg"
1187*4882a593Smuzhiyun      fi
1188*4882a593Smuzhiyun      shift
1189*4882a593Smuzhiyun    done
1190*4882a593Smuzhiyun}
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun
1193*4882a593Smuzhiyun# func_quote_for_expand ARG
1194*4882a593Smuzhiyun# -------------------------
1195*4882a593Smuzhiyun# Aesthetically quote ARG to be evaled later; same as above,
1196*4882a593Smuzhiyun# but do not quote variable references.
1197*4882a593Smuzhiyunfunc_quote_for_expand ()
1198*4882a593Smuzhiyun{
1199*4882a593Smuzhiyun    $debug_cmd
1200*4882a593Smuzhiyun
1201*4882a593Smuzhiyun    case $1 in
1202*4882a593Smuzhiyun      *[\\\`\"]*)
1203*4882a593Smuzhiyun	_G_arg=`$ECHO "$1" | $SED \
1204*4882a593Smuzhiyun	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
1205*4882a593Smuzhiyun      *)
1206*4882a593Smuzhiyun        _G_arg=$1 ;;
1207*4882a593Smuzhiyun    esac
1208*4882a593Smuzhiyun
1209*4882a593Smuzhiyun    case $_G_arg in
1210*4882a593Smuzhiyun      # Double-quote args containing shell metacharacters to delay
1211*4882a593Smuzhiyun      # word splitting and command substitution for a subsequent eval.
1212*4882a593Smuzhiyun      # Many Bourne shells cannot handle close brackets correctly
1213*4882a593Smuzhiyun      # in scan sets, so we specify it separately.
1214*4882a593Smuzhiyun      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1215*4882a593Smuzhiyun        _G_arg=\"$_G_arg\"
1216*4882a593Smuzhiyun        ;;
1217*4882a593Smuzhiyun    esac
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun    func_quote_for_expand_result=$_G_arg
1220*4882a593Smuzhiyun}
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun
1223*4882a593Smuzhiyun# func_stripname PREFIX SUFFIX NAME
1224*4882a593Smuzhiyun# ---------------------------------
1225*4882a593Smuzhiyun# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1226*4882a593Smuzhiyun# PREFIX and SUFFIX must not contain globbing or regex special
1227*4882a593Smuzhiyun# characters, hashes, percent signs, but SUFFIX may contain a leading
1228*4882a593Smuzhiyun# dot (in which case that matches only a dot).
1229*4882a593Smuzhiyunif test yes = "$_G_HAVE_XSI_OPS"; then
1230*4882a593Smuzhiyun  eval 'func_stripname ()
1231*4882a593Smuzhiyun  {
1232*4882a593Smuzhiyun    $debug_cmd
1233*4882a593Smuzhiyun
1234*4882a593Smuzhiyun    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1235*4882a593Smuzhiyun    # positional parameters, so assign one to ordinary variable first.
1236*4882a593Smuzhiyun    func_stripname_result=$3
1237*4882a593Smuzhiyun    func_stripname_result=${func_stripname_result#"$1"}
1238*4882a593Smuzhiyun    func_stripname_result=${func_stripname_result%"$2"}
1239*4882a593Smuzhiyun  }'
1240*4882a593Smuzhiyunelse
1241*4882a593Smuzhiyun  func_stripname ()
1242*4882a593Smuzhiyun  {
1243*4882a593Smuzhiyun    $debug_cmd
1244*4882a593Smuzhiyun
1245*4882a593Smuzhiyun    case $2 in
1246*4882a593Smuzhiyun      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1247*4882a593Smuzhiyun      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1248*4882a593Smuzhiyun    esac
1249*4882a593Smuzhiyun  }
1250*4882a593Smuzhiyunfi
1251*4882a593Smuzhiyun
1252*4882a593Smuzhiyun
1253*4882a593Smuzhiyun# func_show_eval CMD [FAIL_EXP]
1254*4882a593Smuzhiyun# -----------------------------
1255*4882a593Smuzhiyun# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1256*4882a593Smuzhiyun# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1257*4882a593Smuzhiyun# is given, then evaluate it.
1258*4882a593Smuzhiyunfunc_show_eval ()
1259*4882a593Smuzhiyun{
1260*4882a593Smuzhiyun    $debug_cmd
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun    _G_cmd=$1
1263*4882a593Smuzhiyun    _G_fail_exp=${2-':'}
1264*4882a593Smuzhiyun
1265*4882a593Smuzhiyun    func_quote_for_expand "$_G_cmd"
1266*4882a593Smuzhiyun    eval "func_notquiet $func_quote_for_expand_result"
1267*4882a593Smuzhiyun
1268*4882a593Smuzhiyun    $opt_dry_run || {
1269*4882a593Smuzhiyun      eval "$_G_cmd"
1270*4882a593Smuzhiyun      _G_status=$?
1271*4882a593Smuzhiyun      if test 0 -ne "$_G_status"; then
1272*4882a593Smuzhiyun	eval "(exit $_G_status); $_G_fail_exp"
1273*4882a593Smuzhiyun      fi
1274*4882a593Smuzhiyun    }
1275*4882a593Smuzhiyun}
1276*4882a593Smuzhiyun
1277*4882a593Smuzhiyun
1278*4882a593Smuzhiyun# func_show_eval_locale CMD [FAIL_EXP]
1279*4882a593Smuzhiyun# ------------------------------------
1280*4882a593Smuzhiyun# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1281*4882a593Smuzhiyun# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1282*4882a593Smuzhiyun# is given, then evaluate it.  Use the saved locale for evaluation.
1283*4882a593Smuzhiyunfunc_show_eval_locale ()
1284*4882a593Smuzhiyun{
1285*4882a593Smuzhiyun    $debug_cmd
1286*4882a593Smuzhiyun
1287*4882a593Smuzhiyun    _G_cmd=$1
1288*4882a593Smuzhiyun    _G_fail_exp=${2-':'}
1289*4882a593Smuzhiyun
1290*4882a593Smuzhiyun    $opt_quiet || {
1291*4882a593Smuzhiyun      func_quote_for_expand "$_G_cmd"
1292*4882a593Smuzhiyun      eval "func_echo $func_quote_for_expand_result"
1293*4882a593Smuzhiyun    }
1294*4882a593Smuzhiyun
1295*4882a593Smuzhiyun    $opt_dry_run || {
1296*4882a593Smuzhiyun      eval "$_G_user_locale
1297*4882a593Smuzhiyun	    $_G_cmd"
1298*4882a593Smuzhiyun      _G_status=$?
1299*4882a593Smuzhiyun      eval "$_G_safe_locale"
1300*4882a593Smuzhiyun      if test 0 -ne "$_G_status"; then
1301*4882a593Smuzhiyun	eval "(exit $_G_status); $_G_fail_exp"
1302*4882a593Smuzhiyun      fi
1303*4882a593Smuzhiyun    }
1304*4882a593Smuzhiyun}
1305*4882a593Smuzhiyun
1306*4882a593Smuzhiyun
1307*4882a593Smuzhiyun# func_tr_sh
1308*4882a593Smuzhiyun# ----------
1309*4882a593Smuzhiyun# Turn $1 into a string suitable for a shell variable name.
1310*4882a593Smuzhiyun# Result is stored in $func_tr_sh_result.  All characters
1311*4882a593Smuzhiyun# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1312*4882a593Smuzhiyun# if $1 begins with a digit, a '_' is prepended as well.
1313*4882a593Smuzhiyunfunc_tr_sh ()
1314*4882a593Smuzhiyun{
1315*4882a593Smuzhiyun    $debug_cmd
1316*4882a593Smuzhiyun
1317*4882a593Smuzhiyun    case $1 in
1318*4882a593Smuzhiyun    [0-9]* | *[!a-zA-Z0-9_]*)
1319*4882a593Smuzhiyun      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1320*4882a593Smuzhiyun      ;;
1321*4882a593Smuzhiyun    * )
1322*4882a593Smuzhiyun      func_tr_sh_result=$1
1323*4882a593Smuzhiyun      ;;
1324*4882a593Smuzhiyun    esac
1325*4882a593Smuzhiyun}
1326*4882a593Smuzhiyun
1327*4882a593Smuzhiyun
1328*4882a593Smuzhiyun# func_verbose ARG...
1329*4882a593Smuzhiyun# -------------------
1330*4882a593Smuzhiyun# Echo program name prefixed message in verbose mode only.
1331*4882a593Smuzhiyunfunc_verbose ()
1332*4882a593Smuzhiyun{
1333*4882a593Smuzhiyun    $debug_cmd
1334*4882a593Smuzhiyun
1335*4882a593Smuzhiyun    $opt_verbose && func_echo "$*"
1336*4882a593Smuzhiyun
1337*4882a593Smuzhiyun    :
1338*4882a593Smuzhiyun}
1339*4882a593Smuzhiyun
1340*4882a593Smuzhiyun
1341*4882a593Smuzhiyun# func_warn_and_continue ARG...
1342*4882a593Smuzhiyun# -----------------------------
1343*4882a593Smuzhiyun# Echo program name prefixed warning message to standard error.
1344*4882a593Smuzhiyunfunc_warn_and_continue ()
1345*4882a593Smuzhiyun{
1346*4882a593Smuzhiyun    $debug_cmd
1347*4882a593Smuzhiyun
1348*4882a593Smuzhiyun    $require_term_colors
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1351*4882a593Smuzhiyun}
1352*4882a593Smuzhiyun
1353*4882a593Smuzhiyun
1354*4882a593Smuzhiyun# func_warning CATEGORY ARG...
1355*4882a593Smuzhiyun# ----------------------------
1356*4882a593Smuzhiyun# Echo program name prefixed warning message to standard error. Warning
1357*4882a593Smuzhiyun# messages can be filtered according to CATEGORY, where this function
1358*4882a593Smuzhiyun# elides messages where CATEGORY is not listed in the global variable
1359*4882a593Smuzhiyun# 'opt_warning_types'.
1360*4882a593Smuzhiyunfunc_warning ()
1361*4882a593Smuzhiyun{
1362*4882a593Smuzhiyun    $debug_cmd
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun    # CATEGORY must be in the warning_categories list!
1365*4882a593Smuzhiyun    case " $warning_categories " in
1366*4882a593Smuzhiyun      *" $1 "*) ;;
1367*4882a593Smuzhiyun      *) func_internal_error "invalid warning category '$1'" ;;
1368*4882a593Smuzhiyun    esac
1369*4882a593Smuzhiyun
1370*4882a593Smuzhiyun    _G_category=$1
1371*4882a593Smuzhiyun    shift
1372*4882a593Smuzhiyun
1373*4882a593Smuzhiyun    case " $opt_warning_types " in
1374*4882a593Smuzhiyun      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1375*4882a593Smuzhiyun    esac
1376*4882a593Smuzhiyun}
1377*4882a593Smuzhiyun
1378*4882a593Smuzhiyun
1379*4882a593Smuzhiyun# func_sort_ver VER1 VER2
1380*4882a593Smuzhiyun# -----------------------
1381*4882a593Smuzhiyun# 'sort -V' is not generally available.
1382*4882a593Smuzhiyun# Note this deviates from the version comparison in automake
1383*4882a593Smuzhiyun# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1384*4882a593Smuzhiyun# but this should suffice as we won't be specifying old
1385*4882a593Smuzhiyun# version formats or redundant trailing .0 in bootstrap.conf.
1386*4882a593Smuzhiyun# If we did want full compatibility then we should probably
1387*4882a593Smuzhiyun# use m4_version_compare from autoconf.
1388*4882a593Smuzhiyunfunc_sort_ver ()
1389*4882a593Smuzhiyun{
1390*4882a593Smuzhiyun    $debug_cmd
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun    printf '%s\n%s\n' "$1" "$2" \
1393*4882a593Smuzhiyun      | 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
1394*4882a593Smuzhiyun}
1395*4882a593Smuzhiyun
1396*4882a593Smuzhiyun# func_lt_ver PREV CURR
1397*4882a593Smuzhiyun# ---------------------
1398*4882a593Smuzhiyun# Return true if PREV and CURR are in the correct order according to
1399*4882a593Smuzhiyun# func_sort_ver, otherwise false.  Use it like this:
1400*4882a593Smuzhiyun#
1401*4882a593Smuzhiyun#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1402*4882a593Smuzhiyunfunc_lt_ver ()
1403*4882a593Smuzhiyun{
1404*4882a593Smuzhiyun    $debug_cmd
1405*4882a593Smuzhiyun
1406*4882a593Smuzhiyun    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1407*4882a593Smuzhiyun}
1408*4882a593Smuzhiyun
1409*4882a593Smuzhiyun
1410*4882a593Smuzhiyun# Local variables:
1411*4882a593Smuzhiyun# mode: shell-script
1412*4882a593Smuzhiyun# sh-indentation: 2
1413*4882a593Smuzhiyun# eval: (add-hook 'before-save-hook 'time-stamp)
1414*4882a593Smuzhiyun# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1415*4882a593Smuzhiyun# time-stamp-time-zone: "UTC"
1416*4882a593Smuzhiyun# End:
1417*4882a593Smuzhiyun#! /bin/sh
1418*4882a593Smuzhiyun
1419*4882a593Smuzhiyun# Set a version string for this script.
1420*4882a593Smuzhiyunscriptversion=2014-01-07.03; # UTC
1421*4882a593Smuzhiyun
1422*4882a593Smuzhiyun# A portable, pluggable option parser for Bourne shell.
1423*4882a593Smuzhiyun# Written by Gary V. Vaughan, 2010
1424*4882a593Smuzhiyun
1425*4882a593Smuzhiyun# Copyright (C) 2010-2015 Free Software Foundation, Inc.
1426*4882a593Smuzhiyun# This is free software; see the source for copying conditions.  There is NO
1427*4882a593Smuzhiyun# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1428*4882a593Smuzhiyun
1429*4882a593Smuzhiyun# This program is free software: you can redistribute it and/or modify
1430*4882a593Smuzhiyun# it under the terms of the GNU General Public License as published by
1431*4882a593Smuzhiyun# the Free Software Foundation, either version 3 of the License, or
1432*4882a593Smuzhiyun# (at your option) any later version.
1433*4882a593Smuzhiyun
1434*4882a593Smuzhiyun# This program is distributed in the hope that it will be useful,
1435*4882a593Smuzhiyun# but WITHOUT ANY WARRANTY; without even the implied warranty of
1436*4882a593Smuzhiyun# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1437*4882a593Smuzhiyun# GNU General Public License for more details.
1438*4882a593Smuzhiyun
1439*4882a593Smuzhiyun# You should have received a copy of the GNU General Public License
1440*4882a593Smuzhiyun# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1441*4882a593Smuzhiyun
1442*4882a593Smuzhiyun# Please report bugs or propose patches to gary@gnu.org.
1443*4882a593Smuzhiyun
1444*4882a593Smuzhiyun
1445*4882a593Smuzhiyun## ------ ##
1446*4882a593Smuzhiyun## Usage. ##
1447*4882a593Smuzhiyun## ------ ##
1448*4882a593Smuzhiyun
1449*4882a593Smuzhiyun# This file is a library for parsing options in your shell scripts along
1450*4882a593Smuzhiyun# with assorted other useful supporting features that you can make use
1451*4882a593Smuzhiyun# of too.
1452*4882a593Smuzhiyun#
1453*4882a593Smuzhiyun# For the simplest scripts you might need only:
1454*4882a593Smuzhiyun#
1455*4882a593Smuzhiyun#   #!/bin/sh
1456*4882a593Smuzhiyun#   . relative/path/to/funclib.sh
1457*4882a593Smuzhiyun#   . relative/path/to/options-parser
1458*4882a593Smuzhiyun#   scriptversion=1.0
1459*4882a593Smuzhiyun#   func_options ${1+"$@"}
1460*4882a593Smuzhiyun#   eval set dummy "$func_options_result"; shift
1461*4882a593Smuzhiyun#   ...rest of your script...
1462*4882a593Smuzhiyun#
1463*4882a593Smuzhiyun# In order for the '--version' option to work, you will need to have a
1464*4882a593Smuzhiyun# suitably formatted comment like the one at the top of this file
1465*4882a593Smuzhiyun# starting with '# Written by ' and ending with '# warranty; '.
1466*4882a593Smuzhiyun#
1467*4882a593Smuzhiyun# For '-h' and '--help' to work, you will also need a one line
1468*4882a593Smuzhiyun# description of your script's purpose in a comment directly above the
1469*4882a593Smuzhiyun# '# Written by ' line, like the one at the top of this file.
1470*4882a593Smuzhiyun#
1471*4882a593Smuzhiyun# The default options also support '--debug', which will turn on shell
1472*4882a593Smuzhiyun# execution tracing (see the comment above debug_cmd below for another
1473*4882a593Smuzhiyun# use), and '--verbose' and the func_verbose function to allow your script
1474*4882a593Smuzhiyun# to display verbose messages only when your user has specified
1475*4882a593Smuzhiyun# '--verbose'.
1476*4882a593Smuzhiyun#
1477*4882a593Smuzhiyun# After sourcing this file, you can plug processing for additional
1478*4882a593Smuzhiyun# options by amending the variables from the 'Configuration' section
1479*4882a593Smuzhiyun# below, and following the instructions in the 'Option parsing'
1480*4882a593Smuzhiyun# section further down.
1481*4882a593Smuzhiyun
1482*4882a593Smuzhiyun## -------------- ##
1483*4882a593Smuzhiyun## Configuration. ##
1484*4882a593Smuzhiyun## -------------- ##
1485*4882a593Smuzhiyun
1486*4882a593Smuzhiyun# You should override these variables in your script after sourcing this
1487*4882a593Smuzhiyun# file so that they reflect the customisations you have added to the
1488*4882a593Smuzhiyun# option parser.
1489*4882a593Smuzhiyun
1490*4882a593Smuzhiyun# The usage line for option parsing errors and the start of '-h' and
1491*4882a593Smuzhiyun# '--help' output messages. You can embed shell variables for delayed
1492*4882a593Smuzhiyun# expansion at the time the message is displayed, but you will need to
1493*4882a593Smuzhiyun# quote other shell meta-characters carefully to prevent them being
1494*4882a593Smuzhiyun# expanded when the contents are evaled.
1495*4882a593Smuzhiyunusage='$progpath [OPTION]...'
1496*4882a593Smuzhiyun
1497*4882a593Smuzhiyun# Short help message in response to '-h' and '--help'.  Add to this or
1498*4882a593Smuzhiyun# override it after sourcing this library to reflect the full set of
1499*4882a593Smuzhiyun# options your script accepts.
1500*4882a593Smuzhiyunusage_message="\
1501*4882a593Smuzhiyun       --debug        enable verbose shell tracing
1502*4882a593Smuzhiyun   -W, --warnings=CATEGORY
1503*4882a593Smuzhiyun                      report the warnings falling in CATEGORY [all]
1504*4882a593Smuzhiyun   -v, --verbose      verbosely report processing
1505*4882a593Smuzhiyun       --version      print version information and exit
1506*4882a593Smuzhiyun   -h, --help         print short or long help message and exit
1507*4882a593Smuzhiyun"
1508*4882a593Smuzhiyun
1509*4882a593Smuzhiyun# Additional text appended to 'usage_message' in response to '--help'.
1510*4882a593Smuzhiyunlong_help_message="
1511*4882a593SmuzhiyunWarning categories include:
1512*4882a593Smuzhiyun       'all'          show all warnings
1513*4882a593Smuzhiyun       'none'         turn off all the warnings
1514*4882a593Smuzhiyun       'error'        warnings are treated as fatal errors"
1515*4882a593Smuzhiyun
1516*4882a593Smuzhiyun# Help message printed before fatal option parsing errors.
1517*4882a593Smuzhiyunfatal_help="Try '\$progname --help' for more information."
1518*4882a593Smuzhiyun
1519*4882a593Smuzhiyun
1520*4882a593Smuzhiyun
1521*4882a593Smuzhiyun## ------------------------- ##
1522*4882a593Smuzhiyun## Hook function management. ##
1523*4882a593Smuzhiyun## ------------------------- ##
1524*4882a593Smuzhiyun
1525*4882a593Smuzhiyun# This section contains functions for adding, removing, and running hooks
1526*4882a593Smuzhiyun# to the main code.  A hook is just a named list of of function, that can
1527*4882a593Smuzhiyun# be run in order later on.
1528*4882a593Smuzhiyun
1529*4882a593Smuzhiyun# func_hookable FUNC_NAME
1530*4882a593Smuzhiyun# -----------------------
1531*4882a593Smuzhiyun# Declare that FUNC_NAME will run hooks added with
1532*4882a593Smuzhiyun# 'func_add_hook FUNC_NAME ...'.
1533*4882a593Smuzhiyunfunc_hookable ()
1534*4882a593Smuzhiyun{
1535*4882a593Smuzhiyun    $debug_cmd
1536*4882a593Smuzhiyun
1537*4882a593Smuzhiyun    func_append hookable_fns " $1"
1538*4882a593Smuzhiyun}
1539*4882a593Smuzhiyun
1540*4882a593Smuzhiyun
1541*4882a593Smuzhiyun# func_add_hook FUNC_NAME HOOK_FUNC
1542*4882a593Smuzhiyun# ---------------------------------
1543*4882a593Smuzhiyun# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1544*4882a593Smuzhiyun# first have been declared "hookable" by a call to 'func_hookable'.
1545*4882a593Smuzhiyunfunc_add_hook ()
1546*4882a593Smuzhiyun{
1547*4882a593Smuzhiyun    $debug_cmd
1548*4882a593Smuzhiyun
1549*4882a593Smuzhiyun    case " $hookable_fns " in
1550*4882a593Smuzhiyun      *" $1 "*) ;;
1551*4882a593Smuzhiyun      *) func_fatal_error "'$1' does not accept hook functions." ;;
1552*4882a593Smuzhiyun    esac
1553*4882a593Smuzhiyun
1554*4882a593Smuzhiyun    eval func_append ${1}_hooks '" $2"'
1555*4882a593Smuzhiyun}
1556*4882a593Smuzhiyun
1557*4882a593Smuzhiyun
1558*4882a593Smuzhiyun# func_remove_hook FUNC_NAME HOOK_FUNC
1559*4882a593Smuzhiyun# ------------------------------------
1560*4882a593Smuzhiyun# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1561*4882a593Smuzhiyunfunc_remove_hook ()
1562*4882a593Smuzhiyun{
1563*4882a593Smuzhiyun    $debug_cmd
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1566*4882a593Smuzhiyun}
1567*4882a593Smuzhiyun
1568*4882a593Smuzhiyun
1569*4882a593Smuzhiyun# func_run_hooks FUNC_NAME [ARG]...
1570*4882a593Smuzhiyun# ---------------------------------
1571*4882a593Smuzhiyun# Run all hook functions registered to FUNC_NAME.
1572*4882a593Smuzhiyun# It is assumed that the list of hook functions contains nothing more
1573*4882a593Smuzhiyun# than a whitespace-delimited list of legal shell function names, and
1574*4882a593Smuzhiyun# no effort is wasted trying to catch shell meta-characters or preserve
1575*4882a593Smuzhiyun# whitespace.
1576*4882a593Smuzhiyunfunc_run_hooks ()
1577*4882a593Smuzhiyun{
1578*4882a593Smuzhiyun    $debug_cmd
1579*4882a593Smuzhiyun
1580*4882a593Smuzhiyun    case " $hookable_fns " in
1581*4882a593Smuzhiyun      *" $1 "*) ;;
1582*4882a593Smuzhiyun      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1583*4882a593Smuzhiyun    esac
1584*4882a593Smuzhiyun
1585*4882a593Smuzhiyun    eval _G_hook_fns=\$$1_hooks; shift
1586*4882a593Smuzhiyun
1587*4882a593Smuzhiyun    for _G_hook in $_G_hook_fns; do
1588*4882a593Smuzhiyun      eval $_G_hook '"$@"'
1589*4882a593Smuzhiyun
1590*4882a593Smuzhiyun      # store returned options list back into positional
1591*4882a593Smuzhiyun      # parameters for next 'cmd' execution.
1592*4882a593Smuzhiyun      eval _G_hook_result=\$${_G_hook}_result
1593*4882a593Smuzhiyun      eval set dummy "$_G_hook_result"; shift
1594*4882a593Smuzhiyun    done
1595*4882a593Smuzhiyun
1596*4882a593Smuzhiyun    func_quote_for_eval ${1+"$@"}
1597*4882a593Smuzhiyun    func_run_hooks_result=$func_quote_for_eval_result
1598*4882a593Smuzhiyun}
1599*4882a593Smuzhiyun
1600*4882a593Smuzhiyun
1601*4882a593Smuzhiyun
1602*4882a593Smuzhiyun## --------------- ##
1603*4882a593Smuzhiyun## Option parsing. ##
1604*4882a593Smuzhiyun## --------------- ##
1605*4882a593Smuzhiyun
1606*4882a593Smuzhiyun# In order to add your own option parsing hooks, you must accept the
1607*4882a593Smuzhiyun# full positional parameter list in your hook function, remove any
1608*4882a593Smuzhiyun# options that you action, and then pass back the remaining unprocessed
1609*4882a593Smuzhiyun# options in '<hooked_function_name>_result', escaped suitably for
1610*4882a593Smuzhiyun# 'eval'.  Like this:
1611*4882a593Smuzhiyun#
1612*4882a593Smuzhiyun#    my_options_prep ()
1613*4882a593Smuzhiyun#    {
1614*4882a593Smuzhiyun#        $debug_cmd
1615*4882a593Smuzhiyun#
1616*4882a593Smuzhiyun#        # Extend the existing usage message.
1617*4882a593Smuzhiyun#        usage_message=$usage_message'
1618*4882a593Smuzhiyun#      -s, --silent       don'\''t print informational messages
1619*4882a593Smuzhiyun#    '
1620*4882a593Smuzhiyun#
1621*4882a593Smuzhiyun#        func_quote_for_eval ${1+"$@"}
1622*4882a593Smuzhiyun#        my_options_prep_result=$func_quote_for_eval_result
1623*4882a593Smuzhiyun#    }
1624*4882a593Smuzhiyun#    func_add_hook func_options_prep my_options_prep
1625*4882a593Smuzhiyun#
1626*4882a593Smuzhiyun#
1627*4882a593Smuzhiyun#    my_silent_option ()
1628*4882a593Smuzhiyun#    {
1629*4882a593Smuzhiyun#        $debug_cmd
1630*4882a593Smuzhiyun#
1631*4882a593Smuzhiyun#        # Note that for efficiency, we parse as many options as we can
1632*4882a593Smuzhiyun#        # recognise in a loop before passing the remainder back to the
1633*4882a593Smuzhiyun#        # caller on the first unrecognised argument we encounter.
1634*4882a593Smuzhiyun#        while test $# -gt 0; do
1635*4882a593Smuzhiyun#          opt=$1; shift
1636*4882a593Smuzhiyun#          case $opt in
1637*4882a593Smuzhiyun#            --silent|-s) opt_silent=: ;;
1638*4882a593Smuzhiyun#            # Separate non-argument short options:
1639*4882a593Smuzhiyun#            -s*)         func_split_short_opt "$_G_opt"
1640*4882a593Smuzhiyun#                         set dummy "$func_split_short_opt_name" \
1641*4882a593Smuzhiyun#                             "-$func_split_short_opt_arg" ${1+"$@"}
1642*4882a593Smuzhiyun#                         shift
1643*4882a593Smuzhiyun#                         ;;
1644*4882a593Smuzhiyun#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
1645*4882a593Smuzhiyun#          esac
1646*4882a593Smuzhiyun#        done
1647*4882a593Smuzhiyun#
1648*4882a593Smuzhiyun#        func_quote_for_eval ${1+"$@"}
1649*4882a593Smuzhiyun#        my_silent_option_result=$func_quote_for_eval_result
1650*4882a593Smuzhiyun#    }
1651*4882a593Smuzhiyun#    func_add_hook func_parse_options my_silent_option
1652*4882a593Smuzhiyun#
1653*4882a593Smuzhiyun#
1654*4882a593Smuzhiyun#    my_option_validation ()
1655*4882a593Smuzhiyun#    {
1656*4882a593Smuzhiyun#        $debug_cmd
1657*4882a593Smuzhiyun#
1658*4882a593Smuzhiyun#        $opt_silent && $opt_verbose && func_fatal_help "\
1659*4882a593Smuzhiyun#    '--silent' and '--verbose' options are mutually exclusive."
1660*4882a593Smuzhiyun#
1661*4882a593Smuzhiyun#        func_quote_for_eval ${1+"$@"}
1662*4882a593Smuzhiyun#        my_option_validation_result=$func_quote_for_eval_result
1663*4882a593Smuzhiyun#    }
1664*4882a593Smuzhiyun#    func_add_hook func_validate_options my_option_validation
1665*4882a593Smuzhiyun#
1666*4882a593Smuzhiyun# You'll alse need to manually amend $usage_message to reflect the extra
1667*4882a593Smuzhiyun# options you parse.  It's preferable to append if you can, so that
1668*4882a593Smuzhiyun# multiple option parsing hooks can be added safely.
1669*4882a593Smuzhiyun
1670*4882a593Smuzhiyun
1671*4882a593Smuzhiyun# func_options [ARG]...
1672*4882a593Smuzhiyun# ---------------------
1673*4882a593Smuzhiyun# All the functions called inside func_options are hookable. See the
1674*4882a593Smuzhiyun# individual implementations for details.
1675*4882a593Smuzhiyunfunc_hookable func_options
1676*4882a593Smuzhiyunfunc_options ()
1677*4882a593Smuzhiyun{
1678*4882a593Smuzhiyun    $debug_cmd
1679*4882a593Smuzhiyun
1680*4882a593Smuzhiyun    func_options_prep ${1+"$@"}
1681*4882a593Smuzhiyun    eval func_parse_options \
1682*4882a593Smuzhiyun        ${func_options_prep_result+"$func_options_prep_result"}
1683*4882a593Smuzhiyun    eval func_validate_options \
1684*4882a593Smuzhiyun        ${func_parse_options_result+"$func_parse_options_result"}
1685*4882a593Smuzhiyun
1686*4882a593Smuzhiyun    eval func_run_hooks func_options \
1687*4882a593Smuzhiyun        ${func_validate_options_result+"$func_validate_options_result"}
1688*4882a593Smuzhiyun
1689*4882a593Smuzhiyun    # save modified positional parameters for caller
1690*4882a593Smuzhiyun    func_options_result=$func_run_hooks_result
1691*4882a593Smuzhiyun}
1692*4882a593Smuzhiyun
1693*4882a593Smuzhiyun
1694*4882a593Smuzhiyun# func_options_prep [ARG]...
1695*4882a593Smuzhiyun# --------------------------
1696*4882a593Smuzhiyun# All initialisations required before starting the option parse loop.
1697*4882a593Smuzhiyun# Note that when calling hook functions, we pass through the list of
1698*4882a593Smuzhiyun# positional parameters.  If a hook function modifies that list, and
1699*4882a593Smuzhiyun# needs to propogate that back to rest of this script, then the complete
1700*4882a593Smuzhiyun# modified list must be put in 'func_run_hooks_result' before
1701*4882a593Smuzhiyun# returning.
1702*4882a593Smuzhiyunfunc_hookable func_options_prep
1703*4882a593Smuzhiyunfunc_options_prep ()
1704*4882a593Smuzhiyun{
1705*4882a593Smuzhiyun    $debug_cmd
1706*4882a593Smuzhiyun
1707*4882a593Smuzhiyun    # Option defaults:
1708*4882a593Smuzhiyun    opt_verbose=false
1709*4882a593Smuzhiyun    opt_warning_types=
1710*4882a593Smuzhiyun
1711*4882a593Smuzhiyun    func_run_hooks func_options_prep ${1+"$@"}
1712*4882a593Smuzhiyun
1713*4882a593Smuzhiyun    # save modified positional parameters for caller
1714*4882a593Smuzhiyun    func_options_prep_result=$func_run_hooks_result
1715*4882a593Smuzhiyun}
1716*4882a593Smuzhiyun
1717*4882a593Smuzhiyun
1718*4882a593Smuzhiyun# func_parse_options [ARG]...
1719*4882a593Smuzhiyun# ---------------------------
1720*4882a593Smuzhiyun# The main option parsing loop.
1721*4882a593Smuzhiyunfunc_hookable func_parse_options
1722*4882a593Smuzhiyunfunc_parse_options ()
1723*4882a593Smuzhiyun{
1724*4882a593Smuzhiyun    $debug_cmd
1725*4882a593Smuzhiyun
1726*4882a593Smuzhiyun    func_parse_options_result=
1727*4882a593Smuzhiyun
1728*4882a593Smuzhiyun    # this just eases exit handling
1729*4882a593Smuzhiyun    while test $# -gt 0; do
1730*4882a593Smuzhiyun      # Defer to hook functions for initial option parsing, so they
1731*4882a593Smuzhiyun      # get priority in the event of reusing an option name.
1732*4882a593Smuzhiyun      func_run_hooks func_parse_options ${1+"$@"}
1733*4882a593Smuzhiyun
1734*4882a593Smuzhiyun      # Adjust func_parse_options positional parameters to match
1735*4882a593Smuzhiyun      eval set dummy "$func_run_hooks_result"; shift
1736*4882a593Smuzhiyun
1737*4882a593Smuzhiyun      # Break out of the loop if we already parsed every option.
1738*4882a593Smuzhiyun      test $# -gt 0 || break
1739*4882a593Smuzhiyun
1740*4882a593Smuzhiyun      _G_opt=$1
1741*4882a593Smuzhiyun      shift
1742*4882a593Smuzhiyun      case $_G_opt in
1743*4882a593Smuzhiyun        --debug|-x)   debug_cmd='set -x'
1744*4882a593Smuzhiyun                      func_echo "enabling shell trace mode"
1745*4882a593Smuzhiyun                      $debug_cmd
1746*4882a593Smuzhiyun                      ;;
1747*4882a593Smuzhiyun
1748*4882a593Smuzhiyun        --no-warnings|--no-warning|--no-warn)
1749*4882a593Smuzhiyun                      set dummy --warnings none ${1+"$@"}
1750*4882a593Smuzhiyun                      shift
1751*4882a593Smuzhiyun		      ;;
1752*4882a593Smuzhiyun
1753*4882a593Smuzhiyun        --warnings|--warning|-W)
1754*4882a593Smuzhiyun                      test $# = 0 && func_missing_arg $_G_opt && break
1755*4882a593Smuzhiyun                      case " $warning_categories $1" in
1756*4882a593Smuzhiyun                        *" $1 "*)
1757*4882a593Smuzhiyun                          # trailing space prevents matching last $1 above
1758*4882a593Smuzhiyun                          func_append_uniq opt_warning_types " $1"
1759*4882a593Smuzhiyun                          ;;
1760*4882a593Smuzhiyun                        *all)
1761*4882a593Smuzhiyun                          opt_warning_types=$warning_categories
1762*4882a593Smuzhiyun                          ;;
1763*4882a593Smuzhiyun                        *none)
1764*4882a593Smuzhiyun                          opt_warning_types=none
1765*4882a593Smuzhiyun                          warning_func=:
1766*4882a593Smuzhiyun                          ;;
1767*4882a593Smuzhiyun                        *error)
1768*4882a593Smuzhiyun                          opt_warning_types=$warning_categories
1769*4882a593Smuzhiyun                          warning_func=func_fatal_error
1770*4882a593Smuzhiyun                          ;;
1771*4882a593Smuzhiyun                        *)
1772*4882a593Smuzhiyun                          func_fatal_error \
1773*4882a593Smuzhiyun                             "unsupported warning category: '$1'"
1774*4882a593Smuzhiyun                          ;;
1775*4882a593Smuzhiyun                      esac
1776*4882a593Smuzhiyun                      shift
1777*4882a593Smuzhiyun                      ;;
1778*4882a593Smuzhiyun
1779*4882a593Smuzhiyun        --verbose|-v) opt_verbose=: ;;
1780*4882a593Smuzhiyun        --version)    func_version ;;
1781*4882a593Smuzhiyun        -\?|-h)       func_usage ;;
1782*4882a593Smuzhiyun        --help)       func_help ;;
1783*4882a593Smuzhiyun
1784*4882a593Smuzhiyun	# Separate optargs to long options (plugins may need this):
1785*4882a593Smuzhiyun	--*=*)        func_split_equals "$_G_opt"
1786*4882a593Smuzhiyun	              set dummy "$func_split_equals_lhs" \
1787*4882a593Smuzhiyun                          "$func_split_equals_rhs" ${1+"$@"}
1788*4882a593Smuzhiyun                      shift
1789*4882a593Smuzhiyun                      ;;
1790*4882a593Smuzhiyun
1791*4882a593Smuzhiyun       # Separate optargs to short options:
1792*4882a593Smuzhiyun        -W*)
1793*4882a593Smuzhiyun                      func_split_short_opt "$_G_opt"
1794*4882a593Smuzhiyun                      set dummy "$func_split_short_opt_name" \
1795*4882a593Smuzhiyun                          "$func_split_short_opt_arg" ${1+"$@"}
1796*4882a593Smuzhiyun                      shift
1797*4882a593Smuzhiyun                      ;;
1798*4882a593Smuzhiyun
1799*4882a593Smuzhiyun        # Separate non-argument short options:
1800*4882a593Smuzhiyun        -\?*|-h*|-v*|-x*)
1801*4882a593Smuzhiyun                      func_split_short_opt "$_G_opt"
1802*4882a593Smuzhiyun                      set dummy "$func_split_short_opt_name" \
1803*4882a593Smuzhiyun                          "-$func_split_short_opt_arg" ${1+"$@"}
1804*4882a593Smuzhiyun                      shift
1805*4882a593Smuzhiyun                      ;;
1806*4882a593Smuzhiyun
1807*4882a593Smuzhiyun        --)           break ;;
1808*4882a593Smuzhiyun        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1809*4882a593Smuzhiyun        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1810*4882a593Smuzhiyun      esac
1811*4882a593Smuzhiyun    done
1812*4882a593Smuzhiyun
1813*4882a593Smuzhiyun    # save modified positional parameters for caller
1814*4882a593Smuzhiyun    func_quote_for_eval ${1+"$@"}
1815*4882a593Smuzhiyun    func_parse_options_result=$func_quote_for_eval_result
1816*4882a593Smuzhiyun}
1817*4882a593Smuzhiyun
1818*4882a593Smuzhiyun
1819*4882a593Smuzhiyun# func_validate_options [ARG]...
1820*4882a593Smuzhiyun# ------------------------------
1821*4882a593Smuzhiyun# Perform any sanity checks on option settings and/or unconsumed
1822*4882a593Smuzhiyun# arguments.
1823*4882a593Smuzhiyunfunc_hookable func_validate_options
1824*4882a593Smuzhiyunfunc_validate_options ()
1825*4882a593Smuzhiyun{
1826*4882a593Smuzhiyun    $debug_cmd
1827*4882a593Smuzhiyun
1828*4882a593Smuzhiyun    # Display all warnings if -W was not given.
1829*4882a593Smuzhiyun    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1830*4882a593Smuzhiyun
1831*4882a593Smuzhiyun    func_run_hooks func_validate_options ${1+"$@"}
1832*4882a593Smuzhiyun
1833*4882a593Smuzhiyun    # Bail if the options were screwed!
1834*4882a593Smuzhiyun    $exit_cmd $EXIT_FAILURE
1835*4882a593Smuzhiyun
1836*4882a593Smuzhiyun    # save modified positional parameters for caller
1837*4882a593Smuzhiyun    func_validate_options_result=$func_run_hooks_result
1838*4882a593Smuzhiyun}
1839*4882a593Smuzhiyun
1840*4882a593Smuzhiyun
1841*4882a593Smuzhiyun
1842*4882a593Smuzhiyun## ----------------- ##
1843*4882a593Smuzhiyun## Helper functions. ##
1844*4882a593Smuzhiyun## ----------------- ##
1845*4882a593Smuzhiyun
1846*4882a593Smuzhiyun# This section contains the helper functions used by the rest of the
1847*4882a593Smuzhiyun# hookable option parser framework in ascii-betical order.
1848*4882a593Smuzhiyun
1849*4882a593Smuzhiyun
1850*4882a593Smuzhiyun# func_fatal_help ARG...
1851*4882a593Smuzhiyun# ----------------------
1852*4882a593Smuzhiyun# Echo program name prefixed message to standard error, followed by
1853*4882a593Smuzhiyun# a help hint, and exit.
1854*4882a593Smuzhiyunfunc_fatal_help ()
1855*4882a593Smuzhiyun{
1856*4882a593Smuzhiyun    $debug_cmd
1857*4882a593Smuzhiyun
1858*4882a593Smuzhiyun    eval \$ECHO \""Usage: $usage"\"
1859*4882a593Smuzhiyun    eval \$ECHO \""$fatal_help"\"
1860*4882a593Smuzhiyun    func_error ${1+"$@"}
1861*4882a593Smuzhiyun    exit $EXIT_FAILURE
1862*4882a593Smuzhiyun}
1863*4882a593Smuzhiyun
1864*4882a593Smuzhiyun
1865*4882a593Smuzhiyun# func_help
1866*4882a593Smuzhiyun# ---------
1867*4882a593Smuzhiyun# Echo long help message to standard output and exit.
1868*4882a593Smuzhiyunfunc_help ()
1869*4882a593Smuzhiyun{
1870*4882a593Smuzhiyun    $debug_cmd
1871*4882a593Smuzhiyun
1872*4882a593Smuzhiyun    func_usage_message
1873*4882a593Smuzhiyun    $ECHO "$long_help_message"
1874*4882a593Smuzhiyun    exit 0
1875*4882a593Smuzhiyun}
1876*4882a593Smuzhiyun
1877*4882a593Smuzhiyun
1878*4882a593Smuzhiyun# func_missing_arg ARGNAME
1879*4882a593Smuzhiyun# ------------------------
1880*4882a593Smuzhiyun# Echo program name prefixed message to standard error and set global
1881*4882a593Smuzhiyun# exit_cmd.
1882*4882a593Smuzhiyunfunc_missing_arg ()
1883*4882a593Smuzhiyun{
1884*4882a593Smuzhiyun    $debug_cmd
1885*4882a593Smuzhiyun
1886*4882a593Smuzhiyun    func_error "Missing argument for '$1'."
1887*4882a593Smuzhiyun    exit_cmd=exit
1888*4882a593Smuzhiyun}
1889*4882a593Smuzhiyun
1890*4882a593Smuzhiyun
1891*4882a593Smuzhiyun# func_split_equals STRING
1892*4882a593Smuzhiyun# ------------------------
1893*4882a593Smuzhiyun# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
1894*4882a593Smuzhiyun# splitting STRING at the '=' sign.
1895*4882a593Smuzhiyuntest -z "$_G_HAVE_XSI_OPS" \
1896*4882a593Smuzhiyun    && (eval 'x=a/b/c;
1897*4882a593Smuzhiyun      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
1898*4882a593Smuzhiyun    && _G_HAVE_XSI_OPS=yes
1899*4882a593Smuzhiyun
1900*4882a593Smuzhiyunif test yes = "$_G_HAVE_XSI_OPS"
1901*4882a593Smuzhiyunthen
1902*4882a593Smuzhiyun  # This is an XSI compatible shell, allowing a faster implementation...
1903*4882a593Smuzhiyun  eval 'func_split_equals ()
1904*4882a593Smuzhiyun  {
1905*4882a593Smuzhiyun      $debug_cmd
1906*4882a593Smuzhiyun
1907*4882a593Smuzhiyun      func_split_equals_lhs=${1%%=*}
1908*4882a593Smuzhiyun      func_split_equals_rhs=${1#*=}
1909*4882a593Smuzhiyun      test "x$func_split_equals_lhs" = "x$1" \
1910*4882a593Smuzhiyun        && func_split_equals_rhs=
1911*4882a593Smuzhiyun  }'
1912*4882a593Smuzhiyunelse
1913*4882a593Smuzhiyun  # ...otherwise fall back to using expr, which is often a shell builtin.
1914*4882a593Smuzhiyun  func_split_equals ()
1915*4882a593Smuzhiyun  {
1916*4882a593Smuzhiyun      $debug_cmd
1917*4882a593Smuzhiyun
1918*4882a593Smuzhiyun      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
1919*4882a593Smuzhiyun      func_split_equals_rhs=
1920*4882a593Smuzhiyun      test "x$func_split_equals_lhs" = "x$1" \
1921*4882a593Smuzhiyun        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
1922*4882a593Smuzhiyun  }
1923*4882a593Smuzhiyunfi #func_split_equals
1924*4882a593Smuzhiyun
1925*4882a593Smuzhiyun
1926*4882a593Smuzhiyun# func_split_short_opt SHORTOPT
1927*4882a593Smuzhiyun# -----------------------------
1928*4882a593Smuzhiyun# Set func_split_short_opt_name and func_split_short_opt_arg shell
1929*4882a593Smuzhiyun# variables after splitting SHORTOPT after the 2nd character.
1930*4882a593Smuzhiyunif test yes = "$_G_HAVE_XSI_OPS"
1931*4882a593Smuzhiyunthen
1932*4882a593Smuzhiyun  # This is an XSI compatible shell, allowing a faster implementation...
1933*4882a593Smuzhiyun  eval 'func_split_short_opt ()
1934*4882a593Smuzhiyun  {
1935*4882a593Smuzhiyun      $debug_cmd
1936*4882a593Smuzhiyun
1937*4882a593Smuzhiyun      func_split_short_opt_arg=${1#??}
1938*4882a593Smuzhiyun      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1939*4882a593Smuzhiyun  }'
1940*4882a593Smuzhiyunelse
1941*4882a593Smuzhiyun  # ...otherwise fall back to using expr, which is often a shell builtin.
1942*4882a593Smuzhiyun  func_split_short_opt ()
1943*4882a593Smuzhiyun  {
1944*4882a593Smuzhiyun      $debug_cmd
1945*4882a593Smuzhiyun
1946*4882a593Smuzhiyun      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1947*4882a593Smuzhiyun      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1948*4882a593Smuzhiyun  }
1949*4882a593Smuzhiyunfi #func_split_short_opt
1950*4882a593Smuzhiyun
1951*4882a593Smuzhiyun
1952*4882a593Smuzhiyun# func_usage
1953*4882a593Smuzhiyun# ----------
1954*4882a593Smuzhiyun# Echo short help message to standard output and exit.
1955*4882a593Smuzhiyunfunc_usage ()
1956*4882a593Smuzhiyun{
1957*4882a593Smuzhiyun    $debug_cmd
1958*4882a593Smuzhiyun
1959*4882a593Smuzhiyun    func_usage_message
1960*4882a593Smuzhiyun    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
1961*4882a593Smuzhiyun    exit 0
1962*4882a593Smuzhiyun}
1963*4882a593Smuzhiyun
1964*4882a593Smuzhiyun
1965*4882a593Smuzhiyun# func_usage_message
1966*4882a593Smuzhiyun# ------------------
1967*4882a593Smuzhiyun# Echo short help message to standard output.
1968*4882a593Smuzhiyunfunc_usage_message ()
1969*4882a593Smuzhiyun{
1970*4882a593Smuzhiyun    $debug_cmd
1971*4882a593Smuzhiyun
1972*4882a593Smuzhiyun    eval \$ECHO \""Usage: $usage"\"
1973*4882a593Smuzhiyun    echo
1974*4882a593Smuzhiyun    $SED -n 's|^# ||
1975*4882a593Smuzhiyun        /^Written by/{
1976*4882a593Smuzhiyun          x;p;x
1977*4882a593Smuzhiyun        }
1978*4882a593Smuzhiyun	h
1979*4882a593Smuzhiyun	/^Written by/q' < "$progpath"
1980*4882a593Smuzhiyun    echo
1981*4882a593Smuzhiyun    eval \$ECHO \""$usage_message"\"
1982*4882a593Smuzhiyun}
1983*4882a593Smuzhiyun
1984*4882a593Smuzhiyun
1985*4882a593Smuzhiyun# func_version
1986*4882a593Smuzhiyun# ------------
1987*4882a593Smuzhiyun# Echo version message to standard output and exit.
1988*4882a593Smuzhiyunfunc_version ()
1989*4882a593Smuzhiyun{
1990*4882a593Smuzhiyun    $debug_cmd
1991*4882a593Smuzhiyun
1992*4882a593Smuzhiyun    printf '%s\n' "$progname $scriptversion"
1993*4882a593Smuzhiyun    $SED -n '
1994*4882a593Smuzhiyun        /(C)/!b go
1995*4882a593Smuzhiyun        :more
1996*4882a593Smuzhiyun        /\./!{
1997*4882a593Smuzhiyun          N
1998*4882a593Smuzhiyun          s|\n# | |
1999*4882a593Smuzhiyun          b more
2000*4882a593Smuzhiyun        }
2001*4882a593Smuzhiyun        :go
2002*4882a593Smuzhiyun        /^# Written by /,/# warranty; / {
2003*4882a593Smuzhiyun          s|^# ||
2004*4882a593Smuzhiyun          s|^# *$||
2005*4882a593Smuzhiyun          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2006*4882a593Smuzhiyun          p
2007*4882a593Smuzhiyun        }
2008*4882a593Smuzhiyun        /^# Written by / {
2009*4882a593Smuzhiyun          s|^# ||
2010*4882a593Smuzhiyun          p
2011*4882a593Smuzhiyun        }
2012*4882a593Smuzhiyun        /^warranty; /q' < "$progpath"
2013*4882a593Smuzhiyun
2014*4882a593Smuzhiyun    exit $?
2015*4882a593Smuzhiyun}
2016*4882a593Smuzhiyun
2017*4882a593Smuzhiyun
2018*4882a593Smuzhiyun# Local variables:
2019*4882a593Smuzhiyun# mode: shell-script
2020*4882a593Smuzhiyun# sh-indentation: 2
2021*4882a593Smuzhiyun# eval: (add-hook 'before-save-hook 'time-stamp)
2022*4882a593Smuzhiyun# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2023*4882a593Smuzhiyun# time-stamp-time-zone: "UTC"
2024*4882a593Smuzhiyun# End:
2025*4882a593Smuzhiyun
2026*4882a593Smuzhiyun# Set a version string.
2027*4882a593Smuzhiyunscriptversion='(GNU libtool) 2.4.6'
2028*4882a593Smuzhiyun
2029*4882a593Smuzhiyun
2030*4882a593Smuzhiyun# func_echo ARG...
2031*4882a593Smuzhiyun# ----------------
2032*4882a593Smuzhiyun# Libtool also displays the current mode in messages, so override
2033*4882a593Smuzhiyun# funclib.sh func_echo with this custom definition.
2034*4882a593Smuzhiyunfunc_echo ()
2035*4882a593Smuzhiyun{
2036*4882a593Smuzhiyun    $debug_cmd
2037*4882a593Smuzhiyun
2038*4882a593Smuzhiyun    _G_message=$*
2039*4882a593Smuzhiyun
2040*4882a593Smuzhiyun    func_echo_IFS=$IFS
2041*4882a593Smuzhiyun    IFS=$nl
2042*4882a593Smuzhiyun    for _G_line in $_G_message; do
2043*4882a593Smuzhiyun      IFS=$func_echo_IFS
2044*4882a593Smuzhiyun      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2045*4882a593Smuzhiyun    done
2046*4882a593Smuzhiyun    IFS=$func_echo_IFS
2047*4882a593Smuzhiyun}
2048*4882a593Smuzhiyun
2049*4882a593Smuzhiyun
2050*4882a593Smuzhiyun# func_warning ARG...
2051*4882a593Smuzhiyun# -------------------
2052*4882a593Smuzhiyun# Libtool warnings are not categorized, so override funclib.sh
2053*4882a593Smuzhiyun# func_warning with this simpler definition.
2054*4882a593Smuzhiyunfunc_warning ()
2055*4882a593Smuzhiyun{
2056*4882a593Smuzhiyun    $debug_cmd
2057*4882a593Smuzhiyun
2058*4882a593Smuzhiyun    $warning_func ${1+"$@"}
2059*4882a593Smuzhiyun}
2060*4882a593Smuzhiyun
2061*4882a593Smuzhiyun
2062*4882a593Smuzhiyun## ---------------- ##
2063*4882a593Smuzhiyun## Options parsing. ##
2064*4882a593Smuzhiyun## ---------------- ##
2065*4882a593Smuzhiyun
2066*4882a593Smuzhiyun# Hook in the functions to make sure our own options are parsed during
2067*4882a593Smuzhiyun# the option parsing loop.
2068*4882a593Smuzhiyun
2069*4882a593Smuzhiyunusage='$progpath [OPTION]... [MODE-ARG]...'
2070*4882a593Smuzhiyun
2071*4882a593Smuzhiyun# Short help message in response to '-h'.
2072*4882a593Smuzhiyunusage_message="Options:
2073*4882a593Smuzhiyun       --config             show all configuration variables
2074*4882a593Smuzhiyun       --debug              enable verbose shell tracing
2075*4882a593Smuzhiyun   -n, --dry-run            display commands without modifying any files
2076*4882a593Smuzhiyun       --features           display basic configuration information and exit
2077*4882a593Smuzhiyun       --mode=MODE          use operation mode MODE
2078*4882a593Smuzhiyun       --no-warnings        equivalent to '-Wnone'
2079*4882a593Smuzhiyun       --preserve-dup-deps  don't remove duplicate dependency libraries
2080*4882a593Smuzhiyun       --quiet, --silent    don't print informational messages
2081*4882a593Smuzhiyun       --tag=TAG            use configuration variables from tag TAG
2082*4882a593Smuzhiyun   -v, --verbose            print more informational messages than default
2083*4882a593Smuzhiyun       --version            print version information
2084*4882a593Smuzhiyun   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2085*4882a593Smuzhiyun   -h, --help, --help-all   print short, long, or detailed help message
2086*4882a593Smuzhiyun"
2087*4882a593Smuzhiyun
2088*4882a593Smuzhiyun# Additional text appended to 'usage_message' in response to '--help'.
2089*4882a593Smuzhiyunfunc_help ()
2090*4882a593Smuzhiyun{
2091*4882a593Smuzhiyun    $debug_cmd
2092*4882a593Smuzhiyun
2093*4882a593Smuzhiyun    func_usage_message
2094*4882a593Smuzhiyun    $ECHO "$long_help_message
2095*4882a593Smuzhiyun
2096*4882a593SmuzhiyunMODE must be one of the following:
2097*4882a593Smuzhiyun
2098*4882a593Smuzhiyun       clean           remove files from the build directory
2099*4882a593Smuzhiyun       compile         compile a source file into a libtool object
2100*4882a593Smuzhiyun       execute         automatically set library path, then run a program
2101*4882a593Smuzhiyun       finish          complete the installation of libtool libraries
2102*4882a593Smuzhiyun       install         install libraries or executables
2103*4882a593Smuzhiyun       link            create a library or an executable
2104*4882a593Smuzhiyun       uninstall       remove libraries from an installed directory
2105*4882a593Smuzhiyun
2106*4882a593SmuzhiyunMODE-ARGS vary depending on the MODE.  When passed as first option,
2107*4882a593Smuzhiyun'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2108*4882a593SmuzhiyunTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2109*4882a593Smuzhiyun
2110*4882a593SmuzhiyunWhen reporting a bug, please describe a test case to reproduce it and
2111*4882a593Smuzhiyuninclude the following information:
2112*4882a593Smuzhiyun
2113*4882a593Smuzhiyun       host-triplet:   $host
2114*4882a593Smuzhiyun       shell:          $SHELL
2115*4882a593Smuzhiyun       compiler:       $LTCC
2116*4882a593Smuzhiyun       compiler flags: $LTCFLAGS
2117*4882a593Smuzhiyun       linker:         $LD (gnu? $with_gnu_ld)
2118*4882a593Smuzhiyun       version:        $progname (GNU libtool) 2.4.6
2119*4882a593Smuzhiyun       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2120*4882a593Smuzhiyun       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2121*4882a593Smuzhiyun
2122*4882a593SmuzhiyunReport bugs to <bug-libtool@gnu.org>.
2123*4882a593SmuzhiyunGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2124*4882a593SmuzhiyunGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2125*4882a593Smuzhiyun    exit 0
2126*4882a593Smuzhiyun}
2127*4882a593Smuzhiyun
2128*4882a593Smuzhiyun
2129*4882a593Smuzhiyun# func_lo2o OBJECT-NAME
2130*4882a593Smuzhiyun# ---------------------
2131*4882a593Smuzhiyun# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2132*4882a593Smuzhiyun# object suffix.
2133*4882a593Smuzhiyun
2134*4882a593Smuzhiyunlo2o=s/\\.lo\$/.$objext/
2135*4882a593Smuzhiyuno2lo=s/\\.$objext\$/.lo/
2136*4882a593Smuzhiyun
2137*4882a593Smuzhiyunif test yes = "$_G_HAVE_XSI_OPS"; then
2138*4882a593Smuzhiyun  eval 'func_lo2o ()
2139*4882a593Smuzhiyun  {
2140*4882a593Smuzhiyun    case $1 in
2141*4882a593Smuzhiyun      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2142*4882a593Smuzhiyun      *   ) func_lo2o_result=$1               ;;
2143*4882a593Smuzhiyun    esac
2144*4882a593Smuzhiyun  }'
2145*4882a593Smuzhiyun
2146*4882a593Smuzhiyun  # func_xform LIBOBJ-OR-SOURCE
2147*4882a593Smuzhiyun  # ---------------------------
2148*4882a593Smuzhiyun  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2149*4882a593Smuzhiyun  # suffix to a '.lo' libtool-object suffix.
2150*4882a593Smuzhiyun  eval 'func_xform ()
2151*4882a593Smuzhiyun  {
2152*4882a593Smuzhiyun    func_xform_result=${1%.*}.lo
2153*4882a593Smuzhiyun  }'
2154*4882a593Smuzhiyunelse
2155*4882a593Smuzhiyun  # ...otherwise fall back to using sed.
2156*4882a593Smuzhiyun  func_lo2o ()
2157*4882a593Smuzhiyun  {
2158*4882a593Smuzhiyun    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2159*4882a593Smuzhiyun  }
2160*4882a593Smuzhiyun
2161*4882a593Smuzhiyun  func_xform ()
2162*4882a593Smuzhiyun  {
2163*4882a593Smuzhiyun    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2164*4882a593Smuzhiyun  }
2165*4882a593Smuzhiyunfi
2166*4882a593Smuzhiyun
2167*4882a593Smuzhiyun
2168*4882a593Smuzhiyun# func_fatal_configuration ARG...
2169*4882a593Smuzhiyun# -------------------------------
2170*4882a593Smuzhiyun# Echo program name prefixed message to standard error, followed by
2171*4882a593Smuzhiyun# a configuration failure hint, and exit.
2172*4882a593Smuzhiyunfunc_fatal_configuration ()
2173*4882a593Smuzhiyun{
2174*4882a593Smuzhiyun    func__fatal_error ${1+"$@"} \
2175*4882a593Smuzhiyun      "See the $PACKAGE documentation for more information." \
2176*4882a593Smuzhiyun      "Fatal configuration error."
2177*4882a593Smuzhiyun}
2178*4882a593Smuzhiyun
2179*4882a593Smuzhiyun
2180*4882a593Smuzhiyun# func_config
2181*4882a593Smuzhiyun# -----------
2182*4882a593Smuzhiyun# Display the configuration for all the tags in this script.
2183*4882a593Smuzhiyunfunc_config ()
2184*4882a593Smuzhiyun{
2185*4882a593Smuzhiyun    re_begincf='^# ### BEGIN LIBTOOL'
2186*4882a593Smuzhiyun    re_endcf='^# ### END LIBTOOL'
2187*4882a593Smuzhiyun
2188*4882a593Smuzhiyun    # Default configuration.
2189*4882a593Smuzhiyun    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2190*4882a593Smuzhiyun
2191*4882a593Smuzhiyun    # Now print the configurations for the tags.
2192*4882a593Smuzhiyun    for tagname in $taglist; do
2193*4882a593Smuzhiyun      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2194*4882a593Smuzhiyun    done
2195*4882a593Smuzhiyun
2196*4882a593Smuzhiyun    exit $?
2197*4882a593Smuzhiyun}
2198*4882a593Smuzhiyun
2199*4882a593Smuzhiyun
2200*4882a593Smuzhiyun# func_features
2201*4882a593Smuzhiyun# -------------
2202*4882a593Smuzhiyun# Display the features supported by this script.
2203*4882a593Smuzhiyunfunc_features ()
2204*4882a593Smuzhiyun{
2205*4882a593Smuzhiyun    echo "host: $host"
2206*4882a593Smuzhiyun    if test yes = "$build_libtool_libs"; then
2207*4882a593Smuzhiyun      echo "enable shared libraries"
2208*4882a593Smuzhiyun    else
2209*4882a593Smuzhiyun      echo "disable shared libraries"
2210*4882a593Smuzhiyun    fi
2211*4882a593Smuzhiyun    if test yes = "$build_old_libs"; then
2212*4882a593Smuzhiyun      echo "enable static libraries"
2213*4882a593Smuzhiyun    else
2214*4882a593Smuzhiyun      echo "disable static libraries"
2215*4882a593Smuzhiyun    fi
2216*4882a593Smuzhiyun
2217*4882a593Smuzhiyun    exit $?
2218*4882a593Smuzhiyun}
2219*4882a593Smuzhiyun
2220*4882a593Smuzhiyun
2221*4882a593Smuzhiyun# func_enable_tag TAGNAME
2222*4882a593Smuzhiyun# -----------------------
2223*4882a593Smuzhiyun# Verify that TAGNAME is valid, and either flag an error and exit, or
2224*4882a593Smuzhiyun# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2225*4882a593Smuzhiyun# variable here.
2226*4882a593Smuzhiyunfunc_enable_tag ()
2227*4882a593Smuzhiyun{
2228*4882a593Smuzhiyun    # Global variable:
2229*4882a593Smuzhiyun    tagname=$1
2230*4882a593Smuzhiyun
2231*4882a593Smuzhiyun    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2232*4882a593Smuzhiyun    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2233*4882a593Smuzhiyun    sed_extractcf=/$re_begincf/,/$re_endcf/p
2234*4882a593Smuzhiyun
2235*4882a593Smuzhiyun    # Validate tagname.
2236*4882a593Smuzhiyun    case $tagname in
2237*4882a593Smuzhiyun      *[!-_A-Za-z0-9,/]*)
2238*4882a593Smuzhiyun        func_fatal_error "invalid tag name: $tagname"
2239*4882a593Smuzhiyun        ;;
2240*4882a593Smuzhiyun    esac
2241*4882a593Smuzhiyun
2242*4882a593Smuzhiyun    # Don't test for the "default" C tag, as we know it's
2243*4882a593Smuzhiyun    # there but not specially marked.
2244*4882a593Smuzhiyun    case $tagname in
2245*4882a593Smuzhiyun        CC) ;;
2246*4882a593Smuzhiyun    *)
2247*4882a593Smuzhiyun        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2248*4882a593Smuzhiyun	  taglist="$taglist $tagname"
2249*4882a593Smuzhiyun
2250*4882a593Smuzhiyun	  # Evaluate the configuration.  Be careful to quote the path
2251*4882a593Smuzhiyun	  # and the sed script, to avoid splitting on whitespace, but
2252*4882a593Smuzhiyun	  # also don't use non-portable quotes within backquotes within
2253*4882a593Smuzhiyun	  # quotes we have to do it in 2 steps:
2254*4882a593Smuzhiyun	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2255*4882a593Smuzhiyun	  eval "$extractedcf"
2256*4882a593Smuzhiyun        else
2257*4882a593Smuzhiyun	  func_error "ignoring unknown tag $tagname"
2258*4882a593Smuzhiyun        fi
2259*4882a593Smuzhiyun        ;;
2260*4882a593Smuzhiyun    esac
2261*4882a593Smuzhiyun}
2262*4882a593Smuzhiyun
2263*4882a593Smuzhiyun
2264*4882a593Smuzhiyun# func_check_version_match
2265*4882a593Smuzhiyun# ------------------------
2266*4882a593Smuzhiyun# Ensure that we are using m4 macros, and libtool script from the same
2267*4882a593Smuzhiyun# release of libtool.
2268*4882a593Smuzhiyunfunc_check_version_match ()
2269*4882a593Smuzhiyun{
2270*4882a593Smuzhiyun    if test "$package_revision" != "$macro_revision"; then
2271*4882a593Smuzhiyun      if test "$VERSION" != "$macro_version"; then
2272*4882a593Smuzhiyun        if test -z "$macro_version"; then
2273*4882a593Smuzhiyun          cat >&2 <<_LT_EOF
2274*4882a593Smuzhiyun$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2275*4882a593Smuzhiyun$progname: definition of this LT_INIT comes from an older release.
2276*4882a593Smuzhiyun$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2277*4882a593Smuzhiyun$progname: and run autoconf again.
2278*4882a593Smuzhiyun_LT_EOF
2279*4882a593Smuzhiyun        else
2280*4882a593Smuzhiyun          cat >&2 <<_LT_EOF
2281*4882a593Smuzhiyun$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2282*4882a593Smuzhiyun$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2283*4882a593Smuzhiyun$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2284*4882a593Smuzhiyun$progname: and run autoconf again.
2285*4882a593Smuzhiyun_LT_EOF
2286*4882a593Smuzhiyun        fi
2287*4882a593Smuzhiyun      else
2288*4882a593Smuzhiyun        cat >&2 <<_LT_EOF
2289*4882a593Smuzhiyun$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2290*4882a593Smuzhiyun$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2291*4882a593Smuzhiyun$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2292*4882a593Smuzhiyun$progname: of $PACKAGE $VERSION and run autoconf again.
2293*4882a593Smuzhiyun_LT_EOF
2294*4882a593Smuzhiyun      fi
2295*4882a593Smuzhiyun
2296*4882a593Smuzhiyun      exit $EXIT_MISMATCH
2297*4882a593Smuzhiyun    fi
2298*4882a593Smuzhiyun}
2299*4882a593Smuzhiyun
2300*4882a593Smuzhiyun
2301*4882a593Smuzhiyun# libtool_options_prep [ARG]...
2302*4882a593Smuzhiyun# -----------------------------
2303*4882a593Smuzhiyun# Preparation for options parsed by libtool.
2304*4882a593Smuzhiyunlibtool_options_prep ()
2305*4882a593Smuzhiyun{
2306*4882a593Smuzhiyun    $debug_mode
2307*4882a593Smuzhiyun
2308*4882a593Smuzhiyun    # Option defaults:
2309*4882a593Smuzhiyun    opt_config=false
2310*4882a593Smuzhiyun    opt_dlopen=
2311*4882a593Smuzhiyun    opt_dry_run=false
2312*4882a593Smuzhiyun    opt_help=false
2313*4882a593Smuzhiyun    opt_mode=
2314*4882a593Smuzhiyun    opt_preserve_dup_deps=false
2315*4882a593Smuzhiyun    opt_quiet=false
2316*4882a593Smuzhiyun
2317*4882a593Smuzhiyun    nonopt=
2318*4882a593Smuzhiyun    preserve_args=
2319*4882a593Smuzhiyun
2320*4882a593Smuzhiyun    # Shorthand for --mode=foo, only valid as the first argument
2321*4882a593Smuzhiyun    case $1 in
2322*4882a593Smuzhiyun    clean|clea|cle|cl)
2323*4882a593Smuzhiyun      shift; set dummy --mode clean ${1+"$@"}; shift
2324*4882a593Smuzhiyun      ;;
2325*4882a593Smuzhiyun    compile|compil|compi|comp|com|co|c)
2326*4882a593Smuzhiyun      shift; set dummy --mode compile ${1+"$@"}; shift
2327*4882a593Smuzhiyun      ;;
2328*4882a593Smuzhiyun    execute|execut|execu|exec|exe|ex|e)
2329*4882a593Smuzhiyun      shift; set dummy --mode execute ${1+"$@"}; shift
2330*4882a593Smuzhiyun      ;;
2331*4882a593Smuzhiyun    finish|finis|fini|fin|fi|f)
2332*4882a593Smuzhiyun      shift; set dummy --mode finish ${1+"$@"}; shift
2333*4882a593Smuzhiyun      ;;
2334*4882a593Smuzhiyun    install|instal|insta|inst|ins|in|i)
2335*4882a593Smuzhiyun      shift; set dummy --mode install ${1+"$@"}; shift
2336*4882a593Smuzhiyun      ;;
2337*4882a593Smuzhiyun    link|lin|li|l)
2338*4882a593Smuzhiyun      shift; set dummy --mode link ${1+"$@"}; shift
2339*4882a593Smuzhiyun      ;;
2340*4882a593Smuzhiyun    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2341*4882a593Smuzhiyun      shift; set dummy --mode uninstall ${1+"$@"}; shift
2342*4882a593Smuzhiyun      ;;
2343*4882a593Smuzhiyun    esac
2344*4882a593Smuzhiyun
2345*4882a593Smuzhiyun    # Pass back the list of options.
2346*4882a593Smuzhiyun    func_quote_for_eval ${1+"$@"}
2347*4882a593Smuzhiyun    libtool_options_prep_result=$func_quote_for_eval_result
2348*4882a593Smuzhiyun}
2349*4882a593Smuzhiyunfunc_add_hook func_options_prep libtool_options_prep
2350*4882a593Smuzhiyun
2351*4882a593Smuzhiyun
2352*4882a593Smuzhiyun# libtool_parse_options [ARG]...
2353*4882a593Smuzhiyun# ---------------------------------
2354*4882a593Smuzhiyun# Provide handling for libtool specific options.
2355*4882a593Smuzhiyunlibtool_parse_options ()
2356*4882a593Smuzhiyun{
2357*4882a593Smuzhiyun    $debug_cmd
2358*4882a593Smuzhiyun
2359*4882a593Smuzhiyun    # Perform our own loop to consume as many options as possible in
2360*4882a593Smuzhiyun    # each iteration.
2361*4882a593Smuzhiyun    while test $# -gt 0; do
2362*4882a593Smuzhiyun      _G_opt=$1
2363*4882a593Smuzhiyun      shift
2364*4882a593Smuzhiyun      case $_G_opt in
2365*4882a593Smuzhiyun        --dry-run|--dryrun|-n)
2366*4882a593Smuzhiyun                        opt_dry_run=:
2367*4882a593Smuzhiyun                        ;;
2368*4882a593Smuzhiyun
2369*4882a593Smuzhiyun        --config)       func_config ;;
2370*4882a593Smuzhiyun
2371*4882a593Smuzhiyun        --dlopen|-dlopen)
2372*4882a593Smuzhiyun                        opt_dlopen="${opt_dlopen+$opt_dlopen
2373*4882a593Smuzhiyun}$1"
2374*4882a593Smuzhiyun                        shift
2375*4882a593Smuzhiyun                        ;;
2376*4882a593Smuzhiyun
2377*4882a593Smuzhiyun        --preserve-dup-deps)
2378*4882a593Smuzhiyun                        opt_preserve_dup_deps=: ;;
2379*4882a593Smuzhiyun
2380*4882a593Smuzhiyun        --features)     func_features ;;
2381*4882a593Smuzhiyun
2382*4882a593Smuzhiyun        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2383*4882a593Smuzhiyun
2384*4882a593Smuzhiyun        --help)         opt_help=: ;;
2385*4882a593Smuzhiyun
2386*4882a593Smuzhiyun        --help-all)     opt_help=': help-all' ;;
2387*4882a593Smuzhiyun
2388*4882a593Smuzhiyun        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2389*4882a593Smuzhiyun                        opt_mode=$1
2390*4882a593Smuzhiyun                        case $1 in
2391*4882a593Smuzhiyun                          # Valid mode arguments:
2392*4882a593Smuzhiyun                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2393*4882a593Smuzhiyun
2394*4882a593Smuzhiyun                          # Catch anything else as an error
2395*4882a593Smuzhiyun                          *) func_error "invalid argument for $_G_opt"
2396*4882a593Smuzhiyun                             exit_cmd=exit
2397*4882a593Smuzhiyun                             break
2398*4882a593Smuzhiyun                             ;;
2399*4882a593Smuzhiyun                        esac
2400*4882a593Smuzhiyun                        shift
2401*4882a593Smuzhiyun                        ;;
2402*4882a593Smuzhiyun
2403*4882a593Smuzhiyun        --no-silent|--no-quiet)
2404*4882a593Smuzhiyun                        opt_quiet=false
2405*4882a593Smuzhiyun                        func_append preserve_args " $_G_opt"
2406*4882a593Smuzhiyun                        ;;
2407*4882a593Smuzhiyun
2408*4882a593Smuzhiyun        --no-warnings|--no-warning|--no-warn)
2409*4882a593Smuzhiyun                        opt_warning=false
2410*4882a593Smuzhiyun                        func_append preserve_args " $_G_opt"
2411*4882a593Smuzhiyun                        ;;
2412*4882a593Smuzhiyun
2413*4882a593Smuzhiyun        --no-verbose)
2414*4882a593Smuzhiyun                        opt_verbose=false
2415*4882a593Smuzhiyun                        func_append preserve_args " $_G_opt"
2416*4882a593Smuzhiyun                        ;;
2417*4882a593Smuzhiyun
2418*4882a593Smuzhiyun        --silent|--quiet)
2419*4882a593Smuzhiyun                        opt_quiet=:
2420*4882a593Smuzhiyun                        opt_verbose=false
2421*4882a593Smuzhiyun                        func_append preserve_args " $_G_opt"
2422*4882a593Smuzhiyun                        ;;
2423*4882a593Smuzhiyun
2424*4882a593Smuzhiyun        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2425*4882a593Smuzhiyun                        opt_tag=$1
2426*4882a593Smuzhiyun                        func_append preserve_args " $_G_opt $1"
2427*4882a593Smuzhiyun                        func_enable_tag "$1"
2428*4882a593Smuzhiyun                        shift
2429*4882a593Smuzhiyun                        ;;
2430*4882a593Smuzhiyun
2431*4882a593Smuzhiyun        --verbose|-v)   opt_quiet=false
2432*4882a593Smuzhiyun                        opt_verbose=:
2433*4882a593Smuzhiyun                        func_append preserve_args " $_G_opt"
2434*4882a593Smuzhiyun                        ;;
2435*4882a593Smuzhiyun
2436*4882a593Smuzhiyun	# An option not handled by this hook function:
2437*4882a593Smuzhiyun        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
2438*4882a593Smuzhiyun      esac
2439*4882a593Smuzhiyun    done
2440*4882a593Smuzhiyun
2441*4882a593Smuzhiyun
2442*4882a593Smuzhiyun    # save modified positional parameters for caller
2443*4882a593Smuzhiyun    func_quote_for_eval ${1+"$@"}
2444*4882a593Smuzhiyun    libtool_parse_options_result=$func_quote_for_eval_result
2445*4882a593Smuzhiyun}
2446*4882a593Smuzhiyunfunc_add_hook func_parse_options libtool_parse_options
2447*4882a593Smuzhiyun
2448*4882a593Smuzhiyun
2449*4882a593Smuzhiyun
2450*4882a593Smuzhiyun# libtool_validate_options [ARG]...
2451*4882a593Smuzhiyun# ---------------------------------
2452*4882a593Smuzhiyun# Perform any sanity checks on option settings and/or unconsumed
2453*4882a593Smuzhiyun# arguments.
2454*4882a593Smuzhiyunlibtool_validate_options ()
2455*4882a593Smuzhiyun{
2456*4882a593Smuzhiyun    # save first non-option argument
2457*4882a593Smuzhiyun    if test 0 -lt $#; then
2458*4882a593Smuzhiyun      nonopt=$1
2459*4882a593Smuzhiyun      shift
2460*4882a593Smuzhiyun    fi
2461*4882a593Smuzhiyun
2462*4882a593Smuzhiyun    # preserve --debug
2463*4882a593Smuzhiyun    test : = "$debug_cmd" || func_append preserve_args " --debug"
2464*4882a593Smuzhiyun
2465*4882a593Smuzhiyun    case $host in
2466*4882a593Smuzhiyun      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2467*4882a593Smuzhiyun      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2468*4882a593Smuzhiyun      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2469*4882a593Smuzhiyun        # don't eliminate duplications in $postdeps and $predeps
2470*4882a593Smuzhiyun        opt_duplicate_compiler_generated_deps=:
2471*4882a593Smuzhiyun        ;;
2472*4882a593Smuzhiyun      *)
2473*4882a593Smuzhiyun        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2474*4882a593Smuzhiyun        ;;
2475*4882a593Smuzhiyun    esac
2476*4882a593Smuzhiyun
2477*4882a593Smuzhiyun    $opt_help || {
2478*4882a593Smuzhiyun      # Sanity checks first:
2479*4882a593Smuzhiyun      func_check_version_match
2480*4882a593Smuzhiyun
2481*4882a593Smuzhiyun      test yes != "$build_libtool_libs" \
2482*4882a593Smuzhiyun        && test yes != "$build_old_libs" \
2483*4882a593Smuzhiyun        && func_fatal_configuration "not configured to build any kind of library"
2484*4882a593Smuzhiyun
2485*4882a593Smuzhiyun      # Darwin sucks
2486*4882a593Smuzhiyun      eval std_shrext=\"$shrext_cmds\"
2487*4882a593Smuzhiyun
2488*4882a593Smuzhiyun      # Only execute mode is allowed to have -dlopen flags.
2489*4882a593Smuzhiyun      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2490*4882a593Smuzhiyun        func_error "unrecognized option '-dlopen'"
2491*4882a593Smuzhiyun        $ECHO "$help" 1>&2
2492*4882a593Smuzhiyun        exit $EXIT_FAILURE
2493*4882a593Smuzhiyun      fi
2494*4882a593Smuzhiyun
2495*4882a593Smuzhiyun      # Change the help message to a mode-specific one.
2496*4882a593Smuzhiyun      generic_help=$help
2497*4882a593Smuzhiyun      help="Try '$progname --help --mode=$opt_mode' for more information."
2498*4882a593Smuzhiyun    }
2499*4882a593Smuzhiyun
2500*4882a593Smuzhiyun    # Pass back the unparsed argument list
2501*4882a593Smuzhiyun    func_quote_for_eval ${1+"$@"}
2502*4882a593Smuzhiyun    libtool_validate_options_result=$func_quote_for_eval_result
2503*4882a593Smuzhiyun}
2504*4882a593Smuzhiyunfunc_add_hook func_validate_options libtool_validate_options
2505*4882a593Smuzhiyun
2506*4882a593Smuzhiyun
2507*4882a593Smuzhiyun# Process options as early as possible so that --help and --version
2508*4882a593Smuzhiyun# can return quickly.
2509*4882a593Smuzhiyunfunc_options ${1+"$@"}
2510*4882a593Smuzhiyuneval set dummy "$func_options_result"; shift
2511*4882a593Smuzhiyun
2512*4882a593Smuzhiyun
2513*4882a593Smuzhiyun
2514*4882a593Smuzhiyun## ----------- ##
2515*4882a593Smuzhiyun##    Main.    ##
2516*4882a593Smuzhiyun## ----------- ##
2517*4882a593Smuzhiyun
2518*4882a593Smuzhiyunmagic='%%%MAGIC variable%%%'
2519*4882a593Smuzhiyunmagic_exe='%%%MAGIC EXE variable%%%'
2520*4882a593Smuzhiyun
2521*4882a593Smuzhiyun# Global variables.
2522*4882a593Smuzhiyunextracted_archives=
2523*4882a593Smuzhiyunextracted_serial=0
2524*4882a593Smuzhiyun
2525*4882a593Smuzhiyun# If this variable is set in any of the actions, the command in it
2526*4882a593Smuzhiyun# will be execed at the end.  This prevents here-documents from being
2527*4882a593Smuzhiyun# left over by shells.
2528*4882a593Smuzhiyunexec_cmd=
2529*4882a593Smuzhiyun
2530*4882a593Smuzhiyun
2531*4882a593Smuzhiyun# A function that is used when there is no print builtin or printf.
2532*4882a593Smuzhiyunfunc_fallback_echo ()
2533*4882a593Smuzhiyun{
2534*4882a593Smuzhiyun  eval 'cat <<_LTECHO_EOF
2535*4882a593Smuzhiyun$1
2536*4882a593Smuzhiyun_LTECHO_EOF'
2537*4882a593Smuzhiyun}
2538*4882a593Smuzhiyun
2539*4882a593Smuzhiyun# func_generated_by_libtool
2540*4882a593Smuzhiyun# True iff stdin has been generated by Libtool. This function is only
2541*4882a593Smuzhiyun# a basic sanity check; it will hardly flush out determined imposters.
2542*4882a593Smuzhiyunfunc_generated_by_libtool_p ()
2543*4882a593Smuzhiyun{
2544*4882a593Smuzhiyun  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2545*4882a593Smuzhiyun}
2546*4882a593Smuzhiyun
2547*4882a593Smuzhiyun# func_lalib_p file
2548*4882a593Smuzhiyun# True iff FILE is a libtool '.la' library or '.lo' object file.
2549*4882a593Smuzhiyun# This function is only a basic sanity check; it will hardly flush out
2550*4882a593Smuzhiyun# determined imposters.
2551*4882a593Smuzhiyunfunc_lalib_p ()
2552*4882a593Smuzhiyun{
2553*4882a593Smuzhiyun    test -f "$1" &&
2554*4882a593Smuzhiyun      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2555*4882a593Smuzhiyun}
2556*4882a593Smuzhiyun
2557*4882a593Smuzhiyun# func_lalib_unsafe_p file
2558*4882a593Smuzhiyun# True iff FILE is a libtool '.la' library or '.lo' object file.
2559*4882a593Smuzhiyun# This function implements the same check as func_lalib_p without
2560*4882a593Smuzhiyun# resorting to external programs.  To this end, it redirects stdin and
2561*4882a593Smuzhiyun# closes it afterwards, without saving the original file descriptor.
2562*4882a593Smuzhiyun# As a safety measure, use it only where a negative result would be
2563*4882a593Smuzhiyun# fatal anyway.  Works if 'file' does not exist.
2564*4882a593Smuzhiyunfunc_lalib_unsafe_p ()
2565*4882a593Smuzhiyun{
2566*4882a593Smuzhiyun    lalib_p=no
2567*4882a593Smuzhiyun    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2568*4882a593Smuzhiyun	for lalib_p_l in 1 2 3 4
2569*4882a593Smuzhiyun	do
2570*4882a593Smuzhiyun	    read lalib_p_line
2571*4882a593Smuzhiyun	    case $lalib_p_line in
2572*4882a593Smuzhiyun		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2573*4882a593Smuzhiyun	    esac
2574*4882a593Smuzhiyun	done
2575*4882a593Smuzhiyun	exec 0<&5 5<&-
2576*4882a593Smuzhiyun    fi
2577*4882a593Smuzhiyun    test yes = "$lalib_p"
2578*4882a593Smuzhiyun}
2579*4882a593Smuzhiyun
2580*4882a593Smuzhiyun# func_ltwrapper_script_p file
2581*4882a593Smuzhiyun# True iff FILE is a libtool wrapper script
2582*4882a593Smuzhiyun# This function is only a basic sanity check; it will hardly flush out
2583*4882a593Smuzhiyun# determined imposters.
2584*4882a593Smuzhiyunfunc_ltwrapper_script_p ()
2585*4882a593Smuzhiyun{
2586*4882a593Smuzhiyun    test -f "$1" &&
2587*4882a593Smuzhiyun      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2588*4882a593Smuzhiyun}
2589*4882a593Smuzhiyun
2590*4882a593Smuzhiyun# func_ltwrapper_executable_p file
2591*4882a593Smuzhiyun# True iff FILE is a libtool wrapper executable
2592*4882a593Smuzhiyun# This function is only a basic sanity check; it will hardly flush out
2593*4882a593Smuzhiyun# determined imposters.
2594*4882a593Smuzhiyunfunc_ltwrapper_executable_p ()
2595*4882a593Smuzhiyun{
2596*4882a593Smuzhiyun    func_ltwrapper_exec_suffix=
2597*4882a593Smuzhiyun    case $1 in
2598*4882a593Smuzhiyun    *.exe) ;;
2599*4882a593Smuzhiyun    *) func_ltwrapper_exec_suffix=.exe ;;
2600*4882a593Smuzhiyun    esac
2601*4882a593Smuzhiyun    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2602*4882a593Smuzhiyun}
2603*4882a593Smuzhiyun
2604*4882a593Smuzhiyun# func_ltwrapper_scriptname file
2605*4882a593Smuzhiyun# Assumes file is an ltwrapper_executable
2606*4882a593Smuzhiyun# uses $file to determine the appropriate filename for a
2607*4882a593Smuzhiyun# temporary ltwrapper_script.
2608*4882a593Smuzhiyunfunc_ltwrapper_scriptname ()
2609*4882a593Smuzhiyun{
2610*4882a593Smuzhiyun    func_dirname_and_basename "$1" "" "."
2611*4882a593Smuzhiyun    func_stripname '' '.exe' "$func_basename_result"
2612*4882a593Smuzhiyun    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2613*4882a593Smuzhiyun}
2614*4882a593Smuzhiyun
2615*4882a593Smuzhiyun# func_ltwrapper_p file
2616*4882a593Smuzhiyun# True iff FILE is a libtool wrapper script or wrapper executable
2617*4882a593Smuzhiyun# This function is only a basic sanity check; it will hardly flush out
2618*4882a593Smuzhiyun# determined imposters.
2619*4882a593Smuzhiyunfunc_ltwrapper_p ()
2620*4882a593Smuzhiyun{
2621*4882a593Smuzhiyun    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2622*4882a593Smuzhiyun}
2623*4882a593Smuzhiyun
2624*4882a593Smuzhiyun
2625*4882a593Smuzhiyun# func_execute_cmds commands fail_cmd
2626*4882a593Smuzhiyun# Execute tilde-delimited COMMANDS.
2627*4882a593Smuzhiyun# If FAIL_CMD is given, eval that upon failure.
2628*4882a593Smuzhiyun# FAIL_CMD may read-access the current command in variable CMD!
2629*4882a593Smuzhiyunfunc_execute_cmds ()
2630*4882a593Smuzhiyun{
2631*4882a593Smuzhiyun    $debug_cmd
2632*4882a593Smuzhiyun
2633*4882a593Smuzhiyun    save_ifs=$IFS; IFS='~'
2634*4882a593Smuzhiyun    for cmd in $1; do
2635*4882a593Smuzhiyun      IFS=$sp$nl
2636*4882a593Smuzhiyun      eval cmd=\"$cmd\"
2637*4882a593Smuzhiyun      IFS=$save_ifs
2638*4882a593Smuzhiyun      func_show_eval "$cmd" "${2-:}"
2639*4882a593Smuzhiyun    done
2640*4882a593Smuzhiyun    IFS=$save_ifs
2641*4882a593Smuzhiyun}
2642*4882a593Smuzhiyun
2643*4882a593Smuzhiyun
2644*4882a593Smuzhiyun# func_source file
2645*4882a593Smuzhiyun# Source FILE, adding directory component if necessary.
2646*4882a593Smuzhiyun# Note that it is not necessary on cygwin/mingw to append a dot to
2647*4882a593Smuzhiyun# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2648*4882a593Smuzhiyun# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2649*4882a593Smuzhiyun# 'FILE.' does not work on cygwin managed mounts.
2650*4882a593Smuzhiyunfunc_source ()
2651*4882a593Smuzhiyun{
2652*4882a593Smuzhiyun    $debug_cmd
2653*4882a593Smuzhiyun
2654*4882a593Smuzhiyun    case $1 in
2655*4882a593Smuzhiyun    */* | *\\*)	. "$1" ;;
2656*4882a593Smuzhiyun    *)		. "./$1" ;;
2657*4882a593Smuzhiyun    esac
2658*4882a593Smuzhiyun}
2659*4882a593Smuzhiyun
2660*4882a593Smuzhiyun
2661*4882a593Smuzhiyun# func_resolve_sysroot PATH
2662*4882a593Smuzhiyun# Replace a leading = in PATH with a sysroot.  Store the result into
2663*4882a593Smuzhiyun# func_resolve_sysroot_result
2664*4882a593Smuzhiyunfunc_resolve_sysroot ()
2665*4882a593Smuzhiyun{
2666*4882a593Smuzhiyun  func_resolve_sysroot_result=$1
2667*4882a593Smuzhiyun  case $func_resolve_sysroot_result in
2668*4882a593Smuzhiyun  =*)
2669*4882a593Smuzhiyun    func_stripname '=' '' "$func_resolve_sysroot_result"
2670*4882a593Smuzhiyun    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2671*4882a593Smuzhiyun    ;;
2672*4882a593Smuzhiyun  esac
2673*4882a593Smuzhiyun}
2674*4882a593Smuzhiyun
2675*4882a593Smuzhiyun# func_replace_sysroot PATH
2676*4882a593Smuzhiyun# If PATH begins with the sysroot, replace it with = and
2677*4882a593Smuzhiyun# store the result into func_replace_sysroot_result.
2678*4882a593Smuzhiyunfunc_replace_sysroot ()
2679*4882a593Smuzhiyun{
2680*4882a593Smuzhiyun  case $lt_sysroot:$1 in
2681*4882a593Smuzhiyun  ?*:"$lt_sysroot"*)
2682*4882a593Smuzhiyun    func_stripname "$lt_sysroot" '' "$1"
2683*4882a593Smuzhiyun    func_replace_sysroot_result='='$func_stripname_result
2684*4882a593Smuzhiyun    ;;
2685*4882a593Smuzhiyun  *)
2686*4882a593Smuzhiyun    # Including no sysroot.
2687*4882a593Smuzhiyun    func_replace_sysroot_result=$1
2688*4882a593Smuzhiyun    ;;
2689*4882a593Smuzhiyun  esac
2690*4882a593Smuzhiyun}
2691*4882a593Smuzhiyun
2692*4882a593Smuzhiyun# func_infer_tag arg
2693*4882a593Smuzhiyun# Infer tagged configuration to use if any are available and
2694*4882a593Smuzhiyun# if one wasn't chosen via the "--tag" command line option.
2695*4882a593Smuzhiyun# Only attempt this if the compiler in the base compile
2696*4882a593Smuzhiyun# command doesn't match the default compiler.
2697*4882a593Smuzhiyun# arg is usually of the form 'gcc ...'
2698*4882a593Smuzhiyunfunc_infer_tag ()
2699*4882a593Smuzhiyun{
2700*4882a593Smuzhiyun    $debug_cmd
2701*4882a593Smuzhiyun
2702*4882a593Smuzhiyun    if test -n "$available_tags" && test -z "$tagname"; then
2703*4882a593Smuzhiyun      CC_quoted=
2704*4882a593Smuzhiyun      for arg in $CC; do
2705*4882a593Smuzhiyun	func_append_quoted CC_quoted "$arg"
2706*4882a593Smuzhiyun      done
2707*4882a593Smuzhiyun      CC_expanded=`func_echo_all $CC`
2708*4882a593Smuzhiyun      CC_quoted_expanded=`func_echo_all $CC_quoted`
2709*4882a593Smuzhiyun      case $@ in
2710*4882a593Smuzhiyun      # Blanks in the command may have been stripped by the calling shell,
2711*4882a593Smuzhiyun      # but not from the CC environment variable when configure was run.
2712*4882a593Smuzhiyun      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2713*4882a593Smuzhiyun      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2714*4882a593Smuzhiyun      # Blanks at the start of $base_compile will cause this to fail
2715*4882a593Smuzhiyun      # if we don't check for them as well.
2716*4882a593Smuzhiyun      *)
2717*4882a593Smuzhiyun	for z in $available_tags; do
2718*4882a593Smuzhiyun	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2719*4882a593Smuzhiyun	    # Evaluate the configuration.
2720*4882a593Smuzhiyun	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2721*4882a593Smuzhiyun	    CC_quoted=
2722*4882a593Smuzhiyun	    for arg in $CC; do
2723*4882a593Smuzhiyun	      # Double-quote args containing other shell metacharacters.
2724*4882a593Smuzhiyun	      func_append_quoted CC_quoted "$arg"
2725*4882a593Smuzhiyun	    done
2726*4882a593Smuzhiyun	    CC_expanded=`func_echo_all $CC`
2727*4882a593Smuzhiyun	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2728*4882a593Smuzhiyun	    case "$@ " in
2729*4882a593Smuzhiyun	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2730*4882a593Smuzhiyun	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2731*4882a593Smuzhiyun	      # The compiler in the base compile command matches
2732*4882a593Smuzhiyun	      # the one in the tagged configuration.
2733*4882a593Smuzhiyun	      # Assume this is the tagged configuration we want.
2734*4882a593Smuzhiyun	      tagname=$z
2735*4882a593Smuzhiyun	      break
2736*4882a593Smuzhiyun	      ;;
2737*4882a593Smuzhiyun	    esac
2738*4882a593Smuzhiyun	  fi
2739*4882a593Smuzhiyun	done
2740*4882a593Smuzhiyun	# If $tagname still isn't set, then no tagged configuration
2741*4882a593Smuzhiyun	# was found and let the user know that the "--tag" command
2742*4882a593Smuzhiyun	# line option must be used.
2743*4882a593Smuzhiyun	if test -z "$tagname"; then
2744*4882a593Smuzhiyun	  func_echo "unable to infer tagged configuration"
2745*4882a593Smuzhiyun	  func_fatal_error "specify a tag with '--tag'"
2746*4882a593Smuzhiyun#	else
2747*4882a593Smuzhiyun#	  func_verbose "using $tagname tagged configuration"
2748*4882a593Smuzhiyun	fi
2749*4882a593Smuzhiyun	;;
2750*4882a593Smuzhiyun      esac
2751*4882a593Smuzhiyun    fi
2752*4882a593Smuzhiyun}
2753*4882a593Smuzhiyun
2754*4882a593Smuzhiyun
2755*4882a593Smuzhiyun
2756*4882a593Smuzhiyun# func_write_libtool_object output_name pic_name nonpic_name
2757*4882a593Smuzhiyun# Create a libtool object file (analogous to a ".la" file),
2758*4882a593Smuzhiyun# but don't create it if we're doing a dry run.
2759*4882a593Smuzhiyunfunc_write_libtool_object ()
2760*4882a593Smuzhiyun{
2761*4882a593Smuzhiyun    write_libobj=$1
2762*4882a593Smuzhiyun    if test yes = "$build_libtool_libs"; then
2763*4882a593Smuzhiyun      write_lobj=\'$2\'
2764*4882a593Smuzhiyun    else
2765*4882a593Smuzhiyun      write_lobj=none
2766*4882a593Smuzhiyun    fi
2767*4882a593Smuzhiyun
2768*4882a593Smuzhiyun    if test yes = "$build_old_libs"; then
2769*4882a593Smuzhiyun      write_oldobj=\'$3\'
2770*4882a593Smuzhiyun    else
2771*4882a593Smuzhiyun      write_oldobj=none
2772*4882a593Smuzhiyun    fi
2773*4882a593Smuzhiyun
2774*4882a593Smuzhiyun    $opt_dry_run || {
2775*4882a593Smuzhiyun      cat >${write_libobj}T <<EOF
2776*4882a593Smuzhiyun# $write_libobj - a libtool object file
2777*4882a593Smuzhiyun# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2778*4882a593Smuzhiyun#
2779*4882a593Smuzhiyun# Please DO NOT delete this file!
2780*4882a593Smuzhiyun# It is necessary for linking the library.
2781*4882a593Smuzhiyun
2782*4882a593Smuzhiyun# Name of the PIC object.
2783*4882a593Smuzhiyunpic_object=$write_lobj
2784*4882a593Smuzhiyun
2785*4882a593Smuzhiyun# Name of the non-PIC object
2786*4882a593Smuzhiyunnon_pic_object=$write_oldobj
2787*4882a593Smuzhiyun
2788*4882a593SmuzhiyunEOF
2789*4882a593Smuzhiyun      $MV "${write_libobj}T" "$write_libobj"
2790*4882a593Smuzhiyun    }
2791*4882a593Smuzhiyun}
2792*4882a593Smuzhiyun
2793*4882a593Smuzhiyun
2794*4882a593Smuzhiyun##################################################
2795*4882a593Smuzhiyun# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
2796*4882a593Smuzhiyun##################################################
2797*4882a593Smuzhiyun
2798*4882a593Smuzhiyun# func_convert_core_file_wine_to_w32 ARG
2799*4882a593Smuzhiyun# Helper function used by file name conversion functions when $build is *nix,
2800*4882a593Smuzhiyun# and $host is mingw, cygwin, or some other w32 environment. Relies on a
2801*4882a593Smuzhiyun# correctly configured wine environment available, with the winepath program
2802*4882a593Smuzhiyun# in $build's $PATH.
2803*4882a593Smuzhiyun#
2804*4882a593Smuzhiyun# ARG is the $build file name to be converted to w32 format.
2805*4882a593Smuzhiyun# Result is available in $func_convert_core_file_wine_to_w32_result, and will
2806*4882a593Smuzhiyun# be empty on error (or when ARG is empty)
2807*4882a593Smuzhiyunfunc_convert_core_file_wine_to_w32 ()
2808*4882a593Smuzhiyun{
2809*4882a593Smuzhiyun  $debug_cmd
2810*4882a593Smuzhiyun
2811*4882a593Smuzhiyun  func_convert_core_file_wine_to_w32_result=$1
2812*4882a593Smuzhiyun  if test -n "$1"; then
2813*4882a593Smuzhiyun    # Unfortunately, winepath does not exit with a non-zero error code, so we
2814*4882a593Smuzhiyun    # are forced to check the contents of stdout. On the other hand, if the
2815*4882a593Smuzhiyun    # command is not found, the shell will set an exit code of 127 and print
2816*4882a593Smuzhiyun    # *an error message* to stdout. So we must check for both error code of
2817*4882a593Smuzhiyun    # zero AND non-empty stdout, which explains the odd construction:
2818*4882a593Smuzhiyun    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
2819*4882a593Smuzhiyun    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
2820*4882a593Smuzhiyun      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
2821*4882a593Smuzhiyun        $SED -e "$sed_naive_backslashify"`
2822*4882a593Smuzhiyun    else
2823*4882a593Smuzhiyun      func_convert_core_file_wine_to_w32_result=
2824*4882a593Smuzhiyun    fi
2825*4882a593Smuzhiyun  fi
2826*4882a593Smuzhiyun}
2827*4882a593Smuzhiyun# end: func_convert_core_file_wine_to_w32
2828*4882a593Smuzhiyun
2829*4882a593Smuzhiyun
2830*4882a593Smuzhiyun# func_convert_core_path_wine_to_w32 ARG
2831*4882a593Smuzhiyun# Helper function used by path conversion functions when $build is *nix, and
2832*4882a593Smuzhiyun# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
2833*4882a593Smuzhiyun# configured wine environment available, with the winepath program in $build's
2834*4882a593Smuzhiyun# $PATH. Assumes ARG has no leading or trailing path separator characters.
2835*4882a593Smuzhiyun#
2836*4882a593Smuzhiyun# ARG is path to be converted from $build format to win32.
2837*4882a593Smuzhiyun# Result is available in $func_convert_core_path_wine_to_w32_result.
2838*4882a593Smuzhiyun# Unconvertible file (directory) names in ARG are skipped; if no directory names
2839*4882a593Smuzhiyun# are convertible, then the result may be empty.
2840*4882a593Smuzhiyunfunc_convert_core_path_wine_to_w32 ()
2841*4882a593Smuzhiyun{
2842*4882a593Smuzhiyun  $debug_cmd
2843*4882a593Smuzhiyun
2844*4882a593Smuzhiyun  # unfortunately, winepath doesn't convert paths, only file names
2845*4882a593Smuzhiyun  func_convert_core_path_wine_to_w32_result=
2846*4882a593Smuzhiyun  if test -n "$1"; then
2847*4882a593Smuzhiyun    oldIFS=$IFS
2848*4882a593Smuzhiyun    IFS=:
2849*4882a593Smuzhiyun    for func_convert_core_path_wine_to_w32_f in $1; do
2850*4882a593Smuzhiyun      IFS=$oldIFS
2851*4882a593Smuzhiyun      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
2852*4882a593Smuzhiyun      if test -n "$func_convert_core_file_wine_to_w32_result"; then
2853*4882a593Smuzhiyun        if test -z "$func_convert_core_path_wine_to_w32_result"; then
2854*4882a593Smuzhiyun          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
2855*4882a593Smuzhiyun        else
2856*4882a593Smuzhiyun          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
2857*4882a593Smuzhiyun        fi
2858*4882a593Smuzhiyun      fi
2859*4882a593Smuzhiyun    done
2860*4882a593Smuzhiyun    IFS=$oldIFS
2861*4882a593Smuzhiyun  fi
2862*4882a593Smuzhiyun}
2863*4882a593Smuzhiyun# end: func_convert_core_path_wine_to_w32
2864*4882a593Smuzhiyun
2865*4882a593Smuzhiyun
2866*4882a593Smuzhiyun# func_cygpath ARGS...
2867*4882a593Smuzhiyun# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
2868*4882a593Smuzhiyun# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
2869*4882a593Smuzhiyun# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
2870*4882a593Smuzhiyun# (2), returns the Cygwin file name or path in func_cygpath_result (input
2871*4882a593Smuzhiyun# file name or path is assumed to be in w32 format, as previously converted
2872*4882a593Smuzhiyun# from $build's *nix or MSYS format). In case (3), returns the w32 file name
2873*4882a593Smuzhiyun# or path in func_cygpath_result (input file name or path is assumed to be in
2874*4882a593Smuzhiyun# Cygwin format). Returns an empty string on error.
2875*4882a593Smuzhiyun#
2876*4882a593Smuzhiyun# ARGS are passed to cygpath, with the last one being the file name or path to
2877*4882a593Smuzhiyun# be converted.
2878*4882a593Smuzhiyun#
2879*4882a593Smuzhiyun# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
2880*4882a593Smuzhiyun# environment variable; do not put it in $PATH.
2881*4882a593Smuzhiyunfunc_cygpath ()
2882*4882a593Smuzhiyun{
2883*4882a593Smuzhiyun  $debug_cmd
2884*4882a593Smuzhiyun
2885*4882a593Smuzhiyun  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
2886*4882a593Smuzhiyun    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
2887*4882a593Smuzhiyun    if test "$?" -ne 0; then
2888*4882a593Smuzhiyun      # on failure, ensure result is empty
2889*4882a593Smuzhiyun      func_cygpath_result=
2890*4882a593Smuzhiyun    fi
2891*4882a593Smuzhiyun  else
2892*4882a593Smuzhiyun    func_cygpath_result=
2893*4882a593Smuzhiyun    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
2894*4882a593Smuzhiyun  fi
2895*4882a593Smuzhiyun}
2896*4882a593Smuzhiyun#end: func_cygpath
2897*4882a593Smuzhiyun
2898*4882a593Smuzhiyun
2899*4882a593Smuzhiyun# func_convert_core_msys_to_w32 ARG
2900*4882a593Smuzhiyun# Convert file name or path ARG from MSYS format to w32 format.  Return
2901*4882a593Smuzhiyun# result in func_convert_core_msys_to_w32_result.
2902*4882a593Smuzhiyunfunc_convert_core_msys_to_w32 ()
2903*4882a593Smuzhiyun{
2904*4882a593Smuzhiyun  $debug_cmd
2905*4882a593Smuzhiyun
2906*4882a593Smuzhiyun  # awkward: cmd appends spaces to result
2907*4882a593Smuzhiyun  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
2908*4882a593Smuzhiyun    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
2909*4882a593Smuzhiyun}
2910*4882a593Smuzhiyun#end: func_convert_core_msys_to_w32
2911*4882a593Smuzhiyun
2912*4882a593Smuzhiyun
2913*4882a593Smuzhiyun# func_convert_file_check ARG1 ARG2
2914*4882a593Smuzhiyun# Verify that ARG1 (a file name in $build format) was converted to $host
2915*4882a593Smuzhiyun# format in ARG2. Otherwise, emit an error message, but continue (resetting
2916*4882a593Smuzhiyun# func_to_host_file_result to ARG1).
2917*4882a593Smuzhiyunfunc_convert_file_check ()
2918*4882a593Smuzhiyun{
2919*4882a593Smuzhiyun  $debug_cmd
2920*4882a593Smuzhiyun
2921*4882a593Smuzhiyun  if test -z "$2" && test -n "$1"; then
2922*4882a593Smuzhiyun    func_error "Could not determine host file name corresponding to"
2923*4882a593Smuzhiyun    func_error "  '$1'"
2924*4882a593Smuzhiyun    func_error "Continuing, but uninstalled executables may not work."
2925*4882a593Smuzhiyun    # Fallback:
2926*4882a593Smuzhiyun    func_to_host_file_result=$1
2927*4882a593Smuzhiyun  fi
2928*4882a593Smuzhiyun}
2929*4882a593Smuzhiyun# end func_convert_file_check
2930*4882a593Smuzhiyun
2931*4882a593Smuzhiyun
2932*4882a593Smuzhiyun# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
2933*4882a593Smuzhiyun# Verify that FROM_PATH (a path in $build format) was converted to $host
2934*4882a593Smuzhiyun# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
2935*4882a593Smuzhiyun# func_to_host_file_result to a simplistic fallback value (see below).
2936*4882a593Smuzhiyunfunc_convert_path_check ()
2937*4882a593Smuzhiyun{
2938*4882a593Smuzhiyun  $debug_cmd
2939*4882a593Smuzhiyun
2940*4882a593Smuzhiyun  if test -z "$4" && test -n "$3"; then
2941*4882a593Smuzhiyun    func_error "Could not determine the host path corresponding to"
2942*4882a593Smuzhiyun    func_error "  '$3'"
2943*4882a593Smuzhiyun    func_error "Continuing, but uninstalled executables may not work."
2944*4882a593Smuzhiyun    # Fallback.  This is a deliberately simplistic "conversion" and
2945*4882a593Smuzhiyun    # should not be "improved".  See libtool.info.
2946*4882a593Smuzhiyun    if test "x$1" != "x$2"; then
2947*4882a593Smuzhiyun      lt_replace_pathsep_chars="s|$1|$2|g"
2948*4882a593Smuzhiyun      func_to_host_path_result=`echo "$3" |
2949*4882a593Smuzhiyun        $SED -e "$lt_replace_pathsep_chars"`
2950*4882a593Smuzhiyun    else
2951*4882a593Smuzhiyun      func_to_host_path_result=$3
2952*4882a593Smuzhiyun    fi
2953*4882a593Smuzhiyun  fi
2954*4882a593Smuzhiyun}
2955*4882a593Smuzhiyun# end func_convert_path_check
2956*4882a593Smuzhiyun
2957*4882a593Smuzhiyun
2958*4882a593Smuzhiyun# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
2959*4882a593Smuzhiyun# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
2960*4882a593Smuzhiyun# and appending REPL if ORIG matches BACKPAT.
2961*4882a593Smuzhiyunfunc_convert_path_front_back_pathsep ()
2962*4882a593Smuzhiyun{
2963*4882a593Smuzhiyun  $debug_cmd
2964*4882a593Smuzhiyun
2965*4882a593Smuzhiyun  case $4 in
2966*4882a593Smuzhiyun  $1 ) func_to_host_path_result=$3$func_to_host_path_result
2967*4882a593Smuzhiyun    ;;
2968*4882a593Smuzhiyun  esac
2969*4882a593Smuzhiyun  case $4 in
2970*4882a593Smuzhiyun  $2 ) func_append func_to_host_path_result "$3"
2971*4882a593Smuzhiyun    ;;
2972*4882a593Smuzhiyun  esac
2973*4882a593Smuzhiyun}
2974*4882a593Smuzhiyun# end func_convert_path_front_back_pathsep
2975*4882a593Smuzhiyun
2976*4882a593Smuzhiyun
2977*4882a593Smuzhiyun##################################################
2978*4882a593Smuzhiyun# $build to $host FILE NAME CONVERSION FUNCTIONS #
2979*4882a593Smuzhiyun##################################################
2980*4882a593Smuzhiyun# invoked via '$to_host_file_cmd ARG'
2981*4882a593Smuzhiyun#
2982*4882a593Smuzhiyun# In each case, ARG is the path to be converted from $build to $host format.
2983*4882a593Smuzhiyun# Result will be available in $func_to_host_file_result.
2984*4882a593Smuzhiyun
2985*4882a593Smuzhiyun
2986*4882a593Smuzhiyun# func_to_host_file ARG
2987*4882a593Smuzhiyun# Converts the file name ARG from $build format to $host format. Return result
2988*4882a593Smuzhiyun# in func_to_host_file_result.
2989*4882a593Smuzhiyunfunc_to_host_file ()
2990*4882a593Smuzhiyun{
2991*4882a593Smuzhiyun  $debug_cmd
2992*4882a593Smuzhiyun
2993*4882a593Smuzhiyun  $to_host_file_cmd "$1"
2994*4882a593Smuzhiyun}
2995*4882a593Smuzhiyun# end func_to_host_file
2996*4882a593Smuzhiyun
2997*4882a593Smuzhiyun
2998*4882a593Smuzhiyun# func_to_tool_file ARG LAZY
2999*4882a593Smuzhiyun# converts the file name ARG from $build format to toolchain format. Return
3000*4882a593Smuzhiyun# result in func_to_tool_file_result.  If the conversion in use is listed
3001*4882a593Smuzhiyun# in (the comma separated) LAZY, no conversion takes place.
3002*4882a593Smuzhiyunfunc_to_tool_file ()
3003*4882a593Smuzhiyun{
3004*4882a593Smuzhiyun  $debug_cmd
3005*4882a593Smuzhiyun
3006*4882a593Smuzhiyun  case ,$2, in
3007*4882a593Smuzhiyun    *,"$to_tool_file_cmd",*)
3008*4882a593Smuzhiyun      func_to_tool_file_result=$1
3009*4882a593Smuzhiyun      ;;
3010*4882a593Smuzhiyun    *)
3011*4882a593Smuzhiyun      $to_tool_file_cmd "$1"
3012*4882a593Smuzhiyun      func_to_tool_file_result=$func_to_host_file_result
3013*4882a593Smuzhiyun      ;;
3014*4882a593Smuzhiyun  esac
3015*4882a593Smuzhiyun}
3016*4882a593Smuzhiyun# end func_to_tool_file
3017*4882a593Smuzhiyun
3018*4882a593Smuzhiyun
3019*4882a593Smuzhiyun# func_convert_file_noop ARG
3020*4882a593Smuzhiyun# Copy ARG to func_to_host_file_result.
3021*4882a593Smuzhiyunfunc_convert_file_noop ()
3022*4882a593Smuzhiyun{
3023*4882a593Smuzhiyun  func_to_host_file_result=$1
3024*4882a593Smuzhiyun}
3025*4882a593Smuzhiyun# end func_convert_file_noop
3026*4882a593Smuzhiyun
3027*4882a593Smuzhiyun
3028*4882a593Smuzhiyun# func_convert_file_msys_to_w32 ARG
3029*4882a593Smuzhiyun# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3030*4882a593Smuzhiyun# conversion to w32 is not available inside the cwrapper.  Returns result in
3031*4882a593Smuzhiyun# func_to_host_file_result.
3032*4882a593Smuzhiyunfunc_convert_file_msys_to_w32 ()
3033*4882a593Smuzhiyun{
3034*4882a593Smuzhiyun  $debug_cmd
3035*4882a593Smuzhiyun
3036*4882a593Smuzhiyun  func_to_host_file_result=$1
3037*4882a593Smuzhiyun  if test -n "$1"; then
3038*4882a593Smuzhiyun    func_convert_core_msys_to_w32 "$1"
3039*4882a593Smuzhiyun    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3040*4882a593Smuzhiyun  fi
3041*4882a593Smuzhiyun  func_convert_file_check "$1" "$func_to_host_file_result"
3042*4882a593Smuzhiyun}
3043*4882a593Smuzhiyun# end func_convert_file_msys_to_w32
3044*4882a593Smuzhiyun
3045*4882a593Smuzhiyun
3046*4882a593Smuzhiyun# func_convert_file_cygwin_to_w32 ARG
3047*4882a593Smuzhiyun# Convert file name ARG from Cygwin to w32 format.  Returns result in
3048*4882a593Smuzhiyun# func_to_host_file_result.
3049*4882a593Smuzhiyunfunc_convert_file_cygwin_to_w32 ()
3050*4882a593Smuzhiyun{
3051*4882a593Smuzhiyun  $debug_cmd
3052*4882a593Smuzhiyun
3053*4882a593Smuzhiyun  func_to_host_file_result=$1
3054*4882a593Smuzhiyun  if test -n "$1"; then
3055*4882a593Smuzhiyun    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3056*4882a593Smuzhiyun    # LT_CYGPATH in this case.
3057*4882a593Smuzhiyun    func_to_host_file_result=`cygpath -m "$1"`
3058*4882a593Smuzhiyun  fi
3059*4882a593Smuzhiyun  func_convert_file_check "$1" "$func_to_host_file_result"
3060*4882a593Smuzhiyun}
3061*4882a593Smuzhiyun# end func_convert_file_cygwin_to_w32
3062*4882a593Smuzhiyun
3063*4882a593Smuzhiyun
3064*4882a593Smuzhiyun# func_convert_file_nix_to_w32 ARG
3065*4882a593Smuzhiyun# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3066*4882a593Smuzhiyun# and a working winepath. Returns result in func_to_host_file_result.
3067*4882a593Smuzhiyunfunc_convert_file_nix_to_w32 ()
3068*4882a593Smuzhiyun{
3069*4882a593Smuzhiyun  $debug_cmd
3070*4882a593Smuzhiyun
3071*4882a593Smuzhiyun  func_to_host_file_result=$1
3072*4882a593Smuzhiyun  if test -n "$1"; then
3073*4882a593Smuzhiyun    func_convert_core_file_wine_to_w32 "$1"
3074*4882a593Smuzhiyun    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3075*4882a593Smuzhiyun  fi
3076*4882a593Smuzhiyun  func_convert_file_check "$1" "$func_to_host_file_result"
3077*4882a593Smuzhiyun}
3078*4882a593Smuzhiyun# end func_convert_file_nix_to_w32
3079*4882a593Smuzhiyun
3080*4882a593Smuzhiyun
3081*4882a593Smuzhiyun# func_convert_file_msys_to_cygwin ARG
3082*4882a593Smuzhiyun# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3083*4882a593Smuzhiyun# Returns result in func_to_host_file_result.
3084*4882a593Smuzhiyunfunc_convert_file_msys_to_cygwin ()
3085*4882a593Smuzhiyun{
3086*4882a593Smuzhiyun  $debug_cmd
3087*4882a593Smuzhiyun
3088*4882a593Smuzhiyun  func_to_host_file_result=$1
3089*4882a593Smuzhiyun  if test -n "$1"; then
3090*4882a593Smuzhiyun    func_convert_core_msys_to_w32 "$1"
3091*4882a593Smuzhiyun    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3092*4882a593Smuzhiyun    func_to_host_file_result=$func_cygpath_result
3093*4882a593Smuzhiyun  fi
3094*4882a593Smuzhiyun  func_convert_file_check "$1" "$func_to_host_file_result"
3095*4882a593Smuzhiyun}
3096*4882a593Smuzhiyun# end func_convert_file_msys_to_cygwin
3097*4882a593Smuzhiyun
3098*4882a593Smuzhiyun
3099*4882a593Smuzhiyun# func_convert_file_nix_to_cygwin ARG
3100*4882a593Smuzhiyun# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3101*4882a593Smuzhiyun# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3102*4882a593Smuzhiyun# in func_to_host_file_result.
3103*4882a593Smuzhiyunfunc_convert_file_nix_to_cygwin ()
3104*4882a593Smuzhiyun{
3105*4882a593Smuzhiyun  $debug_cmd
3106*4882a593Smuzhiyun
3107*4882a593Smuzhiyun  func_to_host_file_result=$1
3108*4882a593Smuzhiyun  if test -n "$1"; then
3109*4882a593Smuzhiyun    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3110*4882a593Smuzhiyun    func_convert_core_file_wine_to_w32 "$1"
3111*4882a593Smuzhiyun    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3112*4882a593Smuzhiyun    func_to_host_file_result=$func_cygpath_result
3113*4882a593Smuzhiyun  fi
3114*4882a593Smuzhiyun  func_convert_file_check "$1" "$func_to_host_file_result"
3115*4882a593Smuzhiyun}
3116*4882a593Smuzhiyun# end func_convert_file_nix_to_cygwin
3117*4882a593Smuzhiyun
3118*4882a593Smuzhiyun
3119*4882a593Smuzhiyun#############################################
3120*4882a593Smuzhiyun# $build to $host PATH CONVERSION FUNCTIONS #
3121*4882a593Smuzhiyun#############################################
3122*4882a593Smuzhiyun# invoked via '$to_host_path_cmd ARG'
3123*4882a593Smuzhiyun#
3124*4882a593Smuzhiyun# In each case, ARG is the path to be converted from $build to $host format.
3125*4882a593Smuzhiyun# The result will be available in $func_to_host_path_result.
3126*4882a593Smuzhiyun#
3127*4882a593Smuzhiyun# Path separators are also converted from $build format to $host format.  If
3128*4882a593Smuzhiyun# ARG begins or ends with a path separator character, it is preserved (but
3129*4882a593Smuzhiyun# converted to $host format) on output.
3130*4882a593Smuzhiyun#
3131*4882a593Smuzhiyun# All path conversion functions are named using the following convention:
3132*4882a593Smuzhiyun#   file name conversion function    : func_convert_file_X_to_Y ()
3133*4882a593Smuzhiyun#   path conversion function         : func_convert_path_X_to_Y ()
3134*4882a593Smuzhiyun# where, for any given $build/$host combination the 'X_to_Y' value is the
3135*4882a593Smuzhiyun# same.  If conversion functions are added for new $build/$host combinations,
3136*4882a593Smuzhiyun# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3137*4882a593Smuzhiyun# will break.
3138*4882a593Smuzhiyun
3139*4882a593Smuzhiyun
3140*4882a593Smuzhiyun# func_init_to_host_path_cmd
3141*4882a593Smuzhiyun# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3142*4882a593Smuzhiyun# appropriate value, based on the value of $to_host_file_cmd.
3143*4882a593Smuzhiyunto_host_path_cmd=
3144*4882a593Smuzhiyunfunc_init_to_host_path_cmd ()
3145*4882a593Smuzhiyun{
3146*4882a593Smuzhiyun  $debug_cmd
3147*4882a593Smuzhiyun
3148*4882a593Smuzhiyun  if test -z "$to_host_path_cmd"; then
3149*4882a593Smuzhiyun    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3150*4882a593Smuzhiyun    to_host_path_cmd=func_convert_path_$func_stripname_result
3151*4882a593Smuzhiyun  fi
3152*4882a593Smuzhiyun}
3153*4882a593Smuzhiyun
3154*4882a593Smuzhiyun
3155*4882a593Smuzhiyun# func_to_host_path ARG
3156*4882a593Smuzhiyun# Converts the path ARG from $build format to $host format. Return result
3157*4882a593Smuzhiyun# in func_to_host_path_result.
3158*4882a593Smuzhiyunfunc_to_host_path ()
3159*4882a593Smuzhiyun{
3160*4882a593Smuzhiyun  $debug_cmd
3161*4882a593Smuzhiyun
3162*4882a593Smuzhiyun  func_init_to_host_path_cmd
3163*4882a593Smuzhiyun  $to_host_path_cmd "$1"
3164*4882a593Smuzhiyun}
3165*4882a593Smuzhiyun# end func_to_host_path
3166*4882a593Smuzhiyun
3167*4882a593Smuzhiyun
3168*4882a593Smuzhiyun# func_convert_path_noop ARG
3169*4882a593Smuzhiyun# Copy ARG to func_to_host_path_result.
3170*4882a593Smuzhiyunfunc_convert_path_noop ()
3171*4882a593Smuzhiyun{
3172*4882a593Smuzhiyun  func_to_host_path_result=$1
3173*4882a593Smuzhiyun}
3174*4882a593Smuzhiyun# end func_convert_path_noop
3175*4882a593Smuzhiyun
3176*4882a593Smuzhiyun
3177*4882a593Smuzhiyun# func_convert_path_msys_to_w32 ARG
3178*4882a593Smuzhiyun# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3179*4882a593Smuzhiyun# conversion to w32 is not available inside the cwrapper.  Returns result in
3180*4882a593Smuzhiyun# func_to_host_path_result.
3181*4882a593Smuzhiyunfunc_convert_path_msys_to_w32 ()
3182*4882a593Smuzhiyun{
3183*4882a593Smuzhiyun  $debug_cmd
3184*4882a593Smuzhiyun
3185*4882a593Smuzhiyun  func_to_host_path_result=$1
3186*4882a593Smuzhiyun  if test -n "$1"; then
3187*4882a593Smuzhiyun    # Remove leading and trailing path separator characters from ARG.  MSYS
3188*4882a593Smuzhiyun    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3189*4882a593Smuzhiyun    # and winepath ignores them completely.
3190*4882a593Smuzhiyun    func_stripname : : "$1"
3191*4882a593Smuzhiyun    func_to_host_path_tmp1=$func_stripname_result
3192*4882a593Smuzhiyun    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3193*4882a593Smuzhiyun    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3194*4882a593Smuzhiyun    func_convert_path_check : ";" \
3195*4882a593Smuzhiyun      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3196*4882a593Smuzhiyun    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3197*4882a593Smuzhiyun  fi
3198*4882a593Smuzhiyun}
3199*4882a593Smuzhiyun# end func_convert_path_msys_to_w32
3200*4882a593Smuzhiyun
3201*4882a593Smuzhiyun
3202*4882a593Smuzhiyun# func_convert_path_cygwin_to_w32 ARG
3203*4882a593Smuzhiyun# Convert path ARG from Cygwin to w32 format.  Returns result in
3204*4882a593Smuzhiyun# func_to_host_file_result.
3205*4882a593Smuzhiyunfunc_convert_path_cygwin_to_w32 ()
3206*4882a593Smuzhiyun{
3207*4882a593Smuzhiyun  $debug_cmd
3208*4882a593Smuzhiyun
3209*4882a593Smuzhiyun  func_to_host_path_result=$1
3210*4882a593Smuzhiyun  if test -n "$1"; then
3211*4882a593Smuzhiyun    # See func_convert_path_msys_to_w32:
3212*4882a593Smuzhiyun    func_stripname : : "$1"
3213*4882a593Smuzhiyun    func_to_host_path_tmp1=$func_stripname_result
3214*4882a593Smuzhiyun    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3215*4882a593Smuzhiyun    func_convert_path_check : ";" \
3216*4882a593Smuzhiyun      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3217*4882a593Smuzhiyun    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3218*4882a593Smuzhiyun  fi
3219*4882a593Smuzhiyun}
3220*4882a593Smuzhiyun# end func_convert_path_cygwin_to_w32
3221*4882a593Smuzhiyun
3222*4882a593Smuzhiyun
3223*4882a593Smuzhiyun# func_convert_path_nix_to_w32 ARG
3224*4882a593Smuzhiyun# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3225*4882a593Smuzhiyun# a working winepath.  Returns result in func_to_host_file_result.
3226*4882a593Smuzhiyunfunc_convert_path_nix_to_w32 ()
3227*4882a593Smuzhiyun{
3228*4882a593Smuzhiyun  $debug_cmd
3229*4882a593Smuzhiyun
3230*4882a593Smuzhiyun  func_to_host_path_result=$1
3231*4882a593Smuzhiyun  if test -n "$1"; then
3232*4882a593Smuzhiyun    # See func_convert_path_msys_to_w32:
3233*4882a593Smuzhiyun    func_stripname : : "$1"
3234*4882a593Smuzhiyun    func_to_host_path_tmp1=$func_stripname_result
3235*4882a593Smuzhiyun    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3236*4882a593Smuzhiyun    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3237*4882a593Smuzhiyun    func_convert_path_check : ";" \
3238*4882a593Smuzhiyun      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3239*4882a593Smuzhiyun    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3240*4882a593Smuzhiyun  fi
3241*4882a593Smuzhiyun}
3242*4882a593Smuzhiyun# end func_convert_path_nix_to_w32
3243*4882a593Smuzhiyun
3244*4882a593Smuzhiyun
3245*4882a593Smuzhiyun# func_convert_path_msys_to_cygwin ARG
3246*4882a593Smuzhiyun# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3247*4882a593Smuzhiyun# Returns result in func_to_host_file_result.
3248*4882a593Smuzhiyunfunc_convert_path_msys_to_cygwin ()
3249*4882a593Smuzhiyun{
3250*4882a593Smuzhiyun  $debug_cmd
3251*4882a593Smuzhiyun
3252*4882a593Smuzhiyun  func_to_host_path_result=$1
3253*4882a593Smuzhiyun  if test -n "$1"; then
3254*4882a593Smuzhiyun    # See func_convert_path_msys_to_w32:
3255*4882a593Smuzhiyun    func_stripname : : "$1"
3256*4882a593Smuzhiyun    func_to_host_path_tmp1=$func_stripname_result
3257*4882a593Smuzhiyun    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3258*4882a593Smuzhiyun    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3259*4882a593Smuzhiyun    func_to_host_path_result=$func_cygpath_result
3260*4882a593Smuzhiyun    func_convert_path_check : : \
3261*4882a593Smuzhiyun      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3262*4882a593Smuzhiyun    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3263*4882a593Smuzhiyun  fi
3264*4882a593Smuzhiyun}
3265*4882a593Smuzhiyun# end func_convert_path_msys_to_cygwin
3266*4882a593Smuzhiyun
3267*4882a593Smuzhiyun
3268*4882a593Smuzhiyun# func_convert_path_nix_to_cygwin ARG
3269*4882a593Smuzhiyun# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3270*4882a593Smuzhiyun# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3271*4882a593Smuzhiyun# func_to_host_file_result.
3272*4882a593Smuzhiyunfunc_convert_path_nix_to_cygwin ()
3273*4882a593Smuzhiyun{
3274*4882a593Smuzhiyun  $debug_cmd
3275*4882a593Smuzhiyun
3276*4882a593Smuzhiyun  func_to_host_path_result=$1
3277*4882a593Smuzhiyun  if test -n "$1"; then
3278*4882a593Smuzhiyun    # Remove leading and trailing path separator characters from
3279*4882a593Smuzhiyun    # ARG. msys behavior is inconsistent here, cygpath turns them
3280*4882a593Smuzhiyun    # into '.;' and ';.', and winepath ignores them completely.
3281*4882a593Smuzhiyun    func_stripname : : "$1"
3282*4882a593Smuzhiyun    func_to_host_path_tmp1=$func_stripname_result
3283*4882a593Smuzhiyun    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3284*4882a593Smuzhiyun    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3285*4882a593Smuzhiyun    func_to_host_path_result=$func_cygpath_result
3286*4882a593Smuzhiyun    func_convert_path_check : : \
3287*4882a593Smuzhiyun      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3288*4882a593Smuzhiyun    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3289*4882a593Smuzhiyun  fi
3290*4882a593Smuzhiyun}
3291*4882a593Smuzhiyun# end func_convert_path_nix_to_cygwin
3292*4882a593Smuzhiyun
3293*4882a593Smuzhiyun
3294*4882a593Smuzhiyun# func_dll_def_p FILE
3295*4882a593Smuzhiyun# True iff FILE is a Windows DLL '.def' file.
3296*4882a593Smuzhiyun# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3297*4882a593Smuzhiyunfunc_dll_def_p ()
3298*4882a593Smuzhiyun{
3299*4882a593Smuzhiyun  $debug_cmd
3300*4882a593Smuzhiyun
3301*4882a593Smuzhiyun  func_dll_def_p_tmp=`$SED -n \
3302*4882a593Smuzhiyun    -e 's/^[	 ]*//' \
3303*4882a593Smuzhiyun    -e '/^\(;.*\)*$/d' \
3304*4882a593Smuzhiyun    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3305*4882a593Smuzhiyun    -e q \
3306*4882a593Smuzhiyun    "$1"`
3307*4882a593Smuzhiyun  test DEF = "$func_dll_def_p_tmp"
3308*4882a593Smuzhiyun}
3309*4882a593Smuzhiyun
3310*4882a593Smuzhiyun
3311*4882a593Smuzhiyun# func_mode_compile arg...
3312*4882a593Smuzhiyunfunc_mode_compile ()
3313*4882a593Smuzhiyun{
3314*4882a593Smuzhiyun    $debug_cmd
3315*4882a593Smuzhiyun
3316*4882a593Smuzhiyun    # Get the compilation command and the source file.
3317*4882a593Smuzhiyun    base_compile=
3318*4882a593Smuzhiyun    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3319*4882a593Smuzhiyun    suppress_opt=yes
3320*4882a593Smuzhiyun    suppress_output=
3321*4882a593Smuzhiyun    arg_mode=normal
3322*4882a593Smuzhiyun    libobj=
3323*4882a593Smuzhiyun    later=
3324*4882a593Smuzhiyun    pie_flag=
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun    for arg
3327*4882a593Smuzhiyun    do
3328*4882a593Smuzhiyun      case $arg_mode in
3329*4882a593Smuzhiyun      arg  )
3330*4882a593Smuzhiyun	# do not "continue".  Instead, add this to base_compile
3331*4882a593Smuzhiyun	lastarg=$arg
3332*4882a593Smuzhiyun	arg_mode=normal
3333*4882a593Smuzhiyun	;;
3334*4882a593Smuzhiyun
3335*4882a593Smuzhiyun      target )
3336*4882a593Smuzhiyun	libobj=$arg
3337*4882a593Smuzhiyun	arg_mode=normal
3338*4882a593Smuzhiyun	continue
3339*4882a593Smuzhiyun	;;
3340*4882a593Smuzhiyun
3341*4882a593Smuzhiyun      normal )
3342*4882a593Smuzhiyun	# Accept any command-line options.
3343*4882a593Smuzhiyun	case $arg in
3344*4882a593Smuzhiyun	-o)
3345*4882a593Smuzhiyun	  test -n "$libobj" && \
3346*4882a593Smuzhiyun	    func_fatal_error "you cannot specify '-o' more than once"
3347*4882a593Smuzhiyun	  arg_mode=target
3348*4882a593Smuzhiyun	  continue
3349*4882a593Smuzhiyun	  ;;
3350*4882a593Smuzhiyun
3351*4882a593Smuzhiyun	-pie | -fpie | -fPIE)
3352*4882a593Smuzhiyun          func_append pie_flag " $arg"
3353*4882a593Smuzhiyun	  continue
3354*4882a593Smuzhiyun	  ;;
3355*4882a593Smuzhiyun
3356*4882a593Smuzhiyun	-shared | -static | -prefer-pic | -prefer-non-pic)
3357*4882a593Smuzhiyun	  func_append later " $arg"
3358*4882a593Smuzhiyun	  continue
3359*4882a593Smuzhiyun	  ;;
3360*4882a593Smuzhiyun
3361*4882a593Smuzhiyun	-no-suppress)
3362*4882a593Smuzhiyun	  suppress_opt=no
3363*4882a593Smuzhiyun	  continue
3364*4882a593Smuzhiyun	  ;;
3365*4882a593Smuzhiyun
3366*4882a593Smuzhiyun	-Xcompiler)
3367*4882a593Smuzhiyun	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3368*4882a593Smuzhiyun	  continue      #  The current "srcfile" will either be retained or
3369*4882a593Smuzhiyun	  ;;            #  replaced later.  I would guess that would be a bug.
3370*4882a593Smuzhiyun
3371*4882a593Smuzhiyun	-Wc,*)
3372*4882a593Smuzhiyun	  func_stripname '-Wc,' '' "$arg"
3373*4882a593Smuzhiyun	  args=$func_stripname_result
3374*4882a593Smuzhiyun	  lastarg=
3375*4882a593Smuzhiyun	  save_ifs=$IFS; IFS=,
3376*4882a593Smuzhiyun	  for arg in $args; do
3377*4882a593Smuzhiyun	    IFS=$save_ifs
3378*4882a593Smuzhiyun	    func_append_quoted lastarg "$arg"
3379*4882a593Smuzhiyun	  done
3380*4882a593Smuzhiyun	  IFS=$save_ifs
3381*4882a593Smuzhiyun	  func_stripname ' ' '' "$lastarg"
3382*4882a593Smuzhiyun	  lastarg=$func_stripname_result
3383*4882a593Smuzhiyun
3384*4882a593Smuzhiyun	  # Add the arguments to base_compile.
3385*4882a593Smuzhiyun	  func_append base_compile " $lastarg"
3386*4882a593Smuzhiyun	  continue
3387*4882a593Smuzhiyun	  ;;
3388*4882a593Smuzhiyun
3389*4882a593Smuzhiyun	*)
3390*4882a593Smuzhiyun	  # Accept the current argument as the source file.
3391*4882a593Smuzhiyun	  # The previous "srcfile" becomes the current argument.
3392*4882a593Smuzhiyun	  #
3393*4882a593Smuzhiyun	  lastarg=$srcfile
3394*4882a593Smuzhiyun	  srcfile=$arg
3395*4882a593Smuzhiyun	  ;;
3396*4882a593Smuzhiyun	esac  #  case $arg
3397*4882a593Smuzhiyun	;;
3398*4882a593Smuzhiyun      esac    #  case $arg_mode
3399*4882a593Smuzhiyun
3400*4882a593Smuzhiyun      # Aesthetically quote the previous argument.
3401*4882a593Smuzhiyun      func_append_quoted base_compile "$lastarg"
3402*4882a593Smuzhiyun    done # for arg
3403*4882a593Smuzhiyun
3404*4882a593Smuzhiyun    case $arg_mode in
3405*4882a593Smuzhiyun    arg)
3406*4882a593Smuzhiyun      func_fatal_error "you must specify an argument for -Xcompile"
3407*4882a593Smuzhiyun      ;;
3408*4882a593Smuzhiyun    target)
3409*4882a593Smuzhiyun      func_fatal_error "you must specify a target with '-o'"
3410*4882a593Smuzhiyun      ;;
3411*4882a593Smuzhiyun    *)
3412*4882a593Smuzhiyun      # Get the name of the library object.
3413*4882a593Smuzhiyun      test -z "$libobj" && {
3414*4882a593Smuzhiyun	func_basename "$srcfile"
3415*4882a593Smuzhiyun	libobj=$func_basename_result
3416*4882a593Smuzhiyun      }
3417*4882a593Smuzhiyun      ;;
3418*4882a593Smuzhiyun    esac
3419*4882a593Smuzhiyun
3420*4882a593Smuzhiyun    # Recognize several different file suffixes.
3421*4882a593Smuzhiyun    # If the user specifies -o file.o, it is replaced with file.lo
3422*4882a593Smuzhiyun    case $libobj in
3423*4882a593Smuzhiyun    *.[cCFSifmso] | \
3424*4882a593Smuzhiyun    *.ada | *.adb | *.ads | *.asm | \
3425*4882a593Smuzhiyun    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3426*4882a593Smuzhiyun    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3427*4882a593Smuzhiyun      func_xform "$libobj"
3428*4882a593Smuzhiyun      libobj=$func_xform_result
3429*4882a593Smuzhiyun      ;;
3430*4882a593Smuzhiyun    esac
3431*4882a593Smuzhiyun
3432*4882a593Smuzhiyun    case $libobj in
3433*4882a593Smuzhiyun    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3434*4882a593Smuzhiyun    *)
3435*4882a593Smuzhiyun      func_fatal_error "cannot determine name of library object from '$libobj'"
3436*4882a593Smuzhiyun      ;;
3437*4882a593Smuzhiyun    esac
3438*4882a593Smuzhiyun
3439*4882a593Smuzhiyun    func_infer_tag $base_compile
3440*4882a593Smuzhiyun
3441*4882a593Smuzhiyun    for arg in $later; do
3442*4882a593Smuzhiyun      case $arg in
3443*4882a593Smuzhiyun      -shared)
3444*4882a593Smuzhiyun	test yes = "$build_libtool_libs" \
3445*4882a593Smuzhiyun	  || func_fatal_configuration "cannot build a shared library"
3446*4882a593Smuzhiyun	build_old_libs=no
3447*4882a593Smuzhiyun	continue
3448*4882a593Smuzhiyun	;;
3449*4882a593Smuzhiyun
3450*4882a593Smuzhiyun      -static)
3451*4882a593Smuzhiyun	build_libtool_libs=no
3452*4882a593Smuzhiyun	build_old_libs=yes
3453*4882a593Smuzhiyun	continue
3454*4882a593Smuzhiyun	;;
3455*4882a593Smuzhiyun
3456*4882a593Smuzhiyun      -prefer-pic)
3457*4882a593Smuzhiyun	pic_mode=yes
3458*4882a593Smuzhiyun	continue
3459*4882a593Smuzhiyun	;;
3460*4882a593Smuzhiyun
3461*4882a593Smuzhiyun      -prefer-non-pic)
3462*4882a593Smuzhiyun	pic_mode=no
3463*4882a593Smuzhiyun	continue
3464*4882a593Smuzhiyun	;;
3465*4882a593Smuzhiyun      esac
3466*4882a593Smuzhiyun    done
3467*4882a593Smuzhiyun
3468*4882a593Smuzhiyun    func_quote_for_eval "$libobj"
3469*4882a593Smuzhiyun    test "X$libobj" != "X$func_quote_for_eval_result" \
3470*4882a593Smuzhiyun      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3471*4882a593Smuzhiyun      && func_warning "libobj name '$libobj' may not contain shell special characters."
3472*4882a593Smuzhiyun    func_dirname_and_basename "$obj" "/" ""
3473*4882a593Smuzhiyun    objname=$func_basename_result
3474*4882a593Smuzhiyun    xdir=$func_dirname_result
3475*4882a593Smuzhiyun    lobj=$xdir$objdir/$objname
3476*4882a593Smuzhiyun
3477*4882a593Smuzhiyun    test -z "$base_compile" && \
3478*4882a593Smuzhiyun      func_fatal_help "you must specify a compilation command"
3479*4882a593Smuzhiyun
3480*4882a593Smuzhiyun    # Delete any leftover library objects.
3481*4882a593Smuzhiyun    if test yes = "$build_old_libs"; then
3482*4882a593Smuzhiyun      removelist="$obj $lobj $libobj ${libobj}T"
3483*4882a593Smuzhiyun    else
3484*4882a593Smuzhiyun      removelist="$lobj $libobj ${libobj}T"
3485*4882a593Smuzhiyun    fi
3486*4882a593Smuzhiyun
3487*4882a593Smuzhiyun    # On Cygwin there's no "real" PIC flag so we must build both object types
3488*4882a593Smuzhiyun    case $host_os in
3489*4882a593Smuzhiyun    cygwin* | mingw* | pw32* | os2* | cegcc*)
3490*4882a593Smuzhiyun      pic_mode=default
3491*4882a593Smuzhiyun      ;;
3492*4882a593Smuzhiyun    esac
3493*4882a593Smuzhiyun    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3494*4882a593Smuzhiyun      # non-PIC code in shared libraries is not supported
3495*4882a593Smuzhiyun      pic_mode=default
3496*4882a593Smuzhiyun    fi
3497*4882a593Smuzhiyun
3498*4882a593Smuzhiyun    # Calculate the filename of the output object if compiler does
3499*4882a593Smuzhiyun    # not support -o with -c
3500*4882a593Smuzhiyun    if test no = "$compiler_c_o"; then
3501*4882a593Smuzhiyun      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3502*4882a593Smuzhiyun      lockfile=$output_obj.lock
3503*4882a593Smuzhiyun    else
3504*4882a593Smuzhiyun      output_obj=
3505*4882a593Smuzhiyun      need_locks=no
3506*4882a593Smuzhiyun      lockfile=
3507*4882a593Smuzhiyun    fi
3508*4882a593Smuzhiyun
3509*4882a593Smuzhiyun    # Lock this critical section if it is needed
3510*4882a593Smuzhiyun    # We use this script file to make the link, it avoids creating a new file
3511*4882a593Smuzhiyun    if test yes = "$need_locks"; then
3512*4882a593Smuzhiyun      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3513*4882a593Smuzhiyun	func_echo "Waiting for $lockfile to be removed"
3514*4882a593Smuzhiyun	sleep 2
3515*4882a593Smuzhiyun      done
3516*4882a593Smuzhiyun    elif test warn = "$need_locks"; then
3517*4882a593Smuzhiyun      if test -f "$lockfile"; then
3518*4882a593Smuzhiyun	$ECHO "\
3519*4882a593Smuzhiyun*** ERROR, $lockfile exists and contains:
3520*4882a593Smuzhiyun`cat $lockfile 2>/dev/null`
3521*4882a593Smuzhiyun
3522*4882a593SmuzhiyunThis indicates that another process is trying to use the same
3523*4882a593Smuzhiyuntemporary object file, and libtool could not work around it because
3524*4882a593Smuzhiyunyour compiler does not support '-c' and '-o' together.  If you
3525*4882a593Smuzhiyunrepeat this compilation, it may succeed, by chance, but you had better
3526*4882a593Smuzhiyunavoid parallel builds (make -j) in this platform, or get a better
3527*4882a593Smuzhiyuncompiler."
3528*4882a593Smuzhiyun
3529*4882a593Smuzhiyun	$opt_dry_run || $RM $removelist
3530*4882a593Smuzhiyun	exit $EXIT_FAILURE
3531*4882a593Smuzhiyun      fi
3532*4882a593Smuzhiyun      func_append removelist " $output_obj"
3533*4882a593Smuzhiyun      $ECHO "$srcfile" > "$lockfile"
3534*4882a593Smuzhiyun    fi
3535*4882a593Smuzhiyun
3536*4882a593Smuzhiyun    $opt_dry_run || $RM $removelist
3537*4882a593Smuzhiyun    func_append removelist " $lockfile"
3538*4882a593Smuzhiyun    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3539*4882a593Smuzhiyun
3540*4882a593Smuzhiyun    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3541*4882a593Smuzhiyun    srcfile=$func_to_tool_file_result
3542*4882a593Smuzhiyun    func_quote_for_eval "$srcfile"
3543*4882a593Smuzhiyun    qsrcfile=$func_quote_for_eval_result
3544*4882a593Smuzhiyun
3545*4882a593Smuzhiyun    # Only build a PIC object if we are building libtool libraries.
3546*4882a593Smuzhiyun    if test yes = "$build_libtool_libs"; then
3547*4882a593Smuzhiyun      # Without this assignment, base_compile gets emptied.
3548*4882a593Smuzhiyun      fbsd_hideous_sh_bug=$base_compile
3549*4882a593Smuzhiyun
3550*4882a593Smuzhiyun      if test no != "$pic_mode"; then
3551*4882a593Smuzhiyun	command="$base_compile $qsrcfile $pic_flag"
3552*4882a593Smuzhiyun      else
3553*4882a593Smuzhiyun	# Don't build PIC code
3554*4882a593Smuzhiyun	command="$base_compile $qsrcfile"
3555*4882a593Smuzhiyun      fi
3556*4882a593Smuzhiyun
3557*4882a593Smuzhiyun      func_mkdir_p "$xdir$objdir"
3558*4882a593Smuzhiyun
3559*4882a593Smuzhiyun      if test -z "$output_obj"; then
3560*4882a593Smuzhiyun	# Place PIC objects in $objdir
3561*4882a593Smuzhiyun	func_append command " -o $lobj"
3562*4882a593Smuzhiyun      fi
3563*4882a593Smuzhiyun
3564*4882a593Smuzhiyun      func_show_eval_locale "$command"	\
3565*4882a593Smuzhiyun          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3566*4882a593Smuzhiyun
3567*4882a593Smuzhiyun      if test warn = "$need_locks" &&
3568*4882a593Smuzhiyun	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3569*4882a593Smuzhiyun	$ECHO "\
3570*4882a593Smuzhiyun*** ERROR, $lockfile contains:
3571*4882a593Smuzhiyun`cat $lockfile 2>/dev/null`
3572*4882a593Smuzhiyun
3573*4882a593Smuzhiyunbut it should contain:
3574*4882a593Smuzhiyun$srcfile
3575*4882a593Smuzhiyun
3576*4882a593SmuzhiyunThis indicates that another process is trying to use the same
3577*4882a593Smuzhiyuntemporary object file, and libtool could not work around it because
3578*4882a593Smuzhiyunyour compiler does not support '-c' and '-o' together.  If you
3579*4882a593Smuzhiyunrepeat this compilation, it may succeed, by chance, but you had better
3580*4882a593Smuzhiyunavoid parallel builds (make -j) in this platform, or get a better
3581*4882a593Smuzhiyuncompiler."
3582*4882a593Smuzhiyun
3583*4882a593Smuzhiyun	$opt_dry_run || $RM $removelist
3584*4882a593Smuzhiyun	exit $EXIT_FAILURE
3585*4882a593Smuzhiyun      fi
3586*4882a593Smuzhiyun
3587*4882a593Smuzhiyun      # Just move the object if needed, then go on to compile the next one
3588*4882a593Smuzhiyun      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3589*4882a593Smuzhiyun	func_show_eval '$MV "$output_obj" "$lobj"' \
3590*4882a593Smuzhiyun	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3591*4882a593Smuzhiyun      fi
3592*4882a593Smuzhiyun
3593*4882a593Smuzhiyun      # Allow error messages only from the first compilation.
3594*4882a593Smuzhiyun      if test yes = "$suppress_opt"; then
3595*4882a593Smuzhiyun	suppress_output=' >/dev/null 2>&1'
3596*4882a593Smuzhiyun      fi
3597*4882a593Smuzhiyun    fi
3598*4882a593Smuzhiyun
3599*4882a593Smuzhiyun    # Only build a position-dependent object if we build old libraries.
3600*4882a593Smuzhiyun    if test yes = "$build_old_libs"; then
3601*4882a593Smuzhiyun      if test yes != "$pic_mode"; then
3602*4882a593Smuzhiyun	# Don't build PIC code
3603*4882a593Smuzhiyun	command="$base_compile $qsrcfile$pie_flag"
3604*4882a593Smuzhiyun      else
3605*4882a593Smuzhiyun	command="$base_compile $qsrcfile $pic_flag"
3606*4882a593Smuzhiyun      fi
3607*4882a593Smuzhiyun      if test yes = "$compiler_c_o"; then
3608*4882a593Smuzhiyun	func_append command " -o $obj"
3609*4882a593Smuzhiyun      fi
3610*4882a593Smuzhiyun
3611*4882a593Smuzhiyun      # Suppress compiler output if we already did a PIC compilation.
3612*4882a593Smuzhiyun      func_append command "$suppress_output"
3613*4882a593Smuzhiyun      func_show_eval_locale "$command" \
3614*4882a593Smuzhiyun        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3615*4882a593Smuzhiyun
3616*4882a593Smuzhiyun      if test warn = "$need_locks" &&
3617*4882a593Smuzhiyun	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3618*4882a593Smuzhiyun	$ECHO "\
3619*4882a593Smuzhiyun*** ERROR, $lockfile contains:
3620*4882a593Smuzhiyun`cat $lockfile 2>/dev/null`
3621*4882a593Smuzhiyun
3622*4882a593Smuzhiyunbut it should contain:
3623*4882a593Smuzhiyun$srcfile
3624*4882a593Smuzhiyun
3625*4882a593SmuzhiyunThis indicates that another process is trying to use the same
3626*4882a593Smuzhiyuntemporary object file, and libtool could not work around it because
3627*4882a593Smuzhiyunyour compiler does not support '-c' and '-o' together.  If you
3628*4882a593Smuzhiyunrepeat this compilation, it may succeed, by chance, but you had better
3629*4882a593Smuzhiyunavoid parallel builds (make -j) in this platform, or get a better
3630*4882a593Smuzhiyuncompiler."
3631*4882a593Smuzhiyun
3632*4882a593Smuzhiyun	$opt_dry_run || $RM $removelist
3633*4882a593Smuzhiyun	exit $EXIT_FAILURE
3634*4882a593Smuzhiyun      fi
3635*4882a593Smuzhiyun
3636*4882a593Smuzhiyun      # Just move the object if needed
3637*4882a593Smuzhiyun      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3638*4882a593Smuzhiyun	func_show_eval '$MV "$output_obj" "$obj"' \
3639*4882a593Smuzhiyun	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3640*4882a593Smuzhiyun      fi
3641*4882a593Smuzhiyun    fi
3642*4882a593Smuzhiyun
3643*4882a593Smuzhiyun    $opt_dry_run || {
3644*4882a593Smuzhiyun      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3645*4882a593Smuzhiyun
3646*4882a593Smuzhiyun      # Unlock the critical section if it was locked
3647*4882a593Smuzhiyun      if test no != "$need_locks"; then
3648*4882a593Smuzhiyun	removelist=$lockfile
3649*4882a593Smuzhiyun        $RM "$lockfile"
3650*4882a593Smuzhiyun      fi
3651*4882a593Smuzhiyun    }
3652*4882a593Smuzhiyun
3653*4882a593Smuzhiyun    exit $EXIT_SUCCESS
3654*4882a593Smuzhiyun}
3655*4882a593Smuzhiyun
3656*4882a593Smuzhiyun$opt_help || {
3657*4882a593Smuzhiyun  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3658*4882a593Smuzhiyun}
3659*4882a593Smuzhiyun
3660*4882a593Smuzhiyunfunc_mode_help ()
3661*4882a593Smuzhiyun{
3662*4882a593Smuzhiyun    # We need to display help for each of the modes.
3663*4882a593Smuzhiyun    case $opt_mode in
3664*4882a593Smuzhiyun      "")
3665*4882a593Smuzhiyun        # Generic help is extracted from the usage comments
3666*4882a593Smuzhiyun        # at the start of this file.
3667*4882a593Smuzhiyun        func_help
3668*4882a593Smuzhiyun        ;;
3669*4882a593Smuzhiyun
3670*4882a593Smuzhiyun      clean)
3671*4882a593Smuzhiyun        $ECHO \
3672*4882a593Smuzhiyun"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3673*4882a593Smuzhiyun
3674*4882a593SmuzhiyunRemove files from the build directory.
3675*4882a593Smuzhiyun
3676*4882a593SmuzhiyunRM is the name of the program to use to delete files associated with each FILE
3677*4882a593Smuzhiyun(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3678*4882a593Smuzhiyunto RM.
3679*4882a593Smuzhiyun
3680*4882a593SmuzhiyunIf FILE is a libtool library, object or program, all the files associated
3681*4882a593Smuzhiyunwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3682*4882a593Smuzhiyun        ;;
3683*4882a593Smuzhiyun
3684*4882a593Smuzhiyun      compile)
3685*4882a593Smuzhiyun      $ECHO \
3686*4882a593Smuzhiyun"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3687*4882a593Smuzhiyun
3688*4882a593SmuzhiyunCompile a source file into a libtool library object.
3689*4882a593Smuzhiyun
3690*4882a593SmuzhiyunThis mode accepts the following additional options:
3691*4882a593Smuzhiyun
3692*4882a593Smuzhiyun  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3693*4882a593Smuzhiyun  -no-suppress      do not suppress compiler output for multiple passes
3694*4882a593Smuzhiyun  -prefer-pic       try to build PIC objects only
3695*4882a593Smuzhiyun  -prefer-non-pic   try to build non-PIC objects only
3696*4882a593Smuzhiyun  -shared           do not build a '.o' file suitable for static linking
3697*4882a593Smuzhiyun  -static           only build a '.o' file suitable for static linking
3698*4882a593Smuzhiyun  -Wc,FLAG          pass FLAG directly to the compiler
3699*4882a593Smuzhiyun
3700*4882a593SmuzhiyunCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3701*4882a593Smuzhiyunfrom the given SOURCEFILE.
3702*4882a593Smuzhiyun
3703*4882a593SmuzhiyunThe output file name is determined by removing the directory component from
3704*4882a593SmuzhiyunSOURCEFILE, then substituting the C source code suffix '.c' with the
3705*4882a593Smuzhiyunlibrary object suffix, '.lo'."
3706*4882a593Smuzhiyun        ;;
3707*4882a593Smuzhiyun
3708*4882a593Smuzhiyun      execute)
3709*4882a593Smuzhiyun        $ECHO \
3710*4882a593Smuzhiyun"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3711*4882a593Smuzhiyun
3712*4882a593SmuzhiyunAutomatically set library path, then run a program.
3713*4882a593Smuzhiyun
3714*4882a593SmuzhiyunThis mode accepts the following additional options:
3715*4882a593Smuzhiyun
3716*4882a593Smuzhiyun  -dlopen FILE      add the directory containing FILE to the library path
3717*4882a593Smuzhiyun
3718*4882a593SmuzhiyunThis mode sets the library path environment variable according to '-dlopen'
3719*4882a593Smuzhiyunflags.
3720*4882a593Smuzhiyun
3721*4882a593SmuzhiyunIf any of the ARGS are libtool executable wrappers, then they are translated
3722*4882a593Smuzhiyuninto their corresponding uninstalled binary, and any of their required library
3723*4882a593Smuzhiyundirectories are added to the library path.
3724*4882a593Smuzhiyun
3725*4882a593SmuzhiyunThen, COMMAND is executed, with ARGS as arguments."
3726*4882a593Smuzhiyun        ;;
3727*4882a593Smuzhiyun
3728*4882a593Smuzhiyun      finish)
3729*4882a593Smuzhiyun        $ECHO \
3730*4882a593Smuzhiyun"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3731*4882a593Smuzhiyun
3732*4882a593SmuzhiyunComplete the installation of libtool libraries.
3733*4882a593Smuzhiyun
3734*4882a593SmuzhiyunEach LIBDIR is a directory that contains libtool libraries.
3735*4882a593Smuzhiyun
3736*4882a593SmuzhiyunThe commands that this mode executes may require superuser privileges.  Use
3737*4882a593Smuzhiyunthe '--dry-run' option if you just want to see what would be executed."
3738*4882a593Smuzhiyun        ;;
3739*4882a593Smuzhiyun
3740*4882a593Smuzhiyun      install)
3741*4882a593Smuzhiyun        $ECHO \
3742*4882a593Smuzhiyun"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3743*4882a593Smuzhiyun
3744*4882a593SmuzhiyunInstall executables or libraries.
3745*4882a593Smuzhiyun
3746*4882a593SmuzhiyunINSTALL-COMMAND is the installation command.  The first component should be
3747*4882a593Smuzhiyuneither the 'install' or 'cp' program.
3748*4882a593Smuzhiyun
3749*4882a593SmuzhiyunThe following components of INSTALL-COMMAND are treated specially:
3750*4882a593Smuzhiyun
3751*4882a593Smuzhiyun  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3752*4882a593Smuzhiyun
3753*4882a593SmuzhiyunThe rest of the components are interpreted as arguments to that command (only
3754*4882a593SmuzhiyunBSD-compatible install options are recognized)."
3755*4882a593Smuzhiyun        ;;
3756*4882a593Smuzhiyun
3757*4882a593Smuzhiyun      link)
3758*4882a593Smuzhiyun        $ECHO \
3759*4882a593Smuzhiyun"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3760*4882a593Smuzhiyun
3761*4882a593SmuzhiyunLink object files or libraries together to form another library, or to
3762*4882a593Smuzhiyuncreate an executable program.
3763*4882a593Smuzhiyun
3764*4882a593SmuzhiyunLINK-COMMAND is a command using the C compiler that you would use to create
3765*4882a593Smuzhiyuna program from several object files.
3766*4882a593Smuzhiyun
3767*4882a593SmuzhiyunThe following components of LINK-COMMAND are treated specially:
3768*4882a593Smuzhiyun
3769*4882a593Smuzhiyun  -all-static       do not do any dynamic linking at all
3770*4882a593Smuzhiyun  -avoid-version    do not add a version suffix if possible
3771*4882a593Smuzhiyun  -bindir BINDIR    specify path to binaries directory (for systems where
3772*4882a593Smuzhiyun                    libraries must be found in the PATH setting at runtime)
3773*4882a593Smuzhiyun  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3774*4882a593Smuzhiyun  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3775*4882a593Smuzhiyun  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3776*4882a593Smuzhiyun  -export-symbols SYMFILE
3777*4882a593Smuzhiyun                    try to export only the symbols listed in SYMFILE
3778*4882a593Smuzhiyun  -export-symbols-regex REGEX
3779*4882a593Smuzhiyun                    try to export only the symbols matching REGEX
3780*4882a593Smuzhiyun  -LLIBDIR          search LIBDIR for required installed libraries
3781*4882a593Smuzhiyun  -lNAME            OUTPUT-FILE requires the installed library libNAME
3782*4882a593Smuzhiyun  -module           build a library that can dlopened
3783*4882a593Smuzhiyun  -no-fast-install  disable the fast-install mode
3784*4882a593Smuzhiyun  -no-install       link a not-installable executable
3785*4882a593Smuzhiyun  -no-undefined     declare that a library does not refer to external symbols
3786*4882a593Smuzhiyun  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3787*4882a593Smuzhiyun  -objectlist FILE  use a list of object files found in FILE to specify objects
3788*4882a593Smuzhiyun  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3789*4882a593Smuzhiyun  -precious-files-regex REGEX
3790*4882a593Smuzhiyun                    don't remove output files matching REGEX
3791*4882a593Smuzhiyun  -release RELEASE  specify package release information
3792*4882a593Smuzhiyun  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
3793*4882a593Smuzhiyun  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
3794*4882a593Smuzhiyun  -shared           only do dynamic linking of libtool libraries
3795*4882a593Smuzhiyun  -shrext SUFFIX    override the standard shared library file extension
3796*4882a593Smuzhiyun  -static           do not do any dynamic linking of uninstalled libtool libraries
3797*4882a593Smuzhiyun  -static-libtool-libs
3798*4882a593Smuzhiyun                    do not do any dynamic linking of libtool libraries
3799*4882a593Smuzhiyun  -version-info CURRENT[:REVISION[:AGE]]
3800*4882a593Smuzhiyun                    specify library version info [each variable defaults to 0]
3801*4882a593Smuzhiyun  -weak LIBNAME     declare that the target provides the LIBNAME interface
3802*4882a593Smuzhiyun  -Wc,FLAG
3803*4882a593Smuzhiyun  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
3804*4882a593Smuzhiyun  -Wl,FLAG
3805*4882a593Smuzhiyun  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
3806*4882a593Smuzhiyun  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
3807*4882a593Smuzhiyun
3808*4882a593SmuzhiyunAll other options (arguments beginning with '-') are ignored.
3809*4882a593Smuzhiyun
3810*4882a593SmuzhiyunEvery other argument is treated as a filename.  Files ending in '.la' are
3811*4882a593Smuzhiyuntreated as uninstalled libtool libraries, other files are standard or library
3812*4882a593Smuzhiyunobject files.
3813*4882a593Smuzhiyun
3814*4882a593SmuzhiyunIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
3815*4882a593Smuzhiyunonly library objects ('.lo' files) may be specified, and '-rpath' is
3816*4882a593Smuzhiyunrequired, except when creating a convenience library.
3817*4882a593Smuzhiyun
3818*4882a593SmuzhiyunIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
3819*4882a593Smuzhiyunusing 'ar' and 'ranlib', or on Windows using 'lib'.
3820*4882a593Smuzhiyun
3821*4882a593SmuzhiyunIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
3822*4882a593Smuzhiyunis created, otherwise an executable program is created."
3823*4882a593Smuzhiyun        ;;
3824*4882a593Smuzhiyun
3825*4882a593Smuzhiyun      uninstall)
3826*4882a593Smuzhiyun        $ECHO \
3827*4882a593Smuzhiyun"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
3828*4882a593Smuzhiyun
3829*4882a593SmuzhiyunRemove libraries from an installation directory.
3830*4882a593Smuzhiyun
3831*4882a593SmuzhiyunRM is the name of the program to use to delete files associated with each FILE
3832*4882a593Smuzhiyun(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3833*4882a593Smuzhiyunto RM.
3834*4882a593Smuzhiyun
3835*4882a593SmuzhiyunIf FILE is a libtool library, all the files associated with it are deleted.
3836*4882a593SmuzhiyunOtherwise, only FILE itself is deleted using RM."
3837*4882a593Smuzhiyun        ;;
3838*4882a593Smuzhiyun
3839*4882a593Smuzhiyun      *)
3840*4882a593Smuzhiyun        func_fatal_help "invalid operation mode '$opt_mode'"
3841*4882a593Smuzhiyun        ;;
3842*4882a593Smuzhiyun    esac
3843*4882a593Smuzhiyun
3844*4882a593Smuzhiyun    echo
3845*4882a593Smuzhiyun    $ECHO "Try '$progname --help' for more information about other modes."
3846*4882a593Smuzhiyun}
3847*4882a593Smuzhiyun
3848*4882a593Smuzhiyun# Now that we've collected a possible --mode arg, show help if necessary
3849*4882a593Smuzhiyunif $opt_help; then
3850*4882a593Smuzhiyun  if test : = "$opt_help"; then
3851*4882a593Smuzhiyun    func_mode_help
3852*4882a593Smuzhiyun  else
3853*4882a593Smuzhiyun    {
3854*4882a593Smuzhiyun      func_help noexit
3855*4882a593Smuzhiyun      for opt_mode in compile link execute install finish uninstall clean; do
3856*4882a593Smuzhiyun	func_mode_help
3857*4882a593Smuzhiyun      done
3858*4882a593Smuzhiyun    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
3859*4882a593Smuzhiyun    {
3860*4882a593Smuzhiyun      func_help noexit
3861*4882a593Smuzhiyun      for opt_mode in compile link execute install finish uninstall clean; do
3862*4882a593Smuzhiyun	echo
3863*4882a593Smuzhiyun	func_mode_help
3864*4882a593Smuzhiyun      done
3865*4882a593Smuzhiyun    } |
3866*4882a593Smuzhiyun    $SED '1d
3867*4882a593Smuzhiyun      /^When reporting/,/^Report/{
3868*4882a593Smuzhiyun	H
3869*4882a593Smuzhiyun	d
3870*4882a593Smuzhiyun      }
3871*4882a593Smuzhiyun      $x
3872*4882a593Smuzhiyun      /information about other modes/d
3873*4882a593Smuzhiyun      /more detailed .*MODE/d
3874*4882a593Smuzhiyun      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
3875*4882a593Smuzhiyun  fi
3876*4882a593Smuzhiyun  exit $?
3877*4882a593Smuzhiyunfi
3878*4882a593Smuzhiyun
3879*4882a593Smuzhiyun
3880*4882a593Smuzhiyun# func_mode_execute arg...
3881*4882a593Smuzhiyunfunc_mode_execute ()
3882*4882a593Smuzhiyun{
3883*4882a593Smuzhiyun    $debug_cmd
3884*4882a593Smuzhiyun
3885*4882a593Smuzhiyun    # The first argument is the command name.
3886*4882a593Smuzhiyun    cmd=$nonopt
3887*4882a593Smuzhiyun    test -z "$cmd" && \
3888*4882a593Smuzhiyun      func_fatal_help "you must specify a COMMAND"
3889*4882a593Smuzhiyun
3890*4882a593Smuzhiyun    # Handle -dlopen flags immediately.
3891*4882a593Smuzhiyun    for file in $opt_dlopen; do
3892*4882a593Smuzhiyun      test -f "$file" \
3893*4882a593Smuzhiyun	|| func_fatal_help "'$file' is not a file"
3894*4882a593Smuzhiyun
3895*4882a593Smuzhiyun      dir=
3896*4882a593Smuzhiyun      case $file in
3897*4882a593Smuzhiyun      *.la)
3898*4882a593Smuzhiyun	func_resolve_sysroot "$file"
3899*4882a593Smuzhiyun	file=$func_resolve_sysroot_result
3900*4882a593Smuzhiyun
3901*4882a593Smuzhiyun	# Check to see that this really is a libtool archive.
3902*4882a593Smuzhiyun	func_lalib_unsafe_p "$file" \
3903*4882a593Smuzhiyun	  || func_fatal_help "'$lib' is not a valid libtool archive"
3904*4882a593Smuzhiyun
3905*4882a593Smuzhiyun	# Read the libtool library.
3906*4882a593Smuzhiyun	dlname=
3907*4882a593Smuzhiyun	library_names=
3908*4882a593Smuzhiyun	func_source "$file"
3909*4882a593Smuzhiyun
3910*4882a593Smuzhiyun	# Skip this library if it cannot be dlopened.
3911*4882a593Smuzhiyun	if test -z "$dlname"; then
3912*4882a593Smuzhiyun	  # Warn if it was a shared library.
3913*4882a593Smuzhiyun	  test -n "$library_names" && \
3914*4882a593Smuzhiyun	    func_warning "'$file' was not linked with '-export-dynamic'"
3915*4882a593Smuzhiyun	  continue
3916*4882a593Smuzhiyun	fi
3917*4882a593Smuzhiyun
3918*4882a593Smuzhiyun	func_dirname "$file" "" "."
3919*4882a593Smuzhiyun	dir=$func_dirname_result
3920*4882a593Smuzhiyun
3921*4882a593Smuzhiyun	if test -f "$dir/$objdir/$dlname"; then
3922*4882a593Smuzhiyun	  func_append dir "/$objdir"
3923*4882a593Smuzhiyun	else
3924*4882a593Smuzhiyun	  if test ! -f "$dir/$dlname"; then
3925*4882a593Smuzhiyun	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
3926*4882a593Smuzhiyun	  fi
3927*4882a593Smuzhiyun	fi
3928*4882a593Smuzhiyun	;;
3929*4882a593Smuzhiyun
3930*4882a593Smuzhiyun      *.lo)
3931*4882a593Smuzhiyun	# Just add the directory containing the .lo file.
3932*4882a593Smuzhiyun	func_dirname "$file" "" "."
3933*4882a593Smuzhiyun	dir=$func_dirname_result
3934*4882a593Smuzhiyun	;;
3935*4882a593Smuzhiyun
3936*4882a593Smuzhiyun      *)
3937*4882a593Smuzhiyun	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
3938*4882a593Smuzhiyun	continue
3939*4882a593Smuzhiyun	;;
3940*4882a593Smuzhiyun      esac
3941*4882a593Smuzhiyun
3942*4882a593Smuzhiyun      # Get the absolute pathname.
3943*4882a593Smuzhiyun      absdir=`cd "$dir" && pwd`
3944*4882a593Smuzhiyun      test -n "$absdir" && dir=$absdir
3945*4882a593Smuzhiyun
3946*4882a593Smuzhiyun      # Now add the directory to shlibpath_var.
3947*4882a593Smuzhiyun      if eval "test -z \"\$$shlibpath_var\""; then
3948*4882a593Smuzhiyun	eval "$shlibpath_var=\"\$dir\""
3949*4882a593Smuzhiyun      else
3950*4882a593Smuzhiyun	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
3951*4882a593Smuzhiyun      fi
3952*4882a593Smuzhiyun    done
3953*4882a593Smuzhiyun
3954*4882a593Smuzhiyun    # This variable tells wrapper scripts just to set shlibpath_var
3955*4882a593Smuzhiyun    # rather than running their programs.
3956*4882a593Smuzhiyun    libtool_execute_magic=$magic
3957*4882a593Smuzhiyun
3958*4882a593Smuzhiyun    # Check if any of the arguments is a wrapper script.
3959*4882a593Smuzhiyun    args=
3960*4882a593Smuzhiyun    for file
3961*4882a593Smuzhiyun    do
3962*4882a593Smuzhiyun      case $file in
3963*4882a593Smuzhiyun      -* | *.la | *.lo ) ;;
3964*4882a593Smuzhiyun      *)
3965*4882a593Smuzhiyun	# Do a test to see if this is really a libtool program.
3966*4882a593Smuzhiyun	if func_ltwrapper_script_p "$file"; then
3967*4882a593Smuzhiyun	  func_source "$file"
3968*4882a593Smuzhiyun	  # Transform arg to wrapped name.
3969*4882a593Smuzhiyun	  file=$progdir/$program
3970*4882a593Smuzhiyun	elif func_ltwrapper_executable_p "$file"; then
3971*4882a593Smuzhiyun	  func_ltwrapper_scriptname "$file"
3972*4882a593Smuzhiyun	  func_source "$func_ltwrapper_scriptname_result"
3973*4882a593Smuzhiyun	  # Transform arg to wrapped name.
3974*4882a593Smuzhiyun	  file=$progdir/$program
3975*4882a593Smuzhiyun	fi
3976*4882a593Smuzhiyun	;;
3977*4882a593Smuzhiyun      esac
3978*4882a593Smuzhiyun      # Quote arguments (to preserve shell metacharacters).
3979*4882a593Smuzhiyun      func_append_quoted args "$file"
3980*4882a593Smuzhiyun    done
3981*4882a593Smuzhiyun
3982*4882a593Smuzhiyun    if $opt_dry_run; then
3983*4882a593Smuzhiyun      # Display what would be done.
3984*4882a593Smuzhiyun      if test -n "$shlibpath_var"; then
3985*4882a593Smuzhiyun	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
3986*4882a593Smuzhiyun	echo "export $shlibpath_var"
3987*4882a593Smuzhiyun      fi
3988*4882a593Smuzhiyun      $ECHO "$cmd$args"
3989*4882a593Smuzhiyun      exit $EXIT_SUCCESS
3990*4882a593Smuzhiyun    else
3991*4882a593Smuzhiyun      if test -n "$shlibpath_var"; then
3992*4882a593Smuzhiyun	# Export the shlibpath_var.
3993*4882a593Smuzhiyun	eval "export $shlibpath_var"
3994*4882a593Smuzhiyun      fi
3995*4882a593Smuzhiyun
3996*4882a593Smuzhiyun      # Restore saved environment variables
3997*4882a593Smuzhiyun      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
3998*4882a593Smuzhiyun      do
3999*4882a593Smuzhiyun	eval "if test \"\${save_$lt_var+set}\" = set; then
4000*4882a593Smuzhiyun                $lt_var=\$save_$lt_var; export $lt_var
4001*4882a593Smuzhiyun	      else
4002*4882a593Smuzhiyun		$lt_unset $lt_var
4003*4882a593Smuzhiyun	      fi"
4004*4882a593Smuzhiyun      done
4005*4882a593Smuzhiyun
4006*4882a593Smuzhiyun      # Now prepare to actually exec the command.
4007*4882a593Smuzhiyun      exec_cmd=\$cmd$args
4008*4882a593Smuzhiyun    fi
4009*4882a593Smuzhiyun}
4010*4882a593Smuzhiyun
4011*4882a593Smuzhiyuntest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
4012*4882a593Smuzhiyun
4013*4882a593Smuzhiyun
4014*4882a593Smuzhiyun# func_mode_finish arg...
4015*4882a593Smuzhiyunfunc_mode_finish ()
4016*4882a593Smuzhiyun{
4017*4882a593Smuzhiyun    $debug_cmd
4018*4882a593Smuzhiyun
4019*4882a593Smuzhiyun    libs=
4020*4882a593Smuzhiyun    libdirs=
4021*4882a593Smuzhiyun    admincmds=
4022*4882a593Smuzhiyun
4023*4882a593Smuzhiyun    for opt in "$nonopt" ${1+"$@"}
4024*4882a593Smuzhiyun    do
4025*4882a593Smuzhiyun      if test -d "$opt"; then
4026*4882a593Smuzhiyun	func_append libdirs " $opt"
4027*4882a593Smuzhiyun
4028*4882a593Smuzhiyun      elif test -f "$opt"; then
4029*4882a593Smuzhiyun	if func_lalib_unsafe_p "$opt"; then
4030*4882a593Smuzhiyun	  func_append libs " $opt"
4031*4882a593Smuzhiyun	else
4032*4882a593Smuzhiyun	  func_warning "'$opt' is not a valid libtool archive"
4033*4882a593Smuzhiyun	fi
4034*4882a593Smuzhiyun
4035*4882a593Smuzhiyun      else
4036*4882a593Smuzhiyun	func_fatal_error "invalid argument '$opt'"
4037*4882a593Smuzhiyun      fi
4038*4882a593Smuzhiyun    done
4039*4882a593Smuzhiyun
4040*4882a593Smuzhiyun    if test -n "$libs"; then
4041*4882a593Smuzhiyun      if test -n "$lt_sysroot"; then
4042*4882a593Smuzhiyun        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4043*4882a593Smuzhiyun        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4044*4882a593Smuzhiyun      else
4045*4882a593Smuzhiyun        sysroot_cmd=
4046*4882a593Smuzhiyun      fi
4047*4882a593Smuzhiyun
4048*4882a593Smuzhiyun      # Remove sysroot references
4049*4882a593Smuzhiyun      if $opt_dry_run; then
4050*4882a593Smuzhiyun        for lib in $libs; do
4051*4882a593Smuzhiyun          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4052*4882a593Smuzhiyun        done
4053*4882a593Smuzhiyun      else
4054*4882a593Smuzhiyun        tmpdir=`func_mktempdir`
4055*4882a593Smuzhiyun        for lib in $libs; do
4056*4882a593Smuzhiyun	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4057*4882a593Smuzhiyun	    > $tmpdir/tmp-la
4058*4882a593Smuzhiyun	  mv -f $tmpdir/tmp-la $lib
4059*4882a593Smuzhiyun	done
4060*4882a593Smuzhiyun        ${RM}r "$tmpdir"
4061*4882a593Smuzhiyun      fi
4062*4882a593Smuzhiyun    fi
4063*4882a593Smuzhiyun
4064*4882a593Smuzhiyun    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4065*4882a593Smuzhiyun      for libdir in $libdirs; do
4066*4882a593Smuzhiyun	if test -n "$finish_cmds"; then
4067*4882a593Smuzhiyun	  # Do each command in the finish commands.
4068*4882a593Smuzhiyun	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4069*4882a593Smuzhiyun'"$cmd"'"'
4070*4882a593Smuzhiyun	fi
4071*4882a593Smuzhiyun	if test -n "$finish_eval"; then
4072*4882a593Smuzhiyun	  # Do the single finish_eval.
4073*4882a593Smuzhiyun	  eval cmds=\"$finish_eval\"
4074*4882a593Smuzhiyun	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4075*4882a593Smuzhiyun       $cmds"
4076*4882a593Smuzhiyun	fi
4077*4882a593Smuzhiyun      done
4078*4882a593Smuzhiyun    fi
4079*4882a593Smuzhiyun
4080*4882a593Smuzhiyun    # Exit here if they wanted silent mode.
4081*4882a593Smuzhiyun    $opt_quiet && exit $EXIT_SUCCESS
4082*4882a593Smuzhiyun
4083*4882a593Smuzhiyun    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4084*4882a593Smuzhiyun      echo "----------------------------------------------------------------------"
4085*4882a593Smuzhiyun      echo "Libraries have been installed in:"
4086*4882a593Smuzhiyun      for libdir in $libdirs; do
4087*4882a593Smuzhiyun	$ECHO "   $libdir"
4088*4882a593Smuzhiyun      done
4089*4882a593Smuzhiyun      echo
4090*4882a593Smuzhiyun      echo "If you ever happen to want to link against installed libraries"
4091*4882a593Smuzhiyun      echo "in a given directory, LIBDIR, you must either use libtool, and"
4092*4882a593Smuzhiyun      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4093*4882a593Smuzhiyun      echo "flag during linking and do at least one of the following:"
4094*4882a593Smuzhiyun      if test -n "$shlibpath_var"; then
4095*4882a593Smuzhiyun	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4096*4882a593Smuzhiyun	echo "     during execution"
4097*4882a593Smuzhiyun      fi
4098*4882a593Smuzhiyun      if test -n "$runpath_var"; then
4099*4882a593Smuzhiyun	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4100*4882a593Smuzhiyun	echo "     during linking"
4101*4882a593Smuzhiyun      fi
4102*4882a593Smuzhiyun      if test -n "$hardcode_libdir_flag_spec"; then
4103*4882a593Smuzhiyun	libdir=LIBDIR
4104*4882a593Smuzhiyun	eval flag=\"$hardcode_libdir_flag_spec\"
4105*4882a593Smuzhiyun
4106*4882a593Smuzhiyun	$ECHO "   - use the '$flag' linker flag"
4107*4882a593Smuzhiyun      fi
4108*4882a593Smuzhiyun      if test -n "$admincmds"; then
4109*4882a593Smuzhiyun	$ECHO "   - have your system administrator run these commands:$admincmds"
4110*4882a593Smuzhiyun      fi
4111*4882a593Smuzhiyun      if test -f /etc/ld.so.conf; then
4112*4882a593Smuzhiyun	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4113*4882a593Smuzhiyun      fi
4114*4882a593Smuzhiyun      echo
4115*4882a593Smuzhiyun
4116*4882a593Smuzhiyun      echo "See any operating system documentation about shared libraries for"
4117*4882a593Smuzhiyun      case $host in
4118*4882a593Smuzhiyun	solaris2.[6789]|solaris2.1[0-9])
4119*4882a593Smuzhiyun	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4120*4882a593Smuzhiyun	  echo "pages."
4121*4882a593Smuzhiyun	  ;;
4122*4882a593Smuzhiyun	*)
4123*4882a593Smuzhiyun	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4124*4882a593Smuzhiyun	  ;;
4125*4882a593Smuzhiyun      esac
4126*4882a593Smuzhiyun      echo "----------------------------------------------------------------------"
4127*4882a593Smuzhiyun    fi
4128*4882a593Smuzhiyun    exit $EXIT_SUCCESS
4129*4882a593Smuzhiyun}
4130*4882a593Smuzhiyun
4131*4882a593Smuzhiyuntest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4132*4882a593Smuzhiyun
4133*4882a593Smuzhiyun
4134*4882a593Smuzhiyun# func_mode_install arg...
4135*4882a593Smuzhiyunfunc_mode_install ()
4136*4882a593Smuzhiyun{
4137*4882a593Smuzhiyun    $debug_cmd
4138*4882a593Smuzhiyun
4139*4882a593Smuzhiyun    # There may be an optional sh(1) argument at the beginning of
4140*4882a593Smuzhiyun    # install_prog (especially on Windows NT).
4141*4882a593Smuzhiyun    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4142*4882a593Smuzhiyun       # Allow the use of GNU shtool's install command.
4143*4882a593Smuzhiyun       case $nonopt in *shtool*) :;; *) false;; esac
4144*4882a593Smuzhiyun    then
4145*4882a593Smuzhiyun      # Aesthetically quote it.
4146*4882a593Smuzhiyun      func_quote_for_eval "$nonopt"
4147*4882a593Smuzhiyun      install_prog="$func_quote_for_eval_result "
4148*4882a593Smuzhiyun      arg=$1
4149*4882a593Smuzhiyun      shift
4150*4882a593Smuzhiyun    else
4151*4882a593Smuzhiyun      install_prog=
4152*4882a593Smuzhiyun      arg=$nonopt
4153*4882a593Smuzhiyun    fi
4154*4882a593Smuzhiyun
4155*4882a593Smuzhiyun    # The real first argument should be the name of the installation program.
4156*4882a593Smuzhiyun    # Aesthetically quote it.
4157*4882a593Smuzhiyun    func_quote_for_eval "$arg"
4158*4882a593Smuzhiyun    func_append install_prog "$func_quote_for_eval_result"
4159*4882a593Smuzhiyun    install_shared_prog=$install_prog
4160*4882a593Smuzhiyun    case " $install_prog " in
4161*4882a593Smuzhiyun      *[\\\ /]cp\ *) install_cp=: ;;
4162*4882a593Smuzhiyun      *) install_cp=false ;;
4163*4882a593Smuzhiyun    esac
4164*4882a593Smuzhiyun
4165*4882a593Smuzhiyun    # We need to accept at least all the BSD install flags.
4166*4882a593Smuzhiyun    dest=
4167*4882a593Smuzhiyun    files=
4168*4882a593Smuzhiyun    opts=
4169*4882a593Smuzhiyun    prev=
4170*4882a593Smuzhiyun    install_type=
4171*4882a593Smuzhiyun    isdir=false
4172*4882a593Smuzhiyun    stripme=
4173*4882a593Smuzhiyun    no_mode=:
4174*4882a593Smuzhiyun    for arg
4175*4882a593Smuzhiyun    do
4176*4882a593Smuzhiyun      arg2=
4177*4882a593Smuzhiyun      if test -n "$dest"; then
4178*4882a593Smuzhiyun	func_append files " $dest"
4179*4882a593Smuzhiyun	dest=$arg
4180*4882a593Smuzhiyun	continue
4181*4882a593Smuzhiyun      fi
4182*4882a593Smuzhiyun
4183*4882a593Smuzhiyun      case $arg in
4184*4882a593Smuzhiyun      -d) isdir=: ;;
4185*4882a593Smuzhiyun      -f)
4186*4882a593Smuzhiyun	if $install_cp; then :; else
4187*4882a593Smuzhiyun	  prev=$arg
4188*4882a593Smuzhiyun	fi
4189*4882a593Smuzhiyun	;;
4190*4882a593Smuzhiyun      -g | -m | -o)
4191*4882a593Smuzhiyun	prev=$arg
4192*4882a593Smuzhiyun	;;
4193*4882a593Smuzhiyun      -s)
4194*4882a593Smuzhiyun	stripme=" -s"
4195*4882a593Smuzhiyun	continue
4196*4882a593Smuzhiyun	;;
4197*4882a593Smuzhiyun      -*)
4198*4882a593Smuzhiyun	;;
4199*4882a593Smuzhiyun      *)
4200*4882a593Smuzhiyun	# If the previous option needed an argument, then skip it.
4201*4882a593Smuzhiyun	if test -n "$prev"; then
4202*4882a593Smuzhiyun	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4203*4882a593Smuzhiyun	    arg2=$install_override_mode
4204*4882a593Smuzhiyun	    no_mode=false
4205*4882a593Smuzhiyun	  fi
4206*4882a593Smuzhiyun	  prev=
4207*4882a593Smuzhiyun	else
4208*4882a593Smuzhiyun	  dest=$arg
4209*4882a593Smuzhiyun	  continue
4210*4882a593Smuzhiyun	fi
4211*4882a593Smuzhiyun	;;
4212*4882a593Smuzhiyun      esac
4213*4882a593Smuzhiyun
4214*4882a593Smuzhiyun      # Aesthetically quote the argument.
4215*4882a593Smuzhiyun      func_quote_for_eval "$arg"
4216*4882a593Smuzhiyun      func_append install_prog " $func_quote_for_eval_result"
4217*4882a593Smuzhiyun      if test -n "$arg2"; then
4218*4882a593Smuzhiyun	func_quote_for_eval "$arg2"
4219*4882a593Smuzhiyun      fi
4220*4882a593Smuzhiyun      func_append install_shared_prog " $func_quote_for_eval_result"
4221*4882a593Smuzhiyun    done
4222*4882a593Smuzhiyun
4223*4882a593Smuzhiyun    test -z "$install_prog" && \
4224*4882a593Smuzhiyun      func_fatal_help "you must specify an install program"
4225*4882a593Smuzhiyun
4226*4882a593Smuzhiyun    test -n "$prev" && \
4227*4882a593Smuzhiyun      func_fatal_help "the '$prev' option requires an argument"
4228*4882a593Smuzhiyun
4229*4882a593Smuzhiyun    if test -n "$install_override_mode" && $no_mode; then
4230*4882a593Smuzhiyun      if $install_cp; then :; else
4231*4882a593Smuzhiyun	func_quote_for_eval "$install_override_mode"
4232*4882a593Smuzhiyun	func_append install_shared_prog " -m $func_quote_for_eval_result"
4233*4882a593Smuzhiyun      fi
4234*4882a593Smuzhiyun    fi
4235*4882a593Smuzhiyun
4236*4882a593Smuzhiyun    if test -z "$files"; then
4237*4882a593Smuzhiyun      if test -z "$dest"; then
4238*4882a593Smuzhiyun	func_fatal_help "no file or destination specified"
4239*4882a593Smuzhiyun      else
4240*4882a593Smuzhiyun	func_fatal_help "you must specify a destination"
4241*4882a593Smuzhiyun      fi
4242*4882a593Smuzhiyun    fi
4243*4882a593Smuzhiyun
4244*4882a593Smuzhiyun    # Strip any trailing slash from the destination.
4245*4882a593Smuzhiyun    func_stripname '' '/' "$dest"
4246*4882a593Smuzhiyun    dest=$func_stripname_result
4247*4882a593Smuzhiyun
4248*4882a593Smuzhiyun    # Check to see that the destination is a directory.
4249*4882a593Smuzhiyun    test -d "$dest" && isdir=:
4250*4882a593Smuzhiyun    if $isdir; then
4251*4882a593Smuzhiyun      destdir=$dest
4252*4882a593Smuzhiyun      destname=
4253*4882a593Smuzhiyun    else
4254*4882a593Smuzhiyun      func_dirname_and_basename "$dest" "" "."
4255*4882a593Smuzhiyun      destdir=$func_dirname_result
4256*4882a593Smuzhiyun      destname=$func_basename_result
4257*4882a593Smuzhiyun
4258*4882a593Smuzhiyun      # Not a directory, so check to see that there is only one file specified.
4259*4882a593Smuzhiyun      set dummy $files; shift
4260*4882a593Smuzhiyun      test "$#" -gt 1 && \
4261*4882a593Smuzhiyun	func_fatal_help "'$dest' is not a directory"
4262*4882a593Smuzhiyun    fi
4263*4882a593Smuzhiyun    case $destdir in
4264*4882a593Smuzhiyun    [\\/]* | [A-Za-z]:[\\/]*) ;;
4265*4882a593Smuzhiyun    *)
4266*4882a593Smuzhiyun      for file in $files; do
4267*4882a593Smuzhiyun	case $file in
4268*4882a593Smuzhiyun	*.lo) ;;
4269*4882a593Smuzhiyun	*)
4270*4882a593Smuzhiyun	  func_fatal_help "'$destdir' must be an absolute directory name"
4271*4882a593Smuzhiyun	  ;;
4272*4882a593Smuzhiyun	esac
4273*4882a593Smuzhiyun      done
4274*4882a593Smuzhiyun      ;;
4275*4882a593Smuzhiyun    esac
4276*4882a593Smuzhiyun
4277*4882a593Smuzhiyun    # This variable tells wrapper scripts just to set variables rather
4278*4882a593Smuzhiyun    # than running their programs.
4279*4882a593Smuzhiyun    libtool_install_magic=$magic
4280*4882a593Smuzhiyun
4281*4882a593Smuzhiyun    staticlibs=
4282*4882a593Smuzhiyun    future_libdirs=
4283*4882a593Smuzhiyun    current_libdirs=
4284*4882a593Smuzhiyun    for file in $files; do
4285*4882a593Smuzhiyun
4286*4882a593Smuzhiyun      # Do each installation.
4287*4882a593Smuzhiyun      case $file in
4288*4882a593Smuzhiyun      *.$libext)
4289*4882a593Smuzhiyun	# Do the static libraries later.
4290*4882a593Smuzhiyun	func_append staticlibs " $file"
4291*4882a593Smuzhiyun	;;
4292*4882a593Smuzhiyun
4293*4882a593Smuzhiyun      *.la)
4294*4882a593Smuzhiyun	func_resolve_sysroot "$file"
4295*4882a593Smuzhiyun	file=$func_resolve_sysroot_result
4296*4882a593Smuzhiyun
4297*4882a593Smuzhiyun	# Check to see that this really is a libtool archive.
4298*4882a593Smuzhiyun	func_lalib_unsafe_p "$file" \
4299*4882a593Smuzhiyun	  || func_fatal_help "'$file' is not a valid libtool archive"
4300*4882a593Smuzhiyun
4301*4882a593Smuzhiyun	library_names=
4302*4882a593Smuzhiyun	old_library=
4303*4882a593Smuzhiyun	relink_command=
4304*4882a593Smuzhiyun	func_source "$file"
4305*4882a593Smuzhiyun
4306*4882a593Smuzhiyun	# Add the libdir to current_libdirs if it is the destination.
4307*4882a593Smuzhiyun	if test "X$destdir" = "X$libdir"; then
4308*4882a593Smuzhiyun	  case "$current_libdirs " in
4309*4882a593Smuzhiyun	  *" $libdir "*) ;;
4310*4882a593Smuzhiyun	  *) func_append current_libdirs " $libdir" ;;
4311*4882a593Smuzhiyun	  esac
4312*4882a593Smuzhiyun	else
4313*4882a593Smuzhiyun	  # Note the libdir as a future libdir.
4314*4882a593Smuzhiyun	  case "$future_libdirs " in
4315*4882a593Smuzhiyun	  *" $libdir "*) ;;
4316*4882a593Smuzhiyun	  *) func_append future_libdirs " $libdir" ;;
4317*4882a593Smuzhiyun	  esac
4318*4882a593Smuzhiyun	fi
4319*4882a593Smuzhiyun
4320*4882a593Smuzhiyun	func_dirname "$file" "/" ""
4321*4882a593Smuzhiyun	dir=$func_dirname_result
4322*4882a593Smuzhiyun	func_append dir "$objdir"
4323*4882a593Smuzhiyun
4324*4882a593Smuzhiyun	if test -n "$relink_command"; then
4325*4882a593Smuzhiyun	  # Determine the prefix the user has applied to our future dir.
4326*4882a593Smuzhiyun	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4327*4882a593Smuzhiyun
4328*4882a593Smuzhiyun	  # Don't allow the user to place us outside of our expected
4329*4882a593Smuzhiyun	  # location b/c this prevents finding dependent libraries that
4330*4882a593Smuzhiyun	  # are installed to the same prefix.
4331*4882a593Smuzhiyun	  # At present, this check doesn't affect windows .dll's that
4332*4882a593Smuzhiyun	  # are installed into $libdir/../bin (currently, that works fine)
4333*4882a593Smuzhiyun	  # but it's something to keep an eye on.
4334*4882a593Smuzhiyun	  test "$inst_prefix_dir" = "$destdir" && \
4335*4882a593Smuzhiyun	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4336*4882a593Smuzhiyun
4337*4882a593Smuzhiyun	  if test -n "$inst_prefix_dir"; then
4338*4882a593Smuzhiyun	    # Stick the inst_prefix_dir data into the link command.
4339*4882a593Smuzhiyun	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4340*4882a593Smuzhiyun	  else
4341*4882a593Smuzhiyun	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4342*4882a593Smuzhiyun	  fi
4343*4882a593Smuzhiyun
4344*4882a593Smuzhiyun	  func_warning "relinking '$file'"
4345*4882a593Smuzhiyun	  func_show_eval "$relink_command" \
4346*4882a593Smuzhiyun	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4347*4882a593Smuzhiyun	fi
4348*4882a593Smuzhiyun
4349*4882a593Smuzhiyun	# See the names of the shared library.
4350*4882a593Smuzhiyun	set dummy $library_names; shift
4351*4882a593Smuzhiyun	if test -n "$1"; then
4352*4882a593Smuzhiyun	  realname=$1
4353*4882a593Smuzhiyun	  shift
4354*4882a593Smuzhiyun
4355*4882a593Smuzhiyun	  srcname=$realname
4356*4882a593Smuzhiyun	  test -n "$relink_command" && srcname=${realname}T
4357*4882a593Smuzhiyun
4358*4882a593Smuzhiyun	  # Install the shared library and build the symlinks.
4359*4882a593Smuzhiyun	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4360*4882a593Smuzhiyun	      'exit $?'
4361*4882a593Smuzhiyun	  tstripme=$stripme
4362*4882a593Smuzhiyun	  case $host_os in
4363*4882a593Smuzhiyun	  cygwin* | mingw* | pw32* | cegcc*)
4364*4882a593Smuzhiyun	    case $realname in
4365*4882a593Smuzhiyun	    *.dll.a)
4366*4882a593Smuzhiyun	      tstripme=
4367*4882a593Smuzhiyun	      ;;
4368*4882a593Smuzhiyun	    esac
4369*4882a593Smuzhiyun	    ;;
4370*4882a593Smuzhiyun	  os2*)
4371*4882a593Smuzhiyun	    case $realname in
4372*4882a593Smuzhiyun	    *_dll.a)
4373*4882a593Smuzhiyun	      tstripme=
4374*4882a593Smuzhiyun	      ;;
4375*4882a593Smuzhiyun	    esac
4376*4882a593Smuzhiyun	    ;;
4377*4882a593Smuzhiyun	  esac
4378*4882a593Smuzhiyun	  if test -n "$tstripme" && test -n "$striplib"; then
4379*4882a593Smuzhiyun	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4380*4882a593Smuzhiyun	  fi
4381*4882a593Smuzhiyun
4382*4882a593Smuzhiyun	  if test "$#" -gt 0; then
4383*4882a593Smuzhiyun	    # Delete the old symlinks, and create new ones.
4384*4882a593Smuzhiyun	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4385*4882a593Smuzhiyun	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4386*4882a593Smuzhiyun	    # so we also need to try rm && ln -s.
4387*4882a593Smuzhiyun	    for linkname
4388*4882a593Smuzhiyun	    do
4389*4882a593Smuzhiyun	      test "$linkname" != "$realname" \
4390*4882a593Smuzhiyun		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4391*4882a593Smuzhiyun	    done
4392*4882a593Smuzhiyun	  fi
4393*4882a593Smuzhiyun
4394*4882a593Smuzhiyun	  # Do each command in the postinstall commands.
4395*4882a593Smuzhiyun	  lib=$destdir/$realname
4396*4882a593Smuzhiyun	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4397*4882a593Smuzhiyun	fi
4398*4882a593Smuzhiyun
4399*4882a593Smuzhiyun	# Install the pseudo-library for information purposes.
4400*4882a593Smuzhiyun	func_basename "$file"
4401*4882a593Smuzhiyun	name=$func_basename_result
4402*4882a593Smuzhiyun	instname=$dir/${name}i
4403*4882a593Smuzhiyun	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4404*4882a593Smuzhiyun
4405*4882a593Smuzhiyun	# Maybe install the static library, too.
4406*4882a593Smuzhiyun	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4407*4882a593Smuzhiyun	;;
4408*4882a593Smuzhiyun
4409*4882a593Smuzhiyun      *.lo)
4410*4882a593Smuzhiyun	# Install (i.e. copy) a libtool object.
4411*4882a593Smuzhiyun
4412*4882a593Smuzhiyun	# Figure out destination file name, if it wasn't already specified.
4413*4882a593Smuzhiyun	if test -n "$destname"; then
4414*4882a593Smuzhiyun	  destfile=$destdir/$destname
4415*4882a593Smuzhiyun	else
4416*4882a593Smuzhiyun	  func_basename "$file"
4417*4882a593Smuzhiyun	  destfile=$func_basename_result
4418*4882a593Smuzhiyun	  destfile=$destdir/$destfile
4419*4882a593Smuzhiyun	fi
4420*4882a593Smuzhiyun
4421*4882a593Smuzhiyun	# Deduce the name of the destination old-style object file.
4422*4882a593Smuzhiyun	case $destfile in
4423*4882a593Smuzhiyun	*.lo)
4424*4882a593Smuzhiyun	  func_lo2o "$destfile"
4425*4882a593Smuzhiyun	  staticdest=$func_lo2o_result
4426*4882a593Smuzhiyun	  ;;
4427*4882a593Smuzhiyun	*.$objext)
4428*4882a593Smuzhiyun	  staticdest=$destfile
4429*4882a593Smuzhiyun	  destfile=
4430*4882a593Smuzhiyun	  ;;
4431*4882a593Smuzhiyun	*)
4432*4882a593Smuzhiyun	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4433*4882a593Smuzhiyun	  ;;
4434*4882a593Smuzhiyun	esac
4435*4882a593Smuzhiyun
4436*4882a593Smuzhiyun	# Install the libtool object if requested.
4437*4882a593Smuzhiyun	test -n "$destfile" && \
4438*4882a593Smuzhiyun	  func_show_eval "$install_prog $file $destfile" 'exit $?'
4439*4882a593Smuzhiyun
4440*4882a593Smuzhiyun	# Install the old object if enabled.
4441*4882a593Smuzhiyun	if test yes = "$build_old_libs"; then
4442*4882a593Smuzhiyun	  # Deduce the name of the old-style object file.
4443*4882a593Smuzhiyun	  func_lo2o "$file"
4444*4882a593Smuzhiyun	  staticobj=$func_lo2o_result
4445*4882a593Smuzhiyun	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4446*4882a593Smuzhiyun	fi
4447*4882a593Smuzhiyun	exit $EXIT_SUCCESS
4448*4882a593Smuzhiyun	;;
4449*4882a593Smuzhiyun
4450*4882a593Smuzhiyun      *)
4451*4882a593Smuzhiyun	# Figure out destination file name, if it wasn't already specified.
4452*4882a593Smuzhiyun	if test -n "$destname"; then
4453*4882a593Smuzhiyun	  destfile=$destdir/$destname
4454*4882a593Smuzhiyun	else
4455*4882a593Smuzhiyun	  func_basename "$file"
4456*4882a593Smuzhiyun	  destfile=$func_basename_result
4457*4882a593Smuzhiyun	  destfile=$destdir/$destfile
4458*4882a593Smuzhiyun	fi
4459*4882a593Smuzhiyun
4460*4882a593Smuzhiyun	# If the file is missing, and there is a .exe on the end, strip it
4461*4882a593Smuzhiyun	# because it is most likely a libtool script we actually want to
4462*4882a593Smuzhiyun	# install
4463*4882a593Smuzhiyun	stripped_ext=
4464*4882a593Smuzhiyun	case $file in
4465*4882a593Smuzhiyun	  *.exe)
4466*4882a593Smuzhiyun	    if test ! -f "$file"; then
4467*4882a593Smuzhiyun	      func_stripname '' '.exe' "$file"
4468*4882a593Smuzhiyun	      file=$func_stripname_result
4469*4882a593Smuzhiyun	      stripped_ext=.exe
4470*4882a593Smuzhiyun	    fi
4471*4882a593Smuzhiyun	    ;;
4472*4882a593Smuzhiyun	esac
4473*4882a593Smuzhiyun
4474*4882a593Smuzhiyun	# Do a test to see if this is really a libtool program.
4475*4882a593Smuzhiyun	case $host in
4476*4882a593Smuzhiyun	*cygwin* | *mingw*)
4477*4882a593Smuzhiyun	    if func_ltwrapper_executable_p "$file"; then
4478*4882a593Smuzhiyun	      func_ltwrapper_scriptname "$file"
4479*4882a593Smuzhiyun	      wrapper=$func_ltwrapper_scriptname_result
4480*4882a593Smuzhiyun	    else
4481*4882a593Smuzhiyun	      func_stripname '' '.exe' "$file"
4482*4882a593Smuzhiyun	      wrapper=$func_stripname_result
4483*4882a593Smuzhiyun	    fi
4484*4882a593Smuzhiyun	    ;;
4485*4882a593Smuzhiyun	*)
4486*4882a593Smuzhiyun	    wrapper=$file
4487*4882a593Smuzhiyun	    ;;
4488*4882a593Smuzhiyun	esac
4489*4882a593Smuzhiyun	if func_ltwrapper_script_p "$wrapper"; then
4490*4882a593Smuzhiyun	  notinst_deplibs=
4491*4882a593Smuzhiyun	  relink_command=
4492*4882a593Smuzhiyun
4493*4882a593Smuzhiyun	  func_source "$wrapper"
4494*4882a593Smuzhiyun
4495*4882a593Smuzhiyun	  # Check the variables that should have been set.
4496*4882a593Smuzhiyun	  test -z "$generated_by_libtool_version" && \
4497*4882a593Smuzhiyun	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4498*4882a593Smuzhiyun
4499*4882a593Smuzhiyun	  finalize=:
4500*4882a593Smuzhiyun	  for lib in $notinst_deplibs; do
4501*4882a593Smuzhiyun	    # Check to see that each library is installed.
4502*4882a593Smuzhiyun	    libdir=
4503*4882a593Smuzhiyun	    if test -f "$lib"; then
4504*4882a593Smuzhiyun	      func_source "$lib"
4505*4882a593Smuzhiyun	    fi
4506*4882a593Smuzhiyun	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4507*4882a593Smuzhiyun	    if test -n "$libdir" && test ! -f "$libfile"; then
4508*4882a593Smuzhiyun	      func_warning "'$lib' has not been installed in '$libdir'"
4509*4882a593Smuzhiyun	      finalize=false
4510*4882a593Smuzhiyun	    fi
4511*4882a593Smuzhiyun	  done
4512*4882a593Smuzhiyun
4513*4882a593Smuzhiyun	  relink_command=
4514*4882a593Smuzhiyun	  func_source "$wrapper"
4515*4882a593Smuzhiyun
4516*4882a593Smuzhiyun	  outputname=
4517*4882a593Smuzhiyun	  if test no = "$fast_install" && test -n "$relink_command"; then
4518*4882a593Smuzhiyun	    $opt_dry_run || {
4519*4882a593Smuzhiyun	      if $finalize; then
4520*4882a593Smuzhiyun	        tmpdir=`func_mktempdir`
4521*4882a593Smuzhiyun		func_basename "$file$stripped_ext"
4522*4882a593Smuzhiyun		file=$func_basename_result
4523*4882a593Smuzhiyun	        outputname=$tmpdir/$file
4524*4882a593Smuzhiyun	        # Replace the output file specification.
4525*4882a593Smuzhiyun	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4526*4882a593Smuzhiyun
4527*4882a593Smuzhiyun	        $opt_quiet || {
4528*4882a593Smuzhiyun	          func_quote_for_expand "$relink_command"
4529*4882a593Smuzhiyun		  eval "func_echo $func_quote_for_expand_result"
4530*4882a593Smuzhiyun	        }
4531*4882a593Smuzhiyun	        if eval "$relink_command"; then :
4532*4882a593Smuzhiyun	          else
4533*4882a593Smuzhiyun		  func_error "error: relink '$file' with the above command before installing it"
4534*4882a593Smuzhiyun		  $opt_dry_run || ${RM}r "$tmpdir"
4535*4882a593Smuzhiyun		  continue
4536*4882a593Smuzhiyun	        fi
4537*4882a593Smuzhiyun	        file=$outputname
4538*4882a593Smuzhiyun	      else
4539*4882a593Smuzhiyun	        func_warning "cannot relink '$file'"
4540*4882a593Smuzhiyun	      fi
4541*4882a593Smuzhiyun	    }
4542*4882a593Smuzhiyun	  else
4543*4882a593Smuzhiyun	    # Install the binary that we compiled earlier.
4544*4882a593Smuzhiyun	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4545*4882a593Smuzhiyun	  fi
4546*4882a593Smuzhiyun	fi
4547*4882a593Smuzhiyun
4548*4882a593Smuzhiyun	# remove .exe since cygwin /usr/bin/install will append another
4549*4882a593Smuzhiyun	# one anyway
4550*4882a593Smuzhiyun	case $install_prog,$host in
4551*4882a593Smuzhiyun	*/usr/bin/install*,*cygwin*)
4552*4882a593Smuzhiyun	  case $file:$destfile in
4553*4882a593Smuzhiyun	  *.exe:*.exe)
4554*4882a593Smuzhiyun	    # this is ok
4555*4882a593Smuzhiyun	    ;;
4556*4882a593Smuzhiyun	  *.exe:*)
4557*4882a593Smuzhiyun	    destfile=$destfile.exe
4558*4882a593Smuzhiyun	    ;;
4559*4882a593Smuzhiyun	  *:*.exe)
4560*4882a593Smuzhiyun	    func_stripname '' '.exe' "$destfile"
4561*4882a593Smuzhiyun	    destfile=$func_stripname_result
4562*4882a593Smuzhiyun	    ;;
4563*4882a593Smuzhiyun	  esac
4564*4882a593Smuzhiyun	  ;;
4565*4882a593Smuzhiyun	esac
4566*4882a593Smuzhiyun	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4567*4882a593Smuzhiyun	$opt_dry_run || if test -n "$outputname"; then
4568*4882a593Smuzhiyun	  ${RM}r "$tmpdir"
4569*4882a593Smuzhiyun	fi
4570*4882a593Smuzhiyun	;;
4571*4882a593Smuzhiyun      esac
4572*4882a593Smuzhiyun    done
4573*4882a593Smuzhiyun
4574*4882a593Smuzhiyun    for file in $staticlibs; do
4575*4882a593Smuzhiyun      func_basename "$file"
4576*4882a593Smuzhiyun      name=$func_basename_result
4577*4882a593Smuzhiyun
4578*4882a593Smuzhiyun      # Set up the ranlib parameters.
4579*4882a593Smuzhiyun      oldlib=$destdir/$name
4580*4882a593Smuzhiyun      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4581*4882a593Smuzhiyun      tool_oldlib=$func_to_tool_file_result
4582*4882a593Smuzhiyun
4583*4882a593Smuzhiyun      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4584*4882a593Smuzhiyun
4585*4882a593Smuzhiyun      if test -n "$stripme" && test -n "$old_striplib"; then
4586*4882a593Smuzhiyun	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4587*4882a593Smuzhiyun      fi
4588*4882a593Smuzhiyun
4589*4882a593Smuzhiyun      # Do each command in the postinstall commands.
4590*4882a593Smuzhiyun      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4591*4882a593Smuzhiyun    done
4592*4882a593Smuzhiyun
4593*4882a593Smuzhiyun    test -n "$future_libdirs" && \
4594*4882a593Smuzhiyun      func_warning "remember to run '$progname --finish$future_libdirs'"
4595*4882a593Smuzhiyun
4596*4882a593Smuzhiyun    if test -n "$current_libdirs"; then
4597*4882a593Smuzhiyun      # Maybe just do a dry run.
4598*4882a593Smuzhiyun      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4599*4882a593Smuzhiyun      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4600*4882a593Smuzhiyun    else
4601*4882a593Smuzhiyun      exit $EXIT_SUCCESS
4602*4882a593Smuzhiyun    fi
4603*4882a593Smuzhiyun}
4604*4882a593Smuzhiyun
4605*4882a593Smuzhiyuntest install = "$opt_mode" && func_mode_install ${1+"$@"}
4606*4882a593Smuzhiyun
4607*4882a593Smuzhiyun
4608*4882a593Smuzhiyun# func_generate_dlsyms outputname originator pic_p
4609*4882a593Smuzhiyun# Extract symbols from dlprefiles and create ${outputname}S.o with
4610*4882a593Smuzhiyun# a dlpreopen symbol table.
4611*4882a593Smuzhiyunfunc_generate_dlsyms ()
4612*4882a593Smuzhiyun{
4613*4882a593Smuzhiyun    $debug_cmd
4614*4882a593Smuzhiyun
4615*4882a593Smuzhiyun    my_outputname=$1
4616*4882a593Smuzhiyun    my_originator=$2
4617*4882a593Smuzhiyun    my_pic_p=${3-false}
4618*4882a593Smuzhiyun    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4619*4882a593Smuzhiyun    my_dlsyms=
4620*4882a593Smuzhiyun
4621*4882a593Smuzhiyun    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4622*4882a593Smuzhiyun      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4623*4882a593Smuzhiyun	my_dlsyms=${my_outputname}S.c
4624*4882a593Smuzhiyun      else
4625*4882a593Smuzhiyun	func_error "not configured to extract global symbols from dlpreopened files"
4626*4882a593Smuzhiyun      fi
4627*4882a593Smuzhiyun    fi
4628*4882a593Smuzhiyun
4629*4882a593Smuzhiyun    if test -n "$my_dlsyms"; then
4630*4882a593Smuzhiyun      case $my_dlsyms in
4631*4882a593Smuzhiyun      "") ;;
4632*4882a593Smuzhiyun      *.c)
4633*4882a593Smuzhiyun	# Discover the nlist of each of the dlfiles.
4634*4882a593Smuzhiyun	nlist=$output_objdir/$my_outputname.nm
4635*4882a593Smuzhiyun
4636*4882a593Smuzhiyun	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4637*4882a593Smuzhiyun
4638*4882a593Smuzhiyun	# Parse the name list into a source file.
4639*4882a593Smuzhiyun	func_verbose "creating $output_objdir/$my_dlsyms"
4640*4882a593Smuzhiyun
4641*4882a593Smuzhiyun	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4642*4882a593Smuzhiyun/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4643*4882a593Smuzhiyun/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4644*4882a593Smuzhiyun
4645*4882a593Smuzhiyun#ifdef __cplusplus
4646*4882a593Smuzhiyunextern \"C\" {
4647*4882a593Smuzhiyun#endif
4648*4882a593Smuzhiyun
4649*4882a593Smuzhiyun#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4650*4882a593Smuzhiyun#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4651*4882a593Smuzhiyun#endif
4652*4882a593Smuzhiyun
4653*4882a593Smuzhiyun/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4654*4882a593Smuzhiyun#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4655*4882a593Smuzhiyun/* DATA imports from DLLs on WIN32 can't be const, because runtime
4656*4882a593Smuzhiyun   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4657*4882a593Smuzhiyun# define LT_DLSYM_CONST
4658*4882a593Smuzhiyun#elif defined __osf__
4659*4882a593Smuzhiyun/* This system does not cope well with relocations in const data.  */
4660*4882a593Smuzhiyun# define LT_DLSYM_CONST
4661*4882a593Smuzhiyun#else
4662*4882a593Smuzhiyun# define LT_DLSYM_CONST const
4663*4882a593Smuzhiyun#endif
4664*4882a593Smuzhiyun
4665*4882a593Smuzhiyun#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4666*4882a593Smuzhiyun
4667*4882a593Smuzhiyun/* External symbol declarations for the compiler. */\
4668*4882a593Smuzhiyun"
4669*4882a593Smuzhiyun
4670*4882a593Smuzhiyun	if test yes = "$dlself"; then
4671*4882a593Smuzhiyun	  func_verbose "generating symbol list for '$output'"
4672*4882a593Smuzhiyun
4673*4882a593Smuzhiyun	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4674*4882a593Smuzhiyun
4675*4882a593Smuzhiyun	  # Add our own program objects to the symbol list.
4676*4882a593Smuzhiyun	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4677*4882a593Smuzhiyun	  for progfile in $progfiles; do
4678*4882a593Smuzhiyun	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4679*4882a593Smuzhiyun	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4680*4882a593Smuzhiyun	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4681*4882a593Smuzhiyun	  done
4682*4882a593Smuzhiyun
4683*4882a593Smuzhiyun	  if test -n "$exclude_expsyms"; then
4684*4882a593Smuzhiyun	    $opt_dry_run || {
4685*4882a593Smuzhiyun	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4686*4882a593Smuzhiyun	      eval '$MV "$nlist"T "$nlist"'
4687*4882a593Smuzhiyun	    }
4688*4882a593Smuzhiyun	  fi
4689*4882a593Smuzhiyun
4690*4882a593Smuzhiyun	  if test -n "$export_symbols_regex"; then
4691*4882a593Smuzhiyun	    $opt_dry_run || {
4692*4882a593Smuzhiyun	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4693*4882a593Smuzhiyun	      eval '$MV "$nlist"T "$nlist"'
4694*4882a593Smuzhiyun	    }
4695*4882a593Smuzhiyun	  fi
4696*4882a593Smuzhiyun
4697*4882a593Smuzhiyun	  # Prepare the list of exported symbols
4698*4882a593Smuzhiyun	  if test -z "$export_symbols"; then
4699*4882a593Smuzhiyun	    export_symbols=$output_objdir/$outputname.exp
4700*4882a593Smuzhiyun	    $opt_dry_run || {
4701*4882a593Smuzhiyun	      $RM $export_symbols
4702*4882a593Smuzhiyun	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4703*4882a593Smuzhiyun	      case $host in
4704*4882a593Smuzhiyun	      *cygwin* | *mingw* | *cegcc* )
4705*4882a593Smuzhiyun                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4706*4882a593Smuzhiyun                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4707*4882a593Smuzhiyun	        ;;
4708*4882a593Smuzhiyun	      esac
4709*4882a593Smuzhiyun	    }
4710*4882a593Smuzhiyun	  else
4711*4882a593Smuzhiyun	    $opt_dry_run || {
4712*4882a593Smuzhiyun	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4713*4882a593Smuzhiyun	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4714*4882a593Smuzhiyun	      eval '$MV "$nlist"T "$nlist"'
4715*4882a593Smuzhiyun	      case $host in
4716*4882a593Smuzhiyun	        *cygwin* | *mingw* | *cegcc* )
4717*4882a593Smuzhiyun	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4718*4882a593Smuzhiyun	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4719*4882a593Smuzhiyun	          ;;
4720*4882a593Smuzhiyun	      esac
4721*4882a593Smuzhiyun	    }
4722*4882a593Smuzhiyun	  fi
4723*4882a593Smuzhiyun	fi
4724*4882a593Smuzhiyun
4725*4882a593Smuzhiyun	for dlprefile in $dlprefiles; do
4726*4882a593Smuzhiyun	  func_verbose "extracting global C symbols from '$dlprefile'"
4727*4882a593Smuzhiyun	  func_basename "$dlprefile"
4728*4882a593Smuzhiyun	  name=$func_basename_result
4729*4882a593Smuzhiyun          case $host in
4730*4882a593Smuzhiyun	    *cygwin* | *mingw* | *cegcc* )
4731*4882a593Smuzhiyun	      # if an import library, we need to obtain dlname
4732*4882a593Smuzhiyun	      if func_win32_import_lib_p "$dlprefile"; then
4733*4882a593Smuzhiyun	        func_tr_sh "$dlprefile"
4734*4882a593Smuzhiyun	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4735*4882a593Smuzhiyun	        dlprefile_dlbasename=
4736*4882a593Smuzhiyun	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4737*4882a593Smuzhiyun	          # Use subshell, to avoid clobbering current variable values
4738*4882a593Smuzhiyun	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4739*4882a593Smuzhiyun	          if test -n "$dlprefile_dlname"; then
4740*4882a593Smuzhiyun	            func_basename "$dlprefile_dlname"
4741*4882a593Smuzhiyun	            dlprefile_dlbasename=$func_basename_result
4742*4882a593Smuzhiyun	          else
4743*4882a593Smuzhiyun	            # no lafile. user explicitly requested -dlpreopen <import library>.
4744*4882a593Smuzhiyun	            $sharedlib_from_linklib_cmd "$dlprefile"
4745*4882a593Smuzhiyun	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4746*4882a593Smuzhiyun	          fi
4747*4882a593Smuzhiyun	        fi
4748*4882a593Smuzhiyun	        $opt_dry_run || {
4749*4882a593Smuzhiyun	          if test -n "$dlprefile_dlbasename"; then
4750*4882a593Smuzhiyun	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4751*4882a593Smuzhiyun	          else
4752*4882a593Smuzhiyun	            func_warning "Could not compute DLL name from $name"
4753*4882a593Smuzhiyun	            eval '$ECHO ": $name " >> "$nlist"'
4754*4882a593Smuzhiyun	          fi
4755*4882a593Smuzhiyun	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4756*4882a593Smuzhiyun	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4757*4882a593Smuzhiyun	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4758*4882a593Smuzhiyun	        }
4759*4882a593Smuzhiyun	      else # not an import lib
4760*4882a593Smuzhiyun	        $opt_dry_run || {
4761*4882a593Smuzhiyun	          eval '$ECHO ": $name " >> "$nlist"'
4762*4882a593Smuzhiyun	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4763*4882a593Smuzhiyun	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4764*4882a593Smuzhiyun	        }
4765*4882a593Smuzhiyun	      fi
4766*4882a593Smuzhiyun	    ;;
4767*4882a593Smuzhiyun	    *)
4768*4882a593Smuzhiyun	      $opt_dry_run || {
4769*4882a593Smuzhiyun	        eval '$ECHO ": $name " >> "$nlist"'
4770*4882a593Smuzhiyun	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4771*4882a593Smuzhiyun	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4772*4882a593Smuzhiyun	      }
4773*4882a593Smuzhiyun	    ;;
4774*4882a593Smuzhiyun          esac
4775*4882a593Smuzhiyun	done
4776*4882a593Smuzhiyun
4777*4882a593Smuzhiyun	$opt_dry_run || {
4778*4882a593Smuzhiyun	  # Make sure we have at least an empty file.
4779*4882a593Smuzhiyun	  test -f "$nlist" || : > "$nlist"
4780*4882a593Smuzhiyun
4781*4882a593Smuzhiyun	  if test -n "$exclude_expsyms"; then
4782*4882a593Smuzhiyun	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4783*4882a593Smuzhiyun	    $MV "$nlist"T "$nlist"
4784*4882a593Smuzhiyun	  fi
4785*4882a593Smuzhiyun
4786*4882a593Smuzhiyun	  # Try sorting and uniquifying the output.
4787*4882a593Smuzhiyun	  if $GREP -v "^: " < "$nlist" |
4788*4882a593Smuzhiyun	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4789*4882a593Smuzhiyun		sort -k 3
4790*4882a593Smuzhiyun	      else
4791*4882a593Smuzhiyun		sort +2
4792*4882a593Smuzhiyun	      fi |
4793*4882a593Smuzhiyun	      uniq > "$nlist"S; then
4794*4882a593Smuzhiyun	    :
4795*4882a593Smuzhiyun	  else
4796*4882a593Smuzhiyun	    $GREP -v "^: " < "$nlist" > "$nlist"S
4797*4882a593Smuzhiyun	  fi
4798*4882a593Smuzhiyun
4799*4882a593Smuzhiyun	  if test -f "$nlist"S; then
4800*4882a593Smuzhiyun	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
4801*4882a593Smuzhiyun	  else
4802*4882a593Smuzhiyun	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
4803*4882a593Smuzhiyun	  fi
4804*4882a593Smuzhiyun
4805*4882a593Smuzhiyun	  func_show_eval '$RM "${nlist}I"'
4806*4882a593Smuzhiyun	  if test -n "$global_symbol_to_import"; then
4807*4882a593Smuzhiyun	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
4808*4882a593Smuzhiyun	  fi
4809*4882a593Smuzhiyun
4810*4882a593Smuzhiyun	  echo >> "$output_objdir/$my_dlsyms" "\
4811*4882a593Smuzhiyun
4812*4882a593Smuzhiyun/* The mapping between symbol names and symbols.  */
4813*4882a593Smuzhiyuntypedef struct {
4814*4882a593Smuzhiyun  const char *name;
4815*4882a593Smuzhiyun  void *address;
4816*4882a593Smuzhiyun} lt_dlsymlist;
4817*4882a593Smuzhiyunextern LT_DLSYM_CONST lt_dlsymlist
4818*4882a593Smuzhiyunlt_${my_prefix}_LTX_preloaded_symbols[];\
4819*4882a593Smuzhiyun"
4820*4882a593Smuzhiyun
4821*4882a593Smuzhiyun	  if test -s "$nlist"I; then
4822*4882a593Smuzhiyun	    echo >> "$output_objdir/$my_dlsyms" "\
4823*4882a593Smuzhiyunstatic void lt_syminit(void)
4824*4882a593Smuzhiyun{
4825*4882a593Smuzhiyun  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
4826*4882a593Smuzhiyun  for (; symbol->name; ++symbol)
4827*4882a593Smuzhiyun    {"
4828*4882a593Smuzhiyun	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
4829*4882a593Smuzhiyun	    echo >> "$output_objdir/$my_dlsyms" "\
4830*4882a593Smuzhiyun    }
4831*4882a593Smuzhiyun}"
4832*4882a593Smuzhiyun	  fi
4833*4882a593Smuzhiyun	  echo >> "$output_objdir/$my_dlsyms" "\
4834*4882a593SmuzhiyunLT_DLSYM_CONST lt_dlsymlist
4835*4882a593Smuzhiyunlt_${my_prefix}_LTX_preloaded_symbols[] =
4836*4882a593Smuzhiyun{ {\"$my_originator\", (void *) 0},"
4837*4882a593Smuzhiyun
4838*4882a593Smuzhiyun	  if test -s "$nlist"I; then
4839*4882a593Smuzhiyun	    echo >> "$output_objdir/$my_dlsyms" "\
4840*4882a593Smuzhiyun  {\"@INIT@\", (void *) &lt_syminit},"
4841*4882a593Smuzhiyun	  fi
4842*4882a593Smuzhiyun
4843*4882a593Smuzhiyun	  case $need_lib_prefix in
4844*4882a593Smuzhiyun	  no)
4845*4882a593Smuzhiyun	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
4846*4882a593Smuzhiyun	    ;;
4847*4882a593Smuzhiyun	  *)
4848*4882a593Smuzhiyun	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
4849*4882a593Smuzhiyun	    ;;
4850*4882a593Smuzhiyun	  esac
4851*4882a593Smuzhiyun	  echo >> "$output_objdir/$my_dlsyms" "\
4852*4882a593Smuzhiyun  {0, (void *) 0}
4853*4882a593Smuzhiyun};
4854*4882a593Smuzhiyun
4855*4882a593Smuzhiyun/* This works around a problem in FreeBSD linker */
4856*4882a593Smuzhiyun#ifdef FREEBSD_WORKAROUND
4857*4882a593Smuzhiyunstatic const void *lt_preloaded_setup() {
4858*4882a593Smuzhiyun  return lt_${my_prefix}_LTX_preloaded_symbols;
4859*4882a593Smuzhiyun}
4860*4882a593Smuzhiyun#endif
4861*4882a593Smuzhiyun
4862*4882a593Smuzhiyun#ifdef __cplusplus
4863*4882a593Smuzhiyun}
4864*4882a593Smuzhiyun#endif\
4865*4882a593Smuzhiyun"
4866*4882a593Smuzhiyun	} # !$opt_dry_run
4867*4882a593Smuzhiyun
4868*4882a593Smuzhiyun	pic_flag_for_symtable=
4869*4882a593Smuzhiyun	case "$compile_command " in
4870*4882a593Smuzhiyun	*" -static "*) ;;
4871*4882a593Smuzhiyun	*)
4872*4882a593Smuzhiyun	  case $host in
4873*4882a593Smuzhiyun	  # compiling the symbol table file with pic_flag works around
4874*4882a593Smuzhiyun	  # a FreeBSD bug that causes programs to crash when -lm is
4875*4882a593Smuzhiyun	  # linked before any other PIC object.  But we must not use
4876*4882a593Smuzhiyun	  # pic_flag when linking with -static.  The problem exists in
4877*4882a593Smuzhiyun	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
4878*4882a593Smuzhiyun	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
4879*4882a593Smuzhiyun	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
4880*4882a593Smuzhiyun	  *-*-hpux*)
4881*4882a593Smuzhiyun	    pic_flag_for_symtable=" $pic_flag"  ;;
4882*4882a593Smuzhiyun	  *)
4883*4882a593Smuzhiyun	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
4884*4882a593Smuzhiyun	    ;;
4885*4882a593Smuzhiyun	  esac
4886*4882a593Smuzhiyun	  ;;
4887*4882a593Smuzhiyun	esac
4888*4882a593Smuzhiyun	symtab_cflags=
4889*4882a593Smuzhiyun	for arg in $LTCFLAGS; do
4890*4882a593Smuzhiyun	  case $arg in
4891*4882a593Smuzhiyun	  -pie | -fpie | -fPIE) ;;
4892*4882a593Smuzhiyun	  *) func_append symtab_cflags " $arg" ;;
4893*4882a593Smuzhiyun	  esac
4894*4882a593Smuzhiyun	done
4895*4882a593Smuzhiyun
4896*4882a593Smuzhiyun	# Now compile the dynamic symbol file.
4897*4882a593Smuzhiyun	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
4898*4882a593Smuzhiyun
4899*4882a593Smuzhiyun	# Clean up the generated files.
4900*4882a593Smuzhiyun	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
4901*4882a593Smuzhiyun
4902*4882a593Smuzhiyun	# Transform the symbol file into the correct name.
4903*4882a593Smuzhiyun	symfileobj=$output_objdir/${my_outputname}S.$objext
4904*4882a593Smuzhiyun	case $host in
4905*4882a593Smuzhiyun	*cygwin* | *mingw* | *cegcc* )
4906*4882a593Smuzhiyun	  if test -f "$output_objdir/$my_outputname.def"; then
4907*4882a593Smuzhiyun	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
4908*4882a593Smuzhiyun	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
4909*4882a593Smuzhiyun	  else
4910*4882a593Smuzhiyun	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4911*4882a593Smuzhiyun	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4912*4882a593Smuzhiyun	  fi
4913*4882a593Smuzhiyun	  ;;
4914*4882a593Smuzhiyun	*)
4915*4882a593Smuzhiyun	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4916*4882a593Smuzhiyun	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4917*4882a593Smuzhiyun	  ;;
4918*4882a593Smuzhiyun	esac
4919*4882a593Smuzhiyun	;;
4920*4882a593Smuzhiyun      *)
4921*4882a593Smuzhiyun	func_fatal_error "unknown suffix for '$my_dlsyms'"
4922*4882a593Smuzhiyun	;;
4923*4882a593Smuzhiyun      esac
4924*4882a593Smuzhiyun    else
4925*4882a593Smuzhiyun      # We keep going just in case the user didn't refer to
4926*4882a593Smuzhiyun      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
4927*4882a593Smuzhiyun      # really was required.
4928*4882a593Smuzhiyun
4929*4882a593Smuzhiyun      # Nullify the symbol file.
4930*4882a593Smuzhiyun      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
4931*4882a593Smuzhiyun      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
4932*4882a593Smuzhiyun    fi
4933*4882a593Smuzhiyun}
4934*4882a593Smuzhiyun
4935*4882a593Smuzhiyun# func_cygming_gnu_implib_p ARG
4936*4882a593Smuzhiyun# This predicate returns with zero status (TRUE) if
4937*4882a593Smuzhiyun# ARG is a GNU/binutils-style import library. Returns
4938*4882a593Smuzhiyun# with nonzero status (FALSE) otherwise.
4939*4882a593Smuzhiyunfunc_cygming_gnu_implib_p ()
4940*4882a593Smuzhiyun{
4941*4882a593Smuzhiyun  $debug_cmd
4942*4882a593Smuzhiyun
4943*4882a593Smuzhiyun  func_to_tool_file "$1" func_convert_file_msys_to_w32
4944*4882a593Smuzhiyun  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)$'`
4945*4882a593Smuzhiyun  test -n "$func_cygming_gnu_implib_tmp"
4946*4882a593Smuzhiyun}
4947*4882a593Smuzhiyun
4948*4882a593Smuzhiyun# func_cygming_ms_implib_p ARG
4949*4882a593Smuzhiyun# This predicate returns with zero status (TRUE) if
4950*4882a593Smuzhiyun# ARG is an MS-style import library. Returns
4951*4882a593Smuzhiyun# with nonzero status (FALSE) otherwise.
4952*4882a593Smuzhiyunfunc_cygming_ms_implib_p ()
4953*4882a593Smuzhiyun{
4954*4882a593Smuzhiyun  $debug_cmd
4955*4882a593Smuzhiyun
4956*4882a593Smuzhiyun  func_to_tool_file "$1" func_convert_file_msys_to_w32
4957*4882a593Smuzhiyun  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
4958*4882a593Smuzhiyun  test -n "$func_cygming_ms_implib_tmp"
4959*4882a593Smuzhiyun}
4960*4882a593Smuzhiyun
4961*4882a593Smuzhiyun# func_win32_libid arg
4962*4882a593Smuzhiyun# return the library type of file 'arg'
4963*4882a593Smuzhiyun#
4964*4882a593Smuzhiyun# Need a lot of goo to handle *both* DLLs and import libs
4965*4882a593Smuzhiyun# Has to be a shell function in order to 'eat' the argument
4966*4882a593Smuzhiyun# that is supplied when $file_magic_command is called.
4967*4882a593Smuzhiyun# Despite the name, also deal with 64 bit binaries.
4968*4882a593Smuzhiyunfunc_win32_libid ()
4969*4882a593Smuzhiyun{
4970*4882a593Smuzhiyun  $debug_cmd
4971*4882a593Smuzhiyun
4972*4882a593Smuzhiyun  win32_libid_type=unknown
4973*4882a593Smuzhiyun  win32_fileres=`file -L $1 2>/dev/null`
4974*4882a593Smuzhiyun  case $win32_fileres in
4975*4882a593Smuzhiyun  *ar\ archive\ import\ library*) # definitely import
4976*4882a593Smuzhiyun    win32_libid_type="x86 archive import"
4977*4882a593Smuzhiyun    ;;
4978*4882a593Smuzhiyun  *ar\ archive*) # could be an import, or static
4979*4882a593Smuzhiyun    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
4980*4882a593Smuzhiyun    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
4981*4882a593Smuzhiyun       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
4982*4882a593Smuzhiyun      case $nm_interface in
4983*4882a593Smuzhiyun      "MS dumpbin")
4984*4882a593Smuzhiyun	if func_cygming_ms_implib_p "$1" ||
4985*4882a593Smuzhiyun	   func_cygming_gnu_implib_p "$1"
4986*4882a593Smuzhiyun	then
4987*4882a593Smuzhiyun	  win32_nmres=import
4988*4882a593Smuzhiyun	else
4989*4882a593Smuzhiyun	  win32_nmres=
4990*4882a593Smuzhiyun	fi
4991*4882a593Smuzhiyun	;;
4992*4882a593Smuzhiyun      *)
4993*4882a593Smuzhiyun	func_to_tool_file "$1" func_convert_file_msys_to_w32
4994*4882a593Smuzhiyun	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
4995*4882a593Smuzhiyun	  $SED -n -e '
4996*4882a593Smuzhiyun	    1,100{
4997*4882a593Smuzhiyun		/ I /{
4998*4882a593Smuzhiyun		    s|.*|import|
4999*4882a593Smuzhiyun		    p
5000*4882a593Smuzhiyun		    q
5001*4882a593Smuzhiyun		}
5002*4882a593Smuzhiyun	    }'`
5003*4882a593Smuzhiyun	;;
5004*4882a593Smuzhiyun      esac
5005*4882a593Smuzhiyun      case $win32_nmres in
5006*4882a593Smuzhiyun      import*)  win32_libid_type="x86 archive import";;
5007*4882a593Smuzhiyun      *)        win32_libid_type="x86 archive static";;
5008*4882a593Smuzhiyun      esac
5009*4882a593Smuzhiyun    fi
5010*4882a593Smuzhiyun    ;;
5011*4882a593Smuzhiyun  *DLL*)
5012*4882a593Smuzhiyun    win32_libid_type="x86 DLL"
5013*4882a593Smuzhiyun    ;;
5014*4882a593Smuzhiyun  *executable*) # but shell scripts are "executable" too...
5015*4882a593Smuzhiyun    case $win32_fileres in
5016*4882a593Smuzhiyun    *MS\ Windows\ PE\ Intel*)
5017*4882a593Smuzhiyun      win32_libid_type="x86 DLL"
5018*4882a593Smuzhiyun      ;;
5019*4882a593Smuzhiyun    esac
5020*4882a593Smuzhiyun    ;;
5021*4882a593Smuzhiyun  esac
5022*4882a593Smuzhiyun  $ECHO "$win32_libid_type"
5023*4882a593Smuzhiyun}
5024*4882a593Smuzhiyun
5025*4882a593Smuzhiyun# func_cygming_dll_for_implib ARG
5026*4882a593Smuzhiyun#
5027*4882a593Smuzhiyun# Platform-specific function to extract the
5028*4882a593Smuzhiyun# name of the DLL associated with the specified
5029*4882a593Smuzhiyun# import library ARG.
5030*4882a593Smuzhiyun# Invoked by eval'ing the libtool variable
5031*4882a593Smuzhiyun#    $sharedlib_from_linklib_cmd
5032*4882a593Smuzhiyun# Result is available in the variable
5033*4882a593Smuzhiyun#    $sharedlib_from_linklib_result
5034*4882a593Smuzhiyunfunc_cygming_dll_for_implib ()
5035*4882a593Smuzhiyun{
5036*4882a593Smuzhiyun  $debug_cmd
5037*4882a593Smuzhiyun
5038*4882a593Smuzhiyun  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5039*4882a593Smuzhiyun}
5040*4882a593Smuzhiyun
5041*4882a593Smuzhiyun# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5042*4882a593Smuzhiyun#
5043*4882a593Smuzhiyun# The is the core of a fallback implementation of a
5044*4882a593Smuzhiyun# platform-specific function to extract the name of the
5045*4882a593Smuzhiyun# DLL associated with the specified import library LIBNAME.
5046*4882a593Smuzhiyun#
5047*4882a593Smuzhiyun# SECTION_NAME is either .idata$6 or .idata$7, depending
5048*4882a593Smuzhiyun# on the platform and compiler that created the implib.
5049*4882a593Smuzhiyun#
5050*4882a593Smuzhiyun# Echos the name of the DLL associated with the
5051*4882a593Smuzhiyun# specified import library.
5052*4882a593Smuzhiyunfunc_cygming_dll_for_implib_fallback_core ()
5053*4882a593Smuzhiyun{
5054*4882a593Smuzhiyun  $debug_cmd
5055*4882a593Smuzhiyun
5056*4882a593Smuzhiyun  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5057*4882a593Smuzhiyun  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5058*4882a593Smuzhiyun    $SED '/^Contents of section '"$match_literal"':/{
5059*4882a593Smuzhiyun      # Place marker at beginning of archive member dllname section
5060*4882a593Smuzhiyun      s/.*/====MARK====/
5061*4882a593Smuzhiyun      p
5062*4882a593Smuzhiyun      d
5063*4882a593Smuzhiyun    }
5064*4882a593Smuzhiyun    # These lines can sometimes be longer than 43 characters, but
5065*4882a593Smuzhiyun    # are always uninteresting
5066*4882a593Smuzhiyun    /:[	 ]*file format pe[i]\{,1\}-/d
5067*4882a593Smuzhiyun    /^In archive [^:]*:/d
5068*4882a593Smuzhiyun    # Ensure marker is printed
5069*4882a593Smuzhiyun    /^====MARK====/p
5070*4882a593Smuzhiyun    # Remove all lines with less than 43 characters
5071*4882a593Smuzhiyun    /^.\{43\}/!d
5072*4882a593Smuzhiyun    # From remaining lines, remove first 43 characters
5073*4882a593Smuzhiyun    s/^.\{43\}//' |
5074*4882a593Smuzhiyun    $SED -n '
5075*4882a593Smuzhiyun      # Join marker and all lines until next marker into a single line
5076*4882a593Smuzhiyun      /^====MARK====/ b para
5077*4882a593Smuzhiyun      H
5078*4882a593Smuzhiyun      $ b para
5079*4882a593Smuzhiyun      b
5080*4882a593Smuzhiyun      :para
5081*4882a593Smuzhiyun      x
5082*4882a593Smuzhiyun      s/\n//g
5083*4882a593Smuzhiyun      # Remove the marker
5084*4882a593Smuzhiyun      s/^====MARK====//
5085*4882a593Smuzhiyun      # Remove trailing dots and whitespace
5086*4882a593Smuzhiyun      s/[\. \t]*$//
5087*4882a593Smuzhiyun      # Print
5088*4882a593Smuzhiyun      /./p' |
5089*4882a593Smuzhiyun    # we now have a list, one entry per line, of the stringified
5090*4882a593Smuzhiyun    # contents of the appropriate section of all members of the
5091*4882a593Smuzhiyun    # archive that possess that section. Heuristic: eliminate
5092*4882a593Smuzhiyun    # all those that have a first or second character that is
5093*4882a593Smuzhiyun    # a '.' (that is, objdump's representation of an unprintable
5094*4882a593Smuzhiyun    # character.) This should work for all archives with less than
5095*4882a593Smuzhiyun    # 0x302f exports -- but will fail for DLLs whose name actually
5096*4882a593Smuzhiyun    # begins with a literal '.' or a single character followed by
5097*4882a593Smuzhiyun    # a '.'.
5098*4882a593Smuzhiyun    #
5099*4882a593Smuzhiyun    # Of those that remain, print the first one.
5100*4882a593Smuzhiyun    $SED -e '/^\./d;/^.\./d;q'
5101*4882a593Smuzhiyun}
5102*4882a593Smuzhiyun
5103*4882a593Smuzhiyun# func_cygming_dll_for_implib_fallback ARG
5104*4882a593Smuzhiyun# Platform-specific function to extract the
5105*4882a593Smuzhiyun# name of the DLL associated with the specified
5106*4882a593Smuzhiyun# import library ARG.
5107*4882a593Smuzhiyun#
5108*4882a593Smuzhiyun# This fallback implementation is for use when $DLLTOOL
5109*4882a593Smuzhiyun# does not support the --identify-strict option.
5110*4882a593Smuzhiyun# Invoked by eval'ing the libtool variable
5111*4882a593Smuzhiyun#    $sharedlib_from_linklib_cmd
5112*4882a593Smuzhiyun# Result is available in the variable
5113*4882a593Smuzhiyun#    $sharedlib_from_linklib_result
5114*4882a593Smuzhiyunfunc_cygming_dll_for_implib_fallback ()
5115*4882a593Smuzhiyun{
5116*4882a593Smuzhiyun  $debug_cmd
5117*4882a593Smuzhiyun
5118*4882a593Smuzhiyun  if func_cygming_gnu_implib_p "$1"; then
5119*4882a593Smuzhiyun    # binutils import library
5120*4882a593Smuzhiyun    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5121*4882a593Smuzhiyun  elif func_cygming_ms_implib_p "$1"; then
5122*4882a593Smuzhiyun    # ms-generated import library
5123*4882a593Smuzhiyun    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5124*4882a593Smuzhiyun  else
5125*4882a593Smuzhiyun    # unknown
5126*4882a593Smuzhiyun    sharedlib_from_linklib_result=
5127*4882a593Smuzhiyun  fi
5128*4882a593Smuzhiyun}
5129*4882a593Smuzhiyun
5130*4882a593Smuzhiyun
5131*4882a593Smuzhiyun# func_extract_an_archive dir oldlib
5132*4882a593Smuzhiyunfunc_extract_an_archive ()
5133*4882a593Smuzhiyun{
5134*4882a593Smuzhiyun    $debug_cmd
5135*4882a593Smuzhiyun
5136*4882a593Smuzhiyun    f_ex_an_ar_dir=$1; shift
5137*4882a593Smuzhiyun    f_ex_an_ar_oldlib=$1
5138*4882a593Smuzhiyun    if test yes = "$lock_old_archive_extraction"; then
5139*4882a593Smuzhiyun      lockfile=$f_ex_an_ar_oldlib.lock
5140*4882a593Smuzhiyun      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5141*4882a593Smuzhiyun	func_echo "Waiting for $lockfile to be removed"
5142*4882a593Smuzhiyun	sleep 2
5143*4882a593Smuzhiyun      done
5144*4882a593Smuzhiyun    fi
5145*4882a593Smuzhiyun    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5146*4882a593Smuzhiyun		   'stat=$?; rm -f "$lockfile"; exit $stat'
5147*4882a593Smuzhiyun    if test yes = "$lock_old_archive_extraction"; then
5148*4882a593Smuzhiyun      $opt_dry_run || rm -f "$lockfile"
5149*4882a593Smuzhiyun    fi
5150*4882a593Smuzhiyun    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5151*4882a593Smuzhiyun     :
5152*4882a593Smuzhiyun    else
5153*4882a593Smuzhiyun      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5154*4882a593Smuzhiyun    fi
5155*4882a593Smuzhiyun}
5156*4882a593Smuzhiyun
5157*4882a593Smuzhiyun
5158*4882a593Smuzhiyun# func_extract_archives gentop oldlib ...
5159*4882a593Smuzhiyunfunc_extract_archives ()
5160*4882a593Smuzhiyun{
5161*4882a593Smuzhiyun    $debug_cmd
5162*4882a593Smuzhiyun
5163*4882a593Smuzhiyun    my_gentop=$1; shift
5164*4882a593Smuzhiyun    my_oldlibs=${1+"$@"}
5165*4882a593Smuzhiyun    my_oldobjs=
5166*4882a593Smuzhiyun    my_xlib=
5167*4882a593Smuzhiyun    my_xabs=
5168*4882a593Smuzhiyun    my_xdir=
5169*4882a593Smuzhiyun
5170*4882a593Smuzhiyun    for my_xlib in $my_oldlibs; do
5171*4882a593Smuzhiyun      # Extract the objects.
5172*4882a593Smuzhiyun      case $my_xlib in
5173*4882a593Smuzhiyun	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5174*4882a593Smuzhiyun	*) my_xabs=`pwd`"/$my_xlib" ;;
5175*4882a593Smuzhiyun      esac
5176*4882a593Smuzhiyun      func_basename "$my_xlib"
5177*4882a593Smuzhiyun      my_xlib=$func_basename_result
5178*4882a593Smuzhiyun      my_xlib_u=$my_xlib
5179*4882a593Smuzhiyun      while :; do
5180*4882a593Smuzhiyun        case " $extracted_archives " in
5181*4882a593Smuzhiyun	*" $my_xlib_u "*)
5182*4882a593Smuzhiyun	  func_arith $extracted_serial + 1
5183*4882a593Smuzhiyun	  extracted_serial=$func_arith_result
5184*4882a593Smuzhiyun	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5185*4882a593Smuzhiyun	*) break ;;
5186*4882a593Smuzhiyun	esac
5187*4882a593Smuzhiyun      done
5188*4882a593Smuzhiyun      extracted_archives="$extracted_archives $my_xlib_u"
5189*4882a593Smuzhiyun      my_xdir=$my_gentop/$my_xlib_u
5190*4882a593Smuzhiyun
5191*4882a593Smuzhiyun      func_mkdir_p "$my_xdir"
5192*4882a593Smuzhiyun
5193*4882a593Smuzhiyun      case $host in
5194*4882a593Smuzhiyun      *-darwin*)
5195*4882a593Smuzhiyun	func_verbose "Extracting $my_xabs"
5196*4882a593Smuzhiyun	# Do not bother doing anything if just a dry run
5197*4882a593Smuzhiyun	$opt_dry_run || {
5198*4882a593Smuzhiyun	  darwin_orig_dir=`pwd`
5199*4882a593Smuzhiyun	  cd $my_xdir || exit $?
5200*4882a593Smuzhiyun	  darwin_archive=$my_xabs
5201*4882a593Smuzhiyun	  darwin_curdir=`pwd`
5202*4882a593Smuzhiyun	  func_basename "$darwin_archive"
5203*4882a593Smuzhiyun	  darwin_base_archive=$func_basename_result
5204*4882a593Smuzhiyun	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5205*4882a593Smuzhiyun	  if test -n "$darwin_arches"; then
5206*4882a593Smuzhiyun	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5207*4882a593Smuzhiyun	    darwin_arch=
5208*4882a593Smuzhiyun	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5209*4882a593Smuzhiyun	    for darwin_arch in  $darwin_arches; do
5210*4882a593Smuzhiyun	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5211*4882a593Smuzhiyun	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5212*4882a593Smuzhiyun	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5213*4882a593Smuzhiyun	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5214*4882a593Smuzhiyun	      cd "$darwin_curdir"
5215*4882a593Smuzhiyun	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5216*4882a593Smuzhiyun	    done # $darwin_arches
5217*4882a593Smuzhiyun            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5218*4882a593Smuzhiyun	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5219*4882a593Smuzhiyun	    darwin_file=
5220*4882a593Smuzhiyun	    darwin_files=
5221*4882a593Smuzhiyun	    for darwin_file in $darwin_filelist; do
5222*4882a593Smuzhiyun	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5223*4882a593Smuzhiyun	      $LIPO -create -output "$darwin_file" $darwin_files
5224*4882a593Smuzhiyun	    done # $darwin_filelist
5225*4882a593Smuzhiyun	    $RM -rf unfat-$$
5226*4882a593Smuzhiyun	    cd "$darwin_orig_dir"
5227*4882a593Smuzhiyun	  else
5228*4882a593Smuzhiyun	    cd $darwin_orig_dir
5229*4882a593Smuzhiyun	    func_extract_an_archive "$my_xdir" "$my_xabs"
5230*4882a593Smuzhiyun	  fi # $darwin_arches
5231*4882a593Smuzhiyun	} # !$opt_dry_run
5232*4882a593Smuzhiyun	;;
5233*4882a593Smuzhiyun      *)
5234*4882a593Smuzhiyun        func_extract_an_archive "$my_xdir" "$my_xabs"
5235*4882a593Smuzhiyun	;;
5236*4882a593Smuzhiyun      esac
5237*4882a593Smuzhiyun      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5238*4882a593Smuzhiyun    done
5239*4882a593Smuzhiyun
5240*4882a593Smuzhiyun    func_extract_archives_result=$my_oldobjs
5241*4882a593Smuzhiyun}
5242*4882a593Smuzhiyun
5243*4882a593Smuzhiyun
5244*4882a593Smuzhiyun# func_emit_wrapper [arg=no]
5245*4882a593Smuzhiyun#
5246*4882a593Smuzhiyun# Emit a libtool wrapper script on stdout.
5247*4882a593Smuzhiyun# Don't directly open a file because we may want to
5248*4882a593Smuzhiyun# incorporate the script contents within a cygwin/mingw
5249*4882a593Smuzhiyun# wrapper executable.  Must ONLY be called from within
5250*4882a593Smuzhiyun# func_mode_link because it depends on a number of variables
5251*4882a593Smuzhiyun# set therein.
5252*4882a593Smuzhiyun#
5253*4882a593Smuzhiyun# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5254*4882a593Smuzhiyun# variable will take.  If 'yes', then the emitted script
5255*4882a593Smuzhiyun# will assume that the directory where it is stored is
5256*4882a593Smuzhiyun# the $objdir directory.  This is a cygwin/mingw-specific
5257*4882a593Smuzhiyun# behavior.
5258*4882a593Smuzhiyunfunc_emit_wrapper ()
5259*4882a593Smuzhiyun{
5260*4882a593Smuzhiyun	func_emit_wrapper_arg1=${1-no}
5261*4882a593Smuzhiyun
5262*4882a593Smuzhiyun	$ECHO "\
5263*4882a593Smuzhiyun#! $SHELL
5264*4882a593Smuzhiyun
5265*4882a593Smuzhiyun# $output - temporary wrapper script for $objdir/$outputname
5266*4882a593Smuzhiyun# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5267*4882a593Smuzhiyun#
5268*4882a593Smuzhiyun# The $output program cannot be directly executed until all the libtool
5269*4882a593Smuzhiyun# libraries that it depends on are installed.
5270*4882a593Smuzhiyun#
5271*4882a593Smuzhiyun# This wrapper script should never be moved out of the build directory.
5272*4882a593Smuzhiyun# If it is, it will not operate correctly.
5273*4882a593Smuzhiyun
5274*4882a593Smuzhiyun# Sed substitution that helps us do robust quoting.  It backslashifies
5275*4882a593Smuzhiyun# metacharacters that are still active within double-quoted strings.
5276*4882a593Smuzhiyunsed_quote_subst='$sed_quote_subst'
5277*4882a593Smuzhiyun
5278*4882a593Smuzhiyun# Be Bourne compatible
5279*4882a593Smuzhiyunif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5280*4882a593Smuzhiyun  emulate sh
5281*4882a593Smuzhiyun  NULLCMD=:
5282*4882a593Smuzhiyun  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5283*4882a593Smuzhiyun  # is contrary to our usage.  Disable this feature.
5284*4882a593Smuzhiyun  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5285*4882a593Smuzhiyun  setopt NO_GLOB_SUBST
5286*4882a593Smuzhiyunelse
5287*4882a593Smuzhiyun  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5288*4882a593Smuzhiyunfi
5289*4882a593SmuzhiyunBIN_SH=xpg4; export BIN_SH # for Tru64
5290*4882a593SmuzhiyunDUALCASE=1; export DUALCASE # for MKS sh
5291*4882a593Smuzhiyun
5292*4882a593Smuzhiyun# The HP-UX ksh and POSIX shell print the target directory to stdout
5293*4882a593Smuzhiyun# if CDPATH is set.
5294*4882a593Smuzhiyun(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5295*4882a593Smuzhiyun
5296*4882a593Smuzhiyunrelink_command=\"$relink_command\"
5297*4882a593Smuzhiyun
5298*4882a593Smuzhiyun# This environment variable determines our operation mode.
5299*4882a593Smuzhiyunif test \"\$libtool_install_magic\" = \"$magic\"; then
5300*4882a593Smuzhiyun  # install mode needs the following variables:
5301*4882a593Smuzhiyun  generated_by_libtool_version='$macro_version'
5302*4882a593Smuzhiyun  notinst_deplibs='$notinst_deplibs'
5303*4882a593Smuzhiyunelse
5304*4882a593Smuzhiyun  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5305*4882a593Smuzhiyun  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5306*4882a593Smuzhiyun    file=\"\$0\""
5307*4882a593Smuzhiyun
5308*4882a593Smuzhiyun    func_quote "$ECHO"
5309*4882a593Smuzhiyun    qECHO=$func_quote_result
5310*4882a593Smuzhiyun    $ECHO "\
5311*4882a593Smuzhiyun
5312*4882a593Smuzhiyun# A function that is used when there is no print builtin or printf.
5313*4882a593Smuzhiyunfunc_fallback_echo ()
5314*4882a593Smuzhiyun{
5315*4882a593Smuzhiyun  eval 'cat <<_LTECHO_EOF
5316*4882a593Smuzhiyun\$1
5317*4882a593Smuzhiyun_LTECHO_EOF'
5318*4882a593Smuzhiyun}
5319*4882a593Smuzhiyun    ECHO=\"$qECHO\"
5320*4882a593Smuzhiyun  fi
5321*4882a593Smuzhiyun
5322*4882a593Smuzhiyun# Very basic option parsing. These options are (a) specific to
5323*4882a593Smuzhiyun# the libtool wrapper, (b) are identical between the wrapper
5324*4882a593Smuzhiyun# /script/ and the wrapper /executable/ that is used only on
5325*4882a593Smuzhiyun# windows platforms, and (c) all begin with the string "--lt-"
5326*4882a593Smuzhiyun# (application programs are unlikely to have options that match
5327*4882a593Smuzhiyun# this pattern).
5328*4882a593Smuzhiyun#
5329*4882a593Smuzhiyun# There are only two supported options: --lt-debug and
5330*4882a593Smuzhiyun# --lt-dump-script. There is, deliberately, no --lt-help.
5331*4882a593Smuzhiyun#
5332*4882a593Smuzhiyun# The first argument to this parsing function should be the
5333*4882a593Smuzhiyun# script's $0 value, followed by "$@".
5334*4882a593Smuzhiyunlt_option_debug=
5335*4882a593Smuzhiyunfunc_parse_lt_options ()
5336*4882a593Smuzhiyun{
5337*4882a593Smuzhiyun  lt_script_arg0=\$0
5338*4882a593Smuzhiyun  shift
5339*4882a593Smuzhiyun  for lt_opt
5340*4882a593Smuzhiyun  do
5341*4882a593Smuzhiyun    case \"\$lt_opt\" in
5342*4882a593Smuzhiyun    --lt-debug) lt_option_debug=1 ;;
5343*4882a593Smuzhiyun    --lt-dump-script)
5344*4882a593Smuzhiyun        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5345*4882a593Smuzhiyun        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5346*4882a593Smuzhiyun        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5347*4882a593Smuzhiyun        cat \"\$lt_dump_D/\$lt_dump_F\"
5348*4882a593Smuzhiyun        exit 0
5349*4882a593Smuzhiyun      ;;
5350*4882a593Smuzhiyun    --lt-*)
5351*4882a593Smuzhiyun        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5352*4882a593Smuzhiyun        exit 1
5353*4882a593Smuzhiyun      ;;
5354*4882a593Smuzhiyun    esac
5355*4882a593Smuzhiyun  done
5356*4882a593Smuzhiyun
5357*4882a593Smuzhiyun  # Print the debug banner immediately:
5358*4882a593Smuzhiyun  if test -n \"\$lt_option_debug\"; then
5359*4882a593Smuzhiyun    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5360*4882a593Smuzhiyun  fi
5361*4882a593Smuzhiyun}
5362*4882a593Smuzhiyun
5363*4882a593Smuzhiyun# Used when --lt-debug. Prints its arguments to stdout
5364*4882a593Smuzhiyun# (redirection is the responsibility of the caller)
5365*4882a593Smuzhiyunfunc_lt_dump_args ()
5366*4882a593Smuzhiyun{
5367*4882a593Smuzhiyun  lt_dump_args_N=1;
5368*4882a593Smuzhiyun  for lt_arg
5369*4882a593Smuzhiyun  do
5370*4882a593Smuzhiyun    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5371*4882a593Smuzhiyun    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5372*4882a593Smuzhiyun  done
5373*4882a593Smuzhiyun}
5374*4882a593Smuzhiyun
5375*4882a593Smuzhiyun# Core function for launching the target application
5376*4882a593Smuzhiyunfunc_exec_program_core ()
5377*4882a593Smuzhiyun{
5378*4882a593Smuzhiyun"
5379*4882a593Smuzhiyun  case $host in
5380*4882a593Smuzhiyun  # Backslashes separate directories on plain windows
5381*4882a593Smuzhiyun  *-*-mingw | *-*-os2* | *-cegcc*)
5382*4882a593Smuzhiyun    $ECHO "\
5383*4882a593Smuzhiyun      if test -n \"\$lt_option_debug\"; then
5384*4882a593Smuzhiyun        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5385*4882a593Smuzhiyun        func_lt_dump_args \${1+\"\$@\"} 1>&2
5386*4882a593Smuzhiyun      fi
5387*4882a593Smuzhiyun      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5388*4882a593Smuzhiyun"
5389*4882a593Smuzhiyun    ;;
5390*4882a593Smuzhiyun
5391*4882a593Smuzhiyun  *)
5392*4882a593Smuzhiyun    $ECHO "\
5393*4882a593Smuzhiyun      if test -n \"\$lt_option_debug\"; then
5394*4882a593Smuzhiyun        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5395*4882a593Smuzhiyun        func_lt_dump_args \${1+\"\$@\"} 1>&2
5396*4882a593Smuzhiyun      fi
5397*4882a593Smuzhiyun      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5398*4882a593Smuzhiyun"
5399*4882a593Smuzhiyun    ;;
5400*4882a593Smuzhiyun  esac
5401*4882a593Smuzhiyun  $ECHO "\
5402*4882a593Smuzhiyun      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5403*4882a593Smuzhiyun      exit 1
5404*4882a593Smuzhiyun}
5405*4882a593Smuzhiyun
5406*4882a593Smuzhiyun# A function to encapsulate launching the target application
5407*4882a593Smuzhiyun# Strips options in the --lt-* namespace from \$@ and
5408*4882a593Smuzhiyun# launches target application with the remaining arguments.
5409*4882a593Smuzhiyunfunc_exec_program ()
5410*4882a593Smuzhiyun{
5411*4882a593Smuzhiyun  case \" \$* \" in
5412*4882a593Smuzhiyun  *\\ --lt-*)
5413*4882a593Smuzhiyun    for lt_wr_arg
5414*4882a593Smuzhiyun    do
5415*4882a593Smuzhiyun      case \$lt_wr_arg in
5416*4882a593Smuzhiyun      --lt-*) ;;
5417*4882a593Smuzhiyun      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5418*4882a593Smuzhiyun      esac
5419*4882a593Smuzhiyun      shift
5420*4882a593Smuzhiyun    done ;;
5421*4882a593Smuzhiyun  esac
5422*4882a593Smuzhiyun  func_exec_program_core \${1+\"\$@\"}
5423*4882a593Smuzhiyun}
5424*4882a593Smuzhiyun
5425*4882a593Smuzhiyun  # Parse options
5426*4882a593Smuzhiyun  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5427*4882a593Smuzhiyun
5428*4882a593Smuzhiyun  # Find the directory that this script lives in.
5429*4882a593Smuzhiyun  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5430*4882a593Smuzhiyun  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5431*4882a593Smuzhiyun
5432*4882a593Smuzhiyun  # Follow symbolic links until we get to the real thisdir.
5433*4882a593Smuzhiyun  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5434*4882a593Smuzhiyun  while test -n \"\$file\"; do
5435*4882a593Smuzhiyun    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5436*4882a593Smuzhiyun
5437*4882a593Smuzhiyun    # If there was a directory component, then change thisdir.
5438*4882a593Smuzhiyun    if test \"x\$destdir\" != \"x\$file\"; then
5439*4882a593Smuzhiyun      case \"\$destdir\" in
5440*4882a593Smuzhiyun      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5441*4882a593Smuzhiyun      *) thisdir=\"\$thisdir/\$destdir\" ;;
5442*4882a593Smuzhiyun      esac
5443*4882a593Smuzhiyun    fi
5444*4882a593Smuzhiyun
5445*4882a593Smuzhiyun    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5446*4882a593Smuzhiyun    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5447*4882a593Smuzhiyun  done
5448*4882a593Smuzhiyun
5449*4882a593Smuzhiyun  # Usually 'no', except on cygwin/mingw when embedded into
5450*4882a593Smuzhiyun  # the cwrapper.
5451*4882a593Smuzhiyun  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5452*4882a593Smuzhiyun  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5453*4882a593Smuzhiyun    # special case for '.'
5454*4882a593Smuzhiyun    if test \"\$thisdir\" = \".\"; then
5455*4882a593Smuzhiyun      thisdir=\`pwd\`
5456*4882a593Smuzhiyun    fi
5457*4882a593Smuzhiyun    # remove .libs from thisdir
5458*4882a593Smuzhiyun    case \"\$thisdir\" in
5459*4882a593Smuzhiyun    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5460*4882a593Smuzhiyun    $objdir )   thisdir=. ;;
5461*4882a593Smuzhiyun    esac
5462*4882a593Smuzhiyun  fi
5463*4882a593Smuzhiyun
5464*4882a593Smuzhiyun  # Try to get the absolute directory name.
5465*4882a593Smuzhiyun  absdir=\`cd \"\$thisdir\" && pwd\`
5466*4882a593Smuzhiyun  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5467*4882a593Smuzhiyun"
5468*4882a593Smuzhiyun
5469*4882a593Smuzhiyun	if test yes = "$fast_install"; then
5470*4882a593Smuzhiyun	  $ECHO "\
5471*4882a593Smuzhiyun  program=lt-'$outputname'$exeext
5472*4882a593Smuzhiyun  progdir=\"\$thisdir/$objdir\"
5473*4882a593Smuzhiyun
5474*4882a593Smuzhiyun  if test ! -f \"\$progdir/\$program\" ||
5475*4882a593Smuzhiyun     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5476*4882a593Smuzhiyun       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5477*4882a593Smuzhiyun
5478*4882a593Smuzhiyun    file=\"\$\$-\$program\"
5479*4882a593Smuzhiyun
5480*4882a593Smuzhiyun    if test ! -d \"\$progdir\"; then
5481*4882a593Smuzhiyun      $MKDIR \"\$progdir\"
5482*4882a593Smuzhiyun    else
5483*4882a593Smuzhiyun      $RM \"\$progdir/\$file\"
5484*4882a593Smuzhiyun    fi"
5485*4882a593Smuzhiyun
5486*4882a593Smuzhiyun	  $ECHO "\
5487*4882a593Smuzhiyun
5488*4882a593Smuzhiyun    # relink executable if necessary
5489*4882a593Smuzhiyun    if test -n \"\$relink_command\"; then
5490*4882a593Smuzhiyun      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5491*4882a593Smuzhiyun      else
5492*4882a593Smuzhiyun	\$ECHO \"\$relink_command_output\" >&2
5493*4882a593Smuzhiyun	$RM \"\$progdir/\$file\"
5494*4882a593Smuzhiyun	exit 1
5495*4882a593Smuzhiyun      fi
5496*4882a593Smuzhiyun    fi
5497*4882a593Smuzhiyun
5498*4882a593Smuzhiyun    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5499*4882a593Smuzhiyun    { $RM \"\$progdir/\$program\";
5500*4882a593Smuzhiyun      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5501*4882a593Smuzhiyun    $RM \"\$progdir/\$file\"
5502*4882a593Smuzhiyun  fi"
5503*4882a593Smuzhiyun	else
5504*4882a593Smuzhiyun	  $ECHO "\
5505*4882a593Smuzhiyun  program='$outputname'
5506*4882a593Smuzhiyun  progdir=\"\$thisdir/$objdir\"
5507*4882a593Smuzhiyun"
5508*4882a593Smuzhiyun	fi
5509*4882a593Smuzhiyun
5510*4882a593Smuzhiyun	$ECHO "\
5511*4882a593Smuzhiyun
5512*4882a593Smuzhiyun  if test -f \"\$progdir/\$program\"; then"
5513*4882a593Smuzhiyun
5514*4882a593Smuzhiyun	# fixup the dll searchpath if we need to.
5515*4882a593Smuzhiyun	#
5516*4882a593Smuzhiyun	# Fix the DLL searchpath if we need to.  Do this before prepending
5517*4882a593Smuzhiyun	# to shlibpath, because on Windows, both are PATH and uninstalled
5518*4882a593Smuzhiyun	# libraries must come first.
5519*4882a593Smuzhiyun	if test -n "$dllsearchpath"; then
5520*4882a593Smuzhiyun	  $ECHO "\
5521*4882a593Smuzhiyun    # Add the dll search path components to the executable PATH
5522*4882a593Smuzhiyun    PATH=$dllsearchpath:\$PATH
5523*4882a593Smuzhiyun"
5524*4882a593Smuzhiyun	fi
5525*4882a593Smuzhiyun
5526*4882a593Smuzhiyun	# Export our shlibpath_var if we have one.
5527*4882a593Smuzhiyun	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5528*4882a593Smuzhiyun	  $ECHO "\
5529*4882a593Smuzhiyun    # Add our own library path to $shlibpath_var
5530*4882a593Smuzhiyun    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5531*4882a593Smuzhiyun
5532*4882a593Smuzhiyun    # Some systems cannot cope with colon-terminated $shlibpath_var
5533*4882a593Smuzhiyun    # The second colon is a workaround for a bug in BeOS R4 sed
5534*4882a593Smuzhiyun    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
5535*4882a593Smuzhiyun
5536*4882a593Smuzhiyun    export $shlibpath_var
5537*4882a593Smuzhiyun"
5538*4882a593Smuzhiyun	fi
5539*4882a593Smuzhiyun
5540*4882a593Smuzhiyun	$ECHO "\
5541*4882a593Smuzhiyun    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5542*4882a593Smuzhiyun      # Run the actual program with our arguments.
5543*4882a593Smuzhiyun      func_exec_program \${1+\"\$@\"}
5544*4882a593Smuzhiyun    fi
5545*4882a593Smuzhiyun  else
5546*4882a593Smuzhiyun    # The program doesn't exist.
5547*4882a593Smuzhiyun    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5548*4882a593Smuzhiyun    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5549*4882a593Smuzhiyun    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5550*4882a593Smuzhiyun    exit 1
5551*4882a593Smuzhiyun  fi
5552*4882a593Smuzhiyunfi\
5553*4882a593Smuzhiyun"
5554*4882a593Smuzhiyun}
5555*4882a593Smuzhiyun
5556*4882a593Smuzhiyun
5557*4882a593Smuzhiyun# func_emit_cwrapperexe_src
5558*4882a593Smuzhiyun# emit the source code for a wrapper executable on stdout
5559*4882a593Smuzhiyun# Must ONLY be called from within func_mode_link because
5560*4882a593Smuzhiyun# it depends on a number of variable set therein.
5561*4882a593Smuzhiyunfunc_emit_cwrapperexe_src ()
5562*4882a593Smuzhiyun{
5563*4882a593Smuzhiyun	cat <<EOF
5564*4882a593Smuzhiyun
5565*4882a593Smuzhiyun/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5566*4882a593Smuzhiyun   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5567*4882a593Smuzhiyun
5568*4882a593Smuzhiyun   The $output program cannot be directly executed until all the libtool
5569*4882a593Smuzhiyun   libraries that it depends on are installed.
5570*4882a593Smuzhiyun
5571*4882a593Smuzhiyun   This wrapper executable should never be moved out of the build directory.
5572*4882a593Smuzhiyun   If it is, it will not operate correctly.
5573*4882a593Smuzhiyun*/
5574*4882a593SmuzhiyunEOF
5575*4882a593Smuzhiyun	    cat <<"EOF"
5576*4882a593Smuzhiyun#ifdef _MSC_VER
5577*4882a593Smuzhiyun# define _CRT_SECURE_NO_DEPRECATE 1
5578*4882a593Smuzhiyun#endif
5579*4882a593Smuzhiyun#include <stdio.h>
5580*4882a593Smuzhiyun#include <stdlib.h>
5581*4882a593Smuzhiyun#ifdef _MSC_VER
5582*4882a593Smuzhiyun# include <direct.h>
5583*4882a593Smuzhiyun# include <process.h>
5584*4882a593Smuzhiyun# include <io.h>
5585*4882a593Smuzhiyun#else
5586*4882a593Smuzhiyun# include <unistd.h>
5587*4882a593Smuzhiyun# include <stdint.h>
5588*4882a593Smuzhiyun# ifdef __CYGWIN__
5589*4882a593Smuzhiyun#  include <io.h>
5590*4882a593Smuzhiyun# endif
5591*4882a593Smuzhiyun#endif
5592*4882a593Smuzhiyun#include <malloc.h>
5593*4882a593Smuzhiyun#include <stdarg.h>
5594*4882a593Smuzhiyun#include <assert.h>
5595*4882a593Smuzhiyun#include <string.h>
5596*4882a593Smuzhiyun#include <ctype.h>
5597*4882a593Smuzhiyun#include <errno.h>
5598*4882a593Smuzhiyun#include <fcntl.h>
5599*4882a593Smuzhiyun#include <sys/stat.h>
5600*4882a593Smuzhiyun
5601*4882a593Smuzhiyun#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5602*4882a593Smuzhiyun
5603*4882a593Smuzhiyun/* declarations of non-ANSI functions */
5604*4882a593Smuzhiyun#if defined __MINGW32__
5605*4882a593Smuzhiyun# ifdef __STRICT_ANSI__
5606*4882a593Smuzhiyunint _putenv (const char *);
5607*4882a593Smuzhiyun# endif
5608*4882a593Smuzhiyun#elif defined __CYGWIN__
5609*4882a593Smuzhiyun# ifdef __STRICT_ANSI__
5610*4882a593Smuzhiyunchar *realpath (const char *, char *);
5611*4882a593Smuzhiyunint putenv (char *);
5612*4882a593Smuzhiyunint setenv (const char *, const char *, int);
5613*4882a593Smuzhiyun# endif
5614*4882a593Smuzhiyun/* #elif defined other_platform || defined ... */
5615*4882a593Smuzhiyun#endif
5616*4882a593Smuzhiyun
5617*4882a593Smuzhiyun/* portability defines, excluding path handling macros */
5618*4882a593Smuzhiyun#if defined _MSC_VER
5619*4882a593Smuzhiyun# define setmode _setmode
5620*4882a593Smuzhiyun# define stat    _stat
5621*4882a593Smuzhiyun# define chmod   _chmod
5622*4882a593Smuzhiyun# define getcwd  _getcwd
5623*4882a593Smuzhiyun# define putenv  _putenv
5624*4882a593Smuzhiyun# define S_IXUSR _S_IEXEC
5625*4882a593Smuzhiyun#elif defined __MINGW32__
5626*4882a593Smuzhiyun# define setmode _setmode
5627*4882a593Smuzhiyun# define stat    _stat
5628*4882a593Smuzhiyun# define chmod   _chmod
5629*4882a593Smuzhiyun# define getcwd  _getcwd
5630*4882a593Smuzhiyun# define putenv  _putenv
5631*4882a593Smuzhiyun#elif defined __CYGWIN__
5632*4882a593Smuzhiyun# define HAVE_SETENV
5633*4882a593Smuzhiyun# define FOPEN_WB "wb"
5634*4882a593Smuzhiyun/* #elif defined other platforms ... */
5635*4882a593Smuzhiyun#endif
5636*4882a593Smuzhiyun
5637*4882a593Smuzhiyun#if defined PATH_MAX
5638*4882a593Smuzhiyun# define LT_PATHMAX PATH_MAX
5639*4882a593Smuzhiyun#elif defined MAXPATHLEN
5640*4882a593Smuzhiyun# define LT_PATHMAX MAXPATHLEN
5641*4882a593Smuzhiyun#else
5642*4882a593Smuzhiyun# define LT_PATHMAX 1024
5643*4882a593Smuzhiyun#endif
5644*4882a593Smuzhiyun
5645*4882a593Smuzhiyun#ifndef S_IXOTH
5646*4882a593Smuzhiyun# define S_IXOTH 0
5647*4882a593Smuzhiyun#endif
5648*4882a593Smuzhiyun#ifndef S_IXGRP
5649*4882a593Smuzhiyun# define S_IXGRP 0
5650*4882a593Smuzhiyun#endif
5651*4882a593Smuzhiyun
5652*4882a593Smuzhiyun/* path handling portability macros */
5653*4882a593Smuzhiyun#ifndef DIR_SEPARATOR
5654*4882a593Smuzhiyun# define DIR_SEPARATOR '/'
5655*4882a593Smuzhiyun# define PATH_SEPARATOR ':'
5656*4882a593Smuzhiyun#endif
5657*4882a593Smuzhiyun
5658*4882a593Smuzhiyun#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5659*4882a593Smuzhiyun  defined __OS2__
5660*4882a593Smuzhiyun# define HAVE_DOS_BASED_FILE_SYSTEM
5661*4882a593Smuzhiyun# define FOPEN_WB "wb"
5662*4882a593Smuzhiyun# ifndef DIR_SEPARATOR_2
5663*4882a593Smuzhiyun#  define DIR_SEPARATOR_2 '\\'
5664*4882a593Smuzhiyun# endif
5665*4882a593Smuzhiyun# ifndef PATH_SEPARATOR_2
5666*4882a593Smuzhiyun#  define PATH_SEPARATOR_2 ';'
5667*4882a593Smuzhiyun# endif
5668*4882a593Smuzhiyun#endif
5669*4882a593Smuzhiyun
5670*4882a593Smuzhiyun#ifndef DIR_SEPARATOR_2
5671*4882a593Smuzhiyun# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5672*4882a593Smuzhiyun#else /* DIR_SEPARATOR_2 */
5673*4882a593Smuzhiyun# define IS_DIR_SEPARATOR(ch) \
5674*4882a593Smuzhiyun	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5675*4882a593Smuzhiyun#endif /* DIR_SEPARATOR_2 */
5676*4882a593Smuzhiyun
5677*4882a593Smuzhiyun#ifndef PATH_SEPARATOR_2
5678*4882a593Smuzhiyun# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5679*4882a593Smuzhiyun#else /* PATH_SEPARATOR_2 */
5680*4882a593Smuzhiyun# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5681*4882a593Smuzhiyun#endif /* PATH_SEPARATOR_2 */
5682*4882a593Smuzhiyun
5683*4882a593Smuzhiyun#ifndef FOPEN_WB
5684*4882a593Smuzhiyun# define FOPEN_WB "w"
5685*4882a593Smuzhiyun#endif
5686*4882a593Smuzhiyun#ifndef _O_BINARY
5687*4882a593Smuzhiyun# define _O_BINARY 0
5688*4882a593Smuzhiyun#endif
5689*4882a593Smuzhiyun
5690*4882a593Smuzhiyun#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5691*4882a593Smuzhiyun#define XFREE(stale) do { \
5692*4882a593Smuzhiyun  if (stale) { free (stale); stale = 0; } \
5693*4882a593Smuzhiyun} while (0)
5694*4882a593Smuzhiyun
5695*4882a593Smuzhiyun#if defined LT_DEBUGWRAPPER
5696*4882a593Smuzhiyunstatic int lt_debug = 1;
5697*4882a593Smuzhiyun#else
5698*4882a593Smuzhiyunstatic int lt_debug = 0;
5699*4882a593Smuzhiyun#endif
5700*4882a593Smuzhiyun
5701*4882a593Smuzhiyunconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5702*4882a593Smuzhiyun
5703*4882a593Smuzhiyunvoid *xmalloc (size_t num);
5704*4882a593Smuzhiyunchar *xstrdup (const char *string);
5705*4882a593Smuzhiyunconst char *base_name (const char *name);
5706*4882a593Smuzhiyunchar *find_executable (const char *wrapper);
5707*4882a593Smuzhiyunchar *chase_symlinks (const char *pathspec);
5708*4882a593Smuzhiyunint make_executable (const char *path);
5709*4882a593Smuzhiyunint check_executable (const char *path);
5710*4882a593Smuzhiyunchar *strendzap (char *str, const char *pat);
5711*4882a593Smuzhiyunvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5712*4882a593Smuzhiyunvoid lt_fatal (const char *file, int line, const char *message, ...);
5713*4882a593Smuzhiyunstatic const char *nonnull (const char *s);
5714*4882a593Smuzhiyunstatic const char *nonempty (const char *s);
5715*4882a593Smuzhiyunvoid lt_setenv (const char *name, const char *value);
5716*4882a593Smuzhiyunchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5717*4882a593Smuzhiyunvoid lt_update_exe_path (const char *name, const char *value);
5718*4882a593Smuzhiyunvoid lt_update_lib_path (const char *name, const char *value);
5719*4882a593Smuzhiyunchar **prepare_spawn (char **argv);
5720*4882a593Smuzhiyunvoid lt_dump_script (FILE *f);
5721*4882a593SmuzhiyunEOF
5722*4882a593Smuzhiyun
5723*4882a593Smuzhiyun	    cat <<EOF
5724*4882a593Smuzhiyun#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5725*4882a593Smuzhiyun# define externally_visible volatile
5726*4882a593Smuzhiyun#else
5727*4882a593Smuzhiyun# define externally_visible __attribute__((externally_visible)) volatile
5728*4882a593Smuzhiyun#endif
5729*4882a593Smuzhiyunexternally_visible const char * MAGIC_EXE = "$magic_exe";
5730*4882a593Smuzhiyunconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5731*4882a593SmuzhiyunEOF
5732*4882a593Smuzhiyun
5733*4882a593Smuzhiyun	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5734*4882a593Smuzhiyun              func_to_host_path "$temp_rpath"
5735*4882a593Smuzhiyun	      cat <<EOF
5736*4882a593Smuzhiyunconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5737*4882a593SmuzhiyunEOF
5738*4882a593Smuzhiyun	    else
5739*4882a593Smuzhiyun	      cat <<"EOF"
5740*4882a593Smuzhiyunconst char * LIB_PATH_VALUE   = "";
5741*4882a593SmuzhiyunEOF
5742*4882a593Smuzhiyun	    fi
5743*4882a593Smuzhiyun
5744*4882a593Smuzhiyun	    if test -n "$dllsearchpath"; then
5745*4882a593Smuzhiyun              func_to_host_path "$dllsearchpath:"
5746*4882a593Smuzhiyun	      cat <<EOF
5747*4882a593Smuzhiyunconst char * EXE_PATH_VARNAME = "PATH";
5748*4882a593Smuzhiyunconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5749*4882a593SmuzhiyunEOF
5750*4882a593Smuzhiyun	    else
5751*4882a593Smuzhiyun	      cat <<"EOF"
5752*4882a593Smuzhiyunconst char * EXE_PATH_VARNAME = "";
5753*4882a593Smuzhiyunconst char * EXE_PATH_VALUE   = "";
5754*4882a593SmuzhiyunEOF
5755*4882a593Smuzhiyun	    fi
5756*4882a593Smuzhiyun
5757*4882a593Smuzhiyun	    if test yes = "$fast_install"; then
5758*4882a593Smuzhiyun	      cat <<EOF
5759*4882a593Smuzhiyunconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5760*4882a593SmuzhiyunEOF
5761*4882a593Smuzhiyun	    else
5762*4882a593Smuzhiyun	      cat <<EOF
5763*4882a593Smuzhiyunconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5764*4882a593SmuzhiyunEOF
5765*4882a593Smuzhiyun	    fi
5766*4882a593Smuzhiyun
5767*4882a593Smuzhiyun
5768*4882a593Smuzhiyun	    cat <<"EOF"
5769*4882a593Smuzhiyun
5770*4882a593Smuzhiyun#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5771*4882a593Smuzhiyun
5772*4882a593Smuzhiyunstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5773*4882a593Smuzhiyunstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5774*4882a593Smuzhiyunstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5775*4882a593Smuzhiyun
5776*4882a593Smuzhiyunint
5777*4882a593Smuzhiyunmain (int argc, char *argv[])
5778*4882a593Smuzhiyun{
5779*4882a593Smuzhiyun  char **newargz;
5780*4882a593Smuzhiyun  int  newargc;
5781*4882a593Smuzhiyun  char *tmp_pathspec;
5782*4882a593Smuzhiyun  char *actual_cwrapper_path;
5783*4882a593Smuzhiyun  char *actual_cwrapper_name;
5784*4882a593Smuzhiyun  char *target_name;
5785*4882a593Smuzhiyun  char *lt_argv_zero;
5786*4882a593Smuzhiyun  int rval = 127;
5787*4882a593Smuzhiyun
5788*4882a593Smuzhiyun  int i;
5789*4882a593Smuzhiyun
5790*4882a593Smuzhiyun  program_name = (char *) xstrdup (base_name (argv[0]));
5791*4882a593Smuzhiyun  newargz = XMALLOC (char *, (size_t) argc + 1);
5792*4882a593Smuzhiyun
5793*4882a593Smuzhiyun  /* very simple arg parsing; don't want to rely on getopt
5794*4882a593Smuzhiyun   * also, copy all non cwrapper options to newargz, except
5795*4882a593Smuzhiyun   * argz[0], which is handled differently
5796*4882a593Smuzhiyun   */
5797*4882a593Smuzhiyun  newargc=0;
5798*4882a593Smuzhiyun  for (i = 1; i < argc; i++)
5799*4882a593Smuzhiyun    {
5800*4882a593Smuzhiyun      if (STREQ (argv[i], dumpscript_opt))
5801*4882a593Smuzhiyun	{
5802*4882a593SmuzhiyunEOF
5803*4882a593Smuzhiyun	    case $host in
5804*4882a593Smuzhiyun	      *mingw* | *cygwin* )
5805*4882a593Smuzhiyun		# make stdout use "unix" line endings
5806*4882a593Smuzhiyun		echo "          setmode(1,_O_BINARY);"
5807*4882a593Smuzhiyun		;;
5808*4882a593Smuzhiyun	      esac
5809*4882a593Smuzhiyun
5810*4882a593Smuzhiyun	    cat <<"EOF"
5811*4882a593Smuzhiyun	  lt_dump_script (stdout);
5812*4882a593Smuzhiyun	  return 0;
5813*4882a593Smuzhiyun	}
5814*4882a593Smuzhiyun      if (STREQ (argv[i], debug_opt))
5815*4882a593Smuzhiyun	{
5816*4882a593Smuzhiyun          lt_debug = 1;
5817*4882a593Smuzhiyun          continue;
5818*4882a593Smuzhiyun	}
5819*4882a593Smuzhiyun      if (STREQ (argv[i], ltwrapper_option_prefix))
5820*4882a593Smuzhiyun        {
5821*4882a593Smuzhiyun          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
5822*4882a593Smuzhiyun             namespace, but it is not one of the ones we know about and
5823*4882a593Smuzhiyun             have already dealt with, above (inluding dump-script), then
5824*4882a593Smuzhiyun             report an error. Otherwise, targets might begin to believe
5825*4882a593Smuzhiyun             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
5826*4882a593Smuzhiyun             namespace. The first time any user complains about this, we'll
5827*4882a593Smuzhiyun             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
5828*4882a593Smuzhiyun             or a configure.ac-settable value.
5829*4882a593Smuzhiyun           */
5830*4882a593Smuzhiyun          lt_fatal (__FILE__, __LINE__,
5831*4882a593Smuzhiyun		    "unrecognized %s option: '%s'",
5832*4882a593Smuzhiyun                    ltwrapper_option_prefix, argv[i]);
5833*4882a593Smuzhiyun        }
5834*4882a593Smuzhiyun      /* otherwise ... */
5835*4882a593Smuzhiyun      newargz[++newargc] = xstrdup (argv[i]);
5836*4882a593Smuzhiyun    }
5837*4882a593Smuzhiyun  newargz[++newargc] = NULL;
5838*4882a593Smuzhiyun
5839*4882a593SmuzhiyunEOF
5840*4882a593Smuzhiyun	    cat <<EOF
5841*4882a593Smuzhiyun  /* The GNU banner must be the first non-error debug message */
5842*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
5843*4882a593SmuzhiyunEOF
5844*4882a593Smuzhiyun	    cat <<"EOF"
5845*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
5846*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
5847*4882a593Smuzhiyun
5848*4882a593Smuzhiyun  tmp_pathspec = find_executable (argv[0]);
5849*4882a593Smuzhiyun  if (tmp_pathspec == NULL)
5850*4882a593Smuzhiyun    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
5851*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__,
5852*4882a593Smuzhiyun                  "(main) found exe (before symlink chase) at: %s\n",
5853*4882a593Smuzhiyun		  tmp_pathspec);
5854*4882a593Smuzhiyun
5855*4882a593Smuzhiyun  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
5856*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__,
5857*4882a593Smuzhiyun                  "(main) found exe (after symlink chase) at: %s\n",
5858*4882a593Smuzhiyun		  actual_cwrapper_path);
5859*4882a593Smuzhiyun  XFREE (tmp_pathspec);
5860*4882a593Smuzhiyun
5861*4882a593Smuzhiyun  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
5862*4882a593Smuzhiyun  strendzap (actual_cwrapper_path, actual_cwrapper_name);
5863*4882a593Smuzhiyun
5864*4882a593Smuzhiyun  /* wrapper name transforms */
5865*4882a593Smuzhiyun  strendzap (actual_cwrapper_name, ".exe");
5866*4882a593Smuzhiyun  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
5867*4882a593Smuzhiyun  XFREE (actual_cwrapper_name);
5868*4882a593Smuzhiyun  actual_cwrapper_name = tmp_pathspec;
5869*4882a593Smuzhiyun  tmp_pathspec = 0;
5870*4882a593Smuzhiyun
5871*4882a593Smuzhiyun  /* target_name transforms -- use actual target program name; might have lt- prefix */
5872*4882a593Smuzhiyun  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
5873*4882a593Smuzhiyun  strendzap (target_name, ".exe");
5874*4882a593Smuzhiyun  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
5875*4882a593Smuzhiyun  XFREE (target_name);
5876*4882a593Smuzhiyun  target_name = tmp_pathspec;
5877*4882a593Smuzhiyun  tmp_pathspec = 0;
5878*4882a593Smuzhiyun
5879*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__,
5880*4882a593Smuzhiyun		  "(main) libtool target name: %s\n",
5881*4882a593Smuzhiyun		  target_name);
5882*4882a593SmuzhiyunEOF
5883*4882a593Smuzhiyun
5884*4882a593Smuzhiyun	    cat <<EOF
5885*4882a593Smuzhiyun  newargz[0] =
5886*4882a593Smuzhiyun    XMALLOC (char, (strlen (actual_cwrapper_path) +
5887*4882a593Smuzhiyun		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
5888*4882a593Smuzhiyun  strcpy (newargz[0], actual_cwrapper_path);
5889*4882a593Smuzhiyun  strcat (newargz[0], "$objdir");
5890*4882a593Smuzhiyun  strcat (newargz[0], "/");
5891*4882a593SmuzhiyunEOF
5892*4882a593Smuzhiyun
5893*4882a593Smuzhiyun	    cat <<"EOF"
5894*4882a593Smuzhiyun  /* stop here, and copy so we don't have to do this twice */
5895*4882a593Smuzhiyun  tmp_pathspec = xstrdup (newargz[0]);
5896*4882a593Smuzhiyun
5897*4882a593Smuzhiyun  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
5898*4882a593Smuzhiyun  strcat (newargz[0], actual_cwrapper_name);
5899*4882a593Smuzhiyun
5900*4882a593Smuzhiyun  /* DO want the lt- prefix here if it exists, so use target_name */
5901*4882a593Smuzhiyun  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
5902*4882a593Smuzhiyun  XFREE (tmp_pathspec);
5903*4882a593Smuzhiyun  tmp_pathspec = NULL;
5904*4882a593SmuzhiyunEOF
5905*4882a593Smuzhiyun
5906*4882a593Smuzhiyun	    case $host_os in
5907*4882a593Smuzhiyun	      mingw*)
5908*4882a593Smuzhiyun	    cat <<"EOF"
5909*4882a593Smuzhiyun  {
5910*4882a593Smuzhiyun    char* p;
5911*4882a593Smuzhiyun    while ((p = strchr (newargz[0], '\\')) != NULL)
5912*4882a593Smuzhiyun      {
5913*4882a593Smuzhiyun	*p = '/';
5914*4882a593Smuzhiyun      }
5915*4882a593Smuzhiyun    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
5916*4882a593Smuzhiyun      {
5917*4882a593Smuzhiyun	*p = '/';
5918*4882a593Smuzhiyun      }
5919*4882a593Smuzhiyun  }
5920*4882a593SmuzhiyunEOF
5921*4882a593Smuzhiyun	    ;;
5922*4882a593Smuzhiyun	    esac
5923*4882a593Smuzhiyun
5924*4882a593Smuzhiyun	    cat <<"EOF"
5925*4882a593Smuzhiyun  XFREE (target_name);
5926*4882a593Smuzhiyun  XFREE (actual_cwrapper_path);
5927*4882a593Smuzhiyun  XFREE (actual_cwrapper_name);
5928*4882a593Smuzhiyun
5929*4882a593Smuzhiyun  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
5930*4882a593Smuzhiyun  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
5931*4882a593Smuzhiyun  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
5932*4882a593Smuzhiyun     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
5933*4882a593Smuzhiyun     because on Windows, both *_VARNAMEs are PATH but uninstalled
5934*4882a593Smuzhiyun     libraries must come first. */
5935*4882a593Smuzhiyun  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
5936*4882a593Smuzhiyun  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
5937*4882a593Smuzhiyun
5938*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
5939*4882a593Smuzhiyun		  nonnull (lt_argv_zero));
5940*4882a593Smuzhiyun  for (i = 0; i < newargc; i++)
5941*4882a593Smuzhiyun    {
5942*4882a593Smuzhiyun      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
5943*4882a593Smuzhiyun		      i, nonnull (newargz[i]));
5944*4882a593Smuzhiyun    }
5945*4882a593Smuzhiyun
5946*4882a593SmuzhiyunEOF
5947*4882a593Smuzhiyun
5948*4882a593Smuzhiyun	    case $host_os in
5949*4882a593Smuzhiyun	      mingw*)
5950*4882a593Smuzhiyun		cat <<"EOF"
5951*4882a593Smuzhiyun  /* execv doesn't actually work on mingw as expected on unix */
5952*4882a593Smuzhiyun  newargz = prepare_spawn (newargz);
5953*4882a593Smuzhiyun  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
5954*4882a593Smuzhiyun  if (rval == -1)
5955*4882a593Smuzhiyun    {
5956*4882a593Smuzhiyun      /* failed to start process */
5957*4882a593Smuzhiyun      lt_debugprintf (__FILE__, __LINE__,
5958*4882a593Smuzhiyun		      "(main) failed to launch target \"%s\": %s\n",
5959*4882a593Smuzhiyun		      lt_argv_zero, nonnull (strerror (errno)));
5960*4882a593Smuzhiyun      return 127;
5961*4882a593Smuzhiyun    }
5962*4882a593Smuzhiyun  return rval;
5963*4882a593SmuzhiyunEOF
5964*4882a593Smuzhiyun		;;
5965*4882a593Smuzhiyun	      *)
5966*4882a593Smuzhiyun		cat <<"EOF"
5967*4882a593Smuzhiyun  execv (lt_argv_zero, newargz);
5968*4882a593Smuzhiyun  return rval; /* =127, but avoids unused variable warning */
5969*4882a593SmuzhiyunEOF
5970*4882a593Smuzhiyun		;;
5971*4882a593Smuzhiyun	    esac
5972*4882a593Smuzhiyun
5973*4882a593Smuzhiyun	    cat <<"EOF"
5974*4882a593Smuzhiyun}
5975*4882a593Smuzhiyun
5976*4882a593Smuzhiyunvoid *
5977*4882a593Smuzhiyunxmalloc (size_t num)
5978*4882a593Smuzhiyun{
5979*4882a593Smuzhiyun  void *p = (void *) malloc (num);
5980*4882a593Smuzhiyun  if (!p)
5981*4882a593Smuzhiyun    lt_fatal (__FILE__, __LINE__, "memory exhausted");
5982*4882a593Smuzhiyun
5983*4882a593Smuzhiyun  return p;
5984*4882a593Smuzhiyun}
5985*4882a593Smuzhiyun
5986*4882a593Smuzhiyunchar *
5987*4882a593Smuzhiyunxstrdup (const char *string)
5988*4882a593Smuzhiyun{
5989*4882a593Smuzhiyun  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
5990*4882a593Smuzhiyun			  string) : NULL;
5991*4882a593Smuzhiyun}
5992*4882a593Smuzhiyun
5993*4882a593Smuzhiyunconst char *
5994*4882a593Smuzhiyunbase_name (const char *name)
5995*4882a593Smuzhiyun{
5996*4882a593Smuzhiyun  const char *base;
5997*4882a593Smuzhiyun
5998*4882a593Smuzhiyun#if defined HAVE_DOS_BASED_FILE_SYSTEM
5999*4882a593Smuzhiyun  /* Skip over the disk name in MSDOS pathnames. */
6000*4882a593Smuzhiyun  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6001*4882a593Smuzhiyun    name += 2;
6002*4882a593Smuzhiyun#endif
6003*4882a593Smuzhiyun
6004*4882a593Smuzhiyun  for (base = name; *name; name++)
6005*4882a593Smuzhiyun    if (IS_DIR_SEPARATOR (*name))
6006*4882a593Smuzhiyun      base = name + 1;
6007*4882a593Smuzhiyun  return base;
6008*4882a593Smuzhiyun}
6009*4882a593Smuzhiyun
6010*4882a593Smuzhiyunint
6011*4882a593Smuzhiyuncheck_executable (const char *path)
6012*4882a593Smuzhiyun{
6013*4882a593Smuzhiyun  struct stat st;
6014*4882a593Smuzhiyun
6015*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6016*4882a593Smuzhiyun                  nonempty (path));
6017*4882a593Smuzhiyun  if ((!path) || (!*path))
6018*4882a593Smuzhiyun    return 0;
6019*4882a593Smuzhiyun
6020*4882a593Smuzhiyun  if ((stat (path, &st) >= 0)
6021*4882a593Smuzhiyun      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6022*4882a593Smuzhiyun    return 1;
6023*4882a593Smuzhiyun  else
6024*4882a593Smuzhiyun    return 0;
6025*4882a593Smuzhiyun}
6026*4882a593Smuzhiyun
6027*4882a593Smuzhiyunint
6028*4882a593Smuzhiyunmake_executable (const char *path)
6029*4882a593Smuzhiyun{
6030*4882a593Smuzhiyun  int rval = 0;
6031*4882a593Smuzhiyun  struct stat st;
6032*4882a593Smuzhiyun
6033*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6034*4882a593Smuzhiyun                  nonempty (path));
6035*4882a593Smuzhiyun  if ((!path) || (!*path))
6036*4882a593Smuzhiyun    return 0;
6037*4882a593Smuzhiyun
6038*4882a593Smuzhiyun  if (stat (path, &st) >= 0)
6039*4882a593Smuzhiyun    {
6040*4882a593Smuzhiyun      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6041*4882a593Smuzhiyun    }
6042*4882a593Smuzhiyun  return rval;
6043*4882a593Smuzhiyun}
6044*4882a593Smuzhiyun
6045*4882a593Smuzhiyun/* Searches for the full path of the wrapper.  Returns
6046*4882a593Smuzhiyun   newly allocated full path name if found, NULL otherwise
6047*4882a593Smuzhiyun   Does not chase symlinks, even on platforms that support them.
6048*4882a593Smuzhiyun*/
6049*4882a593Smuzhiyunchar *
6050*4882a593Smuzhiyunfind_executable (const char *wrapper)
6051*4882a593Smuzhiyun{
6052*4882a593Smuzhiyun  int has_slash = 0;
6053*4882a593Smuzhiyun  const char *p;
6054*4882a593Smuzhiyun  const char *p_next;
6055*4882a593Smuzhiyun  /* static buffer for getcwd */
6056*4882a593Smuzhiyun  char tmp[LT_PATHMAX + 1];
6057*4882a593Smuzhiyun  size_t tmp_len;
6058*4882a593Smuzhiyun  char *concat_name;
6059*4882a593Smuzhiyun
6060*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6061*4882a593Smuzhiyun                  nonempty (wrapper));
6062*4882a593Smuzhiyun
6063*4882a593Smuzhiyun  if ((wrapper == NULL) || (*wrapper == '\0'))
6064*4882a593Smuzhiyun    return NULL;
6065*4882a593Smuzhiyun
6066*4882a593Smuzhiyun  /* Absolute path? */
6067*4882a593Smuzhiyun#if defined HAVE_DOS_BASED_FILE_SYSTEM
6068*4882a593Smuzhiyun  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6069*4882a593Smuzhiyun    {
6070*4882a593Smuzhiyun      concat_name = xstrdup (wrapper);
6071*4882a593Smuzhiyun      if (check_executable (concat_name))
6072*4882a593Smuzhiyun	return concat_name;
6073*4882a593Smuzhiyun      XFREE (concat_name);
6074*4882a593Smuzhiyun    }
6075*4882a593Smuzhiyun  else
6076*4882a593Smuzhiyun    {
6077*4882a593Smuzhiyun#endif
6078*4882a593Smuzhiyun      if (IS_DIR_SEPARATOR (wrapper[0]))
6079*4882a593Smuzhiyun	{
6080*4882a593Smuzhiyun	  concat_name = xstrdup (wrapper);
6081*4882a593Smuzhiyun	  if (check_executable (concat_name))
6082*4882a593Smuzhiyun	    return concat_name;
6083*4882a593Smuzhiyun	  XFREE (concat_name);
6084*4882a593Smuzhiyun	}
6085*4882a593Smuzhiyun#if defined HAVE_DOS_BASED_FILE_SYSTEM
6086*4882a593Smuzhiyun    }
6087*4882a593Smuzhiyun#endif
6088*4882a593Smuzhiyun
6089*4882a593Smuzhiyun  for (p = wrapper; *p; p++)
6090*4882a593Smuzhiyun    if (*p == '/')
6091*4882a593Smuzhiyun      {
6092*4882a593Smuzhiyun	has_slash = 1;
6093*4882a593Smuzhiyun	break;
6094*4882a593Smuzhiyun      }
6095*4882a593Smuzhiyun  if (!has_slash)
6096*4882a593Smuzhiyun    {
6097*4882a593Smuzhiyun      /* no slashes; search PATH */
6098*4882a593Smuzhiyun      const char *path = getenv ("PATH");
6099*4882a593Smuzhiyun      if (path != NULL)
6100*4882a593Smuzhiyun	{
6101*4882a593Smuzhiyun	  for (p = path; *p; p = p_next)
6102*4882a593Smuzhiyun	    {
6103*4882a593Smuzhiyun	      const char *q;
6104*4882a593Smuzhiyun	      size_t p_len;
6105*4882a593Smuzhiyun	      for (q = p; *q; q++)
6106*4882a593Smuzhiyun		if (IS_PATH_SEPARATOR (*q))
6107*4882a593Smuzhiyun		  break;
6108*4882a593Smuzhiyun	      p_len = (size_t) (q - p);
6109*4882a593Smuzhiyun	      p_next = (*q == '\0' ? q : q + 1);
6110*4882a593Smuzhiyun	      if (p_len == 0)
6111*4882a593Smuzhiyun		{
6112*4882a593Smuzhiyun		  /* empty path: current directory */
6113*4882a593Smuzhiyun		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6114*4882a593Smuzhiyun		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6115*4882a593Smuzhiyun                              nonnull (strerror (errno)));
6116*4882a593Smuzhiyun		  tmp_len = strlen (tmp);
6117*4882a593Smuzhiyun		  concat_name =
6118*4882a593Smuzhiyun		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6119*4882a593Smuzhiyun		  memcpy (concat_name, tmp, tmp_len);
6120*4882a593Smuzhiyun		  concat_name[tmp_len] = '/';
6121*4882a593Smuzhiyun		  strcpy (concat_name + tmp_len + 1, wrapper);
6122*4882a593Smuzhiyun		}
6123*4882a593Smuzhiyun	      else
6124*4882a593Smuzhiyun		{
6125*4882a593Smuzhiyun		  concat_name =
6126*4882a593Smuzhiyun		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6127*4882a593Smuzhiyun		  memcpy (concat_name, p, p_len);
6128*4882a593Smuzhiyun		  concat_name[p_len] = '/';
6129*4882a593Smuzhiyun		  strcpy (concat_name + p_len + 1, wrapper);
6130*4882a593Smuzhiyun		}
6131*4882a593Smuzhiyun	      if (check_executable (concat_name))
6132*4882a593Smuzhiyun		return concat_name;
6133*4882a593Smuzhiyun	      XFREE (concat_name);
6134*4882a593Smuzhiyun	    }
6135*4882a593Smuzhiyun	}
6136*4882a593Smuzhiyun      /* not found in PATH; assume curdir */
6137*4882a593Smuzhiyun    }
6138*4882a593Smuzhiyun  /* Relative path | not found in path: prepend cwd */
6139*4882a593Smuzhiyun  if (getcwd (tmp, LT_PATHMAX) == NULL)
6140*4882a593Smuzhiyun    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6141*4882a593Smuzhiyun              nonnull (strerror (errno)));
6142*4882a593Smuzhiyun  tmp_len = strlen (tmp);
6143*4882a593Smuzhiyun  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6144*4882a593Smuzhiyun  memcpy (concat_name, tmp, tmp_len);
6145*4882a593Smuzhiyun  concat_name[tmp_len] = '/';
6146*4882a593Smuzhiyun  strcpy (concat_name + tmp_len + 1, wrapper);
6147*4882a593Smuzhiyun
6148*4882a593Smuzhiyun  if (check_executable (concat_name))
6149*4882a593Smuzhiyun    return concat_name;
6150*4882a593Smuzhiyun  XFREE (concat_name);
6151*4882a593Smuzhiyun  return NULL;
6152*4882a593Smuzhiyun}
6153*4882a593Smuzhiyun
6154*4882a593Smuzhiyunchar *
6155*4882a593Smuzhiyunchase_symlinks (const char *pathspec)
6156*4882a593Smuzhiyun{
6157*4882a593Smuzhiyun#ifndef S_ISLNK
6158*4882a593Smuzhiyun  return xstrdup (pathspec);
6159*4882a593Smuzhiyun#else
6160*4882a593Smuzhiyun  char buf[LT_PATHMAX];
6161*4882a593Smuzhiyun  struct stat s;
6162*4882a593Smuzhiyun  char *tmp_pathspec = xstrdup (pathspec);
6163*4882a593Smuzhiyun  char *p;
6164*4882a593Smuzhiyun  int has_symlinks = 0;
6165*4882a593Smuzhiyun  while (strlen (tmp_pathspec) && !has_symlinks)
6166*4882a593Smuzhiyun    {
6167*4882a593Smuzhiyun      lt_debugprintf (__FILE__, __LINE__,
6168*4882a593Smuzhiyun		      "checking path component for symlinks: %s\n",
6169*4882a593Smuzhiyun		      tmp_pathspec);
6170*4882a593Smuzhiyun      if (lstat (tmp_pathspec, &s) == 0)
6171*4882a593Smuzhiyun	{
6172*4882a593Smuzhiyun	  if (S_ISLNK (s.st_mode) != 0)
6173*4882a593Smuzhiyun	    {
6174*4882a593Smuzhiyun	      has_symlinks = 1;
6175*4882a593Smuzhiyun	      break;
6176*4882a593Smuzhiyun	    }
6177*4882a593Smuzhiyun
6178*4882a593Smuzhiyun	  /* search backwards for last DIR_SEPARATOR */
6179*4882a593Smuzhiyun	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6180*4882a593Smuzhiyun	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6181*4882a593Smuzhiyun	    p--;
6182*4882a593Smuzhiyun	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6183*4882a593Smuzhiyun	    {
6184*4882a593Smuzhiyun	      /* no more DIR_SEPARATORS left */
6185*4882a593Smuzhiyun	      break;
6186*4882a593Smuzhiyun	    }
6187*4882a593Smuzhiyun	  *p = '\0';
6188*4882a593Smuzhiyun	}
6189*4882a593Smuzhiyun      else
6190*4882a593Smuzhiyun	{
6191*4882a593Smuzhiyun	  lt_fatal (__FILE__, __LINE__,
6192*4882a593Smuzhiyun		    "error accessing file \"%s\": %s",
6193*4882a593Smuzhiyun		    tmp_pathspec, nonnull (strerror (errno)));
6194*4882a593Smuzhiyun	}
6195*4882a593Smuzhiyun    }
6196*4882a593Smuzhiyun  XFREE (tmp_pathspec);
6197*4882a593Smuzhiyun
6198*4882a593Smuzhiyun  if (!has_symlinks)
6199*4882a593Smuzhiyun    {
6200*4882a593Smuzhiyun      return xstrdup (pathspec);
6201*4882a593Smuzhiyun    }
6202*4882a593Smuzhiyun
6203*4882a593Smuzhiyun  tmp_pathspec = realpath (pathspec, buf);
6204*4882a593Smuzhiyun  if (tmp_pathspec == 0)
6205*4882a593Smuzhiyun    {
6206*4882a593Smuzhiyun      lt_fatal (__FILE__, __LINE__,
6207*4882a593Smuzhiyun		"could not follow symlinks for %s", pathspec);
6208*4882a593Smuzhiyun    }
6209*4882a593Smuzhiyun  return xstrdup (tmp_pathspec);
6210*4882a593Smuzhiyun#endif
6211*4882a593Smuzhiyun}
6212*4882a593Smuzhiyun
6213*4882a593Smuzhiyunchar *
6214*4882a593Smuzhiyunstrendzap (char *str, const char *pat)
6215*4882a593Smuzhiyun{
6216*4882a593Smuzhiyun  size_t len, patlen;
6217*4882a593Smuzhiyun
6218*4882a593Smuzhiyun  assert (str != NULL);
6219*4882a593Smuzhiyun  assert (pat != NULL);
6220*4882a593Smuzhiyun
6221*4882a593Smuzhiyun  len = strlen (str);
6222*4882a593Smuzhiyun  patlen = strlen (pat);
6223*4882a593Smuzhiyun
6224*4882a593Smuzhiyun  if (patlen <= len)
6225*4882a593Smuzhiyun    {
6226*4882a593Smuzhiyun      str += len - patlen;
6227*4882a593Smuzhiyun      if (STREQ (str, pat))
6228*4882a593Smuzhiyun	*str = '\0';
6229*4882a593Smuzhiyun    }
6230*4882a593Smuzhiyun  return str;
6231*4882a593Smuzhiyun}
6232*4882a593Smuzhiyun
6233*4882a593Smuzhiyunvoid
6234*4882a593Smuzhiyunlt_debugprintf (const char *file, int line, const char *fmt, ...)
6235*4882a593Smuzhiyun{
6236*4882a593Smuzhiyun  va_list args;
6237*4882a593Smuzhiyun  if (lt_debug)
6238*4882a593Smuzhiyun    {
6239*4882a593Smuzhiyun      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6240*4882a593Smuzhiyun      va_start (args, fmt);
6241*4882a593Smuzhiyun      (void) vfprintf (stderr, fmt, args);
6242*4882a593Smuzhiyun      va_end (args);
6243*4882a593Smuzhiyun    }
6244*4882a593Smuzhiyun}
6245*4882a593Smuzhiyun
6246*4882a593Smuzhiyunstatic void
6247*4882a593Smuzhiyunlt_error_core (int exit_status, const char *file,
6248*4882a593Smuzhiyun	       int line, const char *mode,
6249*4882a593Smuzhiyun	       const char *message, va_list ap)
6250*4882a593Smuzhiyun{
6251*4882a593Smuzhiyun  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6252*4882a593Smuzhiyun  vfprintf (stderr, message, ap);
6253*4882a593Smuzhiyun  fprintf (stderr, ".\n");
6254*4882a593Smuzhiyun
6255*4882a593Smuzhiyun  if (exit_status >= 0)
6256*4882a593Smuzhiyun    exit (exit_status);
6257*4882a593Smuzhiyun}
6258*4882a593Smuzhiyun
6259*4882a593Smuzhiyunvoid
6260*4882a593Smuzhiyunlt_fatal (const char *file, int line, const char *message, ...)
6261*4882a593Smuzhiyun{
6262*4882a593Smuzhiyun  va_list ap;
6263*4882a593Smuzhiyun  va_start (ap, message);
6264*4882a593Smuzhiyun  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6265*4882a593Smuzhiyun  va_end (ap);
6266*4882a593Smuzhiyun}
6267*4882a593Smuzhiyun
6268*4882a593Smuzhiyunstatic const char *
6269*4882a593Smuzhiyunnonnull (const char *s)
6270*4882a593Smuzhiyun{
6271*4882a593Smuzhiyun  return s ? s : "(null)";
6272*4882a593Smuzhiyun}
6273*4882a593Smuzhiyun
6274*4882a593Smuzhiyunstatic const char *
6275*4882a593Smuzhiyunnonempty (const char *s)
6276*4882a593Smuzhiyun{
6277*4882a593Smuzhiyun  return (s && !*s) ? "(empty)" : nonnull (s);
6278*4882a593Smuzhiyun}
6279*4882a593Smuzhiyun
6280*4882a593Smuzhiyunvoid
6281*4882a593Smuzhiyunlt_setenv (const char *name, const char *value)
6282*4882a593Smuzhiyun{
6283*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__,
6284*4882a593Smuzhiyun		  "(lt_setenv) setting '%s' to '%s'\n",
6285*4882a593Smuzhiyun                  nonnull (name), nonnull (value));
6286*4882a593Smuzhiyun  {
6287*4882a593Smuzhiyun#ifdef HAVE_SETENV
6288*4882a593Smuzhiyun    /* always make a copy, for consistency with !HAVE_SETENV */
6289*4882a593Smuzhiyun    char *str = xstrdup (value);
6290*4882a593Smuzhiyun    setenv (name, str, 1);
6291*4882a593Smuzhiyun#else
6292*4882a593Smuzhiyun    size_t len = strlen (name) + 1 + strlen (value) + 1;
6293*4882a593Smuzhiyun    char *str = XMALLOC (char, len);
6294*4882a593Smuzhiyun    sprintf (str, "%s=%s", name, value);
6295*4882a593Smuzhiyun    if (putenv (str) != EXIT_SUCCESS)
6296*4882a593Smuzhiyun      {
6297*4882a593Smuzhiyun        XFREE (str);
6298*4882a593Smuzhiyun      }
6299*4882a593Smuzhiyun#endif
6300*4882a593Smuzhiyun  }
6301*4882a593Smuzhiyun}
6302*4882a593Smuzhiyun
6303*4882a593Smuzhiyunchar *
6304*4882a593Smuzhiyunlt_extend_str (const char *orig_value, const char *add, int to_end)
6305*4882a593Smuzhiyun{
6306*4882a593Smuzhiyun  char *new_value;
6307*4882a593Smuzhiyun  if (orig_value && *orig_value)
6308*4882a593Smuzhiyun    {
6309*4882a593Smuzhiyun      size_t orig_value_len = strlen (orig_value);
6310*4882a593Smuzhiyun      size_t add_len = strlen (add);
6311*4882a593Smuzhiyun      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6312*4882a593Smuzhiyun      if (to_end)
6313*4882a593Smuzhiyun        {
6314*4882a593Smuzhiyun          strcpy (new_value, orig_value);
6315*4882a593Smuzhiyun          strcpy (new_value + orig_value_len, add);
6316*4882a593Smuzhiyun        }
6317*4882a593Smuzhiyun      else
6318*4882a593Smuzhiyun        {
6319*4882a593Smuzhiyun          strcpy (new_value, add);
6320*4882a593Smuzhiyun          strcpy (new_value + add_len, orig_value);
6321*4882a593Smuzhiyun        }
6322*4882a593Smuzhiyun    }
6323*4882a593Smuzhiyun  else
6324*4882a593Smuzhiyun    {
6325*4882a593Smuzhiyun      new_value = xstrdup (add);
6326*4882a593Smuzhiyun    }
6327*4882a593Smuzhiyun  return new_value;
6328*4882a593Smuzhiyun}
6329*4882a593Smuzhiyun
6330*4882a593Smuzhiyunvoid
6331*4882a593Smuzhiyunlt_update_exe_path (const char *name, const char *value)
6332*4882a593Smuzhiyun{
6333*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__,
6334*4882a593Smuzhiyun		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6335*4882a593Smuzhiyun                  nonnull (name), nonnull (value));
6336*4882a593Smuzhiyun
6337*4882a593Smuzhiyun  if (name && *name && value && *value)
6338*4882a593Smuzhiyun    {
6339*4882a593Smuzhiyun      char *new_value = lt_extend_str (getenv (name), value, 0);
6340*4882a593Smuzhiyun      /* some systems can't cope with a ':'-terminated path #' */
6341*4882a593Smuzhiyun      size_t len = strlen (new_value);
6342*4882a593Smuzhiyun      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6343*4882a593Smuzhiyun        {
6344*4882a593Smuzhiyun          new_value[--len] = '\0';
6345*4882a593Smuzhiyun        }
6346*4882a593Smuzhiyun      lt_setenv (name, new_value);
6347*4882a593Smuzhiyun      XFREE (new_value);
6348*4882a593Smuzhiyun    }
6349*4882a593Smuzhiyun}
6350*4882a593Smuzhiyun
6351*4882a593Smuzhiyunvoid
6352*4882a593Smuzhiyunlt_update_lib_path (const char *name, const char *value)
6353*4882a593Smuzhiyun{
6354*4882a593Smuzhiyun  lt_debugprintf (__FILE__, __LINE__,
6355*4882a593Smuzhiyun		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6356*4882a593Smuzhiyun                  nonnull (name), nonnull (value));
6357*4882a593Smuzhiyun
6358*4882a593Smuzhiyun  if (name && *name && value && *value)
6359*4882a593Smuzhiyun    {
6360*4882a593Smuzhiyun      char *new_value = lt_extend_str (getenv (name), value, 0);
6361*4882a593Smuzhiyun      lt_setenv (name, new_value);
6362*4882a593Smuzhiyun      XFREE (new_value);
6363*4882a593Smuzhiyun    }
6364*4882a593Smuzhiyun}
6365*4882a593Smuzhiyun
6366*4882a593SmuzhiyunEOF
6367*4882a593Smuzhiyun	    case $host_os in
6368*4882a593Smuzhiyun	      mingw*)
6369*4882a593Smuzhiyun		cat <<"EOF"
6370*4882a593Smuzhiyun
6371*4882a593Smuzhiyun/* Prepares an argument vector before calling spawn().
6372*4882a593Smuzhiyun   Note that spawn() does not by itself call the command interpreter
6373*4882a593Smuzhiyun     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6374*4882a593Smuzhiyun      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6375*4882a593Smuzhiyun         GetVersionEx(&v);
6376*4882a593Smuzhiyun         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6377*4882a593Smuzhiyun      }) ? "cmd.exe" : "command.com").
6378*4882a593Smuzhiyun   Instead it simply concatenates the arguments, separated by ' ', and calls
6379*4882a593Smuzhiyun   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6380*4882a593Smuzhiyun   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6381*4882a593Smuzhiyun   special way:
6382*4882a593Smuzhiyun   - Space and tab are interpreted as delimiters. They are not treated as
6383*4882a593Smuzhiyun     delimiters if they are surrounded by double quotes: "...".
6384*4882a593Smuzhiyun   - Unescaped double quotes are removed from the input. Their only effect is
6385*4882a593Smuzhiyun     that within double quotes, space and tab are treated like normal
6386*4882a593Smuzhiyun     characters.
6387*4882a593Smuzhiyun   - Backslashes not followed by double quotes are not special.
6388*4882a593Smuzhiyun   - But 2*n+1 backslashes followed by a double quote become
6389*4882a593Smuzhiyun     n backslashes followed by a double quote (n >= 0):
6390*4882a593Smuzhiyun       \" -> "
6391*4882a593Smuzhiyun       \\\" -> \"
6392*4882a593Smuzhiyun       \\\\\" -> \\"
6393*4882a593Smuzhiyun */
6394*4882a593Smuzhiyun#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"
6395*4882a593Smuzhiyun#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"
6396*4882a593Smuzhiyunchar **
6397*4882a593Smuzhiyunprepare_spawn (char **argv)
6398*4882a593Smuzhiyun{
6399*4882a593Smuzhiyun  size_t argc;
6400*4882a593Smuzhiyun  char **new_argv;
6401*4882a593Smuzhiyun  size_t i;
6402*4882a593Smuzhiyun
6403*4882a593Smuzhiyun  /* Count number of arguments.  */
6404*4882a593Smuzhiyun  for (argc = 0; argv[argc] != NULL; argc++)
6405*4882a593Smuzhiyun    ;
6406*4882a593Smuzhiyun
6407*4882a593Smuzhiyun  /* Allocate new argument vector.  */
6408*4882a593Smuzhiyun  new_argv = XMALLOC (char *, argc + 1);
6409*4882a593Smuzhiyun
6410*4882a593Smuzhiyun  /* Put quoted arguments into the new argument vector.  */
6411*4882a593Smuzhiyun  for (i = 0; i < argc; i++)
6412*4882a593Smuzhiyun    {
6413*4882a593Smuzhiyun      const char *string = argv[i];
6414*4882a593Smuzhiyun
6415*4882a593Smuzhiyun      if (string[0] == '\0')
6416*4882a593Smuzhiyun	new_argv[i] = xstrdup ("\"\"");
6417*4882a593Smuzhiyun      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6418*4882a593Smuzhiyun	{
6419*4882a593Smuzhiyun	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6420*4882a593Smuzhiyun	  size_t length;
6421*4882a593Smuzhiyun	  unsigned int backslashes;
6422*4882a593Smuzhiyun	  const char *s;
6423*4882a593Smuzhiyun	  char *quoted_string;
6424*4882a593Smuzhiyun	  char *p;
6425*4882a593Smuzhiyun
6426*4882a593Smuzhiyun	  length = 0;
6427*4882a593Smuzhiyun	  backslashes = 0;
6428*4882a593Smuzhiyun	  if (quote_around)
6429*4882a593Smuzhiyun	    length++;
6430*4882a593Smuzhiyun	  for (s = string; *s != '\0'; s++)
6431*4882a593Smuzhiyun	    {
6432*4882a593Smuzhiyun	      char c = *s;
6433*4882a593Smuzhiyun	      if (c == '"')
6434*4882a593Smuzhiyun		length += backslashes + 1;
6435*4882a593Smuzhiyun	      length++;
6436*4882a593Smuzhiyun	      if (c == '\\')
6437*4882a593Smuzhiyun		backslashes++;
6438*4882a593Smuzhiyun	      else
6439*4882a593Smuzhiyun		backslashes = 0;
6440*4882a593Smuzhiyun	    }
6441*4882a593Smuzhiyun	  if (quote_around)
6442*4882a593Smuzhiyun	    length += backslashes + 1;
6443*4882a593Smuzhiyun
6444*4882a593Smuzhiyun	  quoted_string = XMALLOC (char, length + 1);
6445*4882a593Smuzhiyun
6446*4882a593Smuzhiyun	  p = quoted_string;
6447*4882a593Smuzhiyun	  backslashes = 0;
6448*4882a593Smuzhiyun	  if (quote_around)
6449*4882a593Smuzhiyun	    *p++ = '"';
6450*4882a593Smuzhiyun	  for (s = string; *s != '\0'; s++)
6451*4882a593Smuzhiyun	    {
6452*4882a593Smuzhiyun	      char c = *s;
6453*4882a593Smuzhiyun	      if (c == '"')
6454*4882a593Smuzhiyun		{
6455*4882a593Smuzhiyun		  unsigned int j;
6456*4882a593Smuzhiyun		  for (j = backslashes + 1; j > 0; j--)
6457*4882a593Smuzhiyun		    *p++ = '\\';
6458*4882a593Smuzhiyun		}
6459*4882a593Smuzhiyun	      *p++ = c;
6460*4882a593Smuzhiyun	      if (c == '\\')
6461*4882a593Smuzhiyun		backslashes++;
6462*4882a593Smuzhiyun	      else
6463*4882a593Smuzhiyun		backslashes = 0;
6464*4882a593Smuzhiyun	    }
6465*4882a593Smuzhiyun	  if (quote_around)
6466*4882a593Smuzhiyun	    {
6467*4882a593Smuzhiyun	      unsigned int j;
6468*4882a593Smuzhiyun	      for (j = backslashes; j > 0; j--)
6469*4882a593Smuzhiyun		*p++ = '\\';
6470*4882a593Smuzhiyun	      *p++ = '"';
6471*4882a593Smuzhiyun	    }
6472*4882a593Smuzhiyun	  *p = '\0';
6473*4882a593Smuzhiyun
6474*4882a593Smuzhiyun	  new_argv[i] = quoted_string;
6475*4882a593Smuzhiyun	}
6476*4882a593Smuzhiyun      else
6477*4882a593Smuzhiyun	new_argv[i] = (char *) string;
6478*4882a593Smuzhiyun    }
6479*4882a593Smuzhiyun  new_argv[argc] = NULL;
6480*4882a593Smuzhiyun
6481*4882a593Smuzhiyun  return new_argv;
6482*4882a593Smuzhiyun}
6483*4882a593SmuzhiyunEOF
6484*4882a593Smuzhiyun		;;
6485*4882a593Smuzhiyun	    esac
6486*4882a593Smuzhiyun
6487*4882a593Smuzhiyun            cat <<"EOF"
6488*4882a593Smuzhiyunvoid lt_dump_script (FILE* f)
6489*4882a593Smuzhiyun{
6490*4882a593SmuzhiyunEOF
6491*4882a593Smuzhiyun	    func_emit_wrapper yes |
6492*4882a593Smuzhiyun	      $SED -n -e '
6493*4882a593Smuzhiyuns/^\(.\{79\}\)\(..*\)/\1\
6494*4882a593Smuzhiyun\2/
6495*4882a593Smuzhiyunh
6496*4882a593Smuzhiyuns/\([\\"]\)/\\\1/g
6497*4882a593Smuzhiyuns/$/\\n/
6498*4882a593Smuzhiyuns/\([^\n]*\).*/  fputs ("\1", f);/p
6499*4882a593Smuzhiyung
6500*4882a593SmuzhiyunD'
6501*4882a593Smuzhiyun            cat <<"EOF"
6502*4882a593Smuzhiyun}
6503*4882a593SmuzhiyunEOF
6504*4882a593Smuzhiyun}
6505*4882a593Smuzhiyun# end: func_emit_cwrapperexe_src
6506*4882a593Smuzhiyun
6507*4882a593Smuzhiyun# func_win32_import_lib_p ARG
6508*4882a593Smuzhiyun# True if ARG is an import lib, as indicated by $file_magic_cmd
6509*4882a593Smuzhiyunfunc_win32_import_lib_p ()
6510*4882a593Smuzhiyun{
6511*4882a593Smuzhiyun    $debug_cmd
6512*4882a593Smuzhiyun
6513*4882a593Smuzhiyun    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6514*4882a593Smuzhiyun    *import*) : ;;
6515*4882a593Smuzhiyun    *) false ;;
6516*4882a593Smuzhiyun    esac
6517*4882a593Smuzhiyun}
6518*4882a593Smuzhiyun
6519*4882a593Smuzhiyun# func_suncc_cstd_abi
6520*4882a593Smuzhiyun# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6521*4882a593Smuzhiyun# Several compiler flags select an ABI that is incompatible with the
6522*4882a593Smuzhiyun# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6523*4882a593Smuzhiyunfunc_suncc_cstd_abi ()
6524*4882a593Smuzhiyun{
6525*4882a593Smuzhiyun    $debug_cmd
6526*4882a593Smuzhiyun
6527*4882a593Smuzhiyun    case " $compile_command " in
6528*4882a593Smuzhiyun    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6529*4882a593Smuzhiyun      suncc_use_cstd_abi=no
6530*4882a593Smuzhiyun      ;;
6531*4882a593Smuzhiyun    *)
6532*4882a593Smuzhiyun      suncc_use_cstd_abi=yes
6533*4882a593Smuzhiyun      ;;
6534*4882a593Smuzhiyun    esac
6535*4882a593Smuzhiyun}
6536*4882a593Smuzhiyun
6537*4882a593Smuzhiyun# func_mode_link arg...
6538*4882a593Smuzhiyunfunc_mode_link ()
6539*4882a593Smuzhiyun{
6540*4882a593Smuzhiyun    $debug_cmd
6541*4882a593Smuzhiyun
6542*4882a593Smuzhiyun    case $host in
6543*4882a593Smuzhiyun    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6544*4882a593Smuzhiyun      # It is impossible to link a dll without this setting, and
6545*4882a593Smuzhiyun      # we shouldn't force the makefile maintainer to figure out
6546*4882a593Smuzhiyun      # what system we are compiling for in order to pass an extra
6547*4882a593Smuzhiyun      # flag for every libtool invocation.
6548*4882a593Smuzhiyun      # allow_undefined=no
6549*4882a593Smuzhiyun
6550*4882a593Smuzhiyun      # FIXME: Unfortunately, there are problems with the above when trying
6551*4882a593Smuzhiyun      # to make a dll that has undefined symbols, in which case not
6552*4882a593Smuzhiyun      # even a static library is built.  For now, we need to specify
6553*4882a593Smuzhiyun      # -no-undefined on the libtool link line when we can be certain
6554*4882a593Smuzhiyun      # that all symbols are satisfied, otherwise we get a static library.
6555*4882a593Smuzhiyun      allow_undefined=yes
6556*4882a593Smuzhiyun      ;;
6557*4882a593Smuzhiyun    *)
6558*4882a593Smuzhiyun      allow_undefined=yes
6559*4882a593Smuzhiyun      ;;
6560*4882a593Smuzhiyun    esac
6561*4882a593Smuzhiyun    libtool_args=$nonopt
6562*4882a593Smuzhiyun    base_compile="$nonopt $@"
6563*4882a593Smuzhiyun    compile_command=$nonopt
6564*4882a593Smuzhiyun    finalize_command=$nonopt
6565*4882a593Smuzhiyun
6566*4882a593Smuzhiyun    compile_rpath=
6567*4882a593Smuzhiyun    finalize_rpath=
6568*4882a593Smuzhiyun    compile_shlibpath=
6569*4882a593Smuzhiyun    finalize_shlibpath=
6570*4882a593Smuzhiyun    convenience=
6571*4882a593Smuzhiyun    old_convenience=
6572*4882a593Smuzhiyun    deplibs=
6573*4882a593Smuzhiyun    old_deplibs=
6574*4882a593Smuzhiyun    compiler_flags=
6575*4882a593Smuzhiyun    linker_flags=
6576*4882a593Smuzhiyun    dllsearchpath=
6577*4882a593Smuzhiyun    lib_search_path=`pwd`
6578*4882a593Smuzhiyun    inst_prefix_dir=
6579*4882a593Smuzhiyun    new_inherited_linker_flags=
6580*4882a593Smuzhiyun
6581*4882a593Smuzhiyun    avoid_version=no
6582*4882a593Smuzhiyun    bindir=
6583*4882a593Smuzhiyun    dlfiles=
6584*4882a593Smuzhiyun    dlprefiles=
6585*4882a593Smuzhiyun    dlself=no
6586*4882a593Smuzhiyun    export_dynamic=no
6587*4882a593Smuzhiyun    export_symbols=
6588*4882a593Smuzhiyun    export_symbols_regex=
6589*4882a593Smuzhiyun    generated=
6590*4882a593Smuzhiyun    libobjs=
6591*4882a593Smuzhiyun    ltlibs=
6592*4882a593Smuzhiyun    module=no
6593*4882a593Smuzhiyun    no_install=no
6594*4882a593Smuzhiyun    objs=
6595*4882a593Smuzhiyun    os2dllname=
6596*4882a593Smuzhiyun    non_pic_objects=
6597*4882a593Smuzhiyun    precious_files_regex=
6598*4882a593Smuzhiyun    prefer_static_libs=no
6599*4882a593Smuzhiyun    preload=false
6600*4882a593Smuzhiyun    prev=
6601*4882a593Smuzhiyun    prevarg=
6602*4882a593Smuzhiyun    release=
6603*4882a593Smuzhiyun    rpath=
6604*4882a593Smuzhiyun    xrpath=
6605*4882a593Smuzhiyun    perm_rpath=
6606*4882a593Smuzhiyun    temp_rpath=
6607*4882a593Smuzhiyun    thread_safe=no
6608*4882a593Smuzhiyun    vinfo=
6609*4882a593Smuzhiyun    vinfo_number=no
6610*4882a593Smuzhiyun    weak_libs=
6611*4882a593Smuzhiyun    single_module=$wl-single_module
6612*4882a593Smuzhiyun    func_infer_tag $base_compile
6613*4882a593Smuzhiyun
6614*4882a593Smuzhiyun    # We need to know -static, to get the right output filenames.
6615*4882a593Smuzhiyun    for arg
6616*4882a593Smuzhiyun    do
6617*4882a593Smuzhiyun      case $arg in
6618*4882a593Smuzhiyun      -shared)
6619*4882a593Smuzhiyun	test yes != "$build_libtool_libs" \
6620*4882a593Smuzhiyun	  && func_fatal_configuration "cannot build a shared library"
6621*4882a593Smuzhiyun	build_old_libs=no
6622*4882a593Smuzhiyun	break
6623*4882a593Smuzhiyun	;;
6624*4882a593Smuzhiyun      -all-static | -static | -static-libtool-libs)
6625*4882a593Smuzhiyun	case $arg in
6626*4882a593Smuzhiyun	-all-static)
6627*4882a593Smuzhiyun	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6628*4882a593Smuzhiyun	    func_warning "complete static linking is impossible in this configuration"
6629*4882a593Smuzhiyun	  fi
6630*4882a593Smuzhiyun	  if test -n "$link_static_flag"; then
6631*4882a593Smuzhiyun	    dlopen_self=$dlopen_self_static
6632*4882a593Smuzhiyun	  fi
6633*4882a593Smuzhiyun	  prefer_static_libs=yes
6634*4882a593Smuzhiyun	  ;;
6635*4882a593Smuzhiyun	-static)
6636*4882a593Smuzhiyun	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6637*4882a593Smuzhiyun	    dlopen_self=$dlopen_self_static
6638*4882a593Smuzhiyun	  fi
6639*4882a593Smuzhiyun	  prefer_static_libs=built
6640*4882a593Smuzhiyun	  ;;
6641*4882a593Smuzhiyun	-static-libtool-libs)
6642*4882a593Smuzhiyun	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6643*4882a593Smuzhiyun	    dlopen_self=$dlopen_self_static
6644*4882a593Smuzhiyun	  fi
6645*4882a593Smuzhiyun	  prefer_static_libs=yes
6646*4882a593Smuzhiyun	  ;;
6647*4882a593Smuzhiyun	esac
6648*4882a593Smuzhiyun	build_libtool_libs=no
6649*4882a593Smuzhiyun	build_old_libs=yes
6650*4882a593Smuzhiyun	break
6651*4882a593Smuzhiyun	;;
6652*4882a593Smuzhiyun      esac
6653*4882a593Smuzhiyun    done
6654*4882a593Smuzhiyun
6655*4882a593Smuzhiyun    # See if our shared archives depend on static archives.
6656*4882a593Smuzhiyun    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6657*4882a593Smuzhiyun
6658*4882a593Smuzhiyun    # Go through the arguments, transforming them on the way.
6659*4882a593Smuzhiyun    while test "$#" -gt 0; do
6660*4882a593Smuzhiyun      arg=$1
6661*4882a593Smuzhiyun      shift
6662*4882a593Smuzhiyun      func_quote_for_eval "$arg"
6663*4882a593Smuzhiyun      qarg=$func_quote_for_eval_unquoted_result
6664*4882a593Smuzhiyun      func_append libtool_args " $func_quote_for_eval_result"
6665*4882a593Smuzhiyun
6666*4882a593Smuzhiyun      # If the previous option needs an argument, assign it.
6667*4882a593Smuzhiyun      if test -n "$prev"; then
6668*4882a593Smuzhiyun	case $prev in
6669*4882a593Smuzhiyun	output)
6670*4882a593Smuzhiyun	  func_append compile_command " @OUTPUT@"
6671*4882a593Smuzhiyun	  func_append finalize_command " @OUTPUT@"
6672*4882a593Smuzhiyun	  ;;
6673*4882a593Smuzhiyun	esac
6674*4882a593Smuzhiyun
6675*4882a593Smuzhiyun	case $prev in
6676*4882a593Smuzhiyun	bindir)
6677*4882a593Smuzhiyun	  bindir=$arg
6678*4882a593Smuzhiyun	  prev=
6679*4882a593Smuzhiyun	  continue
6680*4882a593Smuzhiyun	  ;;
6681*4882a593Smuzhiyun	dlfiles|dlprefiles)
6682*4882a593Smuzhiyun	  $preload || {
6683*4882a593Smuzhiyun	    # Add the symbol object into the linking commands.
6684*4882a593Smuzhiyun	    func_append compile_command " @SYMFILE@"
6685*4882a593Smuzhiyun	    func_append finalize_command " @SYMFILE@"
6686*4882a593Smuzhiyun	    preload=:
6687*4882a593Smuzhiyun	  }
6688*4882a593Smuzhiyun	  case $arg in
6689*4882a593Smuzhiyun	  *.la | *.lo) ;;  # We handle these cases below.
6690*4882a593Smuzhiyun	  force)
6691*4882a593Smuzhiyun	    if test no = "$dlself"; then
6692*4882a593Smuzhiyun	      dlself=needless
6693*4882a593Smuzhiyun	      export_dynamic=yes
6694*4882a593Smuzhiyun	    fi
6695*4882a593Smuzhiyun	    prev=
6696*4882a593Smuzhiyun	    continue
6697*4882a593Smuzhiyun	    ;;
6698*4882a593Smuzhiyun	  self)
6699*4882a593Smuzhiyun	    if test dlprefiles = "$prev"; then
6700*4882a593Smuzhiyun	      dlself=yes
6701*4882a593Smuzhiyun	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6702*4882a593Smuzhiyun	      dlself=yes
6703*4882a593Smuzhiyun	    else
6704*4882a593Smuzhiyun	      dlself=needless
6705*4882a593Smuzhiyun	      export_dynamic=yes
6706*4882a593Smuzhiyun	    fi
6707*4882a593Smuzhiyun	    prev=
6708*4882a593Smuzhiyun	    continue
6709*4882a593Smuzhiyun	    ;;
6710*4882a593Smuzhiyun	  *)
6711*4882a593Smuzhiyun	    if test dlfiles = "$prev"; then
6712*4882a593Smuzhiyun	      func_append dlfiles " $arg"
6713*4882a593Smuzhiyun	    else
6714*4882a593Smuzhiyun	      func_append dlprefiles " $arg"
6715*4882a593Smuzhiyun	    fi
6716*4882a593Smuzhiyun	    prev=
6717*4882a593Smuzhiyun	    continue
6718*4882a593Smuzhiyun	    ;;
6719*4882a593Smuzhiyun	  esac
6720*4882a593Smuzhiyun	  ;;
6721*4882a593Smuzhiyun	expsyms)
6722*4882a593Smuzhiyun	  export_symbols=$arg
6723*4882a593Smuzhiyun	  test -f "$arg" \
6724*4882a593Smuzhiyun	    || func_fatal_error "symbol file '$arg' does not exist"
6725*4882a593Smuzhiyun	  prev=
6726*4882a593Smuzhiyun	  continue
6727*4882a593Smuzhiyun	  ;;
6728*4882a593Smuzhiyun	expsyms_regex)
6729*4882a593Smuzhiyun	  export_symbols_regex=$arg
6730*4882a593Smuzhiyun	  prev=
6731*4882a593Smuzhiyun	  continue
6732*4882a593Smuzhiyun	  ;;
6733*4882a593Smuzhiyun	framework)
6734*4882a593Smuzhiyun	  case $host in
6735*4882a593Smuzhiyun	    *-*-darwin*)
6736*4882a593Smuzhiyun	      case "$deplibs " in
6737*4882a593Smuzhiyun		*" $qarg.ltframework "*) ;;
6738*4882a593Smuzhiyun		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6739*4882a593Smuzhiyun		   ;;
6740*4882a593Smuzhiyun	      esac
6741*4882a593Smuzhiyun	      ;;
6742*4882a593Smuzhiyun	  esac
6743*4882a593Smuzhiyun	  prev=
6744*4882a593Smuzhiyun	  continue
6745*4882a593Smuzhiyun	  ;;
6746*4882a593Smuzhiyun	inst_prefix)
6747*4882a593Smuzhiyun	  inst_prefix_dir=$arg
6748*4882a593Smuzhiyun	  prev=
6749*4882a593Smuzhiyun	  continue
6750*4882a593Smuzhiyun	  ;;
6751*4882a593Smuzhiyun	mllvm)
6752*4882a593Smuzhiyun	  # Clang does not use LLVM to link, so we can simply discard any
6753*4882a593Smuzhiyun	  # '-mllvm $arg' options when doing the link step.
6754*4882a593Smuzhiyun	  prev=
6755*4882a593Smuzhiyun	  continue
6756*4882a593Smuzhiyun	  ;;
6757*4882a593Smuzhiyun	objectlist)
6758*4882a593Smuzhiyun	  if test -f "$arg"; then
6759*4882a593Smuzhiyun	    save_arg=$arg
6760*4882a593Smuzhiyun	    moreargs=
6761*4882a593Smuzhiyun	    for fil in `cat "$save_arg"`
6762*4882a593Smuzhiyun	    do
6763*4882a593Smuzhiyun#	      func_append moreargs " $fil"
6764*4882a593Smuzhiyun	      arg=$fil
6765*4882a593Smuzhiyun	      # A libtool-controlled object.
6766*4882a593Smuzhiyun
6767*4882a593Smuzhiyun	      # Check to see that this really is a libtool object.
6768*4882a593Smuzhiyun	      if func_lalib_unsafe_p "$arg"; then
6769*4882a593Smuzhiyun		pic_object=
6770*4882a593Smuzhiyun		non_pic_object=
6771*4882a593Smuzhiyun
6772*4882a593Smuzhiyun		# Read the .lo file
6773*4882a593Smuzhiyun		func_source "$arg"
6774*4882a593Smuzhiyun
6775*4882a593Smuzhiyun		if test -z "$pic_object" ||
6776*4882a593Smuzhiyun		   test -z "$non_pic_object" ||
6777*4882a593Smuzhiyun		   test none = "$pic_object" &&
6778*4882a593Smuzhiyun		   test none = "$non_pic_object"; then
6779*4882a593Smuzhiyun		  func_fatal_error "cannot find name of object for '$arg'"
6780*4882a593Smuzhiyun		fi
6781*4882a593Smuzhiyun
6782*4882a593Smuzhiyun		# Extract subdirectory from the argument.
6783*4882a593Smuzhiyun		func_dirname "$arg" "/" ""
6784*4882a593Smuzhiyun		xdir=$func_dirname_result
6785*4882a593Smuzhiyun
6786*4882a593Smuzhiyun		if test none != "$pic_object"; then
6787*4882a593Smuzhiyun		  # Prepend the subdirectory the object is found in.
6788*4882a593Smuzhiyun		  pic_object=$xdir$pic_object
6789*4882a593Smuzhiyun
6790*4882a593Smuzhiyun		  if test dlfiles = "$prev"; then
6791*4882a593Smuzhiyun		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
6792*4882a593Smuzhiyun		      func_append dlfiles " $pic_object"
6793*4882a593Smuzhiyun		      prev=
6794*4882a593Smuzhiyun		      continue
6795*4882a593Smuzhiyun		    else
6796*4882a593Smuzhiyun		      # If libtool objects are unsupported, then we need to preload.
6797*4882a593Smuzhiyun		      prev=dlprefiles
6798*4882a593Smuzhiyun		    fi
6799*4882a593Smuzhiyun		  fi
6800*4882a593Smuzhiyun
6801*4882a593Smuzhiyun		  # CHECK ME:  I think I busted this.  -Ossama
6802*4882a593Smuzhiyun		  if test dlprefiles = "$prev"; then
6803*4882a593Smuzhiyun		    # Preload the old-style object.
6804*4882a593Smuzhiyun		    func_append dlprefiles " $pic_object"
6805*4882a593Smuzhiyun		    prev=
6806*4882a593Smuzhiyun		  fi
6807*4882a593Smuzhiyun
6808*4882a593Smuzhiyun		  # A PIC object.
6809*4882a593Smuzhiyun		  func_append libobjs " $pic_object"
6810*4882a593Smuzhiyun		  arg=$pic_object
6811*4882a593Smuzhiyun		fi
6812*4882a593Smuzhiyun
6813*4882a593Smuzhiyun		# Non-PIC object.
6814*4882a593Smuzhiyun		if test none != "$non_pic_object"; then
6815*4882a593Smuzhiyun		  # Prepend the subdirectory the object is found in.
6816*4882a593Smuzhiyun		  non_pic_object=$xdir$non_pic_object
6817*4882a593Smuzhiyun
6818*4882a593Smuzhiyun		  # A standard non-PIC object
6819*4882a593Smuzhiyun		  func_append non_pic_objects " $non_pic_object"
6820*4882a593Smuzhiyun		  if test -z "$pic_object" || test none = "$pic_object"; then
6821*4882a593Smuzhiyun		    arg=$non_pic_object
6822*4882a593Smuzhiyun		  fi
6823*4882a593Smuzhiyun		else
6824*4882a593Smuzhiyun		  # If the PIC object exists, use it instead.
6825*4882a593Smuzhiyun		  # $xdir was prepended to $pic_object above.
6826*4882a593Smuzhiyun		  non_pic_object=$pic_object
6827*4882a593Smuzhiyun		  func_append non_pic_objects " $non_pic_object"
6828*4882a593Smuzhiyun		fi
6829*4882a593Smuzhiyun	      else
6830*4882a593Smuzhiyun		# Only an error if not doing a dry-run.
6831*4882a593Smuzhiyun		if $opt_dry_run; then
6832*4882a593Smuzhiyun		  # Extract subdirectory from the argument.
6833*4882a593Smuzhiyun		  func_dirname "$arg" "/" ""
6834*4882a593Smuzhiyun		  xdir=$func_dirname_result
6835*4882a593Smuzhiyun
6836*4882a593Smuzhiyun		  func_lo2o "$arg"
6837*4882a593Smuzhiyun		  pic_object=$xdir$objdir/$func_lo2o_result
6838*4882a593Smuzhiyun		  non_pic_object=$xdir$func_lo2o_result
6839*4882a593Smuzhiyun		  func_append libobjs " $pic_object"
6840*4882a593Smuzhiyun		  func_append non_pic_objects " $non_pic_object"
6841*4882a593Smuzhiyun	        else
6842*4882a593Smuzhiyun		  func_fatal_error "'$arg' is not a valid libtool object"
6843*4882a593Smuzhiyun		fi
6844*4882a593Smuzhiyun	      fi
6845*4882a593Smuzhiyun	    done
6846*4882a593Smuzhiyun	  else
6847*4882a593Smuzhiyun	    func_fatal_error "link input file '$arg' does not exist"
6848*4882a593Smuzhiyun	  fi
6849*4882a593Smuzhiyun	  arg=$save_arg
6850*4882a593Smuzhiyun	  prev=
6851*4882a593Smuzhiyun	  continue
6852*4882a593Smuzhiyun	  ;;
6853*4882a593Smuzhiyun	os2dllname)
6854*4882a593Smuzhiyun	  os2dllname=$arg
6855*4882a593Smuzhiyun	  prev=
6856*4882a593Smuzhiyun	  continue
6857*4882a593Smuzhiyun	  ;;
6858*4882a593Smuzhiyun	precious_regex)
6859*4882a593Smuzhiyun	  precious_files_regex=$arg
6860*4882a593Smuzhiyun	  prev=
6861*4882a593Smuzhiyun	  continue
6862*4882a593Smuzhiyun	  ;;
6863*4882a593Smuzhiyun	release)
6864*4882a593Smuzhiyun	  release=-$arg
6865*4882a593Smuzhiyun	  prev=
6866*4882a593Smuzhiyun	  continue
6867*4882a593Smuzhiyun	  ;;
6868*4882a593Smuzhiyun	rpath | xrpath)
6869*4882a593Smuzhiyun	  # We need an absolute path.
6870*4882a593Smuzhiyun	  case $arg in
6871*4882a593Smuzhiyun	  [\\/]* | [A-Za-z]:[\\/]*) ;;
6872*4882a593Smuzhiyun	  *)
6873*4882a593Smuzhiyun	    func_fatal_error "only absolute run-paths are allowed"
6874*4882a593Smuzhiyun	    ;;
6875*4882a593Smuzhiyun	  esac
6876*4882a593Smuzhiyun	  if test rpath = "$prev"; then
6877*4882a593Smuzhiyun	    case "$rpath " in
6878*4882a593Smuzhiyun	    *" $arg "*) ;;
6879*4882a593Smuzhiyun	    *) func_append rpath " $arg" ;;
6880*4882a593Smuzhiyun	    esac
6881*4882a593Smuzhiyun	  else
6882*4882a593Smuzhiyun	    case "$xrpath " in
6883*4882a593Smuzhiyun	    *" $arg "*) ;;
6884*4882a593Smuzhiyun	    *) func_append xrpath " $arg" ;;
6885*4882a593Smuzhiyun	    esac
6886*4882a593Smuzhiyun	  fi
6887*4882a593Smuzhiyun	  prev=
6888*4882a593Smuzhiyun	  continue
6889*4882a593Smuzhiyun	  ;;
6890*4882a593Smuzhiyun	shrext)
6891*4882a593Smuzhiyun	  shrext_cmds=$arg
6892*4882a593Smuzhiyun	  prev=
6893*4882a593Smuzhiyun	  continue
6894*4882a593Smuzhiyun	  ;;
6895*4882a593Smuzhiyun	weak)
6896*4882a593Smuzhiyun	  func_append weak_libs " $arg"
6897*4882a593Smuzhiyun	  prev=
6898*4882a593Smuzhiyun	  continue
6899*4882a593Smuzhiyun	  ;;
6900*4882a593Smuzhiyun	xcclinker)
6901*4882a593Smuzhiyun	  func_append linker_flags " $qarg"
6902*4882a593Smuzhiyun	  func_append compiler_flags " $qarg"
6903*4882a593Smuzhiyun	  prev=
6904*4882a593Smuzhiyun	  func_append compile_command " $qarg"
6905*4882a593Smuzhiyun	  func_append finalize_command " $qarg"
6906*4882a593Smuzhiyun	  continue
6907*4882a593Smuzhiyun	  ;;
6908*4882a593Smuzhiyun	xcompiler)
6909*4882a593Smuzhiyun	  func_append compiler_flags " $qarg"
6910*4882a593Smuzhiyun	  prev=
6911*4882a593Smuzhiyun	  func_append compile_command " $qarg"
6912*4882a593Smuzhiyun	  func_append finalize_command " $qarg"
6913*4882a593Smuzhiyun	  continue
6914*4882a593Smuzhiyun	  ;;
6915*4882a593Smuzhiyun	xlinker)
6916*4882a593Smuzhiyun	  func_append linker_flags " $qarg"
6917*4882a593Smuzhiyun	  func_append compiler_flags " $wl$qarg"
6918*4882a593Smuzhiyun	  prev=
6919*4882a593Smuzhiyun	  func_append compile_command " $wl$qarg"
6920*4882a593Smuzhiyun	  func_append finalize_command " $wl$qarg"
6921*4882a593Smuzhiyun	  continue
6922*4882a593Smuzhiyun	  ;;
6923*4882a593Smuzhiyun	*)
6924*4882a593Smuzhiyun	  eval "$prev=\"\$arg\""
6925*4882a593Smuzhiyun	  prev=
6926*4882a593Smuzhiyun	  continue
6927*4882a593Smuzhiyun	  ;;
6928*4882a593Smuzhiyun	esac
6929*4882a593Smuzhiyun      fi # test -n "$prev"
6930*4882a593Smuzhiyun
6931*4882a593Smuzhiyun      prevarg=$arg
6932*4882a593Smuzhiyun
6933*4882a593Smuzhiyun      case $arg in
6934*4882a593Smuzhiyun      -all-static)
6935*4882a593Smuzhiyun	if test -n "$link_static_flag"; then
6936*4882a593Smuzhiyun	  # See comment for -static flag below, for more details.
6937*4882a593Smuzhiyun	  func_append compile_command " $link_static_flag"
6938*4882a593Smuzhiyun	  func_append finalize_command " $link_static_flag"
6939*4882a593Smuzhiyun	fi
6940*4882a593Smuzhiyun	continue
6941*4882a593Smuzhiyun	;;
6942*4882a593Smuzhiyun
6943*4882a593Smuzhiyun      -allow-undefined)
6944*4882a593Smuzhiyun	# FIXME: remove this flag sometime in the future.
6945*4882a593Smuzhiyun	func_fatal_error "'-allow-undefined' must not be used because it is the default"
6946*4882a593Smuzhiyun	;;
6947*4882a593Smuzhiyun
6948*4882a593Smuzhiyun      -avoid-version)
6949*4882a593Smuzhiyun	avoid_version=yes
6950*4882a593Smuzhiyun	continue
6951*4882a593Smuzhiyun	;;
6952*4882a593Smuzhiyun
6953*4882a593Smuzhiyun      -bindir)
6954*4882a593Smuzhiyun	prev=bindir
6955*4882a593Smuzhiyun	continue
6956*4882a593Smuzhiyun	;;
6957*4882a593Smuzhiyun
6958*4882a593Smuzhiyun      -dlopen)
6959*4882a593Smuzhiyun	prev=dlfiles
6960*4882a593Smuzhiyun	continue
6961*4882a593Smuzhiyun	;;
6962*4882a593Smuzhiyun
6963*4882a593Smuzhiyun      -dlpreopen)
6964*4882a593Smuzhiyun	prev=dlprefiles
6965*4882a593Smuzhiyun	continue
6966*4882a593Smuzhiyun	;;
6967*4882a593Smuzhiyun
6968*4882a593Smuzhiyun      -export-dynamic)
6969*4882a593Smuzhiyun	export_dynamic=yes
6970*4882a593Smuzhiyun	continue
6971*4882a593Smuzhiyun	;;
6972*4882a593Smuzhiyun
6973*4882a593Smuzhiyun      -export-symbols | -export-symbols-regex)
6974*4882a593Smuzhiyun	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
6975*4882a593Smuzhiyun	  func_fatal_error "more than one -exported-symbols argument is not allowed"
6976*4882a593Smuzhiyun	fi
6977*4882a593Smuzhiyun	if test X-export-symbols = "X$arg"; then
6978*4882a593Smuzhiyun	  prev=expsyms
6979*4882a593Smuzhiyun	else
6980*4882a593Smuzhiyun	  prev=expsyms_regex
6981*4882a593Smuzhiyun	fi
6982*4882a593Smuzhiyun	continue
6983*4882a593Smuzhiyun	;;
6984*4882a593Smuzhiyun
6985*4882a593Smuzhiyun      -framework)
6986*4882a593Smuzhiyun	prev=framework
6987*4882a593Smuzhiyun	continue
6988*4882a593Smuzhiyun	;;
6989*4882a593Smuzhiyun
6990*4882a593Smuzhiyun      -inst-prefix-dir)
6991*4882a593Smuzhiyun	prev=inst_prefix
6992*4882a593Smuzhiyun	continue
6993*4882a593Smuzhiyun	;;
6994*4882a593Smuzhiyun
6995*4882a593Smuzhiyun      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
6996*4882a593Smuzhiyun      # so, if we see these flags be careful not to treat them like -L
6997*4882a593Smuzhiyun      -L[A-Z][A-Z]*:*)
6998*4882a593Smuzhiyun	case $with_gcc/$host in
6999*4882a593Smuzhiyun	no/*-*-irix* | /*-*-irix*)
7000*4882a593Smuzhiyun	  func_append compile_command " $arg"
7001*4882a593Smuzhiyun	  func_append finalize_command " $arg"
7002*4882a593Smuzhiyun	  ;;
7003*4882a593Smuzhiyun	esac
7004*4882a593Smuzhiyun	continue
7005*4882a593Smuzhiyun	;;
7006*4882a593Smuzhiyun
7007*4882a593Smuzhiyun      -L*)
7008*4882a593Smuzhiyun	func_stripname "-L" '' "$arg"
7009*4882a593Smuzhiyun	if test -z "$func_stripname_result"; then
7010*4882a593Smuzhiyun	  if test "$#" -gt 0; then
7011*4882a593Smuzhiyun	    func_fatal_error "require no space between '-L' and '$1'"
7012*4882a593Smuzhiyun	  else
7013*4882a593Smuzhiyun	    func_fatal_error "need path for '-L' option"
7014*4882a593Smuzhiyun	  fi
7015*4882a593Smuzhiyun	fi
7016*4882a593Smuzhiyun	func_resolve_sysroot "$func_stripname_result"
7017*4882a593Smuzhiyun	dir=$func_resolve_sysroot_result
7018*4882a593Smuzhiyun	# We need an absolute path.
7019*4882a593Smuzhiyun	case $dir in
7020*4882a593Smuzhiyun	[\\/]* | [A-Za-z]:[\\/]*) ;;
7021*4882a593Smuzhiyun	*)
7022*4882a593Smuzhiyun	  absdir=`cd "$dir" && pwd`
7023*4882a593Smuzhiyun	  test -z "$absdir" && \
7024*4882a593Smuzhiyun	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7025*4882a593Smuzhiyun	  dir=$absdir
7026*4882a593Smuzhiyun	  ;;
7027*4882a593Smuzhiyun	esac
7028*4882a593Smuzhiyun	case "$deplibs " in
7029*4882a593Smuzhiyun	*" -L$dir "* | *" $arg "*)
7030*4882a593Smuzhiyun	  # Will only happen for absolute or sysroot arguments
7031*4882a593Smuzhiyun	  ;;
7032*4882a593Smuzhiyun	*)
7033*4882a593Smuzhiyun	  # Preserve sysroot, but never include relative directories
7034*4882a593Smuzhiyun	  case $dir in
7035*4882a593Smuzhiyun	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7036*4882a593Smuzhiyun	    *) func_append deplibs " -L$dir" ;;
7037*4882a593Smuzhiyun	  esac
7038*4882a593Smuzhiyun	  func_append lib_search_path " $dir"
7039*4882a593Smuzhiyun	  ;;
7040*4882a593Smuzhiyun	esac
7041*4882a593Smuzhiyun	case $host in
7042*4882a593Smuzhiyun	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7043*4882a593Smuzhiyun	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7044*4882a593Smuzhiyun	  case :$dllsearchpath: in
7045*4882a593Smuzhiyun	  *":$dir:"*) ;;
7046*4882a593Smuzhiyun	  ::) dllsearchpath=$dir;;
7047*4882a593Smuzhiyun	  *) func_append dllsearchpath ":$dir";;
7048*4882a593Smuzhiyun	  esac
7049*4882a593Smuzhiyun	  case :$dllsearchpath: in
7050*4882a593Smuzhiyun	  *":$testbindir:"*) ;;
7051*4882a593Smuzhiyun	  ::) dllsearchpath=$testbindir;;
7052*4882a593Smuzhiyun	  *) func_append dllsearchpath ":$testbindir";;
7053*4882a593Smuzhiyun	  esac
7054*4882a593Smuzhiyun	  ;;
7055*4882a593Smuzhiyun	esac
7056*4882a593Smuzhiyun	continue
7057*4882a593Smuzhiyun	;;
7058*4882a593Smuzhiyun
7059*4882a593Smuzhiyun      -l*)
7060*4882a593Smuzhiyun	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7061*4882a593Smuzhiyun	  case $host in
7062*4882a593Smuzhiyun	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7063*4882a593Smuzhiyun	    # These systems don't actually have a C or math library (as such)
7064*4882a593Smuzhiyun	    continue
7065*4882a593Smuzhiyun	    ;;
7066*4882a593Smuzhiyun	  *-*-os2*)
7067*4882a593Smuzhiyun	    # These systems don't actually have a C library (as such)
7068*4882a593Smuzhiyun	    test X-lc = "X$arg" && continue
7069*4882a593Smuzhiyun	    ;;
7070*4882a593Smuzhiyun	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
7071*4882a593Smuzhiyun	    # Do not include libc due to us having libc/libc_r.
7072*4882a593Smuzhiyun	    test X-lc = "X$arg" && continue
7073*4882a593Smuzhiyun	    ;;
7074*4882a593Smuzhiyun	  *-*-rhapsody* | *-*-darwin1.[012])
7075*4882a593Smuzhiyun	    # Rhapsody C and math libraries are in the System framework
7076*4882a593Smuzhiyun	    func_append deplibs " System.ltframework"
7077*4882a593Smuzhiyun	    continue
7078*4882a593Smuzhiyun	    ;;
7079*4882a593Smuzhiyun	  *-*-sco3.2v5* | *-*-sco5v6*)
7080*4882a593Smuzhiyun	    # Causes problems with __ctype
7081*4882a593Smuzhiyun	    test X-lc = "X$arg" && continue
7082*4882a593Smuzhiyun	    ;;
7083*4882a593Smuzhiyun	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7084*4882a593Smuzhiyun	    # Compiler inserts libc in the correct place for threads to work
7085*4882a593Smuzhiyun	    test X-lc = "X$arg" && continue
7086*4882a593Smuzhiyun	    ;;
7087*4882a593Smuzhiyun	  esac
7088*4882a593Smuzhiyun	elif test X-lc_r = "X$arg"; then
7089*4882a593Smuzhiyun	 case $host in
7090*4882a593Smuzhiyun	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
7091*4882a593Smuzhiyun	   # Do not include libc_r directly, use -pthread flag.
7092*4882a593Smuzhiyun	   continue
7093*4882a593Smuzhiyun	   ;;
7094*4882a593Smuzhiyun	 esac
7095*4882a593Smuzhiyun	fi
7096*4882a593Smuzhiyun	func_append deplibs " $arg"
7097*4882a593Smuzhiyun	continue
7098*4882a593Smuzhiyun	;;
7099*4882a593Smuzhiyun
7100*4882a593Smuzhiyun      -mllvm)
7101*4882a593Smuzhiyun	prev=mllvm
7102*4882a593Smuzhiyun	continue
7103*4882a593Smuzhiyun	;;
7104*4882a593Smuzhiyun
7105*4882a593Smuzhiyun      -module)
7106*4882a593Smuzhiyun	module=yes
7107*4882a593Smuzhiyun	continue
7108*4882a593Smuzhiyun	;;
7109*4882a593Smuzhiyun
7110*4882a593Smuzhiyun      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7111*4882a593Smuzhiyun      # classes, name mangling, and exception handling.
7112*4882a593Smuzhiyun      # Darwin uses the -arch flag to determine output architecture.
7113*4882a593Smuzhiyun      -model|-arch|-isysroot|--sysroot)
7114*4882a593Smuzhiyun	func_append compiler_flags " $arg"
7115*4882a593Smuzhiyun	func_append compile_command " $arg"
7116*4882a593Smuzhiyun	func_append finalize_command " $arg"
7117*4882a593Smuzhiyun	prev=xcompiler
7118*4882a593Smuzhiyun	continue
7119*4882a593Smuzhiyun	;;
7120*4882a593Smuzhiyun
7121*4882a593Smuzhiyun      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7122*4882a593Smuzhiyun      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7123*4882a593Smuzhiyun	func_append compiler_flags " $arg"
7124*4882a593Smuzhiyun	func_append compile_command " $arg"
7125*4882a593Smuzhiyun	func_append finalize_command " $arg"
7126*4882a593Smuzhiyun	case "$new_inherited_linker_flags " in
7127*4882a593Smuzhiyun	    *" $arg "*) ;;
7128*4882a593Smuzhiyun	    * ) func_append new_inherited_linker_flags " $arg" ;;
7129*4882a593Smuzhiyun	esac
7130*4882a593Smuzhiyun
7131*4882a593Smuzhiyun	# As we are forced to pass -nostdlib to g++ during linking, the option
7132*4882a593Smuzhiyun	# -pthread{,s} is not in effect;  add the -lpthread to $deplist
7133*4882a593Smuzhiyun	# explicitly to link correctly.
7134*4882a593Smuzhiyun	if test "$tagname" = CXX -a x"$with_gcc" = xyes; then
7135*4882a593Smuzhiyun	  case "$arg" in
7136*4882a593Smuzhiyun	    -pthread*) func_append deplibs " -lpthread" ;;
7137*4882a593Smuzhiyun	  esac
7138*4882a593Smuzhiyun	fi
7139*4882a593Smuzhiyun
7140*4882a593Smuzhiyun	continue
7141*4882a593Smuzhiyun	;;
7142*4882a593Smuzhiyun
7143*4882a593Smuzhiyun      -multi_module)
7144*4882a593Smuzhiyun	single_module=$wl-multi_module
7145*4882a593Smuzhiyun	continue
7146*4882a593Smuzhiyun	;;
7147*4882a593Smuzhiyun
7148*4882a593Smuzhiyun      -no-fast-install)
7149*4882a593Smuzhiyun	fast_install=no
7150*4882a593Smuzhiyun	continue
7151*4882a593Smuzhiyun	;;
7152*4882a593Smuzhiyun
7153*4882a593Smuzhiyun      -no-install)
7154*4882a593Smuzhiyun	case $host in
7155*4882a593Smuzhiyun	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7156*4882a593Smuzhiyun	  # The PATH hackery in wrapper scripts is required on Windows
7157*4882a593Smuzhiyun	  # and Darwin in order for the loader to find any dlls it needs.
7158*4882a593Smuzhiyun	  func_warning "'-no-install' is ignored for $host"
7159*4882a593Smuzhiyun	  func_warning "assuming '-no-fast-install' instead"
7160*4882a593Smuzhiyun	  fast_install=no
7161*4882a593Smuzhiyun	  ;;
7162*4882a593Smuzhiyun	*) no_install=yes ;;
7163*4882a593Smuzhiyun	esac
7164*4882a593Smuzhiyun	continue
7165*4882a593Smuzhiyun	;;
7166*4882a593Smuzhiyun
7167*4882a593Smuzhiyun      -no-undefined)
7168*4882a593Smuzhiyun	allow_undefined=no
7169*4882a593Smuzhiyun	continue
7170*4882a593Smuzhiyun	;;
7171*4882a593Smuzhiyun
7172*4882a593Smuzhiyun      -objectlist)
7173*4882a593Smuzhiyun	prev=objectlist
7174*4882a593Smuzhiyun	continue
7175*4882a593Smuzhiyun	;;
7176*4882a593Smuzhiyun
7177*4882a593Smuzhiyun      -os2dllname)
7178*4882a593Smuzhiyun	prev=os2dllname
7179*4882a593Smuzhiyun	continue
7180*4882a593Smuzhiyun	;;
7181*4882a593Smuzhiyun
7182*4882a593Smuzhiyun      -o) prev=output ;;
7183*4882a593Smuzhiyun
7184*4882a593Smuzhiyun      -precious-files-regex)
7185*4882a593Smuzhiyun	prev=precious_regex
7186*4882a593Smuzhiyun	continue
7187*4882a593Smuzhiyun	;;
7188*4882a593Smuzhiyun
7189*4882a593Smuzhiyun      -release)
7190*4882a593Smuzhiyun	prev=release
7191*4882a593Smuzhiyun	continue
7192*4882a593Smuzhiyun	;;
7193*4882a593Smuzhiyun
7194*4882a593Smuzhiyun      -rpath)
7195*4882a593Smuzhiyun	prev=rpath
7196*4882a593Smuzhiyun	continue
7197*4882a593Smuzhiyun	;;
7198*4882a593Smuzhiyun
7199*4882a593Smuzhiyun      -R)
7200*4882a593Smuzhiyun	prev=xrpath
7201*4882a593Smuzhiyun	continue
7202*4882a593Smuzhiyun	;;
7203*4882a593Smuzhiyun
7204*4882a593Smuzhiyun      -R*)
7205*4882a593Smuzhiyun	func_stripname '-R' '' "$arg"
7206*4882a593Smuzhiyun	dir=$func_stripname_result
7207*4882a593Smuzhiyun	# We need an absolute path.
7208*4882a593Smuzhiyun	case $dir in
7209*4882a593Smuzhiyun	[\\/]* | [A-Za-z]:[\\/]*) ;;
7210*4882a593Smuzhiyun	=*)
7211*4882a593Smuzhiyun	  func_stripname '=' '' "$dir"
7212*4882a593Smuzhiyun	  dir=$lt_sysroot$func_stripname_result
7213*4882a593Smuzhiyun	  ;;
7214*4882a593Smuzhiyun	*)
7215*4882a593Smuzhiyun	  func_fatal_error "only absolute run-paths are allowed"
7216*4882a593Smuzhiyun	  ;;
7217*4882a593Smuzhiyun	esac
7218*4882a593Smuzhiyun	case "$xrpath " in
7219*4882a593Smuzhiyun	*" $dir "*) ;;
7220*4882a593Smuzhiyun	*) func_append xrpath " $dir" ;;
7221*4882a593Smuzhiyun	esac
7222*4882a593Smuzhiyun	continue
7223*4882a593Smuzhiyun	;;
7224*4882a593Smuzhiyun
7225*4882a593Smuzhiyun      -shared)
7226*4882a593Smuzhiyun	# The effects of -shared are defined in a previous loop.
7227*4882a593Smuzhiyun	continue
7228*4882a593Smuzhiyun	;;
7229*4882a593Smuzhiyun
7230*4882a593Smuzhiyun      -shrext)
7231*4882a593Smuzhiyun	prev=shrext
7232*4882a593Smuzhiyun	continue
7233*4882a593Smuzhiyun	;;
7234*4882a593Smuzhiyun
7235*4882a593Smuzhiyun      -static | -static-libtool-libs)
7236*4882a593Smuzhiyun	# The effects of -static are defined in a previous loop.
7237*4882a593Smuzhiyun	# We used to do the same as -all-static on platforms that
7238*4882a593Smuzhiyun	# didn't have a PIC flag, but the assumption that the effects
7239*4882a593Smuzhiyun	# would be equivalent was wrong.  It would break on at least
7240*4882a593Smuzhiyun	# Digital Unix and AIX.
7241*4882a593Smuzhiyun	continue
7242*4882a593Smuzhiyun	;;
7243*4882a593Smuzhiyun
7244*4882a593Smuzhiyun      -thread-safe)
7245*4882a593Smuzhiyun	thread_safe=yes
7246*4882a593Smuzhiyun	continue
7247*4882a593Smuzhiyun	;;
7248*4882a593Smuzhiyun
7249*4882a593Smuzhiyun      -version-info)
7250*4882a593Smuzhiyun	prev=vinfo
7251*4882a593Smuzhiyun	continue
7252*4882a593Smuzhiyun	;;
7253*4882a593Smuzhiyun
7254*4882a593Smuzhiyun      -version-number)
7255*4882a593Smuzhiyun	prev=vinfo
7256*4882a593Smuzhiyun	vinfo_number=yes
7257*4882a593Smuzhiyun	continue
7258*4882a593Smuzhiyun	;;
7259*4882a593Smuzhiyun
7260*4882a593Smuzhiyun      -weak)
7261*4882a593Smuzhiyun        prev=weak
7262*4882a593Smuzhiyun	continue
7263*4882a593Smuzhiyun	;;
7264*4882a593Smuzhiyun
7265*4882a593Smuzhiyun      -Wc,*)
7266*4882a593Smuzhiyun	func_stripname '-Wc,' '' "$arg"
7267*4882a593Smuzhiyun	args=$func_stripname_result
7268*4882a593Smuzhiyun	arg=
7269*4882a593Smuzhiyun	save_ifs=$IFS; IFS=,
7270*4882a593Smuzhiyun	for flag in $args; do
7271*4882a593Smuzhiyun	  IFS=$save_ifs
7272*4882a593Smuzhiyun          func_quote_for_eval "$flag"
7273*4882a593Smuzhiyun	  func_append arg " $func_quote_for_eval_result"
7274*4882a593Smuzhiyun	  func_append compiler_flags " $func_quote_for_eval_result"
7275*4882a593Smuzhiyun	done
7276*4882a593Smuzhiyun	IFS=$save_ifs
7277*4882a593Smuzhiyun	func_stripname ' ' '' "$arg"
7278*4882a593Smuzhiyun	arg=$func_stripname_result
7279*4882a593Smuzhiyun	;;
7280*4882a593Smuzhiyun
7281*4882a593Smuzhiyun      -Wl,*)
7282*4882a593Smuzhiyun	func_stripname '-Wl,' '' "$arg"
7283*4882a593Smuzhiyun	args=$func_stripname_result
7284*4882a593Smuzhiyun	arg=
7285*4882a593Smuzhiyun	save_ifs=$IFS; IFS=,
7286*4882a593Smuzhiyun	for flag in $args; do
7287*4882a593Smuzhiyun	  IFS=$save_ifs
7288*4882a593Smuzhiyun          func_quote_for_eval "$flag"
7289*4882a593Smuzhiyun	  func_append arg " $wl$func_quote_for_eval_result"
7290*4882a593Smuzhiyun	  func_append compiler_flags " $wl$func_quote_for_eval_result"
7291*4882a593Smuzhiyun	  func_append linker_flags " $func_quote_for_eval_result"
7292*4882a593Smuzhiyun	done
7293*4882a593Smuzhiyun	IFS=$save_ifs
7294*4882a593Smuzhiyun	func_stripname ' ' '' "$arg"
7295*4882a593Smuzhiyun	arg=$func_stripname_result
7296*4882a593Smuzhiyun	;;
7297*4882a593Smuzhiyun
7298*4882a593Smuzhiyun      -Xcompiler)
7299*4882a593Smuzhiyun	prev=xcompiler
7300*4882a593Smuzhiyun	continue
7301*4882a593Smuzhiyun	;;
7302*4882a593Smuzhiyun
7303*4882a593Smuzhiyun      -Xlinker)
7304*4882a593Smuzhiyun	prev=xlinker
7305*4882a593Smuzhiyun	continue
7306*4882a593Smuzhiyun	;;
7307*4882a593Smuzhiyun
7308*4882a593Smuzhiyun      -XCClinker)
7309*4882a593Smuzhiyun	prev=xcclinker
7310*4882a593Smuzhiyun	continue
7311*4882a593Smuzhiyun	;;
7312*4882a593Smuzhiyun
7313*4882a593Smuzhiyun      # -msg_* for osf cc
7314*4882a593Smuzhiyun      -msg_*)
7315*4882a593Smuzhiyun	func_quote_for_eval "$arg"
7316*4882a593Smuzhiyun	arg=$func_quote_for_eval_result
7317*4882a593Smuzhiyun	;;
7318*4882a593Smuzhiyun
7319*4882a593Smuzhiyun      # Flags to be passed through unchanged, with rationale:
7320*4882a593Smuzhiyun      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7321*4882a593Smuzhiyun      # -r[0-9][0-9]*        specify processor for the SGI compiler
7322*4882a593Smuzhiyun      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7323*4882a593Smuzhiyun      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7324*4882a593Smuzhiyun      # -q*                  compiler args for the IBM compiler
7325*4882a593Smuzhiyun      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7326*4882a593Smuzhiyun      # -F/path              path to uninstalled frameworks, gcc on darwin
7327*4882a593Smuzhiyun      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7328*4882a593Smuzhiyun      # -fstack-protector*   stack protector flags for GCC
7329*4882a593Smuzhiyun      # @file                GCC response files
7330*4882a593Smuzhiyun      # -tp=*                Portland pgcc target processor selection
7331*4882a593Smuzhiyun      # --sysroot=*          for sysroot support
7332*4882a593Smuzhiyun      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7333*4882a593Smuzhiyun      # -specs=*             GCC specs files
7334*4882a593Smuzhiyun      # -stdlib=*            select c++ std lib with clang
7335*4882a593Smuzhiyun      # -fsanitize=*         Clang/GCC memory and address sanitizer
7336*4882a593Smuzhiyun      # -fuse-ld=*           Linker select flags for GCC
7337*4882a593Smuzhiyun      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7338*4882a593Smuzhiyun      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7339*4882a593Smuzhiyun      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7340*4882a593Smuzhiyun      -specs=*|-fsanitize=*|-fuse-ld=*)
7341*4882a593Smuzhiyun        func_quote_for_eval "$arg"
7342*4882a593Smuzhiyun	arg=$func_quote_for_eval_result
7343*4882a593Smuzhiyun        func_append compile_command " $arg"
7344*4882a593Smuzhiyun        func_append finalize_command " $arg"
7345*4882a593Smuzhiyun        func_append compiler_flags " $arg"
7346*4882a593Smuzhiyun        continue
7347*4882a593Smuzhiyun        ;;
7348*4882a593Smuzhiyun
7349*4882a593Smuzhiyun      -Z*)
7350*4882a593Smuzhiyun        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7351*4882a593Smuzhiyun          # OS/2 uses -Zxxx to specify OS/2-specific options
7352*4882a593Smuzhiyun	  compiler_flags="$compiler_flags $arg"
7353*4882a593Smuzhiyun	  func_append compile_command " $arg"
7354*4882a593Smuzhiyun	  func_append finalize_command " $arg"
7355*4882a593Smuzhiyun	  case $arg in
7356*4882a593Smuzhiyun	  -Zlinker | -Zstack)
7357*4882a593Smuzhiyun	    prev=xcompiler
7358*4882a593Smuzhiyun	    ;;
7359*4882a593Smuzhiyun	  esac
7360*4882a593Smuzhiyun	  continue
7361*4882a593Smuzhiyun        else
7362*4882a593Smuzhiyun	  # Otherwise treat like 'Some other compiler flag' below
7363*4882a593Smuzhiyun	  func_quote_for_eval "$arg"
7364*4882a593Smuzhiyun	  arg=$func_quote_for_eval_result
7365*4882a593Smuzhiyun        fi
7366*4882a593Smuzhiyun	;;
7367*4882a593Smuzhiyun
7368*4882a593Smuzhiyun      # Some other compiler flag.
7369*4882a593Smuzhiyun      -* | +*)
7370*4882a593Smuzhiyun        func_quote_for_eval "$arg"
7371*4882a593Smuzhiyun	arg=$func_quote_for_eval_result
7372*4882a593Smuzhiyun	;;
7373*4882a593Smuzhiyun
7374*4882a593Smuzhiyun      *.$objext)
7375*4882a593Smuzhiyun	# A standard object.
7376*4882a593Smuzhiyun	func_append objs " $arg"
7377*4882a593Smuzhiyun	;;
7378*4882a593Smuzhiyun
7379*4882a593Smuzhiyun      *.lo)
7380*4882a593Smuzhiyun	# A libtool-controlled object.
7381*4882a593Smuzhiyun
7382*4882a593Smuzhiyun	# Check to see that this really is a libtool object.
7383*4882a593Smuzhiyun	if func_lalib_unsafe_p "$arg"; then
7384*4882a593Smuzhiyun	  pic_object=
7385*4882a593Smuzhiyun	  non_pic_object=
7386*4882a593Smuzhiyun
7387*4882a593Smuzhiyun	  # Read the .lo file
7388*4882a593Smuzhiyun	  func_source "$arg"
7389*4882a593Smuzhiyun
7390*4882a593Smuzhiyun	  if test -z "$pic_object" ||
7391*4882a593Smuzhiyun	     test -z "$non_pic_object" ||
7392*4882a593Smuzhiyun	     test none = "$pic_object" &&
7393*4882a593Smuzhiyun	     test none = "$non_pic_object"; then
7394*4882a593Smuzhiyun	    func_fatal_error "cannot find name of object for '$arg'"
7395*4882a593Smuzhiyun	  fi
7396*4882a593Smuzhiyun
7397*4882a593Smuzhiyun	  # Extract subdirectory from the argument.
7398*4882a593Smuzhiyun	  func_dirname "$arg" "/" ""
7399*4882a593Smuzhiyun	  xdir=$func_dirname_result
7400*4882a593Smuzhiyun
7401*4882a593Smuzhiyun	  test none = "$pic_object" || {
7402*4882a593Smuzhiyun	    # Prepend the subdirectory the object is found in.
7403*4882a593Smuzhiyun	    pic_object=$xdir$pic_object
7404*4882a593Smuzhiyun
7405*4882a593Smuzhiyun	    if test dlfiles = "$prev"; then
7406*4882a593Smuzhiyun	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7407*4882a593Smuzhiyun		func_append dlfiles " $pic_object"
7408*4882a593Smuzhiyun		prev=
7409*4882a593Smuzhiyun		continue
7410*4882a593Smuzhiyun	      else
7411*4882a593Smuzhiyun		# If libtool objects are unsupported, then we need to preload.
7412*4882a593Smuzhiyun		prev=dlprefiles
7413*4882a593Smuzhiyun	      fi
7414*4882a593Smuzhiyun	    fi
7415*4882a593Smuzhiyun
7416*4882a593Smuzhiyun	    # CHECK ME:  I think I busted this.  -Ossama
7417*4882a593Smuzhiyun	    if test dlprefiles = "$prev"; then
7418*4882a593Smuzhiyun	      # Preload the old-style object.
7419*4882a593Smuzhiyun	      func_append dlprefiles " $pic_object"
7420*4882a593Smuzhiyun	      prev=
7421*4882a593Smuzhiyun	    fi
7422*4882a593Smuzhiyun
7423*4882a593Smuzhiyun	    # A PIC object.
7424*4882a593Smuzhiyun	    func_append libobjs " $pic_object"
7425*4882a593Smuzhiyun	    arg=$pic_object
7426*4882a593Smuzhiyun	  }
7427*4882a593Smuzhiyun
7428*4882a593Smuzhiyun	  # Non-PIC object.
7429*4882a593Smuzhiyun	  if test none != "$non_pic_object"; then
7430*4882a593Smuzhiyun	    # Prepend the subdirectory the object is found in.
7431*4882a593Smuzhiyun	    non_pic_object=$xdir$non_pic_object
7432*4882a593Smuzhiyun
7433*4882a593Smuzhiyun	    # A standard non-PIC object
7434*4882a593Smuzhiyun	    func_append non_pic_objects " $non_pic_object"
7435*4882a593Smuzhiyun	    if test -z "$pic_object" || test none = "$pic_object"; then
7436*4882a593Smuzhiyun	      arg=$non_pic_object
7437*4882a593Smuzhiyun	    fi
7438*4882a593Smuzhiyun	  else
7439*4882a593Smuzhiyun	    # If the PIC object exists, use it instead.
7440*4882a593Smuzhiyun	    # $xdir was prepended to $pic_object above.
7441*4882a593Smuzhiyun	    non_pic_object=$pic_object
7442*4882a593Smuzhiyun	    func_append non_pic_objects " $non_pic_object"
7443*4882a593Smuzhiyun	  fi
7444*4882a593Smuzhiyun	else
7445*4882a593Smuzhiyun	  # Only an error if not doing a dry-run.
7446*4882a593Smuzhiyun	  if $opt_dry_run; then
7447*4882a593Smuzhiyun	    # Extract subdirectory from the argument.
7448*4882a593Smuzhiyun	    func_dirname "$arg" "/" ""
7449*4882a593Smuzhiyun	    xdir=$func_dirname_result
7450*4882a593Smuzhiyun
7451*4882a593Smuzhiyun	    func_lo2o "$arg"
7452*4882a593Smuzhiyun	    pic_object=$xdir$objdir/$func_lo2o_result
7453*4882a593Smuzhiyun	    non_pic_object=$xdir$func_lo2o_result
7454*4882a593Smuzhiyun	    func_append libobjs " $pic_object"
7455*4882a593Smuzhiyun	    func_append non_pic_objects " $non_pic_object"
7456*4882a593Smuzhiyun	  else
7457*4882a593Smuzhiyun	    func_fatal_error "'$arg' is not a valid libtool object"
7458*4882a593Smuzhiyun	  fi
7459*4882a593Smuzhiyun	fi
7460*4882a593Smuzhiyun	;;
7461*4882a593Smuzhiyun
7462*4882a593Smuzhiyun      *.$libext)
7463*4882a593Smuzhiyun	# An archive.
7464*4882a593Smuzhiyun	func_append deplibs " $arg"
7465*4882a593Smuzhiyun	func_append old_deplibs " $arg"
7466*4882a593Smuzhiyun	continue
7467*4882a593Smuzhiyun	;;
7468*4882a593Smuzhiyun
7469*4882a593Smuzhiyun      *.la)
7470*4882a593Smuzhiyun	# A libtool-controlled library.
7471*4882a593Smuzhiyun
7472*4882a593Smuzhiyun	func_resolve_sysroot "$arg"
7473*4882a593Smuzhiyun	if test dlfiles = "$prev"; then
7474*4882a593Smuzhiyun	  # This library was specified with -dlopen.
7475*4882a593Smuzhiyun	  func_append dlfiles " $func_resolve_sysroot_result"
7476*4882a593Smuzhiyun	  prev=
7477*4882a593Smuzhiyun	elif test dlprefiles = "$prev"; then
7478*4882a593Smuzhiyun	  # The library was specified with -dlpreopen.
7479*4882a593Smuzhiyun	  func_append dlprefiles " $func_resolve_sysroot_result"
7480*4882a593Smuzhiyun	  prev=
7481*4882a593Smuzhiyun	else
7482*4882a593Smuzhiyun	  func_append deplibs " $func_resolve_sysroot_result"
7483*4882a593Smuzhiyun	fi
7484*4882a593Smuzhiyun	continue
7485*4882a593Smuzhiyun	;;
7486*4882a593Smuzhiyun
7487*4882a593Smuzhiyun      # Some other compiler argument.
7488*4882a593Smuzhiyun      *)
7489*4882a593Smuzhiyun	# Unknown arguments in both finalize_command and compile_command need
7490*4882a593Smuzhiyun	# to be aesthetically quoted because they are evaled later.
7491*4882a593Smuzhiyun	func_quote_for_eval "$arg"
7492*4882a593Smuzhiyun	arg=$func_quote_for_eval_result
7493*4882a593Smuzhiyun	;;
7494*4882a593Smuzhiyun      esac # arg
7495*4882a593Smuzhiyun
7496*4882a593Smuzhiyun      # Now actually substitute the argument into the commands.
7497*4882a593Smuzhiyun      if test -n "$arg"; then
7498*4882a593Smuzhiyun	func_append compile_command " $arg"
7499*4882a593Smuzhiyun	func_append finalize_command " $arg"
7500*4882a593Smuzhiyun      fi
7501*4882a593Smuzhiyun    done # argument parsing loop
7502*4882a593Smuzhiyun
7503*4882a593Smuzhiyun    test -n "$prev" && \
7504*4882a593Smuzhiyun      func_fatal_help "the '$prevarg' option requires an argument"
7505*4882a593Smuzhiyun
7506*4882a593Smuzhiyun    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7507*4882a593Smuzhiyun      eval arg=\"$export_dynamic_flag_spec\"
7508*4882a593Smuzhiyun      func_append compile_command " $arg"
7509*4882a593Smuzhiyun      func_append finalize_command " $arg"
7510*4882a593Smuzhiyun    fi
7511*4882a593Smuzhiyun
7512*4882a593Smuzhiyun    oldlibs=
7513*4882a593Smuzhiyun    # calculate the name of the file, without its directory
7514*4882a593Smuzhiyun    func_basename "$output"
7515*4882a593Smuzhiyun    outputname=$func_basename_result
7516*4882a593Smuzhiyun    libobjs_save=$libobjs
7517*4882a593Smuzhiyun
7518*4882a593Smuzhiyun    if test -n "$shlibpath_var"; then
7519*4882a593Smuzhiyun      # get the directories listed in $shlibpath_var
7520*4882a593Smuzhiyun      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7521*4882a593Smuzhiyun    else
7522*4882a593Smuzhiyun      shlib_search_path=
7523*4882a593Smuzhiyun    fi
7524*4882a593Smuzhiyun    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7525*4882a593Smuzhiyun    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7526*4882a593Smuzhiyun
7527*4882a593Smuzhiyun    # Definition is injected by LT_CONFIG during libtool generation.
7528*4882a593Smuzhiyun    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7529*4882a593Smuzhiyun
7530*4882a593Smuzhiyun    func_dirname "$output" "/" ""
7531*4882a593Smuzhiyun    output_objdir=$func_dirname_result$objdir
7532*4882a593Smuzhiyun    func_to_tool_file "$output_objdir/"
7533*4882a593Smuzhiyun    tool_output_objdir=$func_to_tool_file_result
7534*4882a593Smuzhiyun    # Create the object directory.
7535*4882a593Smuzhiyun    func_mkdir_p "$output_objdir"
7536*4882a593Smuzhiyun
7537*4882a593Smuzhiyun    # Determine the type of output
7538*4882a593Smuzhiyun    case $output in
7539*4882a593Smuzhiyun    "")
7540*4882a593Smuzhiyun      func_fatal_help "you must specify an output file"
7541*4882a593Smuzhiyun      ;;
7542*4882a593Smuzhiyun    *.$libext) linkmode=oldlib ;;
7543*4882a593Smuzhiyun    *.lo | *.$objext) linkmode=obj ;;
7544*4882a593Smuzhiyun    *.la) linkmode=lib ;;
7545*4882a593Smuzhiyun    *) linkmode=prog ;; # Anything else should be a program.
7546*4882a593Smuzhiyun    esac
7547*4882a593Smuzhiyun
7548*4882a593Smuzhiyun    specialdeplibs=
7549*4882a593Smuzhiyun
7550*4882a593Smuzhiyun    libs=
7551*4882a593Smuzhiyun    # Find all interdependent deplibs by searching for libraries
7552*4882a593Smuzhiyun    # that are linked more than once (e.g. -la -lb -la)
7553*4882a593Smuzhiyun    for deplib in $deplibs; do
7554*4882a593Smuzhiyun      if $opt_preserve_dup_deps; then
7555*4882a593Smuzhiyun	case "$libs " in
7556*4882a593Smuzhiyun	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7557*4882a593Smuzhiyun	esac
7558*4882a593Smuzhiyun      fi
7559*4882a593Smuzhiyun      func_append libs " $deplib"
7560*4882a593Smuzhiyun    done
7561*4882a593Smuzhiyun
7562*4882a593Smuzhiyun    if test lib = "$linkmode"; then
7563*4882a593Smuzhiyun      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7564*4882a593Smuzhiyun
7565*4882a593Smuzhiyun      # Compute libraries that are listed more than once in $predeps
7566*4882a593Smuzhiyun      # $postdeps and mark them as special (i.e., whose duplicates are
7567*4882a593Smuzhiyun      # not to be eliminated).
7568*4882a593Smuzhiyun      pre_post_deps=
7569*4882a593Smuzhiyun      if $opt_duplicate_compiler_generated_deps; then
7570*4882a593Smuzhiyun	for pre_post_dep in $predeps $postdeps; do
7571*4882a593Smuzhiyun	  case "$pre_post_deps " in
7572*4882a593Smuzhiyun	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7573*4882a593Smuzhiyun	  esac
7574*4882a593Smuzhiyun	  func_append pre_post_deps " $pre_post_dep"
7575*4882a593Smuzhiyun	done
7576*4882a593Smuzhiyun      fi
7577*4882a593Smuzhiyun      pre_post_deps=
7578*4882a593Smuzhiyun    fi
7579*4882a593Smuzhiyun
7580*4882a593Smuzhiyun    deplibs=
7581*4882a593Smuzhiyun    newdependency_libs=
7582*4882a593Smuzhiyun    newlib_search_path=
7583*4882a593Smuzhiyun    need_relink=no # whether we're linking any uninstalled libtool libraries
7584*4882a593Smuzhiyun    notinst_deplibs= # not-installed libtool libraries
7585*4882a593Smuzhiyun    notinst_path= # paths that contain not-installed libtool libraries
7586*4882a593Smuzhiyun
7587*4882a593Smuzhiyun    case $linkmode in
7588*4882a593Smuzhiyun    lib)
7589*4882a593Smuzhiyun	passes="conv dlpreopen link"
7590*4882a593Smuzhiyun	for file in $dlfiles $dlprefiles; do
7591*4882a593Smuzhiyun	  case $file in
7592*4882a593Smuzhiyun	  *.la) ;;
7593*4882a593Smuzhiyun	  *)
7594*4882a593Smuzhiyun	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7595*4882a593Smuzhiyun	    ;;
7596*4882a593Smuzhiyun	  esac
7597*4882a593Smuzhiyun	done
7598*4882a593Smuzhiyun	;;
7599*4882a593Smuzhiyun    prog)
7600*4882a593Smuzhiyun	compile_deplibs=
7601*4882a593Smuzhiyun	finalize_deplibs=
7602*4882a593Smuzhiyun	alldeplibs=false
7603*4882a593Smuzhiyun	newdlfiles=
7604*4882a593Smuzhiyun	newdlprefiles=
7605*4882a593Smuzhiyun	passes="conv scan dlopen dlpreopen link"
7606*4882a593Smuzhiyun	;;
7607*4882a593Smuzhiyun    *)  passes="conv"
7608*4882a593Smuzhiyun	;;
7609*4882a593Smuzhiyun    esac
7610*4882a593Smuzhiyun
7611*4882a593Smuzhiyun    for pass in $passes; do
7612*4882a593Smuzhiyun      # The preopen pass in lib mode reverses $deplibs; put it back here
7613*4882a593Smuzhiyun      # so that -L comes before libs that need it for instance...
7614*4882a593Smuzhiyun      if test lib,link = "$linkmode,$pass"; then
7615*4882a593Smuzhiyun	## FIXME: Find the place where the list is rebuilt in the wrong
7616*4882a593Smuzhiyun	##        order, and fix it there properly
7617*4882a593Smuzhiyun        tmp_deplibs=
7618*4882a593Smuzhiyun	for deplib in $deplibs; do
7619*4882a593Smuzhiyun	  tmp_deplibs="$deplib $tmp_deplibs"
7620*4882a593Smuzhiyun	done
7621*4882a593Smuzhiyun	deplibs=$tmp_deplibs
7622*4882a593Smuzhiyun      fi
7623*4882a593Smuzhiyun
7624*4882a593Smuzhiyun      if test lib,link = "$linkmode,$pass" ||
7625*4882a593Smuzhiyun	 test prog,scan = "$linkmode,$pass"; then
7626*4882a593Smuzhiyun	libs=$deplibs
7627*4882a593Smuzhiyun	deplibs=
7628*4882a593Smuzhiyun      fi
7629*4882a593Smuzhiyun      if test prog = "$linkmode"; then
7630*4882a593Smuzhiyun	case $pass in
7631*4882a593Smuzhiyun	dlopen) libs=$dlfiles ;;
7632*4882a593Smuzhiyun	dlpreopen) libs=$dlprefiles ;;
7633*4882a593Smuzhiyun	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7634*4882a593Smuzhiyun	esac
7635*4882a593Smuzhiyun      fi
7636*4882a593Smuzhiyun      if test lib,dlpreopen = "$linkmode,$pass"; then
7637*4882a593Smuzhiyun	# Collect and forward deplibs of preopened libtool libs
7638*4882a593Smuzhiyun	for lib in $dlprefiles; do
7639*4882a593Smuzhiyun	  # Ignore non-libtool-libs
7640*4882a593Smuzhiyun	  dependency_libs=
7641*4882a593Smuzhiyun	  func_resolve_sysroot "$lib"
7642*4882a593Smuzhiyun	  case $lib in
7643*4882a593Smuzhiyun	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7644*4882a593Smuzhiyun	  esac
7645*4882a593Smuzhiyun
7646*4882a593Smuzhiyun	  # Collect preopened libtool deplibs, except any this library
7647*4882a593Smuzhiyun	  # has declared as weak libs
7648*4882a593Smuzhiyun	  for deplib in $dependency_libs; do
7649*4882a593Smuzhiyun	    func_basename "$deplib"
7650*4882a593Smuzhiyun            deplib_base=$func_basename_result
7651*4882a593Smuzhiyun	    case " $weak_libs " in
7652*4882a593Smuzhiyun	    *" $deplib_base "*) ;;
7653*4882a593Smuzhiyun	    *) func_append deplibs " $deplib" ;;
7654*4882a593Smuzhiyun	    esac
7655*4882a593Smuzhiyun	  done
7656*4882a593Smuzhiyun	done
7657*4882a593Smuzhiyun	libs=$dlprefiles
7658*4882a593Smuzhiyun      fi
7659*4882a593Smuzhiyun      if test dlopen = "$pass"; then
7660*4882a593Smuzhiyun	# Collect dlpreopened libraries
7661*4882a593Smuzhiyun	save_deplibs=$deplibs
7662*4882a593Smuzhiyun	deplibs=
7663*4882a593Smuzhiyun      fi
7664*4882a593Smuzhiyun
7665*4882a593Smuzhiyun      for deplib in $libs; do
7666*4882a593Smuzhiyun	lib=
7667*4882a593Smuzhiyun	found=false
7668*4882a593Smuzhiyun	case $deplib in
7669*4882a593Smuzhiyun	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7670*4882a593Smuzhiyun        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7671*4882a593Smuzhiyun	  if test prog,link = "$linkmode,$pass"; then
7672*4882a593Smuzhiyun	    compile_deplibs="$deplib $compile_deplibs"
7673*4882a593Smuzhiyun	    finalize_deplibs="$deplib $finalize_deplibs"
7674*4882a593Smuzhiyun	  else
7675*4882a593Smuzhiyun	    func_append compiler_flags " $deplib"
7676*4882a593Smuzhiyun	    if test lib = "$linkmode"; then
7677*4882a593Smuzhiyun		case "$new_inherited_linker_flags " in
7678*4882a593Smuzhiyun		    *" $deplib "*) ;;
7679*4882a593Smuzhiyun		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7680*4882a593Smuzhiyun		esac
7681*4882a593Smuzhiyun	    fi
7682*4882a593Smuzhiyun	  fi
7683*4882a593Smuzhiyun	  continue
7684*4882a593Smuzhiyun	  ;;
7685*4882a593Smuzhiyun	-l*)
7686*4882a593Smuzhiyun	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7687*4882a593Smuzhiyun	    func_warning "'-l' is ignored for archives/objects"
7688*4882a593Smuzhiyun	    continue
7689*4882a593Smuzhiyun	  fi
7690*4882a593Smuzhiyun	  func_stripname '-l' '' "$deplib"
7691*4882a593Smuzhiyun	  name=$func_stripname_result
7692*4882a593Smuzhiyun	  if test lib = "$linkmode"; then
7693*4882a593Smuzhiyun	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7694*4882a593Smuzhiyun	  else
7695*4882a593Smuzhiyun	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7696*4882a593Smuzhiyun	  fi
7697*4882a593Smuzhiyun	  for searchdir in $searchdirs; do
7698*4882a593Smuzhiyun	    for search_ext in .la $std_shrext .so .a; do
7699*4882a593Smuzhiyun	      # Search the libtool library
7700*4882a593Smuzhiyun	      lib=$searchdir/lib$name$search_ext
7701*4882a593Smuzhiyun	      if test -f "$lib"; then
7702*4882a593Smuzhiyun		if test .la = "$search_ext"; then
7703*4882a593Smuzhiyun		  found=:
7704*4882a593Smuzhiyun		else
7705*4882a593Smuzhiyun		  found=false
7706*4882a593Smuzhiyun		fi
7707*4882a593Smuzhiyun		break 2
7708*4882a593Smuzhiyun	      fi
7709*4882a593Smuzhiyun	    done
7710*4882a593Smuzhiyun	  done
7711*4882a593Smuzhiyun	  if $found; then
7712*4882a593Smuzhiyun	    # deplib is a libtool library
7713*4882a593Smuzhiyun	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7714*4882a593Smuzhiyun	    # We need to do some special things here, and not later.
7715*4882a593Smuzhiyun	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7716*4882a593Smuzhiyun	      case " $predeps $postdeps " in
7717*4882a593Smuzhiyun	      *" $deplib "*)
7718*4882a593Smuzhiyun		if func_lalib_p "$lib"; then
7719*4882a593Smuzhiyun		  library_names=
7720*4882a593Smuzhiyun		  old_library=
7721*4882a593Smuzhiyun		  func_source "$lib"
7722*4882a593Smuzhiyun		  for l in $old_library $library_names; do
7723*4882a593Smuzhiyun		    ll=$l
7724*4882a593Smuzhiyun		  done
7725*4882a593Smuzhiyun		  if test "X$ll" = "X$old_library"; then # only static version available
7726*4882a593Smuzhiyun		    found=false
7727*4882a593Smuzhiyun		    func_dirname "$lib" "" "."
7728*4882a593Smuzhiyun		    ladir=$func_dirname_result
7729*4882a593Smuzhiyun		    lib=$ladir/$old_library
7730*4882a593Smuzhiyun		    if test prog,link = "$linkmode,$pass"; then
7731*4882a593Smuzhiyun		      compile_deplibs="$deplib $compile_deplibs"
7732*4882a593Smuzhiyun		      finalize_deplibs="$deplib $finalize_deplibs"
7733*4882a593Smuzhiyun		    else
7734*4882a593Smuzhiyun		      deplibs="$deplib $deplibs"
7735*4882a593Smuzhiyun		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7736*4882a593Smuzhiyun		    fi
7737*4882a593Smuzhiyun		    continue
7738*4882a593Smuzhiyun		  fi
7739*4882a593Smuzhiyun		fi
7740*4882a593Smuzhiyun		;;
7741*4882a593Smuzhiyun	      *) ;;
7742*4882a593Smuzhiyun	      esac
7743*4882a593Smuzhiyun	    fi
7744*4882a593Smuzhiyun	  else
7745*4882a593Smuzhiyun	    # deplib doesn't seem to be a libtool library
7746*4882a593Smuzhiyun	    if test prog,link = "$linkmode,$pass"; then
7747*4882a593Smuzhiyun	      compile_deplibs="$deplib $compile_deplibs"
7748*4882a593Smuzhiyun	      finalize_deplibs="$deplib $finalize_deplibs"
7749*4882a593Smuzhiyun	    else
7750*4882a593Smuzhiyun	      deplibs="$deplib $deplibs"
7751*4882a593Smuzhiyun	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7752*4882a593Smuzhiyun	    fi
7753*4882a593Smuzhiyun	    continue
7754*4882a593Smuzhiyun	  fi
7755*4882a593Smuzhiyun	  ;; # -l
7756*4882a593Smuzhiyun	*.ltframework)
7757*4882a593Smuzhiyun	  if test prog,link = "$linkmode,$pass"; then
7758*4882a593Smuzhiyun	    compile_deplibs="$deplib $compile_deplibs"
7759*4882a593Smuzhiyun	    finalize_deplibs="$deplib $finalize_deplibs"
7760*4882a593Smuzhiyun	  else
7761*4882a593Smuzhiyun	    deplibs="$deplib $deplibs"
7762*4882a593Smuzhiyun	    if test lib = "$linkmode"; then
7763*4882a593Smuzhiyun		case "$new_inherited_linker_flags " in
7764*4882a593Smuzhiyun		    *" $deplib "*) ;;
7765*4882a593Smuzhiyun		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7766*4882a593Smuzhiyun		esac
7767*4882a593Smuzhiyun	    fi
7768*4882a593Smuzhiyun	  fi
7769*4882a593Smuzhiyun	  continue
7770*4882a593Smuzhiyun	  ;;
7771*4882a593Smuzhiyun	-L*)
7772*4882a593Smuzhiyun	  case $linkmode in
7773*4882a593Smuzhiyun	  lib)
7774*4882a593Smuzhiyun	    deplibs="$deplib $deplibs"
7775*4882a593Smuzhiyun	    test conv = "$pass" && continue
7776*4882a593Smuzhiyun	    newdependency_libs="$deplib $newdependency_libs"
7777*4882a593Smuzhiyun	    func_stripname '-L' '' "$deplib"
7778*4882a593Smuzhiyun	    func_resolve_sysroot "$func_stripname_result"
7779*4882a593Smuzhiyun	    func_append newlib_search_path " $func_resolve_sysroot_result"
7780*4882a593Smuzhiyun	    ;;
7781*4882a593Smuzhiyun	  prog)
7782*4882a593Smuzhiyun	    if test conv = "$pass"; then
7783*4882a593Smuzhiyun	      deplibs="$deplib $deplibs"
7784*4882a593Smuzhiyun	      continue
7785*4882a593Smuzhiyun	    fi
7786*4882a593Smuzhiyun	    if test scan = "$pass"; then
7787*4882a593Smuzhiyun	      deplibs="$deplib $deplibs"
7788*4882a593Smuzhiyun	    else
7789*4882a593Smuzhiyun	      compile_deplibs="$deplib $compile_deplibs"
7790*4882a593Smuzhiyun	      finalize_deplibs="$deplib $finalize_deplibs"
7791*4882a593Smuzhiyun	    fi
7792*4882a593Smuzhiyun	    func_stripname '-L' '' "$deplib"
7793*4882a593Smuzhiyun	    func_resolve_sysroot "$func_stripname_result"
7794*4882a593Smuzhiyun	    func_append newlib_search_path " $func_resolve_sysroot_result"
7795*4882a593Smuzhiyun	    ;;
7796*4882a593Smuzhiyun	  *)
7797*4882a593Smuzhiyun	    func_warning "'-L' is ignored for archives/objects"
7798*4882a593Smuzhiyun	    ;;
7799*4882a593Smuzhiyun	  esac # linkmode
7800*4882a593Smuzhiyun	  continue
7801*4882a593Smuzhiyun	  ;; # -L
7802*4882a593Smuzhiyun	-R*)
7803*4882a593Smuzhiyun	  if test link = "$pass"; then
7804*4882a593Smuzhiyun	    func_stripname '-R' '' "$deplib"
7805*4882a593Smuzhiyun	    func_resolve_sysroot "$func_stripname_result"
7806*4882a593Smuzhiyun	    dir=$func_resolve_sysroot_result
7807*4882a593Smuzhiyun	    # Make sure the xrpath contains only unique directories.
7808*4882a593Smuzhiyun	    case "$xrpath " in
7809*4882a593Smuzhiyun	    *" $dir "*) ;;
7810*4882a593Smuzhiyun	    *) func_append xrpath " $dir" ;;
7811*4882a593Smuzhiyun	    esac
7812*4882a593Smuzhiyun	  fi
7813*4882a593Smuzhiyun	  deplibs="$deplib $deplibs"
7814*4882a593Smuzhiyun	  continue
7815*4882a593Smuzhiyun	  ;;
7816*4882a593Smuzhiyun	*.la)
7817*4882a593Smuzhiyun	  func_resolve_sysroot "$deplib"
7818*4882a593Smuzhiyun	  lib=$func_resolve_sysroot_result
7819*4882a593Smuzhiyun	  ;;
7820*4882a593Smuzhiyun	*.$libext)
7821*4882a593Smuzhiyun	  if test conv = "$pass"; then
7822*4882a593Smuzhiyun	    deplibs="$deplib $deplibs"
7823*4882a593Smuzhiyun	    continue
7824*4882a593Smuzhiyun	  fi
7825*4882a593Smuzhiyun	  case $linkmode in
7826*4882a593Smuzhiyun	  lib)
7827*4882a593Smuzhiyun	    # Linking convenience modules into shared libraries is allowed,
7828*4882a593Smuzhiyun	    # but linking other static libraries is non-portable.
7829*4882a593Smuzhiyun	    case " $dlpreconveniencelibs " in
7830*4882a593Smuzhiyun	    *" $deplib "*) ;;
7831*4882a593Smuzhiyun	    *)
7832*4882a593Smuzhiyun	      valid_a_lib=false
7833*4882a593Smuzhiyun	      case $deplibs_check_method in
7834*4882a593Smuzhiyun		match_pattern*)
7835*4882a593Smuzhiyun		  set dummy $deplibs_check_method; shift
7836*4882a593Smuzhiyun		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
7837*4882a593Smuzhiyun		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
7838*4882a593Smuzhiyun		    | $EGREP "$match_pattern_regex" > /dev/null; then
7839*4882a593Smuzhiyun		    valid_a_lib=:
7840*4882a593Smuzhiyun		  fi
7841*4882a593Smuzhiyun		;;
7842*4882a593Smuzhiyun		pass_all)
7843*4882a593Smuzhiyun		  valid_a_lib=:
7844*4882a593Smuzhiyun		;;
7845*4882a593Smuzhiyun	      esac
7846*4882a593Smuzhiyun	      if $valid_a_lib; then
7847*4882a593Smuzhiyun		echo
7848*4882a593Smuzhiyun		$ECHO "*** Warning: Linking the shared library $output against the"
7849*4882a593Smuzhiyun		$ECHO "*** static library $deplib is not portable!"
7850*4882a593Smuzhiyun		deplibs="$deplib $deplibs"
7851*4882a593Smuzhiyun	      else
7852*4882a593Smuzhiyun		echo
7853*4882a593Smuzhiyun		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
7854*4882a593Smuzhiyun		echo "*** I have the capability to make that library automatically link in when"
7855*4882a593Smuzhiyun		echo "*** you link to this library.  But I can only do this if you have a"
7856*4882a593Smuzhiyun		echo "*** shared version of the library, which you do not appear to have"
7857*4882a593Smuzhiyun		echo "*** because the file extensions .$libext of this argument makes me believe"
7858*4882a593Smuzhiyun		echo "*** that it is just a static archive that I should not use here."
7859*4882a593Smuzhiyun	      fi
7860*4882a593Smuzhiyun	      ;;
7861*4882a593Smuzhiyun	    esac
7862*4882a593Smuzhiyun	    continue
7863*4882a593Smuzhiyun	    ;;
7864*4882a593Smuzhiyun	  prog)
7865*4882a593Smuzhiyun	    if test link != "$pass"; then
7866*4882a593Smuzhiyun	      deplibs="$deplib $deplibs"
7867*4882a593Smuzhiyun	    else
7868*4882a593Smuzhiyun	      compile_deplibs="$deplib $compile_deplibs"
7869*4882a593Smuzhiyun	      finalize_deplibs="$deplib $finalize_deplibs"
7870*4882a593Smuzhiyun	    fi
7871*4882a593Smuzhiyun	    continue
7872*4882a593Smuzhiyun	    ;;
7873*4882a593Smuzhiyun	  esac # linkmode
7874*4882a593Smuzhiyun	  ;; # *.$libext
7875*4882a593Smuzhiyun	*.lo | *.$objext)
7876*4882a593Smuzhiyun	  if test conv = "$pass"; then
7877*4882a593Smuzhiyun	    deplibs="$deplib $deplibs"
7878*4882a593Smuzhiyun	  elif test prog = "$linkmode"; then
7879*4882a593Smuzhiyun	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
7880*4882a593Smuzhiyun	      # If there is no dlopen support or we're linking statically,
7881*4882a593Smuzhiyun	      # we need to preload.
7882*4882a593Smuzhiyun	      func_append newdlprefiles " $deplib"
7883*4882a593Smuzhiyun	      compile_deplibs="$deplib $compile_deplibs"
7884*4882a593Smuzhiyun	      finalize_deplibs="$deplib $finalize_deplibs"
7885*4882a593Smuzhiyun	    else
7886*4882a593Smuzhiyun	      func_append newdlfiles " $deplib"
7887*4882a593Smuzhiyun	    fi
7888*4882a593Smuzhiyun	  fi
7889*4882a593Smuzhiyun	  continue
7890*4882a593Smuzhiyun	  ;;
7891*4882a593Smuzhiyun	%DEPLIBS%)
7892*4882a593Smuzhiyun	  alldeplibs=:
7893*4882a593Smuzhiyun	  continue
7894*4882a593Smuzhiyun	  ;;
7895*4882a593Smuzhiyun	esac # case $deplib
7896*4882a593Smuzhiyun
7897*4882a593Smuzhiyun	$found || test -f "$lib" \
7898*4882a593Smuzhiyun	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
7899*4882a593Smuzhiyun
7900*4882a593Smuzhiyun	# Check to see that this really is a libtool archive.
7901*4882a593Smuzhiyun	func_lalib_unsafe_p "$lib" \
7902*4882a593Smuzhiyun	  || func_fatal_error "'$lib' is not a valid libtool archive"
7903*4882a593Smuzhiyun
7904*4882a593Smuzhiyun	func_dirname "$lib" "" "."
7905*4882a593Smuzhiyun	ladir=$func_dirname_result
7906*4882a593Smuzhiyun
7907*4882a593Smuzhiyun	dlname=
7908*4882a593Smuzhiyun	dlopen=
7909*4882a593Smuzhiyun	dlpreopen=
7910*4882a593Smuzhiyun	libdir=
7911*4882a593Smuzhiyun	library_names=
7912*4882a593Smuzhiyun	old_library=
7913*4882a593Smuzhiyun	inherited_linker_flags=
7914*4882a593Smuzhiyun	# If the library was installed with an old release of libtool,
7915*4882a593Smuzhiyun	# it will not redefine variables installed, or shouldnotlink
7916*4882a593Smuzhiyun	installed=yes
7917*4882a593Smuzhiyun	shouldnotlink=no
7918*4882a593Smuzhiyun	avoidtemprpath=
7919*4882a593Smuzhiyun
7920*4882a593Smuzhiyun
7921*4882a593Smuzhiyun	# Read the .la file
7922*4882a593Smuzhiyun	func_source "$lib"
7923*4882a593Smuzhiyun
7924*4882a593Smuzhiyun	# Convert "-framework foo" to "foo.ltframework"
7925*4882a593Smuzhiyun	if test -n "$inherited_linker_flags"; then
7926*4882a593Smuzhiyun	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
7927*4882a593Smuzhiyun	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
7928*4882a593Smuzhiyun	    case " $new_inherited_linker_flags " in
7929*4882a593Smuzhiyun	      *" $tmp_inherited_linker_flag "*) ;;
7930*4882a593Smuzhiyun	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
7931*4882a593Smuzhiyun	    esac
7932*4882a593Smuzhiyun	  done
7933*4882a593Smuzhiyun	fi
7934*4882a593Smuzhiyun	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
7935*4882a593Smuzhiyun	if test lib,link = "$linkmode,$pass" ||
7936*4882a593Smuzhiyun	   test prog,scan = "$linkmode,$pass" ||
7937*4882a593Smuzhiyun	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
7938*4882a593Smuzhiyun	  test -n "$dlopen" && func_append dlfiles " $dlopen"
7939*4882a593Smuzhiyun	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
7940*4882a593Smuzhiyun	fi
7941*4882a593Smuzhiyun
7942*4882a593Smuzhiyun	if test conv = "$pass"; then
7943*4882a593Smuzhiyun	  # Only check for convenience libraries
7944*4882a593Smuzhiyun	  deplibs="$lib $deplibs"
7945*4882a593Smuzhiyun	  if test -z "$libdir"; then
7946*4882a593Smuzhiyun	    if test -z "$old_library"; then
7947*4882a593Smuzhiyun	      func_fatal_error "cannot find name of link library for '$lib'"
7948*4882a593Smuzhiyun	    fi
7949*4882a593Smuzhiyun	    # It is a libtool convenience library, so add in its objects.
7950*4882a593Smuzhiyun	    func_append convenience " $ladir/$objdir/$old_library"
7951*4882a593Smuzhiyun	    func_append old_convenience " $ladir/$objdir/$old_library"
7952*4882a593Smuzhiyun	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
7953*4882a593Smuzhiyun	    func_fatal_error "'$lib' is not a convenience library"
7954*4882a593Smuzhiyun	  fi
7955*4882a593Smuzhiyun	  tmp_libs=
7956*4882a593Smuzhiyun	  for deplib in $dependency_libs; do
7957*4882a593Smuzhiyun	    deplibs="$deplib $deplibs"
7958*4882a593Smuzhiyun	    if $opt_preserve_dup_deps; then
7959*4882a593Smuzhiyun	      case "$tmp_libs " in
7960*4882a593Smuzhiyun	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
7961*4882a593Smuzhiyun	      esac
7962*4882a593Smuzhiyun	    fi
7963*4882a593Smuzhiyun	    func_append tmp_libs " $deplib"
7964*4882a593Smuzhiyun	  done
7965*4882a593Smuzhiyun	  continue
7966*4882a593Smuzhiyun	fi # $pass = conv
7967*4882a593Smuzhiyun
7968*4882a593Smuzhiyun
7969*4882a593Smuzhiyun	# Get the name of the library we link against.
7970*4882a593Smuzhiyun	linklib=
7971*4882a593Smuzhiyun	if test -n "$old_library" &&
7972*4882a593Smuzhiyun	   { test yes = "$prefer_static_libs" ||
7973*4882a593Smuzhiyun	     test built,no = "$prefer_static_libs,$installed"; }; then
7974*4882a593Smuzhiyun	  linklib=$old_library
7975*4882a593Smuzhiyun	else
7976*4882a593Smuzhiyun	  for l in $old_library $library_names; do
7977*4882a593Smuzhiyun	    linklib=$l
7978*4882a593Smuzhiyun	  done
7979*4882a593Smuzhiyun	fi
7980*4882a593Smuzhiyun	if test -z "$linklib"; then
7981*4882a593Smuzhiyun	  func_fatal_error "cannot find name of link library for '$lib'"
7982*4882a593Smuzhiyun	fi
7983*4882a593Smuzhiyun
7984*4882a593Smuzhiyun	# This library was specified with -dlopen.
7985*4882a593Smuzhiyun	if test dlopen = "$pass"; then
7986*4882a593Smuzhiyun	  test -z "$libdir" \
7987*4882a593Smuzhiyun	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
7988*4882a593Smuzhiyun	  if test -z "$dlname" ||
7989*4882a593Smuzhiyun	     test yes != "$dlopen_support" ||
7990*4882a593Smuzhiyun	     test no = "$build_libtool_libs"
7991*4882a593Smuzhiyun	  then
7992*4882a593Smuzhiyun	    # If there is no dlname, no dlopen support or we're linking
7993*4882a593Smuzhiyun	    # statically, we need to preload.  We also need to preload any
7994*4882a593Smuzhiyun	    # dependent libraries so libltdl's deplib preloader doesn't
7995*4882a593Smuzhiyun	    # bomb out in the load deplibs phase.
7996*4882a593Smuzhiyun	    func_append dlprefiles " $lib $dependency_libs"
7997*4882a593Smuzhiyun	  else
7998*4882a593Smuzhiyun	    func_append newdlfiles " $lib"
7999*4882a593Smuzhiyun	  fi
8000*4882a593Smuzhiyun	  continue
8001*4882a593Smuzhiyun	fi # $pass = dlopen
8002*4882a593Smuzhiyun
8003*4882a593Smuzhiyun	# We need an absolute path.
8004*4882a593Smuzhiyun	case $ladir in
8005*4882a593Smuzhiyun	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8006*4882a593Smuzhiyun	*)
8007*4882a593Smuzhiyun	  abs_ladir=`cd "$ladir" && pwd`
8008*4882a593Smuzhiyun	  if test -z "$abs_ladir"; then
8009*4882a593Smuzhiyun	    func_warning "cannot determine absolute directory name of '$ladir'"
8010*4882a593Smuzhiyun	    func_warning "passing it literally to the linker, although it might fail"
8011*4882a593Smuzhiyun	    abs_ladir=$ladir
8012*4882a593Smuzhiyun	  fi
8013*4882a593Smuzhiyun	  ;;
8014*4882a593Smuzhiyun	esac
8015*4882a593Smuzhiyun	func_basename "$lib"
8016*4882a593Smuzhiyun	laname=$func_basename_result
8017*4882a593Smuzhiyun
8018*4882a593Smuzhiyun	# Find the relevant object directory and library name.
8019*4882a593Smuzhiyun	if test yes = "$installed"; then
8020*4882a593Smuzhiyun	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8021*4882a593Smuzhiyun	    func_warning "library '$lib' was moved."
8022*4882a593Smuzhiyun	    dir=$ladir
8023*4882a593Smuzhiyun	    absdir=$abs_ladir
8024*4882a593Smuzhiyun	    libdir=$abs_ladir
8025*4882a593Smuzhiyun	  else
8026*4882a593Smuzhiyun	    dir=$lt_sysroot$libdir
8027*4882a593Smuzhiyun	    absdir=$lt_sysroot$libdir
8028*4882a593Smuzhiyun	  fi
8029*4882a593Smuzhiyun	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8030*4882a593Smuzhiyun	else
8031*4882a593Smuzhiyun	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8032*4882a593Smuzhiyun	    dir=$ladir
8033*4882a593Smuzhiyun	    absdir=$abs_ladir
8034*4882a593Smuzhiyun	    # Remove this search path later
8035*4882a593Smuzhiyun	    func_append notinst_path " $abs_ladir"
8036*4882a593Smuzhiyun	  else
8037*4882a593Smuzhiyun	    dir=$ladir/$objdir
8038*4882a593Smuzhiyun	    absdir=$abs_ladir/$objdir
8039*4882a593Smuzhiyun	    # Remove this search path later
8040*4882a593Smuzhiyun	    func_append notinst_path " $abs_ladir"
8041*4882a593Smuzhiyun	  fi
8042*4882a593Smuzhiyun	fi # $installed = yes
8043*4882a593Smuzhiyun	func_stripname 'lib' '.la' "$laname"
8044*4882a593Smuzhiyun	name=$func_stripname_result
8045*4882a593Smuzhiyun
8046*4882a593Smuzhiyun	# This library was specified with -dlpreopen.
8047*4882a593Smuzhiyun	if test dlpreopen = "$pass"; then
8048*4882a593Smuzhiyun	  if test -z "$libdir" && test prog = "$linkmode"; then
8049*4882a593Smuzhiyun	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8050*4882a593Smuzhiyun	  fi
8051*4882a593Smuzhiyun	  case $host in
8052*4882a593Smuzhiyun	    # special handling for platforms with PE-DLLs.
8053*4882a593Smuzhiyun	    *cygwin* | *mingw* | *cegcc* )
8054*4882a593Smuzhiyun	      # Linker will automatically link against shared library if both
8055*4882a593Smuzhiyun	      # static and shared are present.  Therefore, ensure we extract
8056*4882a593Smuzhiyun	      # symbols from the import library if a shared library is present
8057*4882a593Smuzhiyun	      # (otherwise, the dlopen module name will be incorrect).  We do
8058*4882a593Smuzhiyun	      # this by putting the import library name into $newdlprefiles.
8059*4882a593Smuzhiyun	      # We recover the dlopen module name by 'saving' the la file
8060*4882a593Smuzhiyun	      # name in a special purpose variable, and (later) extracting the
8061*4882a593Smuzhiyun	      # dlname from the la file.
8062*4882a593Smuzhiyun	      if test -n "$dlname"; then
8063*4882a593Smuzhiyun	        func_tr_sh "$dir/$linklib"
8064*4882a593Smuzhiyun	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8065*4882a593Smuzhiyun	        func_append newdlprefiles " $dir/$linklib"
8066*4882a593Smuzhiyun	      else
8067*4882a593Smuzhiyun	        func_append newdlprefiles " $dir/$old_library"
8068*4882a593Smuzhiyun	        # Keep a list of preopened convenience libraries to check
8069*4882a593Smuzhiyun	        # that they are being used correctly in the link pass.
8070*4882a593Smuzhiyun	        test -z "$libdir" && \
8071*4882a593Smuzhiyun	          func_append dlpreconveniencelibs " $dir/$old_library"
8072*4882a593Smuzhiyun	      fi
8073*4882a593Smuzhiyun	    ;;
8074*4882a593Smuzhiyun	    * )
8075*4882a593Smuzhiyun	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8076*4882a593Smuzhiyun	      # are required to link).
8077*4882a593Smuzhiyun	      if test -n "$old_library"; then
8078*4882a593Smuzhiyun	        func_append newdlprefiles " $dir/$old_library"
8079*4882a593Smuzhiyun	        # Keep a list of preopened convenience libraries to check
8080*4882a593Smuzhiyun	        # that they are being used correctly in the link pass.
8081*4882a593Smuzhiyun	        test -z "$libdir" && \
8082*4882a593Smuzhiyun	          func_append dlpreconveniencelibs " $dir/$old_library"
8083*4882a593Smuzhiyun	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8084*4882a593Smuzhiyun	      elif test -n "$dlname"; then
8085*4882a593Smuzhiyun	        func_append newdlprefiles " $dir/$dlname"
8086*4882a593Smuzhiyun	      else
8087*4882a593Smuzhiyun	        func_append newdlprefiles " $dir/$linklib"
8088*4882a593Smuzhiyun	      fi
8089*4882a593Smuzhiyun	    ;;
8090*4882a593Smuzhiyun	  esac
8091*4882a593Smuzhiyun	fi # $pass = dlpreopen
8092*4882a593Smuzhiyun
8093*4882a593Smuzhiyun	if test -z "$libdir"; then
8094*4882a593Smuzhiyun	  # Link the convenience library
8095*4882a593Smuzhiyun	  if test lib = "$linkmode"; then
8096*4882a593Smuzhiyun	    deplibs="$dir/$old_library $deplibs"
8097*4882a593Smuzhiyun	  elif test prog,link = "$linkmode,$pass"; then
8098*4882a593Smuzhiyun	    compile_deplibs="$dir/$old_library $compile_deplibs"
8099*4882a593Smuzhiyun	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8100*4882a593Smuzhiyun	  else
8101*4882a593Smuzhiyun	    deplibs="$lib $deplibs" # used for prog,scan pass
8102*4882a593Smuzhiyun	  fi
8103*4882a593Smuzhiyun	  continue
8104*4882a593Smuzhiyun	fi
8105*4882a593Smuzhiyun
8106*4882a593Smuzhiyun
8107*4882a593Smuzhiyun	if test prog = "$linkmode" && test link != "$pass"; then
8108*4882a593Smuzhiyun	  func_append newlib_search_path " $ladir"
8109*4882a593Smuzhiyun	  deplibs="$lib $deplibs"
8110*4882a593Smuzhiyun
8111*4882a593Smuzhiyun	  linkalldeplibs=false
8112*4882a593Smuzhiyun	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8113*4882a593Smuzhiyun	     test no = "$build_libtool_libs"; then
8114*4882a593Smuzhiyun	    linkalldeplibs=:
8115*4882a593Smuzhiyun	  fi
8116*4882a593Smuzhiyun
8117*4882a593Smuzhiyun	  tmp_libs=
8118*4882a593Smuzhiyun	  for deplib in $dependency_libs; do
8119*4882a593Smuzhiyun	    case $deplib in
8120*4882a593Smuzhiyun	    -L*) func_stripname '-L' '' "$deplib"
8121*4882a593Smuzhiyun	         func_resolve_sysroot "$func_stripname_result"
8122*4882a593Smuzhiyun	         func_append newlib_search_path " $func_resolve_sysroot_result"
8123*4882a593Smuzhiyun		 ;;
8124*4882a593Smuzhiyun	    esac
8125*4882a593Smuzhiyun	    # Need to link against all dependency_libs?
8126*4882a593Smuzhiyun	    if $linkalldeplibs; then
8127*4882a593Smuzhiyun	      deplibs="$deplib $deplibs"
8128*4882a593Smuzhiyun	    else
8129*4882a593Smuzhiyun	      # Need to hardcode shared library paths
8130*4882a593Smuzhiyun	      # or/and link against static libraries
8131*4882a593Smuzhiyun	      newdependency_libs="$deplib $newdependency_libs"
8132*4882a593Smuzhiyun	    fi
8133*4882a593Smuzhiyun	    if $opt_preserve_dup_deps; then
8134*4882a593Smuzhiyun	      case "$tmp_libs " in
8135*4882a593Smuzhiyun	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8136*4882a593Smuzhiyun	      esac
8137*4882a593Smuzhiyun	    fi
8138*4882a593Smuzhiyun	    func_append tmp_libs " $deplib"
8139*4882a593Smuzhiyun	  done # for deplib
8140*4882a593Smuzhiyun	  continue
8141*4882a593Smuzhiyun	fi # $linkmode = prog...
8142*4882a593Smuzhiyun
8143*4882a593Smuzhiyun	if test prog,link = "$linkmode,$pass"; then
8144*4882a593Smuzhiyun	  if test -n "$library_names" &&
8145*4882a593Smuzhiyun	     { { test no = "$prefer_static_libs" ||
8146*4882a593Smuzhiyun	         test built,yes = "$prefer_static_libs,$installed"; } ||
8147*4882a593Smuzhiyun	       test -z "$old_library"; }; then
8148*4882a593Smuzhiyun	    # We need to hardcode the library path
8149*4882a593Smuzhiyun	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8150*4882a593Smuzhiyun	      # Make sure the rpath contains only unique directories.
8151*4882a593Smuzhiyun	      case $temp_rpath: in
8152*4882a593Smuzhiyun	      *"$absdir:"*) ;;
8153*4882a593Smuzhiyun	      *) func_append temp_rpath "$absdir:" ;;
8154*4882a593Smuzhiyun	      esac
8155*4882a593Smuzhiyun	    fi
8156*4882a593Smuzhiyun
8157*4882a593Smuzhiyun	    # Hardcode the library path.
8158*4882a593Smuzhiyun	    # Skip directories that are in the system default run-time
8159*4882a593Smuzhiyun	    # search path.
8160*4882a593Smuzhiyun	    case " $sys_lib_dlsearch_path " in
8161*4882a593Smuzhiyun	    *" $absdir "*) ;;
8162*4882a593Smuzhiyun	    *)
8163*4882a593Smuzhiyun	      case "$compile_rpath " in
8164*4882a593Smuzhiyun	      *" $absdir "*) ;;
8165*4882a593Smuzhiyun	      *) func_append compile_rpath " $absdir" ;;
8166*4882a593Smuzhiyun	      esac
8167*4882a593Smuzhiyun	      ;;
8168*4882a593Smuzhiyun	    esac
8169*4882a593Smuzhiyun	    case " $sys_lib_dlsearch_path " in
8170*4882a593Smuzhiyun	    *" $libdir "*) ;;
8171*4882a593Smuzhiyun	    *)
8172*4882a593Smuzhiyun	      case "$finalize_rpath " in
8173*4882a593Smuzhiyun	      *" $libdir "*) ;;
8174*4882a593Smuzhiyun	      *) func_append finalize_rpath " $libdir" ;;
8175*4882a593Smuzhiyun	      esac
8176*4882a593Smuzhiyun	      ;;
8177*4882a593Smuzhiyun	    esac
8178*4882a593Smuzhiyun	  fi # $linkmode,$pass = prog,link...
8179*4882a593Smuzhiyun
8180*4882a593Smuzhiyun	  if $alldeplibs &&
8181*4882a593Smuzhiyun	     { test pass_all = "$deplibs_check_method" ||
8182*4882a593Smuzhiyun	       { test yes = "$build_libtool_libs" &&
8183*4882a593Smuzhiyun		 test -n "$library_names"; }; }; then
8184*4882a593Smuzhiyun	    # We only need to search for static libraries
8185*4882a593Smuzhiyun	    continue
8186*4882a593Smuzhiyun	  fi
8187*4882a593Smuzhiyun	fi
8188*4882a593Smuzhiyun
8189*4882a593Smuzhiyun	link_static=no # Whether the deplib will be linked statically
8190*4882a593Smuzhiyun	use_static_libs=$prefer_static_libs
8191*4882a593Smuzhiyun	if test built = "$use_static_libs" && test yes = "$installed"; then
8192*4882a593Smuzhiyun	  use_static_libs=no
8193*4882a593Smuzhiyun	fi
8194*4882a593Smuzhiyun	if test -n "$library_names" &&
8195*4882a593Smuzhiyun	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8196*4882a593Smuzhiyun	  case $host in
8197*4882a593Smuzhiyun	  *cygwin* | *mingw* | *cegcc* | *os2*)
8198*4882a593Smuzhiyun	      # No point in relinking DLLs because paths are not encoded
8199*4882a593Smuzhiyun	      func_append notinst_deplibs " $lib"
8200*4882a593Smuzhiyun	      need_relink=no
8201*4882a593Smuzhiyun	    ;;
8202*4882a593Smuzhiyun	  *)
8203*4882a593Smuzhiyun	    if test no = "$installed"; then
8204*4882a593Smuzhiyun	      func_append notinst_deplibs " $lib"
8205*4882a593Smuzhiyun	      need_relink=yes
8206*4882a593Smuzhiyun	    fi
8207*4882a593Smuzhiyun	    ;;
8208*4882a593Smuzhiyun	  esac
8209*4882a593Smuzhiyun	  # This is a shared library
8210*4882a593Smuzhiyun
8211*4882a593Smuzhiyun	  # Warn about portability, can't link against -module's on some
8212*4882a593Smuzhiyun	  # systems (darwin).  Don't bleat about dlopened modules though!
8213*4882a593Smuzhiyun	  dlopenmodule=
8214*4882a593Smuzhiyun	  for dlpremoduletest in $dlprefiles; do
8215*4882a593Smuzhiyun	    if test "X$dlpremoduletest" = "X$lib"; then
8216*4882a593Smuzhiyun	      dlopenmodule=$dlpremoduletest
8217*4882a593Smuzhiyun	      break
8218*4882a593Smuzhiyun	    fi
8219*4882a593Smuzhiyun	  done
8220*4882a593Smuzhiyun	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8221*4882a593Smuzhiyun	    echo
8222*4882a593Smuzhiyun	    if test prog = "$linkmode"; then
8223*4882a593Smuzhiyun	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8224*4882a593Smuzhiyun	    else
8225*4882a593Smuzhiyun	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8226*4882a593Smuzhiyun	    fi
8227*4882a593Smuzhiyun	    $ECHO "*** $linklib is not portable!"
8228*4882a593Smuzhiyun	  fi
8229*4882a593Smuzhiyun	  if test lib = "$linkmode" &&
8230*4882a593Smuzhiyun	     test yes = "$hardcode_into_libs"; then
8231*4882a593Smuzhiyun	    # Hardcode the library path.
8232*4882a593Smuzhiyun	    # Skip directories that are in the system default run-time
8233*4882a593Smuzhiyun	    # search path.
8234*4882a593Smuzhiyun	    case " $sys_lib_dlsearch_path " in
8235*4882a593Smuzhiyun	    *" $absdir "*) ;;
8236*4882a593Smuzhiyun	    *)
8237*4882a593Smuzhiyun	      case "$compile_rpath " in
8238*4882a593Smuzhiyun	      *" $absdir "*) ;;
8239*4882a593Smuzhiyun	      *) func_append compile_rpath " $absdir" ;;
8240*4882a593Smuzhiyun	      esac
8241*4882a593Smuzhiyun	      ;;
8242*4882a593Smuzhiyun	    esac
8243*4882a593Smuzhiyun	    case " $sys_lib_dlsearch_path " in
8244*4882a593Smuzhiyun	    *" $libdir "*) ;;
8245*4882a593Smuzhiyun	    *)
8246*4882a593Smuzhiyun	      case "$finalize_rpath " in
8247*4882a593Smuzhiyun	      *" $libdir "*) ;;
8248*4882a593Smuzhiyun	      *) func_append finalize_rpath " $libdir" ;;
8249*4882a593Smuzhiyun	      esac
8250*4882a593Smuzhiyun	      ;;
8251*4882a593Smuzhiyun	    esac
8252*4882a593Smuzhiyun	  fi
8253*4882a593Smuzhiyun
8254*4882a593Smuzhiyun	  if test -n "$old_archive_from_expsyms_cmds"; then
8255*4882a593Smuzhiyun	    # figure out the soname
8256*4882a593Smuzhiyun	    set dummy $library_names
8257*4882a593Smuzhiyun	    shift
8258*4882a593Smuzhiyun	    realname=$1
8259*4882a593Smuzhiyun	    shift
8260*4882a593Smuzhiyun	    libname=`eval "\\$ECHO \"$libname_spec\""`
8261*4882a593Smuzhiyun	    # use dlname if we got it. it's perfectly good, no?
8262*4882a593Smuzhiyun	    if test -n "$dlname"; then
8263*4882a593Smuzhiyun	      soname=$dlname
8264*4882a593Smuzhiyun	    elif test -n "$soname_spec"; then
8265*4882a593Smuzhiyun	      # bleh windows
8266*4882a593Smuzhiyun	      case $host in
8267*4882a593Smuzhiyun	      *cygwin* | mingw* | *cegcc* | *os2*)
8268*4882a593Smuzhiyun	        func_arith $current - $age
8269*4882a593Smuzhiyun		major=$func_arith_result
8270*4882a593Smuzhiyun		versuffix=-$major
8271*4882a593Smuzhiyun		;;
8272*4882a593Smuzhiyun	      esac
8273*4882a593Smuzhiyun	      eval soname=\"$soname_spec\"
8274*4882a593Smuzhiyun	    else
8275*4882a593Smuzhiyun	      soname=$realname
8276*4882a593Smuzhiyun	    fi
8277*4882a593Smuzhiyun
8278*4882a593Smuzhiyun	    # Make a new name for the extract_expsyms_cmds to use
8279*4882a593Smuzhiyun	    soroot=$soname
8280*4882a593Smuzhiyun	    func_basename "$soroot"
8281*4882a593Smuzhiyun	    soname=$func_basename_result
8282*4882a593Smuzhiyun	    func_stripname 'lib' '.dll' "$soname"
8283*4882a593Smuzhiyun	    newlib=libimp-$func_stripname_result.a
8284*4882a593Smuzhiyun
8285*4882a593Smuzhiyun	    # If the library has no export list, then create one now
8286*4882a593Smuzhiyun	    if test -f "$output_objdir/$soname-def"; then :
8287*4882a593Smuzhiyun	    else
8288*4882a593Smuzhiyun	      func_verbose "extracting exported symbol list from '$soname'"
8289*4882a593Smuzhiyun	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8290*4882a593Smuzhiyun	    fi
8291*4882a593Smuzhiyun
8292*4882a593Smuzhiyun	    # Create $newlib
8293*4882a593Smuzhiyun	    if test -f "$output_objdir/$newlib"; then :; else
8294*4882a593Smuzhiyun	      func_verbose "generating import library for '$soname'"
8295*4882a593Smuzhiyun	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8296*4882a593Smuzhiyun	    fi
8297*4882a593Smuzhiyun	    # make sure the library variables are pointing to the new library
8298*4882a593Smuzhiyun	    dir=$output_objdir
8299*4882a593Smuzhiyun	    linklib=$newlib
8300*4882a593Smuzhiyun	  fi # test -n "$old_archive_from_expsyms_cmds"
8301*4882a593Smuzhiyun
8302*4882a593Smuzhiyun	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8303*4882a593Smuzhiyun	    add_shlibpath=
8304*4882a593Smuzhiyun	    add_dir=
8305*4882a593Smuzhiyun	    add=
8306*4882a593Smuzhiyun	    lib_linked=yes
8307*4882a593Smuzhiyun	    case $hardcode_action in
8308*4882a593Smuzhiyun	    immediate | unsupported)
8309*4882a593Smuzhiyun	      if test no = "$hardcode_direct"; then
8310*4882a593Smuzhiyun		add=$dir/$linklib
8311*4882a593Smuzhiyun		case $host in
8312*4882a593Smuzhiyun		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8313*4882a593Smuzhiyun		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8314*4882a593Smuzhiyun		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8315*4882a593Smuzhiyun		    *-*-unixware7*) add_dir=-L$dir ;;
8316*4882a593Smuzhiyun		  *-*-darwin* )
8317*4882a593Smuzhiyun		    # if the lib is a (non-dlopened) module then we cannot
8318*4882a593Smuzhiyun		    # link against it, someone is ignoring the earlier warnings
8319*4882a593Smuzhiyun		    if /usr/bin/file -L $add 2> /dev/null |
8320*4882a593Smuzhiyun			 $GREP ": [^:]* bundle" >/dev/null; then
8321*4882a593Smuzhiyun		      if test "X$dlopenmodule" != "X$lib"; then
8322*4882a593Smuzhiyun			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8323*4882a593Smuzhiyun			if test -z "$old_library"; then
8324*4882a593Smuzhiyun			  echo
8325*4882a593Smuzhiyun			  echo "*** And there doesn't seem to be a static archive available"
8326*4882a593Smuzhiyun			  echo "*** The link will probably fail, sorry"
8327*4882a593Smuzhiyun			else
8328*4882a593Smuzhiyun			  add=$dir/$old_library
8329*4882a593Smuzhiyun			fi
8330*4882a593Smuzhiyun		      elif test -n "$old_library"; then
8331*4882a593Smuzhiyun			add=$dir/$old_library
8332*4882a593Smuzhiyun		      fi
8333*4882a593Smuzhiyun		    fi
8334*4882a593Smuzhiyun		esac
8335*4882a593Smuzhiyun	      elif test no = "$hardcode_minus_L"; then
8336*4882a593Smuzhiyun		case $host in
8337*4882a593Smuzhiyun		*-*-sunos*) add_shlibpath=$dir ;;
8338*4882a593Smuzhiyun		esac
8339*4882a593Smuzhiyun		add_dir=-L$dir
8340*4882a593Smuzhiyun		add=-l$name
8341*4882a593Smuzhiyun	      elif test no = "$hardcode_shlibpath_var"; then
8342*4882a593Smuzhiyun		add_shlibpath=$dir
8343*4882a593Smuzhiyun		add=-l$name
8344*4882a593Smuzhiyun	      else
8345*4882a593Smuzhiyun		lib_linked=no
8346*4882a593Smuzhiyun	      fi
8347*4882a593Smuzhiyun	      ;;
8348*4882a593Smuzhiyun	    relink)
8349*4882a593Smuzhiyun	      if test yes = "$hardcode_direct" &&
8350*4882a593Smuzhiyun	         test no = "$hardcode_direct_absolute"; then
8351*4882a593Smuzhiyun		add=$dir/$linklib
8352*4882a593Smuzhiyun	      elif test yes = "$hardcode_minus_L"; then
8353*4882a593Smuzhiyun		add_dir=-L$absdir
8354*4882a593Smuzhiyun		# Try looking first in the location we're being installed to.
8355*4882a593Smuzhiyun		if test -n "$inst_prefix_dir"; then
8356*4882a593Smuzhiyun		  case $libdir in
8357*4882a593Smuzhiyun		    [\\/]*)
8358*4882a593Smuzhiyun		      func_append add_dir " -L$inst_prefix_dir$libdir"
8359*4882a593Smuzhiyun		      ;;
8360*4882a593Smuzhiyun		  esac
8361*4882a593Smuzhiyun		fi
8362*4882a593Smuzhiyun		add=-l$name
8363*4882a593Smuzhiyun	      elif test yes = "$hardcode_shlibpath_var"; then
8364*4882a593Smuzhiyun		add_shlibpath=$dir
8365*4882a593Smuzhiyun		add=-l$name
8366*4882a593Smuzhiyun	      else
8367*4882a593Smuzhiyun		lib_linked=no
8368*4882a593Smuzhiyun	      fi
8369*4882a593Smuzhiyun	      ;;
8370*4882a593Smuzhiyun	    *) lib_linked=no ;;
8371*4882a593Smuzhiyun	    esac
8372*4882a593Smuzhiyun
8373*4882a593Smuzhiyun	    if test yes != "$lib_linked"; then
8374*4882a593Smuzhiyun	      func_fatal_configuration "unsupported hardcode properties"
8375*4882a593Smuzhiyun	    fi
8376*4882a593Smuzhiyun
8377*4882a593Smuzhiyun	    if test -n "$add_shlibpath"; then
8378*4882a593Smuzhiyun	      case :$compile_shlibpath: in
8379*4882a593Smuzhiyun	      *":$add_shlibpath:"*) ;;
8380*4882a593Smuzhiyun	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8381*4882a593Smuzhiyun	      esac
8382*4882a593Smuzhiyun	    fi
8383*4882a593Smuzhiyun	    if test prog = "$linkmode"; then
8384*4882a593Smuzhiyun	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8385*4882a593Smuzhiyun	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8386*4882a593Smuzhiyun	    else
8387*4882a593Smuzhiyun	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8388*4882a593Smuzhiyun	      test -n "$add" && deplibs="$add $deplibs"
8389*4882a593Smuzhiyun	      if test yes != "$hardcode_direct" &&
8390*4882a593Smuzhiyun		 test yes != "$hardcode_minus_L" &&
8391*4882a593Smuzhiyun		 test yes = "$hardcode_shlibpath_var"; then
8392*4882a593Smuzhiyun		case :$finalize_shlibpath: in
8393*4882a593Smuzhiyun		*":$libdir:"*) ;;
8394*4882a593Smuzhiyun		*) func_append finalize_shlibpath "$libdir:" ;;
8395*4882a593Smuzhiyun		esac
8396*4882a593Smuzhiyun	      fi
8397*4882a593Smuzhiyun	    fi
8398*4882a593Smuzhiyun	  fi
8399*4882a593Smuzhiyun
8400*4882a593Smuzhiyun	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8401*4882a593Smuzhiyun	    add_shlibpath=
8402*4882a593Smuzhiyun	    add_dir=
8403*4882a593Smuzhiyun	    add=
8404*4882a593Smuzhiyun	    # Finalize command for both is simple: just hardcode it.
8405*4882a593Smuzhiyun	    if test yes = "$hardcode_direct" &&
8406*4882a593Smuzhiyun	       test no = "$hardcode_direct_absolute"; then
8407*4882a593Smuzhiyun	      add=$libdir/$linklib
8408*4882a593Smuzhiyun	    elif test yes = "$hardcode_minus_L"; then
8409*4882a593Smuzhiyun	      add_dir=-L$libdir
8410*4882a593Smuzhiyun	      add=-l$name
8411*4882a593Smuzhiyun	    elif test yes = "$hardcode_shlibpath_var"; then
8412*4882a593Smuzhiyun	      case :$finalize_shlibpath: in
8413*4882a593Smuzhiyun	      *":$libdir:"*) ;;
8414*4882a593Smuzhiyun	      *) func_append finalize_shlibpath "$libdir:" ;;
8415*4882a593Smuzhiyun	      esac
8416*4882a593Smuzhiyun	      add=-l$name
8417*4882a593Smuzhiyun	    elif test yes = "$hardcode_automatic"; then
8418*4882a593Smuzhiyun	      if test -n "$inst_prefix_dir" &&
8419*4882a593Smuzhiyun		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8420*4882a593Smuzhiyun		add=$inst_prefix_dir$libdir/$linklib
8421*4882a593Smuzhiyun	      else
8422*4882a593Smuzhiyun		add=$libdir/$linklib
8423*4882a593Smuzhiyun	      fi
8424*4882a593Smuzhiyun	    else
8425*4882a593Smuzhiyun	      # We cannot seem to hardcode it, guess we'll fake it.
8426*4882a593Smuzhiyun	      add_dir=-L$libdir
8427*4882a593Smuzhiyun	      # Try looking first in the location we're being installed to.
8428*4882a593Smuzhiyun	      if test -n "$inst_prefix_dir"; then
8429*4882a593Smuzhiyun		case $libdir in
8430*4882a593Smuzhiyun		  [\\/]*)
8431*4882a593Smuzhiyun		    func_append add_dir " -L$inst_prefix_dir$libdir"
8432*4882a593Smuzhiyun		    ;;
8433*4882a593Smuzhiyun		esac
8434*4882a593Smuzhiyun	      fi
8435*4882a593Smuzhiyun	      add=-l$name
8436*4882a593Smuzhiyun	    fi
8437*4882a593Smuzhiyun
8438*4882a593Smuzhiyun	    if test prog = "$linkmode"; then
8439*4882a593Smuzhiyun	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8440*4882a593Smuzhiyun	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8441*4882a593Smuzhiyun	    else
8442*4882a593Smuzhiyun	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8443*4882a593Smuzhiyun	      test -n "$add" && deplibs="$add $deplibs"
8444*4882a593Smuzhiyun	    fi
8445*4882a593Smuzhiyun	  fi
8446*4882a593Smuzhiyun	elif test prog = "$linkmode"; then
8447*4882a593Smuzhiyun	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8448*4882a593Smuzhiyun	  # is not unsupported.  This is valid on all known static and
8449*4882a593Smuzhiyun	  # shared platforms.
8450*4882a593Smuzhiyun	  if test unsupported != "$hardcode_direct"; then
8451*4882a593Smuzhiyun	    test -n "$old_library" && linklib=$old_library
8452*4882a593Smuzhiyun	    compile_deplibs="$dir/$linklib $compile_deplibs"
8453*4882a593Smuzhiyun	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8454*4882a593Smuzhiyun	  else
8455*4882a593Smuzhiyun	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8456*4882a593Smuzhiyun	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8457*4882a593Smuzhiyun	  fi
8458*4882a593Smuzhiyun	elif test yes = "$build_libtool_libs"; then
8459*4882a593Smuzhiyun	  # Not a shared library
8460*4882a593Smuzhiyun	  if test pass_all != "$deplibs_check_method"; then
8461*4882a593Smuzhiyun	    # We're trying link a shared library against a static one
8462*4882a593Smuzhiyun	    # but the system doesn't support it.
8463*4882a593Smuzhiyun
8464*4882a593Smuzhiyun	    # Just print a warning and add the library to dependency_libs so
8465*4882a593Smuzhiyun	    # that the program can be linked against the static library.
8466*4882a593Smuzhiyun	    echo
8467*4882a593Smuzhiyun	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8468*4882a593Smuzhiyun	    echo "*** I have the capability to make that library automatically link in when"
8469*4882a593Smuzhiyun	    echo "*** you link to this library.  But I can only do this if you have a"
8470*4882a593Smuzhiyun	    echo "*** shared version of the library, which you do not appear to have."
8471*4882a593Smuzhiyun	    if test yes = "$module"; then
8472*4882a593Smuzhiyun	      echo "*** But as you try to build a module library, libtool will still create "
8473*4882a593Smuzhiyun	      echo "*** a static module, that should work as long as the dlopening application"
8474*4882a593Smuzhiyun	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8475*4882a593Smuzhiyun	      if test -z "$global_symbol_pipe"; then
8476*4882a593Smuzhiyun		echo
8477*4882a593Smuzhiyun		echo "*** However, this would only work if libtool was able to extract symbol"
8478*4882a593Smuzhiyun		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8479*4882a593Smuzhiyun		echo "*** not find such a program.  So, this module is probably useless."
8480*4882a593Smuzhiyun		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8481*4882a593Smuzhiyun	      fi
8482*4882a593Smuzhiyun	      if test no = "$build_old_libs"; then
8483*4882a593Smuzhiyun		build_libtool_libs=module
8484*4882a593Smuzhiyun		build_old_libs=yes
8485*4882a593Smuzhiyun	      else
8486*4882a593Smuzhiyun		build_libtool_libs=no
8487*4882a593Smuzhiyun	      fi
8488*4882a593Smuzhiyun	    fi
8489*4882a593Smuzhiyun	  else
8490*4882a593Smuzhiyun	    deplibs="$dir/$old_library $deplibs"
8491*4882a593Smuzhiyun	    link_static=yes
8492*4882a593Smuzhiyun	  fi
8493*4882a593Smuzhiyun	fi # link shared/static library?
8494*4882a593Smuzhiyun
8495*4882a593Smuzhiyun	if test lib = "$linkmode"; then
8496*4882a593Smuzhiyun	  if test -n "$dependency_libs" &&
8497*4882a593Smuzhiyun	     { test yes != "$hardcode_into_libs" ||
8498*4882a593Smuzhiyun	       test yes = "$build_old_libs" ||
8499*4882a593Smuzhiyun	       test yes = "$link_static"; }; then
8500*4882a593Smuzhiyun	    # Extract -R from dependency_libs
8501*4882a593Smuzhiyun	    temp_deplibs=
8502*4882a593Smuzhiyun	    for libdir in $dependency_libs; do
8503*4882a593Smuzhiyun	      case $libdir in
8504*4882a593Smuzhiyun	      -R*) func_stripname '-R' '' "$libdir"
8505*4882a593Smuzhiyun	           temp_xrpath=$func_stripname_result
8506*4882a593Smuzhiyun		   case " $xrpath " in
8507*4882a593Smuzhiyun		   *" $temp_xrpath "*) ;;
8508*4882a593Smuzhiyun		   *) func_append xrpath " $temp_xrpath";;
8509*4882a593Smuzhiyun		   esac;;
8510*4882a593Smuzhiyun	      *) func_append temp_deplibs " $libdir";;
8511*4882a593Smuzhiyun	      esac
8512*4882a593Smuzhiyun	    done
8513*4882a593Smuzhiyun	    dependency_libs=$temp_deplibs
8514*4882a593Smuzhiyun	  fi
8515*4882a593Smuzhiyun
8516*4882a593Smuzhiyun	  func_append newlib_search_path " $absdir"
8517*4882a593Smuzhiyun	  # Link against this library
8518*4882a593Smuzhiyun	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8519*4882a593Smuzhiyun	  # ... and its dependency_libs
8520*4882a593Smuzhiyun	  tmp_libs=
8521*4882a593Smuzhiyun	  for deplib in $dependency_libs; do
8522*4882a593Smuzhiyun	    newdependency_libs="$deplib $newdependency_libs"
8523*4882a593Smuzhiyun	    case $deplib in
8524*4882a593Smuzhiyun              -L*) func_stripname '-L' '' "$deplib"
8525*4882a593Smuzhiyun                   func_resolve_sysroot "$func_stripname_result";;
8526*4882a593Smuzhiyun              *) func_resolve_sysroot "$deplib" ;;
8527*4882a593Smuzhiyun            esac
8528*4882a593Smuzhiyun	    if $opt_preserve_dup_deps; then
8529*4882a593Smuzhiyun	      case "$tmp_libs " in
8530*4882a593Smuzhiyun	      *" $func_resolve_sysroot_result "*)
8531*4882a593Smuzhiyun                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8532*4882a593Smuzhiyun	      esac
8533*4882a593Smuzhiyun	    fi
8534*4882a593Smuzhiyun	    func_append tmp_libs " $func_resolve_sysroot_result"
8535*4882a593Smuzhiyun	  done
8536*4882a593Smuzhiyun
8537*4882a593Smuzhiyun	  if test no != "$link_all_deplibs"; then
8538*4882a593Smuzhiyun	    # Add the search paths of all dependency libraries
8539*4882a593Smuzhiyun	    for deplib in $dependency_libs; do
8540*4882a593Smuzhiyun	      path=
8541*4882a593Smuzhiyun	      case $deplib in
8542*4882a593Smuzhiyun	      -L*) path=$deplib ;;
8543*4882a593Smuzhiyun	      *.la)
8544*4882a593Smuzhiyun	        func_resolve_sysroot "$deplib"
8545*4882a593Smuzhiyun	        deplib=$func_resolve_sysroot_result
8546*4882a593Smuzhiyun	        func_dirname "$deplib" "" "."
8547*4882a593Smuzhiyun		dir=$func_dirname_result
8548*4882a593Smuzhiyun		# We need an absolute path.
8549*4882a593Smuzhiyun		case $dir in
8550*4882a593Smuzhiyun		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8551*4882a593Smuzhiyun		*)
8552*4882a593Smuzhiyun		  absdir=`cd "$dir" && pwd`
8553*4882a593Smuzhiyun		  if test -z "$absdir"; then
8554*4882a593Smuzhiyun		    func_warning "cannot determine absolute directory name of '$dir'"
8555*4882a593Smuzhiyun		    absdir=$dir
8556*4882a593Smuzhiyun		  fi
8557*4882a593Smuzhiyun		  ;;
8558*4882a593Smuzhiyun		esac
8559*4882a593Smuzhiyun		if $GREP "^installed=no" $deplib > /dev/null; then
8560*4882a593Smuzhiyun		case $host in
8561*4882a593Smuzhiyun		*-*-darwin*)
8562*4882a593Smuzhiyun		  depdepl=
8563*4882a593Smuzhiyun		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8564*4882a593Smuzhiyun		  if test -n "$deplibrary_names"; then
8565*4882a593Smuzhiyun		    for tmp in $deplibrary_names; do
8566*4882a593Smuzhiyun		      depdepl=$tmp
8567*4882a593Smuzhiyun		    done
8568*4882a593Smuzhiyun		    if test -f "$absdir/$objdir/$depdepl"; then
8569*4882a593Smuzhiyun		      depdepl=$absdir/$objdir/$depdepl
8570*4882a593Smuzhiyun		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8571*4882a593Smuzhiyun                      if test -z "$darwin_install_name"; then
8572*4882a593Smuzhiyun                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8573*4882a593Smuzhiyun                      fi
8574*4882a593Smuzhiyun		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8575*4882a593Smuzhiyun		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8576*4882a593Smuzhiyun		      path=
8577*4882a593Smuzhiyun		    fi
8578*4882a593Smuzhiyun		  fi
8579*4882a593Smuzhiyun		  ;;
8580*4882a593Smuzhiyun		*)
8581*4882a593Smuzhiyun		  path=-L$absdir/$objdir
8582*4882a593Smuzhiyun		  ;;
8583*4882a593Smuzhiyun		esac
8584*4882a593Smuzhiyun		else
8585*4882a593Smuzhiyun		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8586*4882a593Smuzhiyun		  test -z "$libdir" && \
8587*4882a593Smuzhiyun		    func_fatal_error "'$deplib' is not a valid libtool archive"
8588*4882a593Smuzhiyun		  test "$absdir" != "$libdir" && \
8589*4882a593Smuzhiyun		    func_warning "'$deplib' seems to be moved"
8590*4882a593Smuzhiyun
8591*4882a593Smuzhiyun		  path=-L$absdir
8592*4882a593Smuzhiyun		fi
8593*4882a593Smuzhiyun		;;
8594*4882a593Smuzhiyun	      esac
8595*4882a593Smuzhiyun	      case " $deplibs " in
8596*4882a593Smuzhiyun	      *" $path "*) ;;
8597*4882a593Smuzhiyun	      *) deplibs="$path $deplibs" ;;
8598*4882a593Smuzhiyun	      esac
8599*4882a593Smuzhiyun	    done
8600*4882a593Smuzhiyun	  fi # link_all_deplibs != no
8601*4882a593Smuzhiyun	fi # linkmode = lib
8602*4882a593Smuzhiyun      done # for deplib in $libs
8603*4882a593Smuzhiyun      if test link = "$pass"; then
8604*4882a593Smuzhiyun	if test prog = "$linkmode"; then
8605*4882a593Smuzhiyun	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8606*4882a593Smuzhiyun	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8607*4882a593Smuzhiyun	else
8608*4882a593Smuzhiyun	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8609*4882a593Smuzhiyun	fi
8610*4882a593Smuzhiyun      fi
8611*4882a593Smuzhiyun      dependency_libs=$newdependency_libs
8612*4882a593Smuzhiyun      if test dlpreopen = "$pass"; then
8613*4882a593Smuzhiyun	# Link the dlpreopened libraries before other libraries
8614*4882a593Smuzhiyun	for deplib in $save_deplibs; do
8615*4882a593Smuzhiyun	  deplibs="$deplib $deplibs"
8616*4882a593Smuzhiyun	done
8617*4882a593Smuzhiyun      fi
8618*4882a593Smuzhiyun      if test dlopen != "$pass"; then
8619*4882a593Smuzhiyun	test conv = "$pass" || {
8620*4882a593Smuzhiyun	  # Make sure lib_search_path contains only unique directories.
8621*4882a593Smuzhiyun	  lib_search_path=
8622*4882a593Smuzhiyun	  for dir in $newlib_search_path; do
8623*4882a593Smuzhiyun	    case "$lib_search_path " in
8624*4882a593Smuzhiyun	    *" $dir "*) ;;
8625*4882a593Smuzhiyun	    *) func_append lib_search_path " $dir" ;;
8626*4882a593Smuzhiyun	    esac
8627*4882a593Smuzhiyun	  done
8628*4882a593Smuzhiyun	  newlib_search_path=
8629*4882a593Smuzhiyun	}
8630*4882a593Smuzhiyun
8631*4882a593Smuzhiyun	if test prog,link = "$linkmode,$pass"; then
8632*4882a593Smuzhiyun	  vars="compile_deplibs finalize_deplibs"
8633*4882a593Smuzhiyun	else
8634*4882a593Smuzhiyun	  vars=deplibs
8635*4882a593Smuzhiyun	fi
8636*4882a593Smuzhiyun	for var in $vars dependency_libs; do
8637*4882a593Smuzhiyun	  # Add libraries to $var in reverse order
8638*4882a593Smuzhiyun	  eval tmp_libs=\"\$$var\"
8639*4882a593Smuzhiyun	  new_libs=
8640*4882a593Smuzhiyun	  for deplib in $tmp_libs; do
8641*4882a593Smuzhiyun	    # FIXME: Pedantically, this is the right thing to do, so
8642*4882a593Smuzhiyun	    #        that some nasty dependency loop isn't accidentally
8643*4882a593Smuzhiyun	    #        broken:
8644*4882a593Smuzhiyun	    #new_libs="$deplib $new_libs"
8645*4882a593Smuzhiyun	    # Pragmatically, this seems to cause very few problems in
8646*4882a593Smuzhiyun	    # practice:
8647*4882a593Smuzhiyun	    case $deplib in
8648*4882a593Smuzhiyun	    -L*) new_libs="$deplib $new_libs" ;;
8649*4882a593Smuzhiyun	    -R*) ;;
8650*4882a593Smuzhiyun	    *)
8651*4882a593Smuzhiyun	      # And here is the reason: when a library appears more
8652*4882a593Smuzhiyun	      # than once as an explicit dependence of a library, or
8653*4882a593Smuzhiyun	      # is implicitly linked in more than once by the
8654*4882a593Smuzhiyun	      # compiler, it is considered special, and multiple
8655*4882a593Smuzhiyun	      # occurrences thereof are not removed.  Compare this
8656*4882a593Smuzhiyun	      # with having the same library being listed as a
8657*4882a593Smuzhiyun	      # dependency of multiple other libraries: in this case,
8658*4882a593Smuzhiyun	      # we know (pedantically, we assume) the library does not
8659*4882a593Smuzhiyun	      # need to be listed more than once, so we keep only the
8660*4882a593Smuzhiyun	      # last copy.  This is not always right, but it is rare
8661*4882a593Smuzhiyun	      # enough that we require users that really mean to play
8662*4882a593Smuzhiyun	      # such unportable linking tricks to link the library
8663*4882a593Smuzhiyun	      # using -Wl,-lname, so that libtool does not consider it
8664*4882a593Smuzhiyun	      # for duplicate removal.
8665*4882a593Smuzhiyun	      case " $specialdeplibs " in
8666*4882a593Smuzhiyun	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8667*4882a593Smuzhiyun	      *)
8668*4882a593Smuzhiyun		case " $new_libs " in
8669*4882a593Smuzhiyun		*" $deplib "*) ;;
8670*4882a593Smuzhiyun		*) new_libs="$deplib $new_libs" ;;
8671*4882a593Smuzhiyun		esac
8672*4882a593Smuzhiyun		;;
8673*4882a593Smuzhiyun	      esac
8674*4882a593Smuzhiyun	      ;;
8675*4882a593Smuzhiyun	    esac
8676*4882a593Smuzhiyun	  done
8677*4882a593Smuzhiyun	  tmp_libs=
8678*4882a593Smuzhiyun	  for deplib in $new_libs; do
8679*4882a593Smuzhiyun	    case $deplib in
8680*4882a593Smuzhiyun	    -L*)
8681*4882a593Smuzhiyun	      case " $tmp_libs " in
8682*4882a593Smuzhiyun	      *" $deplib "*) ;;
8683*4882a593Smuzhiyun	      *) func_append tmp_libs " $deplib" ;;
8684*4882a593Smuzhiyun	      esac
8685*4882a593Smuzhiyun	      ;;
8686*4882a593Smuzhiyun	    *) func_append tmp_libs " $deplib" ;;
8687*4882a593Smuzhiyun	    esac
8688*4882a593Smuzhiyun	  done
8689*4882a593Smuzhiyun	  eval $var=\"$tmp_libs\"
8690*4882a593Smuzhiyun	done # for var
8691*4882a593Smuzhiyun      fi
8692*4882a593Smuzhiyun
8693*4882a593Smuzhiyun      # Add Sun CC postdeps if required:
8694*4882a593Smuzhiyun      test CXX = "$tagname" && {
8695*4882a593Smuzhiyun        case $host_os in
8696*4882a593Smuzhiyun        linux*)
8697*4882a593Smuzhiyun          case `$CC -V 2>&1 | sed 5q` in
8698*4882a593Smuzhiyun          *Sun\ C*) # Sun C++ 5.9
8699*4882a593Smuzhiyun            func_suncc_cstd_abi
8700*4882a593Smuzhiyun
8701*4882a593Smuzhiyun            if test no != "$suncc_use_cstd_abi"; then
8702*4882a593Smuzhiyun              func_append postdeps ' -library=Cstd -library=Crun'
8703*4882a593Smuzhiyun            fi
8704*4882a593Smuzhiyun            ;;
8705*4882a593Smuzhiyun          esac
8706*4882a593Smuzhiyun          ;;
8707*4882a593Smuzhiyun
8708*4882a593Smuzhiyun        solaris*)
8709*4882a593Smuzhiyun          func_cc_basename "$CC"
8710*4882a593Smuzhiyun          case $func_cc_basename_result in
8711*4882a593Smuzhiyun          CC* | sunCC*)
8712*4882a593Smuzhiyun            func_suncc_cstd_abi
8713*4882a593Smuzhiyun
8714*4882a593Smuzhiyun            if test no != "$suncc_use_cstd_abi"; then
8715*4882a593Smuzhiyun              func_append postdeps ' -library=Cstd -library=Crun'
8716*4882a593Smuzhiyun            fi
8717*4882a593Smuzhiyun            ;;
8718*4882a593Smuzhiyun          esac
8719*4882a593Smuzhiyun          ;;
8720*4882a593Smuzhiyun        esac
8721*4882a593Smuzhiyun      }
8722*4882a593Smuzhiyun
8723*4882a593Smuzhiyun      # Last step: remove runtime libs from dependency_libs
8724*4882a593Smuzhiyun      # (they stay in deplibs)
8725*4882a593Smuzhiyun      tmp_libs=
8726*4882a593Smuzhiyun      for i in $dependency_libs; do
8727*4882a593Smuzhiyun	case " $predeps $postdeps $compiler_lib_search_path " in
8728*4882a593Smuzhiyun	*" $i "*)
8729*4882a593Smuzhiyun	  i=
8730*4882a593Smuzhiyun	  ;;
8731*4882a593Smuzhiyun	esac
8732*4882a593Smuzhiyun	if test -n "$i"; then
8733*4882a593Smuzhiyun	  func_append tmp_libs " $i"
8734*4882a593Smuzhiyun	fi
8735*4882a593Smuzhiyun      done
8736*4882a593Smuzhiyun      dependency_libs=$tmp_libs
8737*4882a593Smuzhiyun    done # for pass
8738*4882a593Smuzhiyun    if test prog = "$linkmode"; then
8739*4882a593Smuzhiyun      dlfiles=$newdlfiles
8740*4882a593Smuzhiyun    fi
8741*4882a593Smuzhiyun    if test prog = "$linkmode" || test lib = "$linkmode"; then
8742*4882a593Smuzhiyun      dlprefiles=$newdlprefiles
8743*4882a593Smuzhiyun    fi
8744*4882a593Smuzhiyun
8745*4882a593Smuzhiyun    case $linkmode in
8746*4882a593Smuzhiyun    oldlib)
8747*4882a593Smuzhiyun      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8748*4882a593Smuzhiyun	func_warning "'-dlopen' is ignored for archives"
8749*4882a593Smuzhiyun      fi
8750*4882a593Smuzhiyun
8751*4882a593Smuzhiyun      case " $deplibs" in
8752*4882a593Smuzhiyun      *\ -l* | *\ -L*)
8753*4882a593Smuzhiyun	func_warning "'-l' and '-L' are ignored for archives" ;;
8754*4882a593Smuzhiyun      esac
8755*4882a593Smuzhiyun
8756*4882a593Smuzhiyun      test -n "$rpath" && \
8757*4882a593Smuzhiyun	func_warning "'-rpath' is ignored for archives"
8758*4882a593Smuzhiyun
8759*4882a593Smuzhiyun      test -n "$xrpath" && \
8760*4882a593Smuzhiyun	func_warning "'-R' is ignored for archives"
8761*4882a593Smuzhiyun
8762*4882a593Smuzhiyun      test -n "$vinfo" && \
8763*4882a593Smuzhiyun	func_warning "'-version-info/-version-number' is ignored for archives"
8764*4882a593Smuzhiyun
8765*4882a593Smuzhiyun      test -n "$release" && \
8766*4882a593Smuzhiyun	func_warning "'-release' is ignored for archives"
8767*4882a593Smuzhiyun
8768*4882a593Smuzhiyun      test -n "$export_symbols$export_symbols_regex" && \
8769*4882a593Smuzhiyun	func_warning "'-export-symbols' is ignored for archives"
8770*4882a593Smuzhiyun
8771*4882a593Smuzhiyun      # Now set the variables for building old libraries.
8772*4882a593Smuzhiyun      build_libtool_libs=no
8773*4882a593Smuzhiyun      oldlibs=$output
8774*4882a593Smuzhiyun      func_append objs "$old_deplibs"
8775*4882a593Smuzhiyun      ;;
8776*4882a593Smuzhiyun
8777*4882a593Smuzhiyun    lib)
8778*4882a593Smuzhiyun      # Make sure we only generate libraries of the form 'libNAME.la'.
8779*4882a593Smuzhiyun      case $outputname in
8780*4882a593Smuzhiyun      lib*)
8781*4882a593Smuzhiyun	func_stripname 'lib' '.la' "$outputname"
8782*4882a593Smuzhiyun	name=$func_stripname_result
8783*4882a593Smuzhiyun	eval shared_ext=\"$shrext_cmds\"
8784*4882a593Smuzhiyun	eval libname=\"$libname_spec\"
8785*4882a593Smuzhiyun	;;
8786*4882a593Smuzhiyun      *)
8787*4882a593Smuzhiyun	test no = "$module" \
8788*4882a593Smuzhiyun	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
8789*4882a593Smuzhiyun
8790*4882a593Smuzhiyun	if test no != "$need_lib_prefix"; then
8791*4882a593Smuzhiyun	  # Add the "lib" prefix for modules if required
8792*4882a593Smuzhiyun	  func_stripname '' '.la' "$outputname"
8793*4882a593Smuzhiyun	  name=$func_stripname_result
8794*4882a593Smuzhiyun	  eval shared_ext=\"$shrext_cmds\"
8795*4882a593Smuzhiyun	  eval libname=\"$libname_spec\"
8796*4882a593Smuzhiyun	else
8797*4882a593Smuzhiyun	  func_stripname '' '.la' "$outputname"
8798*4882a593Smuzhiyun	  libname=$func_stripname_result
8799*4882a593Smuzhiyun	fi
8800*4882a593Smuzhiyun	;;
8801*4882a593Smuzhiyun      esac
8802*4882a593Smuzhiyun
8803*4882a593Smuzhiyun      if test -n "$objs"; then
8804*4882a593Smuzhiyun	if test pass_all != "$deplibs_check_method"; then
8805*4882a593Smuzhiyun	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
8806*4882a593Smuzhiyun	else
8807*4882a593Smuzhiyun	  echo
8808*4882a593Smuzhiyun	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
8809*4882a593Smuzhiyun	  $ECHO "*** objects $objs is not portable!"
8810*4882a593Smuzhiyun	  func_append libobjs " $objs"
8811*4882a593Smuzhiyun	fi
8812*4882a593Smuzhiyun      fi
8813*4882a593Smuzhiyun
8814*4882a593Smuzhiyun      test no = "$dlself" \
8815*4882a593Smuzhiyun	|| func_warning "'-dlopen self' is ignored for libtool libraries"
8816*4882a593Smuzhiyun
8817*4882a593Smuzhiyun      set dummy $rpath
8818*4882a593Smuzhiyun      shift
8819*4882a593Smuzhiyun      test 1 -lt "$#" \
8820*4882a593Smuzhiyun	&& func_warning "ignoring multiple '-rpath's for a libtool library"
8821*4882a593Smuzhiyun
8822*4882a593Smuzhiyun      install_libdir=$1
8823*4882a593Smuzhiyun
8824*4882a593Smuzhiyun      oldlibs=
8825*4882a593Smuzhiyun      if test -z "$rpath"; then
8826*4882a593Smuzhiyun	if test yes = "$build_libtool_libs"; then
8827*4882a593Smuzhiyun	  # Building a libtool convenience library.
8828*4882a593Smuzhiyun	  # Some compilers have problems with a '.al' extension so
8829*4882a593Smuzhiyun	  # convenience libraries should have the same extension an
8830*4882a593Smuzhiyun	  # archive normally would.
8831*4882a593Smuzhiyun	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
8832*4882a593Smuzhiyun	  build_libtool_libs=convenience
8833*4882a593Smuzhiyun	  build_old_libs=yes
8834*4882a593Smuzhiyun	fi
8835*4882a593Smuzhiyun
8836*4882a593Smuzhiyun	test -n "$vinfo" && \
8837*4882a593Smuzhiyun	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
8838*4882a593Smuzhiyun
8839*4882a593Smuzhiyun	test -n "$release" && \
8840*4882a593Smuzhiyun	  func_warning "'-release' is ignored for convenience libraries"
8841*4882a593Smuzhiyun      else
8842*4882a593Smuzhiyun
8843*4882a593Smuzhiyun	# Parse the version information argument.
8844*4882a593Smuzhiyun	save_ifs=$IFS; IFS=:
8845*4882a593Smuzhiyun	set dummy $vinfo 0 0 0
8846*4882a593Smuzhiyun	shift
8847*4882a593Smuzhiyun	IFS=$save_ifs
8848*4882a593Smuzhiyun
8849*4882a593Smuzhiyun	test -n "$7" && \
8850*4882a593Smuzhiyun	  func_fatal_help "too many parameters to '-version-info'"
8851*4882a593Smuzhiyun
8852*4882a593Smuzhiyun	# convert absolute version numbers to libtool ages
8853*4882a593Smuzhiyun	# this retains compatibility with .la files and attempts
8854*4882a593Smuzhiyun	# to make the code below a bit more comprehensible
8855*4882a593Smuzhiyun
8856*4882a593Smuzhiyun	case $vinfo_number in
8857*4882a593Smuzhiyun	yes)
8858*4882a593Smuzhiyun	  number_major=$1
8859*4882a593Smuzhiyun	  number_minor=$2
8860*4882a593Smuzhiyun	  number_revision=$3
8861*4882a593Smuzhiyun	  #
8862*4882a593Smuzhiyun	  # There are really only two kinds -- those that
8863*4882a593Smuzhiyun	  # use the current revision as the major version
8864*4882a593Smuzhiyun	  # and those that subtract age and use age as
8865*4882a593Smuzhiyun	  # a minor version.  But, then there is irix
8866*4882a593Smuzhiyun	  # that has an extra 1 added just for fun
8867*4882a593Smuzhiyun	  #
8868*4882a593Smuzhiyun	  case $version_type in
8869*4882a593Smuzhiyun	  # correct linux to gnu/linux during the next big refactor
8870*4882a593Smuzhiyun	  darwin|freebsd-elf|linux|osf|windows|none)
8871*4882a593Smuzhiyun	    func_arith $number_major + $number_minor
8872*4882a593Smuzhiyun	    current=$func_arith_result
8873*4882a593Smuzhiyun	    age=$number_minor
8874*4882a593Smuzhiyun	    revision=$number_revision
8875*4882a593Smuzhiyun	    ;;
8876*4882a593Smuzhiyun	  freebsd-aout|qnx|sunos)
8877*4882a593Smuzhiyun	    current=$number_major
8878*4882a593Smuzhiyun	    revision=$number_minor
8879*4882a593Smuzhiyun	    age=0
8880*4882a593Smuzhiyun	    ;;
8881*4882a593Smuzhiyun	  irix|nonstopux)
8882*4882a593Smuzhiyun	    func_arith $number_major + $number_minor
8883*4882a593Smuzhiyun	    current=$func_arith_result
8884*4882a593Smuzhiyun	    age=$number_minor
8885*4882a593Smuzhiyun	    revision=$number_minor
8886*4882a593Smuzhiyun	    lt_irix_increment=no
8887*4882a593Smuzhiyun	    ;;
8888*4882a593Smuzhiyun	  esac
8889*4882a593Smuzhiyun	  ;;
8890*4882a593Smuzhiyun	no)
8891*4882a593Smuzhiyun	  current=$1
8892*4882a593Smuzhiyun	  revision=$2
8893*4882a593Smuzhiyun	  age=$3
8894*4882a593Smuzhiyun	  ;;
8895*4882a593Smuzhiyun	esac
8896*4882a593Smuzhiyun
8897*4882a593Smuzhiyun	# Check that each of the things are valid numbers.
8898*4882a593Smuzhiyun	case $current in
8899*4882a593Smuzhiyun	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]) ;;
8900*4882a593Smuzhiyun	*)
8901*4882a593Smuzhiyun	  func_error "CURRENT '$current' must be a nonnegative integer"
8902*4882a593Smuzhiyun	  func_fatal_error "'$vinfo' is not valid version information"
8903*4882a593Smuzhiyun	  ;;
8904*4882a593Smuzhiyun	esac
8905*4882a593Smuzhiyun
8906*4882a593Smuzhiyun	case $revision in
8907*4882a593Smuzhiyun	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]) ;;
8908*4882a593Smuzhiyun	*)
8909*4882a593Smuzhiyun	  func_error "REVISION '$revision' must be a nonnegative integer"
8910*4882a593Smuzhiyun	  func_fatal_error "'$vinfo' is not valid version information"
8911*4882a593Smuzhiyun	  ;;
8912*4882a593Smuzhiyun	esac
8913*4882a593Smuzhiyun
8914*4882a593Smuzhiyun	case $age in
8915*4882a593Smuzhiyun	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]) ;;
8916*4882a593Smuzhiyun	*)
8917*4882a593Smuzhiyun	  func_error "AGE '$age' must be a nonnegative integer"
8918*4882a593Smuzhiyun	  func_fatal_error "'$vinfo' is not valid version information"
8919*4882a593Smuzhiyun	  ;;
8920*4882a593Smuzhiyun	esac
8921*4882a593Smuzhiyun
8922*4882a593Smuzhiyun	if test "$age" -gt "$current"; then
8923*4882a593Smuzhiyun	  func_error "AGE '$age' is greater than the current interface number '$current'"
8924*4882a593Smuzhiyun	  func_fatal_error "'$vinfo' is not valid version information"
8925*4882a593Smuzhiyun	fi
8926*4882a593Smuzhiyun
8927*4882a593Smuzhiyun	# Calculate the version variables.
8928*4882a593Smuzhiyun	major=
8929*4882a593Smuzhiyun	versuffix=
8930*4882a593Smuzhiyun	verstring=
8931*4882a593Smuzhiyun	case $version_type in
8932*4882a593Smuzhiyun	none) ;;
8933*4882a593Smuzhiyun
8934*4882a593Smuzhiyun	darwin)
8935*4882a593Smuzhiyun	  # Like Linux, but with the current version available in
8936*4882a593Smuzhiyun	  # verstring for coding it into the library header
8937*4882a593Smuzhiyun	  func_arith $current - $age
8938*4882a593Smuzhiyun	  major=.$func_arith_result
8939*4882a593Smuzhiyun	  versuffix=$major.$age.$revision
8940*4882a593Smuzhiyun	  # Darwin ld doesn't like 0 for these options...
8941*4882a593Smuzhiyun	  func_arith $current + 1
8942*4882a593Smuzhiyun	  minor_current=$func_arith_result
8943*4882a593Smuzhiyun	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8944*4882a593Smuzhiyun	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8945*4882a593Smuzhiyun          # On Darwin other compilers
8946*4882a593Smuzhiyun          case $CC in
8947*4882a593Smuzhiyun              nagfor*)
8948*4882a593Smuzhiyun                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8949*4882a593Smuzhiyun                  ;;
8950*4882a593Smuzhiyun              *)
8951*4882a593Smuzhiyun                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8952*4882a593Smuzhiyun                  ;;
8953*4882a593Smuzhiyun          esac
8954*4882a593Smuzhiyun	  ;;
8955*4882a593Smuzhiyun
8956*4882a593Smuzhiyun	freebsd-aout)
8957*4882a593Smuzhiyun	  major=.$current
8958*4882a593Smuzhiyun	  versuffix=.$current.$revision
8959*4882a593Smuzhiyun	  ;;
8960*4882a593Smuzhiyun
8961*4882a593Smuzhiyun	freebsd-elf)
8962*4882a593Smuzhiyun	  func_arith $current - $age
8963*4882a593Smuzhiyun	  major=.$func_arith_result
8964*4882a593Smuzhiyun	  versuffix=$major.$age.$revision
8965*4882a593Smuzhiyun	  ;;
8966*4882a593Smuzhiyun
8967*4882a593Smuzhiyun	irix | nonstopux)
8968*4882a593Smuzhiyun	  if test no = "$lt_irix_increment"; then
8969*4882a593Smuzhiyun	    func_arith $current - $age
8970*4882a593Smuzhiyun	  else
8971*4882a593Smuzhiyun	    func_arith $current - $age + 1
8972*4882a593Smuzhiyun	  fi
8973*4882a593Smuzhiyun	  major=$func_arith_result
8974*4882a593Smuzhiyun
8975*4882a593Smuzhiyun	  case $version_type in
8976*4882a593Smuzhiyun	    nonstopux) verstring_prefix=nonstopux ;;
8977*4882a593Smuzhiyun	    *)         verstring_prefix=sgi ;;
8978*4882a593Smuzhiyun	  esac
8979*4882a593Smuzhiyun	  verstring=$verstring_prefix$major.$revision
8980*4882a593Smuzhiyun
8981*4882a593Smuzhiyun	  # Add in all the interfaces that we are compatible with.
8982*4882a593Smuzhiyun	  loop=$revision
8983*4882a593Smuzhiyun	  while test 0 -ne "$loop"; do
8984*4882a593Smuzhiyun	    func_arith $revision - $loop
8985*4882a593Smuzhiyun	    iface=$func_arith_result
8986*4882a593Smuzhiyun	    func_arith $loop - 1
8987*4882a593Smuzhiyun	    loop=$func_arith_result
8988*4882a593Smuzhiyun	    verstring=$verstring_prefix$major.$iface:$verstring
8989*4882a593Smuzhiyun	  done
8990*4882a593Smuzhiyun
8991*4882a593Smuzhiyun	  # Before this point, $major must not contain '.'.
8992*4882a593Smuzhiyun	  major=.$major
8993*4882a593Smuzhiyun	  versuffix=$major.$revision
8994*4882a593Smuzhiyun	  ;;
8995*4882a593Smuzhiyun
8996*4882a593Smuzhiyun	linux) # correct to gnu/linux during the next big refactor
8997*4882a593Smuzhiyun	  func_arith $current - $age
8998*4882a593Smuzhiyun	  major=.$func_arith_result
8999*4882a593Smuzhiyun	  versuffix=$major.$age.$revision
9000*4882a593Smuzhiyun	  ;;
9001*4882a593Smuzhiyun
9002*4882a593Smuzhiyun	osf)
9003*4882a593Smuzhiyun	  func_arith $current - $age
9004*4882a593Smuzhiyun	  major=.$func_arith_result
9005*4882a593Smuzhiyun	  versuffix=.$current.$age.$revision
9006*4882a593Smuzhiyun	  verstring=$current.$age.$revision
9007*4882a593Smuzhiyun
9008*4882a593Smuzhiyun	  # Add in all the interfaces that we are compatible with.
9009*4882a593Smuzhiyun	  loop=$age
9010*4882a593Smuzhiyun	  while test 0 -ne "$loop"; do
9011*4882a593Smuzhiyun	    func_arith $current - $loop
9012*4882a593Smuzhiyun	    iface=$func_arith_result
9013*4882a593Smuzhiyun	    func_arith $loop - 1
9014*4882a593Smuzhiyun	    loop=$func_arith_result
9015*4882a593Smuzhiyun	    verstring=$verstring:$iface.0
9016*4882a593Smuzhiyun	  done
9017*4882a593Smuzhiyun
9018*4882a593Smuzhiyun	  # Make executables depend on our current version.
9019*4882a593Smuzhiyun	  func_append verstring ":$current.0"
9020*4882a593Smuzhiyun	  ;;
9021*4882a593Smuzhiyun
9022*4882a593Smuzhiyun	qnx)
9023*4882a593Smuzhiyun	  major=.$current
9024*4882a593Smuzhiyun	  versuffix=.$current
9025*4882a593Smuzhiyun	  ;;
9026*4882a593Smuzhiyun
9027*4882a593Smuzhiyun	sco)
9028*4882a593Smuzhiyun	  major=.$current
9029*4882a593Smuzhiyun	  versuffix=.$current
9030*4882a593Smuzhiyun	  ;;
9031*4882a593Smuzhiyun
9032*4882a593Smuzhiyun	sunos)
9033*4882a593Smuzhiyun	  major=.$current
9034*4882a593Smuzhiyun	  versuffix=.$current.$revision
9035*4882a593Smuzhiyun	  ;;
9036*4882a593Smuzhiyun
9037*4882a593Smuzhiyun	windows)
9038*4882a593Smuzhiyun	  # Use '-' rather than '.', since we only want one
9039*4882a593Smuzhiyun	  # extension on DOS 8.3 file systems.
9040*4882a593Smuzhiyun	  func_arith $current - $age
9041*4882a593Smuzhiyun	  major=$func_arith_result
9042*4882a593Smuzhiyun	  versuffix=-$major
9043*4882a593Smuzhiyun	  ;;
9044*4882a593Smuzhiyun
9045*4882a593Smuzhiyun	*)
9046*4882a593Smuzhiyun	  func_fatal_configuration "unknown library version type '$version_type'"
9047*4882a593Smuzhiyun	  ;;
9048*4882a593Smuzhiyun	esac
9049*4882a593Smuzhiyun
9050*4882a593Smuzhiyun	# Clear the version info if we defaulted, and they specified a release.
9051*4882a593Smuzhiyun	if test -z "$vinfo" && test -n "$release"; then
9052*4882a593Smuzhiyun	  major=
9053*4882a593Smuzhiyun	  case $version_type in
9054*4882a593Smuzhiyun	  darwin)
9055*4882a593Smuzhiyun	    # we can't check for "0.0" in archive_cmds due to quoting
9056*4882a593Smuzhiyun	    # problems, so we reset it completely
9057*4882a593Smuzhiyun	    verstring=
9058*4882a593Smuzhiyun	    ;;
9059*4882a593Smuzhiyun	  *)
9060*4882a593Smuzhiyun	    verstring=0.0
9061*4882a593Smuzhiyun	    ;;
9062*4882a593Smuzhiyun	  esac
9063*4882a593Smuzhiyun	  if test no = "$need_version"; then
9064*4882a593Smuzhiyun	    versuffix=
9065*4882a593Smuzhiyun	  else
9066*4882a593Smuzhiyun	    versuffix=.0.0
9067*4882a593Smuzhiyun	  fi
9068*4882a593Smuzhiyun	fi
9069*4882a593Smuzhiyun
9070*4882a593Smuzhiyun	# Remove version info from name if versioning should be avoided
9071*4882a593Smuzhiyun	if test yes,no = "$avoid_version,$need_version"; then
9072*4882a593Smuzhiyun	  major=
9073*4882a593Smuzhiyun	  versuffix=
9074*4882a593Smuzhiyun	  verstring=
9075*4882a593Smuzhiyun	fi
9076*4882a593Smuzhiyun
9077*4882a593Smuzhiyun	# Check to see if the archive will have undefined symbols.
9078*4882a593Smuzhiyun	if test yes = "$allow_undefined"; then
9079*4882a593Smuzhiyun	  if test unsupported = "$allow_undefined_flag"; then
9080*4882a593Smuzhiyun	    if test yes = "$build_old_libs"; then
9081*4882a593Smuzhiyun	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9082*4882a593Smuzhiyun	      build_libtool_libs=no
9083*4882a593Smuzhiyun	    else
9084*4882a593Smuzhiyun	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9085*4882a593Smuzhiyun	    fi
9086*4882a593Smuzhiyun	  fi
9087*4882a593Smuzhiyun	else
9088*4882a593Smuzhiyun	  # Don't allow undefined symbols.
9089*4882a593Smuzhiyun	  allow_undefined_flag=$no_undefined_flag
9090*4882a593Smuzhiyun	fi
9091*4882a593Smuzhiyun
9092*4882a593Smuzhiyun      fi
9093*4882a593Smuzhiyun
9094*4882a593Smuzhiyun      func_generate_dlsyms "$libname" "$libname" :
9095*4882a593Smuzhiyun      func_append libobjs " $symfileobj"
9096*4882a593Smuzhiyun      test " " = "$libobjs" && libobjs=
9097*4882a593Smuzhiyun
9098*4882a593Smuzhiyun      if test relink != "$opt_mode"; then
9099*4882a593Smuzhiyun	# Remove our outputs, but don't remove object files since they
9100*4882a593Smuzhiyun	# may have been created when compiling PIC objects.
9101*4882a593Smuzhiyun	removelist=
9102*4882a593Smuzhiyun	tempremovelist=`$ECHO "$output_objdir/*"`
9103*4882a593Smuzhiyun	for p in $tempremovelist; do
9104*4882a593Smuzhiyun	  case $p in
9105*4882a593Smuzhiyun	    *.$objext | *.gcno)
9106*4882a593Smuzhiyun	       ;;
9107*4882a593Smuzhiyun	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9108*4882a593Smuzhiyun	       if test -n "$precious_files_regex"; then
9109*4882a593Smuzhiyun		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9110*4882a593Smuzhiyun		 then
9111*4882a593Smuzhiyun		   continue
9112*4882a593Smuzhiyun		 fi
9113*4882a593Smuzhiyun	       fi
9114*4882a593Smuzhiyun	       func_append removelist " $p"
9115*4882a593Smuzhiyun	       ;;
9116*4882a593Smuzhiyun	    *) ;;
9117*4882a593Smuzhiyun	  esac
9118*4882a593Smuzhiyun	done
9119*4882a593Smuzhiyun	test -n "$removelist" && \
9120*4882a593Smuzhiyun	  func_show_eval "${RM}r \$removelist"
9121*4882a593Smuzhiyun      fi
9122*4882a593Smuzhiyun
9123*4882a593Smuzhiyun      # Now set the variables for building old libraries.
9124*4882a593Smuzhiyun      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9125*4882a593Smuzhiyun	func_append oldlibs " $output_objdir/$libname.$libext"
9126*4882a593Smuzhiyun
9127*4882a593Smuzhiyun	# Transform .lo files to .o files.
9128*4882a593Smuzhiyun	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9129*4882a593Smuzhiyun      fi
9130*4882a593Smuzhiyun
9131*4882a593Smuzhiyun      # Eliminate all temporary directories.
9132*4882a593Smuzhiyun      #for path in $notinst_path; do
9133*4882a593Smuzhiyun      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9134*4882a593Smuzhiyun      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9135*4882a593Smuzhiyun      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9136*4882a593Smuzhiyun      #done
9137*4882a593Smuzhiyun
9138*4882a593Smuzhiyun      if test -n "$xrpath"; then
9139*4882a593Smuzhiyun	# If the user specified any rpath flags, then add them.
9140*4882a593Smuzhiyun	temp_xrpath=
9141*4882a593Smuzhiyun	for libdir in $xrpath; do
9142*4882a593Smuzhiyun	  func_replace_sysroot "$libdir"
9143*4882a593Smuzhiyun	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9144*4882a593Smuzhiyun	  case "$finalize_rpath " in
9145*4882a593Smuzhiyun	  *" $libdir "*) ;;
9146*4882a593Smuzhiyun	  *) func_append finalize_rpath " $libdir" ;;
9147*4882a593Smuzhiyun	  esac
9148*4882a593Smuzhiyun	done
9149*4882a593Smuzhiyun	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9150*4882a593Smuzhiyun	  dependency_libs="$temp_xrpath $dependency_libs"
9151*4882a593Smuzhiyun	fi
9152*4882a593Smuzhiyun      fi
9153*4882a593Smuzhiyun
9154*4882a593Smuzhiyun      # Make sure dlfiles contains only unique files that won't be dlpreopened
9155*4882a593Smuzhiyun      old_dlfiles=$dlfiles
9156*4882a593Smuzhiyun      dlfiles=
9157*4882a593Smuzhiyun      for lib in $old_dlfiles; do
9158*4882a593Smuzhiyun	case " $dlprefiles $dlfiles " in
9159*4882a593Smuzhiyun	*" $lib "*) ;;
9160*4882a593Smuzhiyun	*) func_append dlfiles " $lib" ;;
9161*4882a593Smuzhiyun	esac
9162*4882a593Smuzhiyun      done
9163*4882a593Smuzhiyun
9164*4882a593Smuzhiyun      # Make sure dlprefiles contains only unique files
9165*4882a593Smuzhiyun      old_dlprefiles=$dlprefiles
9166*4882a593Smuzhiyun      dlprefiles=
9167*4882a593Smuzhiyun      for lib in $old_dlprefiles; do
9168*4882a593Smuzhiyun	case "$dlprefiles " in
9169*4882a593Smuzhiyun	*" $lib "*) ;;
9170*4882a593Smuzhiyun	*) func_append dlprefiles " $lib" ;;
9171*4882a593Smuzhiyun	esac
9172*4882a593Smuzhiyun      done
9173*4882a593Smuzhiyun
9174*4882a593Smuzhiyun      if test yes = "$build_libtool_libs"; then
9175*4882a593Smuzhiyun	if test -n "$rpath"; then
9176*4882a593Smuzhiyun	  case $host in
9177*4882a593Smuzhiyun	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9178*4882a593Smuzhiyun	    # these systems don't actually have a c library (as such)!
9179*4882a593Smuzhiyun	    ;;
9180*4882a593Smuzhiyun	  *-*-rhapsody* | *-*-darwin1.[012])
9181*4882a593Smuzhiyun	    # Rhapsody C library is in the System framework
9182*4882a593Smuzhiyun	    func_append deplibs " System.ltframework"
9183*4882a593Smuzhiyun	    ;;
9184*4882a593Smuzhiyun	  *-*-netbsd*)
9185*4882a593Smuzhiyun	    # Don't link with libc until the a.out ld.so is fixed.
9186*4882a593Smuzhiyun	    ;;
9187*4882a593Smuzhiyun	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
9188*4882a593Smuzhiyun	    # Do not include libc due to us having libc/libc_r.
9189*4882a593Smuzhiyun	    ;;
9190*4882a593Smuzhiyun	  *-*-sco3.2v5* | *-*-sco5v6*)
9191*4882a593Smuzhiyun	    # Causes problems with __ctype
9192*4882a593Smuzhiyun	    ;;
9193*4882a593Smuzhiyun	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9194*4882a593Smuzhiyun	    # Compiler inserts libc in the correct place for threads to work
9195*4882a593Smuzhiyun	    ;;
9196*4882a593Smuzhiyun	  *)
9197*4882a593Smuzhiyun	    # Add libc to deplibs on all other systems if necessary.
9198*4882a593Smuzhiyun	    if test yes = "$build_libtool_need_lc"; then
9199*4882a593Smuzhiyun	      func_append deplibs " -lc"
9200*4882a593Smuzhiyun	    fi
9201*4882a593Smuzhiyun	    ;;
9202*4882a593Smuzhiyun	  esac
9203*4882a593Smuzhiyun	fi
9204*4882a593Smuzhiyun
9205*4882a593Smuzhiyun	# Transform deplibs into only deplibs that can be linked in shared.
9206*4882a593Smuzhiyun	name_save=$name
9207*4882a593Smuzhiyun	libname_save=$libname
9208*4882a593Smuzhiyun	release_save=$release
9209*4882a593Smuzhiyun	versuffix_save=$versuffix
9210*4882a593Smuzhiyun	major_save=$major
9211*4882a593Smuzhiyun	# I'm not sure if I'm treating the release correctly.  I think
9212*4882a593Smuzhiyun	# release should show up in the -l (ie -lgmp5) so we don't want to
9213*4882a593Smuzhiyun	# add it in twice.  Is that correct?
9214*4882a593Smuzhiyun	release=
9215*4882a593Smuzhiyun	versuffix=
9216*4882a593Smuzhiyun	major=
9217*4882a593Smuzhiyun	newdeplibs=
9218*4882a593Smuzhiyun	droppeddeps=no
9219*4882a593Smuzhiyun	case $deplibs_check_method in
9220*4882a593Smuzhiyun	pass_all)
9221*4882a593Smuzhiyun	  # Don't check for shared/static.  Everything works.
9222*4882a593Smuzhiyun	  # This might be a little naive.  We might want to check
9223*4882a593Smuzhiyun	  # whether the library exists or not.  But this is on
9224*4882a593Smuzhiyun	  # osf3 & osf4 and I'm not really sure... Just
9225*4882a593Smuzhiyun	  # implementing what was already the behavior.
9226*4882a593Smuzhiyun	  newdeplibs=$deplibs
9227*4882a593Smuzhiyun	  ;;
9228*4882a593Smuzhiyun	test_compile)
9229*4882a593Smuzhiyun	  # This code stresses the "libraries are programs" paradigm to its
9230*4882a593Smuzhiyun	  # limits. Maybe even breaks it.  We compile a program, linking it
9231*4882a593Smuzhiyun	  # against the deplibs as a proxy for the library.  Then we can check
9232*4882a593Smuzhiyun	  # whether they linked in statically or dynamically with ldd.
9233*4882a593Smuzhiyun	  $opt_dry_run || $RM conftest.c
9234*4882a593Smuzhiyun	  cat > conftest.c <<EOF
9235*4882a593Smuzhiyun	  int main() { return 0; }
9236*4882a593SmuzhiyunEOF
9237*4882a593Smuzhiyun	  $opt_dry_run || $RM conftest
9238*4882a593Smuzhiyun	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9239*4882a593Smuzhiyun	    ldd_output=`ldd conftest`
9240*4882a593Smuzhiyun	    for i in $deplibs; do
9241*4882a593Smuzhiyun	      case $i in
9242*4882a593Smuzhiyun	      -l*)
9243*4882a593Smuzhiyun		func_stripname -l '' "$i"
9244*4882a593Smuzhiyun		name=$func_stripname_result
9245*4882a593Smuzhiyun		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9246*4882a593Smuzhiyun		  case " $predeps $postdeps " in
9247*4882a593Smuzhiyun		  *" $i "*)
9248*4882a593Smuzhiyun		    func_append newdeplibs " $i"
9249*4882a593Smuzhiyun		    i=
9250*4882a593Smuzhiyun		    ;;
9251*4882a593Smuzhiyun		  esac
9252*4882a593Smuzhiyun		fi
9253*4882a593Smuzhiyun		if test -n "$i"; then
9254*4882a593Smuzhiyun		  libname=`eval "\\$ECHO \"$libname_spec\""`
9255*4882a593Smuzhiyun		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9256*4882a593Smuzhiyun		  set dummy $deplib_matches; shift
9257*4882a593Smuzhiyun		  deplib_match=$1
9258*4882a593Smuzhiyun		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9259*4882a593Smuzhiyun		    func_append newdeplibs " $i"
9260*4882a593Smuzhiyun		  else
9261*4882a593Smuzhiyun		    droppeddeps=yes
9262*4882a593Smuzhiyun		    echo
9263*4882a593Smuzhiyun		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9264*4882a593Smuzhiyun		    echo "*** I have the capability to make that library automatically link in when"
9265*4882a593Smuzhiyun		    echo "*** you link to this library.  But I can only do this if you have a"
9266*4882a593Smuzhiyun		    echo "*** shared version of the library, which I believe you do not have"
9267*4882a593Smuzhiyun		    echo "*** because a test_compile did reveal that the linker did not use it for"
9268*4882a593Smuzhiyun		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9269*4882a593Smuzhiyun		  fi
9270*4882a593Smuzhiyun		fi
9271*4882a593Smuzhiyun		;;
9272*4882a593Smuzhiyun	      *)
9273*4882a593Smuzhiyun		func_append newdeplibs " $i"
9274*4882a593Smuzhiyun		;;
9275*4882a593Smuzhiyun	      esac
9276*4882a593Smuzhiyun	    done
9277*4882a593Smuzhiyun	  else
9278*4882a593Smuzhiyun	    # Error occurred in the first compile.  Let's try to salvage
9279*4882a593Smuzhiyun	    # the situation: Compile a separate program for each library.
9280*4882a593Smuzhiyun	    for i in $deplibs; do
9281*4882a593Smuzhiyun	      case $i in
9282*4882a593Smuzhiyun	      -l*)
9283*4882a593Smuzhiyun		func_stripname -l '' "$i"
9284*4882a593Smuzhiyun		name=$func_stripname_result
9285*4882a593Smuzhiyun		$opt_dry_run || $RM conftest
9286*4882a593Smuzhiyun		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9287*4882a593Smuzhiyun		  ldd_output=`ldd conftest`
9288*4882a593Smuzhiyun		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9289*4882a593Smuzhiyun		    case " $predeps $postdeps " in
9290*4882a593Smuzhiyun		    *" $i "*)
9291*4882a593Smuzhiyun		      func_append newdeplibs " $i"
9292*4882a593Smuzhiyun		      i=
9293*4882a593Smuzhiyun		      ;;
9294*4882a593Smuzhiyun		    esac
9295*4882a593Smuzhiyun		  fi
9296*4882a593Smuzhiyun		  if test -n "$i"; then
9297*4882a593Smuzhiyun		    libname=`eval "\\$ECHO \"$libname_spec\""`
9298*4882a593Smuzhiyun		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9299*4882a593Smuzhiyun		    set dummy $deplib_matches; shift
9300*4882a593Smuzhiyun		    deplib_match=$1
9301*4882a593Smuzhiyun		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9302*4882a593Smuzhiyun		      func_append newdeplibs " $i"
9303*4882a593Smuzhiyun		    else
9304*4882a593Smuzhiyun		      droppeddeps=yes
9305*4882a593Smuzhiyun		      echo
9306*4882a593Smuzhiyun		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9307*4882a593Smuzhiyun		      echo "*** I have the capability to make that library automatically link in when"
9308*4882a593Smuzhiyun		      echo "*** you link to this library.  But I can only do this if you have a"
9309*4882a593Smuzhiyun		      echo "*** shared version of the library, which you do not appear to have"
9310*4882a593Smuzhiyun		      echo "*** because a test_compile did reveal that the linker did not use this one"
9311*4882a593Smuzhiyun		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9312*4882a593Smuzhiyun		    fi
9313*4882a593Smuzhiyun		  fi
9314*4882a593Smuzhiyun		else
9315*4882a593Smuzhiyun		  droppeddeps=yes
9316*4882a593Smuzhiyun		  echo
9317*4882a593Smuzhiyun		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9318*4882a593Smuzhiyun		  echo "*** make it link in!  You will probably need to install it or some"
9319*4882a593Smuzhiyun		  echo "*** library that it depends on before this library will be fully"
9320*4882a593Smuzhiyun		  echo "*** functional.  Installing it before continuing would be even better."
9321*4882a593Smuzhiyun		fi
9322*4882a593Smuzhiyun		;;
9323*4882a593Smuzhiyun	      *)
9324*4882a593Smuzhiyun		func_append newdeplibs " $i"
9325*4882a593Smuzhiyun		;;
9326*4882a593Smuzhiyun	      esac
9327*4882a593Smuzhiyun	    done
9328*4882a593Smuzhiyun	  fi
9329*4882a593Smuzhiyun	  ;;
9330*4882a593Smuzhiyun	file_magic*)
9331*4882a593Smuzhiyun	  set dummy $deplibs_check_method; shift
9332*4882a593Smuzhiyun	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9333*4882a593Smuzhiyun	  for a_deplib in $deplibs; do
9334*4882a593Smuzhiyun	    case $a_deplib in
9335*4882a593Smuzhiyun	    -l*)
9336*4882a593Smuzhiyun	      func_stripname -l '' "$a_deplib"
9337*4882a593Smuzhiyun	      name=$func_stripname_result
9338*4882a593Smuzhiyun	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9339*4882a593Smuzhiyun		case " $predeps $postdeps " in
9340*4882a593Smuzhiyun		*" $a_deplib "*)
9341*4882a593Smuzhiyun		  func_append newdeplibs " $a_deplib"
9342*4882a593Smuzhiyun		  a_deplib=
9343*4882a593Smuzhiyun		  ;;
9344*4882a593Smuzhiyun		esac
9345*4882a593Smuzhiyun	      fi
9346*4882a593Smuzhiyun	      if test -n "$a_deplib"; then
9347*4882a593Smuzhiyun		libname=`eval "\\$ECHO \"$libname_spec\""`
9348*4882a593Smuzhiyun		if test -n "$file_magic_glob"; then
9349*4882a593Smuzhiyun		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9350*4882a593Smuzhiyun		else
9351*4882a593Smuzhiyun		  libnameglob=$libname
9352*4882a593Smuzhiyun		fi
9353*4882a593Smuzhiyun		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9354*4882a593Smuzhiyun		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9355*4882a593Smuzhiyun		  if test yes = "$want_nocaseglob"; then
9356*4882a593Smuzhiyun		    shopt -s nocaseglob
9357*4882a593Smuzhiyun		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9358*4882a593Smuzhiyun		    $nocaseglob
9359*4882a593Smuzhiyun		  else
9360*4882a593Smuzhiyun		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9361*4882a593Smuzhiyun		  fi
9362*4882a593Smuzhiyun		  for potent_lib in $potential_libs; do
9363*4882a593Smuzhiyun		      # Follow soft links.
9364*4882a593Smuzhiyun		      if ls -lLd "$potent_lib" 2>/dev/null |
9365*4882a593Smuzhiyun			 $GREP " -> " >/dev/null; then
9366*4882a593Smuzhiyun			continue
9367*4882a593Smuzhiyun		      fi
9368*4882a593Smuzhiyun		      # The statement above tries to avoid entering an
9369*4882a593Smuzhiyun		      # endless loop below, in case of cyclic links.
9370*4882a593Smuzhiyun		      # We might still enter an endless loop, since a link
9371*4882a593Smuzhiyun		      # loop can be closed while we follow links,
9372*4882a593Smuzhiyun		      # but so what?
9373*4882a593Smuzhiyun		      potlib=$potent_lib
9374*4882a593Smuzhiyun		      while test -h "$potlib" 2>/dev/null; do
9375*4882a593Smuzhiyun			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9376*4882a593Smuzhiyun			case $potliblink in
9377*4882a593Smuzhiyun			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9378*4882a593Smuzhiyun			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9379*4882a593Smuzhiyun			esac
9380*4882a593Smuzhiyun		      done
9381*4882a593Smuzhiyun		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9382*4882a593Smuzhiyun			 $SED -e 10q |
9383*4882a593Smuzhiyun			 $EGREP "$file_magic_regex" > /dev/null; then
9384*4882a593Smuzhiyun			func_append newdeplibs " $a_deplib"
9385*4882a593Smuzhiyun			a_deplib=
9386*4882a593Smuzhiyun			break 2
9387*4882a593Smuzhiyun		      fi
9388*4882a593Smuzhiyun		  done
9389*4882a593Smuzhiyun		done
9390*4882a593Smuzhiyun	      fi
9391*4882a593Smuzhiyun	      if test -n "$a_deplib"; then
9392*4882a593Smuzhiyun		droppeddeps=yes
9393*4882a593Smuzhiyun		echo
9394*4882a593Smuzhiyun		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9395*4882a593Smuzhiyun		echo "*** I have the capability to make that library automatically link in when"
9396*4882a593Smuzhiyun		echo "*** you link to this library.  But I can only do this if you have a"
9397*4882a593Smuzhiyun		echo "*** shared version of the library, which you do not appear to have"
9398*4882a593Smuzhiyun		echo "*** because I did check the linker path looking for a file starting"
9399*4882a593Smuzhiyun		if test -z "$potlib"; then
9400*4882a593Smuzhiyun		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9401*4882a593Smuzhiyun		else
9402*4882a593Smuzhiyun		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9403*4882a593Smuzhiyun		  $ECHO "*** using a file magic. Last file checked: $potlib"
9404*4882a593Smuzhiyun		fi
9405*4882a593Smuzhiyun	      fi
9406*4882a593Smuzhiyun	      ;;
9407*4882a593Smuzhiyun	    *)
9408*4882a593Smuzhiyun	      # Add a -L argument.
9409*4882a593Smuzhiyun	      func_append newdeplibs " $a_deplib"
9410*4882a593Smuzhiyun	      ;;
9411*4882a593Smuzhiyun	    esac
9412*4882a593Smuzhiyun	  done # Gone through all deplibs.
9413*4882a593Smuzhiyun	  ;;
9414*4882a593Smuzhiyun	match_pattern*)
9415*4882a593Smuzhiyun	  set dummy $deplibs_check_method; shift
9416*4882a593Smuzhiyun	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9417*4882a593Smuzhiyun	  for a_deplib in $deplibs; do
9418*4882a593Smuzhiyun	    case $a_deplib in
9419*4882a593Smuzhiyun	    -l*)
9420*4882a593Smuzhiyun	      func_stripname -l '' "$a_deplib"
9421*4882a593Smuzhiyun	      name=$func_stripname_result
9422*4882a593Smuzhiyun	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9423*4882a593Smuzhiyun		case " $predeps $postdeps " in
9424*4882a593Smuzhiyun		*" $a_deplib "*)
9425*4882a593Smuzhiyun		  func_append newdeplibs " $a_deplib"
9426*4882a593Smuzhiyun		  a_deplib=
9427*4882a593Smuzhiyun		  ;;
9428*4882a593Smuzhiyun		esac
9429*4882a593Smuzhiyun	      fi
9430*4882a593Smuzhiyun	      if test -n "$a_deplib"; then
9431*4882a593Smuzhiyun		libname=`eval "\\$ECHO \"$libname_spec\""`
9432*4882a593Smuzhiyun		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9433*4882a593Smuzhiyun		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9434*4882a593Smuzhiyun		  for potent_lib in $potential_libs; do
9435*4882a593Smuzhiyun		    potlib=$potent_lib # see symlink-check above in file_magic test
9436*4882a593Smuzhiyun		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9437*4882a593Smuzhiyun		       $EGREP "$match_pattern_regex" > /dev/null; then
9438*4882a593Smuzhiyun		      func_append newdeplibs " $a_deplib"
9439*4882a593Smuzhiyun		      a_deplib=
9440*4882a593Smuzhiyun		      break 2
9441*4882a593Smuzhiyun		    fi
9442*4882a593Smuzhiyun		  done
9443*4882a593Smuzhiyun		done
9444*4882a593Smuzhiyun	      fi
9445*4882a593Smuzhiyun	      if test -n "$a_deplib"; then
9446*4882a593Smuzhiyun		droppeddeps=yes
9447*4882a593Smuzhiyun		echo
9448*4882a593Smuzhiyun		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9449*4882a593Smuzhiyun		echo "*** I have the capability to make that library automatically link in when"
9450*4882a593Smuzhiyun		echo "*** you link to this library.  But I can only do this if you have a"
9451*4882a593Smuzhiyun		echo "*** shared version of the library, which you do not appear to have"
9452*4882a593Smuzhiyun		echo "*** because I did check the linker path looking for a file starting"
9453*4882a593Smuzhiyun		if test -z "$potlib"; then
9454*4882a593Smuzhiyun		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9455*4882a593Smuzhiyun		else
9456*4882a593Smuzhiyun		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9457*4882a593Smuzhiyun		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9458*4882a593Smuzhiyun		fi
9459*4882a593Smuzhiyun	      fi
9460*4882a593Smuzhiyun	      ;;
9461*4882a593Smuzhiyun	    *)
9462*4882a593Smuzhiyun	      # Add a -L argument.
9463*4882a593Smuzhiyun	      func_append newdeplibs " $a_deplib"
9464*4882a593Smuzhiyun	      ;;
9465*4882a593Smuzhiyun	    esac
9466*4882a593Smuzhiyun	  done # Gone through all deplibs.
9467*4882a593Smuzhiyun	  ;;
9468*4882a593Smuzhiyun	none | unknown | *)
9469*4882a593Smuzhiyun	  newdeplibs=
9470*4882a593Smuzhiyun	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9471*4882a593Smuzhiyun	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9472*4882a593Smuzhiyun	    for i in $predeps $postdeps; do
9473*4882a593Smuzhiyun	      # can't use Xsed below, because $i might contain '/'
9474*4882a593Smuzhiyun	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9475*4882a593Smuzhiyun	    done
9476*4882a593Smuzhiyun	  fi
9477*4882a593Smuzhiyun	  case $tmp_deplibs in
9478*4882a593Smuzhiyun	  *[!\	\ ]*)
9479*4882a593Smuzhiyun	    echo
9480*4882a593Smuzhiyun	    if test none = "$deplibs_check_method"; then
9481*4882a593Smuzhiyun	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9482*4882a593Smuzhiyun	    else
9483*4882a593Smuzhiyun	      echo "*** Warning: inter-library dependencies are not known to be supported."
9484*4882a593Smuzhiyun	    fi
9485*4882a593Smuzhiyun	    echo "*** All declared inter-library dependencies are being dropped."
9486*4882a593Smuzhiyun	    droppeddeps=yes
9487*4882a593Smuzhiyun	    ;;
9488*4882a593Smuzhiyun	  esac
9489*4882a593Smuzhiyun	  ;;
9490*4882a593Smuzhiyun	esac
9491*4882a593Smuzhiyun	versuffix=$versuffix_save
9492*4882a593Smuzhiyun	major=$major_save
9493*4882a593Smuzhiyun	release=$release_save
9494*4882a593Smuzhiyun	libname=$libname_save
9495*4882a593Smuzhiyun	name=$name_save
9496*4882a593Smuzhiyun
9497*4882a593Smuzhiyun	case $host in
9498*4882a593Smuzhiyun	*-*-rhapsody* | *-*-darwin1.[012])
9499*4882a593Smuzhiyun	  # On Rhapsody replace the C library with the System framework
9500*4882a593Smuzhiyun	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9501*4882a593Smuzhiyun	  ;;
9502*4882a593Smuzhiyun	esac
9503*4882a593Smuzhiyun
9504*4882a593Smuzhiyun	if test yes = "$droppeddeps"; then
9505*4882a593Smuzhiyun	  if test yes = "$module"; then
9506*4882a593Smuzhiyun	    echo
9507*4882a593Smuzhiyun	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9508*4882a593Smuzhiyun	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9509*4882a593Smuzhiyun	    echo "*** a static module, that should work as long as the dlopening"
9510*4882a593Smuzhiyun	    echo "*** application is linked with the -dlopen flag."
9511*4882a593Smuzhiyun	    if test -z "$global_symbol_pipe"; then
9512*4882a593Smuzhiyun	      echo
9513*4882a593Smuzhiyun	      echo "*** However, this would only work if libtool was able to extract symbol"
9514*4882a593Smuzhiyun	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9515*4882a593Smuzhiyun	      echo "*** not find such a program.  So, this module is probably useless."
9516*4882a593Smuzhiyun	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9517*4882a593Smuzhiyun	    fi
9518*4882a593Smuzhiyun	    if test no = "$build_old_libs"; then
9519*4882a593Smuzhiyun	      oldlibs=$output_objdir/$libname.$libext
9520*4882a593Smuzhiyun	      build_libtool_libs=module
9521*4882a593Smuzhiyun	      build_old_libs=yes
9522*4882a593Smuzhiyun	    else
9523*4882a593Smuzhiyun	      build_libtool_libs=no
9524*4882a593Smuzhiyun	    fi
9525*4882a593Smuzhiyun	  else
9526*4882a593Smuzhiyun	    echo "*** The inter-library dependencies that have been dropped here will be"
9527*4882a593Smuzhiyun	    echo "*** automatically added whenever a program is linked with this library"
9528*4882a593Smuzhiyun	    echo "*** or is declared to -dlopen it."
9529*4882a593Smuzhiyun
9530*4882a593Smuzhiyun	    if test no = "$allow_undefined"; then
9531*4882a593Smuzhiyun	      echo
9532*4882a593Smuzhiyun	      echo "*** Since this library must not contain undefined symbols,"
9533*4882a593Smuzhiyun	      echo "*** because either the platform does not support them or"
9534*4882a593Smuzhiyun	      echo "*** it was explicitly requested with -no-undefined,"
9535*4882a593Smuzhiyun	      echo "*** libtool will only create a static version of it."
9536*4882a593Smuzhiyun	      if test no = "$build_old_libs"; then
9537*4882a593Smuzhiyun		oldlibs=$output_objdir/$libname.$libext
9538*4882a593Smuzhiyun		build_libtool_libs=module
9539*4882a593Smuzhiyun		build_old_libs=yes
9540*4882a593Smuzhiyun	      else
9541*4882a593Smuzhiyun		build_libtool_libs=no
9542*4882a593Smuzhiyun	      fi
9543*4882a593Smuzhiyun	    fi
9544*4882a593Smuzhiyun	  fi
9545*4882a593Smuzhiyun	fi
9546*4882a593Smuzhiyun	# Done checking deplibs!
9547*4882a593Smuzhiyun	deplibs=$newdeplibs
9548*4882a593Smuzhiyun      fi
9549*4882a593Smuzhiyun      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9550*4882a593Smuzhiyun      case $host in
9551*4882a593Smuzhiyun	*-*-darwin*)
9552*4882a593Smuzhiyun	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9553*4882a593Smuzhiyun	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9554*4882a593Smuzhiyun	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9555*4882a593Smuzhiyun	  ;;
9556*4882a593Smuzhiyun      esac
9557*4882a593Smuzhiyun
9558*4882a593Smuzhiyun      # move library search paths that coincide with paths to not yet
9559*4882a593Smuzhiyun      # installed libraries to the beginning of the library search list
9560*4882a593Smuzhiyun      new_libs=
9561*4882a593Smuzhiyun      for path in $notinst_path; do
9562*4882a593Smuzhiyun	case " $new_libs " in
9563*4882a593Smuzhiyun	*" -L$path/$objdir "*) ;;
9564*4882a593Smuzhiyun	*)
9565*4882a593Smuzhiyun	  case " $deplibs " in
9566*4882a593Smuzhiyun	  *" -L$path/$objdir "*)
9567*4882a593Smuzhiyun	    func_append new_libs " -L$path/$objdir" ;;
9568*4882a593Smuzhiyun	  esac
9569*4882a593Smuzhiyun	  ;;
9570*4882a593Smuzhiyun	esac
9571*4882a593Smuzhiyun      done
9572*4882a593Smuzhiyun      for deplib in $deplibs; do
9573*4882a593Smuzhiyun	case $deplib in
9574*4882a593Smuzhiyun	-L*)
9575*4882a593Smuzhiyun	  case " $new_libs " in
9576*4882a593Smuzhiyun	  *" $deplib "*) ;;
9577*4882a593Smuzhiyun	  *) func_append new_libs " $deplib" ;;
9578*4882a593Smuzhiyun	  esac
9579*4882a593Smuzhiyun	  ;;
9580*4882a593Smuzhiyun	*) func_append new_libs " $deplib" ;;
9581*4882a593Smuzhiyun	esac
9582*4882a593Smuzhiyun      done
9583*4882a593Smuzhiyun      deplibs=$new_libs
9584*4882a593Smuzhiyun
9585*4882a593Smuzhiyun      # All the library-specific variables (install_libdir is set above).
9586*4882a593Smuzhiyun      library_names=
9587*4882a593Smuzhiyun      old_library=
9588*4882a593Smuzhiyun      dlname=
9589*4882a593Smuzhiyun
9590*4882a593Smuzhiyun      # Test again, we may have decided not to build it any more
9591*4882a593Smuzhiyun      if test yes = "$build_libtool_libs"; then
9592*4882a593Smuzhiyun	# Remove $wl instances when linking with ld.
9593*4882a593Smuzhiyun	# FIXME: should test the right _cmds variable.
9594*4882a593Smuzhiyun	case $archive_cmds in
9595*4882a593Smuzhiyun	  *\$LD\ *) wl= ;;
9596*4882a593Smuzhiyun        esac
9597*4882a593Smuzhiyun	if test yes = "$hardcode_into_libs"; then
9598*4882a593Smuzhiyun	  # Hardcode the library paths
9599*4882a593Smuzhiyun	  hardcode_libdirs=
9600*4882a593Smuzhiyun	  dep_rpath=
9601*4882a593Smuzhiyun	  rpath=$finalize_rpath
9602*4882a593Smuzhiyun	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9603*4882a593Smuzhiyun	  for libdir in $rpath; do
9604*4882a593Smuzhiyun	    if test -n "$hardcode_libdir_flag_spec"; then
9605*4882a593Smuzhiyun	      if test -n "$hardcode_libdir_separator"; then
9606*4882a593Smuzhiyun		func_replace_sysroot "$libdir"
9607*4882a593Smuzhiyun		libdir=$func_replace_sysroot_result
9608*4882a593Smuzhiyun		if test -z "$hardcode_libdirs"; then
9609*4882a593Smuzhiyun		  hardcode_libdirs=$libdir
9610*4882a593Smuzhiyun		else
9611*4882a593Smuzhiyun		  # Just accumulate the unique libdirs.
9612*4882a593Smuzhiyun		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9613*4882a593Smuzhiyun		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9614*4882a593Smuzhiyun		    ;;
9615*4882a593Smuzhiyun		  *)
9616*4882a593Smuzhiyun		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9617*4882a593Smuzhiyun		    ;;
9618*4882a593Smuzhiyun		  esac
9619*4882a593Smuzhiyun		fi
9620*4882a593Smuzhiyun	      else
9621*4882a593Smuzhiyun		eval flag=\"$hardcode_libdir_flag_spec\"
9622*4882a593Smuzhiyun		func_append dep_rpath " $flag"
9623*4882a593Smuzhiyun	      fi
9624*4882a593Smuzhiyun	    elif test -n "$runpath_var"; then
9625*4882a593Smuzhiyun	      case "$perm_rpath " in
9626*4882a593Smuzhiyun	      *" $libdir "*) ;;
9627*4882a593Smuzhiyun	      *) func_append perm_rpath " $libdir" ;;
9628*4882a593Smuzhiyun	      esac
9629*4882a593Smuzhiyun	    fi
9630*4882a593Smuzhiyun	  done
9631*4882a593Smuzhiyun	  # Substitute the hardcoded libdirs into the rpath.
9632*4882a593Smuzhiyun	  if test -n "$hardcode_libdir_separator" &&
9633*4882a593Smuzhiyun	     test -n "$hardcode_libdirs"; then
9634*4882a593Smuzhiyun	    libdir=$hardcode_libdirs
9635*4882a593Smuzhiyun	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9636*4882a593Smuzhiyun	  fi
9637*4882a593Smuzhiyun	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9638*4882a593Smuzhiyun	    # We should set the runpath_var.
9639*4882a593Smuzhiyun	    rpath=
9640*4882a593Smuzhiyun	    for dir in $perm_rpath; do
9641*4882a593Smuzhiyun	      func_append rpath "$dir:"
9642*4882a593Smuzhiyun	    done
9643*4882a593Smuzhiyun	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9644*4882a593Smuzhiyun	  fi
9645*4882a593Smuzhiyun	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9646*4882a593Smuzhiyun	fi
9647*4882a593Smuzhiyun
9648*4882a593Smuzhiyun	shlibpath=$finalize_shlibpath
9649*4882a593Smuzhiyun	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9650*4882a593Smuzhiyun	if test -n "$shlibpath"; then
9651*4882a593Smuzhiyun	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9652*4882a593Smuzhiyun	fi
9653*4882a593Smuzhiyun
9654*4882a593Smuzhiyun	# Get the real and link names of the library.
9655*4882a593Smuzhiyun	eval shared_ext=\"$shrext_cmds\"
9656*4882a593Smuzhiyun	eval library_names=\"$library_names_spec\"
9657*4882a593Smuzhiyun	set dummy $library_names
9658*4882a593Smuzhiyun	shift
9659*4882a593Smuzhiyun	realname=$1
9660*4882a593Smuzhiyun	shift
9661*4882a593Smuzhiyun
9662*4882a593Smuzhiyun	if test -n "$soname_spec"; then
9663*4882a593Smuzhiyun	  eval soname=\"$soname_spec\"
9664*4882a593Smuzhiyun	else
9665*4882a593Smuzhiyun	  soname=$realname
9666*4882a593Smuzhiyun	fi
9667*4882a593Smuzhiyun	if test -z "$dlname"; then
9668*4882a593Smuzhiyun	  dlname=$soname
9669*4882a593Smuzhiyun	fi
9670*4882a593Smuzhiyun
9671*4882a593Smuzhiyun	lib=$output_objdir/$realname
9672*4882a593Smuzhiyun	linknames=
9673*4882a593Smuzhiyun	for link
9674*4882a593Smuzhiyun	do
9675*4882a593Smuzhiyun	  func_append linknames " $link"
9676*4882a593Smuzhiyun	done
9677*4882a593Smuzhiyun
9678*4882a593Smuzhiyun	# Use standard objects if they are pic
9679*4882a593Smuzhiyun	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9680*4882a593Smuzhiyun	test "X$libobjs" = "X " && libobjs=
9681*4882a593Smuzhiyun
9682*4882a593Smuzhiyun	delfiles=
9683*4882a593Smuzhiyun	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9684*4882a593Smuzhiyun	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9685*4882a593Smuzhiyun	  export_symbols=$output_objdir/$libname.uexp
9686*4882a593Smuzhiyun	  func_append delfiles " $export_symbols"
9687*4882a593Smuzhiyun	fi
9688*4882a593Smuzhiyun
9689*4882a593Smuzhiyun	orig_export_symbols=
9690*4882a593Smuzhiyun	case $host_os in
9691*4882a593Smuzhiyun	cygwin* | mingw* | cegcc*)
9692*4882a593Smuzhiyun	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9693*4882a593Smuzhiyun	    # exporting using user supplied symfile
9694*4882a593Smuzhiyun	    func_dll_def_p "$export_symbols" || {
9695*4882a593Smuzhiyun	      # and it's NOT already a .def file. Must figure out
9696*4882a593Smuzhiyun	      # which of the given symbols are data symbols and tag
9697*4882a593Smuzhiyun	      # them as such. So, trigger use of export_symbols_cmds.
9698*4882a593Smuzhiyun	      # export_symbols gets reassigned inside the "prepare
9699*4882a593Smuzhiyun	      # the list of exported symbols" if statement, so the
9700*4882a593Smuzhiyun	      # include_expsyms logic still works.
9701*4882a593Smuzhiyun	      orig_export_symbols=$export_symbols
9702*4882a593Smuzhiyun	      export_symbols=
9703*4882a593Smuzhiyun	      always_export_symbols=yes
9704*4882a593Smuzhiyun	    }
9705*4882a593Smuzhiyun	  fi
9706*4882a593Smuzhiyun	  ;;
9707*4882a593Smuzhiyun	esac
9708*4882a593Smuzhiyun
9709*4882a593Smuzhiyun	# Prepare the list of exported symbols
9710*4882a593Smuzhiyun	if test -z "$export_symbols"; then
9711*4882a593Smuzhiyun	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9712*4882a593Smuzhiyun	    func_verbose "generating symbol list for '$libname.la'"
9713*4882a593Smuzhiyun	    export_symbols=$output_objdir/$libname.exp
9714*4882a593Smuzhiyun	    $opt_dry_run || $RM $export_symbols
9715*4882a593Smuzhiyun	    cmds=$export_symbols_cmds
9716*4882a593Smuzhiyun	    save_ifs=$IFS; IFS='~'
9717*4882a593Smuzhiyun	    for cmd1 in $cmds; do
9718*4882a593Smuzhiyun	      IFS=$save_ifs
9719*4882a593Smuzhiyun	      # Take the normal branch if the nm_file_list_spec branch
9720*4882a593Smuzhiyun	      # doesn't work or if tool conversion is not needed.
9721*4882a593Smuzhiyun	      case $nm_file_list_spec~$to_tool_file_cmd in
9722*4882a593Smuzhiyun		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9723*4882a593Smuzhiyun		  try_normal_branch=yes
9724*4882a593Smuzhiyun		  eval cmd=\"$cmd1\"
9725*4882a593Smuzhiyun		  func_len " $cmd"
9726*4882a593Smuzhiyun		  len=$func_len_result
9727*4882a593Smuzhiyun		  ;;
9728*4882a593Smuzhiyun		*)
9729*4882a593Smuzhiyun		  try_normal_branch=no
9730*4882a593Smuzhiyun		  ;;
9731*4882a593Smuzhiyun	      esac
9732*4882a593Smuzhiyun	      if test yes = "$try_normal_branch" \
9733*4882a593Smuzhiyun		 && { test "$len" -lt "$max_cmd_len" \
9734*4882a593Smuzhiyun		      || test "$max_cmd_len" -le -1; }
9735*4882a593Smuzhiyun	      then
9736*4882a593Smuzhiyun		func_show_eval "$cmd" 'exit $?'
9737*4882a593Smuzhiyun		skipped_export=false
9738*4882a593Smuzhiyun	      elif test -n "$nm_file_list_spec"; then
9739*4882a593Smuzhiyun		func_basename "$output"
9740*4882a593Smuzhiyun		output_la=$func_basename_result
9741*4882a593Smuzhiyun		save_libobjs=$libobjs
9742*4882a593Smuzhiyun		save_output=$output
9743*4882a593Smuzhiyun		output=$output_objdir/$output_la.nm
9744*4882a593Smuzhiyun		func_to_tool_file "$output"
9745*4882a593Smuzhiyun		libobjs=$nm_file_list_spec$func_to_tool_file_result
9746*4882a593Smuzhiyun		func_append delfiles " $output"
9747*4882a593Smuzhiyun		func_verbose "creating $NM input file list: $output"
9748*4882a593Smuzhiyun		for obj in $save_libobjs; do
9749*4882a593Smuzhiyun		  func_to_tool_file "$obj"
9750*4882a593Smuzhiyun		  $ECHO "$func_to_tool_file_result"
9751*4882a593Smuzhiyun		done > "$output"
9752*4882a593Smuzhiyun		eval cmd=\"$cmd1\"
9753*4882a593Smuzhiyun		func_show_eval "$cmd" 'exit $?'
9754*4882a593Smuzhiyun		output=$save_output
9755*4882a593Smuzhiyun		libobjs=$save_libobjs
9756*4882a593Smuzhiyun		skipped_export=false
9757*4882a593Smuzhiyun	      else
9758*4882a593Smuzhiyun		# The command line is too long to execute in one step.
9759*4882a593Smuzhiyun		func_verbose "using reloadable object file for export list..."
9760*4882a593Smuzhiyun		skipped_export=:
9761*4882a593Smuzhiyun		# Break out early, otherwise skipped_export may be
9762*4882a593Smuzhiyun		# set to false by a later but shorter cmd.
9763*4882a593Smuzhiyun		break
9764*4882a593Smuzhiyun	      fi
9765*4882a593Smuzhiyun	    done
9766*4882a593Smuzhiyun	    IFS=$save_ifs
9767*4882a593Smuzhiyun	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9768*4882a593Smuzhiyun	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9769*4882a593Smuzhiyun	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9770*4882a593Smuzhiyun	    fi
9771*4882a593Smuzhiyun	  fi
9772*4882a593Smuzhiyun	fi
9773*4882a593Smuzhiyun
9774*4882a593Smuzhiyun	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9775*4882a593Smuzhiyun	  tmp_export_symbols=$export_symbols
9776*4882a593Smuzhiyun	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
9777*4882a593Smuzhiyun	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
9778*4882a593Smuzhiyun	fi
9779*4882a593Smuzhiyun
9780*4882a593Smuzhiyun	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
9781*4882a593Smuzhiyun	  # The given exports_symbols file has to be filtered, so filter it.
9782*4882a593Smuzhiyun	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
9783*4882a593Smuzhiyun	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
9784*4882a593Smuzhiyun	  # 's' commands, which not all seds can handle. GNU sed should be fine
9785*4882a593Smuzhiyun	  # though. Also, the filter scales superlinearly with the number of
9786*4882a593Smuzhiyun	  # global variables. join(1) would be nice here, but unfortunately
9787*4882a593Smuzhiyun	  # isn't a blessed tool.
9788*4882a593Smuzhiyun	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
9789*4882a593Smuzhiyun	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
9790*4882a593Smuzhiyun	  export_symbols=$output_objdir/$libname.def
9791*4882a593Smuzhiyun	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
9792*4882a593Smuzhiyun	fi
9793*4882a593Smuzhiyun
9794*4882a593Smuzhiyun	tmp_deplibs=
9795*4882a593Smuzhiyun	for test_deplib in $deplibs; do
9796*4882a593Smuzhiyun	  case " $convenience " in
9797*4882a593Smuzhiyun	  *" $test_deplib "*) ;;
9798*4882a593Smuzhiyun	  *)
9799*4882a593Smuzhiyun	    func_append tmp_deplibs " $test_deplib"
9800*4882a593Smuzhiyun	    ;;
9801*4882a593Smuzhiyun	  esac
9802*4882a593Smuzhiyun	done
9803*4882a593Smuzhiyun	deplibs=$tmp_deplibs
9804*4882a593Smuzhiyun
9805*4882a593Smuzhiyun	if test -n "$convenience"; then
9806*4882a593Smuzhiyun	  if test -n "$whole_archive_flag_spec" &&
9807*4882a593Smuzhiyun	    test yes = "$compiler_needs_object" &&
9808*4882a593Smuzhiyun	    test -z "$libobjs"; then
9809*4882a593Smuzhiyun	    # extract the archives, so we have objects to list.
9810*4882a593Smuzhiyun	    # TODO: could optimize this to just extract one archive.
9811*4882a593Smuzhiyun	    whole_archive_flag_spec=
9812*4882a593Smuzhiyun	  fi
9813*4882a593Smuzhiyun	  if test -n "$whole_archive_flag_spec"; then
9814*4882a593Smuzhiyun	    save_libobjs=$libobjs
9815*4882a593Smuzhiyun	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
9816*4882a593Smuzhiyun	    test "X$libobjs" = "X " && libobjs=
9817*4882a593Smuzhiyun	  else
9818*4882a593Smuzhiyun	    gentop=$output_objdir/${outputname}x
9819*4882a593Smuzhiyun	    func_append generated " $gentop"
9820*4882a593Smuzhiyun
9821*4882a593Smuzhiyun	    func_extract_archives $gentop $convenience
9822*4882a593Smuzhiyun	    func_append libobjs " $func_extract_archives_result"
9823*4882a593Smuzhiyun	    test "X$libobjs" = "X " && libobjs=
9824*4882a593Smuzhiyun	  fi
9825*4882a593Smuzhiyun	fi
9826*4882a593Smuzhiyun
9827*4882a593Smuzhiyun	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
9828*4882a593Smuzhiyun	  eval flag=\"$thread_safe_flag_spec\"
9829*4882a593Smuzhiyun	  func_append linker_flags " $flag"
9830*4882a593Smuzhiyun	fi
9831*4882a593Smuzhiyun
9832*4882a593Smuzhiyun	# Make a backup of the uninstalled library when relinking
9833*4882a593Smuzhiyun	if test relink = "$opt_mode"; then
9834*4882a593Smuzhiyun	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
9835*4882a593Smuzhiyun	fi
9836*4882a593Smuzhiyun
9837*4882a593Smuzhiyun	# Do each of the archive commands.
9838*4882a593Smuzhiyun	if test yes = "$module" && test -n "$module_cmds"; then
9839*4882a593Smuzhiyun	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
9840*4882a593Smuzhiyun	    eval test_cmds=\"$module_expsym_cmds\"
9841*4882a593Smuzhiyun	    cmds=$module_expsym_cmds
9842*4882a593Smuzhiyun	  else
9843*4882a593Smuzhiyun	    eval test_cmds=\"$module_cmds\"
9844*4882a593Smuzhiyun	    cmds=$module_cmds
9845*4882a593Smuzhiyun	  fi
9846*4882a593Smuzhiyun	else
9847*4882a593Smuzhiyun	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
9848*4882a593Smuzhiyun	    eval test_cmds=\"$archive_expsym_cmds\"
9849*4882a593Smuzhiyun	    cmds=$archive_expsym_cmds
9850*4882a593Smuzhiyun	  else
9851*4882a593Smuzhiyun	    eval test_cmds=\"$archive_cmds\"
9852*4882a593Smuzhiyun	    cmds=$archive_cmds
9853*4882a593Smuzhiyun	  fi
9854*4882a593Smuzhiyun	fi
9855*4882a593Smuzhiyun
9856*4882a593Smuzhiyun	if test : != "$skipped_export" &&
9857*4882a593Smuzhiyun	   func_len " $test_cmds" &&
9858*4882a593Smuzhiyun	   len=$func_len_result &&
9859*4882a593Smuzhiyun	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
9860*4882a593Smuzhiyun	  :
9861*4882a593Smuzhiyun	else
9862*4882a593Smuzhiyun	  # The command line is too long to link in one step, link piecewise
9863*4882a593Smuzhiyun	  # or, if using GNU ld and skipped_export is not :, use a linker
9864*4882a593Smuzhiyun	  # script.
9865*4882a593Smuzhiyun
9866*4882a593Smuzhiyun	  # Save the value of $output and $libobjs because we want to
9867*4882a593Smuzhiyun	  # use them later.  If we have whole_archive_flag_spec, we
9868*4882a593Smuzhiyun	  # want to use save_libobjs as it was before
9869*4882a593Smuzhiyun	  # whole_archive_flag_spec was expanded, because we can't
9870*4882a593Smuzhiyun	  # assume the linker understands whole_archive_flag_spec.
9871*4882a593Smuzhiyun	  # This may have to be revisited, in case too many
9872*4882a593Smuzhiyun	  # convenience libraries get linked in and end up exceeding
9873*4882a593Smuzhiyun	  # the spec.
9874*4882a593Smuzhiyun	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
9875*4882a593Smuzhiyun	    save_libobjs=$libobjs
9876*4882a593Smuzhiyun	  fi
9877*4882a593Smuzhiyun	  save_output=$output
9878*4882a593Smuzhiyun	  func_basename "$output"
9879*4882a593Smuzhiyun	  output_la=$func_basename_result
9880*4882a593Smuzhiyun
9881*4882a593Smuzhiyun	  # Clear the reloadable object creation command queue and
9882*4882a593Smuzhiyun	  # initialize k to one.
9883*4882a593Smuzhiyun	  test_cmds=
9884*4882a593Smuzhiyun	  concat_cmds=
9885*4882a593Smuzhiyun	  objlist=
9886*4882a593Smuzhiyun	  last_robj=
9887*4882a593Smuzhiyun	  k=1
9888*4882a593Smuzhiyun
9889*4882a593Smuzhiyun	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
9890*4882a593Smuzhiyun	    output=$output_objdir/$output_la.lnkscript
9891*4882a593Smuzhiyun	    func_verbose "creating GNU ld script: $output"
9892*4882a593Smuzhiyun	    echo 'INPUT (' > $output
9893*4882a593Smuzhiyun	    for obj in $save_libobjs
9894*4882a593Smuzhiyun	    do
9895*4882a593Smuzhiyun	      func_to_tool_file "$obj"
9896*4882a593Smuzhiyun	      $ECHO "$func_to_tool_file_result" >> $output
9897*4882a593Smuzhiyun	    done
9898*4882a593Smuzhiyun	    echo ')' >> $output
9899*4882a593Smuzhiyun	    func_append delfiles " $output"
9900*4882a593Smuzhiyun	    func_to_tool_file "$output"
9901*4882a593Smuzhiyun	    output=$func_to_tool_file_result
9902*4882a593Smuzhiyun	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
9903*4882a593Smuzhiyun	    output=$output_objdir/$output_la.lnk
9904*4882a593Smuzhiyun	    func_verbose "creating linker input file list: $output"
9905*4882a593Smuzhiyun	    : > $output
9906*4882a593Smuzhiyun	    set x $save_libobjs
9907*4882a593Smuzhiyun	    shift
9908*4882a593Smuzhiyun	    firstobj=
9909*4882a593Smuzhiyun	    if test yes = "$compiler_needs_object"; then
9910*4882a593Smuzhiyun	      firstobj="$1 "
9911*4882a593Smuzhiyun	      shift
9912*4882a593Smuzhiyun	    fi
9913*4882a593Smuzhiyun	    for obj
9914*4882a593Smuzhiyun	    do
9915*4882a593Smuzhiyun	      func_to_tool_file "$obj"
9916*4882a593Smuzhiyun	      $ECHO "$func_to_tool_file_result" >> $output
9917*4882a593Smuzhiyun	    done
9918*4882a593Smuzhiyun	    func_append delfiles " $output"
9919*4882a593Smuzhiyun	    func_to_tool_file "$output"
9920*4882a593Smuzhiyun	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
9921*4882a593Smuzhiyun	  else
9922*4882a593Smuzhiyun	    if test -n "$save_libobjs"; then
9923*4882a593Smuzhiyun	      func_verbose "creating reloadable object files..."
9924*4882a593Smuzhiyun	      output=$output_objdir/$output_la-$k.$objext
9925*4882a593Smuzhiyun	      eval test_cmds=\"$reload_cmds\"
9926*4882a593Smuzhiyun	      func_len " $test_cmds"
9927*4882a593Smuzhiyun	      len0=$func_len_result
9928*4882a593Smuzhiyun	      len=$len0
9929*4882a593Smuzhiyun
9930*4882a593Smuzhiyun	      # Loop over the list of objects to be linked.
9931*4882a593Smuzhiyun	      for obj in $save_libobjs
9932*4882a593Smuzhiyun	      do
9933*4882a593Smuzhiyun		func_len " $obj"
9934*4882a593Smuzhiyun		func_arith $len + $func_len_result
9935*4882a593Smuzhiyun		len=$func_arith_result
9936*4882a593Smuzhiyun		if test -z "$objlist" ||
9937*4882a593Smuzhiyun		   test "$len" -lt "$max_cmd_len"; then
9938*4882a593Smuzhiyun		  func_append objlist " $obj"
9939*4882a593Smuzhiyun		else
9940*4882a593Smuzhiyun		  # The command $test_cmds is almost too long, add a
9941*4882a593Smuzhiyun		  # command to the queue.
9942*4882a593Smuzhiyun		  if test 1 -eq "$k"; then
9943*4882a593Smuzhiyun		    # The first file doesn't have a previous command to add.
9944*4882a593Smuzhiyun		    reload_objs=$objlist
9945*4882a593Smuzhiyun		    eval concat_cmds=\"$reload_cmds\"
9946*4882a593Smuzhiyun		  else
9947*4882a593Smuzhiyun		    # All subsequent reloadable object files will link in
9948*4882a593Smuzhiyun		    # the last one created.
9949*4882a593Smuzhiyun		    reload_objs="$objlist $last_robj"
9950*4882a593Smuzhiyun		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
9951*4882a593Smuzhiyun		  fi
9952*4882a593Smuzhiyun		  last_robj=$output_objdir/$output_la-$k.$objext
9953*4882a593Smuzhiyun		  func_arith $k + 1
9954*4882a593Smuzhiyun		  k=$func_arith_result
9955*4882a593Smuzhiyun		  output=$output_objdir/$output_la-$k.$objext
9956*4882a593Smuzhiyun		  objlist=" $obj"
9957*4882a593Smuzhiyun		  func_len " $last_robj"
9958*4882a593Smuzhiyun		  func_arith $len0 + $func_len_result
9959*4882a593Smuzhiyun		  len=$func_arith_result
9960*4882a593Smuzhiyun		fi
9961*4882a593Smuzhiyun	      done
9962*4882a593Smuzhiyun	      # Handle the remaining objects by creating one last
9963*4882a593Smuzhiyun	      # reloadable object file.  All subsequent reloadable object
9964*4882a593Smuzhiyun	      # files will link in the last one created.
9965*4882a593Smuzhiyun	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
9966*4882a593Smuzhiyun	      reload_objs="$objlist $last_robj"
9967*4882a593Smuzhiyun	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
9968*4882a593Smuzhiyun	      if test -n "$last_robj"; then
9969*4882a593Smuzhiyun	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
9970*4882a593Smuzhiyun	      fi
9971*4882a593Smuzhiyun	      func_append delfiles " $output"
9972*4882a593Smuzhiyun
9973*4882a593Smuzhiyun	    else
9974*4882a593Smuzhiyun	      output=
9975*4882a593Smuzhiyun	    fi
9976*4882a593Smuzhiyun
9977*4882a593Smuzhiyun	    ${skipped_export-false} && {
9978*4882a593Smuzhiyun	      func_verbose "generating symbol list for '$libname.la'"
9979*4882a593Smuzhiyun	      export_symbols=$output_objdir/$libname.exp
9980*4882a593Smuzhiyun	      $opt_dry_run || $RM $export_symbols
9981*4882a593Smuzhiyun	      libobjs=$output
9982*4882a593Smuzhiyun	      # Append the command to create the export file.
9983*4882a593Smuzhiyun	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
9984*4882a593Smuzhiyun	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
9985*4882a593Smuzhiyun	      if test -n "$last_robj"; then
9986*4882a593Smuzhiyun		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
9987*4882a593Smuzhiyun	      fi
9988*4882a593Smuzhiyun	    }
9989*4882a593Smuzhiyun
9990*4882a593Smuzhiyun	    test -n "$save_libobjs" &&
9991*4882a593Smuzhiyun	      func_verbose "creating a temporary reloadable object file: $output"
9992*4882a593Smuzhiyun
9993*4882a593Smuzhiyun	    # Loop through the commands generated above and execute them.
9994*4882a593Smuzhiyun	    save_ifs=$IFS; IFS='~'
9995*4882a593Smuzhiyun	    for cmd in $concat_cmds; do
9996*4882a593Smuzhiyun	      IFS=$save_ifs
9997*4882a593Smuzhiyun	      $opt_quiet || {
9998*4882a593Smuzhiyun		  func_quote_for_expand "$cmd"
9999*4882a593Smuzhiyun		  eval "func_echo $func_quote_for_expand_result"
10000*4882a593Smuzhiyun	      }
10001*4882a593Smuzhiyun	      $opt_dry_run || eval "$cmd" || {
10002*4882a593Smuzhiyun		lt_exit=$?
10003*4882a593Smuzhiyun
10004*4882a593Smuzhiyun		# Restore the uninstalled library and exit
10005*4882a593Smuzhiyun		if test relink = "$opt_mode"; then
10006*4882a593Smuzhiyun		  ( cd "$output_objdir" && \
10007*4882a593Smuzhiyun		    $RM "${realname}T" && \
10008*4882a593Smuzhiyun		    $MV "${realname}U" "$realname" )
10009*4882a593Smuzhiyun		fi
10010*4882a593Smuzhiyun
10011*4882a593Smuzhiyun		exit $lt_exit
10012*4882a593Smuzhiyun	      }
10013*4882a593Smuzhiyun	    done
10014*4882a593Smuzhiyun	    IFS=$save_ifs
10015*4882a593Smuzhiyun
10016*4882a593Smuzhiyun	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10017*4882a593Smuzhiyun	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10018*4882a593Smuzhiyun	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
10019*4882a593Smuzhiyun	    fi
10020*4882a593Smuzhiyun	  fi
10021*4882a593Smuzhiyun
10022*4882a593Smuzhiyun          ${skipped_export-false} && {
10023*4882a593Smuzhiyun	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10024*4882a593Smuzhiyun	      tmp_export_symbols=$export_symbols
10025*4882a593Smuzhiyun	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10026*4882a593Smuzhiyun	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10027*4882a593Smuzhiyun	    fi
10028*4882a593Smuzhiyun
10029*4882a593Smuzhiyun	    if test -n "$orig_export_symbols"; then
10030*4882a593Smuzhiyun	      # The given exports_symbols file has to be filtered, so filter it.
10031*4882a593Smuzhiyun	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10032*4882a593Smuzhiyun	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10033*4882a593Smuzhiyun	      # 's' commands, which not all seds can handle. GNU sed should be fine
10034*4882a593Smuzhiyun	      # though. Also, the filter scales superlinearly with the number of
10035*4882a593Smuzhiyun	      # global variables. join(1) would be nice here, but unfortunately
10036*4882a593Smuzhiyun	      # isn't a blessed tool.
10037*4882a593Smuzhiyun	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10038*4882a593Smuzhiyun	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10039*4882a593Smuzhiyun	      export_symbols=$output_objdir/$libname.def
10040*4882a593Smuzhiyun	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10041*4882a593Smuzhiyun	    fi
10042*4882a593Smuzhiyun	  }
10043*4882a593Smuzhiyun
10044*4882a593Smuzhiyun	  libobjs=$output
10045*4882a593Smuzhiyun	  # Restore the value of output.
10046*4882a593Smuzhiyun	  output=$save_output
10047*4882a593Smuzhiyun
10048*4882a593Smuzhiyun	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10049*4882a593Smuzhiyun	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10050*4882a593Smuzhiyun	    test "X$libobjs" = "X " && libobjs=
10051*4882a593Smuzhiyun	  fi
10052*4882a593Smuzhiyun	  # Expand the library linking commands again to reset the
10053*4882a593Smuzhiyun	  # value of $libobjs for piecewise linking.
10054*4882a593Smuzhiyun
10055*4882a593Smuzhiyun	  # Do each of the archive commands.
10056*4882a593Smuzhiyun	  if test yes = "$module" && test -n "$module_cmds"; then
10057*4882a593Smuzhiyun	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10058*4882a593Smuzhiyun	      cmds=$module_expsym_cmds
10059*4882a593Smuzhiyun	    else
10060*4882a593Smuzhiyun	      cmds=$module_cmds
10061*4882a593Smuzhiyun	    fi
10062*4882a593Smuzhiyun	  else
10063*4882a593Smuzhiyun	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10064*4882a593Smuzhiyun	      cmds=$archive_expsym_cmds
10065*4882a593Smuzhiyun	    else
10066*4882a593Smuzhiyun	      cmds=$archive_cmds
10067*4882a593Smuzhiyun	    fi
10068*4882a593Smuzhiyun	  fi
10069*4882a593Smuzhiyun	fi
10070*4882a593Smuzhiyun
10071*4882a593Smuzhiyun	if test -n "$delfiles"; then
10072*4882a593Smuzhiyun	  # Append the command to remove temporary files to $cmds.
10073*4882a593Smuzhiyun	  eval cmds=\"\$cmds~\$RM $delfiles\"
10074*4882a593Smuzhiyun	fi
10075*4882a593Smuzhiyun
10076*4882a593Smuzhiyun	# Add any objects from preloaded convenience libraries
10077*4882a593Smuzhiyun	if test -n "$dlprefiles"; then
10078*4882a593Smuzhiyun	  gentop=$output_objdir/${outputname}x
10079*4882a593Smuzhiyun	  func_append generated " $gentop"
10080*4882a593Smuzhiyun
10081*4882a593Smuzhiyun	  func_extract_archives $gentop $dlprefiles
10082*4882a593Smuzhiyun	  func_append libobjs " $func_extract_archives_result"
10083*4882a593Smuzhiyun	  test "X$libobjs" = "X " && libobjs=
10084*4882a593Smuzhiyun	fi
10085*4882a593Smuzhiyun
10086*4882a593Smuzhiyun	save_ifs=$IFS; IFS='~'
10087*4882a593Smuzhiyun	for cmd in $cmds; do
10088*4882a593Smuzhiyun	  IFS=$sp$nl
10089*4882a593Smuzhiyun	  eval cmd=\"$cmd\"
10090*4882a593Smuzhiyun	  IFS=$save_ifs
10091*4882a593Smuzhiyun	  $opt_quiet || {
10092*4882a593Smuzhiyun	    func_quote_for_expand "$cmd"
10093*4882a593Smuzhiyun	    eval "func_echo $func_quote_for_expand_result"
10094*4882a593Smuzhiyun	  }
10095*4882a593Smuzhiyun	  $opt_dry_run || eval "$cmd" || {
10096*4882a593Smuzhiyun	    lt_exit=$?
10097*4882a593Smuzhiyun
10098*4882a593Smuzhiyun	    # Restore the uninstalled library and exit
10099*4882a593Smuzhiyun	    if test relink = "$opt_mode"; then
10100*4882a593Smuzhiyun	      ( cd "$output_objdir" && \
10101*4882a593Smuzhiyun	        $RM "${realname}T" && \
10102*4882a593Smuzhiyun		$MV "${realname}U" "$realname" )
10103*4882a593Smuzhiyun	    fi
10104*4882a593Smuzhiyun
10105*4882a593Smuzhiyun	    exit $lt_exit
10106*4882a593Smuzhiyun	  }
10107*4882a593Smuzhiyun	done
10108*4882a593Smuzhiyun	IFS=$save_ifs
10109*4882a593Smuzhiyun
10110*4882a593Smuzhiyun	# Restore the uninstalled library and exit
10111*4882a593Smuzhiyun	if test relink = "$opt_mode"; then
10112*4882a593Smuzhiyun	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10113*4882a593Smuzhiyun
10114*4882a593Smuzhiyun	  if test -n "$convenience"; then
10115*4882a593Smuzhiyun	    if test -z "$whole_archive_flag_spec"; then
10116*4882a593Smuzhiyun	      func_show_eval '${RM}r "$gentop"'
10117*4882a593Smuzhiyun	    fi
10118*4882a593Smuzhiyun	  fi
10119*4882a593Smuzhiyun
10120*4882a593Smuzhiyun	  exit $EXIT_SUCCESS
10121*4882a593Smuzhiyun	fi
10122*4882a593Smuzhiyun
10123*4882a593Smuzhiyun	# Create links to the real library.
10124*4882a593Smuzhiyun	for linkname in $linknames; do
10125*4882a593Smuzhiyun	  if test "$realname" != "$linkname"; then
10126*4882a593Smuzhiyun	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10127*4882a593Smuzhiyun	  fi
10128*4882a593Smuzhiyun	done
10129*4882a593Smuzhiyun
10130*4882a593Smuzhiyun	# If -module or -export-dynamic was specified, set the dlname.
10131*4882a593Smuzhiyun	if test yes = "$module" || test yes = "$export_dynamic"; then
10132*4882a593Smuzhiyun	  # On all known operating systems, these are identical.
10133*4882a593Smuzhiyun	  dlname=$soname
10134*4882a593Smuzhiyun	fi
10135*4882a593Smuzhiyun      fi
10136*4882a593Smuzhiyun      ;;
10137*4882a593Smuzhiyun
10138*4882a593Smuzhiyun    obj)
10139*4882a593Smuzhiyun      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10140*4882a593Smuzhiyun	func_warning "'-dlopen' is ignored for objects"
10141*4882a593Smuzhiyun      fi
10142*4882a593Smuzhiyun
10143*4882a593Smuzhiyun      case " $deplibs" in
10144*4882a593Smuzhiyun      *\ -l* | *\ -L*)
10145*4882a593Smuzhiyun	func_warning "'-l' and '-L' are ignored for objects" ;;
10146*4882a593Smuzhiyun      esac
10147*4882a593Smuzhiyun
10148*4882a593Smuzhiyun      test -n "$rpath" && \
10149*4882a593Smuzhiyun	func_warning "'-rpath' is ignored for objects"
10150*4882a593Smuzhiyun
10151*4882a593Smuzhiyun      test -n "$xrpath" && \
10152*4882a593Smuzhiyun	func_warning "'-R' is ignored for objects"
10153*4882a593Smuzhiyun
10154*4882a593Smuzhiyun      test -n "$vinfo" && \
10155*4882a593Smuzhiyun	func_warning "'-version-info' is ignored for objects"
10156*4882a593Smuzhiyun
10157*4882a593Smuzhiyun      test -n "$release" && \
10158*4882a593Smuzhiyun	func_warning "'-release' is ignored for objects"
10159*4882a593Smuzhiyun
10160*4882a593Smuzhiyun      case $output in
10161*4882a593Smuzhiyun      *.lo)
10162*4882a593Smuzhiyun	test -n "$objs$old_deplibs" && \
10163*4882a593Smuzhiyun	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10164*4882a593Smuzhiyun
10165*4882a593Smuzhiyun	libobj=$output
10166*4882a593Smuzhiyun	func_lo2o "$libobj"
10167*4882a593Smuzhiyun	obj=$func_lo2o_result
10168*4882a593Smuzhiyun	;;
10169*4882a593Smuzhiyun      *)
10170*4882a593Smuzhiyun	libobj=
10171*4882a593Smuzhiyun	obj=$output
10172*4882a593Smuzhiyun	;;
10173*4882a593Smuzhiyun      esac
10174*4882a593Smuzhiyun
10175*4882a593Smuzhiyun      # Delete the old objects.
10176*4882a593Smuzhiyun      $opt_dry_run || $RM $obj $libobj
10177*4882a593Smuzhiyun
10178*4882a593Smuzhiyun      # Objects from convenience libraries.  This assumes
10179*4882a593Smuzhiyun      # single-version convenience libraries.  Whenever we create
10180*4882a593Smuzhiyun      # different ones for PIC/non-PIC, this we'll have to duplicate
10181*4882a593Smuzhiyun      # the extraction.
10182*4882a593Smuzhiyun      reload_conv_objs=
10183*4882a593Smuzhiyun      gentop=
10184*4882a593Smuzhiyun      # if reload_cmds runs $LD directly, get rid of -Wl from
10185*4882a593Smuzhiyun      # whole_archive_flag_spec and hope we can get by with turning comma
10186*4882a593Smuzhiyun      # into space.
10187*4882a593Smuzhiyun      case $reload_cmds in
10188*4882a593Smuzhiyun        *\$LD[\ \$]*) wl= ;;
10189*4882a593Smuzhiyun      esac
10190*4882a593Smuzhiyun      if test -n "$convenience"; then
10191*4882a593Smuzhiyun	if test -n "$whole_archive_flag_spec"; then
10192*4882a593Smuzhiyun	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10193*4882a593Smuzhiyun	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10194*4882a593Smuzhiyun	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10195*4882a593Smuzhiyun	else
10196*4882a593Smuzhiyun	  gentop=$output_objdir/${obj}x
10197*4882a593Smuzhiyun	  func_append generated " $gentop"
10198*4882a593Smuzhiyun
10199*4882a593Smuzhiyun	  func_extract_archives $gentop $convenience
10200*4882a593Smuzhiyun	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10201*4882a593Smuzhiyun	fi
10202*4882a593Smuzhiyun      fi
10203*4882a593Smuzhiyun
10204*4882a593Smuzhiyun      # If we're not building shared, we need to use non_pic_objs
10205*4882a593Smuzhiyun      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10206*4882a593Smuzhiyun
10207*4882a593Smuzhiyun      # Create the old-style object.
10208*4882a593Smuzhiyun      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10209*4882a593Smuzhiyun
10210*4882a593Smuzhiyun      output=$obj
10211*4882a593Smuzhiyun      func_execute_cmds "$reload_cmds" 'exit $?'
10212*4882a593Smuzhiyun
10213*4882a593Smuzhiyun      # Exit if we aren't doing a library object file.
10214*4882a593Smuzhiyun      if test -z "$libobj"; then
10215*4882a593Smuzhiyun	if test -n "$gentop"; then
10216*4882a593Smuzhiyun	  func_show_eval '${RM}r "$gentop"'
10217*4882a593Smuzhiyun	fi
10218*4882a593Smuzhiyun
10219*4882a593Smuzhiyun	exit $EXIT_SUCCESS
10220*4882a593Smuzhiyun      fi
10221*4882a593Smuzhiyun
10222*4882a593Smuzhiyun      test yes = "$build_libtool_libs" || {
10223*4882a593Smuzhiyun	if test -n "$gentop"; then
10224*4882a593Smuzhiyun	  func_show_eval '${RM}r "$gentop"'
10225*4882a593Smuzhiyun	fi
10226*4882a593Smuzhiyun
10227*4882a593Smuzhiyun	# Create an invalid libtool object if no PIC, so that we don't
10228*4882a593Smuzhiyun	# accidentally link it into a program.
10229*4882a593Smuzhiyun	# $show "echo timestamp > $libobj"
10230*4882a593Smuzhiyun	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10231*4882a593Smuzhiyun	exit $EXIT_SUCCESS
10232*4882a593Smuzhiyun      }
10233*4882a593Smuzhiyun
10234*4882a593Smuzhiyun      if test -n "$pic_flag" || test default != "$pic_mode"; then
10235*4882a593Smuzhiyun	# Only do commands if we really have different PIC objects.
10236*4882a593Smuzhiyun	reload_objs="$libobjs $reload_conv_objs"
10237*4882a593Smuzhiyun	output=$libobj
10238*4882a593Smuzhiyun	func_execute_cmds "$reload_cmds" 'exit $?'
10239*4882a593Smuzhiyun      fi
10240*4882a593Smuzhiyun
10241*4882a593Smuzhiyun      if test -n "$gentop"; then
10242*4882a593Smuzhiyun	func_show_eval '${RM}r "$gentop"'
10243*4882a593Smuzhiyun      fi
10244*4882a593Smuzhiyun
10245*4882a593Smuzhiyun      exit $EXIT_SUCCESS
10246*4882a593Smuzhiyun      ;;
10247*4882a593Smuzhiyun
10248*4882a593Smuzhiyun    prog)
10249*4882a593Smuzhiyun      case $host in
10250*4882a593Smuzhiyun	*cygwin*) func_stripname '' '.exe' "$output"
10251*4882a593Smuzhiyun	          output=$func_stripname_result.exe;;
10252*4882a593Smuzhiyun      esac
10253*4882a593Smuzhiyun      test -n "$vinfo" && \
10254*4882a593Smuzhiyun	func_warning "'-version-info' is ignored for programs"
10255*4882a593Smuzhiyun
10256*4882a593Smuzhiyun      test -n "$release" && \
10257*4882a593Smuzhiyun	func_warning "'-release' is ignored for programs"
10258*4882a593Smuzhiyun
10259*4882a593Smuzhiyun      $preload \
10260*4882a593Smuzhiyun	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10261*4882a593Smuzhiyun	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10262*4882a593Smuzhiyun
10263*4882a593Smuzhiyun      case $host in
10264*4882a593Smuzhiyun      *-*-rhapsody* | *-*-darwin1.[012])
10265*4882a593Smuzhiyun	# On Rhapsody replace the C library is the System framework
10266*4882a593Smuzhiyun	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10267*4882a593Smuzhiyun	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10268*4882a593Smuzhiyun	;;
10269*4882a593Smuzhiyun      esac
10270*4882a593Smuzhiyun
10271*4882a593Smuzhiyun      case $host in
10272*4882a593Smuzhiyun      *-*-darwin*)
10273*4882a593Smuzhiyun	# Don't allow lazy linking, it breaks C++ global constructors
10274*4882a593Smuzhiyun	# But is supposedly fixed on 10.4 or later (yay!).
10275*4882a593Smuzhiyun	if test CXX = "$tagname"; then
10276*4882a593Smuzhiyun	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10277*4882a593Smuzhiyun	    10.[0123])
10278*4882a593Smuzhiyun	      func_append compile_command " $wl-bind_at_load"
10279*4882a593Smuzhiyun	      func_append finalize_command " $wl-bind_at_load"
10280*4882a593Smuzhiyun	    ;;
10281*4882a593Smuzhiyun	  esac
10282*4882a593Smuzhiyun	fi
10283*4882a593Smuzhiyun	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10284*4882a593Smuzhiyun	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10285*4882a593Smuzhiyun	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10286*4882a593Smuzhiyun	;;
10287*4882a593Smuzhiyun      esac
10288*4882a593Smuzhiyun
10289*4882a593Smuzhiyun
10290*4882a593Smuzhiyun      # move library search paths that coincide with paths to not yet
10291*4882a593Smuzhiyun      # installed libraries to the beginning of the library search list
10292*4882a593Smuzhiyun      new_libs=
10293*4882a593Smuzhiyun      for path in $notinst_path; do
10294*4882a593Smuzhiyun	case " $new_libs " in
10295*4882a593Smuzhiyun	*" -L$path/$objdir "*) ;;
10296*4882a593Smuzhiyun	*)
10297*4882a593Smuzhiyun	  case " $compile_deplibs " in
10298*4882a593Smuzhiyun	  *" -L$path/$objdir "*)
10299*4882a593Smuzhiyun	    func_append new_libs " -L$path/$objdir" ;;
10300*4882a593Smuzhiyun	  esac
10301*4882a593Smuzhiyun	  ;;
10302*4882a593Smuzhiyun	esac
10303*4882a593Smuzhiyun      done
10304*4882a593Smuzhiyun      for deplib in $compile_deplibs; do
10305*4882a593Smuzhiyun	case $deplib in
10306*4882a593Smuzhiyun	-L*)
10307*4882a593Smuzhiyun	  case " $new_libs " in
10308*4882a593Smuzhiyun	  *" $deplib "*) ;;
10309*4882a593Smuzhiyun	  *) func_append new_libs " $deplib" ;;
10310*4882a593Smuzhiyun	  esac
10311*4882a593Smuzhiyun	  ;;
10312*4882a593Smuzhiyun	*) func_append new_libs " $deplib" ;;
10313*4882a593Smuzhiyun	esac
10314*4882a593Smuzhiyun      done
10315*4882a593Smuzhiyun      compile_deplibs=$new_libs
10316*4882a593Smuzhiyun
10317*4882a593Smuzhiyun
10318*4882a593Smuzhiyun      func_append compile_command " $compile_deplibs"
10319*4882a593Smuzhiyun      func_append finalize_command " $finalize_deplibs"
10320*4882a593Smuzhiyun
10321*4882a593Smuzhiyun      if test -n "$rpath$xrpath"; then
10322*4882a593Smuzhiyun	# If the user specified any rpath flags, then add them.
10323*4882a593Smuzhiyun	for libdir in $rpath $xrpath; do
10324*4882a593Smuzhiyun	  # This is the magic to use -rpath.
10325*4882a593Smuzhiyun	  case "$finalize_rpath " in
10326*4882a593Smuzhiyun	  *" $libdir "*) ;;
10327*4882a593Smuzhiyun	  *) func_append finalize_rpath " $libdir" ;;
10328*4882a593Smuzhiyun	  esac
10329*4882a593Smuzhiyun	done
10330*4882a593Smuzhiyun      fi
10331*4882a593Smuzhiyun
10332*4882a593Smuzhiyun      # Now hardcode the library paths
10333*4882a593Smuzhiyun      rpath=
10334*4882a593Smuzhiyun      hardcode_libdirs=
10335*4882a593Smuzhiyun      for libdir in $compile_rpath $finalize_rpath; do
10336*4882a593Smuzhiyun	if test -n "$hardcode_libdir_flag_spec"; then
10337*4882a593Smuzhiyun	  if test -n "$hardcode_libdir_separator"; then
10338*4882a593Smuzhiyun	    if test -z "$hardcode_libdirs"; then
10339*4882a593Smuzhiyun	      hardcode_libdirs=$libdir
10340*4882a593Smuzhiyun	    else
10341*4882a593Smuzhiyun	      # Just accumulate the unique libdirs.
10342*4882a593Smuzhiyun	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10343*4882a593Smuzhiyun	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10344*4882a593Smuzhiyun		;;
10345*4882a593Smuzhiyun	      *)
10346*4882a593Smuzhiyun		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10347*4882a593Smuzhiyun		;;
10348*4882a593Smuzhiyun	      esac
10349*4882a593Smuzhiyun	    fi
10350*4882a593Smuzhiyun	  else
10351*4882a593Smuzhiyun	    eval flag=\"$hardcode_libdir_flag_spec\"
10352*4882a593Smuzhiyun	    func_append rpath " $flag"
10353*4882a593Smuzhiyun	  fi
10354*4882a593Smuzhiyun	elif test -n "$runpath_var"; then
10355*4882a593Smuzhiyun	  case "$perm_rpath " in
10356*4882a593Smuzhiyun	  *" $libdir "*) ;;
10357*4882a593Smuzhiyun	  *) func_append perm_rpath " $libdir" ;;
10358*4882a593Smuzhiyun	  esac
10359*4882a593Smuzhiyun	fi
10360*4882a593Smuzhiyun	case $host in
10361*4882a593Smuzhiyun	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10362*4882a593Smuzhiyun	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10363*4882a593Smuzhiyun	  case :$dllsearchpath: in
10364*4882a593Smuzhiyun	  *":$libdir:"*) ;;
10365*4882a593Smuzhiyun	  ::) dllsearchpath=$libdir;;
10366*4882a593Smuzhiyun	  *) func_append dllsearchpath ":$libdir";;
10367*4882a593Smuzhiyun	  esac
10368*4882a593Smuzhiyun	  case :$dllsearchpath: in
10369*4882a593Smuzhiyun	  *":$testbindir:"*) ;;
10370*4882a593Smuzhiyun	  ::) dllsearchpath=$testbindir;;
10371*4882a593Smuzhiyun	  *) func_append dllsearchpath ":$testbindir";;
10372*4882a593Smuzhiyun	  esac
10373*4882a593Smuzhiyun	  ;;
10374*4882a593Smuzhiyun	esac
10375*4882a593Smuzhiyun      done
10376*4882a593Smuzhiyun      # Substitute the hardcoded libdirs into the rpath.
10377*4882a593Smuzhiyun      if test -n "$hardcode_libdir_separator" &&
10378*4882a593Smuzhiyun	 test -n "$hardcode_libdirs"; then
10379*4882a593Smuzhiyun	libdir=$hardcode_libdirs
10380*4882a593Smuzhiyun	eval rpath=\" $hardcode_libdir_flag_spec\"
10381*4882a593Smuzhiyun      fi
10382*4882a593Smuzhiyun      compile_rpath=$rpath
10383*4882a593Smuzhiyun
10384*4882a593Smuzhiyun      rpath=
10385*4882a593Smuzhiyun      hardcode_libdirs=
10386*4882a593Smuzhiyun      for libdir in $finalize_rpath; do
10387*4882a593Smuzhiyun	if test -n "$hardcode_libdir_flag_spec"; then
10388*4882a593Smuzhiyun	  if test -n "$hardcode_libdir_separator"; then
10389*4882a593Smuzhiyun	    if test -z "$hardcode_libdirs"; then
10390*4882a593Smuzhiyun	      hardcode_libdirs=$libdir
10391*4882a593Smuzhiyun	    else
10392*4882a593Smuzhiyun	      # Just accumulate the unique libdirs.
10393*4882a593Smuzhiyun	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10394*4882a593Smuzhiyun	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10395*4882a593Smuzhiyun		;;
10396*4882a593Smuzhiyun	      *)
10397*4882a593Smuzhiyun		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10398*4882a593Smuzhiyun		;;
10399*4882a593Smuzhiyun	      esac
10400*4882a593Smuzhiyun	    fi
10401*4882a593Smuzhiyun	  else
10402*4882a593Smuzhiyun	    eval flag=\"$hardcode_libdir_flag_spec\"
10403*4882a593Smuzhiyun	    func_append rpath " $flag"
10404*4882a593Smuzhiyun	  fi
10405*4882a593Smuzhiyun	elif test -n "$runpath_var"; then
10406*4882a593Smuzhiyun	  case "$finalize_perm_rpath " in
10407*4882a593Smuzhiyun	  *" $libdir "*) ;;
10408*4882a593Smuzhiyun	  *) func_append finalize_perm_rpath " $libdir" ;;
10409*4882a593Smuzhiyun	  esac
10410*4882a593Smuzhiyun	fi
10411*4882a593Smuzhiyun      done
10412*4882a593Smuzhiyun      # Substitute the hardcoded libdirs into the rpath.
10413*4882a593Smuzhiyun      if test -n "$hardcode_libdir_separator" &&
10414*4882a593Smuzhiyun	 test -n "$hardcode_libdirs"; then
10415*4882a593Smuzhiyun	libdir=$hardcode_libdirs
10416*4882a593Smuzhiyun	eval rpath=\" $hardcode_libdir_flag_spec\"
10417*4882a593Smuzhiyun      fi
10418*4882a593Smuzhiyun      finalize_rpath=$rpath
10419*4882a593Smuzhiyun
10420*4882a593Smuzhiyun      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10421*4882a593Smuzhiyun	# Transform all the library objects into standard objects.
10422*4882a593Smuzhiyun	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10423*4882a593Smuzhiyun	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10424*4882a593Smuzhiyun      fi
10425*4882a593Smuzhiyun
10426*4882a593Smuzhiyun      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10427*4882a593Smuzhiyun
10428*4882a593Smuzhiyun      # template prelinking step
10429*4882a593Smuzhiyun      if test -n "$prelink_cmds"; then
10430*4882a593Smuzhiyun	func_execute_cmds "$prelink_cmds" 'exit $?'
10431*4882a593Smuzhiyun      fi
10432*4882a593Smuzhiyun
10433*4882a593Smuzhiyun      wrappers_required=:
10434*4882a593Smuzhiyun      case $host in
10435*4882a593Smuzhiyun      *cegcc* | *mingw32ce*)
10436*4882a593Smuzhiyun        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10437*4882a593Smuzhiyun        wrappers_required=false
10438*4882a593Smuzhiyun        ;;
10439*4882a593Smuzhiyun      *cygwin* | *mingw* )
10440*4882a593Smuzhiyun        test yes = "$build_libtool_libs" || wrappers_required=false
10441*4882a593Smuzhiyun        ;;
10442*4882a593Smuzhiyun      *)
10443*4882a593Smuzhiyun        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10444*4882a593Smuzhiyun          wrappers_required=false
10445*4882a593Smuzhiyun        fi
10446*4882a593Smuzhiyun        ;;
10447*4882a593Smuzhiyun      esac
10448*4882a593Smuzhiyun      $wrappers_required || {
10449*4882a593Smuzhiyun	# Replace the output file specification.
10450*4882a593Smuzhiyun	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10451*4882a593Smuzhiyun	link_command=$compile_command$compile_rpath
10452*4882a593Smuzhiyun
10453*4882a593Smuzhiyun	# We have no uninstalled library dependencies, so finalize right now.
10454*4882a593Smuzhiyun	exit_status=0
10455*4882a593Smuzhiyun	func_show_eval "$link_command" 'exit_status=$?'
10456*4882a593Smuzhiyun
10457*4882a593Smuzhiyun	if test -n "$postlink_cmds"; then
10458*4882a593Smuzhiyun	  func_to_tool_file "$output"
10459*4882a593Smuzhiyun	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10460*4882a593Smuzhiyun	  func_execute_cmds "$postlink_cmds" 'exit $?'
10461*4882a593Smuzhiyun	fi
10462*4882a593Smuzhiyun
10463*4882a593Smuzhiyun	# Delete the generated files.
10464*4882a593Smuzhiyun	if test -f "$output_objdir/${outputname}S.$objext"; then
10465*4882a593Smuzhiyun	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10466*4882a593Smuzhiyun	fi
10467*4882a593Smuzhiyun
10468*4882a593Smuzhiyun	exit $exit_status
10469*4882a593Smuzhiyun      }
10470*4882a593Smuzhiyun
10471*4882a593Smuzhiyun      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10472*4882a593Smuzhiyun	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10473*4882a593Smuzhiyun      fi
10474*4882a593Smuzhiyun      if test -n "$finalize_shlibpath"; then
10475*4882a593Smuzhiyun	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10476*4882a593Smuzhiyun      fi
10477*4882a593Smuzhiyun
10478*4882a593Smuzhiyun      compile_var=
10479*4882a593Smuzhiyun      finalize_var=
10480*4882a593Smuzhiyun      if test -n "$runpath_var"; then
10481*4882a593Smuzhiyun	if test -n "$perm_rpath"; then
10482*4882a593Smuzhiyun	  # We should set the runpath_var.
10483*4882a593Smuzhiyun	  rpath=
10484*4882a593Smuzhiyun	  for dir in $perm_rpath; do
10485*4882a593Smuzhiyun	    func_append rpath "$dir:"
10486*4882a593Smuzhiyun	  done
10487*4882a593Smuzhiyun	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10488*4882a593Smuzhiyun	fi
10489*4882a593Smuzhiyun	if test -n "$finalize_perm_rpath"; then
10490*4882a593Smuzhiyun	  # We should set the runpath_var.
10491*4882a593Smuzhiyun	  rpath=
10492*4882a593Smuzhiyun	  for dir in $finalize_perm_rpath; do
10493*4882a593Smuzhiyun	    func_append rpath "$dir:"
10494*4882a593Smuzhiyun	  done
10495*4882a593Smuzhiyun	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10496*4882a593Smuzhiyun	fi
10497*4882a593Smuzhiyun      fi
10498*4882a593Smuzhiyun
10499*4882a593Smuzhiyun      if test yes = "$no_install"; then
10500*4882a593Smuzhiyun	# We don't need to create a wrapper script.
10501*4882a593Smuzhiyun	link_command=$compile_var$compile_command$compile_rpath
10502*4882a593Smuzhiyun	# Replace the output file specification.
10503*4882a593Smuzhiyun	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10504*4882a593Smuzhiyun	# Delete the old output file.
10505*4882a593Smuzhiyun	$opt_dry_run || $RM $output
10506*4882a593Smuzhiyun	# Link the executable and exit
10507*4882a593Smuzhiyun	func_show_eval "$link_command" 'exit $?'
10508*4882a593Smuzhiyun
10509*4882a593Smuzhiyun	if test -n "$postlink_cmds"; then
10510*4882a593Smuzhiyun	  func_to_tool_file "$output"
10511*4882a593Smuzhiyun	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10512*4882a593Smuzhiyun	  func_execute_cmds "$postlink_cmds" 'exit $?'
10513*4882a593Smuzhiyun	fi
10514*4882a593Smuzhiyun
10515*4882a593Smuzhiyun	exit $EXIT_SUCCESS
10516*4882a593Smuzhiyun      fi
10517*4882a593Smuzhiyun
10518*4882a593Smuzhiyun      case $hardcode_action,$fast_install in
10519*4882a593Smuzhiyun        relink,*)
10520*4882a593Smuzhiyun	  # Fast installation is not supported
10521*4882a593Smuzhiyun	  link_command=$compile_var$compile_command$compile_rpath
10522*4882a593Smuzhiyun	  relink_command=$finalize_var$finalize_command$finalize_rpath
10523*4882a593Smuzhiyun
10524*4882a593Smuzhiyun	  func_warning "this platform does not like uninstalled shared libraries"
10525*4882a593Smuzhiyun	  func_warning "'$output' will be relinked during installation"
10526*4882a593Smuzhiyun	  ;;
10527*4882a593Smuzhiyun        *,yes)
10528*4882a593Smuzhiyun	  link_command=$finalize_var$compile_command$finalize_rpath
10529*4882a593Smuzhiyun	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10530*4882a593Smuzhiyun          ;;
10531*4882a593Smuzhiyun	*,no)
10532*4882a593Smuzhiyun	  link_command=$compile_var$compile_command$compile_rpath
10533*4882a593Smuzhiyun	  relink_command=$finalize_var$finalize_command$finalize_rpath
10534*4882a593Smuzhiyun          ;;
10535*4882a593Smuzhiyun	*,needless)
10536*4882a593Smuzhiyun	  link_command=$finalize_var$compile_command$finalize_rpath
10537*4882a593Smuzhiyun	  relink_command=
10538*4882a593Smuzhiyun          ;;
10539*4882a593Smuzhiyun      esac
10540*4882a593Smuzhiyun
10541*4882a593Smuzhiyun      # Replace the output file specification.
10542*4882a593Smuzhiyun      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10543*4882a593Smuzhiyun
10544*4882a593Smuzhiyun      # Delete the old output files.
10545*4882a593Smuzhiyun      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10546*4882a593Smuzhiyun
10547*4882a593Smuzhiyun      func_show_eval "$link_command" 'exit $?'
10548*4882a593Smuzhiyun
10549*4882a593Smuzhiyun      if test -n "$postlink_cmds"; then
10550*4882a593Smuzhiyun	func_to_tool_file "$output_objdir/$outputname"
10551*4882a593Smuzhiyun	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'`
10552*4882a593Smuzhiyun	func_execute_cmds "$postlink_cmds" 'exit $?'
10553*4882a593Smuzhiyun      fi
10554*4882a593Smuzhiyun
10555*4882a593Smuzhiyun      # Now create the wrapper script.
10556*4882a593Smuzhiyun      func_verbose "creating $output"
10557*4882a593Smuzhiyun
10558*4882a593Smuzhiyun      # Quote the relink command for shipping.
10559*4882a593Smuzhiyun      if test -n "$relink_command"; then
10560*4882a593Smuzhiyun	# Preserve any variables that may affect compiler behavior
10561*4882a593Smuzhiyun	for var in $variables_saved_for_relink; do
10562*4882a593Smuzhiyun	  if eval test -z \"\${$var+set}\"; then
10563*4882a593Smuzhiyun	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10564*4882a593Smuzhiyun	  elif eval var_value=\$$var; test -z "$var_value"; then
10565*4882a593Smuzhiyun	    relink_command="$var=; export $var; $relink_command"
10566*4882a593Smuzhiyun	  else
10567*4882a593Smuzhiyun	    func_quote_for_eval "$var_value"
10568*4882a593Smuzhiyun	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10569*4882a593Smuzhiyun	  fi
10570*4882a593Smuzhiyun	done
10571*4882a593Smuzhiyun	func_quote "(cd `pwd`; $relink_command)"
10572*4882a593Smuzhiyun	relink_command=$func_quote_result
10573*4882a593Smuzhiyun      fi
10574*4882a593Smuzhiyun
10575*4882a593Smuzhiyun      # Only actually do things if not in dry run mode.
10576*4882a593Smuzhiyun      $opt_dry_run || {
10577*4882a593Smuzhiyun	# win32 will think the script is a binary if it has
10578*4882a593Smuzhiyun	# a .exe suffix, so we strip it off here.
10579*4882a593Smuzhiyun	case $output in
10580*4882a593Smuzhiyun	  *.exe) func_stripname '' '.exe' "$output"
10581*4882a593Smuzhiyun	         output=$func_stripname_result ;;
10582*4882a593Smuzhiyun	esac
10583*4882a593Smuzhiyun	# test for cygwin because mv fails w/o .exe extensions
10584*4882a593Smuzhiyun	case $host in
10585*4882a593Smuzhiyun	  *cygwin*)
10586*4882a593Smuzhiyun	    exeext=.exe
10587*4882a593Smuzhiyun	    func_stripname '' '.exe' "$outputname"
10588*4882a593Smuzhiyun	    outputname=$func_stripname_result ;;
10589*4882a593Smuzhiyun	  *) exeext= ;;
10590*4882a593Smuzhiyun	esac
10591*4882a593Smuzhiyun	case $host in
10592*4882a593Smuzhiyun	  *cygwin* | *mingw* )
10593*4882a593Smuzhiyun	    func_dirname_and_basename "$output" "" "."
10594*4882a593Smuzhiyun	    output_name=$func_basename_result
10595*4882a593Smuzhiyun	    output_path=$func_dirname_result
10596*4882a593Smuzhiyun	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10597*4882a593Smuzhiyun	    cwrapper=$output_path/$output_name.exe
10598*4882a593Smuzhiyun	    $RM $cwrappersource $cwrapper
10599*4882a593Smuzhiyun	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10600*4882a593Smuzhiyun
10601*4882a593Smuzhiyun	    func_emit_cwrapperexe_src > $cwrappersource
10602*4882a593Smuzhiyun
10603*4882a593Smuzhiyun	    # The wrapper executable is built using the $host compiler,
10604*4882a593Smuzhiyun	    # because it contains $host paths and files. If cross-
10605*4882a593Smuzhiyun	    # compiling, it, like the target executable, must be
10606*4882a593Smuzhiyun	    # executed on the $host or under an emulation environment.
10607*4882a593Smuzhiyun	    $opt_dry_run || {
10608*4882a593Smuzhiyun	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10609*4882a593Smuzhiyun	      $STRIP $cwrapper
10610*4882a593Smuzhiyun	    }
10611*4882a593Smuzhiyun
10612*4882a593Smuzhiyun	    # Now, create the wrapper script for func_source use:
10613*4882a593Smuzhiyun	    func_ltwrapper_scriptname $cwrapper
10614*4882a593Smuzhiyun	    $RM $func_ltwrapper_scriptname_result
10615*4882a593Smuzhiyun	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10616*4882a593Smuzhiyun	    $opt_dry_run || {
10617*4882a593Smuzhiyun	      # note: this script will not be executed, so do not chmod.
10618*4882a593Smuzhiyun	      if test "x$build" = "x$host"; then
10619*4882a593Smuzhiyun		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10620*4882a593Smuzhiyun	      else
10621*4882a593Smuzhiyun		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10622*4882a593Smuzhiyun	      fi
10623*4882a593Smuzhiyun	    }
10624*4882a593Smuzhiyun	  ;;
10625*4882a593Smuzhiyun	  * )
10626*4882a593Smuzhiyun	    $RM $output
10627*4882a593Smuzhiyun	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10628*4882a593Smuzhiyun
10629*4882a593Smuzhiyun	    func_emit_wrapper no > $output
10630*4882a593Smuzhiyun	    chmod +x $output
10631*4882a593Smuzhiyun	  ;;
10632*4882a593Smuzhiyun	esac
10633*4882a593Smuzhiyun      }
10634*4882a593Smuzhiyun      exit $EXIT_SUCCESS
10635*4882a593Smuzhiyun      ;;
10636*4882a593Smuzhiyun    esac
10637*4882a593Smuzhiyun
10638*4882a593Smuzhiyun    # See if we need to build an old-fashioned archive.
10639*4882a593Smuzhiyun    for oldlib in $oldlibs; do
10640*4882a593Smuzhiyun
10641*4882a593Smuzhiyun      case $build_libtool_libs in
10642*4882a593Smuzhiyun        convenience)
10643*4882a593Smuzhiyun	  oldobjs="$libobjs_save $symfileobj"
10644*4882a593Smuzhiyun	  addlibs=$convenience
10645*4882a593Smuzhiyun	  build_libtool_libs=no
10646*4882a593Smuzhiyun	  ;;
10647*4882a593Smuzhiyun	module)
10648*4882a593Smuzhiyun	  oldobjs=$libobjs_save
10649*4882a593Smuzhiyun	  addlibs=$old_convenience
10650*4882a593Smuzhiyun	  build_libtool_libs=no
10651*4882a593Smuzhiyun          ;;
10652*4882a593Smuzhiyun	*)
10653*4882a593Smuzhiyun	  oldobjs="$old_deplibs $non_pic_objects"
10654*4882a593Smuzhiyun	  $preload && test -f "$symfileobj" \
10655*4882a593Smuzhiyun	    && func_append oldobjs " $symfileobj"
10656*4882a593Smuzhiyun	  addlibs=$old_convenience
10657*4882a593Smuzhiyun	  ;;
10658*4882a593Smuzhiyun      esac
10659*4882a593Smuzhiyun
10660*4882a593Smuzhiyun      if test -n "$addlibs"; then
10661*4882a593Smuzhiyun	gentop=$output_objdir/${outputname}x
10662*4882a593Smuzhiyun	func_append generated " $gentop"
10663*4882a593Smuzhiyun
10664*4882a593Smuzhiyun	func_extract_archives $gentop $addlibs
10665*4882a593Smuzhiyun	func_append oldobjs " $func_extract_archives_result"
10666*4882a593Smuzhiyun      fi
10667*4882a593Smuzhiyun
10668*4882a593Smuzhiyun      # Do each command in the archive commands.
10669*4882a593Smuzhiyun      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10670*4882a593Smuzhiyun	cmds=$old_archive_from_new_cmds
10671*4882a593Smuzhiyun      else
10672*4882a593Smuzhiyun
10673*4882a593Smuzhiyun	# Add any objects from preloaded convenience libraries
10674*4882a593Smuzhiyun	if test -n "$dlprefiles"; then
10675*4882a593Smuzhiyun	  gentop=$output_objdir/${outputname}x
10676*4882a593Smuzhiyun	  func_append generated " $gentop"
10677*4882a593Smuzhiyun
10678*4882a593Smuzhiyun	  func_extract_archives $gentop $dlprefiles
10679*4882a593Smuzhiyun	  func_append oldobjs " $func_extract_archives_result"
10680*4882a593Smuzhiyun	fi
10681*4882a593Smuzhiyun
10682*4882a593Smuzhiyun	# POSIX demands no paths to be encoded in archives.  We have
10683*4882a593Smuzhiyun	# to avoid creating archives with duplicate basenames if we
10684*4882a593Smuzhiyun	# might have to extract them afterwards, e.g., when creating a
10685*4882a593Smuzhiyun	# static archive out of a convenience library, or when linking
10686*4882a593Smuzhiyun	# the entirety of a libtool archive into another (currently
10687*4882a593Smuzhiyun	# not supported by libtool).
10688*4882a593Smuzhiyun	if (for obj in $oldobjs
10689*4882a593Smuzhiyun	    do
10690*4882a593Smuzhiyun	      func_basename "$obj"
10691*4882a593Smuzhiyun	      $ECHO "$func_basename_result"
10692*4882a593Smuzhiyun	    done | sort | sort -uc >/dev/null 2>&1); then
10693*4882a593Smuzhiyun	  :
10694*4882a593Smuzhiyun	else
10695*4882a593Smuzhiyun	  echo "copying selected object files to avoid basename conflicts..."
10696*4882a593Smuzhiyun	  gentop=$output_objdir/${outputname}x
10697*4882a593Smuzhiyun	  func_append generated " $gentop"
10698*4882a593Smuzhiyun	  func_mkdir_p "$gentop"
10699*4882a593Smuzhiyun	  save_oldobjs=$oldobjs
10700*4882a593Smuzhiyun	  oldobjs=
10701*4882a593Smuzhiyun	  counter=1
10702*4882a593Smuzhiyun	  for obj in $save_oldobjs
10703*4882a593Smuzhiyun	  do
10704*4882a593Smuzhiyun	    func_basename "$obj"
10705*4882a593Smuzhiyun	    objbase=$func_basename_result
10706*4882a593Smuzhiyun	    case " $oldobjs " in
10707*4882a593Smuzhiyun	    " ") oldobjs=$obj ;;
10708*4882a593Smuzhiyun	    *[\ /]"$objbase "*)
10709*4882a593Smuzhiyun	      while :; do
10710*4882a593Smuzhiyun		# Make sure we don't pick an alternate name that also
10711*4882a593Smuzhiyun		# overlaps.
10712*4882a593Smuzhiyun		newobj=lt$counter-$objbase
10713*4882a593Smuzhiyun		func_arith $counter + 1
10714*4882a593Smuzhiyun		counter=$func_arith_result
10715*4882a593Smuzhiyun		case " $oldobjs " in
10716*4882a593Smuzhiyun		*[\ /]"$newobj "*) ;;
10717*4882a593Smuzhiyun		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10718*4882a593Smuzhiyun		esac
10719*4882a593Smuzhiyun	      done
10720*4882a593Smuzhiyun	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10721*4882a593Smuzhiyun	      func_append oldobjs " $gentop/$newobj"
10722*4882a593Smuzhiyun	      ;;
10723*4882a593Smuzhiyun	    *) func_append oldobjs " $obj" ;;
10724*4882a593Smuzhiyun	    esac
10725*4882a593Smuzhiyun	  done
10726*4882a593Smuzhiyun	fi
10727*4882a593Smuzhiyun	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10728*4882a593Smuzhiyun	tool_oldlib=$func_to_tool_file_result
10729*4882a593Smuzhiyun	eval cmds=\"$old_archive_cmds\"
10730*4882a593Smuzhiyun
10731*4882a593Smuzhiyun	func_len " $cmds"
10732*4882a593Smuzhiyun	len=$func_len_result
10733*4882a593Smuzhiyun	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10734*4882a593Smuzhiyun	  cmds=$old_archive_cmds
10735*4882a593Smuzhiyun	elif test -n "$archiver_list_spec"; then
10736*4882a593Smuzhiyun	  func_verbose "using command file archive linking..."
10737*4882a593Smuzhiyun	  for obj in $oldobjs
10738*4882a593Smuzhiyun	  do
10739*4882a593Smuzhiyun	    func_to_tool_file "$obj"
10740*4882a593Smuzhiyun	    $ECHO "$func_to_tool_file_result"
10741*4882a593Smuzhiyun	  done > $output_objdir/$libname.libcmd
10742*4882a593Smuzhiyun	  func_to_tool_file "$output_objdir/$libname.libcmd"
10743*4882a593Smuzhiyun	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10744*4882a593Smuzhiyun	  cmds=$old_archive_cmds
10745*4882a593Smuzhiyun	else
10746*4882a593Smuzhiyun	  # the command line is too long to link in one step, link in parts
10747*4882a593Smuzhiyun	  func_verbose "using piecewise archive linking..."
10748*4882a593Smuzhiyun	  save_RANLIB=$RANLIB
10749*4882a593Smuzhiyun	  RANLIB=:
10750*4882a593Smuzhiyun	  objlist=
10751*4882a593Smuzhiyun	  concat_cmds=
10752*4882a593Smuzhiyun	  save_oldobjs=$oldobjs
10753*4882a593Smuzhiyun	  oldobjs=
10754*4882a593Smuzhiyun	  # Is there a better way of finding the last object in the list?
10755*4882a593Smuzhiyun	  for obj in $save_oldobjs
10756*4882a593Smuzhiyun	  do
10757*4882a593Smuzhiyun	    last_oldobj=$obj
10758*4882a593Smuzhiyun	  done
10759*4882a593Smuzhiyun	  eval test_cmds=\"$old_archive_cmds\"
10760*4882a593Smuzhiyun	  func_len " $test_cmds"
10761*4882a593Smuzhiyun	  len0=$func_len_result
10762*4882a593Smuzhiyun	  len=$len0
10763*4882a593Smuzhiyun	  for obj in $save_oldobjs
10764*4882a593Smuzhiyun	  do
10765*4882a593Smuzhiyun	    func_len " $obj"
10766*4882a593Smuzhiyun	    func_arith $len + $func_len_result
10767*4882a593Smuzhiyun	    len=$func_arith_result
10768*4882a593Smuzhiyun	    func_append objlist " $obj"
10769*4882a593Smuzhiyun	    if test "$len" -lt "$max_cmd_len"; then
10770*4882a593Smuzhiyun	      :
10771*4882a593Smuzhiyun	    else
10772*4882a593Smuzhiyun	      # the above command should be used before it gets too long
10773*4882a593Smuzhiyun	      oldobjs=$objlist
10774*4882a593Smuzhiyun	      if test "$obj" = "$last_oldobj"; then
10775*4882a593Smuzhiyun		RANLIB=$save_RANLIB
10776*4882a593Smuzhiyun	      fi
10777*4882a593Smuzhiyun	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10778*4882a593Smuzhiyun	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
10779*4882a593Smuzhiyun	      objlist=
10780*4882a593Smuzhiyun	      len=$len0
10781*4882a593Smuzhiyun	    fi
10782*4882a593Smuzhiyun	  done
10783*4882a593Smuzhiyun	  RANLIB=$save_RANLIB
10784*4882a593Smuzhiyun	  oldobjs=$objlist
10785*4882a593Smuzhiyun	  if test -z "$oldobjs"; then
10786*4882a593Smuzhiyun	    eval cmds=\"\$concat_cmds\"
10787*4882a593Smuzhiyun	  else
10788*4882a593Smuzhiyun	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
10789*4882a593Smuzhiyun	  fi
10790*4882a593Smuzhiyun	fi
10791*4882a593Smuzhiyun      fi
10792*4882a593Smuzhiyun      func_execute_cmds "$cmds" 'exit $?'
10793*4882a593Smuzhiyun    done
10794*4882a593Smuzhiyun
10795*4882a593Smuzhiyun    test -n "$generated" && \
10796*4882a593Smuzhiyun      func_show_eval "${RM}r$generated"
10797*4882a593Smuzhiyun
10798*4882a593Smuzhiyun    # Now create the libtool archive.
10799*4882a593Smuzhiyun    case $output in
10800*4882a593Smuzhiyun    *.la)
10801*4882a593Smuzhiyun      old_library=
10802*4882a593Smuzhiyun      test yes = "$build_old_libs" && old_library=$libname.$libext
10803*4882a593Smuzhiyun      func_verbose "creating $output"
10804*4882a593Smuzhiyun
10805*4882a593Smuzhiyun      # Preserve any variables that may affect compiler behavior
10806*4882a593Smuzhiyun      for var in $variables_saved_for_relink; do
10807*4882a593Smuzhiyun	if eval test -z \"\${$var+set}\"; then
10808*4882a593Smuzhiyun	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10809*4882a593Smuzhiyun	elif eval var_value=\$$var; test -z "$var_value"; then
10810*4882a593Smuzhiyun	  relink_command="$var=; export $var; $relink_command"
10811*4882a593Smuzhiyun	else
10812*4882a593Smuzhiyun	  func_quote_for_eval "$var_value"
10813*4882a593Smuzhiyun	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10814*4882a593Smuzhiyun	fi
10815*4882a593Smuzhiyun      done
10816*4882a593Smuzhiyun      # Quote the link command for shipping.
10817*4882a593Smuzhiyun      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
10818*4882a593Smuzhiyun      func_quote "$relink_command"
10819*4882a593Smuzhiyun      relink_command=$func_quote_result
10820*4882a593Smuzhiyun      if test yes = "$hardcode_automatic"; then
10821*4882a593Smuzhiyun	relink_command=
10822*4882a593Smuzhiyun      fi
10823*4882a593Smuzhiyun
10824*4882a593Smuzhiyun      # Only create the output if not a dry run.
10825*4882a593Smuzhiyun      $opt_dry_run || {
10826*4882a593Smuzhiyun	for installed in no yes; do
10827*4882a593Smuzhiyun	  if test yes = "$installed"; then
10828*4882a593Smuzhiyun	    if test -z "$install_libdir"; then
10829*4882a593Smuzhiyun	      break
10830*4882a593Smuzhiyun	    fi
10831*4882a593Smuzhiyun	    output=$output_objdir/${outputname}i
10832*4882a593Smuzhiyun	    # Replace all uninstalled libtool libraries with the installed ones
10833*4882a593Smuzhiyun	    newdependency_libs=
10834*4882a593Smuzhiyun	    for deplib in $dependency_libs; do
10835*4882a593Smuzhiyun	      case $deplib in
10836*4882a593Smuzhiyun	      *.la)
10837*4882a593Smuzhiyun		func_basename "$deplib"
10838*4882a593Smuzhiyun		name=$func_basename_result
10839*4882a593Smuzhiyun		func_resolve_sysroot "$deplib"
10840*4882a593Smuzhiyun		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
10841*4882a593Smuzhiyun		test -z "$libdir" && \
10842*4882a593Smuzhiyun		  func_fatal_error "'$deplib' is not a valid libtool archive"
10843*4882a593Smuzhiyun		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
10844*4882a593Smuzhiyun		;;
10845*4882a593Smuzhiyun	      -L*)
10846*4882a593Smuzhiyun		func_stripname -L '' "$deplib"
10847*4882a593Smuzhiyun		func_replace_sysroot "$func_stripname_result"
10848*4882a593Smuzhiyun		func_append newdependency_libs " -L$func_replace_sysroot_result"
10849*4882a593Smuzhiyun		;;
10850*4882a593Smuzhiyun	      -R*)
10851*4882a593Smuzhiyun		func_stripname -R '' "$deplib"
10852*4882a593Smuzhiyun		func_replace_sysroot "$func_stripname_result"
10853*4882a593Smuzhiyun		func_append newdependency_libs " -R$func_replace_sysroot_result"
10854*4882a593Smuzhiyun		;;
10855*4882a593Smuzhiyun	      *) func_append newdependency_libs " $deplib" ;;
10856*4882a593Smuzhiyun	      esac
10857*4882a593Smuzhiyun	    done
10858*4882a593Smuzhiyun	    dependency_libs=$newdependency_libs
10859*4882a593Smuzhiyun	    newdlfiles=
10860*4882a593Smuzhiyun
10861*4882a593Smuzhiyun	    for lib in $dlfiles; do
10862*4882a593Smuzhiyun	      case $lib in
10863*4882a593Smuzhiyun	      *.la)
10864*4882a593Smuzhiyun	        func_basename "$lib"
10865*4882a593Smuzhiyun		name=$func_basename_result
10866*4882a593Smuzhiyun		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
10867*4882a593Smuzhiyun		test -z "$libdir" && \
10868*4882a593Smuzhiyun		  func_fatal_error "'$lib' is not a valid libtool archive"
10869*4882a593Smuzhiyun		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
10870*4882a593Smuzhiyun		;;
10871*4882a593Smuzhiyun	      *) func_append newdlfiles " $lib" ;;
10872*4882a593Smuzhiyun	      esac
10873*4882a593Smuzhiyun	    done
10874*4882a593Smuzhiyun	    dlfiles=$newdlfiles
10875*4882a593Smuzhiyun	    newdlprefiles=
10876*4882a593Smuzhiyun	    for lib in $dlprefiles; do
10877*4882a593Smuzhiyun	      case $lib in
10878*4882a593Smuzhiyun	      *.la)
10879*4882a593Smuzhiyun		# Only pass preopened files to the pseudo-archive (for
10880*4882a593Smuzhiyun		# eventual linking with the app. that links it) if we
10881*4882a593Smuzhiyun		# didn't already link the preopened objects directly into
10882*4882a593Smuzhiyun		# the library:
10883*4882a593Smuzhiyun		func_basename "$lib"
10884*4882a593Smuzhiyun		name=$func_basename_result
10885*4882a593Smuzhiyun		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
10886*4882a593Smuzhiyun		test -z "$libdir" && \
10887*4882a593Smuzhiyun		  func_fatal_error "'$lib' is not a valid libtool archive"
10888*4882a593Smuzhiyun		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
10889*4882a593Smuzhiyun		;;
10890*4882a593Smuzhiyun	      esac
10891*4882a593Smuzhiyun	    done
10892*4882a593Smuzhiyun	    dlprefiles=$newdlprefiles
10893*4882a593Smuzhiyun	  else
10894*4882a593Smuzhiyun	    newdlfiles=
10895*4882a593Smuzhiyun	    for lib in $dlfiles; do
10896*4882a593Smuzhiyun	      case $lib in
10897*4882a593Smuzhiyun		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
10898*4882a593Smuzhiyun		*) abs=`pwd`"/$lib" ;;
10899*4882a593Smuzhiyun	      esac
10900*4882a593Smuzhiyun	      func_append newdlfiles " $abs"
10901*4882a593Smuzhiyun	    done
10902*4882a593Smuzhiyun	    dlfiles=$newdlfiles
10903*4882a593Smuzhiyun	    newdlprefiles=
10904*4882a593Smuzhiyun	    for lib in $dlprefiles; do
10905*4882a593Smuzhiyun	      case $lib in
10906*4882a593Smuzhiyun		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
10907*4882a593Smuzhiyun		*) abs=`pwd`"/$lib" ;;
10908*4882a593Smuzhiyun	      esac
10909*4882a593Smuzhiyun	      func_append newdlprefiles " $abs"
10910*4882a593Smuzhiyun	    done
10911*4882a593Smuzhiyun	    dlprefiles=$newdlprefiles
10912*4882a593Smuzhiyun	  fi
10913*4882a593Smuzhiyun	  $RM $output
10914*4882a593Smuzhiyun	  # place dlname in correct position for cygwin
10915*4882a593Smuzhiyun	  # In fact, it would be nice if we could use this code for all target
10916*4882a593Smuzhiyun	  # systems that can't hard-code library paths into their executables
10917*4882a593Smuzhiyun	  # and that have no shared library path variable independent of PATH,
10918*4882a593Smuzhiyun	  # but it turns out we can't easily determine that from inspecting
10919*4882a593Smuzhiyun	  # libtool variables, so we have to hard-code the OSs to which it
10920*4882a593Smuzhiyun	  # applies here; at the moment, that means platforms that use the PE
10921*4882a593Smuzhiyun	  # object format with DLL files.  See the long comment at the top of
10922*4882a593Smuzhiyun	  # tests/bindir.at for full details.
10923*4882a593Smuzhiyun	  tdlname=$dlname
10924*4882a593Smuzhiyun	  case $host,$output,$installed,$module,$dlname in
10925*4882a593Smuzhiyun	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
10926*4882a593Smuzhiyun	      # If a -bindir argument was supplied, place the dll there.
10927*4882a593Smuzhiyun	      if test -n "$bindir"; then
10928*4882a593Smuzhiyun		func_relative_path "$install_libdir" "$bindir"
10929*4882a593Smuzhiyun		tdlname=$func_relative_path_result/$dlname
10930*4882a593Smuzhiyun	      else
10931*4882a593Smuzhiyun		# Otherwise fall back on heuristic.
10932*4882a593Smuzhiyun		tdlname=../bin/$dlname
10933*4882a593Smuzhiyun	      fi
10934*4882a593Smuzhiyun	      ;;
10935*4882a593Smuzhiyun	  esac
10936*4882a593Smuzhiyun	  $ECHO > $output "\
10937*4882a593Smuzhiyun# $outputname - a libtool library file
10938*4882a593Smuzhiyun# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
10939*4882a593Smuzhiyun#
10940*4882a593Smuzhiyun# Please DO NOT delete this file!
10941*4882a593Smuzhiyun# It is necessary for linking the library.
10942*4882a593Smuzhiyun
10943*4882a593Smuzhiyun# The name that we can dlopen(3).
10944*4882a593Smuzhiyundlname='$tdlname'
10945*4882a593Smuzhiyun
10946*4882a593Smuzhiyun# Names of this library.
10947*4882a593Smuzhiyunlibrary_names='$library_names'
10948*4882a593Smuzhiyun
10949*4882a593Smuzhiyun# The name of the static archive.
10950*4882a593Smuzhiyunold_library='$old_library'
10951*4882a593Smuzhiyun
10952*4882a593Smuzhiyun# Linker flags that cannot go in dependency_libs.
10953*4882a593Smuzhiyuninherited_linker_flags='$new_inherited_linker_flags'
10954*4882a593Smuzhiyun
10955*4882a593Smuzhiyun# Libraries that this one depends upon.
10956*4882a593Smuzhiyundependency_libs='$dependency_libs'
10957*4882a593Smuzhiyun
10958*4882a593Smuzhiyun# Names of additional weak libraries provided by this library
10959*4882a593Smuzhiyunweak_library_names='$weak_libs'
10960*4882a593Smuzhiyun
10961*4882a593Smuzhiyun# Version information for $libname.
10962*4882a593Smuzhiyuncurrent=$current
10963*4882a593Smuzhiyunage=$age
10964*4882a593Smuzhiyunrevision=$revision
10965*4882a593Smuzhiyun
10966*4882a593Smuzhiyun# Is this an already installed library?
10967*4882a593Smuzhiyuninstalled=$installed
10968*4882a593Smuzhiyun
10969*4882a593Smuzhiyun# Should we warn about portability when linking against -modules?
10970*4882a593Smuzhiyunshouldnotlink=$module
10971*4882a593Smuzhiyun
10972*4882a593Smuzhiyun# Files to dlopen/dlpreopen
10973*4882a593Smuzhiyundlopen='$dlfiles'
10974*4882a593Smuzhiyundlpreopen='$dlprefiles'
10975*4882a593Smuzhiyun
10976*4882a593Smuzhiyun# Directory that this library needs to be installed in:
10977*4882a593Smuzhiyunlibdir='$install_libdir'"
10978*4882a593Smuzhiyun	  if test no,yes = "$installed,$need_relink"; then
10979*4882a593Smuzhiyun	    $ECHO >> $output "\
10980*4882a593Smuzhiyunrelink_command=\"$relink_command\""
10981*4882a593Smuzhiyun	  fi
10982*4882a593Smuzhiyun	done
10983*4882a593Smuzhiyun      }
10984*4882a593Smuzhiyun
10985*4882a593Smuzhiyun      # Do a symbolic link so that the libtool archive can be found in
10986*4882a593Smuzhiyun      # LD_LIBRARY_PATH before the program is installed.
10987*4882a593Smuzhiyun      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
10988*4882a593Smuzhiyun      ;;
10989*4882a593Smuzhiyun    esac
10990*4882a593Smuzhiyun    exit $EXIT_SUCCESS
10991*4882a593Smuzhiyun}
10992*4882a593Smuzhiyun
10993*4882a593Smuzhiyunif test link = "$opt_mode" || test relink = "$opt_mode"; then
10994*4882a593Smuzhiyun  func_mode_link ${1+"$@"}
10995*4882a593Smuzhiyunfi
10996*4882a593Smuzhiyun
10997*4882a593Smuzhiyun
10998*4882a593Smuzhiyun# func_mode_uninstall arg...
10999*4882a593Smuzhiyunfunc_mode_uninstall ()
11000*4882a593Smuzhiyun{
11001*4882a593Smuzhiyun    $debug_cmd
11002*4882a593Smuzhiyun
11003*4882a593Smuzhiyun    RM=$nonopt
11004*4882a593Smuzhiyun    files=
11005*4882a593Smuzhiyun    rmforce=false
11006*4882a593Smuzhiyun    exit_status=0
11007*4882a593Smuzhiyun
11008*4882a593Smuzhiyun    # This variable tells wrapper scripts just to set variables rather
11009*4882a593Smuzhiyun    # than running their programs.
11010*4882a593Smuzhiyun    libtool_install_magic=$magic
11011*4882a593Smuzhiyun
11012*4882a593Smuzhiyun    for arg
11013*4882a593Smuzhiyun    do
11014*4882a593Smuzhiyun      case $arg in
11015*4882a593Smuzhiyun      -f) func_append RM " $arg"; rmforce=: ;;
11016*4882a593Smuzhiyun      -*) func_append RM " $arg" ;;
11017*4882a593Smuzhiyun      *) func_append files " $arg" ;;
11018*4882a593Smuzhiyun      esac
11019*4882a593Smuzhiyun    done
11020*4882a593Smuzhiyun
11021*4882a593Smuzhiyun    test -z "$RM" && \
11022*4882a593Smuzhiyun      func_fatal_help "you must specify an RM program"
11023*4882a593Smuzhiyun
11024*4882a593Smuzhiyun    rmdirs=
11025*4882a593Smuzhiyun
11026*4882a593Smuzhiyun    for file in $files; do
11027*4882a593Smuzhiyun      func_dirname "$file" "" "."
11028*4882a593Smuzhiyun      dir=$func_dirname_result
11029*4882a593Smuzhiyun      if test . = "$dir"; then
11030*4882a593Smuzhiyun	odir=$objdir
11031*4882a593Smuzhiyun      else
11032*4882a593Smuzhiyun	odir=$dir/$objdir
11033*4882a593Smuzhiyun      fi
11034*4882a593Smuzhiyun      func_basename "$file"
11035*4882a593Smuzhiyun      name=$func_basename_result
11036*4882a593Smuzhiyun      test uninstall = "$opt_mode" && odir=$dir
11037*4882a593Smuzhiyun
11038*4882a593Smuzhiyun      # Remember odir for removal later, being careful to avoid duplicates
11039*4882a593Smuzhiyun      if test clean = "$opt_mode"; then
11040*4882a593Smuzhiyun	case " $rmdirs " in
11041*4882a593Smuzhiyun	  *" $odir "*) ;;
11042*4882a593Smuzhiyun	  *) func_append rmdirs " $odir" ;;
11043*4882a593Smuzhiyun	esac
11044*4882a593Smuzhiyun      fi
11045*4882a593Smuzhiyun
11046*4882a593Smuzhiyun      # Don't error if the file doesn't exist and rm -f was used.
11047*4882a593Smuzhiyun      if { test -L "$file"; } >/dev/null 2>&1 ||
11048*4882a593Smuzhiyun	 { test -h "$file"; } >/dev/null 2>&1 ||
11049*4882a593Smuzhiyun	 test -f "$file"; then
11050*4882a593Smuzhiyun	:
11051*4882a593Smuzhiyun      elif test -d "$file"; then
11052*4882a593Smuzhiyun	exit_status=1
11053*4882a593Smuzhiyun	continue
11054*4882a593Smuzhiyun      elif $rmforce; then
11055*4882a593Smuzhiyun	continue
11056*4882a593Smuzhiyun      fi
11057*4882a593Smuzhiyun
11058*4882a593Smuzhiyun      rmfiles=$file
11059*4882a593Smuzhiyun
11060*4882a593Smuzhiyun      case $name in
11061*4882a593Smuzhiyun      *.la)
11062*4882a593Smuzhiyun	# Possibly a libtool archive, so verify it.
11063*4882a593Smuzhiyun	if func_lalib_p "$file"; then
11064*4882a593Smuzhiyun	  func_source $dir/$name
11065*4882a593Smuzhiyun
11066*4882a593Smuzhiyun	  # Delete the libtool libraries and symlinks.
11067*4882a593Smuzhiyun	  for n in $library_names; do
11068*4882a593Smuzhiyun	    func_append rmfiles " $odir/$n"
11069*4882a593Smuzhiyun	  done
11070*4882a593Smuzhiyun	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11071*4882a593Smuzhiyun
11072*4882a593Smuzhiyun	  case $opt_mode in
11073*4882a593Smuzhiyun	  clean)
11074*4882a593Smuzhiyun	    case " $library_names " in
11075*4882a593Smuzhiyun	    *" $dlname "*) ;;
11076*4882a593Smuzhiyun	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11077*4882a593Smuzhiyun	    esac
11078*4882a593Smuzhiyun	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11079*4882a593Smuzhiyun	    ;;
11080*4882a593Smuzhiyun	  uninstall)
11081*4882a593Smuzhiyun	    if test -n "$library_names"; then
11082*4882a593Smuzhiyun	      # Do each command in the postuninstall commands.
11083*4882a593Smuzhiyun	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11084*4882a593Smuzhiyun	    fi
11085*4882a593Smuzhiyun
11086*4882a593Smuzhiyun	    if test -n "$old_library"; then
11087*4882a593Smuzhiyun	      # Do each command in the old_postuninstall commands.
11088*4882a593Smuzhiyun	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11089*4882a593Smuzhiyun	    fi
11090*4882a593Smuzhiyun	    # FIXME: should reinstall the best remaining shared library.
11091*4882a593Smuzhiyun	    ;;
11092*4882a593Smuzhiyun	  esac
11093*4882a593Smuzhiyun	fi
11094*4882a593Smuzhiyun	;;
11095*4882a593Smuzhiyun
11096*4882a593Smuzhiyun      *.lo)
11097*4882a593Smuzhiyun	# Possibly a libtool object, so verify it.
11098*4882a593Smuzhiyun	if func_lalib_p "$file"; then
11099*4882a593Smuzhiyun
11100*4882a593Smuzhiyun	  # Read the .lo file
11101*4882a593Smuzhiyun	  func_source $dir/$name
11102*4882a593Smuzhiyun
11103*4882a593Smuzhiyun	  # Add PIC object to the list of files to remove.
11104*4882a593Smuzhiyun	  if test -n "$pic_object" && test none != "$pic_object"; then
11105*4882a593Smuzhiyun	    func_append rmfiles " $dir/$pic_object"
11106*4882a593Smuzhiyun	  fi
11107*4882a593Smuzhiyun
11108*4882a593Smuzhiyun	  # Add non-PIC object to the list of files to remove.
11109*4882a593Smuzhiyun	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11110*4882a593Smuzhiyun	    func_append rmfiles " $dir/$non_pic_object"
11111*4882a593Smuzhiyun	  fi
11112*4882a593Smuzhiyun	fi
11113*4882a593Smuzhiyun	;;
11114*4882a593Smuzhiyun
11115*4882a593Smuzhiyun      *)
11116*4882a593Smuzhiyun	if test clean = "$opt_mode"; then
11117*4882a593Smuzhiyun	  noexename=$name
11118*4882a593Smuzhiyun	  case $file in
11119*4882a593Smuzhiyun	  *.exe)
11120*4882a593Smuzhiyun	    func_stripname '' '.exe' "$file"
11121*4882a593Smuzhiyun	    file=$func_stripname_result
11122*4882a593Smuzhiyun	    func_stripname '' '.exe' "$name"
11123*4882a593Smuzhiyun	    noexename=$func_stripname_result
11124*4882a593Smuzhiyun	    # $file with .exe has already been added to rmfiles,
11125*4882a593Smuzhiyun	    # add $file without .exe
11126*4882a593Smuzhiyun	    func_append rmfiles " $file"
11127*4882a593Smuzhiyun	    ;;
11128*4882a593Smuzhiyun	  esac
11129*4882a593Smuzhiyun	  # Do a test to see if this is a libtool program.
11130*4882a593Smuzhiyun	  if func_ltwrapper_p "$file"; then
11131*4882a593Smuzhiyun	    if func_ltwrapper_executable_p "$file"; then
11132*4882a593Smuzhiyun	      func_ltwrapper_scriptname "$file"
11133*4882a593Smuzhiyun	      relink_command=
11134*4882a593Smuzhiyun	      func_source $func_ltwrapper_scriptname_result
11135*4882a593Smuzhiyun	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11136*4882a593Smuzhiyun	    else
11137*4882a593Smuzhiyun	      relink_command=
11138*4882a593Smuzhiyun	      func_source $dir/$noexename
11139*4882a593Smuzhiyun	    fi
11140*4882a593Smuzhiyun
11141*4882a593Smuzhiyun	    # note $name still contains .exe if it was in $file originally
11142*4882a593Smuzhiyun	    # as does the version of $file that was added into $rmfiles
11143*4882a593Smuzhiyun	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11144*4882a593Smuzhiyun	    if test yes = "$fast_install" && test -n "$relink_command"; then
11145*4882a593Smuzhiyun	      func_append rmfiles " $odir/lt-$name"
11146*4882a593Smuzhiyun	    fi
11147*4882a593Smuzhiyun	    if test "X$noexename" != "X$name"; then
11148*4882a593Smuzhiyun	      func_append rmfiles " $odir/lt-$noexename.c"
11149*4882a593Smuzhiyun	    fi
11150*4882a593Smuzhiyun	  fi
11151*4882a593Smuzhiyun	fi
11152*4882a593Smuzhiyun	;;
11153*4882a593Smuzhiyun      esac
11154*4882a593Smuzhiyun      func_show_eval "$RM $rmfiles" 'exit_status=1'
11155*4882a593Smuzhiyun    done
11156*4882a593Smuzhiyun
11157*4882a593Smuzhiyun    # Try to remove the $objdir's in the directories where we deleted files
11158*4882a593Smuzhiyun    for dir in $rmdirs; do
11159*4882a593Smuzhiyun      if test -d "$dir"; then
11160*4882a593Smuzhiyun	func_show_eval "rmdir $dir >/dev/null 2>&1"
11161*4882a593Smuzhiyun      fi
11162*4882a593Smuzhiyun    done
11163*4882a593Smuzhiyun
11164*4882a593Smuzhiyun    exit $exit_status
11165*4882a593Smuzhiyun}
11166*4882a593Smuzhiyun
11167*4882a593Smuzhiyunif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11168*4882a593Smuzhiyun  func_mode_uninstall ${1+"$@"}
11169*4882a593Smuzhiyunfi
11170*4882a593Smuzhiyun
11171*4882a593Smuzhiyuntest -z "$opt_mode" && {
11172*4882a593Smuzhiyun  help=$generic_help
11173*4882a593Smuzhiyun  func_fatal_help "you must specify a MODE"
11174*4882a593Smuzhiyun}
11175*4882a593Smuzhiyun
11176*4882a593Smuzhiyuntest -z "$exec_cmd" && \
11177*4882a593Smuzhiyun  func_fatal_help "invalid operation mode '$opt_mode'"
11178*4882a593Smuzhiyun
11179*4882a593Smuzhiyunif test -n "$exec_cmd"; then
11180*4882a593Smuzhiyun  eval exec "$exec_cmd"
11181*4882a593Smuzhiyun  exit $EXIT_FAILURE
11182*4882a593Smuzhiyunfi
11183*4882a593Smuzhiyun
11184*4882a593Smuzhiyunexit $exit_status
11185*4882a593Smuzhiyun
11186*4882a593Smuzhiyun
11187*4882a593Smuzhiyun# The TAGs below are defined such that we never get into a situation
11188*4882a593Smuzhiyun# where we disable both kinds of libraries.  Given conflicting
11189*4882a593Smuzhiyun# choices, we go for a static library, that is the most portable,
11190*4882a593Smuzhiyun# since we can't tell whether shared libraries were disabled because
11191*4882a593Smuzhiyun# the user asked for that or because the platform doesn't support
11192*4882a593Smuzhiyun# them.  This is particularly important on AIX, because we don't
11193*4882a593Smuzhiyun# support having both static and shared libraries enabled at the same
11194*4882a593Smuzhiyun# time on that platform, so we default to a shared-only configuration.
11195*4882a593Smuzhiyun# If a disable-shared tag is given, we'll fallback to a static-only
11196*4882a593Smuzhiyun# configuration.  But we'll never go from static-only to shared-only.
11197*4882a593Smuzhiyun
11198*4882a593Smuzhiyun# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11199*4882a593Smuzhiyunbuild_libtool_libs=no
11200*4882a593Smuzhiyunbuild_old_libs=yes
11201*4882a593Smuzhiyun# ### END LIBTOOL TAG CONFIG: disable-shared
11202*4882a593Smuzhiyun
11203*4882a593Smuzhiyun# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11204*4882a593Smuzhiyunbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11205*4882a593Smuzhiyun# ### END LIBTOOL TAG CONFIG: disable-static
11206*4882a593Smuzhiyun
11207*4882a593Smuzhiyun# Local Variables:
11208*4882a593Smuzhiyun# mode:shell-script
11209*4882a593Smuzhiyun# sh-indentation:2
11210*4882a593Smuzhiyun# End:
11211