ltmain.sh revision fe24f8a2
1fe24f8a2Smrg#! /bin/sh
2fe24f8a2Smrg## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3fe24f8a2Smrg##               by inline-source v2014-01-03.01
434977a2fSmrg
5fe24f8a2Smrg# libtool (GNU libtool) 2.4.6
6fe24f8a2Smrg# Provide generalized library-building support services.
734977a2fSmrg# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
834977a2fSmrg
9fe24f8a2Smrg# Copyright (C) 1996-2015 Free Software Foundation, Inc.
1034977a2fSmrg# This is free software; see the source for copying conditions.  There is NO
1134977a2fSmrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1234977a2fSmrg
1334977a2fSmrg# GNU Libtool is free software; you can redistribute it and/or modify
14ee3138f1Smrg# it under the terms of the GNU General Public License as published by
15ee3138f1Smrg# the Free Software Foundation; either version 2 of the License, or
16ee3138f1Smrg# (at your option) any later version.
17ee3138f1Smrg#
1834977a2fSmrg# As a special exception to the GNU General Public License,
1934977a2fSmrg# if you distribute this file as part of a program or library that
2034977a2fSmrg# is built using GNU Libtool, you may include this file under the
2134977a2fSmrg# same distribution terms that you use for the rest of that program.
2234977a2fSmrg#
2334977a2fSmrg# GNU Libtool is distributed in the hope that it will be useful, but
24ee3138f1Smrg# WITHOUT ANY WARRANTY; without even the implied warranty of
25ee3138f1Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26ee3138f1Smrg# General Public License for more details.
27ee3138f1Smrg#
28ee3138f1Smrg# You should have received a copy of the GNU General Public License
29fe24f8a2Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
3079a8a9c6Smrg
31ee3138f1Smrg
32b425557eSmrgPROGRAM=libtool
33ee3138f1SmrgPACKAGE=libtool
34fe24f8a2SmrgVERSION=2.4.6
35fe24f8a2Smrgpackage_revision=2.4.6
36ee3138f1Smrg
37fe24f8a2Smrg
38fe24f8a2Smrg## ------ ##
39fe24f8a2Smrg## Usage. ##
40fe24f8a2Smrg## ------ ##
41fe24f8a2Smrg
42fe24f8a2Smrg# Run './libtool --help' for help with using this script from the
43fe24f8a2Smrg# command line.
44fe24f8a2Smrg
45fe24f8a2Smrg
46fe24f8a2Smrg## ------------------------------- ##
47fe24f8a2Smrg## User overridable command paths. ##
48fe24f8a2Smrg## ------------------------------- ##
49fe24f8a2Smrg
50fe24f8a2Smrg# After configure completes, it has a better idea of some of the
51fe24f8a2Smrg# shell tools we need than the defaults used by the functions shared
52fe24f8a2Smrg# with bootstrap, so set those here where they can still be over-
53fe24f8a2Smrg# ridden by the user, but otherwise take precedence.
54fe24f8a2Smrg
55fe24f8a2Smrg: ${AUTOCONF="autoconf"}
56fe24f8a2Smrg: ${AUTOMAKE="automake"}
57fe24f8a2Smrg
58fe24f8a2Smrg
59fe24f8a2Smrg## -------------------------- ##
60fe24f8a2Smrg## Source external libraries. ##
61fe24f8a2Smrg## -------------------------- ##
62fe24f8a2Smrg
63fe24f8a2Smrg# Much of our low-level functionality needs to be sourced from external
64fe24f8a2Smrg# libraries, which are installed to $pkgauxdir.
65fe24f8a2Smrg
66fe24f8a2Smrg# Set a version string for this script.
67fe24f8a2Smrgscriptversion=2015-01-20.17; # UTC
68fe24f8a2Smrg
69fe24f8a2Smrg# General shell script boiler plate, and helper functions.
70fe24f8a2Smrg# Written by Gary V. Vaughan, 2004
71fe24f8a2Smrg
72fe24f8a2Smrg# Copyright (C) 2004-2015 Free Software Foundation, Inc.
73fe24f8a2Smrg# This is free software; see the source for copying conditions.  There is NO
74fe24f8a2Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75fe24f8a2Smrg
76fe24f8a2Smrg# This program is free software; you can redistribute it and/or modify
77fe24f8a2Smrg# it under the terms of the GNU General Public License as published by
78fe24f8a2Smrg# the Free Software Foundation; either version 3 of the License, or
79fe24f8a2Smrg# (at your option) any later version.
80fe24f8a2Smrg
81fe24f8a2Smrg# As a special exception to the GNU General Public License, if you distribute
82fe24f8a2Smrg# this file as part of a program or library that is built using GNU Libtool,
83fe24f8a2Smrg# you may include this file under the same distribution terms that you use
84fe24f8a2Smrg# for the rest of that program.
85fe24f8a2Smrg
86fe24f8a2Smrg# This program is distributed in the hope that it will be useful,
87fe24f8a2Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
88fe24f8a2Smrg# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
89fe24f8a2Smrg# General Public License for more details.
90fe24f8a2Smrg
91fe24f8a2Smrg# You should have received a copy of the GNU General Public License
92fe24f8a2Smrg# along with this program. If not, see <http://www.gnu.org/licenses/>.
93fe24f8a2Smrg
94fe24f8a2Smrg# Please report bugs or propose patches to gary@gnu.org.
95fe24f8a2Smrg
96fe24f8a2Smrg
97fe24f8a2Smrg## ------ ##
98fe24f8a2Smrg## Usage. ##
99fe24f8a2Smrg## ------ ##
100fe24f8a2Smrg
101fe24f8a2Smrg# Evaluate this file near the top of your script to gain access to
102fe24f8a2Smrg# the functions and variables defined here:
103fe24f8a2Smrg#
104fe24f8a2Smrg#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
105fe24f8a2Smrg#
106fe24f8a2Smrg# If you need to override any of the default environment variable
107fe24f8a2Smrg# settings, do that before evaluating this file.
108fe24f8a2Smrg
109fe24f8a2Smrg
110fe24f8a2Smrg## -------------------- ##
111fe24f8a2Smrg## Shell normalisation. ##
112fe24f8a2Smrg## -------------------- ##
113fe24f8a2Smrg
114fe24f8a2Smrg# Some shells need a little help to be as Bourne compatible as possible.
115fe24f8a2Smrg# Before doing anything else, make sure all that help has been provided!
116fe24f8a2Smrg
117fe24f8a2SmrgDUALCASE=1; export DUALCASE # for MKS sh
118fe24f8a2Smrgif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
119ee3138f1Smrg  emulate sh
120ee3138f1Smrg  NULLCMD=:
121fe24f8a2Smrg  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
122ee3138f1Smrg  # is contrary to our usage.  Disable this feature.
123ee3138f1Smrg  alias -g '${1+"$@"}'='"$@"'
124ee3138f1Smrg  setopt NO_GLOB_SUBST
125ee3138f1Smrgelse
126fe24f8a2Smrg  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
127ee3138f1Smrgfi
128b425557eSmrg
129fe24f8a2Smrg# NLS nuisances: We save the old values in case they are required later.
130fe24f8a2Smrg_G_user_locale=
131fe24f8a2Smrg_G_safe_locale=
132fe24f8a2Smrgfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
133ee3138f1Smrgdo
134fe24f8a2Smrg  eval "if test set = \"\${$_G_var+set}\"; then
135fe24f8a2Smrg          save_$_G_var=\$$_G_var
136fe24f8a2Smrg          $_G_var=C
137fe24f8a2Smrg	  export $_G_var
138fe24f8a2Smrg	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
139fe24f8a2Smrg	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
140ee3138f1Smrg	fi"
141ee3138f1Smrgdone
142ee3138f1Smrg
143fe24f8a2Smrg# CDPATH.
144fe24f8a2Smrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
14534977a2fSmrg
146fe24f8a2Smrg# Make sure IFS has a sensible default
147fe24f8a2Smrgsp=' '
148fe24f8a2Smrgnl='
149fe24f8a2Smrg'
150fe24f8a2SmrgIFS="$sp	$nl"
151fe24f8a2Smrg
152fe24f8a2Smrg# There are apparently some retarded systems that use ';' as a PATH separator!
153fe24f8a2Smrgif test "${PATH_SEPARATOR+set}" != set; then
154fe24f8a2Smrg  PATH_SEPARATOR=:
155fe24f8a2Smrg  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
156fe24f8a2Smrg    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
157fe24f8a2Smrg      PATH_SEPARATOR=';'
158fe24f8a2Smrg  }
159fe24f8a2Smrgfi
16034977a2fSmrg
16134977a2fSmrg
16234977a2fSmrg
163fe24f8a2Smrg## ------------------------- ##
164fe24f8a2Smrg## Locate command utilities. ##
165fe24f8a2Smrg## ------------------------- ##
166fe24f8a2Smrg
167fe24f8a2Smrg
168fe24f8a2Smrg# func_executable_p FILE
169fe24f8a2Smrg# ----------------------
170fe24f8a2Smrg# Check that FILE is an executable regular file.
171fe24f8a2Smrgfunc_executable_p ()
172fe24f8a2Smrg{
173fe24f8a2Smrg    test -f "$1" && test -x "$1"
174fe24f8a2Smrg}
175fe24f8a2Smrg
176fe24f8a2Smrg
177fe24f8a2Smrg# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
178fe24f8a2Smrg# --------------------------------------------
179fe24f8a2Smrg# Search for either a program that responds to --version with output
180fe24f8a2Smrg# containing "GNU", or else returned by CHECK_FUNC otherwise, by
181fe24f8a2Smrg# trying all the directories in PATH with each of the elements of
182fe24f8a2Smrg# PROGS_LIST.
183fe24f8a2Smrg#
184fe24f8a2Smrg# CHECK_FUNC should accept the path to a candidate program, and
185fe24f8a2Smrg# set $func_check_prog_result if it truncates its output less than
186fe24f8a2Smrg# $_G_path_prog_max characters.
187fe24f8a2Smrgfunc_path_progs ()
188fe24f8a2Smrg{
189fe24f8a2Smrg    _G_progs_list=$1
190fe24f8a2Smrg    _G_check_func=$2
191fe24f8a2Smrg    _G_PATH=${3-"$PATH"}
192fe24f8a2Smrg
193fe24f8a2Smrg    _G_path_prog_max=0
194fe24f8a2Smrg    _G_path_prog_found=false
195fe24f8a2Smrg    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
196fe24f8a2Smrg    for _G_dir in $_G_PATH; do
197fe24f8a2Smrg      IFS=$_G_save_IFS
198fe24f8a2Smrg      test -z "$_G_dir" && _G_dir=.
199fe24f8a2Smrg      for _G_prog_name in $_G_progs_list; do
200fe24f8a2Smrg        for _exeext in '' .EXE; do
201fe24f8a2Smrg          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
202fe24f8a2Smrg          func_executable_p "$_G_path_prog" || continue
203fe24f8a2Smrg          case `"$_G_path_prog" --version 2>&1` in
204fe24f8a2Smrg            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
205fe24f8a2Smrg            *)     $_G_check_func $_G_path_prog
206fe24f8a2Smrg		   func_path_progs_result=$func_check_prog_result
207fe24f8a2Smrg		   ;;
208fe24f8a2Smrg          esac
209fe24f8a2Smrg          $_G_path_prog_found && break 3
210fe24f8a2Smrg        done
211fe24f8a2Smrg      done
212fe24f8a2Smrg    done
213fe24f8a2Smrg    IFS=$_G_save_IFS
214fe24f8a2Smrg    test -z "$func_path_progs_result" && {
215fe24f8a2Smrg      echo "no acceptable sed could be found in \$PATH" >&2
216fe24f8a2Smrg      exit 1
217fe24f8a2Smrg    }
218fe24f8a2Smrg}
219fe24f8a2Smrg
220fe24f8a2Smrg
221fe24f8a2Smrg# We want to be able to use the functions in this file before configure
222fe24f8a2Smrg# has figured out where the best binaries are kept, which means we have
223fe24f8a2Smrg# to search for them ourselves - except when the results are already set
224fe24f8a2Smrg# where we skip the searches.
225fe24f8a2Smrg
226fe24f8a2Smrg# Unless the user overrides by setting SED, search the path for either GNU
227fe24f8a2Smrg# sed, or the sed that truncates its output the least.
228fe24f8a2Smrgtest -z "$SED" && {
229fe24f8a2Smrg  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
230fe24f8a2Smrg  for _G_i in 1 2 3 4 5 6 7; do
231fe24f8a2Smrg    _G_sed_script=$_G_sed_script$nl$_G_sed_script
232fe24f8a2Smrg  done
233fe24f8a2Smrg  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
234fe24f8a2Smrg  _G_sed_script=
235fe24f8a2Smrg
236fe24f8a2Smrg  func_check_prog_sed ()
237fe24f8a2Smrg  {
238fe24f8a2Smrg    _G_path_prog=$1
239fe24f8a2Smrg
240fe24f8a2Smrg    _G_count=0
241fe24f8a2Smrg    printf 0123456789 >conftest.in
242fe24f8a2Smrg    while :
243fe24f8a2Smrg    do
244fe24f8a2Smrg      cat conftest.in conftest.in >conftest.tmp
245fe24f8a2Smrg      mv conftest.tmp conftest.in
246fe24f8a2Smrg      cp conftest.in conftest.nl
247fe24f8a2Smrg      echo '' >> conftest.nl
248fe24f8a2Smrg      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
249fe24f8a2Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
250fe24f8a2Smrg      _G_count=`expr $_G_count + 1`
251fe24f8a2Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
252fe24f8a2Smrg        # Best one so far, save it but keep looking for a better one
253fe24f8a2Smrg        func_check_prog_result=$_G_path_prog
254fe24f8a2Smrg        _G_path_prog_max=$_G_count
255fe24f8a2Smrg      fi
256fe24f8a2Smrg      # 10*(2^10) chars as input seems more than enough
257fe24f8a2Smrg      test 10 -lt "$_G_count" && break
258fe24f8a2Smrg    done
259fe24f8a2Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
260fe24f8a2Smrg  }
261fe24f8a2Smrg
262fe24f8a2Smrg  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
263fe24f8a2Smrg  rm -f conftest.sed
264fe24f8a2Smrg  SED=$func_path_progs_result
265fe24f8a2Smrg}
266fe24f8a2Smrg
267fe24f8a2Smrg
268fe24f8a2Smrg# Unless the user overrides by setting GREP, search the path for either GNU
269fe24f8a2Smrg# grep, or the grep that truncates its output the least.
270fe24f8a2Smrgtest -z "$GREP" && {
271fe24f8a2Smrg  func_check_prog_grep ()
272fe24f8a2Smrg  {
273fe24f8a2Smrg    _G_path_prog=$1
274fe24f8a2Smrg
275fe24f8a2Smrg    _G_count=0
276fe24f8a2Smrg    _G_path_prog_max=0
277fe24f8a2Smrg    printf 0123456789 >conftest.in
278fe24f8a2Smrg    while :
279fe24f8a2Smrg    do
280fe24f8a2Smrg      cat conftest.in conftest.in >conftest.tmp
281fe24f8a2Smrg      mv conftest.tmp conftest.in
282fe24f8a2Smrg      cp conftest.in conftest.nl
283fe24f8a2Smrg      echo 'GREP' >> conftest.nl
284fe24f8a2Smrg      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
285fe24f8a2Smrg      diff conftest.out conftest.nl >/dev/null 2>&1 || break
286fe24f8a2Smrg      _G_count=`expr $_G_count + 1`
287fe24f8a2Smrg      if test "$_G_count" -gt "$_G_path_prog_max"; then
288fe24f8a2Smrg        # Best one so far, save it but keep looking for a better one
289fe24f8a2Smrg        func_check_prog_result=$_G_path_prog
290fe24f8a2Smrg        _G_path_prog_max=$_G_count
291fe24f8a2Smrg      fi
292fe24f8a2Smrg      # 10*(2^10) chars as input seems more than enough
293fe24f8a2Smrg      test 10 -lt "$_G_count" && break
294fe24f8a2Smrg    done
295fe24f8a2Smrg    rm -f conftest.in conftest.tmp conftest.nl conftest.out
296fe24f8a2Smrg  }
297fe24f8a2Smrg
298fe24f8a2Smrg  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
299fe24f8a2Smrg  GREP=$func_path_progs_result
300fe24f8a2Smrg}
301fe24f8a2Smrg
302fe24f8a2Smrg
303fe24f8a2Smrg## ------------------------------- ##
304fe24f8a2Smrg## User overridable command paths. ##
305fe24f8a2Smrg## ------------------------------- ##
306fe24f8a2Smrg
307fe24f8a2Smrg# All uppercase variable names are used for environment variables.  These
308fe24f8a2Smrg# variables can be overridden by the user before calling a script that
309fe24f8a2Smrg# uses them if a suitable command of that name is not already available
310fe24f8a2Smrg# in the command search PATH.
31134977a2fSmrg
31234977a2fSmrg: ${CP="cp -f"}
313fe24f8a2Smrg: ${ECHO="printf %s\n"}
314fe24f8a2Smrg: ${EGREP="$GREP -E"}
315fe24f8a2Smrg: ${FGREP="$GREP -F"}
316fe24f8a2Smrg: ${LN_S="ln -s"}
31734977a2fSmrg: ${MAKE="make"}
31834977a2fSmrg: ${MKDIR="mkdir"}
31934977a2fSmrg: ${MV="mv -f"}
32034977a2fSmrg: ${RM="rm -f"}
32134977a2fSmrg: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
322ee3138f1Smrg
32334977a2fSmrg
324fe24f8a2Smrg## -------------------- ##
325fe24f8a2Smrg## Useful sed snippets. ##
326fe24f8a2Smrg## -------------------- ##
3273e72ca8cSmrg
328fe24f8a2Smrgsed_dirname='s|/[^/]*$||'
329fe24f8a2Smrgsed_basename='s|^.*/||'
3303e72ca8cSmrg
331fe24f8a2Smrg# Sed substitution that helps us do robust quoting.  It backslashifies
332fe24f8a2Smrg# metacharacters that are still active within double-quoted strings.
333fe24f8a2Smrgsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
3343e72ca8cSmrg
335fe24f8a2Smrg# Same as above, but do not quote variable references.
336fe24f8a2Smrgsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
3373e72ca8cSmrg
338fe24f8a2Smrg# Sed substitution that turns a string into a regex matching for the
339fe24f8a2Smrg# string literally.
340fe24f8a2Smrgsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
3413e72ca8cSmrg
342fe24f8a2Smrg# Sed substitution that converts a w32 file name or path
343fe24f8a2Smrg# that contains forward slashes, into one that contains
344fe24f8a2Smrg# (escaped) backslashes.  A very naive implementation.
345fe24f8a2Smrgsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
346fe24f8a2Smrg
347fe24f8a2Smrg# Re-'\' parameter expansions in output of sed_double_quote_subst that
348fe24f8a2Smrg# were '\'-ed in input to the same.  If an odd number of '\' preceded a
349fe24f8a2Smrg# '$' in input to sed_double_quote_subst, that '$' was protected from
350fe24f8a2Smrg# expansion.  Since each input '\' is now two '\'s, look for any number
351fe24f8a2Smrg# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
352fe24f8a2Smrg_G_bs='\\'
353fe24f8a2Smrg_G_bs2='\\\\'
354fe24f8a2Smrg_G_bs4='\\\\\\\\'
355fe24f8a2Smrg_G_dollar='\$'
356fe24f8a2Smrgsed_double_backslash="\
357fe24f8a2Smrg  s/$_G_bs4/&\\
358fe24f8a2Smrg/g
359fe24f8a2Smrg  s/^$_G_bs2$_G_dollar/$_G_bs&/
360fe24f8a2Smrg  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
361fe24f8a2Smrg  s/\n//g"
3623e72ca8cSmrg
363ee3138f1Smrg
364fe24f8a2Smrg## ----------------- ##
365fe24f8a2Smrg## Global variables. ##
366fe24f8a2Smrg## ----------------- ##
36734977a2fSmrg
368fe24f8a2Smrg# Except for the global variables explicitly listed below, the following
369fe24f8a2Smrg# functions in the '^func_' namespace, and the '^require_' namespace
370fe24f8a2Smrg# variables initialised in the 'Resource management' section, sourcing
371fe24f8a2Smrg# this file will not pollute your global namespace with anything
372fe24f8a2Smrg# else. There's no portable way to scope variables in Bourne shell
373fe24f8a2Smrg# though, so actually running these functions will sometimes place
374fe24f8a2Smrg# results into a variable named after the function, and often use
375fe24f8a2Smrg# temporary variables in the '^_G_' namespace. If you are careful to
376fe24f8a2Smrg# avoid using those namespaces casually in your sourcing script, things
377fe24f8a2Smrg# should continue to work as you expect. And, of course, you can freely
378fe24f8a2Smrg# overwrite any of the functions or variables defined here before
379fe24f8a2Smrg# calling anything to customize them.
380b425557eSmrg
381fe24f8a2SmrgEXIT_SUCCESS=0
382fe24f8a2SmrgEXIT_FAILURE=1
383fe24f8a2SmrgEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
384fe24f8a2SmrgEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
385b425557eSmrg
386fe24f8a2Smrg# Allow overriding, eg assuming that you follow the convention of
387fe24f8a2Smrg# putting '$debug_cmd' at the start of all your functions, you can get
388fe24f8a2Smrg# bash to show function call trace with:
389fe24f8a2Smrg#
390fe24f8a2Smrg#    debug_cmd='eval echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
391fe24f8a2Smrgdebug_cmd=${debug_cmd-":"}
392fe24f8a2Smrgexit_cmd=:
393b425557eSmrg
394fe24f8a2Smrg# By convention, finish your script with:
395fe24f8a2Smrg#
396fe24f8a2Smrg#    exit $exit_status
397fe24f8a2Smrg#
398fe24f8a2Smrg# so that you can set exit_status to non-zero if you want to indicate
399fe24f8a2Smrg# something went wrong during execution without actually bailing out at
400fe24f8a2Smrg# the point of failure.
401fe24f8a2Smrgexit_status=$EXIT_SUCCESS
402b425557eSmrg
403fe24f8a2Smrg# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
404fe24f8a2Smrg# is ksh but when the shell is invoked as "sh" and the current value of
405fe24f8a2Smrg# the _XPG environment variable is not equal to 1 (one), the special
406fe24f8a2Smrg# positional parameter $0, within a function call, is the name of the
407fe24f8a2Smrg# function.
408fe24f8a2Smrgprogpath=$0
40934977a2fSmrg
410fe24f8a2Smrg# The name of this program.
411fe24f8a2Smrgprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
41234977a2fSmrg
413fe24f8a2Smrg# Make sure we have an absolute progpath for reexecution:
41434977a2fSmrgcase $progpath in
41534977a2fSmrg  [\\/]*|[A-Za-z]:\\*) ;;
41634977a2fSmrg  *[\\/]*)
417fe24f8a2Smrg     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
41834977a2fSmrg     progdir=`cd "$progdir" && pwd`
419fe24f8a2Smrg     progpath=$progdir/$progname
42034977a2fSmrg     ;;
42134977a2fSmrg  *)
422fe24f8a2Smrg     _G_IFS=$IFS
4233e72ca8cSmrg     IFS=${PATH_SEPARATOR-:}
42434977a2fSmrg     for progdir in $PATH; do
425fe24f8a2Smrg       IFS=$_G_IFS
42634977a2fSmrg       test -x "$progdir/$progname" && break
42734977a2fSmrg     done
428fe24f8a2Smrg     IFS=$_G_IFS
42934977a2fSmrg     test -n "$progdir" || progdir=`pwd`
430fe24f8a2Smrg     progpath=$progdir/$progname
43134977a2fSmrg     ;;
43234977a2fSmrgesac
43334977a2fSmrg
43434977a2fSmrg
435fe24f8a2Smrg## ----------------- ##
436fe24f8a2Smrg## Standard options. ##
437fe24f8a2Smrg## ----------------- ##
4383e72ca8cSmrg
439fe24f8a2Smrg# The following options affect the operation of the functions defined
440fe24f8a2Smrg# below, and should be set appropriately depending on run-time para-
441fe24f8a2Smrg# meters passed on the command line.
44234977a2fSmrg
44334977a2fSmrgopt_dry_run=false
44434977a2fSmrgopt_quiet=false
44534977a2fSmrgopt_verbose=false
44634977a2fSmrg
447fe24f8a2Smrg# Categories 'all' and 'none' are always available.  Append any others
448fe24f8a2Smrg# you will pass as the first argument to func_warning from your own
449fe24f8a2Smrg# code.
450fe24f8a2Smrgwarning_categories=
45134977a2fSmrg
452fe24f8a2Smrg# By default, display warnings according to 'opt_warning_types'.  Set
453fe24f8a2Smrg# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
454fe24f8a2Smrg# treat the next displayed warning as a fatal error.
455fe24f8a2Smrgwarning_func=func_warn_and_continue
45634977a2fSmrg
457fe24f8a2Smrg# Set to 'all' to display all warnings, 'none' to suppress all
458fe24f8a2Smrg# warnings, or a space delimited list of some subset of
459fe24f8a2Smrg# 'warning_categories' to display only the listed warnings.
460fe24f8a2Smrgopt_warning_types=all
46134977a2fSmrg
462b425557eSmrg
463fe24f8a2Smrg## -------------------- ##
464fe24f8a2Smrg## Resource management. ##
465fe24f8a2Smrg## -------------------- ##
46634977a2fSmrg
467fe24f8a2Smrg# This section contains definitions for functions that each ensure a
468fe24f8a2Smrg# particular resource (a file, or a non-empty configuration variable for
469fe24f8a2Smrg# example) is available, and if appropriate to extract default values
470fe24f8a2Smrg# from pertinent package files. Call them using their associated
471fe24f8a2Smrg# 'require_*' variable to ensure that they are executed, at most, once.
472fe24f8a2Smrg#
473fe24f8a2Smrg# It's entirely deliberate that calling these functions can set
474fe24f8a2Smrg# variables that don't obey the namespace limitations obeyed by the rest
475fe24f8a2Smrg# of this file, in order that that they be as useful as possible to
476fe24f8a2Smrg# callers.
47734977a2fSmrg
47834977a2fSmrg
479fe24f8a2Smrg# require_term_colors
480fe24f8a2Smrg# -------------------
481fe24f8a2Smrg# Allow display of bold text on terminals that support it.
482fe24f8a2Smrgrequire_term_colors=func_require_term_colors
483fe24f8a2Smrgfunc_require_term_colors ()
48434977a2fSmrg{
485fe24f8a2Smrg    $debug_cmd
486fe24f8a2Smrg
487fe24f8a2Smrg    test -t 1 && {
488fe24f8a2Smrg      # COLORTERM and USE_ANSI_COLORS environment variables take
489fe24f8a2Smrg      # precedence, because most terminfo databases neglect to describe
490fe24f8a2Smrg      # whether color sequences are supported.
491fe24f8a2Smrg      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
492fe24f8a2Smrg
493fe24f8a2Smrg      if test 1 = "$USE_ANSI_COLORS"; then
494fe24f8a2Smrg        # Standard ANSI escape sequences
495fe24f8a2Smrg        tc_reset='[0m'
496fe24f8a2Smrg        tc_bold='[1m';   tc_standout='[7m'
497fe24f8a2Smrg        tc_red='[31m';   tc_green='[32m'
498fe24f8a2Smrg        tc_blue='[34m';  tc_cyan='[36m'
499fe24f8a2Smrg      else
500fe24f8a2Smrg        # Otherwise trust the terminfo database after all.
501fe24f8a2Smrg        test -n "`tput sgr0 2>/dev/null`" && {
502fe24f8a2Smrg          tc_reset=`tput sgr0`
503fe24f8a2Smrg          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
504fe24f8a2Smrg          tc_standout=$tc_bold
505fe24f8a2Smrg          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
506fe24f8a2Smrg          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
507fe24f8a2Smrg          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
508fe24f8a2Smrg          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
509fe24f8a2Smrg          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
510fe24f8a2Smrg        }
511fe24f8a2Smrg      fi
512fe24f8a2Smrg    }
51334977a2fSmrg
514fe24f8a2Smrg    require_term_colors=:
51534977a2fSmrg}
51634977a2fSmrg
51734977a2fSmrg
518fe24f8a2Smrg## ----------------- ##
519fe24f8a2Smrg## Function library. ##
520fe24f8a2Smrg## ----------------- ##
521fe24f8a2Smrg
522fe24f8a2Smrg# This section contains a variety of useful functions to call in your
523fe24f8a2Smrg# scripts. Take note of the portable wrappers for features provided by
524fe24f8a2Smrg# some modern shells, which will fall back to slower equivalents on
525fe24f8a2Smrg# less featureful shells.
526fe24f8a2Smrg
527fe24f8a2Smrg
528fe24f8a2Smrg# func_append VAR VALUE
529fe24f8a2Smrg# ---------------------
530fe24f8a2Smrg# Append VALUE onto the existing contents of VAR.
531fe24f8a2Smrg
532fe24f8a2Smrg  # We should try to minimise forks, especially on Windows where they are
533fe24f8a2Smrg  # unreasonably slow, so skip the feature probes when bash or zsh are
534fe24f8a2Smrg  # being used:
535fe24f8a2Smrg  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
536fe24f8a2Smrg    : ${_G_HAVE_ARITH_OP="yes"}
537fe24f8a2Smrg    : ${_G_HAVE_XSI_OPS="yes"}
538fe24f8a2Smrg    # The += operator was introduced in bash 3.1
539fe24f8a2Smrg    case $BASH_VERSION in
540fe24f8a2Smrg      [12].* | 3.0 | 3.0*) ;;
541fe24f8a2Smrg      *)
542fe24f8a2Smrg        : ${_G_HAVE_PLUSEQ_OP="yes"}
543fe24f8a2Smrg        ;;
544fe24f8a2Smrg    esac
545fe24f8a2Smrg  fi
546fe24f8a2Smrg
547fe24f8a2Smrg  # _G_HAVE_PLUSEQ_OP
548fe24f8a2Smrg  # Can be empty, in which case the shell is probed, "yes" if += is
549fe24f8a2Smrg  # useable or anything else if it does not work.
550fe24f8a2Smrg  test -z "$_G_HAVE_PLUSEQ_OP" \
551fe24f8a2Smrg    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
552fe24f8a2Smrg    && _G_HAVE_PLUSEQ_OP=yes
553fe24f8a2Smrg
554fe24f8a2Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"
555fe24f8a2Smrgthen
556fe24f8a2Smrg  # This is an XSI compatible shell, allowing a faster implementation...
557fe24f8a2Smrg  eval 'func_append ()
558fe24f8a2Smrg  {
559fe24f8a2Smrg    $debug_cmd
560fe24f8a2Smrg
561fe24f8a2Smrg    eval "$1+=\$2"
562fe24f8a2Smrg  }'
563fe24f8a2Smrgelse
564fe24f8a2Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
565fe24f8a2Smrg  func_append ()
566fe24f8a2Smrg  {
567fe24f8a2Smrg    $debug_cmd
568fe24f8a2Smrg
569fe24f8a2Smrg    eval "$1=\$$1\$2"
570fe24f8a2Smrg  }
571fe24f8a2Smrgfi
572fe24f8a2Smrg
573fe24f8a2Smrg
574fe24f8a2Smrg# func_append_quoted VAR VALUE
575fe24f8a2Smrg# ----------------------------
576fe24f8a2Smrg# Quote VALUE and append to the end of shell variable VAR, separated
577fe24f8a2Smrg# by a space.
578fe24f8a2Smrgif test yes = "$_G_HAVE_PLUSEQ_OP"; then
579fe24f8a2Smrg  eval 'func_append_quoted ()
580fe24f8a2Smrg  {
581fe24f8a2Smrg    $debug_cmd
582fe24f8a2Smrg
583fe24f8a2Smrg    func_quote_for_eval "$2"
584fe24f8a2Smrg    eval "$1+=\\ \$func_quote_for_eval_result"
585fe24f8a2Smrg  }'
586fe24f8a2Smrgelse
587fe24f8a2Smrg  func_append_quoted ()
588fe24f8a2Smrg  {
589fe24f8a2Smrg    $debug_cmd
590fe24f8a2Smrg
591fe24f8a2Smrg    func_quote_for_eval "$2"
592fe24f8a2Smrg    eval "$1=\$$1\\ \$func_quote_for_eval_result"
593fe24f8a2Smrg  }
594fe24f8a2Smrgfi
595fe24f8a2Smrg
596fe24f8a2Smrg
597fe24f8a2Smrg# func_append_uniq VAR VALUE
598fe24f8a2Smrg# --------------------------
599fe24f8a2Smrg# Append unique VALUE onto the existing contents of VAR, assuming
600fe24f8a2Smrg# entries are delimited by the first character of VALUE.  For example:
601fe24f8a2Smrg#
602fe24f8a2Smrg#   func_append_uniq options " --another-option option-argument"
603fe24f8a2Smrg#
604fe24f8a2Smrg# will only append to $options if " --another-option option-argument "
605fe24f8a2Smrg# is not already present somewhere in $options already (note spaces at
606fe24f8a2Smrg# each end implied by leading space in second argument).
607fe24f8a2Smrgfunc_append_uniq ()
608fe24f8a2Smrg{
609fe24f8a2Smrg    $debug_cmd
610fe24f8a2Smrg
611fe24f8a2Smrg    eval _G_current_value='`$ECHO $'$1'`'
612fe24f8a2Smrg    _G_delim=`expr "$2" : '\(.\)'`
613fe24f8a2Smrg
614fe24f8a2Smrg    case $_G_delim$_G_current_value$_G_delim in
615fe24f8a2Smrg      *"$2$_G_delim"*) ;;
616fe24f8a2Smrg      *) func_append "$@" ;;
617fe24f8a2Smrg    esac
618fe24f8a2Smrg}
619fe24f8a2Smrg
620fe24f8a2Smrg
621fe24f8a2Smrg# func_arith TERM...
622fe24f8a2Smrg# ------------------
623fe24f8a2Smrg# Set func_arith_result to the result of evaluating TERMs.
624fe24f8a2Smrg  test -z "$_G_HAVE_ARITH_OP" \
625fe24f8a2Smrg    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
626fe24f8a2Smrg    && _G_HAVE_ARITH_OP=yes
627fe24f8a2Smrg
628fe24f8a2Smrgif test yes = "$_G_HAVE_ARITH_OP"; then
629fe24f8a2Smrg  eval 'func_arith ()
630fe24f8a2Smrg  {
631fe24f8a2Smrg    $debug_cmd
632fe24f8a2Smrg
633fe24f8a2Smrg    func_arith_result=$(( $* ))
634fe24f8a2Smrg  }'
635fe24f8a2Smrgelse
636fe24f8a2Smrg  func_arith ()
637fe24f8a2Smrg  {
638fe24f8a2Smrg    $debug_cmd
639fe24f8a2Smrg
640fe24f8a2Smrg    func_arith_result=`expr "$@"`
641fe24f8a2Smrg  }
642fe24f8a2Smrgfi
643fe24f8a2Smrg
644fe24f8a2Smrg
645fe24f8a2Smrg# func_basename FILE
646fe24f8a2Smrg# ------------------
647fe24f8a2Smrg# Set func_basename_result to FILE with everything up to and including
648fe24f8a2Smrg# the last / stripped.
649fe24f8a2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
650fe24f8a2Smrg  # If this shell supports suffix pattern removal, then use it to avoid
651fe24f8a2Smrg  # forking. Hide the definitions single quotes in case the shell chokes
652fe24f8a2Smrg  # on unsupported syntax...
653fe24f8a2Smrg  _b='func_basename_result=${1##*/}'
654fe24f8a2Smrg  _d='case $1 in
655fe24f8a2Smrg        */*) func_dirname_result=${1%/*}$2 ;;
656fe24f8a2Smrg        *  ) func_dirname_result=$3        ;;
657fe24f8a2Smrg      esac'
658fe24f8a2Smrg
659fe24f8a2Smrgelse
660fe24f8a2Smrg  # ...otherwise fall back to using sed.
661fe24f8a2Smrg  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
662fe24f8a2Smrg  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
663fe24f8a2Smrg      if test "X$func_dirname_result" = "X$1"; then
664fe24f8a2Smrg        func_dirname_result=$3
665fe24f8a2Smrg      else
666fe24f8a2Smrg        func_append func_dirname_result "$2"
667fe24f8a2Smrg      fi'
668fe24f8a2Smrgfi
669fe24f8a2Smrg
670fe24f8a2Smrgeval 'func_basename ()
671fe24f8a2Smrg{
672fe24f8a2Smrg    $debug_cmd
673fe24f8a2Smrg
674fe24f8a2Smrg    '"$_b"'
675fe24f8a2Smrg}'
676fe24f8a2Smrg
677fe24f8a2Smrg
678fe24f8a2Smrg# func_dirname FILE APPEND NONDIR_REPLACEMENT
679fe24f8a2Smrg# -------------------------------------------
680fe24f8a2Smrg# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
681fe24f8a2Smrg# otherwise set result to NONDIR_REPLACEMENT.
682fe24f8a2Smrgeval 'func_dirname ()
683fe24f8a2Smrg{
684fe24f8a2Smrg    $debug_cmd
685fe24f8a2Smrg
686fe24f8a2Smrg    '"$_d"'
687fe24f8a2Smrg}'
688fe24f8a2Smrg
689fe24f8a2Smrg
690fe24f8a2Smrg# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
691fe24f8a2Smrg# --------------------------------------------------------
692fe24f8a2Smrg# Perform func_basename and func_dirname in a single function
693fe24f8a2Smrg# call:
694fe24f8a2Smrg#   dirname:  Compute the dirname of FILE.  If nonempty,
695fe24f8a2Smrg#             add APPEND to the result, otherwise set result
696fe24f8a2Smrg#             to NONDIR_REPLACEMENT.
697fe24f8a2Smrg#             value returned in "$func_dirname_result"
698fe24f8a2Smrg#   basename: Compute filename of FILE.
699fe24f8a2Smrg#             value retuned in "$func_basename_result"
700fe24f8a2Smrg# For efficiency, we do not delegate to the functions above but instead
701fe24f8a2Smrg# duplicate the functionality here.
702fe24f8a2Smrgeval 'func_dirname_and_basename ()
703fe24f8a2Smrg{
704fe24f8a2Smrg    $debug_cmd
705fe24f8a2Smrg
706fe24f8a2Smrg    '"$_b"'
707fe24f8a2Smrg    '"$_d"'
708fe24f8a2Smrg}'
709fe24f8a2Smrg
710fe24f8a2Smrg
711fe24f8a2Smrg# func_echo ARG...
712fe24f8a2Smrg# ----------------
713fe24f8a2Smrg# Echo program name prefixed message.
714fe24f8a2Smrgfunc_echo ()
715fe24f8a2Smrg{
716fe24f8a2Smrg    $debug_cmd
717fe24f8a2Smrg
718fe24f8a2Smrg    _G_message=$*
719fe24f8a2Smrg
720fe24f8a2Smrg    func_echo_IFS=$IFS
721fe24f8a2Smrg    IFS=$nl
722fe24f8a2Smrg    for _G_line in $_G_message; do
723fe24f8a2Smrg      IFS=$func_echo_IFS
724fe24f8a2Smrg      $ECHO "$progname: $_G_line"
725fe24f8a2Smrg    done
726fe24f8a2Smrg    IFS=$func_echo_IFS
727fe24f8a2Smrg}
728fe24f8a2Smrg
729fe24f8a2Smrg
730fe24f8a2Smrg# func_echo_all ARG...
731fe24f8a2Smrg# --------------------
732fe24f8a2Smrg# Invoke $ECHO with all args, space-separated.
733fe24f8a2Smrgfunc_echo_all ()
734fe24f8a2Smrg{
735fe24f8a2Smrg    $ECHO "$*"
736fe24f8a2Smrg}
737fe24f8a2Smrg
738fe24f8a2Smrg
739fe24f8a2Smrg# func_echo_infix_1 INFIX ARG...
740fe24f8a2Smrg# ------------------------------
741fe24f8a2Smrg# Echo program name, followed by INFIX on the first line, with any
742fe24f8a2Smrg# additional lines not showing INFIX.
743fe24f8a2Smrgfunc_echo_infix_1 ()
744fe24f8a2Smrg{
745fe24f8a2Smrg    $debug_cmd
746fe24f8a2Smrg
747fe24f8a2Smrg    $require_term_colors
748fe24f8a2Smrg
749fe24f8a2Smrg    _G_infix=$1; shift
750fe24f8a2Smrg    _G_indent=$_G_infix
751fe24f8a2Smrg    _G_prefix="$progname: $_G_infix: "
752fe24f8a2Smrg    _G_message=$*
753fe24f8a2Smrg
754fe24f8a2Smrg    # Strip color escape sequences before counting printable length
755fe24f8a2Smrg    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
756fe24f8a2Smrg    do
757fe24f8a2Smrg      test -n "$_G_tc" && {
758fe24f8a2Smrg        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
759fe24f8a2Smrg        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
760fe24f8a2Smrg      }
761fe24f8a2Smrg    done
762fe24f8a2Smrg    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
763fe24f8a2Smrg
764fe24f8a2Smrg    func_echo_infix_1_IFS=$IFS
765fe24f8a2Smrg    IFS=$nl
766fe24f8a2Smrg    for _G_line in $_G_message; do
767fe24f8a2Smrg      IFS=$func_echo_infix_1_IFS
768fe24f8a2Smrg      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
769fe24f8a2Smrg      _G_prefix=$_G_indent
770fe24f8a2Smrg    done
771fe24f8a2Smrg    IFS=$func_echo_infix_1_IFS
772fe24f8a2Smrg}
773fe24f8a2Smrg
774fe24f8a2Smrg
775fe24f8a2Smrg# func_error ARG...
776fe24f8a2Smrg# -----------------
777fe24f8a2Smrg# Echo program name prefixed message to standard error.
778fe24f8a2Smrgfunc_error ()
779fe24f8a2Smrg{
780fe24f8a2Smrg    $debug_cmd
781fe24f8a2Smrg
782fe24f8a2Smrg    $require_term_colors
783fe24f8a2Smrg
784fe24f8a2Smrg    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
785fe24f8a2Smrg}
786fe24f8a2Smrg
787fe24f8a2Smrg
788fe24f8a2Smrg# func_fatal_error ARG...
789fe24f8a2Smrg# -----------------------
790fe24f8a2Smrg# Echo program name prefixed message to standard error, and exit.
791fe24f8a2Smrgfunc_fatal_error ()
792fe24f8a2Smrg{
793fe24f8a2Smrg    $debug_cmd
794fe24f8a2Smrg
795fe24f8a2Smrg    func_error "$*"
796fe24f8a2Smrg    exit $EXIT_FAILURE
797fe24f8a2Smrg}
798fe24f8a2Smrg
799fe24f8a2Smrg
800fe24f8a2Smrg# func_grep EXPRESSION FILENAME
801fe24f8a2Smrg# -----------------------------
80234977a2fSmrg# Check whether EXPRESSION matches any line of FILENAME, without output.
80334977a2fSmrgfunc_grep ()
80434977a2fSmrg{
805fe24f8a2Smrg    $debug_cmd
806fe24f8a2Smrg
80734977a2fSmrg    $GREP "$1" "$2" >/dev/null 2>&1
80834977a2fSmrg}
80934977a2fSmrg
81034977a2fSmrg
811fe24f8a2Smrg# func_len STRING
812fe24f8a2Smrg# ---------------
813fe24f8a2Smrg# Set func_len_result to the length of STRING. STRING may not
814fe24f8a2Smrg# start with a hyphen.
815fe24f8a2Smrg  test -z "$_G_HAVE_XSI_OPS" \
816fe24f8a2Smrg    && (eval 'x=a/b/c;
817fe24f8a2Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
818fe24f8a2Smrg    && _G_HAVE_XSI_OPS=yes
819fe24f8a2Smrg
820fe24f8a2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
821fe24f8a2Smrg  eval 'func_len ()
822fe24f8a2Smrg  {
823fe24f8a2Smrg    $debug_cmd
824fe24f8a2Smrg
825fe24f8a2Smrg    func_len_result=${#1}
826fe24f8a2Smrg  }'
827fe24f8a2Smrgelse
828fe24f8a2Smrg  func_len ()
829fe24f8a2Smrg  {
830fe24f8a2Smrg    $debug_cmd
831fe24f8a2Smrg
832fe24f8a2Smrg    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
833fe24f8a2Smrg  }
834fe24f8a2Smrgfi
835fe24f8a2Smrg
836fe24f8a2Smrg
837fe24f8a2Smrg# func_mkdir_p DIRECTORY-PATH
838fe24f8a2Smrg# ---------------------------
83934977a2fSmrg# Make sure the entire path to DIRECTORY-PATH is available.
84034977a2fSmrgfunc_mkdir_p ()
84134977a2fSmrg{
842fe24f8a2Smrg    $debug_cmd
84334977a2fSmrg
844fe24f8a2Smrg    _G_directory_path=$1
845fe24f8a2Smrg    _G_dir_list=
84634977a2fSmrg
847fe24f8a2Smrg    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
848fe24f8a2Smrg
849fe24f8a2Smrg      # Protect directory names starting with '-'
850fe24f8a2Smrg      case $_G_directory_path in
851fe24f8a2Smrg        -*) _G_directory_path=./$_G_directory_path ;;
85234977a2fSmrg      esac
85334977a2fSmrg
85434977a2fSmrg      # While some portion of DIR does not yet exist...
855fe24f8a2Smrg      while test ! -d "$_G_directory_path"; do
85634977a2fSmrg        # ...make a list in topmost first order.  Use a colon delimited
85734977a2fSmrg	# list incase some portion of path contains whitespace.
858fe24f8a2Smrg        _G_dir_list=$_G_directory_path:$_G_dir_list
85934977a2fSmrg
86034977a2fSmrg        # If the last portion added has no slash in it, the list is done
861fe24f8a2Smrg        case $_G_directory_path in */*) ;; *) break ;; esac
86234977a2fSmrg
86334977a2fSmrg        # ...otherwise throw away the child directory and loop
864fe24f8a2Smrg        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
86534977a2fSmrg      done
866fe24f8a2Smrg      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
86734977a2fSmrg
868fe24f8a2Smrg      func_mkdir_p_IFS=$IFS; IFS=:
869fe24f8a2Smrg      for _G_dir in $_G_dir_list; do
870fe24f8a2Smrg	IFS=$func_mkdir_p_IFS
871fe24f8a2Smrg        # mkdir can fail with a 'File exist' error if two processes
87234977a2fSmrg        # try to create one of the directories concurrently.  Don't
87334977a2fSmrg        # stop in that case!
874fe24f8a2Smrg        $MKDIR "$_G_dir" 2>/dev/null || :
87534977a2fSmrg      done
876fe24f8a2Smrg      IFS=$func_mkdir_p_IFS
87734977a2fSmrg
87834977a2fSmrg      # Bail out if we (or some other process) failed to create a directory.
879fe24f8a2Smrg      test -d "$_G_directory_path" || \
880fe24f8a2Smrg        func_fatal_error "Failed to create '$1'"
88134977a2fSmrg    fi
88234977a2fSmrg}
883ee3138f1Smrg
884ee3138f1Smrg
885fe24f8a2Smrg# func_mktempdir [BASENAME]
886fe24f8a2Smrg# -------------------------
887ee3138f1Smrg# Make a temporary directory that won't clash with other running
888ee3138f1Smrg# libtool processes, and avoids race conditions if possible.  If
889fe24f8a2Smrg# given, BASENAME is the basename for that directory.
890ee3138f1Smrgfunc_mktempdir ()
891ee3138f1Smrg{
892fe24f8a2Smrg    $debug_cmd
893fe24f8a2Smrg
894fe24f8a2Smrg    _G_template=${TMPDIR-/tmp}/${1-$progname}
895ee3138f1Smrg
896fe24f8a2Smrg    if test : = "$opt_dry_run"; then
897ee3138f1Smrg      # Return a directory name, but don't create it in dry-run mode
898fe24f8a2Smrg      _G_tmpdir=$_G_template-$$
899ee3138f1Smrg    else
900ee3138f1Smrg
901ee3138f1Smrg      # If mktemp works, use that first and foremost
902fe24f8a2Smrg      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
903ee3138f1Smrg
904fe24f8a2Smrg      if test ! -d "$_G_tmpdir"; then
90534977a2fSmrg        # Failing that, at least try and use $RANDOM to avoid a race
906fe24f8a2Smrg        _G_tmpdir=$_G_template-${RANDOM-0}$$
907ee3138f1Smrg
908fe24f8a2Smrg        func_mktempdir_umask=`umask`
90934977a2fSmrg        umask 0077
910fe24f8a2Smrg        $MKDIR "$_G_tmpdir"
911fe24f8a2Smrg        umask $func_mktempdir_umask
912ee3138f1Smrg      fi
913ee3138f1Smrg
914ee3138f1Smrg      # If we're not in dry-run mode, bomb out on failure
915fe24f8a2Smrg      test -d "$_G_tmpdir" || \
916fe24f8a2Smrg        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
917fe24f8a2Smrg    fi
918fe24f8a2Smrg
919fe24f8a2Smrg    $ECHO "$_G_tmpdir"
920fe24f8a2Smrg}
921fe24f8a2Smrg
922fe24f8a2Smrg
923fe24f8a2Smrg# func_normal_abspath PATH
924fe24f8a2Smrg# ------------------------
925fe24f8a2Smrg# Remove doubled-up and trailing slashes, "." path components,
926fe24f8a2Smrg# and cancel out any ".." path components in PATH after making
927fe24f8a2Smrg# it an absolute path.
928fe24f8a2Smrgfunc_normal_abspath ()
929fe24f8a2Smrg{
930fe24f8a2Smrg    $debug_cmd
931fe24f8a2Smrg
932fe24f8a2Smrg    # These SED scripts presuppose an absolute path with a trailing slash.
933fe24f8a2Smrg    _G_pathcar='s|^/\([^/]*\).*$|\1|'
934fe24f8a2Smrg    _G_pathcdr='s|^/[^/]*||'
935fe24f8a2Smrg    _G_removedotparts=':dotsl
936fe24f8a2Smrg		s|/\./|/|g
937fe24f8a2Smrg		t dotsl
938fe24f8a2Smrg		s|/\.$|/|'
939fe24f8a2Smrg    _G_collapseslashes='s|/\{1,\}|/|g'
940fe24f8a2Smrg    _G_finalslash='s|/*$|/|'
941fe24f8a2Smrg
942fe24f8a2Smrg    # Start from root dir and reassemble the path.
943fe24f8a2Smrg    func_normal_abspath_result=
944fe24f8a2Smrg    func_normal_abspath_tpath=$1
945fe24f8a2Smrg    func_normal_abspath_altnamespace=
946fe24f8a2Smrg    case $func_normal_abspath_tpath in
947fe24f8a2Smrg      "")
948fe24f8a2Smrg        # Empty path, that just means $cwd.
949fe24f8a2Smrg        func_stripname '' '/' "`pwd`"
950fe24f8a2Smrg        func_normal_abspath_result=$func_stripname_result
951fe24f8a2Smrg        return
952fe24f8a2Smrg        ;;
953fe24f8a2Smrg      # The next three entries are used to spot a run of precisely
954fe24f8a2Smrg      # two leading slashes without using negated character classes;
955fe24f8a2Smrg      # we take advantage of case's first-match behaviour.
956fe24f8a2Smrg      ///*)
957fe24f8a2Smrg        # Unusual form of absolute path, do nothing.
958fe24f8a2Smrg        ;;
959fe24f8a2Smrg      //*)
960fe24f8a2Smrg        # Not necessarily an ordinary path; POSIX reserves leading '//'
961fe24f8a2Smrg        # and for example Cygwin uses it to access remote file shares
962fe24f8a2Smrg        # over CIFS/SMB, so we conserve a leading double slash if found.
963fe24f8a2Smrg        func_normal_abspath_altnamespace=/
964fe24f8a2Smrg        ;;
965fe24f8a2Smrg      /*)
966fe24f8a2Smrg        # Absolute path, do nothing.
967fe24f8a2Smrg        ;;
968fe24f8a2Smrg      *)
969fe24f8a2Smrg        # Relative path, prepend $cwd.
970fe24f8a2Smrg        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
971fe24f8a2Smrg        ;;
972fe24f8a2Smrg    esac
973fe24f8a2Smrg
974fe24f8a2Smrg    # Cancel out all the simple stuff to save iterations.  We also want
975fe24f8a2Smrg    # the path to end with a slash for ease of parsing, so make sure
976fe24f8a2Smrg    # there is one (and only one) here.
977fe24f8a2Smrg    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
978fe24f8a2Smrg          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
979fe24f8a2Smrg    while :; do
980fe24f8a2Smrg      # Processed it all yet?
981fe24f8a2Smrg      if test / = "$func_normal_abspath_tpath"; then
982fe24f8a2Smrg        # If we ascended to the root using ".." the result may be empty now.
983fe24f8a2Smrg        if test -z "$func_normal_abspath_result"; then
984fe24f8a2Smrg          func_normal_abspath_result=/
985fe24f8a2Smrg        fi
986fe24f8a2Smrg        break
987fe24f8a2Smrg      fi
988fe24f8a2Smrg      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
989fe24f8a2Smrg          -e "$_G_pathcar"`
990fe24f8a2Smrg      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
991fe24f8a2Smrg          -e "$_G_pathcdr"`
992fe24f8a2Smrg      # Figure out what to do with it
993fe24f8a2Smrg      case $func_normal_abspath_tcomponent in
994fe24f8a2Smrg        "")
995fe24f8a2Smrg          # Trailing empty path component, ignore it.
996fe24f8a2Smrg          ;;
997fe24f8a2Smrg        ..)
998fe24f8a2Smrg          # Parent dir; strip last assembled component from result.
999fe24f8a2Smrg          func_dirname "$func_normal_abspath_result"
1000fe24f8a2Smrg          func_normal_abspath_result=$func_dirname_result
1001fe24f8a2Smrg          ;;
1002fe24f8a2Smrg        *)
1003fe24f8a2Smrg          # Actual path component, append it.
1004fe24f8a2Smrg          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
1005fe24f8a2Smrg          ;;
1006fe24f8a2Smrg      esac
1007fe24f8a2Smrg    done
1008fe24f8a2Smrg    # Restore leading double-slash if one was found on entry.
1009fe24f8a2Smrg    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
1010fe24f8a2Smrg}
1011fe24f8a2Smrg
1012fe24f8a2Smrg
1013fe24f8a2Smrg# func_notquiet ARG...
1014fe24f8a2Smrg# --------------------
1015fe24f8a2Smrg# Echo program name prefixed message only when not in quiet mode.
1016fe24f8a2Smrgfunc_notquiet ()
1017fe24f8a2Smrg{
1018fe24f8a2Smrg    $debug_cmd
1019fe24f8a2Smrg
1020fe24f8a2Smrg    $opt_quiet || func_echo ${1+"$@"}
1021fe24f8a2Smrg
1022fe24f8a2Smrg    # A bug in bash halts the script if the last line of a function
1023fe24f8a2Smrg    # fails when set -e is in force, so we need another command to
1024fe24f8a2Smrg    # work around that:
1025fe24f8a2Smrg    :
1026fe24f8a2Smrg}
1027fe24f8a2Smrg
1028fe24f8a2Smrg
1029fe24f8a2Smrg# func_relative_path SRCDIR DSTDIR
1030fe24f8a2Smrg# --------------------------------
1031fe24f8a2Smrg# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
1032fe24f8a2Smrgfunc_relative_path ()
1033fe24f8a2Smrg{
1034fe24f8a2Smrg    $debug_cmd
1035fe24f8a2Smrg
1036fe24f8a2Smrg    func_relative_path_result=
1037fe24f8a2Smrg    func_normal_abspath "$1"
1038fe24f8a2Smrg    func_relative_path_tlibdir=$func_normal_abspath_result
1039fe24f8a2Smrg    func_normal_abspath "$2"
1040fe24f8a2Smrg    func_relative_path_tbindir=$func_normal_abspath_result
1041fe24f8a2Smrg
1042fe24f8a2Smrg    # Ascend the tree starting from libdir
1043fe24f8a2Smrg    while :; do
1044fe24f8a2Smrg      # check if we have found a prefix of bindir
1045fe24f8a2Smrg      case $func_relative_path_tbindir in
1046fe24f8a2Smrg        $func_relative_path_tlibdir)
1047fe24f8a2Smrg          # found an exact match
1048fe24f8a2Smrg          func_relative_path_tcancelled=
1049fe24f8a2Smrg          break
1050fe24f8a2Smrg          ;;
1051fe24f8a2Smrg        $func_relative_path_tlibdir*)
1052fe24f8a2Smrg          # found a matching prefix
1053fe24f8a2Smrg          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
1054fe24f8a2Smrg          func_relative_path_tcancelled=$func_stripname_result
1055fe24f8a2Smrg          if test -z "$func_relative_path_result"; then
1056fe24f8a2Smrg            func_relative_path_result=.
1057fe24f8a2Smrg          fi
1058fe24f8a2Smrg          break
1059fe24f8a2Smrg          ;;
1060fe24f8a2Smrg        *)
1061fe24f8a2Smrg          func_dirname $func_relative_path_tlibdir
1062fe24f8a2Smrg          func_relative_path_tlibdir=$func_dirname_result
1063fe24f8a2Smrg          if test -z "$func_relative_path_tlibdir"; then
1064fe24f8a2Smrg            # Have to descend all the way to the root!
1065fe24f8a2Smrg            func_relative_path_result=../$func_relative_path_result
1066fe24f8a2Smrg            func_relative_path_tcancelled=$func_relative_path_tbindir
1067fe24f8a2Smrg            break
1068fe24f8a2Smrg          fi
1069fe24f8a2Smrg          func_relative_path_result=../$func_relative_path_result
1070fe24f8a2Smrg          ;;
1071fe24f8a2Smrg      esac
1072fe24f8a2Smrg    done
1073fe24f8a2Smrg
1074fe24f8a2Smrg    # Now calculate path; take care to avoid doubling-up slashes.
1075fe24f8a2Smrg    func_stripname '' '/' "$func_relative_path_result"
1076fe24f8a2Smrg    func_relative_path_result=$func_stripname_result
1077fe24f8a2Smrg    func_stripname '/' '/' "$func_relative_path_tcancelled"
1078fe24f8a2Smrg    if test -n "$func_stripname_result"; then
1079fe24f8a2Smrg      func_append func_relative_path_result "/$func_stripname_result"
1080fe24f8a2Smrg    fi
1081fe24f8a2Smrg
1082fe24f8a2Smrg    # Normalisation. If bindir is libdir, return '.' else relative path.
1083fe24f8a2Smrg    if test -n "$func_relative_path_result"; then
1084fe24f8a2Smrg      func_stripname './' '' "$func_relative_path_result"
1085fe24f8a2Smrg      func_relative_path_result=$func_stripname_result
1086ee3138f1Smrg    fi
1087ee3138f1Smrg
1088fe24f8a2Smrg    test -n "$func_relative_path_result" || func_relative_path_result=.
1089fe24f8a2Smrg
1090fe24f8a2Smrg    :
1091fe24f8a2Smrg}
1092fe24f8a2Smrg
1093fe24f8a2Smrg
1094fe24f8a2Smrg# func_quote_for_eval ARG...
1095fe24f8a2Smrg# --------------------------
1096fe24f8a2Smrg# Aesthetically quote ARGs to be evaled later.
1097fe24f8a2Smrg# This function returns two values:
1098fe24f8a2Smrg#   i) func_quote_for_eval_result
1099fe24f8a2Smrg#      double-quoted, suitable for a subsequent eval
1100fe24f8a2Smrg#  ii) func_quote_for_eval_unquoted_result
1101fe24f8a2Smrg#      has all characters that are still active within double
1102fe24f8a2Smrg#      quotes backslashified.
1103fe24f8a2Smrgfunc_quote_for_eval ()
1104fe24f8a2Smrg{
1105fe24f8a2Smrg    $debug_cmd
1106fe24f8a2Smrg
1107fe24f8a2Smrg    func_quote_for_eval_unquoted_result=
1108fe24f8a2Smrg    func_quote_for_eval_result=
1109fe24f8a2Smrg    while test 0 -lt $#; do
1110fe24f8a2Smrg      case $1 in
1111fe24f8a2Smrg        *[\\\`\"\$]*)
1112fe24f8a2Smrg	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
1113fe24f8a2Smrg        *)
1114fe24f8a2Smrg          _G_unquoted_arg=$1 ;;
1115fe24f8a2Smrg      esac
1116fe24f8a2Smrg      if test -n "$func_quote_for_eval_unquoted_result"; then
1117fe24f8a2Smrg	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
1118fe24f8a2Smrg      else
1119fe24f8a2Smrg        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
1120fe24f8a2Smrg      fi
1121fe24f8a2Smrg
1122fe24f8a2Smrg      case $_G_unquoted_arg in
1123fe24f8a2Smrg        # Double-quote args containing shell metacharacters to delay
1124fe24f8a2Smrg        # word splitting, command substitution and variable expansion
1125fe24f8a2Smrg        # for a subsequent eval.
1126fe24f8a2Smrg        # Many Bourne shells cannot handle close brackets correctly
1127fe24f8a2Smrg        # in scan sets, so we specify it separately.
1128fe24f8a2Smrg        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1129fe24f8a2Smrg          _G_quoted_arg=\"$_G_unquoted_arg\"
1130fe24f8a2Smrg          ;;
1131fe24f8a2Smrg        *)
1132fe24f8a2Smrg          _G_quoted_arg=$_G_unquoted_arg
1133fe24f8a2Smrg	  ;;
1134fe24f8a2Smrg      esac
1135fe24f8a2Smrg
1136fe24f8a2Smrg      if test -n "$func_quote_for_eval_result"; then
1137fe24f8a2Smrg	func_append func_quote_for_eval_result " $_G_quoted_arg"
1138fe24f8a2Smrg      else
1139fe24f8a2Smrg        func_append func_quote_for_eval_result "$_G_quoted_arg"
1140fe24f8a2Smrg      fi
1141fe24f8a2Smrg      shift
1142fe24f8a2Smrg    done
1143fe24f8a2Smrg}
1144fe24f8a2Smrg
1145fe24f8a2Smrg
1146fe24f8a2Smrg# func_quote_for_expand ARG
1147fe24f8a2Smrg# -------------------------
1148fe24f8a2Smrg# Aesthetically quote ARG to be evaled later; same as above,
1149fe24f8a2Smrg# but do not quote variable references.
1150fe24f8a2Smrgfunc_quote_for_expand ()
1151fe24f8a2Smrg{
1152fe24f8a2Smrg    $debug_cmd
1153fe24f8a2Smrg
1154fe24f8a2Smrg    case $1 in
1155fe24f8a2Smrg      *[\\\`\"]*)
1156fe24f8a2Smrg	_G_arg=`$ECHO "$1" | $SED \
1157fe24f8a2Smrg	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
1158fe24f8a2Smrg      *)
1159fe24f8a2Smrg        _G_arg=$1 ;;
1160fe24f8a2Smrg    esac
1161fe24f8a2Smrg
1162fe24f8a2Smrg    case $_G_arg in
1163fe24f8a2Smrg      # Double-quote args containing shell metacharacters to delay
1164fe24f8a2Smrg      # word splitting and command substitution for a subsequent eval.
1165fe24f8a2Smrg      # Many Bourne shells cannot handle close brackets correctly
1166fe24f8a2Smrg      # in scan sets, so we specify it separately.
1167fe24f8a2Smrg      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1168fe24f8a2Smrg        _G_arg=\"$_G_arg\"
1169fe24f8a2Smrg        ;;
1170fe24f8a2Smrg    esac
1171fe24f8a2Smrg
1172fe24f8a2Smrg    func_quote_for_expand_result=$_G_arg
1173fe24f8a2Smrg}
1174fe24f8a2Smrg
1175fe24f8a2Smrg
1176fe24f8a2Smrg# func_stripname PREFIX SUFFIX NAME
1177fe24f8a2Smrg# ---------------------------------
1178fe24f8a2Smrg# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1179fe24f8a2Smrg# PREFIX and SUFFIX must not contain globbing or regex special
1180fe24f8a2Smrg# characters, hashes, percent signs, but SUFFIX may contain a leading
1181fe24f8a2Smrg# dot (in which case that matches only a dot).
1182fe24f8a2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
1183fe24f8a2Smrg  eval 'func_stripname ()
1184fe24f8a2Smrg  {
1185fe24f8a2Smrg    $debug_cmd
1186fe24f8a2Smrg
1187fe24f8a2Smrg    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1188fe24f8a2Smrg    # positional parameters, so assign one to ordinary variable first.
1189fe24f8a2Smrg    func_stripname_result=$3
1190fe24f8a2Smrg    func_stripname_result=${func_stripname_result#"$1"}
1191fe24f8a2Smrg    func_stripname_result=${func_stripname_result%"$2"}
1192fe24f8a2Smrg  }'
1193fe24f8a2Smrgelse
1194fe24f8a2Smrg  func_stripname ()
1195fe24f8a2Smrg  {
1196fe24f8a2Smrg    $debug_cmd
1197fe24f8a2Smrg
1198fe24f8a2Smrg    case $2 in
1199fe24f8a2Smrg      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1200fe24f8a2Smrg      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1201fe24f8a2Smrg    esac
1202fe24f8a2Smrg  }
1203fe24f8a2Smrgfi
1204fe24f8a2Smrg
1205fe24f8a2Smrg
1206fe24f8a2Smrg# func_show_eval CMD [FAIL_EXP]
1207fe24f8a2Smrg# -----------------------------
1208fe24f8a2Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1209fe24f8a2Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1210fe24f8a2Smrg# is given, then evaluate it.
1211fe24f8a2Smrgfunc_show_eval ()
1212fe24f8a2Smrg{
1213fe24f8a2Smrg    $debug_cmd
1214fe24f8a2Smrg
1215fe24f8a2Smrg    _G_cmd=$1
1216fe24f8a2Smrg    _G_fail_exp=${2-':'}
1217fe24f8a2Smrg
1218fe24f8a2Smrg    func_quote_for_expand "$_G_cmd"
1219fe24f8a2Smrg    eval "func_notquiet $func_quote_for_expand_result"
1220fe24f8a2Smrg
1221fe24f8a2Smrg    $opt_dry_run || {
1222fe24f8a2Smrg      eval "$_G_cmd"
1223fe24f8a2Smrg      _G_status=$?
1224fe24f8a2Smrg      if test 0 -ne "$_G_status"; then
1225fe24f8a2Smrg	eval "(exit $_G_status); $_G_fail_exp"
1226fe24f8a2Smrg      fi
1227fe24f8a2Smrg    }
1228fe24f8a2Smrg}
1229fe24f8a2Smrg
1230fe24f8a2Smrg
1231fe24f8a2Smrg# func_show_eval_locale CMD [FAIL_EXP]
1232fe24f8a2Smrg# ------------------------------------
1233fe24f8a2Smrg# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
1234fe24f8a2Smrg# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
1235fe24f8a2Smrg# is given, then evaluate it.  Use the saved locale for evaluation.
1236fe24f8a2Smrgfunc_show_eval_locale ()
1237fe24f8a2Smrg{
1238fe24f8a2Smrg    $debug_cmd
1239fe24f8a2Smrg
1240fe24f8a2Smrg    _G_cmd=$1
1241fe24f8a2Smrg    _G_fail_exp=${2-':'}
1242fe24f8a2Smrg
1243fe24f8a2Smrg    $opt_quiet || {
1244fe24f8a2Smrg      func_quote_for_expand "$_G_cmd"
1245fe24f8a2Smrg      eval "func_echo $func_quote_for_expand_result"
1246fe24f8a2Smrg    }
1247fe24f8a2Smrg
1248fe24f8a2Smrg    $opt_dry_run || {
1249fe24f8a2Smrg      eval "$_G_user_locale
1250fe24f8a2Smrg	    $_G_cmd"
1251fe24f8a2Smrg      _G_status=$?
1252fe24f8a2Smrg      eval "$_G_safe_locale"
1253fe24f8a2Smrg      if test 0 -ne "$_G_status"; then
1254fe24f8a2Smrg	eval "(exit $_G_status); $_G_fail_exp"
1255fe24f8a2Smrg      fi
1256fe24f8a2Smrg    }
1257fe24f8a2Smrg}
1258fe24f8a2Smrg
1259fe24f8a2Smrg
1260fe24f8a2Smrg# func_tr_sh
1261fe24f8a2Smrg# ----------
1262fe24f8a2Smrg# Turn $1 into a string suitable for a shell variable name.
1263fe24f8a2Smrg# Result is stored in $func_tr_sh_result.  All characters
1264fe24f8a2Smrg# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
1265fe24f8a2Smrg# if $1 begins with a digit, a '_' is prepended as well.
1266fe24f8a2Smrgfunc_tr_sh ()
1267fe24f8a2Smrg{
1268fe24f8a2Smrg    $debug_cmd
1269fe24f8a2Smrg
1270fe24f8a2Smrg    case $1 in
1271fe24f8a2Smrg    [0-9]* | *[!a-zA-Z0-9_]*)
1272fe24f8a2Smrg      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
1273fe24f8a2Smrg      ;;
1274fe24f8a2Smrg    * )
1275fe24f8a2Smrg      func_tr_sh_result=$1
1276fe24f8a2Smrg      ;;
1277fe24f8a2Smrg    esac
1278fe24f8a2Smrg}
1279fe24f8a2Smrg
1280fe24f8a2Smrg
1281fe24f8a2Smrg# func_verbose ARG...
1282fe24f8a2Smrg# -------------------
1283fe24f8a2Smrg# Echo program name prefixed message in verbose mode only.
1284fe24f8a2Smrgfunc_verbose ()
1285fe24f8a2Smrg{
1286fe24f8a2Smrg    $debug_cmd
1287fe24f8a2Smrg
1288fe24f8a2Smrg    $opt_verbose && func_echo "$*"
1289fe24f8a2Smrg
1290fe24f8a2Smrg    :
1291fe24f8a2Smrg}
1292fe24f8a2Smrg
1293fe24f8a2Smrg
1294fe24f8a2Smrg# func_warn_and_continue ARG...
1295fe24f8a2Smrg# -----------------------------
1296fe24f8a2Smrg# Echo program name prefixed warning message to standard error.
1297fe24f8a2Smrgfunc_warn_and_continue ()
1298fe24f8a2Smrg{
1299fe24f8a2Smrg    $debug_cmd
1300fe24f8a2Smrg
1301fe24f8a2Smrg    $require_term_colors
1302fe24f8a2Smrg
1303fe24f8a2Smrg    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
1304fe24f8a2Smrg}
1305fe24f8a2Smrg
1306fe24f8a2Smrg
1307fe24f8a2Smrg# func_warning CATEGORY ARG...
1308fe24f8a2Smrg# ----------------------------
1309fe24f8a2Smrg# Echo program name prefixed warning message to standard error. Warning
1310fe24f8a2Smrg# messages can be filtered according to CATEGORY, where this function
1311fe24f8a2Smrg# elides messages where CATEGORY is not listed in the global variable
1312fe24f8a2Smrg# 'opt_warning_types'.
1313fe24f8a2Smrgfunc_warning ()
1314fe24f8a2Smrg{
1315fe24f8a2Smrg    $debug_cmd
1316fe24f8a2Smrg
1317fe24f8a2Smrg    # CATEGORY must be in the warning_categories list!
1318fe24f8a2Smrg    case " $warning_categories " in
1319fe24f8a2Smrg      *" $1 "*) ;;
1320fe24f8a2Smrg      *) func_internal_error "invalid warning category '$1'" ;;
1321fe24f8a2Smrg    esac
1322fe24f8a2Smrg
1323fe24f8a2Smrg    _G_category=$1
1324fe24f8a2Smrg    shift
1325fe24f8a2Smrg
1326fe24f8a2Smrg    case " $opt_warning_types " in
1327fe24f8a2Smrg      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1328fe24f8a2Smrg    esac
1329fe24f8a2Smrg}
1330fe24f8a2Smrg
1331fe24f8a2Smrg
1332fe24f8a2Smrg# func_sort_ver VER1 VER2
1333fe24f8a2Smrg# -----------------------
1334fe24f8a2Smrg# 'sort -V' is not generally available.
1335fe24f8a2Smrg# Note this deviates from the version comparison in automake
1336fe24f8a2Smrg# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1337fe24f8a2Smrg# but this should suffice as we won't be specifying old
1338fe24f8a2Smrg# version formats or redundant trailing .0 in bootstrap.conf.
1339fe24f8a2Smrg# If we did want full compatibility then we should probably
1340fe24f8a2Smrg# use m4_version_compare from autoconf.
1341fe24f8a2Smrgfunc_sort_ver ()
1342fe24f8a2Smrg{
1343fe24f8a2Smrg    $debug_cmd
1344fe24f8a2Smrg
1345fe24f8a2Smrg    printf '%s\n%s\n' "$1" "$2" \
1346fe24f8a2Smrg      | 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
1347fe24f8a2Smrg}
1348fe24f8a2Smrg
1349fe24f8a2Smrg# func_lt_ver PREV CURR
1350fe24f8a2Smrg# ---------------------
1351fe24f8a2Smrg# Return true if PREV and CURR are in the correct order according to
1352fe24f8a2Smrg# func_sort_ver, otherwise false.  Use it like this:
1353fe24f8a2Smrg#
1354fe24f8a2Smrg#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1355fe24f8a2Smrgfunc_lt_ver ()
1356fe24f8a2Smrg{
1357fe24f8a2Smrg    $debug_cmd
1358fe24f8a2Smrg
1359fe24f8a2Smrg    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1360fe24f8a2Smrg}
1361fe24f8a2Smrg
1362fe24f8a2Smrg
1363fe24f8a2Smrg# Local variables:
1364fe24f8a2Smrg# mode: shell-script
1365fe24f8a2Smrg# sh-indentation: 2
1366fe24f8a2Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1367fe24f8a2Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1368fe24f8a2Smrg# time-stamp-time-zone: "UTC"
1369fe24f8a2Smrg# End:
1370fe24f8a2Smrg#! /bin/sh
1371fe24f8a2Smrg
1372fe24f8a2Smrg# Set a version string for this script.
1373fe24f8a2Smrgscriptversion=2014-01-07.03; # UTC
1374fe24f8a2Smrg
1375fe24f8a2Smrg# A portable, pluggable option parser for Bourne shell.
1376fe24f8a2Smrg# Written by Gary V. Vaughan, 2010
1377fe24f8a2Smrg
1378fe24f8a2Smrg# Copyright (C) 2010-2015 Free Software Foundation, Inc.
1379fe24f8a2Smrg# This is free software; see the source for copying conditions.  There is NO
1380fe24f8a2Smrg# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1381fe24f8a2Smrg
1382fe24f8a2Smrg# This program is free software: you can redistribute it and/or modify
1383fe24f8a2Smrg# it under the terms of the GNU General Public License as published by
1384fe24f8a2Smrg# the Free Software Foundation, either version 3 of the License, or
1385fe24f8a2Smrg# (at your option) any later version.
1386fe24f8a2Smrg
1387fe24f8a2Smrg# This program is distributed in the hope that it will be useful,
1388fe24f8a2Smrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1389fe24f8a2Smrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1390fe24f8a2Smrg# GNU General Public License for more details.
1391fe24f8a2Smrg
1392fe24f8a2Smrg# You should have received a copy of the GNU General Public License
1393fe24f8a2Smrg# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1394fe24f8a2Smrg
1395fe24f8a2Smrg# Please report bugs or propose patches to gary@gnu.org.
1396fe24f8a2Smrg
1397fe24f8a2Smrg
1398fe24f8a2Smrg## ------ ##
1399fe24f8a2Smrg## Usage. ##
1400fe24f8a2Smrg## ------ ##
1401fe24f8a2Smrg
1402fe24f8a2Smrg# This file is a library for parsing options in your shell scripts along
1403fe24f8a2Smrg# with assorted other useful supporting features that you can make use
1404fe24f8a2Smrg# of too.
1405fe24f8a2Smrg#
1406fe24f8a2Smrg# For the simplest scripts you might need only:
1407fe24f8a2Smrg#
1408fe24f8a2Smrg#   #!/bin/sh
1409fe24f8a2Smrg#   . relative/path/to/funclib.sh
1410fe24f8a2Smrg#   . relative/path/to/options-parser
1411fe24f8a2Smrg#   scriptversion=1.0
1412fe24f8a2Smrg#   func_options ${1+"$@"}
1413fe24f8a2Smrg#   eval set dummy "$func_options_result"; shift
1414fe24f8a2Smrg#   ...rest of your script...
1415fe24f8a2Smrg#
1416fe24f8a2Smrg# In order for the '--version' option to work, you will need to have a
1417fe24f8a2Smrg# suitably formatted comment like the one at the top of this file
1418fe24f8a2Smrg# starting with '# Written by ' and ending with '# warranty; '.
1419fe24f8a2Smrg#
1420fe24f8a2Smrg# For '-h' and '--help' to work, you will also need a one line
1421fe24f8a2Smrg# description of your script's purpose in a comment directly above the
1422fe24f8a2Smrg# '# Written by ' line, like the one at the top of this file.
1423fe24f8a2Smrg#
1424fe24f8a2Smrg# The default options also support '--debug', which will turn on shell
1425fe24f8a2Smrg# execution tracing (see the comment above debug_cmd below for another
1426fe24f8a2Smrg# use), and '--verbose' and the func_verbose function to allow your script
1427fe24f8a2Smrg# to display verbose messages only when your user has specified
1428fe24f8a2Smrg# '--verbose'.
1429fe24f8a2Smrg#
1430fe24f8a2Smrg# After sourcing this file, you can plug processing for additional
1431fe24f8a2Smrg# options by amending the variables from the 'Configuration' section
1432fe24f8a2Smrg# below, and following the instructions in the 'Option parsing'
1433fe24f8a2Smrg# section further down.
1434fe24f8a2Smrg
1435fe24f8a2Smrg## -------------- ##
1436fe24f8a2Smrg## Configuration. ##
1437fe24f8a2Smrg## -------------- ##
1438fe24f8a2Smrg
1439fe24f8a2Smrg# You should override these variables in your script after sourcing this
1440fe24f8a2Smrg# file so that they reflect the customisations you have added to the
1441fe24f8a2Smrg# option parser.
1442fe24f8a2Smrg
1443fe24f8a2Smrg# The usage line for option parsing errors and the start of '-h' and
1444fe24f8a2Smrg# '--help' output messages. You can embed shell variables for delayed
1445fe24f8a2Smrg# expansion at the time the message is displayed, but you will need to
1446fe24f8a2Smrg# quote other shell meta-characters carefully to prevent them being
1447fe24f8a2Smrg# expanded when the contents are evaled.
1448fe24f8a2Smrgusage='$progpath [OPTION]...'
1449fe24f8a2Smrg
1450fe24f8a2Smrg# Short help message in response to '-h' and '--help'.  Add to this or
1451fe24f8a2Smrg# override it after sourcing this library to reflect the full set of
1452fe24f8a2Smrg# options your script accepts.
1453fe24f8a2Smrgusage_message="\
1454fe24f8a2Smrg       --debug        enable verbose shell tracing
1455fe24f8a2Smrg   -W, --warnings=CATEGORY
1456fe24f8a2Smrg                      report the warnings falling in CATEGORY [all]
1457fe24f8a2Smrg   -v, --verbose      verbosely report processing
1458fe24f8a2Smrg       --version      print version information and exit
1459fe24f8a2Smrg   -h, --help         print short or long help message and exit
1460fe24f8a2Smrg"
1461fe24f8a2Smrg
1462fe24f8a2Smrg# Additional text appended to 'usage_message' in response to '--help'.
1463fe24f8a2Smrglong_help_message="
1464fe24f8a2SmrgWarning categories include:
1465fe24f8a2Smrg       'all'          show all warnings
1466fe24f8a2Smrg       'none'         turn off all the warnings
1467fe24f8a2Smrg       'error'        warnings are treated as fatal errors"
1468fe24f8a2Smrg
1469fe24f8a2Smrg# Help message printed before fatal option parsing errors.
1470fe24f8a2Smrgfatal_help="Try '\$progname --help' for more information."
1471fe24f8a2Smrg
1472fe24f8a2Smrg
1473fe24f8a2Smrg
1474fe24f8a2Smrg## ------------------------- ##
1475fe24f8a2Smrg## Hook function management. ##
1476fe24f8a2Smrg## ------------------------- ##
1477fe24f8a2Smrg
1478fe24f8a2Smrg# This section contains functions for adding, removing, and running hooks
1479fe24f8a2Smrg# to the main code.  A hook is just a named list of of function, that can
1480fe24f8a2Smrg# be run in order later on.
1481fe24f8a2Smrg
1482fe24f8a2Smrg# func_hookable FUNC_NAME
1483fe24f8a2Smrg# -----------------------
1484fe24f8a2Smrg# Declare that FUNC_NAME will run hooks added with
1485fe24f8a2Smrg# 'func_add_hook FUNC_NAME ...'.
1486fe24f8a2Smrgfunc_hookable ()
1487fe24f8a2Smrg{
1488fe24f8a2Smrg    $debug_cmd
1489fe24f8a2Smrg
1490fe24f8a2Smrg    func_append hookable_fns " $1"
1491fe24f8a2Smrg}
1492fe24f8a2Smrg
1493fe24f8a2Smrg
1494fe24f8a2Smrg# func_add_hook FUNC_NAME HOOK_FUNC
1495fe24f8a2Smrg# ---------------------------------
1496fe24f8a2Smrg# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1497fe24f8a2Smrg# first have been declared "hookable" by a call to 'func_hookable'.
1498fe24f8a2Smrgfunc_add_hook ()
1499fe24f8a2Smrg{
1500fe24f8a2Smrg    $debug_cmd
1501fe24f8a2Smrg
1502fe24f8a2Smrg    case " $hookable_fns " in
1503fe24f8a2Smrg      *" $1 "*) ;;
1504fe24f8a2Smrg      *) func_fatal_error "'$1' does not accept hook functions." ;;
1505fe24f8a2Smrg    esac
1506fe24f8a2Smrg
1507fe24f8a2Smrg    eval func_append ${1}_hooks '" $2"'
1508fe24f8a2Smrg}
1509fe24f8a2Smrg
1510fe24f8a2Smrg
1511fe24f8a2Smrg# func_remove_hook FUNC_NAME HOOK_FUNC
1512fe24f8a2Smrg# ------------------------------------
1513fe24f8a2Smrg# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1514fe24f8a2Smrgfunc_remove_hook ()
1515fe24f8a2Smrg{
1516fe24f8a2Smrg    $debug_cmd
1517fe24f8a2Smrg
1518fe24f8a2Smrg    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1519fe24f8a2Smrg}
1520fe24f8a2Smrg
1521fe24f8a2Smrg
1522fe24f8a2Smrg# func_run_hooks FUNC_NAME [ARG]...
1523fe24f8a2Smrg# ---------------------------------
1524fe24f8a2Smrg# Run all hook functions registered to FUNC_NAME.
1525fe24f8a2Smrg# It is assumed that the list of hook functions contains nothing more
1526fe24f8a2Smrg# than a whitespace-delimited list of legal shell function names, and
1527fe24f8a2Smrg# no effort is wasted trying to catch shell meta-characters or preserve
1528fe24f8a2Smrg# whitespace.
1529fe24f8a2Smrgfunc_run_hooks ()
1530fe24f8a2Smrg{
1531fe24f8a2Smrg    $debug_cmd
1532fe24f8a2Smrg
1533fe24f8a2Smrg    case " $hookable_fns " in
1534fe24f8a2Smrg      *" $1 "*) ;;
1535fe24f8a2Smrg      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1536fe24f8a2Smrg    esac
1537fe24f8a2Smrg
1538fe24f8a2Smrg    eval _G_hook_fns=\$$1_hooks; shift
1539fe24f8a2Smrg
1540fe24f8a2Smrg    for _G_hook in $_G_hook_fns; do
1541fe24f8a2Smrg      eval $_G_hook '"$@"'
1542fe24f8a2Smrg
1543fe24f8a2Smrg      # store returned options list back into positional
1544fe24f8a2Smrg      # parameters for next 'cmd' execution.
1545fe24f8a2Smrg      eval _G_hook_result=\$${_G_hook}_result
1546fe24f8a2Smrg      eval set dummy "$_G_hook_result"; shift
1547fe24f8a2Smrg    done
1548fe24f8a2Smrg
1549fe24f8a2Smrg    func_quote_for_eval ${1+"$@"}
1550fe24f8a2Smrg    func_run_hooks_result=$func_quote_for_eval_result
1551fe24f8a2Smrg}
1552fe24f8a2Smrg
1553fe24f8a2Smrg
1554fe24f8a2Smrg
1555fe24f8a2Smrg## --------------- ##
1556fe24f8a2Smrg## Option parsing. ##
1557fe24f8a2Smrg## --------------- ##
1558fe24f8a2Smrg
1559fe24f8a2Smrg# In order to add your own option parsing hooks, you must accept the
1560fe24f8a2Smrg# full positional parameter list in your hook function, remove any
1561fe24f8a2Smrg# options that you action, and then pass back the remaining unprocessed
1562fe24f8a2Smrg# options in '<hooked_function_name>_result', escaped suitably for
1563fe24f8a2Smrg# 'eval'.  Like this:
1564fe24f8a2Smrg#
1565fe24f8a2Smrg#    my_options_prep ()
1566fe24f8a2Smrg#    {
1567fe24f8a2Smrg#        $debug_cmd
1568fe24f8a2Smrg#
1569fe24f8a2Smrg#        # Extend the existing usage message.
1570fe24f8a2Smrg#        usage_message=$usage_message'
1571fe24f8a2Smrg#      -s, --silent       don'\''t print informational messages
1572fe24f8a2Smrg#    '
1573fe24f8a2Smrg#
1574fe24f8a2Smrg#        func_quote_for_eval ${1+"$@"}
1575fe24f8a2Smrg#        my_options_prep_result=$func_quote_for_eval_result
1576fe24f8a2Smrg#    }
1577fe24f8a2Smrg#    func_add_hook func_options_prep my_options_prep
1578fe24f8a2Smrg#
1579fe24f8a2Smrg#
1580fe24f8a2Smrg#    my_silent_option ()
1581fe24f8a2Smrg#    {
1582fe24f8a2Smrg#        $debug_cmd
1583fe24f8a2Smrg#
1584fe24f8a2Smrg#        # Note that for efficiency, we parse as many options as we can
1585fe24f8a2Smrg#        # recognise in a loop before passing the remainder back to the
1586fe24f8a2Smrg#        # caller on the first unrecognised argument we encounter.
1587fe24f8a2Smrg#        while test $# -gt 0; do
1588fe24f8a2Smrg#          opt=$1; shift
1589fe24f8a2Smrg#          case $opt in
1590fe24f8a2Smrg#            --silent|-s) opt_silent=: ;;
1591fe24f8a2Smrg#            # Separate non-argument short options:
1592fe24f8a2Smrg#            -s*)         func_split_short_opt "$_G_opt"
1593fe24f8a2Smrg#                         set dummy "$func_split_short_opt_name" \
1594fe24f8a2Smrg#                             "-$func_split_short_opt_arg" ${1+"$@"}
1595fe24f8a2Smrg#                         shift
1596fe24f8a2Smrg#                         ;;
1597fe24f8a2Smrg#            *)            set dummy "$_G_opt" "$*"; shift; break ;;
1598fe24f8a2Smrg#          esac
1599fe24f8a2Smrg#        done
1600fe24f8a2Smrg#
1601fe24f8a2Smrg#        func_quote_for_eval ${1+"$@"}
1602fe24f8a2Smrg#        my_silent_option_result=$func_quote_for_eval_result
1603fe24f8a2Smrg#    }
1604fe24f8a2Smrg#    func_add_hook func_parse_options my_silent_option
1605fe24f8a2Smrg#
1606fe24f8a2Smrg#
1607fe24f8a2Smrg#    my_option_validation ()
1608fe24f8a2Smrg#    {
1609fe24f8a2Smrg#        $debug_cmd
1610fe24f8a2Smrg#
1611fe24f8a2Smrg#        $opt_silent && $opt_verbose && func_fatal_help "\
1612fe24f8a2Smrg#    '--silent' and '--verbose' options are mutually exclusive."
1613fe24f8a2Smrg#
1614fe24f8a2Smrg#        func_quote_for_eval ${1+"$@"}
1615fe24f8a2Smrg#        my_option_validation_result=$func_quote_for_eval_result
1616fe24f8a2Smrg#    }
1617fe24f8a2Smrg#    func_add_hook func_validate_options my_option_validation
1618fe24f8a2Smrg#
1619fe24f8a2Smrg# You'll alse need to manually amend $usage_message to reflect the extra
1620fe24f8a2Smrg# options you parse.  It's preferable to append if you can, so that
1621fe24f8a2Smrg# multiple option parsing hooks can be added safely.
1622fe24f8a2Smrg
1623fe24f8a2Smrg
1624fe24f8a2Smrg# func_options [ARG]...
1625fe24f8a2Smrg# ---------------------
1626fe24f8a2Smrg# All the functions called inside func_options are hookable. See the
1627fe24f8a2Smrg# individual implementations for details.
1628fe24f8a2Smrgfunc_hookable func_options
1629fe24f8a2Smrgfunc_options ()
1630fe24f8a2Smrg{
1631fe24f8a2Smrg    $debug_cmd
1632fe24f8a2Smrg
1633fe24f8a2Smrg    func_options_prep ${1+"$@"}
1634fe24f8a2Smrg    eval func_parse_options \
1635fe24f8a2Smrg        ${func_options_prep_result+"$func_options_prep_result"}
1636fe24f8a2Smrg    eval func_validate_options \
1637fe24f8a2Smrg        ${func_parse_options_result+"$func_parse_options_result"}
1638fe24f8a2Smrg
1639fe24f8a2Smrg    eval func_run_hooks func_options \
1640fe24f8a2Smrg        ${func_validate_options_result+"$func_validate_options_result"}
1641fe24f8a2Smrg
1642fe24f8a2Smrg    # save modified positional parameters for caller
1643fe24f8a2Smrg    func_options_result=$func_run_hooks_result
1644ee3138f1Smrg}
1645ee3138f1Smrg
1646ee3138f1Smrg
1647fe24f8a2Smrg# func_options_prep [ARG]...
1648fe24f8a2Smrg# --------------------------
1649fe24f8a2Smrg# All initialisations required before starting the option parse loop.
1650fe24f8a2Smrg# Note that when calling hook functions, we pass through the list of
1651fe24f8a2Smrg# positional parameters.  If a hook function modifies that list, and
1652fe24f8a2Smrg# needs to propogate that back to rest of this script, then the complete
1653fe24f8a2Smrg# modified list must be put in 'func_run_hooks_result' before
1654fe24f8a2Smrg# returning.
1655fe24f8a2Smrgfunc_hookable func_options_prep
1656fe24f8a2Smrgfunc_options_prep ()
1657ee3138f1Smrg{
1658fe24f8a2Smrg    $debug_cmd
165934977a2fSmrg
1660fe24f8a2Smrg    # Option defaults:
1661fe24f8a2Smrg    opt_verbose=false
1662fe24f8a2Smrg    opt_warning_types=
1663fe24f8a2Smrg
1664fe24f8a2Smrg    func_run_hooks func_options_prep ${1+"$@"}
1665fe24f8a2Smrg
1666fe24f8a2Smrg    # save modified positional parameters for caller
1667fe24f8a2Smrg    func_options_prep_result=$func_run_hooks_result
1668ee3138f1Smrg}
1669ee3138f1Smrg
1670ee3138f1Smrg
1671fe24f8a2Smrg# func_parse_options [ARG]...
1672fe24f8a2Smrg# ---------------------------
1673fe24f8a2Smrg# The main option parsing loop.
1674fe24f8a2Smrgfunc_hookable func_parse_options
1675fe24f8a2Smrgfunc_parse_options ()
1676ee3138f1Smrg{
1677fe24f8a2Smrg    $debug_cmd
167834977a2fSmrg
1679fe24f8a2Smrg    func_parse_options_result=
168034977a2fSmrg
1681fe24f8a2Smrg    # this just eases exit handling
1682fe24f8a2Smrg    while test $# -gt 0; do
1683fe24f8a2Smrg      # Defer to hook functions for initial option parsing, so they
1684fe24f8a2Smrg      # get priority in the event of reusing an option name.
1685fe24f8a2Smrg      func_run_hooks func_parse_options ${1+"$@"}
1686ee3138f1Smrg
1687fe24f8a2Smrg      # Adjust func_parse_options positional parameters to match
1688fe24f8a2Smrg      eval set dummy "$func_run_hooks_result"; shift
1689ee3138f1Smrg
1690fe24f8a2Smrg      # Break out of the loop if we already parsed every option.
1691fe24f8a2Smrg      test $# -gt 0 || break
1692ee3138f1Smrg
1693fe24f8a2Smrg      _G_opt=$1
1694fe24f8a2Smrg      shift
1695fe24f8a2Smrg      case $_G_opt in
1696fe24f8a2Smrg        --debug|-x)   debug_cmd='set -x'
1697fe24f8a2Smrg                      func_echo "enabling shell trace mode"
1698fe24f8a2Smrg                      $debug_cmd
1699fe24f8a2Smrg                      ;;
1700fe24f8a2Smrg
1701fe24f8a2Smrg        --no-warnings|--no-warning|--no-warn)
1702fe24f8a2Smrg                      set dummy --warnings none ${1+"$@"}
1703fe24f8a2Smrg                      shift
1704fe24f8a2Smrg		      ;;
170534977a2fSmrg
1706fe24f8a2Smrg        --warnings|--warning|-W)
1707fe24f8a2Smrg                      test $# = 0 && func_missing_arg $_G_opt && break
1708fe24f8a2Smrg                      case " $warning_categories $1" in
1709fe24f8a2Smrg                        *" $1 "*)
1710fe24f8a2Smrg                          # trailing space prevents matching last $1 above
1711fe24f8a2Smrg                          func_append_uniq opt_warning_types " $1"
1712fe24f8a2Smrg                          ;;
1713fe24f8a2Smrg                        *all)
1714fe24f8a2Smrg                          opt_warning_types=$warning_categories
1715fe24f8a2Smrg                          ;;
1716fe24f8a2Smrg                        *none)
1717fe24f8a2Smrg                          opt_warning_types=none
1718fe24f8a2Smrg                          warning_func=:
1719fe24f8a2Smrg                          ;;
1720fe24f8a2Smrg                        *error)
1721fe24f8a2Smrg                          opt_warning_types=$warning_categories
1722fe24f8a2Smrg                          warning_func=func_fatal_error
1723fe24f8a2Smrg                          ;;
1724fe24f8a2Smrg                        *)
1725fe24f8a2Smrg                          func_fatal_error \
1726fe24f8a2Smrg                             "unsupported warning category: '$1'"
1727fe24f8a2Smrg                          ;;
1728fe24f8a2Smrg                      esac
1729fe24f8a2Smrg                      shift
1730fe24f8a2Smrg                      ;;
1731fe24f8a2Smrg
1732fe24f8a2Smrg        --verbose|-v) opt_verbose=: ;;
1733fe24f8a2Smrg        --version)    func_version ;;
1734fe24f8a2Smrg        -\?|-h)       func_usage ;;
1735fe24f8a2Smrg        --help)       func_help ;;
1736fe24f8a2Smrg
1737fe24f8a2Smrg	# Separate optargs to long options (plugins may need this):
1738fe24f8a2Smrg	--*=*)        func_split_equals "$_G_opt"
1739fe24f8a2Smrg	              set dummy "$func_split_equals_lhs" \
1740fe24f8a2Smrg                          "$func_split_equals_rhs" ${1+"$@"}
1741fe24f8a2Smrg                      shift
1742fe24f8a2Smrg                      ;;
1743fe24f8a2Smrg
1744fe24f8a2Smrg       # Separate optargs to short options:
1745fe24f8a2Smrg        -W*)
1746fe24f8a2Smrg                      func_split_short_opt "$_G_opt"
1747fe24f8a2Smrg                      set dummy "$func_split_short_opt_name" \
1748fe24f8a2Smrg                          "$func_split_short_opt_arg" ${1+"$@"}
1749fe24f8a2Smrg                      shift
1750fe24f8a2Smrg                      ;;
1751fe24f8a2Smrg
1752fe24f8a2Smrg        # Separate non-argument short options:
1753fe24f8a2Smrg        -\?*|-h*|-v*|-x*)
1754fe24f8a2Smrg                      func_split_short_opt "$_G_opt"
1755fe24f8a2Smrg                      set dummy "$func_split_short_opt_name" \
1756fe24f8a2Smrg                          "-$func_split_short_opt_arg" ${1+"$@"}
1757fe24f8a2Smrg                      shift
1758fe24f8a2Smrg                      ;;
1759fe24f8a2Smrg
1760fe24f8a2Smrg        --)           break ;;
1761fe24f8a2Smrg        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1762fe24f8a2Smrg        *)            set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1763fe24f8a2Smrg      esac
1764fe24f8a2Smrg    done
1765fe24f8a2Smrg
1766fe24f8a2Smrg    # save modified positional parameters for caller
1767fe24f8a2Smrg    func_quote_for_eval ${1+"$@"}
1768fe24f8a2Smrg    func_parse_options_result=$func_quote_for_eval_result
1769ee3138f1Smrg}
1770ee3138f1Smrg
177134977a2fSmrg
1772fe24f8a2Smrg# func_validate_options [ARG]...
1773fe24f8a2Smrg# ------------------------------
1774fe24f8a2Smrg# Perform any sanity checks on option settings and/or unconsumed
1775fe24f8a2Smrg# arguments.
1776fe24f8a2Smrgfunc_hookable func_validate_options
1777fe24f8a2Smrgfunc_validate_options ()
1778ee3138f1Smrg{
1779fe24f8a2Smrg    $debug_cmd
178034977a2fSmrg
1781fe24f8a2Smrg    # Display all warnings if -W was not given.
1782fe24f8a2Smrg    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
178334977a2fSmrg
1784fe24f8a2Smrg    func_run_hooks func_validate_options ${1+"$@"}
1785ee3138f1Smrg
1786fe24f8a2Smrg    # Bail if the options were screwed!
1787fe24f8a2Smrg    $exit_cmd $EXIT_FAILURE
1788fe24f8a2Smrg
1789fe24f8a2Smrg    # save modified positional parameters for caller
1790fe24f8a2Smrg    func_validate_options_result=$func_run_hooks_result
17913e72ca8cSmrg}
17923e72ca8cSmrg
1793ee3138f1Smrg
17943e72ca8cSmrg
1795fe24f8a2Smrg## ----------------- ##
1796fe24f8a2Smrg## Helper functions. ##
1797fe24f8a2Smrg## ----------------- ##
1798ee3138f1Smrg
1799fe24f8a2Smrg# This section contains the helper functions used by the rest of the
1800fe24f8a2Smrg# hookable option parser framework in ascii-betical order.
1801fe24f8a2Smrg
1802fe24f8a2Smrg
1803fe24f8a2Smrg# func_fatal_help ARG...
1804fe24f8a2Smrg# ----------------------
1805fe24f8a2Smrg# Echo program name prefixed message to standard error, followed by
1806fe24f8a2Smrg# a help hint, and exit.
1807fe24f8a2Smrgfunc_fatal_help ()
180834977a2fSmrg{
1809fe24f8a2Smrg    $debug_cmd
18103e72ca8cSmrg
1811fe24f8a2Smrg    eval \$ECHO \""Usage: $usage"\"
1812fe24f8a2Smrg    eval \$ECHO \""$fatal_help"\"
1813fe24f8a2Smrg    func_error ${1+"$@"}
1814fe24f8a2Smrg    exit $EXIT_FAILURE
181534977a2fSmrg}
1816ee3138f1Smrg
1817fe24f8a2Smrg
1818fe24f8a2Smrg# func_help
1819fe24f8a2Smrg# ---------
1820fe24f8a2Smrg# Echo long help message to standard output and exit.
182134977a2fSmrgfunc_help ()
182234977a2fSmrg{
1823fe24f8a2Smrg    $debug_cmd
1824fe24f8a2Smrg
1825fe24f8a2Smrg    func_usage_message
1826fe24f8a2Smrg    $ECHO "$long_help_message"
1827fe24f8a2Smrg    exit 0
182834977a2fSmrg}
1829ee3138f1Smrg
1830fe24f8a2Smrg
1831fe24f8a2Smrg# func_missing_arg ARGNAME
1832fe24f8a2Smrg# ------------------------
183334977a2fSmrg# Echo program name prefixed message to standard error and set global
183434977a2fSmrg# exit_cmd.
183534977a2fSmrgfunc_missing_arg ()
183634977a2fSmrg{
1837fe24f8a2Smrg    $debug_cmd
18383e72ca8cSmrg
1839fe24f8a2Smrg    func_error "Missing argument for '$1'."
184034977a2fSmrg    exit_cmd=exit
184134977a2fSmrg}
184234977a2fSmrg
184334977a2fSmrg
1844fe24f8a2Smrg# func_split_equals STRING
1845fe24f8a2Smrg# ------------------------
1846fe24f8a2Smrg# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
1847fe24f8a2Smrg# splitting STRING at the '=' sign.
1848fe24f8a2Smrgtest -z "$_G_HAVE_XSI_OPS" \
1849fe24f8a2Smrg    && (eval 'x=a/b/c;
1850fe24f8a2Smrg      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
1851fe24f8a2Smrg    && _G_HAVE_XSI_OPS=yes
1852fe24f8a2Smrg
1853fe24f8a2Smrgif test yes = "$_G_HAVE_XSI_OPS"
1854fe24f8a2Smrgthen
1855fe24f8a2Smrg  # This is an XSI compatible shell, allowing a faster implementation...
1856fe24f8a2Smrg  eval 'func_split_equals ()
1857fe24f8a2Smrg  {
1858fe24f8a2Smrg      $debug_cmd
1859fe24f8a2Smrg
1860fe24f8a2Smrg      func_split_equals_lhs=${1%%=*}
1861fe24f8a2Smrg      func_split_equals_rhs=${1#*=}
1862fe24f8a2Smrg      test "x$func_split_equals_lhs" = "x$1" \
1863fe24f8a2Smrg        && func_split_equals_rhs=
1864fe24f8a2Smrg  }'
1865fe24f8a2Smrgelse
1866fe24f8a2Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1867fe24f8a2Smrg  func_split_equals ()
1868fe24f8a2Smrg  {
1869fe24f8a2Smrg      $debug_cmd
1870fe24f8a2Smrg
1871fe24f8a2Smrg      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
1872fe24f8a2Smrg      func_split_equals_rhs=
1873fe24f8a2Smrg      test "x$func_split_equals_lhs" = "x$1" \
1874fe24f8a2Smrg        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
1875fe24f8a2Smrg  }
1876fe24f8a2Smrgfi #func_split_equals
1877fe24f8a2Smrg
1878fe24f8a2Smrg
1879fe24f8a2Smrg# func_split_short_opt SHORTOPT
1880fe24f8a2Smrg# -----------------------------
18813e72ca8cSmrg# Set func_split_short_opt_name and func_split_short_opt_arg shell
18823e72ca8cSmrg# variables after splitting SHORTOPT after the 2nd character.
1883fe24f8a2Smrgif test yes = "$_G_HAVE_XSI_OPS"
1884fe24f8a2Smrgthen
1885fe24f8a2Smrg  # This is an XSI compatible shell, allowing a faster implementation...
1886fe24f8a2Smrg  eval 'func_split_short_opt ()
1887fe24f8a2Smrg  {
1888fe24f8a2Smrg      $debug_cmd
1889fe24f8a2Smrg
1890fe24f8a2Smrg      func_split_short_opt_arg=${1#??}
1891fe24f8a2Smrg      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1892fe24f8a2Smrg  }'
1893fe24f8a2Smrgelse
1894fe24f8a2Smrg  # ...otherwise fall back to using expr, which is often a shell builtin.
1895fe24f8a2Smrg  func_split_short_opt ()
1896fe24f8a2Smrg  {
1897fe24f8a2Smrg      $debug_cmd
1898fe24f8a2Smrg
1899fe24f8a2Smrg      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1900fe24f8a2Smrg      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1901fe24f8a2Smrg  }
1902fe24f8a2Smrgfi #func_split_short_opt
1903fe24f8a2Smrg
1904fe24f8a2Smrg
1905fe24f8a2Smrg# func_usage
1906fe24f8a2Smrg# ----------
1907fe24f8a2Smrg# Echo short help message to standard output and exit.
1908fe24f8a2Smrgfunc_usage ()
19093e72ca8cSmrg{
1910fe24f8a2Smrg    $debug_cmd
19113e72ca8cSmrg
1912fe24f8a2Smrg    func_usage_message
1913fe24f8a2Smrg    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
1914fe24f8a2Smrg    exit 0
1915fe24f8a2Smrg}
19163e72ca8cSmrg
19173e72ca8cSmrg
1918fe24f8a2Smrg# func_usage_message
1919fe24f8a2Smrg# ------------------
1920fe24f8a2Smrg# Echo short help message to standard output.
1921fe24f8a2Smrgfunc_usage_message ()
19223e72ca8cSmrg{
1923fe24f8a2Smrg    $debug_cmd
19243e72ca8cSmrg
1925fe24f8a2Smrg    eval \$ECHO \""Usage: $usage"\"
1926fe24f8a2Smrg    echo
1927fe24f8a2Smrg    $SED -n 's|^# ||
1928fe24f8a2Smrg        /^Written by/{
1929fe24f8a2Smrg          x;p;x
1930fe24f8a2Smrg        }
1931fe24f8a2Smrg	h
1932fe24f8a2Smrg	/^Written by/q' < "$progpath"
1933fe24f8a2Smrg    echo
1934fe24f8a2Smrg    eval \$ECHO \""$usage_message"\"
1935fe24f8a2Smrg}
19363e72ca8cSmrg
193734977a2fSmrg
1938fe24f8a2Smrg# func_version
1939fe24f8a2Smrg# ------------
1940fe24f8a2Smrg# Echo version message to standard output and exit.
1941fe24f8a2Smrgfunc_version ()
1942fe24f8a2Smrg{
1943fe24f8a2Smrg    $debug_cmd
194434977a2fSmrg
1945fe24f8a2Smrg    printf '%s\n' "$progname $scriptversion"
1946fe24f8a2Smrg    $SED -n '
1947fe24f8a2Smrg        /(C)/!b go
1948fe24f8a2Smrg        :more
1949fe24f8a2Smrg        /\./!{
1950fe24f8a2Smrg          N
1951fe24f8a2Smrg          s|\n# | |
1952fe24f8a2Smrg          b more
1953fe24f8a2Smrg        }
1954fe24f8a2Smrg        :go
1955fe24f8a2Smrg        /^# Written by /,/# warranty; / {
1956fe24f8a2Smrg          s|^# ||
1957fe24f8a2Smrg          s|^# *$||
1958fe24f8a2Smrg          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
1959fe24f8a2Smrg          p
1960fe24f8a2Smrg        }
1961fe24f8a2Smrg        /^# Written by / {
1962fe24f8a2Smrg          s|^# ||
1963fe24f8a2Smrg          p
1964fe24f8a2Smrg        }
1965fe24f8a2Smrg        /^warranty; /q' < "$progpath"
196634977a2fSmrg
1967fe24f8a2Smrg    exit $?
1968fe24f8a2Smrg}
196934977a2fSmrg
1970ee3138f1Smrg
1971fe24f8a2Smrg# Local variables:
1972fe24f8a2Smrg# mode: shell-script
1973fe24f8a2Smrg# sh-indentation: 2
1974fe24f8a2Smrg# eval: (add-hook 'before-save-hook 'time-stamp)
1975fe24f8a2Smrg# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1976fe24f8a2Smrg# time-stamp-time-zone: "UTC"
1977fe24f8a2Smrg# End:
1978ee3138f1Smrg
1979fe24f8a2Smrg# Set a version string.
1980fe24f8a2Smrgscriptversion='(GNU libtool) 2.4.6'
1981ee3138f1Smrg
198234977a2fSmrg
1983fe24f8a2Smrg# func_echo ARG...
1984fe24f8a2Smrg# ----------------
1985fe24f8a2Smrg# Libtool also displays the current mode in messages, so override
1986fe24f8a2Smrg# funclib.sh func_echo with this custom definition.
1987fe24f8a2Smrgfunc_echo ()
19883e72ca8cSmrg{
1989fe24f8a2Smrg    $debug_cmd
19903e72ca8cSmrg
1991fe24f8a2Smrg    _G_message=$*
19923e72ca8cSmrg
1993fe24f8a2Smrg    func_echo_IFS=$IFS
1994fe24f8a2Smrg    IFS=$nl
1995fe24f8a2Smrg    for _G_line in $_G_message; do
1996fe24f8a2Smrg      IFS=$func_echo_IFS
1997fe24f8a2Smrg      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
1998fe24f8a2Smrg    done
1999fe24f8a2Smrg    IFS=$func_echo_IFS
2000fe24f8a2Smrg}
20013e72ca8cSmrg
2002fe24f8a2Smrg
2003fe24f8a2Smrg# func_warning ARG...
2004fe24f8a2Smrg# -------------------
2005fe24f8a2Smrg# Libtool warnings are not categorized, so override funclib.sh
2006fe24f8a2Smrg# func_warning with this simpler definition.
2007fe24f8a2Smrgfunc_warning ()
20083e72ca8cSmrg{
2009fe24f8a2Smrg    $debug_cmd
20103e72ca8cSmrg
2011fe24f8a2Smrg    $warning_func ${1+"$@"}
2012fe24f8a2Smrg}
20133e72ca8cSmrg
20143e72ca8cSmrg
2015fe24f8a2Smrg## ---------------- ##
2016fe24f8a2Smrg## Options parsing. ##
2017fe24f8a2Smrg## ---------------- ##
2018fe24f8a2Smrg
2019fe24f8a2Smrg# Hook in the functions to make sure our own options are parsed during
2020fe24f8a2Smrg# the option parsing loop.
2021fe24f8a2Smrg
2022fe24f8a2Smrgusage='$progpath [OPTION]... [MODE-ARG]...'
2023fe24f8a2Smrg
2024fe24f8a2Smrg# Short help message in response to '-h'.
2025fe24f8a2Smrgusage_message="Options:
2026fe24f8a2Smrg       --config             show all configuration variables
2027fe24f8a2Smrg       --debug              enable verbose shell tracing
2028fe24f8a2Smrg   -n, --dry-run            display commands without modifying any files
2029fe24f8a2Smrg       --features           display basic configuration information and exit
2030fe24f8a2Smrg       --mode=MODE          use operation mode MODE
2031fe24f8a2Smrg       --no-warnings        equivalent to '-Wnone'
2032fe24f8a2Smrg       --preserve-dup-deps  don't remove duplicate dependency libraries
2033fe24f8a2Smrg       --quiet, --silent    don't print informational messages
2034fe24f8a2Smrg       --tag=TAG            use configuration variables from tag TAG
2035fe24f8a2Smrg   -v, --verbose            print more informational messages than default
2036fe24f8a2Smrg       --version            print version information
2037fe24f8a2Smrg   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2038fe24f8a2Smrg   -h, --help, --help-all   print short, long, or detailed help message
2039fe24f8a2Smrg"
20403e72ca8cSmrg
2041fe24f8a2Smrg# Additional text appended to 'usage_message' in response to '--help'.
2042fe24f8a2Smrgfunc_help ()
20433e72ca8cSmrg{
2044fe24f8a2Smrg    $debug_cmd
2045fe24f8a2Smrg
2046fe24f8a2Smrg    func_usage_message
2047fe24f8a2Smrg    $ECHO "$long_help_message
2048fe24f8a2Smrg
2049fe24f8a2SmrgMODE must be one of the following:
2050fe24f8a2Smrg
2051fe24f8a2Smrg       clean           remove files from the build directory
2052fe24f8a2Smrg       compile         compile a source file into a libtool object
2053fe24f8a2Smrg       execute         automatically set library path, then run a program
2054fe24f8a2Smrg       finish          complete the installation of libtool libraries
2055fe24f8a2Smrg       install         install libraries or executables
2056fe24f8a2Smrg       link            create a library or an executable
2057fe24f8a2Smrg       uninstall       remove libraries from an installed directory
2058fe24f8a2Smrg
2059fe24f8a2SmrgMODE-ARGS vary depending on the MODE.  When passed as first option,
2060fe24f8a2Smrg'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2061fe24f8a2SmrgTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2062fe24f8a2Smrg
2063fe24f8a2SmrgWhen reporting a bug, please describe a test case to reproduce it and
2064fe24f8a2Smrginclude the following information:
2065fe24f8a2Smrg
2066fe24f8a2Smrg       host-triplet:   $host
2067fe24f8a2Smrg       shell:          $SHELL
2068fe24f8a2Smrg       compiler:       $LTCC
2069fe24f8a2Smrg       compiler flags: $LTCFLAGS
2070fe24f8a2Smrg       linker:         $LD (gnu? $with_gnu_ld)
2071fe24f8a2Smrg       version:        $progname (GNU libtool) 2.4.6
2072fe24f8a2Smrg       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2073fe24f8a2Smrg       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2074fe24f8a2Smrg
2075fe24f8a2SmrgReport bugs to <bug-libtool@gnu.org>.
2076fe24f8a2SmrgGNU libtool home page: <http://www.gnu.org/software/libtool/>.
2077fe24f8a2SmrgGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2078fe24f8a2Smrg    exit 0
2079fe24f8a2Smrg}
20803e72ca8cSmrg
20813e72ca8cSmrg
2082fe24f8a2Smrg# func_lo2o OBJECT-NAME
2083fe24f8a2Smrg# ---------------------
2084fe24f8a2Smrg# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2085fe24f8a2Smrg# object suffix.
2086fe24f8a2Smrg
2087fe24f8a2Smrglo2o=s/\\.lo\$/.$objext/
2088fe24f8a2Smrgo2lo=s/\\.$objext\$/.lo/
2089fe24f8a2Smrg
2090fe24f8a2Smrgif test yes = "$_G_HAVE_XSI_OPS"; then
2091fe24f8a2Smrg  eval 'func_lo2o ()
2092fe24f8a2Smrg  {
2093fe24f8a2Smrg    case $1 in
2094fe24f8a2Smrg      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2095fe24f8a2Smrg      *   ) func_lo2o_result=$1               ;;
2096fe24f8a2Smrg    esac
2097fe24f8a2Smrg  }'
2098fe24f8a2Smrg
2099fe24f8a2Smrg  # func_xform LIBOBJ-OR-SOURCE
2100fe24f8a2Smrg  # ---------------------------
2101fe24f8a2Smrg  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2102fe24f8a2Smrg  # suffix to a '.lo' libtool-object suffix.
2103fe24f8a2Smrg  eval 'func_xform ()
2104fe24f8a2Smrg  {
2105fe24f8a2Smrg    func_xform_result=${1%.*}.lo
2106fe24f8a2Smrg  }'
2107fe24f8a2Smrgelse
2108fe24f8a2Smrg  # ...otherwise fall back to using sed.
2109fe24f8a2Smrg  func_lo2o ()
2110fe24f8a2Smrg  {
2111fe24f8a2Smrg    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2112fe24f8a2Smrg  }
2113fe24f8a2Smrg
2114fe24f8a2Smrg  func_xform ()
2115fe24f8a2Smrg  {
2116fe24f8a2Smrg    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2117fe24f8a2Smrg  }
2118fe24f8a2Smrgfi
21193e72ca8cSmrg
21203e72ca8cSmrg
2121fe24f8a2Smrg# func_fatal_configuration ARG...
2122fe24f8a2Smrg# -------------------------------
212334977a2fSmrg# Echo program name prefixed message to standard error, followed by
212434977a2fSmrg# a configuration failure hint, and exit.
212534977a2fSmrgfunc_fatal_configuration ()
212634977a2fSmrg{
2127fe24f8a2Smrg    func__fatal_error ${1+"$@"} \
2128fe24f8a2Smrg      "See the $PACKAGE documentation for more information." \
2129fe24f8a2Smrg      "Fatal configuration error."
213034977a2fSmrg}
2131ee3138f1Smrg
2132ee3138f1Smrg
213334977a2fSmrg# func_config
2134fe24f8a2Smrg# -----------
213534977a2fSmrg# Display the configuration for all the tags in this script.
213634977a2fSmrgfunc_config ()
213734977a2fSmrg{
213834977a2fSmrg    re_begincf='^# ### BEGIN LIBTOOL'
213934977a2fSmrg    re_endcf='^# ### END LIBTOOL'
214034977a2fSmrg
214134977a2fSmrg    # Default configuration.
214234977a2fSmrg    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
2143ee3138f1Smrg
2144ee3138f1Smrg    # Now print the configurations for the tags.
2145ee3138f1Smrg    for tagname in $taglist; do
214634977a2fSmrg      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
2147ee3138f1Smrg    done
2148ee3138f1Smrg
214934977a2fSmrg    exit $?
215034977a2fSmrg}
2151ee3138f1Smrg
2152fe24f8a2Smrg
215334977a2fSmrg# func_features
2154fe24f8a2Smrg# -------------
215534977a2fSmrg# Display the features supported by this script.
215634977a2fSmrgfunc_features ()
215734977a2fSmrg{
2158b425557eSmrg    echo "host: $host"
2159fe24f8a2Smrg    if test yes = "$build_libtool_libs"; then
2160b425557eSmrg      echo "enable shared libraries"
2161ee3138f1Smrg    else
2162b425557eSmrg      echo "disable shared libraries"
2163ee3138f1Smrg    fi
2164fe24f8a2Smrg    if test yes = "$build_old_libs"; then
2165b425557eSmrg      echo "enable static libraries"
2166ee3138f1Smrg    else
2167b425557eSmrg      echo "disable static libraries"
2168ee3138f1Smrg    fi
216934977a2fSmrg
2170ee3138f1Smrg    exit $?
217134977a2fSmrg}
2172ee3138f1Smrg
2173fe24f8a2Smrg
2174fe24f8a2Smrg# func_enable_tag TAGNAME
2175fe24f8a2Smrg# -----------------------
217634977a2fSmrg# Verify that TAGNAME is valid, and either flag an error and exit, or
217734977a2fSmrg# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
217834977a2fSmrg# variable here.
217934977a2fSmrgfunc_enable_tag ()
218034977a2fSmrg{
2181fe24f8a2Smrg    # Global variable:
2182fe24f8a2Smrg    tagname=$1
2183ee3138f1Smrg
2184fe24f8a2Smrg    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
2185fe24f8a2Smrg    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2186fe24f8a2Smrg    sed_extractcf=/$re_begincf/,/$re_endcf/p
2187ee3138f1Smrg
2188fe24f8a2Smrg    # Validate tagname.
2189fe24f8a2Smrg    case $tagname in
2190fe24f8a2Smrg      *[!-_A-Za-z0-9,/]*)
2191fe24f8a2Smrg        func_fatal_error "invalid tag name: $tagname"
2192fe24f8a2Smrg        ;;
2193fe24f8a2Smrg    esac
2194ee3138f1Smrg
2195fe24f8a2Smrg    # Don't test for the "default" C tag, as we know it's
2196fe24f8a2Smrg    # there but not specially marked.
2197fe24f8a2Smrg    case $tagname in
2198fe24f8a2Smrg        CC) ;;
219934977a2fSmrg    *)
2200fe24f8a2Smrg        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
2201fe24f8a2Smrg	  taglist="$taglist $tagname"
2202fe24f8a2Smrg
2203fe24f8a2Smrg	  # Evaluate the configuration.  Be careful to quote the path
2204fe24f8a2Smrg	  # and the sed script, to avoid splitting on whitespace, but
2205fe24f8a2Smrg	  # also don't use non-portable quotes within backquotes within
2206fe24f8a2Smrg	  # quotes we have to do it in 2 steps:
2207fe24f8a2Smrg	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
2208fe24f8a2Smrg	  eval "$extractedcf"
2209fe24f8a2Smrg        else
2210fe24f8a2Smrg	  func_error "ignoring unknown tag $tagname"
2211fe24f8a2Smrg        fi
2212fe24f8a2Smrg        ;;
2213fe24f8a2Smrg    esac
221434977a2fSmrg}
221534977a2fSmrg
2216fe24f8a2Smrg
22173e72ca8cSmrg# func_check_version_match
2218fe24f8a2Smrg# ------------------------
22193e72ca8cSmrg# Ensure that we are using m4 macros, and libtool script from the same
22203e72ca8cSmrg# release of libtool.
22213e72ca8cSmrgfunc_check_version_match ()
222234977a2fSmrg{
2223fe24f8a2Smrg    if test "$package_revision" != "$macro_revision"; then
2224fe24f8a2Smrg      if test "$VERSION" != "$macro_version"; then
2225fe24f8a2Smrg        if test -z "$macro_version"; then
2226fe24f8a2Smrg          cat >&2 <<_LT_EOF
22273e72ca8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
22283e72ca8cSmrg$progname: definition of this LT_INIT comes from an older release.
22293e72ca8cSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
22303e72ca8cSmrg$progname: and run autoconf again.
22313e72ca8cSmrg_LT_EOF
2232fe24f8a2Smrg        else
2233fe24f8a2Smrg          cat >&2 <<_LT_EOF
22343e72ca8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
22353e72ca8cSmrg$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
22363e72ca8cSmrg$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
22373e72ca8cSmrg$progname: and run autoconf again.
22383e72ca8cSmrg_LT_EOF
2239fe24f8a2Smrg        fi
2240fe24f8a2Smrg      else
2241fe24f8a2Smrg        cat >&2 <<_LT_EOF
22423e72ca8cSmrg$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
22433e72ca8cSmrg$progname: but the definition of this LT_INIT comes from revision $macro_revision.
22443e72ca8cSmrg$progname: You should recreate aclocal.m4 with macros from revision $package_revision
22453e72ca8cSmrg$progname: of $PACKAGE $VERSION and run autoconf again.
22463e72ca8cSmrg_LT_EOF
2247fe24f8a2Smrg      fi
22483e72ca8cSmrg
2249fe24f8a2Smrg      exit $EXIT_MISMATCH
2250fe24f8a2Smrg    fi
22513e72ca8cSmrg}
22523e72ca8cSmrg
22533e72ca8cSmrg
2254fe24f8a2Smrg# libtool_options_prep [ARG]...
2255fe24f8a2Smrg# -----------------------------
2256fe24f8a2Smrg# Preparation for options parsed by libtool.
2257fe24f8a2Smrglibtool_options_prep ()
2258fe24f8a2Smrg{
2259fe24f8a2Smrg    $debug_mode
22603e72ca8cSmrg
2261fe24f8a2Smrg    # Option defaults:
2262fe24f8a2Smrg    opt_config=false
2263fe24f8a2Smrg    opt_dlopen=
2264fe24f8a2Smrg    opt_dry_run=false
2265fe24f8a2Smrg    opt_help=false
2266fe24f8a2Smrg    opt_mode=
2267fe24f8a2Smrg    opt_preserve_dup_deps=false
2268fe24f8a2Smrg    opt_quiet=false
22693e72ca8cSmrg
2270fe24f8a2Smrg    nonopt=
2271fe24f8a2Smrg    preserve_args=
22723e72ca8cSmrg
2273fe24f8a2Smrg    # Shorthand for --mode=foo, only valid as the first argument
2274fe24f8a2Smrg    case $1 in
2275fe24f8a2Smrg    clean|clea|cle|cl)
2276fe24f8a2Smrg      shift; set dummy --mode clean ${1+"$@"}; shift
2277fe24f8a2Smrg      ;;
2278fe24f8a2Smrg    compile|compil|compi|comp|com|co|c)
2279fe24f8a2Smrg      shift; set dummy --mode compile ${1+"$@"}; shift
2280fe24f8a2Smrg      ;;
2281fe24f8a2Smrg    execute|execut|execu|exec|exe|ex|e)
2282fe24f8a2Smrg      shift; set dummy --mode execute ${1+"$@"}; shift
2283fe24f8a2Smrg      ;;
2284fe24f8a2Smrg    finish|finis|fini|fin|fi|f)
2285fe24f8a2Smrg      shift; set dummy --mode finish ${1+"$@"}; shift
2286fe24f8a2Smrg      ;;
2287fe24f8a2Smrg    install|instal|insta|inst|ins|in|i)
2288fe24f8a2Smrg      shift; set dummy --mode install ${1+"$@"}; shift
2289fe24f8a2Smrg      ;;
2290fe24f8a2Smrg    link|lin|li|l)
2291fe24f8a2Smrg      shift; set dummy --mode link ${1+"$@"}; shift
2292fe24f8a2Smrg      ;;
2293fe24f8a2Smrg    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
2294fe24f8a2Smrg      shift; set dummy --mode uninstall ${1+"$@"}; shift
2295fe24f8a2Smrg      ;;
2296fe24f8a2Smrg    esac
2297fe24f8a2Smrg
2298fe24f8a2Smrg    # Pass back the list of options.
2299fe24f8a2Smrg    func_quote_for_eval ${1+"$@"}
2300fe24f8a2Smrg    libtool_options_prep_result=$func_quote_for_eval_result
2301fe24f8a2Smrg}
2302fe24f8a2Smrgfunc_add_hook func_options_prep libtool_options_prep
2303ee3138f1Smrg
2304ee3138f1Smrg
2305fe24f8a2Smrg# libtool_parse_options [ARG]...
2306fe24f8a2Smrg# ---------------------------------
2307fe24f8a2Smrg# Provide handling for libtool specific options.
2308fe24f8a2Smrglibtool_parse_options ()
23093e72ca8cSmrg{
2310fe24f8a2Smrg    $debug_cmd
231134977a2fSmrg
2312fe24f8a2Smrg    # Perform our own loop to consume as many options as possible in
2313fe24f8a2Smrg    # each iteration.
2314fe24f8a2Smrg    while test $# -gt 0; do
2315fe24f8a2Smrg      _G_opt=$1
2316fe24f8a2Smrg      shift
2317fe24f8a2Smrg      case $_G_opt in
2318fe24f8a2Smrg        --dry-run|--dryrun|-n)
2319fe24f8a2Smrg                        opt_dry_run=:
2320fe24f8a2Smrg                        ;;
2321fe24f8a2Smrg
2322fe24f8a2Smrg        --config)       func_config ;;
2323fe24f8a2Smrg
2324fe24f8a2Smrg        --dlopen|-dlopen)
2325fe24f8a2Smrg                        opt_dlopen="${opt_dlopen+$opt_dlopen
2326fe24f8a2Smrg}$1"
2327fe24f8a2Smrg                        shift
2328fe24f8a2Smrg                        ;;
2329fe24f8a2Smrg
2330fe24f8a2Smrg        --preserve-dup-deps)
2331fe24f8a2Smrg                        opt_preserve_dup_deps=: ;;
2332fe24f8a2Smrg
2333fe24f8a2Smrg        --features)     func_features ;;
2334fe24f8a2Smrg
2335fe24f8a2Smrg        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2336fe24f8a2Smrg
2337fe24f8a2Smrg        --help)         opt_help=: ;;
2338fe24f8a2Smrg
2339fe24f8a2Smrg        --help-all)     opt_help=': help-all' ;;
2340fe24f8a2Smrg
2341fe24f8a2Smrg        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2342fe24f8a2Smrg                        opt_mode=$1
2343fe24f8a2Smrg                        case $1 in
2344fe24f8a2Smrg                          # Valid mode arguments:
2345fe24f8a2Smrg                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
2346fe24f8a2Smrg
2347fe24f8a2Smrg                          # Catch anything else as an error
2348fe24f8a2Smrg                          *) func_error "invalid argument for $_G_opt"
2349fe24f8a2Smrg                             exit_cmd=exit
2350fe24f8a2Smrg                             break
2351fe24f8a2Smrg                             ;;
2352fe24f8a2Smrg                        esac
2353fe24f8a2Smrg                        shift
2354fe24f8a2Smrg                        ;;
2355fe24f8a2Smrg
2356fe24f8a2Smrg        --no-silent|--no-quiet)
2357fe24f8a2Smrg                        opt_quiet=false
2358fe24f8a2Smrg                        func_append preserve_args " $_G_opt"
2359fe24f8a2Smrg                        ;;
2360fe24f8a2Smrg
2361fe24f8a2Smrg        --no-warnings|--no-warning|--no-warn)
2362fe24f8a2Smrg                        opt_warning=false
2363fe24f8a2Smrg                        func_append preserve_args " $_G_opt"
2364fe24f8a2Smrg                        ;;
2365fe24f8a2Smrg
2366fe24f8a2Smrg        --no-verbose)
2367fe24f8a2Smrg                        opt_verbose=false
2368fe24f8a2Smrg                        func_append preserve_args " $_G_opt"
2369fe24f8a2Smrg                        ;;
2370fe24f8a2Smrg
2371fe24f8a2Smrg        --silent|--quiet)
2372fe24f8a2Smrg                        opt_quiet=:
2373fe24f8a2Smrg                        opt_verbose=false
2374fe24f8a2Smrg                        func_append preserve_args " $_G_opt"
2375fe24f8a2Smrg                        ;;
2376fe24f8a2Smrg
2377fe24f8a2Smrg        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2378fe24f8a2Smrg                        opt_tag=$1
2379fe24f8a2Smrg                        func_append preserve_args " $_G_opt $1"
2380fe24f8a2Smrg                        func_enable_tag "$1"
2381fe24f8a2Smrg                        shift
2382fe24f8a2Smrg                        ;;
2383fe24f8a2Smrg
2384fe24f8a2Smrg        --verbose|-v)   opt_quiet=false
2385fe24f8a2Smrg                        opt_verbose=:
2386fe24f8a2Smrg                        func_append preserve_args " $_G_opt"
2387fe24f8a2Smrg                        ;;
2388fe24f8a2Smrg
2389fe24f8a2Smrg	# An option not handled by this hook function:
2390fe24f8a2Smrg        *)		set dummy "$_G_opt" ${1+"$@"};	shift; break  ;;
2391fe24f8a2Smrg      esac
2392fe24f8a2Smrg    done
23933e72ca8cSmrg
23943e72ca8cSmrg
2395fe24f8a2Smrg    # save modified positional parameters for caller
2396fe24f8a2Smrg    func_quote_for_eval ${1+"$@"}
2397fe24f8a2Smrg    libtool_parse_options_result=$func_quote_for_eval_result
2398fe24f8a2Smrg}
2399fe24f8a2Smrgfunc_add_hook func_parse_options libtool_parse_options
240034977a2fSmrg
2401ee3138f1Smrg
240234977a2fSmrg
2403fe24f8a2Smrg# libtool_validate_options [ARG]...
2404fe24f8a2Smrg# ---------------------------------
2405fe24f8a2Smrg# Perform any sanity checks on option settings and/or unconsumed
2406fe24f8a2Smrg# arguments.
2407fe24f8a2Smrglibtool_validate_options ()
2408fe24f8a2Smrg{
2409fe24f8a2Smrg    # save first non-option argument
2410fe24f8a2Smrg    if test 0 -lt $#; then
2411fe24f8a2Smrg      nonopt=$1
2412fe24f8a2Smrg      shift
241334977a2fSmrg    fi
241434977a2fSmrg
2415fe24f8a2Smrg    # preserve --debug
2416fe24f8a2Smrg    test : = "$debug_cmd" || func_append preserve_args " --debug"
241734977a2fSmrg
2418fe24f8a2Smrg    case $host in
2419fe24f8a2Smrg      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2420fe24f8a2Smrg      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2421fe24f8a2Smrg      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
2422fe24f8a2Smrg        # don't eliminate duplications in $postdeps and $predeps
2423fe24f8a2Smrg        opt_duplicate_compiler_generated_deps=:
2424fe24f8a2Smrg        ;;
2425fe24f8a2Smrg      *)
2426fe24f8a2Smrg        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
2427fe24f8a2Smrg        ;;
2428fe24f8a2Smrg    esac
242934977a2fSmrg
2430fe24f8a2Smrg    $opt_help || {
2431fe24f8a2Smrg      # Sanity checks first:
2432fe24f8a2Smrg      func_check_version_match
2433fe24f8a2Smrg
2434fe24f8a2Smrg      test yes != "$build_libtool_libs" \
2435fe24f8a2Smrg        && test yes != "$build_old_libs" \
2436fe24f8a2Smrg        && func_fatal_configuration "not configured to build any kind of library"
2437fe24f8a2Smrg
2438fe24f8a2Smrg      # Darwin sucks
2439fe24f8a2Smrg      eval std_shrext=\"$shrext_cmds\"
2440fe24f8a2Smrg
2441fe24f8a2Smrg      # Only execute mode is allowed to have -dlopen flags.
2442fe24f8a2Smrg      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2443fe24f8a2Smrg        func_error "unrecognized option '-dlopen'"
2444fe24f8a2Smrg        $ECHO "$help" 1>&2
2445fe24f8a2Smrg        exit $EXIT_FAILURE
2446fe24f8a2Smrg      fi
244734977a2fSmrg
2448fe24f8a2Smrg      # Change the help message to a mode-specific one.
2449fe24f8a2Smrg      generic_help=$help
2450fe24f8a2Smrg      help="Try '$progname --help --mode=$opt_mode' for more information."
2451fe24f8a2Smrg    }
245234977a2fSmrg
2453fe24f8a2Smrg    # Pass back the unparsed argument list
2454fe24f8a2Smrg    func_quote_for_eval ${1+"$@"}
2455fe24f8a2Smrg    libtool_validate_options_result=$func_quote_for_eval_result
24563e72ca8cSmrg}
2457fe24f8a2Smrgfunc_add_hook func_validate_options libtool_validate_options
245834977a2fSmrg
2459ee3138f1Smrg
2460fe24f8a2Smrg# Process options as early as possible so that --help and --version
2461fe24f8a2Smrg# can return quickly.
2462fe24f8a2Smrgfunc_options ${1+"$@"}
2463fe24f8a2Smrgeval set dummy "$func_options_result"; shift
2464fe24f8a2Smrg
2465ee3138f1Smrg
2466ee3138f1Smrg
24673e72ca8cSmrg## ----------- ##
24683e72ca8cSmrg##    Main.    ##
24693e72ca8cSmrg## ----------- ##
2470ee3138f1Smrg
2471fe24f8a2Smrgmagic='%%%MAGIC variable%%%'
2472fe24f8a2Smrgmagic_exe='%%%MAGIC EXE variable%%%'
2473fe24f8a2Smrg
2474fe24f8a2Smrg# Global variables.
2475fe24f8a2Smrgextracted_archives=
2476fe24f8a2Smrgextracted_serial=0
2477fe24f8a2Smrg
2478fe24f8a2Smrg# If this variable is set in any of the actions, the command in it
2479fe24f8a2Smrg# will be execed at the end.  This prevents here-documents from being
2480fe24f8a2Smrg# left over by shells.
2481fe24f8a2Smrgexec_cmd=
2482fe24f8a2Smrg
2483fe24f8a2Smrg
2484fe24f8a2Smrg# A function that is used when there is no print builtin or printf.
2485fe24f8a2Smrgfunc_fallback_echo ()
2486fe24f8a2Smrg{
2487fe24f8a2Smrg  eval 'cat <<_LTECHO_EOF
2488fe24f8a2Smrg$1
2489fe24f8a2Smrg_LTECHO_EOF'
2490fe24f8a2Smrg}
2491fe24f8a2Smrg
2492fe24f8a2Smrg# func_generated_by_libtool
2493fe24f8a2Smrg# True iff stdin has been generated by Libtool. This function is only
2494fe24f8a2Smrg# a basic sanity check; it will hardly flush out determined imposters.
2495fe24f8a2Smrgfunc_generated_by_libtool_p ()
2496fe24f8a2Smrg{
2497fe24f8a2Smrg  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2498fe24f8a2Smrg}
2499fe24f8a2Smrg
250034977a2fSmrg# func_lalib_p file
2501fe24f8a2Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
250234977a2fSmrg# This function is only a basic sanity check; it will hardly flush out
250334977a2fSmrg# determined imposters.
250434977a2fSmrgfunc_lalib_p ()
250534977a2fSmrg{
250634977a2fSmrg    test -f "$1" &&
2507fe24f8a2Smrg      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
250834977a2fSmrg}
2509ee3138f1Smrg
251034977a2fSmrg# func_lalib_unsafe_p file
2511fe24f8a2Smrg# True iff FILE is a libtool '.la' library or '.lo' object file.
251234977a2fSmrg# This function implements the same check as func_lalib_p without
251334977a2fSmrg# resorting to external programs.  To this end, it redirects stdin and
251434977a2fSmrg# closes it afterwards, without saving the original file descriptor.
251534977a2fSmrg# As a safety measure, use it only where a negative result would be
2516fe24f8a2Smrg# fatal anyway.  Works if 'file' does not exist.
251734977a2fSmrgfunc_lalib_unsafe_p ()
251834977a2fSmrg{
251934977a2fSmrg    lalib_p=no
252034977a2fSmrg    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
252134977a2fSmrg	for lalib_p_l in 1 2 3 4
252234977a2fSmrg	do
252334977a2fSmrg	    read lalib_p_line
2524fe24f8a2Smrg	    case $lalib_p_line in
252534977a2fSmrg		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
252634977a2fSmrg	    esac
252734977a2fSmrg	done
252834977a2fSmrg	exec 0<&5 5<&-
252934977a2fSmrg    fi
2530fe24f8a2Smrg    test yes = "$lalib_p"
253134977a2fSmrg}
2532ee3138f1Smrg
253334977a2fSmrg# func_ltwrapper_script_p file
253434977a2fSmrg# True iff FILE is a libtool wrapper script
253534977a2fSmrg# This function is only a basic sanity check; it will hardly flush out
253634977a2fSmrg# determined imposters.
253734977a2fSmrgfunc_ltwrapper_script_p ()
253834977a2fSmrg{
2539fe24f8a2Smrg    test -f "$1" &&
2540fe24f8a2Smrg      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
254134977a2fSmrg}
2542ee3138f1Smrg
254334977a2fSmrg# func_ltwrapper_executable_p file
254434977a2fSmrg# True iff FILE is a libtool wrapper executable
254534977a2fSmrg# This function is only a basic sanity check; it will hardly flush out
254634977a2fSmrg# determined imposters.
254734977a2fSmrgfunc_ltwrapper_executable_p ()
254834977a2fSmrg{
254934977a2fSmrg    func_ltwrapper_exec_suffix=
255034977a2fSmrg    case $1 in
255134977a2fSmrg    *.exe) ;;
255234977a2fSmrg    *) func_ltwrapper_exec_suffix=.exe ;;
255334977a2fSmrg    esac
255434977a2fSmrg    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
255534977a2fSmrg}
255634977a2fSmrg
255734977a2fSmrg# func_ltwrapper_scriptname file
255834977a2fSmrg# Assumes file is an ltwrapper_executable
255934977a2fSmrg# uses $file to determine the appropriate filename for a
256034977a2fSmrg# temporary ltwrapper_script.
256134977a2fSmrgfunc_ltwrapper_scriptname ()
256234977a2fSmrg{
25633e72ca8cSmrg    func_dirname_and_basename "$1" "" "."
25643e72ca8cSmrg    func_stripname '' '.exe' "$func_basename_result"
2565fe24f8a2Smrg    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
256634977a2fSmrg}
256734977a2fSmrg
256834977a2fSmrg# func_ltwrapper_p file
256934977a2fSmrg# True iff FILE is a libtool wrapper script or wrapper executable
257034977a2fSmrg# This function is only a basic sanity check; it will hardly flush out
257134977a2fSmrg# determined imposters.
257234977a2fSmrgfunc_ltwrapper_p ()
257334977a2fSmrg{
257434977a2fSmrg    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
257534977a2fSmrg}
257634977a2fSmrg
257734977a2fSmrg
257834977a2fSmrg# func_execute_cmds commands fail_cmd
257934977a2fSmrg# Execute tilde-delimited COMMANDS.
258034977a2fSmrg# If FAIL_CMD is given, eval that upon failure.
258134977a2fSmrg# FAIL_CMD may read-access the current command in variable CMD!
258234977a2fSmrgfunc_execute_cmds ()
258334977a2fSmrg{
2584fe24f8a2Smrg    $debug_cmd
2585fe24f8a2Smrg
258634977a2fSmrg    save_ifs=$IFS; IFS='~'
258734977a2fSmrg    for cmd in $1; do
2588fe24f8a2Smrg      IFS=$sp$nl
258934977a2fSmrg      eval cmd=\"$cmd\"
2590fe24f8a2Smrg      IFS=$save_ifs
259134977a2fSmrg      func_show_eval "$cmd" "${2-:}"
259234977a2fSmrg    done
259334977a2fSmrg    IFS=$save_ifs
259434977a2fSmrg}
259534977a2fSmrg
259634977a2fSmrg
259734977a2fSmrg# func_source file
259834977a2fSmrg# Source FILE, adding directory component if necessary.
259934977a2fSmrg# Note that it is not necessary on cygwin/mingw to append a dot to
260034977a2fSmrg# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
260134977a2fSmrg# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2602fe24f8a2Smrg# 'FILE.' does not work on cygwin managed mounts.
260334977a2fSmrgfunc_source ()
260434977a2fSmrg{
2605fe24f8a2Smrg    $debug_cmd
2606fe24f8a2Smrg
260734977a2fSmrg    case $1 in
260834977a2fSmrg    */* | *\\*)	. "$1" ;;
260934977a2fSmrg    *)		. "./$1" ;;
261034977a2fSmrg    esac
261134977a2fSmrg}
261234977a2fSmrg
261334977a2fSmrg
26143e72ca8cSmrg# func_resolve_sysroot PATH
26153e72ca8cSmrg# Replace a leading = in PATH with a sysroot.  Store the result into
26163e72ca8cSmrg# func_resolve_sysroot_result
26173e72ca8cSmrgfunc_resolve_sysroot ()
26183e72ca8cSmrg{
26193e72ca8cSmrg  func_resolve_sysroot_result=$1
26203e72ca8cSmrg  case $func_resolve_sysroot_result in
26213e72ca8cSmrg  =*)
26223e72ca8cSmrg    func_stripname '=' '' "$func_resolve_sysroot_result"
26233e72ca8cSmrg    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
26243e72ca8cSmrg    ;;
26253e72ca8cSmrg  esac
26263e72ca8cSmrg}
26273e72ca8cSmrg
26283e72ca8cSmrg# func_replace_sysroot PATH
26293e72ca8cSmrg# If PATH begins with the sysroot, replace it with = and
26303e72ca8cSmrg# store the result into func_replace_sysroot_result.
26313e72ca8cSmrgfunc_replace_sysroot ()
26323e72ca8cSmrg{
2633fe24f8a2Smrg  case $lt_sysroot:$1 in
26343e72ca8cSmrg  ?*:"$lt_sysroot"*)
26353e72ca8cSmrg    func_stripname "$lt_sysroot" '' "$1"
2636fe24f8a2Smrg    func_replace_sysroot_result='='$func_stripname_result
26373e72ca8cSmrg    ;;
26383e72ca8cSmrg  *)
26393e72ca8cSmrg    # Including no sysroot.
26403e72ca8cSmrg    func_replace_sysroot_result=$1
26413e72ca8cSmrg    ;;
26423e72ca8cSmrg  esac
26433e72ca8cSmrg}
26443e72ca8cSmrg
264534977a2fSmrg# func_infer_tag arg
264634977a2fSmrg# Infer tagged configuration to use if any are available and
264734977a2fSmrg# if one wasn't chosen via the "--tag" command line option.
264834977a2fSmrg# Only attempt this if the compiler in the base compile
264934977a2fSmrg# command doesn't match the default compiler.
265034977a2fSmrg# arg is usually of the form 'gcc ...'
265134977a2fSmrgfunc_infer_tag ()
265234977a2fSmrg{
2653fe24f8a2Smrg    $debug_cmd
2654fe24f8a2Smrg
265534977a2fSmrg    if test -n "$available_tags" && test -z "$tagname"; then
265634977a2fSmrg      CC_quoted=
265734977a2fSmrg      for arg in $CC; do
26583e72ca8cSmrg	func_append_quoted CC_quoted "$arg"
265934977a2fSmrg      done
2660b425557eSmrg      CC_expanded=`func_echo_all $CC`
2661b425557eSmrg      CC_quoted_expanded=`func_echo_all $CC_quoted`
266234977a2fSmrg      case $@ in
266334977a2fSmrg      # Blanks in the command may have been stripped by the calling shell,
266434977a2fSmrg      # but not from the CC environment variable when configure was run.
2665b425557eSmrg      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2666b425557eSmrg      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
266734977a2fSmrg      # Blanks at the start of $base_compile will cause this to fail
266834977a2fSmrg      # if we don't check for them as well.
266934977a2fSmrg      *)
267034977a2fSmrg	for z in $available_tags; do
267134977a2fSmrg	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
267234977a2fSmrg	    # Evaluate the configuration.
2673fe24f8a2Smrg	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
267434977a2fSmrg	    CC_quoted=
267534977a2fSmrg	    for arg in $CC; do
267634977a2fSmrg	      # Double-quote args containing other shell metacharacters.
26773e72ca8cSmrg	      func_append_quoted CC_quoted "$arg"
267834977a2fSmrg	    done
2679b425557eSmrg	    CC_expanded=`func_echo_all $CC`
2680b425557eSmrg	    CC_quoted_expanded=`func_echo_all $CC_quoted`
268134977a2fSmrg	    case "$@ " in
2682b425557eSmrg	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
2683b425557eSmrg	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
268434977a2fSmrg	      # The compiler in the base compile command matches
268534977a2fSmrg	      # the one in the tagged configuration.
268634977a2fSmrg	      # Assume this is the tagged configuration we want.
268734977a2fSmrg	      tagname=$z
268834977a2fSmrg	      break
268934977a2fSmrg	      ;;
269034977a2fSmrg	    esac
269134977a2fSmrg	  fi
269234977a2fSmrg	done
269334977a2fSmrg	# If $tagname still isn't set, then no tagged configuration
269434977a2fSmrg	# was found and let the user know that the "--tag" command
269534977a2fSmrg	# line option must be used.
269634977a2fSmrg	if test -z "$tagname"; then
269734977a2fSmrg	  func_echo "unable to infer tagged configuration"
2698fe24f8a2Smrg	  func_fatal_error "specify a tag with '--tag'"
269934977a2fSmrg#	else
270034977a2fSmrg#	  func_verbose "using $tagname tagged configuration"
270134977a2fSmrg	fi
270234977a2fSmrg	;;
270334977a2fSmrg      esac
270434977a2fSmrg    fi
270534977a2fSmrg}
270634977a2fSmrg
270734977a2fSmrg
27083e72ca8cSmrg
27093e72ca8cSmrg# func_write_libtool_object output_name pic_name nonpic_name
27103e72ca8cSmrg# Create a libtool object file (analogous to a ".la" file),
27113e72ca8cSmrg# but don't create it if we're doing a dry run.
27123e72ca8cSmrgfunc_write_libtool_object ()
27133e72ca8cSmrg{
2714fe24f8a2Smrg    write_libobj=$1
2715fe24f8a2Smrg    if test yes = "$build_libtool_libs"; then
2716fe24f8a2Smrg      write_lobj=\'$2\'
27173e72ca8cSmrg    else
27183e72ca8cSmrg      write_lobj=none
27193e72ca8cSmrg    fi
27203e72ca8cSmrg
2721fe24f8a2Smrg    if test yes = "$build_old_libs"; then
2722fe24f8a2Smrg      write_oldobj=\'$3\'
27233e72ca8cSmrg    else
27243e72ca8cSmrg      write_oldobj=none
27253e72ca8cSmrg    fi
27263e72ca8cSmrg
27273e72ca8cSmrg    $opt_dry_run || {
27283e72ca8cSmrg      cat >${write_libobj}T <<EOF
27293e72ca8cSmrg# $write_libobj - a libtool object file
2730fe24f8a2Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
27313e72ca8cSmrg#
27323e72ca8cSmrg# Please DO NOT delete this file!
27333e72ca8cSmrg# It is necessary for linking the library.
27343e72ca8cSmrg
27353e72ca8cSmrg# Name of the PIC object.
27363e72ca8cSmrgpic_object=$write_lobj
27373e72ca8cSmrg
27383e72ca8cSmrg# Name of the non-PIC object
27393e72ca8cSmrgnon_pic_object=$write_oldobj
27403e72ca8cSmrg
27413e72ca8cSmrgEOF
2742fe24f8a2Smrg      $MV "${write_libobj}T" "$write_libobj"
27433e72ca8cSmrg    }
27443e72ca8cSmrg}
27453e72ca8cSmrg
27463e72ca8cSmrg
27473e72ca8cSmrg##################################################
27483e72ca8cSmrg# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
27493e72ca8cSmrg##################################################
27503e72ca8cSmrg
27513e72ca8cSmrg# func_convert_core_file_wine_to_w32 ARG
27523e72ca8cSmrg# Helper function used by file name conversion functions when $build is *nix,
27533e72ca8cSmrg# and $host is mingw, cygwin, or some other w32 environment. Relies on a
27543e72ca8cSmrg# correctly configured wine environment available, with the winepath program
27553e72ca8cSmrg# in $build's $PATH.
27563e72ca8cSmrg#
27573e72ca8cSmrg# ARG is the $build file name to be converted to w32 format.
27583e72ca8cSmrg# Result is available in $func_convert_core_file_wine_to_w32_result, and will
27593e72ca8cSmrg# be empty on error (or when ARG is empty)
27603e72ca8cSmrgfunc_convert_core_file_wine_to_w32 ()
27613e72ca8cSmrg{
2762fe24f8a2Smrg  $debug_cmd
2763fe24f8a2Smrg
2764fe24f8a2Smrg  func_convert_core_file_wine_to_w32_result=$1
27653e72ca8cSmrg  if test -n "$1"; then
27663e72ca8cSmrg    # Unfortunately, winepath does not exit with a non-zero error code, so we
27673e72ca8cSmrg    # are forced to check the contents of stdout. On the other hand, if the
27683e72ca8cSmrg    # command is not found, the shell will set an exit code of 127 and print
27693e72ca8cSmrg    # *an error message* to stdout. So we must check for both error code of
27703e72ca8cSmrg    # zero AND non-empty stdout, which explains the odd construction:
27713e72ca8cSmrg    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
2772fe24f8a2Smrg    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
27733e72ca8cSmrg      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
2774fe24f8a2Smrg        $SED -e "$sed_naive_backslashify"`
27753e72ca8cSmrg    else
27763e72ca8cSmrg      func_convert_core_file_wine_to_w32_result=
27773e72ca8cSmrg    fi
27783e72ca8cSmrg  fi
27793e72ca8cSmrg}
27803e72ca8cSmrg# end: func_convert_core_file_wine_to_w32
27813e72ca8cSmrg
27823e72ca8cSmrg
27833e72ca8cSmrg# func_convert_core_path_wine_to_w32 ARG
27843e72ca8cSmrg# Helper function used by path conversion functions when $build is *nix, and
27853e72ca8cSmrg# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
27863e72ca8cSmrg# configured wine environment available, with the winepath program in $build's
27873e72ca8cSmrg# $PATH. Assumes ARG has no leading or trailing path separator characters.
27883e72ca8cSmrg#
27893e72ca8cSmrg# ARG is path to be converted from $build format to win32.
27903e72ca8cSmrg# Result is available in $func_convert_core_path_wine_to_w32_result.
27913e72ca8cSmrg# Unconvertible file (directory) names in ARG are skipped; if no directory names
27923e72ca8cSmrg# are convertible, then the result may be empty.
27933e72ca8cSmrgfunc_convert_core_path_wine_to_w32 ()
27943e72ca8cSmrg{
2795fe24f8a2Smrg  $debug_cmd
2796fe24f8a2Smrg
27973e72ca8cSmrg  # unfortunately, winepath doesn't convert paths, only file names
2798fe24f8a2Smrg  func_convert_core_path_wine_to_w32_result=
27993e72ca8cSmrg  if test -n "$1"; then
28003e72ca8cSmrg    oldIFS=$IFS
28013e72ca8cSmrg    IFS=:
28023e72ca8cSmrg    for func_convert_core_path_wine_to_w32_f in $1; do
28033e72ca8cSmrg      IFS=$oldIFS
28043e72ca8cSmrg      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
2805fe24f8a2Smrg      if test -n "$func_convert_core_file_wine_to_w32_result"; then
28063e72ca8cSmrg        if test -z "$func_convert_core_path_wine_to_w32_result"; then
2807fe24f8a2Smrg          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
28083e72ca8cSmrg        else
28093e72ca8cSmrg          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
28103e72ca8cSmrg        fi
28113e72ca8cSmrg      fi
28123e72ca8cSmrg    done
28133e72ca8cSmrg    IFS=$oldIFS
28143e72ca8cSmrg  fi
28153e72ca8cSmrg}
28163e72ca8cSmrg# end: func_convert_core_path_wine_to_w32
28173e72ca8cSmrg
28183e72ca8cSmrg
28193e72ca8cSmrg# func_cygpath ARGS...
28203e72ca8cSmrg# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
28213e72ca8cSmrg# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
28223e72ca8cSmrg# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
28233e72ca8cSmrg# (2), returns the Cygwin file name or path in func_cygpath_result (input
28243e72ca8cSmrg# file name or path is assumed to be in w32 format, as previously converted
28253e72ca8cSmrg# from $build's *nix or MSYS format). In case (3), returns the w32 file name
28263e72ca8cSmrg# or path in func_cygpath_result (input file name or path is assumed to be in
28273e72ca8cSmrg# Cygwin format). Returns an empty string on error.
28283e72ca8cSmrg#
28293e72ca8cSmrg# ARGS are passed to cygpath, with the last one being the file name or path to
28303e72ca8cSmrg# be converted.
28313e72ca8cSmrg#
28323e72ca8cSmrg# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
28333e72ca8cSmrg# environment variable; do not put it in $PATH.
28343e72ca8cSmrgfunc_cygpath ()
28353e72ca8cSmrg{
2836fe24f8a2Smrg  $debug_cmd
2837fe24f8a2Smrg
28383e72ca8cSmrg  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
28393e72ca8cSmrg    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
28403e72ca8cSmrg    if test "$?" -ne 0; then
28413e72ca8cSmrg      # on failure, ensure result is empty
28423e72ca8cSmrg      func_cygpath_result=
28433e72ca8cSmrg    fi
28443e72ca8cSmrg  else
28453e72ca8cSmrg    func_cygpath_result=
2846fe24f8a2Smrg    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
28473e72ca8cSmrg  fi
28483e72ca8cSmrg}
28493e72ca8cSmrg#end: func_cygpath
28503e72ca8cSmrg
28513e72ca8cSmrg
28523e72ca8cSmrg# func_convert_core_msys_to_w32 ARG
28533e72ca8cSmrg# Convert file name or path ARG from MSYS format to w32 format.  Return
28543e72ca8cSmrg# result in func_convert_core_msys_to_w32_result.
28553e72ca8cSmrgfunc_convert_core_msys_to_w32 ()
28563e72ca8cSmrg{
2857fe24f8a2Smrg  $debug_cmd
2858fe24f8a2Smrg
28593e72ca8cSmrg  # awkward: cmd appends spaces to result
28603e72ca8cSmrg  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
2861fe24f8a2Smrg    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
28623e72ca8cSmrg}
28633e72ca8cSmrg#end: func_convert_core_msys_to_w32
28643e72ca8cSmrg
28653e72ca8cSmrg
28663e72ca8cSmrg# func_convert_file_check ARG1 ARG2
28673e72ca8cSmrg# Verify that ARG1 (a file name in $build format) was converted to $host
28683e72ca8cSmrg# format in ARG2. Otherwise, emit an error message, but continue (resetting
28693e72ca8cSmrg# func_to_host_file_result to ARG1).
28703e72ca8cSmrgfunc_convert_file_check ()
28713e72ca8cSmrg{
2872fe24f8a2Smrg  $debug_cmd
2873fe24f8a2Smrg
2874fe24f8a2Smrg  if test -z "$2" && test -n "$1"; then
28753e72ca8cSmrg    func_error "Could not determine host file name corresponding to"
2876fe24f8a2Smrg    func_error "  '$1'"
28773e72ca8cSmrg    func_error "Continuing, but uninstalled executables may not work."
28783e72ca8cSmrg    # Fallback:
2879fe24f8a2Smrg    func_to_host_file_result=$1
28803e72ca8cSmrg  fi
28813e72ca8cSmrg}
28823e72ca8cSmrg# end func_convert_file_check
28833e72ca8cSmrg
28843e72ca8cSmrg
28853e72ca8cSmrg# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
28863e72ca8cSmrg# Verify that FROM_PATH (a path in $build format) was converted to $host
28873e72ca8cSmrg# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
28883e72ca8cSmrg# func_to_host_file_result to a simplistic fallback value (see below).
28893e72ca8cSmrgfunc_convert_path_check ()
28903e72ca8cSmrg{
2891fe24f8a2Smrg  $debug_cmd
2892fe24f8a2Smrg
28933e72ca8cSmrg  if test -z "$4" && test -n "$3"; then
28943e72ca8cSmrg    func_error "Could not determine the host path corresponding to"
2895fe24f8a2Smrg    func_error "  '$3'"
28963e72ca8cSmrg    func_error "Continuing, but uninstalled executables may not work."
28973e72ca8cSmrg    # Fallback.  This is a deliberately simplistic "conversion" and
28983e72ca8cSmrg    # should not be "improved".  See libtool.info.
28993e72ca8cSmrg    if test "x$1" != "x$2"; then
29003e72ca8cSmrg      lt_replace_pathsep_chars="s|$1|$2|g"
29013e72ca8cSmrg      func_to_host_path_result=`echo "$3" |
29023e72ca8cSmrg        $SED -e "$lt_replace_pathsep_chars"`
29033e72ca8cSmrg    else
2904fe24f8a2Smrg      func_to_host_path_result=$3
29053e72ca8cSmrg    fi
29063e72ca8cSmrg  fi
29073e72ca8cSmrg}
29083e72ca8cSmrg# end func_convert_path_check
29093e72ca8cSmrg
29103e72ca8cSmrg
29113e72ca8cSmrg# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
29123e72ca8cSmrg# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
29133e72ca8cSmrg# and appending REPL if ORIG matches BACKPAT.
29143e72ca8cSmrgfunc_convert_path_front_back_pathsep ()
29153e72ca8cSmrg{
2916fe24f8a2Smrg  $debug_cmd
2917fe24f8a2Smrg
29183e72ca8cSmrg  case $4 in
2919fe24f8a2Smrg  $1 ) func_to_host_path_result=$3$func_to_host_path_result
29203e72ca8cSmrg    ;;
29213e72ca8cSmrg  esac
29223e72ca8cSmrg  case $4 in
29233e72ca8cSmrg  $2 ) func_append func_to_host_path_result "$3"
29243e72ca8cSmrg    ;;
29253e72ca8cSmrg  esac
29263e72ca8cSmrg}
29273e72ca8cSmrg# end func_convert_path_front_back_pathsep
29283e72ca8cSmrg
29293e72ca8cSmrg
29303e72ca8cSmrg##################################################
29313e72ca8cSmrg# $build to $host FILE NAME CONVERSION FUNCTIONS #
29323e72ca8cSmrg##################################################
2933fe24f8a2Smrg# invoked via '$to_host_file_cmd ARG'
29343e72ca8cSmrg#
29353e72ca8cSmrg# In each case, ARG is the path to be converted from $build to $host format.
29363e72ca8cSmrg# Result will be available in $func_to_host_file_result.
29373e72ca8cSmrg
29383e72ca8cSmrg
29393e72ca8cSmrg# func_to_host_file ARG
29403e72ca8cSmrg# Converts the file name ARG from $build format to $host format. Return result
29413e72ca8cSmrg# in func_to_host_file_result.
29423e72ca8cSmrgfunc_to_host_file ()
29433e72ca8cSmrg{
2944fe24f8a2Smrg  $debug_cmd
2945fe24f8a2Smrg
29463e72ca8cSmrg  $to_host_file_cmd "$1"
29473e72ca8cSmrg}
29483e72ca8cSmrg# end func_to_host_file
29493e72ca8cSmrg
29503e72ca8cSmrg
29513e72ca8cSmrg# func_to_tool_file ARG LAZY
29523e72ca8cSmrg# converts the file name ARG from $build format to toolchain format. Return
29533e72ca8cSmrg# result in func_to_tool_file_result.  If the conversion in use is listed
29543e72ca8cSmrg# in (the comma separated) LAZY, no conversion takes place.
29553e72ca8cSmrgfunc_to_tool_file ()
29563e72ca8cSmrg{
2957fe24f8a2Smrg  $debug_cmd
2958fe24f8a2Smrg
29593e72ca8cSmrg  case ,$2, in
29603e72ca8cSmrg    *,"$to_tool_file_cmd",*)
29613e72ca8cSmrg      func_to_tool_file_result=$1
29623e72ca8cSmrg      ;;
29633e72ca8cSmrg    *)
29643e72ca8cSmrg      $to_tool_file_cmd "$1"
29653e72ca8cSmrg      func_to_tool_file_result=$func_to_host_file_result
29663e72ca8cSmrg      ;;
29673e72ca8cSmrg  esac
29683e72ca8cSmrg}
29693e72ca8cSmrg# end func_to_tool_file
29703e72ca8cSmrg
29713e72ca8cSmrg
29723e72ca8cSmrg# func_convert_file_noop ARG
29733e72ca8cSmrg# Copy ARG to func_to_host_file_result.
29743e72ca8cSmrgfunc_convert_file_noop ()
29753e72ca8cSmrg{
2976fe24f8a2Smrg  func_to_host_file_result=$1
29773e72ca8cSmrg}
29783e72ca8cSmrg# end func_convert_file_noop
29793e72ca8cSmrg
29803e72ca8cSmrg
29813e72ca8cSmrg# func_convert_file_msys_to_w32 ARG
29823e72ca8cSmrg# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
29833e72ca8cSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
29843e72ca8cSmrg# func_to_host_file_result.
29853e72ca8cSmrgfunc_convert_file_msys_to_w32 ()
29863e72ca8cSmrg{
2987fe24f8a2Smrg  $debug_cmd
2988fe24f8a2Smrg
2989fe24f8a2Smrg  func_to_host_file_result=$1
29903e72ca8cSmrg  if test -n "$1"; then
29913e72ca8cSmrg    func_convert_core_msys_to_w32 "$1"
2992fe24f8a2Smrg    func_to_host_file_result=$func_convert_core_msys_to_w32_result
29933e72ca8cSmrg  fi
29943e72ca8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
29953e72ca8cSmrg}
29963e72ca8cSmrg# end func_convert_file_msys_to_w32
29973e72ca8cSmrg
29983e72ca8cSmrg
29993e72ca8cSmrg# func_convert_file_cygwin_to_w32 ARG
30003e72ca8cSmrg# Convert file name ARG from Cygwin to w32 format.  Returns result in
30013e72ca8cSmrg# func_to_host_file_result.
30023e72ca8cSmrgfunc_convert_file_cygwin_to_w32 ()
30033e72ca8cSmrg{
3004fe24f8a2Smrg  $debug_cmd
3005fe24f8a2Smrg
3006fe24f8a2Smrg  func_to_host_file_result=$1
30073e72ca8cSmrg  if test -n "$1"; then
30083e72ca8cSmrg    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
30093e72ca8cSmrg    # LT_CYGPATH in this case.
30103e72ca8cSmrg    func_to_host_file_result=`cygpath -m "$1"`
30113e72ca8cSmrg  fi
30123e72ca8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30133e72ca8cSmrg}
30143e72ca8cSmrg# end func_convert_file_cygwin_to_w32
30153e72ca8cSmrg
30163e72ca8cSmrg
30173e72ca8cSmrg# func_convert_file_nix_to_w32 ARG
30183e72ca8cSmrg# Convert file name ARG from *nix to w32 format.  Requires a wine environment
30193e72ca8cSmrg# and a working winepath. Returns result in func_to_host_file_result.
30203e72ca8cSmrgfunc_convert_file_nix_to_w32 ()
30213e72ca8cSmrg{
3022fe24f8a2Smrg  $debug_cmd
3023fe24f8a2Smrg
3024fe24f8a2Smrg  func_to_host_file_result=$1
30253e72ca8cSmrg  if test -n "$1"; then
30263e72ca8cSmrg    func_convert_core_file_wine_to_w32 "$1"
3027fe24f8a2Smrg    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
30283e72ca8cSmrg  fi
30293e72ca8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30303e72ca8cSmrg}
30313e72ca8cSmrg# end func_convert_file_nix_to_w32
30323e72ca8cSmrg
30333e72ca8cSmrg
30343e72ca8cSmrg# func_convert_file_msys_to_cygwin ARG
30353e72ca8cSmrg# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
30363e72ca8cSmrg# Returns result in func_to_host_file_result.
30373e72ca8cSmrgfunc_convert_file_msys_to_cygwin ()
30383e72ca8cSmrg{
3039fe24f8a2Smrg  $debug_cmd
3040fe24f8a2Smrg
3041fe24f8a2Smrg  func_to_host_file_result=$1
30423e72ca8cSmrg  if test -n "$1"; then
30433e72ca8cSmrg    func_convert_core_msys_to_w32 "$1"
30443e72ca8cSmrg    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3045fe24f8a2Smrg    func_to_host_file_result=$func_cygpath_result
30463e72ca8cSmrg  fi
30473e72ca8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30483e72ca8cSmrg}
30493e72ca8cSmrg# end func_convert_file_msys_to_cygwin
30503e72ca8cSmrg
30513e72ca8cSmrg
30523e72ca8cSmrg# func_convert_file_nix_to_cygwin ARG
30533e72ca8cSmrg# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
30543e72ca8cSmrg# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
30553e72ca8cSmrg# in func_to_host_file_result.
30563e72ca8cSmrgfunc_convert_file_nix_to_cygwin ()
30573e72ca8cSmrg{
3058fe24f8a2Smrg  $debug_cmd
3059fe24f8a2Smrg
3060fe24f8a2Smrg  func_to_host_file_result=$1
30613e72ca8cSmrg  if test -n "$1"; then
30623e72ca8cSmrg    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
30633e72ca8cSmrg    func_convert_core_file_wine_to_w32 "$1"
30643e72ca8cSmrg    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3065fe24f8a2Smrg    func_to_host_file_result=$func_cygpath_result
30663e72ca8cSmrg  fi
30673e72ca8cSmrg  func_convert_file_check "$1" "$func_to_host_file_result"
30683e72ca8cSmrg}
30693e72ca8cSmrg# end func_convert_file_nix_to_cygwin
30703e72ca8cSmrg
30713e72ca8cSmrg
30723e72ca8cSmrg#############################################
30733e72ca8cSmrg# $build to $host PATH CONVERSION FUNCTIONS #
30743e72ca8cSmrg#############################################
3075fe24f8a2Smrg# invoked via '$to_host_path_cmd ARG'
30763e72ca8cSmrg#
30773e72ca8cSmrg# In each case, ARG is the path to be converted from $build to $host format.
30783e72ca8cSmrg# The result will be available in $func_to_host_path_result.
30793e72ca8cSmrg#
30803e72ca8cSmrg# Path separators are also converted from $build format to $host format.  If
30813e72ca8cSmrg# ARG begins or ends with a path separator character, it is preserved (but
30823e72ca8cSmrg# converted to $host format) on output.
30833e72ca8cSmrg#
30843e72ca8cSmrg# All path conversion functions are named using the following convention:
30853e72ca8cSmrg#   file name conversion function    : func_convert_file_X_to_Y ()
30863e72ca8cSmrg#   path conversion function         : func_convert_path_X_to_Y ()
30873e72ca8cSmrg# where, for any given $build/$host combination the 'X_to_Y' value is the
30883e72ca8cSmrg# same.  If conversion functions are added for new $build/$host combinations,
30893e72ca8cSmrg# the two new functions must follow this pattern, or func_init_to_host_path_cmd
30903e72ca8cSmrg# will break.
30913e72ca8cSmrg
30923e72ca8cSmrg
30933e72ca8cSmrg# func_init_to_host_path_cmd
30943e72ca8cSmrg# Ensures that function "pointer" variable $to_host_path_cmd is set to the
30953e72ca8cSmrg# appropriate value, based on the value of $to_host_file_cmd.
30963e72ca8cSmrgto_host_path_cmd=
30973e72ca8cSmrgfunc_init_to_host_path_cmd ()
30983e72ca8cSmrg{
3099fe24f8a2Smrg  $debug_cmd
3100fe24f8a2Smrg
31013e72ca8cSmrg  if test -z "$to_host_path_cmd"; then
31023e72ca8cSmrg    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3103fe24f8a2Smrg    to_host_path_cmd=func_convert_path_$func_stripname_result
31043e72ca8cSmrg  fi
31053e72ca8cSmrg}
31063e72ca8cSmrg
31073e72ca8cSmrg
31083e72ca8cSmrg# func_to_host_path ARG
31093e72ca8cSmrg# Converts the path ARG from $build format to $host format. Return result
31103e72ca8cSmrg# in func_to_host_path_result.
31113e72ca8cSmrgfunc_to_host_path ()
31123e72ca8cSmrg{
3113fe24f8a2Smrg  $debug_cmd
3114fe24f8a2Smrg
31153e72ca8cSmrg  func_init_to_host_path_cmd
31163e72ca8cSmrg  $to_host_path_cmd "$1"
31173e72ca8cSmrg}
31183e72ca8cSmrg# end func_to_host_path
31193e72ca8cSmrg
31203e72ca8cSmrg
31213e72ca8cSmrg# func_convert_path_noop ARG
31223e72ca8cSmrg# Copy ARG to func_to_host_path_result.
31233e72ca8cSmrgfunc_convert_path_noop ()
31243e72ca8cSmrg{
3125fe24f8a2Smrg  func_to_host_path_result=$1
31263e72ca8cSmrg}
31273e72ca8cSmrg# end func_convert_path_noop
31283e72ca8cSmrg
31293e72ca8cSmrg
31303e72ca8cSmrg# func_convert_path_msys_to_w32 ARG
31313e72ca8cSmrg# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
31323e72ca8cSmrg# conversion to w32 is not available inside the cwrapper.  Returns result in
31333e72ca8cSmrg# func_to_host_path_result.
31343e72ca8cSmrgfunc_convert_path_msys_to_w32 ()
31353e72ca8cSmrg{
3136fe24f8a2Smrg  $debug_cmd
3137fe24f8a2Smrg
3138fe24f8a2Smrg  func_to_host_path_result=$1
31393e72ca8cSmrg  if test -n "$1"; then
31403e72ca8cSmrg    # Remove leading and trailing path separator characters from ARG.  MSYS
31413e72ca8cSmrg    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
31423e72ca8cSmrg    # and winepath ignores them completely.
31433e72ca8cSmrg    func_stripname : : "$1"
31443e72ca8cSmrg    func_to_host_path_tmp1=$func_stripname_result
31453e72ca8cSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3146fe24f8a2Smrg    func_to_host_path_result=$func_convert_core_msys_to_w32_result
31473e72ca8cSmrg    func_convert_path_check : ";" \
31483e72ca8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31493e72ca8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31503e72ca8cSmrg  fi
31513e72ca8cSmrg}
31523e72ca8cSmrg# end func_convert_path_msys_to_w32
31533e72ca8cSmrg
31543e72ca8cSmrg
31553e72ca8cSmrg# func_convert_path_cygwin_to_w32 ARG
31563e72ca8cSmrg# Convert path ARG from Cygwin to w32 format.  Returns result in
31573e72ca8cSmrg# func_to_host_file_result.
31583e72ca8cSmrgfunc_convert_path_cygwin_to_w32 ()
31593e72ca8cSmrg{
3160fe24f8a2Smrg  $debug_cmd
3161fe24f8a2Smrg
3162fe24f8a2Smrg  func_to_host_path_result=$1
31633e72ca8cSmrg  if test -n "$1"; then
31643e72ca8cSmrg    # See func_convert_path_msys_to_w32:
31653e72ca8cSmrg    func_stripname : : "$1"
31663e72ca8cSmrg    func_to_host_path_tmp1=$func_stripname_result
31673e72ca8cSmrg    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
31683e72ca8cSmrg    func_convert_path_check : ";" \
31693e72ca8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31703e72ca8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31713e72ca8cSmrg  fi
31723e72ca8cSmrg}
31733e72ca8cSmrg# end func_convert_path_cygwin_to_w32
31743e72ca8cSmrg
31753e72ca8cSmrg
31763e72ca8cSmrg# func_convert_path_nix_to_w32 ARG
31773e72ca8cSmrg# Convert path ARG from *nix to w32 format.  Requires a wine environment and
31783e72ca8cSmrg# a working winepath.  Returns result in func_to_host_file_result.
31793e72ca8cSmrgfunc_convert_path_nix_to_w32 ()
318034977a2fSmrg{
3181fe24f8a2Smrg  $debug_cmd
3182fe24f8a2Smrg
3183fe24f8a2Smrg  func_to_host_path_result=$1
31843e72ca8cSmrg  if test -n "$1"; then
31853e72ca8cSmrg    # See func_convert_path_msys_to_w32:
31863e72ca8cSmrg    func_stripname : : "$1"
31873e72ca8cSmrg    func_to_host_path_tmp1=$func_stripname_result
31883e72ca8cSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3189fe24f8a2Smrg    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
31903e72ca8cSmrg    func_convert_path_check : ";" \
31913e72ca8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
31923e72ca8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
31933e72ca8cSmrg  fi
31943e72ca8cSmrg}
31953e72ca8cSmrg# end func_convert_path_nix_to_w32
319634977a2fSmrg
319734977a2fSmrg
31983e72ca8cSmrg# func_convert_path_msys_to_cygwin ARG
31993e72ca8cSmrg# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
32003e72ca8cSmrg# Returns result in func_to_host_file_result.
32013e72ca8cSmrgfunc_convert_path_msys_to_cygwin ()
32023e72ca8cSmrg{
3203fe24f8a2Smrg  $debug_cmd
3204fe24f8a2Smrg
3205fe24f8a2Smrg  func_to_host_path_result=$1
32063e72ca8cSmrg  if test -n "$1"; then
32073e72ca8cSmrg    # See func_convert_path_msys_to_w32:
32083e72ca8cSmrg    func_stripname : : "$1"
32093e72ca8cSmrg    func_to_host_path_tmp1=$func_stripname_result
32103e72ca8cSmrg    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
32113e72ca8cSmrg    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3212fe24f8a2Smrg    func_to_host_path_result=$func_cygpath_result
32133e72ca8cSmrg    func_convert_path_check : : \
32143e72ca8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32153e72ca8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
32163e72ca8cSmrg  fi
32173e72ca8cSmrg}
32183e72ca8cSmrg# end func_convert_path_msys_to_cygwin
321934977a2fSmrg
322034977a2fSmrg
32213e72ca8cSmrg# func_convert_path_nix_to_cygwin ARG
32223e72ca8cSmrg# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
32233e72ca8cSmrg# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
32243e72ca8cSmrg# func_to_host_file_result.
32253e72ca8cSmrgfunc_convert_path_nix_to_cygwin ()
32263e72ca8cSmrg{
3227fe24f8a2Smrg  $debug_cmd
3228fe24f8a2Smrg
3229fe24f8a2Smrg  func_to_host_path_result=$1
32303e72ca8cSmrg  if test -n "$1"; then
32313e72ca8cSmrg    # Remove leading and trailing path separator characters from
32323e72ca8cSmrg    # ARG. msys behavior is inconsistent here, cygpath turns them
32333e72ca8cSmrg    # into '.;' and ';.', and winepath ignores them completely.
32343e72ca8cSmrg    func_stripname : : "$1"
32353e72ca8cSmrg    func_to_host_path_tmp1=$func_stripname_result
32363e72ca8cSmrg    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
32373e72ca8cSmrg    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3238fe24f8a2Smrg    func_to_host_path_result=$func_cygpath_result
32393e72ca8cSmrg    func_convert_path_check : : \
32403e72ca8cSmrg      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32413e72ca8cSmrg    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
32423e72ca8cSmrg  fi
324334977a2fSmrg}
32443e72ca8cSmrg# end func_convert_path_nix_to_cygwin
32453e72ca8cSmrg
324634977a2fSmrg
3247fe24f8a2Smrg# func_dll_def_p FILE
3248fe24f8a2Smrg# True iff FILE is a Windows DLL '.def' file.
3249fe24f8a2Smrg# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3250fe24f8a2Smrgfunc_dll_def_p ()
3251fe24f8a2Smrg{
3252fe24f8a2Smrg  $debug_cmd
3253fe24f8a2Smrg
3254fe24f8a2Smrg  func_dll_def_p_tmp=`$SED -n \
3255fe24f8a2Smrg    -e 's/^[	 ]*//' \
3256fe24f8a2Smrg    -e '/^\(;.*\)*$/d' \
3257fe24f8a2Smrg    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3258fe24f8a2Smrg    -e q \
3259fe24f8a2Smrg    "$1"`
3260fe24f8a2Smrg  test DEF = "$func_dll_def_p_tmp"
3261fe24f8a2Smrg}
3262fe24f8a2Smrg
3263fe24f8a2Smrg
326434977a2fSmrg# func_mode_compile arg...
326534977a2fSmrgfunc_mode_compile ()
326634977a2fSmrg{
3267fe24f8a2Smrg    $debug_cmd
3268fe24f8a2Smrg
326934977a2fSmrg    # Get the compilation command and the source file.
327034977a2fSmrg    base_compile=
3271fe24f8a2Smrg    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
327234977a2fSmrg    suppress_opt=yes
327334977a2fSmrg    suppress_output=
327434977a2fSmrg    arg_mode=normal
327534977a2fSmrg    libobj=
327634977a2fSmrg    later=
327734977a2fSmrg    pie_flag=
327834977a2fSmrg
327934977a2fSmrg    for arg
328034977a2fSmrg    do
328134977a2fSmrg      case $arg_mode in
328234977a2fSmrg      arg  )
328334977a2fSmrg	# do not "continue".  Instead, add this to base_compile
3284fe24f8a2Smrg	lastarg=$arg
328534977a2fSmrg	arg_mode=normal
328634977a2fSmrg	;;
328734977a2fSmrg
328834977a2fSmrg      target )
3289fe24f8a2Smrg	libobj=$arg
329034977a2fSmrg	arg_mode=normal
329134977a2fSmrg	continue
329234977a2fSmrg	;;
329334977a2fSmrg
329434977a2fSmrg      normal )
329534977a2fSmrg	# Accept any command-line options.
329634977a2fSmrg	case $arg in
329734977a2fSmrg	-o)
329834977a2fSmrg	  test -n "$libobj" && \
3299fe24f8a2Smrg	    func_fatal_error "you cannot specify '-o' more than once"
330034977a2fSmrg	  arg_mode=target
330134977a2fSmrg	  continue
330234977a2fSmrg	  ;;
330334977a2fSmrg
330434977a2fSmrg	-pie | -fpie | -fPIE)
33053e72ca8cSmrg          func_append pie_flag " $arg"
330634977a2fSmrg	  continue
330734977a2fSmrg	  ;;
330834977a2fSmrg
330934977a2fSmrg	-shared | -static | -prefer-pic | -prefer-non-pic)
33103e72ca8cSmrg	  func_append later " $arg"
331134977a2fSmrg	  continue
331234977a2fSmrg	  ;;
3313ee3138f1Smrg
3314ee3138f1Smrg	-no-suppress)
3315ee3138f1Smrg	  suppress_opt=no
3316ee3138f1Smrg	  continue
3317ee3138f1Smrg	  ;;
3318ee3138f1Smrg
3319ee3138f1Smrg	-Xcompiler)
3320ee3138f1Smrg	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
3321ee3138f1Smrg	  continue      #  The current "srcfile" will either be retained or
3322ee3138f1Smrg	  ;;            #  replaced later.  I would guess that would be a bug.
3323ee3138f1Smrg
3324ee3138f1Smrg	-Wc,*)
332534977a2fSmrg	  func_stripname '-Wc,' '' "$arg"
332634977a2fSmrg	  args=$func_stripname_result
3327ee3138f1Smrg	  lastarg=
3328fe24f8a2Smrg	  save_ifs=$IFS; IFS=,
332934977a2fSmrg	  for arg in $args; do
3330fe24f8a2Smrg	    IFS=$save_ifs
33313e72ca8cSmrg	    func_append_quoted lastarg "$arg"
3332ee3138f1Smrg	  done
3333fe24f8a2Smrg	  IFS=$save_ifs
333434977a2fSmrg	  func_stripname ' ' '' "$lastarg"
333534977a2fSmrg	  lastarg=$func_stripname_result
3336ee3138f1Smrg
3337ee3138f1Smrg	  # Add the arguments to base_compile.
33383e72ca8cSmrg	  func_append base_compile " $lastarg"
3339ee3138f1Smrg	  continue
3340ee3138f1Smrg	  ;;
3341ee3138f1Smrg
334234977a2fSmrg	*)
3343ee3138f1Smrg	  # Accept the current argument as the source file.
3344ee3138f1Smrg	  # The previous "srcfile" becomes the current argument.
3345ee3138f1Smrg	  #
3346fe24f8a2Smrg	  lastarg=$srcfile
3347fe24f8a2Smrg	  srcfile=$arg
3348ee3138f1Smrg	  ;;
3349ee3138f1Smrg	esac  #  case $arg
3350ee3138f1Smrg	;;
3351ee3138f1Smrg      esac    #  case $arg_mode
3352ee3138f1Smrg
3353ee3138f1Smrg      # Aesthetically quote the previous argument.
33543e72ca8cSmrg      func_append_quoted base_compile "$lastarg"
3355ee3138f1Smrg    done # for arg
3356ee3138f1Smrg
3357ee3138f1Smrg    case $arg_mode in
3358ee3138f1Smrg    arg)
335934977a2fSmrg      func_fatal_error "you must specify an argument for -Xcompile"
3360ee3138f1Smrg      ;;
3361ee3138f1Smrg    target)
3362fe24f8a2Smrg      func_fatal_error "you must specify a target with '-o'"
3363ee3138f1Smrg      ;;
3364ee3138f1Smrg    *)
3365ee3138f1Smrg      # Get the name of the library object.
336634977a2fSmrg      test -z "$libobj" && {
336734977a2fSmrg	func_basename "$srcfile"
3368fe24f8a2Smrg	libobj=$func_basename_result
336934977a2fSmrg      }
3370ee3138f1Smrg      ;;
3371ee3138f1Smrg    esac
3372ee3138f1Smrg
3373ee3138f1Smrg    # Recognize several different file suffixes.
3374ee3138f1Smrg    # If the user specifies -o file.o, it is replaced with file.lo
3375ee3138f1Smrg    case $libobj in
337634977a2fSmrg    *.[cCFSifmso] | \
337734977a2fSmrg    *.ada | *.adb | *.ads | *.asm | \
337834977a2fSmrg    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
33793e72ca8cSmrg    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
338034977a2fSmrg      func_xform "$libobj"
338134977a2fSmrg      libobj=$func_xform_result
338234977a2fSmrg      ;;
3383ee3138f1Smrg    esac
3384ee3138f1Smrg
3385ee3138f1Smrg    case $libobj in
338634977a2fSmrg    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
3387ee3138f1Smrg    *)
3388fe24f8a2Smrg      func_fatal_error "cannot determine name of library object from '$libobj'"
3389ee3138f1Smrg      ;;
3390ee3138f1Smrg    esac
3391ee3138f1Smrg
3392ee3138f1Smrg    func_infer_tag $base_compile
3393ee3138f1Smrg
3394ee3138f1Smrg    for arg in $later; do
3395ee3138f1Smrg      case $arg in
339634977a2fSmrg      -shared)
3397fe24f8a2Smrg	test yes = "$build_libtool_libs" \
3398fe24f8a2Smrg	  || func_fatal_configuration "cannot build a shared library"
339934977a2fSmrg	build_old_libs=no
340034977a2fSmrg	continue
340134977a2fSmrg	;;
340234977a2fSmrg
3403ee3138f1Smrg      -static)
340434977a2fSmrg	build_libtool_libs=no
3405ee3138f1Smrg	build_old_libs=yes
3406ee3138f1Smrg	continue
3407ee3138f1Smrg	;;
3408ee3138f1Smrg
3409ee3138f1Smrg      -prefer-pic)
3410ee3138f1Smrg	pic_mode=yes
3411ee3138f1Smrg	continue
3412ee3138f1Smrg	;;
3413ee3138f1Smrg
3414ee3138f1Smrg      -prefer-non-pic)
3415ee3138f1Smrg	pic_mode=no
3416ee3138f1Smrg	continue
3417ee3138f1Smrg	;;
3418ee3138f1Smrg      esac
3419ee3138f1Smrg    done
3420ee3138f1Smrg
342134977a2fSmrg    func_quote_for_eval "$libobj"
342234977a2fSmrg    test "X$libobj" != "X$func_quote_for_eval_result" \
342334977a2fSmrg      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3424fe24f8a2Smrg      && func_warning "libobj name '$libobj' may not contain shell special characters."
342534977a2fSmrg    func_dirname_and_basename "$obj" "/" ""
3426fe24f8a2Smrg    objname=$func_basename_result
3427fe24f8a2Smrg    xdir=$func_dirname_result
3428fe24f8a2Smrg    lobj=$xdir$objdir/$objname
3429ee3138f1Smrg
343034977a2fSmrg    test -z "$base_compile" && \
343134977a2fSmrg      func_fatal_help "you must specify a compilation command"
3432ee3138f1Smrg
3433ee3138f1Smrg    # Delete any leftover library objects.
3434fe24f8a2Smrg    if test yes = "$build_old_libs"; then
3435ee3138f1Smrg      removelist="$obj $lobj $libobj ${libobj}T"
3436ee3138f1Smrg    else
3437ee3138f1Smrg      removelist="$lobj $libobj ${libobj}T"
3438ee3138f1Smrg    fi
3439ee3138f1Smrg
3440ee3138f1Smrg    # On Cygwin there's no "real" PIC flag so we must build both object types
3441ee3138f1Smrg    case $host_os in
344234977a2fSmrg    cygwin* | mingw* | pw32* | os2* | cegcc*)
3443ee3138f1Smrg      pic_mode=default
3444ee3138f1Smrg      ;;
3445ee3138f1Smrg    esac
3446fe24f8a2Smrg    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
3447ee3138f1Smrg      # non-PIC code in shared libraries is not supported
3448ee3138f1Smrg      pic_mode=default
3449ee3138f1Smrg    fi
3450ee3138f1Smrg
3451ee3138f1Smrg    # Calculate the filename of the output object if compiler does
3452ee3138f1Smrg    # not support -o with -c
3453fe24f8a2Smrg    if test no = "$compiler_c_o"; then
3454fe24f8a2Smrg      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3455fe24f8a2Smrg      lockfile=$output_obj.lock
3456ee3138f1Smrg    else
3457ee3138f1Smrg      output_obj=
3458ee3138f1Smrg      need_locks=no
3459ee3138f1Smrg      lockfile=
3460ee3138f1Smrg    fi
3461ee3138f1Smrg
3462ee3138f1Smrg    # Lock this critical section if it is needed
3463ee3138f1Smrg    # We use this script file to make the link, it avoids creating a new file
3464fe24f8a2Smrg    if test yes = "$need_locks"; then
346534977a2fSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
346634977a2fSmrg	func_echo "Waiting for $lockfile to be removed"
3467ee3138f1Smrg	sleep 2
3468ee3138f1Smrg      done
3469fe24f8a2Smrg    elif test warn = "$need_locks"; then
3470ee3138f1Smrg      if test -f "$lockfile"; then
347134977a2fSmrg	$ECHO "\
3472ee3138f1Smrg*** ERROR, $lockfile exists and contains:
3473ee3138f1Smrg`cat $lockfile 2>/dev/null`
3474ee3138f1Smrg
3475ee3138f1SmrgThis indicates that another process is trying to use the same
3476ee3138f1Smrgtemporary object file, and libtool could not work around it because
3477fe24f8a2Smrgyour compiler does not support '-c' and '-o' together.  If you
3478ee3138f1Smrgrepeat this compilation, it may succeed, by chance, but you had better
3479ee3138f1Smrgavoid parallel builds (make -j) in this platform, or get a better
3480ee3138f1Smrgcompiler."
3481ee3138f1Smrg
348234977a2fSmrg	$opt_dry_run || $RM $removelist
3483ee3138f1Smrg	exit $EXIT_FAILURE
3484ee3138f1Smrg      fi
34853e72ca8cSmrg      func_append removelist " $output_obj"
348634977a2fSmrg      $ECHO "$srcfile" > "$lockfile"
3487ee3138f1Smrg    fi
3488ee3138f1Smrg
348934977a2fSmrg    $opt_dry_run || $RM $removelist
34903e72ca8cSmrg    func_append removelist " $lockfile"
349134977a2fSmrg    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
349234977a2fSmrg
34933e72ca8cSmrg    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
34943e72ca8cSmrg    srcfile=$func_to_tool_file_result
349534977a2fSmrg    func_quote_for_eval "$srcfile"
349634977a2fSmrg    qsrcfile=$func_quote_for_eval_result
3497ee3138f1Smrg
3498ee3138f1Smrg    # Only build a PIC object if we are building libtool libraries.
3499fe24f8a2Smrg    if test yes = "$build_libtool_libs"; then
3500ee3138f1Smrg      # Without this assignment, base_compile gets emptied.
3501ee3138f1Smrg      fbsd_hideous_sh_bug=$base_compile
3502ee3138f1Smrg
3503fe24f8a2Smrg      if test no != "$pic_mode"; then
3504ee3138f1Smrg	command="$base_compile $qsrcfile $pic_flag"
3505ee3138f1Smrg      else
3506ee3138f1Smrg	# Don't build PIC code
3507ee3138f1Smrg	command="$base_compile $qsrcfile"
3508ee3138f1Smrg      fi
3509ee3138f1Smrg
351034977a2fSmrg      func_mkdir_p "$xdir$objdir"
3511ee3138f1Smrg
3512ee3138f1Smrg      if test -z "$output_obj"; then
3513ee3138f1Smrg	# Place PIC objects in $objdir
35143e72ca8cSmrg	func_append command " -o $lobj"
3515ee3138f1Smrg      fi
3516ee3138f1Smrg
351734977a2fSmrg      func_show_eval_locale "$command"	\
351834977a2fSmrg          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
3519ee3138f1Smrg
3520fe24f8a2Smrg      if test warn = "$need_locks" &&
3521ee3138f1Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
352234977a2fSmrg	$ECHO "\
3523ee3138f1Smrg*** ERROR, $lockfile contains:
3524ee3138f1Smrg`cat $lockfile 2>/dev/null`
3525ee3138f1Smrg
3526ee3138f1Smrgbut it should contain:
3527ee3138f1Smrg$srcfile
3528ee3138f1Smrg
3529ee3138f1SmrgThis indicates that another process is trying to use the same
3530ee3138f1Smrgtemporary object file, and libtool could not work around it because
3531fe24f8a2Smrgyour compiler does not support '-c' and '-o' together.  If you
3532ee3138f1Smrgrepeat this compilation, it may succeed, by chance, but you had better
3533ee3138f1Smrgavoid parallel builds (make -j) in this platform, or get a better
3534ee3138f1Smrgcompiler."
3535ee3138f1Smrg
353634977a2fSmrg	$opt_dry_run || $RM $removelist
3537ee3138f1Smrg	exit $EXIT_FAILURE
3538ee3138f1Smrg      fi
3539ee3138f1Smrg
3540ee3138f1Smrg      # Just move the object if needed, then go on to compile the next one
3541ee3138f1Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
354234977a2fSmrg	func_show_eval '$MV "$output_obj" "$lobj"' \
354334977a2fSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3544ee3138f1Smrg      fi
3545ee3138f1Smrg
3546ee3138f1Smrg      # Allow error messages only from the first compilation.
3547fe24f8a2Smrg      if test yes = "$suppress_opt"; then
354834977a2fSmrg	suppress_output=' >/dev/null 2>&1'
3549ee3138f1Smrg      fi
3550ee3138f1Smrg    fi
3551ee3138f1Smrg
3552ee3138f1Smrg    # Only build a position-dependent object if we build old libraries.
3553fe24f8a2Smrg    if test yes = "$build_old_libs"; then
3554fe24f8a2Smrg      if test yes != "$pic_mode"; then
3555ee3138f1Smrg	# Don't build PIC code
355634977a2fSmrg	command="$base_compile $qsrcfile$pie_flag"
3557ee3138f1Smrg      else
3558ee3138f1Smrg	command="$base_compile $qsrcfile $pic_flag"
3559ee3138f1Smrg      fi
3560fe24f8a2Smrg      if test yes = "$compiler_c_o"; then
35613e72ca8cSmrg	func_append command " -o $obj"
3562ee3138f1Smrg      fi
3563ee3138f1Smrg
3564ee3138f1Smrg      # Suppress compiler output if we already did a PIC compilation.
35653e72ca8cSmrg      func_append command "$suppress_output"
356634977a2fSmrg      func_show_eval_locale "$command" \
356734977a2fSmrg        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
3568ee3138f1Smrg
3569fe24f8a2Smrg      if test warn = "$need_locks" &&
3570ee3138f1Smrg	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
357134977a2fSmrg	$ECHO "\
3572ee3138f1Smrg*** ERROR, $lockfile contains:
3573ee3138f1Smrg`cat $lockfile 2>/dev/null`
3574ee3138f1Smrg
3575ee3138f1Smrgbut it should contain:
3576ee3138f1Smrg$srcfile
3577ee3138f1Smrg
3578ee3138f1SmrgThis indicates that another process is trying to use the same
3579ee3138f1Smrgtemporary object file, and libtool could not work around it because
3580fe24f8a2Smrgyour compiler does not support '-c' and '-o' together.  If you
3581ee3138f1Smrgrepeat this compilation, it may succeed, by chance, but you had better
3582ee3138f1Smrgavoid parallel builds (make -j) in this platform, or get a better
3583ee3138f1Smrgcompiler."
3584ee3138f1Smrg
358534977a2fSmrg	$opt_dry_run || $RM $removelist
3586ee3138f1Smrg	exit $EXIT_FAILURE
3587ee3138f1Smrg      fi
3588ee3138f1Smrg
3589ee3138f1Smrg      # Just move the object if needed
3590ee3138f1Smrg      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
359134977a2fSmrg	func_show_eval '$MV "$output_obj" "$obj"' \
359234977a2fSmrg	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
3593ee3138f1Smrg      fi
3594ee3138f1Smrg    fi
3595ee3138f1Smrg
359634977a2fSmrg    $opt_dry_run || {
359734977a2fSmrg      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
3598ee3138f1Smrg
359934977a2fSmrg      # Unlock the critical section if it was locked
3600fe24f8a2Smrg      if test no != "$need_locks"; then
360134977a2fSmrg	removelist=$lockfile
360234977a2fSmrg        $RM "$lockfile"
360334977a2fSmrg      fi
360434977a2fSmrg    }
3605ee3138f1Smrg
3606ee3138f1Smrg    exit $EXIT_SUCCESS
360734977a2fSmrg}
3608ee3138f1Smrg
360934977a2fSmrg$opt_help || {
3610fe24f8a2Smrg  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
361134977a2fSmrg}
3612ee3138f1Smrg
361334977a2fSmrgfunc_mode_help ()
361434977a2fSmrg{
361534977a2fSmrg    # We need to display help for each of the modes.
36163e72ca8cSmrg    case $opt_mode in
361734977a2fSmrg      "")
361834977a2fSmrg        # Generic help is extracted from the usage comments
361934977a2fSmrg        # at the start of this file.
362034977a2fSmrg        func_help
362134977a2fSmrg        ;;
3622ee3138f1Smrg
362334977a2fSmrg      clean)
362434977a2fSmrg        $ECHO \
362534977a2fSmrg"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
3626ee3138f1Smrg
362734977a2fSmrgRemove files from the build directory.
3628ee3138f1Smrg
362934977a2fSmrgRM is the name of the program to use to delete files associated with each FILE
3630fe24f8a2Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
363134977a2fSmrgto RM.
3632ee3138f1Smrg
363334977a2fSmrgIf FILE is a libtool library, object or program, all the files associated
363434977a2fSmrgwith it are deleted. Otherwise, only FILE itself is deleted using RM."
363534977a2fSmrg        ;;
3636ee3138f1Smrg
363734977a2fSmrg      compile)
363834977a2fSmrg      $ECHO \
363934977a2fSmrg"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
3640ee3138f1Smrg
364134977a2fSmrgCompile a source file into a libtool library object.
3642ee3138f1Smrg
364334977a2fSmrgThis mode accepts the following additional options:
3644ee3138f1Smrg
364534977a2fSmrg  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
364634977a2fSmrg  -no-suppress      do not suppress compiler output for multiple passes
3647b425557eSmrg  -prefer-pic       try to build PIC objects only
3648b425557eSmrg  -prefer-non-pic   try to build non-PIC objects only
3649fe24f8a2Smrg  -shared           do not build a '.o' file suitable for static linking
3650fe24f8a2Smrg  -static           only build a '.o' file suitable for static linking
3651b425557eSmrg  -Wc,FLAG          pass FLAG directly to the compiler
3652ee3138f1Smrg
3653fe24f8a2SmrgCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
365434977a2fSmrgfrom the given SOURCEFILE.
3655ee3138f1Smrg
365634977a2fSmrgThe output file name is determined by removing the directory component from
3657fe24f8a2SmrgSOURCEFILE, then substituting the C source code suffix '.c' with the
3658fe24f8a2Smrglibrary object suffix, '.lo'."
365934977a2fSmrg        ;;
3660ee3138f1Smrg
366134977a2fSmrg      execute)
366234977a2fSmrg        $ECHO \
366334977a2fSmrg"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
3664ee3138f1Smrg
366534977a2fSmrgAutomatically set library path, then run a program.
3666ee3138f1Smrg
366734977a2fSmrgThis mode accepts the following additional options:
3668ee3138f1Smrg
366934977a2fSmrg  -dlopen FILE      add the directory containing FILE to the library path
3670ee3138f1Smrg
3671fe24f8a2SmrgThis mode sets the library path environment variable according to '-dlopen'
367234977a2fSmrgflags.
3673ee3138f1Smrg
367434977a2fSmrgIf any of the ARGS are libtool executable wrappers, then they are translated
367534977a2fSmrginto their corresponding uninstalled binary, and any of their required library
367634977a2fSmrgdirectories are added to the library path.
3677ee3138f1Smrg
367834977a2fSmrgThen, COMMAND is executed, with ARGS as arguments."
367934977a2fSmrg        ;;
3680ee3138f1Smrg
368134977a2fSmrg      finish)
368234977a2fSmrg        $ECHO \
368334977a2fSmrg"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
3684ee3138f1Smrg
368534977a2fSmrgComplete the installation of libtool libraries.
3686ee3138f1Smrg
368734977a2fSmrgEach LIBDIR is a directory that contains libtool libraries.
3688ee3138f1Smrg
368934977a2fSmrgThe commands that this mode executes may require superuser privileges.  Use
3690fe24f8a2Smrgthe '--dry-run' option if you just want to see what would be executed."
369134977a2fSmrg        ;;
3692ee3138f1Smrg
369334977a2fSmrg      install)
369434977a2fSmrg        $ECHO \
369534977a2fSmrg"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
3696ee3138f1Smrg
369734977a2fSmrgInstall executables or libraries.
3698ee3138f1Smrg
369934977a2fSmrgINSTALL-COMMAND is the installation command.  The first component should be
3700fe24f8a2Smrgeither the 'install' or 'cp' program.
3701ee3138f1Smrg
370234977a2fSmrgThe following components of INSTALL-COMMAND are treated specially:
3703ee3138f1Smrg
3704b425557eSmrg  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
3705ee3138f1Smrg
370634977a2fSmrgThe rest of the components are interpreted as arguments to that command (only
370734977a2fSmrgBSD-compatible install options are recognized)."
370834977a2fSmrg        ;;
3709ee3138f1Smrg
371034977a2fSmrg      link)
371134977a2fSmrg        $ECHO \
371234977a2fSmrg"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
3713ee3138f1Smrg
371434977a2fSmrgLink object files or libraries together to form another library, or to
371534977a2fSmrgcreate an executable program.
3716ee3138f1Smrg
371734977a2fSmrgLINK-COMMAND is a command using the C compiler that you would use to create
371834977a2fSmrga program from several object files.
3719ee3138f1Smrg
372034977a2fSmrgThe following components of LINK-COMMAND are treated specially:
3721ee3138f1Smrg
372234977a2fSmrg  -all-static       do not do any dynamic linking at all
372334977a2fSmrg  -avoid-version    do not add a version suffix if possible
3724b425557eSmrg  -bindir BINDIR    specify path to binaries directory (for systems where
3725b425557eSmrg                    libraries must be found in the PATH setting at runtime)
3726fe24f8a2Smrg  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
372734977a2fSmrg  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
372834977a2fSmrg  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
372934977a2fSmrg  -export-symbols SYMFILE
373034977a2fSmrg                    try to export only the symbols listed in SYMFILE
373134977a2fSmrg  -export-symbols-regex REGEX
373234977a2fSmrg                    try to export only the symbols matching REGEX
373334977a2fSmrg  -LLIBDIR          search LIBDIR for required installed libraries
373434977a2fSmrg  -lNAME            OUTPUT-FILE requires the installed library libNAME
373534977a2fSmrg  -module           build a library that can dlopened
373634977a2fSmrg  -no-fast-install  disable the fast-install mode
373734977a2fSmrg  -no-install       link a not-installable executable
373834977a2fSmrg  -no-undefined     declare that a library does not refer to external symbols
373934977a2fSmrg  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3740fe24f8a2Smrg  -objectlist FILE  use a list of object files found in FILE to specify objects
3741fe24f8a2Smrg  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
374234977a2fSmrg  -precious-files-regex REGEX
374334977a2fSmrg                    don't remove output files matching REGEX
374434977a2fSmrg  -release RELEASE  specify package release information
374534977a2fSmrg  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
374634977a2fSmrg  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
374734977a2fSmrg  -shared           only do dynamic linking of libtool libraries
374834977a2fSmrg  -shrext SUFFIX    override the standard shared library file extension
374934977a2fSmrg  -static           do not do any dynamic linking of uninstalled libtool libraries
375034977a2fSmrg  -static-libtool-libs
375134977a2fSmrg                    do not do any dynamic linking of libtool libraries
375234977a2fSmrg  -version-info CURRENT[:REVISION[:AGE]]
375334977a2fSmrg                    specify library version info [each variable defaults to 0]
375434977a2fSmrg  -weak LIBNAME     declare that the target provides the LIBNAME interface
3755b425557eSmrg  -Wc,FLAG
3756b425557eSmrg  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
3757b425557eSmrg  -Wl,FLAG
3758b425557eSmrg  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
3759b425557eSmrg  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
3760ee3138f1Smrg
3761fe24f8a2SmrgAll other options (arguments beginning with '-') are ignored.
3762ee3138f1Smrg
3763fe24f8a2SmrgEvery other argument is treated as a filename.  Files ending in '.la' are
376434977a2fSmrgtreated as uninstalled libtool libraries, other files are standard or library
376534977a2fSmrgobject files.
376679a8a9c6Smrg
3767fe24f8a2SmrgIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
3768fe24f8a2Smrgonly library objects ('.lo' files) may be specified, and '-rpath' is
376934977a2fSmrgrequired, except when creating a convenience library.
3770ee3138f1Smrg
3771fe24f8a2SmrgIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
3772fe24f8a2Smrgusing 'ar' and 'ranlib', or on Windows using 'lib'.
3773ee3138f1Smrg
3774fe24f8a2SmrgIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
377534977a2fSmrgis created, otherwise an executable program is created."
3776ee3138f1Smrg        ;;
3777ee3138f1Smrg
377834977a2fSmrg      uninstall)
377934977a2fSmrg        $ECHO \
378034977a2fSmrg"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
3781ee3138f1Smrg
378234977a2fSmrgRemove libraries from an installation directory.
3783ee3138f1Smrg
378434977a2fSmrgRM is the name of the program to use to delete files associated with each FILE
3785fe24f8a2Smrg(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
378634977a2fSmrgto RM.
3787ee3138f1Smrg
378834977a2fSmrgIf FILE is a libtool library, all the files associated with it are deleted.
378934977a2fSmrgOtherwise, only FILE itself is deleted using RM."
379034977a2fSmrg        ;;
3791ee3138f1Smrg
379234977a2fSmrg      *)
3793fe24f8a2Smrg        func_fatal_help "invalid operation mode '$opt_mode'"
379434977a2fSmrg        ;;
379534977a2fSmrg    esac
3796ee3138f1Smrg
3797b425557eSmrg    echo
3798fe24f8a2Smrg    $ECHO "Try '$progname --help' for more information about other modes."
379934977a2fSmrg}
3800ee3138f1Smrg
3801b425557eSmrg# Now that we've collected a possible --mode arg, show help if necessary
3802b425557eSmrgif $opt_help; then
3803fe24f8a2Smrg  if test : = "$opt_help"; then
3804b425557eSmrg    func_mode_help
3805b425557eSmrg  else
3806b425557eSmrg    {
3807b425557eSmrg      func_help noexit
38083e72ca8cSmrg      for opt_mode in compile link execute install finish uninstall clean; do
3809b425557eSmrg	func_mode_help
3810b425557eSmrg      done
3811fe24f8a2Smrg    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
3812b425557eSmrg    {
3813b425557eSmrg      func_help noexit
38143e72ca8cSmrg      for opt_mode in compile link execute install finish uninstall clean; do
3815b425557eSmrg	echo
3816b425557eSmrg	func_mode_help
3817b425557eSmrg      done
3818b425557eSmrg    } |
3819fe24f8a2Smrg    $SED '1d
3820b425557eSmrg      /^When reporting/,/^Report/{
3821b425557eSmrg	H
3822b425557eSmrg	d
3823b425557eSmrg      }
3824b425557eSmrg      $x
3825b425557eSmrg      /information about other modes/d
3826b425557eSmrg      /more detailed .*MODE/d
3827b425557eSmrg      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
3828b425557eSmrg  fi
3829b425557eSmrg  exit $?
3830b425557eSmrgfi
3831ee3138f1Smrg
3832ee3138f1Smrg
383334977a2fSmrg# func_mode_execute arg...
383434977a2fSmrgfunc_mode_execute ()
383534977a2fSmrg{
3836fe24f8a2Smrg    $debug_cmd
3837fe24f8a2Smrg
383834977a2fSmrg    # The first argument is the command name.
3839fe24f8a2Smrg    cmd=$nonopt
384034977a2fSmrg    test -z "$cmd" && \
384134977a2fSmrg      func_fatal_help "you must specify a COMMAND"
3842ee3138f1Smrg
384334977a2fSmrg    # Handle -dlopen flags immediately.
38443e72ca8cSmrg    for file in $opt_dlopen; do
384534977a2fSmrg      test -f "$file" \
3846fe24f8a2Smrg	|| func_fatal_help "'$file' is not a file"
3847ee3138f1Smrg
384834977a2fSmrg      dir=
384934977a2fSmrg      case $file in
385034977a2fSmrg      *.la)
38513e72ca8cSmrg	func_resolve_sysroot "$file"
38523e72ca8cSmrg	file=$func_resolve_sysroot_result
38533e72ca8cSmrg
385434977a2fSmrg	# Check to see that this really is a libtool archive.
385534977a2fSmrg	func_lalib_unsafe_p "$file" \
3856fe24f8a2Smrg	  || func_fatal_help "'$lib' is not a valid libtool archive"
3857ee3138f1Smrg
385834977a2fSmrg	# Read the libtool library.
385934977a2fSmrg	dlname=
386034977a2fSmrg	library_names=
386134977a2fSmrg	func_source "$file"
3862ee3138f1Smrg
386334977a2fSmrg	# Skip this library if it cannot be dlopened.
386434977a2fSmrg	if test -z "$dlname"; then
386534977a2fSmrg	  # Warn if it was a shared library.
386634977a2fSmrg	  test -n "$library_names" && \
3867fe24f8a2Smrg	    func_warning "'$file' was not linked with '-export-dynamic'"
386834977a2fSmrg	  continue
386934977a2fSmrg	fi
3870ee3138f1Smrg
387134977a2fSmrg	func_dirname "$file" "" "."
3872fe24f8a2Smrg	dir=$func_dirname_result
3873ee3138f1Smrg
387434977a2fSmrg	if test -f "$dir/$objdir/$dlname"; then
38753e72ca8cSmrg	  func_append dir "/$objdir"
387634977a2fSmrg	else
387734977a2fSmrg	  if test ! -f "$dir/$dlname"; then
3878fe24f8a2Smrg	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
387934977a2fSmrg	  fi
388034977a2fSmrg	fi
3881ee3138f1Smrg	;;
3882ee3138f1Smrg
388334977a2fSmrg      *.lo)
388434977a2fSmrg	# Just add the directory containing the .lo file.
388534977a2fSmrg	func_dirname "$file" "" "."
3886fe24f8a2Smrg	dir=$func_dirname_result
3887ee3138f1Smrg	;;
3888ee3138f1Smrg
388934977a2fSmrg      *)
3890fe24f8a2Smrg	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
3891ee3138f1Smrg	continue
3892ee3138f1Smrg	;;
389334977a2fSmrg      esac
3894ee3138f1Smrg
389534977a2fSmrg      # Get the absolute pathname.
389634977a2fSmrg      absdir=`cd "$dir" && pwd`
3897fe24f8a2Smrg      test -n "$absdir" && dir=$absdir
3898ee3138f1Smrg
389934977a2fSmrg      # Now add the directory to shlibpath_var.
390034977a2fSmrg      if eval "test -z \"\$$shlibpath_var\""; then
390134977a2fSmrg	eval "$shlibpath_var=\"\$dir\""
390234977a2fSmrg      else
390334977a2fSmrg	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
390434977a2fSmrg      fi
390534977a2fSmrg    done
3906ee3138f1Smrg
390734977a2fSmrg    # This variable tells wrapper scripts just to set shlibpath_var
390834977a2fSmrg    # rather than running their programs.
3909fe24f8a2Smrg    libtool_execute_magic=$magic
3910ee3138f1Smrg
391134977a2fSmrg    # Check if any of the arguments is a wrapper script.
391234977a2fSmrg    args=
391334977a2fSmrg    for file
391434977a2fSmrg    do
391534977a2fSmrg      case $file in
3916b425557eSmrg      -* | *.la | *.lo ) ;;
391734977a2fSmrg      *)
391834977a2fSmrg	# Do a test to see if this is really a libtool program.
391934977a2fSmrg	if func_ltwrapper_script_p "$file"; then
392034977a2fSmrg	  func_source "$file"
392134977a2fSmrg	  # Transform arg to wrapped name.
3922fe24f8a2Smrg	  file=$progdir/$program
392334977a2fSmrg	elif func_ltwrapper_executable_p "$file"; then
392434977a2fSmrg	  func_ltwrapper_scriptname "$file"
392534977a2fSmrg	  func_source "$func_ltwrapper_scriptname_result"
392634977a2fSmrg	  # Transform arg to wrapped name.
3927fe24f8a2Smrg	  file=$progdir/$program
392834977a2fSmrg	fi
392934977a2fSmrg	;;
393034977a2fSmrg      esac
393134977a2fSmrg      # Quote arguments (to preserve shell metacharacters).
39323e72ca8cSmrg      func_append_quoted args "$file"
393334977a2fSmrg    done
3934ee3138f1Smrg
3935fe24f8a2Smrg    if $opt_dry_run; then
3936fe24f8a2Smrg      # Display what would be done.
3937fe24f8a2Smrg      if test -n "$shlibpath_var"; then
3938fe24f8a2Smrg	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
3939fe24f8a2Smrg	echo "export $shlibpath_var"
3940fe24f8a2Smrg      fi
3941fe24f8a2Smrg      $ECHO "$cmd$args"
3942fe24f8a2Smrg      exit $EXIT_SUCCESS
3943fe24f8a2Smrg    else
394434977a2fSmrg      if test -n "$shlibpath_var"; then
394534977a2fSmrg	# Export the shlibpath_var.
394634977a2fSmrg	eval "export $shlibpath_var"
394734977a2fSmrg      fi
3948ee3138f1Smrg
394934977a2fSmrg      # Restore saved environment variables
395034977a2fSmrg      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
395134977a2fSmrg      do
395234977a2fSmrg	eval "if test \"\${save_$lt_var+set}\" = set; then
395334977a2fSmrg                $lt_var=\$save_$lt_var; export $lt_var
3954ee3138f1Smrg	      else
395534977a2fSmrg		$lt_unset $lt_var
395634977a2fSmrg	      fi"
395734977a2fSmrg      done
3958ee3138f1Smrg
395934977a2fSmrg      # Now prepare to actually exec the command.
3960fe24f8a2Smrg      exec_cmd=\$cmd$args
396134977a2fSmrg    fi
396234977a2fSmrg}
3963ee3138f1Smrg
3964fe24f8a2Smrgtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
3965ee3138f1Smrg
3966ee3138f1Smrg
396734977a2fSmrg# func_mode_finish arg...
396834977a2fSmrgfunc_mode_finish ()
396934977a2fSmrg{
3970fe24f8a2Smrg    $debug_cmd
3971fe24f8a2Smrg
39723e72ca8cSmrg    libs=
39733e72ca8cSmrg    libdirs=
397434977a2fSmrg    admincmds=
3975ee3138f1Smrg
39763e72ca8cSmrg    for opt in "$nonopt" ${1+"$@"}
39773e72ca8cSmrg    do
39783e72ca8cSmrg      if test -d "$opt"; then
39793e72ca8cSmrg	func_append libdirs " $opt"
39803e72ca8cSmrg
39813e72ca8cSmrg      elif test -f "$opt"; then
39823e72ca8cSmrg	if func_lalib_unsafe_p "$opt"; then
39833e72ca8cSmrg	  func_append libs " $opt"
39843e72ca8cSmrg	else
3985fe24f8a2Smrg	  func_warning "'$opt' is not a valid libtool archive"
39863e72ca8cSmrg	fi
39873e72ca8cSmrg
39883e72ca8cSmrg      else
3989fe24f8a2Smrg	func_fatal_error "invalid argument '$opt'"
39903e72ca8cSmrg      fi
39913e72ca8cSmrg    done
39923e72ca8cSmrg
39933e72ca8cSmrg    if test -n "$libs"; then
39943e72ca8cSmrg      if test -n "$lt_sysroot"; then
39953e72ca8cSmrg        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
39963e72ca8cSmrg        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
39973e72ca8cSmrg      else
39983e72ca8cSmrg        sysroot_cmd=
39993e72ca8cSmrg      fi
40003e72ca8cSmrg
40013e72ca8cSmrg      # Remove sysroot references
40023e72ca8cSmrg      if $opt_dry_run; then
40033e72ca8cSmrg        for lib in $libs; do
4004fe24f8a2Smrg          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
40053e72ca8cSmrg        done
40063e72ca8cSmrg      else
40073e72ca8cSmrg        tmpdir=`func_mktempdir`
40083e72ca8cSmrg        for lib in $libs; do
4009fe24f8a2Smrg	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
40103e72ca8cSmrg	    > $tmpdir/tmp-la
40113e72ca8cSmrg	  mv -f $tmpdir/tmp-la $lib
40123e72ca8cSmrg	done
40133e72ca8cSmrg        ${RM}r "$tmpdir"
40143e72ca8cSmrg      fi
40153e72ca8cSmrg    fi
4016ee3138f1Smrg
40173e72ca8cSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
401834977a2fSmrg      for libdir in $libdirs; do
401934977a2fSmrg	if test -n "$finish_cmds"; then
402034977a2fSmrg	  # Do each command in the finish commands.
402134977a2fSmrg	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
402234977a2fSmrg'"$cmd"'"'
4023ee3138f1Smrg	fi
402434977a2fSmrg	if test -n "$finish_eval"; then
402534977a2fSmrg	  # Do the single finish_eval.
402634977a2fSmrg	  eval cmds=\"$finish_eval\"
40273e72ca8cSmrg	  $opt_dry_run || eval "$cmds" || func_append admincmds "
402834977a2fSmrg       $cmds"
402934977a2fSmrg	fi
403034977a2fSmrg      done
403134977a2fSmrg    fi
4032ee3138f1Smrg
403334977a2fSmrg    # Exit here if they wanted silent mode.
4034fe24f8a2Smrg    $opt_quiet && exit $EXIT_SUCCESS
4035ee3138f1Smrg
40363e72ca8cSmrg    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
40373e72ca8cSmrg      echo "----------------------------------------------------------------------"
40383e72ca8cSmrg      echo "Libraries have been installed in:"
40393e72ca8cSmrg      for libdir in $libdirs; do
40403e72ca8cSmrg	$ECHO "   $libdir"
40413e72ca8cSmrg      done
40423e72ca8cSmrg      echo
40433e72ca8cSmrg      echo "If you ever happen to want to link against installed libraries"
40443e72ca8cSmrg      echo "in a given directory, LIBDIR, you must either use libtool, and"
4045fe24f8a2Smrg      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
40463e72ca8cSmrg      echo "flag during linking and do at least one of the following:"
40473e72ca8cSmrg      if test -n "$shlibpath_var"; then
4048fe24f8a2Smrg	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
40493e72ca8cSmrg	echo "     during execution"
40503e72ca8cSmrg      fi
40513e72ca8cSmrg      if test -n "$runpath_var"; then
4052fe24f8a2Smrg	echo "   - add LIBDIR to the '$runpath_var' environment variable"
40533e72ca8cSmrg	echo "     during linking"
40543e72ca8cSmrg      fi
40553e72ca8cSmrg      if test -n "$hardcode_libdir_flag_spec"; then
40563e72ca8cSmrg	libdir=LIBDIR
40573e72ca8cSmrg	eval flag=\"$hardcode_libdir_flag_spec\"
4058ee3138f1Smrg
4059fe24f8a2Smrg	$ECHO "   - use the '$flag' linker flag"
40603e72ca8cSmrg      fi
40613e72ca8cSmrg      if test -n "$admincmds"; then
40623e72ca8cSmrg	$ECHO "   - have your system administrator run these commands:$admincmds"
40633e72ca8cSmrg      fi
40643e72ca8cSmrg      if test -f /etc/ld.so.conf; then
4065fe24f8a2Smrg	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
40663e72ca8cSmrg      fi
40673e72ca8cSmrg      echo
406834977a2fSmrg
40693e72ca8cSmrg      echo "See any operating system documentation about shared libraries for"
40703e72ca8cSmrg      case $host in
40713e72ca8cSmrg	solaris2.[6789]|solaris2.1[0-9])
40723e72ca8cSmrg	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
40733e72ca8cSmrg	  echo "pages."
40743e72ca8cSmrg	  ;;
40753e72ca8cSmrg	*)
40763e72ca8cSmrg	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
40773e72ca8cSmrg	  ;;
40783e72ca8cSmrg      esac
40793e72ca8cSmrg      echo "----------------------------------------------------------------------"
40803e72ca8cSmrg    fi
408134977a2fSmrg    exit $EXIT_SUCCESS
408234977a2fSmrg}
4083ee3138f1Smrg
4084fe24f8a2Smrgtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
4085ee3138f1Smrg
408679a8a9c6Smrg
408734977a2fSmrg# func_mode_install arg...
408834977a2fSmrgfunc_mode_install ()
408934977a2fSmrg{
4090fe24f8a2Smrg    $debug_cmd
4091fe24f8a2Smrg
409234977a2fSmrg    # There may be an optional sh(1) argument at the beginning of
409334977a2fSmrg    # install_prog (especially on Windows NT).
4094fe24f8a2Smrg    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
409534977a2fSmrg       # Allow the use of GNU shtool's install command.
4096fe24f8a2Smrg       case $nonopt in *shtool*) :;; *) false;; esac
4097fe24f8a2Smrg    then
409834977a2fSmrg      # Aesthetically quote it.
409934977a2fSmrg      func_quote_for_eval "$nonopt"
410034977a2fSmrg      install_prog="$func_quote_for_eval_result "
410134977a2fSmrg      arg=$1
410234977a2fSmrg      shift
410334977a2fSmrg    else
410434977a2fSmrg      install_prog=
410534977a2fSmrg      arg=$nonopt
4106ee3138f1Smrg    fi
4107ee3138f1Smrg
410834977a2fSmrg    # The real first argument should be the name of the installation program.
410934977a2fSmrg    # Aesthetically quote it.
411034977a2fSmrg    func_quote_for_eval "$arg"
41113e72ca8cSmrg    func_append install_prog "$func_quote_for_eval_result"
4112b425557eSmrg    install_shared_prog=$install_prog
4113b425557eSmrg    case " $install_prog " in
4114b425557eSmrg      *[\\\ /]cp\ *) install_cp=: ;;
4115b425557eSmrg      *) install_cp=false ;;
4116b425557eSmrg    esac
4117ee3138f1Smrg
411834977a2fSmrg    # We need to accept at least all the BSD install flags.
411934977a2fSmrg    dest=
412034977a2fSmrg    files=
412134977a2fSmrg    opts=
412234977a2fSmrg    prev=
412334977a2fSmrg    install_type=
4124fe24f8a2Smrg    isdir=false
412534977a2fSmrg    stripme=
4126b425557eSmrg    no_mode=:
412734977a2fSmrg    for arg
412834977a2fSmrg    do
4129b425557eSmrg      arg2=
413034977a2fSmrg      if test -n "$dest"; then
41313e72ca8cSmrg	func_append files " $dest"
413234977a2fSmrg	dest=$arg
413334977a2fSmrg	continue
413434977a2fSmrg      fi
4135ee3138f1Smrg
413634977a2fSmrg      case $arg in
4137fe24f8a2Smrg      -d) isdir=: ;;
413834977a2fSmrg      -f)
4139b425557eSmrg	if $install_cp; then :; else
4140b425557eSmrg	  prev=$arg
4141b425557eSmrg	fi
414234977a2fSmrg	;;
414334977a2fSmrg      -g | -m | -o)
414434977a2fSmrg	prev=$arg
414534977a2fSmrg	;;
414634977a2fSmrg      -s)
414734977a2fSmrg	stripme=" -s"
414834977a2fSmrg	continue
414934977a2fSmrg	;;
415034977a2fSmrg      -*)
415134977a2fSmrg	;;
415234977a2fSmrg      *)
415334977a2fSmrg	# If the previous option needed an argument, then skip it.
415434977a2fSmrg	if test -n "$prev"; then
4155fe24f8a2Smrg	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
4156b425557eSmrg	    arg2=$install_override_mode
4157b425557eSmrg	    no_mode=false
4158b425557eSmrg	  fi
415934977a2fSmrg	  prev=
416034977a2fSmrg	else
416134977a2fSmrg	  dest=$arg
416234977a2fSmrg	  continue
416334977a2fSmrg	fi
416434977a2fSmrg	;;
416534977a2fSmrg      esac
4166ee3138f1Smrg
416734977a2fSmrg      # Aesthetically quote the argument.
416834977a2fSmrg      func_quote_for_eval "$arg"
41693e72ca8cSmrg      func_append install_prog " $func_quote_for_eval_result"
4170b425557eSmrg      if test -n "$arg2"; then
4171b425557eSmrg	func_quote_for_eval "$arg2"
4172b425557eSmrg      fi
41733e72ca8cSmrg      func_append install_shared_prog " $func_quote_for_eval_result"
417434977a2fSmrg    done
417534977a2fSmrg
417634977a2fSmrg    test -z "$install_prog" && \
417734977a2fSmrg      func_fatal_help "you must specify an install program"
417834977a2fSmrg
417934977a2fSmrg    test -n "$prev" && \
4180fe24f8a2Smrg      func_fatal_help "the '$prev' option requires an argument"
418134977a2fSmrg
4182b425557eSmrg    if test -n "$install_override_mode" && $no_mode; then
4183b425557eSmrg      if $install_cp; then :; else
4184b425557eSmrg	func_quote_for_eval "$install_override_mode"
41853e72ca8cSmrg	func_append install_shared_prog " -m $func_quote_for_eval_result"
4186b425557eSmrg      fi
4187b425557eSmrg    fi
4188b425557eSmrg
418934977a2fSmrg    if test -z "$files"; then
419034977a2fSmrg      if test -z "$dest"; then
419134977a2fSmrg	func_fatal_help "no file or destination specified"
419234977a2fSmrg      else
419334977a2fSmrg	func_fatal_help "you must specify a destination"
4194ee3138f1Smrg      fi
4195ee3138f1Smrg    fi
4196ee3138f1Smrg
419734977a2fSmrg    # Strip any trailing slash from the destination.
419834977a2fSmrg    func_stripname '' '/' "$dest"
419934977a2fSmrg    dest=$func_stripname_result
4200ee3138f1Smrg
420134977a2fSmrg    # Check to see that the destination is a directory.
4202fe24f8a2Smrg    test -d "$dest" && isdir=:
4203fe24f8a2Smrg    if $isdir; then
4204fe24f8a2Smrg      destdir=$dest
420534977a2fSmrg      destname=
420634977a2fSmrg    else
420734977a2fSmrg      func_dirname_and_basename "$dest" "" "."
4208fe24f8a2Smrg      destdir=$func_dirname_result
4209fe24f8a2Smrg      destname=$func_basename_result
421034977a2fSmrg
421134977a2fSmrg      # Not a directory, so check to see that there is only one file specified.
421234977a2fSmrg      set dummy $files; shift
421334977a2fSmrg      test "$#" -gt 1 && \
4214fe24f8a2Smrg	func_fatal_help "'$dest' is not a directory"
421534977a2fSmrg    fi
421634977a2fSmrg    case $destdir in
421734977a2fSmrg    [\\/]* | [A-Za-z]:[\\/]*) ;;
4218ee3138f1Smrg    *)
421934977a2fSmrg      for file in $files; do
422034977a2fSmrg	case $file in
422134977a2fSmrg	*.lo) ;;
422234977a2fSmrg	*)
4223fe24f8a2Smrg	  func_fatal_help "'$destdir' must be an absolute directory name"
422434977a2fSmrg	  ;;
422534977a2fSmrg	esac
422634977a2fSmrg      done
4227ee3138f1Smrg      ;;
4228ee3138f1Smrg    esac
4229ee3138f1Smrg
423034977a2fSmrg    # This variable tells wrapper scripts just to set variables rather
423134977a2fSmrg    # than running their programs.
4232fe24f8a2Smrg    libtool_install_magic=$magic
4233ee3138f1Smrg
423434977a2fSmrg    staticlibs=
423534977a2fSmrg    future_libdirs=
423634977a2fSmrg    current_libdirs=
423734977a2fSmrg    for file in $files; do
4238ee3138f1Smrg
423934977a2fSmrg      # Do each installation.
424034977a2fSmrg      case $file in
424134977a2fSmrg      *.$libext)
424234977a2fSmrg	# Do the static libraries later.
42433e72ca8cSmrg	func_append staticlibs " $file"
424434977a2fSmrg	;;
424534977a2fSmrg
424634977a2fSmrg      *.la)
42473e72ca8cSmrg	func_resolve_sysroot "$file"
42483e72ca8cSmrg	file=$func_resolve_sysroot_result
42493e72ca8cSmrg
425034977a2fSmrg	# Check to see that this really is a libtool archive.
425134977a2fSmrg	func_lalib_unsafe_p "$file" \
4252fe24f8a2Smrg	  || func_fatal_help "'$file' is not a valid libtool archive"
425334977a2fSmrg
425434977a2fSmrg	library_names=
425534977a2fSmrg	old_library=
425634977a2fSmrg	relink_command=
425734977a2fSmrg	func_source "$file"
425834977a2fSmrg
425934977a2fSmrg	# Add the libdir to current_libdirs if it is the destination.
426034977a2fSmrg	if test "X$destdir" = "X$libdir"; then
426134977a2fSmrg	  case "$current_libdirs " in
426234977a2fSmrg	  *" $libdir "*) ;;
42633e72ca8cSmrg	  *) func_append current_libdirs " $libdir" ;;
4264ee3138f1Smrg	  esac
426534977a2fSmrg	else
426634977a2fSmrg	  # Note the libdir as a future libdir.
426734977a2fSmrg	  case "$future_libdirs " in
426834977a2fSmrg	  *" $libdir "*) ;;
42693e72ca8cSmrg	  *) func_append future_libdirs " $libdir" ;;
427034977a2fSmrg	  esac
427134977a2fSmrg	fi
4272ee3138f1Smrg
427334977a2fSmrg	func_dirname "$file" "/" ""
4274fe24f8a2Smrg	dir=$func_dirname_result
42753e72ca8cSmrg	func_append dir "$objdir"
427634977a2fSmrg
427734977a2fSmrg	if test -n "$relink_command"; then
427834977a2fSmrg	  # Determine the prefix the user has applied to our future dir.
4279b425557eSmrg	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
428034977a2fSmrg
428134977a2fSmrg	  # Don't allow the user to place us outside of our expected
428234977a2fSmrg	  # location b/c this prevents finding dependent libraries that
428334977a2fSmrg	  # are installed to the same prefix.
428434977a2fSmrg	  # At present, this check doesn't affect windows .dll's that
428534977a2fSmrg	  # are installed into $libdir/../bin (currently, that works fine)
428634977a2fSmrg	  # but it's something to keep an eye on.
428734977a2fSmrg	  test "$inst_prefix_dir" = "$destdir" && \
4288fe24f8a2Smrg	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
428934977a2fSmrg
429034977a2fSmrg	  if test -n "$inst_prefix_dir"; then
429134977a2fSmrg	    # Stick the inst_prefix_dir data into the link command.
4292b425557eSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
429334977a2fSmrg	  else
4294b425557eSmrg	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
429534977a2fSmrg	  fi
429634977a2fSmrg
4297fe24f8a2Smrg	  func_warning "relinking '$file'"
429834977a2fSmrg	  func_show_eval "$relink_command" \
4299fe24f8a2Smrg	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
430034977a2fSmrg	fi
430134977a2fSmrg
430234977a2fSmrg	# See the names of the shared library.
430334977a2fSmrg	set dummy $library_names; shift
430434977a2fSmrg	if test -n "$1"; then
4305fe24f8a2Smrg	  realname=$1
430634977a2fSmrg	  shift
430734977a2fSmrg
4308fe24f8a2Smrg	  srcname=$realname
4309fe24f8a2Smrg	  test -n "$relink_command" && srcname=${realname}T
431034977a2fSmrg
431134977a2fSmrg	  # Install the shared library and build the symlinks.
4312b425557eSmrg	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
431334977a2fSmrg	      'exit $?'
4314fe24f8a2Smrg	  tstripme=$stripme
431534977a2fSmrg	  case $host_os in
431634977a2fSmrg	  cygwin* | mingw* | pw32* | cegcc*)
431734977a2fSmrg	    case $realname in
431834977a2fSmrg	    *.dll.a)
4319fe24f8a2Smrg	      tstripme=
4320fe24f8a2Smrg	      ;;
4321fe24f8a2Smrg	    esac
4322fe24f8a2Smrg	    ;;
4323fe24f8a2Smrg	  os2*)
4324fe24f8a2Smrg	    case $realname in
4325fe24f8a2Smrg	    *_dll.a)
4326fe24f8a2Smrg	      tstripme=
432734977a2fSmrg	      ;;
432834977a2fSmrg	    esac
4329ee3138f1Smrg	    ;;
4330ee3138f1Smrg	  esac
433134977a2fSmrg	  if test -n "$tstripme" && test -n "$striplib"; then
433234977a2fSmrg	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
433379a8a9c6Smrg	  fi
433434977a2fSmrg
433534977a2fSmrg	  if test "$#" -gt 0; then
433634977a2fSmrg	    # Delete the old symlinks, and create new ones.
4337fe24f8a2Smrg	    # Try 'ln -sf' first, because the 'ln' binary might depend on
433834977a2fSmrg	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
433934977a2fSmrg	    # so we also need to try rm && ln -s.
434034977a2fSmrg	    for linkname
434134977a2fSmrg	    do
434234977a2fSmrg	      test "$linkname" != "$realname" \
434334977a2fSmrg		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
4344ee3138f1Smrg	    done
4345ee3138f1Smrg	  fi
4346ee3138f1Smrg
434734977a2fSmrg	  # Do each command in the postinstall commands.
4348fe24f8a2Smrg	  lib=$destdir/$realname
434934977a2fSmrg	  func_execute_cmds "$postinstall_cmds" 'exit $?'
4350ee3138f1Smrg	fi
4351ee3138f1Smrg
435234977a2fSmrg	# Install the pseudo-library for information purposes.
435334977a2fSmrg	func_basename "$file"
4354fe24f8a2Smrg	name=$func_basename_result
4355fe24f8a2Smrg	instname=$dir/${name}i
435634977a2fSmrg	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
4357ee3138f1Smrg
435834977a2fSmrg	# Maybe install the static library, too.
43593e72ca8cSmrg	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
436034977a2fSmrg	;;
4361ee3138f1Smrg
436234977a2fSmrg      *.lo)
436334977a2fSmrg	# Install (i.e. copy) a libtool object.
4364ee3138f1Smrg
436534977a2fSmrg	# Figure out destination file name, if it wasn't already specified.
436634977a2fSmrg	if test -n "$destname"; then
4367fe24f8a2Smrg	  destfile=$destdir/$destname
436834977a2fSmrg	else
436934977a2fSmrg	  func_basename "$file"
4370fe24f8a2Smrg	  destfile=$func_basename_result
4371fe24f8a2Smrg	  destfile=$destdir/$destfile
437234977a2fSmrg	fi
437334977a2fSmrg
437434977a2fSmrg	# Deduce the name of the destination old-style object file.
437534977a2fSmrg	case $destfile in
437634977a2fSmrg	*.lo)
437734977a2fSmrg	  func_lo2o "$destfile"
437834977a2fSmrg	  staticdest=$func_lo2o_result
437934977a2fSmrg	  ;;
438034977a2fSmrg	*.$objext)
4381fe24f8a2Smrg	  staticdest=$destfile
438234977a2fSmrg	  destfile=
438334977a2fSmrg	  ;;
438434977a2fSmrg	*)
4385fe24f8a2Smrg	  func_fatal_help "cannot copy a libtool object to '$destfile'"
438634977a2fSmrg	  ;;
4387ee3138f1Smrg	esac
4388ee3138f1Smrg
438934977a2fSmrg	# Install the libtool object if requested.
439034977a2fSmrg	test -n "$destfile" && \
439134977a2fSmrg	  func_show_eval "$install_prog $file $destfile" 'exit $?'
439234977a2fSmrg
439334977a2fSmrg	# Install the old object if enabled.
4394fe24f8a2Smrg	if test yes = "$build_old_libs"; then
439534977a2fSmrg	  # Deduce the name of the old-style object file.
439634977a2fSmrg	  func_lo2o "$file"
439734977a2fSmrg	  staticobj=$func_lo2o_result
439834977a2fSmrg	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
4399ee3138f1Smrg	fi
440034977a2fSmrg	exit $EXIT_SUCCESS
440134977a2fSmrg	;;
4402ee3138f1Smrg
440334977a2fSmrg      *)
440434977a2fSmrg	# Figure out destination file name, if it wasn't already specified.
440534977a2fSmrg	if test -n "$destname"; then
4406fe24f8a2Smrg	  destfile=$destdir/$destname
440734977a2fSmrg	else
440834977a2fSmrg	  func_basename "$file"
4409fe24f8a2Smrg	  destfile=$func_basename_result
4410fe24f8a2Smrg	  destfile=$destdir/$destfile
441134977a2fSmrg	fi
4412ee3138f1Smrg
441334977a2fSmrg	# If the file is missing, and there is a .exe on the end, strip it
441434977a2fSmrg	# because it is most likely a libtool script we actually want to
441534977a2fSmrg	# install
4416fe24f8a2Smrg	stripped_ext=
441734977a2fSmrg	case $file in
441834977a2fSmrg	  *.exe)
441934977a2fSmrg	    if test ! -f "$file"; then
442034977a2fSmrg	      func_stripname '' '.exe' "$file"
442134977a2fSmrg	      file=$func_stripname_result
4422fe24f8a2Smrg	      stripped_ext=.exe
442334977a2fSmrg	    fi
442434977a2fSmrg	    ;;
442534977a2fSmrg	esac
4426ee3138f1Smrg
442734977a2fSmrg	# Do a test to see if this is really a libtool program.
442834977a2fSmrg	case $host in
442934977a2fSmrg	*cygwin* | *mingw*)
443034977a2fSmrg	    if func_ltwrapper_executable_p "$file"; then
443134977a2fSmrg	      func_ltwrapper_scriptname "$file"
443234977a2fSmrg	      wrapper=$func_ltwrapper_scriptname_result
443334977a2fSmrg	    else
443434977a2fSmrg	      func_stripname '' '.exe' "$file"
443534977a2fSmrg	      wrapper=$func_stripname_result
443634977a2fSmrg	    fi
443734977a2fSmrg	    ;;
443834977a2fSmrg	*)
443934977a2fSmrg	    wrapper=$file
444034977a2fSmrg	    ;;
444134977a2fSmrg	esac
444234977a2fSmrg	if func_ltwrapper_script_p "$wrapper"; then
444334977a2fSmrg	  notinst_deplibs=
444434977a2fSmrg	  relink_command=
4445ee3138f1Smrg
444634977a2fSmrg	  func_source "$wrapper"
444734977a2fSmrg
444834977a2fSmrg	  # Check the variables that should have been set.
444934977a2fSmrg	  test -z "$generated_by_libtool_version" && \
4450fe24f8a2Smrg	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
445134977a2fSmrg
4452fe24f8a2Smrg	  finalize=:
445334977a2fSmrg	  for lib in $notinst_deplibs; do
445434977a2fSmrg	    # Check to see that each library is installed.
445534977a2fSmrg	    libdir=
445634977a2fSmrg	    if test -f "$lib"; then
445734977a2fSmrg	      func_source "$lib"
445834977a2fSmrg	    fi
4459fe24f8a2Smrg	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
446034977a2fSmrg	    if test -n "$libdir" && test ! -f "$libfile"; then
4461fe24f8a2Smrg	      func_warning "'$lib' has not been installed in '$libdir'"
4462fe24f8a2Smrg	      finalize=false
446334977a2fSmrg	    fi
446434977a2fSmrg	  done
446534977a2fSmrg
446634977a2fSmrg	  relink_command=
446734977a2fSmrg	  func_source "$wrapper"
446834977a2fSmrg
446934977a2fSmrg	  outputname=
4470fe24f8a2Smrg	  if test no = "$fast_install" && test -n "$relink_command"; then
447134977a2fSmrg	    $opt_dry_run || {
4472fe24f8a2Smrg	      if $finalize; then
447334977a2fSmrg	        tmpdir=`func_mktempdir`
447434977a2fSmrg		func_basename "$file$stripped_ext"
4475fe24f8a2Smrg		file=$func_basename_result
4476fe24f8a2Smrg	        outputname=$tmpdir/$file
447734977a2fSmrg	        # Replace the output file specification.
4478b425557eSmrg	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
447934977a2fSmrg
4480fe24f8a2Smrg	        $opt_quiet || {
448134977a2fSmrg	          func_quote_for_expand "$relink_command"
448234977a2fSmrg		  eval "func_echo $func_quote_for_expand_result"
448334977a2fSmrg	        }
448434977a2fSmrg	        if eval "$relink_command"; then :
448534977a2fSmrg	          else
4486fe24f8a2Smrg		  func_error "error: relink '$file' with the above command before installing it"
448734977a2fSmrg		  $opt_dry_run || ${RM}r "$tmpdir"
448834977a2fSmrg		  continue
448934977a2fSmrg	        fi
4490fe24f8a2Smrg	        file=$outputname
449134977a2fSmrg	      else
4492fe24f8a2Smrg	        func_warning "cannot relink '$file'"
449334977a2fSmrg	      fi
449434977a2fSmrg	    }
4495ee3138f1Smrg	  else
449634977a2fSmrg	    # Install the binary that we compiled earlier.
4497b425557eSmrg	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
4498ee3138f1Smrg	  fi
449934977a2fSmrg	fi
4500ee3138f1Smrg
450134977a2fSmrg	# remove .exe since cygwin /usr/bin/install will append another
450234977a2fSmrg	# one anyway
450334977a2fSmrg	case $install_prog,$host in
450434977a2fSmrg	*/usr/bin/install*,*cygwin*)
450534977a2fSmrg	  case $file:$destfile in
450634977a2fSmrg	  *.exe:*.exe)
450734977a2fSmrg	    # this is ok
450834977a2fSmrg	    ;;
450934977a2fSmrg	  *.exe:*)
451034977a2fSmrg	    destfile=$destfile.exe
451134977a2fSmrg	    ;;
451234977a2fSmrg	  *:*.exe)
451334977a2fSmrg	    func_stripname '' '.exe' "$destfile"
451434977a2fSmrg	    destfile=$func_stripname_result
451534977a2fSmrg	    ;;
451634977a2fSmrg	  esac
4517ee3138f1Smrg	  ;;
4518ee3138f1Smrg	esac
451934977a2fSmrg	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
452034977a2fSmrg	$opt_dry_run || if test -n "$outputname"; then
452134977a2fSmrg	  ${RM}r "$tmpdir"
452234977a2fSmrg	fi
452334977a2fSmrg	;;
452434977a2fSmrg      esac
452534977a2fSmrg    done
4526ee3138f1Smrg
452734977a2fSmrg    for file in $staticlibs; do
452834977a2fSmrg      func_basename "$file"
4529fe24f8a2Smrg      name=$func_basename_result
453034977a2fSmrg
453134977a2fSmrg      # Set up the ranlib parameters.
4532fe24f8a2Smrg      oldlib=$destdir/$name
45333e72ca8cSmrg      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
45343e72ca8cSmrg      tool_oldlib=$func_to_tool_file_result
453534977a2fSmrg
453634977a2fSmrg      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
453734977a2fSmrg
453834977a2fSmrg      if test -n "$stripme" && test -n "$old_striplib"; then
45393e72ca8cSmrg	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
454034977a2fSmrg      fi
454134977a2fSmrg
454234977a2fSmrg      # Do each command in the postinstall commands.
454334977a2fSmrg      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
454434977a2fSmrg    done
454534977a2fSmrg
454634977a2fSmrg    test -n "$future_libdirs" && \
4547fe24f8a2Smrg      func_warning "remember to run '$progname --finish$future_libdirs'"
454834977a2fSmrg
454934977a2fSmrg    if test -n "$current_libdirs"; then
455034977a2fSmrg      # Maybe just do a dry run.
455134977a2fSmrg      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4552fe24f8a2Smrg      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
455334977a2fSmrg    else
455434977a2fSmrg      exit $EXIT_SUCCESS
455534977a2fSmrg    fi
455634977a2fSmrg}
455734977a2fSmrg
4558fe24f8a2Smrgtest install = "$opt_mode" && func_mode_install ${1+"$@"}
455934977a2fSmrg
456034977a2fSmrg
456134977a2fSmrg# func_generate_dlsyms outputname originator pic_p
456234977a2fSmrg# Extract symbols from dlprefiles and create ${outputname}S.o with
456334977a2fSmrg# a dlpreopen symbol table.
456434977a2fSmrgfunc_generate_dlsyms ()
456534977a2fSmrg{
4566fe24f8a2Smrg    $debug_cmd
4567fe24f8a2Smrg
4568fe24f8a2Smrg    my_outputname=$1
4569fe24f8a2Smrg    my_originator=$2
4570fe24f8a2Smrg    my_pic_p=${3-false}
4571fe24f8a2Smrg    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
457234977a2fSmrg    my_dlsyms=
457334977a2fSmrg
4574fe24f8a2Smrg    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
457534977a2fSmrg      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4576fe24f8a2Smrg	my_dlsyms=${my_outputname}S.c
457734977a2fSmrg      else
457834977a2fSmrg	func_error "not configured to extract global symbols from dlpreopened files"
457934977a2fSmrg      fi
458034977a2fSmrg    fi
458134977a2fSmrg
458234977a2fSmrg    if test -n "$my_dlsyms"; then
458334977a2fSmrg      case $my_dlsyms in
458434977a2fSmrg      "") ;;
458534977a2fSmrg      *.c)
458634977a2fSmrg	# Discover the nlist of each of the dlfiles.
4587fe24f8a2Smrg	nlist=$output_objdir/$my_outputname.nm
458834977a2fSmrg
458934977a2fSmrg	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
459034977a2fSmrg
459134977a2fSmrg	# Parse the name list into a source file.
459234977a2fSmrg	func_verbose "creating $output_objdir/$my_dlsyms"
459334977a2fSmrg
459434977a2fSmrg	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4595fe24f8a2Smrg/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4596fe24f8a2Smrg/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
459734977a2fSmrg
459834977a2fSmrg#ifdef __cplusplus
459934977a2fSmrgextern \"C\" {
460034977a2fSmrg#endif
460134977a2fSmrg
4602fe24f8a2Smrg#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
4603b425557eSmrg#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
4604b425557eSmrg#endif
4605b425557eSmrg
46063e72ca8cSmrg/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4607fe24f8a2Smrg#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4608fe24f8a2Smrg/* DATA imports from DLLs on WIN32 can't be const, because runtime
46093e72ca8cSmrg   relocations are performed -- see ld's documentation on pseudo-relocs.  */
46103e72ca8cSmrg# define LT_DLSYM_CONST
4611fe24f8a2Smrg#elif defined __osf__
46123e72ca8cSmrg/* This system does not cope well with relocations in const data.  */
46133e72ca8cSmrg# define LT_DLSYM_CONST
46143e72ca8cSmrg#else
46153e72ca8cSmrg# define LT_DLSYM_CONST const
46163e72ca8cSmrg#endif
46173e72ca8cSmrg
4618fe24f8a2Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4619fe24f8a2Smrg
462034977a2fSmrg/* External symbol declarations for the compiler. */\
462134977a2fSmrg"
462234977a2fSmrg
4623fe24f8a2Smrg	if test yes = "$dlself"; then
4624fe24f8a2Smrg	  func_verbose "generating symbol list for '$output'"
462534977a2fSmrg
462634977a2fSmrg	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
462734977a2fSmrg
462834977a2fSmrg	  # Add our own program objects to the symbol list.
4629b425557eSmrg	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
463034977a2fSmrg	  for progfile in $progfiles; do
46313e72ca8cSmrg	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4632fe24f8a2Smrg	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
46333e72ca8cSmrg	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
463434977a2fSmrg	  done
463534977a2fSmrg
463634977a2fSmrg	  if test -n "$exclude_expsyms"; then
463734977a2fSmrg	    $opt_dry_run || {
463834977a2fSmrg	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
463934977a2fSmrg	      eval '$MV "$nlist"T "$nlist"'
464034977a2fSmrg	    }
4641ee3138f1Smrg	  fi
464234977a2fSmrg
464334977a2fSmrg	  if test -n "$export_symbols_regex"; then
464434977a2fSmrg	    $opt_dry_run || {
464534977a2fSmrg	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
464634977a2fSmrg	      eval '$MV "$nlist"T "$nlist"'
464734977a2fSmrg	    }
464834977a2fSmrg	  fi
464934977a2fSmrg
465034977a2fSmrg	  # Prepare the list of exported symbols
465134977a2fSmrg	  if test -z "$export_symbols"; then
4652fe24f8a2Smrg	    export_symbols=$output_objdir/$outputname.exp
465334977a2fSmrg	    $opt_dry_run || {
465434977a2fSmrg	      $RM $export_symbols
4655fe24f8a2Smrg	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
465634977a2fSmrg	      case $host in
465734977a2fSmrg	      *cygwin* | *mingw* | *cegcc* )
465834977a2fSmrg                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
465934977a2fSmrg                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
466034977a2fSmrg	        ;;
466134977a2fSmrg	      esac
466234977a2fSmrg	    }
4663ee3138f1Smrg	  else
466434977a2fSmrg	    $opt_dry_run || {
4665fe24f8a2Smrg	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
466634977a2fSmrg	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
466734977a2fSmrg	      eval '$MV "$nlist"T "$nlist"'
466834977a2fSmrg	      case $host in
4669b425557eSmrg	        *cygwin* | *mingw* | *cegcc* )
467034977a2fSmrg	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
467134977a2fSmrg	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
467234977a2fSmrg	          ;;
467334977a2fSmrg	      esac
467434977a2fSmrg	    }
4675ee3138f1Smrg	  fi
467634977a2fSmrg	fi
4677ee3138f1Smrg
467834977a2fSmrg	for dlprefile in $dlprefiles; do
4679fe24f8a2Smrg	  func_verbose "extracting global C symbols from '$dlprefile'"
468034977a2fSmrg	  func_basename "$dlprefile"
4681fe24f8a2Smrg	  name=$func_basename_result
46823e72ca8cSmrg          case $host in
46833e72ca8cSmrg	    *cygwin* | *mingw* | *cegcc* )
46843e72ca8cSmrg	      # if an import library, we need to obtain dlname
46853e72ca8cSmrg	      if func_win32_import_lib_p "$dlprefile"; then
46863e72ca8cSmrg	        func_tr_sh "$dlprefile"
46873e72ca8cSmrg	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4688fe24f8a2Smrg	        dlprefile_dlbasename=
46893e72ca8cSmrg	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
46903e72ca8cSmrg	          # Use subshell, to avoid clobbering current variable values
46913e72ca8cSmrg	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
4692fe24f8a2Smrg	          if test -n "$dlprefile_dlname"; then
46933e72ca8cSmrg	            func_basename "$dlprefile_dlname"
4694fe24f8a2Smrg	            dlprefile_dlbasename=$func_basename_result
46953e72ca8cSmrg	          else
46963e72ca8cSmrg	            # no lafile. user explicitly requested -dlpreopen <import library>.
46973e72ca8cSmrg	            $sharedlib_from_linklib_cmd "$dlprefile"
46983e72ca8cSmrg	            dlprefile_dlbasename=$sharedlib_from_linklib_result
46993e72ca8cSmrg	          fi
47003e72ca8cSmrg	        fi
47013e72ca8cSmrg	        $opt_dry_run || {
4702fe24f8a2Smrg	          if test -n "$dlprefile_dlbasename"; then
47033e72ca8cSmrg	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
47043e72ca8cSmrg	          else
47053e72ca8cSmrg	            func_warning "Could not compute DLL name from $name"
47063e72ca8cSmrg	            eval '$ECHO ": $name " >> "$nlist"'
47073e72ca8cSmrg	          fi
47083e72ca8cSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47093e72ca8cSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
47103e72ca8cSmrg	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
47113e72ca8cSmrg	        }
47123e72ca8cSmrg	      else # not an import lib
47133e72ca8cSmrg	        $opt_dry_run || {
47143e72ca8cSmrg	          eval '$ECHO ": $name " >> "$nlist"'
47153e72ca8cSmrg	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47163e72ca8cSmrg	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
47173e72ca8cSmrg	        }
47183e72ca8cSmrg	      fi
47193e72ca8cSmrg	    ;;
47203e72ca8cSmrg	    *)
47213e72ca8cSmrg	      $opt_dry_run || {
47223e72ca8cSmrg	        eval '$ECHO ": $name " >> "$nlist"'
47233e72ca8cSmrg	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
47243e72ca8cSmrg	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
47253e72ca8cSmrg	      }
47263e72ca8cSmrg	    ;;
47273e72ca8cSmrg          esac
472834977a2fSmrg	done
472934977a2fSmrg
473034977a2fSmrg	$opt_dry_run || {
473134977a2fSmrg	  # Make sure we have at least an empty file.
473234977a2fSmrg	  test -f "$nlist" || : > "$nlist"
473334977a2fSmrg
473434977a2fSmrg	  if test -n "$exclude_expsyms"; then
473534977a2fSmrg	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
473634977a2fSmrg	    $MV "$nlist"T "$nlist"
4737ee3138f1Smrg	  fi
473834977a2fSmrg
473934977a2fSmrg	  # Try sorting and uniquifying the output.
474034977a2fSmrg	  if $GREP -v "^: " < "$nlist" |
474134977a2fSmrg	      if sort -k 3 </dev/null >/dev/null 2>&1; then
474234977a2fSmrg		sort -k 3
474334977a2fSmrg	      else
474434977a2fSmrg		sort +2
474534977a2fSmrg	      fi |
474634977a2fSmrg	      uniq > "$nlist"S; then
474734977a2fSmrg	    :
4748ee3138f1Smrg	  else
474934977a2fSmrg	    $GREP -v "^: " < "$nlist" > "$nlist"S
4750ee3138f1Smrg	  fi
4751ee3138f1Smrg
475234977a2fSmrg	  if test -f "$nlist"S; then
475334977a2fSmrg	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
4754ee3138f1Smrg	  else
4755b425557eSmrg	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
4756ee3138f1Smrg	  fi
4757ee3138f1Smrg
4758fe24f8a2Smrg	  func_show_eval '$RM "${nlist}I"'
4759fe24f8a2Smrg	  if test -n "$global_symbol_to_import"; then
4760fe24f8a2Smrg	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
4761fe24f8a2Smrg	  fi
4762fe24f8a2Smrg
4763b425557eSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
4764ee3138f1Smrg
476534977a2fSmrg/* The mapping between symbol names and symbols.  */
476634977a2fSmrgtypedef struct {
476734977a2fSmrg  const char *name;
476834977a2fSmrg  void *address;
476934977a2fSmrg} lt_dlsymlist;
47703e72ca8cSmrgextern LT_DLSYM_CONST lt_dlsymlist
4771fe24f8a2Smrglt_${my_prefix}_LTX_preloaded_symbols[];\
4772fe24f8a2Smrg"
4773fe24f8a2Smrg
4774fe24f8a2Smrg	  if test -s "$nlist"I; then
4775fe24f8a2Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4776fe24f8a2Smrgstatic void lt_syminit(void)
4777fe24f8a2Smrg{
4778fe24f8a2Smrg  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
4779fe24f8a2Smrg  for (; symbol->name; ++symbol)
4780fe24f8a2Smrg    {"
4781fe24f8a2Smrg	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
4782fe24f8a2Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4783fe24f8a2Smrg    }
4784fe24f8a2Smrg}"
4785fe24f8a2Smrg	  fi
4786fe24f8a2Smrg	  echo >> "$output_objdir/$my_dlsyms" "\
47873e72ca8cSmrgLT_DLSYM_CONST lt_dlsymlist
478834977a2fSmrglt_${my_prefix}_LTX_preloaded_symbols[] =
4789fe24f8a2Smrg{ {\"$my_originator\", (void *) 0},"
4790fe24f8a2Smrg
4791fe24f8a2Smrg	  if test -s "$nlist"I; then
4792fe24f8a2Smrg	    echo >> "$output_objdir/$my_dlsyms" "\
4793fe24f8a2Smrg  {\"@INIT@\", (void *) &lt_syminit},"
4794fe24f8a2Smrg	  fi
4795ee3138f1Smrg
479634977a2fSmrg	  case $need_lib_prefix in
479734977a2fSmrg	  no)
479834977a2fSmrg	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
479934977a2fSmrg	    ;;
480034977a2fSmrg	  *)
480134977a2fSmrg	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
480234977a2fSmrg	    ;;
480334977a2fSmrg	  esac
4804b425557eSmrg	  echo >> "$output_objdir/$my_dlsyms" "\
480534977a2fSmrg  {0, (void *) 0}
480634977a2fSmrg};
4807ee3138f1Smrg
480834977a2fSmrg/* This works around a problem in FreeBSD linker */
480934977a2fSmrg#ifdef FREEBSD_WORKAROUND
481034977a2fSmrgstatic const void *lt_preloaded_setup() {
481134977a2fSmrg  return lt_${my_prefix}_LTX_preloaded_symbols;
481234977a2fSmrg}
481334977a2fSmrg#endif
481434977a2fSmrg
481534977a2fSmrg#ifdef __cplusplus
481634977a2fSmrg}
481734977a2fSmrg#endif\
481834977a2fSmrg"
481934977a2fSmrg	} # !$opt_dry_run
482034977a2fSmrg
482134977a2fSmrg	pic_flag_for_symtable=
482234977a2fSmrg	case "$compile_command " in
482334977a2fSmrg	*" -static "*) ;;
482434977a2fSmrg	*)
482534977a2fSmrg	  case $host in
482634977a2fSmrg	  # compiling the symbol table file with pic_flag works around
482734977a2fSmrg	  # a FreeBSD bug that causes programs to crash when -lm is
482834977a2fSmrg	  # linked before any other PIC object.  But we must not use
482934977a2fSmrg	  # pic_flag when linking with -static.  The problem exists in
483034977a2fSmrg	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
48313e72ca8cSmrg	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
483234977a2fSmrg	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
483334977a2fSmrg	  *-*-hpux*)
483434977a2fSmrg	    pic_flag_for_symtable=" $pic_flag"  ;;
483534977a2fSmrg	  *)
4836fe24f8a2Smrg	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
483734977a2fSmrg	    ;;
483834977a2fSmrg	  esac
483934977a2fSmrg	  ;;
484034977a2fSmrg	esac
484134977a2fSmrg	symtab_cflags=
484234977a2fSmrg	for arg in $LTCFLAGS; do
484334977a2fSmrg	  case $arg in
484434977a2fSmrg	  -pie | -fpie | -fPIE) ;;
48453e72ca8cSmrg	  *) func_append symtab_cflags " $arg" ;;
484634977a2fSmrg	  esac
484734977a2fSmrg	done
4848ee3138f1Smrg
484934977a2fSmrg	# Now compile the dynamic symbol file.
485034977a2fSmrg	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
4851ee3138f1Smrg
485234977a2fSmrg	# Clean up the generated files.
4853fe24f8a2Smrg	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
4854ee3138f1Smrg
485534977a2fSmrg	# Transform the symbol file into the correct name.
4856fe24f8a2Smrg	symfileobj=$output_objdir/${my_outputname}S.$objext
485734977a2fSmrg	case $host in
485834977a2fSmrg	*cygwin* | *mingw* | *cegcc* )
485934977a2fSmrg	  if test -f "$output_objdir/$my_outputname.def"; then
4860b425557eSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
4861b425557eSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
486234977a2fSmrg	  else
4863b425557eSmrg	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4864b425557eSmrg	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4865ee3138f1Smrg	  fi
486634977a2fSmrg	  ;;
486734977a2fSmrg	*)
4868b425557eSmrg	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
4869b425557eSmrg	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
487034977a2fSmrg	  ;;
487134977a2fSmrg	esac
487234977a2fSmrg	;;
487334977a2fSmrg      *)
4874fe24f8a2Smrg	func_fatal_error "unknown suffix for '$my_dlsyms'"
487534977a2fSmrg	;;
487634977a2fSmrg      esac
487734977a2fSmrg    else
487834977a2fSmrg      # We keep going just in case the user didn't refer to
487934977a2fSmrg      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
488034977a2fSmrg      # really was required.
4881ee3138f1Smrg
488234977a2fSmrg      # Nullify the symbol file.
4883b425557eSmrg      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
4884b425557eSmrg      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
488534977a2fSmrg    fi
488634977a2fSmrg}
4887ee3138f1Smrg
4888fe24f8a2Smrg# func_cygming_gnu_implib_p ARG
4889fe24f8a2Smrg# This predicate returns with zero status (TRUE) if
4890fe24f8a2Smrg# ARG is a GNU/binutils-style import library. Returns
4891fe24f8a2Smrg# with nonzero status (FALSE) otherwise.
4892fe24f8a2Smrgfunc_cygming_gnu_implib_p ()
4893fe24f8a2Smrg{
4894fe24f8a2Smrg  $debug_cmd
4895fe24f8a2Smrg
4896fe24f8a2Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4897fe24f8a2Smrg  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)$'`
4898fe24f8a2Smrg  test -n "$func_cygming_gnu_implib_tmp"
4899fe24f8a2Smrg}
4900fe24f8a2Smrg
4901fe24f8a2Smrg# func_cygming_ms_implib_p ARG
4902fe24f8a2Smrg# This predicate returns with zero status (TRUE) if
4903fe24f8a2Smrg# ARG is an MS-style import library. Returns
4904fe24f8a2Smrg# with nonzero status (FALSE) otherwise.
4905fe24f8a2Smrgfunc_cygming_ms_implib_p ()
4906fe24f8a2Smrg{
4907fe24f8a2Smrg  $debug_cmd
4908fe24f8a2Smrg
4909fe24f8a2Smrg  func_to_tool_file "$1" func_convert_file_msys_to_w32
4910fe24f8a2Smrg  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
4911fe24f8a2Smrg  test -n "$func_cygming_ms_implib_tmp"
4912fe24f8a2Smrg}
4913fe24f8a2Smrg
491434977a2fSmrg# func_win32_libid arg
491534977a2fSmrg# return the library type of file 'arg'
491634977a2fSmrg#
491734977a2fSmrg# Need a lot of goo to handle *both* DLLs and import libs
491834977a2fSmrg# Has to be a shell function in order to 'eat' the argument
491934977a2fSmrg# that is supplied when $file_magic_command is called.
4920b425557eSmrg# Despite the name, also deal with 64 bit binaries.
492134977a2fSmrgfunc_win32_libid ()
492234977a2fSmrg{
4923fe24f8a2Smrg  $debug_cmd
4924fe24f8a2Smrg
4925fe24f8a2Smrg  win32_libid_type=unknown
492634977a2fSmrg  win32_fileres=`file -L $1 2>/dev/null`
492734977a2fSmrg  case $win32_fileres in
492834977a2fSmrg  *ar\ archive\ import\ library*) # definitely import
492934977a2fSmrg    win32_libid_type="x86 archive import"
493034977a2fSmrg    ;;
493134977a2fSmrg  *ar\ archive*) # could be an import, or static
4932b425557eSmrg    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
493334977a2fSmrg    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
4934b425557eSmrg       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
4935fe24f8a2Smrg      case $nm_interface in
4936fe24f8a2Smrg      "MS dumpbin")
4937fe24f8a2Smrg	if func_cygming_ms_implib_p "$1" ||
4938fe24f8a2Smrg	   func_cygming_gnu_implib_p "$1"
4939fe24f8a2Smrg	then
4940fe24f8a2Smrg	  win32_nmres=import
4941fe24f8a2Smrg	else
4942fe24f8a2Smrg	  win32_nmres=
4943fe24f8a2Smrg	fi
4944fe24f8a2Smrg	;;
4945fe24f8a2Smrg      *)
4946fe24f8a2Smrg	func_to_tool_file "$1" func_convert_file_msys_to_w32
4947fe24f8a2Smrg	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
4948fe24f8a2Smrg	  $SED -n -e '
494934977a2fSmrg	    1,100{
495034977a2fSmrg		/ I /{
4951fe24f8a2Smrg		    s|.*|import|
495234977a2fSmrg		    p
495334977a2fSmrg		    q
495434977a2fSmrg		}
495534977a2fSmrg	    }'`
4956fe24f8a2Smrg	;;
4957fe24f8a2Smrg      esac
495834977a2fSmrg      case $win32_nmres in
495934977a2fSmrg      import*)  win32_libid_type="x86 archive import";;
496034977a2fSmrg      *)        win32_libid_type="x86 archive static";;
496134977a2fSmrg      esac
496234977a2fSmrg    fi
496334977a2fSmrg    ;;
496434977a2fSmrg  *DLL*)
496534977a2fSmrg    win32_libid_type="x86 DLL"
496634977a2fSmrg    ;;
496734977a2fSmrg  *executable*) # but shell scripts are "executable" too...
496834977a2fSmrg    case $win32_fileres in
496934977a2fSmrg    *MS\ Windows\ PE\ Intel*)
497034977a2fSmrg      win32_libid_type="x86 DLL"
497134977a2fSmrg      ;;
497234977a2fSmrg    esac
497334977a2fSmrg    ;;
497434977a2fSmrg  esac
497534977a2fSmrg  $ECHO "$win32_libid_type"
497634977a2fSmrg}
4977ee3138f1Smrg
49783e72ca8cSmrg# func_cygming_dll_for_implib ARG
49793e72ca8cSmrg#
49803e72ca8cSmrg# Platform-specific function to extract the
49813e72ca8cSmrg# name of the DLL associated with the specified
49823e72ca8cSmrg# import library ARG.
49833e72ca8cSmrg# Invoked by eval'ing the libtool variable
49843e72ca8cSmrg#    $sharedlib_from_linklib_cmd
49853e72ca8cSmrg# Result is available in the variable
49863e72ca8cSmrg#    $sharedlib_from_linklib_result
49873e72ca8cSmrgfunc_cygming_dll_for_implib ()
49883e72ca8cSmrg{
4989fe24f8a2Smrg  $debug_cmd
4990fe24f8a2Smrg
49913e72ca8cSmrg  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
49923e72ca8cSmrg}
49933e72ca8cSmrg
49943e72ca8cSmrg# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
49953e72ca8cSmrg#
49963e72ca8cSmrg# The is the core of a fallback implementation of a
49973e72ca8cSmrg# platform-specific function to extract the name of the
49983e72ca8cSmrg# DLL associated with the specified import library LIBNAME.
49993e72ca8cSmrg#
50003e72ca8cSmrg# SECTION_NAME is either .idata$6 or .idata$7, depending
50013e72ca8cSmrg# on the platform and compiler that created the implib.
50023e72ca8cSmrg#
50033e72ca8cSmrg# Echos the name of the DLL associated with the
50043e72ca8cSmrg# specified import library.
50053e72ca8cSmrgfunc_cygming_dll_for_implib_fallback_core ()
50063e72ca8cSmrg{
5007fe24f8a2Smrg  $debug_cmd
5008fe24f8a2Smrg
50093e72ca8cSmrg  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
50103e72ca8cSmrg  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
50113e72ca8cSmrg    $SED '/^Contents of section '"$match_literal"':/{
50123e72ca8cSmrg      # Place marker at beginning of archive member dllname section
50133e72ca8cSmrg      s/.*/====MARK====/
50143e72ca8cSmrg      p
50153e72ca8cSmrg      d
50163e72ca8cSmrg    }
50173e72ca8cSmrg    # These lines can sometimes be longer than 43 characters, but
50183e72ca8cSmrg    # are always uninteresting
50193e72ca8cSmrg    /:[	 ]*file format pe[i]\{,1\}-/d
50203e72ca8cSmrg    /^In archive [^:]*:/d
50213e72ca8cSmrg    # Ensure marker is printed
50223e72ca8cSmrg    /^====MARK====/p
50233e72ca8cSmrg    # Remove all lines with less than 43 characters
50243e72ca8cSmrg    /^.\{43\}/!d
50253e72ca8cSmrg    # From remaining lines, remove first 43 characters
50263e72ca8cSmrg    s/^.\{43\}//' |
50273e72ca8cSmrg    $SED -n '
50283e72ca8cSmrg      # Join marker and all lines until next marker into a single line
50293e72ca8cSmrg      /^====MARK====/ b para
50303e72ca8cSmrg      H
50313e72ca8cSmrg      $ b para
50323e72ca8cSmrg      b
50333e72ca8cSmrg      :para
50343e72ca8cSmrg      x
50353e72ca8cSmrg      s/\n//g
50363e72ca8cSmrg      # Remove the marker
50373e72ca8cSmrg      s/^====MARK====//
50383e72ca8cSmrg      # Remove trailing dots and whitespace
50393e72ca8cSmrg      s/[\. \t]*$//
50403e72ca8cSmrg      # Print
50413e72ca8cSmrg      /./p' |
50423e72ca8cSmrg    # we now have a list, one entry per line, of the stringified
50433e72ca8cSmrg    # contents of the appropriate section of all members of the
5044fe24f8a2Smrg    # archive that possess that section. Heuristic: eliminate
5045fe24f8a2Smrg    # all those that have a first or second character that is
50463e72ca8cSmrg    # a '.' (that is, objdump's representation of an unprintable
50473e72ca8cSmrg    # character.) This should work for all archives with less than
50483e72ca8cSmrg    # 0x302f exports -- but will fail for DLLs whose name actually
50493e72ca8cSmrg    # begins with a literal '.' or a single character followed by
50503e72ca8cSmrg    # a '.'.
50513e72ca8cSmrg    #
50523e72ca8cSmrg    # Of those that remain, print the first one.
50533e72ca8cSmrg    $SED -e '/^\./d;/^.\./d;q'
50543e72ca8cSmrg}
50553e72ca8cSmrg
50563e72ca8cSmrg# func_cygming_dll_for_implib_fallback ARG
50573e72ca8cSmrg# Platform-specific function to extract the
50583e72ca8cSmrg# name of the DLL associated with the specified
50593e72ca8cSmrg# import library ARG.
50603e72ca8cSmrg#
50613e72ca8cSmrg# This fallback implementation is for use when $DLLTOOL
50623e72ca8cSmrg# does not support the --identify-strict option.
50633e72ca8cSmrg# Invoked by eval'ing the libtool variable
50643e72ca8cSmrg#    $sharedlib_from_linklib_cmd
50653e72ca8cSmrg# Result is available in the variable
50663e72ca8cSmrg#    $sharedlib_from_linklib_result
50673e72ca8cSmrgfunc_cygming_dll_for_implib_fallback ()
50683e72ca8cSmrg{
5069fe24f8a2Smrg  $debug_cmd
5070fe24f8a2Smrg
5071fe24f8a2Smrg  if func_cygming_gnu_implib_p "$1"; then
50723e72ca8cSmrg    # binutils import library
50733e72ca8cSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
5074fe24f8a2Smrg  elif func_cygming_ms_implib_p "$1"; then
50753e72ca8cSmrg    # ms-generated import library
50763e72ca8cSmrg    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
50773e72ca8cSmrg  else
50783e72ca8cSmrg    # unknown
5079fe24f8a2Smrg    sharedlib_from_linklib_result=
50803e72ca8cSmrg  fi
50813e72ca8cSmrg}
5082ee3138f1Smrg
5083ee3138f1Smrg
508434977a2fSmrg# func_extract_an_archive dir oldlib
508534977a2fSmrgfunc_extract_an_archive ()
508634977a2fSmrg{
5087fe24f8a2Smrg    $debug_cmd
5088fe24f8a2Smrg
5089fe24f8a2Smrg    f_ex_an_ar_dir=$1; shift
5090fe24f8a2Smrg    f_ex_an_ar_oldlib=$1
5091fe24f8a2Smrg    if test yes = "$lock_old_archive_extraction"; then
5092b425557eSmrg      lockfile=$f_ex_an_ar_oldlib.lock
5093b425557eSmrg      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
5094b425557eSmrg	func_echo "Waiting for $lockfile to be removed"
5095b425557eSmrg	sleep 2
5096b425557eSmrg      done
5097b425557eSmrg    fi
5098b425557eSmrg    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
5099b425557eSmrg		   'stat=$?; rm -f "$lockfile"; exit $stat'
5100fe24f8a2Smrg    if test yes = "$lock_old_archive_extraction"; then
5101b425557eSmrg      $opt_dry_run || rm -f "$lockfile"
5102b425557eSmrg    fi
510334977a2fSmrg    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
510434977a2fSmrg     :
510534977a2fSmrg    else
510634977a2fSmrg      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
510734977a2fSmrg    fi
510834977a2fSmrg}
5109ee3138f1Smrg
5110ee3138f1Smrg
511134977a2fSmrg# func_extract_archives gentop oldlib ...
511234977a2fSmrgfunc_extract_archives ()
511334977a2fSmrg{
5114fe24f8a2Smrg    $debug_cmd
5115fe24f8a2Smrg
5116fe24f8a2Smrg    my_gentop=$1; shift
511734977a2fSmrg    my_oldlibs=${1+"$@"}
5118fe24f8a2Smrg    my_oldobjs=
5119fe24f8a2Smrg    my_xlib=
5120fe24f8a2Smrg    my_xabs=
5121fe24f8a2Smrg    my_xdir=
5122ee3138f1Smrg
512334977a2fSmrg    for my_xlib in $my_oldlibs; do
512434977a2fSmrg      # Extract the objects.
512534977a2fSmrg      case $my_xlib in
5126fe24f8a2Smrg	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
512734977a2fSmrg	*) my_xabs=`pwd`"/$my_xlib" ;;
512834977a2fSmrg      esac
512934977a2fSmrg      func_basename "$my_xlib"
5130fe24f8a2Smrg      my_xlib=$func_basename_result
513134977a2fSmrg      my_xlib_u=$my_xlib
513234977a2fSmrg      while :; do
513334977a2fSmrg        case " $extracted_archives " in
513434977a2fSmrg	*" $my_xlib_u "*)
513534977a2fSmrg	  func_arith $extracted_serial + 1
513634977a2fSmrg	  extracted_serial=$func_arith_result
513734977a2fSmrg	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
513834977a2fSmrg	*) break ;;
513934977a2fSmrg	esac
514034977a2fSmrg      done
514134977a2fSmrg      extracted_archives="$extracted_archives $my_xlib_u"
5142fe24f8a2Smrg      my_xdir=$my_gentop/$my_xlib_u
5143ee3138f1Smrg
514434977a2fSmrg      func_mkdir_p "$my_xdir"
5145ee3138f1Smrg
514634977a2fSmrg      case $host in
514734977a2fSmrg      *-darwin*)
514834977a2fSmrg	func_verbose "Extracting $my_xabs"
514934977a2fSmrg	# Do not bother doing anything if just a dry run
515034977a2fSmrg	$opt_dry_run || {
515134977a2fSmrg	  darwin_orig_dir=`pwd`
515234977a2fSmrg	  cd $my_xdir || exit $?
515334977a2fSmrg	  darwin_archive=$my_xabs
515434977a2fSmrg	  darwin_curdir=`pwd`
5155fe24f8a2Smrg	  func_basename "$darwin_archive"
5156fe24f8a2Smrg	  darwin_base_archive=$func_basename_result
515734977a2fSmrg	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
515834977a2fSmrg	  if test -n "$darwin_arches"; then
515934977a2fSmrg	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
516034977a2fSmrg	    darwin_arch=
516134977a2fSmrg	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
5162fe24f8a2Smrg	    for darwin_arch in  $darwin_arches; do
5163fe24f8a2Smrg	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5164fe24f8a2Smrg	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5165fe24f8a2Smrg	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5166fe24f8a2Smrg	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
516734977a2fSmrg	      cd "$darwin_curdir"
5168fe24f8a2Smrg	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
516934977a2fSmrg	    done # $darwin_arches
517034977a2fSmrg            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5171fe24f8a2Smrg	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
517234977a2fSmrg	    darwin_file=
517334977a2fSmrg	    darwin_files=
517434977a2fSmrg	    for darwin_file in $darwin_filelist; do
5175b425557eSmrg	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
517634977a2fSmrg	      $LIPO -create -output "$darwin_file" $darwin_files
517734977a2fSmrg	    done # $darwin_filelist
517834977a2fSmrg	    $RM -rf unfat-$$
517934977a2fSmrg	    cd "$darwin_orig_dir"
5180ee3138f1Smrg	  else
518134977a2fSmrg	    cd $darwin_orig_dir
518234977a2fSmrg	    func_extract_an_archive "$my_xdir" "$my_xabs"
518334977a2fSmrg	  fi # $darwin_arches
518434977a2fSmrg	} # !$opt_dry_run
518534977a2fSmrg	;;
518634977a2fSmrg      *)
518734977a2fSmrg        func_extract_an_archive "$my_xdir" "$my_xabs"
518834977a2fSmrg	;;
518934977a2fSmrg      esac
5190b425557eSmrg      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
519134977a2fSmrg    done
5192ee3138f1Smrg
5193fe24f8a2Smrg    func_extract_archives_result=$my_oldobjs
519434977a2fSmrg}
5195ee3138f1Smrg
5196ee3138f1Smrg
5197b425557eSmrg# func_emit_wrapper [arg=no]
5198b425557eSmrg#
5199b425557eSmrg# Emit a libtool wrapper script on stdout.
5200b425557eSmrg# Don't directly open a file because we may want to
5201b425557eSmrg# incorporate the script contents within a cygwin/mingw
5202b425557eSmrg# wrapper executable.  Must ONLY be called from within
5203b425557eSmrg# func_mode_link because it depends on a number of variables
5204b425557eSmrg# set therein.
520534977a2fSmrg#
5206b425557eSmrg# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
5207b425557eSmrg# variable will take.  If 'yes', then the emitted script
5208fe24f8a2Smrg# will assume that the directory where it is stored is
5209b425557eSmrg# the $objdir directory.  This is a cygwin/mingw-specific
5210b425557eSmrg# behavior.
5211b425557eSmrgfunc_emit_wrapper ()
521234977a2fSmrg{
5213b425557eSmrg	func_emit_wrapper_arg1=${1-no}
5214ee3138f1Smrg
521534977a2fSmrg	$ECHO "\
521634977a2fSmrg#! $SHELL
5217ee3138f1Smrg
521834977a2fSmrg# $output - temporary wrapper script for $objdir/$outputname
5219fe24f8a2Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
522034977a2fSmrg#
522134977a2fSmrg# The $output program cannot be directly executed until all the libtool
522234977a2fSmrg# libraries that it depends on are installed.
522334977a2fSmrg#
522434977a2fSmrg# This wrapper script should never be moved out of the build directory.
522534977a2fSmrg# If it is, it will not operate correctly.
5226ee3138f1Smrg
522734977a2fSmrg# Sed substitution that helps us do robust quoting.  It backslashifies
522834977a2fSmrg# metacharacters that are still active within double-quoted strings.
522934977a2fSmrgsed_quote_subst='$sed_quote_subst'
5230ee3138f1Smrg
523134977a2fSmrg# Be Bourne compatible
523234977a2fSmrgif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
523334977a2fSmrg  emulate sh
523434977a2fSmrg  NULLCMD=:
523534977a2fSmrg  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
523634977a2fSmrg  # is contrary to our usage.  Disable this feature.
523734977a2fSmrg  alias -g '\${1+\"\$@\"}'='\"\$@\"'
523834977a2fSmrg  setopt NO_GLOB_SUBST
523934977a2fSmrgelse
524034977a2fSmrg  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
524134977a2fSmrgfi
524234977a2fSmrgBIN_SH=xpg4; export BIN_SH # for Tru64
524334977a2fSmrgDUALCASE=1; export DUALCASE # for MKS sh
5244ee3138f1Smrg
524534977a2fSmrg# The HP-UX ksh and POSIX shell print the target directory to stdout
524634977a2fSmrg# if CDPATH is set.
524734977a2fSmrg(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
5248ee3138f1Smrg
524934977a2fSmrgrelink_command=\"$relink_command\"
5250ee3138f1Smrg
525134977a2fSmrg# This environment variable determines our operation mode.
525234977a2fSmrgif test \"\$libtool_install_magic\" = \"$magic\"; then
525334977a2fSmrg  # install mode needs the following variables:
525434977a2fSmrg  generated_by_libtool_version='$macro_version'
525534977a2fSmrg  notinst_deplibs='$notinst_deplibs'
525634977a2fSmrgelse
525734977a2fSmrg  # When we are sourced in execute mode, \$file and \$ECHO are already set.
525834977a2fSmrg  if test \"\$libtool_execute_magic\" != \"$magic\"; then
5259b425557eSmrg    file=\"\$0\""
5260b425557eSmrg
5261b425557eSmrg    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
5262b425557eSmrg    $ECHO "\
5263b425557eSmrg
5264b425557eSmrg# A function that is used when there is no print builtin or printf.
5265b425557eSmrgfunc_fallback_echo ()
5266b425557eSmrg{
5267b425557eSmrg  eval 'cat <<_LTECHO_EOF
5268b425557eSmrg\$1
5269b425557eSmrg_LTECHO_EOF'
5270b425557eSmrg}
5271b425557eSmrg    ECHO=\"$qECHO\"
5272b425557eSmrg  fi
5273b425557eSmrg
5274b425557eSmrg# Very basic option parsing. These options are (a) specific to
5275b425557eSmrg# the libtool wrapper, (b) are identical between the wrapper
5276fe24f8a2Smrg# /script/ and the wrapper /executable/ that is used only on
5277b425557eSmrg# windows platforms, and (c) all begin with the string "--lt-"
5278fe24f8a2Smrg# (application programs are unlikely to have options that match
5279b425557eSmrg# this pattern).
5280b425557eSmrg#
5281b425557eSmrg# There are only two supported options: --lt-debug and
5282b425557eSmrg# --lt-dump-script. There is, deliberately, no --lt-help.
5283b425557eSmrg#
5284b425557eSmrg# The first argument to this parsing function should be the
5285b425557eSmrg# script's $0 value, followed by "$@".
5286b425557eSmrglt_option_debug=
5287b425557eSmrgfunc_parse_lt_options ()
5288b425557eSmrg{
5289b425557eSmrg  lt_script_arg0=\$0
5290b425557eSmrg  shift
5291b425557eSmrg  for lt_opt
5292b425557eSmrg  do
5293b425557eSmrg    case \"\$lt_opt\" in
5294b425557eSmrg    --lt-debug) lt_option_debug=1 ;;
5295b425557eSmrg    --lt-dump-script)
5296b425557eSmrg        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
5297b425557eSmrg        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
5298b425557eSmrg        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
5299b425557eSmrg        cat \"\$lt_dump_D/\$lt_dump_F\"
5300b425557eSmrg        exit 0
5301b425557eSmrg      ;;
5302b425557eSmrg    --lt-*)
5303b425557eSmrg        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
5304b425557eSmrg        exit 1
5305b425557eSmrg      ;;
5306b425557eSmrg    esac
5307b425557eSmrg  done
5308b425557eSmrg
5309b425557eSmrg  # Print the debug banner immediately:
5310b425557eSmrg  if test -n \"\$lt_option_debug\"; then
5311fe24f8a2Smrg    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
5312b425557eSmrg  fi
5313b425557eSmrg}
5314b425557eSmrg
5315b425557eSmrg# Used when --lt-debug. Prints its arguments to stdout
5316b425557eSmrg# (redirection is the responsibility of the caller)
5317b425557eSmrgfunc_lt_dump_args ()
5318b425557eSmrg{
5319b425557eSmrg  lt_dump_args_N=1;
5320b425557eSmrg  for lt_arg
5321b425557eSmrg  do
5322fe24f8a2Smrg    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
5323b425557eSmrg    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
5324b425557eSmrg  done
5325b425557eSmrg}
5326b425557eSmrg
5327b425557eSmrg# Core function for launching the target application
5328b425557eSmrgfunc_exec_program_core ()
5329b425557eSmrg{
533034977a2fSmrg"
5331b425557eSmrg  case $host in
5332b425557eSmrg  # Backslashes separate directories on plain windows
5333b425557eSmrg  *-*-mingw | *-*-os2* | *-cegcc*)
5334b425557eSmrg    $ECHO "\
5335b425557eSmrg      if test -n \"\$lt_option_debug\"; then
5336fe24f8a2Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
5337b425557eSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5338b425557eSmrg      fi
5339b425557eSmrg      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
5340b425557eSmrg"
5341b425557eSmrg    ;;
5342b425557eSmrg
5343b425557eSmrg  *)
5344b425557eSmrg    $ECHO "\
5345b425557eSmrg      if test -n \"\$lt_option_debug\"; then
5346fe24f8a2Smrg        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
5347b425557eSmrg        func_lt_dump_args \${1+\"\$@\"} 1>&2
5348b425557eSmrg      fi
5349b425557eSmrg      exec \"\$progdir/\$program\" \${1+\"\$@\"}
5350b425557eSmrg"
5351b425557eSmrg    ;;
5352b425557eSmrg  esac
5353b425557eSmrg  $ECHO "\
5354b425557eSmrg      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
5355b425557eSmrg      exit 1
5356b425557eSmrg}
5357b425557eSmrg
5358b425557eSmrg# A function to encapsulate launching the target application
5359b425557eSmrg# Strips options in the --lt-* namespace from \$@ and
5360b425557eSmrg# launches target application with the remaining arguments.
5361b425557eSmrgfunc_exec_program ()
5362b425557eSmrg{
53633e72ca8cSmrg  case \" \$* \" in
53643e72ca8cSmrg  *\\ --lt-*)
53653e72ca8cSmrg    for lt_wr_arg
53663e72ca8cSmrg    do
53673e72ca8cSmrg      case \$lt_wr_arg in
53683e72ca8cSmrg      --lt-*) ;;
53693e72ca8cSmrg      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
53703e72ca8cSmrg      esac
53713e72ca8cSmrg      shift
53723e72ca8cSmrg    done ;;
53733e72ca8cSmrg  esac
5374b425557eSmrg  func_exec_program_core \${1+\"\$@\"}
5375b425557eSmrg}
5376b425557eSmrg
5377b425557eSmrg  # Parse options
5378b425557eSmrg  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
5379ee3138f1Smrg
538034977a2fSmrg  # Find the directory that this script lives in.
5381b425557eSmrg  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
538234977a2fSmrg  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
5383ee3138f1Smrg
538434977a2fSmrg  # Follow symbolic links until we get to the real thisdir.
5385b425557eSmrg  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
538634977a2fSmrg  while test -n \"\$file\"; do
5387b425557eSmrg    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
5388ee3138f1Smrg
538934977a2fSmrg    # If there was a directory component, then change thisdir.
539034977a2fSmrg    if test \"x\$destdir\" != \"x\$file\"; then
539134977a2fSmrg      case \"\$destdir\" in
539234977a2fSmrg      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
539334977a2fSmrg      *) thisdir=\"\$thisdir/\$destdir\" ;;
5394ee3138f1Smrg      esac
539534977a2fSmrg    fi
5396ee3138f1Smrg
5397b425557eSmrg    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
5398b425557eSmrg    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
539934977a2fSmrg  done
5400ee3138f1Smrg
540134977a2fSmrg  # Usually 'no', except on cygwin/mingw when embedded into
540234977a2fSmrg  # the cwrapper.
5403b425557eSmrg  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
540434977a2fSmrg  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
540534977a2fSmrg    # special case for '.'
540634977a2fSmrg    if test \"\$thisdir\" = \".\"; then
540734977a2fSmrg      thisdir=\`pwd\`
540834977a2fSmrg    fi
540934977a2fSmrg    # remove .libs from thisdir
541034977a2fSmrg    case \"\$thisdir\" in
5411b425557eSmrg    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
541234977a2fSmrg    $objdir )   thisdir=. ;;
541334977a2fSmrg    esac
541434977a2fSmrg  fi
541534977a2fSmrg
541634977a2fSmrg  # Try to get the absolute directory name.
541734977a2fSmrg  absdir=\`cd \"\$thisdir\" && pwd\`
541834977a2fSmrg  test -n \"\$absdir\" && thisdir=\"\$absdir\"
541934977a2fSmrg"
542034977a2fSmrg
5421fe24f8a2Smrg	if test yes = "$fast_install"; then
542234977a2fSmrg	  $ECHO "\
542334977a2fSmrg  program=lt-'$outputname'$exeext
542434977a2fSmrg  progdir=\"\$thisdir/$objdir\"
542534977a2fSmrg
542634977a2fSmrg  if test ! -f \"\$progdir/\$program\" ||
5427fe24f8a2Smrg     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
542834977a2fSmrg       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
542934977a2fSmrg
543034977a2fSmrg    file=\"\$\$-\$program\"
543134977a2fSmrg
543234977a2fSmrg    if test ! -d \"\$progdir\"; then
543334977a2fSmrg      $MKDIR \"\$progdir\"
543434977a2fSmrg    else
543534977a2fSmrg      $RM \"\$progdir/\$file\"
543634977a2fSmrg    fi"
543734977a2fSmrg
543834977a2fSmrg	  $ECHO "\
543934977a2fSmrg
544034977a2fSmrg    # relink executable if necessary
544134977a2fSmrg    if test -n \"\$relink_command\"; then
544234977a2fSmrg      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
544334977a2fSmrg      else
5444fe24f8a2Smrg	\$ECHO \"\$relink_command_output\" >&2
544534977a2fSmrg	$RM \"\$progdir/\$file\"
544634977a2fSmrg	exit 1
5447ee3138f1Smrg      fi
544834977a2fSmrg    fi
5449ee3138f1Smrg
545034977a2fSmrg    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
545134977a2fSmrg    { $RM \"\$progdir/\$program\";
545234977a2fSmrg      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
545334977a2fSmrg    $RM \"\$progdir/\$file\"
545434977a2fSmrg  fi"
545534977a2fSmrg	else
545634977a2fSmrg	  $ECHO "\
545734977a2fSmrg  program='$outputname'
545834977a2fSmrg  progdir=\"\$thisdir/$objdir\"
545934977a2fSmrg"
5460ee3138f1Smrg	fi
5461ee3138f1Smrg
546234977a2fSmrg	$ECHO "\
5463ee3138f1Smrg
546434977a2fSmrg  if test -f \"\$progdir/\$program\"; then"
5465ee3138f1Smrg
54663e72ca8cSmrg	# fixup the dll searchpath if we need to.
54673e72ca8cSmrg	#
54683e72ca8cSmrg	# Fix the DLL searchpath if we need to.  Do this before prepending
54693e72ca8cSmrg	# to shlibpath, because on Windows, both are PATH and uninstalled
54703e72ca8cSmrg	# libraries must come first.
54713e72ca8cSmrg	if test -n "$dllsearchpath"; then
54723e72ca8cSmrg	  $ECHO "\
54733e72ca8cSmrg    # Add the dll search path components to the executable PATH
54743e72ca8cSmrg    PATH=$dllsearchpath:\$PATH
54753e72ca8cSmrg"
54763e72ca8cSmrg	fi
54773e72ca8cSmrg
547834977a2fSmrg	# Export our shlibpath_var if we have one.
5479fe24f8a2Smrg	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
548034977a2fSmrg	  $ECHO "\
548134977a2fSmrg    # Add our own library path to $shlibpath_var
548234977a2fSmrg    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
5483ee3138f1Smrg
548434977a2fSmrg    # Some systems cannot cope with colon-terminated $shlibpath_var
548534977a2fSmrg    # The second colon is a workaround for a bug in BeOS R4 sed
5486b425557eSmrg    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
548734977a2fSmrg
548834977a2fSmrg    export $shlibpath_var
548934977a2fSmrg"
5490ee3138f1Smrg	fi
5491ee3138f1Smrg
549234977a2fSmrg	$ECHO "\
549334977a2fSmrg    if test \"\$libtool_execute_magic\" != \"$magic\"; then
549434977a2fSmrg      # Run the actual program with our arguments.
5495b425557eSmrg      func_exec_program \${1+\"\$@\"}
549634977a2fSmrg    fi
549734977a2fSmrg  else
549834977a2fSmrg    # The program doesn't exist.
5499fe24f8a2Smrg    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
550034977a2fSmrg    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
5501b425557eSmrg    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
550234977a2fSmrg    exit 1
550334977a2fSmrg  fi
550434977a2fSmrgfi\
550534977a2fSmrg"
550634977a2fSmrg}
5507ee3138f1Smrg
5508ee3138f1Smrg
550934977a2fSmrg# func_emit_cwrapperexe_src
551034977a2fSmrg# emit the source code for a wrapper executable on stdout
551134977a2fSmrg# Must ONLY be called from within func_mode_link because
551234977a2fSmrg# it depends on a number of variable set therein.
551334977a2fSmrgfunc_emit_cwrapperexe_src ()
551434977a2fSmrg{
551534977a2fSmrg	cat <<EOF
5516ee3138f1Smrg
551734977a2fSmrg/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5518fe24f8a2Smrg   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
5519ee3138f1Smrg
552034977a2fSmrg   The $output program cannot be directly executed until all the libtool
552134977a2fSmrg   libraries that it depends on are installed.
5522ee3138f1Smrg
552334977a2fSmrg   This wrapper executable should never be moved out of the build directory.
552434977a2fSmrg   If it is, it will not operate correctly.
552534977a2fSmrg*/
552634977a2fSmrgEOF
552734977a2fSmrg	    cat <<"EOF"
5528b425557eSmrg#ifdef _MSC_VER
5529b425557eSmrg# define _CRT_SECURE_NO_DEPRECATE 1
5530b425557eSmrg#endif
553134977a2fSmrg#include <stdio.h>
553234977a2fSmrg#include <stdlib.h>
553334977a2fSmrg#ifdef _MSC_VER
553434977a2fSmrg# include <direct.h>
553534977a2fSmrg# include <process.h>
553634977a2fSmrg# include <io.h>
553734977a2fSmrg#else
553834977a2fSmrg# include <unistd.h>
553934977a2fSmrg# include <stdint.h>
554034977a2fSmrg# ifdef __CYGWIN__
554134977a2fSmrg#  include <io.h>
554234977a2fSmrg# endif
554334977a2fSmrg#endif
554434977a2fSmrg#include <malloc.h>
554534977a2fSmrg#include <stdarg.h>
554634977a2fSmrg#include <assert.h>
554734977a2fSmrg#include <string.h>
554834977a2fSmrg#include <ctype.h>
554934977a2fSmrg#include <errno.h>
555034977a2fSmrg#include <fcntl.h>
555134977a2fSmrg#include <sys/stat.h>
5552ee3138f1Smrg
5553fe24f8a2Smrg#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5554fe24f8a2Smrg
5555b425557eSmrg/* declarations of non-ANSI functions */
5556fe24f8a2Smrg#if defined __MINGW32__
5557b425557eSmrg# ifdef __STRICT_ANSI__
5558b425557eSmrgint _putenv (const char *);
5559b425557eSmrg# endif
5560fe24f8a2Smrg#elif defined __CYGWIN__
5561b425557eSmrg# ifdef __STRICT_ANSI__
5562b425557eSmrgchar *realpath (const char *, char *);
5563b425557eSmrgint putenv (char *);
5564b425557eSmrgint setenv (const char *, const char *, int);
5565b425557eSmrg# endif
5566fe24f8a2Smrg/* #elif defined other_platform || defined ... */
5567b425557eSmrg#endif
5568b425557eSmrg
5569b425557eSmrg/* portability defines, excluding path handling macros */
5570fe24f8a2Smrg#if defined _MSC_VER
5571b425557eSmrg# define setmode _setmode
5572b425557eSmrg# define stat    _stat
5573b425557eSmrg# define chmod   _chmod
5574b425557eSmrg# define getcwd  _getcwd
5575b425557eSmrg# define putenv  _putenv
5576b425557eSmrg# define S_IXUSR _S_IEXEC
5577fe24f8a2Smrg#elif defined __MINGW32__
5578b425557eSmrg# define setmode _setmode
5579b425557eSmrg# define stat    _stat
5580b425557eSmrg# define chmod   _chmod
5581b425557eSmrg# define getcwd  _getcwd
5582b425557eSmrg# define putenv  _putenv
5583fe24f8a2Smrg#elif defined __CYGWIN__
5584b425557eSmrg# define HAVE_SETENV
5585b425557eSmrg# define FOPEN_WB "wb"
5586fe24f8a2Smrg/* #elif defined other platforms ... */
5587b425557eSmrg#endif
5588b425557eSmrg
5589fe24f8a2Smrg#if defined PATH_MAX
559034977a2fSmrg# define LT_PATHMAX PATH_MAX
5591fe24f8a2Smrg#elif defined MAXPATHLEN
559234977a2fSmrg# define LT_PATHMAX MAXPATHLEN
559334977a2fSmrg#else
559434977a2fSmrg# define LT_PATHMAX 1024
559534977a2fSmrg#endif
5596ee3138f1Smrg
559734977a2fSmrg#ifndef S_IXOTH
559834977a2fSmrg# define S_IXOTH 0
559934977a2fSmrg#endif
560034977a2fSmrg#ifndef S_IXGRP
560134977a2fSmrg# define S_IXGRP 0
560234977a2fSmrg#endif
5603ee3138f1Smrg
5604b425557eSmrg/* path handling portability macros */
560534977a2fSmrg#ifndef DIR_SEPARATOR
560634977a2fSmrg# define DIR_SEPARATOR '/'
560734977a2fSmrg# define PATH_SEPARATOR ':'
560834977a2fSmrg#endif
5609ee3138f1Smrg
5610fe24f8a2Smrg#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5611fe24f8a2Smrg  defined __OS2__
561234977a2fSmrg# define HAVE_DOS_BASED_FILE_SYSTEM
561334977a2fSmrg# define FOPEN_WB "wb"
561434977a2fSmrg# ifndef DIR_SEPARATOR_2
561534977a2fSmrg#  define DIR_SEPARATOR_2 '\\'
561634977a2fSmrg# endif
561734977a2fSmrg# ifndef PATH_SEPARATOR_2
561834977a2fSmrg#  define PATH_SEPARATOR_2 ';'
561934977a2fSmrg# endif
562034977a2fSmrg#endif
5621ee3138f1Smrg
562234977a2fSmrg#ifndef DIR_SEPARATOR_2
562334977a2fSmrg# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
562434977a2fSmrg#else /* DIR_SEPARATOR_2 */
562534977a2fSmrg# define IS_DIR_SEPARATOR(ch) \
562634977a2fSmrg	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
562734977a2fSmrg#endif /* DIR_SEPARATOR_2 */
5628ee3138f1Smrg
562934977a2fSmrg#ifndef PATH_SEPARATOR_2
563034977a2fSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
563134977a2fSmrg#else /* PATH_SEPARATOR_2 */
563234977a2fSmrg# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
563334977a2fSmrg#endif /* PATH_SEPARATOR_2 */
5634ee3138f1Smrg
563534977a2fSmrg#ifndef FOPEN_WB
563634977a2fSmrg# define FOPEN_WB "w"
563734977a2fSmrg#endif
563834977a2fSmrg#ifndef _O_BINARY
563934977a2fSmrg# define _O_BINARY 0
564034977a2fSmrg#endif
5641ee3138f1Smrg
564234977a2fSmrg#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
564334977a2fSmrg#define XFREE(stale) do { \
5644fe24f8a2Smrg  if (stale) { free (stale); stale = 0; } \
564534977a2fSmrg} while (0)
5646ee3138f1Smrg
5647fe24f8a2Smrg#if defined LT_DEBUGWRAPPER
5648b425557eSmrgstatic int lt_debug = 1;
564934977a2fSmrg#else
5650b425557eSmrgstatic int lt_debug = 0;
565134977a2fSmrg#endif
5652ee3138f1Smrg
5653b425557eSmrgconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
5654ee3138f1Smrg
565534977a2fSmrgvoid *xmalloc (size_t num);
565634977a2fSmrgchar *xstrdup (const char *string);
565734977a2fSmrgconst char *base_name (const char *name);
565834977a2fSmrgchar *find_executable (const char *wrapper);
565934977a2fSmrgchar *chase_symlinks (const char *pathspec);
566034977a2fSmrgint make_executable (const char *path);
566134977a2fSmrgint check_executable (const char *path);
566234977a2fSmrgchar *strendzap (char *str, const char *pat);
5663b425557eSmrgvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
5664b425557eSmrgvoid lt_fatal (const char *file, int line, const char *message, ...);
5665b425557eSmrgstatic const char *nonnull (const char *s);
5666b425557eSmrgstatic const char *nonempty (const char *s);
566734977a2fSmrgvoid lt_setenv (const char *name, const char *value);
566834977a2fSmrgchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
566934977a2fSmrgvoid lt_update_exe_path (const char *name, const char *value);
567034977a2fSmrgvoid lt_update_lib_path (const char *name, const char *value);
5671b425557eSmrgchar **prepare_spawn (char **argv);
5672b425557eSmrgvoid lt_dump_script (FILE *f);
567334977a2fSmrgEOF
567434977a2fSmrg
567534977a2fSmrg	    cat <<EOF
5676fe24f8a2Smrg#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5677fe24f8a2Smrg# define externally_visible volatile
5678fe24f8a2Smrg#else
5679fe24f8a2Smrg# define externally_visible __attribute__((externally_visible)) volatile
5680fe24f8a2Smrg#endif
5681fe24f8a2Smrgexternally_visible const char * MAGIC_EXE = "$magic_exe";
568234977a2fSmrgconst char * LIB_PATH_VARNAME = "$shlibpath_var";
568334977a2fSmrgEOF
5684ee3138f1Smrg
5685fe24f8a2Smrg	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
56863e72ca8cSmrg              func_to_host_path "$temp_rpath"
568734977a2fSmrg	      cat <<EOF
56883e72ca8cSmrgconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
568934977a2fSmrgEOF
569034977a2fSmrg	    else
569134977a2fSmrg	      cat <<"EOF"
569234977a2fSmrgconst char * LIB_PATH_VALUE   = "";
569334977a2fSmrgEOF
5694ee3138f1Smrg	    fi
5695ee3138f1Smrg
569634977a2fSmrg	    if test -n "$dllsearchpath"; then
56973e72ca8cSmrg              func_to_host_path "$dllsearchpath:"
569834977a2fSmrg	      cat <<EOF
569934977a2fSmrgconst char * EXE_PATH_VARNAME = "PATH";
57003e72ca8cSmrgconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
5701ee3138f1SmrgEOF
5702ee3138f1Smrg	    else
570334977a2fSmrg	      cat <<"EOF"
570434977a2fSmrgconst char * EXE_PATH_VARNAME = "";
570534977a2fSmrgconst char * EXE_PATH_VALUE   = "";
570634977a2fSmrgEOF
5707ee3138f1Smrg	    fi
570834977a2fSmrg
5709fe24f8a2Smrg	    if test yes = "$fast_install"; then
571034977a2fSmrg	      cat <<EOF
571134977a2fSmrgconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
571234977a2fSmrgEOF
5713ee3138f1Smrg	    else
571434977a2fSmrg	      cat <<EOF
571534977a2fSmrgconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
571634977a2fSmrgEOF
5717ee3138f1Smrg	    fi
5718ee3138f1Smrg
5719ee3138f1Smrg
572034977a2fSmrg	    cat <<"EOF"
5721ee3138f1Smrg
572234977a2fSmrg#define LTWRAPPER_OPTION_PREFIX         "--lt-"
5723ee3138f1Smrg
572434977a2fSmrgstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
572534977a2fSmrgstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
5726b425557eSmrgstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
5727ee3138f1Smrg
572834977a2fSmrgint
572934977a2fSmrgmain (int argc, char *argv[])
573034977a2fSmrg{
573134977a2fSmrg  char **newargz;
573234977a2fSmrg  int  newargc;
573334977a2fSmrg  char *tmp_pathspec;
573434977a2fSmrg  char *actual_cwrapper_path;
573534977a2fSmrg  char *actual_cwrapper_name;
573634977a2fSmrg  char *target_name;
573734977a2fSmrg  char *lt_argv_zero;
5738fe24f8a2Smrg  int rval = 127;
5739ee3138f1Smrg
574034977a2fSmrg  int i;
5741ee3138f1Smrg
574234977a2fSmrg  program_name = (char *) xstrdup (base_name (argv[0]));
5743fe24f8a2Smrg  newargz = XMALLOC (char *, (size_t) argc + 1);
5744ee3138f1Smrg
5745b425557eSmrg  /* very simple arg parsing; don't want to rely on getopt
5746b425557eSmrg   * also, copy all non cwrapper options to newargz, except
5747b425557eSmrg   * argz[0], which is handled differently
5748b425557eSmrg   */
5749b425557eSmrg  newargc=0;
575034977a2fSmrg  for (i = 1; i < argc; i++)
575134977a2fSmrg    {
5752fe24f8a2Smrg      if (STREQ (argv[i], dumpscript_opt))
575334977a2fSmrg	{
575434977a2fSmrgEOF
5755fe24f8a2Smrg	    case $host in
575634977a2fSmrg	      *mingw* | *cygwin* )
575734977a2fSmrg		# make stdout use "unix" line endings
575834977a2fSmrg		echo "          setmode(1,_O_BINARY);"
575934977a2fSmrg		;;
576034977a2fSmrg	      esac
5761ee3138f1Smrg
576234977a2fSmrg	    cat <<"EOF"
5763b425557eSmrg	  lt_dump_script (stdout);
576434977a2fSmrg	  return 0;
576534977a2fSmrg	}
5766fe24f8a2Smrg      if (STREQ (argv[i], debug_opt))
5767b425557eSmrg	{
5768b425557eSmrg          lt_debug = 1;
5769b425557eSmrg          continue;
5770b425557eSmrg	}
5771fe24f8a2Smrg      if (STREQ (argv[i], ltwrapper_option_prefix))
5772b425557eSmrg        {
5773b425557eSmrg          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
5774b425557eSmrg             namespace, but it is not one of the ones we know about and
5775b425557eSmrg             have already dealt with, above (inluding dump-script), then
5776b425557eSmrg             report an error. Otherwise, targets might begin to believe
5777b425557eSmrg             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
5778b425557eSmrg             namespace. The first time any user complains about this, we'll
5779b425557eSmrg             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
5780b425557eSmrg             or a configure.ac-settable value.
5781b425557eSmrg           */
5782b425557eSmrg          lt_fatal (__FILE__, __LINE__,
5783b425557eSmrg		    "unrecognized %s option: '%s'",
5784b425557eSmrg                    ltwrapper_option_prefix, argv[i]);
5785b425557eSmrg        }
5786b425557eSmrg      /* otherwise ... */
5787b425557eSmrg      newargz[++newargc] = xstrdup (argv[i]);
578834977a2fSmrg    }
5789b425557eSmrg  newargz[++newargc] = NULL;
5790b425557eSmrg
5791b425557eSmrgEOF
5792b425557eSmrg	    cat <<EOF
5793b425557eSmrg  /* The GNU banner must be the first non-error debug message */
5794fe24f8a2Smrg  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
5795b425557eSmrgEOF
5796b425557eSmrg	    cat <<"EOF"
5797b425557eSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
5798b425557eSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
5799ee3138f1Smrg
580034977a2fSmrg  tmp_pathspec = find_executable (argv[0]);
580134977a2fSmrg  if (tmp_pathspec == NULL)
5802b425557eSmrg    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
5803b425557eSmrg  lt_debugprintf (__FILE__, __LINE__,
5804b425557eSmrg                  "(main) found exe (before symlink chase) at: %s\n",
5805b425557eSmrg		  tmp_pathspec);
580634977a2fSmrg
580734977a2fSmrg  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
5808b425557eSmrg  lt_debugprintf (__FILE__, __LINE__,
5809b425557eSmrg                  "(main) found exe (after symlink chase) at: %s\n",
5810b425557eSmrg		  actual_cwrapper_path);
581134977a2fSmrg  XFREE (tmp_pathspec);
581234977a2fSmrg
5813b425557eSmrg  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
581434977a2fSmrg  strendzap (actual_cwrapper_path, actual_cwrapper_name);
581534977a2fSmrg
581634977a2fSmrg  /* wrapper name transforms */
581734977a2fSmrg  strendzap (actual_cwrapper_name, ".exe");
581834977a2fSmrg  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
581934977a2fSmrg  XFREE (actual_cwrapper_name);
582034977a2fSmrg  actual_cwrapper_name = tmp_pathspec;
582134977a2fSmrg  tmp_pathspec = 0;
582234977a2fSmrg
582334977a2fSmrg  /* target_name transforms -- use actual target program name; might have lt- prefix */
582434977a2fSmrg  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
582534977a2fSmrg  strendzap (target_name, ".exe");
582634977a2fSmrg  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
582734977a2fSmrg  XFREE (target_name);
582834977a2fSmrg  target_name = tmp_pathspec;
582934977a2fSmrg  tmp_pathspec = 0;
583034977a2fSmrg
5831b425557eSmrg  lt_debugprintf (__FILE__, __LINE__,
5832b425557eSmrg		  "(main) libtool target name: %s\n",
5833b425557eSmrg		  target_name);
583434977a2fSmrgEOF
5835ee3138f1Smrg
583634977a2fSmrg	    cat <<EOF
583734977a2fSmrg  newargz[0] =
583834977a2fSmrg    XMALLOC (char, (strlen (actual_cwrapper_path) +
583934977a2fSmrg		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
584034977a2fSmrg  strcpy (newargz[0], actual_cwrapper_path);
584134977a2fSmrg  strcat (newargz[0], "$objdir");
584234977a2fSmrg  strcat (newargz[0], "/");
584334977a2fSmrgEOF
5844ee3138f1Smrg
584534977a2fSmrg	    cat <<"EOF"
584634977a2fSmrg  /* stop here, and copy so we don't have to do this twice */
584734977a2fSmrg  tmp_pathspec = xstrdup (newargz[0]);
5848ee3138f1Smrg
584934977a2fSmrg  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
585034977a2fSmrg  strcat (newargz[0], actual_cwrapper_name);
5851ee3138f1Smrg
585234977a2fSmrg  /* DO want the lt- prefix here if it exists, so use target_name */
585334977a2fSmrg  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
585434977a2fSmrg  XFREE (tmp_pathspec);
585534977a2fSmrg  tmp_pathspec = NULL;
585634977a2fSmrgEOF
5857ee3138f1Smrg
585834977a2fSmrg	    case $host_os in
585934977a2fSmrg	      mingw*)
586034977a2fSmrg	    cat <<"EOF"
586134977a2fSmrg  {
586234977a2fSmrg    char* p;
586334977a2fSmrg    while ((p = strchr (newargz[0], '\\')) != NULL)
586434977a2fSmrg      {
586534977a2fSmrg	*p = '/';
586634977a2fSmrg      }
586734977a2fSmrg    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
586834977a2fSmrg      {
586934977a2fSmrg	*p = '/';
587034977a2fSmrg      }
587134977a2fSmrg  }
587234977a2fSmrgEOF
587334977a2fSmrg	    ;;
587434977a2fSmrg	    esac
5875ee3138f1Smrg
587634977a2fSmrg	    cat <<"EOF"
587734977a2fSmrg  XFREE (target_name);
587834977a2fSmrg  XFREE (actual_cwrapper_path);
587934977a2fSmrg  XFREE (actual_cwrapper_name);
5880ee3138f1Smrg
588134977a2fSmrg  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
588234977a2fSmrg  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
58833e72ca8cSmrg  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
58843e72ca8cSmrg     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
58853e72ca8cSmrg     because on Windows, both *_VARNAMEs are PATH but uninstalled
58863e72ca8cSmrg     libraries must come first. */
588734977a2fSmrg  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
58883e72ca8cSmrg  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
5889ee3138f1Smrg
5890b425557eSmrg  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
5891b425557eSmrg		  nonnull (lt_argv_zero));
589234977a2fSmrg  for (i = 0; i < newargc; i++)
589334977a2fSmrg    {
5894b425557eSmrg      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
5895b425557eSmrg		      i, nonnull (newargz[i]));
589634977a2fSmrg    }
5897ee3138f1Smrg
589834977a2fSmrgEOF
5899ee3138f1Smrg
590034977a2fSmrg	    case $host_os in
590134977a2fSmrg	      mingw*)
590234977a2fSmrg		cat <<"EOF"
590334977a2fSmrg  /* execv doesn't actually work on mingw as expected on unix */
5904b425557eSmrg  newargz = prepare_spawn (newargz);
5905fe24f8a2Smrg  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
590634977a2fSmrg  if (rval == -1)
590734977a2fSmrg    {
590834977a2fSmrg      /* failed to start process */
5909b425557eSmrg      lt_debugprintf (__FILE__, __LINE__,
5910b425557eSmrg		      "(main) failed to launch target \"%s\": %s\n",
5911b425557eSmrg		      lt_argv_zero, nonnull (strerror (errno)));
591234977a2fSmrg      return 127;
591334977a2fSmrg    }
591434977a2fSmrg  return rval;
591534977a2fSmrgEOF
591634977a2fSmrg		;;
591734977a2fSmrg	      *)
591834977a2fSmrg		cat <<"EOF"
591934977a2fSmrg  execv (lt_argv_zero, newargz);
592034977a2fSmrg  return rval; /* =127, but avoids unused variable warning */
592134977a2fSmrgEOF
592234977a2fSmrg		;;
592334977a2fSmrg	    esac
5924ee3138f1Smrg
592534977a2fSmrg	    cat <<"EOF"
592634977a2fSmrg}
5927ee3138f1Smrg
592834977a2fSmrgvoid *
592934977a2fSmrgxmalloc (size_t num)
593034977a2fSmrg{
593134977a2fSmrg  void *p = (void *) malloc (num);
593234977a2fSmrg  if (!p)
5933b425557eSmrg    lt_fatal (__FILE__, __LINE__, "memory exhausted");
5934ee3138f1Smrg
593534977a2fSmrg  return p;
593634977a2fSmrg}
5937ee3138f1Smrg
593834977a2fSmrgchar *
593934977a2fSmrgxstrdup (const char *string)
594034977a2fSmrg{
594134977a2fSmrg  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
594234977a2fSmrg			  string) : NULL;
594334977a2fSmrg}
5944ee3138f1Smrg
594534977a2fSmrgconst char *
594634977a2fSmrgbase_name (const char *name)
594734977a2fSmrg{
594834977a2fSmrg  const char *base;
5949ee3138f1Smrg
5950fe24f8a2Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
595134977a2fSmrg  /* Skip over the disk name in MSDOS pathnames. */
595234977a2fSmrg  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
595334977a2fSmrg    name += 2;
595434977a2fSmrg#endif
5955ee3138f1Smrg
595634977a2fSmrg  for (base = name; *name; name++)
595734977a2fSmrg    if (IS_DIR_SEPARATOR (*name))
595834977a2fSmrg      base = name + 1;
595934977a2fSmrg  return base;
596034977a2fSmrg}
5961ee3138f1Smrg
596234977a2fSmrgint
596334977a2fSmrgcheck_executable (const char *path)
596434977a2fSmrg{
596534977a2fSmrg  struct stat st;
5966ee3138f1Smrg
5967b425557eSmrg  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
5968b425557eSmrg                  nonempty (path));
596934977a2fSmrg  if ((!path) || (!*path))
597034977a2fSmrg    return 0;
5971ee3138f1Smrg
597234977a2fSmrg  if ((stat (path, &st) >= 0)
597334977a2fSmrg      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
597434977a2fSmrg    return 1;
597534977a2fSmrg  else
597634977a2fSmrg    return 0;
597734977a2fSmrg}
5978ee3138f1Smrg
597934977a2fSmrgint
598034977a2fSmrgmake_executable (const char *path)
598134977a2fSmrg{
598234977a2fSmrg  int rval = 0;
598334977a2fSmrg  struct stat st;
5984ee3138f1Smrg
5985b425557eSmrg  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
5986b425557eSmrg                  nonempty (path));
598734977a2fSmrg  if ((!path) || (!*path))
598834977a2fSmrg    return 0;
5989ee3138f1Smrg
599034977a2fSmrg  if (stat (path, &st) >= 0)
599134977a2fSmrg    {
599234977a2fSmrg      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
599334977a2fSmrg    }
599434977a2fSmrg  return rval;
599534977a2fSmrg}
5996ee3138f1Smrg
599734977a2fSmrg/* Searches for the full path of the wrapper.  Returns
599834977a2fSmrg   newly allocated full path name if found, NULL otherwise
599934977a2fSmrg   Does not chase symlinks, even on platforms that support them.
600034977a2fSmrg*/
600134977a2fSmrgchar *
600234977a2fSmrgfind_executable (const char *wrapper)
600334977a2fSmrg{
600434977a2fSmrg  int has_slash = 0;
600534977a2fSmrg  const char *p;
600634977a2fSmrg  const char *p_next;
600734977a2fSmrg  /* static buffer for getcwd */
600834977a2fSmrg  char tmp[LT_PATHMAX + 1];
6009fe24f8a2Smrg  size_t tmp_len;
601034977a2fSmrg  char *concat_name;
6011ee3138f1Smrg
6012b425557eSmrg  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
6013b425557eSmrg                  nonempty (wrapper));
6014ee3138f1Smrg
601534977a2fSmrg  if ((wrapper == NULL) || (*wrapper == '\0'))
601634977a2fSmrg    return NULL;
6017ee3138f1Smrg
601834977a2fSmrg  /* Absolute path? */
6019fe24f8a2Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
602034977a2fSmrg  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
602134977a2fSmrg    {
602234977a2fSmrg      concat_name = xstrdup (wrapper);
602334977a2fSmrg      if (check_executable (concat_name))
602434977a2fSmrg	return concat_name;
602534977a2fSmrg      XFREE (concat_name);
602634977a2fSmrg    }
602734977a2fSmrg  else
602834977a2fSmrg    {
602934977a2fSmrg#endif
603034977a2fSmrg      if (IS_DIR_SEPARATOR (wrapper[0]))
603134977a2fSmrg	{
603234977a2fSmrg	  concat_name = xstrdup (wrapper);
603334977a2fSmrg	  if (check_executable (concat_name))
603434977a2fSmrg	    return concat_name;
603534977a2fSmrg	  XFREE (concat_name);
603634977a2fSmrg	}
6037fe24f8a2Smrg#if defined HAVE_DOS_BASED_FILE_SYSTEM
603834977a2fSmrg    }
603934977a2fSmrg#endif
6040ee3138f1Smrg
604134977a2fSmrg  for (p = wrapper; *p; p++)
604234977a2fSmrg    if (*p == '/')
604334977a2fSmrg      {
604434977a2fSmrg	has_slash = 1;
604534977a2fSmrg	break;
604634977a2fSmrg      }
604734977a2fSmrg  if (!has_slash)
604834977a2fSmrg    {
604934977a2fSmrg      /* no slashes; search PATH */
605034977a2fSmrg      const char *path = getenv ("PATH");
605134977a2fSmrg      if (path != NULL)
605234977a2fSmrg	{
605334977a2fSmrg	  for (p = path; *p; p = p_next)
605434977a2fSmrg	    {
605534977a2fSmrg	      const char *q;
605634977a2fSmrg	      size_t p_len;
605734977a2fSmrg	      for (q = p; *q; q++)
605834977a2fSmrg		if (IS_PATH_SEPARATOR (*q))
605934977a2fSmrg		  break;
6060fe24f8a2Smrg	      p_len = (size_t) (q - p);
606134977a2fSmrg	      p_next = (*q == '\0' ? q : q + 1);
606234977a2fSmrg	      if (p_len == 0)
606334977a2fSmrg		{
606434977a2fSmrg		  /* empty path: current directory */
606534977a2fSmrg		  if (getcwd (tmp, LT_PATHMAX) == NULL)
6066b425557eSmrg		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6067b425557eSmrg                              nonnull (strerror (errno)));
606834977a2fSmrg		  tmp_len = strlen (tmp);
606934977a2fSmrg		  concat_name =
607034977a2fSmrg		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
607134977a2fSmrg		  memcpy (concat_name, tmp, tmp_len);
607234977a2fSmrg		  concat_name[tmp_len] = '/';
607334977a2fSmrg		  strcpy (concat_name + tmp_len + 1, wrapper);
607434977a2fSmrg		}
607534977a2fSmrg	      else
607634977a2fSmrg		{
607734977a2fSmrg		  concat_name =
607834977a2fSmrg		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
607934977a2fSmrg		  memcpy (concat_name, p, p_len);
608034977a2fSmrg		  concat_name[p_len] = '/';
608134977a2fSmrg		  strcpy (concat_name + p_len + 1, wrapper);
608234977a2fSmrg		}
608334977a2fSmrg	      if (check_executable (concat_name))
608434977a2fSmrg		return concat_name;
608534977a2fSmrg	      XFREE (concat_name);
608634977a2fSmrg	    }
608734977a2fSmrg	}
608834977a2fSmrg      /* not found in PATH; assume curdir */
608934977a2fSmrg    }
609034977a2fSmrg  /* Relative path | not found in path: prepend cwd */
609134977a2fSmrg  if (getcwd (tmp, LT_PATHMAX) == NULL)
6092b425557eSmrg    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
6093b425557eSmrg              nonnull (strerror (errno)));
609434977a2fSmrg  tmp_len = strlen (tmp);
609534977a2fSmrg  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
609634977a2fSmrg  memcpy (concat_name, tmp, tmp_len);
609734977a2fSmrg  concat_name[tmp_len] = '/';
609834977a2fSmrg  strcpy (concat_name + tmp_len + 1, wrapper);
6099ee3138f1Smrg
610034977a2fSmrg  if (check_executable (concat_name))
610134977a2fSmrg    return concat_name;
610234977a2fSmrg  XFREE (concat_name);
610334977a2fSmrg  return NULL;
610434977a2fSmrg}
6105ee3138f1Smrg
610634977a2fSmrgchar *
610734977a2fSmrgchase_symlinks (const char *pathspec)
610834977a2fSmrg{
610934977a2fSmrg#ifndef S_ISLNK
611034977a2fSmrg  return xstrdup (pathspec);
611134977a2fSmrg#else
611234977a2fSmrg  char buf[LT_PATHMAX];
611334977a2fSmrg  struct stat s;
611434977a2fSmrg  char *tmp_pathspec = xstrdup (pathspec);
611534977a2fSmrg  char *p;
611634977a2fSmrg  int has_symlinks = 0;
611734977a2fSmrg  while (strlen (tmp_pathspec) && !has_symlinks)
611834977a2fSmrg    {
6119b425557eSmrg      lt_debugprintf (__FILE__, __LINE__,
6120b425557eSmrg		      "checking path component for symlinks: %s\n",
6121b425557eSmrg		      tmp_pathspec);
612234977a2fSmrg      if (lstat (tmp_pathspec, &s) == 0)
612334977a2fSmrg	{
612434977a2fSmrg	  if (S_ISLNK (s.st_mode) != 0)
612534977a2fSmrg	    {
612634977a2fSmrg	      has_symlinks = 1;
612734977a2fSmrg	      break;
612834977a2fSmrg	    }
6129ee3138f1Smrg
613034977a2fSmrg	  /* search backwards for last DIR_SEPARATOR */
613134977a2fSmrg	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
613234977a2fSmrg	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
613334977a2fSmrg	    p--;
613434977a2fSmrg	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
613534977a2fSmrg	    {
613634977a2fSmrg	      /* no more DIR_SEPARATORS left */
613734977a2fSmrg	      break;
613834977a2fSmrg	    }
613934977a2fSmrg	  *p = '\0';
614034977a2fSmrg	}
614134977a2fSmrg      else
614234977a2fSmrg	{
6143b425557eSmrg	  lt_fatal (__FILE__, __LINE__,
6144b425557eSmrg		    "error accessing file \"%s\": %s",
6145b425557eSmrg		    tmp_pathspec, nonnull (strerror (errno)));
614634977a2fSmrg	}
614734977a2fSmrg    }
614834977a2fSmrg  XFREE (tmp_pathspec);
6149ee3138f1Smrg
615034977a2fSmrg  if (!has_symlinks)
615134977a2fSmrg    {
615234977a2fSmrg      return xstrdup (pathspec);
615334977a2fSmrg    }
6154ee3138f1Smrg
615534977a2fSmrg  tmp_pathspec = realpath (pathspec, buf);
615634977a2fSmrg  if (tmp_pathspec == 0)
615734977a2fSmrg    {
6158b425557eSmrg      lt_fatal (__FILE__, __LINE__,
6159b425557eSmrg		"could not follow symlinks for %s", pathspec);
616034977a2fSmrg    }
616134977a2fSmrg  return xstrdup (tmp_pathspec);
616234977a2fSmrg#endif
616334977a2fSmrg}
6164ee3138f1Smrg
616534977a2fSmrgchar *
616634977a2fSmrgstrendzap (char *str, const char *pat)
616734977a2fSmrg{
616834977a2fSmrg  size_t len, patlen;
6169ee3138f1Smrg
617034977a2fSmrg  assert (str != NULL);
617134977a2fSmrg  assert (pat != NULL);
6172ee3138f1Smrg
617334977a2fSmrg  len = strlen (str);
617434977a2fSmrg  patlen = strlen (pat);
6175ee3138f1Smrg
617634977a2fSmrg  if (patlen <= len)
617734977a2fSmrg    {
617834977a2fSmrg      str += len - patlen;
6179fe24f8a2Smrg      if (STREQ (str, pat))
618034977a2fSmrg	*str = '\0';
618134977a2fSmrg    }
618234977a2fSmrg  return str;
618334977a2fSmrg}
6184ee3138f1Smrg
6185b425557eSmrgvoid
6186b425557eSmrglt_debugprintf (const char *file, int line, const char *fmt, ...)
6187b425557eSmrg{
6188b425557eSmrg  va_list args;
6189b425557eSmrg  if (lt_debug)
6190b425557eSmrg    {
6191b425557eSmrg      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
6192b425557eSmrg      va_start (args, fmt);
6193b425557eSmrg      (void) vfprintf (stderr, fmt, args);
6194b425557eSmrg      va_end (args);
6195b425557eSmrg    }
6196b425557eSmrg}
6197b425557eSmrg
619834977a2fSmrgstatic void
6199b425557eSmrglt_error_core (int exit_status, const char *file,
6200b425557eSmrg	       int line, const char *mode,
620134977a2fSmrg	       const char *message, va_list ap)
620234977a2fSmrg{
6203b425557eSmrg  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
620434977a2fSmrg  vfprintf (stderr, message, ap);
620534977a2fSmrg  fprintf (stderr, ".\n");
6206ee3138f1Smrg
620734977a2fSmrg  if (exit_status >= 0)
620834977a2fSmrg    exit (exit_status);
620934977a2fSmrg}
6210ee3138f1Smrg
621134977a2fSmrgvoid
6212b425557eSmrglt_fatal (const char *file, int line, const char *message, ...)
621334977a2fSmrg{
621434977a2fSmrg  va_list ap;
621534977a2fSmrg  va_start (ap, message);
6216b425557eSmrg  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
621734977a2fSmrg  va_end (ap);
621834977a2fSmrg}
6219ee3138f1Smrg
6220b425557eSmrgstatic const char *
6221b425557eSmrgnonnull (const char *s)
6222b425557eSmrg{
6223b425557eSmrg  return s ? s : "(null)";
6224b425557eSmrg}
6225b425557eSmrg
6226b425557eSmrgstatic const char *
6227b425557eSmrgnonempty (const char *s)
6228b425557eSmrg{
6229b425557eSmrg  return (s && !*s) ? "(empty)" : nonnull (s);
6230b425557eSmrg}
6231b425557eSmrg
623234977a2fSmrgvoid
623334977a2fSmrglt_setenv (const char *name, const char *value)
623434977a2fSmrg{
6235b425557eSmrg  lt_debugprintf (__FILE__, __LINE__,
6236b425557eSmrg		  "(lt_setenv) setting '%s' to '%s'\n",
6237b425557eSmrg                  nonnull (name), nonnull (value));
623834977a2fSmrg  {
623934977a2fSmrg#ifdef HAVE_SETENV
624034977a2fSmrg    /* always make a copy, for consistency with !HAVE_SETENV */
624134977a2fSmrg    char *str = xstrdup (value);
624234977a2fSmrg    setenv (name, str, 1);
624334977a2fSmrg#else
6244fe24f8a2Smrg    size_t len = strlen (name) + 1 + strlen (value) + 1;
624534977a2fSmrg    char *str = XMALLOC (char, len);
624634977a2fSmrg    sprintf (str, "%s=%s", name, value);
624734977a2fSmrg    if (putenv (str) != EXIT_SUCCESS)
624834977a2fSmrg      {
624934977a2fSmrg        XFREE (str);
625034977a2fSmrg      }
625134977a2fSmrg#endif
625234977a2fSmrg  }
625334977a2fSmrg}
6254ee3138f1Smrg
625534977a2fSmrgchar *
625634977a2fSmrglt_extend_str (const char *orig_value, const char *add, int to_end)
625734977a2fSmrg{
625834977a2fSmrg  char *new_value;
625934977a2fSmrg  if (orig_value && *orig_value)
626034977a2fSmrg    {
6261fe24f8a2Smrg      size_t orig_value_len = strlen (orig_value);
6262fe24f8a2Smrg      size_t add_len = strlen (add);
626334977a2fSmrg      new_value = XMALLOC (char, add_len + orig_value_len + 1);
626434977a2fSmrg      if (to_end)
626534977a2fSmrg        {
626634977a2fSmrg          strcpy (new_value, orig_value);
626734977a2fSmrg          strcpy (new_value + orig_value_len, add);
626834977a2fSmrg        }
626934977a2fSmrg      else
627034977a2fSmrg        {
627134977a2fSmrg          strcpy (new_value, add);
627234977a2fSmrg          strcpy (new_value + add_len, orig_value);
627334977a2fSmrg        }
627434977a2fSmrg    }
627534977a2fSmrg  else
627634977a2fSmrg    {
627734977a2fSmrg      new_value = xstrdup (add);
627834977a2fSmrg    }
627934977a2fSmrg  return new_value;
628034977a2fSmrg}
6281ee3138f1Smrg
628234977a2fSmrgvoid
628334977a2fSmrglt_update_exe_path (const char *name, const char *value)
628434977a2fSmrg{
6285b425557eSmrg  lt_debugprintf (__FILE__, __LINE__,
6286b425557eSmrg		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
6287b425557eSmrg                  nonnull (name), nonnull (value));
6288ee3138f1Smrg
628934977a2fSmrg  if (name && *name && value && *value)
629034977a2fSmrg    {
629134977a2fSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
629234977a2fSmrg      /* some systems can't cope with a ':'-terminated path #' */
6293fe24f8a2Smrg      size_t len = strlen (new_value);
6294fe24f8a2Smrg      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
629534977a2fSmrg        {
6296fe24f8a2Smrg          new_value[--len] = '\0';
629734977a2fSmrg        }
629834977a2fSmrg      lt_setenv (name, new_value);
629934977a2fSmrg      XFREE (new_value);
630034977a2fSmrg    }
630134977a2fSmrg}
6302ee3138f1Smrg
630334977a2fSmrgvoid
630434977a2fSmrglt_update_lib_path (const char *name, const char *value)
630534977a2fSmrg{
6306b425557eSmrg  lt_debugprintf (__FILE__, __LINE__,
6307b425557eSmrg		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
6308b425557eSmrg                  nonnull (name), nonnull (value));
6309ee3138f1Smrg
631034977a2fSmrg  if (name && *name && value && *value)
631134977a2fSmrg    {
631234977a2fSmrg      char *new_value = lt_extend_str (getenv (name), value, 0);
631334977a2fSmrg      lt_setenv (name, new_value);
631434977a2fSmrg      XFREE (new_value);
631534977a2fSmrg    }
631634977a2fSmrg}
6317ee3138f1Smrg
6318b425557eSmrgEOF
6319b425557eSmrg	    case $host_os in
6320b425557eSmrg	      mingw*)
6321b425557eSmrg		cat <<"EOF"
6322b425557eSmrg
6323b425557eSmrg/* Prepares an argument vector before calling spawn().
6324b425557eSmrg   Note that spawn() does not by itself call the command interpreter
6325b425557eSmrg     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
6326b425557eSmrg      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
6327b425557eSmrg         GetVersionEx(&v);
6328b425557eSmrg         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
6329b425557eSmrg      }) ? "cmd.exe" : "command.com").
6330b425557eSmrg   Instead it simply concatenates the arguments, separated by ' ', and calls
6331b425557eSmrg   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
6332b425557eSmrg   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
6333b425557eSmrg   special way:
6334b425557eSmrg   - Space and tab are interpreted as delimiters. They are not treated as
6335b425557eSmrg     delimiters if they are surrounded by double quotes: "...".
6336b425557eSmrg   - Unescaped double quotes are removed from the input. Their only effect is
6337b425557eSmrg     that within double quotes, space and tab are treated like normal
6338b425557eSmrg     characters.
6339b425557eSmrg   - Backslashes not followed by double quotes are not special.
6340b425557eSmrg   - But 2*n+1 backslashes followed by a double quote become
6341b425557eSmrg     n backslashes followed by a double quote (n >= 0):
6342b425557eSmrg       \" -> "
6343b425557eSmrg       \\\" -> \"
6344b425557eSmrg       \\\\\" -> \\"
6345b425557eSmrg */
6346b425557eSmrg#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"
6347b425557eSmrg#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"
6348b425557eSmrgchar **
6349b425557eSmrgprepare_spawn (char **argv)
6350b425557eSmrg{
6351b425557eSmrg  size_t argc;
6352b425557eSmrg  char **new_argv;
6353b425557eSmrg  size_t i;
6354b425557eSmrg
6355b425557eSmrg  /* Count number of arguments.  */
6356b425557eSmrg  for (argc = 0; argv[argc] != NULL; argc++)
6357b425557eSmrg    ;
6358b425557eSmrg
6359b425557eSmrg  /* Allocate new argument vector.  */
6360b425557eSmrg  new_argv = XMALLOC (char *, argc + 1);
6361b425557eSmrg
6362b425557eSmrg  /* Put quoted arguments into the new argument vector.  */
6363b425557eSmrg  for (i = 0; i < argc; i++)
6364b425557eSmrg    {
6365b425557eSmrg      const char *string = argv[i];
6366b425557eSmrg
6367b425557eSmrg      if (string[0] == '\0')
6368b425557eSmrg	new_argv[i] = xstrdup ("\"\"");
6369b425557eSmrg      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
6370b425557eSmrg	{
6371b425557eSmrg	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
6372b425557eSmrg	  size_t length;
6373b425557eSmrg	  unsigned int backslashes;
6374b425557eSmrg	  const char *s;
6375b425557eSmrg	  char *quoted_string;
6376b425557eSmrg	  char *p;
6377b425557eSmrg
6378b425557eSmrg	  length = 0;
6379b425557eSmrg	  backslashes = 0;
6380b425557eSmrg	  if (quote_around)
6381b425557eSmrg	    length++;
6382b425557eSmrg	  for (s = string; *s != '\0'; s++)
6383b425557eSmrg	    {
6384b425557eSmrg	      char c = *s;
6385b425557eSmrg	      if (c == '"')
6386b425557eSmrg		length += backslashes + 1;
6387b425557eSmrg	      length++;
6388b425557eSmrg	      if (c == '\\')
6389b425557eSmrg		backslashes++;
6390b425557eSmrg	      else
6391b425557eSmrg		backslashes = 0;
6392b425557eSmrg	    }
6393b425557eSmrg	  if (quote_around)
6394b425557eSmrg	    length += backslashes + 1;
6395b425557eSmrg
6396b425557eSmrg	  quoted_string = XMALLOC (char, length + 1);
6397b425557eSmrg
6398b425557eSmrg	  p = quoted_string;
6399b425557eSmrg	  backslashes = 0;
6400b425557eSmrg	  if (quote_around)
6401b425557eSmrg	    *p++ = '"';
6402b425557eSmrg	  for (s = string; *s != '\0'; s++)
6403b425557eSmrg	    {
6404b425557eSmrg	      char c = *s;
6405b425557eSmrg	      if (c == '"')
6406b425557eSmrg		{
6407b425557eSmrg		  unsigned int j;
6408b425557eSmrg		  for (j = backslashes + 1; j > 0; j--)
6409b425557eSmrg		    *p++ = '\\';
6410b425557eSmrg		}
6411b425557eSmrg	      *p++ = c;
6412b425557eSmrg	      if (c == '\\')
6413b425557eSmrg		backslashes++;
6414b425557eSmrg	      else
6415b425557eSmrg		backslashes = 0;
6416b425557eSmrg	    }
6417b425557eSmrg	  if (quote_around)
6418b425557eSmrg	    {
6419b425557eSmrg	      unsigned int j;
6420b425557eSmrg	      for (j = backslashes; j > 0; j--)
6421b425557eSmrg		*p++ = '\\';
6422b425557eSmrg	      *p++ = '"';
6423b425557eSmrg	    }
6424b425557eSmrg	  *p = '\0';
6425b425557eSmrg
6426b425557eSmrg	  new_argv[i] = quoted_string;
6427b425557eSmrg	}
6428b425557eSmrg      else
6429b425557eSmrg	new_argv[i] = (char *) string;
6430b425557eSmrg    }
6431b425557eSmrg  new_argv[argc] = NULL;
6432b425557eSmrg
6433b425557eSmrg  return new_argv;
6434b425557eSmrg}
6435b425557eSmrgEOF
6436b425557eSmrg		;;
6437b425557eSmrg	    esac
6438b425557eSmrg
6439b425557eSmrg            cat <<"EOF"
6440b425557eSmrgvoid lt_dump_script (FILE* f)
6441b425557eSmrg{
6442b425557eSmrgEOF
6443b425557eSmrg	    func_emit_wrapper yes |
64443e72ca8cSmrg	      $SED -n -e '
64453e72ca8cSmrgs/^\(.\{79\}\)\(..*\)/\1\
64463e72ca8cSmrg\2/
64473e72ca8cSmrgh
64483e72ca8cSmrgs/\([\\"]\)/\\\1/g
64493e72ca8cSmrgs/$/\\n/
64503e72ca8cSmrgs/\([^\n]*\).*/  fputs ("\1", f);/p
64513e72ca8cSmrgg
64523e72ca8cSmrgD'
6453b425557eSmrg            cat <<"EOF"
6454b425557eSmrg}
645534977a2fSmrgEOF
645634977a2fSmrg}
645734977a2fSmrg# end: func_emit_cwrapperexe_src
6458ee3138f1Smrg
6459b425557eSmrg# func_win32_import_lib_p ARG
6460b425557eSmrg# True if ARG is an import lib, as indicated by $file_magic_cmd
6461b425557eSmrgfunc_win32_import_lib_p ()
6462b425557eSmrg{
6463fe24f8a2Smrg    $debug_cmd
6464fe24f8a2Smrg
6465b425557eSmrg    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
6466b425557eSmrg    *import*) : ;;
6467b425557eSmrg    *) false ;;
6468b425557eSmrg    esac
6469b425557eSmrg}
6470b425557eSmrg
6471fe24f8a2Smrg# func_suncc_cstd_abi
6472fe24f8a2Smrg# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6473fe24f8a2Smrg# Several compiler flags select an ABI that is incompatible with the
6474fe24f8a2Smrg# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6475fe24f8a2Smrgfunc_suncc_cstd_abi ()
6476fe24f8a2Smrg{
6477fe24f8a2Smrg    $debug_cmd
6478fe24f8a2Smrg
6479fe24f8a2Smrg    case " $compile_command " in
6480fe24f8a2Smrg    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6481fe24f8a2Smrg      suncc_use_cstd_abi=no
6482fe24f8a2Smrg      ;;
6483fe24f8a2Smrg    *)
6484fe24f8a2Smrg      suncc_use_cstd_abi=yes
6485fe24f8a2Smrg      ;;
6486fe24f8a2Smrg    esac
6487fe24f8a2Smrg}
6488fe24f8a2Smrg
648934977a2fSmrg# func_mode_link arg...
649034977a2fSmrgfunc_mode_link ()
649134977a2fSmrg{
6492fe24f8a2Smrg    $debug_cmd
6493fe24f8a2Smrg
649434977a2fSmrg    case $host in
649534977a2fSmrg    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
649634977a2fSmrg      # It is impossible to link a dll without this setting, and
649734977a2fSmrg      # we shouldn't force the makefile maintainer to figure out
6498fe24f8a2Smrg      # what system we are compiling for in order to pass an extra
649934977a2fSmrg      # flag for every libtool invocation.
650034977a2fSmrg      # allow_undefined=no
6501ee3138f1Smrg
650234977a2fSmrg      # FIXME: Unfortunately, there are problems with the above when trying
6503fe24f8a2Smrg      # to make a dll that has undefined symbols, in which case not
650434977a2fSmrg      # even a static library is built.  For now, we need to specify
650534977a2fSmrg      # -no-undefined on the libtool link line when we can be certain
650634977a2fSmrg      # that all symbols are satisfied, otherwise we get a static library.
650734977a2fSmrg      allow_undefined=yes
650834977a2fSmrg      ;;
650934977a2fSmrg    *)
651034977a2fSmrg      allow_undefined=yes
651134977a2fSmrg      ;;
651234977a2fSmrg    esac
651334977a2fSmrg    libtool_args=$nonopt
651434977a2fSmrg    base_compile="$nonopt $@"
651534977a2fSmrg    compile_command=$nonopt
651634977a2fSmrg    finalize_command=$nonopt
6517ee3138f1Smrg
651834977a2fSmrg    compile_rpath=
651934977a2fSmrg    finalize_rpath=
652034977a2fSmrg    compile_shlibpath=
652134977a2fSmrg    finalize_shlibpath=
652234977a2fSmrg    convenience=
652334977a2fSmrg    old_convenience=
652434977a2fSmrg    deplibs=
652534977a2fSmrg    old_deplibs=
652634977a2fSmrg    compiler_flags=
652734977a2fSmrg    linker_flags=
652834977a2fSmrg    dllsearchpath=
652934977a2fSmrg    lib_search_path=`pwd`
653034977a2fSmrg    inst_prefix_dir=
653134977a2fSmrg    new_inherited_linker_flags=
6532ee3138f1Smrg
653334977a2fSmrg    avoid_version=no
6534b425557eSmrg    bindir=
653534977a2fSmrg    dlfiles=
653634977a2fSmrg    dlprefiles=
653734977a2fSmrg    dlself=no
653834977a2fSmrg    export_dynamic=no
653934977a2fSmrg    export_symbols=
654034977a2fSmrg    export_symbols_regex=
654134977a2fSmrg    generated=
654234977a2fSmrg    libobjs=
654334977a2fSmrg    ltlibs=
654434977a2fSmrg    module=no
654534977a2fSmrg    no_install=no
654634977a2fSmrg    objs=
6547fe24f8a2Smrg    os2dllname=
654834977a2fSmrg    non_pic_objects=
654934977a2fSmrg    precious_files_regex=
655034977a2fSmrg    prefer_static_libs=no
6551fe24f8a2Smrg    preload=false
655234977a2fSmrg    prev=
655334977a2fSmrg    prevarg=
655434977a2fSmrg    release=
655534977a2fSmrg    rpath=
655634977a2fSmrg    xrpath=
655734977a2fSmrg    perm_rpath=
655834977a2fSmrg    temp_rpath=
655934977a2fSmrg    thread_safe=no
656034977a2fSmrg    vinfo=
656134977a2fSmrg    vinfo_number=no
656234977a2fSmrg    weak_libs=
6563fe24f8a2Smrg    single_module=$wl-single_module
656434977a2fSmrg    func_infer_tag $base_compile
6565ee3138f1Smrg
656634977a2fSmrg    # We need to know -static, to get the right output filenames.
656734977a2fSmrg    for arg
656834977a2fSmrg    do
656934977a2fSmrg      case $arg in
657034977a2fSmrg      -shared)
6571fe24f8a2Smrg	test yes != "$build_libtool_libs" \
6572fe24f8a2Smrg	  && func_fatal_configuration "cannot build a shared library"
657334977a2fSmrg	build_old_libs=no
657434977a2fSmrg	break
657534977a2fSmrg	;;
657634977a2fSmrg      -all-static | -static | -static-libtool-libs)
657734977a2fSmrg	case $arg in
657834977a2fSmrg	-all-static)
6579fe24f8a2Smrg	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
658034977a2fSmrg	    func_warning "complete static linking is impossible in this configuration"
658134977a2fSmrg	  fi
658234977a2fSmrg	  if test -n "$link_static_flag"; then
658334977a2fSmrg	    dlopen_self=$dlopen_self_static
658434977a2fSmrg	  fi
658534977a2fSmrg	  prefer_static_libs=yes
658634977a2fSmrg	  ;;
658734977a2fSmrg	-static)
658834977a2fSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
658934977a2fSmrg	    dlopen_self=$dlopen_self_static
659034977a2fSmrg	  fi
659134977a2fSmrg	  prefer_static_libs=built
659234977a2fSmrg	  ;;
659334977a2fSmrg	-static-libtool-libs)
659434977a2fSmrg	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
659534977a2fSmrg	    dlopen_self=$dlopen_self_static
659634977a2fSmrg	  fi
659734977a2fSmrg	  prefer_static_libs=yes
659834977a2fSmrg	  ;;
659934977a2fSmrg	esac
660034977a2fSmrg	build_libtool_libs=no
660134977a2fSmrg	build_old_libs=yes
660234977a2fSmrg	break
660334977a2fSmrg	;;
660434977a2fSmrg      esac
660534977a2fSmrg    done
6606ee3138f1Smrg
660734977a2fSmrg    # See if our shared archives depend on static archives.
660834977a2fSmrg    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
6609ee3138f1Smrg
661034977a2fSmrg    # Go through the arguments, transforming them on the way.
661134977a2fSmrg    while test "$#" -gt 0; do
6612fe24f8a2Smrg      arg=$1
661334977a2fSmrg      shift
661434977a2fSmrg      func_quote_for_eval "$arg"
661534977a2fSmrg      qarg=$func_quote_for_eval_unquoted_result
661634977a2fSmrg      func_append libtool_args " $func_quote_for_eval_result"
6617ee3138f1Smrg
661834977a2fSmrg      # If the previous option needs an argument, assign it.
661934977a2fSmrg      if test -n "$prev"; then
662034977a2fSmrg	case $prev in
662134977a2fSmrg	output)
662234977a2fSmrg	  func_append compile_command " @OUTPUT@"
662334977a2fSmrg	  func_append finalize_command " @OUTPUT@"
662434977a2fSmrg	  ;;
662534977a2fSmrg	esac
6626ee3138f1Smrg
662734977a2fSmrg	case $prev in
6628b425557eSmrg	bindir)
6629fe24f8a2Smrg	  bindir=$arg
6630b425557eSmrg	  prev=
6631b425557eSmrg	  continue
6632b425557eSmrg	  ;;
663334977a2fSmrg	dlfiles|dlprefiles)
6634fe24f8a2Smrg	  $preload || {
663534977a2fSmrg	    # Add the symbol object into the linking commands.
663634977a2fSmrg	    func_append compile_command " @SYMFILE@"
663734977a2fSmrg	    func_append finalize_command " @SYMFILE@"
6638fe24f8a2Smrg	    preload=:
6639fe24f8a2Smrg	  }
664034977a2fSmrg	  case $arg in
664134977a2fSmrg	  *.la | *.lo) ;;  # We handle these cases below.
664234977a2fSmrg	  force)
6643fe24f8a2Smrg	    if test no = "$dlself"; then
664434977a2fSmrg	      dlself=needless
664534977a2fSmrg	      export_dynamic=yes
664634977a2fSmrg	    fi
664734977a2fSmrg	    prev=
664834977a2fSmrg	    continue
664934977a2fSmrg	    ;;
665034977a2fSmrg	  self)
6651fe24f8a2Smrg	    if test dlprefiles = "$prev"; then
665234977a2fSmrg	      dlself=yes
6653fe24f8a2Smrg	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
665434977a2fSmrg	      dlself=yes
665534977a2fSmrg	    else
665634977a2fSmrg	      dlself=needless
665734977a2fSmrg	      export_dynamic=yes
665834977a2fSmrg	    fi
665934977a2fSmrg	    prev=
666034977a2fSmrg	    continue
666134977a2fSmrg	    ;;
666234977a2fSmrg	  *)
6663fe24f8a2Smrg	    if test dlfiles = "$prev"; then
66643e72ca8cSmrg	      func_append dlfiles " $arg"
666534977a2fSmrg	    else
66663e72ca8cSmrg	      func_append dlprefiles " $arg"
666734977a2fSmrg	    fi
666834977a2fSmrg	    prev=
666934977a2fSmrg	    continue
667034977a2fSmrg	    ;;
667134977a2fSmrg	  esac
667234977a2fSmrg	  ;;
667334977a2fSmrg	expsyms)
6674fe24f8a2Smrg	  export_symbols=$arg
667534977a2fSmrg	  test -f "$arg" \
6676fe24f8a2Smrg	    || func_fatal_error "symbol file '$arg' does not exist"
667734977a2fSmrg	  prev=
667834977a2fSmrg	  continue
667934977a2fSmrg	  ;;
668034977a2fSmrg	expsyms_regex)
6681fe24f8a2Smrg	  export_symbols_regex=$arg
668234977a2fSmrg	  prev=
668334977a2fSmrg	  continue
668434977a2fSmrg	  ;;
668534977a2fSmrg	framework)
6686ee3138f1Smrg	  case $host in
668734977a2fSmrg	    *-*-darwin*)
668834977a2fSmrg	      case "$deplibs " in
668934977a2fSmrg		*" $qarg.ltframework "*) ;;
66903e72ca8cSmrg		*) func_append deplibs " $qarg.ltframework" # this is fixed later
669134977a2fSmrg		   ;;
669234977a2fSmrg	      esac
669334977a2fSmrg	      ;;
6694ee3138f1Smrg	  esac
669534977a2fSmrg	  prev=
669634977a2fSmrg	  continue
6697ee3138f1Smrg	  ;;
669834977a2fSmrg	inst_prefix)
6699fe24f8a2Smrg	  inst_prefix_dir=$arg
6700fe24f8a2Smrg	  prev=
6701fe24f8a2Smrg	  continue
6702fe24f8a2Smrg	  ;;
6703fe24f8a2Smrg	mllvm)
6704fe24f8a2Smrg	  # Clang does not use LLVM to link, so we can simply discard any
6705fe24f8a2Smrg	  # '-mllvm $arg' options when doing the link step.
670634977a2fSmrg	  prev=
670734977a2fSmrg	  continue
6708ee3138f1Smrg	  ;;
670934977a2fSmrg	objectlist)
671034977a2fSmrg	  if test -f "$arg"; then
671134977a2fSmrg	    save_arg=$arg
671234977a2fSmrg	    moreargs=
671334977a2fSmrg	    for fil in `cat "$save_arg"`
671434977a2fSmrg	    do
67153e72ca8cSmrg#	      func_append moreargs " $fil"
671634977a2fSmrg	      arg=$fil
671734977a2fSmrg	      # A libtool-controlled object.
6718ee3138f1Smrg
671934977a2fSmrg	      # Check to see that this really is a libtool object.
672034977a2fSmrg	      if func_lalib_unsafe_p "$arg"; then
672134977a2fSmrg		pic_object=
672234977a2fSmrg		non_pic_object=
6723ee3138f1Smrg
672434977a2fSmrg		# Read the .lo file
672534977a2fSmrg		func_source "$arg"
6726ee3138f1Smrg
672734977a2fSmrg		if test -z "$pic_object" ||
672834977a2fSmrg		   test -z "$non_pic_object" ||
6729fe24f8a2Smrg		   test none = "$pic_object" &&
6730fe24f8a2Smrg		   test none = "$non_pic_object"; then
6731fe24f8a2Smrg		  func_fatal_error "cannot find name of object for '$arg'"
673234977a2fSmrg		fi
6733ee3138f1Smrg
673434977a2fSmrg		# Extract subdirectory from the argument.
673534977a2fSmrg		func_dirname "$arg" "/" ""
6736fe24f8a2Smrg		xdir=$func_dirname_result
6737ee3138f1Smrg
6738fe24f8a2Smrg		if test none != "$pic_object"; then
673934977a2fSmrg		  # Prepend the subdirectory the object is found in.
6740fe24f8a2Smrg		  pic_object=$xdir$pic_object
6741ee3138f1Smrg
6742fe24f8a2Smrg		  if test dlfiles = "$prev"; then
6743fe24f8a2Smrg		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
67443e72ca8cSmrg		      func_append dlfiles " $pic_object"
674534977a2fSmrg		      prev=
674634977a2fSmrg		      continue
674734977a2fSmrg		    else
674834977a2fSmrg		      # If libtool objects are unsupported, then we need to preload.
674934977a2fSmrg		      prev=dlprefiles
675034977a2fSmrg		    fi
675134977a2fSmrg		  fi
6752ee3138f1Smrg
675334977a2fSmrg		  # CHECK ME:  I think I busted this.  -Ossama
6754fe24f8a2Smrg		  if test dlprefiles = "$prev"; then
675534977a2fSmrg		    # Preload the old-style object.
67563e72ca8cSmrg		    func_append dlprefiles " $pic_object"
675734977a2fSmrg		    prev=
675834977a2fSmrg		  fi
6759ee3138f1Smrg
676034977a2fSmrg		  # A PIC object.
676134977a2fSmrg		  func_append libobjs " $pic_object"
6762fe24f8a2Smrg		  arg=$pic_object
676334977a2fSmrg		fi
6764ee3138f1Smrg
676534977a2fSmrg		# Non-PIC object.
6766fe24f8a2Smrg		if test none != "$non_pic_object"; then
676734977a2fSmrg		  # Prepend the subdirectory the object is found in.
6768fe24f8a2Smrg		  non_pic_object=$xdir$non_pic_object
676934977a2fSmrg
677034977a2fSmrg		  # A standard non-PIC object
677134977a2fSmrg		  func_append non_pic_objects " $non_pic_object"
6772fe24f8a2Smrg		  if test -z "$pic_object" || test none = "$pic_object"; then
6773fe24f8a2Smrg		    arg=$non_pic_object
677434977a2fSmrg		  fi
677534977a2fSmrg		else
677634977a2fSmrg		  # If the PIC object exists, use it instead.
677734977a2fSmrg		  # $xdir was prepended to $pic_object above.
6778fe24f8a2Smrg		  non_pic_object=$pic_object
677934977a2fSmrg		  func_append non_pic_objects " $non_pic_object"
678034977a2fSmrg		fi
678134977a2fSmrg	      else
678234977a2fSmrg		# Only an error if not doing a dry-run.
678334977a2fSmrg		if $opt_dry_run; then
678434977a2fSmrg		  # Extract subdirectory from the argument.
678534977a2fSmrg		  func_dirname "$arg" "/" ""
6786fe24f8a2Smrg		  xdir=$func_dirname_result
678734977a2fSmrg
678834977a2fSmrg		  func_lo2o "$arg"
678934977a2fSmrg		  pic_object=$xdir$objdir/$func_lo2o_result
679034977a2fSmrg		  non_pic_object=$xdir$func_lo2o_result
679134977a2fSmrg		  func_append libobjs " $pic_object"
679234977a2fSmrg		  func_append non_pic_objects " $non_pic_object"
679334977a2fSmrg	        else
6794fe24f8a2Smrg		  func_fatal_error "'$arg' is not a valid libtool object"
679534977a2fSmrg		fi
679634977a2fSmrg	      fi
679734977a2fSmrg	    done
6798ee3138f1Smrg	  else
6799fe24f8a2Smrg	    func_fatal_error "link input file '$arg' does not exist"
6800ee3138f1Smrg	  fi
680134977a2fSmrg	  arg=$save_arg
680234977a2fSmrg	  prev=
680334977a2fSmrg	  continue
680434977a2fSmrg	  ;;
6805fe24f8a2Smrg	os2dllname)
6806fe24f8a2Smrg	  os2dllname=$arg
6807fe24f8a2Smrg	  prev=
6808fe24f8a2Smrg	  continue
6809fe24f8a2Smrg	  ;;
681034977a2fSmrg	precious_regex)
6811fe24f8a2Smrg	  precious_files_regex=$arg
681234977a2fSmrg	  prev=
681334977a2fSmrg	  continue
681434977a2fSmrg	  ;;
681534977a2fSmrg	release)
6816fe24f8a2Smrg	  release=-$arg
681734977a2fSmrg	  prev=
681834977a2fSmrg	  continue
681934977a2fSmrg	  ;;
682034977a2fSmrg	rpath | xrpath)
682134977a2fSmrg	  # We need an absolute path.
682234977a2fSmrg	  case $arg in
682334977a2fSmrg	  [\\/]* | [A-Za-z]:[\\/]*) ;;
682434977a2fSmrg	  *)
682534977a2fSmrg	    func_fatal_error "only absolute run-paths are allowed"
682634977a2fSmrg	    ;;
682734977a2fSmrg	  esac
6828fe24f8a2Smrg	  if test rpath = "$prev"; then
682934977a2fSmrg	    case "$rpath " in
683034977a2fSmrg	    *" $arg "*) ;;
68313e72ca8cSmrg	    *) func_append rpath " $arg" ;;
683234977a2fSmrg	    esac
6833ee3138f1Smrg	  else
683434977a2fSmrg	    case "$xrpath " in
683534977a2fSmrg	    *" $arg "*) ;;
68363e72ca8cSmrg	    *) func_append xrpath " $arg" ;;
683734977a2fSmrg	    esac
6838ee3138f1Smrg	  fi
683934977a2fSmrg	  prev=
684034977a2fSmrg	  continue
684134977a2fSmrg	  ;;
684234977a2fSmrg	shrext)
6843fe24f8a2Smrg	  shrext_cmds=$arg
684434977a2fSmrg	  prev=
684534977a2fSmrg	  continue
684634977a2fSmrg	  ;;
684734977a2fSmrg	weak)
68483e72ca8cSmrg	  func_append weak_libs " $arg"
684934977a2fSmrg	  prev=
685034977a2fSmrg	  continue
685134977a2fSmrg	  ;;
685234977a2fSmrg	xcclinker)
68533e72ca8cSmrg	  func_append linker_flags " $qarg"
68543e72ca8cSmrg	  func_append compiler_flags " $qarg"
685534977a2fSmrg	  prev=
685634977a2fSmrg	  func_append compile_command " $qarg"
685734977a2fSmrg	  func_append finalize_command " $qarg"
685834977a2fSmrg	  continue
685934977a2fSmrg	  ;;
686034977a2fSmrg	xcompiler)
68613e72ca8cSmrg	  func_append compiler_flags " $qarg"
686234977a2fSmrg	  prev=
686334977a2fSmrg	  func_append compile_command " $qarg"
686434977a2fSmrg	  func_append finalize_command " $qarg"
686534977a2fSmrg	  continue
686634977a2fSmrg	  ;;
686734977a2fSmrg	xlinker)
68683e72ca8cSmrg	  func_append linker_flags " $qarg"
68693e72ca8cSmrg	  func_append compiler_flags " $wl$qarg"
687034977a2fSmrg	  prev=
687134977a2fSmrg	  func_append compile_command " $wl$qarg"
687234977a2fSmrg	  func_append finalize_command " $wl$qarg"
687334977a2fSmrg	  continue
687434977a2fSmrg	  ;;
687534977a2fSmrg	*)
687634977a2fSmrg	  eval "$prev=\"\$arg\""
687734977a2fSmrg	  prev=
687834977a2fSmrg	  continue
687934977a2fSmrg	  ;;
6880ee3138f1Smrg	esac
688134977a2fSmrg      fi # test -n "$prev"
6882ee3138f1Smrg
6883fe24f8a2Smrg      prevarg=$arg
6884ee3138f1Smrg
688534977a2fSmrg      case $arg in
688634977a2fSmrg      -all-static)
688734977a2fSmrg	if test -n "$link_static_flag"; then
688834977a2fSmrg	  # See comment for -static flag below, for more details.
688934977a2fSmrg	  func_append compile_command " $link_static_flag"
689034977a2fSmrg	  func_append finalize_command " $link_static_flag"
689134977a2fSmrg	fi
689234977a2fSmrg	continue
689334977a2fSmrg	;;
6894ee3138f1Smrg
689534977a2fSmrg      -allow-undefined)
689634977a2fSmrg	# FIXME: remove this flag sometime in the future.
6897fe24f8a2Smrg	func_fatal_error "'-allow-undefined' must not be used because it is the default"
689834977a2fSmrg	;;
6899ee3138f1Smrg
690034977a2fSmrg      -avoid-version)
690134977a2fSmrg	avoid_version=yes
690234977a2fSmrg	continue
690334977a2fSmrg	;;
6904ee3138f1Smrg
6905b425557eSmrg      -bindir)
6906b425557eSmrg	prev=bindir
6907b425557eSmrg	continue
6908b425557eSmrg	;;
6909b425557eSmrg
691034977a2fSmrg      -dlopen)
691134977a2fSmrg	prev=dlfiles
691234977a2fSmrg	continue
691334977a2fSmrg	;;
6914ee3138f1Smrg
691534977a2fSmrg      -dlpreopen)
691634977a2fSmrg	prev=dlprefiles
691734977a2fSmrg	continue
691834977a2fSmrg	;;
6919ee3138f1Smrg
692034977a2fSmrg      -export-dynamic)
692134977a2fSmrg	export_dynamic=yes
692234977a2fSmrg	continue
692334977a2fSmrg	;;
6924ee3138f1Smrg
692534977a2fSmrg      -export-symbols | -export-symbols-regex)
692634977a2fSmrg	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
692734977a2fSmrg	  func_fatal_error "more than one -exported-symbols argument is not allowed"
692834977a2fSmrg	fi
6929fe24f8a2Smrg	if test X-export-symbols = "X$arg"; then
693034977a2fSmrg	  prev=expsyms
693134977a2fSmrg	else
693234977a2fSmrg	  prev=expsyms_regex
693334977a2fSmrg	fi
693434977a2fSmrg	continue
693534977a2fSmrg	;;
6936ee3138f1Smrg
693734977a2fSmrg      -framework)
693834977a2fSmrg	prev=framework
693934977a2fSmrg	continue
694034977a2fSmrg	;;
6941ee3138f1Smrg
694234977a2fSmrg      -inst-prefix-dir)
694334977a2fSmrg	prev=inst_prefix
694434977a2fSmrg	continue
694534977a2fSmrg	;;
6946ee3138f1Smrg
694734977a2fSmrg      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
694834977a2fSmrg      # so, if we see these flags be careful not to treat them like -L
694934977a2fSmrg      -L[A-Z][A-Z]*:*)
695034977a2fSmrg	case $with_gcc/$host in
695134977a2fSmrg	no/*-*-irix* | /*-*-irix*)
695234977a2fSmrg	  func_append compile_command " $arg"
695334977a2fSmrg	  func_append finalize_command " $arg"
695434977a2fSmrg	  ;;
695534977a2fSmrg	esac
695634977a2fSmrg	continue
695734977a2fSmrg	;;
6958ee3138f1Smrg
695934977a2fSmrg      -L*)
69603e72ca8cSmrg	func_stripname "-L" '' "$arg"
69613e72ca8cSmrg	if test -z "$func_stripname_result"; then
696234977a2fSmrg	  if test "$#" -gt 0; then
6963fe24f8a2Smrg	    func_fatal_error "require no space between '-L' and '$1'"
696434977a2fSmrg	  else
6965fe24f8a2Smrg	    func_fatal_error "need path for '-L' option"
696634977a2fSmrg	  fi
696734977a2fSmrg	fi
69683e72ca8cSmrg	func_resolve_sysroot "$func_stripname_result"
69693e72ca8cSmrg	dir=$func_resolve_sysroot_result
697034977a2fSmrg	# We need an absolute path.
697134977a2fSmrg	case $dir in
697234977a2fSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
697334977a2fSmrg	*)
697434977a2fSmrg	  absdir=`cd "$dir" && pwd`
697534977a2fSmrg	  test -z "$absdir" && \
6976fe24f8a2Smrg	    func_fatal_error "cannot determine absolute directory name of '$dir'"
6977fe24f8a2Smrg	  dir=$absdir
697834977a2fSmrg	  ;;
697934977a2fSmrg	esac
698034977a2fSmrg	case "$deplibs " in
69813e72ca8cSmrg	*" -L$dir "* | *" $arg "*)
69823e72ca8cSmrg	  # Will only happen for absolute or sysroot arguments
69833e72ca8cSmrg	  ;;
698434977a2fSmrg	*)
69853e72ca8cSmrg	  # Preserve sysroot, but never include relative directories
69863e72ca8cSmrg	  case $dir in
69873e72ca8cSmrg	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
69883e72ca8cSmrg	    *) func_append deplibs " -L$dir" ;;
69893e72ca8cSmrg	  esac
69903e72ca8cSmrg	  func_append lib_search_path " $dir"
699134977a2fSmrg	  ;;
699234977a2fSmrg	esac
699334977a2fSmrg	case $host in
699434977a2fSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
6995b425557eSmrg	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
699634977a2fSmrg	  case :$dllsearchpath: in
699734977a2fSmrg	  *":$dir:"*) ;;
699834977a2fSmrg	  ::) dllsearchpath=$dir;;
69993e72ca8cSmrg	  *) func_append dllsearchpath ":$dir";;
700034977a2fSmrg	  esac
700134977a2fSmrg	  case :$dllsearchpath: in
700234977a2fSmrg	  *":$testbindir:"*) ;;
700334977a2fSmrg	  ::) dllsearchpath=$testbindir;;
70043e72ca8cSmrg	  *) func_append dllsearchpath ":$testbindir";;
700534977a2fSmrg	  esac
700634977a2fSmrg	  ;;
700734977a2fSmrg	esac
700834977a2fSmrg	continue
700934977a2fSmrg	;;
7010ee3138f1Smrg
701134977a2fSmrg      -l*)
7012fe24f8a2Smrg	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
701334977a2fSmrg	  case $host in
7014b425557eSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
701534977a2fSmrg	    # These systems don't actually have a C or math library (as such)
701634977a2fSmrg	    continue
701734977a2fSmrg	    ;;
701834977a2fSmrg	  *-*-os2*)
701934977a2fSmrg	    # These systems don't actually have a C library (as such)
7020fe24f8a2Smrg	    test X-lc = "X$arg" && continue
702134977a2fSmrg	    ;;
7022fe24f8a2Smrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
702334977a2fSmrg	    # Do not include libc due to us having libc/libc_r.
7024fe24f8a2Smrg	    test X-lc = "X$arg" && continue
702534977a2fSmrg	    ;;
702634977a2fSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
702734977a2fSmrg	    # Rhapsody C and math libraries are in the System framework
70283e72ca8cSmrg	    func_append deplibs " System.ltframework"
702934977a2fSmrg	    continue
703034977a2fSmrg	    ;;
703134977a2fSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
703234977a2fSmrg	    # Causes problems with __ctype
7033fe24f8a2Smrg	    test X-lc = "X$arg" && continue
703434977a2fSmrg	    ;;
703534977a2fSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
703634977a2fSmrg	    # Compiler inserts libc in the correct place for threads to work
7037fe24f8a2Smrg	    test X-lc = "X$arg" && continue
703834977a2fSmrg	    ;;
703934977a2fSmrg	  esac
7040fe24f8a2Smrg	elif test X-lc_r = "X$arg"; then
704134977a2fSmrg	 case $host in
7042fe24f8a2Smrg	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
704334977a2fSmrg	   # Do not include libc_r directly, use -pthread flag.
704434977a2fSmrg	   continue
704534977a2fSmrg	   ;;
704634977a2fSmrg	 esac
704734977a2fSmrg	fi
70483e72ca8cSmrg	func_append deplibs " $arg"
704934977a2fSmrg	continue
705034977a2fSmrg	;;
7051ee3138f1Smrg
7052fe24f8a2Smrg      -mllvm)
7053fe24f8a2Smrg	prev=mllvm
7054fe24f8a2Smrg	continue
7055fe24f8a2Smrg	;;
7056fe24f8a2Smrg
705734977a2fSmrg      -module)
705834977a2fSmrg	module=yes
705934977a2fSmrg	continue
706034977a2fSmrg	;;
7061ee3138f1Smrg
706234977a2fSmrg      # Tru64 UNIX uses -model [arg] to determine the layout of C++
706334977a2fSmrg      # classes, name mangling, and exception handling.
706434977a2fSmrg      # Darwin uses the -arch flag to determine output architecture.
70653e72ca8cSmrg      -model|-arch|-isysroot|--sysroot)
70663e72ca8cSmrg	func_append compiler_flags " $arg"
706734977a2fSmrg	func_append compile_command " $arg"
706834977a2fSmrg	func_append finalize_command " $arg"
706934977a2fSmrg	prev=xcompiler
707034977a2fSmrg	continue
707134977a2fSmrg	;;
7072ee3138f1Smrg
70733e72ca8cSmrg      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
70743e72ca8cSmrg      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
70753e72ca8cSmrg	func_append compiler_flags " $arg"
707634977a2fSmrg	func_append compile_command " $arg"
707734977a2fSmrg	func_append finalize_command " $arg"
707834977a2fSmrg	case "$new_inherited_linker_flags " in
707934977a2fSmrg	    *" $arg "*) ;;
70803e72ca8cSmrg	    * ) func_append new_inherited_linker_flags " $arg" ;;
708134977a2fSmrg	esac
708234977a2fSmrg	continue
708334977a2fSmrg	;;
7084ee3138f1Smrg
708534977a2fSmrg      -multi_module)
7086fe24f8a2Smrg	single_module=$wl-multi_module
708734977a2fSmrg	continue
708834977a2fSmrg	;;
7089ee3138f1Smrg
709034977a2fSmrg      -no-fast-install)
709134977a2fSmrg	fast_install=no
709234977a2fSmrg	continue
709334977a2fSmrg	;;
7094ee3138f1Smrg
709534977a2fSmrg      -no-install)
709634977a2fSmrg	case $host in
709734977a2fSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
709834977a2fSmrg	  # The PATH hackery in wrapper scripts is required on Windows
709934977a2fSmrg	  # and Darwin in order for the loader to find any dlls it needs.
7100fe24f8a2Smrg	  func_warning "'-no-install' is ignored for $host"
7101fe24f8a2Smrg	  func_warning "assuming '-no-fast-install' instead"
710234977a2fSmrg	  fast_install=no
710334977a2fSmrg	  ;;
710434977a2fSmrg	*) no_install=yes ;;
710534977a2fSmrg	esac
710634977a2fSmrg	continue
710734977a2fSmrg	;;
7108ee3138f1Smrg
710934977a2fSmrg      -no-undefined)
711034977a2fSmrg	allow_undefined=no
711134977a2fSmrg	continue
711234977a2fSmrg	;;
7113ee3138f1Smrg
711434977a2fSmrg      -objectlist)
711534977a2fSmrg	prev=objectlist
711634977a2fSmrg	continue
711734977a2fSmrg	;;
7118ee3138f1Smrg
7119fe24f8a2Smrg      -os2dllname)
7120fe24f8a2Smrg	prev=os2dllname
7121fe24f8a2Smrg	continue
7122fe24f8a2Smrg	;;
7123fe24f8a2Smrg
712434977a2fSmrg      -o) prev=output ;;
7125ee3138f1Smrg
712634977a2fSmrg      -precious-files-regex)
712734977a2fSmrg	prev=precious_regex
712834977a2fSmrg	continue
712934977a2fSmrg	;;
7130ee3138f1Smrg
713134977a2fSmrg      -release)
713234977a2fSmrg	prev=release
713334977a2fSmrg	continue
713434977a2fSmrg	;;
7135ee3138f1Smrg
713634977a2fSmrg      -rpath)
713734977a2fSmrg	prev=rpath
713834977a2fSmrg	continue
713934977a2fSmrg	;;
7140ee3138f1Smrg
714134977a2fSmrg      -R)
714234977a2fSmrg	prev=xrpath
714334977a2fSmrg	continue
714434977a2fSmrg	;;
7145ee3138f1Smrg
714634977a2fSmrg      -R*)
714734977a2fSmrg	func_stripname '-R' '' "$arg"
714834977a2fSmrg	dir=$func_stripname_result
714934977a2fSmrg	# We need an absolute path.
715034977a2fSmrg	case $dir in
715134977a2fSmrg	[\\/]* | [A-Za-z]:[\\/]*) ;;
71523e72ca8cSmrg	=*)
71533e72ca8cSmrg	  func_stripname '=' '' "$dir"
71543e72ca8cSmrg	  dir=$lt_sysroot$func_stripname_result
71553e72ca8cSmrg	  ;;
715634977a2fSmrg	*)
715734977a2fSmrg	  func_fatal_error "only absolute run-paths are allowed"
715834977a2fSmrg	  ;;
715934977a2fSmrg	esac
716034977a2fSmrg	case "$xrpath " in
716134977a2fSmrg	*" $dir "*) ;;
71623e72ca8cSmrg	*) func_append xrpath " $dir" ;;
716334977a2fSmrg	esac
716434977a2fSmrg	continue
716534977a2fSmrg	;;
7166ee3138f1Smrg
716734977a2fSmrg      -shared)
716834977a2fSmrg	# The effects of -shared are defined in a previous loop.
716934977a2fSmrg	continue
717034977a2fSmrg	;;
7171ee3138f1Smrg
717234977a2fSmrg      -shrext)
717334977a2fSmrg	prev=shrext
717434977a2fSmrg	continue
717534977a2fSmrg	;;
7176ee3138f1Smrg
717734977a2fSmrg      -static | -static-libtool-libs)
717834977a2fSmrg	# The effects of -static are defined in a previous loop.
717934977a2fSmrg	# We used to do the same as -all-static on platforms that
718034977a2fSmrg	# didn't have a PIC flag, but the assumption that the effects
718134977a2fSmrg	# would be equivalent was wrong.  It would break on at least
718234977a2fSmrg	# Digital Unix and AIX.
718334977a2fSmrg	continue
718434977a2fSmrg	;;
7185ee3138f1Smrg
718634977a2fSmrg      -thread-safe)
718734977a2fSmrg	thread_safe=yes
718834977a2fSmrg	continue
718934977a2fSmrg	;;
7190ee3138f1Smrg
719134977a2fSmrg      -version-info)
719234977a2fSmrg	prev=vinfo
719334977a2fSmrg	continue
719434977a2fSmrg	;;
7195ee3138f1Smrg
719634977a2fSmrg      -version-number)
719734977a2fSmrg	prev=vinfo
719834977a2fSmrg	vinfo_number=yes
719934977a2fSmrg	continue
720034977a2fSmrg	;;
7201ee3138f1Smrg
720234977a2fSmrg      -weak)
720334977a2fSmrg        prev=weak
720434977a2fSmrg	continue
720534977a2fSmrg	;;
7206ee3138f1Smrg
720734977a2fSmrg      -Wc,*)
720834977a2fSmrg	func_stripname '-Wc,' '' "$arg"
720934977a2fSmrg	args=$func_stripname_result
721034977a2fSmrg	arg=
7211fe24f8a2Smrg	save_ifs=$IFS; IFS=,
721234977a2fSmrg	for flag in $args; do
7213fe24f8a2Smrg	  IFS=$save_ifs
721434977a2fSmrg          func_quote_for_eval "$flag"
72153e72ca8cSmrg	  func_append arg " $func_quote_for_eval_result"
72163e72ca8cSmrg	  func_append compiler_flags " $func_quote_for_eval_result"
721734977a2fSmrg	done
7218fe24f8a2Smrg	IFS=$save_ifs
721934977a2fSmrg	func_stripname ' ' '' "$arg"
722034977a2fSmrg	arg=$func_stripname_result
722134977a2fSmrg	;;
7222ee3138f1Smrg
722334977a2fSmrg      -Wl,*)
722434977a2fSmrg	func_stripname '-Wl,' '' "$arg"
722534977a2fSmrg	args=$func_stripname_result
722634977a2fSmrg	arg=
7227fe24f8a2Smrg	save_ifs=$IFS; IFS=,
722834977a2fSmrg	for flag in $args; do
7229fe24f8a2Smrg	  IFS=$save_ifs
723034977a2fSmrg          func_quote_for_eval "$flag"
72313e72ca8cSmrg	  func_append arg " $wl$func_quote_for_eval_result"
72323e72ca8cSmrg	  func_append compiler_flags " $wl$func_quote_for_eval_result"
72333e72ca8cSmrg	  func_append linker_flags " $func_quote_for_eval_result"
723434977a2fSmrg	done
7235fe24f8a2Smrg	IFS=$save_ifs
723634977a2fSmrg	func_stripname ' ' '' "$arg"
723734977a2fSmrg	arg=$func_stripname_result
723834977a2fSmrg	;;
7239ee3138f1Smrg
724034977a2fSmrg      -Xcompiler)
724134977a2fSmrg	prev=xcompiler
724234977a2fSmrg	continue
724334977a2fSmrg	;;
7244ee3138f1Smrg
724534977a2fSmrg      -Xlinker)
724634977a2fSmrg	prev=xlinker
724734977a2fSmrg	continue
724834977a2fSmrg	;;
7249ee3138f1Smrg
725034977a2fSmrg      -XCClinker)
725134977a2fSmrg	prev=xcclinker
725234977a2fSmrg	continue
725334977a2fSmrg	;;
7254ee3138f1Smrg
725534977a2fSmrg      # -msg_* for osf cc
725634977a2fSmrg      -msg_*)
725734977a2fSmrg	func_quote_for_eval "$arg"
7258fe24f8a2Smrg	arg=$func_quote_for_eval_result
725934977a2fSmrg	;;
7260ee3138f1Smrg
7261b425557eSmrg      # Flags to be passed through unchanged, with rationale:
7262b425557eSmrg      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
7263b425557eSmrg      # -r[0-9][0-9]*        specify processor for the SGI compiler
7264b425557eSmrg      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
7265b425557eSmrg      # +DA*, +DD*           enable 64-bit mode for the HP compiler
7266b425557eSmrg      # -q*                  compiler args for the IBM compiler
7267b425557eSmrg      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
7268b425557eSmrg      # -F/path              path to uninstalled frameworks, gcc on darwin
7269b425557eSmrg      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7270fe24f8a2Smrg      # -fstack-protector*   stack protector flags for GCC
7271b425557eSmrg      # @file                GCC response files
7272b425557eSmrg      # -tp=*                Portland pgcc target processor selection
72733e72ca8cSmrg      # --sysroot=*          for sysroot support
7274fe24f8a2Smrg      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7275fe24f8a2Smrg      # -stdlib=*            select c++ std lib with clang
727634977a2fSmrg      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
72773e72ca8cSmrg      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7278fe24f8a2Smrg      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*)
727934977a2fSmrg        func_quote_for_eval "$arg"
7280fe24f8a2Smrg	arg=$func_quote_for_eval_result
728134977a2fSmrg        func_append compile_command " $arg"
728234977a2fSmrg        func_append finalize_command " $arg"
72833e72ca8cSmrg        func_append compiler_flags " $arg"
728434977a2fSmrg        continue
728534977a2fSmrg        ;;
7286ee3138f1Smrg
7287fe24f8a2Smrg      -Z*)
7288fe24f8a2Smrg        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7289fe24f8a2Smrg          # OS/2 uses -Zxxx to specify OS/2-specific options
7290fe24f8a2Smrg	  compiler_flags="$compiler_flags $arg"
7291fe24f8a2Smrg	  func_append compile_command " $arg"
7292fe24f8a2Smrg	  func_append finalize_command " $arg"
7293fe24f8a2Smrg	  case $arg in
7294fe24f8a2Smrg	  -Zlinker | -Zstack)
7295fe24f8a2Smrg	    prev=xcompiler
7296fe24f8a2Smrg	    ;;
7297fe24f8a2Smrg	  esac
7298fe24f8a2Smrg	  continue
7299fe24f8a2Smrg        else
7300fe24f8a2Smrg	  # Otherwise treat like 'Some other compiler flag' below
7301fe24f8a2Smrg	  func_quote_for_eval "$arg"
7302fe24f8a2Smrg	  arg=$func_quote_for_eval_result
7303fe24f8a2Smrg        fi
7304fe24f8a2Smrg	;;
7305fe24f8a2Smrg
730634977a2fSmrg      # Some other compiler flag.
730734977a2fSmrg      -* | +*)
730834977a2fSmrg        func_quote_for_eval "$arg"
7309fe24f8a2Smrg	arg=$func_quote_for_eval_result
731034977a2fSmrg	;;
7311ee3138f1Smrg
731234977a2fSmrg      *.$objext)
731334977a2fSmrg	# A standard object.
73143e72ca8cSmrg	func_append objs " $arg"
731534977a2fSmrg	;;
7316ee3138f1Smrg
731734977a2fSmrg      *.lo)
731834977a2fSmrg	# A libtool-controlled object.
7319ee3138f1Smrg
732034977a2fSmrg	# Check to see that this really is a libtool object.
732134977a2fSmrg	if func_lalib_unsafe_p "$arg"; then
732234977a2fSmrg	  pic_object=
732334977a2fSmrg	  non_pic_object=
7324ee3138f1Smrg
732534977a2fSmrg	  # Read the .lo file
732634977a2fSmrg	  func_source "$arg"
7327ee3138f1Smrg
732834977a2fSmrg	  if test -z "$pic_object" ||
732934977a2fSmrg	     test -z "$non_pic_object" ||
7330fe24f8a2Smrg	     test none = "$pic_object" &&
7331fe24f8a2Smrg	     test none = "$non_pic_object"; then
7332fe24f8a2Smrg	    func_fatal_error "cannot find name of object for '$arg'"
733334977a2fSmrg	  fi
7334ee3138f1Smrg
733534977a2fSmrg	  # Extract subdirectory from the argument.
733634977a2fSmrg	  func_dirname "$arg" "/" ""
7337fe24f8a2Smrg	  xdir=$func_dirname_result
7338ee3138f1Smrg
7339fe24f8a2Smrg	  test none = "$pic_object" || {
734034977a2fSmrg	    # Prepend the subdirectory the object is found in.
7341fe24f8a2Smrg	    pic_object=$xdir$pic_object
7342ee3138f1Smrg
7343fe24f8a2Smrg	    if test dlfiles = "$prev"; then
7344fe24f8a2Smrg	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
73453e72ca8cSmrg		func_append dlfiles " $pic_object"
734634977a2fSmrg		prev=
734734977a2fSmrg		continue
734834977a2fSmrg	      else
734934977a2fSmrg		# If libtool objects are unsupported, then we need to preload.
735034977a2fSmrg		prev=dlprefiles
735134977a2fSmrg	      fi
735234977a2fSmrg	    fi
7353ee3138f1Smrg
735434977a2fSmrg	    # CHECK ME:  I think I busted this.  -Ossama
7355fe24f8a2Smrg	    if test dlprefiles = "$prev"; then
735634977a2fSmrg	      # Preload the old-style object.
73573e72ca8cSmrg	      func_append dlprefiles " $pic_object"
735834977a2fSmrg	      prev=
735934977a2fSmrg	    fi
7360ee3138f1Smrg
736134977a2fSmrg	    # A PIC object.
736234977a2fSmrg	    func_append libobjs " $pic_object"
7363fe24f8a2Smrg	    arg=$pic_object
7364fe24f8a2Smrg	  }
7365ee3138f1Smrg
736634977a2fSmrg	  # Non-PIC object.
7367fe24f8a2Smrg	  if test none != "$non_pic_object"; then
736834977a2fSmrg	    # Prepend the subdirectory the object is found in.
7369fe24f8a2Smrg	    non_pic_object=$xdir$non_pic_object
7370ee3138f1Smrg
737134977a2fSmrg	    # A standard non-PIC object
737234977a2fSmrg	    func_append non_pic_objects " $non_pic_object"
7373fe24f8a2Smrg	    if test -z "$pic_object" || test none = "$pic_object"; then
7374fe24f8a2Smrg	      arg=$non_pic_object
737534977a2fSmrg	    fi
737634977a2fSmrg	  else
737734977a2fSmrg	    # If the PIC object exists, use it instead.
737834977a2fSmrg	    # $xdir was prepended to $pic_object above.
7379fe24f8a2Smrg	    non_pic_object=$pic_object
738034977a2fSmrg	    func_append non_pic_objects " $non_pic_object"
738134977a2fSmrg	  fi
738234977a2fSmrg	else
738334977a2fSmrg	  # Only an error if not doing a dry-run.
738434977a2fSmrg	  if $opt_dry_run; then
738534977a2fSmrg	    # Extract subdirectory from the argument.
738634977a2fSmrg	    func_dirname "$arg" "/" ""
7387fe24f8a2Smrg	    xdir=$func_dirname_result
738834977a2fSmrg
738934977a2fSmrg	    func_lo2o "$arg"
739034977a2fSmrg	    pic_object=$xdir$objdir/$func_lo2o_result
739134977a2fSmrg	    non_pic_object=$xdir$func_lo2o_result
739234977a2fSmrg	    func_append libobjs " $pic_object"
739334977a2fSmrg	    func_append non_pic_objects " $non_pic_object"
739434977a2fSmrg	  else
7395fe24f8a2Smrg	    func_fatal_error "'$arg' is not a valid libtool object"
739634977a2fSmrg	  fi
739734977a2fSmrg	fi
739834977a2fSmrg	;;
739934977a2fSmrg
740034977a2fSmrg      *.$libext)
740134977a2fSmrg	# An archive.
74023e72ca8cSmrg	func_append deplibs " $arg"
74033e72ca8cSmrg	func_append old_deplibs " $arg"
740434977a2fSmrg	continue
740534977a2fSmrg	;;
740634977a2fSmrg
740734977a2fSmrg      *.la)
740834977a2fSmrg	# A libtool-controlled library.
740934977a2fSmrg
74103e72ca8cSmrg	func_resolve_sysroot "$arg"
7411fe24f8a2Smrg	if test dlfiles = "$prev"; then
741234977a2fSmrg	  # This library was specified with -dlopen.
74133e72ca8cSmrg	  func_append dlfiles " $func_resolve_sysroot_result"
741434977a2fSmrg	  prev=
7415fe24f8a2Smrg	elif test dlprefiles = "$prev"; then
741634977a2fSmrg	  # The library was specified with -dlpreopen.
74173e72ca8cSmrg	  func_append dlprefiles " $func_resolve_sysroot_result"
741834977a2fSmrg	  prev=
741934977a2fSmrg	else
74203e72ca8cSmrg	  func_append deplibs " $func_resolve_sysroot_result"
742134977a2fSmrg	fi
742234977a2fSmrg	continue
742334977a2fSmrg	;;
742434977a2fSmrg
742534977a2fSmrg      # Some other compiler argument.
742634977a2fSmrg      *)
742734977a2fSmrg	# Unknown arguments in both finalize_command and compile_command need
742834977a2fSmrg	# to be aesthetically quoted because they are evaled later.
742934977a2fSmrg	func_quote_for_eval "$arg"
7430fe24f8a2Smrg	arg=$func_quote_for_eval_result
743134977a2fSmrg	;;
743234977a2fSmrg      esac # arg
743334977a2fSmrg
743434977a2fSmrg      # Now actually substitute the argument into the commands.
743534977a2fSmrg      if test -n "$arg"; then
743634977a2fSmrg	func_append compile_command " $arg"
743734977a2fSmrg	func_append finalize_command " $arg"
743834977a2fSmrg      fi
743934977a2fSmrg    done # argument parsing loop
744034977a2fSmrg
744134977a2fSmrg    test -n "$prev" && \
7442fe24f8a2Smrg      func_fatal_help "the '$prevarg' option requires an argument"
744334977a2fSmrg
7444fe24f8a2Smrg    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
744534977a2fSmrg      eval arg=\"$export_dynamic_flag_spec\"
744634977a2fSmrg      func_append compile_command " $arg"
744734977a2fSmrg      func_append finalize_command " $arg"
744834977a2fSmrg    fi
744934977a2fSmrg
745034977a2fSmrg    oldlibs=
745134977a2fSmrg    # calculate the name of the file, without its directory
745234977a2fSmrg    func_basename "$output"
7453fe24f8a2Smrg    outputname=$func_basename_result
7454fe24f8a2Smrg    libobjs_save=$libobjs
745534977a2fSmrg
745634977a2fSmrg    if test -n "$shlibpath_var"; then
745734977a2fSmrg      # get the directories listed in $shlibpath_var
7458fe24f8a2Smrg      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
745934977a2fSmrg    else
746034977a2fSmrg      shlib_search_path=
746134977a2fSmrg    fi
746234977a2fSmrg    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
746334977a2fSmrg    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
746434977a2fSmrg
7465fe24f8a2Smrg    # Definition is injected by LT_CONFIG during libtool generation.
7466fe24f8a2Smrg    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7467fe24f8a2Smrg
746834977a2fSmrg    func_dirname "$output" "/" ""
7469fe24f8a2Smrg    output_objdir=$func_dirname_result$objdir
74703e72ca8cSmrg    func_to_tool_file "$output_objdir/"
74713e72ca8cSmrg    tool_output_objdir=$func_to_tool_file_result
747234977a2fSmrg    # Create the object directory.
747334977a2fSmrg    func_mkdir_p "$output_objdir"
747434977a2fSmrg
747534977a2fSmrg    # Determine the type of output
747634977a2fSmrg    case $output in
747734977a2fSmrg    "")
747834977a2fSmrg      func_fatal_help "you must specify an output file"
747934977a2fSmrg      ;;
748034977a2fSmrg    *.$libext) linkmode=oldlib ;;
748134977a2fSmrg    *.lo | *.$objext) linkmode=obj ;;
748234977a2fSmrg    *.la) linkmode=lib ;;
748334977a2fSmrg    *) linkmode=prog ;; # Anything else should be a program.
748434977a2fSmrg    esac
748534977a2fSmrg
748634977a2fSmrg    specialdeplibs=
748734977a2fSmrg
748834977a2fSmrg    libs=
748934977a2fSmrg    # Find all interdependent deplibs by searching for libraries
749034977a2fSmrg    # that are linked more than once (e.g. -la -lb -la)
749134977a2fSmrg    for deplib in $deplibs; do
7492fe24f8a2Smrg      if $opt_preserve_dup_deps; then
749334977a2fSmrg	case "$libs " in
74943e72ca8cSmrg	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
749534977a2fSmrg	esac
749634977a2fSmrg      fi
74973e72ca8cSmrg      func_append libs " $deplib"
749834977a2fSmrg    done
749934977a2fSmrg
7500fe24f8a2Smrg    if test lib = "$linkmode"; then
750134977a2fSmrg      libs="$predeps $libs $compiler_lib_search_path $postdeps"
750234977a2fSmrg
750334977a2fSmrg      # Compute libraries that are listed more than once in $predeps
750434977a2fSmrg      # $postdeps and mark them as special (i.e., whose duplicates are
750534977a2fSmrg      # not to be eliminated).
750634977a2fSmrg      pre_post_deps=
750734977a2fSmrg      if $opt_duplicate_compiler_generated_deps; then
750834977a2fSmrg	for pre_post_dep in $predeps $postdeps; do
750934977a2fSmrg	  case "$pre_post_deps " in
75103e72ca8cSmrg	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
751134977a2fSmrg	  esac
75123e72ca8cSmrg	  func_append pre_post_deps " $pre_post_dep"
751334977a2fSmrg	done
751434977a2fSmrg      fi
751534977a2fSmrg      pre_post_deps=
751634977a2fSmrg    fi
751734977a2fSmrg
751834977a2fSmrg    deplibs=
751934977a2fSmrg    newdependency_libs=
752034977a2fSmrg    newlib_search_path=
752134977a2fSmrg    need_relink=no # whether we're linking any uninstalled libtool libraries
752234977a2fSmrg    notinst_deplibs= # not-installed libtool libraries
752334977a2fSmrg    notinst_path= # paths that contain not-installed libtool libraries
752434977a2fSmrg
752534977a2fSmrg    case $linkmode in
752634977a2fSmrg    lib)
752734977a2fSmrg	passes="conv dlpreopen link"
752834977a2fSmrg	for file in $dlfiles $dlprefiles; do
752934977a2fSmrg	  case $file in
753034977a2fSmrg	  *.la) ;;
753134977a2fSmrg	  *)
7532fe24f8a2Smrg	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
753334977a2fSmrg	    ;;
753434977a2fSmrg	  esac
753534977a2fSmrg	done
753634977a2fSmrg	;;
753734977a2fSmrg    prog)
753834977a2fSmrg	compile_deplibs=
753934977a2fSmrg	finalize_deplibs=
7540fe24f8a2Smrg	alldeplibs=false
754134977a2fSmrg	newdlfiles=
754234977a2fSmrg	newdlprefiles=
754334977a2fSmrg	passes="conv scan dlopen dlpreopen link"
754434977a2fSmrg	;;
754534977a2fSmrg    *)  passes="conv"
754634977a2fSmrg	;;
754734977a2fSmrg    esac
754834977a2fSmrg
754934977a2fSmrg    for pass in $passes; do
755034977a2fSmrg      # The preopen pass in lib mode reverses $deplibs; put it back here
755134977a2fSmrg      # so that -L comes before libs that need it for instance...
7552fe24f8a2Smrg      if test lib,link = "$linkmode,$pass"; then
755334977a2fSmrg	## FIXME: Find the place where the list is rebuilt in the wrong
755434977a2fSmrg	##        order, and fix it there properly
755534977a2fSmrg        tmp_deplibs=
755634977a2fSmrg	for deplib in $deplibs; do
755734977a2fSmrg	  tmp_deplibs="$deplib $tmp_deplibs"
755834977a2fSmrg	done
7559fe24f8a2Smrg	deplibs=$tmp_deplibs
756034977a2fSmrg      fi
756134977a2fSmrg
7562fe24f8a2Smrg      if test lib,link = "$linkmode,$pass" ||
7563fe24f8a2Smrg	 test prog,scan = "$linkmode,$pass"; then
7564fe24f8a2Smrg	libs=$deplibs
756534977a2fSmrg	deplibs=
756634977a2fSmrg      fi
7567fe24f8a2Smrg      if test prog = "$linkmode"; then
756834977a2fSmrg	case $pass in
7569fe24f8a2Smrg	dlopen) libs=$dlfiles ;;
7570fe24f8a2Smrg	dlpreopen) libs=$dlprefiles ;;
757134977a2fSmrg	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
757234977a2fSmrg	esac
757334977a2fSmrg      fi
7574fe24f8a2Smrg      if test lib,dlpreopen = "$linkmode,$pass"; then
757534977a2fSmrg	# Collect and forward deplibs of preopened libtool libs
757634977a2fSmrg	for lib in $dlprefiles; do
757734977a2fSmrg	  # Ignore non-libtool-libs
757834977a2fSmrg	  dependency_libs=
75793e72ca8cSmrg	  func_resolve_sysroot "$lib"
758034977a2fSmrg	  case $lib in
75813e72ca8cSmrg	  *.la)	func_source "$func_resolve_sysroot_result" ;;
758234977a2fSmrg	  esac
758334977a2fSmrg
758434977a2fSmrg	  # Collect preopened libtool deplibs, except any this library
758534977a2fSmrg	  # has declared as weak libs
758634977a2fSmrg	  for deplib in $dependency_libs; do
7587b425557eSmrg	    func_basename "$deplib"
7588b425557eSmrg            deplib_base=$func_basename_result
758934977a2fSmrg	    case " $weak_libs " in
759034977a2fSmrg	    *" $deplib_base "*) ;;
75913e72ca8cSmrg	    *) func_append deplibs " $deplib" ;;
759234977a2fSmrg	    esac
759334977a2fSmrg	  done
759434977a2fSmrg	done
7595fe24f8a2Smrg	libs=$dlprefiles
759634977a2fSmrg      fi
7597fe24f8a2Smrg      if test dlopen = "$pass"; then
759834977a2fSmrg	# Collect dlpreopened libraries
7599fe24f8a2Smrg	save_deplibs=$deplibs
760034977a2fSmrg	deplibs=
760134977a2fSmrg      fi
760234977a2fSmrg
760334977a2fSmrg      for deplib in $libs; do
760434977a2fSmrg	lib=
7605fe24f8a2Smrg	found=false
760634977a2fSmrg	case $deplib in
76073e72ca8cSmrg	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
76083e72ca8cSmrg        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7609fe24f8a2Smrg	  if test prog,link = "$linkmode,$pass"; then
761034977a2fSmrg	    compile_deplibs="$deplib $compile_deplibs"
761134977a2fSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
761234977a2fSmrg	  else
76133e72ca8cSmrg	    func_append compiler_flags " $deplib"
7614fe24f8a2Smrg	    if test lib = "$linkmode"; then
761534977a2fSmrg		case "$new_inherited_linker_flags " in
761634977a2fSmrg		    *" $deplib "*) ;;
76173e72ca8cSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
761834977a2fSmrg		esac
761934977a2fSmrg	    fi
762034977a2fSmrg	  fi
762134977a2fSmrg	  continue
762234977a2fSmrg	  ;;
762334977a2fSmrg	-l*)
7624fe24f8a2Smrg	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7625fe24f8a2Smrg	    func_warning "'-l' is ignored for archives/objects"
762634977a2fSmrg	    continue
762734977a2fSmrg	  fi
762834977a2fSmrg	  func_stripname '-l' '' "$deplib"
762934977a2fSmrg	  name=$func_stripname_result
7630fe24f8a2Smrg	  if test lib = "$linkmode"; then
763134977a2fSmrg	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
763234977a2fSmrg	  else
763334977a2fSmrg	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
763434977a2fSmrg	  fi
763534977a2fSmrg	  for searchdir in $searchdirs; do
763634977a2fSmrg	    for search_ext in .la $std_shrext .so .a; do
763734977a2fSmrg	      # Search the libtool library
7638fe24f8a2Smrg	      lib=$searchdir/lib$name$search_ext
763934977a2fSmrg	      if test -f "$lib"; then
7640fe24f8a2Smrg		if test .la = "$search_ext"; then
7641fe24f8a2Smrg		  found=:
764234977a2fSmrg		else
7643fe24f8a2Smrg		  found=false
764434977a2fSmrg		fi
764534977a2fSmrg		break 2
764634977a2fSmrg	      fi
764734977a2fSmrg	    done
764834977a2fSmrg	  done
7649fe24f8a2Smrg	  if $found; then
7650fe24f8a2Smrg	    # deplib is a libtool library
765134977a2fSmrg	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
765234977a2fSmrg	    # We need to do some special things here, and not later.
7653fe24f8a2Smrg	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
765434977a2fSmrg	      case " $predeps $postdeps " in
765534977a2fSmrg	      *" $deplib "*)
765634977a2fSmrg		if func_lalib_p "$lib"; then
765734977a2fSmrg		  library_names=
765834977a2fSmrg		  old_library=
765934977a2fSmrg		  func_source "$lib"
766034977a2fSmrg		  for l in $old_library $library_names; do
7661fe24f8a2Smrg		    ll=$l
766234977a2fSmrg		  done
7663fe24f8a2Smrg		  if test "X$ll" = "X$old_library"; then # only static version available
7664fe24f8a2Smrg		    found=false
766534977a2fSmrg		    func_dirname "$lib" "" "."
7666fe24f8a2Smrg		    ladir=$func_dirname_result
766734977a2fSmrg		    lib=$ladir/$old_library
7668fe24f8a2Smrg		    if test prog,link = "$linkmode,$pass"; then
766934977a2fSmrg		      compile_deplibs="$deplib $compile_deplibs"
767034977a2fSmrg		      finalize_deplibs="$deplib $finalize_deplibs"
767134977a2fSmrg		    else
767234977a2fSmrg		      deplibs="$deplib $deplibs"
7673fe24f8a2Smrg		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
767434977a2fSmrg		    fi
767534977a2fSmrg		    continue
767634977a2fSmrg		  fi
767734977a2fSmrg		fi
767834977a2fSmrg		;;
767934977a2fSmrg	      *) ;;
768034977a2fSmrg	      esac
768134977a2fSmrg	    fi
7682fe24f8a2Smrg	  else
7683fe24f8a2Smrg	    # deplib doesn't seem to be a libtool library
7684fe24f8a2Smrg	    if test prog,link = "$linkmode,$pass"; then
7685fe24f8a2Smrg	      compile_deplibs="$deplib $compile_deplibs"
7686fe24f8a2Smrg	      finalize_deplibs="$deplib $finalize_deplibs"
7687fe24f8a2Smrg	    else
7688fe24f8a2Smrg	      deplibs="$deplib $deplibs"
7689fe24f8a2Smrg	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7690fe24f8a2Smrg	    fi
7691fe24f8a2Smrg	    continue
769234977a2fSmrg	  fi
769334977a2fSmrg	  ;; # -l
769434977a2fSmrg	*.ltframework)
7695fe24f8a2Smrg	  if test prog,link = "$linkmode,$pass"; then
769634977a2fSmrg	    compile_deplibs="$deplib $compile_deplibs"
769734977a2fSmrg	    finalize_deplibs="$deplib $finalize_deplibs"
769834977a2fSmrg	  else
769934977a2fSmrg	    deplibs="$deplib $deplibs"
7700fe24f8a2Smrg	    if test lib = "$linkmode"; then
770134977a2fSmrg		case "$new_inherited_linker_flags " in
770234977a2fSmrg		    *" $deplib "*) ;;
77033e72ca8cSmrg		    * ) func_append new_inherited_linker_flags " $deplib" ;;
770434977a2fSmrg		esac
770534977a2fSmrg	    fi
770634977a2fSmrg	  fi
770734977a2fSmrg	  continue
770834977a2fSmrg	  ;;
770934977a2fSmrg	-L*)
771034977a2fSmrg	  case $linkmode in
771134977a2fSmrg	  lib)
771234977a2fSmrg	    deplibs="$deplib $deplibs"
7713fe24f8a2Smrg	    test conv = "$pass" && continue
771434977a2fSmrg	    newdependency_libs="$deplib $newdependency_libs"
771534977a2fSmrg	    func_stripname '-L' '' "$deplib"
77163e72ca8cSmrg	    func_resolve_sysroot "$func_stripname_result"
77173e72ca8cSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
771834977a2fSmrg	    ;;
771934977a2fSmrg	  prog)
7720fe24f8a2Smrg	    if test conv = "$pass"; then
772134977a2fSmrg	      deplibs="$deplib $deplibs"
772234977a2fSmrg	      continue
772334977a2fSmrg	    fi
7724fe24f8a2Smrg	    if test scan = "$pass"; then
772534977a2fSmrg	      deplibs="$deplib $deplibs"
772634977a2fSmrg	    else
772734977a2fSmrg	      compile_deplibs="$deplib $compile_deplibs"
772834977a2fSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
772934977a2fSmrg	    fi
773034977a2fSmrg	    func_stripname '-L' '' "$deplib"
77313e72ca8cSmrg	    func_resolve_sysroot "$func_stripname_result"
77323e72ca8cSmrg	    func_append newlib_search_path " $func_resolve_sysroot_result"
773334977a2fSmrg	    ;;
773434977a2fSmrg	  *)
7735fe24f8a2Smrg	    func_warning "'-L' is ignored for archives/objects"
773634977a2fSmrg	    ;;
773734977a2fSmrg	  esac # linkmode
773834977a2fSmrg	  continue
773934977a2fSmrg	  ;; # -L
774034977a2fSmrg	-R*)
7741fe24f8a2Smrg	  if test link = "$pass"; then
774234977a2fSmrg	    func_stripname '-R' '' "$deplib"
77433e72ca8cSmrg	    func_resolve_sysroot "$func_stripname_result"
77443e72ca8cSmrg	    dir=$func_resolve_sysroot_result
774534977a2fSmrg	    # Make sure the xrpath contains only unique directories.
774634977a2fSmrg	    case "$xrpath " in
774734977a2fSmrg	    *" $dir "*) ;;
77483e72ca8cSmrg	    *) func_append xrpath " $dir" ;;
774934977a2fSmrg	    esac
775034977a2fSmrg	  fi
775134977a2fSmrg	  deplibs="$deplib $deplibs"
775234977a2fSmrg	  continue
775334977a2fSmrg	  ;;
77543e72ca8cSmrg	*.la)
77553e72ca8cSmrg	  func_resolve_sysroot "$deplib"
77563e72ca8cSmrg	  lib=$func_resolve_sysroot_result
77573e72ca8cSmrg	  ;;
775834977a2fSmrg	*.$libext)
7759fe24f8a2Smrg	  if test conv = "$pass"; then
776034977a2fSmrg	    deplibs="$deplib $deplibs"
776134977a2fSmrg	    continue
776234977a2fSmrg	  fi
776334977a2fSmrg	  case $linkmode in
776434977a2fSmrg	  lib)
776534977a2fSmrg	    # Linking convenience modules into shared libraries is allowed,
776634977a2fSmrg	    # but linking other static libraries is non-portable.
776734977a2fSmrg	    case " $dlpreconveniencelibs " in
776834977a2fSmrg	    *" $deplib "*) ;;
776934977a2fSmrg	    *)
7770fe24f8a2Smrg	      valid_a_lib=false
777134977a2fSmrg	      case $deplibs_check_method in
777234977a2fSmrg		match_pattern*)
777334977a2fSmrg		  set dummy $deplibs_check_method; shift
777434977a2fSmrg		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
7775b425557eSmrg		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
777634977a2fSmrg		    | $EGREP "$match_pattern_regex" > /dev/null; then
7777fe24f8a2Smrg		    valid_a_lib=:
777834977a2fSmrg		  fi
777934977a2fSmrg		;;
778034977a2fSmrg		pass_all)
7781fe24f8a2Smrg		  valid_a_lib=:
778234977a2fSmrg		;;
778334977a2fSmrg	      esac
7784fe24f8a2Smrg	      if $valid_a_lib; then
7785fe24f8a2Smrg		echo
7786fe24f8a2Smrg		$ECHO "*** Warning: Linking the shared library $output against the"
7787fe24f8a2Smrg		$ECHO "*** static library $deplib is not portable!"
7788fe24f8a2Smrg		deplibs="$deplib $deplibs"
7789fe24f8a2Smrg	      else
7790b425557eSmrg		echo
779134977a2fSmrg		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
7792b425557eSmrg		echo "*** I have the capability to make that library automatically link in when"
7793b425557eSmrg		echo "*** you link to this library.  But I can only do this if you have a"
7794b425557eSmrg		echo "*** shared version of the library, which you do not appear to have"
7795b425557eSmrg		echo "*** because the file extensions .$libext of this argument makes me believe"
7796b425557eSmrg		echo "*** that it is just a static archive that I should not use here."
779734977a2fSmrg	      fi
779834977a2fSmrg	      ;;
779934977a2fSmrg	    esac
780034977a2fSmrg	    continue
780134977a2fSmrg	    ;;
780234977a2fSmrg	  prog)
7803fe24f8a2Smrg	    if test link != "$pass"; then
780434977a2fSmrg	      deplibs="$deplib $deplibs"
780534977a2fSmrg	    else
780634977a2fSmrg	      compile_deplibs="$deplib $compile_deplibs"
780734977a2fSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
780834977a2fSmrg	    fi
780934977a2fSmrg	    continue
781034977a2fSmrg	    ;;
781134977a2fSmrg	  esac # linkmode
781234977a2fSmrg	  ;; # *.$libext
781334977a2fSmrg	*.lo | *.$objext)
7814fe24f8a2Smrg	  if test conv = "$pass"; then
781534977a2fSmrg	    deplibs="$deplib $deplibs"
7816fe24f8a2Smrg	  elif test prog = "$linkmode"; then
7817fe24f8a2Smrg	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
781834977a2fSmrg	      # If there is no dlopen support or we're linking statically,
781934977a2fSmrg	      # we need to preload.
78203e72ca8cSmrg	      func_append newdlprefiles " $deplib"
782134977a2fSmrg	      compile_deplibs="$deplib $compile_deplibs"
782234977a2fSmrg	      finalize_deplibs="$deplib $finalize_deplibs"
782334977a2fSmrg	    else
78243e72ca8cSmrg	      func_append newdlfiles " $deplib"
782534977a2fSmrg	    fi
782634977a2fSmrg	  fi
782734977a2fSmrg	  continue
782834977a2fSmrg	  ;;
782934977a2fSmrg	%DEPLIBS%)
7830fe24f8a2Smrg	  alldeplibs=:
783134977a2fSmrg	  continue
783234977a2fSmrg	  ;;
783334977a2fSmrg	esac # case $deplib
783434977a2fSmrg
7835fe24f8a2Smrg	$found || test -f "$lib" \
7836fe24f8a2Smrg	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
783734977a2fSmrg
783834977a2fSmrg	# Check to see that this really is a libtool archive.
783934977a2fSmrg	func_lalib_unsafe_p "$lib" \
7840fe24f8a2Smrg	  || func_fatal_error "'$lib' is not a valid libtool archive"
784134977a2fSmrg
784234977a2fSmrg	func_dirname "$lib" "" "."
7843fe24f8a2Smrg	ladir=$func_dirname_result
784434977a2fSmrg
784534977a2fSmrg	dlname=
784634977a2fSmrg	dlopen=
784734977a2fSmrg	dlpreopen=
784834977a2fSmrg	libdir=
784934977a2fSmrg	library_names=
785034977a2fSmrg	old_library=
785134977a2fSmrg	inherited_linker_flags=
785234977a2fSmrg	# If the library was installed with an old release of libtool,
785334977a2fSmrg	# it will not redefine variables installed, or shouldnotlink
785434977a2fSmrg	installed=yes
785534977a2fSmrg	shouldnotlink=no
785634977a2fSmrg	avoidtemprpath=
785734977a2fSmrg
785834977a2fSmrg
785934977a2fSmrg	# Read the .la file
786034977a2fSmrg	func_source "$lib"
786134977a2fSmrg
786234977a2fSmrg	# Convert "-framework foo" to "foo.ltframework"
786334977a2fSmrg	if test -n "$inherited_linker_flags"; then
7864b425557eSmrg	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
786534977a2fSmrg	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
786634977a2fSmrg	    case " $new_inherited_linker_flags " in
786734977a2fSmrg	      *" $tmp_inherited_linker_flag "*) ;;
78683e72ca8cSmrg	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
786934977a2fSmrg	    esac
787034977a2fSmrg	  done
787134977a2fSmrg	fi
7872b425557eSmrg	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
7873fe24f8a2Smrg	if test lib,link = "$linkmode,$pass" ||
7874fe24f8a2Smrg	   test prog,scan = "$linkmode,$pass" ||
7875fe24f8a2Smrg	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
78763e72ca8cSmrg	  test -n "$dlopen" && func_append dlfiles " $dlopen"
78773e72ca8cSmrg	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
787834977a2fSmrg	fi
787934977a2fSmrg
7880fe24f8a2Smrg	if test conv = "$pass"; then
788134977a2fSmrg	  # Only check for convenience libraries
788234977a2fSmrg	  deplibs="$lib $deplibs"
788334977a2fSmrg	  if test -z "$libdir"; then
788434977a2fSmrg	    if test -z "$old_library"; then
7885fe24f8a2Smrg	      func_fatal_error "cannot find name of link library for '$lib'"
788634977a2fSmrg	    fi
788734977a2fSmrg	    # It is a libtool convenience library, so add in its objects.
78883e72ca8cSmrg	    func_append convenience " $ladir/$objdir/$old_library"
78893e72ca8cSmrg	    func_append old_convenience " $ladir/$objdir/$old_library"
7890fe24f8a2Smrg	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
7891fe24f8a2Smrg	    func_fatal_error "'$lib' is not a convenience library"
789234977a2fSmrg	  fi
789334977a2fSmrg	  tmp_libs=
789434977a2fSmrg	  for deplib in $dependency_libs; do
789534977a2fSmrg	    deplibs="$deplib $deplibs"
7896fe24f8a2Smrg	    if $opt_preserve_dup_deps; then
789734977a2fSmrg	      case "$tmp_libs " in
78983e72ca8cSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
789934977a2fSmrg	      esac
790034977a2fSmrg	    fi
79013e72ca8cSmrg	    func_append tmp_libs " $deplib"
790234977a2fSmrg	  done
790334977a2fSmrg	  continue
790434977a2fSmrg	fi # $pass = conv
790534977a2fSmrg
790634977a2fSmrg
790734977a2fSmrg	# Get the name of the library we link against.
790834977a2fSmrg	linklib=
79093e72ca8cSmrg	if test -n "$old_library" &&
7910fe24f8a2Smrg	   { test yes = "$prefer_static_libs" ||
7911fe24f8a2Smrg	     test built,no = "$prefer_static_libs,$installed"; }; then
79123e72ca8cSmrg	  linklib=$old_library
79133e72ca8cSmrg	else
79143e72ca8cSmrg	  for l in $old_library $library_names; do
7915fe24f8a2Smrg	    linklib=$l
79163e72ca8cSmrg	  done
79173e72ca8cSmrg	fi
791834977a2fSmrg	if test -z "$linklib"; then
7919fe24f8a2Smrg	  func_fatal_error "cannot find name of link library for '$lib'"
792034977a2fSmrg	fi
792134977a2fSmrg
792234977a2fSmrg	# This library was specified with -dlopen.
7923fe24f8a2Smrg	if test dlopen = "$pass"; then
7924fe24f8a2Smrg	  test -z "$libdir" \
7925fe24f8a2Smrg	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
792634977a2fSmrg	  if test -z "$dlname" ||
7927fe24f8a2Smrg	     test yes != "$dlopen_support" ||
7928fe24f8a2Smrg	     test no = "$build_libtool_libs"
7929fe24f8a2Smrg	  then
793034977a2fSmrg	    # If there is no dlname, no dlopen support or we're linking
793134977a2fSmrg	    # statically, we need to preload.  We also need to preload any
793234977a2fSmrg	    # dependent libraries so libltdl's deplib preloader doesn't
793334977a2fSmrg	    # bomb out in the load deplibs phase.
79343e72ca8cSmrg	    func_append dlprefiles " $lib $dependency_libs"
793534977a2fSmrg	  else
79363e72ca8cSmrg	    func_append newdlfiles " $lib"
793734977a2fSmrg	  fi
793834977a2fSmrg	  continue
793934977a2fSmrg	fi # $pass = dlopen
794034977a2fSmrg
794134977a2fSmrg	# We need an absolute path.
794234977a2fSmrg	case $ladir in
7943fe24f8a2Smrg	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
794434977a2fSmrg	*)
794534977a2fSmrg	  abs_ladir=`cd "$ladir" && pwd`
794634977a2fSmrg	  if test -z "$abs_ladir"; then
7947fe24f8a2Smrg	    func_warning "cannot determine absolute directory name of '$ladir'"
794834977a2fSmrg	    func_warning "passing it literally to the linker, although it might fail"
7949fe24f8a2Smrg	    abs_ladir=$ladir
795034977a2fSmrg	  fi
795134977a2fSmrg	  ;;
795234977a2fSmrg	esac
795334977a2fSmrg	func_basename "$lib"
7954fe24f8a2Smrg	laname=$func_basename_result
795534977a2fSmrg
795634977a2fSmrg	# Find the relevant object directory and library name.
7957fe24f8a2Smrg	if test yes = "$installed"; then
79583e72ca8cSmrg	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7959fe24f8a2Smrg	    func_warning "library '$lib' was moved."
7960fe24f8a2Smrg	    dir=$ladir
7961fe24f8a2Smrg	    absdir=$abs_ladir
7962fe24f8a2Smrg	    libdir=$abs_ladir
796334977a2fSmrg	  else
7964fe24f8a2Smrg	    dir=$lt_sysroot$libdir
7965fe24f8a2Smrg	    absdir=$lt_sysroot$libdir
796634977a2fSmrg	  fi
7967fe24f8a2Smrg	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
796834977a2fSmrg	else
796934977a2fSmrg	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
7970fe24f8a2Smrg	    dir=$ladir
7971fe24f8a2Smrg	    absdir=$abs_ladir
797234977a2fSmrg	    # Remove this search path later
79733e72ca8cSmrg	    func_append notinst_path " $abs_ladir"
797434977a2fSmrg	  else
7975fe24f8a2Smrg	    dir=$ladir/$objdir
7976fe24f8a2Smrg	    absdir=$abs_ladir/$objdir
797734977a2fSmrg	    # Remove this search path later
79783e72ca8cSmrg	    func_append notinst_path " $abs_ladir"
797934977a2fSmrg	  fi
798034977a2fSmrg	fi # $installed = yes
798134977a2fSmrg	func_stripname 'lib' '.la' "$laname"
798234977a2fSmrg	name=$func_stripname_result
798334977a2fSmrg
798434977a2fSmrg	# This library was specified with -dlpreopen.
7985fe24f8a2Smrg	if test dlpreopen = "$pass"; then
7986fe24f8a2Smrg	  if test -z "$libdir" && test prog = "$linkmode"; then
7987fe24f8a2Smrg	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
798834977a2fSmrg	  fi
7989fe24f8a2Smrg	  case $host in
79903e72ca8cSmrg	    # special handling for platforms with PE-DLLs.
79913e72ca8cSmrg	    *cygwin* | *mingw* | *cegcc* )
79923e72ca8cSmrg	      # Linker will automatically link against shared library if both
79933e72ca8cSmrg	      # static and shared are present.  Therefore, ensure we extract
79943e72ca8cSmrg	      # symbols from the import library if a shared library is present
79953e72ca8cSmrg	      # (otherwise, the dlopen module name will be incorrect).  We do
79963e72ca8cSmrg	      # this by putting the import library name into $newdlprefiles.
79973e72ca8cSmrg	      # We recover the dlopen module name by 'saving' the la file
79983e72ca8cSmrg	      # name in a special purpose variable, and (later) extracting the
79993e72ca8cSmrg	      # dlname from the la file.
80003e72ca8cSmrg	      if test -n "$dlname"; then
80013e72ca8cSmrg	        func_tr_sh "$dir/$linklib"
80023e72ca8cSmrg	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
80033e72ca8cSmrg	        func_append newdlprefiles " $dir/$linklib"
80043e72ca8cSmrg	      else
80053e72ca8cSmrg	        func_append newdlprefiles " $dir/$old_library"
80063e72ca8cSmrg	        # Keep a list of preopened convenience libraries to check
80073e72ca8cSmrg	        # that they are being used correctly in the link pass.
80083e72ca8cSmrg	        test -z "$libdir" && \
80093e72ca8cSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
80103e72ca8cSmrg	      fi
80113e72ca8cSmrg	    ;;
80123e72ca8cSmrg	    * )
80133e72ca8cSmrg	      # Prefer using a static library (so that no silly _DYNAMIC symbols
80143e72ca8cSmrg	      # are required to link).
80153e72ca8cSmrg	      if test -n "$old_library"; then
80163e72ca8cSmrg	        func_append newdlprefiles " $dir/$old_library"
80173e72ca8cSmrg	        # Keep a list of preopened convenience libraries to check
80183e72ca8cSmrg	        # that they are being used correctly in the link pass.
80193e72ca8cSmrg	        test -z "$libdir" && \
80203e72ca8cSmrg	          func_append dlpreconveniencelibs " $dir/$old_library"
80213e72ca8cSmrg	      # Otherwise, use the dlname, so that lt_dlopen finds it.
80223e72ca8cSmrg	      elif test -n "$dlname"; then
80233e72ca8cSmrg	        func_append newdlprefiles " $dir/$dlname"
80243e72ca8cSmrg	      else
80253e72ca8cSmrg	        func_append newdlprefiles " $dir/$linklib"
80263e72ca8cSmrg	      fi
80273e72ca8cSmrg	    ;;
80283e72ca8cSmrg	  esac
802934977a2fSmrg	fi # $pass = dlpreopen
803034977a2fSmrg
803134977a2fSmrg	if test -z "$libdir"; then
803234977a2fSmrg	  # Link the convenience library
8033fe24f8a2Smrg	  if test lib = "$linkmode"; then
803434977a2fSmrg	    deplibs="$dir/$old_library $deplibs"
8035fe24f8a2Smrg	  elif test prog,link = "$linkmode,$pass"; then
803634977a2fSmrg	    compile_deplibs="$dir/$old_library $compile_deplibs"
803734977a2fSmrg	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
803834977a2fSmrg	  else
803934977a2fSmrg	    deplibs="$lib $deplibs" # used for prog,scan pass
804034977a2fSmrg	  fi
804134977a2fSmrg	  continue
804234977a2fSmrg	fi
804334977a2fSmrg
804434977a2fSmrg
8045fe24f8a2Smrg	if test prog = "$linkmode" && test link != "$pass"; then
80463e72ca8cSmrg	  func_append newlib_search_path " $ladir"
804734977a2fSmrg	  deplibs="$lib $deplibs"
804834977a2fSmrg
8049fe24f8a2Smrg	  linkalldeplibs=false
8050fe24f8a2Smrg	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8051fe24f8a2Smrg	     test no = "$build_libtool_libs"; then
8052fe24f8a2Smrg	    linkalldeplibs=:
805334977a2fSmrg	  fi
805434977a2fSmrg
805534977a2fSmrg	  tmp_libs=
805634977a2fSmrg	  for deplib in $dependency_libs; do
805734977a2fSmrg	    case $deplib in
805834977a2fSmrg	    -L*) func_stripname '-L' '' "$deplib"
80593e72ca8cSmrg	         func_resolve_sysroot "$func_stripname_result"
80603e72ca8cSmrg	         func_append newlib_search_path " $func_resolve_sysroot_result"
806134977a2fSmrg		 ;;
806234977a2fSmrg	    esac
806334977a2fSmrg	    # Need to link against all dependency_libs?
8064fe24f8a2Smrg	    if $linkalldeplibs; then
806534977a2fSmrg	      deplibs="$deplib $deplibs"
806634977a2fSmrg	    else
806734977a2fSmrg	      # Need to hardcode shared library paths
806834977a2fSmrg	      # or/and link against static libraries
806934977a2fSmrg	      newdependency_libs="$deplib $newdependency_libs"
807034977a2fSmrg	    fi
8071fe24f8a2Smrg	    if $opt_preserve_dup_deps; then
807234977a2fSmrg	      case "$tmp_libs " in
80733e72ca8cSmrg	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
807434977a2fSmrg	      esac
807534977a2fSmrg	    fi
80763e72ca8cSmrg	    func_append tmp_libs " $deplib"
807734977a2fSmrg	  done # for deplib
807834977a2fSmrg	  continue
807934977a2fSmrg	fi # $linkmode = prog...
808034977a2fSmrg
8081fe24f8a2Smrg	if test prog,link = "$linkmode,$pass"; then
808234977a2fSmrg	  if test -n "$library_names" &&
8083fe24f8a2Smrg	     { { test no = "$prefer_static_libs" ||
8084fe24f8a2Smrg	         test built,yes = "$prefer_static_libs,$installed"; } ||
808534977a2fSmrg	       test -z "$old_library"; }; then
808634977a2fSmrg	    # We need to hardcode the library path
8087fe24f8a2Smrg	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
808834977a2fSmrg	      # Make sure the rpath contains only unique directories.
8089fe24f8a2Smrg	      case $temp_rpath: in
809034977a2fSmrg	      *"$absdir:"*) ;;
80913e72ca8cSmrg	      *) func_append temp_rpath "$absdir:" ;;
809234977a2fSmrg	      esac
809334977a2fSmrg	    fi
809434977a2fSmrg
809534977a2fSmrg	    # Hardcode the library path.
809634977a2fSmrg	    # Skip directories that are in the system default run-time
809734977a2fSmrg	    # search path.
809834977a2fSmrg	    case " $sys_lib_dlsearch_path " in
809934977a2fSmrg	    *" $absdir "*) ;;
810034977a2fSmrg	    *)
810134977a2fSmrg	      case "$compile_rpath " in
810234977a2fSmrg	      *" $absdir "*) ;;
81033e72ca8cSmrg	      *) func_append compile_rpath " $absdir" ;;
810434977a2fSmrg	      esac
810534977a2fSmrg	      ;;
810634977a2fSmrg	    esac
810734977a2fSmrg	    case " $sys_lib_dlsearch_path " in
810834977a2fSmrg	    *" $libdir "*) ;;
810934977a2fSmrg	    *)
811034977a2fSmrg	      case "$finalize_rpath " in
811134977a2fSmrg	      *" $libdir "*) ;;
81123e72ca8cSmrg	      *) func_append finalize_rpath " $libdir" ;;
811334977a2fSmrg	      esac
811434977a2fSmrg	      ;;
811534977a2fSmrg	    esac
811634977a2fSmrg	  fi # $linkmode,$pass = prog,link...
811734977a2fSmrg
8118fe24f8a2Smrg	  if $alldeplibs &&
8119fe24f8a2Smrg	     { test pass_all = "$deplibs_check_method" ||
8120fe24f8a2Smrg	       { test yes = "$build_libtool_libs" &&
812134977a2fSmrg		 test -n "$library_names"; }; }; then
812234977a2fSmrg	    # We only need to search for static libraries
812334977a2fSmrg	    continue
812434977a2fSmrg	  fi
812534977a2fSmrg	fi
812634977a2fSmrg
812734977a2fSmrg	link_static=no # Whether the deplib will be linked statically
812834977a2fSmrg	use_static_libs=$prefer_static_libs
8129fe24f8a2Smrg	if test built = "$use_static_libs" && test yes = "$installed"; then
813034977a2fSmrg	  use_static_libs=no
813134977a2fSmrg	fi
813234977a2fSmrg	if test -n "$library_names" &&
8133fe24f8a2Smrg	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
813434977a2fSmrg	  case $host in
8135fe24f8a2Smrg	  *cygwin* | *mingw* | *cegcc* | *os2*)
813634977a2fSmrg	      # No point in relinking DLLs because paths are not encoded
81373e72ca8cSmrg	      func_append notinst_deplibs " $lib"
813834977a2fSmrg	      need_relink=no
813934977a2fSmrg	    ;;
814034977a2fSmrg	  *)
8141fe24f8a2Smrg	    if test no = "$installed"; then
81423e72ca8cSmrg	      func_append notinst_deplibs " $lib"
814334977a2fSmrg	      need_relink=yes
814434977a2fSmrg	    fi
814534977a2fSmrg	    ;;
814634977a2fSmrg	  esac
814734977a2fSmrg	  # This is a shared library
814834977a2fSmrg
814934977a2fSmrg	  # Warn about portability, can't link against -module's on some
815034977a2fSmrg	  # systems (darwin).  Don't bleat about dlopened modules though!
8151fe24f8a2Smrg	  dlopenmodule=
815234977a2fSmrg	  for dlpremoduletest in $dlprefiles; do
815334977a2fSmrg	    if test "X$dlpremoduletest" = "X$lib"; then
8154fe24f8a2Smrg	      dlopenmodule=$dlpremoduletest
815534977a2fSmrg	      break
815634977a2fSmrg	    fi
815734977a2fSmrg	  done
8158fe24f8a2Smrg	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
8159b425557eSmrg	    echo
8160fe24f8a2Smrg	    if test prog = "$linkmode"; then
816134977a2fSmrg	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
816234977a2fSmrg	    else
816334977a2fSmrg	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
816434977a2fSmrg	    fi
816534977a2fSmrg	    $ECHO "*** $linklib is not portable!"
816634977a2fSmrg	  fi
8167fe24f8a2Smrg	  if test lib = "$linkmode" &&
8168fe24f8a2Smrg	     test yes = "$hardcode_into_libs"; then
816934977a2fSmrg	    # Hardcode the library path.
817034977a2fSmrg	    # Skip directories that are in the system default run-time
817134977a2fSmrg	    # search path.
817234977a2fSmrg	    case " $sys_lib_dlsearch_path " in
817334977a2fSmrg	    *" $absdir "*) ;;
817434977a2fSmrg	    *)
817534977a2fSmrg	      case "$compile_rpath " in
817634977a2fSmrg	      *" $absdir "*) ;;
81773e72ca8cSmrg	      *) func_append compile_rpath " $absdir" ;;
817834977a2fSmrg	      esac
817934977a2fSmrg	      ;;
818034977a2fSmrg	    esac
818134977a2fSmrg	    case " $sys_lib_dlsearch_path " in
818234977a2fSmrg	    *" $libdir "*) ;;
818334977a2fSmrg	    *)
818434977a2fSmrg	      case "$finalize_rpath " in
818534977a2fSmrg	      *" $libdir "*) ;;
81863e72ca8cSmrg	      *) func_append finalize_rpath " $libdir" ;;
818734977a2fSmrg	      esac
818834977a2fSmrg	      ;;
818934977a2fSmrg	    esac
819034977a2fSmrg	  fi
819134977a2fSmrg
819234977a2fSmrg	  if test -n "$old_archive_from_expsyms_cmds"; then
819334977a2fSmrg	    # figure out the soname
819434977a2fSmrg	    set dummy $library_names
819534977a2fSmrg	    shift
8196fe24f8a2Smrg	    realname=$1
819734977a2fSmrg	    shift
819834977a2fSmrg	    libname=`eval "\\$ECHO \"$libname_spec\""`
819934977a2fSmrg	    # use dlname if we got it. it's perfectly good, no?
820034977a2fSmrg	    if test -n "$dlname"; then
8201fe24f8a2Smrg	      soname=$dlname
820234977a2fSmrg	    elif test -n "$soname_spec"; then
820334977a2fSmrg	      # bleh windows
820434977a2fSmrg	      case $host in
8205fe24f8a2Smrg	      *cygwin* | mingw* | *cegcc* | *os2*)
820634977a2fSmrg	        func_arith $current - $age
820734977a2fSmrg		major=$func_arith_result
8208fe24f8a2Smrg		versuffix=-$major
820934977a2fSmrg		;;
821034977a2fSmrg	      esac
821134977a2fSmrg	      eval soname=\"$soname_spec\"
821234977a2fSmrg	    else
8213fe24f8a2Smrg	      soname=$realname
821434977a2fSmrg	    fi
821534977a2fSmrg
821634977a2fSmrg	    # Make a new name for the extract_expsyms_cmds to use
8217fe24f8a2Smrg	    soroot=$soname
821834977a2fSmrg	    func_basename "$soroot"
8219fe24f8a2Smrg	    soname=$func_basename_result
822034977a2fSmrg	    func_stripname 'lib' '.dll' "$soname"
822134977a2fSmrg	    newlib=libimp-$func_stripname_result.a
822234977a2fSmrg
822334977a2fSmrg	    # If the library has no export list, then create one now
822434977a2fSmrg	    if test -f "$output_objdir/$soname-def"; then :
822534977a2fSmrg	    else
8226fe24f8a2Smrg	      func_verbose "extracting exported symbol list from '$soname'"
822734977a2fSmrg	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
822834977a2fSmrg	    fi
822934977a2fSmrg
823034977a2fSmrg	    # Create $newlib
823134977a2fSmrg	    if test -f "$output_objdir/$newlib"; then :; else
8232fe24f8a2Smrg	      func_verbose "generating import library for '$soname'"
823334977a2fSmrg	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
823434977a2fSmrg	    fi
823534977a2fSmrg	    # make sure the library variables are pointing to the new library
823634977a2fSmrg	    dir=$output_objdir
823734977a2fSmrg	    linklib=$newlib
823834977a2fSmrg	  fi # test -n "$old_archive_from_expsyms_cmds"
823934977a2fSmrg
8240fe24f8a2Smrg	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
824134977a2fSmrg	    add_shlibpath=
824234977a2fSmrg	    add_dir=
824334977a2fSmrg	    add=
824434977a2fSmrg	    lib_linked=yes
824534977a2fSmrg	    case $hardcode_action in
824634977a2fSmrg	    immediate | unsupported)
8247fe24f8a2Smrg	      if test no = "$hardcode_direct"; then
8248fe24f8a2Smrg		add=$dir/$linklib
824934977a2fSmrg		case $host in
8250fe24f8a2Smrg		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8251fe24f8a2Smrg		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
825234977a2fSmrg		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8253fe24f8a2Smrg		    *-*-unixware7*) add_dir=-L$dir ;;
825434977a2fSmrg		  *-*-darwin* )
8255fe24f8a2Smrg		    # if the lib is a (non-dlopened) module then we cannot
825634977a2fSmrg		    # link against it, someone is ignoring the earlier warnings
825734977a2fSmrg		    if /usr/bin/file -L $add 2> /dev/null |
8258fe24f8a2Smrg			 $GREP ": [^:]* bundle" >/dev/null; then
825934977a2fSmrg		      if test "X$dlopenmodule" != "X$lib"; then
826034977a2fSmrg			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
8261fe24f8a2Smrg			if test -z "$old_library"; then
8262b425557eSmrg			  echo
8263b425557eSmrg			  echo "*** And there doesn't seem to be a static archive available"
8264b425557eSmrg			  echo "*** The link will probably fail, sorry"
826534977a2fSmrg			else
8266fe24f8a2Smrg			  add=$dir/$old_library
826734977a2fSmrg			fi
826834977a2fSmrg		      elif test -n "$old_library"; then
8269fe24f8a2Smrg			add=$dir/$old_library
827034977a2fSmrg		      fi
827134977a2fSmrg		    fi
827234977a2fSmrg		esac
8273fe24f8a2Smrg	      elif test no = "$hardcode_minus_L"; then
827434977a2fSmrg		case $host in
8275fe24f8a2Smrg		*-*-sunos*) add_shlibpath=$dir ;;
827634977a2fSmrg		esac
8277fe24f8a2Smrg		add_dir=-L$dir
8278fe24f8a2Smrg		add=-l$name
8279fe24f8a2Smrg	      elif test no = "$hardcode_shlibpath_var"; then
8280fe24f8a2Smrg		add_shlibpath=$dir
8281fe24f8a2Smrg		add=-l$name
828234977a2fSmrg	      else
828334977a2fSmrg		lib_linked=no
828434977a2fSmrg	      fi
828534977a2fSmrg	      ;;
828634977a2fSmrg	    relink)
8287fe24f8a2Smrg	      if test yes = "$hardcode_direct" &&
8288fe24f8a2Smrg	         test no = "$hardcode_direct_absolute"; then
8289fe24f8a2Smrg		add=$dir/$linklib
8290fe24f8a2Smrg	      elif test yes = "$hardcode_minus_L"; then
8291fe24f8a2Smrg		add_dir=-L$absdir
829234977a2fSmrg		# Try looking first in the location we're being installed to.
829334977a2fSmrg		if test -n "$inst_prefix_dir"; then
829434977a2fSmrg		  case $libdir in
829534977a2fSmrg		    [\\/]*)
82963e72ca8cSmrg		      func_append add_dir " -L$inst_prefix_dir$libdir"
829734977a2fSmrg		      ;;
829834977a2fSmrg		  esac
829934977a2fSmrg		fi
8300fe24f8a2Smrg		add=-l$name
8301fe24f8a2Smrg	      elif test yes = "$hardcode_shlibpath_var"; then
8302fe24f8a2Smrg		add_shlibpath=$dir
8303fe24f8a2Smrg		add=-l$name
830434977a2fSmrg	      else
830534977a2fSmrg		lib_linked=no
830634977a2fSmrg	      fi
830734977a2fSmrg	      ;;
830834977a2fSmrg	    *) lib_linked=no ;;
830934977a2fSmrg	    esac
831034977a2fSmrg
8311fe24f8a2Smrg	    if test yes != "$lib_linked"; then
831234977a2fSmrg	      func_fatal_configuration "unsupported hardcode properties"
831334977a2fSmrg	    fi
831434977a2fSmrg
831534977a2fSmrg	    if test -n "$add_shlibpath"; then
831634977a2fSmrg	      case :$compile_shlibpath: in
831734977a2fSmrg	      *":$add_shlibpath:"*) ;;
83183e72ca8cSmrg	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
831934977a2fSmrg	      esac
832034977a2fSmrg	    fi
8321fe24f8a2Smrg	    if test prog = "$linkmode"; then
832234977a2fSmrg	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
832334977a2fSmrg	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
832434977a2fSmrg	    else
832534977a2fSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
832634977a2fSmrg	      test -n "$add" && deplibs="$add $deplibs"
8327fe24f8a2Smrg	      if test yes != "$hardcode_direct" &&
8328fe24f8a2Smrg		 test yes != "$hardcode_minus_L" &&
8329fe24f8a2Smrg		 test yes = "$hardcode_shlibpath_var"; then
833034977a2fSmrg		case :$finalize_shlibpath: in
833134977a2fSmrg		*":$libdir:"*) ;;
83323e72ca8cSmrg		*) func_append finalize_shlibpath "$libdir:" ;;
833334977a2fSmrg		esac
833434977a2fSmrg	      fi
833534977a2fSmrg	    fi
833634977a2fSmrg	  fi
833734977a2fSmrg
8338fe24f8a2Smrg	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
833934977a2fSmrg	    add_shlibpath=
834034977a2fSmrg	    add_dir=
834134977a2fSmrg	    add=
834234977a2fSmrg	    # Finalize command for both is simple: just hardcode it.
8343fe24f8a2Smrg	    if test yes = "$hardcode_direct" &&
8344fe24f8a2Smrg	       test no = "$hardcode_direct_absolute"; then
8345fe24f8a2Smrg	      add=$libdir/$linklib
8346fe24f8a2Smrg	    elif test yes = "$hardcode_minus_L"; then
8347fe24f8a2Smrg	      add_dir=-L$libdir
8348fe24f8a2Smrg	      add=-l$name
8349fe24f8a2Smrg	    elif test yes = "$hardcode_shlibpath_var"; then
835034977a2fSmrg	      case :$finalize_shlibpath: in
835134977a2fSmrg	      *":$libdir:"*) ;;
83523e72ca8cSmrg	      *) func_append finalize_shlibpath "$libdir:" ;;
835334977a2fSmrg	      esac
8354fe24f8a2Smrg	      add=-l$name
8355fe24f8a2Smrg	    elif test yes = "$hardcode_automatic"; then
835634977a2fSmrg	      if test -n "$inst_prefix_dir" &&
8357fe24f8a2Smrg		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8358fe24f8a2Smrg		add=$inst_prefix_dir$libdir/$linklib
835934977a2fSmrg	      else
8360fe24f8a2Smrg		add=$libdir/$linklib
836134977a2fSmrg	      fi
836234977a2fSmrg	    else
836334977a2fSmrg	      # We cannot seem to hardcode it, guess we'll fake it.
8364fe24f8a2Smrg	      add_dir=-L$libdir
836534977a2fSmrg	      # Try looking first in the location we're being installed to.
836634977a2fSmrg	      if test -n "$inst_prefix_dir"; then
836734977a2fSmrg		case $libdir in
836834977a2fSmrg		  [\\/]*)
83693e72ca8cSmrg		    func_append add_dir " -L$inst_prefix_dir$libdir"
837034977a2fSmrg		    ;;
837134977a2fSmrg		esac
837234977a2fSmrg	      fi
8373fe24f8a2Smrg	      add=-l$name
837434977a2fSmrg	    fi
837534977a2fSmrg
8376fe24f8a2Smrg	    if test prog = "$linkmode"; then
837734977a2fSmrg	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
837834977a2fSmrg	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
837934977a2fSmrg	    else
838034977a2fSmrg	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
838134977a2fSmrg	      test -n "$add" && deplibs="$add $deplibs"
838234977a2fSmrg	    fi
838334977a2fSmrg	  fi
8384fe24f8a2Smrg	elif test prog = "$linkmode"; then
838534977a2fSmrg	  # Here we assume that one of hardcode_direct or hardcode_minus_L
838634977a2fSmrg	  # is not unsupported.  This is valid on all known static and
838734977a2fSmrg	  # shared platforms.
8388fe24f8a2Smrg	  if test unsupported != "$hardcode_direct"; then
8389fe24f8a2Smrg	    test -n "$old_library" && linklib=$old_library
839034977a2fSmrg	    compile_deplibs="$dir/$linklib $compile_deplibs"
839134977a2fSmrg	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
839234977a2fSmrg	  else
839334977a2fSmrg	    compile_deplibs="-l$name -L$dir $compile_deplibs"
839434977a2fSmrg	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
839534977a2fSmrg	  fi
8396fe24f8a2Smrg	elif test yes = "$build_libtool_libs"; then
839734977a2fSmrg	  # Not a shared library
8398fe24f8a2Smrg	  if test pass_all != "$deplibs_check_method"; then
839934977a2fSmrg	    # We're trying link a shared library against a static one
840034977a2fSmrg	    # but the system doesn't support it.
840134977a2fSmrg
840234977a2fSmrg	    # Just print a warning and add the library to dependency_libs so
840334977a2fSmrg	    # that the program can be linked against the static library.
8404b425557eSmrg	    echo
8405fe24f8a2Smrg	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
8406b425557eSmrg	    echo "*** I have the capability to make that library automatically link in when"
8407b425557eSmrg	    echo "*** you link to this library.  But I can only do this if you have a"
8408b425557eSmrg	    echo "*** shared version of the library, which you do not appear to have."
8409fe24f8a2Smrg	    if test yes = "$module"; then
8410b425557eSmrg	      echo "*** But as you try to build a module library, libtool will still create "
8411b425557eSmrg	      echo "*** a static module, that should work as long as the dlopening application"
8412b425557eSmrg	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
841334977a2fSmrg	      if test -z "$global_symbol_pipe"; then
8414b425557eSmrg		echo
8415b425557eSmrg		echo "*** However, this would only work if libtool was able to extract symbol"
8416fe24f8a2Smrg		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
8417b425557eSmrg		echo "*** not find such a program.  So, this module is probably useless."
8418fe24f8a2Smrg		echo "*** 'nm' from GNU binutils and a full rebuild may help."
841934977a2fSmrg	      fi
8420fe24f8a2Smrg	      if test no = "$build_old_libs"; then
842134977a2fSmrg		build_libtool_libs=module
842234977a2fSmrg		build_old_libs=yes
842334977a2fSmrg	      else
842434977a2fSmrg		build_libtool_libs=no
842534977a2fSmrg	      fi
842634977a2fSmrg	    fi
842734977a2fSmrg	  else
842834977a2fSmrg	    deplibs="$dir/$old_library $deplibs"
842934977a2fSmrg	    link_static=yes
843034977a2fSmrg	  fi
843134977a2fSmrg	fi # link shared/static library?
843234977a2fSmrg
8433fe24f8a2Smrg	if test lib = "$linkmode"; then
843434977a2fSmrg	  if test -n "$dependency_libs" &&
8435fe24f8a2Smrg	     { test yes != "$hardcode_into_libs" ||
8436fe24f8a2Smrg	       test yes = "$build_old_libs" ||
8437fe24f8a2Smrg	       test yes = "$link_static"; }; then
843834977a2fSmrg	    # Extract -R from dependency_libs
843934977a2fSmrg	    temp_deplibs=
844034977a2fSmrg	    for libdir in $dependency_libs; do
844134977a2fSmrg	      case $libdir in
844234977a2fSmrg	      -R*) func_stripname '-R' '' "$libdir"
844334977a2fSmrg	           temp_xrpath=$func_stripname_result
844434977a2fSmrg		   case " $xrpath " in
844534977a2fSmrg		   *" $temp_xrpath "*) ;;
84463e72ca8cSmrg		   *) func_append xrpath " $temp_xrpath";;
844734977a2fSmrg		   esac;;
84483e72ca8cSmrg	      *) func_append temp_deplibs " $libdir";;
844934977a2fSmrg	      esac
845034977a2fSmrg	    done
8451fe24f8a2Smrg	    dependency_libs=$temp_deplibs
845234977a2fSmrg	  fi
845334977a2fSmrg
84543e72ca8cSmrg	  func_append newlib_search_path " $absdir"
845534977a2fSmrg	  # Link against this library
8456fe24f8a2Smrg	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
845734977a2fSmrg	  # ... and its dependency_libs
845834977a2fSmrg	  tmp_libs=
845934977a2fSmrg	  for deplib in $dependency_libs; do
846034977a2fSmrg	    newdependency_libs="$deplib $newdependency_libs"
84613e72ca8cSmrg	    case $deplib in
84623e72ca8cSmrg              -L*) func_stripname '-L' '' "$deplib"
84633e72ca8cSmrg                   func_resolve_sysroot "$func_stripname_result";;
84643e72ca8cSmrg              *) func_resolve_sysroot "$deplib" ;;
84653e72ca8cSmrg            esac
8466fe24f8a2Smrg	    if $opt_preserve_dup_deps; then
846734977a2fSmrg	      case "$tmp_libs " in
84683e72ca8cSmrg	      *" $func_resolve_sysroot_result "*)
84693e72ca8cSmrg                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
847034977a2fSmrg	      esac
847134977a2fSmrg	    fi
84723e72ca8cSmrg	    func_append tmp_libs " $func_resolve_sysroot_result"
847334977a2fSmrg	  done
847434977a2fSmrg
8475fe24f8a2Smrg	  if test no != "$link_all_deplibs"; then
847634977a2fSmrg	    # Add the search paths of all dependency libraries
847734977a2fSmrg	    for deplib in $dependency_libs; do
8478b425557eSmrg	      path=
847934977a2fSmrg	      case $deplib in
8480fe24f8a2Smrg	      -L*) path=$deplib ;;
848134977a2fSmrg	      *.la)
84823e72ca8cSmrg	        func_resolve_sysroot "$deplib"
84833e72ca8cSmrg	        deplib=$func_resolve_sysroot_result
848434977a2fSmrg	        func_dirname "$deplib" "" "."
84853e72ca8cSmrg		dir=$func_dirname_result
848634977a2fSmrg		# We need an absolute path.
848734977a2fSmrg		case $dir in
8488fe24f8a2Smrg		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
848934977a2fSmrg		*)
849034977a2fSmrg		  absdir=`cd "$dir" && pwd`
849134977a2fSmrg		  if test -z "$absdir"; then
8492fe24f8a2Smrg		    func_warning "cannot determine absolute directory name of '$dir'"
8493fe24f8a2Smrg		    absdir=$dir
849434977a2fSmrg		  fi
849534977a2fSmrg		  ;;
849634977a2fSmrg		esac
849734977a2fSmrg		if $GREP "^installed=no" $deplib > /dev/null; then
849834977a2fSmrg		case $host in
849934977a2fSmrg		*-*-darwin*)
850034977a2fSmrg		  depdepl=
8501fe24f8a2Smrg		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
8502fe24f8a2Smrg		  if test -n "$deplibrary_names"; then
8503fe24f8a2Smrg		    for tmp in $deplibrary_names; do
850434977a2fSmrg		      depdepl=$tmp
850534977a2fSmrg		    done
8506fe24f8a2Smrg		    if test -f "$absdir/$objdir/$depdepl"; then
8507fe24f8a2Smrg		      depdepl=$absdir/$objdir/$depdepl
8508fe24f8a2Smrg		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
850934977a2fSmrg                      if test -z "$darwin_install_name"; then
8510fe24f8a2Smrg                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
851134977a2fSmrg                      fi
8512fe24f8a2Smrg		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8513fe24f8a2Smrg		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
851434977a2fSmrg		      path=
851534977a2fSmrg		    fi
851634977a2fSmrg		  fi
851734977a2fSmrg		  ;;
851834977a2fSmrg		*)
8519fe24f8a2Smrg		  path=-L$absdir/$objdir
852034977a2fSmrg		  ;;
852134977a2fSmrg		esac
852234977a2fSmrg		else
8523fe24f8a2Smrg		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
852434977a2fSmrg		  test -z "$libdir" && \
8525fe24f8a2Smrg		    func_fatal_error "'$deplib' is not a valid libtool archive"
852634977a2fSmrg		  test "$absdir" != "$libdir" && \
8527fe24f8a2Smrg		    func_warning "'$deplib' seems to be moved"
852834977a2fSmrg
8529fe24f8a2Smrg		  path=-L$absdir
853034977a2fSmrg		fi
853134977a2fSmrg		;;
853234977a2fSmrg	      esac
853334977a2fSmrg	      case " $deplibs " in
853434977a2fSmrg	      *" $path "*) ;;
853534977a2fSmrg	      *) deplibs="$path $deplibs" ;;
853634977a2fSmrg	      esac
853734977a2fSmrg	    done
853834977a2fSmrg	  fi # link_all_deplibs != no
853934977a2fSmrg	fi # linkmode = lib
854034977a2fSmrg      done # for deplib in $libs
8541fe24f8a2Smrg      if test link = "$pass"; then
8542fe24f8a2Smrg	if test prog = "$linkmode"; then
854334977a2fSmrg	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
854434977a2fSmrg	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
854534977a2fSmrg	else
8546b425557eSmrg	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
854734977a2fSmrg	fi
854834977a2fSmrg      fi
8549fe24f8a2Smrg      dependency_libs=$newdependency_libs
8550fe24f8a2Smrg      if test dlpreopen = "$pass"; then
855134977a2fSmrg	# Link the dlpreopened libraries before other libraries
855234977a2fSmrg	for deplib in $save_deplibs; do
855334977a2fSmrg	  deplibs="$deplib $deplibs"
855434977a2fSmrg	done
855534977a2fSmrg      fi
8556fe24f8a2Smrg      if test dlopen != "$pass"; then
8557fe24f8a2Smrg	test conv = "$pass" || {
855834977a2fSmrg	  # Make sure lib_search_path contains only unique directories.
855934977a2fSmrg	  lib_search_path=
856034977a2fSmrg	  for dir in $newlib_search_path; do
856134977a2fSmrg	    case "$lib_search_path " in
856234977a2fSmrg	    *" $dir "*) ;;
85633e72ca8cSmrg	    *) func_append lib_search_path " $dir" ;;
856434977a2fSmrg	    esac
856534977a2fSmrg	  done
856634977a2fSmrg	  newlib_search_path=
8567fe24f8a2Smrg	}
856834977a2fSmrg
8569fe24f8a2Smrg	if test prog,link = "$linkmode,$pass"; then
857034977a2fSmrg	  vars="compile_deplibs finalize_deplibs"
8571fe24f8a2Smrg	else
8572fe24f8a2Smrg	  vars=deplibs
857334977a2fSmrg	fi
857434977a2fSmrg	for var in $vars dependency_libs; do
857534977a2fSmrg	  # Add libraries to $var in reverse order
857634977a2fSmrg	  eval tmp_libs=\"\$$var\"
857734977a2fSmrg	  new_libs=
857834977a2fSmrg	  for deplib in $tmp_libs; do
857934977a2fSmrg	    # FIXME: Pedantically, this is the right thing to do, so
858034977a2fSmrg	    #        that some nasty dependency loop isn't accidentally
858134977a2fSmrg	    #        broken:
858234977a2fSmrg	    #new_libs="$deplib $new_libs"
858334977a2fSmrg	    # Pragmatically, this seems to cause very few problems in
858434977a2fSmrg	    # practice:
858534977a2fSmrg	    case $deplib in
858634977a2fSmrg	    -L*) new_libs="$deplib $new_libs" ;;
858734977a2fSmrg	    -R*) ;;
858834977a2fSmrg	    *)
858934977a2fSmrg	      # And here is the reason: when a library appears more
859034977a2fSmrg	      # than once as an explicit dependence of a library, or
859134977a2fSmrg	      # is implicitly linked in more than once by the
859234977a2fSmrg	      # compiler, it is considered special, and multiple
859334977a2fSmrg	      # occurrences thereof are not removed.  Compare this
859434977a2fSmrg	      # with having the same library being listed as a
859534977a2fSmrg	      # dependency of multiple other libraries: in this case,
859634977a2fSmrg	      # we know (pedantically, we assume) the library does not
859734977a2fSmrg	      # need to be listed more than once, so we keep only the
859834977a2fSmrg	      # last copy.  This is not always right, but it is rare
859934977a2fSmrg	      # enough that we require users that really mean to play
860034977a2fSmrg	      # such unportable linking tricks to link the library
860134977a2fSmrg	      # using -Wl,-lname, so that libtool does not consider it
860234977a2fSmrg	      # for duplicate removal.
860334977a2fSmrg	      case " $specialdeplibs " in
860434977a2fSmrg	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
860534977a2fSmrg	      *)
860634977a2fSmrg		case " $new_libs " in
860734977a2fSmrg		*" $deplib "*) ;;
860834977a2fSmrg		*) new_libs="$deplib $new_libs" ;;
860934977a2fSmrg		esac
861034977a2fSmrg		;;
861134977a2fSmrg	      esac
861234977a2fSmrg	      ;;
861334977a2fSmrg	    esac
861434977a2fSmrg	  done
861534977a2fSmrg	  tmp_libs=
861634977a2fSmrg	  for deplib in $new_libs; do
861734977a2fSmrg	    case $deplib in
861834977a2fSmrg	    -L*)
861934977a2fSmrg	      case " $tmp_libs " in
862034977a2fSmrg	      *" $deplib "*) ;;
86213e72ca8cSmrg	      *) func_append tmp_libs " $deplib" ;;
862234977a2fSmrg	      esac
862334977a2fSmrg	      ;;
86243e72ca8cSmrg	    *) func_append tmp_libs " $deplib" ;;
862534977a2fSmrg	    esac
862634977a2fSmrg	  done
862734977a2fSmrg	  eval $var=\"$tmp_libs\"
862834977a2fSmrg	done # for var
862934977a2fSmrg      fi
8630fe24f8a2Smrg
8631fe24f8a2Smrg      # Add Sun CC postdeps if required:
8632fe24f8a2Smrg      test CXX = "$tagname" && {
8633fe24f8a2Smrg        case $host_os in
8634fe24f8a2Smrg        linux*)
8635fe24f8a2Smrg          case `$CC -V 2>&1 | sed 5q` in
8636fe24f8a2Smrg          *Sun\ C*) # Sun C++ 5.9
8637fe24f8a2Smrg            func_suncc_cstd_abi
8638fe24f8a2Smrg
8639fe24f8a2Smrg            if test no != "$suncc_use_cstd_abi"; then
8640fe24f8a2Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8641fe24f8a2Smrg            fi
8642fe24f8a2Smrg            ;;
8643fe24f8a2Smrg          esac
8644fe24f8a2Smrg          ;;
8645fe24f8a2Smrg
8646fe24f8a2Smrg        solaris*)
8647fe24f8a2Smrg          func_cc_basename "$CC"
8648fe24f8a2Smrg          case $func_cc_basename_result in
8649fe24f8a2Smrg          CC* | sunCC*)
8650fe24f8a2Smrg            func_suncc_cstd_abi
8651fe24f8a2Smrg
8652fe24f8a2Smrg            if test no != "$suncc_use_cstd_abi"; then
8653fe24f8a2Smrg              func_append postdeps ' -library=Cstd -library=Crun'
8654fe24f8a2Smrg            fi
8655fe24f8a2Smrg            ;;
8656fe24f8a2Smrg          esac
8657fe24f8a2Smrg          ;;
8658fe24f8a2Smrg        esac
8659fe24f8a2Smrg      }
8660fe24f8a2Smrg
866134977a2fSmrg      # Last step: remove runtime libs from dependency_libs
866234977a2fSmrg      # (they stay in deplibs)
866334977a2fSmrg      tmp_libs=
8664fe24f8a2Smrg      for i in $dependency_libs; do
866534977a2fSmrg	case " $predeps $postdeps $compiler_lib_search_path " in
866634977a2fSmrg	*" $i "*)
8667fe24f8a2Smrg	  i=
866834977a2fSmrg	  ;;
866934977a2fSmrg	esac
8670fe24f8a2Smrg	if test -n "$i"; then
86713e72ca8cSmrg	  func_append tmp_libs " $i"
867234977a2fSmrg	fi
867334977a2fSmrg      done
867434977a2fSmrg      dependency_libs=$tmp_libs
867534977a2fSmrg    done # for pass
8676fe24f8a2Smrg    if test prog = "$linkmode"; then
8677fe24f8a2Smrg      dlfiles=$newdlfiles
867834977a2fSmrg    fi
8679fe24f8a2Smrg    if test prog = "$linkmode" || test lib = "$linkmode"; then
8680fe24f8a2Smrg      dlprefiles=$newdlprefiles
868134977a2fSmrg    fi
868234977a2fSmrg
868334977a2fSmrg    case $linkmode in
868434977a2fSmrg    oldlib)
8685fe24f8a2Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8686fe24f8a2Smrg	func_warning "'-dlopen' is ignored for archives"
868734977a2fSmrg      fi
868834977a2fSmrg
868934977a2fSmrg      case " $deplibs" in
869034977a2fSmrg      *\ -l* | *\ -L*)
8691fe24f8a2Smrg	func_warning "'-l' and '-L' are ignored for archives" ;;
869234977a2fSmrg      esac
869334977a2fSmrg
869434977a2fSmrg      test -n "$rpath" && \
8695fe24f8a2Smrg	func_warning "'-rpath' is ignored for archives"
869634977a2fSmrg
869734977a2fSmrg      test -n "$xrpath" && \
8698fe24f8a2Smrg	func_warning "'-R' is ignored for archives"
869934977a2fSmrg
870034977a2fSmrg      test -n "$vinfo" && \
8701fe24f8a2Smrg	func_warning "'-version-info/-version-number' is ignored for archives"
870234977a2fSmrg
870334977a2fSmrg      test -n "$release" && \
8704fe24f8a2Smrg	func_warning "'-release' is ignored for archives"
870534977a2fSmrg
870634977a2fSmrg      test -n "$export_symbols$export_symbols_regex" && \
8707fe24f8a2Smrg	func_warning "'-export-symbols' is ignored for archives"
870834977a2fSmrg
870934977a2fSmrg      # Now set the variables for building old libraries.
871034977a2fSmrg      build_libtool_libs=no
8711fe24f8a2Smrg      oldlibs=$output
87123e72ca8cSmrg      func_append objs "$old_deplibs"
871334977a2fSmrg      ;;
871434977a2fSmrg
871534977a2fSmrg    lib)
8716fe24f8a2Smrg      # Make sure we only generate libraries of the form 'libNAME.la'.
871734977a2fSmrg      case $outputname in
871834977a2fSmrg      lib*)
871934977a2fSmrg	func_stripname 'lib' '.la' "$outputname"
872034977a2fSmrg	name=$func_stripname_result
872134977a2fSmrg	eval shared_ext=\"$shrext_cmds\"
872234977a2fSmrg	eval libname=\"$libname_spec\"
872334977a2fSmrg	;;
872434977a2fSmrg      *)
8725fe24f8a2Smrg	test no = "$module" \
8726fe24f8a2Smrg	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
872734977a2fSmrg
8728fe24f8a2Smrg	if test no != "$need_lib_prefix"; then
872934977a2fSmrg	  # Add the "lib" prefix for modules if required
873034977a2fSmrg	  func_stripname '' '.la' "$outputname"
873134977a2fSmrg	  name=$func_stripname_result
873234977a2fSmrg	  eval shared_ext=\"$shrext_cmds\"
873334977a2fSmrg	  eval libname=\"$libname_spec\"
873434977a2fSmrg	else
873534977a2fSmrg	  func_stripname '' '.la' "$outputname"
873634977a2fSmrg	  libname=$func_stripname_result
873734977a2fSmrg	fi
873834977a2fSmrg	;;
873934977a2fSmrg      esac
874034977a2fSmrg
874134977a2fSmrg      if test -n "$objs"; then
8742fe24f8a2Smrg	if test pass_all != "$deplibs_check_method"; then
8743fe24f8a2Smrg	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
874434977a2fSmrg	else
8745b425557eSmrg	  echo
874634977a2fSmrg	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
874734977a2fSmrg	  $ECHO "*** objects $objs is not portable!"
87483e72ca8cSmrg	  func_append libobjs " $objs"
874934977a2fSmrg	fi
875034977a2fSmrg      fi
875134977a2fSmrg
8752fe24f8a2Smrg      test no = "$dlself" \
8753fe24f8a2Smrg	|| func_warning "'-dlopen self' is ignored for libtool libraries"
875434977a2fSmrg
875534977a2fSmrg      set dummy $rpath
875634977a2fSmrg      shift
8757fe24f8a2Smrg      test 1 -lt "$#" \
8758fe24f8a2Smrg	&& func_warning "ignoring multiple '-rpath's for a libtool library"
875934977a2fSmrg
8760fe24f8a2Smrg      install_libdir=$1
876134977a2fSmrg
876234977a2fSmrg      oldlibs=
876334977a2fSmrg      if test -z "$rpath"; then
8764fe24f8a2Smrg	if test yes = "$build_libtool_libs"; then
876534977a2fSmrg	  # Building a libtool convenience library.
8766fe24f8a2Smrg	  # Some compilers have problems with a '.al' extension so
876734977a2fSmrg	  # convenience libraries should have the same extension an
876834977a2fSmrg	  # archive normally would.
876934977a2fSmrg	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
877034977a2fSmrg	  build_libtool_libs=convenience
877134977a2fSmrg	  build_old_libs=yes
877234977a2fSmrg	fi
877334977a2fSmrg
877434977a2fSmrg	test -n "$vinfo" && \
8775fe24f8a2Smrg	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
877634977a2fSmrg
877734977a2fSmrg	test -n "$release" && \
8778fe24f8a2Smrg	  func_warning "'-release' is ignored for convenience libraries"
877934977a2fSmrg      else
878034977a2fSmrg
878134977a2fSmrg	# Parse the version information argument.
8782fe24f8a2Smrg	save_ifs=$IFS; IFS=:
878334977a2fSmrg	set dummy $vinfo 0 0 0
878434977a2fSmrg	shift
8785fe24f8a2Smrg	IFS=$save_ifs
878634977a2fSmrg
878734977a2fSmrg	test -n "$7" && \
8788fe24f8a2Smrg	  func_fatal_help "too many parameters to '-version-info'"
878934977a2fSmrg
879034977a2fSmrg	# convert absolute version numbers to libtool ages
879134977a2fSmrg	# this retains compatibility with .la files and attempts
879234977a2fSmrg	# to make the code below a bit more comprehensible
879334977a2fSmrg
879434977a2fSmrg	case $vinfo_number in
879534977a2fSmrg	yes)
8796fe24f8a2Smrg	  number_major=$1
8797fe24f8a2Smrg	  number_minor=$2
8798fe24f8a2Smrg	  number_revision=$3
879934977a2fSmrg	  #
880034977a2fSmrg	  # There are really only two kinds -- those that
880134977a2fSmrg	  # use the current revision as the major version
880234977a2fSmrg	  # and those that subtract age and use age as
880334977a2fSmrg	  # a minor version.  But, then there is irix
8804fe24f8a2Smrg	  # that has an extra 1 added just for fun
880534977a2fSmrg	  #
880634977a2fSmrg	  case $version_type in
88073e72ca8cSmrg	  # correct linux to gnu/linux during the next big refactor
8808fe24f8a2Smrg	  darwin|freebsd-elf|linux|osf|windows|none)
880934977a2fSmrg	    func_arith $number_major + $number_minor
881034977a2fSmrg	    current=$func_arith_result
8811fe24f8a2Smrg	    age=$number_minor
8812fe24f8a2Smrg	    revision=$number_revision
881334977a2fSmrg	    ;;
8814fe24f8a2Smrg	  freebsd-aout|qnx|sunos)
8815fe24f8a2Smrg	    current=$number_major
8816fe24f8a2Smrg	    revision=$number_minor
8817fe24f8a2Smrg	    age=0
881834977a2fSmrg	    ;;
881934977a2fSmrg	  irix|nonstopux)
882034977a2fSmrg	    func_arith $number_major + $number_minor
882134977a2fSmrg	    current=$func_arith_result
8822fe24f8a2Smrg	    age=$number_minor
8823fe24f8a2Smrg	    revision=$number_minor
882434977a2fSmrg	    lt_irix_increment=no
882534977a2fSmrg	    ;;
882634977a2fSmrg	  esac
882734977a2fSmrg	  ;;
882834977a2fSmrg	no)
8829fe24f8a2Smrg	  current=$1
8830fe24f8a2Smrg	  revision=$2
8831fe24f8a2Smrg	  age=$3
883234977a2fSmrg	  ;;
883334977a2fSmrg	esac
883434977a2fSmrg
883534977a2fSmrg	# Check that each of the things are valid numbers.
883634977a2fSmrg	case $current in
883734977a2fSmrg	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]) ;;
883834977a2fSmrg	*)
8839fe24f8a2Smrg	  func_error "CURRENT '$current' must be a nonnegative integer"
8840fe24f8a2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
884134977a2fSmrg	  ;;
884234977a2fSmrg	esac
884334977a2fSmrg
884434977a2fSmrg	case $revision in
884534977a2fSmrg	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]) ;;
884634977a2fSmrg	*)
8847fe24f8a2Smrg	  func_error "REVISION '$revision' must be a nonnegative integer"
8848fe24f8a2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
884934977a2fSmrg	  ;;
885034977a2fSmrg	esac
885134977a2fSmrg
885234977a2fSmrg	case $age in
885334977a2fSmrg	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]) ;;
885434977a2fSmrg	*)
8855fe24f8a2Smrg	  func_error "AGE '$age' must be a nonnegative integer"
8856fe24f8a2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
885734977a2fSmrg	  ;;
885834977a2fSmrg	esac
885934977a2fSmrg
886034977a2fSmrg	if test "$age" -gt "$current"; then
8861fe24f8a2Smrg	  func_error "AGE '$age' is greater than the current interface number '$current'"
8862fe24f8a2Smrg	  func_fatal_error "'$vinfo' is not valid version information"
886334977a2fSmrg	fi
886434977a2fSmrg
886534977a2fSmrg	# Calculate the version variables.
886634977a2fSmrg	major=
886734977a2fSmrg	versuffix=
886834977a2fSmrg	verstring=
886934977a2fSmrg	case $version_type in
887034977a2fSmrg	none) ;;
887134977a2fSmrg
887234977a2fSmrg	darwin)
887334977a2fSmrg	  # Like Linux, but with the current version available in
887434977a2fSmrg	  # verstring for coding it into the library header
887534977a2fSmrg	  func_arith $current - $age
887634977a2fSmrg	  major=.$func_arith_result
8877fe24f8a2Smrg	  versuffix=$major.$age.$revision
887834977a2fSmrg	  # Darwin ld doesn't like 0 for these options...
887934977a2fSmrg	  func_arith $current + 1
888034977a2fSmrg	  minor_current=$func_arith_result
8881fe24f8a2Smrg	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
888234977a2fSmrg	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8883fe24f8a2Smrg          # On Darwin other compilers
8884fe24f8a2Smrg          case $CC in
8885fe24f8a2Smrg              nagfor*)
8886fe24f8a2Smrg                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8887fe24f8a2Smrg                  ;;
8888fe24f8a2Smrg              *)
8889fe24f8a2Smrg                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8890fe24f8a2Smrg                  ;;
8891fe24f8a2Smrg          esac
889234977a2fSmrg	  ;;
889334977a2fSmrg
889434977a2fSmrg	freebsd-aout)
8895fe24f8a2Smrg	  major=.$current
8896fe24f8a2Smrg	  versuffix=.$current.$revision
889734977a2fSmrg	  ;;
889834977a2fSmrg
889934977a2fSmrg	freebsd-elf)
8900fe24f8a2Smrg	  func_arith $current - $age
8901fe24f8a2Smrg	  major=.$func_arith_result
8902fe24f8a2Smrg	  versuffix=$major.$age.$revision
890334977a2fSmrg	  ;;
890434977a2fSmrg
890534977a2fSmrg	irix | nonstopux)
8906fe24f8a2Smrg	  if test no = "$lt_irix_increment"; then
890734977a2fSmrg	    func_arith $current - $age
890834977a2fSmrg	  else
890934977a2fSmrg	    func_arith $current - $age + 1
891034977a2fSmrg	  fi
891134977a2fSmrg	  major=$func_arith_result
891234977a2fSmrg
891334977a2fSmrg	  case $version_type in
891434977a2fSmrg	    nonstopux) verstring_prefix=nonstopux ;;
891534977a2fSmrg	    *)         verstring_prefix=sgi ;;
891634977a2fSmrg	  esac
8917fe24f8a2Smrg	  verstring=$verstring_prefix$major.$revision
891834977a2fSmrg
891934977a2fSmrg	  # Add in all the interfaces that we are compatible with.
892034977a2fSmrg	  loop=$revision
8921fe24f8a2Smrg	  while test 0 -ne "$loop"; do
892234977a2fSmrg	    func_arith $revision - $loop
892334977a2fSmrg	    iface=$func_arith_result
892434977a2fSmrg	    func_arith $loop - 1
892534977a2fSmrg	    loop=$func_arith_result
8926fe24f8a2Smrg	    verstring=$verstring_prefix$major.$iface:$verstring
892734977a2fSmrg	  done
892834977a2fSmrg
8929fe24f8a2Smrg	  # Before this point, $major must not contain '.'.
893034977a2fSmrg	  major=.$major
8931fe24f8a2Smrg	  versuffix=$major.$revision
893234977a2fSmrg	  ;;
893334977a2fSmrg
89343e72ca8cSmrg	linux) # correct to gnu/linux during the next big refactor
893534977a2fSmrg	  func_arith $current - $age
893634977a2fSmrg	  major=.$func_arith_result
8937fe24f8a2Smrg	  versuffix=$major.$age.$revision
893834977a2fSmrg	  ;;
893934977a2fSmrg
894034977a2fSmrg	osf)
894134977a2fSmrg	  func_arith $current - $age
894234977a2fSmrg	  major=.$func_arith_result
8943fe24f8a2Smrg	  versuffix=.$current.$age.$revision
8944fe24f8a2Smrg	  verstring=$current.$age.$revision
894534977a2fSmrg
894634977a2fSmrg	  # Add in all the interfaces that we are compatible with.
894734977a2fSmrg	  loop=$age
8948fe24f8a2Smrg	  while test 0 -ne "$loop"; do
894934977a2fSmrg	    func_arith $current - $loop
895034977a2fSmrg	    iface=$func_arith_result
895134977a2fSmrg	    func_arith $loop - 1
895234977a2fSmrg	    loop=$func_arith_result
8953fe24f8a2Smrg	    verstring=$verstring:$iface.0
895434977a2fSmrg	  done
895534977a2fSmrg
895634977a2fSmrg	  # Make executables depend on our current version.
8957fe24f8a2Smrg	  func_append verstring ":$current.0"
895834977a2fSmrg	  ;;
895934977a2fSmrg
896034977a2fSmrg	qnx)
8961fe24f8a2Smrg	  major=.$current
8962fe24f8a2Smrg	  versuffix=.$current
8963fe24f8a2Smrg	  ;;
8964fe24f8a2Smrg
8965fe24f8a2Smrg	sco)
8966fe24f8a2Smrg	  major=.$current
8967fe24f8a2Smrg	  versuffix=.$current
896834977a2fSmrg	  ;;
896934977a2fSmrg
897034977a2fSmrg	sunos)
8971fe24f8a2Smrg	  major=.$current
8972fe24f8a2Smrg	  versuffix=.$current.$revision
897334977a2fSmrg	  ;;
897434977a2fSmrg
897534977a2fSmrg	windows)
897634977a2fSmrg	  # Use '-' rather than '.', since we only want one
8977fe24f8a2Smrg	  # extension on DOS 8.3 file systems.
897834977a2fSmrg	  func_arith $current - $age
897934977a2fSmrg	  major=$func_arith_result
8980fe24f8a2Smrg	  versuffix=-$major
898134977a2fSmrg	  ;;
898234977a2fSmrg
898334977a2fSmrg	*)
8984fe24f8a2Smrg	  func_fatal_configuration "unknown library version type '$version_type'"
898534977a2fSmrg	  ;;
898634977a2fSmrg	esac
898734977a2fSmrg
898834977a2fSmrg	# Clear the version info if we defaulted, and they specified a release.
898934977a2fSmrg	if test -z "$vinfo" && test -n "$release"; then
899034977a2fSmrg	  major=
899134977a2fSmrg	  case $version_type in
899234977a2fSmrg	  darwin)
899334977a2fSmrg	    # we can't check for "0.0" in archive_cmds due to quoting
899434977a2fSmrg	    # problems, so we reset it completely
899534977a2fSmrg	    verstring=
899634977a2fSmrg	    ;;
899734977a2fSmrg	  *)
8998fe24f8a2Smrg	    verstring=0.0
899934977a2fSmrg	    ;;
900034977a2fSmrg	  esac
9001fe24f8a2Smrg	  if test no = "$need_version"; then
900234977a2fSmrg	    versuffix=
900334977a2fSmrg	  else
9004fe24f8a2Smrg	    versuffix=.0.0
900534977a2fSmrg	  fi
900634977a2fSmrg	fi
900734977a2fSmrg
900834977a2fSmrg	# Remove version info from name if versioning should be avoided
9009fe24f8a2Smrg	if test yes,no = "$avoid_version,$need_version"; then
901034977a2fSmrg	  major=
901134977a2fSmrg	  versuffix=
9012fe24f8a2Smrg	  verstring=
901334977a2fSmrg	fi
901434977a2fSmrg
901534977a2fSmrg	# Check to see if the archive will have undefined symbols.
9016fe24f8a2Smrg	if test yes = "$allow_undefined"; then
9017fe24f8a2Smrg	  if test unsupported = "$allow_undefined_flag"; then
9018fe24f8a2Smrg	    if test yes = "$build_old_libs"; then
9019fe24f8a2Smrg	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
9020fe24f8a2Smrg	      build_libtool_libs=no
9021fe24f8a2Smrg	    else
9022fe24f8a2Smrg	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9023fe24f8a2Smrg	    fi
902434977a2fSmrg	  fi
902534977a2fSmrg	else
902634977a2fSmrg	  # Don't allow undefined symbols.
9027fe24f8a2Smrg	  allow_undefined_flag=$no_undefined_flag
902834977a2fSmrg	fi
902934977a2fSmrg
903034977a2fSmrg      fi
903134977a2fSmrg
9032fe24f8a2Smrg      func_generate_dlsyms "$libname" "$libname" :
90333e72ca8cSmrg      func_append libobjs " $symfileobj"
9034fe24f8a2Smrg      test " " = "$libobjs" && libobjs=
903534977a2fSmrg
9036fe24f8a2Smrg      if test relink != "$opt_mode"; then
903734977a2fSmrg	# Remove our outputs, but don't remove object files since they
903834977a2fSmrg	# may have been created when compiling PIC objects.
903934977a2fSmrg	removelist=
904034977a2fSmrg	tempremovelist=`$ECHO "$output_objdir/*"`
904134977a2fSmrg	for p in $tempremovelist; do
904234977a2fSmrg	  case $p in
904334977a2fSmrg	    *.$objext | *.gcno)
904434977a2fSmrg	       ;;
9045fe24f8a2Smrg	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9046fe24f8a2Smrg	       if test -n "$precious_files_regex"; then
904734977a2fSmrg		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
904834977a2fSmrg		 then
904934977a2fSmrg		   continue
905034977a2fSmrg		 fi
905134977a2fSmrg	       fi
90523e72ca8cSmrg	       func_append removelist " $p"
905334977a2fSmrg	       ;;
905434977a2fSmrg	    *) ;;
905534977a2fSmrg	  esac
905634977a2fSmrg	done
905734977a2fSmrg	test -n "$removelist" && \
905834977a2fSmrg	  func_show_eval "${RM}r \$removelist"
905934977a2fSmrg      fi
906034977a2fSmrg
906134977a2fSmrg      # Now set the variables for building old libraries.
9062fe24f8a2Smrg      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
90633e72ca8cSmrg	func_append oldlibs " $output_objdir/$libname.$libext"
906434977a2fSmrg
906534977a2fSmrg	# Transform .lo files to .o files.
9066fe24f8a2Smrg	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
906734977a2fSmrg      fi
906834977a2fSmrg
906934977a2fSmrg      # Eliminate all temporary directories.
907034977a2fSmrg      #for path in $notinst_path; do
9071b425557eSmrg      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
9072b425557eSmrg      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
9073b425557eSmrg      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
907434977a2fSmrg      #done
907534977a2fSmrg
907634977a2fSmrg      if test -n "$xrpath"; then
907734977a2fSmrg	# If the user specified any rpath flags, then add them.
907834977a2fSmrg	temp_xrpath=
907934977a2fSmrg	for libdir in $xrpath; do
90803e72ca8cSmrg	  func_replace_sysroot "$libdir"
90813e72ca8cSmrg	  func_append temp_xrpath " -R$func_replace_sysroot_result"
908234977a2fSmrg	  case "$finalize_rpath " in
908334977a2fSmrg	  *" $libdir "*) ;;
90843e72ca8cSmrg	  *) func_append finalize_rpath " $libdir" ;;
908534977a2fSmrg	  esac
908634977a2fSmrg	done
9087fe24f8a2Smrg	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
908834977a2fSmrg	  dependency_libs="$temp_xrpath $dependency_libs"
908934977a2fSmrg	fi
909034977a2fSmrg      fi
909134977a2fSmrg
909234977a2fSmrg      # Make sure dlfiles contains only unique files that won't be dlpreopened
9093fe24f8a2Smrg      old_dlfiles=$dlfiles
909434977a2fSmrg      dlfiles=
909534977a2fSmrg      for lib in $old_dlfiles; do
909634977a2fSmrg	case " $dlprefiles $dlfiles " in
909734977a2fSmrg	*" $lib "*) ;;
90983e72ca8cSmrg	*) func_append dlfiles " $lib" ;;
909934977a2fSmrg	esac
910034977a2fSmrg      done
910134977a2fSmrg
910234977a2fSmrg      # Make sure dlprefiles contains only unique files
9103fe24f8a2Smrg      old_dlprefiles=$dlprefiles
910434977a2fSmrg      dlprefiles=
910534977a2fSmrg      for lib in $old_dlprefiles; do
910634977a2fSmrg	case "$dlprefiles " in
910734977a2fSmrg	*" $lib "*) ;;
91083e72ca8cSmrg	*) func_append dlprefiles " $lib" ;;
910934977a2fSmrg	esac
911034977a2fSmrg      done
911134977a2fSmrg
9112fe24f8a2Smrg      if test yes = "$build_libtool_libs"; then
911334977a2fSmrg	if test -n "$rpath"; then
911434977a2fSmrg	  case $host in
9115b425557eSmrg	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
911634977a2fSmrg	    # these systems don't actually have a c library (as such)!
911734977a2fSmrg	    ;;
911834977a2fSmrg	  *-*-rhapsody* | *-*-darwin1.[012])
911934977a2fSmrg	    # Rhapsody C library is in the System framework
91203e72ca8cSmrg	    func_append deplibs " System.ltframework"
912134977a2fSmrg	    ;;
912234977a2fSmrg	  *-*-netbsd*)
912334977a2fSmrg	    # Don't link with libc until the a.out ld.so is fixed.
912434977a2fSmrg	    ;;
912534977a2fSmrg	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
912634977a2fSmrg	    # Do not include libc due to us having libc/libc_r.
912734977a2fSmrg	    ;;
912834977a2fSmrg	  *-*-sco3.2v5* | *-*-sco5v6*)
912934977a2fSmrg	    # Causes problems with __ctype
913034977a2fSmrg	    ;;
913134977a2fSmrg	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
913234977a2fSmrg	    # Compiler inserts libc in the correct place for threads to work
913334977a2fSmrg	    ;;
913434977a2fSmrg	  *)
913534977a2fSmrg	    # Add libc to deplibs on all other systems if necessary.
9136fe24f8a2Smrg	    if test yes = "$build_libtool_need_lc"; then
91373e72ca8cSmrg	      func_append deplibs " -lc"
913834977a2fSmrg	    fi
913934977a2fSmrg	    ;;
914034977a2fSmrg	  esac
914134977a2fSmrg	fi
914234977a2fSmrg
914334977a2fSmrg	# Transform deplibs into only deplibs that can be linked in shared.
914434977a2fSmrg	name_save=$name
914534977a2fSmrg	libname_save=$libname
914634977a2fSmrg	release_save=$release
914734977a2fSmrg	versuffix_save=$versuffix
914834977a2fSmrg	major_save=$major
914934977a2fSmrg	# I'm not sure if I'm treating the release correctly.  I think
915034977a2fSmrg	# release should show up in the -l (ie -lgmp5) so we don't want to
915134977a2fSmrg	# add it in twice.  Is that correct?
9152fe24f8a2Smrg	release=
9153fe24f8a2Smrg	versuffix=
9154fe24f8a2Smrg	major=
915534977a2fSmrg	newdeplibs=
915634977a2fSmrg	droppeddeps=no
915734977a2fSmrg	case $deplibs_check_method in
915834977a2fSmrg	pass_all)
915934977a2fSmrg	  # Don't check for shared/static.  Everything works.
916034977a2fSmrg	  # This might be a little naive.  We might want to check
916134977a2fSmrg	  # whether the library exists or not.  But this is on
916234977a2fSmrg	  # osf3 & osf4 and I'm not really sure... Just
916334977a2fSmrg	  # implementing what was already the behavior.
916434977a2fSmrg	  newdeplibs=$deplibs
916534977a2fSmrg	  ;;
916634977a2fSmrg	test_compile)
916734977a2fSmrg	  # This code stresses the "libraries are programs" paradigm to its
916834977a2fSmrg	  # limits. Maybe even breaks it.  We compile a program, linking it
916934977a2fSmrg	  # against the deplibs as a proxy for the library.  Then we can check
917034977a2fSmrg	  # whether they linked in statically or dynamically with ldd.
917134977a2fSmrg	  $opt_dry_run || $RM conftest.c
917234977a2fSmrg	  cat > conftest.c <<EOF
917334977a2fSmrg	  int main() { return 0; }
917434977a2fSmrgEOF
917534977a2fSmrg	  $opt_dry_run || $RM conftest
917634977a2fSmrg	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
917734977a2fSmrg	    ldd_output=`ldd conftest`
917834977a2fSmrg	    for i in $deplibs; do
917934977a2fSmrg	      case $i in
918034977a2fSmrg	      -l*)
918134977a2fSmrg		func_stripname -l '' "$i"
918234977a2fSmrg		name=$func_stripname_result
9183fe24f8a2Smrg		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
918434977a2fSmrg		  case " $predeps $postdeps " in
918534977a2fSmrg		  *" $i "*)
91863e72ca8cSmrg		    func_append newdeplibs " $i"
9187fe24f8a2Smrg		    i=
918834977a2fSmrg		    ;;
918934977a2fSmrg		  esac
919034977a2fSmrg		fi
9191fe24f8a2Smrg		if test -n "$i"; then
919234977a2fSmrg		  libname=`eval "\\$ECHO \"$libname_spec\""`
919334977a2fSmrg		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
919434977a2fSmrg		  set dummy $deplib_matches; shift
919534977a2fSmrg		  deplib_match=$1
9196fe24f8a2Smrg		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
91973e72ca8cSmrg		    func_append newdeplibs " $i"
919834977a2fSmrg		  else
919934977a2fSmrg		    droppeddeps=yes
9200b425557eSmrg		    echo
920134977a2fSmrg		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9202b425557eSmrg		    echo "*** I have the capability to make that library automatically link in when"
9203b425557eSmrg		    echo "*** you link to this library.  But I can only do this if you have a"
9204b425557eSmrg		    echo "*** shared version of the library, which I believe you do not have"
9205b425557eSmrg		    echo "*** because a test_compile did reveal that the linker did not use it for"
9206b425557eSmrg		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
920734977a2fSmrg		  fi
920834977a2fSmrg		fi
920934977a2fSmrg		;;
921034977a2fSmrg	      *)
92113e72ca8cSmrg		func_append newdeplibs " $i"
921234977a2fSmrg		;;
921334977a2fSmrg	      esac
921434977a2fSmrg	    done
921534977a2fSmrg	  else
921634977a2fSmrg	    # Error occurred in the first compile.  Let's try to salvage
921734977a2fSmrg	    # the situation: Compile a separate program for each library.
921834977a2fSmrg	    for i in $deplibs; do
921934977a2fSmrg	      case $i in
922034977a2fSmrg	      -l*)
922134977a2fSmrg		func_stripname -l '' "$i"
922234977a2fSmrg		name=$func_stripname_result
922334977a2fSmrg		$opt_dry_run || $RM conftest
922434977a2fSmrg		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
922534977a2fSmrg		  ldd_output=`ldd conftest`
9226fe24f8a2Smrg		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
922734977a2fSmrg		    case " $predeps $postdeps " in
922834977a2fSmrg		    *" $i "*)
92293e72ca8cSmrg		      func_append newdeplibs " $i"
9230fe24f8a2Smrg		      i=
923134977a2fSmrg		      ;;
923234977a2fSmrg		    esac
923334977a2fSmrg		  fi
9234fe24f8a2Smrg		  if test -n "$i"; then
923534977a2fSmrg		    libname=`eval "\\$ECHO \"$libname_spec\""`
923634977a2fSmrg		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
923734977a2fSmrg		    set dummy $deplib_matches; shift
923834977a2fSmrg		    deplib_match=$1
9239fe24f8a2Smrg		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
92403e72ca8cSmrg		      func_append newdeplibs " $i"
924134977a2fSmrg		    else
924234977a2fSmrg		      droppeddeps=yes
9243b425557eSmrg		      echo
924434977a2fSmrg		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
9245b425557eSmrg		      echo "*** I have the capability to make that library automatically link in when"
9246b425557eSmrg		      echo "*** you link to this library.  But I can only do this if you have a"
9247b425557eSmrg		      echo "*** shared version of the library, which you do not appear to have"
9248b425557eSmrg		      echo "*** because a test_compile did reveal that the linker did not use this one"
9249b425557eSmrg		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
925034977a2fSmrg		    fi
925134977a2fSmrg		  fi
925234977a2fSmrg		else
925334977a2fSmrg		  droppeddeps=yes
9254b425557eSmrg		  echo
925534977a2fSmrg		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
9256b425557eSmrg		  echo "*** make it link in!  You will probably need to install it or some"
9257b425557eSmrg		  echo "*** library that it depends on before this library will be fully"
9258b425557eSmrg		  echo "*** functional.  Installing it before continuing would be even better."
925934977a2fSmrg		fi
926034977a2fSmrg		;;
926134977a2fSmrg	      *)
92623e72ca8cSmrg		func_append newdeplibs " $i"
926334977a2fSmrg		;;
926434977a2fSmrg	      esac
926534977a2fSmrg	    done
926634977a2fSmrg	  fi
926734977a2fSmrg	  ;;
926834977a2fSmrg	file_magic*)
926934977a2fSmrg	  set dummy $deplibs_check_method; shift
927034977a2fSmrg	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
927134977a2fSmrg	  for a_deplib in $deplibs; do
927234977a2fSmrg	    case $a_deplib in
927334977a2fSmrg	    -l*)
927434977a2fSmrg	      func_stripname -l '' "$a_deplib"
927534977a2fSmrg	      name=$func_stripname_result
9276fe24f8a2Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
927734977a2fSmrg		case " $predeps $postdeps " in
927834977a2fSmrg		*" $a_deplib "*)
92793e72ca8cSmrg		  func_append newdeplibs " $a_deplib"
9280fe24f8a2Smrg		  a_deplib=
928134977a2fSmrg		  ;;
928234977a2fSmrg		esac
928334977a2fSmrg	      fi
9284fe24f8a2Smrg	      if test -n "$a_deplib"; then
928534977a2fSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
92863e72ca8cSmrg		if test -n "$file_magic_glob"; then
92873e72ca8cSmrg		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
92883e72ca8cSmrg		else
92893e72ca8cSmrg		  libnameglob=$libname
92903e72ca8cSmrg		fi
9291fe24f8a2Smrg		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
929234977a2fSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9293fe24f8a2Smrg		  if test yes = "$want_nocaseglob"; then
92943e72ca8cSmrg		    shopt -s nocaseglob
92953e72ca8cSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
92963e72ca8cSmrg		    $nocaseglob
92973e72ca8cSmrg		  else
92983e72ca8cSmrg		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
92993e72ca8cSmrg		  fi
930034977a2fSmrg		  for potent_lib in $potential_libs; do
930134977a2fSmrg		      # Follow soft links.
930234977a2fSmrg		      if ls -lLd "$potent_lib" 2>/dev/null |
930334977a2fSmrg			 $GREP " -> " >/dev/null; then
930434977a2fSmrg			continue
930534977a2fSmrg		      fi
930634977a2fSmrg		      # The statement above tries to avoid entering an
930734977a2fSmrg		      # endless loop below, in case of cyclic links.
930834977a2fSmrg		      # We might still enter an endless loop, since a link
930934977a2fSmrg		      # loop can be closed while we follow links,
931034977a2fSmrg		      # but so what?
9311fe24f8a2Smrg		      potlib=$potent_lib
931234977a2fSmrg		      while test -h "$potlib" 2>/dev/null; do
9313fe24f8a2Smrg			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
931434977a2fSmrg			case $potliblink in
9315fe24f8a2Smrg			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9316fe24f8a2Smrg			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
931734977a2fSmrg			esac
931834977a2fSmrg		      done
931934977a2fSmrg		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
932034977a2fSmrg			 $SED -e 10q |
932134977a2fSmrg			 $EGREP "$file_magic_regex" > /dev/null; then
93223e72ca8cSmrg			func_append newdeplibs " $a_deplib"
9323fe24f8a2Smrg			a_deplib=
932434977a2fSmrg			break 2
932534977a2fSmrg		      fi
932634977a2fSmrg		  done
932734977a2fSmrg		done
932834977a2fSmrg	      fi
9329fe24f8a2Smrg	      if test -n "$a_deplib"; then
933034977a2fSmrg		droppeddeps=yes
9331b425557eSmrg		echo
933234977a2fSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9333b425557eSmrg		echo "*** I have the capability to make that library automatically link in when"
9334b425557eSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9335b425557eSmrg		echo "*** shared version of the library, which you do not appear to have"
9336b425557eSmrg		echo "*** because I did check the linker path looking for a file starting"
9337fe24f8a2Smrg		if test -z "$potlib"; then
933834977a2fSmrg		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
933934977a2fSmrg		else
934034977a2fSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
934134977a2fSmrg		  $ECHO "*** using a file magic. Last file checked: $potlib"
934234977a2fSmrg		fi
934334977a2fSmrg	      fi
934434977a2fSmrg	      ;;
934534977a2fSmrg	    *)
934634977a2fSmrg	      # Add a -L argument.
93473e72ca8cSmrg	      func_append newdeplibs " $a_deplib"
934834977a2fSmrg	      ;;
934934977a2fSmrg	    esac
935034977a2fSmrg	  done # Gone through all deplibs.
935134977a2fSmrg	  ;;
935234977a2fSmrg	match_pattern*)
935334977a2fSmrg	  set dummy $deplibs_check_method; shift
935434977a2fSmrg	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
935534977a2fSmrg	  for a_deplib in $deplibs; do
935634977a2fSmrg	    case $a_deplib in
935734977a2fSmrg	    -l*)
935834977a2fSmrg	      func_stripname -l '' "$a_deplib"
935934977a2fSmrg	      name=$func_stripname_result
9360fe24f8a2Smrg	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
936134977a2fSmrg		case " $predeps $postdeps " in
936234977a2fSmrg		*" $a_deplib "*)
93633e72ca8cSmrg		  func_append newdeplibs " $a_deplib"
9364fe24f8a2Smrg		  a_deplib=
936534977a2fSmrg		  ;;
936634977a2fSmrg		esac
936734977a2fSmrg	      fi
9368fe24f8a2Smrg	      if test -n "$a_deplib"; then
936934977a2fSmrg		libname=`eval "\\$ECHO \"$libname_spec\""`
937034977a2fSmrg		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
937134977a2fSmrg		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
937234977a2fSmrg		  for potent_lib in $potential_libs; do
9373fe24f8a2Smrg		    potlib=$potent_lib # see symlink-check above in file_magic test
9374b425557eSmrg		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
937534977a2fSmrg		       $EGREP "$match_pattern_regex" > /dev/null; then
93763e72ca8cSmrg		      func_append newdeplibs " $a_deplib"
9377fe24f8a2Smrg		      a_deplib=
937834977a2fSmrg		      break 2
937934977a2fSmrg		    fi
938034977a2fSmrg		  done
938134977a2fSmrg		done
938234977a2fSmrg	      fi
9383fe24f8a2Smrg	      if test -n "$a_deplib"; then
938434977a2fSmrg		droppeddeps=yes
9385b425557eSmrg		echo
938634977a2fSmrg		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
9387b425557eSmrg		echo "*** I have the capability to make that library automatically link in when"
9388b425557eSmrg		echo "*** you link to this library.  But I can only do this if you have a"
9389b425557eSmrg		echo "*** shared version of the library, which you do not appear to have"
9390b425557eSmrg		echo "*** because I did check the linker path looking for a file starting"
9391fe24f8a2Smrg		if test -z "$potlib"; then
939234977a2fSmrg		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
939334977a2fSmrg		else
939434977a2fSmrg		  $ECHO "*** with $libname and none of the candidates passed a file format test"
939534977a2fSmrg		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
939634977a2fSmrg		fi
939734977a2fSmrg	      fi
939834977a2fSmrg	      ;;
939934977a2fSmrg	    *)
940034977a2fSmrg	      # Add a -L argument.
94013e72ca8cSmrg	      func_append newdeplibs " $a_deplib"
940234977a2fSmrg	      ;;
940334977a2fSmrg	    esac
940434977a2fSmrg	  done # Gone through all deplibs.
940534977a2fSmrg	  ;;
940634977a2fSmrg	none | unknown | *)
9407fe24f8a2Smrg	  newdeplibs=
9408b425557eSmrg	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9409fe24f8a2Smrg	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
9410fe24f8a2Smrg	    for i in $predeps $postdeps; do
941134977a2fSmrg	      # can't use Xsed below, because $i might contain '/'
9412fe24f8a2Smrg	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
941334977a2fSmrg	    done
941434977a2fSmrg	  fi
9415b425557eSmrg	  case $tmp_deplibs in
9416b425557eSmrg	  *[!\	\ ]*)
9417b425557eSmrg	    echo
9418fe24f8a2Smrg	    if test none = "$deplibs_check_method"; then
9419b425557eSmrg	      echo "*** Warning: inter-library dependencies are not supported in this platform."
942034977a2fSmrg	    else
9421b425557eSmrg	      echo "*** Warning: inter-library dependencies are not known to be supported."
942234977a2fSmrg	    fi
9423b425557eSmrg	    echo "*** All declared inter-library dependencies are being dropped."
942434977a2fSmrg	    droppeddeps=yes
9425b425557eSmrg	    ;;
9426b425557eSmrg	  esac
942734977a2fSmrg	  ;;
942834977a2fSmrg	esac
942934977a2fSmrg	versuffix=$versuffix_save
943034977a2fSmrg	major=$major_save
943134977a2fSmrg	release=$release_save
943234977a2fSmrg	libname=$libname_save
943334977a2fSmrg	name=$name_save
943434977a2fSmrg
943534977a2fSmrg	case $host in
943634977a2fSmrg	*-*-rhapsody* | *-*-darwin1.[012])
943734977a2fSmrg	  # On Rhapsody replace the C library with the System framework
9438b425557eSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
943934977a2fSmrg	  ;;
944034977a2fSmrg	esac
944134977a2fSmrg
9442fe24f8a2Smrg	if test yes = "$droppeddeps"; then
9443fe24f8a2Smrg	  if test yes = "$module"; then
9444b425557eSmrg	    echo
9445b425557eSmrg	    echo "*** Warning: libtool could not satisfy all declared inter-library"
944634977a2fSmrg	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
9447b425557eSmrg	    echo "*** a static module, that should work as long as the dlopening"
9448b425557eSmrg	    echo "*** application is linked with the -dlopen flag."
944934977a2fSmrg	    if test -z "$global_symbol_pipe"; then
9450b425557eSmrg	      echo
9451b425557eSmrg	      echo "*** However, this would only work if libtool was able to extract symbol"
9452fe24f8a2Smrg	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
9453b425557eSmrg	      echo "*** not find such a program.  So, this module is probably useless."
9454fe24f8a2Smrg	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
945534977a2fSmrg	    fi
9456fe24f8a2Smrg	    if test no = "$build_old_libs"; then
9457fe24f8a2Smrg	      oldlibs=$output_objdir/$libname.$libext
945834977a2fSmrg	      build_libtool_libs=module
945934977a2fSmrg	      build_old_libs=yes
946034977a2fSmrg	    else
946134977a2fSmrg	      build_libtool_libs=no
946234977a2fSmrg	    fi
946334977a2fSmrg	  else
9464b425557eSmrg	    echo "*** The inter-library dependencies that have been dropped here will be"
9465b425557eSmrg	    echo "*** automatically added whenever a program is linked with this library"
9466b425557eSmrg	    echo "*** or is declared to -dlopen it."
946734977a2fSmrg
9468fe24f8a2Smrg	    if test no = "$allow_undefined"; then
9469b425557eSmrg	      echo
9470b425557eSmrg	      echo "*** Since this library must not contain undefined symbols,"
9471b425557eSmrg	      echo "*** because either the platform does not support them or"
9472b425557eSmrg	      echo "*** it was explicitly requested with -no-undefined,"
9473b425557eSmrg	      echo "*** libtool will only create a static version of it."
9474fe24f8a2Smrg	      if test no = "$build_old_libs"; then
9475fe24f8a2Smrg		oldlibs=$output_objdir/$libname.$libext
947634977a2fSmrg		build_libtool_libs=module
947734977a2fSmrg		build_old_libs=yes
947834977a2fSmrg	      else
947934977a2fSmrg		build_libtool_libs=no
948034977a2fSmrg	      fi
948134977a2fSmrg	    fi
948234977a2fSmrg	  fi
948334977a2fSmrg	fi
948434977a2fSmrg	# Done checking deplibs!
948534977a2fSmrg	deplibs=$newdeplibs
948634977a2fSmrg      fi
948734977a2fSmrg      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
948834977a2fSmrg      case $host in
948934977a2fSmrg	*-*-darwin*)
9490b425557eSmrg	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9491b425557eSmrg	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
9492b425557eSmrg	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
949334977a2fSmrg	  ;;
949434977a2fSmrg      esac
949534977a2fSmrg
949634977a2fSmrg      # move library search paths that coincide with paths to not yet
949734977a2fSmrg      # installed libraries to the beginning of the library search list
949834977a2fSmrg      new_libs=
949934977a2fSmrg      for path in $notinst_path; do
950034977a2fSmrg	case " $new_libs " in
950134977a2fSmrg	*" -L$path/$objdir "*) ;;
950234977a2fSmrg	*)
950334977a2fSmrg	  case " $deplibs " in
950434977a2fSmrg	  *" -L$path/$objdir "*)
95053e72ca8cSmrg	    func_append new_libs " -L$path/$objdir" ;;
950634977a2fSmrg	  esac
950734977a2fSmrg	  ;;
950834977a2fSmrg	esac
950934977a2fSmrg      done
951034977a2fSmrg      for deplib in $deplibs; do
951134977a2fSmrg	case $deplib in
951234977a2fSmrg	-L*)
951334977a2fSmrg	  case " $new_libs " in
951434977a2fSmrg	  *" $deplib "*) ;;
95153e72ca8cSmrg	  *) func_append new_libs " $deplib" ;;
951634977a2fSmrg	  esac
951734977a2fSmrg	  ;;
95183e72ca8cSmrg	*) func_append new_libs " $deplib" ;;
951934977a2fSmrg	esac
952034977a2fSmrg      done
9521fe24f8a2Smrg      deplibs=$new_libs
952234977a2fSmrg
952334977a2fSmrg      # All the library-specific variables (install_libdir is set above).
952434977a2fSmrg      library_names=
952534977a2fSmrg      old_library=
952634977a2fSmrg      dlname=
952734977a2fSmrg
952834977a2fSmrg      # Test again, we may have decided not to build it any more
9529fe24f8a2Smrg      if test yes = "$build_libtool_libs"; then
9530fe24f8a2Smrg	# Remove $wl instances when linking with ld.
95313e72ca8cSmrg	# FIXME: should test the right _cmds variable.
95323e72ca8cSmrg	case $archive_cmds in
95333e72ca8cSmrg	  *\$LD\ *) wl= ;;
95343e72ca8cSmrg        esac
9535fe24f8a2Smrg	if test yes = "$hardcode_into_libs"; then
953634977a2fSmrg	  # Hardcode the library paths
953734977a2fSmrg	  hardcode_libdirs=
953834977a2fSmrg	  dep_rpath=
9539fe24f8a2Smrg	  rpath=$finalize_rpath
9540fe24f8a2Smrg	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
954134977a2fSmrg	  for libdir in $rpath; do
954234977a2fSmrg	    if test -n "$hardcode_libdir_flag_spec"; then
954334977a2fSmrg	      if test -n "$hardcode_libdir_separator"; then
95443e72ca8cSmrg		func_replace_sysroot "$libdir"
95453e72ca8cSmrg		libdir=$func_replace_sysroot_result
954634977a2fSmrg		if test -z "$hardcode_libdirs"; then
9547fe24f8a2Smrg		  hardcode_libdirs=$libdir
954834977a2fSmrg		else
954934977a2fSmrg		  # Just accumulate the unique libdirs.
955034977a2fSmrg		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
955134977a2fSmrg		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
955234977a2fSmrg		    ;;
955334977a2fSmrg		  *)
95543e72ca8cSmrg		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
955534977a2fSmrg		    ;;
955634977a2fSmrg		  esac
955734977a2fSmrg		fi
955834977a2fSmrg	      else
955934977a2fSmrg		eval flag=\"$hardcode_libdir_flag_spec\"
95603e72ca8cSmrg		func_append dep_rpath " $flag"
956134977a2fSmrg	      fi
956234977a2fSmrg	    elif test -n "$runpath_var"; then
956334977a2fSmrg	      case "$perm_rpath " in
956434977a2fSmrg	      *" $libdir "*) ;;
95653e72ca8cSmrg	      *) func_append perm_rpath " $libdir" ;;
956634977a2fSmrg	      esac
956734977a2fSmrg	    fi
956834977a2fSmrg	  done
956934977a2fSmrg	  # Substitute the hardcoded libdirs into the rpath.
957034977a2fSmrg	  if test -n "$hardcode_libdir_separator" &&
957134977a2fSmrg	     test -n "$hardcode_libdirs"; then
9572fe24f8a2Smrg	    libdir=$hardcode_libdirs
95733e72ca8cSmrg	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
957434977a2fSmrg	  fi
957534977a2fSmrg	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
957634977a2fSmrg	    # We should set the runpath_var.
957734977a2fSmrg	    rpath=
957834977a2fSmrg	    for dir in $perm_rpath; do
95793e72ca8cSmrg	      func_append rpath "$dir:"
958034977a2fSmrg	    done
958134977a2fSmrg	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
958234977a2fSmrg	  fi
958334977a2fSmrg	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
958434977a2fSmrg	fi
9585ee3138f1Smrg
9586fe24f8a2Smrg	shlibpath=$finalize_shlibpath
9587fe24f8a2Smrg	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
958834977a2fSmrg	if test -n "$shlibpath"; then
958934977a2fSmrg	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
959034977a2fSmrg	fi
9591ee3138f1Smrg
959234977a2fSmrg	# Get the real and link names of the library.
959334977a2fSmrg	eval shared_ext=\"$shrext_cmds\"
959434977a2fSmrg	eval library_names=\"$library_names_spec\"
959534977a2fSmrg	set dummy $library_names
959634977a2fSmrg	shift
9597fe24f8a2Smrg	realname=$1
959834977a2fSmrg	shift
9599ee3138f1Smrg
960034977a2fSmrg	if test -n "$soname_spec"; then
960134977a2fSmrg	  eval soname=\"$soname_spec\"
960234977a2fSmrg	else
9603fe24f8a2Smrg	  soname=$realname
960434977a2fSmrg	fi
960534977a2fSmrg	if test -z "$dlname"; then
960634977a2fSmrg	  dlname=$soname
960734977a2fSmrg	fi
9608ee3138f1Smrg
9609fe24f8a2Smrg	lib=$output_objdir/$realname
961034977a2fSmrg	linknames=
961134977a2fSmrg	for link
961234977a2fSmrg	do
96133e72ca8cSmrg	  func_append linknames " $link"
961434977a2fSmrg	done
9615ee3138f1Smrg
961634977a2fSmrg	# Use standard objects if they are pic
9617b425557eSmrg	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
961834977a2fSmrg	test "X$libobjs" = "X " && libobjs=
9619ee3138f1Smrg
962034977a2fSmrg	delfiles=
962134977a2fSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
962234977a2fSmrg	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9623fe24f8a2Smrg	  export_symbols=$output_objdir/$libname.uexp
96243e72ca8cSmrg	  func_append delfiles " $export_symbols"
962534977a2fSmrg	fi
9626ee3138f1Smrg
962734977a2fSmrg	orig_export_symbols=
962834977a2fSmrg	case $host_os in
962934977a2fSmrg	cygwin* | mingw* | cegcc*)
963034977a2fSmrg	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
963134977a2fSmrg	    # exporting using user supplied symfile
9632fe24f8a2Smrg	    func_dll_def_p "$export_symbols" || {
963334977a2fSmrg	      # and it's NOT already a .def file. Must figure out
963434977a2fSmrg	      # which of the given symbols are data symbols and tag
963534977a2fSmrg	      # them as such. So, trigger use of export_symbols_cmds.
963634977a2fSmrg	      # export_symbols gets reassigned inside the "prepare
963734977a2fSmrg	      # the list of exported symbols" if statement, so the
963834977a2fSmrg	      # include_expsyms logic still works.
9639fe24f8a2Smrg	      orig_export_symbols=$export_symbols
964034977a2fSmrg	      export_symbols=
964134977a2fSmrg	      always_export_symbols=yes
9642fe24f8a2Smrg	    }
964334977a2fSmrg	  fi
964434977a2fSmrg	  ;;
964534977a2fSmrg	esac
9646ee3138f1Smrg
964734977a2fSmrg	# Prepare the list of exported symbols
964834977a2fSmrg	if test -z "$export_symbols"; then
9649fe24f8a2Smrg	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9650fe24f8a2Smrg	    func_verbose "generating symbol list for '$libname.la'"
9651fe24f8a2Smrg	    export_symbols=$output_objdir/$libname.exp
965234977a2fSmrg	    $opt_dry_run || $RM $export_symbols
965334977a2fSmrg	    cmds=$export_symbols_cmds
9654fe24f8a2Smrg	    save_ifs=$IFS; IFS='~'
96553e72ca8cSmrg	    for cmd1 in $cmds; do
9656fe24f8a2Smrg	      IFS=$save_ifs
96573e72ca8cSmrg	      # Take the normal branch if the nm_file_list_spec branch
96583e72ca8cSmrg	      # doesn't work or if tool conversion is not needed.
96593e72ca8cSmrg	      case $nm_file_list_spec~$to_tool_file_cmd in
96603e72ca8cSmrg		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
96613e72ca8cSmrg		  try_normal_branch=yes
96623e72ca8cSmrg		  eval cmd=\"$cmd1\"
96633e72ca8cSmrg		  func_len " $cmd"
96643e72ca8cSmrg		  len=$func_len_result
96653e72ca8cSmrg		  ;;
96663e72ca8cSmrg		*)
96673e72ca8cSmrg		  try_normal_branch=no
96683e72ca8cSmrg		  ;;
96693e72ca8cSmrg	      esac
9670fe24f8a2Smrg	      if test yes = "$try_normal_branch" \
96713e72ca8cSmrg		 && { test "$len" -lt "$max_cmd_len" \
96723e72ca8cSmrg		      || test "$max_cmd_len" -le -1; }
96733e72ca8cSmrg	      then
96743e72ca8cSmrg		func_show_eval "$cmd" 'exit $?'
96753e72ca8cSmrg		skipped_export=false
96763e72ca8cSmrg	      elif test -n "$nm_file_list_spec"; then
96773e72ca8cSmrg		func_basename "$output"
96783e72ca8cSmrg		output_la=$func_basename_result
96793e72ca8cSmrg		save_libobjs=$libobjs
96803e72ca8cSmrg		save_output=$output
9681fe24f8a2Smrg		output=$output_objdir/$output_la.nm
96823e72ca8cSmrg		func_to_tool_file "$output"
96833e72ca8cSmrg		libobjs=$nm_file_list_spec$func_to_tool_file_result
96843e72ca8cSmrg		func_append delfiles " $output"
96853e72ca8cSmrg		func_verbose "creating $NM input file list: $output"
96863e72ca8cSmrg		for obj in $save_libobjs; do
96873e72ca8cSmrg		  func_to_tool_file "$obj"
96883e72ca8cSmrg		  $ECHO "$func_to_tool_file_result"
96893e72ca8cSmrg		done > "$output"
96903e72ca8cSmrg		eval cmd=\"$cmd1\"
969134977a2fSmrg		func_show_eval "$cmd" 'exit $?'
96923e72ca8cSmrg		output=$save_output
96933e72ca8cSmrg		libobjs=$save_libobjs
969434977a2fSmrg		skipped_export=false
969534977a2fSmrg	      else
969634977a2fSmrg		# The command line is too long to execute in one step.
969734977a2fSmrg		func_verbose "using reloadable object file for export list..."
969834977a2fSmrg		skipped_export=:
969934977a2fSmrg		# Break out early, otherwise skipped_export may be
970034977a2fSmrg		# set to false by a later but shorter cmd.
970134977a2fSmrg		break
970234977a2fSmrg	      fi
970334977a2fSmrg	    done
9704fe24f8a2Smrg	    IFS=$save_ifs
9705fe24f8a2Smrg	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
970634977a2fSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
970734977a2fSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
970834977a2fSmrg	    fi
970934977a2fSmrg	  fi
9710ee3138f1Smrg	fi
9711ee3138f1Smrg
971234977a2fSmrg	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9713fe24f8a2Smrg	  tmp_export_symbols=$export_symbols
9714fe24f8a2Smrg	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
9715b425557eSmrg	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
971634977a2fSmrg	fi
9717ee3138f1Smrg
9718fe24f8a2Smrg	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
971934977a2fSmrg	  # The given exports_symbols file has to be filtered, so filter it.
9720fe24f8a2Smrg	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
972134977a2fSmrg	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
9722fe24f8a2Smrg	  # 's' commands, which not all seds can handle. GNU sed should be fine
972334977a2fSmrg	  # though. Also, the filter scales superlinearly with the number of
972434977a2fSmrg	  # global variables. join(1) would be nice here, but unfortunately
972534977a2fSmrg	  # isn't a blessed tool.
972634977a2fSmrg	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
97273e72ca8cSmrg	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
972834977a2fSmrg	  export_symbols=$output_objdir/$libname.def
972934977a2fSmrg	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
973034977a2fSmrg	fi
9731ee3138f1Smrg
973234977a2fSmrg	tmp_deplibs=
973334977a2fSmrg	for test_deplib in $deplibs; do
973434977a2fSmrg	  case " $convenience " in
973534977a2fSmrg	  *" $test_deplib "*) ;;
973634977a2fSmrg	  *)
97373e72ca8cSmrg	    func_append tmp_deplibs " $test_deplib"
973834977a2fSmrg	    ;;
973934977a2fSmrg	  esac
974034977a2fSmrg	done
9741fe24f8a2Smrg	deplibs=$tmp_deplibs
9742ee3138f1Smrg
974334977a2fSmrg	if test -n "$convenience"; then
974434977a2fSmrg	  if test -n "$whole_archive_flag_spec" &&
9745fe24f8a2Smrg	    test yes = "$compiler_needs_object" &&
974634977a2fSmrg	    test -z "$libobjs"; then
974734977a2fSmrg	    # extract the archives, so we have objects to list.
974834977a2fSmrg	    # TODO: could optimize this to just extract one archive.
974934977a2fSmrg	    whole_archive_flag_spec=
975034977a2fSmrg	  fi
975134977a2fSmrg	  if test -n "$whole_archive_flag_spec"; then
975234977a2fSmrg	    save_libobjs=$libobjs
975334977a2fSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
975434977a2fSmrg	    test "X$libobjs" = "X " && libobjs=
975534977a2fSmrg	  else
9756fe24f8a2Smrg	    gentop=$output_objdir/${outputname}x
97573e72ca8cSmrg	    func_append generated " $gentop"
9758ee3138f1Smrg
975934977a2fSmrg	    func_extract_archives $gentop $convenience
97603e72ca8cSmrg	    func_append libobjs " $func_extract_archives_result"
976134977a2fSmrg	    test "X$libobjs" = "X " && libobjs=
976234977a2fSmrg	  fi
9763ee3138f1Smrg	fi
9764ee3138f1Smrg
9765fe24f8a2Smrg	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
976634977a2fSmrg	  eval flag=\"$thread_safe_flag_spec\"
97673e72ca8cSmrg	  func_append linker_flags " $flag"
9768ee3138f1Smrg	fi
9769ee3138f1Smrg
977034977a2fSmrg	# Make a backup of the uninstalled library when relinking
9771fe24f8a2Smrg	if test relink = "$opt_mode"; then
977234977a2fSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
977334977a2fSmrg	fi
9774ee3138f1Smrg
977534977a2fSmrg	# Do each of the archive commands.
9776fe24f8a2Smrg	if test yes = "$module" && test -n "$module_cmds"; then
977734977a2fSmrg	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
977834977a2fSmrg	    eval test_cmds=\"$module_expsym_cmds\"
977934977a2fSmrg	    cmds=$module_expsym_cmds
978034977a2fSmrg	  else
978134977a2fSmrg	    eval test_cmds=\"$module_cmds\"
978234977a2fSmrg	    cmds=$module_cmds
978334977a2fSmrg	  fi
9784ee3138f1Smrg	else
978534977a2fSmrg	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
978634977a2fSmrg	    eval test_cmds=\"$archive_expsym_cmds\"
978734977a2fSmrg	    cmds=$archive_expsym_cmds
978834977a2fSmrg	  else
978934977a2fSmrg	    eval test_cmds=\"$archive_cmds\"
979034977a2fSmrg	    cmds=$archive_cmds
979134977a2fSmrg	  fi
9792ee3138f1Smrg	fi
9793ee3138f1Smrg
9794fe24f8a2Smrg	if test : != "$skipped_export" &&
979534977a2fSmrg	   func_len " $test_cmds" &&
979634977a2fSmrg	   len=$func_len_result &&
979734977a2fSmrg	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
979834977a2fSmrg	  :
979934977a2fSmrg	else
980034977a2fSmrg	  # The command line is too long to link in one step, link piecewise
980134977a2fSmrg	  # or, if using GNU ld and skipped_export is not :, use a linker
980234977a2fSmrg	  # script.
9803ee3138f1Smrg
980434977a2fSmrg	  # Save the value of $output and $libobjs because we want to
980534977a2fSmrg	  # use them later.  If we have whole_archive_flag_spec, we
980634977a2fSmrg	  # want to use save_libobjs as it was before
980734977a2fSmrg	  # whole_archive_flag_spec was expanded, because we can't
980834977a2fSmrg	  # assume the linker understands whole_archive_flag_spec.
980934977a2fSmrg	  # This may have to be revisited, in case too many
981034977a2fSmrg	  # convenience libraries get linked in and end up exceeding
981134977a2fSmrg	  # the spec.
981234977a2fSmrg	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
981334977a2fSmrg	    save_libobjs=$libobjs
981434977a2fSmrg	  fi
981534977a2fSmrg	  save_output=$output
9816b425557eSmrg	  func_basename "$output"
9817b425557eSmrg	  output_la=$func_basename_result
9818ee3138f1Smrg
981934977a2fSmrg	  # Clear the reloadable object creation command queue and
982034977a2fSmrg	  # initialize k to one.
982134977a2fSmrg	  test_cmds=
982234977a2fSmrg	  concat_cmds=
982334977a2fSmrg	  objlist=
982434977a2fSmrg	  last_robj=
982534977a2fSmrg	  k=1
982634977a2fSmrg
9827fe24f8a2Smrg	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
9828fe24f8a2Smrg	    output=$output_objdir/$output_la.lnkscript
982934977a2fSmrg	    func_verbose "creating GNU ld script: $output"
9830b425557eSmrg	    echo 'INPUT (' > $output
983134977a2fSmrg	    for obj in $save_libobjs
9832ee3138f1Smrg	    do
98333e72ca8cSmrg	      func_to_tool_file "$obj"
98343e72ca8cSmrg	      $ECHO "$func_to_tool_file_result" >> $output
983534977a2fSmrg	    done
9836b425557eSmrg	    echo ')' >> $output
98373e72ca8cSmrg	    func_append delfiles " $output"
98383e72ca8cSmrg	    func_to_tool_file "$output"
98393e72ca8cSmrg	    output=$func_to_tool_file_result
9840fe24f8a2Smrg	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
9841fe24f8a2Smrg	    output=$output_objdir/$output_la.lnk
984234977a2fSmrg	    func_verbose "creating linker input file list: $output"
984334977a2fSmrg	    : > $output
984434977a2fSmrg	    set x $save_libobjs
984534977a2fSmrg	    shift
984634977a2fSmrg	    firstobj=
9847fe24f8a2Smrg	    if test yes = "$compiler_needs_object"; then
984834977a2fSmrg	      firstobj="$1 "
984934977a2fSmrg	      shift
985034977a2fSmrg	    fi
985134977a2fSmrg	    for obj
985234977a2fSmrg	    do
98533e72ca8cSmrg	      func_to_tool_file "$obj"
98543e72ca8cSmrg	      $ECHO "$func_to_tool_file_result" >> $output
985534977a2fSmrg	    done
98563e72ca8cSmrg	    func_append delfiles " $output"
98573e72ca8cSmrg	    func_to_tool_file "$output"
98583e72ca8cSmrg	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
985934977a2fSmrg	  else
986034977a2fSmrg	    if test -n "$save_libobjs"; then
986134977a2fSmrg	      func_verbose "creating reloadable object files..."
9862fe24f8a2Smrg	      output=$output_objdir/$output_la-$k.$objext
986334977a2fSmrg	      eval test_cmds=\"$reload_cmds\"
986434977a2fSmrg	      func_len " $test_cmds"
986534977a2fSmrg	      len0=$func_len_result
986634977a2fSmrg	      len=$len0
986734977a2fSmrg
986834977a2fSmrg	      # Loop over the list of objects to be linked.
986934977a2fSmrg	      for obj in $save_libobjs
987034977a2fSmrg	      do
987134977a2fSmrg		func_len " $obj"
987234977a2fSmrg		func_arith $len + $func_len_result
987334977a2fSmrg		len=$func_arith_result
9874fe24f8a2Smrg		if test -z "$objlist" ||
987534977a2fSmrg		   test "$len" -lt "$max_cmd_len"; then
987634977a2fSmrg		  func_append objlist " $obj"
987734977a2fSmrg		else
987834977a2fSmrg		  # The command $test_cmds is almost too long, add a
987934977a2fSmrg		  # command to the queue.
9880fe24f8a2Smrg		  if test 1 -eq "$k"; then
988134977a2fSmrg		    # The first file doesn't have a previous command to add.
9882b425557eSmrg		    reload_objs=$objlist
9883b425557eSmrg		    eval concat_cmds=\"$reload_cmds\"
988434977a2fSmrg		  else
988534977a2fSmrg		    # All subsequent reloadable object files will link in
988634977a2fSmrg		    # the last one created.
9887b425557eSmrg		    reload_objs="$objlist $last_robj"
9888b425557eSmrg		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
988934977a2fSmrg		  fi
9890fe24f8a2Smrg		  last_robj=$output_objdir/$output_la-$k.$objext
989134977a2fSmrg		  func_arith $k + 1
989234977a2fSmrg		  k=$func_arith_result
9893fe24f8a2Smrg		  output=$output_objdir/$output_la-$k.$objext
9894b425557eSmrg		  objlist=" $obj"
989534977a2fSmrg		  func_len " $last_robj"
989634977a2fSmrg		  func_arith $len0 + $func_len_result
989734977a2fSmrg		  len=$func_arith_result
989834977a2fSmrg		fi
989934977a2fSmrg	      done
990034977a2fSmrg	      # Handle the remaining objects by creating one last
990134977a2fSmrg	      # reloadable object file.  All subsequent reloadable object
990234977a2fSmrg	      # files will link in the last one created.
990334977a2fSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
9904b425557eSmrg	      reload_objs="$objlist $last_robj"
9905fe24f8a2Smrg	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
990634977a2fSmrg	      if test -n "$last_robj"; then
9907fe24f8a2Smrg	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
990834977a2fSmrg	      fi
99093e72ca8cSmrg	      func_append delfiles " $output"
9910ee3138f1Smrg
991134977a2fSmrg	    else
991234977a2fSmrg	      output=
991334977a2fSmrg	    fi
9914ee3138f1Smrg
9915fe24f8a2Smrg	    ${skipped_export-false} && {
9916fe24f8a2Smrg	      func_verbose "generating symbol list for '$libname.la'"
9917fe24f8a2Smrg	      export_symbols=$output_objdir/$libname.exp
991834977a2fSmrg	      $opt_dry_run || $RM $export_symbols
991934977a2fSmrg	      libobjs=$output
992034977a2fSmrg	      # Append the command to create the export file.
992134977a2fSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
992234977a2fSmrg	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
992334977a2fSmrg	      if test -n "$last_robj"; then
992434977a2fSmrg		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
992534977a2fSmrg	      fi
9926fe24f8a2Smrg	    }
9927ee3138f1Smrg
992834977a2fSmrg	    test -n "$save_libobjs" &&
992934977a2fSmrg	      func_verbose "creating a temporary reloadable object file: $output"
9930ee3138f1Smrg
993134977a2fSmrg	    # Loop through the commands generated above and execute them.
9932fe24f8a2Smrg	    save_ifs=$IFS; IFS='~'
993334977a2fSmrg	    for cmd in $concat_cmds; do
9934fe24f8a2Smrg	      IFS=$save_ifs
9935fe24f8a2Smrg	      $opt_quiet || {
993634977a2fSmrg		  func_quote_for_expand "$cmd"
993734977a2fSmrg		  eval "func_echo $func_quote_for_expand_result"
993834977a2fSmrg	      }
993934977a2fSmrg	      $opt_dry_run || eval "$cmd" || {
994034977a2fSmrg		lt_exit=$?
994134977a2fSmrg
994234977a2fSmrg		# Restore the uninstalled library and exit
9943fe24f8a2Smrg		if test relink = "$opt_mode"; then
994434977a2fSmrg		  ( cd "$output_objdir" && \
994534977a2fSmrg		    $RM "${realname}T" && \
994634977a2fSmrg		    $MV "${realname}U" "$realname" )
994734977a2fSmrg		fi
9948ee3138f1Smrg
994934977a2fSmrg		exit $lt_exit
995034977a2fSmrg	      }
995134977a2fSmrg	    done
9952fe24f8a2Smrg	    IFS=$save_ifs
9953ee3138f1Smrg
995434977a2fSmrg	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
995534977a2fSmrg	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
995634977a2fSmrg	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
9957ee3138f1Smrg	    fi
9958ee3138f1Smrg	  fi
9959ee3138f1Smrg
9960fe24f8a2Smrg          ${skipped_export-false} && {
996134977a2fSmrg	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
9962fe24f8a2Smrg	      tmp_export_symbols=$export_symbols
9963fe24f8a2Smrg	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
9964b425557eSmrg	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
996534977a2fSmrg	    fi
9966ee3138f1Smrg
996734977a2fSmrg	    if test -n "$orig_export_symbols"; then
996834977a2fSmrg	      # The given exports_symbols file has to be filtered, so filter it.
9969fe24f8a2Smrg	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
997034977a2fSmrg	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
9971fe24f8a2Smrg	      # 's' commands, which not all seds can handle. GNU sed should be fine
997234977a2fSmrg	      # though. Also, the filter scales superlinearly with the number of
997334977a2fSmrg	      # global variables. join(1) would be nice here, but unfortunately
997434977a2fSmrg	      # isn't a blessed tool.
997534977a2fSmrg	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
99763e72ca8cSmrg	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
997734977a2fSmrg	      export_symbols=$output_objdir/$libname.def
997834977a2fSmrg	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
997934977a2fSmrg	    fi
9980fe24f8a2Smrg	  }
9981ee3138f1Smrg
998234977a2fSmrg	  libobjs=$output
998334977a2fSmrg	  # Restore the value of output.
998434977a2fSmrg	  output=$save_output
9985ee3138f1Smrg
998634977a2fSmrg	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
998734977a2fSmrg	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
998834977a2fSmrg	    test "X$libobjs" = "X " && libobjs=
998934977a2fSmrg	  fi
999034977a2fSmrg	  # Expand the library linking commands again to reset the
999134977a2fSmrg	  # value of $libobjs for piecewise linking.
9992ee3138f1Smrg
999334977a2fSmrg	  # Do each of the archive commands.
9994fe24f8a2Smrg	  if test yes = "$module" && test -n "$module_cmds"; then
999534977a2fSmrg	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
999634977a2fSmrg	      cmds=$module_expsym_cmds
999734977a2fSmrg	    else
999834977a2fSmrg	      cmds=$module_cmds
9999ee3138f1Smrg	    fi
10000ee3138f1Smrg	  else
1000134977a2fSmrg	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
1000234977a2fSmrg	      cmds=$archive_expsym_cmds
1000334977a2fSmrg	    else
1000434977a2fSmrg	      cmds=$archive_cmds
1000534977a2fSmrg	    fi
10006ee3138f1Smrg	  fi
1000734977a2fSmrg	fi
10008ee3138f1Smrg
1000934977a2fSmrg	if test -n "$delfiles"; then
1001034977a2fSmrg	  # Append the command to remove temporary files to $cmds.
1001134977a2fSmrg	  eval cmds=\"\$cmds~\$RM $delfiles\"
1001234977a2fSmrg	fi
10013ee3138f1Smrg
1001434977a2fSmrg	# Add any objects from preloaded convenience libraries
1001534977a2fSmrg	if test -n "$dlprefiles"; then
10016fe24f8a2Smrg	  gentop=$output_objdir/${outputname}x
100173e72ca8cSmrg	  func_append generated " $gentop"
10018ee3138f1Smrg
1001934977a2fSmrg	  func_extract_archives $gentop $dlprefiles
100203e72ca8cSmrg	  func_append libobjs " $func_extract_archives_result"
1002134977a2fSmrg	  test "X$libobjs" = "X " && libobjs=
1002234977a2fSmrg	fi
10023ee3138f1Smrg
10024fe24f8a2Smrg	save_ifs=$IFS; IFS='~'
1002534977a2fSmrg	for cmd in $cmds; do
10026fe24f8a2Smrg	  IFS=$sp$nl
1002734977a2fSmrg	  eval cmd=\"$cmd\"
10028fe24f8a2Smrg	  IFS=$save_ifs
10029fe24f8a2Smrg	  $opt_quiet || {
1003034977a2fSmrg	    func_quote_for_expand "$cmd"
1003134977a2fSmrg	    eval "func_echo $func_quote_for_expand_result"
1003234977a2fSmrg	  }
1003334977a2fSmrg	  $opt_dry_run || eval "$cmd" || {
1003434977a2fSmrg	    lt_exit=$?
10035ee3138f1Smrg
1003634977a2fSmrg	    # Restore the uninstalled library and exit
10037fe24f8a2Smrg	    if test relink = "$opt_mode"; then
1003834977a2fSmrg	      ( cd "$output_objdir" && \
1003934977a2fSmrg	        $RM "${realname}T" && \
1004034977a2fSmrg		$MV "${realname}U" "$realname" )
1004134977a2fSmrg	    fi
10042ee3138f1Smrg
1004334977a2fSmrg	    exit $lt_exit
1004434977a2fSmrg	  }
1004534977a2fSmrg	done
10046fe24f8a2Smrg	IFS=$save_ifs
10047ee3138f1Smrg
1004834977a2fSmrg	# Restore the uninstalled library and exit
10049fe24f8a2Smrg	if test relink = "$opt_mode"; then
1005034977a2fSmrg	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
10051ee3138f1Smrg
1005234977a2fSmrg	  if test -n "$convenience"; then
1005334977a2fSmrg	    if test -z "$whole_archive_flag_spec"; then
1005434977a2fSmrg	      func_show_eval '${RM}r "$gentop"'
1005534977a2fSmrg	    fi
1005634977a2fSmrg	  fi
10057ee3138f1Smrg
1005834977a2fSmrg	  exit $EXIT_SUCCESS
1005934977a2fSmrg	fi
1006034977a2fSmrg
1006134977a2fSmrg	# Create links to the real library.
1006234977a2fSmrg	for linkname in $linknames; do
1006334977a2fSmrg	  if test "$realname" != "$linkname"; then
1006434977a2fSmrg	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
10065ee3138f1Smrg	  fi
10066ee3138f1Smrg	done
10067ee3138f1Smrg
1006834977a2fSmrg	# If -module or -export-dynamic was specified, set the dlname.
10069fe24f8a2Smrg	if test yes = "$module" || test yes = "$export_dynamic"; then
1007034977a2fSmrg	  # On all known operating systems, these are identical.
10071fe24f8a2Smrg	  dlname=$soname
1007234977a2fSmrg	fi
1007334977a2fSmrg      fi
10074ee3138f1Smrg      ;;
10075ee3138f1Smrg
1007634977a2fSmrg    obj)
10077fe24f8a2Smrg      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10078fe24f8a2Smrg	func_warning "'-dlopen' is ignored for objects"
1007934977a2fSmrg      fi
10080ee3138f1Smrg
1008134977a2fSmrg      case " $deplibs" in
1008234977a2fSmrg      *\ -l* | *\ -L*)
10083fe24f8a2Smrg	func_warning "'-l' and '-L' are ignored for objects" ;;
10084ee3138f1Smrg      esac
10085ee3138f1Smrg
1008634977a2fSmrg      test -n "$rpath" && \
10087fe24f8a2Smrg	func_warning "'-rpath' is ignored for objects"
1008834977a2fSmrg
1008934977a2fSmrg      test -n "$xrpath" && \
10090fe24f8a2Smrg	func_warning "'-R' is ignored for objects"
10091ee3138f1Smrg
1009234977a2fSmrg      test -n "$vinfo" && \
10093fe24f8a2Smrg	func_warning "'-version-info' is ignored for objects"
10094ee3138f1Smrg
1009534977a2fSmrg      test -n "$release" && \
10096fe24f8a2Smrg	func_warning "'-release' is ignored for objects"
1009734977a2fSmrg
1009834977a2fSmrg      case $output in
1009934977a2fSmrg      *.lo)
1010034977a2fSmrg	test -n "$objs$old_deplibs" && \
10101fe24f8a2Smrg	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
1010234977a2fSmrg
1010334977a2fSmrg	libobj=$output
1010434977a2fSmrg	func_lo2o "$libobj"
1010534977a2fSmrg	obj=$func_lo2o_result
10106ee3138f1Smrg	;;
10107ee3138f1Smrg      *)
1010834977a2fSmrg	libobj=
10109fe24f8a2Smrg	obj=$output
10110ee3138f1Smrg	;;
10111ee3138f1Smrg      esac
10112ee3138f1Smrg
1011334977a2fSmrg      # Delete the old objects.
1011434977a2fSmrg      $opt_dry_run || $RM $obj $libobj
10115ee3138f1Smrg
1011634977a2fSmrg      # Objects from convenience libraries.  This assumes
1011734977a2fSmrg      # single-version convenience libraries.  Whenever we create
1011834977a2fSmrg      # different ones for PIC/non-PIC, this we'll have to duplicate
1011934977a2fSmrg      # the extraction.
1012034977a2fSmrg      reload_conv_objs=
1012134977a2fSmrg      gentop=
10122fe24f8a2Smrg      # if reload_cmds runs $LD directly, get rid of -Wl from
10123fe24f8a2Smrg      # whole_archive_flag_spec and hope we can get by with turning comma
10124fe24f8a2Smrg      # into space.
10125fe24f8a2Smrg      case $reload_cmds in
10126fe24f8a2Smrg        *\$LD[\ \$]*) wl= ;;
10127fe24f8a2Smrg      esac
1012834977a2fSmrg      if test -n "$convenience"; then
1012934977a2fSmrg	if test -n "$whole_archive_flag_spec"; then
1013034977a2fSmrg	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10131fe24f8a2Smrg	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10132fe24f8a2Smrg	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
1013334977a2fSmrg	else
10134fe24f8a2Smrg	  gentop=$output_objdir/${obj}x
101353e72ca8cSmrg	  func_append generated " $gentop"
10136ee3138f1Smrg
1013734977a2fSmrg	  func_extract_archives $gentop $convenience
1013834977a2fSmrg	  reload_conv_objs="$reload_objs $func_extract_archives_result"
1013934977a2fSmrg	fi
10140ee3138f1Smrg      fi
10141ee3138f1Smrg
101423e72ca8cSmrg      # If we're not building shared, we need to use non_pic_objs
10143fe24f8a2Smrg      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
101443e72ca8cSmrg
1014534977a2fSmrg      # Create the old-style object.
10146fe24f8a2Smrg      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
10147ee3138f1Smrg
10148fe24f8a2Smrg      output=$obj
1014934977a2fSmrg      func_execute_cmds "$reload_cmds" 'exit $?'
10150ee3138f1Smrg
1015134977a2fSmrg      # Exit if we aren't doing a library object file.
1015234977a2fSmrg      if test -z "$libobj"; then
1015334977a2fSmrg	if test -n "$gentop"; then
1015434977a2fSmrg	  func_show_eval '${RM}r "$gentop"'
1015534977a2fSmrg	fi
1015634977a2fSmrg
1015734977a2fSmrg	exit $EXIT_SUCCESS
10158ee3138f1Smrg      fi
1015934977a2fSmrg
10160fe24f8a2Smrg      test yes = "$build_libtool_libs" || {
1016134977a2fSmrg	if test -n "$gentop"; then
1016234977a2fSmrg	  func_show_eval '${RM}r "$gentop"'
1016334977a2fSmrg	fi
1016434977a2fSmrg
1016534977a2fSmrg	# Create an invalid libtool object if no PIC, so that we don't
1016634977a2fSmrg	# accidentally link it into a program.
1016734977a2fSmrg	# $show "echo timestamp > $libobj"
1016834977a2fSmrg	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
1016934977a2fSmrg	exit $EXIT_SUCCESS
10170fe24f8a2Smrg      }
1017134977a2fSmrg
10172fe24f8a2Smrg      if test -n "$pic_flag" || test default != "$pic_mode"; then
1017334977a2fSmrg	# Only do commands if we really have different PIC objects.
1017434977a2fSmrg	reload_objs="$libobjs $reload_conv_objs"
10175fe24f8a2Smrg	output=$libobj
1017634977a2fSmrg	func_execute_cmds "$reload_cmds" 'exit $?'
1017734977a2fSmrg      fi
1017834977a2fSmrg
1017934977a2fSmrg      if test -n "$gentop"; then
1018034977a2fSmrg	func_show_eval '${RM}r "$gentop"'
1018134977a2fSmrg      fi
1018234977a2fSmrg
1018334977a2fSmrg      exit $EXIT_SUCCESS
10184ee3138f1Smrg      ;;
10185ee3138f1Smrg
1018634977a2fSmrg    prog)
1018734977a2fSmrg      case $host in
1018834977a2fSmrg	*cygwin*) func_stripname '' '.exe' "$output"
1018934977a2fSmrg	          output=$func_stripname_result.exe;;
1019034977a2fSmrg      esac
1019134977a2fSmrg      test -n "$vinfo" && \
10192fe24f8a2Smrg	func_warning "'-version-info' is ignored for programs"
10193ee3138f1Smrg
1019434977a2fSmrg      test -n "$release" && \
10195fe24f8a2Smrg	func_warning "'-release' is ignored for programs"
10196ee3138f1Smrg
10197fe24f8a2Smrg      $preload \
10198fe24f8a2Smrg	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10199fe24f8a2Smrg	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
1020034977a2fSmrg
1020134977a2fSmrg      case $host in
1020234977a2fSmrg      *-*-rhapsody* | *-*-darwin1.[012])
1020334977a2fSmrg	# On Rhapsody replace the C library is the System framework
10204b425557eSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
10205b425557eSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
10206ee3138f1Smrg	;;
1020734977a2fSmrg      esac
10208ee3138f1Smrg
1020934977a2fSmrg      case $host in
1021034977a2fSmrg      *-*-darwin*)
1021134977a2fSmrg	# Don't allow lazy linking, it breaks C++ global constructors
1021234977a2fSmrg	# But is supposedly fixed on 10.4 or later (yay!).
10213fe24f8a2Smrg	if test CXX = "$tagname"; then
1021434977a2fSmrg	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
1021534977a2fSmrg	    10.[0123])
10216fe24f8a2Smrg	      func_append compile_command " $wl-bind_at_load"
10217fe24f8a2Smrg	      func_append finalize_command " $wl-bind_at_load"
1021834977a2fSmrg	    ;;
1021934977a2fSmrg	  esac
10220ee3138f1Smrg	fi
1022134977a2fSmrg	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
10222b425557eSmrg	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
10223b425557eSmrg	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
1022434977a2fSmrg	;;
1022534977a2fSmrg      esac
10226ee3138f1Smrg
10227ee3138f1Smrg
1022834977a2fSmrg      # move library search paths that coincide with paths to not yet
1022934977a2fSmrg      # installed libraries to the beginning of the library search list
1023034977a2fSmrg      new_libs=
1023134977a2fSmrg      for path in $notinst_path; do
1023234977a2fSmrg	case " $new_libs " in
1023334977a2fSmrg	*" -L$path/$objdir "*) ;;
1023434977a2fSmrg	*)
1023534977a2fSmrg	  case " $compile_deplibs " in
1023634977a2fSmrg	  *" -L$path/$objdir "*)
102373e72ca8cSmrg	    func_append new_libs " -L$path/$objdir" ;;
10238ee3138f1Smrg	  esac
1023934977a2fSmrg	  ;;
1024034977a2fSmrg	esac
1024134977a2fSmrg      done
1024234977a2fSmrg      for deplib in $compile_deplibs; do
1024334977a2fSmrg	case $deplib in
1024434977a2fSmrg	-L*)
1024534977a2fSmrg	  case " $new_libs " in
1024634977a2fSmrg	  *" $deplib "*) ;;
102473e72ca8cSmrg	  *) func_append new_libs " $deplib" ;;
10248ee3138f1Smrg	  esac
1024934977a2fSmrg	  ;;
102503e72ca8cSmrg	*) func_append new_libs " $deplib" ;;
1025134977a2fSmrg	esac
1025234977a2fSmrg      done
10253fe24f8a2Smrg      compile_deplibs=$new_libs
10254ee3138f1Smrg
10255ee3138f1Smrg
102563e72ca8cSmrg      func_append compile_command " $compile_deplibs"
102573e72ca8cSmrg      func_append finalize_command " $finalize_deplibs"
10258ee3138f1Smrg
1025934977a2fSmrg      if test -n "$rpath$xrpath"; then
1026034977a2fSmrg	# If the user specified any rpath flags, then add them.
1026134977a2fSmrg	for libdir in $rpath $xrpath; do
1026234977a2fSmrg	  # This is the magic to use -rpath.
1026334977a2fSmrg	  case "$finalize_rpath " in
1026434977a2fSmrg	  *" $libdir "*) ;;
102653e72ca8cSmrg	  *) func_append finalize_rpath " $libdir" ;;
1026634977a2fSmrg	  esac
1026734977a2fSmrg	done
1026834977a2fSmrg      fi
10269ee3138f1Smrg
1027034977a2fSmrg      # Now hardcode the library paths
1027134977a2fSmrg      rpath=
1027234977a2fSmrg      hardcode_libdirs=
1027334977a2fSmrg      for libdir in $compile_rpath $finalize_rpath; do
1027434977a2fSmrg	if test -n "$hardcode_libdir_flag_spec"; then
1027534977a2fSmrg	  if test -n "$hardcode_libdir_separator"; then
1027634977a2fSmrg	    if test -z "$hardcode_libdirs"; then
10277fe24f8a2Smrg	      hardcode_libdirs=$libdir
1027834977a2fSmrg	    else
1027934977a2fSmrg	      # Just accumulate the unique libdirs.
1028034977a2fSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1028134977a2fSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1028234977a2fSmrg		;;
1028334977a2fSmrg	      *)
102843e72ca8cSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1028534977a2fSmrg		;;
1028634977a2fSmrg	      esac
1028734977a2fSmrg	    fi
10288ee3138f1Smrg	  else
1028934977a2fSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
102903e72ca8cSmrg	    func_append rpath " $flag"
10291ee3138f1Smrg	  fi
1029234977a2fSmrg	elif test -n "$runpath_var"; then
1029334977a2fSmrg	  case "$perm_rpath " in
1029434977a2fSmrg	  *" $libdir "*) ;;
102953e72ca8cSmrg	  *) func_append perm_rpath " $libdir" ;;
1029634977a2fSmrg	  esac
1029734977a2fSmrg	fi
1029834977a2fSmrg	case $host in
1029934977a2fSmrg	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10300fe24f8a2Smrg	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
1030134977a2fSmrg	  case :$dllsearchpath: in
1030234977a2fSmrg	  *":$libdir:"*) ;;
1030334977a2fSmrg	  ::) dllsearchpath=$libdir;;
103043e72ca8cSmrg	  *) func_append dllsearchpath ":$libdir";;
1030534977a2fSmrg	  esac
1030634977a2fSmrg	  case :$dllsearchpath: in
1030734977a2fSmrg	  *":$testbindir:"*) ;;
1030834977a2fSmrg	  ::) dllsearchpath=$testbindir;;
103093e72ca8cSmrg	  *) func_append dllsearchpath ":$testbindir";;
1031034977a2fSmrg	  esac
1031134977a2fSmrg	  ;;
1031234977a2fSmrg	esac
1031334977a2fSmrg      done
1031434977a2fSmrg      # Substitute the hardcoded libdirs into the rpath.
1031534977a2fSmrg      if test -n "$hardcode_libdir_separator" &&
1031634977a2fSmrg	 test -n "$hardcode_libdirs"; then
10317fe24f8a2Smrg	libdir=$hardcode_libdirs
1031834977a2fSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1031934977a2fSmrg      fi
10320fe24f8a2Smrg      compile_rpath=$rpath
10321ee3138f1Smrg
1032234977a2fSmrg      rpath=
1032334977a2fSmrg      hardcode_libdirs=
1032434977a2fSmrg      for libdir in $finalize_rpath; do
1032534977a2fSmrg	if test -n "$hardcode_libdir_flag_spec"; then
1032634977a2fSmrg	  if test -n "$hardcode_libdir_separator"; then
1032734977a2fSmrg	    if test -z "$hardcode_libdirs"; then
10328fe24f8a2Smrg	      hardcode_libdirs=$libdir
1032934977a2fSmrg	    else
1033034977a2fSmrg	      # Just accumulate the unique libdirs.
1033134977a2fSmrg	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
1033234977a2fSmrg	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
1033334977a2fSmrg		;;
1033434977a2fSmrg	      *)
103353e72ca8cSmrg		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
1033634977a2fSmrg		;;
1033734977a2fSmrg	      esac
1033834977a2fSmrg	    fi
10339ee3138f1Smrg	  else
1034034977a2fSmrg	    eval flag=\"$hardcode_libdir_flag_spec\"
103413e72ca8cSmrg	    func_append rpath " $flag"
10342ee3138f1Smrg	  fi
1034334977a2fSmrg	elif test -n "$runpath_var"; then
1034434977a2fSmrg	  case "$finalize_perm_rpath " in
1034534977a2fSmrg	  *" $libdir "*) ;;
103463e72ca8cSmrg	  *) func_append finalize_perm_rpath " $libdir" ;;
1034734977a2fSmrg	  esac
10348ee3138f1Smrg	fi
1034934977a2fSmrg      done
1035034977a2fSmrg      # Substitute the hardcoded libdirs into the rpath.
1035134977a2fSmrg      if test -n "$hardcode_libdir_separator" &&
1035234977a2fSmrg	 test -n "$hardcode_libdirs"; then
10353fe24f8a2Smrg	libdir=$hardcode_libdirs
1035434977a2fSmrg	eval rpath=\" $hardcode_libdir_flag_spec\"
1035534977a2fSmrg      fi
10356fe24f8a2Smrg      finalize_rpath=$rpath
10357ee3138f1Smrg
10358fe24f8a2Smrg      if test -n "$libobjs" && test yes = "$build_old_libs"; then
1035934977a2fSmrg	# Transform all the library objects into standard objects.
10360b425557eSmrg	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
10361b425557eSmrg	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
1036234977a2fSmrg      fi
10363ee3138f1Smrg
10364fe24f8a2Smrg      func_generate_dlsyms "$outputname" "@PROGRAM@" false
10365ee3138f1Smrg
1036634977a2fSmrg      # template prelinking step
1036734977a2fSmrg      if test -n "$prelink_cmds"; then
1036834977a2fSmrg	func_execute_cmds "$prelink_cmds" 'exit $?'
1036934977a2fSmrg      fi
10370ee3138f1Smrg
10371fe24f8a2Smrg      wrappers_required=:
1037234977a2fSmrg      case $host in
10373b425557eSmrg      *cegcc* | *mingw32ce*)
10374b425557eSmrg        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10375fe24f8a2Smrg        wrappers_required=false
10376b425557eSmrg        ;;
1037734977a2fSmrg      *cygwin* | *mingw* )
10378fe24f8a2Smrg        test yes = "$build_libtool_libs" || wrappers_required=false
1037934977a2fSmrg        ;;
1038034977a2fSmrg      *)
10381fe24f8a2Smrg        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10382fe24f8a2Smrg          wrappers_required=false
1038334977a2fSmrg        fi
1038434977a2fSmrg        ;;
1038534977a2fSmrg      esac
10386fe24f8a2Smrg      $wrappers_required || {
1038734977a2fSmrg	# Replace the output file specification.
10388b425557eSmrg	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10389fe24f8a2Smrg	link_command=$compile_command$compile_rpath
10390ee3138f1Smrg
1039134977a2fSmrg	# We have no uninstalled library dependencies, so finalize right now.
1039234977a2fSmrg	exit_status=0
1039334977a2fSmrg	func_show_eval "$link_command" 'exit_status=$?'
10394ee3138f1Smrg
103953e72ca8cSmrg	if test -n "$postlink_cmds"; then
103963e72ca8cSmrg	  func_to_tool_file "$output"
103973e72ca8cSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
103983e72ca8cSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
103993e72ca8cSmrg	fi
104003e72ca8cSmrg
1040134977a2fSmrg	# Delete the generated files.
10402fe24f8a2Smrg	if test -f "$output_objdir/${outputname}S.$objext"; then
10403fe24f8a2Smrg	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
10404ee3138f1Smrg	fi
10405ee3138f1Smrg
1040634977a2fSmrg	exit $exit_status
10407fe24f8a2Smrg      }
10408ee3138f1Smrg
1040934977a2fSmrg      if test -n "$compile_shlibpath$finalize_shlibpath"; then
1041034977a2fSmrg	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
1041134977a2fSmrg      fi
1041234977a2fSmrg      if test -n "$finalize_shlibpath"; then
1041334977a2fSmrg	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
1041434977a2fSmrg      fi
10415ee3138f1Smrg
1041634977a2fSmrg      compile_var=
1041734977a2fSmrg      finalize_var=
1041834977a2fSmrg      if test -n "$runpath_var"; then
1041934977a2fSmrg	if test -n "$perm_rpath"; then
1042034977a2fSmrg	  # We should set the runpath_var.
1042134977a2fSmrg	  rpath=
1042234977a2fSmrg	  for dir in $perm_rpath; do
104233e72ca8cSmrg	    func_append rpath "$dir:"
1042434977a2fSmrg	  done
1042534977a2fSmrg	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
10426ee3138f1Smrg	fi
1042734977a2fSmrg	if test -n "$finalize_perm_rpath"; then
1042834977a2fSmrg	  # We should set the runpath_var.
1042934977a2fSmrg	  rpath=
1043034977a2fSmrg	  for dir in $finalize_perm_rpath; do
104313e72ca8cSmrg	    func_append rpath "$dir:"
1043234977a2fSmrg	  done
1043334977a2fSmrg	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
10434ee3138f1Smrg	fi
1043534977a2fSmrg      fi
10436ee3138f1Smrg
10437fe24f8a2Smrg      if test yes = "$no_install"; then
1043834977a2fSmrg	# We don't need to create a wrapper script.
10439fe24f8a2Smrg	link_command=$compile_var$compile_command$compile_rpath
1044034977a2fSmrg	# Replace the output file specification.
10441b425557eSmrg	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
1044234977a2fSmrg	# Delete the old output file.
1044334977a2fSmrg	$opt_dry_run || $RM $output
1044434977a2fSmrg	# Link the executable and exit
1044534977a2fSmrg	func_show_eval "$link_command" 'exit $?'
104463e72ca8cSmrg
104473e72ca8cSmrg	if test -n "$postlink_cmds"; then
104483e72ca8cSmrg	  func_to_tool_file "$output"
104493e72ca8cSmrg	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
104503e72ca8cSmrg	  func_execute_cmds "$postlink_cmds" 'exit $?'
104513e72ca8cSmrg	fi
104523e72ca8cSmrg
10453ee3138f1Smrg	exit $EXIT_SUCCESS
1045434977a2fSmrg      fi
10455ee3138f1Smrg
10456fe24f8a2Smrg      case $hardcode_action,$fast_install in
10457fe24f8a2Smrg        relink,*)
10458fe24f8a2Smrg	  # Fast installation is not supported
10459fe24f8a2Smrg	  link_command=$compile_var$compile_command$compile_rpath
10460fe24f8a2Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
1046134977a2fSmrg
10462fe24f8a2Smrg	  func_warning "this platform does not like uninstalled shared libraries"
10463fe24f8a2Smrg	  func_warning "'$output' will be relinked during installation"
10464fe24f8a2Smrg	  ;;
10465fe24f8a2Smrg        *,yes)
10466fe24f8a2Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10467fe24f8a2Smrg	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10468fe24f8a2Smrg          ;;
10469fe24f8a2Smrg	*,no)
10470fe24f8a2Smrg	  link_command=$compile_var$compile_command$compile_rpath
10471fe24f8a2Smrg	  relink_command=$finalize_var$finalize_command$finalize_rpath
10472fe24f8a2Smrg          ;;
10473fe24f8a2Smrg	*,needless)
10474fe24f8a2Smrg	  link_command=$finalize_var$compile_command$finalize_rpath
10475fe24f8a2Smrg	  relink_command=
10476fe24f8a2Smrg          ;;
10477fe24f8a2Smrg      esac
10478ee3138f1Smrg
1047934977a2fSmrg      # Replace the output file specification.
10480b425557eSmrg      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
10481ee3138f1Smrg
1048234977a2fSmrg      # Delete the old output files.
1048334977a2fSmrg      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
10484ee3138f1Smrg
1048534977a2fSmrg      func_show_eval "$link_command" 'exit $?'
10486ee3138f1Smrg
104873e72ca8cSmrg      if test -n "$postlink_cmds"; then
104883e72ca8cSmrg	func_to_tool_file "$output_objdir/$outputname"
104893e72ca8cSmrg	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'`
104903e72ca8cSmrg	func_execute_cmds "$postlink_cmds" 'exit $?'
104913e72ca8cSmrg      fi
104923e72ca8cSmrg
1049334977a2fSmrg      # Now create the wrapper script.
1049434977a2fSmrg      func_verbose "creating $output"
10495ee3138f1Smrg
1049634977a2fSmrg      # Quote the relink command for shipping.
1049734977a2fSmrg      if test -n "$relink_command"; then
1049834977a2fSmrg	# Preserve any variables that may affect compiler behavior
1049934977a2fSmrg	for var in $variables_saved_for_relink; do
1050034977a2fSmrg	  if eval test -z \"\${$var+set}\"; then
1050134977a2fSmrg	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1050234977a2fSmrg	  elif eval var_value=\$$var; test -z "$var_value"; then
1050334977a2fSmrg	    relink_command="$var=; export $var; $relink_command"
10504ee3138f1Smrg	  else
1050534977a2fSmrg	    func_quote_for_eval "$var_value"
1050634977a2fSmrg	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10507ee3138f1Smrg	  fi
1050834977a2fSmrg	done
1050934977a2fSmrg	relink_command="(cd `pwd`; $relink_command)"
10510b425557eSmrg	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
1051134977a2fSmrg      fi
1051234977a2fSmrg
1051334977a2fSmrg      # Only actually do things if not in dry run mode.
1051434977a2fSmrg      $opt_dry_run || {
1051534977a2fSmrg	# win32 will think the script is a binary if it has
1051634977a2fSmrg	# a .exe suffix, so we strip it off here.
1051734977a2fSmrg	case $output in
1051834977a2fSmrg	  *.exe) func_stripname '' '.exe' "$output"
1051934977a2fSmrg	         output=$func_stripname_result ;;
1052034977a2fSmrg	esac
1052134977a2fSmrg	# test for cygwin because mv fails w/o .exe extensions
1052234977a2fSmrg	case $host in
1052334977a2fSmrg	  *cygwin*)
1052434977a2fSmrg	    exeext=.exe
1052534977a2fSmrg	    func_stripname '' '.exe' "$outputname"
1052634977a2fSmrg	    outputname=$func_stripname_result ;;
1052734977a2fSmrg	  *) exeext= ;;
10528ee3138f1Smrg	esac
1052934977a2fSmrg	case $host in
1053034977a2fSmrg	  *cygwin* | *mingw* )
1053134977a2fSmrg	    func_dirname_and_basename "$output" "" "."
1053234977a2fSmrg	    output_name=$func_basename_result
1053334977a2fSmrg	    output_path=$func_dirname_result
10534fe24f8a2Smrg	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10535fe24f8a2Smrg	    cwrapper=$output_path/$output_name.exe
1053634977a2fSmrg	    $RM $cwrappersource $cwrapper
1053734977a2fSmrg	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
1053834977a2fSmrg
1053934977a2fSmrg	    func_emit_cwrapperexe_src > $cwrappersource
1054034977a2fSmrg
1054134977a2fSmrg	    # The wrapper executable is built using the $host compiler,
1054234977a2fSmrg	    # because it contains $host paths and files. If cross-
1054334977a2fSmrg	    # compiling, it, like the target executable, must be
1054434977a2fSmrg	    # executed on the $host or under an emulation environment.
1054534977a2fSmrg	    $opt_dry_run || {
1054634977a2fSmrg	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
1054734977a2fSmrg	      $STRIP $cwrapper
1054834977a2fSmrg	    }
10549ee3138f1Smrg
1055034977a2fSmrg	    # Now, create the wrapper script for func_source use:
1055134977a2fSmrg	    func_ltwrapper_scriptname $cwrapper
1055234977a2fSmrg	    $RM $func_ltwrapper_scriptname_result
1055334977a2fSmrg	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
1055434977a2fSmrg	    $opt_dry_run || {
1055534977a2fSmrg	      # note: this script will not be executed, so do not chmod.
10556fe24f8a2Smrg	      if test "x$build" = "x$host"; then
1055734977a2fSmrg		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
1055834977a2fSmrg	      else
1055934977a2fSmrg		func_emit_wrapper no > $func_ltwrapper_scriptname_result
1056034977a2fSmrg	      fi
1056134977a2fSmrg	    }
1056234977a2fSmrg	  ;;
1056334977a2fSmrg	  * )
1056434977a2fSmrg	    $RM $output
1056534977a2fSmrg	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
10566ee3138f1Smrg
1056734977a2fSmrg	    func_emit_wrapper no > $output
1056834977a2fSmrg	    chmod +x $output
1056934977a2fSmrg	  ;;
1057034977a2fSmrg	esac
1057134977a2fSmrg      }
1057234977a2fSmrg      exit $EXIT_SUCCESS
1057334977a2fSmrg      ;;
1057434977a2fSmrg    esac
10575ee3138f1Smrg
1057634977a2fSmrg    # See if we need to build an old-fashioned archive.
1057734977a2fSmrg    for oldlib in $oldlibs; do
10578ee3138f1Smrg
10579fe24f8a2Smrg      case $build_libtool_libs in
10580fe24f8a2Smrg        convenience)
10581fe24f8a2Smrg	  oldobjs="$libobjs_save $symfileobj"
10582fe24f8a2Smrg	  addlibs=$convenience
1058334977a2fSmrg	  build_libtool_libs=no
10584fe24f8a2Smrg	  ;;
10585fe24f8a2Smrg	module)
10586fe24f8a2Smrg	  oldobjs=$libobjs_save
10587fe24f8a2Smrg	  addlibs=$old_convenience
10588fe24f8a2Smrg	  build_libtool_libs=no
10589fe24f8a2Smrg          ;;
10590fe24f8a2Smrg	*)
1059134977a2fSmrg	  oldobjs="$old_deplibs $non_pic_objects"
10592fe24f8a2Smrg	  $preload && test -f "$symfileobj" \
10593fe24f8a2Smrg	    && func_append oldobjs " $symfileobj"
10594fe24f8a2Smrg	  addlibs=$old_convenience
10595fe24f8a2Smrg	  ;;
10596fe24f8a2Smrg      esac
10597ee3138f1Smrg
1059834977a2fSmrg      if test -n "$addlibs"; then
10599fe24f8a2Smrg	gentop=$output_objdir/${outputname}x
106003e72ca8cSmrg	func_append generated " $gentop"
10601ee3138f1Smrg
1060234977a2fSmrg	func_extract_archives $gentop $addlibs
106033e72ca8cSmrg	func_append oldobjs " $func_extract_archives_result"
1060434977a2fSmrg      fi
10605ee3138f1Smrg
1060634977a2fSmrg      # Do each command in the archive commands.
10607fe24f8a2Smrg      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
1060834977a2fSmrg	cmds=$old_archive_from_new_cmds
1060934977a2fSmrg      else
10610ee3138f1Smrg
1061134977a2fSmrg	# Add any objects from preloaded convenience libraries
1061234977a2fSmrg	if test -n "$dlprefiles"; then
10613fe24f8a2Smrg	  gentop=$output_objdir/${outputname}x
106143e72ca8cSmrg	  func_append generated " $gentop"
10615ee3138f1Smrg
1061634977a2fSmrg	  func_extract_archives $gentop $dlprefiles
106173e72ca8cSmrg	  func_append oldobjs " $func_extract_archives_result"
1061834977a2fSmrg	fi
10619ee3138f1Smrg
1062034977a2fSmrg	# POSIX demands no paths to be encoded in archives.  We have
1062134977a2fSmrg	# to avoid creating archives with duplicate basenames if we
1062234977a2fSmrg	# might have to extract them afterwards, e.g., when creating a
1062334977a2fSmrg	# static archive out of a convenience library, or when linking
1062434977a2fSmrg	# the entirety of a libtool archive into another (currently
1062534977a2fSmrg	# not supported by libtool).
1062634977a2fSmrg	if (for obj in $oldobjs
1062734977a2fSmrg	    do
1062834977a2fSmrg	      func_basename "$obj"
1062934977a2fSmrg	      $ECHO "$func_basename_result"
1063034977a2fSmrg	    done | sort | sort -uc >/dev/null 2>&1); then
1063134977a2fSmrg	  :
1063234977a2fSmrg	else
10633b425557eSmrg	  echo "copying selected object files to avoid basename conflicts..."
10634fe24f8a2Smrg	  gentop=$output_objdir/${outputname}x
106353e72ca8cSmrg	  func_append generated " $gentop"
1063634977a2fSmrg	  func_mkdir_p "$gentop"
1063734977a2fSmrg	  save_oldobjs=$oldobjs
1063834977a2fSmrg	  oldobjs=
1063934977a2fSmrg	  counter=1
1064034977a2fSmrg	  for obj in $save_oldobjs
1064134977a2fSmrg	  do
1064234977a2fSmrg	    func_basename "$obj"
10643fe24f8a2Smrg	    objbase=$func_basename_result
1064434977a2fSmrg	    case " $oldobjs " in
1064534977a2fSmrg	    " ") oldobjs=$obj ;;
1064634977a2fSmrg	    *[\ /]"$objbase "*)
1064734977a2fSmrg	      while :; do
1064834977a2fSmrg		# Make sure we don't pick an alternate name that also
1064934977a2fSmrg		# overlaps.
1065034977a2fSmrg		newobj=lt$counter-$objbase
1065134977a2fSmrg		func_arith $counter + 1
1065234977a2fSmrg		counter=$func_arith_result
1065334977a2fSmrg		case " $oldobjs " in
1065434977a2fSmrg		*[\ /]"$newobj "*) ;;
1065534977a2fSmrg		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
1065634977a2fSmrg		esac
1065734977a2fSmrg	      done
1065834977a2fSmrg	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
106593e72ca8cSmrg	      func_append oldobjs " $gentop/$newobj"
1066034977a2fSmrg	      ;;
106613e72ca8cSmrg	    *) func_append oldobjs " $obj" ;;
1066234977a2fSmrg	    esac
10663ee3138f1Smrg	  done
10664ee3138f1Smrg	fi
106653e72ca8cSmrg	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
106663e72ca8cSmrg	tool_oldlib=$func_to_tool_file_result
1066734977a2fSmrg	eval cmds=\"$old_archive_cmds\"
10668ee3138f1Smrg
1066934977a2fSmrg	func_len " $cmds"
1067034977a2fSmrg	len=$func_len_result
1067134977a2fSmrg	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
1067234977a2fSmrg	  cmds=$old_archive_cmds
106733e72ca8cSmrg	elif test -n "$archiver_list_spec"; then
106743e72ca8cSmrg	  func_verbose "using command file archive linking..."
106753e72ca8cSmrg	  for obj in $oldobjs
106763e72ca8cSmrg	  do
106773e72ca8cSmrg	    func_to_tool_file "$obj"
106783e72ca8cSmrg	    $ECHO "$func_to_tool_file_result"
106793e72ca8cSmrg	  done > $output_objdir/$libname.libcmd
106803e72ca8cSmrg	  func_to_tool_file "$output_objdir/$libname.libcmd"
106813e72ca8cSmrg	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
106823e72ca8cSmrg	  cmds=$old_archive_cmds
1068334977a2fSmrg	else
1068434977a2fSmrg	  # the command line is too long to link in one step, link in parts
1068534977a2fSmrg	  func_verbose "using piecewise archive linking..."
1068634977a2fSmrg	  save_RANLIB=$RANLIB
1068734977a2fSmrg	  RANLIB=:
1068834977a2fSmrg	  objlist=
1068934977a2fSmrg	  concat_cmds=
1069034977a2fSmrg	  save_oldobjs=$oldobjs
1069134977a2fSmrg	  oldobjs=
1069234977a2fSmrg	  # Is there a better way of finding the last object in the list?
1069334977a2fSmrg	  for obj in $save_oldobjs
1069434977a2fSmrg	  do
1069534977a2fSmrg	    last_oldobj=$obj
1069634977a2fSmrg	  done
1069734977a2fSmrg	  eval test_cmds=\"$old_archive_cmds\"
1069834977a2fSmrg	  func_len " $test_cmds"
1069934977a2fSmrg	  len0=$func_len_result
1070034977a2fSmrg	  len=$len0
1070134977a2fSmrg	  for obj in $save_oldobjs
1070234977a2fSmrg	  do
1070334977a2fSmrg	    func_len " $obj"
1070434977a2fSmrg	    func_arith $len + $func_len_result
1070534977a2fSmrg	    len=$func_arith_result
1070634977a2fSmrg	    func_append objlist " $obj"
1070734977a2fSmrg	    if test "$len" -lt "$max_cmd_len"; then
1070834977a2fSmrg	      :
1070934977a2fSmrg	    else
1071034977a2fSmrg	      # the above command should be used before it gets too long
1071134977a2fSmrg	      oldobjs=$objlist
10712fe24f8a2Smrg	      if test "$obj" = "$last_oldobj"; then
1071334977a2fSmrg		RANLIB=$save_RANLIB
1071434977a2fSmrg	      fi
1071534977a2fSmrg	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10716fe24f8a2Smrg	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
1071734977a2fSmrg	      objlist=
1071834977a2fSmrg	      len=$len0
1071934977a2fSmrg	    fi
1072034977a2fSmrg	  done
1072134977a2fSmrg	  RANLIB=$save_RANLIB
1072234977a2fSmrg	  oldobjs=$objlist
10723fe24f8a2Smrg	  if test -z "$oldobjs"; then
1072434977a2fSmrg	    eval cmds=\"\$concat_cmds\"
1072534977a2fSmrg	  else
1072634977a2fSmrg	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
1072734977a2fSmrg	  fi
1072834977a2fSmrg	fi
1072934977a2fSmrg      fi
1073034977a2fSmrg      func_execute_cmds "$cmds" 'exit $?'
10731ee3138f1Smrg    done
10732ee3138f1Smrg
1073334977a2fSmrg    test -n "$generated" && \
1073434977a2fSmrg      func_show_eval "${RM}r$generated"
10735ee3138f1Smrg
1073634977a2fSmrg    # Now create the libtool archive.
1073734977a2fSmrg    case $output in
1073834977a2fSmrg    *.la)
1073934977a2fSmrg      old_library=
10740fe24f8a2Smrg      test yes = "$build_old_libs" && old_library=$libname.$libext
1074134977a2fSmrg      func_verbose "creating $output"
10742ee3138f1Smrg
1074334977a2fSmrg      # Preserve any variables that may affect compiler behavior
1074434977a2fSmrg      for var in $variables_saved_for_relink; do
1074534977a2fSmrg	if eval test -z \"\${$var+set}\"; then
1074634977a2fSmrg	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
1074734977a2fSmrg	elif eval var_value=\$$var; test -z "$var_value"; then
1074834977a2fSmrg	  relink_command="$var=; export $var; $relink_command"
10749ee3138f1Smrg	else
1075034977a2fSmrg	  func_quote_for_eval "$var_value"
1075134977a2fSmrg	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
10752ee3138f1Smrg	fi
1075334977a2fSmrg      done
1075434977a2fSmrg      # Quote the link command for shipping.
10755fe24f8a2Smrg      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
10756b425557eSmrg      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
10757fe24f8a2Smrg      if test yes = "$hardcode_automatic"; then
1075834977a2fSmrg	relink_command=
1075934977a2fSmrg      fi
10760ee3138f1Smrg
1076134977a2fSmrg      # Only create the output if not a dry run.
1076234977a2fSmrg      $opt_dry_run || {
1076334977a2fSmrg	for installed in no yes; do
10764fe24f8a2Smrg	  if test yes = "$installed"; then
1076534977a2fSmrg	    if test -z "$install_libdir"; then
1076634977a2fSmrg	      break
1076734977a2fSmrg	    fi
10768fe24f8a2Smrg	    output=$output_objdir/${outputname}i
1076934977a2fSmrg	    # Replace all uninstalled libtool libraries with the installed ones
1077034977a2fSmrg	    newdependency_libs=
1077134977a2fSmrg	    for deplib in $dependency_libs; do
1077234977a2fSmrg	      case $deplib in
1077334977a2fSmrg	      *.la)
1077434977a2fSmrg		func_basename "$deplib"
10775fe24f8a2Smrg		name=$func_basename_result
107763e72ca8cSmrg		func_resolve_sysroot "$deplib"
10777fe24f8a2Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
1077834977a2fSmrg		test -z "$libdir" && \
10779fe24f8a2Smrg		  func_fatal_error "'$deplib' is not a valid libtool archive"
107803e72ca8cSmrg		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
107813e72ca8cSmrg		;;
107823e72ca8cSmrg	      -L*)
107833e72ca8cSmrg		func_stripname -L '' "$deplib"
107843e72ca8cSmrg		func_replace_sysroot "$func_stripname_result"
107853e72ca8cSmrg		func_append newdependency_libs " -L$func_replace_sysroot_result"
107863e72ca8cSmrg		;;
107873e72ca8cSmrg	      -R*)
107883e72ca8cSmrg		func_stripname -R '' "$deplib"
107893e72ca8cSmrg		func_replace_sysroot "$func_stripname_result"
107903e72ca8cSmrg		func_append newdependency_libs " -R$func_replace_sysroot_result"
1079134977a2fSmrg		;;
107923e72ca8cSmrg	      *) func_append newdependency_libs " $deplib" ;;
1079334977a2fSmrg	      esac
1079434977a2fSmrg	    done
10795fe24f8a2Smrg	    dependency_libs=$newdependency_libs
1079634977a2fSmrg	    newdlfiles=
1079734977a2fSmrg
1079834977a2fSmrg	    for lib in $dlfiles; do
1079934977a2fSmrg	      case $lib in
1080034977a2fSmrg	      *.la)
1080134977a2fSmrg	        func_basename "$lib"
10802fe24f8a2Smrg		name=$func_basename_result
10803fe24f8a2Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1080434977a2fSmrg		test -z "$libdir" && \
10805fe24f8a2Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
108063e72ca8cSmrg		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
1080734977a2fSmrg		;;
108083e72ca8cSmrg	      *) func_append newdlfiles " $lib" ;;
1080934977a2fSmrg	      esac
1081034977a2fSmrg	    done
10811fe24f8a2Smrg	    dlfiles=$newdlfiles
1081234977a2fSmrg	    newdlprefiles=
1081334977a2fSmrg	    for lib in $dlprefiles; do
1081434977a2fSmrg	      case $lib in
1081534977a2fSmrg	      *.la)
1081634977a2fSmrg		# Only pass preopened files to the pseudo-archive (for
1081734977a2fSmrg		# eventual linking with the app. that links it) if we
1081834977a2fSmrg		# didn't already link the preopened objects directly into
1081934977a2fSmrg		# the library:
1082034977a2fSmrg		func_basename "$lib"
10821fe24f8a2Smrg		name=$func_basename_result
10822fe24f8a2Smrg		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
1082334977a2fSmrg		test -z "$libdir" && \
10824fe24f8a2Smrg		  func_fatal_error "'$lib' is not a valid libtool archive"
108253e72ca8cSmrg		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
1082634977a2fSmrg		;;
1082734977a2fSmrg	      esac
1082834977a2fSmrg	    done
10829fe24f8a2Smrg	    dlprefiles=$newdlprefiles
1083034977a2fSmrg	  else
1083134977a2fSmrg	    newdlfiles=
1083234977a2fSmrg	    for lib in $dlfiles; do
1083334977a2fSmrg	      case $lib in
10834fe24f8a2Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1083534977a2fSmrg		*) abs=`pwd`"/$lib" ;;
1083634977a2fSmrg	      esac
108373e72ca8cSmrg	      func_append newdlfiles " $abs"
1083834977a2fSmrg	    done
10839fe24f8a2Smrg	    dlfiles=$newdlfiles
1084034977a2fSmrg	    newdlprefiles=
1084134977a2fSmrg	    for lib in $dlprefiles; do
1084234977a2fSmrg	      case $lib in
10843fe24f8a2Smrg		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
1084434977a2fSmrg		*) abs=`pwd`"/$lib" ;;
1084534977a2fSmrg	      esac
108463e72ca8cSmrg	      func_append newdlprefiles " $abs"
1084734977a2fSmrg	    done
10848fe24f8a2Smrg	    dlprefiles=$newdlprefiles
1084934977a2fSmrg	  fi
1085034977a2fSmrg	  $RM $output
1085134977a2fSmrg	  # place dlname in correct position for cygwin
10852b425557eSmrg	  # In fact, it would be nice if we could use this code for all target
10853b425557eSmrg	  # systems that can't hard-code library paths into their executables
10854b425557eSmrg	  # and that have no shared library path variable independent of PATH,
10855b425557eSmrg	  # but it turns out we can't easily determine that from inspecting
10856b425557eSmrg	  # libtool variables, so we have to hard-code the OSs to which it
10857b425557eSmrg	  # applies here; at the moment, that means platforms that use the PE
10858b425557eSmrg	  # object format with DLL files.  See the long comment at the top of
10859b425557eSmrg	  # tests/bindir.at for full details.
1086034977a2fSmrg	  tdlname=$dlname
1086134977a2fSmrg	  case $host,$output,$installed,$module,$dlname in
10862b425557eSmrg	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
10863b425557eSmrg	      # If a -bindir argument was supplied, place the dll there.
10864fe24f8a2Smrg	      if test -n "$bindir"; then
10865b425557eSmrg		func_relative_path "$install_libdir" "$bindir"
10866fe24f8a2Smrg		tdlname=$func_relative_path_result/$dlname
10867b425557eSmrg	      else
10868b425557eSmrg		# Otherwise fall back on heuristic.
10869b425557eSmrg		tdlname=../bin/$dlname
10870b425557eSmrg	      fi
10871b425557eSmrg	      ;;
1087234977a2fSmrg	  esac
1087334977a2fSmrg	  $ECHO > $output "\
1087434977a2fSmrg# $outputname - a libtool library file
10875fe24f8a2Smrg# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
1087634977a2fSmrg#
1087734977a2fSmrg# Please DO NOT delete this file!
1087834977a2fSmrg# It is necessary for linking the library.
10879ee3138f1Smrg
1088034977a2fSmrg# The name that we can dlopen(3).
1088134977a2fSmrgdlname='$tdlname'
10882ee3138f1Smrg
1088334977a2fSmrg# Names of this library.
1088434977a2fSmrglibrary_names='$library_names'
10885ee3138f1Smrg
1088634977a2fSmrg# The name of the static archive.
1088734977a2fSmrgold_library='$old_library'
10888ee3138f1Smrg
10889fe24f8a2Smrg# Linker flags that cannot go in dependency_libs.
1089034977a2fSmrginherited_linker_flags='$new_inherited_linker_flags'
10891ee3138f1Smrg
1089234977a2fSmrg# Libraries that this one depends upon.
1089334977a2fSmrgdependency_libs='$dependency_libs'
10894ee3138f1Smrg
1089534977a2fSmrg# Names of additional weak libraries provided by this library
1089634977a2fSmrgweak_library_names='$weak_libs'
10897ee3138f1Smrg
1089834977a2fSmrg# Version information for $libname.
1089934977a2fSmrgcurrent=$current
1090034977a2fSmrgage=$age
1090134977a2fSmrgrevision=$revision
10902ee3138f1Smrg
1090334977a2fSmrg# Is this an already installed library?
1090434977a2fSmrginstalled=$installed
10905ee3138f1Smrg
1090634977a2fSmrg# Should we warn about portability when linking against -modules?
1090734977a2fSmrgshouldnotlink=$module
10908ee3138f1Smrg
1090934977a2fSmrg# Files to dlopen/dlpreopen
1091034977a2fSmrgdlopen='$dlfiles'
1091134977a2fSmrgdlpreopen='$dlprefiles'
10912ee3138f1Smrg
1091334977a2fSmrg# Directory that this library needs to be installed in:
1091434977a2fSmrglibdir='$install_libdir'"
10915fe24f8a2Smrg	  if test no,yes = "$installed,$need_relink"; then
1091634977a2fSmrg	    $ECHO >> $output "\
1091734977a2fSmrgrelink_command=\"$relink_command\""
1091834977a2fSmrg	  fi
1091934977a2fSmrg	done
1092034977a2fSmrg      }
10921ee3138f1Smrg
1092234977a2fSmrg      # Do a symbolic link so that the libtool archive can be found in
1092334977a2fSmrg      # LD_LIBRARY_PATH before the program is installed.
1092434977a2fSmrg      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
1092534977a2fSmrg      ;;
1092634977a2fSmrg    esac
1092734977a2fSmrg    exit $EXIT_SUCCESS
1092834977a2fSmrg}
10929ee3138f1Smrg
10930fe24f8a2Smrgif test link = "$opt_mode" || test relink = "$opt_mode"; then
10931fe24f8a2Smrg  func_mode_link ${1+"$@"}
10932fe24f8a2Smrgfi
10933ee3138f1Smrg
10934ee3138f1Smrg
1093534977a2fSmrg# func_mode_uninstall arg...
1093634977a2fSmrgfunc_mode_uninstall ()
1093734977a2fSmrg{
10938fe24f8a2Smrg    $debug_cmd
10939fe24f8a2Smrg
10940fe24f8a2Smrg    RM=$nonopt
10941ee3138f1Smrg    files=
10942fe24f8a2Smrg    rmforce=false
10943ee3138f1Smrg    exit_status=0
10944ee3138f1Smrg
10945ee3138f1Smrg    # This variable tells wrapper scripts just to set variables rather
10946ee3138f1Smrg    # than running their programs.
10947fe24f8a2Smrg    libtool_install_magic=$magic
10948ee3138f1Smrg
10949ee3138f1Smrg    for arg
10950ee3138f1Smrg    do
10951ee3138f1Smrg      case $arg in
10952fe24f8a2Smrg      -f) func_append RM " $arg"; rmforce=: ;;
109533e72ca8cSmrg      -*) func_append RM " $arg" ;;
109543e72ca8cSmrg      *) func_append files " $arg" ;;
10955ee3138f1Smrg      esac
10956ee3138f1Smrg    done
10957ee3138f1Smrg
1095834977a2fSmrg    test -z "$RM" && \
1095934977a2fSmrg      func_fatal_help "you must specify an RM program"
10960ee3138f1Smrg
10961ee3138f1Smrg    rmdirs=
10962ee3138f1Smrg
10963ee3138f1Smrg    for file in $files; do
1096434977a2fSmrg      func_dirname "$file" "" "."
10965fe24f8a2Smrg      dir=$func_dirname_result
10966fe24f8a2Smrg      if test . = "$dir"; then
10967fe24f8a2Smrg	odir=$objdir
10968ee3138f1Smrg      else
10969fe24f8a2Smrg	odir=$dir/$objdir
10970ee3138f1Smrg      fi
1097134977a2fSmrg      func_basename "$file"
10972fe24f8a2Smrg      name=$func_basename_result
10973fe24f8a2Smrg      test uninstall = "$opt_mode" && odir=$dir
10974ee3138f1Smrg
109753e72ca8cSmrg      # Remember odir for removal later, being careful to avoid duplicates
10976fe24f8a2Smrg      if test clean = "$opt_mode"; then
10977ee3138f1Smrg	case " $rmdirs " in
109783e72ca8cSmrg	  *" $odir "*) ;;
109793e72ca8cSmrg	  *) func_append rmdirs " $odir" ;;
10980ee3138f1Smrg	esac
10981ee3138f1Smrg      fi
10982ee3138f1Smrg
10983ee3138f1Smrg      # Don't error if the file doesn't exist and rm -f was used.
1098434977a2fSmrg      if { test -L "$file"; } >/dev/null 2>&1 ||
1098534977a2fSmrg	 { test -h "$file"; } >/dev/null 2>&1 ||
1098634977a2fSmrg	 test -f "$file"; then
10987ee3138f1Smrg	:
10988ee3138f1Smrg      elif test -d "$file"; then
10989ee3138f1Smrg	exit_status=1
10990ee3138f1Smrg	continue
10991fe24f8a2Smrg      elif $rmforce; then
10992ee3138f1Smrg	continue
10993ee3138f1Smrg      fi
10994ee3138f1Smrg
10995fe24f8a2Smrg      rmfiles=$file
10996ee3138f1Smrg
10997ee3138f1Smrg      case $name in
10998ee3138f1Smrg      *.la)
10999ee3138f1Smrg	# Possibly a libtool archive, so verify it.
1100034977a2fSmrg	if func_lalib_p "$file"; then
1100134977a2fSmrg	  func_source $dir/$name
11002ee3138f1Smrg
11003ee3138f1Smrg	  # Delete the libtool libraries and symlinks.
11004ee3138f1Smrg	  for n in $library_names; do
110053e72ca8cSmrg	    func_append rmfiles " $odir/$n"
11006ee3138f1Smrg	  done
110073e72ca8cSmrg	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
11008ee3138f1Smrg
11009fe24f8a2Smrg	  case $opt_mode in
11010ee3138f1Smrg	  clean)
110113e72ca8cSmrg	    case " $library_names " in
11012ee3138f1Smrg	    *" $dlname "*) ;;
110133e72ca8cSmrg	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
11014ee3138f1Smrg	    esac
110153e72ca8cSmrg	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
11016ee3138f1Smrg	    ;;
11017ee3138f1Smrg	  uninstall)
11018ee3138f1Smrg	    if test -n "$library_names"; then
11019ee3138f1Smrg	      # Do each command in the postuninstall commands.
11020fe24f8a2Smrg	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
11021ee3138f1Smrg	    fi
11022ee3138f1Smrg
11023ee3138f1Smrg	    if test -n "$old_library"; then
11024ee3138f1Smrg	      # Do each command in the old_postuninstall commands.
11025fe24f8a2Smrg	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
11026ee3138f1Smrg	    fi
11027ee3138f1Smrg	    # FIXME: should reinstall the best remaining shared library.
11028ee3138f1Smrg	    ;;
11029ee3138f1Smrg	  esac
11030ee3138f1Smrg	fi
11031ee3138f1Smrg	;;
11032ee3138f1Smrg
11033ee3138f1Smrg      *.lo)
11034ee3138f1Smrg	# Possibly a libtool object, so verify it.
1103534977a2fSmrg	if func_lalib_p "$file"; then
11036ee3138f1Smrg
11037ee3138f1Smrg	  # Read the .lo file
1103834977a2fSmrg	  func_source $dir/$name
11039ee3138f1Smrg
11040ee3138f1Smrg	  # Add PIC object to the list of files to remove.
11041fe24f8a2Smrg	  if test -n "$pic_object" && test none != "$pic_object"; then
110423e72ca8cSmrg	    func_append rmfiles " $dir/$pic_object"
11043ee3138f1Smrg	  fi
11044ee3138f1Smrg
11045ee3138f1Smrg	  # Add non-PIC object to the list of files to remove.
11046fe24f8a2Smrg	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
110473e72ca8cSmrg	    func_append rmfiles " $dir/$non_pic_object"
11048ee3138f1Smrg	  fi
11049ee3138f1Smrg	fi
11050ee3138f1Smrg	;;
11051ee3138f1Smrg
11052ee3138f1Smrg      *)
11053fe24f8a2Smrg	if test clean = "$opt_mode"; then
11054ee3138f1Smrg	  noexename=$name
11055ee3138f1Smrg	  case $file in
11056ee3138f1Smrg	  *.exe)
1105734977a2fSmrg	    func_stripname '' '.exe' "$file"
1105834977a2fSmrg	    file=$func_stripname_result
1105934977a2fSmrg	    func_stripname '' '.exe' "$name"
1106034977a2fSmrg	    noexename=$func_stripname_result
11061ee3138f1Smrg	    # $file with .exe has already been added to rmfiles,
11062ee3138f1Smrg	    # add $file without .exe
110633e72ca8cSmrg	    func_append rmfiles " $file"
11064ee3138f1Smrg	    ;;
11065ee3138f1Smrg	  esac
11066ee3138f1Smrg	  # Do a test to see if this is a libtool program.
1106734977a2fSmrg	  if func_ltwrapper_p "$file"; then
1106834977a2fSmrg	    if func_ltwrapper_executable_p "$file"; then
1106934977a2fSmrg	      func_ltwrapper_scriptname "$file"
1107034977a2fSmrg	      relink_command=
1107134977a2fSmrg	      func_source $func_ltwrapper_scriptname_result
110723e72ca8cSmrg	      func_append rmfiles " $func_ltwrapper_scriptname_result"
1107334977a2fSmrg	    else
1107434977a2fSmrg	      relink_command=
1107534977a2fSmrg	      func_source $dir/$noexename
1107634977a2fSmrg	    fi
11077ee3138f1Smrg
11078ee3138f1Smrg	    # note $name still contains .exe if it was in $file originally
11079ee3138f1Smrg	    # as does the version of $file that was added into $rmfiles
11080fe24f8a2Smrg	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11081fe24f8a2Smrg	    if test yes = "$fast_install" && test -n "$relink_command"; then
110823e72ca8cSmrg	      func_append rmfiles " $odir/lt-$name"
11083ee3138f1Smrg	    fi
11084fe24f8a2Smrg	    if test "X$noexename" != "X$name"; then
11085fe24f8a2Smrg	      func_append rmfiles " $odir/lt-$noexename.c"
11086ee3138f1Smrg	    fi
11087ee3138f1Smrg	  fi
11088ee3138f1Smrg	fi
11089ee3138f1Smrg	;;
11090ee3138f1Smrg      esac
1109134977a2fSmrg      func_show_eval "$RM $rmfiles" 'exit_status=1'
11092ee3138f1Smrg    done
11093ee3138f1Smrg
11094fe24f8a2Smrg    # Try to remove the $objdir's in the directories where we deleted files
11095ee3138f1Smrg    for dir in $rmdirs; do
11096ee3138f1Smrg      if test -d "$dir"; then
1109734977a2fSmrg	func_show_eval "rmdir $dir >/dev/null 2>&1"
11098ee3138f1Smrg      fi
11099ee3138f1Smrg    done
11100ee3138f1Smrg
11101ee3138f1Smrg    exit $exit_status
1110234977a2fSmrg}
11103ee3138f1Smrg
11104fe24f8a2Smrgif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
11105fe24f8a2Smrg  func_mode_uninstall ${1+"$@"}
11106fe24f8a2Smrgfi
11107ee3138f1Smrg
111083e72ca8cSmrgtest -z "$opt_mode" && {
11109fe24f8a2Smrg  help=$generic_help
1111034977a2fSmrg  func_fatal_help "you must specify a MODE"
1111134977a2fSmrg}
1111234977a2fSmrg
1111334977a2fSmrgtest -z "$exec_cmd" && \
11114fe24f8a2Smrg  func_fatal_help "invalid operation mode '$opt_mode'"
11115ee3138f1Smrg
11116ee3138f1Smrgif test -n "$exec_cmd"; then
1111734977a2fSmrg  eval exec "$exec_cmd"
11118ee3138f1Smrg  exit $EXIT_FAILURE
11119ee3138f1Smrgfi
11120ee3138f1Smrg
1112134977a2fSmrgexit $exit_status
11122ee3138f1Smrg
11123ee3138f1Smrg
11124ee3138f1Smrg# The TAGs below are defined such that we never get into a situation
11125fe24f8a2Smrg# where we disable both kinds of libraries.  Given conflicting
11126ee3138f1Smrg# choices, we go for a static library, that is the most portable,
11127ee3138f1Smrg# since we can't tell whether shared libraries were disabled because
11128ee3138f1Smrg# the user asked for that or because the platform doesn't support
11129ee3138f1Smrg# them.  This is particularly important on AIX, because we don't
11130ee3138f1Smrg# support having both static and shared libraries enabled at the same
11131ee3138f1Smrg# time on that platform, so we default to a shared-only configuration.
11132ee3138f1Smrg# If a disable-shared tag is given, we'll fallback to a static-only
11133ee3138f1Smrg# configuration.  But we'll never go from static-only to shared-only.
11134ee3138f1Smrg
11135ee3138f1Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
1113634977a2fSmrgbuild_libtool_libs=no
1113734977a2fSmrgbuild_old_libs=yes
11138ee3138f1Smrg# ### END LIBTOOL TAG CONFIG: disable-shared
11139ee3138f1Smrg
11140ee3138f1Smrg# ### BEGIN LIBTOOL TAG CONFIG: disable-static
1114134977a2fSmrgbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
11142ee3138f1Smrg# ### END LIBTOOL TAG CONFIG: disable-static
11143ee3138f1Smrg
11144ee3138f1Smrg# Local Variables:
11145ee3138f1Smrg# mode:shell-script
11146ee3138f1Smrg# sh-indentation:2
11147ee3138f1Smrg# End:
11148