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