xref: /freebsd/contrib/ldns/ltmain.sh (revision 5afab0e5e56fe90a378fb57249600e7924e1cab2)
1986ba33cSDag-Erling Smørgrav#! /bin/sh
2986ba33cSDag-Erling Smørgrav## DO NOT EDIT - This file generated from ./build-aux/ltmain.in
3986ba33cSDag-Erling Smørgrav##               by inline-source v2014-01-03.01
47b5038d7SDag-Erling Smørgrav
5986ba33cSDag-Erling Smørgrav# libtool (GNU libtool) 2.4.6
6986ba33cSDag-Erling Smørgrav# Provide generalized library-building support services.
77b5038d7SDag-Erling Smørgrav# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
87b5038d7SDag-Erling Smørgrav
9986ba33cSDag-Erling Smørgrav# Copyright (C) 1996-2015 Free Software Foundation, Inc.
107b5038d7SDag-Erling Smørgrav# This is free software; see the source for copying conditions.  There is NO
117b5038d7SDag-Erling Smørgrav# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
127b5038d7SDag-Erling Smørgrav
137b5038d7SDag-Erling Smørgrav# GNU Libtool is free software; you can redistribute it and/or modify
147b5038d7SDag-Erling Smørgrav# it under the terms of the GNU General Public License as published by
157b5038d7SDag-Erling Smørgrav# the Free Software Foundation; either version 2 of the License, or
167b5038d7SDag-Erling Smørgrav# (at your option) any later version.
177b5038d7SDag-Erling Smørgrav#
187b5038d7SDag-Erling Smørgrav# As a special exception to the GNU General Public License,
197b5038d7SDag-Erling Smørgrav# if you distribute this file as part of a program or library that
207b5038d7SDag-Erling Smørgrav# is built using GNU Libtool, you may include this file under the
217b5038d7SDag-Erling Smørgrav# same distribution terms that you use for the rest of that program.
227b5038d7SDag-Erling Smørgrav#
237b5038d7SDag-Erling Smørgrav# GNU Libtool is distributed in the hope that it will be useful, but
247b5038d7SDag-Erling Smørgrav# WITHOUT ANY WARRANTY; without even the implied warranty of
257b5038d7SDag-Erling Smørgrav# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
267b5038d7SDag-Erling Smørgrav# General Public License for more details.
277b5038d7SDag-Erling Smørgrav#
287b5038d7SDag-Erling Smørgrav# You should have received a copy of the GNU General Public License
29986ba33cSDag-Erling Smørgrav# along with this program.  If not, see <http://www.gnu.org/licenses/>.
307b5038d7SDag-Erling Smørgrav
317b5038d7SDag-Erling Smørgrav
327b5038d7SDag-Erling SmørgravPROGRAM=libtool
337b5038d7SDag-Erling SmørgravPACKAGE=libtool
34*5afab0e5SDag-Erling SmørgravVERSION="2.4.6 Debian-2.4.6-15build2"
35986ba33cSDag-Erling Smørgravpackage_revision=2.4.6
367b5038d7SDag-Erling Smørgrav
37986ba33cSDag-Erling Smørgrav
38986ba33cSDag-Erling Smørgrav## ------ ##
39986ba33cSDag-Erling Smørgrav## Usage. ##
40986ba33cSDag-Erling Smørgrav## ------ ##
41986ba33cSDag-Erling Smørgrav
42986ba33cSDag-Erling Smørgrav# Run './libtool --help' for help with using this script from the
43986ba33cSDag-Erling Smørgrav# command line.
44986ba33cSDag-Erling Smørgrav
45986ba33cSDag-Erling Smørgrav
46986ba33cSDag-Erling Smørgrav## ------------------------------- ##
47986ba33cSDag-Erling Smørgrav## User overridable command paths. ##
48986ba33cSDag-Erling Smørgrav## ------------------------------- ##
49986ba33cSDag-Erling Smørgrav
50986ba33cSDag-Erling Smørgrav# After configure completes, it has a better idea of some of the
51986ba33cSDag-Erling Smørgrav# shell tools we need than the defaults used by the functions shared
52986ba33cSDag-Erling Smørgrav# with bootstrap, so set those here where they can still be over-
53986ba33cSDag-Erling Smørgrav# ridden by the user, but otherwise take precedence.
54986ba33cSDag-Erling Smørgrav
55986ba33cSDag-Erling Smørgrav: ${AUTOCONF="autoconf"}
56986ba33cSDag-Erling Smørgrav: ${AUTOMAKE="automake"}
57986ba33cSDag-Erling Smørgrav
58986ba33cSDag-Erling Smørgrav
59986ba33cSDag-Erling Smørgrav## -------------------------- ##
60986ba33cSDag-Erling Smørgrav## Source external libraries. ##
61986ba33cSDag-Erling Smørgrav## -------------------------- ##
62986ba33cSDag-Erling Smørgrav
63986ba33cSDag-Erling Smørgrav# Much of our low-level functionality needs to be sourced from external
64986ba33cSDag-Erling Smørgrav# libraries, which are installed to $pkgauxdir.
65986ba33cSDag-Erling Smørgrav
66986ba33cSDag-Erling Smørgrav# Set a version string for this script.
67986ba33cSDag-Erling Smørgravscriptversion=2015-01-20.17; # UTC
68986ba33cSDag-Erling Smørgrav
69986ba33cSDag-Erling Smørgrav# General shell script boiler plate, and helper functions.
70986ba33cSDag-Erling Smørgrav# Written by Gary V. Vaughan, 2004
71986ba33cSDag-Erling Smørgrav
72986ba33cSDag-Erling Smørgrav# Copyright (C) 2004-2015 Free Software Foundation, Inc.
73986ba33cSDag-Erling Smørgrav# This is free software; see the source for copying conditions.  There is NO
74986ba33cSDag-Erling Smørgrav# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
75986ba33cSDag-Erling Smørgrav
76986ba33cSDag-Erling Smørgrav# This program is free software; you can redistribute it and/or modify
77986ba33cSDag-Erling Smørgrav# it under the terms of the GNU General Public License as published by
78986ba33cSDag-Erling Smørgrav# the Free Software Foundation; either version 3 of the License, or
79986ba33cSDag-Erling Smørgrav# (at your option) any later version.
80986ba33cSDag-Erling Smørgrav
81986ba33cSDag-Erling Smørgrav# As a special exception to the GNU General Public License, if you distribute
82986ba33cSDag-Erling Smørgrav# this file as part of a program or library that is built using GNU Libtool,
83986ba33cSDag-Erling Smørgrav# you may include this file under the same distribution terms that you use
84986ba33cSDag-Erling Smørgrav# for the rest of that program.
85986ba33cSDag-Erling Smørgrav
86986ba33cSDag-Erling Smørgrav# This program is distributed in the hope that it will be useful,
87986ba33cSDag-Erling Smørgrav# but WITHOUT ANY WARRANTY; without even the implied warranty of
88986ba33cSDag-Erling Smørgrav# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
89986ba33cSDag-Erling Smørgrav# General Public License for more details.
90986ba33cSDag-Erling Smørgrav
91986ba33cSDag-Erling Smørgrav# You should have received a copy of the GNU General Public License
92986ba33cSDag-Erling Smørgrav# along with this program. If not, see <http://www.gnu.org/licenses/>.
93986ba33cSDag-Erling Smørgrav
94986ba33cSDag-Erling Smørgrav# Please report bugs or propose patches to gary@gnu.org.
95986ba33cSDag-Erling Smørgrav
96986ba33cSDag-Erling Smørgrav
97986ba33cSDag-Erling Smørgrav## ------ ##
98986ba33cSDag-Erling Smørgrav## Usage. ##
99986ba33cSDag-Erling Smørgrav## ------ ##
100986ba33cSDag-Erling Smørgrav
101986ba33cSDag-Erling Smørgrav# Evaluate this file near the top of your script to gain access to
102986ba33cSDag-Erling Smørgrav# the functions and variables defined here:
103986ba33cSDag-Erling Smørgrav#
104986ba33cSDag-Erling Smørgrav#   . `echo "$0" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh
105986ba33cSDag-Erling Smørgrav#
106986ba33cSDag-Erling Smørgrav# If you need to override any of the default environment variable
107986ba33cSDag-Erling Smørgrav# settings, do that before evaluating this file.
108986ba33cSDag-Erling Smørgrav
109986ba33cSDag-Erling Smørgrav
110986ba33cSDag-Erling Smørgrav## -------------------- ##
111986ba33cSDag-Erling Smørgrav## Shell normalisation. ##
112986ba33cSDag-Erling Smørgrav## -------------------- ##
113986ba33cSDag-Erling Smørgrav
114986ba33cSDag-Erling Smørgrav# Some shells need a little help to be as Bourne compatible as possible.
115986ba33cSDag-Erling Smørgrav# Before doing anything else, make sure all that help has been provided!
116986ba33cSDag-Erling Smørgrav
117986ba33cSDag-Erling SmørgravDUALCASE=1; export DUALCASE # for MKS sh
118986ba33cSDag-Erling Smørgravif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
1197b5038d7SDag-Erling Smørgrav  emulate sh
1207b5038d7SDag-Erling Smørgrav  NULLCMD=:
121986ba33cSDag-Erling Smørgrav  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
1227b5038d7SDag-Erling Smørgrav  # is contrary to our usage.  Disable this feature.
1237b5038d7SDag-Erling Smørgrav  alias -g '${1+"$@"}'='"$@"'
1247b5038d7SDag-Erling Smørgrav  setopt NO_GLOB_SUBST
1257b5038d7SDag-Erling Smørgravelse
1267b5038d7SDag-Erling Smørgrav  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac
1277b5038d7SDag-Erling Smørgravfi
1287b5038d7SDag-Erling Smørgrav
129986ba33cSDag-Erling Smørgrav# NLS nuisances: We save the old values in case they are required later.
130986ba33cSDag-Erling Smørgrav_G_user_locale=
131986ba33cSDag-Erling Smørgrav_G_safe_locale=
132986ba33cSDag-Erling Smørgravfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
1337b5038d7SDag-Erling Smørgravdo
134986ba33cSDag-Erling Smørgrav  eval "if test set = \"\${$_G_var+set}\"; then
135986ba33cSDag-Erling Smørgrav          save_$_G_var=\$$_G_var
136986ba33cSDag-Erling Smørgrav          $_G_var=C
137986ba33cSDag-Erling Smørgrav	  export $_G_var
138986ba33cSDag-Erling Smørgrav	  _G_user_locale=\"$_G_var=\\\$save_\$_G_var; \$_G_user_locale\"
139986ba33cSDag-Erling Smørgrav	  _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\"
1407b5038d7SDag-Erling Smørgrav	fi"
1417b5038d7SDag-Erling Smørgravdone
1427b5038d7SDag-Erling Smørgrav
143986ba33cSDag-Erling Smørgrav# CDPATH.
144986ba33cSDag-Erling Smørgrav(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
1457b5038d7SDag-Erling Smørgrav
146986ba33cSDag-Erling Smørgrav# Make sure IFS has a sensible default
147986ba33cSDag-Erling Smørgravsp=' '
148986ba33cSDag-Erling Smørgravnl='
149986ba33cSDag-Erling Smørgrav'
150986ba33cSDag-Erling SmørgravIFS="$sp	$nl"
151986ba33cSDag-Erling Smørgrav
152986ba33cSDag-Erling Smørgrav# There are apparently some retarded systems that use ';' as a PATH separator!
153986ba33cSDag-Erling Smørgravif test "${PATH_SEPARATOR+set}" != set; then
154986ba33cSDag-Erling Smørgrav  PATH_SEPARATOR=:
155986ba33cSDag-Erling Smørgrav  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
156986ba33cSDag-Erling Smørgrav    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
157986ba33cSDag-Erling Smørgrav      PATH_SEPARATOR=';'
158986ba33cSDag-Erling Smørgrav  }
159986ba33cSDag-Erling Smørgravfi
160986ba33cSDag-Erling Smørgrav
161986ba33cSDag-Erling Smørgrav
162986ba33cSDag-Erling Smørgrav
163986ba33cSDag-Erling Smørgrav## ------------------------- ##
164986ba33cSDag-Erling Smørgrav## Locate command utilities. ##
165986ba33cSDag-Erling Smørgrav## ------------------------- ##
166986ba33cSDag-Erling Smørgrav
167986ba33cSDag-Erling Smørgrav
168986ba33cSDag-Erling Smørgrav# func_executable_p FILE
169986ba33cSDag-Erling Smørgrav# ----------------------
170986ba33cSDag-Erling Smørgrav# Check that FILE is an executable regular file.
171986ba33cSDag-Erling Smørgravfunc_executable_p ()
172986ba33cSDag-Erling Smørgrav{
173986ba33cSDag-Erling Smørgrav    test -f "$1" && test -x "$1"
174986ba33cSDag-Erling Smørgrav}
175986ba33cSDag-Erling Smørgrav
176986ba33cSDag-Erling Smørgrav
177986ba33cSDag-Erling Smørgrav# func_path_progs PROGS_LIST CHECK_FUNC [PATH]
178986ba33cSDag-Erling Smørgrav# --------------------------------------------
179986ba33cSDag-Erling Smørgrav# Search for either a program that responds to --version with output
180986ba33cSDag-Erling Smørgrav# containing "GNU", or else returned by CHECK_FUNC otherwise, by
181986ba33cSDag-Erling Smørgrav# trying all the directories in PATH with each of the elements of
182986ba33cSDag-Erling Smørgrav# PROGS_LIST.
183986ba33cSDag-Erling Smørgrav#
184986ba33cSDag-Erling Smørgrav# CHECK_FUNC should accept the path to a candidate program, and
185986ba33cSDag-Erling Smørgrav# set $func_check_prog_result if it truncates its output less than
186986ba33cSDag-Erling Smørgrav# $_G_path_prog_max characters.
187986ba33cSDag-Erling Smørgravfunc_path_progs ()
188986ba33cSDag-Erling Smørgrav{
189986ba33cSDag-Erling Smørgrav    _G_progs_list=$1
190986ba33cSDag-Erling Smørgrav    _G_check_func=$2
191986ba33cSDag-Erling Smørgrav    _G_PATH=${3-"$PATH"}
192986ba33cSDag-Erling Smørgrav
193986ba33cSDag-Erling Smørgrav    _G_path_prog_max=0
194986ba33cSDag-Erling Smørgrav    _G_path_prog_found=false
195986ba33cSDag-Erling Smørgrav    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}
196986ba33cSDag-Erling Smørgrav    for _G_dir in $_G_PATH; do
197986ba33cSDag-Erling Smørgrav      IFS=$_G_save_IFS
198986ba33cSDag-Erling Smørgrav      test -z "$_G_dir" && _G_dir=.
199986ba33cSDag-Erling Smørgrav      for _G_prog_name in $_G_progs_list; do
200986ba33cSDag-Erling Smørgrav        for _exeext in '' .EXE; do
201986ba33cSDag-Erling Smørgrav          _G_path_prog=$_G_dir/$_G_prog_name$_exeext
202986ba33cSDag-Erling Smørgrav          func_executable_p "$_G_path_prog" || continue
203986ba33cSDag-Erling Smørgrav          case `"$_G_path_prog" --version 2>&1` in
204986ba33cSDag-Erling Smørgrav            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;
205986ba33cSDag-Erling Smørgrav            *)     $_G_check_func $_G_path_prog
206986ba33cSDag-Erling Smørgrav		   func_path_progs_result=$func_check_prog_result
207986ba33cSDag-Erling Smørgrav		   ;;
208986ba33cSDag-Erling Smørgrav          esac
209986ba33cSDag-Erling Smørgrav          $_G_path_prog_found && break 3
210986ba33cSDag-Erling Smørgrav        done
211986ba33cSDag-Erling Smørgrav      done
212986ba33cSDag-Erling Smørgrav    done
213986ba33cSDag-Erling Smørgrav    IFS=$_G_save_IFS
214986ba33cSDag-Erling Smørgrav    test -z "$func_path_progs_result" && {
215986ba33cSDag-Erling Smørgrav      echo "no acceptable sed could be found in \$PATH" >&2
216986ba33cSDag-Erling Smørgrav      exit 1
217986ba33cSDag-Erling Smørgrav    }
218986ba33cSDag-Erling Smørgrav}
219986ba33cSDag-Erling Smørgrav
220986ba33cSDag-Erling Smørgrav
221986ba33cSDag-Erling Smørgrav# We want to be able to use the functions in this file before configure
222986ba33cSDag-Erling Smørgrav# has figured out where the best binaries are kept, which means we have
223986ba33cSDag-Erling Smørgrav# to search for them ourselves - except when the results are already set
224986ba33cSDag-Erling Smørgrav# where we skip the searches.
225986ba33cSDag-Erling Smørgrav
226986ba33cSDag-Erling Smørgrav# Unless the user overrides by setting SED, search the path for either GNU
227986ba33cSDag-Erling Smørgrav# sed, or the sed that truncates its output the least.
228986ba33cSDag-Erling Smørgravtest -z "$SED" && {
229986ba33cSDag-Erling Smørgrav  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
230986ba33cSDag-Erling Smørgrav  for _G_i in 1 2 3 4 5 6 7; do
231986ba33cSDag-Erling Smørgrav    _G_sed_script=$_G_sed_script$nl$_G_sed_script
232986ba33cSDag-Erling Smørgrav  done
233986ba33cSDag-Erling Smørgrav  echo "$_G_sed_script" 2>/dev/null | sed 99q >conftest.sed
234986ba33cSDag-Erling Smørgrav  _G_sed_script=
235986ba33cSDag-Erling Smørgrav
236986ba33cSDag-Erling Smørgrav  func_check_prog_sed ()
237986ba33cSDag-Erling Smørgrav  {
238986ba33cSDag-Erling Smørgrav    _G_path_prog=$1
239986ba33cSDag-Erling Smørgrav
240986ba33cSDag-Erling Smørgrav    _G_count=0
241986ba33cSDag-Erling Smørgrav    printf 0123456789 >conftest.in
242986ba33cSDag-Erling Smørgrav    while :
243986ba33cSDag-Erling Smørgrav    do
244986ba33cSDag-Erling Smørgrav      cat conftest.in conftest.in >conftest.tmp
245986ba33cSDag-Erling Smørgrav      mv conftest.tmp conftest.in
246986ba33cSDag-Erling Smørgrav      cp conftest.in conftest.nl
247986ba33cSDag-Erling Smørgrav      echo '' >> conftest.nl
248986ba33cSDag-Erling Smørgrav      "$_G_path_prog" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break
249986ba33cSDag-Erling Smørgrav      diff conftest.out conftest.nl >/dev/null 2>&1 || break
250986ba33cSDag-Erling Smørgrav      _G_count=`expr $_G_count + 1`
251986ba33cSDag-Erling Smørgrav      if test "$_G_count" -gt "$_G_path_prog_max"; then
252986ba33cSDag-Erling Smørgrav        # Best one so far, save it but keep looking for a better one
253986ba33cSDag-Erling Smørgrav        func_check_prog_result=$_G_path_prog
254986ba33cSDag-Erling Smørgrav        _G_path_prog_max=$_G_count
255986ba33cSDag-Erling Smørgrav      fi
256986ba33cSDag-Erling Smørgrav      # 10*(2^10) chars as input seems more than enough
257986ba33cSDag-Erling Smørgrav      test 10 -lt "$_G_count" && break
258986ba33cSDag-Erling Smørgrav    done
259986ba33cSDag-Erling Smørgrav    rm -f conftest.in conftest.tmp conftest.nl conftest.out
260986ba33cSDag-Erling Smørgrav  }
261986ba33cSDag-Erling Smørgrav
262986ba33cSDag-Erling Smørgrav  func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin
263986ba33cSDag-Erling Smørgrav  rm -f conftest.sed
264986ba33cSDag-Erling Smørgrav  SED=$func_path_progs_result
265986ba33cSDag-Erling Smørgrav}
266986ba33cSDag-Erling Smørgrav
267986ba33cSDag-Erling Smørgrav
268986ba33cSDag-Erling Smørgrav# Unless the user overrides by setting GREP, search the path for either GNU
269986ba33cSDag-Erling Smørgrav# grep, or the grep that truncates its output the least.
270986ba33cSDag-Erling Smørgravtest -z "$GREP" && {
271986ba33cSDag-Erling Smørgrav  func_check_prog_grep ()
272986ba33cSDag-Erling Smørgrav  {
273986ba33cSDag-Erling Smørgrav    _G_path_prog=$1
274986ba33cSDag-Erling Smørgrav
275986ba33cSDag-Erling Smørgrav    _G_count=0
276986ba33cSDag-Erling Smørgrav    _G_path_prog_max=0
277986ba33cSDag-Erling Smørgrav    printf 0123456789 >conftest.in
278986ba33cSDag-Erling Smørgrav    while :
279986ba33cSDag-Erling Smørgrav    do
280986ba33cSDag-Erling Smørgrav      cat conftest.in conftest.in >conftest.tmp
281986ba33cSDag-Erling Smørgrav      mv conftest.tmp conftest.in
282986ba33cSDag-Erling Smørgrav      cp conftest.in conftest.nl
283986ba33cSDag-Erling Smørgrav      echo 'GREP' >> conftest.nl
284986ba33cSDag-Erling Smørgrav      "$_G_path_prog" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break
285986ba33cSDag-Erling Smørgrav      diff conftest.out conftest.nl >/dev/null 2>&1 || break
286986ba33cSDag-Erling Smørgrav      _G_count=`expr $_G_count + 1`
287986ba33cSDag-Erling Smørgrav      if test "$_G_count" -gt "$_G_path_prog_max"; then
288986ba33cSDag-Erling Smørgrav        # Best one so far, save it but keep looking for a better one
289986ba33cSDag-Erling Smørgrav        func_check_prog_result=$_G_path_prog
290986ba33cSDag-Erling Smørgrav        _G_path_prog_max=$_G_count
291986ba33cSDag-Erling Smørgrav      fi
292986ba33cSDag-Erling Smørgrav      # 10*(2^10) chars as input seems more than enough
293986ba33cSDag-Erling Smørgrav      test 10 -lt "$_G_count" && break
294986ba33cSDag-Erling Smørgrav    done
295986ba33cSDag-Erling Smørgrav    rm -f conftest.in conftest.tmp conftest.nl conftest.out
296986ba33cSDag-Erling Smørgrav  }
297986ba33cSDag-Erling Smørgrav
298986ba33cSDag-Erling Smørgrav  func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin
299986ba33cSDag-Erling Smørgrav  GREP=$func_path_progs_result
300986ba33cSDag-Erling Smørgrav}
301986ba33cSDag-Erling Smørgrav
302986ba33cSDag-Erling Smørgrav
303986ba33cSDag-Erling Smørgrav## ------------------------------- ##
304986ba33cSDag-Erling Smørgrav## User overridable command paths. ##
305986ba33cSDag-Erling Smørgrav## ------------------------------- ##
306986ba33cSDag-Erling Smørgrav
307986ba33cSDag-Erling Smørgrav# All uppercase variable names are used for environment variables.  These
308986ba33cSDag-Erling Smørgrav# variables can be overridden by the user before calling a script that
309986ba33cSDag-Erling Smørgrav# uses them if a suitable command of that name is not already available
310986ba33cSDag-Erling Smørgrav# in the command search PATH.
311986ba33cSDag-Erling Smørgrav
312986ba33cSDag-Erling Smørgrav: ${CP="cp -f"}
313986ba33cSDag-Erling Smørgrav: ${ECHO="printf %s\n"}
314986ba33cSDag-Erling Smørgrav: ${EGREP="$GREP -E"}
315986ba33cSDag-Erling Smørgrav: ${FGREP="$GREP -F"}
316986ba33cSDag-Erling Smørgrav: ${LN_S="ln -s"}
317986ba33cSDag-Erling Smørgrav: ${MAKE="make"}
318986ba33cSDag-Erling Smørgrav: ${MKDIR="mkdir"}
319986ba33cSDag-Erling Smørgrav: ${MV="mv -f"}
320986ba33cSDag-Erling Smørgrav: ${RM="rm -f"}
321986ba33cSDag-Erling Smørgrav: ${SHELL="${CONFIG_SHELL-/bin/sh}"}
322986ba33cSDag-Erling Smørgrav
323986ba33cSDag-Erling Smørgrav
324986ba33cSDag-Erling Smørgrav## -------------------- ##
325986ba33cSDag-Erling Smørgrav## Useful sed snippets. ##
326986ba33cSDag-Erling Smørgrav## -------------------- ##
327986ba33cSDag-Erling Smørgrav
328986ba33cSDag-Erling Smørgravsed_dirname='s|/[^/]*$||'
329986ba33cSDag-Erling Smørgravsed_basename='s|^.*/||'
330986ba33cSDag-Erling Smørgrav
331986ba33cSDag-Erling Smørgrav# Sed substitution that helps us do robust quoting.  It backslashifies
332986ba33cSDag-Erling Smørgrav# metacharacters that are still active within double-quoted strings.
333986ba33cSDag-Erling Smørgravsed_quote_subst='s|\([`"$\\]\)|\\\1|g'
334986ba33cSDag-Erling Smørgrav
335986ba33cSDag-Erling Smørgrav# Same as above, but do not quote variable references.
336986ba33cSDag-Erling Smørgravsed_double_quote_subst='s/\(["`\\]\)/\\\1/g'
337986ba33cSDag-Erling Smørgrav
338986ba33cSDag-Erling Smørgrav# Sed substitution that turns a string into a regex matching for the
339986ba33cSDag-Erling Smørgrav# string literally.
340986ba33cSDag-Erling Smørgravsed_make_literal_regex='s|[].[^$\\*\/]|\\&|g'
341986ba33cSDag-Erling Smørgrav
342986ba33cSDag-Erling Smørgrav# Sed substitution that converts a w32 file name or path
343986ba33cSDag-Erling Smørgrav# that contains forward slashes, into one that contains
344986ba33cSDag-Erling Smørgrav# (escaped) backslashes.  A very naive implementation.
345986ba33cSDag-Erling Smørgravsed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g'
346986ba33cSDag-Erling Smørgrav
347986ba33cSDag-Erling Smørgrav# Re-'\' parameter expansions in output of sed_double_quote_subst that
348986ba33cSDag-Erling Smørgrav# were '\'-ed in input to the same.  If an odd number of '\' preceded a
349986ba33cSDag-Erling Smørgrav# '$' in input to sed_double_quote_subst, that '$' was protected from
350986ba33cSDag-Erling Smørgrav# expansion.  Since each input '\' is now two '\'s, look for any number
351986ba33cSDag-Erling Smørgrav# of runs of four '\'s followed by two '\'s and then a '$'.  '\' that '$'.
352986ba33cSDag-Erling Smørgrav_G_bs='\\'
353986ba33cSDag-Erling Smørgrav_G_bs2='\\\\'
354986ba33cSDag-Erling Smørgrav_G_bs4='\\\\\\\\'
355986ba33cSDag-Erling Smørgrav_G_dollar='\$'
356986ba33cSDag-Erling Smørgravsed_double_backslash="\
357986ba33cSDag-Erling Smørgrav  s/$_G_bs4/&\\
358986ba33cSDag-Erling Smørgrav/g
359986ba33cSDag-Erling Smørgrav  s/^$_G_bs2$_G_dollar/$_G_bs&/
360986ba33cSDag-Erling Smørgrav  s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g
361986ba33cSDag-Erling Smørgrav  s/\n//g"
362986ba33cSDag-Erling Smørgrav
363986ba33cSDag-Erling Smørgrav
364986ba33cSDag-Erling Smørgrav## ----------------- ##
365986ba33cSDag-Erling Smørgrav## Global variables. ##
366986ba33cSDag-Erling Smørgrav## ----------------- ##
367986ba33cSDag-Erling Smørgrav
368986ba33cSDag-Erling Smørgrav# Except for the global variables explicitly listed below, the following
369986ba33cSDag-Erling Smørgrav# functions in the '^func_' namespace, and the '^require_' namespace
370986ba33cSDag-Erling Smørgrav# variables initialised in the 'Resource management' section, sourcing
371986ba33cSDag-Erling Smørgrav# this file will not pollute your global namespace with anything
372986ba33cSDag-Erling Smørgrav# else. There's no portable way to scope variables in Bourne shell
373986ba33cSDag-Erling Smørgrav# though, so actually running these functions will sometimes place
374986ba33cSDag-Erling Smørgrav# results into a variable named after the function, and often use
375986ba33cSDag-Erling Smørgrav# temporary variables in the '^_G_' namespace. If you are careful to
376986ba33cSDag-Erling Smørgrav# avoid using those namespaces casually in your sourcing script, things
377986ba33cSDag-Erling Smørgrav# should continue to work as you expect. And, of course, you can freely
378986ba33cSDag-Erling Smørgrav# overwrite any of the functions or variables defined here before
379986ba33cSDag-Erling Smørgrav# calling anything to customize them.
380986ba33cSDag-Erling Smørgrav
381986ba33cSDag-Erling SmørgravEXIT_SUCCESS=0
382986ba33cSDag-Erling SmørgravEXIT_FAILURE=1
383986ba33cSDag-Erling SmørgravEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.
384986ba33cSDag-Erling SmørgravEXIT_SKIP=77	  # $? = 77 is used to indicate a skipped test to automake.
385986ba33cSDag-Erling Smørgrav
386986ba33cSDag-Erling Smørgrav# Allow overriding, eg assuming that you follow the convention of
387986ba33cSDag-Erling Smørgrav# putting '$debug_cmd' at the start of all your functions, you can get
388986ba33cSDag-Erling Smørgrav# bash to show function call trace with:
389986ba33cSDag-Erling Smørgrav#
390*5afab0e5SDag-Erling Smørgrav#    debug_cmd='echo "${FUNCNAME[0]} $*" >&2' bash your-script-name
391986ba33cSDag-Erling Smørgravdebug_cmd=${debug_cmd-":"}
392986ba33cSDag-Erling Smørgravexit_cmd=:
393986ba33cSDag-Erling Smørgrav
394986ba33cSDag-Erling Smørgrav# By convention, finish your script with:
395986ba33cSDag-Erling Smørgrav#
396986ba33cSDag-Erling Smørgrav#    exit $exit_status
397986ba33cSDag-Erling Smørgrav#
398986ba33cSDag-Erling Smørgrav# so that you can set exit_status to non-zero if you want to indicate
399986ba33cSDag-Erling Smørgrav# something went wrong during execution without actually bailing out at
400986ba33cSDag-Erling Smørgrav# the point of failure.
401986ba33cSDag-Erling Smørgravexit_status=$EXIT_SUCCESS
4027b5038d7SDag-Erling Smørgrav
4037b5038d7SDag-Erling Smørgrav# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
4047b5038d7SDag-Erling Smørgrav# is ksh but when the shell is invoked as "sh" and the current value of
4057b5038d7SDag-Erling Smørgrav# the _XPG environment variable is not equal to 1 (one), the special
4067b5038d7SDag-Erling Smørgrav# positional parameter $0, within a function call, is the name of the
4077b5038d7SDag-Erling Smørgrav# function.
408986ba33cSDag-Erling Smørgravprogpath=$0
409986ba33cSDag-Erling Smørgrav
410986ba33cSDag-Erling Smørgrav# The name of this program.
411986ba33cSDag-Erling Smørgravprogname=`$ECHO "$progpath" |$SED "$sed_basename"`
412986ba33cSDag-Erling Smørgrav
413986ba33cSDag-Erling Smørgrav# Make sure we have an absolute progpath for reexecution:
414986ba33cSDag-Erling Smørgravcase $progpath in
415986ba33cSDag-Erling Smørgrav  [\\/]*|[A-Za-z]:\\*) ;;
416986ba33cSDag-Erling Smørgrav  *[\\/]*)
417986ba33cSDag-Erling Smørgrav     progdir=`$ECHO "$progpath" |$SED "$sed_dirname"`
418986ba33cSDag-Erling Smørgrav     progdir=`cd "$progdir" && pwd`
419986ba33cSDag-Erling Smørgrav     progpath=$progdir/$progname
420986ba33cSDag-Erling Smørgrav     ;;
421986ba33cSDag-Erling Smørgrav  *)
422986ba33cSDag-Erling Smørgrav     _G_IFS=$IFS
423986ba33cSDag-Erling Smørgrav     IFS=${PATH_SEPARATOR-:}
424986ba33cSDag-Erling Smørgrav     for progdir in $PATH; do
425986ba33cSDag-Erling Smørgrav       IFS=$_G_IFS
426986ba33cSDag-Erling Smørgrav       test -x "$progdir/$progname" && break
427986ba33cSDag-Erling Smørgrav     done
428986ba33cSDag-Erling Smørgrav     IFS=$_G_IFS
429986ba33cSDag-Erling Smørgrav     test -n "$progdir" || progdir=`pwd`
430986ba33cSDag-Erling Smørgrav     progpath=$progdir/$progname
431986ba33cSDag-Erling Smørgrav     ;;
432986ba33cSDag-Erling Smørgravesac
4337b5038d7SDag-Erling Smørgrav
4347b5038d7SDag-Erling Smørgrav
435986ba33cSDag-Erling Smørgrav## ----------------- ##
436986ba33cSDag-Erling Smørgrav## Standard options. ##
437986ba33cSDag-Erling Smørgrav## ----------------- ##
4387b5038d7SDag-Erling Smørgrav
439986ba33cSDag-Erling Smørgrav# The following options affect the operation of the functions defined
440986ba33cSDag-Erling Smørgrav# below, and should be set appropriately depending on run-time para-
441986ba33cSDag-Erling Smørgrav# meters passed on the command line.
4427b5038d7SDag-Erling Smørgrav
443986ba33cSDag-Erling Smørgravopt_dry_run=false
444986ba33cSDag-Erling Smørgravopt_quiet=false
445986ba33cSDag-Erling Smørgravopt_verbose=false
4467b5038d7SDag-Erling Smørgrav
447986ba33cSDag-Erling Smørgrav# Categories 'all' and 'none' are always available.  Append any others
448986ba33cSDag-Erling Smørgrav# you will pass as the first argument to func_warning from your own
449986ba33cSDag-Erling Smørgrav# code.
450986ba33cSDag-Erling Smørgravwarning_categories=
4517b5038d7SDag-Erling Smørgrav
452986ba33cSDag-Erling Smørgrav# By default, display warnings according to 'opt_warning_types'.  Set
453986ba33cSDag-Erling Smørgrav# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to
454986ba33cSDag-Erling Smørgrav# treat the next displayed warning as a fatal error.
455986ba33cSDag-Erling Smørgravwarning_func=func_warn_and_continue
4567b5038d7SDag-Erling Smørgrav
457986ba33cSDag-Erling Smørgrav# Set to 'all' to display all warnings, 'none' to suppress all
458986ba33cSDag-Erling Smørgrav# warnings, or a space delimited list of some subset of
459986ba33cSDag-Erling Smørgrav# 'warning_categories' to display only the listed warnings.
460986ba33cSDag-Erling Smørgravopt_warning_types=all
4617b5038d7SDag-Erling Smørgrav
462986ba33cSDag-Erling Smørgrav
463986ba33cSDag-Erling Smørgrav## -------------------- ##
464986ba33cSDag-Erling Smørgrav## Resource management. ##
465986ba33cSDag-Erling Smørgrav## -------------------- ##
466986ba33cSDag-Erling Smørgrav
467986ba33cSDag-Erling Smørgrav# This section contains definitions for functions that each ensure a
468986ba33cSDag-Erling Smørgrav# particular resource (a file, or a non-empty configuration variable for
469986ba33cSDag-Erling Smørgrav# example) is available, and if appropriate to extract default values
470986ba33cSDag-Erling Smørgrav# from pertinent package files. Call them using their associated
471986ba33cSDag-Erling Smørgrav# 'require_*' variable to ensure that they are executed, at most, once.
472986ba33cSDag-Erling Smørgrav#
473986ba33cSDag-Erling Smørgrav# It's entirely deliberate that calling these functions can set
474986ba33cSDag-Erling Smørgrav# variables that don't obey the namespace limitations obeyed by the rest
475986ba33cSDag-Erling Smørgrav# of this file, in order that that they be as useful as possible to
476986ba33cSDag-Erling Smørgrav# callers.
477986ba33cSDag-Erling Smørgrav
478986ba33cSDag-Erling Smørgrav
479986ba33cSDag-Erling Smørgrav# require_term_colors
480986ba33cSDag-Erling Smørgrav# -------------------
481986ba33cSDag-Erling Smørgrav# Allow display of bold text on terminals that support it.
482986ba33cSDag-Erling Smørgravrequire_term_colors=func_require_term_colors
483986ba33cSDag-Erling Smørgravfunc_require_term_colors ()
484986ba33cSDag-Erling Smørgrav{
485986ba33cSDag-Erling Smørgrav    $debug_cmd
486986ba33cSDag-Erling Smørgrav
487986ba33cSDag-Erling Smørgrav    test -t 1 && {
488986ba33cSDag-Erling Smørgrav      # COLORTERM and USE_ANSI_COLORS environment variables take
489986ba33cSDag-Erling Smørgrav      # precedence, because most terminfo databases neglect to describe
490986ba33cSDag-Erling Smørgrav      # whether color sequences are supported.
491986ba33cSDag-Erling Smørgrav      test -n "${COLORTERM+set}" && : ${USE_ANSI_COLORS="1"}
492986ba33cSDag-Erling Smørgrav
493986ba33cSDag-Erling Smørgrav      if test 1 = "$USE_ANSI_COLORS"; then
494986ba33cSDag-Erling Smørgrav        # Standard ANSI escape sequences
495986ba33cSDag-Erling Smørgrav        tc_reset=''
496986ba33cSDag-Erling Smørgrav        tc_bold='';   tc_standout=''
497986ba33cSDag-Erling Smørgrav        tc_red='';   tc_green=''
498986ba33cSDag-Erling Smørgrav        tc_blue='';  tc_cyan=''
499986ba33cSDag-Erling Smørgrav      else
500986ba33cSDag-Erling Smørgrav        # Otherwise trust the terminfo database after all.
501986ba33cSDag-Erling Smørgrav        test -n "`tput sgr0 2>/dev/null`" && {
502986ba33cSDag-Erling Smørgrav          tc_reset=`tput sgr0`
503986ba33cSDag-Erling Smørgrav          test -n "`tput bold 2>/dev/null`" && tc_bold=`tput bold`
504986ba33cSDag-Erling Smørgrav          tc_standout=$tc_bold
505986ba33cSDag-Erling Smørgrav          test -n "`tput smso 2>/dev/null`" && tc_standout=`tput smso`
506986ba33cSDag-Erling Smørgrav          test -n "`tput setaf 1 2>/dev/null`" && tc_red=`tput setaf 1`
507986ba33cSDag-Erling Smørgrav          test -n "`tput setaf 2 2>/dev/null`" && tc_green=`tput setaf 2`
508986ba33cSDag-Erling Smørgrav          test -n "`tput setaf 4 2>/dev/null`" && tc_blue=`tput setaf 4`
509986ba33cSDag-Erling Smørgrav          test -n "`tput setaf 5 2>/dev/null`" && tc_cyan=`tput setaf 5`
510986ba33cSDag-Erling Smørgrav        }
511986ba33cSDag-Erling Smørgrav      fi
512986ba33cSDag-Erling Smørgrav    }
513986ba33cSDag-Erling Smørgrav
514986ba33cSDag-Erling Smørgrav    require_term_colors=:
515986ba33cSDag-Erling Smørgrav}
516986ba33cSDag-Erling Smørgrav
517986ba33cSDag-Erling Smørgrav
518986ba33cSDag-Erling Smørgrav## ----------------- ##
519986ba33cSDag-Erling Smørgrav## Function library. ##
520986ba33cSDag-Erling Smørgrav## ----------------- ##
521986ba33cSDag-Erling Smørgrav
522986ba33cSDag-Erling Smørgrav# This section contains a variety of useful functions to call in your
523986ba33cSDag-Erling Smørgrav# scripts. Take note of the portable wrappers for features provided by
524986ba33cSDag-Erling Smørgrav# some modern shells, which will fall back to slower equivalents on
525986ba33cSDag-Erling Smørgrav# less featureful shells.
526986ba33cSDag-Erling Smørgrav
527986ba33cSDag-Erling Smørgrav
528986ba33cSDag-Erling Smørgrav# func_append VAR VALUE
529986ba33cSDag-Erling Smørgrav# ---------------------
530986ba33cSDag-Erling Smørgrav# Append VALUE onto the existing contents of VAR.
531986ba33cSDag-Erling Smørgrav
532986ba33cSDag-Erling Smørgrav  # We should try to minimise forks, especially on Windows where they are
533986ba33cSDag-Erling Smørgrav  # unreasonably slow, so skip the feature probes when bash or zsh are
534986ba33cSDag-Erling Smørgrav  # being used:
535986ba33cSDag-Erling Smørgrav  if test set = "${BASH_VERSION+set}${ZSH_VERSION+set}"; then
536986ba33cSDag-Erling Smørgrav    : ${_G_HAVE_ARITH_OP="yes"}
537986ba33cSDag-Erling Smørgrav    : ${_G_HAVE_XSI_OPS="yes"}
538986ba33cSDag-Erling Smørgrav    # The += operator was introduced in bash 3.1
539986ba33cSDag-Erling Smørgrav    case $BASH_VERSION in
540986ba33cSDag-Erling Smørgrav      [12].* | 3.0 | 3.0*) ;;
541986ba33cSDag-Erling Smørgrav      *)
542986ba33cSDag-Erling Smørgrav        : ${_G_HAVE_PLUSEQ_OP="yes"}
543986ba33cSDag-Erling Smørgrav        ;;
544986ba33cSDag-Erling Smørgrav    esac
545986ba33cSDag-Erling Smørgrav  fi
546986ba33cSDag-Erling Smørgrav
547986ba33cSDag-Erling Smørgrav  # _G_HAVE_PLUSEQ_OP
548986ba33cSDag-Erling Smørgrav  # Can be empty, in which case the shell is probed, "yes" if += is
549986ba33cSDag-Erling Smørgrav  # useable or anything else if it does not work.
550986ba33cSDag-Erling Smørgrav  test -z "$_G_HAVE_PLUSEQ_OP" \
551986ba33cSDag-Erling Smørgrav    && (eval 'x=a; x+=" b"; test "a b" = "$x"') 2>/dev/null \
552986ba33cSDag-Erling Smørgrav    && _G_HAVE_PLUSEQ_OP=yes
553986ba33cSDag-Erling Smørgrav
554986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_PLUSEQ_OP"
555986ba33cSDag-Erling Smørgravthen
556986ba33cSDag-Erling Smørgrav  # This is an XSI compatible shell, allowing a faster implementation...
557986ba33cSDag-Erling Smørgrav  eval 'func_append ()
558986ba33cSDag-Erling Smørgrav  {
559986ba33cSDag-Erling Smørgrav    $debug_cmd
560986ba33cSDag-Erling Smørgrav
561986ba33cSDag-Erling Smørgrav    eval "$1+=\$2"
562986ba33cSDag-Erling Smørgrav  }'
563986ba33cSDag-Erling Smørgravelse
564986ba33cSDag-Erling Smørgrav  # ...otherwise fall back to using expr, which is often a shell builtin.
565986ba33cSDag-Erling Smørgrav  func_append ()
566986ba33cSDag-Erling Smørgrav  {
567986ba33cSDag-Erling Smørgrav    $debug_cmd
568986ba33cSDag-Erling Smørgrav
569986ba33cSDag-Erling Smørgrav    eval "$1=\$$1\$2"
570986ba33cSDag-Erling Smørgrav  }
571986ba33cSDag-Erling Smørgravfi
572986ba33cSDag-Erling Smørgrav
573986ba33cSDag-Erling Smørgrav
574986ba33cSDag-Erling Smørgrav# func_append_quoted VAR VALUE
575986ba33cSDag-Erling Smørgrav# ----------------------------
576986ba33cSDag-Erling Smørgrav# Quote VALUE and append to the end of shell variable VAR, separated
577986ba33cSDag-Erling Smørgrav# by a space.
578986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_PLUSEQ_OP"; then
579986ba33cSDag-Erling Smørgrav  eval 'func_append_quoted ()
580986ba33cSDag-Erling Smørgrav  {
581986ba33cSDag-Erling Smørgrav    $debug_cmd
582986ba33cSDag-Erling Smørgrav
583986ba33cSDag-Erling Smørgrav    func_quote_for_eval "$2"
584986ba33cSDag-Erling Smørgrav    eval "$1+=\\ \$func_quote_for_eval_result"
585986ba33cSDag-Erling Smørgrav  }'
586986ba33cSDag-Erling Smørgravelse
587986ba33cSDag-Erling Smørgrav  func_append_quoted ()
588986ba33cSDag-Erling Smørgrav  {
589986ba33cSDag-Erling Smørgrav    $debug_cmd
590986ba33cSDag-Erling Smørgrav
591986ba33cSDag-Erling Smørgrav    func_quote_for_eval "$2"
592986ba33cSDag-Erling Smørgrav    eval "$1=\$$1\\ \$func_quote_for_eval_result"
593986ba33cSDag-Erling Smørgrav  }
594986ba33cSDag-Erling Smørgravfi
595986ba33cSDag-Erling Smørgrav
596986ba33cSDag-Erling Smørgrav
597986ba33cSDag-Erling Smørgrav# func_append_uniq VAR VALUE
598986ba33cSDag-Erling Smørgrav# --------------------------
599986ba33cSDag-Erling Smørgrav# Append unique VALUE onto the existing contents of VAR, assuming
600986ba33cSDag-Erling Smørgrav# entries are delimited by the first character of VALUE.  For example:
601986ba33cSDag-Erling Smørgrav#
602986ba33cSDag-Erling Smørgrav#   func_append_uniq options " --another-option option-argument"
603986ba33cSDag-Erling Smørgrav#
604986ba33cSDag-Erling Smørgrav# will only append to $options if " --another-option option-argument "
605986ba33cSDag-Erling Smørgrav# is not already present somewhere in $options already (note spaces at
606986ba33cSDag-Erling Smørgrav# each end implied by leading space in second argument).
607986ba33cSDag-Erling Smørgravfunc_append_uniq ()
608986ba33cSDag-Erling Smørgrav{
609986ba33cSDag-Erling Smørgrav    $debug_cmd
610986ba33cSDag-Erling Smørgrav
611986ba33cSDag-Erling Smørgrav    eval _G_current_value='`$ECHO $'$1'`'
612986ba33cSDag-Erling Smørgrav    _G_delim=`expr "$2" : '\(.\)'`
613986ba33cSDag-Erling Smørgrav
614986ba33cSDag-Erling Smørgrav    case $_G_delim$_G_current_value$_G_delim in
615986ba33cSDag-Erling Smørgrav      *"$2$_G_delim"*) ;;
616986ba33cSDag-Erling Smørgrav      *) func_append "$@" ;;
617986ba33cSDag-Erling Smørgrav    esac
618986ba33cSDag-Erling Smørgrav}
619986ba33cSDag-Erling Smørgrav
620986ba33cSDag-Erling Smørgrav
621986ba33cSDag-Erling Smørgrav# func_arith TERM...
622986ba33cSDag-Erling Smørgrav# ------------------
623986ba33cSDag-Erling Smørgrav# Set func_arith_result to the result of evaluating TERMs.
624986ba33cSDag-Erling Smørgrav  test -z "$_G_HAVE_ARITH_OP" \
625986ba33cSDag-Erling Smørgrav    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \
626986ba33cSDag-Erling Smørgrav    && _G_HAVE_ARITH_OP=yes
627986ba33cSDag-Erling Smørgrav
628986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_ARITH_OP"; then
629986ba33cSDag-Erling Smørgrav  eval 'func_arith ()
630986ba33cSDag-Erling Smørgrav  {
631986ba33cSDag-Erling Smørgrav    $debug_cmd
632986ba33cSDag-Erling Smørgrav
633986ba33cSDag-Erling Smørgrav    func_arith_result=$(( $* ))
634986ba33cSDag-Erling Smørgrav  }'
635986ba33cSDag-Erling Smørgravelse
636986ba33cSDag-Erling Smørgrav  func_arith ()
637986ba33cSDag-Erling Smørgrav  {
638986ba33cSDag-Erling Smørgrav    $debug_cmd
639986ba33cSDag-Erling Smørgrav
640986ba33cSDag-Erling Smørgrav    func_arith_result=`expr "$@"`
641986ba33cSDag-Erling Smørgrav  }
642986ba33cSDag-Erling Smørgravfi
643986ba33cSDag-Erling Smørgrav
644986ba33cSDag-Erling Smørgrav
645986ba33cSDag-Erling Smørgrav# func_basename FILE
646986ba33cSDag-Erling Smørgrav# ------------------
647986ba33cSDag-Erling Smørgrav# Set func_basename_result to FILE with everything up to and including
648986ba33cSDag-Erling Smørgrav# the last / stripped.
649986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_XSI_OPS"; then
650986ba33cSDag-Erling Smørgrav  # If this shell supports suffix pattern removal, then use it to avoid
651986ba33cSDag-Erling Smørgrav  # forking. Hide the definitions single quotes in case the shell chokes
652986ba33cSDag-Erling Smørgrav  # on unsupported syntax...
653986ba33cSDag-Erling Smørgrav  _b='func_basename_result=${1##*/}'
654986ba33cSDag-Erling Smørgrav  _d='case $1 in
655986ba33cSDag-Erling Smørgrav        */*) func_dirname_result=${1%/*}$2 ;;
656986ba33cSDag-Erling Smørgrav        *  ) func_dirname_result=$3        ;;
657986ba33cSDag-Erling Smørgrav      esac'
658986ba33cSDag-Erling Smørgrav
659986ba33cSDag-Erling Smørgravelse
660986ba33cSDag-Erling Smørgrav  # ...otherwise fall back to using sed.
661986ba33cSDag-Erling Smørgrav  _b='func_basename_result=`$ECHO "$1" |$SED "$sed_basename"`'
662986ba33cSDag-Erling Smørgrav  _d='func_dirname_result=`$ECHO "$1"  |$SED "$sed_dirname"`
663986ba33cSDag-Erling Smørgrav      if test "X$func_dirname_result" = "X$1"; then
664986ba33cSDag-Erling Smørgrav        func_dirname_result=$3
665986ba33cSDag-Erling Smørgrav      else
666986ba33cSDag-Erling Smørgrav        func_append func_dirname_result "$2"
667986ba33cSDag-Erling Smørgrav      fi'
668986ba33cSDag-Erling Smørgravfi
669986ba33cSDag-Erling Smørgrav
670986ba33cSDag-Erling Smørgraveval 'func_basename ()
671986ba33cSDag-Erling Smørgrav{
672986ba33cSDag-Erling Smørgrav    $debug_cmd
673986ba33cSDag-Erling Smørgrav
674986ba33cSDag-Erling Smørgrav    '"$_b"'
675986ba33cSDag-Erling Smørgrav}'
676986ba33cSDag-Erling Smørgrav
677986ba33cSDag-Erling Smørgrav
678986ba33cSDag-Erling Smørgrav# func_dirname FILE APPEND NONDIR_REPLACEMENT
679986ba33cSDag-Erling Smørgrav# -------------------------------------------
6807b5038d7SDag-Erling Smørgrav# Compute the dirname of FILE.  If nonempty, add APPEND to the result,
6817b5038d7SDag-Erling Smørgrav# otherwise set result to NONDIR_REPLACEMENT.
682986ba33cSDag-Erling Smørgraveval 'func_dirname ()
6837b5038d7SDag-Erling Smørgrav{
684986ba33cSDag-Erling Smørgrav    $debug_cmd
685986ba33cSDag-Erling Smørgrav
686986ba33cSDag-Erling Smørgrav    '"$_d"'
687986ba33cSDag-Erling Smørgrav}'
6887b5038d7SDag-Erling Smørgrav
6897b5038d7SDag-Erling Smørgrav
690986ba33cSDag-Erling Smørgrav# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT
691986ba33cSDag-Erling Smørgrav# --------------------------------------------------------
692986ba33cSDag-Erling Smørgrav# Perform func_basename and func_dirname in a single function
6937b5038d7SDag-Erling Smørgrav# call:
6947b5038d7SDag-Erling Smørgrav#   dirname:  Compute the dirname of FILE.  If nonempty,
6957b5038d7SDag-Erling Smørgrav#             add APPEND to the result, otherwise set result
6967b5038d7SDag-Erling Smørgrav#             to NONDIR_REPLACEMENT.
6977b5038d7SDag-Erling Smørgrav#             value returned in "$func_dirname_result"
6987b5038d7SDag-Erling Smørgrav#   basename: Compute filename of FILE.
6997b5038d7SDag-Erling Smørgrav#             value retuned in "$func_basename_result"
700986ba33cSDag-Erling Smørgrav# For efficiency, we do not delegate to the functions above but instead
701986ba33cSDag-Erling Smørgrav# duplicate the functionality here.
702986ba33cSDag-Erling Smørgraveval 'func_dirname_and_basename ()
7037b5038d7SDag-Erling Smørgrav{
704986ba33cSDag-Erling Smørgrav    $debug_cmd
705986ba33cSDag-Erling Smørgrav
706986ba33cSDag-Erling Smørgrav    '"$_b"'
707986ba33cSDag-Erling Smørgrav    '"$_d"'
708986ba33cSDag-Erling Smørgrav}'
709986ba33cSDag-Erling Smørgrav
710986ba33cSDag-Erling Smørgrav
711986ba33cSDag-Erling Smørgrav# func_echo ARG...
712986ba33cSDag-Erling Smørgrav# ----------------
713986ba33cSDag-Erling Smørgrav# Echo program name prefixed message.
714986ba33cSDag-Erling Smørgravfunc_echo ()
715986ba33cSDag-Erling Smørgrav{
716986ba33cSDag-Erling Smørgrav    $debug_cmd
717986ba33cSDag-Erling Smørgrav
718986ba33cSDag-Erling Smørgrav    _G_message=$*
719986ba33cSDag-Erling Smørgrav
720986ba33cSDag-Erling Smørgrav    func_echo_IFS=$IFS
721986ba33cSDag-Erling Smørgrav    IFS=$nl
722986ba33cSDag-Erling Smørgrav    for _G_line in $_G_message; do
723986ba33cSDag-Erling Smørgrav      IFS=$func_echo_IFS
724986ba33cSDag-Erling Smørgrav      $ECHO "$progname: $_G_line"
725986ba33cSDag-Erling Smørgrav    done
726986ba33cSDag-Erling Smørgrav    IFS=$func_echo_IFS
727986ba33cSDag-Erling Smørgrav}
728986ba33cSDag-Erling Smørgrav
729986ba33cSDag-Erling Smørgrav
730986ba33cSDag-Erling Smørgrav# func_echo_all ARG...
731986ba33cSDag-Erling Smørgrav# --------------------
732986ba33cSDag-Erling Smørgrav# Invoke $ECHO with all args, space-separated.
733986ba33cSDag-Erling Smørgravfunc_echo_all ()
734986ba33cSDag-Erling Smørgrav{
735986ba33cSDag-Erling Smørgrav    $ECHO "$*"
736986ba33cSDag-Erling Smørgrav}
737986ba33cSDag-Erling Smørgrav
738986ba33cSDag-Erling Smørgrav
739986ba33cSDag-Erling Smørgrav# func_echo_infix_1 INFIX ARG...
740986ba33cSDag-Erling Smørgrav# ------------------------------
741986ba33cSDag-Erling Smørgrav# Echo program name, followed by INFIX on the first line, with any
742986ba33cSDag-Erling Smørgrav# additional lines not showing INFIX.
743986ba33cSDag-Erling Smørgravfunc_echo_infix_1 ()
744986ba33cSDag-Erling Smørgrav{
745986ba33cSDag-Erling Smørgrav    $debug_cmd
746986ba33cSDag-Erling Smørgrav
747986ba33cSDag-Erling Smørgrav    $require_term_colors
748986ba33cSDag-Erling Smørgrav
749986ba33cSDag-Erling Smørgrav    _G_infix=$1; shift
750986ba33cSDag-Erling Smørgrav    _G_indent=$_G_infix
751986ba33cSDag-Erling Smørgrav    _G_prefix="$progname: $_G_infix: "
752986ba33cSDag-Erling Smørgrav    _G_message=$*
753986ba33cSDag-Erling Smørgrav
754986ba33cSDag-Erling Smørgrav    # Strip color escape sequences before counting printable length
755986ba33cSDag-Erling Smørgrav    for _G_tc in "$tc_reset" "$tc_bold" "$tc_standout" "$tc_red" "$tc_green" "$tc_blue" "$tc_cyan"
756986ba33cSDag-Erling Smørgrav    do
757986ba33cSDag-Erling Smørgrav      test -n "$_G_tc" && {
758986ba33cSDag-Erling Smørgrav        _G_esc_tc=`$ECHO "$_G_tc" | $SED "$sed_make_literal_regex"`
759986ba33cSDag-Erling Smørgrav        _G_indent=`$ECHO "$_G_indent" | $SED "s|$_G_esc_tc||g"`
760986ba33cSDag-Erling Smørgrav      }
761986ba33cSDag-Erling Smørgrav    done
762986ba33cSDag-Erling Smørgrav    _G_indent="$progname: "`echo "$_G_indent" | $SED 's|.| |g'`"  " ## exclude from sc_prohibit_nested_quotes
763986ba33cSDag-Erling Smørgrav
764986ba33cSDag-Erling Smørgrav    func_echo_infix_1_IFS=$IFS
765986ba33cSDag-Erling Smørgrav    IFS=$nl
766986ba33cSDag-Erling Smørgrav    for _G_line in $_G_message; do
767986ba33cSDag-Erling Smørgrav      IFS=$func_echo_infix_1_IFS
768986ba33cSDag-Erling Smørgrav      $ECHO "$_G_prefix$tc_bold$_G_line$tc_reset" >&2
769986ba33cSDag-Erling Smørgrav      _G_prefix=$_G_indent
770986ba33cSDag-Erling Smørgrav    done
771986ba33cSDag-Erling Smørgrav    IFS=$func_echo_infix_1_IFS
772986ba33cSDag-Erling Smørgrav}
773986ba33cSDag-Erling Smørgrav
774986ba33cSDag-Erling Smørgrav
775986ba33cSDag-Erling Smørgrav# func_error ARG...
776986ba33cSDag-Erling Smørgrav# -----------------
777986ba33cSDag-Erling Smørgrav# Echo program name prefixed message to standard error.
778986ba33cSDag-Erling Smørgravfunc_error ()
779986ba33cSDag-Erling Smørgrav{
780986ba33cSDag-Erling Smørgrav    $debug_cmd
781986ba33cSDag-Erling Smørgrav
782986ba33cSDag-Erling Smørgrav    $require_term_colors
783986ba33cSDag-Erling Smørgrav
784986ba33cSDag-Erling Smørgrav    func_echo_infix_1 "  $tc_standout${tc_red}error$tc_reset" "$*" >&2
785986ba33cSDag-Erling Smørgrav}
786986ba33cSDag-Erling Smørgrav
787986ba33cSDag-Erling Smørgrav
788986ba33cSDag-Erling Smørgrav# func_fatal_error ARG...
789986ba33cSDag-Erling Smørgrav# -----------------------
790986ba33cSDag-Erling Smørgrav# Echo program name prefixed message to standard error, and exit.
791986ba33cSDag-Erling Smørgravfunc_fatal_error ()
792986ba33cSDag-Erling Smørgrav{
793986ba33cSDag-Erling Smørgrav    $debug_cmd
794986ba33cSDag-Erling Smørgrav
795986ba33cSDag-Erling Smørgrav    func_error "$*"
796986ba33cSDag-Erling Smørgrav    exit $EXIT_FAILURE
797986ba33cSDag-Erling Smørgrav}
798986ba33cSDag-Erling Smørgrav
799986ba33cSDag-Erling Smørgrav
800986ba33cSDag-Erling Smørgrav# func_grep EXPRESSION FILENAME
801986ba33cSDag-Erling Smørgrav# -----------------------------
802986ba33cSDag-Erling Smørgrav# Check whether EXPRESSION matches any line of FILENAME, without output.
803986ba33cSDag-Erling Smørgravfunc_grep ()
804986ba33cSDag-Erling Smørgrav{
805986ba33cSDag-Erling Smørgrav    $debug_cmd
806986ba33cSDag-Erling Smørgrav
807986ba33cSDag-Erling Smørgrav    $GREP "$1" "$2" >/dev/null 2>&1
808986ba33cSDag-Erling Smørgrav}
809986ba33cSDag-Erling Smørgrav
810986ba33cSDag-Erling Smørgrav
811986ba33cSDag-Erling Smørgrav# func_len STRING
812986ba33cSDag-Erling Smørgrav# ---------------
813986ba33cSDag-Erling Smørgrav# Set func_len_result to the length of STRING. STRING may not
814986ba33cSDag-Erling Smørgrav# start with a hyphen.
815986ba33cSDag-Erling Smørgrav  test -z "$_G_HAVE_XSI_OPS" \
816986ba33cSDag-Erling Smørgrav    && (eval 'x=a/b/c;
817986ba33cSDag-Erling Smørgrav      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
818986ba33cSDag-Erling Smørgrav    && _G_HAVE_XSI_OPS=yes
819986ba33cSDag-Erling Smørgrav
820986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_XSI_OPS"; then
821986ba33cSDag-Erling Smørgrav  eval 'func_len ()
822986ba33cSDag-Erling Smørgrav  {
823986ba33cSDag-Erling Smørgrav    $debug_cmd
824986ba33cSDag-Erling Smørgrav
825986ba33cSDag-Erling Smørgrav    func_len_result=${#1}
826986ba33cSDag-Erling Smørgrav  }'
8277b5038d7SDag-Erling Smørgravelse
828986ba33cSDag-Erling Smørgrav  func_len ()
8297b5038d7SDag-Erling Smørgrav  {
830986ba33cSDag-Erling Smørgrav    $debug_cmd
831986ba33cSDag-Erling Smørgrav
832986ba33cSDag-Erling Smørgrav    func_len_result=`expr "$1" : ".*" 2>/dev/null || echo $max_cmd_len`
833986ba33cSDag-Erling Smørgrav  }
834986ba33cSDag-Erling Smørgravfi
835986ba33cSDag-Erling Smørgrav
836986ba33cSDag-Erling Smørgrav
837986ba33cSDag-Erling Smørgrav# func_mkdir_p DIRECTORY-PATH
838986ba33cSDag-Erling Smørgrav# ---------------------------
839986ba33cSDag-Erling Smørgrav# Make sure the entire path to DIRECTORY-PATH is available.
840986ba33cSDag-Erling Smørgravfunc_mkdir_p ()
841986ba33cSDag-Erling Smørgrav{
842986ba33cSDag-Erling Smørgrav    $debug_cmd
843986ba33cSDag-Erling Smørgrav
844986ba33cSDag-Erling Smørgrav    _G_directory_path=$1
845986ba33cSDag-Erling Smørgrav    _G_dir_list=
846986ba33cSDag-Erling Smørgrav
847986ba33cSDag-Erling Smørgrav    if test -n "$_G_directory_path" && test : != "$opt_dry_run"; then
848986ba33cSDag-Erling Smørgrav
849986ba33cSDag-Erling Smørgrav      # Protect directory names starting with '-'
850986ba33cSDag-Erling Smørgrav      case $_G_directory_path in
851986ba33cSDag-Erling Smørgrav        -*) _G_directory_path=./$_G_directory_path ;;
8527b5038d7SDag-Erling Smørgrav      esac
853986ba33cSDag-Erling Smørgrav
854986ba33cSDag-Erling Smørgrav      # While some portion of DIR does not yet exist...
855986ba33cSDag-Erling Smørgrav      while test ! -d "$_G_directory_path"; do
856986ba33cSDag-Erling Smørgrav        # ...make a list in topmost first order.  Use a colon delimited
857986ba33cSDag-Erling Smørgrav	# list incase some portion of path contains whitespace.
858986ba33cSDag-Erling Smørgrav        _G_dir_list=$_G_directory_path:$_G_dir_list
859986ba33cSDag-Erling Smørgrav
860986ba33cSDag-Erling Smørgrav        # If the last portion added has no slash in it, the list is done
861986ba33cSDag-Erling Smørgrav        case $_G_directory_path in */*) ;; *) break ;; esac
862986ba33cSDag-Erling Smørgrav
863986ba33cSDag-Erling Smørgrav        # ...otherwise throw away the child directory and loop
864986ba33cSDag-Erling Smørgrav        _G_directory_path=`$ECHO "$_G_directory_path" | $SED -e "$sed_dirname"`
865986ba33cSDag-Erling Smørgrav      done
866986ba33cSDag-Erling Smørgrav      _G_dir_list=`$ECHO "$_G_dir_list" | $SED 's|:*$||'`
867986ba33cSDag-Erling Smørgrav
868986ba33cSDag-Erling Smørgrav      func_mkdir_p_IFS=$IFS; IFS=:
869986ba33cSDag-Erling Smørgrav      for _G_dir in $_G_dir_list; do
870986ba33cSDag-Erling Smørgrav	IFS=$func_mkdir_p_IFS
871986ba33cSDag-Erling Smørgrav        # mkdir can fail with a 'File exist' error if two processes
872986ba33cSDag-Erling Smørgrav        # try to create one of the directories concurrently.  Don't
873986ba33cSDag-Erling Smørgrav        # stop in that case!
874986ba33cSDag-Erling Smørgrav        $MKDIR "$_G_dir" 2>/dev/null || :
875986ba33cSDag-Erling Smørgrav      done
876986ba33cSDag-Erling Smørgrav      IFS=$func_mkdir_p_IFS
877986ba33cSDag-Erling Smørgrav
878986ba33cSDag-Erling Smørgrav      # Bail out if we (or some other process) failed to create a directory.
879986ba33cSDag-Erling Smørgrav      test -d "$_G_directory_path" || \
880986ba33cSDag-Erling Smørgrav        func_fatal_error "Failed to create '$1'"
881986ba33cSDag-Erling Smørgrav    fi
882986ba33cSDag-Erling Smørgrav}
8837b5038d7SDag-Erling Smørgrav
8847b5038d7SDag-Erling Smørgrav
885986ba33cSDag-Erling Smørgrav# func_mktempdir [BASENAME]
886986ba33cSDag-Erling Smørgrav# -------------------------
887986ba33cSDag-Erling Smørgrav# Make a temporary directory that won't clash with other running
888986ba33cSDag-Erling Smørgrav# libtool processes, and avoids race conditions if possible.  If
889986ba33cSDag-Erling Smørgrav# given, BASENAME is the basename for that directory.
890986ba33cSDag-Erling Smørgravfunc_mktempdir ()
891986ba33cSDag-Erling Smørgrav{
892986ba33cSDag-Erling Smørgrav    $debug_cmd
893986ba33cSDag-Erling Smørgrav
894986ba33cSDag-Erling Smørgrav    _G_template=${TMPDIR-/tmp}/${1-$progname}
895986ba33cSDag-Erling Smørgrav
896986ba33cSDag-Erling Smørgrav    if test : = "$opt_dry_run"; then
897986ba33cSDag-Erling Smørgrav      # Return a directory name, but don't create it in dry-run mode
898986ba33cSDag-Erling Smørgrav      _G_tmpdir=$_G_template-$$
899986ba33cSDag-Erling Smørgrav    else
900986ba33cSDag-Erling Smørgrav
901986ba33cSDag-Erling Smørgrav      # If mktemp works, use that first and foremost
902986ba33cSDag-Erling Smørgrav      _G_tmpdir=`mktemp -d "$_G_template-XXXXXXXX" 2>/dev/null`
903986ba33cSDag-Erling Smørgrav
904986ba33cSDag-Erling Smørgrav      if test ! -d "$_G_tmpdir"; then
905986ba33cSDag-Erling Smørgrav        # Failing that, at least try and use $RANDOM to avoid a race
906986ba33cSDag-Erling Smørgrav        _G_tmpdir=$_G_template-${RANDOM-0}$$
907986ba33cSDag-Erling Smørgrav
908986ba33cSDag-Erling Smørgrav        func_mktempdir_umask=`umask`
909986ba33cSDag-Erling Smørgrav        umask 0077
910986ba33cSDag-Erling Smørgrav        $MKDIR "$_G_tmpdir"
911986ba33cSDag-Erling Smørgrav        umask $func_mktempdir_umask
912986ba33cSDag-Erling Smørgrav      fi
913986ba33cSDag-Erling Smørgrav
914986ba33cSDag-Erling Smørgrav      # If we're not in dry-run mode, bomb out on failure
915986ba33cSDag-Erling Smørgrav      test -d "$_G_tmpdir" || \
916986ba33cSDag-Erling Smørgrav        func_fatal_error "cannot create temporary directory '$_G_tmpdir'"
917986ba33cSDag-Erling Smørgrav    fi
918986ba33cSDag-Erling Smørgrav
919986ba33cSDag-Erling Smørgrav    $ECHO "$_G_tmpdir"
920986ba33cSDag-Erling Smørgrav}
921986ba33cSDag-Erling Smørgrav
9227b5038d7SDag-Erling Smørgrav
9237b5038d7SDag-Erling Smørgrav# func_normal_abspath PATH
924986ba33cSDag-Erling Smørgrav# ------------------------
9257b5038d7SDag-Erling Smørgrav# Remove doubled-up and trailing slashes, "." path components,
9267b5038d7SDag-Erling Smørgrav# and cancel out any ".." path components in PATH after making
9277b5038d7SDag-Erling Smørgrav# it an absolute path.
9287b5038d7SDag-Erling Smørgravfunc_normal_abspath ()
9297b5038d7SDag-Erling Smørgrav{
930986ba33cSDag-Erling Smørgrav    $debug_cmd
931986ba33cSDag-Erling Smørgrav
932986ba33cSDag-Erling Smørgrav    # These SED scripts presuppose an absolute path with a trailing slash.
933986ba33cSDag-Erling Smørgrav    _G_pathcar='s|^/\([^/]*\).*$|\1|'
934986ba33cSDag-Erling Smørgrav    _G_pathcdr='s|^/[^/]*||'
935986ba33cSDag-Erling Smørgrav    _G_removedotparts=':dotsl
936986ba33cSDag-Erling Smørgrav		s|/\./|/|g
937986ba33cSDag-Erling Smørgrav		t dotsl
938986ba33cSDag-Erling Smørgrav		s|/\.$|/|'
939986ba33cSDag-Erling Smørgrav    _G_collapseslashes='s|/\{1,\}|/|g'
940986ba33cSDag-Erling Smørgrav    _G_finalslash='s|/*$|/|'
941986ba33cSDag-Erling Smørgrav
9427b5038d7SDag-Erling Smørgrav    # Start from root dir and reassemble the path.
9437b5038d7SDag-Erling Smørgrav    func_normal_abspath_result=
9447b5038d7SDag-Erling Smørgrav    func_normal_abspath_tpath=$1
9457b5038d7SDag-Erling Smørgrav    func_normal_abspath_altnamespace=
9467b5038d7SDag-Erling Smørgrav    case $func_normal_abspath_tpath in
9477b5038d7SDag-Erling Smørgrav      "")
9487b5038d7SDag-Erling Smørgrav        # Empty path, that just means $cwd.
9497b5038d7SDag-Erling Smørgrav        func_stripname '' '/' "`pwd`"
9507b5038d7SDag-Erling Smørgrav        func_normal_abspath_result=$func_stripname_result
9517b5038d7SDag-Erling Smørgrav        return
9527b5038d7SDag-Erling Smørgrav        ;;
9537b5038d7SDag-Erling Smørgrav      # The next three entries are used to spot a run of precisely
9547b5038d7SDag-Erling Smørgrav      # two leading slashes without using negated character classes;
9557b5038d7SDag-Erling Smørgrav      # we take advantage of case's first-match behaviour.
9567b5038d7SDag-Erling Smørgrav      ///*)
9577b5038d7SDag-Erling Smørgrav        # Unusual form of absolute path, do nothing.
9587b5038d7SDag-Erling Smørgrav        ;;
9597b5038d7SDag-Erling Smørgrav      //*)
9607b5038d7SDag-Erling Smørgrav        # Not necessarily an ordinary path; POSIX reserves leading '//'
9617b5038d7SDag-Erling Smørgrav        # and for example Cygwin uses it to access remote file shares
9627b5038d7SDag-Erling Smørgrav        # over CIFS/SMB, so we conserve a leading double slash if found.
9637b5038d7SDag-Erling Smørgrav        func_normal_abspath_altnamespace=/
9647b5038d7SDag-Erling Smørgrav        ;;
9657b5038d7SDag-Erling Smørgrav      /*)
9667b5038d7SDag-Erling Smørgrav        # Absolute path, do nothing.
9677b5038d7SDag-Erling Smørgrav        ;;
9687b5038d7SDag-Erling Smørgrav      *)
9697b5038d7SDag-Erling Smørgrav        # Relative path, prepend $cwd.
9707b5038d7SDag-Erling Smørgrav        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
9717b5038d7SDag-Erling Smørgrav        ;;
9727b5038d7SDag-Erling Smørgrav    esac
973986ba33cSDag-Erling Smørgrav
9747b5038d7SDag-Erling Smørgrav    # Cancel out all the simple stuff to save iterations.  We also want
9757b5038d7SDag-Erling Smørgrav    # the path to end with a slash for ease of parsing, so make sure
9767b5038d7SDag-Erling Smørgrav    # there is one (and only one) here.
9777b5038d7SDag-Erling Smørgrav    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
978986ba33cSDag-Erling Smørgrav          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
9797b5038d7SDag-Erling Smørgrav    while :; do
9807b5038d7SDag-Erling Smørgrav      # Processed it all yet?
981986ba33cSDag-Erling Smørgrav      if test / = "$func_normal_abspath_tpath"; then
9827b5038d7SDag-Erling Smørgrav        # If we ascended to the root using ".." the result may be empty now.
9837b5038d7SDag-Erling Smørgrav        if test -z "$func_normal_abspath_result"; then
9847b5038d7SDag-Erling Smørgrav          func_normal_abspath_result=/
9857b5038d7SDag-Erling Smørgrav        fi
9867b5038d7SDag-Erling Smørgrav        break
9877b5038d7SDag-Erling Smørgrav      fi
9887b5038d7SDag-Erling Smørgrav      func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \
989986ba33cSDag-Erling Smørgrav          -e "$_G_pathcar"`
9907b5038d7SDag-Erling Smørgrav      func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
991986ba33cSDag-Erling Smørgrav          -e "$_G_pathcdr"`
9927b5038d7SDag-Erling Smørgrav      # Figure out what to do with it
9937b5038d7SDag-Erling Smørgrav      case $func_normal_abspath_tcomponent in
9947b5038d7SDag-Erling Smørgrav        "")
9957b5038d7SDag-Erling Smørgrav          # Trailing empty path component, ignore it.
9967b5038d7SDag-Erling Smørgrav          ;;
9977b5038d7SDag-Erling Smørgrav        ..)
9987b5038d7SDag-Erling Smørgrav          # Parent dir; strip last assembled component from result.
9997b5038d7SDag-Erling Smørgrav          func_dirname "$func_normal_abspath_result"
10007b5038d7SDag-Erling Smørgrav          func_normal_abspath_result=$func_dirname_result
10017b5038d7SDag-Erling Smørgrav          ;;
10027b5038d7SDag-Erling Smørgrav        *)
10037b5038d7SDag-Erling Smørgrav          # Actual path component, append it.
1004986ba33cSDag-Erling Smørgrav          func_append func_normal_abspath_result "/$func_normal_abspath_tcomponent"
10057b5038d7SDag-Erling Smørgrav          ;;
10067b5038d7SDag-Erling Smørgrav      esac
10077b5038d7SDag-Erling Smørgrav    done
10087b5038d7SDag-Erling Smørgrav    # Restore leading double-slash if one was found on entry.
10097b5038d7SDag-Erling Smørgrav    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result
10107b5038d7SDag-Erling Smørgrav}
10117b5038d7SDag-Erling Smørgrav
1012986ba33cSDag-Erling Smørgrav
1013986ba33cSDag-Erling Smørgrav# func_notquiet ARG...
1014986ba33cSDag-Erling Smørgrav# --------------------
1015986ba33cSDag-Erling Smørgrav# Echo program name prefixed message only when not in quiet mode.
1016986ba33cSDag-Erling Smørgravfunc_notquiet ()
1017986ba33cSDag-Erling Smørgrav{
1018986ba33cSDag-Erling Smørgrav    $debug_cmd
1019986ba33cSDag-Erling Smørgrav
1020986ba33cSDag-Erling Smørgrav    $opt_quiet || func_echo ${1+"$@"}
1021986ba33cSDag-Erling Smørgrav
1022986ba33cSDag-Erling Smørgrav    # A bug in bash halts the script if the last line of a function
1023986ba33cSDag-Erling Smørgrav    # fails when set -e is in force, so we need another command to
1024986ba33cSDag-Erling Smørgrav    # work around that:
1025986ba33cSDag-Erling Smørgrav    :
1026986ba33cSDag-Erling Smørgrav}
1027986ba33cSDag-Erling Smørgrav
1028986ba33cSDag-Erling Smørgrav
10297b5038d7SDag-Erling Smørgrav# func_relative_path SRCDIR DSTDIR
1030986ba33cSDag-Erling Smørgrav# --------------------------------
1031986ba33cSDag-Erling Smørgrav# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.
10327b5038d7SDag-Erling Smørgravfunc_relative_path ()
10337b5038d7SDag-Erling Smørgrav{
1034986ba33cSDag-Erling Smørgrav    $debug_cmd
1035986ba33cSDag-Erling Smørgrav
10367b5038d7SDag-Erling Smørgrav    func_relative_path_result=
10377b5038d7SDag-Erling Smørgrav    func_normal_abspath "$1"
10387b5038d7SDag-Erling Smørgrav    func_relative_path_tlibdir=$func_normal_abspath_result
10397b5038d7SDag-Erling Smørgrav    func_normal_abspath "$2"
10407b5038d7SDag-Erling Smørgrav    func_relative_path_tbindir=$func_normal_abspath_result
10417b5038d7SDag-Erling Smørgrav
10427b5038d7SDag-Erling Smørgrav    # Ascend the tree starting from libdir
10437b5038d7SDag-Erling Smørgrav    while :; do
10447b5038d7SDag-Erling Smørgrav      # check if we have found a prefix of bindir
10457b5038d7SDag-Erling Smørgrav      case $func_relative_path_tbindir in
10467b5038d7SDag-Erling Smørgrav        $func_relative_path_tlibdir)
10477b5038d7SDag-Erling Smørgrav          # found an exact match
10487b5038d7SDag-Erling Smørgrav          func_relative_path_tcancelled=
10497b5038d7SDag-Erling Smørgrav          break
10507b5038d7SDag-Erling Smørgrav          ;;
10517b5038d7SDag-Erling Smørgrav        $func_relative_path_tlibdir*)
10527b5038d7SDag-Erling Smørgrav          # found a matching prefix
10537b5038d7SDag-Erling Smørgrav          func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir"
10547b5038d7SDag-Erling Smørgrav          func_relative_path_tcancelled=$func_stripname_result
10557b5038d7SDag-Erling Smørgrav          if test -z "$func_relative_path_result"; then
10567b5038d7SDag-Erling Smørgrav            func_relative_path_result=.
10577b5038d7SDag-Erling Smørgrav          fi
10587b5038d7SDag-Erling Smørgrav          break
10597b5038d7SDag-Erling Smørgrav          ;;
10607b5038d7SDag-Erling Smørgrav        *)
10617b5038d7SDag-Erling Smørgrav          func_dirname $func_relative_path_tlibdir
1062986ba33cSDag-Erling Smørgrav          func_relative_path_tlibdir=$func_dirname_result
1063986ba33cSDag-Erling Smørgrav          if test -z "$func_relative_path_tlibdir"; then
10647b5038d7SDag-Erling Smørgrav            # Have to descend all the way to the root!
10657b5038d7SDag-Erling Smørgrav            func_relative_path_result=../$func_relative_path_result
10667b5038d7SDag-Erling Smørgrav            func_relative_path_tcancelled=$func_relative_path_tbindir
10677b5038d7SDag-Erling Smørgrav            break
10687b5038d7SDag-Erling Smørgrav          fi
10697b5038d7SDag-Erling Smørgrav          func_relative_path_result=../$func_relative_path_result
10707b5038d7SDag-Erling Smørgrav          ;;
10717b5038d7SDag-Erling Smørgrav      esac
10727b5038d7SDag-Erling Smørgrav    done
10737b5038d7SDag-Erling Smørgrav
10747b5038d7SDag-Erling Smørgrav    # Now calculate path; take care to avoid doubling-up slashes.
10757b5038d7SDag-Erling Smørgrav    func_stripname '' '/' "$func_relative_path_result"
10767b5038d7SDag-Erling Smørgrav    func_relative_path_result=$func_stripname_result
10777b5038d7SDag-Erling Smørgrav    func_stripname '/' '/' "$func_relative_path_tcancelled"
1078986ba33cSDag-Erling Smørgrav    if test -n "$func_stripname_result"; then
1079986ba33cSDag-Erling Smørgrav      func_append func_relative_path_result "/$func_stripname_result"
10807b5038d7SDag-Erling Smørgrav    fi
10817b5038d7SDag-Erling Smørgrav
1082986ba33cSDag-Erling Smørgrav    # Normalisation. If bindir is libdir, return '.' else relative path.
1083986ba33cSDag-Erling Smørgrav    if test -n "$func_relative_path_result"; then
1084986ba33cSDag-Erling Smørgrav      func_stripname './' '' "$func_relative_path_result"
10857b5038d7SDag-Erling Smørgrav      func_relative_path_result=$func_stripname_result
10867b5038d7SDag-Erling Smørgrav    fi
10877b5038d7SDag-Erling Smørgrav
1088986ba33cSDag-Erling Smørgrav    test -n "$func_relative_path_result" || func_relative_path_result=.
10897b5038d7SDag-Erling Smørgrav
10907b5038d7SDag-Erling Smørgrav    :
10917b5038d7SDag-Erling Smørgrav}
10927b5038d7SDag-Erling Smørgrav
10937b5038d7SDag-Erling Smørgrav
1094986ba33cSDag-Erling Smørgrav# func_quote_for_eval ARG...
1095986ba33cSDag-Erling Smørgrav# --------------------------
1096986ba33cSDag-Erling Smørgrav# Aesthetically quote ARGs to be evaled later.
1097986ba33cSDag-Erling Smørgrav# This function returns two values:
1098986ba33cSDag-Erling Smørgrav#   i) func_quote_for_eval_result
1099986ba33cSDag-Erling Smørgrav#      double-quoted, suitable for a subsequent eval
1100986ba33cSDag-Erling Smørgrav#  ii) func_quote_for_eval_unquoted_result
1101986ba33cSDag-Erling Smørgrav#      has all characters that are still active within double
1102986ba33cSDag-Erling Smørgrav#      quotes backslashified.
11037b5038d7SDag-Erling Smørgravfunc_quote_for_eval ()
11047b5038d7SDag-Erling Smørgrav{
1105986ba33cSDag-Erling Smørgrav    $debug_cmd
1106986ba33cSDag-Erling Smørgrav
1107986ba33cSDag-Erling Smørgrav    func_quote_for_eval_unquoted_result=
1108986ba33cSDag-Erling Smørgrav    func_quote_for_eval_result=
1109986ba33cSDag-Erling Smørgrav    while test 0 -lt $#; do
11107b5038d7SDag-Erling Smørgrav      case $1 in
11117b5038d7SDag-Erling Smørgrav        *[\\\`\"\$]*)
1112986ba33cSDag-Erling Smørgrav	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
11137b5038d7SDag-Erling Smørgrav        *)
1114986ba33cSDag-Erling Smørgrav          _G_unquoted_arg=$1 ;;
11157b5038d7SDag-Erling Smørgrav      esac
1116986ba33cSDag-Erling Smørgrav      if test -n "$func_quote_for_eval_unquoted_result"; then
1117986ba33cSDag-Erling Smørgrav	func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
1118986ba33cSDag-Erling Smørgrav      else
1119986ba33cSDag-Erling Smørgrav        func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg"
1120986ba33cSDag-Erling Smørgrav      fi
11217b5038d7SDag-Erling Smørgrav
1122986ba33cSDag-Erling Smørgrav      case $_G_unquoted_arg in
11237b5038d7SDag-Erling Smørgrav        # Double-quote args containing shell metacharacters to delay
1124986ba33cSDag-Erling Smørgrav        # word splitting, command substitution and variable expansion
1125986ba33cSDag-Erling Smørgrav        # for a subsequent eval.
11267b5038d7SDag-Erling Smørgrav        # Many Bourne shells cannot handle close brackets correctly
11277b5038d7SDag-Erling Smørgrav        # in scan sets, so we specify it separately.
11287b5038d7SDag-Erling Smørgrav        *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1129986ba33cSDag-Erling Smørgrav          _G_quoted_arg=\"$_G_unquoted_arg\"
11307b5038d7SDag-Erling Smørgrav          ;;
11317b5038d7SDag-Erling Smørgrav        *)
1132986ba33cSDag-Erling Smørgrav          _G_quoted_arg=$_G_unquoted_arg
1133986ba33cSDag-Erling Smørgrav	  ;;
11347b5038d7SDag-Erling Smørgrav      esac
1135986ba33cSDag-Erling Smørgrav
1136986ba33cSDag-Erling Smørgrav      if test -n "$func_quote_for_eval_result"; then
1137986ba33cSDag-Erling Smørgrav	func_append func_quote_for_eval_result " $_G_quoted_arg"
1138986ba33cSDag-Erling Smørgrav      else
1139986ba33cSDag-Erling Smørgrav        func_append func_quote_for_eval_result "$_G_quoted_arg"
1140986ba33cSDag-Erling Smørgrav      fi
1141986ba33cSDag-Erling Smørgrav      shift
1142986ba33cSDag-Erling Smørgrav    done
11437b5038d7SDag-Erling Smørgrav}
11447b5038d7SDag-Erling Smørgrav
11457b5038d7SDag-Erling Smørgrav
1146986ba33cSDag-Erling Smørgrav# func_quote_for_expand ARG
1147986ba33cSDag-Erling Smørgrav# -------------------------
11487b5038d7SDag-Erling Smørgrav# Aesthetically quote ARG to be evaled later; same as above,
11497b5038d7SDag-Erling Smørgrav# but do not quote variable references.
11507b5038d7SDag-Erling Smørgravfunc_quote_for_expand ()
11517b5038d7SDag-Erling Smørgrav{
1152986ba33cSDag-Erling Smørgrav    $debug_cmd
1153986ba33cSDag-Erling Smørgrav
11547b5038d7SDag-Erling Smørgrav    case $1 in
11557b5038d7SDag-Erling Smørgrav      *[\\\`\"]*)
1156986ba33cSDag-Erling Smørgrav	_G_arg=`$ECHO "$1" | $SED \
1157986ba33cSDag-Erling Smørgrav	    -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;;
11587b5038d7SDag-Erling Smørgrav      *)
1159986ba33cSDag-Erling Smørgrav        _G_arg=$1 ;;
11607b5038d7SDag-Erling Smørgrav    esac
11617b5038d7SDag-Erling Smørgrav
1162986ba33cSDag-Erling Smørgrav    case $_G_arg in
11637b5038d7SDag-Erling Smørgrav      # Double-quote args containing shell metacharacters to delay
11647b5038d7SDag-Erling Smørgrav      # word splitting and command substitution for a subsequent eval.
11657b5038d7SDag-Erling Smørgrav      # Many Bourne shells cannot handle close brackets correctly
11667b5038d7SDag-Erling Smørgrav      # in scan sets, so we specify it separately.
11677b5038d7SDag-Erling Smørgrav      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
1168986ba33cSDag-Erling Smørgrav        _G_arg=\"$_G_arg\"
11697b5038d7SDag-Erling Smørgrav        ;;
11707b5038d7SDag-Erling Smørgrav    esac
11717b5038d7SDag-Erling Smørgrav
1172986ba33cSDag-Erling Smørgrav    func_quote_for_expand_result=$_G_arg
11737b5038d7SDag-Erling Smørgrav}
11747b5038d7SDag-Erling Smørgrav
11757b5038d7SDag-Erling Smørgrav
1176986ba33cSDag-Erling Smørgrav# func_stripname PREFIX SUFFIX NAME
1177986ba33cSDag-Erling Smørgrav# ---------------------------------
1178986ba33cSDag-Erling Smørgrav# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.
1179986ba33cSDag-Erling Smørgrav# PREFIX and SUFFIX must not contain globbing or regex special
1180986ba33cSDag-Erling Smørgrav# characters, hashes, percent signs, but SUFFIX may contain a leading
1181986ba33cSDag-Erling Smørgrav# dot (in which case that matches only a dot).
1182986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_XSI_OPS"; then
1183986ba33cSDag-Erling Smørgrav  eval 'func_stripname ()
1184986ba33cSDag-Erling Smørgrav  {
1185986ba33cSDag-Erling Smørgrav    $debug_cmd
1186986ba33cSDag-Erling Smørgrav
1187986ba33cSDag-Erling Smørgrav    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are
1188986ba33cSDag-Erling Smørgrav    # positional parameters, so assign one to ordinary variable first.
1189986ba33cSDag-Erling Smørgrav    func_stripname_result=$3
1190986ba33cSDag-Erling Smørgrav    func_stripname_result=${func_stripname_result#"$1"}
1191986ba33cSDag-Erling Smørgrav    func_stripname_result=${func_stripname_result%"$2"}
1192986ba33cSDag-Erling Smørgrav  }'
1193986ba33cSDag-Erling Smørgravelse
1194986ba33cSDag-Erling Smørgrav  func_stripname ()
1195986ba33cSDag-Erling Smørgrav  {
1196986ba33cSDag-Erling Smørgrav    $debug_cmd
1197986ba33cSDag-Erling Smørgrav
1198986ba33cSDag-Erling Smørgrav    case $2 in
1199986ba33cSDag-Erling Smørgrav      .*) func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%\\\\$2\$%%"`;;
1200986ba33cSDag-Erling Smørgrav      *)  func_stripname_result=`$ECHO "$3" | $SED -e "s%^$1%%" -e "s%$2\$%%"`;;
1201986ba33cSDag-Erling Smørgrav    esac
1202986ba33cSDag-Erling Smørgrav  }
1203986ba33cSDag-Erling Smørgravfi
1204986ba33cSDag-Erling Smørgrav
1205986ba33cSDag-Erling Smørgrav
1206986ba33cSDag-Erling Smørgrav# func_show_eval CMD [FAIL_EXP]
1207986ba33cSDag-Erling Smørgrav# -----------------------------
1208986ba33cSDag-Erling Smørgrav# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
12097b5038d7SDag-Erling Smørgrav# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
12107b5038d7SDag-Erling Smørgrav# is given, then evaluate it.
12117b5038d7SDag-Erling Smørgravfunc_show_eval ()
12127b5038d7SDag-Erling Smørgrav{
1213986ba33cSDag-Erling Smørgrav    $debug_cmd
12147b5038d7SDag-Erling Smørgrav
1215986ba33cSDag-Erling Smørgrav    _G_cmd=$1
1216986ba33cSDag-Erling Smørgrav    _G_fail_exp=${2-':'}
1217986ba33cSDag-Erling Smørgrav
1218986ba33cSDag-Erling Smørgrav    func_quote_for_expand "$_G_cmd"
1219986ba33cSDag-Erling Smørgrav    eval "func_notquiet $func_quote_for_expand_result"
1220986ba33cSDag-Erling Smørgrav
1221986ba33cSDag-Erling Smørgrav    $opt_dry_run || {
1222986ba33cSDag-Erling Smørgrav      eval "$_G_cmd"
1223986ba33cSDag-Erling Smørgrav      _G_status=$?
1224986ba33cSDag-Erling Smørgrav      if test 0 -ne "$_G_status"; then
1225986ba33cSDag-Erling Smørgrav	eval "(exit $_G_status); $_G_fail_exp"
1226986ba33cSDag-Erling Smørgrav      fi
12277b5038d7SDag-Erling Smørgrav    }
12287b5038d7SDag-Erling Smørgrav}
12297b5038d7SDag-Erling Smørgrav
12307b5038d7SDag-Erling Smørgrav
1231986ba33cSDag-Erling Smørgrav# func_show_eval_locale CMD [FAIL_EXP]
1232986ba33cSDag-Erling Smørgrav# ------------------------------------
1233986ba33cSDag-Erling Smørgrav# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is
12347b5038d7SDag-Erling Smørgrav# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP
12357b5038d7SDag-Erling Smørgrav# is given, then evaluate it.  Use the saved locale for evaluation.
12367b5038d7SDag-Erling Smørgravfunc_show_eval_locale ()
12377b5038d7SDag-Erling Smørgrav{
1238986ba33cSDag-Erling Smørgrav    $debug_cmd
12397b5038d7SDag-Erling Smørgrav
1240986ba33cSDag-Erling Smørgrav    _G_cmd=$1
1241986ba33cSDag-Erling Smørgrav    _G_fail_exp=${2-':'}
1242986ba33cSDag-Erling Smørgrav
1243986ba33cSDag-Erling Smørgrav    $opt_quiet || {
1244986ba33cSDag-Erling Smørgrav      func_quote_for_expand "$_G_cmd"
12457b5038d7SDag-Erling Smørgrav      eval "func_echo $func_quote_for_expand_result"
12467b5038d7SDag-Erling Smørgrav    }
12477b5038d7SDag-Erling Smørgrav
1248986ba33cSDag-Erling Smørgrav    $opt_dry_run || {
1249986ba33cSDag-Erling Smørgrav      eval "$_G_user_locale
1250986ba33cSDag-Erling Smørgrav	    $_G_cmd"
1251986ba33cSDag-Erling Smørgrav      _G_status=$?
1252986ba33cSDag-Erling Smørgrav      eval "$_G_safe_locale"
1253986ba33cSDag-Erling Smørgrav      if test 0 -ne "$_G_status"; then
1254986ba33cSDag-Erling Smørgrav	eval "(exit $_G_status); $_G_fail_exp"
12557b5038d7SDag-Erling Smørgrav      fi
12567b5038d7SDag-Erling Smørgrav    }
1257986ba33cSDag-Erling Smørgrav}
1258986ba33cSDag-Erling Smørgrav
12597b5038d7SDag-Erling Smørgrav
12607b5038d7SDag-Erling Smørgrav# func_tr_sh
1261986ba33cSDag-Erling Smørgrav# ----------
12627b5038d7SDag-Erling Smørgrav# Turn $1 into a string suitable for a shell variable name.
12637b5038d7SDag-Erling Smørgrav# Result is stored in $func_tr_sh_result.  All characters
12647b5038d7SDag-Erling Smørgrav# not in the set a-zA-Z0-9_ are replaced with '_'. Further,
12657b5038d7SDag-Erling Smørgrav# if $1 begins with a digit, a '_' is prepended as well.
12667b5038d7SDag-Erling Smørgravfunc_tr_sh ()
12677b5038d7SDag-Erling Smørgrav{
1268986ba33cSDag-Erling Smørgrav    $debug_cmd
1269986ba33cSDag-Erling Smørgrav
12707b5038d7SDag-Erling Smørgrav    case $1 in
12717b5038d7SDag-Erling Smørgrav    [0-9]* | *[!a-zA-Z0-9_]*)
1272986ba33cSDag-Erling Smørgrav      func_tr_sh_result=`$ECHO "$1" | $SED -e 's/^\([0-9]\)/_\1/' -e 's/[^a-zA-Z0-9_]/_/g'`
12737b5038d7SDag-Erling Smørgrav      ;;
12747b5038d7SDag-Erling Smørgrav    * )
12757b5038d7SDag-Erling Smørgrav      func_tr_sh_result=$1
12767b5038d7SDag-Erling Smørgrav      ;;
12777b5038d7SDag-Erling Smørgrav    esac
12787b5038d7SDag-Erling Smørgrav}
12797b5038d7SDag-Erling Smørgrav
12807b5038d7SDag-Erling Smørgrav
1281986ba33cSDag-Erling Smørgrav# func_verbose ARG...
1282986ba33cSDag-Erling Smørgrav# -------------------
1283986ba33cSDag-Erling Smørgrav# Echo program name prefixed message in verbose mode only.
1284986ba33cSDag-Erling Smørgravfunc_verbose ()
12857b5038d7SDag-Erling Smørgrav{
1286986ba33cSDag-Erling Smørgrav    $debug_cmd
12877b5038d7SDag-Erling Smørgrav
1288986ba33cSDag-Erling Smørgrav    $opt_verbose && func_echo "$*"
1289986ba33cSDag-Erling Smørgrav
1290986ba33cSDag-Erling Smørgrav    :
12917b5038d7SDag-Erling Smørgrav}
12927b5038d7SDag-Erling Smørgrav
1293986ba33cSDag-Erling Smørgrav
1294986ba33cSDag-Erling Smørgrav# func_warn_and_continue ARG...
1295986ba33cSDag-Erling Smørgrav# -----------------------------
1296986ba33cSDag-Erling Smørgrav# Echo program name prefixed warning message to standard error.
1297986ba33cSDag-Erling Smørgravfunc_warn_and_continue ()
12987b5038d7SDag-Erling Smørgrav{
1299986ba33cSDag-Erling Smørgrav    $debug_cmd
13007b5038d7SDag-Erling Smørgrav
1301986ba33cSDag-Erling Smørgrav    $require_term_colors
1302986ba33cSDag-Erling Smørgrav
1303986ba33cSDag-Erling Smørgrav    func_echo_infix_1 "${tc_red}warning$tc_reset" "$*" >&2
13047b5038d7SDag-Erling Smørgrav}
13057b5038d7SDag-Erling Smørgrav
1306986ba33cSDag-Erling Smørgrav
1307986ba33cSDag-Erling Smørgrav# func_warning CATEGORY ARG...
1308986ba33cSDag-Erling Smørgrav# ----------------------------
1309986ba33cSDag-Erling Smørgrav# Echo program name prefixed warning message to standard error. Warning
1310986ba33cSDag-Erling Smørgrav# messages can be filtered according to CATEGORY, where this function
1311986ba33cSDag-Erling Smørgrav# elides messages where CATEGORY is not listed in the global variable
1312986ba33cSDag-Erling Smørgrav# 'opt_warning_types'.
1313986ba33cSDag-Erling Smørgravfunc_warning ()
1314986ba33cSDag-Erling Smørgrav{
1315986ba33cSDag-Erling Smørgrav    $debug_cmd
1316986ba33cSDag-Erling Smørgrav
1317986ba33cSDag-Erling Smørgrav    # CATEGORY must be in the warning_categories list!
1318986ba33cSDag-Erling Smørgrav    case " $warning_categories " in
1319986ba33cSDag-Erling Smørgrav      *" $1 "*) ;;
1320986ba33cSDag-Erling Smørgrav      *) func_internal_error "invalid warning category '$1'" ;;
1321986ba33cSDag-Erling Smørgrav    esac
1322986ba33cSDag-Erling Smørgrav
1323986ba33cSDag-Erling Smørgrav    _G_category=$1
1324986ba33cSDag-Erling Smørgrav    shift
1325986ba33cSDag-Erling Smørgrav
1326986ba33cSDag-Erling Smørgrav    case " $opt_warning_types " in
1327986ba33cSDag-Erling Smørgrav      *" $_G_category "*) $warning_func ${1+"$@"} ;;
1328986ba33cSDag-Erling Smørgrav    esac
1329986ba33cSDag-Erling Smørgrav}
1330986ba33cSDag-Erling Smørgrav
1331986ba33cSDag-Erling Smørgrav
1332986ba33cSDag-Erling Smørgrav# func_sort_ver VER1 VER2
1333986ba33cSDag-Erling Smørgrav# -----------------------
1334986ba33cSDag-Erling Smørgrav# 'sort -V' is not generally available.
1335986ba33cSDag-Erling Smørgrav# Note this deviates from the version comparison in automake
1336986ba33cSDag-Erling Smørgrav# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
1337986ba33cSDag-Erling Smørgrav# but this should suffice as we won't be specifying old
1338986ba33cSDag-Erling Smørgrav# version formats or redundant trailing .0 in bootstrap.conf.
1339986ba33cSDag-Erling Smørgrav# If we did want full compatibility then we should probably
1340986ba33cSDag-Erling Smørgrav# use m4_version_compare from autoconf.
1341986ba33cSDag-Erling Smørgravfunc_sort_ver ()
1342986ba33cSDag-Erling Smørgrav{
1343986ba33cSDag-Erling Smørgrav    $debug_cmd
1344986ba33cSDag-Erling Smørgrav
1345986ba33cSDag-Erling Smørgrav    printf '%s\n%s\n' "$1" "$2" \
1346986ba33cSDag-Erling Smørgrav      | 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
1347986ba33cSDag-Erling Smørgrav}
1348986ba33cSDag-Erling Smørgrav
1349986ba33cSDag-Erling Smørgrav# func_lt_ver PREV CURR
1350986ba33cSDag-Erling Smørgrav# ---------------------
1351986ba33cSDag-Erling Smørgrav# Return true if PREV and CURR are in the correct order according to
1352986ba33cSDag-Erling Smørgrav# func_sort_ver, otherwise false.  Use it like this:
1353986ba33cSDag-Erling Smørgrav#
1354986ba33cSDag-Erling Smørgrav#  func_lt_ver "$prev_ver" "$proposed_ver" || func_fatal_error "..."
1355986ba33cSDag-Erling Smørgravfunc_lt_ver ()
1356986ba33cSDag-Erling Smørgrav{
1357986ba33cSDag-Erling Smørgrav    $debug_cmd
1358986ba33cSDag-Erling Smørgrav
1359986ba33cSDag-Erling Smørgrav    test "x$1" = x`func_sort_ver "$1" "$2" | $SED 1q`
1360986ba33cSDag-Erling Smørgrav}
1361986ba33cSDag-Erling Smørgrav
1362986ba33cSDag-Erling Smørgrav
1363986ba33cSDag-Erling Smørgrav# Local variables:
1364986ba33cSDag-Erling Smørgrav# mode: shell-script
1365986ba33cSDag-Erling Smørgrav# sh-indentation: 2
1366986ba33cSDag-Erling Smørgrav# eval: (add-hook 'before-save-hook 'time-stamp)
1367986ba33cSDag-Erling Smørgrav# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
1368986ba33cSDag-Erling Smørgrav# time-stamp-time-zone: "UTC"
1369986ba33cSDag-Erling Smørgrav# End:
1370986ba33cSDag-Erling Smørgrav#! /bin/sh
1371986ba33cSDag-Erling Smørgrav
1372986ba33cSDag-Erling Smørgrav# Set a version string for this script.
1373*5afab0e5SDag-Erling Smørgravscriptversion=2015-10-07.11; # UTC
1374986ba33cSDag-Erling Smørgrav
1375986ba33cSDag-Erling Smørgrav# A portable, pluggable option parser for Bourne shell.
1376986ba33cSDag-Erling Smørgrav# Written by Gary V. Vaughan, 2010
1377986ba33cSDag-Erling Smørgrav
1378986ba33cSDag-Erling Smørgrav# Copyright (C) 2010-2015 Free Software Foundation, Inc.
1379986ba33cSDag-Erling Smørgrav# This is free software; see the source for copying conditions.  There is NO
1380986ba33cSDag-Erling Smørgrav# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1381986ba33cSDag-Erling Smørgrav
1382986ba33cSDag-Erling Smørgrav# This program is free software: you can redistribute it and/or modify
1383986ba33cSDag-Erling Smørgrav# it under the terms of the GNU General Public License as published by
1384986ba33cSDag-Erling Smørgrav# the Free Software Foundation, either version 3 of the License, or
1385986ba33cSDag-Erling Smørgrav# (at your option) any later version.
1386986ba33cSDag-Erling Smørgrav
1387986ba33cSDag-Erling Smørgrav# This program is distributed in the hope that it will be useful,
1388986ba33cSDag-Erling Smørgrav# but WITHOUT ANY WARRANTY; without even the implied warranty of
1389986ba33cSDag-Erling Smørgrav# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1390986ba33cSDag-Erling Smørgrav# GNU General Public License for more details.
1391986ba33cSDag-Erling Smørgrav
1392986ba33cSDag-Erling Smørgrav# You should have received a copy of the GNU General Public License
1393986ba33cSDag-Erling Smørgrav# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1394986ba33cSDag-Erling Smørgrav
1395986ba33cSDag-Erling Smørgrav# Please report bugs or propose patches to gary@gnu.org.
1396986ba33cSDag-Erling Smørgrav
1397986ba33cSDag-Erling Smørgrav
1398986ba33cSDag-Erling Smørgrav## ------ ##
1399986ba33cSDag-Erling Smørgrav## Usage. ##
1400986ba33cSDag-Erling Smørgrav## ------ ##
1401986ba33cSDag-Erling Smørgrav
1402986ba33cSDag-Erling Smørgrav# This file is a library for parsing options in your shell scripts along
1403986ba33cSDag-Erling Smørgrav# with assorted other useful supporting features that you can make use
1404986ba33cSDag-Erling Smørgrav# of too.
1405986ba33cSDag-Erling Smørgrav#
1406986ba33cSDag-Erling Smørgrav# For the simplest scripts you might need only:
1407986ba33cSDag-Erling Smørgrav#
1408986ba33cSDag-Erling Smørgrav#   #!/bin/sh
1409986ba33cSDag-Erling Smørgrav#   . relative/path/to/funclib.sh
1410986ba33cSDag-Erling Smørgrav#   . relative/path/to/options-parser
1411986ba33cSDag-Erling Smørgrav#   scriptversion=1.0
1412986ba33cSDag-Erling Smørgrav#   func_options ${1+"$@"}
1413986ba33cSDag-Erling Smørgrav#   eval set dummy "$func_options_result"; shift
1414986ba33cSDag-Erling Smørgrav#   ...rest of your script...
1415986ba33cSDag-Erling Smørgrav#
1416986ba33cSDag-Erling Smørgrav# In order for the '--version' option to work, you will need to have a
1417986ba33cSDag-Erling Smørgrav# suitably formatted comment like the one at the top of this file
1418986ba33cSDag-Erling Smørgrav# starting with '# Written by ' and ending with '# warranty; '.
1419986ba33cSDag-Erling Smørgrav#
1420986ba33cSDag-Erling Smørgrav# For '-h' and '--help' to work, you will also need a one line
1421986ba33cSDag-Erling Smørgrav# description of your script's purpose in a comment directly above the
1422986ba33cSDag-Erling Smørgrav# '# Written by ' line, like the one at the top of this file.
1423986ba33cSDag-Erling Smørgrav#
1424986ba33cSDag-Erling Smørgrav# The default options also support '--debug', which will turn on shell
1425986ba33cSDag-Erling Smørgrav# execution tracing (see the comment above debug_cmd below for another
1426986ba33cSDag-Erling Smørgrav# use), and '--verbose' and the func_verbose function to allow your script
1427986ba33cSDag-Erling Smørgrav# to display verbose messages only when your user has specified
1428986ba33cSDag-Erling Smørgrav# '--verbose'.
1429986ba33cSDag-Erling Smørgrav#
1430986ba33cSDag-Erling Smørgrav# After sourcing this file, you can plug processing for additional
1431986ba33cSDag-Erling Smørgrav# options by amending the variables from the 'Configuration' section
1432986ba33cSDag-Erling Smørgrav# below, and following the instructions in the 'Option parsing'
1433986ba33cSDag-Erling Smørgrav# section further down.
1434986ba33cSDag-Erling Smørgrav
1435986ba33cSDag-Erling Smørgrav## -------------- ##
1436986ba33cSDag-Erling Smørgrav## Configuration. ##
1437986ba33cSDag-Erling Smørgrav## -------------- ##
1438986ba33cSDag-Erling Smørgrav
1439986ba33cSDag-Erling Smørgrav# You should override these variables in your script after sourcing this
1440986ba33cSDag-Erling Smørgrav# file so that they reflect the customisations you have added to the
1441986ba33cSDag-Erling Smørgrav# option parser.
1442986ba33cSDag-Erling Smørgrav
1443986ba33cSDag-Erling Smørgrav# The usage line for option parsing errors and the start of '-h' and
1444986ba33cSDag-Erling Smørgrav# '--help' output messages. You can embed shell variables for delayed
1445986ba33cSDag-Erling Smørgrav# expansion at the time the message is displayed, but you will need to
1446986ba33cSDag-Erling Smørgrav# quote other shell meta-characters carefully to prevent them being
1447986ba33cSDag-Erling Smørgrav# expanded when the contents are evaled.
1448986ba33cSDag-Erling Smørgravusage='$progpath [OPTION]...'
1449986ba33cSDag-Erling Smørgrav
1450986ba33cSDag-Erling Smørgrav# Short help message in response to '-h' and '--help'.  Add to this or
1451986ba33cSDag-Erling Smørgrav# override it after sourcing this library to reflect the full set of
1452986ba33cSDag-Erling Smørgrav# options your script accepts.
1453986ba33cSDag-Erling Smørgravusage_message="\
1454986ba33cSDag-Erling Smørgrav       --debug        enable verbose shell tracing
1455986ba33cSDag-Erling Smørgrav   -W, --warnings=CATEGORY
1456986ba33cSDag-Erling Smørgrav                      report the warnings falling in CATEGORY [all]
1457986ba33cSDag-Erling Smørgrav   -v, --verbose      verbosely report processing
1458986ba33cSDag-Erling Smørgrav       --version      print version information and exit
1459986ba33cSDag-Erling Smørgrav   -h, --help         print short or long help message and exit
1460986ba33cSDag-Erling Smørgrav"
1461986ba33cSDag-Erling Smørgrav
1462986ba33cSDag-Erling Smørgrav# Additional text appended to 'usage_message' in response to '--help'.
1463986ba33cSDag-Erling Smørgravlong_help_message="
1464986ba33cSDag-Erling SmørgravWarning categories include:
1465986ba33cSDag-Erling Smørgrav       'all'          show all warnings
1466986ba33cSDag-Erling Smørgrav       'none'         turn off all the warnings
1467986ba33cSDag-Erling Smørgrav       'error'        warnings are treated as fatal errors"
1468986ba33cSDag-Erling Smørgrav
1469986ba33cSDag-Erling Smørgrav# Help message printed before fatal option parsing errors.
1470986ba33cSDag-Erling Smørgravfatal_help="Try '\$progname --help' for more information."
1471986ba33cSDag-Erling Smørgrav
1472986ba33cSDag-Erling Smørgrav
1473986ba33cSDag-Erling Smørgrav
1474986ba33cSDag-Erling Smørgrav## ------------------------- ##
1475986ba33cSDag-Erling Smørgrav## Hook function management. ##
1476986ba33cSDag-Erling Smørgrav## ------------------------- ##
1477986ba33cSDag-Erling Smørgrav
1478986ba33cSDag-Erling Smørgrav# This section contains functions for adding, removing, and running hooks
1479986ba33cSDag-Erling Smørgrav# to the main code.  A hook is just a named list of of function, that can
1480986ba33cSDag-Erling Smørgrav# be run in order later on.
1481986ba33cSDag-Erling Smørgrav
1482986ba33cSDag-Erling Smørgrav# func_hookable FUNC_NAME
1483986ba33cSDag-Erling Smørgrav# -----------------------
1484986ba33cSDag-Erling Smørgrav# Declare that FUNC_NAME will run hooks added with
1485986ba33cSDag-Erling Smørgrav# 'func_add_hook FUNC_NAME ...'.
1486986ba33cSDag-Erling Smørgravfunc_hookable ()
1487986ba33cSDag-Erling Smørgrav{
1488986ba33cSDag-Erling Smørgrav    $debug_cmd
1489986ba33cSDag-Erling Smørgrav
1490986ba33cSDag-Erling Smørgrav    func_append hookable_fns " $1"
1491986ba33cSDag-Erling Smørgrav}
1492986ba33cSDag-Erling Smørgrav
1493986ba33cSDag-Erling Smørgrav
1494986ba33cSDag-Erling Smørgrav# func_add_hook FUNC_NAME HOOK_FUNC
1495986ba33cSDag-Erling Smørgrav# ---------------------------------
1496986ba33cSDag-Erling Smørgrav# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must
1497986ba33cSDag-Erling Smørgrav# first have been declared "hookable" by a call to 'func_hookable'.
1498986ba33cSDag-Erling Smørgravfunc_add_hook ()
1499986ba33cSDag-Erling Smørgrav{
1500986ba33cSDag-Erling Smørgrav    $debug_cmd
1501986ba33cSDag-Erling Smørgrav
1502986ba33cSDag-Erling Smørgrav    case " $hookable_fns " in
1503986ba33cSDag-Erling Smørgrav      *" $1 "*) ;;
1504986ba33cSDag-Erling Smørgrav      *) func_fatal_error "'$1' does not accept hook functions." ;;
1505986ba33cSDag-Erling Smørgrav    esac
1506986ba33cSDag-Erling Smørgrav
1507986ba33cSDag-Erling Smørgrav    eval func_append ${1}_hooks '" $2"'
1508986ba33cSDag-Erling Smørgrav}
1509986ba33cSDag-Erling Smørgrav
1510986ba33cSDag-Erling Smørgrav
1511986ba33cSDag-Erling Smørgrav# func_remove_hook FUNC_NAME HOOK_FUNC
1512986ba33cSDag-Erling Smørgrav# ------------------------------------
1513986ba33cSDag-Erling Smørgrav# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.
1514986ba33cSDag-Erling Smørgravfunc_remove_hook ()
1515986ba33cSDag-Erling Smørgrav{
1516986ba33cSDag-Erling Smørgrav    $debug_cmd
1517986ba33cSDag-Erling Smørgrav
1518986ba33cSDag-Erling Smørgrav    eval ${1}_hooks='`$ECHO "\$'$1'_hooks" |$SED "s| '$2'||"`'
1519986ba33cSDag-Erling Smørgrav}
1520986ba33cSDag-Erling Smørgrav
1521986ba33cSDag-Erling Smørgrav
1522986ba33cSDag-Erling Smørgrav# func_run_hooks FUNC_NAME [ARG]...
1523986ba33cSDag-Erling Smørgrav# ---------------------------------
1524986ba33cSDag-Erling Smørgrav# Run all hook functions registered to FUNC_NAME.
1525986ba33cSDag-Erling Smørgrav# It is assumed that the list of hook functions contains nothing more
1526986ba33cSDag-Erling Smørgrav# than a whitespace-delimited list of legal shell function names, and
1527986ba33cSDag-Erling Smørgrav# no effort is wasted trying to catch shell meta-characters or preserve
1528986ba33cSDag-Erling Smørgrav# whitespace.
1529986ba33cSDag-Erling Smørgravfunc_run_hooks ()
1530986ba33cSDag-Erling Smørgrav{
1531986ba33cSDag-Erling Smørgrav    $debug_cmd
1532986ba33cSDag-Erling Smørgrav
1533*5afab0e5SDag-Erling Smørgrav    _G_rc_run_hooks=false
1534*5afab0e5SDag-Erling Smørgrav
1535986ba33cSDag-Erling Smørgrav    case " $hookable_fns " in
1536986ba33cSDag-Erling Smørgrav      *" $1 "*) ;;
1537986ba33cSDag-Erling Smørgrav      *) func_fatal_error "'$1' does not support hook funcions.n" ;;
1538986ba33cSDag-Erling Smørgrav    esac
1539986ba33cSDag-Erling Smørgrav
1540986ba33cSDag-Erling Smørgrav    eval _G_hook_fns=\$$1_hooks; shift
1541986ba33cSDag-Erling Smørgrav
1542986ba33cSDag-Erling Smørgrav    for _G_hook in $_G_hook_fns; do
1543*5afab0e5SDag-Erling Smørgrav      if eval $_G_hook '"$@"'; then
1544986ba33cSDag-Erling Smørgrav        # store returned options list back into positional
1545986ba33cSDag-Erling Smørgrav        # parameters for next 'cmd' execution.
1546986ba33cSDag-Erling Smørgrav        eval _G_hook_result=\$${_G_hook}_result
1547986ba33cSDag-Erling Smørgrav        eval set dummy "$_G_hook_result"; shift
1548*5afab0e5SDag-Erling Smørgrav        _G_rc_run_hooks=:
1549*5afab0e5SDag-Erling Smørgrav      fi
1550986ba33cSDag-Erling Smørgrav    done
1551986ba33cSDag-Erling Smørgrav
1552*5afab0e5SDag-Erling Smørgrav    $_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result
1553986ba33cSDag-Erling Smørgrav}
1554986ba33cSDag-Erling Smørgrav
1555986ba33cSDag-Erling Smørgrav
1556986ba33cSDag-Erling Smørgrav
1557986ba33cSDag-Erling Smørgrav## --------------- ##
1558986ba33cSDag-Erling Smørgrav## Option parsing. ##
1559986ba33cSDag-Erling Smørgrav## --------------- ##
1560986ba33cSDag-Erling Smørgrav
1561986ba33cSDag-Erling Smørgrav# In order to add your own option parsing hooks, you must accept the
1562*5afab0e5SDag-Erling Smørgrav# full positional parameter list in your hook function, you may remove/edit
1563*5afab0e5SDag-Erling Smørgrav# any options that you action, and then pass back the remaining unprocessed
1564986ba33cSDag-Erling Smørgrav# options in '<hooked_function_name>_result', escaped suitably for
1565*5afab0e5SDag-Erling Smørgrav# 'eval'.  In this case you also must return $EXIT_SUCCESS to let the
1566*5afab0e5SDag-Erling Smørgrav# hook's caller know that it should pay attention to
1567*5afab0e5SDag-Erling Smørgrav# '<hooked_function_name>_result'.  Returning $EXIT_FAILURE signalizes that
1568*5afab0e5SDag-Erling Smørgrav# arguments are left untouched by the hook and therefore caller will ignore the
1569*5afab0e5SDag-Erling Smørgrav# result variable.
1570*5afab0e5SDag-Erling Smørgrav#
1571*5afab0e5SDag-Erling Smørgrav# Like this:
1572986ba33cSDag-Erling Smørgrav#
1573986ba33cSDag-Erling Smørgrav#    my_options_prep ()
1574986ba33cSDag-Erling Smørgrav#    {
1575986ba33cSDag-Erling Smørgrav#        $debug_cmd
1576986ba33cSDag-Erling Smørgrav#
1577986ba33cSDag-Erling Smørgrav#        # Extend the existing usage message.
1578986ba33cSDag-Erling Smørgrav#        usage_message=$usage_message'
1579986ba33cSDag-Erling Smørgrav#      -s, --silent       don'\''t print informational messages
1580986ba33cSDag-Erling Smørgrav#    '
1581*5afab0e5SDag-Erling Smørgrav#        # No change in '$@' (ignored completely by this hook).  There is
1582*5afab0e5SDag-Erling Smørgrav#        # no need to do the equivalent (but slower) action:
1583*5afab0e5SDag-Erling Smørgrav#        # func_quote_for_eval ${1+"$@"}
1584*5afab0e5SDag-Erling Smørgrav#        # my_options_prep_result=$func_quote_for_eval_result
1585*5afab0e5SDag-Erling Smørgrav#        false
1586986ba33cSDag-Erling Smørgrav#    }
1587986ba33cSDag-Erling Smørgrav#    func_add_hook func_options_prep my_options_prep
1588986ba33cSDag-Erling Smørgrav#
1589986ba33cSDag-Erling Smørgrav#
1590986ba33cSDag-Erling Smørgrav#    my_silent_option ()
1591986ba33cSDag-Erling Smørgrav#    {
1592986ba33cSDag-Erling Smørgrav#        $debug_cmd
1593986ba33cSDag-Erling Smørgrav#
1594*5afab0e5SDag-Erling Smørgrav#        args_changed=false
1595*5afab0e5SDag-Erling Smørgrav#
1596986ba33cSDag-Erling Smørgrav#        # Note that for efficiency, we parse as many options as we can
1597986ba33cSDag-Erling Smørgrav#        # recognise in a loop before passing the remainder back to the
1598986ba33cSDag-Erling Smørgrav#        # caller on the first unrecognised argument we encounter.
1599986ba33cSDag-Erling Smørgrav#        while test $# -gt 0; do
1600986ba33cSDag-Erling Smørgrav#          opt=$1; shift
1601986ba33cSDag-Erling Smørgrav#          case $opt in
1602*5afab0e5SDag-Erling Smørgrav#            --silent|-s) opt_silent=:
1603*5afab0e5SDag-Erling Smørgrav#                         args_changed=:
1604*5afab0e5SDag-Erling Smørgrav#                         ;;
1605986ba33cSDag-Erling Smørgrav#            # Separate non-argument short options:
1606986ba33cSDag-Erling Smørgrav#            -s*)         func_split_short_opt "$_G_opt"
1607986ba33cSDag-Erling Smørgrav#                         set dummy "$func_split_short_opt_name" \
1608986ba33cSDag-Erling Smørgrav#                             "-$func_split_short_opt_arg" ${1+"$@"}
1609986ba33cSDag-Erling Smørgrav#                         shift
1610*5afab0e5SDag-Erling Smørgrav#                         args_changed=:
1611986ba33cSDag-Erling Smørgrav#                         ;;
1612*5afab0e5SDag-Erling Smørgrav#            *)           # Make sure the first unrecognised option "$_G_opt"
1613*5afab0e5SDag-Erling Smørgrav#                         # is added back to "$@", we could need that later
1614*5afab0e5SDag-Erling Smørgrav#                         # if $args_changed is true.
1615*5afab0e5SDag-Erling Smørgrav#                         set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
1616986ba33cSDag-Erling Smørgrav#          esac
1617986ba33cSDag-Erling Smørgrav#        done
1618986ba33cSDag-Erling Smørgrav#
1619*5afab0e5SDag-Erling Smørgrav#        if $args_changed; then
1620986ba33cSDag-Erling Smørgrav#          func_quote_for_eval ${1+"$@"}
1621986ba33cSDag-Erling Smørgrav#          my_silent_option_result=$func_quote_for_eval_result
1622*5afab0e5SDag-Erling Smørgrav#        fi
1623*5afab0e5SDag-Erling Smørgrav#
1624*5afab0e5SDag-Erling Smørgrav#        $args_changed
1625986ba33cSDag-Erling Smørgrav#    }
1626986ba33cSDag-Erling Smørgrav#    func_add_hook func_parse_options my_silent_option
1627986ba33cSDag-Erling Smørgrav#
1628986ba33cSDag-Erling Smørgrav#
1629986ba33cSDag-Erling Smørgrav#    my_option_validation ()
1630986ba33cSDag-Erling Smørgrav#    {
1631986ba33cSDag-Erling Smørgrav#        $debug_cmd
1632986ba33cSDag-Erling Smørgrav#
1633986ba33cSDag-Erling Smørgrav#        $opt_silent && $opt_verbose && func_fatal_help "\
1634986ba33cSDag-Erling Smørgrav#    '--silent' and '--verbose' options are mutually exclusive."
1635986ba33cSDag-Erling Smørgrav#
1636*5afab0e5SDag-Erling Smørgrav#        false
1637986ba33cSDag-Erling Smørgrav#    }
1638986ba33cSDag-Erling Smørgrav#    func_add_hook func_validate_options my_option_validation
1639986ba33cSDag-Erling Smørgrav#
1640*5afab0e5SDag-Erling Smørgrav# You'll also need to manually amend $usage_message to reflect the extra
1641986ba33cSDag-Erling Smørgrav# options you parse.  It's preferable to append if you can, so that
1642986ba33cSDag-Erling Smørgrav# multiple option parsing hooks can be added safely.
1643986ba33cSDag-Erling Smørgrav
1644986ba33cSDag-Erling Smørgrav
1645*5afab0e5SDag-Erling Smørgrav# func_options_finish [ARG]...
1646*5afab0e5SDag-Erling Smørgrav# ----------------------------
1647*5afab0e5SDag-Erling Smørgrav# Finishing the option parse loop (call 'func_options' hooks ATM).
1648*5afab0e5SDag-Erling Smørgravfunc_options_finish ()
1649*5afab0e5SDag-Erling Smørgrav{
1650*5afab0e5SDag-Erling Smørgrav    $debug_cmd
1651*5afab0e5SDag-Erling Smørgrav
1652*5afab0e5SDag-Erling Smørgrav    _G_func_options_finish_exit=false
1653*5afab0e5SDag-Erling Smørgrav    if func_run_hooks func_options ${1+"$@"}; then
1654*5afab0e5SDag-Erling Smørgrav      func_options_finish_result=$func_run_hooks_result
1655*5afab0e5SDag-Erling Smørgrav      _G_func_options_finish_exit=:
1656*5afab0e5SDag-Erling Smørgrav    fi
1657*5afab0e5SDag-Erling Smørgrav
1658*5afab0e5SDag-Erling Smørgrav    $_G_func_options_finish_exit
1659*5afab0e5SDag-Erling Smørgrav}
1660*5afab0e5SDag-Erling Smørgrav
1661*5afab0e5SDag-Erling Smørgrav
1662986ba33cSDag-Erling Smørgrav# func_options [ARG]...
1663986ba33cSDag-Erling Smørgrav# ---------------------
1664986ba33cSDag-Erling Smørgrav# All the functions called inside func_options are hookable. See the
1665986ba33cSDag-Erling Smørgrav# individual implementations for details.
1666986ba33cSDag-Erling Smørgravfunc_hookable func_options
1667986ba33cSDag-Erling Smørgravfunc_options ()
1668986ba33cSDag-Erling Smørgrav{
1669986ba33cSDag-Erling Smørgrav    $debug_cmd
1670986ba33cSDag-Erling Smørgrav
1671*5afab0e5SDag-Erling Smørgrav    _G_rc_options=false
1672986ba33cSDag-Erling Smørgrav
1673*5afab0e5SDag-Erling Smørgrav    for my_func in options_prep parse_options validate_options options_finish
1674*5afab0e5SDag-Erling Smørgrav    do
1675*5afab0e5SDag-Erling Smørgrav      if eval func_$my_func '${1+"$@"}'; then
1676*5afab0e5SDag-Erling Smørgrav        eval _G_res_var='$'"func_${my_func}_result"
1677*5afab0e5SDag-Erling Smørgrav        eval set dummy "$_G_res_var" ; shift
1678*5afab0e5SDag-Erling Smørgrav        _G_rc_options=:
1679*5afab0e5SDag-Erling Smørgrav      fi
1680*5afab0e5SDag-Erling Smørgrav    done
1681986ba33cSDag-Erling Smørgrav
1682*5afab0e5SDag-Erling Smørgrav    # Save modified positional parameters for caller.  As a top-level
1683*5afab0e5SDag-Erling Smørgrav    # options-parser function we always need to set the 'func_options_result'
1684*5afab0e5SDag-Erling Smørgrav    # variable (regardless the $_G_rc_options value).
1685*5afab0e5SDag-Erling Smørgrav    if $_G_rc_options; then
1686*5afab0e5SDag-Erling Smørgrav      func_options_result=$_G_res_var
1687*5afab0e5SDag-Erling Smørgrav    else
1688*5afab0e5SDag-Erling Smørgrav      func_quote_for_eval ${1+"$@"}
1689*5afab0e5SDag-Erling Smørgrav      func_options_result=$func_quote_for_eval_result
1690*5afab0e5SDag-Erling Smørgrav    fi
1691*5afab0e5SDag-Erling Smørgrav
1692*5afab0e5SDag-Erling Smørgrav    $_G_rc_options
1693986ba33cSDag-Erling Smørgrav}
1694986ba33cSDag-Erling Smørgrav
1695986ba33cSDag-Erling Smørgrav
1696986ba33cSDag-Erling Smørgrav# func_options_prep [ARG]...
1697986ba33cSDag-Erling Smørgrav# --------------------------
1698986ba33cSDag-Erling Smørgrav# All initialisations required before starting the option parse loop.
1699986ba33cSDag-Erling Smørgrav# Note that when calling hook functions, we pass through the list of
1700986ba33cSDag-Erling Smørgrav# positional parameters.  If a hook function modifies that list, and
1701*5afab0e5SDag-Erling Smørgrav# needs to propagate that back to rest of this script, then the complete
1702986ba33cSDag-Erling Smørgrav# modified list must be put in 'func_run_hooks_result' before
1703*5afab0e5SDag-Erling Smørgrav# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned).
1704986ba33cSDag-Erling Smørgravfunc_hookable func_options_prep
1705986ba33cSDag-Erling Smørgravfunc_options_prep ()
1706986ba33cSDag-Erling Smørgrav{
1707986ba33cSDag-Erling Smørgrav    $debug_cmd
1708986ba33cSDag-Erling Smørgrav
1709986ba33cSDag-Erling Smørgrav    # Option defaults:
1710986ba33cSDag-Erling Smørgrav    opt_verbose=false
1711986ba33cSDag-Erling Smørgrav    opt_warning_types=
1712986ba33cSDag-Erling Smørgrav
1713*5afab0e5SDag-Erling Smørgrav    _G_rc_options_prep=false
1714*5afab0e5SDag-Erling Smørgrav    if func_run_hooks func_options_prep ${1+"$@"}; then
1715*5afab0e5SDag-Erling Smørgrav      _G_rc_options_prep=:
1716986ba33cSDag-Erling Smørgrav      # save modified positional parameters for caller
1717986ba33cSDag-Erling Smørgrav      func_options_prep_result=$func_run_hooks_result
1718*5afab0e5SDag-Erling Smørgrav    fi
1719*5afab0e5SDag-Erling Smørgrav
1720*5afab0e5SDag-Erling Smørgrav    $_G_rc_options_prep
1721986ba33cSDag-Erling Smørgrav}
1722986ba33cSDag-Erling Smørgrav
1723986ba33cSDag-Erling Smørgrav
1724986ba33cSDag-Erling Smørgrav# func_parse_options [ARG]...
1725986ba33cSDag-Erling Smørgrav# ---------------------------
1726986ba33cSDag-Erling Smørgrav# The main option parsing loop.
1727986ba33cSDag-Erling Smørgravfunc_hookable func_parse_options
1728986ba33cSDag-Erling Smørgravfunc_parse_options ()
1729986ba33cSDag-Erling Smørgrav{
1730986ba33cSDag-Erling Smørgrav    $debug_cmd
1731986ba33cSDag-Erling Smørgrav
1732986ba33cSDag-Erling Smørgrav    func_parse_options_result=
1733986ba33cSDag-Erling Smørgrav
1734*5afab0e5SDag-Erling Smørgrav    _G_rc_parse_options=false
1735986ba33cSDag-Erling Smørgrav    # this just eases exit handling
1736986ba33cSDag-Erling Smørgrav    while test $# -gt 0; do
1737986ba33cSDag-Erling Smørgrav      # Defer to hook functions for initial option parsing, so they
1738986ba33cSDag-Erling Smørgrav      # get priority in the event of reusing an option name.
1739*5afab0e5SDag-Erling Smørgrav      if func_run_hooks func_parse_options ${1+"$@"}; then
1740986ba33cSDag-Erling Smørgrav        eval set dummy "$func_run_hooks_result"; shift
1741*5afab0e5SDag-Erling Smørgrav        _G_rc_parse_options=:
1742*5afab0e5SDag-Erling Smørgrav      fi
1743986ba33cSDag-Erling Smørgrav
1744986ba33cSDag-Erling Smørgrav      # Break out of the loop if we already parsed every option.
1745986ba33cSDag-Erling Smørgrav      test $# -gt 0 || break
1746986ba33cSDag-Erling Smørgrav
1747*5afab0e5SDag-Erling Smørgrav      _G_match_parse_options=:
1748986ba33cSDag-Erling Smørgrav      _G_opt=$1
1749986ba33cSDag-Erling Smørgrav      shift
1750986ba33cSDag-Erling Smørgrav      case $_G_opt in
1751986ba33cSDag-Erling Smørgrav        --debug|-x)   debug_cmd='set -x'
1752986ba33cSDag-Erling Smørgrav                      func_echo "enabling shell trace mode"
1753986ba33cSDag-Erling Smørgrav                      $debug_cmd
1754986ba33cSDag-Erling Smørgrav                      ;;
1755986ba33cSDag-Erling Smørgrav
1756986ba33cSDag-Erling Smørgrav        --no-warnings|--no-warning|--no-warn)
1757986ba33cSDag-Erling Smørgrav                      set dummy --warnings none ${1+"$@"}
1758986ba33cSDag-Erling Smørgrav                      shift
1759986ba33cSDag-Erling Smørgrav		      ;;
1760986ba33cSDag-Erling Smørgrav
1761986ba33cSDag-Erling Smørgrav        --warnings|--warning|-W)
1762*5afab0e5SDag-Erling Smørgrav                      if test $# = 0 && func_missing_arg $_G_opt; then
1763*5afab0e5SDag-Erling Smørgrav                        _G_rc_parse_options=:
1764*5afab0e5SDag-Erling Smørgrav                        break
1765*5afab0e5SDag-Erling Smørgrav                      fi
1766986ba33cSDag-Erling Smørgrav                      case " $warning_categories $1" in
1767986ba33cSDag-Erling Smørgrav                        *" $1 "*)
1768986ba33cSDag-Erling Smørgrav                          # trailing space prevents matching last $1 above
1769986ba33cSDag-Erling Smørgrav                          func_append_uniq opt_warning_types " $1"
1770986ba33cSDag-Erling Smørgrav                          ;;
1771986ba33cSDag-Erling Smørgrav                        *all)
1772986ba33cSDag-Erling Smørgrav                          opt_warning_types=$warning_categories
1773986ba33cSDag-Erling Smørgrav                          ;;
1774986ba33cSDag-Erling Smørgrav                        *none)
1775986ba33cSDag-Erling Smørgrav                          opt_warning_types=none
1776986ba33cSDag-Erling Smørgrav                          warning_func=:
1777986ba33cSDag-Erling Smørgrav                          ;;
1778986ba33cSDag-Erling Smørgrav                        *error)
1779986ba33cSDag-Erling Smørgrav                          opt_warning_types=$warning_categories
1780986ba33cSDag-Erling Smørgrav                          warning_func=func_fatal_error
1781986ba33cSDag-Erling Smørgrav                          ;;
1782986ba33cSDag-Erling Smørgrav                        *)
1783986ba33cSDag-Erling Smørgrav                          func_fatal_error \
1784986ba33cSDag-Erling Smørgrav                             "unsupported warning category: '$1'"
1785986ba33cSDag-Erling Smørgrav                          ;;
1786986ba33cSDag-Erling Smørgrav                      esac
1787986ba33cSDag-Erling Smørgrav                      shift
1788986ba33cSDag-Erling Smørgrav                      ;;
1789986ba33cSDag-Erling Smørgrav
1790986ba33cSDag-Erling Smørgrav        --verbose|-v) opt_verbose=: ;;
1791986ba33cSDag-Erling Smørgrav        --version)    func_version ;;
1792986ba33cSDag-Erling Smørgrav        -\?|-h)       func_usage ;;
1793986ba33cSDag-Erling Smørgrav        --help)       func_help ;;
1794986ba33cSDag-Erling Smørgrav
1795986ba33cSDag-Erling Smørgrav	# Separate optargs to long options (plugins may need this):
1796986ba33cSDag-Erling Smørgrav	--*=*)        func_split_equals "$_G_opt"
1797986ba33cSDag-Erling Smørgrav	              set dummy "$func_split_equals_lhs" \
1798986ba33cSDag-Erling Smørgrav                          "$func_split_equals_rhs" ${1+"$@"}
1799986ba33cSDag-Erling Smørgrav                      shift
1800986ba33cSDag-Erling Smørgrav                      ;;
1801986ba33cSDag-Erling Smørgrav
1802986ba33cSDag-Erling Smørgrav       # Separate optargs to short options:
1803986ba33cSDag-Erling Smørgrav        -W*)
1804986ba33cSDag-Erling Smørgrav                      func_split_short_opt "$_G_opt"
1805986ba33cSDag-Erling Smørgrav                      set dummy "$func_split_short_opt_name" \
1806986ba33cSDag-Erling Smørgrav                          "$func_split_short_opt_arg" ${1+"$@"}
1807986ba33cSDag-Erling Smørgrav                      shift
1808986ba33cSDag-Erling Smørgrav                      ;;
1809986ba33cSDag-Erling Smørgrav
1810986ba33cSDag-Erling Smørgrav        # Separate non-argument short options:
1811986ba33cSDag-Erling Smørgrav        -\?*|-h*|-v*|-x*)
1812986ba33cSDag-Erling Smørgrav                      func_split_short_opt "$_G_opt"
1813986ba33cSDag-Erling Smørgrav                      set dummy "$func_split_short_opt_name" \
1814986ba33cSDag-Erling Smørgrav                          "-$func_split_short_opt_arg" ${1+"$@"}
1815986ba33cSDag-Erling Smørgrav                      shift
1816986ba33cSDag-Erling Smørgrav                      ;;
1817986ba33cSDag-Erling Smørgrav
1818*5afab0e5SDag-Erling Smørgrav        --)           _G_rc_parse_options=: ; break ;;
1819986ba33cSDag-Erling Smørgrav        -*)           func_fatal_help "unrecognised option: '$_G_opt'" ;;
1820*5afab0e5SDag-Erling Smørgrav        *)            set dummy "$_G_opt" ${1+"$@"}; shift
1821*5afab0e5SDag-Erling Smørgrav                      _G_match_parse_options=false
1822*5afab0e5SDag-Erling Smørgrav                      break
1823*5afab0e5SDag-Erling Smørgrav                      ;;
1824986ba33cSDag-Erling Smørgrav      esac
1825*5afab0e5SDag-Erling Smørgrav
1826*5afab0e5SDag-Erling Smørgrav      $_G_match_parse_options && _G_rc_parse_options=:
1827986ba33cSDag-Erling Smørgrav    done
1828986ba33cSDag-Erling Smørgrav
1829*5afab0e5SDag-Erling Smørgrav
1830*5afab0e5SDag-Erling Smørgrav    if $_G_rc_parse_options; then
1831986ba33cSDag-Erling Smørgrav      # save modified positional parameters for caller
1832986ba33cSDag-Erling Smørgrav      func_quote_for_eval ${1+"$@"}
1833986ba33cSDag-Erling Smørgrav      func_parse_options_result=$func_quote_for_eval_result
1834*5afab0e5SDag-Erling Smørgrav    fi
1835*5afab0e5SDag-Erling Smørgrav
1836*5afab0e5SDag-Erling Smørgrav    $_G_rc_parse_options
1837986ba33cSDag-Erling Smørgrav}
1838986ba33cSDag-Erling Smørgrav
1839986ba33cSDag-Erling Smørgrav
1840986ba33cSDag-Erling Smørgrav# func_validate_options [ARG]...
1841986ba33cSDag-Erling Smørgrav# ------------------------------
1842986ba33cSDag-Erling Smørgrav# Perform any sanity checks on option settings and/or unconsumed
1843986ba33cSDag-Erling Smørgrav# arguments.
1844986ba33cSDag-Erling Smørgravfunc_hookable func_validate_options
1845986ba33cSDag-Erling Smørgravfunc_validate_options ()
1846986ba33cSDag-Erling Smørgrav{
1847986ba33cSDag-Erling Smørgrav    $debug_cmd
1848986ba33cSDag-Erling Smørgrav
1849*5afab0e5SDag-Erling Smørgrav    _G_rc_validate_options=false
1850*5afab0e5SDag-Erling Smørgrav
1851986ba33cSDag-Erling Smørgrav    # Display all warnings if -W was not given.
1852986ba33cSDag-Erling Smørgrav    test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
1853986ba33cSDag-Erling Smørgrav
1854*5afab0e5SDag-Erling Smørgrav    if func_run_hooks func_validate_options ${1+"$@"}; then
1855*5afab0e5SDag-Erling Smørgrav      # save modified positional parameters for caller
1856*5afab0e5SDag-Erling Smørgrav      func_validate_options_result=$func_run_hooks_result
1857*5afab0e5SDag-Erling Smørgrav      _G_rc_validate_options=:
1858*5afab0e5SDag-Erling Smørgrav    fi
1859986ba33cSDag-Erling Smørgrav
1860986ba33cSDag-Erling Smørgrav    # Bail if the options were screwed!
1861986ba33cSDag-Erling Smørgrav    $exit_cmd $EXIT_FAILURE
1862986ba33cSDag-Erling Smørgrav
1863*5afab0e5SDag-Erling Smørgrav    $_G_rc_validate_options
1864986ba33cSDag-Erling Smørgrav}
1865986ba33cSDag-Erling Smørgrav
1866986ba33cSDag-Erling Smørgrav
1867986ba33cSDag-Erling Smørgrav
1868986ba33cSDag-Erling Smørgrav## ----------------- ##
1869986ba33cSDag-Erling Smørgrav## Helper functions. ##
1870986ba33cSDag-Erling Smørgrav## ----------------- ##
1871986ba33cSDag-Erling Smørgrav
1872986ba33cSDag-Erling Smørgrav# This section contains the helper functions used by the rest of the
1873986ba33cSDag-Erling Smørgrav# hookable option parser framework in ascii-betical order.
1874986ba33cSDag-Erling Smørgrav
1875986ba33cSDag-Erling Smørgrav
1876986ba33cSDag-Erling Smørgrav# func_fatal_help ARG...
1877986ba33cSDag-Erling Smørgrav# ----------------------
1878986ba33cSDag-Erling Smørgrav# Echo program name prefixed message to standard error, followed by
1879986ba33cSDag-Erling Smørgrav# a help hint, and exit.
1880986ba33cSDag-Erling Smørgravfunc_fatal_help ()
1881986ba33cSDag-Erling Smørgrav{
1882986ba33cSDag-Erling Smørgrav    $debug_cmd
1883986ba33cSDag-Erling Smørgrav
1884986ba33cSDag-Erling Smørgrav    eval \$ECHO \""Usage: $usage"\"
1885986ba33cSDag-Erling Smørgrav    eval \$ECHO \""$fatal_help"\"
1886986ba33cSDag-Erling Smørgrav    func_error ${1+"$@"}
1887986ba33cSDag-Erling Smørgrav    exit $EXIT_FAILURE
1888986ba33cSDag-Erling Smørgrav}
1889986ba33cSDag-Erling Smørgrav
1890986ba33cSDag-Erling Smørgrav
1891986ba33cSDag-Erling Smørgrav# func_help
1892986ba33cSDag-Erling Smørgrav# ---------
1893986ba33cSDag-Erling Smørgrav# Echo long help message to standard output and exit.
18947b5038d7SDag-Erling Smørgravfunc_help ()
18957b5038d7SDag-Erling Smørgrav{
1896986ba33cSDag-Erling Smørgrav    $debug_cmd
18977b5038d7SDag-Erling Smørgrav
1898986ba33cSDag-Erling Smørgrav    func_usage_message
1899986ba33cSDag-Erling Smørgrav    $ECHO "$long_help_message"
1900986ba33cSDag-Erling Smørgrav    exit 0
19017b5038d7SDag-Erling Smørgrav}
19027b5038d7SDag-Erling Smørgrav
1903986ba33cSDag-Erling Smørgrav
1904986ba33cSDag-Erling Smørgrav# func_missing_arg ARGNAME
1905986ba33cSDag-Erling Smørgrav# ------------------------
19067b5038d7SDag-Erling Smørgrav# Echo program name prefixed message to standard error and set global
19077b5038d7SDag-Erling Smørgrav# exit_cmd.
19087b5038d7SDag-Erling Smørgravfunc_missing_arg ()
19097b5038d7SDag-Erling Smørgrav{
1910986ba33cSDag-Erling Smørgrav    $debug_cmd
19117b5038d7SDag-Erling Smørgrav
1912986ba33cSDag-Erling Smørgrav    func_error "Missing argument for '$1'."
19137b5038d7SDag-Erling Smørgrav    exit_cmd=exit
19147b5038d7SDag-Erling Smørgrav}
19157b5038d7SDag-Erling Smørgrav
19167b5038d7SDag-Erling Smørgrav
1917986ba33cSDag-Erling Smørgrav# func_split_equals STRING
1918986ba33cSDag-Erling Smørgrav# ------------------------
1919986ba33cSDag-Erling Smørgrav# Set func_split_equals_lhs and func_split_equals_rhs shell variables after
1920986ba33cSDag-Erling Smørgrav# splitting STRING at the '=' sign.
1921986ba33cSDag-Erling Smørgravtest -z "$_G_HAVE_XSI_OPS" \
1922986ba33cSDag-Erling Smørgrav    && (eval 'x=a/b/c;
1923986ba33cSDag-Erling Smørgrav      test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \
1924986ba33cSDag-Erling Smørgrav    && _G_HAVE_XSI_OPS=yes
1925986ba33cSDag-Erling Smørgrav
1926986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_XSI_OPS"
1927986ba33cSDag-Erling Smørgravthen
1928986ba33cSDag-Erling Smørgrav  # This is an XSI compatible shell, allowing a faster implementation...
1929986ba33cSDag-Erling Smørgrav  eval 'func_split_equals ()
1930986ba33cSDag-Erling Smørgrav  {
1931986ba33cSDag-Erling Smørgrav      $debug_cmd
1932986ba33cSDag-Erling Smørgrav
1933986ba33cSDag-Erling Smørgrav      func_split_equals_lhs=${1%%=*}
1934986ba33cSDag-Erling Smørgrav      func_split_equals_rhs=${1#*=}
1935986ba33cSDag-Erling Smørgrav      test "x$func_split_equals_lhs" = "x$1" \
1936986ba33cSDag-Erling Smørgrav        && func_split_equals_rhs=
1937986ba33cSDag-Erling Smørgrav  }'
1938986ba33cSDag-Erling Smørgravelse
1939986ba33cSDag-Erling Smørgrav  # ...otherwise fall back to using expr, which is often a shell builtin.
1940986ba33cSDag-Erling Smørgrav  func_split_equals ()
1941986ba33cSDag-Erling Smørgrav  {
1942986ba33cSDag-Erling Smørgrav      $debug_cmd
1943986ba33cSDag-Erling Smørgrav
1944986ba33cSDag-Erling Smørgrav      func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'`
1945986ba33cSDag-Erling Smørgrav      func_split_equals_rhs=
1946986ba33cSDag-Erling Smørgrav      test "x$func_split_equals_lhs" = "x$1" \
1947986ba33cSDag-Erling Smørgrav        || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'`
1948986ba33cSDag-Erling Smørgrav  }
1949986ba33cSDag-Erling Smørgravfi #func_split_equals
1950986ba33cSDag-Erling Smørgrav
1951986ba33cSDag-Erling Smørgrav
1952986ba33cSDag-Erling Smørgrav# func_split_short_opt SHORTOPT
1953986ba33cSDag-Erling Smørgrav# -----------------------------
19547b5038d7SDag-Erling Smørgrav# Set func_split_short_opt_name and func_split_short_opt_arg shell
19557b5038d7SDag-Erling Smørgrav# variables after splitting SHORTOPT after the 2nd character.
1956986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_XSI_OPS"
1957986ba33cSDag-Erling Smørgravthen
1958986ba33cSDag-Erling Smørgrav  # This is an XSI compatible shell, allowing a faster implementation...
1959986ba33cSDag-Erling Smørgrav  eval 'func_split_short_opt ()
1960986ba33cSDag-Erling Smørgrav  {
1961986ba33cSDag-Erling Smørgrav      $debug_cmd
1962986ba33cSDag-Erling Smørgrav
1963986ba33cSDag-Erling Smørgrav      func_split_short_opt_arg=${1#??}
1964986ba33cSDag-Erling Smørgrav      func_split_short_opt_name=${1%"$func_split_short_opt_arg"}
1965986ba33cSDag-Erling Smørgrav  }'
1966986ba33cSDag-Erling Smørgravelse
1967986ba33cSDag-Erling Smørgrav  # ...otherwise fall back to using expr, which is often a shell builtin.
19687b5038d7SDag-Erling Smørgrav  func_split_short_opt ()
19697b5038d7SDag-Erling Smørgrav  {
1970986ba33cSDag-Erling Smørgrav      $debug_cmd
19717b5038d7SDag-Erling Smørgrav
1972986ba33cSDag-Erling Smørgrav      func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'`
1973986ba33cSDag-Erling Smørgrav      func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'`
1974986ba33cSDag-Erling Smørgrav  }
1975986ba33cSDag-Erling Smørgravfi #func_split_short_opt
19767b5038d7SDag-Erling Smørgrav
19777b5038d7SDag-Erling Smørgrav
1978986ba33cSDag-Erling Smørgrav# func_usage
1979986ba33cSDag-Erling Smørgrav# ----------
1980986ba33cSDag-Erling Smørgrav# Echo short help message to standard output and exit.
1981986ba33cSDag-Erling Smørgravfunc_usage ()
19827b5038d7SDag-Erling Smørgrav{
1983986ba33cSDag-Erling Smørgrav    $debug_cmd
19847b5038d7SDag-Erling Smørgrav
1985986ba33cSDag-Erling Smørgrav    func_usage_message
1986986ba33cSDag-Erling Smørgrav    $ECHO "Run '$progname --help |${PAGER-more}' for full usage"
1987986ba33cSDag-Erling Smørgrav    exit 0
1988986ba33cSDag-Erling Smørgrav}
19897b5038d7SDag-Erling Smørgrav
19907b5038d7SDag-Erling Smørgrav
1991986ba33cSDag-Erling Smørgrav# func_usage_message
1992986ba33cSDag-Erling Smørgrav# ------------------
1993986ba33cSDag-Erling Smørgrav# Echo short help message to standard output.
1994986ba33cSDag-Erling Smørgravfunc_usage_message ()
19957b5038d7SDag-Erling Smørgrav{
1996986ba33cSDag-Erling Smørgrav    $debug_cmd
19977b5038d7SDag-Erling Smørgrav
1998986ba33cSDag-Erling Smørgrav    eval \$ECHO \""Usage: $usage"\"
1999986ba33cSDag-Erling Smørgrav    echo
2000986ba33cSDag-Erling Smørgrav    $SED -n 's|^# ||
2001986ba33cSDag-Erling Smørgrav        /^Written by/{
2002986ba33cSDag-Erling Smørgrav          x;p;x
2003986ba33cSDag-Erling Smørgrav        }
2004986ba33cSDag-Erling Smørgrav	h
2005986ba33cSDag-Erling Smørgrav	/^Written by/q' < "$progpath"
2006986ba33cSDag-Erling Smørgrav    echo
2007986ba33cSDag-Erling Smørgrav    eval \$ECHO \""$usage_message"\"
2008986ba33cSDag-Erling Smørgrav}
2009986ba33cSDag-Erling Smørgrav
2010986ba33cSDag-Erling Smørgrav
2011986ba33cSDag-Erling Smørgrav# func_version
2012986ba33cSDag-Erling Smørgrav# ------------
2013986ba33cSDag-Erling Smørgrav# Echo version message to standard output and exit.
2014986ba33cSDag-Erling Smørgravfunc_version ()
20157b5038d7SDag-Erling Smørgrav{
2016986ba33cSDag-Erling Smørgrav    $debug_cmd
2017986ba33cSDag-Erling Smørgrav
2018986ba33cSDag-Erling Smørgrav    printf '%s\n' "$progname $scriptversion"
2019986ba33cSDag-Erling Smørgrav    $SED -n '
2020986ba33cSDag-Erling Smørgrav        /(C)/!b go
2021986ba33cSDag-Erling Smørgrav        :more
2022986ba33cSDag-Erling Smørgrav        /\./!{
2023986ba33cSDag-Erling Smørgrav          N
2024986ba33cSDag-Erling Smørgrav          s|\n# | |
2025986ba33cSDag-Erling Smørgrav          b more
2026986ba33cSDag-Erling Smørgrav        }
2027986ba33cSDag-Erling Smørgrav        :go
2028986ba33cSDag-Erling Smørgrav        /^# Written by /,/# warranty; / {
2029986ba33cSDag-Erling Smørgrav          s|^# ||
2030986ba33cSDag-Erling Smørgrav          s|^# *$||
2031986ba33cSDag-Erling Smørgrav          s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2|
2032986ba33cSDag-Erling Smørgrav          p
2033986ba33cSDag-Erling Smørgrav        }
2034986ba33cSDag-Erling Smørgrav        /^# Written by / {
2035986ba33cSDag-Erling Smørgrav          s|^# ||
2036986ba33cSDag-Erling Smørgrav          p
2037986ba33cSDag-Erling Smørgrav        }
2038986ba33cSDag-Erling Smørgrav        /^warranty; /q' < "$progpath"
2039986ba33cSDag-Erling Smørgrav
2040986ba33cSDag-Erling Smørgrav    exit $?
2041986ba33cSDag-Erling Smørgrav}
20427b5038d7SDag-Erling Smørgrav
20437b5038d7SDag-Erling Smørgrav
2044986ba33cSDag-Erling Smørgrav# Local variables:
2045986ba33cSDag-Erling Smørgrav# mode: shell-script
2046986ba33cSDag-Erling Smørgrav# sh-indentation: 2
2047986ba33cSDag-Erling Smørgrav# eval: (add-hook 'before-save-hook 'time-stamp)
2048986ba33cSDag-Erling Smørgrav# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC"
2049986ba33cSDag-Erling Smørgrav# time-stamp-time-zone: "UTC"
2050986ba33cSDag-Erling Smørgrav# End:
2051986ba33cSDag-Erling Smørgrav
2052986ba33cSDag-Erling Smørgrav# Set a version string.
2053*5afab0e5SDag-Erling Smørgravscriptversion='(GNU libtool) 2.4.6'
2054986ba33cSDag-Erling Smørgrav
2055986ba33cSDag-Erling Smørgrav
2056986ba33cSDag-Erling Smørgrav# func_echo ARG...
2057986ba33cSDag-Erling Smørgrav# ----------------
2058986ba33cSDag-Erling Smørgrav# Libtool also displays the current mode in messages, so override
2059986ba33cSDag-Erling Smørgrav# funclib.sh func_echo with this custom definition.
2060986ba33cSDag-Erling Smørgravfunc_echo ()
20617b5038d7SDag-Erling Smørgrav{
2062986ba33cSDag-Erling Smørgrav    $debug_cmd
2063986ba33cSDag-Erling Smørgrav
2064986ba33cSDag-Erling Smørgrav    _G_message=$*
2065986ba33cSDag-Erling Smørgrav
2066986ba33cSDag-Erling Smørgrav    func_echo_IFS=$IFS
2067986ba33cSDag-Erling Smørgrav    IFS=$nl
2068986ba33cSDag-Erling Smørgrav    for _G_line in $_G_message; do
2069986ba33cSDag-Erling Smørgrav      IFS=$func_echo_IFS
2070986ba33cSDag-Erling Smørgrav      $ECHO "$progname${opt_mode+: $opt_mode}: $_G_line"
2071986ba33cSDag-Erling Smørgrav    done
2072986ba33cSDag-Erling Smørgrav    IFS=$func_echo_IFS
2073986ba33cSDag-Erling Smørgrav}
20747b5038d7SDag-Erling Smørgrav
20757b5038d7SDag-Erling Smørgrav
2076986ba33cSDag-Erling Smørgrav# func_warning ARG...
2077986ba33cSDag-Erling Smørgrav# -------------------
2078986ba33cSDag-Erling Smørgrav# Libtool warnings are not categorized, so override funclib.sh
2079986ba33cSDag-Erling Smørgrav# func_warning with this simpler definition.
2080986ba33cSDag-Erling Smørgravfunc_warning ()
20817b5038d7SDag-Erling Smørgrav{
2082986ba33cSDag-Erling Smørgrav    $debug_cmd
2083986ba33cSDag-Erling Smørgrav
2084986ba33cSDag-Erling Smørgrav    $warning_func ${1+"$@"}
2085986ba33cSDag-Erling Smørgrav}
20867b5038d7SDag-Erling Smørgrav
20877b5038d7SDag-Erling Smørgrav
2088986ba33cSDag-Erling Smørgrav## ---------------- ##
2089986ba33cSDag-Erling Smørgrav## Options parsing. ##
2090986ba33cSDag-Erling Smørgrav## ---------------- ##
2091986ba33cSDag-Erling Smørgrav
2092986ba33cSDag-Erling Smørgrav# Hook in the functions to make sure our own options are parsed during
2093986ba33cSDag-Erling Smørgrav# the option parsing loop.
2094986ba33cSDag-Erling Smørgrav
2095986ba33cSDag-Erling Smørgravusage='$progpath [OPTION]... [MODE-ARG]...'
2096986ba33cSDag-Erling Smørgrav
2097986ba33cSDag-Erling Smørgrav# Short help message in response to '-h'.
2098986ba33cSDag-Erling Smørgravusage_message="Options:
2099986ba33cSDag-Erling Smørgrav       --config             show all configuration variables
2100986ba33cSDag-Erling Smørgrav       --debug              enable verbose shell tracing
2101986ba33cSDag-Erling Smørgrav   -n, --dry-run            display commands without modifying any files
2102986ba33cSDag-Erling Smørgrav       --features           display basic configuration information and exit
2103986ba33cSDag-Erling Smørgrav       --mode=MODE          use operation mode MODE
2104986ba33cSDag-Erling Smørgrav       --no-warnings        equivalent to '-Wnone'
2105986ba33cSDag-Erling Smørgrav       --preserve-dup-deps  don't remove duplicate dependency libraries
2106986ba33cSDag-Erling Smørgrav       --quiet, --silent    don't print informational messages
2107986ba33cSDag-Erling Smørgrav       --tag=TAG            use configuration variables from tag TAG
2108986ba33cSDag-Erling Smørgrav   -v, --verbose            print more informational messages than default
2109986ba33cSDag-Erling Smørgrav       --version            print version information
2110986ba33cSDag-Erling Smørgrav   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]
2111986ba33cSDag-Erling Smørgrav   -h, --help, --help-all   print short, long, or detailed help message
2112986ba33cSDag-Erling Smørgrav"
2113986ba33cSDag-Erling Smørgrav
2114986ba33cSDag-Erling Smørgrav# Additional text appended to 'usage_message' in response to '--help'.
2115986ba33cSDag-Erling Smørgravfunc_help ()
2116986ba33cSDag-Erling Smørgrav{
2117986ba33cSDag-Erling Smørgrav    $debug_cmd
2118986ba33cSDag-Erling Smørgrav
2119986ba33cSDag-Erling Smørgrav    func_usage_message
2120986ba33cSDag-Erling Smørgrav    $ECHO "$long_help_message
2121986ba33cSDag-Erling Smørgrav
2122986ba33cSDag-Erling SmørgravMODE must be one of the following:
2123986ba33cSDag-Erling Smørgrav
2124986ba33cSDag-Erling Smørgrav       clean           remove files from the build directory
2125986ba33cSDag-Erling Smørgrav       compile         compile a source file into a libtool object
2126986ba33cSDag-Erling Smørgrav       execute         automatically set library path, then run a program
2127986ba33cSDag-Erling Smørgrav       finish          complete the installation of libtool libraries
2128986ba33cSDag-Erling Smørgrav       install         install libraries or executables
2129986ba33cSDag-Erling Smørgrav       link            create a library or an executable
2130986ba33cSDag-Erling Smørgrav       uninstall       remove libraries from an installed directory
2131986ba33cSDag-Erling Smørgrav
2132986ba33cSDag-Erling SmørgravMODE-ARGS vary depending on the MODE.  When passed as first option,
2133986ba33cSDag-Erling Smørgrav'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.
2134986ba33cSDag-Erling SmørgravTry '$progname --help --mode=MODE' for a more detailed description of MODE.
2135986ba33cSDag-Erling Smørgrav
2136986ba33cSDag-Erling SmørgravWhen reporting a bug, please describe a test case to reproduce it and
2137986ba33cSDag-Erling Smørgravinclude the following information:
2138986ba33cSDag-Erling Smørgrav
2139986ba33cSDag-Erling Smørgrav       host-triplet:   $host
2140986ba33cSDag-Erling Smørgrav       shell:          $SHELL
2141986ba33cSDag-Erling Smørgrav       compiler:       $LTCC
2142986ba33cSDag-Erling Smørgrav       compiler flags: $LTCFLAGS
2143986ba33cSDag-Erling Smørgrav       linker:         $LD (gnu? $with_gnu_ld)
2144*5afab0e5SDag-Erling Smørgrav       version:        $progname $scriptversion Debian-2.4.6-15build2
2145986ba33cSDag-Erling Smørgrav       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`
2146986ba33cSDag-Erling Smørgrav       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`
2147986ba33cSDag-Erling Smørgrav
2148986ba33cSDag-Erling SmørgravReport bugs to <bug-libtool@gnu.org>.
2149986ba33cSDag-Erling SmørgravGNU libtool home page: <http://www.gnu.org/s/libtool/>.
2150986ba33cSDag-Erling SmørgravGeneral help using GNU software: <http://www.gnu.org/gethelp/>."
2151986ba33cSDag-Erling Smørgrav    exit 0
2152986ba33cSDag-Erling Smørgrav}
2153986ba33cSDag-Erling Smørgrav
2154986ba33cSDag-Erling Smørgrav
2155986ba33cSDag-Erling Smørgrav# func_lo2o OBJECT-NAME
2156986ba33cSDag-Erling Smørgrav# ---------------------
2157986ba33cSDag-Erling Smørgrav# Transform OBJECT-NAME from a '.lo' suffix to the platform specific
2158986ba33cSDag-Erling Smørgrav# object suffix.
2159986ba33cSDag-Erling Smørgrav
2160986ba33cSDag-Erling Smørgravlo2o=s/\\.lo\$/.$objext/
2161986ba33cSDag-Erling Smørgravo2lo=s/\\.$objext\$/.lo/
2162986ba33cSDag-Erling Smørgrav
2163986ba33cSDag-Erling Smørgravif test yes = "$_G_HAVE_XSI_OPS"; then
2164986ba33cSDag-Erling Smørgrav  eval 'func_lo2o ()
2165986ba33cSDag-Erling Smørgrav  {
2166986ba33cSDag-Erling Smørgrav    case $1 in
2167986ba33cSDag-Erling Smørgrav      *.lo) func_lo2o_result=${1%.lo}.$objext ;;
2168986ba33cSDag-Erling Smørgrav      *   ) func_lo2o_result=$1               ;;
2169986ba33cSDag-Erling Smørgrav    esac
2170986ba33cSDag-Erling Smørgrav  }'
2171986ba33cSDag-Erling Smørgrav
2172986ba33cSDag-Erling Smørgrav  # func_xform LIBOBJ-OR-SOURCE
2173986ba33cSDag-Erling Smørgrav  # ---------------------------
2174986ba33cSDag-Erling Smørgrav  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)
2175986ba33cSDag-Erling Smørgrav  # suffix to a '.lo' libtool-object suffix.
2176986ba33cSDag-Erling Smørgrav  eval 'func_xform ()
2177986ba33cSDag-Erling Smørgrav  {
2178986ba33cSDag-Erling Smørgrav    func_xform_result=${1%.*}.lo
2179986ba33cSDag-Erling Smørgrav  }'
2180986ba33cSDag-Erling Smørgravelse
2181986ba33cSDag-Erling Smørgrav  # ...otherwise fall back to using sed.
21827b5038d7SDag-Erling Smørgrav  func_lo2o ()
21837b5038d7SDag-Erling Smørgrav  {
2184986ba33cSDag-Erling Smørgrav    func_lo2o_result=`$ECHO "$1" | $SED "$lo2o"`
2185986ba33cSDag-Erling Smørgrav  }
21867b5038d7SDag-Erling Smørgrav
21877b5038d7SDag-Erling Smørgrav  func_xform ()
21887b5038d7SDag-Erling Smørgrav  {
2189986ba33cSDag-Erling Smørgrav    func_xform_result=`$ECHO "$1" | $SED 's|\.[^.]*$|.lo|'`
2190986ba33cSDag-Erling Smørgrav  }
2191986ba33cSDag-Erling Smørgravfi
21927b5038d7SDag-Erling Smørgrav
21937b5038d7SDag-Erling Smørgrav
2194986ba33cSDag-Erling Smørgrav# func_fatal_configuration ARG...
2195986ba33cSDag-Erling Smørgrav# -------------------------------
21967b5038d7SDag-Erling Smørgrav# Echo program name prefixed message to standard error, followed by
21977b5038d7SDag-Erling Smørgrav# a configuration failure hint, and exit.
21987b5038d7SDag-Erling Smørgravfunc_fatal_configuration ()
21997b5038d7SDag-Erling Smørgrav{
2200986ba33cSDag-Erling Smørgrav    func__fatal_error ${1+"$@"} \
2201986ba33cSDag-Erling Smørgrav      "See the $PACKAGE documentation for more information." \
2202986ba33cSDag-Erling Smørgrav      "Fatal configuration error."
22037b5038d7SDag-Erling Smørgrav}
22047b5038d7SDag-Erling Smørgrav
22057b5038d7SDag-Erling Smørgrav
22067b5038d7SDag-Erling Smørgrav# func_config
2207986ba33cSDag-Erling Smørgrav# -----------
22087b5038d7SDag-Erling Smørgrav# Display the configuration for all the tags in this script.
22097b5038d7SDag-Erling Smørgravfunc_config ()
22107b5038d7SDag-Erling Smørgrav{
22117b5038d7SDag-Erling Smørgrav    re_begincf='^# ### BEGIN LIBTOOL'
22127b5038d7SDag-Erling Smørgrav    re_endcf='^# ### END LIBTOOL'
22137b5038d7SDag-Erling Smørgrav
22147b5038d7SDag-Erling Smørgrav    # Default configuration.
22157b5038d7SDag-Erling Smørgrav    $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath"
22167b5038d7SDag-Erling Smørgrav
22177b5038d7SDag-Erling Smørgrav    # Now print the configurations for the tags.
22187b5038d7SDag-Erling Smørgrav    for tagname in $taglist; do
22197b5038d7SDag-Erling Smørgrav      $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath"
22207b5038d7SDag-Erling Smørgrav    done
22217b5038d7SDag-Erling Smørgrav
22227b5038d7SDag-Erling Smørgrav    exit $?
22237b5038d7SDag-Erling Smørgrav}
22247b5038d7SDag-Erling Smørgrav
2225986ba33cSDag-Erling Smørgrav
22267b5038d7SDag-Erling Smørgrav# func_features
2227986ba33cSDag-Erling Smørgrav# -------------
22287b5038d7SDag-Erling Smørgrav# Display the features supported by this script.
22297b5038d7SDag-Erling Smørgravfunc_features ()
22307b5038d7SDag-Erling Smørgrav{
22317b5038d7SDag-Erling Smørgrav    echo "host: $host"
2232986ba33cSDag-Erling Smørgrav    if test yes = "$build_libtool_libs"; then
22337b5038d7SDag-Erling Smørgrav      echo "enable shared libraries"
22347b5038d7SDag-Erling Smørgrav    else
22357b5038d7SDag-Erling Smørgrav      echo "disable shared libraries"
22367b5038d7SDag-Erling Smørgrav    fi
2237986ba33cSDag-Erling Smørgrav    if test yes = "$build_old_libs"; then
22387b5038d7SDag-Erling Smørgrav      echo "enable static libraries"
22397b5038d7SDag-Erling Smørgrav    else
22407b5038d7SDag-Erling Smørgrav      echo "disable static libraries"
22417b5038d7SDag-Erling Smørgrav    fi
22427b5038d7SDag-Erling Smørgrav
22437b5038d7SDag-Erling Smørgrav    exit $?
22447b5038d7SDag-Erling Smørgrav}
22457b5038d7SDag-Erling Smørgrav
2246986ba33cSDag-Erling Smørgrav
2247986ba33cSDag-Erling Smørgrav# func_enable_tag TAGNAME
2248986ba33cSDag-Erling Smørgrav# -----------------------
22497b5038d7SDag-Erling Smørgrav# Verify that TAGNAME is valid, and either flag an error and exit, or
22507b5038d7SDag-Erling Smørgrav# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist
22517b5038d7SDag-Erling Smørgrav# variable here.
22527b5038d7SDag-Erling Smørgravfunc_enable_tag ()
22537b5038d7SDag-Erling Smørgrav{
22547b5038d7SDag-Erling Smørgrav    # Global variable:
2255986ba33cSDag-Erling Smørgrav    tagname=$1
22567b5038d7SDag-Erling Smørgrav
22577b5038d7SDag-Erling Smørgrav    re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$"
22587b5038d7SDag-Erling Smørgrav    re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$"
2259986ba33cSDag-Erling Smørgrav    sed_extractcf=/$re_begincf/,/$re_endcf/p
22607b5038d7SDag-Erling Smørgrav
22617b5038d7SDag-Erling Smørgrav    # Validate tagname.
22627b5038d7SDag-Erling Smørgrav    case $tagname in
22637b5038d7SDag-Erling Smørgrav      *[!-_A-Za-z0-9,/]*)
22647b5038d7SDag-Erling Smørgrav        func_fatal_error "invalid tag name: $tagname"
22657b5038d7SDag-Erling Smørgrav        ;;
22667b5038d7SDag-Erling Smørgrav    esac
22677b5038d7SDag-Erling Smørgrav
22687b5038d7SDag-Erling Smørgrav    # Don't test for the "default" C tag, as we know it's
22697b5038d7SDag-Erling Smørgrav    # there but not specially marked.
22707b5038d7SDag-Erling Smørgrav    case $tagname in
22717b5038d7SDag-Erling Smørgrav        CC) ;;
22727b5038d7SDag-Erling Smørgrav    *)
22737b5038d7SDag-Erling Smørgrav        if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then
22747b5038d7SDag-Erling Smørgrav	  taglist="$taglist $tagname"
22757b5038d7SDag-Erling Smørgrav
22767b5038d7SDag-Erling Smørgrav	  # Evaluate the configuration.  Be careful to quote the path
22777b5038d7SDag-Erling Smørgrav	  # and the sed script, to avoid splitting on whitespace, but
22787b5038d7SDag-Erling Smørgrav	  # also don't use non-portable quotes within backquotes within
22797b5038d7SDag-Erling Smørgrav	  # quotes we have to do it in 2 steps:
22807b5038d7SDag-Erling Smørgrav	  extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"`
22817b5038d7SDag-Erling Smørgrav	  eval "$extractedcf"
22827b5038d7SDag-Erling Smørgrav        else
22837b5038d7SDag-Erling Smørgrav	  func_error "ignoring unknown tag $tagname"
22847b5038d7SDag-Erling Smørgrav        fi
22857b5038d7SDag-Erling Smørgrav        ;;
22867b5038d7SDag-Erling Smørgrav    esac
22877b5038d7SDag-Erling Smørgrav}
22887b5038d7SDag-Erling Smørgrav
2289986ba33cSDag-Erling Smørgrav
22907b5038d7SDag-Erling Smørgrav# func_check_version_match
2291986ba33cSDag-Erling Smørgrav# ------------------------
22927b5038d7SDag-Erling Smørgrav# Ensure that we are using m4 macros, and libtool script from the same
22937b5038d7SDag-Erling Smørgrav# release of libtool.
22947b5038d7SDag-Erling Smørgravfunc_check_version_match ()
22957b5038d7SDag-Erling Smørgrav{
22967b5038d7SDag-Erling Smørgrav    if test "$package_revision" != "$macro_revision"; then
22977b5038d7SDag-Erling Smørgrav      if test "$VERSION" != "$macro_version"; then
22987b5038d7SDag-Erling Smørgrav        if test -z "$macro_version"; then
22997b5038d7SDag-Erling Smørgrav          cat >&2 <<_LT_EOF
23007b5038d7SDag-Erling Smørgrav$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
23017b5038d7SDag-Erling Smørgrav$progname: definition of this LT_INIT comes from an older release.
23027b5038d7SDag-Erling Smørgrav$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
23037b5038d7SDag-Erling Smørgrav$progname: and run autoconf again.
23047b5038d7SDag-Erling Smørgrav_LT_EOF
23057b5038d7SDag-Erling Smørgrav        else
23067b5038d7SDag-Erling Smørgrav          cat >&2 <<_LT_EOF
23077b5038d7SDag-Erling Smørgrav$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the
23087b5038d7SDag-Erling Smørgrav$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.
23097b5038d7SDag-Erling Smørgrav$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION
23107b5038d7SDag-Erling Smørgrav$progname: and run autoconf again.
23117b5038d7SDag-Erling Smørgrav_LT_EOF
23127b5038d7SDag-Erling Smørgrav        fi
23137b5038d7SDag-Erling Smørgrav      else
23147b5038d7SDag-Erling Smørgrav        cat >&2 <<_LT_EOF
23157b5038d7SDag-Erling Smørgrav$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,
23167b5038d7SDag-Erling Smørgrav$progname: but the definition of this LT_INIT comes from revision $macro_revision.
23177b5038d7SDag-Erling Smørgrav$progname: You should recreate aclocal.m4 with macros from revision $package_revision
23187b5038d7SDag-Erling Smørgrav$progname: of $PACKAGE $VERSION and run autoconf again.
23197b5038d7SDag-Erling Smørgrav_LT_EOF
23207b5038d7SDag-Erling Smørgrav      fi
23217b5038d7SDag-Erling Smørgrav
23227b5038d7SDag-Erling Smørgrav      exit $EXIT_MISMATCH
23237b5038d7SDag-Erling Smørgrav    fi
23247b5038d7SDag-Erling Smørgrav}
23257b5038d7SDag-Erling Smørgrav
23267b5038d7SDag-Erling Smørgrav
2327986ba33cSDag-Erling Smørgrav# libtool_options_prep [ARG]...
2328986ba33cSDag-Erling Smørgrav# -----------------------------
2329986ba33cSDag-Erling Smørgrav# Preparation for options parsed by libtool.
2330986ba33cSDag-Erling Smørgravlibtool_options_prep ()
2331986ba33cSDag-Erling Smørgrav{
2332986ba33cSDag-Erling Smørgrav    $debug_mode
2333986ba33cSDag-Erling Smørgrav
2334986ba33cSDag-Erling Smørgrav    # Option defaults:
2335986ba33cSDag-Erling Smørgrav    opt_config=false
2336986ba33cSDag-Erling Smørgrav    opt_dlopen=
2337986ba33cSDag-Erling Smørgrav    opt_dry_run=false
2338986ba33cSDag-Erling Smørgrav    opt_help=false
2339986ba33cSDag-Erling Smørgrav    opt_mode=
2340986ba33cSDag-Erling Smørgrav    opt_preserve_dup_deps=false
2341986ba33cSDag-Erling Smørgrav    opt_quiet=false
2342986ba33cSDag-Erling Smørgrav
2343986ba33cSDag-Erling Smørgrav    nonopt=
2344986ba33cSDag-Erling Smørgrav    preserve_args=
2345986ba33cSDag-Erling Smørgrav
2346*5afab0e5SDag-Erling Smørgrav    _G_rc_lt_options_prep=:
2347*5afab0e5SDag-Erling Smørgrav
23487b5038d7SDag-Erling Smørgrav    # Shorthand for --mode=foo, only valid as the first argument
23497b5038d7SDag-Erling Smørgrav    case $1 in
23507b5038d7SDag-Erling Smørgrav    clean|clea|cle|cl)
23517b5038d7SDag-Erling Smørgrav      shift; set dummy --mode clean ${1+"$@"}; shift
23527b5038d7SDag-Erling Smørgrav      ;;
23537b5038d7SDag-Erling Smørgrav    compile|compil|compi|comp|com|co|c)
23547b5038d7SDag-Erling Smørgrav      shift; set dummy --mode compile ${1+"$@"}; shift
23557b5038d7SDag-Erling Smørgrav      ;;
23567b5038d7SDag-Erling Smørgrav    execute|execut|execu|exec|exe|ex|e)
23577b5038d7SDag-Erling Smørgrav      shift; set dummy --mode execute ${1+"$@"}; shift
23587b5038d7SDag-Erling Smørgrav      ;;
23597b5038d7SDag-Erling Smørgrav    finish|finis|fini|fin|fi|f)
23607b5038d7SDag-Erling Smørgrav      shift; set dummy --mode finish ${1+"$@"}; shift
23617b5038d7SDag-Erling Smørgrav      ;;
23627b5038d7SDag-Erling Smørgrav    install|instal|insta|inst|ins|in|i)
23637b5038d7SDag-Erling Smørgrav      shift; set dummy --mode install ${1+"$@"}; shift
23647b5038d7SDag-Erling Smørgrav      ;;
23657b5038d7SDag-Erling Smørgrav    link|lin|li|l)
23667b5038d7SDag-Erling Smørgrav      shift; set dummy --mode link ${1+"$@"}; shift
23677b5038d7SDag-Erling Smørgrav      ;;
23687b5038d7SDag-Erling Smørgrav    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
23697b5038d7SDag-Erling Smørgrav      shift; set dummy --mode uninstall ${1+"$@"}; shift
23707b5038d7SDag-Erling Smørgrav      ;;
2371*5afab0e5SDag-Erling Smørgrav    *)
2372*5afab0e5SDag-Erling Smørgrav      _G_rc_lt_options_prep=false
2373*5afab0e5SDag-Erling Smørgrav      ;;
23747b5038d7SDag-Erling Smørgrav    esac
23757b5038d7SDag-Erling Smørgrav
2376*5afab0e5SDag-Erling Smørgrav    if $_G_rc_lt_options_prep; then
2377986ba33cSDag-Erling Smørgrav      # Pass back the list of options.
2378986ba33cSDag-Erling Smørgrav      func_quote_for_eval ${1+"$@"}
2379986ba33cSDag-Erling Smørgrav      libtool_options_prep_result=$func_quote_for_eval_result
2380*5afab0e5SDag-Erling Smørgrav    fi
2381*5afab0e5SDag-Erling Smørgrav
2382*5afab0e5SDag-Erling Smørgrav    $_G_rc_lt_options_prep
2383986ba33cSDag-Erling Smørgrav}
2384986ba33cSDag-Erling Smørgravfunc_add_hook func_options_prep libtool_options_prep
23857b5038d7SDag-Erling Smørgrav
23867b5038d7SDag-Erling Smørgrav
2387986ba33cSDag-Erling Smørgrav# libtool_parse_options [ARG]...
2388986ba33cSDag-Erling Smørgrav# ---------------------------------
2389986ba33cSDag-Erling Smørgrav# Provide handling for libtool specific options.
2390986ba33cSDag-Erling Smørgravlibtool_parse_options ()
23917b5038d7SDag-Erling Smørgrav{
2392986ba33cSDag-Erling Smørgrav    $debug_cmd
2393986ba33cSDag-Erling Smørgrav
2394*5afab0e5SDag-Erling Smørgrav    _G_rc_lt_parse_options=false
2395*5afab0e5SDag-Erling Smørgrav
2396986ba33cSDag-Erling Smørgrav    # Perform our own loop to consume as many options as possible in
2397986ba33cSDag-Erling Smørgrav    # each iteration.
23987b5038d7SDag-Erling Smørgrav    while test $# -gt 0; do
2399*5afab0e5SDag-Erling Smørgrav      _G_match_lt_parse_options=:
2400986ba33cSDag-Erling Smørgrav      _G_opt=$1
24017b5038d7SDag-Erling Smørgrav      shift
2402986ba33cSDag-Erling Smørgrav      case $_G_opt in
24037b5038d7SDag-Erling Smørgrav        --dry-run|--dryrun|-n)
24047b5038d7SDag-Erling Smørgrav                        opt_dry_run=:
24057b5038d7SDag-Erling Smørgrav                        ;;
2406986ba33cSDag-Erling Smørgrav
2407986ba33cSDag-Erling Smørgrav        --config)       func_config ;;
2408986ba33cSDag-Erling Smørgrav
24097b5038d7SDag-Erling Smørgrav        --dlopen|-dlopen)
24107b5038d7SDag-Erling Smørgrav                        opt_dlopen="${opt_dlopen+$opt_dlopen
2411986ba33cSDag-Erling Smørgrav}$1"
24127b5038d7SDag-Erling Smørgrav                        shift
24137b5038d7SDag-Erling Smørgrav                        ;;
2414986ba33cSDag-Erling Smørgrav
24157b5038d7SDag-Erling Smørgrav        --preserve-dup-deps)
2416986ba33cSDag-Erling Smørgrav                        opt_preserve_dup_deps=: ;;
2417986ba33cSDag-Erling Smørgrav
2418986ba33cSDag-Erling Smørgrav        --features)     func_features ;;
2419986ba33cSDag-Erling Smørgrav
2420986ba33cSDag-Erling Smørgrav        --finish)       set dummy --mode finish ${1+"$@"}; shift ;;
2421986ba33cSDag-Erling Smørgrav
2422986ba33cSDag-Erling Smørgrav        --help)         opt_help=: ;;
2423986ba33cSDag-Erling Smørgrav
2424986ba33cSDag-Erling Smørgrav        --help-all)     opt_help=': help-all' ;;
2425986ba33cSDag-Erling Smørgrav
2426986ba33cSDag-Erling Smørgrav        --mode)         test $# = 0 && func_missing_arg $_G_opt && break
2427986ba33cSDag-Erling Smørgrav                        opt_mode=$1
2428986ba33cSDag-Erling Smørgrav                        case $1 in
24297b5038d7SDag-Erling Smørgrav                          # Valid mode arguments:
24307b5038d7SDag-Erling Smørgrav                          clean|compile|execute|finish|install|link|relink|uninstall) ;;
24317b5038d7SDag-Erling Smørgrav
24327b5038d7SDag-Erling Smørgrav                          # Catch anything else as an error
2433986ba33cSDag-Erling Smørgrav                          *) func_error "invalid argument for $_G_opt"
24347b5038d7SDag-Erling Smørgrav                             exit_cmd=exit
24357b5038d7SDag-Erling Smørgrav                             break
24367b5038d7SDag-Erling Smørgrav                             ;;
24377b5038d7SDag-Erling Smørgrav                        esac
24387b5038d7SDag-Erling Smørgrav                        shift
24397b5038d7SDag-Erling Smørgrav                        ;;
2440986ba33cSDag-Erling Smørgrav
24417b5038d7SDag-Erling Smørgrav        --no-silent|--no-quiet)
2442986ba33cSDag-Erling Smørgrav                        opt_quiet=false
2443986ba33cSDag-Erling Smørgrav                        func_append preserve_args " $_G_opt"
24447b5038d7SDag-Erling Smørgrav                        ;;
2445986ba33cSDag-Erling Smørgrav
2446986ba33cSDag-Erling Smørgrav        --no-warnings|--no-warning|--no-warn)
24477b5038d7SDag-Erling Smørgrav                        opt_warning=false
2448986ba33cSDag-Erling Smørgrav                        func_append preserve_args " $_G_opt"
24497b5038d7SDag-Erling Smørgrav                        ;;
2450986ba33cSDag-Erling Smørgrav
24517b5038d7SDag-Erling Smørgrav        --no-verbose)
24527b5038d7SDag-Erling Smørgrav                        opt_verbose=false
2453986ba33cSDag-Erling Smørgrav                        func_append preserve_args " $_G_opt"
24547b5038d7SDag-Erling Smørgrav                        ;;
2455986ba33cSDag-Erling Smørgrav
24567b5038d7SDag-Erling Smørgrav        --silent|--quiet)
2457986ba33cSDag-Erling Smørgrav                        opt_quiet=:
24587b5038d7SDag-Erling Smørgrav                        opt_verbose=false
2459986ba33cSDag-Erling Smørgrav                        func_append preserve_args " $_G_opt"
24607b5038d7SDag-Erling Smørgrav                        ;;
2461986ba33cSDag-Erling Smørgrav
2462986ba33cSDag-Erling Smørgrav        --tag)          test $# = 0 && func_missing_arg $_G_opt && break
2463986ba33cSDag-Erling Smørgrav                        opt_tag=$1
2464986ba33cSDag-Erling Smørgrav                        func_append preserve_args " $_G_opt $1"
2465986ba33cSDag-Erling Smørgrav                        func_enable_tag "$1"
2466986ba33cSDag-Erling Smørgrav                        shift
2467986ba33cSDag-Erling Smørgrav                        ;;
2468986ba33cSDag-Erling Smørgrav
2469986ba33cSDag-Erling Smørgrav        --verbose|-v)   opt_quiet=false
24707b5038d7SDag-Erling Smørgrav                        opt_verbose=:
2471986ba33cSDag-Erling Smørgrav                        func_append preserve_args " $_G_opt"
24727b5038d7SDag-Erling Smørgrav                        ;;
24737b5038d7SDag-Erling Smørgrav
2474986ba33cSDag-Erling Smørgrav        # An option not handled by this hook function:
2475*5afab0e5SDag-Erling Smørgrav        *)              set dummy "$_G_opt" ${1+"$@"} ; shift
2476*5afab0e5SDag-Erling Smørgrav                        _G_match_lt_parse_options=false
2477*5afab0e5SDag-Erling Smørgrav                        break
2478*5afab0e5SDag-Erling Smørgrav                        ;;
24797b5038d7SDag-Erling Smørgrav      esac
2480*5afab0e5SDag-Erling Smørgrav      $_G_match_lt_parse_options && _G_rc_lt_parse_options=:
24817b5038d7SDag-Erling Smørgrav    done
24827b5038d7SDag-Erling Smørgrav
2483*5afab0e5SDag-Erling Smørgrav    if $_G_rc_lt_parse_options; then
2484986ba33cSDag-Erling Smørgrav      # save modified positional parameters for caller
2485986ba33cSDag-Erling Smørgrav      func_quote_for_eval ${1+"$@"}
2486986ba33cSDag-Erling Smørgrav      libtool_parse_options_result=$func_quote_for_eval_result
2487*5afab0e5SDag-Erling Smørgrav    fi
2488*5afab0e5SDag-Erling Smørgrav
2489*5afab0e5SDag-Erling Smørgrav    $_G_rc_lt_parse_options
2490986ba33cSDag-Erling Smørgrav}
2491986ba33cSDag-Erling Smørgravfunc_add_hook func_parse_options libtool_parse_options
2492986ba33cSDag-Erling Smørgrav
2493986ba33cSDag-Erling Smørgrav
2494986ba33cSDag-Erling Smørgrav
2495986ba33cSDag-Erling Smørgrav# libtool_validate_options [ARG]...
2496986ba33cSDag-Erling Smørgrav# ---------------------------------
2497986ba33cSDag-Erling Smørgrav# Perform any sanity checks on option settings and/or unconsumed
2498986ba33cSDag-Erling Smørgrav# arguments.
2499986ba33cSDag-Erling Smørgravlibtool_validate_options ()
2500986ba33cSDag-Erling Smørgrav{
25017b5038d7SDag-Erling Smørgrav    # save first non-option argument
2502986ba33cSDag-Erling Smørgrav    if test 0 -lt $#; then
2503986ba33cSDag-Erling Smørgrav      nonopt=$1
25047b5038d7SDag-Erling Smørgrav      shift
25057b5038d7SDag-Erling Smørgrav    fi
25067b5038d7SDag-Erling Smørgrav
25077b5038d7SDag-Erling Smørgrav    # preserve --debug
2508986ba33cSDag-Erling Smørgrav    test : = "$debug_cmd" || func_append preserve_args " --debug"
25097b5038d7SDag-Erling Smørgrav
25107b5038d7SDag-Erling Smørgrav    case $host in
2511986ba33cSDag-Erling Smørgrav      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452
2512986ba33cSDag-Erling Smørgrav      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788
2513986ba33cSDag-Erling Smørgrav      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)
25147b5038d7SDag-Erling Smørgrav        # don't eliminate duplications in $postdeps and $predeps
25157b5038d7SDag-Erling Smørgrav        opt_duplicate_compiler_generated_deps=:
25167b5038d7SDag-Erling Smørgrav        ;;
25177b5038d7SDag-Erling Smørgrav      *)
25187b5038d7SDag-Erling Smørgrav        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps
25197b5038d7SDag-Erling Smørgrav        ;;
25207b5038d7SDag-Erling Smørgrav    esac
25217b5038d7SDag-Erling Smørgrav
25227b5038d7SDag-Erling Smørgrav    $opt_help || {
25237b5038d7SDag-Erling Smørgrav      # Sanity checks first:
25247b5038d7SDag-Erling Smørgrav      func_check_version_match
25257b5038d7SDag-Erling Smørgrav
2526986ba33cSDag-Erling Smørgrav      test yes != "$build_libtool_libs" \
2527986ba33cSDag-Erling Smørgrav        && test yes != "$build_old_libs" \
2528986ba33cSDag-Erling Smørgrav        && func_fatal_configuration "not configured to build any kind of library"
25297b5038d7SDag-Erling Smørgrav
25307b5038d7SDag-Erling Smørgrav      # Darwin sucks
25317b5038d7SDag-Erling Smørgrav      eval std_shrext=\"$shrext_cmds\"
25327b5038d7SDag-Erling Smørgrav
25337b5038d7SDag-Erling Smørgrav      # Only execute mode is allowed to have -dlopen flags.
2534986ba33cSDag-Erling Smørgrav      if test -n "$opt_dlopen" && test execute != "$opt_mode"; then
2535986ba33cSDag-Erling Smørgrav        func_error "unrecognized option '-dlopen'"
25367b5038d7SDag-Erling Smørgrav        $ECHO "$help" 1>&2
25377b5038d7SDag-Erling Smørgrav        exit $EXIT_FAILURE
25387b5038d7SDag-Erling Smørgrav      fi
25397b5038d7SDag-Erling Smørgrav
25407b5038d7SDag-Erling Smørgrav      # Change the help message to a mode-specific one.
2541986ba33cSDag-Erling Smørgrav      generic_help=$help
2542986ba33cSDag-Erling Smørgrav      help="Try '$progname --help --mode=$opt_mode' for more information."
25437b5038d7SDag-Erling Smørgrav    }
25447b5038d7SDag-Erling Smørgrav
2545986ba33cSDag-Erling Smørgrav    # Pass back the unparsed argument list
2546986ba33cSDag-Erling Smørgrav    func_quote_for_eval ${1+"$@"}
2547986ba33cSDag-Erling Smørgrav    libtool_validate_options_result=$func_quote_for_eval_result
25487b5038d7SDag-Erling Smørgrav}
2549986ba33cSDag-Erling Smørgravfunc_add_hook func_validate_options libtool_validate_options
25507b5038d7SDag-Erling Smørgrav
25517b5038d7SDag-Erling Smørgrav
2552986ba33cSDag-Erling Smørgrav# Process options as early as possible so that --help and --version
2553986ba33cSDag-Erling Smørgrav# can return quickly.
2554986ba33cSDag-Erling Smørgravfunc_options ${1+"$@"}
2555986ba33cSDag-Erling Smørgraveval set dummy "$func_options_result"; shift
2556986ba33cSDag-Erling Smørgrav
25577b5038d7SDag-Erling Smørgrav
25587b5038d7SDag-Erling Smørgrav
25597b5038d7SDag-Erling Smørgrav## ----------- ##
25607b5038d7SDag-Erling Smørgrav##    Main.    ##
25617b5038d7SDag-Erling Smørgrav## ----------- ##
25627b5038d7SDag-Erling Smørgrav
2563986ba33cSDag-Erling Smørgravmagic='%%%MAGIC variable%%%'
2564986ba33cSDag-Erling Smørgravmagic_exe='%%%MAGIC EXE variable%%%'
2565986ba33cSDag-Erling Smørgrav
2566986ba33cSDag-Erling Smørgrav# Global variables.
2567986ba33cSDag-Erling Smørgravextracted_archives=
2568986ba33cSDag-Erling Smørgravextracted_serial=0
2569986ba33cSDag-Erling Smørgrav
2570986ba33cSDag-Erling Smørgrav# If this variable is set in any of the actions, the command in it
2571986ba33cSDag-Erling Smørgrav# will be execed at the end.  This prevents here-documents from being
2572986ba33cSDag-Erling Smørgrav# left over by shells.
2573986ba33cSDag-Erling Smørgravexec_cmd=
2574986ba33cSDag-Erling Smørgrav
2575986ba33cSDag-Erling Smørgrav
2576986ba33cSDag-Erling Smørgrav# A function that is used when there is no print builtin or printf.
2577986ba33cSDag-Erling Smørgravfunc_fallback_echo ()
2578986ba33cSDag-Erling Smørgrav{
2579986ba33cSDag-Erling Smørgrav  eval 'cat <<_LTECHO_EOF
2580986ba33cSDag-Erling Smørgrav$1
2581986ba33cSDag-Erling Smørgrav_LTECHO_EOF'
2582986ba33cSDag-Erling Smørgrav}
2583986ba33cSDag-Erling Smørgrav
2584986ba33cSDag-Erling Smørgrav# func_generated_by_libtool
2585986ba33cSDag-Erling Smørgrav# True iff stdin has been generated by Libtool. This function is only
2586986ba33cSDag-Erling Smørgrav# a basic sanity check; it will hardly flush out determined imposters.
2587986ba33cSDag-Erling Smørgravfunc_generated_by_libtool_p ()
2588986ba33cSDag-Erling Smørgrav{
2589986ba33cSDag-Erling Smørgrav  $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1
2590986ba33cSDag-Erling Smørgrav}
2591986ba33cSDag-Erling Smørgrav
25927b5038d7SDag-Erling Smørgrav# func_lalib_p file
2593986ba33cSDag-Erling Smørgrav# True iff FILE is a libtool '.la' library or '.lo' object file.
25947b5038d7SDag-Erling Smørgrav# This function is only a basic sanity check; it will hardly flush out
25957b5038d7SDag-Erling Smørgrav# determined imposters.
25967b5038d7SDag-Erling Smørgravfunc_lalib_p ()
25977b5038d7SDag-Erling Smørgrav{
25987b5038d7SDag-Erling Smørgrav    test -f "$1" &&
2599986ba33cSDag-Erling Smørgrav      $SED -e 4q "$1" 2>/dev/null | func_generated_by_libtool_p
26007b5038d7SDag-Erling Smørgrav}
26017b5038d7SDag-Erling Smørgrav
26027b5038d7SDag-Erling Smørgrav# func_lalib_unsafe_p file
2603986ba33cSDag-Erling Smørgrav# True iff FILE is a libtool '.la' library or '.lo' object file.
26047b5038d7SDag-Erling Smørgrav# This function implements the same check as func_lalib_p without
26057b5038d7SDag-Erling Smørgrav# resorting to external programs.  To this end, it redirects stdin and
26067b5038d7SDag-Erling Smørgrav# closes it afterwards, without saving the original file descriptor.
26077b5038d7SDag-Erling Smørgrav# As a safety measure, use it only where a negative result would be
2608986ba33cSDag-Erling Smørgrav# fatal anyway.  Works if 'file' does not exist.
26097b5038d7SDag-Erling Smørgravfunc_lalib_unsafe_p ()
26107b5038d7SDag-Erling Smørgrav{
26117b5038d7SDag-Erling Smørgrav    lalib_p=no
26127b5038d7SDag-Erling Smørgrav    if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then
26137b5038d7SDag-Erling Smørgrav	for lalib_p_l in 1 2 3 4
26147b5038d7SDag-Erling Smørgrav	do
26157b5038d7SDag-Erling Smørgrav	    read lalib_p_line
2616986ba33cSDag-Erling Smørgrav	    case $lalib_p_line in
26177b5038d7SDag-Erling Smørgrav		\#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;;
26187b5038d7SDag-Erling Smørgrav	    esac
26197b5038d7SDag-Erling Smørgrav	done
26207b5038d7SDag-Erling Smørgrav	exec 0<&5 5<&-
26217b5038d7SDag-Erling Smørgrav    fi
2622986ba33cSDag-Erling Smørgrav    test yes = "$lalib_p"
26237b5038d7SDag-Erling Smørgrav}
26247b5038d7SDag-Erling Smørgrav
26257b5038d7SDag-Erling Smørgrav# func_ltwrapper_script_p file
26267b5038d7SDag-Erling Smørgrav# True iff FILE is a libtool wrapper script
26277b5038d7SDag-Erling Smørgrav# This function is only a basic sanity check; it will hardly flush out
26287b5038d7SDag-Erling Smørgrav# determined imposters.
26297b5038d7SDag-Erling Smørgravfunc_ltwrapper_script_p ()
26307b5038d7SDag-Erling Smørgrav{
2631986ba33cSDag-Erling Smørgrav    test -f "$1" &&
2632986ba33cSDag-Erling Smørgrav      $lt_truncate_bin < "$1" 2>/dev/null | func_generated_by_libtool_p
26337b5038d7SDag-Erling Smørgrav}
26347b5038d7SDag-Erling Smørgrav
26357b5038d7SDag-Erling Smørgrav# func_ltwrapper_executable_p file
26367b5038d7SDag-Erling Smørgrav# True iff FILE is a libtool wrapper executable
26377b5038d7SDag-Erling Smørgrav# This function is only a basic sanity check; it will hardly flush out
26387b5038d7SDag-Erling Smørgrav# determined imposters.
26397b5038d7SDag-Erling Smørgravfunc_ltwrapper_executable_p ()
26407b5038d7SDag-Erling Smørgrav{
26417b5038d7SDag-Erling Smørgrav    func_ltwrapper_exec_suffix=
26427b5038d7SDag-Erling Smørgrav    case $1 in
26437b5038d7SDag-Erling Smørgrav    *.exe) ;;
26447b5038d7SDag-Erling Smørgrav    *) func_ltwrapper_exec_suffix=.exe ;;
26457b5038d7SDag-Erling Smørgrav    esac
26467b5038d7SDag-Erling Smørgrav    $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1
26477b5038d7SDag-Erling Smørgrav}
26487b5038d7SDag-Erling Smørgrav
26497b5038d7SDag-Erling Smørgrav# func_ltwrapper_scriptname file
26507b5038d7SDag-Erling Smørgrav# Assumes file is an ltwrapper_executable
26517b5038d7SDag-Erling Smørgrav# uses $file to determine the appropriate filename for a
26527b5038d7SDag-Erling Smørgrav# temporary ltwrapper_script.
26537b5038d7SDag-Erling Smørgravfunc_ltwrapper_scriptname ()
26547b5038d7SDag-Erling Smørgrav{
26557b5038d7SDag-Erling Smørgrav    func_dirname_and_basename "$1" "" "."
26567b5038d7SDag-Erling Smørgrav    func_stripname '' '.exe' "$func_basename_result"
2657986ba33cSDag-Erling Smørgrav    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper
26587b5038d7SDag-Erling Smørgrav}
26597b5038d7SDag-Erling Smørgrav
26607b5038d7SDag-Erling Smørgrav# func_ltwrapper_p file
26617b5038d7SDag-Erling Smørgrav# True iff FILE is a libtool wrapper script or wrapper executable
26627b5038d7SDag-Erling Smørgrav# This function is only a basic sanity check; it will hardly flush out
26637b5038d7SDag-Erling Smørgrav# determined imposters.
26647b5038d7SDag-Erling Smørgravfunc_ltwrapper_p ()
26657b5038d7SDag-Erling Smørgrav{
26667b5038d7SDag-Erling Smørgrav    func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1"
26677b5038d7SDag-Erling Smørgrav}
26687b5038d7SDag-Erling Smørgrav
26697b5038d7SDag-Erling Smørgrav
26707b5038d7SDag-Erling Smørgrav# func_execute_cmds commands fail_cmd
26717b5038d7SDag-Erling Smørgrav# Execute tilde-delimited COMMANDS.
26727b5038d7SDag-Erling Smørgrav# If FAIL_CMD is given, eval that upon failure.
26737b5038d7SDag-Erling Smørgrav# FAIL_CMD may read-access the current command in variable CMD!
26747b5038d7SDag-Erling Smørgravfunc_execute_cmds ()
26757b5038d7SDag-Erling Smørgrav{
2676986ba33cSDag-Erling Smørgrav    $debug_cmd
2677986ba33cSDag-Erling Smørgrav
26787b5038d7SDag-Erling Smørgrav    save_ifs=$IFS; IFS='~'
26797b5038d7SDag-Erling Smørgrav    for cmd in $1; do
2680986ba33cSDag-Erling Smørgrav      IFS=$sp$nl
26817b5038d7SDag-Erling Smørgrav      eval cmd=\"$cmd\"
2682986ba33cSDag-Erling Smørgrav      IFS=$save_ifs
26837b5038d7SDag-Erling Smørgrav      func_show_eval "$cmd" "${2-:}"
26847b5038d7SDag-Erling Smørgrav    done
26857b5038d7SDag-Erling Smørgrav    IFS=$save_ifs
26867b5038d7SDag-Erling Smørgrav}
26877b5038d7SDag-Erling Smørgrav
26887b5038d7SDag-Erling Smørgrav
26897b5038d7SDag-Erling Smørgrav# func_source file
26907b5038d7SDag-Erling Smørgrav# Source FILE, adding directory component if necessary.
26917b5038d7SDag-Erling Smørgrav# Note that it is not necessary on cygwin/mingw to append a dot to
26927b5038d7SDag-Erling Smørgrav# FILE even if both FILE and FILE.exe exist: automatic-append-.exe
26937b5038d7SDag-Erling Smørgrav# behavior happens only for exec(3), not for open(2)!  Also, sourcing
2694986ba33cSDag-Erling Smørgrav# 'FILE.' does not work on cygwin managed mounts.
26957b5038d7SDag-Erling Smørgravfunc_source ()
26967b5038d7SDag-Erling Smørgrav{
2697986ba33cSDag-Erling Smørgrav    $debug_cmd
2698986ba33cSDag-Erling Smørgrav
26997b5038d7SDag-Erling Smørgrav    case $1 in
27007b5038d7SDag-Erling Smørgrav    */* | *\\*)	. "$1" ;;
27017b5038d7SDag-Erling Smørgrav    *)		. "./$1" ;;
27027b5038d7SDag-Erling Smørgrav    esac
27037b5038d7SDag-Erling Smørgrav}
27047b5038d7SDag-Erling Smørgrav
27057b5038d7SDag-Erling Smørgrav
27067b5038d7SDag-Erling Smørgrav# func_resolve_sysroot PATH
27077b5038d7SDag-Erling Smørgrav# Replace a leading = in PATH with a sysroot.  Store the result into
27087b5038d7SDag-Erling Smørgrav# func_resolve_sysroot_result
27097b5038d7SDag-Erling Smørgravfunc_resolve_sysroot ()
27107b5038d7SDag-Erling Smørgrav{
27117b5038d7SDag-Erling Smørgrav  func_resolve_sysroot_result=$1
27127b5038d7SDag-Erling Smørgrav  case $func_resolve_sysroot_result in
27137b5038d7SDag-Erling Smørgrav  =*)
27147b5038d7SDag-Erling Smørgrav    func_stripname '=' '' "$func_resolve_sysroot_result"
27157b5038d7SDag-Erling Smørgrav    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result
27167b5038d7SDag-Erling Smørgrav    ;;
27177b5038d7SDag-Erling Smørgrav  esac
27187b5038d7SDag-Erling Smørgrav}
27197b5038d7SDag-Erling Smørgrav
27207b5038d7SDag-Erling Smørgrav# func_replace_sysroot PATH
27217b5038d7SDag-Erling Smørgrav# If PATH begins with the sysroot, replace it with = and
27227b5038d7SDag-Erling Smørgrav# store the result into func_replace_sysroot_result.
27237b5038d7SDag-Erling Smørgravfunc_replace_sysroot ()
27247b5038d7SDag-Erling Smørgrav{
2725986ba33cSDag-Erling Smørgrav  case $lt_sysroot:$1 in
27267b5038d7SDag-Erling Smørgrav  ?*:"$lt_sysroot"*)
27277b5038d7SDag-Erling Smørgrav    func_stripname "$lt_sysroot" '' "$1"
2728986ba33cSDag-Erling Smørgrav    func_replace_sysroot_result='='$func_stripname_result
27297b5038d7SDag-Erling Smørgrav    ;;
27307b5038d7SDag-Erling Smørgrav  *)
27317b5038d7SDag-Erling Smørgrav    # Including no sysroot.
27327b5038d7SDag-Erling Smørgrav    func_replace_sysroot_result=$1
27337b5038d7SDag-Erling Smørgrav    ;;
27347b5038d7SDag-Erling Smørgrav  esac
27357b5038d7SDag-Erling Smørgrav}
27367b5038d7SDag-Erling Smørgrav
27377b5038d7SDag-Erling Smørgrav# func_infer_tag arg
27387b5038d7SDag-Erling Smørgrav# Infer tagged configuration to use if any are available and
27397b5038d7SDag-Erling Smørgrav# if one wasn't chosen via the "--tag" command line option.
27407b5038d7SDag-Erling Smørgrav# Only attempt this if the compiler in the base compile
27417b5038d7SDag-Erling Smørgrav# command doesn't match the default compiler.
27427b5038d7SDag-Erling Smørgrav# arg is usually of the form 'gcc ...'
27437b5038d7SDag-Erling Smørgravfunc_infer_tag ()
27447b5038d7SDag-Erling Smørgrav{
2745986ba33cSDag-Erling Smørgrav    $debug_cmd
2746986ba33cSDag-Erling Smørgrav
27477b5038d7SDag-Erling Smørgrav    if test -n "$available_tags" && test -z "$tagname"; then
27487b5038d7SDag-Erling Smørgrav      CC_quoted=
27497b5038d7SDag-Erling Smørgrav      for arg in $CC; do
27507b5038d7SDag-Erling Smørgrav	func_append_quoted CC_quoted "$arg"
27517b5038d7SDag-Erling Smørgrav      done
27527b5038d7SDag-Erling Smørgrav      CC_expanded=`func_echo_all $CC`
27537b5038d7SDag-Erling Smørgrav      CC_quoted_expanded=`func_echo_all $CC_quoted`
27547b5038d7SDag-Erling Smørgrav      case $@ in
27557b5038d7SDag-Erling Smørgrav      # Blanks in the command may have been stripped by the calling shell,
27567b5038d7SDag-Erling Smørgrav      # but not from the CC environment variable when configure was run.
27577b5038d7SDag-Erling Smørgrav      " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
27587b5038d7SDag-Erling Smørgrav      " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;;
27597b5038d7SDag-Erling Smørgrav      # Blanks at the start of $base_compile will cause this to fail
27607b5038d7SDag-Erling Smørgrav      # if we don't check for them as well.
27617b5038d7SDag-Erling Smørgrav      *)
27627b5038d7SDag-Erling Smørgrav	for z in $available_tags; do
27637b5038d7SDag-Erling Smørgrav	  if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
27647b5038d7SDag-Erling Smørgrav	    # Evaluate the configuration.
2765986ba33cSDag-Erling Smørgrav	    eval "`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
27667b5038d7SDag-Erling Smørgrav	    CC_quoted=
27677b5038d7SDag-Erling Smørgrav	    for arg in $CC; do
27687b5038d7SDag-Erling Smørgrav	      # Double-quote args containing other shell metacharacters.
27697b5038d7SDag-Erling Smørgrav	      func_append_quoted CC_quoted "$arg"
27707b5038d7SDag-Erling Smørgrav	    done
27717b5038d7SDag-Erling Smørgrav	    CC_expanded=`func_echo_all $CC`
27727b5038d7SDag-Erling Smørgrav	    CC_quoted_expanded=`func_echo_all $CC_quoted`
27737b5038d7SDag-Erling Smørgrav	    case "$@ " in
27747b5038d7SDag-Erling Smørgrav	    " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \
27757b5038d7SDag-Erling Smørgrav	    " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*)
27767b5038d7SDag-Erling Smørgrav	      # The compiler in the base compile command matches
27777b5038d7SDag-Erling Smørgrav	      # the one in the tagged configuration.
27787b5038d7SDag-Erling Smørgrav	      # Assume this is the tagged configuration we want.
27797b5038d7SDag-Erling Smørgrav	      tagname=$z
27807b5038d7SDag-Erling Smørgrav	      break
27817b5038d7SDag-Erling Smørgrav	      ;;
27827b5038d7SDag-Erling Smørgrav	    esac
27837b5038d7SDag-Erling Smørgrav	  fi
27847b5038d7SDag-Erling Smørgrav	done
27857b5038d7SDag-Erling Smørgrav	# If $tagname still isn't set, then no tagged configuration
27867b5038d7SDag-Erling Smørgrav	# was found and let the user know that the "--tag" command
27877b5038d7SDag-Erling Smørgrav	# line option must be used.
27887b5038d7SDag-Erling Smørgrav	if test -z "$tagname"; then
27897b5038d7SDag-Erling Smørgrav	  func_echo "unable to infer tagged configuration"
2790986ba33cSDag-Erling Smørgrav	  func_fatal_error "specify a tag with '--tag'"
27917b5038d7SDag-Erling Smørgrav#	else
27927b5038d7SDag-Erling Smørgrav#	  func_verbose "using $tagname tagged configuration"
27937b5038d7SDag-Erling Smørgrav	fi
27947b5038d7SDag-Erling Smørgrav	;;
27957b5038d7SDag-Erling Smørgrav      esac
27967b5038d7SDag-Erling Smørgrav    fi
27977b5038d7SDag-Erling Smørgrav}
27987b5038d7SDag-Erling Smørgrav
27997b5038d7SDag-Erling Smørgrav
28007b5038d7SDag-Erling Smørgrav
28017b5038d7SDag-Erling Smørgrav# func_write_libtool_object output_name pic_name nonpic_name
28027b5038d7SDag-Erling Smørgrav# Create a libtool object file (analogous to a ".la" file),
28037b5038d7SDag-Erling Smørgrav# but don't create it if we're doing a dry run.
28047b5038d7SDag-Erling Smørgravfunc_write_libtool_object ()
28057b5038d7SDag-Erling Smørgrav{
2806986ba33cSDag-Erling Smørgrav    write_libobj=$1
2807986ba33cSDag-Erling Smørgrav    if test yes = "$build_libtool_libs"; then
2808986ba33cSDag-Erling Smørgrav      write_lobj=\'$2\'
28097b5038d7SDag-Erling Smørgrav    else
28107b5038d7SDag-Erling Smørgrav      write_lobj=none
28117b5038d7SDag-Erling Smørgrav    fi
28127b5038d7SDag-Erling Smørgrav
2813986ba33cSDag-Erling Smørgrav    if test yes = "$build_old_libs"; then
2814986ba33cSDag-Erling Smørgrav      write_oldobj=\'$3\'
28157b5038d7SDag-Erling Smørgrav    else
28167b5038d7SDag-Erling Smørgrav      write_oldobj=none
28177b5038d7SDag-Erling Smørgrav    fi
28187b5038d7SDag-Erling Smørgrav
28197b5038d7SDag-Erling Smørgrav    $opt_dry_run || {
28207b5038d7SDag-Erling Smørgrav      cat >${write_libobj}T <<EOF
28217b5038d7SDag-Erling Smørgrav# $write_libobj - a libtool object file
2822986ba33cSDag-Erling Smørgrav# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
28237b5038d7SDag-Erling Smørgrav#
28247b5038d7SDag-Erling Smørgrav# Please DO NOT delete this file!
28257b5038d7SDag-Erling Smørgrav# It is necessary for linking the library.
28267b5038d7SDag-Erling Smørgrav
28277b5038d7SDag-Erling Smørgrav# Name of the PIC object.
28287b5038d7SDag-Erling Smørgravpic_object=$write_lobj
28297b5038d7SDag-Erling Smørgrav
28307b5038d7SDag-Erling Smørgrav# Name of the non-PIC object
28317b5038d7SDag-Erling Smørgravnon_pic_object=$write_oldobj
28327b5038d7SDag-Erling Smørgrav
28337b5038d7SDag-Erling SmørgravEOF
2834986ba33cSDag-Erling Smørgrav      $MV "${write_libobj}T" "$write_libobj"
28357b5038d7SDag-Erling Smørgrav    }
28367b5038d7SDag-Erling Smørgrav}
28377b5038d7SDag-Erling Smørgrav
28387b5038d7SDag-Erling Smørgrav
28397b5038d7SDag-Erling Smørgrav##################################################
28407b5038d7SDag-Erling Smørgrav# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #
28417b5038d7SDag-Erling Smørgrav##################################################
28427b5038d7SDag-Erling Smørgrav
28437b5038d7SDag-Erling Smørgrav# func_convert_core_file_wine_to_w32 ARG
28447b5038d7SDag-Erling Smørgrav# Helper function used by file name conversion functions when $build is *nix,
28457b5038d7SDag-Erling Smørgrav# and $host is mingw, cygwin, or some other w32 environment. Relies on a
28467b5038d7SDag-Erling Smørgrav# correctly configured wine environment available, with the winepath program
28477b5038d7SDag-Erling Smørgrav# in $build's $PATH.
28487b5038d7SDag-Erling Smørgrav#
28497b5038d7SDag-Erling Smørgrav# ARG is the $build file name to be converted to w32 format.
28507b5038d7SDag-Erling Smørgrav# Result is available in $func_convert_core_file_wine_to_w32_result, and will
28517b5038d7SDag-Erling Smørgrav# be empty on error (or when ARG is empty)
28527b5038d7SDag-Erling Smørgravfunc_convert_core_file_wine_to_w32 ()
28537b5038d7SDag-Erling Smørgrav{
2854986ba33cSDag-Erling Smørgrav  $debug_cmd
2855986ba33cSDag-Erling Smørgrav
2856986ba33cSDag-Erling Smørgrav  func_convert_core_file_wine_to_w32_result=$1
28577b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
28587b5038d7SDag-Erling Smørgrav    # Unfortunately, winepath does not exit with a non-zero error code, so we
28597b5038d7SDag-Erling Smørgrav    # are forced to check the contents of stdout. On the other hand, if the
28607b5038d7SDag-Erling Smørgrav    # command is not found, the shell will set an exit code of 127 and print
28617b5038d7SDag-Erling Smørgrav    # *an error message* to stdout. So we must check for both error code of
28627b5038d7SDag-Erling Smørgrav    # zero AND non-empty stdout, which explains the odd construction:
28637b5038d7SDag-Erling Smørgrav    func_convert_core_file_wine_to_w32_tmp=`winepath -w "$1" 2>/dev/null`
2864986ba33cSDag-Erling Smørgrav    if test "$?" -eq 0 && test -n "$func_convert_core_file_wine_to_w32_tmp"; then
28657b5038d7SDag-Erling Smørgrav      func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" |
2866986ba33cSDag-Erling Smørgrav        $SED -e "$sed_naive_backslashify"`
28677b5038d7SDag-Erling Smørgrav    else
28687b5038d7SDag-Erling Smørgrav      func_convert_core_file_wine_to_w32_result=
28697b5038d7SDag-Erling Smørgrav    fi
28707b5038d7SDag-Erling Smørgrav  fi
28717b5038d7SDag-Erling Smørgrav}
28727b5038d7SDag-Erling Smørgrav# end: func_convert_core_file_wine_to_w32
28737b5038d7SDag-Erling Smørgrav
28747b5038d7SDag-Erling Smørgrav
28757b5038d7SDag-Erling Smørgrav# func_convert_core_path_wine_to_w32 ARG
28767b5038d7SDag-Erling Smørgrav# Helper function used by path conversion functions when $build is *nix, and
28777b5038d7SDag-Erling Smørgrav# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly
28787b5038d7SDag-Erling Smørgrav# configured wine environment available, with the winepath program in $build's
28797b5038d7SDag-Erling Smørgrav# $PATH. Assumes ARG has no leading or trailing path separator characters.
28807b5038d7SDag-Erling Smørgrav#
28817b5038d7SDag-Erling Smørgrav# ARG is path to be converted from $build format to win32.
28827b5038d7SDag-Erling Smørgrav# Result is available in $func_convert_core_path_wine_to_w32_result.
28837b5038d7SDag-Erling Smørgrav# Unconvertible file (directory) names in ARG are skipped; if no directory names
28847b5038d7SDag-Erling Smørgrav# are convertible, then the result may be empty.
28857b5038d7SDag-Erling Smørgravfunc_convert_core_path_wine_to_w32 ()
28867b5038d7SDag-Erling Smørgrav{
2887986ba33cSDag-Erling Smørgrav  $debug_cmd
2888986ba33cSDag-Erling Smørgrav
28897b5038d7SDag-Erling Smørgrav  # unfortunately, winepath doesn't convert paths, only file names
2890986ba33cSDag-Erling Smørgrav  func_convert_core_path_wine_to_w32_result=
28917b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
28927b5038d7SDag-Erling Smørgrav    oldIFS=$IFS
28937b5038d7SDag-Erling Smørgrav    IFS=:
28947b5038d7SDag-Erling Smørgrav    for func_convert_core_path_wine_to_w32_f in $1; do
28957b5038d7SDag-Erling Smørgrav      IFS=$oldIFS
28967b5038d7SDag-Erling Smørgrav      func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f"
28977b5038d7SDag-Erling Smørgrav      if test -n "$func_convert_core_file_wine_to_w32_result"; then
28987b5038d7SDag-Erling Smørgrav        if test -z "$func_convert_core_path_wine_to_w32_result"; then
2899986ba33cSDag-Erling Smørgrav          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result
29007b5038d7SDag-Erling Smørgrav        else
29017b5038d7SDag-Erling Smørgrav          func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result"
29027b5038d7SDag-Erling Smørgrav        fi
29037b5038d7SDag-Erling Smørgrav      fi
29047b5038d7SDag-Erling Smørgrav    done
29057b5038d7SDag-Erling Smørgrav    IFS=$oldIFS
29067b5038d7SDag-Erling Smørgrav  fi
29077b5038d7SDag-Erling Smørgrav}
29087b5038d7SDag-Erling Smørgrav# end: func_convert_core_path_wine_to_w32
29097b5038d7SDag-Erling Smørgrav
29107b5038d7SDag-Erling Smørgrav
29117b5038d7SDag-Erling Smørgrav# func_cygpath ARGS...
29127b5038d7SDag-Erling Smørgrav# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when
29137b5038d7SDag-Erling Smørgrav# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)
29147b5038d7SDag-Erling Smørgrav# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or
29157b5038d7SDag-Erling Smørgrav# (2), returns the Cygwin file name or path in func_cygpath_result (input
29167b5038d7SDag-Erling Smørgrav# file name or path is assumed to be in w32 format, as previously converted
29177b5038d7SDag-Erling Smørgrav# from $build's *nix or MSYS format). In case (3), returns the w32 file name
29187b5038d7SDag-Erling Smørgrav# or path in func_cygpath_result (input file name or path is assumed to be in
29197b5038d7SDag-Erling Smørgrav# Cygwin format). Returns an empty string on error.
29207b5038d7SDag-Erling Smørgrav#
29217b5038d7SDag-Erling Smørgrav# ARGS are passed to cygpath, with the last one being the file name or path to
29227b5038d7SDag-Erling Smørgrav# be converted.
29237b5038d7SDag-Erling Smørgrav#
29247b5038d7SDag-Erling Smørgrav# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH
29257b5038d7SDag-Erling Smørgrav# environment variable; do not put it in $PATH.
29267b5038d7SDag-Erling Smørgravfunc_cygpath ()
29277b5038d7SDag-Erling Smørgrav{
2928986ba33cSDag-Erling Smørgrav  $debug_cmd
2929986ba33cSDag-Erling Smørgrav
29307b5038d7SDag-Erling Smørgrav  if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then
29317b5038d7SDag-Erling Smørgrav    func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null`
29327b5038d7SDag-Erling Smørgrav    if test "$?" -ne 0; then
29337b5038d7SDag-Erling Smørgrav      # on failure, ensure result is empty
29347b5038d7SDag-Erling Smørgrav      func_cygpath_result=
29357b5038d7SDag-Erling Smørgrav    fi
29367b5038d7SDag-Erling Smørgrav  else
29377b5038d7SDag-Erling Smørgrav    func_cygpath_result=
2938986ba33cSDag-Erling Smørgrav    func_error "LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'"
29397b5038d7SDag-Erling Smørgrav  fi
29407b5038d7SDag-Erling Smørgrav}
29417b5038d7SDag-Erling Smørgrav#end: func_cygpath
29427b5038d7SDag-Erling Smørgrav
29437b5038d7SDag-Erling Smørgrav
29447b5038d7SDag-Erling Smørgrav# func_convert_core_msys_to_w32 ARG
29457b5038d7SDag-Erling Smørgrav# Convert file name or path ARG from MSYS format to w32 format.  Return
29467b5038d7SDag-Erling Smørgrav# result in func_convert_core_msys_to_w32_result.
29477b5038d7SDag-Erling Smørgravfunc_convert_core_msys_to_w32 ()
29487b5038d7SDag-Erling Smørgrav{
2949986ba33cSDag-Erling Smørgrav  $debug_cmd
2950986ba33cSDag-Erling Smørgrav
29517b5038d7SDag-Erling Smørgrav  # awkward: cmd appends spaces to result
29527b5038d7SDag-Erling Smørgrav  func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null |
2953986ba33cSDag-Erling Smørgrav    $SED -e 's/[ ]*$//' -e "$sed_naive_backslashify"`
29547b5038d7SDag-Erling Smørgrav}
29557b5038d7SDag-Erling Smørgrav#end: func_convert_core_msys_to_w32
29567b5038d7SDag-Erling Smørgrav
29577b5038d7SDag-Erling Smørgrav
29587b5038d7SDag-Erling Smørgrav# func_convert_file_check ARG1 ARG2
29597b5038d7SDag-Erling Smørgrav# Verify that ARG1 (a file name in $build format) was converted to $host
29607b5038d7SDag-Erling Smørgrav# format in ARG2. Otherwise, emit an error message, but continue (resetting
29617b5038d7SDag-Erling Smørgrav# func_to_host_file_result to ARG1).
29627b5038d7SDag-Erling Smørgravfunc_convert_file_check ()
29637b5038d7SDag-Erling Smørgrav{
2964986ba33cSDag-Erling Smørgrav  $debug_cmd
2965986ba33cSDag-Erling Smørgrav
29667b5038d7SDag-Erling Smørgrav  if test -z "$2" && test -n "$1"; then
29677b5038d7SDag-Erling Smørgrav    func_error "Could not determine host file name corresponding to"
2968986ba33cSDag-Erling Smørgrav    func_error "  '$1'"
29697b5038d7SDag-Erling Smørgrav    func_error "Continuing, but uninstalled executables may not work."
29707b5038d7SDag-Erling Smørgrav    # Fallback:
2971986ba33cSDag-Erling Smørgrav    func_to_host_file_result=$1
29727b5038d7SDag-Erling Smørgrav  fi
29737b5038d7SDag-Erling Smørgrav}
29747b5038d7SDag-Erling Smørgrav# end func_convert_file_check
29757b5038d7SDag-Erling Smørgrav
29767b5038d7SDag-Erling Smørgrav
29777b5038d7SDag-Erling Smørgrav# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH
29787b5038d7SDag-Erling Smørgrav# Verify that FROM_PATH (a path in $build format) was converted to $host
29797b5038d7SDag-Erling Smørgrav# format in TO_PATH. Otherwise, emit an error message, but continue, resetting
29807b5038d7SDag-Erling Smørgrav# func_to_host_file_result to a simplistic fallback value (see below).
29817b5038d7SDag-Erling Smørgravfunc_convert_path_check ()
29827b5038d7SDag-Erling Smørgrav{
2983986ba33cSDag-Erling Smørgrav  $debug_cmd
2984986ba33cSDag-Erling Smørgrav
29857b5038d7SDag-Erling Smørgrav  if test -z "$4" && test -n "$3"; then
29867b5038d7SDag-Erling Smørgrav    func_error "Could not determine the host path corresponding to"
2987986ba33cSDag-Erling Smørgrav    func_error "  '$3'"
29887b5038d7SDag-Erling Smørgrav    func_error "Continuing, but uninstalled executables may not work."
29897b5038d7SDag-Erling Smørgrav    # Fallback.  This is a deliberately simplistic "conversion" and
29907b5038d7SDag-Erling Smørgrav    # should not be "improved".  See libtool.info.
29917b5038d7SDag-Erling Smørgrav    if test "x$1" != "x$2"; then
29927b5038d7SDag-Erling Smørgrav      lt_replace_pathsep_chars="s|$1|$2|g"
29937b5038d7SDag-Erling Smørgrav      func_to_host_path_result=`echo "$3" |
29947b5038d7SDag-Erling Smørgrav        $SED -e "$lt_replace_pathsep_chars"`
29957b5038d7SDag-Erling Smørgrav    else
2996986ba33cSDag-Erling Smørgrav      func_to_host_path_result=$3
29977b5038d7SDag-Erling Smørgrav    fi
29987b5038d7SDag-Erling Smørgrav  fi
29997b5038d7SDag-Erling Smørgrav}
30007b5038d7SDag-Erling Smørgrav# end func_convert_path_check
30017b5038d7SDag-Erling Smørgrav
30027b5038d7SDag-Erling Smørgrav
30037b5038d7SDag-Erling Smørgrav# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG
30047b5038d7SDag-Erling Smørgrav# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT
30057b5038d7SDag-Erling Smørgrav# and appending REPL if ORIG matches BACKPAT.
30067b5038d7SDag-Erling Smørgravfunc_convert_path_front_back_pathsep ()
30077b5038d7SDag-Erling Smørgrav{
3008986ba33cSDag-Erling Smørgrav  $debug_cmd
3009986ba33cSDag-Erling Smørgrav
30107b5038d7SDag-Erling Smørgrav  case $4 in
3011986ba33cSDag-Erling Smørgrav  $1 ) func_to_host_path_result=$3$func_to_host_path_result
30127b5038d7SDag-Erling Smørgrav    ;;
30137b5038d7SDag-Erling Smørgrav  esac
30147b5038d7SDag-Erling Smørgrav  case $4 in
30157b5038d7SDag-Erling Smørgrav  $2 ) func_append func_to_host_path_result "$3"
30167b5038d7SDag-Erling Smørgrav    ;;
30177b5038d7SDag-Erling Smørgrav  esac
30187b5038d7SDag-Erling Smørgrav}
30197b5038d7SDag-Erling Smørgrav# end func_convert_path_front_back_pathsep
30207b5038d7SDag-Erling Smørgrav
30217b5038d7SDag-Erling Smørgrav
30227b5038d7SDag-Erling Smørgrav##################################################
30237b5038d7SDag-Erling Smørgrav# $build to $host FILE NAME CONVERSION FUNCTIONS #
30247b5038d7SDag-Erling Smørgrav##################################################
3025986ba33cSDag-Erling Smørgrav# invoked via '$to_host_file_cmd ARG'
30267b5038d7SDag-Erling Smørgrav#
30277b5038d7SDag-Erling Smørgrav# In each case, ARG is the path to be converted from $build to $host format.
30287b5038d7SDag-Erling Smørgrav# Result will be available in $func_to_host_file_result.
30297b5038d7SDag-Erling Smørgrav
30307b5038d7SDag-Erling Smørgrav
30317b5038d7SDag-Erling Smørgrav# func_to_host_file ARG
30327b5038d7SDag-Erling Smørgrav# Converts the file name ARG from $build format to $host format. Return result
30337b5038d7SDag-Erling Smørgrav# in func_to_host_file_result.
30347b5038d7SDag-Erling Smørgravfunc_to_host_file ()
30357b5038d7SDag-Erling Smørgrav{
3036986ba33cSDag-Erling Smørgrav  $debug_cmd
3037986ba33cSDag-Erling Smørgrav
30387b5038d7SDag-Erling Smørgrav  $to_host_file_cmd "$1"
30397b5038d7SDag-Erling Smørgrav}
30407b5038d7SDag-Erling Smørgrav# end func_to_host_file
30417b5038d7SDag-Erling Smørgrav
30427b5038d7SDag-Erling Smørgrav
30437b5038d7SDag-Erling Smørgrav# func_to_tool_file ARG LAZY
30447b5038d7SDag-Erling Smørgrav# converts the file name ARG from $build format to toolchain format. Return
30457b5038d7SDag-Erling Smørgrav# result in func_to_tool_file_result.  If the conversion in use is listed
30467b5038d7SDag-Erling Smørgrav# in (the comma separated) LAZY, no conversion takes place.
30477b5038d7SDag-Erling Smørgravfunc_to_tool_file ()
30487b5038d7SDag-Erling Smørgrav{
3049986ba33cSDag-Erling Smørgrav  $debug_cmd
3050986ba33cSDag-Erling Smørgrav
30517b5038d7SDag-Erling Smørgrav  case ,$2, in
30527b5038d7SDag-Erling Smørgrav    *,"$to_tool_file_cmd",*)
30537b5038d7SDag-Erling Smørgrav      func_to_tool_file_result=$1
30547b5038d7SDag-Erling Smørgrav      ;;
30557b5038d7SDag-Erling Smørgrav    *)
30567b5038d7SDag-Erling Smørgrav      $to_tool_file_cmd "$1"
30577b5038d7SDag-Erling Smørgrav      func_to_tool_file_result=$func_to_host_file_result
30587b5038d7SDag-Erling Smørgrav      ;;
30597b5038d7SDag-Erling Smørgrav  esac
30607b5038d7SDag-Erling Smørgrav}
30617b5038d7SDag-Erling Smørgrav# end func_to_tool_file
30627b5038d7SDag-Erling Smørgrav
30637b5038d7SDag-Erling Smørgrav
30647b5038d7SDag-Erling Smørgrav# func_convert_file_noop ARG
30657b5038d7SDag-Erling Smørgrav# Copy ARG to func_to_host_file_result.
30667b5038d7SDag-Erling Smørgravfunc_convert_file_noop ()
30677b5038d7SDag-Erling Smørgrav{
3068986ba33cSDag-Erling Smørgrav  func_to_host_file_result=$1
30697b5038d7SDag-Erling Smørgrav}
30707b5038d7SDag-Erling Smørgrav# end func_convert_file_noop
30717b5038d7SDag-Erling Smørgrav
30727b5038d7SDag-Erling Smørgrav
30737b5038d7SDag-Erling Smørgrav# func_convert_file_msys_to_w32 ARG
30747b5038d7SDag-Erling Smørgrav# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic
30757b5038d7SDag-Erling Smørgrav# conversion to w32 is not available inside the cwrapper.  Returns result in
30767b5038d7SDag-Erling Smørgrav# func_to_host_file_result.
30777b5038d7SDag-Erling Smørgravfunc_convert_file_msys_to_w32 ()
30787b5038d7SDag-Erling Smørgrav{
3079986ba33cSDag-Erling Smørgrav  $debug_cmd
3080986ba33cSDag-Erling Smørgrav
3081986ba33cSDag-Erling Smørgrav  func_to_host_file_result=$1
30827b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
30837b5038d7SDag-Erling Smørgrav    func_convert_core_msys_to_w32 "$1"
3084986ba33cSDag-Erling Smørgrav    func_to_host_file_result=$func_convert_core_msys_to_w32_result
30857b5038d7SDag-Erling Smørgrav  fi
30867b5038d7SDag-Erling Smørgrav  func_convert_file_check "$1" "$func_to_host_file_result"
30877b5038d7SDag-Erling Smørgrav}
30887b5038d7SDag-Erling Smørgrav# end func_convert_file_msys_to_w32
30897b5038d7SDag-Erling Smørgrav
30907b5038d7SDag-Erling Smørgrav
30917b5038d7SDag-Erling Smørgrav# func_convert_file_cygwin_to_w32 ARG
30927b5038d7SDag-Erling Smørgrav# Convert file name ARG from Cygwin to w32 format.  Returns result in
30937b5038d7SDag-Erling Smørgrav# func_to_host_file_result.
30947b5038d7SDag-Erling Smørgravfunc_convert_file_cygwin_to_w32 ()
30957b5038d7SDag-Erling Smørgrav{
3096986ba33cSDag-Erling Smørgrav  $debug_cmd
3097986ba33cSDag-Erling Smørgrav
3098986ba33cSDag-Erling Smørgrav  func_to_host_file_result=$1
30997b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
31007b5038d7SDag-Erling Smørgrav    # because $build is cygwin, we call "the" cygpath in $PATH; no need to use
31017b5038d7SDag-Erling Smørgrav    # LT_CYGPATH in this case.
31027b5038d7SDag-Erling Smørgrav    func_to_host_file_result=`cygpath -m "$1"`
31037b5038d7SDag-Erling Smørgrav  fi
31047b5038d7SDag-Erling Smørgrav  func_convert_file_check "$1" "$func_to_host_file_result"
31057b5038d7SDag-Erling Smørgrav}
31067b5038d7SDag-Erling Smørgrav# end func_convert_file_cygwin_to_w32
31077b5038d7SDag-Erling Smørgrav
31087b5038d7SDag-Erling Smørgrav
31097b5038d7SDag-Erling Smørgrav# func_convert_file_nix_to_w32 ARG
31107b5038d7SDag-Erling Smørgrav# Convert file name ARG from *nix to w32 format.  Requires a wine environment
31117b5038d7SDag-Erling Smørgrav# and a working winepath. Returns result in func_to_host_file_result.
31127b5038d7SDag-Erling Smørgravfunc_convert_file_nix_to_w32 ()
31137b5038d7SDag-Erling Smørgrav{
3114986ba33cSDag-Erling Smørgrav  $debug_cmd
3115986ba33cSDag-Erling Smørgrav
3116986ba33cSDag-Erling Smørgrav  func_to_host_file_result=$1
31177b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
31187b5038d7SDag-Erling Smørgrav    func_convert_core_file_wine_to_w32 "$1"
3119986ba33cSDag-Erling Smørgrav    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result
31207b5038d7SDag-Erling Smørgrav  fi
31217b5038d7SDag-Erling Smørgrav  func_convert_file_check "$1" "$func_to_host_file_result"
31227b5038d7SDag-Erling Smørgrav}
31237b5038d7SDag-Erling Smørgrav# end func_convert_file_nix_to_w32
31247b5038d7SDag-Erling Smørgrav
31257b5038d7SDag-Erling Smørgrav
31267b5038d7SDag-Erling Smørgrav# func_convert_file_msys_to_cygwin ARG
31277b5038d7SDag-Erling Smørgrav# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
31287b5038d7SDag-Erling Smørgrav# Returns result in func_to_host_file_result.
31297b5038d7SDag-Erling Smørgravfunc_convert_file_msys_to_cygwin ()
31307b5038d7SDag-Erling Smørgrav{
3131986ba33cSDag-Erling Smørgrav  $debug_cmd
3132986ba33cSDag-Erling Smørgrav
3133986ba33cSDag-Erling Smørgrav  func_to_host_file_result=$1
31347b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
31357b5038d7SDag-Erling Smørgrav    func_convert_core_msys_to_w32 "$1"
31367b5038d7SDag-Erling Smørgrav    func_cygpath -u "$func_convert_core_msys_to_w32_result"
3137986ba33cSDag-Erling Smørgrav    func_to_host_file_result=$func_cygpath_result
31387b5038d7SDag-Erling Smørgrav  fi
31397b5038d7SDag-Erling Smørgrav  func_convert_file_check "$1" "$func_to_host_file_result"
31407b5038d7SDag-Erling Smørgrav}
31417b5038d7SDag-Erling Smørgrav# end func_convert_file_msys_to_cygwin
31427b5038d7SDag-Erling Smørgrav
31437b5038d7SDag-Erling Smørgrav
31447b5038d7SDag-Erling Smørgrav# func_convert_file_nix_to_cygwin ARG
31457b5038d7SDag-Erling Smørgrav# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed
31467b5038d7SDag-Erling Smørgrav# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result
31477b5038d7SDag-Erling Smørgrav# in func_to_host_file_result.
31487b5038d7SDag-Erling Smørgravfunc_convert_file_nix_to_cygwin ()
31497b5038d7SDag-Erling Smørgrav{
3150986ba33cSDag-Erling Smørgrav  $debug_cmd
3151986ba33cSDag-Erling Smørgrav
3152986ba33cSDag-Erling Smørgrav  func_to_host_file_result=$1
31537b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
31547b5038d7SDag-Erling Smørgrav    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.
31557b5038d7SDag-Erling Smørgrav    func_convert_core_file_wine_to_w32 "$1"
31567b5038d7SDag-Erling Smørgrav    func_cygpath -u "$func_convert_core_file_wine_to_w32_result"
3157986ba33cSDag-Erling Smørgrav    func_to_host_file_result=$func_cygpath_result
31587b5038d7SDag-Erling Smørgrav  fi
31597b5038d7SDag-Erling Smørgrav  func_convert_file_check "$1" "$func_to_host_file_result"
31607b5038d7SDag-Erling Smørgrav}
31617b5038d7SDag-Erling Smørgrav# end func_convert_file_nix_to_cygwin
31627b5038d7SDag-Erling Smørgrav
31637b5038d7SDag-Erling Smørgrav
31647b5038d7SDag-Erling Smørgrav#############################################
31657b5038d7SDag-Erling Smørgrav# $build to $host PATH CONVERSION FUNCTIONS #
31667b5038d7SDag-Erling Smørgrav#############################################
3167986ba33cSDag-Erling Smørgrav# invoked via '$to_host_path_cmd ARG'
31687b5038d7SDag-Erling Smørgrav#
31697b5038d7SDag-Erling Smørgrav# In each case, ARG is the path to be converted from $build to $host format.
31707b5038d7SDag-Erling Smørgrav# The result will be available in $func_to_host_path_result.
31717b5038d7SDag-Erling Smørgrav#
31727b5038d7SDag-Erling Smørgrav# Path separators are also converted from $build format to $host format.  If
31737b5038d7SDag-Erling Smørgrav# ARG begins or ends with a path separator character, it is preserved (but
31747b5038d7SDag-Erling Smørgrav# converted to $host format) on output.
31757b5038d7SDag-Erling Smørgrav#
31767b5038d7SDag-Erling Smørgrav# All path conversion functions are named using the following convention:
31777b5038d7SDag-Erling Smørgrav#   file name conversion function    : func_convert_file_X_to_Y ()
31787b5038d7SDag-Erling Smørgrav#   path conversion function         : func_convert_path_X_to_Y ()
31797b5038d7SDag-Erling Smørgrav# where, for any given $build/$host combination the 'X_to_Y' value is the
31807b5038d7SDag-Erling Smørgrav# same.  If conversion functions are added for new $build/$host combinations,
31817b5038d7SDag-Erling Smørgrav# the two new functions must follow this pattern, or func_init_to_host_path_cmd
31827b5038d7SDag-Erling Smørgrav# will break.
31837b5038d7SDag-Erling Smørgrav
31847b5038d7SDag-Erling Smørgrav
31857b5038d7SDag-Erling Smørgrav# func_init_to_host_path_cmd
31867b5038d7SDag-Erling Smørgrav# Ensures that function "pointer" variable $to_host_path_cmd is set to the
31877b5038d7SDag-Erling Smørgrav# appropriate value, based on the value of $to_host_file_cmd.
31887b5038d7SDag-Erling Smørgravto_host_path_cmd=
31897b5038d7SDag-Erling Smørgravfunc_init_to_host_path_cmd ()
31907b5038d7SDag-Erling Smørgrav{
3191986ba33cSDag-Erling Smørgrav  $debug_cmd
3192986ba33cSDag-Erling Smørgrav
31937b5038d7SDag-Erling Smørgrav  if test -z "$to_host_path_cmd"; then
31947b5038d7SDag-Erling Smørgrav    func_stripname 'func_convert_file_' '' "$to_host_file_cmd"
3195986ba33cSDag-Erling Smørgrav    to_host_path_cmd=func_convert_path_$func_stripname_result
31967b5038d7SDag-Erling Smørgrav  fi
31977b5038d7SDag-Erling Smørgrav}
31987b5038d7SDag-Erling Smørgrav
31997b5038d7SDag-Erling Smørgrav
32007b5038d7SDag-Erling Smørgrav# func_to_host_path ARG
32017b5038d7SDag-Erling Smørgrav# Converts the path ARG from $build format to $host format. Return result
32027b5038d7SDag-Erling Smørgrav# in func_to_host_path_result.
32037b5038d7SDag-Erling Smørgravfunc_to_host_path ()
32047b5038d7SDag-Erling Smørgrav{
3205986ba33cSDag-Erling Smørgrav  $debug_cmd
3206986ba33cSDag-Erling Smørgrav
32077b5038d7SDag-Erling Smørgrav  func_init_to_host_path_cmd
32087b5038d7SDag-Erling Smørgrav  $to_host_path_cmd "$1"
32097b5038d7SDag-Erling Smørgrav}
32107b5038d7SDag-Erling Smørgrav# end func_to_host_path
32117b5038d7SDag-Erling Smørgrav
32127b5038d7SDag-Erling Smørgrav
32137b5038d7SDag-Erling Smørgrav# func_convert_path_noop ARG
32147b5038d7SDag-Erling Smørgrav# Copy ARG to func_to_host_path_result.
32157b5038d7SDag-Erling Smørgravfunc_convert_path_noop ()
32167b5038d7SDag-Erling Smørgrav{
3217986ba33cSDag-Erling Smørgrav  func_to_host_path_result=$1
32187b5038d7SDag-Erling Smørgrav}
32197b5038d7SDag-Erling Smørgrav# end func_convert_path_noop
32207b5038d7SDag-Erling Smørgrav
32217b5038d7SDag-Erling Smørgrav
32227b5038d7SDag-Erling Smørgrav# func_convert_path_msys_to_w32 ARG
32237b5038d7SDag-Erling Smørgrav# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic
32247b5038d7SDag-Erling Smørgrav# conversion to w32 is not available inside the cwrapper.  Returns result in
32257b5038d7SDag-Erling Smørgrav# func_to_host_path_result.
32267b5038d7SDag-Erling Smørgravfunc_convert_path_msys_to_w32 ()
32277b5038d7SDag-Erling Smørgrav{
3228986ba33cSDag-Erling Smørgrav  $debug_cmd
3229986ba33cSDag-Erling Smørgrav
3230986ba33cSDag-Erling Smørgrav  func_to_host_path_result=$1
32317b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
32327b5038d7SDag-Erling Smørgrav    # Remove leading and trailing path separator characters from ARG.  MSYS
32337b5038d7SDag-Erling Smørgrav    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';
32347b5038d7SDag-Erling Smørgrav    # and winepath ignores them completely.
32357b5038d7SDag-Erling Smørgrav    func_stripname : : "$1"
32367b5038d7SDag-Erling Smørgrav    func_to_host_path_tmp1=$func_stripname_result
32377b5038d7SDag-Erling Smørgrav    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
3238986ba33cSDag-Erling Smørgrav    func_to_host_path_result=$func_convert_core_msys_to_w32_result
32397b5038d7SDag-Erling Smørgrav    func_convert_path_check : ";" \
32407b5038d7SDag-Erling Smørgrav      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32417b5038d7SDag-Erling Smørgrav    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
32427b5038d7SDag-Erling Smørgrav  fi
32437b5038d7SDag-Erling Smørgrav}
32447b5038d7SDag-Erling Smørgrav# end func_convert_path_msys_to_w32
32457b5038d7SDag-Erling Smørgrav
32467b5038d7SDag-Erling Smørgrav
32477b5038d7SDag-Erling Smørgrav# func_convert_path_cygwin_to_w32 ARG
32487b5038d7SDag-Erling Smørgrav# Convert path ARG from Cygwin to w32 format.  Returns result in
32497b5038d7SDag-Erling Smørgrav# func_to_host_file_result.
32507b5038d7SDag-Erling Smørgravfunc_convert_path_cygwin_to_w32 ()
32517b5038d7SDag-Erling Smørgrav{
3252986ba33cSDag-Erling Smørgrav  $debug_cmd
3253986ba33cSDag-Erling Smørgrav
3254986ba33cSDag-Erling Smørgrav  func_to_host_path_result=$1
32557b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
32567b5038d7SDag-Erling Smørgrav    # See func_convert_path_msys_to_w32:
32577b5038d7SDag-Erling Smørgrav    func_stripname : : "$1"
32587b5038d7SDag-Erling Smørgrav    func_to_host_path_tmp1=$func_stripname_result
32597b5038d7SDag-Erling Smørgrav    func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"`
32607b5038d7SDag-Erling Smørgrav    func_convert_path_check : ";" \
32617b5038d7SDag-Erling Smørgrav      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32627b5038d7SDag-Erling Smørgrav    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
32637b5038d7SDag-Erling Smørgrav  fi
32647b5038d7SDag-Erling Smørgrav}
32657b5038d7SDag-Erling Smørgrav# end func_convert_path_cygwin_to_w32
32667b5038d7SDag-Erling Smørgrav
32677b5038d7SDag-Erling Smørgrav
32687b5038d7SDag-Erling Smørgrav# func_convert_path_nix_to_w32 ARG
32697b5038d7SDag-Erling Smørgrav# Convert path ARG from *nix to w32 format.  Requires a wine environment and
32707b5038d7SDag-Erling Smørgrav# a working winepath.  Returns result in func_to_host_file_result.
32717b5038d7SDag-Erling Smørgravfunc_convert_path_nix_to_w32 ()
32727b5038d7SDag-Erling Smørgrav{
3273986ba33cSDag-Erling Smørgrav  $debug_cmd
3274986ba33cSDag-Erling Smørgrav
3275986ba33cSDag-Erling Smørgrav  func_to_host_path_result=$1
32767b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
32777b5038d7SDag-Erling Smørgrav    # See func_convert_path_msys_to_w32:
32787b5038d7SDag-Erling Smørgrav    func_stripname : : "$1"
32797b5038d7SDag-Erling Smørgrav    func_to_host_path_tmp1=$func_stripname_result
32807b5038d7SDag-Erling Smørgrav    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
3281986ba33cSDag-Erling Smørgrav    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result
32827b5038d7SDag-Erling Smørgrav    func_convert_path_check : ";" \
32837b5038d7SDag-Erling Smørgrav      "$func_to_host_path_tmp1" "$func_to_host_path_result"
32847b5038d7SDag-Erling Smørgrav    func_convert_path_front_back_pathsep ":*" "*:" ";" "$1"
32857b5038d7SDag-Erling Smørgrav  fi
32867b5038d7SDag-Erling Smørgrav}
32877b5038d7SDag-Erling Smørgrav# end func_convert_path_nix_to_w32
32887b5038d7SDag-Erling Smørgrav
32897b5038d7SDag-Erling Smørgrav
32907b5038d7SDag-Erling Smørgrav# func_convert_path_msys_to_cygwin ARG
32917b5038d7SDag-Erling Smørgrav# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.
32927b5038d7SDag-Erling Smørgrav# Returns result in func_to_host_file_result.
32937b5038d7SDag-Erling Smørgravfunc_convert_path_msys_to_cygwin ()
32947b5038d7SDag-Erling Smørgrav{
3295986ba33cSDag-Erling Smørgrav  $debug_cmd
3296986ba33cSDag-Erling Smørgrav
3297986ba33cSDag-Erling Smørgrav  func_to_host_path_result=$1
32987b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
32997b5038d7SDag-Erling Smørgrav    # See func_convert_path_msys_to_w32:
33007b5038d7SDag-Erling Smørgrav    func_stripname : : "$1"
33017b5038d7SDag-Erling Smørgrav    func_to_host_path_tmp1=$func_stripname_result
33027b5038d7SDag-Erling Smørgrav    func_convert_core_msys_to_w32 "$func_to_host_path_tmp1"
33037b5038d7SDag-Erling Smørgrav    func_cygpath -u -p "$func_convert_core_msys_to_w32_result"
3304986ba33cSDag-Erling Smørgrav    func_to_host_path_result=$func_cygpath_result
33057b5038d7SDag-Erling Smørgrav    func_convert_path_check : : \
33067b5038d7SDag-Erling Smørgrav      "$func_to_host_path_tmp1" "$func_to_host_path_result"
33077b5038d7SDag-Erling Smørgrav    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
33087b5038d7SDag-Erling Smørgrav  fi
33097b5038d7SDag-Erling Smørgrav}
33107b5038d7SDag-Erling Smørgrav# end func_convert_path_msys_to_cygwin
33117b5038d7SDag-Erling Smørgrav
33127b5038d7SDag-Erling Smørgrav
33137b5038d7SDag-Erling Smørgrav# func_convert_path_nix_to_cygwin ARG
33147b5038d7SDag-Erling Smørgrav# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a
33157b5038d7SDag-Erling Smørgrav# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in
33167b5038d7SDag-Erling Smørgrav# func_to_host_file_result.
33177b5038d7SDag-Erling Smørgravfunc_convert_path_nix_to_cygwin ()
33187b5038d7SDag-Erling Smørgrav{
3319986ba33cSDag-Erling Smørgrav  $debug_cmd
3320986ba33cSDag-Erling Smørgrav
3321986ba33cSDag-Erling Smørgrav  func_to_host_path_result=$1
33227b5038d7SDag-Erling Smørgrav  if test -n "$1"; then
33237b5038d7SDag-Erling Smørgrav    # Remove leading and trailing path separator characters from
33247b5038d7SDag-Erling Smørgrav    # ARG. msys behavior is inconsistent here, cygpath turns them
33257b5038d7SDag-Erling Smørgrav    # into '.;' and ';.', and winepath ignores them completely.
33267b5038d7SDag-Erling Smørgrav    func_stripname : : "$1"
33277b5038d7SDag-Erling Smørgrav    func_to_host_path_tmp1=$func_stripname_result
33287b5038d7SDag-Erling Smørgrav    func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1"
33297b5038d7SDag-Erling Smørgrav    func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result"
3330986ba33cSDag-Erling Smørgrav    func_to_host_path_result=$func_cygpath_result
33317b5038d7SDag-Erling Smørgrav    func_convert_path_check : : \
33327b5038d7SDag-Erling Smørgrav      "$func_to_host_path_tmp1" "$func_to_host_path_result"
33337b5038d7SDag-Erling Smørgrav    func_convert_path_front_back_pathsep ":*" "*:" : "$1"
33347b5038d7SDag-Erling Smørgrav  fi
33357b5038d7SDag-Erling Smørgrav}
33367b5038d7SDag-Erling Smørgrav# end func_convert_path_nix_to_cygwin
33377b5038d7SDag-Erling Smørgrav
33387b5038d7SDag-Erling Smørgrav
3339986ba33cSDag-Erling Smørgrav# func_dll_def_p FILE
3340986ba33cSDag-Erling Smørgrav# True iff FILE is a Windows DLL '.def' file.
3341986ba33cSDag-Erling Smørgrav# Keep in sync with _LT_DLL_DEF_P in libtool.m4
3342986ba33cSDag-Erling Smørgravfunc_dll_def_p ()
3343986ba33cSDag-Erling Smørgrav{
3344986ba33cSDag-Erling Smørgrav  $debug_cmd
3345986ba33cSDag-Erling Smørgrav
3346986ba33cSDag-Erling Smørgrav  func_dll_def_p_tmp=`$SED -n \
3347986ba33cSDag-Erling Smørgrav    -e 's/^[	 ]*//' \
3348986ba33cSDag-Erling Smørgrav    -e '/^\(;.*\)*$/d' \
3349986ba33cSDag-Erling Smørgrav    -e 's/^\(EXPORTS\|LIBRARY\)\([	 ].*\)*$/DEF/p' \
3350986ba33cSDag-Erling Smørgrav    -e q \
3351986ba33cSDag-Erling Smørgrav    "$1"`
3352986ba33cSDag-Erling Smørgrav  test DEF = "$func_dll_def_p_tmp"
3353986ba33cSDag-Erling Smørgrav}
3354986ba33cSDag-Erling Smørgrav
3355986ba33cSDag-Erling Smørgrav
33567b5038d7SDag-Erling Smørgrav# func_mode_compile arg...
33577b5038d7SDag-Erling Smørgravfunc_mode_compile ()
33587b5038d7SDag-Erling Smørgrav{
3359986ba33cSDag-Erling Smørgrav    $debug_cmd
3360986ba33cSDag-Erling Smørgrav
33617b5038d7SDag-Erling Smørgrav    # Get the compilation command and the source file.
33627b5038d7SDag-Erling Smørgrav    base_compile=
3363986ba33cSDag-Erling Smørgrav    srcfile=$nonopt  #  always keep a non-empty value in "srcfile"
33647b5038d7SDag-Erling Smørgrav    suppress_opt=yes
33657b5038d7SDag-Erling Smørgrav    suppress_output=
33667b5038d7SDag-Erling Smørgrav    arg_mode=normal
33677b5038d7SDag-Erling Smørgrav    libobj=
33687b5038d7SDag-Erling Smørgrav    later=
33697b5038d7SDag-Erling Smørgrav    pie_flag=
33707b5038d7SDag-Erling Smørgrav
33717b5038d7SDag-Erling Smørgrav    for arg
33727b5038d7SDag-Erling Smørgrav    do
33737b5038d7SDag-Erling Smørgrav      case $arg_mode in
33747b5038d7SDag-Erling Smørgrav      arg  )
33757b5038d7SDag-Erling Smørgrav	# do not "continue".  Instead, add this to base_compile
3376986ba33cSDag-Erling Smørgrav	lastarg=$arg
33777b5038d7SDag-Erling Smørgrav	arg_mode=normal
33787b5038d7SDag-Erling Smørgrav	;;
33797b5038d7SDag-Erling Smørgrav
33807b5038d7SDag-Erling Smørgrav      target )
3381986ba33cSDag-Erling Smørgrav	libobj=$arg
33827b5038d7SDag-Erling Smørgrav	arg_mode=normal
33837b5038d7SDag-Erling Smørgrav	continue
33847b5038d7SDag-Erling Smørgrav	;;
33857b5038d7SDag-Erling Smørgrav
33867b5038d7SDag-Erling Smørgrav      normal )
33877b5038d7SDag-Erling Smørgrav	# Accept any command-line options.
33887b5038d7SDag-Erling Smørgrav	case $arg in
33897b5038d7SDag-Erling Smørgrav	-o)
33907b5038d7SDag-Erling Smørgrav	  test -n "$libobj" && \
3391986ba33cSDag-Erling Smørgrav	    func_fatal_error "you cannot specify '-o' more than once"
33927b5038d7SDag-Erling Smørgrav	  arg_mode=target
33937b5038d7SDag-Erling Smørgrav	  continue
33947b5038d7SDag-Erling Smørgrav	  ;;
33957b5038d7SDag-Erling Smørgrav
33967b5038d7SDag-Erling Smørgrav	-pie | -fpie | -fPIE)
33977b5038d7SDag-Erling Smørgrav          func_append pie_flag " $arg"
33987b5038d7SDag-Erling Smørgrav	  continue
33997b5038d7SDag-Erling Smørgrav	  ;;
34007b5038d7SDag-Erling Smørgrav
34017b5038d7SDag-Erling Smørgrav	-shared | -static | -prefer-pic | -prefer-non-pic)
34027b5038d7SDag-Erling Smørgrav	  func_append later " $arg"
34037b5038d7SDag-Erling Smørgrav	  continue
34047b5038d7SDag-Erling Smørgrav	  ;;
34057b5038d7SDag-Erling Smørgrav
34067b5038d7SDag-Erling Smørgrav	-no-suppress)
34077b5038d7SDag-Erling Smørgrav	  suppress_opt=no
34087b5038d7SDag-Erling Smørgrav	  continue
34097b5038d7SDag-Erling Smørgrav	  ;;
34107b5038d7SDag-Erling Smørgrav
34117b5038d7SDag-Erling Smørgrav	-Xcompiler)
34127b5038d7SDag-Erling Smørgrav	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
34137b5038d7SDag-Erling Smørgrav	  continue      #  The current "srcfile" will either be retained or
34147b5038d7SDag-Erling Smørgrav	  ;;            #  replaced later.  I would guess that would be a bug.
34157b5038d7SDag-Erling Smørgrav
34167b5038d7SDag-Erling Smørgrav	-Wc,*)
34177b5038d7SDag-Erling Smørgrav	  func_stripname '-Wc,' '' "$arg"
34187b5038d7SDag-Erling Smørgrav	  args=$func_stripname_result
34197b5038d7SDag-Erling Smørgrav	  lastarg=
3420986ba33cSDag-Erling Smørgrav	  save_ifs=$IFS; IFS=,
34217b5038d7SDag-Erling Smørgrav	  for arg in $args; do
3422986ba33cSDag-Erling Smørgrav	    IFS=$save_ifs
34237b5038d7SDag-Erling Smørgrav	    func_append_quoted lastarg "$arg"
34247b5038d7SDag-Erling Smørgrav	  done
3425986ba33cSDag-Erling Smørgrav	  IFS=$save_ifs
34267b5038d7SDag-Erling Smørgrav	  func_stripname ' ' '' "$lastarg"
34277b5038d7SDag-Erling Smørgrav	  lastarg=$func_stripname_result
34287b5038d7SDag-Erling Smørgrav
34297b5038d7SDag-Erling Smørgrav	  # Add the arguments to base_compile.
34307b5038d7SDag-Erling Smørgrav	  func_append base_compile " $lastarg"
34317b5038d7SDag-Erling Smørgrav	  continue
34327b5038d7SDag-Erling Smørgrav	  ;;
34337b5038d7SDag-Erling Smørgrav
34347b5038d7SDag-Erling Smørgrav	*)
34357b5038d7SDag-Erling Smørgrav	  # Accept the current argument as the source file.
34367b5038d7SDag-Erling Smørgrav	  # The previous "srcfile" becomes the current argument.
34377b5038d7SDag-Erling Smørgrav	  #
3438986ba33cSDag-Erling Smørgrav	  lastarg=$srcfile
3439986ba33cSDag-Erling Smørgrav	  srcfile=$arg
34407b5038d7SDag-Erling Smørgrav	  ;;
34417b5038d7SDag-Erling Smørgrav	esac  #  case $arg
34427b5038d7SDag-Erling Smørgrav	;;
34437b5038d7SDag-Erling Smørgrav      esac    #  case $arg_mode
34447b5038d7SDag-Erling Smørgrav
34457b5038d7SDag-Erling Smørgrav      # Aesthetically quote the previous argument.
34467b5038d7SDag-Erling Smørgrav      func_append_quoted base_compile "$lastarg"
34477b5038d7SDag-Erling Smørgrav    done # for arg
34487b5038d7SDag-Erling Smørgrav
34497b5038d7SDag-Erling Smørgrav    case $arg_mode in
34507b5038d7SDag-Erling Smørgrav    arg)
34517b5038d7SDag-Erling Smørgrav      func_fatal_error "you must specify an argument for -Xcompile"
34527b5038d7SDag-Erling Smørgrav      ;;
34537b5038d7SDag-Erling Smørgrav    target)
3454986ba33cSDag-Erling Smørgrav      func_fatal_error "you must specify a target with '-o'"
34557b5038d7SDag-Erling Smørgrav      ;;
34567b5038d7SDag-Erling Smørgrav    *)
34577b5038d7SDag-Erling Smørgrav      # Get the name of the library object.
34587b5038d7SDag-Erling Smørgrav      test -z "$libobj" && {
34597b5038d7SDag-Erling Smørgrav	func_basename "$srcfile"
3460986ba33cSDag-Erling Smørgrav	libobj=$func_basename_result
34617b5038d7SDag-Erling Smørgrav      }
34627b5038d7SDag-Erling Smørgrav      ;;
34637b5038d7SDag-Erling Smørgrav    esac
34647b5038d7SDag-Erling Smørgrav
34657b5038d7SDag-Erling Smørgrav    # Recognize several different file suffixes.
34667b5038d7SDag-Erling Smørgrav    # If the user specifies -o file.o, it is replaced with file.lo
34677b5038d7SDag-Erling Smørgrav    case $libobj in
34687b5038d7SDag-Erling Smørgrav    *.[cCFSifmso] | \
34697b5038d7SDag-Erling Smørgrav    *.ada | *.adb | *.ads | *.asm | \
34707b5038d7SDag-Erling Smørgrav    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \
34717b5038d7SDag-Erling Smørgrav    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)
34727b5038d7SDag-Erling Smørgrav      func_xform "$libobj"
34737b5038d7SDag-Erling Smørgrav      libobj=$func_xform_result
34747b5038d7SDag-Erling Smørgrav      ;;
34757b5038d7SDag-Erling Smørgrav    esac
34767b5038d7SDag-Erling Smørgrav
34777b5038d7SDag-Erling Smørgrav    case $libobj in
34787b5038d7SDag-Erling Smørgrav    *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;;
34797b5038d7SDag-Erling Smørgrav    *)
3480986ba33cSDag-Erling Smørgrav      func_fatal_error "cannot determine name of library object from '$libobj'"
34817b5038d7SDag-Erling Smørgrav      ;;
34827b5038d7SDag-Erling Smørgrav    esac
34837b5038d7SDag-Erling Smørgrav
34847b5038d7SDag-Erling Smørgrav    func_infer_tag $base_compile
34857b5038d7SDag-Erling Smørgrav
34867b5038d7SDag-Erling Smørgrav    for arg in $later; do
34877b5038d7SDag-Erling Smørgrav      case $arg in
34887b5038d7SDag-Erling Smørgrav      -shared)
3489986ba33cSDag-Erling Smørgrav	test yes = "$build_libtool_libs" \
3490986ba33cSDag-Erling Smørgrav	  || func_fatal_configuration "cannot build a shared library"
34917b5038d7SDag-Erling Smørgrav	build_old_libs=no
34927b5038d7SDag-Erling Smørgrav	continue
34937b5038d7SDag-Erling Smørgrav	;;
34947b5038d7SDag-Erling Smørgrav
34957b5038d7SDag-Erling Smørgrav      -static)
34967b5038d7SDag-Erling Smørgrav	build_libtool_libs=no
34977b5038d7SDag-Erling Smørgrav	build_old_libs=yes
34987b5038d7SDag-Erling Smørgrav	continue
34997b5038d7SDag-Erling Smørgrav	;;
35007b5038d7SDag-Erling Smørgrav
35017b5038d7SDag-Erling Smørgrav      -prefer-pic)
35027b5038d7SDag-Erling Smørgrav	pic_mode=yes
35037b5038d7SDag-Erling Smørgrav	continue
35047b5038d7SDag-Erling Smørgrav	;;
35057b5038d7SDag-Erling Smørgrav
35067b5038d7SDag-Erling Smørgrav      -prefer-non-pic)
35077b5038d7SDag-Erling Smørgrav	pic_mode=no
35087b5038d7SDag-Erling Smørgrav	continue
35097b5038d7SDag-Erling Smørgrav	;;
35107b5038d7SDag-Erling Smørgrav      esac
35117b5038d7SDag-Erling Smørgrav    done
35127b5038d7SDag-Erling Smørgrav
35137b5038d7SDag-Erling Smørgrav    func_quote_for_eval "$libobj"
35147b5038d7SDag-Erling Smørgrav    test "X$libobj" != "X$func_quote_for_eval_result" \
35157b5038d7SDag-Erling Smørgrav      && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"'	 &()|`$[]' \
3516986ba33cSDag-Erling Smørgrav      && func_warning "libobj name '$libobj' may not contain shell special characters."
35177b5038d7SDag-Erling Smørgrav    func_dirname_and_basename "$obj" "/" ""
3518986ba33cSDag-Erling Smørgrav    objname=$func_basename_result
3519986ba33cSDag-Erling Smørgrav    xdir=$func_dirname_result
3520986ba33cSDag-Erling Smørgrav    lobj=$xdir$objdir/$objname
35217b5038d7SDag-Erling Smørgrav
35227b5038d7SDag-Erling Smørgrav    test -z "$base_compile" && \
35237b5038d7SDag-Erling Smørgrav      func_fatal_help "you must specify a compilation command"
35247b5038d7SDag-Erling Smørgrav
35257b5038d7SDag-Erling Smørgrav    # Delete any leftover library objects.
3526986ba33cSDag-Erling Smørgrav    if test yes = "$build_old_libs"; then
35277b5038d7SDag-Erling Smørgrav      removelist="$obj $lobj $libobj ${libobj}T"
35287b5038d7SDag-Erling Smørgrav    else
35297b5038d7SDag-Erling Smørgrav      removelist="$lobj $libobj ${libobj}T"
35307b5038d7SDag-Erling Smørgrav    fi
35317b5038d7SDag-Erling Smørgrav
35327b5038d7SDag-Erling Smørgrav    # On Cygwin there's no "real" PIC flag so we must build both object types
35337b5038d7SDag-Erling Smørgrav    case $host_os in
35347b5038d7SDag-Erling Smørgrav    cygwin* | mingw* | pw32* | os2* | cegcc*)
35357b5038d7SDag-Erling Smørgrav      pic_mode=default
35367b5038d7SDag-Erling Smørgrav      ;;
35377b5038d7SDag-Erling Smørgrav    esac
3538986ba33cSDag-Erling Smørgrav    if test no = "$pic_mode" && test pass_all != "$deplibs_check_method"; then
35397b5038d7SDag-Erling Smørgrav      # non-PIC code in shared libraries is not supported
35407b5038d7SDag-Erling Smørgrav      pic_mode=default
35417b5038d7SDag-Erling Smørgrav    fi
35427b5038d7SDag-Erling Smørgrav
35437b5038d7SDag-Erling Smørgrav    # Calculate the filename of the output object if compiler does
35447b5038d7SDag-Erling Smørgrav    # not support -o with -c
3545986ba33cSDag-Erling Smørgrav    if test no = "$compiler_c_o"; then
3546986ba33cSDag-Erling Smørgrav      output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.$objext
3547986ba33cSDag-Erling Smørgrav      lockfile=$output_obj.lock
35487b5038d7SDag-Erling Smørgrav    else
35497b5038d7SDag-Erling Smørgrav      output_obj=
35507b5038d7SDag-Erling Smørgrav      need_locks=no
35517b5038d7SDag-Erling Smørgrav      lockfile=
35527b5038d7SDag-Erling Smørgrav    fi
35537b5038d7SDag-Erling Smørgrav
35547b5038d7SDag-Erling Smørgrav    # Lock this critical section if it is needed
35557b5038d7SDag-Erling Smørgrav    # We use this script file to make the link, it avoids creating a new file
3556986ba33cSDag-Erling Smørgrav    if test yes = "$need_locks"; then
35577b5038d7SDag-Erling Smørgrav      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
35587b5038d7SDag-Erling Smørgrav	func_echo "Waiting for $lockfile to be removed"
35597b5038d7SDag-Erling Smørgrav	sleep 2
35607b5038d7SDag-Erling Smørgrav      done
3561986ba33cSDag-Erling Smørgrav    elif test warn = "$need_locks"; then
35627b5038d7SDag-Erling Smørgrav      if test -f "$lockfile"; then
35637b5038d7SDag-Erling Smørgrav	$ECHO "\
35647b5038d7SDag-Erling Smørgrav*** ERROR, $lockfile exists and contains:
35657b5038d7SDag-Erling Smørgrav`cat $lockfile 2>/dev/null`
35667b5038d7SDag-Erling Smørgrav
35677b5038d7SDag-Erling SmørgravThis indicates that another process is trying to use the same
35687b5038d7SDag-Erling Smørgravtemporary object file, and libtool could not work around it because
3569986ba33cSDag-Erling Smørgravyour compiler does not support '-c' and '-o' together.  If you
35707b5038d7SDag-Erling Smørgravrepeat this compilation, it may succeed, by chance, but you had better
35717b5038d7SDag-Erling Smørgravavoid parallel builds (make -j) in this platform, or get a better
35727b5038d7SDag-Erling Smørgravcompiler."
35737b5038d7SDag-Erling Smørgrav
35747b5038d7SDag-Erling Smørgrav	$opt_dry_run || $RM $removelist
35757b5038d7SDag-Erling Smørgrav	exit $EXIT_FAILURE
35767b5038d7SDag-Erling Smørgrav      fi
35777b5038d7SDag-Erling Smørgrav      func_append removelist " $output_obj"
35787b5038d7SDag-Erling Smørgrav      $ECHO "$srcfile" > "$lockfile"
35797b5038d7SDag-Erling Smørgrav    fi
35807b5038d7SDag-Erling Smørgrav
35817b5038d7SDag-Erling Smørgrav    $opt_dry_run || $RM $removelist
35827b5038d7SDag-Erling Smørgrav    func_append removelist " $lockfile"
35837b5038d7SDag-Erling Smørgrav    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15
35847b5038d7SDag-Erling Smørgrav
35857b5038d7SDag-Erling Smørgrav    func_to_tool_file "$srcfile" func_convert_file_msys_to_w32
35867b5038d7SDag-Erling Smørgrav    srcfile=$func_to_tool_file_result
35877b5038d7SDag-Erling Smørgrav    func_quote_for_eval "$srcfile"
35887b5038d7SDag-Erling Smørgrav    qsrcfile=$func_quote_for_eval_result
35897b5038d7SDag-Erling Smørgrav
35907b5038d7SDag-Erling Smørgrav    # Only build a PIC object if we are building libtool libraries.
3591986ba33cSDag-Erling Smørgrav    if test yes = "$build_libtool_libs"; then
35927b5038d7SDag-Erling Smørgrav      # Without this assignment, base_compile gets emptied.
35937b5038d7SDag-Erling Smørgrav      fbsd_hideous_sh_bug=$base_compile
35947b5038d7SDag-Erling Smørgrav
3595986ba33cSDag-Erling Smørgrav      if test no != "$pic_mode"; then
35967b5038d7SDag-Erling Smørgrav	command="$base_compile $qsrcfile $pic_flag"
35977b5038d7SDag-Erling Smørgrav      else
35987b5038d7SDag-Erling Smørgrav	# Don't build PIC code
35997b5038d7SDag-Erling Smørgrav	command="$base_compile $qsrcfile"
36007b5038d7SDag-Erling Smørgrav      fi
36017b5038d7SDag-Erling Smørgrav
36027b5038d7SDag-Erling Smørgrav      func_mkdir_p "$xdir$objdir"
36037b5038d7SDag-Erling Smørgrav
36047b5038d7SDag-Erling Smørgrav      if test -z "$output_obj"; then
36057b5038d7SDag-Erling Smørgrav	# Place PIC objects in $objdir
36067b5038d7SDag-Erling Smørgrav	func_append command " -o $lobj"
36077b5038d7SDag-Erling Smørgrav      fi
36087b5038d7SDag-Erling Smørgrav
36097b5038d7SDag-Erling Smørgrav      func_show_eval_locale "$command"	\
36107b5038d7SDag-Erling Smørgrav          'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE'
36117b5038d7SDag-Erling Smørgrav
3612986ba33cSDag-Erling Smørgrav      if test warn = "$need_locks" &&
36137b5038d7SDag-Erling Smørgrav	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
36147b5038d7SDag-Erling Smørgrav	$ECHO "\
36157b5038d7SDag-Erling Smørgrav*** ERROR, $lockfile contains:
36167b5038d7SDag-Erling Smørgrav`cat $lockfile 2>/dev/null`
36177b5038d7SDag-Erling Smørgrav
36187b5038d7SDag-Erling Smørgravbut it should contain:
36197b5038d7SDag-Erling Smørgrav$srcfile
36207b5038d7SDag-Erling Smørgrav
36217b5038d7SDag-Erling SmørgravThis indicates that another process is trying to use the same
36227b5038d7SDag-Erling Smørgravtemporary object file, and libtool could not work around it because
3623986ba33cSDag-Erling Smørgravyour compiler does not support '-c' and '-o' together.  If you
36247b5038d7SDag-Erling Smørgravrepeat this compilation, it may succeed, by chance, but you had better
36257b5038d7SDag-Erling Smørgravavoid parallel builds (make -j) in this platform, or get a better
36267b5038d7SDag-Erling Smørgravcompiler."
36277b5038d7SDag-Erling Smørgrav
36287b5038d7SDag-Erling Smørgrav	$opt_dry_run || $RM $removelist
36297b5038d7SDag-Erling Smørgrav	exit $EXIT_FAILURE
36307b5038d7SDag-Erling Smørgrav      fi
36317b5038d7SDag-Erling Smørgrav
36327b5038d7SDag-Erling Smørgrav      # Just move the object if needed, then go on to compile the next one
36337b5038d7SDag-Erling Smørgrav      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
36347b5038d7SDag-Erling Smørgrav	func_show_eval '$MV "$output_obj" "$lobj"' \
36357b5038d7SDag-Erling Smørgrav	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
36367b5038d7SDag-Erling Smørgrav      fi
36377b5038d7SDag-Erling Smørgrav
36387b5038d7SDag-Erling Smørgrav      # Allow error messages only from the first compilation.
3639986ba33cSDag-Erling Smørgrav      if test yes = "$suppress_opt"; then
36407b5038d7SDag-Erling Smørgrav	suppress_output=' >/dev/null 2>&1'
36417b5038d7SDag-Erling Smørgrav      fi
36427b5038d7SDag-Erling Smørgrav    fi
36437b5038d7SDag-Erling Smørgrav
36447b5038d7SDag-Erling Smørgrav    # Only build a position-dependent object if we build old libraries.
3645986ba33cSDag-Erling Smørgrav    if test yes = "$build_old_libs"; then
3646986ba33cSDag-Erling Smørgrav      if test yes != "$pic_mode"; then
36477b5038d7SDag-Erling Smørgrav	# Don't build PIC code
36487b5038d7SDag-Erling Smørgrav	command="$base_compile $qsrcfile$pie_flag"
36497b5038d7SDag-Erling Smørgrav      else
36507b5038d7SDag-Erling Smørgrav	command="$base_compile $qsrcfile $pic_flag"
36517b5038d7SDag-Erling Smørgrav      fi
3652986ba33cSDag-Erling Smørgrav      if test yes = "$compiler_c_o"; then
36537b5038d7SDag-Erling Smørgrav	func_append command " -o $obj"
36547b5038d7SDag-Erling Smørgrav      fi
36557b5038d7SDag-Erling Smørgrav
36567b5038d7SDag-Erling Smørgrav      # Suppress compiler output if we already did a PIC compilation.
36577b5038d7SDag-Erling Smørgrav      func_append command "$suppress_output"
36587b5038d7SDag-Erling Smørgrav      func_show_eval_locale "$command" \
36597b5038d7SDag-Erling Smørgrav        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'
36607b5038d7SDag-Erling Smørgrav
3661986ba33cSDag-Erling Smørgrav      if test warn = "$need_locks" &&
36627b5038d7SDag-Erling Smørgrav	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
36637b5038d7SDag-Erling Smørgrav	$ECHO "\
36647b5038d7SDag-Erling Smørgrav*** ERROR, $lockfile contains:
36657b5038d7SDag-Erling Smørgrav`cat $lockfile 2>/dev/null`
36667b5038d7SDag-Erling Smørgrav
36677b5038d7SDag-Erling Smørgravbut it should contain:
36687b5038d7SDag-Erling Smørgrav$srcfile
36697b5038d7SDag-Erling Smørgrav
36707b5038d7SDag-Erling SmørgravThis indicates that another process is trying to use the same
36717b5038d7SDag-Erling Smørgravtemporary object file, and libtool could not work around it because
3672986ba33cSDag-Erling Smørgravyour compiler does not support '-c' and '-o' together.  If you
36737b5038d7SDag-Erling Smørgravrepeat this compilation, it may succeed, by chance, but you had better
36747b5038d7SDag-Erling Smørgravavoid parallel builds (make -j) in this platform, or get a better
36757b5038d7SDag-Erling Smørgravcompiler."
36767b5038d7SDag-Erling Smørgrav
36777b5038d7SDag-Erling Smørgrav	$opt_dry_run || $RM $removelist
36787b5038d7SDag-Erling Smørgrav	exit $EXIT_FAILURE
36797b5038d7SDag-Erling Smørgrav      fi
36807b5038d7SDag-Erling Smørgrav
36817b5038d7SDag-Erling Smørgrav      # Just move the object if needed
36827b5038d7SDag-Erling Smørgrav      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
36837b5038d7SDag-Erling Smørgrav	func_show_eval '$MV "$output_obj" "$obj"' \
36847b5038d7SDag-Erling Smørgrav	  'error=$?; $opt_dry_run || $RM $removelist; exit $error'
36857b5038d7SDag-Erling Smørgrav      fi
36867b5038d7SDag-Erling Smørgrav    fi
36877b5038d7SDag-Erling Smørgrav
36887b5038d7SDag-Erling Smørgrav    $opt_dry_run || {
36897b5038d7SDag-Erling Smørgrav      func_write_libtool_object "$libobj" "$objdir/$objname" "$objname"
36907b5038d7SDag-Erling Smørgrav
36917b5038d7SDag-Erling Smørgrav      # Unlock the critical section if it was locked
3692986ba33cSDag-Erling Smørgrav      if test no != "$need_locks"; then
36937b5038d7SDag-Erling Smørgrav	removelist=$lockfile
36947b5038d7SDag-Erling Smørgrav        $RM "$lockfile"
36957b5038d7SDag-Erling Smørgrav      fi
36967b5038d7SDag-Erling Smørgrav    }
36977b5038d7SDag-Erling Smørgrav
36987b5038d7SDag-Erling Smørgrav    exit $EXIT_SUCCESS
36997b5038d7SDag-Erling Smørgrav}
37007b5038d7SDag-Erling Smørgrav
37017b5038d7SDag-Erling Smørgrav$opt_help || {
3702986ba33cSDag-Erling Smørgrav  test compile = "$opt_mode" && func_mode_compile ${1+"$@"}
37037b5038d7SDag-Erling Smørgrav}
37047b5038d7SDag-Erling Smørgrav
37057b5038d7SDag-Erling Smørgravfunc_mode_help ()
37067b5038d7SDag-Erling Smørgrav{
37077b5038d7SDag-Erling Smørgrav    # We need to display help for each of the modes.
37087b5038d7SDag-Erling Smørgrav    case $opt_mode in
37097b5038d7SDag-Erling Smørgrav      "")
37107b5038d7SDag-Erling Smørgrav        # Generic help is extracted from the usage comments
37117b5038d7SDag-Erling Smørgrav        # at the start of this file.
37127b5038d7SDag-Erling Smørgrav        func_help
37137b5038d7SDag-Erling Smørgrav        ;;
37147b5038d7SDag-Erling Smørgrav
37157b5038d7SDag-Erling Smørgrav      clean)
37167b5038d7SDag-Erling Smørgrav        $ECHO \
37177b5038d7SDag-Erling Smørgrav"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...
37187b5038d7SDag-Erling Smørgrav
37197b5038d7SDag-Erling SmørgravRemove files from the build directory.
37207b5038d7SDag-Erling Smørgrav
37217b5038d7SDag-Erling SmørgravRM is the name of the program to use to delete files associated with each FILE
3722986ba33cSDag-Erling Smørgrav(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
37237b5038d7SDag-Erling Smørgravto RM.
37247b5038d7SDag-Erling Smørgrav
37257b5038d7SDag-Erling SmørgravIf FILE is a libtool library, object or program, all the files associated
37267b5038d7SDag-Erling Smørgravwith it are deleted. Otherwise, only FILE itself is deleted using RM."
37277b5038d7SDag-Erling Smørgrav        ;;
37287b5038d7SDag-Erling Smørgrav
37297b5038d7SDag-Erling Smørgrav      compile)
37307b5038d7SDag-Erling Smørgrav      $ECHO \
37317b5038d7SDag-Erling Smørgrav"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE
37327b5038d7SDag-Erling Smørgrav
37337b5038d7SDag-Erling SmørgravCompile a source file into a libtool library object.
37347b5038d7SDag-Erling Smørgrav
37357b5038d7SDag-Erling SmørgravThis mode accepts the following additional options:
37367b5038d7SDag-Erling Smørgrav
37377b5038d7SDag-Erling Smørgrav  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE
37387b5038d7SDag-Erling Smørgrav  -no-suppress      do not suppress compiler output for multiple passes
37397b5038d7SDag-Erling Smørgrav  -prefer-pic       try to build PIC objects only
37407b5038d7SDag-Erling Smørgrav  -prefer-non-pic   try to build non-PIC objects only
3741986ba33cSDag-Erling Smørgrav  -shared           do not build a '.o' file suitable for static linking
3742986ba33cSDag-Erling Smørgrav  -static           only build a '.o' file suitable for static linking
37437b5038d7SDag-Erling Smørgrav  -Wc,FLAG          pass FLAG directly to the compiler
37447b5038d7SDag-Erling Smørgrav
3745986ba33cSDag-Erling SmørgravCOMPILE-COMMAND is a command to be used in creating a 'standard' object file
37467b5038d7SDag-Erling Smørgravfrom the given SOURCEFILE.
37477b5038d7SDag-Erling Smørgrav
37487b5038d7SDag-Erling SmørgravThe output file name is determined by removing the directory component from
3749986ba33cSDag-Erling SmørgravSOURCEFILE, then substituting the C source code suffix '.c' with the
3750986ba33cSDag-Erling Smørgravlibrary object suffix, '.lo'."
37517b5038d7SDag-Erling Smørgrav        ;;
37527b5038d7SDag-Erling Smørgrav
37537b5038d7SDag-Erling Smørgrav      execute)
37547b5038d7SDag-Erling Smørgrav        $ECHO \
37557b5038d7SDag-Erling Smørgrav"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...
37567b5038d7SDag-Erling Smørgrav
37577b5038d7SDag-Erling SmørgravAutomatically set library path, then run a program.
37587b5038d7SDag-Erling Smørgrav
37597b5038d7SDag-Erling SmørgravThis mode accepts the following additional options:
37607b5038d7SDag-Erling Smørgrav
37617b5038d7SDag-Erling Smørgrav  -dlopen FILE      add the directory containing FILE to the library path
37627b5038d7SDag-Erling Smørgrav
3763986ba33cSDag-Erling SmørgravThis mode sets the library path environment variable according to '-dlopen'
37647b5038d7SDag-Erling Smørgravflags.
37657b5038d7SDag-Erling Smørgrav
37667b5038d7SDag-Erling SmørgravIf any of the ARGS are libtool executable wrappers, then they are translated
37677b5038d7SDag-Erling Smørgravinto their corresponding uninstalled binary, and any of their required library
37687b5038d7SDag-Erling Smørgravdirectories are added to the library path.
37697b5038d7SDag-Erling Smørgrav
37707b5038d7SDag-Erling SmørgravThen, COMMAND is executed, with ARGS as arguments."
37717b5038d7SDag-Erling Smørgrav        ;;
37727b5038d7SDag-Erling Smørgrav
37737b5038d7SDag-Erling Smørgrav      finish)
37747b5038d7SDag-Erling Smørgrav        $ECHO \
37757b5038d7SDag-Erling Smørgrav"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...
37767b5038d7SDag-Erling Smørgrav
37777b5038d7SDag-Erling SmørgravComplete the installation of libtool libraries.
37787b5038d7SDag-Erling Smørgrav
37797b5038d7SDag-Erling SmørgravEach LIBDIR is a directory that contains libtool libraries.
37807b5038d7SDag-Erling Smørgrav
37817b5038d7SDag-Erling SmørgravThe commands that this mode executes may require superuser privileges.  Use
3782986ba33cSDag-Erling Smørgravthe '--dry-run' option if you just want to see what would be executed."
37837b5038d7SDag-Erling Smørgrav        ;;
37847b5038d7SDag-Erling Smørgrav
37857b5038d7SDag-Erling Smørgrav      install)
37867b5038d7SDag-Erling Smørgrav        $ECHO \
37877b5038d7SDag-Erling Smørgrav"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...
37887b5038d7SDag-Erling Smørgrav
37897b5038d7SDag-Erling SmørgravInstall executables or libraries.
37907b5038d7SDag-Erling Smørgrav
37917b5038d7SDag-Erling SmørgravINSTALL-COMMAND is the installation command.  The first component should be
3792986ba33cSDag-Erling Smørgraveither the 'install' or 'cp' program.
37937b5038d7SDag-Erling Smørgrav
37947b5038d7SDag-Erling SmørgravThe following components of INSTALL-COMMAND are treated specially:
37957b5038d7SDag-Erling Smørgrav
37967b5038d7SDag-Erling Smørgrav  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation
37977b5038d7SDag-Erling Smørgrav
37987b5038d7SDag-Erling SmørgravThe rest of the components are interpreted as arguments to that command (only
37997b5038d7SDag-Erling SmørgravBSD-compatible install options are recognized)."
38007b5038d7SDag-Erling Smørgrav        ;;
38017b5038d7SDag-Erling Smørgrav
38027b5038d7SDag-Erling Smørgrav      link)
38037b5038d7SDag-Erling Smørgrav        $ECHO \
38047b5038d7SDag-Erling Smørgrav"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...
38057b5038d7SDag-Erling Smørgrav
38067b5038d7SDag-Erling SmørgravLink object files or libraries together to form another library, or to
38077b5038d7SDag-Erling Smørgravcreate an executable program.
38087b5038d7SDag-Erling Smørgrav
38097b5038d7SDag-Erling SmørgravLINK-COMMAND is a command using the C compiler that you would use to create
38107b5038d7SDag-Erling Smørgrava program from several object files.
38117b5038d7SDag-Erling Smørgrav
38127b5038d7SDag-Erling SmørgravThe following components of LINK-COMMAND are treated specially:
38137b5038d7SDag-Erling Smørgrav
38147b5038d7SDag-Erling Smørgrav  -all-static       do not do any dynamic linking at all
38157b5038d7SDag-Erling Smørgrav  -avoid-version    do not add a version suffix if possible
38167b5038d7SDag-Erling Smørgrav  -bindir BINDIR    specify path to binaries directory (for systems where
38177b5038d7SDag-Erling Smørgrav                    libraries must be found in the PATH setting at runtime)
3818986ba33cSDag-Erling Smørgrav  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime
38197b5038d7SDag-Erling Smørgrav  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols
38207b5038d7SDag-Erling Smørgrav  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)
38217b5038d7SDag-Erling Smørgrav  -export-symbols SYMFILE
38227b5038d7SDag-Erling Smørgrav                    try to export only the symbols listed in SYMFILE
38237b5038d7SDag-Erling Smørgrav  -export-symbols-regex REGEX
38247b5038d7SDag-Erling Smørgrav                    try to export only the symbols matching REGEX
38257b5038d7SDag-Erling Smørgrav  -LLIBDIR          search LIBDIR for required installed libraries
38267b5038d7SDag-Erling Smørgrav  -lNAME            OUTPUT-FILE requires the installed library libNAME
38277b5038d7SDag-Erling Smørgrav  -module           build a library that can dlopened
38287b5038d7SDag-Erling Smørgrav  -no-fast-install  disable the fast-install mode
38297b5038d7SDag-Erling Smørgrav  -no-install       link a not-installable executable
38307b5038d7SDag-Erling Smørgrav  -no-undefined     declare that a library does not refer to external symbols
38317b5038d7SDag-Erling Smørgrav  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
3832986ba33cSDag-Erling Smørgrav  -objectlist FILE  use a list of object files found in FILE to specify objects
3833986ba33cSDag-Erling Smørgrav  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)
38347b5038d7SDag-Erling Smørgrav  -precious-files-regex REGEX
38357b5038d7SDag-Erling Smørgrav                    don't remove output files matching REGEX
38367b5038d7SDag-Erling Smørgrav  -release RELEASE  specify package release information
38377b5038d7SDag-Erling Smørgrav  -rpath LIBDIR     the created library will eventually be installed in LIBDIR
38387b5038d7SDag-Erling Smørgrav  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
38397b5038d7SDag-Erling Smørgrav  -shared           only do dynamic linking of libtool libraries
38407b5038d7SDag-Erling Smørgrav  -shrext SUFFIX    override the standard shared library file extension
38417b5038d7SDag-Erling Smørgrav  -static           do not do any dynamic linking of uninstalled libtool libraries
38427b5038d7SDag-Erling Smørgrav  -static-libtool-libs
38437b5038d7SDag-Erling Smørgrav                    do not do any dynamic linking of libtool libraries
38447b5038d7SDag-Erling Smørgrav  -version-info CURRENT[:REVISION[:AGE]]
38457b5038d7SDag-Erling Smørgrav                    specify library version info [each variable defaults to 0]
38467b5038d7SDag-Erling Smørgrav  -weak LIBNAME     declare that the target provides the LIBNAME interface
38477b5038d7SDag-Erling Smørgrav  -Wc,FLAG
38487b5038d7SDag-Erling Smørgrav  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler
38497b5038d7SDag-Erling Smørgrav  -Wl,FLAG
38507b5038d7SDag-Erling Smørgrav  -Xlinker FLAG     pass linker-specific FLAG directly to the linker
38517b5038d7SDag-Erling Smørgrav  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)
38527b5038d7SDag-Erling Smørgrav
3853986ba33cSDag-Erling SmørgravAll other options (arguments beginning with '-') are ignored.
38547b5038d7SDag-Erling Smørgrav
3855986ba33cSDag-Erling SmørgravEvery other argument is treated as a filename.  Files ending in '.la' are
38567b5038d7SDag-Erling Smørgravtreated as uninstalled libtool libraries, other files are standard or library
38577b5038d7SDag-Erling Smørgravobject files.
38587b5038d7SDag-Erling Smørgrav
3859986ba33cSDag-Erling SmørgravIf the OUTPUT-FILE ends in '.la', then a libtool library is created,
3860986ba33cSDag-Erling Smørgravonly library objects ('.lo' files) may be specified, and '-rpath' is
38617b5038d7SDag-Erling Smørgravrequired, except when creating a convenience library.
38627b5038d7SDag-Erling Smørgrav
3863986ba33cSDag-Erling SmørgravIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
3864986ba33cSDag-Erling Smørgravusing 'ar' and 'ranlib', or on Windows using 'lib'.
38657b5038d7SDag-Erling Smørgrav
3866986ba33cSDag-Erling SmørgravIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file
38677b5038d7SDag-Erling Smørgravis created, otherwise an executable program is created."
38687b5038d7SDag-Erling Smørgrav        ;;
38697b5038d7SDag-Erling Smørgrav
38707b5038d7SDag-Erling Smørgrav      uninstall)
38717b5038d7SDag-Erling Smørgrav        $ECHO \
38727b5038d7SDag-Erling Smørgrav"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...
38737b5038d7SDag-Erling Smørgrav
38747b5038d7SDag-Erling SmørgravRemove libraries from an installation directory.
38757b5038d7SDag-Erling Smørgrav
38767b5038d7SDag-Erling SmørgravRM is the name of the program to use to delete files associated with each FILE
3877986ba33cSDag-Erling Smørgrav(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed
38787b5038d7SDag-Erling Smørgravto RM.
38797b5038d7SDag-Erling Smørgrav
38807b5038d7SDag-Erling SmørgravIf FILE is a libtool library, all the files associated with it are deleted.
38817b5038d7SDag-Erling SmørgravOtherwise, only FILE itself is deleted using RM."
38827b5038d7SDag-Erling Smørgrav        ;;
38837b5038d7SDag-Erling Smørgrav
38847b5038d7SDag-Erling Smørgrav      *)
3885986ba33cSDag-Erling Smørgrav        func_fatal_help "invalid operation mode '$opt_mode'"
38867b5038d7SDag-Erling Smørgrav        ;;
38877b5038d7SDag-Erling Smørgrav    esac
38887b5038d7SDag-Erling Smørgrav
38897b5038d7SDag-Erling Smørgrav    echo
3890986ba33cSDag-Erling Smørgrav    $ECHO "Try '$progname --help' for more information about other modes."
38917b5038d7SDag-Erling Smørgrav}
38927b5038d7SDag-Erling Smørgrav
38937b5038d7SDag-Erling Smørgrav# Now that we've collected a possible --mode arg, show help if necessary
38947b5038d7SDag-Erling Smørgravif $opt_help; then
3895986ba33cSDag-Erling Smørgrav  if test : = "$opt_help"; then
38967b5038d7SDag-Erling Smørgrav    func_mode_help
38977b5038d7SDag-Erling Smørgrav  else
38987b5038d7SDag-Erling Smørgrav    {
38997b5038d7SDag-Erling Smørgrav      func_help noexit
39007b5038d7SDag-Erling Smørgrav      for opt_mode in compile link execute install finish uninstall clean; do
39017b5038d7SDag-Erling Smørgrav	func_mode_help
39027b5038d7SDag-Erling Smørgrav      done
3903986ba33cSDag-Erling Smørgrav    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'
39047b5038d7SDag-Erling Smørgrav    {
39057b5038d7SDag-Erling Smørgrav      func_help noexit
39067b5038d7SDag-Erling Smørgrav      for opt_mode in compile link execute install finish uninstall clean; do
39077b5038d7SDag-Erling Smørgrav	echo
39087b5038d7SDag-Erling Smørgrav	func_mode_help
39097b5038d7SDag-Erling Smørgrav      done
39107b5038d7SDag-Erling Smørgrav    } |
3911986ba33cSDag-Erling Smørgrav    $SED '1d
39127b5038d7SDag-Erling Smørgrav      /^When reporting/,/^Report/{
39137b5038d7SDag-Erling Smørgrav	H
39147b5038d7SDag-Erling Smørgrav	d
39157b5038d7SDag-Erling Smørgrav      }
39167b5038d7SDag-Erling Smørgrav      $x
39177b5038d7SDag-Erling Smørgrav      /information about other modes/d
39187b5038d7SDag-Erling Smørgrav      /more detailed .*MODE/d
39197b5038d7SDag-Erling Smørgrav      s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/'
39207b5038d7SDag-Erling Smørgrav  fi
39217b5038d7SDag-Erling Smørgrav  exit $?
39227b5038d7SDag-Erling Smørgravfi
39237b5038d7SDag-Erling Smørgrav
39247b5038d7SDag-Erling Smørgrav
39257b5038d7SDag-Erling Smørgrav# func_mode_execute arg...
39267b5038d7SDag-Erling Smørgravfunc_mode_execute ()
39277b5038d7SDag-Erling Smørgrav{
3928986ba33cSDag-Erling Smørgrav    $debug_cmd
3929986ba33cSDag-Erling Smørgrav
39307b5038d7SDag-Erling Smørgrav    # The first argument is the command name.
3931986ba33cSDag-Erling Smørgrav    cmd=$nonopt
39327b5038d7SDag-Erling Smørgrav    test -z "$cmd" && \
39337b5038d7SDag-Erling Smørgrav      func_fatal_help "you must specify a COMMAND"
39347b5038d7SDag-Erling Smørgrav
39357b5038d7SDag-Erling Smørgrav    # Handle -dlopen flags immediately.
39367b5038d7SDag-Erling Smørgrav    for file in $opt_dlopen; do
39377b5038d7SDag-Erling Smørgrav      test -f "$file" \
3938986ba33cSDag-Erling Smørgrav	|| func_fatal_help "'$file' is not a file"
39397b5038d7SDag-Erling Smørgrav
39407b5038d7SDag-Erling Smørgrav      dir=
39417b5038d7SDag-Erling Smørgrav      case $file in
39427b5038d7SDag-Erling Smørgrav      *.la)
39437b5038d7SDag-Erling Smørgrav	func_resolve_sysroot "$file"
39447b5038d7SDag-Erling Smørgrav	file=$func_resolve_sysroot_result
39457b5038d7SDag-Erling Smørgrav
39467b5038d7SDag-Erling Smørgrav	# Check to see that this really is a libtool archive.
39477b5038d7SDag-Erling Smørgrav	func_lalib_unsafe_p "$file" \
3948986ba33cSDag-Erling Smørgrav	  || func_fatal_help "'$lib' is not a valid libtool archive"
39497b5038d7SDag-Erling Smørgrav
39507b5038d7SDag-Erling Smørgrav	# Read the libtool library.
39517b5038d7SDag-Erling Smørgrav	dlname=
39527b5038d7SDag-Erling Smørgrav	library_names=
39537b5038d7SDag-Erling Smørgrav	func_source "$file"
39547b5038d7SDag-Erling Smørgrav
39557b5038d7SDag-Erling Smørgrav	# Skip this library if it cannot be dlopened.
39567b5038d7SDag-Erling Smørgrav	if test -z "$dlname"; then
39577b5038d7SDag-Erling Smørgrav	  # Warn if it was a shared library.
39587b5038d7SDag-Erling Smørgrav	  test -n "$library_names" && \
3959986ba33cSDag-Erling Smørgrav	    func_warning "'$file' was not linked with '-export-dynamic'"
39607b5038d7SDag-Erling Smørgrav	  continue
39617b5038d7SDag-Erling Smørgrav	fi
39627b5038d7SDag-Erling Smørgrav
39637b5038d7SDag-Erling Smørgrav	func_dirname "$file" "" "."
3964986ba33cSDag-Erling Smørgrav	dir=$func_dirname_result
39657b5038d7SDag-Erling Smørgrav
39667b5038d7SDag-Erling Smørgrav	if test -f "$dir/$objdir/$dlname"; then
39677b5038d7SDag-Erling Smørgrav	  func_append dir "/$objdir"
39687b5038d7SDag-Erling Smørgrav	else
39697b5038d7SDag-Erling Smørgrav	  if test ! -f "$dir/$dlname"; then
3970986ba33cSDag-Erling Smørgrav	    func_fatal_error "cannot find '$dlname' in '$dir' or '$dir/$objdir'"
39717b5038d7SDag-Erling Smørgrav	  fi
39727b5038d7SDag-Erling Smørgrav	fi
39737b5038d7SDag-Erling Smørgrav	;;
39747b5038d7SDag-Erling Smørgrav
39757b5038d7SDag-Erling Smørgrav      *.lo)
39767b5038d7SDag-Erling Smørgrav	# Just add the directory containing the .lo file.
39777b5038d7SDag-Erling Smørgrav	func_dirname "$file" "" "."
3978986ba33cSDag-Erling Smørgrav	dir=$func_dirname_result
39797b5038d7SDag-Erling Smørgrav	;;
39807b5038d7SDag-Erling Smørgrav
39817b5038d7SDag-Erling Smørgrav      *)
3982986ba33cSDag-Erling Smørgrav	func_warning "'-dlopen' is ignored for non-libtool libraries and objects"
39837b5038d7SDag-Erling Smørgrav	continue
39847b5038d7SDag-Erling Smørgrav	;;
39857b5038d7SDag-Erling Smørgrav      esac
39867b5038d7SDag-Erling Smørgrav
39877b5038d7SDag-Erling Smørgrav      # Get the absolute pathname.
39887b5038d7SDag-Erling Smørgrav      absdir=`cd "$dir" && pwd`
3989986ba33cSDag-Erling Smørgrav      test -n "$absdir" && dir=$absdir
39907b5038d7SDag-Erling Smørgrav
39917b5038d7SDag-Erling Smørgrav      # Now add the directory to shlibpath_var.
39927b5038d7SDag-Erling Smørgrav      if eval "test -z \"\$$shlibpath_var\""; then
39937b5038d7SDag-Erling Smørgrav	eval "$shlibpath_var=\"\$dir\""
39947b5038d7SDag-Erling Smørgrav      else
39957b5038d7SDag-Erling Smørgrav	eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\""
39967b5038d7SDag-Erling Smørgrav      fi
39977b5038d7SDag-Erling Smørgrav    done
39987b5038d7SDag-Erling Smørgrav
39997b5038d7SDag-Erling Smørgrav    # This variable tells wrapper scripts just to set shlibpath_var
40007b5038d7SDag-Erling Smørgrav    # rather than running their programs.
4001986ba33cSDag-Erling Smørgrav    libtool_execute_magic=$magic
40027b5038d7SDag-Erling Smørgrav
40037b5038d7SDag-Erling Smørgrav    # Check if any of the arguments is a wrapper script.
40047b5038d7SDag-Erling Smørgrav    args=
40057b5038d7SDag-Erling Smørgrav    for file
40067b5038d7SDag-Erling Smørgrav    do
40077b5038d7SDag-Erling Smørgrav      case $file in
40087b5038d7SDag-Erling Smørgrav      -* | *.la | *.lo ) ;;
40097b5038d7SDag-Erling Smørgrav      *)
40107b5038d7SDag-Erling Smørgrav	# Do a test to see if this is really a libtool program.
40117b5038d7SDag-Erling Smørgrav	if func_ltwrapper_script_p "$file"; then
40127b5038d7SDag-Erling Smørgrav	  func_source "$file"
40137b5038d7SDag-Erling Smørgrav	  # Transform arg to wrapped name.
4014986ba33cSDag-Erling Smørgrav	  file=$progdir/$program
40157b5038d7SDag-Erling Smørgrav	elif func_ltwrapper_executable_p "$file"; then
40167b5038d7SDag-Erling Smørgrav	  func_ltwrapper_scriptname "$file"
40177b5038d7SDag-Erling Smørgrav	  func_source "$func_ltwrapper_scriptname_result"
40187b5038d7SDag-Erling Smørgrav	  # Transform arg to wrapped name.
4019986ba33cSDag-Erling Smørgrav	  file=$progdir/$program
40207b5038d7SDag-Erling Smørgrav	fi
40217b5038d7SDag-Erling Smørgrav	;;
40227b5038d7SDag-Erling Smørgrav      esac
40237b5038d7SDag-Erling Smørgrav      # Quote arguments (to preserve shell metacharacters).
40247b5038d7SDag-Erling Smørgrav      func_append_quoted args "$file"
40257b5038d7SDag-Erling Smørgrav    done
40267b5038d7SDag-Erling Smørgrav
4027986ba33cSDag-Erling Smørgrav    if $opt_dry_run; then
4028986ba33cSDag-Erling Smørgrav      # Display what would be done.
4029986ba33cSDag-Erling Smørgrav      if test -n "$shlibpath_var"; then
4030986ba33cSDag-Erling Smørgrav	eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\""
4031986ba33cSDag-Erling Smørgrav	echo "export $shlibpath_var"
4032986ba33cSDag-Erling Smørgrav      fi
4033986ba33cSDag-Erling Smørgrav      $ECHO "$cmd$args"
4034986ba33cSDag-Erling Smørgrav      exit $EXIT_SUCCESS
4035986ba33cSDag-Erling Smørgrav    else
40367b5038d7SDag-Erling Smørgrav      if test -n "$shlibpath_var"; then
40377b5038d7SDag-Erling Smørgrav	# Export the shlibpath_var.
40387b5038d7SDag-Erling Smørgrav	eval "export $shlibpath_var"
40397b5038d7SDag-Erling Smørgrav      fi
40407b5038d7SDag-Erling Smørgrav
40417b5038d7SDag-Erling Smørgrav      # Restore saved environment variables
40427b5038d7SDag-Erling Smørgrav      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES
40437b5038d7SDag-Erling Smørgrav      do
40447b5038d7SDag-Erling Smørgrav	eval "if test \"\${save_$lt_var+set}\" = set; then
40457b5038d7SDag-Erling Smørgrav                $lt_var=\$save_$lt_var; export $lt_var
40467b5038d7SDag-Erling Smørgrav	      else
40477b5038d7SDag-Erling Smørgrav		$lt_unset $lt_var
40487b5038d7SDag-Erling Smørgrav	      fi"
40497b5038d7SDag-Erling Smørgrav      done
40507b5038d7SDag-Erling Smørgrav
40517b5038d7SDag-Erling Smørgrav      # Now prepare to actually exec the command.
4052986ba33cSDag-Erling Smørgrav      exec_cmd=\$cmd$args
40537b5038d7SDag-Erling Smørgrav    fi
40547b5038d7SDag-Erling Smørgrav}
40557b5038d7SDag-Erling Smørgrav
4056986ba33cSDag-Erling Smørgravtest execute = "$opt_mode" && func_mode_execute ${1+"$@"}
40577b5038d7SDag-Erling Smørgrav
40587b5038d7SDag-Erling Smørgrav
40597b5038d7SDag-Erling Smørgrav# func_mode_finish arg...
40607b5038d7SDag-Erling Smørgravfunc_mode_finish ()
40617b5038d7SDag-Erling Smørgrav{
4062986ba33cSDag-Erling Smørgrav    $debug_cmd
4063986ba33cSDag-Erling Smørgrav
40647b5038d7SDag-Erling Smørgrav    libs=
40657b5038d7SDag-Erling Smørgrav    libdirs=
40667b5038d7SDag-Erling Smørgrav    admincmds=
40677b5038d7SDag-Erling Smørgrav
40687b5038d7SDag-Erling Smørgrav    for opt in "$nonopt" ${1+"$@"}
40697b5038d7SDag-Erling Smørgrav    do
40707b5038d7SDag-Erling Smørgrav      if test -d "$opt"; then
40717b5038d7SDag-Erling Smørgrav	func_append libdirs " $opt"
40727b5038d7SDag-Erling Smørgrav
40737b5038d7SDag-Erling Smørgrav      elif test -f "$opt"; then
40747b5038d7SDag-Erling Smørgrav	if func_lalib_unsafe_p "$opt"; then
40757b5038d7SDag-Erling Smørgrav	  func_append libs " $opt"
40767b5038d7SDag-Erling Smørgrav	else
4077986ba33cSDag-Erling Smørgrav	  func_warning "'$opt' is not a valid libtool archive"
40787b5038d7SDag-Erling Smørgrav	fi
40797b5038d7SDag-Erling Smørgrav
40807b5038d7SDag-Erling Smørgrav      else
4081986ba33cSDag-Erling Smørgrav	func_fatal_error "invalid argument '$opt'"
40827b5038d7SDag-Erling Smørgrav      fi
40837b5038d7SDag-Erling Smørgrav    done
40847b5038d7SDag-Erling Smørgrav
40857b5038d7SDag-Erling Smørgrav    if test -n "$libs"; then
40867b5038d7SDag-Erling Smørgrav      if test -n "$lt_sysroot"; then
40877b5038d7SDag-Erling Smørgrav        sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"`
40887b5038d7SDag-Erling Smørgrav        sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;"
40897b5038d7SDag-Erling Smørgrav      else
40907b5038d7SDag-Erling Smørgrav        sysroot_cmd=
40917b5038d7SDag-Erling Smørgrav      fi
40927b5038d7SDag-Erling Smørgrav
40937b5038d7SDag-Erling Smørgrav      # Remove sysroot references
40947b5038d7SDag-Erling Smørgrav      if $opt_dry_run; then
40957b5038d7SDag-Erling Smørgrav        for lib in $libs; do
4096986ba33cSDag-Erling Smørgrav          echo "removing references to $lt_sysroot and '=' prefixes from $lib"
40977b5038d7SDag-Erling Smørgrav        done
40987b5038d7SDag-Erling Smørgrav      else
40997b5038d7SDag-Erling Smørgrav        tmpdir=`func_mktempdir`
41007b5038d7SDag-Erling Smørgrav        for lib in $libs; do
4101986ba33cSDag-Erling Smørgrav	  $SED -e "$sysroot_cmd s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \
41027b5038d7SDag-Erling Smørgrav	    > $tmpdir/tmp-la
41037b5038d7SDag-Erling Smørgrav	  mv -f $tmpdir/tmp-la $lib
41047b5038d7SDag-Erling Smørgrav	done
41057b5038d7SDag-Erling Smørgrav        ${RM}r "$tmpdir"
41067b5038d7SDag-Erling Smørgrav      fi
41077b5038d7SDag-Erling Smørgrav    fi
41087b5038d7SDag-Erling Smørgrav
41097b5038d7SDag-Erling Smørgrav    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
41107b5038d7SDag-Erling Smørgrav      for libdir in $libdirs; do
41117b5038d7SDag-Erling Smørgrav	if test -n "$finish_cmds"; then
41127b5038d7SDag-Erling Smørgrav	  # Do each command in the finish commands.
41137b5038d7SDag-Erling Smørgrav	  func_execute_cmds "$finish_cmds" 'admincmds="$admincmds
41147b5038d7SDag-Erling Smørgrav'"$cmd"'"'
41157b5038d7SDag-Erling Smørgrav	fi
41167b5038d7SDag-Erling Smørgrav	if test -n "$finish_eval"; then
41177b5038d7SDag-Erling Smørgrav	  # Do the single finish_eval.
41187b5038d7SDag-Erling Smørgrav	  eval cmds=\"$finish_eval\"
41197b5038d7SDag-Erling Smørgrav	  $opt_dry_run || eval "$cmds" || func_append admincmds "
41207b5038d7SDag-Erling Smørgrav       $cmds"
41217b5038d7SDag-Erling Smørgrav	fi
41227b5038d7SDag-Erling Smørgrav      done
41237b5038d7SDag-Erling Smørgrav    fi
41247b5038d7SDag-Erling Smørgrav
41257b5038d7SDag-Erling Smørgrav    # Exit here if they wanted silent mode.
4126986ba33cSDag-Erling Smørgrav    $opt_quiet && exit $EXIT_SUCCESS
41277b5038d7SDag-Erling Smørgrav
41287b5038d7SDag-Erling Smørgrav    if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then
41297b5038d7SDag-Erling Smørgrav      echo "----------------------------------------------------------------------"
41307b5038d7SDag-Erling Smørgrav      echo "Libraries have been installed in:"
41317b5038d7SDag-Erling Smørgrav      for libdir in $libdirs; do
41327b5038d7SDag-Erling Smørgrav	$ECHO "   $libdir"
41337b5038d7SDag-Erling Smørgrav      done
41347b5038d7SDag-Erling Smørgrav      echo
41357b5038d7SDag-Erling Smørgrav      echo "If you ever happen to want to link against installed libraries"
41367b5038d7SDag-Erling Smørgrav      echo "in a given directory, LIBDIR, you must either use libtool, and"
4137986ba33cSDag-Erling Smørgrav      echo "specify the full pathname of the library, or use the '-LLIBDIR'"
41387b5038d7SDag-Erling Smørgrav      echo "flag during linking and do at least one of the following:"
41397b5038d7SDag-Erling Smørgrav      if test -n "$shlibpath_var"; then
4140986ba33cSDag-Erling Smørgrav	echo "   - add LIBDIR to the '$shlibpath_var' environment variable"
41417b5038d7SDag-Erling Smørgrav	echo "     during execution"
41427b5038d7SDag-Erling Smørgrav      fi
41437b5038d7SDag-Erling Smørgrav      if test -n "$runpath_var"; then
4144986ba33cSDag-Erling Smørgrav	echo "   - add LIBDIR to the '$runpath_var' environment variable"
41457b5038d7SDag-Erling Smørgrav	echo "     during linking"
41467b5038d7SDag-Erling Smørgrav      fi
41477b5038d7SDag-Erling Smørgrav      if test -n "$hardcode_libdir_flag_spec"; then
41487b5038d7SDag-Erling Smørgrav	libdir=LIBDIR
41497b5038d7SDag-Erling Smørgrav	eval flag=\"$hardcode_libdir_flag_spec\"
41507b5038d7SDag-Erling Smørgrav
4151986ba33cSDag-Erling Smørgrav	$ECHO "   - use the '$flag' linker flag"
41527b5038d7SDag-Erling Smørgrav      fi
41537b5038d7SDag-Erling Smørgrav      if test -n "$admincmds"; then
41547b5038d7SDag-Erling Smørgrav	$ECHO "   - have your system administrator run these commands:$admincmds"
41557b5038d7SDag-Erling Smørgrav      fi
41567b5038d7SDag-Erling Smørgrav      if test -f /etc/ld.so.conf; then
4157986ba33cSDag-Erling Smørgrav	echo "   - have your system administrator add LIBDIR to '/etc/ld.so.conf'"
41587b5038d7SDag-Erling Smørgrav      fi
41597b5038d7SDag-Erling Smørgrav      echo
41607b5038d7SDag-Erling Smørgrav
41617b5038d7SDag-Erling Smørgrav      echo "See any operating system documentation about shared libraries for"
41627b5038d7SDag-Erling Smørgrav      case $host in
41637b5038d7SDag-Erling Smørgrav	solaris2.[6789]|solaris2.1[0-9])
41647b5038d7SDag-Erling Smørgrav	  echo "more information, such as the ld(1), crle(1) and ld.so(8) manual"
41657b5038d7SDag-Erling Smørgrav	  echo "pages."
41667b5038d7SDag-Erling Smørgrav	  ;;
41677b5038d7SDag-Erling Smørgrav	*)
41687b5038d7SDag-Erling Smørgrav	  echo "more information, such as the ld(1) and ld.so(8) manual pages."
41697b5038d7SDag-Erling Smørgrav	  ;;
41707b5038d7SDag-Erling Smørgrav      esac
41717b5038d7SDag-Erling Smørgrav      echo "----------------------------------------------------------------------"
41727b5038d7SDag-Erling Smørgrav    fi
41737b5038d7SDag-Erling Smørgrav    exit $EXIT_SUCCESS
41747b5038d7SDag-Erling Smørgrav}
41757b5038d7SDag-Erling Smørgrav
4176986ba33cSDag-Erling Smørgravtest finish = "$opt_mode" && func_mode_finish ${1+"$@"}
41777b5038d7SDag-Erling Smørgrav
41787b5038d7SDag-Erling Smørgrav
41797b5038d7SDag-Erling Smørgrav# func_mode_install arg...
41807b5038d7SDag-Erling Smørgravfunc_mode_install ()
41817b5038d7SDag-Erling Smørgrav{
4182986ba33cSDag-Erling Smørgrav    $debug_cmd
4183986ba33cSDag-Erling Smørgrav
41847b5038d7SDag-Erling Smørgrav    # There may be an optional sh(1) argument at the beginning of
41857b5038d7SDag-Erling Smørgrav    # install_prog (especially on Windows NT).
4186986ba33cSDag-Erling Smørgrav    if test "$SHELL" = "$nonopt" || test /bin/sh = "$nonopt" ||
41877b5038d7SDag-Erling Smørgrav       # Allow the use of GNU shtool's install command.
4188986ba33cSDag-Erling Smørgrav       case $nonopt in *shtool*) :;; *) false;; esac
4189986ba33cSDag-Erling Smørgrav    then
41907b5038d7SDag-Erling Smørgrav      # Aesthetically quote it.
41917b5038d7SDag-Erling Smørgrav      func_quote_for_eval "$nonopt"
41927b5038d7SDag-Erling Smørgrav      install_prog="$func_quote_for_eval_result "
41937b5038d7SDag-Erling Smørgrav      arg=$1
41947b5038d7SDag-Erling Smørgrav      shift
41957b5038d7SDag-Erling Smørgrav    else
41967b5038d7SDag-Erling Smørgrav      install_prog=
41977b5038d7SDag-Erling Smørgrav      arg=$nonopt
41987b5038d7SDag-Erling Smørgrav    fi
41997b5038d7SDag-Erling Smørgrav
42007b5038d7SDag-Erling Smørgrav    # The real first argument should be the name of the installation program.
42017b5038d7SDag-Erling Smørgrav    # Aesthetically quote it.
42027b5038d7SDag-Erling Smørgrav    func_quote_for_eval "$arg"
42037b5038d7SDag-Erling Smørgrav    func_append install_prog "$func_quote_for_eval_result"
42047b5038d7SDag-Erling Smørgrav    install_shared_prog=$install_prog
42057b5038d7SDag-Erling Smørgrav    case " $install_prog " in
42067b5038d7SDag-Erling Smørgrav      *[\\\ /]cp\ *) install_cp=: ;;
42077b5038d7SDag-Erling Smørgrav      *) install_cp=false ;;
42087b5038d7SDag-Erling Smørgrav    esac
42097b5038d7SDag-Erling Smørgrav
42107b5038d7SDag-Erling Smørgrav    # We need to accept at least all the BSD install flags.
42117b5038d7SDag-Erling Smørgrav    dest=
42127b5038d7SDag-Erling Smørgrav    files=
42137b5038d7SDag-Erling Smørgrav    opts=
42147b5038d7SDag-Erling Smørgrav    prev=
42157b5038d7SDag-Erling Smørgrav    install_type=
4216986ba33cSDag-Erling Smørgrav    isdir=false
42177b5038d7SDag-Erling Smørgrav    stripme=
42187b5038d7SDag-Erling Smørgrav    no_mode=:
42197b5038d7SDag-Erling Smørgrav    for arg
42207b5038d7SDag-Erling Smørgrav    do
42217b5038d7SDag-Erling Smørgrav      arg2=
42227b5038d7SDag-Erling Smørgrav      if test -n "$dest"; then
42237b5038d7SDag-Erling Smørgrav	func_append files " $dest"
42247b5038d7SDag-Erling Smørgrav	dest=$arg
42257b5038d7SDag-Erling Smørgrav	continue
42267b5038d7SDag-Erling Smørgrav      fi
42277b5038d7SDag-Erling Smørgrav
42287b5038d7SDag-Erling Smørgrav      case $arg in
4229986ba33cSDag-Erling Smørgrav      -d) isdir=: ;;
42307b5038d7SDag-Erling Smørgrav      -f)
42317b5038d7SDag-Erling Smørgrav	if $install_cp; then :; else
42327b5038d7SDag-Erling Smørgrav	  prev=$arg
42337b5038d7SDag-Erling Smørgrav	fi
42347b5038d7SDag-Erling Smørgrav	;;
42357b5038d7SDag-Erling Smørgrav      -g | -m | -o)
42367b5038d7SDag-Erling Smørgrav	prev=$arg
42377b5038d7SDag-Erling Smørgrav	;;
42387b5038d7SDag-Erling Smørgrav      -s)
42397b5038d7SDag-Erling Smørgrav	stripme=" -s"
42407b5038d7SDag-Erling Smørgrav	continue
42417b5038d7SDag-Erling Smørgrav	;;
42427b5038d7SDag-Erling Smørgrav      -*)
42437b5038d7SDag-Erling Smørgrav	;;
42447b5038d7SDag-Erling Smørgrav      *)
42457b5038d7SDag-Erling Smørgrav	# If the previous option needed an argument, then skip it.
42467b5038d7SDag-Erling Smørgrav	if test -n "$prev"; then
4247986ba33cSDag-Erling Smørgrav	  if test X-m = "X$prev" && test -n "$install_override_mode"; then
42487b5038d7SDag-Erling Smørgrav	    arg2=$install_override_mode
42497b5038d7SDag-Erling Smørgrav	    no_mode=false
42507b5038d7SDag-Erling Smørgrav	  fi
42517b5038d7SDag-Erling Smørgrav	  prev=
42527b5038d7SDag-Erling Smørgrav	else
42537b5038d7SDag-Erling Smørgrav	  dest=$arg
42547b5038d7SDag-Erling Smørgrav	  continue
42557b5038d7SDag-Erling Smørgrav	fi
42567b5038d7SDag-Erling Smørgrav	;;
42577b5038d7SDag-Erling Smørgrav      esac
42587b5038d7SDag-Erling Smørgrav
42597b5038d7SDag-Erling Smørgrav      # Aesthetically quote the argument.
42607b5038d7SDag-Erling Smørgrav      func_quote_for_eval "$arg"
42617b5038d7SDag-Erling Smørgrav      func_append install_prog " $func_quote_for_eval_result"
42627b5038d7SDag-Erling Smørgrav      if test -n "$arg2"; then
42637b5038d7SDag-Erling Smørgrav	func_quote_for_eval "$arg2"
42647b5038d7SDag-Erling Smørgrav      fi
42657b5038d7SDag-Erling Smørgrav      func_append install_shared_prog " $func_quote_for_eval_result"
42667b5038d7SDag-Erling Smørgrav    done
42677b5038d7SDag-Erling Smørgrav
42687b5038d7SDag-Erling Smørgrav    test -z "$install_prog" && \
42697b5038d7SDag-Erling Smørgrav      func_fatal_help "you must specify an install program"
42707b5038d7SDag-Erling Smørgrav
42717b5038d7SDag-Erling Smørgrav    test -n "$prev" && \
4272986ba33cSDag-Erling Smørgrav      func_fatal_help "the '$prev' option requires an argument"
42737b5038d7SDag-Erling Smørgrav
42747b5038d7SDag-Erling Smørgrav    if test -n "$install_override_mode" && $no_mode; then
42757b5038d7SDag-Erling Smørgrav      if $install_cp; then :; else
42767b5038d7SDag-Erling Smørgrav	func_quote_for_eval "$install_override_mode"
42777b5038d7SDag-Erling Smørgrav	func_append install_shared_prog " -m $func_quote_for_eval_result"
42787b5038d7SDag-Erling Smørgrav      fi
42797b5038d7SDag-Erling Smørgrav    fi
42807b5038d7SDag-Erling Smørgrav
42817b5038d7SDag-Erling Smørgrav    if test -z "$files"; then
42827b5038d7SDag-Erling Smørgrav      if test -z "$dest"; then
42837b5038d7SDag-Erling Smørgrav	func_fatal_help "no file or destination specified"
42847b5038d7SDag-Erling Smørgrav      else
42857b5038d7SDag-Erling Smørgrav	func_fatal_help "you must specify a destination"
42867b5038d7SDag-Erling Smørgrav      fi
42877b5038d7SDag-Erling Smørgrav    fi
42887b5038d7SDag-Erling Smørgrav
42897b5038d7SDag-Erling Smørgrav    # Strip any trailing slash from the destination.
42907b5038d7SDag-Erling Smørgrav    func_stripname '' '/' "$dest"
42917b5038d7SDag-Erling Smørgrav    dest=$func_stripname_result
42927b5038d7SDag-Erling Smørgrav
42937b5038d7SDag-Erling Smørgrav    # Check to see that the destination is a directory.
4294986ba33cSDag-Erling Smørgrav    test -d "$dest" && isdir=:
4295986ba33cSDag-Erling Smørgrav    if $isdir; then
4296986ba33cSDag-Erling Smørgrav      destdir=$dest
42977b5038d7SDag-Erling Smørgrav      destname=
42987b5038d7SDag-Erling Smørgrav    else
42997b5038d7SDag-Erling Smørgrav      func_dirname_and_basename "$dest" "" "."
4300986ba33cSDag-Erling Smørgrav      destdir=$func_dirname_result
4301986ba33cSDag-Erling Smørgrav      destname=$func_basename_result
43027b5038d7SDag-Erling Smørgrav
43037b5038d7SDag-Erling Smørgrav      # Not a directory, so check to see that there is only one file specified.
43047b5038d7SDag-Erling Smørgrav      set dummy $files; shift
43057b5038d7SDag-Erling Smørgrav      test "$#" -gt 1 && \
4306986ba33cSDag-Erling Smørgrav	func_fatal_help "'$dest' is not a directory"
43077b5038d7SDag-Erling Smørgrav    fi
43087b5038d7SDag-Erling Smørgrav    case $destdir in
43097b5038d7SDag-Erling Smørgrav    [\\/]* | [A-Za-z]:[\\/]*) ;;
43107b5038d7SDag-Erling Smørgrav    *)
43117b5038d7SDag-Erling Smørgrav      for file in $files; do
43127b5038d7SDag-Erling Smørgrav	case $file in
43137b5038d7SDag-Erling Smørgrav	*.lo) ;;
43147b5038d7SDag-Erling Smørgrav	*)
4315986ba33cSDag-Erling Smørgrav	  func_fatal_help "'$destdir' must be an absolute directory name"
43167b5038d7SDag-Erling Smørgrav	  ;;
43177b5038d7SDag-Erling Smørgrav	esac
43187b5038d7SDag-Erling Smørgrav      done
43197b5038d7SDag-Erling Smørgrav      ;;
43207b5038d7SDag-Erling Smørgrav    esac
43217b5038d7SDag-Erling Smørgrav
43227b5038d7SDag-Erling Smørgrav    # This variable tells wrapper scripts just to set variables rather
43237b5038d7SDag-Erling Smørgrav    # than running their programs.
4324986ba33cSDag-Erling Smørgrav    libtool_install_magic=$magic
43257b5038d7SDag-Erling Smørgrav
43267b5038d7SDag-Erling Smørgrav    staticlibs=
43277b5038d7SDag-Erling Smørgrav    future_libdirs=
43287b5038d7SDag-Erling Smørgrav    current_libdirs=
43297b5038d7SDag-Erling Smørgrav    for file in $files; do
43307b5038d7SDag-Erling Smørgrav
43317b5038d7SDag-Erling Smørgrav      # Do each installation.
43327b5038d7SDag-Erling Smørgrav      case $file in
43337b5038d7SDag-Erling Smørgrav      *.$libext)
43347b5038d7SDag-Erling Smørgrav	# Do the static libraries later.
43357b5038d7SDag-Erling Smørgrav	func_append staticlibs " $file"
43367b5038d7SDag-Erling Smørgrav	;;
43377b5038d7SDag-Erling Smørgrav
43387b5038d7SDag-Erling Smørgrav      *.la)
43397b5038d7SDag-Erling Smørgrav	func_resolve_sysroot "$file"
43407b5038d7SDag-Erling Smørgrav	file=$func_resolve_sysroot_result
43417b5038d7SDag-Erling Smørgrav
43427b5038d7SDag-Erling Smørgrav	# Check to see that this really is a libtool archive.
43437b5038d7SDag-Erling Smørgrav	func_lalib_unsafe_p "$file" \
4344986ba33cSDag-Erling Smørgrav	  || func_fatal_help "'$file' is not a valid libtool archive"
43457b5038d7SDag-Erling Smørgrav
43467b5038d7SDag-Erling Smørgrav	library_names=
43477b5038d7SDag-Erling Smørgrav	old_library=
43487b5038d7SDag-Erling Smørgrav	relink_command=
43497b5038d7SDag-Erling Smørgrav	func_source "$file"
43507b5038d7SDag-Erling Smørgrav
43517b5038d7SDag-Erling Smørgrav	# Add the libdir to current_libdirs if it is the destination.
43527b5038d7SDag-Erling Smørgrav	if test "X$destdir" = "X$libdir"; then
43537b5038d7SDag-Erling Smørgrav	  case "$current_libdirs " in
43547b5038d7SDag-Erling Smørgrav	  *" $libdir "*) ;;
43557b5038d7SDag-Erling Smørgrav	  *) func_append current_libdirs " $libdir" ;;
43567b5038d7SDag-Erling Smørgrav	  esac
43577b5038d7SDag-Erling Smørgrav	else
43587b5038d7SDag-Erling Smørgrav	  # Note the libdir as a future libdir.
43597b5038d7SDag-Erling Smørgrav	  case "$future_libdirs " in
43607b5038d7SDag-Erling Smørgrav	  *" $libdir "*) ;;
43617b5038d7SDag-Erling Smørgrav	  *) func_append future_libdirs " $libdir" ;;
43627b5038d7SDag-Erling Smørgrav	  esac
43637b5038d7SDag-Erling Smørgrav	fi
43647b5038d7SDag-Erling Smørgrav
43657b5038d7SDag-Erling Smørgrav	func_dirname "$file" "/" ""
4366986ba33cSDag-Erling Smørgrav	dir=$func_dirname_result
43677b5038d7SDag-Erling Smørgrav	func_append dir "$objdir"
43687b5038d7SDag-Erling Smørgrav
43697b5038d7SDag-Erling Smørgrav	if test -n "$relink_command"; then
43707b5038d7SDag-Erling Smørgrav	  # Determine the prefix the user has applied to our future dir.
43717b5038d7SDag-Erling Smørgrav	  inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"`
43727b5038d7SDag-Erling Smørgrav
43737b5038d7SDag-Erling Smørgrav	  # Don't allow the user to place us outside of our expected
43747b5038d7SDag-Erling Smørgrav	  # location b/c this prevents finding dependent libraries that
43757b5038d7SDag-Erling Smørgrav	  # are installed to the same prefix.
43767b5038d7SDag-Erling Smørgrav	  # At present, this check doesn't affect windows .dll's that
43777b5038d7SDag-Erling Smørgrav	  # are installed into $libdir/../bin (currently, that works fine)
43787b5038d7SDag-Erling Smørgrav	  # but it's something to keep an eye on.
43797b5038d7SDag-Erling Smørgrav	  test "$inst_prefix_dir" = "$destdir" && \
4380986ba33cSDag-Erling Smørgrav	    func_fatal_error "error: cannot install '$file' to a directory not ending in $libdir"
43817b5038d7SDag-Erling Smørgrav
43827b5038d7SDag-Erling Smørgrav	  if test -n "$inst_prefix_dir"; then
43837b5038d7SDag-Erling Smørgrav	    # Stick the inst_prefix_dir data into the link command.
43847b5038d7SDag-Erling Smørgrav	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
43857b5038d7SDag-Erling Smørgrav	  else
43867b5038d7SDag-Erling Smørgrav	    relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
43877b5038d7SDag-Erling Smørgrav	  fi
43887b5038d7SDag-Erling Smørgrav
4389986ba33cSDag-Erling Smørgrav	  func_warning "relinking '$file'"
43907b5038d7SDag-Erling Smørgrav	  func_show_eval "$relink_command" \
4391986ba33cSDag-Erling Smørgrav	    'func_fatal_error "error: relink '\''$file'\'' with the above command before installing it"'
43927b5038d7SDag-Erling Smørgrav	fi
43937b5038d7SDag-Erling Smørgrav
43947b5038d7SDag-Erling Smørgrav	# See the names of the shared library.
43957b5038d7SDag-Erling Smørgrav	set dummy $library_names; shift
43967b5038d7SDag-Erling Smørgrav	if test -n "$1"; then
4397986ba33cSDag-Erling Smørgrav	  realname=$1
43987b5038d7SDag-Erling Smørgrav	  shift
43997b5038d7SDag-Erling Smørgrav
4400986ba33cSDag-Erling Smørgrav	  srcname=$realname
4401986ba33cSDag-Erling Smørgrav	  test -n "$relink_command" && srcname=${realname}T
44027b5038d7SDag-Erling Smørgrav
44037b5038d7SDag-Erling Smørgrav	  # Install the shared library and build the symlinks.
44047b5038d7SDag-Erling Smørgrav	  func_show_eval "$install_shared_prog $dir/$srcname $destdir/$realname" \
44057b5038d7SDag-Erling Smørgrav	      'exit $?'
4406986ba33cSDag-Erling Smørgrav	  tstripme=$stripme
44077b5038d7SDag-Erling Smørgrav	  case $host_os in
44087b5038d7SDag-Erling Smørgrav	  cygwin* | mingw* | pw32* | cegcc*)
44097b5038d7SDag-Erling Smørgrav	    case $realname in
44107b5038d7SDag-Erling Smørgrav	    *.dll.a)
4411986ba33cSDag-Erling Smørgrav	      tstripme=
4412986ba33cSDag-Erling Smørgrav	      ;;
4413986ba33cSDag-Erling Smørgrav	    esac
4414986ba33cSDag-Erling Smørgrav	    ;;
4415986ba33cSDag-Erling Smørgrav	  os2*)
4416986ba33cSDag-Erling Smørgrav	    case $realname in
4417986ba33cSDag-Erling Smørgrav	    *_dll.a)
4418986ba33cSDag-Erling Smørgrav	      tstripme=
44197b5038d7SDag-Erling Smørgrav	      ;;
44207b5038d7SDag-Erling Smørgrav	    esac
44217b5038d7SDag-Erling Smørgrav	    ;;
44227b5038d7SDag-Erling Smørgrav	  esac
44237b5038d7SDag-Erling Smørgrav	  if test -n "$tstripme" && test -n "$striplib"; then
44247b5038d7SDag-Erling Smørgrav	    func_show_eval "$striplib $destdir/$realname" 'exit $?'
44257b5038d7SDag-Erling Smørgrav	  fi
44267b5038d7SDag-Erling Smørgrav
44277b5038d7SDag-Erling Smørgrav	  if test "$#" -gt 0; then
44287b5038d7SDag-Erling Smørgrav	    # Delete the old symlinks, and create new ones.
4429986ba33cSDag-Erling Smørgrav	    # Try 'ln -sf' first, because the 'ln' binary might depend on
44307b5038d7SDag-Erling Smørgrav	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
44317b5038d7SDag-Erling Smørgrav	    # so we also need to try rm && ln -s.
44327b5038d7SDag-Erling Smørgrav	    for linkname
44337b5038d7SDag-Erling Smørgrav	    do
44347b5038d7SDag-Erling Smørgrav	      test "$linkname" != "$realname" \
44357b5038d7SDag-Erling Smørgrav		&& func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })"
44367b5038d7SDag-Erling Smørgrav	    done
44377b5038d7SDag-Erling Smørgrav	  fi
44387b5038d7SDag-Erling Smørgrav
44397b5038d7SDag-Erling Smørgrav	  # Do each command in the postinstall commands.
4440986ba33cSDag-Erling Smørgrav	  lib=$destdir/$realname
44417b5038d7SDag-Erling Smørgrav	  func_execute_cmds "$postinstall_cmds" 'exit $?'
44427b5038d7SDag-Erling Smørgrav	fi
44437b5038d7SDag-Erling Smørgrav
44447b5038d7SDag-Erling Smørgrav	# Install the pseudo-library for information purposes.
44457b5038d7SDag-Erling Smørgrav	func_basename "$file"
4446986ba33cSDag-Erling Smørgrav	name=$func_basename_result
4447986ba33cSDag-Erling Smørgrav	instname=$dir/${name}i
44487b5038d7SDag-Erling Smørgrav	func_show_eval "$install_prog $instname $destdir/$name" 'exit $?'
44497b5038d7SDag-Erling Smørgrav
44507b5038d7SDag-Erling Smørgrav	# Maybe install the static library, too.
44517b5038d7SDag-Erling Smørgrav	test -n "$old_library" && func_append staticlibs " $dir/$old_library"
44527b5038d7SDag-Erling Smørgrav	;;
44537b5038d7SDag-Erling Smørgrav
44547b5038d7SDag-Erling Smørgrav      *.lo)
44557b5038d7SDag-Erling Smørgrav	# Install (i.e. copy) a libtool object.
44567b5038d7SDag-Erling Smørgrav
44577b5038d7SDag-Erling Smørgrav	# Figure out destination file name, if it wasn't already specified.
44587b5038d7SDag-Erling Smørgrav	if test -n "$destname"; then
4459986ba33cSDag-Erling Smørgrav	  destfile=$destdir/$destname
44607b5038d7SDag-Erling Smørgrav	else
44617b5038d7SDag-Erling Smørgrav	  func_basename "$file"
4462986ba33cSDag-Erling Smørgrav	  destfile=$func_basename_result
4463986ba33cSDag-Erling Smørgrav	  destfile=$destdir/$destfile
44647b5038d7SDag-Erling Smørgrav	fi
44657b5038d7SDag-Erling Smørgrav
44667b5038d7SDag-Erling Smørgrav	# Deduce the name of the destination old-style object file.
44677b5038d7SDag-Erling Smørgrav	case $destfile in
44687b5038d7SDag-Erling Smørgrav	*.lo)
44697b5038d7SDag-Erling Smørgrav	  func_lo2o "$destfile"
44707b5038d7SDag-Erling Smørgrav	  staticdest=$func_lo2o_result
44717b5038d7SDag-Erling Smørgrav	  ;;
44727b5038d7SDag-Erling Smørgrav	*.$objext)
4473986ba33cSDag-Erling Smørgrav	  staticdest=$destfile
44747b5038d7SDag-Erling Smørgrav	  destfile=
44757b5038d7SDag-Erling Smørgrav	  ;;
44767b5038d7SDag-Erling Smørgrav	*)
4477986ba33cSDag-Erling Smørgrav	  func_fatal_help "cannot copy a libtool object to '$destfile'"
44787b5038d7SDag-Erling Smørgrav	  ;;
44797b5038d7SDag-Erling Smørgrav	esac
44807b5038d7SDag-Erling Smørgrav
44817b5038d7SDag-Erling Smørgrav	# Install the libtool object if requested.
44827b5038d7SDag-Erling Smørgrav	test -n "$destfile" && \
44837b5038d7SDag-Erling Smørgrav	  func_show_eval "$install_prog $file $destfile" 'exit $?'
44847b5038d7SDag-Erling Smørgrav
44857b5038d7SDag-Erling Smørgrav	# Install the old object if enabled.
4486986ba33cSDag-Erling Smørgrav	if test yes = "$build_old_libs"; then
44877b5038d7SDag-Erling Smørgrav	  # Deduce the name of the old-style object file.
44887b5038d7SDag-Erling Smørgrav	  func_lo2o "$file"
44897b5038d7SDag-Erling Smørgrav	  staticobj=$func_lo2o_result
44907b5038d7SDag-Erling Smørgrav	  func_show_eval "$install_prog \$staticobj \$staticdest" 'exit $?'
44917b5038d7SDag-Erling Smørgrav	fi
44927b5038d7SDag-Erling Smørgrav	exit $EXIT_SUCCESS
44937b5038d7SDag-Erling Smørgrav	;;
44947b5038d7SDag-Erling Smørgrav
44957b5038d7SDag-Erling Smørgrav      *)
44967b5038d7SDag-Erling Smørgrav	# Figure out destination file name, if it wasn't already specified.
44977b5038d7SDag-Erling Smørgrav	if test -n "$destname"; then
4498986ba33cSDag-Erling Smørgrav	  destfile=$destdir/$destname
44997b5038d7SDag-Erling Smørgrav	else
45007b5038d7SDag-Erling Smørgrav	  func_basename "$file"
4501986ba33cSDag-Erling Smørgrav	  destfile=$func_basename_result
4502986ba33cSDag-Erling Smørgrav	  destfile=$destdir/$destfile
45037b5038d7SDag-Erling Smørgrav	fi
45047b5038d7SDag-Erling Smørgrav
45057b5038d7SDag-Erling Smørgrav	# If the file is missing, and there is a .exe on the end, strip it
45067b5038d7SDag-Erling Smørgrav	# because it is most likely a libtool script we actually want to
45077b5038d7SDag-Erling Smørgrav	# install
4508986ba33cSDag-Erling Smørgrav	stripped_ext=
45097b5038d7SDag-Erling Smørgrav	case $file in
45107b5038d7SDag-Erling Smørgrav	  *.exe)
45117b5038d7SDag-Erling Smørgrav	    if test ! -f "$file"; then
45127b5038d7SDag-Erling Smørgrav	      func_stripname '' '.exe' "$file"
45137b5038d7SDag-Erling Smørgrav	      file=$func_stripname_result
4514986ba33cSDag-Erling Smørgrav	      stripped_ext=.exe
45157b5038d7SDag-Erling Smørgrav	    fi
45167b5038d7SDag-Erling Smørgrav	    ;;
45177b5038d7SDag-Erling Smørgrav	esac
45187b5038d7SDag-Erling Smørgrav
45197b5038d7SDag-Erling Smørgrav	# Do a test to see if this is really a libtool program.
45207b5038d7SDag-Erling Smørgrav	case $host in
45217b5038d7SDag-Erling Smørgrav	*cygwin* | *mingw*)
45227b5038d7SDag-Erling Smørgrav	    if func_ltwrapper_executable_p "$file"; then
45237b5038d7SDag-Erling Smørgrav	      func_ltwrapper_scriptname "$file"
45247b5038d7SDag-Erling Smørgrav	      wrapper=$func_ltwrapper_scriptname_result
45257b5038d7SDag-Erling Smørgrav	    else
45267b5038d7SDag-Erling Smørgrav	      func_stripname '' '.exe' "$file"
45277b5038d7SDag-Erling Smørgrav	      wrapper=$func_stripname_result
45287b5038d7SDag-Erling Smørgrav	    fi
45297b5038d7SDag-Erling Smørgrav	    ;;
45307b5038d7SDag-Erling Smørgrav	*)
45317b5038d7SDag-Erling Smørgrav	    wrapper=$file
45327b5038d7SDag-Erling Smørgrav	    ;;
45337b5038d7SDag-Erling Smørgrav	esac
45347b5038d7SDag-Erling Smørgrav	if func_ltwrapper_script_p "$wrapper"; then
45357b5038d7SDag-Erling Smørgrav	  notinst_deplibs=
45367b5038d7SDag-Erling Smørgrav	  relink_command=
45377b5038d7SDag-Erling Smørgrav
45387b5038d7SDag-Erling Smørgrav	  func_source "$wrapper"
45397b5038d7SDag-Erling Smørgrav
45407b5038d7SDag-Erling Smørgrav	  # Check the variables that should have been set.
45417b5038d7SDag-Erling Smørgrav	  test -z "$generated_by_libtool_version" && \
4542986ba33cSDag-Erling Smørgrav	    func_fatal_error "invalid libtool wrapper script '$wrapper'"
45437b5038d7SDag-Erling Smørgrav
4544986ba33cSDag-Erling Smørgrav	  finalize=:
45457b5038d7SDag-Erling Smørgrav	  for lib in $notinst_deplibs; do
45467b5038d7SDag-Erling Smørgrav	    # Check to see that each library is installed.
45477b5038d7SDag-Erling Smørgrav	    libdir=
45487b5038d7SDag-Erling Smørgrav	    if test -f "$lib"; then
45497b5038d7SDag-Erling Smørgrav	      func_source "$lib"
45507b5038d7SDag-Erling Smørgrav	    fi
4551986ba33cSDag-Erling Smørgrav	    libfile=$libdir/`$ECHO "$lib" | $SED 's%^.*/%%g'`
45527b5038d7SDag-Erling Smørgrav	    if test -n "$libdir" && test ! -f "$libfile"; then
4553986ba33cSDag-Erling Smørgrav	      func_warning "'$lib' has not been installed in '$libdir'"
4554986ba33cSDag-Erling Smørgrav	      finalize=false
45557b5038d7SDag-Erling Smørgrav	    fi
45567b5038d7SDag-Erling Smørgrav	  done
45577b5038d7SDag-Erling Smørgrav
45587b5038d7SDag-Erling Smørgrav	  relink_command=
45597b5038d7SDag-Erling Smørgrav	  func_source "$wrapper"
45607b5038d7SDag-Erling Smørgrav
45617b5038d7SDag-Erling Smørgrav	  outputname=
4562986ba33cSDag-Erling Smørgrav	  if test no = "$fast_install" && test -n "$relink_command"; then
45637b5038d7SDag-Erling Smørgrav	    $opt_dry_run || {
4564986ba33cSDag-Erling Smørgrav	      if $finalize; then
45657b5038d7SDag-Erling Smørgrav	        tmpdir=`func_mktempdir`
45667b5038d7SDag-Erling Smørgrav		func_basename "$file$stripped_ext"
4567986ba33cSDag-Erling Smørgrav		file=$func_basename_result
4568986ba33cSDag-Erling Smørgrav	        outputname=$tmpdir/$file
45697b5038d7SDag-Erling Smørgrav	        # Replace the output file specification.
45707b5038d7SDag-Erling Smørgrav	        relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'`
45717b5038d7SDag-Erling Smørgrav
4572986ba33cSDag-Erling Smørgrav	        $opt_quiet || {
45737b5038d7SDag-Erling Smørgrav	          func_quote_for_expand "$relink_command"
45747b5038d7SDag-Erling Smørgrav		  eval "func_echo $func_quote_for_expand_result"
45757b5038d7SDag-Erling Smørgrav	        }
45767b5038d7SDag-Erling Smørgrav	        if eval "$relink_command"; then :
45777b5038d7SDag-Erling Smørgrav	          else
4578986ba33cSDag-Erling Smørgrav		  func_error "error: relink '$file' with the above command before installing it"
45797b5038d7SDag-Erling Smørgrav		  $opt_dry_run || ${RM}r "$tmpdir"
45807b5038d7SDag-Erling Smørgrav		  continue
45817b5038d7SDag-Erling Smørgrav	        fi
4582986ba33cSDag-Erling Smørgrav	        file=$outputname
45837b5038d7SDag-Erling Smørgrav	      else
4584986ba33cSDag-Erling Smørgrav	        func_warning "cannot relink '$file'"
45857b5038d7SDag-Erling Smørgrav	      fi
45867b5038d7SDag-Erling Smørgrav	    }
45877b5038d7SDag-Erling Smørgrav	  else
45887b5038d7SDag-Erling Smørgrav	    # Install the binary that we compiled earlier.
45897b5038d7SDag-Erling Smørgrav	    file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"`
45907b5038d7SDag-Erling Smørgrav	  fi
45917b5038d7SDag-Erling Smørgrav	fi
45927b5038d7SDag-Erling Smørgrav
45937b5038d7SDag-Erling Smørgrav	# remove .exe since cygwin /usr/bin/install will append another
45947b5038d7SDag-Erling Smørgrav	# one anyway
45957b5038d7SDag-Erling Smørgrav	case $install_prog,$host in
45967b5038d7SDag-Erling Smørgrav	*/usr/bin/install*,*cygwin*)
45977b5038d7SDag-Erling Smørgrav	  case $file:$destfile in
45987b5038d7SDag-Erling Smørgrav	  *.exe:*.exe)
45997b5038d7SDag-Erling Smørgrav	    # this is ok
46007b5038d7SDag-Erling Smørgrav	    ;;
46017b5038d7SDag-Erling Smørgrav	  *.exe:*)
46027b5038d7SDag-Erling Smørgrav	    destfile=$destfile.exe
46037b5038d7SDag-Erling Smørgrav	    ;;
46047b5038d7SDag-Erling Smørgrav	  *:*.exe)
46057b5038d7SDag-Erling Smørgrav	    func_stripname '' '.exe' "$destfile"
46067b5038d7SDag-Erling Smørgrav	    destfile=$func_stripname_result
46077b5038d7SDag-Erling Smørgrav	    ;;
46087b5038d7SDag-Erling Smørgrav	  esac
46097b5038d7SDag-Erling Smørgrav	  ;;
46107b5038d7SDag-Erling Smørgrav	esac
46117b5038d7SDag-Erling Smørgrav	func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?'
46127b5038d7SDag-Erling Smørgrav	$opt_dry_run || if test -n "$outputname"; then
46137b5038d7SDag-Erling Smørgrav	  ${RM}r "$tmpdir"
46147b5038d7SDag-Erling Smørgrav	fi
46157b5038d7SDag-Erling Smørgrav	;;
46167b5038d7SDag-Erling Smørgrav      esac
46177b5038d7SDag-Erling Smørgrav    done
46187b5038d7SDag-Erling Smørgrav
46197b5038d7SDag-Erling Smørgrav    for file in $staticlibs; do
46207b5038d7SDag-Erling Smørgrav      func_basename "$file"
4621986ba33cSDag-Erling Smørgrav      name=$func_basename_result
46227b5038d7SDag-Erling Smørgrav
46237b5038d7SDag-Erling Smørgrav      # Set up the ranlib parameters.
4624986ba33cSDag-Erling Smørgrav      oldlib=$destdir/$name
46257b5038d7SDag-Erling Smørgrav      func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
46267b5038d7SDag-Erling Smørgrav      tool_oldlib=$func_to_tool_file_result
46277b5038d7SDag-Erling Smørgrav
46287b5038d7SDag-Erling Smørgrav      func_show_eval "$install_prog \$file \$oldlib" 'exit $?'
46297b5038d7SDag-Erling Smørgrav
46307b5038d7SDag-Erling Smørgrav      if test -n "$stripme" && test -n "$old_striplib"; then
46317b5038d7SDag-Erling Smørgrav	func_show_eval "$old_striplib $tool_oldlib" 'exit $?'
46327b5038d7SDag-Erling Smørgrav      fi
46337b5038d7SDag-Erling Smørgrav
46347b5038d7SDag-Erling Smørgrav      # Do each command in the postinstall commands.
46357b5038d7SDag-Erling Smørgrav      func_execute_cmds "$old_postinstall_cmds" 'exit $?'
46367b5038d7SDag-Erling Smørgrav    done
46377b5038d7SDag-Erling Smørgrav
46387b5038d7SDag-Erling Smørgrav    test -n "$future_libdirs" && \
4639986ba33cSDag-Erling Smørgrav      func_warning "remember to run '$progname --finish$future_libdirs'"
46407b5038d7SDag-Erling Smørgrav
46417b5038d7SDag-Erling Smørgrav    if test -n "$current_libdirs"; then
46427b5038d7SDag-Erling Smørgrav      # Maybe just do a dry run.
46437b5038d7SDag-Erling Smørgrav      $opt_dry_run && current_libdirs=" -n$current_libdirs"
4644986ba33cSDag-Erling Smørgrav      exec_cmd='$SHELL "$progpath" $preserve_args --finish$current_libdirs'
46457b5038d7SDag-Erling Smørgrav    else
46467b5038d7SDag-Erling Smørgrav      exit $EXIT_SUCCESS
46477b5038d7SDag-Erling Smørgrav    fi
46487b5038d7SDag-Erling Smørgrav}
46497b5038d7SDag-Erling Smørgrav
4650986ba33cSDag-Erling Smørgravtest install = "$opt_mode" && func_mode_install ${1+"$@"}
46517b5038d7SDag-Erling Smørgrav
46527b5038d7SDag-Erling Smørgrav
46537b5038d7SDag-Erling Smørgrav# func_generate_dlsyms outputname originator pic_p
46547b5038d7SDag-Erling Smørgrav# Extract symbols from dlprefiles and create ${outputname}S.o with
46557b5038d7SDag-Erling Smørgrav# a dlpreopen symbol table.
46567b5038d7SDag-Erling Smørgravfunc_generate_dlsyms ()
46577b5038d7SDag-Erling Smørgrav{
4658986ba33cSDag-Erling Smørgrav    $debug_cmd
4659986ba33cSDag-Erling Smørgrav
4660986ba33cSDag-Erling Smørgrav    my_outputname=$1
4661986ba33cSDag-Erling Smørgrav    my_originator=$2
4662986ba33cSDag-Erling Smørgrav    my_pic_p=${3-false}
4663986ba33cSDag-Erling Smørgrav    my_prefix=`$ECHO "$my_originator" | $SED 's%[^a-zA-Z0-9]%_%g'`
46647b5038d7SDag-Erling Smørgrav    my_dlsyms=
46657b5038d7SDag-Erling Smørgrav
4666986ba33cSDag-Erling Smørgrav    if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
46677b5038d7SDag-Erling Smørgrav      if test -n "$NM" && test -n "$global_symbol_pipe"; then
4668986ba33cSDag-Erling Smørgrav	my_dlsyms=${my_outputname}S.c
46697b5038d7SDag-Erling Smørgrav      else
46707b5038d7SDag-Erling Smørgrav	func_error "not configured to extract global symbols from dlpreopened files"
46717b5038d7SDag-Erling Smørgrav      fi
46727b5038d7SDag-Erling Smørgrav    fi
46737b5038d7SDag-Erling Smørgrav
46747b5038d7SDag-Erling Smørgrav    if test -n "$my_dlsyms"; then
46757b5038d7SDag-Erling Smørgrav      case $my_dlsyms in
46767b5038d7SDag-Erling Smørgrav      "") ;;
46777b5038d7SDag-Erling Smørgrav      *.c)
46787b5038d7SDag-Erling Smørgrav	# Discover the nlist of each of the dlfiles.
4679986ba33cSDag-Erling Smørgrav	nlist=$output_objdir/$my_outputname.nm
46807b5038d7SDag-Erling Smørgrav
46817b5038d7SDag-Erling Smørgrav	func_show_eval "$RM $nlist ${nlist}S ${nlist}T"
46827b5038d7SDag-Erling Smørgrav
46837b5038d7SDag-Erling Smørgrav	# Parse the name list into a source file.
46847b5038d7SDag-Erling Smørgrav	func_verbose "creating $output_objdir/$my_dlsyms"
46857b5038d7SDag-Erling Smørgrav
46867b5038d7SDag-Erling Smørgrav	$opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\
4687986ba33cSDag-Erling Smørgrav/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */
4688986ba33cSDag-Erling Smørgrav/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */
46897b5038d7SDag-Erling Smørgrav
46907b5038d7SDag-Erling Smørgrav#ifdef __cplusplus
46917b5038d7SDag-Erling Smørgravextern \"C\" {
46927b5038d7SDag-Erling Smørgrav#endif
46937b5038d7SDag-Erling Smørgrav
4694986ba33cSDag-Erling Smørgrav#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))
46957b5038d7SDag-Erling Smørgrav#pragma GCC diagnostic ignored \"-Wstrict-prototypes\"
46967b5038d7SDag-Erling Smørgrav#endif
46977b5038d7SDag-Erling Smørgrav
46987b5038d7SDag-Erling Smørgrav/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */
4699986ba33cSDag-Erling Smørgrav#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE
4700986ba33cSDag-Erling Smørgrav/* DATA imports from DLLs on WIN32 can't be const, because runtime
47017b5038d7SDag-Erling Smørgrav   relocations are performed -- see ld's documentation on pseudo-relocs.  */
47027b5038d7SDag-Erling Smørgrav# define LT_DLSYM_CONST
4703986ba33cSDag-Erling Smørgrav#elif defined __osf__
47047b5038d7SDag-Erling Smørgrav/* This system does not cope well with relocations in const data.  */
47057b5038d7SDag-Erling Smørgrav# define LT_DLSYM_CONST
47067b5038d7SDag-Erling Smørgrav#else
47077b5038d7SDag-Erling Smørgrav# define LT_DLSYM_CONST const
47087b5038d7SDag-Erling Smørgrav#endif
47097b5038d7SDag-Erling Smørgrav
4710986ba33cSDag-Erling Smørgrav#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
4711986ba33cSDag-Erling Smørgrav
47127b5038d7SDag-Erling Smørgrav/* External symbol declarations for the compiler. */\
47137b5038d7SDag-Erling Smørgrav"
47147b5038d7SDag-Erling Smørgrav
4715986ba33cSDag-Erling Smørgrav	if test yes = "$dlself"; then
4716986ba33cSDag-Erling Smørgrav	  func_verbose "generating symbol list for '$output'"
47177b5038d7SDag-Erling Smørgrav
47187b5038d7SDag-Erling Smørgrav	  $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist"
47197b5038d7SDag-Erling Smørgrav
47207b5038d7SDag-Erling Smørgrav	  # Add our own program objects to the symbol list.
47217b5038d7SDag-Erling Smørgrav	  progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP`
47227b5038d7SDag-Erling Smørgrav	  for progfile in $progfiles; do
47237b5038d7SDag-Erling Smørgrav	    func_to_tool_file "$progfile" func_convert_file_msys_to_w32
4724986ba33cSDag-Erling Smørgrav	    func_verbose "extracting global C symbols from '$func_to_tool_file_result'"
47257b5038d7SDag-Erling Smørgrav	    $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'"
47267b5038d7SDag-Erling Smørgrav	  done
47277b5038d7SDag-Erling Smørgrav
47287b5038d7SDag-Erling Smørgrav	  if test -n "$exclude_expsyms"; then
47297b5038d7SDag-Erling Smørgrav	    $opt_dry_run || {
47307b5038d7SDag-Erling Smørgrav	      eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
47317b5038d7SDag-Erling Smørgrav	      eval '$MV "$nlist"T "$nlist"'
47327b5038d7SDag-Erling Smørgrav	    }
47337b5038d7SDag-Erling Smørgrav	  fi
47347b5038d7SDag-Erling Smørgrav
47357b5038d7SDag-Erling Smørgrav	  if test -n "$export_symbols_regex"; then
47367b5038d7SDag-Erling Smørgrav	    $opt_dry_run || {
47377b5038d7SDag-Erling Smørgrav	      eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
47387b5038d7SDag-Erling Smørgrav	      eval '$MV "$nlist"T "$nlist"'
47397b5038d7SDag-Erling Smørgrav	    }
47407b5038d7SDag-Erling Smørgrav	  fi
47417b5038d7SDag-Erling Smørgrav
47427b5038d7SDag-Erling Smørgrav	  # Prepare the list of exported symbols
47437b5038d7SDag-Erling Smørgrav	  if test -z "$export_symbols"; then
4744986ba33cSDag-Erling Smørgrav	    export_symbols=$output_objdir/$outputname.exp
47457b5038d7SDag-Erling Smørgrav	    $opt_dry_run || {
47467b5038d7SDag-Erling Smørgrav	      $RM $export_symbols
4747986ba33cSDag-Erling Smørgrav	      eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
47487b5038d7SDag-Erling Smørgrav	      case $host in
47497b5038d7SDag-Erling Smørgrav	      *cygwin* | *mingw* | *cegcc* )
47507b5038d7SDag-Erling Smørgrav                eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
47517b5038d7SDag-Erling Smørgrav                eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
47527b5038d7SDag-Erling Smørgrav	        ;;
47537b5038d7SDag-Erling Smørgrav	      esac
47547b5038d7SDag-Erling Smørgrav	    }
47557b5038d7SDag-Erling Smørgrav	  else
47567b5038d7SDag-Erling Smørgrav	    $opt_dry_run || {
4757986ba33cSDag-Erling Smørgrav	      eval "$SED -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
47587b5038d7SDag-Erling Smørgrav	      eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
47597b5038d7SDag-Erling Smørgrav	      eval '$MV "$nlist"T "$nlist"'
47607b5038d7SDag-Erling Smørgrav	      case $host in
47617b5038d7SDag-Erling Smørgrav	        *cygwin* | *mingw* | *cegcc* )
47627b5038d7SDag-Erling Smørgrav	          eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
47637b5038d7SDag-Erling Smørgrav	          eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
47647b5038d7SDag-Erling Smørgrav	          ;;
47657b5038d7SDag-Erling Smørgrav	      esac
47667b5038d7SDag-Erling Smørgrav	    }
47677b5038d7SDag-Erling Smørgrav	  fi
47687b5038d7SDag-Erling Smørgrav	fi
47697b5038d7SDag-Erling Smørgrav
47707b5038d7SDag-Erling Smørgrav	for dlprefile in $dlprefiles; do
4771986ba33cSDag-Erling Smørgrav	  func_verbose "extracting global C symbols from '$dlprefile'"
47727b5038d7SDag-Erling Smørgrav	  func_basename "$dlprefile"
4773986ba33cSDag-Erling Smørgrav	  name=$func_basename_result
47747b5038d7SDag-Erling Smørgrav          case $host in
47757b5038d7SDag-Erling Smørgrav	    *cygwin* | *mingw* | *cegcc* )
47767b5038d7SDag-Erling Smørgrav	      # if an import library, we need to obtain dlname
47777b5038d7SDag-Erling Smørgrav	      if func_win32_import_lib_p "$dlprefile"; then
47787b5038d7SDag-Erling Smørgrav	        func_tr_sh "$dlprefile"
47797b5038d7SDag-Erling Smørgrav	        eval "curr_lafile=\$libfile_$func_tr_sh_result"
4780986ba33cSDag-Erling Smørgrav	        dlprefile_dlbasename=
47817b5038d7SDag-Erling Smørgrav	        if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then
47827b5038d7SDag-Erling Smørgrav	          # Use subshell, to avoid clobbering current variable values
47837b5038d7SDag-Erling Smørgrav	          dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"`
47847b5038d7SDag-Erling Smørgrav	          if test -n "$dlprefile_dlname"; then
47857b5038d7SDag-Erling Smørgrav	            func_basename "$dlprefile_dlname"
4786986ba33cSDag-Erling Smørgrav	            dlprefile_dlbasename=$func_basename_result
47877b5038d7SDag-Erling Smørgrav	          else
47887b5038d7SDag-Erling Smørgrav	            # no lafile. user explicitly requested -dlpreopen <import library>.
47897b5038d7SDag-Erling Smørgrav	            $sharedlib_from_linklib_cmd "$dlprefile"
47907b5038d7SDag-Erling Smørgrav	            dlprefile_dlbasename=$sharedlib_from_linklib_result
47917b5038d7SDag-Erling Smørgrav	          fi
47927b5038d7SDag-Erling Smørgrav	        fi
47937b5038d7SDag-Erling Smørgrav	        $opt_dry_run || {
47947b5038d7SDag-Erling Smørgrav	          if test -n "$dlprefile_dlbasename"; then
47957b5038d7SDag-Erling Smørgrav	            eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"'
47967b5038d7SDag-Erling Smørgrav	          else
47977b5038d7SDag-Erling Smørgrav	            func_warning "Could not compute DLL name from $name"
47987b5038d7SDag-Erling Smørgrav	            eval '$ECHO ": $name " >> "$nlist"'
47997b5038d7SDag-Erling Smørgrav	          fi
48007b5038d7SDag-Erling Smørgrav	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
48017b5038d7SDag-Erling Smørgrav	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe |
48027b5038d7SDag-Erling Smørgrav	            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'"
48037b5038d7SDag-Erling Smørgrav	        }
48047b5038d7SDag-Erling Smørgrav	      else # not an import lib
48057b5038d7SDag-Erling Smørgrav	        $opt_dry_run || {
48067b5038d7SDag-Erling Smørgrav	          eval '$ECHO ": $name " >> "$nlist"'
48077b5038d7SDag-Erling Smørgrav	          func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
48087b5038d7SDag-Erling Smørgrav	          eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
48097b5038d7SDag-Erling Smørgrav	        }
48107b5038d7SDag-Erling Smørgrav	      fi
48117b5038d7SDag-Erling Smørgrav	    ;;
48127b5038d7SDag-Erling Smørgrav	    *)
48137b5038d7SDag-Erling Smørgrav	      $opt_dry_run || {
48147b5038d7SDag-Erling Smørgrav	        eval '$ECHO ": $name " >> "$nlist"'
48157b5038d7SDag-Erling Smørgrav	        func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32
48167b5038d7SDag-Erling Smørgrav	        eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'"
48177b5038d7SDag-Erling Smørgrav	      }
48187b5038d7SDag-Erling Smørgrav	    ;;
48197b5038d7SDag-Erling Smørgrav          esac
48207b5038d7SDag-Erling Smørgrav	done
48217b5038d7SDag-Erling Smørgrav
48227b5038d7SDag-Erling Smørgrav	$opt_dry_run || {
48237b5038d7SDag-Erling Smørgrav	  # Make sure we have at least an empty file.
48247b5038d7SDag-Erling Smørgrav	  test -f "$nlist" || : > "$nlist"
48257b5038d7SDag-Erling Smørgrav
48267b5038d7SDag-Erling Smørgrav	  if test -n "$exclude_expsyms"; then
48277b5038d7SDag-Erling Smørgrav	    $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
48287b5038d7SDag-Erling Smørgrav	    $MV "$nlist"T "$nlist"
48297b5038d7SDag-Erling Smørgrav	  fi
48307b5038d7SDag-Erling Smørgrav
48317b5038d7SDag-Erling Smørgrav	  # Try sorting and uniquifying the output.
48327b5038d7SDag-Erling Smørgrav	  if $GREP -v "^: " < "$nlist" |
48337b5038d7SDag-Erling Smørgrav	      if sort -k 3 </dev/null >/dev/null 2>&1; then
48347b5038d7SDag-Erling Smørgrav		sort -k 3
48357b5038d7SDag-Erling Smørgrav	      else
48367b5038d7SDag-Erling Smørgrav		sort +2
48377b5038d7SDag-Erling Smørgrav	      fi |
48387b5038d7SDag-Erling Smørgrav	      uniq > "$nlist"S; then
48397b5038d7SDag-Erling Smørgrav	    :
48407b5038d7SDag-Erling Smørgrav	  else
48417b5038d7SDag-Erling Smørgrav	    $GREP -v "^: " < "$nlist" > "$nlist"S
48427b5038d7SDag-Erling Smørgrav	  fi
48437b5038d7SDag-Erling Smørgrav
48447b5038d7SDag-Erling Smørgrav	  if test -f "$nlist"S; then
48457b5038d7SDag-Erling Smørgrav	    eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"'
48467b5038d7SDag-Erling Smørgrav	  else
48477b5038d7SDag-Erling Smørgrav	    echo '/* NONE */' >> "$output_objdir/$my_dlsyms"
48487b5038d7SDag-Erling Smørgrav	  fi
48497b5038d7SDag-Erling Smørgrav
4850986ba33cSDag-Erling Smørgrav	  func_show_eval '$RM "${nlist}I"'
4851986ba33cSDag-Erling Smørgrav	  if test -n "$global_symbol_to_import"; then
4852986ba33cSDag-Erling Smørgrav	    eval "$global_symbol_to_import"' < "$nlist"S > "$nlist"I'
4853986ba33cSDag-Erling Smørgrav	  fi
4854986ba33cSDag-Erling Smørgrav
48557b5038d7SDag-Erling Smørgrav	  echo >> "$output_objdir/$my_dlsyms" "\
48567b5038d7SDag-Erling Smørgrav
48577b5038d7SDag-Erling Smørgrav/* The mapping between symbol names and symbols.  */
48587b5038d7SDag-Erling Smørgravtypedef struct {
48597b5038d7SDag-Erling Smørgrav  const char *name;
48607b5038d7SDag-Erling Smørgrav  void *address;
48617b5038d7SDag-Erling Smørgrav} lt_dlsymlist;
48627b5038d7SDag-Erling Smørgravextern LT_DLSYM_CONST lt_dlsymlist
4863986ba33cSDag-Erling Smørgravlt_${my_prefix}_LTX_preloaded_symbols[];\
4864986ba33cSDag-Erling Smørgrav"
4865986ba33cSDag-Erling Smørgrav
4866986ba33cSDag-Erling Smørgrav	  if test -s "$nlist"I; then
4867986ba33cSDag-Erling Smørgrav	    echo >> "$output_objdir/$my_dlsyms" "\
4868986ba33cSDag-Erling Smørgravstatic void lt_syminit(void)
4869986ba33cSDag-Erling Smørgrav{
4870986ba33cSDag-Erling Smørgrav  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;
4871986ba33cSDag-Erling Smørgrav  for (; symbol->name; ++symbol)
4872986ba33cSDag-Erling Smørgrav    {"
4873986ba33cSDag-Erling Smørgrav	    $SED 's/.*/      if (STREQ (symbol->name, \"&\")) symbol->address = (void *) \&&;/' < "$nlist"I >> "$output_objdir/$my_dlsyms"
4874986ba33cSDag-Erling Smørgrav	    echo >> "$output_objdir/$my_dlsyms" "\
4875986ba33cSDag-Erling Smørgrav    }
4876986ba33cSDag-Erling Smørgrav}"
4877986ba33cSDag-Erling Smørgrav	  fi
4878986ba33cSDag-Erling Smørgrav	  echo >> "$output_objdir/$my_dlsyms" "\
48797b5038d7SDag-Erling SmørgravLT_DLSYM_CONST lt_dlsymlist
48807b5038d7SDag-Erling Smørgravlt_${my_prefix}_LTX_preloaded_symbols[] =
4881986ba33cSDag-Erling Smørgrav{ {\"$my_originator\", (void *) 0},"
4882986ba33cSDag-Erling Smørgrav
4883986ba33cSDag-Erling Smørgrav	  if test -s "$nlist"I; then
4884986ba33cSDag-Erling Smørgrav	    echo >> "$output_objdir/$my_dlsyms" "\
4885986ba33cSDag-Erling Smørgrav  {\"@INIT@\", (void *) &lt_syminit},"
4886986ba33cSDag-Erling Smørgrav	  fi
48877b5038d7SDag-Erling Smørgrav
48887b5038d7SDag-Erling Smørgrav	  case $need_lib_prefix in
48897b5038d7SDag-Erling Smørgrav	  no)
48907b5038d7SDag-Erling Smørgrav	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms"
48917b5038d7SDag-Erling Smørgrav	    ;;
48927b5038d7SDag-Erling Smørgrav	  *)
48937b5038d7SDag-Erling Smørgrav	    eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms"
48947b5038d7SDag-Erling Smørgrav	    ;;
48957b5038d7SDag-Erling Smørgrav	  esac
48967b5038d7SDag-Erling Smørgrav	  echo >> "$output_objdir/$my_dlsyms" "\
48977b5038d7SDag-Erling Smørgrav  {0, (void *) 0}
48987b5038d7SDag-Erling Smørgrav};
48997b5038d7SDag-Erling Smørgrav
49007b5038d7SDag-Erling Smørgrav/* This works around a problem in FreeBSD linker */
49017b5038d7SDag-Erling Smørgrav#ifdef FREEBSD_WORKAROUND
49027b5038d7SDag-Erling Smørgravstatic const void *lt_preloaded_setup() {
49037b5038d7SDag-Erling Smørgrav  return lt_${my_prefix}_LTX_preloaded_symbols;
49047b5038d7SDag-Erling Smørgrav}
49057b5038d7SDag-Erling Smørgrav#endif
49067b5038d7SDag-Erling Smørgrav
49077b5038d7SDag-Erling Smørgrav#ifdef __cplusplus
49087b5038d7SDag-Erling Smørgrav}
49097b5038d7SDag-Erling Smørgrav#endif\
49107b5038d7SDag-Erling Smørgrav"
49117b5038d7SDag-Erling Smørgrav	} # !$opt_dry_run
49127b5038d7SDag-Erling Smørgrav
49137b5038d7SDag-Erling Smørgrav	pic_flag_for_symtable=
49147b5038d7SDag-Erling Smørgrav	case "$compile_command " in
49157b5038d7SDag-Erling Smørgrav	*" -static "*) ;;
49167b5038d7SDag-Erling Smørgrav	*)
49177b5038d7SDag-Erling Smørgrav	  case $host in
49187b5038d7SDag-Erling Smørgrav	  # compiling the symbol table file with pic_flag works around
49197b5038d7SDag-Erling Smørgrav	  # a FreeBSD bug that causes programs to crash when -lm is
49207b5038d7SDag-Erling Smørgrav	  # linked before any other PIC object.  But we must not use
49217b5038d7SDag-Erling Smørgrav	  # pic_flag when linking with -static.  The problem exists in
49227b5038d7SDag-Erling Smørgrav	  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.
49237b5038d7SDag-Erling Smørgrav	  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)
49247b5038d7SDag-Erling Smørgrav	    pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;;
49257b5038d7SDag-Erling Smørgrav	  *-*-hpux*)
49267b5038d7SDag-Erling Smørgrav	    pic_flag_for_symtable=" $pic_flag"  ;;
49277b5038d7SDag-Erling Smørgrav	  *)
4928986ba33cSDag-Erling Smørgrav	    $my_pic_p && pic_flag_for_symtable=" $pic_flag"
49297b5038d7SDag-Erling Smørgrav	    ;;
49307b5038d7SDag-Erling Smørgrav	  esac
49317b5038d7SDag-Erling Smørgrav	  ;;
49327b5038d7SDag-Erling Smørgrav	esac
49337b5038d7SDag-Erling Smørgrav	symtab_cflags=
49347b5038d7SDag-Erling Smørgrav	for arg in $LTCFLAGS; do
49357b5038d7SDag-Erling Smørgrav	  case $arg in
49367b5038d7SDag-Erling Smørgrav	  -pie | -fpie | -fPIE) ;;
49377b5038d7SDag-Erling Smørgrav	  *) func_append symtab_cflags " $arg" ;;
49387b5038d7SDag-Erling Smørgrav	  esac
49397b5038d7SDag-Erling Smørgrav	done
49407b5038d7SDag-Erling Smørgrav
49417b5038d7SDag-Erling Smørgrav	# Now compile the dynamic symbol file.
49427b5038d7SDag-Erling Smørgrav	func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?'
49437b5038d7SDag-Erling Smørgrav
49447b5038d7SDag-Erling Smørgrav	# Clean up the generated files.
4945986ba33cSDag-Erling Smørgrav	func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T" "${nlist}I"'
49467b5038d7SDag-Erling Smørgrav
49477b5038d7SDag-Erling Smørgrav	# Transform the symbol file into the correct name.
4948986ba33cSDag-Erling Smørgrav	symfileobj=$output_objdir/${my_outputname}S.$objext
49497b5038d7SDag-Erling Smørgrav	case $host in
49507b5038d7SDag-Erling Smørgrav	*cygwin* | *mingw* | *cegcc* )
49517b5038d7SDag-Erling Smørgrav	  if test -f "$output_objdir/$my_outputname.def"; then
49527b5038d7SDag-Erling Smørgrav	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
49537b5038d7SDag-Erling Smørgrav	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"`
49547b5038d7SDag-Erling Smørgrav	  else
49557b5038d7SDag-Erling Smørgrav	    compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
49567b5038d7SDag-Erling Smørgrav	    finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
49577b5038d7SDag-Erling Smørgrav	  fi
49587b5038d7SDag-Erling Smørgrav	  ;;
49597b5038d7SDag-Erling Smørgrav	*)
49607b5038d7SDag-Erling Smørgrav	  compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"`
49617b5038d7SDag-Erling Smørgrav	  finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"`
49627b5038d7SDag-Erling Smørgrav	  ;;
49637b5038d7SDag-Erling Smørgrav	esac
49647b5038d7SDag-Erling Smørgrav	;;
49657b5038d7SDag-Erling Smørgrav      *)
4966986ba33cSDag-Erling Smørgrav	func_fatal_error "unknown suffix for '$my_dlsyms'"
49677b5038d7SDag-Erling Smørgrav	;;
49687b5038d7SDag-Erling Smørgrav      esac
49697b5038d7SDag-Erling Smørgrav    else
49707b5038d7SDag-Erling Smørgrav      # We keep going just in case the user didn't refer to
49717b5038d7SDag-Erling Smørgrav      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe
49727b5038d7SDag-Erling Smørgrav      # really was required.
49737b5038d7SDag-Erling Smørgrav
49747b5038d7SDag-Erling Smørgrav      # Nullify the symbol file.
49757b5038d7SDag-Erling Smørgrav      compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"`
49767b5038d7SDag-Erling Smørgrav      finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"`
49777b5038d7SDag-Erling Smørgrav    fi
49787b5038d7SDag-Erling Smørgrav}
49797b5038d7SDag-Erling Smørgrav
4980986ba33cSDag-Erling Smørgrav# func_cygming_gnu_implib_p ARG
4981986ba33cSDag-Erling Smørgrav# This predicate returns with zero status (TRUE) if
4982986ba33cSDag-Erling Smørgrav# ARG is a GNU/binutils-style import library. Returns
4983986ba33cSDag-Erling Smørgrav# with nonzero status (FALSE) otherwise.
4984986ba33cSDag-Erling Smørgravfunc_cygming_gnu_implib_p ()
4985986ba33cSDag-Erling Smørgrav{
4986986ba33cSDag-Erling Smørgrav  $debug_cmd
4987986ba33cSDag-Erling Smørgrav
4988986ba33cSDag-Erling Smørgrav  func_to_tool_file "$1" func_convert_file_msys_to_w32
4989986ba33cSDag-Erling Smørgrav  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)$'`
4990986ba33cSDag-Erling Smørgrav  test -n "$func_cygming_gnu_implib_tmp"
4991986ba33cSDag-Erling Smørgrav}
4992986ba33cSDag-Erling Smørgrav
4993986ba33cSDag-Erling Smørgrav# func_cygming_ms_implib_p ARG
4994986ba33cSDag-Erling Smørgrav# This predicate returns with zero status (TRUE) if
4995986ba33cSDag-Erling Smørgrav# ARG is an MS-style import library. Returns
4996986ba33cSDag-Erling Smørgrav# with nonzero status (FALSE) otherwise.
4997986ba33cSDag-Erling Smørgravfunc_cygming_ms_implib_p ()
4998986ba33cSDag-Erling Smørgrav{
4999986ba33cSDag-Erling Smørgrav  $debug_cmd
5000986ba33cSDag-Erling Smørgrav
5001986ba33cSDag-Erling Smørgrav  func_to_tool_file "$1" func_convert_file_msys_to_w32
5002986ba33cSDag-Erling Smørgrav  func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'`
5003986ba33cSDag-Erling Smørgrav  test -n "$func_cygming_ms_implib_tmp"
5004986ba33cSDag-Erling Smørgrav}
5005986ba33cSDag-Erling Smørgrav
50067b5038d7SDag-Erling Smørgrav# func_win32_libid arg
50077b5038d7SDag-Erling Smørgrav# return the library type of file 'arg'
50087b5038d7SDag-Erling Smørgrav#
50097b5038d7SDag-Erling Smørgrav# Need a lot of goo to handle *both* DLLs and import libs
50107b5038d7SDag-Erling Smørgrav# Has to be a shell function in order to 'eat' the argument
50117b5038d7SDag-Erling Smørgrav# that is supplied when $file_magic_command is called.
50127b5038d7SDag-Erling Smørgrav# Despite the name, also deal with 64 bit binaries.
50137b5038d7SDag-Erling Smørgravfunc_win32_libid ()
50147b5038d7SDag-Erling Smørgrav{
5015986ba33cSDag-Erling Smørgrav  $debug_cmd
5016986ba33cSDag-Erling Smørgrav
5017986ba33cSDag-Erling Smørgrav  win32_libid_type=unknown
50187b5038d7SDag-Erling Smørgrav  win32_fileres=`file -L $1 2>/dev/null`
50197b5038d7SDag-Erling Smørgrav  case $win32_fileres in
50207b5038d7SDag-Erling Smørgrav  *ar\ archive\ import\ library*) # definitely import
50217b5038d7SDag-Erling Smørgrav    win32_libid_type="x86 archive import"
50227b5038d7SDag-Erling Smørgrav    ;;
50237b5038d7SDag-Erling Smørgrav  *ar\ archive*) # could be an import, or static
50247b5038d7SDag-Erling Smørgrav    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.
50257b5038d7SDag-Erling Smørgrav    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |
50267b5038d7SDag-Erling Smørgrav       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then
5027986ba33cSDag-Erling Smørgrav      case $nm_interface in
5028986ba33cSDag-Erling Smørgrav      "MS dumpbin")
5029986ba33cSDag-Erling Smørgrav	if func_cygming_ms_implib_p "$1" ||
5030986ba33cSDag-Erling Smørgrav	   func_cygming_gnu_implib_p "$1"
5031986ba33cSDag-Erling Smørgrav	then
5032986ba33cSDag-Erling Smørgrav	  win32_nmres=import
5033986ba33cSDag-Erling Smørgrav	else
5034986ba33cSDag-Erling Smørgrav	  win32_nmres=
5035986ba33cSDag-Erling Smørgrav	fi
5036986ba33cSDag-Erling Smørgrav	;;
5037986ba33cSDag-Erling Smørgrav      *)
50387b5038d7SDag-Erling Smørgrav	func_to_tool_file "$1" func_convert_file_msys_to_w32
50397b5038d7SDag-Erling Smørgrav	win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" |
50407b5038d7SDag-Erling Smørgrav	  $SED -n -e '
50417b5038d7SDag-Erling Smørgrav	    1,100{
50427b5038d7SDag-Erling Smørgrav		/ I /{
5043986ba33cSDag-Erling Smørgrav		    s|.*|import|
50447b5038d7SDag-Erling Smørgrav		    p
50457b5038d7SDag-Erling Smørgrav		    q
50467b5038d7SDag-Erling Smørgrav		}
50477b5038d7SDag-Erling Smørgrav	    }'`
5048986ba33cSDag-Erling Smørgrav	;;
5049986ba33cSDag-Erling Smørgrav      esac
50507b5038d7SDag-Erling Smørgrav      case $win32_nmres in
50517b5038d7SDag-Erling Smørgrav      import*)  win32_libid_type="x86 archive import";;
50527b5038d7SDag-Erling Smørgrav      *)        win32_libid_type="x86 archive static";;
50537b5038d7SDag-Erling Smørgrav      esac
50547b5038d7SDag-Erling Smørgrav    fi
50557b5038d7SDag-Erling Smørgrav    ;;
50567b5038d7SDag-Erling Smørgrav  *DLL*)
50577b5038d7SDag-Erling Smørgrav    win32_libid_type="x86 DLL"
50587b5038d7SDag-Erling Smørgrav    ;;
50597b5038d7SDag-Erling Smørgrav  *executable*) # but shell scripts are "executable" too...
50607b5038d7SDag-Erling Smørgrav    case $win32_fileres in
50617b5038d7SDag-Erling Smørgrav    *MS\ Windows\ PE\ Intel*)
50627b5038d7SDag-Erling Smørgrav      win32_libid_type="x86 DLL"
50637b5038d7SDag-Erling Smørgrav      ;;
50647b5038d7SDag-Erling Smørgrav    esac
50657b5038d7SDag-Erling Smørgrav    ;;
50667b5038d7SDag-Erling Smørgrav  esac
50677b5038d7SDag-Erling Smørgrav  $ECHO "$win32_libid_type"
50687b5038d7SDag-Erling Smørgrav}
50697b5038d7SDag-Erling Smørgrav
50707b5038d7SDag-Erling Smørgrav# func_cygming_dll_for_implib ARG
50717b5038d7SDag-Erling Smørgrav#
50727b5038d7SDag-Erling Smørgrav# Platform-specific function to extract the
50737b5038d7SDag-Erling Smørgrav# name of the DLL associated with the specified
50747b5038d7SDag-Erling Smørgrav# import library ARG.
50757b5038d7SDag-Erling Smørgrav# Invoked by eval'ing the libtool variable
50767b5038d7SDag-Erling Smørgrav#    $sharedlib_from_linklib_cmd
50777b5038d7SDag-Erling Smørgrav# Result is available in the variable
50787b5038d7SDag-Erling Smørgrav#    $sharedlib_from_linklib_result
50797b5038d7SDag-Erling Smørgravfunc_cygming_dll_for_implib ()
50807b5038d7SDag-Erling Smørgrav{
5081986ba33cSDag-Erling Smørgrav  $debug_cmd
5082986ba33cSDag-Erling Smørgrav
50837b5038d7SDag-Erling Smørgrav  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"`
50847b5038d7SDag-Erling Smørgrav}
50857b5038d7SDag-Erling Smørgrav
50867b5038d7SDag-Erling Smørgrav# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs
50877b5038d7SDag-Erling Smørgrav#
50887b5038d7SDag-Erling Smørgrav# The is the core of a fallback implementation of a
50897b5038d7SDag-Erling Smørgrav# platform-specific function to extract the name of the
50907b5038d7SDag-Erling Smørgrav# DLL associated with the specified import library LIBNAME.
50917b5038d7SDag-Erling Smørgrav#
50927b5038d7SDag-Erling Smørgrav# SECTION_NAME is either .idata$6 or .idata$7, depending
50937b5038d7SDag-Erling Smørgrav# on the platform and compiler that created the implib.
50947b5038d7SDag-Erling Smørgrav#
50957b5038d7SDag-Erling Smørgrav# Echos the name of the DLL associated with the
50967b5038d7SDag-Erling Smørgrav# specified import library.
50977b5038d7SDag-Erling Smørgravfunc_cygming_dll_for_implib_fallback_core ()
50987b5038d7SDag-Erling Smørgrav{
5099986ba33cSDag-Erling Smørgrav  $debug_cmd
5100986ba33cSDag-Erling Smørgrav
51017b5038d7SDag-Erling Smørgrav  match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"`
51027b5038d7SDag-Erling Smørgrav  $OBJDUMP -s --section "$1" "$2" 2>/dev/null |
51037b5038d7SDag-Erling Smørgrav    $SED '/^Contents of section '"$match_literal"':/{
51047b5038d7SDag-Erling Smørgrav      # Place marker at beginning of archive member dllname section
51057b5038d7SDag-Erling Smørgrav      s/.*/====MARK====/
51067b5038d7SDag-Erling Smørgrav      p
51077b5038d7SDag-Erling Smørgrav      d
51087b5038d7SDag-Erling Smørgrav    }
51097b5038d7SDag-Erling Smørgrav    # These lines can sometimes be longer than 43 characters, but
51107b5038d7SDag-Erling Smørgrav    # are always uninteresting
51117b5038d7SDag-Erling Smørgrav    /:[	 ]*file format pe[i]\{,1\}-/d
51127b5038d7SDag-Erling Smørgrav    /^In archive [^:]*:/d
51137b5038d7SDag-Erling Smørgrav    # Ensure marker is printed
51147b5038d7SDag-Erling Smørgrav    /^====MARK====/p
51157b5038d7SDag-Erling Smørgrav    # Remove all lines with less than 43 characters
51167b5038d7SDag-Erling Smørgrav    /^.\{43\}/!d
51177b5038d7SDag-Erling Smørgrav    # From remaining lines, remove first 43 characters
51187b5038d7SDag-Erling Smørgrav    s/^.\{43\}//' |
51197b5038d7SDag-Erling Smørgrav    $SED -n '
51207b5038d7SDag-Erling Smørgrav      # Join marker and all lines until next marker into a single line
51217b5038d7SDag-Erling Smørgrav      /^====MARK====/ b para
51227b5038d7SDag-Erling Smørgrav      H
51237b5038d7SDag-Erling Smørgrav      $ b para
51247b5038d7SDag-Erling Smørgrav      b
51257b5038d7SDag-Erling Smørgrav      :para
51267b5038d7SDag-Erling Smørgrav      x
51277b5038d7SDag-Erling Smørgrav      s/\n//g
51287b5038d7SDag-Erling Smørgrav      # Remove the marker
51297b5038d7SDag-Erling Smørgrav      s/^====MARK====//
51307b5038d7SDag-Erling Smørgrav      # Remove trailing dots and whitespace
51317b5038d7SDag-Erling Smørgrav      s/[\. \t]*$//
51327b5038d7SDag-Erling Smørgrav      # Print
51337b5038d7SDag-Erling Smørgrav      /./p' |
51347b5038d7SDag-Erling Smørgrav    # we now have a list, one entry per line, of the stringified
51357b5038d7SDag-Erling Smørgrav    # contents of the appropriate section of all members of the
5136986ba33cSDag-Erling Smørgrav    # archive that possess that section. Heuristic: eliminate
5137986ba33cSDag-Erling Smørgrav    # all those that have a first or second character that is
51387b5038d7SDag-Erling Smørgrav    # a '.' (that is, objdump's representation of an unprintable
51397b5038d7SDag-Erling Smørgrav    # character.) This should work for all archives with less than
51407b5038d7SDag-Erling Smørgrav    # 0x302f exports -- but will fail for DLLs whose name actually
51417b5038d7SDag-Erling Smørgrav    # begins with a literal '.' or a single character followed by
51427b5038d7SDag-Erling Smørgrav    # a '.'.
51437b5038d7SDag-Erling Smørgrav    #
51447b5038d7SDag-Erling Smørgrav    # Of those that remain, print the first one.
51457b5038d7SDag-Erling Smørgrav    $SED -e '/^\./d;/^.\./d;q'
51467b5038d7SDag-Erling Smørgrav}
51477b5038d7SDag-Erling Smørgrav
51487b5038d7SDag-Erling Smørgrav# func_cygming_dll_for_implib_fallback ARG
51497b5038d7SDag-Erling Smørgrav# Platform-specific function to extract the
51507b5038d7SDag-Erling Smørgrav# name of the DLL associated with the specified
51517b5038d7SDag-Erling Smørgrav# import library ARG.
51527b5038d7SDag-Erling Smørgrav#
51537b5038d7SDag-Erling Smørgrav# This fallback implementation is for use when $DLLTOOL
51547b5038d7SDag-Erling Smørgrav# does not support the --identify-strict option.
51557b5038d7SDag-Erling Smørgrav# Invoked by eval'ing the libtool variable
51567b5038d7SDag-Erling Smørgrav#    $sharedlib_from_linklib_cmd
51577b5038d7SDag-Erling Smørgrav# Result is available in the variable
51587b5038d7SDag-Erling Smørgrav#    $sharedlib_from_linklib_result
51597b5038d7SDag-Erling Smørgravfunc_cygming_dll_for_implib_fallback ()
51607b5038d7SDag-Erling Smørgrav{
5161986ba33cSDag-Erling Smørgrav  $debug_cmd
5162986ba33cSDag-Erling Smørgrav
51637b5038d7SDag-Erling Smørgrav  if func_cygming_gnu_implib_p "$1"; then
51647b5038d7SDag-Erling Smørgrav    # binutils import library
51657b5038d7SDag-Erling Smørgrav    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"`
51667b5038d7SDag-Erling Smørgrav  elif func_cygming_ms_implib_p "$1"; then
51677b5038d7SDag-Erling Smørgrav    # ms-generated import library
51687b5038d7SDag-Erling Smørgrav    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"`
51697b5038d7SDag-Erling Smørgrav  else
51707b5038d7SDag-Erling Smørgrav    # unknown
5171986ba33cSDag-Erling Smørgrav    sharedlib_from_linklib_result=
51727b5038d7SDag-Erling Smørgrav  fi
51737b5038d7SDag-Erling Smørgrav}
51747b5038d7SDag-Erling Smørgrav
51757b5038d7SDag-Erling Smørgrav
51767b5038d7SDag-Erling Smørgrav# func_extract_an_archive dir oldlib
51777b5038d7SDag-Erling Smørgravfunc_extract_an_archive ()
51787b5038d7SDag-Erling Smørgrav{
5179986ba33cSDag-Erling Smørgrav    $debug_cmd
5180986ba33cSDag-Erling Smørgrav
5181986ba33cSDag-Erling Smørgrav    f_ex_an_ar_dir=$1; shift
5182986ba33cSDag-Erling Smørgrav    f_ex_an_ar_oldlib=$1
5183986ba33cSDag-Erling Smørgrav    if test yes = "$lock_old_archive_extraction"; then
51847b5038d7SDag-Erling Smørgrav      lockfile=$f_ex_an_ar_oldlib.lock
51857b5038d7SDag-Erling Smørgrav      until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do
51867b5038d7SDag-Erling Smørgrav	func_echo "Waiting for $lockfile to be removed"
51877b5038d7SDag-Erling Smørgrav	sleep 2
51887b5038d7SDag-Erling Smørgrav      done
51897b5038d7SDag-Erling Smørgrav    fi
51907b5038d7SDag-Erling Smørgrav    func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \
51917b5038d7SDag-Erling Smørgrav		   'stat=$?; rm -f "$lockfile"; exit $stat'
5192986ba33cSDag-Erling Smørgrav    if test yes = "$lock_old_archive_extraction"; then
51937b5038d7SDag-Erling Smørgrav      $opt_dry_run || rm -f "$lockfile"
51947b5038d7SDag-Erling Smørgrav    fi
51957b5038d7SDag-Erling Smørgrav    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
51967b5038d7SDag-Erling Smørgrav     :
51977b5038d7SDag-Erling Smørgrav    else
51987b5038d7SDag-Erling Smørgrav      func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib"
51997b5038d7SDag-Erling Smørgrav    fi
52007b5038d7SDag-Erling Smørgrav}
52017b5038d7SDag-Erling Smørgrav
52027b5038d7SDag-Erling Smørgrav
52037b5038d7SDag-Erling Smørgrav# func_extract_archives gentop oldlib ...
52047b5038d7SDag-Erling Smørgravfunc_extract_archives ()
52057b5038d7SDag-Erling Smørgrav{
5206986ba33cSDag-Erling Smørgrav    $debug_cmd
5207986ba33cSDag-Erling Smørgrav
5208986ba33cSDag-Erling Smørgrav    my_gentop=$1; shift
52097b5038d7SDag-Erling Smørgrav    my_oldlibs=${1+"$@"}
5210986ba33cSDag-Erling Smørgrav    my_oldobjs=
5211986ba33cSDag-Erling Smørgrav    my_xlib=
5212986ba33cSDag-Erling Smørgrav    my_xabs=
5213986ba33cSDag-Erling Smørgrav    my_xdir=
52147b5038d7SDag-Erling Smørgrav
52157b5038d7SDag-Erling Smørgrav    for my_xlib in $my_oldlibs; do
52167b5038d7SDag-Erling Smørgrav      # Extract the objects.
52177b5038d7SDag-Erling Smørgrav      case $my_xlib in
5218986ba33cSDag-Erling Smørgrav	[\\/]* | [A-Za-z]:[\\/]*) my_xabs=$my_xlib ;;
52197b5038d7SDag-Erling Smørgrav	*) my_xabs=`pwd`"/$my_xlib" ;;
52207b5038d7SDag-Erling Smørgrav      esac
52217b5038d7SDag-Erling Smørgrav      func_basename "$my_xlib"
5222986ba33cSDag-Erling Smørgrav      my_xlib=$func_basename_result
52237b5038d7SDag-Erling Smørgrav      my_xlib_u=$my_xlib
52247b5038d7SDag-Erling Smørgrav      while :; do
52257b5038d7SDag-Erling Smørgrav        case " $extracted_archives " in
52267b5038d7SDag-Erling Smørgrav	*" $my_xlib_u "*)
52277b5038d7SDag-Erling Smørgrav	  func_arith $extracted_serial + 1
52287b5038d7SDag-Erling Smørgrav	  extracted_serial=$func_arith_result
52297b5038d7SDag-Erling Smørgrav	  my_xlib_u=lt$extracted_serial-$my_xlib ;;
52307b5038d7SDag-Erling Smørgrav	*) break ;;
52317b5038d7SDag-Erling Smørgrav	esac
52327b5038d7SDag-Erling Smørgrav      done
52337b5038d7SDag-Erling Smørgrav      extracted_archives="$extracted_archives $my_xlib_u"
5234986ba33cSDag-Erling Smørgrav      my_xdir=$my_gentop/$my_xlib_u
52357b5038d7SDag-Erling Smørgrav
52367b5038d7SDag-Erling Smørgrav      func_mkdir_p "$my_xdir"
52377b5038d7SDag-Erling Smørgrav
52387b5038d7SDag-Erling Smørgrav      case $host in
52397b5038d7SDag-Erling Smørgrav      *-darwin*)
52407b5038d7SDag-Erling Smørgrav	func_verbose "Extracting $my_xabs"
52417b5038d7SDag-Erling Smørgrav	# Do not bother doing anything if just a dry run
52427b5038d7SDag-Erling Smørgrav	$opt_dry_run || {
52437b5038d7SDag-Erling Smørgrav	  darwin_orig_dir=`pwd`
52447b5038d7SDag-Erling Smørgrav	  cd $my_xdir || exit $?
52457b5038d7SDag-Erling Smørgrav	  darwin_archive=$my_xabs
52467b5038d7SDag-Erling Smørgrav	  darwin_curdir=`pwd`
5247986ba33cSDag-Erling Smørgrav	  func_basename "$darwin_archive"
5248986ba33cSDag-Erling Smørgrav	  darwin_base_archive=$func_basename_result
52497b5038d7SDag-Erling Smørgrav	  darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true`
52507b5038d7SDag-Erling Smørgrav	  if test -n "$darwin_arches"; then
52517b5038d7SDag-Erling Smørgrav	    darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'`
52527b5038d7SDag-Erling Smørgrav	    darwin_arch=
52537b5038d7SDag-Erling Smørgrav	    func_verbose "$darwin_base_archive has multiple architectures $darwin_arches"
52547b5038d7SDag-Erling Smørgrav	    for darwin_arch in  $darwin_arches; do
5255986ba33cSDag-Erling Smørgrav	      func_mkdir_p "unfat-$$/$darwin_base_archive-$darwin_arch"
5256986ba33cSDag-Erling Smørgrav	      $LIPO -thin $darwin_arch -output "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive" "$darwin_archive"
5257986ba33cSDag-Erling Smørgrav	      cd "unfat-$$/$darwin_base_archive-$darwin_arch"
5258986ba33cSDag-Erling Smørgrav	      func_extract_an_archive "`pwd`" "$darwin_base_archive"
52597b5038d7SDag-Erling Smørgrav	      cd "$darwin_curdir"
5260986ba33cSDag-Erling Smørgrav	      $RM "unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive"
52617b5038d7SDag-Erling Smørgrav	    done # $darwin_arches
52627b5038d7SDag-Erling Smørgrav            ## Okay now we've a bunch of thin objects, gotta fatten them up :)
5263986ba33cSDag-Erling Smørgrav	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$sed_basename" | sort -u`
52647b5038d7SDag-Erling Smørgrav	    darwin_file=
52657b5038d7SDag-Erling Smørgrav	    darwin_files=
52667b5038d7SDag-Erling Smørgrav	    for darwin_file in $darwin_filelist; do
52677b5038d7SDag-Erling Smørgrav	      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`
52687b5038d7SDag-Erling Smørgrav	      $LIPO -create -output "$darwin_file" $darwin_files
52697b5038d7SDag-Erling Smørgrav	    done # $darwin_filelist
52707b5038d7SDag-Erling Smørgrav	    $RM -rf unfat-$$
52717b5038d7SDag-Erling Smørgrav	    cd "$darwin_orig_dir"
52727b5038d7SDag-Erling Smørgrav	  else
52737b5038d7SDag-Erling Smørgrav	    cd $darwin_orig_dir
52747b5038d7SDag-Erling Smørgrav	    func_extract_an_archive "$my_xdir" "$my_xabs"
52757b5038d7SDag-Erling Smørgrav	  fi # $darwin_arches
52767b5038d7SDag-Erling Smørgrav	} # !$opt_dry_run
52777b5038d7SDag-Erling Smørgrav	;;
52787b5038d7SDag-Erling Smørgrav      *)
52797b5038d7SDag-Erling Smørgrav        func_extract_an_archive "$my_xdir" "$my_xabs"
52807b5038d7SDag-Erling Smørgrav	;;
52817b5038d7SDag-Erling Smørgrav      esac
52827b5038d7SDag-Erling Smørgrav      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP`
52837b5038d7SDag-Erling Smørgrav    done
52847b5038d7SDag-Erling Smørgrav
5285986ba33cSDag-Erling Smørgrav    func_extract_archives_result=$my_oldobjs
52867b5038d7SDag-Erling Smørgrav}
52877b5038d7SDag-Erling Smørgrav
52887b5038d7SDag-Erling Smørgrav
52897b5038d7SDag-Erling Smørgrav# func_emit_wrapper [arg=no]
52907b5038d7SDag-Erling Smørgrav#
52917b5038d7SDag-Erling Smørgrav# Emit a libtool wrapper script on stdout.
52927b5038d7SDag-Erling Smørgrav# Don't directly open a file because we may want to
52937b5038d7SDag-Erling Smørgrav# incorporate the script contents within a cygwin/mingw
52947b5038d7SDag-Erling Smørgrav# wrapper executable.  Must ONLY be called from within
52957b5038d7SDag-Erling Smørgrav# func_mode_link because it depends on a number of variables
52967b5038d7SDag-Erling Smørgrav# set therein.
52977b5038d7SDag-Erling Smørgrav#
52987b5038d7SDag-Erling Smørgrav# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR
52997b5038d7SDag-Erling Smørgrav# variable will take.  If 'yes', then the emitted script
5300986ba33cSDag-Erling Smørgrav# will assume that the directory where it is stored is
53017b5038d7SDag-Erling Smørgrav# the $objdir directory.  This is a cygwin/mingw-specific
53027b5038d7SDag-Erling Smørgrav# behavior.
53037b5038d7SDag-Erling Smørgravfunc_emit_wrapper ()
53047b5038d7SDag-Erling Smørgrav{
53057b5038d7SDag-Erling Smørgrav	func_emit_wrapper_arg1=${1-no}
53067b5038d7SDag-Erling Smørgrav
53077b5038d7SDag-Erling Smørgrav	$ECHO "\
53087b5038d7SDag-Erling Smørgrav#! $SHELL
53097b5038d7SDag-Erling Smørgrav
53107b5038d7SDag-Erling Smørgrav# $output - temporary wrapper script for $objdir/$outputname
5311986ba33cSDag-Erling Smørgrav# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
53127b5038d7SDag-Erling Smørgrav#
53137b5038d7SDag-Erling Smørgrav# The $output program cannot be directly executed until all the libtool
53147b5038d7SDag-Erling Smørgrav# libraries that it depends on are installed.
53157b5038d7SDag-Erling Smørgrav#
53167b5038d7SDag-Erling Smørgrav# This wrapper script should never be moved out of the build directory.
53177b5038d7SDag-Erling Smørgrav# If it is, it will not operate correctly.
53187b5038d7SDag-Erling Smørgrav
53197b5038d7SDag-Erling Smørgrav# Sed substitution that helps us do robust quoting.  It backslashifies
53207b5038d7SDag-Erling Smørgrav# metacharacters that are still active within double-quoted strings.
53217b5038d7SDag-Erling Smørgravsed_quote_subst='$sed_quote_subst'
53227b5038d7SDag-Erling Smørgrav
53237b5038d7SDag-Erling Smørgrav# Be Bourne compatible
53247b5038d7SDag-Erling Smørgravif test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then
53257b5038d7SDag-Erling Smørgrav  emulate sh
53267b5038d7SDag-Erling Smørgrav  NULLCMD=:
53277b5038d7SDag-Erling Smørgrav  # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which
53287b5038d7SDag-Erling Smørgrav  # is contrary to our usage.  Disable this feature.
53297b5038d7SDag-Erling Smørgrav  alias -g '\${1+\"\$@\"}'='\"\$@\"'
53307b5038d7SDag-Erling Smørgrav  setopt NO_GLOB_SUBST
53317b5038d7SDag-Erling Smørgravelse
53327b5038d7SDag-Erling Smørgrav  case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac
53337b5038d7SDag-Erling Smørgravfi
53347b5038d7SDag-Erling SmørgravBIN_SH=xpg4; export BIN_SH # for Tru64
53357b5038d7SDag-Erling SmørgravDUALCASE=1; export DUALCASE # for MKS sh
53367b5038d7SDag-Erling Smørgrav
53377b5038d7SDag-Erling Smørgrav# The HP-UX ksh and POSIX shell print the target directory to stdout
53387b5038d7SDag-Erling Smørgrav# if CDPATH is set.
53397b5038d7SDag-Erling Smørgrav(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
53407b5038d7SDag-Erling Smørgrav
53417b5038d7SDag-Erling Smørgravrelink_command=\"$relink_command\"
53427b5038d7SDag-Erling Smørgrav
53437b5038d7SDag-Erling Smørgrav# This environment variable determines our operation mode.
53447b5038d7SDag-Erling Smørgravif test \"\$libtool_install_magic\" = \"$magic\"; then
53457b5038d7SDag-Erling Smørgrav  # install mode needs the following variables:
53467b5038d7SDag-Erling Smørgrav  generated_by_libtool_version='$macro_version'
53477b5038d7SDag-Erling Smørgrav  notinst_deplibs='$notinst_deplibs'
53487b5038d7SDag-Erling Smørgravelse
53497b5038d7SDag-Erling Smørgrav  # When we are sourced in execute mode, \$file and \$ECHO are already set.
53507b5038d7SDag-Erling Smørgrav  if test \"\$libtool_execute_magic\" != \"$magic\"; then
53517b5038d7SDag-Erling Smørgrav    file=\"\$0\""
53527b5038d7SDag-Erling Smørgrav
53537b5038d7SDag-Erling Smørgrav    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
53547b5038d7SDag-Erling Smørgrav    $ECHO "\
53557b5038d7SDag-Erling Smørgrav
53567b5038d7SDag-Erling Smørgrav# A function that is used when there is no print builtin or printf.
53577b5038d7SDag-Erling Smørgravfunc_fallback_echo ()
53587b5038d7SDag-Erling Smørgrav{
53597b5038d7SDag-Erling Smørgrav  eval 'cat <<_LTECHO_EOF
53607b5038d7SDag-Erling Smørgrav\$1
53617b5038d7SDag-Erling Smørgrav_LTECHO_EOF'
53627b5038d7SDag-Erling Smørgrav}
53637b5038d7SDag-Erling Smørgrav    ECHO=\"$qECHO\"
53647b5038d7SDag-Erling Smørgrav  fi
53657b5038d7SDag-Erling Smørgrav
53667b5038d7SDag-Erling Smørgrav# Very basic option parsing. These options are (a) specific to
53677b5038d7SDag-Erling Smørgrav# the libtool wrapper, (b) are identical between the wrapper
5368986ba33cSDag-Erling Smørgrav# /script/ and the wrapper /executable/ that is used only on
53697b5038d7SDag-Erling Smørgrav# windows platforms, and (c) all begin with the string "--lt-"
5370986ba33cSDag-Erling Smørgrav# (application programs are unlikely to have options that match
53717b5038d7SDag-Erling Smørgrav# this pattern).
53727b5038d7SDag-Erling Smørgrav#
53737b5038d7SDag-Erling Smørgrav# There are only two supported options: --lt-debug and
53747b5038d7SDag-Erling Smørgrav# --lt-dump-script. There is, deliberately, no --lt-help.
53757b5038d7SDag-Erling Smørgrav#
53767b5038d7SDag-Erling Smørgrav# The first argument to this parsing function should be the
53777b5038d7SDag-Erling Smørgrav# script's $0 value, followed by "$@".
53787b5038d7SDag-Erling Smørgravlt_option_debug=
53797b5038d7SDag-Erling Smørgravfunc_parse_lt_options ()
53807b5038d7SDag-Erling Smørgrav{
53817b5038d7SDag-Erling Smørgrav  lt_script_arg0=\$0
53827b5038d7SDag-Erling Smørgrav  shift
53837b5038d7SDag-Erling Smørgrav  for lt_opt
53847b5038d7SDag-Erling Smørgrav  do
53857b5038d7SDag-Erling Smørgrav    case \"\$lt_opt\" in
53867b5038d7SDag-Erling Smørgrav    --lt-debug) lt_option_debug=1 ;;
53877b5038d7SDag-Erling Smørgrav    --lt-dump-script)
53887b5038d7SDag-Erling Smørgrav        lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\`
53897b5038d7SDag-Erling Smørgrav        test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=.
53907b5038d7SDag-Erling Smørgrav        lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\`
53917b5038d7SDag-Erling Smørgrav        cat \"\$lt_dump_D/\$lt_dump_F\"
53927b5038d7SDag-Erling Smørgrav        exit 0
53937b5038d7SDag-Erling Smørgrav      ;;
53947b5038d7SDag-Erling Smørgrav    --lt-*)
53957b5038d7SDag-Erling Smørgrav        \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2
53967b5038d7SDag-Erling Smørgrav        exit 1
53977b5038d7SDag-Erling Smørgrav      ;;
53987b5038d7SDag-Erling Smørgrav    esac
53997b5038d7SDag-Erling Smørgrav  done
54007b5038d7SDag-Erling Smørgrav
54017b5038d7SDag-Erling Smørgrav  # Print the debug banner immediately:
54027b5038d7SDag-Erling Smørgrav  if test -n \"\$lt_option_debug\"; then
5403986ba33cSDag-Erling Smørgrav    echo \"$outputname:$output:\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\" 1>&2
54047b5038d7SDag-Erling Smørgrav  fi
54057b5038d7SDag-Erling Smørgrav}
54067b5038d7SDag-Erling Smørgrav
54077b5038d7SDag-Erling Smørgrav# Used when --lt-debug. Prints its arguments to stdout
54087b5038d7SDag-Erling Smørgrav# (redirection is the responsibility of the caller)
54097b5038d7SDag-Erling Smørgravfunc_lt_dump_args ()
54107b5038d7SDag-Erling Smørgrav{
54117b5038d7SDag-Erling Smørgrav  lt_dump_args_N=1;
54127b5038d7SDag-Erling Smørgrav  for lt_arg
54137b5038d7SDag-Erling Smørgrav  do
5414986ba33cSDag-Erling Smørgrav    \$ECHO \"$outputname:$output:\$LINENO: newargv[\$lt_dump_args_N]: \$lt_arg\"
54157b5038d7SDag-Erling Smørgrav    lt_dump_args_N=\`expr \$lt_dump_args_N + 1\`
54167b5038d7SDag-Erling Smørgrav  done
54177b5038d7SDag-Erling Smørgrav}
54187b5038d7SDag-Erling Smørgrav
54197b5038d7SDag-Erling Smørgrav# Core function for launching the target application
54207b5038d7SDag-Erling Smørgravfunc_exec_program_core ()
54217b5038d7SDag-Erling Smørgrav{
54227b5038d7SDag-Erling Smørgrav"
54237b5038d7SDag-Erling Smørgrav  case $host in
54247b5038d7SDag-Erling Smørgrav  # Backslashes separate directories on plain windows
54257b5038d7SDag-Erling Smørgrav  *-*-mingw | *-*-os2* | *-cegcc*)
54267b5038d7SDag-Erling Smørgrav    $ECHO "\
54277b5038d7SDag-Erling Smørgrav      if test -n \"\$lt_option_debug\"; then
5428986ba33cSDag-Erling Smørgrav        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2
54297b5038d7SDag-Erling Smørgrav        func_lt_dump_args \${1+\"\$@\"} 1>&2
54307b5038d7SDag-Erling Smørgrav      fi
54317b5038d7SDag-Erling Smørgrav      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
54327b5038d7SDag-Erling Smørgrav"
54337b5038d7SDag-Erling Smørgrav    ;;
54347b5038d7SDag-Erling Smørgrav
54357b5038d7SDag-Erling Smørgrav  *)
54367b5038d7SDag-Erling Smørgrav    $ECHO "\
54377b5038d7SDag-Erling Smørgrav      if test -n \"\$lt_option_debug\"; then
5438986ba33cSDag-Erling Smørgrav        \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir/\$program\" 1>&2
54397b5038d7SDag-Erling Smørgrav        func_lt_dump_args \${1+\"\$@\"} 1>&2
54407b5038d7SDag-Erling Smørgrav      fi
54417b5038d7SDag-Erling Smørgrav      exec \"\$progdir/\$program\" \${1+\"\$@\"}
54427b5038d7SDag-Erling Smørgrav"
54437b5038d7SDag-Erling Smørgrav    ;;
54447b5038d7SDag-Erling Smørgrav  esac
54457b5038d7SDag-Erling Smørgrav  $ECHO "\
54467b5038d7SDag-Erling Smørgrav      \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2
54477b5038d7SDag-Erling Smørgrav      exit 1
54487b5038d7SDag-Erling Smørgrav}
54497b5038d7SDag-Erling Smørgrav
54507b5038d7SDag-Erling Smørgrav# A function to encapsulate launching the target application
54517b5038d7SDag-Erling Smørgrav# Strips options in the --lt-* namespace from \$@ and
54527b5038d7SDag-Erling Smørgrav# launches target application with the remaining arguments.
54537b5038d7SDag-Erling Smørgravfunc_exec_program ()
54547b5038d7SDag-Erling Smørgrav{
54557b5038d7SDag-Erling Smørgrav  case \" \$* \" in
54567b5038d7SDag-Erling Smørgrav  *\\ --lt-*)
54577b5038d7SDag-Erling Smørgrav    for lt_wr_arg
54587b5038d7SDag-Erling Smørgrav    do
54597b5038d7SDag-Erling Smørgrav      case \$lt_wr_arg in
54607b5038d7SDag-Erling Smørgrav      --lt-*) ;;
54617b5038d7SDag-Erling Smørgrav      *) set x \"\$@\" \"\$lt_wr_arg\"; shift;;
54627b5038d7SDag-Erling Smørgrav      esac
54637b5038d7SDag-Erling Smørgrav      shift
54647b5038d7SDag-Erling Smørgrav    done ;;
54657b5038d7SDag-Erling Smørgrav  esac
54667b5038d7SDag-Erling Smørgrav  func_exec_program_core \${1+\"\$@\"}
54677b5038d7SDag-Erling Smørgrav}
54687b5038d7SDag-Erling Smørgrav
54697b5038d7SDag-Erling Smørgrav  # Parse options
54707b5038d7SDag-Erling Smørgrav  func_parse_lt_options \"\$0\" \${1+\"\$@\"}
54717b5038d7SDag-Erling Smørgrav
54727b5038d7SDag-Erling Smørgrav  # Find the directory that this script lives in.
54737b5038d7SDag-Erling Smørgrav  thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\`
54747b5038d7SDag-Erling Smørgrav  test \"x\$thisdir\" = \"x\$file\" && thisdir=.
54757b5038d7SDag-Erling Smørgrav
54767b5038d7SDag-Erling Smørgrav  # Follow symbolic links until we get to the real thisdir.
54777b5038d7SDag-Erling Smørgrav  file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\`
54787b5038d7SDag-Erling Smørgrav  while test -n \"\$file\"; do
54797b5038d7SDag-Erling Smørgrav    destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\`
54807b5038d7SDag-Erling Smørgrav
54817b5038d7SDag-Erling Smørgrav    # If there was a directory component, then change thisdir.
54827b5038d7SDag-Erling Smørgrav    if test \"x\$destdir\" != \"x\$file\"; then
54837b5038d7SDag-Erling Smørgrav      case \"\$destdir\" in
54847b5038d7SDag-Erling Smørgrav      [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;;
54857b5038d7SDag-Erling Smørgrav      *) thisdir=\"\$thisdir/\$destdir\" ;;
54867b5038d7SDag-Erling Smørgrav      esac
54877b5038d7SDag-Erling Smørgrav    fi
54887b5038d7SDag-Erling Smørgrav
54897b5038d7SDag-Erling Smørgrav    file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\`
54907b5038d7SDag-Erling Smørgrav    file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\`
54917b5038d7SDag-Erling Smørgrav  done
54927b5038d7SDag-Erling Smørgrav
54937b5038d7SDag-Erling Smørgrav  # Usually 'no', except on cygwin/mingw when embedded into
54947b5038d7SDag-Erling Smørgrav  # the cwrapper.
54957b5038d7SDag-Erling Smørgrav  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1
54967b5038d7SDag-Erling Smørgrav  if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then
54977b5038d7SDag-Erling Smørgrav    # special case for '.'
54987b5038d7SDag-Erling Smørgrav    if test \"\$thisdir\" = \".\"; then
54997b5038d7SDag-Erling Smørgrav      thisdir=\`pwd\`
55007b5038d7SDag-Erling Smørgrav    fi
55017b5038d7SDag-Erling Smørgrav    # remove .libs from thisdir
55027b5038d7SDag-Erling Smørgrav    case \"\$thisdir\" in
55037b5038d7SDag-Erling Smørgrav    *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;;
55047b5038d7SDag-Erling Smørgrav    $objdir )   thisdir=. ;;
55057b5038d7SDag-Erling Smørgrav    esac
55067b5038d7SDag-Erling Smørgrav  fi
55077b5038d7SDag-Erling Smørgrav
55087b5038d7SDag-Erling Smørgrav  # Try to get the absolute directory name.
55097b5038d7SDag-Erling Smørgrav  absdir=\`cd \"\$thisdir\" && pwd\`
55107b5038d7SDag-Erling Smørgrav  test -n \"\$absdir\" && thisdir=\"\$absdir\"
55117b5038d7SDag-Erling Smørgrav"
55127b5038d7SDag-Erling Smørgrav
5513986ba33cSDag-Erling Smørgrav	if test yes = "$fast_install"; then
55147b5038d7SDag-Erling Smørgrav	  $ECHO "\
55157b5038d7SDag-Erling Smørgrav  program=lt-'$outputname'$exeext
55167b5038d7SDag-Erling Smørgrav  progdir=\"\$thisdir/$objdir\"
55177b5038d7SDag-Erling Smørgrav
55187b5038d7SDag-Erling Smørgrav  if test ! -f \"\$progdir/\$program\" ||
5519986ba33cSDag-Erling Smørgrav     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | $SED 1q\`; \\
55207b5038d7SDag-Erling Smørgrav       test \"X\$file\" != \"X\$progdir/\$program\"; }; then
55217b5038d7SDag-Erling Smørgrav
55227b5038d7SDag-Erling Smørgrav    file=\"\$\$-\$program\"
55237b5038d7SDag-Erling Smørgrav
55247b5038d7SDag-Erling Smørgrav    if test ! -d \"\$progdir\"; then
55257b5038d7SDag-Erling Smørgrav      $MKDIR \"\$progdir\"
55267b5038d7SDag-Erling Smørgrav    else
55277b5038d7SDag-Erling Smørgrav      $RM \"\$progdir/\$file\"
55287b5038d7SDag-Erling Smørgrav    fi"
55297b5038d7SDag-Erling Smørgrav
55307b5038d7SDag-Erling Smørgrav	  $ECHO "\
55317b5038d7SDag-Erling Smørgrav
55327b5038d7SDag-Erling Smørgrav    # relink executable if necessary
55337b5038d7SDag-Erling Smørgrav    if test -n \"\$relink_command\"; then
55347b5038d7SDag-Erling Smørgrav      if relink_command_output=\`eval \$relink_command 2>&1\`; then :
55357b5038d7SDag-Erling Smørgrav      else
5536986ba33cSDag-Erling Smørgrav	\$ECHO \"\$relink_command_output\" >&2
55377b5038d7SDag-Erling Smørgrav	$RM \"\$progdir/\$file\"
55387b5038d7SDag-Erling Smørgrav	exit 1
55397b5038d7SDag-Erling Smørgrav      fi
55407b5038d7SDag-Erling Smørgrav    fi
55417b5038d7SDag-Erling Smørgrav
55427b5038d7SDag-Erling Smørgrav    $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null ||
55437b5038d7SDag-Erling Smørgrav    { $RM \"\$progdir/\$program\";
55447b5038d7SDag-Erling Smørgrav      $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; }
55457b5038d7SDag-Erling Smørgrav    $RM \"\$progdir/\$file\"
55467b5038d7SDag-Erling Smørgrav  fi"
55477b5038d7SDag-Erling Smørgrav	else
55487b5038d7SDag-Erling Smørgrav	  $ECHO "\
55497b5038d7SDag-Erling Smørgrav  program='$outputname'
55507b5038d7SDag-Erling Smørgrav  progdir=\"\$thisdir/$objdir\"
55517b5038d7SDag-Erling Smørgrav"
55527b5038d7SDag-Erling Smørgrav	fi
55537b5038d7SDag-Erling Smørgrav
55547b5038d7SDag-Erling Smørgrav	$ECHO "\
55557b5038d7SDag-Erling Smørgrav
55567b5038d7SDag-Erling Smørgrav  if test -f \"\$progdir/\$program\"; then"
55577b5038d7SDag-Erling Smørgrav
55587b5038d7SDag-Erling Smørgrav	# fixup the dll searchpath if we need to.
55597b5038d7SDag-Erling Smørgrav	#
55607b5038d7SDag-Erling Smørgrav	# Fix the DLL searchpath if we need to.  Do this before prepending
55617b5038d7SDag-Erling Smørgrav	# to shlibpath, because on Windows, both are PATH and uninstalled
55627b5038d7SDag-Erling Smørgrav	# libraries must come first.
55637b5038d7SDag-Erling Smørgrav	if test -n "$dllsearchpath"; then
55647b5038d7SDag-Erling Smørgrav	  $ECHO "\
55657b5038d7SDag-Erling Smørgrav    # Add the dll search path components to the executable PATH
55667b5038d7SDag-Erling Smørgrav    PATH=$dllsearchpath:\$PATH
55677b5038d7SDag-Erling Smørgrav"
55687b5038d7SDag-Erling Smørgrav	fi
55697b5038d7SDag-Erling Smørgrav
55707b5038d7SDag-Erling Smørgrav	# Export our shlibpath_var if we have one.
5571986ba33cSDag-Erling Smørgrav	if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
55727b5038d7SDag-Erling Smørgrav	  $ECHO "\
55737b5038d7SDag-Erling Smørgrav    # Add our own library path to $shlibpath_var
55747b5038d7SDag-Erling Smørgrav    $shlibpath_var=\"$temp_rpath\$$shlibpath_var\"
55757b5038d7SDag-Erling Smørgrav
55767b5038d7SDag-Erling Smørgrav    # Some systems cannot cope with colon-terminated $shlibpath_var
55777b5038d7SDag-Erling Smørgrav    # The second colon is a workaround for a bug in BeOS R4 sed
55787b5038d7SDag-Erling Smørgrav    $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\`
55797b5038d7SDag-Erling Smørgrav
55807b5038d7SDag-Erling Smørgrav    export $shlibpath_var
55817b5038d7SDag-Erling Smørgrav"
55827b5038d7SDag-Erling Smørgrav	fi
55837b5038d7SDag-Erling Smørgrav
55847b5038d7SDag-Erling Smørgrav	$ECHO "\
55857b5038d7SDag-Erling Smørgrav    if test \"\$libtool_execute_magic\" != \"$magic\"; then
55867b5038d7SDag-Erling Smørgrav      # Run the actual program with our arguments.
55877b5038d7SDag-Erling Smørgrav      func_exec_program \${1+\"\$@\"}
55887b5038d7SDag-Erling Smørgrav    fi
55897b5038d7SDag-Erling Smørgrav  else
55907b5038d7SDag-Erling Smørgrav    # The program doesn't exist.
5591986ba33cSDag-Erling Smørgrav    \$ECHO \"\$0: error: '\$progdir/\$program' does not exist\" 1>&2
55927b5038d7SDag-Erling Smørgrav    \$ECHO \"This script is just a wrapper for \$program.\" 1>&2
55937b5038d7SDag-Erling Smørgrav    \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2
55947b5038d7SDag-Erling Smørgrav    exit 1
55957b5038d7SDag-Erling Smørgrav  fi
55967b5038d7SDag-Erling Smørgravfi\
55977b5038d7SDag-Erling Smørgrav"
55987b5038d7SDag-Erling Smørgrav}
55997b5038d7SDag-Erling Smørgrav
56007b5038d7SDag-Erling Smørgrav
56017b5038d7SDag-Erling Smørgrav# func_emit_cwrapperexe_src
56027b5038d7SDag-Erling Smørgrav# emit the source code for a wrapper executable on stdout
56037b5038d7SDag-Erling Smørgrav# Must ONLY be called from within func_mode_link because
56047b5038d7SDag-Erling Smørgrav# it depends on a number of variable set therein.
56057b5038d7SDag-Erling Smørgravfunc_emit_cwrapperexe_src ()
56067b5038d7SDag-Erling Smørgrav{
56077b5038d7SDag-Erling Smørgrav	cat <<EOF
56087b5038d7SDag-Erling Smørgrav
56097b5038d7SDag-Erling Smørgrav/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
5610986ba33cSDag-Erling Smørgrav   Generated by $PROGRAM (GNU $PACKAGE) $VERSION
56117b5038d7SDag-Erling Smørgrav
56127b5038d7SDag-Erling Smørgrav   The $output program cannot be directly executed until all the libtool
56137b5038d7SDag-Erling Smørgrav   libraries that it depends on are installed.
56147b5038d7SDag-Erling Smørgrav
56157b5038d7SDag-Erling Smørgrav   This wrapper executable should never be moved out of the build directory.
56167b5038d7SDag-Erling Smørgrav   If it is, it will not operate correctly.
56177b5038d7SDag-Erling Smørgrav*/
56187b5038d7SDag-Erling SmørgravEOF
56197b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
56207b5038d7SDag-Erling Smørgrav#ifdef _MSC_VER
56217b5038d7SDag-Erling Smørgrav# define _CRT_SECURE_NO_DEPRECATE 1
56227b5038d7SDag-Erling Smørgrav#endif
56237b5038d7SDag-Erling Smørgrav#include <stdio.h>
56247b5038d7SDag-Erling Smørgrav#include <stdlib.h>
56257b5038d7SDag-Erling Smørgrav#ifdef _MSC_VER
56267b5038d7SDag-Erling Smørgrav# include <direct.h>
56277b5038d7SDag-Erling Smørgrav# include <process.h>
56287b5038d7SDag-Erling Smørgrav# include <io.h>
56297b5038d7SDag-Erling Smørgrav#else
56307b5038d7SDag-Erling Smørgrav# include <unistd.h>
56317b5038d7SDag-Erling Smørgrav# include <stdint.h>
56327b5038d7SDag-Erling Smørgrav# ifdef __CYGWIN__
56337b5038d7SDag-Erling Smørgrav#  include <io.h>
56347b5038d7SDag-Erling Smørgrav# endif
56357b5038d7SDag-Erling Smørgrav#endif
56367b5038d7SDag-Erling Smørgrav#include <malloc.h>
56377b5038d7SDag-Erling Smørgrav#include <stdarg.h>
56387b5038d7SDag-Erling Smørgrav#include <assert.h>
56397b5038d7SDag-Erling Smørgrav#include <string.h>
56407b5038d7SDag-Erling Smørgrav#include <ctype.h>
56417b5038d7SDag-Erling Smørgrav#include <errno.h>
56427b5038d7SDag-Erling Smørgrav#include <fcntl.h>
56437b5038d7SDag-Erling Smørgrav#include <sys/stat.h>
56447b5038d7SDag-Erling Smørgrav
5645986ba33cSDag-Erling Smørgrav#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)
5646986ba33cSDag-Erling Smørgrav
56477b5038d7SDag-Erling Smørgrav/* declarations of non-ANSI functions */
5648986ba33cSDag-Erling Smørgrav#if defined __MINGW32__
56497b5038d7SDag-Erling Smørgrav# ifdef __STRICT_ANSI__
56507b5038d7SDag-Erling Smørgravint _putenv (const char *);
56517b5038d7SDag-Erling Smørgrav# endif
5652986ba33cSDag-Erling Smørgrav#elif defined __CYGWIN__
56537b5038d7SDag-Erling Smørgrav# ifdef __STRICT_ANSI__
56547b5038d7SDag-Erling Smørgravchar *realpath (const char *, char *);
56557b5038d7SDag-Erling Smørgravint putenv (char *);
56567b5038d7SDag-Erling Smørgravint setenv (const char *, const char *, int);
56577b5038d7SDag-Erling Smørgrav# endif
5658986ba33cSDag-Erling Smørgrav/* #elif defined other_platform || defined ... */
56597b5038d7SDag-Erling Smørgrav#endif
56607b5038d7SDag-Erling Smørgrav
56617b5038d7SDag-Erling Smørgrav/* portability defines, excluding path handling macros */
5662986ba33cSDag-Erling Smørgrav#if defined _MSC_VER
56637b5038d7SDag-Erling Smørgrav# define setmode _setmode
56647b5038d7SDag-Erling Smørgrav# define stat    _stat
56657b5038d7SDag-Erling Smørgrav# define chmod   _chmod
56667b5038d7SDag-Erling Smørgrav# define getcwd  _getcwd
56677b5038d7SDag-Erling Smørgrav# define putenv  _putenv
56687b5038d7SDag-Erling Smørgrav# define S_IXUSR _S_IEXEC
5669986ba33cSDag-Erling Smørgrav#elif defined __MINGW32__
56707b5038d7SDag-Erling Smørgrav# define setmode _setmode
56717b5038d7SDag-Erling Smørgrav# define stat    _stat
56727b5038d7SDag-Erling Smørgrav# define chmod   _chmod
56737b5038d7SDag-Erling Smørgrav# define getcwd  _getcwd
56747b5038d7SDag-Erling Smørgrav# define putenv  _putenv
5675986ba33cSDag-Erling Smørgrav#elif defined __CYGWIN__
56767b5038d7SDag-Erling Smørgrav# define HAVE_SETENV
56777b5038d7SDag-Erling Smørgrav# define FOPEN_WB "wb"
5678986ba33cSDag-Erling Smørgrav/* #elif defined other platforms ... */
56797b5038d7SDag-Erling Smørgrav#endif
56807b5038d7SDag-Erling Smørgrav
5681986ba33cSDag-Erling Smørgrav#if defined PATH_MAX
56827b5038d7SDag-Erling Smørgrav# define LT_PATHMAX PATH_MAX
5683986ba33cSDag-Erling Smørgrav#elif defined MAXPATHLEN
56847b5038d7SDag-Erling Smørgrav# define LT_PATHMAX MAXPATHLEN
56857b5038d7SDag-Erling Smørgrav#else
56867b5038d7SDag-Erling Smørgrav# define LT_PATHMAX 1024
56877b5038d7SDag-Erling Smørgrav#endif
56887b5038d7SDag-Erling Smørgrav
56897b5038d7SDag-Erling Smørgrav#ifndef S_IXOTH
56907b5038d7SDag-Erling Smørgrav# define S_IXOTH 0
56917b5038d7SDag-Erling Smørgrav#endif
56927b5038d7SDag-Erling Smørgrav#ifndef S_IXGRP
56937b5038d7SDag-Erling Smørgrav# define S_IXGRP 0
56947b5038d7SDag-Erling Smørgrav#endif
56957b5038d7SDag-Erling Smørgrav
56967b5038d7SDag-Erling Smørgrav/* path handling portability macros */
56977b5038d7SDag-Erling Smørgrav#ifndef DIR_SEPARATOR
56987b5038d7SDag-Erling Smørgrav# define DIR_SEPARATOR '/'
56997b5038d7SDag-Erling Smørgrav# define PATH_SEPARATOR ':'
57007b5038d7SDag-Erling Smørgrav#endif
57017b5038d7SDag-Erling Smørgrav
5702986ba33cSDag-Erling Smørgrav#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \
5703986ba33cSDag-Erling Smørgrav  defined __OS2__
57047b5038d7SDag-Erling Smørgrav# define HAVE_DOS_BASED_FILE_SYSTEM
57057b5038d7SDag-Erling Smørgrav# define FOPEN_WB "wb"
57067b5038d7SDag-Erling Smørgrav# ifndef DIR_SEPARATOR_2
57077b5038d7SDag-Erling Smørgrav#  define DIR_SEPARATOR_2 '\\'
57087b5038d7SDag-Erling Smørgrav# endif
57097b5038d7SDag-Erling Smørgrav# ifndef PATH_SEPARATOR_2
57107b5038d7SDag-Erling Smørgrav#  define PATH_SEPARATOR_2 ';'
57117b5038d7SDag-Erling Smørgrav# endif
57127b5038d7SDag-Erling Smørgrav#endif
57137b5038d7SDag-Erling Smørgrav
57147b5038d7SDag-Erling Smørgrav#ifndef DIR_SEPARATOR_2
57157b5038d7SDag-Erling Smørgrav# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
57167b5038d7SDag-Erling Smørgrav#else /* DIR_SEPARATOR_2 */
57177b5038d7SDag-Erling Smørgrav# define IS_DIR_SEPARATOR(ch) \
57187b5038d7SDag-Erling Smørgrav	(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
57197b5038d7SDag-Erling Smørgrav#endif /* DIR_SEPARATOR_2 */
57207b5038d7SDag-Erling Smørgrav
57217b5038d7SDag-Erling Smørgrav#ifndef PATH_SEPARATOR_2
57227b5038d7SDag-Erling Smørgrav# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
57237b5038d7SDag-Erling Smørgrav#else /* PATH_SEPARATOR_2 */
57247b5038d7SDag-Erling Smørgrav# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
57257b5038d7SDag-Erling Smørgrav#endif /* PATH_SEPARATOR_2 */
57267b5038d7SDag-Erling Smørgrav
57277b5038d7SDag-Erling Smørgrav#ifndef FOPEN_WB
57287b5038d7SDag-Erling Smørgrav# define FOPEN_WB "w"
57297b5038d7SDag-Erling Smørgrav#endif
57307b5038d7SDag-Erling Smørgrav#ifndef _O_BINARY
57317b5038d7SDag-Erling Smørgrav# define _O_BINARY 0
57327b5038d7SDag-Erling Smørgrav#endif
57337b5038d7SDag-Erling Smørgrav
57347b5038d7SDag-Erling Smørgrav#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
57357b5038d7SDag-Erling Smørgrav#define XFREE(stale) do { \
5736986ba33cSDag-Erling Smørgrav  if (stale) { free (stale); stale = 0; } \
57377b5038d7SDag-Erling Smørgrav} while (0)
57387b5038d7SDag-Erling Smørgrav
5739986ba33cSDag-Erling Smørgrav#if defined LT_DEBUGWRAPPER
57407b5038d7SDag-Erling Smørgravstatic int lt_debug = 1;
57417b5038d7SDag-Erling Smørgrav#else
57427b5038d7SDag-Erling Smørgravstatic int lt_debug = 0;
57437b5038d7SDag-Erling Smørgrav#endif
57447b5038d7SDag-Erling Smørgrav
57457b5038d7SDag-Erling Smørgravconst char *program_name = "libtool-wrapper"; /* in case xstrdup fails */
57467b5038d7SDag-Erling Smørgrav
57477b5038d7SDag-Erling Smørgravvoid *xmalloc (size_t num);
57487b5038d7SDag-Erling Smørgravchar *xstrdup (const char *string);
57497b5038d7SDag-Erling Smørgravconst char *base_name (const char *name);
57507b5038d7SDag-Erling Smørgravchar *find_executable (const char *wrapper);
57517b5038d7SDag-Erling Smørgravchar *chase_symlinks (const char *pathspec);
57527b5038d7SDag-Erling Smørgravint make_executable (const char *path);
57537b5038d7SDag-Erling Smørgravint check_executable (const char *path);
57547b5038d7SDag-Erling Smørgravchar *strendzap (char *str, const char *pat);
57557b5038d7SDag-Erling Smørgravvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);
57567b5038d7SDag-Erling Smørgravvoid lt_fatal (const char *file, int line, const char *message, ...);
57577b5038d7SDag-Erling Smørgravstatic const char *nonnull (const char *s);
57587b5038d7SDag-Erling Smørgravstatic const char *nonempty (const char *s);
57597b5038d7SDag-Erling Smørgravvoid lt_setenv (const char *name, const char *value);
57607b5038d7SDag-Erling Smørgravchar *lt_extend_str (const char *orig_value, const char *add, int to_end);
57617b5038d7SDag-Erling Smørgravvoid lt_update_exe_path (const char *name, const char *value);
57627b5038d7SDag-Erling Smørgravvoid lt_update_lib_path (const char *name, const char *value);
57637b5038d7SDag-Erling Smørgravchar **prepare_spawn (char **argv);
57647b5038d7SDag-Erling Smørgravvoid lt_dump_script (FILE *f);
57657b5038d7SDag-Erling SmørgravEOF
57667b5038d7SDag-Erling Smørgrav
57677b5038d7SDag-Erling Smørgrav	    cat <<EOF
5768986ba33cSDag-Erling Smørgrav#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
5769986ba33cSDag-Erling Smørgrav# define externally_visible volatile
5770986ba33cSDag-Erling Smørgrav#else
5771986ba33cSDag-Erling Smørgrav# define externally_visible __attribute__((externally_visible)) volatile
5772986ba33cSDag-Erling Smørgrav#endif
5773986ba33cSDag-Erling Smørgravexternally_visible const char * MAGIC_EXE = "$magic_exe";
57747b5038d7SDag-Erling Smørgravconst char * LIB_PATH_VARNAME = "$shlibpath_var";
57757b5038d7SDag-Erling SmørgravEOF
57767b5038d7SDag-Erling Smørgrav
5777986ba33cSDag-Erling Smørgrav	    if test yes = "$shlibpath_overrides_runpath" && test -n "$shlibpath_var" && test -n "$temp_rpath"; then
57787b5038d7SDag-Erling Smørgrav              func_to_host_path "$temp_rpath"
57797b5038d7SDag-Erling Smørgrav	      cat <<EOF
57807b5038d7SDag-Erling Smørgravconst char * LIB_PATH_VALUE   = "$func_to_host_path_result";
57817b5038d7SDag-Erling SmørgravEOF
57827b5038d7SDag-Erling Smørgrav	    else
57837b5038d7SDag-Erling Smørgrav	      cat <<"EOF"
57847b5038d7SDag-Erling Smørgravconst char * LIB_PATH_VALUE   = "";
57857b5038d7SDag-Erling SmørgravEOF
57867b5038d7SDag-Erling Smørgrav	    fi
57877b5038d7SDag-Erling Smørgrav
57887b5038d7SDag-Erling Smørgrav	    if test -n "$dllsearchpath"; then
57897b5038d7SDag-Erling Smørgrav              func_to_host_path "$dllsearchpath:"
57907b5038d7SDag-Erling Smørgrav	      cat <<EOF
57917b5038d7SDag-Erling Smørgravconst char * EXE_PATH_VARNAME = "PATH";
57927b5038d7SDag-Erling Smørgravconst char * EXE_PATH_VALUE   = "$func_to_host_path_result";
57937b5038d7SDag-Erling SmørgravEOF
57947b5038d7SDag-Erling Smørgrav	    else
57957b5038d7SDag-Erling Smørgrav	      cat <<"EOF"
57967b5038d7SDag-Erling Smørgravconst char * EXE_PATH_VARNAME = "";
57977b5038d7SDag-Erling Smørgravconst char * EXE_PATH_VALUE   = "";
57987b5038d7SDag-Erling SmørgravEOF
57997b5038d7SDag-Erling Smørgrav	    fi
58007b5038d7SDag-Erling Smørgrav
5801986ba33cSDag-Erling Smørgrav	    if test yes = "$fast_install"; then
58027b5038d7SDag-Erling Smørgrav	      cat <<EOF
58037b5038d7SDag-Erling Smørgravconst char * TARGET_PROGRAM_NAME = "lt-$outputname"; /* hopefully, no .exe */
58047b5038d7SDag-Erling SmørgravEOF
58057b5038d7SDag-Erling Smørgrav	    else
58067b5038d7SDag-Erling Smørgrav	      cat <<EOF
58077b5038d7SDag-Erling Smørgravconst char * TARGET_PROGRAM_NAME = "$outputname"; /* hopefully, no .exe */
58087b5038d7SDag-Erling SmørgravEOF
58097b5038d7SDag-Erling Smørgrav	    fi
58107b5038d7SDag-Erling Smørgrav
58117b5038d7SDag-Erling Smørgrav
58127b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
58137b5038d7SDag-Erling Smørgrav
58147b5038d7SDag-Erling Smørgrav#define LTWRAPPER_OPTION_PREFIX         "--lt-"
58157b5038d7SDag-Erling Smørgrav
58167b5038d7SDag-Erling Smørgravstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;
58177b5038d7SDag-Erling Smørgravstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX "dump-script";
58187b5038d7SDag-Erling Smørgravstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX "debug";
58197b5038d7SDag-Erling Smørgrav
58207b5038d7SDag-Erling Smørgravint
58217b5038d7SDag-Erling Smørgravmain (int argc, char *argv[])
58227b5038d7SDag-Erling Smørgrav{
58237b5038d7SDag-Erling Smørgrav  char **newargz;
58247b5038d7SDag-Erling Smørgrav  int  newargc;
58257b5038d7SDag-Erling Smørgrav  char *tmp_pathspec;
58267b5038d7SDag-Erling Smørgrav  char *actual_cwrapper_path;
58277b5038d7SDag-Erling Smørgrav  char *actual_cwrapper_name;
58287b5038d7SDag-Erling Smørgrav  char *target_name;
58297b5038d7SDag-Erling Smørgrav  char *lt_argv_zero;
5830986ba33cSDag-Erling Smørgrav  int rval = 127;
58317b5038d7SDag-Erling Smørgrav
58327b5038d7SDag-Erling Smørgrav  int i;
58337b5038d7SDag-Erling Smørgrav
58347b5038d7SDag-Erling Smørgrav  program_name = (char *) xstrdup (base_name (argv[0]));
5835986ba33cSDag-Erling Smørgrav  newargz = XMALLOC (char *, (size_t) argc + 1);
58367b5038d7SDag-Erling Smørgrav
58377b5038d7SDag-Erling Smørgrav  /* very simple arg parsing; don't want to rely on getopt
58387b5038d7SDag-Erling Smørgrav   * also, copy all non cwrapper options to newargz, except
58397b5038d7SDag-Erling Smørgrav   * argz[0], which is handled differently
58407b5038d7SDag-Erling Smørgrav   */
58417b5038d7SDag-Erling Smørgrav  newargc=0;
58427b5038d7SDag-Erling Smørgrav  for (i = 1; i < argc; i++)
58437b5038d7SDag-Erling Smørgrav    {
5844986ba33cSDag-Erling Smørgrav      if (STREQ (argv[i], dumpscript_opt))
58457b5038d7SDag-Erling Smørgrav	{
58467b5038d7SDag-Erling SmørgravEOF
5847986ba33cSDag-Erling Smørgrav	    case $host in
58487b5038d7SDag-Erling Smørgrav	      *mingw* | *cygwin* )
58497b5038d7SDag-Erling Smørgrav		# make stdout use "unix" line endings
58507b5038d7SDag-Erling Smørgrav		echo "          setmode(1,_O_BINARY);"
58517b5038d7SDag-Erling Smørgrav		;;
58527b5038d7SDag-Erling Smørgrav	      esac
58537b5038d7SDag-Erling Smørgrav
58547b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
58557b5038d7SDag-Erling Smørgrav	  lt_dump_script (stdout);
58567b5038d7SDag-Erling Smørgrav	  return 0;
58577b5038d7SDag-Erling Smørgrav	}
5858986ba33cSDag-Erling Smørgrav      if (STREQ (argv[i], debug_opt))
58597b5038d7SDag-Erling Smørgrav	{
58607b5038d7SDag-Erling Smørgrav          lt_debug = 1;
58617b5038d7SDag-Erling Smørgrav          continue;
58627b5038d7SDag-Erling Smørgrav	}
5863986ba33cSDag-Erling Smørgrav      if (STREQ (argv[i], ltwrapper_option_prefix))
58647b5038d7SDag-Erling Smørgrav        {
58657b5038d7SDag-Erling Smørgrav          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX
58667b5038d7SDag-Erling Smørgrav             namespace, but it is not one of the ones we know about and
58677b5038d7SDag-Erling Smørgrav             have already dealt with, above (inluding dump-script), then
58687b5038d7SDag-Erling Smørgrav             report an error. Otherwise, targets might begin to believe
58697b5038d7SDag-Erling Smørgrav             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX
58707b5038d7SDag-Erling Smørgrav             namespace. The first time any user complains about this, we'll
58717b5038d7SDag-Erling Smørgrav             need to make LTWRAPPER_OPTION_PREFIX a configure-time option
58727b5038d7SDag-Erling Smørgrav             or a configure.ac-settable value.
58737b5038d7SDag-Erling Smørgrav           */
58747b5038d7SDag-Erling Smørgrav          lt_fatal (__FILE__, __LINE__,
58757b5038d7SDag-Erling Smørgrav		    "unrecognized %s option: '%s'",
58767b5038d7SDag-Erling Smørgrav                    ltwrapper_option_prefix, argv[i]);
58777b5038d7SDag-Erling Smørgrav        }
58787b5038d7SDag-Erling Smørgrav      /* otherwise ... */
58797b5038d7SDag-Erling Smørgrav      newargz[++newargc] = xstrdup (argv[i]);
58807b5038d7SDag-Erling Smørgrav    }
58817b5038d7SDag-Erling Smørgrav  newargz[++newargc] = NULL;
58827b5038d7SDag-Erling Smørgrav
58837b5038d7SDag-Erling SmørgravEOF
58847b5038d7SDag-Erling Smørgrav	    cat <<EOF
58857b5038d7SDag-Erling Smørgrav  /* The GNU banner must be the first non-error debug message */
5886986ba33cSDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__, "libtool wrapper (GNU $PACKAGE) $VERSION\n");
58877b5038d7SDag-Erling SmørgravEOF
58887b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
58897b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__, "(main) argv[0]: %s\n", argv[0]);
58907b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__, "(main) program_name: %s\n", program_name);
58917b5038d7SDag-Erling Smørgrav
58927b5038d7SDag-Erling Smørgrav  tmp_pathspec = find_executable (argv[0]);
58937b5038d7SDag-Erling Smørgrav  if (tmp_pathspec == NULL)
58947b5038d7SDag-Erling Smørgrav    lt_fatal (__FILE__, __LINE__, "couldn't find %s", argv[0]);
58957b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__,
58967b5038d7SDag-Erling Smørgrav                  "(main) found exe (before symlink chase) at: %s\n",
58977b5038d7SDag-Erling Smørgrav		  tmp_pathspec);
58987b5038d7SDag-Erling Smørgrav
58997b5038d7SDag-Erling Smørgrav  actual_cwrapper_path = chase_symlinks (tmp_pathspec);
59007b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__,
59017b5038d7SDag-Erling Smørgrav                  "(main) found exe (after symlink chase) at: %s\n",
59027b5038d7SDag-Erling Smørgrav		  actual_cwrapper_path);
59037b5038d7SDag-Erling Smørgrav  XFREE (tmp_pathspec);
59047b5038d7SDag-Erling Smørgrav
59057b5038d7SDag-Erling Smørgrav  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));
59067b5038d7SDag-Erling Smørgrav  strendzap (actual_cwrapper_path, actual_cwrapper_name);
59077b5038d7SDag-Erling Smørgrav
59087b5038d7SDag-Erling Smørgrav  /* wrapper name transforms */
59097b5038d7SDag-Erling Smørgrav  strendzap (actual_cwrapper_name, ".exe");
59107b5038d7SDag-Erling Smørgrav  tmp_pathspec = lt_extend_str (actual_cwrapper_name, ".exe", 1);
59117b5038d7SDag-Erling Smørgrav  XFREE (actual_cwrapper_name);
59127b5038d7SDag-Erling Smørgrav  actual_cwrapper_name = tmp_pathspec;
59137b5038d7SDag-Erling Smørgrav  tmp_pathspec = 0;
59147b5038d7SDag-Erling Smørgrav
59157b5038d7SDag-Erling Smørgrav  /* target_name transforms -- use actual target program name; might have lt- prefix */
59167b5038d7SDag-Erling Smørgrav  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));
59177b5038d7SDag-Erling Smørgrav  strendzap (target_name, ".exe");
59187b5038d7SDag-Erling Smørgrav  tmp_pathspec = lt_extend_str (target_name, ".exe", 1);
59197b5038d7SDag-Erling Smørgrav  XFREE (target_name);
59207b5038d7SDag-Erling Smørgrav  target_name = tmp_pathspec;
59217b5038d7SDag-Erling Smørgrav  tmp_pathspec = 0;
59227b5038d7SDag-Erling Smørgrav
59237b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__,
59247b5038d7SDag-Erling Smørgrav		  "(main) libtool target name: %s\n",
59257b5038d7SDag-Erling Smørgrav		  target_name);
59267b5038d7SDag-Erling SmørgravEOF
59277b5038d7SDag-Erling Smørgrav
59287b5038d7SDag-Erling Smørgrav	    cat <<EOF
59297b5038d7SDag-Erling Smørgrav  newargz[0] =
59307b5038d7SDag-Erling Smørgrav    XMALLOC (char, (strlen (actual_cwrapper_path) +
59317b5038d7SDag-Erling Smørgrav		    strlen ("$objdir") + 1 + strlen (actual_cwrapper_name) + 1));
59327b5038d7SDag-Erling Smørgrav  strcpy (newargz[0], actual_cwrapper_path);
59337b5038d7SDag-Erling Smørgrav  strcat (newargz[0], "$objdir");
59347b5038d7SDag-Erling Smørgrav  strcat (newargz[0], "/");
59357b5038d7SDag-Erling SmørgravEOF
59367b5038d7SDag-Erling Smørgrav
59377b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
59387b5038d7SDag-Erling Smørgrav  /* stop here, and copy so we don't have to do this twice */
59397b5038d7SDag-Erling Smørgrav  tmp_pathspec = xstrdup (newargz[0]);
59407b5038d7SDag-Erling Smørgrav
59417b5038d7SDag-Erling Smørgrav  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */
59427b5038d7SDag-Erling Smørgrav  strcat (newargz[0], actual_cwrapper_name);
59437b5038d7SDag-Erling Smørgrav
59447b5038d7SDag-Erling Smørgrav  /* DO want the lt- prefix here if it exists, so use target_name */
59457b5038d7SDag-Erling Smørgrav  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);
59467b5038d7SDag-Erling Smørgrav  XFREE (tmp_pathspec);
59477b5038d7SDag-Erling Smørgrav  tmp_pathspec = NULL;
59487b5038d7SDag-Erling SmørgravEOF
59497b5038d7SDag-Erling Smørgrav
59507b5038d7SDag-Erling Smørgrav	    case $host_os in
59517b5038d7SDag-Erling Smørgrav	      mingw*)
59527b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
59537b5038d7SDag-Erling Smørgrav  {
59547b5038d7SDag-Erling Smørgrav    char* p;
59557b5038d7SDag-Erling Smørgrav    while ((p = strchr (newargz[0], '\\')) != NULL)
59567b5038d7SDag-Erling Smørgrav      {
59577b5038d7SDag-Erling Smørgrav	*p = '/';
59587b5038d7SDag-Erling Smørgrav      }
59597b5038d7SDag-Erling Smørgrav    while ((p = strchr (lt_argv_zero, '\\')) != NULL)
59607b5038d7SDag-Erling Smørgrav      {
59617b5038d7SDag-Erling Smørgrav	*p = '/';
59627b5038d7SDag-Erling Smørgrav      }
59637b5038d7SDag-Erling Smørgrav  }
59647b5038d7SDag-Erling SmørgravEOF
59657b5038d7SDag-Erling Smørgrav	    ;;
59667b5038d7SDag-Erling Smørgrav	    esac
59677b5038d7SDag-Erling Smørgrav
59687b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
59697b5038d7SDag-Erling Smørgrav  XFREE (target_name);
59707b5038d7SDag-Erling Smørgrav  XFREE (actual_cwrapper_path);
59717b5038d7SDag-Erling Smørgrav  XFREE (actual_cwrapper_name);
59727b5038d7SDag-Erling Smørgrav
59737b5038d7SDag-Erling Smørgrav  lt_setenv ("BIN_SH", "xpg4"); /* for Tru64 */
59747b5038d7SDag-Erling Smørgrav  lt_setenv ("DUALCASE", "1");  /* for MSK sh */
59757b5038d7SDag-Erling Smørgrav  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must
59767b5038d7SDag-Erling Smørgrav     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)
59777b5038d7SDag-Erling Smørgrav     because on Windows, both *_VARNAMEs are PATH but uninstalled
59787b5038d7SDag-Erling Smørgrav     libraries must come first. */
59797b5038d7SDag-Erling Smørgrav  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);
59807b5038d7SDag-Erling Smørgrav  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);
59817b5038d7SDag-Erling Smørgrav
59827b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__, "(main) lt_argv_zero: %s\n",
59837b5038d7SDag-Erling Smørgrav		  nonnull (lt_argv_zero));
59847b5038d7SDag-Erling Smørgrav  for (i = 0; i < newargc; i++)
59857b5038d7SDag-Erling Smørgrav    {
59867b5038d7SDag-Erling Smørgrav      lt_debugprintf (__FILE__, __LINE__, "(main) newargz[%d]: %s\n",
59877b5038d7SDag-Erling Smørgrav		      i, nonnull (newargz[i]));
59887b5038d7SDag-Erling Smørgrav    }
59897b5038d7SDag-Erling Smørgrav
59907b5038d7SDag-Erling SmørgravEOF
59917b5038d7SDag-Erling Smørgrav
59927b5038d7SDag-Erling Smørgrav	    case $host_os in
59937b5038d7SDag-Erling Smørgrav	      mingw*)
59947b5038d7SDag-Erling Smørgrav		cat <<"EOF"
59957b5038d7SDag-Erling Smørgrav  /* execv doesn't actually work on mingw as expected on unix */
59967b5038d7SDag-Erling Smørgrav  newargz = prepare_spawn (newargz);
5997986ba33cSDag-Erling Smørgrav  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
59987b5038d7SDag-Erling Smørgrav  if (rval == -1)
59997b5038d7SDag-Erling Smørgrav    {
60007b5038d7SDag-Erling Smørgrav      /* failed to start process */
60017b5038d7SDag-Erling Smørgrav      lt_debugprintf (__FILE__, __LINE__,
60027b5038d7SDag-Erling Smørgrav		      "(main) failed to launch target \"%s\": %s\n",
60037b5038d7SDag-Erling Smørgrav		      lt_argv_zero, nonnull (strerror (errno)));
60047b5038d7SDag-Erling Smørgrav      return 127;
60057b5038d7SDag-Erling Smørgrav    }
60067b5038d7SDag-Erling Smørgrav  return rval;
60077b5038d7SDag-Erling SmørgravEOF
60087b5038d7SDag-Erling Smørgrav		;;
60097b5038d7SDag-Erling Smørgrav	      *)
60107b5038d7SDag-Erling Smørgrav		cat <<"EOF"
60117b5038d7SDag-Erling Smørgrav  execv (lt_argv_zero, newargz);
60127b5038d7SDag-Erling Smørgrav  return rval; /* =127, but avoids unused variable warning */
60137b5038d7SDag-Erling SmørgravEOF
60147b5038d7SDag-Erling Smørgrav		;;
60157b5038d7SDag-Erling Smørgrav	    esac
60167b5038d7SDag-Erling Smørgrav
60177b5038d7SDag-Erling Smørgrav	    cat <<"EOF"
60187b5038d7SDag-Erling Smørgrav}
60197b5038d7SDag-Erling Smørgrav
60207b5038d7SDag-Erling Smørgravvoid *
60217b5038d7SDag-Erling Smørgravxmalloc (size_t num)
60227b5038d7SDag-Erling Smørgrav{
60237b5038d7SDag-Erling Smørgrav  void *p = (void *) malloc (num);
60247b5038d7SDag-Erling Smørgrav  if (!p)
60257b5038d7SDag-Erling Smørgrav    lt_fatal (__FILE__, __LINE__, "memory exhausted");
60267b5038d7SDag-Erling Smørgrav
60277b5038d7SDag-Erling Smørgrav  return p;
60287b5038d7SDag-Erling Smørgrav}
60297b5038d7SDag-Erling Smørgrav
60307b5038d7SDag-Erling Smørgravchar *
60317b5038d7SDag-Erling Smørgravxstrdup (const char *string)
60327b5038d7SDag-Erling Smørgrav{
60337b5038d7SDag-Erling Smørgrav  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),
60347b5038d7SDag-Erling Smørgrav			  string) : NULL;
60357b5038d7SDag-Erling Smørgrav}
60367b5038d7SDag-Erling Smørgrav
60377b5038d7SDag-Erling Smørgravconst char *
60387b5038d7SDag-Erling Smørgravbase_name (const char *name)
60397b5038d7SDag-Erling Smørgrav{
60407b5038d7SDag-Erling Smørgrav  const char *base;
60417b5038d7SDag-Erling Smørgrav
6042986ba33cSDag-Erling Smørgrav#if defined HAVE_DOS_BASED_FILE_SYSTEM
60437b5038d7SDag-Erling Smørgrav  /* Skip over the disk name in MSDOS pathnames. */
60447b5038d7SDag-Erling Smørgrav  if (isalpha ((unsigned char) name[0]) && name[1] == ':')
60457b5038d7SDag-Erling Smørgrav    name += 2;
60467b5038d7SDag-Erling Smørgrav#endif
60477b5038d7SDag-Erling Smørgrav
60487b5038d7SDag-Erling Smørgrav  for (base = name; *name; name++)
60497b5038d7SDag-Erling Smørgrav    if (IS_DIR_SEPARATOR (*name))
60507b5038d7SDag-Erling Smørgrav      base = name + 1;
60517b5038d7SDag-Erling Smørgrav  return base;
60527b5038d7SDag-Erling Smørgrav}
60537b5038d7SDag-Erling Smørgrav
60547b5038d7SDag-Erling Smørgravint
60557b5038d7SDag-Erling Smørgravcheck_executable (const char *path)
60567b5038d7SDag-Erling Smørgrav{
60577b5038d7SDag-Erling Smørgrav  struct stat st;
60587b5038d7SDag-Erling Smørgrav
60597b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__, "(check_executable): %s\n",
60607b5038d7SDag-Erling Smørgrav                  nonempty (path));
60617b5038d7SDag-Erling Smørgrav  if ((!path) || (!*path))
60627b5038d7SDag-Erling Smørgrav    return 0;
60637b5038d7SDag-Erling Smørgrav
60647b5038d7SDag-Erling Smørgrav  if ((stat (path, &st) >= 0)
60657b5038d7SDag-Erling Smørgrav      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
60667b5038d7SDag-Erling Smørgrav    return 1;
60677b5038d7SDag-Erling Smørgrav  else
60687b5038d7SDag-Erling Smørgrav    return 0;
60697b5038d7SDag-Erling Smørgrav}
60707b5038d7SDag-Erling Smørgrav
60717b5038d7SDag-Erling Smørgravint
60727b5038d7SDag-Erling Smørgravmake_executable (const char *path)
60737b5038d7SDag-Erling Smørgrav{
60747b5038d7SDag-Erling Smørgrav  int rval = 0;
60757b5038d7SDag-Erling Smørgrav  struct stat st;
60767b5038d7SDag-Erling Smørgrav
60777b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n",
60787b5038d7SDag-Erling Smørgrav                  nonempty (path));
60797b5038d7SDag-Erling Smørgrav  if ((!path) || (!*path))
60807b5038d7SDag-Erling Smørgrav    return 0;
60817b5038d7SDag-Erling Smørgrav
60827b5038d7SDag-Erling Smørgrav  if (stat (path, &st) >= 0)
60837b5038d7SDag-Erling Smørgrav    {
60847b5038d7SDag-Erling Smørgrav      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);
60857b5038d7SDag-Erling Smørgrav    }
60867b5038d7SDag-Erling Smørgrav  return rval;
60877b5038d7SDag-Erling Smørgrav}
60887b5038d7SDag-Erling Smørgrav
60897b5038d7SDag-Erling Smørgrav/* Searches for the full path of the wrapper.  Returns
60907b5038d7SDag-Erling Smørgrav   newly allocated full path name if found, NULL otherwise
60917b5038d7SDag-Erling Smørgrav   Does not chase symlinks, even on platforms that support them.
60927b5038d7SDag-Erling Smørgrav*/
60937b5038d7SDag-Erling Smørgravchar *
60947b5038d7SDag-Erling Smørgravfind_executable (const char *wrapper)
60957b5038d7SDag-Erling Smørgrav{
60967b5038d7SDag-Erling Smørgrav  int has_slash = 0;
60977b5038d7SDag-Erling Smørgrav  const char *p;
60987b5038d7SDag-Erling Smørgrav  const char *p_next;
60997b5038d7SDag-Erling Smørgrav  /* static buffer for getcwd */
61007b5038d7SDag-Erling Smørgrav  char tmp[LT_PATHMAX + 1];
6101986ba33cSDag-Erling Smørgrav  size_t tmp_len;
61027b5038d7SDag-Erling Smørgrav  char *concat_name;
61037b5038d7SDag-Erling Smørgrav
61047b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n",
61057b5038d7SDag-Erling Smørgrav                  nonempty (wrapper));
61067b5038d7SDag-Erling Smørgrav
61077b5038d7SDag-Erling Smørgrav  if ((wrapper == NULL) || (*wrapper == '\0'))
61087b5038d7SDag-Erling Smørgrav    return NULL;
61097b5038d7SDag-Erling Smørgrav
61107b5038d7SDag-Erling Smørgrav  /* Absolute path? */
6111986ba33cSDag-Erling Smørgrav#if defined HAVE_DOS_BASED_FILE_SYSTEM
61127b5038d7SDag-Erling Smørgrav  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')
61137b5038d7SDag-Erling Smørgrav    {
61147b5038d7SDag-Erling Smørgrav      concat_name = xstrdup (wrapper);
61157b5038d7SDag-Erling Smørgrav      if (check_executable (concat_name))
61167b5038d7SDag-Erling Smørgrav	return concat_name;
61177b5038d7SDag-Erling Smørgrav      XFREE (concat_name);
61187b5038d7SDag-Erling Smørgrav    }
61197b5038d7SDag-Erling Smørgrav  else
61207b5038d7SDag-Erling Smørgrav    {
61217b5038d7SDag-Erling Smørgrav#endif
61227b5038d7SDag-Erling Smørgrav      if (IS_DIR_SEPARATOR (wrapper[0]))
61237b5038d7SDag-Erling Smørgrav	{
61247b5038d7SDag-Erling Smørgrav	  concat_name = xstrdup (wrapper);
61257b5038d7SDag-Erling Smørgrav	  if (check_executable (concat_name))
61267b5038d7SDag-Erling Smørgrav	    return concat_name;
61277b5038d7SDag-Erling Smørgrav	  XFREE (concat_name);
61287b5038d7SDag-Erling Smørgrav	}
6129986ba33cSDag-Erling Smørgrav#if defined HAVE_DOS_BASED_FILE_SYSTEM
61307b5038d7SDag-Erling Smørgrav    }
61317b5038d7SDag-Erling Smørgrav#endif
61327b5038d7SDag-Erling Smørgrav
61337b5038d7SDag-Erling Smørgrav  for (p = wrapper; *p; p++)
61347b5038d7SDag-Erling Smørgrav    if (*p == '/')
61357b5038d7SDag-Erling Smørgrav      {
61367b5038d7SDag-Erling Smørgrav	has_slash = 1;
61377b5038d7SDag-Erling Smørgrav	break;
61387b5038d7SDag-Erling Smørgrav      }
61397b5038d7SDag-Erling Smørgrav  if (!has_slash)
61407b5038d7SDag-Erling Smørgrav    {
61417b5038d7SDag-Erling Smørgrav      /* no slashes; search PATH */
61427b5038d7SDag-Erling Smørgrav      const char *path = getenv ("PATH");
61437b5038d7SDag-Erling Smørgrav      if (path != NULL)
61447b5038d7SDag-Erling Smørgrav	{
61457b5038d7SDag-Erling Smørgrav	  for (p = path; *p; p = p_next)
61467b5038d7SDag-Erling Smørgrav	    {
61477b5038d7SDag-Erling Smørgrav	      const char *q;
61487b5038d7SDag-Erling Smørgrav	      size_t p_len;
61497b5038d7SDag-Erling Smørgrav	      for (q = p; *q; q++)
61507b5038d7SDag-Erling Smørgrav		if (IS_PATH_SEPARATOR (*q))
61517b5038d7SDag-Erling Smørgrav		  break;
6152986ba33cSDag-Erling Smørgrav	      p_len = (size_t) (q - p);
61537b5038d7SDag-Erling Smørgrav	      p_next = (*q == '\0' ? q : q + 1);
61547b5038d7SDag-Erling Smørgrav	      if (p_len == 0)
61557b5038d7SDag-Erling Smørgrav		{
61567b5038d7SDag-Erling Smørgrav		  /* empty path: current directory */
61577b5038d7SDag-Erling Smørgrav		  if (getcwd (tmp, LT_PATHMAX) == NULL)
61587b5038d7SDag-Erling Smørgrav		    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
61597b5038d7SDag-Erling Smørgrav                              nonnull (strerror (errno)));
61607b5038d7SDag-Erling Smørgrav		  tmp_len = strlen (tmp);
61617b5038d7SDag-Erling Smørgrav		  concat_name =
61627b5038d7SDag-Erling Smørgrav		    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
61637b5038d7SDag-Erling Smørgrav		  memcpy (concat_name, tmp, tmp_len);
61647b5038d7SDag-Erling Smørgrav		  concat_name[tmp_len] = '/';
61657b5038d7SDag-Erling Smørgrav		  strcpy (concat_name + tmp_len + 1, wrapper);
61667b5038d7SDag-Erling Smørgrav		}
61677b5038d7SDag-Erling Smørgrav	      else
61687b5038d7SDag-Erling Smørgrav		{
61697b5038d7SDag-Erling Smørgrav		  concat_name =
61707b5038d7SDag-Erling Smørgrav		    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);
61717b5038d7SDag-Erling Smørgrav		  memcpy (concat_name, p, p_len);
61727b5038d7SDag-Erling Smørgrav		  concat_name[p_len] = '/';
61737b5038d7SDag-Erling Smørgrav		  strcpy (concat_name + p_len + 1, wrapper);
61747b5038d7SDag-Erling Smørgrav		}
61757b5038d7SDag-Erling Smørgrav	      if (check_executable (concat_name))
61767b5038d7SDag-Erling Smørgrav		return concat_name;
61777b5038d7SDag-Erling Smørgrav	      XFREE (concat_name);
61787b5038d7SDag-Erling Smørgrav	    }
61797b5038d7SDag-Erling Smørgrav	}
61807b5038d7SDag-Erling Smørgrav      /* not found in PATH; assume curdir */
61817b5038d7SDag-Erling Smørgrav    }
61827b5038d7SDag-Erling Smørgrav  /* Relative path | not found in path: prepend cwd */
61837b5038d7SDag-Erling Smørgrav  if (getcwd (tmp, LT_PATHMAX) == NULL)
61847b5038d7SDag-Erling Smørgrav    lt_fatal (__FILE__, __LINE__, "getcwd failed: %s",
61857b5038d7SDag-Erling Smørgrav              nonnull (strerror (errno)));
61867b5038d7SDag-Erling Smørgrav  tmp_len = strlen (tmp);
61877b5038d7SDag-Erling Smørgrav  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);
61887b5038d7SDag-Erling Smørgrav  memcpy (concat_name, tmp, tmp_len);
61897b5038d7SDag-Erling Smørgrav  concat_name[tmp_len] = '/';
61907b5038d7SDag-Erling Smørgrav  strcpy (concat_name + tmp_len + 1, wrapper);
61917b5038d7SDag-Erling Smørgrav
61927b5038d7SDag-Erling Smørgrav  if (check_executable (concat_name))
61937b5038d7SDag-Erling Smørgrav    return concat_name;
61947b5038d7SDag-Erling Smørgrav  XFREE (concat_name);
61957b5038d7SDag-Erling Smørgrav  return NULL;
61967b5038d7SDag-Erling Smørgrav}
61977b5038d7SDag-Erling Smørgrav
61987b5038d7SDag-Erling Smørgravchar *
61997b5038d7SDag-Erling Smørgravchase_symlinks (const char *pathspec)
62007b5038d7SDag-Erling Smørgrav{
62017b5038d7SDag-Erling Smørgrav#ifndef S_ISLNK
62027b5038d7SDag-Erling Smørgrav  return xstrdup (pathspec);
62037b5038d7SDag-Erling Smørgrav#else
62047b5038d7SDag-Erling Smørgrav  char buf[LT_PATHMAX];
62057b5038d7SDag-Erling Smørgrav  struct stat s;
62067b5038d7SDag-Erling Smørgrav  char *tmp_pathspec = xstrdup (pathspec);
62077b5038d7SDag-Erling Smørgrav  char *p;
62087b5038d7SDag-Erling Smørgrav  int has_symlinks = 0;
62097b5038d7SDag-Erling Smørgrav  while (strlen (tmp_pathspec) && !has_symlinks)
62107b5038d7SDag-Erling Smørgrav    {
62117b5038d7SDag-Erling Smørgrav      lt_debugprintf (__FILE__, __LINE__,
62127b5038d7SDag-Erling Smørgrav		      "checking path component for symlinks: %s\n",
62137b5038d7SDag-Erling Smørgrav		      tmp_pathspec);
62147b5038d7SDag-Erling Smørgrav      if (lstat (tmp_pathspec, &s) == 0)
62157b5038d7SDag-Erling Smørgrav	{
62167b5038d7SDag-Erling Smørgrav	  if (S_ISLNK (s.st_mode) != 0)
62177b5038d7SDag-Erling Smørgrav	    {
62187b5038d7SDag-Erling Smørgrav	      has_symlinks = 1;
62197b5038d7SDag-Erling Smørgrav	      break;
62207b5038d7SDag-Erling Smørgrav	    }
62217b5038d7SDag-Erling Smørgrav
62227b5038d7SDag-Erling Smørgrav	  /* search backwards for last DIR_SEPARATOR */
62237b5038d7SDag-Erling Smørgrav	  p = tmp_pathspec + strlen (tmp_pathspec) - 1;
62247b5038d7SDag-Erling Smørgrav	  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
62257b5038d7SDag-Erling Smørgrav	    p--;
62267b5038d7SDag-Erling Smørgrav	  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))
62277b5038d7SDag-Erling Smørgrav	    {
62287b5038d7SDag-Erling Smørgrav	      /* no more DIR_SEPARATORS left */
62297b5038d7SDag-Erling Smørgrav	      break;
62307b5038d7SDag-Erling Smørgrav	    }
62317b5038d7SDag-Erling Smørgrav	  *p = '\0';
62327b5038d7SDag-Erling Smørgrav	}
62337b5038d7SDag-Erling Smørgrav      else
62347b5038d7SDag-Erling Smørgrav	{
62357b5038d7SDag-Erling Smørgrav	  lt_fatal (__FILE__, __LINE__,
62367b5038d7SDag-Erling Smørgrav		    "error accessing file \"%s\": %s",
62377b5038d7SDag-Erling Smørgrav		    tmp_pathspec, nonnull (strerror (errno)));
62387b5038d7SDag-Erling Smørgrav	}
62397b5038d7SDag-Erling Smørgrav    }
62407b5038d7SDag-Erling Smørgrav  XFREE (tmp_pathspec);
62417b5038d7SDag-Erling Smørgrav
62427b5038d7SDag-Erling Smørgrav  if (!has_symlinks)
62437b5038d7SDag-Erling Smørgrav    {
62447b5038d7SDag-Erling Smørgrav      return xstrdup (pathspec);
62457b5038d7SDag-Erling Smørgrav    }
62467b5038d7SDag-Erling Smørgrav
62477b5038d7SDag-Erling Smørgrav  tmp_pathspec = realpath (pathspec, buf);
62487b5038d7SDag-Erling Smørgrav  if (tmp_pathspec == 0)
62497b5038d7SDag-Erling Smørgrav    {
62507b5038d7SDag-Erling Smørgrav      lt_fatal (__FILE__, __LINE__,
62517b5038d7SDag-Erling Smørgrav		"could not follow symlinks for %s", pathspec);
62527b5038d7SDag-Erling Smørgrav    }
62537b5038d7SDag-Erling Smørgrav  return xstrdup (tmp_pathspec);
62547b5038d7SDag-Erling Smørgrav#endif
62557b5038d7SDag-Erling Smørgrav}
62567b5038d7SDag-Erling Smørgrav
62577b5038d7SDag-Erling Smørgravchar *
62587b5038d7SDag-Erling Smørgravstrendzap (char *str, const char *pat)
62597b5038d7SDag-Erling Smørgrav{
62607b5038d7SDag-Erling Smørgrav  size_t len, patlen;
62617b5038d7SDag-Erling Smørgrav
62627b5038d7SDag-Erling Smørgrav  assert (str != NULL);
62637b5038d7SDag-Erling Smørgrav  assert (pat != NULL);
62647b5038d7SDag-Erling Smørgrav
62657b5038d7SDag-Erling Smørgrav  len = strlen (str);
62667b5038d7SDag-Erling Smørgrav  patlen = strlen (pat);
62677b5038d7SDag-Erling Smørgrav
62687b5038d7SDag-Erling Smørgrav  if (patlen <= len)
62697b5038d7SDag-Erling Smørgrav    {
62707b5038d7SDag-Erling Smørgrav      str += len - patlen;
6271986ba33cSDag-Erling Smørgrav      if (STREQ (str, pat))
62727b5038d7SDag-Erling Smørgrav	*str = '\0';
62737b5038d7SDag-Erling Smørgrav    }
62747b5038d7SDag-Erling Smørgrav  return str;
62757b5038d7SDag-Erling Smørgrav}
62767b5038d7SDag-Erling Smørgrav
62777b5038d7SDag-Erling Smørgravvoid
62787b5038d7SDag-Erling Smørgravlt_debugprintf (const char *file, int line, const char *fmt, ...)
62797b5038d7SDag-Erling Smørgrav{
62807b5038d7SDag-Erling Smørgrav  va_list args;
62817b5038d7SDag-Erling Smørgrav  if (lt_debug)
62827b5038d7SDag-Erling Smørgrav    {
62837b5038d7SDag-Erling Smørgrav      (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line);
62847b5038d7SDag-Erling Smørgrav      va_start (args, fmt);
62857b5038d7SDag-Erling Smørgrav      (void) vfprintf (stderr, fmt, args);
62867b5038d7SDag-Erling Smørgrav      va_end (args);
62877b5038d7SDag-Erling Smørgrav    }
62887b5038d7SDag-Erling Smørgrav}
62897b5038d7SDag-Erling Smørgrav
62907b5038d7SDag-Erling Smørgravstatic void
62917b5038d7SDag-Erling Smørgravlt_error_core (int exit_status, const char *file,
62927b5038d7SDag-Erling Smørgrav	       int line, const char *mode,
62937b5038d7SDag-Erling Smørgrav	       const char *message, va_list ap)
62947b5038d7SDag-Erling Smørgrav{
62957b5038d7SDag-Erling Smørgrav  fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode);
62967b5038d7SDag-Erling Smørgrav  vfprintf (stderr, message, ap);
62977b5038d7SDag-Erling Smørgrav  fprintf (stderr, ".\n");
62987b5038d7SDag-Erling Smørgrav
62997b5038d7SDag-Erling Smørgrav  if (exit_status >= 0)
63007b5038d7SDag-Erling Smørgrav    exit (exit_status);
63017b5038d7SDag-Erling Smørgrav}
63027b5038d7SDag-Erling Smørgrav
63037b5038d7SDag-Erling Smørgravvoid
63047b5038d7SDag-Erling Smørgravlt_fatal (const char *file, int line, const char *message, ...)
63057b5038d7SDag-Erling Smørgrav{
63067b5038d7SDag-Erling Smørgrav  va_list ap;
63077b5038d7SDag-Erling Smørgrav  va_start (ap, message);
63087b5038d7SDag-Erling Smørgrav  lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap);
63097b5038d7SDag-Erling Smørgrav  va_end (ap);
63107b5038d7SDag-Erling Smørgrav}
63117b5038d7SDag-Erling Smørgrav
63127b5038d7SDag-Erling Smørgravstatic const char *
63137b5038d7SDag-Erling Smørgravnonnull (const char *s)
63147b5038d7SDag-Erling Smørgrav{
63157b5038d7SDag-Erling Smørgrav  return s ? s : "(null)";
63167b5038d7SDag-Erling Smørgrav}
63177b5038d7SDag-Erling Smørgrav
63187b5038d7SDag-Erling Smørgravstatic const char *
63197b5038d7SDag-Erling Smørgravnonempty (const char *s)
63207b5038d7SDag-Erling Smørgrav{
63217b5038d7SDag-Erling Smørgrav  return (s && !*s) ? "(empty)" : nonnull (s);
63227b5038d7SDag-Erling Smørgrav}
63237b5038d7SDag-Erling Smørgrav
63247b5038d7SDag-Erling Smørgravvoid
63257b5038d7SDag-Erling Smørgravlt_setenv (const char *name, const char *value)
63267b5038d7SDag-Erling Smørgrav{
63277b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__,
63287b5038d7SDag-Erling Smørgrav		  "(lt_setenv) setting '%s' to '%s'\n",
63297b5038d7SDag-Erling Smørgrav                  nonnull (name), nonnull (value));
63307b5038d7SDag-Erling Smørgrav  {
63317b5038d7SDag-Erling Smørgrav#ifdef HAVE_SETENV
63327b5038d7SDag-Erling Smørgrav    /* always make a copy, for consistency with !HAVE_SETENV */
63337b5038d7SDag-Erling Smørgrav    char *str = xstrdup (value);
63347b5038d7SDag-Erling Smørgrav    setenv (name, str, 1);
63357b5038d7SDag-Erling Smørgrav#else
6336986ba33cSDag-Erling Smørgrav    size_t len = strlen (name) + 1 + strlen (value) + 1;
63377b5038d7SDag-Erling Smørgrav    char *str = XMALLOC (char, len);
63387b5038d7SDag-Erling Smørgrav    sprintf (str, "%s=%s", name, value);
63397b5038d7SDag-Erling Smørgrav    if (putenv (str) != EXIT_SUCCESS)
63407b5038d7SDag-Erling Smørgrav      {
63417b5038d7SDag-Erling Smørgrav        XFREE (str);
63427b5038d7SDag-Erling Smørgrav      }
63437b5038d7SDag-Erling Smørgrav#endif
63447b5038d7SDag-Erling Smørgrav  }
63457b5038d7SDag-Erling Smørgrav}
63467b5038d7SDag-Erling Smørgrav
63477b5038d7SDag-Erling Smørgravchar *
63487b5038d7SDag-Erling Smørgravlt_extend_str (const char *orig_value, const char *add, int to_end)
63497b5038d7SDag-Erling Smørgrav{
63507b5038d7SDag-Erling Smørgrav  char *new_value;
63517b5038d7SDag-Erling Smørgrav  if (orig_value && *orig_value)
63527b5038d7SDag-Erling Smørgrav    {
6353986ba33cSDag-Erling Smørgrav      size_t orig_value_len = strlen (orig_value);
6354986ba33cSDag-Erling Smørgrav      size_t add_len = strlen (add);
63557b5038d7SDag-Erling Smørgrav      new_value = XMALLOC (char, add_len + orig_value_len + 1);
63567b5038d7SDag-Erling Smørgrav      if (to_end)
63577b5038d7SDag-Erling Smørgrav        {
63587b5038d7SDag-Erling Smørgrav          strcpy (new_value, orig_value);
63597b5038d7SDag-Erling Smørgrav          strcpy (new_value + orig_value_len, add);
63607b5038d7SDag-Erling Smørgrav        }
63617b5038d7SDag-Erling Smørgrav      else
63627b5038d7SDag-Erling Smørgrav        {
63637b5038d7SDag-Erling Smørgrav          strcpy (new_value, add);
63647b5038d7SDag-Erling Smørgrav          strcpy (new_value + add_len, orig_value);
63657b5038d7SDag-Erling Smørgrav        }
63667b5038d7SDag-Erling Smørgrav    }
63677b5038d7SDag-Erling Smørgrav  else
63687b5038d7SDag-Erling Smørgrav    {
63697b5038d7SDag-Erling Smørgrav      new_value = xstrdup (add);
63707b5038d7SDag-Erling Smørgrav    }
63717b5038d7SDag-Erling Smørgrav  return new_value;
63727b5038d7SDag-Erling Smørgrav}
63737b5038d7SDag-Erling Smørgrav
63747b5038d7SDag-Erling Smørgravvoid
63757b5038d7SDag-Erling Smørgravlt_update_exe_path (const char *name, const char *value)
63767b5038d7SDag-Erling Smørgrav{
63777b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__,
63787b5038d7SDag-Erling Smørgrav		  "(lt_update_exe_path) modifying '%s' by prepending '%s'\n",
63797b5038d7SDag-Erling Smørgrav                  nonnull (name), nonnull (value));
63807b5038d7SDag-Erling Smørgrav
63817b5038d7SDag-Erling Smørgrav  if (name && *name && value && *value)
63827b5038d7SDag-Erling Smørgrav    {
63837b5038d7SDag-Erling Smørgrav      char *new_value = lt_extend_str (getenv (name), value, 0);
63847b5038d7SDag-Erling Smørgrav      /* some systems can't cope with a ':'-terminated path #' */
6385986ba33cSDag-Erling Smørgrav      size_t len = strlen (new_value);
6386986ba33cSDag-Erling Smørgrav      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))
63877b5038d7SDag-Erling Smørgrav        {
6388986ba33cSDag-Erling Smørgrav          new_value[--len] = '\0';
63897b5038d7SDag-Erling Smørgrav        }
63907b5038d7SDag-Erling Smørgrav      lt_setenv (name, new_value);
63917b5038d7SDag-Erling Smørgrav      XFREE (new_value);
63927b5038d7SDag-Erling Smørgrav    }
63937b5038d7SDag-Erling Smørgrav}
63947b5038d7SDag-Erling Smørgrav
63957b5038d7SDag-Erling Smørgravvoid
63967b5038d7SDag-Erling Smørgravlt_update_lib_path (const char *name, const char *value)
63977b5038d7SDag-Erling Smørgrav{
63987b5038d7SDag-Erling Smørgrav  lt_debugprintf (__FILE__, __LINE__,
63997b5038d7SDag-Erling Smørgrav		  "(lt_update_lib_path) modifying '%s' by prepending '%s'\n",
64007b5038d7SDag-Erling Smørgrav                  nonnull (name), nonnull (value));
64017b5038d7SDag-Erling Smørgrav
64027b5038d7SDag-Erling Smørgrav  if (name && *name && value && *value)
64037b5038d7SDag-Erling Smørgrav    {
64047b5038d7SDag-Erling Smørgrav      char *new_value = lt_extend_str (getenv (name), value, 0);
64057b5038d7SDag-Erling Smørgrav      lt_setenv (name, new_value);
64067b5038d7SDag-Erling Smørgrav      XFREE (new_value);
64077b5038d7SDag-Erling Smørgrav    }
64087b5038d7SDag-Erling Smørgrav}
64097b5038d7SDag-Erling Smørgrav
64107b5038d7SDag-Erling SmørgravEOF
64117b5038d7SDag-Erling Smørgrav	    case $host_os in
64127b5038d7SDag-Erling Smørgrav	      mingw*)
64137b5038d7SDag-Erling Smørgrav		cat <<"EOF"
64147b5038d7SDag-Erling Smørgrav
64157b5038d7SDag-Erling Smørgrav/* Prepares an argument vector before calling spawn().
64167b5038d7SDag-Erling Smørgrav   Note that spawn() does not by itself call the command interpreter
64177b5038d7SDag-Erling Smørgrav     (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") :
64187b5038d7SDag-Erling Smørgrav      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
64197b5038d7SDag-Erling Smørgrav         GetVersionEx(&v);
64207b5038d7SDag-Erling Smørgrav         v.dwPlatformId == VER_PLATFORM_WIN32_NT;
64217b5038d7SDag-Erling Smørgrav      }) ? "cmd.exe" : "command.com").
64227b5038d7SDag-Erling Smørgrav   Instead it simply concatenates the arguments, separated by ' ', and calls
64237b5038d7SDag-Erling Smørgrav   CreateProcess().  We must quote the arguments since Win32 CreateProcess()
64247b5038d7SDag-Erling Smørgrav   interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a
64257b5038d7SDag-Erling Smørgrav   special way:
64267b5038d7SDag-Erling Smørgrav   - Space and tab are interpreted as delimiters. They are not treated as
64277b5038d7SDag-Erling Smørgrav     delimiters if they are surrounded by double quotes: "...".
64287b5038d7SDag-Erling Smørgrav   - Unescaped double quotes are removed from the input. Their only effect is
64297b5038d7SDag-Erling Smørgrav     that within double quotes, space and tab are treated like normal
64307b5038d7SDag-Erling Smørgrav     characters.
64317b5038d7SDag-Erling Smørgrav   - Backslashes not followed by double quotes are not special.
64327b5038d7SDag-Erling Smørgrav   - But 2*n+1 backslashes followed by a double quote become
64337b5038d7SDag-Erling Smørgrav     n backslashes followed by a double quote (n >= 0):
64347b5038d7SDag-Erling Smørgrav       \" -> "
64357b5038d7SDag-Erling Smørgrav       \\\" -> \"
64367b5038d7SDag-Erling Smørgrav       \\\\\" -> \\"
64377b5038d7SDag-Erling Smørgrav */
64387b5038d7SDag-Erling Smørgrav#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"
64397b5038d7SDag-Erling Smørgrav#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"
64407b5038d7SDag-Erling Smørgravchar **
64417b5038d7SDag-Erling Smørgravprepare_spawn (char **argv)
64427b5038d7SDag-Erling Smørgrav{
64437b5038d7SDag-Erling Smørgrav  size_t argc;
64447b5038d7SDag-Erling Smørgrav  char **new_argv;
64457b5038d7SDag-Erling Smørgrav  size_t i;
64467b5038d7SDag-Erling Smørgrav
64477b5038d7SDag-Erling Smørgrav  /* Count number of arguments.  */
64487b5038d7SDag-Erling Smørgrav  for (argc = 0; argv[argc] != NULL; argc++)
64497b5038d7SDag-Erling Smørgrav    ;
64507b5038d7SDag-Erling Smørgrav
64517b5038d7SDag-Erling Smørgrav  /* Allocate new argument vector.  */
64527b5038d7SDag-Erling Smørgrav  new_argv = XMALLOC (char *, argc + 1);
64537b5038d7SDag-Erling Smørgrav
64547b5038d7SDag-Erling Smørgrav  /* Put quoted arguments into the new argument vector.  */
64557b5038d7SDag-Erling Smørgrav  for (i = 0; i < argc; i++)
64567b5038d7SDag-Erling Smørgrav    {
64577b5038d7SDag-Erling Smørgrav      const char *string = argv[i];
64587b5038d7SDag-Erling Smørgrav
64597b5038d7SDag-Erling Smørgrav      if (string[0] == '\0')
64607b5038d7SDag-Erling Smørgrav	new_argv[i] = xstrdup ("\"\"");
64617b5038d7SDag-Erling Smørgrav      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
64627b5038d7SDag-Erling Smørgrav	{
64637b5038d7SDag-Erling Smørgrav	  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);
64647b5038d7SDag-Erling Smørgrav	  size_t length;
64657b5038d7SDag-Erling Smørgrav	  unsigned int backslashes;
64667b5038d7SDag-Erling Smørgrav	  const char *s;
64677b5038d7SDag-Erling Smørgrav	  char *quoted_string;
64687b5038d7SDag-Erling Smørgrav	  char *p;
64697b5038d7SDag-Erling Smørgrav
64707b5038d7SDag-Erling Smørgrav	  length = 0;
64717b5038d7SDag-Erling Smørgrav	  backslashes = 0;
64727b5038d7SDag-Erling Smørgrav	  if (quote_around)
64737b5038d7SDag-Erling Smørgrav	    length++;
64747b5038d7SDag-Erling Smørgrav	  for (s = string; *s != '\0'; s++)
64757b5038d7SDag-Erling Smørgrav	    {
64767b5038d7SDag-Erling Smørgrav	      char c = *s;
64777b5038d7SDag-Erling Smørgrav	      if (c == '"')
64787b5038d7SDag-Erling Smørgrav		length += backslashes + 1;
64797b5038d7SDag-Erling Smørgrav	      length++;
64807b5038d7SDag-Erling Smørgrav	      if (c == '\\')
64817b5038d7SDag-Erling Smørgrav		backslashes++;
64827b5038d7SDag-Erling Smørgrav	      else
64837b5038d7SDag-Erling Smørgrav		backslashes = 0;
64847b5038d7SDag-Erling Smørgrav	    }
64857b5038d7SDag-Erling Smørgrav	  if (quote_around)
64867b5038d7SDag-Erling Smørgrav	    length += backslashes + 1;
64877b5038d7SDag-Erling Smørgrav
64887b5038d7SDag-Erling Smørgrav	  quoted_string = XMALLOC (char, length + 1);
64897b5038d7SDag-Erling Smørgrav
64907b5038d7SDag-Erling Smørgrav	  p = quoted_string;
64917b5038d7SDag-Erling Smørgrav	  backslashes = 0;
64927b5038d7SDag-Erling Smørgrav	  if (quote_around)
64937b5038d7SDag-Erling Smørgrav	    *p++ = '"';
64947b5038d7SDag-Erling Smørgrav	  for (s = string; *s != '\0'; s++)
64957b5038d7SDag-Erling Smørgrav	    {
64967b5038d7SDag-Erling Smørgrav	      char c = *s;
64977b5038d7SDag-Erling Smørgrav	      if (c == '"')
64987b5038d7SDag-Erling Smørgrav		{
64997b5038d7SDag-Erling Smørgrav		  unsigned int j;
65007b5038d7SDag-Erling Smørgrav		  for (j = backslashes + 1; j > 0; j--)
65017b5038d7SDag-Erling Smørgrav		    *p++ = '\\';
65027b5038d7SDag-Erling Smørgrav		}
65037b5038d7SDag-Erling Smørgrav	      *p++ = c;
65047b5038d7SDag-Erling Smørgrav	      if (c == '\\')
65057b5038d7SDag-Erling Smørgrav		backslashes++;
65067b5038d7SDag-Erling Smørgrav	      else
65077b5038d7SDag-Erling Smørgrav		backslashes = 0;
65087b5038d7SDag-Erling Smørgrav	    }
65097b5038d7SDag-Erling Smørgrav	  if (quote_around)
65107b5038d7SDag-Erling Smørgrav	    {
65117b5038d7SDag-Erling Smørgrav	      unsigned int j;
65127b5038d7SDag-Erling Smørgrav	      for (j = backslashes; j > 0; j--)
65137b5038d7SDag-Erling Smørgrav		*p++ = '\\';
65147b5038d7SDag-Erling Smørgrav	      *p++ = '"';
65157b5038d7SDag-Erling Smørgrav	    }
65167b5038d7SDag-Erling Smørgrav	  *p = '\0';
65177b5038d7SDag-Erling Smørgrav
65187b5038d7SDag-Erling Smørgrav	  new_argv[i] = quoted_string;
65197b5038d7SDag-Erling Smørgrav	}
65207b5038d7SDag-Erling Smørgrav      else
65217b5038d7SDag-Erling Smørgrav	new_argv[i] = (char *) string;
65227b5038d7SDag-Erling Smørgrav    }
65237b5038d7SDag-Erling Smørgrav  new_argv[argc] = NULL;
65247b5038d7SDag-Erling Smørgrav
65257b5038d7SDag-Erling Smørgrav  return new_argv;
65267b5038d7SDag-Erling Smørgrav}
65277b5038d7SDag-Erling SmørgravEOF
65287b5038d7SDag-Erling Smørgrav		;;
65297b5038d7SDag-Erling Smørgrav	    esac
65307b5038d7SDag-Erling Smørgrav
65317b5038d7SDag-Erling Smørgrav            cat <<"EOF"
65327b5038d7SDag-Erling Smørgravvoid lt_dump_script (FILE* f)
65337b5038d7SDag-Erling Smørgrav{
65347b5038d7SDag-Erling SmørgravEOF
65357b5038d7SDag-Erling Smørgrav	    func_emit_wrapper yes |
65367b5038d7SDag-Erling Smørgrav	      $SED -n -e '
65377b5038d7SDag-Erling Smørgravs/^\(.\{79\}\)\(..*\)/\1\
65387b5038d7SDag-Erling Smørgrav\2/
65397b5038d7SDag-Erling Smørgravh
65407b5038d7SDag-Erling Smørgravs/\([\\"]\)/\\\1/g
65417b5038d7SDag-Erling Smørgravs/$/\\n/
65427b5038d7SDag-Erling Smørgravs/\([^\n]*\).*/  fputs ("\1", f);/p
65437b5038d7SDag-Erling Smørgravg
65447b5038d7SDag-Erling SmørgravD'
65457b5038d7SDag-Erling Smørgrav            cat <<"EOF"
65467b5038d7SDag-Erling Smørgrav}
65477b5038d7SDag-Erling SmørgravEOF
65487b5038d7SDag-Erling Smørgrav}
65497b5038d7SDag-Erling Smørgrav# end: func_emit_cwrapperexe_src
65507b5038d7SDag-Erling Smørgrav
65517b5038d7SDag-Erling Smørgrav# func_win32_import_lib_p ARG
65527b5038d7SDag-Erling Smørgrav# True if ARG is an import lib, as indicated by $file_magic_cmd
65537b5038d7SDag-Erling Smørgravfunc_win32_import_lib_p ()
65547b5038d7SDag-Erling Smørgrav{
6555986ba33cSDag-Erling Smørgrav    $debug_cmd
6556986ba33cSDag-Erling Smørgrav
65577b5038d7SDag-Erling Smørgrav    case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in
65587b5038d7SDag-Erling Smørgrav    *import*) : ;;
65597b5038d7SDag-Erling Smørgrav    *) false ;;
65607b5038d7SDag-Erling Smørgrav    esac
65617b5038d7SDag-Erling Smørgrav}
65627b5038d7SDag-Erling Smørgrav
6563986ba33cSDag-Erling Smørgrav# func_suncc_cstd_abi
6564986ba33cSDag-Erling Smørgrav# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!
6565986ba33cSDag-Erling Smørgrav# Several compiler flags select an ABI that is incompatible with the
6566986ba33cSDag-Erling Smørgrav# Cstd library. Avoid specifying it if any are in CXXFLAGS.
6567986ba33cSDag-Erling Smørgravfunc_suncc_cstd_abi ()
6568986ba33cSDag-Erling Smørgrav{
6569986ba33cSDag-Erling Smørgrav    $debug_cmd
6570986ba33cSDag-Erling Smørgrav
6571986ba33cSDag-Erling Smørgrav    case " $compile_command " in
6572986ba33cSDag-Erling Smørgrav    *" -compat=g "*|*\ -std=c++[0-9][0-9]\ *|*" -library=stdcxx4 "*|*" -library=stlport4 "*)
6573986ba33cSDag-Erling Smørgrav      suncc_use_cstd_abi=no
6574986ba33cSDag-Erling Smørgrav      ;;
6575986ba33cSDag-Erling Smørgrav    *)
6576986ba33cSDag-Erling Smørgrav      suncc_use_cstd_abi=yes
6577986ba33cSDag-Erling Smørgrav      ;;
6578986ba33cSDag-Erling Smørgrav    esac
6579986ba33cSDag-Erling Smørgrav}
6580986ba33cSDag-Erling Smørgrav
65817b5038d7SDag-Erling Smørgrav# func_mode_link arg...
65827b5038d7SDag-Erling Smørgravfunc_mode_link ()
65837b5038d7SDag-Erling Smørgrav{
6584986ba33cSDag-Erling Smørgrav    $debug_cmd
6585986ba33cSDag-Erling Smørgrav
65867b5038d7SDag-Erling Smørgrav    case $host in
65877b5038d7SDag-Erling Smørgrav    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
65887b5038d7SDag-Erling Smørgrav      # It is impossible to link a dll without this setting, and
65897b5038d7SDag-Erling Smørgrav      # we shouldn't force the makefile maintainer to figure out
6590986ba33cSDag-Erling Smørgrav      # what system we are compiling for in order to pass an extra
65917b5038d7SDag-Erling Smørgrav      # flag for every libtool invocation.
65927b5038d7SDag-Erling Smørgrav      # allow_undefined=no
65937b5038d7SDag-Erling Smørgrav
65947b5038d7SDag-Erling Smørgrav      # FIXME: Unfortunately, there are problems with the above when trying
6595986ba33cSDag-Erling Smørgrav      # to make a dll that has undefined symbols, in which case not
65967b5038d7SDag-Erling Smørgrav      # even a static library is built.  For now, we need to specify
65977b5038d7SDag-Erling Smørgrav      # -no-undefined on the libtool link line when we can be certain
65987b5038d7SDag-Erling Smørgrav      # that all symbols are satisfied, otherwise we get a static library.
65997b5038d7SDag-Erling Smørgrav      allow_undefined=yes
66007b5038d7SDag-Erling Smørgrav      ;;
66017b5038d7SDag-Erling Smørgrav    *)
66027b5038d7SDag-Erling Smørgrav      allow_undefined=yes
66037b5038d7SDag-Erling Smørgrav      ;;
66047b5038d7SDag-Erling Smørgrav    esac
66057b5038d7SDag-Erling Smørgrav    libtool_args=$nonopt
66067b5038d7SDag-Erling Smørgrav    base_compile="$nonopt $@"
66077b5038d7SDag-Erling Smørgrav    compile_command=$nonopt
66087b5038d7SDag-Erling Smørgrav    finalize_command=$nonopt
66097b5038d7SDag-Erling Smørgrav
66107b5038d7SDag-Erling Smørgrav    compile_rpath=
66117b5038d7SDag-Erling Smørgrav    finalize_rpath=
66127b5038d7SDag-Erling Smørgrav    compile_shlibpath=
66137b5038d7SDag-Erling Smørgrav    finalize_shlibpath=
66147b5038d7SDag-Erling Smørgrav    convenience=
66157b5038d7SDag-Erling Smørgrav    old_convenience=
66167b5038d7SDag-Erling Smørgrav    deplibs=
66177b5038d7SDag-Erling Smørgrav    old_deplibs=
66187b5038d7SDag-Erling Smørgrav    compiler_flags=
66197b5038d7SDag-Erling Smørgrav    linker_flags=
66207b5038d7SDag-Erling Smørgrav    dllsearchpath=
66217b5038d7SDag-Erling Smørgrav    lib_search_path=`pwd`
66227b5038d7SDag-Erling Smørgrav    inst_prefix_dir=
66237b5038d7SDag-Erling Smørgrav    new_inherited_linker_flags=
66247b5038d7SDag-Erling Smørgrav
66257b5038d7SDag-Erling Smørgrav    avoid_version=no
66267b5038d7SDag-Erling Smørgrav    bindir=
66277b5038d7SDag-Erling Smørgrav    dlfiles=
66287b5038d7SDag-Erling Smørgrav    dlprefiles=
66297b5038d7SDag-Erling Smørgrav    dlself=no
66307b5038d7SDag-Erling Smørgrav    export_dynamic=no
66317b5038d7SDag-Erling Smørgrav    export_symbols=
66327b5038d7SDag-Erling Smørgrav    export_symbols_regex=
66337b5038d7SDag-Erling Smørgrav    generated=
66347b5038d7SDag-Erling Smørgrav    libobjs=
66357b5038d7SDag-Erling Smørgrav    ltlibs=
66367b5038d7SDag-Erling Smørgrav    module=no
66377b5038d7SDag-Erling Smørgrav    no_install=no
66387b5038d7SDag-Erling Smørgrav    objs=
6639986ba33cSDag-Erling Smørgrav    os2dllname=
66407b5038d7SDag-Erling Smørgrav    non_pic_objects=
66417b5038d7SDag-Erling Smørgrav    precious_files_regex=
66427b5038d7SDag-Erling Smørgrav    prefer_static_libs=no
6643986ba33cSDag-Erling Smørgrav    preload=false
66447b5038d7SDag-Erling Smørgrav    prev=
66457b5038d7SDag-Erling Smørgrav    prevarg=
66467b5038d7SDag-Erling Smørgrav    release=
66477b5038d7SDag-Erling Smørgrav    rpath=
66487b5038d7SDag-Erling Smørgrav    xrpath=
66497b5038d7SDag-Erling Smørgrav    perm_rpath=
66507b5038d7SDag-Erling Smørgrav    temp_rpath=
66517b5038d7SDag-Erling Smørgrav    thread_safe=no
66527b5038d7SDag-Erling Smørgrav    vinfo=
66537b5038d7SDag-Erling Smørgrav    vinfo_number=no
66547b5038d7SDag-Erling Smørgrav    weak_libs=
6655986ba33cSDag-Erling Smørgrav    single_module=$wl-single_module
66567b5038d7SDag-Erling Smørgrav    func_infer_tag $base_compile
66577b5038d7SDag-Erling Smørgrav
66587b5038d7SDag-Erling Smørgrav    # We need to know -static, to get the right output filenames.
66597b5038d7SDag-Erling Smørgrav    for arg
66607b5038d7SDag-Erling Smørgrav    do
66617b5038d7SDag-Erling Smørgrav      case $arg in
66627b5038d7SDag-Erling Smørgrav      -shared)
6663986ba33cSDag-Erling Smørgrav	test yes != "$build_libtool_libs" \
6664986ba33cSDag-Erling Smørgrav	  && func_fatal_configuration "cannot build a shared library"
66657b5038d7SDag-Erling Smørgrav	build_old_libs=no
66667b5038d7SDag-Erling Smørgrav	break
66677b5038d7SDag-Erling Smørgrav	;;
66687b5038d7SDag-Erling Smørgrav      -all-static | -static | -static-libtool-libs)
66697b5038d7SDag-Erling Smørgrav	case $arg in
66707b5038d7SDag-Erling Smørgrav	-all-static)
6671986ba33cSDag-Erling Smørgrav	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; then
66727b5038d7SDag-Erling Smørgrav	    func_warning "complete static linking is impossible in this configuration"
66737b5038d7SDag-Erling Smørgrav	  fi
66747b5038d7SDag-Erling Smørgrav	  if test -n "$link_static_flag"; then
66757b5038d7SDag-Erling Smørgrav	    dlopen_self=$dlopen_self_static
66767b5038d7SDag-Erling Smørgrav	  fi
66777b5038d7SDag-Erling Smørgrav	  prefer_static_libs=yes
66787b5038d7SDag-Erling Smørgrav	  ;;
66797b5038d7SDag-Erling Smørgrav	-static)
66807b5038d7SDag-Erling Smørgrav	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
66817b5038d7SDag-Erling Smørgrav	    dlopen_self=$dlopen_self_static
66827b5038d7SDag-Erling Smørgrav	  fi
66837b5038d7SDag-Erling Smørgrav	  prefer_static_libs=built
66847b5038d7SDag-Erling Smørgrav	  ;;
66857b5038d7SDag-Erling Smørgrav	-static-libtool-libs)
66867b5038d7SDag-Erling Smørgrav	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
66877b5038d7SDag-Erling Smørgrav	    dlopen_self=$dlopen_self_static
66887b5038d7SDag-Erling Smørgrav	  fi
66897b5038d7SDag-Erling Smørgrav	  prefer_static_libs=yes
66907b5038d7SDag-Erling Smørgrav	  ;;
66917b5038d7SDag-Erling Smørgrav	esac
66927b5038d7SDag-Erling Smørgrav	build_libtool_libs=no
66937b5038d7SDag-Erling Smørgrav	build_old_libs=yes
66947b5038d7SDag-Erling Smørgrav	break
66957b5038d7SDag-Erling Smørgrav	;;
66967b5038d7SDag-Erling Smørgrav      esac
66977b5038d7SDag-Erling Smørgrav    done
66987b5038d7SDag-Erling Smørgrav
66997b5038d7SDag-Erling Smørgrav    # See if our shared archives depend on static archives.
67007b5038d7SDag-Erling Smørgrav    test -n "$old_archive_from_new_cmds" && build_old_libs=yes
67017b5038d7SDag-Erling Smørgrav
67027b5038d7SDag-Erling Smørgrav    # Go through the arguments, transforming them on the way.
67037b5038d7SDag-Erling Smørgrav    while test "$#" -gt 0; do
6704986ba33cSDag-Erling Smørgrav      arg=$1
67057b5038d7SDag-Erling Smørgrav      shift
67067b5038d7SDag-Erling Smørgrav      func_quote_for_eval "$arg"
67077b5038d7SDag-Erling Smørgrav      qarg=$func_quote_for_eval_unquoted_result
67087b5038d7SDag-Erling Smørgrav      func_append libtool_args " $func_quote_for_eval_result"
67097b5038d7SDag-Erling Smørgrav
67107b5038d7SDag-Erling Smørgrav      # If the previous option needs an argument, assign it.
67117b5038d7SDag-Erling Smørgrav      if test -n "$prev"; then
67127b5038d7SDag-Erling Smørgrav	case $prev in
67137b5038d7SDag-Erling Smørgrav	output)
67147b5038d7SDag-Erling Smørgrav	  func_append compile_command " @OUTPUT@"
67157b5038d7SDag-Erling Smørgrav	  func_append finalize_command " @OUTPUT@"
67167b5038d7SDag-Erling Smørgrav	  ;;
67177b5038d7SDag-Erling Smørgrav	esac
67187b5038d7SDag-Erling Smørgrav
67197b5038d7SDag-Erling Smørgrav	case $prev in
67207b5038d7SDag-Erling Smørgrav	bindir)
6721986ba33cSDag-Erling Smørgrav	  bindir=$arg
67227b5038d7SDag-Erling Smørgrav	  prev=
67237b5038d7SDag-Erling Smørgrav	  continue
67247b5038d7SDag-Erling Smørgrav	  ;;
67257b5038d7SDag-Erling Smørgrav	dlfiles|dlprefiles)
6726986ba33cSDag-Erling Smørgrav	  $preload || {
67277b5038d7SDag-Erling Smørgrav	    # Add the symbol object into the linking commands.
67287b5038d7SDag-Erling Smørgrav	    func_append compile_command " @SYMFILE@"
67297b5038d7SDag-Erling Smørgrav	    func_append finalize_command " @SYMFILE@"
6730986ba33cSDag-Erling Smørgrav	    preload=:
6731986ba33cSDag-Erling Smørgrav	  }
67327b5038d7SDag-Erling Smørgrav	  case $arg in
67337b5038d7SDag-Erling Smørgrav	  *.la | *.lo) ;;  # We handle these cases below.
67347b5038d7SDag-Erling Smørgrav	  force)
6735986ba33cSDag-Erling Smørgrav	    if test no = "$dlself"; then
67367b5038d7SDag-Erling Smørgrav	      dlself=needless
67377b5038d7SDag-Erling Smørgrav	      export_dynamic=yes
67387b5038d7SDag-Erling Smørgrav	    fi
67397b5038d7SDag-Erling Smørgrav	    prev=
67407b5038d7SDag-Erling Smørgrav	    continue
67417b5038d7SDag-Erling Smørgrav	    ;;
67427b5038d7SDag-Erling Smørgrav	  self)
6743986ba33cSDag-Erling Smørgrav	    if test dlprefiles = "$prev"; then
67447b5038d7SDag-Erling Smørgrav	      dlself=yes
6745986ba33cSDag-Erling Smørgrav	    elif test dlfiles = "$prev" && test yes != "$dlopen_self"; then
67467b5038d7SDag-Erling Smørgrav	      dlself=yes
67477b5038d7SDag-Erling Smørgrav	    else
67487b5038d7SDag-Erling Smørgrav	      dlself=needless
67497b5038d7SDag-Erling Smørgrav	      export_dynamic=yes
67507b5038d7SDag-Erling Smørgrav	    fi
67517b5038d7SDag-Erling Smørgrav	    prev=
67527b5038d7SDag-Erling Smørgrav	    continue
67537b5038d7SDag-Erling Smørgrav	    ;;
67547b5038d7SDag-Erling Smørgrav	  *)
6755986ba33cSDag-Erling Smørgrav	    if test dlfiles = "$prev"; then
67567b5038d7SDag-Erling Smørgrav	      func_append dlfiles " $arg"
67577b5038d7SDag-Erling Smørgrav	    else
67587b5038d7SDag-Erling Smørgrav	      func_append dlprefiles " $arg"
67597b5038d7SDag-Erling Smørgrav	    fi
67607b5038d7SDag-Erling Smørgrav	    prev=
67617b5038d7SDag-Erling Smørgrav	    continue
67627b5038d7SDag-Erling Smørgrav	    ;;
67637b5038d7SDag-Erling Smørgrav	  esac
67647b5038d7SDag-Erling Smørgrav	  ;;
67657b5038d7SDag-Erling Smørgrav	expsyms)
6766986ba33cSDag-Erling Smørgrav	  export_symbols=$arg
67677b5038d7SDag-Erling Smørgrav	  test -f "$arg" \
6768986ba33cSDag-Erling Smørgrav	    || func_fatal_error "symbol file '$arg' does not exist"
67697b5038d7SDag-Erling Smørgrav	  prev=
67707b5038d7SDag-Erling Smørgrav	  continue
67717b5038d7SDag-Erling Smørgrav	  ;;
67727b5038d7SDag-Erling Smørgrav	expsyms_regex)
6773986ba33cSDag-Erling Smørgrav	  export_symbols_regex=$arg
67747b5038d7SDag-Erling Smørgrav	  prev=
67757b5038d7SDag-Erling Smørgrav	  continue
67767b5038d7SDag-Erling Smørgrav	  ;;
67777b5038d7SDag-Erling Smørgrav	framework)
67787b5038d7SDag-Erling Smørgrav	  case $host in
67797b5038d7SDag-Erling Smørgrav	    *-*-darwin*)
67807b5038d7SDag-Erling Smørgrav	      case "$deplibs " in
67817b5038d7SDag-Erling Smørgrav		*" $qarg.ltframework "*) ;;
67827b5038d7SDag-Erling Smørgrav		*) func_append deplibs " $qarg.ltframework" # this is fixed later
67837b5038d7SDag-Erling Smørgrav		   ;;
67847b5038d7SDag-Erling Smørgrav	      esac
67857b5038d7SDag-Erling Smørgrav	      ;;
67867b5038d7SDag-Erling Smørgrav	  esac
67877b5038d7SDag-Erling Smørgrav	  prev=
67887b5038d7SDag-Erling Smørgrav	  continue
67897b5038d7SDag-Erling Smørgrav	  ;;
67907b5038d7SDag-Erling Smørgrav	inst_prefix)
6791986ba33cSDag-Erling Smørgrav	  inst_prefix_dir=$arg
6792986ba33cSDag-Erling Smørgrav	  prev=
6793986ba33cSDag-Erling Smørgrav	  continue
6794986ba33cSDag-Erling Smørgrav	  ;;
6795986ba33cSDag-Erling Smørgrav	mllvm)
6796986ba33cSDag-Erling Smørgrav	  # Clang does not use LLVM to link, so we can simply discard any
6797986ba33cSDag-Erling Smørgrav	  # '-mllvm $arg' options when doing the link step.
67987b5038d7SDag-Erling Smørgrav	  prev=
67997b5038d7SDag-Erling Smørgrav	  continue
68007b5038d7SDag-Erling Smørgrav	  ;;
68017b5038d7SDag-Erling Smørgrav	objectlist)
68027b5038d7SDag-Erling Smørgrav	  if test -f "$arg"; then
68037b5038d7SDag-Erling Smørgrav	    save_arg=$arg
68047b5038d7SDag-Erling Smørgrav	    moreargs=
68057b5038d7SDag-Erling Smørgrav	    for fil in `cat "$save_arg"`
68067b5038d7SDag-Erling Smørgrav	    do
68077b5038d7SDag-Erling Smørgrav#	      func_append moreargs " $fil"
68087b5038d7SDag-Erling Smørgrav	      arg=$fil
68097b5038d7SDag-Erling Smørgrav	      # A libtool-controlled object.
68107b5038d7SDag-Erling Smørgrav
68117b5038d7SDag-Erling Smørgrav	      # Check to see that this really is a libtool object.
68127b5038d7SDag-Erling Smørgrav	      if func_lalib_unsafe_p "$arg"; then
68137b5038d7SDag-Erling Smørgrav		pic_object=
68147b5038d7SDag-Erling Smørgrav		non_pic_object=
68157b5038d7SDag-Erling Smørgrav
68167b5038d7SDag-Erling Smørgrav		# Read the .lo file
68177b5038d7SDag-Erling Smørgrav		func_source "$arg"
68187b5038d7SDag-Erling Smørgrav
68197b5038d7SDag-Erling Smørgrav		if test -z "$pic_object" ||
68207b5038d7SDag-Erling Smørgrav		   test -z "$non_pic_object" ||
6821986ba33cSDag-Erling Smørgrav		   test none = "$pic_object" &&
6822986ba33cSDag-Erling Smørgrav		   test none = "$non_pic_object"; then
6823986ba33cSDag-Erling Smørgrav		  func_fatal_error "cannot find name of object for '$arg'"
68247b5038d7SDag-Erling Smørgrav		fi
68257b5038d7SDag-Erling Smørgrav
68267b5038d7SDag-Erling Smørgrav		# Extract subdirectory from the argument.
68277b5038d7SDag-Erling Smørgrav		func_dirname "$arg" "/" ""
6828986ba33cSDag-Erling Smørgrav		xdir=$func_dirname_result
68297b5038d7SDag-Erling Smørgrav
6830986ba33cSDag-Erling Smørgrav		if test none != "$pic_object"; then
68317b5038d7SDag-Erling Smørgrav		  # Prepend the subdirectory the object is found in.
6832986ba33cSDag-Erling Smørgrav		  pic_object=$xdir$pic_object
68337b5038d7SDag-Erling Smørgrav
6834986ba33cSDag-Erling Smørgrav		  if test dlfiles = "$prev"; then
6835986ba33cSDag-Erling Smørgrav		    if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
68367b5038d7SDag-Erling Smørgrav		      func_append dlfiles " $pic_object"
68377b5038d7SDag-Erling Smørgrav		      prev=
68387b5038d7SDag-Erling Smørgrav		      continue
68397b5038d7SDag-Erling Smørgrav		    else
68407b5038d7SDag-Erling Smørgrav		      # If libtool objects are unsupported, then we need to preload.
68417b5038d7SDag-Erling Smørgrav		      prev=dlprefiles
68427b5038d7SDag-Erling Smørgrav		    fi
68437b5038d7SDag-Erling Smørgrav		  fi
68447b5038d7SDag-Erling Smørgrav
68457b5038d7SDag-Erling Smørgrav		  # CHECK ME:  I think I busted this.  -Ossama
6846986ba33cSDag-Erling Smørgrav		  if test dlprefiles = "$prev"; then
68477b5038d7SDag-Erling Smørgrav		    # Preload the old-style object.
68487b5038d7SDag-Erling Smørgrav		    func_append dlprefiles " $pic_object"
68497b5038d7SDag-Erling Smørgrav		    prev=
68507b5038d7SDag-Erling Smørgrav		  fi
68517b5038d7SDag-Erling Smørgrav
68527b5038d7SDag-Erling Smørgrav		  # A PIC object.
68537b5038d7SDag-Erling Smørgrav		  func_append libobjs " $pic_object"
6854986ba33cSDag-Erling Smørgrav		  arg=$pic_object
68557b5038d7SDag-Erling Smørgrav		fi
68567b5038d7SDag-Erling Smørgrav
68577b5038d7SDag-Erling Smørgrav		# Non-PIC object.
6858986ba33cSDag-Erling Smørgrav		if test none != "$non_pic_object"; then
68597b5038d7SDag-Erling Smørgrav		  # Prepend the subdirectory the object is found in.
6860986ba33cSDag-Erling Smørgrav		  non_pic_object=$xdir$non_pic_object
68617b5038d7SDag-Erling Smørgrav
68627b5038d7SDag-Erling Smørgrav		  # A standard non-PIC object
68637b5038d7SDag-Erling Smørgrav		  func_append non_pic_objects " $non_pic_object"
6864986ba33cSDag-Erling Smørgrav		  if test -z "$pic_object" || test none = "$pic_object"; then
6865986ba33cSDag-Erling Smørgrav		    arg=$non_pic_object
68667b5038d7SDag-Erling Smørgrav		  fi
68677b5038d7SDag-Erling Smørgrav		else
68687b5038d7SDag-Erling Smørgrav		  # If the PIC object exists, use it instead.
68697b5038d7SDag-Erling Smørgrav		  # $xdir was prepended to $pic_object above.
6870986ba33cSDag-Erling Smørgrav		  non_pic_object=$pic_object
68717b5038d7SDag-Erling Smørgrav		  func_append non_pic_objects " $non_pic_object"
68727b5038d7SDag-Erling Smørgrav		fi
68737b5038d7SDag-Erling Smørgrav	      else
68747b5038d7SDag-Erling Smørgrav		# Only an error if not doing a dry-run.
68757b5038d7SDag-Erling Smørgrav		if $opt_dry_run; then
68767b5038d7SDag-Erling Smørgrav		  # Extract subdirectory from the argument.
68777b5038d7SDag-Erling Smørgrav		  func_dirname "$arg" "/" ""
6878986ba33cSDag-Erling Smørgrav		  xdir=$func_dirname_result
68797b5038d7SDag-Erling Smørgrav
68807b5038d7SDag-Erling Smørgrav		  func_lo2o "$arg"
68817b5038d7SDag-Erling Smørgrav		  pic_object=$xdir$objdir/$func_lo2o_result
68827b5038d7SDag-Erling Smørgrav		  non_pic_object=$xdir$func_lo2o_result
68837b5038d7SDag-Erling Smørgrav		  func_append libobjs " $pic_object"
68847b5038d7SDag-Erling Smørgrav		  func_append non_pic_objects " $non_pic_object"
68857b5038d7SDag-Erling Smørgrav	        else
6886986ba33cSDag-Erling Smørgrav		  func_fatal_error "'$arg' is not a valid libtool object"
68877b5038d7SDag-Erling Smørgrav		fi
68887b5038d7SDag-Erling Smørgrav	      fi
68897b5038d7SDag-Erling Smørgrav	    done
68907b5038d7SDag-Erling Smørgrav	  else
6891986ba33cSDag-Erling Smørgrav	    func_fatal_error "link input file '$arg' does not exist"
68927b5038d7SDag-Erling Smørgrav	  fi
68937b5038d7SDag-Erling Smørgrav	  arg=$save_arg
68947b5038d7SDag-Erling Smørgrav	  prev=
68957b5038d7SDag-Erling Smørgrav	  continue
68967b5038d7SDag-Erling Smørgrav	  ;;
6897986ba33cSDag-Erling Smørgrav	os2dllname)
6898986ba33cSDag-Erling Smørgrav	  os2dllname=$arg
6899986ba33cSDag-Erling Smørgrav	  prev=
6900986ba33cSDag-Erling Smørgrav	  continue
6901986ba33cSDag-Erling Smørgrav	  ;;
69027b5038d7SDag-Erling Smørgrav	precious_regex)
6903986ba33cSDag-Erling Smørgrav	  precious_files_regex=$arg
69047b5038d7SDag-Erling Smørgrav	  prev=
69057b5038d7SDag-Erling Smørgrav	  continue
69067b5038d7SDag-Erling Smørgrav	  ;;
69077b5038d7SDag-Erling Smørgrav	release)
6908986ba33cSDag-Erling Smørgrav	  release=-$arg
69097b5038d7SDag-Erling Smørgrav	  prev=
69107b5038d7SDag-Erling Smørgrav	  continue
69117b5038d7SDag-Erling Smørgrav	  ;;
69127b5038d7SDag-Erling Smørgrav	rpath | xrpath)
69137b5038d7SDag-Erling Smørgrav	  # We need an absolute path.
69147b5038d7SDag-Erling Smørgrav	  case $arg in
69157b5038d7SDag-Erling Smørgrav	  [\\/]* | [A-Za-z]:[\\/]*) ;;
69167b5038d7SDag-Erling Smørgrav	  *)
69177b5038d7SDag-Erling Smørgrav	    func_fatal_error "only absolute run-paths are allowed"
69187b5038d7SDag-Erling Smørgrav	    ;;
69197b5038d7SDag-Erling Smørgrav	  esac
6920986ba33cSDag-Erling Smørgrav	  if test rpath = "$prev"; then
69217b5038d7SDag-Erling Smørgrav	    case "$rpath " in
69227b5038d7SDag-Erling Smørgrav	    *" $arg "*) ;;
69237b5038d7SDag-Erling Smørgrav	    *) func_append rpath " $arg" ;;
69247b5038d7SDag-Erling Smørgrav	    esac
69257b5038d7SDag-Erling Smørgrav	  else
69267b5038d7SDag-Erling Smørgrav	    case "$xrpath " in
69277b5038d7SDag-Erling Smørgrav	    *" $arg "*) ;;
69287b5038d7SDag-Erling Smørgrav	    *) func_append xrpath " $arg" ;;
69297b5038d7SDag-Erling Smørgrav	    esac
69307b5038d7SDag-Erling Smørgrav	  fi
69317b5038d7SDag-Erling Smørgrav	  prev=
69327b5038d7SDag-Erling Smørgrav	  continue
69337b5038d7SDag-Erling Smørgrav	  ;;
69347b5038d7SDag-Erling Smørgrav	shrext)
6935986ba33cSDag-Erling Smørgrav	  shrext_cmds=$arg
69367b5038d7SDag-Erling Smørgrav	  prev=
69377b5038d7SDag-Erling Smørgrav	  continue
69387b5038d7SDag-Erling Smørgrav	  ;;
69397b5038d7SDag-Erling Smørgrav	weak)
69407b5038d7SDag-Erling Smørgrav	  func_append weak_libs " $arg"
69417b5038d7SDag-Erling Smørgrav	  prev=
69427b5038d7SDag-Erling Smørgrav	  continue
69437b5038d7SDag-Erling Smørgrav	  ;;
69447b5038d7SDag-Erling Smørgrav	xcclinker)
69457b5038d7SDag-Erling Smørgrav	  func_append linker_flags " $qarg"
69467b5038d7SDag-Erling Smørgrav	  func_append compiler_flags " $qarg"
69477b5038d7SDag-Erling Smørgrav	  prev=
69487b5038d7SDag-Erling Smørgrav	  func_append compile_command " $qarg"
69497b5038d7SDag-Erling Smørgrav	  func_append finalize_command " $qarg"
69507b5038d7SDag-Erling Smørgrav	  continue
69517b5038d7SDag-Erling Smørgrav	  ;;
69527b5038d7SDag-Erling Smørgrav	xcompiler)
69537b5038d7SDag-Erling Smørgrav	  func_append compiler_flags " $qarg"
69547b5038d7SDag-Erling Smørgrav	  prev=
69557b5038d7SDag-Erling Smørgrav	  func_append compile_command " $qarg"
69567b5038d7SDag-Erling Smørgrav	  func_append finalize_command " $qarg"
69577b5038d7SDag-Erling Smørgrav	  continue
69587b5038d7SDag-Erling Smørgrav	  ;;
69597b5038d7SDag-Erling Smørgrav	xlinker)
69607b5038d7SDag-Erling Smørgrav	  func_append linker_flags " $qarg"
69617b5038d7SDag-Erling Smørgrav	  func_append compiler_flags " $wl$qarg"
69627b5038d7SDag-Erling Smørgrav	  prev=
69637b5038d7SDag-Erling Smørgrav	  func_append compile_command " $wl$qarg"
69647b5038d7SDag-Erling Smørgrav	  func_append finalize_command " $wl$qarg"
69657b5038d7SDag-Erling Smørgrav	  continue
69667b5038d7SDag-Erling Smørgrav	  ;;
69677b5038d7SDag-Erling Smørgrav	*)
69687b5038d7SDag-Erling Smørgrav	  eval "$prev=\"\$arg\""
69697b5038d7SDag-Erling Smørgrav	  prev=
69707b5038d7SDag-Erling Smørgrav	  continue
69717b5038d7SDag-Erling Smørgrav	  ;;
69727b5038d7SDag-Erling Smørgrav	esac
69737b5038d7SDag-Erling Smørgrav      fi # test -n "$prev"
69747b5038d7SDag-Erling Smørgrav
6975986ba33cSDag-Erling Smørgrav      prevarg=$arg
69767b5038d7SDag-Erling Smørgrav
69777b5038d7SDag-Erling Smørgrav      case $arg in
69787b5038d7SDag-Erling Smørgrav      -all-static)
69797b5038d7SDag-Erling Smørgrav	if test -n "$link_static_flag"; then
69807b5038d7SDag-Erling Smørgrav	  # See comment for -static flag below, for more details.
69817b5038d7SDag-Erling Smørgrav	  func_append compile_command " $link_static_flag"
69827b5038d7SDag-Erling Smørgrav	  func_append finalize_command " $link_static_flag"
69837b5038d7SDag-Erling Smørgrav	fi
69847b5038d7SDag-Erling Smørgrav	continue
69857b5038d7SDag-Erling Smørgrav	;;
69867b5038d7SDag-Erling Smørgrav
69877b5038d7SDag-Erling Smørgrav      -allow-undefined)
69887b5038d7SDag-Erling Smørgrav	# FIXME: remove this flag sometime in the future.
6989986ba33cSDag-Erling Smørgrav	func_fatal_error "'-allow-undefined' must not be used because it is the default"
69907b5038d7SDag-Erling Smørgrav	;;
69917b5038d7SDag-Erling Smørgrav
69927b5038d7SDag-Erling Smørgrav      -avoid-version)
69937b5038d7SDag-Erling Smørgrav	avoid_version=yes
69947b5038d7SDag-Erling Smørgrav	continue
69957b5038d7SDag-Erling Smørgrav	;;
69967b5038d7SDag-Erling Smørgrav
69977b5038d7SDag-Erling Smørgrav      -bindir)
69987b5038d7SDag-Erling Smørgrav	prev=bindir
69997b5038d7SDag-Erling Smørgrav	continue
70007b5038d7SDag-Erling Smørgrav	;;
70017b5038d7SDag-Erling Smørgrav
70027b5038d7SDag-Erling Smørgrav      -dlopen)
70037b5038d7SDag-Erling Smørgrav	prev=dlfiles
70047b5038d7SDag-Erling Smørgrav	continue
70057b5038d7SDag-Erling Smørgrav	;;
70067b5038d7SDag-Erling Smørgrav
70077b5038d7SDag-Erling Smørgrav      -dlpreopen)
70087b5038d7SDag-Erling Smørgrav	prev=dlprefiles
70097b5038d7SDag-Erling Smørgrav	continue
70107b5038d7SDag-Erling Smørgrav	;;
70117b5038d7SDag-Erling Smørgrav
70127b5038d7SDag-Erling Smørgrav      -export-dynamic)
70137b5038d7SDag-Erling Smørgrav	export_dynamic=yes
70147b5038d7SDag-Erling Smørgrav	continue
70157b5038d7SDag-Erling Smørgrav	;;
70167b5038d7SDag-Erling Smørgrav
70177b5038d7SDag-Erling Smørgrav      -export-symbols | -export-symbols-regex)
70187b5038d7SDag-Erling Smørgrav	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
70197b5038d7SDag-Erling Smørgrav	  func_fatal_error "more than one -exported-symbols argument is not allowed"
70207b5038d7SDag-Erling Smørgrav	fi
7021986ba33cSDag-Erling Smørgrav	if test X-export-symbols = "X$arg"; then
70227b5038d7SDag-Erling Smørgrav	  prev=expsyms
70237b5038d7SDag-Erling Smørgrav	else
70247b5038d7SDag-Erling Smørgrav	  prev=expsyms_regex
70257b5038d7SDag-Erling Smørgrav	fi
70267b5038d7SDag-Erling Smørgrav	continue
70277b5038d7SDag-Erling Smørgrav	;;
70287b5038d7SDag-Erling Smørgrav
70297b5038d7SDag-Erling Smørgrav      -framework)
70307b5038d7SDag-Erling Smørgrav	prev=framework
70317b5038d7SDag-Erling Smørgrav	continue
70327b5038d7SDag-Erling Smørgrav	;;
70337b5038d7SDag-Erling Smørgrav
70347b5038d7SDag-Erling Smørgrav      -inst-prefix-dir)
70357b5038d7SDag-Erling Smørgrav	prev=inst_prefix
70367b5038d7SDag-Erling Smørgrav	continue
70377b5038d7SDag-Erling Smørgrav	;;
70387b5038d7SDag-Erling Smørgrav
70397b5038d7SDag-Erling Smørgrav      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
70407b5038d7SDag-Erling Smørgrav      # so, if we see these flags be careful not to treat them like -L
70417b5038d7SDag-Erling Smørgrav      -L[A-Z][A-Z]*:*)
70427b5038d7SDag-Erling Smørgrav	case $with_gcc/$host in
70437b5038d7SDag-Erling Smørgrav	no/*-*-irix* | /*-*-irix*)
70447b5038d7SDag-Erling Smørgrav	  func_append compile_command " $arg"
70457b5038d7SDag-Erling Smørgrav	  func_append finalize_command " $arg"
70467b5038d7SDag-Erling Smørgrav	  ;;
70477b5038d7SDag-Erling Smørgrav	esac
70487b5038d7SDag-Erling Smørgrav	continue
70497b5038d7SDag-Erling Smørgrav	;;
70507b5038d7SDag-Erling Smørgrav
70517b5038d7SDag-Erling Smørgrav      -L*)
70527b5038d7SDag-Erling Smørgrav	func_stripname "-L" '' "$arg"
70537b5038d7SDag-Erling Smørgrav	if test -z "$func_stripname_result"; then
70547b5038d7SDag-Erling Smørgrav	  if test "$#" -gt 0; then
7055986ba33cSDag-Erling Smørgrav	    func_fatal_error "require no space between '-L' and '$1'"
70567b5038d7SDag-Erling Smørgrav	  else
7057986ba33cSDag-Erling Smørgrav	    func_fatal_error "need path for '-L' option"
70587b5038d7SDag-Erling Smørgrav	  fi
70597b5038d7SDag-Erling Smørgrav	fi
70607b5038d7SDag-Erling Smørgrav	func_resolve_sysroot "$func_stripname_result"
70617b5038d7SDag-Erling Smørgrav	dir=$func_resolve_sysroot_result
70627b5038d7SDag-Erling Smørgrav	# We need an absolute path.
70637b5038d7SDag-Erling Smørgrav	case $dir in
70647b5038d7SDag-Erling Smørgrav	[\\/]* | [A-Za-z]:[\\/]*) ;;
70657b5038d7SDag-Erling Smørgrav	*)
70667b5038d7SDag-Erling Smørgrav	  absdir=`cd "$dir" && pwd`
70677b5038d7SDag-Erling Smørgrav	  test -z "$absdir" && \
7068986ba33cSDag-Erling Smørgrav	    func_fatal_error "cannot determine absolute directory name of '$dir'"
7069986ba33cSDag-Erling Smørgrav	  dir=$absdir
70707b5038d7SDag-Erling Smørgrav	  ;;
70717b5038d7SDag-Erling Smørgrav	esac
70727b5038d7SDag-Erling Smørgrav	case "$deplibs " in
70737b5038d7SDag-Erling Smørgrav	*" -L$dir "* | *" $arg "*)
70747b5038d7SDag-Erling Smørgrav	  # Will only happen for absolute or sysroot arguments
70757b5038d7SDag-Erling Smørgrav	  ;;
70767b5038d7SDag-Erling Smørgrav	*)
70777b5038d7SDag-Erling Smørgrav	  # Preserve sysroot, but never include relative directories
70787b5038d7SDag-Erling Smørgrav	  case $dir in
70797b5038d7SDag-Erling Smørgrav	    [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;;
70807b5038d7SDag-Erling Smørgrav	    *) func_append deplibs " -L$dir" ;;
70817b5038d7SDag-Erling Smørgrav	  esac
70827b5038d7SDag-Erling Smørgrav	  func_append lib_search_path " $dir"
70837b5038d7SDag-Erling Smørgrav	  ;;
70847b5038d7SDag-Erling Smørgrav	esac
70857b5038d7SDag-Erling Smørgrav	case $host in
70867b5038d7SDag-Erling Smørgrav	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
70877b5038d7SDag-Erling Smørgrav	  testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'`
70887b5038d7SDag-Erling Smørgrav	  case :$dllsearchpath: in
70897b5038d7SDag-Erling Smørgrav	  *":$dir:"*) ;;
70907b5038d7SDag-Erling Smørgrav	  ::) dllsearchpath=$dir;;
70917b5038d7SDag-Erling Smørgrav	  *) func_append dllsearchpath ":$dir";;
70927b5038d7SDag-Erling Smørgrav	  esac
70937b5038d7SDag-Erling Smørgrav	  case :$dllsearchpath: in
70947b5038d7SDag-Erling Smørgrav	  *":$testbindir:"*) ;;
70957b5038d7SDag-Erling Smørgrav	  ::) dllsearchpath=$testbindir;;
70967b5038d7SDag-Erling Smørgrav	  *) func_append dllsearchpath ":$testbindir";;
70977b5038d7SDag-Erling Smørgrav	  esac
70987b5038d7SDag-Erling Smørgrav	  ;;
70997b5038d7SDag-Erling Smørgrav	esac
71007b5038d7SDag-Erling Smørgrav	continue
71017b5038d7SDag-Erling Smørgrav	;;
71027b5038d7SDag-Erling Smørgrav
71037b5038d7SDag-Erling Smørgrav      -l*)
7104986ba33cSDag-Erling Smørgrav	if test X-lc = "X$arg" || test X-lm = "X$arg"; then
71057b5038d7SDag-Erling Smørgrav	  case $host in
71067b5038d7SDag-Erling Smørgrav	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)
71077b5038d7SDag-Erling Smørgrav	    # These systems don't actually have a C or math library (as such)
71087b5038d7SDag-Erling Smørgrav	    continue
71097b5038d7SDag-Erling Smørgrav	    ;;
71107b5038d7SDag-Erling Smørgrav	  *-*-os2*)
71117b5038d7SDag-Erling Smørgrav	    # These systems don't actually have a C library (as such)
7112986ba33cSDag-Erling Smørgrav	    test X-lc = "X$arg" && continue
71137b5038d7SDag-Erling Smørgrav	    ;;
7114986ba33cSDag-Erling Smørgrav	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
71157b5038d7SDag-Erling Smørgrav	    # Do not include libc due to us having libc/libc_r.
7116986ba33cSDag-Erling Smørgrav	    test X-lc = "X$arg" && continue
71177b5038d7SDag-Erling Smørgrav	    ;;
71187b5038d7SDag-Erling Smørgrav	  *-*-rhapsody* | *-*-darwin1.[012])
71197b5038d7SDag-Erling Smørgrav	    # Rhapsody C and math libraries are in the System framework
71207b5038d7SDag-Erling Smørgrav	    func_append deplibs " System.ltframework"
71217b5038d7SDag-Erling Smørgrav	    continue
71227b5038d7SDag-Erling Smørgrav	    ;;
71237b5038d7SDag-Erling Smørgrav	  *-*-sco3.2v5* | *-*-sco5v6*)
71247b5038d7SDag-Erling Smørgrav	    # Causes problems with __ctype
7125986ba33cSDag-Erling Smørgrav	    test X-lc = "X$arg" && continue
71267b5038d7SDag-Erling Smørgrav	    ;;
71277b5038d7SDag-Erling Smørgrav	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
71287b5038d7SDag-Erling Smørgrav	    # Compiler inserts libc in the correct place for threads to work
7129986ba33cSDag-Erling Smørgrav	    test X-lc = "X$arg" && continue
71307b5038d7SDag-Erling Smørgrav	    ;;
71317b5038d7SDag-Erling Smørgrav	  esac
7132986ba33cSDag-Erling Smørgrav	elif test X-lc_r = "X$arg"; then
71337b5038d7SDag-Erling Smørgrav	 case $host in
7134986ba33cSDag-Erling Smørgrav	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)
71357b5038d7SDag-Erling Smørgrav	   # Do not include libc_r directly, use -pthread flag.
71367b5038d7SDag-Erling Smørgrav	   continue
71377b5038d7SDag-Erling Smørgrav	   ;;
71387b5038d7SDag-Erling Smørgrav	 esac
71397b5038d7SDag-Erling Smørgrav	fi
71407b5038d7SDag-Erling Smørgrav	func_append deplibs " $arg"
71417b5038d7SDag-Erling Smørgrav	continue
71427b5038d7SDag-Erling Smørgrav	;;
71437b5038d7SDag-Erling Smørgrav
7144986ba33cSDag-Erling Smørgrav      -mllvm)
7145986ba33cSDag-Erling Smørgrav	prev=mllvm
7146986ba33cSDag-Erling Smørgrav	continue
7147986ba33cSDag-Erling Smørgrav	;;
7148986ba33cSDag-Erling Smørgrav
71497b5038d7SDag-Erling Smørgrav      -module)
71507b5038d7SDag-Erling Smørgrav	module=yes
71517b5038d7SDag-Erling Smørgrav	continue
71527b5038d7SDag-Erling Smørgrav	;;
71537b5038d7SDag-Erling Smørgrav
71547b5038d7SDag-Erling Smørgrav      # Tru64 UNIX uses -model [arg] to determine the layout of C++
71557b5038d7SDag-Erling Smørgrav      # classes, name mangling, and exception handling.
71567b5038d7SDag-Erling Smørgrav      # Darwin uses the -arch flag to determine output architecture.
71577b5038d7SDag-Erling Smørgrav      -model|-arch|-isysroot|--sysroot)
71587b5038d7SDag-Erling Smørgrav	func_append compiler_flags " $arg"
71597b5038d7SDag-Erling Smørgrav	func_append compile_command " $arg"
71607b5038d7SDag-Erling Smørgrav	func_append finalize_command " $arg"
71617b5038d7SDag-Erling Smørgrav	prev=xcompiler
71627b5038d7SDag-Erling Smørgrav	continue
71637b5038d7SDag-Erling Smørgrav	;;
71647b5038d7SDag-Erling Smørgrav
71657b5038d7SDag-Erling Smørgrav      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
71667b5038d7SDag-Erling Smørgrav      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
71677b5038d7SDag-Erling Smørgrav	func_append compiler_flags " $arg"
71687b5038d7SDag-Erling Smørgrav	func_append compile_command " $arg"
71697b5038d7SDag-Erling Smørgrav	func_append finalize_command " $arg"
71707b5038d7SDag-Erling Smørgrav	case "$new_inherited_linker_flags " in
71717b5038d7SDag-Erling Smørgrav	    *" $arg "*) ;;
71727b5038d7SDag-Erling Smørgrav	    * ) func_append new_inherited_linker_flags " $arg" ;;
71737b5038d7SDag-Erling Smørgrav	esac
71747b5038d7SDag-Erling Smørgrav	continue
71757b5038d7SDag-Erling Smørgrav	;;
71767b5038d7SDag-Erling Smørgrav
71777b5038d7SDag-Erling Smørgrav      -multi_module)
7178986ba33cSDag-Erling Smørgrav	single_module=$wl-multi_module
71797b5038d7SDag-Erling Smørgrav	continue
71807b5038d7SDag-Erling Smørgrav	;;
71817b5038d7SDag-Erling Smørgrav
71827b5038d7SDag-Erling Smørgrav      -no-fast-install)
71837b5038d7SDag-Erling Smørgrav	fast_install=no
71847b5038d7SDag-Erling Smørgrav	continue
71857b5038d7SDag-Erling Smørgrav	;;
71867b5038d7SDag-Erling Smørgrav
71877b5038d7SDag-Erling Smørgrav      -no-install)
71887b5038d7SDag-Erling Smørgrav	case $host in
71897b5038d7SDag-Erling Smørgrav	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)
71907b5038d7SDag-Erling Smørgrav	  # The PATH hackery in wrapper scripts is required on Windows
71917b5038d7SDag-Erling Smørgrav	  # and Darwin in order for the loader to find any dlls it needs.
7192986ba33cSDag-Erling Smørgrav	  func_warning "'-no-install' is ignored for $host"
7193986ba33cSDag-Erling Smørgrav	  func_warning "assuming '-no-fast-install' instead"
71947b5038d7SDag-Erling Smørgrav	  fast_install=no
71957b5038d7SDag-Erling Smørgrav	  ;;
71967b5038d7SDag-Erling Smørgrav	*) no_install=yes ;;
71977b5038d7SDag-Erling Smørgrav	esac
71987b5038d7SDag-Erling Smørgrav	continue
71997b5038d7SDag-Erling Smørgrav	;;
72007b5038d7SDag-Erling Smørgrav
72017b5038d7SDag-Erling Smørgrav      -no-undefined)
72027b5038d7SDag-Erling Smørgrav	allow_undefined=no
72037b5038d7SDag-Erling Smørgrav	continue
72047b5038d7SDag-Erling Smørgrav	;;
72057b5038d7SDag-Erling Smørgrav
72067b5038d7SDag-Erling Smørgrav      -objectlist)
72077b5038d7SDag-Erling Smørgrav	prev=objectlist
72087b5038d7SDag-Erling Smørgrav	continue
72097b5038d7SDag-Erling Smørgrav	;;
72107b5038d7SDag-Erling Smørgrav
7211986ba33cSDag-Erling Smørgrav      -os2dllname)
7212986ba33cSDag-Erling Smørgrav	prev=os2dllname
7213986ba33cSDag-Erling Smørgrav	continue
7214986ba33cSDag-Erling Smørgrav	;;
7215986ba33cSDag-Erling Smørgrav
72167b5038d7SDag-Erling Smørgrav      -o) prev=output ;;
72177b5038d7SDag-Erling Smørgrav
72187b5038d7SDag-Erling Smørgrav      -precious-files-regex)
72197b5038d7SDag-Erling Smørgrav	prev=precious_regex
72207b5038d7SDag-Erling Smørgrav	continue
72217b5038d7SDag-Erling Smørgrav	;;
72227b5038d7SDag-Erling Smørgrav
72237b5038d7SDag-Erling Smørgrav      -release)
72247b5038d7SDag-Erling Smørgrav	prev=release
72257b5038d7SDag-Erling Smørgrav	continue
72267b5038d7SDag-Erling Smørgrav	;;
72277b5038d7SDag-Erling Smørgrav
72287b5038d7SDag-Erling Smørgrav      -rpath)
72297b5038d7SDag-Erling Smørgrav	prev=rpath
72307b5038d7SDag-Erling Smørgrav	continue
72317b5038d7SDag-Erling Smørgrav	;;
72327b5038d7SDag-Erling Smørgrav
72337b5038d7SDag-Erling Smørgrav      -R)
72347b5038d7SDag-Erling Smørgrav	prev=xrpath
72357b5038d7SDag-Erling Smørgrav	continue
72367b5038d7SDag-Erling Smørgrav	;;
72377b5038d7SDag-Erling Smørgrav
72387b5038d7SDag-Erling Smørgrav      -R*)
72397b5038d7SDag-Erling Smørgrav	func_stripname '-R' '' "$arg"
72407b5038d7SDag-Erling Smørgrav	dir=$func_stripname_result
72417b5038d7SDag-Erling Smørgrav	# We need an absolute path.
72427b5038d7SDag-Erling Smørgrav	case $dir in
72437b5038d7SDag-Erling Smørgrav	[\\/]* | [A-Za-z]:[\\/]*) ;;
72447b5038d7SDag-Erling Smørgrav	=*)
72457b5038d7SDag-Erling Smørgrav	  func_stripname '=' '' "$dir"
72467b5038d7SDag-Erling Smørgrav	  dir=$lt_sysroot$func_stripname_result
72477b5038d7SDag-Erling Smørgrav	  ;;
72487b5038d7SDag-Erling Smørgrav	*)
72497b5038d7SDag-Erling Smørgrav	  func_fatal_error "only absolute run-paths are allowed"
72507b5038d7SDag-Erling Smørgrav	  ;;
72517b5038d7SDag-Erling Smørgrav	esac
72527b5038d7SDag-Erling Smørgrav	case "$xrpath " in
72537b5038d7SDag-Erling Smørgrav	*" $dir "*) ;;
72547b5038d7SDag-Erling Smørgrav	*) func_append xrpath " $dir" ;;
72557b5038d7SDag-Erling Smørgrav	esac
72567b5038d7SDag-Erling Smørgrav	continue
72577b5038d7SDag-Erling Smørgrav	;;
72587b5038d7SDag-Erling Smørgrav
72597b5038d7SDag-Erling Smørgrav      -shared)
72607b5038d7SDag-Erling Smørgrav	# The effects of -shared are defined in a previous loop.
72617b5038d7SDag-Erling Smørgrav	continue
72627b5038d7SDag-Erling Smørgrav	;;
72637b5038d7SDag-Erling Smørgrav
72647b5038d7SDag-Erling Smørgrav      -shrext)
72657b5038d7SDag-Erling Smørgrav	prev=shrext
72667b5038d7SDag-Erling Smørgrav	continue
72677b5038d7SDag-Erling Smørgrav	;;
72687b5038d7SDag-Erling Smørgrav
72697b5038d7SDag-Erling Smørgrav      -static | -static-libtool-libs)
72707b5038d7SDag-Erling Smørgrav	# The effects of -static are defined in a previous loop.
72717b5038d7SDag-Erling Smørgrav	# We used to do the same as -all-static on platforms that
72727b5038d7SDag-Erling Smørgrav	# didn't have a PIC flag, but the assumption that the effects
72737b5038d7SDag-Erling Smørgrav	# would be equivalent was wrong.  It would break on at least
72747b5038d7SDag-Erling Smørgrav	# Digital Unix and AIX.
72757b5038d7SDag-Erling Smørgrav	continue
72767b5038d7SDag-Erling Smørgrav	;;
72777b5038d7SDag-Erling Smørgrav
72787b5038d7SDag-Erling Smørgrav      -thread-safe)
72797b5038d7SDag-Erling Smørgrav	thread_safe=yes
72807b5038d7SDag-Erling Smørgrav	continue
72817b5038d7SDag-Erling Smørgrav	;;
72827b5038d7SDag-Erling Smørgrav
72837b5038d7SDag-Erling Smørgrav      -version-info)
72847b5038d7SDag-Erling Smørgrav	prev=vinfo
72857b5038d7SDag-Erling Smørgrav	continue
72867b5038d7SDag-Erling Smørgrav	;;
72877b5038d7SDag-Erling Smørgrav
72887b5038d7SDag-Erling Smørgrav      -version-number)
72897b5038d7SDag-Erling Smørgrav	prev=vinfo
72907b5038d7SDag-Erling Smørgrav	vinfo_number=yes
72917b5038d7SDag-Erling Smørgrav	continue
72927b5038d7SDag-Erling Smørgrav	;;
72937b5038d7SDag-Erling Smørgrav
72947b5038d7SDag-Erling Smørgrav      -weak)
72957b5038d7SDag-Erling Smørgrav        prev=weak
72967b5038d7SDag-Erling Smørgrav	continue
72977b5038d7SDag-Erling Smørgrav	;;
72987b5038d7SDag-Erling Smørgrav
72997b5038d7SDag-Erling Smørgrav      -Wc,*)
73007b5038d7SDag-Erling Smørgrav	func_stripname '-Wc,' '' "$arg"
73017b5038d7SDag-Erling Smørgrav	args=$func_stripname_result
73027b5038d7SDag-Erling Smørgrav	arg=
7303986ba33cSDag-Erling Smørgrav	save_ifs=$IFS; IFS=,
73047b5038d7SDag-Erling Smørgrav	for flag in $args; do
7305986ba33cSDag-Erling Smørgrav	  IFS=$save_ifs
73067b5038d7SDag-Erling Smørgrav          func_quote_for_eval "$flag"
73077b5038d7SDag-Erling Smørgrav	  func_append arg " $func_quote_for_eval_result"
73087b5038d7SDag-Erling Smørgrav	  func_append compiler_flags " $func_quote_for_eval_result"
73097b5038d7SDag-Erling Smørgrav	done
7310986ba33cSDag-Erling Smørgrav	IFS=$save_ifs
73117b5038d7SDag-Erling Smørgrav	func_stripname ' ' '' "$arg"
73127b5038d7SDag-Erling Smørgrav	arg=$func_stripname_result
73137b5038d7SDag-Erling Smørgrav	;;
73147b5038d7SDag-Erling Smørgrav
73157b5038d7SDag-Erling Smørgrav      -Wl,*)
73167b5038d7SDag-Erling Smørgrav	func_stripname '-Wl,' '' "$arg"
73177b5038d7SDag-Erling Smørgrav	args=$func_stripname_result
73187b5038d7SDag-Erling Smørgrav	arg=
7319986ba33cSDag-Erling Smørgrav	save_ifs=$IFS; IFS=,
73207b5038d7SDag-Erling Smørgrav	for flag in $args; do
7321986ba33cSDag-Erling Smørgrav	  IFS=$save_ifs
73227b5038d7SDag-Erling Smørgrav          func_quote_for_eval "$flag"
73237b5038d7SDag-Erling Smørgrav	  func_append arg " $wl$func_quote_for_eval_result"
73247b5038d7SDag-Erling Smørgrav	  func_append compiler_flags " $wl$func_quote_for_eval_result"
73257b5038d7SDag-Erling Smørgrav	  func_append linker_flags " $func_quote_for_eval_result"
73267b5038d7SDag-Erling Smørgrav	done
7327986ba33cSDag-Erling Smørgrav	IFS=$save_ifs
73287b5038d7SDag-Erling Smørgrav	func_stripname ' ' '' "$arg"
73297b5038d7SDag-Erling Smørgrav	arg=$func_stripname_result
73307b5038d7SDag-Erling Smørgrav	;;
73317b5038d7SDag-Erling Smørgrav
73327b5038d7SDag-Erling Smørgrav      -Xcompiler)
73337b5038d7SDag-Erling Smørgrav	prev=xcompiler
73347b5038d7SDag-Erling Smørgrav	continue
73357b5038d7SDag-Erling Smørgrav	;;
73367b5038d7SDag-Erling Smørgrav
73377b5038d7SDag-Erling Smørgrav      -Xlinker)
73387b5038d7SDag-Erling Smørgrav	prev=xlinker
73397b5038d7SDag-Erling Smørgrav	continue
73407b5038d7SDag-Erling Smørgrav	;;
73417b5038d7SDag-Erling Smørgrav
73427b5038d7SDag-Erling Smørgrav      -XCClinker)
73437b5038d7SDag-Erling Smørgrav	prev=xcclinker
73447b5038d7SDag-Erling Smørgrav	continue
73457b5038d7SDag-Erling Smørgrav	;;
73467b5038d7SDag-Erling Smørgrav
73477b5038d7SDag-Erling Smørgrav      # -msg_* for osf cc
73487b5038d7SDag-Erling Smørgrav      -msg_*)
73497b5038d7SDag-Erling Smørgrav	func_quote_for_eval "$arg"
7350986ba33cSDag-Erling Smørgrav	arg=$func_quote_for_eval_result
73517b5038d7SDag-Erling Smørgrav	;;
73527b5038d7SDag-Erling Smørgrav
73537b5038d7SDag-Erling Smørgrav      # Flags to be passed through unchanged, with rationale:
73547b5038d7SDag-Erling Smørgrav      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler
73557b5038d7SDag-Erling Smørgrav      # -r[0-9][0-9]*        specify processor for the SGI compiler
73567b5038d7SDag-Erling Smørgrav      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler
73577b5038d7SDag-Erling Smørgrav      # +DA*, +DD*           enable 64-bit mode for the HP compiler
73587b5038d7SDag-Erling Smørgrav      # -q*                  compiler args for the IBM compiler
73597b5038d7SDag-Erling Smørgrav      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC
73607b5038d7SDag-Erling Smørgrav      # -F/path              path to uninstalled frameworks, gcc on darwin
73617b5038d7SDag-Erling Smørgrav      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC
7362986ba33cSDag-Erling Smørgrav      # -fstack-protector*   stack protector flags for GCC
73637b5038d7SDag-Erling Smørgrav      # @file                GCC response files
73647b5038d7SDag-Erling Smørgrav      # -tp=*                Portland pgcc target processor selection
73657b5038d7SDag-Erling Smørgrav      # --sysroot=*          for sysroot support
7366986ba33cSDag-Erling Smørgrav      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
7367986ba33cSDag-Erling Smørgrav      # -specs=*             GCC specs files
7368986ba33cSDag-Erling Smørgrav      # -stdlib=*            select c++ std lib with clang
7369986ba33cSDag-Erling Smørgrav      # -fsanitize=*         Clang/GCC memory and address sanitizer
7370*5afab0e5SDag-Erling Smørgrav      # -fuse-ld=*           Linker select flags for GCC
7371*5afab0e5SDag-Erling Smørgrav      # -static-*            direct GCC to link specific libraries statically
7372*5afab0e5SDag-Erling Smørgrav      # -fcilkplus           Cilk Plus language extension features for C/C++
73737b5038d7SDag-Erling Smørgrav      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
73747b5038d7SDag-Erling Smørgrav      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
7375986ba33cSDag-Erling Smørgrav      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \
7376*5afab0e5SDag-Erling Smørgrav      -specs=*|-fsanitize=*|-fuse-ld=*|-static-*|-fcilkplus)
73777b5038d7SDag-Erling Smørgrav        func_quote_for_eval "$arg"
7378986ba33cSDag-Erling Smørgrav	arg=$func_quote_for_eval_result
73797b5038d7SDag-Erling Smørgrav        func_append compile_command " $arg"
73807b5038d7SDag-Erling Smørgrav        func_append finalize_command " $arg"
73817b5038d7SDag-Erling Smørgrav        func_append compiler_flags " $arg"
73827b5038d7SDag-Erling Smørgrav        continue
73837b5038d7SDag-Erling Smørgrav        ;;
73847b5038d7SDag-Erling Smørgrav
7385986ba33cSDag-Erling Smørgrav      -Z*)
7386986ba33cSDag-Erling Smørgrav        if test os2 = "`expr $host : '.*\(os2\)'`"; then
7387986ba33cSDag-Erling Smørgrav          # OS/2 uses -Zxxx to specify OS/2-specific options
7388986ba33cSDag-Erling Smørgrav	  compiler_flags="$compiler_flags $arg"
7389986ba33cSDag-Erling Smørgrav	  func_append compile_command " $arg"
7390986ba33cSDag-Erling Smørgrav	  func_append finalize_command " $arg"
7391986ba33cSDag-Erling Smørgrav	  case $arg in
7392986ba33cSDag-Erling Smørgrav	  -Zlinker | -Zstack)
7393986ba33cSDag-Erling Smørgrav	    prev=xcompiler
7394986ba33cSDag-Erling Smørgrav	    ;;
7395986ba33cSDag-Erling Smørgrav	  esac
7396986ba33cSDag-Erling Smørgrav	  continue
7397986ba33cSDag-Erling Smørgrav        else
7398986ba33cSDag-Erling Smørgrav	  # Otherwise treat like 'Some other compiler flag' below
7399986ba33cSDag-Erling Smørgrav	  func_quote_for_eval "$arg"
7400986ba33cSDag-Erling Smørgrav	  arg=$func_quote_for_eval_result
7401986ba33cSDag-Erling Smørgrav        fi
7402986ba33cSDag-Erling Smørgrav	;;
7403986ba33cSDag-Erling Smørgrav
74047b5038d7SDag-Erling Smørgrav      # Some other compiler flag.
74057b5038d7SDag-Erling Smørgrav      -* | +*)
74067b5038d7SDag-Erling Smørgrav        func_quote_for_eval "$arg"
7407986ba33cSDag-Erling Smørgrav	arg=$func_quote_for_eval_result
74087b5038d7SDag-Erling Smørgrav	;;
74097b5038d7SDag-Erling Smørgrav
74107b5038d7SDag-Erling Smørgrav      *.$objext)
74117b5038d7SDag-Erling Smørgrav	# A standard object.
74127b5038d7SDag-Erling Smørgrav	func_append objs " $arg"
74137b5038d7SDag-Erling Smørgrav	;;
74147b5038d7SDag-Erling Smørgrav
74157b5038d7SDag-Erling Smørgrav      *.lo)
74167b5038d7SDag-Erling Smørgrav	# A libtool-controlled object.
74177b5038d7SDag-Erling Smørgrav
74187b5038d7SDag-Erling Smørgrav	# Check to see that this really is a libtool object.
74197b5038d7SDag-Erling Smørgrav	if func_lalib_unsafe_p "$arg"; then
74207b5038d7SDag-Erling Smørgrav	  pic_object=
74217b5038d7SDag-Erling Smørgrav	  non_pic_object=
74227b5038d7SDag-Erling Smørgrav
74237b5038d7SDag-Erling Smørgrav	  # Read the .lo file
74247b5038d7SDag-Erling Smørgrav	  func_source "$arg"
74257b5038d7SDag-Erling Smørgrav
74267b5038d7SDag-Erling Smørgrav	  if test -z "$pic_object" ||
74277b5038d7SDag-Erling Smørgrav	     test -z "$non_pic_object" ||
7428986ba33cSDag-Erling Smørgrav	     test none = "$pic_object" &&
7429986ba33cSDag-Erling Smørgrav	     test none = "$non_pic_object"; then
7430986ba33cSDag-Erling Smørgrav	    func_fatal_error "cannot find name of object for '$arg'"
74317b5038d7SDag-Erling Smørgrav	  fi
74327b5038d7SDag-Erling Smørgrav
74337b5038d7SDag-Erling Smørgrav	  # Extract subdirectory from the argument.
74347b5038d7SDag-Erling Smørgrav	  func_dirname "$arg" "/" ""
7435986ba33cSDag-Erling Smørgrav	  xdir=$func_dirname_result
74367b5038d7SDag-Erling Smørgrav
7437986ba33cSDag-Erling Smørgrav	  test none = "$pic_object" || {
74387b5038d7SDag-Erling Smørgrav	    # Prepend the subdirectory the object is found in.
7439986ba33cSDag-Erling Smørgrav	    pic_object=$xdir$pic_object
74407b5038d7SDag-Erling Smørgrav
7441986ba33cSDag-Erling Smørgrav	    if test dlfiles = "$prev"; then
7442986ba33cSDag-Erling Smørgrav	      if test yes = "$build_libtool_libs" && test yes = "$dlopen_support"; then
74437b5038d7SDag-Erling Smørgrav		func_append dlfiles " $pic_object"
74447b5038d7SDag-Erling Smørgrav		prev=
74457b5038d7SDag-Erling Smørgrav		continue
74467b5038d7SDag-Erling Smørgrav	      else
74477b5038d7SDag-Erling Smørgrav		# If libtool objects are unsupported, then we need to preload.
74487b5038d7SDag-Erling Smørgrav		prev=dlprefiles
74497b5038d7SDag-Erling Smørgrav	      fi
74507b5038d7SDag-Erling Smørgrav	    fi
74517b5038d7SDag-Erling Smørgrav
74527b5038d7SDag-Erling Smørgrav	    # CHECK ME:  I think I busted this.  -Ossama
7453986ba33cSDag-Erling Smørgrav	    if test dlprefiles = "$prev"; then
74547b5038d7SDag-Erling Smørgrav	      # Preload the old-style object.
74557b5038d7SDag-Erling Smørgrav	      func_append dlprefiles " $pic_object"
74567b5038d7SDag-Erling Smørgrav	      prev=
74577b5038d7SDag-Erling Smørgrav	    fi
74587b5038d7SDag-Erling Smørgrav
74597b5038d7SDag-Erling Smørgrav	    # A PIC object.
74607b5038d7SDag-Erling Smørgrav	    func_append libobjs " $pic_object"
7461986ba33cSDag-Erling Smørgrav	    arg=$pic_object
7462986ba33cSDag-Erling Smørgrav	  }
74637b5038d7SDag-Erling Smørgrav
74647b5038d7SDag-Erling Smørgrav	  # Non-PIC object.
7465986ba33cSDag-Erling Smørgrav	  if test none != "$non_pic_object"; then
74667b5038d7SDag-Erling Smørgrav	    # Prepend the subdirectory the object is found in.
7467986ba33cSDag-Erling Smørgrav	    non_pic_object=$xdir$non_pic_object
74687b5038d7SDag-Erling Smørgrav
74697b5038d7SDag-Erling Smørgrav	    # A standard non-PIC object
74707b5038d7SDag-Erling Smørgrav	    func_append non_pic_objects " $non_pic_object"
7471986ba33cSDag-Erling Smørgrav	    if test -z "$pic_object" || test none = "$pic_object"; then
7472986ba33cSDag-Erling Smørgrav	      arg=$non_pic_object
74737b5038d7SDag-Erling Smørgrav	    fi
74747b5038d7SDag-Erling Smørgrav	  else
74757b5038d7SDag-Erling Smørgrav	    # If the PIC object exists, use it instead.
74767b5038d7SDag-Erling Smørgrav	    # $xdir was prepended to $pic_object above.
7477986ba33cSDag-Erling Smørgrav	    non_pic_object=$pic_object
74787b5038d7SDag-Erling Smørgrav	    func_append non_pic_objects " $non_pic_object"
74797b5038d7SDag-Erling Smørgrav	  fi
74807b5038d7SDag-Erling Smørgrav	else
74817b5038d7SDag-Erling Smørgrav	  # Only an error if not doing a dry-run.
74827b5038d7SDag-Erling Smørgrav	  if $opt_dry_run; then
74837b5038d7SDag-Erling Smørgrav	    # Extract subdirectory from the argument.
74847b5038d7SDag-Erling Smørgrav	    func_dirname "$arg" "/" ""
7485986ba33cSDag-Erling Smørgrav	    xdir=$func_dirname_result
74867b5038d7SDag-Erling Smørgrav
74877b5038d7SDag-Erling Smørgrav	    func_lo2o "$arg"
74887b5038d7SDag-Erling Smørgrav	    pic_object=$xdir$objdir/$func_lo2o_result
74897b5038d7SDag-Erling Smørgrav	    non_pic_object=$xdir$func_lo2o_result
74907b5038d7SDag-Erling Smørgrav	    func_append libobjs " $pic_object"
74917b5038d7SDag-Erling Smørgrav	    func_append non_pic_objects " $non_pic_object"
74927b5038d7SDag-Erling Smørgrav	  else
7493986ba33cSDag-Erling Smørgrav	    func_fatal_error "'$arg' is not a valid libtool object"
74947b5038d7SDag-Erling Smørgrav	  fi
74957b5038d7SDag-Erling Smørgrav	fi
74967b5038d7SDag-Erling Smørgrav	;;
74977b5038d7SDag-Erling Smørgrav
74987b5038d7SDag-Erling Smørgrav      *.$libext)
74997b5038d7SDag-Erling Smørgrav	# An archive.
75007b5038d7SDag-Erling Smørgrav	func_append deplibs " $arg"
75017b5038d7SDag-Erling Smørgrav	func_append old_deplibs " $arg"
75027b5038d7SDag-Erling Smørgrav	continue
75037b5038d7SDag-Erling Smørgrav	;;
75047b5038d7SDag-Erling Smørgrav
75057b5038d7SDag-Erling Smørgrav      *.la)
75067b5038d7SDag-Erling Smørgrav	# A libtool-controlled library.
75077b5038d7SDag-Erling Smørgrav
75087b5038d7SDag-Erling Smørgrav	func_resolve_sysroot "$arg"
7509986ba33cSDag-Erling Smørgrav	if test dlfiles = "$prev"; then
75107b5038d7SDag-Erling Smørgrav	  # This library was specified with -dlopen.
75117b5038d7SDag-Erling Smørgrav	  func_append dlfiles " $func_resolve_sysroot_result"
75127b5038d7SDag-Erling Smørgrav	  prev=
7513986ba33cSDag-Erling Smørgrav	elif test dlprefiles = "$prev"; then
75147b5038d7SDag-Erling Smørgrav	  # The library was specified with -dlpreopen.
75157b5038d7SDag-Erling Smørgrav	  func_append dlprefiles " $func_resolve_sysroot_result"
75167b5038d7SDag-Erling Smørgrav	  prev=
75177b5038d7SDag-Erling Smørgrav	else
75187b5038d7SDag-Erling Smørgrav	  func_append deplibs " $func_resolve_sysroot_result"
75197b5038d7SDag-Erling Smørgrav	fi
75207b5038d7SDag-Erling Smørgrav	continue
75217b5038d7SDag-Erling Smørgrav	;;
75227b5038d7SDag-Erling Smørgrav
75237b5038d7SDag-Erling Smørgrav      # Some other compiler argument.
75247b5038d7SDag-Erling Smørgrav      *)
75257b5038d7SDag-Erling Smørgrav	# Unknown arguments in both finalize_command and compile_command need
75267b5038d7SDag-Erling Smørgrav	# to be aesthetically quoted because they are evaled later.
75277b5038d7SDag-Erling Smørgrav	func_quote_for_eval "$arg"
7528986ba33cSDag-Erling Smørgrav	arg=$func_quote_for_eval_result
75297b5038d7SDag-Erling Smørgrav	;;
75307b5038d7SDag-Erling Smørgrav      esac # arg
75317b5038d7SDag-Erling Smørgrav
75327b5038d7SDag-Erling Smørgrav      # Now actually substitute the argument into the commands.
75337b5038d7SDag-Erling Smørgrav      if test -n "$arg"; then
75347b5038d7SDag-Erling Smørgrav	func_append compile_command " $arg"
75357b5038d7SDag-Erling Smørgrav	func_append finalize_command " $arg"
75367b5038d7SDag-Erling Smørgrav      fi
75377b5038d7SDag-Erling Smørgrav    done # argument parsing loop
75387b5038d7SDag-Erling Smørgrav
75397b5038d7SDag-Erling Smørgrav    test -n "$prev" && \
7540986ba33cSDag-Erling Smørgrav      func_fatal_help "the '$prevarg' option requires an argument"
75417b5038d7SDag-Erling Smørgrav
7542986ba33cSDag-Erling Smørgrav    if test yes = "$export_dynamic" && test -n "$export_dynamic_flag_spec"; then
75437b5038d7SDag-Erling Smørgrav      eval arg=\"$export_dynamic_flag_spec\"
75447b5038d7SDag-Erling Smørgrav      func_append compile_command " $arg"
75457b5038d7SDag-Erling Smørgrav      func_append finalize_command " $arg"
75467b5038d7SDag-Erling Smørgrav    fi
75477b5038d7SDag-Erling Smørgrav
75487b5038d7SDag-Erling Smørgrav    oldlibs=
75497b5038d7SDag-Erling Smørgrav    # calculate the name of the file, without its directory
75507b5038d7SDag-Erling Smørgrav    func_basename "$output"
7551986ba33cSDag-Erling Smørgrav    outputname=$func_basename_result
7552986ba33cSDag-Erling Smørgrav    libobjs_save=$libobjs
75537b5038d7SDag-Erling Smørgrav
75547b5038d7SDag-Erling Smørgrav    if test -n "$shlibpath_var"; then
75557b5038d7SDag-Erling Smørgrav      # get the directories listed in $shlibpath_var
7556986ba33cSDag-Erling Smørgrav      eval shlib_search_path=\`\$ECHO \"\$$shlibpath_var\" \| \$SED \'s/:/ /g\'\`
75577b5038d7SDag-Erling Smørgrav    else
75587b5038d7SDag-Erling Smørgrav      shlib_search_path=
75597b5038d7SDag-Erling Smørgrav    fi
75607b5038d7SDag-Erling Smørgrav    eval sys_lib_search_path=\"$sys_lib_search_path_spec\"
75617b5038d7SDag-Erling Smørgrav    eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\"
75627b5038d7SDag-Erling Smørgrav
7563986ba33cSDag-Erling Smørgrav    # Definition is injected by LT_CONFIG during libtool generation.
7564986ba33cSDag-Erling Smørgrav    func_munge_path_list sys_lib_dlsearch_path "$LT_SYS_LIBRARY_PATH"
7565986ba33cSDag-Erling Smørgrav
75667b5038d7SDag-Erling Smørgrav    func_dirname "$output" "/" ""
7567986ba33cSDag-Erling Smørgrav    output_objdir=$func_dirname_result$objdir
75687b5038d7SDag-Erling Smørgrav    func_to_tool_file "$output_objdir/"
75697b5038d7SDag-Erling Smørgrav    tool_output_objdir=$func_to_tool_file_result
75707b5038d7SDag-Erling Smørgrav    # Create the object directory.
75717b5038d7SDag-Erling Smørgrav    func_mkdir_p "$output_objdir"
75727b5038d7SDag-Erling Smørgrav
75737b5038d7SDag-Erling Smørgrav    # Determine the type of output
75747b5038d7SDag-Erling Smørgrav    case $output in
75757b5038d7SDag-Erling Smørgrav    "")
75767b5038d7SDag-Erling Smørgrav      func_fatal_help "you must specify an output file"
75777b5038d7SDag-Erling Smørgrav      ;;
75787b5038d7SDag-Erling Smørgrav    *.$libext) linkmode=oldlib ;;
75797b5038d7SDag-Erling Smørgrav    *.lo | *.$objext) linkmode=obj ;;
75807b5038d7SDag-Erling Smørgrav    *.la) linkmode=lib ;;
75817b5038d7SDag-Erling Smørgrav    *) linkmode=prog ;; # Anything else should be a program.
75827b5038d7SDag-Erling Smørgrav    esac
75837b5038d7SDag-Erling Smørgrav
75847b5038d7SDag-Erling Smørgrav    specialdeplibs=
75857b5038d7SDag-Erling Smørgrav
75867b5038d7SDag-Erling Smørgrav    libs=
75877b5038d7SDag-Erling Smørgrav    # Find all interdependent deplibs by searching for libraries
75887b5038d7SDag-Erling Smørgrav    # that are linked more than once (e.g. -la -lb -la)
75897b5038d7SDag-Erling Smørgrav    for deplib in $deplibs; do
75907b5038d7SDag-Erling Smørgrav      if $opt_preserve_dup_deps; then
75917b5038d7SDag-Erling Smørgrav	case "$libs " in
75927b5038d7SDag-Erling Smørgrav	*" $deplib "*) func_append specialdeplibs " $deplib" ;;
75937b5038d7SDag-Erling Smørgrav	esac
75947b5038d7SDag-Erling Smørgrav      fi
75957b5038d7SDag-Erling Smørgrav      func_append libs " $deplib"
75967b5038d7SDag-Erling Smørgrav    done
75977b5038d7SDag-Erling Smørgrav
7598986ba33cSDag-Erling Smørgrav    if test lib = "$linkmode"; then
75997b5038d7SDag-Erling Smørgrav      libs="$predeps $libs $compiler_lib_search_path $postdeps"
76007b5038d7SDag-Erling Smørgrav
76017b5038d7SDag-Erling Smørgrav      # Compute libraries that are listed more than once in $predeps
76027b5038d7SDag-Erling Smørgrav      # $postdeps and mark them as special (i.e., whose duplicates are
76037b5038d7SDag-Erling Smørgrav      # not to be eliminated).
76047b5038d7SDag-Erling Smørgrav      pre_post_deps=
76057b5038d7SDag-Erling Smørgrav      if $opt_duplicate_compiler_generated_deps; then
76067b5038d7SDag-Erling Smørgrav	for pre_post_dep in $predeps $postdeps; do
76077b5038d7SDag-Erling Smørgrav	  case "$pre_post_deps " in
76087b5038d7SDag-Erling Smørgrav	  *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;;
76097b5038d7SDag-Erling Smørgrav	  esac
76107b5038d7SDag-Erling Smørgrav	  func_append pre_post_deps " $pre_post_dep"
76117b5038d7SDag-Erling Smørgrav	done
76127b5038d7SDag-Erling Smørgrav      fi
76137b5038d7SDag-Erling Smørgrav      pre_post_deps=
76147b5038d7SDag-Erling Smørgrav    fi
76157b5038d7SDag-Erling Smørgrav
76167b5038d7SDag-Erling Smørgrav    deplibs=
76177b5038d7SDag-Erling Smørgrav    newdependency_libs=
76187b5038d7SDag-Erling Smørgrav    newlib_search_path=
76197b5038d7SDag-Erling Smørgrav    need_relink=no # whether we're linking any uninstalled libtool libraries
76207b5038d7SDag-Erling Smørgrav    notinst_deplibs= # not-installed libtool libraries
76217b5038d7SDag-Erling Smørgrav    notinst_path= # paths that contain not-installed libtool libraries
76227b5038d7SDag-Erling Smørgrav
76237b5038d7SDag-Erling Smørgrav    case $linkmode in
76247b5038d7SDag-Erling Smørgrav    lib)
76257b5038d7SDag-Erling Smørgrav	passes="conv dlpreopen link"
76267b5038d7SDag-Erling Smørgrav	for file in $dlfiles $dlprefiles; do
76277b5038d7SDag-Erling Smørgrav	  case $file in
76287b5038d7SDag-Erling Smørgrav	  *.la) ;;
76297b5038d7SDag-Erling Smørgrav	  *)
7630986ba33cSDag-Erling Smørgrav	    func_fatal_help "libraries can '-dlopen' only libtool libraries: $file"
76317b5038d7SDag-Erling Smørgrav	    ;;
76327b5038d7SDag-Erling Smørgrav	  esac
76337b5038d7SDag-Erling Smørgrav	done
76347b5038d7SDag-Erling Smørgrav	;;
76357b5038d7SDag-Erling Smørgrav    prog)
76367b5038d7SDag-Erling Smørgrav	compile_deplibs=
76377b5038d7SDag-Erling Smørgrav	finalize_deplibs=
7638986ba33cSDag-Erling Smørgrav	alldeplibs=false
76397b5038d7SDag-Erling Smørgrav	newdlfiles=
76407b5038d7SDag-Erling Smørgrav	newdlprefiles=
76417b5038d7SDag-Erling Smørgrav	passes="conv scan dlopen dlpreopen link"
76427b5038d7SDag-Erling Smørgrav	;;
76437b5038d7SDag-Erling Smørgrav    *)  passes="conv"
76447b5038d7SDag-Erling Smørgrav	;;
76457b5038d7SDag-Erling Smørgrav    esac
76467b5038d7SDag-Erling Smørgrav
76477b5038d7SDag-Erling Smørgrav    for pass in $passes; do
76487b5038d7SDag-Erling Smørgrav      # The preopen pass in lib mode reverses $deplibs; put it back here
76497b5038d7SDag-Erling Smørgrav      # so that -L comes before libs that need it for instance...
7650986ba33cSDag-Erling Smørgrav      if test lib,link = "$linkmode,$pass"; then
76517b5038d7SDag-Erling Smørgrav	## FIXME: Find the place where the list is rebuilt in the wrong
76527b5038d7SDag-Erling Smørgrav	##        order, and fix it there properly
76537b5038d7SDag-Erling Smørgrav        tmp_deplibs=
76547b5038d7SDag-Erling Smørgrav	for deplib in $deplibs; do
76557b5038d7SDag-Erling Smørgrav	  tmp_deplibs="$deplib $tmp_deplibs"
76567b5038d7SDag-Erling Smørgrav	done
7657986ba33cSDag-Erling Smørgrav	deplibs=$tmp_deplibs
76587b5038d7SDag-Erling Smørgrav      fi
76597b5038d7SDag-Erling Smørgrav
7660986ba33cSDag-Erling Smørgrav      if test lib,link = "$linkmode,$pass" ||
7661986ba33cSDag-Erling Smørgrav	 test prog,scan = "$linkmode,$pass"; then
7662986ba33cSDag-Erling Smørgrav	libs=$deplibs
76637b5038d7SDag-Erling Smørgrav	deplibs=
76647b5038d7SDag-Erling Smørgrav      fi
7665986ba33cSDag-Erling Smørgrav      if test prog = "$linkmode"; then
76667b5038d7SDag-Erling Smørgrav	case $pass in
7667986ba33cSDag-Erling Smørgrav	dlopen) libs=$dlfiles ;;
7668986ba33cSDag-Erling Smørgrav	dlpreopen) libs=$dlprefiles ;;
76697b5038d7SDag-Erling Smørgrav	link)
76707b5038d7SDag-Erling Smørgrav	  libs="$deplibs %DEPLIBS%"
76717b5038d7SDag-Erling Smørgrav	  test "X$link_all_deplibs" != Xno && libs="$libs $dependency_libs"
76727b5038d7SDag-Erling Smørgrav	  ;;
76737b5038d7SDag-Erling Smørgrav	esac
76747b5038d7SDag-Erling Smørgrav      fi
7675986ba33cSDag-Erling Smørgrav      if test lib,dlpreopen = "$linkmode,$pass"; then
76767b5038d7SDag-Erling Smørgrav	# Collect and forward deplibs of preopened libtool libs
76777b5038d7SDag-Erling Smørgrav	for lib in $dlprefiles; do
76787b5038d7SDag-Erling Smørgrav	  # Ignore non-libtool-libs
76797b5038d7SDag-Erling Smørgrav	  dependency_libs=
76807b5038d7SDag-Erling Smørgrav	  func_resolve_sysroot "$lib"
76817b5038d7SDag-Erling Smørgrav	  case $lib in
76827b5038d7SDag-Erling Smørgrav	  *.la)	func_source "$func_resolve_sysroot_result" ;;
76837b5038d7SDag-Erling Smørgrav	  esac
76847b5038d7SDag-Erling Smørgrav
76857b5038d7SDag-Erling Smørgrav	  # Collect preopened libtool deplibs, except any this library
76867b5038d7SDag-Erling Smørgrav	  # has declared as weak libs
76877b5038d7SDag-Erling Smørgrav	  for deplib in $dependency_libs; do
76887b5038d7SDag-Erling Smørgrav	    func_basename "$deplib"
76897b5038d7SDag-Erling Smørgrav            deplib_base=$func_basename_result
76907b5038d7SDag-Erling Smørgrav	    case " $weak_libs " in
76917b5038d7SDag-Erling Smørgrav	    *" $deplib_base "*) ;;
76927b5038d7SDag-Erling Smørgrav	    *) func_append deplibs " $deplib" ;;
76937b5038d7SDag-Erling Smørgrav	    esac
76947b5038d7SDag-Erling Smørgrav	  done
76957b5038d7SDag-Erling Smørgrav	done
7696986ba33cSDag-Erling Smørgrav	libs=$dlprefiles
76977b5038d7SDag-Erling Smørgrav      fi
7698986ba33cSDag-Erling Smørgrav      if test dlopen = "$pass"; then
76997b5038d7SDag-Erling Smørgrav	# Collect dlpreopened libraries
7700986ba33cSDag-Erling Smørgrav	save_deplibs=$deplibs
77017b5038d7SDag-Erling Smørgrav	deplibs=
77027b5038d7SDag-Erling Smørgrav      fi
77037b5038d7SDag-Erling Smørgrav
77047b5038d7SDag-Erling Smørgrav      for deplib in $libs; do
77057b5038d7SDag-Erling Smørgrav	lib=
7706986ba33cSDag-Erling Smørgrav	found=false
77077b5038d7SDag-Erling Smørgrav	case $deplib in
77087b5038d7SDag-Erling Smørgrav	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \
77097b5038d7SDag-Erling Smørgrav        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)
7710986ba33cSDag-Erling Smørgrav	  if test prog,link = "$linkmode,$pass"; then
77117b5038d7SDag-Erling Smørgrav	    compile_deplibs="$deplib $compile_deplibs"
77127b5038d7SDag-Erling Smørgrav	    finalize_deplibs="$deplib $finalize_deplibs"
77137b5038d7SDag-Erling Smørgrav	  else
77147b5038d7SDag-Erling Smørgrav	    func_append compiler_flags " $deplib"
7715986ba33cSDag-Erling Smørgrav	    if test lib = "$linkmode"; then
77167b5038d7SDag-Erling Smørgrav		case "$new_inherited_linker_flags " in
77177b5038d7SDag-Erling Smørgrav		    *" $deplib "*) ;;
77187b5038d7SDag-Erling Smørgrav		    * ) func_append new_inherited_linker_flags " $deplib" ;;
77197b5038d7SDag-Erling Smørgrav		esac
77207b5038d7SDag-Erling Smørgrav	    fi
77217b5038d7SDag-Erling Smørgrav	  fi
77227b5038d7SDag-Erling Smørgrav	  continue
77237b5038d7SDag-Erling Smørgrav	  ;;
77247b5038d7SDag-Erling Smørgrav	-l*)
7725986ba33cSDag-Erling Smørgrav	  if test lib != "$linkmode" && test prog != "$linkmode"; then
7726986ba33cSDag-Erling Smørgrav	    func_warning "'-l' is ignored for archives/objects"
77277b5038d7SDag-Erling Smørgrav	    continue
77287b5038d7SDag-Erling Smørgrav	  fi
77297b5038d7SDag-Erling Smørgrav	  func_stripname '-l' '' "$deplib"
77307b5038d7SDag-Erling Smørgrav	  name=$func_stripname_result
7731986ba33cSDag-Erling Smørgrav	  if test lib = "$linkmode"; then
77327b5038d7SDag-Erling Smørgrav	    searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path"
77337b5038d7SDag-Erling Smørgrav	  else
77347b5038d7SDag-Erling Smørgrav	    searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path"
77357b5038d7SDag-Erling Smørgrav	  fi
77367b5038d7SDag-Erling Smørgrav	  for searchdir in $searchdirs; do
77377b5038d7SDag-Erling Smørgrav	    for search_ext in .la $std_shrext .so .a; do
77387b5038d7SDag-Erling Smørgrav	      # Search the libtool library
7739986ba33cSDag-Erling Smørgrav	      lib=$searchdir/lib$name$search_ext
77407b5038d7SDag-Erling Smørgrav	      if test -f "$lib"; then
7741986ba33cSDag-Erling Smørgrav		if test .la = "$search_ext"; then
7742986ba33cSDag-Erling Smørgrav		  found=:
77437b5038d7SDag-Erling Smørgrav		else
7744986ba33cSDag-Erling Smørgrav		  found=false
77457b5038d7SDag-Erling Smørgrav		fi
77467b5038d7SDag-Erling Smørgrav		break 2
77477b5038d7SDag-Erling Smørgrav	      fi
77487b5038d7SDag-Erling Smørgrav	    done
77497b5038d7SDag-Erling Smørgrav	  done
7750986ba33cSDag-Erling Smørgrav	  if $found; then
7751986ba33cSDag-Erling Smørgrav	    # deplib is a libtool library
77527b5038d7SDag-Erling Smørgrav	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
77537b5038d7SDag-Erling Smørgrav	    # We need to do some special things here, and not later.
7754986ba33cSDag-Erling Smørgrav	    if test yes = "$allow_libtool_libs_with_static_runtimes"; then
77557b5038d7SDag-Erling Smørgrav	      case " $predeps $postdeps " in
77567b5038d7SDag-Erling Smørgrav	      *" $deplib "*)
77577b5038d7SDag-Erling Smørgrav		if func_lalib_p "$lib"; then
77587b5038d7SDag-Erling Smørgrav		  library_names=
77597b5038d7SDag-Erling Smørgrav		  old_library=
77607b5038d7SDag-Erling Smørgrav		  func_source "$lib"
77617b5038d7SDag-Erling Smørgrav		  for l in $old_library $library_names; do
7762986ba33cSDag-Erling Smørgrav		    ll=$l
77637b5038d7SDag-Erling Smørgrav		  done
77647b5038d7SDag-Erling Smørgrav		  if test "X$ll" = "X$old_library"; then # only static version available
7765986ba33cSDag-Erling Smørgrav		    found=false
77667b5038d7SDag-Erling Smørgrav		    func_dirname "$lib" "" "."
7767986ba33cSDag-Erling Smørgrav		    ladir=$func_dirname_result
77687b5038d7SDag-Erling Smørgrav		    lib=$ladir/$old_library
7769986ba33cSDag-Erling Smørgrav		    if test prog,link = "$linkmode,$pass"; then
77707b5038d7SDag-Erling Smørgrav		      compile_deplibs="$deplib $compile_deplibs"
77717b5038d7SDag-Erling Smørgrav		      finalize_deplibs="$deplib $finalize_deplibs"
77727b5038d7SDag-Erling Smørgrav		    else
77737b5038d7SDag-Erling Smørgrav		      deplibs="$deplib $deplibs"
7774986ba33cSDag-Erling Smørgrav		      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
77757b5038d7SDag-Erling Smørgrav		    fi
77767b5038d7SDag-Erling Smørgrav		    continue
77777b5038d7SDag-Erling Smørgrav		  fi
77787b5038d7SDag-Erling Smørgrav		fi
77797b5038d7SDag-Erling Smørgrav		;;
77807b5038d7SDag-Erling Smørgrav	      *) ;;
77817b5038d7SDag-Erling Smørgrav	      esac
77827b5038d7SDag-Erling Smørgrav	    fi
7783986ba33cSDag-Erling Smørgrav	  else
7784986ba33cSDag-Erling Smørgrav	    # deplib doesn't seem to be a libtool library
7785986ba33cSDag-Erling Smørgrav	    if test prog,link = "$linkmode,$pass"; then
77867b5038d7SDag-Erling Smørgrav	      compile_deplibs="$deplib $compile_deplibs"
77877b5038d7SDag-Erling Smørgrav	      finalize_deplibs="$deplib $finalize_deplibs"
77887b5038d7SDag-Erling Smørgrav	    else
77897b5038d7SDag-Erling Smørgrav	      deplibs="$deplib $deplibs"
7790986ba33cSDag-Erling Smørgrav	      test lib = "$linkmode" && newdependency_libs="$deplib $newdependency_libs"
7791986ba33cSDag-Erling Smørgrav	    fi
7792986ba33cSDag-Erling Smørgrav	    continue
7793986ba33cSDag-Erling Smørgrav	  fi
7794986ba33cSDag-Erling Smørgrav	  ;; # -l
7795986ba33cSDag-Erling Smørgrav	*.ltframework)
7796986ba33cSDag-Erling Smørgrav	  if test prog,link = "$linkmode,$pass"; then
7797986ba33cSDag-Erling Smørgrav	    compile_deplibs="$deplib $compile_deplibs"
7798986ba33cSDag-Erling Smørgrav	    finalize_deplibs="$deplib $finalize_deplibs"
7799986ba33cSDag-Erling Smørgrav	  else
7800986ba33cSDag-Erling Smørgrav	    deplibs="$deplib $deplibs"
7801986ba33cSDag-Erling Smørgrav	    if test lib = "$linkmode"; then
78027b5038d7SDag-Erling Smørgrav		case "$new_inherited_linker_flags " in
78037b5038d7SDag-Erling Smørgrav		    *" $deplib "*) ;;
78047b5038d7SDag-Erling Smørgrav		    * ) func_append new_inherited_linker_flags " $deplib" ;;
78057b5038d7SDag-Erling Smørgrav		esac
78067b5038d7SDag-Erling Smørgrav	    fi
78077b5038d7SDag-Erling Smørgrav	  fi
78087b5038d7SDag-Erling Smørgrav	  continue
78097b5038d7SDag-Erling Smørgrav	  ;;
78107b5038d7SDag-Erling Smørgrav	-L*)
78117b5038d7SDag-Erling Smørgrav	  case $linkmode in
78127b5038d7SDag-Erling Smørgrav	  lib)
78137b5038d7SDag-Erling Smørgrav	    deplibs="$deplib $deplibs"
7814986ba33cSDag-Erling Smørgrav	    test conv = "$pass" && continue
78157b5038d7SDag-Erling Smørgrav	    newdependency_libs="$deplib $newdependency_libs"
78167b5038d7SDag-Erling Smørgrav	    func_stripname '-L' '' "$deplib"
78177b5038d7SDag-Erling Smørgrav	    func_resolve_sysroot "$func_stripname_result"
78187b5038d7SDag-Erling Smørgrav	    func_append newlib_search_path " $func_resolve_sysroot_result"
78197b5038d7SDag-Erling Smørgrav	    ;;
78207b5038d7SDag-Erling Smørgrav	  prog)
7821986ba33cSDag-Erling Smørgrav	    if test conv = "$pass"; then
78227b5038d7SDag-Erling Smørgrav	      deplibs="$deplib $deplibs"
78237b5038d7SDag-Erling Smørgrav	      continue
78247b5038d7SDag-Erling Smørgrav	    fi
7825986ba33cSDag-Erling Smørgrav	    if test scan = "$pass"; then
78267b5038d7SDag-Erling Smørgrav	      deplibs="$deplib $deplibs"
78277b5038d7SDag-Erling Smørgrav	    else
78287b5038d7SDag-Erling Smørgrav	      compile_deplibs="$deplib $compile_deplibs"
78297b5038d7SDag-Erling Smørgrav	      finalize_deplibs="$deplib $finalize_deplibs"
78307b5038d7SDag-Erling Smørgrav	    fi
78317b5038d7SDag-Erling Smørgrav	    func_stripname '-L' '' "$deplib"
78327b5038d7SDag-Erling Smørgrav	    func_resolve_sysroot "$func_stripname_result"
78337b5038d7SDag-Erling Smørgrav	    func_append newlib_search_path " $func_resolve_sysroot_result"
78347b5038d7SDag-Erling Smørgrav	    ;;
78357b5038d7SDag-Erling Smørgrav	  *)
7836986ba33cSDag-Erling Smørgrav	    func_warning "'-L' is ignored for archives/objects"
78377b5038d7SDag-Erling Smørgrav	    ;;
78387b5038d7SDag-Erling Smørgrav	  esac # linkmode
78397b5038d7SDag-Erling Smørgrav	  continue
78407b5038d7SDag-Erling Smørgrav	  ;; # -L
78417b5038d7SDag-Erling Smørgrav	-R*)
7842986ba33cSDag-Erling Smørgrav	  if test link = "$pass"; then
78437b5038d7SDag-Erling Smørgrav	    func_stripname '-R' '' "$deplib"
78447b5038d7SDag-Erling Smørgrav	    func_resolve_sysroot "$func_stripname_result"
78457b5038d7SDag-Erling Smørgrav	    dir=$func_resolve_sysroot_result
78467b5038d7SDag-Erling Smørgrav	    # Make sure the xrpath contains only unique directories.
78477b5038d7SDag-Erling Smørgrav	    case "$xrpath " in
78487b5038d7SDag-Erling Smørgrav	    *" $dir "*) ;;
78497b5038d7SDag-Erling Smørgrav	    *) func_append xrpath " $dir" ;;
78507b5038d7SDag-Erling Smørgrav	    esac
78517b5038d7SDag-Erling Smørgrav	  fi
78527b5038d7SDag-Erling Smørgrav	  deplibs="$deplib $deplibs"
78537b5038d7SDag-Erling Smørgrav	  continue
78547b5038d7SDag-Erling Smørgrav	  ;;
78557b5038d7SDag-Erling Smørgrav	*.la)
78567b5038d7SDag-Erling Smørgrav	  func_resolve_sysroot "$deplib"
78577b5038d7SDag-Erling Smørgrav	  lib=$func_resolve_sysroot_result
78587b5038d7SDag-Erling Smørgrav	  ;;
78597b5038d7SDag-Erling Smørgrav	*.$libext)
7860986ba33cSDag-Erling Smørgrav	  if test conv = "$pass"; then
78617b5038d7SDag-Erling Smørgrav	    deplibs="$deplib $deplibs"
78627b5038d7SDag-Erling Smørgrav	    continue
78637b5038d7SDag-Erling Smørgrav	  fi
78647b5038d7SDag-Erling Smørgrav	  case $linkmode in
78657b5038d7SDag-Erling Smørgrav	  lib)
78667b5038d7SDag-Erling Smørgrav	    # Linking convenience modules into shared libraries is allowed,
78677b5038d7SDag-Erling Smørgrav	    # but linking other static libraries is non-portable.
78687b5038d7SDag-Erling Smørgrav	    case " $dlpreconveniencelibs " in
78697b5038d7SDag-Erling Smørgrav	    *" $deplib "*) ;;
78707b5038d7SDag-Erling Smørgrav	    *)
7871986ba33cSDag-Erling Smørgrav	      valid_a_lib=false
78727b5038d7SDag-Erling Smørgrav	      case $deplibs_check_method in
78737b5038d7SDag-Erling Smørgrav		match_pattern*)
78747b5038d7SDag-Erling Smørgrav		  set dummy $deplibs_check_method; shift
78757b5038d7SDag-Erling Smørgrav		  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
78767b5038d7SDag-Erling Smørgrav		  if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \
78777b5038d7SDag-Erling Smørgrav		    | $EGREP "$match_pattern_regex" > /dev/null; then
7878986ba33cSDag-Erling Smørgrav		    valid_a_lib=:
78797b5038d7SDag-Erling Smørgrav		  fi
78807b5038d7SDag-Erling Smørgrav		;;
78817b5038d7SDag-Erling Smørgrav		pass_all)
7882986ba33cSDag-Erling Smørgrav		  valid_a_lib=:
78837b5038d7SDag-Erling Smørgrav		;;
78847b5038d7SDag-Erling Smørgrav	      esac
7885986ba33cSDag-Erling Smørgrav	      if $valid_a_lib; then
7886986ba33cSDag-Erling Smørgrav		echo
7887986ba33cSDag-Erling Smørgrav		$ECHO "*** Warning: Linking the shared library $output against the"
7888986ba33cSDag-Erling Smørgrav		$ECHO "*** static library $deplib is not portable!"
7889986ba33cSDag-Erling Smørgrav		deplibs="$deplib $deplibs"
7890986ba33cSDag-Erling Smørgrav	      else
78917b5038d7SDag-Erling Smørgrav		echo
78927b5038d7SDag-Erling Smørgrav		$ECHO "*** Warning: Trying to link with static lib archive $deplib."
78937b5038d7SDag-Erling Smørgrav		echo "*** I have the capability to make that library automatically link in when"
78947b5038d7SDag-Erling Smørgrav		echo "*** you link to this library.  But I can only do this if you have a"
78957b5038d7SDag-Erling Smørgrav		echo "*** shared version of the library, which you do not appear to have"
78967b5038d7SDag-Erling Smørgrav		echo "*** because the file extensions .$libext of this argument makes me believe"
78977b5038d7SDag-Erling Smørgrav		echo "*** that it is just a static archive that I should not use here."
78987b5038d7SDag-Erling Smørgrav	      fi
78997b5038d7SDag-Erling Smørgrav	      ;;
79007b5038d7SDag-Erling Smørgrav	    esac
79017b5038d7SDag-Erling Smørgrav	    continue
79027b5038d7SDag-Erling Smørgrav	    ;;
79037b5038d7SDag-Erling Smørgrav	  prog)
7904986ba33cSDag-Erling Smørgrav	    if test link != "$pass"; then
79057b5038d7SDag-Erling Smørgrav	      deplibs="$deplib $deplibs"
79067b5038d7SDag-Erling Smørgrav	    else
79077b5038d7SDag-Erling Smørgrav	      compile_deplibs="$deplib $compile_deplibs"
79087b5038d7SDag-Erling Smørgrav	      finalize_deplibs="$deplib $finalize_deplibs"
79097b5038d7SDag-Erling Smørgrav	    fi
79107b5038d7SDag-Erling Smørgrav	    continue
79117b5038d7SDag-Erling Smørgrav	    ;;
79127b5038d7SDag-Erling Smørgrav	  esac # linkmode
79137b5038d7SDag-Erling Smørgrav	  ;; # *.$libext
79147b5038d7SDag-Erling Smørgrav	*.lo | *.$objext)
7915986ba33cSDag-Erling Smørgrav	  if test conv = "$pass"; then
79167b5038d7SDag-Erling Smørgrav	    deplibs="$deplib $deplibs"
7917986ba33cSDag-Erling Smørgrav	  elif test prog = "$linkmode"; then
7918986ba33cSDag-Erling Smørgrav	    if test dlpreopen = "$pass" || test yes != "$dlopen_support" || test no = "$build_libtool_libs"; then
79197b5038d7SDag-Erling Smørgrav	      # If there is no dlopen support or we're linking statically,
79207b5038d7SDag-Erling Smørgrav	      # we need to preload.
79217b5038d7SDag-Erling Smørgrav	      func_append newdlprefiles " $deplib"
79227b5038d7SDag-Erling Smørgrav	      compile_deplibs="$deplib $compile_deplibs"
79237b5038d7SDag-Erling Smørgrav	      finalize_deplibs="$deplib $finalize_deplibs"
79247b5038d7SDag-Erling Smørgrav	    else
79257b5038d7SDag-Erling Smørgrav	      func_append newdlfiles " $deplib"
79267b5038d7SDag-Erling Smørgrav	    fi
79277b5038d7SDag-Erling Smørgrav	  fi
79287b5038d7SDag-Erling Smørgrav	  continue
79297b5038d7SDag-Erling Smørgrav	  ;;
79307b5038d7SDag-Erling Smørgrav	%DEPLIBS%)
7931986ba33cSDag-Erling Smørgrav	  alldeplibs=:
79327b5038d7SDag-Erling Smørgrav	  continue
79337b5038d7SDag-Erling Smørgrav	  ;;
79347b5038d7SDag-Erling Smørgrav	esac # case $deplib
79357b5038d7SDag-Erling Smørgrav
7936986ba33cSDag-Erling Smørgrav	$found || test -f "$lib" \
7937986ba33cSDag-Erling Smørgrav	  || func_fatal_error "cannot find the library '$lib' or unhandled argument '$deplib'"
79387b5038d7SDag-Erling Smørgrav
79397b5038d7SDag-Erling Smørgrav	# Check to see that this really is a libtool archive.
79407b5038d7SDag-Erling Smørgrav	func_lalib_unsafe_p "$lib" \
7941986ba33cSDag-Erling Smørgrav	  || func_fatal_error "'$lib' is not a valid libtool archive"
79427b5038d7SDag-Erling Smørgrav
79437b5038d7SDag-Erling Smørgrav	func_dirname "$lib" "" "."
7944986ba33cSDag-Erling Smørgrav	ladir=$func_dirname_result
79457b5038d7SDag-Erling Smørgrav
79467b5038d7SDag-Erling Smørgrav	dlname=
79477b5038d7SDag-Erling Smørgrav	dlopen=
79487b5038d7SDag-Erling Smørgrav	dlpreopen=
79497b5038d7SDag-Erling Smørgrav	libdir=
79507b5038d7SDag-Erling Smørgrav	library_names=
79517b5038d7SDag-Erling Smørgrav	old_library=
79527b5038d7SDag-Erling Smørgrav	inherited_linker_flags=
79537b5038d7SDag-Erling Smørgrav	# If the library was installed with an old release of libtool,
79547b5038d7SDag-Erling Smørgrav	# it will not redefine variables installed, or shouldnotlink
79557b5038d7SDag-Erling Smørgrav	installed=yes
79567b5038d7SDag-Erling Smørgrav	shouldnotlink=no
79577b5038d7SDag-Erling Smørgrav	avoidtemprpath=
79587b5038d7SDag-Erling Smørgrav
79597b5038d7SDag-Erling Smørgrav
79607b5038d7SDag-Erling Smørgrav	# Read the .la file
79617b5038d7SDag-Erling Smørgrav	func_source "$lib"
79627b5038d7SDag-Erling Smørgrav
79637b5038d7SDag-Erling Smørgrav	# Convert "-framework foo" to "foo.ltframework"
79647b5038d7SDag-Erling Smørgrav	if test -n "$inherited_linker_flags"; then
79657b5038d7SDag-Erling Smørgrav	  tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'`
79667b5038d7SDag-Erling Smørgrav	  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do
79677b5038d7SDag-Erling Smørgrav	    case " $new_inherited_linker_flags " in
79687b5038d7SDag-Erling Smørgrav	      *" $tmp_inherited_linker_flag "*) ;;
79697b5038d7SDag-Erling Smørgrav	      *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";;
79707b5038d7SDag-Erling Smørgrav	    esac
79717b5038d7SDag-Erling Smørgrav	  done
79727b5038d7SDag-Erling Smørgrav	fi
79737b5038d7SDag-Erling Smørgrav	dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
7974986ba33cSDag-Erling Smørgrav	if test lib,link = "$linkmode,$pass" ||
7975986ba33cSDag-Erling Smørgrav	   test prog,scan = "$linkmode,$pass" ||
7976986ba33cSDag-Erling Smørgrav	   { test prog != "$linkmode" && test lib != "$linkmode"; }; then
79777b5038d7SDag-Erling Smørgrav	  test -n "$dlopen" && func_append dlfiles " $dlopen"
79787b5038d7SDag-Erling Smørgrav	  test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen"
79797b5038d7SDag-Erling Smørgrav	fi
79807b5038d7SDag-Erling Smørgrav
7981986ba33cSDag-Erling Smørgrav	if test conv = "$pass"; then
79827b5038d7SDag-Erling Smørgrav	  # Only check for convenience libraries
79837b5038d7SDag-Erling Smørgrav	  deplibs="$lib $deplibs"
79847b5038d7SDag-Erling Smørgrav	  if test -z "$libdir"; then
79857b5038d7SDag-Erling Smørgrav	    if test -z "$old_library"; then
7986986ba33cSDag-Erling Smørgrav	      func_fatal_error "cannot find name of link library for '$lib'"
79877b5038d7SDag-Erling Smørgrav	    fi
79887b5038d7SDag-Erling Smørgrav	    # It is a libtool convenience library, so add in its objects.
79897b5038d7SDag-Erling Smørgrav	    func_append convenience " $ladir/$objdir/$old_library"
79907b5038d7SDag-Erling Smørgrav	    func_append old_convenience " $ladir/$objdir/$old_library"
79917b5038d7SDag-Erling Smørgrav	    tmp_libs=
79927b5038d7SDag-Erling Smørgrav	    for deplib in $dependency_libs; do
79937b5038d7SDag-Erling Smørgrav	      deplibs="$deplib $deplibs"
79947b5038d7SDag-Erling Smørgrav	      if $opt_preserve_dup_deps; then
79957b5038d7SDag-Erling Smørgrav		case "$tmp_libs " in
79967b5038d7SDag-Erling Smørgrav		*" $deplib "*) func_append specialdeplibs " $deplib" ;;
79977b5038d7SDag-Erling Smørgrav		esac
79987b5038d7SDag-Erling Smørgrav	      fi
79997b5038d7SDag-Erling Smørgrav	      func_append tmp_libs " $deplib"
80007b5038d7SDag-Erling Smørgrav	    done
8001986ba33cSDag-Erling Smørgrav	  elif test prog != "$linkmode" && test lib != "$linkmode"; then
8002986ba33cSDag-Erling Smørgrav	    func_fatal_error "'$lib' is not a convenience library"
80037b5038d7SDag-Erling Smørgrav	  fi
80047b5038d7SDag-Erling Smørgrav	  continue
80057b5038d7SDag-Erling Smørgrav	fi # $pass = conv
80067b5038d7SDag-Erling Smørgrav
80077b5038d7SDag-Erling Smørgrav
80087b5038d7SDag-Erling Smørgrav	# Get the name of the library we link against.
80097b5038d7SDag-Erling Smørgrav	linklib=
80107b5038d7SDag-Erling Smørgrav	if test -n "$old_library" &&
8011986ba33cSDag-Erling Smørgrav	   { test yes = "$prefer_static_libs" ||
8012986ba33cSDag-Erling Smørgrav	     test built,no = "$prefer_static_libs,$installed"; }; then
80137b5038d7SDag-Erling Smørgrav	  linklib=$old_library
80147b5038d7SDag-Erling Smørgrav	else
80157b5038d7SDag-Erling Smørgrav	  for l in $old_library $library_names; do
8016986ba33cSDag-Erling Smørgrav	    linklib=$l
80177b5038d7SDag-Erling Smørgrav	  done
80187b5038d7SDag-Erling Smørgrav	fi
80197b5038d7SDag-Erling Smørgrav	if test -z "$linklib"; then
8020986ba33cSDag-Erling Smørgrav	  func_fatal_error "cannot find name of link library for '$lib'"
80217b5038d7SDag-Erling Smørgrav	fi
80227b5038d7SDag-Erling Smørgrav
80237b5038d7SDag-Erling Smørgrav	# This library was specified with -dlopen.
8024986ba33cSDag-Erling Smørgrav	if test dlopen = "$pass"; then
8025986ba33cSDag-Erling Smørgrav	  test -z "$libdir" \
8026986ba33cSDag-Erling Smørgrav	    && func_fatal_error "cannot -dlopen a convenience library: '$lib'"
80277b5038d7SDag-Erling Smørgrav	  if test -z "$dlname" ||
8028986ba33cSDag-Erling Smørgrav	     test yes != "$dlopen_support" ||
8029986ba33cSDag-Erling Smørgrav	     test no = "$build_libtool_libs"
8030986ba33cSDag-Erling Smørgrav	  then
80317b5038d7SDag-Erling Smørgrav	    # If there is no dlname, no dlopen support or we're linking
80327b5038d7SDag-Erling Smørgrav	    # statically, we need to preload.  We also need to preload any
80337b5038d7SDag-Erling Smørgrav	    # dependent libraries so libltdl's deplib preloader doesn't
80347b5038d7SDag-Erling Smørgrav	    # bomb out in the load deplibs phase.
80357b5038d7SDag-Erling Smørgrav	    func_append dlprefiles " $lib $dependency_libs"
80367b5038d7SDag-Erling Smørgrav	  else
80377b5038d7SDag-Erling Smørgrav	    func_append newdlfiles " $lib"
80387b5038d7SDag-Erling Smørgrav	  fi
80397b5038d7SDag-Erling Smørgrav	  continue
80407b5038d7SDag-Erling Smørgrav	fi # $pass = dlopen
80417b5038d7SDag-Erling Smørgrav
80427b5038d7SDag-Erling Smørgrav	# We need an absolute path.
80437b5038d7SDag-Erling Smørgrav	case $ladir in
8044986ba33cSDag-Erling Smørgrav	[\\/]* | [A-Za-z]:[\\/]*) abs_ladir=$ladir ;;
80457b5038d7SDag-Erling Smørgrav	*)
80467b5038d7SDag-Erling Smørgrav	  abs_ladir=`cd "$ladir" && pwd`
80477b5038d7SDag-Erling Smørgrav	  if test -z "$abs_ladir"; then
8048986ba33cSDag-Erling Smørgrav	    func_warning "cannot determine absolute directory name of '$ladir'"
80497b5038d7SDag-Erling Smørgrav	    func_warning "passing it literally to the linker, although it might fail"
8050986ba33cSDag-Erling Smørgrav	    abs_ladir=$ladir
80517b5038d7SDag-Erling Smørgrav	  fi
80527b5038d7SDag-Erling Smørgrav	  ;;
80537b5038d7SDag-Erling Smørgrav	esac
80547b5038d7SDag-Erling Smørgrav	func_basename "$lib"
8055986ba33cSDag-Erling Smørgrav	laname=$func_basename_result
80567b5038d7SDag-Erling Smørgrav
80577b5038d7SDag-Erling Smørgrav	# Find the relevant object directory and library name.
8058986ba33cSDag-Erling Smørgrav	if test yes = "$installed"; then
80597b5038d7SDag-Erling Smørgrav	  if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8060986ba33cSDag-Erling Smørgrav	    func_warning "library '$lib' was moved."
8061986ba33cSDag-Erling Smørgrav	    dir=$ladir
8062986ba33cSDag-Erling Smørgrav	    absdir=$abs_ladir
8063986ba33cSDag-Erling Smørgrav	    libdir=$abs_ladir
80647b5038d7SDag-Erling Smørgrav	  else
8065986ba33cSDag-Erling Smørgrav	    dir=$lt_sysroot$libdir
8066986ba33cSDag-Erling Smørgrav	    absdir=$lt_sysroot$libdir
80677b5038d7SDag-Erling Smørgrav	  fi
8068986ba33cSDag-Erling Smørgrav	  test yes = "$hardcode_automatic" && avoidtemprpath=yes
80697b5038d7SDag-Erling Smørgrav	else
80707b5038d7SDag-Erling Smørgrav	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
8071986ba33cSDag-Erling Smørgrav	    dir=$ladir
8072986ba33cSDag-Erling Smørgrav	    absdir=$abs_ladir
80737b5038d7SDag-Erling Smørgrav	    # Remove this search path later
80747b5038d7SDag-Erling Smørgrav	    func_append notinst_path " $abs_ladir"
80757b5038d7SDag-Erling Smørgrav	  else
8076986ba33cSDag-Erling Smørgrav	    dir=$ladir/$objdir
8077986ba33cSDag-Erling Smørgrav	    absdir=$abs_ladir/$objdir
80787b5038d7SDag-Erling Smørgrav	    # Remove this search path later
80797b5038d7SDag-Erling Smørgrav	    func_append notinst_path " $abs_ladir"
80807b5038d7SDag-Erling Smørgrav	  fi
80817b5038d7SDag-Erling Smørgrav	fi # $installed = yes
80827b5038d7SDag-Erling Smørgrav	func_stripname 'lib' '.la' "$laname"
80837b5038d7SDag-Erling Smørgrav	name=$func_stripname_result
80847b5038d7SDag-Erling Smørgrav
80857b5038d7SDag-Erling Smørgrav	# This library was specified with -dlpreopen.
8086986ba33cSDag-Erling Smørgrav	if test dlpreopen = "$pass"; then
8087986ba33cSDag-Erling Smørgrav	  if test -z "$libdir" && test prog = "$linkmode"; then
8088986ba33cSDag-Erling Smørgrav	    func_fatal_error "only libraries may -dlpreopen a convenience library: '$lib'"
80897b5038d7SDag-Erling Smørgrav	  fi
8090986ba33cSDag-Erling Smørgrav	  case $host in
80917b5038d7SDag-Erling Smørgrav	    # special handling for platforms with PE-DLLs.
80927b5038d7SDag-Erling Smørgrav	    *cygwin* | *mingw* | *cegcc* )
80937b5038d7SDag-Erling Smørgrav	      # Linker will automatically link against shared library if both
80947b5038d7SDag-Erling Smørgrav	      # static and shared are present.  Therefore, ensure we extract
80957b5038d7SDag-Erling Smørgrav	      # symbols from the import library if a shared library is present
80967b5038d7SDag-Erling Smørgrav	      # (otherwise, the dlopen module name will be incorrect).  We do
80977b5038d7SDag-Erling Smørgrav	      # this by putting the import library name into $newdlprefiles.
80987b5038d7SDag-Erling Smørgrav	      # We recover the dlopen module name by 'saving' the la file
80997b5038d7SDag-Erling Smørgrav	      # name in a special purpose variable, and (later) extracting the
81007b5038d7SDag-Erling Smørgrav	      # dlname from the la file.
81017b5038d7SDag-Erling Smørgrav	      if test -n "$dlname"; then
81027b5038d7SDag-Erling Smørgrav	        func_tr_sh "$dir/$linklib"
81037b5038d7SDag-Erling Smørgrav	        eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname"
81047b5038d7SDag-Erling Smørgrav	        func_append newdlprefiles " $dir/$linklib"
81057b5038d7SDag-Erling Smørgrav	      else
81067b5038d7SDag-Erling Smørgrav	        func_append newdlprefiles " $dir/$old_library"
81077b5038d7SDag-Erling Smørgrav	        # Keep a list of preopened convenience libraries to check
81087b5038d7SDag-Erling Smørgrav	        # that they are being used correctly in the link pass.
81097b5038d7SDag-Erling Smørgrav	        test -z "$libdir" && \
81107b5038d7SDag-Erling Smørgrav	          func_append dlpreconveniencelibs " $dir/$old_library"
81117b5038d7SDag-Erling Smørgrav	      fi
81127b5038d7SDag-Erling Smørgrav	    ;;
81137b5038d7SDag-Erling Smørgrav	    * )
81147b5038d7SDag-Erling Smørgrav	      # Prefer using a static library (so that no silly _DYNAMIC symbols
81157b5038d7SDag-Erling Smørgrav	      # are required to link).
81167b5038d7SDag-Erling Smørgrav	      if test -n "$old_library"; then
81177b5038d7SDag-Erling Smørgrav	        func_append newdlprefiles " $dir/$old_library"
81187b5038d7SDag-Erling Smørgrav	        # Keep a list of preopened convenience libraries to check
81197b5038d7SDag-Erling Smørgrav	        # that they are being used correctly in the link pass.
81207b5038d7SDag-Erling Smørgrav	        test -z "$libdir" && \
81217b5038d7SDag-Erling Smørgrav	          func_append dlpreconveniencelibs " $dir/$old_library"
81227b5038d7SDag-Erling Smørgrav	      # Otherwise, use the dlname, so that lt_dlopen finds it.
81237b5038d7SDag-Erling Smørgrav	      elif test -n "$dlname"; then
81247b5038d7SDag-Erling Smørgrav	        func_append newdlprefiles " $dir/$dlname"
81257b5038d7SDag-Erling Smørgrav	      else
81267b5038d7SDag-Erling Smørgrav	        func_append newdlprefiles " $dir/$linklib"
81277b5038d7SDag-Erling Smørgrav	      fi
81287b5038d7SDag-Erling Smørgrav	    ;;
81297b5038d7SDag-Erling Smørgrav	  esac
81307b5038d7SDag-Erling Smørgrav	fi # $pass = dlpreopen
81317b5038d7SDag-Erling Smørgrav
81327b5038d7SDag-Erling Smørgrav	if test -z "$libdir"; then
81337b5038d7SDag-Erling Smørgrav	  # Link the convenience library
8134986ba33cSDag-Erling Smørgrav	  if test lib = "$linkmode"; then
81357b5038d7SDag-Erling Smørgrav	    deplibs="$dir/$old_library $deplibs"
8136986ba33cSDag-Erling Smørgrav	  elif test prog,link = "$linkmode,$pass"; then
81377b5038d7SDag-Erling Smørgrav	    compile_deplibs="$dir/$old_library $compile_deplibs"
81387b5038d7SDag-Erling Smørgrav	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
81397b5038d7SDag-Erling Smørgrav	  else
81407b5038d7SDag-Erling Smørgrav	    deplibs="$lib $deplibs" # used for prog,scan pass
81417b5038d7SDag-Erling Smørgrav	  fi
81427b5038d7SDag-Erling Smørgrav	  continue
81437b5038d7SDag-Erling Smørgrav	fi
81447b5038d7SDag-Erling Smørgrav
81457b5038d7SDag-Erling Smørgrav
8146986ba33cSDag-Erling Smørgrav	if test prog = "$linkmode" && test link != "$pass"; then
81477b5038d7SDag-Erling Smørgrav	  func_append newlib_search_path " $ladir"
81487b5038d7SDag-Erling Smørgrav	  deplibs="$lib $deplibs"
81497b5038d7SDag-Erling Smørgrav
8150986ba33cSDag-Erling Smørgrav	  linkalldeplibs=false
8151986ba33cSDag-Erling Smørgrav	  if test no != "$link_all_deplibs" || test -z "$library_names" ||
8152986ba33cSDag-Erling Smørgrav	     test no = "$build_libtool_libs"; then
8153986ba33cSDag-Erling Smørgrav	    linkalldeplibs=:
81547b5038d7SDag-Erling Smørgrav	  fi
81557b5038d7SDag-Erling Smørgrav
81567b5038d7SDag-Erling Smørgrav	  tmp_libs=
81577b5038d7SDag-Erling Smørgrav	  for deplib in $dependency_libs; do
81587b5038d7SDag-Erling Smørgrav	    case $deplib in
81597b5038d7SDag-Erling Smørgrav	    -L*) func_stripname '-L' '' "$deplib"
81607b5038d7SDag-Erling Smørgrav	         func_resolve_sysroot "$func_stripname_result"
81617b5038d7SDag-Erling Smørgrav	         func_append newlib_search_path " $func_resolve_sysroot_result"
81627b5038d7SDag-Erling Smørgrav		 ;;
81637b5038d7SDag-Erling Smørgrav	    esac
81647b5038d7SDag-Erling Smørgrav	    # Need to link against all dependency_libs?
8165986ba33cSDag-Erling Smørgrav	    if $linkalldeplibs; then
81667b5038d7SDag-Erling Smørgrav	      deplibs="$deplib $deplibs"
81677b5038d7SDag-Erling Smørgrav	    else
81687b5038d7SDag-Erling Smørgrav	      # Need to hardcode shared library paths
81697b5038d7SDag-Erling Smørgrav	      # or/and link against static libraries
81707b5038d7SDag-Erling Smørgrav	      newdependency_libs="$deplib $newdependency_libs"
81717b5038d7SDag-Erling Smørgrav	    fi
81727b5038d7SDag-Erling Smørgrav	    if $opt_preserve_dup_deps; then
81737b5038d7SDag-Erling Smørgrav	      case "$tmp_libs " in
81747b5038d7SDag-Erling Smørgrav	      *" $deplib "*) func_append specialdeplibs " $deplib" ;;
81757b5038d7SDag-Erling Smørgrav	      esac
81767b5038d7SDag-Erling Smørgrav	    fi
81777b5038d7SDag-Erling Smørgrav	    func_append tmp_libs " $deplib"
81787b5038d7SDag-Erling Smørgrav	  done # for deplib
81797b5038d7SDag-Erling Smørgrav	  continue
81807b5038d7SDag-Erling Smørgrav	fi # $linkmode = prog...
81817b5038d7SDag-Erling Smørgrav
8182986ba33cSDag-Erling Smørgrav	if test prog,link = "$linkmode,$pass"; then
81837b5038d7SDag-Erling Smørgrav	  if test -n "$library_names" &&
8184986ba33cSDag-Erling Smørgrav	     { { test no = "$prefer_static_libs" ||
8185986ba33cSDag-Erling Smørgrav	         test built,yes = "$prefer_static_libs,$installed"; } ||
81867b5038d7SDag-Erling Smørgrav	       test -z "$old_library"; }; then
81877b5038d7SDag-Erling Smørgrav	    # We need to hardcode the library path
81887b5038d7SDag-Erling Smørgrav	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath"; then
81897b5038d7SDag-Erling Smørgrav	      # Make sure the rpath contains only unique directories.
8190986ba33cSDag-Erling Smørgrav	      case $temp_rpath: in
81917b5038d7SDag-Erling Smørgrav	      *"$absdir:"*) ;;
81927b5038d7SDag-Erling Smørgrav	      *) func_append temp_rpath "$absdir:" ;;
81937b5038d7SDag-Erling Smørgrav	      esac
81947b5038d7SDag-Erling Smørgrav	    fi
81957b5038d7SDag-Erling Smørgrav
81967b5038d7SDag-Erling Smørgrav	    # Hardcode the library path.
81977b5038d7SDag-Erling Smørgrav	    # Skip directories that are in the system default run-time
81987b5038d7SDag-Erling Smørgrav	    # search path.
81997b5038d7SDag-Erling Smørgrav	    case " $sys_lib_dlsearch_path " in
82007b5038d7SDag-Erling Smørgrav	    *" $absdir "*) ;;
82017b5038d7SDag-Erling Smørgrav	    *)
82027b5038d7SDag-Erling Smørgrav	      case "$compile_rpath " in
82037b5038d7SDag-Erling Smørgrav	      *" $absdir "*) ;;
82047b5038d7SDag-Erling Smørgrav	      *) func_append compile_rpath " $absdir" ;;
82057b5038d7SDag-Erling Smørgrav	      esac
82067b5038d7SDag-Erling Smørgrav	      ;;
82077b5038d7SDag-Erling Smørgrav	    esac
82087b5038d7SDag-Erling Smørgrav	    case " $sys_lib_dlsearch_path " in
82097b5038d7SDag-Erling Smørgrav	    *" $libdir "*) ;;
82107b5038d7SDag-Erling Smørgrav	    *)
82117b5038d7SDag-Erling Smørgrav	      case "$finalize_rpath " in
82127b5038d7SDag-Erling Smørgrav	      *" $libdir "*) ;;
82137b5038d7SDag-Erling Smørgrav	      *) func_append finalize_rpath " $libdir" ;;
82147b5038d7SDag-Erling Smørgrav	      esac
82157b5038d7SDag-Erling Smørgrav	      ;;
82167b5038d7SDag-Erling Smørgrav	    esac
82177b5038d7SDag-Erling Smørgrav	  fi # $linkmode,$pass = prog,link...
82187b5038d7SDag-Erling Smørgrav
8219986ba33cSDag-Erling Smørgrav	  if $alldeplibs &&
8220986ba33cSDag-Erling Smørgrav	     { test pass_all = "$deplibs_check_method" ||
8221986ba33cSDag-Erling Smørgrav	       { test yes = "$build_libtool_libs" &&
82227b5038d7SDag-Erling Smørgrav		 test -n "$library_names"; }; }; then
82237b5038d7SDag-Erling Smørgrav	    # We only need to search for static libraries
82247b5038d7SDag-Erling Smørgrav	    continue
82257b5038d7SDag-Erling Smørgrav	  fi
82267b5038d7SDag-Erling Smørgrav	fi
82277b5038d7SDag-Erling Smørgrav
82287b5038d7SDag-Erling Smørgrav	link_static=no # Whether the deplib will be linked statically
82297b5038d7SDag-Erling Smørgrav	use_static_libs=$prefer_static_libs
8230986ba33cSDag-Erling Smørgrav	if test built = "$use_static_libs" && test yes = "$installed"; then
82317b5038d7SDag-Erling Smørgrav	  use_static_libs=no
82327b5038d7SDag-Erling Smørgrav	fi
82337b5038d7SDag-Erling Smørgrav	if test -n "$library_names" &&
8234986ba33cSDag-Erling Smørgrav	   { test no = "$use_static_libs" || test -z "$old_library"; }; then
82357b5038d7SDag-Erling Smørgrav	  case $host in
8236986ba33cSDag-Erling Smørgrav	  *cygwin* | *mingw* | *cegcc* | *os2*)
82377b5038d7SDag-Erling Smørgrav	      # No point in relinking DLLs because paths are not encoded
82387b5038d7SDag-Erling Smørgrav	      func_append notinst_deplibs " $lib"
82397b5038d7SDag-Erling Smørgrav	      need_relink=no
82407b5038d7SDag-Erling Smørgrav	    ;;
82417b5038d7SDag-Erling Smørgrav	  *)
8242986ba33cSDag-Erling Smørgrav	    if test no = "$installed"; then
82437b5038d7SDag-Erling Smørgrav	      func_append notinst_deplibs " $lib"
82447b5038d7SDag-Erling Smørgrav	      need_relink=yes
82457b5038d7SDag-Erling Smørgrav	    fi
82467b5038d7SDag-Erling Smørgrav	    ;;
82477b5038d7SDag-Erling Smørgrav	  esac
82487b5038d7SDag-Erling Smørgrav	  # This is a shared library
82497b5038d7SDag-Erling Smørgrav
82507b5038d7SDag-Erling Smørgrav	  # Warn about portability, can't link against -module's on some
82517b5038d7SDag-Erling Smørgrav	  # systems (darwin).  Don't bleat about dlopened modules though!
8252986ba33cSDag-Erling Smørgrav	  dlopenmodule=
82537b5038d7SDag-Erling Smørgrav	  for dlpremoduletest in $dlprefiles; do
82547b5038d7SDag-Erling Smørgrav	    if test "X$dlpremoduletest" = "X$lib"; then
8255986ba33cSDag-Erling Smørgrav	      dlopenmodule=$dlpremoduletest
82567b5038d7SDag-Erling Smørgrav	      break
82577b5038d7SDag-Erling Smørgrav	    fi
82587b5038d7SDag-Erling Smørgrav	  done
8259986ba33cSDag-Erling Smørgrav	  if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then
82607b5038d7SDag-Erling Smørgrav	    echo
8261986ba33cSDag-Erling Smørgrav	    if test prog = "$linkmode"; then
82627b5038d7SDag-Erling Smørgrav	      $ECHO "*** Warning: Linking the executable $output against the loadable module"
82637b5038d7SDag-Erling Smørgrav	    else
82647b5038d7SDag-Erling Smørgrav	      $ECHO "*** Warning: Linking the shared library $output against the loadable module"
82657b5038d7SDag-Erling Smørgrav	    fi
82667b5038d7SDag-Erling Smørgrav	    $ECHO "*** $linklib is not portable!"
82677b5038d7SDag-Erling Smørgrav	  fi
8268986ba33cSDag-Erling Smørgrav	  if test lib = "$linkmode" &&
8269986ba33cSDag-Erling Smørgrav	     test yes = "$hardcode_into_libs"; then
82707b5038d7SDag-Erling Smørgrav	    # Hardcode the library path.
82717b5038d7SDag-Erling Smørgrav	    # Skip directories that are in the system default run-time
82727b5038d7SDag-Erling Smørgrav	    # search path.
82737b5038d7SDag-Erling Smørgrav	    case " $sys_lib_dlsearch_path " in
82747b5038d7SDag-Erling Smørgrav	    *" $absdir "*) ;;
82757b5038d7SDag-Erling Smørgrav	    *)
82767b5038d7SDag-Erling Smørgrav	      case "$compile_rpath " in
82777b5038d7SDag-Erling Smørgrav	      *" $absdir "*) ;;
82787b5038d7SDag-Erling Smørgrav	      *) func_append compile_rpath " $absdir" ;;
82797b5038d7SDag-Erling Smørgrav	      esac
82807b5038d7SDag-Erling Smørgrav	      ;;
82817b5038d7SDag-Erling Smørgrav	    esac
82827b5038d7SDag-Erling Smørgrav	    case " $sys_lib_dlsearch_path " in
82837b5038d7SDag-Erling Smørgrav	    *" $libdir "*) ;;
82847b5038d7SDag-Erling Smørgrav	    *)
82857b5038d7SDag-Erling Smørgrav	      case "$finalize_rpath " in
82867b5038d7SDag-Erling Smørgrav	      *" $libdir "*) ;;
82877b5038d7SDag-Erling Smørgrav	      *) func_append finalize_rpath " $libdir" ;;
82887b5038d7SDag-Erling Smørgrav	      esac
82897b5038d7SDag-Erling Smørgrav	      ;;
82907b5038d7SDag-Erling Smørgrav	    esac
82917b5038d7SDag-Erling Smørgrav	  fi
82927b5038d7SDag-Erling Smørgrav
82937b5038d7SDag-Erling Smørgrav	  if test -n "$old_archive_from_expsyms_cmds"; then
82947b5038d7SDag-Erling Smørgrav	    # figure out the soname
82957b5038d7SDag-Erling Smørgrav	    set dummy $library_names
82967b5038d7SDag-Erling Smørgrav	    shift
8297986ba33cSDag-Erling Smørgrav	    realname=$1
82987b5038d7SDag-Erling Smørgrav	    shift
82997b5038d7SDag-Erling Smørgrav	    libname=`eval "\\$ECHO \"$libname_spec\""`
83007b5038d7SDag-Erling Smørgrav	    # use dlname if we got it. it's perfectly good, no?
83017b5038d7SDag-Erling Smørgrav	    if test -n "$dlname"; then
8302986ba33cSDag-Erling Smørgrav	      soname=$dlname
83037b5038d7SDag-Erling Smørgrav	    elif test -n "$soname_spec"; then
83047b5038d7SDag-Erling Smørgrav	      # bleh windows
83057b5038d7SDag-Erling Smørgrav	      case $host in
8306986ba33cSDag-Erling Smørgrav	      *cygwin* | mingw* | *cegcc* | *os2*)
83077b5038d7SDag-Erling Smørgrav	        func_arith $current - $age
83087b5038d7SDag-Erling Smørgrav		major=$func_arith_result
8309986ba33cSDag-Erling Smørgrav		versuffix=-$major
83107b5038d7SDag-Erling Smørgrav		;;
83117b5038d7SDag-Erling Smørgrav	      esac
83127b5038d7SDag-Erling Smørgrav	      eval soname=\"$soname_spec\"
83137b5038d7SDag-Erling Smørgrav	    else
8314986ba33cSDag-Erling Smørgrav	      soname=$realname
83157b5038d7SDag-Erling Smørgrav	    fi
83167b5038d7SDag-Erling Smørgrav
83177b5038d7SDag-Erling Smørgrav	    # Make a new name for the extract_expsyms_cmds to use
8318986ba33cSDag-Erling Smørgrav	    soroot=$soname
83197b5038d7SDag-Erling Smørgrav	    func_basename "$soroot"
8320986ba33cSDag-Erling Smørgrav	    soname=$func_basename_result
83217b5038d7SDag-Erling Smørgrav	    func_stripname 'lib' '.dll' "$soname"
83227b5038d7SDag-Erling Smørgrav	    newlib=libimp-$func_stripname_result.a
83237b5038d7SDag-Erling Smørgrav
83247b5038d7SDag-Erling Smørgrav	    # If the library has no export list, then create one now
83257b5038d7SDag-Erling Smørgrav	    if test -f "$output_objdir/$soname-def"; then :
83267b5038d7SDag-Erling Smørgrav	    else
8327986ba33cSDag-Erling Smørgrav	      func_verbose "extracting exported symbol list from '$soname'"
83287b5038d7SDag-Erling Smørgrav	      func_execute_cmds "$extract_expsyms_cmds" 'exit $?'
83297b5038d7SDag-Erling Smørgrav	    fi
83307b5038d7SDag-Erling Smørgrav
83317b5038d7SDag-Erling Smørgrav	    # Create $newlib
83327b5038d7SDag-Erling Smørgrav	    if test -f "$output_objdir/$newlib"; then :; else
8333986ba33cSDag-Erling Smørgrav	      func_verbose "generating import library for '$soname'"
83347b5038d7SDag-Erling Smørgrav	      func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?'
83357b5038d7SDag-Erling Smørgrav	    fi
83367b5038d7SDag-Erling Smørgrav	    # make sure the library variables are pointing to the new library
83377b5038d7SDag-Erling Smørgrav	    dir=$output_objdir
83387b5038d7SDag-Erling Smørgrav	    linklib=$newlib
83397b5038d7SDag-Erling Smørgrav	  fi # test -n "$old_archive_from_expsyms_cmds"
83407b5038d7SDag-Erling Smørgrav
8341986ba33cSDag-Erling Smørgrav	  if test prog = "$linkmode" || test relink != "$opt_mode"; then
83427b5038d7SDag-Erling Smørgrav	    add_shlibpath=
83437b5038d7SDag-Erling Smørgrav	    add_dir=
83447b5038d7SDag-Erling Smørgrav	    add=
83457b5038d7SDag-Erling Smørgrav	    lib_linked=yes
83467b5038d7SDag-Erling Smørgrav	    case $hardcode_action in
83477b5038d7SDag-Erling Smørgrav	    immediate | unsupported)
8348986ba33cSDag-Erling Smørgrav	      if test no = "$hardcode_direct"; then
8349986ba33cSDag-Erling Smørgrav		add=$dir/$linklib
83507b5038d7SDag-Erling Smørgrav		case $host in
8351986ba33cSDag-Erling Smørgrav		  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;
8352986ba33cSDag-Erling Smørgrav		  *-*-sysv4*uw2*) add_dir=-L$dir ;;
83537b5038d7SDag-Erling Smørgrav		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
8354986ba33cSDag-Erling Smørgrav		    *-*-unixware7*) add_dir=-L$dir ;;
83557b5038d7SDag-Erling Smørgrav		  *-*-darwin* )
83567b5038d7SDag-Erling Smørgrav		    # if the lib is a (non-dlopened) module then we cannot
83577b5038d7SDag-Erling Smørgrav		    # link against it, someone is ignoring the earlier warnings
83587b5038d7SDag-Erling Smørgrav		    if /usr/bin/file -L $add 2> /dev/null |
83597b5038d7SDag-Erling Smørgrav			 $GREP ": [^:]* bundle" >/dev/null; then
83607b5038d7SDag-Erling Smørgrav		      if test "X$dlopenmodule" != "X$lib"; then
83617b5038d7SDag-Erling Smørgrav			$ECHO "*** Warning: lib $linklib is a module, not a shared library"
83627b5038d7SDag-Erling Smørgrav			if test -z "$old_library"; then
83637b5038d7SDag-Erling Smørgrav			  echo
83647b5038d7SDag-Erling Smørgrav			  echo "*** And there doesn't seem to be a static archive available"
83657b5038d7SDag-Erling Smørgrav			  echo "*** The link will probably fail, sorry"
83667b5038d7SDag-Erling Smørgrav			else
8367986ba33cSDag-Erling Smørgrav			  add=$dir/$old_library
83687b5038d7SDag-Erling Smørgrav			fi
83697b5038d7SDag-Erling Smørgrav		      elif test -n "$old_library"; then
8370986ba33cSDag-Erling Smørgrav			add=$dir/$old_library
83717b5038d7SDag-Erling Smørgrav		      fi
83727b5038d7SDag-Erling Smørgrav		    fi
83737b5038d7SDag-Erling Smørgrav		esac
8374986ba33cSDag-Erling Smørgrav	      elif test no = "$hardcode_minus_L"; then
83757b5038d7SDag-Erling Smørgrav		case $host in
8376986ba33cSDag-Erling Smørgrav		*-*-sunos*) add_shlibpath=$dir ;;
83777b5038d7SDag-Erling Smørgrav		esac
8378986ba33cSDag-Erling Smørgrav		add_dir=-L$dir
8379986ba33cSDag-Erling Smørgrav		add=-l$name
8380986ba33cSDag-Erling Smørgrav	      elif test no = "$hardcode_shlibpath_var"; then
8381986ba33cSDag-Erling Smørgrav		add_shlibpath=$dir
8382986ba33cSDag-Erling Smørgrav		add=-l$name
83837b5038d7SDag-Erling Smørgrav	      else
83847b5038d7SDag-Erling Smørgrav		lib_linked=no
83857b5038d7SDag-Erling Smørgrav	      fi
83867b5038d7SDag-Erling Smørgrav	      ;;
83877b5038d7SDag-Erling Smørgrav	    relink)
8388986ba33cSDag-Erling Smørgrav	      if test yes = "$hardcode_direct" &&
8389986ba33cSDag-Erling Smørgrav	         test no = "$hardcode_direct_absolute"; then
8390986ba33cSDag-Erling Smørgrav		add=$dir/$linklib
8391986ba33cSDag-Erling Smørgrav	      elif test yes = "$hardcode_minus_L"; then
8392986ba33cSDag-Erling Smørgrav		add_dir=-L$absdir
83937b5038d7SDag-Erling Smørgrav		# Try looking first in the location we're being installed to.
83947b5038d7SDag-Erling Smørgrav		if test -n "$inst_prefix_dir"; then
83957b5038d7SDag-Erling Smørgrav		  case $libdir in
83967b5038d7SDag-Erling Smørgrav		    [\\/]*)
83977b5038d7SDag-Erling Smørgrav		      func_append add_dir " -L$inst_prefix_dir$libdir"
83987b5038d7SDag-Erling Smørgrav		      ;;
83997b5038d7SDag-Erling Smørgrav		  esac
84007b5038d7SDag-Erling Smørgrav		fi
8401986ba33cSDag-Erling Smørgrav		add=-l$name
8402986ba33cSDag-Erling Smørgrav	      elif test yes = "$hardcode_shlibpath_var"; then
8403986ba33cSDag-Erling Smørgrav		add_shlibpath=$dir
8404986ba33cSDag-Erling Smørgrav		add=-l$name
84057b5038d7SDag-Erling Smørgrav	      else
84067b5038d7SDag-Erling Smørgrav		lib_linked=no
84077b5038d7SDag-Erling Smørgrav	      fi
84087b5038d7SDag-Erling Smørgrav	      ;;
84097b5038d7SDag-Erling Smørgrav	    *) lib_linked=no ;;
84107b5038d7SDag-Erling Smørgrav	    esac
84117b5038d7SDag-Erling Smørgrav
8412986ba33cSDag-Erling Smørgrav	    if test yes != "$lib_linked"; then
84137b5038d7SDag-Erling Smørgrav	      func_fatal_configuration "unsupported hardcode properties"
84147b5038d7SDag-Erling Smørgrav	    fi
84157b5038d7SDag-Erling Smørgrav
84167b5038d7SDag-Erling Smørgrav	    if test -n "$add_shlibpath"; then
84177b5038d7SDag-Erling Smørgrav	      case :$compile_shlibpath: in
84187b5038d7SDag-Erling Smørgrav	      *":$add_shlibpath:"*) ;;
84197b5038d7SDag-Erling Smørgrav	      *) func_append compile_shlibpath "$add_shlibpath:" ;;
84207b5038d7SDag-Erling Smørgrav	      esac
84217b5038d7SDag-Erling Smørgrav	    fi
8422986ba33cSDag-Erling Smørgrav	    if test prog = "$linkmode"; then
84237b5038d7SDag-Erling Smørgrav	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
84247b5038d7SDag-Erling Smørgrav	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
84257b5038d7SDag-Erling Smørgrav	    else
84267b5038d7SDag-Erling Smørgrav	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
84277b5038d7SDag-Erling Smørgrav	      test -n "$add" && deplibs="$add $deplibs"
8428986ba33cSDag-Erling Smørgrav	      if test yes != "$hardcode_direct" &&
8429986ba33cSDag-Erling Smørgrav		 test yes != "$hardcode_minus_L" &&
8430986ba33cSDag-Erling Smørgrav		 test yes = "$hardcode_shlibpath_var"; then
84317b5038d7SDag-Erling Smørgrav		case :$finalize_shlibpath: in
84327b5038d7SDag-Erling Smørgrav		*":$libdir:"*) ;;
84337b5038d7SDag-Erling Smørgrav		*) func_append finalize_shlibpath "$libdir:" ;;
84347b5038d7SDag-Erling Smørgrav		esac
84357b5038d7SDag-Erling Smørgrav	      fi
84367b5038d7SDag-Erling Smørgrav	    fi
84377b5038d7SDag-Erling Smørgrav	  fi
84387b5038d7SDag-Erling Smørgrav
8439986ba33cSDag-Erling Smørgrav	  if test prog = "$linkmode" || test relink = "$opt_mode"; then
84407b5038d7SDag-Erling Smørgrav	    add_shlibpath=
84417b5038d7SDag-Erling Smørgrav	    add_dir=
84427b5038d7SDag-Erling Smørgrav	    add=
84437b5038d7SDag-Erling Smørgrav	    # Finalize command for both is simple: just hardcode it.
8444986ba33cSDag-Erling Smørgrav	    if test yes = "$hardcode_direct" &&
8445986ba33cSDag-Erling Smørgrav	       test no = "$hardcode_direct_absolute"; then
8446986ba33cSDag-Erling Smørgrav	      add=$libdir/$linklib
8447986ba33cSDag-Erling Smørgrav	    elif test yes = "$hardcode_minus_L"; then
8448986ba33cSDag-Erling Smørgrav	      add_dir=-L$libdir
8449986ba33cSDag-Erling Smørgrav	      add=-l$name
8450986ba33cSDag-Erling Smørgrav	    elif test yes = "$hardcode_shlibpath_var"; then
84517b5038d7SDag-Erling Smørgrav	      case :$finalize_shlibpath: in
84527b5038d7SDag-Erling Smørgrav	      *":$libdir:"*) ;;
84537b5038d7SDag-Erling Smørgrav	      *) func_append finalize_shlibpath "$libdir:" ;;
84547b5038d7SDag-Erling Smørgrav	      esac
8455986ba33cSDag-Erling Smørgrav	      add=-l$name
8456986ba33cSDag-Erling Smørgrav	    elif test yes = "$hardcode_automatic"; then
84577b5038d7SDag-Erling Smørgrav	      if test -n "$inst_prefix_dir" &&
84587b5038d7SDag-Erling Smørgrav		 test -f "$inst_prefix_dir$libdir/$linklib"; then
8459986ba33cSDag-Erling Smørgrav		add=$inst_prefix_dir$libdir/$linklib
84607b5038d7SDag-Erling Smørgrav	      else
8461986ba33cSDag-Erling Smørgrav		add=$libdir/$linklib
84627b5038d7SDag-Erling Smørgrav	      fi
84637b5038d7SDag-Erling Smørgrav	    else
84647b5038d7SDag-Erling Smørgrav	      # We cannot seem to hardcode it, guess we'll fake it.
8465986ba33cSDag-Erling Smørgrav	      add_dir=-L$libdir
84667b5038d7SDag-Erling Smørgrav	      # Try looking first in the location we're being installed to.
84677b5038d7SDag-Erling Smørgrav	      if test -n "$inst_prefix_dir"; then
84687b5038d7SDag-Erling Smørgrav		case $libdir in
84697b5038d7SDag-Erling Smørgrav		  [\\/]*)
84707b5038d7SDag-Erling Smørgrav		    func_append add_dir " -L$inst_prefix_dir$libdir"
84717b5038d7SDag-Erling Smørgrav		    ;;
84727b5038d7SDag-Erling Smørgrav		esac
84737b5038d7SDag-Erling Smørgrav	      fi
8474986ba33cSDag-Erling Smørgrav	      add=-l$name
84757b5038d7SDag-Erling Smørgrav	    fi
84767b5038d7SDag-Erling Smørgrav
8477986ba33cSDag-Erling Smørgrav	    if test prog = "$linkmode"; then
84787b5038d7SDag-Erling Smørgrav	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
84797b5038d7SDag-Erling Smørgrav	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
84807b5038d7SDag-Erling Smørgrav	    else
84817b5038d7SDag-Erling Smørgrav	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
84827b5038d7SDag-Erling Smørgrav	      test -n "$add" && deplibs="$add $deplibs"
84837b5038d7SDag-Erling Smørgrav	    fi
84847b5038d7SDag-Erling Smørgrav	  fi
8485986ba33cSDag-Erling Smørgrav	elif test prog = "$linkmode"; then
84867b5038d7SDag-Erling Smørgrav	  # Here we assume that one of hardcode_direct or hardcode_minus_L
84877b5038d7SDag-Erling Smørgrav	  # is not unsupported.  This is valid on all known static and
84887b5038d7SDag-Erling Smørgrav	  # shared platforms.
8489986ba33cSDag-Erling Smørgrav	  if test unsupported != "$hardcode_direct"; then
8490986ba33cSDag-Erling Smørgrav	    test -n "$old_library" && linklib=$old_library
84917b5038d7SDag-Erling Smørgrav	    compile_deplibs="$dir/$linklib $compile_deplibs"
84927b5038d7SDag-Erling Smørgrav	    finalize_deplibs="$dir/$linklib $finalize_deplibs"
84937b5038d7SDag-Erling Smørgrav	  else
84947b5038d7SDag-Erling Smørgrav	    compile_deplibs="-l$name -L$dir $compile_deplibs"
84957b5038d7SDag-Erling Smørgrav	    finalize_deplibs="-l$name -L$dir $finalize_deplibs"
84967b5038d7SDag-Erling Smørgrav	  fi
8497986ba33cSDag-Erling Smørgrav	elif test yes = "$build_libtool_libs"; then
84987b5038d7SDag-Erling Smørgrav	  # Not a shared library
8499986ba33cSDag-Erling Smørgrav	  if test pass_all != "$deplibs_check_method"; then
85007b5038d7SDag-Erling Smørgrav	    # We're trying link a shared library against a static one
85017b5038d7SDag-Erling Smørgrav	    # but the system doesn't support it.
85027b5038d7SDag-Erling Smørgrav
85037b5038d7SDag-Erling Smørgrav	    # Just print a warning and add the library to dependency_libs so
85047b5038d7SDag-Erling Smørgrav	    # that the program can be linked against the static library.
85057b5038d7SDag-Erling Smørgrav	    echo
85067b5038d7SDag-Erling Smørgrav	    $ECHO "*** Warning: This system cannot link to static lib archive $lib."
85077b5038d7SDag-Erling Smørgrav	    echo "*** I have the capability to make that library automatically link in when"
85087b5038d7SDag-Erling Smørgrav	    echo "*** you link to this library.  But I can only do this if you have a"
85097b5038d7SDag-Erling Smørgrav	    echo "*** shared version of the library, which you do not appear to have."
8510986ba33cSDag-Erling Smørgrav	    if test yes = "$module"; then
85117b5038d7SDag-Erling Smørgrav	      echo "*** But as you try to build a module library, libtool will still create "
85127b5038d7SDag-Erling Smørgrav	      echo "*** a static module, that should work as long as the dlopening application"
85137b5038d7SDag-Erling Smørgrav	      echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
85147b5038d7SDag-Erling Smørgrav	      if test -z "$global_symbol_pipe"; then
85157b5038d7SDag-Erling Smørgrav		echo
85167b5038d7SDag-Erling Smørgrav		echo "*** However, this would only work if libtool was able to extract symbol"
8517986ba33cSDag-Erling Smørgrav		echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
85187b5038d7SDag-Erling Smørgrav		echo "*** not find such a program.  So, this module is probably useless."
8519986ba33cSDag-Erling Smørgrav		echo "*** 'nm' from GNU binutils and a full rebuild may help."
85207b5038d7SDag-Erling Smørgrav	      fi
8521986ba33cSDag-Erling Smørgrav	      if test no = "$build_old_libs"; then
85227b5038d7SDag-Erling Smørgrav		build_libtool_libs=module
85237b5038d7SDag-Erling Smørgrav		build_old_libs=yes
85247b5038d7SDag-Erling Smørgrav	      else
85257b5038d7SDag-Erling Smørgrav		build_libtool_libs=no
85267b5038d7SDag-Erling Smørgrav	      fi
85277b5038d7SDag-Erling Smørgrav	    fi
85287b5038d7SDag-Erling Smørgrav	  else
85297b5038d7SDag-Erling Smørgrav	    deplibs="$dir/$old_library $deplibs"
85307b5038d7SDag-Erling Smørgrav	    link_static=yes
85317b5038d7SDag-Erling Smørgrav	  fi
85327b5038d7SDag-Erling Smørgrav	fi # link shared/static library?
85337b5038d7SDag-Erling Smørgrav
8534986ba33cSDag-Erling Smørgrav	if test lib = "$linkmode"; then
85357b5038d7SDag-Erling Smørgrav	  if test -n "$dependency_libs" &&
8536986ba33cSDag-Erling Smørgrav	     { test yes != "$hardcode_into_libs" ||
8537986ba33cSDag-Erling Smørgrav	       test yes = "$build_old_libs" ||
8538986ba33cSDag-Erling Smørgrav	       test yes = "$link_static"; }; then
85397b5038d7SDag-Erling Smørgrav	    # Extract -R from dependency_libs
85407b5038d7SDag-Erling Smørgrav	    temp_deplibs=
85417b5038d7SDag-Erling Smørgrav	    for libdir in $dependency_libs; do
85427b5038d7SDag-Erling Smørgrav	      case $libdir in
85437b5038d7SDag-Erling Smørgrav	      -R*) func_stripname '-R' '' "$libdir"
85447b5038d7SDag-Erling Smørgrav	           temp_xrpath=$func_stripname_result
85457b5038d7SDag-Erling Smørgrav		   case " $xrpath " in
85467b5038d7SDag-Erling Smørgrav		   *" $temp_xrpath "*) ;;
85477b5038d7SDag-Erling Smørgrav		   *) func_append xrpath " $temp_xrpath";;
85487b5038d7SDag-Erling Smørgrav		   esac;;
85497b5038d7SDag-Erling Smørgrav	      *) func_append temp_deplibs " $libdir";;
85507b5038d7SDag-Erling Smørgrav	      esac
85517b5038d7SDag-Erling Smørgrav	    done
8552986ba33cSDag-Erling Smørgrav	    dependency_libs=$temp_deplibs
85537b5038d7SDag-Erling Smørgrav	  fi
85547b5038d7SDag-Erling Smørgrav
85557b5038d7SDag-Erling Smørgrav	  func_append newlib_search_path " $absdir"
85567b5038d7SDag-Erling Smørgrav	  # Link against this library
8557986ba33cSDag-Erling Smørgrav	  test no = "$link_static" && newdependency_libs="$abs_ladir/$laname $newdependency_libs"
85587b5038d7SDag-Erling Smørgrav	  # ... and its dependency_libs
85597b5038d7SDag-Erling Smørgrav	  tmp_libs=
85607b5038d7SDag-Erling Smørgrav	  for deplib in $dependency_libs; do
85617b5038d7SDag-Erling Smørgrav	    newdependency_libs="$deplib $newdependency_libs"
85627b5038d7SDag-Erling Smørgrav	    case $deplib in
85637b5038d7SDag-Erling Smørgrav              -L*) func_stripname '-L' '' "$deplib"
85647b5038d7SDag-Erling Smørgrav                   func_resolve_sysroot "$func_stripname_result";;
85657b5038d7SDag-Erling Smørgrav              *) func_resolve_sysroot "$deplib" ;;
85667b5038d7SDag-Erling Smørgrav            esac
85677b5038d7SDag-Erling Smørgrav	    if $opt_preserve_dup_deps; then
85687b5038d7SDag-Erling Smørgrav	      case "$tmp_libs " in
85697b5038d7SDag-Erling Smørgrav	      *" $func_resolve_sysroot_result "*)
85707b5038d7SDag-Erling Smørgrav                func_append specialdeplibs " $func_resolve_sysroot_result" ;;
85717b5038d7SDag-Erling Smørgrav	      esac
85727b5038d7SDag-Erling Smørgrav	    fi
85737b5038d7SDag-Erling Smørgrav	    func_append tmp_libs " $func_resolve_sysroot_result"
85747b5038d7SDag-Erling Smørgrav	  done
85757b5038d7SDag-Erling Smørgrav
8576986ba33cSDag-Erling Smørgrav	  if test no != "$link_all_deplibs"; then
85777b5038d7SDag-Erling Smørgrav	    # Add the search paths of all dependency libraries
85787b5038d7SDag-Erling Smørgrav	    for deplib in $dependency_libs; do
85797b5038d7SDag-Erling Smørgrav	      path=
85807b5038d7SDag-Erling Smørgrav	      case $deplib in
8581986ba33cSDag-Erling Smørgrav	      -L*) path=$deplib ;;
85827b5038d7SDag-Erling Smørgrav	      *.la)
85837b5038d7SDag-Erling Smørgrav	        func_resolve_sysroot "$deplib"
85847b5038d7SDag-Erling Smørgrav	        deplib=$func_resolve_sysroot_result
85857b5038d7SDag-Erling Smørgrav	        func_dirname "$deplib" "" "."
85867b5038d7SDag-Erling Smørgrav		dir=$func_dirname_result
85877b5038d7SDag-Erling Smørgrav		# We need an absolute path.
85887b5038d7SDag-Erling Smørgrav		case $dir in
8589986ba33cSDag-Erling Smørgrav		[\\/]* | [A-Za-z]:[\\/]*) absdir=$dir ;;
85907b5038d7SDag-Erling Smørgrav		*)
85917b5038d7SDag-Erling Smørgrav		  absdir=`cd "$dir" && pwd`
85927b5038d7SDag-Erling Smørgrav		  if test -z "$absdir"; then
8593986ba33cSDag-Erling Smørgrav		    func_warning "cannot determine absolute directory name of '$dir'"
8594986ba33cSDag-Erling Smørgrav		    absdir=$dir
85957b5038d7SDag-Erling Smørgrav		  fi
85967b5038d7SDag-Erling Smørgrav		  ;;
85977b5038d7SDag-Erling Smørgrav		esac
85987b5038d7SDag-Erling Smørgrav		if $GREP "^installed=no" $deplib > /dev/null; then
85997b5038d7SDag-Erling Smørgrav		case $host in
86007b5038d7SDag-Erling Smørgrav		*-*-darwin*)
86017b5038d7SDag-Erling Smørgrav		  depdepl=
8602986ba33cSDag-Erling Smørgrav		  eval deplibrary_names=`$SED -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
86037b5038d7SDag-Erling Smørgrav		  if test -n "$deplibrary_names"; then
86047b5038d7SDag-Erling Smørgrav		    for tmp in $deplibrary_names; do
86057b5038d7SDag-Erling Smørgrav		      depdepl=$tmp
86067b5038d7SDag-Erling Smørgrav		    done
86077b5038d7SDag-Erling Smørgrav		    if test -f "$absdir/$objdir/$depdepl"; then
8608986ba33cSDag-Erling Smørgrav		      depdepl=$absdir/$objdir/$depdepl
8609986ba33cSDag-Erling Smørgrav		      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`
86107b5038d7SDag-Erling Smørgrav                      if test -z "$darwin_install_name"; then
8611986ba33cSDag-Erling Smørgrav                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`
86127b5038d7SDag-Erling Smørgrav                      fi
8613986ba33cSDag-Erling Smørgrav		      func_append compiler_flags " $wl-dylib_file $wl$darwin_install_name:$depdepl"
8614986ba33cSDag-Erling Smørgrav		      func_append linker_flags " -dylib_file $darwin_install_name:$depdepl"
86157b5038d7SDag-Erling Smørgrav		      path=
86167b5038d7SDag-Erling Smørgrav		    fi
86177b5038d7SDag-Erling Smørgrav		  fi
86187b5038d7SDag-Erling Smørgrav		  ;;
86197b5038d7SDag-Erling Smørgrav		*)
8620986ba33cSDag-Erling Smørgrav		  path=-L$absdir/$objdir
86217b5038d7SDag-Erling Smørgrav		  ;;
86227b5038d7SDag-Erling Smørgrav		esac
86237b5038d7SDag-Erling Smørgrav		else
8624986ba33cSDag-Erling Smørgrav		  eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
86257b5038d7SDag-Erling Smørgrav		  test -z "$libdir" && \
8626986ba33cSDag-Erling Smørgrav		    func_fatal_error "'$deplib' is not a valid libtool archive"
86277b5038d7SDag-Erling Smørgrav		  test "$absdir" != "$libdir" && \
8628986ba33cSDag-Erling Smørgrav		    func_warning "'$deplib' seems to be moved"
86297b5038d7SDag-Erling Smørgrav
8630986ba33cSDag-Erling Smørgrav		  path=-L$absdir
86317b5038d7SDag-Erling Smørgrav		fi
86327b5038d7SDag-Erling Smørgrav		;;
86337b5038d7SDag-Erling Smørgrav	      esac
86347b5038d7SDag-Erling Smørgrav	      case " $deplibs " in
86357b5038d7SDag-Erling Smørgrav	      *" $path "*) ;;
86367b5038d7SDag-Erling Smørgrav	      *) deplibs="$path $deplibs" ;;
86377b5038d7SDag-Erling Smørgrav	      esac
86387b5038d7SDag-Erling Smørgrav	    done
86397b5038d7SDag-Erling Smørgrav	  fi # link_all_deplibs != no
86407b5038d7SDag-Erling Smørgrav	fi # linkmode = lib
86417b5038d7SDag-Erling Smørgrav      done # for deplib in $libs
8642986ba33cSDag-Erling Smørgrav      if test link = "$pass"; then
8643986ba33cSDag-Erling Smørgrav	if test prog = "$linkmode"; then
86447b5038d7SDag-Erling Smørgrav	  compile_deplibs="$new_inherited_linker_flags $compile_deplibs"
86457b5038d7SDag-Erling Smørgrav	  finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs"
86467b5038d7SDag-Erling Smørgrav	else
86477b5038d7SDag-Erling Smørgrav	  compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
86487b5038d7SDag-Erling Smørgrav	fi
86497b5038d7SDag-Erling Smørgrav      fi
8650986ba33cSDag-Erling Smørgrav      dependency_libs=$newdependency_libs
8651986ba33cSDag-Erling Smørgrav      if test dlpreopen = "$pass"; then
86527b5038d7SDag-Erling Smørgrav	# Link the dlpreopened libraries before other libraries
86537b5038d7SDag-Erling Smørgrav	for deplib in $save_deplibs; do
86547b5038d7SDag-Erling Smørgrav	  deplibs="$deplib $deplibs"
86557b5038d7SDag-Erling Smørgrav	done
86567b5038d7SDag-Erling Smørgrav      fi
8657986ba33cSDag-Erling Smørgrav      if test dlopen != "$pass"; then
8658986ba33cSDag-Erling Smørgrav	test conv = "$pass" || {
86597b5038d7SDag-Erling Smørgrav	  # Make sure lib_search_path contains only unique directories.
86607b5038d7SDag-Erling Smørgrav	  lib_search_path=
86617b5038d7SDag-Erling Smørgrav	  for dir in $newlib_search_path; do
86627b5038d7SDag-Erling Smørgrav	    case "$lib_search_path " in
86637b5038d7SDag-Erling Smørgrav	    *" $dir "*) ;;
86647b5038d7SDag-Erling Smørgrav	    *) func_append lib_search_path " $dir" ;;
86657b5038d7SDag-Erling Smørgrav	    esac
86667b5038d7SDag-Erling Smørgrav	  done
86677b5038d7SDag-Erling Smørgrav	  newlib_search_path=
8668986ba33cSDag-Erling Smørgrav	}
86697b5038d7SDag-Erling Smørgrav
8670986ba33cSDag-Erling Smørgrav	if test prog,link = "$linkmode,$pass"; then
86717b5038d7SDag-Erling Smørgrav	  vars="compile_deplibs finalize_deplibs"
8672986ba33cSDag-Erling Smørgrav	else
8673986ba33cSDag-Erling Smørgrav	  vars=deplibs
86747b5038d7SDag-Erling Smørgrav	fi
86757b5038d7SDag-Erling Smørgrav	for var in $vars dependency_libs; do
86767b5038d7SDag-Erling Smørgrav	  # Add libraries to $var in reverse order
86777b5038d7SDag-Erling Smørgrav	  eval tmp_libs=\"\$$var\"
86787b5038d7SDag-Erling Smørgrav	  new_libs=
86797b5038d7SDag-Erling Smørgrav	  for deplib in $tmp_libs; do
86807b5038d7SDag-Erling Smørgrav	    # FIXME: Pedantically, this is the right thing to do, so
86817b5038d7SDag-Erling Smørgrav	    #        that some nasty dependency loop isn't accidentally
86827b5038d7SDag-Erling Smørgrav	    #        broken:
86837b5038d7SDag-Erling Smørgrav	    #new_libs="$deplib $new_libs"
86847b5038d7SDag-Erling Smørgrav	    # Pragmatically, this seems to cause very few problems in
86857b5038d7SDag-Erling Smørgrav	    # practice:
86867b5038d7SDag-Erling Smørgrav	    case $deplib in
86877b5038d7SDag-Erling Smørgrav	    -L*) new_libs="$deplib $new_libs" ;;
86887b5038d7SDag-Erling Smørgrav	    -R*) ;;
86897b5038d7SDag-Erling Smørgrav	    *)
86907b5038d7SDag-Erling Smørgrav	      # And here is the reason: when a library appears more
86917b5038d7SDag-Erling Smørgrav	      # than once as an explicit dependence of a library, or
86927b5038d7SDag-Erling Smørgrav	      # is implicitly linked in more than once by the
86937b5038d7SDag-Erling Smørgrav	      # compiler, it is considered special, and multiple
86947b5038d7SDag-Erling Smørgrav	      # occurrences thereof are not removed.  Compare this
86957b5038d7SDag-Erling Smørgrav	      # with having the same library being listed as a
86967b5038d7SDag-Erling Smørgrav	      # dependency of multiple other libraries: in this case,
86977b5038d7SDag-Erling Smørgrav	      # we know (pedantically, we assume) the library does not
86987b5038d7SDag-Erling Smørgrav	      # need to be listed more than once, so we keep only the
86997b5038d7SDag-Erling Smørgrav	      # last copy.  This is not always right, but it is rare
87007b5038d7SDag-Erling Smørgrav	      # enough that we require users that really mean to play
87017b5038d7SDag-Erling Smørgrav	      # such unportable linking tricks to link the library
87027b5038d7SDag-Erling Smørgrav	      # using -Wl,-lname, so that libtool does not consider it
87037b5038d7SDag-Erling Smørgrav	      # for duplicate removal.
87047b5038d7SDag-Erling Smørgrav	      case " $specialdeplibs " in
87057b5038d7SDag-Erling Smørgrav	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
87067b5038d7SDag-Erling Smørgrav	      *)
87077b5038d7SDag-Erling Smørgrav		case " $new_libs " in
87087b5038d7SDag-Erling Smørgrav		*" $deplib "*) ;;
87097b5038d7SDag-Erling Smørgrav		*) new_libs="$deplib $new_libs" ;;
87107b5038d7SDag-Erling Smørgrav		esac
87117b5038d7SDag-Erling Smørgrav		;;
87127b5038d7SDag-Erling Smørgrav	      esac
87137b5038d7SDag-Erling Smørgrav	      ;;
87147b5038d7SDag-Erling Smørgrav	    esac
87157b5038d7SDag-Erling Smørgrav	  done
87167b5038d7SDag-Erling Smørgrav	  tmp_libs=
87177b5038d7SDag-Erling Smørgrav	  for deplib in $new_libs; do
87187b5038d7SDag-Erling Smørgrav	    case $deplib in
87197b5038d7SDag-Erling Smørgrav	    -L*)
87207b5038d7SDag-Erling Smørgrav	      case " $tmp_libs " in
87217b5038d7SDag-Erling Smørgrav	      *" $deplib "*) ;;
87227b5038d7SDag-Erling Smørgrav	      *) func_append tmp_libs " $deplib" ;;
87237b5038d7SDag-Erling Smørgrav	      esac
87247b5038d7SDag-Erling Smørgrav	      ;;
87257b5038d7SDag-Erling Smørgrav	    *) func_append tmp_libs " $deplib" ;;
87267b5038d7SDag-Erling Smørgrav	    esac
87277b5038d7SDag-Erling Smørgrav	  done
87287b5038d7SDag-Erling Smørgrav	  eval $var=\"$tmp_libs\"
87297b5038d7SDag-Erling Smørgrav	done # for var
87307b5038d7SDag-Erling Smørgrav      fi
8731986ba33cSDag-Erling Smørgrav
8732986ba33cSDag-Erling Smørgrav      # Add Sun CC postdeps if required:
8733986ba33cSDag-Erling Smørgrav      test CXX = "$tagname" && {
8734986ba33cSDag-Erling Smørgrav        case $host_os in
8735986ba33cSDag-Erling Smørgrav        linux*)
8736986ba33cSDag-Erling Smørgrav          case `$CC -V 2>&1 | sed 5q` in
8737986ba33cSDag-Erling Smørgrav          *Sun\ C*) # Sun C++ 5.9
8738986ba33cSDag-Erling Smørgrav            func_suncc_cstd_abi
8739986ba33cSDag-Erling Smørgrav
8740986ba33cSDag-Erling Smørgrav            if test no != "$suncc_use_cstd_abi"; then
8741986ba33cSDag-Erling Smørgrav              func_append postdeps ' -library=Cstd -library=Crun'
8742986ba33cSDag-Erling Smørgrav            fi
8743986ba33cSDag-Erling Smørgrav            ;;
8744986ba33cSDag-Erling Smørgrav          esac
8745986ba33cSDag-Erling Smørgrav          ;;
8746986ba33cSDag-Erling Smørgrav
8747986ba33cSDag-Erling Smørgrav        solaris*)
8748986ba33cSDag-Erling Smørgrav          func_cc_basename "$CC"
8749986ba33cSDag-Erling Smørgrav          case $func_cc_basename_result in
8750986ba33cSDag-Erling Smørgrav          CC* | sunCC*)
8751986ba33cSDag-Erling Smørgrav            func_suncc_cstd_abi
8752986ba33cSDag-Erling Smørgrav
8753986ba33cSDag-Erling Smørgrav            if test no != "$suncc_use_cstd_abi"; then
8754986ba33cSDag-Erling Smørgrav              func_append postdeps ' -library=Cstd -library=Crun'
8755986ba33cSDag-Erling Smørgrav            fi
8756986ba33cSDag-Erling Smørgrav            ;;
8757986ba33cSDag-Erling Smørgrav          esac
8758986ba33cSDag-Erling Smørgrav          ;;
8759986ba33cSDag-Erling Smørgrav        esac
8760986ba33cSDag-Erling Smørgrav      }
8761986ba33cSDag-Erling Smørgrav
87627b5038d7SDag-Erling Smørgrav      # Last step: remove runtime libs from dependency_libs
87637b5038d7SDag-Erling Smørgrav      # (they stay in deplibs)
87647b5038d7SDag-Erling Smørgrav      tmp_libs=
87657b5038d7SDag-Erling Smørgrav      for i in $dependency_libs; do
87667b5038d7SDag-Erling Smørgrav	case " $predeps $postdeps $compiler_lib_search_path " in
87677b5038d7SDag-Erling Smørgrav	*" $i "*)
8768986ba33cSDag-Erling Smørgrav	  i=
87697b5038d7SDag-Erling Smørgrav	  ;;
87707b5038d7SDag-Erling Smørgrav	esac
87717b5038d7SDag-Erling Smørgrav	if test -n "$i"; then
87727b5038d7SDag-Erling Smørgrav	  func_append tmp_libs " $i"
87737b5038d7SDag-Erling Smørgrav	fi
87747b5038d7SDag-Erling Smørgrav      done
87757b5038d7SDag-Erling Smørgrav      dependency_libs=$tmp_libs
87767b5038d7SDag-Erling Smørgrav    done # for pass
8777986ba33cSDag-Erling Smørgrav    if test prog = "$linkmode"; then
8778986ba33cSDag-Erling Smørgrav      dlfiles=$newdlfiles
87797b5038d7SDag-Erling Smørgrav    fi
8780986ba33cSDag-Erling Smørgrav    if test prog = "$linkmode" || test lib = "$linkmode"; then
8781986ba33cSDag-Erling Smørgrav      dlprefiles=$newdlprefiles
87827b5038d7SDag-Erling Smørgrav    fi
87837b5038d7SDag-Erling Smørgrav
87847b5038d7SDag-Erling Smørgrav    case $linkmode in
87857b5038d7SDag-Erling Smørgrav    oldlib)
8786986ba33cSDag-Erling Smørgrav      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
8787986ba33cSDag-Erling Smørgrav	func_warning "'-dlopen' is ignored for archives"
87887b5038d7SDag-Erling Smørgrav      fi
87897b5038d7SDag-Erling Smørgrav
87907b5038d7SDag-Erling Smørgrav      case " $deplibs" in
87917b5038d7SDag-Erling Smørgrav      *\ -l* | *\ -L*)
8792986ba33cSDag-Erling Smørgrav	func_warning "'-l' and '-L' are ignored for archives" ;;
87937b5038d7SDag-Erling Smørgrav      esac
87947b5038d7SDag-Erling Smørgrav
87957b5038d7SDag-Erling Smørgrav      test -n "$rpath" && \
8796986ba33cSDag-Erling Smørgrav	func_warning "'-rpath' is ignored for archives"
87977b5038d7SDag-Erling Smørgrav
87987b5038d7SDag-Erling Smørgrav      test -n "$xrpath" && \
8799986ba33cSDag-Erling Smørgrav	func_warning "'-R' is ignored for archives"
88007b5038d7SDag-Erling Smørgrav
88017b5038d7SDag-Erling Smørgrav      test -n "$vinfo" && \
8802986ba33cSDag-Erling Smørgrav	func_warning "'-version-info/-version-number' is ignored for archives"
88037b5038d7SDag-Erling Smørgrav
88047b5038d7SDag-Erling Smørgrav      test -n "$release" && \
8805986ba33cSDag-Erling Smørgrav	func_warning "'-release' is ignored for archives"
88067b5038d7SDag-Erling Smørgrav
88077b5038d7SDag-Erling Smørgrav      test -n "$export_symbols$export_symbols_regex" && \
8808986ba33cSDag-Erling Smørgrav	func_warning "'-export-symbols' is ignored for archives"
88097b5038d7SDag-Erling Smørgrav
88107b5038d7SDag-Erling Smørgrav      # Now set the variables for building old libraries.
88117b5038d7SDag-Erling Smørgrav      build_libtool_libs=no
8812986ba33cSDag-Erling Smørgrav      oldlibs=$output
88137b5038d7SDag-Erling Smørgrav      func_append objs "$old_deplibs"
88147b5038d7SDag-Erling Smørgrav      ;;
88157b5038d7SDag-Erling Smørgrav
88167b5038d7SDag-Erling Smørgrav    lib)
8817986ba33cSDag-Erling Smørgrav      # Make sure we only generate libraries of the form 'libNAME.la'.
88187b5038d7SDag-Erling Smørgrav      case $outputname in
88197b5038d7SDag-Erling Smørgrav      lib*)
88207b5038d7SDag-Erling Smørgrav	func_stripname 'lib' '.la' "$outputname"
88217b5038d7SDag-Erling Smørgrav	name=$func_stripname_result
88227b5038d7SDag-Erling Smørgrav	eval shared_ext=\"$shrext_cmds\"
88237b5038d7SDag-Erling Smørgrav	eval libname=\"$libname_spec\"
88247b5038d7SDag-Erling Smørgrav	;;
88257b5038d7SDag-Erling Smørgrav      *)
8826986ba33cSDag-Erling Smørgrav	test no = "$module" \
8827986ba33cSDag-Erling Smørgrav	  && func_fatal_help "libtool library '$output' must begin with 'lib'"
88287b5038d7SDag-Erling Smørgrav
8829986ba33cSDag-Erling Smørgrav	if test no != "$need_lib_prefix"; then
88307b5038d7SDag-Erling Smørgrav	  # Add the "lib" prefix for modules if required
88317b5038d7SDag-Erling Smørgrav	  func_stripname '' '.la' "$outputname"
88327b5038d7SDag-Erling Smørgrav	  name=$func_stripname_result
88337b5038d7SDag-Erling Smørgrav	  eval shared_ext=\"$shrext_cmds\"
88347b5038d7SDag-Erling Smørgrav	  eval libname=\"$libname_spec\"
88357b5038d7SDag-Erling Smørgrav	else
88367b5038d7SDag-Erling Smørgrav	  func_stripname '' '.la' "$outputname"
88377b5038d7SDag-Erling Smørgrav	  libname=$func_stripname_result
88387b5038d7SDag-Erling Smørgrav	fi
88397b5038d7SDag-Erling Smørgrav	;;
88407b5038d7SDag-Erling Smørgrav      esac
88417b5038d7SDag-Erling Smørgrav
88427b5038d7SDag-Erling Smørgrav      if test -n "$objs"; then
8843986ba33cSDag-Erling Smørgrav	if test pass_all != "$deplibs_check_method"; then
8844986ba33cSDag-Erling Smørgrav	  func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs"
88457b5038d7SDag-Erling Smørgrav	else
88467b5038d7SDag-Erling Smørgrav	  echo
88477b5038d7SDag-Erling Smørgrav	  $ECHO "*** Warning: Linking the shared library $output against the non-libtool"
88487b5038d7SDag-Erling Smørgrav	  $ECHO "*** objects $objs is not portable!"
88497b5038d7SDag-Erling Smørgrav	  func_append libobjs " $objs"
88507b5038d7SDag-Erling Smørgrav	fi
88517b5038d7SDag-Erling Smørgrav      fi
88527b5038d7SDag-Erling Smørgrav
8853986ba33cSDag-Erling Smørgrav      test no = "$dlself" \
8854986ba33cSDag-Erling Smørgrav	|| func_warning "'-dlopen self' is ignored for libtool libraries"
88557b5038d7SDag-Erling Smørgrav
88567b5038d7SDag-Erling Smørgrav      set dummy $rpath
88577b5038d7SDag-Erling Smørgrav      shift
8858986ba33cSDag-Erling Smørgrav      test 1 -lt "$#" \
8859986ba33cSDag-Erling Smørgrav	&& func_warning "ignoring multiple '-rpath's for a libtool library"
88607b5038d7SDag-Erling Smørgrav
8861986ba33cSDag-Erling Smørgrav      install_libdir=$1
88627b5038d7SDag-Erling Smørgrav
88637b5038d7SDag-Erling Smørgrav      oldlibs=
88647b5038d7SDag-Erling Smørgrav      if test -z "$rpath"; then
8865986ba33cSDag-Erling Smørgrav	if test yes = "$build_libtool_libs"; then
88667b5038d7SDag-Erling Smørgrav	  # Building a libtool convenience library.
8867986ba33cSDag-Erling Smørgrav	  # Some compilers have problems with a '.al' extension so
88687b5038d7SDag-Erling Smørgrav	  # convenience libraries should have the same extension an
88697b5038d7SDag-Erling Smørgrav	  # archive normally would.
88707b5038d7SDag-Erling Smørgrav	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
88717b5038d7SDag-Erling Smørgrav	  build_libtool_libs=convenience
88727b5038d7SDag-Erling Smørgrav	  build_old_libs=yes
88737b5038d7SDag-Erling Smørgrav	fi
88747b5038d7SDag-Erling Smørgrav
88757b5038d7SDag-Erling Smørgrav	test -n "$vinfo" && \
8876986ba33cSDag-Erling Smørgrav	  func_warning "'-version-info/-version-number' is ignored for convenience libraries"
88777b5038d7SDag-Erling Smørgrav
88787b5038d7SDag-Erling Smørgrav	test -n "$release" && \
8879986ba33cSDag-Erling Smørgrav	  func_warning "'-release' is ignored for convenience libraries"
88807b5038d7SDag-Erling Smørgrav      else
88817b5038d7SDag-Erling Smørgrav
88827b5038d7SDag-Erling Smørgrav	# Parse the version information argument.
8883986ba33cSDag-Erling Smørgrav	save_ifs=$IFS; IFS=:
88847b5038d7SDag-Erling Smørgrav	set dummy $vinfo 0 0 0
88857b5038d7SDag-Erling Smørgrav	shift
8886986ba33cSDag-Erling Smørgrav	IFS=$save_ifs
88877b5038d7SDag-Erling Smørgrav
88887b5038d7SDag-Erling Smørgrav	test -n "$7" && \
8889986ba33cSDag-Erling Smørgrav	  func_fatal_help "too many parameters to '-version-info'"
88907b5038d7SDag-Erling Smørgrav
88917b5038d7SDag-Erling Smørgrav	# convert absolute version numbers to libtool ages
88927b5038d7SDag-Erling Smørgrav	# this retains compatibility with .la files and attempts
88937b5038d7SDag-Erling Smørgrav	# to make the code below a bit more comprehensible
88947b5038d7SDag-Erling Smørgrav
88957b5038d7SDag-Erling Smørgrav	case $vinfo_number in
88967b5038d7SDag-Erling Smørgrav	yes)
8897986ba33cSDag-Erling Smørgrav	  number_major=$1
8898986ba33cSDag-Erling Smørgrav	  number_minor=$2
8899986ba33cSDag-Erling Smørgrav	  number_revision=$3
89007b5038d7SDag-Erling Smørgrav	  #
89017b5038d7SDag-Erling Smørgrav	  # There are really only two kinds -- those that
89027b5038d7SDag-Erling Smørgrav	  # use the current revision as the major version
89037b5038d7SDag-Erling Smørgrav	  # and those that subtract age and use age as
89047b5038d7SDag-Erling Smørgrav	  # a minor version.  But, then there is irix
8905986ba33cSDag-Erling Smørgrav	  # that has an extra 1 added just for fun
89067b5038d7SDag-Erling Smørgrav	  #
89077b5038d7SDag-Erling Smørgrav	  case $version_type in
89087b5038d7SDag-Erling Smørgrav	  # correct linux to gnu/linux during the next big refactor
8909986ba33cSDag-Erling Smørgrav	  darwin|freebsd-elf|linux|osf|windows|none)
89107b5038d7SDag-Erling Smørgrav	    func_arith $number_major + $number_minor
89117b5038d7SDag-Erling Smørgrav	    current=$func_arith_result
8912986ba33cSDag-Erling Smørgrav	    age=$number_minor
8913986ba33cSDag-Erling Smørgrav	    revision=$number_revision
89147b5038d7SDag-Erling Smørgrav	    ;;
8915986ba33cSDag-Erling Smørgrav	  freebsd-aout|qnx|sunos)
8916986ba33cSDag-Erling Smørgrav	    current=$number_major
8917986ba33cSDag-Erling Smørgrav	    revision=$number_minor
8918986ba33cSDag-Erling Smørgrav	    age=0
89197b5038d7SDag-Erling Smørgrav	    ;;
89207b5038d7SDag-Erling Smørgrav	  irix|nonstopux)
89217b5038d7SDag-Erling Smørgrav	    func_arith $number_major + $number_minor
89227b5038d7SDag-Erling Smørgrav	    current=$func_arith_result
8923986ba33cSDag-Erling Smørgrav	    age=$number_minor
8924986ba33cSDag-Erling Smørgrav	    revision=$number_minor
89257b5038d7SDag-Erling Smørgrav	    lt_irix_increment=no
89267b5038d7SDag-Erling Smørgrav	    ;;
89277b5038d7SDag-Erling Smørgrav	  *)
8928986ba33cSDag-Erling Smørgrav	    func_fatal_configuration "$modename: unknown library version type '$version_type'"
89297b5038d7SDag-Erling Smørgrav	    ;;
89307b5038d7SDag-Erling Smørgrav	  esac
89317b5038d7SDag-Erling Smørgrav	  ;;
89327b5038d7SDag-Erling Smørgrav	no)
8933986ba33cSDag-Erling Smørgrav	  current=$1
8934986ba33cSDag-Erling Smørgrav	  revision=$2
8935986ba33cSDag-Erling Smørgrav	  age=$3
89367b5038d7SDag-Erling Smørgrav	  ;;
89377b5038d7SDag-Erling Smørgrav	esac
89387b5038d7SDag-Erling Smørgrav
89397b5038d7SDag-Erling Smørgrav	# Check that each of the things are valid numbers.
89407b5038d7SDag-Erling Smørgrav	case $current in
89417b5038d7SDag-Erling Smørgrav	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]) ;;
89427b5038d7SDag-Erling Smørgrav	*)
8943986ba33cSDag-Erling Smørgrav	  func_error "CURRENT '$current' must be a nonnegative integer"
8944986ba33cSDag-Erling Smørgrav	  func_fatal_error "'$vinfo' is not valid version information"
89457b5038d7SDag-Erling Smørgrav	  ;;
89467b5038d7SDag-Erling Smørgrav	esac
89477b5038d7SDag-Erling Smørgrav
89487b5038d7SDag-Erling Smørgrav	case $revision in
89497b5038d7SDag-Erling Smørgrav	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]) ;;
89507b5038d7SDag-Erling Smørgrav	*)
8951986ba33cSDag-Erling Smørgrav	  func_error "REVISION '$revision' must be a nonnegative integer"
8952986ba33cSDag-Erling Smørgrav	  func_fatal_error "'$vinfo' is not valid version information"
89537b5038d7SDag-Erling Smørgrav	  ;;
89547b5038d7SDag-Erling Smørgrav	esac
89557b5038d7SDag-Erling Smørgrav
89567b5038d7SDag-Erling Smørgrav	case $age in
89577b5038d7SDag-Erling Smørgrav	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]) ;;
89587b5038d7SDag-Erling Smørgrav	*)
8959986ba33cSDag-Erling Smørgrav	  func_error "AGE '$age' must be a nonnegative integer"
8960986ba33cSDag-Erling Smørgrav	  func_fatal_error "'$vinfo' is not valid version information"
89617b5038d7SDag-Erling Smørgrav	  ;;
89627b5038d7SDag-Erling Smørgrav	esac
89637b5038d7SDag-Erling Smørgrav
89647b5038d7SDag-Erling Smørgrav	if test "$age" -gt "$current"; then
8965986ba33cSDag-Erling Smørgrav	  func_error "AGE '$age' is greater than the current interface number '$current'"
8966986ba33cSDag-Erling Smørgrav	  func_fatal_error "'$vinfo' is not valid version information"
89677b5038d7SDag-Erling Smørgrav	fi
89687b5038d7SDag-Erling Smørgrav
89697b5038d7SDag-Erling Smørgrav	# Calculate the version variables.
89707b5038d7SDag-Erling Smørgrav	major=
89717b5038d7SDag-Erling Smørgrav	versuffix=
89727b5038d7SDag-Erling Smørgrav	verstring=
89737b5038d7SDag-Erling Smørgrav	case $version_type in
89747b5038d7SDag-Erling Smørgrav	none) ;;
89757b5038d7SDag-Erling Smørgrav
89767b5038d7SDag-Erling Smørgrav	darwin)
89777b5038d7SDag-Erling Smørgrav	  # Like Linux, but with the current version available in
89787b5038d7SDag-Erling Smørgrav	  # verstring for coding it into the library header
89797b5038d7SDag-Erling Smørgrav	  func_arith $current - $age
89807b5038d7SDag-Erling Smørgrav	  major=.$func_arith_result
8981986ba33cSDag-Erling Smørgrav	  versuffix=$major.$age.$revision
89827b5038d7SDag-Erling Smørgrav	  # Darwin ld doesn't like 0 for these options...
89837b5038d7SDag-Erling Smørgrav	  func_arith $current + 1
89847b5038d7SDag-Erling Smørgrav	  minor_current=$func_arith_result
8985986ba33cSDag-Erling Smørgrav	  xlcverstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
89867b5038d7SDag-Erling Smørgrav	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8987986ba33cSDag-Erling Smørgrav          # On Darwin other compilers
8988986ba33cSDag-Erling Smørgrav          case $CC in
8989986ba33cSDag-Erling Smørgrav              nagfor*)
8990986ba33cSDag-Erling Smørgrav                  verstring="$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision"
8991986ba33cSDag-Erling Smørgrav                  ;;
8992986ba33cSDag-Erling Smørgrav              *)
8993986ba33cSDag-Erling Smørgrav                  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
8994986ba33cSDag-Erling Smørgrav                  ;;
8995986ba33cSDag-Erling Smørgrav          esac
89967b5038d7SDag-Erling Smørgrav	  ;;
89977b5038d7SDag-Erling Smørgrav
89987b5038d7SDag-Erling Smørgrav	freebsd-aout)
8999986ba33cSDag-Erling Smørgrav	  major=.$current
9000986ba33cSDag-Erling Smørgrav	  versuffix=.$current.$revision
90017b5038d7SDag-Erling Smørgrav	  ;;
90027b5038d7SDag-Erling Smørgrav
90037b5038d7SDag-Erling Smørgrav	freebsd-elf)
9004986ba33cSDag-Erling Smørgrav	  func_arith $current - $age
9005986ba33cSDag-Erling Smørgrav	  major=.$func_arith_result
9006986ba33cSDag-Erling Smørgrav	  versuffix=$major.$age.$revision
90077b5038d7SDag-Erling Smørgrav	  ;;
90087b5038d7SDag-Erling Smørgrav
90097b5038d7SDag-Erling Smørgrav	irix | nonstopux)
9010986ba33cSDag-Erling Smørgrav	  if test no = "$lt_irix_increment"; then
90117b5038d7SDag-Erling Smørgrav	    func_arith $current - $age
90127b5038d7SDag-Erling Smørgrav	  else
90137b5038d7SDag-Erling Smørgrav	    func_arith $current - $age + 1
90147b5038d7SDag-Erling Smørgrav	  fi
90157b5038d7SDag-Erling Smørgrav	  major=$func_arith_result
90167b5038d7SDag-Erling Smørgrav
90177b5038d7SDag-Erling Smørgrav	  case $version_type in
90187b5038d7SDag-Erling Smørgrav	    nonstopux) verstring_prefix=nonstopux ;;
90197b5038d7SDag-Erling Smørgrav	    *)         verstring_prefix=sgi ;;
90207b5038d7SDag-Erling Smørgrav	  esac
9021986ba33cSDag-Erling Smørgrav	  verstring=$verstring_prefix$major.$revision
90227b5038d7SDag-Erling Smørgrav
90237b5038d7SDag-Erling Smørgrav	  # Add in all the interfaces that we are compatible with.
90247b5038d7SDag-Erling Smørgrav	  loop=$revision
9025986ba33cSDag-Erling Smørgrav	  while test 0 -ne "$loop"; do
90267b5038d7SDag-Erling Smørgrav	    func_arith $revision - $loop
90277b5038d7SDag-Erling Smørgrav	    iface=$func_arith_result
90287b5038d7SDag-Erling Smørgrav	    func_arith $loop - 1
90297b5038d7SDag-Erling Smørgrav	    loop=$func_arith_result
9030986ba33cSDag-Erling Smørgrav	    verstring=$verstring_prefix$major.$iface:$verstring
90317b5038d7SDag-Erling Smørgrav	  done
90327b5038d7SDag-Erling Smørgrav
9033986ba33cSDag-Erling Smørgrav	  # Before this point, $major must not contain '.'.
90347b5038d7SDag-Erling Smørgrav	  major=.$major
9035986ba33cSDag-Erling Smørgrav	  versuffix=$major.$revision
90367b5038d7SDag-Erling Smørgrav	  ;;
90377b5038d7SDag-Erling Smørgrav
90387b5038d7SDag-Erling Smørgrav	linux) # correct to gnu/linux during the next big refactor
90397b5038d7SDag-Erling Smørgrav	  func_arith $current - $age
90407b5038d7SDag-Erling Smørgrav	  major=.$func_arith_result
9041986ba33cSDag-Erling Smørgrav	  versuffix=$major.$age.$revision
90427b5038d7SDag-Erling Smørgrav	  ;;
90437b5038d7SDag-Erling Smørgrav
90447b5038d7SDag-Erling Smørgrav	osf)
90457b5038d7SDag-Erling Smørgrav	  func_arith $current - $age
90467b5038d7SDag-Erling Smørgrav	  major=.$func_arith_result
9047986ba33cSDag-Erling Smørgrav	  versuffix=.$current.$age.$revision
9048986ba33cSDag-Erling Smørgrav	  verstring=$current.$age.$revision
90497b5038d7SDag-Erling Smørgrav
90507b5038d7SDag-Erling Smørgrav	  # Add in all the interfaces that we are compatible with.
90517b5038d7SDag-Erling Smørgrav	  loop=$age
9052986ba33cSDag-Erling Smørgrav	  while test 0 -ne "$loop"; do
90537b5038d7SDag-Erling Smørgrav	    func_arith $current - $loop
90547b5038d7SDag-Erling Smørgrav	    iface=$func_arith_result
90557b5038d7SDag-Erling Smørgrav	    func_arith $loop - 1
90567b5038d7SDag-Erling Smørgrav	    loop=$func_arith_result
9057986ba33cSDag-Erling Smørgrav	    verstring=$verstring:$iface.0
90587b5038d7SDag-Erling Smørgrav	  done
90597b5038d7SDag-Erling Smørgrav
90607b5038d7SDag-Erling Smørgrav	  # Make executables depend on our current version.
9061986ba33cSDag-Erling Smørgrav	  func_append verstring ":$current.0"
90627b5038d7SDag-Erling Smørgrav	  ;;
90637b5038d7SDag-Erling Smørgrav
90647b5038d7SDag-Erling Smørgrav	qnx)
9065986ba33cSDag-Erling Smørgrav	  major=.$current
9066986ba33cSDag-Erling Smørgrav	  versuffix=.$current
9067986ba33cSDag-Erling Smørgrav	  ;;
9068986ba33cSDag-Erling Smørgrav
9069986ba33cSDag-Erling Smørgrav	sco)
9070986ba33cSDag-Erling Smørgrav	  major=.$current
9071986ba33cSDag-Erling Smørgrav	  versuffix=.$current
90727b5038d7SDag-Erling Smørgrav	  ;;
90737b5038d7SDag-Erling Smørgrav
90747b5038d7SDag-Erling Smørgrav	sunos)
9075986ba33cSDag-Erling Smørgrav	  major=.$current
9076986ba33cSDag-Erling Smørgrav	  versuffix=.$current.$revision
90777b5038d7SDag-Erling Smørgrav	  ;;
90787b5038d7SDag-Erling Smørgrav
90797b5038d7SDag-Erling Smørgrav	windows)
90807b5038d7SDag-Erling Smørgrav	  # Use '-' rather than '.', since we only want one
90817b5038d7SDag-Erling Smørgrav	  # extension on DOS 8.3 file systems.
90827b5038d7SDag-Erling Smørgrav	  func_arith $current - $age
90837b5038d7SDag-Erling Smørgrav	  major=$func_arith_result
9084986ba33cSDag-Erling Smørgrav	  versuffix=-$major
90857b5038d7SDag-Erling Smørgrav	  ;;
90867b5038d7SDag-Erling Smørgrav
90877b5038d7SDag-Erling Smørgrav	*)
9088986ba33cSDag-Erling Smørgrav	  func_fatal_configuration "unknown library version type '$version_type'"
90897b5038d7SDag-Erling Smørgrav	  ;;
90907b5038d7SDag-Erling Smørgrav	esac
90917b5038d7SDag-Erling Smørgrav
90927b5038d7SDag-Erling Smørgrav	# Clear the version info if we defaulted, and they specified a release.
90937b5038d7SDag-Erling Smørgrav	if test -z "$vinfo" && test -n "$release"; then
90947b5038d7SDag-Erling Smørgrav	  major=
90957b5038d7SDag-Erling Smørgrav	  case $version_type in
90967b5038d7SDag-Erling Smørgrav	  darwin)
90977b5038d7SDag-Erling Smørgrav	    # we can't check for "0.0" in archive_cmds due to quoting
90987b5038d7SDag-Erling Smørgrav	    # problems, so we reset it completely
90997b5038d7SDag-Erling Smørgrav	    verstring=
91007b5038d7SDag-Erling Smørgrav	    ;;
91017b5038d7SDag-Erling Smørgrav	  *)
9102986ba33cSDag-Erling Smørgrav	    verstring=0.0
91037b5038d7SDag-Erling Smørgrav	    ;;
91047b5038d7SDag-Erling Smørgrav	  esac
9105986ba33cSDag-Erling Smørgrav	  if test no = "$need_version"; then
91067b5038d7SDag-Erling Smørgrav	    versuffix=
91077b5038d7SDag-Erling Smørgrav	  else
9108986ba33cSDag-Erling Smørgrav	    versuffix=.0.0
91097b5038d7SDag-Erling Smørgrav	  fi
91107b5038d7SDag-Erling Smørgrav	fi
91117b5038d7SDag-Erling Smørgrav
91127b5038d7SDag-Erling Smørgrav	# Remove version info from name if versioning should be avoided
9113986ba33cSDag-Erling Smørgrav	if test yes,no = "$avoid_version,$need_version"; then
91147b5038d7SDag-Erling Smørgrav	  major=
91157b5038d7SDag-Erling Smørgrav	  versuffix=
9116986ba33cSDag-Erling Smørgrav	  verstring=
91177b5038d7SDag-Erling Smørgrav	fi
91187b5038d7SDag-Erling Smørgrav
91197b5038d7SDag-Erling Smørgrav	# Check to see if the archive will have undefined symbols.
9120986ba33cSDag-Erling Smørgrav	if test yes = "$allow_undefined"; then
9121986ba33cSDag-Erling Smørgrav	  if test unsupported = "$allow_undefined_flag"; then
9122986ba33cSDag-Erling Smørgrav	    if test yes = "$build_old_libs"; then
9123986ba33cSDag-Erling Smørgrav	      func_warning "undefined symbols not allowed in $host shared libraries; building static only"
91247b5038d7SDag-Erling Smørgrav	      build_libtool_libs=no
9125986ba33cSDag-Erling Smørgrav	    else
9126986ba33cSDag-Erling Smørgrav	      func_fatal_error "can't build $host shared library unless -no-undefined is specified"
9127986ba33cSDag-Erling Smørgrav	    fi
91287b5038d7SDag-Erling Smørgrav	  fi
91297b5038d7SDag-Erling Smørgrav	else
91307b5038d7SDag-Erling Smørgrav	  # Don't allow undefined symbols.
9131986ba33cSDag-Erling Smørgrav	  allow_undefined_flag=$no_undefined_flag
91327b5038d7SDag-Erling Smørgrav	fi
91337b5038d7SDag-Erling Smørgrav
91347b5038d7SDag-Erling Smørgrav      fi
91357b5038d7SDag-Erling Smørgrav
9136986ba33cSDag-Erling Smørgrav      func_generate_dlsyms "$libname" "$libname" :
91377b5038d7SDag-Erling Smørgrav      func_append libobjs " $symfileobj"
9138986ba33cSDag-Erling Smørgrav      test " " = "$libobjs" && libobjs=
91397b5038d7SDag-Erling Smørgrav
9140986ba33cSDag-Erling Smørgrav      if test relink != "$opt_mode"; then
91417b5038d7SDag-Erling Smørgrav	# Remove our outputs, but don't remove object files since they
91427b5038d7SDag-Erling Smørgrav	# may have been created when compiling PIC objects.
91437b5038d7SDag-Erling Smørgrav	removelist=
91447b5038d7SDag-Erling Smørgrav	tempremovelist=`$ECHO "$output_objdir/*"`
91457b5038d7SDag-Erling Smørgrav	for p in $tempremovelist; do
91467b5038d7SDag-Erling Smørgrav	  case $p in
91477b5038d7SDag-Erling Smørgrav	    *.$objext | *.gcno)
91487b5038d7SDag-Erling Smørgrav	       ;;
9149986ba33cSDag-Erling Smørgrav	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)
9150986ba33cSDag-Erling Smørgrav	       if test -n "$precious_files_regex"; then
91517b5038d7SDag-Erling Smørgrav		 if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
91527b5038d7SDag-Erling Smørgrav		 then
91537b5038d7SDag-Erling Smørgrav		   continue
91547b5038d7SDag-Erling Smørgrav		 fi
91557b5038d7SDag-Erling Smørgrav	       fi
91567b5038d7SDag-Erling Smørgrav	       func_append removelist " $p"
91577b5038d7SDag-Erling Smørgrav	       ;;
91587b5038d7SDag-Erling Smørgrav	    *) ;;
91597b5038d7SDag-Erling Smørgrav	  esac
91607b5038d7SDag-Erling Smørgrav	done
91617b5038d7SDag-Erling Smørgrav	test -n "$removelist" && \
91627b5038d7SDag-Erling Smørgrav	  func_show_eval "${RM}r \$removelist"
91637b5038d7SDag-Erling Smørgrav      fi
91647b5038d7SDag-Erling Smørgrav
91657b5038d7SDag-Erling Smørgrav      # Now set the variables for building old libraries.
9166986ba33cSDag-Erling Smørgrav      if test yes = "$build_old_libs" && test convenience != "$build_libtool_libs"; then
91677b5038d7SDag-Erling Smørgrav	func_append oldlibs " $output_objdir/$libname.$libext"
91687b5038d7SDag-Erling Smørgrav
91697b5038d7SDag-Erling Smørgrav	# Transform .lo files to .o files.
9170986ba33cSDag-Erling Smørgrav	oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; $lo2o" | $NL2SP`
91717b5038d7SDag-Erling Smørgrav      fi
91727b5038d7SDag-Erling Smørgrav
91737b5038d7SDag-Erling Smørgrav      # Eliminate all temporary directories.
91747b5038d7SDag-Erling Smørgrav      #for path in $notinst_path; do
91757b5038d7SDag-Erling Smørgrav      #	lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"`
91767b5038d7SDag-Erling Smørgrav      #	deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"`
91777b5038d7SDag-Erling Smørgrav      #	dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"`
91787b5038d7SDag-Erling Smørgrav      #done
91797b5038d7SDag-Erling Smørgrav
91807b5038d7SDag-Erling Smørgrav      if test -n "$xrpath"; then
91817b5038d7SDag-Erling Smørgrav	# If the user specified any rpath flags, then add them.
91827b5038d7SDag-Erling Smørgrav	temp_xrpath=
91837b5038d7SDag-Erling Smørgrav	for libdir in $xrpath; do
91847b5038d7SDag-Erling Smørgrav	  func_replace_sysroot "$libdir"
91857b5038d7SDag-Erling Smørgrav	  func_append temp_xrpath " -R$func_replace_sysroot_result"
91867b5038d7SDag-Erling Smørgrav	  case "$finalize_rpath " in
91877b5038d7SDag-Erling Smørgrav	  *" $libdir "*) ;;
91887b5038d7SDag-Erling Smørgrav	  *) func_append finalize_rpath " $libdir" ;;
91897b5038d7SDag-Erling Smørgrav	  esac
91907b5038d7SDag-Erling Smørgrav	done
9191986ba33cSDag-Erling Smørgrav	if test yes != "$hardcode_into_libs" || test yes = "$build_old_libs"; then
91927b5038d7SDag-Erling Smørgrav	  dependency_libs="$temp_xrpath $dependency_libs"
91937b5038d7SDag-Erling Smørgrav	fi
91947b5038d7SDag-Erling Smørgrav      fi
91957b5038d7SDag-Erling Smørgrav
91967b5038d7SDag-Erling Smørgrav      # Make sure dlfiles contains only unique files that won't be dlpreopened
9197986ba33cSDag-Erling Smørgrav      old_dlfiles=$dlfiles
91987b5038d7SDag-Erling Smørgrav      dlfiles=
91997b5038d7SDag-Erling Smørgrav      for lib in $old_dlfiles; do
92007b5038d7SDag-Erling Smørgrav	case " $dlprefiles $dlfiles " in
92017b5038d7SDag-Erling Smørgrav	*" $lib "*) ;;
92027b5038d7SDag-Erling Smørgrav	*) func_append dlfiles " $lib" ;;
92037b5038d7SDag-Erling Smørgrav	esac
92047b5038d7SDag-Erling Smørgrav      done
92057b5038d7SDag-Erling Smørgrav
92067b5038d7SDag-Erling Smørgrav      # Make sure dlprefiles contains only unique files
9207986ba33cSDag-Erling Smørgrav      old_dlprefiles=$dlprefiles
92087b5038d7SDag-Erling Smørgrav      dlprefiles=
92097b5038d7SDag-Erling Smørgrav      for lib in $old_dlprefiles; do
92107b5038d7SDag-Erling Smørgrav	case "$dlprefiles " in
92117b5038d7SDag-Erling Smørgrav	*" $lib "*) ;;
92127b5038d7SDag-Erling Smørgrav	*) func_append dlprefiles " $lib" ;;
92137b5038d7SDag-Erling Smørgrav	esac
92147b5038d7SDag-Erling Smørgrav      done
92157b5038d7SDag-Erling Smørgrav
9216986ba33cSDag-Erling Smørgrav      if test yes = "$build_libtool_libs"; then
92177b5038d7SDag-Erling Smørgrav	if test -n "$rpath"; then
92187b5038d7SDag-Erling Smørgrav	  case $host in
92197b5038d7SDag-Erling Smørgrav	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)
92207b5038d7SDag-Erling Smørgrav	    # these systems don't actually have a c library (as such)!
92217b5038d7SDag-Erling Smørgrav	    ;;
92227b5038d7SDag-Erling Smørgrav	  *-*-rhapsody* | *-*-darwin1.[012])
92237b5038d7SDag-Erling Smørgrav	    # Rhapsody C library is in the System framework
92247b5038d7SDag-Erling Smørgrav	    func_append deplibs " System.ltframework"
92257b5038d7SDag-Erling Smørgrav	    ;;
92267b5038d7SDag-Erling Smørgrav	  *-*-netbsd*)
92277b5038d7SDag-Erling Smørgrav	    # Don't link with libc until the a.out ld.so is fixed.
92287b5038d7SDag-Erling Smørgrav	    ;;
92297b5038d7SDag-Erling Smørgrav	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
92307b5038d7SDag-Erling Smørgrav	    # Do not include libc due to us having libc/libc_r.
92317b5038d7SDag-Erling Smørgrav	    ;;
92327b5038d7SDag-Erling Smørgrav	  *-*-sco3.2v5* | *-*-sco5v6*)
92337b5038d7SDag-Erling Smørgrav	    # Causes problems with __ctype
92347b5038d7SDag-Erling Smørgrav	    ;;
92357b5038d7SDag-Erling Smørgrav	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
92367b5038d7SDag-Erling Smørgrav	    # Compiler inserts libc in the correct place for threads to work
92377b5038d7SDag-Erling Smørgrav	    ;;
92387b5038d7SDag-Erling Smørgrav	  *)
92397b5038d7SDag-Erling Smørgrav	    # Add libc to deplibs on all other systems if necessary.
9240986ba33cSDag-Erling Smørgrav	    if test yes = "$build_libtool_need_lc"; then
92417b5038d7SDag-Erling Smørgrav	      func_append deplibs " -lc"
92427b5038d7SDag-Erling Smørgrav	    fi
92437b5038d7SDag-Erling Smørgrav	    ;;
92447b5038d7SDag-Erling Smørgrav	  esac
92457b5038d7SDag-Erling Smørgrav	fi
92467b5038d7SDag-Erling Smørgrav
92477b5038d7SDag-Erling Smørgrav	# Transform deplibs into only deplibs that can be linked in shared.
92487b5038d7SDag-Erling Smørgrav	name_save=$name
92497b5038d7SDag-Erling Smørgrav	libname_save=$libname
92507b5038d7SDag-Erling Smørgrav	release_save=$release
92517b5038d7SDag-Erling Smørgrav	versuffix_save=$versuffix
92527b5038d7SDag-Erling Smørgrav	major_save=$major
92537b5038d7SDag-Erling Smørgrav	# I'm not sure if I'm treating the release correctly.  I think
92547b5038d7SDag-Erling Smørgrav	# release should show up in the -l (ie -lgmp5) so we don't want to
92557b5038d7SDag-Erling Smørgrav	# add it in twice.  Is that correct?
9256986ba33cSDag-Erling Smørgrav	release=
9257986ba33cSDag-Erling Smørgrav	versuffix=
9258986ba33cSDag-Erling Smørgrav	major=
92597b5038d7SDag-Erling Smørgrav	newdeplibs=
92607b5038d7SDag-Erling Smørgrav	droppeddeps=no
92617b5038d7SDag-Erling Smørgrav	case $deplibs_check_method in
92627b5038d7SDag-Erling Smørgrav	pass_all)
92637b5038d7SDag-Erling Smørgrav	  # Don't check for shared/static.  Everything works.
92647b5038d7SDag-Erling Smørgrav	  # This might be a little naive.  We might want to check
92657b5038d7SDag-Erling Smørgrav	  # whether the library exists or not.  But this is on
92667b5038d7SDag-Erling Smørgrav	  # osf3 & osf4 and I'm not really sure... Just
92677b5038d7SDag-Erling Smørgrav	  # implementing what was already the behavior.
92687b5038d7SDag-Erling Smørgrav	  newdeplibs=$deplibs
92697b5038d7SDag-Erling Smørgrav	  ;;
92707b5038d7SDag-Erling Smørgrav	test_compile)
92717b5038d7SDag-Erling Smørgrav	  # This code stresses the "libraries are programs" paradigm to its
92727b5038d7SDag-Erling Smørgrav	  # limits. Maybe even breaks it.  We compile a program, linking it
92737b5038d7SDag-Erling Smørgrav	  # against the deplibs as a proxy for the library.  Then we can check
92747b5038d7SDag-Erling Smørgrav	  # whether they linked in statically or dynamically with ldd.
92757b5038d7SDag-Erling Smørgrav	  $opt_dry_run || $RM conftest.c
92767b5038d7SDag-Erling Smørgrav	  cat > conftest.c <<EOF
92777b5038d7SDag-Erling Smørgrav	  int main() { return 0; }
92787b5038d7SDag-Erling SmørgravEOF
92797b5038d7SDag-Erling Smørgrav	  $opt_dry_run || $RM conftest
92807b5038d7SDag-Erling Smørgrav	  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then
92817b5038d7SDag-Erling Smørgrav	    ldd_output=`ldd conftest`
92827b5038d7SDag-Erling Smørgrav	    for i in $deplibs; do
92837b5038d7SDag-Erling Smørgrav	      case $i in
92847b5038d7SDag-Erling Smørgrav	      -l*)
92857b5038d7SDag-Erling Smørgrav		func_stripname -l '' "$i"
92867b5038d7SDag-Erling Smørgrav		name=$func_stripname_result
9287986ba33cSDag-Erling Smørgrav		if test yes = "$allow_libtool_libs_with_static_runtimes"; then
92887b5038d7SDag-Erling Smørgrav		  case " $predeps $postdeps " in
92897b5038d7SDag-Erling Smørgrav		  *" $i "*)
92907b5038d7SDag-Erling Smørgrav		    func_append newdeplibs " $i"
9291986ba33cSDag-Erling Smørgrav		    i=
92927b5038d7SDag-Erling Smørgrav		    ;;
92937b5038d7SDag-Erling Smørgrav		  esac
92947b5038d7SDag-Erling Smørgrav		fi
92957b5038d7SDag-Erling Smørgrav		if test -n "$i"; then
92967b5038d7SDag-Erling Smørgrav		  libname=`eval "\\$ECHO \"$libname_spec\""`
92977b5038d7SDag-Erling Smørgrav		  deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
92987b5038d7SDag-Erling Smørgrav		  set dummy $deplib_matches; shift
92997b5038d7SDag-Erling Smørgrav		  deplib_match=$1
93007b5038d7SDag-Erling Smørgrav		  if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
93017b5038d7SDag-Erling Smørgrav		    func_append newdeplibs " $i"
93027b5038d7SDag-Erling Smørgrav		  else
93037b5038d7SDag-Erling Smørgrav		    droppeddeps=yes
93047b5038d7SDag-Erling Smørgrav		    echo
93057b5038d7SDag-Erling Smørgrav		    $ECHO "*** Warning: dynamic linker does not accept needed library $i."
93067b5038d7SDag-Erling Smørgrav		    echo "*** I have the capability to make that library automatically link in when"
93077b5038d7SDag-Erling Smørgrav		    echo "*** you link to this library.  But I can only do this if you have a"
93087b5038d7SDag-Erling Smørgrav		    echo "*** shared version of the library, which I believe you do not have"
93097b5038d7SDag-Erling Smørgrav		    echo "*** because a test_compile did reveal that the linker did not use it for"
93107b5038d7SDag-Erling Smørgrav		    echo "*** its dynamic dependency list that programs get resolved with at runtime."
93117b5038d7SDag-Erling Smørgrav		  fi
93127b5038d7SDag-Erling Smørgrav		fi
93137b5038d7SDag-Erling Smørgrav		;;
93147b5038d7SDag-Erling Smørgrav	      *)
93157b5038d7SDag-Erling Smørgrav		func_append newdeplibs " $i"
93167b5038d7SDag-Erling Smørgrav		;;
93177b5038d7SDag-Erling Smørgrav	      esac
93187b5038d7SDag-Erling Smørgrav	    done
93197b5038d7SDag-Erling Smørgrav	  else
93207b5038d7SDag-Erling Smørgrav	    # Error occurred in the first compile.  Let's try to salvage
93217b5038d7SDag-Erling Smørgrav	    # the situation: Compile a separate program for each library.
93227b5038d7SDag-Erling Smørgrav	    for i in $deplibs; do
93237b5038d7SDag-Erling Smørgrav	      case $i in
93247b5038d7SDag-Erling Smørgrav	      -l*)
93257b5038d7SDag-Erling Smørgrav		func_stripname -l '' "$i"
93267b5038d7SDag-Erling Smørgrav		name=$func_stripname_result
93277b5038d7SDag-Erling Smørgrav		$opt_dry_run || $RM conftest
93287b5038d7SDag-Erling Smørgrav		if $LTCC $LTCFLAGS -o conftest conftest.c $i; then
93297b5038d7SDag-Erling Smørgrav		  ldd_output=`ldd conftest`
9330986ba33cSDag-Erling Smørgrav		  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
93317b5038d7SDag-Erling Smørgrav		    case " $predeps $postdeps " in
93327b5038d7SDag-Erling Smørgrav		    *" $i "*)
93337b5038d7SDag-Erling Smørgrav		      func_append newdeplibs " $i"
9334986ba33cSDag-Erling Smørgrav		      i=
93357b5038d7SDag-Erling Smørgrav		      ;;
93367b5038d7SDag-Erling Smørgrav		    esac
93377b5038d7SDag-Erling Smørgrav		  fi
93387b5038d7SDag-Erling Smørgrav		  if test -n "$i"; then
93397b5038d7SDag-Erling Smørgrav		    libname=`eval "\\$ECHO \"$libname_spec\""`
93407b5038d7SDag-Erling Smørgrav		    deplib_matches=`eval "\\$ECHO \"$library_names_spec\""`
93417b5038d7SDag-Erling Smørgrav		    set dummy $deplib_matches; shift
93427b5038d7SDag-Erling Smørgrav		    deplib_match=$1
93437b5038d7SDag-Erling Smørgrav		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then
93447b5038d7SDag-Erling Smørgrav		      func_append newdeplibs " $i"
93457b5038d7SDag-Erling Smørgrav		    else
93467b5038d7SDag-Erling Smørgrav		      droppeddeps=yes
93477b5038d7SDag-Erling Smørgrav		      echo
93487b5038d7SDag-Erling Smørgrav		      $ECHO "*** Warning: dynamic linker does not accept needed library $i."
93497b5038d7SDag-Erling Smørgrav		      echo "*** I have the capability to make that library automatically link in when"
93507b5038d7SDag-Erling Smørgrav		      echo "*** you link to this library.  But I can only do this if you have a"
93517b5038d7SDag-Erling Smørgrav		      echo "*** shared version of the library, which you do not appear to have"
93527b5038d7SDag-Erling Smørgrav		      echo "*** because a test_compile did reveal that the linker did not use this one"
93537b5038d7SDag-Erling Smørgrav		      echo "*** as a dynamic dependency that programs can get resolved with at runtime."
93547b5038d7SDag-Erling Smørgrav		    fi
93557b5038d7SDag-Erling Smørgrav		  fi
93567b5038d7SDag-Erling Smørgrav		else
93577b5038d7SDag-Erling Smørgrav		  droppeddeps=yes
93587b5038d7SDag-Erling Smørgrav		  echo
93597b5038d7SDag-Erling Smørgrav		  $ECHO "*** Warning!  Library $i is needed by this library but I was not able to"
93607b5038d7SDag-Erling Smørgrav		  echo "*** make it link in!  You will probably need to install it or some"
93617b5038d7SDag-Erling Smørgrav		  echo "*** library that it depends on before this library will be fully"
93627b5038d7SDag-Erling Smørgrav		  echo "*** functional.  Installing it before continuing would be even better."
93637b5038d7SDag-Erling Smørgrav		fi
93647b5038d7SDag-Erling Smørgrav		;;
93657b5038d7SDag-Erling Smørgrav	      *)
93667b5038d7SDag-Erling Smørgrav		func_append newdeplibs " $i"
93677b5038d7SDag-Erling Smørgrav		;;
93687b5038d7SDag-Erling Smørgrav	      esac
93697b5038d7SDag-Erling Smørgrav	    done
93707b5038d7SDag-Erling Smørgrav	  fi
93717b5038d7SDag-Erling Smørgrav	  ;;
93727b5038d7SDag-Erling Smørgrav	file_magic*)
93737b5038d7SDag-Erling Smørgrav	  set dummy $deplibs_check_method; shift
93747b5038d7SDag-Erling Smørgrav	  file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
93757b5038d7SDag-Erling Smørgrav	  for a_deplib in $deplibs; do
93767b5038d7SDag-Erling Smørgrav	    case $a_deplib in
93777b5038d7SDag-Erling Smørgrav	    -l*)
93787b5038d7SDag-Erling Smørgrav	      func_stripname -l '' "$a_deplib"
93797b5038d7SDag-Erling Smørgrav	      name=$func_stripname_result
9380986ba33cSDag-Erling Smørgrav	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
93817b5038d7SDag-Erling Smørgrav		case " $predeps $postdeps " in
93827b5038d7SDag-Erling Smørgrav		*" $a_deplib "*)
93837b5038d7SDag-Erling Smørgrav		  func_append newdeplibs " $a_deplib"
9384986ba33cSDag-Erling Smørgrav		  a_deplib=
93857b5038d7SDag-Erling Smørgrav		  ;;
93867b5038d7SDag-Erling Smørgrav		esac
93877b5038d7SDag-Erling Smørgrav	      fi
93887b5038d7SDag-Erling Smørgrav	      if test -n "$a_deplib"; then
93897b5038d7SDag-Erling Smørgrav		libname=`eval "\\$ECHO \"$libname_spec\""`
93907b5038d7SDag-Erling Smørgrav		if test -n "$file_magic_glob"; then
93917b5038d7SDag-Erling Smørgrav		  libnameglob=`func_echo_all "$libname" | $SED -e $file_magic_glob`
93927b5038d7SDag-Erling Smørgrav		else
93937b5038d7SDag-Erling Smørgrav		  libnameglob=$libname
93947b5038d7SDag-Erling Smørgrav		fi
9395986ba33cSDag-Erling Smørgrav		test yes = "$want_nocaseglob" && nocaseglob=`shopt -p nocaseglob`
93967b5038d7SDag-Erling Smørgrav		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
9397986ba33cSDag-Erling Smørgrav		  if test yes = "$want_nocaseglob"; then
93987b5038d7SDag-Erling Smørgrav		    shopt -s nocaseglob
93997b5038d7SDag-Erling Smørgrav		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
94007b5038d7SDag-Erling Smørgrav		    $nocaseglob
94017b5038d7SDag-Erling Smørgrav		  else
94027b5038d7SDag-Erling Smørgrav		    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`
94037b5038d7SDag-Erling Smørgrav		  fi
94047b5038d7SDag-Erling Smørgrav		  for potent_lib in $potential_libs; do
94057b5038d7SDag-Erling Smørgrav		      # Follow soft links.
94067b5038d7SDag-Erling Smørgrav		      if ls -lLd "$potent_lib" 2>/dev/null |
94077b5038d7SDag-Erling Smørgrav			 $GREP " -> " >/dev/null; then
94087b5038d7SDag-Erling Smørgrav			continue
94097b5038d7SDag-Erling Smørgrav		      fi
94107b5038d7SDag-Erling Smørgrav		      # The statement above tries to avoid entering an
94117b5038d7SDag-Erling Smørgrav		      # endless loop below, in case of cyclic links.
94127b5038d7SDag-Erling Smørgrav		      # We might still enter an endless loop, since a link
94137b5038d7SDag-Erling Smørgrav		      # loop can be closed while we follow links,
94147b5038d7SDag-Erling Smørgrav		      # but so what?
9415986ba33cSDag-Erling Smørgrav		      potlib=$potent_lib
94167b5038d7SDag-Erling Smørgrav		      while test -h "$potlib" 2>/dev/null; do
9417986ba33cSDag-Erling Smørgrav			potliblink=`ls -ld $potlib | $SED 's/.* -> //'`
94187b5038d7SDag-Erling Smørgrav			case $potliblink in
9419986ba33cSDag-Erling Smørgrav			[\\/]* | [A-Za-z]:[\\/]*) potlib=$potliblink;;
9420986ba33cSDag-Erling Smørgrav			*) potlib=`$ECHO "$potlib" | $SED 's|[^/]*$||'`"$potliblink";;
94217b5038d7SDag-Erling Smørgrav			esac
94227b5038d7SDag-Erling Smørgrav		      done
94237b5038d7SDag-Erling Smørgrav		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null |
94247b5038d7SDag-Erling Smørgrav			 $SED -e 10q |
94257b5038d7SDag-Erling Smørgrav			 $EGREP "$file_magic_regex" > /dev/null; then
94267b5038d7SDag-Erling Smørgrav			func_append newdeplibs " $a_deplib"
9427986ba33cSDag-Erling Smørgrav			a_deplib=
94287b5038d7SDag-Erling Smørgrav			break 2
94297b5038d7SDag-Erling Smørgrav		      fi
94307b5038d7SDag-Erling Smørgrav		  done
94317b5038d7SDag-Erling Smørgrav		done
94327b5038d7SDag-Erling Smørgrav	      fi
94337b5038d7SDag-Erling Smørgrav	      if test -n "$a_deplib"; then
94347b5038d7SDag-Erling Smørgrav		droppeddeps=yes
94357b5038d7SDag-Erling Smørgrav		echo
94367b5038d7SDag-Erling Smørgrav		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
94377b5038d7SDag-Erling Smørgrav		echo "*** I have the capability to make that library automatically link in when"
94387b5038d7SDag-Erling Smørgrav		echo "*** you link to this library.  But I can only do this if you have a"
94397b5038d7SDag-Erling Smørgrav		echo "*** shared version of the library, which you do not appear to have"
94407b5038d7SDag-Erling Smørgrav		echo "*** because I did check the linker path looking for a file starting"
94417b5038d7SDag-Erling Smørgrav		if test -z "$potlib"; then
94427b5038d7SDag-Erling Smørgrav		  $ECHO "*** with $libname but no candidates were found. (...for file magic test)"
94437b5038d7SDag-Erling Smørgrav		else
94447b5038d7SDag-Erling Smørgrav		  $ECHO "*** with $libname and none of the candidates passed a file format test"
94457b5038d7SDag-Erling Smørgrav		  $ECHO "*** using a file magic. Last file checked: $potlib"
94467b5038d7SDag-Erling Smørgrav		fi
94477b5038d7SDag-Erling Smørgrav	      fi
94487b5038d7SDag-Erling Smørgrav	      ;;
94497b5038d7SDag-Erling Smørgrav	    *)
94507b5038d7SDag-Erling Smørgrav	      # Add a -L argument.
94517b5038d7SDag-Erling Smørgrav	      func_append newdeplibs " $a_deplib"
94527b5038d7SDag-Erling Smørgrav	      ;;
94537b5038d7SDag-Erling Smørgrav	    esac
94547b5038d7SDag-Erling Smørgrav	  done # Gone through all deplibs.
94557b5038d7SDag-Erling Smørgrav	  ;;
94567b5038d7SDag-Erling Smørgrav	match_pattern*)
94577b5038d7SDag-Erling Smørgrav	  set dummy $deplibs_check_method; shift
94587b5038d7SDag-Erling Smørgrav	  match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"`
94597b5038d7SDag-Erling Smørgrav	  for a_deplib in $deplibs; do
94607b5038d7SDag-Erling Smørgrav	    case $a_deplib in
94617b5038d7SDag-Erling Smørgrav	    -l*)
94627b5038d7SDag-Erling Smørgrav	      func_stripname -l '' "$a_deplib"
94637b5038d7SDag-Erling Smørgrav	      name=$func_stripname_result
9464986ba33cSDag-Erling Smørgrav	      if test yes = "$allow_libtool_libs_with_static_runtimes"; then
94657b5038d7SDag-Erling Smørgrav		case " $predeps $postdeps " in
94667b5038d7SDag-Erling Smørgrav		*" $a_deplib "*)
94677b5038d7SDag-Erling Smørgrav		  func_append newdeplibs " $a_deplib"
9468986ba33cSDag-Erling Smørgrav		  a_deplib=
94697b5038d7SDag-Erling Smørgrav		  ;;
94707b5038d7SDag-Erling Smørgrav		esac
94717b5038d7SDag-Erling Smørgrav	      fi
94727b5038d7SDag-Erling Smørgrav	      if test -n "$a_deplib"; then
94737b5038d7SDag-Erling Smørgrav		libname=`eval "\\$ECHO \"$libname_spec\""`
94747b5038d7SDag-Erling Smørgrav		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
94757b5038d7SDag-Erling Smørgrav		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
94767b5038d7SDag-Erling Smørgrav		  for potent_lib in $potential_libs; do
9477986ba33cSDag-Erling Smørgrav		    potlib=$potent_lib # see symlink-check above in file_magic test
94787b5038d7SDag-Erling Smørgrav		    if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \
94797b5038d7SDag-Erling Smørgrav		       $EGREP "$match_pattern_regex" > /dev/null; then
94807b5038d7SDag-Erling Smørgrav		      func_append newdeplibs " $a_deplib"
9481986ba33cSDag-Erling Smørgrav		      a_deplib=
94827b5038d7SDag-Erling Smørgrav		      break 2
94837b5038d7SDag-Erling Smørgrav		    fi
94847b5038d7SDag-Erling Smørgrav		  done
94857b5038d7SDag-Erling Smørgrav		done
94867b5038d7SDag-Erling Smørgrav	      fi
94877b5038d7SDag-Erling Smørgrav	      if test -n "$a_deplib"; then
94887b5038d7SDag-Erling Smørgrav		droppeddeps=yes
94897b5038d7SDag-Erling Smørgrav		echo
94907b5038d7SDag-Erling Smørgrav		$ECHO "*** Warning: linker path does not have real file for library $a_deplib."
94917b5038d7SDag-Erling Smørgrav		echo "*** I have the capability to make that library automatically link in when"
94927b5038d7SDag-Erling Smørgrav		echo "*** you link to this library.  But I can only do this if you have a"
94937b5038d7SDag-Erling Smørgrav		echo "*** shared version of the library, which you do not appear to have"
94947b5038d7SDag-Erling Smørgrav		echo "*** because I did check the linker path looking for a file starting"
94957b5038d7SDag-Erling Smørgrav		if test -z "$potlib"; then
94967b5038d7SDag-Erling Smørgrav		  $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)"
94977b5038d7SDag-Erling Smørgrav		else
94987b5038d7SDag-Erling Smørgrav		  $ECHO "*** with $libname and none of the candidates passed a file format test"
94997b5038d7SDag-Erling Smørgrav		  $ECHO "*** using a regex pattern. Last file checked: $potlib"
95007b5038d7SDag-Erling Smørgrav		fi
95017b5038d7SDag-Erling Smørgrav	      fi
95027b5038d7SDag-Erling Smørgrav	      ;;
95037b5038d7SDag-Erling Smørgrav	    *)
95047b5038d7SDag-Erling Smørgrav	      # Add a -L argument.
95057b5038d7SDag-Erling Smørgrav	      func_append newdeplibs " $a_deplib"
95067b5038d7SDag-Erling Smørgrav	      ;;
95077b5038d7SDag-Erling Smørgrav	    esac
95087b5038d7SDag-Erling Smørgrav	  done # Gone through all deplibs.
95097b5038d7SDag-Erling Smørgrav	  ;;
95107b5038d7SDag-Erling Smørgrav	none | unknown | *)
9511986ba33cSDag-Erling Smørgrav	  newdeplibs=
95127b5038d7SDag-Erling Smørgrav	  tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`
9513986ba33cSDag-Erling Smørgrav	  if test yes = "$allow_libtool_libs_with_static_runtimes"; then
95147b5038d7SDag-Erling Smørgrav	    for i in $predeps $postdeps; do
95157b5038d7SDag-Erling Smørgrav	      # can't use Xsed below, because $i might contain '/'
9516986ba33cSDag-Erling Smørgrav	      tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s|$i||"`
95177b5038d7SDag-Erling Smørgrav	    done
95187b5038d7SDag-Erling Smørgrav	  fi
95197b5038d7SDag-Erling Smørgrav	  case $tmp_deplibs in
95207b5038d7SDag-Erling Smørgrav	  *[!\	\ ]*)
95217b5038d7SDag-Erling Smørgrav	    echo
9522986ba33cSDag-Erling Smørgrav	    if test none = "$deplibs_check_method"; then
95237b5038d7SDag-Erling Smørgrav	      echo "*** Warning: inter-library dependencies are not supported in this platform."
95247b5038d7SDag-Erling Smørgrav	    else
95257b5038d7SDag-Erling Smørgrav	      echo "*** Warning: inter-library dependencies are not known to be supported."
95267b5038d7SDag-Erling Smørgrav	    fi
95277b5038d7SDag-Erling Smørgrav	    echo "*** All declared inter-library dependencies are being dropped."
95287b5038d7SDag-Erling Smørgrav	    droppeddeps=yes
95297b5038d7SDag-Erling Smørgrav	    ;;
95307b5038d7SDag-Erling Smørgrav	  esac
95317b5038d7SDag-Erling Smørgrav	  ;;
95327b5038d7SDag-Erling Smørgrav	esac
95337b5038d7SDag-Erling Smørgrav	versuffix=$versuffix_save
95347b5038d7SDag-Erling Smørgrav	major=$major_save
95357b5038d7SDag-Erling Smørgrav	release=$release_save
95367b5038d7SDag-Erling Smørgrav	libname=$libname_save
95377b5038d7SDag-Erling Smørgrav	name=$name_save
95387b5038d7SDag-Erling Smørgrav
95397b5038d7SDag-Erling Smørgrav	case $host in
95407b5038d7SDag-Erling Smørgrav	*-*-rhapsody* | *-*-darwin1.[012])
95417b5038d7SDag-Erling Smørgrav	  # On Rhapsody replace the C library with the System framework
95427b5038d7SDag-Erling Smørgrav	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'`
95437b5038d7SDag-Erling Smørgrav	  ;;
95447b5038d7SDag-Erling Smørgrav	esac
95457b5038d7SDag-Erling Smørgrav
9546986ba33cSDag-Erling Smørgrav	if test yes = "$droppeddeps"; then
9547986ba33cSDag-Erling Smørgrav	  if test yes = "$module"; then
95487b5038d7SDag-Erling Smørgrav	    echo
95497b5038d7SDag-Erling Smørgrav	    echo "*** Warning: libtool could not satisfy all declared inter-library"
95507b5038d7SDag-Erling Smørgrav	    $ECHO "*** dependencies of module $libname.  Therefore, libtool will create"
95517b5038d7SDag-Erling Smørgrav	    echo "*** a static module, that should work as long as the dlopening"
95527b5038d7SDag-Erling Smørgrav	    echo "*** application is linked with the -dlopen flag."
95537b5038d7SDag-Erling Smørgrav	    if test -z "$global_symbol_pipe"; then
95547b5038d7SDag-Erling Smørgrav	      echo
95557b5038d7SDag-Erling Smørgrav	      echo "*** However, this would only work if libtool was able to extract symbol"
9556986ba33cSDag-Erling Smørgrav	      echo "*** lists from a program, using 'nm' or equivalent, but libtool could"
95577b5038d7SDag-Erling Smørgrav	      echo "*** not find such a program.  So, this module is probably useless."
9558986ba33cSDag-Erling Smørgrav	      echo "*** 'nm' from GNU binutils and a full rebuild may help."
95597b5038d7SDag-Erling Smørgrav	    fi
9560986ba33cSDag-Erling Smørgrav	    if test no = "$build_old_libs"; then
9561986ba33cSDag-Erling Smørgrav	      oldlibs=$output_objdir/$libname.$libext
95627b5038d7SDag-Erling Smørgrav	      build_libtool_libs=module
95637b5038d7SDag-Erling Smørgrav	      build_old_libs=yes
95647b5038d7SDag-Erling Smørgrav	    else
95657b5038d7SDag-Erling Smørgrav	      build_libtool_libs=no
95667b5038d7SDag-Erling Smørgrav	    fi
95677b5038d7SDag-Erling Smørgrav	  else
95687b5038d7SDag-Erling Smørgrav	    echo "*** The inter-library dependencies that have been dropped here will be"
95697b5038d7SDag-Erling Smørgrav	    echo "*** automatically added whenever a program is linked with this library"
95707b5038d7SDag-Erling Smørgrav	    echo "*** or is declared to -dlopen it."
95717b5038d7SDag-Erling Smørgrav
9572986ba33cSDag-Erling Smørgrav	    if test no = "$allow_undefined"; then
95737b5038d7SDag-Erling Smørgrav	      echo
95747b5038d7SDag-Erling Smørgrav	      echo "*** Since this library must not contain undefined symbols,"
95757b5038d7SDag-Erling Smørgrav	      echo "*** because either the platform does not support them or"
95767b5038d7SDag-Erling Smørgrav	      echo "*** it was explicitly requested with -no-undefined,"
95777b5038d7SDag-Erling Smørgrav	      echo "*** libtool will only create a static version of it."
9578986ba33cSDag-Erling Smørgrav	      if test no = "$build_old_libs"; then
9579986ba33cSDag-Erling Smørgrav		oldlibs=$output_objdir/$libname.$libext
95807b5038d7SDag-Erling Smørgrav		build_libtool_libs=module
95817b5038d7SDag-Erling Smørgrav		build_old_libs=yes
95827b5038d7SDag-Erling Smørgrav	      else
95837b5038d7SDag-Erling Smørgrav		build_libtool_libs=no
95847b5038d7SDag-Erling Smørgrav	      fi
95857b5038d7SDag-Erling Smørgrav	    fi
95867b5038d7SDag-Erling Smørgrav	  fi
95877b5038d7SDag-Erling Smørgrav	fi
95887b5038d7SDag-Erling Smørgrav	# Done checking deplibs!
95897b5038d7SDag-Erling Smørgrav	deplibs=$newdeplibs
95907b5038d7SDag-Erling Smørgrav      fi
95917b5038d7SDag-Erling Smørgrav      # Time to change all our "foo.ltframework" stuff back to "-framework foo"
95927b5038d7SDag-Erling Smørgrav      case $host in
95937b5038d7SDag-Erling Smørgrav	*-*-darwin*)
95947b5038d7SDag-Erling Smørgrav	  newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
95957b5038d7SDag-Erling Smørgrav	  new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
95967b5038d7SDag-Erling Smørgrav	  deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
95977b5038d7SDag-Erling Smørgrav	  ;;
95987b5038d7SDag-Erling Smørgrav      esac
95997b5038d7SDag-Erling Smørgrav
96007b5038d7SDag-Erling Smørgrav      # move library search paths that coincide with paths to not yet
96017b5038d7SDag-Erling Smørgrav      # installed libraries to the beginning of the library search list
96027b5038d7SDag-Erling Smørgrav      new_libs=
96037b5038d7SDag-Erling Smørgrav      for path in $notinst_path; do
96047b5038d7SDag-Erling Smørgrav	case " $new_libs " in
96057b5038d7SDag-Erling Smørgrav	*" -L$path/$objdir "*) ;;
96067b5038d7SDag-Erling Smørgrav	*)
96077b5038d7SDag-Erling Smørgrav	  case " $deplibs " in
96087b5038d7SDag-Erling Smørgrav	  *" -L$path/$objdir "*)
96097b5038d7SDag-Erling Smørgrav	    func_append new_libs " -L$path/$objdir" ;;
96107b5038d7SDag-Erling Smørgrav	  esac
96117b5038d7SDag-Erling Smørgrav	  ;;
96127b5038d7SDag-Erling Smørgrav	esac
96137b5038d7SDag-Erling Smørgrav      done
96147b5038d7SDag-Erling Smørgrav      for deplib in $deplibs; do
96157b5038d7SDag-Erling Smørgrav	case $deplib in
96167b5038d7SDag-Erling Smørgrav	-L*)
96177b5038d7SDag-Erling Smørgrav	  case " $new_libs " in
96187b5038d7SDag-Erling Smørgrav	  *" $deplib "*) ;;
96197b5038d7SDag-Erling Smørgrav	  *) func_append new_libs " $deplib" ;;
96207b5038d7SDag-Erling Smørgrav	  esac
96217b5038d7SDag-Erling Smørgrav	  ;;
96227b5038d7SDag-Erling Smørgrav	*) func_append new_libs " $deplib" ;;
96237b5038d7SDag-Erling Smørgrav	esac
96247b5038d7SDag-Erling Smørgrav      done
9625986ba33cSDag-Erling Smørgrav      deplibs=$new_libs
96267b5038d7SDag-Erling Smørgrav
96277b5038d7SDag-Erling Smørgrav      # All the library-specific variables (install_libdir is set above).
96287b5038d7SDag-Erling Smørgrav      library_names=
96297b5038d7SDag-Erling Smørgrav      old_library=
96307b5038d7SDag-Erling Smørgrav      dlname=
96317b5038d7SDag-Erling Smørgrav
96327b5038d7SDag-Erling Smørgrav      # Test again, we may have decided not to build it any more
9633986ba33cSDag-Erling Smørgrav      if test yes = "$build_libtool_libs"; then
9634986ba33cSDag-Erling Smørgrav	# Remove $wl instances when linking with ld.
96357b5038d7SDag-Erling Smørgrav	# FIXME: should test the right _cmds variable.
96367b5038d7SDag-Erling Smørgrav	case $archive_cmds in
96377b5038d7SDag-Erling Smørgrav	  *\$LD\ *) wl= ;;
96387b5038d7SDag-Erling Smørgrav        esac
9639986ba33cSDag-Erling Smørgrav	if test yes = "$hardcode_into_libs"; then
96407b5038d7SDag-Erling Smørgrav	  # Hardcode the library paths
96417b5038d7SDag-Erling Smørgrav	  hardcode_libdirs=
96427b5038d7SDag-Erling Smørgrav	  dep_rpath=
9643986ba33cSDag-Erling Smørgrav	  rpath=$finalize_rpath
9644986ba33cSDag-Erling Smørgrav	  test relink = "$opt_mode" || rpath=$compile_rpath$rpath
96457b5038d7SDag-Erling Smørgrav	  for libdir in $rpath; do
96467b5038d7SDag-Erling Smørgrav	    if test -n "$hardcode_libdir_flag_spec"; then
96477b5038d7SDag-Erling Smørgrav	      if test -n "$hardcode_libdir_separator"; then
96487b5038d7SDag-Erling Smørgrav		func_replace_sysroot "$libdir"
96497b5038d7SDag-Erling Smørgrav		libdir=$func_replace_sysroot_result
96507b5038d7SDag-Erling Smørgrav		if test -z "$hardcode_libdirs"; then
9651986ba33cSDag-Erling Smørgrav		  hardcode_libdirs=$libdir
96527b5038d7SDag-Erling Smørgrav		else
96537b5038d7SDag-Erling Smørgrav		  # Just accumulate the unique libdirs.
96547b5038d7SDag-Erling Smørgrav		  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
96557b5038d7SDag-Erling Smørgrav		  *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
96567b5038d7SDag-Erling Smørgrav		    ;;
96577b5038d7SDag-Erling Smørgrav		  *)
96587b5038d7SDag-Erling Smørgrav		    func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
96597b5038d7SDag-Erling Smørgrav		    ;;
96607b5038d7SDag-Erling Smørgrav		  esac
96617b5038d7SDag-Erling Smørgrav		fi
96627b5038d7SDag-Erling Smørgrav	      else
96637b5038d7SDag-Erling Smørgrav		eval flag=\"$hardcode_libdir_flag_spec\"
96647b5038d7SDag-Erling Smørgrav		func_append dep_rpath " $flag"
96657b5038d7SDag-Erling Smørgrav	      fi
96667b5038d7SDag-Erling Smørgrav	    elif test -n "$runpath_var"; then
96677b5038d7SDag-Erling Smørgrav	      case "$perm_rpath " in
96687b5038d7SDag-Erling Smørgrav	      *" $libdir "*) ;;
96697b5038d7SDag-Erling Smørgrav	      *) func_append perm_rpath " $libdir" ;;
96707b5038d7SDag-Erling Smørgrav	      esac
96717b5038d7SDag-Erling Smørgrav	    fi
96727b5038d7SDag-Erling Smørgrav	  done
96737b5038d7SDag-Erling Smørgrav	  # Substitute the hardcoded libdirs into the rpath.
96747b5038d7SDag-Erling Smørgrav	  if test -n "$hardcode_libdir_separator" &&
96757b5038d7SDag-Erling Smørgrav	     test -n "$hardcode_libdirs"; then
9676986ba33cSDag-Erling Smørgrav	    libdir=$hardcode_libdirs
96777b5038d7SDag-Erling Smørgrav	    eval "dep_rpath=\"$hardcode_libdir_flag_spec\""
96787b5038d7SDag-Erling Smørgrav	  fi
96797b5038d7SDag-Erling Smørgrav	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
96807b5038d7SDag-Erling Smørgrav	    # We should set the runpath_var.
96817b5038d7SDag-Erling Smørgrav	    rpath=
96827b5038d7SDag-Erling Smørgrav	    for dir in $perm_rpath; do
96837b5038d7SDag-Erling Smørgrav	      func_append rpath "$dir:"
96847b5038d7SDag-Erling Smørgrav	    done
96857b5038d7SDag-Erling Smørgrav	    eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var"
96867b5038d7SDag-Erling Smørgrav	  fi
96877b5038d7SDag-Erling Smørgrav	  test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs"
96887b5038d7SDag-Erling Smørgrav	fi
96897b5038d7SDag-Erling Smørgrav
9690986ba33cSDag-Erling Smørgrav	shlibpath=$finalize_shlibpath
9691986ba33cSDag-Erling Smørgrav	test relink = "$opt_mode" || shlibpath=$compile_shlibpath$shlibpath
96927b5038d7SDag-Erling Smørgrav	if test -n "$shlibpath"; then
96937b5038d7SDag-Erling Smørgrav	  eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var"
96947b5038d7SDag-Erling Smørgrav	fi
96957b5038d7SDag-Erling Smørgrav
96967b5038d7SDag-Erling Smørgrav	# Get the real and link names of the library.
96977b5038d7SDag-Erling Smørgrav	eval shared_ext=\"$shrext_cmds\"
96987b5038d7SDag-Erling Smørgrav	eval library_names=\"$library_names_spec\"
96997b5038d7SDag-Erling Smørgrav	set dummy $library_names
97007b5038d7SDag-Erling Smørgrav	shift
9701986ba33cSDag-Erling Smørgrav	realname=$1
97027b5038d7SDag-Erling Smørgrav	shift
97037b5038d7SDag-Erling Smørgrav
97047b5038d7SDag-Erling Smørgrav	if test -n "$soname_spec"; then
97057b5038d7SDag-Erling Smørgrav	  eval soname=\"$soname_spec\"
97067b5038d7SDag-Erling Smørgrav	else
9707986ba33cSDag-Erling Smørgrav	  soname=$realname
97087b5038d7SDag-Erling Smørgrav	fi
97097b5038d7SDag-Erling Smørgrav	if test -z "$dlname"; then
97107b5038d7SDag-Erling Smørgrav	  dlname=$soname
97117b5038d7SDag-Erling Smørgrav	fi
97127b5038d7SDag-Erling Smørgrav
9713986ba33cSDag-Erling Smørgrav	lib=$output_objdir/$realname
97147b5038d7SDag-Erling Smørgrav	linknames=
97157b5038d7SDag-Erling Smørgrav	for link
97167b5038d7SDag-Erling Smørgrav	do
97177b5038d7SDag-Erling Smørgrav	  func_append linknames " $link"
97187b5038d7SDag-Erling Smørgrav	done
97197b5038d7SDag-Erling Smørgrav
97207b5038d7SDag-Erling Smørgrav	# Use standard objects if they are pic
97217b5038d7SDag-Erling Smørgrav	test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP`
97227b5038d7SDag-Erling Smørgrav	test "X$libobjs" = "X " && libobjs=
97237b5038d7SDag-Erling Smørgrav
97247b5038d7SDag-Erling Smørgrav	delfiles=
97257b5038d7SDag-Erling Smørgrav	if test -n "$export_symbols" && test -n "$include_expsyms"; then
97267b5038d7SDag-Erling Smørgrav	  $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp"
9727986ba33cSDag-Erling Smørgrav	  export_symbols=$output_objdir/$libname.uexp
97287b5038d7SDag-Erling Smørgrav	  func_append delfiles " $export_symbols"
97297b5038d7SDag-Erling Smørgrav	fi
97307b5038d7SDag-Erling Smørgrav
97317b5038d7SDag-Erling Smørgrav	orig_export_symbols=
97327b5038d7SDag-Erling Smørgrav	case $host_os in
97337b5038d7SDag-Erling Smørgrav	cygwin* | mingw* | cegcc*)
97347b5038d7SDag-Erling Smørgrav	  if test -n "$export_symbols" && test -z "$export_symbols_regex"; then
97357b5038d7SDag-Erling Smørgrav	    # exporting using user supplied symfile
9736986ba33cSDag-Erling Smørgrav	    func_dll_def_p "$export_symbols" || {
97377b5038d7SDag-Erling Smørgrav	      # and it's NOT already a .def file. Must figure out
97387b5038d7SDag-Erling Smørgrav	      # which of the given symbols are data symbols and tag
97397b5038d7SDag-Erling Smørgrav	      # them as such. So, trigger use of export_symbols_cmds.
97407b5038d7SDag-Erling Smørgrav	      # export_symbols gets reassigned inside the "prepare
97417b5038d7SDag-Erling Smørgrav	      # the list of exported symbols" if statement, so the
97427b5038d7SDag-Erling Smørgrav	      # include_expsyms logic still works.
9743986ba33cSDag-Erling Smørgrav	      orig_export_symbols=$export_symbols
97447b5038d7SDag-Erling Smørgrav	      export_symbols=
97457b5038d7SDag-Erling Smørgrav	      always_export_symbols=yes
9746986ba33cSDag-Erling Smørgrav	    }
97477b5038d7SDag-Erling Smørgrav	  fi
97487b5038d7SDag-Erling Smørgrav	  ;;
97497b5038d7SDag-Erling Smørgrav	esac
97507b5038d7SDag-Erling Smørgrav
97517b5038d7SDag-Erling Smørgrav	# Prepare the list of exported symbols
97527b5038d7SDag-Erling Smørgrav	if test -z "$export_symbols"; then
9753986ba33cSDag-Erling Smørgrav	  if test yes = "$always_export_symbols" || test -n "$export_symbols_regex"; then
9754986ba33cSDag-Erling Smørgrav	    func_verbose "generating symbol list for '$libname.la'"
9755986ba33cSDag-Erling Smørgrav	    export_symbols=$output_objdir/$libname.exp
97567b5038d7SDag-Erling Smørgrav	    $opt_dry_run || $RM $export_symbols
97577b5038d7SDag-Erling Smørgrav	    cmds=$export_symbols_cmds
9758986ba33cSDag-Erling Smørgrav	    save_ifs=$IFS; IFS='~'
97597b5038d7SDag-Erling Smørgrav	    for cmd1 in $cmds; do
9760986ba33cSDag-Erling Smørgrav	      IFS=$save_ifs
97617b5038d7SDag-Erling Smørgrav	      # Take the normal branch if the nm_file_list_spec branch
97627b5038d7SDag-Erling Smørgrav	      # doesn't work or if tool conversion is not needed.
97637b5038d7SDag-Erling Smørgrav	      case $nm_file_list_spec~$to_tool_file_cmd in
97647b5038d7SDag-Erling Smørgrav		*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)
97657b5038d7SDag-Erling Smørgrav		  try_normal_branch=yes
97667b5038d7SDag-Erling Smørgrav		  eval cmd=\"$cmd1\"
97677b5038d7SDag-Erling Smørgrav		  func_len " $cmd"
97687b5038d7SDag-Erling Smørgrav		  len=$func_len_result
97697b5038d7SDag-Erling Smørgrav		  ;;
97707b5038d7SDag-Erling Smørgrav		*)
97717b5038d7SDag-Erling Smørgrav		  try_normal_branch=no
97727b5038d7SDag-Erling Smørgrav		  ;;
97737b5038d7SDag-Erling Smørgrav	      esac
9774986ba33cSDag-Erling Smørgrav	      if test yes = "$try_normal_branch" \
97757b5038d7SDag-Erling Smørgrav		 && { test "$len" -lt "$max_cmd_len" \
97767b5038d7SDag-Erling Smørgrav		      || test "$max_cmd_len" -le -1; }
97777b5038d7SDag-Erling Smørgrav	      then
97787b5038d7SDag-Erling Smørgrav		func_show_eval "$cmd" 'exit $?'
97797b5038d7SDag-Erling Smørgrav		skipped_export=false
97807b5038d7SDag-Erling Smørgrav	      elif test -n "$nm_file_list_spec"; then
97817b5038d7SDag-Erling Smørgrav		func_basename "$output"
97827b5038d7SDag-Erling Smørgrav		output_la=$func_basename_result
97837b5038d7SDag-Erling Smørgrav		save_libobjs=$libobjs
97847b5038d7SDag-Erling Smørgrav		save_output=$output
9785986ba33cSDag-Erling Smørgrav		output=$output_objdir/$output_la.nm
97867b5038d7SDag-Erling Smørgrav		func_to_tool_file "$output"
97877b5038d7SDag-Erling Smørgrav		libobjs=$nm_file_list_spec$func_to_tool_file_result
97887b5038d7SDag-Erling Smørgrav		func_append delfiles " $output"
97897b5038d7SDag-Erling Smørgrav		func_verbose "creating $NM input file list: $output"
97907b5038d7SDag-Erling Smørgrav		for obj in $save_libobjs; do
97917b5038d7SDag-Erling Smørgrav		  func_to_tool_file "$obj"
97927b5038d7SDag-Erling Smørgrav		  $ECHO "$func_to_tool_file_result"
97937b5038d7SDag-Erling Smørgrav		done > "$output"
97947b5038d7SDag-Erling Smørgrav		eval cmd=\"$cmd1\"
97957b5038d7SDag-Erling Smørgrav		func_show_eval "$cmd" 'exit $?'
97967b5038d7SDag-Erling Smørgrav		output=$save_output
97977b5038d7SDag-Erling Smørgrav		libobjs=$save_libobjs
97987b5038d7SDag-Erling Smørgrav		skipped_export=false
97997b5038d7SDag-Erling Smørgrav	      else
98007b5038d7SDag-Erling Smørgrav		# The command line is too long to execute in one step.
98017b5038d7SDag-Erling Smørgrav		func_verbose "using reloadable object file for export list..."
98027b5038d7SDag-Erling Smørgrav		skipped_export=:
98037b5038d7SDag-Erling Smørgrav		# Break out early, otherwise skipped_export may be
98047b5038d7SDag-Erling Smørgrav		# set to false by a later but shorter cmd.
98057b5038d7SDag-Erling Smørgrav		break
98067b5038d7SDag-Erling Smørgrav	      fi
98077b5038d7SDag-Erling Smørgrav	    done
9808986ba33cSDag-Erling Smørgrav	    IFS=$save_ifs
9809986ba33cSDag-Erling Smørgrav	    if test -n "$export_symbols_regex" && test : != "$skipped_export"; then
98107b5038d7SDag-Erling Smørgrav	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
98117b5038d7SDag-Erling Smørgrav	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
98127b5038d7SDag-Erling Smørgrav	    fi
98137b5038d7SDag-Erling Smørgrav	  fi
98147b5038d7SDag-Erling Smørgrav	fi
98157b5038d7SDag-Erling Smørgrav
98167b5038d7SDag-Erling Smørgrav	if test -n "$export_symbols" && test -n "$include_expsyms"; then
9817986ba33cSDag-Erling Smørgrav	  tmp_export_symbols=$export_symbols
9818986ba33cSDag-Erling Smørgrav	  test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
98197b5038d7SDag-Erling Smørgrav	  $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
98207b5038d7SDag-Erling Smørgrav	fi
98217b5038d7SDag-Erling Smørgrav
9822986ba33cSDag-Erling Smørgrav	if test : != "$skipped_export" && test -n "$orig_export_symbols"; then
98237b5038d7SDag-Erling Smørgrav	  # The given exports_symbols file has to be filtered, so filter it.
9824986ba33cSDag-Erling Smørgrav	  func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
98257b5038d7SDag-Erling Smørgrav	  # FIXME: $output_objdir/$libname.filter potentially contains lots of
9826986ba33cSDag-Erling Smørgrav	  # 's' commands, which not all seds can handle. GNU sed should be fine
98277b5038d7SDag-Erling Smørgrav	  # though. Also, the filter scales superlinearly with the number of
98287b5038d7SDag-Erling Smørgrav	  # global variables. join(1) would be nice here, but unfortunately
98297b5038d7SDag-Erling Smørgrav	  # isn't a blessed tool.
98307b5038d7SDag-Erling Smørgrav	  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
98317b5038d7SDag-Erling Smørgrav	  func_append delfiles " $export_symbols $output_objdir/$libname.filter"
98327b5038d7SDag-Erling Smørgrav	  export_symbols=$output_objdir/$libname.def
98337b5038d7SDag-Erling Smørgrav	  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
98347b5038d7SDag-Erling Smørgrav	fi
98357b5038d7SDag-Erling Smørgrav
98367b5038d7SDag-Erling Smørgrav	tmp_deplibs=
98377b5038d7SDag-Erling Smørgrav	for test_deplib in $deplibs; do
98387b5038d7SDag-Erling Smørgrav	  case " $convenience " in
98397b5038d7SDag-Erling Smørgrav	  *" $test_deplib "*) ;;
98407b5038d7SDag-Erling Smørgrav	  *)
98417b5038d7SDag-Erling Smørgrav	    func_append tmp_deplibs " $test_deplib"
98427b5038d7SDag-Erling Smørgrav	    ;;
98437b5038d7SDag-Erling Smørgrav	  esac
98447b5038d7SDag-Erling Smørgrav	done
9845986ba33cSDag-Erling Smørgrav	deplibs=$tmp_deplibs
98467b5038d7SDag-Erling Smørgrav
98477b5038d7SDag-Erling Smørgrav	if test -n "$convenience"; then
98487b5038d7SDag-Erling Smørgrav	  if test -n "$whole_archive_flag_spec" &&
9849986ba33cSDag-Erling Smørgrav	    test yes = "$compiler_needs_object" &&
98507b5038d7SDag-Erling Smørgrav	    test -z "$libobjs"; then
98517b5038d7SDag-Erling Smørgrav	    # extract the archives, so we have objects to list.
98527b5038d7SDag-Erling Smørgrav	    # TODO: could optimize this to just extract one archive.
98537b5038d7SDag-Erling Smørgrav	    whole_archive_flag_spec=
98547b5038d7SDag-Erling Smørgrav	  fi
98557b5038d7SDag-Erling Smørgrav	  if test -n "$whole_archive_flag_spec"; then
98567b5038d7SDag-Erling Smørgrav	    save_libobjs=$libobjs
98577b5038d7SDag-Erling Smørgrav	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
98587b5038d7SDag-Erling Smørgrav	    test "X$libobjs" = "X " && libobjs=
98597b5038d7SDag-Erling Smørgrav	  else
9860986ba33cSDag-Erling Smørgrav	    gentop=$output_objdir/${outputname}x
98617b5038d7SDag-Erling Smørgrav	    func_append generated " $gentop"
98627b5038d7SDag-Erling Smørgrav
98637b5038d7SDag-Erling Smørgrav	    func_extract_archives $gentop $convenience
98647b5038d7SDag-Erling Smørgrav	    func_append libobjs " $func_extract_archives_result"
98657b5038d7SDag-Erling Smørgrav	    test "X$libobjs" = "X " && libobjs=
98667b5038d7SDag-Erling Smørgrav	  fi
98677b5038d7SDag-Erling Smørgrav	fi
98687b5038d7SDag-Erling Smørgrav
9869986ba33cSDag-Erling Smørgrav	if test yes = "$thread_safe" && test -n "$thread_safe_flag_spec"; then
98707b5038d7SDag-Erling Smørgrav	  eval flag=\"$thread_safe_flag_spec\"
98717b5038d7SDag-Erling Smørgrav	  func_append linker_flags " $flag"
98727b5038d7SDag-Erling Smørgrav	fi
98737b5038d7SDag-Erling Smørgrav
98747b5038d7SDag-Erling Smørgrav	# Make a backup of the uninstalled library when relinking
9875986ba33cSDag-Erling Smørgrav	if test relink = "$opt_mode"; then
98767b5038d7SDag-Erling Smørgrav	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?
98777b5038d7SDag-Erling Smørgrav	fi
98787b5038d7SDag-Erling Smørgrav
98797b5038d7SDag-Erling Smørgrav	# Do each of the archive commands.
9880986ba33cSDag-Erling Smørgrav	if test yes = "$module" && test -n "$module_cmds"; then
98817b5038d7SDag-Erling Smørgrav	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
98827b5038d7SDag-Erling Smørgrav	    eval test_cmds=\"$module_expsym_cmds\"
98837b5038d7SDag-Erling Smørgrav	    cmds=$module_expsym_cmds
98847b5038d7SDag-Erling Smørgrav	  else
98857b5038d7SDag-Erling Smørgrav	    eval test_cmds=\"$module_cmds\"
98867b5038d7SDag-Erling Smørgrav	    cmds=$module_cmds
98877b5038d7SDag-Erling Smørgrav	  fi
98887b5038d7SDag-Erling Smørgrav	else
98897b5038d7SDag-Erling Smørgrav	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
98907b5038d7SDag-Erling Smørgrav	    eval test_cmds=\"$archive_expsym_cmds\"
98917b5038d7SDag-Erling Smørgrav	    cmds=$archive_expsym_cmds
98927b5038d7SDag-Erling Smørgrav	  else
98937b5038d7SDag-Erling Smørgrav	    eval test_cmds=\"$archive_cmds\"
98947b5038d7SDag-Erling Smørgrav	    cmds=$archive_cmds
98957b5038d7SDag-Erling Smørgrav	  fi
98967b5038d7SDag-Erling Smørgrav	fi
98977b5038d7SDag-Erling Smørgrav
9898986ba33cSDag-Erling Smørgrav	if test : != "$skipped_export" &&
98997b5038d7SDag-Erling Smørgrav	   func_len " $test_cmds" &&
99007b5038d7SDag-Erling Smørgrav	   len=$func_len_result &&
99017b5038d7SDag-Erling Smørgrav	   test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
99027b5038d7SDag-Erling Smørgrav	  :
99037b5038d7SDag-Erling Smørgrav	else
99047b5038d7SDag-Erling Smørgrav	  # The command line is too long to link in one step, link piecewise
99057b5038d7SDag-Erling Smørgrav	  # or, if using GNU ld and skipped_export is not :, use a linker
99067b5038d7SDag-Erling Smørgrav	  # script.
99077b5038d7SDag-Erling Smørgrav
99087b5038d7SDag-Erling Smørgrav	  # Save the value of $output and $libobjs because we want to
99097b5038d7SDag-Erling Smørgrav	  # use them later.  If we have whole_archive_flag_spec, we
99107b5038d7SDag-Erling Smørgrav	  # want to use save_libobjs as it was before
99117b5038d7SDag-Erling Smørgrav	  # whole_archive_flag_spec was expanded, because we can't
99127b5038d7SDag-Erling Smørgrav	  # assume the linker understands whole_archive_flag_spec.
99137b5038d7SDag-Erling Smørgrav	  # This may have to be revisited, in case too many
99147b5038d7SDag-Erling Smørgrav	  # convenience libraries get linked in and end up exceeding
99157b5038d7SDag-Erling Smørgrav	  # the spec.
99167b5038d7SDag-Erling Smørgrav	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
99177b5038d7SDag-Erling Smørgrav	    save_libobjs=$libobjs
99187b5038d7SDag-Erling Smørgrav	  fi
99197b5038d7SDag-Erling Smørgrav	  save_output=$output
99207b5038d7SDag-Erling Smørgrav	  func_basename "$output"
99217b5038d7SDag-Erling Smørgrav	  output_la=$func_basename_result
99227b5038d7SDag-Erling Smørgrav
99237b5038d7SDag-Erling Smørgrav	  # Clear the reloadable object creation command queue and
99247b5038d7SDag-Erling Smørgrav	  # initialize k to one.
99257b5038d7SDag-Erling Smørgrav	  test_cmds=
99267b5038d7SDag-Erling Smørgrav	  concat_cmds=
99277b5038d7SDag-Erling Smørgrav	  objlist=
99287b5038d7SDag-Erling Smørgrav	  last_robj=
99297b5038d7SDag-Erling Smørgrav	  k=1
99307b5038d7SDag-Erling Smørgrav
9931986ba33cSDag-Erling Smørgrav	  if test -n "$save_libobjs" && test : != "$skipped_export" && test yes = "$with_gnu_ld"; then
9932986ba33cSDag-Erling Smørgrav	    output=$output_objdir/$output_la.lnkscript
99337b5038d7SDag-Erling Smørgrav	    func_verbose "creating GNU ld script: $output"
99347b5038d7SDag-Erling Smørgrav	    echo 'INPUT (' > $output
99357b5038d7SDag-Erling Smørgrav	    for obj in $save_libobjs
99367b5038d7SDag-Erling Smørgrav	    do
99377b5038d7SDag-Erling Smørgrav	      func_to_tool_file "$obj"
99387b5038d7SDag-Erling Smørgrav	      $ECHO "$func_to_tool_file_result" >> $output
99397b5038d7SDag-Erling Smørgrav	    done
99407b5038d7SDag-Erling Smørgrav	    echo ')' >> $output
99417b5038d7SDag-Erling Smørgrav	    func_append delfiles " $output"
99427b5038d7SDag-Erling Smørgrav	    func_to_tool_file "$output"
99437b5038d7SDag-Erling Smørgrav	    output=$func_to_tool_file_result
9944986ba33cSDag-Erling Smørgrav	  elif test -n "$save_libobjs" && test : != "$skipped_export" && test -n "$file_list_spec"; then
9945986ba33cSDag-Erling Smørgrav	    output=$output_objdir/$output_la.lnk
99467b5038d7SDag-Erling Smørgrav	    func_verbose "creating linker input file list: $output"
99477b5038d7SDag-Erling Smørgrav	    : > $output
99487b5038d7SDag-Erling Smørgrav	    set x $save_libobjs
99497b5038d7SDag-Erling Smørgrav	    shift
99507b5038d7SDag-Erling Smørgrav	    firstobj=
9951986ba33cSDag-Erling Smørgrav	    if test yes = "$compiler_needs_object"; then
99527b5038d7SDag-Erling Smørgrav	      firstobj="$1 "
99537b5038d7SDag-Erling Smørgrav	      shift
99547b5038d7SDag-Erling Smørgrav	    fi
99557b5038d7SDag-Erling Smørgrav	    for obj
99567b5038d7SDag-Erling Smørgrav	    do
99577b5038d7SDag-Erling Smørgrav	      func_to_tool_file "$obj"
99587b5038d7SDag-Erling Smørgrav	      $ECHO "$func_to_tool_file_result" >> $output
99597b5038d7SDag-Erling Smørgrav	    done
99607b5038d7SDag-Erling Smørgrav	    func_append delfiles " $output"
99617b5038d7SDag-Erling Smørgrav	    func_to_tool_file "$output"
99627b5038d7SDag-Erling Smørgrav	    output=$firstobj\"$file_list_spec$func_to_tool_file_result\"
99637b5038d7SDag-Erling Smørgrav	  else
99647b5038d7SDag-Erling Smørgrav	    if test -n "$save_libobjs"; then
99657b5038d7SDag-Erling Smørgrav	      func_verbose "creating reloadable object files..."
9966986ba33cSDag-Erling Smørgrav	      output=$output_objdir/$output_la-$k.$objext
99677b5038d7SDag-Erling Smørgrav	      eval test_cmds=\"$reload_cmds\"
99687b5038d7SDag-Erling Smørgrav	      func_len " $test_cmds"
99697b5038d7SDag-Erling Smørgrav	      len0=$func_len_result
99707b5038d7SDag-Erling Smørgrav	      len=$len0
99717b5038d7SDag-Erling Smørgrav
99727b5038d7SDag-Erling Smørgrav	      # Loop over the list of objects to be linked.
99737b5038d7SDag-Erling Smørgrav	      for obj in $save_libobjs
99747b5038d7SDag-Erling Smørgrav	      do
99757b5038d7SDag-Erling Smørgrav		func_len " $obj"
99767b5038d7SDag-Erling Smørgrav		func_arith $len + $func_len_result
99777b5038d7SDag-Erling Smørgrav		len=$func_arith_result
9978986ba33cSDag-Erling Smørgrav		if test -z "$objlist" ||
99797b5038d7SDag-Erling Smørgrav		   test "$len" -lt "$max_cmd_len"; then
99807b5038d7SDag-Erling Smørgrav		  func_append objlist " $obj"
99817b5038d7SDag-Erling Smørgrav		else
99827b5038d7SDag-Erling Smørgrav		  # The command $test_cmds is almost too long, add a
99837b5038d7SDag-Erling Smørgrav		  # command to the queue.
9984986ba33cSDag-Erling Smørgrav		  if test 1 -eq "$k"; then
99857b5038d7SDag-Erling Smørgrav		    # The first file doesn't have a previous command to add.
99867b5038d7SDag-Erling Smørgrav		    reload_objs=$objlist
99877b5038d7SDag-Erling Smørgrav		    eval concat_cmds=\"$reload_cmds\"
99887b5038d7SDag-Erling Smørgrav		  else
99897b5038d7SDag-Erling Smørgrav		    # All subsequent reloadable object files will link in
99907b5038d7SDag-Erling Smørgrav		    # the last one created.
99917b5038d7SDag-Erling Smørgrav		    reload_objs="$objlist $last_robj"
99927b5038d7SDag-Erling Smørgrav		    eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\"
99937b5038d7SDag-Erling Smørgrav		  fi
9994986ba33cSDag-Erling Smørgrav		  last_robj=$output_objdir/$output_la-$k.$objext
99957b5038d7SDag-Erling Smørgrav		  func_arith $k + 1
99967b5038d7SDag-Erling Smørgrav		  k=$func_arith_result
9997986ba33cSDag-Erling Smørgrav		  output=$output_objdir/$output_la-$k.$objext
99987b5038d7SDag-Erling Smørgrav		  objlist=" $obj"
99997b5038d7SDag-Erling Smørgrav		  func_len " $last_robj"
100007b5038d7SDag-Erling Smørgrav		  func_arith $len0 + $func_len_result
100017b5038d7SDag-Erling Smørgrav		  len=$func_arith_result
100027b5038d7SDag-Erling Smørgrav		fi
100037b5038d7SDag-Erling Smørgrav	      done
100047b5038d7SDag-Erling Smørgrav	      # Handle the remaining objects by creating one last
100057b5038d7SDag-Erling Smørgrav	      # reloadable object file.  All subsequent reloadable object
100067b5038d7SDag-Erling Smørgrav	      # files will link in the last one created.
100077b5038d7SDag-Erling Smørgrav	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
100087b5038d7SDag-Erling Smørgrav	      reload_objs="$objlist $last_robj"
10009986ba33cSDag-Erling Smørgrav	      eval concat_cmds=\"\$concat_cmds$reload_cmds\"
100107b5038d7SDag-Erling Smørgrav	      if test -n "$last_robj"; then
10011986ba33cSDag-Erling Smørgrav	        eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
100127b5038d7SDag-Erling Smørgrav	      fi
100137b5038d7SDag-Erling Smørgrav	      func_append delfiles " $output"
100147b5038d7SDag-Erling Smørgrav
100157b5038d7SDag-Erling Smørgrav	    else
100167b5038d7SDag-Erling Smørgrav	      output=
100177b5038d7SDag-Erling Smørgrav	    fi
100187b5038d7SDag-Erling Smørgrav
10019986ba33cSDag-Erling Smørgrav	    ${skipped_export-false} && {
10020986ba33cSDag-Erling Smørgrav	      func_verbose "generating symbol list for '$libname.la'"
10021986ba33cSDag-Erling Smørgrav	      export_symbols=$output_objdir/$libname.exp
100227b5038d7SDag-Erling Smørgrav	      $opt_dry_run || $RM $export_symbols
100237b5038d7SDag-Erling Smørgrav	      libobjs=$output
100247b5038d7SDag-Erling Smørgrav	      # Append the command to create the export file.
100257b5038d7SDag-Erling Smørgrav	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
100267b5038d7SDag-Erling Smørgrav	      eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\"
100277b5038d7SDag-Erling Smørgrav	      if test -n "$last_robj"; then
100287b5038d7SDag-Erling Smørgrav		eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\"
100297b5038d7SDag-Erling Smørgrav	      fi
10030986ba33cSDag-Erling Smørgrav	    }
100317b5038d7SDag-Erling Smørgrav
100327b5038d7SDag-Erling Smørgrav	    test -n "$save_libobjs" &&
100337b5038d7SDag-Erling Smørgrav	      func_verbose "creating a temporary reloadable object file: $output"
100347b5038d7SDag-Erling Smørgrav
100357b5038d7SDag-Erling Smørgrav	    # Loop through the commands generated above and execute them.
10036986ba33cSDag-Erling Smørgrav	    save_ifs=$IFS; IFS='~'
100377b5038d7SDag-Erling Smørgrav	    for cmd in $concat_cmds; do
10038986ba33cSDag-Erling Smørgrav	      IFS=$save_ifs
10039986ba33cSDag-Erling Smørgrav	      $opt_quiet || {
100407b5038d7SDag-Erling Smørgrav		  func_quote_for_expand "$cmd"
100417b5038d7SDag-Erling Smørgrav		  eval "func_echo $func_quote_for_expand_result"
100427b5038d7SDag-Erling Smørgrav	      }
100437b5038d7SDag-Erling Smørgrav	      $opt_dry_run || eval "$cmd" || {
100447b5038d7SDag-Erling Smørgrav		lt_exit=$?
100457b5038d7SDag-Erling Smørgrav
100467b5038d7SDag-Erling Smørgrav		# Restore the uninstalled library and exit
10047986ba33cSDag-Erling Smørgrav		if test relink = "$opt_mode"; then
100487b5038d7SDag-Erling Smørgrav		  ( cd "$output_objdir" && \
100497b5038d7SDag-Erling Smørgrav		    $RM "${realname}T" && \
100507b5038d7SDag-Erling Smørgrav		    $MV "${realname}U" "$realname" )
100517b5038d7SDag-Erling Smørgrav		fi
100527b5038d7SDag-Erling Smørgrav
100537b5038d7SDag-Erling Smørgrav		exit $lt_exit
100547b5038d7SDag-Erling Smørgrav	      }
100557b5038d7SDag-Erling Smørgrav	    done
10056986ba33cSDag-Erling Smørgrav	    IFS=$save_ifs
100577b5038d7SDag-Erling Smørgrav
100587b5038d7SDag-Erling Smørgrav	    if test -n "$export_symbols_regex" && ${skipped_export-false}; then
100597b5038d7SDag-Erling Smørgrav	      func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
100607b5038d7SDag-Erling Smørgrav	      func_show_eval '$MV "${export_symbols}T" "$export_symbols"'
100617b5038d7SDag-Erling Smørgrav	    fi
100627b5038d7SDag-Erling Smørgrav	  fi
100637b5038d7SDag-Erling Smørgrav
10064986ba33cSDag-Erling Smørgrav          ${skipped_export-false} && {
100657b5038d7SDag-Erling Smørgrav	    if test -n "$export_symbols" && test -n "$include_expsyms"; then
10066986ba33cSDag-Erling Smørgrav	      tmp_export_symbols=$export_symbols
10067986ba33cSDag-Erling Smørgrav	      test -n "$orig_export_symbols" && tmp_export_symbols=$orig_export_symbols
100687b5038d7SDag-Erling Smørgrav	      $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"'
100697b5038d7SDag-Erling Smørgrav	    fi
100707b5038d7SDag-Erling Smørgrav
100717b5038d7SDag-Erling Smørgrav	    if test -n "$orig_export_symbols"; then
100727b5038d7SDag-Erling Smørgrav	      # The given exports_symbols file has to be filtered, so filter it.
10073986ba33cSDag-Erling Smørgrav	      func_verbose "filter symbol list for '$libname.la' to tag DATA exports"
100747b5038d7SDag-Erling Smørgrav	      # FIXME: $output_objdir/$libname.filter potentially contains lots of
10075986ba33cSDag-Erling Smørgrav	      # 's' commands, which not all seds can handle. GNU sed should be fine
100767b5038d7SDag-Erling Smørgrav	      # though. Also, the filter scales superlinearly with the number of
100777b5038d7SDag-Erling Smørgrav	      # global variables. join(1) would be nice here, but unfortunately
100787b5038d7SDag-Erling Smørgrav	      # isn't a blessed tool.
100797b5038d7SDag-Erling Smørgrav	      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter
100807b5038d7SDag-Erling Smørgrav	      func_append delfiles " $export_symbols $output_objdir/$libname.filter"
100817b5038d7SDag-Erling Smørgrav	      export_symbols=$output_objdir/$libname.def
100827b5038d7SDag-Erling Smørgrav	      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols
100837b5038d7SDag-Erling Smørgrav	    fi
10084986ba33cSDag-Erling Smørgrav	  }
100857b5038d7SDag-Erling Smørgrav
100867b5038d7SDag-Erling Smørgrav	  libobjs=$output
100877b5038d7SDag-Erling Smørgrav	  # Restore the value of output.
100887b5038d7SDag-Erling Smørgrav	  output=$save_output
100897b5038d7SDag-Erling Smørgrav
100907b5038d7SDag-Erling Smørgrav	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
100917b5038d7SDag-Erling Smørgrav	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
100927b5038d7SDag-Erling Smørgrav	    test "X$libobjs" = "X " && libobjs=
100937b5038d7SDag-Erling Smørgrav	  fi
100947b5038d7SDag-Erling Smørgrav	  # Expand the library linking commands again to reset the
100957b5038d7SDag-Erling Smørgrav	  # value of $libobjs for piecewise linking.
100967b5038d7SDag-Erling Smørgrav
100977b5038d7SDag-Erling Smørgrav	  # Do each of the archive commands.
10098986ba33cSDag-Erling Smørgrav	  if test yes = "$module" && test -n "$module_cmds"; then
100997b5038d7SDag-Erling Smørgrav	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
101007b5038d7SDag-Erling Smørgrav	      cmds=$module_expsym_cmds
101017b5038d7SDag-Erling Smørgrav	    else
101027b5038d7SDag-Erling Smørgrav	      cmds=$module_cmds
101037b5038d7SDag-Erling Smørgrav	    fi
101047b5038d7SDag-Erling Smørgrav	  else
101057b5038d7SDag-Erling Smørgrav	    if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
101067b5038d7SDag-Erling Smørgrav	      cmds=$archive_expsym_cmds
101077b5038d7SDag-Erling Smørgrav	    else
101087b5038d7SDag-Erling Smørgrav	      cmds=$archive_cmds
101097b5038d7SDag-Erling Smørgrav	    fi
101107b5038d7SDag-Erling Smørgrav	  fi
101117b5038d7SDag-Erling Smørgrav	fi
101127b5038d7SDag-Erling Smørgrav
101137b5038d7SDag-Erling Smørgrav	if test -n "$delfiles"; then
101147b5038d7SDag-Erling Smørgrav	  # Append the command to remove temporary files to $cmds.
101157b5038d7SDag-Erling Smørgrav	  eval cmds=\"\$cmds~\$RM $delfiles\"
101167b5038d7SDag-Erling Smørgrav	fi
101177b5038d7SDag-Erling Smørgrav
101187b5038d7SDag-Erling Smørgrav	# Add any objects from preloaded convenience libraries
101197b5038d7SDag-Erling Smørgrav	if test -n "$dlprefiles"; then
10120986ba33cSDag-Erling Smørgrav	  gentop=$output_objdir/${outputname}x
101217b5038d7SDag-Erling Smørgrav	  func_append generated " $gentop"
101227b5038d7SDag-Erling Smørgrav
101237b5038d7SDag-Erling Smørgrav	  func_extract_archives $gentop $dlprefiles
101247b5038d7SDag-Erling Smørgrav	  func_append libobjs " $func_extract_archives_result"
101257b5038d7SDag-Erling Smørgrav	  test "X$libobjs" = "X " && libobjs=
101267b5038d7SDag-Erling Smørgrav	fi
101277b5038d7SDag-Erling Smørgrav
10128986ba33cSDag-Erling Smørgrav	save_ifs=$IFS; IFS='~'
101297b5038d7SDag-Erling Smørgrav	for cmd in $cmds; do
10130986ba33cSDag-Erling Smørgrav	  IFS=$sp$nl
101317b5038d7SDag-Erling Smørgrav	  eval cmd=\"$cmd\"
10132986ba33cSDag-Erling Smørgrav	  IFS=$save_ifs
10133986ba33cSDag-Erling Smørgrav	  $opt_quiet || {
101347b5038d7SDag-Erling Smørgrav	    func_quote_for_expand "$cmd"
101357b5038d7SDag-Erling Smørgrav	    eval "func_echo $func_quote_for_expand_result"
101367b5038d7SDag-Erling Smørgrav	  }
101377b5038d7SDag-Erling Smørgrav	  $opt_dry_run || eval "$cmd" || {
101387b5038d7SDag-Erling Smørgrav	    lt_exit=$?
101397b5038d7SDag-Erling Smørgrav
101407b5038d7SDag-Erling Smørgrav	    # Restore the uninstalled library and exit
10141986ba33cSDag-Erling Smørgrav	    if test relink = "$opt_mode"; then
101427b5038d7SDag-Erling Smørgrav	      ( cd "$output_objdir" && \
101437b5038d7SDag-Erling Smørgrav	        $RM "${realname}T" && \
101447b5038d7SDag-Erling Smørgrav		$MV "${realname}U" "$realname" )
101457b5038d7SDag-Erling Smørgrav	    fi
101467b5038d7SDag-Erling Smørgrav
101477b5038d7SDag-Erling Smørgrav	    exit $lt_exit
101487b5038d7SDag-Erling Smørgrav	  }
101497b5038d7SDag-Erling Smørgrav	done
10150986ba33cSDag-Erling Smørgrav	IFS=$save_ifs
101517b5038d7SDag-Erling Smørgrav
101527b5038d7SDag-Erling Smørgrav	# Restore the uninstalled library and exit
10153986ba33cSDag-Erling Smørgrav	if test relink = "$opt_mode"; then
101547b5038d7SDag-Erling Smørgrav	  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?
101557b5038d7SDag-Erling Smørgrav
101567b5038d7SDag-Erling Smørgrav	  if test -n "$convenience"; then
101577b5038d7SDag-Erling Smørgrav	    if test -z "$whole_archive_flag_spec"; then
101587b5038d7SDag-Erling Smørgrav	      func_show_eval '${RM}r "$gentop"'
101597b5038d7SDag-Erling Smørgrav	    fi
101607b5038d7SDag-Erling Smørgrav	  fi
101617b5038d7SDag-Erling Smørgrav
101627b5038d7SDag-Erling Smørgrav	  exit $EXIT_SUCCESS
101637b5038d7SDag-Erling Smørgrav	fi
101647b5038d7SDag-Erling Smørgrav
101657b5038d7SDag-Erling Smørgrav	# Create links to the real library.
101667b5038d7SDag-Erling Smørgrav	for linkname in $linknames; do
101677b5038d7SDag-Erling Smørgrav	  if test "$realname" != "$linkname"; then
101687b5038d7SDag-Erling Smørgrav	    func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?'
101697b5038d7SDag-Erling Smørgrav	  fi
101707b5038d7SDag-Erling Smørgrav	done
101717b5038d7SDag-Erling Smørgrav
101727b5038d7SDag-Erling Smørgrav	# If -module or -export-dynamic was specified, set the dlname.
10173986ba33cSDag-Erling Smørgrav	if test yes = "$module" || test yes = "$export_dynamic"; then
101747b5038d7SDag-Erling Smørgrav	  # On all known operating systems, these are identical.
10175986ba33cSDag-Erling Smørgrav	  dlname=$soname
101767b5038d7SDag-Erling Smørgrav	fi
101777b5038d7SDag-Erling Smørgrav      fi
101787b5038d7SDag-Erling Smørgrav      ;;
101797b5038d7SDag-Erling Smørgrav
101807b5038d7SDag-Erling Smørgrav    obj)
10181986ba33cSDag-Erling Smørgrav      if test -n "$dlfiles$dlprefiles" || test no != "$dlself"; then
10182986ba33cSDag-Erling Smørgrav	func_warning "'-dlopen' is ignored for objects"
101837b5038d7SDag-Erling Smørgrav      fi
101847b5038d7SDag-Erling Smørgrav
101857b5038d7SDag-Erling Smørgrav      case " $deplibs" in
101867b5038d7SDag-Erling Smørgrav      *\ -l* | *\ -L*)
10187986ba33cSDag-Erling Smørgrav	func_warning "'-l' and '-L' are ignored for objects" ;;
101887b5038d7SDag-Erling Smørgrav      esac
101897b5038d7SDag-Erling Smørgrav
101907b5038d7SDag-Erling Smørgrav      test -n "$rpath" && \
10191986ba33cSDag-Erling Smørgrav	func_warning "'-rpath' is ignored for objects"
101927b5038d7SDag-Erling Smørgrav
101937b5038d7SDag-Erling Smørgrav      test -n "$xrpath" && \
10194986ba33cSDag-Erling Smørgrav	func_warning "'-R' is ignored for objects"
101957b5038d7SDag-Erling Smørgrav
101967b5038d7SDag-Erling Smørgrav      test -n "$vinfo" && \
10197986ba33cSDag-Erling Smørgrav	func_warning "'-version-info' is ignored for objects"
101987b5038d7SDag-Erling Smørgrav
101997b5038d7SDag-Erling Smørgrav      test -n "$release" && \
10200986ba33cSDag-Erling Smørgrav	func_warning "'-release' is ignored for objects"
102017b5038d7SDag-Erling Smørgrav
102027b5038d7SDag-Erling Smørgrav      case $output in
102037b5038d7SDag-Erling Smørgrav      *.lo)
102047b5038d7SDag-Erling Smørgrav	test -n "$objs$old_deplibs" && \
10205986ba33cSDag-Erling Smørgrav	  func_fatal_error "cannot build library object '$output' from non-libtool objects"
102067b5038d7SDag-Erling Smørgrav
102077b5038d7SDag-Erling Smørgrav	libobj=$output
102087b5038d7SDag-Erling Smørgrav	func_lo2o "$libobj"
102097b5038d7SDag-Erling Smørgrav	obj=$func_lo2o_result
102107b5038d7SDag-Erling Smørgrav	;;
102117b5038d7SDag-Erling Smørgrav      *)
102127b5038d7SDag-Erling Smørgrav	libobj=
10213986ba33cSDag-Erling Smørgrav	obj=$output
102147b5038d7SDag-Erling Smørgrav	;;
102157b5038d7SDag-Erling Smørgrav      esac
102167b5038d7SDag-Erling Smørgrav
102177b5038d7SDag-Erling Smørgrav      # Delete the old objects.
102187b5038d7SDag-Erling Smørgrav      $opt_dry_run || $RM $obj $libobj
102197b5038d7SDag-Erling Smørgrav
102207b5038d7SDag-Erling Smørgrav      # Objects from convenience libraries.  This assumes
102217b5038d7SDag-Erling Smørgrav      # single-version convenience libraries.  Whenever we create
102227b5038d7SDag-Erling Smørgrav      # different ones for PIC/non-PIC, this we'll have to duplicate
102237b5038d7SDag-Erling Smørgrav      # the extraction.
102247b5038d7SDag-Erling Smørgrav      reload_conv_objs=
102257b5038d7SDag-Erling Smørgrav      gentop=
10226986ba33cSDag-Erling Smørgrav      # if reload_cmds runs $LD directly, get rid of -Wl from
10227986ba33cSDag-Erling Smørgrav      # whole_archive_flag_spec and hope we can get by with turning comma
10228986ba33cSDag-Erling Smørgrav      # into space.
10229986ba33cSDag-Erling Smørgrav      case $reload_cmds in
10230986ba33cSDag-Erling Smørgrav        *\$LD[\ \$]*) wl= ;;
10231986ba33cSDag-Erling Smørgrav      esac
102327b5038d7SDag-Erling Smørgrav      if test -n "$convenience"; then
102337b5038d7SDag-Erling Smørgrav	if test -n "$whole_archive_flag_spec"; then
102347b5038d7SDag-Erling Smørgrav	  eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\"
10235986ba33cSDag-Erling Smørgrav	  test -n "$wl" || tmp_whole_archive_flags=`$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'`
10236986ba33cSDag-Erling Smørgrav	  reload_conv_objs=$reload_objs\ $tmp_whole_archive_flags
102377b5038d7SDag-Erling Smørgrav	else
10238986ba33cSDag-Erling Smørgrav	  gentop=$output_objdir/${obj}x
102397b5038d7SDag-Erling Smørgrav	  func_append generated " $gentop"
102407b5038d7SDag-Erling Smørgrav
102417b5038d7SDag-Erling Smørgrav	  func_extract_archives $gentop $convenience
102427b5038d7SDag-Erling Smørgrav	  reload_conv_objs="$reload_objs $func_extract_archives_result"
102437b5038d7SDag-Erling Smørgrav	fi
102447b5038d7SDag-Erling Smørgrav      fi
102457b5038d7SDag-Erling Smørgrav
102467b5038d7SDag-Erling Smørgrav      # If we're not building shared, we need to use non_pic_objs
10247986ba33cSDag-Erling Smørgrav      test yes = "$build_libtool_libs" || libobjs=$non_pic_objects
102487b5038d7SDag-Erling Smørgrav
102497b5038d7SDag-Erling Smørgrav      # Create the old-style object.
10250986ba33cSDag-Erling Smørgrav      reload_objs=$objs$old_deplibs' '`$ECHO "$libobjs" | $SP2NL | $SED "/\.$libext$/d; /\.lib$/d; $lo2o" | $NL2SP`' '$reload_conv_objs
102517b5038d7SDag-Erling Smørgrav
10252986ba33cSDag-Erling Smørgrav      output=$obj
102537b5038d7SDag-Erling Smørgrav      func_execute_cmds "$reload_cmds" 'exit $?'
102547b5038d7SDag-Erling Smørgrav
102557b5038d7SDag-Erling Smørgrav      # Exit if we aren't doing a library object file.
102567b5038d7SDag-Erling Smørgrav      if test -z "$libobj"; then
102577b5038d7SDag-Erling Smørgrav	if test -n "$gentop"; then
102587b5038d7SDag-Erling Smørgrav	  func_show_eval '${RM}r "$gentop"'
102597b5038d7SDag-Erling Smørgrav	fi
102607b5038d7SDag-Erling Smørgrav
102617b5038d7SDag-Erling Smørgrav	exit $EXIT_SUCCESS
102627b5038d7SDag-Erling Smørgrav      fi
102637b5038d7SDag-Erling Smørgrav
10264986ba33cSDag-Erling Smørgrav      test yes = "$build_libtool_libs" || {
102657b5038d7SDag-Erling Smørgrav	if test -n "$gentop"; then
102667b5038d7SDag-Erling Smørgrav	  func_show_eval '${RM}r "$gentop"'
102677b5038d7SDag-Erling Smørgrav	fi
102687b5038d7SDag-Erling Smørgrav
102697b5038d7SDag-Erling Smørgrav	# Create an invalid libtool object if no PIC, so that we don't
102707b5038d7SDag-Erling Smørgrav	# accidentally link it into a program.
102717b5038d7SDag-Erling Smørgrav	# $show "echo timestamp > $libobj"
102727b5038d7SDag-Erling Smørgrav	# $opt_dry_run || eval "echo timestamp > $libobj" || exit $?
102737b5038d7SDag-Erling Smørgrav	exit $EXIT_SUCCESS
10274986ba33cSDag-Erling Smørgrav      }
102757b5038d7SDag-Erling Smørgrav
10276986ba33cSDag-Erling Smørgrav      if test -n "$pic_flag" || test default != "$pic_mode"; then
102777b5038d7SDag-Erling Smørgrav	# Only do commands if we really have different PIC objects.
102787b5038d7SDag-Erling Smørgrav	reload_objs="$libobjs $reload_conv_objs"
10279986ba33cSDag-Erling Smørgrav	output=$libobj
102807b5038d7SDag-Erling Smørgrav	func_execute_cmds "$reload_cmds" 'exit $?'
102817b5038d7SDag-Erling Smørgrav      fi
102827b5038d7SDag-Erling Smørgrav
102837b5038d7SDag-Erling Smørgrav      if test -n "$gentop"; then
102847b5038d7SDag-Erling Smørgrav	func_show_eval '${RM}r "$gentop"'
102857b5038d7SDag-Erling Smørgrav      fi
102867b5038d7SDag-Erling Smørgrav
102877b5038d7SDag-Erling Smørgrav      exit $EXIT_SUCCESS
102887b5038d7SDag-Erling Smørgrav      ;;
102897b5038d7SDag-Erling Smørgrav
102907b5038d7SDag-Erling Smørgrav    prog)
102917b5038d7SDag-Erling Smørgrav      case $host in
102927b5038d7SDag-Erling Smørgrav	*cygwin*) func_stripname '' '.exe' "$output"
102937b5038d7SDag-Erling Smørgrav	          output=$func_stripname_result.exe;;
102947b5038d7SDag-Erling Smørgrav      esac
102957b5038d7SDag-Erling Smørgrav      test -n "$vinfo" && \
10296986ba33cSDag-Erling Smørgrav	func_warning "'-version-info' is ignored for programs"
102977b5038d7SDag-Erling Smørgrav
102987b5038d7SDag-Erling Smørgrav      test -n "$release" && \
10299986ba33cSDag-Erling Smørgrav	func_warning "'-release' is ignored for programs"
103007b5038d7SDag-Erling Smørgrav
10301986ba33cSDag-Erling Smørgrav      $preload \
10302986ba33cSDag-Erling Smørgrav	&& test unknown,unknown,unknown = "$dlopen_support,$dlopen_self,$dlopen_self_static" \
10303986ba33cSDag-Erling Smørgrav	&& func_warning "'LT_INIT([dlopen])' not used. Assuming no dlopen support."
103047b5038d7SDag-Erling Smørgrav
103057b5038d7SDag-Erling Smørgrav      case $host in
103067b5038d7SDag-Erling Smørgrav      *-*-rhapsody* | *-*-darwin1.[012])
103077b5038d7SDag-Erling Smørgrav	# On Rhapsody replace the C library is the System framework
103087b5038d7SDag-Erling Smørgrav	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'`
103097b5038d7SDag-Erling Smørgrav	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'`
103107b5038d7SDag-Erling Smørgrav	;;
103117b5038d7SDag-Erling Smørgrav      esac
103127b5038d7SDag-Erling Smørgrav
103137b5038d7SDag-Erling Smørgrav      case $host in
103147b5038d7SDag-Erling Smørgrav      *-*-darwin*)
103157b5038d7SDag-Erling Smørgrav	# Don't allow lazy linking, it breaks C++ global constructors
103167b5038d7SDag-Erling Smørgrav	# But is supposedly fixed on 10.4 or later (yay!).
10317986ba33cSDag-Erling Smørgrav	if test CXX = "$tagname"; then
103187b5038d7SDag-Erling Smørgrav	  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in
103197b5038d7SDag-Erling Smørgrav	    10.[0123])
10320986ba33cSDag-Erling Smørgrav	      func_append compile_command " $wl-bind_at_load"
10321986ba33cSDag-Erling Smørgrav	      func_append finalize_command " $wl-bind_at_load"
103227b5038d7SDag-Erling Smørgrav	    ;;
103237b5038d7SDag-Erling Smørgrav	  esac
103247b5038d7SDag-Erling Smørgrav	fi
103257b5038d7SDag-Erling Smørgrav	# Time to change all our "foo.ltframework" stuff back to "-framework foo"
103267b5038d7SDag-Erling Smørgrav	compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
103277b5038d7SDag-Erling Smørgrav	finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'`
103287b5038d7SDag-Erling Smørgrav	;;
103297b5038d7SDag-Erling Smørgrav      esac
103307b5038d7SDag-Erling Smørgrav
103317b5038d7SDag-Erling Smørgrav
103327b5038d7SDag-Erling Smørgrav      # move library search paths that coincide with paths to not yet
103337b5038d7SDag-Erling Smørgrav      # installed libraries to the beginning of the library search list
103347b5038d7SDag-Erling Smørgrav      new_libs=
103357b5038d7SDag-Erling Smørgrav      for path in $notinst_path; do
103367b5038d7SDag-Erling Smørgrav	case " $new_libs " in
103377b5038d7SDag-Erling Smørgrav	*" -L$path/$objdir "*) ;;
103387b5038d7SDag-Erling Smørgrav	*)
103397b5038d7SDag-Erling Smørgrav	  case " $compile_deplibs " in
103407b5038d7SDag-Erling Smørgrav	  *" -L$path/$objdir "*)
103417b5038d7SDag-Erling Smørgrav	    func_append new_libs " -L$path/$objdir" ;;
103427b5038d7SDag-Erling Smørgrav	  esac
103437b5038d7SDag-Erling Smørgrav	  ;;
103447b5038d7SDag-Erling Smørgrav	esac
103457b5038d7SDag-Erling Smørgrav      done
103467b5038d7SDag-Erling Smørgrav      for deplib in $compile_deplibs; do
103477b5038d7SDag-Erling Smørgrav	case $deplib in
103487b5038d7SDag-Erling Smørgrav	-L*)
103497b5038d7SDag-Erling Smørgrav	  case " $new_libs " in
103507b5038d7SDag-Erling Smørgrav	  *" $deplib "*) ;;
103517b5038d7SDag-Erling Smørgrav	  *) func_append new_libs " $deplib" ;;
103527b5038d7SDag-Erling Smørgrav	  esac
103537b5038d7SDag-Erling Smørgrav	  ;;
103547b5038d7SDag-Erling Smørgrav	*) func_append new_libs " $deplib" ;;
103557b5038d7SDag-Erling Smørgrav	esac
103567b5038d7SDag-Erling Smørgrav      done
10357986ba33cSDag-Erling Smørgrav      compile_deplibs=$new_libs
103587b5038d7SDag-Erling Smørgrav
103597b5038d7SDag-Erling Smørgrav
103607b5038d7SDag-Erling Smørgrav      func_append compile_command " $compile_deplibs"
103617b5038d7SDag-Erling Smørgrav      func_append finalize_command " $finalize_deplibs"
103627b5038d7SDag-Erling Smørgrav
103637b5038d7SDag-Erling Smørgrav      if test -n "$rpath$xrpath"; then
103647b5038d7SDag-Erling Smørgrav	# If the user specified any rpath flags, then add them.
103657b5038d7SDag-Erling Smørgrav	for libdir in $rpath $xrpath; do
103667b5038d7SDag-Erling Smørgrav	  # This is the magic to use -rpath.
103677b5038d7SDag-Erling Smørgrav	  case "$finalize_rpath " in
103687b5038d7SDag-Erling Smørgrav	  *" $libdir "*) ;;
103697b5038d7SDag-Erling Smørgrav	  *) func_append finalize_rpath " $libdir" ;;
103707b5038d7SDag-Erling Smørgrav	  esac
103717b5038d7SDag-Erling Smørgrav	done
103727b5038d7SDag-Erling Smørgrav      fi
103737b5038d7SDag-Erling Smørgrav
103747b5038d7SDag-Erling Smørgrav      # Now hardcode the library paths
103757b5038d7SDag-Erling Smørgrav      rpath=
103767b5038d7SDag-Erling Smørgrav      hardcode_libdirs=
103777b5038d7SDag-Erling Smørgrav      for libdir in $compile_rpath $finalize_rpath; do
103787b5038d7SDag-Erling Smørgrav	if test -n "$hardcode_libdir_flag_spec"; then
103797b5038d7SDag-Erling Smørgrav	  if test -n "$hardcode_libdir_separator"; then
103807b5038d7SDag-Erling Smørgrav	    if test -z "$hardcode_libdirs"; then
10381986ba33cSDag-Erling Smørgrav	      hardcode_libdirs=$libdir
103827b5038d7SDag-Erling Smørgrav	    else
103837b5038d7SDag-Erling Smørgrav	      # Just accumulate the unique libdirs.
103847b5038d7SDag-Erling Smørgrav	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
103857b5038d7SDag-Erling Smørgrav	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
103867b5038d7SDag-Erling Smørgrav		;;
103877b5038d7SDag-Erling Smørgrav	      *)
103887b5038d7SDag-Erling Smørgrav		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
103897b5038d7SDag-Erling Smørgrav		;;
103907b5038d7SDag-Erling Smørgrav	      esac
103917b5038d7SDag-Erling Smørgrav	    fi
103927b5038d7SDag-Erling Smørgrav	  else
103937b5038d7SDag-Erling Smørgrav	    eval flag=\"$hardcode_libdir_flag_spec\"
103947b5038d7SDag-Erling Smørgrav	    func_append rpath " $flag"
103957b5038d7SDag-Erling Smørgrav	  fi
103967b5038d7SDag-Erling Smørgrav	elif test -n "$runpath_var"; then
103977b5038d7SDag-Erling Smørgrav	  case "$perm_rpath " in
103987b5038d7SDag-Erling Smørgrav	  *" $libdir "*) ;;
103997b5038d7SDag-Erling Smørgrav	  *) func_append perm_rpath " $libdir" ;;
104007b5038d7SDag-Erling Smørgrav	  esac
104017b5038d7SDag-Erling Smørgrav	fi
104027b5038d7SDag-Erling Smørgrav	case $host in
104037b5038d7SDag-Erling Smørgrav	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)
10404986ba33cSDag-Erling Smørgrav	  testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'`
104057b5038d7SDag-Erling Smørgrav	  case :$dllsearchpath: in
104067b5038d7SDag-Erling Smørgrav	  *":$libdir:"*) ;;
104077b5038d7SDag-Erling Smørgrav	  ::) dllsearchpath=$libdir;;
104087b5038d7SDag-Erling Smørgrav	  *) func_append dllsearchpath ":$libdir";;
104097b5038d7SDag-Erling Smørgrav	  esac
104107b5038d7SDag-Erling Smørgrav	  case :$dllsearchpath: in
104117b5038d7SDag-Erling Smørgrav	  *":$testbindir:"*) ;;
104127b5038d7SDag-Erling Smørgrav	  ::) dllsearchpath=$testbindir;;
104137b5038d7SDag-Erling Smørgrav	  *) func_append dllsearchpath ":$testbindir";;
104147b5038d7SDag-Erling Smørgrav	  esac
104157b5038d7SDag-Erling Smørgrav	  ;;
104167b5038d7SDag-Erling Smørgrav	esac
104177b5038d7SDag-Erling Smørgrav      done
104187b5038d7SDag-Erling Smørgrav      # Substitute the hardcoded libdirs into the rpath.
104197b5038d7SDag-Erling Smørgrav      if test -n "$hardcode_libdir_separator" &&
104207b5038d7SDag-Erling Smørgrav	 test -n "$hardcode_libdirs"; then
10421986ba33cSDag-Erling Smørgrav	libdir=$hardcode_libdirs
104227b5038d7SDag-Erling Smørgrav	eval rpath=\" $hardcode_libdir_flag_spec\"
104237b5038d7SDag-Erling Smørgrav      fi
10424986ba33cSDag-Erling Smørgrav      compile_rpath=$rpath
104257b5038d7SDag-Erling Smørgrav
104267b5038d7SDag-Erling Smørgrav      rpath=
104277b5038d7SDag-Erling Smørgrav      hardcode_libdirs=
104287b5038d7SDag-Erling Smørgrav      for libdir in $finalize_rpath; do
104297b5038d7SDag-Erling Smørgrav	if test -n "$hardcode_libdir_flag_spec"; then
104307b5038d7SDag-Erling Smørgrav	  if test -n "$hardcode_libdir_separator"; then
104317b5038d7SDag-Erling Smørgrav	    if test -z "$hardcode_libdirs"; then
10432986ba33cSDag-Erling Smørgrav	      hardcode_libdirs=$libdir
104337b5038d7SDag-Erling Smørgrav	    else
104347b5038d7SDag-Erling Smørgrav	      # Just accumulate the unique libdirs.
104357b5038d7SDag-Erling Smørgrav	      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in
104367b5038d7SDag-Erling Smørgrav	      *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*)
104377b5038d7SDag-Erling Smørgrav		;;
104387b5038d7SDag-Erling Smørgrav	      *)
104397b5038d7SDag-Erling Smørgrav		func_append hardcode_libdirs "$hardcode_libdir_separator$libdir"
104407b5038d7SDag-Erling Smørgrav		;;
104417b5038d7SDag-Erling Smørgrav	      esac
104427b5038d7SDag-Erling Smørgrav	    fi
104437b5038d7SDag-Erling Smørgrav	  else
104447b5038d7SDag-Erling Smørgrav	    eval flag=\"$hardcode_libdir_flag_spec\"
104457b5038d7SDag-Erling Smørgrav	    func_append rpath " $flag"
104467b5038d7SDag-Erling Smørgrav	  fi
104477b5038d7SDag-Erling Smørgrav	elif test -n "$runpath_var"; then
104487b5038d7SDag-Erling Smørgrav	  case "$finalize_perm_rpath " in
104497b5038d7SDag-Erling Smørgrav	  *" $libdir "*) ;;
104507b5038d7SDag-Erling Smørgrav	  *) func_append finalize_perm_rpath " $libdir" ;;
104517b5038d7SDag-Erling Smørgrav	  esac
104527b5038d7SDag-Erling Smørgrav	fi
104537b5038d7SDag-Erling Smørgrav      done
104547b5038d7SDag-Erling Smørgrav      # Substitute the hardcoded libdirs into the rpath.
104557b5038d7SDag-Erling Smørgrav      if test -n "$hardcode_libdir_separator" &&
104567b5038d7SDag-Erling Smørgrav	 test -n "$hardcode_libdirs"; then
10457986ba33cSDag-Erling Smørgrav	libdir=$hardcode_libdirs
104587b5038d7SDag-Erling Smørgrav	eval rpath=\" $hardcode_libdir_flag_spec\"
104597b5038d7SDag-Erling Smørgrav      fi
10460986ba33cSDag-Erling Smørgrav      finalize_rpath=$rpath
104617b5038d7SDag-Erling Smørgrav
10462986ba33cSDag-Erling Smørgrav      if test -n "$libobjs" && test yes = "$build_old_libs"; then
104637b5038d7SDag-Erling Smørgrav	# Transform all the library objects into standard objects.
104647b5038d7SDag-Erling Smørgrav	compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
104657b5038d7SDag-Erling Smørgrav	finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP`
104667b5038d7SDag-Erling Smørgrav      fi
104677b5038d7SDag-Erling Smørgrav
10468986ba33cSDag-Erling Smørgrav      func_generate_dlsyms "$outputname" "@PROGRAM@" false
104697b5038d7SDag-Erling Smørgrav
104707b5038d7SDag-Erling Smørgrav      # template prelinking step
104717b5038d7SDag-Erling Smørgrav      if test -n "$prelink_cmds"; then
104727b5038d7SDag-Erling Smørgrav	func_execute_cmds "$prelink_cmds" 'exit $?'
104737b5038d7SDag-Erling Smørgrav      fi
104747b5038d7SDag-Erling Smørgrav
10475986ba33cSDag-Erling Smørgrav      wrappers_required=:
104767b5038d7SDag-Erling Smørgrav      case $host in
104777b5038d7SDag-Erling Smørgrav      *cegcc* | *mingw32ce*)
104787b5038d7SDag-Erling Smørgrav        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.
10479986ba33cSDag-Erling Smørgrav        wrappers_required=false
104807b5038d7SDag-Erling Smørgrav        ;;
104817b5038d7SDag-Erling Smørgrav      *cygwin* | *mingw* )
10482986ba33cSDag-Erling Smørgrav        test yes = "$build_libtool_libs" || wrappers_required=false
104837b5038d7SDag-Erling Smørgrav        ;;
104847b5038d7SDag-Erling Smørgrav      *)
10485986ba33cSDag-Erling Smørgrav        if test no = "$need_relink" || test yes != "$build_libtool_libs"; then
10486986ba33cSDag-Erling Smørgrav          wrappers_required=false
104877b5038d7SDag-Erling Smørgrav        fi
104887b5038d7SDag-Erling Smørgrav        ;;
104897b5038d7SDag-Erling Smørgrav      esac
10490986ba33cSDag-Erling Smørgrav      $wrappers_required || {
104917b5038d7SDag-Erling Smørgrav	# Replace the output file specification.
104927b5038d7SDag-Erling Smørgrav	compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
10493986ba33cSDag-Erling Smørgrav	link_command=$compile_command$compile_rpath
104947b5038d7SDag-Erling Smørgrav
104957b5038d7SDag-Erling Smørgrav	# We have no uninstalled library dependencies, so finalize right now.
104967b5038d7SDag-Erling Smørgrav	exit_status=0
104977b5038d7SDag-Erling Smørgrav	func_show_eval "$link_command" 'exit_status=$?'
104987b5038d7SDag-Erling Smørgrav
104997b5038d7SDag-Erling Smørgrav	if test -n "$postlink_cmds"; then
105007b5038d7SDag-Erling Smørgrav	  func_to_tool_file "$output"
105017b5038d7SDag-Erling Smørgrav	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
105027b5038d7SDag-Erling Smørgrav	  func_execute_cmds "$postlink_cmds" 'exit $?'
105037b5038d7SDag-Erling Smørgrav	fi
105047b5038d7SDag-Erling Smørgrav
105057b5038d7SDag-Erling Smørgrav	# Delete the generated files.
10506986ba33cSDag-Erling Smørgrav	if test -f "$output_objdir/${outputname}S.$objext"; then
10507986ba33cSDag-Erling Smørgrav	  func_show_eval '$RM "$output_objdir/${outputname}S.$objext"'
105087b5038d7SDag-Erling Smørgrav	fi
105097b5038d7SDag-Erling Smørgrav
105107b5038d7SDag-Erling Smørgrav	exit $exit_status
10511986ba33cSDag-Erling Smørgrav      }
105127b5038d7SDag-Erling Smørgrav
105137b5038d7SDag-Erling Smørgrav      if test -n "$compile_shlibpath$finalize_shlibpath"; then
105147b5038d7SDag-Erling Smørgrav	compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command"
105157b5038d7SDag-Erling Smørgrav      fi
105167b5038d7SDag-Erling Smørgrav      if test -n "$finalize_shlibpath"; then
105177b5038d7SDag-Erling Smørgrav	finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command"
105187b5038d7SDag-Erling Smørgrav      fi
105197b5038d7SDag-Erling Smørgrav
105207b5038d7SDag-Erling Smørgrav      compile_var=
105217b5038d7SDag-Erling Smørgrav      finalize_var=
105227b5038d7SDag-Erling Smørgrav      if test -n "$runpath_var"; then
105237b5038d7SDag-Erling Smørgrav	if test -n "$perm_rpath"; then
105247b5038d7SDag-Erling Smørgrav	  # We should set the runpath_var.
105257b5038d7SDag-Erling Smørgrav	  rpath=
105267b5038d7SDag-Erling Smørgrav	  for dir in $perm_rpath; do
105277b5038d7SDag-Erling Smørgrav	    func_append rpath "$dir:"
105287b5038d7SDag-Erling Smørgrav	  done
105297b5038d7SDag-Erling Smørgrav	  compile_var="$runpath_var=\"$rpath\$$runpath_var\" "
105307b5038d7SDag-Erling Smørgrav	fi
105317b5038d7SDag-Erling Smørgrav	if test -n "$finalize_perm_rpath"; then
105327b5038d7SDag-Erling Smørgrav	  # We should set the runpath_var.
105337b5038d7SDag-Erling Smørgrav	  rpath=
105347b5038d7SDag-Erling Smørgrav	  for dir in $finalize_perm_rpath; do
105357b5038d7SDag-Erling Smørgrav	    func_append rpath "$dir:"
105367b5038d7SDag-Erling Smørgrav	  done
105377b5038d7SDag-Erling Smørgrav	  finalize_var="$runpath_var=\"$rpath\$$runpath_var\" "
105387b5038d7SDag-Erling Smørgrav	fi
105397b5038d7SDag-Erling Smørgrav      fi
105407b5038d7SDag-Erling Smørgrav
10541986ba33cSDag-Erling Smørgrav      if test yes = "$no_install"; then
105427b5038d7SDag-Erling Smørgrav	# We don't need to create a wrapper script.
10543986ba33cSDag-Erling Smørgrav	link_command=$compile_var$compile_command$compile_rpath
105447b5038d7SDag-Erling Smørgrav	# Replace the output file specification.
105457b5038d7SDag-Erling Smørgrav	link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'`
105467b5038d7SDag-Erling Smørgrav	# Delete the old output file.
105477b5038d7SDag-Erling Smørgrav	$opt_dry_run || $RM $output
105487b5038d7SDag-Erling Smørgrav	# Link the executable and exit
105497b5038d7SDag-Erling Smørgrav	func_show_eval "$link_command" 'exit $?'
105507b5038d7SDag-Erling Smørgrav
105517b5038d7SDag-Erling Smørgrav	if test -n "$postlink_cmds"; then
105527b5038d7SDag-Erling Smørgrav	  func_to_tool_file "$output"
105537b5038d7SDag-Erling Smørgrav	  postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'`
105547b5038d7SDag-Erling Smørgrav	  func_execute_cmds "$postlink_cmds" 'exit $?'
105557b5038d7SDag-Erling Smørgrav	fi
105567b5038d7SDag-Erling Smørgrav
105577b5038d7SDag-Erling Smørgrav	exit $EXIT_SUCCESS
105587b5038d7SDag-Erling Smørgrav      fi
105597b5038d7SDag-Erling Smørgrav
10560986ba33cSDag-Erling Smørgrav      case $hardcode_action,$fast_install in
10561986ba33cSDag-Erling Smørgrav        relink,*)
105627b5038d7SDag-Erling Smørgrav	  # Fast installation is not supported
10563986ba33cSDag-Erling Smørgrav	  link_command=$compile_var$compile_command$compile_rpath
10564986ba33cSDag-Erling Smørgrav	  relink_command=$finalize_var$finalize_command$finalize_rpath
105657b5038d7SDag-Erling Smørgrav
105667b5038d7SDag-Erling Smørgrav	  func_warning "this platform does not like uninstalled shared libraries"
10567986ba33cSDag-Erling Smørgrav	  func_warning "'$output' will be relinked during installation"
10568986ba33cSDag-Erling Smørgrav	  ;;
10569986ba33cSDag-Erling Smørgrav        *,yes)
10570986ba33cSDag-Erling Smørgrav	  link_command=$finalize_var$compile_command$finalize_rpath
105717b5038d7SDag-Erling Smørgrav	  relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'`
10572986ba33cSDag-Erling Smørgrav          ;;
10573986ba33cSDag-Erling Smørgrav	*,no)
10574986ba33cSDag-Erling Smørgrav	  link_command=$compile_var$compile_command$compile_rpath
10575986ba33cSDag-Erling Smørgrav	  relink_command=$finalize_var$finalize_command$finalize_rpath
10576986ba33cSDag-Erling Smørgrav          ;;
10577986ba33cSDag-Erling Smørgrav	*,needless)
10578986ba33cSDag-Erling Smørgrav	  link_command=$finalize_var$compile_command$finalize_rpath
105797b5038d7SDag-Erling Smørgrav	  relink_command=
10580986ba33cSDag-Erling Smørgrav          ;;
10581986ba33cSDag-Erling Smørgrav      esac
105827b5038d7SDag-Erling Smørgrav
105837b5038d7SDag-Erling Smørgrav      # Replace the output file specification.
105847b5038d7SDag-Erling Smørgrav      link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'`
105857b5038d7SDag-Erling Smørgrav
105867b5038d7SDag-Erling Smørgrav      # Delete the old output files.
105877b5038d7SDag-Erling Smørgrav      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname
105887b5038d7SDag-Erling Smørgrav
105897b5038d7SDag-Erling Smørgrav      func_show_eval "$link_command" 'exit $?'
105907b5038d7SDag-Erling Smørgrav
105917b5038d7SDag-Erling Smørgrav      if test -n "$postlink_cmds"; then
105927b5038d7SDag-Erling Smørgrav	func_to_tool_file "$output_objdir/$outputname"
105937b5038d7SDag-Erling Smørgrav	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'`
105947b5038d7SDag-Erling Smørgrav	func_execute_cmds "$postlink_cmds" 'exit $?'
105957b5038d7SDag-Erling Smørgrav      fi
105967b5038d7SDag-Erling Smørgrav
105977b5038d7SDag-Erling Smørgrav      # Now create the wrapper script.
105987b5038d7SDag-Erling Smørgrav      func_verbose "creating $output"
105997b5038d7SDag-Erling Smørgrav
106007b5038d7SDag-Erling Smørgrav      # Quote the relink command for shipping.
106017b5038d7SDag-Erling Smørgrav      if test -n "$relink_command"; then
106027b5038d7SDag-Erling Smørgrav	# Preserve any variables that may affect compiler behavior
106037b5038d7SDag-Erling Smørgrav	for var in $variables_saved_for_relink; do
106047b5038d7SDag-Erling Smørgrav	  if eval test -z \"\${$var+set}\"; then
106057b5038d7SDag-Erling Smørgrav	    relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
106067b5038d7SDag-Erling Smørgrav	  elif eval var_value=\$$var; test -z "$var_value"; then
106077b5038d7SDag-Erling Smørgrav	    relink_command="$var=; export $var; $relink_command"
106087b5038d7SDag-Erling Smørgrav	  else
106097b5038d7SDag-Erling Smørgrav	    func_quote_for_eval "$var_value"
106107b5038d7SDag-Erling Smørgrav	    relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
106117b5038d7SDag-Erling Smørgrav	  fi
106127b5038d7SDag-Erling Smørgrav	done
106137b5038d7SDag-Erling Smørgrav	relink_command="(cd `pwd`; $relink_command)"
106147b5038d7SDag-Erling Smørgrav	relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
106157b5038d7SDag-Erling Smørgrav      fi
106167b5038d7SDag-Erling Smørgrav
106177b5038d7SDag-Erling Smørgrav      # Only actually do things if not in dry run mode.
106187b5038d7SDag-Erling Smørgrav      $opt_dry_run || {
106197b5038d7SDag-Erling Smørgrav	# win32 will think the script is a binary if it has
106207b5038d7SDag-Erling Smørgrav	# a .exe suffix, so we strip it off here.
106217b5038d7SDag-Erling Smørgrav	case $output in
106227b5038d7SDag-Erling Smørgrav	  *.exe) func_stripname '' '.exe' "$output"
106237b5038d7SDag-Erling Smørgrav	         output=$func_stripname_result ;;
106247b5038d7SDag-Erling Smørgrav	esac
106257b5038d7SDag-Erling Smørgrav	# test for cygwin because mv fails w/o .exe extensions
106267b5038d7SDag-Erling Smørgrav	case $host in
106277b5038d7SDag-Erling Smørgrav	  *cygwin*)
106287b5038d7SDag-Erling Smørgrav	    exeext=.exe
106297b5038d7SDag-Erling Smørgrav	    func_stripname '' '.exe' "$outputname"
106307b5038d7SDag-Erling Smørgrav	    outputname=$func_stripname_result ;;
106317b5038d7SDag-Erling Smørgrav	  *) exeext= ;;
106327b5038d7SDag-Erling Smørgrav	esac
106337b5038d7SDag-Erling Smørgrav	case $host in
106347b5038d7SDag-Erling Smørgrav	  *cygwin* | *mingw* )
106357b5038d7SDag-Erling Smørgrav	    func_dirname_and_basename "$output" "" "."
106367b5038d7SDag-Erling Smørgrav	    output_name=$func_basename_result
106377b5038d7SDag-Erling Smørgrav	    output_path=$func_dirname_result
10638986ba33cSDag-Erling Smørgrav	    cwrappersource=$output_path/$objdir/lt-$output_name.c
10639986ba33cSDag-Erling Smørgrav	    cwrapper=$output_path/$output_name.exe
106407b5038d7SDag-Erling Smørgrav	    $RM $cwrappersource $cwrapper
106417b5038d7SDag-Erling Smørgrav	    trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
106427b5038d7SDag-Erling Smørgrav
106437b5038d7SDag-Erling Smørgrav	    func_emit_cwrapperexe_src > $cwrappersource
106447b5038d7SDag-Erling Smørgrav
106457b5038d7SDag-Erling Smørgrav	    # The wrapper executable is built using the $host compiler,
106467b5038d7SDag-Erling Smørgrav	    # because it contains $host paths and files. If cross-
106477b5038d7SDag-Erling Smørgrav	    # compiling, it, like the target executable, must be
106487b5038d7SDag-Erling Smørgrav	    # executed on the $host or under an emulation environment.
106497b5038d7SDag-Erling Smørgrav	    $opt_dry_run || {
106507b5038d7SDag-Erling Smørgrav	      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource
106517b5038d7SDag-Erling Smørgrav	      $STRIP $cwrapper
106527b5038d7SDag-Erling Smørgrav	    }
106537b5038d7SDag-Erling Smørgrav
106547b5038d7SDag-Erling Smørgrav	    # Now, create the wrapper script for func_source use:
106557b5038d7SDag-Erling Smørgrav	    func_ltwrapper_scriptname $cwrapper
106567b5038d7SDag-Erling Smørgrav	    $RM $func_ltwrapper_scriptname_result
106577b5038d7SDag-Erling Smørgrav	    trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15
106587b5038d7SDag-Erling Smørgrav	    $opt_dry_run || {
106597b5038d7SDag-Erling Smørgrav	      # note: this script will not be executed, so do not chmod.
106607b5038d7SDag-Erling Smørgrav	      if test "x$build" = "x$host"; then
106617b5038d7SDag-Erling Smørgrav		$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result
106627b5038d7SDag-Erling Smørgrav	      else
106637b5038d7SDag-Erling Smørgrav		func_emit_wrapper no > $func_ltwrapper_scriptname_result
106647b5038d7SDag-Erling Smørgrav	      fi
106657b5038d7SDag-Erling Smørgrav	    }
106667b5038d7SDag-Erling Smørgrav	  ;;
106677b5038d7SDag-Erling Smørgrav	  * )
106687b5038d7SDag-Erling Smørgrav	    $RM $output
106697b5038d7SDag-Erling Smørgrav	    trap "$RM $output; exit $EXIT_FAILURE" 1 2 15
106707b5038d7SDag-Erling Smørgrav
106717b5038d7SDag-Erling Smørgrav	    func_emit_wrapper no > $output
106727b5038d7SDag-Erling Smørgrav	    chmod +x $output
106737b5038d7SDag-Erling Smørgrav	  ;;
106747b5038d7SDag-Erling Smørgrav	esac
106757b5038d7SDag-Erling Smørgrav      }
106767b5038d7SDag-Erling Smørgrav      exit $EXIT_SUCCESS
106777b5038d7SDag-Erling Smørgrav      ;;
106787b5038d7SDag-Erling Smørgrav    esac
106797b5038d7SDag-Erling Smørgrav
106807b5038d7SDag-Erling Smørgrav    # See if we need to build an old-fashioned archive.
106817b5038d7SDag-Erling Smørgrav    for oldlib in $oldlibs; do
106827b5038d7SDag-Erling Smørgrav
10683986ba33cSDag-Erling Smørgrav      case $build_libtool_libs in
10684986ba33cSDag-Erling Smørgrav        convenience)
106857b5038d7SDag-Erling Smørgrav	  oldobjs="$libobjs_save $symfileobj"
10686986ba33cSDag-Erling Smørgrav	  addlibs=$convenience
106877b5038d7SDag-Erling Smørgrav	  build_libtool_libs=no
10688986ba33cSDag-Erling Smørgrav	  ;;
10689986ba33cSDag-Erling Smørgrav	module)
10690986ba33cSDag-Erling Smørgrav	  oldobjs=$libobjs_save
10691986ba33cSDag-Erling Smørgrav	  addlibs=$old_convenience
106927b5038d7SDag-Erling Smørgrav	  build_libtool_libs=no
10693986ba33cSDag-Erling Smørgrav          ;;
10694986ba33cSDag-Erling Smørgrav	*)
106957b5038d7SDag-Erling Smørgrav	  oldobjs="$old_deplibs $non_pic_objects"
10696986ba33cSDag-Erling Smørgrav	  $preload && test -f "$symfileobj" \
10697986ba33cSDag-Erling Smørgrav	    && func_append oldobjs " $symfileobj"
10698986ba33cSDag-Erling Smørgrav	  addlibs=$old_convenience
10699986ba33cSDag-Erling Smørgrav	  ;;
10700986ba33cSDag-Erling Smørgrav      esac
107017b5038d7SDag-Erling Smørgrav
107027b5038d7SDag-Erling Smørgrav      if test -n "$addlibs"; then
10703986ba33cSDag-Erling Smørgrav	gentop=$output_objdir/${outputname}x
107047b5038d7SDag-Erling Smørgrav	func_append generated " $gentop"
107057b5038d7SDag-Erling Smørgrav
107067b5038d7SDag-Erling Smørgrav	func_extract_archives $gentop $addlibs
107077b5038d7SDag-Erling Smørgrav	func_append oldobjs " $func_extract_archives_result"
107087b5038d7SDag-Erling Smørgrav      fi
107097b5038d7SDag-Erling Smørgrav
107107b5038d7SDag-Erling Smørgrav      # Do each command in the archive commands.
10711986ba33cSDag-Erling Smørgrav      if test -n "$old_archive_from_new_cmds" && test yes = "$build_libtool_libs"; then
107127b5038d7SDag-Erling Smørgrav	cmds=$old_archive_from_new_cmds
107137b5038d7SDag-Erling Smørgrav      else
107147b5038d7SDag-Erling Smørgrav
107157b5038d7SDag-Erling Smørgrav	# Add any objects from preloaded convenience libraries
107167b5038d7SDag-Erling Smørgrav	if test -n "$dlprefiles"; then
10717986ba33cSDag-Erling Smørgrav	  gentop=$output_objdir/${outputname}x
107187b5038d7SDag-Erling Smørgrav	  func_append generated " $gentop"
107197b5038d7SDag-Erling Smørgrav
107207b5038d7SDag-Erling Smørgrav	  func_extract_archives $gentop $dlprefiles
107217b5038d7SDag-Erling Smørgrav	  func_append oldobjs " $func_extract_archives_result"
107227b5038d7SDag-Erling Smørgrav	fi
107237b5038d7SDag-Erling Smørgrav
107247b5038d7SDag-Erling Smørgrav	# POSIX demands no paths to be encoded in archives.  We have
107257b5038d7SDag-Erling Smørgrav	# to avoid creating archives with duplicate basenames if we
107267b5038d7SDag-Erling Smørgrav	# might have to extract them afterwards, e.g., when creating a
107277b5038d7SDag-Erling Smørgrav	# static archive out of a convenience library, or when linking
107287b5038d7SDag-Erling Smørgrav	# the entirety of a libtool archive into another (currently
107297b5038d7SDag-Erling Smørgrav	# not supported by libtool).
107307b5038d7SDag-Erling Smørgrav	if (for obj in $oldobjs
107317b5038d7SDag-Erling Smørgrav	    do
107327b5038d7SDag-Erling Smørgrav	      func_basename "$obj"
107337b5038d7SDag-Erling Smørgrav	      $ECHO "$func_basename_result"
107347b5038d7SDag-Erling Smørgrav	    done | sort | sort -uc >/dev/null 2>&1); then
107357b5038d7SDag-Erling Smørgrav	  :
107367b5038d7SDag-Erling Smørgrav	else
107377b5038d7SDag-Erling Smørgrav	  echo "copying selected object files to avoid basename conflicts..."
10738986ba33cSDag-Erling Smørgrav	  gentop=$output_objdir/${outputname}x
107397b5038d7SDag-Erling Smørgrav	  func_append generated " $gentop"
107407b5038d7SDag-Erling Smørgrav	  func_mkdir_p "$gentop"
107417b5038d7SDag-Erling Smørgrav	  save_oldobjs=$oldobjs
107427b5038d7SDag-Erling Smørgrav	  oldobjs=
107437b5038d7SDag-Erling Smørgrav	  counter=1
107447b5038d7SDag-Erling Smørgrav	  for obj in $save_oldobjs
107457b5038d7SDag-Erling Smørgrav	  do
107467b5038d7SDag-Erling Smørgrav	    func_basename "$obj"
10747986ba33cSDag-Erling Smørgrav	    objbase=$func_basename_result
107487b5038d7SDag-Erling Smørgrav	    case " $oldobjs " in
107497b5038d7SDag-Erling Smørgrav	    " ") oldobjs=$obj ;;
107507b5038d7SDag-Erling Smørgrav	    *[\ /]"$objbase "*)
107517b5038d7SDag-Erling Smørgrav	      while :; do
107527b5038d7SDag-Erling Smørgrav		# Make sure we don't pick an alternate name that also
107537b5038d7SDag-Erling Smørgrav		# overlaps.
107547b5038d7SDag-Erling Smørgrav		newobj=lt$counter-$objbase
107557b5038d7SDag-Erling Smørgrav		func_arith $counter + 1
107567b5038d7SDag-Erling Smørgrav		counter=$func_arith_result
107577b5038d7SDag-Erling Smørgrav		case " $oldobjs " in
107587b5038d7SDag-Erling Smørgrav		*[\ /]"$newobj "*) ;;
107597b5038d7SDag-Erling Smørgrav		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
107607b5038d7SDag-Erling Smørgrav		esac
107617b5038d7SDag-Erling Smørgrav	      done
107627b5038d7SDag-Erling Smørgrav	      func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
107637b5038d7SDag-Erling Smørgrav	      func_append oldobjs " $gentop/$newobj"
107647b5038d7SDag-Erling Smørgrav	      ;;
107657b5038d7SDag-Erling Smørgrav	    *) func_append oldobjs " $obj" ;;
107667b5038d7SDag-Erling Smørgrav	    esac
107677b5038d7SDag-Erling Smørgrav	  done
107687b5038d7SDag-Erling Smørgrav	fi
107697b5038d7SDag-Erling Smørgrav	func_to_tool_file "$oldlib" func_convert_file_msys_to_w32
107707b5038d7SDag-Erling Smørgrav	tool_oldlib=$func_to_tool_file_result
107717b5038d7SDag-Erling Smørgrav	eval cmds=\"$old_archive_cmds\"
107727b5038d7SDag-Erling Smørgrav
107737b5038d7SDag-Erling Smørgrav	func_len " $cmds"
107747b5038d7SDag-Erling Smørgrav	len=$func_len_result
107757b5038d7SDag-Erling Smørgrav	if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then
107767b5038d7SDag-Erling Smørgrav	  cmds=$old_archive_cmds
107777b5038d7SDag-Erling Smørgrav	elif test -n "$archiver_list_spec"; then
107787b5038d7SDag-Erling Smørgrav	  func_verbose "using command file archive linking..."
107797b5038d7SDag-Erling Smørgrav	  for obj in $oldobjs
107807b5038d7SDag-Erling Smørgrav	  do
107817b5038d7SDag-Erling Smørgrav	    func_to_tool_file "$obj"
107827b5038d7SDag-Erling Smørgrav	    $ECHO "$func_to_tool_file_result"
107837b5038d7SDag-Erling Smørgrav	  done > $output_objdir/$libname.libcmd
107847b5038d7SDag-Erling Smørgrav	  func_to_tool_file "$output_objdir/$libname.libcmd"
107857b5038d7SDag-Erling Smørgrav	  oldobjs=" $archiver_list_spec$func_to_tool_file_result"
107867b5038d7SDag-Erling Smørgrav	  cmds=$old_archive_cmds
107877b5038d7SDag-Erling Smørgrav	else
107887b5038d7SDag-Erling Smørgrav	  # the command line is too long to link in one step, link in parts
107897b5038d7SDag-Erling Smørgrav	  func_verbose "using piecewise archive linking..."
107907b5038d7SDag-Erling Smørgrav	  save_RANLIB=$RANLIB
107917b5038d7SDag-Erling Smørgrav	  RANLIB=:
107927b5038d7SDag-Erling Smørgrav	  objlist=
107937b5038d7SDag-Erling Smørgrav	  concat_cmds=
107947b5038d7SDag-Erling Smørgrav	  save_oldobjs=$oldobjs
107957b5038d7SDag-Erling Smørgrav	  oldobjs=
107967b5038d7SDag-Erling Smørgrav	  # Is there a better way of finding the last object in the list?
107977b5038d7SDag-Erling Smørgrav	  for obj in $save_oldobjs
107987b5038d7SDag-Erling Smørgrav	  do
107997b5038d7SDag-Erling Smørgrav	    last_oldobj=$obj
108007b5038d7SDag-Erling Smørgrav	  done
108017b5038d7SDag-Erling Smørgrav	  eval test_cmds=\"$old_archive_cmds\"
108027b5038d7SDag-Erling Smørgrav	  func_len " $test_cmds"
108037b5038d7SDag-Erling Smørgrav	  len0=$func_len_result
108047b5038d7SDag-Erling Smørgrav	  len=$len0
108057b5038d7SDag-Erling Smørgrav	  for obj in $save_oldobjs
108067b5038d7SDag-Erling Smørgrav	  do
108077b5038d7SDag-Erling Smørgrav	    func_len " $obj"
108087b5038d7SDag-Erling Smørgrav	    func_arith $len + $func_len_result
108097b5038d7SDag-Erling Smørgrav	    len=$func_arith_result
108107b5038d7SDag-Erling Smørgrav	    func_append objlist " $obj"
108117b5038d7SDag-Erling Smørgrav	    if test "$len" -lt "$max_cmd_len"; then
108127b5038d7SDag-Erling Smørgrav	      :
108137b5038d7SDag-Erling Smørgrav	    else
108147b5038d7SDag-Erling Smørgrav	      # the above command should be used before it gets too long
108157b5038d7SDag-Erling Smørgrav	      oldobjs=$objlist
108167b5038d7SDag-Erling Smørgrav	      if test "$obj" = "$last_oldobj"; then
108177b5038d7SDag-Erling Smørgrav		RANLIB=$save_RANLIB
108187b5038d7SDag-Erling Smørgrav	      fi
108197b5038d7SDag-Erling Smørgrav	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
10820986ba33cSDag-Erling Smørgrav	      eval concat_cmds=\"\$concat_cmds$old_archive_cmds\"
108217b5038d7SDag-Erling Smørgrav	      objlist=
108227b5038d7SDag-Erling Smørgrav	      len=$len0
108237b5038d7SDag-Erling Smørgrav	    fi
108247b5038d7SDag-Erling Smørgrav	  done
108257b5038d7SDag-Erling Smørgrav	  RANLIB=$save_RANLIB
108267b5038d7SDag-Erling Smørgrav	  oldobjs=$objlist
10827986ba33cSDag-Erling Smørgrav	  if test -z "$oldobjs"; then
108287b5038d7SDag-Erling Smørgrav	    eval cmds=\"\$concat_cmds\"
108297b5038d7SDag-Erling Smørgrav	  else
108307b5038d7SDag-Erling Smørgrav	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
108317b5038d7SDag-Erling Smørgrav	  fi
108327b5038d7SDag-Erling Smørgrav	fi
108337b5038d7SDag-Erling Smørgrav      fi
108347b5038d7SDag-Erling Smørgrav      func_execute_cmds "$cmds" 'exit $?'
108357b5038d7SDag-Erling Smørgrav    done
108367b5038d7SDag-Erling Smørgrav
108377b5038d7SDag-Erling Smørgrav    test -n "$generated" && \
108387b5038d7SDag-Erling Smørgrav      func_show_eval "${RM}r$generated"
108397b5038d7SDag-Erling Smørgrav
108407b5038d7SDag-Erling Smørgrav    # Now create the libtool archive.
108417b5038d7SDag-Erling Smørgrav    case $output in
108427b5038d7SDag-Erling Smørgrav    *.la)
108437b5038d7SDag-Erling Smørgrav      old_library=
10844986ba33cSDag-Erling Smørgrav      test yes = "$build_old_libs" && old_library=$libname.$libext
108457b5038d7SDag-Erling Smørgrav      func_verbose "creating $output"
108467b5038d7SDag-Erling Smørgrav
108477b5038d7SDag-Erling Smørgrav      # Preserve any variables that may affect compiler behavior
108487b5038d7SDag-Erling Smørgrav      for var in $variables_saved_for_relink; do
108497b5038d7SDag-Erling Smørgrav	if eval test -z \"\${$var+set}\"; then
108507b5038d7SDag-Erling Smørgrav	  relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command"
108517b5038d7SDag-Erling Smørgrav	elif eval var_value=\$$var; test -z "$var_value"; then
108527b5038d7SDag-Erling Smørgrav	  relink_command="$var=; export $var; $relink_command"
108537b5038d7SDag-Erling Smørgrav	else
108547b5038d7SDag-Erling Smørgrav	  func_quote_for_eval "$var_value"
108557b5038d7SDag-Erling Smørgrav	  relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
108567b5038d7SDag-Erling Smørgrav	fi
108577b5038d7SDag-Erling Smørgrav      done
108587b5038d7SDag-Erling Smørgrav      # Quote the link command for shipping.
10859986ba33cSDag-Erling Smørgrav      relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
108607b5038d7SDag-Erling Smørgrav      relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
10861986ba33cSDag-Erling Smørgrav      if test yes = "$hardcode_automatic"; then
108627b5038d7SDag-Erling Smørgrav	relink_command=
108637b5038d7SDag-Erling Smørgrav      fi
108647b5038d7SDag-Erling Smørgrav
108657b5038d7SDag-Erling Smørgrav      # Only create the output if not a dry run.
108667b5038d7SDag-Erling Smørgrav      $opt_dry_run || {
108677b5038d7SDag-Erling Smørgrav	for installed in no yes; do
10868986ba33cSDag-Erling Smørgrav	  if test yes = "$installed"; then
108697b5038d7SDag-Erling Smørgrav	    if test -z "$install_libdir"; then
108707b5038d7SDag-Erling Smørgrav	      break
108717b5038d7SDag-Erling Smørgrav	    fi
10872986ba33cSDag-Erling Smørgrav	    output=$output_objdir/${outputname}i
108737b5038d7SDag-Erling Smørgrav	    # Replace all uninstalled libtool libraries with the installed ones
108747b5038d7SDag-Erling Smørgrav	    newdependency_libs=
108757b5038d7SDag-Erling Smørgrav	    for deplib in $dependency_libs; do
108767b5038d7SDag-Erling Smørgrav	      case $deplib in
108777b5038d7SDag-Erling Smørgrav	      *.la)
108787b5038d7SDag-Erling Smørgrav		func_basename "$deplib"
10879986ba33cSDag-Erling Smørgrav		name=$func_basename_result
108807b5038d7SDag-Erling Smørgrav		func_resolve_sysroot "$deplib"
10881986ba33cSDag-Erling Smørgrav		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result`
108827b5038d7SDag-Erling Smørgrav		test -z "$libdir" && \
10883986ba33cSDag-Erling Smørgrav		  func_fatal_error "'$deplib' is not a valid libtool archive"
108847b5038d7SDag-Erling Smørgrav		func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name"
108857b5038d7SDag-Erling Smørgrav		;;
108867b5038d7SDag-Erling Smørgrav	      -L*)
108877b5038d7SDag-Erling Smørgrav		func_stripname -L '' "$deplib"
108887b5038d7SDag-Erling Smørgrav		func_replace_sysroot "$func_stripname_result"
108897b5038d7SDag-Erling Smørgrav		func_append newdependency_libs " -L$func_replace_sysroot_result"
108907b5038d7SDag-Erling Smørgrav		;;
108917b5038d7SDag-Erling Smørgrav	      -R*)
108927b5038d7SDag-Erling Smørgrav		func_stripname -R '' "$deplib"
108937b5038d7SDag-Erling Smørgrav		func_replace_sysroot "$func_stripname_result"
108947b5038d7SDag-Erling Smørgrav		func_append newdependency_libs " -R$func_replace_sysroot_result"
108957b5038d7SDag-Erling Smørgrav		;;
108967b5038d7SDag-Erling Smørgrav	      *) func_append newdependency_libs " $deplib" ;;
108977b5038d7SDag-Erling Smørgrav	      esac
108987b5038d7SDag-Erling Smørgrav	    done
10899986ba33cSDag-Erling Smørgrav	    dependency_libs=$newdependency_libs
109007b5038d7SDag-Erling Smørgrav	    newdlfiles=
109017b5038d7SDag-Erling Smørgrav
109027b5038d7SDag-Erling Smørgrav	    for lib in $dlfiles; do
109037b5038d7SDag-Erling Smørgrav	      case $lib in
109047b5038d7SDag-Erling Smørgrav	      *.la)
109057b5038d7SDag-Erling Smørgrav	        func_basename "$lib"
10906986ba33cSDag-Erling Smørgrav		name=$func_basename_result
10907986ba33cSDag-Erling Smørgrav		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
109087b5038d7SDag-Erling Smørgrav		test -z "$libdir" && \
10909986ba33cSDag-Erling Smørgrav		  func_fatal_error "'$lib' is not a valid libtool archive"
109107b5038d7SDag-Erling Smørgrav		func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name"
109117b5038d7SDag-Erling Smørgrav		;;
109127b5038d7SDag-Erling Smørgrav	      *) func_append newdlfiles " $lib" ;;
109137b5038d7SDag-Erling Smørgrav	      esac
109147b5038d7SDag-Erling Smørgrav	    done
10915986ba33cSDag-Erling Smørgrav	    dlfiles=$newdlfiles
109167b5038d7SDag-Erling Smørgrav	    newdlprefiles=
109177b5038d7SDag-Erling Smørgrav	    for lib in $dlprefiles; do
109187b5038d7SDag-Erling Smørgrav	      case $lib in
109197b5038d7SDag-Erling Smørgrav	      *.la)
109207b5038d7SDag-Erling Smørgrav		# Only pass preopened files to the pseudo-archive (for
109217b5038d7SDag-Erling Smørgrav		# eventual linking with the app. that links it) if we
109227b5038d7SDag-Erling Smørgrav		# didn't already link the preopened objects directly into
109237b5038d7SDag-Erling Smørgrav		# the library:
109247b5038d7SDag-Erling Smørgrav		func_basename "$lib"
10925986ba33cSDag-Erling Smørgrav		name=$func_basename_result
10926986ba33cSDag-Erling Smørgrav		eval libdir=`$SED -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
109277b5038d7SDag-Erling Smørgrav		test -z "$libdir" && \
10928986ba33cSDag-Erling Smørgrav		  func_fatal_error "'$lib' is not a valid libtool archive"
109297b5038d7SDag-Erling Smørgrav		func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name"
109307b5038d7SDag-Erling Smørgrav		;;
109317b5038d7SDag-Erling Smørgrav	      esac
109327b5038d7SDag-Erling Smørgrav	    done
10933986ba33cSDag-Erling Smørgrav	    dlprefiles=$newdlprefiles
109347b5038d7SDag-Erling Smørgrav	  else
109357b5038d7SDag-Erling Smørgrav	    newdlfiles=
109367b5038d7SDag-Erling Smørgrav	    for lib in $dlfiles; do
109377b5038d7SDag-Erling Smørgrav	      case $lib in
10938986ba33cSDag-Erling Smørgrav		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
109397b5038d7SDag-Erling Smørgrav		*) abs=`pwd`"/$lib" ;;
109407b5038d7SDag-Erling Smørgrav	      esac
109417b5038d7SDag-Erling Smørgrav	      func_append newdlfiles " $abs"
109427b5038d7SDag-Erling Smørgrav	    done
10943986ba33cSDag-Erling Smørgrav	    dlfiles=$newdlfiles
109447b5038d7SDag-Erling Smørgrav	    newdlprefiles=
109457b5038d7SDag-Erling Smørgrav	    for lib in $dlprefiles; do
109467b5038d7SDag-Erling Smørgrav	      case $lib in
10947986ba33cSDag-Erling Smørgrav		[\\/]* | [A-Za-z]:[\\/]*) abs=$lib ;;
109487b5038d7SDag-Erling Smørgrav		*) abs=`pwd`"/$lib" ;;
109497b5038d7SDag-Erling Smørgrav	      esac
109507b5038d7SDag-Erling Smørgrav	      func_append newdlprefiles " $abs"
109517b5038d7SDag-Erling Smørgrav	    done
10952986ba33cSDag-Erling Smørgrav	    dlprefiles=$newdlprefiles
109537b5038d7SDag-Erling Smørgrav	  fi
109547b5038d7SDag-Erling Smørgrav	  $RM $output
109557b5038d7SDag-Erling Smørgrav	  # place dlname in correct position for cygwin
109567b5038d7SDag-Erling Smørgrav	  # In fact, it would be nice if we could use this code for all target
109577b5038d7SDag-Erling Smørgrav	  # systems that can't hard-code library paths into their executables
109587b5038d7SDag-Erling Smørgrav	  # and that have no shared library path variable independent of PATH,
109597b5038d7SDag-Erling Smørgrav	  # but it turns out we can't easily determine that from inspecting
109607b5038d7SDag-Erling Smørgrav	  # libtool variables, so we have to hard-code the OSs to which it
109617b5038d7SDag-Erling Smørgrav	  # applies here; at the moment, that means platforms that use the PE
109627b5038d7SDag-Erling Smørgrav	  # object format with DLL files.  See the long comment at the top of
109637b5038d7SDag-Erling Smørgrav	  # tests/bindir.at for full details.
109647b5038d7SDag-Erling Smørgrav	  tdlname=$dlname
109657b5038d7SDag-Erling Smørgrav	  case $host,$output,$installed,$module,$dlname in
109667b5038d7SDag-Erling Smørgrav	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)
109677b5038d7SDag-Erling Smørgrav	      # If a -bindir argument was supplied, place the dll there.
10968986ba33cSDag-Erling Smørgrav	      if test -n "$bindir"; then
109697b5038d7SDag-Erling Smørgrav		func_relative_path "$install_libdir" "$bindir"
10970986ba33cSDag-Erling Smørgrav		tdlname=$func_relative_path_result/$dlname
109717b5038d7SDag-Erling Smørgrav	      else
109727b5038d7SDag-Erling Smørgrav		# Otherwise fall back on heuristic.
109737b5038d7SDag-Erling Smørgrav		tdlname=../bin/$dlname
109747b5038d7SDag-Erling Smørgrav	      fi
109757b5038d7SDag-Erling Smørgrav	      ;;
109767b5038d7SDag-Erling Smørgrav	  esac
109777b5038d7SDag-Erling Smørgrav	  $ECHO > $output "\
109787b5038d7SDag-Erling Smørgrav# $outputname - a libtool library file
10979986ba33cSDag-Erling Smørgrav# Generated by $PROGRAM (GNU $PACKAGE) $VERSION
109807b5038d7SDag-Erling Smørgrav#
109817b5038d7SDag-Erling Smørgrav# Please DO NOT delete this file!
109827b5038d7SDag-Erling Smørgrav# It is necessary for linking the library.
109837b5038d7SDag-Erling Smørgrav
109847b5038d7SDag-Erling Smørgrav# The name that we can dlopen(3).
109857b5038d7SDag-Erling Smørgravdlname='$tdlname'
109867b5038d7SDag-Erling Smørgrav
109877b5038d7SDag-Erling Smørgrav# Names of this library.
109887b5038d7SDag-Erling Smørgravlibrary_names='$library_names'
109897b5038d7SDag-Erling Smørgrav
109907b5038d7SDag-Erling Smørgrav# The name of the static archive.
109917b5038d7SDag-Erling Smørgravold_library='$old_library'
109927b5038d7SDag-Erling Smørgrav
109937b5038d7SDag-Erling Smørgrav# Linker flags that cannot go in dependency_libs.
109947b5038d7SDag-Erling Smørgravinherited_linker_flags='$new_inherited_linker_flags'
109957b5038d7SDag-Erling Smørgrav
109967b5038d7SDag-Erling Smørgrav# Libraries that this one depends upon.
109977b5038d7SDag-Erling Smørgravdependency_libs='$dependency_libs'
109987b5038d7SDag-Erling Smørgrav
109997b5038d7SDag-Erling Smørgrav# Names of additional weak libraries provided by this library
110007b5038d7SDag-Erling Smørgravweak_library_names='$weak_libs'
110017b5038d7SDag-Erling Smørgrav
110027b5038d7SDag-Erling Smørgrav# Version information for $libname.
110037b5038d7SDag-Erling Smørgravcurrent=$current
110047b5038d7SDag-Erling Smørgravage=$age
110057b5038d7SDag-Erling Smørgravrevision=$revision
110067b5038d7SDag-Erling Smørgrav
110077b5038d7SDag-Erling Smørgrav# Is this an already installed library?
110087b5038d7SDag-Erling Smørgravinstalled=$installed
110097b5038d7SDag-Erling Smørgrav
110107b5038d7SDag-Erling Smørgrav# Should we warn about portability when linking against -modules?
110117b5038d7SDag-Erling Smørgravshouldnotlink=$module
110127b5038d7SDag-Erling Smørgrav
110137b5038d7SDag-Erling Smørgrav# Files to dlopen/dlpreopen
110147b5038d7SDag-Erling Smørgravdlopen='$dlfiles'
110157b5038d7SDag-Erling Smørgravdlpreopen='$dlprefiles'
110167b5038d7SDag-Erling Smørgrav
110177b5038d7SDag-Erling Smørgrav# Directory that this library needs to be installed in:
110187b5038d7SDag-Erling Smørgravlibdir='$install_libdir'"
11019986ba33cSDag-Erling Smørgrav	  if test no,yes = "$installed,$need_relink"; then
110207b5038d7SDag-Erling Smørgrav	    $ECHO >> $output "\
110217b5038d7SDag-Erling Smørgravrelink_command=\"$relink_command\""
110227b5038d7SDag-Erling Smørgrav	  fi
110237b5038d7SDag-Erling Smørgrav	done
110247b5038d7SDag-Erling Smørgrav      }
110257b5038d7SDag-Erling Smørgrav
110267b5038d7SDag-Erling Smørgrav      # Do a symbolic link so that the libtool archive can be found in
110277b5038d7SDag-Erling Smørgrav      # LD_LIBRARY_PATH before the program is installed.
110287b5038d7SDag-Erling Smørgrav      func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?'
110297b5038d7SDag-Erling Smørgrav      ;;
110307b5038d7SDag-Erling Smørgrav    esac
110317b5038d7SDag-Erling Smørgrav    exit $EXIT_SUCCESS
110327b5038d7SDag-Erling Smørgrav}
110337b5038d7SDag-Erling Smørgrav
11034986ba33cSDag-Erling Smørgravif test link = "$opt_mode" || test relink = "$opt_mode"; then
110357b5038d7SDag-Erling Smørgrav  func_mode_link ${1+"$@"}
11036986ba33cSDag-Erling Smørgravfi
110377b5038d7SDag-Erling Smørgrav
110387b5038d7SDag-Erling Smørgrav
110397b5038d7SDag-Erling Smørgrav# func_mode_uninstall arg...
110407b5038d7SDag-Erling Smørgravfunc_mode_uninstall ()
110417b5038d7SDag-Erling Smørgrav{
11042986ba33cSDag-Erling Smørgrav    $debug_cmd
11043986ba33cSDag-Erling Smørgrav
11044986ba33cSDag-Erling Smørgrav    RM=$nonopt
110457b5038d7SDag-Erling Smørgrav    files=
11046986ba33cSDag-Erling Smørgrav    rmforce=false
110477b5038d7SDag-Erling Smørgrav    exit_status=0
110487b5038d7SDag-Erling Smørgrav
110497b5038d7SDag-Erling Smørgrav    # This variable tells wrapper scripts just to set variables rather
110507b5038d7SDag-Erling Smørgrav    # than running their programs.
11051986ba33cSDag-Erling Smørgrav    libtool_install_magic=$magic
110527b5038d7SDag-Erling Smørgrav
110537b5038d7SDag-Erling Smørgrav    for arg
110547b5038d7SDag-Erling Smørgrav    do
110557b5038d7SDag-Erling Smørgrav      case $arg in
11056986ba33cSDag-Erling Smørgrav      -f) func_append RM " $arg"; rmforce=: ;;
110577b5038d7SDag-Erling Smørgrav      -*) func_append RM " $arg" ;;
110587b5038d7SDag-Erling Smørgrav      *) func_append files " $arg" ;;
110597b5038d7SDag-Erling Smørgrav      esac
110607b5038d7SDag-Erling Smørgrav    done
110617b5038d7SDag-Erling Smørgrav
110627b5038d7SDag-Erling Smørgrav    test -z "$RM" && \
110637b5038d7SDag-Erling Smørgrav      func_fatal_help "you must specify an RM program"
110647b5038d7SDag-Erling Smørgrav
110657b5038d7SDag-Erling Smørgrav    rmdirs=
110667b5038d7SDag-Erling Smørgrav
110677b5038d7SDag-Erling Smørgrav    for file in $files; do
110687b5038d7SDag-Erling Smørgrav      func_dirname "$file" "" "."
11069986ba33cSDag-Erling Smørgrav      dir=$func_dirname_result
11070986ba33cSDag-Erling Smørgrav      if test . = "$dir"; then
11071986ba33cSDag-Erling Smørgrav	odir=$objdir
110727b5038d7SDag-Erling Smørgrav      else
11073986ba33cSDag-Erling Smørgrav	odir=$dir/$objdir
110747b5038d7SDag-Erling Smørgrav      fi
110757b5038d7SDag-Erling Smørgrav      func_basename "$file"
11076986ba33cSDag-Erling Smørgrav      name=$func_basename_result
11077986ba33cSDag-Erling Smørgrav      test uninstall = "$opt_mode" && odir=$dir
110787b5038d7SDag-Erling Smørgrav
110797b5038d7SDag-Erling Smørgrav      # Remember odir for removal later, being careful to avoid duplicates
11080986ba33cSDag-Erling Smørgrav      if test clean = "$opt_mode"; then
110817b5038d7SDag-Erling Smørgrav	case " $rmdirs " in
110827b5038d7SDag-Erling Smørgrav	  *" $odir "*) ;;
110837b5038d7SDag-Erling Smørgrav	  *) func_append rmdirs " $odir" ;;
110847b5038d7SDag-Erling Smørgrav	esac
110857b5038d7SDag-Erling Smørgrav      fi
110867b5038d7SDag-Erling Smørgrav
110877b5038d7SDag-Erling Smørgrav      # Don't error if the file doesn't exist and rm -f was used.
110887b5038d7SDag-Erling Smørgrav      if { test -L "$file"; } >/dev/null 2>&1 ||
110897b5038d7SDag-Erling Smørgrav	 { test -h "$file"; } >/dev/null 2>&1 ||
110907b5038d7SDag-Erling Smørgrav	 test -f "$file"; then
110917b5038d7SDag-Erling Smørgrav	:
110927b5038d7SDag-Erling Smørgrav      elif test -d "$file"; then
110937b5038d7SDag-Erling Smørgrav	exit_status=1
110947b5038d7SDag-Erling Smørgrav	continue
11095986ba33cSDag-Erling Smørgrav      elif $rmforce; then
110967b5038d7SDag-Erling Smørgrav	continue
110977b5038d7SDag-Erling Smørgrav      fi
110987b5038d7SDag-Erling Smørgrav
11099986ba33cSDag-Erling Smørgrav      rmfiles=$file
111007b5038d7SDag-Erling Smørgrav
111017b5038d7SDag-Erling Smørgrav      case $name in
111027b5038d7SDag-Erling Smørgrav      *.la)
111037b5038d7SDag-Erling Smørgrav	# Possibly a libtool archive, so verify it.
111047b5038d7SDag-Erling Smørgrav	if func_lalib_p "$file"; then
111057b5038d7SDag-Erling Smørgrav	  func_source $dir/$name
111067b5038d7SDag-Erling Smørgrav
111077b5038d7SDag-Erling Smørgrav	  # Delete the libtool libraries and symlinks.
111087b5038d7SDag-Erling Smørgrav	  for n in $library_names; do
111097b5038d7SDag-Erling Smørgrav	    func_append rmfiles " $odir/$n"
111107b5038d7SDag-Erling Smørgrav	  done
111117b5038d7SDag-Erling Smørgrav	  test -n "$old_library" && func_append rmfiles " $odir/$old_library"
111127b5038d7SDag-Erling Smørgrav
11113986ba33cSDag-Erling Smørgrav	  case $opt_mode in
111147b5038d7SDag-Erling Smørgrav	  clean)
111157b5038d7SDag-Erling Smørgrav	    case " $library_names " in
111167b5038d7SDag-Erling Smørgrav	    *" $dlname "*) ;;
111177b5038d7SDag-Erling Smørgrav	    *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;;
111187b5038d7SDag-Erling Smørgrav	    esac
111197b5038d7SDag-Erling Smørgrav	    test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i"
111207b5038d7SDag-Erling Smørgrav	    ;;
111217b5038d7SDag-Erling Smørgrav	  uninstall)
111227b5038d7SDag-Erling Smørgrav	    if test -n "$library_names"; then
111237b5038d7SDag-Erling Smørgrav	      # Do each command in the postuninstall commands.
11124986ba33cSDag-Erling Smørgrav	      func_execute_cmds "$postuninstall_cmds" '$rmforce || exit_status=1'
111257b5038d7SDag-Erling Smørgrav	    fi
111267b5038d7SDag-Erling Smørgrav
111277b5038d7SDag-Erling Smørgrav	    if test -n "$old_library"; then
111287b5038d7SDag-Erling Smørgrav	      # Do each command in the old_postuninstall commands.
11129986ba33cSDag-Erling Smørgrav	      func_execute_cmds "$old_postuninstall_cmds" '$rmforce || exit_status=1'
111307b5038d7SDag-Erling Smørgrav	    fi
111317b5038d7SDag-Erling Smørgrav	    # FIXME: should reinstall the best remaining shared library.
111327b5038d7SDag-Erling Smørgrav	    ;;
111337b5038d7SDag-Erling Smørgrav	  esac
111347b5038d7SDag-Erling Smørgrav	fi
111357b5038d7SDag-Erling Smørgrav	;;
111367b5038d7SDag-Erling Smørgrav
111377b5038d7SDag-Erling Smørgrav      *.lo)
111387b5038d7SDag-Erling Smørgrav	# Possibly a libtool object, so verify it.
111397b5038d7SDag-Erling Smørgrav	if func_lalib_p "$file"; then
111407b5038d7SDag-Erling Smørgrav
111417b5038d7SDag-Erling Smørgrav	  # Read the .lo file
111427b5038d7SDag-Erling Smørgrav	  func_source $dir/$name
111437b5038d7SDag-Erling Smørgrav
111447b5038d7SDag-Erling Smørgrav	  # Add PIC object to the list of files to remove.
11145986ba33cSDag-Erling Smørgrav	  if test -n "$pic_object" && test none != "$pic_object"; then
111467b5038d7SDag-Erling Smørgrav	    func_append rmfiles " $dir/$pic_object"
111477b5038d7SDag-Erling Smørgrav	  fi
111487b5038d7SDag-Erling Smørgrav
111497b5038d7SDag-Erling Smørgrav	  # Add non-PIC object to the list of files to remove.
11150986ba33cSDag-Erling Smørgrav	  if test -n "$non_pic_object" && test none != "$non_pic_object"; then
111517b5038d7SDag-Erling Smørgrav	    func_append rmfiles " $dir/$non_pic_object"
111527b5038d7SDag-Erling Smørgrav	  fi
111537b5038d7SDag-Erling Smørgrav	fi
111547b5038d7SDag-Erling Smørgrav	;;
111557b5038d7SDag-Erling Smørgrav
111567b5038d7SDag-Erling Smørgrav      *)
11157986ba33cSDag-Erling Smørgrav	if test clean = "$opt_mode"; then
111587b5038d7SDag-Erling Smørgrav	  noexename=$name
111597b5038d7SDag-Erling Smørgrav	  case $file in
111607b5038d7SDag-Erling Smørgrav	  *.exe)
111617b5038d7SDag-Erling Smørgrav	    func_stripname '' '.exe' "$file"
111627b5038d7SDag-Erling Smørgrav	    file=$func_stripname_result
111637b5038d7SDag-Erling Smørgrav	    func_stripname '' '.exe' "$name"
111647b5038d7SDag-Erling Smørgrav	    noexename=$func_stripname_result
111657b5038d7SDag-Erling Smørgrav	    # $file with .exe has already been added to rmfiles,
111667b5038d7SDag-Erling Smørgrav	    # add $file without .exe
111677b5038d7SDag-Erling Smørgrav	    func_append rmfiles " $file"
111687b5038d7SDag-Erling Smørgrav	    ;;
111697b5038d7SDag-Erling Smørgrav	  esac
111707b5038d7SDag-Erling Smørgrav	  # Do a test to see if this is a libtool program.
111717b5038d7SDag-Erling Smørgrav	  if func_ltwrapper_p "$file"; then
111727b5038d7SDag-Erling Smørgrav	    if func_ltwrapper_executable_p "$file"; then
111737b5038d7SDag-Erling Smørgrav	      func_ltwrapper_scriptname "$file"
111747b5038d7SDag-Erling Smørgrav	      relink_command=
111757b5038d7SDag-Erling Smørgrav	      func_source $func_ltwrapper_scriptname_result
111767b5038d7SDag-Erling Smørgrav	      func_append rmfiles " $func_ltwrapper_scriptname_result"
111777b5038d7SDag-Erling Smørgrav	    else
111787b5038d7SDag-Erling Smørgrav	      relink_command=
111797b5038d7SDag-Erling Smørgrav	      func_source $dir/$noexename
111807b5038d7SDag-Erling Smørgrav	    fi
111817b5038d7SDag-Erling Smørgrav
111827b5038d7SDag-Erling Smørgrav	    # note $name still contains .exe if it was in $file originally
111837b5038d7SDag-Erling Smørgrav	    # as does the version of $file that was added into $rmfiles
11184986ba33cSDag-Erling Smørgrav	    func_append rmfiles " $odir/$name $odir/${name}S.$objext"
11185986ba33cSDag-Erling Smørgrav	    if test yes = "$fast_install" && test -n "$relink_command"; then
111867b5038d7SDag-Erling Smørgrav	      func_append rmfiles " $odir/lt-$name"
111877b5038d7SDag-Erling Smørgrav	    fi
111887b5038d7SDag-Erling Smørgrav	    if test "X$noexename" != "X$name"; then
11189986ba33cSDag-Erling Smørgrav	      func_append rmfiles " $odir/lt-$noexename.c"
111907b5038d7SDag-Erling Smørgrav	    fi
111917b5038d7SDag-Erling Smørgrav	  fi
111927b5038d7SDag-Erling Smørgrav	fi
111937b5038d7SDag-Erling Smørgrav	;;
111947b5038d7SDag-Erling Smørgrav      esac
111957b5038d7SDag-Erling Smørgrav      func_show_eval "$RM $rmfiles" 'exit_status=1'
111967b5038d7SDag-Erling Smørgrav    done
111977b5038d7SDag-Erling Smørgrav
11198986ba33cSDag-Erling Smørgrav    # Try to remove the $objdir's in the directories where we deleted files
111997b5038d7SDag-Erling Smørgrav    for dir in $rmdirs; do
112007b5038d7SDag-Erling Smørgrav      if test -d "$dir"; then
112017b5038d7SDag-Erling Smørgrav	func_show_eval "rmdir $dir >/dev/null 2>&1"
112027b5038d7SDag-Erling Smørgrav      fi
112037b5038d7SDag-Erling Smørgrav    done
112047b5038d7SDag-Erling Smørgrav
112057b5038d7SDag-Erling Smørgrav    exit $exit_status
112067b5038d7SDag-Erling Smørgrav}
112077b5038d7SDag-Erling Smørgrav
11208986ba33cSDag-Erling Smørgravif test uninstall = "$opt_mode" || test clean = "$opt_mode"; then
112097b5038d7SDag-Erling Smørgrav  func_mode_uninstall ${1+"$@"}
11210986ba33cSDag-Erling Smørgravfi
112117b5038d7SDag-Erling Smørgrav
112127b5038d7SDag-Erling Smørgravtest -z "$opt_mode" && {
11213986ba33cSDag-Erling Smørgrav  help=$generic_help
112147b5038d7SDag-Erling Smørgrav  func_fatal_help "you must specify a MODE"
112157b5038d7SDag-Erling Smørgrav}
112167b5038d7SDag-Erling Smørgrav
112177b5038d7SDag-Erling Smørgravtest -z "$exec_cmd" && \
11218986ba33cSDag-Erling Smørgrav  func_fatal_help "invalid operation mode '$opt_mode'"
112197b5038d7SDag-Erling Smørgrav
112207b5038d7SDag-Erling Smørgravif test -n "$exec_cmd"; then
112217b5038d7SDag-Erling Smørgrav  eval exec "$exec_cmd"
112227b5038d7SDag-Erling Smørgrav  exit $EXIT_FAILURE
112237b5038d7SDag-Erling Smørgravfi
112247b5038d7SDag-Erling Smørgrav
112257b5038d7SDag-Erling Smørgravexit $exit_status
112267b5038d7SDag-Erling Smørgrav
112277b5038d7SDag-Erling Smørgrav
112287b5038d7SDag-Erling Smørgrav# The TAGs below are defined such that we never get into a situation
11229986ba33cSDag-Erling Smørgrav# where we disable both kinds of libraries.  Given conflicting
112307b5038d7SDag-Erling Smørgrav# choices, we go for a static library, that is the most portable,
112317b5038d7SDag-Erling Smørgrav# since we can't tell whether shared libraries were disabled because
112327b5038d7SDag-Erling Smørgrav# the user asked for that or because the platform doesn't support
112337b5038d7SDag-Erling Smørgrav# them.  This is particularly important on AIX, because we don't
112347b5038d7SDag-Erling Smørgrav# support having both static and shared libraries enabled at the same
112357b5038d7SDag-Erling Smørgrav# time on that platform, so we default to a shared-only configuration.
112367b5038d7SDag-Erling Smørgrav# If a disable-shared tag is given, we'll fallback to a static-only
112377b5038d7SDag-Erling Smørgrav# configuration.  But we'll never go from static-only to shared-only.
112387b5038d7SDag-Erling Smørgrav
112397b5038d7SDag-Erling Smørgrav# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
112407b5038d7SDag-Erling Smørgravbuild_libtool_libs=no
112417b5038d7SDag-Erling Smørgravbuild_old_libs=yes
112427b5038d7SDag-Erling Smørgrav# ### END LIBTOOL TAG CONFIG: disable-shared
112437b5038d7SDag-Erling Smørgrav
112447b5038d7SDag-Erling Smørgrav# ### BEGIN LIBTOOL TAG CONFIG: disable-static
112457b5038d7SDag-Erling Smørgravbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
112467b5038d7SDag-Erling Smørgrav# ### END LIBTOOL TAG CONFIG: disable-static
112477b5038d7SDag-Erling Smørgrav
112487b5038d7SDag-Erling Smørgrav# Local Variables:
112497b5038d7SDag-Erling Smørgrav# mode:shell-script
112507b5038d7SDag-Erling Smørgrav# sh-indentation:2
112517b5038d7SDag-Erling Smørgrav# End:
11252