1beef1b22Smrg#! /usr/bin/env sh
2f395c03eSmrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3beef1b22Smrg##               by inline-source v2019-02-19.15
4e4f6584cSmrg
5beef1b22Smrg# libtool (GNU libtool) 2.4.7
6f395c03eSmrg# Provide generalized library-building support services.
7e4f6584cSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
8e4f6584cSmrg
9beef1b22Smrg# Copyright (C) 1996-2019, 2021-2022 Free Software Foundation, Inc.
10e4f6584cSmrg# This is free software; see the source for copying conditions.  There is NO
11e4f6584cSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12e4f6584cSmrg
13e4f6584cSmrg# GNU Libtool is free software; you can redistribute it and/or modify
1409885543Smrg# it under the terms of the GNU General Public License as published by
1509885543Smrg# the Free Software Foundation; either version 2 of the License, or
1609885543Smrg# (at your option) any later version.
1709885543Smrg#
18e4f6584cSmrg# As a special exception to the GNU General Public License,
19e4f6584cSmrg# if you distribute this file as part of a program or library that
20e4f6584cSmrg# is built using GNU Libtool, you may include this file under the
21e4f6584cSmrg# same distribution terms that you use for the rest of that program.
22e4f6584cSmrg#
23e4f6584cSmrg# GNU Libtool is distributed in the hope that it will be useful, but
2409885543Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
2509885543Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
2609885543Smrg# General Public License for more details.
2709885543Smrg#
2809885543Smrg# You should have received a copy of the GNU General Public License
29f395c03eSmrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30b698ba48Smrg
3109885543Smrg
32b12e5c03SmrgPROGRAM=libtool
3309885543SmrgPACKAGE=libtool
34beef1b22SmrgVERSION=2.4.7
35beef1b22Smrgpackage_revision=2.4.7
367104f784Smrg
37f395c03eSmrg
38f395c03eSmrg## ------ ##
39f395c03eSmrg## Usage. ##
40f395c03eSmrg## ------ ##
41f395c03eSmrg
42f395c03eSmrg# Run './libtool --help' for help with using this script from the
43f395c03eSmrg# command line.
44f395c03eSmrg
45f395c03eSmrg
46f395c03eSmrg## ------------------------------- ##
47f395c03eSmrg## User overridable command paths. ##
48f395c03eSmrg## ------------------------------- ##
49f395c03eSmrg
50f395c03eSmrg# After configure completes, it has a better idea of some of the
51f395c03eSmrg# shell tools we need than the defaults used by the functions shared
52f395c03eSmrg# with bootstrap, so set those here where they can still be over-
53f395c03eSmrg# ridden by the user, but otherwise take precedence.
54f395c03eSmrg
55f395c03eSmrg: ${AUTOCONF="autoconf"}
56f395c03eSmrg: ${AUTOMAKE="automake"}
57f395c03eSmrg
58f395c03eSmrg
59f395c03eSmrg## -------------------------- ##
60f395c03eSmrg## Source external libraries. ##
61f395c03eSmrg## -------------------------- ##
62f395c03eSmrg
63f395c03eSmrg# Much of our low-level functionality needs to be sourced from external
64f395c03eSmrg# libraries, which are installed to $pkgauxdir.
65f395c03eSmrg
66f395c03eSmrg# Set a version string for this script.
67beef1b22Smrgscriptversion=2019-02-19.15; # UTC
68f395c03eSmrg
69f395c03eSmrg# General shell script boiler plate, and helper functions.
70f395c03eSmrg# Written by Gary V. Vaughan, 2004
71f395c03eSmrg
72beef1b22Smrg# This is free software.  There is NO warranty; not even for
73beef1b22Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
74beef1b22Smrg#
75beef1b22Smrg# Copyright (C) 2004-2019, 2021 Bootstrap Authors
76beef1b22Smrg#
77beef1b22Smrg# This file is dual licensed under the terms of the MIT license
78beef1b22Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
79beef1b22Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
80beef1b22Smrg# these licenses when using or redistributing this software or any of
81beef1b22Smrg# the files within it.  See the URLs above, or the file `LICENSE`
82beef1b22Smrg# included in the Bootstrap distribution for the full license texts.
83f395c03eSmrg
84beef1b22Smrg# Please report bugs or propose patches to:
85beef1b22Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
86f395c03eSmrg
87f395c03eSmrg
88f395c03eSmrg## ------ ##
89f395c03eSmrg## Usage. ##
90f395c03eSmrg## ------ ##
91f395c03eSmrg
92f395c03eSmrg# Evaluate this file near the top of your script to gain access to
93f395c03eSmrg# the functions and variables defined here:
94f395c03eSmrg#
95f395c03eSmrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
96f395c03eSmrg#
97f395c03eSmrg# If you need to override any of the default environment variable
98f395c03eSmrg# settings, do that before evaluating this file.
99f395c03eSmrg
100f395c03eSmrg
101f395c03eSmrg## -------------------- ##
102f395c03eSmrg## Shell normalisation. ##
103f395c03eSmrg## -------------------- ##
104f395c03eSmrg
105f395c03eSmrg# Some shells need a little help to be as Bourne compatible as possible.
106f395c03eSmrg# Before doing anything else, make sure all that help has been provided!
107f395c03eSmrg
108f395c03eSmrgDUALCASE=1; export DUALCASE # for MKS sh
109f395c03eSmrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1107104f784Smrg  emulate sh
1117104f784Smrg  NULLCMD=:
112f395c03eSmrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1137104f784Smrg  # is contrary to our usage.  Disable this feature.
1147104f784Smrg  alias -g '${1+"$@"}'='"$@"'
11509885543Smrg  setopt NO_GLOB_SUBST
1167104f784Smrgelse
117f395c03eSmrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
11809885543Smrgfi
119b12e5c03Smrg
120f395c03eSmrg# NLS nuisances: We save the old values in case they are required later.
121f395c03eSmrg_G_user_locale=
122f395c03eSmrg_G_safe_locale=
123f395c03eSmrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1247104f784Smrgdo
125f395c03eSmrg  eval "if test set = \"\${$_G_var+set}\"; then
126f395c03eSmrg          save_$_G_var=\$$_G_var
127f395c03eSmrg          $_G_var=C
128f395c03eSmrg	  export $_G_var
129f395c03eSmrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
130f395c03eSmrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1317104f784Smrg	fi"
1327104f784Smrgdone
133beef1b22Smrg# These NLS vars are set unconditionally (bootstrap issue #24).  Unset those
134beef1b22Smrg# in case the environment reset is needed later and the $save_* variant is not
135beef1b22Smrg# defined (see the code above).
136beef1b22SmrgLC_ALL=C
137beef1b22SmrgLANGUAGE=C
138beef1b22Smrgexport LANGUAGE LC_ALL
139e4f6584cSmrg
140f395c03eSmrg# Make sure IFS has a sensible default
141f395c03eSmrgsp=' '
142f395c03eSmrgnl='
143f395c03eSmrg'
144f395c03eSmrgIFS="$sp	$nl"
145f395c03eSmrg
146f395c03eSmrg# There are apparently some retarded systems that use ';' as a PATH separator!
147f395c03eSmrgif test "${PATH_SEPARATOR+set}" != set; then
148f395c03eSmrg  PATH_SEPARATOR=:
149f395c03eSmrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
150f395c03eSmrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
151f395c03eSmrg      PATH_SEPARATOR=';'
152f395c03eSmrg  }
153f395c03eSmrgfi
154e4f6584cSmrg
155e4f6584cSmrg
156beef1b22Smrg# func_unset VAR
157beef1b22Smrg# --------------
158beef1b22Smrg# Portably unset VAR.
159beef1b22Smrg# In some shells, an 'unset VAR' statement leaves a non-zero return
160beef1b22Smrg# status if VAR is already unset, which might be problematic if the
161beef1b22Smrg# statement is used at the end of a function (thus poisoning its return
162beef1b22Smrg# value) or when 'set -e' is active (causing even a spurious abort of
163beef1b22Smrg# the script in this case).
164beef1b22Smrgfunc_unset ()
165beef1b22Smrg{
166beef1b22Smrg    { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; }
167beef1b22Smrg}
168beef1b22Smrg
169beef1b22Smrg
170beef1b22Smrg# Make sure CDPATH doesn't cause `cd` commands to output the target dir.
171beef1b22Smrgfunc_unset CDPATH
172beef1b22Smrg
173beef1b22Smrg# Make sure ${,E,F}GREP behave sanely.
174beef1b22Smrgfunc_unset GREP_OPTIONS
175beef1b22Smrg
176e4f6584cSmrg
177f395c03eSmrg## ------------------------- ##
178f395c03eSmrg## Locate command utilities. ##
179f395c03eSmrg## ------------------------- ##
180f395c03eSmrg
181f395c03eSmrg
182f395c03eSmrg# func_executable_p FILE
183f395c03eSmrg# ----------------------
184f395c03eSmrg# Check that FILE is an executable regular file.
185f395c03eSmrgfunc_executable_p ()
186f395c03eSmrg{
187f395c03eSmrg    test -f "$1" && test -x "$1"
188f395c03eSmrg}
189f395c03eSmrg
190f395c03eSmrg
191f395c03eSmrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
192f395c03eSmrg# --------------------------------------------
193f395c03eSmrg# Search for either a program that responds to --version with output
194f395c03eSmrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
195f395c03eSmrg# trying all the directories in PATH with each of the elements of
196f395c03eSmrg# PROGS_LIST.
197f395c03eSmrg#
198f395c03eSmrg# CHECK_FUNC should accept the path to a candidate program, and
199f395c03eSmrg# set $func_check_prog_result if it truncates its output less than
200f395c03eSmrg# $_G_path_prog_max characters.
201f395c03eSmrgfunc_path_progs ()
202f395c03eSmrg{
203f395c03eSmrg    _G_progs_list=$1
204f395c03eSmrg    _G_check_func=$2
205f395c03eSmrg    _G_PATH=${3-"$PATH"}
206f395c03eSmrg
207f395c03eSmrg    _G_path_prog_max=0
208f395c03eSmrg    _G_path_prog_found=false
209f395c03eSmrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
210f395c03eSmrg    for _G_dir in $_G_PATH; do
211f395c03eSmrg      IFS=$_G_save_IFS
212f395c03eSmrg      test -z "$_G_dir" && _G_dir=.
213f395c03eSmrg      for _G_prog_name in $_G_progs_list; do
214f395c03eSmrg        for _exeext in '' .EXE; do
215f395c03eSmrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
216f395c03eSmrg          func_executable_p "$_G_path_prog" || continue
217f395c03eSmrg          case `"$_G_path_prog" --version 2>&1` in
218f395c03eSmrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
219f395c03eSmrg            *)     $_G_check_func $_G_path_prog
220f395c03eSmrg		   func_path_progs_result=$func_check_prog_result
221f395c03eSmrg		   ;;
222f395c03eSmrg          esac
223f395c03eSmrg          $_G_path_prog_found && break 3
224f395c03eSmrg        done
225f395c03eSmrg      done
226f395c03eSmrg    done
227f395c03eSmrg    IFS=$_G_save_IFS
228f395c03eSmrg    test -z "$func_path_progs_result" && {
229f395c03eSmrg      echo "no acceptable sed could be found in \$PATH" >&2
230f395c03eSmrg      exit 1
231f395c03eSmrg    }
232f395c03eSmrg}
233f395c03eSmrg
234f395c03eSmrg
235f395c03eSmrg# We want to be able to use the functions in this file before configure
236f395c03eSmrg# has figured out where the best binaries are kept, which means we have
237f395c03eSmrg# to search for them ourselves - except when the results are already set
238f395c03eSmrg# where we skip the searches.
239f395c03eSmrg
240f395c03eSmrg# Unless the user overrides by setting SED, search the path for either GNU
241f395c03eSmrg# sed, or the sed that truncates its output the least.
242f395c03eSmrgtest -z "$SED" && {
243f395c03eSmrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
244f395c03eSmrg  for _G_i in 1 2 3 4 5 6 7; do
245f395c03eSmrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
246f395c03eSmrg  done
247f395c03eSmrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
248f395c03eSmrg  _G_sed_script=
249f395c03eSmrg
250f395c03eSmrg  func_check_prog_sed ()
251f395c03eSmrg  {
252f395c03eSmrg    _G_path_prog=$1
253f395c03eSmrg
254f395c03eSmrg    _G_count=0
255f395c03eSmrg    printf 0123456789 >conftest.in
256f395c03eSmrg    while :
257f395c03eSmrg    do
258f395c03eSmrg      cat conftest.in conftest.in >conftest.tmp
259f395c03eSmrg      mv conftest.tmp conftest.in
260f395c03eSmrg      cp conftest.in conftest.nl
261f395c03eSmrg      echo '' >> conftest.nl
262f395c03eSmrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
263f395c03eSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
264f395c03eSmrg      _G_count=`expr $_G_count + 1`
265f395c03eSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
266f395c03eSmrg        # Best one so far, save it but keep looking for a better one
267f395c03eSmrg        func_check_prog_result=$_G_path_prog
268f395c03eSmrg        _G_path_prog_max=$_G_count
269f395c03eSmrg      fi
270f395c03eSmrg      # 10*(2^10) chars as input seems more than enough
271f395c03eSmrg      test 10 -lt "$_G_count" && break
272f395c03eSmrg    done
273f395c03eSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
274f395c03eSmrg  }
275f395c03eSmrg
276beef1b22Smrg  func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin"
277f395c03eSmrg  rm -f conftest.sed
278f395c03eSmrg  SED=$func_path_progs_result
279f395c03eSmrg}
280f395c03eSmrg
281f395c03eSmrg
282f395c03eSmrg# Unless the user overrides by setting GREP, search the path for either GNU
283f395c03eSmrg# grep, or the grep that truncates its output the least.
284f395c03eSmrgtest -z "$GREP" && {
285f395c03eSmrg  func_check_prog_grep ()
286f395c03eSmrg  {
287f395c03eSmrg    _G_path_prog=$1
288f395c03eSmrg
289f395c03eSmrg    _G_count=0
290f395c03eSmrg    _G_path_prog_max=0
291f395c03eSmrg    printf 0123456789 >conftest.in
292f395c03eSmrg    while :
293f395c03eSmrg    do
294f395c03eSmrg      cat conftest.in conftest.in >conftest.tmp
295f395c03eSmrg      mv conftest.tmp conftest.in
296f395c03eSmrg      cp conftest.in conftest.nl
297f395c03eSmrg      echo 'GREP' >> conftest.nl
298f395c03eSmrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
299f395c03eSmrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
300f395c03eSmrg      _G_count=`expr $_G_count + 1`
301f395c03eSmrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
302f395c03eSmrg        # Best one so far, save it but keep looking for a better one
303f395c03eSmrg        func_check_prog_result=$_G_path_prog
304f395c03eSmrg        _G_path_prog_max=$_G_count
305f395c03eSmrg      fi
306f395c03eSmrg      # 10*(2^10) chars as input seems more than enough
307f395c03eSmrg      test 10 -lt "$_G_count" && break
308f395c03eSmrg    done
309f395c03eSmrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
310f395c03eSmrg  }
311f395c03eSmrg
312beef1b22Smrg  func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin"
313f395c03eSmrg  GREP=$func_path_progs_result
314f395c03eSmrg}
315f395c03eSmrg
316f395c03eSmrg
317f395c03eSmrg## ------------------------------- ##
318f395c03eSmrg## User overridable command paths. ##
319f395c03eSmrg## ------------------------------- ##
320f395c03eSmrg
321f395c03eSmrg# All uppercase variable names are used for environment variables.  These
322f395c03eSmrg# variables can be overridden by the user before calling a script that
323f395c03eSmrg# uses them if a suitable command of that name is not already available
324f395c03eSmrg# in the command search PATH.
325e4f6584cSmrg
326e4f6584cSmrg: ${CP="cp -f"}
327f395c03eSmrg: ${ECHO="printf %s\n"}
328f395c03eSmrg: ${EGREP="$GREP -E"}
329f395c03eSmrg: ${FGREP="$GREP -F"}
330f395c03eSmrg: ${LN_S="ln -s"}
331e4f6584cSmrg: ${MAKE="make"}
332e4f6584cSmrg: ${MKDIR="mkdir"}
333e4f6584cSmrg: ${MV="mv -f"}
334e4f6584cSmrg: ${RM="rm -f"}
335e4f6584cSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
33609885543Smrg
337e4f6584cSmrg
338f395c03eSmrg## -------------------- ##
339f395c03eSmrg## Useful sed snippets. ##
340f395c03eSmrg## -------------------- ##
341b12e5c03Smrg
342f395c03eSmrgsed_dirname='s|/[^/]*$||'
343f395c03eSmrgsed_basename='s|^.*/||'
344b12e5c03Smrg
345f395c03eSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
346f395c03eSmrg# metacharacters that are still active within double-quoted strings.
347f395c03eSmrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
348b12e5c03Smrg
349f395c03eSmrg# Same as above, but do not quote variable references.
350f395c03eSmrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
351b12e5c03Smrg
352f395c03eSmrg# Sed substitution that turns a string into a regex matching for the
353f395c03eSmrg# string literally.
354f395c03eSmrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
355b12e5c03Smrg
356f395c03eSmrg# Sed substitution that converts a w32 file name or path
357f395c03eSmrg# that contains forward slashes, into one that contains
358f395c03eSmrg# (escaped) backslashes.  A very naive implementation.
359f395c03eSmrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
360f395c03eSmrg
361f395c03eSmrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
362f395c03eSmrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
363f395c03eSmrg# '$' in input to sed_double_quote_subst, that '$' was protected from
364f395c03eSmrg# expansion.  Since each input '\' is now two '\'s, look for any number
365f395c03eSmrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
366f395c03eSmrg_G_bs='\\'
367f395c03eSmrg_G_bs2='\\\\'
368f395c03eSmrg_G_bs4='\\\\\\\\'
369f395c03eSmrg_G_dollar='\$'
370f395c03eSmrgsed_double_backslash="\
371f395c03eSmrg  s/$_G_bs4/&\\
372f395c03eSmrg/g
373f395c03eSmrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
374f395c03eSmrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
375f395c03eSmrg  s/\n//g"
376b12e5c03Smrg
377beef1b22Smrg# require_check_ifs_backslash
378beef1b22Smrg# ---------------------------
379beef1b22Smrg# Check if we can use backslash as IFS='\' separator, and set
380beef1b22Smrg# $check_ifs_backshlash_broken to ':' or 'false'.
381beef1b22Smrgrequire_check_ifs_backslash=func_require_check_ifs_backslash
382beef1b22Smrgfunc_require_check_ifs_backslash ()
383beef1b22Smrg{
384beef1b22Smrg  _G_save_IFS=$IFS
385beef1b22Smrg  IFS='\'
386beef1b22Smrg  _G_check_ifs_backshlash='a\\b'
387beef1b22Smrg  for _G_i in $_G_check_ifs_backshlash
388beef1b22Smrg  do
389beef1b22Smrg  case $_G_i in
390beef1b22Smrg  a)
391beef1b22Smrg    check_ifs_backshlash_broken=false
392beef1b22Smrg    ;;
393beef1b22Smrg  '')
394beef1b22Smrg    break
395beef1b22Smrg    ;;
396beef1b22Smrg  *)
397beef1b22Smrg    check_ifs_backshlash_broken=:
398beef1b22Smrg    break
399beef1b22Smrg    ;;
400beef1b22Smrg  esac
401beef1b22Smrg  done
402beef1b22Smrg  IFS=$_G_save_IFS
403beef1b22Smrg  require_check_ifs_backslash=:
404beef1b22Smrg}
405beef1b22Smrg
406b12e5c03Smrg
407f395c03eSmrg## ----------------- ##
408f395c03eSmrg## Global variables. ##
409f395c03eSmrg## ----------------- ##
410b12e5c03Smrg
411f395c03eSmrg# Except for the global variables explicitly listed below, the following
412f395c03eSmrg# functions in the '^func_' namespace, and the '^require_' namespace
413f395c03eSmrg# variables initialised in the 'Resource management' section, sourcing
414f395c03eSmrg# this file will not pollute your global namespace with anything
415f395c03eSmrg# else. There's no portable way to scope variables in Bourne shell
416f395c03eSmrg# though, so actually running these functions will sometimes place
417f395c03eSmrg# results into a variable named after the function, and often use
418f395c03eSmrg# temporary variables in the '^_G_' namespace. If you are careful to
419f395c03eSmrg# avoid using those namespaces casually in your sourcing script, things
420f395c03eSmrg# should continue to work as you expect. And, of course, you can freely
421f395c03eSmrg# overwrite any of the functions or variables defined here before
422f395c03eSmrg# calling anything to customize them.
423b12e5c03Smrg
424f395c03eSmrgEXIT_SUCCESS=0
425f395c03eSmrgEXIT_FAILURE=1
426f395c03eSmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
427f395c03eSmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
4282ec8c4b4Smrg
429f395c03eSmrg# Allow overriding, eg assuming that you follow the convention of
430f395c03eSmrg# putting '$debug_cmd' at the start of all your functions, you can get
431f395c03eSmrg# bash to show function call trace with:
432f395c03eSmrg#
433f395c03eSmrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
434f395c03eSmrgdebug_cmd=${debug_cmd-":"}
435f395c03eSmrgexit_cmd=:
436e4f6584cSmrg
437f395c03eSmrg# By convention, finish your script with:
438f395c03eSmrg#
439f395c03eSmrg#    exit $exit_status
440f395c03eSmrg#
441f395c03eSmrg# so that you can set exit_status to non-zero if you want to indicate
442f395c03eSmrg# something went wrong during execution without actually bailing out at
443f395c03eSmrg# the point of failure.
444f395c03eSmrgexit_status=$EXIT_SUCCESS
445b12e5c03Smrg
446f395c03eSmrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
447f395c03eSmrg# is ksh but when the shell is invoked as "sh" and the current value of
448f395c03eSmrg# the _XPG environment variable is not equal to 1 (one), the special
449f395c03eSmrg# positional parameter $0, within a function call, is the name of the
450f395c03eSmrg# function.
451f395c03eSmrgprogpath=$0
452e4f6584cSmrg
453f395c03eSmrg# The name of this program.
454f395c03eSmrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
455e4f6584cSmrg
456f395c03eSmrg# Make sure we have an absolute progpath for reexecution:
457e4f6584cSmrgcase $progpath in
458e4f6584cSmrg  [\\/]*|[A-Za-z]:\\*) ;;
459e4f6584cSmrg  *[\\/]*)
460f395c03eSmrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
461e4f6584cSmrg     progdir=`cd "$progdir" && pwd`
462f395c03eSmrg     progpath=$progdir/$progname
463e4f6584cSmrg     ;;
464e4f6584cSmrg  *)
465f395c03eSmrg     _G_IFS=$IFS
466b12e5c03Smrg     IFS=${PATH_SEPARATOR-:}
467e4f6584cSmrg     for progdir in $PATH; do
468f395c03eSmrg       IFS=$_G_IFS
469e4f6584cSmrg       test -x "$progdir/$progname" && break
470e4f6584cSmrg     done
471f395c03eSmrg     IFS=$_G_IFS
472e4f6584cSmrg     test -n "$progdir" || progdir=`pwd`
473f395c03eSmrg     progpath=$progdir/$progname
474e4f6584cSmrg     ;;
475e4f6584cSmrgesac
476e4f6584cSmrg
477e4f6584cSmrg
478f395c03eSmrg## ----------------- ##
479f395c03eSmrg## Standard options. ##
480f395c03eSmrg## ----------------- ##
481b12e5c03Smrg
482f395c03eSmrg# The following options affect the operation of the functions defined
483f395c03eSmrg# below, and should be set appropriately depending on run-time para-
484f395c03eSmrg# meters passed on the command line.
485e4f6584cSmrg
486e4f6584cSmrgopt_dry_run=false
487e4f6584cSmrgopt_quiet=false
488e4f6584cSmrgopt_verbose=false
489e4f6584cSmrg
490f395c03eSmrg# Categories 'all' and 'none' are always available.  Append any others
491f395c03eSmrg# you will pass as the first argument to func_warning from your own
492f395c03eSmrg# code.
493f395c03eSmrgwarning_categories=
494e4f6584cSmrg
495f395c03eSmrg# By default, display warnings according to 'opt_warning_types'.  Set
496f395c03eSmrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
497f395c03eSmrg# treat the next displayed warning as a fatal error.
498f395c03eSmrgwarning_func=func_warn_and_continue
499e4f6584cSmrg
500f395c03eSmrg# Set to 'all' to display all warnings, 'none' to suppress all
501f395c03eSmrg# warnings, or a space delimited list of some subset of
502f395c03eSmrg# 'warning_categories' to display only the listed warnings.
503f395c03eSmrgopt_warning_types=all
504e4f6584cSmrg
505b12e5c03Smrg
506f395c03eSmrg## -------------------- ##
507f395c03eSmrg## Resource management. ##
508f395c03eSmrg## -------------------- ##
509e4f6584cSmrg
510f395c03eSmrg# This section contains definitions for functions that each ensure a
511f395c03eSmrg# particular resource (a file, or a non-empty configuration variable for
512f395c03eSmrg# example) is available, and if appropriate to extract default values
513f395c03eSmrg# from pertinent package files. Call them using their associated
514f395c03eSmrg# 'require_*' variable to ensure that they are executed, at most, once.
515f395c03eSmrg#
516f395c03eSmrg# It's entirely deliberate that calling these functions can set
517f395c03eSmrg# variables that don't obey the namespace limitations obeyed by the rest
518f395c03eSmrg# of this file, in order that that they be as useful as possible to
519f395c03eSmrg# callers.
520e4f6584cSmrg
521e4f6584cSmrg
522f395c03eSmrg# require_term_colors
523f395c03eSmrg# -------------------
524f395c03eSmrg# Allow display of bold text on terminals that support it.
525f395c03eSmrgrequire_term_colors=func_require_term_colors
526f395c03eSmrgfunc_require_term_colors ()
527e4f6584cSmrg{
528f395c03eSmrg    $debug_cmd
529f395c03eSmrg
530f395c03eSmrg    test -t 1 && {
531f395c03eSmrg      # COLORTERM and USE_ANSI_COLORS environment variables take
532f395c03eSmrg      # precedence, because most terminfo databases neglect to describe
533f395c03eSmrg      # whether color sequences are supported.
534f395c03eSmrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
535f395c03eSmrg
536f395c03eSmrg      if test 1 = "$USE_ANSI_COLORS"; then
537f395c03eSmrg        # Standard ANSI escape sequences
538f395c03eSmrg        tc_reset='[0m'
539f395c03eSmrg        tc_bold='[1m';   tc_standout='[7m'
540f395c03eSmrg        tc_red='[31m';   tc_green='[32m'
541f395c03eSmrg        tc_blue='[34m';  tc_cyan='[36m'
542f395c03eSmrg      else
543f395c03eSmrg        # Otherwise trust the terminfo database after all.
544f395c03eSmrg        test -n "`tput sgr0 2>/dev/null`" && {
545f395c03eSmrg          tc_reset=`tput sgr0`
546f395c03eSmrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
547f395c03eSmrg          tc_standout=$tc_bold
548f395c03eSmrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
549f395c03eSmrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
550f395c03eSmrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
551f395c03eSmrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
552f395c03eSmrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
553f395c03eSmrg        }
554f395c03eSmrg      fi
555f395c03eSmrg    }
556e4f6584cSmrg
557f395c03eSmrg    require_term_colors=:
558e4f6584cSmrg}
559e4f6584cSmrg
560e4f6584cSmrg
561f395c03eSmrg## ----------------- ##
562f395c03eSmrg## Function library. ##
563f395c03eSmrg## ----------------- ##
564f395c03eSmrg
565f395c03eSmrg# This section contains a variety of useful functions to call in your
566f395c03eSmrg# scripts. Take note of the portable wrappers for features provided by
567f395c03eSmrg# some modern shells, which will fall back to slower equivalents on
568f395c03eSmrg# less featureful shells.
569f395c03eSmrg
570f395c03eSmrg
571f395c03eSmrg# func_append VAR VALUE
572f395c03eSmrg# ---------------------
573f395c03eSmrg# Append VALUE onto the existing contents of VAR.
574f395c03eSmrg
575f395c03eSmrg  # We should try to minimise forks, especially on Windows where they are
576f395c03eSmrg  # unreasonably slow, so skip the feature probes when bash or zsh are
577f395c03eSmrg  # being used:
578f395c03eSmrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
579f395c03eSmrg    : ${_G_HAVE_ARITH_OP="yes"}
580f395c03eSmrg    : ${_G_HAVE_XSI_OPS="yes"}
581f395c03eSmrg    # The += operator was introduced in bash 3.1
582f395c03eSmrg    case $BASH_VERSION in
583f395c03eSmrg      [12].* | 3.0 | 3.0*) ;;
584f395c03eSmrg      *)
585f395c03eSmrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
586f395c03eSmrg        ;;
587f395c03eSmrg    esac
588f395c03eSmrg  fi
589f395c03eSmrg
590f395c03eSmrg  # _G_HAVE_PLUSEQ_OP
591f395c03eSmrg  # Can be empty, in which case the shell is probed, "yes" if += is
592f395c03eSmrg  # useable or anything else if it does not work.
593f395c03eSmrg  test -z "$_G_HAVE_PLUSEQ_OP" \
594f395c03eSmrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
595f395c03eSmrg    && _G_HAVE_PLUSEQ_OP=yes
596f395c03eSmrg
597f395c03eSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"
598f395c03eSmrgthen
599f395c03eSmrg  # This is an XSI compatible shell, allowing a faster implementation...
600f395c03eSmrg  eval 'func_append ()
601f395c03eSmrg  {
602f395c03eSmrg    $debug_cmd
603f395c03eSmrg
604f395c03eSmrg    eval "$1+=\$2"
605f395c03eSmrg  }'
606f395c03eSmrgelse
607f395c03eSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
608f395c03eSmrg  func_append ()
609f395c03eSmrg  {
610f395c03eSmrg    $debug_cmd
611f395c03eSmrg
612f395c03eSmrg    eval "$1=\$$1\$2"
613f395c03eSmrg  }
614f395c03eSmrgfi
615f395c03eSmrg
616f395c03eSmrg
617f395c03eSmrg# func_append_quoted VAR VALUE
618f395c03eSmrg# ----------------------------
619f395c03eSmrg# Quote VALUE and append to the end of shell variable VAR, separated
620f395c03eSmrg# by a space.
621f395c03eSmrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
622f395c03eSmrg  eval 'func_append_quoted ()
623f395c03eSmrg  {
624f395c03eSmrg    $debug_cmd
625f395c03eSmrg
626beef1b22Smrg    func_quote_arg pretty "$2"
627beef1b22Smrg    eval "$1+=\\ \$func_quote_arg_result"
628f395c03eSmrg  }'
629f395c03eSmrgelse
630f395c03eSmrg  func_append_quoted ()
631f395c03eSmrg  {
632f395c03eSmrg    $debug_cmd
633f395c03eSmrg
634beef1b22Smrg    func_quote_arg pretty "$2"
635beef1b22Smrg    eval "$1=\$$1\\ \$func_quote_arg_result"
636f395c03eSmrg  }
637f395c03eSmrgfi
638f395c03eSmrg
639f395c03eSmrg
640f395c03eSmrg# func_append_uniq VAR VALUE
641f395c03eSmrg# --------------------------
642f395c03eSmrg# Append unique VALUE onto the existing contents of VAR, assuming
643f395c03eSmrg# entries are delimited by the first character of VALUE.  For example:
644f395c03eSmrg#
645f395c03eSmrg#   func_append_uniq options " --another-option option-argument"
646f395c03eSmrg#
647f395c03eSmrg# will only append to $options if " --another-option option-argument "
648f395c03eSmrg# is not already present somewhere in $options already (note spaces at
649f395c03eSmrg# each end implied by leading space in second argument).
650f395c03eSmrgfunc_append_uniq ()
651f395c03eSmrg{
652f395c03eSmrg    $debug_cmd
653f395c03eSmrg
654f395c03eSmrg    eval _G_current_value='`$ECHO $'$1'`'
655f395c03eSmrg    _G_delim=`expr "$2" : '\(.\)'`
656f395c03eSmrg
657f395c03eSmrg    case $_G_delim$_G_current_value$_G_delim in
658f395c03eSmrg      *"$2$_G_delim"*) ;;
659f395c03eSmrg      *) func_append "$@" ;;
660f395c03eSmrg    esac
661f395c03eSmrg}
662f395c03eSmrg
663f395c03eSmrg
664f395c03eSmrg# func_arith TERM...
665f395c03eSmrg# ------------------
666f395c03eSmrg# Set func_arith_result to the result of evaluating TERMs.
667f395c03eSmrg  test -z "$_G_HAVE_ARITH_OP" \
668f395c03eSmrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
669f395c03eSmrg    && _G_HAVE_ARITH_OP=yes
670f395c03eSmrg
671f395c03eSmrgif test yes = "$_G_HAVE_ARITH_OP"; then
672f395c03eSmrg  eval 'func_arith ()
673f395c03eSmrg  {
674f395c03eSmrg    $debug_cmd
675f395c03eSmrg
676f395c03eSmrg    func_arith_result=$(( $* ))
677f395c03eSmrg  }'
678f395c03eSmrgelse
679f395c03eSmrg  func_arith ()
680f395c03eSmrg  {
681f395c03eSmrg    $debug_cmd
682f395c03eSmrg
683f395c03eSmrg    func_arith_result=`expr "$@"`
684f395c03eSmrg  }
685f395c03eSmrgfi
686f395c03eSmrg
687f395c03eSmrg
688f395c03eSmrg# func_basename FILE
689f395c03eSmrg# ------------------
690f395c03eSmrg# Set func_basename_result to FILE with everything up to and including
691f395c03eSmrg# the last / stripped.
692f395c03eSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
693f395c03eSmrg  # If this shell supports suffix pattern removal, then use it to avoid
694f395c03eSmrg  # forking. Hide the definitions single quotes in case the shell chokes
695f395c03eSmrg  # on unsupported syntax...
696f395c03eSmrg  _b='func_basename_result=${1##*/}'
697f395c03eSmrg  _d='case $1 in
698f395c03eSmrg        */*) func_dirname_result=${1%/*}$2 ;;
699f395c03eSmrg        *  ) func_dirname_result=$3        ;;
700f395c03eSmrg      esac'
701f395c03eSmrg
702f395c03eSmrgelse
703f395c03eSmrg  # ...otherwise fall back to using sed.
704f395c03eSmrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
705f395c03eSmrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
706f395c03eSmrg      if test "X$func_dirname_result" = "X$1"; then
707f395c03eSmrg        func_dirname_result=$3
708f395c03eSmrg      else
709f395c03eSmrg        func_append func_dirname_result "$2"
710f395c03eSmrg      fi'
711f395c03eSmrgfi
712f395c03eSmrg
713f395c03eSmrgeval 'func_basename ()
714f395c03eSmrg{
715f395c03eSmrg    $debug_cmd
716f395c03eSmrg
717f395c03eSmrg    '"$_b"'
718f395c03eSmrg}'
719f395c03eSmrg
720f395c03eSmrg
721f395c03eSmrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
722f395c03eSmrg# -------------------------------------------
723f395c03eSmrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
724f395c03eSmrg# otherwise set result to NONDIR_REPLACEMENT.
725f395c03eSmrgeval 'func_dirname ()
726f395c03eSmrg{
727f395c03eSmrg    $debug_cmd
728f395c03eSmrg
729f395c03eSmrg    '"$_d"'
730f395c03eSmrg}'
731f395c03eSmrg
732f395c03eSmrg
733f395c03eSmrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
734f395c03eSmrg# --------------------------------------------------------
735f395c03eSmrg# Perform func_basename and func_dirname in a single function
736f395c03eSmrg# call:
737f395c03eSmrg#   dirname:  Compute the dirname of FILE.  If nonempty,
738f395c03eSmrg#             add APPEND to the result, otherwise set result
739f395c03eSmrg#             to NONDIR_REPLACEMENT.
740f395c03eSmrg#             value returned in "$func_dirname_result"
741f395c03eSmrg#   basename: Compute filename of FILE.
742f395c03eSmrg#             value retuned in "$func_basename_result"
743f395c03eSmrg# For efficiency, we do not delegate to the functions above but instead
744f395c03eSmrg# duplicate the functionality here.
745f395c03eSmrgeval 'func_dirname_and_basename ()
746f395c03eSmrg{
747f395c03eSmrg    $debug_cmd
748f395c03eSmrg
749f395c03eSmrg    '"$_b"'
750f395c03eSmrg    '"$_d"'
751f395c03eSmrg}'
752f395c03eSmrg
753f395c03eSmrg
754f395c03eSmrg# func_echo ARG...
755f395c03eSmrg# ----------------
756f395c03eSmrg# Echo program name prefixed message.
757f395c03eSmrgfunc_echo ()
758f395c03eSmrg{
759f395c03eSmrg    $debug_cmd
760f395c03eSmrg
761f395c03eSmrg    _G_message=$*
762f395c03eSmrg
763f395c03eSmrg    func_echo_IFS=$IFS
764f395c03eSmrg    IFS=$nl
765f395c03eSmrg    for _G_line in $_G_message; do
766f395c03eSmrg      IFS=$func_echo_IFS
767f395c03eSmrg      $ECHO "$progname: $_G_line"
768f395c03eSmrg    done
769f395c03eSmrg    IFS=$func_echo_IFS
770f395c03eSmrg}
771f395c03eSmrg
772f395c03eSmrg
773f395c03eSmrg# func_echo_all ARG...
774f395c03eSmrg# --------------------
775f395c03eSmrg# Invoke $ECHO with all args, space-separated.
776f395c03eSmrgfunc_echo_all ()
777f395c03eSmrg{
778f395c03eSmrg    $ECHO "$*"
779f395c03eSmrg}
780f395c03eSmrg
781f395c03eSmrg
782f395c03eSmrg# func_echo_infix_1 INFIX ARG...
783f395c03eSmrg# ------------------------------
784f395c03eSmrg# Echo program name, followed by INFIX on the first line, with any
785f395c03eSmrg# additional lines not showing INFIX.
786f395c03eSmrgfunc_echo_infix_1 ()
787f395c03eSmrg{
788f395c03eSmrg    $debug_cmd
789f395c03eSmrg
790f395c03eSmrg    $require_term_colors
791f395c03eSmrg
792f395c03eSmrg    _G_infix=$1; shift
793f395c03eSmrg    _G_indent=$_G_infix
794f395c03eSmrg    _G_prefix="$progname: $_G_infix: "
795f395c03eSmrg    _G_message=$*
796f395c03eSmrg
797f395c03eSmrg    # Strip color escape sequences before counting printable length
798f395c03eSmrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
799f395c03eSmrg    do
800f395c03eSmrg      test -n "$_G_tc" && {
801f395c03eSmrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
802f395c03eSmrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
803f395c03eSmrg      }
804f395c03eSmrg    done
805f395c03eSmrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
806f395c03eSmrg
807f395c03eSmrg    func_echo_infix_1_IFS=$IFS
808f395c03eSmrg    IFS=$nl
809f395c03eSmrg    for _G_line in $_G_message; do
810f395c03eSmrg      IFS=$func_echo_infix_1_IFS
811f395c03eSmrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
812f395c03eSmrg      _G_prefix=$_G_indent
813f395c03eSmrg    done
814f395c03eSmrg    IFS=$func_echo_infix_1_IFS
815f395c03eSmrg}
816f395c03eSmrg
817f395c03eSmrg
818f395c03eSmrg# func_error ARG...
819f395c03eSmrg# -----------------
820f395c03eSmrg# Echo program name prefixed message to standard error.
821f395c03eSmrgfunc_error ()
822f395c03eSmrg{
823f395c03eSmrg    $debug_cmd
824f395c03eSmrg
825f395c03eSmrg    $require_term_colors
826f395c03eSmrg
827f395c03eSmrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
828f395c03eSmrg}
829f395c03eSmrg
830f395c03eSmrg
831f395c03eSmrg# func_fatal_error ARG...
832f395c03eSmrg# -----------------------
833f395c03eSmrg# Echo program name prefixed message to standard error, and exit.
834f395c03eSmrgfunc_fatal_error ()
835f395c03eSmrg{
836f395c03eSmrg    $debug_cmd
837f395c03eSmrg
838f395c03eSmrg    func_error "$*"
839f395c03eSmrg    exit $EXIT_FAILURE
840f395c03eSmrg}
841f395c03eSmrg
842f395c03eSmrg
843f395c03eSmrg# func_grep EXPRESSION FILENAME
844f395c03eSmrg# -----------------------------
845e4f6584cSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
846e4f6584cSmrgfunc_grep ()
847e4f6584cSmrg{
848f395c03eSmrg    $debug_cmd
849f395c03eSmrg
850e4f6584cSmrg    $GREP "$1" "$2" >/dev/null 2>&1
851e4f6584cSmrg}
852e4f6584cSmrg
853e4f6584cSmrg
854f395c03eSmrg# func_len STRING
855f395c03eSmrg# ---------------
856f395c03eSmrg# Set func_len_result to the length of STRING. STRING may not
857f395c03eSmrg# start with a hyphen.
858f395c03eSmrg  test -z "$_G_HAVE_XSI_OPS" \
859f395c03eSmrg    && (eval 'x=a/b/c;
860f395c03eSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
861f395c03eSmrg    && _G_HAVE_XSI_OPS=yes
862f395c03eSmrg
863f395c03eSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
864f395c03eSmrg  eval 'func_len ()
865f395c03eSmrg  {
866f395c03eSmrg    $debug_cmd
867f395c03eSmrg
868f395c03eSmrg    func_len_result=${#1}
869f395c03eSmrg  }'
870f395c03eSmrgelse
871f395c03eSmrg  func_len ()
872f395c03eSmrg  {
873f395c03eSmrg    $debug_cmd
874f395c03eSmrg
875f395c03eSmrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
876f395c03eSmrg  }
877f395c03eSmrgfi
878f395c03eSmrg
879f395c03eSmrg
880f395c03eSmrg# func_mkdir_p DIRECTORY-PATH
881f395c03eSmrg# ---------------------------
882e4f6584cSmrg# Make sure the entire path to DIRECTORY-PATH is available.
883e4f6584cSmrgfunc_mkdir_p ()
884e4f6584cSmrg{
885f395c03eSmrg    $debug_cmd
886f395c03eSmrg
887f395c03eSmrg    _G_directory_path=$1
888f395c03eSmrg    _G_dir_list=
889e4f6584cSmrg
890f395c03eSmrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
891e4f6584cSmrg
892f395c03eSmrg      # Protect directory names starting with '-'
893f395c03eSmrg      case $_G_directory_path in
894f395c03eSmrg        -*) _G_directory_path=./$_G_directory_path ;;
895e4f6584cSmrg      esac
896e4f6584cSmrg
897e4f6584cSmrg      # While some portion of DIR does not yet exist...
898f395c03eSmrg      while test ! -d "$_G_directory_path"; do
899e4f6584cSmrg        # ...make a list in topmost first order.  Use a colon delimited
900e4f6584cSmrg	# list incase some portion of path contains whitespace.
901f395c03eSmrg        _G_dir_list=$_G_directory_path:$_G_dir_list
902e4f6584cSmrg
903e4f6584cSmrg        # If the last portion added has no slash in it, the list is done
904f395c03eSmrg        case $_G_directory_path in */*) ;; *) break ;; esac
905e4f6584cSmrg
906e4f6584cSmrg        # ...otherwise throw away the child directory and loop
907f395c03eSmrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
908e4f6584cSmrg      done
909f395c03eSmrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
910e4f6584cSmrg
911f395c03eSmrg      func_mkdir_p_IFS=$IFS; IFS=:
912f395c03eSmrg      for _G_dir in $_G_dir_list; do
913f395c03eSmrg	IFS=$func_mkdir_p_IFS
914f395c03eSmrg        # mkdir can fail with a 'File exist' error if two processes
915e4f6584cSmrg        # try to create one of the directories concurrently.  Don't
916e4f6584cSmrg        # stop in that case!
917f395c03eSmrg        $MKDIR "$_G_dir" 2>/dev/null || :
918e4f6584cSmrg      done
919f395c03eSmrg      IFS=$func_mkdir_p_IFS
920e4f6584cSmrg
921e4f6584cSmrg      # Bail out if we (or some other process) failed to create a directory.
922f395c03eSmrg      test -d "$_G_directory_path" || \
923f395c03eSmrg        func_fatal_error "Failed to create '$1'"
924e4f6584cSmrg    fi
925e4f6584cSmrg}
92609885543Smrg
92709885543Smrg
928f395c03eSmrg# func_mktempdir [BASENAME]
929f395c03eSmrg# -------------------------
93009885543Smrg# Make a temporary directory that won't clash with other running
93109885543Smrg# libtool processes, and avoids race conditions if possible.  If
932f395c03eSmrg# given, BASENAME is the basename for that directory.
93309885543Smrgfunc_mktempdir ()
93409885543Smrg{
935f395c03eSmrg    $debug_cmd
936f395c03eSmrg
937f395c03eSmrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
93809885543Smrg
939f395c03eSmrg    if test : = "$opt_dry_run"; then
94009885543Smrg      # Return a directory name, but don't create it in dry-run mode
941f395c03eSmrg      _G_tmpdir=$_G_template-$$
94209885543Smrg    else
94309885543Smrg
94409885543Smrg      # If mktemp works, use that first and foremost
945f395c03eSmrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
94609885543Smrg
947f395c03eSmrg      if test ! -d "$_G_tmpdir"; then
948e4f6584cSmrg        # Failing that, at least try and use $RANDOM to avoid a race
949f395c03eSmrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
95009885543Smrg
951f395c03eSmrg        func_mktempdir_umask=`umask`
952e4f6584cSmrg        umask 0077
953f395c03eSmrg        $MKDIR "$_G_tmpdir"
954f395c03eSmrg        umask $func_mktempdir_umask
95509885543Smrg      fi
95609885543Smrg
95709885543Smrg      # If we're not in dry-run mode, bomb out on failure
958f395c03eSmrg      test -d "$_G_tmpdir" || \
959f395c03eSmrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
96009885543Smrg    fi
96109885543Smrg
962f395c03eSmrg    $ECHO "$_G_tmpdir"
96309885543Smrg}
96409885543Smrg
96509885543Smrg
966f395c03eSmrg# func_normal_abspath PATH
967f395c03eSmrg# ------------------------
968f395c03eSmrg# Remove doubled-up and trailing slashes, "." path components,
969f395c03eSmrg# and cancel out any ".." path components in PATH after making
970f395c03eSmrg# it an absolute path.
971f395c03eSmrgfunc_normal_abspath ()
97209885543Smrg{
973f395c03eSmrg    $debug_cmd
974e4f6584cSmrg
975f395c03eSmrg    # These SED scripts presuppose an absolute path with a trailing slash.
976f395c03eSmrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
977f395c03eSmrg    _G_pathcdr='s|^/[^/]*||'
978f395c03eSmrg    _G_removedotparts=':dotsl
979f395c03eSmrg		s|/\./|/|g
980f395c03eSmrg		t dotsl
981f395c03eSmrg		s|/\.$|/|'
982f395c03eSmrg    _G_collapseslashes='s|/\{1,\}|/|g'
983f395c03eSmrg    _G_finalslash='s|/*$|/|'
984f395c03eSmrg
985f395c03eSmrg    # Start from root dir and reassemble the path.
986f395c03eSmrg    func_normal_abspath_result=
987f395c03eSmrg    func_normal_abspath_tpath=$1
988f395c03eSmrg    func_normal_abspath_altnamespace=
989f395c03eSmrg    case $func_normal_abspath_tpath in
990f395c03eSmrg      "")
991f395c03eSmrg        # Empty path, that just means $cwd.
992f395c03eSmrg        func_stripname '' '/' "`pwd`"
993f395c03eSmrg        func_normal_abspath_result=$func_stripname_result
994f395c03eSmrg        return
995f395c03eSmrg        ;;
996f395c03eSmrg      # The next three entries are used to spot a run of precisely
997f395c03eSmrg      # two leading slashes without using negated character classes;
998f395c03eSmrg      # we take advantage of case's first-match behaviour.
999f395c03eSmrg      ///*)
1000f395c03eSmrg        # Unusual form of absolute path, do nothing.
1001f395c03eSmrg        ;;
1002f395c03eSmrg      //*)
1003f395c03eSmrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
1004f395c03eSmrg        # and for example Cygwin uses it to access remote file shares
1005f395c03eSmrg        # over CIFS/SMB, so we conserve a leading double slash if found.
1006f395c03eSmrg        func_normal_abspath_altnamespace=/
1007f395c03eSmrg        ;;
1008f395c03eSmrg      /*)
1009f395c03eSmrg        # Absolute path, do nothing.
1010e4f6584cSmrg        ;;
1011e4f6584cSmrg      *)
1012f395c03eSmrg        # Relative path, prepend $cwd.
1013f395c03eSmrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
1014f395c03eSmrg        ;;
101509885543Smrg    esac
1016f395c03eSmrg
1017f395c03eSmrg    # Cancel out all the simple stuff to save iterations.  We also want
1018f395c03eSmrg    # the path to end with a slash for ease of parsing, so make sure
1019f395c03eSmrg    # there is one (and only one) here.
1020f395c03eSmrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1021f395c03eSmrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
1022f395c03eSmrg    while :; do
1023f395c03eSmrg      # Processed it all yet?
1024f395c03eSmrg      if test / = "$func_normal_abspath_tpath"; then
1025f395c03eSmrg        # If we ascended to the root using ".." the result may be empty now.
1026f395c03eSmrg        if test -z "$func_normal_abspath_result"; then
1027f395c03eSmrg          func_normal_abspath_result=/
1028f395c03eSmrg        fi
1029f395c03eSmrg        break
1030f395c03eSmrg      fi
1031f395c03eSmrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
1032f395c03eSmrg          -e "$_G_pathcar"`
1033f395c03eSmrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
1034f395c03eSmrg          -e "$_G_pathcdr"`
1035f395c03eSmrg      # Figure out what to do with it
1036f395c03eSmrg      case $func_normal_abspath_tcomponent in
1037f395c03eSmrg        "")
1038f395c03eSmrg          # Trailing empty path component, ignore it.
1039f395c03eSmrg          ;;
1040f395c03eSmrg        ..)
1041f395c03eSmrg          # Parent dir; strip last assembled component from result.
1042f395c03eSmrg          func_dirname "$func_normal_abspath_result"
1043f395c03eSmrg          func_normal_abspath_result=$func_dirname_result
1044f395c03eSmrg          ;;
1045f395c03eSmrg        *)
1046f395c03eSmrg          # Actual path component, append it.
1047f395c03eSmrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1048f395c03eSmrg          ;;
1049f395c03eSmrg      esac
1050f395c03eSmrg    done
1051f395c03eSmrg    # Restore leading double-slash if one was found on entry.
1052f395c03eSmrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1053f395c03eSmrg}
1054f395c03eSmrg
1055f395c03eSmrg
1056f395c03eSmrg# func_notquiet ARG...
1057f395c03eSmrg# --------------------
1058f395c03eSmrg# Echo program name prefixed message only when not in quiet mode.
1059f395c03eSmrgfunc_notquiet ()
1060f395c03eSmrg{
1061f395c03eSmrg    $debug_cmd
1062f395c03eSmrg
1063f395c03eSmrg    $opt_quiet || func_echo ${1+"$@"}
1064f395c03eSmrg
1065f395c03eSmrg    # A bug in bash halts the script if the last line of a function
1066f395c03eSmrg    # fails when set -e is in force, so we need another command to
1067f395c03eSmrg    # work around that:
1068f395c03eSmrg    :
1069f395c03eSmrg}
1070f395c03eSmrg
1071f395c03eSmrg
1072f395c03eSmrg# func_relative_path SRCDIR DSTDIR
1073f395c03eSmrg# --------------------------------
1074f395c03eSmrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1075f395c03eSmrgfunc_relative_path ()
1076f395c03eSmrg{
1077f395c03eSmrg    $debug_cmd
1078f395c03eSmrg
1079f395c03eSmrg    func_relative_path_result=
1080f395c03eSmrg    func_normal_abspath "$1"
1081f395c03eSmrg    func_relative_path_tlibdir=$func_normal_abspath_result
1082f395c03eSmrg    func_normal_abspath "$2"
1083f395c03eSmrg    func_relative_path_tbindir=$func_normal_abspath_result
1084f395c03eSmrg
1085f395c03eSmrg    # Ascend the tree starting from libdir
1086f395c03eSmrg    while :; do
1087f395c03eSmrg      # check if we have found a prefix of bindir
1088f395c03eSmrg      case $func_relative_path_tbindir in
1089f395c03eSmrg        $func_relative_path_tlibdir)
1090f395c03eSmrg          # found an exact match
1091f395c03eSmrg          func_relative_path_tcancelled=
1092f395c03eSmrg          break
1093f395c03eSmrg          ;;
1094f395c03eSmrg        $func_relative_path_tlibdir*)
1095f395c03eSmrg          # found a matching prefix
1096f395c03eSmrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1097f395c03eSmrg          func_relative_path_tcancelled=$func_stripname_result
1098f395c03eSmrg          if test -z "$func_relative_path_result"; then
1099f395c03eSmrg            func_relative_path_result=.
1100f395c03eSmrg          fi
1101f395c03eSmrg          break
1102f395c03eSmrg          ;;
1103f395c03eSmrg        *)
1104f395c03eSmrg          func_dirname $func_relative_path_tlibdir
1105f395c03eSmrg          func_relative_path_tlibdir=$func_dirname_result
1106f395c03eSmrg          if test -z "$func_relative_path_tlibdir"; then
1107f395c03eSmrg            # Have to descend all the way to the root!
1108f395c03eSmrg            func_relative_path_result=../$func_relative_path_result
1109f395c03eSmrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1110f395c03eSmrg            break
1111f395c03eSmrg          fi
1112f395c03eSmrg          func_relative_path_result=../$func_relative_path_result
1113f395c03eSmrg          ;;
1114f395c03eSmrg      esac
1115f395c03eSmrg    done
1116f395c03eSmrg
1117f395c03eSmrg    # Now calculate path; take care to avoid doubling-up slashes.
1118f395c03eSmrg    func_stripname '' '/' "$func_relative_path_result"
1119f395c03eSmrg    func_relative_path_result=$func_stripname_result
1120f395c03eSmrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1121f395c03eSmrg    if test -n "$func_stripname_result"; then
1122f395c03eSmrg      func_append func_relative_path_result "/$func_stripname_result"
1123f395c03eSmrg    fi
1124f395c03eSmrg
1125f395c03eSmrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1126f395c03eSmrg    if test -n "$func_relative_path_result"; then
1127f395c03eSmrg      func_stripname './' '' "$func_relative_path_result"
1128f395c03eSmrg      func_relative_path_result=$func_stripname_result
1129f395c03eSmrg    fi
1130f395c03eSmrg
1131f395c03eSmrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1132f395c03eSmrg
1133f395c03eSmrg    :
113409885543Smrg}
113509885543Smrg
113609885543Smrg
1137beef1b22Smrg# func_quote_portable EVAL ARG
1138beef1b22Smrg# ----------------------------
1139beef1b22Smrg# Internal function to portably implement func_quote_arg.  Note that we still
1140beef1b22Smrg# keep attention to performance here so we as much as possible try to avoid
1141beef1b22Smrg# calling sed binary (so far O(N) complexity as long as func_append is O(1)).
1142beef1b22Smrgfunc_quote_portable ()
1143f395c03eSmrg{
1144f395c03eSmrg    $debug_cmd
1145f395c03eSmrg
1146beef1b22Smrg    $require_check_ifs_backslash
1147beef1b22Smrg
1148beef1b22Smrg    func_quote_portable_result=$2
1149beef1b22Smrg
1150beef1b22Smrg    # one-time-loop (easy break)
1151beef1b22Smrg    while true
1152beef1b22Smrg    do
1153beef1b22Smrg      if $1; then
1154beef1b22Smrg        func_quote_portable_result=`$ECHO "$2" | $SED \
1155beef1b22Smrg          -e "$sed_double_quote_subst" -e "$sed_double_backslash"`
1156beef1b22Smrg        break
1157f395c03eSmrg      fi
1158f395c03eSmrg
1159beef1b22Smrg      # Quote for eval.
1160beef1b22Smrg      case $func_quote_portable_result in
1161beef1b22Smrg        *[\\\`\"\$]*)
1162beef1b22Smrg          # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string
1163beef1b22Smrg          # contains the shell wildcard characters.
1164beef1b22Smrg          case $check_ifs_backshlash_broken$func_quote_portable_result in
1165beef1b22Smrg            :*|*[\[\*\?]*)
1166beef1b22Smrg              func_quote_portable_result=`$ECHO "$func_quote_portable_result" \
1167beef1b22Smrg                  | $SED "$sed_quote_subst"`
1168beef1b22Smrg              break
1169beef1b22Smrg              ;;
1170beef1b22Smrg          esac
1171beef1b22Smrg
1172beef1b22Smrg          func_quote_portable_old_IFS=$IFS
1173beef1b22Smrg          for _G_char in '\' '`' '"' '$'
1174beef1b22Smrg          do
1175beef1b22Smrg            # STATE($1) PREV($2) SEPARATOR($3)
1176beef1b22Smrg            set start "" ""
1177beef1b22Smrg            func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy
1178beef1b22Smrg            IFS=$_G_char
1179beef1b22Smrg            for _G_part in $func_quote_portable_result
1180beef1b22Smrg            do
1181beef1b22Smrg              case $1 in
1182beef1b22Smrg              quote)
1183beef1b22Smrg                func_append func_quote_portable_result "$3$2"
1184beef1b22Smrg                set quote "$_G_part" "\\$_G_char"
1185beef1b22Smrg                ;;
1186beef1b22Smrg              start)
1187beef1b22Smrg                set first "" ""
1188beef1b22Smrg                func_quote_portable_result=
1189beef1b22Smrg                ;;
1190beef1b22Smrg              first)
1191beef1b22Smrg                set quote "$_G_part" ""
1192beef1b22Smrg                ;;
1193beef1b22Smrg              esac
1194beef1b22Smrg            done
1195beef1b22Smrg          done
1196beef1b22Smrg          IFS=$func_quote_portable_old_IFS
1197f395c03eSmrg          ;;
1198beef1b22Smrg        *) ;;
1199f395c03eSmrg      esac
1200beef1b22Smrg      break
1201f395c03eSmrg    done
1202beef1b22Smrg
1203beef1b22Smrg    func_quote_portable_unquoted_result=$func_quote_portable_result
1204beef1b22Smrg    case $func_quote_portable_result in
1205beef1b22Smrg      # double-quote args containing shell metacharacters to delay
1206beef1b22Smrg      # word splitting, command substitution and variable expansion
1207beef1b22Smrg      # for a subsequent eval.
1208beef1b22Smrg      # many bourne shells cannot handle close brackets correctly
1209beef1b22Smrg      # in scan sets, so we specify it separately.
1210beef1b22Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1211beef1b22Smrg        func_quote_portable_result=\"$func_quote_portable_result\"
1212beef1b22Smrg        ;;
1213beef1b22Smrg    esac
1214f395c03eSmrg}
1215f395c03eSmrg
1216f395c03eSmrg
1217beef1b22Smrg# func_quotefast_eval ARG
1218beef1b22Smrg# -----------------------
1219beef1b22Smrg# Quote one ARG (internal).  This is equivalent to 'func_quote_arg eval ARG',
1220beef1b22Smrg# but optimized for speed.  Result is stored in $func_quotefast_eval.
1221beef1b22Smrgif test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then
1222beef1b22Smrg  printf -v _GL_test_printf_tilde %q '~'
1223beef1b22Smrg  if test '\~' = "$_GL_test_printf_tilde"; then
1224beef1b22Smrg    func_quotefast_eval ()
1225beef1b22Smrg    {
1226beef1b22Smrg      printf -v func_quotefast_eval_result %q "$1"
1227beef1b22Smrg    }
1228beef1b22Smrg  else
1229beef1b22Smrg    # Broken older Bash implementations.  Make those faster too if possible.
1230beef1b22Smrg    func_quotefast_eval ()
1231beef1b22Smrg    {
1232beef1b22Smrg      case $1 in
1233beef1b22Smrg        '~'*)
1234beef1b22Smrg          func_quote_portable false "$1"
1235beef1b22Smrg          func_quotefast_eval_result=$func_quote_portable_result
1236beef1b22Smrg          ;;
1237beef1b22Smrg        *)
1238beef1b22Smrg          printf -v func_quotefast_eval_result %q "$1"
1239beef1b22Smrg          ;;
1240beef1b22Smrg      esac
1241beef1b22Smrg    }
1242beef1b22Smrg  fi
1243beef1b22Smrgelse
1244beef1b22Smrg  func_quotefast_eval ()
1245beef1b22Smrg  {
1246beef1b22Smrg    func_quote_portable false "$1"
1247beef1b22Smrg    func_quotefast_eval_result=$func_quote_portable_result
1248beef1b22Smrg  }
1249beef1b22Smrgfi
1250f395c03eSmrg
1251beef1b22Smrg
1252beef1b22Smrg# func_quote_arg MODEs ARG
1253beef1b22Smrg# ------------------------
1254beef1b22Smrg# Quote one ARG to be evaled later.  MODEs argument may contain zero or more
1255beef1b22Smrg# specifiers listed below separated by ',' character.  This function returns two
1256beef1b22Smrg# values:
1257beef1b22Smrg#   i) func_quote_arg_result
1258beef1b22Smrg#      double-quoted (when needed), suitable for a subsequent eval
1259beef1b22Smrg#  ii) func_quote_arg_unquoted_result
1260beef1b22Smrg#      has all characters that are still active within double
1261beef1b22Smrg#      quotes backslashified.  Available only if 'unquoted' is specified.
1262beef1b22Smrg#
1263beef1b22Smrg# Available modes:
1264beef1b22Smrg# ----------------
1265beef1b22Smrg# 'eval' (default)
1266beef1b22Smrg#       - escape shell special characters
1267beef1b22Smrg# 'expand'
1268beef1b22Smrg#       - the same as 'eval';  but do not quote variable references
1269beef1b22Smrg# 'pretty'
1270beef1b22Smrg#       - request aesthetic output, i.e. '"a b"' instead of 'a\ b'.  This might
1271beef1b22Smrg#         be used later in func_quote to get output like: 'echo "a b"' instead
1272beef1b22Smrg#         of 'echo a\ b'.  This is slower than default on some shells.
1273beef1b22Smrg# 'unquoted'
1274beef1b22Smrg#       - produce also $func_quote_arg_unquoted_result which does not contain
1275beef1b22Smrg#         wrapping double-quotes.
1276beef1b22Smrg#
1277beef1b22Smrg# Examples for 'func_quote_arg pretty,unquoted string':
1278beef1b22Smrg#
1279beef1b22Smrg#   string      | *_result              | *_unquoted_result
1280beef1b22Smrg#   ------------+-----------------------+-------------------
1281beef1b22Smrg#   "           | \"                    | \"
1282beef1b22Smrg#   a b         | "a b"                 | a b
1283beef1b22Smrg#   "a b"       | "\"a b\""             | \"a b\"
1284beef1b22Smrg#   *           | "*"                   | *
1285beef1b22Smrg#   z="${x-$y}" | "z=\"\${x-\$y}\""     | z=\"\${x-\$y}\"
1286beef1b22Smrg#
1287beef1b22Smrg# Examples for 'func_quote_arg pretty,unquoted,expand string':
1288beef1b22Smrg#
1289beef1b22Smrg#   string        |   *_result          |  *_unquoted_result
1290beef1b22Smrg#   --------------+---------------------+--------------------
1291beef1b22Smrg#   z="${x-$y}"   | "z=\"${x-$y}\""     | z=\"${x-$y}\"
1292beef1b22Smrgfunc_quote_arg ()
1293beef1b22Smrg{
1294beef1b22Smrg    _G_quote_expand=false
1295beef1b22Smrg    case ,$1, in
1296beef1b22Smrg      *,expand,*)
1297beef1b22Smrg        _G_quote_expand=:
1298beef1b22Smrg        ;;
1299e4f6584cSmrg    esac
1300e4f6584cSmrg
1301beef1b22Smrg    case ,$1, in
1302beef1b22Smrg      *,pretty,*|*,expand,*|*,unquoted,*)
1303beef1b22Smrg        func_quote_portable $_G_quote_expand "$2"
1304beef1b22Smrg        func_quote_arg_result=$func_quote_portable_result
1305beef1b22Smrg        func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result
1306beef1b22Smrg        ;;
1307beef1b22Smrg      *)
1308beef1b22Smrg        # Faster quote-for-eval for some shells.
1309beef1b22Smrg        func_quotefast_eval "$2"
1310beef1b22Smrg        func_quote_arg_result=$func_quotefast_eval_result
1311e4f6584cSmrg        ;;
1312e4f6584cSmrg    esac
1313beef1b22Smrg}
1314beef1b22Smrg
1315e4f6584cSmrg
1316beef1b22Smrg# func_quote MODEs ARGs...
1317beef1b22Smrg# ------------------------
1318beef1b22Smrg# Quote all ARGs to be evaled later and join them into single command.  See
1319beef1b22Smrg# func_quote_arg's description for more info.
1320beef1b22Smrgfunc_quote ()
1321beef1b22Smrg{
1322beef1b22Smrg    $debug_cmd
1323beef1b22Smrg    _G_func_quote_mode=$1 ; shift
1324beef1b22Smrg    func_quote_result=
1325beef1b22Smrg    while test 0 -lt $#; do
1326beef1b22Smrg      func_quote_arg "$_G_func_quote_mode" "$1"
1327beef1b22Smrg      if test -n "$func_quote_result"; then
1328beef1b22Smrg        func_append func_quote_result " $func_quote_arg_result"
1329beef1b22Smrg      else
1330beef1b22Smrg        func_append func_quote_result "$func_quote_arg_result"
1331beef1b22Smrg      fi
1332beef1b22Smrg      shift
1333beef1b22Smrg    done
1334f395c03eSmrg}
1335f395c03eSmrg
1336f395c03eSmrg
1337f395c03eSmrg# func_stripname PREFIX SUFFIX NAME
1338f395c03eSmrg# ---------------------------------
1339f395c03eSmrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1340f395c03eSmrg# PREFIX and SUFFIX must not contain globbing or regex special
1341f395c03eSmrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1342f395c03eSmrg# dot (in which case that matches only a dot).
1343f395c03eSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
1344f395c03eSmrg  eval 'func_stripname ()
1345f395c03eSmrg  {
1346f395c03eSmrg    $debug_cmd
1347f395c03eSmrg
1348f395c03eSmrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1349f395c03eSmrg    # positional parameters, so assign one to ordinary variable first.
1350f395c03eSmrg    func_stripname_result=$3
1351f395c03eSmrg    func_stripname_result=${func_stripname_result#"$1"}
1352f395c03eSmrg    func_stripname_result=${func_stripname_result%"$2"}
1353f395c03eSmrg  }'
1354f395c03eSmrgelse
1355f395c03eSmrg  func_stripname ()
1356f395c03eSmrg  {
1357f395c03eSmrg    $debug_cmd
1358f395c03eSmrg
1359f395c03eSmrg    case $2 in
1360f395c03eSmrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1361f395c03eSmrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1362f395c03eSmrg    esac
1363f395c03eSmrg  }
1364f395c03eSmrgfi
1365f395c03eSmrg
1366f395c03eSmrg
1367f395c03eSmrg# func_show_eval CMD [FAIL_EXP]
1368f395c03eSmrg# -----------------------------
1369f395c03eSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1370f395c03eSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1371f395c03eSmrg# is given, then evaluate it.
1372f395c03eSmrgfunc_show_eval ()
1373f395c03eSmrg{
1374f395c03eSmrg    $debug_cmd
1375f395c03eSmrg
1376f395c03eSmrg    _G_cmd=$1
1377f395c03eSmrg    _G_fail_exp=${2-':'}
1378f395c03eSmrg
1379beef1b22Smrg    func_quote_arg pretty,expand "$_G_cmd"
1380beef1b22Smrg    eval "func_notquiet $func_quote_arg_result"
1381f395c03eSmrg
1382f395c03eSmrg    $opt_dry_run || {
1383f395c03eSmrg      eval "$_G_cmd"
1384f395c03eSmrg      _G_status=$?
1385f395c03eSmrg      if test 0 -ne "$_G_status"; then
1386f395c03eSmrg	eval "(exit $_G_status); $_G_fail_exp"
1387f395c03eSmrg      fi
1388f395c03eSmrg    }
1389f395c03eSmrg}
1390f395c03eSmrg
1391f395c03eSmrg
1392f395c03eSmrg# func_show_eval_locale CMD [FAIL_EXP]
1393f395c03eSmrg# ------------------------------------
1394f395c03eSmrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1395f395c03eSmrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1396f395c03eSmrg# is given, then evaluate it.  Use the saved locale for evaluation.
1397f395c03eSmrgfunc_show_eval_locale ()
1398f395c03eSmrg{
1399f395c03eSmrg    $debug_cmd
1400f395c03eSmrg
1401f395c03eSmrg    _G_cmd=$1
1402f395c03eSmrg    _G_fail_exp=${2-':'}
1403f395c03eSmrg
1404f395c03eSmrg    $opt_quiet || {
1405beef1b22Smrg      func_quote_arg expand,pretty "$_G_cmd"
1406beef1b22Smrg      eval "func_echo $func_quote_arg_result"
1407f395c03eSmrg    }
1408f395c03eSmrg
1409f395c03eSmrg    $opt_dry_run || {
1410f395c03eSmrg      eval "$_G_user_locale
1411f395c03eSmrg	    $_G_cmd"
1412f395c03eSmrg      _G_status=$?
1413f395c03eSmrg      eval "$_G_safe_locale"
1414f395c03eSmrg      if test 0 -ne "$_G_status"; then
1415f395c03eSmrg	eval "(exit $_G_status); $_G_fail_exp"
1416f395c03eSmrg      fi
1417f395c03eSmrg    }
1418f395c03eSmrg}
1419f395c03eSmrg
1420f395c03eSmrg
1421f395c03eSmrg# func_tr_sh
1422f395c03eSmrg# ----------
1423f395c03eSmrg# Turn $1 into a string suitable for a shell variable name.
1424f395c03eSmrg# Result is stored in $func_tr_sh_result.  All characters
1425f395c03eSmrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1426f395c03eSmrg# if $1 begins with a digit, a '_' is prepended as well.
1427f395c03eSmrgfunc_tr_sh ()
1428f395c03eSmrg{
1429f395c03eSmrg    $debug_cmd
1430f395c03eSmrg
1431f395c03eSmrg    case $1 in
1432f395c03eSmrg    [0-9]* | *[!a-zA-Z0-9_]*)
1433f395c03eSmrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1434f395c03eSmrg      ;;
1435f395c03eSmrg    * )
1436f395c03eSmrg      func_tr_sh_result=$1
1437f395c03eSmrg      ;;
1438f395c03eSmrg    esac
1439f395c03eSmrg}
1440f395c03eSmrg
1441f395c03eSmrg
1442f395c03eSmrg# func_verbose ARG...
1443f395c03eSmrg# -------------------
1444f395c03eSmrg# Echo program name prefixed message in verbose mode only.
1445f395c03eSmrgfunc_verbose ()
1446f395c03eSmrg{
1447f395c03eSmrg    $debug_cmd
1448f395c03eSmrg
1449f395c03eSmrg    $opt_verbose && func_echo "$*"
1450f395c03eSmrg
1451f395c03eSmrg    :
1452f395c03eSmrg}
1453f395c03eSmrg
1454f395c03eSmrg
1455f395c03eSmrg# func_warn_and_continue ARG...
1456f395c03eSmrg# -----------------------------
1457f395c03eSmrg# Echo program name prefixed warning message to standard error.
1458f395c03eSmrgfunc_warn_and_continue ()
1459f395c03eSmrg{
1460f395c03eSmrg    $debug_cmd
1461f395c03eSmrg
1462f395c03eSmrg    $require_term_colors
1463f395c03eSmrg
1464f395c03eSmrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1465f395c03eSmrg}
1466f395c03eSmrg
1467f395c03eSmrg
1468f395c03eSmrg# func_warning CATEGORY ARG...
1469f395c03eSmrg# ----------------------------
1470f395c03eSmrg# Echo program name prefixed warning message to standard error. Warning
1471f395c03eSmrg# messages can be filtered according to CATEGORY, where this function
1472f395c03eSmrg# elides messages where CATEGORY is not listed in the global variable
1473f395c03eSmrg# 'opt_warning_types'.
1474f395c03eSmrgfunc_warning ()
1475f395c03eSmrg{
1476f395c03eSmrg    $debug_cmd
1477f395c03eSmrg
1478f395c03eSmrg    # CATEGORY must be in the warning_categories list!
1479f395c03eSmrg    case " $warning_categories " in
1480f395c03eSmrg      *" $1 "*) ;;
1481f395c03eSmrg      *) func_internal_error "invalid warning category '$1'" ;;
1482f395c03eSmrg    esac
1483f395c03eSmrg
1484f395c03eSmrg    _G_category=$1
1485f395c03eSmrg    shift
1486f395c03eSmrg
1487f395c03eSmrg    case " $opt_warning_types " in
1488f395c03eSmrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1489f395c03eSmrg    esac
149009885543Smrg}
149109885543Smrg
149209885543Smrg
1493f395c03eSmrg# func_sort_ver VER1 VER2
1494f395c03eSmrg# -----------------------
1495f395c03eSmrg# 'sort -V' is not generally available.
1496f395c03eSmrg# Note this deviates from the version comparison in automake
1497f395c03eSmrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1498f395c03eSmrg# but this should suffice as we won't be specifying old
1499f395c03eSmrg# version formats or redundant trailing .0 in bootstrap.conf.
1500f395c03eSmrg# If we did want full compatibility then we should probably
1501f395c03eSmrg# use m4_version_compare from autoconf.
1502f395c03eSmrgfunc_sort_ver ()
1503f395c03eSmrg{
1504f395c03eSmrg    $debug_cmd
1505f395c03eSmrg
1506f395c03eSmrg    printf '%s\n%s\n' "$1" "$2" \
1507f395c03eSmrg      | 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
1508f395c03eSmrg}
1509f395c03eSmrg
1510f395c03eSmrg# func_lt_ver PREV CURR
1511f395c03eSmrg# ---------------------
1512f395c03eSmrg# Return true if PREV and CURR are in the correct order according to
1513f395c03eSmrg# func_sort_ver, otherwise false.  Use it like this:
1514f395c03eSmrg#
1515f395c03eSmrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1516f395c03eSmrgfunc_lt_ver ()
1517f395c03eSmrg{
1518f395c03eSmrg    $debug_cmd
1519f395c03eSmrg
1520f395c03eSmrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1521f395c03eSmrg}
1522f395c03eSmrg
1523f395c03eSmrg
1524f395c03eSmrg# Local variables:
1525f395c03eSmrg# mode: shell-script
1526f395c03eSmrg# sh-indentation: 2
1527f395c03eSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
1528f395c03eSmrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1529f395c03eSmrg# time-stamp-time-zone: "UTC"
1530f395c03eSmrg# End:
1531f395c03eSmrg#! /bin/sh
1532f395c03eSmrg
1533f395c03eSmrg# A portable, pluggable option parser for Bourne shell.
1534f395c03eSmrg# Written by Gary V. Vaughan, 2010
1535f395c03eSmrg
1536beef1b22Smrg# This is free software.  There is NO warranty; not even for
1537beef1b22Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1538beef1b22Smrg#
1539beef1b22Smrg# Copyright (C) 2010-2019, 2021 Bootstrap Authors
1540beef1b22Smrg#
1541beef1b22Smrg# This file is dual licensed under the terms of the MIT license
1542beef1b22Smrg# <https://opensource.org/license/MIT>, and GPL version 2 or later
1543beef1b22Smrg# <http://www.gnu.org/licenses/gpl-2.0.html>.  You must apply one of
1544beef1b22Smrg# these licenses when using or redistributing this software or any of
1545beef1b22Smrg# the files within it.  See the URLs above, or the file `LICENSE`
1546beef1b22Smrg# included in the Bootstrap distribution for the full license texts.
1547f395c03eSmrg
1548beef1b22Smrg# Please report bugs or propose patches to:
1549beef1b22Smrg# <https://github.com/gnulib-modules/bootstrap/issues>
1550f395c03eSmrg
1551beef1b22Smrg# Set a version string for this script.
1552beef1b22Smrgscriptversion=2019-02-19.15; # UTC
1553f395c03eSmrg
1554f395c03eSmrg
1555f395c03eSmrg## ------ ##
1556f395c03eSmrg## Usage. ##
1557f395c03eSmrg## ------ ##
1558f395c03eSmrg
1559f395c03eSmrg# This file is a library for parsing options in your shell scripts along
1560f395c03eSmrg# with assorted other useful supporting features that you can make use
1561f395c03eSmrg# of too.
1562f395c03eSmrg#
1563f395c03eSmrg# For the simplest scripts you might need only:
1564f395c03eSmrg#
1565f395c03eSmrg#   #!/bin/sh
1566f395c03eSmrg#   . relative/path/to/funclib.sh
1567f395c03eSmrg#   . relative/path/to/options-parser
1568f395c03eSmrg#   scriptversion=1.0
1569f395c03eSmrg#   func_options ${1+"$@"}
1570f395c03eSmrg#   eval set dummy "$func_options_result"; shift
1571f395c03eSmrg#   ...rest of your script...
1572f395c03eSmrg#
1573f395c03eSmrg# In order for the '--version' option to work, you will need to have a
1574f395c03eSmrg# suitably formatted comment like the one at the top of this file
1575beef1b22Smrg# starting with '# Written by ' and ending with '# Copyright'.
1576f395c03eSmrg#
1577f395c03eSmrg# For '-h' and '--help' to work, you will also need a one line
1578f395c03eSmrg# description of your script's purpose in a comment directly above the
1579f395c03eSmrg# '# Written by ' line, like the one at the top of this file.
1580f395c03eSmrg#
1581f395c03eSmrg# The default options also support '--debug', which will turn on shell
1582f395c03eSmrg# execution tracing (see the comment above debug_cmd below for another
1583f395c03eSmrg# use), and '--verbose' and the func_verbose function to allow your script
1584f395c03eSmrg# to display verbose messages only when your user has specified
1585f395c03eSmrg# '--verbose'.
1586f395c03eSmrg#
1587beef1b22Smrg# After sourcing this file, you can plug in processing for additional
1588f395c03eSmrg# options by amending the variables from the 'Configuration' section
1589f395c03eSmrg# below, and following the instructions in the 'Option parsing'
1590f395c03eSmrg# section further down.
1591f395c03eSmrg
1592f395c03eSmrg## -------------- ##
1593f395c03eSmrg## Configuration. ##
1594f395c03eSmrg## -------------- ##
1595f395c03eSmrg
1596f395c03eSmrg# You should override these variables in your script after sourcing this
1597f395c03eSmrg# file so that they reflect the customisations you have added to the
1598f395c03eSmrg# option parser.
1599f395c03eSmrg
1600f395c03eSmrg# The usage line for option parsing errors and the start of '-h' and
1601f395c03eSmrg# '--help' output messages. You can embed shell variables for delayed
1602f395c03eSmrg# expansion at the time the message is displayed, but you will need to
1603f395c03eSmrg# quote other shell meta-characters carefully to prevent them being
1604f395c03eSmrg# expanded when the contents are evaled.
1605f395c03eSmrgusage='$progpath [OPTION]...'
1606f395c03eSmrg
1607f395c03eSmrg# Short help message in response to '-h' and '--help'.  Add to this or
1608f395c03eSmrg# override it after sourcing this library to reflect the full set of
1609f395c03eSmrg# options your script accepts.
1610f395c03eSmrgusage_message="\
1611f395c03eSmrg       --debug        enable verbose shell tracing
1612f395c03eSmrg   -W, --warnings=CATEGORY
1613f395c03eSmrg                      report the warnings falling in CATEGORY [all]
1614f395c03eSmrg   -v, --verbose      verbosely report processing
1615f395c03eSmrg       --version      print version information and exit
1616f395c03eSmrg   -h, --help         print short or long help message and exit
1617f395c03eSmrg"
1618f395c03eSmrg
1619f395c03eSmrg# Additional text appended to 'usage_message' in response to '--help'.
1620f395c03eSmrglong_help_message="
1621f395c03eSmrgWarning categories include:
1622f395c03eSmrg       'all'          show all warnings
1623f395c03eSmrg       'none'         turn off all the warnings
1624f395c03eSmrg       'error'        warnings are treated as fatal errors"
1625f395c03eSmrg
1626f395c03eSmrg# Help message printed before fatal option parsing errors.
1627f395c03eSmrgfatal_help="Try '\$progname --help' for more information."
1628f395c03eSmrg
1629f395c03eSmrg
1630f395c03eSmrg
1631f395c03eSmrg## ------------------------- ##
1632f395c03eSmrg## Hook function management. ##
1633f395c03eSmrg## ------------------------- ##
1634f395c03eSmrg
1635f395c03eSmrg# This section contains functions for adding, removing, and running hooks
1636beef1b22Smrg# in the main code.  A hook is just a list of function names that can be
1637beef1b22Smrg# run in order later on.
1638f395c03eSmrg
1639f395c03eSmrg# func_hookable FUNC_NAME
1640f395c03eSmrg# -----------------------
1641f395c03eSmrg# Declare that FUNC_NAME will run hooks added with
1642f395c03eSmrg# 'func_add_hook FUNC_NAME ...'.
1643f395c03eSmrgfunc_hookable ()
1644f395c03eSmrg{
1645f395c03eSmrg    $debug_cmd
1646f395c03eSmrg
1647f395c03eSmrg    func_append hookable_fns " $1"
1648f395c03eSmrg}
1649f395c03eSmrg
1650f395c03eSmrg
1651f395c03eSmrg# func_add_hook FUNC_NAME HOOK_FUNC
1652f395c03eSmrg# ---------------------------------
1653f395c03eSmrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1654f395c03eSmrg# first have been declared "hookable" by a call to 'func_hookable'.
1655f395c03eSmrgfunc_add_hook ()
1656f395c03eSmrg{
1657f395c03eSmrg    $debug_cmd
1658f395c03eSmrg
1659f395c03eSmrg    case " $hookable_fns " in
1660f395c03eSmrg      *" $1 "*) ;;
1661f395c03eSmrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1662f395c03eSmrg    esac
1663f395c03eSmrg
1664f395c03eSmrg    eval func_append ${1}_hooks '" $2"'
1665f395c03eSmrg}
1666f395c03eSmrg
1667f395c03eSmrg
1668f395c03eSmrg# func_remove_hook FUNC_NAME HOOK_FUNC
1669f395c03eSmrg# ------------------------------------
1670beef1b22Smrg# Remove HOOK_FUNC from the list of hook functions to be called by
1671beef1b22Smrg# FUNC_NAME.
1672f395c03eSmrgfunc_remove_hook ()
1673f395c03eSmrg{
1674f395c03eSmrg    $debug_cmd
1675f395c03eSmrg
1676f395c03eSmrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1677f395c03eSmrg}
1678f395c03eSmrg
1679f395c03eSmrg
1680beef1b22Smrg# func_propagate_result FUNC_NAME_A FUNC_NAME_B
1681beef1b22Smrg# ---------------------------------------------
1682beef1b22Smrg# If the *_result variable of FUNC_NAME_A _is set_, assign its value to
1683beef1b22Smrg# *_result variable of FUNC_NAME_B.
1684beef1b22Smrgfunc_propagate_result ()
1685beef1b22Smrg{
1686beef1b22Smrg    $debug_cmd
1687beef1b22Smrg
1688beef1b22Smrg    func_propagate_result_result=:
1689beef1b22Smrg    if eval "test \"\${${1}_result+set}\" = set"
1690beef1b22Smrg    then
1691beef1b22Smrg      eval "${2}_result=\$${1}_result"
1692beef1b22Smrg    else
1693beef1b22Smrg      func_propagate_result_result=false
1694beef1b22Smrg    fi
1695beef1b22Smrg}
1696beef1b22Smrg
1697beef1b22Smrg
1698f395c03eSmrg# func_run_hooks FUNC_NAME [ARG]...
1699f395c03eSmrg# ---------------------------------
1700f395c03eSmrg# Run all hook functions registered to FUNC_NAME.
1701beef1b22Smrg# It's assumed that the list of hook functions contains nothing more
1702f395c03eSmrg# than a whitespace-delimited list of legal shell function names, and
1703f395c03eSmrg# no effort is wasted trying to catch shell meta-characters or preserve
1704f395c03eSmrg# whitespace.
1705f395c03eSmrgfunc_run_hooks ()
1706f395c03eSmrg{
1707f395c03eSmrg    $debug_cmd
1708f395c03eSmrg
1709f395c03eSmrg    case " $hookable_fns " in
1710f395c03eSmrg      *" $1 "*) ;;
1711beef1b22Smrg      *) func_fatal_error "'$1' does not support hook functions." ;;
1712f395c03eSmrg    esac
1713f395c03eSmrg
1714f395c03eSmrg    eval _G_hook_fns=\$$1_hooks; shift
1715f395c03eSmrg
1716f395c03eSmrg    for _G_hook in $_G_hook_fns; do
1717beef1b22Smrg      func_unset "${_G_hook}_result"
1718beef1b22Smrg      eval $_G_hook '${1+"$@"}'
1719beef1b22Smrg      func_propagate_result $_G_hook func_run_hooks
1720beef1b22Smrg      if $func_propagate_result_result; then
1721beef1b22Smrg        eval set dummy "$func_run_hooks_result"; shift
1722beef1b22Smrg      fi
1723f395c03eSmrg    done
1724f395c03eSmrg}
1725f395c03eSmrg
1726f395c03eSmrg
1727f395c03eSmrg
1728f395c03eSmrg## --------------- ##
1729f395c03eSmrg## Option parsing. ##
1730f395c03eSmrg## --------------- ##
1731f395c03eSmrg
1732f395c03eSmrg# In order to add your own option parsing hooks, you must accept the
1733beef1b22Smrg# full positional parameter list from your hook function.  You may remove
1734beef1b22Smrg# or edit any options that you action, and then pass back the remaining
1735beef1b22Smrg# unprocessed options in '<hooked_function_name>_result', escaped
1736beef1b22Smrg# suitably for 'eval'.
1737beef1b22Smrg#
1738beef1b22Smrg# The '<hooked_function_name>_result' variable is automatically unset
1739beef1b22Smrg# before your hook gets called; for best performance, only set the
1740beef1b22Smrg# *_result variable when necessary (i.e. don't call the 'func_quote'
1741beef1b22Smrg# function unnecessarily because it can be an expensive operation on some
1742beef1b22Smrg# machines).
1743beef1b22Smrg#
1744beef1b22Smrg# Like this:
1745f395c03eSmrg#
1746f395c03eSmrg#    my_options_prep ()
1747f395c03eSmrg#    {
1748f395c03eSmrg#        $debug_cmd
1749f395c03eSmrg#
1750f395c03eSmrg#        # Extend the existing usage message.
1751f395c03eSmrg#        usage_message=$usage_message'
1752f395c03eSmrg#      -s, --silent       don'\''t print informational messages
1753f395c03eSmrg#    '
1754beef1b22Smrg#        # No change in '$@' (ignored completely by this hook).  Leave
1755beef1b22Smrg#        # my_options_prep_result variable intact.
1756f395c03eSmrg#    }
1757f395c03eSmrg#    func_add_hook func_options_prep my_options_prep
1758f395c03eSmrg#
1759f395c03eSmrg#
1760f395c03eSmrg#    my_silent_option ()
1761f395c03eSmrg#    {
1762f395c03eSmrg#        $debug_cmd
1763f395c03eSmrg#
1764beef1b22Smrg#        args_changed=false
1765beef1b22Smrg#
1766beef1b22Smrg#        # Note that, for efficiency, we parse as many options as we can
1767f395c03eSmrg#        # recognise in a loop before passing the remainder back to the
1768f395c03eSmrg#        # caller on the first unrecognised argument we encounter.
1769f395c03eSmrg#        while test $# -gt 0; do
1770f395c03eSmrg#          opt=$1; shift
1771f395c03eSmrg#          case $opt in
1772beef1b22Smrg#            --silent|-s) opt_silent=:
1773beef1b22Smrg#                         args_changed=:
1774beef1b22Smrg#                         ;;
1775f395c03eSmrg#            # Separate non-argument short options:
1776f395c03eSmrg#            -s*)         func_split_short_opt "$_G_opt"
1777f395c03eSmrg#                         set dummy "$func_split_short_opt_name" \
1778f395c03eSmrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1779f395c03eSmrg#                         shift
1780beef1b22Smrg#                         args_changed=:
1781f395c03eSmrg#                         ;;
1782beef1b22Smrg#            *)           # Make sure the first unrecognised option "$_G_opt"
1783beef1b22Smrg#                         # is added back to "$@" in case we need it later,
1784beef1b22Smrg#                         # if $args_changed was set to 'true'.
1785beef1b22Smrg#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1786f395c03eSmrg#          esac
1787f395c03eSmrg#        done
1788f395c03eSmrg#
1789beef1b22Smrg#        # Only call 'func_quote' here if we processed at least one argument.
1790beef1b22Smrg#        if $args_changed; then
1791beef1b22Smrg#          func_quote eval ${1+"$@"}
1792beef1b22Smrg#          my_silent_option_result=$func_quote_result
1793beef1b22Smrg#        fi
1794f395c03eSmrg#    }
1795f395c03eSmrg#    func_add_hook func_parse_options my_silent_option
1796f395c03eSmrg#
1797f395c03eSmrg#
1798f395c03eSmrg#    my_option_validation ()
1799f395c03eSmrg#    {
1800f395c03eSmrg#        $debug_cmd
1801f395c03eSmrg#
1802f395c03eSmrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1803f395c03eSmrg#    '--silent' and '--verbose' options are mutually exclusive."
1804f395c03eSmrg#    }
1805f395c03eSmrg#    func_add_hook func_validate_options my_option_validation
1806f395c03eSmrg#
1807beef1b22Smrg# You'll also need to manually amend $usage_message to reflect the extra
1808f395c03eSmrg# options you parse.  It's preferable to append if you can, so that
1809f395c03eSmrg# multiple option parsing hooks can be added safely.
1810f395c03eSmrg
1811f395c03eSmrg
1812beef1b22Smrg# func_options_finish [ARG]...
1813beef1b22Smrg# ----------------------------
1814beef1b22Smrg# Finishing the option parse loop (call 'func_options' hooks ATM).
1815beef1b22Smrgfunc_options_finish ()
1816beef1b22Smrg{
1817beef1b22Smrg    $debug_cmd
1818beef1b22Smrg
1819beef1b22Smrg    func_run_hooks func_options ${1+"$@"}
1820beef1b22Smrg    func_propagate_result func_run_hooks func_options_finish
1821beef1b22Smrg}
1822beef1b22Smrg
1823beef1b22Smrg
1824f395c03eSmrg# func_options [ARG]...
1825f395c03eSmrg# ---------------------
1826f395c03eSmrg# All the functions called inside func_options are hookable. See the
1827f395c03eSmrg# individual implementations for details.
1828f395c03eSmrgfunc_hookable func_options
1829f395c03eSmrgfunc_options ()
183009885543Smrg{
1831f395c03eSmrg    $debug_cmd
18322ec8c4b4Smrg
1833beef1b22Smrg    _G_options_quoted=false
1834e4f6584cSmrg
1835beef1b22Smrg    for my_func in options_prep parse_options validate_options options_finish
1836beef1b22Smrg    do
1837beef1b22Smrg      func_unset func_${my_func}_result
1838beef1b22Smrg      func_unset func_run_hooks_result
1839beef1b22Smrg      eval func_$my_func '${1+"$@"}'
1840beef1b22Smrg      func_propagate_result func_$my_func func_options
1841beef1b22Smrg      if $func_propagate_result_result; then
1842beef1b22Smrg        eval set dummy "$func_options_result"; shift
1843beef1b22Smrg        _G_options_quoted=:
1844beef1b22Smrg      fi
1845beef1b22Smrg    done
1846f395c03eSmrg
1847beef1b22Smrg    $_G_options_quoted || {
1848beef1b22Smrg      # As we (func_options) are top-level options-parser function and
1849beef1b22Smrg      # nobody quoted "$@" for us yet, we need to do it explicitly for
1850beef1b22Smrg      # caller.
1851beef1b22Smrg      func_quote eval ${1+"$@"}
1852beef1b22Smrg      func_options_result=$func_quote_result
1853beef1b22Smrg    }
185409885543Smrg}
185509885543Smrg
1856e4f6584cSmrg
1857f395c03eSmrg# func_options_prep [ARG]...
1858f395c03eSmrg# --------------------------
1859f395c03eSmrg# All initialisations required before starting the option parse loop.
1860f395c03eSmrg# Note that when calling hook functions, we pass through the list of
1861f395c03eSmrg# positional parameters.  If a hook function modifies that list, and
1862beef1b22Smrg# needs to propagate that back to rest of this script, then the complete
1863beef1b22Smrg# modified list must be put in 'func_run_hooks_result' before returning.
1864f395c03eSmrgfunc_hookable func_options_prep
1865f395c03eSmrgfunc_options_prep ()
186609885543Smrg{
1867f395c03eSmrg    $debug_cmd
1868e4f6584cSmrg
1869f395c03eSmrg    # Option defaults:
1870f395c03eSmrg    opt_verbose=false
1871f395c03eSmrg    opt_warning_types=
1872e4f6584cSmrg
1873f395c03eSmrg    func_run_hooks func_options_prep ${1+"$@"}
1874beef1b22Smrg    func_propagate_result func_run_hooks func_options_prep
1875e4f6584cSmrg}
187609885543Smrg
1877f395c03eSmrg
1878f395c03eSmrg# func_parse_options [ARG]...
1879f395c03eSmrg# ---------------------------
1880f395c03eSmrg# The main option parsing loop.
1881f395c03eSmrgfunc_hookable func_parse_options
1882f395c03eSmrgfunc_parse_options ()
1883b12e5c03Smrg{
1884f395c03eSmrg    $debug_cmd
1885f395c03eSmrg
1886beef1b22Smrg    _G_parse_options_requote=false
1887f395c03eSmrg    # this just eases exit handling
1888f395c03eSmrg    while test $# -gt 0; do
1889f395c03eSmrg      # Defer to hook functions for initial option parsing, so they
1890f395c03eSmrg      # get priority in the event of reusing an option name.
1891f395c03eSmrg      func_run_hooks func_parse_options ${1+"$@"}
1892beef1b22Smrg      func_propagate_result func_run_hooks func_parse_options
1893beef1b22Smrg      if $func_propagate_result_result; then
1894beef1b22Smrg        eval set dummy "$func_parse_options_result"; shift
1895beef1b22Smrg        # Even though we may have changed "$@", we passed the "$@" array
1896beef1b22Smrg        # down into the hook and it quoted it for us (because we are in
1897beef1b22Smrg        # this if-branch).  No need to quote it again.
1898beef1b22Smrg        _G_parse_options_requote=false
1899beef1b22Smrg      fi
1900f395c03eSmrg
1901f395c03eSmrg      # Break out of the loop if we already parsed every option.
1902f395c03eSmrg      test $# -gt 0 || break
1903f395c03eSmrg
1904beef1b22Smrg      # We expect that one of the options parsed in this function matches
1905beef1b22Smrg      # and thus we remove _G_opt from "$@" and need to re-quote.
1906beef1b22Smrg      _G_match_parse_options=:
1907f395c03eSmrg      _G_opt=$1
1908f395c03eSmrg      shift
1909f395c03eSmrg      case $_G_opt in
1910f395c03eSmrg        --debug|-x)   debug_cmd='set -x'
1911beef1b22Smrg                      func_echo "enabling shell trace mode" >&2
1912f395c03eSmrg                      $debug_cmd
1913f395c03eSmrg                      ;;
1914f395c03eSmrg
1915f395c03eSmrg        --no-warnings|--no-warning|--no-warn)
1916f395c03eSmrg                      set dummy --warnings none ${1+"$@"}
1917f395c03eSmrg                      shift
1918f395c03eSmrg		      ;;
1919f395c03eSmrg
1920f395c03eSmrg        --warnings|--warning|-W)
1921beef1b22Smrg                      if test $# = 0 && func_missing_arg $_G_opt; then
1922beef1b22Smrg                        _G_parse_options_requote=:
1923beef1b22Smrg                        break
1924beef1b22Smrg                      fi
1925f395c03eSmrg                      case " $warning_categories $1" in
1926f395c03eSmrg                        *" $1 "*)
1927f395c03eSmrg                          # trailing space prevents matching last $1 above
1928f395c03eSmrg                          func_append_uniq opt_warning_types " $1"
1929f395c03eSmrg                          ;;
1930f395c03eSmrg                        *all)
1931f395c03eSmrg                          opt_warning_types=$warning_categories
1932f395c03eSmrg                          ;;
1933f395c03eSmrg                        *none)
1934f395c03eSmrg                          opt_warning_types=none
1935f395c03eSmrg                          warning_func=:
1936f395c03eSmrg                          ;;
1937f395c03eSmrg                        *error)
1938f395c03eSmrg                          opt_warning_types=$warning_categories
1939f395c03eSmrg                          warning_func=func_fatal_error
1940f395c03eSmrg                          ;;
1941f395c03eSmrg                        *)
1942f395c03eSmrg                          func_fatal_error \
1943f395c03eSmrg                             "unsupported warning category: '$1'"
1944f395c03eSmrg                          ;;
1945f395c03eSmrg                      esac
1946f395c03eSmrg                      shift
1947f395c03eSmrg                      ;;
1948f395c03eSmrg
1949f395c03eSmrg        --verbose|-v) opt_verbose=: ;;
1950f395c03eSmrg        --version)    func_version ;;
1951f395c03eSmrg        -\?|-h)       func_usage ;;
1952f395c03eSmrg        --help)       func_help ;;
1953f395c03eSmrg
1954f395c03eSmrg	# Separate optargs to long options (plugins may need this):
1955f395c03eSmrg	--*=*)        func_split_equals "$_G_opt"
1956f395c03eSmrg	              set dummy "$func_split_equals_lhs" \
1957f395c03eSmrg                          "$func_split_equals_rhs" ${1+"$@"}
1958f395c03eSmrg                      shift
1959f395c03eSmrg                      ;;
1960f395c03eSmrg
1961f395c03eSmrg       # Separate optargs to short options:
1962f395c03eSmrg        -W*)
1963f395c03eSmrg                      func_split_short_opt "$_G_opt"
1964f395c03eSmrg                      set dummy "$func_split_short_opt_name" \
1965f395c03eSmrg                          "$func_split_short_opt_arg" ${1+"$@"}
1966f395c03eSmrg                      shift
1967f395c03eSmrg                      ;;
1968f395c03eSmrg
1969f395c03eSmrg        # Separate non-argument short options:
1970f395c03eSmrg        -\?*|-h*|-v*|-x*)
1971f395c03eSmrg                      func_split_short_opt "$_G_opt"
1972f395c03eSmrg                      set dummy "$func_split_short_opt_name" \
1973f395c03eSmrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1974f395c03eSmrg                      shift
1975f395c03eSmrg                      ;;
1976f395c03eSmrg
1977beef1b22Smrg        --)           _G_parse_options_requote=: ; break ;;
1978f395c03eSmrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1979beef1b22Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1980beef1b22Smrg                      _G_match_parse_options=false
1981beef1b22Smrg                      break
1982beef1b22Smrg                      ;;
1983f395c03eSmrg      esac
1984beef1b22Smrg
1985beef1b22Smrg      if $_G_match_parse_options; then
1986beef1b22Smrg        _G_parse_options_requote=:
1987beef1b22Smrg      fi
1988f395c03eSmrg    done
1989f395c03eSmrg
1990beef1b22Smrg    if $_G_parse_options_requote; then
1991beef1b22Smrg      # save modified positional parameters for caller
1992beef1b22Smrg      func_quote eval ${1+"$@"}
1993beef1b22Smrg      func_parse_options_result=$func_quote_result
1994beef1b22Smrg    fi
1995b12e5c03Smrg}
1996e4f6584cSmrg
1997e4f6584cSmrg
1998f395c03eSmrg# func_validate_options [ARG]...
1999f395c03eSmrg# ------------------------------
2000f395c03eSmrg# Perform any sanity checks on option settings and/or unconsumed
2001f395c03eSmrg# arguments.
2002f395c03eSmrgfunc_hookable func_validate_options
2003f395c03eSmrgfunc_validate_options ()
2004e4f6584cSmrg{
2005f395c03eSmrg    $debug_cmd
2006b12e5c03Smrg
2007f395c03eSmrg    # Display all warnings if -W was not given.
2008f395c03eSmrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
2009f395c03eSmrg
2010f395c03eSmrg    func_run_hooks func_validate_options ${1+"$@"}
2011beef1b22Smrg    func_propagate_result func_run_hooks func_validate_options
2012f395c03eSmrg
2013f395c03eSmrg    # Bail if the options were screwed!
2014f395c03eSmrg    $exit_cmd $EXIT_FAILURE
2015e4f6584cSmrg}
2016e4f6584cSmrg
2017f395c03eSmrg
2018f395c03eSmrg
2019f395c03eSmrg## ----------------- ##
2020f395c03eSmrg## Helper functions. ##
2021f395c03eSmrg## ----------------- ##
2022f395c03eSmrg
2023f395c03eSmrg# This section contains the helper functions used by the rest of the
2024f395c03eSmrg# hookable option parser framework in ascii-betical order.
2025f395c03eSmrg
2026f395c03eSmrg
2027f395c03eSmrg# func_fatal_help ARG...
2028f395c03eSmrg# ----------------------
2029f395c03eSmrg# Echo program name prefixed message to standard error, followed by
2030f395c03eSmrg# a help hint, and exit.
2031f395c03eSmrgfunc_fatal_help ()
2032e4f6584cSmrg{
2033f395c03eSmrg    $debug_cmd
2034b12e5c03Smrg
2035f395c03eSmrg    eval \$ECHO \""Usage: $usage"\"
2036f395c03eSmrg    eval \$ECHO \""$fatal_help"\"
2037f395c03eSmrg    func_error ${1+"$@"}
2038f395c03eSmrg    exit $EXIT_FAILURE
2039e4f6584cSmrg}
2040e4f6584cSmrg
2041f395c03eSmrg
2042f395c03eSmrg# func_help
2043f395c03eSmrg# ---------
2044f395c03eSmrg# Echo long help message to standard output and exit.
2045e4f6584cSmrgfunc_help ()
2046e4f6584cSmrg{
2047f395c03eSmrg    $debug_cmd
2048f395c03eSmrg
2049f395c03eSmrg    func_usage_message
2050f395c03eSmrg    $ECHO "$long_help_message"
2051f395c03eSmrg    exit 0
2052e4f6584cSmrg}
2053e4f6584cSmrg
2054f395c03eSmrg
2055f395c03eSmrg# func_missing_arg ARGNAME
2056f395c03eSmrg# ------------------------
2057e4f6584cSmrg# Echo program name prefixed message to standard error and set global
2058e4f6584cSmrg# exit_cmd.
2059e4f6584cSmrgfunc_missing_arg ()
2060e4f6584cSmrg{
2061f395c03eSmrg    $debug_cmd
2062b12e5c03Smrg
2063f395c03eSmrg    func_error "Missing argument for '$1'."
2064e4f6584cSmrg    exit_cmd=exit
206509885543Smrg}
206609885543Smrg
20672ec8c4b4Smrg
2068f395c03eSmrg# func_split_equals STRING
2069f395c03eSmrg# ------------------------
2070beef1b22Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables
2071beef1b22Smrg# after splitting STRING at the '=' sign.
2072f395c03eSmrgtest -z "$_G_HAVE_XSI_OPS" \
2073f395c03eSmrg    && (eval 'x=a/b/c;
2074f395c03eSmrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
2075f395c03eSmrg    && _G_HAVE_XSI_OPS=yes
2076f395c03eSmrg
2077f395c03eSmrgif test yes = "$_G_HAVE_XSI_OPS"
2078f395c03eSmrgthen
2079f395c03eSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2080f395c03eSmrg  eval 'func_split_equals ()
2081f395c03eSmrg  {
2082f395c03eSmrg      $debug_cmd
2083f395c03eSmrg
2084f395c03eSmrg      func_split_equals_lhs=${1%%=*}
2085f395c03eSmrg      func_split_equals_rhs=${1#*=}
2086beef1b22Smrg      if test "x$func_split_equals_lhs" = "x$1"; then
2087beef1b22Smrg        func_split_equals_rhs=
2088beef1b22Smrg      fi
2089f395c03eSmrg  }'
2090f395c03eSmrgelse
2091f395c03eSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2092f395c03eSmrg  func_split_equals ()
2093f395c03eSmrg  {
2094f395c03eSmrg      $debug_cmd
2095f395c03eSmrg
2096f395c03eSmrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
2097f395c03eSmrg      func_split_equals_rhs=
2098beef1b22Smrg      test "x$func_split_equals_lhs=" = "x$1" \
2099f395c03eSmrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
2100f395c03eSmrg  }
2101f395c03eSmrgfi #func_split_equals
2102f395c03eSmrg
2103f395c03eSmrg
2104f395c03eSmrg# func_split_short_opt SHORTOPT
2105f395c03eSmrg# -----------------------------
2106b12e5c03Smrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
2107b12e5c03Smrg# variables after splitting SHORTOPT after the 2nd character.
2108f395c03eSmrgif test yes = "$_G_HAVE_XSI_OPS"
2109f395c03eSmrgthen
2110f395c03eSmrg  # This is an XSI compatible shell, allowing a faster implementation...
2111f395c03eSmrg  eval 'func_split_short_opt ()
2112f395c03eSmrg  {
2113f395c03eSmrg      $debug_cmd
2114f395c03eSmrg
2115f395c03eSmrg      func_split_short_opt_arg=${1#??}
2116f395c03eSmrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
2117f395c03eSmrg  }'
2118f395c03eSmrgelse
2119f395c03eSmrg  # ...otherwise fall back to using expr, which is often a shell builtin.
2120f395c03eSmrg  func_split_short_opt ()
2121f395c03eSmrg  {
2122f395c03eSmrg      $debug_cmd
2123f395c03eSmrg
2124beef1b22Smrg      func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'`
2125f395c03eSmrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
2126f395c03eSmrg  }
2127f395c03eSmrgfi #func_split_short_opt
2128f395c03eSmrg
2129f395c03eSmrg
2130f395c03eSmrg# func_usage
2131f395c03eSmrg# ----------
2132f395c03eSmrg# Echo short help message to standard output and exit.
2133f395c03eSmrgfunc_usage ()
2134b12e5c03Smrg{
2135f395c03eSmrg    $debug_cmd
2136b12e5c03Smrg
2137f395c03eSmrg    func_usage_message
2138f395c03eSmrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
2139f395c03eSmrg    exit 0
2140f395c03eSmrg}
21412ec8c4b4Smrg
2142e4f6584cSmrg
2143f395c03eSmrg# func_usage_message
2144f395c03eSmrg# ------------------
2145f395c03eSmrg# Echo short help message to standard output.
2146f395c03eSmrgfunc_usage_message ()
2147b12e5c03Smrg{
2148f395c03eSmrg    $debug_cmd
2149b12e5c03Smrg
2150f395c03eSmrg    eval \$ECHO \""Usage: $usage"\"
2151f395c03eSmrg    echo
2152f395c03eSmrg    $SED -n 's|^# ||
2153f395c03eSmrg        /^Written by/{
2154f395c03eSmrg          x;p;x
2155f395c03eSmrg        }
2156f395c03eSmrg	h
2157f395c03eSmrg	/^Written by/q' < "$progpath"
2158f395c03eSmrg    echo
2159f395c03eSmrg    eval \$ECHO \""$usage_message"\"
2160f395c03eSmrg}
2161b12e5c03Smrg
2162b12e5c03Smrg
2163f395c03eSmrg# func_version
2164f395c03eSmrg# ------------
2165f395c03eSmrg# Echo version message to standard output and exit.
2166beef1b22Smrg# The version message is extracted from the calling file's header
2167beef1b22Smrg# comments, with leading '# ' stripped:
2168beef1b22Smrg#   1. First display the progname and version
2169beef1b22Smrg#   2. Followed by the header comment line matching  /^# Written by /
2170beef1b22Smrg#   3. Then a blank line followed by the first following line matching
2171beef1b22Smrg#      /^# Copyright /
2172beef1b22Smrg#   4. Immediately followed by any lines between the previous matches,
2173beef1b22Smrg#      except lines preceding the intervening completely blank line.
2174beef1b22Smrg# For example, see the header comments of this file.
2175f395c03eSmrgfunc_version ()
2176f395c03eSmrg{
2177f395c03eSmrg    $debug_cmd
2178e4f6584cSmrg
2179f395c03eSmrg    printf '%s\n' "$progname $scriptversion"
2180f395c03eSmrg    $SED -n '
2181beef1b22Smrg        /^# Written by /!b
2182beef1b22Smrg        s|^# ||; p; n
2183beef1b22Smrg
2184beef1b22Smrg        :fwd2blnk
2185beef1b22Smrg        /./ {
2186beef1b22Smrg          n
2187beef1b22Smrg          b fwd2blnk
2188f395c03eSmrg        }
2189beef1b22Smrg        p; n
2190beef1b22Smrg
2191beef1b22Smrg        :holdwrnt
2192beef1b22Smrg        s|^# ||
2193beef1b22Smrg        s|^# *$||
2194beef1b22Smrg        /^Copyright /!{
2195beef1b22Smrg          /./H
2196beef1b22Smrg          n
2197beef1b22Smrg          b holdwrnt
2198f395c03eSmrg        }
2199beef1b22Smrg
2200beef1b22Smrg        s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2201beef1b22Smrg        G
2202beef1b22Smrg        s|\(\n\)\n*|\1|g
2203beef1b22Smrg        p; q' < "$progpath"
2204e4f6584cSmrg
2205f395c03eSmrg    exit $?
2206f395c03eSmrg}
220709885543Smrg
220809885543Smrg
2209f395c03eSmrg# Local variables:
2210f395c03eSmrg# mode: shell-script
2211f395c03eSmrg# sh-indentation: 2
2212f395c03eSmrg# eval: (add-hook 'before-save-hook 'time-stamp)
2213beef1b22Smrg# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2214f395c03eSmrg# time-stamp-time-zone: "UTC"
2215f395c03eSmrg# End:
221609885543Smrg
2217f395c03eSmrg# Set a version string.
2218beef1b22Smrgscriptversion='(GNU libtool) 2.4.7'
22192ec8c4b4Smrg
2220e4f6584cSmrg
2221f395c03eSmrg# func_echo ARG...
2222f395c03eSmrg# ----------------
2223f395c03eSmrg# Libtool also displays the current mode in messages, so override
2224f395c03eSmrg# funclib.sh func_echo with this custom definition.
2225f395c03eSmrgfunc_echo ()
2226b12e5c03Smrg{
2227f395c03eSmrg    $debug_cmd
2228b12e5c03Smrg
2229f395c03eSmrg    _G_message=$*
2230f395c03eSmrg
2231f395c03eSmrg    func_echo_IFS=$IFS
2232f395c03eSmrg    IFS=$nl
2233f395c03eSmrg    for _G_line in $_G_message; do
2234f395c03eSmrg      IFS=$func_echo_IFS
2235f395c03eSmrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2236f395c03eSmrg    done
2237f395c03eSmrg    IFS=$func_echo_IFS
2238f395c03eSmrg}
2239b12e5c03Smrg
2240b12e5c03Smrg
2241f395c03eSmrg# func_warning ARG...
2242f395c03eSmrg# -------------------
2243f395c03eSmrg# Libtool warnings are not categorized, so override funclib.sh
2244f395c03eSmrg# func_warning with this simpler definition.
2245f395c03eSmrgfunc_warning ()
2246b12e5c03Smrg{
2247f395c03eSmrg    $debug_cmd
2248f395c03eSmrg
2249f395c03eSmrg    $warning_func ${1+"$@"}
2250f395c03eSmrg}
2251f395c03eSmrg
2252b12e5c03Smrg
2253f395c03eSmrg## ---------------- ##
2254f395c03eSmrg## Options parsing. ##
2255f395c03eSmrg## ---------------- ##
2256f395c03eSmrg
2257f395c03eSmrg# Hook in the functions to make sure our own options are parsed during
2258f395c03eSmrg# the option parsing loop.
2259f395c03eSmrg
2260f395c03eSmrgusage='$progpath [OPTION]... [MODE-ARG]...'
2261f395c03eSmrg
2262f395c03eSmrg# Short help message in response to '-h'.
2263f395c03eSmrgusage_message="Options:
2264f395c03eSmrg       --config             show all configuration variables
2265f395c03eSmrg       --debug              enable verbose shell tracing
2266f395c03eSmrg   -n, --dry-run            display commands without modifying any files
2267f395c03eSmrg       --features           display basic configuration information and exit
2268f395c03eSmrg       --mode=MODE          use operation mode MODE
2269f395c03eSmrg       --no-warnings        equivalent to '-Wnone'
2270f395c03eSmrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2271f395c03eSmrg       --quiet, --silent    don't print informational messages
2272f395c03eSmrg       --tag=TAG            use configuration variables from tag TAG
2273f395c03eSmrg   -v, --verbose            print more informational messages than default
2274f395c03eSmrg       --version            print version information
2275f395c03eSmrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2276f395c03eSmrg   -h, --help, --help-all   print short, long, or detailed help message
2277f395c03eSmrg"
2278b12e5c03Smrg
2279f395c03eSmrg# Additional text appended to 'usage_message' in response to '--help'.
2280f395c03eSmrgfunc_help ()
2281b12e5c03Smrg{
2282f395c03eSmrg    $debug_cmd
2283f395c03eSmrg
2284f395c03eSmrg    func_usage_message
2285f395c03eSmrg    $ECHO "$long_help_message
2286f395c03eSmrg
2287f395c03eSmrgMODE must be one of the following:
2288f395c03eSmrg
2289f395c03eSmrg       clean           remove files from the build directory
2290f395c03eSmrg       compile         compile a source file into a libtool object
2291f395c03eSmrg       execute         automatically set library path, then run a program
2292f395c03eSmrg       finish          complete the installation of libtool libraries
2293f395c03eSmrg       install         install libraries or executables
2294f395c03eSmrg       link            create a library or an executable
2295f395c03eSmrg       uninstall       remove libraries from an installed directory
2296f395c03eSmrg
2297f395c03eSmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2298f395c03eSmrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2299f395c03eSmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2300f395c03eSmrg
2301f395c03eSmrgWhen reporting a bug, please describe a test case to reproduce it and
2302f395c03eSmrginclude the following information:
2303f395c03eSmrg
2304f395c03eSmrg       host-triplet:   $host
2305f395c03eSmrg       shell:          $SHELL
2306f395c03eSmrg       compiler:       $LTCC
2307f395c03eSmrg       compiler flags: $LTCFLAGS
2308f395c03eSmrg       linker:         $LD (gnu? $with_gnu_ld)
2309beef1b22Smrg       version:        $progname (GNU libtool) 2.4.7
2310f395c03eSmrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2311f395c03eSmrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2312f395c03eSmrg
2313f395c03eSmrgReport bugs to <bug-libtool@gnu.org>.
2314f395c03eSmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2315f395c03eSmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2316f395c03eSmrg    exit 0
2317f395c03eSmrg}
2318b12e5c03Smrg
2319b12e5c03Smrg
2320f395c03eSmrg# func_lo2o OBJECT-NAME
2321f395c03eSmrg# ---------------------
2322f395c03eSmrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2323f395c03eSmrg# object suffix.
2324b12e5c03Smrg
2325f395c03eSmrglo2o=s/\\.lo\$/.$objext/
2326f395c03eSmrgo2lo=s/\\.$objext\$/.lo/
2327b12e5c03Smrg
2328f395c03eSmrgif test yes = "$_G_HAVE_XSI_OPS"; then
2329f395c03eSmrg  eval 'func_lo2o ()
2330f395c03eSmrg  {
2331f395c03eSmrg    case $1 in
2332f395c03eSmrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2333f395c03eSmrg      *   ) func_lo2o_result=$1               ;;
2334f395c03eSmrg    esac
2335f395c03eSmrg  }'
2336f395c03eSmrg
2337f395c03eSmrg  # func_xform LIBOBJ-OR-SOURCE
2338f395c03eSmrg  # ---------------------------
2339f395c03eSmrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2340f395c03eSmrg  # suffix to a '.lo' libtool-object suffix.
2341f395c03eSmrg  eval 'func_xform ()
2342f395c03eSmrg  {
2343f395c03eSmrg    func_xform_result=${1%.*}.lo
2344f395c03eSmrg  }'
2345f395c03eSmrgelse
2346f395c03eSmrg  # ...otherwise fall back to using sed.
2347f395c03eSmrg  func_lo2o ()
2348f395c03eSmrg  {
2349f395c03eSmrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2350f395c03eSmrg  }
2351f395c03eSmrg
2352f395c03eSmrg  func_xform ()
2353f395c03eSmrg  {
2354f395c03eSmrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2355f395c03eSmrg  }
2356f395c03eSmrgfi
2357b12e5c03Smrg
2358b12e5c03Smrg
2359f395c03eSmrg# func_fatal_configuration ARG...
2360f395c03eSmrg# -------------------------------
2361e4f6584cSmrg# Echo program name prefixed message to standard error, followed by
2362e4f6584cSmrg# a configuration failure hint, and exit.
2363e4f6584cSmrgfunc_fatal_configuration ()
2364e4f6584cSmrg{
2365beef1b22Smrg    func_fatal_error ${1+"$@"} \
2366f395c03eSmrg      "See the $PACKAGE documentation for more information." \
2367f395c03eSmrg      "Fatal configuration error."
2368e4f6584cSmrg}
23697104f784Smrg
23702ec8c4b4Smrg
2371e4f6584cSmrg# func_config
2372f395c03eSmrg# -----------
2373e4f6584cSmrg# Display the configuration for all the tags in this script.
2374e4f6584cSmrgfunc_config ()
2375e4f6584cSmrg{
2376e4f6584cSmrg    re_begincf='^# ### BEGIN LIBTOOL'
2377e4f6584cSmrg    re_endcf='^# ### END LIBTOOL'
2378e4f6584cSmrg
2379e4f6584cSmrg    # Default configuration.
2380e4f6584cSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
238109885543Smrg
238209885543Smrg    # Now print the configurations for the tags.
238309885543Smrg    for tagname in $taglist; do
2384e4f6584cSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
238509885543Smrg    done
2386b698ba48Smrg
2387e4f6584cSmrg    exit $?
2388e4f6584cSmrg}
2389b698ba48Smrg
2390f395c03eSmrg
2391e4f6584cSmrg# func_features
2392f395c03eSmrg# -------------
2393e4f6584cSmrg# Display the features supported by this script.
2394e4f6584cSmrgfunc_features ()
2395e4f6584cSmrg{
2396b12e5c03Smrg    echo "host: $host"
2397f395c03eSmrg    if test yes = "$build_libtool_libs"; then
2398b12e5c03Smrg      echo "enable shared libraries"
239909885543Smrg    else
2400b12e5c03Smrg      echo "disable shared libraries"
240109885543Smrg    fi
2402f395c03eSmrg    if test yes = "$build_old_libs"; then
2403b12e5c03Smrg      echo "enable static libraries"
240409885543Smrg    else
2405b12e5c03Smrg      echo "disable static libraries"
240609885543Smrg    fi
2407e4f6584cSmrg
240809885543Smrg    exit $?
2409e4f6584cSmrg}
241009885543Smrg
2411f395c03eSmrg
2412f395c03eSmrg# func_enable_tag TAGNAME
2413f395c03eSmrg# -----------------------
2414e4f6584cSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
2415e4f6584cSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
2416e4f6584cSmrg# variable here.
2417e4f6584cSmrgfunc_enable_tag ()
2418e4f6584cSmrg{
2419f395c03eSmrg    # Global variable:
2420f395c03eSmrg    tagname=$1
242109885543Smrg
2422f395c03eSmrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2423f395c03eSmrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2424f395c03eSmrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
24252ec8c4b4Smrg
2426f395c03eSmrg    # Validate tagname.
2427f395c03eSmrg    case $tagname in
2428f395c03eSmrg      *[!-_A-Za-z0-9,/]*)
2429f395c03eSmrg        func_fatal_error "invalid tag name: $tagname"
2430f395c03eSmrg        ;;
2431f395c03eSmrg    esac
243209885543Smrg
2433f395c03eSmrg    # Don't test for the "default" C tag, as we know it's
2434f395c03eSmrg    # there but not specially marked.
2435f395c03eSmrg    case $tagname in
2436f395c03eSmrg        CC) ;;
2437e4f6584cSmrg    *)
2438f395c03eSmrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2439f395c03eSmrg	  taglist="$taglist $tagname"
2440f395c03eSmrg
2441f395c03eSmrg	  # Evaluate the configuration.  Be careful to quote the path
2442f395c03eSmrg	  # and the sed script, to avoid splitting on whitespace, but
2443f395c03eSmrg	  # also don't use non-portable quotes within backquotes within
2444f395c03eSmrg	  # quotes we have to do it in 2 steps:
2445f395c03eSmrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2446f395c03eSmrg	  eval "$extractedcf"
2447f395c03eSmrg        else
2448f395c03eSmrg	  func_error "ignoring unknown tag $tagname"
2449f395c03eSmrg        fi
2450f395c03eSmrg        ;;
2451f395c03eSmrg    esac
2452e4f6584cSmrg}
2453e4f6584cSmrg
2454f395c03eSmrg
2455b12e5c03Smrg# func_check_version_match
2456f395c03eSmrg# ------------------------
2457b12e5c03Smrg# Ensure that we are using m4 macros, and libtool script from the same
2458b12e5c03Smrg# release of libtool.
2459b12e5c03Smrgfunc_check_version_match ()
2460e4f6584cSmrg{
2461f395c03eSmrg    if test "$package_revision" != "$macro_revision"; then
2462f395c03eSmrg      if test "$VERSION" != "$macro_version"; then
2463f395c03eSmrg        if test -z "$macro_version"; then
2464f395c03eSmrg          cat >&2 <<_LT_EOF
2465b12e5c03Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2466b12e5c03Smrg$progname: definition of this LT_INIT comes from an older release.
2467b12e5c03Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2468b12e5c03Smrg$progname: and run autoconf again.
2469b12e5c03Smrg_LT_EOF
2470f395c03eSmrg        else
2471f395c03eSmrg          cat >&2 <<_LT_EOF
2472b12e5c03Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
2473b12e5c03Smrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
2474b12e5c03Smrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
2475b12e5c03Smrg$progname: and run autoconf again.
2476b12e5c03Smrg_LT_EOF
2477f395c03eSmrg        fi
2478f395c03eSmrg      else
2479f395c03eSmrg        cat >&2 <<_LT_EOF
2480b12e5c03Smrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
2481b12e5c03Smrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
2482b12e5c03Smrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
2483b12e5c03Smrg$progname: of $PACKAGE $VERSION and run autoconf again.
2484b12e5c03Smrg_LT_EOF
2485f395c03eSmrg      fi
2486b12e5c03Smrg
2487f395c03eSmrg      exit $EXIT_MISMATCH
2488f395c03eSmrg    fi
2489b12e5c03Smrg}
2490b12e5c03Smrg
2491b12e5c03Smrg
2492f395c03eSmrg# libtool_options_prep [ARG]...
2493f395c03eSmrg# -----------------------------
2494f395c03eSmrg# Preparation for options parsed by libtool.
2495f395c03eSmrglibtool_options_prep ()
2496f395c03eSmrg{
2497f395c03eSmrg    $debug_mode
2498b698ba48Smrg
2499f395c03eSmrg    # Option defaults:
2500f395c03eSmrg    opt_config=false
2501f395c03eSmrg    opt_dlopen=
2502f395c03eSmrg    opt_dry_run=false
2503f395c03eSmrg    opt_help=false
2504f395c03eSmrg    opt_mode=
2505f395c03eSmrg    opt_preserve_dup_deps=false
2506f395c03eSmrg    opt_quiet=false
250709885543Smrg
2508f395c03eSmrg    nonopt=
2509f395c03eSmrg    preserve_args=
2510b12e5c03Smrg
2511beef1b22Smrg    _G_rc_lt_options_prep=:
2512beef1b22Smrg
2513f395c03eSmrg    # Shorthand for --mode=foo, only valid as the first argument
2514f395c03eSmrg    case $1 in
2515f395c03eSmrg    clean|clea|cle|cl)
2516f395c03eSmrg      shift; set dummy --mode clean ${1+"$@"}; shift
2517f395c03eSmrg      ;;
2518f395c03eSmrg    compile|compil|compi|comp|com|co|c)
2519f395c03eSmrg      shift; set dummy --mode compile ${1+"$@"}; shift
2520f395c03eSmrg      ;;
2521f395c03eSmrg    execute|execut|execu|exec|exe|ex|e)
2522f395c03eSmrg      shift; set dummy --mode execute ${1+"$@"}; shift
2523f395c03eSmrg      ;;
2524f395c03eSmrg    finish|finis|fini|fin|fi|f)
2525f395c03eSmrg      shift; set dummy --mode finish ${1+"$@"}; shift
2526f395c03eSmrg      ;;
2527f395c03eSmrg    install|instal|insta|inst|ins|in|i)
2528f395c03eSmrg      shift; set dummy --mode install ${1+"$@"}; shift
2529f395c03eSmrg      ;;
2530f395c03eSmrg    link|lin|li|l)
2531f395c03eSmrg      shift; set dummy --mode link ${1+"$@"}; shift
2532f395c03eSmrg      ;;
2533f395c03eSmrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2534f395c03eSmrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2535f395c03eSmrg      ;;
2536beef1b22Smrg    *)
2537beef1b22Smrg      _G_rc_lt_options_prep=false
2538beef1b22Smrg      ;;
2539f395c03eSmrg    esac
2540f395c03eSmrg
2541beef1b22Smrg    if $_G_rc_lt_options_prep; then
2542beef1b22Smrg      # Pass back the list of options.
2543beef1b22Smrg      func_quote eval ${1+"$@"}
2544beef1b22Smrg      libtool_options_prep_result=$func_quote_result
2545beef1b22Smrg    fi
2546f395c03eSmrg}
2547f395c03eSmrgfunc_add_hook func_options_prep libtool_options_prep
2548b12e5c03Smrg
2549b12e5c03Smrg
2550f395c03eSmrg# libtool_parse_options [ARG]...
2551f395c03eSmrg# ---------------------------------
2552f395c03eSmrg# Provide handling for libtool specific options.
2553f395c03eSmrglibtool_parse_options ()
2554b12e5c03Smrg{
2555f395c03eSmrg    $debug_cmd
2556e4f6584cSmrg
2557beef1b22Smrg    _G_rc_lt_parse_options=false
2558beef1b22Smrg
2559f395c03eSmrg    # Perform our own loop to consume as many options as possible in
2560f395c03eSmrg    # each iteration.
2561f395c03eSmrg    while test $# -gt 0; do
2562beef1b22Smrg      _G_match_lt_parse_options=:
2563f395c03eSmrg      _G_opt=$1
2564f395c03eSmrg      shift
2565f395c03eSmrg      case $_G_opt in
2566f395c03eSmrg        --dry-run|--dryrun|-n)
2567f395c03eSmrg                        opt_dry_run=:
2568f395c03eSmrg                        ;;
2569f395c03eSmrg
2570f395c03eSmrg        --config)       func_config ;;
2571f395c03eSmrg
2572f395c03eSmrg        --dlopen|-dlopen)
2573f395c03eSmrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2574f395c03eSmrg}$1"
2575f395c03eSmrg                        shift
2576f395c03eSmrg                        ;;
2577f395c03eSmrg
2578f395c03eSmrg        --preserve-dup-deps)
2579f395c03eSmrg                        opt_preserve_dup_deps=: ;;
2580f395c03eSmrg
2581f395c03eSmrg        --features)     func_features ;;
2582f395c03eSmrg
2583f395c03eSmrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2584f395c03eSmrg
2585f395c03eSmrg        --help)         opt_help=: ;;
2586f395c03eSmrg
2587f395c03eSmrg        --help-all)     opt_help=': help-all' ;;
2588f395c03eSmrg
2589f395c03eSmrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2590f395c03eSmrg                        opt_mode=$1
2591f395c03eSmrg                        case $1 in
2592f395c03eSmrg                          # Valid mode arguments:
2593f395c03eSmrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2594f395c03eSmrg
2595f395c03eSmrg                          # Catch anything else as an error
2596f395c03eSmrg                          *) func_error "invalid argument for $_G_opt"
2597f395c03eSmrg                             exit_cmd=exit
2598f395c03eSmrg                             break
2599f395c03eSmrg                             ;;
2600f395c03eSmrg                        esac
2601f395c03eSmrg                        shift
2602f395c03eSmrg                        ;;
2603f395c03eSmrg
2604f395c03eSmrg        --no-silent|--no-quiet)
2605f395c03eSmrg                        opt_quiet=false
2606f395c03eSmrg                        func_append preserve_args " $_G_opt"
2607f395c03eSmrg                        ;;
2608f395c03eSmrg
2609f395c03eSmrg        --no-warnings|--no-warning|--no-warn)
2610f395c03eSmrg                        opt_warning=false
2611f395c03eSmrg                        func_append preserve_args " $_G_opt"
2612f395c03eSmrg                        ;;
2613f395c03eSmrg
2614f395c03eSmrg        --no-verbose)
2615f395c03eSmrg                        opt_verbose=false
2616f395c03eSmrg                        func_append preserve_args " $_G_opt"
2617f395c03eSmrg                        ;;
2618f395c03eSmrg
2619f395c03eSmrg        --silent|--quiet)
2620f395c03eSmrg                        opt_quiet=:
2621f395c03eSmrg                        opt_verbose=false
2622f395c03eSmrg                        func_append preserve_args " $_G_opt"
2623f395c03eSmrg                        ;;
2624f395c03eSmrg
2625f395c03eSmrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2626f395c03eSmrg                        opt_tag=$1
2627f395c03eSmrg                        func_append preserve_args " $_G_opt $1"
2628f395c03eSmrg                        func_enable_tag "$1"
2629f395c03eSmrg                        shift
2630f395c03eSmrg                        ;;
2631f395c03eSmrg
2632f395c03eSmrg        --verbose|-v)   opt_quiet=false
2633f395c03eSmrg                        opt_verbose=:
2634f395c03eSmrg                        func_append preserve_args " $_G_opt"
2635f395c03eSmrg                        ;;
2636f395c03eSmrg
2637beef1b22Smrg        # An option not handled by this hook function:
2638beef1b22Smrg        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2639beef1b22Smrg                        _G_match_lt_parse_options=false
2640beef1b22Smrg                        break
2641beef1b22Smrg                        ;;
2642f395c03eSmrg      esac
2643beef1b22Smrg      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
2644f395c03eSmrg    done
2645b12e5c03Smrg
2646beef1b22Smrg    if $_G_rc_lt_parse_options; then
2647beef1b22Smrg      # save modified positional parameters for caller
2648beef1b22Smrg      func_quote eval ${1+"$@"}
2649beef1b22Smrg      libtool_parse_options_result=$func_quote_result
2650beef1b22Smrg    fi
2651f395c03eSmrg}
2652f395c03eSmrgfunc_add_hook func_parse_options libtool_parse_options
2653e4f6584cSmrg
26542ec8c4b4Smrg
2655e4f6584cSmrg
2656f395c03eSmrg# libtool_validate_options [ARG]...
2657f395c03eSmrg# ---------------------------------
2658f395c03eSmrg# Perform any sanity checks on option settings and/or unconsumed
2659f395c03eSmrg# arguments.
2660f395c03eSmrglibtool_validate_options ()
2661f395c03eSmrg{
2662f395c03eSmrg    # save first non-option argument
2663f395c03eSmrg    if test 0 -lt $#; then
2664f395c03eSmrg      nonopt=$1
2665f395c03eSmrg      shift
2666e4f6584cSmrg    fi
2667e4f6584cSmrg
2668f395c03eSmrg    # preserve --debug
2669f395c03eSmrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
2670e4f6584cSmrg
2671f395c03eSmrg    case $host in
2672f395c03eSmrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2673f395c03eSmrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2674f395c03eSmrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2675f395c03eSmrg        # don't eliminate duplications in $postdeps and $predeps
2676f395c03eSmrg        opt_duplicate_compiler_generated_deps=:
2677f395c03eSmrg        ;;
2678f395c03eSmrg      *)
2679f395c03eSmrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2680f395c03eSmrg        ;;
2681f395c03eSmrg    esac
268209885543Smrg
2683f395c03eSmrg    $opt_help || {
2684f395c03eSmrg      # Sanity checks first:
2685f395c03eSmrg      func_check_version_match
2686e4f6584cSmrg
2687f395c03eSmrg      test yes != "$build_libtool_libs" \
2688f395c03eSmrg        && test yes != "$build_old_libs" \
2689f395c03eSmrg        && func_fatal_configuration "not configured to build any kind of library"
2690e4f6584cSmrg
2691f395c03eSmrg      # Darwin sucks
2692f395c03eSmrg      eval std_shrext=\"$shrext_cmds\"
2693f395c03eSmrg
2694f395c03eSmrg      # Only execute mode is allowed to have -dlopen flags.
2695f395c03eSmrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2696f395c03eSmrg        func_error "unrecognized option '-dlopen'"
2697f395c03eSmrg        $ECHO "$help" 1>&2
2698f395c03eSmrg        exit $EXIT_FAILURE
2699f395c03eSmrg      fi
2700f395c03eSmrg
2701f395c03eSmrg      # Change the help message to a mode-specific one.
2702f395c03eSmrg      generic_help=$help
2703f395c03eSmrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2704f395c03eSmrg    }
2705f395c03eSmrg
2706f395c03eSmrg    # Pass back the unparsed argument list
2707beef1b22Smrg    func_quote eval ${1+"$@"}
2708beef1b22Smrg    libtool_validate_options_result=$func_quote_result
2709b12e5c03Smrg}
2710f395c03eSmrgfunc_add_hook func_validate_options libtool_validate_options
2711f395c03eSmrg
2712e4f6584cSmrg
2713f395c03eSmrg# Process options as early as possible so that --help and --version
2714f395c03eSmrg# can return quickly.
2715f395c03eSmrgfunc_options ${1+"$@"}
2716f395c03eSmrgeval set dummy "$func_options_result"; shift
2717e4f6584cSmrg
271809885543Smrg
271909885543Smrg
2720b12e5c03Smrg## ----------- ##
2721b12e5c03Smrg##    Main.    ##
2722b12e5c03Smrg## ----------- ##
272309885543Smrg
2724f395c03eSmrgmagic='%%%MAGIC variable%%%'
2725f395c03eSmrgmagic_exe='%%%MAGIC EXE variable%%%'
2726f395c03eSmrg
2727f395c03eSmrg# Global variables.
2728f395c03eSmrgextracted_archives=
2729f395c03eSmrgextracted_serial=0
2730f395c03eSmrg
2731f395c03eSmrg# If this variable is set in any of the actions, the command in it
2732f395c03eSmrg# will be execed at the end.  This prevents here-documents from being
2733f395c03eSmrg# left over by shells.
2734f395c03eSmrgexec_cmd=
2735f395c03eSmrg
2736f395c03eSmrg
2737f395c03eSmrg# A function that is used when there is no print builtin or printf.
2738f395c03eSmrgfunc_fallback_echo ()
2739f395c03eSmrg{
2740f395c03eSmrg  eval 'cat <<_LTECHO_EOF
2741f395c03eSmrg$1
2742f395c03eSmrg_LTECHO_EOF'
2743f395c03eSmrg}
2744f395c03eSmrg
2745f395c03eSmrg# func_generated_by_libtool
2746f395c03eSmrg# True iff stdin has been generated by Libtool. This function is only
2747f395c03eSmrg# a basic sanity check; it will hardly flush out determined imposters.
2748f395c03eSmrgfunc_generated_by_libtool_p ()
2749f395c03eSmrg{
2750f395c03eSmrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2751f395c03eSmrg}
2752f395c03eSmrg
2753e4f6584cSmrg# func_lalib_p file
2754f395c03eSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2755e4f6584cSmrg# This function is only a basic sanity check; it will hardly flush out
2756e4f6584cSmrg# determined imposters.
2757e4f6584cSmrgfunc_lalib_p ()
2758e4f6584cSmrg{
2759e4f6584cSmrg    test -f "$1" &&
2760f395c03eSmrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
2761e4f6584cSmrg}
276209885543Smrg
2763e4f6584cSmrg# func_lalib_unsafe_p file
2764f395c03eSmrg# True iff FILE is a libtool '.la' library or '.lo' object file.
2765e4f6584cSmrg# This function implements the same check as func_lalib_p without
2766e4f6584cSmrg# resorting to external programs.  To this end, it redirects stdin and
2767e4f6584cSmrg# closes it afterwards, without saving the original file descriptor.
2768e4f6584cSmrg# As a safety measure, use it only where a negative result would be
2769f395c03eSmrg# fatal anyway.  Works if 'file' does not exist.
2770e4f6584cSmrgfunc_lalib_unsafe_p ()
2771e4f6584cSmrg{
2772e4f6584cSmrg    lalib_p=no
2773e4f6584cSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
2774e4f6584cSmrg	for lalib_p_l in 1 2 3 4
2775e4f6584cSmrg	do
2776e4f6584cSmrg	    read lalib_p_line
2777f395c03eSmrg	    case $lalib_p_line in
2778e4f6584cSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
2779e4f6584cSmrg	    esac
2780e4f6584cSmrg	done
2781e4f6584cSmrg	exec 0<&5 5<&-
2782e4f6584cSmrg    fi
2783f395c03eSmrg    test yes = "$lalib_p"
2784e4f6584cSmrg}
278509885543Smrg
2786e4f6584cSmrg# func_ltwrapper_script_p file
2787e4f6584cSmrg# True iff FILE is a libtool wrapper script
2788e4f6584cSmrg# This function is only a basic sanity check; it will hardly flush out
2789e4f6584cSmrg# determined imposters.
2790e4f6584cSmrgfunc_ltwrapper_script_p ()
2791e4f6584cSmrg{
2792f395c03eSmrg    test -f "$1" &&
2793f395c03eSmrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
2794e4f6584cSmrg}
279509885543Smrg
2796e4f6584cSmrg# func_ltwrapper_executable_p file
2797e4f6584cSmrg# True iff FILE is a libtool wrapper executable
2798e4f6584cSmrg# This function is only a basic sanity check; it will hardly flush out
2799e4f6584cSmrg# determined imposters.
2800e4f6584cSmrgfunc_ltwrapper_executable_p ()
2801e4f6584cSmrg{
2802e4f6584cSmrg    func_ltwrapper_exec_suffix=
2803e4f6584cSmrg    case $1 in
2804e4f6584cSmrg    *.exe) ;;
2805e4f6584cSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
2806e4f6584cSmrg    esac
2807e4f6584cSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
2808e4f6584cSmrg}
28092ec8c4b4Smrg
2810e4f6584cSmrg# func_ltwrapper_scriptname file
2811e4f6584cSmrg# Assumes file is an ltwrapper_executable
2812e4f6584cSmrg# uses $file to determine the appropriate filename for a
2813e4f6584cSmrg# temporary ltwrapper_script.
2814e4f6584cSmrgfunc_ltwrapper_scriptname ()
2815e4f6584cSmrg{
2816b12e5c03Smrg    func_dirname_and_basename "$1" "" "."
2817b12e5c03Smrg    func_stripname '' '.exe' "$func_basename_result"
2818f395c03eSmrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
2819e4f6584cSmrg}
2820e4f6584cSmrg
2821e4f6584cSmrg# func_ltwrapper_p file
2822e4f6584cSmrg# True iff FILE is a libtool wrapper script or wrapper executable
2823e4f6584cSmrg# This function is only a basic sanity check; it will hardly flush out
2824e4f6584cSmrg# determined imposters.
2825e4f6584cSmrgfunc_ltwrapper_p ()
2826e4f6584cSmrg{
2827e4f6584cSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
2828e4f6584cSmrg}
2829e4f6584cSmrg
2830e4f6584cSmrg
2831e4f6584cSmrg# func_execute_cmds commands fail_cmd
2832e4f6584cSmrg# Execute tilde-delimited COMMANDS.
2833e4f6584cSmrg# If FAIL_CMD is given, eval that upon failure.
2834e4f6584cSmrg# FAIL_CMD may read-access the current command in variable CMD!
2835e4f6584cSmrgfunc_execute_cmds ()
2836e4f6584cSmrg{
2837f395c03eSmrg    $debug_cmd
2838f395c03eSmrg
2839e4f6584cSmrg    save_ifs=$IFS; IFS='~'
2840e4f6584cSmrg    for cmd in $1; do
2841f395c03eSmrg      IFS=$sp$nl
2842e4f6584cSmrg      eval cmd=\"$cmd\"
2843f395c03eSmrg      IFS=$save_ifs
2844e4f6584cSmrg      func_show_eval "$cmd" "${2-:}"
2845e4f6584cSmrg    done
2846e4f6584cSmrg    IFS=$save_ifs
2847e4f6584cSmrg}
2848e4f6584cSmrg
2849e4f6584cSmrg
2850e4f6584cSmrg# func_source file
2851e4f6584cSmrg# Source FILE, adding directory component if necessary.
2852e4f6584cSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
2853e4f6584cSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
2854e4f6584cSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2855f395c03eSmrg# 'FILE.' does not work on cygwin managed mounts.
2856e4f6584cSmrgfunc_source ()
2857e4f6584cSmrg{
2858f395c03eSmrg    $debug_cmd
2859f395c03eSmrg
2860e4f6584cSmrg    case $1 in
2861e4f6584cSmrg    */* | *\\*)	. "$1" ;;
2862e4f6584cSmrg    *)		. "./$1" ;;
2863e4f6584cSmrg    esac
2864e4f6584cSmrg}
2865e4f6584cSmrg
2866e4f6584cSmrg
2867b12e5c03Smrg# func_resolve_sysroot PATH
2868b12e5c03Smrg# Replace a leading = in PATH with a sysroot.  Store the result into
2869b12e5c03Smrg# func_resolve_sysroot_result
2870b12e5c03Smrgfunc_resolve_sysroot ()
2871b12e5c03Smrg{
2872b12e5c03Smrg  func_resolve_sysroot_result=$1
2873b12e5c03Smrg  case $func_resolve_sysroot_result in
2874b12e5c03Smrg  =*)
2875b12e5c03Smrg    func_stripname '=' '' "$func_resolve_sysroot_result"
2876b12e5c03Smrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
2877b12e5c03Smrg    ;;
2878b12e5c03Smrg  esac
2879b12e5c03Smrg}
2880b12e5c03Smrg
2881b12e5c03Smrg# func_replace_sysroot PATH
2882b12e5c03Smrg# If PATH begins with the sysroot, replace it with = and
2883b12e5c03Smrg# store the result into func_replace_sysroot_result.
2884b12e5c03Smrgfunc_replace_sysroot ()
2885b12e5c03Smrg{
2886f395c03eSmrg  case $lt_sysroot:$1 in
2887b12e5c03Smrg  ?*:"$lt_sysroot"*)
2888b12e5c03Smrg    func_stripname "$lt_sysroot" '' "$1"
2889f395c03eSmrg    func_replace_sysroot_result='='$func_stripname_result
2890b12e5c03Smrg    ;;
2891b12e5c03Smrg  *)
2892b12e5c03Smrg    # Including no sysroot.
2893b12e5c03Smrg    func_replace_sysroot_result=$1
2894b12e5c03Smrg    ;;
2895b12e5c03Smrg  esac
2896b12e5c03Smrg}
2897b12e5c03Smrg
2898e4f6584cSmrg# func_infer_tag arg
2899e4f6584cSmrg# Infer tagged configuration to use if any are available and
2900e4f6584cSmrg# if one wasn't chosen via the "--tag" command line option.
2901e4f6584cSmrg# Only attempt this if the compiler in the base compile
2902e4f6584cSmrg# command doesn't match the default compiler.
2903e4f6584cSmrg# arg is usually of the form 'gcc ...'
2904e4f6584cSmrgfunc_infer_tag ()
2905e4f6584cSmrg{
2906f395c03eSmrg    $debug_cmd
2907f395c03eSmrg
2908e4f6584cSmrg    if test -n "$available_tags" && test -z "$tagname"; then
2909e4f6584cSmrg      CC_quoted=
2910e4f6584cSmrg      for arg in $CC; do
2911b12e5c03Smrg	func_append_quoted CC_quoted "$arg"
2912e4f6584cSmrg      done
2913b12e5c03Smrg      CC_expanded=`func_echo_all $CC`
2914b12e5c03Smrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
2915e4f6584cSmrg      case $@ in
2916e4f6584cSmrg      # Blanks in the command may have been stripped by the calling shell,
2917e4f6584cSmrg      # but not from the CC environment variable when configure was run.
2918b12e5c03Smrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2919b12e5c03Smrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
2920e4f6584cSmrg      # Blanks at the start of $base_compile will cause this to fail
2921e4f6584cSmrg      # if we don't check for them as well.
2922e4f6584cSmrg      *)
2923e4f6584cSmrg	for z in $available_tags; do
2924e4f6584cSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
2925e4f6584cSmrg	    # Evaluate the configuration.
2926f395c03eSmrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
2927e4f6584cSmrg	    CC_quoted=
2928e4f6584cSmrg	    for arg in $CC; do
2929e4f6584cSmrg	      # Double-quote args containing other shell metacharacters.
2930b12e5c03Smrg	      func_append_quoted CC_quoted "$arg"
2931e4f6584cSmrg	    done
2932b12e5c03Smrg	    CC_expanded=`func_echo_all $CC`
2933b12e5c03Smrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
2934e4f6584cSmrg	    case "$@ " in
2935b12e5c03Smrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2936b12e5c03Smrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
2937e4f6584cSmrg	      # The compiler in the base compile command matches
2938e4f6584cSmrg	      # the one in the tagged configuration.
2939e4f6584cSmrg	      # Assume this is the tagged configuration we want.
2940e4f6584cSmrg	      tagname=$z
2941e4f6584cSmrg	      break
2942e4f6584cSmrg	      ;;
2943e4f6584cSmrg	    esac
2944e4f6584cSmrg	  fi
2945e4f6584cSmrg	done
2946e4f6584cSmrg	# If $tagname still isn't set, then no tagged configuration
2947e4f6584cSmrg	# was found and let the user know that the "--tag" command
2948e4f6584cSmrg	# line option must be used.
2949e4f6584cSmrg	if test -z "$tagname"; then
2950e4f6584cSmrg	  func_echo "unable to infer tagged configuration"
2951f395c03eSmrg	  func_fatal_error "specify a tag with '--tag'"
2952e4f6584cSmrg#	else
2953e4f6584cSmrg#	  func_verbose "using $tagname tagged configuration"
2954e4f6584cSmrg	fi
2955e4f6584cSmrg	;;
2956e4f6584cSmrg      esac
2957e4f6584cSmrg    fi
2958e4f6584cSmrg}
2959e4f6584cSmrg
2960e4f6584cSmrg
2961e4f6584cSmrg
2962e4f6584cSmrg# func_write_libtool_object output_name pic_name nonpic_name
2963e4f6584cSmrg# Create a libtool object file (analogous to a ".la" file),
2964e4f6584cSmrg# but don't create it if we're doing a dry run.
2965e4f6584cSmrgfunc_write_libtool_object ()
2966e4f6584cSmrg{
2967f395c03eSmrg    write_libobj=$1
2968f395c03eSmrg    if test yes = "$build_libtool_libs"; then
2969f395c03eSmrg      write_lobj=\'$2\'
2970e4f6584cSmrg    else
2971e4f6584cSmrg      write_lobj=none
2972e4f6584cSmrg    fi
2973e4f6584cSmrg
2974f395c03eSmrg    if test yes = "$build_old_libs"; then
2975f395c03eSmrg      write_oldobj=\'$3\'
2976e4f6584cSmrg    else
2977e4f6584cSmrg      write_oldobj=none
2978e4f6584cSmrg    fi
2979e4f6584cSmrg
2980e4f6584cSmrg    $opt_dry_run || {
2981e4f6584cSmrg      cat >${write_libobj}T <<EOF
2982e4f6584cSmrg# $write_libobj - a libtool object file
2983f395c03eSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
2984e4f6584cSmrg#
2985e4f6584cSmrg# Please DO NOT delete this file!
2986e4f6584cSmrg# It is necessary for linking the library.
2987e4f6584cSmrg
2988e4f6584cSmrg# Name of the PIC object.
2989e4f6584cSmrgpic_object=$write_lobj
2990e4f6584cSmrg
2991e4f6584cSmrg# Name of the non-PIC object
2992e4f6584cSmrgnon_pic_object=$write_oldobj
2993e4f6584cSmrg
2994e4f6584cSmrgEOF
2995f395c03eSmrg      $MV "${write_libobj}T" "$write_libobj"
2996e4f6584cSmrg    }
2997e4f6584cSmrg}
2998e4f6584cSmrg
2999b12e5c03Smrg
3000b12e5c03Smrg##################################################
3001b12e5c03Smrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
3002b12e5c03Smrg##################################################
3003b12e5c03Smrg
3004b12e5c03Smrg# func_convert_core_file_wine_to_w32 ARG
3005b12e5c03Smrg# Helper function used by file name conversion functions when $build is *nix,
3006b12e5c03Smrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
3007b12e5c03Smrg# correctly configured wine environment available, with the winepath program
3008b12e5c03Smrg# in $build's $PATH.
3009b12e5c03Smrg#
3010b12e5c03Smrg# ARG is the $build file name to be converted to w32 format.
3011b12e5c03Smrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
3012b12e5c03Smrg# be empty on error (or when ARG is empty)
3013b12e5c03Smrgfunc_convert_core_file_wine_to_w32 ()
3014b12e5c03Smrg{
3015f395c03eSmrg  $debug_cmd
3016f395c03eSmrg
3017f395c03eSmrg  func_convert_core_file_wine_to_w32_result=$1
3018b12e5c03Smrg  if test -n "$1"; then
3019b12e5c03Smrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
3020b12e5c03Smrg    # are forced to check the contents of stdout. On the other hand, if the
3021b12e5c03Smrg    # command is not found, the shell will set an exit code of 127 and print
3022b12e5c03Smrg    # *an error message* to stdout. So we must check for both error code of
3023b12e5c03Smrg    # zero AND non-empty stdout, which explains the odd construction:
3024b12e5c03Smrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
3025f395c03eSmrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
3026b12e5c03Smrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
3027f395c03eSmrg        $SED -e "$sed_naive_backslashify"`
3028b12e5c03Smrg    else
3029b12e5c03Smrg      func_convert_core_file_wine_to_w32_result=
3030b12e5c03Smrg    fi
3031b12e5c03Smrg  fi
3032b12e5c03Smrg}
3033b12e5c03Smrg# end: func_convert_core_file_wine_to_w32
3034b12e5c03Smrg
3035b12e5c03Smrg
3036b12e5c03Smrg# func_convert_core_path_wine_to_w32 ARG
3037b12e5c03Smrg# Helper function used by path conversion functions when $build is *nix, and
3038b12e5c03Smrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
3039b12e5c03Smrg# configured wine environment available, with the winepath program in $build's
3040b12e5c03Smrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
3041b12e5c03Smrg#
3042b12e5c03Smrg# ARG is path to be converted from $build format to win32.
3043b12e5c03Smrg# Result is available in $func_convert_core_path_wine_to_w32_result.
3044b12e5c03Smrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
3045b12e5c03Smrg# are convertible, then the result may be empty.
3046b12e5c03Smrgfunc_convert_core_path_wine_to_w32 ()
3047b12e5c03Smrg{
3048f395c03eSmrg  $debug_cmd
3049f395c03eSmrg
3050b12e5c03Smrg  # unfortunately, winepath doesn't convert paths, only file names
3051f395c03eSmrg  func_convert_core_path_wine_to_w32_result=
3052b12e5c03Smrg  if test -n "$1"; then
3053b12e5c03Smrg    oldIFS=$IFS
3054b12e5c03Smrg    IFS=:
3055b12e5c03Smrg    for func_convert_core_path_wine_to_w32_f in $1; do
3056b12e5c03Smrg      IFS=$oldIFS
3057b12e5c03Smrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
3058f395c03eSmrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
3059b12e5c03Smrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
3060f395c03eSmrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
3061b12e5c03Smrg        else
3062b12e5c03Smrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
3063b12e5c03Smrg        fi
3064b12e5c03Smrg      fi
3065b12e5c03Smrg    done
3066b12e5c03Smrg    IFS=$oldIFS
3067b12e5c03Smrg  fi
3068b12e5c03Smrg}
3069b12e5c03Smrg# end: func_convert_core_path_wine_to_w32
3070b12e5c03Smrg
3071b12e5c03Smrg
3072b12e5c03Smrg# func_cygpath ARGS...
3073b12e5c03Smrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
3074b12e5c03Smrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
3075b12e5c03Smrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
3076b12e5c03Smrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
3077b12e5c03Smrg# file name or path is assumed to be in w32 format, as previously converted
3078b12e5c03Smrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
3079b12e5c03Smrg# or path in func_cygpath_result (input file name or path is assumed to be in
3080b12e5c03Smrg# Cygwin format). Returns an empty string on error.
3081b12e5c03Smrg#
3082b12e5c03Smrg# ARGS are passed to cygpath, with the last one being the file name or path to
3083b12e5c03Smrg# be converted.
3084b12e5c03Smrg#
3085b12e5c03Smrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
3086b12e5c03Smrg# environment variable; do not put it in $PATH.
3087b12e5c03Smrgfunc_cygpath ()
3088b12e5c03Smrg{
3089f395c03eSmrg  $debug_cmd
3090f395c03eSmrg
3091b12e5c03Smrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
3092b12e5c03Smrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
3093b12e5c03Smrg    if test "$?" -ne 0; then
3094b12e5c03Smrg      # on failure, ensure result is empty
3095b12e5c03Smrg      func_cygpath_result=
3096b12e5c03Smrg    fi
3097b12e5c03Smrg  else
3098b12e5c03Smrg    func_cygpath_result=
3099f395c03eSmrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
3100b12e5c03Smrg  fi
3101b12e5c03Smrg}
3102b12e5c03Smrg#end: func_cygpath
3103b12e5c03Smrg
3104b12e5c03Smrg
3105b12e5c03Smrg# func_convert_core_msys_to_w32 ARG
3106b12e5c03Smrg# Convert file name or path ARG from MSYS format to w32 format.  Return
3107b12e5c03Smrg# result in func_convert_core_msys_to_w32_result.
3108b12e5c03Smrgfunc_convert_core_msys_to_w32 ()
3109b12e5c03Smrg{
3110f395c03eSmrg  $debug_cmd
3111f395c03eSmrg
3112b12e5c03Smrg  # awkward: cmd appends spaces to result
3113b12e5c03Smrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
3114f395c03eSmrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
3115b12e5c03Smrg}
3116b12e5c03Smrg#end: func_convert_core_msys_to_w32
3117b12e5c03Smrg
3118b12e5c03Smrg
3119b12e5c03Smrg# func_convert_file_check ARG1 ARG2
3120b12e5c03Smrg# Verify that ARG1 (a file name in $build format) was converted to $host
3121b12e5c03Smrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
3122b12e5c03Smrg# func_to_host_file_result to ARG1).
3123b12e5c03Smrgfunc_convert_file_check ()
3124b12e5c03Smrg{
3125f395c03eSmrg  $debug_cmd
3126f395c03eSmrg
3127f395c03eSmrg  if test -z "$2" && test -n "$1"; then
3128b12e5c03Smrg    func_error "Could not determine host file name corresponding to"
3129f395c03eSmrg    func_error "  '$1'"
3130b12e5c03Smrg    func_error "Continuing, but uninstalled executables may not work."
3131b12e5c03Smrg    # Fallback:
3132f395c03eSmrg    func_to_host_file_result=$1
3133b12e5c03Smrg  fi
3134b12e5c03Smrg}
3135b12e5c03Smrg# end func_convert_file_check
3136b12e5c03Smrg
3137b12e5c03Smrg
3138b12e5c03Smrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
3139b12e5c03Smrg# Verify that FROM_PATH (a path in $build format) was converted to $host
3140b12e5c03Smrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
3141b12e5c03Smrg# func_to_host_file_result to a simplistic fallback value (see below).
3142b12e5c03Smrgfunc_convert_path_check ()
3143b12e5c03Smrg{
3144f395c03eSmrg  $debug_cmd
3145f395c03eSmrg
3146b12e5c03Smrg  if test -z "$4" && test -n "$3"; then
3147b12e5c03Smrg    func_error "Could not determine the host path corresponding to"
3148f395c03eSmrg    func_error "  '$3'"
3149b12e5c03Smrg    func_error "Continuing, but uninstalled executables may not work."
3150b12e5c03Smrg    # Fallback.  This is a deliberately simplistic "conversion" and
3151b12e5c03Smrg    # should not be "improved".  See libtool.info.
3152b12e5c03Smrg    if test "x$1" != "x$2"; then
3153b12e5c03Smrg      lt_replace_pathsep_chars="s|$1|$2|g"
3154b12e5c03Smrg      func_to_host_path_result=`echo "$3" |
3155b12e5c03Smrg        $SED -e "$lt_replace_pathsep_chars"`
3156b12e5c03Smrg    else
3157f395c03eSmrg      func_to_host_path_result=$3
3158b12e5c03Smrg    fi
3159b12e5c03Smrg  fi
3160b12e5c03Smrg}
3161b12e5c03Smrg# end func_convert_path_check
3162b12e5c03Smrg
3163b12e5c03Smrg
3164b12e5c03Smrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
3165b12e5c03Smrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
3166b12e5c03Smrg# and appending REPL if ORIG matches BACKPAT.
3167b12e5c03Smrgfunc_convert_path_front_back_pathsep ()
3168b12e5c03Smrg{
3169f395c03eSmrg  $debug_cmd
3170f395c03eSmrg
3171b12e5c03Smrg  case $4 in
3172f395c03eSmrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
3173b12e5c03Smrg    ;;
3174b12e5c03Smrg  esac
3175b12e5c03Smrg  case $4 in
3176b12e5c03Smrg  $2 ) func_append func_to_host_path_result "$3"
3177b12e5c03Smrg    ;;
3178b12e5c03Smrg  esac
3179b12e5c03Smrg}
3180b12e5c03Smrg# end func_convert_path_front_back_pathsep
3181b12e5c03Smrg
3182b12e5c03Smrg
3183b12e5c03Smrg##################################################
3184b12e5c03Smrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
3185b12e5c03Smrg##################################################
3186f395c03eSmrg# invoked via '$to_host_file_cmd ARG'
3187b12e5c03Smrg#
3188b12e5c03Smrg# In each case, ARG is the path to be converted from $build to $host format.
3189b12e5c03Smrg# Result will be available in $func_to_host_file_result.
3190b12e5c03Smrg
3191b12e5c03Smrg
3192b12e5c03Smrg# func_to_host_file ARG
3193b12e5c03Smrg# Converts the file name ARG from $build format to $host format. Return result
3194b12e5c03Smrg# in func_to_host_file_result.
3195b12e5c03Smrgfunc_to_host_file ()
3196b12e5c03Smrg{
3197f395c03eSmrg  $debug_cmd
3198f395c03eSmrg
3199b12e5c03Smrg  $to_host_file_cmd "$1"
3200b12e5c03Smrg}
3201b12e5c03Smrg# end func_to_host_file
3202b12e5c03Smrg
3203b12e5c03Smrg
3204b12e5c03Smrg# func_to_tool_file ARG LAZY
3205b12e5c03Smrg# converts the file name ARG from $build format to toolchain format. Return
3206b12e5c03Smrg# result in func_to_tool_file_result.  If the conversion in use is listed
3207b12e5c03Smrg# in (the comma separated) LAZY, no conversion takes place.
3208b12e5c03Smrgfunc_to_tool_file ()
3209b12e5c03Smrg{
3210f395c03eSmrg  $debug_cmd
3211f395c03eSmrg
3212b12e5c03Smrg  case ,$2, in
3213b12e5c03Smrg    *,"$to_tool_file_cmd",*)
3214b12e5c03Smrg      func_to_tool_file_result=$1
3215b12e5c03Smrg      ;;
3216b12e5c03Smrg    *)
3217b12e5c03Smrg      $to_tool_file_cmd "$1"
3218b12e5c03Smrg      func_to_tool_file_result=$func_to_host_file_result
3219b12e5c03Smrg      ;;
3220b12e5c03Smrg  esac
3221b12e5c03Smrg}
3222b12e5c03Smrg# end func_to_tool_file
3223b12e5c03Smrg
3224b12e5c03Smrg
3225b12e5c03Smrg# func_convert_file_noop ARG
3226b12e5c03Smrg# Copy ARG to func_to_host_file_result.
3227b12e5c03Smrgfunc_convert_file_noop ()
3228b12e5c03Smrg{
3229f395c03eSmrg  func_to_host_file_result=$1
3230b12e5c03Smrg}
3231b12e5c03Smrg# end func_convert_file_noop
3232b12e5c03Smrg
3233b12e5c03Smrg
3234b12e5c03Smrg# func_convert_file_msys_to_w32 ARG
3235b12e5c03Smrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
3236b12e5c03Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3237b12e5c03Smrg# func_to_host_file_result.
3238b12e5c03Smrgfunc_convert_file_msys_to_w32 ()
3239b12e5c03Smrg{
3240f395c03eSmrg  $debug_cmd
3241f395c03eSmrg
3242f395c03eSmrg  func_to_host_file_result=$1
3243b12e5c03Smrg  if test -n "$1"; then
3244b12e5c03Smrg    func_convert_core_msys_to_w32 "$1"
3245f395c03eSmrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
3246b12e5c03Smrg  fi
3247b12e5c03Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3248b12e5c03Smrg}
3249b12e5c03Smrg# end func_convert_file_msys_to_w32
3250b12e5c03Smrg
3251b12e5c03Smrg
3252b12e5c03Smrg# func_convert_file_cygwin_to_w32 ARG
3253b12e5c03Smrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
3254b12e5c03Smrg# func_to_host_file_result.
3255b12e5c03Smrgfunc_convert_file_cygwin_to_w32 ()
3256b12e5c03Smrg{
3257f395c03eSmrg  $debug_cmd
3258f395c03eSmrg
3259f395c03eSmrg  func_to_host_file_result=$1
3260b12e5c03Smrg  if test -n "$1"; then
3261b12e5c03Smrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
3262b12e5c03Smrg    # LT_CYGPATH in this case.
3263b12e5c03Smrg    func_to_host_file_result=`cygpath -m "$1"`
3264b12e5c03Smrg  fi
3265b12e5c03Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3266b12e5c03Smrg}
3267b12e5c03Smrg# end func_convert_file_cygwin_to_w32
3268b12e5c03Smrg
3269b12e5c03Smrg
3270b12e5c03Smrg# func_convert_file_nix_to_w32 ARG
3271b12e5c03Smrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
3272b12e5c03Smrg# and a working winepath. Returns result in func_to_host_file_result.
3273b12e5c03Smrgfunc_convert_file_nix_to_w32 ()
3274b12e5c03Smrg{
3275f395c03eSmrg  $debug_cmd
3276f395c03eSmrg
3277f395c03eSmrg  func_to_host_file_result=$1
3278b12e5c03Smrg  if test -n "$1"; then
3279b12e5c03Smrg    func_convert_core_file_wine_to_w32 "$1"
3280f395c03eSmrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
3281b12e5c03Smrg  fi
3282b12e5c03Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3283b12e5c03Smrg}
3284b12e5c03Smrg# end func_convert_file_nix_to_w32
3285b12e5c03Smrg
3286b12e5c03Smrg
3287b12e5c03Smrg# func_convert_file_msys_to_cygwin ARG
3288b12e5c03Smrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3289b12e5c03Smrg# Returns result in func_to_host_file_result.
3290b12e5c03Smrgfunc_convert_file_msys_to_cygwin ()
3291b12e5c03Smrg{
3292f395c03eSmrg  $debug_cmd
3293f395c03eSmrg
3294f395c03eSmrg  func_to_host_file_result=$1
3295b12e5c03Smrg  if test -n "$1"; then
3296b12e5c03Smrg    func_convert_core_msys_to_w32 "$1"
3297b12e5c03Smrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3298f395c03eSmrg    func_to_host_file_result=$func_cygpath_result
3299b12e5c03Smrg  fi
3300b12e5c03Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3301b12e5c03Smrg}
3302b12e5c03Smrg# end func_convert_file_msys_to_cygwin
3303b12e5c03Smrg
3304b12e5c03Smrg
3305b12e5c03Smrg# func_convert_file_nix_to_cygwin ARG
3306b12e5c03Smrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
3307b12e5c03Smrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
3308b12e5c03Smrg# in func_to_host_file_result.
3309b12e5c03Smrgfunc_convert_file_nix_to_cygwin ()
3310b12e5c03Smrg{
3311f395c03eSmrg  $debug_cmd
3312f395c03eSmrg
3313f395c03eSmrg  func_to_host_file_result=$1
3314b12e5c03Smrg  if test -n "$1"; then
3315b12e5c03Smrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
3316b12e5c03Smrg    func_convert_core_file_wine_to_w32 "$1"
3317b12e5c03Smrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3318f395c03eSmrg    func_to_host_file_result=$func_cygpath_result
3319b12e5c03Smrg  fi
3320b12e5c03Smrg  func_convert_file_check "$1" "$func_to_host_file_result"
3321b12e5c03Smrg}
3322b12e5c03Smrg# end func_convert_file_nix_to_cygwin
3323b12e5c03Smrg
3324b12e5c03Smrg
3325b12e5c03Smrg#############################################
3326b12e5c03Smrg# $build to $host PATH CONVERSION FUNCTIONS #
3327b12e5c03Smrg#############################################
3328f395c03eSmrg# invoked via '$to_host_path_cmd ARG'
3329b12e5c03Smrg#
3330b12e5c03Smrg# In each case, ARG is the path to be converted from $build to $host format.
3331b12e5c03Smrg# The result will be available in $func_to_host_path_result.
3332b12e5c03Smrg#
3333b12e5c03Smrg# Path separators are also converted from $build format to $host format.  If
3334b12e5c03Smrg# ARG begins or ends with a path separator character, it is preserved (but
3335b12e5c03Smrg# converted to $host format) on output.
3336b12e5c03Smrg#
3337b12e5c03Smrg# All path conversion functions are named using the following convention:
3338b12e5c03Smrg#   file name conversion function    : func_convert_file_X_to_Y ()
3339b12e5c03Smrg#   path conversion function         : func_convert_path_X_to_Y ()
3340b12e5c03Smrg# where, for any given $build/$host combination the 'X_to_Y' value is the
3341b12e5c03Smrg# same.  If conversion functions are added for new $build/$host combinations,
3342b12e5c03Smrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
3343b12e5c03Smrg# will break.
3344b12e5c03Smrg
3345b12e5c03Smrg
3346b12e5c03Smrg# func_init_to_host_path_cmd
3347b12e5c03Smrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
3348b12e5c03Smrg# appropriate value, based on the value of $to_host_file_cmd.
3349b12e5c03Smrgto_host_path_cmd=
3350b12e5c03Smrgfunc_init_to_host_path_cmd ()
3351b12e5c03Smrg{
3352f395c03eSmrg  $debug_cmd
3353f395c03eSmrg
3354b12e5c03Smrg  if test -z "$to_host_path_cmd"; then
3355b12e5c03Smrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3356f395c03eSmrg    to_host_path_cmd=func_convert_path_$func_stripname_result
3357b12e5c03Smrg  fi
3358b12e5c03Smrg}
3359b12e5c03Smrg
3360b12e5c03Smrg
3361b12e5c03Smrg# func_to_host_path ARG
3362b12e5c03Smrg# Converts the path ARG from $build format to $host format. Return result
3363b12e5c03Smrg# in func_to_host_path_result.
3364b12e5c03Smrgfunc_to_host_path ()
3365b12e5c03Smrg{
3366f395c03eSmrg  $debug_cmd
3367f395c03eSmrg
3368b12e5c03Smrg  func_init_to_host_path_cmd
3369b12e5c03Smrg  $to_host_path_cmd "$1"
3370b12e5c03Smrg}
3371b12e5c03Smrg# end func_to_host_path
3372b12e5c03Smrg
3373b12e5c03Smrg
3374b12e5c03Smrg# func_convert_path_noop ARG
3375b12e5c03Smrg# Copy ARG to func_to_host_path_result.
3376b12e5c03Smrgfunc_convert_path_noop ()
3377b12e5c03Smrg{
3378f395c03eSmrg  func_to_host_path_result=$1
3379b12e5c03Smrg}
3380b12e5c03Smrg# end func_convert_path_noop
3381b12e5c03Smrg
3382b12e5c03Smrg
3383b12e5c03Smrg# func_convert_path_msys_to_w32 ARG
3384b12e5c03Smrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
3385b12e5c03Smrg# conversion to w32 is not available inside the cwrapper.  Returns result in
3386b12e5c03Smrg# func_to_host_path_result.
3387b12e5c03Smrgfunc_convert_path_msys_to_w32 ()
3388b12e5c03Smrg{
3389f395c03eSmrg  $debug_cmd
3390f395c03eSmrg
3391f395c03eSmrg  func_to_host_path_result=$1
3392b12e5c03Smrg  if test -n "$1"; then
3393b12e5c03Smrg    # Remove leading and trailing path separator characters from ARG.  MSYS
3394b12e5c03Smrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
3395b12e5c03Smrg    # and winepath ignores them completely.
3396b12e5c03Smrg    func_stripname : : "$1"
3397b12e5c03Smrg    func_to_host_path_tmp1=$func_stripname_result
3398b12e5c03Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3399f395c03eSmrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
3400b12e5c03Smrg    func_convert_path_check : ";" \
3401b12e5c03Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3402b12e5c03Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3403b12e5c03Smrg  fi
3404b12e5c03Smrg}
3405b12e5c03Smrg# end func_convert_path_msys_to_w32
3406b12e5c03Smrg
3407b12e5c03Smrg
3408b12e5c03Smrg# func_convert_path_cygwin_to_w32 ARG
3409b12e5c03Smrg# Convert path ARG from Cygwin to w32 format.  Returns result in
3410b12e5c03Smrg# func_to_host_file_result.
3411b12e5c03Smrgfunc_convert_path_cygwin_to_w32 ()
3412b12e5c03Smrg{
3413f395c03eSmrg  $debug_cmd
3414f395c03eSmrg
3415f395c03eSmrg  func_to_host_path_result=$1
3416b12e5c03Smrg  if test -n "$1"; then
3417b12e5c03Smrg    # See func_convert_path_msys_to_w32:
3418b12e5c03Smrg    func_stripname : : "$1"
3419b12e5c03Smrg    func_to_host_path_tmp1=$func_stripname_result
3420b12e5c03Smrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
3421b12e5c03Smrg    func_convert_path_check : ";" \
3422b12e5c03Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3423b12e5c03Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3424b12e5c03Smrg  fi
3425b12e5c03Smrg}
3426b12e5c03Smrg# end func_convert_path_cygwin_to_w32
3427b12e5c03Smrg
3428b12e5c03Smrg
3429b12e5c03Smrg# func_convert_path_nix_to_w32 ARG
3430b12e5c03Smrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
3431b12e5c03Smrg# a working winepath.  Returns result in func_to_host_file_result.
3432b12e5c03Smrgfunc_convert_path_nix_to_w32 ()
3433b12e5c03Smrg{
3434f395c03eSmrg  $debug_cmd
3435f395c03eSmrg
3436f395c03eSmrg  func_to_host_path_result=$1
3437b12e5c03Smrg  if test -n "$1"; then
3438b12e5c03Smrg    # See func_convert_path_msys_to_w32:
3439b12e5c03Smrg    func_stripname : : "$1"
3440b12e5c03Smrg    func_to_host_path_tmp1=$func_stripname_result
3441b12e5c03Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3442f395c03eSmrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
3443b12e5c03Smrg    func_convert_path_check : ";" \
3444b12e5c03Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3445b12e5c03Smrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
3446b12e5c03Smrg  fi
3447b12e5c03Smrg}
3448b12e5c03Smrg# end func_convert_path_nix_to_w32
3449b12e5c03Smrg
3450b12e5c03Smrg
3451b12e5c03Smrg# func_convert_path_msys_to_cygwin ARG
3452b12e5c03Smrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
3453b12e5c03Smrg# Returns result in func_to_host_file_result.
3454b12e5c03Smrgfunc_convert_path_msys_to_cygwin ()
3455b12e5c03Smrg{
3456f395c03eSmrg  $debug_cmd
3457f395c03eSmrg
3458f395c03eSmrg  func_to_host_path_result=$1
3459b12e5c03Smrg  if test -n "$1"; then
3460b12e5c03Smrg    # See func_convert_path_msys_to_w32:
3461b12e5c03Smrg    func_stripname : : "$1"
3462b12e5c03Smrg    func_to_host_path_tmp1=$func_stripname_result
3463b12e5c03Smrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3464b12e5c03Smrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3465f395c03eSmrg    func_to_host_path_result=$func_cygpath_result
3466b12e5c03Smrg    func_convert_path_check : : \
3467b12e5c03Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3468b12e5c03Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3469b12e5c03Smrg  fi
3470b12e5c03Smrg}
3471b12e5c03Smrg# end func_convert_path_msys_to_cygwin
3472b12e5c03Smrg
3473b12e5c03Smrg
3474b12e5c03Smrg# func_convert_path_nix_to_cygwin ARG
3475b12e5c03Smrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
3476b12e5c03Smrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
3477b12e5c03Smrg# func_to_host_file_result.
3478b12e5c03Smrgfunc_convert_path_nix_to_cygwin ()
3479b12e5c03Smrg{
3480f395c03eSmrg  $debug_cmd
3481f395c03eSmrg
3482f395c03eSmrg  func_to_host_path_result=$1
3483b12e5c03Smrg  if test -n "$1"; then
3484b12e5c03Smrg    # Remove leading and trailing path separator characters from
3485b12e5c03Smrg    # ARG. msys behavior is inconsistent here, cygpath turns them
3486b12e5c03Smrg    # into '.;' and ';.', and winepath ignores them completely.
3487b12e5c03Smrg    func_stripname : : "$1"
3488b12e5c03Smrg    func_to_host_path_tmp1=$func_stripname_result
3489b12e5c03Smrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3490b12e5c03Smrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3491f395c03eSmrg    func_to_host_path_result=$func_cygpath_result
3492b12e5c03Smrg    func_convert_path_check : : \
3493b12e5c03Smrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
3494b12e5c03Smrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
3495b12e5c03Smrg  fi
3496b12e5c03Smrg}
3497b12e5c03Smrg# end func_convert_path_nix_to_cygwin
3498b12e5c03Smrg
3499b12e5c03Smrg
3500f395c03eSmrg# func_dll_def_p FILE
3501f395c03eSmrg# True iff FILE is a Windows DLL '.def' file.
3502f395c03eSmrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3503f395c03eSmrgfunc_dll_def_p ()
3504f395c03eSmrg{
3505f395c03eSmrg  $debug_cmd
3506f395c03eSmrg
3507f395c03eSmrg  func_dll_def_p_tmp=`$SED -n \
3508f395c03eSmrg    -e 's/^[	 ]*//' \
3509f395c03eSmrg    -e '/^\(;.*\)*$/d' \
3510f395c03eSmrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3511f395c03eSmrg    -e q \
3512f395c03eSmrg    "$1"`
3513f395c03eSmrg  test DEF = "$func_dll_def_p_tmp"
3514f395c03eSmrg}
3515f395c03eSmrg
3516f395c03eSmrg
3517e4f6584cSmrg# func_mode_compile arg...
3518e4f6584cSmrgfunc_mode_compile ()
3519e4f6584cSmrg{
3520f395c03eSmrg    $debug_cmd
3521f395c03eSmrg
3522e4f6584cSmrg    # Get the compilation command and the source file.
3523e4f6584cSmrg    base_compile=
3524f395c03eSmrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
3525e4f6584cSmrg    suppress_opt=yes
3526e4f6584cSmrg    suppress_output=
3527e4f6584cSmrg    arg_mode=normal
3528e4f6584cSmrg    libobj=
3529e4f6584cSmrg    later=
3530e4f6584cSmrg    pie_flag=
3531e4f6584cSmrg
3532e4f6584cSmrg    for arg
3533e4f6584cSmrg    do
3534e4f6584cSmrg      case $arg_mode in
3535e4f6584cSmrg      arg  )
3536e4f6584cSmrg	# do not "continue".  Instead, add this to base_compile
3537f395c03eSmrg	lastarg=$arg
3538e4f6584cSmrg	arg_mode=normal
3539e4f6584cSmrg	;;
3540e4f6584cSmrg
3541e4f6584cSmrg      target )
3542f395c03eSmrg	libobj=$arg
3543e4f6584cSmrg	arg_mode=normal
3544e4f6584cSmrg	continue
3545e4f6584cSmrg	;;
3546e4f6584cSmrg
3547e4f6584cSmrg      normal )
3548e4f6584cSmrg	# Accept any command-line options.
3549e4f6584cSmrg	case $arg in
3550e4f6584cSmrg	-o)
3551e4f6584cSmrg	  test -n "$libobj" && \
3552f395c03eSmrg	    func_fatal_error "you cannot specify '-o' more than once"
3553e4f6584cSmrg	  arg_mode=target
3554e4f6584cSmrg	  continue
3555e4f6584cSmrg	  ;;
3556e4f6584cSmrg
3557e4f6584cSmrg	-pie | -fpie | -fPIE)
3558b12e5c03Smrg          func_append pie_flag " $arg"
3559e4f6584cSmrg	  continue
3560e4f6584cSmrg	  ;;
3561e4f6584cSmrg
3562e4f6584cSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
3563b12e5c03Smrg	  func_append later " $arg"
3564e4f6584cSmrg	  continue
3565e4f6584cSmrg	  ;;
3566e4f6584cSmrg
3567e4f6584cSmrg	-no-suppress)
356809885543Smrg	  suppress_opt=no
356909885543Smrg	  continue
357009885543Smrg	  ;;
357109885543Smrg
357209885543Smrg	-Xcompiler)
357309885543Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
357409885543Smrg	  continue      #  The current "srcfile" will either be retained or
357509885543Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
357609885543Smrg
357709885543Smrg	-Wc,*)
3578e4f6584cSmrg	  func_stripname '-Wc,' '' "$arg"
3579e4f6584cSmrg	  args=$func_stripname_result
358009885543Smrg	  lastarg=
3581f395c03eSmrg	  save_ifs=$IFS; IFS=,
3582e4f6584cSmrg	  for arg in $args; do
3583f395c03eSmrg	    IFS=$save_ifs
3584b12e5c03Smrg	    func_append_quoted lastarg "$arg"
358509885543Smrg	  done
3586f395c03eSmrg	  IFS=$save_ifs
3587e4f6584cSmrg	  func_stripname ' ' '' "$lastarg"
3588e4f6584cSmrg	  lastarg=$func_stripname_result
358909885543Smrg
359009885543Smrg	  # Add the arguments to base_compile.
3591b12e5c03Smrg	  func_append base_compile " $lastarg"
359209885543Smrg	  continue
359309885543Smrg	  ;;
359409885543Smrg
3595e4f6584cSmrg	*)
359609885543Smrg	  # Accept the current argument as the source file.
359709885543Smrg	  # The previous "srcfile" becomes the current argument.
359809885543Smrg	  #
3599f395c03eSmrg	  lastarg=$srcfile
3600f395c03eSmrg	  srcfile=$arg
360109885543Smrg	  ;;
360209885543Smrg	esac  #  case $arg
360309885543Smrg	;;
360409885543Smrg      esac    #  case $arg_mode
360509885543Smrg
360609885543Smrg      # Aesthetically quote the previous argument.
3607b12e5c03Smrg      func_append_quoted base_compile "$lastarg"
360809885543Smrg    done # for arg
360909885543Smrg
361009885543Smrg    case $arg_mode in
361109885543Smrg    arg)
3612e4f6584cSmrg      func_fatal_error "you must specify an argument for -Xcompile"
361309885543Smrg      ;;
361409885543Smrg    target)
3615f395c03eSmrg      func_fatal_error "you must specify a target with '-o'"
361609885543Smrg      ;;
361709885543Smrg    *)
361809885543Smrg      # Get the name of the library object.
3619e4f6584cSmrg      test -z "$libobj" && {
3620e4f6584cSmrg	func_basename "$srcfile"
3621f395c03eSmrg	libobj=$func_basename_result
3622e4f6584cSmrg      }
362309885543Smrg      ;;
362409885543Smrg    esac
362509885543Smrg
362609885543Smrg    # Recognize several different file suffixes.
362709885543Smrg    # If the user specifies -o file.o, it is replaced with file.lo
362809885543Smrg    case $libobj in
3629e4f6584cSmrg    *.[cCFSifmso] | \
3630e4f6584cSmrg    *.ada | *.adb | *.ads | *.asm | \
3631e4f6584cSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
3632b12e5c03Smrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
3633e4f6584cSmrg      func_xform "$libobj"
3634e4f6584cSmrg      libobj=$func_xform_result
3635e4f6584cSmrg      ;;
363609885543Smrg    esac
363709885543Smrg
363809885543Smrg    case $libobj in
3639e4f6584cSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
364009885543Smrg    *)
3641f395c03eSmrg      func_fatal_error "cannot determine name of library object from '$libobj'"
364209885543Smrg      ;;
364309885543Smrg    esac
364409885543Smrg
364509885543Smrg    func_infer_tag $base_compile
364609885543Smrg
364709885543Smrg    for arg in $later; do
364809885543Smrg      case $arg in
3649e4f6584cSmrg      -shared)
3650f395c03eSmrg	test yes = "$build_libtool_libs" \
3651f395c03eSmrg	  || func_fatal_configuration "cannot build a shared library"
3652e4f6584cSmrg	build_old_libs=no
3653e4f6584cSmrg	continue
3654e4f6584cSmrg	;;
3655e4f6584cSmrg
365609885543Smrg      -static)
3657e4f6584cSmrg	build_libtool_libs=no
365809885543Smrg	build_old_libs=yes
365909885543Smrg	continue
366009885543Smrg	;;
366109885543Smrg
366209885543Smrg      -prefer-pic)
366309885543Smrg	pic_mode=yes
366409885543Smrg	continue
366509885543Smrg	;;
366609885543Smrg
366709885543Smrg      -prefer-non-pic)
366809885543Smrg	pic_mode=no
366909885543Smrg	continue
367009885543Smrg	;;
367109885543Smrg      esac
367209885543Smrg    done
367309885543Smrg
3674beef1b22Smrg    func_quote_arg pretty "$libobj"
3675beef1b22Smrg    test "X$libobj" != "X$func_quote_arg_result" \
3676e4f6584cSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3677f395c03eSmrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
3678e4f6584cSmrg    func_dirname_and_basename "$obj" "/" ""
3679f395c03eSmrg    objname=$func_basename_result
3680f395c03eSmrg    xdir=$func_dirname_result
3681f395c03eSmrg    lobj=$xdir$objdir/$objname
368209885543Smrg
3683e4f6584cSmrg    test -z "$base_compile" && \
3684e4f6584cSmrg      func_fatal_help "you must specify a compilation command"
368509885543Smrg
368609885543Smrg    # Delete any leftover library objects.
3687f395c03eSmrg    if test yes = "$build_old_libs"; then
368809885543Smrg      removelist="$obj $lobj $libobj ${libobj}T"
368909885543Smrg    else
369009885543Smrg      removelist="$lobj $libobj ${libobj}T"
369109885543Smrg    fi
369209885543Smrg
369309885543Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
369409885543Smrg    case $host_os in
3695e4f6584cSmrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
369609885543Smrg      pic_mode=default
369709885543Smrg      ;;
369809885543Smrg    esac
3699f395c03eSmrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
370009885543Smrg      # non-PIC code in shared libraries is not supported
370109885543Smrg      pic_mode=default
370209885543Smrg    fi
370309885543Smrg
370409885543Smrg    # Calculate the filename of the output object if compiler does
370509885543Smrg    # not support -o with -c
3706f395c03eSmrg    if test no = "$compiler_c_o"; then
3707f395c03eSmrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3708f395c03eSmrg      lockfile=$output_obj.lock
370909885543Smrg    else
371009885543Smrg      output_obj=
371109885543Smrg      need_locks=no
371209885543Smrg      lockfile=
371309885543Smrg    fi
371409885543Smrg
371509885543Smrg    # Lock this critical section if it is needed
371609885543Smrg    # We use this script file to make the link, it avoids creating a new file
3717f395c03eSmrg    if test yes = "$need_locks"; then
3718e4f6584cSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
3719e4f6584cSmrg	func_echo "Waiting for $lockfile to be removed"
372009885543Smrg	sleep 2
372109885543Smrg      done
3722f395c03eSmrg    elif test warn = "$need_locks"; then
372309885543Smrg      if test -f "$lockfile"; then
3724e4f6584cSmrg	$ECHO "\
372509885543Smrg*** ERROR, $lockfile exists and contains:
372609885543Smrg`cat $lockfile 2>/dev/null`
372709885543Smrg
372809885543SmrgThis indicates that another process is trying to use the same
372909885543Smrgtemporary object file, and libtool could not work around it because
3730f395c03eSmrgyour compiler does not support '-c' and '-o' together.  If you
373109885543Smrgrepeat this compilation, it may succeed, by chance, but you had better
373209885543Smrgavoid parallel builds (make -j) in this platform, or get a better
373309885543Smrgcompiler."
373409885543Smrg
3735e4f6584cSmrg	$opt_dry_run || $RM $removelist
373609885543Smrg	exit $EXIT_FAILURE
373709885543Smrg      fi
3738b12e5c03Smrg      func_append removelist " $output_obj"
3739e4f6584cSmrg      $ECHO "$srcfile" > "$lockfile"
374009885543Smrg    fi
374109885543Smrg
3742e4f6584cSmrg    $opt_dry_run || $RM $removelist
3743b12e5c03Smrg    func_append removelist " $lockfile"
3744e4f6584cSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
3745e4f6584cSmrg
3746b12e5c03Smrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
3747b12e5c03Smrg    srcfile=$func_to_tool_file_result
3748beef1b22Smrg    func_quote_arg pretty "$srcfile"
3749beef1b22Smrg    qsrcfile=$func_quote_arg_result
375009885543Smrg
375109885543Smrg    # Only build a PIC object if we are building libtool libraries.
3752f395c03eSmrg    if test yes = "$build_libtool_libs"; then
375309885543Smrg      # Without this assignment, base_compile gets emptied.
375409885543Smrg      fbsd_hideous_sh_bug=$base_compile
375509885543Smrg
3756f395c03eSmrg      if test no != "$pic_mode"; then
375709885543Smrg	command="$base_compile $qsrcfile $pic_flag"
375809885543Smrg      else
375909885543Smrg	# Don't build PIC code
376009885543Smrg	command="$base_compile $qsrcfile"
376109885543Smrg      fi
376209885543Smrg
3763e4f6584cSmrg      func_mkdir_p "$xdir$objdir"
376409885543Smrg
376509885543Smrg      if test -z "$output_obj"; then
376609885543Smrg	# Place PIC objects in $objdir
3767b12e5c03Smrg	func_append command " -o $lobj"
376809885543Smrg      fi
376909885543Smrg
3770e4f6584cSmrg      func_show_eval_locale "$command"	\
3771e4f6584cSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
377209885543Smrg
3773f395c03eSmrg      if test warn = "$need_locks" &&
377409885543Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3775e4f6584cSmrg	$ECHO "\
377609885543Smrg*** ERROR, $lockfile contains:
377709885543Smrg`cat $lockfile 2>/dev/null`
377809885543Smrg
377909885543Smrgbut it should contain:
378009885543Smrg$srcfile
378109885543Smrg
378209885543SmrgThis indicates that another process is trying to use the same
378309885543Smrgtemporary object file, and libtool could not work around it because
3784f395c03eSmrgyour compiler does not support '-c' and '-o' together.  If you
378509885543Smrgrepeat this compilation, it may succeed, by chance, but you had better
378609885543Smrgavoid parallel builds (make -j) in this platform, or get a better
378709885543Smrgcompiler."
378809885543Smrg
3789e4f6584cSmrg	$opt_dry_run || $RM $removelist
379009885543Smrg	exit $EXIT_FAILURE
379109885543Smrg      fi
379209885543Smrg
379309885543Smrg      # Just move the object if needed, then go on to compile the next one
379409885543Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
3795e4f6584cSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
3796e4f6584cSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
379709885543Smrg      fi
379809885543Smrg
379909885543Smrg      # Allow error messages only from the first compilation.
3800f395c03eSmrg      if test yes = "$suppress_opt"; then
3801e4f6584cSmrg	suppress_output=' >/dev/null 2>&1'
380209885543Smrg      fi
380309885543Smrg    fi
380409885543Smrg
380509885543Smrg    # Only build a position-dependent object if we build old libraries.
3806f395c03eSmrg    if test yes = "$build_old_libs"; then
3807f395c03eSmrg      if test yes != "$pic_mode"; then
380809885543Smrg	# Don't build PIC code
3809e4f6584cSmrg	command="$base_compile $qsrcfile$pie_flag"
381009885543Smrg      else
381109885543Smrg	command="$base_compile $qsrcfile $pic_flag"
381209885543Smrg      fi
3813f395c03eSmrg      if test yes = "$compiler_c_o"; then
3814b12e5c03Smrg	func_append command " -o $obj"
381509885543Smrg      fi
381609885543Smrg
381709885543Smrg      # Suppress compiler output if we already did a PIC compilation.
3818b12e5c03Smrg      func_append command "$suppress_output"
3819e4f6584cSmrg      func_show_eval_locale "$command" \
3820e4f6584cSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
382109885543Smrg
3822f395c03eSmrg      if test warn = "$need_locks" &&
382309885543Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
3824e4f6584cSmrg	$ECHO "\
382509885543Smrg*** ERROR, $lockfile contains:
382609885543Smrg`cat $lockfile 2>/dev/null`
382709885543Smrg
382809885543Smrgbut it should contain:
382909885543Smrg$srcfile
383009885543Smrg
383109885543SmrgThis indicates that another process is trying to use the same
383209885543Smrgtemporary object file, and libtool could not work around it because
3833f395c03eSmrgyour compiler does not support '-c' and '-o' together.  If you
383409885543Smrgrepeat this compilation, it may succeed, by chance, but you had better
383509885543Smrgavoid parallel builds (make -j) in this platform, or get a better
383609885543Smrgcompiler."
383709885543Smrg
3838e4f6584cSmrg	$opt_dry_run || $RM $removelist
383909885543Smrg	exit $EXIT_FAILURE
384009885543Smrg      fi
384109885543Smrg
384209885543Smrg      # Just move the object if needed
384309885543Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
3844e4f6584cSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
3845e4f6584cSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
384609885543Smrg      fi
384709885543Smrg    fi
384809885543Smrg
3849e4f6584cSmrg    $opt_dry_run || {
3850e4f6584cSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
385109885543Smrg
3852e4f6584cSmrg      # Unlock the critical section if it was locked
3853f395c03eSmrg      if test no != "$need_locks"; then
3854e4f6584cSmrg	removelist=$lockfile
3855e4f6584cSmrg        $RM "$lockfile"
3856e4f6584cSmrg      fi
3857e4f6584cSmrg    }
385809885543Smrg
385909885543Smrg    exit $EXIT_SUCCESS
3860e4f6584cSmrg}
386109885543Smrg
3862e4f6584cSmrg$opt_help || {
3863f395c03eSmrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
3864e4f6584cSmrg}
386509885543Smrg
3866e4f6584cSmrgfunc_mode_help ()
3867e4f6584cSmrg{
3868e4f6584cSmrg    # We need to display help for each of the modes.
3869b12e5c03Smrg    case $opt_mode in
3870e4f6584cSmrg      "")
3871e4f6584cSmrg        # Generic help is extracted from the usage comments
3872e4f6584cSmrg        # at the start of this file.
3873e4f6584cSmrg        func_help
3874e4f6584cSmrg        ;;
387509885543Smrg
3876e4f6584cSmrg      clean)
3877e4f6584cSmrg        $ECHO \
3878e4f6584cSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
387909885543Smrg
3880e4f6584cSmrgRemove files from the build directory.
388109885543Smrg
3882e4f6584cSmrgRM is the name of the program to use to delete files associated with each FILE
3883f395c03eSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
3884e4f6584cSmrgto RM.
388509885543Smrg
3886e4f6584cSmrgIf FILE is a libtool library, object or program, all the files associated
3887e4f6584cSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
3888e4f6584cSmrg        ;;
388909885543Smrg
3890e4f6584cSmrg      compile)
3891e4f6584cSmrg      $ECHO \
3892e4f6584cSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
389309885543Smrg
3894e4f6584cSmrgCompile a source file into a libtool library object.
389509885543Smrg
3896e4f6584cSmrgThis mode accepts the following additional options:
389709885543Smrg
3898e4f6584cSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
3899e4f6584cSmrg  -no-suppress      do not suppress compiler output for multiple passes
3900b12e5c03Smrg  -prefer-pic       try to build PIC objects only
3901b12e5c03Smrg  -prefer-non-pic   try to build non-PIC objects only
3902f395c03eSmrg  -shared           do not build a '.o' file suitable for static linking
3903f395c03eSmrg  -static           only build a '.o' file suitable for static linking
3904beef1b22Smrg  -Wc,FLAG
3905beef1b22Smrg  -Xcompiler FLAG   pass FLAG directly to the compiler
390609885543Smrg
3907f395c03eSmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
3908e4f6584cSmrgfrom the given SOURCEFILE.
390909885543Smrg
3910e4f6584cSmrgThe output file name is determined by removing the directory component from
3911f395c03eSmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3912f395c03eSmrglibrary object suffix, '.lo'."
3913e4f6584cSmrg        ;;
391409885543Smrg
3915e4f6584cSmrg      execute)
3916e4f6584cSmrg        $ECHO \
3917e4f6584cSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
391809885543Smrg
3919e4f6584cSmrgAutomatically set library path, then run a program.
392009885543Smrg
3921e4f6584cSmrgThis mode accepts the following additional options:
392209885543Smrg
3923e4f6584cSmrg  -dlopen FILE      add the directory containing FILE to the library path
392409885543Smrg
3925f395c03eSmrgThis mode sets the library path environment variable according to '-dlopen'
3926e4f6584cSmrgflags.
392709885543Smrg
3928e4f6584cSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
3929e4f6584cSmrginto their corresponding uninstalled binary, and any of their required library
3930e4f6584cSmrgdirectories are added to the library path.
393109885543Smrg
3932e4f6584cSmrgThen, COMMAND is executed, with ARGS as arguments."
3933e4f6584cSmrg        ;;
393409885543Smrg
3935e4f6584cSmrg      finish)
3936e4f6584cSmrg        $ECHO \
3937e4f6584cSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
393809885543Smrg
3939e4f6584cSmrgComplete the installation of libtool libraries.
394009885543Smrg
3941e4f6584cSmrgEach LIBDIR is a directory that contains libtool libraries.
394209885543Smrg
3943e4f6584cSmrgThe commands that this mode executes may require superuser privileges.  Use
3944f395c03eSmrgthe '--dry-run' option if you just want to see what would be executed."
3945e4f6584cSmrg        ;;
394609885543Smrg
3947e4f6584cSmrg      install)
3948e4f6584cSmrg        $ECHO \
3949e4f6584cSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
395009885543Smrg
3951e4f6584cSmrgInstall executables or libraries.
395209885543Smrg
3953e4f6584cSmrgINSTALL-COMMAND is the installation command.  The first component should be
3954f395c03eSmrgeither the 'install' or 'cp' program.
395509885543Smrg
3956e4f6584cSmrgThe following components of INSTALL-COMMAND are treated specially:
395709885543Smrg
3958b12e5c03Smrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
395909885543Smrg
3960e4f6584cSmrgThe rest of the components are interpreted as arguments to that command (only
3961e4f6584cSmrgBSD-compatible install options are recognized)."
3962e4f6584cSmrg        ;;
396309885543Smrg
3964e4f6584cSmrg      link)
3965e4f6584cSmrg        $ECHO \
3966e4f6584cSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
396709885543Smrg
3968e4f6584cSmrgLink object files or libraries together to form another library, or to
3969e4f6584cSmrgcreate an executable program.
397009885543Smrg
3971e4f6584cSmrgLINK-COMMAND is a command using the C compiler that you would use to create
3972e4f6584cSmrga program from several object files.
397309885543Smrg
3974e4f6584cSmrgThe following components of LINK-COMMAND are treated specially:
397509885543Smrg
3976e4f6584cSmrg  -all-static       do not do any dynamic linking at all
3977e4f6584cSmrg  -avoid-version    do not add a version suffix if possible
3978b12e5c03Smrg  -bindir BINDIR    specify path to binaries directory (for systems where
3979b12e5c03Smrg                    libraries must be found in the PATH setting at runtime)
3980f395c03eSmrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
3981e4f6584cSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
3982e4f6584cSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
3983e4f6584cSmrg  -export-symbols SYMFILE
3984e4f6584cSmrg                    try to export only the symbols listed in SYMFILE
3985e4f6584cSmrg  -export-symbols-regex REGEX
3986e4f6584cSmrg                    try to export only the symbols matching REGEX
3987e4f6584cSmrg  -LLIBDIR          search LIBDIR for required installed libraries
3988e4f6584cSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
3989e4f6584cSmrg  -module           build a library that can dlopened
3990e4f6584cSmrg  -no-fast-install  disable the fast-install mode
3991e4f6584cSmrg  -no-install       link a not-installable executable
3992e4f6584cSmrg  -no-undefined     declare that a library does not refer to external symbols
3993e4f6584cSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3994f395c03eSmrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3995f395c03eSmrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
3996e4f6584cSmrg  -precious-files-regex REGEX
3997e4f6584cSmrg                    don't remove output files matching REGEX
3998e4f6584cSmrg  -release RELEASE  specify package release information
3999e4f6584cSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
4000e4f6584cSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
4001e4f6584cSmrg  -shared           only do dynamic linking of libtool libraries
4002e4f6584cSmrg  -shrext SUFFIX    override the standard shared library file extension
4003e4f6584cSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
4004e4f6584cSmrg  -static-libtool-libs
4005e4f6584cSmrg                    do not do any dynamic linking of libtool libraries
4006e4f6584cSmrg  -version-info CURRENT[:REVISION[:AGE]]
4007e4f6584cSmrg                    specify library version info [each variable defaults to 0]
4008e4f6584cSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
4009b12e5c03Smrg  -Wc,FLAG
4010b12e5c03Smrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
4011beef1b22Smrg  -Wa,FLAG
4012beef1b22Smrg  -Xassembler FLAG  pass linker-specific FLAG directly to the assembler
4013b12e5c03Smrg  -Wl,FLAG
4014b12e5c03Smrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
4015b12e5c03Smrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
401609885543Smrg
4017f395c03eSmrgAll other options (arguments beginning with '-') are ignored.
401809885543Smrg
4019f395c03eSmrgEvery other argument is treated as a filename.  Files ending in '.la' are
4020e4f6584cSmrgtreated as uninstalled libtool libraries, other files are standard or library
4021e4f6584cSmrgobject files.
402209885543Smrg
4023f395c03eSmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
4024f395c03eSmrgonly library objects ('.lo' files) may be specified, and '-rpath' is
4025e4f6584cSmrgrequired, except when creating a convenience library.
402609885543Smrg
4027f395c03eSmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
4028f395c03eSmrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
402909885543Smrg
4030f395c03eSmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
4031e4f6584cSmrgis created, otherwise an executable program is created."
4032b698ba48Smrg        ;;
403309885543Smrg
4034e4f6584cSmrg      uninstall)
4035e4f6584cSmrg        $ECHO \
4036e4f6584cSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
403709885543Smrg
4038e4f6584cSmrgRemove libraries from an installation directory.
403909885543Smrg
4040e4f6584cSmrgRM is the name of the program to use to delete files associated with each FILE
4041f395c03eSmrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
4042e4f6584cSmrgto RM.
40432ec8c4b4Smrg
4044e4f6584cSmrgIf FILE is a libtool library, all the files associated with it are deleted.
4045e4f6584cSmrgOtherwise, only FILE itself is deleted using RM."
4046e4f6584cSmrg        ;;
40472ec8c4b4Smrg
4048e4f6584cSmrg      *)
4049f395c03eSmrg        func_fatal_help "invalid operation mode '$opt_mode'"
4050e4f6584cSmrg        ;;
4051e4f6584cSmrg    esac
40522ec8c4b4Smrg
4053b12e5c03Smrg    echo
4054f395c03eSmrg    $ECHO "Try '$progname --help' for more information about other modes."
4055e4f6584cSmrg}
40562ec8c4b4Smrg
4057b12e5c03Smrg# Now that we've collected a possible --mode arg, show help if necessary
4058b12e5c03Smrgif $opt_help; then
4059f395c03eSmrg  if test : = "$opt_help"; then
4060b12e5c03Smrg    func_mode_help
4061b12e5c03Smrg  else
4062b12e5c03Smrg    {
4063b12e5c03Smrg      func_help noexit
4064b12e5c03Smrg      for opt_mode in compile link execute install finish uninstall clean; do
4065b12e5c03Smrg	func_mode_help
4066b12e5c03Smrg      done
4067f395c03eSmrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
4068b12e5c03Smrg    {
4069b12e5c03Smrg      func_help noexit
4070b12e5c03Smrg      for opt_mode in compile link execute install finish uninstall clean; do
4071b12e5c03Smrg	echo
4072b12e5c03Smrg	func_mode_help
4073b12e5c03Smrg      done
4074b12e5c03Smrg    } |
4075f395c03eSmrg    $SED '1d
4076b12e5c03Smrg      /^When reporting/,/^Report/{
4077b12e5c03Smrg	H
4078b12e5c03Smrg	d
4079b12e5c03Smrg      }
4080b12e5c03Smrg      $x
4081b12e5c03Smrg      /information about other modes/d
4082b12e5c03Smrg      /more detailed .*MODE/d
4083b12e5c03Smrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
4084b12e5c03Smrg  fi
4085b12e5c03Smrg  exit $?
4086b12e5c03Smrgfi
40872ec8c4b4Smrg
40882ec8c4b4Smrg
4089e4f6584cSmrg# func_mode_execute arg...
4090e4f6584cSmrgfunc_mode_execute ()
4091e4f6584cSmrg{
4092f395c03eSmrg    $debug_cmd
4093f395c03eSmrg
4094e4f6584cSmrg    # The first argument is the command name.
4095f395c03eSmrg    cmd=$nonopt
4096e4f6584cSmrg    test -z "$cmd" && \
4097e4f6584cSmrg      func_fatal_help "you must specify a COMMAND"
4098b698ba48Smrg
4099e4f6584cSmrg    # Handle -dlopen flags immediately.
4100b12e5c03Smrg    for file in $opt_dlopen; do
4101e4f6584cSmrg      test -f "$file" \
4102f395c03eSmrg	|| func_fatal_help "'$file' is not a file"
4103b698ba48Smrg
4104e4f6584cSmrg      dir=
4105e4f6584cSmrg      case $file in
4106e4f6584cSmrg      *.la)
4107b12e5c03Smrg	func_resolve_sysroot "$file"
4108b12e5c03Smrg	file=$func_resolve_sysroot_result
4109b12e5c03Smrg
4110e4f6584cSmrg	# Check to see that this really is a libtool archive.
4111e4f6584cSmrg	func_lalib_unsafe_p "$file" \
4112f395c03eSmrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
4113b698ba48Smrg
4114e4f6584cSmrg	# Read the libtool library.
4115e4f6584cSmrg	dlname=
4116e4f6584cSmrg	library_names=
4117e4f6584cSmrg	func_source "$file"
411809885543Smrg
4119e4f6584cSmrg	# Skip this library if it cannot be dlopened.
4120e4f6584cSmrg	if test -z "$dlname"; then
4121e4f6584cSmrg	  # Warn if it was a shared library.
4122e4f6584cSmrg	  test -n "$library_names" && \
4123f395c03eSmrg	    func_warning "'$file' was not linked with '-export-dynamic'"
4124e4f6584cSmrg	  continue
4125e4f6584cSmrg	fi
412609885543Smrg
4127e4f6584cSmrg	func_dirname "$file" "" "."
4128f395c03eSmrg	dir=$func_dirname_result
412909885543Smrg
4130e4f6584cSmrg	if test -f "$dir/$objdir/$dlname"; then
4131b12e5c03Smrg	  func_append dir "/$objdir"
4132e4f6584cSmrg	else
4133e4f6584cSmrg	  if test ! -f "$dir/$dlname"; then
4134f395c03eSmrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
4135e4f6584cSmrg	  fi
4136e4f6584cSmrg	fi
4137b698ba48Smrg	;;
413809885543Smrg
4139e4f6584cSmrg      *.lo)
4140e4f6584cSmrg	# Just add the directory containing the .lo file.
4141e4f6584cSmrg	func_dirname "$file" "" "."
4142f395c03eSmrg	dir=$func_dirname_result
4143b698ba48Smrg	;;
414409885543Smrg
4145e4f6584cSmrg      *)
4146f395c03eSmrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
4147b698ba48Smrg	continue
4148b698ba48Smrg	;;
4149e4f6584cSmrg      esac
415009885543Smrg
4151e4f6584cSmrg      # Get the absolute pathname.
4152e4f6584cSmrg      absdir=`cd "$dir" && pwd`
4153f395c03eSmrg      test -n "$absdir" && dir=$absdir
41542ec8c4b4Smrg
4155e4f6584cSmrg      # Now add the directory to shlibpath_var.
4156e4f6584cSmrg      if eval "test -z \"\$$shlibpath_var\""; then
4157e4f6584cSmrg	eval "$shlibpath_var=\"\$dir\""
4158e4f6584cSmrg      else
4159e4f6584cSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
4160e4f6584cSmrg      fi
4161e4f6584cSmrg    done
41622ec8c4b4Smrg
4163e4f6584cSmrg    # This variable tells wrapper scripts just to set shlibpath_var
4164e4f6584cSmrg    # rather than running their programs.
4165f395c03eSmrg    libtool_execute_magic=$magic
41662ec8c4b4Smrg
4167e4f6584cSmrg    # Check if any of the arguments is a wrapper script.
4168e4f6584cSmrg    args=
4169e4f6584cSmrg    for file
4170e4f6584cSmrg    do
4171e4f6584cSmrg      case $file in
4172b12e5c03Smrg      -* | *.la | *.lo ) ;;
4173e4f6584cSmrg      *)
4174e4f6584cSmrg	# Do a test to see if this is really a libtool program.
4175e4f6584cSmrg	if func_ltwrapper_script_p "$file"; then
4176e4f6584cSmrg	  func_source "$file"
4177e4f6584cSmrg	  # Transform arg to wrapped name.
4178f395c03eSmrg	  file=$progdir/$program
4179e4f6584cSmrg	elif func_ltwrapper_executable_p "$file"; then
4180e4f6584cSmrg	  func_ltwrapper_scriptname "$file"
4181e4f6584cSmrg	  func_source "$func_ltwrapper_scriptname_result"
4182e4f6584cSmrg	  # Transform arg to wrapped name.
4183f395c03eSmrg	  file=$progdir/$program
4184e4f6584cSmrg	fi
4185e4f6584cSmrg	;;
4186e4f6584cSmrg      esac
4187e4f6584cSmrg      # Quote arguments (to preserve shell metacharacters).
4188b12e5c03Smrg      func_append_quoted args "$file"
4189e4f6584cSmrg    done
41902ec8c4b4Smrg
4191f395c03eSmrg    if $opt_dry_run; then
4192f395c03eSmrg      # Display what would be done.
4193f395c03eSmrg      if test -n "$shlibpath_var"; then
4194f395c03eSmrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4195f395c03eSmrg	echo "export $shlibpath_var"
4196f395c03eSmrg      fi
4197f395c03eSmrg      $ECHO "$cmd$args"
4198f395c03eSmrg      exit $EXIT_SUCCESS
4199f395c03eSmrg    else
4200e4f6584cSmrg      if test -n "$shlibpath_var"; then
4201e4f6584cSmrg	# Export the shlibpath_var.
4202e4f6584cSmrg	eval "export $shlibpath_var"
4203e4f6584cSmrg      fi
42042ec8c4b4Smrg
4205e4f6584cSmrg      # Restore saved environment variables
4206e4f6584cSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
4207e4f6584cSmrg      do
4208e4f6584cSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
4209e4f6584cSmrg                $lt_var=\$save_$lt_var; export $lt_var
4210b698ba48Smrg	      else
4211e4f6584cSmrg		$lt_unset $lt_var
4212e4f6584cSmrg	      fi"
4213e4f6584cSmrg      done
42142ec8c4b4Smrg
4215e4f6584cSmrg      # Now prepare to actually exec the command.
4216f395c03eSmrg      exec_cmd=\$cmd$args
4217e4f6584cSmrg    fi
4218e4f6584cSmrg}
42192ec8c4b4Smrg
4220f395c03eSmrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
42212ec8c4b4Smrg
4222b698ba48Smrg
4223e4f6584cSmrg# func_mode_finish arg...
4224e4f6584cSmrgfunc_mode_finish ()
4225e4f6584cSmrg{
4226f395c03eSmrg    $debug_cmd
4227f395c03eSmrg
4228b12e5c03Smrg    libs=
4229b12e5c03Smrg    libdirs=
4230e4f6584cSmrg    admincmds=
423109885543Smrg
4232b12e5c03Smrg    for opt in "$nonopt" ${1+"$@"}
4233b12e5c03Smrg    do
4234b12e5c03Smrg      if test -d "$opt"; then
4235b12e5c03Smrg	func_append libdirs " $opt"
4236b12e5c03Smrg
4237b12e5c03Smrg      elif test -f "$opt"; then
4238b12e5c03Smrg	if func_lalib_unsafe_p "$opt"; then
4239b12e5c03Smrg	  func_append libs " $opt"
4240b12e5c03Smrg	else
4241f395c03eSmrg	  func_warning "'$opt' is not a valid libtool archive"
4242b12e5c03Smrg	fi
4243b12e5c03Smrg
4244b12e5c03Smrg      else
4245f395c03eSmrg	func_fatal_error "invalid argument '$opt'"
4246b12e5c03Smrg      fi
4247b12e5c03Smrg    done
4248b12e5c03Smrg
4249b12e5c03Smrg    if test -n "$libs"; then
4250b12e5c03Smrg      if test -n "$lt_sysroot"; then
4251b12e5c03Smrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
4252b12e5c03Smrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
4253b12e5c03Smrg      else
4254b12e5c03Smrg        sysroot_cmd=
4255b12e5c03Smrg      fi
4256b12e5c03Smrg
4257b12e5c03Smrg      # Remove sysroot references
4258b12e5c03Smrg      if $opt_dry_run; then
4259b12e5c03Smrg        for lib in $libs; do
4260f395c03eSmrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
4261b12e5c03Smrg        done
4262b12e5c03Smrg      else
4263b12e5c03Smrg        tmpdir=`func_mktempdir`
4264b12e5c03Smrg        for lib in $libs; do
4265f395c03eSmrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
4266b12e5c03Smrg	    > $tmpdir/tmp-la
4267b12e5c03Smrg	  mv -f $tmpdir/tmp-la $lib
4268b12e5c03Smrg	done
4269b12e5c03Smrg        ${RM}r "$tmpdir"
4270b12e5c03Smrg      fi
4271b12e5c03Smrg    fi
427209885543Smrg
4273b12e5c03Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4274e4f6584cSmrg      for libdir in $libdirs; do
4275e4f6584cSmrg	if test -n "$finish_cmds"; then
4276e4f6584cSmrg	  # Do each command in the finish commands.
4277e4f6584cSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
4278e4f6584cSmrg'"$cmd"'"'
4279b698ba48Smrg	fi
4280e4f6584cSmrg	if test -n "$finish_eval"; then
4281e4f6584cSmrg	  # Do the single finish_eval.
4282e4f6584cSmrg	  eval cmds=\"$finish_eval\"
4283b12e5c03Smrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
4284e4f6584cSmrg       $cmds"
4285e4f6584cSmrg	fi
4286e4f6584cSmrg      done
4287e4f6584cSmrg    fi
428809885543Smrg
4289e4f6584cSmrg    # Exit here if they wanted silent mode.
4290f395c03eSmrg    $opt_quiet && exit $EXIT_SUCCESS
429109885543Smrg
4292b12e5c03Smrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
4293b12e5c03Smrg      echo "----------------------------------------------------------------------"
4294b12e5c03Smrg      echo "Libraries have been installed in:"
4295b12e5c03Smrg      for libdir in $libdirs; do
4296b12e5c03Smrg	$ECHO "   $libdir"
4297b12e5c03Smrg      done
4298b12e5c03Smrg      echo
4299b12e5c03Smrg      echo "If you ever happen to want to link against installed libraries"
4300b12e5c03Smrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4301f395c03eSmrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
4302b12e5c03Smrg      echo "flag during linking and do at least one of the following:"
4303b12e5c03Smrg      if test -n "$shlibpath_var"; then
4304f395c03eSmrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
4305b12e5c03Smrg	echo "     during execution"
4306b12e5c03Smrg      fi
4307b12e5c03Smrg      if test -n "$runpath_var"; then
4308f395c03eSmrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
4309b12e5c03Smrg	echo "     during linking"
4310b12e5c03Smrg      fi
4311b12e5c03Smrg      if test -n "$hardcode_libdir_flag_spec"; then
4312b12e5c03Smrg	libdir=LIBDIR
4313b12e5c03Smrg	eval flag=\"$hardcode_libdir_flag_spec\"
4314b12e5c03Smrg
4315f395c03eSmrg	$ECHO "   - use the '$flag' linker flag"
4316b12e5c03Smrg      fi
4317b12e5c03Smrg      if test -n "$admincmds"; then
4318b12e5c03Smrg	$ECHO "   - have your system administrator run these commands:$admincmds"
4319b12e5c03Smrg      fi
4320b12e5c03Smrg      if test -f /etc/ld.so.conf; then
4321f395c03eSmrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
4322b12e5c03Smrg      fi
4323b12e5c03Smrg      echo
4324e4f6584cSmrg
4325b12e5c03Smrg      echo "See any operating system documentation about shared libraries for"
4326b12e5c03Smrg      case $host in
4327b12e5c03Smrg	solaris2.[6789]|solaris2.1[0-9])
4328b12e5c03Smrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
4329b12e5c03Smrg	  echo "pages."
4330b12e5c03Smrg	  ;;
4331b12e5c03Smrg	*)
4332b12e5c03Smrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
4333b12e5c03Smrg	  ;;
4334b12e5c03Smrg      esac
4335b12e5c03Smrg      echo "----------------------------------------------------------------------"
4336e4f6584cSmrg    fi
4337e4f6584cSmrg    exit $EXIT_SUCCESS
4338e4f6584cSmrg}
4339e4f6584cSmrg
4340f395c03eSmrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4341e4f6584cSmrg
4342e4f6584cSmrg
4343e4f6584cSmrg# func_mode_install arg...
4344e4f6584cSmrgfunc_mode_install ()
4345e4f6584cSmrg{
4346f395c03eSmrg    $debug_cmd
4347f395c03eSmrg
4348e4f6584cSmrg    # There may be an optional sh(1) argument at the beginning of
4349e4f6584cSmrg    # install_prog (especially on Windows NT).
4350f395c03eSmrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
4351e4f6584cSmrg       # Allow the use of GNU shtool's install command.
4352f395c03eSmrg       case $nonopt in *shtool*) :;; *) false;; esac
4353f395c03eSmrg    then
4354e4f6584cSmrg      # Aesthetically quote it.
4355beef1b22Smrg      func_quote_arg pretty "$nonopt"
4356beef1b22Smrg      install_prog="$func_quote_arg_result "
4357e4f6584cSmrg      arg=$1
4358e4f6584cSmrg      shift
4359e4f6584cSmrg    else
4360e4f6584cSmrg      install_prog=
4361e4f6584cSmrg      arg=$nonopt
4362e4f6584cSmrg    fi
4363e4f6584cSmrg
4364e4f6584cSmrg    # The real first argument should be the name of the installation program.
4365e4f6584cSmrg    # Aesthetically quote it.
4366beef1b22Smrg    func_quote_arg pretty "$arg"
4367beef1b22Smrg    func_append install_prog "$func_quote_arg_result"
4368b12e5c03Smrg    install_shared_prog=$install_prog
4369b12e5c03Smrg    case " $install_prog " in
4370b12e5c03Smrg      *[\\\ /]cp\ *) install_cp=: ;;
4371b12e5c03Smrg      *) install_cp=false ;;
4372b12e5c03Smrg    esac
4373e4f6584cSmrg
4374e4f6584cSmrg    # We need to accept at least all the BSD install flags.
4375e4f6584cSmrg    dest=
4376e4f6584cSmrg    files=
4377e4f6584cSmrg    opts=
4378e4f6584cSmrg    prev=
4379e4f6584cSmrg    install_type=
4380f395c03eSmrg    isdir=false
4381e4f6584cSmrg    stripme=
4382b12e5c03Smrg    no_mode=:
4383e4f6584cSmrg    for arg
4384e4f6584cSmrg    do
4385b12e5c03Smrg      arg2=
4386e4f6584cSmrg      if test -n "$dest"; then
4387b12e5c03Smrg	func_append files " $dest"
4388e4f6584cSmrg	dest=$arg
4389e4f6584cSmrg	continue
4390e4f6584cSmrg      fi
4391e4f6584cSmrg
4392e4f6584cSmrg      case $arg in
4393f395c03eSmrg      -d) isdir=: ;;
4394e4f6584cSmrg      -f)
4395b12e5c03Smrg	if $install_cp; then :; else
4396b12e5c03Smrg	  prev=$arg
4397b12e5c03Smrg	fi
4398e4f6584cSmrg	;;
4399e4f6584cSmrg      -g | -m | -o)
4400e4f6584cSmrg	prev=$arg
4401e4f6584cSmrg	;;
4402e4f6584cSmrg      -s)
4403e4f6584cSmrg	stripme=" -s"
4404e4f6584cSmrg	continue
4405e4f6584cSmrg	;;
4406e4f6584cSmrg      -*)
4407e4f6584cSmrg	;;
4408e4f6584cSmrg      *)
4409e4f6584cSmrg	# If the previous option needed an argument, then skip it.
4410e4f6584cSmrg	if test -n "$prev"; then
4411f395c03eSmrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4412b12e5c03Smrg	    arg2=$install_override_mode
4413b12e5c03Smrg	    no_mode=false
4414b12e5c03Smrg	  fi
4415b698ba48Smrg	  prev=
44162ec8c4b4Smrg	else
4417e4f6584cSmrg	  dest=$arg
4418e4f6584cSmrg	  continue
441909885543Smrg	fi
4420b698ba48Smrg	;;
4421e4f6584cSmrg      esac
442209885543Smrg
4423e4f6584cSmrg      # Aesthetically quote the argument.
4424beef1b22Smrg      func_quote_arg pretty "$arg"
4425beef1b22Smrg      func_append install_prog " $func_quote_arg_result"
4426b12e5c03Smrg      if test -n "$arg2"; then
4427beef1b22Smrg	func_quote_arg pretty "$arg2"
4428b12e5c03Smrg      fi
4429beef1b22Smrg      func_append install_shared_prog " $func_quote_arg_result"
4430e4f6584cSmrg    done
443109885543Smrg
4432e4f6584cSmrg    test -z "$install_prog" && \
4433e4f6584cSmrg      func_fatal_help "you must specify an install program"
443409885543Smrg
4435e4f6584cSmrg    test -n "$prev" && \
4436f395c03eSmrg      func_fatal_help "the '$prev' option requires an argument"
44372ec8c4b4Smrg
4438b12e5c03Smrg    if test -n "$install_override_mode" && $no_mode; then
4439b12e5c03Smrg      if $install_cp; then :; else
4440beef1b22Smrg	func_quote_arg pretty "$install_override_mode"
4441beef1b22Smrg	func_append install_shared_prog " -m $func_quote_arg_result"
4442b12e5c03Smrg      fi
4443b12e5c03Smrg    fi
4444b12e5c03Smrg
4445e4f6584cSmrg    if test -z "$files"; then
4446e4f6584cSmrg      if test -z "$dest"; then
4447e4f6584cSmrg	func_fatal_help "no file or destination specified"
4448e4f6584cSmrg      else
4449e4f6584cSmrg	func_fatal_help "you must specify a destination"
4450e4f6584cSmrg      fi
4451b698ba48Smrg    fi
44522ec8c4b4Smrg
4453e4f6584cSmrg    # Strip any trailing slash from the destination.
4454e4f6584cSmrg    func_stripname '' '/' "$dest"
4455e4f6584cSmrg    dest=$func_stripname_result
44562ec8c4b4Smrg
4457e4f6584cSmrg    # Check to see that the destination is a directory.
4458f395c03eSmrg    test -d "$dest" && isdir=:
4459f395c03eSmrg    if $isdir; then
4460f395c03eSmrg      destdir=$dest
4461e4f6584cSmrg      destname=
4462b698ba48Smrg    else
4463e4f6584cSmrg      func_dirname_and_basename "$dest" "" "."
4464f395c03eSmrg      destdir=$func_dirname_result
4465f395c03eSmrg      destname=$func_basename_result
44662ec8c4b4Smrg
4467e4f6584cSmrg      # Not a directory, so check to see that there is only one file specified.
4468e4f6584cSmrg      set dummy $files; shift
4469e4f6584cSmrg      test "$#" -gt 1 && \
4470f395c03eSmrg	func_fatal_help "'$dest' is not a directory"
44712ec8c4b4Smrg    fi
4472e4f6584cSmrg    case $destdir in
4473e4f6584cSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4474b698ba48Smrg    *)
4475e4f6584cSmrg      for file in $files; do
4476e4f6584cSmrg	case $file in
4477e4f6584cSmrg	*.lo) ;;
4478e4f6584cSmrg	*)
4479f395c03eSmrg	  func_fatal_help "'$destdir' must be an absolute directory name"
4480e4f6584cSmrg	  ;;
4481e4f6584cSmrg	esac
4482e4f6584cSmrg      done
4483b698ba48Smrg      ;;
4484b698ba48Smrg    esac
448509885543Smrg
4486e4f6584cSmrg    # This variable tells wrapper scripts just to set variables rather
4487e4f6584cSmrg    # than running their programs.
4488f395c03eSmrg    libtool_install_magic=$magic
448909885543Smrg
4490e4f6584cSmrg    staticlibs=
4491e4f6584cSmrg    future_libdirs=
4492e4f6584cSmrg    current_libdirs=
4493e4f6584cSmrg    for file in $files; do
449409885543Smrg
4495e4f6584cSmrg      # Do each installation.
4496e4f6584cSmrg      case $file in
4497e4f6584cSmrg      *.$libext)
4498e4f6584cSmrg	# Do the static libraries later.
4499b12e5c03Smrg	func_append staticlibs " $file"
4500e4f6584cSmrg	;;
4501e4f6584cSmrg
4502e4f6584cSmrg      *.la)
4503b12e5c03Smrg	func_resolve_sysroot "$file"
4504b12e5c03Smrg	file=$func_resolve_sysroot_result
4505b12e5c03Smrg
4506e4f6584cSmrg	# Check to see that this really is a libtool archive.
4507e4f6584cSmrg	func_lalib_unsafe_p "$file" \
4508f395c03eSmrg	  || func_fatal_help "'$file' is not a valid libtool archive"
4509e4f6584cSmrg
4510e4f6584cSmrg	library_names=
4511e4f6584cSmrg	old_library=
4512e4f6584cSmrg	relink_command=
4513e4f6584cSmrg	func_source "$file"
4514e4f6584cSmrg
4515e4f6584cSmrg	# Add the libdir to current_libdirs if it is the destination.
4516e4f6584cSmrg	if test "X$destdir" = "X$libdir"; then
4517e4f6584cSmrg	  case "$current_libdirs " in
4518e4f6584cSmrg	  *" $libdir "*) ;;
4519b12e5c03Smrg	  *) func_append current_libdirs " $libdir" ;;
45202ec8c4b4Smrg	  esac
4521e4f6584cSmrg	else
4522e4f6584cSmrg	  # Note the libdir as a future libdir.
4523e4f6584cSmrg	  case "$future_libdirs " in
4524e4f6584cSmrg	  *" $libdir "*) ;;
4525b12e5c03Smrg	  *) func_append future_libdirs " $libdir" ;;
4526e4f6584cSmrg	  esac
4527e4f6584cSmrg	fi
45282ec8c4b4Smrg
4529e4f6584cSmrg	func_dirname "$file" "/" ""
4530f395c03eSmrg	dir=$func_dirname_result
4531b12e5c03Smrg	func_append dir "$objdir"
4532e4f6584cSmrg
4533e4f6584cSmrg	if test -n "$relink_command"; then
4534e4f6584cSmrg	  # Determine the prefix the user has applied to our future dir.
4535b12e5c03Smrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
4536e4f6584cSmrg
4537e4f6584cSmrg	  # Don't allow the user to place us outside of our expected
4538e4f6584cSmrg	  # location b/c this prevents finding dependent libraries that
4539e4f6584cSmrg	  # are installed to the same prefix.
4540e4f6584cSmrg	  # At present, this check doesn't affect windows .dll's that
4541e4f6584cSmrg	  # are installed into $libdir/../bin (currently, that works fine)
4542e4f6584cSmrg	  # but it's something to keep an eye on.
4543e4f6584cSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4544f395c03eSmrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
4545e4f6584cSmrg
4546e4f6584cSmrg	  if test -n "$inst_prefix_dir"; then
4547e4f6584cSmrg	    # Stick the inst_prefix_dir data into the link command.
4548b12e5c03Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
4549e4f6584cSmrg	  else
4550b12e5c03Smrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
4551e4f6584cSmrg	  fi
4552e4f6584cSmrg
4553f395c03eSmrg	  func_warning "relinking '$file'"
4554e4f6584cSmrg	  func_show_eval "$relink_command" \
4555f395c03eSmrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
4556e4f6584cSmrg	fi
4557e4f6584cSmrg
4558e4f6584cSmrg	# See the names of the shared library.
4559e4f6584cSmrg	set dummy $library_names; shift
4560e4f6584cSmrg	if test -n "$1"; then
4561f395c03eSmrg	  realname=$1
4562e4f6584cSmrg	  shift
4563e4f6584cSmrg
4564f395c03eSmrg	  srcname=$realname
4565f395c03eSmrg	  test -n "$relink_command" && srcname=${realname}T
4566e4f6584cSmrg
4567e4f6584cSmrg	  # Install the shared library and build the symlinks.
4568b12e5c03Smrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
4569e4f6584cSmrg	      'exit $?'
4570f395c03eSmrg	  tstripme=$stripme
4571e4f6584cSmrg	  case $host_os in
4572e4f6584cSmrg	  cygwin* | mingw* | pw32* | cegcc*)
4573e4f6584cSmrg	    case $realname in
4574e4f6584cSmrg	    *.dll.a)
4575f395c03eSmrg	      tstripme=
4576f395c03eSmrg	      ;;
4577f395c03eSmrg	    esac
4578f395c03eSmrg	    ;;
4579f395c03eSmrg	  os2*)
4580f395c03eSmrg	    case $realname in
4581f395c03eSmrg	    *_dll.a)
4582f395c03eSmrg	      tstripme=
4583e4f6584cSmrg	      ;;
4584e4f6584cSmrg	    esac
45852ec8c4b4Smrg	    ;;
45862ec8c4b4Smrg	  esac
4587e4f6584cSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
4588e4f6584cSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
4589b698ba48Smrg	  fi
4590e4f6584cSmrg
4591e4f6584cSmrg	  if test "$#" -gt 0; then
4592e4f6584cSmrg	    # Delete the old symlinks, and create new ones.
4593f395c03eSmrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
4594e4f6584cSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
4595e4f6584cSmrg	    # so we also need to try rm && ln -s.
4596e4f6584cSmrg	    for linkname
4597e4f6584cSmrg	    do
4598e4f6584cSmrg	      test "$linkname" != "$realname" \
4599e4f6584cSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4600b698ba48Smrg	    done
4601b698ba48Smrg	  fi
460209885543Smrg
4603e4f6584cSmrg	  # Do each command in the postinstall commands.
4604f395c03eSmrg	  lib=$destdir/$realname
4605e4f6584cSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4606b698ba48Smrg	fi
460709885543Smrg
4608e4f6584cSmrg	# Install the pseudo-library for information purposes.
4609e4f6584cSmrg	func_basename "$file"
4610f395c03eSmrg	name=$func_basename_result
4611f395c03eSmrg	instname=$dir/${name}i
4612e4f6584cSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
461309885543Smrg
4614e4f6584cSmrg	# Maybe install the static library, too.
4615b12e5c03Smrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
4616e4f6584cSmrg	;;
461709885543Smrg
4618e4f6584cSmrg      *.lo)
4619e4f6584cSmrg	# Install (i.e. copy) a libtool object.
462009885543Smrg
4621e4f6584cSmrg	# Figure out destination file name, if it wasn't already specified.
4622e4f6584cSmrg	if test -n "$destname"; then
4623f395c03eSmrg	  destfile=$destdir/$destname
4624e4f6584cSmrg	else
4625e4f6584cSmrg	  func_basename "$file"
4626f395c03eSmrg	  destfile=$func_basename_result
4627f395c03eSmrg	  destfile=$destdir/$destfile
4628b698ba48Smrg	fi
462909885543Smrg
4630e4f6584cSmrg	# Deduce the name of the destination old-style object file.
4631e4f6584cSmrg	case $destfile in
4632e4f6584cSmrg	*.lo)
4633e4f6584cSmrg	  func_lo2o "$destfile"
4634e4f6584cSmrg	  staticdest=$func_lo2o_result
4635e4f6584cSmrg	  ;;
4636e4f6584cSmrg	*.$objext)
4637f395c03eSmrg	  staticdest=$destfile
4638e4f6584cSmrg	  destfile=
4639e4f6584cSmrg	  ;;
4640e4f6584cSmrg	*)
4641f395c03eSmrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
4642e4f6584cSmrg	  ;;
4643e4f6584cSmrg	esac
464409885543Smrg
4645e4f6584cSmrg	# Install the libtool object if requested.
4646e4f6584cSmrg	test -n "$destfile" && \
4647e4f6584cSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
464809885543Smrg
4649e4f6584cSmrg	# Install the old object if enabled.
4650f395c03eSmrg	if test yes = "$build_old_libs"; then
4651e4f6584cSmrg	  # Deduce the name of the old-style object file.
4652e4f6584cSmrg	  func_lo2o "$file"
4653e4f6584cSmrg	  staticobj=$func_lo2o_result
4654e4f6584cSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
465509885543Smrg	fi
4656e4f6584cSmrg	exit $EXIT_SUCCESS
4657e4f6584cSmrg	;;
465809885543Smrg
4659e4f6584cSmrg      *)
4660e4f6584cSmrg	# Figure out destination file name, if it wasn't already specified.
4661e4f6584cSmrg	if test -n "$destname"; then
4662f395c03eSmrg	  destfile=$destdir/$destname
4663e4f6584cSmrg	else
4664e4f6584cSmrg	  func_basename "$file"
4665f395c03eSmrg	  destfile=$func_basename_result
4666f395c03eSmrg	  destfile=$destdir/$destfile
4667e4f6584cSmrg	fi
466809885543Smrg
4669e4f6584cSmrg	# If the file is missing, and there is a .exe on the end, strip it
4670e4f6584cSmrg	# because it is most likely a libtool script we actually want to
4671e4f6584cSmrg	# install
4672f395c03eSmrg	stripped_ext=
4673e4f6584cSmrg	case $file in
4674e4f6584cSmrg	  *.exe)
4675e4f6584cSmrg	    if test ! -f "$file"; then
4676e4f6584cSmrg	      func_stripname '' '.exe' "$file"
4677e4f6584cSmrg	      file=$func_stripname_result
4678f395c03eSmrg	      stripped_ext=.exe
4679e4f6584cSmrg	    fi
4680e4f6584cSmrg	    ;;
4681e4f6584cSmrg	esac
4682e4f6584cSmrg
4683e4f6584cSmrg	# Do a test to see if this is really a libtool program.
4684e4f6584cSmrg	case $host in
4685e4f6584cSmrg	*cygwin* | *mingw*)
4686e4f6584cSmrg	    if func_ltwrapper_executable_p "$file"; then
4687e4f6584cSmrg	      func_ltwrapper_scriptname "$file"
4688e4f6584cSmrg	      wrapper=$func_ltwrapper_scriptname_result
4689e4f6584cSmrg	    else
4690e4f6584cSmrg	      func_stripname '' '.exe' "$file"
4691e4f6584cSmrg	      wrapper=$func_stripname_result
4692e4f6584cSmrg	    fi
4693e4f6584cSmrg	    ;;
4694b698ba48Smrg	*)
4695e4f6584cSmrg	    wrapper=$file
4696e4f6584cSmrg	    ;;
4697e4f6584cSmrg	esac
4698e4f6584cSmrg	if func_ltwrapper_script_p "$wrapper"; then
4699e4f6584cSmrg	  notinst_deplibs=
4700e4f6584cSmrg	  relink_command=
4701e4f6584cSmrg
4702e4f6584cSmrg	  func_source "$wrapper"
4703e4f6584cSmrg
4704e4f6584cSmrg	  # Check the variables that should have been set.
4705e4f6584cSmrg	  test -z "$generated_by_libtool_version" && \
4706f395c03eSmrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
4707e4f6584cSmrg
4708f395c03eSmrg	  finalize=:
4709e4f6584cSmrg	  for lib in $notinst_deplibs; do
4710e4f6584cSmrg	    # Check to see that each library is installed.
4711e4f6584cSmrg	    libdir=
4712e4f6584cSmrg	    if test -f "$lib"; then
4713e4f6584cSmrg	      func_source "$lib"
4714e4f6584cSmrg	    fi
4715f395c03eSmrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
4716e4f6584cSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4717f395c03eSmrg	      func_warning "'$lib' has not been installed in '$libdir'"
4718f395c03eSmrg	      finalize=false
4719e4f6584cSmrg	    fi
4720e4f6584cSmrg	  done
4721e4f6584cSmrg
4722e4f6584cSmrg	  relink_command=
4723e4f6584cSmrg	  func_source "$wrapper"
4724e4f6584cSmrg
4725e4f6584cSmrg	  outputname=
4726f395c03eSmrg	  if test no = "$fast_install" && test -n "$relink_command"; then
4727e4f6584cSmrg	    $opt_dry_run || {
4728f395c03eSmrg	      if $finalize; then
4729e4f6584cSmrg	        tmpdir=`func_mktempdir`
4730e4f6584cSmrg		func_basename "$file$stripped_ext"
4731f395c03eSmrg		file=$func_basename_result
4732f395c03eSmrg	        outputname=$tmpdir/$file
4733e4f6584cSmrg	        # Replace the output file specification.
4734b12e5c03Smrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
4735e4f6584cSmrg
4736f395c03eSmrg	        $opt_quiet || {
4737beef1b22Smrg	          func_quote_arg expand,pretty "$relink_command"
4738beef1b22Smrg		  eval "func_echo $func_quote_arg_result"
4739e4f6584cSmrg	        }
4740e4f6584cSmrg	        if eval "$relink_command"; then :
4741e4f6584cSmrg	          else
4742f395c03eSmrg		  func_error "error: relink '$file' with the above command before installing it"
4743e4f6584cSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
4744e4f6584cSmrg		  continue
4745e4f6584cSmrg	        fi
4746f395c03eSmrg	        file=$outputname
4747e4f6584cSmrg	      else
4748f395c03eSmrg	        func_warning "cannot relink '$file'"
4749e4f6584cSmrg	      fi
4750e4f6584cSmrg	    }
4751e4f6584cSmrg	  else
4752e4f6584cSmrg	    # Install the binary that we compiled earlier.
4753b12e5c03Smrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4754b698ba48Smrg	  fi
4755e4f6584cSmrg	fi
4756e4f6584cSmrg
4757e4f6584cSmrg	# remove .exe since cygwin /usr/bin/install will append another
4758e4f6584cSmrg	# one anyway
4759e4f6584cSmrg	case $install_prog,$host in
4760e4f6584cSmrg	*/usr/bin/install*,*cygwin*)
4761e4f6584cSmrg	  case $file:$destfile in
4762e4f6584cSmrg	  *.exe:*.exe)
4763e4f6584cSmrg	    # this is ok
4764e4f6584cSmrg	    ;;
4765e4f6584cSmrg	  *.exe:*)
4766e4f6584cSmrg	    destfile=$destfile.exe
4767e4f6584cSmrg	    ;;
4768e4f6584cSmrg	  *:*.exe)
4769e4f6584cSmrg	    func_stripname '' '.exe' "$destfile"
4770e4f6584cSmrg	    destfile=$func_stripname_result
4771e4f6584cSmrg	    ;;
4772e4f6584cSmrg	  esac
4773b698ba48Smrg	  ;;
4774b698ba48Smrg	esac
4775e4f6584cSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
4776e4f6584cSmrg	$opt_dry_run || if test -n "$outputname"; then
4777e4f6584cSmrg	  ${RM}r "$tmpdir"
4778e4f6584cSmrg	fi
4779e4f6584cSmrg	;;
4780e4f6584cSmrg      esac
4781e4f6584cSmrg    done
478209885543Smrg
4783e4f6584cSmrg    for file in $staticlibs; do
4784e4f6584cSmrg      func_basename "$file"
4785f395c03eSmrg      name=$func_basename_result
4786e4f6584cSmrg
4787e4f6584cSmrg      # Set up the ranlib parameters.
4788f395c03eSmrg      oldlib=$destdir/$name
4789b12e5c03Smrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
4790b12e5c03Smrg      tool_oldlib=$func_to_tool_file_result
4791e4f6584cSmrg
4792e4f6584cSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
4793e4f6584cSmrg
4794e4f6584cSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
4795b12e5c03Smrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
4796e4f6584cSmrg      fi
4797e4f6584cSmrg
4798e4f6584cSmrg      # Do each command in the postinstall commands.
4799e4f6584cSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
4800e4f6584cSmrg    done
4801e4f6584cSmrg
4802e4f6584cSmrg    test -n "$future_libdirs" && \
4803f395c03eSmrg      func_warning "remember to run '$progname --finish$future_libdirs'"
4804e4f6584cSmrg
4805e4f6584cSmrg    if test -n "$current_libdirs"; then
4806e4f6584cSmrg      # Maybe just do a dry run.
4807e4f6584cSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4808f395c03eSmrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
4809e4f6584cSmrg    else
4810e4f6584cSmrg      exit $EXIT_SUCCESS
4811e4f6584cSmrg    fi
4812e4f6584cSmrg}
4813e4f6584cSmrg
4814f395c03eSmrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
4815e4f6584cSmrg
4816e4f6584cSmrg
4817e4f6584cSmrg# func_generate_dlsyms outputname originator pic_p
4818e4f6584cSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
4819e4f6584cSmrg# a dlpreopen symbol table.
4820e4f6584cSmrgfunc_generate_dlsyms ()
4821e4f6584cSmrg{
4822f395c03eSmrg    $debug_cmd
4823f395c03eSmrg
4824f395c03eSmrg    my_outputname=$1
4825f395c03eSmrg    my_originator=$2
4826f395c03eSmrg    my_pic_p=${3-false}
4827f395c03eSmrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
4828e4f6584cSmrg    my_dlsyms=
4829e4f6584cSmrg
4830f395c03eSmrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
4831e4f6584cSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4832f395c03eSmrg	my_dlsyms=${my_outputname}S.c
4833e4f6584cSmrg      else
4834e4f6584cSmrg	func_error "not configured to extract global symbols from dlpreopened files"
4835e4f6584cSmrg      fi
4836e4f6584cSmrg    fi
4837e4f6584cSmrg
4838e4f6584cSmrg    if test -n "$my_dlsyms"; then
4839e4f6584cSmrg      case $my_dlsyms in
4840e4f6584cSmrg      "") ;;
4841e4f6584cSmrg      *.c)
4842e4f6584cSmrg	# Discover the nlist of each of the dlfiles.
4843f395c03eSmrg	nlist=$output_objdir/$my_outputname.nm
4844e4f6584cSmrg
4845e4f6584cSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
4846e4f6584cSmrg
4847e4f6584cSmrg	# Parse the name list into a source file.
4848e4f6584cSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
4849e4f6584cSmrg
4850e4f6584cSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4851f395c03eSmrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4852f395c03eSmrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
4853e4f6584cSmrg
4854e4f6584cSmrg#ifdef __cplusplus
4855e4f6584cSmrgextern \"C\" {
4856e4f6584cSmrg#endif
4857e4f6584cSmrg
4858f395c03eSmrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4859b12e5c03Smrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4860b12e5c03Smrg#endif
4861b12e5c03Smrg
4862b12e5c03Smrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4863f395c03eSmrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4864f395c03eSmrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
4865b12e5c03Smrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
4866b12e5c03Smrg# define LT_DLSYM_CONST
4867f395c03eSmrg#elif defined __osf__
4868b12e5c03Smrg/* This system does not cope well with relocations in const data.  */
4869b12e5c03Smrg# define LT_DLSYM_CONST
4870b12e5c03Smrg#else
4871b12e5c03Smrg# define LT_DLSYM_CONST const
4872b12e5c03Smrg#endif
4873b12e5c03Smrg
4874f395c03eSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4875f395c03eSmrg
4876e4f6584cSmrg/* External symbol declarations for the compiler. */\
4877e4f6584cSmrg"
4878e4f6584cSmrg
4879f395c03eSmrg	if test yes = "$dlself"; then
4880f395c03eSmrg	  func_verbose "generating symbol list for '$output'"
4881e4f6584cSmrg
4882e4f6584cSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
4883e4f6584cSmrg
4884e4f6584cSmrg	  # Add our own program objects to the symbol list.
4885b12e5c03Smrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
4886e4f6584cSmrg	  for progfile in $progfiles; do
4887b12e5c03Smrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4888f395c03eSmrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
4889b12e5c03Smrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
4890e4f6584cSmrg	  done
4891e4f6584cSmrg
4892e4f6584cSmrg	  if test -n "$exclude_expsyms"; then
4893e4f6584cSmrg	    $opt_dry_run || {
4894e4f6584cSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
4895e4f6584cSmrg	      eval '$MV "$nlist"T "$nlist"'
4896e4f6584cSmrg	    }
4897b698ba48Smrg	  fi
4898e4f6584cSmrg
4899e4f6584cSmrg	  if test -n "$export_symbols_regex"; then
4900e4f6584cSmrg	    $opt_dry_run || {
4901e4f6584cSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
4902e4f6584cSmrg	      eval '$MV "$nlist"T "$nlist"'
4903e4f6584cSmrg	    }
4904e4f6584cSmrg	  fi
4905e4f6584cSmrg
4906e4f6584cSmrg	  # Prepare the list of exported symbols
4907e4f6584cSmrg	  if test -z "$export_symbols"; then
4908f395c03eSmrg	    export_symbols=$output_objdir/$outputname.exp
4909e4f6584cSmrg	    $opt_dry_run || {
4910e4f6584cSmrg	      $RM $export_symbols
4911f395c03eSmrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
4912e4f6584cSmrg	      case $host in
4913e4f6584cSmrg	      *cygwin* | *mingw* | *cegcc* )
4914e4f6584cSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4915e4f6584cSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
4916e4f6584cSmrg	        ;;
4917e4f6584cSmrg	      esac
4918e4f6584cSmrg	    }
4919b698ba48Smrg	  else
4920e4f6584cSmrg	    $opt_dry_run || {
4921f395c03eSmrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
4922e4f6584cSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
4923e4f6584cSmrg	      eval '$MV "$nlist"T "$nlist"'
4924e4f6584cSmrg	      case $host in
4925b12e5c03Smrg	        *cygwin* | *mingw* | *cegcc* )
4926e4f6584cSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
4927e4f6584cSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
4928e4f6584cSmrg	          ;;
4929e4f6584cSmrg	      esac
4930e4f6584cSmrg	    }
4931b698ba48Smrg	  fi
4932e4f6584cSmrg	fi
493309885543Smrg
4934e4f6584cSmrg	for dlprefile in $dlprefiles; do
4935f395c03eSmrg	  func_verbose "extracting global C symbols from '$dlprefile'"
4936e4f6584cSmrg	  func_basename "$dlprefile"
4937f395c03eSmrg	  name=$func_basename_result
4938b12e5c03Smrg          case $host in
4939b12e5c03Smrg	    *cygwin* | *mingw* | *cegcc* )
4940b12e5c03Smrg	      # if an import library, we need to obtain dlname
4941b12e5c03Smrg	      if func_win32_import_lib_p "$dlprefile"; then
4942b12e5c03Smrg	        func_tr_sh "$dlprefile"
4943b12e5c03Smrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4944f395c03eSmrg	        dlprefile_dlbasename=
4945b12e5c03Smrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
4946b12e5c03Smrg	          # Use subshell, to avoid clobbering current variable values
4947b12e5c03Smrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4948f395c03eSmrg	          if test -n "$dlprefile_dlname"; then
4949b12e5c03Smrg	            func_basename "$dlprefile_dlname"
4950f395c03eSmrg	            dlprefile_dlbasename=$func_basename_result
4951b12e5c03Smrg	          else
4952b12e5c03Smrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
4953b12e5c03Smrg	            $sharedlib_from_linklib_cmd "$dlprefile"
4954b12e5c03Smrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
4955b12e5c03Smrg	          fi
4956b12e5c03Smrg	        fi
4957b12e5c03Smrg	        $opt_dry_run || {
4958f395c03eSmrg	          if test -n "$dlprefile_dlbasename"; then
4959b12e5c03Smrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
4960b12e5c03Smrg	          else
4961b12e5c03Smrg	            func_warning "Could not compute DLL name from $name"
4962b12e5c03Smrg	            eval '$ECHO ": $name " >> "$nlist"'
4963b12e5c03Smrg	          fi
4964b12e5c03Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4965b12e5c03Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
4966b12e5c03Smrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
4967b12e5c03Smrg	        }
4968b12e5c03Smrg	      else # not an import lib
4969b12e5c03Smrg	        $opt_dry_run || {
4970b12e5c03Smrg	          eval '$ECHO ": $name " >> "$nlist"'
4971b12e5c03Smrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4972b12e5c03Smrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4973b12e5c03Smrg	        }
4974b12e5c03Smrg	      fi
4975b12e5c03Smrg	    ;;
4976b12e5c03Smrg	    *)
4977b12e5c03Smrg	      $opt_dry_run || {
4978b12e5c03Smrg	        eval '$ECHO ": $name " >> "$nlist"'
4979b12e5c03Smrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
4980b12e5c03Smrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
4981b12e5c03Smrg	      }
4982b12e5c03Smrg	    ;;
4983b12e5c03Smrg          esac
4984e4f6584cSmrg	done
4985e4f6584cSmrg
4986e4f6584cSmrg	$opt_dry_run || {
4987e4f6584cSmrg	  # Make sure we have at least an empty file.
4988e4f6584cSmrg	  test -f "$nlist" || : > "$nlist"
4989e4f6584cSmrg
4990e4f6584cSmrg	  if test -n "$exclude_expsyms"; then
4991e4f6584cSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
4992e4f6584cSmrg	    $MV "$nlist"T "$nlist"
4993b698ba48Smrg	  fi
4994e4f6584cSmrg
4995e4f6584cSmrg	  # Try sorting and uniquifying the output.
4996e4f6584cSmrg	  if $GREP -v "^: " < "$nlist" |
4997e4f6584cSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
4998e4f6584cSmrg		sort -k 3
4999e4f6584cSmrg	      else
5000e4f6584cSmrg		sort +2
5001e4f6584cSmrg	      fi |
5002e4f6584cSmrg	      uniq > "$nlist"S; then
5003e4f6584cSmrg	    :
5004b698ba48Smrg	  else
5005e4f6584cSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
5006b698ba48Smrg	  fi
500709885543Smrg
5008e4f6584cSmrg	  if test -f "$nlist"S; then
5009e4f6584cSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
5010b698ba48Smrg	  else
5011b12e5c03Smrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
5012b698ba48Smrg	  fi
501309885543Smrg
5014f395c03eSmrg	  func_show_eval '$RM "${nlist}I"'
5015f395c03eSmrg	  if test -n "$global_symbol_to_import"; then
5016f395c03eSmrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
5017f395c03eSmrg	  fi
5018f395c03eSmrg
5019b12e5c03Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
502009885543Smrg
5021e4f6584cSmrg/* The mapping between symbol names and symbols.  */
5022e4f6584cSmrgtypedef struct {
5023e4f6584cSmrg  const char *name;
5024e4f6584cSmrg  void *address;
5025e4f6584cSmrg} lt_dlsymlist;
5026b12e5c03Smrgextern LT_DLSYM_CONST lt_dlsymlist
5027f395c03eSmrglt_${my_prefix}_LTX_preloaded_symbols[];\
5028f395c03eSmrg"
5029f395c03eSmrg
5030f395c03eSmrg	  if test -s "$nlist"I; then
5031f395c03eSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5032f395c03eSmrgstatic void lt_syminit(void)
5033f395c03eSmrg{
5034f395c03eSmrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
5035f395c03eSmrg  for (; symbol->name; ++symbol)
5036f395c03eSmrg    {"
5037f395c03eSmrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
5038f395c03eSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5039f395c03eSmrg    }
5040f395c03eSmrg}"
5041f395c03eSmrg	  fi
5042f395c03eSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
5043b12e5c03SmrgLT_DLSYM_CONST lt_dlsymlist
5044e4f6584cSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
5045f395c03eSmrg{ {\"$my_originator\", (void *) 0},"
5046f395c03eSmrg
5047f395c03eSmrg	  if test -s "$nlist"I; then
5048f395c03eSmrg	    echo >> "$output_objdir/$my_dlsyms" "\
5049f395c03eSmrg  {\"@INIT@\", (void *) &lt_syminit},"
5050f395c03eSmrg	  fi
505109885543Smrg
5052e4f6584cSmrg	  case $need_lib_prefix in
5053e4f6584cSmrg	  no)
5054e4f6584cSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
5055e4f6584cSmrg	    ;;
5056e4f6584cSmrg	  *)
5057e4f6584cSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
5058e4f6584cSmrg	    ;;
5059e4f6584cSmrg	  esac
5060b12e5c03Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
5061e4f6584cSmrg  {0, (void *) 0}
5062e4f6584cSmrg};
506309885543Smrg
5064e4f6584cSmrg/* This works around a problem in FreeBSD linker */
5065e4f6584cSmrg#ifdef FREEBSD_WORKAROUND
5066e4f6584cSmrgstatic const void *lt_preloaded_setup() {
5067e4f6584cSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
5068e4f6584cSmrg}
5069e4f6584cSmrg#endif
5070e4f6584cSmrg
5071e4f6584cSmrg#ifdef __cplusplus
5072e4f6584cSmrg}
5073e4f6584cSmrg#endif\
5074e4f6584cSmrg"
5075e4f6584cSmrg	} # !$opt_dry_run
5076e4f6584cSmrg
5077e4f6584cSmrg	pic_flag_for_symtable=
5078e4f6584cSmrg	case "$compile_command " in
5079e4f6584cSmrg	*" -static "*) ;;
5080e4f6584cSmrg	*)
5081e4f6584cSmrg	  case $host in
5082e4f6584cSmrg	  # compiling the symbol table file with pic_flag works around
5083e4f6584cSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
5084e4f6584cSmrg	  # linked before any other PIC object.  But we must not use
5085e4f6584cSmrg	  # pic_flag when linking with -static.  The problem exists in
5086e4f6584cSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
5087b12e5c03Smrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
5088e4f6584cSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
5089e4f6584cSmrg	  *-*-hpux*)
5090e4f6584cSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
5091e4f6584cSmrg	  *)
5092f395c03eSmrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
5093e4f6584cSmrg	    ;;
5094e4f6584cSmrg	  esac
5095e4f6584cSmrg	  ;;
5096e4f6584cSmrg	esac
5097e4f6584cSmrg	symtab_cflags=
5098e4f6584cSmrg	for arg in $LTCFLAGS; do
5099e4f6584cSmrg	  case $arg in
5100e4f6584cSmrg	  -pie | -fpie | -fPIE) ;;
5101b12e5c03Smrg	  *) func_append symtab_cflags " $arg" ;;
5102e4f6584cSmrg	  esac
5103e4f6584cSmrg	done
510409885543Smrg
5105e4f6584cSmrg	# Now compile the dynamic symbol file.
5106e4f6584cSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
51072ec8c4b4Smrg
5108e4f6584cSmrg	# Clean up the generated files.
5109f395c03eSmrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
511009885543Smrg
5111e4f6584cSmrg	# Transform the symbol file into the correct name.
5112f395c03eSmrg	symfileobj=$output_objdir/${my_outputname}S.$objext
5113e4f6584cSmrg	case $host in
5114e4f6584cSmrg	*cygwin* | *mingw* | *cegcc* )
5115e4f6584cSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
5116b12e5c03Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5117b12e5c03Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
5118e4f6584cSmrg	  else
5119b12e5c03Smrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5120b12e5c03Smrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5121b698ba48Smrg	  fi
5122e4f6584cSmrg	  ;;
5123e4f6584cSmrg	*)
5124b12e5c03Smrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5125b12e5c03Smrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
5126e4f6584cSmrg	  ;;
5127e4f6584cSmrg	esac
5128e4f6584cSmrg	;;
5129e4f6584cSmrg      *)
5130f395c03eSmrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
5131e4f6584cSmrg	;;
5132e4f6584cSmrg      esac
5133e4f6584cSmrg    else
5134e4f6584cSmrg      # We keep going just in case the user didn't refer to
5135e4f6584cSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
5136e4f6584cSmrg      # really was required.
513709885543Smrg
5138e4f6584cSmrg      # Nullify the symbol file.
5139b12e5c03Smrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
5140b12e5c03Smrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
5141e4f6584cSmrg    fi
5142e4f6584cSmrg}
51432ec8c4b4Smrg
5144f395c03eSmrg# func_cygming_gnu_implib_p ARG
5145f395c03eSmrg# This predicate returns with zero status (TRUE) if
5146f395c03eSmrg# ARG is a GNU/binutils-style import library. Returns
5147f395c03eSmrg# with nonzero status (FALSE) otherwise.
5148f395c03eSmrgfunc_cygming_gnu_implib_p ()
5149f395c03eSmrg{
5150f395c03eSmrg  $debug_cmd
5151f395c03eSmrg
5152f395c03eSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5153f395c03eSmrg  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)$'`
5154f395c03eSmrg  test -n "$func_cygming_gnu_implib_tmp"
5155f395c03eSmrg}
5156f395c03eSmrg
5157f395c03eSmrg# func_cygming_ms_implib_p ARG
5158f395c03eSmrg# This predicate returns with zero status (TRUE) if
5159f395c03eSmrg# ARG is an MS-style import library. Returns
5160f395c03eSmrg# with nonzero status (FALSE) otherwise.
5161f395c03eSmrgfunc_cygming_ms_implib_p ()
5162f395c03eSmrg{
5163f395c03eSmrg  $debug_cmd
5164f395c03eSmrg
5165f395c03eSmrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
5166f395c03eSmrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5167f395c03eSmrg  test -n "$func_cygming_ms_implib_tmp"
5168f395c03eSmrg}
5169f395c03eSmrg
5170e4f6584cSmrg# func_win32_libid arg
5171e4f6584cSmrg# return the library type of file 'arg'
5172e4f6584cSmrg#
5173e4f6584cSmrg# Need a lot of goo to handle *both* DLLs and import libs
5174e4f6584cSmrg# Has to be a shell function in order to 'eat' the argument
5175e4f6584cSmrg# that is supplied when $file_magic_command is called.
5176b12e5c03Smrg# Despite the name, also deal with 64 bit binaries.
5177e4f6584cSmrgfunc_win32_libid ()
5178e4f6584cSmrg{
5179f395c03eSmrg  $debug_cmd
5180f395c03eSmrg
5181f395c03eSmrg  win32_libid_type=unknown
5182e4f6584cSmrg  win32_fileres=`file -L $1 2>/dev/null`
5183e4f6584cSmrg  case $win32_fileres in
5184e4f6584cSmrg  *ar\ archive\ import\ library*) # definitely import
5185e4f6584cSmrg    win32_libid_type="x86 archive import"
5186e4f6584cSmrg    ;;
5187e4f6584cSmrg  *ar\ archive*) # could be an import, or static
5188b12e5c03Smrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
5189e4f6584cSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
5190b12e5c03Smrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5191f395c03eSmrg      case $nm_interface in
5192f395c03eSmrg      "MS dumpbin")
5193f395c03eSmrg	if func_cygming_ms_implib_p "$1" ||
5194f395c03eSmrg	   func_cygming_gnu_implib_p "$1"
5195f395c03eSmrg	then
5196f395c03eSmrg	  win32_nmres=import
5197f395c03eSmrg	else
5198f395c03eSmrg	  win32_nmres=
5199f395c03eSmrg	fi
5200f395c03eSmrg	;;
5201f395c03eSmrg      *)
5202f395c03eSmrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
5203f395c03eSmrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
5204f395c03eSmrg	  $SED -n -e '
5205e4f6584cSmrg	    1,100{
5206e4f6584cSmrg		/ I /{
5207f395c03eSmrg		    s|.*|import|
5208e4f6584cSmrg		    p
5209e4f6584cSmrg		    q
5210e4f6584cSmrg		}
5211e4f6584cSmrg	    }'`
5212f395c03eSmrg	;;
5213f395c03eSmrg      esac
5214e4f6584cSmrg      case $win32_nmres in
5215e4f6584cSmrg      import*)  win32_libid_type="x86 archive import";;
5216e4f6584cSmrg      *)        win32_libid_type="x86 archive static";;
5217e4f6584cSmrg      esac
5218e4f6584cSmrg    fi
5219e4f6584cSmrg    ;;
5220e4f6584cSmrg  *DLL*)
5221e4f6584cSmrg    win32_libid_type="x86 DLL"
5222e4f6584cSmrg    ;;
5223e4f6584cSmrg  *executable*) # but shell scripts are "executable" too...
5224e4f6584cSmrg    case $win32_fileres in
5225e4f6584cSmrg    *MS\ Windows\ PE\ Intel*)
5226e4f6584cSmrg      win32_libid_type="x86 DLL"
5227e4f6584cSmrg      ;;
5228e4f6584cSmrg    esac
5229e4f6584cSmrg    ;;
5230e4f6584cSmrg  esac
5231e4f6584cSmrg  $ECHO "$win32_libid_type"
5232e4f6584cSmrg}
52332ec8c4b4Smrg
5234b12e5c03Smrg# func_cygming_dll_for_implib ARG
5235b12e5c03Smrg#
5236b12e5c03Smrg# Platform-specific function to extract the
5237b12e5c03Smrg# name of the DLL associated with the specified
5238b12e5c03Smrg# import library ARG.
5239b12e5c03Smrg# Invoked by eval'ing the libtool variable
5240b12e5c03Smrg#    $sharedlib_from_linklib_cmd
5241b12e5c03Smrg# Result is available in the variable
5242b12e5c03Smrg#    $sharedlib_from_linklib_result
5243b12e5c03Smrgfunc_cygming_dll_for_implib ()
5244b12e5c03Smrg{
5245f395c03eSmrg  $debug_cmd
5246f395c03eSmrg
5247b12e5c03Smrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
5248b12e5c03Smrg}
5249b12e5c03Smrg
5250b12e5c03Smrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
5251b12e5c03Smrg#
5252b12e5c03Smrg# The is the core of a fallback implementation of a
5253b12e5c03Smrg# platform-specific function to extract the name of the
5254b12e5c03Smrg# DLL associated with the specified import library LIBNAME.
5255b12e5c03Smrg#
5256b12e5c03Smrg# SECTION_NAME is either .idata$6 or .idata$7, depending
5257b12e5c03Smrg# on the platform and compiler that created the implib.
5258b12e5c03Smrg#
5259b12e5c03Smrg# Echos the name of the DLL associated with the
5260b12e5c03Smrg# specified import library.
5261b12e5c03Smrgfunc_cygming_dll_for_implib_fallback_core ()
5262b12e5c03Smrg{
5263f395c03eSmrg  $debug_cmd
5264f395c03eSmrg
5265b12e5c03Smrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
5266b12e5c03Smrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
5267b12e5c03Smrg    $SED '/^Contents of section '"$match_literal"':/{
5268b12e5c03Smrg      # Place marker at beginning of archive member dllname section
5269b12e5c03Smrg      s/.*/====MARK====/
5270b12e5c03Smrg      p
5271b12e5c03Smrg      d
5272b12e5c03Smrg    }
5273b12e5c03Smrg    # These lines can sometimes be longer than 43 characters, but
5274b12e5c03Smrg    # are always uninteresting
5275b12e5c03Smrg    /:[	 ]*file format pe[i]\{,1\}-/d
5276b12e5c03Smrg    /^In archive [^:]*:/d
5277b12e5c03Smrg    # Ensure marker is printed
5278b12e5c03Smrg    /^====MARK====/p
5279b12e5c03Smrg    # Remove all lines with less than 43 characters
5280b12e5c03Smrg    /^.\{43\}/!d
5281b12e5c03Smrg    # From remaining lines, remove first 43 characters
5282b12e5c03Smrg    s/^.\{43\}//' |
5283b12e5c03Smrg    $SED -n '
5284b12e5c03Smrg      # Join marker and all lines until next marker into a single line
5285b12e5c03Smrg      /^====MARK====/ b para
5286b12e5c03Smrg      H
5287b12e5c03Smrg      $ b para
5288b12e5c03Smrg      b
5289b12e5c03Smrg      :para
5290b12e5c03Smrg      x
5291b12e5c03Smrg      s/\n//g
5292b12e5c03Smrg      # Remove the marker
5293b12e5c03Smrg      s/^====MARK====//
5294b12e5c03Smrg      # Remove trailing dots and whitespace
5295b12e5c03Smrg      s/[\. \t]*$//
5296b12e5c03Smrg      # Print
5297b12e5c03Smrg      /./p' |
5298b12e5c03Smrg    # we now have a list, one entry per line, of the stringified
5299b12e5c03Smrg    # contents of the appropriate section of all members of the
5300f395c03eSmrg    # archive that possess that section. Heuristic: eliminate
5301f395c03eSmrg    # all those that have a first or second character that is
5302b12e5c03Smrg    # a '.' (that is, objdump's representation of an unprintable
5303b12e5c03Smrg    # character.) This should work for all archives with less than
5304b12e5c03Smrg    # 0x302f exports -- but will fail for DLLs whose name actually
5305b12e5c03Smrg    # begins with a literal '.' or a single character followed by
5306b12e5c03Smrg    # a '.'.
5307b12e5c03Smrg    #
5308b12e5c03Smrg    # Of those that remain, print the first one.
5309b12e5c03Smrg    $SED -e '/^\./d;/^.\./d;q'
5310b12e5c03Smrg}
5311b12e5c03Smrg
5312b12e5c03Smrg# func_cygming_dll_for_implib_fallback ARG
5313b12e5c03Smrg# Platform-specific function to extract the
5314b12e5c03Smrg# name of the DLL associated with the specified
5315b12e5c03Smrg# import library ARG.
5316b12e5c03Smrg#
5317b12e5c03Smrg# This fallback implementation is for use when $DLLTOOL
5318b12e5c03Smrg# does not support the --identify-strict option.
5319b12e5c03Smrg# Invoked by eval'ing the libtool variable
5320b12e5c03Smrg#    $sharedlib_from_linklib_cmd
5321b12e5c03Smrg# Result is available in the variable
5322b12e5c03Smrg#    $sharedlib_from_linklib_result
5323b12e5c03Smrgfunc_cygming_dll_for_implib_fallback ()
5324b12e5c03Smrg{
5325f395c03eSmrg  $debug_cmd
5326f395c03eSmrg
5327f395c03eSmrg  if func_cygming_gnu_implib_p "$1"; then
5328b12e5c03Smrg    # binutils import library
5329b12e5c03Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5330f395c03eSmrg  elif func_cygming_ms_implib_p "$1"; then
5331b12e5c03Smrg    # ms-generated import library
5332b12e5c03Smrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
5333b12e5c03Smrg  else
5334b12e5c03Smrg    # unknown
5335f395c03eSmrg    sharedlib_from_linklib_result=
5336b12e5c03Smrg  fi
5337b12e5c03Smrg}
53382ec8c4b4Smrg
53392ec8c4b4Smrg
5340e4f6584cSmrg# func_extract_an_archive dir oldlib
5341e4f6584cSmrgfunc_extract_an_archive ()
5342e4f6584cSmrg{
5343f395c03eSmrg    $debug_cmd
5344f395c03eSmrg
5345f395c03eSmrg    f_ex_an_ar_dir=$1; shift
5346f395c03eSmrg    f_ex_an_ar_oldlib=$1
5347f395c03eSmrg    if test yes = "$lock_old_archive_extraction"; then
5348b12e5c03Smrg      lockfile=$f_ex_an_ar_oldlib.lock
5349b12e5c03Smrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5350b12e5c03Smrg	func_echo "Waiting for $lockfile to be removed"
5351b12e5c03Smrg	sleep 2
5352b12e5c03Smrg      done
5353b12e5c03Smrg    fi
5354b12e5c03Smrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5355b12e5c03Smrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5356f395c03eSmrg    if test yes = "$lock_old_archive_extraction"; then
5357b12e5c03Smrg      $opt_dry_run || rm -f "$lockfile"
5358b12e5c03Smrg    fi
5359e4f6584cSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
5360e4f6584cSmrg     :
5361e4f6584cSmrg    else
5362e4f6584cSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
5363e4f6584cSmrg    fi
5364e4f6584cSmrg}
536509885543Smrg
536609885543Smrg
5367e4f6584cSmrg# func_extract_archives gentop oldlib ...
5368e4f6584cSmrgfunc_extract_archives ()
5369e4f6584cSmrg{
5370f395c03eSmrg    $debug_cmd
5371f395c03eSmrg
5372f395c03eSmrg    my_gentop=$1; shift
5373e4f6584cSmrg    my_oldlibs=${1+"$@"}
5374f395c03eSmrg    my_oldobjs=
5375f395c03eSmrg    my_xlib=
5376f395c03eSmrg    my_xabs=
5377f395c03eSmrg    my_xdir=
537809885543Smrg
5379e4f6584cSmrg    for my_xlib in $my_oldlibs; do
5380e4f6584cSmrg      # Extract the objects.
5381e4f6584cSmrg      case $my_xlib in
5382f395c03eSmrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
5383e4f6584cSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
5384e4f6584cSmrg      esac
5385e4f6584cSmrg      func_basename "$my_xlib"
5386f395c03eSmrg      my_xlib=$func_basename_result
5387e4f6584cSmrg      my_xlib_u=$my_xlib
5388e4f6584cSmrg      while :; do
5389e4f6584cSmrg        case " $extracted_archives " in
5390e4f6584cSmrg	*" $my_xlib_u "*)
5391e4f6584cSmrg	  func_arith $extracted_serial + 1
5392e4f6584cSmrg	  extracted_serial=$func_arith_result
5393e4f6584cSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
5394e4f6584cSmrg	*) break ;;
5395e4f6584cSmrg	esac
5396e4f6584cSmrg      done
5397e4f6584cSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5398f395c03eSmrg      my_xdir=$my_gentop/$my_xlib_u
539909885543Smrg
5400e4f6584cSmrg      func_mkdir_p "$my_xdir"
54012ec8c4b4Smrg
5402e4f6584cSmrg      case $host in
5403e4f6584cSmrg      *-darwin*)
5404e4f6584cSmrg	func_verbose "Extracting $my_xabs"
5405e4f6584cSmrg	# Do not bother doing anything if just a dry run
5406e4f6584cSmrg	$opt_dry_run || {
5407e4f6584cSmrg	  darwin_orig_dir=`pwd`
5408e4f6584cSmrg	  cd $my_xdir || exit $?
5409e4f6584cSmrg	  darwin_archive=$my_xabs
5410e4f6584cSmrg	  darwin_curdir=`pwd`
5411f395c03eSmrg	  func_basename "$darwin_archive"
5412f395c03eSmrg	  darwin_base_archive=$func_basename_result
5413e4f6584cSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
5414e4f6584cSmrg	  if test -n "$darwin_arches"; then
5415e4f6584cSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
5416e4f6584cSmrg	    darwin_arch=
5417e4f6584cSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5418f395c03eSmrg	    for darwin_arch in  $darwin_arches; do
5419f395c03eSmrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5420f395c03eSmrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5421f395c03eSmrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5422f395c03eSmrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
5423e4f6584cSmrg	      cd "$darwin_curdir"
5424f395c03eSmrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
5425e4f6584cSmrg	    done # $darwin_arches
5426e4f6584cSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5427f395c03eSmrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
5428e4f6584cSmrg	    darwin_file=
5429e4f6584cSmrg	    darwin_files=
5430e4f6584cSmrg	    for darwin_file in $darwin_filelist; do
5431b12e5c03Smrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
5432e4f6584cSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
5433e4f6584cSmrg	    done # $darwin_filelist
5434e4f6584cSmrg	    $RM -rf unfat-$$
5435e4f6584cSmrg	    cd "$darwin_orig_dir"
5436b698ba48Smrg	  else
5437e4f6584cSmrg	    cd $darwin_orig_dir
5438e4f6584cSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
5439e4f6584cSmrg	  fi # $darwin_arches
5440e4f6584cSmrg	} # !$opt_dry_run
5441e4f6584cSmrg	;;
5442e4f6584cSmrg      *)
5443e4f6584cSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
5444e4f6584cSmrg	;;
5445e4f6584cSmrg      esac
5446b12e5c03Smrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
5447e4f6584cSmrg    done
544809885543Smrg
5449f395c03eSmrg    func_extract_archives_result=$my_oldobjs
5450e4f6584cSmrg}
545109885543Smrg
545209885543Smrg
5453b12e5c03Smrg# func_emit_wrapper [arg=no]
5454b12e5c03Smrg#
5455b12e5c03Smrg# Emit a libtool wrapper script on stdout.
5456b12e5c03Smrg# Don't directly open a file because we may want to
5457b12e5c03Smrg# incorporate the script contents within a cygwin/mingw
5458b12e5c03Smrg# wrapper executable.  Must ONLY be called from within
5459b12e5c03Smrg# func_mode_link because it depends on a number of variables
5460b12e5c03Smrg# set therein.
5461e4f6584cSmrg#
5462b12e5c03Smrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5463b12e5c03Smrg# variable will take.  If 'yes', then the emitted script
5464f395c03eSmrg# will assume that the directory where it is stored is
5465b12e5c03Smrg# the $objdir directory.  This is a cygwin/mingw-specific
5466b12e5c03Smrg# behavior.
5467b12e5c03Smrgfunc_emit_wrapper ()
5468e4f6584cSmrg{
5469b12e5c03Smrg	func_emit_wrapper_arg1=${1-no}
5470b698ba48Smrg
5471e4f6584cSmrg	$ECHO "\
5472e4f6584cSmrg#! $SHELL
547309885543Smrg
5474e4f6584cSmrg# $output - temporary wrapper script for $objdir/$outputname
5475f395c03eSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5476e4f6584cSmrg#
5477e4f6584cSmrg# The $output program cannot be directly executed until all the libtool
5478e4f6584cSmrg# libraries that it depends on are installed.
5479e4f6584cSmrg#
5480e4f6584cSmrg# This wrapper script should never be moved out of the build directory.
5481e4f6584cSmrg# If it is, it will not operate correctly.
548209885543Smrg
5483e4f6584cSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
5484e4f6584cSmrg# metacharacters that are still active within double-quoted strings.
5485e4f6584cSmrgsed_quote_subst='$sed_quote_subst'
548609885543Smrg
5487e4f6584cSmrg# Be Bourne compatible
5488e4f6584cSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
5489e4f6584cSmrg  emulate sh
5490e4f6584cSmrg  NULLCMD=:
5491e4f6584cSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
5492e4f6584cSmrg  # is contrary to our usage.  Disable this feature.
5493e4f6584cSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
5494e4f6584cSmrg  setopt NO_GLOB_SUBST
5495e4f6584cSmrgelse
5496e4f6584cSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
5497e4f6584cSmrgfi
5498e4f6584cSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
5499e4f6584cSmrgDUALCASE=1; export DUALCASE # for MKS sh
550009885543Smrg
5501e4f6584cSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
5502e4f6584cSmrg# if CDPATH is set.
5503e4f6584cSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
550409885543Smrg
5505e4f6584cSmrgrelink_command=\"$relink_command\"
550609885543Smrg
5507e4f6584cSmrg# This environment variable determines our operation mode.
5508e4f6584cSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
5509e4f6584cSmrg  # install mode needs the following variables:
5510e4f6584cSmrg  generated_by_libtool_version='$macro_version'
5511e4f6584cSmrg  notinst_deplibs='$notinst_deplibs'
5512e4f6584cSmrgelse
5513e4f6584cSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
5514e4f6584cSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5515b12e5c03Smrg    file=\"\$0\""
5516b12e5c03Smrg
5517beef1b22Smrg    func_quote_arg pretty "$ECHO"
5518beef1b22Smrg    qECHO=$func_quote_arg_result
5519b12e5c03Smrg    $ECHO "\
5520b12e5c03Smrg
5521b12e5c03Smrg# A function that is used when there is no print builtin or printf.
5522b12e5c03Smrgfunc_fallback_echo ()
5523b12e5c03Smrg{
5524b12e5c03Smrg  eval 'cat <<_LTECHO_EOF
5525b12e5c03Smrg\$1
5526b12e5c03Smrg_LTECHO_EOF'
5527b12e5c03Smrg}
5528beef1b22Smrg    ECHO=$qECHO
5529b12e5c03Smrg  fi
5530b12e5c03Smrg
5531b12e5c03Smrg# Very basic option parsing. These options are (a) specific to
5532b12e5c03Smrg# the libtool wrapper, (b) are identical between the wrapper
5533f395c03eSmrg# /script/ and the wrapper /executable/ that is used only on
5534b12e5c03Smrg# windows platforms, and (c) all begin with the string "--lt-"
5535f395c03eSmrg# (application programs are unlikely to have options that match
5536b12e5c03Smrg# this pattern).
5537b12e5c03Smrg#
5538b12e5c03Smrg# There are only two supported options: --lt-debug and
5539b12e5c03Smrg# --lt-dump-script. There is, deliberately, no --lt-help.
5540b12e5c03Smrg#
5541b12e5c03Smrg# The first argument to this parsing function should be the
5542b12e5c03Smrg# script's $0 value, followed by "$@".
5543b12e5c03Smrglt_option_debug=
5544b12e5c03Smrgfunc_parse_lt_options ()
5545b12e5c03Smrg{
5546b12e5c03Smrg  lt_script_arg0=\$0
5547b12e5c03Smrg  shift
5548b12e5c03Smrg  for lt_opt
5549b12e5c03Smrg  do
5550b12e5c03Smrg    case \"\$lt_opt\" in
5551b12e5c03Smrg    --lt-debug) lt_option_debug=1 ;;
5552b12e5c03Smrg    --lt-dump-script)
5553b12e5c03Smrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5554b12e5c03Smrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5555b12e5c03Smrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5556b12e5c03Smrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5557b12e5c03Smrg        exit 0
5558b12e5c03Smrg      ;;
5559b12e5c03Smrg    --lt-*)
5560b12e5c03Smrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5561b12e5c03Smrg        exit 1
5562b12e5c03Smrg      ;;
5563b12e5c03Smrg    esac
5564b12e5c03Smrg  done
5565b12e5c03Smrg
5566b12e5c03Smrg  # Print the debug banner immediately:
5567b12e5c03Smrg  if test -n \"\$lt_option_debug\"; then
5568f395c03eSmrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5569b12e5c03Smrg  fi
5570b12e5c03Smrg}
5571b12e5c03Smrg
5572b12e5c03Smrg# Used when --lt-debug. Prints its arguments to stdout
5573b12e5c03Smrg# (redirection is the responsibility of the caller)
5574b12e5c03Smrgfunc_lt_dump_args ()
5575b12e5c03Smrg{
5576b12e5c03Smrg  lt_dump_args_N=1;
5577b12e5c03Smrg  for lt_arg
5578b12e5c03Smrg  do
5579f395c03eSmrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5580b12e5c03Smrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5581b12e5c03Smrg  done
5582b12e5c03Smrg}
5583b12e5c03Smrg
5584b12e5c03Smrg# Core function for launching the target application
5585b12e5c03Smrgfunc_exec_program_core ()
5586b12e5c03Smrg{
5587e4f6584cSmrg"
5588b12e5c03Smrg  case $host in
5589b12e5c03Smrg  # Backslashes separate directories on plain windows
5590b12e5c03Smrg  *-*-mingw | *-*-os2* | *-cegcc*)
5591b12e5c03Smrg    $ECHO "\
5592b12e5c03Smrg      if test -n \"\$lt_option_debug\"; then
5593f395c03eSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5594b12e5c03Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5595b12e5c03Smrg      fi
5596b12e5c03Smrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5597b12e5c03Smrg"
5598b12e5c03Smrg    ;;
5599b12e5c03Smrg
5600b12e5c03Smrg  *)
5601b12e5c03Smrg    $ECHO "\
5602b12e5c03Smrg      if test -n \"\$lt_option_debug\"; then
5603f395c03eSmrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5604b12e5c03Smrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5605b12e5c03Smrg      fi
5606b12e5c03Smrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5607b12e5c03Smrg"
5608b12e5c03Smrg    ;;
5609b12e5c03Smrg  esac
5610b12e5c03Smrg  $ECHO "\
5611b12e5c03Smrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5612b12e5c03Smrg      exit 1
5613b12e5c03Smrg}
5614b12e5c03Smrg
5615b12e5c03Smrg# A function to encapsulate launching the target application
5616b12e5c03Smrg# Strips options in the --lt-* namespace from \$@ and
5617b12e5c03Smrg# launches target application with the remaining arguments.
5618b12e5c03Smrgfunc_exec_program ()
5619b12e5c03Smrg{
5620b12e5c03Smrg  case \" \$* \" in
5621b12e5c03Smrg  *\\ --lt-*)
5622b12e5c03Smrg    for lt_wr_arg
5623b12e5c03Smrg    do
5624b12e5c03Smrg      case \$lt_wr_arg in
5625b12e5c03Smrg      --lt-*) ;;
5626b12e5c03Smrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
5627b12e5c03Smrg      esac
5628b12e5c03Smrg      shift
5629b12e5c03Smrg    done ;;
5630b12e5c03Smrg  esac
5631b12e5c03Smrg  func_exec_program_core \${1+\"\$@\"}
5632b12e5c03Smrg}
5633b12e5c03Smrg
5634b12e5c03Smrg  # Parse options
5635b12e5c03Smrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
563609885543Smrg
5637e4f6584cSmrg  # Find the directory that this script lives in.
5638b12e5c03Smrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
5639e4f6584cSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
564009885543Smrg
5641e4f6584cSmrg  # Follow symbolic links until we get to the real thisdir.
5642b12e5c03Smrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
5643e4f6584cSmrg  while test -n \"\$file\"; do
5644b12e5c03Smrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
564509885543Smrg
5646e4f6584cSmrg    # If there was a directory component, then change thisdir.
5647e4f6584cSmrg    if test \"x\$destdir\" != \"x\$file\"; then
5648e4f6584cSmrg      case \"\$destdir\" in
5649e4f6584cSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
5650e4f6584cSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5651b698ba48Smrg      esac
5652e4f6584cSmrg    fi
565309885543Smrg
5654b12e5c03Smrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5655b12e5c03Smrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
5656e4f6584cSmrg  done
565709885543Smrg
5658e4f6584cSmrg  # Usually 'no', except on cygwin/mingw when embedded into
5659e4f6584cSmrg  # the cwrapper.
5660b12e5c03Smrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
5661e4f6584cSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
5662e4f6584cSmrg    # special case for '.'
5663e4f6584cSmrg    if test \"\$thisdir\" = \".\"; then
5664e4f6584cSmrg      thisdir=\`pwd\`
5665e4f6584cSmrg    fi
5666e4f6584cSmrg    # remove .libs from thisdir
5667e4f6584cSmrg    case \"\$thisdir\" in
5668b12e5c03Smrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
5669e4f6584cSmrg    $objdir )   thisdir=. ;;
5670e4f6584cSmrg    esac
5671e4f6584cSmrg  fi
5672e4f6584cSmrg
5673e4f6584cSmrg  # Try to get the absolute directory name.
5674e4f6584cSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
5675e4f6584cSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
5676e4f6584cSmrg"
5677e4f6584cSmrg
5678f395c03eSmrg	if test yes = "$fast_install"; then
5679e4f6584cSmrg	  $ECHO "\
5680e4f6584cSmrg  program=lt-'$outputname'$exeext
5681e4f6584cSmrg  progdir=\"\$thisdir/$objdir\"
5682e4f6584cSmrg
5683e4f6584cSmrg  if test ! -f \"\$progdir/\$program\" ||
5684f395c03eSmrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
5685e4f6584cSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
5686e4f6584cSmrg
5687e4f6584cSmrg    file=\"\$\$-\$program\"
5688e4f6584cSmrg
5689e4f6584cSmrg    if test ! -d \"\$progdir\"; then
5690e4f6584cSmrg      $MKDIR \"\$progdir\"
5691e4f6584cSmrg    else
5692e4f6584cSmrg      $RM \"\$progdir/\$file\"
5693e4f6584cSmrg    fi"
5694e4f6584cSmrg
5695e4f6584cSmrg	  $ECHO "\
5696e4f6584cSmrg
5697e4f6584cSmrg    # relink executable if necessary
5698e4f6584cSmrg    if test -n \"\$relink_command\"; then
5699e4f6584cSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
5700e4f6584cSmrg      else
5701f395c03eSmrg	\$ECHO \"\$relink_command_output\" >&2
5702e4f6584cSmrg	$RM \"\$progdir/\$file\"
5703e4f6584cSmrg	exit 1
5704b698ba48Smrg      fi
5705e4f6584cSmrg    fi
570609885543Smrg
5707e4f6584cSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
5708e4f6584cSmrg    { $RM \"\$progdir/\$program\";
5709e4f6584cSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
5710e4f6584cSmrg    $RM \"\$progdir/\$file\"
5711e4f6584cSmrg  fi"
5712e4f6584cSmrg	else
5713e4f6584cSmrg	  $ECHO "\
5714e4f6584cSmrg  program='$outputname'
5715e4f6584cSmrg  progdir=\"\$thisdir/$objdir\"
5716e4f6584cSmrg"
5717b698ba48Smrg	fi
571809885543Smrg
5719e4f6584cSmrg	$ECHO "\
572009885543Smrg
5721e4f6584cSmrg  if test -f \"\$progdir/\$program\"; then"
572209885543Smrg
5723b12e5c03Smrg	# fixup the dll searchpath if we need to.
5724b12e5c03Smrg	#
5725b12e5c03Smrg	# Fix the DLL searchpath if we need to.  Do this before prepending
5726b12e5c03Smrg	# to shlibpath, because on Windows, both are PATH and uninstalled
5727b12e5c03Smrg	# libraries must come first.
5728b12e5c03Smrg	if test -n "$dllsearchpath"; then
5729b12e5c03Smrg	  $ECHO "\
5730b12e5c03Smrg    # Add the dll search path components to the executable PATH
5731b12e5c03Smrg    PATH=$dllsearchpath:\$PATH
5732b12e5c03Smrg"
5733b12e5c03Smrg	fi
5734b12e5c03Smrg
5735e4f6584cSmrg	# Export our shlibpath_var if we have one.
5736f395c03eSmrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5737e4f6584cSmrg	  $ECHO "\
5738e4f6584cSmrg    # Add our own library path to $shlibpath_var
5739e4f6584cSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5740e4f6584cSmrg
5741e4f6584cSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
5742e4f6584cSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
5743b12e5c03Smrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
574409885543Smrg
5745e4f6584cSmrg    export $shlibpath_var
5746e4f6584cSmrg"
5747b698ba48Smrg	fi
574809885543Smrg
5749e4f6584cSmrg	$ECHO "\
5750e4f6584cSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
5751e4f6584cSmrg      # Run the actual program with our arguments.
5752b12e5c03Smrg      func_exec_program \${1+\"\$@\"}
5753e4f6584cSmrg    fi
5754e4f6584cSmrg  else
5755e4f6584cSmrg    # The program doesn't exist.
5756f395c03eSmrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
5757e4f6584cSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5758b12e5c03Smrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
5759e4f6584cSmrg    exit 1
5760e4f6584cSmrg  fi
5761e4f6584cSmrgfi\
5762e4f6584cSmrg"
5763e4f6584cSmrg}
576409885543Smrg
57652ec8c4b4Smrg
5766e4f6584cSmrg# func_emit_cwrapperexe_src
5767e4f6584cSmrg# emit the source code for a wrapper executable on stdout
5768e4f6584cSmrg# Must ONLY be called from within func_mode_link because
5769e4f6584cSmrg# it depends on a number of variable set therein.
5770e4f6584cSmrgfunc_emit_cwrapperexe_src ()
5771e4f6584cSmrg{
5772e4f6584cSmrg	cat <<EOF
577309885543Smrg
5774e4f6584cSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5775f395c03eSmrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
577609885543Smrg
5777e4f6584cSmrg   The $output program cannot be directly executed until all the libtool
5778e4f6584cSmrg   libraries that it depends on are installed.
577909885543Smrg
5780e4f6584cSmrg   This wrapper executable should never be moved out of the build directory.
5781e4f6584cSmrg   If it is, it will not operate correctly.
5782e4f6584cSmrg*/
5783e4f6584cSmrgEOF
5784e4f6584cSmrg	    cat <<"EOF"
5785b12e5c03Smrg#ifdef _MSC_VER
5786b12e5c03Smrg# define _CRT_SECURE_NO_DEPRECATE 1
5787b12e5c03Smrg#endif
5788e4f6584cSmrg#include <stdio.h>
5789e4f6584cSmrg#include <stdlib.h>
5790e4f6584cSmrg#ifdef _MSC_VER
5791e4f6584cSmrg# include <direct.h>
5792e4f6584cSmrg# include <process.h>
5793e4f6584cSmrg# include <io.h>
5794e4f6584cSmrg#else
5795e4f6584cSmrg# include <unistd.h>
5796e4f6584cSmrg# include <stdint.h>
5797e4f6584cSmrg# ifdef __CYGWIN__
5798e4f6584cSmrg#  include <io.h>
5799e4f6584cSmrg# endif
5800e4f6584cSmrg#endif
5801e4f6584cSmrg#include <malloc.h>
5802e4f6584cSmrg#include <stdarg.h>
5803e4f6584cSmrg#include <assert.h>
5804e4f6584cSmrg#include <string.h>
5805e4f6584cSmrg#include <ctype.h>
5806e4f6584cSmrg#include <errno.h>
5807e4f6584cSmrg#include <fcntl.h>
5808e4f6584cSmrg#include <sys/stat.h>
580909885543Smrg
5810f395c03eSmrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5811f395c03eSmrg
5812b12e5c03Smrg/* declarations of non-ANSI functions */
5813f395c03eSmrg#if defined __MINGW32__
5814b12e5c03Smrg# ifdef __STRICT_ANSI__
5815b12e5c03Smrgint _putenv (const char *);
5816b12e5c03Smrg# endif
5817f395c03eSmrg#elif defined __CYGWIN__
5818b12e5c03Smrg# ifdef __STRICT_ANSI__
5819b12e5c03Smrgchar *realpath (const char *, char *);
5820b12e5c03Smrgint putenv (char *);
5821b12e5c03Smrgint setenv (const char *, const char *, int);
5822b12e5c03Smrg# endif
5823f395c03eSmrg/* #elif defined other_platform || defined ... */
5824b12e5c03Smrg#endif
5825b12e5c03Smrg
5826b12e5c03Smrg/* portability defines, excluding path handling macros */
5827f395c03eSmrg#if defined _MSC_VER
5828b12e5c03Smrg# define setmode _setmode
5829b12e5c03Smrg# define stat    _stat
5830b12e5c03Smrg# define chmod   _chmod
5831b12e5c03Smrg# define getcwd  _getcwd
5832b12e5c03Smrg# define putenv  _putenv
5833b12e5c03Smrg# define S_IXUSR _S_IEXEC
5834f395c03eSmrg#elif defined __MINGW32__
5835b12e5c03Smrg# define setmode _setmode
5836b12e5c03Smrg# define stat    _stat
5837b12e5c03Smrg# define chmod   _chmod
5838b12e5c03Smrg# define getcwd  _getcwd
5839b12e5c03Smrg# define putenv  _putenv
5840f395c03eSmrg#elif defined __CYGWIN__
5841b12e5c03Smrg# define HAVE_SETENV
5842b12e5c03Smrg# define FOPEN_WB "wb"
5843f395c03eSmrg/* #elif defined other platforms ... */
5844b12e5c03Smrg#endif
5845b12e5c03Smrg
5846f395c03eSmrg#if defined PATH_MAX
5847e4f6584cSmrg# define LT_PATHMAX PATH_MAX
5848f395c03eSmrg#elif defined MAXPATHLEN
5849e4f6584cSmrg# define LT_PATHMAX MAXPATHLEN
5850e4f6584cSmrg#else
5851e4f6584cSmrg# define LT_PATHMAX 1024
5852e4f6584cSmrg#endif
585309885543Smrg
5854e4f6584cSmrg#ifndef S_IXOTH
5855e4f6584cSmrg# define S_IXOTH 0
5856e4f6584cSmrg#endif
5857e4f6584cSmrg#ifndef S_IXGRP
5858e4f6584cSmrg# define S_IXGRP 0
5859e4f6584cSmrg#endif
586009885543Smrg
5861b12e5c03Smrg/* path handling portability macros */
5862e4f6584cSmrg#ifndef DIR_SEPARATOR
5863e4f6584cSmrg# define DIR_SEPARATOR '/'
5864e4f6584cSmrg# define PATH_SEPARATOR ':'
5865e4f6584cSmrg#endif
586609885543Smrg
5867f395c03eSmrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5868f395c03eSmrg  defined __OS2__
5869e4f6584cSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
5870e4f6584cSmrg# define FOPEN_WB "wb"
5871e4f6584cSmrg# ifndef DIR_SEPARATOR_2
5872e4f6584cSmrg#  define DIR_SEPARATOR_2 '\\'
5873e4f6584cSmrg# endif
5874e4f6584cSmrg# ifndef PATH_SEPARATOR_2
5875e4f6584cSmrg#  define PATH_SEPARATOR_2 ';'
5876e4f6584cSmrg# endif
5877e4f6584cSmrg#endif
587809885543Smrg
5879e4f6584cSmrg#ifndef DIR_SEPARATOR_2
5880e4f6584cSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
5881e4f6584cSmrg#else /* DIR_SEPARATOR_2 */
5882e4f6584cSmrg# define IS_DIR_SEPARATOR(ch) \
5883e4f6584cSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
5884e4f6584cSmrg#endif /* DIR_SEPARATOR_2 */
588509885543Smrg
5886e4f6584cSmrg#ifndef PATH_SEPARATOR_2
5887e4f6584cSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
5888e4f6584cSmrg#else /* PATH_SEPARATOR_2 */
5889e4f6584cSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
5890e4f6584cSmrg#endif /* PATH_SEPARATOR_2 */
589109885543Smrg
5892e4f6584cSmrg#ifndef FOPEN_WB
5893e4f6584cSmrg# define FOPEN_WB "w"
5894e4f6584cSmrg#endif
5895e4f6584cSmrg#ifndef _O_BINARY
5896e4f6584cSmrg# define _O_BINARY 0
5897e4f6584cSmrg#endif
589809885543Smrg
5899e4f6584cSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
5900e4f6584cSmrg#define XFREE(stale) do { \
5901f395c03eSmrg  if (stale) { free (stale); stale = 0; } \
5902e4f6584cSmrg} while (0)
590309885543Smrg
5904f395c03eSmrg#if defined LT_DEBUGWRAPPER
5905b12e5c03Smrgstatic int lt_debug = 1;
5906e4f6584cSmrg#else
5907b12e5c03Smrgstatic int lt_debug = 0;
5908e4f6584cSmrg#endif
590909885543Smrg
5910b12e5c03Smrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
591109885543Smrg
5912e4f6584cSmrgvoid *xmalloc (size_t num);
5913e4f6584cSmrgchar *xstrdup (const char *string);
5914e4f6584cSmrgconst char *base_name (const char *name);
5915e4f6584cSmrgchar *find_executable (const char *wrapper);
5916e4f6584cSmrgchar *chase_symlinks (const char *pathspec);
5917e4f6584cSmrgint make_executable (const char *path);
5918e4f6584cSmrgint check_executable (const char *path);
5919e4f6584cSmrgchar *strendzap (char *str, const char *pat);
5920b12e5c03Smrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5921b12e5c03Smrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5922b12e5c03Smrgstatic const char *nonnull (const char *s);
5923b12e5c03Smrgstatic const char *nonempty (const char *s);
5924e4f6584cSmrgvoid lt_setenv (const char *name, const char *value);
5925e4f6584cSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
5926e4f6584cSmrgvoid lt_update_exe_path (const char *name, const char *value);
5927e4f6584cSmrgvoid lt_update_lib_path (const char *name, const char *value);
5928b12e5c03Smrgchar **prepare_spawn (char **argv);
5929b12e5c03Smrgvoid lt_dump_script (FILE *f);
5930e4f6584cSmrgEOF
5931e4f6584cSmrg
5932e4f6584cSmrg	    cat <<EOF
5933f395c03eSmrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5934f395c03eSmrg# define externally_visible volatile
5935f395c03eSmrg#else
5936f395c03eSmrg# define externally_visible __attribute__((externally_visible)) volatile
5937f395c03eSmrg#endif
5938f395c03eSmrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
5939e4f6584cSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
5940e4f6584cSmrgEOF
594109885543Smrg
5942f395c03eSmrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
5943b12e5c03Smrg              func_to_host_path "$temp_rpath"
5944e4f6584cSmrg	      cat <<EOF
5945b12e5c03Smrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
5946e4f6584cSmrgEOF
5947e4f6584cSmrg	    else
5948e4f6584cSmrg	      cat <<"EOF"
5949e4f6584cSmrgconst char * LIB_PATH_VALUE   = "";
5950e4f6584cSmrgEOF
5951b698ba48Smrg	    fi
595209885543Smrg
5953e4f6584cSmrg	    if test -n "$dllsearchpath"; then
5954b12e5c03Smrg              func_to_host_path "$dllsearchpath:"
5955e4f6584cSmrg	      cat <<EOF
5956e4f6584cSmrgconst char * EXE_PATH_VARNAME = "PATH";
5957b12e5c03Smrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5958b698ba48SmrgEOF
5959b698ba48Smrg	    else
5960e4f6584cSmrg	      cat <<"EOF"
5961e4f6584cSmrgconst char * EXE_PATH_VARNAME = "";
5962e4f6584cSmrgconst char * EXE_PATH_VALUE   = "";
5963e4f6584cSmrgEOF
5964b698ba48Smrg	    fi
5965e4f6584cSmrg
5966f395c03eSmrg	    if test yes = "$fast_install"; then
5967e4f6584cSmrg	      cat <<EOF
5968e4f6584cSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
5969e4f6584cSmrgEOF
5970b698ba48Smrg	    else
5971e4f6584cSmrg	      cat <<EOF
5972e4f6584cSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
5973e4f6584cSmrgEOF
5974b698ba48Smrg	    fi
597509885543Smrg
597609885543Smrg
5977e4f6584cSmrg	    cat <<"EOF"
597809885543Smrg
5979e4f6584cSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
598009885543Smrg
5981e4f6584cSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
5982e4f6584cSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5983b12e5c03Smrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
598409885543Smrg
5985e4f6584cSmrgint
5986e4f6584cSmrgmain (int argc, char *argv[])
5987e4f6584cSmrg{
5988e4f6584cSmrg  char **newargz;
5989e4f6584cSmrg  int  newargc;
5990e4f6584cSmrg  char *tmp_pathspec;
5991e4f6584cSmrg  char *actual_cwrapper_path;
5992e4f6584cSmrg  char *actual_cwrapper_name;
5993e4f6584cSmrg  char *target_name;
5994e4f6584cSmrg  char *lt_argv_zero;
5995f395c03eSmrg  int rval = 127;
599609885543Smrg
5997e4f6584cSmrg  int i;
599809885543Smrg
5999e4f6584cSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
6000f395c03eSmrg  newargz = XMALLOC (char *, (size_t) argc + 1);
600109885543Smrg
6002b12e5c03Smrg  /* very simple arg parsing; don't want to rely on getopt
6003b12e5c03Smrg   * also, copy all non cwrapper options to newargz, except
6004b12e5c03Smrg   * argz[0], which is handled differently
6005b12e5c03Smrg   */
6006b12e5c03Smrg  newargc=0;
6007e4f6584cSmrg  for (i = 1; i < argc; i++)
6008e4f6584cSmrg    {
6009f395c03eSmrg      if (STREQ (argv[i], dumpscript_opt))
6010e4f6584cSmrg	{
6011e4f6584cSmrgEOF
6012f395c03eSmrg	    case $host in
6013e4f6584cSmrg	      *mingw* | *cygwin* )
6014e4f6584cSmrg		# make stdout use "unix" line endings
6015e4f6584cSmrg		echo "          setmode(1,_O_BINARY);"
6016e4f6584cSmrg		;;
6017e4f6584cSmrg	      esac
601809885543Smrg
6019e4f6584cSmrg	    cat <<"EOF"
6020b12e5c03Smrg	  lt_dump_script (stdout);
6021e4f6584cSmrg	  return 0;
6022e4f6584cSmrg	}
6023f395c03eSmrg      if (STREQ (argv[i], debug_opt))
6024b12e5c03Smrg	{
6025b12e5c03Smrg          lt_debug = 1;
6026b12e5c03Smrg          continue;
6027b12e5c03Smrg	}
6028f395c03eSmrg      if (STREQ (argv[i], ltwrapper_option_prefix))
6029b12e5c03Smrg        {
6030b12e5c03Smrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
6031b12e5c03Smrg             namespace, but it is not one of the ones we know about and
6032b12e5c03Smrg             have already dealt with, above (inluding dump-script), then
6033b12e5c03Smrg             report an error. Otherwise, targets might begin to believe
6034b12e5c03Smrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
6035b12e5c03Smrg             namespace. The first time any user complains about this, we'll
6036b12e5c03Smrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
6037b12e5c03Smrg             or a configure.ac-settable value.
6038b12e5c03Smrg           */
6039b12e5c03Smrg          lt_fatal (__FILE__, __LINE__,
6040b12e5c03Smrg		    "unrecognized %s option: '%s'",
6041b12e5c03Smrg                    ltwrapper_option_prefix, argv[i]);
6042b12e5c03Smrg        }
6043b12e5c03Smrg      /* otherwise ... */
6044b12e5c03Smrg      newargz[++newargc] = xstrdup (argv[i]);
6045e4f6584cSmrg    }
6046b12e5c03Smrg  newargz[++newargc] = NULL;
6047b12e5c03Smrg
6048b12e5c03SmrgEOF
6049b12e5c03Smrg	    cat <<EOF
6050b12e5c03Smrg  /* The GNU banner must be the first non-error debug message */
6051f395c03eSmrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
6052b12e5c03SmrgEOF
6053b12e5c03Smrg	    cat <<"EOF"
6054b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
6055b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
605609885543Smrg
6057e4f6584cSmrg  tmp_pathspec = find_executable (argv[0]);
6058e4f6584cSmrg  if (tmp_pathspec == NULL)
6059b12e5c03Smrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
6060b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__,
6061b12e5c03Smrg                  "(main) found exe (before symlink chase) at: %s\n",
6062b12e5c03Smrg		  tmp_pathspec);
6063e4f6584cSmrg
6064e4f6584cSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
6065b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__,
6066b12e5c03Smrg                  "(main) found exe (after symlink chase) at: %s\n",
6067b12e5c03Smrg		  actual_cwrapper_path);
6068e4f6584cSmrg  XFREE (tmp_pathspec);
6069e4f6584cSmrg
6070b12e5c03Smrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
6071e4f6584cSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
6072e4f6584cSmrg
6073e4f6584cSmrg  /* wrapper name transforms */
6074e4f6584cSmrg  strendzap (actual_cwrapper_name, ".exe");
6075e4f6584cSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
6076e4f6584cSmrg  XFREE (actual_cwrapper_name);
6077e4f6584cSmrg  actual_cwrapper_name = tmp_pathspec;
6078e4f6584cSmrg  tmp_pathspec = 0;
6079e4f6584cSmrg
6080e4f6584cSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
6081e4f6584cSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
6082e4f6584cSmrg  strendzap (target_name, ".exe");
6083e4f6584cSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
6084e4f6584cSmrg  XFREE (target_name);
6085e4f6584cSmrg  target_name = tmp_pathspec;
6086e4f6584cSmrg  tmp_pathspec = 0;
6087e4f6584cSmrg
6088b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__,
6089b12e5c03Smrg		  "(main) libtool target name: %s\n",
6090b12e5c03Smrg		  target_name);
6091e4f6584cSmrgEOF
609209885543Smrg
6093e4f6584cSmrg	    cat <<EOF
6094e4f6584cSmrg  newargz[0] =
6095e4f6584cSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
6096e4f6584cSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
6097e4f6584cSmrg  strcpy (newargz[0], actual_cwrapper_path);
6098e4f6584cSmrg  strcat (newargz[0], "$objdir");
6099e4f6584cSmrg  strcat (newargz[0], "/");
6100e4f6584cSmrgEOF
610109885543Smrg
6102e4f6584cSmrg	    cat <<"EOF"
6103e4f6584cSmrg  /* stop here, and copy so we don't have to do this twice */
6104e4f6584cSmrg  tmp_pathspec = xstrdup (newargz[0]);
610509885543Smrg
6106e4f6584cSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
6107e4f6584cSmrg  strcat (newargz[0], actual_cwrapper_name);
610809885543Smrg
6109e4f6584cSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
6110e4f6584cSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
6111e4f6584cSmrg  XFREE (tmp_pathspec);
6112e4f6584cSmrg  tmp_pathspec = NULL;
6113e4f6584cSmrgEOF
611409885543Smrg
6115e4f6584cSmrg	    case $host_os in
6116e4f6584cSmrg	      mingw*)
6117e4f6584cSmrg	    cat <<"EOF"
6118e4f6584cSmrg  {
6119e4f6584cSmrg    char* p;
6120e4f6584cSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
6121e4f6584cSmrg      {
6122e4f6584cSmrg	*p = '/';
6123e4f6584cSmrg      }
6124e4f6584cSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
6125e4f6584cSmrg      {
6126e4f6584cSmrg	*p = '/';
6127e4f6584cSmrg      }
6128e4f6584cSmrg  }
6129e4f6584cSmrgEOF
6130e4f6584cSmrg	    ;;
6131e4f6584cSmrg	    esac
613209885543Smrg
6133e4f6584cSmrg	    cat <<"EOF"
6134e4f6584cSmrg  XFREE (target_name);
6135e4f6584cSmrg  XFREE (actual_cwrapper_path);
6136e4f6584cSmrg  XFREE (actual_cwrapper_name);
613709885543Smrg
6138e4f6584cSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
6139e4f6584cSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
6140b12e5c03Smrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
6141b12e5c03Smrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
6142b12e5c03Smrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
6143b12e5c03Smrg     libraries must come first. */
6144e4f6584cSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
6145b12e5c03Smrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
614609885543Smrg
6147b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
6148b12e5c03Smrg		  nonnull (lt_argv_zero));
6149e4f6584cSmrg  for (i = 0; i < newargc; i++)
6150e4f6584cSmrg    {
6151b12e5c03Smrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
6152b12e5c03Smrg		      i, nonnull (newargz[i]));
6153e4f6584cSmrg    }
615409885543Smrg
6155e4f6584cSmrgEOF
615609885543Smrg
6157e4f6584cSmrg	    case $host_os in
6158e4f6584cSmrg	      mingw*)
6159e4f6584cSmrg		cat <<"EOF"
6160e4f6584cSmrg  /* execv doesn't actually work on mingw as expected on unix */
6161b12e5c03Smrg  newargz = prepare_spawn (newargz);
6162f395c03eSmrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
6163e4f6584cSmrg  if (rval == -1)
6164e4f6584cSmrg    {
6165e4f6584cSmrg      /* failed to start process */
6166b12e5c03Smrg      lt_debugprintf (__FILE__, __LINE__,
6167b12e5c03Smrg		      "(main) failed to launch target \"%s\": %s\n",
6168b12e5c03Smrg		      lt_argv_zero, nonnull (strerror (errno)));
6169e4f6584cSmrg      return 127;
6170e4f6584cSmrg    }
6171e4f6584cSmrg  return rval;
6172e4f6584cSmrgEOF
6173e4f6584cSmrg		;;
6174e4f6584cSmrg	      *)
6175e4f6584cSmrg		cat <<"EOF"
6176e4f6584cSmrg  execv (lt_argv_zero, newargz);
6177e4f6584cSmrg  return rval; /* =127, but avoids unused variable warning */
6178e4f6584cSmrgEOF
6179e4f6584cSmrg		;;
6180e4f6584cSmrg	    esac
618109885543Smrg
6182e4f6584cSmrg	    cat <<"EOF"
6183e4f6584cSmrg}
618409885543Smrg
6185e4f6584cSmrgvoid *
6186e4f6584cSmrgxmalloc (size_t num)
6187e4f6584cSmrg{
6188e4f6584cSmrg  void *p = (void *) malloc (num);
6189e4f6584cSmrg  if (!p)
6190b12e5c03Smrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
619109885543Smrg
6192e4f6584cSmrg  return p;
6193e4f6584cSmrg}
619409885543Smrg
6195e4f6584cSmrgchar *
6196e4f6584cSmrgxstrdup (const char *string)
6197e4f6584cSmrg{
6198e4f6584cSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
6199e4f6584cSmrg			  string) : NULL;
6200e4f6584cSmrg}
620109885543Smrg
6202e4f6584cSmrgconst char *
6203e4f6584cSmrgbase_name (const char *name)
6204e4f6584cSmrg{
6205e4f6584cSmrg  const char *base;
6206b698ba48Smrg
6207f395c03eSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6208e4f6584cSmrg  /* Skip over the disk name in MSDOS pathnames. */
6209e4f6584cSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
6210e4f6584cSmrg    name += 2;
6211e4f6584cSmrg#endif
6212b698ba48Smrg
6213e4f6584cSmrg  for (base = name; *name; name++)
6214e4f6584cSmrg    if (IS_DIR_SEPARATOR (*name))
6215e4f6584cSmrg      base = name + 1;
6216e4f6584cSmrg  return base;
6217e4f6584cSmrg}
6218b698ba48Smrg
6219e4f6584cSmrgint
6220e4f6584cSmrgcheck_executable (const char *path)
6221e4f6584cSmrg{
6222e4f6584cSmrg  struct stat st;
6223b698ba48Smrg
6224b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
6225b12e5c03Smrg                  nonempty (path));
6226e4f6584cSmrg  if ((!path) || (!*path))
6227e4f6584cSmrg    return 0;
6228b698ba48Smrg
6229e4f6584cSmrg  if ((stat (path, &st) >= 0)
6230e4f6584cSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
6231e4f6584cSmrg    return 1;
6232e4f6584cSmrg  else
6233e4f6584cSmrg    return 0;
6234e4f6584cSmrg}
623509885543Smrg
6236e4f6584cSmrgint
6237e4f6584cSmrgmake_executable (const char *path)
6238e4f6584cSmrg{
6239e4f6584cSmrg  int rval = 0;
6240e4f6584cSmrg  struct stat st;
624109885543Smrg
6242b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
6243b12e5c03Smrg                  nonempty (path));
6244e4f6584cSmrg  if ((!path) || (!*path))
6245e4f6584cSmrg    return 0;
62462ec8c4b4Smrg
6247e4f6584cSmrg  if (stat (path, &st) >= 0)
6248e4f6584cSmrg    {
6249e4f6584cSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
6250e4f6584cSmrg    }
6251e4f6584cSmrg  return rval;
6252e4f6584cSmrg}
6253b698ba48Smrg
6254e4f6584cSmrg/* Searches for the full path of the wrapper.  Returns
6255e4f6584cSmrg   newly allocated full path name if found, NULL otherwise
6256e4f6584cSmrg   Does not chase symlinks, even on platforms that support them.
6257e4f6584cSmrg*/
6258e4f6584cSmrgchar *
6259e4f6584cSmrgfind_executable (const char *wrapper)
6260e4f6584cSmrg{
6261e4f6584cSmrg  int has_slash = 0;
6262e4f6584cSmrg  const char *p;
6263e4f6584cSmrg  const char *p_next;
6264e4f6584cSmrg  /* static buffer for getcwd */
6265e4f6584cSmrg  char tmp[LT_PATHMAX + 1];
6266f395c03eSmrg  size_t tmp_len;
6267e4f6584cSmrg  char *concat_name;
6268b698ba48Smrg
6269b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6270b12e5c03Smrg                  nonempty (wrapper));
6271b698ba48Smrg
6272e4f6584cSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
6273e4f6584cSmrg    return NULL;
6274b698ba48Smrg
6275e4f6584cSmrg  /* Absolute path? */
6276f395c03eSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6277e4f6584cSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
6278e4f6584cSmrg    {
6279e4f6584cSmrg      concat_name = xstrdup (wrapper);
6280e4f6584cSmrg      if (check_executable (concat_name))
6281e4f6584cSmrg	return concat_name;
6282e4f6584cSmrg      XFREE (concat_name);
6283e4f6584cSmrg    }
6284e4f6584cSmrg  else
6285e4f6584cSmrg    {
6286e4f6584cSmrg#endif
6287e4f6584cSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
6288e4f6584cSmrg	{
6289e4f6584cSmrg	  concat_name = xstrdup (wrapper);
6290e4f6584cSmrg	  if (check_executable (concat_name))
6291e4f6584cSmrg	    return concat_name;
6292e4f6584cSmrg	  XFREE (concat_name);
6293e4f6584cSmrg	}
6294f395c03eSmrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
6295e4f6584cSmrg    }
6296e4f6584cSmrg#endif
629709885543Smrg
6298e4f6584cSmrg  for (p = wrapper; *p; p++)
6299e4f6584cSmrg    if (*p == '/')
6300e4f6584cSmrg      {
6301e4f6584cSmrg	has_slash = 1;
6302e4f6584cSmrg	break;
6303e4f6584cSmrg      }
6304e4f6584cSmrg  if (!has_slash)
6305e4f6584cSmrg    {
6306e4f6584cSmrg      /* no slashes; search PATH */
6307e4f6584cSmrg      const char *path = getenv ("PATH");
6308e4f6584cSmrg      if (path != NULL)
6309e4f6584cSmrg	{
6310e4f6584cSmrg	  for (p = path; *p; p = p_next)
6311e4f6584cSmrg	    {
6312e4f6584cSmrg	      const char *q;
6313e4f6584cSmrg	      size_t p_len;
6314e4f6584cSmrg	      for (q = p; *q; q++)
6315e4f6584cSmrg		if (IS_PATH_SEPARATOR (*q))
6316e4f6584cSmrg		  break;
6317f395c03eSmrg	      p_len = (size_t) (q - p);
6318e4f6584cSmrg	      p_next = (*q == '\0' ? q : q + 1);
6319e4f6584cSmrg	      if (p_len == 0)
6320e4f6584cSmrg		{
6321e4f6584cSmrg		  /* empty path: current directory */
6322e4f6584cSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6323b12e5c03Smrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6324b12e5c03Smrg                              nonnull (strerror (errno)));
6325e4f6584cSmrg		  tmp_len = strlen (tmp);
6326e4f6584cSmrg		  concat_name =
6327e4f6584cSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6328e4f6584cSmrg		  memcpy (concat_name, tmp, tmp_len);
6329e4f6584cSmrg		  concat_name[tmp_len] = '/';
6330e4f6584cSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
6331e4f6584cSmrg		}
6332e4f6584cSmrg	      else
6333e4f6584cSmrg		{
6334e4f6584cSmrg		  concat_name =
6335e4f6584cSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
6336e4f6584cSmrg		  memcpy (concat_name, p, p_len);
6337e4f6584cSmrg		  concat_name[p_len] = '/';
6338e4f6584cSmrg		  strcpy (concat_name + p_len + 1, wrapper);
6339e4f6584cSmrg		}
6340e4f6584cSmrg	      if (check_executable (concat_name))
6341e4f6584cSmrg		return concat_name;
6342e4f6584cSmrg	      XFREE (concat_name);
6343e4f6584cSmrg	    }
6344e4f6584cSmrg	}
6345e4f6584cSmrg      /* not found in PATH; assume curdir */
6346e4f6584cSmrg    }
6347e4f6584cSmrg  /* Relative path | not found in path: prepend cwd */
6348e4f6584cSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6349b12e5c03Smrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6350b12e5c03Smrg              nonnull (strerror (errno)));
6351e4f6584cSmrg  tmp_len = strlen (tmp);
6352e4f6584cSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
6353e4f6584cSmrg  memcpy (concat_name, tmp, tmp_len);
6354e4f6584cSmrg  concat_name[tmp_len] = '/';
6355e4f6584cSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
635609885543Smrg
6357e4f6584cSmrg  if (check_executable (concat_name))
6358e4f6584cSmrg    return concat_name;
6359e4f6584cSmrg  XFREE (concat_name);
6360e4f6584cSmrg  return NULL;
6361e4f6584cSmrg}
636209885543Smrg
6363e4f6584cSmrgchar *
6364e4f6584cSmrgchase_symlinks (const char *pathspec)
6365e4f6584cSmrg{
6366e4f6584cSmrg#ifndef S_ISLNK
6367e4f6584cSmrg  return xstrdup (pathspec);
6368e4f6584cSmrg#else
6369e4f6584cSmrg  char buf[LT_PATHMAX];
6370e4f6584cSmrg  struct stat s;
6371e4f6584cSmrg  char *tmp_pathspec = xstrdup (pathspec);
6372e4f6584cSmrg  char *p;
6373e4f6584cSmrg  int has_symlinks = 0;
6374e4f6584cSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
6375e4f6584cSmrg    {
6376b12e5c03Smrg      lt_debugprintf (__FILE__, __LINE__,
6377b12e5c03Smrg		      "checking path component for symlinks: %s\n",
6378b12e5c03Smrg		      tmp_pathspec);
6379e4f6584cSmrg      if (lstat (tmp_pathspec, &s) == 0)
6380e4f6584cSmrg	{
6381e4f6584cSmrg	  if (S_ISLNK (s.st_mode) != 0)
6382e4f6584cSmrg	    {
6383e4f6584cSmrg	      has_symlinks = 1;
6384e4f6584cSmrg	      break;
6385e4f6584cSmrg	    }
638609885543Smrg
6387e4f6584cSmrg	  /* search backwards for last DIR_SEPARATOR */
6388e4f6584cSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
6389e4f6584cSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6390e4f6584cSmrg	    p--;
6391e4f6584cSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
6392e4f6584cSmrg	    {
6393e4f6584cSmrg	      /* no more DIR_SEPARATORS left */
6394e4f6584cSmrg	      break;
6395e4f6584cSmrg	    }
6396e4f6584cSmrg	  *p = '\0';
6397e4f6584cSmrg	}
6398e4f6584cSmrg      else
6399e4f6584cSmrg	{
6400b12e5c03Smrg	  lt_fatal (__FILE__, __LINE__,
6401b12e5c03Smrg		    "error accessing file \"%s\": %s",
6402b12e5c03Smrg		    tmp_pathspec, nonnull (strerror (errno)));
6403e4f6584cSmrg	}
6404e4f6584cSmrg    }
6405e4f6584cSmrg  XFREE (tmp_pathspec);
640609885543Smrg
6407e4f6584cSmrg  if (!has_symlinks)
6408e4f6584cSmrg    {
6409e4f6584cSmrg      return xstrdup (pathspec);
6410e4f6584cSmrg    }
641109885543Smrg
6412e4f6584cSmrg  tmp_pathspec = realpath (pathspec, buf);
6413e4f6584cSmrg  if (tmp_pathspec == 0)
6414e4f6584cSmrg    {
6415b12e5c03Smrg      lt_fatal (__FILE__, __LINE__,
6416b12e5c03Smrg		"could not follow symlinks for %s", pathspec);
6417e4f6584cSmrg    }
6418e4f6584cSmrg  return xstrdup (tmp_pathspec);
6419e4f6584cSmrg#endif
6420e4f6584cSmrg}
642109885543Smrg
6422e4f6584cSmrgchar *
6423e4f6584cSmrgstrendzap (char *str, const char *pat)
6424e4f6584cSmrg{
6425e4f6584cSmrg  size_t len, patlen;
642609885543Smrg
6427e4f6584cSmrg  assert (str != NULL);
6428e4f6584cSmrg  assert (pat != NULL);
642909885543Smrg
6430e4f6584cSmrg  len = strlen (str);
6431e4f6584cSmrg  patlen = strlen (pat);
643209885543Smrg
6433e4f6584cSmrg  if (patlen <= len)
6434e4f6584cSmrg    {
6435e4f6584cSmrg      str += len - patlen;
6436f395c03eSmrg      if (STREQ (str, pat))
6437e4f6584cSmrg	*str = '\0';
6438e4f6584cSmrg    }
6439e4f6584cSmrg  return str;
6440e4f6584cSmrg}
644109885543Smrg
6442b12e5c03Smrgvoid
6443b12e5c03Smrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6444b12e5c03Smrg{
6445b12e5c03Smrg  va_list args;
6446b12e5c03Smrg  if (lt_debug)
6447b12e5c03Smrg    {
6448b12e5c03Smrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6449b12e5c03Smrg      va_start (args, fmt);
6450b12e5c03Smrg      (void) vfprintf (stderr, fmt, args);
6451b12e5c03Smrg      va_end (args);
6452b12e5c03Smrg    }
6453b12e5c03Smrg}
6454b12e5c03Smrg
6455e4f6584cSmrgstatic void
6456b12e5c03Smrglt_error_core (int exit_status, const char *file,
6457b12e5c03Smrg	       int line, const char *mode,
6458e4f6584cSmrg	       const char *message, va_list ap)
6459e4f6584cSmrg{
6460b12e5c03Smrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
6461e4f6584cSmrg  vfprintf (stderr, message, ap);
6462e4f6584cSmrg  fprintf (stderr, ".\n");
646309885543Smrg
6464e4f6584cSmrg  if (exit_status >= 0)
6465e4f6584cSmrg    exit (exit_status);
6466e4f6584cSmrg}
646709885543Smrg
6468e4f6584cSmrgvoid
6469b12e5c03Smrglt_fatal (const char *file, int line, const char *message, ...)
6470e4f6584cSmrg{
6471e4f6584cSmrg  va_list ap;
6472e4f6584cSmrg  va_start (ap, message);
6473b12e5c03Smrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
6474e4f6584cSmrg  va_end (ap);
6475e4f6584cSmrg}
647609885543Smrg
6477b12e5c03Smrgstatic const char *
6478b12e5c03Smrgnonnull (const char *s)
6479b12e5c03Smrg{
6480b12e5c03Smrg  return s ? s : "(null)";
6481b12e5c03Smrg}
6482b12e5c03Smrg
6483b12e5c03Smrgstatic const char *
6484b12e5c03Smrgnonempty (const char *s)
6485b12e5c03Smrg{
6486b12e5c03Smrg  return (s && !*s) ? "(empty)" : nonnull (s);
6487b12e5c03Smrg}
6488b12e5c03Smrg
6489e4f6584cSmrgvoid
6490e4f6584cSmrglt_setenv (const char *name, const char *value)
6491e4f6584cSmrg{
6492b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__,
6493b12e5c03Smrg		  "(lt_setenv) setting '%s' to '%s'\n",
6494b12e5c03Smrg                  nonnull (name), nonnull (value));
6495e4f6584cSmrg  {
6496e4f6584cSmrg#ifdef HAVE_SETENV
6497e4f6584cSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
6498e4f6584cSmrg    char *str = xstrdup (value);
6499e4f6584cSmrg    setenv (name, str, 1);
6500e4f6584cSmrg#else
6501f395c03eSmrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
6502e4f6584cSmrg    char *str = XMALLOC (char, len);
6503e4f6584cSmrg    sprintf (str, "%s=%s", name, value);
6504e4f6584cSmrg    if (putenv (str) != EXIT_SUCCESS)
6505e4f6584cSmrg      {
6506e4f6584cSmrg        XFREE (str);
6507e4f6584cSmrg      }
6508e4f6584cSmrg#endif
6509e4f6584cSmrg  }
6510e4f6584cSmrg}
651109885543Smrg
6512e4f6584cSmrgchar *
6513e4f6584cSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
6514e4f6584cSmrg{
6515e4f6584cSmrg  char *new_value;
6516e4f6584cSmrg  if (orig_value && *orig_value)
6517e4f6584cSmrg    {
6518f395c03eSmrg      size_t orig_value_len = strlen (orig_value);
6519f395c03eSmrg      size_t add_len = strlen (add);
6520e4f6584cSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
6521e4f6584cSmrg      if (to_end)
6522e4f6584cSmrg        {
6523e4f6584cSmrg          strcpy (new_value, orig_value);
6524e4f6584cSmrg          strcpy (new_value + orig_value_len, add);
6525e4f6584cSmrg        }
6526e4f6584cSmrg      else
6527e4f6584cSmrg        {
6528e4f6584cSmrg          strcpy (new_value, add);
6529e4f6584cSmrg          strcpy (new_value + add_len, orig_value);
6530e4f6584cSmrg        }
6531e4f6584cSmrg    }
6532e4f6584cSmrg  else
6533e4f6584cSmrg    {
6534e4f6584cSmrg      new_value = xstrdup (add);
6535e4f6584cSmrg    }
6536e4f6584cSmrg  return new_value;
6537e4f6584cSmrg}
653809885543Smrg
6539e4f6584cSmrgvoid
6540e4f6584cSmrglt_update_exe_path (const char *name, const char *value)
6541e4f6584cSmrg{
6542b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__,
6543b12e5c03Smrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6544b12e5c03Smrg                  nonnull (name), nonnull (value));
654509885543Smrg
6546e4f6584cSmrg  if (name && *name && value && *value)
6547e4f6584cSmrg    {
6548e4f6584cSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6549e4f6584cSmrg      /* some systems can't cope with a ':'-terminated path #' */
6550f395c03eSmrg      size_t len = strlen (new_value);
6551f395c03eSmrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
6552e4f6584cSmrg        {
6553f395c03eSmrg          new_value[--len] = '\0';
6554e4f6584cSmrg        }
6555e4f6584cSmrg      lt_setenv (name, new_value);
6556e4f6584cSmrg      XFREE (new_value);
6557e4f6584cSmrg    }
6558e4f6584cSmrg}
655909885543Smrg
6560e4f6584cSmrgvoid
6561e4f6584cSmrglt_update_lib_path (const char *name, const char *value)
6562e4f6584cSmrg{
6563b12e5c03Smrg  lt_debugprintf (__FILE__, __LINE__,
6564b12e5c03Smrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6565b12e5c03Smrg                  nonnull (name), nonnull (value));
656609885543Smrg
6567e4f6584cSmrg  if (name && *name && value && *value)
6568e4f6584cSmrg    {
6569e4f6584cSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
6570e4f6584cSmrg      lt_setenv (name, new_value);
6571e4f6584cSmrg      XFREE (new_value);
6572e4f6584cSmrg    }
6573e4f6584cSmrg}
657409885543Smrg
6575b12e5c03SmrgEOF
6576b12e5c03Smrg	    case $host_os in
6577b12e5c03Smrg	      mingw*)
6578b12e5c03Smrg		cat <<"EOF"
6579b12e5c03Smrg
6580b12e5c03Smrg/* Prepares an argument vector before calling spawn().
6581b12e5c03Smrg   Note that spawn() does not by itself call the command interpreter
6582b12e5c03Smrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6583b12e5c03Smrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6584b12e5c03Smrg         GetVersionEx(&v);
6585b12e5c03Smrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6586b12e5c03Smrg      }) ? "cmd.exe" : "command.com").
6587b12e5c03Smrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6588b12e5c03Smrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6589b12e5c03Smrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6590b12e5c03Smrg   special way:
6591b12e5c03Smrg   - Space and tab are interpreted as delimiters. They are not treated as
6592b12e5c03Smrg     delimiters if they are surrounded by double quotes: "...".
6593b12e5c03Smrg   - Unescaped double quotes are removed from the input. Their only effect is
6594b12e5c03Smrg     that within double quotes, space and tab are treated like normal
6595b12e5c03Smrg     characters.
6596b12e5c03Smrg   - Backslashes not followed by double quotes are not special.
6597b12e5c03Smrg   - But 2*n+1 backslashes followed by a double quote become
6598b12e5c03Smrg     n backslashes followed by a double quote (n >= 0):
6599b12e5c03Smrg       \" -> "
6600b12e5c03Smrg       \\\" -> \"
6601b12e5c03Smrg       \\\\\" -> \\"
6602b12e5c03Smrg */
6603b12e5c03Smrg#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"
6604b12e5c03Smrg#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"
6605b12e5c03Smrgchar **
6606b12e5c03Smrgprepare_spawn (char **argv)
6607b12e5c03Smrg{
6608b12e5c03Smrg  size_t argc;
6609b12e5c03Smrg  char **new_argv;
6610b12e5c03Smrg  size_t i;
6611b12e5c03Smrg
6612b12e5c03Smrg  /* Count number of arguments.  */
6613b12e5c03Smrg  for (argc = 0; argv[argc] != NULL; argc++)
6614b12e5c03Smrg    ;
6615b12e5c03Smrg
6616b12e5c03Smrg  /* Allocate new argument vector.  */
6617b12e5c03Smrg  new_argv = XMALLOC (char *, argc + 1);
6618b12e5c03Smrg
6619b12e5c03Smrg  /* Put quoted arguments into the new argument vector.  */
6620b12e5c03Smrg  for (i = 0; i < argc; i++)
6621b12e5c03Smrg    {
6622b12e5c03Smrg      const char *string = argv[i];
6623b12e5c03Smrg
6624b12e5c03Smrg      if (string[0] == '\0')
6625b12e5c03Smrg	new_argv[i] = xstrdup ("\"\"");
6626b12e5c03Smrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6627b12e5c03Smrg	{
6628b12e5c03Smrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6629b12e5c03Smrg	  size_t length;
6630b12e5c03Smrg	  unsigned int backslashes;
6631b12e5c03Smrg	  const char *s;
6632b12e5c03Smrg	  char *quoted_string;
6633b12e5c03Smrg	  char *p;
6634b12e5c03Smrg
6635b12e5c03Smrg	  length = 0;
6636b12e5c03Smrg	  backslashes = 0;
6637b12e5c03Smrg	  if (quote_around)
6638b12e5c03Smrg	    length++;
6639b12e5c03Smrg	  for (s = string; *s != '\0'; s++)
6640b12e5c03Smrg	    {
6641b12e5c03Smrg	      char c = *s;
6642b12e5c03Smrg	      if (c == '"')
6643b12e5c03Smrg		length += backslashes + 1;
6644b12e5c03Smrg	      length++;
6645b12e5c03Smrg	      if (c == '\\')
6646b12e5c03Smrg		backslashes++;
6647b12e5c03Smrg	      else
6648b12e5c03Smrg		backslashes = 0;
6649b12e5c03Smrg	    }
6650b12e5c03Smrg	  if (quote_around)
6651b12e5c03Smrg	    length += backslashes + 1;
6652b12e5c03Smrg
6653b12e5c03Smrg	  quoted_string = XMALLOC (char, length + 1);
6654b12e5c03Smrg
6655b12e5c03Smrg	  p = quoted_string;
6656b12e5c03Smrg	  backslashes = 0;
6657b12e5c03Smrg	  if (quote_around)
6658b12e5c03Smrg	    *p++ = '"';
6659b12e5c03Smrg	  for (s = string; *s != '\0'; s++)
6660b12e5c03Smrg	    {
6661b12e5c03Smrg	      char c = *s;
6662b12e5c03Smrg	      if (c == '"')
6663b12e5c03Smrg		{
6664b12e5c03Smrg		  unsigned int j;
6665b12e5c03Smrg		  for (j = backslashes + 1; j > 0; j--)
6666b12e5c03Smrg		    *p++ = '\\';
6667b12e5c03Smrg		}
6668b12e5c03Smrg	      *p++ = c;
6669b12e5c03Smrg	      if (c == '\\')
6670b12e5c03Smrg		backslashes++;
6671b12e5c03Smrg	      else
6672b12e5c03Smrg		backslashes = 0;
6673b12e5c03Smrg	    }
6674b12e5c03Smrg	  if (quote_around)
6675b12e5c03Smrg	    {
6676b12e5c03Smrg	      unsigned int j;
6677b12e5c03Smrg	      for (j = backslashes; j > 0; j--)
6678b12e5c03Smrg		*p++ = '\\';
6679b12e5c03Smrg	      *p++ = '"';
6680b12e5c03Smrg	    }
6681b12e5c03Smrg	  *p = '\0';
6682b12e5c03Smrg
6683b12e5c03Smrg	  new_argv[i] = quoted_string;
6684b12e5c03Smrg	}
6685b12e5c03Smrg      else
6686b12e5c03Smrg	new_argv[i] = (char *) string;
6687b12e5c03Smrg    }
6688b12e5c03Smrg  new_argv[argc] = NULL;
6689b12e5c03Smrg
6690b12e5c03Smrg  return new_argv;
6691b12e5c03Smrg}
6692b12e5c03SmrgEOF
6693b12e5c03Smrg		;;
6694b12e5c03Smrg	    esac
669509885543Smrg
6696b12e5c03Smrg            cat <<"EOF"
6697b12e5c03Smrgvoid lt_dump_script (FILE* f)
6698b12e5c03Smrg{
6699b12e5c03SmrgEOF
6700b12e5c03Smrg	    func_emit_wrapper yes |
6701b12e5c03Smrg	      $SED -n -e '
6702b12e5c03Smrgs/^\(.\{79\}\)\(..*\)/\1\
6703b12e5c03Smrg\2/
6704b12e5c03Smrgh
6705b12e5c03Smrgs/\([\\"]\)/\\\1/g
6706b12e5c03Smrgs/$/\\n/
6707b12e5c03Smrgs/\([^\n]*\).*/  fputs ("\1", f);/p
6708b12e5c03Smrgg
6709b12e5c03SmrgD'
6710b12e5c03Smrg            cat <<"EOF"
6711b12e5c03Smrg}
6712e4f6584cSmrgEOF
6713e4f6584cSmrg}
6714e4f6584cSmrg# end: func_emit_cwrapperexe_src
671509885543Smrg
6716b12e5c03Smrg# func_win32_import_lib_p ARG
6717b12e5c03Smrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6718b12e5c03Smrgfunc_win32_import_lib_p ()
6719b12e5c03Smrg{
6720f395c03eSmrg    $debug_cmd
6721f395c03eSmrg
6722b12e5c03Smrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6723b12e5c03Smrg    *import*) : ;;
6724b12e5c03Smrg    *) false ;;
6725b12e5c03Smrg    esac
6726b12e5c03Smrg}
6727b12e5c03Smrg
6728f395c03eSmrg# func_suncc_cstd_abi
6729f395c03eSmrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6730f395c03eSmrg# Several compiler flags select an ABI that is incompatible with the
6731f395c03eSmrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6732f395c03eSmrgfunc_suncc_cstd_abi ()
6733f395c03eSmrg{
6734f395c03eSmrg    $debug_cmd
6735f395c03eSmrg
6736f395c03eSmrg    case " $compile_command " in
6737f395c03eSmrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6738f395c03eSmrg      suncc_use_cstd_abi=no
6739f395c03eSmrg      ;;
6740f395c03eSmrg    *)
6741f395c03eSmrg      suncc_use_cstd_abi=yes
6742f395c03eSmrg      ;;
6743f395c03eSmrg    esac
6744f395c03eSmrg}
6745f395c03eSmrg
6746e4f6584cSmrg# func_mode_link arg...
6747e4f6584cSmrgfunc_mode_link ()
6748e4f6584cSmrg{
6749f395c03eSmrg    $debug_cmd
6750f395c03eSmrg
6751e4f6584cSmrg    case $host in
6752e4f6584cSmrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6753e4f6584cSmrg      # It is impossible to link a dll without this setting, and
6754e4f6584cSmrg      # we shouldn't force the makefile maintainer to figure out
6755f395c03eSmrg      # what system we are compiling for in order to pass an extra
6756e4f6584cSmrg      # flag for every libtool invocation.
6757e4f6584cSmrg      # allow_undefined=no
675809885543Smrg
6759e4f6584cSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6760f395c03eSmrg      # to make a dll that has undefined symbols, in which case not
6761e4f6584cSmrg      # even a static library is built.  For now, we need to specify
6762e4f6584cSmrg      # -no-undefined on the libtool link line when we can be certain
6763e4f6584cSmrg      # that all symbols are satisfied, otherwise we get a static library.
6764e4f6584cSmrg      allow_undefined=yes
6765e4f6584cSmrg      ;;
6766e4f6584cSmrg    *)
6767e4f6584cSmrg      allow_undefined=yes
6768e4f6584cSmrg      ;;
6769e4f6584cSmrg    esac
6770e4f6584cSmrg    libtool_args=$nonopt
6771e4f6584cSmrg    base_compile="$nonopt $@"
6772e4f6584cSmrg    compile_command=$nonopt
6773e4f6584cSmrg    finalize_command=$nonopt
677409885543Smrg
6775e4f6584cSmrg    compile_rpath=
6776e4f6584cSmrg    finalize_rpath=
6777e4f6584cSmrg    compile_shlibpath=
6778e4f6584cSmrg    finalize_shlibpath=
6779e4f6584cSmrg    convenience=
6780e4f6584cSmrg    old_convenience=
6781e4f6584cSmrg    deplibs=
6782e4f6584cSmrg    old_deplibs=
6783e4f6584cSmrg    compiler_flags=
6784e4f6584cSmrg    linker_flags=
6785e4f6584cSmrg    dllsearchpath=
6786e4f6584cSmrg    lib_search_path=`pwd`
6787e4f6584cSmrg    inst_prefix_dir=
6788e4f6584cSmrg    new_inherited_linker_flags=
678909885543Smrg
6790e4f6584cSmrg    avoid_version=no
6791b12e5c03Smrg    bindir=
6792e4f6584cSmrg    dlfiles=
6793e4f6584cSmrg    dlprefiles=
6794e4f6584cSmrg    dlself=no
6795e4f6584cSmrg    export_dynamic=no
6796e4f6584cSmrg    export_symbols=
6797e4f6584cSmrg    export_symbols_regex=
6798e4f6584cSmrg    generated=
6799e4f6584cSmrg    libobjs=
6800e4f6584cSmrg    ltlibs=
6801e4f6584cSmrg    module=no
6802e4f6584cSmrg    no_install=no
6803e4f6584cSmrg    objs=
6804f395c03eSmrg    os2dllname=
6805e4f6584cSmrg    non_pic_objects=
6806e4f6584cSmrg    precious_files_regex=
6807e4f6584cSmrg    prefer_static_libs=no
6808f395c03eSmrg    preload=false
6809e4f6584cSmrg    prev=
6810e4f6584cSmrg    prevarg=
6811e4f6584cSmrg    release=
6812e4f6584cSmrg    rpath=
6813e4f6584cSmrg    xrpath=
6814e4f6584cSmrg    perm_rpath=
6815e4f6584cSmrg    temp_rpath=
6816e4f6584cSmrg    thread_safe=no
6817e4f6584cSmrg    vinfo=
6818e4f6584cSmrg    vinfo_number=no
6819e4f6584cSmrg    weak_libs=
6820f395c03eSmrg    single_module=$wl-single_module
6821e4f6584cSmrg    func_infer_tag $base_compile
6822e4f6584cSmrg
6823e4f6584cSmrg    # We need to know -static, to get the right output filenames.
6824e4f6584cSmrg    for arg
6825e4f6584cSmrg    do
6826e4f6584cSmrg      case $arg in
6827e4f6584cSmrg      -shared)
6828f395c03eSmrg	test yes != "$build_libtool_libs" \
6829f395c03eSmrg	  && func_fatal_configuration "cannot build a shared library"
6830e4f6584cSmrg	build_old_libs=no
6831e4f6584cSmrg	break
6832e4f6584cSmrg	;;
6833e4f6584cSmrg      -all-static | -static | -static-libtool-libs)
6834e4f6584cSmrg	case $arg in
6835e4f6584cSmrg	-all-static)
6836f395c03eSmrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
6837e4f6584cSmrg	    func_warning "complete static linking is impossible in this configuration"
6838e4f6584cSmrg	  fi
6839e4f6584cSmrg	  if test -n "$link_static_flag"; then
6840e4f6584cSmrg	    dlopen_self=$dlopen_self_static
6841e4f6584cSmrg	  fi
6842e4f6584cSmrg	  prefer_static_libs=yes
6843e4f6584cSmrg	  ;;
6844e4f6584cSmrg	-static)
6845e4f6584cSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6846e4f6584cSmrg	    dlopen_self=$dlopen_self_static
6847e4f6584cSmrg	  fi
6848e4f6584cSmrg	  prefer_static_libs=built
6849e4f6584cSmrg	  ;;
6850e4f6584cSmrg	-static-libtool-libs)
6851e4f6584cSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
6852e4f6584cSmrg	    dlopen_self=$dlopen_self_static
6853b698ba48Smrg	  fi
6854e4f6584cSmrg	  prefer_static_libs=yes
6855e4f6584cSmrg	  ;;
6856e4f6584cSmrg	esac
6857e4f6584cSmrg	build_libtool_libs=no
6858e4f6584cSmrg	build_old_libs=yes
6859e4f6584cSmrg	break
6860e4f6584cSmrg	;;
6861e4f6584cSmrg      esac
6862e4f6584cSmrg    done
686309885543Smrg
6864e4f6584cSmrg    # See if our shared archives depend on static archives.
6865e4f6584cSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
686609885543Smrg
6867e4f6584cSmrg    # Go through the arguments, transforming them on the way.
6868e4f6584cSmrg    while test "$#" -gt 0; do
6869f395c03eSmrg      arg=$1
6870e4f6584cSmrg      shift
6871beef1b22Smrg      func_quote_arg pretty,unquoted "$arg"
6872beef1b22Smrg      qarg=$func_quote_arg_unquoted_result
6873beef1b22Smrg      func_append libtool_args " $func_quote_arg_result"
687409885543Smrg
6875e4f6584cSmrg      # If the previous option needs an argument, assign it.
6876e4f6584cSmrg      if test -n "$prev"; then
6877e4f6584cSmrg	case $prev in
6878e4f6584cSmrg	output)
6879e4f6584cSmrg	  func_append compile_command " @OUTPUT@"
6880e4f6584cSmrg	  func_append finalize_command " @OUTPUT@"
6881e4f6584cSmrg	  ;;
6882e4f6584cSmrg	esac
688309885543Smrg
6884e4f6584cSmrg	case $prev in
6885b12e5c03Smrg	bindir)
6886f395c03eSmrg	  bindir=$arg
6887b12e5c03Smrg	  prev=
6888b12e5c03Smrg	  continue
6889b12e5c03Smrg	  ;;
6890e4f6584cSmrg	dlfiles|dlprefiles)
6891f395c03eSmrg	  $preload || {
6892e4f6584cSmrg	    # Add the symbol object into the linking commands.
6893e4f6584cSmrg	    func_append compile_command " @SYMFILE@"
6894e4f6584cSmrg	    func_append finalize_command " @SYMFILE@"
6895f395c03eSmrg	    preload=:
6896f395c03eSmrg	  }
6897e4f6584cSmrg	  case $arg in
6898e4f6584cSmrg	  *.la | *.lo) ;;  # We handle these cases below.
6899e4f6584cSmrg	  force)
6900f395c03eSmrg	    if test no = "$dlself"; then
6901e4f6584cSmrg	      dlself=needless
6902e4f6584cSmrg	      export_dynamic=yes
6903e4f6584cSmrg	    fi
6904e4f6584cSmrg	    prev=
6905e4f6584cSmrg	    continue
6906e4f6584cSmrg	    ;;
6907e4f6584cSmrg	  self)
6908f395c03eSmrg	    if test dlprefiles = "$prev"; then
6909e4f6584cSmrg	      dlself=yes
6910f395c03eSmrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
6911e4f6584cSmrg	      dlself=yes
6912b698ba48Smrg	    else
6913e4f6584cSmrg	      dlself=needless
6914e4f6584cSmrg	      export_dynamic=yes
6915b698ba48Smrg	    fi
6916e4f6584cSmrg	    prev=
6917e4f6584cSmrg	    continue
6918e4f6584cSmrg	    ;;
6919e4f6584cSmrg	  *)
6920f395c03eSmrg	    if test dlfiles = "$prev"; then
6921b12e5c03Smrg	      func_append dlfiles " $arg"
6922b698ba48Smrg	    else
6923b12e5c03Smrg	      func_append dlprefiles " $arg"
6924b698ba48Smrg	    fi
6925e4f6584cSmrg	    prev=
6926e4f6584cSmrg	    continue
6927e4f6584cSmrg	    ;;
6928e4f6584cSmrg	  esac
6929e4f6584cSmrg	  ;;
6930e4f6584cSmrg	expsyms)
6931f395c03eSmrg	  export_symbols=$arg
6932e4f6584cSmrg	  test -f "$arg" \
6933f395c03eSmrg	    || func_fatal_error "symbol file '$arg' does not exist"
6934e4f6584cSmrg	  prev=
6935e4f6584cSmrg	  continue
6936e4f6584cSmrg	  ;;
6937e4f6584cSmrg	expsyms_regex)
6938f395c03eSmrg	  export_symbols_regex=$arg
6939e4f6584cSmrg	  prev=
6940e4f6584cSmrg	  continue
6941e4f6584cSmrg	  ;;
6942e4f6584cSmrg	framework)
6943b698ba48Smrg	  case $host in
6944e4f6584cSmrg	    *-*-darwin*)
6945e4f6584cSmrg	      case "$deplibs " in
6946e4f6584cSmrg		*" $qarg.ltframework "*) ;;
6947b12e5c03Smrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
6948e4f6584cSmrg		   ;;
6949e4f6584cSmrg	      esac
6950e4f6584cSmrg	      ;;
6951b698ba48Smrg	  esac
6952e4f6584cSmrg	  prev=
6953e4f6584cSmrg	  continue
6954b698ba48Smrg	  ;;
6955e4f6584cSmrg	inst_prefix)
6956f395c03eSmrg	  inst_prefix_dir=$arg
6957f395c03eSmrg	  prev=
6958f395c03eSmrg	  continue
6959f395c03eSmrg	  ;;
6960f395c03eSmrg	mllvm)
6961f395c03eSmrg	  # Clang does not use LLVM to link, so we can simply discard any
6962f395c03eSmrg	  # '-mllvm $arg' options when doing the link step.
6963e4f6584cSmrg	  prev=
6964e4f6584cSmrg	  continue
6965b698ba48Smrg	  ;;
6966e4f6584cSmrg	objectlist)
6967e4f6584cSmrg	  if test -f "$arg"; then
6968e4f6584cSmrg	    save_arg=$arg
6969e4f6584cSmrg	    moreargs=
6970e4f6584cSmrg	    for fil in `cat "$save_arg"`
6971e4f6584cSmrg	    do
6972b12e5c03Smrg#	      func_append moreargs " $fil"
6973e4f6584cSmrg	      arg=$fil
6974e4f6584cSmrg	      # A libtool-controlled object.
697509885543Smrg
6976e4f6584cSmrg	      # Check to see that this really is a libtool object.
6977e4f6584cSmrg	      if func_lalib_unsafe_p "$arg"; then
6978e4f6584cSmrg		pic_object=
6979e4f6584cSmrg		non_pic_object=
698009885543Smrg
6981e4f6584cSmrg		# Read the .lo file
6982e4f6584cSmrg		func_source "$arg"
698309885543Smrg
6984e4f6584cSmrg		if test -z "$pic_object" ||
6985e4f6584cSmrg		   test -z "$non_pic_object" ||
6986f395c03eSmrg		   test none = "$pic_object" &&
6987f395c03eSmrg		   test none = "$non_pic_object"; then
6988f395c03eSmrg		  func_fatal_error "cannot find name of object for '$arg'"
6989e4f6584cSmrg		fi
699009885543Smrg
6991e4f6584cSmrg		# Extract subdirectory from the argument.
6992e4f6584cSmrg		func_dirname "$arg" "/" ""
6993f395c03eSmrg		xdir=$func_dirname_result
69942ec8c4b4Smrg
6995f395c03eSmrg		if test none != "$pic_object"; then
6996e4f6584cSmrg		  # Prepend the subdirectory the object is found in.
6997f395c03eSmrg		  pic_object=$xdir$pic_object
69982ec8c4b4Smrg
6999f395c03eSmrg		  if test dlfiles = "$prev"; then
7000f395c03eSmrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7001b12e5c03Smrg		      func_append dlfiles " $pic_object"
7002e4f6584cSmrg		      prev=
7003e4f6584cSmrg		      continue
7004e4f6584cSmrg		    else
7005e4f6584cSmrg		      # If libtool objects are unsupported, then we need to preload.
7006e4f6584cSmrg		      prev=dlprefiles
7007e4f6584cSmrg		    fi
7008e4f6584cSmrg		  fi
70092ec8c4b4Smrg
7010e4f6584cSmrg		  # CHECK ME:  I think I busted this.  -Ossama
7011f395c03eSmrg		  if test dlprefiles = "$prev"; then
7012e4f6584cSmrg		    # Preload the old-style object.
7013b12e5c03Smrg		    func_append dlprefiles " $pic_object"
7014e4f6584cSmrg		    prev=
7015e4f6584cSmrg		  fi
70162ec8c4b4Smrg
7017e4f6584cSmrg		  # A PIC object.
7018e4f6584cSmrg		  func_append libobjs " $pic_object"
7019f395c03eSmrg		  arg=$pic_object
7020e4f6584cSmrg		fi
70212ec8c4b4Smrg
7022e4f6584cSmrg		# Non-PIC object.
7023f395c03eSmrg		if test none != "$non_pic_object"; then
7024e4f6584cSmrg		  # Prepend the subdirectory the object is found in.
7025f395c03eSmrg		  non_pic_object=$xdir$non_pic_object
70262ec8c4b4Smrg
7027e4f6584cSmrg		  # A standard non-PIC object
7028e4f6584cSmrg		  func_append non_pic_objects " $non_pic_object"
7029f395c03eSmrg		  if test -z "$pic_object" || test none = "$pic_object"; then
7030f395c03eSmrg		    arg=$non_pic_object
7031e4f6584cSmrg		  fi
7032e4f6584cSmrg		else
7033e4f6584cSmrg		  # If the PIC object exists, use it instead.
7034e4f6584cSmrg		  # $xdir was prepended to $pic_object above.
7035f395c03eSmrg		  non_pic_object=$pic_object
7036e4f6584cSmrg		  func_append non_pic_objects " $non_pic_object"
7037e4f6584cSmrg		fi
7038e4f6584cSmrg	      else
7039e4f6584cSmrg		# Only an error if not doing a dry-run.
7040e4f6584cSmrg		if $opt_dry_run; then
7041e4f6584cSmrg		  # Extract subdirectory from the argument.
7042e4f6584cSmrg		  func_dirname "$arg" "/" ""
7043f395c03eSmrg		  xdir=$func_dirname_result
7044e4f6584cSmrg
7045e4f6584cSmrg		  func_lo2o "$arg"
7046e4f6584cSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
7047e4f6584cSmrg		  non_pic_object=$xdir$func_lo2o_result
7048e4f6584cSmrg		  func_append libobjs " $pic_object"
7049e4f6584cSmrg		  func_append non_pic_objects " $non_pic_object"
7050e4f6584cSmrg	        else
7051f395c03eSmrg		  func_fatal_error "'$arg' is not a valid libtool object"
7052e4f6584cSmrg		fi
7053e4f6584cSmrg	      fi
7054e4f6584cSmrg	    done
7055b698ba48Smrg	  else
7056f395c03eSmrg	    func_fatal_error "link input file '$arg' does not exist"
7057b698ba48Smrg	  fi
7058e4f6584cSmrg	  arg=$save_arg
7059e4f6584cSmrg	  prev=
7060e4f6584cSmrg	  continue
7061e4f6584cSmrg	  ;;
7062f395c03eSmrg	os2dllname)
7063f395c03eSmrg	  os2dllname=$arg
7064f395c03eSmrg	  prev=
7065f395c03eSmrg	  continue
7066f395c03eSmrg	  ;;
7067e4f6584cSmrg	precious_regex)
7068f395c03eSmrg	  precious_files_regex=$arg
7069e4f6584cSmrg	  prev=
7070e4f6584cSmrg	  continue
7071e4f6584cSmrg	  ;;
7072e4f6584cSmrg	release)
7073f395c03eSmrg	  release=-$arg
7074e4f6584cSmrg	  prev=
7075e4f6584cSmrg	  continue
7076e4f6584cSmrg	  ;;
7077e4f6584cSmrg	rpath | xrpath)
7078e4f6584cSmrg	  # We need an absolute path.
7079e4f6584cSmrg	  case $arg in
7080e4f6584cSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
7081e4f6584cSmrg	  *)
7082e4f6584cSmrg	    func_fatal_error "only absolute run-paths are allowed"
7083e4f6584cSmrg	    ;;
7084e4f6584cSmrg	  esac
7085f395c03eSmrg	  if test rpath = "$prev"; then
7086e4f6584cSmrg	    case "$rpath " in
7087e4f6584cSmrg	    *" $arg "*) ;;
7088b12e5c03Smrg	    *) func_append rpath " $arg" ;;
7089e4f6584cSmrg	    esac
7090b698ba48Smrg	  else
7091e4f6584cSmrg	    case "$xrpath " in
7092e4f6584cSmrg	    *" $arg "*) ;;
7093b12e5c03Smrg	    *) func_append xrpath " $arg" ;;
7094e4f6584cSmrg	    esac
7095b698ba48Smrg	  fi
7096e4f6584cSmrg	  prev=
7097e4f6584cSmrg	  continue
7098e4f6584cSmrg	  ;;
7099e4f6584cSmrg	shrext)
7100f395c03eSmrg	  shrext_cmds=$arg
7101e4f6584cSmrg	  prev=
7102e4f6584cSmrg	  continue
7103e4f6584cSmrg	  ;;
7104e4f6584cSmrg	weak)
7105b12e5c03Smrg	  func_append weak_libs " $arg"
7106e4f6584cSmrg	  prev=
7107e4f6584cSmrg	  continue
7108e4f6584cSmrg	  ;;
7109beef1b22Smrg	xassembler)
7110beef1b22Smrg	  func_append compiler_flags " -Xassembler $qarg"
7111beef1b22Smrg	  prev=
7112beef1b22Smrg	  func_append compile_command " -Xassembler $qarg"
7113beef1b22Smrg	  func_append finalize_command " -Xassembler $qarg"
7114beef1b22Smrg	  continue
7115beef1b22Smrg	  ;;
7116e4f6584cSmrg	xcclinker)
7117b12e5c03Smrg	  func_append linker_flags " $qarg"
7118b12e5c03Smrg	  func_append compiler_flags " $qarg"
7119e4f6584cSmrg	  prev=
7120e4f6584cSmrg	  func_append compile_command " $qarg"
7121e4f6584cSmrg	  func_append finalize_command " $qarg"
7122e4f6584cSmrg	  continue
7123e4f6584cSmrg	  ;;
7124e4f6584cSmrg	xcompiler)
7125b12e5c03Smrg	  func_append compiler_flags " $qarg"
7126e4f6584cSmrg	  prev=
7127e4f6584cSmrg	  func_append compile_command " $qarg"
7128e4f6584cSmrg	  func_append finalize_command " $qarg"
7129e4f6584cSmrg	  continue
7130e4f6584cSmrg	  ;;
7131e4f6584cSmrg	xlinker)
7132b12e5c03Smrg	  func_append linker_flags " $qarg"
7133b12e5c03Smrg	  func_append compiler_flags " $wl$qarg"
7134e4f6584cSmrg	  prev=
7135e4f6584cSmrg	  func_append compile_command " $wl$qarg"
7136e4f6584cSmrg	  func_append finalize_command " $wl$qarg"
7137e4f6584cSmrg	  continue
7138e4f6584cSmrg	  ;;
7139e4f6584cSmrg	*)
7140e4f6584cSmrg	  eval "$prev=\"\$arg\""
7141e4f6584cSmrg	  prev=
7142e4f6584cSmrg	  continue
7143e4f6584cSmrg	  ;;
71442ec8c4b4Smrg	esac
7145e4f6584cSmrg      fi # test -n "$prev"
71462ec8c4b4Smrg
7147f395c03eSmrg      prevarg=$arg
71482ec8c4b4Smrg
7149e4f6584cSmrg      case $arg in
7150e4f6584cSmrg      -all-static)
7151e4f6584cSmrg	if test -n "$link_static_flag"; then
7152e4f6584cSmrg	  # See comment for -static flag below, for more details.
7153e4f6584cSmrg	  func_append compile_command " $link_static_flag"
7154e4f6584cSmrg	  func_append finalize_command " $link_static_flag"
7155e4f6584cSmrg	fi
7156e4f6584cSmrg	continue
7157e4f6584cSmrg	;;
71582ec8c4b4Smrg
7159e4f6584cSmrg      -allow-undefined)
7160e4f6584cSmrg	# FIXME: remove this flag sometime in the future.
7161f395c03eSmrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
7162e4f6584cSmrg	;;
71632ec8c4b4Smrg
7164e4f6584cSmrg      -avoid-version)
7165e4f6584cSmrg	avoid_version=yes
7166e4f6584cSmrg	continue
7167e4f6584cSmrg	;;
71682ec8c4b4Smrg
7169b12e5c03Smrg      -bindir)
7170b12e5c03Smrg	prev=bindir
7171b12e5c03Smrg	continue
7172b12e5c03Smrg	;;
7173b12e5c03Smrg
7174e4f6584cSmrg      -dlopen)
7175e4f6584cSmrg	prev=dlfiles
7176e4f6584cSmrg	continue
7177e4f6584cSmrg	;;
71782ec8c4b4Smrg
7179e4f6584cSmrg      -dlpreopen)
7180e4f6584cSmrg	prev=dlprefiles
7181e4f6584cSmrg	continue
7182e4f6584cSmrg	;;
71832ec8c4b4Smrg
7184e4f6584cSmrg      -export-dynamic)
7185e4f6584cSmrg	export_dynamic=yes
7186e4f6584cSmrg	continue
7187e4f6584cSmrg	;;
71882ec8c4b4Smrg
7189e4f6584cSmrg      -export-symbols | -export-symbols-regex)
7190e4f6584cSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
7191e4f6584cSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
7192e4f6584cSmrg	fi
7193f395c03eSmrg	if test X-export-symbols = "X$arg"; then
7194e4f6584cSmrg	  prev=expsyms
7195e4f6584cSmrg	else
7196e4f6584cSmrg	  prev=expsyms_regex
7197e4f6584cSmrg	fi
7198e4f6584cSmrg	continue
7199e4f6584cSmrg	;;
72002ec8c4b4Smrg
7201e4f6584cSmrg      -framework)
7202e4f6584cSmrg	prev=framework
7203e4f6584cSmrg	continue
7204e4f6584cSmrg	;;
72052ec8c4b4Smrg
7206e4f6584cSmrg      -inst-prefix-dir)
7207e4f6584cSmrg	prev=inst_prefix
7208e4f6584cSmrg	continue
7209e4f6584cSmrg	;;
72102ec8c4b4Smrg
7211e4f6584cSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
7212e4f6584cSmrg      # so, if we see these flags be careful not to treat them like -L
7213e4f6584cSmrg      -L[A-Z][A-Z]*:*)
7214e4f6584cSmrg	case $with_gcc/$host in
7215e4f6584cSmrg	no/*-*-irix* | /*-*-irix*)
7216e4f6584cSmrg	  func_append compile_command " $arg"
7217e4f6584cSmrg	  func_append finalize_command " $arg"
7218e4f6584cSmrg	  ;;
7219e4f6584cSmrg	esac
7220e4f6584cSmrg	continue
7221e4f6584cSmrg	;;
72222ec8c4b4Smrg
7223e4f6584cSmrg      -L*)
7224b12e5c03Smrg	func_stripname "-L" '' "$arg"
7225b12e5c03Smrg	if test -z "$func_stripname_result"; then
7226e4f6584cSmrg	  if test "$#" -gt 0; then
7227f395c03eSmrg	    func_fatal_error "require no space between '-L' and '$1'"
7228e4f6584cSmrg	  else
7229f395c03eSmrg	    func_fatal_error "need path for '-L' option"
7230e4f6584cSmrg	  fi
7231e4f6584cSmrg	fi
7232b12e5c03Smrg	func_resolve_sysroot "$func_stripname_result"
7233b12e5c03Smrg	dir=$func_resolve_sysroot_result
7234e4f6584cSmrg	# We need an absolute path.
7235e4f6584cSmrg	case $dir in
7236e4f6584cSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7237e4f6584cSmrg	*)
7238e4f6584cSmrg	  absdir=`cd "$dir" && pwd`
7239e4f6584cSmrg	  test -z "$absdir" && \
7240f395c03eSmrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7241f395c03eSmrg	  dir=$absdir
7242e4f6584cSmrg	  ;;
7243e4f6584cSmrg	esac
7244e4f6584cSmrg	case "$deplibs " in
7245b12e5c03Smrg	*" -L$dir "* | *" $arg "*)
7246b12e5c03Smrg	  # Will only happen for absolute or sysroot arguments
7247b12e5c03Smrg	  ;;
7248e4f6584cSmrg	*)
7249b12e5c03Smrg	  # Preserve sysroot, but never include relative directories
7250b12e5c03Smrg	  case $dir in
7251b12e5c03Smrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
7252b12e5c03Smrg	    *) func_append deplibs " -L$dir" ;;
7253b12e5c03Smrg	  esac
7254b12e5c03Smrg	  func_append lib_search_path " $dir"
7255e4f6584cSmrg	  ;;
7256e4f6584cSmrg	esac
7257e4f6584cSmrg	case $host in
7258e4f6584cSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
7259b12e5c03Smrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
7260e4f6584cSmrg	  case :$dllsearchpath: in
7261e4f6584cSmrg	  *":$dir:"*) ;;
7262e4f6584cSmrg	  ::) dllsearchpath=$dir;;
7263b12e5c03Smrg	  *) func_append dllsearchpath ":$dir";;
7264e4f6584cSmrg	  esac
7265e4f6584cSmrg	  case :$dllsearchpath: in
7266e4f6584cSmrg	  *":$testbindir:"*) ;;
7267e4f6584cSmrg	  ::) dllsearchpath=$testbindir;;
7268b12e5c03Smrg	  *) func_append dllsearchpath ":$testbindir";;
7269e4f6584cSmrg	  esac
7270e4f6584cSmrg	  ;;
7271e4f6584cSmrg	esac
7272e4f6584cSmrg	continue
7273e4f6584cSmrg	;;
72742ec8c4b4Smrg
7275e4f6584cSmrg      -l*)
7276f395c03eSmrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
7277e4f6584cSmrg	  case $host in
7278b12e5c03Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
7279e4f6584cSmrg	    # These systems don't actually have a C or math library (as such)
7280e4f6584cSmrg	    continue
7281e4f6584cSmrg	    ;;
7282e4f6584cSmrg	  *-*-os2*)
7283e4f6584cSmrg	    # These systems don't actually have a C library (as such)
7284f395c03eSmrg	    test X-lc = "X$arg" && continue
7285e4f6584cSmrg	    ;;
7286beef1b22Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7287e4f6584cSmrg	    # Do not include libc due to us having libc/libc_r.
7288f395c03eSmrg	    test X-lc = "X$arg" && continue
7289e4f6584cSmrg	    ;;
7290e4f6584cSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
7291e4f6584cSmrg	    # Rhapsody C and math libraries are in the System framework
7292b12e5c03Smrg	    func_append deplibs " System.ltframework"
7293e4f6584cSmrg	    continue
7294e4f6584cSmrg	    ;;
7295e4f6584cSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
7296e4f6584cSmrg	    # Causes problems with __ctype
7297f395c03eSmrg	    test X-lc = "X$arg" && continue
7298e4f6584cSmrg	    ;;
7299e4f6584cSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
7300e4f6584cSmrg	    # Compiler inserts libc in the correct place for threads to work
7301f395c03eSmrg	    test X-lc = "X$arg" && continue
7302e4f6584cSmrg	    ;;
7303e4f6584cSmrg	  esac
7304f395c03eSmrg	elif test X-lc_r = "X$arg"; then
7305e4f6584cSmrg	 case $host in
7306beef1b22Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig* | *-*-midnightbsd*)
7307e4f6584cSmrg	   # Do not include libc_r directly, use -pthread flag.
7308e4f6584cSmrg	   continue
7309e4f6584cSmrg	   ;;
7310e4f6584cSmrg	 esac
7311e4f6584cSmrg	fi
7312b12e5c03Smrg	func_append deplibs " $arg"
7313e4f6584cSmrg	continue
7314e4f6584cSmrg	;;
73152ec8c4b4Smrg
7316f395c03eSmrg      -mllvm)
7317f395c03eSmrg	prev=mllvm
7318f395c03eSmrg	continue
7319f395c03eSmrg	;;
7320f395c03eSmrg
7321e4f6584cSmrg      -module)
7322e4f6584cSmrg	module=yes
7323e4f6584cSmrg	continue
7324e4f6584cSmrg	;;
73252ec8c4b4Smrg
7326e4f6584cSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
7327e4f6584cSmrg      # classes, name mangling, and exception handling.
7328e4f6584cSmrg      # Darwin uses the -arch flag to determine output architecture.
7329b12e5c03Smrg      -model|-arch|-isysroot|--sysroot)
7330b12e5c03Smrg	func_append compiler_flags " $arg"
7331e4f6584cSmrg	func_append compile_command " $arg"
7332e4f6584cSmrg	func_append finalize_command " $arg"
7333e4f6584cSmrg	prev=xcompiler
7334e4f6584cSmrg	continue
7335e4f6584cSmrg	;;
7336beef1b22Smrg     # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199.
7337beef1b22Smrg     -pthread)
7338beef1b22Smrg	case $host in
7339beef1b22Smrg	  *solaris2*) ;;
7340beef1b22Smrg	  *)
7341beef1b22Smrg	    case "$new_inherited_linker_flags " in
7342beef1b22Smrg	        *" $arg "*) ;;
7343beef1b22Smrg	        * ) func_append new_inherited_linker_flags " $arg" ;;
7344beef1b22Smrg	    esac
7345beef1b22Smrg	  ;;
7346beef1b22Smrg	esac
7347beef1b22Smrg	continue
7348beef1b22Smrg	;;
7349beef1b22Smrg      -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \
7350b12e5c03Smrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7351b12e5c03Smrg	func_append compiler_flags " $arg"
7352e4f6584cSmrg	func_append compile_command " $arg"
7353e4f6584cSmrg	func_append finalize_command " $arg"
7354e4f6584cSmrg	case "$new_inherited_linker_flags " in
7355e4f6584cSmrg	    *" $arg "*) ;;
7356b12e5c03Smrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
7357e4f6584cSmrg	esac
7358e4f6584cSmrg	continue
7359e4f6584cSmrg	;;
73602ec8c4b4Smrg
7361e4f6584cSmrg      -multi_module)
7362f395c03eSmrg	single_module=$wl-multi_module
7363e4f6584cSmrg	continue
7364e4f6584cSmrg	;;
73652ec8c4b4Smrg
7366e4f6584cSmrg      -no-fast-install)
7367e4f6584cSmrg	fast_install=no
7368e4f6584cSmrg	continue
7369e4f6584cSmrg	;;
73702ec8c4b4Smrg
7371e4f6584cSmrg      -no-install)
7372e4f6584cSmrg	case $host in
7373e4f6584cSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
7374e4f6584cSmrg	  # The PATH hackery in wrapper scripts is required on Windows
7375e4f6584cSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7376f395c03eSmrg	  func_warning "'-no-install' is ignored for $host"
7377f395c03eSmrg	  func_warning "assuming '-no-fast-install' instead"
7378e4f6584cSmrg	  fast_install=no
7379e4f6584cSmrg	  ;;
7380e4f6584cSmrg	*) no_install=yes ;;
7381e4f6584cSmrg	esac
7382e4f6584cSmrg	continue
7383e4f6584cSmrg	;;
73842ec8c4b4Smrg
7385e4f6584cSmrg      -no-undefined)
7386e4f6584cSmrg	allow_undefined=no
7387e4f6584cSmrg	continue
7388e4f6584cSmrg	;;
73892ec8c4b4Smrg
7390e4f6584cSmrg      -objectlist)
7391e4f6584cSmrg	prev=objectlist
7392e4f6584cSmrg	continue
7393e4f6584cSmrg	;;
73942ec8c4b4Smrg
7395f395c03eSmrg      -os2dllname)
7396f395c03eSmrg	prev=os2dllname
7397f395c03eSmrg	continue
7398f395c03eSmrg	;;
7399f395c03eSmrg
7400e4f6584cSmrg      -o) prev=output ;;
74012ec8c4b4Smrg
7402e4f6584cSmrg      -precious-files-regex)
7403e4f6584cSmrg	prev=precious_regex
7404e4f6584cSmrg	continue
7405e4f6584cSmrg	;;
74062ec8c4b4Smrg
7407e4f6584cSmrg      -release)
7408e4f6584cSmrg	prev=release
7409e4f6584cSmrg	continue
7410e4f6584cSmrg	;;
74112ec8c4b4Smrg
7412e4f6584cSmrg      -rpath)
7413e4f6584cSmrg	prev=rpath
7414e4f6584cSmrg	continue
7415e4f6584cSmrg	;;
74162ec8c4b4Smrg
7417e4f6584cSmrg      -R)
7418e4f6584cSmrg	prev=xrpath
7419e4f6584cSmrg	continue
7420e4f6584cSmrg	;;
74212ec8c4b4Smrg
7422e4f6584cSmrg      -R*)
7423e4f6584cSmrg	func_stripname '-R' '' "$arg"
7424e4f6584cSmrg	dir=$func_stripname_result
7425e4f6584cSmrg	# We need an absolute path.
7426e4f6584cSmrg	case $dir in
7427e4f6584cSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
7428b12e5c03Smrg	=*)
7429b12e5c03Smrg	  func_stripname '=' '' "$dir"
7430b12e5c03Smrg	  dir=$lt_sysroot$func_stripname_result
7431b12e5c03Smrg	  ;;
7432e4f6584cSmrg	*)
7433e4f6584cSmrg	  func_fatal_error "only absolute run-paths are allowed"
7434e4f6584cSmrg	  ;;
7435e4f6584cSmrg	esac
7436e4f6584cSmrg	case "$xrpath " in
7437e4f6584cSmrg	*" $dir "*) ;;
7438b12e5c03Smrg	*) func_append xrpath " $dir" ;;
7439e4f6584cSmrg	esac
7440e4f6584cSmrg	continue
7441e4f6584cSmrg	;;
74422ec8c4b4Smrg
7443e4f6584cSmrg      -shared)
7444e4f6584cSmrg	# The effects of -shared are defined in a previous loop.
7445e4f6584cSmrg	continue
7446e4f6584cSmrg	;;
74472ec8c4b4Smrg
7448e4f6584cSmrg      -shrext)
7449e4f6584cSmrg	prev=shrext
7450e4f6584cSmrg	continue
7451e4f6584cSmrg	;;
74522ec8c4b4Smrg
7453e4f6584cSmrg      -static | -static-libtool-libs)
7454e4f6584cSmrg	# The effects of -static are defined in a previous loop.
7455e4f6584cSmrg	# We used to do the same as -all-static on platforms that
7456e4f6584cSmrg	# didn't have a PIC flag, but the assumption that the effects
7457e4f6584cSmrg	# would be equivalent was wrong.  It would break on at least
7458e4f6584cSmrg	# Digital Unix and AIX.
7459e4f6584cSmrg	continue
7460e4f6584cSmrg	;;
74612ec8c4b4Smrg
7462e4f6584cSmrg      -thread-safe)
7463e4f6584cSmrg	thread_safe=yes
7464e4f6584cSmrg	continue
7465e4f6584cSmrg	;;
74662ec8c4b4Smrg
7467e4f6584cSmrg      -version-info)
7468e4f6584cSmrg	prev=vinfo
7469e4f6584cSmrg	continue
7470e4f6584cSmrg	;;
74712ec8c4b4Smrg
7472e4f6584cSmrg      -version-number)
7473e4f6584cSmrg	prev=vinfo
7474e4f6584cSmrg	vinfo_number=yes
7475e4f6584cSmrg	continue
7476e4f6584cSmrg	;;
747709885543Smrg
7478e4f6584cSmrg      -weak)
7479e4f6584cSmrg        prev=weak
7480e4f6584cSmrg	continue
7481e4f6584cSmrg	;;
748209885543Smrg
7483e4f6584cSmrg      -Wc,*)
7484e4f6584cSmrg	func_stripname '-Wc,' '' "$arg"
7485e4f6584cSmrg	args=$func_stripname_result
7486e4f6584cSmrg	arg=
7487f395c03eSmrg	save_ifs=$IFS; IFS=,
7488e4f6584cSmrg	for flag in $args; do
7489f395c03eSmrg	  IFS=$save_ifs
7490beef1b22Smrg          func_quote_arg pretty "$flag"
7491beef1b22Smrg	  func_append arg " $func_quote_arg_result"
7492beef1b22Smrg	  func_append compiler_flags " $func_quote_arg_result"
7493e4f6584cSmrg	done
7494f395c03eSmrg	IFS=$save_ifs
7495e4f6584cSmrg	func_stripname ' ' '' "$arg"
7496e4f6584cSmrg	arg=$func_stripname_result
7497e4f6584cSmrg	;;
7498b698ba48Smrg
7499e4f6584cSmrg      -Wl,*)
7500e4f6584cSmrg	func_stripname '-Wl,' '' "$arg"
7501e4f6584cSmrg	args=$func_stripname_result
7502e4f6584cSmrg	arg=
7503f395c03eSmrg	save_ifs=$IFS; IFS=,
7504e4f6584cSmrg	for flag in $args; do
7505f395c03eSmrg	  IFS=$save_ifs
7506beef1b22Smrg          func_quote_arg pretty "$flag"
7507beef1b22Smrg	  func_append arg " $wl$func_quote_arg_result"
7508beef1b22Smrg	  func_append compiler_flags " $wl$func_quote_arg_result"
7509beef1b22Smrg	  func_append linker_flags " $func_quote_arg_result"
7510e4f6584cSmrg	done
7511f395c03eSmrg	IFS=$save_ifs
7512e4f6584cSmrg	func_stripname ' ' '' "$arg"
7513e4f6584cSmrg	arg=$func_stripname_result
7514e4f6584cSmrg	;;
7515b698ba48Smrg
7516beef1b22Smrg      -Xassembler)
7517beef1b22Smrg        prev=xassembler
7518beef1b22Smrg        continue
7519beef1b22Smrg        ;;
7520beef1b22Smrg
7521e4f6584cSmrg      -Xcompiler)
7522e4f6584cSmrg	prev=xcompiler
7523e4f6584cSmrg	continue
7524e4f6584cSmrg	;;
7525b698ba48Smrg
7526e4f6584cSmrg      -Xlinker)
7527e4f6584cSmrg	prev=xlinker
7528e4f6584cSmrg	continue
7529e4f6584cSmrg	;;
7530b698ba48Smrg
7531e4f6584cSmrg      -XCClinker)
7532e4f6584cSmrg	prev=xcclinker
7533e4f6584cSmrg	continue
7534e4f6584cSmrg	;;
7535b698ba48Smrg
7536e4f6584cSmrg      # -msg_* for osf cc
7537e4f6584cSmrg      -msg_*)
7538beef1b22Smrg	func_quote_arg pretty "$arg"
7539beef1b22Smrg	arg=$func_quote_arg_result
7540e4f6584cSmrg	;;
7541b698ba48Smrg
7542b12e5c03Smrg      # Flags to be passed through unchanged, with rationale:
7543b12e5c03Smrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7544b12e5c03Smrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7545b12e5c03Smrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7546b12e5c03Smrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7547b12e5c03Smrg      # -q*                  compiler args for the IBM compiler
7548b12e5c03Smrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7549b12e5c03Smrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7550b12e5c03Smrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7551f395c03eSmrg      # -fstack-protector*   stack protector flags for GCC
7552b12e5c03Smrg      # @file                GCC response files
7553b12e5c03Smrg      # -tp=*                Portland pgcc target processor selection
7554b12e5c03Smrg      # --sysroot=*          for sysroot support
7555f395c03eSmrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7556beef1b22Smrg      # -specs=*             GCC specs files
7557f395c03eSmrg      # -stdlib=*            select c++ std lib with clang
7558beef1b22Smrg      # -fsanitize=*         Clang/GCC memory and address sanitizer
7559beef1b22Smrg      # -fuse-ld=*           Linker select flags for GCC
7560beef1b22Smrg      # -Wa,*                Pass flags directly to the assembler
7561e4f6584cSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
7562b12e5c03Smrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7563beef1b22Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7564beef1b22Smrg      -specs=*|-fsanitize=*|-fuse-ld=*|-Wa,*)
7565beef1b22Smrg        func_quote_arg pretty "$arg"
7566beef1b22Smrg	arg=$func_quote_arg_result
7567e4f6584cSmrg        func_append compile_command " $arg"
7568e4f6584cSmrg        func_append finalize_command " $arg"
7569b12e5c03Smrg        func_append compiler_flags " $arg"
7570e4f6584cSmrg        continue
7571e4f6584cSmrg        ;;
7572b698ba48Smrg
7573f395c03eSmrg      -Z*)
7574f395c03eSmrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7575f395c03eSmrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7576f395c03eSmrg	  compiler_flags="$compiler_flags $arg"
7577f395c03eSmrg	  func_append compile_command " $arg"
7578f395c03eSmrg	  func_append finalize_command " $arg"
7579f395c03eSmrg	  case $arg in
7580f395c03eSmrg	  -Zlinker | -Zstack)
7581f395c03eSmrg	    prev=xcompiler
7582f395c03eSmrg	    ;;
7583f395c03eSmrg	  esac
7584f395c03eSmrg	  continue
7585f395c03eSmrg        else
7586f395c03eSmrg	  # Otherwise treat like 'Some other compiler flag' below
7587beef1b22Smrg	  func_quote_arg pretty "$arg"
7588beef1b22Smrg	  arg=$func_quote_arg_result
7589f395c03eSmrg        fi
7590f395c03eSmrg	;;
7591f395c03eSmrg
7592e4f6584cSmrg      # Some other compiler flag.
7593e4f6584cSmrg      -* | +*)
7594beef1b22Smrg        func_quote_arg pretty "$arg"
7595beef1b22Smrg	arg=$func_quote_arg_result
7596e4f6584cSmrg	;;
7597b698ba48Smrg
7598e4f6584cSmrg      *.$objext)
7599e4f6584cSmrg	# A standard object.
7600b12e5c03Smrg	func_append objs " $arg"
7601e4f6584cSmrg	;;
7602b698ba48Smrg
7603e4f6584cSmrg      *.lo)
7604e4f6584cSmrg	# A libtool-controlled object.
7605b698ba48Smrg
7606e4f6584cSmrg	# Check to see that this really is a libtool object.
7607e4f6584cSmrg	if func_lalib_unsafe_p "$arg"; then
7608e4f6584cSmrg	  pic_object=
7609e4f6584cSmrg	  non_pic_object=
7610b698ba48Smrg
7611e4f6584cSmrg	  # Read the .lo file
7612e4f6584cSmrg	  func_source "$arg"
7613b698ba48Smrg
7614e4f6584cSmrg	  if test -z "$pic_object" ||
7615e4f6584cSmrg	     test -z "$non_pic_object" ||
7616f395c03eSmrg	     test none = "$pic_object" &&
7617f395c03eSmrg	     test none = "$non_pic_object"; then
7618f395c03eSmrg	    func_fatal_error "cannot find name of object for '$arg'"
7619e4f6584cSmrg	  fi
7620b698ba48Smrg
7621e4f6584cSmrg	  # Extract subdirectory from the argument.
7622e4f6584cSmrg	  func_dirname "$arg" "/" ""
7623f395c03eSmrg	  xdir=$func_dirname_result
7624b698ba48Smrg
7625f395c03eSmrg	  test none = "$pic_object" || {
7626e4f6584cSmrg	    # Prepend the subdirectory the object is found in.
7627f395c03eSmrg	    pic_object=$xdir$pic_object
7628b698ba48Smrg
7629f395c03eSmrg	    if test dlfiles = "$prev"; then
7630f395c03eSmrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
7631b12e5c03Smrg		func_append dlfiles " $pic_object"
7632e4f6584cSmrg		prev=
7633e4f6584cSmrg		continue
7634e4f6584cSmrg	      else
7635e4f6584cSmrg		# If libtool objects are unsupported, then we need to preload.
7636e4f6584cSmrg		prev=dlprefiles
7637e4f6584cSmrg	      fi
7638e4f6584cSmrg	    fi
7639b698ba48Smrg
7640e4f6584cSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7641f395c03eSmrg	    if test dlprefiles = "$prev"; then
7642e4f6584cSmrg	      # Preload the old-style object.
7643b12e5c03Smrg	      func_append dlprefiles " $pic_object"
7644e4f6584cSmrg	      prev=
7645e4f6584cSmrg	    fi
764609885543Smrg
7647e4f6584cSmrg	    # A PIC object.
7648e4f6584cSmrg	    func_append libobjs " $pic_object"
7649f395c03eSmrg	    arg=$pic_object
7650f395c03eSmrg	  }
765109885543Smrg
7652e4f6584cSmrg	  # Non-PIC object.
7653f395c03eSmrg	  if test none != "$non_pic_object"; then
7654e4f6584cSmrg	    # Prepend the subdirectory the object is found in.
7655f395c03eSmrg	    non_pic_object=$xdir$non_pic_object
765609885543Smrg
7657e4f6584cSmrg	    # A standard non-PIC object
7658e4f6584cSmrg	    func_append non_pic_objects " $non_pic_object"
7659f395c03eSmrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7660f395c03eSmrg	      arg=$non_pic_object
7661e4f6584cSmrg	    fi
7662e4f6584cSmrg	  else
7663e4f6584cSmrg	    # If the PIC object exists, use it instead.
7664e4f6584cSmrg	    # $xdir was prepended to $pic_object above.
7665f395c03eSmrg	    non_pic_object=$pic_object
7666e4f6584cSmrg	    func_append non_pic_objects " $non_pic_object"
7667e4f6584cSmrg	  fi
7668e4f6584cSmrg	else
7669e4f6584cSmrg	  # Only an error if not doing a dry-run.
7670e4f6584cSmrg	  if $opt_dry_run; then
7671e4f6584cSmrg	    # Extract subdirectory from the argument.
7672e4f6584cSmrg	    func_dirname "$arg" "/" ""
7673f395c03eSmrg	    xdir=$func_dirname_result
7674e4f6584cSmrg
7675e4f6584cSmrg	    func_lo2o "$arg"
7676e4f6584cSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
7677e4f6584cSmrg	    non_pic_object=$xdir$func_lo2o_result
7678e4f6584cSmrg	    func_append libobjs " $pic_object"
7679e4f6584cSmrg	    func_append non_pic_objects " $non_pic_object"
7680e4f6584cSmrg	  else
7681f395c03eSmrg	    func_fatal_error "'$arg' is not a valid libtool object"
7682e4f6584cSmrg	  fi
7683e4f6584cSmrg	fi
7684e4f6584cSmrg	;;
768509885543Smrg
7686e4f6584cSmrg      *.$libext)
7687e4f6584cSmrg	# An archive.
7688b12e5c03Smrg	func_append deplibs " $arg"
7689b12e5c03Smrg	func_append old_deplibs " $arg"
7690e4f6584cSmrg	continue
7691e4f6584cSmrg	;;
7692e4f6584cSmrg
7693e4f6584cSmrg      *.la)
7694e4f6584cSmrg	# A libtool-controlled library.
7695e4f6584cSmrg
7696b12e5c03Smrg	func_resolve_sysroot "$arg"
7697f395c03eSmrg	if test dlfiles = "$prev"; then
7698e4f6584cSmrg	  # This library was specified with -dlopen.
7699b12e5c03Smrg	  func_append dlfiles " $func_resolve_sysroot_result"
7700e4f6584cSmrg	  prev=
7701f395c03eSmrg	elif test dlprefiles = "$prev"; then
7702e4f6584cSmrg	  # The library was specified with -dlpreopen.
7703b12e5c03Smrg	  func_append dlprefiles " $func_resolve_sysroot_result"
7704e4f6584cSmrg	  prev=
7705e4f6584cSmrg	else
7706b12e5c03Smrg	  func_append deplibs " $func_resolve_sysroot_result"
7707e4f6584cSmrg	fi
7708e4f6584cSmrg	continue
7709e4f6584cSmrg	;;
7710e4f6584cSmrg
7711e4f6584cSmrg      # Some other compiler argument.
7712e4f6584cSmrg      *)
7713e4f6584cSmrg	# Unknown arguments in both finalize_command and compile_command need
7714e4f6584cSmrg	# to be aesthetically quoted because they are evaled later.
7715beef1b22Smrg	func_quote_arg pretty "$arg"
7716beef1b22Smrg	arg=$func_quote_arg_result
7717e4f6584cSmrg	;;
7718e4f6584cSmrg      esac # arg
7719e4f6584cSmrg
7720e4f6584cSmrg      # Now actually substitute the argument into the commands.
7721e4f6584cSmrg      if test -n "$arg"; then
7722e4f6584cSmrg	func_append compile_command " $arg"
7723e4f6584cSmrg	func_append finalize_command " $arg"
7724e4f6584cSmrg      fi
7725e4f6584cSmrg    done # argument parsing loop
7726e4f6584cSmrg
7727e4f6584cSmrg    test -n "$prev" && \
7728f395c03eSmrg      func_fatal_help "the '$prevarg' option requires an argument"
7729e4f6584cSmrg
7730f395c03eSmrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
7731e4f6584cSmrg      eval arg=\"$export_dynamic_flag_spec\"
7732e4f6584cSmrg      func_append compile_command " $arg"
7733e4f6584cSmrg      func_append finalize_command " $arg"
7734e4f6584cSmrg    fi
7735e4f6584cSmrg
7736e4f6584cSmrg    oldlibs=
7737e4f6584cSmrg    # calculate the name of the file, without its directory
7738e4f6584cSmrg    func_basename "$output"
7739f395c03eSmrg    outputname=$func_basename_result
7740f395c03eSmrg    libobjs_save=$libobjs
7741e4f6584cSmrg
7742e4f6584cSmrg    if test -n "$shlibpath_var"; then
7743e4f6584cSmrg      # get the directories listed in $shlibpath_var
7744f395c03eSmrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
7745e4f6584cSmrg    else
7746e4f6584cSmrg      shlib_search_path=
7747e4f6584cSmrg    fi
7748e4f6584cSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
7749e4f6584cSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
7750e4f6584cSmrg
7751f395c03eSmrg    # Definition is injected by LT_CONFIG during libtool generation.
7752f395c03eSmrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7753f395c03eSmrg
7754e4f6584cSmrg    func_dirname "$output" "/" ""
7755f395c03eSmrg    output_objdir=$func_dirname_result$objdir
7756b12e5c03Smrg    func_to_tool_file "$output_objdir/"
7757b12e5c03Smrg    tool_output_objdir=$func_to_tool_file_result
7758e4f6584cSmrg    # Create the object directory.
7759e4f6584cSmrg    func_mkdir_p "$output_objdir"
7760e4f6584cSmrg
7761e4f6584cSmrg    # Determine the type of output
7762e4f6584cSmrg    case $output in
7763e4f6584cSmrg    "")
7764e4f6584cSmrg      func_fatal_help "you must specify an output file"
7765e4f6584cSmrg      ;;
7766e4f6584cSmrg    *.$libext) linkmode=oldlib ;;
7767e4f6584cSmrg    *.lo | *.$objext) linkmode=obj ;;
7768e4f6584cSmrg    *.la) linkmode=lib ;;
7769e4f6584cSmrg    *) linkmode=prog ;; # Anything else should be a program.
7770e4f6584cSmrg    esac
7771e4f6584cSmrg
7772e4f6584cSmrg    specialdeplibs=
7773e4f6584cSmrg
7774e4f6584cSmrg    libs=
7775e4f6584cSmrg    # Find all interdependent deplibs by searching for libraries
7776e4f6584cSmrg    # that are linked more than once (e.g. -la -lb -la)
7777e4f6584cSmrg    for deplib in $deplibs; do
7778f395c03eSmrg      if $opt_preserve_dup_deps; then
7779e4f6584cSmrg	case "$libs " in
7780b12e5c03Smrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
7781e4f6584cSmrg	esac
7782e4f6584cSmrg      fi
7783b12e5c03Smrg      func_append libs " $deplib"
7784e4f6584cSmrg    done
7785e4f6584cSmrg
7786f395c03eSmrg    if test lib = "$linkmode"; then
7787e4f6584cSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
7788e4f6584cSmrg
7789e4f6584cSmrg      # Compute libraries that are listed more than once in $predeps
7790e4f6584cSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
7791e4f6584cSmrg      # not to be eliminated).
7792e4f6584cSmrg      pre_post_deps=
7793e4f6584cSmrg      if $opt_duplicate_compiler_generated_deps; then
7794e4f6584cSmrg	for pre_post_dep in $predeps $postdeps; do
7795e4f6584cSmrg	  case "$pre_post_deps " in
7796b12e5c03Smrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
7797e4f6584cSmrg	  esac
7798b12e5c03Smrg	  func_append pre_post_deps " $pre_post_dep"
7799e4f6584cSmrg	done
7800e4f6584cSmrg      fi
7801e4f6584cSmrg      pre_post_deps=
7802e4f6584cSmrg    fi
7803e4f6584cSmrg
7804e4f6584cSmrg    deplibs=
7805e4f6584cSmrg    newdependency_libs=
7806e4f6584cSmrg    newlib_search_path=
7807e4f6584cSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
7808e4f6584cSmrg    notinst_deplibs= # not-installed libtool libraries
7809e4f6584cSmrg    notinst_path= # paths that contain not-installed libtool libraries
7810e4f6584cSmrg
7811e4f6584cSmrg    case $linkmode in
7812e4f6584cSmrg    lib)
7813e4f6584cSmrg	passes="conv dlpreopen link"
7814e4f6584cSmrg	for file in $dlfiles $dlprefiles; do
7815e4f6584cSmrg	  case $file in
7816e4f6584cSmrg	  *.la) ;;
7817e4f6584cSmrg	  *)
7818f395c03eSmrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
7819e4f6584cSmrg	    ;;
7820e4f6584cSmrg	  esac
7821e4f6584cSmrg	done
7822e4f6584cSmrg	;;
7823e4f6584cSmrg    prog)
7824e4f6584cSmrg	compile_deplibs=
7825e4f6584cSmrg	finalize_deplibs=
7826f395c03eSmrg	alldeplibs=false
7827e4f6584cSmrg	newdlfiles=
7828e4f6584cSmrg	newdlprefiles=
7829e4f6584cSmrg	passes="conv scan dlopen dlpreopen link"
7830e4f6584cSmrg	;;
7831e4f6584cSmrg    *)  passes="conv"
7832e4f6584cSmrg	;;
7833e4f6584cSmrg    esac
7834e4f6584cSmrg
7835e4f6584cSmrg    for pass in $passes; do
7836e4f6584cSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
7837e4f6584cSmrg      # so that -L comes before libs that need it for instance...
7838f395c03eSmrg      if test lib,link = "$linkmode,$pass"; then
7839e4f6584cSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
7840e4f6584cSmrg	##        order, and fix it there properly
7841e4f6584cSmrg        tmp_deplibs=
7842e4f6584cSmrg	for deplib in $deplibs; do
7843e4f6584cSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
7844e4f6584cSmrg	done
7845f395c03eSmrg	deplibs=$tmp_deplibs
7846e4f6584cSmrg      fi
7847e4f6584cSmrg
7848f395c03eSmrg      if test lib,link = "$linkmode,$pass" ||
7849f395c03eSmrg	 test prog,scan = "$linkmode,$pass"; then
7850f395c03eSmrg	libs=$deplibs
7851e4f6584cSmrg	deplibs=
7852e4f6584cSmrg      fi
7853f395c03eSmrg      if test prog = "$linkmode"; then
7854e4f6584cSmrg	case $pass in
7855f395c03eSmrg	dlopen) libs=$dlfiles ;;
7856f395c03eSmrg	dlpreopen) libs=$dlprefiles ;;
7857f395c03eSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
7858e4f6584cSmrg	esac
7859e4f6584cSmrg      fi
7860f395c03eSmrg      if test lib,dlpreopen = "$linkmode,$pass"; then
7861e4f6584cSmrg	# Collect and forward deplibs of preopened libtool libs
7862e4f6584cSmrg	for lib in $dlprefiles; do
7863e4f6584cSmrg	  # Ignore non-libtool-libs
7864e4f6584cSmrg	  dependency_libs=
7865b12e5c03Smrg	  func_resolve_sysroot "$lib"
7866e4f6584cSmrg	  case $lib in
7867b12e5c03Smrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
7868e4f6584cSmrg	  esac
7869e4f6584cSmrg
7870e4f6584cSmrg	  # Collect preopened libtool deplibs, except any this library
7871e4f6584cSmrg	  # has declared as weak libs
7872e4f6584cSmrg	  for deplib in $dependency_libs; do
7873b12e5c03Smrg	    func_basename "$deplib"
7874b12e5c03Smrg            deplib_base=$func_basename_result
7875e4f6584cSmrg	    case " $weak_libs " in
7876e4f6584cSmrg	    *" $deplib_base "*) ;;
7877b12e5c03Smrg	    *) func_append deplibs " $deplib" ;;
7878e4f6584cSmrg	    esac
7879e4f6584cSmrg	  done
7880e4f6584cSmrg	done
7881f395c03eSmrg	libs=$dlprefiles
7882e4f6584cSmrg      fi
7883f395c03eSmrg      if test dlopen = "$pass"; then
7884e4f6584cSmrg	# Collect dlpreopened libraries
7885f395c03eSmrg	save_deplibs=$deplibs
7886e4f6584cSmrg	deplibs=
7887e4f6584cSmrg      fi
7888e4f6584cSmrg
7889e4f6584cSmrg      for deplib in $libs; do
7890e4f6584cSmrg	lib=
7891f395c03eSmrg	found=false
7892e4f6584cSmrg	case $deplib in
7893b12e5c03Smrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
7894b12e5c03Smrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7895f395c03eSmrg	  if test prog,link = "$linkmode,$pass"; then
7896e4f6584cSmrg	    compile_deplibs="$deplib $compile_deplibs"
7897e4f6584cSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
7898e4f6584cSmrg	  else
7899b12e5c03Smrg	    func_append compiler_flags " $deplib"
7900f395c03eSmrg	    if test lib = "$linkmode"; then
7901e4f6584cSmrg		case "$new_inherited_linker_flags " in
7902e4f6584cSmrg		    *" $deplib "*) ;;
7903b12e5c03Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7904e4f6584cSmrg		esac
7905e4f6584cSmrg	    fi
7906e4f6584cSmrg	  fi
7907e4f6584cSmrg	  continue
7908e4f6584cSmrg	  ;;
7909e4f6584cSmrg	-l*)
7910f395c03eSmrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7911f395c03eSmrg	    func_warning "'-l' is ignored for archives/objects"
7912e4f6584cSmrg	    continue
7913e4f6584cSmrg	  fi
7914e4f6584cSmrg	  func_stripname '-l' '' "$deplib"
7915e4f6584cSmrg	  name=$func_stripname_result
7916f395c03eSmrg	  if test lib = "$linkmode"; then
7917e4f6584cSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
7918e4f6584cSmrg	  else
7919e4f6584cSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
7920e4f6584cSmrg	  fi
7921e4f6584cSmrg	  for searchdir in $searchdirs; do
7922e4f6584cSmrg	    for search_ext in .la $std_shrext .so .a; do
7923e4f6584cSmrg	      # Search the libtool library
7924f395c03eSmrg	      lib=$searchdir/lib$name$search_ext
7925e4f6584cSmrg	      if test -f "$lib"; then
7926f395c03eSmrg		if test .la = "$search_ext"; then
7927f395c03eSmrg		  found=:
7928e4f6584cSmrg		else
7929f395c03eSmrg		  found=false
7930e4f6584cSmrg		fi
7931e4f6584cSmrg		break 2
7932e4f6584cSmrg	      fi
7933e4f6584cSmrg	    done
7934e4f6584cSmrg	  done
7935f395c03eSmrg	  if $found; then
7936f395c03eSmrg	    # deplib is a libtool library
7937e4f6584cSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
7938e4f6584cSmrg	    # We need to do some special things here, and not later.
7939f395c03eSmrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
7940e4f6584cSmrg	      case " $predeps $postdeps " in
7941e4f6584cSmrg	      *" $deplib "*)
7942e4f6584cSmrg		if func_lalib_p "$lib"; then
7943e4f6584cSmrg		  library_names=
7944e4f6584cSmrg		  old_library=
7945e4f6584cSmrg		  func_source "$lib"
7946e4f6584cSmrg		  for l in $old_library $library_names; do
7947f395c03eSmrg		    ll=$l
7948e4f6584cSmrg		  done
7949f395c03eSmrg		  if test "X$ll" = "X$old_library"; then # only static version available
7950f395c03eSmrg		    found=false
7951e4f6584cSmrg		    func_dirname "$lib" "" "."
7952f395c03eSmrg		    ladir=$func_dirname_result
7953e4f6584cSmrg		    lib=$ladir/$old_library
7954f395c03eSmrg		    if test prog,link = "$linkmode,$pass"; then
7955e4f6584cSmrg		      compile_deplibs="$deplib $compile_deplibs"
7956e4f6584cSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
7957e4f6584cSmrg		    else
7958e4f6584cSmrg		      deplibs="$deplib $deplibs"
7959f395c03eSmrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7960e4f6584cSmrg		    fi
7961e4f6584cSmrg		    continue
7962e4f6584cSmrg		  fi
7963e4f6584cSmrg		fi
7964e4f6584cSmrg		;;
7965e4f6584cSmrg	      *) ;;
7966e4f6584cSmrg	      esac
7967e4f6584cSmrg	    fi
7968f395c03eSmrg	  else
7969f395c03eSmrg	    # deplib doesn't seem to be a libtool library
7970f395c03eSmrg	    if test prog,link = "$linkmode,$pass"; then
7971f395c03eSmrg	      compile_deplibs="$deplib $compile_deplibs"
7972f395c03eSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
7973f395c03eSmrg	    else
7974f395c03eSmrg	      deplibs="$deplib $deplibs"
7975f395c03eSmrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7976f395c03eSmrg	    fi
7977f395c03eSmrg	    continue
7978e4f6584cSmrg	  fi
7979e4f6584cSmrg	  ;; # -l
7980e4f6584cSmrg	*.ltframework)
7981f395c03eSmrg	  if test prog,link = "$linkmode,$pass"; then
7982e4f6584cSmrg	    compile_deplibs="$deplib $compile_deplibs"
7983e4f6584cSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
7984e4f6584cSmrg	  else
7985e4f6584cSmrg	    deplibs="$deplib $deplibs"
7986f395c03eSmrg	    if test lib = "$linkmode"; then
7987e4f6584cSmrg		case "$new_inherited_linker_flags " in
7988e4f6584cSmrg		    *" $deplib "*) ;;
7989b12e5c03Smrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
7990e4f6584cSmrg		esac
7991e4f6584cSmrg	    fi
7992e4f6584cSmrg	  fi
7993e4f6584cSmrg	  continue
7994e4f6584cSmrg	  ;;
7995e4f6584cSmrg	-L*)
7996e4f6584cSmrg	  case $linkmode in
7997e4f6584cSmrg	  lib)
7998e4f6584cSmrg	    deplibs="$deplib $deplibs"
7999f395c03eSmrg	    test conv = "$pass" && continue
8000e4f6584cSmrg	    newdependency_libs="$deplib $newdependency_libs"
8001e4f6584cSmrg	    func_stripname '-L' '' "$deplib"
8002b12e5c03Smrg	    func_resolve_sysroot "$func_stripname_result"
8003b12e5c03Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8004e4f6584cSmrg	    ;;
8005e4f6584cSmrg	  prog)
8006f395c03eSmrg	    if test conv = "$pass"; then
8007e4f6584cSmrg	      deplibs="$deplib $deplibs"
8008e4f6584cSmrg	      continue
8009e4f6584cSmrg	    fi
8010f395c03eSmrg	    if test scan = "$pass"; then
8011e4f6584cSmrg	      deplibs="$deplib $deplibs"
8012e4f6584cSmrg	    else
8013e4f6584cSmrg	      compile_deplibs="$deplib $compile_deplibs"
8014e4f6584cSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8015e4f6584cSmrg	    fi
8016e4f6584cSmrg	    func_stripname '-L' '' "$deplib"
8017b12e5c03Smrg	    func_resolve_sysroot "$func_stripname_result"
8018b12e5c03Smrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
8019e4f6584cSmrg	    ;;
8020e4f6584cSmrg	  *)
8021f395c03eSmrg	    func_warning "'-L' is ignored for archives/objects"
8022e4f6584cSmrg	    ;;
8023e4f6584cSmrg	  esac # linkmode
8024e4f6584cSmrg	  continue
8025e4f6584cSmrg	  ;; # -L
8026e4f6584cSmrg	-R*)
8027f395c03eSmrg	  if test link = "$pass"; then
8028e4f6584cSmrg	    func_stripname '-R' '' "$deplib"
8029b12e5c03Smrg	    func_resolve_sysroot "$func_stripname_result"
8030b12e5c03Smrg	    dir=$func_resolve_sysroot_result
8031e4f6584cSmrg	    # Make sure the xrpath contains only unique directories.
8032e4f6584cSmrg	    case "$xrpath " in
8033e4f6584cSmrg	    *" $dir "*) ;;
8034b12e5c03Smrg	    *) func_append xrpath " $dir" ;;
8035e4f6584cSmrg	    esac
8036e4f6584cSmrg	  fi
8037e4f6584cSmrg	  deplibs="$deplib $deplibs"
8038e4f6584cSmrg	  continue
8039e4f6584cSmrg	  ;;
8040b12e5c03Smrg	*.la)
8041b12e5c03Smrg	  func_resolve_sysroot "$deplib"
8042b12e5c03Smrg	  lib=$func_resolve_sysroot_result
8043b12e5c03Smrg	  ;;
8044e4f6584cSmrg	*.$libext)
8045f395c03eSmrg	  if test conv = "$pass"; then
8046e4f6584cSmrg	    deplibs="$deplib $deplibs"
8047e4f6584cSmrg	    continue
8048e4f6584cSmrg	  fi
8049e4f6584cSmrg	  case $linkmode in
8050e4f6584cSmrg	  lib)
8051e4f6584cSmrg	    # Linking convenience modules into shared libraries is allowed,
8052e4f6584cSmrg	    # but linking other static libraries is non-portable.
8053e4f6584cSmrg	    case " $dlpreconveniencelibs " in
8054e4f6584cSmrg	    *" $deplib "*) ;;
8055e4f6584cSmrg	    *)
8056f395c03eSmrg	      valid_a_lib=false
8057e4f6584cSmrg	      case $deplibs_check_method in
8058e4f6584cSmrg		match_pattern*)
8059e4f6584cSmrg		  set dummy $deplibs_check_method; shift
8060e4f6584cSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
8061b12e5c03Smrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
8062e4f6584cSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
8063f395c03eSmrg		    valid_a_lib=:
8064e4f6584cSmrg		  fi
8065e4f6584cSmrg		;;
8066e4f6584cSmrg		pass_all)
8067f395c03eSmrg		  valid_a_lib=:
8068e4f6584cSmrg		;;
8069e4f6584cSmrg	      esac
8070f395c03eSmrg	      if $valid_a_lib; then
8071f395c03eSmrg		echo
8072f395c03eSmrg		$ECHO "*** Warning: Linking the shared library $output against the"
8073f395c03eSmrg		$ECHO "*** static library $deplib is not portable!"
8074f395c03eSmrg		deplibs="$deplib $deplibs"
8075f395c03eSmrg	      else
8076b12e5c03Smrg		echo
8077e4f6584cSmrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
8078b12e5c03Smrg		echo "*** I have the capability to make that library automatically link in when"
8079b12e5c03Smrg		echo "*** you link to this library.  But I can only do this if you have a"
8080b12e5c03Smrg		echo "*** shared version of the library, which you do not appear to have"
8081b12e5c03Smrg		echo "*** because the file extensions .$libext of this argument makes me believe"
8082b12e5c03Smrg		echo "*** that it is just a static archive that I should not use here."
8083e4f6584cSmrg	      fi
8084e4f6584cSmrg	      ;;
8085e4f6584cSmrg	    esac
8086e4f6584cSmrg	    continue
8087e4f6584cSmrg	    ;;
8088e4f6584cSmrg	  prog)
8089f395c03eSmrg	    if test link != "$pass"; then
8090e4f6584cSmrg	      deplibs="$deplib $deplibs"
8091e4f6584cSmrg	    else
8092e4f6584cSmrg	      compile_deplibs="$deplib $compile_deplibs"
8093e4f6584cSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8094e4f6584cSmrg	    fi
8095e4f6584cSmrg	    continue
8096e4f6584cSmrg	    ;;
8097e4f6584cSmrg	  esac # linkmode
8098e4f6584cSmrg	  ;; # *.$libext
8099e4f6584cSmrg	*.lo | *.$objext)
8100f395c03eSmrg	  if test conv = "$pass"; then
8101e4f6584cSmrg	    deplibs="$deplib $deplibs"
8102f395c03eSmrg	  elif test prog = "$linkmode"; then
8103f395c03eSmrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
8104e4f6584cSmrg	      # If there is no dlopen support or we're linking statically,
8105e4f6584cSmrg	      # we need to preload.
8106b12e5c03Smrg	      func_append newdlprefiles " $deplib"
8107e4f6584cSmrg	      compile_deplibs="$deplib $compile_deplibs"
8108e4f6584cSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
8109e4f6584cSmrg	    else
8110b12e5c03Smrg	      func_append newdlfiles " $deplib"
8111e4f6584cSmrg	    fi
8112e4f6584cSmrg	  fi
8113e4f6584cSmrg	  continue
8114e4f6584cSmrg	  ;;
8115e4f6584cSmrg	%DEPLIBS%)
8116f395c03eSmrg	  alldeplibs=:
8117e4f6584cSmrg	  continue
8118e4f6584cSmrg	  ;;
8119e4f6584cSmrg	esac # case $deplib
8120e4f6584cSmrg
8121f395c03eSmrg	$found || test -f "$lib" \
8122f395c03eSmrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
8123e4f6584cSmrg
8124e4f6584cSmrg	# Check to see that this really is a libtool archive.
8125e4f6584cSmrg	func_lalib_unsafe_p "$lib" \
8126f395c03eSmrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
8127e4f6584cSmrg
8128e4f6584cSmrg	func_dirname "$lib" "" "."
8129f395c03eSmrg	ladir=$func_dirname_result
8130e4f6584cSmrg
8131e4f6584cSmrg	dlname=
8132e4f6584cSmrg	dlopen=
8133e4f6584cSmrg	dlpreopen=
8134e4f6584cSmrg	libdir=
8135e4f6584cSmrg	library_names=
8136e4f6584cSmrg	old_library=
8137e4f6584cSmrg	inherited_linker_flags=
8138e4f6584cSmrg	# If the library was installed with an old release of libtool,
8139e4f6584cSmrg	# it will not redefine variables installed, or shouldnotlink
8140e4f6584cSmrg	installed=yes
8141e4f6584cSmrg	shouldnotlink=no
8142e4f6584cSmrg	avoidtemprpath=
8143e4f6584cSmrg
8144e4f6584cSmrg
8145e4f6584cSmrg	# Read the .la file
8146e4f6584cSmrg	func_source "$lib"
8147e4f6584cSmrg
8148e4f6584cSmrg	# Convert "-framework foo" to "foo.ltframework"
8149e4f6584cSmrg	if test -n "$inherited_linker_flags"; then
8150b12e5c03Smrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
8151e4f6584cSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
8152e4f6584cSmrg	    case " $new_inherited_linker_flags " in
8153e4f6584cSmrg	      *" $tmp_inherited_linker_flag "*) ;;
8154b12e5c03Smrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
8155e4f6584cSmrg	    esac
8156e4f6584cSmrg	  done
8157e4f6584cSmrg	fi
8158b12e5c03Smrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8159f395c03eSmrg	if test lib,link = "$linkmode,$pass" ||
8160f395c03eSmrg	   test prog,scan = "$linkmode,$pass" ||
8161f395c03eSmrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
8162b12e5c03Smrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
8163b12e5c03Smrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
8164e4f6584cSmrg	fi
8165e4f6584cSmrg
8166f395c03eSmrg	if test conv = "$pass"; then
8167e4f6584cSmrg	  # Only check for convenience libraries
8168e4f6584cSmrg	  deplibs="$lib $deplibs"
8169e4f6584cSmrg	  if test -z "$libdir"; then
8170e4f6584cSmrg	    if test -z "$old_library"; then
8171f395c03eSmrg	      func_fatal_error "cannot find name of link library for '$lib'"
8172e4f6584cSmrg	    fi
8173e4f6584cSmrg	    # It is a libtool convenience library, so add in its objects.
8174b12e5c03Smrg	    func_append convenience " $ladir/$objdir/$old_library"
8175b12e5c03Smrg	    func_append old_convenience " $ladir/$objdir/$old_library"
8176f395c03eSmrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8177f395c03eSmrg	    func_fatal_error "'$lib' is not a convenience library"
8178e4f6584cSmrg	  fi
8179f395c03eSmrg	  tmp_libs=
8180f395c03eSmrg	  for deplib in $dependency_libs; do
8181f395c03eSmrg	    deplibs="$deplib $deplibs"
8182f395c03eSmrg	    if $opt_preserve_dup_deps; then
8183f395c03eSmrg	      case "$tmp_libs " in
8184f395c03eSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8185f395c03eSmrg	      esac
8186f395c03eSmrg	    fi
8187f395c03eSmrg	    func_append tmp_libs " $deplib"
8188f395c03eSmrg	  done
8189e4f6584cSmrg	  continue
8190e4f6584cSmrg	fi # $pass = conv
8191e4f6584cSmrg
8192e4f6584cSmrg
8193e4f6584cSmrg	# Get the name of the library we link against.
8194e4f6584cSmrg	linklib=
8195b12e5c03Smrg	if test -n "$old_library" &&
8196f395c03eSmrg	   { test yes = "$prefer_static_libs" ||
8197f395c03eSmrg	     test built,no = "$prefer_static_libs,$installed"; }; then
8198b12e5c03Smrg	  linklib=$old_library
8199b12e5c03Smrg	else
8200b12e5c03Smrg	  for l in $old_library $library_names; do
8201f395c03eSmrg	    linklib=$l
8202b12e5c03Smrg	  done
8203b12e5c03Smrg	fi
8204e4f6584cSmrg	if test -z "$linklib"; then
8205f395c03eSmrg	  func_fatal_error "cannot find name of link library for '$lib'"
8206e4f6584cSmrg	fi
8207e4f6584cSmrg
8208e4f6584cSmrg	# This library was specified with -dlopen.
8209f395c03eSmrg	if test dlopen = "$pass"; then
8210f395c03eSmrg	  test -z "$libdir" \
8211f395c03eSmrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
8212e4f6584cSmrg	  if test -z "$dlname" ||
8213f395c03eSmrg	     test yes != "$dlopen_support" ||
8214f395c03eSmrg	     test no = "$build_libtool_libs"
8215f395c03eSmrg	  then
8216e4f6584cSmrg	    # If there is no dlname, no dlopen support or we're linking
8217e4f6584cSmrg	    # statically, we need to preload.  We also need to preload any
8218e4f6584cSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
8219e4f6584cSmrg	    # bomb out in the load deplibs phase.
8220b12e5c03Smrg	    func_append dlprefiles " $lib $dependency_libs"
8221e4f6584cSmrg	  else
8222b12e5c03Smrg	    func_append newdlfiles " $lib"
8223e4f6584cSmrg	  fi
8224e4f6584cSmrg	  continue
8225e4f6584cSmrg	fi # $pass = dlopen
8226e4f6584cSmrg
8227e4f6584cSmrg	# We need an absolute path.
8228e4f6584cSmrg	case $ladir in
8229f395c03eSmrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
8230e4f6584cSmrg	*)
8231e4f6584cSmrg	  abs_ladir=`cd "$ladir" && pwd`
8232e4f6584cSmrg	  if test -z "$abs_ladir"; then
8233f395c03eSmrg	    func_warning "cannot determine absolute directory name of '$ladir'"
8234e4f6584cSmrg	    func_warning "passing it literally to the linker, although it might fail"
8235f395c03eSmrg	    abs_ladir=$ladir
8236e4f6584cSmrg	  fi
8237e4f6584cSmrg	  ;;
8238e4f6584cSmrg	esac
8239e4f6584cSmrg	func_basename "$lib"
8240f395c03eSmrg	laname=$func_basename_result
8241e4f6584cSmrg
8242e4f6584cSmrg	# Find the relevant object directory and library name.
8243f395c03eSmrg	if test yes = "$installed"; then
8244b12e5c03Smrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8245f395c03eSmrg	    func_warning "library '$lib' was moved."
8246f395c03eSmrg	    dir=$ladir
8247f395c03eSmrg	    absdir=$abs_ladir
8248f395c03eSmrg	    libdir=$abs_ladir
8249e4f6584cSmrg	  else
8250f395c03eSmrg	    dir=$lt_sysroot$libdir
8251f395c03eSmrg	    absdir=$lt_sysroot$libdir
8252e4f6584cSmrg	  fi
8253f395c03eSmrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
8254e4f6584cSmrg	else
8255e4f6584cSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8256f395c03eSmrg	    dir=$ladir
8257f395c03eSmrg	    absdir=$abs_ladir
8258e4f6584cSmrg	    # Remove this search path later
8259b12e5c03Smrg	    func_append notinst_path " $abs_ladir"
8260e4f6584cSmrg	  else
8261f395c03eSmrg	    dir=$ladir/$objdir
8262f395c03eSmrg	    absdir=$abs_ladir/$objdir
8263e4f6584cSmrg	    # Remove this search path later
8264b12e5c03Smrg	    func_append notinst_path " $abs_ladir"
8265e4f6584cSmrg	  fi
8266e4f6584cSmrg	fi # $installed = yes
8267e4f6584cSmrg	func_stripname 'lib' '.la' "$laname"
8268e4f6584cSmrg	name=$func_stripname_result
8269e4f6584cSmrg
8270e4f6584cSmrg	# This library was specified with -dlpreopen.
8271f395c03eSmrg	if test dlpreopen = "$pass"; then
8272f395c03eSmrg	  if test -z "$libdir" && test prog = "$linkmode"; then
8273f395c03eSmrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
8274e4f6584cSmrg	  fi
8275f395c03eSmrg	  case $host in
8276b12e5c03Smrg	    # special handling for platforms with PE-DLLs.
8277b12e5c03Smrg	    *cygwin* | *mingw* | *cegcc* )
8278b12e5c03Smrg	      # Linker will automatically link against shared library if both
8279b12e5c03Smrg	      # static and shared are present.  Therefore, ensure we extract
8280b12e5c03Smrg	      # symbols from the import library if a shared library is present
8281b12e5c03Smrg	      # (otherwise, the dlopen module name will be incorrect).  We do
8282b12e5c03Smrg	      # this by putting the import library name into $newdlprefiles.
8283b12e5c03Smrg	      # We recover the dlopen module name by 'saving' the la file
8284b12e5c03Smrg	      # name in a special purpose variable, and (later) extracting the
8285b12e5c03Smrg	      # dlname from the la file.
8286b12e5c03Smrg	      if test -n "$dlname"; then
8287b12e5c03Smrg	        func_tr_sh "$dir/$linklib"
8288b12e5c03Smrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
8289b12e5c03Smrg	        func_append newdlprefiles " $dir/$linklib"
8290b12e5c03Smrg	      else
8291b12e5c03Smrg	        func_append newdlprefiles " $dir/$old_library"
8292b12e5c03Smrg	        # Keep a list of preopened convenience libraries to check
8293b12e5c03Smrg	        # that they are being used correctly in the link pass.
8294b12e5c03Smrg	        test -z "$libdir" && \
8295b12e5c03Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8296b12e5c03Smrg	      fi
8297b12e5c03Smrg	    ;;
8298b12e5c03Smrg	    * )
8299b12e5c03Smrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
8300b12e5c03Smrg	      # are required to link).
8301b12e5c03Smrg	      if test -n "$old_library"; then
8302b12e5c03Smrg	        func_append newdlprefiles " $dir/$old_library"
8303b12e5c03Smrg	        # Keep a list of preopened convenience libraries to check
8304b12e5c03Smrg	        # that they are being used correctly in the link pass.
8305b12e5c03Smrg	        test -z "$libdir" && \
8306b12e5c03Smrg	          func_append dlpreconveniencelibs " $dir/$old_library"
8307b12e5c03Smrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
8308b12e5c03Smrg	      elif test -n "$dlname"; then
8309b12e5c03Smrg	        func_append newdlprefiles " $dir/$dlname"
8310b12e5c03Smrg	      else
8311b12e5c03Smrg	        func_append newdlprefiles " $dir/$linklib"
8312b12e5c03Smrg	      fi
8313b12e5c03Smrg	    ;;
8314b12e5c03Smrg	  esac
8315e4f6584cSmrg	fi # $pass = dlpreopen
8316e4f6584cSmrg
8317e4f6584cSmrg	if test -z "$libdir"; then
8318e4f6584cSmrg	  # Link the convenience library
8319f395c03eSmrg	  if test lib = "$linkmode"; then
8320e4f6584cSmrg	    deplibs="$dir/$old_library $deplibs"
8321f395c03eSmrg	  elif test prog,link = "$linkmode,$pass"; then
8322e4f6584cSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
8323e4f6584cSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
8324e4f6584cSmrg	  else
8325e4f6584cSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
8326e4f6584cSmrg	  fi
8327e4f6584cSmrg	  continue
8328e4f6584cSmrg	fi
8329e4f6584cSmrg
8330e4f6584cSmrg
8331f395c03eSmrg	if test prog = "$linkmode" && test link != "$pass"; then
8332b12e5c03Smrg	  func_append newlib_search_path " $ladir"
8333e4f6584cSmrg	  deplibs="$lib $deplibs"
8334e4f6584cSmrg
8335f395c03eSmrg	  linkalldeplibs=false
8336f395c03eSmrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8337f395c03eSmrg	     test no = "$build_libtool_libs"; then
8338f395c03eSmrg	    linkalldeplibs=:
8339e4f6584cSmrg	  fi
8340e4f6584cSmrg
8341e4f6584cSmrg	  tmp_libs=
8342e4f6584cSmrg	  for deplib in $dependency_libs; do
8343e4f6584cSmrg	    case $deplib in
8344e4f6584cSmrg	    -L*) func_stripname '-L' '' "$deplib"
8345b12e5c03Smrg	         func_resolve_sysroot "$func_stripname_result"
8346b12e5c03Smrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
8347e4f6584cSmrg		 ;;
8348e4f6584cSmrg	    esac
8349e4f6584cSmrg	    # Need to link against all dependency_libs?
8350f395c03eSmrg	    if $linkalldeplibs; then
8351e4f6584cSmrg	      deplibs="$deplib $deplibs"
8352e4f6584cSmrg	    else
8353e4f6584cSmrg	      # Need to hardcode shared library paths
8354e4f6584cSmrg	      # or/and link against static libraries
8355e4f6584cSmrg	      newdependency_libs="$deplib $newdependency_libs"
8356e4f6584cSmrg	    fi
8357f395c03eSmrg	    if $opt_preserve_dup_deps; then
8358e4f6584cSmrg	      case "$tmp_libs " in
8359b12e5c03Smrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
8360e4f6584cSmrg	      esac
8361e4f6584cSmrg	    fi
8362b12e5c03Smrg	    func_append tmp_libs " $deplib"
8363e4f6584cSmrg	  done # for deplib
8364e4f6584cSmrg	  continue
8365e4f6584cSmrg	fi # $linkmode = prog...
8366e4f6584cSmrg
8367f395c03eSmrg	if test prog,link = "$linkmode,$pass"; then
8368e4f6584cSmrg	  if test -n "$library_names" &&
8369f395c03eSmrg	     { { test no = "$prefer_static_libs" ||
8370f395c03eSmrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
8371e4f6584cSmrg	       test -z "$old_library"; }; then
8372e4f6584cSmrg	    # We need to hardcode the library path
8373f395c03eSmrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
8374e4f6584cSmrg	      # Make sure the rpath contains only unique directories.
8375f395c03eSmrg	      case $temp_rpath: in
8376e4f6584cSmrg	      *"$absdir:"*) ;;
8377b12e5c03Smrg	      *) func_append temp_rpath "$absdir:" ;;
8378e4f6584cSmrg	      esac
8379e4f6584cSmrg	    fi
8380e4f6584cSmrg
8381e4f6584cSmrg	    # Hardcode the library path.
8382e4f6584cSmrg	    # Skip directories that are in the system default run-time
8383e4f6584cSmrg	    # search path.
8384e4f6584cSmrg	    case " $sys_lib_dlsearch_path " in
8385e4f6584cSmrg	    *" $absdir "*) ;;
8386e4f6584cSmrg	    *)
8387e4f6584cSmrg	      case "$compile_rpath " in
8388e4f6584cSmrg	      *" $absdir "*) ;;
8389b12e5c03Smrg	      *) func_append compile_rpath " $absdir" ;;
8390e4f6584cSmrg	      esac
8391e4f6584cSmrg	      ;;
8392e4f6584cSmrg	    esac
8393e4f6584cSmrg	    case " $sys_lib_dlsearch_path " in
8394e4f6584cSmrg	    *" $libdir "*) ;;
8395e4f6584cSmrg	    *)
8396e4f6584cSmrg	      case "$finalize_rpath " in
8397e4f6584cSmrg	      *" $libdir "*) ;;
8398b12e5c03Smrg	      *) func_append finalize_rpath " $libdir" ;;
8399e4f6584cSmrg	      esac
8400e4f6584cSmrg	      ;;
8401e4f6584cSmrg	    esac
8402e4f6584cSmrg	  fi # $linkmode,$pass = prog,link...
8403e4f6584cSmrg
8404f395c03eSmrg	  if $alldeplibs &&
8405f395c03eSmrg	     { test pass_all = "$deplibs_check_method" ||
8406f395c03eSmrg	       { test yes = "$build_libtool_libs" &&
8407e4f6584cSmrg		 test -n "$library_names"; }; }; then
8408e4f6584cSmrg	    # We only need to search for static libraries
8409e4f6584cSmrg	    continue
8410e4f6584cSmrg	  fi
8411e4f6584cSmrg	fi
8412e4f6584cSmrg
8413e4f6584cSmrg	link_static=no # Whether the deplib will be linked statically
8414e4f6584cSmrg	use_static_libs=$prefer_static_libs
8415f395c03eSmrg	if test built = "$use_static_libs" && test yes = "$installed"; then
8416e4f6584cSmrg	  use_static_libs=no
8417e4f6584cSmrg	fi
8418e4f6584cSmrg	if test -n "$library_names" &&
8419f395c03eSmrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
8420e4f6584cSmrg	  case $host in
8421f395c03eSmrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
8422e4f6584cSmrg	      # No point in relinking DLLs because paths are not encoded
8423b12e5c03Smrg	      func_append notinst_deplibs " $lib"
8424e4f6584cSmrg	      need_relink=no
8425e4f6584cSmrg	    ;;
8426e4f6584cSmrg	  *)
8427f395c03eSmrg	    if test no = "$installed"; then
8428b12e5c03Smrg	      func_append notinst_deplibs " $lib"
8429e4f6584cSmrg	      need_relink=yes
8430e4f6584cSmrg	    fi
8431e4f6584cSmrg	    ;;
8432e4f6584cSmrg	  esac
8433e4f6584cSmrg	  # This is a shared library
8434e4f6584cSmrg
8435e4f6584cSmrg	  # Warn about portability, can't link against -module's on some
8436e4f6584cSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8437f395c03eSmrg	  dlopenmodule=
8438e4f6584cSmrg	  for dlpremoduletest in $dlprefiles; do
8439e4f6584cSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8440f395c03eSmrg	      dlopenmodule=$dlpremoduletest
8441e4f6584cSmrg	      break
8442e4f6584cSmrg	    fi
8443e4f6584cSmrg	  done
8444f395c03eSmrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8445b12e5c03Smrg	    echo
8446f395c03eSmrg	    if test prog = "$linkmode"; then
8447e4f6584cSmrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
8448e4f6584cSmrg	    else
8449e4f6584cSmrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
8450e4f6584cSmrg	    fi
8451e4f6584cSmrg	    $ECHO "*** $linklib is not portable!"
8452e4f6584cSmrg	  fi
8453f395c03eSmrg	  if test lib = "$linkmode" &&
8454f395c03eSmrg	     test yes = "$hardcode_into_libs"; then
8455e4f6584cSmrg	    # Hardcode the library path.
8456e4f6584cSmrg	    # Skip directories that are in the system default run-time
8457e4f6584cSmrg	    # search path.
8458e4f6584cSmrg	    case " $sys_lib_dlsearch_path " in
8459e4f6584cSmrg	    *" $absdir "*) ;;
8460e4f6584cSmrg	    *)
8461e4f6584cSmrg	      case "$compile_rpath " in
8462e4f6584cSmrg	      *" $absdir "*) ;;
8463b12e5c03Smrg	      *) func_append compile_rpath " $absdir" ;;
8464e4f6584cSmrg	      esac
8465e4f6584cSmrg	      ;;
8466e4f6584cSmrg	    esac
8467e4f6584cSmrg	    case " $sys_lib_dlsearch_path " in
8468e4f6584cSmrg	    *" $libdir "*) ;;
8469e4f6584cSmrg	    *)
8470e4f6584cSmrg	      case "$finalize_rpath " in
8471e4f6584cSmrg	      *" $libdir "*) ;;
8472b12e5c03Smrg	      *) func_append finalize_rpath " $libdir" ;;
8473e4f6584cSmrg	      esac
8474e4f6584cSmrg	      ;;
8475e4f6584cSmrg	    esac
8476e4f6584cSmrg	  fi
8477e4f6584cSmrg
8478e4f6584cSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
8479e4f6584cSmrg	    # figure out the soname
8480e4f6584cSmrg	    set dummy $library_names
8481e4f6584cSmrg	    shift
8482f395c03eSmrg	    realname=$1
8483e4f6584cSmrg	    shift
8484e4f6584cSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
8485e4f6584cSmrg	    # use dlname if we got it. it's perfectly good, no?
8486e4f6584cSmrg	    if test -n "$dlname"; then
8487f395c03eSmrg	      soname=$dlname
8488e4f6584cSmrg	    elif test -n "$soname_spec"; then
8489e4f6584cSmrg	      # bleh windows
8490e4f6584cSmrg	      case $host in
8491f395c03eSmrg	      *cygwin* | mingw* | *cegcc* | *os2*)
8492e4f6584cSmrg	        func_arith $current - $age
8493e4f6584cSmrg		major=$func_arith_result
8494f395c03eSmrg		versuffix=-$major
8495e4f6584cSmrg		;;
8496e4f6584cSmrg	      esac
8497e4f6584cSmrg	      eval soname=\"$soname_spec\"
8498e4f6584cSmrg	    else
8499f395c03eSmrg	      soname=$realname
8500e4f6584cSmrg	    fi
8501e4f6584cSmrg
8502e4f6584cSmrg	    # Make a new name for the extract_expsyms_cmds to use
8503f395c03eSmrg	    soroot=$soname
8504e4f6584cSmrg	    func_basename "$soroot"
8505f395c03eSmrg	    soname=$func_basename_result
8506e4f6584cSmrg	    func_stripname 'lib' '.dll' "$soname"
8507e4f6584cSmrg	    newlib=libimp-$func_stripname_result.a
8508e4f6584cSmrg
8509e4f6584cSmrg	    # If the library has no export list, then create one now
8510e4f6584cSmrg	    if test -f "$output_objdir/$soname-def"; then :
8511e4f6584cSmrg	    else
8512f395c03eSmrg	      func_verbose "extracting exported symbol list from '$soname'"
8513e4f6584cSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
8514e4f6584cSmrg	    fi
8515e4f6584cSmrg
8516e4f6584cSmrg	    # Create $newlib
8517e4f6584cSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8518f395c03eSmrg	      func_verbose "generating import library for '$soname'"
8519e4f6584cSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
8520e4f6584cSmrg	    fi
8521e4f6584cSmrg	    # make sure the library variables are pointing to the new library
8522e4f6584cSmrg	    dir=$output_objdir
8523e4f6584cSmrg	    linklib=$newlib
8524e4f6584cSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
8525e4f6584cSmrg
8526f395c03eSmrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
8527e4f6584cSmrg	    add_shlibpath=
8528e4f6584cSmrg	    add_dir=
8529e4f6584cSmrg	    add=
8530e4f6584cSmrg	    lib_linked=yes
8531e4f6584cSmrg	    case $hardcode_action in
8532e4f6584cSmrg	    immediate | unsupported)
8533f395c03eSmrg	      if test no = "$hardcode_direct"; then
8534f395c03eSmrg		add=$dir/$linklib
8535e4f6584cSmrg		case $host in
8536f395c03eSmrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8537f395c03eSmrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
8538e4f6584cSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8539f395c03eSmrg		    *-*-unixware7*) add_dir=-L$dir ;;
8540e4f6584cSmrg		  *-*-darwin* )
8541f395c03eSmrg		    # if the lib is a (non-dlopened) module then we cannot
8542e4f6584cSmrg		    # link against it, someone is ignoring the earlier warnings
8543e4f6584cSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8544f395c03eSmrg			 $GREP ": [^:]* bundle" >/dev/null; then
8545e4f6584cSmrg		      if test "X$dlopenmodule" != "X$lib"; then
8546e4f6584cSmrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8547f395c03eSmrg			if test -z "$old_library"; then
8548b12e5c03Smrg			  echo
8549b12e5c03Smrg			  echo "*** And there doesn't seem to be a static archive available"
8550b12e5c03Smrg			  echo "*** The link will probably fail, sorry"
8551e4f6584cSmrg			else
8552f395c03eSmrg			  add=$dir/$old_library
8553e4f6584cSmrg			fi
8554e4f6584cSmrg		      elif test -n "$old_library"; then
8555f395c03eSmrg			add=$dir/$old_library
8556e4f6584cSmrg		      fi
8557e4f6584cSmrg		    fi
8558e4f6584cSmrg		esac
8559f395c03eSmrg	      elif test no = "$hardcode_minus_L"; then
8560e4f6584cSmrg		case $host in
8561f395c03eSmrg		*-*-sunos*) add_shlibpath=$dir ;;
8562e4f6584cSmrg		esac
8563f395c03eSmrg		add_dir=-L$dir
8564f395c03eSmrg		add=-l$name
8565f395c03eSmrg	      elif test no = "$hardcode_shlibpath_var"; then
8566f395c03eSmrg		add_shlibpath=$dir
8567f395c03eSmrg		add=-l$name
8568e4f6584cSmrg	      else
8569e4f6584cSmrg		lib_linked=no
8570e4f6584cSmrg	      fi
8571e4f6584cSmrg	      ;;
8572e4f6584cSmrg	    relink)
8573f395c03eSmrg	      if test yes = "$hardcode_direct" &&
8574f395c03eSmrg	         test no = "$hardcode_direct_absolute"; then
8575f395c03eSmrg		add=$dir/$linklib
8576f395c03eSmrg	      elif test yes = "$hardcode_minus_L"; then
8577f395c03eSmrg		add_dir=-L$absdir
8578e4f6584cSmrg		# Try looking first in the location we're being installed to.
8579e4f6584cSmrg		if test -n "$inst_prefix_dir"; then
8580e4f6584cSmrg		  case $libdir in
8581e4f6584cSmrg		    [\\/]*)
8582b12e5c03Smrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
8583e4f6584cSmrg		      ;;
8584e4f6584cSmrg		  esac
8585e4f6584cSmrg		fi
8586f395c03eSmrg		add=-l$name
8587f395c03eSmrg	      elif test yes = "$hardcode_shlibpath_var"; then
8588f395c03eSmrg		add_shlibpath=$dir
8589f395c03eSmrg		add=-l$name
8590e4f6584cSmrg	      else
8591e4f6584cSmrg		lib_linked=no
8592e4f6584cSmrg	      fi
8593e4f6584cSmrg	      ;;
8594e4f6584cSmrg	    *) lib_linked=no ;;
8595e4f6584cSmrg	    esac
8596e4f6584cSmrg
8597f395c03eSmrg	    if test yes != "$lib_linked"; then
8598e4f6584cSmrg	      func_fatal_configuration "unsupported hardcode properties"
8599e4f6584cSmrg	    fi
8600e4f6584cSmrg
8601e4f6584cSmrg	    if test -n "$add_shlibpath"; then
8602e4f6584cSmrg	      case :$compile_shlibpath: in
8603e4f6584cSmrg	      *":$add_shlibpath:"*) ;;
8604b12e5c03Smrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
8605e4f6584cSmrg	      esac
8606e4f6584cSmrg	    fi
8607f395c03eSmrg	    if test prog = "$linkmode"; then
8608e4f6584cSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
8609e4f6584cSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
8610e4f6584cSmrg	    else
8611e4f6584cSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8612e4f6584cSmrg	      test -n "$add" && deplibs="$add $deplibs"
8613f395c03eSmrg	      if test yes != "$hardcode_direct" &&
8614f395c03eSmrg		 test yes != "$hardcode_minus_L" &&
8615f395c03eSmrg		 test yes = "$hardcode_shlibpath_var"; then
8616e4f6584cSmrg		case :$finalize_shlibpath: in
8617e4f6584cSmrg		*":$libdir:"*) ;;
8618b12e5c03Smrg		*) func_append finalize_shlibpath "$libdir:" ;;
8619e4f6584cSmrg		esac
8620e4f6584cSmrg	      fi
8621e4f6584cSmrg	    fi
8622e4f6584cSmrg	  fi
8623e4f6584cSmrg
8624f395c03eSmrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
8625e4f6584cSmrg	    add_shlibpath=
8626e4f6584cSmrg	    add_dir=
8627e4f6584cSmrg	    add=
8628e4f6584cSmrg	    # Finalize command for both is simple: just hardcode it.
8629f395c03eSmrg	    if test yes = "$hardcode_direct" &&
8630f395c03eSmrg	       test no = "$hardcode_direct_absolute"; then
8631f395c03eSmrg	      add=$libdir/$linklib
8632f395c03eSmrg	    elif test yes = "$hardcode_minus_L"; then
8633f395c03eSmrg	      add_dir=-L$libdir
8634f395c03eSmrg	      add=-l$name
8635f395c03eSmrg	    elif test yes = "$hardcode_shlibpath_var"; then
8636e4f6584cSmrg	      case :$finalize_shlibpath: in
8637e4f6584cSmrg	      *":$libdir:"*) ;;
8638b12e5c03Smrg	      *) func_append finalize_shlibpath "$libdir:" ;;
8639e4f6584cSmrg	      esac
8640f395c03eSmrg	      add=-l$name
8641f395c03eSmrg	    elif test yes = "$hardcode_automatic"; then
8642e4f6584cSmrg	      if test -n "$inst_prefix_dir" &&
8643f395c03eSmrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8644f395c03eSmrg		add=$inst_prefix_dir$libdir/$linklib
8645e4f6584cSmrg	      else
8646f395c03eSmrg		add=$libdir/$linklib
8647e4f6584cSmrg	      fi
8648e4f6584cSmrg	    else
8649e4f6584cSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
8650f395c03eSmrg	      add_dir=-L$libdir
8651e4f6584cSmrg	      # Try looking first in the location we're being installed to.
8652e4f6584cSmrg	      if test -n "$inst_prefix_dir"; then
8653e4f6584cSmrg		case $libdir in
8654e4f6584cSmrg		  [\\/]*)
8655b12e5c03Smrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
8656e4f6584cSmrg		    ;;
8657e4f6584cSmrg		esac
8658e4f6584cSmrg	      fi
8659f395c03eSmrg	      add=-l$name
8660e4f6584cSmrg	    fi
8661e4f6584cSmrg
8662f395c03eSmrg	    if test prog = "$linkmode"; then
8663e4f6584cSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
8664e4f6584cSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
8665e4f6584cSmrg	    else
8666e4f6584cSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
8667e4f6584cSmrg	      test -n "$add" && deplibs="$add $deplibs"
8668e4f6584cSmrg	    fi
8669e4f6584cSmrg	  fi
8670f395c03eSmrg	elif test prog = "$linkmode"; then
8671e4f6584cSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
8672e4f6584cSmrg	  # is not unsupported.  This is valid on all known static and
8673e4f6584cSmrg	  # shared platforms.
8674f395c03eSmrg	  if test unsupported != "$hardcode_direct"; then
8675f395c03eSmrg	    test -n "$old_library" && linklib=$old_library
8676e4f6584cSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
8677e4f6584cSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
8678e4f6584cSmrg	  else
8679e4f6584cSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
8680e4f6584cSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
8681e4f6584cSmrg	  fi
8682f395c03eSmrg	elif test yes = "$build_libtool_libs"; then
8683e4f6584cSmrg	  # Not a shared library
8684f395c03eSmrg	  if test pass_all != "$deplibs_check_method"; then
8685e4f6584cSmrg	    # We're trying link a shared library against a static one
8686e4f6584cSmrg	    # but the system doesn't support it.
8687e4f6584cSmrg
8688e4f6584cSmrg	    # Just print a warning and add the library to dependency_libs so
8689e4f6584cSmrg	    # that the program can be linked against the static library.
8690b12e5c03Smrg	    echo
8691f395c03eSmrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8692b12e5c03Smrg	    echo "*** I have the capability to make that library automatically link in when"
8693b12e5c03Smrg	    echo "*** you link to this library.  But I can only do this if you have a"
8694b12e5c03Smrg	    echo "*** shared version of the library, which you do not appear to have."
8695f395c03eSmrg	    if test yes = "$module"; then
8696b12e5c03Smrg	      echo "*** But as you try to build a module library, libtool will still create "
8697b12e5c03Smrg	      echo "*** a static module, that should work as long as the dlopening application"
8698b12e5c03Smrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
8699e4f6584cSmrg	      if test -z "$global_symbol_pipe"; then
8700b12e5c03Smrg		echo
8701b12e5c03Smrg		echo "*** However, this would only work if libtool was able to extract symbol"
8702f395c03eSmrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8703b12e5c03Smrg		echo "*** not find such a program.  So, this module is probably useless."
8704f395c03eSmrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
8705e4f6584cSmrg	      fi
8706f395c03eSmrg	      if test no = "$build_old_libs"; then
8707e4f6584cSmrg		build_libtool_libs=module
8708e4f6584cSmrg		build_old_libs=yes
8709e4f6584cSmrg	      else
8710e4f6584cSmrg		build_libtool_libs=no
8711e4f6584cSmrg	      fi
8712e4f6584cSmrg	    fi
8713e4f6584cSmrg	  else
8714e4f6584cSmrg	    deplibs="$dir/$old_library $deplibs"
8715e4f6584cSmrg	    link_static=yes
8716e4f6584cSmrg	  fi
8717e4f6584cSmrg	fi # link shared/static library?
8718e4f6584cSmrg
8719f395c03eSmrg	if test lib = "$linkmode"; then
8720e4f6584cSmrg	  if test -n "$dependency_libs" &&
8721f395c03eSmrg	     { test yes != "$hardcode_into_libs" ||
8722f395c03eSmrg	       test yes = "$build_old_libs" ||
8723f395c03eSmrg	       test yes = "$link_static"; }; then
8724e4f6584cSmrg	    # Extract -R from dependency_libs
8725e4f6584cSmrg	    temp_deplibs=
8726e4f6584cSmrg	    for libdir in $dependency_libs; do
8727e4f6584cSmrg	      case $libdir in
8728e4f6584cSmrg	      -R*) func_stripname '-R' '' "$libdir"
8729e4f6584cSmrg	           temp_xrpath=$func_stripname_result
8730e4f6584cSmrg		   case " $xrpath " in
8731e4f6584cSmrg		   *" $temp_xrpath "*) ;;
8732b12e5c03Smrg		   *) func_append xrpath " $temp_xrpath";;
8733e4f6584cSmrg		   esac;;
8734b12e5c03Smrg	      *) func_append temp_deplibs " $libdir";;
8735e4f6584cSmrg	      esac
8736e4f6584cSmrg	    done
8737f395c03eSmrg	    dependency_libs=$temp_deplibs
8738e4f6584cSmrg	  fi
8739e4f6584cSmrg
8740b12e5c03Smrg	  func_append newlib_search_path " $absdir"
8741e4f6584cSmrg	  # Link against this library
8742f395c03eSmrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
8743e4f6584cSmrg	  # ... and its dependency_libs
8744e4f6584cSmrg	  tmp_libs=
8745e4f6584cSmrg	  for deplib in $dependency_libs; do
8746e4f6584cSmrg	    newdependency_libs="$deplib $newdependency_libs"
8747b12e5c03Smrg	    case $deplib in
8748b12e5c03Smrg              -L*) func_stripname '-L' '' "$deplib"
8749b12e5c03Smrg                   func_resolve_sysroot "$func_stripname_result";;
8750b12e5c03Smrg              *) func_resolve_sysroot "$deplib" ;;
8751b12e5c03Smrg            esac
8752f395c03eSmrg	    if $opt_preserve_dup_deps; then
8753e4f6584cSmrg	      case "$tmp_libs " in
8754b12e5c03Smrg	      *" $func_resolve_sysroot_result "*)
8755b12e5c03Smrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
8756e4f6584cSmrg	      esac
8757e4f6584cSmrg	    fi
8758b12e5c03Smrg	    func_append tmp_libs " $func_resolve_sysroot_result"
8759e4f6584cSmrg	  done
8760e4f6584cSmrg
8761f395c03eSmrg	  if test no != "$link_all_deplibs"; then
8762e4f6584cSmrg	    # Add the search paths of all dependency libraries
8763e4f6584cSmrg	    for deplib in $dependency_libs; do
87647b58d2e0Smrg	      path=
8765e4f6584cSmrg	      case $deplib in
8766f395c03eSmrg	      -L*) path=$deplib ;;
8767e4f6584cSmrg	      *.la)
8768b12e5c03Smrg	        func_resolve_sysroot "$deplib"
8769b12e5c03Smrg	        deplib=$func_resolve_sysroot_result
8770e4f6584cSmrg	        func_dirname "$deplib" "" "."
8771b12e5c03Smrg		dir=$func_dirname_result
8772e4f6584cSmrg		# We need an absolute path.
8773e4f6584cSmrg		case $dir in
8774f395c03eSmrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
8775e4f6584cSmrg		*)
8776e4f6584cSmrg		  absdir=`cd "$dir" && pwd`
8777e4f6584cSmrg		  if test -z "$absdir"; then
8778f395c03eSmrg		    func_warning "cannot determine absolute directory name of '$dir'"
8779f395c03eSmrg		    absdir=$dir
8780e4f6584cSmrg		  fi
8781e4f6584cSmrg		  ;;
8782e4f6584cSmrg		esac
8783e4f6584cSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
8784e4f6584cSmrg		case $host in
8785e4f6584cSmrg		*-*-darwin*)
8786e4f6584cSmrg		  depdepl=
8787f395c03eSmrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8788f395c03eSmrg		  if test -n "$deplibrary_names"; then
8789f395c03eSmrg		    for tmp in $deplibrary_names; do
8790e4f6584cSmrg		      depdepl=$tmp
8791e4f6584cSmrg		    done
8792f395c03eSmrg		    if test -f "$absdir/$objdir/$depdepl"; then
8793f395c03eSmrg		      depdepl=$absdir/$objdir/$depdepl
8794f395c03eSmrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
8795e4f6584cSmrg                      if test -z "$darwin_install_name"; then
8796f395c03eSmrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
8797e4f6584cSmrg                      fi
8798f395c03eSmrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8799f395c03eSmrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
8800e4f6584cSmrg		      path=
8801e4f6584cSmrg		    fi
8802e4f6584cSmrg		  fi
8803e4f6584cSmrg		  ;;
8804e4f6584cSmrg		*)
8805f395c03eSmrg		  path=-L$absdir/$objdir
8806e4f6584cSmrg		  ;;
8807e4f6584cSmrg		esac
8808e4f6584cSmrg		else
8809f395c03eSmrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
8810e4f6584cSmrg		  test -z "$libdir" && \
8811f395c03eSmrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
8812e4f6584cSmrg		  test "$absdir" != "$libdir" && \
8813f395c03eSmrg		    func_warning "'$deplib' seems to be moved"
8814e4f6584cSmrg
8815f395c03eSmrg		  path=-L$absdir
8816e4f6584cSmrg		fi
8817e4f6584cSmrg		;;
8818e4f6584cSmrg	      esac
8819e4f6584cSmrg	      case " $deplibs " in
8820e4f6584cSmrg	      *" $path "*) ;;
8821e4f6584cSmrg	      *) deplibs="$path $deplibs" ;;
8822e4f6584cSmrg	      esac
8823e4f6584cSmrg	    done
8824e4f6584cSmrg	  fi # link_all_deplibs != no
8825e4f6584cSmrg	fi # linkmode = lib
8826e4f6584cSmrg      done # for deplib in $libs
8827f395c03eSmrg      if test link = "$pass"; then
8828f395c03eSmrg	if test prog = "$linkmode"; then
8829e4f6584cSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
8830e4f6584cSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
8831e4f6584cSmrg	else
8832b12e5c03Smrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
8833e4f6584cSmrg	fi
8834e4f6584cSmrg      fi
8835f395c03eSmrg      dependency_libs=$newdependency_libs
8836f395c03eSmrg      if test dlpreopen = "$pass"; then
8837e4f6584cSmrg	# Link the dlpreopened libraries before other libraries
8838e4f6584cSmrg	for deplib in $save_deplibs; do
8839e4f6584cSmrg	  deplibs="$deplib $deplibs"
8840e4f6584cSmrg	done
8841e4f6584cSmrg      fi
8842f395c03eSmrg      if test dlopen != "$pass"; then
8843f395c03eSmrg	test conv = "$pass" || {
8844e4f6584cSmrg	  # Make sure lib_search_path contains only unique directories.
8845e4f6584cSmrg	  lib_search_path=
8846e4f6584cSmrg	  for dir in $newlib_search_path; do
8847e4f6584cSmrg	    case "$lib_search_path " in
8848e4f6584cSmrg	    *" $dir "*) ;;
8849b12e5c03Smrg	    *) func_append lib_search_path " $dir" ;;
8850e4f6584cSmrg	    esac
8851e4f6584cSmrg	  done
8852e4f6584cSmrg	  newlib_search_path=
8853f395c03eSmrg	}
8854e4f6584cSmrg
8855f395c03eSmrg	if test prog,link = "$linkmode,$pass"; then
8856e4f6584cSmrg	  vars="compile_deplibs finalize_deplibs"
8857f395c03eSmrg	else
8858f395c03eSmrg	  vars=deplibs
8859e4f6584cSmrg	fi
8860e4f6584cSmrg	for var in $vars dependency_libs; do
8861e4f6584cSmrg	  # Add libraries to $var in reverse order
8862e4f6584cSmrg	  eval tmp_libs=\"\$$var\"
8863e4f6584cSmrg	  new_libs=
8864e4f6584cSmrg	  for deplib in $tmp_libs; do
8865e4f6584cSmrg	    # FIXME: Pedantically, this is the right thing to do, so
8866e4f6584cSmrg	    #        that some nasty dependency loop isn't accidentally
8867e4f6584cSmrg	    #        broken:
8868e4f6584cSmrg	    #new_libs="$deplib $new_libs"
8869e4f6584cSmrg	    # Pragmatically, this seems to cause very few problems in
8870e4f6584cSmrg	    # practice:
8871e4f6584cSmrg	    case $deplib in
8872e4f6584cSmrg	    -L*) new_libs="$deplib $new_libs" ;;
8873e4f6584cSmrg	    -R*) ;;
8874e4f6584cSmrg	    *)
8875e4f6584cSmrg	      # And here is the reason: when a library appears more
8876e4f6584cSmrg	      # than once as an explicit dependence of a library, or
8877e4f6584cSmrg	      # is implicitly linked in more than once by the
8878e4f6584cSmrg	      # compiler, it is considered special, and multiple
8879e4f6584cSmrg	      # occurrences thereof are not removed.  Compare this
8880e4f6584cSmrg	      # with having the same library being listed as a
8881e4f6584cSmrg	      # dependency of multiple other libraries: in this case,
8882e4f6584cSmrg	      # we know (pedantically, we assume) the library does not
8883e4f6584cSmrg	      # need to be listed more than once, so we keep only the
8884e4f6584cSmrg	      # last copy.  This is not always right, but it is rare
8885e4f6584cSmrg	      # enough that we require users that really mean to play
8886e4f6584cSmrg	      # such unportable linking tricks to link the library
8887e4f6584cSmrg	      # using -Wl,-lname, so that libtool does not consider it
8888e4f6584cSmrg	      # for duplicate removal.
8889e4f6584cSmrg	      case " $specialdeplibs " in
8890e4f6584cSmrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
8891e4f6584cSmrg	      *)
8892e4f6584cSmrg		case " $new_libs " in
8893e4f6584cSmrg		*" $deplib "*) ;;
8894e4f6584cSmrg		*) new_libs="$deplib $new_libs" ;;
8895e4f6584cSmrg		esac
8896e4f6584cSmrg		;;
8897e4f6584cSmrg	      esac
8898e4f6584cSmrg	      ;;
8899e4f6584cSmrg	    esac
8900e4f6584cSmrg	  done
8901e4f6584cSmrg	  tmp_libs=
8902e4f6584cSmrg	  for deplib in $new_libs; do
8903e4f6584cSmrg	    case $deplib in
8904e4f6584cSmrg	    -L*)
8905e4f6584cSmrg	      case " $tmp_libs " in
8906e4f6584cSmrg	      *" $deplib "*) ;;
8907b12e5c03Smrg	      *) func_append tmp_libs " $deplib" ;;
8908e4f6584cSmrg	      esac
8909e4f6584cSmrg	      ;;
8910b12e5c03Smrg	    *) func_append tmp_libs " $deplib" ;;
8911e4f6584cSmrg	    esac
8912e4f6584cSmrg	  done
8913e4f6584cSmrg	  eval $var=\"$tmp_libs\"
8914e4f6584cSmrg	done # for var
8915e4f6584cSmrg      fi
8916f395c03eSmrg
8917f395c03eSmrg      # Add Sun CC postdeps if required:
8918f395c03eSmrg      test CXX = "$tagname" && {
8919f395c03eSmrg        case $host_os in
8920f395c03eSmrg        linux*)
8921beef1b22Smrg          case `$CC -V 2>&1 | $SED 5q` in
8922f395c03eSmrg          *Sun\ C*) # Sun C++ 5.9
8923f395c03eSmrg            func_suncc_cstd_abi
8924f395c03eSmrg
8925f395c03eSmrg            if test no != "$suncc_use_cstd_abi"; then
8926f395c03eSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8927f395c03eSmrg            fi
8928f395c03eSmrg            ;;
8929f395c03eSmrg          esac
8930f395c03eSmrg          ;;
8931f395c03eSmrg
8932f395c03eSmrg        solaris*)
8933f395c03eSmrg          func_cc_basename "$CC"
8934f395c03eSmrg          case $func_cc_basename_result in
8935f395c03eSmrg          CC* | sunCC*)
8936f395c03eSmrg            func_suncc_cstd_abi
8937f395c03eSmrg
8938f395c03eSmrg            if test no != "$suncc_use_cstd_abi"; then
8939f395c03eSmrg              func_append postdeps ' -library=Cstd -library=Crun'
8940f395c03eSmrg            fi
8941f395c03eSmrg            ;;
8942f395c03eSmrg          esac
8943f395c03eSmrg          ;;
8944f395c03eSmrg        esac
8945f395c03eSmrg      }
8946f395c03eSmrg
8947e4f6584cSmrg      # Last step: remove runtime libs from dependency_libs
8948e4f6584cSmrg      # (they stay in deplibs)
8949e4f6584cSmrg      tmp_libs=
8950f395c03eSmrg      for i in $dependency_libs; do
8951e4f6584cSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
8952e4f6584cSmrg	*" $i "*)
8953f395c03eSmrg	  i=
8954e4f6584cSmrg	  ;;
8955e4f6584cSmrg	esac
8956f395c03eSmrg	if test -n "$i"; then
8957b12e5c03Smrg	  func_append tmp_libs " $i"
8958e4f6584cSmrg	fi
8959e4f6584cSmrg      done
8960e4f6584cSmrg      dependency_libs=$tmp_libs
8961e4f6584cSmrg    done # for pass
8962f395c03eSmrg    if test prog = "$linkmode"; then
8963f395c03eSmrg      dlfiles=$newdlfiles
8964e4f6584cSmrg    fi
8965f395c03eSmrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8966f395c03eSmrg      dlprefiles=$newdlprefiles
8967e4f6584cSmrg    fi
8968e4f6584cSmrg
8969e4f6584cSmrg    case $linkmode in
8970e4f6584cSmrg    oldlib)
8971f395c03eSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8972f395c03eSmrg	func_warning "'-dlopen' is ignored for archives"
8973e4f6584cSmrg      fi
8974e4f6584cSmrg
8975e4f6584cSmrg      case " $deplibs" in
8976e4f6584cSmrg      *\ -l* | *\ -L*)
8977f395c03eSmrg	func_warning "'-l' and '-L' are ignored for archives" ;;
8978e4f6584cSmrg      esac
8979e4f6584cSmrg
8980e4f6584cSmrg      test -n "$rpath" && \
8981f395c03eSmrg	func_warning "'-rpath' is ignored for archives"
8982e4f6584cSmrg
8983e4f6584cSmrg      test -n "$xrpath" && \
8984f395c03eSmrg	func_warning "'-R' is ignored for archives"
8985e4f6584cSmrg
8986e4f6584cSmrg      test -n "$vinfo" && \
8987f395c03eSmrg	func_warning "'-version-info/-version-number' is ignored for archives"
8988e4f6584cSmrg
8989e4f6584cSmrg      test -n "$release" && \
8990f395c03eSmrg	func_warning "'-release' is ignored for archives"
8991e4f6584cSmrg
8992e4f6584cSmrg      test -n "$export_symbols$export_symbols_regex" && \
8993f395c03eSmrg	func_warning "'-export-symbols' is ignored for archives"
8994e4f6584cSmrg
8995e4f6584cSmrg      # Now set the variables for building old libraries.
8996e4f6584cSmrg      build_libtool_libs=no
8997f395c03eSmrg      oldlibs=$output
8998b12e5c03Smrg      func_append objs "$old_deplibs"
8999e4f6584cSmrg      ;;
9000e4f6584cSmrg
9001e4f6584cSmrg    lib)
9002f395c03eSmrg      # Make sure we only generate libraries of the form 'libNAME.la'.
9003e4f6584cSmrg      case $outputname in
9004e4f6584cSmrg      lib*)
9005e4f6584cSmrg	func_stripname 'lib' '.la' "$outputname"
9006e4f6584cSmrg	name=$func_stripname_result
9007e4f6584cSmrg	eval shared_ext=\"$shrext_cmds\"
9008e4f6584cSmrg	eval libname=\"$libname_spec\"
9009e4f6584cSmrg	;;
9010e4f6584cSmrg      *)
9011f395c03eSmrg	test no = "$module" \
9012f395c03eSmrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
9013e4f6584cSmrg
9014f395c03eSmrg	if test no != "$need_lib_prefix"; then
9015e4f6584cSmrg	  # Add the "lib" prefix for modules if required
9016e4f6584cSmrg	  func_stripname '' '.la' "$outputname"
9017e4f6584cSmrg	  name=$func_stripname_result
9018e4f6584cSmrg	  eval shared_ext=\"$shrext_cmds\"
9019e4f6584cSmrg	  eval libname=\"$libname_spec\"
9020e4f6584cSmrg	else
9021e4f6584cSmrg	  func_stripname '' '.la' "$outputname"
9022e4f6584cSmrg	  libname=$func_stripname_result
9023e4f6584cSmrg	fi
9024e4f6584cSmrg	;;
9025e4f6584cSmrg      esac
9026e4f6584cSmrg
9027e4f6584cSmrg      if test -n "$objs"; then
9028f395c03eSmrg	if test pass_all != "$deplibs_check_method"; then
9029f395c03eSmrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
9030e4f6584cSmrg	else
9031b12e5c03Smrg	  echo
9032e4f6584cSmrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
9033e4f6584cSmrg	  $ECHO "*** objects $objs is not portable!"
9034b12e5c03Smrg	  func_append libobjs " $objs"
9035e4f6584cSmrg	fi
9036e4f6584cSmrg      fi
9037e4f6584cSmrg
9038f395c03eSmrg      test no = "$dlself" \
9039f395c03eSmrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
9040e4f6584cSmrg
9041e4f6584cSmrg      set dummy $rpath
9042e4f6584cSmrg      shift
9043f395c03eSmrg      test 1 -lt "$#" \
9044f395c03eSmrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
9045e4f6584cSmrg
9046f395c03eSmrg      install_libdir=$1
9047e4f6584cSmrg
9048e4f6584cSmrg      oldlibs=
9049e4f6584cSmrg      if test -z "$rpath"; then
9050f395c03eSmrg	if test yes = "$build_libtool_libs"; then
9051e4f6584cSmrg	  # Building a libtool convenience library.
9052f395c03eSmrg	  # Some compilers have problems with a '.al' extension so
9053e4f6584cSmrg	  # convenience libraries should have the same extension an
9054e4f6584cSmrg	  # archive normally would.
9055e4f6584cSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
9056e4f6584cSmrg	  build_libtool_libs=convenience
9057e4f6584cSmrg	  build_old_libs=yes
9058e4f6584cSmrg	fi
9059e4f6584cSmrg
9060e4f6584cSmrg	test -n "$vinfo" && \
9061f395c03eSmrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
9062e4f6584cSmrg
9063e4f6584cSmrg	test -n "$release" && \
9064f395c03eSmrg	  func_warning "'-release' is ignored for convenience libraries"
9065e4f6584cSmrg      else
9066e4f6584cSmrg
9067e4f6584cSmrg	# Parse the version information argument.
9068f395c03eSmrg	save_ifs=$IFS; IFS=:
9069e4f6584cSmrg	set dummy $vinfo 0 0 0
9070e4f6584cSmrg	shift
9071f395c03eSmrg	IFS=$save_ifs
9072e4f6584cSmrg
9073e4f6584cSmrg	test -n "$7" && \
9074f395c03eSmrg	  func_fatal_help "too many parameters to '-version-info'"
9075e4f6584cSmrg
9076e4f6584cSmrg	# convert absolute version numbers to libtool ages
9077e4f6584cSmrg	# this retains compatibility with .la files and attempts
9078e4f6584cSmrg	# to make the code below a bit more comprehensible
9079e4f6584cSmrg
9080e4f6584cSmrg	case $vinfo_number in
9081e4f6584cSmrg	yes)
9082f395c03eSmrg	  number_major=$1
9083f395c03eSmrg	  number_minor=$2
9084f395c03eSmrg	  number_revision=$3
9085e4f6584cSmrg	  #
9086e4f6584cSmrg	  # There are really only two kinds -- those that
9087e4f6584cSmrg	  # use the current revision as the major version
9088e4f6584cSmrg	  # and those that subtract age and use age as
9089e4f6584cSmrg	  # a minor version.  But, then there is irix
9090f395c03eSmrg	  # that has an extra 1 added just for fun
9091e4f6584cSmrg	  #
9092e4f6584cSmrg	  case $version_type in
9093b12e5c03Smrg	  # correct linux to gnu/linux during the next big refactor
9094beef1b22Smrg	  darwin|freebsd-elf|linux|midnightbsd-elf|osf|windows|none)
9095e4f6584cSmrg	    func_arith $number_major + $number_minor
9096e4f6584cSmrg	    current=$func_arith_result
9097f395c03eSmrg	    age=$number_minor
9098f395c03eSmrg	    revision=$number_revision
9099e4f6584cSmrg	    ;;
9100f395c03eSmrg	  freebsd-aout|qnx|sunos)
9101f395c03eSmrg	    current=$number_major
9102f395c03eSmrg	    revision=$number_minor
9103f395c03eSmrg	    age=0
9104e4f6584cSmrg	    ;;
9105e4f6584cSmrg	  irix|nonstopux)
9106e4f6584cSmrg	    func_arith $number_major + $number_minor
9107e4f6584cSmrg	    current=$func_arith_result
9108f395c03eSmrg	    age=$number_minor
9109f395c03eSmrg	    revision=$number_minor
9110e4f6584cSmrg	    lt_irix_increment=no
9111e4f6584cSmrg	    ;;
9112e4f6584cSmrg	  esac
9113e4f6584cSmrg	  ;;
9114e4f6584cSmrg	no)
9115f395c03eSmrg	  current=$1
9116f395c03eSmrg	  revision=$2
9117f395c03eSmrg	  age=$3
9118e4f6584cSmrg	  ;;
9119e4f6584cSmrg	esac
9120e4f6584cSmrg
9121e4f6584cSmrg	# Check that each of the things are valid numbers.
9122e4f6584cSmrg	case $current in
9123e4f6584cSmrg	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]) ;;
9124e4f6584cSmrg	*)
9125f395c03eSmrg	  func_error "CURRENT '$current' must be a nonnegative integer"
9126f395c03eSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9127e4f6584cSmrg	  ;;
9128e4f6584cSmrg	esac
9129e4f6584cSmrg
9130e4f6584cSmrg	case $revision in
9131e4f6584cSmrg	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]) ;;
9132e4f6584cSmrg	*)
9133f395c03eSmrg	  func_error "REVISION '$revision' must be a nonnegative integer"
9134f395c03eSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9135e4f6584cSmrg	  ;;
9136e4f6584cSmrg	esac
9137e4f6584cSmrg
9138e4f6584cSmrg	case $age in
9139e4f6584cSmrg	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]) ;;
9140e4f6584cSmrg	*)
9141f395c03eSmrg	  func_error "AGE '$age' must be a nonnegative integer"
9142f395c03eSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9143e4f6584cSmrg	  ;;
9144e4f6584cSmrg	esac
9145e4f6584cSmrg
9146e4f6584cSmrg	if test "$age" -gt "$current"; then
9147f395c03eSmrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
9148f395c03eSmrg	  func_fatal_error "'$vinfo' is not valid version information"
9149e4f6584cSmrg	fi
9150e4f6584cSmrg
9151e4f6584cSmrg	# Calculate the version variables.
9152e4f6584cSmrg	major=
9153e4f6584cSmrg	versuffix=
9154e4f6584cSmrg	verstring=
9155e4f6584cSmrg	case $version_type in
9156e4f6584cSmrg	none) ;;
9157e4f6584cSmrg
9158e4f6584cSmrg	darwin)
9159e4f6584cSmrg	  # Like Linux, but with the current version available in
9160e4f6584cSmrg	  # verstring for coding it into the library header
9161e4f6584cSmrg	  func_arith $current - $age
9162e4f6584cSmrg	  major=.$func_arith_result
9163f395c03eSmrg	  versuffix=$major.$age.$revision
9164e4f6584cSmrg	  # Darwin ld doesn't like 0 for these options...
9165e4f6584cSmrg	  func_arith $current + 1
9166e4f6584cSmrg	  minor_current=$func_arith_result
9167f395c03eSmrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9168e4f6584cSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9169f395c03eSmrg          # On Darwin other compilers
9170f395c03eSmrg          case $CC in
9171f395c03eSmrg              nagfor*)
9172f395c03eSmrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
9173f395c03eSmrg                  ;;
9174f395c03eSmrg              *)
9175f395c03eSmrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
9176f395c03eSmrg                  ;;
9177f395c03eSmrg          esac
9178e4f6584cSmrg	  ;;
9179e4f6584cSmrg
9180e4f6584cSmrg	freebsd-aout)
9181f395c03eSmrg	  major=.$current
9182f395c03eSmrg	  versuffix=.$current.$revision
9183e4f6584cSmrg	  ;;
9184e4f6584cSmrg
9185beef1b22Smrg	freebsd-elf | midnightbsd-elf)
9186f395c03eSmrg	  func_arith $current - $age
9187f395c03eSmrg	  major=.$func_arith_result
9188f395c03eSmrg	  versuffix=$major.$age.$revision
9189e4f6584cSmrg	  ;;
9190e4f6584cSmrg
9191e4f6584cSmrg	irix | nonstopux)
9192f395c03eSmrg	  if test no = "$lt_irix_increment"; then
9193e4f6584cSmrg	    func_arith $current - $age
9194e4f6584cSmrg	  else
9195e4f6584cSmrg	    func_arith $current - $age + 1
9196e4f6584cSmrg	  fi
9197e4f6584cSmrg	  major=$func_arith_result
9198e4f6584cSmrg
9199e4f6584cSmrg	  case $version_type in
9200e4f6584cSmrg	    nonstopux) verstring_prefix=nonstopux ;;
9201e4f6584cSmrg	    *)         verstring_prefix=sgi ;;
9202e4f6584cSmrg	  esac
9203f395c03eSmrg	  verstring=$verstring_prefix$major.$revision
9204e4f6584cSmrg
9205e4f6584cSmrg	  # Add in all the interfaces that we are compatible with.
9206e4f6584cSmrg	  loop=$revision
9207f395c03eSmrg	  while test 0 -ne "$loop"; do
9208e4f6584cSmrg	    func_arith $revision - $loop
9209e4f6584cSmrg	    iface=$func_arith_result
9210e4f6584cSmrg	    func_arith $loop - 1
9211e4f6584cSmrg	    loop=$func_arith_result
9212f395c03eSmrg	    verstring=$verstring_prefix$major.$iface:$verstring
9213e4f6584cSmrg	  done
9214e4f6584cSmrg
9215f395c03eSmrg	  # Before this point, $major must not contain '.'.
9216e4f6584cSmrg	  major=.$major
9217f395c03eSmrg	  versuffix=$major.$revision
9218e4f6584cSmrg	  ;;
9219e4f6584cSmrg
9220b12e5c03Smrg	linux) # correct to gnu/linux during the next big refactor
9221e4f6584cSmrg	  func_arith $current - $age
9222e4f6584cSmrg	  major=.$func_arith_result
9223f395c03eSmrg	  versuffix=$major.$age.$revision
9224e4f6584cSmrg	  ;;
9225e4f6584cSmrg
9226e4f6584cSmrg	osf)
9227e4f6584cSmrg	  func_arith $current - $age
9228e4f6584cSmrg	  major=.$func_arith_result
9229f395c03eSmrg	  versuffix=.$current.$age.$revision
9230f395c03eSmrg	  verstring=$current.$age.$revision
9231e4f6584cSmrg
9232e4f6584cSmrg	  # Add in all the interfaces that we are compatible with.
9233e4f6584cSmrg	  loop=$age
9234f395c03eSmrg	  while test 0 -ne "$loop"; do
9235e4f6584cSmrg	    func_arith $current - $loop
9236e4f6584cSmrg	    iface=$func_arith_result
9237e4f6584cSmrg	    func_arith $loop - 1
9238e4f6584cSmrg	    loop=$func_arith_result
9239f395c03eSmrg	    verstring=$verstring:$iface.0
9240e4f6584cSmrg	  done
9241e4f6584cSmrg
9242e4f6584cSmrg	  # Make executables depend on our current version.
9243f395c03eSmrg	  func_append verstring ":$current.0"
9244e4f6584cSmrg	  ;;
9245e4f6584cSmrg
9246e4f6584cSmrg	qnx)
9247f395c03eSmrg	  major=.$current
9248f395c03eSmrg	  versuffix=.$current
9249f395c03eSmrg	  ;;
9250f395c03eSmrg
9251f395c03eSmrg	sco)
9252f395c03eSmrg	  major=.$current
9253f395c03eSmrg	  versuffix=.$current
9254e4f6584cSmrg	  ;;
9255e4f6584cSmrg
9256e4f6584cSmrg	sunos)
9257f395c03eSmrg	  major=.$current
9258f395c03eSmrg	  versuffix=.$current.$revision
9259e4f6584cSmrg	  ;;
9260e4f6584cSmrg
9261e4f6584cSmrg	windows)
9262e4f6584cSmrg	  # Use '-' rather than '.', since we only want one
9263f395c03eSmrg	  # extension on DOS 8.3 file systems.
9264e4f6584cSmrg	  func_arith $current - $age
9265e4f6584cSmrg	  major=$func_arith_result
9266f395c03eSmrg	  versuffix=-$major
9267e4f6584cSmrg	  ;;
9268e4f6584cSmrg
9269e4f6584cSmrg	*)
9270f395c03eSmrg	  func_fatal_configuration "unknown library version type '$version_type'"
9271e4f6584cSmrg	  ;;
9272e4f6584cSmrg	esac
9273e4f6584cSmrg
9274e4f6584cSmrg	# Clear the version info if we defaulted, and they specified a release.
9275e4f6584cSmrg	if test -z "$vinfo" && test -n "$release"; then
9276e4f6584cSmrg	  major=
9277e4f6584cSmrg	  case $version_type in
9278e4f6584cSmrg	  darwin)
9279e4f6584cSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
9280e4f6584cSmrg	    # problems, so we reset it completely
9281e4f6584cSmrg	    verstring=
9282e4f6584cSmrg	    ;;
9283e4f6584cSmrg	  *)
9284f395c03eSmrg	    verstring=0.0
9285e4f6584cSmrg	    ;;
9286e4f6584cSmrg	  esac
9287f395c03eSmrg	  if test no = "$need_version"; then
9288e4f6584cSmrg	    versuffix=
9289e4f6584cSmrg	  else
9290f395c03eSmrg	    versuffix=.0.0
9291e4f6584cSmrg	  fi
9292e4f6584cSmrg	fi
9293e4f6584cSmrg
9294e4f6584cSmrg	# Remove version info from name if versioning should be avoided
9295f395c03eSmrg	if test yes,no = "$avoid_version,$need_version"; then
9296e4f6584cSmrg	  major=
9297e4f6584cSmrg	  versuffix=
9298f395c03eSmrg	  verstring=
9299e4f6584cSmrg	fi
9300e4f6584cSmrg
9301e4f6584cSmrg	# Check to see if the archive will have undefined symbols.
9302f395c03eSmrg	if test yes = "$allow_undefined"; then
9303f395c03eSmrg	  if test unsupported = "$allow_undefined_flag"; then
9304f395c03eSmrg	    if test yes = "$build_old_libs"; then
9305f395c03eSmrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9306f395c03eSmrg	      build_libtool_libs=no
9307f395c03eSmrg	    else
9308f395c03eSmrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9309f395c03eSmrg	    fi
9310e4f6584cSmrg	  fi
9311e4f6584cSmrg	else
9312e4f6584cSmrg	  # Don't allow undefined symbols.
9313f395c03eSmrg	  allow_undefined_flag=$no_undefined_flag
9314e4f6584cSmrg	fi
9315e4f6584cSmrg
9316e4f6584cSmrg      fi
9317e4f6584cSmrg
9318f395c03eSmrg      func_generate_dlsyms "$libname" "$libname" :
9319b12e5c03Smrg      func_append libobjs " $symfileobj"
9320f395c03eSmrg      test " " = "$libobjs" && libobjs=
9321e4f6584cSmrg
9322f395c03eSmrg      if test relink != "$opt_mode"; then
9323e4f6584cSmrg	# Remove our outputs, but don't remove object files since they
9324e4f6584cSmrg	# may have been created when compiling PIC objects.
9325e4f6584cSmrg	removelist=
9326e4f6584cSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
9327e4f6584cSmrg	for p in $tempremovelist; do
9328e4f6584cSmrg	  case $p in
9329e4f6584cSmrg	    *.$objext | *.gcno)
9330e4f6584cSmrg	       ;;
9331f395c03eSmrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9332f395c03eSmrg	       if test -n "$precious_files_regex"; then
9333e4f6584cSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
9334e4f6584cSmrg		 then
9335e4f6584cSmrg		   continue
9336e4f6584cSmrg		 fi
9337e4f6584cSmrg	       fi
9338b12e5c03Smrg	       func_append removelist " $p"
9339e4f6584cSmrg	       ;;
9340e4f6584cSmrg	    *) ;;
9341e4f6584cSmrg	  esac
9342e4f6584cSmrg	done
9343e4f6584cSmrg	test -n "$removelist" && \
9344e4f6584cSmrg	  func_show_eval "${RM}r \$removelist"
9345e4f6584cSmrg      fi
9346e4f6584cSmrg
9347e4f6584cSmrg      # Now set the variables for building old libraries.
9348f395c03eSmrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
9349b12e5c03Smrg	func_append oldlibs " $output_objdir/$libname.$libext"
9350e4f6584cSmrg
9351e4f6584cSmrg	# Transform .lo files to .o files.
9352f395c03eSmrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
9353e4f6584cSmrg      fi
9354e4f6584cSmrg
9355e4f6584cSmrg      # Eliminate all temporary directories.
9356e4f6584cSmrg      #for path in $notinst_path; do
9357b12e5c03Smrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9358b12e5c03Smrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9359b12e5c03Smrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
9360e4f6584cSmrg      #done
9361e4f6584cSmrg
9362e4f6584cSmrg      if test -n "$xrpath"; then
9363e4f6584cSmrg	# If the user specified any rpath flags, then add them.
9364e4f6584cSmrg	temp_xrpath=
9365e4f6584cSmrg	for libdir in $xrpath; do
9366b12e5c03Smrg	  func_replace_sysroot "$libdir"
9367b12e5c03Smrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
9368e4f6584cSmrg	  case "$finalize_rpath " in
9369e4f6584cSmrg	  *" $libdir "*) ;;
9370b12e5c03Smrg	  *) func_append finalize_rpath " $libdir" ;;
9371e4f6584cSmrg	  esac
9372e4f6584cSmrg	done
9373f395c03eSmrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
9374e4f6584cSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
9375e4f6584cSmrg	fi
9376e4f6584cSmrg      fi
9377e4f6584cSmrg
9378e4f6584cSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9379f395c03eSmrg      old_dlfiles=$dlfiles
9380e4f6584cSmrg      dlfiles=
9381e4f6584cSmrg      for lib in $old_dlfiles; do
9382e4f6584cSmrg	case " $dlprefiles $dlfiles " in
9383e4f6584cSmrg	*" $lib "*) ;;
9384b12e5c03Smrg	*) func_append dlfiles " $lib" ;;
9385e4f6584cSmrg	esac
9386e4f6584cSmrg      done
9387e4f6584cSmrg
9388e4f6584cSmrg      # Make sure dlprefiles contains only unique files
9389f395c03eSmrg      old_dlprefiles=$dlprefiles
9390e4f6584cSmrg      dlprefiles=
9391e4f6584cSmrg      for lib in $old_dlprefiles; do
9392e4f6584cSmrg	case "$dlprefiles " in
9393e4f6584cSmrg	*" $lib "*) ;;
9394b12e5c03Smrg	*) func_append dlprefiles " $lib" ;;
9395e4f6584cSmrg	esac
9396e4f6584cSmrg      done
9397e4f6584cSmrg
9398f395c03eSmrg      if test yes = "$build_libtool_libs"; then
9399e4f6584cSmrg	if test -n "$rpath"; then
9400e4f6584cSmrg	  case $host in
9401b12e5c03Smrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
9402e4f6584cSmrg	    # these systems don't actually have a c library (as such)!
9403e4f6584cSmrg	    ;;
9404e4f6584cSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
9405e4f6584cSmrg	    # Rhapsody C library is in the System framework
9406b12e5c03Smrg	    func_append deplibs " System.ltframework"
9407e4f6584cSmrg	    ;;
9408e4f6584cSmrg	  *-*-netbsd*)
9409e4f6584cSmrg	    # Don't link with libc until the a.out ld.so is fixed.
9410e4f6584cSmrg	    ;;
9411beef1b22Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*)
9412e4f6584cSmrg	    # Do not include libc due to us having libc/libc_r.
9413e4f6584cSmrg	    ;;
9414e4f6584cSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
9415e4f6584cSmrg	    # Causes problems with __ctype
9416e4f6584cSmrg	    ;;
9417e4f6584cSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
9418e4f6584cSmrg	    # Compiler inserts libc in the correct place for threads to work
9419e4f6584cSmrg	    ;;
9420e4f6584cSmrg	  *)
9421e4f6584cSmrg	    # Add libc to deplibs on all other systems if necessary.
9422f395c03eSmrg	    if test yes = "$build_libtool_need_lc"; then
9423b12e5c03Smrg	      func_append deplibs " -lc"
9424e4f6584cSmrg	    fi
9425e4f6584cSmrg	    ;;
9426e4f6584cSmrg	  esac
9427e4f6584cSmrg	fi
9428e4f6584cSmrg
9429e4f6584cSmrg	# Transform deplibs into only deplibs that can be linked in shared.
9430e4f6584cSmrg	name_save=$name
9431e4f6584cSmrg	libname_save=$libname
9432e4f6584cSmrg	release_save=$release
9433e4f6584cSmrg	versuffix_save=$versuffix
9434e4f6584cSmrg	major_save=$major
9435e4f6584cSmrg	# I'm not sure if I'm treating the release correctly.  I think
9436e4f6584cSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
9437e4f6584cSmrg	# add it in twice.  Is that correct?
9438f395c03eSmrg	release=
9439f395c03eSmrg	versuffix=
9440f395c03eSmrg	major=
9441e4f6584cSmrg	newdeplibs=
9442e4f6584cSmrg	droppeddeps=no
9443e4f6584cSmrg	case $deplibs_check_method in
9444e4f6584cSmrg	pass_all)
9445e4f6584cSmrg	  # Don't check for shared/static.  Everything works.
9446e4f6584cSmrg	  # This might be a little naive.  We might want to check
9447e4f6584cSmrg	  # whether the library exists or not.  But this is on
9448e4f6584cSmrg	  # osf3 & osf4 and I'm not really sure... Just
9449e4f6584cSmrg	  # implementing what was already the behavior.
9450e4f6584cSmrg	  newdeplibs=$deplibs
9451e4f6584cSmrg	  ;;
9452e4f6584cSmrg	test_compile)
9453e4f6584cSmrg	  # This code stresses the "libraries are programs" paradigm to its
9454e4f6584cSmrg	  # limits. Maybe even breaks it.  We compile a program, linking it
9455e4f6584cSmrg	  # against the deplibs as a proxy for the library.  Then we can check
9456e4f6584cSmrg	  # whether they linked in statically or dynamically with ldd.
9457e4f6584cSmrg	  $opt_dry_run || $RM conftest.c
9458e4f6584cSmrg	  cat > conftest.c <<EOF
9459e4f6584cSmrg	  int main() { return 0; }
9460e4f6584cSmrgEOF
9461e4f6584cSmrg	  $opt_dry_run || $RM conftest
9462e4f6584cSmrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
9463e4f6584cSmrg	    ldd_output=`ldd conftest`
9464e4f6584cSmrg	    for i in $deplibs; do
9465e4f6584cSmrg	      case $i in
9466e4f6584cSmrg	      -l*)
9467e4f6584cSmrg		func_stripname -l '' "$i"
9468e4f6584cSmrg		name=$func_stripname_result
9469f395c03eSmrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9470e4f6584cSmrg		  case " $predeps $postdeps " in
9471e4f6584cSmrg		  *" $i "*)
9472b12e5c03Smrg		    func_append newdeplibs " $i"
9473f395c03eSmrg		    i=
9474e4f6584cSmrg		    ;;
9475e4f6584cSmrg		  esac
9476e4f6584cSmrg		fi
9477f395c03eSmrg		if test -n "$i"; then
9478e4f6584cSmrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
9479e4f6584cSmrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9480e4f6584cSmrg		  set dummy $deplib_matches; shift
9481e4f6584cSmrg		  deplib_match=$1
9482f395c03eSmrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9483b12e5c03Smrg		    func_append newdeplibs " $i"
9484e4f6584cSmrg		  else
9485e4f6584cSmrg		    droppeddeps=yes
9486b12e5c03Smrg		    echo
9487e4f6584cSmrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9488b12e5c03Smrg		    echo "*** I have the capability to make that library automatically link in when"
9489b12e5c03Smrg		    echo "*** you link to this library.  But I can only do this if you have a"
9490b12e5c03Smrg		    echo "*** shared version of the library, which I believe you do not have"
9491b12e5c03Smrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9492b12e5c03Smrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
9493e4f6584cSmrg		  fi
9494e4f6584cSmrg		fi
9495e4f6584cSmrg		;;
9496e4f6584cSmrg	      *)
9497b12e5c03Smrg		func_append newdeplibs " $i"
9498e4f6584cSmrg		;;
9499e4f6584cSmrg	      esac
9500e4f6584cSmrg	    done
9501e4f6584cSmrg	  else
9502e4f6584cSmrg	    # Error occurred in the first compile.  Let's try to salvage
9503e4f6584cSmrg	    # the situation: Compile a separate program for each library.
9504e4f6584cSmrg	    for i in $deplibs; do
9505e4f6584cSmrg	      case $i in
9506e4f6584cSmrg	      -l*)
9507e4f6584cSmrg		func_stripname -l '' "$i"
9508e4f6584cSmrg		name=$func_stripname_result
9509e4f6584cSmrg		$opt_dry_run || $RM conftest
9510e4f6584cSmrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
9511e4f6584cSmrg		  ldd_output=`ldd conftest`
9512f395c03eSmrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9513e4f6584cSmrg		    case " $predeps $postdeps " in
9514e4f6584cSmrg		    *" $i "*)
9515b12e5c03Smrg		      func_append newdeplibs " $i"
9516f395c03eSmrg		      i=
9517e4f6584cSmrg		      ;;
9518e4f6584cSmrg		    esac
9519e4f6584cSmrg		  fi
9520f395c03eSmrg		  if test -n "$i"; then
9521e4f6584cSmrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
9522e4f6584cSmrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
9523e4f6584cSmrg		    set dummy $deplib_matches; shift
9524e4f6584cSmrg		    deplib_match=$1
9525f395c03eSmrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
9526b12e5c03Smrg		      func_append newdeplibs " $i"
9527e4f6584cSmrg		    else
9528e4f6584cSmrg		      droppeddeps=yes
9529b12e5c03Smrg		      echo
9530e4f6584cSmrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9531b12e5c03Smrg		      echo "*** I have the capability to make that library automatically link in when"
9532b12e5c03Smrg		      echo "*** you link to this library.  But I can only do this if you have a"
9533b12e5c03Smrg		      echo "*** shared version of the library, which you do not appear to have"
9534b12e5c03Smrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9535b12e5c03Smrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
9536e4f6584cSmrg		    fi
9537e4f6584cSmrg		  fi
9538e4f6584cSmrg		else
9539e4f6584cSmrg		  droppeddeps=yes
9540b12e5c03Smrg		  echo
9541e4f6584cSmrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9542b12e5c03Smrg		  echo "*** make it link in!  You will probably need to install it or some"
9543b12e5c03Smrg		  echo "*** library that it depends on before this library will be fully"
9544b12e5c03Smrg		  echo "*** functional.  Installing it before continuing would be even better."
9545e4f6584cSmrg		fi
9546e4f6584cSmrg		;;
9547e4f6584cSmrg	      *)
9548b12e5c03Smrg		func_append newdeplibs " $i"
9549e4f6584cSmrg		;;
9550e4f6584cSmrg	      esac
9551e4f6584cSmrg	    done
9552e4f6584cSmrg	  fi
9553e4f6584cSmrg	  ;;
9554e4f6584cSmrg	file_magic*)
9555e4f6584cSmrg	  set dummy $deplibs_check_method; shift
9556e4f6584cSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9557e4f6584cSmrg	  for a_deplib in $deplibs; do
9558e4f6584cSmrg	    case $a_deplib in
9559e4f6584cSmrg	    -l*)
9560e4f6584cSmrg	      func_stripname -l '' "$a_deplib"
9561e4f6584cSmrg	      name=$func_stripname_result
9562f395c03eSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9563e4f6584cSmrg		case " $predeps $postdeps " in
9564e4f6584cSmrg		*" $a_deplib "*)
9565b12e5c03Smrg		  func_append newdeplibs " $a_deplib"
9566f395c03eSmrg		  a_deplib=
9567e4f6584cSmrg		  ;;
9568e4f6584cSmrg		esac
9569e4f6584cSmrg	      fi
9570f395c03eSmrg	      if test -n "$a_deplib"; then
9571e4f6584cSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9572b12e5c03Smrg		if test -n "$file_magic_glob"; then
9573b12e5c03Smrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
9574b12e5c03Smrg		else
9575b12e5c03Smrg		  libnameglob=$libname
9576b12e5c03Smrg		fi
9577f395c03eSmrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
9578e4f6584cSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9579f395c03eSmrg		  if test yes = "$want_nocaseglob"; then
9580b12e5c03Smrg		    shopt -s nocaseglob
9581b12e5c03Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9582b12e5c03Smrg		    $nocaseglob
9583b12e5c03Smrg		  else
9584b12e5c03Smrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
9585b12e5c03Smrg		  fi
9586e4f6584cSmrg		  for potent_lib in $potential_libs; do
9587e4f6584cSmrg		      # Follow soft links.
9588e4f6584cSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
9589e4f6584cSmrg			 $GREP " -> " >/dev/null; then
9590e4f6584cSmrg			continue
9591e4f6584cSmrg		      fi
9592e4f6584cSmrg		      # The statement above tries to avoid entering an
9593e4f6584cSmrg		      # endless loop below, in case of cyclic links.
9594e4f6584cSmrg		      # We might still enter an endless loop, since a link
9595e4f6584cSmrg		      # loop can be closed while we follow links,
9596e4f6584cSmrg		      # but so what?
9597f395c03eSmrg		      potlib=$potent_lib
9598e4f6584cSmrg		      while test -h "$potlib" 2>/dev/null; do
9599f395c03eSmrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
9600e4f6584cSmrg			case $potliblink in
9601f395c03eSmrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9602f395c03eSmrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
9603e4f6584cSmrg			esac
9604e4f6584cSmrg		      done
9605e4f6584cSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
9606e4f6584cSmrg			 $SED -e 10q |
9607e4f6584cSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
9608b12e5c03Smrg			func_append newdeplibs " $a_deplib"
9609f395c03eSmrg			a_deplib=
9610e4f6584cSmrg			break 2
9611e4f6584cSmrg		      fi
9612e4f6584cSmrg		  done
9613e4f6584cSmrg		done
9614e4f6584cSmrg	      fi
9615f395c03eSmrg	      if test -n "$a_deplib"; then
9616e4f6584cSmrg		droppeddeps=yes
9617b12e5c03Smrg		echo
9618e4f6584cSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9619b12e5c03Smrg		echo "*** I have the capability to make that library automatically link in when"
9620b12e5c03Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9621b12e5c03Smrg		echo "*** shared version of the library, which you do not appear to have"
9622b12e5c03Smrg		echo "*** because I did check the linker path looking for a file starting"
9623f395c03eSmrg		if test -z "$potlib"; then
9624e4f6584cSmrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
9625e4f6584cSmrg		else
9626e4f6584cSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9627e4f6584cSmrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
9628e4f6584cSmrg		fi
9629e4f6584cSmrg	      fi
9630e4f6584cSmrg	      ;;
9631e4f6584cSmrg	    *)
9632e4f6584cSmrg	      # Add a -L argument.
9633b12e5c03Smrg	      func_append newdeplibs " $a_deplib"
9634e4f6584cSmrg	      ;;
9635e4f6584cSmrg	    esac
9636e4f6584cSmrg	  done # Gone through all deplibs.
9637e4f6584cSmrg	  ;;
9638e4f6584cSmrg	match_pattern*)
9639e4f6584cSmrg	  set dummy $deplibs_check_method; shift
9640e4f6584cSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
9641e4f6584cSmrg	  for a_deplib in $deplibs; do
9642e4f6584cSmrg	    case $a_deplib in
9643e4f6584cSmrg	    -l*)
9644e4f6584cSmrg	      func_stripname -l '' "$a_deplib"
9645e4f6584cSmrg	      name=$func_stripname_result
9646f395c03eSmrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9647e4f6584cSmrg		case " $predeps $postdeps " in
9648e4f6584cSmrg		*" $a_deplib "*)
9649b12e5c03Smrg		  func_append newdeplibs " $a_deplib"
9650f395c03eSmrg		  a_deplib=
9651e4f6584cSmrg		  ;;
9652e4f6584cSmrg		esac
9653e4f6584cSmrg	      fi
9654f395c03eSmrg	      if test -n "$a_deplib"; then
9655e4f6584cSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
9656e4f6584cSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9657e4f6584cSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
9658e4f6584cSmrg		  for potent_lib in $potential_libs; do
9659f395c03eSmrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9660b12e5c03Smrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
9661e4f6584cSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
9662b12e5c03Smrg		      func_append newdeplibs " $a_deplib"
9663f395c03eSmrg		      a_deplib=
9664e4f6584cSmrg		      break 2
9665e4f6584cSmrg		    fi
9666e4f6584cSmrg		  done
9667e4f6584cSmrg		done
9668e4f6584cSmrg	      fi
9669f395c03eSmrg	      if test -n "$a_deplib"; then
9670e4f6584cSmrg		droppeddeps=yes
9671b12e5c03Smrg		echo
9672e4f6584cSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9673b12e5c03Smrg		echo "*** I have the capability to make that library automatically link in when"
9674b12e5c03Smrg		echo "*** you link to this library.  But I can only do this if you have a"
9675b12e5c03Smrg		echo "*** shared version of the library, which you do not appear to have"
9676b12e5c03Smrg		echo "*** because I did check the linker path looking for a file starting"
9677f395c03eSmrg		if test -z "$potlib"; then
9678e4f6584cSmrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
9679e4f6584cSmrg		else
9680e4f6584cSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
9681e4f6584cSmrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
9682e4f6584cSmrg		fi
9683e4f6584cSmrg	      fi
9684e4f6584cSmrg	      ;;
9685e4f6584cSmrg	    *)
9686e4f6584cSmrg	      # Add a -L argument.
9687b12e5c03Smrg	      func_append newdeplibs " $a_deplib"
9688e4f6584cSmrg	      ;;
9689e4f6584cSmrg	    esac
9690e4f6584cSmrg	  done # Gone through all deplibs.
9691e4f6584cSmrg	  ;;
9692e4f6584cSmrg	none | unknown | *)
9693f395c03eSmrg	  newdeplibs=
9694b12e5c03Smrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9695f395c03eSmrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9696f395c03eSmrg	    for i in $predeps $postdeps; do
9697e4f6584cSmrg	      # can't use Xsed below, because $i might contain '/'
9698f395c03eSmrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
9699e4f6584cSmrg	    done
9700e4f6584cSmrg	  fi
9701b12e5c03Smrg	  case $tmp_deplibs in
9702b12e5c03Smrg	  *[!\	\ ]*)
9703b12e5c03Smrg	    echo
9704f395c03eSmrg	    if test none = "$deplibs_check_method"; then
9705b12e5c03Smrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
9706e4f6584cSmrg	    else
9707b12e5c03Smrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
9708e4f6584cSmrg	    fi
9709b12e5c03Smrg	    echo "*** All declared inter-library dependencies are being dropped."
9710e4f6584cSmrg	    droppeddeps=yes
9711b12e5c03Smrg	    ;;
9712b12e5c03Smrg	  esac
9713e4f6584cSmrg	  ;;
9714e4f6584cSmrg	esac
9715e4f6584cSmrg	versuffix=$versuffix_save
9716e4f6584cSmrg	major=$major_save
9717e4f6584cSmrg	release=$release_save
9718e4f6584cSmrg	libname=$libname_save
9719e4f6584cSmrg	name=$name_save
9720e4f6584cSmrg
9721e4f6584cSmrg	case $host in
9722e4f6584cSmrg	*-*-rhapsody* | *-*-darwin1.[012])
9723e4f6584cSmrg	  # On Rhapsody replace the C library with the System framework
9724b12e5c03Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
9725e4f6584cSmrg	  ;;
9726e4f6584cSmrg	esac
9727e4f6584cSmrg
9728f395c03eSmrg	if test yes = "$droppeddeps"; then
9729f395c03eSmrg	  if test yes = "$module"; then
9730b12e5c03Smrg	    echo
9731b12e5c03Smrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
9732e4f6584cSmrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9733b12e5c03Smrg	    echo "*** a static module, that should work as long as the dlopening"
9734b12e5c03Smrg	    echo "*** application is linked with the -dlopen flag."
9735e4f6584cSmrg	    if test -z "$global_symbol_pipe"; then
9736b12e5c03Smrg	      echo
9737b12e5c03Smrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9738f395c03eSmrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9739b12e5c03Smrg	      echo "*** not find such a program.  So, this module is probably useless."
9740f395c03eSmrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
9741e4f6584cSmrg	    fi
9742f395c03eSmrg	    if test no = "$build_old_libs"; then
9743f395c03eSmrg	      oldlibs=$output_objdir/$libname.$libext
9744e4f6584cSmrg	      build_libtool_libs=module
9745e4f6584cSmrg	      build_old_libs=yes
9746e4f6584cSmrg	    else
9747e4f6584cSmrg	      build_libtool_libs=no
9748e4f6584cSmrg	    fi
9749e4f6584cSmrg	  else
9750b12e5c03Smrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9751b12e5c03Smrg	    echo "*** automatically added whenever a program is linked with this library"
9752b12e5c03Smrg	    echo "*** or is declared to -dlopen it."
9753e4f6584cSmrg
9754f395c03eSmrg	    if test no = "$allow_undefined"; then
9755b12e5c03Smrg	      echo
9756b12e5c03Smrg	      echo "*** Since this library must not contain undefined symbols,"
9757b12e5c03Smrg	      echo "*** because either the platform does not support them or"
9758b12e5c03Smrg	      echo "*** it was explicitly requested with -no-undefined,"
9759b12e5c03Smrg	      echo "*** libtool will only create a static version of it."
9760f395c03eSmrg	      if test no = "$build_old_libs"; then
9761f395c03eSmrg		oldlibs=$output_objdir/$libname.$libext
9762e4f6584cSmrg		build_libtool_libs=module
9763e4f6584cSmrg		build_old_libs=yes
9764e4f6584cSmrg	      else
9765e4f6584cSmrg		build_libtool_libs=no
9766e4f6584cSmrg	      fi
9767e4f6584cSmrg	    fi
9768e4f6584cSmrg	  fi
9769e4f6584cSmrg	fi
9770e4f6584cSmrg	# Done checking deplibs!
9771e4f6584cSmrg	deplibs=$newdeplibs
9772e4f6584cSmrg      fi
9773e4f6584cSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
9774e4f6584cSmrg      case $host in
9775e4f6584cSmrg	*-*-darwin*)
9776b12e5c03Smrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9777b12e5c03Smrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9778b12e5c03Smrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9779e4f6584cSmrg	  ;;
9780e4f6584cSmrg      esac
9781e4f6584cSmrg
9782e4f6584cSmrg      # move library search paths that coincide with paths to not yet
9783e4f6584cSmrg      # installed libraries to the beginning of the library search list
9784e4f6584cSmrg      new_libs=
9785e4f6584cSmrg      for path in $notinst_path; do
9786e4f6584cSmrg	case " $new_libs " in
9787e4f6584cSmrg	*" -L$path/$objdir "*) ;;
9788e4f6584cSmrg	*)
9789e4f6584cSmrg	  case " $deplibs " in
9790e4f6584cSmrg	  *" -L$path/$objdir "*)
9791b12e5c03Smrg	    func_append new_libs " -L$path/$objdir" ;;
9792e4f6584cSmrg	  esac
9793e4f6584cSmrg	  ;;
9794e4f6584cSmrg	esac
9795e4f6584cSmrg      done
9796e4f6584cSmrg      for deplib in $deplibs; do
9797e4f6584cSmrg	case $deplib in
9798e4f6584cSmrg	-L*)
9799e4f6584cSmrg	  case " $new_libs " in
9800e4f6584cSmrg	  *" $deplib "*) ;;
9801b12e5c03Smrg	  *) func_append new_libs " $deplib" ;;
9802e4f6584cSmrg	  esac
9803e4f6584cSmrg	  ;;
9804b12e5c03Smrg	*) func_append new_libs " $deplib" ;;
9805e4f6584cSmrg	esac
9806e4f6584cSmrg      done
9807f395c03eSmrg      deplibs=$new_libs
9808e4f6584cSmrg
9809e4f6584cSmrg      # All the library-specific variables (install_libdir is set above).
9810e4f6584cSmrg      library_names=
9811e4f6584cSmrg      old_library=
9812e4f6584cSmrg      dlname=
9813e4f6584cSmrg
9814e4f6584cSmrg      # Test again, we may have decided not to build it any more
9815f395c03eSmrg      if test yes = "$build_libtool_libs"; then
9816f395c03eSmrg	# Remove $wl instances when linking with ld.
9817b12e5c03Smrg	# FIXME: should test the right _cmds variable.
9818b12e5c03Smrg	case $archive_cmds in
9819b12e5c03Smrg	  *\$LD\ *) wl= ;;
9820b12e5c03Smrg        esac
9821f395c03eSmrg	if test yes = "$hardcode_into_libs"; then
9822e4f6584cSmrg	  # Hardcode the library paths
9823e4f6584cSmrg	  hardcode_libdirs=
9824e4f6584cSmrg	  dep_rpath=
9825f395c03eSmrg	  rpath=$finalize_rpath
9826f395c03eSmrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
9827e4f6584cSmrg	  for libdir in $rpath; do
9828e4f6584cSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
9829e4f6584cSmrg	      if test -n "$hardcode_libdir_separator"; then
9830b12e5c03Smrg		func_replace_sysroot "$libdir"
9831b12e5c03Smrg		libdir=$func_replace_sysroot_result
9832e4f6584cSmrg		if test -z "$hardcode_libdirs"; then
9833f395c03eSmrg		  hardcode_libdirs=$libdir
9834e4f6584cSmrg		else
9835e4f6584cSmrg		  # Just accumulate the unique libdirs.
9836e4f6584cSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
9837e4f6584cSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
9838e4f6584cSmrg		    ;;
9839e4f6584cSmrg		  *)
9840b12e5c03Smrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
9841e4f6584cSmrg		    ;;
9842e4f6584cSmrg		  esac
9843e4f6584cSmrg		fi
9844e4f6584cSmrg	      else
9845e4f6584cSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
9846b12e5c03Smrg		func_append dep_rpath " $flag"
9847e4f6584cSmrg	      fi
9848e4f6584cSmrg	    elif test -n "$runpath_var"; then
9849e4f6584cSmrg	      case "$perm_rpath " in
9850e4f6584cSmrg	      *" $libdir "*) ;;
9851b12e5c03Smrg	      *) func_append perm_rpath " $libdir" ;;
9852e4f6584cSmrg	      esac
9853e4f6584cSmrg	    fi
9854e4f6584cSmrg	  done
9855e4f6584cSmrg	  # Substitute the hardcoded libdirs into the rpath.
9856e4f6584cSmrg	  if test -n "$hardcode_libdir_separator" &&
9857e4f6584cSmrg	     test -n "$hardcode_libdirs"; then
9858f395c03eSmrg	    libdir=$hardcode_libdirs
9859b12e5c03Smrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
9860e4f6584cSmrg	  fi
9861e4f6584cSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
9862e4f6584cSmrg	    # We should set the runpath_var.
9863e4f6584cSmrg	    rpath=
9864e4f6584cSmrg	    for dir in $perm_rpath; do
9865b12e5c03Smrg	      func_append rpath "$dir:"
9866e4f6584cSmrg	    done
9867e4f6584cSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
9868e4f6584cSmrg	  fi
9869e4f6584cSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
9870e4f6584cSmrg	fi
987109885543Smrg
9872f395c03eSmrg	shlibpath=$finalize_shlibpath
9873f395c03eSmrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
9874e4f6584cSmrg	if test -n "$shlibpath"; then
9875e4f6584cSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
9876e4f6584cSmrg	fi
987709885543Smrg
9878e4f6584cSmrg	# Get the real and link names of the library.
9879e4f6584cSmrg	eval shared_ext=\"$shrext_cmds\"
9880e4f6584cSmrg	eval library_names=\"$library_names_spec\"
9881e4f6584cSmrg	set dummy $library_names
9882e4f6584cSmrg	shift
9883f395c03eSmrg	realname=$1
9884e4f6584cSmrg	shift
988509885543Smrg
9886e4f6584cSmrg	if test -n "$soname_spec"; then
9887e4f6584cSmrg	  eval soname=\"$soname_spec\"
9888e4f6584cSmrg	else
9889f395c03eSmrg	  soname=$realname
9890e4f6584cSmrg	fi
9891e4f6584cSmrg	if test -z "$dlname"; then
9892e4f6584cSmrg	  dlname=$soname
9893e4f6584cSmrg	fi
989409885543Smrg
9895f395c03eSmrg	lib=$output_objdir/$realname
9896e4f6584cSmrg	linknames=
9897e4f6584cSmrg	for link
9898e4f6584cSmrg	do
9899b12e5c03Smrg	  func_append linknames " $link"
9900e4f6584cSmrg	done
990109885543Smrg
9902e4f6584cSmrg	# Use standard objects if they are pic
9903b12e5c03Smrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
9904e4f6584cSmrg	test "X$libobjs" = "X " && libobjs=
99057104f784Smrg
9906e4f6584cSmrg	delfiles=
9907e4f6584cSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9908e4f6584cSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9909f395c03eSmrg	  export_symbols=$output_objdir/$libname.uexp
9910b12e5c03Smrg	  func_append delfiles " $export_symbols"
9911e4f6584cSmrg	fi
991209885543Smrg
9913e4f6584cSmrg	orig_export_symbols=
9914e4f6584cSmrg	case $host_os in
9915e4f6584cSmrg	cygwin* | mingw* | cegcc*)
9916e4f6584cSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
9917e4f6584cSmrg	    # exporting using user supplied symfile
9918f395c03eSmrg	    func_dll_def_p "$export_symbols" || {
9919e4f6584cSmrg	      # and it's NOT already a .def file. Must figure out
9920e4f6584cSmrg	      # which of the given symbols are data symbols and tag
9921e4f6584cSmrg	      # them as such. So, trigger use of export_symbols_cmds.
9922e4f6584cSmrg	      # export_symbols gets reassigned inside the "prepare
9923e4f6584cSmrg	      # the list of exported symbols" if statement, so the
9924e4f6584cSmrg	      # include_expsyms logic still works.
9925f395c03eSmrg	      orig_export_symbols=$export_symbols
9926e4f6584cSmrg	      export_symbols=
9927e4f6584cSmrg	      always_export_symbols=yes
9928f395c03eSmrg	    }
9929e4f6584cSmrg	  fi
9930e4f6584cSmrg	  ;;
9931e4f6584cSmrg	esac
993209885543Smrg
9933e4f6584cSmrg	# Prepare the list of exported symbols
9934e4f6584cSmrg	if test -z "$export_symbols"; then
9935f395c03eSmrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9936f395c03eSmrg	    func_verbose "generating symbol list for '$libname.la'"
9937f395c03eSmrg	    export_symbols=$output_objdir/$libname.exp
9938e4f6584cSmrg	    $opt_dry_run || $RM $export_symbols
9939e4f6584cSmrg	    cmds=$export_symbols_cmds
9940f395c03eSmrg	    save_ifs=$IFS; IFS='~'
9941b12e5c03Smrg	    for cmd1 in $cmds; do
9942f395c03eSmrg	      IFS=$save_ifs
9943b12e5c03Smrg	      # Take the normal branch if the nm_file_list_spec branch
9944b12e5c03Smrg	      # doesn't work or if tool conversion is not needed.
9945b12e5c03Smrg	      case $nm_file_list_spec~$to_tool_file_cmd in
9946b12e5c03Smrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
9947b12e5c03Smrg		  try_normal_branch=yes
9948b12e5c03Smrg		  eval cmd=\"$cmd1\"
9949b12e5c03Smrg		  func_len " $cmd"
9950b12e5c03Smrg		  len=$func_len_result
9951b12e5c03Smrg		  ;;
9952b12e5c03Smrg		*)
9953b12e5c03Smrg		  try_normal_branch=no
9954b12e5c03Smrg		  ;;
9955b12e5c03Smrg	      esac
9956f395c03eSmrg	      if test yes = "$try_normal_branch" \
9957b12e5c03Smrg		 && { test "$len" -lt "$max_cmd_len" \
9958b12e5c03Smrg		      || test "$max_cmd_len" -le -1; }
9959b12e5c03Smrg	      then
9960b12e5c03Smrg		func_show_eval "$cmd" 'exit $?'
9961b12e5c03Smrg		skipped_export=false
9962b12e5c03Smrg	      elif test -n "$nm_file_list_spec"; then
9963b12e5c03Smrg		func_basename "$output"
9964b12e5c03Smrg		output_la=$func_basename_result
9965b12e5c03Smrg		save_libobjs=$libobjs
9966b12e5c03Smrg		save_output=$output
9967f395c03eSmrg		output=$output_objdir/$output_la.nm
9968b12e5c03Smrg		func_to_tool_file "$output"
9969b12e5c03Smrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
9970b12e5c03Smrg		func_append delfiles " $output"
9971b12e5c03Smrg		func_verbose "creating $NM input file list: $output"
9972b12e5c03Smrg		for obj in $save_libobjs; do
9973b12e5c03Smrg		  func_to_tool_file "$obj"
9974b12e5c03Smrg		  $ECHO "$func_to_tool_file_result"
9975b12e5c03Smrg		done > "$output"
9976b12e5c03Smrg		eval cmd=\"$cmd1\"
9977e4f6584cSmrg		func_show_eval "$cmd" 'exit $?'
9978b12e5c03Smrg		output=$save_output
9979b12e5c03Smrg		libobjs=$save_libobjs
9980e4f6584cSmrg		skipped_export=false
9981e4f6584cSmrg	      else
9982e4f6584cSmrg		# The command line is too long to execute in one step.
9983e4f6584cSmrg		func_verbose "using reloadable object file for export list..."
9984e4f6584cSmrg		skipped_export=:
9985e4f6584cSmrg		# Break out early, otherwise skipped_export may be
9986e4f6584cSmrg		# set to false by a later but shorter cmd.
9987e4f6584cSmrg		break
9988e4f6584cSmrg	      fi
9989e4f6584cSmrg	    done
9990f395c03eSmrg	    IFS=$save_ifs
9991f395c03eSmrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
9992e4f6584cSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
9993e4f6584cSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9994e4f6584cSmrg	    fi
9995e4f6584cSmrg	  fi
99962ec8c4b4Smrg	fi
999709885543Smrg
9998e4f6584cSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9999f395c03eSmrg	  tmp_export_symbols=$export_symbols
10000f395c03eSmrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10001b12e5c03Smrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10002e4f6584cSmrg	fi
1000309885543Smrg
10004f395c03eSmrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
10005e4f6584cSmrg	  # The given exports_symbols file has to be filtered, so filter it.
10006f395c03eSmrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10007e4f6584cSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
10008f395c03eSmrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
10009e4f6584cSmrg	  # though. Also, the filter scales superlinearly with the number of
10010e4f6584cSmrg	  # global variables. join(1) would be nice here, but unfortunately
10011e4f6584cSmrg	  # isn't a blessed tool.
10012e4f6584cSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10013b12e5c03Smrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10014e4f6584cSmrg	  export_symbols=$output_objdir/$libname.def
10015e4f6584cSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10016e4f6584cSmrg	fi
1001709885543Smrg
10018e4f6584cSmrg	tmp_deplibs=
10019e4f6584cSmrg	for test_deplib in $deplibs; do
10020e4f6584cSmrg	  case " $convenience " in
10021e4f6584cSmrg	  *" $test_deplib "*) ;;
10022e4f6584cSmrg	  *)
10023b12e5c03Smrg	    func_append tmp_deplibs " $test_deplib"
10024e4f6584cSmrg	    ;;
10025e4f6584cSmrg	  esac
10026e4f6584cSmrg	done
10027f395c03eSmrg	deplibs=$tmp_deplibs
1002809885543Smrg
10029e4f6584cSmrg	if test -n "$convenience"; then
10030e4f6584cSmrg	  if test -n "$whole_archive_flag_spec" &&
10031f395c03eSmrg	    test yes = "$compiler_needs_object" &&
10032e4f6584cSmrg	    test -z "$libobjs"; then
10033e4f6584cSmrg	    # extract the archives, so we have objects to list.
10034e4f6584cSmrg	    # TODO: could optimize this to just extract one archive.
10035e4f6584cSmrg	    whole_archive_flag_spec=
10036e4f6584cSmrg	  fi
10037e4f6584cSmrg	  if test -n "$whole_archive_flag_spec"; then
10038e4f6584cSmrg	    save_libobjs=$libobjs
10039e4f6584cSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10040e4f6584cSmrg	    test "X$libobjs" = "X " && libobjs=
10041e4f6584cSmrg	  else
10042f395c03eSmrg	    gentop=$output_objdir/${outputname}x
10043b12e5c03Smrg	    func_append generated " $gentop"
100442ec8c4b4Smrg
10045e4f6584cSmrg	    func_extract_archives $gentop $convenience
10046b12e5c03Smrg	    func_append libobjs " $func_extract_archives_result"
10047e4f6584cSmrg	    test "X$libobjs" = "X " && libobjs=
10048e4f6584cSmrg	  fi
10049b698ba48Smrg	fi
100502ec8c4b4Smrg
10051f395c03eSmrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
10052e4f6584cSmrg	  eval flag=\"$thread_safe_flag_spec\"
10053b12e5c03Smrg	  func_append linker_flags " $flag"
10054b698ba48Smrg	fi
100552ec8c4b4Smrg
10056e4f6584cSmrg	# Make a backup of the uninstalled library when relinking
10057f395c03eSmrg	if test relink = "$opt_mode"; then
10058e4f6584cSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
10059e4f6584cSmrg	fi
1006009885543Smrg
10061e4f6584cSmrg	# Do each of the archive commands.
10062f395c03eSmrg	if test yes = "$module" && test -n "$module_cmds"; then
10063e4f6584cSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10064e4f6584cSmrg	    eval test_cmds=\"$module_expsym_cmds\"
10065e4f6584cSmrg	    cmds=$module_expsym_cmds
10066e4f6584cSmrg	  else
10067e4f6584cSmrg	    eval test_cmds=\"$module_cmds\"
10068e4f6584cSmrg	    cmds=$module_cmds
10069e4f6584cSmrg	  fi
10070b698ba48Smrg	else
10071e4f6584cSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10072e4f6584cSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
10073e4f6584cSmrg	    cmds=$archive_expsym_cmds
10074e4f6584cSmrg	  else
10075e4f6584cSmrg	    eval test_cmds=\"$archive_cmds\"
10076e4f6584cSmrg	    cmds=$archive_cmds
10077e4f6584cSmrg	  fi
10078b698ba48Smrg	fi
1007909885543Smrg
10080f395c03eSmrg	if test : != "$skipped_export" &&
10081e4f6584cSmrg	   func_len " $test_cmds" &&
10082e4f6584cSmrg	   len=$func_len_result &&
10083e4f6584cSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10084e4f6584cSmrg	  :
10085e4f6584cSmrg	else
10086e4f6584cSmrg	  # The command line is too long to link in one step, link piecewise
10087e4f6584cSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
10088e4f6584cSmrg	  # script.
1008909885543Smrg
10090e4f6584cSmrg	  # Save the value of $output and $libobjs because we want to
10091e4f6584cSmrg	  # use them later.  If we have whole_archive_flag_spec, we
10092e4f6584cSmrg	  # want to use save_libobjs as it was before
10093e4f6584cSmrg	  # whole_archive_flag_spec was expanded, because we can't
10094e4f6584cSmrg	  # assume the linker understands whole_archive_flag_spec.
10095e4f6584cSmrg	  # This may have to be revisited, in case too many
10096e4f6584cSmrg	  # convenience libraries get linked in and end up exceeding
10097e4f6584cSmrg	  # the spec.
10098e4f6584cSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
10099e4f6584cSmrg	    save_libobjs=$libobjs
10100e4f6584cSmrg	  fi
10101e4f6584cSmrg	  save_output=$output
10102b12e5c03Smrg	  func_basename "$output"
10103b12e5c03Smrg	  output_la=$func_basename_result
1010409885543Smrg
10105e4f6584cSmrg	  # Clear the reloadable object creation command queue and
10106e4f6584cSmrg	  # initialize k to one.
10107e4f6584cSmrg	  test_cmds=
10108e4f6584cSmrg	  concat_cmds=
10109e4f6584cSmrg	  objlist=
10110e4f6584cSmrg	  last_robj=
10111e4f6584cSmrg	  k=1
10112e4f6584cSmrg
10113f395c03eSmrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
10114f395c03eSmrg	    output=$output_objdir/$output_la.lnkscript
10115e4f6584cSmrg	    func_verbose "creating GNU ld script: $output"
10116b12e5c03Smrg	    echo 'INPUT (' > $output
10117e4f6584cSmrg	    for obj in $save_libobjs
10118b698ba48Smrg	    do
10119b12e5c03Smrg	      func_to_tool_file "$obj"
10120b12e5c03Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10121e4f6584cSmrg	    done
10122b12e5c03Smrg	    echo ')' >> $output
10123b12e5c03Smrg	    func_append delfiles " $output"
10124b12e5c03Smrg	    func_to_tool_file "$output"
10125b12e5c03Smrg	    output=$func_to_tool_file_result
10126f395c03eSmrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
10127f395c03eSmrg	    output=$output_objdir/$output_la.lnk
10128e4f6584cSmrg	    func_verbose "creating linker input file list: $output"
10129e4f6584cSmrg	    : > $output
10130e4f6584cSmrg	    set x $save_libobjs
10131e4f6584cSmrg	    shift
10132e4f6584cSmrg	    firstobj=
10133f395c03eSmrg	    if test yes = "$compiler_needs_object"; then
10134e4f6584cSmrg	      firstobj="$1 "
10135e4f6584cSmrg	      shift
10136e4f6584cSmrg	    fi
10137e4f6584cSmrg	    for obj
10138e4f6584cSmrg	    do
10139b12e5c03Smrg	      func_to_tool_file "$obj"
10140b12e5c03Smrg	      $ECHO "$func_to_tool_file_result" >> $output
10141e4f6584cSmrg	    done
10142b12e5c03Smrg	    func_append delfiles " $output"
10143b12e5c03Smrg	    func_to_tool_file "$output"
10144b12e5c03Smrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
10145e4f6584cSmrg	  else
10146e4f6584cSmrg	    if test -n "$save_libobjs"; then
10147e4f6584cSmrg	      func_verbose "creating reloadable object files..."
10148f395c03eSmrg	      output=$output_objdir/$output_la-$k.$objext
10149e4f6584cSmrg	      eval test_cmds=\"$reload_cmds\"
10150e4f6584cSmrg	      func_len " $test_cmds"
10151e4f6584cSmrg	      len0=$func_len_result
10152e4f6584cSmrg	      len=$len0
10153e4f6584cSmrg
10154e4f6584cSmrg	      # Loop over the list of objects to be linked.
10155e4f6584cSmrg	      for obj in $save_libobjs
10156e4f6584cSmrg	      do
10157e4f6584cSmrg		func_len " $obj"
10158e4f6584cSmrg		func_arith $len + $func_len_result
10159e4f6584cSmrg		len=$func_arith_result
10160f395c03eSmrg		if test -z "$objlist" ||
10161e4f6584cSmrg		   test "$len" -lt "$max_cmd_len"; then
10162e4f6584cSmrg		  func_append objlist " $obj"
10163e4f6584cSmrg		else
10164e4f6584cSmrg		  # The command $test_cmds is almost too long, add a
10165e4f6584cSmrg		  # command to the queue.
10166f395c03eSmrg		  if test 1 -eq "$k"; then
10167e4f6584cSmrg		    # The first file doesn't have a previous command to add.
10168b12e5c03Smrg		    reload_objs=$objlist
10169b12e5c03Smrg		    eval concat_cmds=\"$reload_cmds\"
10170e4f6584cSmrg		  else
10171e4f6584cSmrg		    # All subsequent reloadable object files will link in
10172e4f6584cSmrg		    # the last one created.
10173b12e5c03Smrg		    reload_objs="$objlist $last_robj"
10174b12e5c03Smrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
10175e4f6584cSmrg		  fi
10176f395c03eSmrg		  last_robj=$output_objdir/$output_la-$k.$objext
10177e4f6584cSmrg		  func_arith $k + 1
10178e4f6584cSmrg		  k=$func_arith_result
10179f395c03eSmrg		  output=$output_objdir/$output_la-$k.$objext
10180b12e5c03Smrg		  objlist=" $obj"
10181e4f6584cSmrg		  func_len " $last_robj"
10182e4f6584cSmrg		  func_arith $len0 + $func_len_result
10183e4f6584cSmrg		  len=$func_arith_result
10184e4f6584cSmrg		fi
10185e4f6584cSmrg	      done
10186e4f6584cSmrg	      # Handle the remaining objects by creating one last
10187e4f6584cSmrg	      # reloadable object file.  All subsequent reloadable object
10188e4f6584cSmrg	      # files will link in the last one created.
10189e4f6584cSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10190b12e5c03Smrg	      reload_objs="$objlist $last_robj"
10191f395c03eSmrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
10192e4f6584cSmrg	      if test -n "$last_robj"; then
10193f395c03eSmrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10194e4f6584cSmrg	      fi
10195b12e5c03Smrg	      func_append delfiles " $output"
1019609885543Smrg
10197e4f6584cSmrg	    else
10198e4f6584cSmrg	      output=
10199e4f6584cSmrg	    fi
1020009885543Smrg
10201f395c03eSmrg	    ${skipped_export-false} && {
10202f395c03eSmrg	      func_verbose "generating symbol list for '$libname.la'"
10203f395c03eSmrg	      export_symbols=$output_objdir/$libname.exp
10204e4f6584cSmrg	      $opt_dry_run || $RM $export_symbols
10205e4f6584cSmrg	      libobjs=$output
10206e4f6584cSmrg	      # Append the command to create the export file.
10207e4f6584cSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10208e4f6584cSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
10209e4f6584cSmrg	      if test -n "$last_robj"; then
10210e4f6584cSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
10211e4f6584cSmrg	      fi
10212f395c03eSmrg	    }
1021309885543Smrg
10214e4f6584cSmrg	    test -n "$save_libobjs" &&
10215e4f6584cSmrg	      func_verbose "creating a temporary reloadable object file: $output"
1021609885543Smrg
10217e4f6584cSmrg	    # Loop through the commands generated above and execute them.
10218f395c03eSmrg	    save_ifs=$IFS; IFS='~'
10219e4f6584cSmrg	    for cmd in $concat_cmds; do
10220f395c03eSmrg	      IFS=$save_ifs
10221f395c03eSmrg	      $opt_quiet || {
10222beef1b22Smrg		  func_quote_arg expand,pretty "$cmd"
10223beef1b22Smrg		  eval "func_echo $func_quote_arg_result"
10224e4f6584cSmrg	      }
10225e4f6584cSmrg	      $opt_dry_run || eval "$cmd" || {
10226e4f6584cSmrg		lt_exit=$?
10227e4f6584cSmrg
10228e4f6584cSmrg		# Restore the uninstalled library and exit
10229f395c03eSmrg		if test relink = "$opt_mode"; then
10230e4f6584cSmrg		  ( cd "$output_objdir" && \
10231e4f6584cSmrg		    $RM "${realname}T" && \
10232e4f6584cSmrg		    $MV "${realname}U" "$realname" )
10233e4f6584cSmrg		fi
1023409885543Smrg
10235e4f6584cSmrg		exit $lt_exit
10236e4f6584cSmrg	      }
10237e4f6584cSmrg	    done
10238f395c03eSmrg	    IFS=$save_ifs
10239b698ba48Smrg
10240e4f6584cSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
10241e4f6584cSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
10242e4f6584cSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
1024309885543Smrg	    fi
1024409885543Smrg	  fi
1024509885543Smrg
10246f395c03eSmrg          ${skipped_export-false} && {
10247e4f6584cSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10248f395c03eSmrg	      tmp_export_symbols=$export_symbols
10249f395c03eSmrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
10250b12e5c03Smrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
10251e4f6584cSmrg	    fi
102522ec8c4b4Smrg
10253e4f6584cSmrg	    if test -n "$orig_export_symbols"; then
10254e4f6584cSmrg	      # The given exports_symbols file has to be filtered, so filter it.
10255f395c03eSmrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
10256e4f6584cSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10257f395c03eSmrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
10258e4f6584cSmrg	      # though. Also, the filter scales superlinearly with the number of
10259e4f6584cSmrg	      # global variables. join(1) would be nice here, but unfortunately
10260e4f6584cSmrg	      # isn't a blessed tool.
10261e4f6584cSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
10262b12e5c03Smrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
10263e4f6584cSmrg	      export_symbols=$output_objdir/$libname.def
10264e4f6584cSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
10265e4f6584cSmrg	    fi
10266f395c03eSmrg	  }
1026709885543Smrg
10268e4f6584cSmrg	  libobjs=$output
10269e4f6584cSmrg	  # Restore the value of output.
10270e4f6584cSmrg	  output=$save_output
1027109885543Smrg
10272e4f6584cSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
10273e4f6584cSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
10274e4f6584cSmrg	    test "X$libobjs" = "X " && libobjs=
10275e4f6584cSmrg	  fi
10276e4f6584cSmrg	  # Expand the library linking commands again to reset the
10277e4f6584cSmrg	  # value of $libobjs for piecewise linking.
1027809885543Smrg
10279e4f6584cSmrg	  # Do each of the archive commands.
10280f395c03eSmrg	  if test yes = "$module" && test -n "$module_cmds"; then
10281e4f6584cSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
10282e4f6584cSmrg	      cmds=$module_expsym_cmds
10283e4f6584cSmrg	    else
10284e4f6584cSmrg	      cmds=$module_cmds
10285b698ba48Smrg	    fi
10286b698ba48Smrg	  else
10287e4f6584cSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
10288e4f6584cSmrg	      cmds=$archive_expsym_cmds
10289e4f6584cSmrg	    else
10290e4f6584cSmrg	      cmds=$archive_cmds
10291e4f6584cSmrg	    fi
10292b698ba48Smrg	  fi
10293e4f6584cSmrg	fi
1029409885543Smrg
10295e4f6584cSmrg	if test -n "$delfiles"; then
10296e4f6584cSmrg	  # Append the command to remove temporary files to $cmds.
10297e4f6584cSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
10298e4f6584cSmrg	fi
1029909885543Smrg
10300e4f6584cSmrg	# Add any objects from preloaded convenience libraries
10301e4f6584cSmrg	if test -n "$dlprefiles"; then
10302f395c03eSmrg	  gentop=$output_objdir/${outputname}x
10303b12e5c03Smrg	  func_append generated " $gentop"
1030409885543Smrg
10305e4f6584cSmrg	  func_extract_archives $gentop $dlprefiles
10306b12e5c03Smrg	  func_append libobjs " $func_extract_archives_result"
10307e4f6584cSmrg	  test "X$libobjs" = "X " && libobjs=
10308e4f6584cSmrg	fi
1030909885543Smrg
10310f395c03eSmrg	save_ifs=$IFS; IFS='~'
10311e4f6584cSmrg	for cmd in $cmds; do
10312f395c03eSmrg	  IFS=$sp$nl
10313e4f6584cSmrg	  eval cmd=\"$cmd\"
10314f395c03eSmrg	  IFS=$save_ifs
10315f395c03eSmrg	  $opt_quiet || {
10316beef1b22Smrg	    func_quote_arg expand,pretty "$cmd"
10317beef1b22Smrg	    eval "func_echo $func_quote_arg_result"
10318e4f6584cSmrg	  }
10319e4f6584cSmrg	  $opt_dry_run || eval "$cmd" || {
10320e4f6584cSmrg	    lt_exit=$?
103212ec8c4b4Smrg
10322e4f6584cSmrg	    # Restore the uninstalled library and exit
10323f395c03eSmrg	    if test relink = "$opt_mode"; then
10324e4f6584cSmrg	      ( cd "$output_objdir" && \
10325e4f6584cSmrg	        $RM "${realname}T" && \
10326e4f6584cSmrg		$MV "${realname}U" "$realname" )
10327e4f6584cSmrg	    fi
103282ec8c4b4Smrg
10329e4f6584cSmrg	    exit $lt_exit
10330e4f6584cSmrg	  }
10331e4f6584cSmrg	done
10332f395c03eSmrg	IFS=$save_ifs
103332ec8c4b4Smrg
10334e4f6584cSmrg	# Restore the uninstalled library and exit
10335f395c03eSmrg	if test relink = "$opt_mode"; then
10336e4f6584cSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
103372ec8c4b4Smrg
10338e4f6584cSmrg	  if test -n "$convenience"; then
10339e4f6584cSmrg	    if test -z "$whole_archive_flag_spec"; then
10340e4f6584cSmrg	      func_show_eval '${RM}r "$gentop"'
10341e4f6584cSmrg	    fi
10342e4f6584cSmrg	  fi
103432ec8c4b4Smrg
10344e4f6584cSmrg	  exit $EXIT_SUCCESS
10345e4f6584cSmrg	fi
10346e4f6584cSmrg
10347e4f6584cSmrg	# Create links to the real library.
10348e4f6584cSmrg	for linkname in $linknames; do
10349e4f6584cSmrg	  if test "$realname" != "$linkname"; then
10350e4f6584cSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10351b698ba48Smrg	  fi
10352b698ba48Smrg	done
103532ec8c4b4Smrg
10354e4f6584cSmrg	# If -module or -export-dynamic was specified, set the dlname.
10355f395c03eSmrg	if test yes = "$module" || test yes = "$export_dynamic"; then
10356e4f6584cSmrg	  # On all known operating systems, these are identical.
10357f395c03eSmrg	  dlname=$soname
10358e4f6584cSmrg	fi
10359e4f6584cSmrg      fi
1036009885543Smrg      ;;
1036109885543Smrg
10362e4f6584cSmrg    obj)
10363f395c03eSmrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10364f395c03eSmrg	func_warning "'-dlopen' is ignored for objects"
10365e4f6584cSmrg      fi
10366b698ba48Smrg
10367e4f6584cSmrg      case " $deplibs" in
10368e4f6584cSmrg      *\ -l* | *\ -L*)
10369f395c03eSmrg	func_warning "'-l' and '-L' are ignored for objects" ;;
103702ec8c4b4Smrg      esac
1037109885543Smrg
10372e4f6584cSmrg      test -n "$rpath" && \
10373f395c03eSmrg	func_warning "'-rpath' is ignored for objects"
10374e4f6584cSmrg
10375e4f6584cSmrg      test -n "$xrpath" && \
10376f395c03eSmrg	func_warning "'-R' is ignored for objects"
1037709885543Smrg
10378e4f6584cSmrg      test -n "$vinfo" && \
10379f395c03eSmrg	func_warning "'-version-info' is ignored for objects"
103802ec8c4b4Smrg
10381e4f6584cSmrg      test -n "$release" && \
10382f395c03eSmrg	func_warning "'-release' is ignored for objects"
10383e4f6584cSmrg
10384e4f6584cSmrg      case $output in
10385e4f6584cSmrg      *.lo)
10386e4f6584cSmrg	test -n "$objs$old_deplibs" && \
10387f395c03eSmrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
10388e4f6584cSmrg
10389e4f6584cSmrg	libobj=$output
10390e4f6584cSmrg	func_lo2o "$libobj"
10391e4f6584cSmrg	obj=$func_lo2o_result
10392b698ba48Smrg	;;
10393b698ba48Smrg      *)
10394e4f6584cSmrg	libobj=
10395f395c03eSmrg	obj=$output
1039609885543Smrg	;;
103972ec8c4b4Smrg      esac
1039809885543Smrg
10399e4f6584cSmrg      # Delete the old objects.
10400e4f6584cSmrg      $opt_dry_run || $RM $obj $libobj
1040109885543Smrg
10402e4f6584cSmrg      # Objects from convenience libraries.  This assumes
10403e4f6584cSmrg      # single-version convenience libraries.  Whenever we create
10404e4f6584cSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
10405e4f6584cSmrg      # the extraction.
10406e4f6584cSmrg      reload_conv_objs=
10407e4f6584cSmrg      gentop=
10408f395c03eSmrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10409f395c03eSmrg      # whole_archive_flag_spec and hope we can get by with turning comma
10410f395c03eSmrg      # into space.
10411f395c03eSmrg      case $reload_cmds in
10412f395c03eSmrg        *\$LD[\ \$]*) wl= ;;
10413f395c03eSmrg      esac
10414e4f6584cSmrg      if test -n "$convenience"; then
10415e4f6584cSmrg	if test -n "$whole_archive_flag_spec"; then
10416e4f6584cSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10417f395c03eSmrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10418f395c03eSmrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
10419e4f6584cSmrg	else
10420f395c03eSmrg	  gentop=$output_objdir/${obj}x
10421b12e5c03Smrg	  func_append generated " $gentop"
10422b698ba48Smrg
10423e4f6584cSmrg	  func_extract_archives $gentop $convenience
10424e4f6584cSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
10425e4f6584cSmrg	fi
10426b698ba48Smrg      fi
10427b698ba48Smrg
10428b12e5c03Smrg      # If we're not building shared, we need to use non_pic_objs
10429f395c03eSmrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
10430b12e5c03Smrg
10431e4f6584cSmrg      # Create the old-style object.
10432f395c03eSmrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10433b698ba48Smrg
10434f395c03eSmrg      output=$obj
10435e4f6584cSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10436b698ba48Smrg
10437e4f6584cSmrg      # Exit if we aren't doing a library object file.
10438e4f6584cSmrg      if test -z "$libobj"; then
10439e4f6584cSmrg	if test -n "$gentop"; then
10440e4f6584cSmrg	  func_show_eval '${RM}r "$gentop"'
10441e4f6584cSmrg	fi
10442e4f6584cSmrg
10443e4f6584cSmrg	exit $EXIT_SUCCESS
10444b698ba48Smrg      fi
10445e4f6584cSmrg
10446f395c03eSmrg      test yes = "$build_libtool_libs" || {
10447e4f6584cSmrg	if test -n "$gentop"; then
10448e4f6584cSmrg	  func_show_eval '${RM}r "$gentop"'
10449e4f6584cSmrg	fi
10450e4f6584cSmrg
10451e4f6584cSmrg	# Create an invalid libtool object if no PIC, so that we don't
10452e4f6584cSmrg	# accidentally link it into a program.
10453e4f6584cSmrg	# $show "echo timestamp > $libobj"
10454e4f6584cSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
10455e4f6584cSmrg	exit $EXIT_SUCCESS
10456f395c03eSmrg      }
10457e4f6584cSmrg
10458f395c03eSmrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
10459e4f6584cSmrg	# Only do commands if we really have different PIC objects.
10460e4f6584cSmrg	reload_objs="$libobjs $reload_conv_objs"
10461f395c03eSmrg	output=$libobj
10462e4f6584cSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
10463e4f6584cSmrg      fi
10464e4f6584cSmrg
10465e4f6584cSmrg      if test -n "$gentop"; then
10466e4f6584cSmrg	func_show_eval '${RM}r "$gentop"'
10467e4f6584cSmrg      fi
10468e4f6584cSmrg
10469e4f6584cSmrg      exit $EXIT_SUCCESS
10470b698ba48Smrg      ;;
1047109885543Smrg
10472e4f6584cSmrg    prog)
10473e4f6584cSmrg      case $host in
10474e4f6584cSmrg	*cygwin*) func_stripname '' '.exe' "$output"
10475e4f6584cSmrg	          output=$func_stripname_result.exe;;
10476e4f6584cSmrg      esac
10477e4f6584cSmrg      test -n "$vinfo" && \
10478f395c03eSmrg	func_warning "'-version-info' is ignored for programs"
1047909885543Smrg
10480e4f6584cSmrg      test -n "$release" && \
10481f395c03eSmrg	func_warning "'-release' is ignored for programs"
1048209885543Smrg
10483f395c03eSmrg      $preload \
10484f395c03eSmrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10485f395c03eSmrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
10486e4f6584cSmrg
10487e4f6584cSmrg      case $host in
10488e4f6584cSmrg      *-*-rhapsody* | *-*-darwin1.[012])
10489e4f6584cSmrg	# On Rhapsody replace the C library is the System framework
10490b12e5c03Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10491b12e5c03Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10492b698ba48Smrg	;;
10493e4f6584cSmrg      esac
10494b698ba48Smrg
10495e4f6584cSmrg      case $host in
10496e4f6584cSmrg      *-*-darwin*)
10497e4f6584cSmrg	# Don't allow lazy linking, it breaks C++ global constructors
10498e4f6584cSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10499f395c03eSmrg	if test CXX = "$tagname"; then
10500e4f6584cSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
10501e4f6584cSmrg	    10.[0123])
10502f395c03eSmrg	      func_append compile_command " $wl-bind_at_load"
10503f395c03eSmrg	      func_append finalize_command " $wl-bind_at_load"
10504e4f6584cSmrg	    ;;
10505e4f6584cSmrg	  esac
10506b698ba48Smrg	fi
10507e4f6584cSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10508b12e5c03Smrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10509b12e5c03Smrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10510e4f6584cSmrg	;;
10511e4f6584cSmrg      esac
10512b698ba48Smrg
10513b698ba48Smrg
10514e4f6584cSmrg      # move library search paths that coincide with paths to not yet
10515e4f6584cSmrg      # installed libraries to the beginning of the library search list
10516e4f6584cSmrg      new_libs=
10517e4f6584cSmrg      for path in $notinst_path; do
10518e4f6584cSmrg	case " $new_libs " in
10519e4f6584cSmrg	*" -L$path/$objdir "*) ;;
10520e4f6584cSmrg	*)
10521e4f6584cSmrg	  case " $compile_deplibs " in
10522e4f6584cSmrg	  *" -L$path/$objdir "*)
10523b12e5c03Smrg	    func_append new_libs " -L$path/$objdir" ;;
105242ec8c4b4Smrg	  esac
10525e4f6584cSmrg	  ;;
10526e4f6584cSmrg	esac
10527e4f6584cSmrg      done
10528e4f6584cSmrg      for deplib in $compile_deplibs; do
10529e4f6584cSmrg	case $deplib in
10530e4f6584cSmrg	-L*)
10531e4f6584cSmrg	  case " $new_libs " in
10532e4f6584cSmrg	  *" $deplib "*) ;;
10533b12e5c03Smrg	  *) func_append new_libs " $deplib" ;;
105342ec8c4b4Smrg	  esac
10535e4f6584cSmrg	  ;;
10536b12e5c03Smrg	*) func_append new_libs " $deplib" ;;
10537e4f6584cSmrg	esac
10538e4f6584cSmrg      done
10539f395c03eSmrg      compile_deplibs=$new_libs
1054009885543Smrg
10541b698ba48Smrg
10542b12e5c03Smrg      func_append compile_command " $compile_deplibs"
10543b12e5c03Smrg      func_append finalize_command " $finalize_deplibs"
10544b698ba48Smrg
10545e4f6584cSmrg      if test -n "$rpath$xrpath"; then
10546e4f6584cSmrg	# If the user specified any rpath flags, then add them.
10547e4f6584cSmrg	for libdir in $rpath $xrpath; do
10548e4f6584cSmrg	  # This is the magic to use -rpath.
10549e4f6584cSmrg	  case "$finalize_rpath " in
10550e4f6584cSmrg	  *" $libdir "*) ;;
10551b12e5c03Smrg	  *) func_append finalize_rpath " $libdir" ;;
10552e4f6584cSmrg	  esac
10553e4f6584cSmrg	done
10554e4f6584cSmrg      fi
10555b698ba48Smrg
10556e4f6584cSmrg      # Now hardcode the library paths
10557e4f6584cSmrg      rpath=
10558e4f6584cSmrg      hardcode_libdirs=
10559e4f6584cSmrg      for libdir in $compile_rpath $finalize_rpath; do
10560e4f6584cSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10561e4f6584cSmrg	  if test -n "$hardcode_libdir_separator"; then
10562e4f6584cSmrg	    if test -z "$hardcode_libdirs"; then
10563f395c03eSmrg	      hardcode_libdirs=$libdir
10564e4f6584cSmrg	    else
10565e4f6584cSmrg	      # Just accumulate the unique libdirs.
10566e4f6584cSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10567e4f6584cSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10568e4f6584cSmrg		;;
10569e4f6584cSmrg	      *)
10570b12e5c03Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10571e4f6584cSmrg		;;
10572e4f6584cSmrg	      esac
10573e4f6584cSmrg	    fi
10574b698ba48Smrg	  else
10575e4f6584cSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10576b12e5c03Smrg	    func_append rpath " $flag"
10577b698ba48Smrg	  fi
10578e4f6584cSmrg	elif test -n "$runpath_var"; then
10579e4f6584cSmrg	  case "$perm_rpath " in
10580e4f6584cSmrg	  *" $libdir "*) ;;
10581b12e5c03Smrg	  *) func_append perm_rpath " $libdir" ;;
10582e4f6584cSmrg	  esac
10583e4f6584cSmrg	fi
10584e4f6584cSmrg	case $host in
10585e4f6584cSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10586f395c03eSmrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
10587e4f6584cSmrg	  case :$dllsearchpath: in
10588e4f6584cSmrg	  *":$libdir:"*) ;;
10589e4f6584cSmrg	  ::) dllsearchpath=$libdir;;
10590b12e5c03Smrg	  *) func_append dllsearchpath ":$libdir";;
10591e4f6584cSmrg	  esac
10592e4f6584cSmrg	  case :$dllsearchpath: in
10593e4f6584cSmrg	  *":$testbindir:"*) ;;
10594e4f6584cSmrg	  ::) dllsearchpath=$testbindir;;
10595b12e5c03Smrg	  *) func_append dllsearchpath ":$testbindir";;
10596e4f6584cSmrg	  esac
10597e4f6584cSmrg	  ;;
10598e4f6584cSmrg	esac
10599e4f6584cSmrg      done
10600e4f6584cSmrg      # Substitute the hardcoded libdirs into the rpath.
10601e4f6584cSmrg      if test -n "$hardcode_libdir_separator" &&
10602e4f6584cSmrg	 test -n "$hardcode_libdirs"; then
10603f395c03eSmrg	libdir=$hardcode_libdirs
10604e4f6584cSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10605e4f6584cSmrg      fi
10606f395c03eSmrg      compile_rpath=$rpath
10607b698ba48Smrg
10608e4f6584cSmrg      rpath=
10609e4f6584cSmrg      hardcode_libdirs=
10610e4f6584cSmrg      for libdir in $finalize_rpath; do
10611e4f6584cSmrg	if test -n "$hardcode_libdir_flag_spec"; then
10612e4f6584cSmrg	  if test -n "$hardcode_libdir_separator"; then
10613e4f6584cSmrg	    if test -z "$hardcode_libdirs"; then
10614f395c03eSmrg	      hardcode_libdirs=$libdir
10615e4f6584cSmrg	    else
10616e4f6584cSmrg	      # Just accumulate the unique libdirs.
10617e4f6584cSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
10618e4f6584cSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
10619e4f6584cSmrg		;;
10620e4f6584cSmrg	      *)
10621b12e5c03Smrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
10622e4f6584cSmrg		;;
10623e4f6584cSmrg	      esac
10624e4f6584cSmrg	    fi
1062509885543Smrg	  else
10626e4f6584cSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
10627b12e5c03Smrg	    func_append rpath " $flag"
1062809885543Smrg	  fi
10629e4f6584cSmrg	elif test -n "$runpath_var"; then
10630e4f6584cSmrg	  case "$finalize_perm_rpath " in
10631e4f6584cSmrg	  *" $libdir "*) ;;
10632b12e5c03Smrg	  *) func_append finalize_perm_rpath " $libdir" ;;
10633e4f6584cSmrg	  esac
1063409885543Smrg	fi
10635e4f6584cSmrg      done
10636e4f6584cSmrg      # Substitute the hardcoded libdirs into the rpath.
10637e4f6584cSmrg      if test -n "$hardcode_libdir_separator" &&
10638e4f6584cSmrg	 test -n "$hardcode_libdirs"; then
10639f395c03eSmrg	libdir=$hardcode_libdirs
10640e4f6584cSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
10641e4f6584cSmrg      fi
10642f395c03eSmrg      finalize_rpath=$rpath
1064309885543Smrg
10644f395c03eSmrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
10645e4f6584cSmrg	# Transform all the library objects into standard objects.
10646b12e5c03Smrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10647b12e5c03Smrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10648e4f6584cSmrg      fi
1064909885543Smrg
10650f395c03eSmrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
1065109885543Smrg
10652e4f6584cSmrg      # template prelinking step
10653e4f6584cSmrg      if test -n "$prelink_cmds"; then
10654e4f6584cSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
10655e4f6584cSmrg      fi
1065609885543Smrg
10657f395c03eSmrg      wrappers_required=:
10658e4f6584cSmrg      case $host in
10659b12e5c03Smrg      *cegcc* | *mingw32ce*)
10660b12e5c03Smrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10661f395c03eSmrg        wrappers_required=false
10662b12e5c03Smrg        ;;
10663e4f6584cSmrg      *cygwin* | *mingw* )
10664f395c03eSmrg        test yes = "$build_libtool_libs" || wrappers_required=false
10665e4f6584cSmrg        ;;
10666e4f6584cSmrg      *)
10667f395c03eSmrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10668f395c03eSmrg          wrappers_required=false
10669e4f6584cSmrg        fi
10670e4f6584cSmrg        ;;
10671e4f6584cSmrg      esac
10672f395c03eSmrg      $wrappers_required || {
10673e4f6584cSmrg	# Replace the output file specification.
10674b12e5c03Smrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10675f395c03eSmrg	link_command=$compile_command$compile_rpath
1067609885543Smrg
10677e4f6584cSmrg	# We have no uninstalled library dependencies, so finalize right now.
10678e4f6584cSmrg	exit_status=0
10679e4f6584cSmrg	func_show_eval "$link_command" 'exit_status=$?'
1068009885543Smrg
10681b12e5c03Smrg	if test -n "$postlink_cmds"; then
10682b12e5c03Smrg	  func_to_tool_file "$output"
10683b12e5c03Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10684b12e5c03Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10685b12e5c03Smrg	fi
10686b12e5c03Smrg
10687e4f6584cSmrg	# Delete the generated files.
10688f395c03eSmrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10689f395c03eSmrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
1069009885543Smrg	fi
1069109885543Smrg
10692e4f6584cSmrg	exit $exit_status
10693f395c03eSmrg      }
1069409885543Smrg
10695e4f6584cSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
10696e4f6584cSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
10697e4f6584cSmrg      fi
10698e4f6584cSmrg      if test -n "$finalize_shlibpath"; then
10699e4f6584cSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
10700e4f6584cSmrg      fi
10701b698ba48Smrg
10702e4f6584cSmrg      compile_var=
10703e4f6584cSmrg      finalize_var=
10704e4f6584cSmrg      if test -n "$runpath_var"; then
10705e4f6584cSmrg	if test -n "$perm_rpath"; then
10706e4f6584cSmrg	  # We should set the runpath_var.
10707e4f6584cSmrg	  rpath=
10708e4f6584cSmrg	  for dir in $perm_rpath; do
10709b12e5c03Smrg	    func_append rpath "$dir:"
10710e4f6584cSmrg	  done
10711e4f6584cSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
1071209885543Smrg	fi
10713e4f6584cSmrg	if test -n "$finalize_perm_rpath"; then
10714e4f6584cSmrg	  # We should set the runpath_var.
10715e4f6584cSmrg	  rpath=
10716e4f6584cSmrg	  for dir in $finalize_perm_rpath; do
10717b12e5c03Smrg	    func_append rpath "$dir:"
10718e4f6584cSmrg	  done
10719e4f6584cSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
1072009885543Smrg	fi
10721e4f6584cSmrg      fi
1072209885543Smrg
10723f395c03eSmrg      if test yes = "$no_install"; then
10724e4f6584cSmrg	# We don't need to create a wrapper script.
10725f395c03eSmrg	link_command=$compile_var$compile_command$compile_rpath
10726e4f6584cSmrg	# Replace the output file specification.
10727b12e5c03Smrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10728e4f6584cSmrg	# Delete the old output file.
10729e4f6584cSmrg	$opt_dry_run || $RM $output
10730e4f6584cSmrg	# Link the executable and exit
10731e4f6584cSmrg	func_show_eval "$link_command" 'exit $?'
10732b12e5c03Smrg
10733b12e5c03Smrg	if test -n "$postlink_cmds"; then
10734b12e5c03Smrg	  func_to_tool_file "$output"
10735b12e5c03Smrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
10736b12e5c03Smrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
10737b12e5c03Smrg	fi
10738b12e5c03Smrg
10739b698ba48Smrg	exit $EXIT_SUCCESS
10740e4f6584cSmrg      fi
107412ec8c4b4Smrg
10742f395c03eSmrg      case $hardcode_action,$fast_install in
10743f395c03eSmrg        relink,*)
10744f395c03eSmrg	  # Fast installation is not supported
10745f395c03eSmrg	  link_command=$compile_var$compile_command$compile_rpath
10746f395c03eSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10747e4f6584cSmrg
10748f395c03eSmrg	  func_warning "this platform does not like uninstalled shared libraries"
10749f395c03eSmrg	  func_warning "'$output' will be relinked during installation"
10750f395c03eSmrg	  ;;
10751f395c03eSmrg        *,yes)
10752f395c03eSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10753f395c03eSmrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10754f395c03eSmrg          ;;
10755f395c03eSmrg	*,no)
10756f395c03eSmrg	  link_command=$compile_var$compile_command$compile_rpath
10757f395c03eSmrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10758f395c03eSmrg          ;;
10759f395c03eSmrg	*,needless)
10760f395c03eSmrg	  link_command=$finalize_var$compile_command$finalize_rpath
10761f395c03eSmrg	  relink_command=
10762f395c03eSmrg          ;;
10763f395c03eSmrg      esac
1076409885543Smrg
10765e4f6584cSmrg      # Replace the output file specification.
10766b12e5c03Smrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
1076709885543Smrg
10768e4f6584cSmrg      # Delete the old output files.
10769e4f6584cSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
1077009885543Smrg
10771e4f6584cSmrg      func_show_eval "$link_command" 'exit $?'
10772b698ba48Smrg
10773b12e5c03Smrg      if test -n "$postlink_cmds"; then
10774b12e5c03Smrg	func_to_tool_file "$output_objdir/$outputname"
10775b12e5c03Smrg	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'`
10776b12e5c03Smrg	func_execute_cmds "$postlink_cmds" 'exit $?'
10777b12e5c03Smrg      fi
10778b12e5c03Smrg
10779e4f6584cSmrg      # Now create the wrapper script.
10780e4f6584cSmrg      func_verbose "creating $output"
10781b698ba48Smrg
10782e4f6584cSmrg      # Quote the relink command for shipping.
10783e4f6584cSmrg      if test -n "$relink_command"; then
10784e4f6584cSmrg	# Preserve any variables that may affect compiler behavior
10785e4f6584cSmrg	for var in $variables_saved_for_relink; do
10786e4f6584cSmrg	  if eval test -z \"\${$var+set}\"; then
10787e4f6584cSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
10788e4f6584cSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
10789e4f6584cSmrg	    relink_command="$var=; export $var; $relink_command"
1079009885543Smrg	  else
10791beef1b22Smrg	    func_quote_arg pretty "$var_value"
10792beef1b22Smrg	    relink_command="$var=$func_quote_arg_result; export $var; $relink_command"
1079309885543Smrg	  fi
10794e4f6584cSmrg	done
10795beef1b22Smrg	func_quote eval cd "`pwd`"
10796beef1b22Smrg	func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)"
10797beef1b22Smrg	relink_command=$func_quote_arg_unquoted_result
10798e4f6584cSmrg      fi
10799e4f6584cSmrg
10800e4f6584cSmrg      # Only actually do things if not in dry run mode.
10801e4f6584cSmrg      $opt_dry_run || {
10802e4f6584cSmrg	# win32 will think the script is a binary if it has
10803e4f6584cSmrg	# a .exe suffix, so we strip it off here.
10804e4f6584cSmrg	case $output in
10805e4f6584cSmrg	  *.exe) func_stripname '' '.exe' "$output"
10806e4f6584cSmrg	         output=$func_stripname_result ;;
10807e4f6584cSmrg	esac
10808e4f6584cSmrg	# test for cygwin because mv fails w/o .exe extensions
10809e4f6584cSmrg	case $host in
10810e4f6584cSmrg	  *cygwin*)
10811e4f6584cSmrg	    exeext=.exe
10812e4f6584cSmrg	    func_stripname '' '.exe' "$outputname"
10813e4f6584cSmrg	    outputname=$func_stripname_result ;;
10814e4f6584cSmrg	  *) exeext= ;;
1081509885543Smrg	esac
10816e4f6584cSmrg	case $host in
10817e4f6584cSmrg	  *cygwin* | *mingw* )
10818e4f6584cSmrg	    func_dirname_and_basename "$output" "" "."
10819e4f6584cSmrg	    output_name=$func_basename_result
10820e4f6584cSmrg	    output_path=$func_dirname_result
10821f395c03eSmrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10822f395c03eSmrg	    cwrapper=$output_path/$output_name.exe
10823e4f6584cSmrg	    $RM $cwrappersource $cwrapper
10824e4f6584cSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
10825e4f6584cSmrg
10826e4f6584cSmrg	    func_emit_cwrapperexe_src > $cwrappersource
10827e4f6584cSmrg
10828e4f6584cSmrg	    # The wrapper executable is built using the $host compiler,
10829e4f6584cSmrg	    # because it contains $host paths and files. If cross-
10830e4f6584cSmrg	    # compiling, it, like the target executable, must be
10831e4f6584cSmrg	    # executed on the $host or under an emulation environment.
10832e4f6584cSmrg	    $opt_dry_run || {
10833e4f6584cSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
10834e4f6584cSmrg	      $STRIP $cwrapper
10835e4f6584cSmrg	    }
1083609885543Smrg
10837e4f6584cSmrg	    # Now, create the wrapper script for func_source use:
10838e4f6584cSmrg	    func_ltwrapper_scriptname $cwrapper
10839e4f6584cSmrg	    $RM $func_ltwrapper_scriptname_result
10840e4f6584cSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
10841e4f6584cSmrg	    $opt_dry_run || {
10842e4f6584cSmrg	      # note: this script will not be executed, so do not chmod.
10843f395c03eSmrg	      if test "x$build" = "x$host"; then
10844e4f6584cSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
10845e4f6584cSmrg	      else
10846e4f6584cSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
10847e4f6584cSmrg	      fi
10848e4f6584cSmrg	    }
10849e4f6584cSmrg	  ;;
10850e4f6584cSmrg	  * )
10851e4f6584cSmrg	    $RM $output
10852e4f6584cSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
1085309885543Smrg
10854e4f6584cSmrg	    func_emit_wrapper no > $output
10855e4f6584cSmrg	    chmod +x $output
10856e4f6584cSmrg	  ;;
10857e4f6584cSmrg	esac
10858e4f6584cSmrg      }
10859e4f6584cSmrg      exit $EXIT_SUCCESS
10860e4f6584cSmrg      ;;
10861e4f6584cSmrg    esac
1086209885543Smrg
10863e4f6584cSmrg    # See if we need to build an old-fashioned archive.
10864e4f6584cSmrg    for oldlib in $oldlibs; do
1086509885543Smrg
10866f395c03eSmrg      case $build_libtool_libs in
10867f395c03eSmrg        convenience)
10868f395c03eSmrg	  oldobjs="$libobjs_save $symfileobj"
10869f395c03eSmrg	  addlibs=$convenience
10870e4f6584cSmrg	  build_libtool_libs=no
10871f395c03eSmrg	  ;;
10872f395c03eSmrg	module)
10873f395c03eSmrg	  oldobjs=$libobjs_save
10874f395c03eSmrg	  addlibs=$old_convenience
10875f395c03eSmrg	  build_libtool_libs=no
10876f395c03eSmrg          ;;
10877f395c03eSmrg	*)
10878e4f6584cSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10879f395c03eSmrg	  $preload && test -f "$symfileobj" \
10880f395c03eSmrg	    && func_append oldobjs " $symfileobj"
10881f395c03eSmrg	  addlibs=$old_convenience
10882f395c03eSmrg	  ;;
10883f395c03eSmrg      esac
1088409885543Smrg
10885e4f6584cSmrg      if test -n "$addlibs"; then
10886f395c03eSmrg	gentop=$output_objdir/${outputname}x
10887b12e5c03Smrg	func_append generated " $gentop"
1088809885543Smrg
10889e4f6584cSmrg	func_extract_archives $gentop $addlibs
10890b12e5c03Smrg	func_append oldobjs " $func_extract_archives_result"
10891e4f6584cSmrg      fi
1089209885543Smrg
10893e4f6584cSmrg      # Do each command in the archive commands.
10894f395c03eSmrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
10895e4f6584cSmrg	cmds=$old_archive_from_new_cmds
10896e4f6584cSmrg      else
1089709885543Smrg
10898e4f6584cSmrg	# Add any objects from preloaded convenience libraries
10899e4f6584cSmrg	if test -n "$dlprefiles"; then
10900f395c03eSmrg	  gentop=$output_objdir/${outputname}x
10901b12e5c03Smrg	  func_append generated " $gentop"
1090209885543Smrg
10903e4f6584cSmrg	  func_extract_archives $gentop $dlprefiles
10904b12e5c03Smrg	  func_append oldobjs " $func_extract_archives_result"
10905e4f6584cSmrg	fi
1090609885543Smrg
10907e4f6584cSmrg	# POSIX demands no paths to be encoded in archives.  We have
10908e4f6584cSmrg	# to avoid creating archives with duplicate basenames if we
10909e4f6584cSmrg	# might have to extract them afterwards, e.g., when creating a
10910e4f6584cSmrg	# static archive out of a convenience library, or when linking
10911e4f6584cSmrg	# the entirety of a libtool archive into another (currently
10912e4f6584cSmrg	# not supported by libtool).
10913e4f6584cSmrg	if (for obj in $oldobjs
10914e4f6584cSmrg	    do
10915e4f6584cSmrg	      func_basename "$obj"
10916e4f6584cSmrg	      $ECHO "$func_basename_result"
10917e4f6584cSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
10918e4f6584cSmrg	  :
10919e4f6584cSmrg	else
10920b12e5c03Smrg	  echo "copying selected object files to avoid basename conflicts..."
10921f395c03eSmrg	  gentop=$output_objdir/${outputname}x
10922b12e5c03Smrg	  func_append generated " $gentop"
10923e4f6584cSmrg	  func_mkdir_p "$gentop"
10924e4f6584cSmrg	  save_oldobjs=$oldobjs
10925e4f6584cSmrg	  oldobjs=
10926e4f6584cSmrg	  counter=1
10927e4f6584cSmrg	  for obj in $save_oldobjs
10928e4f6584cSmrg	  do
10929e4f6584cSmrg	    func_basename "$obj"
10930f395c03eSmrg	    objbase=$func_basename_result
10931e4f6584cSmrg	    case " $oldobjs " in
10932e4f6584cSmrg	    " ") oldobjs=$obj ;;
10933e4f6584cSmrg	    *[\ /]"$objbase "*)
10934e4f6584cSmrg	      while :; do
10935e4f6584cSmrg		# Make sure we don't pick an alternate name that also
10936e4f6584cSmrg		# overlaps.
10937e4f6584cSmrg		newobj=lt$counter-$objbase
10938e4f6584cSmrg		func_arith $counter + 1
10939e4f6584cSmrg		counter=$func_arith_result
10940e4f6584cSmrg		case " $oldobjs " in
10941e4f6584cSmrg		*[\ /]"$newobj "*) ;;
10942e4f6584cSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
10943e4f6584cSmrg		esac
10944e4f6584cSmrg	      done
10945e4f6584cSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
10946b12e5c03Smrg	      func_append oldobjs " $gentop/$newobj"
10947e4f6584cSmrg	      ;;
10948b12e5c03Smrg	    *) func_append oldobjs " $obj" ;;
10949e4f6584cSmrg	    esac
1095009885543Smrg	  done
109512ec8c4b4Smrg	fi
10952b12e5c03Smrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
10953b12e5c03Smrg	tool_oldlib=$func_to_tool_file_result
10954e4f6584cSmrg	eval cmds=\"$old_archive_cmds\"
10955b698ba48Smrg
10956e4f6584cSmrg	func_len " $cmds"
10957e4f6584cSmrg	len=$func_len_result
10958e4f6584cSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
10959e4f6584cSmrg	  cmds=$old_archive_cmds
10960b12e5c03Smrg	elif test -n "$archiver_list_spec"; then
10961b12e5c03Smrg	  func_verbose "using command file archive linking..."
10962b12e5c03Smrg	  for obj in $oldobjs
10963b12e5c03Smrg	  do
10964b12e5c03Smrg	    func_to_tool_file "$obj"
10965b12e5c03Smrg	    $ECHO "$func_to_tool_file_result"
10966b12e5c03Smrg	  done > $output_objdir/$libname.libcmd
10967b12e5c03Smrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
10968b12e5c03Smrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
10969b12e5c03Smrg	  cmds=$old_archive_cmds
10970e4f6584cSmrg	else
10971e4f6584cSmrg	  # the command line is too long to link in one step, link in parts
10972e4f6584cSmrg	  func_verbose "using piecewise archive linking..."
10973e4f6584cSmrg	  save_RANLIB=$RANLIB
10974e4f6584cSmrg	  RANLIB=:
10975e4f6584cSmrg	  objlist=
10976e4f6584cSmrg	  concat_cmds=
10977e4f6584cSmrg	  save_oldobjs=$oldobjs
10978e4f6584cSmrg	  oldobjs=
10979e4f6584cSmrg	  # Is there a better way of finding the last object in the list?
10980e4f6584cSmrg	  for obj in $save_oldobjs
10981e4f6584cSmrg	  do
10982e4f6584cSmrg	    last_oldobj=$obj
10983e4f6584cSmrg	  done
10984e4f6584cSmrg	  eval test_cmds=\"$old_archive_cmds\"
10985e4f6584cSmrg	  func_len " $test_cmds"
10986e4f6584cSmrg	  len0=$func_len_result
10987e4f6584cSmrg	  len=$len0
10988e4f6584cSmrg	  for obj in $save_oldobjs
10989e4f6584cSmrg	  do
10990e4f6584cSmrg	    func_len " $obj"
10991e4f6584cSmrg	    func_arith $len + $func_len_result
10992e4f6584cSmrg	    len=$func_arith_result
10993e4f6584cSmrg	    func_append objlist " $obj"
10994e4f6584cSmrg	    if test "$len" -lt "$max_cmd_len"; then
10995e4f6584cSmrg	      :
10996e4f6584cSmrg	    else
10997e4f6584cSmrg	      # the above command should be used before it gets too long
10998e4f6584cSmrg	      oldobjs=$objlist
10999f395c03eSmrg	      if test "$obj" = "$last_oldobj"; then
11000e4f6584cSmrg		RANLIB=$save_RANLIB
11001e4f6584cSmrg	      fi
11002e4f6584cSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
11003f395c03eSmrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
11004e4f6584cSmrg	      objlist=
11005e4f6584cSmrg	      len=$len0
11006e4f6584cSmrg	    fi
11007e4f6584cSmrg	  done
11008e4f6584cSmrg	  RANLIB=$save_RANLIB
11009e4f6584cSmrg	  oldobjs=$objlist
11010f395c03eSmrg	  if test -z "$oldobjs"; then
11011e4f6584cSmrg	    eval cmds=\"\$concat_cmds\"
11012e4f6584cSmrg	  else
11013e4f6584cSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
11014e4f6584cSmrg	  fi
11015e4f6584cSmrg	fi
11016e4f6584cSmrg      fi
11017e4f6584cSmrg      func_execute_cmds "$cmds" 'exit $?'
1101809885543Smrg    done
1101909885543Smrg
11020e4f6584cSmrg    test -n "$generated" && \
11021e4f6584cSmrg      func_show_eval "${RM}r$generated"
1102209885543Smrg
11023e4f6584cSmrg    # Now create the libtool archive.
11024e4f6584cSmrg    case $output in
11025e4f6584cSmrg    *.la)
11026e4f6584cSmrg      old_library=
11027f395c03eSmrg      test yes = "$build_old_libs" && old_library=$libname.$libext
11028e4f6584cSmrg      func_verbose "creating $output"
110292ec8c4b4Smrg
11030e4f6584cSmrg      # Preserve any variables that may affect compiler behavior
11031e4f6584cSmrg      for var in $variables_saved_for_relink; do
11032e4f6584cSmrg	if eval test -z \"\${$var+set}\"; then
11033e4f6584cSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
11034e4f6584cSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
11035e4f6584cSmrg	  relink_command="$var=; export $var; $relink_command"
11036b698ba48Smrg	else
11037beef1b22Smrg	  func_quote_arg pretty,unquoted "$var_value"
11038beef1b22Smrg	  relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command"
11039b698ba48Smrg	fi
11040e4f6584cSmrg      done
11041e4f6584cSmrg      # Quote the link command for shipping.
11042beef1b22Smrg      func_quote eval cd "`pwd`"
11043beef1b22Smrg      relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
11044beef1b22Smrg      func_quote_arg pretty,unquoted "$relink_command"
11045beef1b22Smrg      relink_command=$func_quote_arg_unquoted_result
11046f395c03eSmrg      if test yes = "$hardcode_automatic"; then
11047e4f6584cSmrg	relink_command=
11048e4f6584cSmrg      fi
1104909885543Smrg
11050e4f6584cSmrg      # Only create the output if not a dry run.
11051e4f6584cSmrg      $opt_dry_run || {
11052e4f6584cSmrg	for installed in no yes; do
11053f395c03eSmrg	  if test yes = "$installed"; then
11054e4f6584cSmrg	    if test -z "$install_libdir"; then
11055e4f6584cSmrg	      break
11056e4f6584cSmrg	    fi
11057f395c03eSmrg	    output=$output_objdir/${outputname}i
11058e4f6584cSmrg	    # Replace all uninstalled libtool libraries with the installed ones
11059e4f6584cSmrg	    newdependency_libs=
11060e4f6584cSmrg	    for deplib in $dependency_libs; do
11061e4f6584cSmrg	      case $deplib in
11062e4f6584cSmrg	      *.la)
11063e4f6584cSmrg		func_basename "$deplib"
11064f395c03eSmrg		name=$func_basename_result
11065b12e5c03Smrg		func_resolve_sysroot "$deplib"
11066f395c03eSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
11067e4f6584cSmrg		test -z "$libdir" && \
11068f395c03eSmrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
11069b12e5c03Smrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
11070b12e5c03Smrg		;;
11071b12e5c03Smrg	      -L*)
11072b12e5c03Smrg		func_stripname -L '' "$deplib"
11073b12e5c03Smrg		func_replace_sysroot "$func_stripname_result"
11074b12e5c03Smrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
11075e4f6584cSmrg		;;
11076b12e5c03Smrg	      -R*)
11077b12e5c03Smrg		func_stripname -R '' "$deplib"
11078b12e5c03Smrg		func_replace_sysroot "$func_stripname_result"
11079b12e5c03Smrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
11080b12e5c03Smrg		;;
11081b12e5c03Smrg	      *) func_append newdependency_libs " $deplib" ;;
11082e4f6584cSmrg	      esac
11083e4f6584cSmrg	    done
11084f395c03eSmrg	    dependency_libs=$newdependency_libs
11085e4f6584cSmrg	    newdlfiles=
11086e4f6584cSmrg
11087e4f6584cSmrg	    for lib in $dlfiles; do
11088e4f6584cSmrg	      case $lib in
11089e4f6584cSmrg	      *.la)
11090e4f6584cSmrg	        func_basename "$lib"
11091f395c03eSmrg		name=$func_basename_result
11092f395c03eSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11093e4f6584cSmrg		test -z "$libdir" && \
11094f395c03eSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11095b12e5c03Smrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
11096e4f6584cSmrg		;;
11097b12e5c03Smrg	      *) func_append newdlfiles " $lib" ;;
11098e4f6584cSmrg	      esac
11099e4f6584cSmrg	    done
11100f395c03eSmrg	    dlfiles=$newdlfiles
11101e4f6584cSmrg	    newdlprefiles=
11102e4f6584cSmrg	    for lib in $dlprefiles; do
11103e4f6584cSmrg	      case $lib in
11104e4f6584cSmrg	      *.la)
11105e4f6584cSmrg		# Only pass preopened files to the pseudo-archive (for
11106e4f6584cSmrg		# eventual linking with the app. that links it) if we
11107e4f6584cSmrg		# didn't already link the preopened objects directly into
11108e4f6584cSmrg		# the library:
11109e4f6584cSmrg		func_basename "$lib"
11110f395c03eSmrg		name=$func_basename_result
11111f395c03eSmrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
11112e4f6584cSmrg		test -z "$libdir" && \
11113f395c03eSmrg		  func_fatal_error "'$lib' is not a valid libtool archive"
11114b12e5c03Smrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
11115e4f6584cSmrg		;;
11116e4f6584cSmrg	      esac
11117e4f6584cSmrg	    done
11118f395c03eSmrg	    dlprefiles=$newdlprefiles
11119e4f6584cSmrg	  else
11120e4f6584cSmrg	    newdlfiles=
11121e4f6584cSmrg	    for lib in $dlfiles; do
11122e4f6584cSmrg	      case $lib in
11123f395c03eSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11124e4f6584cSmrg		*) abs=`pwd`"/$lib" ;;
11125e4f6584cSmrg	      esac
11126b12e5c03Smrg	      func_append newdlfiles " $abs"
11127e4f6584cSmrg	    done
11128f395c03eSmrg	    dlfiles=$newdlfiles
11129e4f6584cSmrg	    newdlprefiles=
11130e4f6584cSmrg	    for lib in $dlprefiles; do
11131e4f6584cSmrg	      case $lib in
11132f395c03eSmrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
11133e4f6584cSmrg		*) abs=`pwd`"/$lib" ;;
11134e4f6584cSmrg	      esac
11135b12e5c03Smrg	      func_append newdlprefiles " $abs"
11136e4f6584cSmrg	    done
11137f395c03eSmrg	    dlprefiles=$newdlprefiles
11138e4f6584cSmrg	  fi
11139e4f6584cSmrg	  $RM $output
11140e4f6584cSmrg	  # place dlname in correct position for cygwin
11141b12e5c03Smrg	  # In fact, it would be nice if we could use this code for all target
11142b12e5c03Smrg	  # systems that can't hard-code library paths into their executables
11143b12e5c03Smrg	  # and that have no shared library path variable independent of PATH,
11144b12e5c03Smrg	  # but it turns out we can't easily determine that from inspecting
11145b12e5c03Smrg	  # libtool variables, so we have to hard-code the OSs to which it
11146b12e5c03Smrg	  # applies here; at the moment, that means platforms that use the PE
11147b12e5c03Smrg	  # object format with DLL files.  See the long comment at the top of
11148b12e5c03Smrg	  # tests/bindir.at for full details.
11149e4f6584cSmrg	  tdlname=$dlname
11150e4f6584cSmrg	  case $host,$output,$installed,$module,$dlname in
11151b12e5c03Smrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
11152b12e5c03Smrg	      # If a -bindir argument was supplied, place the dll there.
11153f395c03eSmrg	      if test -n "$bindir"; then
11154b12e5c03Smrg		func_relative_path "$install_libdir" "$bindir"
11155f395c03eSmrg		tdlname=$func_relative_path_result/$dlname
11156b12e5c03Smrg	      else
11157b12e5c03Smrg		# Otherwise fall back on heuristic.
11158b12e5c03Smrg		tdlname=../bin/$dlname
11159b12e5c03Smrg	      fi
11160b12e5c03Smrg	      ;;
11161e4f6584cSmrg	  esac
11162e4f6584cSmrg	  $ECHO > $output "\
11163e4f6584cSmrg# $outputname - a libtool library file
11164f395c03eSmrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
11165e4f6584cSmrg#
11166e4f6584cSmrg# Please DO NOT delete this file!
11167e4f6584cSmrg# It is necessary for linking the library.
1116809885543Smrg
11169e4f6584cSmrg# The name that we can dlopen(3).
11170e4f6584cSmrgdlname='$tdlname'
1117109885543Smrg
11172e4f6584cSmrg# Names of this library.
11173e4f6584cSmrglibrary_names='$library_names'
1117409885543Smrg
11175e4f6584cSmrg# The name of the static archive.
11176e4f6584cSmrgold_library='$old_library'
1117709885543Smrg
11178f395c03eSmrg# Linker flags that cannot go in dependency_libs.
11179e4f6584cSmrginherited_linker_flags='$new_inherited_linker_flags'
1118009885543Smrg
11181e4f6584cSmrg# Libraries that this one depends upon.
11182e4f6584cSmrgdependency_libs='$dependency_libs'
1118309885543Smrg
11184e4f6584cSmrg# Names of additional weak libraries provided by this library
11185e4f6584cSmrgweak_library_names='$weak_libs'
1118609885543Smrg
11187e4f6584cSmrg# Version information for $libname.
11188e4f6584cSmrgcurrent=$current
11189e4f6584cSmrgage=$age
11190e4f6584cSmrgrevision=$revision
1119109885543Smrg
11192e4f6584cSmrg# Is this an already installed library?
11193e4f6584cSmrginstalled=$installed
1119409885543Smrg
11195e4f6584cSmrg# Should we warn about portability when linking against -modules?
11196e4f6584cSmrgshouldnotlink=$module
1119709885543Smrg
11198e4f6584cSmrg# Files to dlopen/dlpreopen
11199e4f6584cSmrgdlopen='$dlfiles'
11200e4f6584cSmrgdlpreopen='$dlprefiles'
1120109885543Smrg
11202e4f6584cSmrg# Directory that this library needs to be installed in:
11203e4f6584cSmrglibdir='$install_libdir'"
11204f395c03eSmrg	  if test no,yes = "$installed,$need_relink"; then
11205e4f6584cSmrg	    $ECHO >> $output "\
11206e4f6584cSmrgrelink_command=\"$relink_command\""
11207e4f6584cSmrg	  fi
11208e4f6584cSmrg	done
11209e4f6584cSmrg      }
1121009885543Smrg
11211e4f6584cSmrg      # Do a symbolic link so that the libtool archive can be found in
11212e4f6584cSmrg      # LD_LIBRARY_PATH before the program is installed.
11213e4f6584cSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
11214e4f6584cSmrg      ;;
11215e4f6584cSmrg    esac
11216e4f6584cSmrg    exit $EXIT_SUCCESS
11217e4f6584cSmrg}
11218b698ba48Smrg
11219f395c03eSmrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
11220f395c03eSmrg  func_mode_link ${1+"$@"}
11221f395c03eSmrgfi
1122209885543Smrg
1122309885543Smrg
11224e4f6584cSmrg# func_mode_uninstall arg...
11225e4f6584cSmrgfunc_mode_uninstall ()
11226e4f6584cSmrg{
11227f395c03eSmrg    $debug_cmd
11228f395c03eSmrg
11229f395c03eSmrg    RM=$nonopt
1123009885543Smrg    files=
11231f395c03eSmrg    rmforce=false
1123209885543Smrg    exit_status=0
1123309885543Smrg
1123409885543Smrg    # This variable tells wrapper scripts just to set variables rather
1123509885543Smrg    # than running their programs.
11236f395c03eSmrg    libtool_install_magic=$magic
1123709885543Smrg
1123809885543Smrg    for arg
1123909885543Smrg    do
1124009885543Smrg      case $arg in
11241f395c03eSmrg      -f) func_append RM " $arg"; rmforce=: ;;
11242b12e5c03Smrg      -*) func_append RM " $arg" ;;
11243b12e5c03Smrg      *) func_append files " $arg" ;;
1124409885543Smrg      esac
1124509885543Smrg    done
1124609885543Smrg
11247e4f6584cSmrg    test -z "$RM" && \
11248e4f6584cSmrg      func_fatal_help "you must specify an RM program"
1124909885543Smrg
1125009885543Smrg    rmdirs=
1125109885543Smrg
1125209885543Smrg    for file in $files; do
11253e4f6584cSmrg      func_dirname "$file" "" "."
11254f395c03eSmrg      dir=$func_dirname_result
11255f395c03eSmrg      if test . = "$dir"; then
11256f395c03eSmrg	odir=$objdir
1125709885543Smrg      else
11258f395c03eSmrg	odir=$dir/$objdir
1125909885543Smrg      fi
11260e4f6584cSmrg      func_basename "$file"
11261f395c03eSmrg      name=$func_basename_result
11262f395c03eSmrg      test uninstall = "$opt_mode" && odir=$dir
1126309885543Smrg
11264b12e5c03Smrg      # Remember odir for removal later, being careful to avoid duplicates
11265f395c03eSmrg      if test clean = "$opt_mode"; then
1126609885543Smrg	case " $rmdirs " in
11267b12e5c03Smrg	  *" $odir "*) ;;
11268b12e5c03Smrg	  *) func_append rmdirs " $odir" ;;
1126909885543Smrg	esac
1127009885543Smrg      fi
1127109885543Smrg
1127209885543Smrg      # Don't error if the file doesn't exist and rm -f was used.
11273e4f6584cSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
11274e4f6584cSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
11275e4f6584cSmrg	 test -f "$file"; then
1127609885543Smrg	:
1127709885543Smrg      elif test -d "$file"; then
1127809885543Smrg	exit_status=1
1127909885543Smrg	continue
11280f395c03eSmrg      elif $rmforce; then
1128109885543Smrg	continue
1128209885543Smrg      fi
1128309885543Smrg
11284f395c03eSmrg      rmfiles=$file
1128509885543Smrg
1128609885543Smrg      case $name in
1128709885543Smrg      *.la)
1128809885543Smrg	# Possibly a libtool archive, so verify it.
11289e4f6584cSmrg	if func_lalib_p "$file"; then
11290e4f6584cSmrg	  func_source $dir/$name
1129109885543Smrg
1129209885543Smrg	  # Delete the libtool libraries and symlinks.
1129309885543Smrg	  for n in $library_names; do
11294b12e5c03Smrg	    func_append rmfiles " $odir/$n"
1129509885543Smrg	  done
11296b12e5c03Smrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
1129709885543Smrg
11298f395c03eSmrg	  case $opt_mode in
1129909885543Smrg	  clean)
11300b12e5c03Smrg	    case " $library_names " in
1130109885543Smrg	    *" $dlname "*) ;;
11302b12e5c03Smrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
1130309885543Smrg	    esac
11304b12e5c03Smrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
1130509885543Smrg	    ;;
1130609885543Smrg	  uninstall)
1130709885543Smrg	    if test -n "$library_names"; then
1130809885543Smrg	      # Do each command in the postuninstall commands.
11309f395c03eSmrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
1131009885543Smrg	    fi
1131109885543Smrg
1131209885543Smrg	    if test -n "$old_library"; then
1131309885543Smrg	      # Do each command in the old_postuninstall commands.
11314f395c03eSmrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
1131509885543Smrg	    fi
1131609885543Smrg	    # FIXME: should reinstall the best remaining shared library.
1131709885543Smrg	    ;;
1131809885543Smrg	  esac
1131909885543Smrg	fi
1132009885543Smrg	;;
1132109885543Smrg
1132209885543Smrg      *.lo)
1132309885543Smrg	# Possibly a libtool object, so verify it.
11324e4f6584cSmrg	if func_lalib_p "$file"; then
1132509885543Smrg
1132609885543Smrg	  # Read the .lo file
11327e4f6584cSmrg	  func_source $dir/$name
1132809885543Smrg
1132909885543Smrg	  # Add PIC object to the list of files to remove.
11330f395c03eSmrg	  if test -n "$pic_object" && test none != "$pic_object"; then
11331b12e5c03Smrg	    func_append rmfiles " $dir/$pic_object"
1133209885543Smrg	  fi
1133309885543Smrg
1133409885543Smrg	  # Add non-PIC object to the list of files to remove.
11335f395c03eSmrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
11336b12e5c03Smrg	    func_append rmfiles " $dir/$non_pic_object"
1133709885543Smrg	  fi
1133809885543Smrg	fi
1133909885543Smrg	;;
1134009885543Smrg
1134109885543Smrg      *)
11342f395c03eSmrg	if test clean = "$opt_mode"; then
1134309885543Smrg	  noexename=$name
1134409885543Smrg	  case $file in
1134509885543Smrg	  *.exe)
11346e4f6584cSmrg	    func_stripname '' '.exe' "$file"
11347e4f6584cSmrg	    file=$func_stripname_result
11348e4f6584cSmrg	    func_stripname '' '.exe' "$name"
11349e4f6584cSmrg	    noexename=$func_stripname_result
1135009885543Smrg	    # $file with .exe has already been added to rmfiles,
1135109885543Smrg	    # add $file without .exe
11352b12e5c03Smrg	    func_append rmfiles " $file"
1135309885543Smrg	    ;;
1135409885543Smrg	  esac
1135509885543Smrg	  # Do a test to see if this is a libtool program.
11356e4f6584cSmrg	  if func_ltwrapper_p "$file"; then
11357e4f6584cSmrg	    if func_ltwrapper_executable_p "$file"; then
11358e4f6584cSmrg	      func_ltwrapper_scriptname "$file"
11359e4f6584cSmrg	      relink_command=
11360e4f6584cSmrg	      func_source $func_ltwrapper_scriptname_result
11361b12e5c03Smrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
11362e4f6584cSmrg	    else
11363e4f6584cSmrg	      relink_command=
11364e4f6584cSmrg	      func_source $dir/$noexename
11365e4f6584cSmrg	    fi
1136609885543Smrg
1136709885543Smrg	    # note $name still contains .exe if it was in $file originally
1136809885543Smrg	    # as does the version of $file that was added into $rmfiles
11369f395c03eSmrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11370f395c03eSmrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
11371b12e5c03Smrg	      func_append rmfiles " $odir/lt-$name"
1137209885543Smrg	    fi
11373f395c03eSmrg	    if test "X$noexename" != "X$name"; then
11374f395c03eSmrg	      func_append rmfiles " $odir/lt-$noexename.c"
1137509885543Smrg	    fi
1137609885543Smrg	  fi
1137709885543Smrg	fi
1137809885543Smrg	;;
1137909885543Smrg      esac
11380e4f6584cSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
1138109885543Smrg    done
1138209885543Smrg
11383f395c03eSmrg    # Try to remove the $objdir's in the directories where we deleted files
1138409885543Smrg    for dir in $rmdirs; do
1138509885543Smrg      if test -d "$dir"; then
11386e4f6584cSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
1138709885543Smrg      fi
1138809885543Smrg    done
1138909885543Smrg
1139009885543Smrg    exit $exit_status
11391e4f6584cSmrg}
1139209885543Smrg
11393f395c03eSmrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11394f395c03eSmrg  func_mode_uninstall ${1+"$@"}
11395f395c03eSmrgfi
113962ec8c4b4Smrg
11397b12e5c03Smrgtest -z "$opt_mode" && {
11398f395c03eSmrg  help=$generic_help
11399e4f6584cSmrg  func_fatal_help "you must specify a MODE"
11400e4f6584cSmrg}
11401e4f6584cSmrg
11402e4f6584cSmrgtest -z "$exec_cmd" && \
11403f395c03eSmrg  func_fatal_help "invalid operation mode '$opt_mode'"
1140409885543Smrg
1140509885543Smrgif test -n "$exec_cmd"; then
11406e4f6584cSmrg  eval exec "$exec_cmd"
1140709885543Smrg  exit $EXIT_FAILURE
1140809885543Smrgfi
1140909885543Smrg
11410e4f6584cSmrgexit $exit_status
1141109885543Smrg
1141209885543Smrg
1141309885543Smrg# The TAGs below are defined such that we never get into a situation
11414f395c03eSmrg# where we disable both kinds of libraries.  Given conflicting
1141509885543Smrg# choices, we go for a static library, that is the most portable,
1141609885543Smrg# since we can't tell whether shared libraries were disabled because
1141709885543Smrg# the user asked for that or because the platform doesn't support
1141809885543Smrg# them.  This is particularly important on AIX, because we don't
1141909885543Smrg# support having both static and shared libraries enabled at the same
1142009885543Smrg# time on that platform, so we default to a shared-only configuration.
1142109885543Smrg# If a disable-shared tag is given, we'll fallback to a static-only
1142209885543Smrg# configuration.  But we'll never go from static-only to shared-only.
1142309885543Smrg
1142409885543Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
11425e4f6584cSmrgbuild_libtool_libs=no
11426e4f6584cSmrgbuild_old_libs=yes
1142709885543Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
1142809885543Smrg
1142909885543Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
11430e4f6584cSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
1143109885543Smrg# ### END LIBTOOL TAG CONFIG: disable-static
1143209885543Smrg
1143309885543Smrg# Local Variables:
1143409885543Smrg# mode:shell-script
1143509885543Smrg# sh-indentation:2
1143609885543Smrg# End:
11437